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
134 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
135 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
138 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
140 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
142 if (hub_is_superspeed(hub->hdev)) in portspeed()
213 struct usb_hub *hub, in usb_set_lpm_mel() argument
223 * and the hub header decode latency. See USB 3.1 section C 2.2.1 in usb_set_lpm_mel()
228 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
232 * each link + wHubDelay for each hub. Add only for last link. in usb_set_lpm_mel()
236 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
247 if (!hub->hdev->parent) in usb_set_lpm_mel()
260 struct usb_hub *hub, in usb_set_lpm_pel() argument
270 * device and the parent hub into U0. The exit latency is the bigger of in usb_set_lpm_pel()
271 * the device exit latency or the hub exit latency. in usb_set_lpm_pel()
279 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
282 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
336 struct usb_hub *hub; in usb_set_lpm_parameters() local
350 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
354 if (!hub) in usb_set_lpm_parameters()
363 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
366 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
370 * when the parent hub notices the downstream port is trying to in usb_set_lpm_parameters()
371 * transition to U0 to when the hub initiates a U0 transition on its in usb_set_lpm_parameters()
375 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking in usb_set_lpm_parameters()
379 * assume the device exit latencies they are talking about are the hub in usb_set_lpm_parameters()
388 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
397 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
488 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
490 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
493 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
503 struct usb_hub *hub = in led_work() local
505 struct usb_device *hdev = hub->hdev; in led_work()
510 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
518 switch (hub->indicator[i]) { in led_work()
557 set_port_led(hub, i + 1, selector); in led_work()
558 hub->indicator[i] = mode; in led_work()
563 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
564 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
569 &hub->leds, LED_CYCLE_PERIOD); in led_work()
572 /* use a short timeout for hub/port status fetches */
611 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
620 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
621 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
624 dev_err(hub->intfdev, in hub_ext_port_status()
629 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
630 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
633 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
636 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
640 int usb_hub_port_status(struct usb_hub *hub, int port1, in usb_hub_port_status() argument
643 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in usb_hub_port_status()
647 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
652 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
654 if (hub->quiescing) { in hub_resubmit_irq_urb()
655 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
659 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
662 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
663 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
666 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
671 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
673 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
677 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
681 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
689 * work for this hub. Therefore put the interface either when in kick_hub_wq()
692 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
694 kref_get(&hub->kref); in kick_hub_wq()
696 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
701 kref_put(&hub->kref, hub_release); in kick_hub_wq()
706 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
708 if (hub) in usb_kick_hub_wq()
709 kick_hub_wq(hub); in usb_kick_hub_wq()
718 * resume through the normal hub interrupt URB.
723 struct usb_hub *hub; in usb_wakeup_notification() local
729 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
730 if (hub) { in usb_wakeup_notification()
731 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
735 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
736 kick_hub_wq(hub); in usb_wakeup_notification()
744 struct usb_hub *hub = urb->context; in hub_irq() local
756 /* Cause a hub reset after 10 consecutive errors */ in hub_irq()
757 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
758 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
760 hub->error = status; in hub_irq()
767 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
769 hub->event_bits[0] = bits; in hub_irq()
773 hub->nerrors = 0; in hub_irq()
776 kick_hub_wq(hub); in hub_irq()
779 hub_resubmit_irq_urb(hub); in hub_irq()
804 * both can talk to the same hub concurrently.
808 struct usb_hub *hub = in hub_tt_work() local
812 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
813 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
816 struct usb_device *hdev = hub->hdev; in hub_tt_work()
820 next = hub->tt.clear_list.next; in hub_tt_work()
825 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
838 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
840 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
844 * usb_hub_set_port_power - control hub port's power state
845 * @hdev: USB device belonging to the usb hub
846 * @hub: target hub
855 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
869 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
871 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
876 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
879 * High speed HCDs use this to tell the hub driver that some split control or
884 * It may not be possible for that hub to handle additional full (or low)
899 * there can be many TTs per hub). even if they're uncommon. in usb_hub_clear_tt_buffer()
931 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
939 * unless we send these messages to the hub. in hub_power_on()
941 if (hub_is_port_power_switchable(hub)) in hub_power_on()
942 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
944 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
945 "non-switchable hub\n"); in hub_power_on()
946 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
947 if (test_bit(port1, hub->power_bits)) in hub_power_on()
948 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
950 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
953 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
956 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
961 mutex_lock(&hub->status_mutex); in hub_hub_status()
962 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
965 dev_err(hub->intfdev, in hub_hub_status()
968 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
969 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
972 mutex_unlock(&hub->status_mutex); in hub_hub_status()
976 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
979 return set_port_feature(hub->hdev, in hub_set_port_link_state()
989 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
991 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
992 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
998 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1003 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1004 kick_hub_wq(hub); in hub_port_logical_disconnect()
1008 * usb_remove_device - disable a device's port on its parent hub
1021 struct usb_hub *hub; in usb_remove_device() local
1025 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1027 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1028 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1034 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1035 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1048 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1050 struct usb_device *hdev = hub->hdev; in hub_activate()
1062 /* Was the hub disconnected while we were waiting? */ in hub_activate()
1063 if (hub->disconnected) in hub_activate()
1069 kref_get(&hub->kref); in hub_activate()
1071 /* The superspeed hub except for root hub has to use Hub Depth in hub_activate()
1073 * it uses to determine the downstream port number. So hub driver in hub_activate()
1074 * should send a set hub depth request to superspeed hub after in hub_activate()
1075 * the superspeed hub is set configuration in initialization or in hub_activate()
1088 dev_err(hub->intfdev, in hub_activate()
1089 "set hub depth failed\n"); in hub_activate()
1093 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1096 * root hub (assuming usbcore is compiled into the kernel in hub_activate()
1105 delay = hub_power_on_good_delay(hub); in hub_activate()
1107 hub_power_on(hub, false); in hub_activate()
1108 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1110 &hub->init_work, in hub_activate()
1115 to_usb_interface(hub->intfdev)); in hub_activate()
1118 /* The internal host controller state for the hub device in hub_activate()
1120 * Update the device's info so the HW knows it's a hub. in hub_activate()
1125 &hub->tt, GFP_NOIO); in hub_activate()
1127 dev_err(hub->intfdev, in hub_activate()
1128 "Host not accepting hub info update\n"); in hub_activate()
1129 dev_err(hub->intfdev, in hub_activate()
1130 "LS/FS devices and hubs may not work under this hub\n"); in hub_activate()
1133 hub_power_on(hub, true); in hub_activate()
1135 hub_power_on(hub, true); in hub_activate()
1138 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1144 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1148 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1153 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1186 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1187 set_bit(port1, hub->event_bits); in hub_activate()
1202 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1207 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1212 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1216 hub_is_superspeed(hub->hdev)) { in hub_activate()
1218 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1226 clear_bit(port1, hub->removed_bits); in hub_activate()
1239 set_bit(port1, hub->change_bits); in hub_activate()
1253 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1255 set_bit(port1, hub->event_bits); in hub_activate()
1264 if (test_bit(port1, hub->power_bits)) in hub_activate()
1265 set_bit(port1, hub->change_bits); in hub_activate()
1270 set_bit(port1, hub->change_bits); in hub_activate()
1287 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1289 &hub->init_work, in hub_activate()
1298 hub->quiescing = 0; in hub_activate()
1300 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1302 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1303 if (hub->has_indicators && blinkenlights) in hub_activate()
1305 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1308 kick_hub_wq(hub); in hub_activate()
1313 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1317 kref_put(&hub->kref, hub_release); in hub_activate()
1323 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1325 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1330 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1332 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1339 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1341 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1346 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1347 hub->quiescing = 1; in hub_quiesce()
1348 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1353 if (hub->ports[i]->child) in hub_quiesce()
1354 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1359 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1360 usb_kill_urb(hub->urb); in hub_quiesce()
1361 if (hub->has_indicators) in hub_quiesce()
1362 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1363 if (hub->tt.hub) in hub_quiesce()
1364 flush_work(&hub->tt.clear_work); in hub_quiesce()
1367 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1371 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1372 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1375 /* caller has locked the hub device */
1378 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1380 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1381 hub->in_reset = 1; in hub_pre_reset()
1382 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1386 /* caller has locked the hub device */
1389 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1391 hub->in_reset = 0; in hub_post_reset()
1392 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1393 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1397 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1401 struct usb_device *hdev = hub->hdev; in hub_configure()
1402 struct device *hub_dev = hub->intfdev; in hub_configure()
1412 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1413 if (!hub->buffer) { in hub_configure()
1418 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1419 if (!hub->status) { in hub_configure()
1423 mutex_init(&hub->status_mutex); in hub_configure()
1425 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1426 if (!hub->descriptor) { in hub_configure()
1431 /* Request the entire hub descriptor. in hub_configure()
1432 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1433 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1435 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1437 message = "can't read hub descriptor"; in hub_configure()
1445 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1446 message = "hub has too many ports!"; in hub_configure()
1449 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1450 message = "hub doesn't have any ports!"; in hub_configure()
1456 * Accumulate wHubDelay + 40ns for every hub in the tree of devices. in hub_configure()
1460 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1469 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1473 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1474 if (!hub->ports) { in hub_configure()
1479 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1494 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1500 dev_dbg(hub_dev, "standalone hub\n"); in hub_configure()
1528 spin_lock_init(&hub->tt.lock); in hub_configure()
1529 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1530 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1536 hub->tt.hub = hdev; in hub_configure()
1542 hub->tt.multi = 1; in hub_configure()
1546 hub->tt.hub = hdev; in hub_configure()
1552 dev_dbg(hub_dev, "Unrecognized hub protocol %d\n", in hub_configure()
1561 hub->tt.think_time = 666; in hub_configure()
1564 8, hub->tt.think_time); in hub_configure()
1568 hub->tt.think_time = 666 * 2; in hub_configure()
1571 16, hub->tt.think_time); in hub_configure()
1574 hub->tt.think_time = 666 * 3; in hub_configure()
1577 24, hub->tt.think_time); in hub_configure()
1580 hub->tt.think_time = 666 * 4; in hub_configure()
1583 32, hub->tt.think_time); in hub_configure()
1587 /* probe() zeroes hub->indicator[] */ in hub_configure()
1589 hub->has_indicators = 1; in hub_configure()
1594 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1601 message = "can't get hub status"; in hub_configure()
1611 hub->mA_per_port = full_load; in hub_configure()
1613 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1614 hub->limited_power = 1; in hub_configure()
1618 hub->descriptor->bHubContrCurrent; in hub_configure()
1620 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", in hub_configure()
1621 hub->descriptor->bHubContrCurrent); in hub_configure()
1622 hub->limited_power = 1; in hub_configure()
1628 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1630 } else { /* Self-powered external hub */ in hub_configure()
1633 hub->mA_per_port = full_load; in hub_configure()
1635 if (hub->mA_per_port < full_load) in hub_configure()
1637 hub->mA_per_port); in hub_configure()
1639 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1641 message = "can't get hub status"; in hub_configure()
1664 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1665 maxp = sizeof(*hub->buffer); in hub_configure()
1667 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1668 if (!hub->urb) { in hub_configure()
1673 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1674 hub, endpoint->bInterval); in hub_configure()
1676 /* maybe cycle the hub leds */ in hub_configure()
1677 if (hub->has_indicators && blinkenlights) in hub_configure()
1678 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1682 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1684 dev_err(hub->intfdev, in hub_configure()
1691 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1700 /* Update the HCD's internal representation of this hub before hub_wq in hub_configure()
1701 * starts getting port status changes for devices under the hub. in hub_configure()
1705 &hub->tt, GFP_KERNEL); in hub_configure()
1707 message = "can't update HCD hub info"; in hub_configure()
1712 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1714 hub_activate(hub, HUB_INIT); in hub_configure()
1726 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1728 usb_put_dev(hub->hdev); in hub_release()
1729 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1730 kfree(hub); in hub_release()
1737 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1742 * Stop adding new hub events. We do not want to block here and thus in hub_disconnect()
1745 hub->disconnected = 1; in hub_disconnect()
1747 /* Disconnect all children and quiesce the hub */ in hub_disconnect()
1748 hub->error = 0; in hub_disconnect()
1749 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1761 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1765 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1768 usb_free_urb(hub->urb); in hub_disconnect()
1769 kfree(hub->ports); in hub_disconnect()
1770 kfree(hub->descriptor); in hub_disconnect()
1771 kfree(hub->status); in hub_disconnect()
1772 kfree(hub->buffer); in hub_disconnect()
1776 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1779 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1781 kref_put(&hub->kref, hub_release); in hub_disconnect()
1792 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1807 struct usb_hub *hub; in hub_probe() local
1816 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1819 * change on hub downstream ports, so it is safe to do it. in hub_probe()
1822 * below very rare devices when they are plugged into hub in hub_probe()
1833 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1838 * hub during running 'lsusb', but it is probably too in hub_probe()
1841 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1842 * suspend timer for hub, also may decrease power consumption in hub_probe()
1860 } else { /* root hub */ in hub_probe()
1869 "Unsupported bus topology: hub nested too deep\n"); in hub_probe()
1875 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1881 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1885 /* We found a hub */ in hub_probe()
1886 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1888 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1889 if (!hub) in hub_probe()
1892 kref_init(&hub->kref); in hub_probe()
1893 hub->intfdev = &intf->dev; in hub_probe()
1894 hub->hdev = hdev; in hub_probe()
1895 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1896 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1897 INIT_WORK(&hub->events, hub_event); in hub_probe()
1898 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1899 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1900 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1904 usb_set_intfdata(intf, hub); in hub_probe()
1912 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1915 hub->quirk_disable_autosuspend = 1; in hub_probe()
1927 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1928 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1941 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1943 /* assert ifno == 0 (part of hub spec) */ in hub_ioctl()
1955 if (hub->ports[i]->child == NULL) in hub_ioctl()
1959 hub->ports[i]->child->devnum; in hub_ioctl()
1973 * Allow user programs to claim ports on a hub. When a device is attached
1979 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
1986 /* Devices not managed by the hub driver in find_port_owner()
1989 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2028 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
2032 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2033 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2041 struct usb_hub *hub; in usb_device_is_owned() local
2045 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2046 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2051 struct usb_hub *hub; in update_port_device_state() local
2055 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2059 * has a test step to unbind the hub before running the in update_port_device_state()
2061 * which will set the hub's maxchild to 0, further in update_port_device_state()
2064 if (hub) { in update_port_device_state()
2065 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2074 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2078 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2079 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2119 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2168 /* be safe when more hub events are proceed in parallel */ in choose_devnum()
2210 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2215 if (hub->ports[i]->child) in hub_disconnect_children()
2216 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2228 * If *pdev is a normal device then the parent hub must already be locked.
2229 * If *pdev is a root hub then the caller must hold the usb_bus_idr_lock,
2232 * Only hub drivers (including virtual root hub drivers for host
2241 struct usb_hub *hub = NULL; in usb_disconnect() local
2272 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2273 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2282 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2307 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2487 struct usb_hub *hub; in set_usb_port_removable() local
2497 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2503 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2516 * Otherwise, check whether the hub knows whether a port is removable in set_usb_port_removable()
2519 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2525 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2529 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2547 * the parent hub (if udev is a normal device) or else the
2548 * usb_bus_idr_lock (if udev is a root hub). The parent's pointer to
2554 * Only the hub driver or root-hub registrar should ever call this.
2566 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2607 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2622 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2624 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2638 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2724 * @hdev: The hub device
2854 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2859 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2862 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2870 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2885 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2886 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2891 ret = usb_hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2911 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2919 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2930 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2932 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2943 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2947 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2955 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2967 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2972 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2975 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2977 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2990 if (usb_hub_port_status(hub, port1, &portstatus, in hub_port_reset()
2992 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2996 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3000 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3004 ; /* The hub is gone */ in hub_port_reset()
3010 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
3013 dev_dbg(hub->intfdev, in hub_port_reset()
3024 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3027 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3030 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3032 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3036 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3043 if (usb_hub_port_status(hub, port1, in hub_port_reset()
3047 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3078 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
3079 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3102 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3110 * @hub: target hub
3126 static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) in hub_port_stop_enumerate() argument
3128 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3151 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) in usb_port_is_power_on() argument
3155 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3183 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3187 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3203 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3206 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3212 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3216 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3217 !usb_port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3223 status = usb_hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3247 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3250 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3255 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3260 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3363 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3366 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3372 * @udev: device that's no longer in active use, not a root hub
3397 * Devices on USB hub ports have only one "suspend" state, corresponding
3406 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3412 * hub is suspended). Nevertheless, we change @udev->state to
3420 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3421 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3429 * wake up the upstream hub (including maybe the root hub). in usb_port_suspend()
3456 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3457 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3462 * into suspend a few ms after the root hub stops sending packets. in usb_port_suspend()
3471 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3486 ret = usb_hub_port_status(hub, port1, &portstatus, in usb_port_suspend()
3492 if (ret == 0 && port_is_suspended(hub, portstatus)) { in usb_port_suspend()
3528 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3531 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3656 struct usb_hub *hub, int port1, in wait_for_connected() argument
3664 if (!usb_port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3670 status = usb_hub_port_status(hub, port1, portstatus, portchange); in wait_for_connected()
3678 * @udev: device to re-activate, not a root hub
3712 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3713 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3718 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3730 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3731 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3738 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3739 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3741 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3755 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3761 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3763 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3767 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3776 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3780 hub, port1, status, portchange, portstatus); in usb_port_resume()
3785 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3817 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3821 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3828 hdev = hub->hdev; in hub_handle_remote_wakeup()
3854 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3860 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3864 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3868 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3877 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3878 struct usb_device *hdev = hub->hdev; in hub_suspend()
3885 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3887 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3897 hub->wakeup_enabled_descendants += in hub_suspend()
3901 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3902 /* check if there are changes pending on hub ports */ in hub_suspend()
3903 if (check_ports_changed(hub)) { in hub_suspend()
3911 /* Enable hub to send remote wakeup for all ports. */ in hub_suspend()
3925 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3929 /* Report wakeup requests from the ports of a resuming root hub */
3930 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3932 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3939 return; /* Not a root hub */ in report_wakeup_requests()
3955 udev = hub->ports[i]->child; in report_wakeup_requests()
3965 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3968 hub_activate(hub, HUB_RESUME); in hub_resume()
3976 report_wakeup_requests(hub); in hub_resume()
3982 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
3985 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
3990 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3991 * @rhdev: struct usb_device for the root hub
3993 * The USB host controller driver calls this function when its root hub
3996 * When the hub driver is resumed it will take notice and carry out
4002 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4231 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4235 * control transfers to set the hub timeout or enable device-initiated U1/U2
4239 * hub-initiated U1/U2 will be disabled.
4241 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
4286 /* If we can't set the parent hub U1/U2 timeout, in usb_enable_link_state()
4316 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4319 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4323 * it won't have an effect on the bus link state because the parent hub will
4353 /* As soon as usb_set_lpm_timeout(0) return 0, hub initiated LPM in usb_disable_link_state()
4354 * is disabled. Hub will disallows link to enter U1/U2 as well, in usb_disable_link_state()
4355 * even device is initiating LPM. Hence LPM is disabled if hub LPM in usb_disable_link_state()
4368 * Disable hub-initiated and device-initiated U1 and U2 entry.
4424 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4434 struct usb_hub *hub; in usb_enable_lpm() local
4455 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4456 if (!hub) in usb_enable_lpm()
4459 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4484 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4491 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4510 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4540 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4558 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4560 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4561 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4564 if (!hub->error) { in hub_port_disable()
4565 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4566 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4567 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4590 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4592 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4610 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4616 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4619 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4636 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4669 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address() local
4671 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4710 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4716 if (hub) in hub_set_initial_usb2_lpm_policy()
4717 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4819 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4822 struct usb_device *hdev = hub->hdev; in hub_port_init()
4824 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4840 /* root hub ports have a slightly longer reset period in hub_port_init()
4856 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4925 if (!hub->tt.hub) { in hub_port_init()
4926 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4930 udev->tt = &hub->tt; in hub_port_init()
4950 if (hub_port_stop_enumerate(hub, port1, retries)) { in hub_port_init()
4959 "hub failed to enable device, error %d\n", in hub_port_init()
4973 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
5108 * and attached to a superspeed hub port, but the device descriptor in hub_port_init()
5115 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); in hub_port_init()
5139 hub_port_disable(hub, port1, 0); in hub_port_init()
5147 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5163 "connect to a high speed hub\n"); in check_highspeed()
5164 /* hub LEDs are probably harder to miss than syslog */ in check_highspeed()
5165 if (hub->has_indicators) { in check_highspeed()
5166 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5168 &hub->leds, 0); in check_highspeed()
5175 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
5177 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5181 if (!hub->limited_power) in hub_power_remaining()
5184 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5186 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5208 if (delta > hub->mA_per_port) in hub_power_remaining()
5210 delta, hub->mA_per_port); in hub_power_remaining()
5214 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5306 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5312 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5314 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5331 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5335 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5352 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5355 * maybe switch power back on (e.g. root hub was reset) in hub_port_connect()
5358 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5359 && !usb_port_is_power_on(hub, portstatus) in hub_port_connect()
5367 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5375 if (hub_port_stop_enumerate(hub, port1, i)) { in hub_port_connect()
5396 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5400 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5412 status = hub_port_init(hub, udev, port1, i, NULL); in hub_port_connect()
5441 "can't connect bus-powered hub " in hub_port_connect()
5443 if (hub->has_indicators) { in hub_port_connect()
5444 hub->indicator[port1-1] = in hub_port_connect()
5448 &hub->leds, 0); in hub_port_connect()
5459 check_highspeed(hub, udev, port1); in hub_port_connect()
5469 /* We mustn't add new devices if the parent hub has in hub_port_connect()
5500 status = hub_power_remaining(hub); in hub_port_connect()
5502 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5507 hub_port_disable(hub, port1, 1); in hub_port_connect()
5523 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5524 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5525 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5526 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5529 if (hub->hdev->parent || in hub_port_connect()
5538 hub_port_disable(hub, port1, 1); in hub_port_connect()
5539 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5551 * caller already locked the hub
5553 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5557 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5563 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5565 if (hub->has_indicators) { in hub_port_connect_change()
5566 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5567 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5572 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5616 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5623 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5627 /* Handle notifying userspace about hub over-current events */
5662 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5666 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5668 struct usb_device *hdev = hub->hdev; in port_event()
5672 connect_change = test_bit(port1, hub->change_bits); in port_event()
5673 clear_bit(port1, hub->event_bits); in port_event()
5674 clear_bit(port1, hub->wakeup_bits); in port_event()
5676 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5692 * to be shutdown by the hub, this hack enables them again. in port_event()
5697 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5712 hub_power_on(hub, true); in port_event()
5713 usb_hub_port_status(hub, port1, &status, &unused); in port_event()
5747 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5756 while (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5761 usb_hub_port_status(hub, port1, &portstatus, &unused); in port_event()
5767 if (hub_port_reset(hub, port1, NULL, in port_event()
5769 hub_port_disable(hub, port1, 1); in port_event()
5783 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5790 struct usb_hub *hub; in hub_event() local
5796 hub = container_of(work, struct usb_hub, events); in hub_event()
5797 hdev = hub->hdev; in hub_event()
5798 hub_dev = hub->intfdev; in hub_event()
5806 (u16) hub->change_bits[0], in hub_event()
5807 (u16) hub->event_bits[0]); in hub_event()
5812 if (unlikely(hub->disconnected)) in hub_event()
5815 /* If the hub has died, clean up after it */ in hub_event()
5817 hub->error = -ENODEV; in hub_event()
5818 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5829 /* If this is an inactive hub, do nothing */ in hub_event()
5830 if (hub->quiescing) in hub_event()
5833 if (hub->error) { in hub_event()
5834 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5838 dev_dbg(hub_dev, "error resetting hub: %d\n", ret); in hub_event()
5842 hub->nerrors = 0; in hub_event()
5843 hub->error = 0; in hub_event()
5848 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5850 if (test_bit(i, hub->event_bits) in hub_event()
5851 || test_bit(i, hub->change_bits) in hub_event()
5852 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5865 port_event(hub, i); in hub_event()
5871 /* deal with hub status changes */ in hub_event()
5872 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5874 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5882 hub->limited_power = 1; in hub_event()
5884 hub->limited_power = 0; in hub_event()
5893 hub_power_on(hub, true); in hub_event()
5894 hub_hub_status(hub, &status, &unused); in hub_event()
5908 kref_put(&hub->kref, hub_release); in hub_event()
5966 .name = "hub",
5982 printk(KERN_ERR "%s: can't register hub driver\n", in usb_hub_init()
5999 pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name); in usb_hub_init()
6009 * Hub resources are freed for us by usb_deregister. It calls in usb_hub_cleanup()
6013 * individual hub resources. -greg in usb_hub_cleanup()
6223 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
6233 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6241 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6349 * @hdev: USB device belonging to the usb hub
6353 * USB drivers call this function to get hub's child device
6362 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6366 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6373 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6377 if (!hub) in usb_hub_adjust_deviceremovable()
6382 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6398 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6418 * @hdev: USB device belonging to the usb hub
6427 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6429 if (!hub) in usb_get_hub_port_acpi_handle()
6432 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()