Lines Matching +full:has +full:- +full:transaction +full:- +full:translator

1 // SPDX-License-Identifier: GPL-2.0
69 /* Protect struct usb_device->state and ->children members
70 * Note: Both are also protected by ->dev.sem, except that ->state can
78 /* synchronize hub-port add/remove and peering operations */
88 * 10 seconds to send reply for the initial 64-byte descriptor request.
90 /* define initial 64-byte descriptor request timeout in milliseconds */
94 "initial 64-byte descriptor request timeout in milliseconds "
95 "(default 5000 - 5.0 seconds)");
140 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
142 if (hub_is_superspeed(hub->hdev)) in portspeed()
155 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
157 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
163 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
167 if (!udev->bos) in usb_device_supports_lpm()
173 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
174 if (udev->bos->ext_cap && in usb_device_supports_lpm()
176 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
186 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
187 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
191 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
192 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
193 if (udev->parent) in usb_device_supports_lpm()
194 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
196 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
200 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
226 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
228 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
236 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
247 if (!hub->hdev->parent) in usb_set_lpm_mel()
250 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
284 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
287 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
291 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
293 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
297 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
302 * - t1: device PEL
303 * - t2: time for the ERDY to make it from the device to the host.
304 * - t3: a host-specific delay to process the ERDY.
305 * - t4: time for the packet to make it from the host to the device.
319 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
321 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
322 parent = parent->parent) in usb_set_lpm_sel()
324 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
326 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
331 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
343 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
347 if (!udev->bos) in usb_set_lpm_parameters()
350 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
357 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
358 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
359 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
360 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
362 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
363 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
365 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
366 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
378 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
387 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
388 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
392 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
396 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
397 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
401 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
402 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
430 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
432 return -EMSGSIZE; in get_hub_descriptor()
436 return -EINVAL; in get_hub_descriptor()
485 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
490 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
493 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
495 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
505 struct usb_device *hdev = hub->hdev; in led_work()
508 int cursor = -1; in led_work()
510 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
513 for (i = 0; i < hdev->maxchild; i++) { in led_work()
516 /* 30%-50% duty cycle */ in led_work()
518 switch (hub->indicator[i]) { in led_work()
558 hub->indicator[i] = mode; in led_work()
562 cursor %= hdev->maxchild; in led_work()
564 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
569 &hub->leds, LED_CYCLE_PERIOD); in led_work()
582 int i, status = -ETIMEDOUT; in get_hub_status()
585 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
600 int i, status = -ETIMEDOUT; in get_port_status()
603 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
620 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
621 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
623 if (ret != -ENODEV) in hub_ext_port_status()
624 dev_err(hub->intfdev, in hub_ext_port_status()
627 ret = -EIO; in hub_ext_port_status()
629 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
630 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
633 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
636 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
652 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
654 if (hub->quiescing) { in hub_resubmit_irq_urb()
655 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
659 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
660 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
661 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
662 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
663 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
666 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
681 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
692 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
694 kref_get(&hub->kref); in kick_hub_wq()
696 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
699 /* the work has already been scheduled */ in kick_hub_wq()
701 kref_put(&hub->kref, hub_release); in kick_hub_wq()
713 * Let the USB core know that a USB 3.0 device has sent a Function Wake Device
731 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
732 if (port_dev && port_dev->child) in usb_wakeup_notification()
733 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
735 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
744 struct usb_hub *hub = urb->context; in hub_irq()
745 int status = urb->status; in hub_irq()
750 case -ENOENT: /* synchronous unlink */ in hub_irq()
751 case -ECONNRESET: /* async unlink */ in hub_irq()
752 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
757 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
758 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
760 hub->error = status; in hub_irq()
766 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
767 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
769 hub->event_bits[0] = bits; in hub_irq()
773 hub->nerrors = 0; in hub_irq()
812 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
813 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
816 struct usb_device *hdev = hub->hdev; in hub_tt_work()
820 next = hub->tt.clear_list.next; in hub_tt_work()
822 list_del(&clear->clear_list); in hub_tt_work()
825 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
826 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
827 if (status && status != -ENODEV) in hub_tt_work()
828 dev_err(&hdev->dev, in hub_tt_work()
830 clear->tt, clear->devinfo, status); in hub_tt_work()
833 drv = clear->hcd->driver; in hub_tt_work()
834 if (drv->clear_tt_buffer_complete) in hub_tt_work()
835 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
838 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
840 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
844 * usb_hub_set_port_power - control hub port's power state
869 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
871 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
876 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
877 * @urb: an URB associated with the failed or incomplete split transaction
880 * bulk transaction failed in a way that requires clearing internal state of
881 * a transaction translator. This is normally detected (and reported) from
891 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
892 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
893 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
898 * since each TT has "at least two" buffers that can need it (and in usb_hub_clear_tt_buffer()
903 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
905 return -ENOMEM; in usb_hub_clear_tt_buffer()
909 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
910 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
911 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
912 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
916 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
919 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
920 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
923 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
924 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
925 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
926 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
937 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
942 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
944 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
945 "non-switchable hub\n"); in hub_power_on()
946 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
947 if (test_bit(port1, hub->power_bits)) in hub_power_on()
948 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
950 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
961 mutex_lock(&hub->status_mutex); in hub_hub_status()
962 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
964 if (ret != -ENODEV) in hub_hub_status()
965 dev_err(hub->intfdev, in hub_hub_status()
968 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
969 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
972 mutex_unlock(&hub->status_mutex); in hub_hub_status()
979 return set_port_feature(hub->hdev, in hub_set_port_link_state()
985 * Disable a port and mark a logical connect-change event, so that some
987 * and will re-enumerate if there actually is a device attached.
991 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
995 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
996 * - SRP saves power that way in hub_port_logical_disconnect()
997 * - ... new call, TBD ... in hub_port_logical_disconnect()
998 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1003 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1008 * usb_remove_device - disable a device's port on its parent hub
1012 * After @udev's port has been disabled, hub_wq is notified and it will
1013 * see that the device has been disconnected. When the device is
1025 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1026 return -EINVAL; in usb_remove_device()
1027 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1028 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1034 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1035 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1050 struct usb_device *hdev = hub->hdev; in hub_activate()
1060 device_lock(&hdev->dev); in hub_activate()
1063 if (hub->disconnected) in hub_activate()
1069 kref_get(&hub->kref); in hub_activate()
1071 /* The superspeed hub except for root hub has to use Hub Depth in hub_activate()
1082 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1085 hdev->level - 1, 0, NULL, 0, in hub_activate()
1088 dev_err(hub->intfdev, in hub_activate()
1093 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1094 * and the implementation looks like a home-brewed sort of in hub_activate()
1108 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1110 &hub->init_work, in hub_activate()
1115 to_usb_interface(hub->intfdev)); in hub_activate()
1122 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1123 if (hcd->driver->update_hub_device) { in hub_activate()
1124 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1125 &hub->tt, GFP_NOIO); in hub_activate()
1127 dev_err(hub->intfdev, in hub_activate()
1129 dev_err(hub->intfdev, in hub_activate()
1138 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1144 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1147 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1148 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1149 struct usb_device *udev = port_dev->child; in hub_activate()
1158 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1171 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1184 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1187 set_bit(port1, hub->event_bits); in hub_activate()
1199 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1202 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1207 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1212 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1216 hub_is_superspeed(hub->hdev)) { in hub_activate()
1218 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1226 clear_bit(port1, hub->removed_bits); in hub_activate()
1228 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1239 set_bit(port1, hub->change_bits); in hub_activate()
1251 * bit on device-initiated resume. in hub_activate()
1253 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1255 set_bit(port1, hub->event_bits); in hub_activate()
1257 } else if (udev->persist_enabled) { in hub_activate()
1259 udev->reset_resume = 1; in hub_activate()
1264 if (test_bit(port1, hub->power_bits)) in hub_activate()
1265 set_bit(port1, hub->change_bits); in hub_activate()
1270 set_bit(port1, hub->change_bits); in hub_activate()
1274 /* If no port-status-change flags were set, we don't need any in hub_activate()
1279 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1287 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1289 &hub->init_work, in hub_activate()
1291 device_unlock(&hdev->dev); in hub_activate()
1298 hub->quiescing = 0; in hub_activate()
1300 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1302 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1303 if (hub->has_indicators && blinkenlights) in hub_activate()
1305 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1313 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1314 device_unlock(&hdev->dev); in hub_activate()
1317 kref_put(&hub->kref, hub_release); in hub_activate()
1341 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1345 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1346 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1347 hub->quiescing = 1; in hub_quiesce()
1348 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1352 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1353 if (hub->ports[i]->child) in hub_quiesce()
1354 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1359 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1360 usb_kill_urb(hub->urb); in hub_quiesce()
1361 if (hub->has_indicators) in hub_quiesce()
1362 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1363 if (hub->tt.hub) in hub_quiesce()
1364 flush_work(&hub->tt.clear_work); in hub_quiesce()
1371 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1372 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1375 /* caller has locked the hub device */
1381 hub->in_reset = 1; in hub_pre_reset()
1386 /* caller has locked the hub device */
1391 hub->in_reset = 0; in hub_post_reset()
1401 struct usb_device *hdev = hub->hdev; in hub_configure()
1402 struct device *hub_dev = hub->intfdev; in hub_configure()
1412 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1413 if (!hub->buffer) { in hub_configure()
1414 ret = -ENOMEM; in hub_configure()
1418 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1419 if (!hub->status) { in hub_configure()
1420 ret = -ENOMEM; in hub_configure()
1423 mutex_init(&hub->status_mutex); in hub_configure()
1425 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1426 if (!hub->descriptor) { in hub_configure()
1427 ret = -ENOMEM; in hub_configure()
1432 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1433 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1435 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1445 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1446 message = "hub has too many ports!"; in hub_configure()
1447 ret = -ENODEV; in hub_configure()
1449 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1451 ret = -ENODEV; in hub_configure()
1460 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1462 if (hdev->parent) in hub_configure()
1463 delay += hdev->parent->hub_delay; in hub_configure()
1466 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1469 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1473 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1474 if (!hub->ports) { in hub_configure()
1475 ret = -ENOMEM; in hub_configure()
1479 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1494 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1517 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1520 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1524 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1528 spin_lock_init(&hub->tt.lock); in hub_configure()
1529 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1530 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1531 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1536 hub->tt.hub = hdev; in hub_configure()
1542 hub->tt.multi = 1; in hub_configure()
1546 hub->tt.hub = hdev; in hub_configure()
1553 hdev->descriptor.bDeviceProtocol); in hub_configure()
1560 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1561 hub->tt.think_time = 666; in hub_configure()
1564 8, hub->tt.think_time); in hub_configure()
1568 hub->tt.think_time = 666 * 2; in hub_configure()
1571 16, hub->tt.think_time); in hub_configure()
1574 hub->tt.think_time = 666 * 3; in hub_configure()
1577 24, hub->tt.think_time); in hub_configure()
1580 hub->tt.think_time = 666 * 4; in hub_configure()
1583 32, hub->tt.think_time); in hub_configure()
1587 /* probe() zeroes hub->indicator[] */ in hub_configure()
1589 hub->has_indicators = 1; in hub_configure()
1594 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1596 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1597 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1604 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1605 if (hdev == hdev->bus->root_hub) { in hub_configure()
1606 if (hcd->power_budget > 0) in hub_configure()
1607 hdev->bus_mA = hcd->power_budget; in hub_configure()
1609 hdev->bus_mA = full_load * maxchild; in hub_configure()
1610 if (hdev->bus_mA >= full_load) in hub_configure()
1611 hub->mA_per_port = full_load; in hub_configure()
1613 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1614 hub->limited_power = 1; in hub_configure()
1617 int remaining = hdev->bus_mA - in hub_configure()
1618 hub->descriptor->bHubContrCurrent; in hub_configure()
1621 hub->descriptor->bHubContrCurrent); in hub_configure()
1622 hub->limited_power = 1; in hub_configure()
1628 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1630 } else { /* Self-powered external hub */ in hub_configure()
1631 /* FIXME: What about battery-powered external hubs that in hub_configure()
1633 hub->mA_per_port = full_load; in hub_configure()
1635 if (hub->mA_per_port < full_load) in hub_configure()
1637 hub->mA_per_port); in hub_configure()
1646 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1652 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1661 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1664 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1665 maxp = sizeof(*hub->buffer); in hub_configure()
1667 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1668 if (!hub->urb) { in hub_configure()
1669 ret = -ENOMEM; in hub_configure()
1673 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1674 hub, endpoint->bInterval); in hub_configure()
1677 if (hub->has_indicators && blinkenlights) in hub_configure()
1678 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1684 dev_err(hub->intfdev, in hub_configure()
1689 hdev->maxchild = i; in hub_configure()
1690 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1691 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1693 pm_runtime_put(&port_dev->dev); in hub_configure()
1703 if (hcd->driver->update_hub_device) { in hub_configure()
1704 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1705 &hub->tt, GFP_KERNEL); in hub_configure()
1712 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1728 usb_put_dev(hub->hdev); in hub_release()
1729 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1745 hub->disconnected = 1; in hub_disconnect()
1748 hub->error = 0; in hub_disconnect()
1755 port1 = hdev->maxchild; in hub_disconnect()
1756 hdev->maxchild = 0; in hub_disconnect()
1760 for (; port1 > 0; --port1) in hub_disconnect()
1765 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1766 highspeed_hubs--; in hub_disconnect()
1768 usb_free_urb(hub->urb); in hub_disconnect()
1769 kfree(hub->ports); in hub_disconnect()
1770 kfree(hub->descriptor); in hub_disconnect()
1771 kfree(hub->status); in hub_disconnect()
1772 kfree(hub->buffer); in hub_disconnect()
1774 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1776 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1779 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1781 kref_put(&hub->kref, hub_release); in hub_disconnect()
1788 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1789 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1792 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1793 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1797 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1809 desc = intf->cur_altsetting; in hub_probe()
1816 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1821 * - The patch might cause one or more auto supend/resume for in hub_probe()
1837 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1841 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1845 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1846 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1849 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1850 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1858 if (hdev->parent) { /* normal device */ in hub_probe()
1861 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1863 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1867 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1868 dev_err(&intf->dev, in hub_probe()
1870 return -E2BIG; in hub_probe()
1874 if (hdev->parent) { in hub_probe()
1875 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1876 return -ENODEV; in hub_probe()
1881 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1882 return -EIO; in hub_probe()
1886 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1890 return -ENOMEM; in hub_probe()
1892 kref_init(&hub->kref); in hub_probe()
1893 hub->intfdev = &intf->dev; in hub_probe()
1894 hub->hdev = hdev; in hub_probe()
1895 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1896 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1897 INIT_WORK(&hub->events, hub_event); in hub_probe()
1898 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1899 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1900 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1905 intf->needs_remote_wakeup = 1; in hub_probe()
1906 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1908 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1911 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1912 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1914 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { in hub_probe()
1915 hub->quirk_disable_autosuspend = 1; in hub_probe()
1919 if ((id->driver_info & HUB_QUIRK_REDUCE_FRAME_INTR_BINTERVAL) && in hub_probe()
1920 desc->endpoint[0].desc.bInterval > USB_REDUCE_FRAME_INTR_BINTERVAL) { in hub_probe()
1921 desc->endpoint[0].desc.bInterval = in hub_probe()
1927 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1928 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1934 return -ENODEV; in hub_probe()
1950 if (hdev->devnum <= 0) in hub_ioctl()
1951 info->nports = 0; in hub_ioctl()
1953 info->nports = hdev->maxchild; in hub_ioctl()
1954 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1955 if (hub->ports[i]->child == NULL) in hub_ioctl()
1956 info->port[i] = 0; in hub_ioctl()
1958 info->port[i] = in hub_ioctl()
1959 hub->ports[i]->child->devnum; in hub_ioctl()
1964 return info->nports + 1; in hub_ioctl()
1968 return -ENOSYS; in hub_ioctl()
1981 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
1982 return -ENODEV; in find_port_owner()
1983 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
1984 return -EINVAL; in find_port_owner()
1989 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2004 return -EBUSY; in usb_hub_claim_port()
2020 return -ENOENT; in usb_hub_release_port()
2031 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
2032 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2033 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2043 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2045 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2046 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2054 if (udev->parent) { in update_port_device_state()
2055 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2059 * has a test step to unbind the hub before running the in update_port_device_state()
2065 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2066 WRITE_ONCE(port_dev->state, udev->state); in update_port_device_state()
2067 sysfs_notify_dirent(port_dev->state_kn); in update_port_device_state()
2077 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2078 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2079 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2081 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2082 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2083 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2088 * usb_set_device_state - change a device's current state (usbcore, hcds)
2092 * udev->state is _not_ fully protected by the device lock. Although
2100 * Once a device has been added to the device tree, all changes to its state
2103 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2104 * Otherwise udev->state is set to new_state, and if new_state is
2112 int wakeup = -1; in usb_set_device_state()
2115 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2119 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2122 if (udev->parent) { in usb_set_device_state()
2123 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2127 wakeup = (udev->quirks & in usb_set_device_state()
2129 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2134 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2136 udev->active_duration -= jiffies; in usb_set_device_state()
2138 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2139 udev->active_duration += jiffies; in usb_set_device_state()
2140 udev->state = new_state; in usb_set_device_state()
2146 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2153 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2154 * USB-2.0 buses they are also used as device addresses, however on
2155 * USB-3.0 buses the address is assigned by the controller hardware
2166 struct usb_bus *bus = udev->bus; in choose_devnum()
2169 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2171 /* Try to allocate the next devnum beginning at bus->devnum_next. */ in choose_devnum()
2172 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2173 bus->devnum_next); in choose_devnum()
2175 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1); in choose_devnum()
2176 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2178 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2179 udev->devnum = devnum; in choose_devnum()
2181 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2186 if (udev->devnum > 0) { in release_devnum()
2187 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2188 udev->devnum = -1; in release_devnum()
2194 udev->devnum = devnum; in update_devnum()
2195 if (!udev->devaddr) in update_devnum()
2196 udev->devaddr = (u8)devnum; in update_devnum()
2201 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2204 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2205 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2214 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2215 if (hub->ports[i]->child) in hub_disconnect_children()
2216 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2221 * usb_disconnect - disconnect a device (usbcore-internal)
2249 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2250 udev->devnum); in usb_disconnect()
2256 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2266 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2270 if (udev->parent) { in usb_disconnect()
2271 port1 = udev->portnum; in usb_disconnect()
2272 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2273 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2275 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2276 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2279 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2282 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2283 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2285 typec_deattach(port_dev->connector, &udev->dev); in usb_disconnect()
2288 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2292 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2295 device_del(&udev->dev); in usb_disconnect()
2307 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2308 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2312 put_device(&udev->dev); in usb_disconnect()
2320 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2325 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2327 dev_info(&udev->dev, in announce_device()
2329 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2330 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2332 dev_info(&udev->dev, in announce_device()
2334 udev->descriptor.iManufacturer, in announce_device()
2335 udev->descriptor.iProduct, in announce_device()
2336 udev->descriptor.iSerialNumber); in announce_device()
2337 show_string(udev, "Product", udev->product); in announce_device()
2338 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2339 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2347 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2350 * Finish enumeration for On-The-Go devices
2360 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2364 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2365 && udev->config in usb_enumerate_device_otg()
2366 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2368 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2369 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2372 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2373 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2375 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2378 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2379 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2382 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2383 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2395 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2397 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2399 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2407 if (bus->otg_port != 0) { in usb_enumerate_device_otg()
2416 dev_err(&udev->dev, in usb_enumerate_device_otg()
2428 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2431 * This is only called by usb_new_device() -- all comments that apply there
2436 * until it has been authorized.
2443 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2445 if (udev->config == NULL) { in usb_enumerate_device()
2448 if (err != -ENODEV) in usb_enumerate_device()
2449 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2456 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2457 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2458 udev->descriptor.iManufacturer); in usb_enumerate_device()
2459 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2465 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2470 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2471 || udev->bus->is_b_host)) { in usb_enumerate_device()
2474 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2476 return -ENOTSUPP; in usb_enumerate_device()
2486 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2488 u8 port = udev->portnum; in set_usb_port_removable()
2492 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2497 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2500 * If the platform firmware has provided information about a port, in set_usb_port_removable()
2503 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2505 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2509 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2519 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2525 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2529 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2534 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2536 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2541 * usb_new_device - perform initial device setup (usbcore-internal)
2549 * udev has already been installed, but udev is not yet visible through
2554 * Only the hub driver or root-hub registrar should ever call this.
2565 if (udev->parent) { in usb_new_device()
2566 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2570 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2573 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2574 pm_runtime_set_active(&udev->dev); in usb_new_device()
2575 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2576 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2577 pm_runtime_enable(&udev->dev); in usb_new_device()
2587 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2588 udev->devnum, udev->bus->busnum, in usb_new_device()
2589 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2590 /* export the usbdev device-node for libusb */ in usb_new_device()
2591 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2592 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2597 if (udev->serial) in usb_new_device()
2598 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2599 if (udev->product) in usb_new_device()
2600 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2601 if (udev->manufacturer) in usb_new_device()
2602 add_device_randomness(udev->manufacturer, in usb_new_device()
2603 strlen(udev->manufacturer)); in usb_new_device()
2605 device_enable_async_suspend(&udev->dev); in usb_new_device()
2607 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2611 * for configuring the device and invoking the add-device in usb_new_device()
2614 err = device_add(&udev->dev); in usb_new_device()
2616 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2621 if (udev->parent) { in usb_new_device()
2622 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2623 int port1 = udev->portnum; in usb_new_device()
2624 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2626 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2627 &port_dev->dev.kobj, "port"); in usb_new_device()
2631 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2632 &udev->dev.kobj, "device"); in usb_new_device()
2634 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2638 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2639 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2641 typec_attach(port_dev->connector, &udev->dev); in usb_new_device()
2644 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2646 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2651 pm_runtime_disable(&udev->dev); in usb_new_device()
2652 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2658 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2672 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2675 usb_dev->authorized = 0; in usb_deauthorize_device()
2676 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2689 if (usb_dev->authorized == 1) in usb_authorize_device()
2694 dev_err(&usb_dev->dev, in usb_authorize_device()
2699 usb_dev->authorized = 1; in usb_authorize_device()
2707 dev_err(&usb_dev->dev, in usb_authorize_device()
2713 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2723 * get_port_ssp_rate - Match the extended port status to SSP rate
2741 if (!hdev->bos) in get_port_ssp_rate()
2744 ssp_cap = hdev->bos->ssp_cap; in get_port_ssp_rate()
2751 ssac = le32_to_cpu(ssp_cap->bmAttributes) & in get_port_ssp_rate()
2757 attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in get_port_ssp_rate()
2828 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2834 * commands in the default state. This has been seen to cause in use_new_scheme()
2838 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2859 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2862 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2885 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2900 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2901 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2911 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2917 return -EBUSY; in hub_port_wait_reset()
2920 return -ENOTCONN; in hub_port_wait_reset()
2924 return -ENOTCONN; in hub_port_wait_reset()
2928 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
2930 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2932 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2934 return -EAGAIN; in hub_port_wait_reset()
2938 return -EBUSY; in hub_port_wait_reset()
2943 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2945 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2946 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2947 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2949 udev->rx_lanes = 1; in hub_port_wait_reset()
2950 udev->tx_lanes = 1; in hub_port_wait_reset()
2951 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
2953 if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
2954 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2955 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2956 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2958 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2960 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2962 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2972 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2975 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2977 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2979 return -EINVAL; in hub_port_reset()
2996 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3000 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3003 if (status == -ENODEV) { in hub_port_reset()
3006 dev_err(&port_dev->dev, in hub_port_reset()
3012 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
3013 dev_dbg(hub->intfdev, in hub_port_reset()
3022 if (status == 0 || status == -ENOTCONN || status == -ENODEV || in hub_port_reset()
3023 (status == -EBUSY && i == PORT_RESET_TRIES - 1)) { in hub_port_reset()
3024 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3027 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3030 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3032 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3036 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3041 * state, re-issue the warm reset. in hub_port_reset()
3056 dev_dbg(&port_dev->dev, in hub_port_reset()
3062 dev_dbg(&port_dev->dev, in hub_port_reset()
3068 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
3072 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
3079 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3086 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3092 if (hcd->driver->reset_device) in hub_port_reset()
3093 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3102 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3109 * hub_port_stop_enumerate - stop USB enumeration or ignore port events
3128 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3130 if (port_dev->early_stop) { in hub_port_stop_enumerate()
3131 if (port_dev->ignore_event) in hub_port_stop_enumerate()
3143 port_dev->ignore_event = 1; in hub_port_stop_enumerate()
3145 port_dev->ignore_event = 0; in hub_port_stop_enumerate()
3147 return port_dev->ignore_event; in hub_port_stop_enumerate()
3155 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3167 __acquires(&port_dev->status_lock) in usb_lock_port()
3169 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3170 __acquire(&port_dev->status_lock); in usb_lock_port()
3174 __releases(&port_dev->status_lock) in usb_unlock_port()
3176 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3177 __release(&port_dev->status_lock); in usb_unlock_port()
3187 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3200 * is ready for a reset-resume, or should be disconnected.
3206 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3211 if (status == 0 && udev->reset_resume in check_port_resume_type()
3219 status = -ENODEV; in check_port_resume_type()
3221 if (retries--) { in check_port_resume_type()
3227 status = -ENODEV; in check_port_resume_type()
3231 * so try a reset-resume instead. in check_port_resume_type()
3233 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3234 if (udev->persist_enabled) in check_port_resume_type()
3235 udev->reset_resume = 1; in check_port_resume_type()
3237 status = -ENODEV; in check_port_resume_type()
3241 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3243 } else if (udev->reset_resume) { in check_port_resume_type()
3245 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3247 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3250 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3254 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3255 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3256 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3258 * following the reset-resume. in check_port_resume_type()
3260 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3268 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3271 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3278 if (!udev->actconfig) in usb_disable_ltm()
3290 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3293 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3300 if (!udev->actconfig) in usb_enable_ltm()
3311 * usb_enable_remote_wakeup - enable remote wakeup for a device
3314 * For USB-2 devices: Set the device's remote wakeup feature.
3316 * For USB-3 devices: Assume there's only one function on the device and
3322 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3337 * usb_disable_remote_wakeup - disable remote wakeup for a device
3340 * For USB-2 devices: Clear the device's remote wakeup feature.
3342 * For USB-3 devices: Assume there's only one function on the device and
3348 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3360 /* Count of wakeup-enabled devices at or below udev */
3365 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3366 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3371 * usb_port_suspend - suspend a usb device's upstream port
3394 * between a pair of dual-role devices. That will change roles, such
3395 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3401 * - suspend, resume ... when the VBUS power link stays live
3402 * - suspend, disconnect ... VBUS lost
3404 * Once VBUS drop breaks the circuit, the port it's using has to go through
3405 * normal re-enumeration procedures, starting with enabling VBUS power.
3406 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3407 * Linux (2.6) currently has NO mechanisms to initiate that: no hub_wq
3410 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3412 * hub is suspended). Nevertheless, we change @udev->state to
3414 * upstream port setting is stored in @udev->port_is_suspended.
3420 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3421 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3422 int port1 = udev->portnum; in usb_port_suspend()
3434 if (udev->do_remote_wakeup) { in usb_port_suspend()
3437 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3449 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3450 status = -ENOMEM; in usb_port_suspend()
3456 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3461 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3471 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3478 /* Check if the port has been suspended for the timeout case in usb_port_suspend()
3481 if (status == -ETIMEDOUT) { in usb_port_suspend()
3489 dev_dbg(&port_dev->dev, in usb_port_suspend()
3498 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3506 if (udev->do_remote_wakeup) in usb_port_suspend()
3515 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3516 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3517 udev->do_remote_wakeup); in usb_port_suspend()
3519 udev->port_is_suspended = 1; in usb_port_suspend()
3521 /* device has up to 10 msec to fully suspend */ in usb_port_suspend()
3527 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3528 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3529 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3531 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3545 * If @udev->reset_resume is set then the device is reset before the
3554 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3555 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3562 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3568 * operation is carried out here, after the port has been in finish_port_resume()
3571 if (udev->reset_resume) { in finish_port_resume()
3574 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3579 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3580 status = -ENODEV; in finish_port_resume()
3593 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3594 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3595 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3596 udev->reset_resume = 1; in finish_port_resume()
3602 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3608 * udev->reset_resume in finish_port_resume()
3610 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3611 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3623 dev_dbg(&udev->dev, in finish_port_resume()
3638 * the VBUS. In few other cases it has been seen that device fails to
3639 * negotiate link training in first attempt. It has been
3665 status = -ENODEV; in wait_for_connected()
3672 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3677 * usb_port_resume - re-activate a suspended usb device's upstream port
3678 * @udev: device to re-activate, not a root hub
3681 * This will re-activate the suspended device, increasing power usage
3687 * If @udev->reset_resume is set then this routine won't check that the
3695 * for mass-storage devices containing mounted filesystems, since the
3712 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3713 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3714 int port1 = udev->portnum; in usb_port_resume()
3718 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3719 status = pm_runtime_resume_and_get(&port_dev->dev); in usb_port_resume()
3721 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3729 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3733 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3738 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3741 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3744 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3747 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3748 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3760 udev->port_is_suspended = 0; in usb_port_resume()
3761 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3763 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3767 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3775 if (udev->persist_enabled) in usb_port_resume()
3784 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3804 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3805 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3819 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3821 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3828 hdev = hub->hdev; in hub_handle_remote_wakeup()
3829 udev = port_dev->child; in hub_handle_remote_wakeup()
3836 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3853 ret = -ENODEV; in hub_handle_remote_wakeup()
3856 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3864 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3878 struct usb_device *hdev = hub->hdev; in hub_suspend()
3883 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3885 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3886 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3887 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3888 struct usb_device *udev = port_dev->child; in hub_suspend()
3890 if (udev && udev->can_submit) { in hub_suspend()
3891 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3892 dev_name(&udev->dev)); in hub_suspend()
3894 return -EBUSY; in hub_suspend()
3897 hub->wakeup_enabled_descendants += in hub_suspend()
3901 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3905 return -EBUSY; in hub_suspend()
3906 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3910 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3912 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3922 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3932 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3938 if (hdev->parent) in report_wakeup_requests()
3941 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3942 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3952 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3953 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3955 udev = hub->ports[i]->child; in report_wakeup_requests()
3957 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3967 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
3984 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
3990 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3994 * is resumed and Vbus power has been interrupted or the controller
3995 * has been reset. The routine marks @rhdev as having lost power.
3997 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
4002 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4003 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
4016 * device-initiated U1 or U2. This lets the device know the exit latencies from
4032 if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) in usb_req_set_sel()
4036 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
4037 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
4038 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
4039 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
4046 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
4053 dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); in usb_req_set_sel()
4054 return -EINVAL; in usb_req_set_sel()
4064 return -ENOMEM; in usb_req_set_sel()
4066 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
4067 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
4068 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
4069 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
4080 udev->lpm_devinit_allow = 1; in usb_req_set_sel()
4086 * Enable or disable device-initiated U1 or U2 transitions.
4102 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4104 return -EINVAL; in usb_set_device_initiated_lpm()
4107 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4108 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4117 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
4135 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4138 return -EBUSY; in usb_set_device_initiated_lpm()
4157 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4159 return -EINVAL; in usb_set_lpm_timeout()
4164 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4167 return -EINVAL; in usb_set_lpm_timeout()
4170 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4171 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4174 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4177 return -EBUSY; in usb_set_lpm_timeout()
4180 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4182 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4197 if (!udev->lpm_devinit_allow) in usb_device_may_initiate_lpm()
4201 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4203 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4207 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4212 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4216 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) { in usb_device_may_initiate_lpm()
4217 desc = &intf->cur_altsetting->endpoint[j].desc; in usb_device_may_initiate_lpm()
4221 interval = (1 << (desc->bInterval - 1)) * 125; in usb_device_may_initiate_lpm()
4231 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4235 * control transfers to set the hub timeout or enable device-initiated U1/U2
4238 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4239 * hub-initiated U1/U2 will be disabled.
4253 if (!udev->bos) in usb_enable_link_state()
4256 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4257 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4272 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4279 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4287 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4290 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4297 if (udev->actconfig && in usb_enable_link_state()
4305 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4311 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4313 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4316 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4319 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4322 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4324 * still disallow device-initiated U1/U2 entry.
4338 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4340 return -EINVAL; in usb_disable_link_state()
4344 return -EBUSY; in usb_disable_link_state()
4348 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4349 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4356 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4360 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4362 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4368 * Disable hub-initiated and device-initiated U1 and U2 entry.
4372 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4378 if (!udev || !udev->parent || in usb_disable_lpm()
4379 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4380 !udev->lpm_capable || in usb_disable_lpm()
4381 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4384 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4385 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4388 udev->lpm_disable_count++; in usb_disable_lpm()
4389 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4402 return -EBUSY; in usb_disable_lpm()
4409 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4413 return -EINVAL; in usb_unlocked_disable_lpm()
4415 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4417 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4424 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4437 if (!udev || !udev->parent || in usb_enable_lpm()
4438 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4439 !udev->lpm_capable || in usb_enable_lpm()
4440 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4443 udev->lpm_disable_count--; in usb_enable_lpm()
4444 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4448 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4449 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4452 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4455 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4459 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4461 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4464 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4472 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4477 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4479 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4487 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4490 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4491 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4498 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4500 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4554 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4555 * a connection with a plugged-in cable but will signal the host when the cable
4556 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4560 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4561 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4564 if (!hub->error) { in hub_port_disable()
4565 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4567 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4574 if (port_dev->child && set_state) in hub_port_disable()
4575 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4576 if (ret && ret != -ENODEV) in hub_port_disable()
4577 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4582 * usb_port_disable - disable a usb device's upstream port
4590 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4592 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4595 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4598 * of 100ms at least for debounce and power-settling. The corresponding
4601 * Apparently there are some bluetooth and irda-dongles and a number of
4602 * low-speed devices for which this debounce period may last over a second.
4603 * Not covered by the spec - but easy to deal with.
4606 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4607 * every 25ms for transient disconnects. When the port status has been
4616 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4636 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4645 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4649 return -ETIMEDOUT; in hub_port_debounce()
4657 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4668 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4669 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address()
4671 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4678 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4679 return -EINVAL; in hub_set_address()
4680 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4682 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4683 return -EINVAL; in hub_set_address()
4684 if (hcd->driver->address_device) in hub_set_address()
4685 retval = hcd->driver->address_device(hcd, udev, timeout_ms); in hub_set_address()
4710 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4713 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4717 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4719 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4721 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4728 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4730 if (!hcd->driver->enable_device) in hub_enable_device()
4732 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4734 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4735 return -EINVAL; in hub_enable_device()
4737 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4767 buf->bDescriptorType = buf->bMaxPacketSize0 = 0; in get_bMaxPacketSize0()
4773 switch (buf->bMaxPacketSize0) { in get_bMaxPacketSize0()
4775 if (buf->bDescriptorType == USB_DT_DEVICE) { in get_bMaxPacketSize0()
4776 rc = buf->bMaxPacketSize0; in get_bMaxPacketSize0()
4782 rc = -EPROTO; in get_bMaxPacketSize0()
4790 * attempt, lest we get into a time-out/reset loop. in get_bMaxPacketSize0()
4792 if (rc > 0 || (rc == -ETIMEDOUT && first_time && in get_bMaxPacketSize0()
4793 udev->speed > USB_SPEED_FULL)) in get_bMaxPacketSize0()
4805 * If this is called for an already-existing device (as part of
4813 * @udev->descriptor. For an already existing device, @dev_descr
4814 * must be non-NULL. The device descriptor will be stored there,
4815 * not in @udev->descriptor, because descriptors for registered
4822 struct usb_device *hdev = hub->hdev; in hub_port_init()
4823 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4824 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4827 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4829 int devnum = udev->devnum; in hub_port_init()
4838 return -ENOMEM; in hub_port_init()
4843 if (!hdev->parent) { in hub_port_init()
4845 if (port1 == hdev->bus->otg_port) in hub_port_init()
4846 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4861 retval = -ENODEV; in hub_port_init()
4864 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4865 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4866 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4869 oldspeed = udev->speed; in hub_port_init()
4875 switch (udev->speed) { in hub_port_init()
4878 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4881 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4888 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4891 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4898 speed = usb_speed_string(udev->speed); in hub_port_init()
4905 * platform device is usually a dual-role USB controller device. in hub_port_init()
4907 if (udev->bus->controller->driver) in hub_port_init()
4908 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4910 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4912 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4913 dev_info(&udev->dev, in hub_port_init()
4920 if (hdev->tt) { in hub_port_init()
4921 udev->tt = hdev->tt; in hub_port_init()
4922 udev->ttport = hdev->ttport; in hub_port_init()
4923 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4924 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4925 if (!hub->tt.hub) { in hub_port_init()
4926 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4927 retval = -EINVAL; in hub_port_init()
4930 udev->tt = &hub->tt; in hub_port_init()
4931 udev->ttport = port1; in hub_port_init()
4937 * this area, and this is how Linux has done it for ages. in hub_port_init()
4941 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4942 * so it may help with some non-standards-compliant devices. in hub_port_init()
4951 retval = -ENODEV; in hub_port_init()
4958 dev_err(&udev->dev, in hub_port_init()
4967 maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
4968 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
4969 retval = -ENODEV; in hub_port_init()
4976 if (oldspeed != udev->speed) { in hub_port_init()
4977 dev_dbg(&udev->dev, in hub_port_init()
4979 retval = -ENODEV; in hub_port_init()
4983 if (maxp0 != -ENODEV) in hub_port_init()
4984 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4998 if (retval != -ENODEV) in hub_port_init()
4999 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
5003 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5004 devnum = udev->devnum; in hub_port_init()
5005 dev_info(&udev->dev, in hub_port_init()
5007 (udev->config) ? "reset" : "new", in hub_port_init()
5008 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
5010 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
5012 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
5014 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
5021 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
5022 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
5032 if (retval != -ENODEV) in hub_port_init()
5033 dev_err(&udev->dev, in hub_port_init()
5039 if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5040 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5041 retval = -ENODEV; in hub_port_init()
5045 delay = udev->parent->hub_delay; in hub_port_init()
5046 udev->hub_delay = min_t(u32, delay, in hub_port_init()
5050 dev_dbg(&udev->dev, in hub_port_init()
5067 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5073 if (usb_endpoint_maxp(&udev->ep0.desc) == i) { in hub_port_init()
5075 } else if ((udev->speed == USB_SPEED_FULL || in hub_port_init()
5076 udev->speed == USB_SPEED_HIGH) && in hub_port_init()
5079 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
5080 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
5082 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
5083 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
5087 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); in hub_port_init()
5088 retval = -EMSGSIZE; in hub_port_init()
5095 if (retval != -ENODEV) in hub_port_init()
5096 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
5101 udev->descriptor = *descr; in hub_port_init()
5112 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
5113 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
5114 dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); in hub_port_init()
5116 retval = -EINVAL; in hub_port_init()
5122 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5125 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5126 udev->lpm_disable_count = 1; in hub_port_init()
5134 if (hcd->driver->update_device) in hub_port_init()
5135 hcd->driver->update_device(hcd, udev); in hub_port_init()
5152 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5162 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5165 if (hub->has_indicators) { in check_highspeed()
5166 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5168 &hub->leds, 0); in check_highspeed()
5177 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5181 if (!hub->limited_power) in hub_power_remaining()
5184 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5185 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
5186 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5187 struct usb_device *udev = port_dev->child; in hub_power_remaining()
5202 if (udev->actconfig) in hub_power_remaining()
5203 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5204 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5208 if (delta > hub->mA_per_port) in hub_power_remaining()
5209 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
5210 delta, hub->mA_per_port); in hub_power_remaining()
5211 remaining -= delta; in hub_power_remaining()
5214 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5215 -remaining); in hub_power_remaining()
5234 if (memcmp(&udev->descriptor, new_device_descriptor, in descriptors_changed()
5238 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5240 if (udev->bos) { in descriptors_changed()
5241 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5242 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5244 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5254 if (udev->serial) in descriptors_changed()
5255 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5258 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5259 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5268 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5269 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5273 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5278 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5280 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5282 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5290 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5293 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5296 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5297 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5309 int status = -ENODEV; in hub_port_connect()
5312 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5313 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5314 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5315 struct usb_device *udev = port_dev->child; in hub_port_connect()
5316 static int unreliable_port = -1; in hub_port_connect()
5321 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5322 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5323 usb_disconnect(&port_dev->child); in hub_port_connect()
5331 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5337 if (status != -ENODEV && in hub_port_connect()
5340 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5352 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5360 && !port_dev->port_owner) in hub_port_connect()
5367 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5376 status = -ENODEV; in hub_port_connect()
5381 mutex_lock(hcd->address0_mutex); in hub_port_connect()
5386 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5388 dev_err(&port_dev->dev, in hub_port_connect()
5390 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5396 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5397 udev->level = hdev->level + 1; in hub_port_connect()
5400 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5401 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5403 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5406 if (udev->devnum <= 0) { in hub_port_connect()
5407 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5411 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5416 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5420 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5423 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5424 * violate the voltage drop budget. if the new child has in hub_port_connect()
5426 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5429 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5430 && udev->bus_mA <= unit_load) { in hub_port_connect()
5436 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5440 dev_err(&udev->dev, in hub_port_connect()
5441 "can't connect bus-powered hub " in hub_port_connect()
5443 if (hub->has_indicators) { in hub_port_connect()
5444 hub->indicator[port1-1] = in hub_port_connect()
5448 &hub->leds, 0); in hub_port_connect()
5450 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5456 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5457 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5469 /* We mustn't add new devices if the parent hub has in hub_port_connect()
5474 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5475 status = -ENOTCONN; in hub_port_connect()
5477 port_dev->child = udev; in hub_port_connect()
5487 port_dev->child = NULL; in hub_port_connect()
5491 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5492 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5493 udev->speed); in hub_port_connect()
5502 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5513 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5517 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5520 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5521 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5522 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5529 if (hub->hdev->parent || in hub_port_connect()
5530 !hcd->driver->port_handed_over || in hub_port_connect()
5531 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5532 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5533 dev_err(&port_dev->dev, in hub_port_connect()
5539 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5540 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5541 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5547 * a port connection-change occurs;
5548 * a port enable-change occurs (often caused by EMI);
5555 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5557 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5558 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5560 int status = -ENODEV; in hub_port_connect_change()
5562 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5565 if (hub->has_indicators) { in hub_port_connect_change()
5567 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5572 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5579 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5582 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5589 dev_dbg(&udev->dev, in hub_port_connect_change()
5594 udev->bos)) { in hub_port_connect_change()
5595 dev_dbg(&udev->dev, in hub_port_connect_change()
5596 "device descriptor has changed\n"); in hub_port_connect_change()
5603 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5604 udev->persist_enabled) { in hub_port_connect_change()
5616 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5627 /* Handle notifying userspace about hub over-current events */
5634 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5636 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5641 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5650 port_dev->over_current_count); in port_over_current_notify()
5654 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5663 __must_hold(&port_dev->status_lock) in port_event()
5666 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5667 struct usb_device *udev = port_dev->child; in port_event()
5668 struct usb_device *hdev = hub->hdev; in port_event()
5672 connect_change = test_bit(port1, hub->change_bits); in port_event()
5673 clear_bit(port1, hub->event_bits); in port_event()
5674 clear_bit(port1, hub->wakeup_bits); in port_event()
5686 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5697 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5704 port_dev->over_current_count++; in port_event()
5707 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5708 port_dev->over_current_count); in port_event()
5715 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5719 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5724 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5729 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5734 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5740 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5744 if (port_dev->ignore_event && port_dev->early_stop) in port_event()
5762 dev_dbg(&port_dev->dev, "Wait for inactive link disconnect detect\n"); in port_event()
5765 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5766 dev_dbg(&port_dev->dev, "do warm reset, port only\n"); in port_event()
5771 dev_dbg(&port_dev->dev, "do warm reset, full device\n"); in port_event()
5797 hdev = hub->hdev; in hub_event()
5798 hub_dev = hub->intfdev; in hub_event()
5801 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5804 hdev->state, hdev->maxchild, in hub_event()
5806 (u16) hub->change_bits[0], in hub_event()
5807 (u16) hub->event_bits[0]); in hub_event()
5812 if (unlikely(hub->disconnected)) in hub_event()
5815 /* If the hub has died, clean up after it */ in hub_event()
5816 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5817 hub->error = -ENODEV; in hub_event()
5830 if (hub->quiescing) in hub_event()
5833 if (hub->error) { in hub_event()
5834 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5842 hub->nerrors = 0; in hub_event()
5843 hub->error = 0; in hub_event()
5847 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5848 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5850 if (test_bit(i, hub->event_bits) in hub_event()
5851 || test_bit(i, hub->change_bits) in hub_event()
5852 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5859 * (powered-off), we leave it in that state, run in hub_event()
5862 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5863 pm_runtime_barrier(&port_dev->dev); in hub_event()
5867 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5872 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5882 hub->limited_power = 1; in hub_event()
5884 hub->limited_power = 0; in hub_event()
5890 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5896 dev_err(hub_dev, "over-current condition\n"); in hub_event()
5908 kref_put(&hub->kref, hub_release); in hub_event()
5984 return -1; in usb_hub_init()
5989 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
5991 * over to the companion full-speed controller. in usb_hub_init()
6001 return -1; in usb_hub_init()
6013 * individual hub resources. -greg in usb_hub_cleanup()
6019 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
6022 * WARNING - don't use this routine to reset a composite device
6030 * telling hub_wq to pretend the device has been disconnected and then
6031 * re-connected. All drivers will be unbound, and the device will be
6032 * re-enumerated and probed all over again.
6034 * Return: 0 if the reset succeeded, -ENODEV if the device has been
6054 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
6056 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
6060 int port1 = udev->portnum; in usb_reset_and_verify_device()
6062 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
6063 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
6064 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
6065 udev->state); in usb_reset_and_verify_device()
6066 return -EINVAL; in usb_reset_and_verify_device()
6070 return -EISDIR; in usb_reset_and_verify_device()
6075 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
6079 bos = udev->bos; in usb_reset_and_verify_device()
6080 udev->bos = NULL; in usb_reset_and_verify_device()
6082 mutex_lock(hcd->address0_mutex); in usb_reset_and_verify_device()
6086 ret = -ENODEV; in usb_reset_and_verify_device()
6091 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
6094 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
6097 mutex_unlock(hcd->address0_mutex); in usb_reset_and_verify_device()
6104 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
6109 if (!udev->actconfig) in usb_reset_and_verify_device()
6112 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6113 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
6115 dev_warn(&udev->dev, in usb_reset_and_verify_device()
6118 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6123 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
6126 dev_err(&udev->dev, in usb_reset_and_verify_device()
6128 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
6129 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6132 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6136 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
6138 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
6141 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6142 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
6143 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
6146 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
6147 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
6153 * device has been reset, and it will have to use in usb_reset_and_verify_device()
6156 intf->resetting_device = 1; in usb_reset_and_verify_device()
6157 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
6158 desc->bAlternateSetting); in usb_reset_and_verify_device()
6159 intf->resetting_device = 0; in usb_reset_and_verify_device()
6162 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
6164 desc->bInterfaceNumber, in usb_reset_and_verify_device()
6165 desc->bAlternateSetting, in usb_reset_and_verify_device()
6170 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
6171 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
6175 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
6180 udev->bos = bos; in usb_reset_and_verify_device()
6185 udev->bos = bos; in usb_reset_and_verify_device()
6187 return -ENODEV; in usb_reset_and_verify_device()
6191 * usb_reset_device - warn interface drivers and perform a USB port reset
6201 * being unbound or re-bound during the ongoing reset its disconnect()
6203 * routine returns -EINPROGRESS.
6222 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6223 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6225 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6226 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6227 udev->state); in usb_reset_device()
6228 return -EINVAL; in usb_reset_device()
6231 if (!udev->parent) { in usb_reset_device()
6232 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
6233 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6234 return -EISDIR; in usb_reset_device()
6237 if (udev->reset_in_progress) in usb_reset_device()
6238 return -EINPROGRESS; in usb_reset_device()
6239 udev->reset_in_progress = 1; in usb_reset_device()
6241 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6258 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
6259 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6263 if (cintf->dev.driver) { in usb_reset_device()
6264 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6265 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
6266 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
6267 else if (cintf->condition == in usb_reset_device()
6281 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
6282 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6284 int rebind = cintf->needs_binding; in usb_reset_device()
6286 if (!rebind && cintf->dev.driver) { in usb_reset_device()
6287 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6288 if (drv->post_reset) in usb_reset_device()
6289 rebind = (drv->post_reset)(cintf); in usb_reset_device()
6290 else if (cintf->condition == in usb_reset_device()
6294 cintf->needs_binding = 1; in usb_reset_device()
6305 udev->reset_in_progress = 0; in usb_reset_device()
6312 * usb_queue_reset_device - Reset a USB device from an atomic context
6325 * - Scheduling two resets at the same time from two different drivers
6328 * handles ->pre_reset(), the second reset might happen or not.
6330 * - If the reset is delayed so long that the interface is unbound from
6333 * - This function can be called during .probe(). It can also be called
6336 * .disconnect(), call usb_reset_device() directly -- but watch out
6341 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6347 * usb_hub_find_child - Get the pointer of child device
6357 * child's usb_device pointer if non-NULL.
6364 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6366 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6381 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6382 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6384 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6388 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6389 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6390 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6395 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6397 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6398 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6400 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6405 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6411 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6417 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6432 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()