Lines Matching refs:hub

110 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
111 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
114 static inline char *portspeed(struct usb_hub *hub, int portstatus) in portspeed() argument
116 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
118 if (hub_is_superspeed(hub->hdev)) in portspeed()
184 struct usb_hub *hub, in usb_set_lpm_mel() argument
202 (hub->descriptor->u.ss.bHubHdrDecLat * 100); in usb_set_lpm_mel()
229 struct usb_hub *hub, in usb_set_lpm_pel() argument
305 struct usb_hub *hub; in usb_set_lpm_parameters() local
315 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
319 if (!hub) in usb_set_lpm_parameters()
328 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
331 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
353 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
362 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
453 static void set_port_led(struct usb_hub *hub, int port1, int selector) in set_port_led() argument
455 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
458 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
468 struct usb_hub *hub = in led_work() local
470 struct usb_device *hdev = hub->hdev; in led_work()
475 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
483 switch (hub->indicator[i]) { in led_work()
522 set_port_led(hub, i + 1, selector); in led_work()
523 hub->indicator[i] = mode; in led_work()
528 set_port_led(hub, cursor + 1, HUB_LED_GREEN); in led_work()
529 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
534 &hub->leds, LED_CYCLE_PERIOD); in led_work()
576 static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, in hub_ext_port_status() argument
585 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
586 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
589 dev_err(hub->intfdev, in hub_ext_port_status()
594 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
595 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
598 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
601 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
605 static int hub_port_status(struct usb_hub *hub, int port1, in hub_port_status() argument
608 return hub_ext_port_status(hub, port1, HUB_PORT_STATUS, in hub_port_status()
612 static void hub_resubmit_irq_urb(struct usb_hub *hub) in hub_resubmit_irq_urb() argument
617 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
619 if (hub->quiescing) { in hub_resubmit_irq_urb()
620 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
624 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
627 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
628 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
631 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
636 struct usb_hub *hub = from_timer(hub, t, irq_urb_retry); in hub_retry_irq_urb() local
638 hub_resubmit_irq_urb(hub); in hub_retry_irq_urb()
642 static void kick_hub_wq(struct usb_hub *hub) in kick_hub_wq() argument
646 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
657 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
659 kref_get(&hub->kref); in kick_hub_wq()
661 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
666 kref_put(&hub->kref, hub_release); in kick_hub_wq()
671 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_kick_hub_wq() local
673 if (hub) in usb_kick_hub_wq()
674 kick_hub_wq(hub); in usb_kick_hub_wq()
688 struct usb_hub *hub; in usb_wakeup_notification() local
694 hub = usb_hub_to_struct_hub(hdev); in usb_wakeup_notification()
695 if (hub) { in usb_wakeup_notification()
696 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
700 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
701 kick_hub_wq(hub); in usb_wakeup_notification()
709 struct usb_hub *hub = urb->context; in hub_irq() local
722 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
723 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
725 hub->error = status; in hub_irq()
732 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
734 hub->event_bits[0] = bits; in hub_irq()
738 hub->nerrors = 0; in hub_irq()
741 kick_hub_wq(hub); in hub_irq()
744 hub_resubmit_irq_urb(hub); in hub_irq()
773 struct usb_hub *hub = in hub_tt_work() local
777 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
778 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
781 struct usb_device *hdev = hub->hdev; in hub_tt_work()
785 next = hub->tt.clear_list.next; in hub_tt_work()
790 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
803 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
805 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
820 int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, in usb_hub_set_port_power() argument
834 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
836 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
896 static void hub_power_on(struct usb_hub *hub, bool do_delay) in hub_power_on() argument
906 if (hub_is_port_power_switchable(hub)) in hub_power_on()
907 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
909 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
911 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
912 if (test_bit(port1, hub->power_bits)) in hub_power_on()
913 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
915 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
918 msleep(hub_power_on_good_delay(hub)); in hub_power_on()
921 static int hub_hub_status(struct usb_hub *hub, in hub_hub_status() argument
926 mutex_lock(&hub->status_mutex); in hub_hub_status()
927 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
930 dev_err(hub->intfdev, in hub_hub_status()
933 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
934 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
937 mutex_unlock(&hub->status_mutex); in hub_hub_status()
941 static int hub_set_port_link_state(struct usb_hub *hub, int port1, in hub_set_port_link_state() argument
944 return set_port_feature(hub->hdev, in hub_set_port_link_state()
954 static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) in hub_port_logical_disconnect() argument
956 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
957 hub_port_disable(hub, port1, 1); in hub_port_logical_disconnect()
968 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
969 kick_hub_wq(hub); in hub_port_logical_disconnect()
986 struct usb_hub *hub; in usb_remove_device() local
991 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
992 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
995 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
996 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1009 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) in hub_activate() argument
1011 struct usb_device *hdev = hub->hdev; in hub_activate()
1024 if (hub->disconnected) in hub_activate()
1030 kref_get(&hub->kref); in hub_activate()
1049 dev_err(hub->intfdev, in hub_activate()
1066 delay = hub_power_on_good_delay(hub); in hub_activate()
1068 hub_power_on(hub, false); in hub_activate()
1069 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1071 &hub->init_work, in hub_activate()
1076 to_usb_interface(hub->intfdev)); in hub_activate()
1086 &hub->tt, GFP_NOIO); in hub_activate()
1088 dev_err(hub->intfdev, in hub_activate()
1090 dev_err(hub->intfdev, in hub_activate()
1094 hub_power_on(hub, true); in hub_activate()
1096 hub_power_on(hub, true); in hub_activate()
1106 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1111 status = hub_port_status(hub, port1, &portstatus, &portchange); in hub_activate()
1144 hub_port_warm_reset_required(hub, port1, portstatus)) in hub_activate()
1145 set_bit(port1, hub->event_bits); in hub_activate()
1160 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1165 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1170 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1174 hub_is_superspeed(hub->hdev)) { in hub_activate()
1176 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1184 clear_bit(port1, hub->removed_bits); in hub_activate()
1196 set_bit(port1, hub->change_bits); in hub_activate()
1210 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1212 set_bit(port1, hub->change_bits); in hub_activate()
1221 if (test_bit(port1, hub->power_bits)) in hub_activate()
1222 set_bit(port1, hub->change_bits); in hub_activate()
1227 set_bit(port1, hub->change_bits); in hub_activate()
1244 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1246 &hub->init_work, in hub_activate()
1255 hub->quiescing = 0; in hub_activate()
1257 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1259 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1260 if (hub->has_indicators && blinkenlights) in hub_activate()
1262 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1265 kick_hub_wq(hub); in hub_activate()
1270 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1274 kref_put(&hub->kref, hub_release); in hub_activate()
1280 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func2() local
1282 hub_activate(hub, HUB_INIT2); in hub_init_func2()
1287 struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work); in hub_init_func3() local
1289 hub_activate(hub, HUB_INIT3); in hub_init_func3()
1296 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) in hub_quiesce() argument
1298 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1303 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1304 hub->quiescing = 1; in hub_quiesce()
1305 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1310 if (hub->ports[i]->child) in hub_quiesce()
1311 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1316 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1317 usb_kill_urb(hub->urb); in hub_quiesce()
1318 if (hub->has_indicators) in hub_quiesce()
1319 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1320 if (hub->tt.hub) in hub_quiesce()
1321 flush_work(&hub->tt.clear_work); in hub_quiesce()
1324 static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) in hub_pm_barrier_for_all_ports() argument
1328 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1329 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1335 struct usb_hub *hub = usb_get_intfdata(intf); in hub_pre_reset() local
1337 hub_quiesce(hub, HUB_PRE_RESET); in hub_pre_reset()
1338 hub->in_reset = 1; in hub_pre_reset()
1339 hub_pm_barrier_for_all_ports(hub); in hub_pre_reset()
1346 struct usb_hub *hub = usb_get_intfdata(intf); in hub_post_reset() local
1348 hub->in_reset = 0; in hub_post_reset()
1349 hub_pm_barrier_for_all_ports(hub); in hub_post_reset()
1350 hub_activate(hub, HUB_POST_RESET); in hub_post_reset()
1354 static int hub_configure(struct usb_hub *hub, in hub_configure() argument
1358 struct usb_device *hdev = hub->hdev; in hub_configure()
1359 struct device *hub_dev = hub->intfdev; in hub_configure()
1369 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1370 if (!hub->buffer) { in hub_configure()
1375 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1376 if (!hub->status) { in hub_configure()
1380 mutex_init(&hub->status_mutex); in hub_configure()
1382 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1383 if (!hub->descriptor) { in hub_configure()
1392 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1402 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1406 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1417 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1426 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1430 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1431 if (!hub->ports) { in hub_configure()
1436 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1451 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1485 spin_lock_init(&hub->tt.lock); in hub_configure()
1486 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1487 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1493 hub->tt.hub = hdev; in hub_configure()
1499 hub->tt.multi = 1; in hub_configure()
1503 hub->tt.hub = hdev; in hub_configure()
1518 hub->tt.think_time = 666; in hub_configure()
1521 8, hub->tt.think_time); in hub_configure()
1525 hub->tt.think_time = 666 * 2; in hub_configure()
1528 16, hub->tt.think_time); in hub_configure()
1531 hub->tt.think_time = 666 * 3; in hub_configure()
1534 24, hub->tt.think_time); in hub_configure()
1537 hub->tt.think_time = 666 * 4; in hub_configure()
1540 32, hub->tt.think_time); in hub_configure()
1546 hub->has_indicators = 1; in hub_configure()
1551 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1568 hub->mA_per_port = full_load; in hub_configure()
1570 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1571 hub->limited_power = 1; in hub_configure()
1575 hub->descriptor->bHubContrCurrent; in hub_configure()
1578 hub->descriptor->bHubContrCurrent); in hub_configure()
1579 hub->limited_power = 1; in hub_configure()
1585 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1590 hub->mA_per_port = full_load; in hub_configure()
1592 if (hub->mA_per_port < full_load) in hub_configure()
1594 hub->mA_per_port); in hub_configure()
1596 ret = hub_hub_status(hub, &hubstatus, &hubchange); in hub_configure()
1621 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1622 maxp = sizeof(*hub->buffer); in hub_configure()
1624 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1625 if (!hub->urb) { in hub_configure()
1630 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1631 hub, endpoint->bInterval); in hub_configure()
1634 if (hub->has_indicators && blinkenlights) in hub_configure()
1635 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1639 ret = usb_hub_create_port_device(hub, i + 1); in hub_configure()
1641 dev_err(hub->intfdev, in hub_configure()
1648 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1662 &hub->tt, GFP_KERNEL); in hub_configure()
1669 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1671 hub_activate(hub, HUB_INIT); in hub_configure()
1683 struct usb_hub *hub = container_of(kref, struct usb_hub, kref); in hub_release() local
1685 usb_put_dev(hub->hdev); in hub_release()
1686 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1687 kfree(hub); in hub_release()
1694 struct usb_hub *hub = usb_get_intfdata(intf); in hub_disconnect() local
1702 hub->disconnected = 1; in hub_disconnect()
1705 hub->error = 0; in hub_disconnect()
1706 hub_quiesce(hub, HUB_DISCONNECT); in hub_disconnect()
1718 usb_hub_remove_port_device(hub, port1); in hub_disconnect()
1722 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1725 usb_free_urb(hub->urb); in hub_disconnect()
1726 kfree(hub->ports); in hub_disconnect()
1727 kfree(hub->descriptor); in hub_disconnect()
1728 kfree(hub->status); in hub_disconnect()
1729 kfree(hub->buffer); in hub_disconnect()
1732 kref_put(&hub->kref, hub_release); in hub_disconnect()
1758 struct usb_hub *hub; in hub_probe() local
1839 hub = kzalloc(sizeof(*hub), GFP_KERNEL); in hub_probe()
1840 if (!hub) in hub_probe()
1843 kref_init(&hub->kref); in hub_probe()
1844 hub->intfdev = &intf->dev; in hub_probe()
1845 hub->hdev = hdev; in hub_probe()
1846 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1847 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1848 INIT_WORK(&hub->events, hub_event); in hub_probe()
1849 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1850 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1854 usb_set_intfdata(intf, hub); in hub_probe()
1862 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1864 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) in hub_probe()
1875 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in hub_ioctl() local
1889 if (hub->ports[i]->child == NULL) in hub_ioctl()
1893 hub->ports[i]->child->devnum; in hub_ioctl()
1913 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in find_port_owner() local
1923 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1962 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_release_all_ports() local
1966 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
1967 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
1975 struct usb_hub *hub; in usb_device_is_owned() local
1979 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
1980 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
1985 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED() local
1989 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
1990 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2143 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children() local
2148 if (hub->ports[i]->child) in hub_disconnect_children()
2149 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2173 struct usb_hub *hub = NULL; in usb_disconnect() local
2204 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2205 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2214 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2237 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2410 struct usb_hub *hub; in set_usb_port_removable() local
2418 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2424 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2440 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2446 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2450 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2544 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device() local
2546 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2560 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2680 static unsigned hub_is_wusb(struct usb_hub *hub) in hub_is_wusb() argument
2683 if (hub->hdev->parent != NULL) /* not a root hub? */ in hub_is_wusb()
2685 hcd = bus_to_hcd(hub->hdev->bus); in hub_is_wusb()
2726 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, in hub_port_warm_reset_required() argument
2731 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2734 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2742 static int hub_port_wait_reset(struct usb_hub *hub, int port1, in hub_port_wait_reset() argument
2757 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2758 ret = hub_ext_port_status(hub, port1, in hub_port_wait_reset()
2763 ret = hub_port_status(hub, port1, &portstatus, in hub_port_wait_reset()
2783 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2791 if (hub_port_warm_reset_required(hub, port1, portstatus)) in hub_port_wait_reset()
2802 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2804 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2815 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2823 if (hub_is_wusb(hub)) in hub_port_wait_reset()
2825 else if (hub_is_superspeedplus(hub->hdev) && in hub_port_wait_reset()
2826 port_speed_is_ssp(hub->hdev, ext_portstatus & in hub_port_wait_reset()
2829 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2841 static int hub_port_reset(struct usb_hub *hub, int port1, in hub_port_reset() argument
2846 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2849 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2851 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2864 if (hub_port_status(hub, port1, &portstatus, &portchange) == 0) in hub_port_reset()
2865 if (hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2869 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2873 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2883 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2886 dev_dbg(hub->intfdev, in hub_port_reset()
2893 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2896 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2899 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2901 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2905 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2912 if (hub_port_status(hub, port1, in hub_port_reset()
2916 if (!hub_port_warm_reset_required(hub, port1, in hub_port_reset()
2948 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
2971 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2978 static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) in port_is_power_on() argument
2982 if (hub_is_superspeed(hub->hdev)) { in port_is_power_on()
3010 static int port_is_suspended(struct usb_hub *hub, unsigned portstatus) in port_is_suspended() argument
3014 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3030 struct usb_hub *hub, int port1, in check_port_resume_type() argument
3033 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3039 && hub_port_warm_reset_required(hub, port1, portstatus)) { in check_port_resume_type()
3043 else if (status || port_is_suspended(hub, portstatus) || in check_port_resume_type()
3044 !port_is_power_on(hub, portstatus)) { in check_port_resume_type()
3050 status = hub_port_status(hub, port1, &portstatus, in check_port_resume_type()
3074 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3077 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3181 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants() local
3184 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3238 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend() local
3239 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3274 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3275 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); in usb_port_suspend()
3289 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3325 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3328 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3453 struct usb_hub *hub, int *port1, in wait_for_connected() argument
3461 if (!port_is_power_on(hub, *portstatus)) { in wait_for_connected()
3467 status = hub_port_status(hub, *port1, portstatus, portchange); in wait_for_connected()
3509 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume() local
3510 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3515 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3527 status = hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3528 if (status == 0 && !port_is_suspended(hub, portstatus)) { in usb_port_resume()
3535 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3536 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); in usb_port_resume()
3538 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3552 status = hub_port_status(hub, port1, &portstatus, &portchange); in usb_port_resume()
3561 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3563 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3567 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3573 status = wait_for_connected(udev, hub, &port1, &portchange, in usb_port_resume()
3577 hub, port1, status, portchange, portstatus); in usb_port_resume()
3582 hub_port_logical_disconnect(hub, port1); in usb_port_resume()
3614 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
3618 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3625 hdev = hub->hdev; in hub_handle_remote_wakeup()
3651 hub_port_disable(hub, port, 1); in hub_handle_remote_wakeup()
3657 static int check_ports_changed(struct usb_hub *hub) in check_ports_changed() argument
3661 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3665 status = hub_port_status(hub, port1, &portstatus, &portchange); in check_ports_changed()
3674 struct usb_hub *hub = usb_get_intfdata(intf); in hub_suspend() local
3675 struct usb_device *hdev = hub->hdev; in hub_suspend()
3682 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3684 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3694 hub->wakeup_enabled_descendants += in hub_suspend()
3698 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3700 if (check_ports_changed(hub)) { in hub_suspend()
3722 hub_quiesce(hub, HUB_SUSPEND); in hub_suspend()
3727 static void report_wakeup_requests(struct usb_hub *hub) in report_wakeup_requests() argument
3729 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3752 udev = hub->ports[i]->child; in report_wakeup_requests()
3762 struct usb_hub *hub = usb_get_intfdata(intf); in hub_resume() local
3765 hub_activate(hub, HUB_RESUME); in hub_resume()
3773 report_wakeup_requests(hub); in hub_resume()
3779 struct usb_hub *hub = usb_get_intfdata(intf); in hub_reset_resume() local
3782 hub_activate(hub, HUB_RESET_RESUME); in hub_reset_resume()
4204 struct usb_hub *hub; in usb_enable_lpm() local
4225 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4226 if (!hub) in usb_enable_lpm()
4229 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4254 static void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4261 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4280 static inline void hub_usb3_port_prepare_disable(struct usb_hub *hub, in hub_usb3_port_prepare_disable() argument
4310 static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, in hub_handle_remote_wakeup() argument
4323 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) in hub_port_disable() argument
4325 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4326 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4329 if (!hub->error) { in hub_port_disable()
4330 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4331 hub_usb3_port_prepare_disable(hub, port_dev); in hub_port_disable()
4332 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4355 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable() local
4357 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4375 int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) in hub_port_debounce() argument
4381 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4384 ret = hub_port_status(hub, port1, &portstatus, &portchange); in hub_port_debounce()
4401 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4470 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy() local
4476 if (hub) in hub_set_initial_usb2_lpm_policy()
4477 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4511 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4514 struct usb_device *hdev = hub->hdev; in hub_port_init()
4516 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4542 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4614 if (!hub->tt.hub) { in hub_port_init()
4619 udev->tt = &hub->tt; in hub_port_init()
4697 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4798 hub_port_reset(hub, port1, udev, in hub_port_init()
4851 hub_port_disable(hub, port1, 0); in hub_port_init()
4859 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
4877 if (hub->has_indicators) { in check_highspeed()
4878 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
4880 &hub->leds, 0); in check_highspeed()
4887 hub_power_remaining(struct usb_hub *hub) in hub_power_remaining() argument
4889 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
4893 if (!hub->limited_power) in hub_power_remaining()
4896 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
4898 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
4920 if (delta > hub->mA_per_port) in hub_power_remaining()
4922 delta, hub->mA_per_port); in hub_power_remaining()
4926 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
4933 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, in hub_port_connect() argument
4939 struct usb_device *hdev = hub->hdev; in hub_port_connect()
4941 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
4957 clear_bit(port1, hub->removed_bits); in hub_port_connect()
4961 status = hub_port_debounce_be_stable(hub, port1); in hub_port_connect()
4978 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
4984 if (hub_is_port_power_switchable(hub) in hub_port_connect()
4985 && !port_is_power_on(hub, portstatus) in hub_port_connect()
4993 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5012 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5014 udev->wusb = hub_is_wusb(hub); in hub_port_connect()
5017 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5030 status = hub_port_init(hub, udev, port1, i); in hub_port_connect()
5058 if (hub->has_indicators) { in hub_port_connect()
5059 hub->indicator[port1-1] = in hub_port_connect()
5063 &hub->leds, 0); in hub_port_connect()
5074 check_highspeed(hub, udev, port1); in hub_port_connect()
5115 status = hub_power_remaining(hub); in hub_port_connect()
5117 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5122 hub_port_disable(hub, port1, 1); in hub_port_connect()
5134 usb_hub_set_port_power(hdev, hub, port1, false); in hub_port_connect()
5135 msleep(2 * hub_power_on_good_delay(hub)); in hub_port_connect()
5136 usb_hub_set_port_power(hdev, hub, port1, true); in hub_port_connect()
5137 msleep(hub_power_on_good_delay(hub)); in hub_port_connect()
5140 if (hub->hdev->parent || in hub_port_connect()
5149 hub_port_disable(hub, port1, 1); in hub_port_connect()
5150 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5164 static void hub_port_connect_change(struct usb_hub *hub, int port1, in hub_port_connect_change() argument
5168 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5173 portchange, portspeed(hub, portstatus)); in hub_port_connect_change()
5175 if (hub->has_indicators) { in hub_port_connect_change()
5176 set_port_led(hub, port1, HUB_LED_AUTO); in hub_port_connect_change()
5177 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5182 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5206 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5213 hub_port_connect(hub, port1, portstatus, portchange); in hub_port_connect_change()
5254 static void port_event(struct usb_hub *hub, int port1) in port_event() argument
5258 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5260 struct usb_device *hdev = hub->hdev; in port_event()
5263 connect_change = test_bit(port1, hub->change_bits); in port_event()
5264 clear_bit(port1, hub->event_bits); in port_event()
5265 clear_bit(port1, hub->wakeup_bits); in port_event()
5267 if (hub_port_status(hub, port1, &portstatus, &portchange) < 0) in port_event()
5303 hub_power_on(hub, true); in port_event()
5304 hub_port_status(hub, port1, &status, &unused); in port_event()
5334 if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) in port_event()
5341 if (hub_port_warm_reset_required(hub, port1, portstatus)) { in port_event()
5345 if (hub_port_reset(hub, port1, NULL, in port_event()
5347 hub_port_disable(hub, port1, 1); in port_event()
5359 hub_port_connect_change(hub, port1, portstatus, portchange); in port_event()
5366 struct usb_hub *hub; in hub_event() local
5372 hub = container_of(work, struct usb_hub, events); in hub_event()
5373 hdev = hub->hdev; in hub_event()
5374 hub_dev = hub->intfdev; in hub_event()
5380 (u16) hub->change_bits[0], in hub_event()
5381 (u16) hub->event_bits[0]); in hub_event()
5386 if (unlikely(hub->disconnected)) in hub_event()
5391 hub->error = -ENODEV; in hub_event()
5392 hub_quiesce(hub, HUB_DISCONNECT); in hub_event()
5404 if (hub->quiescing) in hub_event()
5407 if (hub->error) { in hub_event()
5408 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5416 hub->nerrors = 0; in hub_event()
5417 hub->error = 0; in hub_event()
5422 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5424 if (test_bit(i, hub->event_bits) in hub_event()
5425 || test_bit(i, hub->change_bits) in hub_event()
5426 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5439 port_event(hub, i); in hub_event()
5446 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5448 else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) in hub_event()
5456 hub->limited_power = 1; in hub_event()
5458 hub->limited_power = 0; in hub_event()
5467 hub_power_on(hub, true); in hub_event()
5468 hub_hub_status(hub, &status, &unused); in hub_event()
5482 kref_put(&hub->kref, hub_release); in hub_event()
5843 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device() local
5858 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
5978 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_find_child() local
5982 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
5989 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_hub_adjust_deviceremovable() local
5993 if (!hub) in usb_hub_adjust_deviceremovable()
5998 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6014 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6043 struct usb_hub *hub = usb_hub_to_struct_hub(hdev); in usb_get_hub_port_acpi_handle() local
6045 if (!hub) in usb_get_hub_port_acpi_handle()
6048 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()