Lines Matching full:hub
3 * USB hub driver.
39 #include "hub.h"
59 /* workqueue to process hub events */
63 /* synchronize hub-port add/remove and peering operations */
91 * hub driver's behavior. On the first initialization attempt, if the
119 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
120 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
123 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
125 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
127 if (hub_is_superspeed(hub->hdev)) in portspeed()
194 struct usb_hub *hub, in usb_set_lpm_mel() argument
204 * and the hub header decode latency. See USB 3.1 section C 2.2.1 in usb_set_lpm_mel()
209 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
213 * each link + wHubDelay for each hub. Add only for last link. in usb_set_lpm_mel()
217 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
228 if (!hub->hdev->parent) in usb_set_lpm_mel()
241 struct usb_hub *hub, in usb_set_lpm_pel() argument
251 * device and the parent hub into U0. The exit latency is the bigger of in usb_set_lpm_pel()
252 * the device exit latency or the hub exit latency. in usb_set_lpm_pel()
260 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
263 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
317 struct usb_hub *hub; in usb_set_lpm_parameters() local
327 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
331 if (!hub) in usb_set_lpm_parameters()
340 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
343 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
347 * when the parent hub notices the downstream port is trying to in usb_set_lpm_parameters()
348 * transition to U0 to when the hub initiates a U0 transition on its in usb_set_lpm_parameters()
352 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking in usb_set_lpm_parameters()
356 * assume the device exit latencies they are talking about are the hub in usb_set_lpm_parameters()
365 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
374 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
465 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
467 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
470 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
480 struct usb_hub *hub = in led_work() local
482 struct usb_device *hdev = hub->hdev; in led_work()
487 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
495 switch (hub->indicator[i]) { in led_work()
534 set_port_led(hub, i + 1, selector); in led_work()
535 hub->indicator[i] = mode; in led_work()
540 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
541 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
546 &hub->leds, LED_CYCLE_PERIOD); in led_work()
549 /* use a short timeout for hub/port status fetches */
588 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
597 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
598 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
601 dev_err(hub->intfdev, in hub_ext_port_status()
606 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
607 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
610 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
613 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
617 int usb_hub_port_status(struct usb_hub *hub, int port1, in usb_hub_port_status() argument
620 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in usb_hub_port_status()
624 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
629 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
631 if (hub->quiescing) { in hub_resubmit_irq_urb()
632 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
636 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
639 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
640 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
643 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
648 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
650 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
654 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
658 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
666 * work for this hub. Therefore put the interface either when in kick_hub_wq()
669 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
671 kref_get(&hub->kref); in kick_hub_wq()
673 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
678 kref_put(&hub->kref, hub_release); in kick_hub_wq()
683 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
685 if (hub) in usb_kick_hub_wq()
686 kick_hub_wq(hub); in usb_kick_hub_wq()
695 * resume through the normal hub interrupt URB.
700 struct usb_hub *hub; in usb_wakeup_notification() local
706 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
707 if (hub) { in usb_wakeup_notification()
708 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
712 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
713 kick_hub_wq(hub); in usb_wakeup_notification()
721 struct usb_hub *hub = urb->context; in hub_irq() local
733 /* Cause a hub reset after 10 consecutive errors */ in hub_irq()
734 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
735 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
737 hub->error = status; in hub_irq()
744 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
746 hub->event_bits[0] = bits; in hub_irq()
750 hub->nerrors = 0; in hub_irq()
753 kick_hub_wq(hub); in hub_irq()
756 hub_resubmit_irq_urb(hub); in hub_irq()
781 * both can talk to the same hub concurrently.
785 struct usb_hub *hub = in hub_tt_work() local
789 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
790 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
793 struct usb_device *hdev = hub->hdev; in hub_tt_work()
797 next = hub->tt.clear_list.next; in hub_tt_work()
802 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
815 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
817 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
821 * usb_hub_set_port_power - control hub port's power state
822 * @hdev: USB device belonging to the usb hub
823 * @hub: target hub
832 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
846 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
848 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
853 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
856 * High speed HCDs use this to tell the hub driver that some split control or
861 * It may not be possible for that hub to handle additional full (or low)
876 * there can be many TTs per hub). even if they're uncommon. in usb_hub_clear_tt_buffer()
908 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
916 * unless we send these messages to the hub. in hub_power_on()
918 if (hub_is_port_power_switchable(hub)) in hub_power_on()
919 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
921 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
922 "non-switchable hub\n"); in hub_power_on()
923 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
924 if (test_bit(port1, hub->power_bits)) in hub_power_on()
925 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
927 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
930 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
933 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
938 mutex_lock(&hub->status_mutex); in hub_hub_status()
939 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
942 dev_err(hub->intfdev, in hub_hub_status()
945 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
946 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
949 mutex_unlock(&hub->status_mutex); in hub_hub_status()
953 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
956 return set_port_feature(hub->hdev, in hub_set_port_link_state()
966 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
968 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
969 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
975 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
980 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
981 kick_hub_wq(hub); in hub_port_logical_disconnect()
985 * usb_remove_device - disable a device's port on its parent hub
998 struct usb_hub *hub; in usb_remove_device() local
1002 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1004 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1005 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1011 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1012 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1025 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1027 struct usb_device *hdev = hub->hdev; in hub_activate()
1039 /* Was the hub disconnected while we were waiting? */ in hub_activate()
1040 if (hub->disconnected) in hub_activate()
1046 kref_get(&hub->kref); in hub_activate()
1048 /* The superspeed hub except for root hub has to use Hub Depth in hub_activate()
1050 * it uses to determine the downstream port number. So hub driver in hub_activate()
1051 * should send a set hub depth request to superspeed hub after in hub_activate()
1052 * the superspeed hub is set configuration in initialization or in hub_activate()
1065 dev_err(hub->intfdev, in hub_activate()
1066 "set hub depth failed\n"); in hub_activate()
1070 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1073 * root hub (assuming usbcore is compiled into the kernel in hub_activate()
1082 delay = hub_power_on_good_delay(hub); in hub_activate()
1084 hub_power_on(hub, false); in hub_activate()
1085 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1087 &hub->init_work, in hub_activate()
1092 to_usb_interface(hub->intfdev)); in hub_activate()
1095 /* The internal host controller state for the hub device in hub_activate()
1097 * Update the device's info so the HW knows it's a hub. in hub_activate()
1102 &hub->tt, GFP_NOIO); in hub_activate()
1104 dev_err(hub->intfdev, in hub_activate()
1105 "Host not accepting hub info update\n"); in hub_activate()
1106 dev_err(hub->intfdev, in hub_activate()
1107 "LS/FS devices and hubs may not work under this hub\n"); in hub_activate()
1110 hub_power_on(hub, true); in hub_activate()
1112 hub_power_on(hub, true); in hub_activate()
1115 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1121 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1125 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1130 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1163 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1164 set_bit(port1, hub->event_bits); in hub_activate()
1179 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1184 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1189 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1193 hub_is_superspeed(hub->hdev)) { in hub_activate()
1195 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1203 clear_bit(port1, hub->removed_bits); in hub_activate()
1216 set_bit(port1, hub->change_bits); in hub_activate()
1230 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1232 set_bit(port1, hub->event_bits); in hub_activate()
1241 if (test_bit(port1, hub->power_bits)) in hub_activate()
1242 set_bit(port1, hub->change_bits); in hub_activate()
1247 set_bit(port1, hub->change_bits); in hub_activate()
1264 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1266 &hub->init_work, in hub_activate()
1275 hub->quiescing = 0; in hub_activate()
1277 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1279 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1280 if (hub->has_indicators && blinkenlights) in hub_activate()
1282 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1285 kick_hub_wq(hub); in hub_activate()
1290 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1294 kref_put(&hub->kref, hub_release); in hub_activate()
1300 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1302 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1307 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1309 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1316 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1318 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1323 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1324 hub->quiescing = 1; in hub_quiesce()
1325 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1330 if (hub->ports[i]->child) in hub_quiesce()
1331 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1336 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1337 usb_kill_urb(hub->urb); in hub_quiesce()
1338 if (hub->has_indicators) in hub_quiesce()
1339 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1340 if (hub->tt.hub) in hub_quiesce()
1341 flush_work(&hub->tt.clear_work); in hub_quiesce()
1344 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1348 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1349 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1352 /* caller has locked the hub device */
1355 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1357 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1358 hub->in_reset = 1; in hub_pre_reset()
1359 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1363 /* caller has locked the hub device */
1366 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1368 hub->in_reset = 0; in hub_post_reset()
1369 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1370 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1374 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1378 struct usb_device *hdev = hub->hdev; in hub_configure()
1379 struct device *hub_dev = hub->intfdev; in hub_configure()
1389 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1390 if (!hub->buffer) { in hub_configure()
1395 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1396 if (!hub->status) { in hub_configure()
1400 mutex_init(&hub->status_mutex); in hub_configure()
1402 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1403 if (!hub->descriptor) { in hub_configure()
1408 /* Request the entire hub descriptor. in hub_configure()
1409 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1410 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1412 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1414 message = "can't read hub descriptor"; in hub_configure()
1422 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1423 message = "hub has too many ports!"; in hub_configure()
1426 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1427 message = "hub doesn't have any ports!"; in hub_configure()
1433 * Accumulate wHubDelay + 40ns for every hub in the tree of devices. in hub_configure()
1437 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1446 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1450 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1451 if (!hub->ports) { in hub_configure()
1456 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1471 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1477 dev_dbg(hub_dev, "standalone hub\n"); in hub_configure()
1505 spin_lock_init(&hub->tt.lock); in hub_configure()
1506 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1507 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1513 hub->tt.hub = hdev; in hub_configure()
1519 hub->tt.multi = 1; in hub_configure()
1523 hub->tt.hub = hdev; in hub_configure()
1529 dev_dbg(hub_dev, "Unrecognized hub protocol %d\n", in hub_configure()
1538 hub->tt.think_time = 666; in hub_configure()
1541 8, hub->tt.think_time); in hub_configure()
1545 hub->tt.think_time = 666 * 2; in hub_configure()
1548 16, hub->tt.think_time); in hub_configure()
1551 hub->tt.think_time = 666 * 3; in hub_configure()
1554 24, hub->tt.think_time); in hub_configure()
1557 hub->tt.think_time = 666 * 4; in hub_configure()
1560 32, hub->tt.think_time); in hub_configure()
1564 /* probe() zeroes hub->indicator[] */ in hub_configure()
1566 hub->has_indicators = 1; in hub_configure()
1571 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1578 message = "can't get hub status"; in hub_configure()
1588 hub->mA_per_port = full_load; in hub_configure()
1590 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1591 hub->limited_power = 1; in hub_configure()
1595 hub->descriptor->bHubContrCurrent; in hub_configure()
1597 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", in hub_configure()
1598 hub->descriptor->bHubContrCurrent); in hub_configure()
1599 hub->limited_power = 1; in hub_configure()
1605 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1607 } else { /* Self-powered external hub */ in hub_configure()
1610 hub->mA_per_port = full_load; in hub_configure()
1612 if (hub->mA_per_port < full_load) in hub_configure()
1614 hub->mA_per_port); in hub_configure()
1616 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1618 message = "can't get hub status"; in hub_configure()
1641 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1642 maxp = sizeof(*hub->buffer); in hub_configure()
1644 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1645 if (!hub->urb) { in hub_configure()
1650 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1651 hub, endpoint->bInterval); in hub_configure()
1653 /* maybe cycle the hub leds */ in hub_configure()
1654 if (hub->has_indicators && blinkenlights) in hub_configure()
1655 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1659 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1661 dev_err(hub->intfdev, in hub_configure()
1668 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1677 /* Update the HCD's internal representation of this hub before hub_wq in hub_configure()
1678 * starts getting port status changes for devices under the hub. in hub_configure()
1682 &hub->tt, GFP_KERNEL); in hub_configure()
1684 message = "can't update HCD hub info"; in hub_configure()
1689 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1691 hub_activate(hub, HUB_INIT); in hub_configure()
1703 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1705 usb_put_dev(hub->hdev); in hub_release()
1706 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1707 kfree(hub); in hub_release()
1714 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1719 * Stop adding new hub events. We do not want to block here and thus in hub_disconnect()
1722 hub->disconnected = 1; in hub_disconnect()
1724 /* Disconnect all children and quiesce the hub */ in hub_disconnect()
1725 hub->error = 0; in hub_disconnect()
1726 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1738 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1742 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1745 usb_free_urb(hub->urb); in hub_disconnect()
1746 kfree(hub->ports); in hub_disconnect()
1747 kfree(hub->descriptor); in hub_disconnect()
1748 kfree(hub->status); in hub_disconnect()
1749 kfree(hub->buffer); in hub_disconnect()
1753 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1756 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1758 kref_put(&hub->kref, hub_release); in hub_disconnect()
1769 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1784 struct usb_hub *hub; in hub_probe() local
1793 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1796 * change on hub downstream ports, so it is safe to do it. in hub_probe()
1799 * below very rare devices when they are plugged into hub in hub_probe()
1810 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1815 * hub during running 'lsusb', but it is probably too in hub_probe()
1818 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1819 * suspend timer for hub, also may decrease power consumption in hub_probe()
1837 } else { /* root hub */ in hub_probe()
1846 "Unsupported bus topology: hub nested too deep\n"); in hub_probe()
1852 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1858 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1862 /* We found a hub */ in hub_probe()
1863 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1865 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1866 if (!hub) in hub_probe()
1869 kref_init(&hub->kref); in hub_probe()
1870 hub->intfdev = &intf->dev; in hub_probe()
1871 hub->hdev = hdev; in hub_probe()
1872 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1873 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1874 INIT_WORK(&hub->events, hub_event); in hub_probe()
1875 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1876 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1877 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1881 usb_set_intfdata(intf, hub); in hub_probe()
1889 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1892 hub->quirk_disable_autosuspend = 1; in hub_probe()
1896 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1897 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1910 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1912 /* assert ifno == 0 (part of hub spec) */ in hub_ioctl()
1924 if (hub->ports[i]->child == NULL) in hub_ioctl()
1928 hub->ports[i]->child->devnum; in hub_ioctl()
1942 * Allow user programs to claim ports on a hub. When a device is attached
1948 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
1955 /* Devices not managed by the hub driver in find_port_owner()
1958 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1997 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
2001 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2002 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2010 struct usb_hub *hub; in usb_device_is_owned() local
2014 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2015 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2020 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2024 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2025 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2064 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2115 * uses always #1 for the root hub of the controller. So USB stack's
2128 /* be safe when more hub events are proceed in parallel */ in choose_devnum()
2178 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2183 if (hub->ports[i]->child) in hub_disconnect_children()
2184 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2196 * If *pdev is a normal device then the parent hub must already be locked.
2197 * If *pdev is a root hub then the caller must hold the usb_bus_idr_lock,
2200 * Only hub drivers (including virtual root hub drivers for host
2209 struct usb_hub *hub = NULL; in usb_disconnect() local
2240 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2241 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2250 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2273 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2446 struct usb_hub *hub; in set_usb_port_removable() local
2456 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2462 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2475 * Otherwise, check whether the hub knows whether a port is removable in set_usb_port_removable()
2478 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2484 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2488 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2506 * the parent hub (if udev is a normal device) or else the
2507 * usb_bus_idr_lock (if udev is a root hub). The parent's pointer to
2513 * Only the hub driver or root-hub registrar should ever call this.
2525 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2566 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2581 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2583 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2597 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2691 * @hdev: The hub device
2764 /* Returns 1 if @hub is a WUSB root hub, 0 otherwise */
2765 static unsigned hub_is_wusb(struct usb_hub *hub) in hub_is_wusb() argument
2768 if (hub->hdev->parent != NULL) /* not a root hub? */ in hub_is_wusb()
2770 hcd = bus_to_hcd(hub->hdev->bus); in hub_is_wusb()
2828 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2833 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2836 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2844 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2859 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2860 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2865 ret = usb_hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2885 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2893 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2904 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2906 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2917 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2921 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2927 if (hub_is_wusb(hub)) in hub_port_wait_reset()
2931 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2943 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2948 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2951 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2953 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2966 if (usb_hub_port_status(hub, port1, &portstatus, in hub_port_reset()
2968 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2972 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2976 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2980 ; /* The hub is gone */ in hub_port_reset()
2986 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2989 dev_dbg(hub->intfdev, in hub_port_reset()
3000 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3003 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3006 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3008 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3012 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3019 if (usb_hub_port_status(hub, port1, in hub_port_reset()
3023 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3054 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
3055 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3078 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3085 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) in usb_port_is_power_on() argument
3089 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3117 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3121 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3137 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3140 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3146 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3150 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3151 !usb_port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3157 status = usb_hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3181 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3184 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3189 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3194 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3297 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3300 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3306 * @udev: device that's no longer in active use, not a root hub
3331 * Devices on USB hub ports have only one "suspend" state, corresponding
3340 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3346 * hub is suspended). Nevertheless, we change @udev->state to
3354 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3355 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3363 * wake up the upstream hub (including maybe the root hub). in usb_port_suspend()
3390 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3391 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3396 * into suspend a few ms after the root hub stops sending packets. in usb_port_suspend()
3405 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3420 ret = usb_hub_port_status(hub, port1, &portstatus, in usb_port_suspend()
3426 if (ret == 0 && port_is_suspended(hub, portstatus)) { in usb_port_suspend()
3462 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3465 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3590 struct usb_hub *hub, int port1, in wait_for_connected() argument
3598 if (!usb_port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3604 status = usb_hub_port_status(hub, port1, portstatus, portchange); in wait_for_connected()
3612 * @udev: device to re-activate, not a root hub
3646 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3647 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3652 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3664 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3665 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3672 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3673 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3675 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3689 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3695 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3697 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3701 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3710 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3714 hub, port1, status, portchange, portstatus); in usb_port_resume()
3719 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3751 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3755 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3762 hdev = hub->hdev; in hub_handle_remote_wakeup()
3788 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3794 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3798 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3802 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3811 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3812 struct usb_device *hdev = hub->hdev; in hub_suspend()
3819 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3821 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3831 hub->wakeup_enabled_descendants += in hub_suspend()
3835 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3836 /* check if there are changes pending on hub ports */ in hub_suspend()
3837 if (check_ports_changed(hub)) { in hub_suspend()
3845 /* Enable hub to send remote wakeup for all ports. */ in hub_suspend()
3859 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3863 /* Report wakeup requests from the ports of a resuming root hub */
3864 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3866 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3873 return; /* Not a root hub */ in report_wakeup_requests()
3889 udev = hub->ports[i]->child; in report_wakeup_requests()
3899 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3902 hub_activate(hub, HUB_RESUME); in hub_resume()
3910 report_wakeup_requests(hub); in hub_resume()
3916 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
3919 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
3924 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3925 * @rhdev: struct usb_device for the root hub
3927 * The USB host controller driver calls this function when its root hub
3930 * When the hub driver is resumed it will take notice and carry out
3936 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4165 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4169 * control transfers to set the hub timeout or enable device-initiated U1/U2
4173 * hub-initiated U1/U2 will be disabled.
4175 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
4213 /* If we can't set the parent hub U1/U2 timeout, in usb_enable_link_state()
4243 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4246 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4250 * it won't have an effect on the bus link state because the parent hub will
4280 /* As soon as usb_set_lpm_timeout(0) return 0, hub initiated LPM in usb_disable_link_state()
4281 * is disabled. Hub will disallows link to enter U1/U2 as well, in usb_disable_link_state()
4282 * even device is initiating LPM. Hence LPM is disabled if hub LPM in usb_disable_link_state()
4295 * Disable hub-initiated and device-initiated U1 and U2 entry.
4351 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4361 struct usb_hub *hub; in usb_enable_lpm() local
4382 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4383 if (!hub) in usb_enable_lpm()
4386 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4411 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4418 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4437 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4467 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4485 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4487 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4488 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4491 if (!hub->error) { in hub_port_disable()
4492 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4493 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4494 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4517 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4519 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4537 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4543 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4546 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4563 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4632 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4638 if (hub) in hub_set_initial_usb2_lpm_policy()
4639 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4673 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4676 struct usb_device *hdev = hub->hdev; in hub_port_init()
4678 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4687 /* root hub ports have a slightly longer reset period in hub_port_init()
4703 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4775 if (!hub->tt.hub) { in hub_port_init()
4776 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4780 udev->tt = &hub->tt; in hub_port_init()
4806 "hub failed to enable device, error %d\n", in hub_port_init()
4858 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4951 * and attached to a superspeed hub port, but the device descriptor in hub_port_init()
4959 hub_port_reset(hub, port1, udev, in hub_port_init()
5014 hub_port_disable(hub, port1, 0); in hub_port_init()
5021 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5037 "connect to a high speed hub\n"); in check_highspeed()
5038 /* hub LEDs are probably harder to miss than syslog */ in check_highspeed()
5039 if (hub->has_indicators) { in check_highspeed()
5040 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5042 &hub->leds, 0); in check_highspeed()
5049 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
5051 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5055 if (!hub->limited_power) in hub_power_remaining()
5058 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5060 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5082 if (delta > hub->mA_per_port) in hub_power_remaining()
5084 delta, hub->mA_per_port); in hub_power_remaining()
5088 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5180 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5186 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5188 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5205 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5209 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5226 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5229 * maybe switch power back on (e.g. root hub was reset) in hub_port_connect()
5232 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5233 && !usb_port_is_power_on(hub, portstatus) in hub_port_connect()
5241 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5265 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5267 udev->wusb = hub_is_wusb(hub); in hub_port_connect()
5270 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5282 status = hub_port_init(hub, udev, port1, i); in hub_port_connect()
5311 "can't connect bus-powered hub " in hub_port_connect()
5313 if (hub->has_indicators) { in hub_port_connect()
5314 hub->indicator[port1-1] = in hub_port_connect()
5318 &hub->leds, 0); in hub_port_connect()
5329 check_highspeed(hub, udev, port1); in hub_port_connect()
5339 /* We mustn't add new devices if the parent hub has in hub_port_connect()
5370 status = hub_power_remaining(hub); in hub_port_connect()
5372 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5377 hub_port_disable(hub, port1, 1); in hub_port_connect()
5393 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5394 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5395 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5396 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5399 if (hub->hdev->parent || in hub_port_connect()
5408 hub_port_disable(hub, port1, 1); in hub_port_connect()
5409 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5421 * caller already locked the hub
5423 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5427 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5434 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5436 if (hub->has_indicators) { in hub_port_connect_change()
5437 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5438 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5443 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5490 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5497 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5501 /* Handle notifying userspace about hub over-current events */
5536 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5540 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5542 struct usb_device *hdev = hub->hdev; in port_event()
5546 connect_change = test_bit(port1, hub->change_bits); in port_event()
5547 clear_bit(port1, hub->event_bits); in port_event()
5548 clear_bit(port1, hub->wakeup_bits); in port_event()
5550 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5566 * to be shutdown by the hub, this hack enables them again. in port_event()
5571 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5586 hub_power_on(hub, true); in port_event()
5587 usb_hub_port_status(hub, port1, &status, &unused); in port_event()
5617 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5626 while (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5631 usb_hub_port_status(hub, port1, &portstatus, &unused); in port_event()
5637 if (hub_port_reset(hub, port1, NULL, in port_event()
5639 hub_port_disable(hub, port1, 1); in port_event()
5653 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5660 struct usb_hub *hub; in hub_event() local
5666 hub = container_of(work, struct usb_hub, events); in hub_event()
5667 hdev = hub->hdev; in hub_event()
5668 hub_dev = hub->intfdev; in hub_event()
5676 (u16) hub->change_bits[0], in hub_event()
5677 (u16) hub->event_bits[0]); in hub_event()
5682 if (unlikely(hub->disconnected)) in hub_event()
5685 /* If the hub has died, clean up after it */ in hub_event()
5687 hub->error = -ENODEV; in hub_event()
5688 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5699 /* If this is an inactive hub, do nothing */ in hub_event()
5700 if (hub->quiescing) in hub_event()
5703 if (hub->error) { in hub_event()
5704 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5708 dev_dbg(hub_dev, "error resetting hub: %d\n", ret); in hub_event()
5712 hub->nerrors = 0; in hub_event()
5713 hub->error = 0; in hub_event()
5718 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5720 if (test_bit(i, hub->event_bits) in hub_event()
5721 || test_bit(i, hub->change_bits) in hub_event()
5722 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5735 port_event(hub, i); in hub_event()
5741 /* deal with hub status changes */ in hub_event()
5742 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5744 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5752 hub->limited_power = 1; in hub_event()
5754 hub->limited_power = 0; in hub_event()
5763 hub_power_on(hub, true); in hub_event()
5764 hub_hub_status(hub, &status, &unused); in hub_event()
5778 kref_put(&hub->kref, hub_release); in hub_event()
5811 .name = "hub",
5827 printk(KERN_ERR "%s: can't register hub driver\n", in usb_hub_init()
5844 pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name); in usb_hub_init()
5854 * Hub resources are freed for us by usb_deregister. It calls in usb_hub_cleanup()
5858 * individual hub resources. -greg in usb_hub_cleanup()
6065 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
6075 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6083 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6191 * @hdev: USB device belonging to the usb hub
6195 * USB drivers call this function to get hub's child device
6204 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6208 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6215 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6219 if (!hub) in usb_hub_adjust_deviceremovable()
6224 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6240 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6260 * @hdev: USB device belonging to the usb hub
6269 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6271 if (!hub) in usb_get_hub_port_acpi_handle()
6274 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()