Lines Matching refs:hub

114 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
115 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
118 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
120 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
122 if (hub_is_superspeed(hub->hdev)) in portspeed()
188 struct usb_hub *hub, in usb_set_lpm_mel() argument
206 (hub->descriptor->u.ss.bHubHdrDecLat * 100); in usb_set_lpm_mel()
233 struct usb_hub *hub, in usb_set_lpm_pel() argument
309 struct usb_hub *hub; in usb_set_lpm_parameters() local
319 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
323 if (!hub) in usb_set_lpm_parameters()
332 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
335 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
357 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
366 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
457 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
459 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
462 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
472 struct usb_hub *hub = in led_work() local
474 struct usb_device *hdev = hub->hdev; in led_work()
479 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
487 switch (hub->indicator[i]) { in led_work()
526 set_port_led(hub, i + 1, selector); in led_work()
527 hub->indicator[i] = mode; in led_work()
532 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
533 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
538 &hub->leds, LED_CYCLE_PERIOD); in led_work()
580 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
589 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
590 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
593 dev_err(hub->intfdev, in hub_ext_port_status()
598 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
599 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
602 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
605 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
609 static int hub_port_status(struct usb_hub *hub, int port1, in hub_port_status() argument
612 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in hub_port_status()
616 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
621 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
623 if (hub->quiescing) { in hub_resubmit_irq_urb()
624 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
628 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
631 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
632 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
635 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
640 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
642 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
646 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
650 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
661 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
663 kref_get(&hub->kref); in kick_hub_wq()
665 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
670 kref_put(&hub->kref, hub_release); in kick_hub_wq()
675 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
677 if (hub) in usb_kick_hub_wq()
678 kick_hub_wq(hub); in usb_kick_hub_wq()
692 struct usb_hub *hub; in usb_wakeup_notification() local
698 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
699 if (hub) { in usb_wakeup_notification()
700 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
704 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
705 kick_hub_wq(hub); in usb_wakeup_notification()
713 struct usb_hub *hub = urb->context; in hub_irq() local
726 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
727 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
729 hub->error = status; in hub_irq()
736 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
738 hub->event_bits[0] = bits; in hub_irq()
742 hub->nerrors = 0; in hub_irq()
745 kick_hub_wq(hub); in hub_irq()
748 hub_resubmit_irq_urb(hub); in hub_irq()
777 struct usb_hub *hub = in hub_tt_work() local
781 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
782 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
785 struct usb_device *hdev = hub->hdev; in hub_tt_work()
789 next = hub->tt.clear_list.next; in hub_tt_work()
794 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
807 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
809 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
824 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
838 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
840 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
900 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
910 if (hub_is_port_power_switchable(hub)) in hub_power_on()
911 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
913 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
915 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
916 if (test_bit(port1, hub->power_bits)) in hub_power_on()
917 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
919 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
922 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
925 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
930 mutex_lock(&hub->status_mutex); in hub_hub_status()
931 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
934 dev_err(hub->intfdev, in hub_hub_status()
937 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
938 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
941 mutex_unlock(&hub->status_mutex); in hub_hub_status()
945 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
948 return set_port_feature(hub->hdev, in hub_set_port_link_state()
958 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
960 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
961 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
972 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
973 kick_hub_wq(hub); in hub_port_logical_disconnect()
990 struct usb_hub *hub; in usb_remove_device() local
996 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
997 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1003 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1004 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1017 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1019 struct usb_device *hdev = hub->hdev; in hub_activate()
1032 if (hub->disconnected) in hub_activate()
1038 kref_get(&hub->kref); in hub_activate()
1057 dev_err(hub->intfdev, in hub_activate()
1074 delay = hub_power_on_good_delay(hub); in hub_activate()
1076 hub_power_on(hub, false); in hub_activate()
1077 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1079 &hub->init_work, in hub_activate()
1084 to_usb_interface(hub->intfdev)); in hub_activate()
1094 &hub->tt, GFP_NOIO); in hub_activate()
1096 dev_err(hub->intfdev, in hub_activate()
1098 dev_err(hub->intfdev, in hub_activate()
1102 hub_power_on(hub, true); in hub_activate()
1104 hub_power_on(hub, true); in hub_activate()
1114 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1119 status = hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1152 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1153 set_bit(port1, hub->event_bits); in hub_activate()
1168 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1173 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1178 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1182 hub_is_superspeed(hub->hdev)) { in hub_activate()
1184 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1192 clear_bit(port1, hub->removed_bits); in hub_activate()
1205 set_bit(port1, hub->change_bits); in hub_activate()
1219 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1221 set_bit(port1, hub->change_bits); in hub_activate()
1230 if (test_bit(port1, hub->power_bits)) in hub_activate()
1231 set_bit(port1, hub->change_bits); in hub_activate()
1236 set_bit(port1, hub->change_bits); in hub_activate()
1253 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1255 &hub->init_work, in hub_activate()
1264 hub->quiescing = 0; in hub_activate()
1266 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1268 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1269 if (hub->has_indicators && blinkenlights) in hub_activate()
1271 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1274 kick_hub_wq(hub); in hub_activate()
1279 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1283 kref_put(&hub->kref, hub_release); in hub_activate()
1289 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1291 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1296 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1298 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1305 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1307 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1312 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1313 hub->quiescing = 1; in hub_quiesce()
1314 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1319 if (hub->ports[i]->child) in hub_quiesce()
1320 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1325 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1326 usb_kill_urb(hub->urb); in hub_quiesce()
1327 if (hub->has_indicators) in hub_quiesce()
1328 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1329 if (hub->tt.hub) in hub_quiesce()
1330 flush_work(&hub->tt.clear_work); in hub_quiesce()
1333 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1337 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1338 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1344 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1346 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1347 hub->in_reset = 1; in hub_pre_reset()
1348 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1355 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1357 hub->in_reset = 0; in hub_post_reset()
1358 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1359 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1363 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1367 struct usb_device *hdev = hub->hdev; in hub_configure()
1368 struct device *hub_dev = hub->intfdev; in hub_configure()
1378 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1379 if (!hub->buffer) { in hub_configure()
1384 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1385 if (!hub->status) { in hub_configure()
1389 mutex_init(&hub->status_mutex); in hub_configure()
1391 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1392 if (!hub->descriptor) { in hub_configure()
1401 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1411 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1415 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1426 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1435 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1439 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1440 if (!hub->ports) { in hub_configure()
1445 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1460 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1494 spin_lock_init(&hub->tt.lock); in hub_configure()
1495 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1496 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1502 hub->tt.hub = hdev; in hub_configure()
1508 hub->tt.multi = 1; in hub_configure()
1512 hub->tt.hub = hdev; in hub_configure()
1527 hub->tt.think_time = 666; in hub_configure()
1530 8, hub->tt.think_time); in hub_configure()
1534 hub->tt.think_time = 666 * 2; in hub_configure()
1537 16, hub->tt.think_time); in hub_configure()
1540 hub->tt.think_time = 666 * 3; in hub_configure()
1543 24, hub->tt.think_time); in hub_configure()
1546 hub->tt.think_time = 666 * 4; in hub_configure()
1549 32, hub->tt.think_time); in hub_configure()
1555 hub->has_indicators = 1; in hub_configure()
1560 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1577 hub->mA_per_port = full_load; in hub_configure()
1579 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1580 hub->limited_power = 1; in hub_configure()
1584 hub->descriptor->bHubContrCurrent; in hub_configure()
1587 hub->descriptor->bHubContrCurrent); in hub_configure()
1588 hub->limited_power = 1; in hub_configure()
1594 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1599 hub->mA_per_port = full_load; in hub_configure()
1601 if (hub->mA_per_port < full_load) in hub_configure()
1603 hub->mA_per_port); in hub_configure()
1605 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1630 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1631 maxp = sizeof(*hub->buffer); in hub_configure()
1633 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1634 if (!hub->urb) { in hub_configure()
1639 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1640 hub, endpoint->bInterval); in hub_configure()
1643 if (hub->has_indicators && blinkenlights) in hub_configure()
1644 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1648 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1650 dev_err(hub->intfdev, in hub_configure()
1657 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1671 &hub->tt, GFP_KERNEL); in hub_configure()
1678 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1680 hub_activate(hub, HUB_INIT); in hub_configure()
1692 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1694 usb_put_dev(hub->hdev); in hub_release()
1695 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1696 kfree(hub); in hub_release()
1703 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1711 hub->disconnected = 1; in hub_disconnect()
1714 hub->error = 0; in hub_disconnect()
1715 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1727 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1731 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1734 usb_free_urb(hub->urb); in hub_disconnect()
1735 kfree(hub->ports); in hub_disconnect()
1736 kfree(hub->descriptor); in hub_disconnect()
1737 kfree(hub->status); in hub_disconnect()
1738 kfree(hub->buffer); in hub_disconnect()
1742 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1745 kref_put(&hub->kref, hub_release); in hub_disconnect()
1771 struct usb_hub *hub; in hub_probe() local
1852 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1853 if (!hub) in hub_probe()
1856 kref_init(&hub->kref); in hub_probe()
1857 hub->intfdev = &intf->dev; in hub_probe()
1858 hub->hdev = hdev; in hub_probe()
1859 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1860 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1861 INIT_WORK(&hub->events, hub_event); in hub_probe()
1862 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1863 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1867 usb_set_intfdata(intf, hub); in hub_probe()
1875 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1878 hub->quirk_disable_autosuspend = 1; in hub_probe()
1882 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) in hub_probe()
1893 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1907 if (hub->ports[i]->child == NULL) in hub_ioctl()
1911 hub->ports[i]->child->devnum; in hub_ioctl()
1931 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
1941 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1980 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
1984 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
1985 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
1993 struct usb_hub *hub; in usb_device_is_owned() local
1997 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
1998 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2003 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
2007 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2008 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2161 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2166 if (hub->ports[i]->child) in hub_disconnect_children()
2167 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2191 struct usb_hub *hub = NULL; in usb_disconnect() local
2222 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2223 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2232 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2255 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2428 struct usb_hub *hub; in set_usb_port_removable() local
2436 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2442 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2458 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2464 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2468 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2562 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2564 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2578 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2698 static unsigned hub_is_wusb(struct usb_hub *hub) in hub_is_wusb() argument
2701 if (hub->hdev->parent != NULL) /* not a root hub? */ in hub_is_wusb()
2703 hcd = bus_to_hcd(hub->hdev->bus); in hub_is_wusb()
2759 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2764 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2767 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2775 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2790 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2791 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2796 ret = hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2816 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2824 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2835 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2837 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2848 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2856 if (hub_is_wusb(hub)) in hub_port_wait_reset()
2858 else if (hub_is_superspeedplus(hub->hdev) && in hub_port_wait_reset()
2859 port_speed_is_ssp(hub->hdev, ext_portstatus & in hub_port_wait_reset()
2862 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2874 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2879 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2882 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2884 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2897 if (hub_port_status(hub, port1, &portstatus, &portchange) == 0) in hub_port_reset()
2898 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2902 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2906 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2916 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2919 dev_dbg(hub->intfdev, in hub_port_reset()
2926 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2929 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2932 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2934 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2938 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2945 if (hub_port_status(hub, port1, in hub_port_reset()
2949 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2981 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3004 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3011 static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) in port_is_power_on() argument
3015 if (hub_is_superspeed(hub->hdev)) { in port_is_power_on()
3043 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3047 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3063 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3066 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3072 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3076 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3077 !port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3083 status = hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3107 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3110 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3120 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3223 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3226 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3280 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3281 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3316 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3317 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3331 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3367 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3370 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3495 struct usb_hub *hub, int *port1, in wait_for_connected() argument
3503 if (!port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3509 status = hub_port_status(hub, *port1, portstatus, portchange); in wait_for_connected()
3551 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3552 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3557 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3569 status = hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3570 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3577 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3578 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3580 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3594 status = hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3603 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3605 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3609 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3615 status = wait_for_connected(udev, hub, &port1, &portchange, in usb_port_resume()
3619 hub, port1, status, portchange, portstatus); in usb_port_resume()
3624 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3656 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3660 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3667 hdev = hub->hdev; in hub_handle_remote_wakeup()
3693 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3699 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3703 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3707 status = hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3716 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3717 struct usb_device *hdev = hub->hdev; in hub_suspend()
3724 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3726 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3736 hub->wakeup_enabled_descendants += in hub_suspend()
3740 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3742 if (check_ports_changed(hub)) { in hub_suspend()
3764 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3769 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3771 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3794 udev = hub->ports[i]->child; in report_wakeup_requests()
3804 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3807 hub_activate(hub, HUB_RESUME); in hub_resume()
3815 report_wakeup_requests(hub); in hub_resume()
3821 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
3824 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
4246 struct usb_hub *hub; in usb_enable_lpm() local
4267 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4268 if (!hub) in usb_enable_lpm()
4271 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4296 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4303 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4322 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4352 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4365 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4367 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4368 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4371 if (!hub->error) { in hub_port_disable()
4372 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4373 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4374 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4397 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4399 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4417 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4423 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4426 ret = hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4443 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4512 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4518 if (hub) in hub_set_initial_usb2_lpm_policy()
4519 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4553 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4556 struct usb_device *hdev = hub->hdev; in hub_port_init()
4558 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4585 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4657 if (!hub->tt.hub) { in hub_port_init()
4662 udev->tt = &hub->tt; in hub_port_init()
4740 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4837 hub_port_reset(hub, port1, udev, in hub_port_init()
4890 hub_port_disable(hub, port1, 0); in hub_port_init()
4898 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
4916 if (hub->has_indicators) { in check_highspeed()
4917 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
4919 &hub->leds, 0); in check_highspeed()
4926 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
4928 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
4932 if (!hub->limited_power) in hub_power_remaining()
4935 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
4937 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
4959 if (delta > hub->mA_per_port) in hub_power_remaining()
4961 delta, hub->mA_per_port); in hub_power_remaining()
4965 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5057 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
5063 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5065 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5081 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5085 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
5102 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5108 if (hub_is_port_power_switchable(hub) in hub_port_connect()
5109 && !port_is_power_on(hub, portstatus) in hub_port_connect()
5117 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5136 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5138 udev->wusb = hub_is_wusb(hub); in hub_port_connect()
5141 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5154 status = hub_port_init(hub, udev, port1, i); in hub_port_connect()
5182 if (hub->has_indicators) { in hub_port_connect()
5183 hub->indicator[port1-1] = in hub_port_connect()
5187 &hub->leds, 0); in hub_port_connect()
5198 check_highspeed(hub, udev, port1); in hub_port_connect()
5239 status = hub_power_remaining(hub); in hub_port_connect()
5241 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5246 hub_port_disable(hub, port1, 1); in hub_port_connect()
5258 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5259 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5260 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5261 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5264 if (hub->hdev->parent || in hub_port_connect()
5273 hub_port_disable(hub, port1, 1); in hub_port_connect()
5274 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5288 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5292 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5299 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5301 if (hub->has_indicators) { in hub_port_connect_change()
5302 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5303 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5308 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5355 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5362 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5403 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5407 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5409 struct usb_device *hdev = hub->hdev; in port_event()
5412 connect_change = test_bit(port1, hub->change_bits); in port_event()
5413 clear_bit(port1, hub->event_bits); in port_event()
5414 clear_bit(port1, hub->wakeup_bits); in port_event()
5416 if (hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5452 hub_power_on(hub, true); in port_event()
5453 hub_port_status(hub, port1, &status, &unused); in port_event()
5483 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5490 if (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5494 if (hub_port_reset(hub, port1, NULL, in port_event()
5496 hub_port_disable(hub, port1, 1); in port_event()
5508 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5515 struct usb_hub *hub; in hub_event() local
5521 hub = container_of(work, struct usb_hub, events); in hub_event()
5522 hdev = hub->hdev; in hub_event()
5523 hub_dev = hub->intfdev; in hub_event()
5531 (u16) hub->change_bits[0], in hub_event()
5532 (u16) hub->event_bits[0]); in hub_event()
5537 if (unlikely(hub->disconnected)) in hub_event()
5542 hub->error = -ENODEV; in hub_event()
5543 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5555 if (hub->quiescing) in hub_event()
5558 if (hub->error) { in hub_event()
5559 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5567 hub->nerrors = 0; in hub_event()
5568 hub->error = 0; in hub_event()
5573 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5575 if (test_bit(i, hub->event_bits) in hub_event()
5576 || test_bit(i, hub->change_bits) in hub_event()
5577 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5590 port_event(hub, i); in hub_event()
5597 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5599 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5607 hub->limited_power = 1; in hub_event()
5609 hub->limited_power = 0; in hub_event()
5618 hub_power_on(hub, true); in hub_event()
5619 hub_hub_status(hub, &status, &unused); in hub_event()
5633 kref_put(&hub->kref, hub_release); in hub_event()
5919 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
5933 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6053 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
6057 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6064 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
6068 if (!hub) in usb_hub_adjust_deviceremovable()
6073 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6089 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6118 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6120 if (!hub) in usb_get_hub_port_acpi_handle()
6123 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()