Lines Matching full:hub

3  * USB hub driver.
39 #include "hub.h"
74 /* workqueue to process hub events */
78 /* synchronize hub-port add/remove and peering operations */
106 * hub driver's behavior. On the first initialization attempt, if the
133 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
134 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
137 static inline char *portspeed(struct usb_hub *hub, int portstatus)
139 if (hub_is_superspeedplus(hub->hdev))
141 if (hub_is_superspeed(hub->hdev))
212 struct usb_hub *hub,
222 * and the hub header decode latency. See USB 3.1 section C 2.2.1
227 hub->descriptor->u.ss.bHubHdrDecLat * 100;
231 * each link + wHubDelay for each hub. Add only for last link.
235 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) +
246 if (!hub->hdev->parent)
259 struct usb_hub *hub,
269 * device and the parent hub into U0. The exit latency is the bigger of
270 * the device exit latency or the hub exit latency.
278 * When the hub starts to receive the LFPS, there is a slight delay for
281 * delay, plus the PEL that we calculated for this hub.
335 struct usb_hub *hub;
349 hub = usb_hub_to_struct_hub(udev->parent);
353 if (!hub)
362 hub, &udev->parent->u1_params, hub_u1_del);
365 hub, &udev->parent->u2_params, hub_u2_del);
369 * when the parent hub notices the downstream port is trying to
370 * transition to U0 to when the hub initiates a U0 transition on its
374 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking
378 * assume the device exit latencies they are talking about are the hub
387 hub, &udev->parent->u1_params, hub_u1_del,
396 hub, &udev->parent->u2_params, hub_u2_del,
487 static void set_port_led(struct usb_hub *hub, int port1, int selector)
489 struct usb_port *port_dev = hub->ports[port1 - 1];
492 status = set_port_feature(hub->hdev, (selector << 8) | port1,
502 struct usb_hub *hub =
504 struct usb_device *hdev = hub->hdev;
509 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing)
517 switch (hub->indicator[i]) {
556 set_port_led(hub, i + 1, selector);
557 hub->indicator[i] = mode;
562 set_port_led(hub, cursor + 1, HUB_LED_GREEN);
563 hub->indicator[cursor] = INDICATOR_CYCLE;
568 &hub->leds, LED_CYCLE_PERIOD);
571 /* use a short timeout for hub/port status fetches */
610 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type,
619 mutex_lock(&hub->status_mutex);
620 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len);
623 dev_err(hub->intfdev,
628 *status = le16_to_cpu(hub->status->port.wPortStatus);
629 *change = le16_to_cpu(hub->status->port.wPortChange);
632 hub->status->port.dwExtPortStatus);
635 mutex_unlock(&hub->status_mutex);
639 int usb_hub_port_status(struct usb_hub *hub, int port1,
642 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS,
646 static void hub_resubmit_irq_urb(struct usb_hub *hub)
651 spin_lock_irqsave(&hub->irq_urb_lock, flags);
653 if (hub->quiescing) {
654 spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
658 status = usb_submit_urb(hub->urb, GFP_ATOMIC);
661 dev_err(hub->intfdev, "resubmit --> %d\n", status);
662 mod_timer(&hub->irq_urb_retry, jiffies + HZ);
665 spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
670 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry);
672 hub_resubmit_irq_urb(hub);
676 static void kick_hub_wq(struct usb_hub *hub)
680 if (hub->disconnected || work_pending(&hub->events))
688 * work for this hub. Therefore put the interface either when
691 intf = to_usb_interface(hub->intfdev);
693 hub_get(hub);
695 if (queue_work(hub_wq, &hub->events))
700 hub_put(hub);
705 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
707 if (hub)
708 kick_hub_wq(hub);
717 * resume through the normal hub interrupt URB.
722 struct usb_hub *hub;
728 hub = usb_hub_to_struct_hub(hdev);
729 if (hub) {
730 port_dev = hub->ports[portnum - 1];
734 set_bit(portnum, hub->wakeup_bits);
735 kick_hub_wq(hub);
743 struct usb_hub *hub = urb->context;
755 /* Cause a hub reset after 10 consecutive errors */
756 dev_dbg(hub->intfdev, "transfer --> %d\n", status);
757 if ((++hub->nerrors < 10) || hub->error)
759 hub->error = status;
766 bits |= ((unsigned long) ((*hub->buffer)[i]))
768 hub->event_bits[0] = bits;
772 hub->nerrors = 0;
775 kick_hub_wq(hub);
778 hub_resubmit_irq_urb(hub);
803 * both can talk to the same hub concurrently.
807 struct usb_hub *hub =
811 spin_lock_irqsave(&hub->tt.lock, flags);
812 while (!list_empty(&hub->tt.clear_list)) {
815 struct usb_device *hdev = hub->hdev;
819 next = hub->tt.clear_list.next;
824 spin_unlock_irqrestore(&hub->tt.lock, flags);
837 spin_lock_irqsave(&hub->tt.lock, flags);
839 spin_unlock_irqrestore(&hub->tt.lock, flags);
843 * usb_hub_set_port_power - control hub port's power state
844 * @hdev: USB device belonging to the usb hub
845 * @hub: target hub
854 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
868 set_bit(port1, hub->power_bits);
870 clear_bit(port1, hub->power_bits);
875 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
878 * High speed HCDs use this to tell the hub driver that some split control or
883 * It may not be possible for that hub to handle additional full (or low)
898 * there can be many TTs per hub). even if they're uncommon.
930 static void hub_power_on(struct usb_hub *hub, bool do_delay)
938 * unless we send these messages to the hub.
940 if (hub_is_port_power_switchable(hub))
941 dev_dbg(hub->intfdev, "enabling power on all ports\n");
943 dev_dbg(hub->intfdev, "trying to enable port power on "
944 "non-switchable hub\n");
945 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++)
946 if (test_bit(port1, hub->power_bits))
947 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER);
949 usb_clear_port_feature(hub->hdev, port1,
952 msleep(hub_power_on_good_delay(hub));
955 static int hub_hub_status(struct usb_hub *hub,
960 mutex_lock(&hub->status_mutex);
961 ret = get_hub_status(hub->hdev, &hub->status->hub);
964 dev_err(hub->intfdev,
967 *status = le16_to_cpu(hub->status->hub.wHubStatus);
968 *change = le16_to_cpu(hub->status->hub.wHubChange);
971 mutex_unlock(&hub->status_mutex);
975 static int hub_set_port_link_state(struct usb_hub *hub, int port1,
978 return set_port_feature(hub->hdev,
988 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
990 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n");
991 hub_port_disable(hub, port1, 1);
997 * That's easy if this hub can switch power per-port, and
1002 set_bit(port1, hub->change_bits);
1003 kick_hub_wq(hub);
1007 * usb_remove_device - disable a device's port on its parent hub
1020 struct usb_hub *hub;
1024 if (!udev->parent) /* Can't remove a root hub */
1026 hub = usb_hub_to_struct_hub(udev->parent);
1027 intf = to_usb_interface(hub->intfdev);
1033 set_bit(udev->portnum, hub->removed_bits);
1034 hub_port_logical_disconnect(hub, udev->portnum);
1047 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1049 struct usb_device *hdev = hub->hdev;
1061 /* Was the hub disconnected while we were waiting? */
1062 if (hub->disconnected)
1068 hub_get(hub);
1070 /* The superspeed hub except for root hub has to use Hub Depth
1072 * it uses to determine the downstream port number. So hub driver
1073 * should send a set hub depth request to superspeed hub after
1074 * the superspeed hub is set configuration in initialization or
1087 dev_err(hub->intfdev,
1088 "set hub depth failed\n");
1092 * hub's initial power-up delays. This is pretty awkward
1095 * root hub (assuming usbcore is compiled into the kernel
1104 delay = hub_power_on_good_delay(hub);
1106 hub_power_on(hub, false);
1107 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2);
1109 &hub->init_work,
1114 to_usb_interface(hub->intfdev));
1117 /* The internal host controller state for the hub device
1119 * Update the device's info so the HW knows it's a hub.
1124 &hub->tt, GFP_NOIO);
1126 dev_err(hub->intfdev,
1127 "Host not accepting hub info update\n");
1128 dev_err(hub->intfdev,
1129 "LS/FS devices and hubs may not work under this hub\n");
1132 hub_power_on(hub, true);
1134 hub_power_on(hub, true);
1137 } else if (hub_is_superspeed(hub->hdev))
1143 * Check each port and set hub->change_bits to let hub_wq know
1147 struct usb_port *port_dev = hub->ports[port1 - 1];
1152 status = usb_hub_port_status(hub, port1, &portstatus, &portchange);
1185 hub_port_warm_reset_required(hub, port1, portstatus))
1186 set_bit(port1, hub->event_bits);
1201 usb_clear_port_feature(hub->hdev, port1,
1206 usb_clear_port_feature(hub->hdev, port1,
1211 usb_clear_port_feature(hub->hdev, port1,
1215 hub_is_superspeed(hub->hdev)) {
1217 usb_clear_port_feature(hub->hdev, port1,
1225 clear_bit(port1, hub->removed_bits);
1238 set_bit(port1, hub->change_bits);
1252 if (portchange || (hub_is_superspeed(hub->hdev) &&
1254 set_bit(port1, hub->event_bits);
1263 if (test_bit(port1, hub->power_bits))
1264 set_bit(port1, hub->change_bits);
1269 set_bit(port1, hub->change_bits);
1286 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3);
1288 &hub->init_work,
1297 hub->quiescing = 0;
1299 status = usb_submit_urb(hub->urb, GFP_NOIO);
1301 dev_err(hub->intfdev, "activate --> %d\n", status);
1302 if (hub->has_indicators && blinkenlights)
1304 &hub->leds, LED_CYCLE_PERIOD);
1307 kick_hub_wq(hub);
1312 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1316 hub_put(hub);
1322 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1324 hub_activate(hub, HUB_INIT2);
1329 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1331 hub_activate(hub, HUB_INIT3);
1338 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
1340 struct usb_device *hdev = hub->hdev;
1345 spin_lock_irqsave(&hub->irq_urb_lock, flags);
1346 hub->quiescing = 1;
1347 spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
1352 if (hub->ports[i]->child)
1353 usb_disconnect(&hub->ports[i]->child);
1358 del_timer_sync(&hub->irq_urb_retry);
1359 usb_kill_urb(hub->urb);
1360 if (hub->has_indicators)
1361 cancel_delayed_work_sync(&hub->leds);
1362 if (hub->tt.hub)
1363 flush_work(&hub->tt.clear_work);
1366 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub)
1370 for (i = 0; i < hub->hdev->maxchild; ++i)
1371 pm_runtime_barrier(&hub->ports[i]->dev);
1374 /* caller has locked the hub device */
1377 struct usb_hub *hub = usb_get_intfdata(intf);
1379 hub_quiesce(hub, HUB_PRE_RESET);
1380 hub->in_reset = 1;
1381 hub_pm_barrier_for_all_ports(hub);
1385 /* caller has locked the hub device */
1388 struct usb_hub *hub = usb_get_intfdata(intf);
1390 hub->in_reset = 0;
1391 hub_pm_barrier_for_all_ports(hub);
1392 hub_activate(hub, HUB_POST_RESET);
1396 static int hub_configure(struct usb_hub *hub,
1400 struct usb_device *hdev = hub->hdev;
1401 struct device *hub_dev = hub->intfdev;
1411 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL);
1412 if (!hub->buffer) {
1417 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL);
1418 if (!hub->status) {
1422 mutex_init(&hub->status_mutex);
1424 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL);
1425 if (!hub->descriptor) {
1430 /* Request the entire hub descriptor.
1431 * hub->descriptor can handle USB_MAXCHILDREN ports,
1432 * but a (non-SS) hub can/will return fewer bytes here.
1434 ret = get_hub_descriptor(hdev, hub->descriptor);
1436 message = "can't read hub descriptor";
1444 if (hub->descriptor->bNbrPorts > maxchild) {
1445 message = "hub has too many ports!";
1448 } else if (hub->descriptor->bNbrPorts == 0) {
1449 message = "hub doesn't have any ports!";
1455 * Accumulate wHubDelay + 40ns for every hub in the tree of devices.
1459 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay);
1468 maxchild = hub->descriptor->bNbrPorts;
1472 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL);
1473 if (!hub->ports) {
1478 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
1493 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
1499 dev_dbg(hub_dev, "standalone hub\n");
1527 spin_lock_init(&hub->tt.lock);
1528 INIT_LIST_HEAD(&hub->tt.clear_list);
1529 INIT_WORK(&hub->tt.clear_work, hub_tt_work);
1535 hub->tt.hub = hdev;
1541 hub->tt.multi = 1;
1545 hub->tt.hub = hdev;
1551 dev_dbg(hub_dev, "Unrecognized hub protocol %d\n",
1560 hub->tt.think_time = 666;
1563 8, hub->tt.think_time);
1567 hub->tt.think_time = 666 * 2;
1570 16, hub->tt.think_time);
1573 hub->tt.think_time = 666 * 3;
1576 24, hub->tt.think_time);
1579 hub->tt.think_time = 666 * 4;
1582 32, hub->tt.think_time);
1586 /* probe() zeroes hub->indicator[] */
1588 hub->has_indicators = 1;
1593 hub->descriptor->bPwrOn2PwrGood * 2);
1600 message = "can't get hub status";
1610 hub->mA_per_port = full_load;
1612 hub->mA_per_port = hdev->bus_mA;
1613 hub->limited_power = 1;
1617 hub->descriptor->bHubContrCurrent;
1619 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",
1620 hub->descriptor->bHubContrCurrent);
1621 hub->limited_power = 1;
1627 hub->mA_per_port = unit_load; /* 7.2.1 */
1629 } else { /* Self-powered external hub */
1632 hub->mA_per_port = full_load;
1634 if (hub->mA_per_port < full_load)
1636 hub->mA_per_port);
1638 ret = hub_hub_status(hub, &hubstatus, &hubchange);
1640 message = "can't get hub status";
1663 if (maxp > sizeof(*hub->buffer))
1664 maxp = sizeof(*hub->buffer);
1666 hub->urb = usb_alloc_urb(0, GFP_KERNEL);
1667 if (!hub->urb) {
1672 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq,
1673 hub, endpoint->bInterval);
1675 /* maybe cycle the hub leds */
1676 if (hub->has_indicators && blinkenlights)
1677 hub->indicator[0] = INDICATOR_CYCLE;
1681 ret = usb_hub_create_port_device(hub, i + 1);
1683 dev_err(hub->intfdev,
1690 struct usb_port *port_dev = hub->ports[i];
1699 /* Update the HCD's internal representation of this hub before hub_wq
1700 * starts getting port status changes for devices under the hub.
1704 &hub->tt, GFP_KERNEL);
1706 message = "can't update HCD hub info";
1711 usb_hub_adjust_deviceremovable(hdev, hub->descriptor);
1713 hub_activate(hub, HUB_INIT);
1725 struct usb_hub *hub = container_of(kref, struct usb_hub, kref);
1727 usb_put_dev(hub->hdev);
1728 usb_put_intf(to_usb_interface(hub->intfdev));
1729 kfree(hub);
1732 void hub_get(struct usb_hub *hub)
1734 kref_get(&hub->kref);
1737 void hub_put(struct usb_hub *hub)
1739 kref_put(&hub->kref, hub_release);
1746 struct usb_hub *hub = usb_get_intfdata(intf);
1751 * Stop adding new hub events. We do not want to block here and thus
1754 hub->disconnected = 1;
1756 /* Disconnect all children and quiesce the hub */
1757 hub->error = 0;
1758 hub_quiesce(hub, HUB_DISCONNECT);
1770 usb_hub_remove_port_device(hub, port1);
1774 if (hub->hdev->speed == USB_SPEED_HIGH)
1777 usb_free_urb(hub->urb);
1778 kfree(hub->ports);
1779 kfree(hub->descriptor);
1780 kfree(hub->status);
1781 kfree(hub->buffer);
1785 if (hub->quirk_disable_autosuspend)
1788 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs);
1790 hub_put(hub);
1801 /* Multiple endpoints? What kind of mutant ninja-hub is this? */
1816 struct usb_hub *hub;
1825 * - Unlike other drivers, the hub driver does not rely on the
1828 * change on hub downstream ports, so it is safe to do it.
1831 * below very rare devices when they are plugged into hub
1842 * autosuspend delay of their parent hub in the probe() to one
1847 * hub during running 'lsusb', but it is probably too
1850 * - Change autosuspend delay of hub can avoid unnecessary auto
1851 * suspend timer for hub, also may decrease power consumption
1869 } else { /* root hub */
1878 "Unsupported bus topology: hub nested too deep\n");
1884 dev_warn(&intf->dev, "ignoring external hub\n");
1890 dev_err(&intf->dev, "bad descriptor, ignoring hub\n");
1894 /* We found a hub */
1895 dev_info(&intf->dev, "USB hub found\n");
1897 hub = kzalloc(sizeof(*hub), GFP_KERNEL);
1898 if (!hub)
1901 kref_init(&hub->kref);
1902 hub->intfdev = &intf->dev;
1903 hub->hdev = hdev;
1904 INIT_DELAYED_WORK(&hub->leds, led_work);
1905 INIT_DELAYED_WORK(&hub->init_work, NULL);
1906 INIT_WORK(&hub->events, hub_event);
1907 INIT_LIST_HEAD(&hub->onboard_hub_devs);
1908 spin_lock_init(&hub->irq_urb_lock);
1909 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0);
1913 usb_set_intfdata(intf, hub);
1921 hub->quirk_check_port_auto_suspend = 1;
1924 hub->quirk_disable_autosuspend = 1;
1936 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) {
1937 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs);
1950 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
1952 /* assert ifno == 0 (part of hub spec) */
1964 if (hub->ports[i]->child == NULL)
1968 hub->ports[i]->child->devnum;
1982 * Allow user programs to claim ports on a hub. When a device is attached
1988 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
1995 /* Devices not managed by the hub driver
1998 *ppowner = &(hub->ports[port1 - 1]->port_owner);
2037 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
2041 if (hub->ports[n]->port_owner == owner)
2042 hub->ports[n]->port_owner = NULL;
2050 struct usb_hub *hub;
2054 hub = usb_hub_to_struct_hub(udev->parent);
2055 return !!hub->ports[udev->portnum - 1]->port_owner;
2060 struct usb_hub *hub;
2064 hub = usb_hub_to_struct_hub(udev->parent);
2068 * has a test step to unbind the hub before running the
2070 * which will set the hub's maxchild to 0, further
2073 if (hub) {
2074 port_dev = hub->ports[udev->portnum - 1];
2083 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
2087 if (hub->ports[i]->child)
2088 recursively_mark_NOTATTACHED(hub->ports[i]->child);
2128 /* root hub wakeup capabilities are managed out-of-band
2177 /* be safe when more hub events are proceed in parallel */
2219 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
2224 if (hub->ports[i]->child)
2225 usb_disconnect(&hub->ports[i]->child);
2237 * If *pdev is a normal device then the parent hub must already be locked.
2238 * If *pdev is a root hub then the caller must hold the usb_bus_idr_lock,
2241 * Only hub drivers (including virtual root hub drivers for host
2250 struct usb_hub *hub = NULL;
2281 hub = usb_hub_to_struct_hub(udev->parent);
2282 port_dev = hub->ports[port1 - 1];
2291 if (!test_and_set_bit(port1, hub->child_usage_bits))
2314 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits))
2494 struct usb_hub *hub;
2504 hub = usb_hub_to_struct_hub(udev->parent);
2510 switch (hub->ports[udev->portnum - 1]->connect_type) {
2523 * Otherwise, check whether the hub knows whether a port is removable
2526 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
2532 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable)
2536 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8)))
2554 * the parent hub (if udev is a normal device) or else the
2555 * usb_bus_idr_lock (if udev is a root hub). The parent's pointer to
2561 * Only the hub driver or root-hub registrar should ever call this.
2573 /* Initialize non-root-hub device wakeup to disabled;
2614 /* check whether the hub or firmware marks this port as non-removable */
2629 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
2631 struct usb_port *port_dev = hub->ports[port1 - 1];
2645 if (!test_and_set_bit(port1, hub->child_usage_bits))
2731 * @hdev: The hub device
2861 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
2866 if (!hub_is_superspeed(hub->hdev))
2869 if (test_bit(port1, hub->warm_reset_bits))
2877 static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2892 if (hub_is_superspeedplus(hub->hdev))
2893 ret = hub_ext_port_status(hub, port1,
2898 ret = usb_hub_port_status(hub, port1, &portstatus,
2918 dev_dbg(&hub->ports[port1 - 1]->dev,
2926 if (hub_port_warm_reset_required(hub, port1, portstatus))
2937 if (!hub_is_superspeed(hub->hdev) &&
2939 usb_clear_port_feature(hub->hdev, port1,
2950 if (hub_is_superspeedplus(hub->hdev)) {
2954 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus);
2962 else if (hub_is_superspeed(hub->hdev))
2974 static int hub_port_reset(struct usb_hub *hub, int port1,
2979 struct usb_port *port_dev = hub->ports[port1 - 1];
2982 if (!hub_is_superspeed(hub->hdev)) {
2984 dev_err(hub->intfdev, "only USB3 hub support "
2997 if (usb_hub_port_status(hub, port1, &portstatus,
2999 if (hub_port_warm_reset_required(hub, port1,
3003 clear_bit(port1, hub->warm_reset_bits);
3007 status = set_port_feature(hub->hdev, port1, (warm ?
3011 ; /* The hub is gone */
3017 status = hub_port_wait_reset(hub, port1, udev, delay,
3020 dev_dbg(hub->intfdev,
3031 usb_clear_port_feature(hub->hdev, port1,
3034 if (!hub_is_superspeed(hub->hdev))
3037 usb_clear_port_feature(hub->hdev, port1,
3039 usb_clear_port_feature(hub->hdev, port1,
3043 usb_clear_port_feature(hub->hdev, port1,
3050 if (usb_hub_port_status(hub, port1,
3054 if (!hub_port_warm_reset_required(hub, port1,
3085 /* Hub needs extra delay after resetting its port. */
3086 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET)
3109 if (!hub_is_superspeed(hub->hdev))
3117 * @hub: target hub
3133 static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries)
3135 struct usb_port *port_dev = hub->ports[port1 - 1];
3158 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
3162 if (hub_is_superspeed(hub->hdev)) {
3190 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus)
3194 if (hub_is_superspeed(hub->hdev)) {
3210 struct usb_hub *hub, int port1,
3213 struct usb_port *port_dev = hub->ports[port1 - 1];
3219 && hub_port_warm_reset_required(hub, port1, portstatus)) {
3223 else if (status || port_is_suspended(hub, portstatus) ||
3224 !usb_port_is_power_on(hub, portstatus)) {
3230 status = usb_hub_port_status(hub, port1, &portstatus,
3254 usb_clear_port_feature(hub->hdev, port1,
3257 usb_clear_port_feature(hub->hdev, port1,
3262 * turned on the port1 bit in hub->change_bits. But after
3267 clear_bit(port1, hub->change_bits);
3370 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
3373 (hub ? hub->wakeup_enabled_descendants : 0);
3379 * @udev: device that's no longer in active use, not a root hub
3404 * Devices on USB hub ports have only one "suspend" state, corresponding
3413 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3419 * hub is suspended). Nevertheless, we change @udev->state to
3427 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3428 struct usb_port *port_dev = hub->ports[udev->portnum - 1];
3436 * wake up the upstream hub (including maybe the root hub).
3463 if (hub_is_superspeed(hub->hdev))
3464 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3);
3469 * into suspend a few ms after the root hub stops sending packets.
3478 status = set_port_feature(hub->hdev, port1,
3493 ret = usb_hub_port_status(hub, port1, &portstatus,
3499 if (ret == 0 && port_is_suspended(hub, portstatus)) {
3535 && test_and_clear_bit(port1, hub->child_usage_bits))
3538 usb_mark_last_busy(hub->hdev);
3663 struct usb_hub *hub, int port1,
3671 if (!usb_port_is_power_on(hub, *portstatus)) {
3677 status = usb_hub_port_status(hub, port1, portstatus, portchange);
3685 * @udev: device to re-activate, not a root hub
3719 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3720 struct usb_port *port_dev = hub->ports[udev->portnum - 1];
3725 if (!test_and_set_bit(port1, hub->child_usage_bits)) {
3737 status = usb_hub_port_status(hub, port1, &portstatus, &portchange);
3738 if (status == 0 && !port_is_suspended(hub, portstatus)) {
3745 if (hub_is_superspeed(hub->hdev))
3746 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0);
3748 status = usb_clear_port_feature(hub->hdev,
3762 status = usb_hub_port_status(hub, port1, &portstatus, &portchange);
3768 if (hub_is_superspeed(hub->hdev)) {
3770 usb_clear_port_feature(hub->hdev, port1,
3774 usb_clear_port_feature(hub->hdev, port1,
3783 status = wait_for_connected(udev, hub, port1, &portchange,
3787 hub, port1, status, portchange, portstatus);
3792 hub_port_logical_disconnect(hub, port1);
3824 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
3828 struct usb_port *port_dev = hub->ports[port - 1];
3835 hdev = hub->hdev;
3861 hub_port_disable(hub, port, 1);
3867 static int check_ports_changed(struct usb_hub *hub)
3871 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) {
3875 status = usb_hub_port_status(hub, port1, &portstatus, &portchange);
3884 struct usb_hub *hub = usb_get_intfdata(intf);
3885 struct usb_device *hdev = hub->hdev;
3892 hub->wakeup_enabled_descendants = 0;
3894 struct usb_port *port_dev = hub->ports[port1 - 1];
3904 hub->wakeup_enabled_descendants +=
3908 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) {
3909 /* check if there are changes pending on hub ports */
3910 if (check_ports_changed(hub)) {
3918 /* Enable hub to send remote wakeup for all ports. */
3932 hub_quiesce(hub, HUB_SUSPEND);
3936 /* Report wakeup requests from the ports of a resuming root hub */
3937 static void report_wakeup_requests(struct usb_hub *hub)
3939 struct usb_device *hdev = hub->hdev;
3946 return; /* Not a root hub */
3962 udev = hub->ports[i]->child;
3972 struct usb_hub *hub = usb_get_intfdata(intf);
3975 hub_activate(hub, HUB_RESUME);
3983 report_wakeup_requests(hub);
3989 struct usb_hub *hub = usb_get_intfdata(intf);
3992 hub_activate(hub, HUB_RESET_RESUME);
3997 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3998 * @rhdev: struct usb_device for the root hub
4000 * The USB host controller driver calls this function when its root hub
4003 * When the hub driver is resumed it will take notice and carry out
4009 dev_notice(&rhdev->dev, "root hub lost power or was reset\n");
4238 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4242 * control transfers to set the hub timeout or enable device-initiated U1/U2
4246 * hub-initiated U1/U2 will be disabled.
4248 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
4293 /* If we can't set the parent hub U1/U2 timeout,
4323 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4326 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4330 * it won't have an effect on the bus link state because the parent hub will
4360 /* As soon as usb_set_lpm_timeout(0) return 0, hub initiated LPM
4361 * is disabled. Hub will disallows link to enter U1/U2 as well,
4362 * even device is initiating LPM. Hence LPM is disabled if hub LPM
4375 * Disable hub-initiated and device-initiated U1 and U2 entry.
4431 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4441 struct usb_hub *hub;
4462 hub = usb_hub_to_struct_hub(udev->parent);
4463 if (!hub)
4466 port_dev = hub->ports[udev->portnum - 1];
4491 static void hub_usb3_port_prepare_disable(struct usb_hub *hub,
4498 ret = hub_set_port_link_state(hub, port_dev->portnum,
4517 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub,
4547 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
4565 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
4567 struct usb_port *port_dev = hub->ports[port1 - 1];
4568 struct usb_device *hdev = hub->hdev;
4571 if (!hub->error) {
4572 if (hub_is_superspeed(hub->hdev)) {
4573 hub_usb3_port_prepare_disable(hub, port_dev);
4574 ret = hub_set_port_link_state(hub, port_dev->portnum,
4597 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
4599 return hub_port_disable(hub, udev->portnum, 0);
4617 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected)
4623 struct usb_port *port_dev = hub->ports[port1 - 1];
4626 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange);
4643 usb_clear_port_feature(hub->hdev, port1,
4676 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
4678 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT)
4717 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
4723 if (hub)
4724 connect_type = hub->ports[udev->portnum - 1]->connect_type;
4826 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
4829 struct usb_device *hdev = hub->hdev;
4831 struct usb_port *port_dev = hub->ports[port1 - 1];
4847 /* root hub ports have a slightly longer reset period
4863 retval = hub_port_reset(hub, port1, udev, delay, false);
4932 if (!hub->tt.hub) {
4933 dev_err(&udev->dev, "parent hub has no TT\n");
4937 udev->tt = &hub->tt;
4957 if (hub_port_stop_enumerate(hub, port1, retries)) {
4966 "hub failed to enable device, error %d\n",
4980 retval = hub_port_reset(hub, port1, udev, delay, false);
5116 * and attached to a superspeed hub port, but the device descriptor
5123 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true);
5147 hub_port_disable(hub, port1, 0);
5155 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1)
5171 "connect to a high speed hub\n");
5172 /* hub LEDs are probably harder to miss than syslog */
5173 if (hub->has_indicators) {
5174 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK;
5176 &hub->leds, 0);
5183 hub_power_remaining(struct usb_hub *hub)
5185 struct usb_device *hdev = hub->hdev;
5189 if (!hub->limited_power)
5192 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent;
5194 struct usb_port *port_dev = hub->ports[port1 - 1];
5216 if (delta > hub->mA_per_port)
5218 delta, hub->mA_per_port);
5222 dev_warn(hub->intfdev, "%dmA over power budget!\n",
5314 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
5320 struct usb_device *hdev = hub->hdev;
5322 struct usb_port *port_dev = hub->ports[port1 - 1];
5339 clear_bit(port1, hub->removed_bits);
5343 status = hub_port_debounce_be_stable(hub, port1);
5360 test_bit(port1, hub->removed_bits)) {
5363 * maybe switch power back on (e.g. root hub was reset)
5366 if (hub_is_port_power_switchable(hub)
5367 && !usb_port_is_power_on(hub, portstatus)
5375 if (hub_is_superspeed(hub->hdev))
5383 if (hub_port_stop_enumerate(hub, port1, i)) {
5404 udev->bus_mA = hub->mA_per_port;
5408 if (hub_is_superspeed(hub->hdev))
5420 status = hub_port_init(hub, udev, port1, i, NULL);
5449 "can't connect bus-powered hub "
5451 if (hub->has_indicators) {
5452 hub->indicator[port1-1] =
5456 &hub->leds, 0);
5467 check_highspeed(hub, udev, port1);
5477 /* We mustn't add new devices if the parent hub has
5508 status = hub_power_remaining(hub);
5510 dev_dbg(hub->intfdev, "%dmA power budget left\n", status);
5515 hub_port_disable(hub, port1, 1);
5531 usb_hub_set_port_power(hdev, hub, port1, false);
5532 msleep(2 * hub_power_on_good_delay(hub));
5533 usb_hub_set_port_power(hdev, hub, port1, true);
5534 msleep(hub_power_on_good_delay(hub));
5537 if (hub->hdev->parent ||
5546 hub_port_disable(hub, port1, 1);
5547 if (hcd->driver->relinquish_port && !hub->hdev->parent) {
5559 * caller already locked the hub
5561 static void hub_port_connect_change(struct usb_hub *hub, int port1,
5565 struct usb_port *port_dev = hub->ports[port1 - 1];
5571 portchange, portspeed(hub, portstatus));
5573 if (hub->has_indicators) {
5574 set_port_led(hub, port1, HUB_LED_AUTO);
5575 hub->indicator[port1-1] = INDICATOR_AUTO;
5580 if (hub->hdev->bus->is_b_host)
5624 clear_bit(port1, hub->change_bits);
5631 hub_port_connect(hub, port1, portstatus, portchange);
5635 /* Handle notifying userspace about hub over-current events */
5670 static void port_event(struct usb_hub *hub, int port1)
5674 struct usb_port *port_dev = hub->ports[port1 - 1];
5676 struct usb_device *hdev = hub->hdev;
5680 connect_change = test_bit(port1, hub->change_bits);
5681 clear_bit(port1, hub->event_bits);
5682 clear_bit(port1, hub->wakeup_bits);
5684 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0)
5700 * to be shutdown by the hub, this hack enables them again.
5705 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n");
5720 hub_power_on(hub, true);
5721 usb_hub_port_status(hub, port1, &status, &unused);
5755 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange))
5764 while (hub_port_warm_reset_required(hub, port1, portstatus)) {
5769 usb_hub_port_status(hub, port1, &portstatus, &unused);
5775 if (hub_port_reset(hub, port1, NULL,
5777 hub_port_disable(hub, port1, 1);
5791 hub_port_connect_change(hub, port1, portstatus, portchange);
5798 struct usb_hub *hub;
5804 hub = container_of(work, struct usb_hub, events);
5805 hdev = hub->hdev;
5806 hub_dev = hub->intfdev;
5814 (u16) hub->change_bits[0],
5815 (u16) hub->event_bits[0]);
5820 if (unlikely(hub->disconnected))
5823 /* If the hub has died, clean up after it */
5825 hub->error = -ENODEV;
5826 hub_quiesce(hub, HUB_DISCONNECT);
5837 /* If this is an inactive hub, do nothing */
5838 if (hub->quiescing)
5841 if (hub->error) {
5842 dev_dbg(hub_dev, "resetting for error %d\n", hub->error);
5846 dev_dbg(hub_dev, "error resetting hub: %d\n", ret);
5850 hub->nerrors = 0;
5851 hub->error = 0;
5856 struct usb_port *port_dev = hub->ports[i - 1];
5858 if (test_bit(i, hub->event_bits)
5859 || test_bit(i, hub->change_bits)
5860 || test_bit(i, hub->wakeup_bits)) {
5873 port_event(hub, i);
5879 /* deal with hub status changes */
5880 if (test_and_clear_bit(0, hub->event_bits) == 0)
5882 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0)
5890 hub->limited_power = 1;
5892 hub->limited_power = 0;
5901 hub_power_on(hub, true);
5902 hub_hub_status(hub, &status, &unused);
5916 hub_put(hub);
5974 .name = "hub",
5990 printk(KERN_ERR "%s: can't register hub driver\n",
6007 pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name);
6017 * Hub resources are freed for us by usb_deregister. It calls
6021 * individual hub resources. -greg
6231 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
6241 dev_dbg(&udev->dev, "%s for root hub!\n", __func__);
6249 port_dev = hub->ports[udev->portnum - 1];
6357 * @hdev: USB device belonging to the usb hub
6361 * USB drivers call this function to get hub's child device
6370 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
6374 return hub->ports[port1 - 1]->child;
6381 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
6385 if (!hub)
6390 struct usb_port *port_dev = hub->ports[i - 1];
6406 struct usb_port *port_dev = hub->ports[i - 1];
6426 * @hdev: USB device belonging to the usb hub
6435 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
6437 if (!hub)
6440 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev);