Lines Matching refs:hub

128 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
129 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
132 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
134 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
136 if (hub_is_superspeed(hub->hdev)) in portspeed()
207 struct usb_hub *hub, in usb_set_lpm_mel() argument
222 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
230 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
241 if (!hub->hdev->parent) in usb_set_lpm_mel()
254 struct usb_hub *hub, in usb_set_lpm_pel() argument
330 struct usb_hub *hub; in usb_set_lpm_parameters() local
344 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
348 if (!hub) in usb_set_lpm_parameters()
357 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
360 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
382 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
391 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
482 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
484 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
487 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
497 struct usb_hub *hub = in led_work() local
499 struct usb_device *hdev = hub->hdev; in led_work()
504 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
512 switch (hub->indicator[i]) { in led_work()
551 set_port_led(hub, i + 1, selector); in led_work()
552 hub->indicator[i] = mode; in led_work()
557 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
558 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
563 &hub->leds, LED_CYCLE_PERIOD); in led_work()
605 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
614 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
615 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
618 dev_err(hub->intfdev, in hub_ext_port_status()
623 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
624 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
627 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
630 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
634 int usb_hub_port_status(struct usb_hub *hub, int port1, in usb_hub_port_status() argument
637 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in usb_hub_port_status()
641 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
646 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
648 if (hub->quiescing) { in hub_resubmit_irq_urb()
649 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
653 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
656 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
657 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
660 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
665 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
667 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
671 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
675 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
686 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
688 kref_get(&hub->kref); in kick_hub_wq()
690 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
695 kref_put(&hub->kref, hub_release); in kick_hub_wq()
700 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
702 if (hub) in usb_kick_hub_wq()
703 kick_hub_wq(hub); in usb_kick_hub_wq()
717 struct usb_hub *hub; in usb_wakeup_notification() local
723 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
724 if (hub) { in usb_wakeup_notification()
725 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
729 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
730 kick_hub_wq(hub); in usb_wakeup_notification()
738 struct usb_hub *hub = urb->context; in hub_irq() local
751 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
752 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
754 hub->error = status; in hub_irq()
761 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
763 hub->event_bits[0] = bits; in hub_irq()
767 hub->nerrors = 0; in hub_irq()
770 kick_hub_wq(hub); in hub_irq()
773 hub_resubmit_irq_urb(hub); in hub_irq()
802 struct usb_hub *hub = in hub_tt_work() local
806 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
807 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
810 struct usb_device *hdev = hub->hdev; in hub_tt_work()
814 next = hub->tt.clear_list.next; in hub_tt_work()
819 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
832 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
834 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
849 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
863 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
865 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
925 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
935 if (hub_is_port_power_switchable(hub)) in hub_power_on()
936 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
938 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
940 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
941 if (test_bit(port1, hub->power_bits)) in hub_power_on()
942 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
944 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
947 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
950 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
955 mutex_lock(&hub->status_mutex); in hub_hub_status()
956 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
959 dev_err(hub->intfdev, in hub_hub_status()
962 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
963 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
966 mutex_unlock(&hub->status_mutex); in hub_hub_status()
970 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
973 return set_port_feature(hub->hdev, in hub_set_port_link_state()
983 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
985 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
986 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
997 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
998 kick_hub_wq(hub); in hub_port_logical_disconnect()
1015 struct usb_hub *hub; in usb_remove_device() local
1021 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1022 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1028 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1029 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1042 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1044 struct usb_device *hdev = hub->hdev; in hub_activate()
1057 if (hub->disconnected) in hub_activate()
1063 kref_get(&hub->kref); in hub_activate()
1082 dev_err(hub->intfdev, in hub_activate()
1099 delay = hub_power_on_good_delay(hub); in hub_activate()
1101 hub_power_on(hub, false); in hub_activate()
1102 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1104 &hub->init_work, in hub_activate()
1109 to_usb_interface(hub->intfdev)); in hub_activate()
1119 &hub->tt, GFP_NOIO); in hub_activate()
1121 dev_err(hub->intfdev, in hub_activate()
1123 dev_err(hub->intfdev, in hub_activate()
1127 hub_power_on(hub, true); in hub_activate()
1129 hub_power_on(hub, true); in hub_activate()
1132 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1142 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1147 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1180 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1181 set_bit(port1, hub->event_bits); in hub_activate()
1196 usb_clear_port_feature(hub->hdev, port1, 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()
1210 hub_is_superspeed(hub->hdev)) { in hub_activate()
1212 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1220 clear_bit(port1, hub->removed_bits); in hub_activate()
1233 set_bit(port1, hub->change_bits); in hub_activate()
1247 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1249 set_bit(port1, hub->event_bits); in hub_activate()
1258 if (test_bit(port1, hub->power_bits)) in hub_activate()
1259 set_bit(port1, hub->change_bits); in hub_activate()
1264 set_bit(port1, hub->change_bits); in hub_activate()
1281 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1283 &hub->init_work, in hub_activate()
1292 hub->quiescing = 0; in hub_activate()
1294 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1296 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1297 if (hub->has_indicators && blinkenlights) in hub_activate()
1299 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1302 kick_hub_wq(hub); in hub_activate()
1307 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1311 kref_put(&hub->kref, hub_release); in hub_activate()
1317 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1319 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1324 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1326 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1333 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1335 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1340 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1341 hub->quiescing = 1; in hub_quiesce()
1342 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1347 if (hub->ports[i]->child) in hub_quiesce()
1348 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1353 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1354 usb_kill_urb(hub->urb); in hub_quiesce()
1355 if (hub->has_indicators) in hub_quiesce()
1356 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1357 if (hub->tt.hub) in hub_quiesce()
1358 flush_work(&hub->tt.clear_work); in hub_quiesce()
1361 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1365 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1366 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1372 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1374 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1375 hub->in_reset = 1; in hub_pre_reset()
1376 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1383 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1385 hub->in_reset = 0; in hub_post_reset()
1386 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1387 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1391 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1395 struct usb_device *hdev = hub->hdev; in hub_configure()
1396 struct device *hub_dev = hub->intfdev; in hub_configure()
1406 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1407 if (!hub->buffer) { in hub_configure()
1412 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1413 if (!hub->status) { in hub_configure()
1417 mutex_init(&hub->status_mutex); in hub_configure()
1419 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1420 if (!hub->descriptor) { in hub_configure()
1429 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1439 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1443 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1454 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1463 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1467 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1468 if (!hub->ports) { in hub_configure()
1473 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1488 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1522 spin_lock_init(&hub->tt.lock); in hub_configure()
1523 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1524 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1530 hub->tt.hub = hdev; in hub_configure()
1536 hub->tt.multi = 1; in hub_configure()
1540 hub->tt.hub = hdev; in hub_configure()
1555 hub->tt.think_time = 666; in hub_configure()
1558 8, hub->tt.think_time); in hub_configure()
1562 hub->tt.think_time = 666 * 2; in hub_configure()
1565 16, hub->tt.think_time); in hub_configure()
1568 hub->tt.think_time = 666 * 3; in hub_configure()
1571 24, hub->tt.think_time); in hub_configure()
1574 hub->tt.think_time = 666 * 4; in hub_configure()
1577 32, hub->tt.think_time); in hub_configure()
1583 hub->has_indicators = 1; in hub_configure()
1588 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1605 hub->mA_per_port = full_load; in hub_configure()
1607 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1608 hub->limited_power = 1; in hub_configure()
1612 hub->descriptor->bHubContrCurrent; in hub_configure()
1615 hub->descriptor->bHubContrCurrent); in hub_configure()
1616 hub->limited_power = 1; in hub_configure()
1622 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1627 hub->mA_per_port = full_load; in hub_configure()
1629 if (hub->mA_per_port < full_load) in hub_configure()
1631 hub->mA_per_port); in hub_configure()
1633 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1658 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1659 maxp = sizeof(*hub->buffer); in hub_configure()
1661 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1662 if (!hub->urb) { in hub_configure()
1667 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1668 hub, endpoint->bInterval); in hub_configure()
1671 if (hub->has_indicators && blinkenlights) in hub_configure()
1672 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1676 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1678 dev_err(hub->intfdev, in hub_configure()
1685 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1699 &hub->tt, GFP_KERNEL); in hub_configure()
1706 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1708 hub_activate(hub, HUB_INIT); in hub_configure()
1720 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1722 usb_put_dev(hub->hdev); in hub_release()
1723 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1724 kfree(hub); in hub_release()
1731 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1739 hub->disconnected = 1; in hub_disconnect()
1742 hub->error = 0; in hub_disconnect()
1743 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1755 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1759 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1762 usb_free_urb(hub->urb); in hub_disconnect()
1763 kfree(hub->ports); in hub_disconnect()
1764 kfree(hub->descriptor); in hub_disconnect()
1765 kfree(hub->status); in hub_disconnect()
1766 kfree(hub->buffer); in hub_disconnect()
1770 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1773 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1775 kref_put(&hub->kref, hub_release); in hub_disconnect()
1801 struct usb_hub *hub; in hub_probe() local
1882 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1883 if (!hub) in hub_probe()
1886 kref_init(&hub->kref); in hub_probe()
1887 hub->intfdev = &intf->dev; in hub_probe()
1888 hub->hdev = hdev; in hub_probe()
1889 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1890 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1891 INIT_WORK(&hub->events, hub_event); in hub_probe()
1892 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1893 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1894 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1898 usb_set_intfdata(intf, hub); in hub_probe()
1906 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1909 hub->quirk_disable_autosuspend = 1; in hub_probe()
1921 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1922 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1935 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1949 if (hub->ports[i]->child == NULL) in hub_ioctl()
1953 hub->ports[i]->child->devnum; in hub_ioctl()
1973 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
1983 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2022 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
2026 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2027 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2035 struct usb_hub *hub; in usb_device_is_owned() local
2039 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2040 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2045 struct usb_hub *hub; in update_port_device_state() local
2049 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2058 if (hub) { in update_port_device_state()
2059 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2068 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2072 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2073 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2204 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2209 if (hub->ports[i]->child) in hub_disconnect_children()
2210 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2235 struct usb_hub *hub = NULL; in usb_disconnect() local
2266 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2267 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2276 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2299 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2479 struct usb_hub *hub; in set_usb_port_removable() local
2489 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2495 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2511 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2517 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2521 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2614 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2616 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2630 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2844 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2849 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2852 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2860 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2875 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2876 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2881 ret = usb_hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2901 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2909 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2920 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2922 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2933 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2937 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2945 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2957 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2962 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2965 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2967 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2980 if (usb_hub_port_status(hub, port1, &portstatus, in hub_port_reset()
2982 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2986 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2990 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3000 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
3003 dev_dbg(hub->intfdev, in hub_port_reset()
3014 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3017 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3020 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3022 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3026 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3033 if (usb_hub_port_status(hub, port1, in hub_port_reset()
3037 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
3069 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3092 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3116 static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries) in hub_port_stop_enumerate() argument
3118 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3141 int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus) in usb_port_is_power_on() argument
3145 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3173 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3177 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3193 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3196 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3202 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3206 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3207 !usb_port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3213 status = usb_hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3237 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3240 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3250 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3353 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3356 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3410 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3411 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3446 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3447 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3461 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3476 ret = usb_hub_port_status(hub, port1, &portstatus, in usb_port_suspend()
3482 if (ret == 0 && port_is_suspended(hub, portstatus)) { in usb_port_suspend()
3518 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3521 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3646 struct usb_hub *hub, int port1, in wait_for_connected() argument
3654 if (!usb_port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3660 status = usb_hub_port_status(hub, port1, portstatus, portchange); in wait_for_connected()
3702 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3703 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3708 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3720 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3721 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3728 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3729 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3731 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3745 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3751 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3753 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3757 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3766 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3770 hub, port1, status, portchange, portstatus); in usb_port_resume()
3775 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3807 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3811 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3818 hdev = hub->hdev; in hub_handle_remote_wakeup()
3844 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3850 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3854 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3858 status = usb_hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3867 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3868 struct usb_device *hdev = hub->hdev; in hub_suspend()
3875 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3877 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3887 hub->wakeup_enabled_descendants += in hub_suspend()
3891 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3893 if (check_ports_changed(hub)) { in hub_suspend()
3915 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3920 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3922 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3945 udev = hub->ports[i]->child; in report_wakeup_requests()
3955 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3958 hub_activate(hub, HUB_RESUME); in hub_resume()
3966 report_wakeup_requests(hub); in hub_resume()
3972 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
3975 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
4424 struct usb_hub *hub; in usb_enable_lpm() local
4445 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4446 if (!hub) in usb_enable_lpm()
4449 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4474 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4481 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4500 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4530 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4548 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4550 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4551 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4554 if (!hub->error) { in hub_port_disable()
4555 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4556 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4557 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4580 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4582 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4600 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4606 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4609 ret = usb_hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4626 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4695 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4701 if (hub) in hub_set_initial_usb2_lpm_policy()
4702 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4804 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4807 struct usb_device *hdev = hub->hdev; in hub_port_init()
4809 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4841 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4910 if (!hub->tt.hub) { in hub_port_init()
4915 udev->tt = &hub->tt; in hub_port_init()
4935 if (hub_port_stop_enumerate(hub, port1, retries)) { in hub_port_init()
4958 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
5100 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); in hub_port_init()
5124 hub_port_disable(hub, port1, 0); in hub_port_init()
5132 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5150 if (hub->has_indicators) { in check_highspeed()
5151 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5153 &hub->leds, 0); in check_highspeed()
5160 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
5162 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5166 if (!hub->limited_power) in hub_power_remaining()
5169 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5171 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5193 if (delta > hub->mA_per_port) in hub_power_remaining()
5195 delta, hub->mA_per_port); in hub_power_remaining()
5199 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5291 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5297 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5299 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5316 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5320 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5337 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5343 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5344 && !usb_port_is_power_on(hub, portstatus) in hub_port_connect()
5352 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5360 if (hub_port_stop_enumerate(hub, port1, i)) { in hub_port_connect()
5381 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5385 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5397 status = hub_port_init(hub, udev, port1, i, NULL); in hub_port_connect()
5428 if (hub->has_indicators) { in hub_port_connect()
5429 hub->indicator[port1-1] = in hub_port_connect()
5433 &hub->leds, 0); in hub_port_connect()
5444 check_highspeed(hub, udev, port1); in hub_port_connect()
5485 status = hub_power_remaining(hub); in hub_port_connect()
5487 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5492 hub_port_disable(hub, port1, 1); in hub_port_connect()
5508 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5509 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5510 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5511 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5514 if (hub->hdev->parent || in hub_port_connect()
5523 hub_port_disable(hub, port1, 1); in hub_port_connect()
5524 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5538 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5542 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5548 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5550 if (hub->has_indicators) { in hub_port_connect_change()
5551 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5552 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5557 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5601 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5608 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5647 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5651 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5653 struct usb_device *hdev = hub->hdev; in port_event()
5657 connect_change = test_bit(port1, hub->change_bits); in port_event()
5658 clear_bit(port1, hub->event_bits); in port_event()
5659 clear_bit(port1, hub->wakeup_bits); in port_event()
5661 if (usb_hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5697 hub_power_on(hub, true); in port_event()
5698 usb_hub_port_status(hub, port1, &status, &unused); in port_event()
5732 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5741 while (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5746 usb_hub_port_status(hub, port1, &portstatus, &unused); in port_event()
5752 if (hub_port_reset(hub, port1, NULL, in port_event()
5754 hub_port_disable(hub, port1, 1); in port_event()
5768 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5775 struct usb_hub *hub; in hub_event() local
5781 hub = container_of(work, struct usb_hub, events); in hub_event()
5782 hdev = hub->hdev; in hub_event()
5783 hub_dev = hub->intfdev; in hub_event()
5791 (u16) hub->change_bits[0], in hub_event()
5792 (u16) hub->event_bits[0]); in hub_event()
5797 if (unlikely(hub->disconnected)) in hub_event()
5802 hub->error = -ENODEV; in hub_event()
5803 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5815 if (hub->quiescing) in hub_event()
5818 if (hub->error) { in hub_event()
5819 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5827 hub->nerrors = 0; in hub_event()
5828 hub->error = 0; in hub_event()
5833 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5835 if (test_bit(i, hub->event_bits) in hub_event()
5836 || test_bit(i, hub->change_bits) in hub_event()
5837 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5850 port_event(hub, i); in hub_event()
5857 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5859 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5867 hub->limited_power = 1; in hub_event()
5869 hub->limited_power = 0; in hub_event()
5878 hub_power_on(hub, true); in hub_event()
5879 hub_hub_status(hub, &status, &unused); in hub_event()
5893 kref_put(&hub->kref, hub_release); in hub_event()
6208 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
6226 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6347 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6351 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6358 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6362 if (!hub) in usb_hub_adjust_deviceremovable()
6367 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6383 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6412 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6414 if (!hub) in usb_get_hub_port_acpi_handle()
6417 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()