Lines Matching refs:hub
133 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
134 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
137 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
139 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
141 if (hub_is_superspeed(hub->hdev)) in portspeed()
212 struct usb_hub *hub, in usb_set_lpm_mel() argument
227 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
235 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
246 if (!hub->hdev->parent) in usb_set_lpm_mel()
259 struct usb_hub *hub, in usb_set_lpm_pel() argument
335 struct usb_hub *hub; in usb_set_lpm_parameters() local
349 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
353 if (!hub) in usb_set_lpm_parameters()
362 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
365 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
387 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
396 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
487 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
489 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
492 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
502 struct usb_hub *hub = in led_work() local
504 struct usb_device *hdev = hub->hdev; in led_work()
509 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
517 switch (hub->indicator[i]) { in led_work()
556 set_port_led(hub, i + 1, selector); in led_work()
557 hub->indicator[i] = mode; in led_work()
562 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
563 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
568 &hub->leds, LED_CYCLE_PERIOD); in led_work()
610 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
619 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
620 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
623 dev_err(hub->intfdev, in hub_ext_port_status()
628 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
629 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
632 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
635 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
639 int usb_hub_port_status(struct usb_hub *hub, int port1, in usb_hub_port_status() argument
642 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in usb_hub_port_status()
646 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
651 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
653 if (hub->quiescing) { in hub_resubmit_irq_urb()
654 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
658 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
661 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
662 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
665 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
670 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
672 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
676 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
680 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
691 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
693 hub_get(hub); in kick_hub_wq()
695 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
700 hub_put(hub); in kick_hub_wq()
705 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
707 if (hub) in usb_kick_hub_wq()
708 kick_hub_wq(hub); in usb_kick_hub_wq()
722 struct usb_hub *hub; in usb_wakeup_notification() local
728 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
729 if (hub) { in usb_wakeup_notification()
730 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
734 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
735 kick_hub_wq(hub); in usb_wakeup_notification()
743 struct usb_hub *hub = urb->context; in hub_irq() local
756 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
757 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
759 hub->error = status; in hub_irq()
766 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
768 hub->event_bits[0] = bits; in hub_irq()
772 hub->nerrors = 0; in hub_irq()
775 kick_hub_wq(hub); in hub_irq()
778 hub_resubmit_irq_urb(hub); in hub_irq()
807 struct usb_hub *hub = in hub_tt_work() local
811 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
812 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
815 struct usb_device *hdev = hub->hdev; in hub_tt_work()
819 next = hub->tt.clear_list.next; in hub_tt_work()
824 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
837 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
839 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
854 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
868 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
870 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
930 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
940 if (hub_is_port_power_switchable(hub)) in hub_power_on()
941 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
943 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
945 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
946 if (test_bit(port1, hub->power_bits)) in hub_power_on()
947 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
949 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
952 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
955 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
960 mutex_lock(&hub->status_mutex); in hub_hub_status()
961 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
964 dev_err(hub->intfdev, in hub_hub_status()
967 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
968 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
971 mutex_unlock(&hub->status_mutex); in hub_hub_status()
975 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
978 return set_port_feature(hub->hdev, in hub_set_port_link_state()
988 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
990 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
991 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
1002 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1003 kick_hub_wq(hub); in hub_port_logical_disconnect()
1020 struct usb_hub *hub; in usb_remove_device() local
1026 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1027 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1033 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1034 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1047 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1049 struct usb_device *hdev = hub->hdev; in hub_activate()
1062 if (hub->disconnected) in hub_activate()
1068 hub_get(hub); in hub_activate()
1087 dev_err(hub->intfdev, in hub_activate()
1104 delay = hub_power_on_good_delay(hub); in hub_activate()
1106 hub_power_on(hub, false); in hub_activate()
1107 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1109 &hub->init_work, in hub_activate()
1114 to_usb_interface(hub->intfdev)); in hub_activate()
1124 &hub->tt, GFP_NOIO); in hub_activate()
1126 dev_err(hub->intfdev, in hub_activate()
1128 dev_err(hub->intfdev, in hub_activate()
1132 hub_power_on(hub, true); in hub_activate()
1134 hub_power_on(hub, true); in hub_activate()
1137 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1147 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1152 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1185 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1186 set_bit(port1, hub->event_bits); in hub_activate()
1201 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1206 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1211 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1215 hub_is_superspeed(hub->hdev)) { in hub_activate()
1217 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1225 clear_bit(port1, hub->removed_bits); in hub_activate()
1238 set_bit(port1, hub->change_bits); in hub_activate()
1252 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1254 set_bit(port1, hub->event_bits); in hub_activate()
1263 if (test_bit(port1, hub->power_bits)) in hub_activate()
1264 set_bit(port1, hub->change_bits); in hub_activate()
1269 set_bit(port1, hub->change_bits); in hub_activate()
1286 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1288 &hub->init_work, in hub_activate()
1297 hub->quiescing = 0; in hub_activate()
1299 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1301 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1302 if (hub->has_indicators && blinkenlights) in hub_activate()
1304 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1307 kick_hub_wq(hub); in hub_activate()
1312 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1316 hub_put(hub); in hub_activate()
1322 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1324 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1329 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1331 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1338 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1340 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1345 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1346 hub->quiescing = 1; in hub_quiesce()
1347 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1352 if (hub->ports[i]->child) in hub_quiesce()
1353 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1358 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1359 usb_kill_urb(hub->urb); in hub_quiesce()
1360 if (hub->has_indicators) in hub_quiesce()
1361 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1362 if (hub->tt.hub) in hub_quiesce()
1363 flush_work(&hub->tt.clear_work); in hub_quiesce()
1366 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1370 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1371 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1377 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1379 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1380 hub->in_reset = 1; in hub_pre_reset()
1381 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1388 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1390 hub->in_reset = 0; in hub_post_reset()
1391 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1392 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1396 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1400 struct usb_device *hdev = hub->hdev; in hub_configure()
1401 struct device *hub_dev = hub->intfdev; in hub_configure()
1411 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1412 if (!hub->buffer) { in hub_configure()
1417 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1418 if (!hub->status) { in hub_configure()
1422 mutex_init(&hub->status_mutex); in hub_configure()
1424 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1425 if (!hub->descriptor) { in hub_configure()
1434 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1444 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1448 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1459 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1468 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1472 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1473 if (!hub->ports) { in hub_configure()
1478 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1493 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1527 spin_lock_init(&hub->tt.lock); in hub_configure()
1528 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1529 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1535 hub->tt.hub = hdev; in hub_configure()
1541 hub->tt.multi = 1; in hub_configure()
1545 hub->tt.hub = hdev; in hub_configure()
1560 hub->tt.think_time = 666; in hub_configure()
1563 8, hub->tt.think_time); in hub_configure()
1567 hub->tt.think_time = 666 * 2; in hub_configure()
1570 16, hub->tt.think_time); in hub_configure()
1573 hub->tt.think_time = 666 * 3; in hub_configure()
1576 24, hub->tt.think_time); in hub_configure()
1579 hub->tt.think_time = 666 * 4; in hub_configure()
1582 32, hub->tt.think_time); in hub_configure()
1588 hub->has_indicators = 1; in hub_configure()
1593 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1610 hub->mA_per_port = full_load; in hub_configure()
1612 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1613 hub->limited_power = 1; in hub_configure()
1617 hub->descriptor->bHubContrCurrent; in hub_configure()
1620 hub->descriptor->bHubContrCurrent); in hub_configure()
1621 hub->limited_power = 1; in hub_configure()
1627 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1632 hub->mA_per_port = full_load; in hub_configure()
1634 if (hub->mA_per_port < full_load) in hub_configure()
1636 hub->mA_per_port); in hub_configure()
1638 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1663 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1664 maxp = sizeof(*hub->buffer); in hub_configure()
1666 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1667 if (!hub->urb) { in hub_configure()
1672 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1673 hub, endpoint->bInterval); in hub_configure()
1676 if (hub->has_indicators && blinkenlights) in hub_configure()
1677 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1681 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1683 dev_err(hub->intfdev, in hub_configure()
1690 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1704 &hub->tt, GFP_KERNEL); in hub_configure()
1711 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1713 hub_activate(hub, HUB_INIT); in hub_configure()
1725 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1727 usb_put_dev(hub->hdev); in hub_release()
1728 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1729 kfree(hub); in hub_release()
1732 void hub_get(struct usb_hub *hub) in hub_get() argument
1734 kref_get(&hub->kref); in hub_get()
1737 void hub_put(struct usb_hub *hub) in hub_put() argument
1739 kref_put(&hub->kref, hub_release); in hub_put()
1746 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1754 hub->disconnected = 1; in hub_disconnect()
1757 hub->error = 0; in hub_disconnect()
1758 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1770 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1774 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1777 usb_free_urb(hub->urb); in hub_disconnect()
1778 kfree(hub->ports); in hub_disconnect()
1779 kfree(hub->descriptor); in hub_disconnect()
1780 kfree(hub->status); in hub_disconnect()
1781 kfree(hub->buffer); in hub_disconnect()
1785 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1788 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1790 hub_put(hub); in hub_disconnect()
1816 struct usb_hub *hub; in hub_probe() local
1908 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1909 if (!hub) in hub_probe()
1912 kref_init(&hub->kref); in hub_probe()
1913 hub->intfdev = &intf->dev; in hub_probe()
1914 hub->hdev = hdev; in hub_probe()
1915 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1916 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1917 INIT_WORK(&hub->events, hub_event); in hub_probe()
1918 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1919 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1920 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1924 usb_set_intfdata(intf, hub); in hub_probe()
1932 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1935 hub->quirk_disable_autosuspend = 1; in hub_probe()
1947 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1948 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1961 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1975 if (hub->ports[i]->child == NULL) in hub_ioctl()
1979 hub->ports[i]->child->devnum; in hub_ioctl()
1999 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
2009 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2048 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
2052 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2053 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2061 struct usb_hub *hub; in usb_device_is_owned() local
2065 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2066 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2071 struct usb_hub *hub; in update_port_device_state() local
2075 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2084 if (hub) { in update_port_device_state()
2085 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2094 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2098 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2099 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2230 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2235 if (hub->ports[i]->child) in hub_disconnect_children()
2236 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2261 struct usb_hub *hub = NULL; in usb_disconnect() local
2292 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2293 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2302 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2325 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2505 struct usb_hub *hub; in set_usb_port_removable() local
2515 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2521 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2537 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2543 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2547 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2640 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2642 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2656 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2872 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2877 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2880 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2888 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2903 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2904 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2909 ret = usb_hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2929 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2937 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2948 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2950 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2961 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2965 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2973 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2985 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2990 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2993 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2995 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
3008 if (usb_hub_port_status(hub, port1, &portstatus, in hub_port_reset()
3010 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3014 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3018 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3028 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
3031 dev_dbg(hub->intfdev, in hub_port_reset()
3042 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3045 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3048 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3050 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3054 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3061 if (usb_hub_port_status(hub, port1, in hub_port_reset()
3065 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3097 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3120 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3144 static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) in hub_port_stop_enumerate() argument
3146 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3169 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) in usb_port_is_power_on() argument
3173 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3201 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3205 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3221 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3224 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3230 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3234 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3235 !usb_port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3241 status = usb_hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3265 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3268 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3278 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3381 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3384 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3438 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3439 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3474 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3475 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3489 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3504 ret = usb_hub_port_status(hub, port1, &portstatus, in usb_port_suspend()
3510 if (ret == 0 && port_is_suspended(hub, portstatus)) { in usb_port_suspend()
3546 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3549 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3674 struct usb_hub *hub, int port1, in wait_for_connected() argument
3682 if (!usb_port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3688 status = usb_hub_port_status(hub, port1, portstatus, portchange); in wait_for_connected()
3730 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3731 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3736 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3748 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3749 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3756 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3757 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3759 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3773 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3779 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3781 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3785 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3794 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3798 hub, port1, status, portchange, portstatus); in usb_port_resume()
3803 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3835 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3839 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3846 hdev = hub->hdev; in hub_handle_remote_wakeup()
3872 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3878 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3882 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3886 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3895 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3896 struct usb_device *hdev = hub->hdev; in hub_suspend()
3903 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3905 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3915 hub->wakeup_enabled_descendants += in hub_suspend()
3919 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3921 if (check_ports_changed(hub)) { in hub_suspend()
3943 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3948 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3950 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3973 udev = hub->ports[i]->child; in report_wakeup_requests()
3983 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3986 hub_activate(hub, HUB_RESUME); in hub_resume()
3994 report_wakeup_requests(hub); in hub_resume()
4000 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
4003 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
4452 struct usb_hub *hub; in usb_enable_lpm() local
4473 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4474 if (!hub) in usb_enable_lpm()
4477 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4502 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4509 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4528 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4558 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4576 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4578 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4579 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4582 if (!hub->error) { in hub_port_disable()
4583 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4584 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4585 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4608 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4610 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4628 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4634 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4637 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4654 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4686 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address() local
4688 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4727 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4733 if (hub) in hub_set_initial_usb2_lpm_policy()
4734 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4836 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4839 struct usb_device *hdev = hub->hdev; in hub_port_init()
4841 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4873 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4942 if (!hub->tt.hub) { in hub_port_init()
4947 udev->tt = &hub->tt; in hub_port_init()
4967 if (hub_port_stop_enumerate(hub, port1, retries)) { in hub_port_init()
4990 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
5133 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); in hub_port_init()
5157 hub_port_disable(hub, port1, 0); in hub_port_init()
5165 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5183 if (hub->has_indicators) { in check_highspeed()
5184 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5186 &hub->leds, 0); in check_highspeed()
5193 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
5195 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5199 if (!hub->limited_power) in hub_power_remaining()
5202 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5204 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5226 if (delta > hub->mA_per_port) in hub_power_remaining()
5228 delta, hub->mA_per_port); in hub_power_remaining()
5232 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5324 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5330 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5332 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5349 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5353 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5370 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5376 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5377 && !usb_port_is_power_on(hub, portstatus) in hub_port_connect()
5385 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5393 if (hub_port_stop_enumerate(hub, port1, i)) { in hub_port_connect()
5414 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5418 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5430 status = hub_port_init(hub, udev, port1, i, NULL); in hub_port_connect()
5461 if (hub->has_indicators) { in hub_port_connect()
5462 hub->indicator[port1-1] = in hub_port_connect()
5466 &hub->leds, 0); in hub_port_connect()
5477 check_highspeed(hub, udev, port1); in hub_port_connect()
5518 status = hub_power_remaining(hub); in hub_port_connect()
5520 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5525 hub_port_disable(hub, port1, 1); in hub_port_connect()
5541 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5542 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5543 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5544 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5547 if (hub->hdev->parent || in hub_port_connect()
5556 hub_port_disable(hub, port1, 1); in hub_port_connect()
5557 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5571 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5575 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5581 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5583 if (hub->has_indicators) { in hub_port_connect_change()
5584 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5585 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5590 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5634 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5641 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5680 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5684 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5686 struct usb_device *hdev = hub->hdev; in port_event()
5690 connect_change = test_bit(port1, hub->change_bits); in port_event()
5691 clear_bit(port1, hub->event_bits); in port_event()
5692 clear_bit(port1, hub->wakeup_bits); in port_event()
5694 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5730 hub_power_on(hub, true); in port_event()
5731 usb_hub_port_status(hub, port1, &status, &unused); in port_event()
5765 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5774 while (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5779 usb_hub_port_status(hub, port1, &portstatus, &unused); in port_event()
5785 if (hub_port_reset(hub, port1, NULL, in port_event()
5787 hub_port_disable(hub, port1, 1); in port_event()
5801 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5808 struct usb_hub *hub; in hub_event() local
5814 hub = container_of(work, struct usb_hub, events); in hub_event()
5815 hdev = hub->hdev; in hub_event()
5816 hub_dev = hub->intfdev; in hub_event()
5824 (u16) hub->change_bits[0], in hub_event()
5825 (u16) hub->event_bits[0]); in hub_event()
5830 if (unlikely(hub->disconnected)) in hub_event()
5835 hub->error = -ENODEV; in hub_event()
5836 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5848 if (hub->quiescing) in hub_event()
5851 if (hub->error) { in hub_event()
5852 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5860 hub->nerrors = 0; in hub_event()
5861 hub->error = 0; in hub_event()
5866 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5868 if (test_bit(i, hub->event_bits) in hub_event()
5869 || test_bit(i, hub->change_bits) in hub_event()
5870 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5883 port_event(hub, i); in hub_event()
5890 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5892 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5900 hub->limited_power = 1; in hub_event()
5902 hub->limited_power = 0; in hub_event()
5911 hub_power_on(hub, true); in hub_event()
5912 hub_hub_status(hub, &status, &unused); in hub_event()
5926 hub_put(hub); in hub_event()
6053 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_hc_release_resources() local
6059 if (hub->ports[i]->child) in hub_hc_release_resources()
6060 hub_hc_release_resources(hub->ports[i]->child); in hub_hc_release_resources()
6274 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
6292 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6413 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6417 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6424 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6428 if (!hub) in usb_hub_adjust_deviceremovable()
6433 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6449 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6478 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6480 if (!hub) in usb_get_hub_port_acpi_handle()
6483 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()