aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/xhci-mem.c')
-rw-r--r--drivers/usb/host/xhci-mem.c106
1 files changed, 70 insertions, 36 deletions
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index a003e79aacdc..627f3438028c 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -846,7 +846,7 @@ static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
846 * Skip ports that don't have known speeds, or have duplicate 846 * Skip ports that don't have known speeds, or have duplicate
847 * Extended Capabilities port speed entries. 847 * Extended Capabilities port speed entries.
848 */ 848 */
849 if (port_speed == 0 || port_speed == -1) 849 if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
850 continue; 850 continue;
851 851
852 /* 852 /*
@@ -974,6 +974,47 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
974 return 0; 974 return 0;
975} 975}
976 976
977/*
978 * Convert interval expressed as 2^(bInterval - 1) == interval into
979 * straight exponent value 2^n == interval.
980 *
981 */
982static unsigned int xhci_parse_exponent_interval(struct usb_device *udev,
983 struct usb_host_endpoint *ep)
984{
985 unsigned int interval;
986
987 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1;
988 if (interval != ep->desc.bInterval - 1)
989 dev_warn(&udev->dev,
990 "ep %#x - rounding interval to %d microframes\n",
991 ep->desc.bEndpointAddress,
992 1 << interval);
993
994 return interval;
995}
996
997/*
998 * Convert bInterval expressed in frames (in 1-255 range) to exponent of
999 * microframes, rounded down to nearest power of 2.
1000 */
1001static unsigned int xhci_parse_frame_interval(struct usb_device *udev,
1002 struct usb_host_endpoint *ep)
1003{
1004 unsigned int interval;
1005
1006 interval = fls(8 * ep->desc.bInterval) - 1;
1007 interval = clamp_val(interval, 3, 10);
1008 if ((1 << interval) != 8 * ep->desc.bInterval)
1009 dev_warn(&udev->dev,
1010 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n",
1011 ep->desc.bEndpointAddress,
1012 1 << interval,
1013 8 * ep->desc.bInterval);
1014
1015 return interval;
1016}
1017
977/* Return the polling or NAK interval. 1018/* Return the polling or NAK interval.
978 * 1019 *
979 * The polling interval is expressed in "microframes". If xHCI's Interval field 1020 * The polling interval is expressed in "microframes". If xHCI's Interval field
@@ -982,7 +1023,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
982 * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval 1023 * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval
983 * is set to 0. 1024 * is set to 0.
984 */ 1025 */
985static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev, 1026static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
986 struct usb_host_endpoint *ep) 1027 struct usb_host_endpoint *ep)
987{ 1028{
988 unsigned int interval = 0; 1029 unsigned int interval = 0;
@@ -991,45 +1032,38 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
991 case USB_SPEED_HIGH: 1032 case USB_SPEED_HIGH:
992 /* Max NAK rate */ 1033 /* Max NAK rate */
993 if (usb_endpoint_xfer_control(&ep->desc) || 1034 if (usb_endpoint_xfer_control(&ep->desc) ||
994 usb_endpoint_xfer_bulk(&ep->desc)) 1035 usb_endpoint_xfer_bulk(&ep->desc)) {
995 interval = ep->desc.bInterval; 1036 interval = ep->desc.bInterval;
1037 break;
1038 }
996 /* Fall through - SS and HS isoc/int have same decoding */ 1039 /* Fall through - SS and HS isoc/int have same decoding */
1040
997 case USB_SPEED_SUPER: 1041 case USB_SPEED_SUPER:
998 if (usb_endpoint_xfer_int(&ep->desc) || 1042 if (usb_endpoint_xfer_int(&ep->desc) ||
999 usb_endpoint_xfer_isoc(&ep->desc)) { 1043 usb_endpoint_xfer_isoc(&ep->desc)) {
1000 if (ep->desc.bInterval == 0) 1044 interval = xhci_parse_exponent_interval(udev, ep);
1001 interval = 0;
1002 else
1003 interval = ep->desc.bInterval - 1;
1004 if (interval > 15)
1005 interval = 15;
1006 if (interval != ep->desc.bInterval + 1)
1007 dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n",
1008 ep->desc.bEndpointAddress, 1 << interval);
1009 } 1045 }
1010 break; 1046 break;
1011 /* Convert bInterval (in 1-255 frames) to microframes and round down to 1047
1012 * nearest power of 2.
1013 */
1014 case USB_SPEED_FULL: 1048 case USB_SPEED_FULL:
1049 if (usb_endpoint_xfer_int(&ep->desc)) {
1050 interval = xhci_parse_exponent_interval(udev, ep);
1051 break;
1052 }
1053 /*
1054 * Fall through for isochronous endpoint interval decoding
1055 * since it uses the same rules as low speed interrupt
1056 * endpoints.
1057 */
1058
1015 case USB_SPEED_LOW: 1059 case USB_SPEED_LOW:
1016 if (usb_endpoint_xfer_int(&ep->desc) || 1060 if (usb_endpoint_xfer_int(&ep->desc) ||
1017 usb_endpoint_xfer_isoc(&ep->desc)) { 1061 usb_endpoint_xfer_isoc(&ep->desc)) {
1018 interval = fls(8*ep->desc.bInterval) - 1; 1062
1019 if (interval > 10) 1063 interval = xhci_parse_frame_interval(udev, ep);
1020 interval = 10;
1021 if (interval < 3)
1022 interval = 3;
1023 if ((1 << interval) != 8*ep->desc.bInterval)
1024 dev_warn(&udev->dev,
1025 "ep %#x - rounding interval"
1026 " to %d microframes, "
1027 "ep desc says %d microframes\n",
1028 ep->desc.bEndpointAddress,
1029 1 << interval,
1030 8*ep->desc.bInterval);
1031 } 1064 }
1032 break; 1065 break;
1066
1033 default: 1067 default:
1034 BUG(); 1068 BUG();
1035 } 1069 }
@@ -1041,7 +1075,7 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
1041 * transaction opportunities per microframe", but that goes in the Max Burst 1075 * transaction opportunities per microframe", but that goes in the Max Burst
1042 * endpoint context field. 1076 * endpoint context field.
1043 */ 1077 */
1044static inline u32 xhci_get_endpoint_mult(struct usb_device *udev, 1078static u32 xhci_get_endpoint_mult(struct usb_device *udev,
1045 struct usb_host_endpoint *ep) 1079 struct usb_host_endpoint *ep)
1046{ 1080{
1047 if (udev->speed != USB_SPEED_SUPER || 1081 if (udev->speed != USB_SPEED_SUPER ||
@@ -1050,7 +1084,7 @@ static inline u32 xhci_get_endpoint_mult(struct usb_device *udev,
1050 return ep->ss_ep_comp.bmAttributes; 1084 return ep->ss_ep_comp.bmAttributes;
1051} 1085}
1052 1086
1053static inline u32 xhci_get_endpoint_type(struct usb_device *udev, 1087static u32 xhci_get_endpoint_type(struct usb_device *udev,
1054 struct usb_host_endpoint *ep) 1088 struct usb_host_endpoint *ep)
1055{ 1089{
1056 int in; 1090 int in;
@@ -1084,7 +1118,7 @@ static inline u32 xhci_get_endpoint_type(struct usb_device *udev,
1084 * Basically, this is the maxpacket size, multiplied by the burst size 1118 * Basically, this is the maxpacket size, multiplied by the burst size
1085 * and mult size. 1119 * and mult size.
1086 */ 1120 */
1087static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci, 1121static u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
1088 struct usb_device *udev, 1122 struct usb_device *udev,
1089 struct usb_host_endpoint *ep) 1123 struct usb_host_endpoint *ep)
1090{ 1124{
@@ -1727,12 +1761,12 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
1727 * found a similar duplicate. 1761 * found a similar duplicate.
1728 */ 1762 */
1729 if (xhci->port_array[i] != major_revision && 1763 if (xhci->port_array[i] != major_revision &&
1730 xhci->port_array[i] != (u8) -1) { 1764 xhci->port_array[i] != DUPLICATE_ENTRY) {
1731 if (xhci->port_array[i] == 0x03) 1765 if (xhci->port_array[i] == 0x03)
1732 xhci->num_usb3_ports--; 1766 xhci->num_usb3_ports--;
1733 else 1767 else
1734 xhci->num_usb2_ports--; 1768 xhci->num_usb2_ports--;
1735 xhci->port_array[i] = (u8) -1; 1769 xhci->port_array[i] = DUPLICATE_ENTRY;
1736 } 1770 }
1737 /* FIXME: Should we disable the port? */ 1771 /* FIXME: Should we disable the port? */
1738 continue; 1772 continue;
@@ -1831,7 +1865,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
1831 for (i = 0; i < num_ports; i++) { 1865 for (i = 0; i < num_ports; i++) {
1832 if (xhci->port_array[i] == 0x03 || 1866 if (xhci->port_array[i] == 0x03 ||
1833 xhci->port_array[i] == 0 || 1867 xhci->port_array[i] == 0 ||
1834 xhci->port_array[i] == -1) 1868 xhci->port_array[i] == DUPLICATE_ENTRY)
1835 continue; 1869 continue;
1836 1870
1837 xhci->usb2_ports[port_index] = 1871 xhci->usb2_ports[port_index] =