Lines Matching +full:autosuspend +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0
49 /* Protect struct usb_device->state and ->children members
50 * Note: Both are also protected by ->dev.sem, except that ->state can
58 /* synchronize hub-port add/remove and peering operations */
68 * 10 seconds to send reply for the initial 64-byte descriptor request.
70 /* define initial 64-byte descriptor request timeout in milliseconds */
74 "initial 64-byte descriptor request timeout in milliseconds "
75 "(default 5000 - 5.0 seconds)");
120 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
122 if (hub_is_superspeed(hub->hdev)) in portspeed()
135 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
137 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
143 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
149 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
150 if (udev->bos->ext_cap && in usb_device_supports_lpm()
152 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
162 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
163 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
167 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
168 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
169 if (udev->parent) in usb_device_supports_lpm()
170 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
172 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
176 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
205 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
206 (hub->descriptor->u.ss.bHubHdrDecLat * 100); in usb_set_lpm_mel()
223 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
252 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
255 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
257 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
260 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
264 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
266 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
270 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
275 * - t1: device PEL
276 * - t2: time for the ERDY to make it from the device to the host.
277 * - t3: a host-specific delay to process the ERDY.
278 * - t4: time for the packet to make it from the host to the device.
292 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
294 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
295 parent = parent->parent) in usb_set_lpm_sel()
297 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
299 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
304 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
316 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
319 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
326 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
327 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
328 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
329 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
331 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
332 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
334 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
335 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
338 * Appendix C, section C.2.2.2, says that there is a slight delay from in usb_set_lpm_parameters()
345 * about the same delays. Use the maximum delay calculations from those in usb_set_lpm_parameters()
347 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
356 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
357 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
361 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
365 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
366 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
370 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
371 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
399 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
401 return -EMSGSIZE; in get_hub_descriptor()
405 return -EINVAL; in get_hub_descriptor()
454 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
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()
464 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
474 struct usb_device *hdev = hub->hdev; in led_work()
477 int cursor = -1; in led_work()
479 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
482 for (i = 0; i < hdev->maxchild; i++) { in led_work()
485 /* 30%-50% duty cycle */ in led_work()
487 switch (hub->indicator[i]) { in led_work()
527 hub->indicator[i] = mode; in led_work()
531 cursor %= hdev->maxchild; in led_work()
533 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
538 &hub->leds, LED_CYCLE_PERIOD); in led_work()
551 int i, status = -ETIMEDOUT; in get_hub_status()
554 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
569 int i, status = -ETIMEDOUT; in get_port_status()
572 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
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()
592 if (ret != -ENODEV) in hub_ext_port_status()
593 dev_err(hub->intfdev, in hub_ext_port_status()
596 ret = -EIO; 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()
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()
629 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
630 status != -ESHUTDOWN) { 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()
650 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
654 * Suppress autosuspend until the event is proceed. 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()
700 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
701 if (port_dev && port_dev->child) in usb_wakeup_notification()
702 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
704 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
713 struct usb_hub *hub = urb->context; in hub_irq()
714 int status = urb->status; in hub_irq()
719 case -ENOENT: /* synchronous unlink */ in hub_irq()
720 case -ECONNRESET: /* async unlink */ in hub_irq()
721 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
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()
735 for (i = 0; i < urb->actual_length; ++i) 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()
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()
791 list_del(&clear->clear_list); in hub_tt_work()
794 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
795 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
796 if (status && status != -ENODEV) in hub_tt_work()
797 dev_err(&hdev->dev, in hub_tt_work()
799 clear->tt, clear->devinfo, status); in hub_tt_work()
802 drv = clear->hcd->driver; in hub_tt_work()
803 if (drv->clear_tt_buffer_complete) in hub_tt_work()
804 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); 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()
813 * usb_hub_set_port_power - control hub port's power state
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()
845 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
860 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
861 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
862 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
872 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
874 return -ENOMEM; in usb_hub_clear_tt_buffer()
878 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
879 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
880 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
881 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
885 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
888 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
889 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
892 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
893 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
894 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
895 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
906 * USB 2.0 hubs. Some hubs do not implement port-power switching 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()
914 "non-switchable hub\n"); 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()
930 mutex_lock(&hub->status_mutex); in hub_hub_status()
931 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
933 if (ret != -ENODEV) 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()
948 return set_port_feature(hub->hdev, in hub_set_port_link_state()
954 * Disable a port and mark a logical connect-change event, so that some
956 * and will re-enumerate if there actually is a device attached.
960 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
964 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
965 * - SRP saves power that way in hub_port_logical_disconnect()
966 * - ... new call, TBD ... in hub_port_logical_disconnect()
967 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
972 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
977 * usb_remove_device - disable a device's port on its parent hub
994 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
995 return -EINVAL; in usb_remove_device()
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()
1019 struct usb_device *hdev = hub->hdev; in hub_activate()
1025 unsigned delay; in hub_activate() local
1029 device_lock(&hdev->dev); in hub_activate()
1032 if (hub->disconnected) in hub_activate()
1038 kref_get(&hub->kref); in hub_activate()
1051 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1054 hdev->level - 1, 0, NULL, 0, in hub_activate()
1057 dev_err(hub->intfdev, in hub_activate()
1062 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1063 * and the implementation looks like a home-brewed sort of in hub_activate()
1074 delay = hub_power_on_good_delay(hub); in hub_activate()
1077 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1079 &hub->init_work, in hub_activate()
1080 msecs_to_jiffies(delay)); in hub_activate()
1082 /* Suppress autosuspend until init is done */ in hub_activate()
1084 to_usb_interface(hub->intfdev)); in hub_activate()
1091 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1092 if (hcd->driver->update_hub_device) { in hub_activate()
1093 ret = hcd->driver->update_hub_device(hcd, hdev, 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()
1110 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1113 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1114 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1115 struct usb_device *udev = port_dev->child; in hub_activate()
1124 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1137 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1150 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1153 set_bit(port1, hub->event_bits); in hub_activate()
1165 /* Clear status-change flags; we'll debounce later */ 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()
1194 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1205 set_bit(port1, hub->change_bits); in hub_activate()
1217 * bit on device-initiated resume. in hub_activate()
1219 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1221 set_bit(port1, hub->change_bits); in hub_activate()
1223 } else if (udev->persist_enabled) { in hub_activate()
1225 udev->reset_resume = 1; 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()
1240 /* If no port-status-change flags were set, we don't need any in hub_activate()
1245 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1249 delay = HUB_DEBOUNCE_STABLE; in hub_activate()
1253 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1255 &hub->init_work, in hub_activate()
1256 msecs_to_jiffies(delay)); in hub_activate()
1257 device_unlock(&hdev->dev); in hub_activate()
1260 msleep(delay); 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()
1277 /* Allow autosuspend if it was suppressed */ in hub_activate()
1279 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1280 device_unlock(&hdev->dev); in hub_activate()
1283 kref_put(&hub->kref, hub_release); in hub_activate()
1307 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1311 /* hub_wq and related activity won't re-trigger */ 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()
1318 for (i = 0; i < hdev->maxchild; ++i) { 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()
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()
1347 hub->in_reset = 1; in hub_pre_reset()
1357 hub->in_reset = 0; in hub_post_reset()
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()
1380 ret = -ENOMEM; in hub_configure()
1384 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1385 if (!hub->status) { in hub_configure()
1386 ret = -ENOMEM; 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()
1393 ret = -ENOMEM; in hub_configure()
1398 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1399 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1401 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1411 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1413 ret = -ENODEV; in hub_configure()
1415 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1417 ret = -ENODEV; in hub_configure()
1426 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure() local
1428 if (hdev->parent) in hub_configure()
1429 delay += hdev->parent->hub_delay; in hub_configure()
1431 delay += USB_TP_TRANSMISSION_DELAY; in hub_configure()
1432 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); 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()
1441 ret = -ENOMEM; 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()
1483 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1486 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1490 dev_dbg(hub_dev, "no over-current protection\n"); 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()
1497 switch (hdev->descriptor.bDeviceProtocol) { 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()
1519 hdev->descriptor.bDeviceProtocol); in hub_configure()
1526 if (hdev->descriptor.bDeviceProtocol != 0) { 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()
1553 /* probe() zeroes hub->indicator[] */ in hub_configure()
1555 hub->has_indicators = 1; in hub_configure()
1560 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1562 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1563 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1570 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1571 if (hdev == hdev->bus->root_hub) { in hub_configure()
1572 if (hcd->power_budget > 0) in hub_configure()
1573 hdev->bus_mA = hcd->power_budget; in hub_configure()
1575 hdev->bus_mA = full_load * maxchild; in hub_configure()
1576 if (hdev->bus_mA >= full_load) 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()
1583 int remaining = hdev->bus_mA - 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()
1596 } else { /* Self-powered external hub */ in hub_configure()
1597 /* FIXME: What about battery-powered external hubs that 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()
1612 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1618 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1627 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); 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()
1635 ret = -ENOMEM; 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()
1650 dev_err(hub->intfdev, in hub_configure()
1655 hdev->maxchild = i; in hub_configure()
1656 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1657 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1659 pm_runtime_put(&port_dev->dev); in hub_configure()
1669 if (hcd->driver->update_hub_device) { in hub_configure()
1670 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1671 &hub->tt, GFP_KERNEL); in hub_configure()
1678 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1694 usb_put_dev(hub->hdev); in hub_release()
1695 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1711 hub->disconnected = 1; in hub_disconnect()
1714 hub->error = 0; in hub_disconnect()
1721 port1 = hdev->maxchild; in hub_disconnect()
1722 hdev->maxchild = 0; in hub_disconnect()
1726 for (; port1 > 0; --port1) in hub_disconnect()
1731 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1732 highspeed_hubs--; 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()
1740 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1742 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1745 kref_put(&hub->kref, hub_release); in hub_disconnect()
1752 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1753 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1756 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1757 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1761 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1773 desc = intf->cur_altsetting; in hub_probe()
1777 * Set default autosuspend delay as 0 to speedup bus suspend, in hub_probe()
1780 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1781 * autosuspend delay to provide enough time to handle a wakeup in hub_probe()
1785 * - The patch might cause one or more auto supend/resume for in hub_probe()
1797 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1801 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1805 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1809 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1810 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1813 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1814 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1822 if (hdev->parent) { /* normal device */ in hub_probe()
1825 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1827 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1831 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1832 dev_err(&intf->dev, in hub_probe()
1834 return -E2BIG; in hub_probe()
1838 if (hdev->parent) { in hub_probe()
1839 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1840 return -ENODEV; in hub_probe()
1845 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1846 return -EIO; in hub_probe()
1850 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1854 return -ENOMEM; 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()
1868 intf->needs_remote_wakeup = 1; in hub_probe()
1869 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1871 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1874 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1875 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1877 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { 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()
1886 return -ENODEV; in hub_probe()
1902 if (hdev->devnum <= 0) in hub_ioctl()
1903 info->nports = 0; in hub_ioctl()
1905 info->nports = hdev->maxchild; in hub_ioctl()
1906 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1907 if (hub->ports[i]->child == NULL) in hub_ioctl()
1908 info->port[i] = 0; in hub_ioctl()
1910 info->port[i] = in hub_ioctl()
1911 hub->ports[i]->child->devnum; in hub_ioctl()
1916 return info->nports + 1; in hub_ioctl()
1920 return -ENOSYS; in hub_ioctl()
1933 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
1934 return -ENODEV; in find_port_owner()
1935 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
1936 return -EINVAL; in find_port_owner()
1941 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1956 return -EBUSY; in usb_hub_claim_port()
1972 return -ENOENT; in usb_hub_release_port()
1983 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
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()
1995 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
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()
2006 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2007 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2008 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2010 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2011 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2012 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2016 * usb_set_device_state - change a device's current state (usbcore, hcds)
2020 * udev->state is _not_ fully protected by the device lock. Although
2031 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2032 * Otherwise udev->state is set to new_state, and if new_state is
2040 int wakeup = -1; in usb_set_device_state()
2043 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2047 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2050 if (udev->parent) { in usb_set_device_state()
2051 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2055 wakeup = (udev->quirks & in usb_set_device_state()
2057 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2062 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2064 udev->active_duration -= jiffies; in usb_set_device_state()
2066 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2067 udev->active_duration += jiffies; in usb_set_device_state()
2068 udev->state = new_state; in usb_set_device_state()
2073 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2080 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2081 * USB-2.0 buses they are also used as device addresses, however on
2082 * USB-3.0 buses the address is assigned by the controller hardware
2086 * device <-> virtual port number becomes 1:1. Why? to simplify the
2095 * We add 1 as an offset to the one-based USB-stack port number
2096 * (zero-based wusb virtual port index) for two reasons: (a) dev addr
2099 * port #1, which is wusb virtual-port #0 has address #2.
2109 struct usb_bus *bus = udev->bus; in choose_devnum()
2112 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2113 if (udev->wusb) { in choose_devnum()
2114 devnum = udev->portnum + 1; in choose_devnum()
2115 BUG_ON(test_bit(devnum, bus->devmap.devicemap)); in choose_devnum()
2118 * bus->devnum_next. */ in choose_devnum()
2119 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2120 bus->devnum_next); in choose_devnum()
2122 devnum = find_next_zero_bit(bus->devmap.devicemap, in choose_devnum()
2124 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2127 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2128 udev->devnum = devnum; in choose_devnum()
2130 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2135 if (udev->devnum > 0) { in release_devnum()
2136 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2137 udev->devnum = -1; in release_devnum()
2144 if (!udev->wusb) in update_devnum()
2145 udev->devnum = devnum; in update_devnum()
2146 if (!udev->devaddr) in update_devnum()
2147 udev->devaddr = (u8)devnum; in update_devnum()
2152 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2155 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2156 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2165 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2166 if (hub->ports[i]->child) in hub_disconnect_children()
2167 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2172 * usb_disconnect - disconnect a device (usbcore-internal)
2199 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2200 udev->devnum); in usb_disconnect()
2206 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2216 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2220 if (udev->parent) { in usb_disconnect()
2221 port1 = udev->portnum; in usb_disconnect()
2222 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2223 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2225 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2226 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2229 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2232 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2233 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2236 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2240 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2243 device_del(&udev->dev); in usb_disconnect()
2255 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2256 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2260 put_device(&udev->dev); in usb_disconnect()
2268 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2273 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2275 dev_info(&udev->dev, in announce_device()
2277 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2278 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2280 dev_info(&udev->dev, in announce_device()
2282 udev->descriptor.iManufacturer, in announce_device()
2283 udev->descriptor.iProduct, in announce_device()
2284 udev->descriptor.iSerialNumber); in announce_device()
2285 show_string(udev, "Product", udev->product); in announce_device()
2286 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2287 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2295 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2298 * Finish enumeration for On-The-Go devices
2308 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2312 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2313 && udev->config in usb_enumerate_device_otg()
2314 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2316 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2317 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2320 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2321 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2323 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2326 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2327 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2330 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2331 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2343 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2345 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2347 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2357 dev_err(&udev->dev, in usb_enumerate_device_otg()
2368 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2372 * and FIXME -- all comments that apply to them apply here wrt to
2384 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2386 if (udev->config == NULL) { in usb_enumerate_device()
2389 if (err != -ENODEV) in usb_enumerate_device()
2390 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2397 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2398 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2399 udev->descriptor.iManufacturer); in usb_enumerate_device()
2400 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2406 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2411 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2412 || udev->bus->is_b_host)) { in usb_enumerate_device()
2415 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2417 return -ENOTSUPP; in usb_enumerate_device()
2427 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2429 u8 port = udev->portnum; in set_usb_port_removable()
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()
2444 udev->removable = USB_DEVICE_REMOVABLE; in set_usb_port_removable()
2448 udev->removable = USB_DEVICE_FIXED; 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()
2473 udev->removable = USB_DEVICE_REMOVABLE; in set_usb_port_removable()
2475 udev->removable = USB_DEVICE_FIXED; in set_usb_port_removable()
2480 * usb_new_device - perform initial device setup (usbcore-internal)
2493 * Only the hub driver or root-hub registrar should ever call this.
2504 if (udev->parent) { in usb_new_device()
2505 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2509 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2512 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2513 pm_runtime_set_active(&udev->dev); in usb_new_device()
2514 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2515 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2516 pm_runtime_enable(&udev->dev); in usb_new_device()
2518 /* By default, forbid autosuspend for all devices. It will be in usb_new_device()
2526 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2527 udev->devnum, udev->bus->busnum, in usb_new_device()
2528 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2529 /* export the usbdev device-node for libusb */ in usb_new_device()
2530 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2531 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2536 if (udev->serial) in usb_new_device()
2537 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2538 if (udev->product) in usb_new_device()
2539 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2540 if (udev->manufacturer) in usb_new_device()
2541 add_device_randomness(udev->manufacturer, in usb_new_device()
2542 strlen(udev->manufacturer)); in usb_new_device()
2544 device_enable_async_suspend(&udev->dev); in usb_new_device()
2546 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2547 if (udev->parent) in usb_new_device()
2551 * for configuring the device and invoking the add-device in usb_new_device()
2554 err = device_add(&udev->dev); in usb_new_device()
2556 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2561 if (udev->parent) { in usb_new_device()
2562 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2563 int port1 = udev->portnum; in usb_new_device()
2564 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2566 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2567 &port_dev->dev.kobj, "port"); in usb_new_device()
2571 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2572 &udev->dev.kobj, "device"); in usb_new_device()
2574 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2578 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2579 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2582 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2584 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2589 pm_runtime_disable(&udev->dev); in usb_new_device()
2590 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2596 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2610 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2613 usb_dev->authorized = 0; in usb_deauthorize_device()
2614 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2627 if (usb_dev->authorized == 1) in usb_authorize_device()
2632 dev_err(&usb_dev->dev, in usb_authorize_device()
2637 if (usb_dev->wusb) { in usb_authorize_device()
2638 result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor)); in usb_authorize_device()
2640 dev_err(&usb_dev->dev, "can't re-read device descriptor for " in usb_authorize_device()
2646 usb_dev->authorized = 1; in usb_authorize_device()
2654 dev_err(&usb_dev->dev, in usb_authorize_device()
2660 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2681 struct usb_ssp_cap_descriptor *ssp_cap = hdev->bos->ssp_cap; in port_speed_is_ssp()
2686 ssa_count = le32_to_cpu(ssp_cap->bmAttributes) & in port_speed_is_ssp()
2690 ss_attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in port_speed_is_ssp()
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()
2704 return hcd->wireless; in hub_is_wusb()
2733 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2743 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
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()
2776 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_wait_reset() argument
2785 delay_time += delay) { in hub_port_wait_reset()
2787 msleep(delay); in hub_port_wait_reset()
2790 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2805 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2806 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2812 /* switch to the long delay after two short delay failures */ in hub_port_wait_reset()
2814 delay = HUB_LONG_RESET_TIME; in hub_port_wait_reset()
2816 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2818 warm ? "warm " : "", delay); in hub_port_wait_reset()
2822 return -EBUSY; in hub_port_wait_reset()
2825 return -ENOTCONN; in hub_port_wait_reset()
2829 return -ENOTCONN; in hub_port_wait_reset()
2833 * but the device may have successfully re-connected. Ignore it. 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()
2839 return -EAGAIN; in hub_port_wait_reset()
2843 return -EBUSY; in hub_port_wait_reset()
2848 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2850 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2851 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2853 udev->rx_lanes = 1; in hub_port_wait_reset()
2854 udev->tx_lanes = 1; in hub_port_wait_reset()
2857 udev->speed = USB_SPEED_WIRELESS; 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()
2861 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2862 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2863 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2865 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2867 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2869 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2875 struct usb_device *udev, unsigned int delay, bool warm) 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()
2886 return -EINVAL; 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()
2909 if (status == -ENODEV) { in hub_port_reset()
2912 dev_err(&port_dev->dev, in hub_port_reset()
2916 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2918 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
2919 dev_dbg(hub->intfdev, in hub_port_reset()
2925 if (status == 0 || status == -ENOTCONN || status == -ENODEV) { 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()
2943 * state, re-issue the warm reset. in hub_port_reset()
2958 dev_dbg(&port_dev->dev, in hub_port_reset()
2964 dev_dbg(&port_dev->dev, in hub_port_reset()
2967 delay = HUB_LONG_RESET_TIME; in hub_port_reset()
2970 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
2974 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
2980 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
2981 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
2988 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
2994 if (hcd->driver->reset_device) in hub_port_reset()
2995 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3004 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3015 if (hub_is_superspeed(hub->hdev)) { in port_is_power_on()
3027 __acquires(&port_dev->status_lock) in usb_lock_port()
3029 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3030 __acquire(&port_dev->status_lock); in usb_lock_port()
3034 __releases(&port_dev->status_lock) in usb_unlock_port()
3036 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3037 __release(&port_dev->status_lock); in usb_unlock_port()
3047 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3060 * is ready for a reset-resume, or should be disconnected.
3066 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3071 if (status == 0 && udev->reset_resume in check_port_resume_type()
3079 status = -ENODEV; in check_port_resume_type()
3081 if (retries--) { in check_port_resume_type()
3087 status = -ENODEV; in check_port_resume_type()
3091 * so try a reset-resume instead. in check_port_resume_type()
3093 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3094 if (udev->persist_enabled) in check_port_resume_type()
3095 udev->reset_resume = 1; in check_port_resume_type()
3097 status = -ENODEV; in check_port_resume_type()
3101 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3103 } else if (udev->reset_resume) { in check_port_resume_type()
3105 /* Late port handoff can set status-change bits */ 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()
3114 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3115 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3116 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3118 * following the reset-resume. in check_port_resume_type()
3120 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3128 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3131 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3138 if (!udev->actconfig) in usb_disable_ltm()
3150 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3153 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3160 if (!udev->actconfig) in usb_enable_ltm()
3171 * usb_enable_remote_wakeup - enable remote wakeup for a device
3174 * For USB-2 devices: Set the device's remote wakeup feature.
3176 * For USB-3 devices: Assume there's only one function on the device and
3182 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3197 * usb_disable_remote_wakeup - disable remote wakeup for a device
3200 * For USB-2 devices: Clear the device's remote wakeup feature.
3202 * For USB-3 devices: Assume there's only one function on the device and
3208 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3220 /* Count of wakeup-enabled devices at or below udev */
3225 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3226 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3231 * usb_port_suspend - suspend a usb device's upstream port
3254 * between a pair of dual-role devices. That will change roles, such
3255 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3261 * - suspend, resume ... when the VBUS power link stays live
3262 * - suspend, disconnect ... VBUS lost
3265 * normal re-enumeration procedures, starting with enabling VBUS power.
3266 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3270 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3272 * hub is suspended). Nevertheless, we change @udev->state to
3274 * upstream port setting is stored in @udev->port_is_suspended.
3280 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3281 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3282 int port1 = udev->portnum; in usb_port_suspend()
3294 if (udev->do_remote_wakeup) { in usb_port_suspend()
3297 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3299 /* bail if autosuspend is requested */ in usb_port_suspend()
3309 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3310 status = -ENOMEM; in usb_port_suspend()
3316 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3321 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3331 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3338 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3346 if (udev->do_remote_wakeup) in usb_port_suspend()
3354 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3355 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3356 udev->do_remote_wakeup); in usb_port_suspend()
3358 udev->port_is_suspended = 1; in usb_port_suspend()
3366 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3367 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3368 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3370 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3384 * If @udev->reset_resume is set then the device is reset before the
3393 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3394 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3401 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3410 if (udev->reset_resume) { in finish_port_resume()
3413 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3418 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3419 status = -ENODEV; in finish_port_resume()
3432 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3433 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3434 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3435 udev->reset_resume = 1; in finish_port_resume()
3441 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3447 * udev->reset_resume in finish_port_resume()
3449 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3450 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3462 dev_dbg(&udev->dev, in finish_port_resume()
3476 * device switch on the RX termination after long delay of host enabling
3504 status = -ENODEV; in wait_for_connected()
3511 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3516 * usb_port_resume - re-activate a suspended usb device's upstream port
3517 * @udev: device to re-activate, not a root hub
3520 * This will re-activate the suspended device, increasing power usage
3526 * If @udev->reset_resume is set then this routine won't check that the
3534 * for mass-storage devices containing mounted filesystems, since the
3551 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3552 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3553 int port1 = udev->portnum; in usb_port_resume()
3557 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3558 status = pm_runtime_get_sync(&port_dev->dev); in usb_port_resume()
3560 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3568 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3572 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3577 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3580 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3583 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3586 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3587 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3602 udev->port_is_suspended = 0; 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()
3614 if (udev->persist_enabled) in usb_port_resume()
3623 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3643 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3644 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3658 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3660 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3667 hdev = hub->hdev; in hub_handle_remote_wakeup()
3668 udev = port_dev->child; in hub_handle_remote_wakeup()
3675 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3692 ret = -ENODEV; in hub_handle_remote_wakeup()
3695 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3703 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3717 struct usb_device *hdev = hub->hdev; in hub_suspend()
3722 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3724 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3725 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3726 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3727 struct usb_device *udev = port_dev->child; in hub_suspend()
3729 if (udev && udev->can_submit) { in hub_suspend()
3730 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3731 dev_name(&udev->dev)); in hub_suspend()
3733 return -EBUSY; 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()
3744 return -EBUSY; in hub_suspend()
3745 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3749 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3751 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3761 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3771 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3777 if (hdev->parent) in report_wakeup_requests()
3780 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3781 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3791 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3792 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3794 udev = hub->ports[i]->child; in report_wakeup_requests()
3796 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3806 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
3823 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
3829 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3836 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
3841 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
3842 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
3855 * device-initiated U1 or U2. This lets the device know the exit latencies from
3871 if (udev->state != USB_STATE_CONFIGURED) in usb_req_set_sel()
3875 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
3876 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
3877 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
3878 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
3885 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
3894 dev_dbg(&udev->dev, "Device-initiated %s disabled due to long SEL %llu us or PEL %llu us\n", in usb_req_set_sel()
3896 return -EINVAL; in usb_req_set_sel()
3900 * If we're enabling device-initiated LPM for one link state, in usb_req_set_sel()
3923 return -ENOMEM; in usb_req_set_sel()
3925 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
3926 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
3927 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
3928 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
3941 * Enable or disable device-initiated U1 or U2 transitions.
3957 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
3959 return -EINVAL; in usb_set_device_initiated_lpm()
3962 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
3963 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
3972 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
3990 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
3993 return -EBUSY; in usb_set_device_initiated_lpm()
4012 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4014 return -EINVAL; in usb_set_lpm_timeout()
4019 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4022 return -EINVAL; in usb_set_lpm_timeout()
4025 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4026 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4029 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4032 return -EBUSY; in usb_set_lpm_timeout()
4035 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4037 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4042 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4046 * control transfers to set the hub timeout or enable device-initiated U1/U2
4049 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4050 * hub-initiated U1/U2 will be disabled.
4060 __u8 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4061 __le16 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4077 dev_warn(&udev->dev, "Set SEL for device-initiated %s failed.\n", in usb_enable_link_state()
4087 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4094 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4102 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4105 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4112 if (udev->actconfig && in usb_enable_link_state()
4115 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4117 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4123 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4128 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4131 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4134 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4136 * still disallow device-initiated U1/U2 entry.
4150 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4152 return -EINVAL; in usb_disable_link_state()
4156 return -EBUSY; in usb_disable_link_state()
4160 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4161 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4168 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4172 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4174 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4180 * Disable hub-initiated and device-initiated U1 and U2 entry.
4184 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4190 if (!udev || !udev->parent || in usb_disable_lpm()
4191 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4192 !udev->lpm_capable || in usb_disable_lpm()
4193 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4196 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4197 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4200 udev->lpm_disable_count++; in usb_disable_lpm()
4201 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4214 return -EBUSY; in usb_disable_lpm()
4221 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4225 return -EINVAL; in usb_unlocked_disable_lpm()
4227 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4229 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4236 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4249 if (!udev || !udev->parent || in usb_enable_lpm()
4250 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4251 !udev->lpm_capable || in usb_enable_lpm()
4252 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4255 udev->lpm_disable_count--; in usb_enable_lpm()
4256 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4260 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4261 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4264 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4267 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4271 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4273 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4276 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4284 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4289 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4291 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4299 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4302 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4303 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4310 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4312 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4361 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4362 * a connection with a plugged-in cable but will signal the host when the cable
4363 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
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()
4374 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4381 if (port_dev->child && set_state) in hub_port_disable()
4382 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4383 if (ret && ret != -ENODEV) in hub_port_disable()
4384 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4389 * usb_port_disable - disable a usb device's upstream port
4397 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4399 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4402 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4404 * Between connect detection and reset signaling there must be a delay
4405 * of 100ms at least for debounce and power-settling. The corresponding
4408 * Apparently there are some bluetooth and irda-dongles and a number of
4409 * low-speed devices for which this debounce period may last over a second.
4410 * Not covered by the spec - but easy to deal with.
4413 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4423 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4443 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4452 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4456 return -ETIMEDOUT; in hub_port_debounce()
4464 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4474 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4480 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4481 return -EINVAL; in hub_set_address()
4482 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4484 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4485 return -EINVAL; in hub_set_address()
4486 if (hcd->driver->address_device) in hub_set_address()
4487 retval = hcd->driver->address_device(hcd, udev); in hub_set_address()
4512 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4515 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4519 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4521 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4523 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4530 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4532 if (!hcd->driver->enable_device) in hub_enable_device()
4534 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4536 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4537 return -EINVAL; in hub_enable_device()
4539 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4546 * If this is called for an already-existing device (as part of
4556 struct usb_device *hdev = hub->hdev; in hub_port_init()
4557 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4558 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4560 unsigned delay = HUB_SHORT_RESET_TIME; in hub_port_init() local
4561 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4563 int devnum = udev->devnum; in hub_port_init()
4570 if (!hdev->parent) { in hub_port_init()
4571 delay = HUB_ROOT_RESET_TIME; in hub_port_init()
4572 if (port1 == hdev->bus->otg_port) in hub_port_init()
4573 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4576 /* Some low speed devices have problems with the quick delay, so */ in hub_port_init()
4579 delay = HUB_LONG_RESET_TIME; in hub_port_init()
4581 mutex_lock(hcd->address0_mutex); in hub_port_init()
4585 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4590 retval = -ENODEV; in hub_port_init()
4593 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4594 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4595 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4598 oldspeed = udev->speed; in hub_port_init()
4605 switch (udev->speed) { in hub_port_init()
4609 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4612 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4619 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4622 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4628 if (udev->speed == USB_SPEED_WIRELESS) in hub_port_init()
4631 speed = usb_speed_string(udev->speed); in hub_port_init()
4638 * platform device is usually a dual-role USB controller device. in hub_port_init()
4640 if (udev->bus->controller->driver) in hub_port_init()
4641 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4643 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4645 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4646 dev_info(&udev->dev, in hub_port_init()
4648 (udev->config) ? "reset" : "new", speed, in hub_port_init()
4652 if (hdev->tt) { in hub_port_init()
4653 udev->tt = hdev->tt; in hub_port_init()
4654 udev->ttport = hdev->ttport; in hub_port_init()
4655 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4656 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4657 if (!hub->tt.hub) { in hub_port_init()
4658 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4659 retval = -EINVAL; in hub_port_init()
4662 udev->tt = &hub->tt; in hub_port_init()
4663 udev->ttport = port1; in hub_port_init()
4672 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4673 * so it may help with some non-standards-compliant devices. in hub_port_init()
4687 dev_err(&udev->dev, in hub_port_init()
4696 retval = -ENOMEM; in hub_port_init()
4706 buf->bMaxPacketSize0 = 0; in hub_port_init()
4712 switch (buf->bMaxPacketSize0) { in hub_port_init()
4714 if (buf->bDescriptorType == in hub_port_init()
4722 r = -EPROTO; in hub_port_init()
4731 if (r == 0 || (r == -ETIMEDOUT && in hub_port_init()
4733 udev->speed > USB_SPEED_FULL)) in hub_port_init()
4736 udev->descriptor.bMaxPacketSize0 = in hub_port_init()
4737 buf->bMaxPacketSize0; in hub_port_init()
4740 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4743 if (oldspeed != udev->speed) { in hub_port_init()
4744 dev_dbg(&udev->dev, in hub_port_init()
4746 retval = -ENODEV; in hub_port_init()
4750 if (r != -ENODEV) in hub_port_init()
4751 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4753 retval = -EMSGSIZE; in hub_port_init()
4764 if (udev->wusb == 0) { in hub_port_init()
4772 if (retval != -ENODEV) in hub_port_init()
4773 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
4777 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
4778 devnum = udev->devnum; in hub_port_init()
4779 dev_info(&udev->dev, in hub_port_init()
4781 (udev->config) ? "reset" : "new", in hub_port_init()
4782 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
4784 (udev->rx_lanes == 2 && udev->tx_lanes == 2) ? in hub_port_init()
4790 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
4791 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
4800 if (retval != -ENODEV) in hub_port_init()
4801 dev_err(&udev->dev, in hub_port_init()
4805 retval = -EMSGSIZE; in hub_port_init()
4807 u32 delay; in hub_port_init() local
4811 delay = udev->parent->hub_delay; in hub_port_init()
4812 udev->hub_delay = min_t(u32, delay, in hub_port_init()
4816 dev_dbg(&udev->dev, in hub_port_init()
4817 "Failed set isoch delay, error %d\n", in hub_port_init()
4833 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
4834 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
4835 dev_err(&udev->dev, "got a wrong device descriptor, " in hub_port_init()
4839 retval = -EINVAL; in hub_port_init()
4843 if (udev->descriptor.bMaxPacketSize0 == 0xff || in hub_port_init()
4844 udev->speed >= USB_SPEED_SUPER) in hub_port_init()
4847 i = udev->descriptor.bMaxPacketSize0; in hub_port_init()
4848 if (usb_endpoint_maxp(&udev->ep0.desc) != i) { in hub_port_init()
4849 if (udev->speed == USB_SPEED_LOW || in hub_port_init()
4851 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); in hub_port_init()
4852 retval = -EMSGSIZE; in hub_port_init()
4855 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
4856 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
4858 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
4859 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
4864 if (retval < (signed)sizeof(udev->descriptor)) { in hub_port_init()
4865 if (retval != -ENODEV) in hub_port_init()
4866 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
4869 retval = -ENOMSG; in hub_port_init()
4875 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
4878 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
4885 if (hcd->driver->update_device) in hub_port_init()
4886 hcd->driver->update_device(hcd, udev); in hub_port_init()
4893 mutex_unlock(hcd->address0_mutex); in hub_port_init()
4903 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
4913 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
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()
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()
4936 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
4937 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
4938 struct usb_device *udev = port_dev->child; in hub_power_remaining()
4953 if (udev->actconfig) in hub_power_remaining()
4954 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
4955 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
4959 if (delta > hub->mA_per_port) in hub_power_remaining()
4960 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
4961 delta, hub->mA_per_port); in hub_power_remaining()
4962 remaining -= delta; in hub_power_remaining()
4965 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
4966 -remaining); in hub_power_remaining()
4985 if (memcmp(&udev->descriptor, old_device_descriptor, in descriptors_changed()
4989 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
4991 if (udev->bos) { in descriptors_changed()
4992 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
4993 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
4995 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5005 if (udev->serial) in descriptors_changed()
5006 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5009 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5010 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5019 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5020 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5024 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5029 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5031 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5033 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5041 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5044 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5047 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5048 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5060 int status = -ENODEV; in hub_port_connect()
5063 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5064 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5065 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5066 struct usb_device *udev = port_dev->child; in hub_port_connect()
5067 static int unreliable_port = -1; in hub_port_connect()
5071 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5072 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5073 usb_disconnect(&port_dev->child); in hub_port_connect()
5081 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5087 if (status != -ENODEV && in hub_port_connect()
5090 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5102 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5110 && !port_dev->port_owner) in hub_port_connect()
5117 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5128 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5130 dev_err(&port_dev->dev, in hub_port_connect()
5136 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5137 udev->level = hdev->level + 1; 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()
5142 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5144 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5147 if (udev->devnum <= 0) { in hub_port_connect()
5148 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5152 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5159 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5162 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5165 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5168 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5169 && udev->bus_mA <= unit_load) { in hub_port_connect()
5175 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5179 dev_err(&udev->dev, in hub_port_connect()
5180 "can't connect bus-powered hub " 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()
5189 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5195 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5196 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5213 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5214 status = -ENOTCONN; in hub_port_connect()
5216 port_dev->child = udev; in hub_port_connect()
5226 port_dev->child = NULL; in hub_port_connect()
5230 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5231 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5232 udev->speed); in hub_port_connect()
5241 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5252 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5255 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5256 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5257 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5264 if (hub->hdev->parent || in hub_port_connect()
5265 !hcd->driver->port_handed_over || in hub_port_connect()
5266 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5267 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5268 dev_err(&port_dev->dev, in hub_port_connect()
5274 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5275 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5276 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5282 * a port connection-change occurs;
5283 * a port enable-change occurs (often caused by EMI);
5290 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5292 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5293 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5295 int status = -ENODEV; in hub_port_connect_change()
5298 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5301 if (hub->has_indicators) { 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()
5315 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5318 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5323 descriptor = udev->descriptor; in hub_port_connect_change()
5325 sizeof(udev->descriptor)); in hub_port_connect_change()
5327 dev_dbg(&udev->dev, in hub_port_connect_change()
5332 udev->bos)) { in hub_port_connect_change()
5333 dev_dbg(&udev->dev, in hub_port_connect_change()
5336 udev->descriptor = descriptor; in hub_port_connect_change()
5342 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5343 udev->persist_enabled) { in hub_port_connect_change()
5355 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5366 /* Handle notifying userspace about hub over-current events */
5373 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5375 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5380 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5389 port_dev->over_current_count); in port_over_current_notify()
5394 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5404 __must_hold(&port_dev->status_lock) in port_event()
5407 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5408 struct usb_device *udev = port_dev->child; 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()
5426 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5437 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5444 port_dev->over_current_count++; in port_event()
5447 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5448 port_dev->over_current_count); in port_event()
5455 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5459 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5464 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5469 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5474 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5480 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5491 dev_dbg(&port_dev->dev, "do warm reset\n"); in port_event()
5493 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5522 hdev = hub->hdev; in hub_event()
5523 hub_dev = hub->intfdev; in hub_event()
5526 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5529 hdev->state, hdev->maxchild, 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()
5541 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5542 hub->error = -ENODEV; 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()
5572 for (i = 1; i <= hdev->maxchild; i++) { 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()
5584 * (powered-off), we leave it in that state, run in hub_event()
5587 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5588 pm_runtime_barrier(&port_dev->dev); in hub_event()
5592 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5597 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5607 hub->limited_power = 1; in hub_event()
5609 hub->limited_power = 0; in hub_event()
5615 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5621 dev_err(hub_dev, "over-current condition\n"); in hub_event()
5631 /* Balance the stuff in kick_hub_wq() and allow autosuspend */ in hub_event()
5633 kref_put(&hub->kref, hub_release); in hub_event()
5679 return -1; in usb_hub_init()
5684 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
5686 * over to the companion full-speed controller. in usb_hub_init()
5696 return -1; in usb_hub_init()
5708 * individual hub resources. -greg in usb_hub_cleanup()
5714 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
5717 * WARNING - don't use this routine to reset a composite device
5726 * re-connected. All drivers will be unbound, and the device will be
5727 * re-enumerated and probed all over again.
5729 * Return: 0 if the reset succeeded, -ENODEV if the device has been
5749 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
5751 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
5752 struct usb_device_descriptor descriptor = udev->descriptor; in usb_reset_and_verify_device()
5755 int port1 = udev->portnum; in usb_reset_and_verify_device()
5757 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
5758 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
5759 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
5760 udev->state); in usb_reset_and_verify_device()
5761 return -EINVAL; in usb_reset_and_verify_device()
5765 return -EISDIR; in usb_reset_and_verify_device()
5770 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
5775 * Device-initiated LPM, and system exit latency settings are cleared in usb_reset_and_verify_device()
5780 dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__); in usb_reset_and_verify_device()
5784 bos = udev->bos; in usb_reset_and_verify_device()
5785 udev->bos = NULL; in usb_reset_and_verify_device()
5790 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
5793 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
5802 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
5803 udev->descriptor = descriptor; /* for disconnect() calls */ in usb_reset_and_verify_device()
5808 if (!udev->actconfig) in usb_reset_and_verify_device()
5811 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5812 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
5814 dev_warn(&udev->dev, in usb_reset_and_verify_device()
5817 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5822 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
5825 dev_err(&udev->dev, in usb_reset_and_verify_device()
5827 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
5828 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5831 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5835 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
5837 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
5840 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
5841 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
5842 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
5845 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
5846 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
5855 intf->resetting_device = 1; in usb_reset_and_verify_device()
5856 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
5857 desc->bAlternateSetting); in usb_reset_and_verify_device()
5858 intf->resetting_device = 0; in usb_reset_and_verify_device()
5861 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
5863 desc->bInterfaceNumber, in usb_reset_and_verify_device()
5864 desc->bAlternateSetting, in usb_reset_and_verify_device()
5869 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
5870 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
5874 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
5879 udev->bos = bos; in usb_reset_and_verify_device()
5884 udev->bos = bos; in usb_reset_and_verify_device()
5888 return -ENODEV; in usb_reset_and_verify_device()
5892 * usb_reset_device - warn interface drivers and perform a USB port reset
5918 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
5919 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
5921 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
5922 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
5923 udev->state); in usb_reset_device()
5924 return -EINVAL; in usb_reset_device()
5927 if (!udev->parent) { in usb_reset_device()
5928 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
5929 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
5930 return -EISDIR; in usb_reset_device()
5933 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
5946 /* Prevent autosuspend during the reset */ in usb_reset_device()
5950 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
5951 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
5955 if (cintf->dev.driver) { in usb_reset_device()
5956 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
5957 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
5958 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
5959 else if (cintf->condition == in usb_reset_device()
5973 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
5974 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
5976 int rebind = cintf->needs_binding; in usb_reset_device()
5978 if (!rebind && cintf->dev.driver) { in usb_reset_device()
5979 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
5980 if (drv->post_reset) in usb_reset_device()
5981 rebind = (drv->post_reset)(cintf); in usb_reset_device()
5982 else if (cintf->condition == in usb_reset_device()
5986 cintf->needs_binding = 1; in usb_reset_device()
6003 * usb_queue_reset_device - Reset a USB device from an atomic context
6016 * - Scheduling two resets at the same time from two different drivers
6019 * handles ->pre_reset(), the second reset might happen or not.
6021 * - If the reset is delayed so long that the interface is unbound from
6024 * - This function can be called during .probe(). It can also be called
6027 * .disconnect(), call usb_reset_device() directly -- but watch out
6032 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6038 * usb_hub_find_child - Get the pointer of child device
6048 * child's usb_device pointer if non-NULL.
6055 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6057 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6072 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6073 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6075 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6079 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6080 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6081 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6086 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6088 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6089 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6091 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6096 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6102 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6108 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6123 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()