aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/hub.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-16 18:04:26 -0400
commit971f115a50afbe409825c9f3399d5a3b9aca4381 (patch)
treecb42dc07a032e325f22b64d961587c081225c6d6 /drivers/usb/core/hub.c
parent2e270d84223262a38d4755c61d55f5c73ea89e56 (diff)
parent500132a0f26ad7d9916102193cbc6c1b1becb373 (diff)
Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (172 commits) USB: Add support for SuperSpeed isoc endpoints xhci: Clean up cycle bit math used during stalls. xhci: Fix cycle bit calculation during stall handling. xhci: Update internal dequeue pointers after stalls. USB: Disable auto-suspend for USB 3.0 hubs. USB: Remove bogus USB_PORT_STAT_SUPER_SPEED symbol. xhci: Return canceled URBs immediately when host is halted. xhci: Fixes for suspend/resume of shared HCDs. xhci: Fix re-init on power loss after resume. xhci: Make roothub functions deal with device removal. xhci: Limit roothub ports to 15 USB3 & 31 USB2 ports. xhci: Return a USB 3.0 hub descriptor for USB3 roothub. xhci: Register second xHCI roothub. xhci: Change xhci_find_slot_id_by_port() API. xhci: Refactor bus suspend state into a struct. xhci: Index with a port array instead of PORTSC addresses. USB: Set usb_hcd->state and flags for shared roothubs. usb: Make core allocate resources per PCI-device. usb: Store bus type in usb_hcd, not in driver flags. usb: Change usb_hcd->bandwidth_mutex to a pointer. ...
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r--drivers/usb/core/hub.c199
1 files changed, 130 insertions, 69 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 19d3435e6140..564eaa5525d7 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -82,6 +82,10 @@ struct usb_hub {
82 void **port_owners; 82 void **port_owners;
83}; 83};
84 84
85static inline int hub_is_superspeed(struct usb_device *hdev)
86{
87 return (hdev->descriptor.bDeviceProtocol == 3);
88}
85 89
86/* Protect struct usb_device->state and ->children members 90/* Protect struct usb_device->state and ->children members
87 * Note: Both are also protected by ->dev.sem, except that ->state can 91 * Note: Both are also protected by ->dev.sem, except that ->state can
@@ -151,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem);
151 155
152static int usb_reset_and_verify_device(struct usb_device *udev); 156static int usb_reset_and_verify_device(struct usb_device *udev);
153 157
154static inline char *portspeed(int portstatus) 158static inline char *portspeed(struct usb_hub *hub, int portstatus)
155{ 159{
160 if (hub_is_superspeed(hub->hdev))
161 return "5.0 Gb/s";
156 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 162 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
157 return "480 Mb/s"; 163 return "480 Mb/s";
158 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 164 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
159 return "1.5 Mb/s"; 165 return "1.5 Mb/s";
160 else if (portstatus & USB_PORT_STAT_SUPER_SPEED)
161 return "5.0 Gb/s";
162 else 166 else
163 return "12 Mb/s"; 167 return "12 Mb/s";
164} 168}
@@ -172,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
172} 176}
173 177
174/* USB 2.0 spec Section 11.24.4.5 */ 178/* USB 2.0 spec Section 11.24.4.5 */
175static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) 179static int get_hub_descriptor(struct usb_device *hdev, void *data)
176{ 180{
177 int i, ret; 181 int i, ret, size;
182 unsigned dtype;
183
184 if (hub_is_superspeed(hdev)) {
185 dtype = USB_DT_SS_HUB;
186 size = USB_DT_SS_HUB_SIZE;
187 } else {
188 dtype = USB_DT_HUB;
189 size = sizeof(struct usb_hub_descriptor);
190 }
178 191
179 for (i = 0; i < 3; i++) { 192 for (i = 0; i < 3; i++) {
180 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), 193 ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
181 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, 194 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
182 USB_DT_HUB << 8, 0, data, size, 195 dtype << 8, 0, data, size,
183 USB_CTRL_GET_TIMEOUT); 196 USB_CTRL_GET_TIMEOUT);
184 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) 197 if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2))
185 return ret; 198 return ret;
@@ -365,6 +378,16 @@ static int hub_port_status(struct usb_hub *hub, int port1,
365 } else { 378 } else {
366 *status = le16_to_cpu(hub->status->port.wPortStatus); 379 *status = le16_to_cpu(hub->status->port.wPortStatus);
367 *change = le16_to_cpu(hub->status->port.wPortChange); 380 *change = le16_to_cpu(hub->status->port.wPortChange);
381
382 if ((hub->hdev->parent != NULL) &&
383 hub_is_superspeed(hub->hdev)) {
384 /* Translate the USB 3 port status */
385 u16 tmp = *status & USB_SS_PORT_STAT_MASK;
386 if (*status & USB_SS_PORT_STAT_POWER)
387 tmp |= USB_PORT_STAT_POWER;
388 *status = tmp;
389 }
390
368 ret = 0; 391 ret = 0;
369 } 392 }
370 mutex_unlock(&hub->status_mutex); 393 mutex_unlock(&hub->status_mutex);
@@ -607,7 +630,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
607 if (hdev->children[port1-1] && set_state) 630 if (hdev->children[port1-1] && set_state)
608 usb_set_device_state(hdev->children[port1-1], 631 usb_set_device_state(hdev->children[port1-1],
609 USB_STATE_NOTATTACHED); 632 USB_STATE_NOTATTACHED);
610 if (!hub->error) 633 if (!hub->error && !hub_is_superspeed(hub->hdev))
611 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); 634 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
612 if (ret) 635 if (ret)
613 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 636 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
@@ -616,7 +639,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
616} 639}
617 640
618/* 641/*
619 * Disable a port and mark a logical connnect-change event, so that some 642 * Disable a port and mark a logical connect-change event, so that some
620 * time later khubd will disconnect() any existing usb_device on the port 643 * time later khubd will disconnect() any existing usb_device on the port
621 * and will re-enumerate if there actually is a device attached. 644 * and will re-enumerate if there actually is a device attached.
622 */ 645 */
@@ -769,12 +792,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
769 * USB3 protocol ports will automatically transition 792 * USB3 protocol ports will automatically transition
770 * to Enabled state when detect an USB3.0 device attach. 793 * to Enabled state when detect an USB3.0 device attach.
771 * Do not disable USB3 protocol ports. 794 * Do not disable USB3 protocol ports.
772 * FIXME: USB3 root hub and external hubs are treated
773 * differently here.
774 */ 795 */
775 if (hdev->descriptor.bDeviceProtocol != 3 || 796 if (!hub_is_superspeed(hdev)) {
776 (!hdev->parent &&
777 !(portstatus & USB_PORT_STAT_SUPER_SPEED))) {
778 clear_port_feature(hdev, port1, 797 clear_port_feature(hdev, port1,
779 USB_PORT_FEAT_ENABLE); 798 USB_PORT_FEAT_ENABLE);
780 portstatus &= ~USB_PORT_STAT_ENABLE; 799 portstatus &= ~USB_PORT_STAT_ENABLE;
@@ -795,6 +814,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
795 clear_port_feature(hub->hdev, port1, 814 clear_port_feature(hub->hdev, port1,
796 USB_PORT_FEAT_C_ENABLE); 815 USB_PORT_FEAT_C_ENABLE);
797 } 816 }
817 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
818 need_debounce_delay = true;
819 clear_port_feature(hub->hdev, port1,
820 USB_PORT_FEAT_C_PORT_LINK_STATE);
821 }
798 822
799 /* We can forget about a "removed" device when there's a 823 /* We can forget about a "removed" device when there's a
800 * physical disconnect or the connect status changes. 824 * physical disconnect or the connect status changes.
@@ -964,12 +988,23 @@ static int hub_configure(struct usb_hub *hub,
964 goto fail; 988 goto fail;
965 } 989 }
966 990
991 if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) {
992 ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
993 HUB_SET_DEPTH, USB_RT_HUB,
994 hdev->level - 1, 0, NULL, 0,
995 USB_CTRL_SET_TIMEOUT);
996
997 if (ret < 0) {
998 message = "can't set hub depth";
999 goto fail;
1000 }
1001 }
1002
967 /* Request the entire hub descriptor. 1003 /* Request the entire hub descriptor.
968 * hub->descriptor can handle USB_MAXCHILDREN ports, 1004 * hub->descriptor can handle USB_MAXCHILDREN ports,
969 * but the hub can/will return fewer bytes here. 1005 * but the hub can/will return fewer bytes here.
970 */ 1006 */
971 ret = get_hub_descriptor(hdev, hub->descriptor, 1007 ret = get_hub_descriptor(hdev, hub->descriptor);
972 sizeof(*hub->descriptor));
973 if (ret < 0) { 1008 if (ret < 0) {
974 message = "can't read hub descriptor"; 1009 message = "can't read hub descriptor";
975 goto fail; 1010 goto fail;
@@ -991,12 +1026,14 @@ static int hub_configure(struct usb_hub *hub,
991 1026
992 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 1027 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
993 1028
994 if (wHubCharacteristics & HUB_CHAR_COMPOUND) { 1029 /* FIXME for USB 3.0, skip for now */
1030 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
1031 !(hub_is_superspeed(hdev))) {
995 int i; 1032 int i;
996 char portstr [USB_MAXCHILDREN + 1]; 1033 char portstr [USB_MAXCHILDREN + 1];
997 1034
998 for (i = 0; i < hdev->maxchild; i++) 1035 for (i = 0; i < hdev->maxchild; i++)
999 portstr[i] = hub->descriptor->DeviceRemovable 1036 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
1000 [((i + 1) / 8)] & (1 << ((i + 1) % 8)) 1037 [((i + 1) / 8)] & (1 << ((i + 1) % 8))
1001 ? 'F' : 'R'; 1038 ? 'F' : 'R';
1002 portstr[hdev->maxchild] = 0; 1039 portstr[hdev->maxchild] = 0;
@@ -1253,8 +1290,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
1253 desc = intf->cur_altsetting; 1290 desc = intf->cur_altsetting;
1254 hdev = interface_to_usbdev(intf); 1291 hdev = interface_to_usbdev(intf);
1255 1292
1256 /* Hubs have proper suspend/resume support */ 1293 /* Hubs have proper suspend/resume support. USB 3.0 device suspend is
1257 usb_enable_autosuspend(hdev); 1294 * different from USB 2.0/1.1 device suspend, and unfortunately we
1295 * don't support it yet. So leave autosuspend disabled for USB 3.0
1296 * external hubs for now. Enable autosuspend for USB 3.0 roothubs,
1297 * since that isn't a "real" hub.
1298 */
1299 if (!hub_is_superspeed(hdev) || !hdev->parent)
1300 usb_enable_autosuspend(hdev);
1258 1301
1259 if (hdev->level == MAX_TOPO_LEVEL) { 1302 if (hdev->level == MAX_TOPO_LEVEL) {
1260 dev_err(&intf->dev, 1303 dev_err(&intf->dev,
@@ -1501,6 +1544,13 @@ void usb_set_device_state(struct usb_device *udev,
1501EXPORT_SYMBOL_GPL(usb_set_device_state); 1544EXPORT_SYMBOL_GPL(usb_set_device_state);
1502 1545
1503/* 1546/*
1547 * Choose a device number.
1548 *
1549 * Device numbers are used as filenames in usbfs. On USB-1.1 and
1550 * USB-2.0 buses they are also used as device addresses, however on
1551 * USB-3.0 buses the address is assigned by the controller hardware
1552 * and it usually is not the same as the device number.
1553 *
1504 * WUSB devices are simple: they have no hubs behind, so the mapping 1554 * WUSB devices are simple: they have no hubs behind, so the mapping
1505 * device <-> virtual port number becomes 1:1. Why? to simplify the 1555 * device <-> virtual port number becomes 1:1. Why? to simplify the
1506 * life of the device connection logic in 1556 * life of the device connection logic in
@@ -1522,7 +1572,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state);
1522 * the HCD must setup data structures before issuing a set address 1572 * the HCD must setup data structures before issuing a set address
1523 * command to the hardware. 1573 * command to the hardware.
1524 */ 1574 */
1525static void choose_address(struct usb_device *udev) 1575static void choose_devnum(struct usb_device *udev)
1526{ 1576{
1527 int devnum; 1577 int devnum;
1528 struct usb_bus *bus = udev->bus; 1578 struct usb_bus *bus = udev->bus;
@@ -1547,7 +1597,7 @@ static void choose_address(struct usb_device *udev)
1547 } 1597 }
1548} 1598}
1549 1599
1550static void release_address(struct usb_device *udev) 1600static void release_devnum(struct usb_device *udev)
1551{ 1601{
1552 if (udev->devnum > 0) { 1602 if (udev->devnum > 0) {
1553 clear_bit(udev->devnum, udev->bus->devmap.devicemap); 1603 clear_bit(udev->devnum, udev->bus->devmap.devicemap);
@@ -1555,7 +1605,7 @@ static void release_address(struct usb_device *udev)
1555 } 1605 }
1556} 1606}
1557 1607
1558static void update_address(struct usb_device *udev, int devnum) 1608static void update_devnum(struct usb_device *udev, int devnum)
1559{ 1609{
1560 /* The address for a WUSB device is managed by wusbcore. */ 1610 /* The address for a WUSB device is managed by wusbcore. */
1561 if (!udev->wusb) 1611 if (!udev->wusb)
@@ -1602,7 +1652,8 @@ void usb_disconnect(struct usb_device **pdev)
1602 * this quiesces everyting except pending urbs. 1652 * this quiesces everyting except pending urbs.
1603 */ 1653 */
1604 usb_set_device_state(udev, USB_STATE_NOTATTACHED); 1654 usb_set_device_state(udev, USB_STATE_NOTATTACHED);
1605 dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); 1655 dev_info(&udev->dev, "USB disconnect, device number %d\n",
1656 udev->devnum);
1606 1657
1607 usb_lock_device(udev); 1658 usb_lock_device(udev);
1608 1659
@@ -1632,7 +1683,7 @@ void usb_disconnect(struct usb_device **pdev)
1632 /* Free the device number and delete the parent's children[] 1683 /* Free the device number and delete the parent's children[]
1633 * (or root_hub) pointer. 1684 * (or root_hub) pointer.
1634 */ 1685 */
1635 release_address(udev); 1686 release_devnum(udev);
1636 1687
1637 /* Avoid races with recursively_mark_NOTATTACHED() */ 1688 /* Avoid races with recursively_mark_NOTATTACHED() */
1638 spin_lock_irq(&device_state_lock); 1689 spin_lock_irq(&device_state_lock);
@@ -2017,7 +2068,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2017 (portstatus & USB_PORT_STAT_ENABLE)) { 2068 (portstatus & USB_PORT_STAT_ENABLE)) {
2018 if (hub_is_wusb(hub)) 2069 if (hub_is_wusb(hub))
2019 udev->speed = USB_SPEED_WIRELESS; 2070 udev->speed = USB_SPEED_WIRELESS;
2020 else if (portstatus & USB_PORT_STAT_SUPER_SPEED) 2071 else if (hub_is_superspeed(hub->hdev))
2021 udev->speed = USB_SPEED_SUPER; 2072 udev->speed = USB_SPEED_SUPER;
2022 else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2073 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
2023 udev->speed = USB_SPEED_HIGH; 2074 udev->speed = USB_SPEED_HIGH;
@@ -2073,7 +2124,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2073 case 0: 2124 case 0:
2074 /* TRSTRCY = 10 ms; plus some extra */ 2125 /* TRSTRCY = 10 ms; plus some extra */
2075 msleep(10 + 40); 2126 msleep(10 + 40);
2076 update_address(udev, 0); 2127 update_devnum(udev, 0);
2077 if (hcd->driver->reset_device) { 2128 if (hcd->driver->reset_device) {
2078 status = hcd->driver->reset_device(hcd, udev); 2129 status = hcd->driver->reset_device(hcd, udev);
2079 if (status < 0) { 2130 if (status < 0) {
@@ -2636,7 +2687,7 @@ static int hub_set_address(struct usb_device *udev, int devnum)
2636 USB_REQ_SET_ADDRESS, 0, devnum, 0, 2687 USB_REQ_SET_ADDRESS, 0, devnum, 0,
2637 NULL, 0, USB_CTRL_SET_TIMEOUT); 2688 NULL, 0, USB_CTRL_SET_TIMEOUT);
2638 if (retval == 0) { 2689 if (retval == 0) {
2639 update_address(udev, devnum); 2690 update_devnum(udev, devnum);
2640 /* Device now using proper address. */ 2691 /* Device now using proper address. */
2641 usb_set_device_state(udev, USB_STATE_ADDRESS); 2692 usb_set_device_state(udev, USB_STATE_ADDRESS);
2642 usb_ep0_reinit(udev); 2693 usb_ep0_reinit(udev);
@@ -2741,9 +2792,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2741 } 2792 }
2742 if (udev->speed != USB_SPEED_SUPER) 2793 if (udev->speed != USB_SPEED_SUPER)
2743 dev_info(&udev->dev, 2794 dev_info(&udev->dev,
2744 "%s %s speed %sUSB device using %s and address %d\n", 2795 "%s %s speed %sUSB device number %d using %s\n",
2745 (udev->config) ? "reset" : "new", speed, type, 2796 (udev->config) ? "reset" : "new", speed, type,
2746 udev->bus->controller->driver->name, devnum); 2797 devnum, udev->bus->controller->driver->name);
2747 2798
2748 /* Set up TT records, if needed */ 2799 /* Set up TT records, if needed */
2749 if (hdev->tt) { 2800 if (hdev->tt) {
@@ -2773,10 +2824,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2773 * value. 2824 * value.
2774 */ 2825 */
2775 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { 2826 for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) {
2776 /*
2777 * An xHCI controller cannot send any packets to a device until
2778 * a set address command successfully completes.
2779 */
2780 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { 2827 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) {
2781 struct usb_device_descriptor *buf; 2828 struct usb_device_descriptor *buf;
2782 int r = 0; 2829 int r = 0;
@@ -2859,9 +2906,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2859 if (udev->speed == USB_SPEED_SUPER) { 2906 if (udev->speed == USB_SPEED_SUPER) {
2860 devnum = udev->devnum; 2907 devnum = udev->devnum;
2861 dev_info(&udev->dev, 2908 dev_info(&udev->dev,
2862 "%s SuperSpeed USB device using %s and address %d\n", 2909 "%s SuperSpeed USB device number %d using %s\n",
2863 (udev->config) ? "reset" : "new", 2910 (udev->config) ? "reset" : "new",
2864 udev->bus->controller->driver->name, devnum); 2911 devnum, udev->bus->controller->driver->name);
2865 } 2912 }
2866 2913
2867 /* cope with hardware quirkiness: 2914 /* cope with hardware quirkiness:
@@ -2924,7 +2971,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2924fail: 2971fail:
2925 if (retval) { 2972 if (retval) {
2926 hub_port_disable(hub, port1, 0); 2973 hub_port_disable(hub, port1, 0);
2927 update_address(udev, devnum); /* for disconnect processing */ 2974 update_devnum(udev, devnum); /* for disconnect processing */
2928 } 2975 }
2929 mutex_unlock(&usb_address0_mutex); 2976 mutex_unlock(&usb_address0_mutex);
2930 return retval; 2977 return retval;
@@ -3015,7 +3062,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3015 3062
3016 dev_dbg (hub_dev, 3063 dev_dbg (hub_dev,
3017 "port %d, status %04x, change %04x, %s\n", 3064 "port %d, status %04x, change %04x, %s\n",
3018 port1, portstatus, portchange, portspeed (portstatus)); 3065 port1, portstatus, portchange, portspeed(hub, portstatus));
3019 3066
3020 if (hub->has_indicators) { 3067 if (hub->has_indicators) {
3021 set_port_led(hub, port1, HUB_LED_AUTO); 3068 set_port_led(hub, port1, HUB_LED_AUTO);
@@ -3116,32 +3163,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3116 udev->level = hdev->level + 1; 3163 udev->level = hdev->level + 1;
3117 udev->wusb = hub_is_wusb(hub); 3164 udev->wusb = hub_is_wusb(hub);
3118 3165
3119 /* 3166 /* Only USB 3.0 devices are connected to SuperSpeed hubs. */
3120 * USB 3.0 devices are reset automatically before the connect 3167 if (hub_is_superspeed(hub->hdev))
3121 * port status change appears, and the root hub port status
3122 * shows the correct speed. We also get port change
3123 * notifications for USB 3.0 devices from the USB 3.0 portion of
3124 * an external USB 3.0 hub, but this isn't handled correctly yet
3125 * FIXME.
3126 */
3127
3128 if (!(hcd->driver->flags & HCD_USB3))
3129 udev->speed = USB_SPEED_UNKNOWN;
3130 else if ((hdev->parent == NULL) &&
3131 (portstatus & USB_PORT_STAT_SUPER_SPEED))
3132 udev->speed = USB_SPEED_SUPER; 3168 udev->speed = USB_SPEED_SUPER;
3133 else 3169 else
3134 udev->speed = USB_SPEED_UNKNOWN; 3170 udev->speed = USB_SPEED_UNKNOWN;
3135 3171
3136 /* 3172 choose_devnum(udev);
3137 * Set the address.
3138 * Note xHCI needs to issue an address device command later
3139 * in the hub_port_init sequence for SS/HS/FS/LS devices,
3140 * and xHC will assign an address to the device. But use
3141 * kernel assigned address here, to avoid any address conflict
3142 * issue.
3143 */
3144 choose_address(udev);
3145 if (udev->devnum <= 0) { 3173 if (udev->devnum <= 0) {
3146 status = -ENOTCONN; /* Don't retry */ 3174 status = -ENOTCONN; /* Don't retry */
3147 goto loop; 3175 goto loop;
@@ -3233,7 +3261,7 @@ loop_disable:
3233 hub_port_disable(hub, port1, 1); 3261 hub_port_disable(hub, port1, 1);
3234loop: 3262loop:
3235 usb_ep0_reinit(udev); 3263 usb_ep0_reinit(udev);
3236 release_address(udev); 3264 release_devnum(udev);
3237 hub_free_dev(udev); 3265 hub_free_dev(udev);
3238 usb_put_dev(udev); 3266 usb_put_dev(udev);
3239 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) 3267 if ((status == -ENOTCONN) || (status == -ENOTSUPP))
@@ -3410,12 +3438,19 @@ static void hub_events(void)
3410 } 3438 }
3411 3439
3412 if (portchange & USB_PORT_STAT_C_OVERCURRENT) { 3440 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
3413 dev_err (hub_dev, 3441 u16 status = 0;
3414 "over-current change on port %d\n", 3442 u16 unused;
3415 i); 3443
3444 dev_dbg(hub_dev, "over-current change on port "
3445 "%d\n", i);
3416 clear_port_feature(hdev, i, 3446 clear_port_feature(hdev, i,
3417 USB_PORT_FEAT_C_OVER_CURRENT); 3447 USB_PORT_FEAT_C_OVER_CURRENT);
3448 msleep(100); /* Cool down */
3418 hub_power_on(hub, true); 3449 hub_power_on(hub, true);
3450 hub_port_status(hub, i, &status, &unused);
3451 if (status & USB_PORT_STAT_OVERCURRENT)
3452 dev_err(hub_dev, "over-current "
3453 "condition on port %d\n", i);
3419 } 3454 }
3420 3455
3421 if (portchange & USB_PORT_STAT_C_RESET) { 3456 if (portchange & USB_PORT_STAT_C_RESET) {
@@ -3425,6 +3460,25 @@ static void hub_events(void)
3425 clear_port_feature(hdev, i, 3460 clear_port_feature(hdev, i,
3426 USB_PORT_FEAT_C_RESET); 3461 USB_PORT_FEAT_C_RESET);
3427 } 3462 }
3463 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
3464 hub_is_superspeed(hub->hdev)) {
3465 dev_dbg(hub_dev,
3466 "warm reset change on port %d\n",
3467 i);
3468 clear_port_feature(hdev, i,
3469 USB_PORT_FEAT_C_BH_PORT_RESET);
3470 }
3471 if (portchange & USB_PORT_STAT_C_LINK_STATE) {
3472 clear_port_feature(hub->hdev, i,
3473 USB_PORT_FEAT_C_PORT_LINK_STATE);
3474 }
3475 if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) {
3476 dev_warn(hub_dev,
3477 "config error on port %d\n",
3478 i);
3479 clear_port_feature(hub->hdev, i,
3480 USB_PORT_FEAT_C_PORT_CONFIG_ERROR);
3481 }
3428 3482
3429 if (connect_change) 3483 if (connect_change)
3430 hub_port_connect_change(hub, i, 3484 hub_port_connect_change(hub, i,
@@ -3447,10 +3501,17 @@ static void hub_events(void)
3447 hub->limited_power = 0; 3501 hub->limited_power = 0;
3448 } 3502 }
3449 if (hubchange & HUB_CHANGE_OVERCURRENT) { 3503 if (hubchange & HUB_CHANGE_OVERCURRENT) {
3450 dev_dbg (hub_dev, "overcurrent change\n"); 3504 u16 status = 0;
3451 msleep(500); /* Cool down */ 3505 u16 unused;
3506
3507 dev_dbg(hub_dev, "over-current change\n");
3452 clear_hub_feature(hdev, C_HUB_OVER_CURRENT); 3508 clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
3509 msleep(500); /* Cool down */
3453 hub_power_on(hub, true); 3510 hub_power_on(hub, true);
3511 hub_hub_status(hub, &status, &unused);
3512 if (status & HUB_STATUS_OVERCURRENT)
3513 dev_err(hub_dev, "over-current "
3514 "condition\n");
3454 } 3515 }
3455 } 3516 }
3456 3517
@@ -3699,13 +3760,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3699 if (!udev->actconfig) 3760 if (!udev->actconfig)
3700 goto done; 3761 goto done;
3701 3762
3702 mutex_lock(&hcd->bandwidth_mutex); 3763 mutex_lock(hcd->bandwidth_mutex);
3703 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); 3764 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
3704 if (ret < 0) { 3765 if (ret < 0) {
3705 dev_warn(&udev->dev, 3766 dev_warn(&udev->dev,
3706 "Busted HC? Not enough HCD resources for " 3767 "Busted HC? Not enough HCD resources for "
3707 "old configuration.\n"); 3768 "old configuration.\n");
3708 mutex_unlock(&hcd->bandwidth_mutex); 3769 mutex_unlock(hcd->bandwidth_mutex);
3709 goto re_enumerate; 3770 goto re_enumerate;
3710 } 3771 }
3711 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3772 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -3716,10 +3777,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3716 dev_err(&udev->dev, 3777 dev_err(&udev->dev,
3717 "can't restore configuration #%d (error=%d)\n", 3778 "can't restore configuration #%d (error=%d)\n",
3718 udev->actconfig->desc.bConfigurationValue, ret); 3779 udev->actconfig->desc.bConfigurationValue, ret);
3719 mutex_unlock(&hcd->bandwidth_mutex); 3780 mutex_unlock(hcd->bandwidth_mutex);
3720 goto re_enumerate; 3781 goto re_enumerate;
3721 } 3782 }
3722 mutex_unlock(&hcd->bandwidth_mutex); 3783 mutex_unlock(hcd->bandwidth_mutex);
3723 usb_set_device_state(udev, USB_STATE_CONFIGURED); 3784 usb_set_device_state(udev, USB_STATE_CONFIGURED);
3724 3785
3725 /* Put interfaces back into the same altsettings as before. 3786 /* Put interfaces back into the same altsettings as before.