Lines Matching +full:autosuspend +full:- +full:delay
1 // SPDX-License-Identifier: GPL-2.0
53 /* Protect struct usb_device->state and ->children members
54 * Note: Both are also protected by ->dev.sem, except that ->state can
62 /* synchronize hub-port add/remove and peering operations */
72 * 10 seconds to send reply for the initial 64-byte descriptor request.
74 /* define initial 64-byte descriptor request timeout in milliseconds */
78 "initial 64-byte descriptor request timeout in milliseconds "
79 "(default 5000 - 5.0 seconds)");
124 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
126 if (hub_is_superspeed(hub->hdev)) in portspeed()
139 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
141 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
147 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
153 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
154 if (udev->bos->ext_cap && in usb_device_supports_lpm()
156 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
166 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
167 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
171 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
172 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
173 if (udev->parent) in usb_device_supports_lpm()
174 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
176 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
180 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
201 * MEL for parent already contains the delay up to parent, so only add in usb_set_lpm_mel()
206 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
208 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
216 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
222 * to cover the delay if the PING_RESPONSE is queued behind a Max Packet in usb_set_lpm_mel()
227 if (!hub->hdev->parent) in usb_set_lpm_mel()
230 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
259 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
262 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
264 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
267 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
271 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
273 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
277 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
282 * - t1: device PEL
283 * - t2: time for the ERDY to make it from the device to the host.
284 * - t3: a host-specific delay to process the ERDY.
285 * - t4: time for the packet to make it from the host to the device.
299 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
301 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
302 parent = parent->parent) in usb_set_lpm_sel()
304 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
306 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
311 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
323 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
326 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
333 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
334 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
335 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
336 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
338 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
339 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
341 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
342 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
345 * Appendix C, section C.2.2.2, says that there is a slight delay from in usb_set_lpm_parameters()
352 * about the same delays. Use the maximum delay calculations from those in usb_set_lpm_parameters()
354 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
363 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
364 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
368 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
372 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
373 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
377 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
378 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
406 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
408 return -EMSGSIZE; in get_hub_descriptor()
412 return -EINVAL; in get_hub_descriptor()
461 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
466 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
469 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
471 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
481 struct usb_device *hdev = hub->hdev; in led_work()
484 int cursor = -1; in led_work()
486 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
489 for (i = 0; i < hdev->maxchild; i++) { in led_work()
492 /* 30%-50% duty cycle */ in led_work()
494 switch (hub->indicator[i]) { in led_work()
534 hub->indicator[i] = mode; in led_work()
538 cursor %= hdev->maxchild; in led_work()
540 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
545 &hub->leds, LED_CYCLE_PERIOD); in led_work()
558 int i, status = -ETIMEDOUT; in get_hub_status()
561 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
576 int i, status = -ETIMEDOUT; in get_port_status()
579 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
596 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
597 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
599 if (ret != -ENODEV) in hub_ext_port_status()
600 dev_err(hub->intfdev, in hub_ext_port_status()
603 ret = -EIO; in hub_ext_port_status()
605 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
606 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
609 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
612 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
628 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
630 if (hub->quiescing) { in hub_resubmit_irq_urb()
631 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
635 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
636 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
637 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
638 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
639 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
642 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
657 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
661 * Suppress autosuspend until the event is proceed. in kick_hub_wq()
668 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
670 kref_get(&hub->kref); in kick_hub_wq()
672 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
677 kref_put(&hub->kref, hub_release); in kick_hub_wq()
707 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
708 if (port_dev && port_dev->child) in usb_wakeup_notification()
709 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
711 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
720 struct usb_hub *hub = urb->context; in hub_irq()
721 int status = urb->status; in hub_irq()
726 case -ENOENT: /* synchronous unlink */ in hub_irq()
727 case -ECONNRESET: /* async unlink */ in hub_irq()
728 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
733 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
734 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
736 hub->error = status; in hub_irq()
742 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
743 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
745 hub->event_bits[0] = bits; in hub_irq()
749 hub->nerrors = 0; in hub_irq()
788 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
789 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
792 struct usb_device *hdev = hub->hdev; in hub_tt_work()
796 next = hub->tt.clear_list.next; in hub_tt_work()
798 list_del(&clear->clear_list); in hub_tt_work()
801 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
802 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
803 if (status && status != -ENODEV) in hub_tt_work()
804 dev_err(&hdev->dev, in hub_tt_work()
806 clear->tt, clear->devinfo, status); in hub_tt_work()
809 drv = clear->hcd->driver; in hub_tt_work()
810 if (drv->clear_tt_buffer_complete) in hub_tt_work()
811 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
814 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
816 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
820 * usb_hub_set_port_power - control hub port's power state
845 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
847 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
852 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
867 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
868 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
869 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
879 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
881 return -ENOMEM; in usb_hub_clear_tt_buffer()
885 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
886 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
887 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
888 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
892 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
895 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
896 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
899 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
900 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
901 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
902 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
913 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
918 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
920 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
921 "non-switchable hub\n"); in hub_power_on()
922 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
923 if (test_bit(port1, hub->power_bits)) in hub_power_on()
924 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
926 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
937 mutex_lock(&hub->status_mutex); in hub_hub_status()
938 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
940 if (ret != -ENODEV) in hub_hub_status()
941 dev_err(hub->intfdev, in hub_hub_status()
944 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
945 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
948 mutex_unlock(&hub->status_mutex); in hub_hub_status()
955 return set_port_feature(hub->hdev, in hub_set_port_link_state()
961 * Disable a port and mark a logical connect-change event, so that some
963 * and will re-enumerate if there actually is a device attached.
967 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
971 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
972 * - SRP saves power that way in hub_port_logical_disconnect()
973 * - ... new call, TBD ... in hub_port_logical_disconnect()
974 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
979 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
984 * usb_remove_device - disable a device's port on its parent hub
1001 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1002 return -EINVAL; in usb_remove_device()
1003 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1004 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1010 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1011 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1026 struct usb_device *hdev = hub->hdev; in hub_activate()
1032 unsigned delay; in hub_activate() local
1036 device_lock(&hdev->dev); in hub_activate()
1039 if (hub->disconnected) in hub_activate()
1045 kref_get(&hub->kref); in hub_activate()
1058 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1061 hdev->level - 1, 0, NULL, 0, in hub_activate()
1064 dev_err(hub->intfdev, in hub_activate()
1069 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1070 * and the implementation looks like a home-brewed sort of in hub_activate()
1081 delay = hub_power_on_good_delay(hub); in hub_activate()
1084 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1086 &hub->init_work, in hub_activate()
1087 msecs_to_jiffies(delay)); in hub_activate()
1089 /* Suppress autosuspend until init is done */ in hub_activate()
1091 to_usb_interface(hub->intfdev)); in hub_activate()
1098 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1099 if (hcd->driver->update_hub_device) { in hub_activate()
1100 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1101 &hub->tt, GFP_NOIO); in hub_activate()
1103 dev_err(hub->intfdev, in hub_activate()
1105 dev_err(hub->intfdev, in hub_activate()
1117 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1120 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1121 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1122 struct usb_device *udev = port_dev->child; in hub_activate()
1131 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1144 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1157 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1160 set_bit(port1, hub->event_bits); in hub_activate()
1172 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1175 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1180 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1185 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1189 hub_is_superspeed(hub->hdev)) { in hub_activate()
1191 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1199 clear_bit(port1, hub->removed_bits); in hub_activate()
1201 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1212 set_bit(port1, hub->change_bits); in hub_activate()
1224 * bit on device-initiated resume. in hub_activate()
1226 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1228 set_bit(port1, hub->change_bits); in hub_activate()
1230 } else if (udev->persist_enabled) { in hub_activate()
1232 udev->reset_resume = 1; in hub_activate()
1237 if (test_bit(port1, hub->power_bits)) in hub_activate()
1238 set_bit(port1, hub->change_bits); in hub_activate()
1243 set_bit(port1, hub->change_bits); in hub_activate()
1247 /* If no port-status-change flags were set, we don't need any in hub_activate()
1252 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1256 delay = HUB_DEBOUNCE_STABLE; in hub_activate()
1260 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1262 &hub->init_work, in hub_activate()
1263 msecs_to_jiffies(delay)); in hub_activate()
1264 device_unlock(&hdev->dev); in hub_activate()
1267 msleep(delay); in hub_activate()
1271 hub->quiescing = 0; in hub_activate()
1273 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1275 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1276 if (hub->has_indicators && blinkenlights) in hub_activate()
1278 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1284 /* Allow autosuspend if it was suppressed */ in hub_activate()
1286 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1287 device_unlock(&hdev->dev); in hub_activate()
1290 kref_put(&hub->kref, hub_release); in hub_activate()
1314 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1318 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1319 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1320 hub->quiescing = 1; in hub_quiesce()
1321 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1325 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1326 if (hub->ports[i]->child) in hub_quiesce()
1327 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1332 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1333 usb_kill_urb(hub->urb); in hub_quiesce()
1334 if (hub->has_indicators) in hub_quiesce()
1335 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1336 if (hub->tt.hub) in hub_quiesce()
1337 flush_work(&hub->tt.clear_work); in hub_quiesce()
1344 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1345 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1354 hub->in_reset = 1; in hub_pre_reset()
1364 hub->in_reset = 0; in hub_post_reset()
1374 struct usb_device *hdev = hub->hdev; in hub_configure()
1375 struct device *hub_dev = hub->intfdev; in hub_configure()
1385 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1386 if (!hub->buffer) { in hub_configure()
1387 ret = -ENOMEM; in hub_configure()
1391 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1392 if (!hub->status) { in hub_configure()
1393 ret = -ENOMEM; in hub_configure()
1396 mutex_init(&hub->status_mutex); in hub_configure()
1398 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1399 if (!hub->descriptor) { in hub_configure()
1400 ret = -ENOMEM; in hub_configure()
1405 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1406 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1408 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1418 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1420 ret = -ENODEV; in hub_configure()
1422 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1424 ret = -ENODEV; in hub_configure()
1433 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure() local
1435 if (hdev->parent) in hub_configure()
1436 delay += hdev->parent->hub_delay; in hub_configure()
1438 delay += USB_TP_TRANSMISSION_DELAY; in hub_configure()
1439 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1442 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1446 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1447 if (!hub->ports) { in hub_configure()
1448 ret = -ENOMEM; in hub_configure()
1452 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1467 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1490 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1493 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1497 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1501 spin_lock_init(&hub->tt.lock); in hub_configure()
1502 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1503 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1504 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1509 hub->tt.hub = hdev; in hub_configure()
1515 hub->tt.multi = 1; in hub_configure()
1519 hub->tt.hub = hdev; in hub_configure()
1526 hdev->descriptor.bDeviceProtocol); in hub_configure()
1533 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1534 hub->tt.think_time = 666; in hub_configure()
1537 8, hub->tt.think_time); in hub_configure()
1541 hub->tt.think_time = 666 * 2; in hub_configure()
1544 16, hub->tt.think_time); in hub_configure()
1547 hub->tt.think_time = 666 * 3; in hub_configure()
1550 24, hub->tt.think_time); in hub_configure()
1553 hub->tt.think_time = 666 * 4; in hub_configure()
1556 32, hub->tt.think_time); in hub_configure()
1560 /* probe() zeroes hub->indicator[] */ in hub_configure()
1562 hub->has_indicators = 1; in hub_configure()
1567 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1569 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1570 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1577 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1578 if (hdev == hdev->bus->root_hub) { in hub_configure()
1579 if (hcd->power_budget > 0) in hub_configure()
1580 hdev->bus_mA = hcd->power_budget; in hub_configure()
1582 hdev->bus_mA = full_load * maxchild; in hub_configure()
1583 if (hdev->bus_mA >= full_load) in hub_configure()
1584 hub->mA_per_port = full_load; in hub_configure()
1586 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1587 hub->limited_power = 1; in hub_configure()
1590 int remaining = hdev->bus_mA - in hub_configure()
1591 hub->descriptor->bHubContrCurrent; in hub_configure()
1594 hub->descriptor->bHubContrCurrent); in hub_configure()
1595 hub->limited_power = 1; in hub_configure()
1601 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1603 } else { /* Self-powered external hub */ in hub_configure()
1604 /* FIXME: What about battery-powered external hubs that in hub_configure()
1606 hub->mA_per_port = full_load; in hub_configure()
1608 if (hub->mA_per_port < full_load) in hub_configure()
1610 hub->mA_per_port); in hub_configure()
1619 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1625 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1634 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1637 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1638 maxp = sizeof(*hub->buffer); in hub_configure()
1640 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1641 if (!hub->urb) { in hub_configure()
1642 ret = -ENOMEM; in hub_configure()
1646 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1647 hub, endpoint->bInterval); in hub_configure()
1650 if (hub->has_indicators && blinkenlights) in hub_configure()
1651 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1657 dev_err(hub->intfdev, in hub_configure()
1662 hdev->maxchild = i; in hub_configure()
1663 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1664 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1666 pm_runtime_put(&port_dev->dev); in hub_configure()
1676 if (hcd->driver->update_hub_device) { in hub_configure()
1677 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1678 &hub->tt, GFP_KERNEL); in hub_configure()
1685 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1701 usb_put_dev(hub->hdev); in hub_release()
1702 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1718 hub->disconnected = 1; in hub_disconnect()
1721 hub->error = 0; in hub_disconnect()
1728 port1 = hdev->maxchild; in hub_disconnect()
1729 hdev->maxchild = 0; in hub_disconnect()
1733 for (; port1 > 0; --port1) in hub_disconnect()
1738 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1739 highspeed_hubs--; in hub_disconnect()
1741 usb_free_urb(hub->urb); in hub_disconnect()
1742 kfree(hub->ports); in hub_disconnect()
1743 kfree(hub->descriptor); in hub_disconnect()
1744 kfree(hub->status); in hub_disconnect()
1745 kfree(hub->buffer); in hub_disconnect()
1747 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1749 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1752 kref_put(&hub->kref, hub_release); in hub_disconnect()
1759 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1760 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1763 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1764 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1768 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1780 desc = intf->cur_altsetting; in hub_probe()
1784 * Set default autosuspend delay as 0 to speedup bus suspend, in hub_probe()
1787 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1788 * autosuspend delay to provide enough time to handle a wakeup in hub_probe()
1792 * - The patch might cause one or more auto supend/resume for in hub_probe()
1804 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1808 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1812 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1816 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1817 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1820 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1821 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1829 if (hdev->parent) { /* normal device */ in hub_probe()
1832 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1834 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1838 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1839 dev_err(&intf->dev, in hub_probe()
1841 return -E2BIG; in hub_probe()
1845 if (hdev->parent) { in hub_probe()
1846 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1847 return -ENODEV; in hub_probe()
1852 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1853 return -EIO; in hub_probe()
1857 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1861 return -ENOMEM; in hub_probe()
1863 kref_init(&hub->kref); in hub_probe()
1864 hub->intfdev = &intf->dev; in hub_probe()
1865 hub->hdev = hdev; in hub_probe()
1866 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1867 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1868 INIT_WORK(&hub->events, hub_event); in hub_probe()
1869 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1870 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1875 intf->needs_remote_wakeup = 1; in hub_probe()
1876 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1878 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1881 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1882 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1884 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { in hub_probe()
1885 hub->quirk_disable_autosuspend = 1; in hub_probe()
1889 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) in hub_probe()
1893 return -ENODEV; in hub_probe()
1909 if (hdev->devnum <= 0) in hub_ioctl()
1910 info->nports = 0; in hub_ioctl()
1912 info->nports = hdev->maxchild; in hub_ioctl()
1913 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1914 if (hub->ports[i]->child == NULL) in hub_ioctl()
1915 info->port[i] = 0; in hub_ioctl()
1917 info->port[i] = in hub_ioctl()
1918 hub->ports[i]->child->devnum; in hub_ioctl()
1923 return info->nports + 1; in hub_ioctl()
1927 return -ENOSYS; in hub_ioctl()
1940 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
1941 return -ENODEV; in find_port_owner()
1942 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
1943 return -EINVAL; in find_port_owner()
1948 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1963 return -EBUSY; in usb_hub_claim_port()
1979 return -ENOENT; in usb_hub_release_port()
1990 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
1991 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
1992 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2002 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2004 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2005 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2013 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2014 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2015 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2017 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2018 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2019 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2023 * usb_set_device_state - change a device's current state (usbcore, hcds)
2027 * udev->state is _not_ fully protected by the device lock. Although
2038 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2039 * Otherwise udev->state is set to new_state, and if new_state is
2047 int wakeup = -1; in usb_set_device_state()
2050 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2054 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2057 if (udev->parent) { in usb_set_device_state()
2058 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2062 wakeup = (udev->quirks & in usb_set_device_state()
2064 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2069 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2071 udev->active_duration -= jiffies; in usb_set_device_state()
2073 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2074 udev->active_duration += jiffies; in usb_set_device_state()
2075 udev->state = new_state; in usb_set_device_state()
2080 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2087 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2088 * USB-2.0 buses they are also used as device addresses, however on
2089 * USB-3.0 buses the address is assigned by the controller hardware
2093 * device <-> virtual port number becomes 1:1. Why? to simplify the
2102 * We add 1 as an offset to the one-based USB-stack port number
2103 * (zero-based wusb virtual port index) for two reasons: (a) dev addr
2106 * port #1, which is wusb virtual-port #0 has address #2.
2116 struct usb_bus *bus = udev->bus; in choose_devnum()
2119 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2120 if (udev->wusb) { in choose_devnum()
2121 devnum = udev->portnum + 1; in choose_devnum()
2122 BUG_ON(test_bit(devnum, bus->devmap.devicemap)); in choose_devnum()
2125 * bus->devnum_next. */ in choose_devnum()
2126 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2127 bus->devnum_next); in choose_devnum()
2129 devnum = find_next_zero_bit(bus->devmap.devicemap, in choose_devnum()
2131 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2134 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2135 udev->devnum = devnum; in choose_devnum()
2137 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2142 if (udev->devnum > 0) { in release_devnum()
2143 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2144 udev->devnum = -1; in release_devnum()
2151 if (!udev->wusb) in update_devnum()
2152 udev->devnum = devnum; in update_devnum()
2153 if (!udev->devaddr) in update_devnum()
2154 udev->devaddr = (u8)devnum; in update_devnum()
2159 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2162 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2163 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2172 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2173 if (hub->ports[i]->child) in hub_disconnect_children()
2174 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2179 * usb_disconnect - disconnect a device (usbcore-internal)
2207 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2208 udev->devnum); in usb_disconnect()
2214 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2224 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2228 if (udev->parent) { in usb_disconnect()
2229 port1 = udev->portnum; in usb_disconnect()
2230 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2231 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2233 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2234 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2237 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2240 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2241 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2244 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2248 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2251 device_del(&udev->dev); in usb_disconnect()
2263 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2264 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2268 put_device(&udev->dev); in usb_disconnect()
2276 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2281 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2283 dev_info(&udev->dev, in announce_device()
2285 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2286 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2288 dev_info(&udev->dev, in announce_device()
2290 udev->descriptor.iManufacturer, in announce_device()
2291 udev->descriptor.iProduct, in announce_device()
2292 udev->descriptor.iSerialNumber); in announce_device()
2293 show_string(udev, "Product", udev->product); in announce_device()
2294 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2295 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2303 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2306 * Finish enumeration for On-The-Go devices
2316 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2320 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2321 && udev->config in usb_enumerate_device_otg()
2322 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2324 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2325 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2328 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2329 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2331 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2334 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2335 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2338 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2339 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2351 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2353 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2355 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2365 dev_err(&udev->dev, in usb_enumerate_device_otg()
2376 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2380 * and FIXME -- all comments that apply to them apply here wrt to
2392 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2394 if (udev->config == NULL) { in usb_enumerate_device()
2397 if (err != -ENODEV) in usb_enumerate_device()
2398 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2405 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2406 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2407 udev->descriptor.iManufacturer); in usb_enumerate_device()
2408 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2414 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2419 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2420 || udev->bus->is_b_host)) { in usb_enumerate_device()
2423 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2425 return -ENOTSUPP; in usb_enumerate_device()
2435 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2437 u8 port = udev->portnum; in set_usb_port_removable()
2441 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2446 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2452 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2454 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2458 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2468 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2474 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2478 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2483 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2485 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2490 * usb_new_device - perform initial device setup (usbcore-internal)
2503 * Only the hub driver or root-hub registrar should ever call this.
2514 if (udev->parent) { in usb_new_device()
2515 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2519 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2522 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2523 pm_runtime_set_active(&udev->dev); in usb_new_device()
2524 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2525 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2526 pm_runtime_enable(&udev->dev); in usb_new_device()
2528 /* By default, forbid autosuspend for all devices. It will be in usb_new_device()
2536 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2537 udev->devnum, udev->bus->busnum, in usb_new_device()
2538 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2539 /* export the usbdev device-node for libusb */ in usb_new_device()
2540 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2541 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2546 if (udev->serial) in usb_new_device()
2547 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2548 if (udev->product) in usb_new_device()
2549 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2550 if (udev->manufacturer) in usb_new_device()
2551 add_device_randomness(udev->manufacturer, in usb_new_device()
2552 strlen(udev->manufacturer)); in usb_new_device()
2554 device_enable_async_suspend(&udev->dev); in usb_new_device()
2556 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2560 * for configuring the device and invoking the add-device in usb_new_device()
2563 err = device_add(&udev->dev); in usb_new_device()
2565 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2570 if (udev->parent) { in usb_new_device()
2571 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2572 int port1 = udev->portnum; in usb_new_device()
2573 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2575 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2576 &port_dev->dev.kobj, "port"); in usb_new_device()
2580 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2581 &udev->dev.kobj, "device"); in usb_new_device()
2583 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2587 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2588 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2591 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2593 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2598 pm_runtime_disable(&udev->dev); in usb_new_device()
2599 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2605 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2619 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2622 usb_dev->authorized = 0; in usb_deauthorize_device()
2623 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2636 if (usb_dev->authorized == 1) in usb_authorize_device()
2641 dev_err(&usb_dev->dev, in usb_authorize_device()
2646 if (usb_dev->wusb) { in usb_authorize_device()
2647 result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor)); in usb_authorize_device()
2649 dev_err(&usb_dev->dev, "can't re-read device descriptor for " in usb_authorize_device()
2655 usb_dev->authorized = 1; in usb_authorize_device()
2663 dev_err(&usb_dev->dev, in usb_authorize_device()
2669 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2680 * get_port_ssp_rate - Match the extended port status to SSP rate
2691 struct usb_ssp_cap_descriptor *ssp_cap = hdev->bos->ssp_cap; in get_port_ssp_rate()
2704 ssac = le32_to_cpu(ssp_cap->bmAttributes) & in get_port_ssp_rate()
2710 attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in get_port_ssp_rate()
2758 if (hub->hdev->parent != NULL) /* not a root hub? */ in hub_is_wusb()
2760 hcd = bus_to_hcd(hub->hdev->bus); in hub_is_wusb()
2761 return hcd->wireless; in hub_is_wusb()
2790 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2800 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2821 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2824 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2833 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_wait_reset() argument
2842 delay_time += delay) { in hub_port_wait_reset()
2844 msleep(delay); in hub_port_wait_reset()
2847 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2862 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2863 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2869 /* switch to the long delay after two short delay failures */ in hub_port_wait_reset()
2871 delay = HUB_LONG_RESET_TIME; in hub_port_wait_reset()
2873 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2875 warm ? "warm " : "", delay); in hub_port_wait_reset()
2879 return -EBUSY; in hub_port_wait_reset()
2882 return -ENOTCONN; in hub_port_wait_reset()
2886 return -ENOTCONN; in hub_port_wait_reset()
2890 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
2892 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2894 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2896 return -EAGAIN; in hub_port_wait_reset()
2900 return -EBUSY; in hub_port_wait_reset()
2905 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2907 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2908 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2909 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2911 udev->rx_lanes = 1; in hub_port_wait_reset()
2912 udev->tx_lanes = 1; in hub_port_wait_reset()
2913 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
2916 udev->speed = USB_SPEED_WIRELESS; in hub_port_wait_reset()
2917 else if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
2918 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2919 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2920 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2922 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2924 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2926 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2932 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_reset() argument
2936 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2939 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2941 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2943 return -EINVAL; in hub_port_reset()
2959 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2963 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2966 if (status == -ENODEV) { in hub_port_reset()
2969 dev_err(&port_dev->dev, in hub_port_reset()
2973 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2975 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
2976 dev_dbg(hub->intfdev, in hub_port_reset()
2982 if (status == 0 || status == -ENOTCONN || status == -ENODEV) { in hub_port_reset()
2983 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2986 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2989 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2991 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2995 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3000 * state, re-issue the warm reset. in hub_port_reset()
3015 dev_dbg(&port_dev->dev, in hub_port_reset()
3021 dev_dbg(&port_dev->dev, in hub_port_reset()
3024 delay = HUB_LONG_RESET_TIME; in hub_port_reset()
3027 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
3031 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
3037 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
3038 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3045 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3051 if (hcd->driver->reset_device) in hub_port_reset()
3052 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3061 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3072 if (hub_is_superspeed(hub->hdev)) { in port_is_power_on()
3084 __acquires(&port_dev->status_lock) in usb_lock_port()
3086 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3087 __acquire(&port_dev->status_lock); in usb_lock_port()
3091 __releases(&port_dev->status_lock) in usb_unlock_port()
3093 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3094 __release(&port_dev->status_lock); in usb_unlock_port()
3104 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3117 * is ready for a reset-resume, or should be disconnected.
3123 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3128 if (status == 0 && udev->reset_resume in check_port_resume_type()
3136 status = -ENODEV; in check_port_resume_type()
3138 if (retries--) { in check_port_resume_type()
3144 status = -ENODEV; in check_port_resume_type()
3148 * so try a reset-resume instead. in check_port_resume_type()
3150 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3151 if (udev->persist_enabled) in check_port_resume_type()
3152 udev->reset_resume = 1; in check_port_resume_type()
3154 status = -ENODEV; in check_port_resume_type()
3158 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3160 } else if (udev->reset_resume) { in check_port_resume_type()
3162 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3164 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3167 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3171 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3172 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3173 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3175 * following the reset-resume. in check_port_resume_type()
3177 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3185 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3188 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3195 if (!udev->actconfig) in usb_disable_ltm()
3207 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3210 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3217 if (!udev->actconfig) in usb_enable_ltm()
3228 * usb_enable_remote_wakeup - enable remote wakeup for a device
3231 * For USB-2 devices: Set the device's remote wakeup feature.
3233 * For USB-3 devices: Assume there's only one function on the device and
3239 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3254 * usb_disable_remote_wakeup - disable remote wakeup for a device
3257 * For USB-2 devices: Clear the device's remote wakeup feature.
3259 * For USB-3 devices: Assume there's only one function on the device and
3265 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3277 /* Count of wakeup-enabled devices at or below udev */
3282 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3283 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3288 * usb_port_suspend - suspend a usb device's upstream port
3311 * between a pair of dual-role devices. That will change roles, such
3312 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3318 * - suspend, resume ... when the VBUS power link stays live
3319 * - suspend, disconnect ... VBUS lost
3322 * normal re-enumeration procedures, starting with enabling VBUS power.
3323 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3327 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3329 * hub is suspended). Nevertheless, we change @udev->state to
3331 * upstream port setting is stored in @udev->port_is_suspended.
3337 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3338 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3339 int port1 = udev->portnum; in usb_port_suspend()
3351 if (udev->do_remote_wakeup) { in usb_port_suspend()
3354 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3356 /* bail if autosuspend is requested */ in usb_port_suspend()
3366 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3367 status = -ENOMEM; in usb_port_suspend()
3373 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3378 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3388 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3398 if (status == -ETIMEDOUT) { in usb_port_suspend()
3406 dev_dbg(&port_dev->dev, in usb_port_suspend()
3415 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3423 if (udev->do_remote_wakeup) in usb_port_suspend()
3432 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3433 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3434 udev->do_remote_wakeup); in usb_port_suspend()
3436 udev->port_is_suspended = 1; in usb_port_suspend()
3444 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3445 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3446 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3448 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3462 * If @udev->reset_resume is set then the device is reset before the
3471 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3472 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3479 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3488 if (udev->reset_resume) { in finish_port_resume()
3491 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3496 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3497 status = -ENODEV; in finish_port_resume()
3510 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3511 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3512 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3513 udev->reset_resume = 1; in finish_port_resume()
3519 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3525 * udev->reset_resume in finish_port_resume()
3527 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3528 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3540 dev_dbg(&udev->dev, in finish_port_resume()
3554 * device switch on the RX termination after long delay of host enabling
3582 status = -ENODEV; in wait_for_connected()
3589 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3594 * usb_port_resume - re-activate a suspended usb device's upstream port
3595 * @udev: device to re-activate, not a root hub
3598 * This will re-activate the suspended device, increasing power usage
3604 * If @udev->reset_resume is set then this routine won't check that the
3612 * for mass-storage devices containing mounted filesystems, since the
3629 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3630 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3631 int port1 = udev->portnum; in usb_port_resume()
3635 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3636 status = pm_runtime_resume_and_get(&port_dev->dev); in usb_port_resume()
3638 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3646 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3650 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3655 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3658 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3661 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3664 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3665 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3677 udev->port_is_suspended = 0; in usb_port_resume()
3678 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3680 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3684 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3692 if (udev->persist_enabled) in usb_port_resume()
3701 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3721 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3722 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3736 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3738 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3745 hdev = hub->hdev; in hub_handle_remote_wakeup()
3746 udev = port_dev->child; in hub_handle_remote_wakeup()
3753 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3770 ret = -ENODEV; in hub_handle_remote_wakeup()
3773 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3781 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3795 struct usb_device *hdev = hub->hdev; in hub_suspend()
3800 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3802 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3803 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3804 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3805 struct usb_device *udev = port_dev->child; in hub_suspend()
3807 if (udev && udev->can_submit) { in hub_suspend()
3808 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3809 dev_name(&udev->dev)); in hub_suspend()
3811 return -EBUSY; in hub_suspend()
3814 hub->wakeup_enabled_descendants += in hub_suspend()
3818 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3822 return -EBUSY; in hub_suspend()
3823 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3827 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3829 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3839 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3849 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3855 if (hdev->parent) in report_wakeup_requests()
3858 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3859 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3869 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3870 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3872 udev = hub->ports[i]->child; in report_wakeup_requests()
3874 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3884 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
3901 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
3907 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3914 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
3919 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
3920 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
3933 * device-initiated U1 or U2. This lets the device know the exit latencies from
3949 if (udev->state != USB_STATE_CONFIGURED) in usb_req_set_sel()
3953 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
3954 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
3955 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
3956 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
3963 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
3972 dev_dbg(&udev->dev, "Device-initiated %s disabled due to long SEL %llu us or PEL %llu us\n", in usb_req_set_sel()
3974 return -EINVAL; in usb_req_set_sel()
3978 * If we're enabling device-initiated LPM for one link state, in usb_req_set_sel()
4001 return -ENOMEM; in usb_req_set_sel()
4003 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
4004 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
4005 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
4006 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
4019 * Enable or disable device-initiated U1 or U2 transitions.
4035 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4037 return -EINVAL; in usb_set_device_initiated_lpm()
4040 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4041 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4050 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
4068 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4071 return -EBUSY; in usb_set_device_initiated_lpm()
4090 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4092 return -EINVAL; in usb_set_lpm_timeout()
4097 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4100 return -EINVAL; in usb_set_lpm_timeout()
4103 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4104 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4107 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4110 return -EBUSY; in usb_set_lpm_timeout()
4113 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4115 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4131 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4133 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4137 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4142 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4146 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) { in usb_device_may_initiate_lpm()
4147 desc = &intf->cur_altsetting->endpoint[j].desc; in usb_device_may_initiate_lpm()
4151 interval = (1 << (desc->bInterval - 1)) * 125; in usb_device_may_initiate_lpm()
4161 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4165 * control transfers to set the hub timeout or enable device-initiated U1/U2
4168 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4169 * hub-initiated U1/U2 will be disabled.
4179 __u8 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4180 __le16 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4196 dev_warn(&udev->dev, "Set SEL for device-initiated %s failed.\n", in usb_enable_link_state()
4206 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4213 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4221 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4224 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4231 if (udev->actconfig && in usb_enable_link_state()
4239 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4245 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4247 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4250 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4253 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4256 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4258 * still disallow device-initiated U1/U2 entry.
4272 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4274 return -EINVAL; in usb_disable_link_state()
4278 return -EBUSY; in usb_disable_link_state()
4282 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4283 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4290 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4294 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4296 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4302 * Disable hub-initiated and device-initiated U1 and U2 entry.
4306 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4312 if (!udev || !udev->parent || in usb_disable_lpm()
4313 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4314 !udev->lpm_capable || in usb_disable_lpm()
4315 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4318 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4319 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4322 udev->lpm_disable_count++; in usb_disable_lpm()
4323 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4336 return -EBUSY; in usb_disable_lpm()
4343 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4347 return -EINVAL; in usb_unlocked_disable_lpm()
4349 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4351 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4358 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4371 if (!udev || !udev->parent || in usb_enable_lpm()
4372 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4373 !udev->lpm_capable || in usb_enable_lpm()
4374 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4377 udev->lpm_disable_count--; in usb_enable_lpm()
4378 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4382 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4383 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4386 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4389 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4393 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4395 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4398 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4406 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4411 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4413 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4421 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4424 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4425 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4432 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4434 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4483 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4484 * a connection with a plugged-in cable but will signal the host when the cable
4485 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4489 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4490 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4493 if (!hub->error) { in hub_port_disable()
4494 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4496 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4503 if (port_dev->child && set_state) in hub_port_disable()
4504 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4505 if (ret && ret != -ENODEV) in hub_port_disable()
4506 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4511 * usb_port_disable - disable a usb device's upstream port
4519 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4521 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4524 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4526 * Between connect detection and reset signaling there must be a delay
4527 * of 100ms at least for debounce and power-settling. The corresponding
4530 * Apparently there are some bluetooth and irda-dongles and a number of
4531 * low-speed devices for which this debounce period may last over a second.
4532 * Not covered by the spec - but easy to deal with.
4535 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4545 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4565 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4574 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4578 return -ETIMEDOUT; in hub_port_debounce()
4586 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4596 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4602 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4603 return -EINVAL; in hub_set_address()
4604 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4606 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4607 return -EINVAL; in hub_set_address()
4608 if (hcd->driver->address_device) in hub_set_address()
4609 retval = hcd->driver->address_device(hcd, udev); in hub_set_address()
4634 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4637 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4641 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4643 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4645 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4652 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4654 if (!hcd->driver->enable_device) in hub_enable_device()
4656 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4658 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4659 return -EINVAL; in hub_enable_device()
4661 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4668 * If this is called for an already-existing device (as part of
4678 struct usb_device *hdev = hub->hdev; in hub_port_init()
4679 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4680 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4682 unsigned delay = HUB_SHORT_RESET_TIME; in hub_port_init() local
4683 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4685 int devnum = udev->devnum; in hub_port_init()
4692 if (!hdev->parent) { in hub_port_init()
4693 delay = HUB_ROOT_RESET_TIME; in hub_port_init()
4694 if (port1 == hdev->bus->otg_port) in hub_port_init()
4695 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4698 /* Some low speed devices have problems with the quick delay, so */ in hub_port_init()
4701 delay = HUB_LONG_RESET_TIME; in hub_port_init()
4703 mutex_lock(hcd->address0_mutex); in hub_port_init()
4707 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4712 retval = -ENODEV; in hub_port_init()
4715 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4716 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4717 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4720 oldspeed = udev->speed; in hub_port_init()
4727 switch (udev->speed) { in hub_port_init()
4731 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4734 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4741 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4744 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4750 if (udev->speed == USB_SPEED_WIRELESS) in hub_port_init()
4753 speed = usb_speed_string(udev->speed); in hub_port_init()
4760 * platform device is usually a dual-role USB controller device. in hub_port_init()
4762 if (udev->bus->controller->driver) in hub_port_init()
4763 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4765 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4767 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4768 dev_info(&udev->dev, in hub_port_init()
4770 (udev->config) ? "reset" : "new", speed, in hub_port_init()
4774 if (hdev->tt) { in hub_port_init()
4775 udev->tt = hdev->tt; in hub_port_init()
4776 udev->ttport = hdev->ttport; in hub_port_init()
4777 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4778 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4779 if (!hub->tt.hub) { in hub_port_init()
4780 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4781 retval = -EINVAL; in hub_port_init()
4784 udev->tt = &hub->tt; in hub_port_init()
4785 udev->ttport = port1; in hub_port_init()
4794 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4795 * so it may help with some non-standards-compliant devices. in hub_port_init()
4809 dev_err(&udev->dev, in hub_port_init()
4818 retval = -ENOMEM; in hub_port_init()
4828 buf->bMaxPacketSize0 = 0; in hub_port_init()
4834 switch (buf->bMaxPacketSize0) { in hub_port_init()
4836 if (buf->bDescriptorType == in hub_port_init()
4844 r = -EPROTO; in hub_port_init()
4853 if (r == 0 || (r == -ETIMEDOUT && in hub_port_init()
4855 udev->speed > USB_SPEED_FULL)) in hub_port_init()
4858 udev->descriptor.bMaxPacketSize0 = in hub_port_init()
4859 buf->bMaxPacketSize0; in hub_port_init()
4862 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4865 if (oldspeed != udev->speed) { in hub_port_init()
4866 dev_dbg(&udev->dev, in hub_port_init()
4868 retval = -ENODEV; in hub_port_init()
4872 if (r != -ENODEV) in hub_port_init()
4873 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4875 retval = -EMSGSIZE; in hub_port_init()
4886 if (udev->wusb == 0) { in hub_port_init()
4894 if (retval != -ENODEV) in hub_port_init()
4895 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
4899 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
4900 devnum = udev->devnum; in hub_port_init()
4901 dev_info(&udev->dev, in hub_port_init()
4903 (udev->config) ? "reset" : "new", in hub_port_init()
4904 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
4906 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
4908 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
4910 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
4916 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
4917 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
4926 if (retval != -ENODEV) in hub_port_init()
4927 dev_err(&udev->dev, in hub_port_init()
4931 retval = -EMSGSIZE; in hub_port_init()
4933 u32 delay; in hub_port_init() local
4937 delay = udev->parent->hub_delay; in hub_port_init()
4938 udev->hub_delay = min_t(u32, delay, in hub_port_init()
4942 dev_dbg(&udev->dev, in hub_port_init()
4943 "Failed set isoch delay, error %d\n", in hub_port_init()
4959 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
4960 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
4961 dev_err(&udev->dev, "got a wrong device descriptor, " in hub_port_init()
4965 retval = -EINVAL; in hub_port_init()
4969 if (udev->descriptor.bMaxPacketSize0 == 0xff || in hub_port_init()
4970 udev->speed >= USB_SPEED_SUPER) in hub_port_init()
4973 i = udev->descriptor.bMaxPacketSize0; in hub_port_init()
4974 if (usb_endpoint_maxp(&udev->ep0.desc) != i) { in hub_port_init()
4975 if (udev->speed == USB_SPEED_LOW || in hub_port_init()
4977 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); in hub_port_init()
4978 retval = -EMSGSIZE; in hub_port_init()
4981 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
4982 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
4984 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
4985 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
4990 if (retval < (signed)sizeof(udev->descriptor)) { in hub_port_init()
4991 if (retval != -ENODEV) in hub_port_init()
4992 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
4995 retval = -ENOMSG; in hub_port_init()
5001 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5004 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5011 if (hcd->driver->update_device) in hub_port_init()
5012 hcd->driver->update_device(hcd, udev); in hub_port_init()
5019 mutex_unlock(hcd->address0_mutex); in hub_port_init()
5029 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5039 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5042 if (hub->has_indicators) { in check_highspeed()
5043 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5045 &hub->leds, 0); in check_highspeed()
5054 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5058 if (!hub->limited_power) in hub_power_remaining()
5061 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5062 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
5063 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5064 struct usb_device *udev = port_dev->child; in hub_power_remaining()
5079 if (udev->actconfig) in hub_power_remaining()
5080 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5081 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5085 if (delta > hub->mA_per_port) in hub_power_remaining()
5086 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
5087 delta, hub->mA_per_port); in hub_power_remaining()
5088 remaining -= delta; in hub_power_remaining()
5091 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5092 -remaining); in hub_power_remaining()
5111 if (memcmp(&udev->descriptor, old_device_descriptor, in descriptors_changed()
5115 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5117 if (udev->bos) { in descriptors_changed()
5118 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5119 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5121 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5131 if (udev->serial) in descriptors_changed()
5132 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5135 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5136 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5145 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5146 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5150 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5155 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5157 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5159 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5167 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5170 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5173 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5174 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5186 int status = -ENODEV; in hub_port_connect()
5189 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5190 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5191 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5192 struct usb_device *udev = port_dev->child; in hub_port_connect()
5193 static int unreliable_port = -1; in hub_port_connect()
5197 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5198 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5199 usb_disconnect(&port_dev->child); in hub_port_connect()
5207 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5213 if (status != -ENODEV && in hub_port_connect()
5216 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5228 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5236 && !port_dev->port_owner) in hub_port_connect()
5243 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5254 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5256 dev_err(&port_dev->dev, in hub_port_connect()
5262 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5263 udev->level = hdev->level + 1; in hub_port_connect()
5264 udev->wusb = hub_is_wusb(hub); in hub_port_connect()
5267 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5268 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5270 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5273 if (udev->devnum <= 0) { in hub_port_connect()
5274 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5278 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5285 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5288 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5291 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5294 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5295 && udev->bus_mA <= unit_load) { in hub_port_connect()
5301 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5305 dev_err(&udev->dev, in hub_port_connect()
5306 "can't connect bus-powered hub " in hub_port_connect()
5308 if (hub->has_indicators) { in hub_port_connect()
5309 hub->indicator[port1-1] = in hub_port_connect()
5313 &hub->leds, 0); in hub_port_connect()
5315 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5321 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5322 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5339 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5340 status = -ENOTCONN; in hub_port_connect()
5342 port_dev->child = udev; in hub_port_connect()
5352 port_dev->child = NULL; in hub_port_connect()
5356 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5357 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5358 udev->speed); in hub_port_connect()
5367 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5378 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5381 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5382 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5383 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5390 if (hub->hdev->parent || in hub_port_connect()
5391 !hcd->driver->port_handed_over || in hub_port_connect()
5392 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5393 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5394 dev_err(&port_dev->dev, in hub_port_connect()
5400 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5401 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5402 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5408 * a port connection-change occurs;
5409 * a port enable-change occurs (often caused by EMI);
5416 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5418 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5419 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5421 int status = -ENODEV; in hub_port_connect_change()
5424 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5427 if (hub->has_indicators) { in hub_port_connect_change()
5429 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5434 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5441 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5444 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5449 descriptor = udev->descriptor; in hub_port_connect_change()
5451 sizeof(udev->descriptor)); in hub_port_connect_change()
5453 dev_dbg(&udev->dev, in hub_port_connect_change()
5458 udev->bos)) { in hub_port_connect_change()
5459 dev_dbg(&udev->dev, in hub_port_connect_change()
5462 udev->descriptor = descriptor; in hub_port_connect_change()
5468 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5469 udev->persist_enabled) { in hub_port_connect_change()
5481 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5492 /* Handle notifying userspace about hub over-current events */
5499 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5501 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5506 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5515 port_dev->over_current_count); in port_over_current_notify()
5520 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5530 __must_hold(&port_dev->status_lock) in port_event()
5533 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5534 struct usb_device *udev = port_dev->child; in port_event()
5535 struct usb_device *hdev = hub->hdev; in port_event()
5538 connect_change = test_bit(port1, hub->change_bits); in port_event()
5539 clear_bit(port1, hub->event_bits); in port_event()
5540 clear_bit(port1, hub->wakeup_bits); in port_event()
5552 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5563 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5570 port_dev->over_current_count++; in port_event()
5573 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5574 port_dev->over_current_count); in port_event()
5581 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5585 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5590 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5595 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5600 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5606 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5617 dev_dbg(&port_dev->dev, "do warm reset\n"); in port_event()
5619 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5648 hdev = hub->hdev; in hub_event()
5649 hub_dev = hub->intfdev; in hub_event()
5652 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5655 hdev->state, hdev->maxchild, in hub_event()
5657 (u16) hub->change_bits[0], in hub_event()
5658 (u16) hub->event_bits[0]); in hub_event()
5663 if (unlikely(hub->disconnected)) in hub_event()
5667 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5668 hub->error = -ENODEV; in hub_event()
5681 if (hub->quiescing) in hub_event()
5684 if (hub->error) { in hub_event()
5685 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5693 hub->nerrors = 0; in hub_event()
5694 hub->error = 0; in hub_event()
5698 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5699 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5701 if (test_bit(i, hub->event_bits) in hub_event()
5702 || test_bit(i, hub->change_bits) in hub_event()
5703 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5710 * (powered-off), we leave it in that state, run in hub_event()
5713 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5714 pm_runtime_barrier(&port_dev->dev); in hub_event()
5718 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5723 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5733 hub->limited_power = 1; in hub_event()
5735 hub->limited_power = 0; in hub_event()
5741 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5747 dev_err(hub_dev, "over-current condition\n"); in hub_event()
5757 /* Balance the stuff in kick_hub_wq() and allow autosuspend */ in hub_event()
5759 kref_put(&hub->kref, hub_release); in hub_event()
5810 return -1; in usb_hub_init()
5815 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
5817 * over to the companion full-speed controller. in usb_hub_init()
5827 return -1; in usb_hub_init()
5839 * individual hub resources. -greg in usb_hub_cleanup()
5845 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
5848 * WARNING - don't use this routine to reset a composite device
5857 * re-connected. All drivers will be unbound, and the device will be
5858 * re-enumerated and probed all over again.
5860 * Return: 0 if the reset succeeded, -ENODEV if the device has been
5880 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
5882 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
5883 struct usb_device_descriptor descriptor = udev->descriptor; in usb_reset_and_verify_device()
5886 int port1 = udev->portnum; in usb_reset_and_verify_device()
5888 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
5889 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
5890 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
5891 udev->state); in usb_reset_and_verify_device()
5892 return -EINVAL; in usb_reset_and_verify_device()
5896 return -EISDIR; in usb_reset_and_verify_device()
5901 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
5906 * Device-initiated LPM, and system exit latency settings are cleared in usb_reset_and_verify_device()
5911 dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__); in usb_reset_and_verify_device()
5915 bos = udev->bos; in usb_reset_and_verify_device()
5916 udev->bos = NULL; in usb_reset_and_verify_device()
5921 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
5924 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
5933 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
5934 udev->descriptor = descriptor; /* for disconnect() calls */ in usb_reset_and_verify_device()
5939 if (!udev->actconfig) in usb_reset_and_verify_device()
5942 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5943 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
5945 dev_warn(&udev->dev, in usb_reset_and_verify_device()
5948 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5953 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
5956 dev_err(&udev->dev, in usb_reset_and_verify_device()
5958 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
5959 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5962 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5966 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
5968 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
5971 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
5972 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
5973 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
5976 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
5977 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
5986 intf->resetting_device = 1; in usb_reset_and_verify_device()
5987 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
5988 desc->bAlternateSetting); in usb_reset_and_verify_device()
5989 intf->resetting_device = 0; in usb_reset_and_verify_device()
5992 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
5994 desc->bInterfaceNumber, in usb_reset_and_verify_device()
5995 desc->bAlternateSetting, in usb_reset_and_verify_device()
6000 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
6001 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
6005 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
6010 udev->bos = bos; in usb_reset_and_verify_device()
6015 udev->bos = bos; in usb_reset_and_verify_device()
6019 return -ENODEV; in usb_reset_and_verify_device()
6023 * usb_reset_device - warn interface drivers and perform a USB port reset
6049 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6050 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6052 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6053 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6054 udev->state); in usb_reset_device()
6055 return -EINVAL; in usb_reset_device()
6058 if (!udev->parent) { in usb_reset_device()
6059 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
6060 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6061 return -EISDIR; in usb_reset_device()
6064 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6077 /* Prevent autosuspend during the reset */ in usb_reset_device()
6081 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
6082 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6086 if (cintf->dev.driver) { in usb_reset_device()
6087 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6088 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
6089 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
6090 else if (cintf->condition == in usb_reset_device()
6104 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
6105 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6107 int rebind = cintf->needs_binding; in usb_reset_device()
6109 if (!rebind && cintf->dev.driver) { in usb_reset_device()
6110 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6111 if (drv->post_reset) in usb_reset_device()
6112 rebind = (drv->post_reset)(cintf); in usb_reset_device()
6113 else if (cintf->condition == in usb_reset_device()
6117 cintf->needs_binding = 1; in usb_reset_device()
6134 * usb_queue_reset_device - Reset a USB device from an atomic context
6147 * - Scheduling two resets at the same time from two different drivers
6150 * handles ->pre_reset(), the second reset might happen or not.
6152 * - If the reset is delayed so long that the interface is unbound from
6155 * - This function can be called during .probe(). It can also be called
6158 * .disconnect(), call usb_reset_device() directly -- but watch out
6163 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6169 * usb_hub_find_child - Get the pointer of child device
6179 * child's usb_device pointer if non-NULL.
6186 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6188 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6203 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6204 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6206 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6210 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6211 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6212 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6217 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6219 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6220 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6222 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6227 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6233 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6239 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6254 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()