Lines Matching full:hub

3  * USB hub driver.
41 #include "hub.h"
75 * assuming no port activity and allowing hub to runtime suspend back.
84 /* workqueue to process hub events */
88 /* synchronize hub-port add/remove and peering operations */
116 * hub driver's behavior. On the first initialization attempt, if the
143 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
144 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
147 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
149 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
151 if (hub_is_superspeed(hub->hdev)) in portspeed()
222 struct usb_hub *hub, in usb_set_lpm_mel() argument
232 * and the hub header decode latency. See USB 3.1 section C 2.2.1 in usb_set_lpm_mel()
237 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
241 * each link + wHubDelay for each hub. Add only for last link. in usb_set_lpm_mel()
245 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
256 if (!hub->hdev->parent) in usb_set_lpm_mel()
269 struct usb_hub *hub, in usb_set_lpm_pel() argument
279 * device and the parent hub into U0. The exit latency is the bigger of in usb_set_lpm_pel()
280 * the device exit latency or the hub exit latency. in usb_set_lpm_pel()
285 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
288 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
339 struct usb_hub *hub; in usb_set_lpm_parameters() local
353 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
357 if (!hub) in usb_set_lpm_parameters()
366 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
369 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
373 * when the parent hub notices the downstream port is trying to in usb_set_lpm_parameters()
374 * transition to U0 to when the hub initiates a U0 transition on its in usb_set_lpm_parameters()
378 * The hub chapter, sections 10.4.2.4 and 10.4.2.5 seem to be talking in usb_set_lpm_parameters()
382 * assume the device exit latencies they are talking about are the hub in usb_set_lpm_parameters()
391 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
400 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
491 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
493 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
496 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
506 struct usb_hub *hub = in led_work() local
508 struct usb_device *hdev = hub->hdev; in led_work()
513 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
521 switch (hub->indicator[i]) { in led_work()
560 set_port_led(hub, i + 1, selector); in led_work()
561 hub->indicator[i] = mode; in led_work()
566 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
567 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
572 &hub->leds, LED_CYCLE_PERIOD); in led_work()
575 /* use a short timeout for hub/port status fetches */
614 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
623 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
624 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
627 dev_err(hub->intfdev, in hub_ext_port_status()
632 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
633 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
636 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
639 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
643 * protects hub->status, and the phy driver only checks the port in hub_ext_port_status()
647 struct usb_device *hdev = hub->hdev; in hub_ext_port_status()
671 int usb_hub_port_status(struct usb_hub *hub, int port1, in usb_hub_port_status() argument
674 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in usb_hub_port_status()
678 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
683 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
685 if (hub->quiescing) { in hub_resubmit_irq_urb()
686 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
690 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
693 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
694 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
697 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
702 struct usb_hub *hub = timer_container_of(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
704 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
708 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
712 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
720 * work for this hub. Therefore put the interface either when in kick_hub_wq()
723 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
725 hub_get(hub); in kick_hub_wq()
727 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
732 hub_put(hub); in kick_hub_wq()
737 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
739 if (hub) in usb_kick_hub_wq()
740 kick_hub_wq(hub); in usb_kick_hub_wq()
749 * resume through the normal hub interrupt URB.
754 struct usb_hub *hub; in usb_wakeup_notification() local
760 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
761 if (hub) { in usb_wakeup_notification()
762 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
766 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
767 kick_hub_wq(hub); in usb_wakeup_notification()
775 struct usb_hub *hub = urb->context; in hub_irq() local
787 /* Cause a hub reset after 10 consecutive errors */ in hub_irq()
788 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
789 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
791 hub->error = status; in hub_irq()
798 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
800 hub->event_bits[0] = bits; in hub_irq()
804 hub->nerrors = 0; in hub_irq()
807 kick_hub_wq(hub); in hub_irq()
810 hub_resubmit_irq_urb(hub); in hub_irq()
835 * both can talk to the same hub concurrently.
839 struct usb_hub *hub = in hub_tt_work() local
843 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
844 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
847 struct usb_device *hdev = hub->hdev; in hub_tt_work()
851 next = hub->tt.clear_list.next; in hub_tt_work()
856 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
869 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
871 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
875 * usb_hub_set_port_power - control hub port's power state
876 * @hdev: USB device belonging to the usb hub
877 * @hub: target hub
886 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
900 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
902 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
907 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
910 * High speed HCDs use this to tell the hub driver that some split control or
915 * It may not be possible for that hub to handle additional full (or low)
930 * there can be many TTs per hub). even if they're uncommon. in usb_hub_clear_tt_buffer()
962 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
970 * unless we send these messages to the hub. in hub_power_on()
972 if (hub_is_port_power_switchable(hub)) in hub_power_on()
973 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
975 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
976 "non-switchable hub\n"); in hub_power_on()
977 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
978 if (test_bit(port1, hub->power_bits)) in hub_power_on()
979 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
981 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
984 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
987 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
992 mutex_lock(&hub->status_mutex); in hub_hub_status()
993 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
996 dev_err(hub->intfdev, in hub_hub_status()
999 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
1000 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
1003 mutex_unlock(&hub->status_mutex); in hub_hub_status()
1007 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
1010 return set_port_feature(hub->hdev, in hub_set_port_link_state()
1020 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
1022 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
1023 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
1029 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1034 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1035 kick_hub_wq(hub); in hub_port_logical_disconnect()
1039 * usb_remove_device - disable a device's port on its parent hub
1052 struct usb_hub *hub; in usb_remove_device() local
1056 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1058 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1059 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1065 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1066 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1079 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1081 struct usb_device *hdev = hub->hdev; in hub_activate()
1093 /* Was the hub disconnected while we were waiting? */ in hub_activate()
1094 if (hub->disconnected) in hub_activate()
1101 hub_get(hub); in hub_activate()
1103 /* The superspeed hub except for root hub has to use Hub Depth in hub_activate()
1105 * it uses to determine the downstream port number. So hub driver in hub_activate()
1106 * should send a set hub depth request to superspeed hub after in hub_activate()
1107 * the superspeed hub is set configuration in initialization or in hub_activate()
1120 dev_err(hub->intfdev, in hub_activate()
1121 "set hub depth failed\n"); in hub_activate()
1125 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1128 * root hub (assuming usbcore is compiled into the kernel in hub_activate()
1137 delay = hub_power_on_good_delay(hub); in hub_activate()
1139 hub_power_on(hub, false); in hub_activate()
1140 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1142 &hub->init_work, in hub_activate()
1147 to_usb_interface(hub->intfdev)); in hub_activate()
1150 /* The internal host controller state for the hub device in hub_activate()
1152 * Update the device's info so the HW knows it's a hub. in hub_activate()
1157 &hub->tt, GFP_NOIO); in hub_activate()
1159 dev_err(hub->intfdev, in hub_activate()
1160 "Host not accepting hub info update\n"); in hub_activate()
1161 dev_err(hub->intfdev, in hub_activate()
1162 "LS/FS devices and hubs may not work under this hub\n"); in hub_activate()
1165 hub_power_on(hub, true); in hub_activate()
1167 hub_power_on(hub, true); in hub_activate()
1170 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1176 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1180 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1185 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1218 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1219 set_bit(port1, hub->event_bits); in hub_activate()
1234 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1239 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1244 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1248 hub_is_superspeed(hub->hdev)) { in hub_activate()
1250 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1258 clear_bit(port1, hub->removed_bits); in hub_activate()
1271 set_bit(port1, hub->change_bits); in hub_activate()
1285 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1287 set_bit(port1, hub->event_bits); in hub_activate()
1296 if (test_bit(port1, hub->power_bits)) in hub_activate()
1297 set_bit(port1, hub->change_bits); in hub_activate()
1302 set_bit(port1, hub->change_bits); in hub_activate()
1319 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1321 &hub->init_work, in hub_activate()
1330 hub->quiescing = 0; in hub_activate()
1332 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1334 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1335 if (hub->has_indicators && blinkenlights) in hub_activate()
1337 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1340 kick_hub_wq(hub); in hub_activate()
1345 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1349 if (type == HUB_RESUME && hub_is_superspeed(hub->hdev)) { in hub_activate()
1350 /* give usb3 downstream links training time after hub resume */ in hub_activate()
1352 to_usb_interface(hub->intfdev)); in hub_activate()
1355 &hub->post_resume_work, in hub_activate()
1360 hub_put(hub); in hub_activate()
1366 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1368 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1373 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1375 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1380 struct usb_hub *hub = container_of(ws, struct usb_hub, post_resume_work.work); in hub_post_resume() local
1382 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_post_resume()
1383 hub_put(hub); in hub_post_resume()
1390 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1392 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1397 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1398 hub->quiescing = 1; in hub_quiesce()
1399 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1404 if (hub->ports[i]->child) in hub_quiesce()
1405 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1410 timer_delete_sync(&hub->irq_urb_retry); in hub_quiesce()
1411 flush_delayed_work(&hub->post_resume_work); in hub_quiesce()
1412 usb_kill_urb(hub->urb); in hub_quiesce()
1413 if (hub->has_indicators) in hub_quiesce()
1414 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1415 if (hub->tt.hub) in hub_quiesce()
1416 flush_work(&hub->tt.clear_work); in hub_quiesce()
1419 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1423 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1424 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1427 /* caller has locked the hub device */
1430 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1432 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1433 hub->in_reset = 1; in hub_pre_reset()
1434 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1438 /* caller has locked the hub device */
1441 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1443 hub->in_reset = 0; in hub_post_reset()
1444 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1445 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1449 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1453 struct usb_device *hdev = hub->hdev; in hub_configure()
1454 struct device *hub_dev = hub->intfdev; in hub_configure()
1464 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1465 if (!hub->buffer) { in hub_configure()
1470 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1471 if (!hub->status) { in hub_configure()
1475 mutex_init(&hub->status_mutex); in hub_configure()
1477 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1478 if (!hub->descriptor) { in hub_configure()
1483 /* Request the entire hub descriptor. in hub_configure()
1484 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1485 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1487 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1489 message = "can't read hub descriptor"; in hub_configure()
1497 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1498 message = "hub has too many ports!"; in hub_configure()
1501 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1502 message = "hub doesn't have any ports!"; in hub_configure()
1508 * Accumulate wHubDelay + 40ns for every hub in the tree of devices. in hub_configure()
1512 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1521 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1525 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1526 if (!hub->ports) { in hub_configure()
1531 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1546 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1552 dev_dbg(hub_dev, "standalone hub\n"); in hub_configure()
1580 spin_lock_init(&hub->tt.lock); in hub_configure()
1581 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1582 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1588 hub->tt.hub = hdev; in hub_configure()
1594 hub->tt.multi = 1; in hub_configure()
1598 hub->tt.hub = hdev; in hub_configure()
1604 dev_dbg(hub_dev, "Unrecognized hub protocol %d\n", in hub_configure()
1613 hub->tt.think_time = 666; in hub_configure()
1616 8, hub->tt.think_time); in hub_configure()
1620 hub->tt.think_time = 666 * 2; in hub_configure()
1623 16, hub->tt.think_time); in hub_configure()
1626 hub->tt.think_time = 666 * 3; in hub_configure()
1629 24, hub->tt.think_time); in hub_configure()
1632 hub->tt.think_time = 666 * 4; in hub_configure()
1635 32, hub->tt.think_time); in hub_configure()
1639 /* probe() zeroes hub->indicator[] */ in hub_configure()
1641 hub->has_indicators = 1; in hub_configure()
1646 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1653 message = "can't get hub status"; in hub_configure()
1663 hub->mA_per_port = full_load; in hub_configure()
1665 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1666 hub->limited_power = 1; in hub_configure()
1670 hub->descriptor->bHubContrCurrent; in hub_configure()
1672 dev_dbg(hub_dev, "hub controller current requirement: %dmA\n", in hub_configure()
1673 hub->descriptor->bHubContrCurrent); in hub_configure()
1674 hub->limited_power = 1; in hub_configure()
1680 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1682 } else { /* Self-powered external hub */ in hub_configure()
1685 hub->mA_per_port = full_load; in hub_configure()
1687 if (hub->mA_per_port < full_load) in hub_configure()
1689 hub->mA_per_port); in hub_configure()
1691 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1693 message = "can't get hub status"; in hub_configure()
1716 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1717 maxp = sizeof(*hub->buffer); in hub_configure()
1719 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1720 if (!hub->urb) { in hub_configure()
1725 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1726 hub, endpoint->bInterval); in hub_configure()
1728 /* maybe cycle the hub leds */ in hub_configure()
1729 if (hub->has_indicators && blinkenlights) in hub_configure()
1730 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1734 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1736 dev_err(hub->intfdev, in hub_configure()
1743 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1752 /* Update the HCD's internal representation of this hub before hub_wq in hub_configure()
1753 * starts getting port status changes for devices under the hub. in hub_configure()
1757 &hub->tt, GFP_KERNEL); in hub_configure()
1759 message = "can't update HCD hub info"; in hub_configure()
1764 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1766 hub_activate(hub, HUB_INIT); in hub_configure()
1778 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1780 usb_put_dev(hub->hdev); in hub_release()
1781 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1782 kfree(hub); in hub_release()
1785 void hub_get(struct usb_hub *hub) in hub_get() argument
1787 kref_get(&hub->kref); in hub_get()
1790 void hub_put(struct usb_hub *hub) in hub_put() argument
1792 kref_put(&hub->kref, hub_release); in hub_put()
1799 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1804 * Stop adding new hub events. We do not want to block here and thus in hub_disconnect()
1807 hub->disconnected = 1; in hub_disconnect()
1809 /* Disconnect all children and quiesce the hub */ in hub_disconnect()
1810 hub->error = 0; in hub_disconnect()
1811 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1823 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1827 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1830 usb_free_urb(hub->urb); in hub_disconnect()
1831 kfree(hub->ports); in hub_disconnect()
1832 kfree(hub->descriptor); in hub_disconnect()
1833 kfree(hub->status); in hub_disconnect()
1834 kfree(hub->buffer); in hub_disconnect()
1838 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1841 onboard_dev_destroy_pdevs(&hub->onboard_devs); in hub_disconnect()
1843 hub_put(hub); in hub_disconnect()
1854 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1869 struct usb_hub *hub; in hub_probe() local
1881 dev_err(&intf->dev, "Invalid hub with more than one config or interface\n"); in hub_probe()
1889 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1892 * change on hub downstream ports, so it is safe to do it. in hub_probe()
1895 * below very rare devices when they are plugged into hub in hub_probe()
1906 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1911 * hub during running 'lsusb', but it is probably too in hub_probe()
1914 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1915 * suspend timer for hub, also may decrease power consumption in hub_probe()
1933 } else { /* root hub */ in hub_probe()
1942 "Unsupported bus topology: hub nested too deep\n"); in hub_probe()
1948 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1954 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1958 /* We found a hub */ in hub_probe()
1959 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1961 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1962 if (!hub) in hub_probe()
1965 kref_init(&hub->kref); in hub_probe()
1966 hub->intfdev = &intf->dev; in hub_probe()
1967 hub->hdev = hdev; in hub_probe()
1968 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1969 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1970 INIT_DELAYED_WORK(&hub->post_resume_work, hub_post_resume); in hub_probe()
1971 INIT_WORK(&hub->events, hub_event); in hub_probe()
1972 INIT_LIST_HEAD(&hub->onboard_devs); in hub_probe()
1973 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1974 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1978 usb_set_intfdata(intf, hub); in hub_probe()
1986 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1989 hub->quirk_disable_autosuspend = 1; in hub_probe()
2001 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
2002 onboard_dev_create_pdevs(hdev, &hub->onboard_devs); in hub_probe()
2015 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
2017 /* assert ifno == 0 (part of hub spec) */ in hub_ioctl()
2029 if (hub->ports[i]->child == NULL) in hub_ioctl()
2033 hub->ports[i]->child->devnum; in hub_ioctl()
2047 * Allow user programs to claim ports on a hub. When a device is attached
2053 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
2060 /* Devices not managed by the hub driver in find_port_owner()
2063 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2102 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
2106 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2107 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2115 struct usb_hub *hub; in usb_device_is_owned() local
2119 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2120 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2125 struct usb_hub *hub; in update_port_device_state() local
2129 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2133 * has a test step to unbind the hub before running the in update_port_device_state()
2135 * which will set the hub's maxchild to 0, further in update_port_device_state()
2138 if (hub) { in update_port_device_state()
2139 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2163 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2167 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2168 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2205 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2247 /* be safe when more hub events are proceed in parallel */ in choose_devnum()
2288 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2293 if (hub->ports[i]->child) in hub_disconnect_children()
2294 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2306 * If *pdev is a normal device then the parent hub must already be locked.
2307 * If *pdev is a root hub then the caller must hold the usb_bus_idr_lock,
2310 * Only hub drivers (including virtual root hub drivers for host
2319 struct usb_hub *hub = NULL; in usb_disconnect() local
2350 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2351 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2360 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2388 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2568 struct usb_hub *hub; in set_usb_port_removable() local
2578 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2584 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2597 * Otherwise, check whether the hub knows whether a port is removable in set_usb_port_removable()
2600 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2606 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2610 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2628 * the parent hub (if udev is a normal device) or else the
2629 * usb_bus_idr_lock (if udev is a root hub). The parent's pointer to
2635 * Only the hub driver or root-hub registrar should ever call this.
2647 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2688 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2703 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2705 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2719 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2807 * @hdev: The hub device
2937 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2942 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2945 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2953 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2968 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2969 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2974 ret = usb_hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2994 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
3002 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
3013 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
3015 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
3026 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
3030 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
3038 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
3050 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
3055 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
3058 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
3060 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
3073 if (usb_hub_port_status(hub, port1, &portstatus, in hub_port_reset()
3075 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3079 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3083 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3087 ; /* The hub is gone */ in hub_port_reset()
3093 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
3096 dev_dbg(hub->intfdev, in hub_port_reset()
3107 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3110 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3113 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3115 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3119 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3126 if (usb_hub_port_status(hub, port1, in hub_port_reset()
3130 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3161 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
3162 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3185 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3193 * @hub: target hub
3209 static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) in hub_port_stop_enumerate() argument
3211 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3234 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) in usb_port_is_power_on() argument
3238 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3266 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3270 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3286 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3289 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3295 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3299 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3300 !usb_port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3306 status = usb_hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3330 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3333 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3338 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3343 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3446 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3449 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3455 * @udev: device that's no longer in active use, not a root hub
3480 * Devices on USB hub ports have only one "suspend" state, corresponding
3489 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3495 * hub is suspended). Nevertheless, we change @udev->state to
3503 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3504 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3512 * wake up the upstream hub (including maybe the root hub). in usb_port_suspend()
3539 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3540 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3545 * into suspend a few ms after the root hub stops sending packets. in usb_port_suspend()
3554 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3569 ret = usb_hub_port_status(hub, port1, &portstatus, in usb_port_suspend()
3575 if (ret == 0 && port_is_suspended(hub, portstatus)) { in usb_port_suspend()
3611 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3614 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3739 struct usb_hub *hub, int port1, in wait_for_connected() argument
3747 if (!usb_port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3753 status = usb_hub_port_status(hub, port1, portstatus, portchange); in wait_for_connected()
3761 * @udev: device to re-activate, not a root hub
3795 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3796 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3801 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3813 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3814 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3821 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3822 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3824 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3838 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3844 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3846 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3850 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3859 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3863 hub, port1, status, portchange, portstatus); in usb_port_resume()
3868 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3900 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3904 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3911 hdev = hub->hdev; in hub_handle_remote_wakeup()
3937 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3943 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3947 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3951 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3960 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3961 struct usb_device *hdev = hub->hdev; in hub_suspend()
3968 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3970 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3980 hub->wakeup_enabled_descendants += in hub_suspend()
3984 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3985 /* check if there are changes pending on hub ports */ in hub_suspend()
3986 if (check_ports_changed(hub)) { in hub_suspend()
3994 /* Enable hub to send remote wakeup for all ports. */ in hub_suspend()
4008 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
4012 /* Report wakeup requests from the ports of a resuming root hub */
4013 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
4015 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
4022 return; /* Not a root hub */ in report_wakeup_requests()
4038 udev = hub->ports[i]->child; in report_wakeup_requests()
4048 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
4051 hub_activate(hub, HUB_RESUME); in hub_resume()
4059 report_wakeup_requests(hub); in hub_resume()
4065 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
4068 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
4073 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
4074 * @rhdev: struct usb_device for the root hub
4076 * The USB host controller driver calls this function when its root hub
4079 * When the hub driver is resumed it will take notice and carry out
4085 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4313 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4317 * control transfers to set the hub timeout or enable device-initiated U1/U2
4321 * hub-initiated U1/U2 will be disabled.
4323 * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
4368 /* If we can't set the parent hub U1/U2 timeout, in usb_enable_link_state()
4384 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4387 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4391 * it won't have an effect on the bus link state because the parent hub will
4419 /* As soon as usb_set_lpm_timeout(0) return 0, hub initiated LPM in usb_disable_link_state()
4420 * is disabled. Hub will disallows link to enter U1/U2 as well, in usb_disable_link_state()
4421 * even device is initiating LPM. Hence LPM is disabled if hub LPM in usb_disable_link_state()
4434 * Disable hub-initiated and device-initiated U1 and U2 entry.
4496 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4506 struct usb_hub *hub; in usb_enable_lpm() local
4527 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4528 if (!hub) in usb_enable_lpm()
4531 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4570 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4577 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4596 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4626 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4644 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4646 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4647 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4650 if (!hub->error) { in hub_port_disable()
4651 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4652 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4653 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4676 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4678 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4696 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4702 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4705 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4722 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4752 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address() local
4754 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4793 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4799 if (hub) in hub_set_initial_usb2_lpm_policy()
4800 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4902 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4905 struct usb_device *hdev = hub->hdev; in hub_port_init()
4907 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4923 /* root hub ports have a slightly longer reset period in hub_port_init()
4939 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
5008 if (!hub->tt.hub) { in hub_port_init()
5009 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
5013 udev->tt = &hub->tt; in hub_port_init()
5033 if (hub_port_stop_enumerate(hub, port1, retries)) { in hub_port_init()
5042 "hub failed to enable device, error %d\n", in hub_port_init()
5056 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
5192 * and attached to a superspeed hub port, but the device descriptor in hub_port_init()
5199 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); in hub_port_init()
5223 hub_port_disable(hub, port1, 0); in hub_port_init()
5231 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5247 "connect to a high speed hub\n"); in check_highspeed()
5248 /* hub LEDs are probably harder to miss than syslog */ in check_highspeed()
5249 if (hub->has_indicators) { in check_highspeed()
5250 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5252 &hub->leds, 0); in check_highspeed()
5259 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
5261 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5265 if (!hub->limited_power) in hub_power_remaining()
5268 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5270 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5292 if (delta > hub->mA_per_port) in hub_power_remaining()
5294 delta, hub->mA_per_port); in hub_power_remaining()
5298 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5390 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5396 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5398 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5415 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5419 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5436 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5439 * maybe switch power back on (e.g. root hub was reset) in hub_port_connect()
5442 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5443 && !usb_port_is_power_on(hub, portstatus) in hub_port_connect()
5451 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5459 if (hub_port_stop_enumerate(hub, port1, i)) { in hub_port_connect()
5480 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5484 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5496 status = hub_port_init(hub, udev, port1, i, NULL); in hub_port_connect()
5525 "can't connect bus-powered hub " in hub_port_connect()
5527 if (hub->has_indicators) { in hub_port_connect()
5528 hub->indicator[port1-1] = in hub_port_connect()
5532 &hub->leds, 0); in hub_port_connect()
5543 check_highspeed(hub, udev, port1); in hub_port_connect()
5553 /* We mustn't add new devices if the parent hub has in hub_port_connect()
5584 status = hub_power_remaining(hub); in hub_port_connect()
5586 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5591 hub_port_disable(hub, port1, 1); in hub_port_connect()
5607 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5608 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5609 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5610 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5613 if (hub->hdev->parent || in hub_port_connect()
5622 hub_port_disable(hub, port1, 1); in hub_port_connect()
5623 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5635 * caller already locked the hub
5637 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5641 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5647 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5649 if (hub->has_indicators) { in hub_port_connect_change()
5650 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5651 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5656 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5700 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5707 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5711 /* Handle notifying userspace about hub over-current events */
5746 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5750 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5752 struct usb_device *hdev = hub->hdev; in port_event()
5757 connect_change = test_bit(port1, hub->change_bits); in port_event()
5758 clear_bit(port1, hub->event_bits); in port_event()
5759 clear_bit(port1, hub->wakeup_bits); in port_event()
5761 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5777 * to be shutdown by the hub, this hack enables them again. in port_event()
5782 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5797 hub_power_on(hub, true); in port_event()
5798 usb_hub_port_status(hub, port1, &status, &unused); in port_event()
5832 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5841 while (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5846 usb_hub_port_status(hub, port1, &portstatus, &unused); in port_event()
5852 err = hub_port_reset(hub, port1, NULL, in port_event()
5857 hub_port_disable(hub, port1, 1); in port_event()
5871 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5878 struct usb_hub *hub; in hub_event() local
5884 hub = container_of(work, struct usb_hub, events); in hub_event()
5885 hdev = hub->hdev; in hub_event()
5886 hub_dev = hub->intfdev; in hub_event()
5894 (u16) hub->change_bits[0], in hub_event()
5895 (u16) hub->event_bits[0]); in hub_event()
5900 if (unlikely(hub->disconnected)) in hub_event()
5903 /* If the hub has died, clean up after it */ in hub_event()
5905 hub->error = -ENODEV; in hub_event()
5906 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5917 /* If this is an inactive hub, do nothing */ in hub_event()
5918 if (hub->quiescing) in hub_event()
5921 if (hub->error) { in hub_event()
5922 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5926 dev_dbg(hub_dev, "error resetting hub: %d\n", ret); in hub_event()
5930 hub->nerrors = 0; in hub_event()
5931 hub->error = 0; in hub_event()
5936 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5938 if (test_bit(i, hub->event_bits) in hub_event()
5939 || test_bit(i, hub->change_bits) in hub_event()
5940 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5953 port_event(hub, i); in hub_event()
5959 /* deal with hub status changes */ in hub_event()
5960 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5962 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5970 hub->limited_power = 1; in hub_event()
5972 hub->limited_power = 0; in hub_event()
5981 hub_power_on(hub, true); in hub_event()
5982 hub_hub_status(hub, &status, &unused); in hub_event()
5996 hub_put(hub); in hub_event()
6054 .name = "hub",
6070 printk(KERN_ERR "%s: can't register hub driver\n", in usb_hub_init()
6087 pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name); in usb_hub_init()
6097 * Hub resources are freed for us by usb_deregister. It calls in usb_hub_cleanup()
6101 * individual hub resources. -greg in usb_hub_cleanup()
6115 * usb device in tree toward the root hub. This function is used only during
6123 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_hc_release_resources() local
6129 if (hub->ports[i]->child) in hub_hc_release_resources()
6130 hub_hc_release_resources(hub->ports[i]->child); in hub_hc_release_resources()
6356 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
6366 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6374 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6482 * @hdev: USB device belonging to the usb hub
6486 * USB drivers call this function to get hub's child device
6495 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6499 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6506 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6510 if (!hub) in usb_hub_adjust_deviceremovable()
6515 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6531 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6551 * @hdev: USB device belonging to the usb hub
6560 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6562 if (!hub) in usb_get_hub_port_acpi_handle()
6565 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()