Lines Matching defs:hub

2  * USB hub driver.
33 #include "hub.h"
44 /* workqueue to process hub events */
48 /* synchronize hub-port add/remove and peering operations */
76 * hub driver's behavior. On the first initialization attempt, if the
105 static inline char *portspeed(struct usb_hub *hub, int portstatus)
107 if (hub_is_superspeed(hub->hdev))
169 struct usb_hub *hub,
179 * to the parent hub into U0. The parent hub must then decode the
180 * packet (hub header decode latency) to figure out which port it was
187 (hub->descriptor->u.ss.bHubHdrDecLat * 100);
190 * How long will it take to transition the downstream hub's port into
191 * U0? The greater of either the hub exit latency or the device exit
214 struct usb_hub *hub,
224 * device and the parent hub into U0. The exit latency is the bigger of
225 * the device exit latency or the hub exit latency.
233 * When the hub starts to receive the LFPS, there is a slight delay for
236 * delay, plus the PEL that we calculated for this hub.
290 struct usb_hub *hub;
300 hub = usb_hub_to_struct_hub(udev->parent);
304 if (!hub)
313 hub, &udev->parent->u1_params, hub_u1_del);
316 hub, &udev->parent->u2_params, hub_u2_del);
320 * when the parent hub notices the downstream port is trying to
321 * transition to U0 to when the hub initiates a U0 transition on its
325 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking
329 * assume the device exit latencies they are talking about are the hub
338 hub, &udev->parent->u1_params, hub_u1_del,
347 hub, &udev->parent->u2_params, hub_u2_del,
429 static void set_port_led(struct usb_hub *hub, int port1, int selector)
431 struct usb_port *port_dev = hub->ports[port1 - 1];
434 status = set_port_feature(hub->hdev, (selector << 8) | port1,
444 struct usb_hub *hub =
446 struct usb_device *hdev = hub->hdev;
451 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing)
459 switch (hub->indicator[i]) {
498 set_port_led(hub, i + 1, selector);
499 hub->indicator[i] = mode;
504 set_port_led(hub, cursor + 1, HUB_LED_GREEN);
505 hub->indicator[cursor] = INDICATOR_CYCLE;
510 &hub->leds, LED_CYCLE_PERIOD);
513 /* use a short timeout for hub/port status fetches */
551 static int hub_port_status(struct usb_hub *hub, int port1,
556 mutex_lock(&hub->status_mutex);
557 ret = get_port_status(hub->hdev, port1, &hub->status->port);
560 dev_err(hub->intfdev,
565 *status = le16_to_cpu(hub->status->port.wPortStatus);
566 *change = le16_to_cpu(hub->status->port.wPortChange);
570 mutex_unlock(&hub->status_mutex);
574 static void kick_hub_wq(struct usb_hub *hub)
578 if (hub->disconnected || work_pending(&hub->events))
586 * work for this hub. Therefore put the interface either when
589 intf = to_usb_interface(hub->intfdev);
591 kref_get(&hub->kref);
593 if (queue_work(hub_wq, &hub->events))
598 kref_put(&hub->kref, hub_release);
603 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
605 if (hub)
606 kick_hub_wq(hub);
615 * resume through the normal hub interrupt URB.
620 struct usb_hub *hub;
625 hub = usb_hub_to_struct_hub(hdev);
626 if (hub) {
627 set_bit(portnum, hub->wakeup_bits);
628 kick_hub_wq(hub);
636 struct usb_hub *hub = urb->context;
648 /* Cause a hub reset after 10 consecutive errors */
649 dev_dbg (hub->intfdev, "transfer --> %d\n", status);
650 if ((++hub->nerrors < 10) || hub->error)
652 hub->error = status;
659 bits |= ((unsigned long) ((*hub->buffer)[i]))
661 hub->event_bits[0] = bits;
665 hub->nerrors = 0;
668 kick_hub_wq(hub);
671 if (hub->quiescing)
674 if ((status = usb_submit_urb (hub->urb, GFP_ATOMIC)) != 0
676 dev_err (hub->intfdev, "resubmit --> %d\n", status);
701 * both can talk to the same hub concurrently.
705 struct usb_hub *hub =
709 spin_lock_irqsave (&hub->tt.lock, flags);
710 while (!list_empty(&hub->tt.clear_list)) {
713 struct usb_device *hdev = hub->hdev;
717 next = hub->tt.clear_list.next;
722 spin_unlock_irqrestore (&hub->tt.lock, flags);
735 spin_lock_irqsave(&hub->tt.lock, flags);
737 spin_unlock_irqrestore (&hub->tt.lock, flags);
741 * usb_hub_set_port_power - control hub port's power state
742 * @hdev: USB device belonging to the usb hub
743 * @hub: target hub
752 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
766 set_bit(port1, hub->power_bits);
768 clear_bit(port1, hub->power_bits);
773 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
776 * High speed HCDs use this to tell the hub driver that some split control or
781 * It may not be possible for that hub to handle additional full (or low)
796 * there can be many TTs per hub). even if they're uncommon.
827 static void hub_power_on(struct usb_hub *hub, bool do_delay)
835 * unless we send these messages to the hub.
837 if (hub_is_port_power_switchable(hub))
838 dev_dbg(hub->intfdev, "enabling power on all ports\n");
840 dev_dbg(hub->intfdev, "trying to enable port power on "
841 "non-switchable hub\n");
842 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++)
843 if (test_bit(port1, hub->power_bits))
844 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER);
846 usb_clear_port_feature(hub->hdev, port1,
849 msleep(hub_power_on_good_delay(hub));
852 static int hub_hub_status(struct usb_hub *hub,
857 mutex_lock(&hub->status_mutex);
858 ret = get_hub_status(hub->hdev, &hub->status->hub);
861 dev_err(hub->intfdev,
864 *status = le16_to_cpu(hub->status->hub.wHubStatus);
865 *change = le16_to_cpu(hub->status->hub.wHubChange);
868 mutex_unlock(&hub->status_mutex);
872 static int hub_set_port_link_state(struct usb_hub *hub, int port1,
875 return set_port_feature(hub->hdev,
890 static int hub_usb3_port_disable(struct usb_hub *hub, int port1)
896 if (!hub_is_superspeed(hub->hdev))
899 ret = hub_port_status(hub, port1, &portstatus, &portchange);
906 * usb 3.0 device hotplugging route to the 2.0 root hub and recognized
913 dev_dbg(&hub->ports[port1 - 1]->dev,
918 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED);
924 ret = hub_port_status(hub, port1, &portstatus, &portchange);
936 dev_warn(&hub->ports[port1 - 1]->dev,
939 return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT);
942 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
944 struct usb_port *port_dev = hub->ports[port1 - 1];
945 struct usb_device *hdev = hub->hdev;
950 if (!hub->error) {
951 if (hub_is_superspeed(hub->hdev))
952 ret = hub_usb3_port_disable(hub, port1);
967 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
969 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n");
970 hub_port_disable(hub, port1, 1);
976 * That's easy if this hub can switch power per-port, and
981 set_bit(port1, hub->change_bits);
982 kick_hub_wq(hub);
986 * usb_remove_device - disable a device's port on its parent hub
999 struct usb_hub *hub;
1002 if (!udev->parent) /* Can't remove a root hub */
1004 hub = usb_hub_to_struct_hub(udev->parent);
1005 intf = to_usb_interface(hub->intfdev);
1008 set_bit(udev->portnum, hub->removed_bits);
1009 hub_port_logical_disconnect(hub, udev->portnum);
1022 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1024 struct usb_device *hdev = hub->hdev;
1038 /* The superspeed hub except for root hub has to use Hub Depth
1040 * it uses to determine the downstream port number. So hub driver
1041 * should send a set hub depth request to superspeed hub after
1042 * the superspeed hub is set configuration in initialization or
1055 dev_err(hub->intfdev,
1056 "set hub depth failed\n");
1060 * hub's initial power-up delays. This is pretty awkward
1063 * root hub (assuming usbcore is compiled into the kernel
1072 unsigned delay = hub_power_on_good_delay(hub);
1074 hub_power_on(hub, false);
1075 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2);
1077 &hub->init_work,
1082 to_usb_interface(hub->intfdev));
1085 /* The internal host controller state for the hub device
1087 * Update the device's info so the HW knows it's a hub.
1092 &hub->tt, GFP_NOIO);
1094 dev_err(hub->intfdev, "Host not "
1095 "accepting hub info "
1097 dev_err(hub->intfdev, "LS/FS devices "
1099 "under this hub\n.");
1102 hub_power_on(hub, true);
1104 hub_power_on(hub, true);
1110 * Check each port and set hub->change_bits to let hub_wq know
1114 struct usb_port *port_dev = hub->ports[port1 - 1];
1119 status = hub_port_status(hub, port1, &portstatus, &portchange);
1150 usb_clear_port_feature(hub->hdev, port1,
1155 usb_clear_port_feature(hub->hdev, port1,
1160 usb_clear_port_feature(hub->hdev, port1,
1164 hub_is_superspeed(hub->hdev)) {
1166 usb_clear_port_feature(hub->hdev, port1,
1174 clear_bit(port1, hub->removed_bits);
1182 set_bit(port1, hub->change_bits);
1196 if (portchange || (hub_is_superspeed(hub->hdev) &&
1198 set_bit(port1, hub->change_bits);
1207 if (test_bit(port1, hub->power_bits))
1208 set_bit(port1, hub->change_bits);
1213 set_bit(port1, hub->change_bits);
1230 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3);
1232 &hub->init_work,
1240 hub->quiescing = 0;
1242 status = usb_submit_urb(hub->urb, GFP_NOIO);
1244 dev_err(hub->intfdev, "activate --> %d\n", status);
1245 if (hub->has_indicators && blinkenlights)
1247 &hub->leds, LED_CYCLE_PERIOD);
1250 kick_hub_wq(hub);
1254 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1260 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1262 hub_activate(hub, HUB_INIT2);
1267 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1269 hub_activate(hub, HUB_INIT3);
1276 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
1278 struct usb_device *hdev = hub->hdev;
1281 cancel_delayed_work_sync(&hub->init_work);
1284 hub->quiescing = 1;
1289 if (hub->ports[i]->child)
1290 usb_disconnect(&hub->ports[i]->child);
1295 usb_kill_urb(hub->urb);
1296 if (hub->has_indicators)
1297 cancel_delayed_work_sync(&hub->leds);
1298 if (hub->tt.hub)
1299 flush_work(&hub->tt.clear_work);
1302 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub)
1306 for (i = 0; i < hub->hdev->maxchild; ++i)
1307 pm_runtime_barrier(&hub->ports[i]->dev);
1310 /* caller has locked the hub device */
1313 struct usb_hub *hub = usb_get_intfdata(intf);
1315 hub_quiesce(hub, HUB_PRE_RESET);
1316 hub->in_reset = 1;
1317 hub_pm_barrier_for_all_ports(hub);
1321 /* caller has locked the hub device */
1324 struct usb_hub *hub = usb_get_intfdata(intf);
1326 hub->in_reset = 0;
1327 hub_pm_barrier_for_all_ports(hub);
1328 hub_activate(hub, HUB_POST_RESET);
1332 static int hub_configure(struct usb_hub *hub,
1336 struct usb_device *hdev = hub->hdev;
1337 struct device *hub_dev = hub->intfdev;
1347 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL);
1348 if (!hub->buffer) {
1353 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL);
1354 if (!hub->status) {
1358 mutex_init(&hub->status_mutex);
1360 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
1361 if (!hub->descriptor) {
1366 /* Request the entire hub descriptor.
1367 * hub->descriptor can handle USB_MAXCHILDREN ports,
1368 * but the hub can/will return fewer bytes here.
1370 ret = get_hub_descriptor(hdev, hub->descriptor);
1372 message = "can't read hub descriptor";
1374 } else if (hub->descriptor->bNbrPorts > USB_MAXCHILDREN) {
1375 message = "hub has too many ports!";
1378 } else if (hub->descriptor->bNbrPorts == 0) {
1379 message = "hub doesn't have any ports!";
1384 maxchild = hub->descriptor->bNbrPorts;
1388 hub->ports = kzalloc(maxchild * sizeof(struct usb_port *), GFP_KERNEL);
1389 if (!hub->ports) {
1394 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
1410 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
1416 dev_dbg(hub_dev, "standalone hub\n");
1444 spin_lock_init (&hub->tt.lock);
1445 INIT_LIST_HEAD (&hub->tt.clear_list);
1446 INIT_WORK(&hub->tt.clear_work, hub_tt_work);
1452 hub->tt.hub = hdev;
1458 hub->tt.multi = 1;
1462 hub->tt.hub = hdev;
1468 dev_dbg(hub_dev, "Unrecognized hub protocol %d\n",
1477 hub->tt.think_time = 666;
1480 8, hub->tt.think_time);
1484 hub->tt.think_time = 666 * 2;
1487 16, hub->tt.think_time);
1490 hub->tt.think_time = 666 * 3;
1493 24, hub->tt.think_time);
1496 hub->tt.think_time = 666 * 4;
1499 32, hub->tt.think_time);
1503 /* probe() zeroes hub->indicator[] */
1505 hub->has_indicators = 1;
1510 hub->descriptor->bPwrOn2PwrGood * 2);
1517 message = "can't get hub status";
1527 hub->mA_per_port = full_load;
1529 hub->mA_per_port = hdev->bus_mA;
1530 hub->limited_power = 1;
1534 hub->descriptor->bHubContrCurrent;
1536 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",
1537 hub->descriptor->bHubContrCurrent);
1538 hub->limited_power = 1;
1544 hub->mA_per_port = unit_load; /* 7.2.1 */
1546 } else { /* Self-powered external hub */
1549 hub->mA_per_port = full_load;
1551 if (hub->mA_per_port < full_load)
1553 hub->mA_per_port);
1555 ret = hub_hub_status(hub, &hubstatus, &hubchange);
1557 message = "can't get hub status";
1580 if (maxp > sizeof(*hub->buffer))
1581 maxp = sizeof(*hub->buffer);
1583 hub->urb = usb_alloc_urb(0, GFP_KERNEL);
1584 if (!hub->urb) {
1589 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq,
1590 hub, endpoint->bInterval);
1592 /* maybe cycle the hub leds */
1593 if (hub->has_indicators && blinkenlights)
1594 hub->indicator[0] = INDICATOR_CYCLE;
1598 ret = usb_hub_create_port_device(hub, i + 1);
1600 dev_err(hub->intfdev,
1607 struct usb_port *port_dev = hub->ports[i];
1616 /* Update the HCD's internal representation of this hub before hub_wq
1617 * starts getting port status changes for devices under the hub.
1621 &hub->tt, GFP_KERNEL);
1623 message = "can't update HCD hub info";
1628 usb_hub_adjust_deviceremovable(hdev, hub->descriptor);
1630 hub_activate(hub, HUB_INIT);
1642 struct usb_hub *hub = container_of(kref, struct usb_hub, kref);
1644 usb_put_dev(hub->hdev);
1645 usb_put_intf(to_usb_interface(hub->intfdev));
1646 kfree(hub);
1653 struct usb_hub *hub = usb_get_intfdata(intf);
1658 * Stop adding new hub events. We do not want to block here and thus
1661 hub->disconnected = 1;
1663 /* Disconnect all children and quiesce the hub */
1664 hub->error = 0;
1665 hub_quiesce(hub, HUB_DISCONNECT);
1677 usb_hub_remove_port_device(hub, port1);
1681 if (hub->hdev->speed == USB_SPEED_HIGH)
1684 usb_free_urb(hub->urb);
1685 kfree(hub->ports);
1686 kfree(hub->descriptor);
1687 kfree(hub->status);
1688 kfree(hub->buffer);
1691 kref_put(&hub->kref, hub_release);
1699 struct usb_hub *hub;
1708 * - Unlike other drivers, the hub driver does not rely on the
1711 * change on hub downstream ports, so it is safe to do it.
1714 * below very rare devices when they are plugged into hub
1725 * autosuspend delay of their parent hub in the probe() to one
1730 * hub during running 'lsusb', but it is probably too
1733 * - Change autosuspend delay of hub can avoid unnecessary auto
1734 * suspend timer for hub, also may decrease power consumption
1752 } else { /* root hub */
1761 "Unsupported bus topology: hub nested too deep\n");
1767 dev_warn(&intf->dev, "ignoring external hub\n");
1777 dev_err (&intf->dev, "bad descriptor, ignoring hub\n");
1781 /* Multiple endpoints? What kind of mutant ninja-hub is this? */
1791 /* We found a hub */
1792 dev_info (&intf->dev, "USB hub found\n");
1794 hub = kzalloc(sizeof(*hub), GFP_KERNEL);
1795 if (!hub) {
1796 dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n");
1800 kref_init(&hub->kref);
1801 hub->intfdev = &intf->dev;
1802 hub->hdev = hdev;
1803 INIT_DELAYED_WORK(&hub->leds, led_work);
1804 INIT_DELAYED_WORK(&hub->init_work, NULL);
1805 INIT_WORK(&hub->events, hub_event);
1809 usb_set_intfdata (intf, hub);
1817 hub->quirk_check_port_auto_suspend = 1;
1819 if (hub_configure(hub, endpoint) >= 0)
1830 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
1832 /* assert ifno == 0 (part of hub spec) */
1844 if (hub->ports[i]->child == NULL)
1848 hub->ports[i]->child->devnum;
1862 * Allow user programs to claim ports on a hub. When a device is attached
1868 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
1875 /* Devices not managed by the hub driver
1878 *ppowner = &(hub->ports[port1 - 1]->port_owner);
1917 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
1921 if (hub->ports[n]->port_owner == owner)
1922 hub->ports[n]->port_owner = NULL;
1930 struct usb_hub *hub;
1934 hub = usb_hub_to_struct_hub(udev->parent);
1935 return !!hub->ports[udev->portnum - 1]->port_owner;
1940 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
1944 if (hub->ports[i]->child)
1945 recursively_mark_NOTATTACHED(hub->ports[i]->child);
1984 /* root hub wakeup capabilities are managed out-of-band
2035 * uses always #1 for the root hub of the controller. So USB stack's
2048 /* be safe when more hub events are proceed in parallel */
2096 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
2101 if (hub->ports[i]->child)
2102 usb_disconnect(&hub->ports[i]->child);
2113 * If *pdev is a normal device then the parent hub must already be locked.
2114 * If *pdev is a root hub then the caller must hold the usb_bus_list_lock,
2117 * Only hub drivers (including virtual root hub drivers for host
2126 struct usb_hub *hub = NULL;
2151 hub = usb_hub_to_struct_hub(udev->parent);
2152 port_dev = hub->ports[port1 - 1];
2161 if (!test_and_set_bit(port1, hub->child_usage_bits))
2184 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits))
2343 struct usb_hub *hub;
2351 hub = usb_hub_to_struct_hub(udev->parent);
2353 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
2359 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable)
2363 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8)))
2377 switch (hub->ports[udev->portnum - 1]->connect_type) {
2396 * the parent hub (if udev is a normal device) or else the
2397 * usb_bus_list_lock (if udev is a root hub). The parent's pointer to
2403 * Only the hub driver or root-hub registrar should ever call this.
2415 /* Initialize non-root-hub device wakeup to disabled;
2456 /* check whether the hub or firmware marks this port as non-removable */
2472 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
2474 struct usb_port *port_dev = hub->ports[port1 - 1];
2488 if (!test_and_set_bit(port1, hub->child_usage_bits))
2578 /* Returns 1 if @hub is a WUSB root hub, 0 otherwise */
2579 static unsigned hub_is_wusb(struct usb_hub *hub)
2582 if (hub->hdev->parent != NULL) /* not a root hub? */
2584 hcd = container_of(hub->hdev->bus, struct usb_hcd, self);
2616 static int hub_port_reset(struct usb_hub *hub, int port1,
2622 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
2627 if (!hub_is_superspeed(hub->hdev))
2630 if (test_bit(port1, hub->warm_reset_bits))
2638 static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2652 ret = hub_port_status(hub, port1, &portstatus, &portchange);
2664 dev_dbg(&hub->ports[port1 - 1]->dev,
2672 if (hub_port_warm_reset_required(hub, port1, portstatus))
2683 if (!hub_is_superspeed(hub->hdev) &&
2693 if (hub_is_wusb(hub))
2695 else if (hub_is_superspeed(hub->hdev))
2706 static void hub_port_finish_reset(struct usb_hub *hub, int port1,
2726 usb_clear_port_feature(hub->hdev,
2728 if (hub_is_superspeed(hub->hdev)) {
2729 usb_clear_port_feature(hub->hdev, port1,
2731 usb_clear_port_feature(hub->hdev, port1,
2733 usb_clear_port_feature(hub->hdev, port1,
2745 static int hub_port_reset(struct usb_hub *hub, int port1,
2750 struct usb_port *port_dev = hub->ports[port1 - 1];
2752 if (!hub_is_superspeed(hub->hdev)) {
2754 dev_err(hub->intfdev, "only USB3 hub support "
2767 status = hub_port_status(hub, port1,
2772 if (hub_port_warm_reset_required(hub, port1, portstatus))
2775 clear_bit(port1, hub->warm_reset_bits);
2779 status = set_port_feature(hub->hdev, port1, (warm ?
2783 ; /* The hub is gone */
2789 status = hub_port_wait_reset(hub, port1, udev, delay,
2792 dev_dbg(hub->intfdev,
2799 hub_port_finish_reset(hub, port1, udev, &status);
2801 if (!hub_is_superspeed(hub->hdev))
2808 if (hub_port_status(hub, port1,
2812 if (!hub_port_warm_reset_required(hub, port1,
2836 if (!hub_is_superspeed(hub->hdev))
2843 static int port_is_power_on(struct usb_hub *hub, unsigned portstatus)
2847 if (hub_is_superspeed(hub->hdev)) {
2875 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus)
2879 if (hub_is_superspeed(hub->hdev)) {
2895 struct usb_hub *hub, int port1,
2898 struct usb_port *port_dev = hub->ports[port1 - 1];
2902 && hub_port_warm_reset_required(hub, port1, portstatus)) {
2906 else if (status || port_is_suspended(hub, portstatus) ||
2907 !port_is_power_on(hub, portstatus) ||
2930 usb_clear_port_feature(hub->hdev, port1,
2933 usb_clear_port_feature(hub->hdev, port1,
3037 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
3040 (hub ? hub->wakeup_enabled_descendants : 0);
3045 * @udev: device that's no longer in active use, not a root hub
3070 * Devices on USB hub ports have only one "suspend" state, corresponding
3079 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3085 * hub is suspended). Nevertheless, we change @udev->state to
3093 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3094 struct usb_port *port_dev = hub->ports[udev->portnum - 1];
3102 * wake up the upstream hub (including maybe the root hub).
3136 if (hub_is_superspeed(hub->hdev))
3137 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3);
3142 * into suspend a few ms after the root hub stops sending packets.
3151 status = set_port_feature(hub->hdev, port1,
3190 && test_and_clear_bit(port1, hub->child_usage_bits))
3193 usb_mark_last_busy(hub->hdev);
3315 struct usb_hub *hub, int *port1,
3325 status = hub_port_status(hub, *port1, portstatus, portchange);
3332 * @udev: device to re-activate, not a root hub
3366 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3367 struct usb_port *port_dev = hub->ports[udev->portnum - 1];
3372 if (!test_and_set_bit(port1, hub->child_usage_bits)) {
3384 status = hub_port_status(hub, port1, &portstatus, &portchange);
3385 if (status == 0 && !port_is_suspended(hub, portstatus))
3389 if (hub_is_superspeed(hub->hdev))
3390 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0);
3392 status = usb_clear_port_feature(hub->hdev,
3406 status = hub_port_status(hub, port1, &portstatus, &portchange);
3415 if (hub_is_superspeed(hub->hdev)) {
3417 usb_clear_port_feature(hub->hdev, port1,
3421 usb_clear_port_feature(hub->hdev, port1,
3426 if (udev->persist_enabled && hub_is_superspeed(hub->hdev))
3427 status = wait_for_ss_port_enable(udev, hub, &port1, &portchange,
3431 hub, port1, status, portchange, portstatus);
3436 hub_port_logical_disconnect(hub, port1);
3472 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
3476 struct usb_port *port_dev = hub->ports[port - 1];
3482 hdev = hub->hdev;
3506 hub_port_disable(hub, port, 1);
3514 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
3522 static int check_ports_changed(struct usb_hub *hub)
3526 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) {
3530 status = hub_port_status(hub, port1, &portstatus, &portchange);
3539 struct usb_hub *hub = usb_get_intfdata (intf);
3540 struct usb_device *hdev = hub->hdev;
3548 hub->wakeup_enabled_descendants = 0;
3550 struct usb_port *port_dev = hub->ports[port1 - 1];
3560 hub->wakeup_enabled_descendants +=
3564 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) {
3565 /* check if there are changes pending on hub ports */
3566 if (check_ports_changed(hub)) {
3574 /* Enable hub to send remote wakeup for all ports. */
3588 hub_quiesce(hub, HUB_SUSPEND);
3594 struct usb_hub *hub = usb_get_intfdata(intf);
3597 hub_activate(hub, HUB_RESUME);
3603 struct usb_hub *hub = usb_get_intfdata(intf);
3606 hub_activate(hub, HUB_RESET_RESUME);
3611 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3612 * @rhdev: struct usb_device for the root hub
3614 * The USB host controller driver calls this function when its root hub
3617 * When the hub driver is resumed it will take notice and carry out
3623 dev_warn(&rhdev->dev, "root hub lost power or was reset\n");
3824 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
3828 * control transfers to set the hub timeout or enable device-initiated U1/U2
3831 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
3880 /* If we can't set the parent hub U1/U2 timeout,
3893 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
3896 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
3900 * it won't have an effect on the bus link state because the parent hub will
3938 * Disable hub-initiated and device-initiated U1 and U2 entry.
3994 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4076 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
4100 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected)
4106 struct usb_port *port_dev = hub->ports[port1 - 1];
4109 ret = hub_port_status(hub, port1, &portstatus, &portchange);
4126 usb_clear_port_feature(hub->hdev, port1,
4195 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
4201 if (hub)
4202 connect_type = hub->ports[udev->portnum - 1]->connect_type;
4236 hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4239 struct usb_device *hdev = hub->hdev;
4247 /* root hub ports have a slightly longer reset period
4265 retval = hub_port_reset(hub, port1, udev, delay, false);
4322 if (!hub->tt.hub) {
4323 dev_err(&udev->dev, "parent hub has no TT\n");
4327 udev->tt = &hub->tt;
4354 "hub failed to enable device, error %d\n",
4397 retval = hub_port_reset(hub, port1, udev, delay, false);
4473 * and attached to a superspeed hub port, but the device descriptor
4481 hub_port_reset(hub, port1, udev,
4532 hub_port_disable(hub, port1, 0);
4540 check_highspeed (struct usb_hub *hub, struct usb_device *udev, int port1)
4556 "connect to a high speed hub\n");
4557 /* hub LEDs are probably harder to miss than syslog */
4558 if (hub->has_indicators) {
4559 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK;
4561 &hub->leds, 0);
4568 hub_power_remaining (struct usb_hub *hub)
4570 struct usb_device *hdev = hub->hdev;
4574 if (!hub->limited_power)
4577 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent;
4579 struct usb_port *port_dev = hub->ports[port1 - 1];
4601 if (delta > hub->mA_per_port)
4603 delta, hub->mA_per_port);
4607 dev_warn(hub->intfdev, "%dmA over power budget!\n",
4614 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
4619 struct usb_device *hdev = hub->hdev;
4621 struct usb_port *port_dev = hub->ports[port1 - 1];
4637 clear_bit(port1, hub->removed_bits);
4641 status = hub_port_debounce_be_stable(hub, port1);
4658 test_bit(port1, hub->removed_bits)) {
4660 /* maybe switch power back on (e.g. root hub was reset) */
4661 if (hub_is_port_power_switchable(hub)
4662 && !port_is_power_on(hub, portstatus))
4669 if (hub_is_superspeed(hub->hdev))
4688 udev->bus_mA = hub->mA_per_port;
4690 udev->wusb = hub_is_wusb(hub);
4693 if (hub_is_superspeed(hub->hdev))
4706 status = hub_port_init(hub, udev, port1, i);
4733 "can't connect bus-powered hub "
4735 if (hub->has_indicators) {
4736 hub->indicator[port1-1] =
4740 &hub->leds, 0);
4751 check_highspeed (hub, udev, port1);
4761 /* We mustn't add new devices if the parent hub has
4792 status = hub_power_remaining(hub);
4794 dev_dbg(hub->intfdev, "%dmA power budget left\n", status);
4799 hub_port_disable(hub, port1, 1);
4808 if (hub->hdev->parent ||
4817 hub_port_disable(hub, port1, 1);
4818 if (hcd->driver->relinquish_port && !hub->hdev->parent)
4829 * caller already locked the hub
4831 static void hub_port_connect_change(struct usb_hub *hub, int port1,
4835 struct usb_port *port_dev = hub->ports[port1 - 1];
4840 portchange, portspeed(hub, portstatus));
4842 if (hub->has_indicators) {
4843 set_port_led(hub, port1, HUB_LED_AUTO);
4844 hub->indicator[port1-1] = INDICATOR_AUTO;
4849 if (hub->hdev->bus->is_b_host)
4873 clear_bit(port1, hub->change_bits);
4880 hub_port_connect(hub, port1, portstatus, portchange);
4884 static void port_event(struct usb_hub *hub, int port1)
4888 struct usb_port *port_dev = hub->ports[port1 - 1];
4890 struct usb_device *hdev = hub->hdev;
4893 connect_change = test_bit(port1, hub->change_bits);
4894 clear_bit(port1, hub->event_bits);
4895 clear_bit(port1, hub->wakeup_bits);
4897 if (hub_port_status(hub, port1, &portstatus, &portchange) < 0)
4913 * to be shutdown by the hub, this hack enables them again.
4918 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n");
4930 hub_power_on(hub, true);
4931 hub_port_status(hub, port1, &status, &unused);
4961 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange))
4968 if (hub_port_warm_reset_required(hub, port1, portstatus)) {
4972 if (hub_port_reset(hub, port1, NULL,
4974 hub_port_disable(hub, port1, 1);
4990 if (reset_device || (udev && hub_is_superspeed(hub->hdev)
5002 hub_port_connect_change(hub, port1, portstatus, portchange);
5009 struct usb_hub *hub;
5015 hub = container_of(work, struct usb_hub, events);
5016 hdev = hub->hdev;
5017 hub_dev = hub->intfdev;
5023 (u16) hub->change_bits[0],
5024 (u16) hub->event_bits[0]);
5029 if (unlikely(hub->disconnected))
5032 /* If the hub has died, clean up after it */
5034 hub->error = -ENODEV;
5035 hub_quiesce(hub, HUB_DISCONNECT);
5046 /* If this is an inactive hub, do nothing */
5047 if (hub->quiescing)
5050 if (hub->error) {
5051 dev_dbg(hub_dev, "resetting for error %d\n", hub->error);
5055 dev_dbg(hub_dev, "error resetting hub: %d\n", ret);
5059 hub->nerrors = 0;
5060 hub->error = 0;
5065 struct usb_port *port_dev = hub->ports[i - 1];
5067 if (test_bit(i, hub->event_bits)
5068 || test_bit(i, hub->change_bits)
5069 || test_bit(i, hub->wakeup_bits)) {
5082 port_event(hub, i);
5088 /* deal with hub status changes */
5089 if (test_and_clear_bit(0, hub->event_bits) == 0)
5091 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0)
5099 hub->limited_power = 1;
5101 hub->limited_power = 0;
5110 hub_power_on(hub, true);
5111 hub_hub_status(hub, &status, &unused);
5125 kref_put(&hub->kref, hub_release);
5144 .name = "hub",
5160 printk(KERN_ERR "%s: can't register hub driver\n",
5177 pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name);
5191 * individual hub resources. -greg
5494 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
5505 dev_dbg(&udev->dev, "%s for root hub!\n", __func__);
5509 port_dev = hub->ports[udev->portnum - 1];
5620 * @hdev: USB device belonging to the usb hub
5624 * USB drivers call this function to get hub's child device
5633 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
5637 return hub->ports[port1 - 1]->child;
5644 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
5648 if (!hub)
5653 struct usb_port *port_dev = hub->ports[i - 1];
5669 struct usb_port *port_dev = hub->ports[i - 1];
5689 * @hdev: USB device belonging to the usb hub
5698 struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
5700 if (!hub)
5703 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev);