Lines Matching +full:ganged +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
57 /* Protect struct usb_device->state and ->children members
58 * Note: Both are also protected by ->dev.sem, except that ->state can
66 /* synchronize hub-port add/remove and peering operations */
76 * 10 seconds to send reply for the initial 64-byte descriptor request.
78 /* define initial 64-byte descriptor request timeout in milliseconds */
82 "initial 64-byte descriptor request timeout in milliseconds "
83 "(default 5000 - 5.0 seconds)");
128 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
130 if (hub_is_superspeed(hub->hdev)) in portspeed()
143 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
145 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
151 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
155 if (!udev->bos) in usb_device_supports_lpm()
161 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
162 if (udev->bos->ext_cap && in usb_device_supports_lpm()
164 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
174 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
175 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
179 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
180 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
181 if (udev->parent) in usb_device_supports_lpm()
182 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
184 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
188 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
214 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
216 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
224 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
235 if (!hub->hdev->parent) in usb_set_lpm_mel()
238 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
272 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
275 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
279 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
281 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
285 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
290 * - t1: device PEL
291 * - t2: time for the ERDY to make it from the device to the host.
292 * - t3: a host-specific delay to process the ERDY.
293 * - t4: time for the packet to make it from the host to the device.
307 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
309 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
310 parent = parent->parent) in usb_set_lpm_sel()
312 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
314 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
319 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
331 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
335 if (!udev->bos) in usb_set_lpm_parameters()
338 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
345 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
346 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
347 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
348 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
350 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
351 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
353 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
354 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
366 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
375 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
376 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
380 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
384 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
385 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
389 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
390 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
418 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
420 return -EMSGSIZE; in get_hub_descriptor()
424 return -EINVAL; in get_hub_descriptor()
473 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
478 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
481 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
483 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
493 struct usb_device *hdev = hub->hdev; in led_work()
496 int cursor = -1; in led_work()
498 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
501 for (i = 0; i < hdev->maxchild; i++) { in led_work()
502 unsigned selector, mode; in led_work() local
504 /* 30%-50% duty cycle */ in led_work()
506 switch (hub->indicator[i]) { in led_work()
511 mode = INDICATOR_AUTO; in led_work()
516 mode = INDICATOR_GREEN_BLINK_OFF; in led_work()
520 mode = INDICATOR_GREEN_BLINK; in led_work()
525 mode = INDICATOR_AMBER_BLINK_OFF; in led_work()
529 mode = INDICATOR_AMBER_BLINK; in led_work()
534 mode = INDICATOR_ALT_BLINK_OFF; in led_work()
538 mode = INDICATOR_ALT_BLINK; in led_work()
546 hub->indicator[i] = mode; in led_work()
550 cursor %= hdev->maxchild; in led_work()
552 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
557 &hub->leds, LED_CYCLE_PERIOD); in led_work()
570 int i, status = -ETIMEDOUT; in get_hub_status()
573 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
588 int i, status = -ETIMEDOUT; in get_port_status()
591 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
608 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
609 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
611 if (ret != -ENODEV) in hub_ext_port_status()
612 dev_err(hub->intfdev, in hub_ext_port_status()
615 ret = -EIO; in hub_ext_port_status()
617 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
618 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
621 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
624 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
628 * protects hub->status, and the phy driver only checks the port in hub_ext_port_status()
632 struct usb_device *hdev = hub->hdev; in hub_ext_port_status()
640 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_ext_port_status()
642 if (hcd->usb_phy) in hub_ext_port_status()
643 usb_phy_notify_port_status(hcd->usb_phy, in hub_ext_port_status()
644 port1 - 1, *status, *change); in hub_ext_port_status()
663 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
665 if (hub->quiescing) { in hub_resubmit_irq_urb()
666 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
670 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
671 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
672 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
673 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
674 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
677 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
692 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
703 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
705 kref_get(&hub->kref); in kick_hub_wq()
707 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
712 kref_put(&hub->kref, hub_release); in kick_hub_wq()
742 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
743 if (port_dev && port_dev->child) in usb_wakeup_notification()
744 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
746 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
755 struct usb_hub *hub = urb->context; in hub_irq()
756 int status = urb->status; in hub_irq()
761 case -ENOENT: /* synchronous unlink */ in hub_irq()
762 case -ECONNRESET: /* async unlink */ in hub_irq()
763 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
768 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
769 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
771 hub->error = status; in hub_irq()
777 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
778 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
780 hub->event_bits[0] = bits; in hub_irq()
784 hub->nerrors = 0; in hub_irq()
823 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
824 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
827 struct usb_device *hdev = hub->hdev; in hub_tt_work()
831 next = hub->tt.clear_list.next; in hub_tt_work()
833 list_del(&clear->clear_list); in hub_tt_work()
836 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
837 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
838 if (status && status != -ENODEV) in hub_tt_work()
839 dev_err(&hdev->dev, in hub_tt_work()
841 clear->tt, clear->devinfo, status); in hub_tt_work()
844 drv = clear->hcd->driver; in hub_tt_work()
845 if (drv->clear_tt_buffer_complete) in hub_tt_work()
846 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
849 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
851 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
855 * usb_hub_set_port_power - control hub port's power state
880 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
882 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
887 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
902 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
903 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
904 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
914 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
916 return -ENOMEM; in usb_hub_clear_tt_buffer()
920 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
921 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
922 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
923 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
927 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
930 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
931 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
934 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
935 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
936 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
937 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
948 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
953 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
955 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
956 "non-switchable hub\n"); in hub_power_on()
957 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
958 if (test_bit(port1, hub->power_bits)) in hub_power_on()
959 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
961 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
972 mutex_lock(&hub->status_mutex); in hub_hub_status()
973 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
975 if (ret != -ENODEV) in hub_hub_status()
976 dev_err(hub->intfdev, in hub_hub_status()
979 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
980 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
983 mutex_unlock(&hub->status_mutex); in hub_hub_status()
990 return set_port_feature(hub->hdev, in hub_set_port_link_state()
996 * Disable a port and mark a logical connect-change event, so that some
998 * and will re-enumerate if there actually is a device attached.
1002 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
1006 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
1007 * - SRP saves power that way in hub_port_logical_disconnect()
1008 * - ... new call, TBD ... in hub_port_logical_disconnect()
1009 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1014 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1019 * usb_remove_device - disable a device's port on its parent hub
1036 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1037 return -EINVAL; in usb_remove_device()
1038 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1039 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1045 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1046 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1061 struct usb_device *hdev = hub->hdev; in hub_activate()
1071 device_lock(&hdev->dev); in hub_activate()
1074 if (hub->disconnected) in hub_activate()
1080 kref_get(&hub->kref); in hub_activate()
1093 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1096 hdev->level - 1, 0, NULL, 0, in hub_activate()
1099 dev_err(hub->intfdev, in hub_activate()
1104 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1105 * and the implementation looks like a home-brewed sort of in hub_activate()
1119 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1121 &hub->init_work, in hub_activate()
1126 to_usb_interface(hub->intfdev)); in hub_activate()
1133 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1134 if (hcd->driver->update_hub_device) { in hub_activate()
1135 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1136 &hub->tt, GFP_NOIO); in hub_activate()
1138 dev_err(hub->intfdev, in hub_activate()
1140 dev_err(hub->intfdev, in hub_activate()
1149 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1155 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1158 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1159 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1160 struct usb_device *udev = port_dev->child; in hub_activate()
1169 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1182 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1195 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1198 set_bit(port1, hub->event_bits); in hub_activate()
1210 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1213 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1218 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1223 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1227 hub_is_superspeed(hub->hdev)) { in hub_activate()
1229 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1237 clear_bit(port1, hub->removed_bits); in hub_activate()
1239 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1250 set_bit(port1, hub->change_bits); in hub_activate()
1262 * bit on device-initiated resume. in hub_activate()
1264 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1266 set_bit(port1, hub->event_bits); in hub_activate()
1268 } else if (udev->persist_enabled) { in hub_activate()
1270 udev->reset_resume = 1; in hub_activate()
1275 if (test_bit(port1, hub->power_bits)) in hub_activate()
1276 set_bit(port1, hub->change_bits); in hub_activate()
1281 set_bit(port1, hub->change_bits); in hub_activate()
1285 /* If no port-status-change flags were set, we don't need any in hub_activate()
1290 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1298 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1300 &hub->init_work, in hub_activate()
1302 device_unlock(&hdev->dev); in hub_activate()
1309 hub->quiescing = 0; in hub_activate()
1311 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1313 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1314 if (hub->has_indicators && blinkenlights) in hub_activate()
1316 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1324 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1325 device_unlock(&hdev->dev); in hub_activate()
1328 kref_put(&hub->kref, hub_release); in hub_activate()
1352 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1356 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1357 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1358 hub->quiescing = 1; in hub_quiesce()
1359 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1363 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1364 if (hub->ports[i]->child) in hub_quiesce()
1365 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1370 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1371 usb_kill_urb(hub->urb); in hub_quiesce()
1372 if (hub->has_indicators) in hub_quiesce()
1373 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1374 if (hub->tt.hub) in hub_quiesce()
1375 flush_work(&hub->tt.clear_work); in hub_quiesce()
1382 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1383 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1392 hub->in_reset = 1; in hub_pre_reset()
1402 hub->in_reset = 0; in hub_post_reset()
1412 struct usb_device *hdev = hub->hdev; in hub_configure()
1413 struct device *hub_dev = hub->intfdev; in hub_configure()
1423 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1424 if (!hub->buffer) { in hub_configure()
1425 ret = -ENOMEM; in hub_configure()
1429 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1430 if (!hub->status) { in hub_configure()
1431 ret = -ENOMEM; in hub_configure()
1434 mutex_init(&hub->status_mutex); in hub_configure()
1436 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1437 if (!hub->descriptor) { in hub_configure()
1438 ret = -ENOMEM; in hub_configure()
1443 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1444 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1446 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1456 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1458 ret = -ENODEV; in hub_configure()
1460 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1462 ret = -ENODEV; in hub_configure()
1471 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1473 if (hdev->parent) in hub_configure()
1474 delay += hdev->parent->hub_delay; in hub_configure()
1477 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1480 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1484 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1485 if (!hub->ports) { in hub_configure()
1486 ret = -ENOMEM; in hub_configure()
1490 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1505 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1515 dev_dbg(hub_dev, "ganged power switching\n"); in hub_configure()
1528 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1531 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1535 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1539 spin_lock_init(&hub->tt.lock); in hub_configure()
1540 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1541 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1542 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1547 hub->tt.hub = hdev; in hub_configure()
1553 hub->tt.multi = 1; in hub_configure()
1557 hub->tt.hub = hdev; in hub_configure()
1564 hdev->descriptor.bDeviceProtocol); in hub_configure()
1571 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1572 hub->tt.think_time = 666; in hub_configure()
1575 8, hub->tt.think_time); in hub_configure()
1579 hub->tt.think_time = 666 * 2; in hub_configure()
1582 16, hub->tt.think_time); in hub_configure()
1585 hub->tt.think_time = 666 * 3; in hub_configure()
1588 24, hub->tt.think_time); in hub_configure()
1591 hub->tt.think_time = 666 * 4; in hub_configure()
1594 32, hub->tt.think_time); in hub_configure()
1598 /* probe() zeroes hub->indicator[] */ in hub_configure()
1600 hub->has_indicators = 1; in hub_configure()
1605 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1607 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1608 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1615 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1616 if (hdev == hdev->bus->root_hub) { in hub_configure()
1617 if (hcd->power_budget > 0) in hub_configure()
1618 hdev->bus_mA = hcd->power_budget; in hub_configure()
1620 hdev->bus_mA = full_load * maxchild; in hub_configure()
1621 if (hdev->bus_mA >= full_load) in hub_configure()
1622 hub->mA_per_port = full_load; in hub_configure()
1624 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1625 hub->limited_power = 1; in hub_configure()
1628 int remaining = hdev->bus_mA - in hub_configure()
1629 hub->descriptor->bHubContrCurrent; in hub_configure()
1632 hub->descriptor->bHubContrCurrent); in hub_configure()
1633 hub->limited_power = 1; in hub_configure()
1639 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1641 } else { /* Self-powered external hub */ in hub_configure()
1642 /* FIXME: What about battery-powered external hubs that in hub_configure()
1644 hub->mA_per_port = full_load; in hub_configure()
1646 if (hub->mA_per_port < full_load) in hub_configure()
1648 hub->mA_per_port); in hub_configure()
1657 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1663 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1672 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1675 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1676 maxp = sizeof(*hub->buffer); in hub_configure()
1678 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1679 if (!hub->urb) { in hub_configure()
1680 ret = -ENOMEM; in hub_configure()
1684 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1685 hub, endpoint->bInterval); in hub_configure()
1688 if (hub->has_indicators && blinkenlights) in hub_configure()
1689 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1695 dev_err(hub->intfdev, in hub_configure()
1700 hdev->maxchild = i; in hub_configure()
1701 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1702 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1704 pm_runtime_put(&port_dev->dev); in hub_configure()
1714 if (hcd->driver->update_hub_device) { in hub_configure()
1715 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1716 &hub->tt, GFP_KERNEL); in hub_configure()
1723 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1739 usb_put_dev(hub->hdev); in hub_release()
1740 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1756 hub->disconnected = 1; in hub_disconnect()
1759 hub->error = 0; in hub_disconnect()
1766 port1 = hdev->maxchild; in hub_disconnect()
1767 hdev->maxchild = 0; in hub_disconnect()
1771 for (; port1 > 0; --port1) in hub_disconnect()
1776 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1777 highspeed_hubs--; in hub_disconnect()
1779 usb_free_urb(hub->urb); in hub_disconnect()
1780 kfree(hub->ports); in hub_disconnect()
1781 kfree(hub->descriptor); in hub_disconnect()
1782 kfree(hub->status); in hub_disconnect()
1783 kfree(hub->buffer); in hub_disconnect()
1785 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1787 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1790 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1792 kref_put(&hub->kref, hub_release); in hub_disconnect()
1799 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1800 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1803 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1804 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1808 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1820 desc = intf->cur_altsetting; in hub_probe()
1827 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1832 * - The patch might cause one or more auto supend/resume for in hub_probe()
1848 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1852 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1856 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1857 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1860 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1861 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1869 if (hdev->parent) { /* normal device */ in hub_probe()
1872 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1874 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1878 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1879 dev_err(&intf->dev, in hub_probe()
1881 return -E2BIG; in hub_probe()
1885 if (hdev->parent) { in hub_probe()
1886 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1887 return -ENODEV; in hub_probe()
1892 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1893 return -EIO; in hub_probe()
1897 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1901 return -ENOMEM; in hub_probe()
1903 kref_init(&hub->kref); in hub_probe()
1904 hub->intfdev = &intf->dev; in hub_probe()
1905 hub->hdev = hdev; in hub_probe()
1906 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1907 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1908 INIT_WORK(&hub->events, hub_event); in hub_probe()
1909 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1910 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1911 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1916 intf->needs_remote_wakeup = 1; in hub_probe()
1917 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1919 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1922 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1923 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1925 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { in hub_probe()
1926 hub->quirk_disable_autosuspend = 1; in hub_probe()
1930 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1931 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1937 return -ENODEV; in hub_probe()
1953 if (hdev->devnum <= 0) in hub_ioctl()
1954 info->nports = 0; in hub_ioctl()
1956 info->nports = hdev->maxchild; in hub_ioctl()
1957 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1958 if (hub->ports[i]->child == NULL) in hub_ioctl()
1959 info->port[i] = 0; in hub_ioctl()
1961 info->port[i] = in hub_ioctl()
1962 hub->ports[i]->child->devnum; in hub_ioctl()
1967 return info->nports + 1; in hub_ioctl()
1971 return -ENOSYS; in hub_ioctl()
1984 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
1985 return -ENODEV; in find_port_owner()
1986 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
1987 return -EINVAL; in find_port_owner()
1992 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2007 return -EBUSY; in usb_hub_claim_port()
2023 return -ENOENT; in usb_hub_release_port()
2034 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
2035 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2036 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2046 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2048 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2049 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2057 if (udev->parent) { in update_port_device_state()
2058 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2059 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2060 WRITE_ONCE(port_dev->state, udev->state); in update_port_device_state()
2061 sysfs_notify_dirent(port_dev->state_kn); in update_port_device_state()
2070 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2071 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2072 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2074 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2075 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2076 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2081 * usb_set_device_state - change a device's current state (usbcore, hcds)
2085 * udev->state is _not_ fully protected by the device lock. Although
2096 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2097 * Otherwise udev->state is set to new_state, and if new_state is
2105 int wakeup = -1; in usb_set_device_state()
2108 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2112 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2115 if (udev->parent) { in usb_set_device_state()
2116 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2120 wakeup = (udev->quirks & in usb_set_device_state()
2122 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2127 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2129 udev->active_duration -= jiffies; in usb_set_device_state()
2131 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2132 udev->active_duration += jiffies; in usb_set_device_state()
2133 udev->state = new_state; in usb_set_device_state()
2139 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2146 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2147 * USB-2.0 buses they are also used as device addresses, however on
2148 * USB-3.0 buses the address is assigned by the controller hardware
2159 struct usb_bus *bus = udev->bus; in choose_devnum()
2162 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2164 /* Try to allocate the next devnum beginning at bus->devnum_next. */ in choose_devnum()
2165 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2166 bus->devnum_next); in choose_devnum()
2168 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1); in choose_devnum()
2169 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2171 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2172 udev->devnum = devnum; in choose_devnum()
2174 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2179 if (udev->devnum > 0) { in release_devnum()
2180 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2181 udev->devnum = -1; in release_devnum()
2187 udev->devnum = devnum; in update_devnum()
2188 if (!udev->devaddr) in update_devnum()
2189 udev->devaddr = (u8)devnum; in update_devnum()
2194 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2197 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2198 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2207 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2208 if (hub->ports[i]->child) in hub_disconnect_children()
2209 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2214 * usb_disconnect - disconnect a device (usbcore-internal)
2242 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2243 udev->devnum); in usb_disconnect()
2249 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2259 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2263 if (udev->parent) { in usb_disconnect()
2264 port1 = udev->portnum; in usb_disconnect()
2265 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2266 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2268 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2269 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2272 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2275 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2276 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2279 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2283 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2286 device_del(&udev->dev); in usb_disconnect()
2298 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2299 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2303 put_device(&udev->dev); in usb_disconnect()
2311 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2316 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2318 dev_info(&udev->dev, in announce_device()
2320 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2321 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2323 dev_info(&udev->dev, in announce_device()
2325 udev->descriptor.iManufacturer, in announce_device()
2326 udev->descriptor.iProduct, in announce_device()
2327 udev->descriptor.iSerialNumber); in announce_device()
2328 show_string(udev, "Product", udev->product); in announce_device()
2329 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2330 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2338 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2341 * Finish enumeration for On-The-Go devices
2351 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2355 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2356 && udev->config in usb_enumerate_device_otg()
2357 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2359 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2360 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2363 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2364 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2366 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2369 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2370 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2373 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2374 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2386 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2388 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2390 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2400 dev_err(&udev->dev, in usb_enumerate_device_otg()
2411 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2414 * This is only called by usb_new_device() -- all comments that apply there
2426 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2428 if (udev->config == NULL) { in usb_enumerate_device()
2431 if (err != -ENODEV) in usb_enumerate_device()
2432 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2439 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2440 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2441 udev->descriptor.iManufacturer); in usb_enumerate_device()
2442 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2448 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2453 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2454 || udev->bus->is_b_host)) { in usb_enumerate_device()
2457 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2459 return -ENOTSUPP; in usb_enumerate_device()
2469 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2471 u8 port = udev->portnum; in set_usb_port_removable()
2475 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2480 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2486 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2488 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2492 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2502 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2508 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2512 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2517 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2519 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2524 * usb_new_device - perform initial device setup (usbcore-internal)
2537 * Only the hub driver or root-hub registrar should ever call this.
2548 if (udev->parent) { in usb_new_device()
2549 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2553 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2556 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2557 pm_runtime_set_active(&udev->dev); in usb_new_device()
2558 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2559 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2560 pm_runtime_enable(&udev->dev); in usb_new_device()
2570 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2571 udev->devnum, udev->bus->busnum, in usb_new_device()
2572 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2573 /* export the usbdev device-node for libusb */ in usb_new_device()
2574 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2575 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2580 if (udev->serial) in usb_new_device()
2581 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2582 if (udev->product) in usb_new_device()
2583 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2584 if (udev->manufacturer) in usb_new_device()
2585 add_device_randomness(udev->manufacturer, in usb_new_device()
2586 strlen(udev->manufacturer)); in usb_new_device()
2588 device_enable_async_suspend(&udev->dev); in usb_new_device()
2590 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2594 * for configuring the device and invoking the add-device in usb_new_device()
2597 err = device_add(&udev->dev); in usb_new_device()
2599 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2604 if (udev->parent) { in usb_new_device()
2605 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2606 int port1 = udev->portnum; in usb_new_device()
2607 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2609 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2610 &port_dev->dev.kobj, "port"); in usb_new_device()
2614 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2615 &udev->dev.kobj, "device"); in usb_new_device()
2617 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2621 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2622 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2625 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2627 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2632 pm_runtime_disable(&udev->dev); in usb_new_device()
2633 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2639 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2653 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2656 usb_dev->authorized = 0; in usb_deauthorize_device()
2657 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2670 if (usb_dev->authorized == 1) in usb_authorize_device()
2675 dev_err(&usb_dev->dev, in usb_authorize_device()
2680 usb_dev->authorized = 1; in usb_authorize_device()
2688 dev_err(&usb_dev->dev, in usb_authorize_device()
2694 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2704 * get_port_ssp_rate - Match the extended port status to SSP rate
2722 if (!hdev->bos) in get_port_ssp_rate()
2725 ssp_cap = hdev->bos->ssp_cap; in get_port_ssp_rate()
2732 ssac = le32_to_cpu(ssp_cap->bmAttributes) & in get_port_ssp_rate()
2738 attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in get_port_ssp_rate()
2809 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2819 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2832 /* Is a USB 3.0 port in the Inactive or Compliance Mode state?
2840 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2843 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2866 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2881 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2882 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2892 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2898 return -EBUSY; in hub_port_wait_reset()
2901 return -ENOTCONN; in hub_port_wait_reset()
2905 return -ENOTCONN; in hub_port_wait_reset()
2909 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
2911 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2913 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2915 return -EAGAIN; in hub_port_wait_reset()
2919 return -EBUSY; in hub_port_wait_reset()
2924 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2926 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2927 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2928 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2930 udev->rx_lanes = 1; in hub_port_wait_reset()
2931 udev->tx_lanes = 1; in hub_port_wait_reset()
2932 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
2934 if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
2935 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2936 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2937 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2939 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2941 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2943 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2953 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2956 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2958 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2960 return -EINVAL; in hub_port_reset()
2977 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2981 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2984 if (status == -ENODEV) { in hub_port_reset()
2987 dev_err(&port_dev->dev, in hub_port_reset()
2993 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
2994 dev_dbg(hub->intfdev, in hub_port_reset()
3003 if (status == 0 || status == -ENOTCONN || status == -ENODEV || in hub_port_reset()
3004 (status == -EBUSY && i == PORT_RESET_TRIES - 1)) { in hub_port_reset()
3005 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3008 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3011 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3013 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3017 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3022 * state, re-issue the warm reset. in hub_port_reset()
3033 * If the port is in SS.Inactive or Compliance Mode, the in hub_port_reset()
3037 dev_dbg(&port_dev->dev, in hub_port_reset()
3043 dev_dbg(&port_dev->dev, in hub_port_reset()
3049 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
3053 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
3060 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3067 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3073 if (hcd->driver->reset_device) in hub_port_reset()
3074 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3083 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3090 * hub_port_stop_enumerate - stop USB enumeration or ignore port events
3109 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3111 if (port_dev->early_stop) { in hub_port_stop_enumerate()
3112 if (port_dev->ignore_event) in hub_port_stop_enumerate()
3124 port_dev->ignore_event = 1; in hub_port_stop_enumerate()
3126 port_dev->ignore_event = 0; in hub_port_stop_enumerate()
3128 return port_dev->ignore_event; in hub_port_stop_enumerate()
3136 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3148 __acquires(&port_dev->status_lock) in usb_lock_port()
3150 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3151 __acquire(&port_dev->status_lock); in usb_lock_port()
3155 __releases(&port_dev->status_lock) in usb_unlock_port()
3157 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3158 __release(&port_dev->status_lock); in usb_unlock_port()
3168 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3181 * is ready for a reset-resume, or should be disconnected.
3187 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3192 if (status == 0 && udev->reset_resume in check_port_resume_type()
3200 status = -ENODEV; in check_port_resume_type()
3202 if (retries--) { in check_port_resume_type()
3208 status = -ENODEV; in check_port_resume_type()
3212 * so try a reset-resume instead. in check_port_resume_type()
3214 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3215 if (udev->persist_enabled) in check_port_resume_type()
3216 udev->reset_resume = 1; in check_port_resume_type()
3218 status = -ENODEV; in check_port_resume_type()
3222 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3224 } else if (udev->reset_resume) { in check_port_resume_type()
3226 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3228 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3231 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3235 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3236 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3237 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3239 * following the reset-resume. in check_port_resume_type()
3241 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3249 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3252 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3259 if (!udev->actconfig) in usb_disable_ltm()
3271 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3274 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3281 if (!udev->actconfig) in usb_enable_ltm()
3292 * usb_enable_remote_wakeup - enable remote wakeup for a device
3295 * For USB-2 devices: Set the device's remote wakeup feature.
3297 * For USB-3 devices: Assume there's only one function on the device and
3303 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3318 * usb_disable_remote_wakeup - disable remote wakeup for a device
3321 * For USB-2 devices: Clear the device's remote wakeup feature.
3323 * For USB-3 devices: Assume there's only one function on the device and
3329 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3341 /* Count of wakeup-enabled devices at or below udev */
3346 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3347 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3352 * usb_port_suspend - suspend a usb device's upstream port
3375 * between a pair of dual-role devices. That will change roles, such
3376 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3382 * - suspend, resume ... when the VBUS power link stays live
3383 * - suspend, disconnect ... VBUS lost
3386 * normal re-enumeration procedures, starting with enabling VBUS power.
3387 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3391 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3393 * hub is suspended). Nevertheless, we change @udev->state to
3395 * upstream port setting is stored in @udev->port_is_suspended.
3401 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3402 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3403 int port1 = udev->portnum; in usb_port_suspend()
3415 if (udev->do_remote_wakeup) { in usb_port_suspend()
3418 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3430 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3431 status = -ENOMEM; in usb_port_suspend()
3437 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3442 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3452 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3462 if (status == -ETIMEDOUT) { in usb_port_suspend()
3470 dev_dbg(&port_dev->dev, in usb_port_suspend()
3479 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3487 if (udev->do_remote_wakeup) in usb_port_suspend()
3496 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3497 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3498 udev->do_remote_wakeup); in usb_port_suspend()
3500 udev->port_is_suspended = 1; in usb_port_suspend()
3508 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3509 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3510 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3512 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3526 * If @udev->reset_resume is set then the device is reset before the
3535 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3536 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3543 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3552 if (udev->reset_resume) { in finish_port_resume()
3555 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3560 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3561 status = -ENODEV; in finish_port_resume()
3574 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3575 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3576 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3577 udev->reset_resume = 1; in finish_port_resume()
3583 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3589 * udev->reset_resume in finish_port_resume()
3591 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3592 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3604 dev_dbg(&udev->dev, in finish_port_resume()
3646 status = -ENODEV; in wait_for_connected()
3653 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3658 * usb_port_resume - re-activate a suspended usb device's upstream port
3659 * @udev: device to re-activate, not a root hub
3662 * This will re-activate the suspended device, increasing power usage
3668 * If @udev->reset_resume is set then this routine won't check that the
3676 * for mass-storage devices containing mounted filesystems, since the
3693 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3694 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3695 int port1 = udev->portnum; in usb_port_resume()
3699 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3700 status = pm_runtime_resume_and_get(&port_dev->dev); in usb_port_resume()
3702 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3710 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3714 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3719 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3722 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3725 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3728 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3729 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3741 udev->port_is_suspended = 0; in usb_port_resume()
3742 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3744 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3748 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3756 if (udev->persist_enabled) in usb_port_resume()
3765 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3785 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3786 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3800 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3802 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3809 hdev = hub->hdev; in hub_handle_remote_wakeup()
3810 udev = port_dev->child; in hub_handle_remote_wakeup()
3817 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3834 ret = -ENODEV; in hub_handle_remote_wakeup()
3837 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3845 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3859 struct usb_device *hdev = hub->hdev; in hub_suspend()
3864 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3866 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3867 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3868 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3869 struct usb_device *udev = port_dev->child; in hub_suspend()
3871 if (udev && udev->can_submit) { in hub_suspend()
3872 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3873 dev_name(&udev->dev)); in hub_suspend()
3875 return -EBUSY; in hub_suspend()
3878 hub->wakeup_enabled_descendants += in hub_suspend()
3882 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3886 return -EBUSY; in hub_suspend()
3887 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3891 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3893 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3903 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3913 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3919 if (hdev->parent) in report_wakeup_requests()
3922 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3923 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3933 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3934 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3936 udev = hub->ports[i]->child; in report_wakeup_requests()
3938 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3948 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
3965 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
3971 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3978 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
3983 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
3984 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
3997 * device-initiated U1 or U2. This lets the device know the exit latencies from
4013 if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) in usb_req_set_sel()
4017 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
4018 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
4019 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
4020 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
4027 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
4034 dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); in usb_req_set_sel()
4035 return -EINVAL; in usb_req_set_sel()
4045 return -ENOMEM; in usb_req_set_sel()
4047 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
4048 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
4049 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
4050 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
4061 udev->lpm_devinit_allow = 1; in usb_req_set_sel()
4067 * Enable or disable device-initiated U1 or U2 transitions.
4083 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4085 return -EINVAL; in usb_set_device_initiated_lpm()
4088 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4089 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4098 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
4116 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4119 return -EBUSY; in usb_set_device_initiated_lpm()
4138 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4140 return -EINVAL; in usb_set_lpm_timeout()
4145 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4148 return -EINVAL; in usb_set_lpm_timeout()
4151 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4152 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4155 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4158 return -EBUSY; in usb_set_lpm_timeout()
4161 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4163 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4178 if (!udev->lpm_devinit_allow) in usb_device_may_initiate_lpm()
4182 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4184 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4188 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4193 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4197 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) { in usb_device_may_initiate_lpm()
4198 desc = &intf->cur_altsetting->endpoint[j].desc; in usb_device_may_initiate_lpm()
4202 interval = (1 << (desc->bInterval - 1)) * 125; in usb_device_may_initiate_lpm()
4212 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4216 * control transfers to set the hub timeout or enable device-initiated U1/U2
4219 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4220 * hub-initiated U1/U2 will be disabled.
4234 if (!udev->bos) in usb_enable_link_state()
4237 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4238 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4253 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4260 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4268 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4271 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4278 if (udev->actconfig && in usb_enable_link_state()
4286 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4292 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4294 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4297 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4300 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4303 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4305 * still disallow device-initiated U1/U2 entry.
4319 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4321 return -EINVAL; in usb_disable_link_state()
4325 return -EBUSY; in usb_disable_link_state()
4329 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4330 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4337 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4341 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4343 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4349 * Disable hub-initiated and device-initiated U1 and U2 entry.
4353 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4359 if (!udev || !udev->parent || in usb_disable_lpm()
4360 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4361 !udev->lpm_capable || in usb_disable_lpm()
4362 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4365 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4366 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4369 udev->lpm_disable_count++; in usb_disable_lpm()
4370 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4383 return -EBUSY; in usb_disable_lpm()
4390 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4394 return -EINVAL; in usb_unlocked_disable_lpm()
4396 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4398 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4405 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4418 if (!udev || !udev->parent || in usb_enable_lpm()
4419 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4420 !udev->lpm_capable || in usb_enable_lpm()
4421 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4424 udev->lpm_disable_count--; in usb_enable_lpm()
4425 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4429 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4430 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4433 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4436 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4440 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4442 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4445 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4453 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4458 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4460 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4468 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4471 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4472 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4479 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4481 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4535 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4536 * a connection with a plugged-in cable but will signal the host when the cable
4537 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4541 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4542 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4545 if (!hub->error) { in hub_port_disable()
4546 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4548 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4555 if (port_dev->child && set_state) in hub_port_disable()
4556 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4557 if (ret && ret != -ENODEV) in hub_port_disable()
4558 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4563 * usb_port_disable - disable a usb device's upstream port
4571 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4573 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4576 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4579 * of 100ms at least for debounce and power-settling. The corresponding
4582 * Apparently there are some bluetooth and irda-dongles and a number of
4583 * low-speed devices for which this debounce period may last over a second.
4584 * Not covered by the spec - but easy to deal with.
4587 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4597 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4617 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4626 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4630 return -ETIMEDOUT; in hub_port_debounce()
4638 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4648 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4654 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4655 return -EINVAL; in hub_set_address()
4656 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4658 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4659 return -EINVAL; in hub_set_address()
4660 if (hcd->driver->address_device) in hub_set_address()
4661 retval = hcd->driver->address_device(hcd, udev); in hub_set_address()
4686 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4689 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4693 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4695 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4697 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4704 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4706 if (!hcd->driver->enable_device) in hub_enable_device()
4708 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4710 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4711 return -EINVAL; in hub_enable_device()
4713 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4743 buf->bDescriptorType = buf->bMaxPacketSize0 = 0; in get_bMaxPacketSize0()
4749 switch (buf->bMaxPacketSize0) { in get_bMaxPacketSize0()
4751 if (buf->bDescriptorType == USB_DT_DEVICE) { in get_bMaxPacketSize0()
4752 rc = buf->bMaxPacketSize0; in get_bMaxPacketSize0()
4758 rc = -EPROTO; in get_bMaxPacketSize0()
4766 * attempt, lest we get into a time-out/reset loop. in get_bMaxPacketSize0()
4768 if (rc > 0 || (rc == -ETIMEDOUT && first_time && in get_bMaxPacketSize0()
4769 udev->speed > USB_SPEED_FULL)) in get_bMaxPacketSize0()
4781 * If this is called for an already-existing device (as part of
4789 * @udev->descriptor. For an already existing device, @dev_descr
4790 * must be non-NULL. The device descriptor will be stored there,
4791 * not in @udev->descriptor, because descriptors for registered
4798 struct usb_device *hdev = hub->hdev; in hub_port_init()
4799 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4800 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4803 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4805 int devnum = udev->devnum; in hub_port_init()
4814 return -ENOMEM; in hub_port_init()
4819 if (!hdev->parent) { in hub_port_init()
4821 if (port1 == hdev->bus->otg_port) in hub_port_init()
4822 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4837 retval = -ENODEV; in hub_port_init()
4840 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4841 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4842 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4845 oldspeed = udev->speed; in hub_port_init()
4851 switch (udev->speed) { in hub_port_init()
4854 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4857 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4864 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4867 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4874 speed = usb_speed_string(udev->speed); in hub_port_init()
4881 * platform device is usually a dual-role USB controller device. in hub_port_init()
4883 if (udev->bus->controller->driver) in hub_port_init()
4884 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4886 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4888 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4889 dev_info(&udev->dev, in hub_port_init()
4896 if (hdev->tt) { in hub_port_init()
4897 udev->tt = hdev->tt; in hub_port_init()
4898 udev->ttport = hdev->ttport; in hub_port_init()
4899 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4900 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4901 if (!hub->tt.hub) { in hub_port_init()
4902 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4903 retval = -EINVAL; in hub_port_init()
4906 udev->tt = &hub->tt; in hub_port_init()
4907 udev->ttport = port1; in hub_port_init()
4917 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4918 * so it may help with some non-standards-compliant devices. in hub_port_init()
4927 retval = -ENODEV; in hub_port_init()
4934 dev_err(&udev->dev, in hub_port_init()
4943 maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
4944 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
4945 retval = -ENODEV; in hub_port_init()
4952 if (oldspeed != udev->speed) { in hub_port_init()
4953 dev_dbg(&udev->dev, in hub_port_init()
4955 retval = -ENODEV; in hub_port_init()
4959 if (maxp0 != -ENODEV) in hub_port_init()
4960 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4974 if (retval != -ENODEV) in hub_port_init()
4975 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
4979 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
4980 devnum = udev->devnum; in hub_port_init()
4981 dev_info(&udev->dev, in hub_port_init()
4983 (udev->config) ? "reset" : "new", in hub_port_init()
4984 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
4986 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
4988 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
4990 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
4997 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
4998 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
5008 if (retval != -ENODEV) in hub_port_init()
5009 dev_err(&udev->dev, in hub_port_init()
5015 if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5016 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5017 retval = -ENODEV; in hub_port_init()
5021 delay = udev->parent->hub_delay; in hub_port_init()
5022 udev->hub_delay = min_t(u32, delay, in hub_port_init()
5026 dev_dbg(&udev->dev, in hub_port_init()
5043 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5049 if (usb_endpoint_maxp(&udev->ep0.desc) == i) { in hub_port_init()
5051 } else if ((udev->speed == USB_SPEED_FULL || in hub_port_init()
5052 udev->speed == USB_SPEED_HIGH) && in hub_port_init()
5055 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
5056 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
5058 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
5059 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
5063 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); in hub_port_init()
5064 retval = -EMSGSIZE; in hub_port_init()
5071 if (retval != -ENODEV) in hub_port_init()
5072 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
5077 udev->descriptor = *descr; in hub_port_init()
5088 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
5089 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
5090 dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); in hub_port_init()
5092 retval = -EINVAL; in hub_port_init()
5098 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5101 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5102 udev->lpm_disable_count = 1; in hub_port_init()
5110 if (hcd->driver->update_device) in hub_port_init()
5111 hcd->driver->update_device(hcd, udev); in hub_port_init()
5128 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5138 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5141 if (hub->has_indicators) { in check_highspeed()
5142 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5144 &hub->leds, 0); in check_highspeed()
5153 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5157 if (!hub->limited_power) in hub_power_remaining()
5160 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5161 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
5162 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5163 struct usb_device *udev = port_dev->child; in hub_power_remaining()
5178 if (udev->actconfig) in hub_power_remaining()
5179 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5180 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5184 if (delta > hub->mA_per_port) in hub_power_remaining()
5185 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
5186 delta, hub->mA_per_port); in hub_power_remaining()
5187 remaining -= delta; in hub_power_remaining()
5190 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5191 -remaining); in hub_power_remaining()
5210 if (memcmp(&udev->descriptor, new_device_descriptor, in descriptors_changed()
5214 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5216 if (udev->bos) { in descriptors_changed()
5217 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5218 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5220 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5230 if (udev->serial) in descriptors_changed()
5231 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5234 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5235 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5244 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5245 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5249 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5254 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5256 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5258 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5266 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5269 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5272 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5273 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5285 int status = -ENODEV; in hub_port_connect()
5288 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5289 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5290 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5291 struct usb_device *udev = port_dev->child; in hub_port_connect()
5292 static int unreliable_port = -1; in hub_port_connect()
5297 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5298 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5299 usb_disconnect(&port_dev->child); in hub_port_connect()
5307 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5313 if (status != -ENODEV && in hub_port_connect()
5316 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5328 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5336 && !port_dev->port_owner) in hub_port_connect()
5343 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5352 status = -ENODEV; in hub_port_connect()
5357 mutex_lock(hcd->address0_mutex); in hub_port_connect()
5362 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5364 dev_err(&port_dev->dev, in hub_port_connect()
5366 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5372 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5373 udev->level = hdev->level + 1; in hub_port_connect()
5376 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5377 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5379 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5382 if (udev->devnum <= 0) { in hub_port_connect()
5383 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5387 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5392 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5396 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5399 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5402 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5405 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5406 && udev->bus_mA <= unit_load) { in hub_port_connect()
5412 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5416 dev_err(&udev->dev, in hub_port_connect()
5417 "can't connect bus-powered hub " in hub_port_connect()
5419 if (hub->has_indicators) { in hub_port_connect()
5420 hub->indicator[port1-1] = in hub_port_connect()
5424 &hub->leds, 0); in hub_port_connect()
5426 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5432 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5433 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5450 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5451 status = -ENOTCONN; in hub_port_connect()
5453 port_dev->child = udev; in hub_port_connect()
5463 port_dev->child = NULL; in hub_port_connect()
5467 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5468 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5469 udev->speed); in hub_port_connect()
5478 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5489 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5493 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5496 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5497 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5498 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5505 if (hub->hdev->parent || in hub_port_connect()
5506 !hcd->driver->port_handed_over || in hub_port_connect()
5507 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5508 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5509 dev_err(&port_dev->dev, in hub_port_connect()
5515 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5516 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5517 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5523 * a port connection-change occurs;
5524 * a port enable-change occurs (often caused by EMI);
5531 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5533 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5534 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5536 int status = -ENODEV; in hub_port_connect_change()
5538 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5541 if (hub->has_indicators) { in hub_port_connect_change()
5543 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5548 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5555 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5558 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5565 dev_dbg(&udev->dev, in hub_port_connect_change()
5570 udev->bos)) { in hub_port_connect_change()
5571 dev_dbg(&udev->dev, in hub_port_connect_change()
5579 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5580 udev->persist_enabled) { in hub_port_connect_change()
5592 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5603 /* Handle notifying userspace about hub over-current events */
5610 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5612 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5617 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5626 port_dev->over_current_count); in port_over_current_notify()
5630 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5639 __must_hold(&port_dev->status_lock) in port_event()
5642 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5643 struct usb_device *udev = port_dev->child; in port_event()
5644 struct usb_device *hdev = hub->hdev; in port_event()
5648 connect_change = test_bit(port1, hub->change_bits); in port_event()
5649 clear_bit(port1, hub->event_bits); in port_event()
5650 clear_bit(port1, hub->wakeup_bits); in port_event()
5662 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5673 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5680 port_dev->over_current_count++; in port_event()
5683 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5684 port_dev->over_current_count); in port_event()
5691 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5695 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5700 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5705 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5710 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5716 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5720 if (port_dev->ignore_event && port_dev->early_stop) in port_event()
5738 dev_dbg(&port_dev->dev, "Wait for inactive link disconnect detect\n"); in port_event()
5741 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5742 dev_dbg(&port_dev->dev, "do warm reset, port only\n"); in port_event()
5747 dev_dbg(&port_dev->dev, "do warm reset, full device\n"); in port_event()
5773 hdev = hub->hdev; in hub_event()
5774 hub_dev = hub->intfdev; in hub_event()
5777 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5780 hdev->state, hdev->maxchild, in hub_event()
5782 (u16) hub->change_bits[0], in hub_event()
5783 (u16) hub->event_bits[0]); in hub_event()
5788 if (unlikely(hub->disconnected)) in hub_event()
5792 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5793 hub->error = -ENODEV; in hub_event()
5806 if (hub->quiescing) in hub_event()
5809 if (hub->error) { in hub_event()
5810 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5818 hub->nerrors = 0; in hub_event()
5819 hub->error = 0; in hub_event()
5823 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5824 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5826 if (test_bit(i, hub->event_bits) in hub_event()
5827 || test_bit(i, hub->change_bits) in hub_event()
5828 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5835 * (powered-off), we leave it in that state, run in hub_event()
5838 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5839 pm_runtime_barrier(&port_dev->dev); in hub_event()
5843 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5848 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5858 hub->limited_power = 1; in hub_event()
5860 hub->limited_power = 0; in hub_event()
5866 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5872 dev_err(hub_dev, "over-current condition\n"); in hub_event()
5884 kref_put(&hub->kref, hub_release); in hub_event()
5945 return -1; in usb_hub_init()
5950 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
5952 * over to the companion full-speed controller. in usb_hub_init()
5962 return -1; in usb_hub_init()
5974 * individual hub resources. -greg in usb_hub_cleanup()
5980 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
5983 * WARNING - don't use this routine to reset a composite device
5992 * re-connected. All drivers will be unbound, and the device will be
5993 * re-enumerated and probed all over again.
5995 * Return: 0 if the reset succeeded, -ENODEV if the device has been
6015 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
6017 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
6021 int port1 = udev->portnum; in usb_reset_and_verify_device()
6023 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
6024 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
6025 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
6026 udev->state); in usb_reset_and_verify_device()
6027 return -EINVAL; in usb_reset_and_verify_device()
6031 return -EISDIR; in usb_reset_and_verify_device()
6036 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
6040 bos = udev->bos; in usb_reset_and_verify_device()
6041 udev->bos = NULL; in usb_reset_and_verify_device()
6043 mutex_lock(hcd->address0_mutex); in usb_reset_and_verify_device()
6047 ret = -ENODEV; in usb_reset_and_verify_device()
6052 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
6055 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
6058 mutex_unlock(hcd->address0_mutex); in usb_reset_and_verify_device()
6065 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
6070 if (!udev->actconfig) in usb_reset_and_verify_device()
6073 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6074 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
6076 dev_warn(&udev->dev, in usb_reset_and_verify_device()
6079 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6084 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
6087 dev_err(&udev->dev, in usb_reset_and_verify_device()
6089 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
6090 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6093 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6097 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
6099 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
6102 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6103 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
6104 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
6107 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
6108 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
6117 intf->resetting_device = 1; in usb_reset_and_verify_device()
6118 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
6119 desc->bAlternateSetting); in usb_reset_and_verify_device()
6120 intf->resetting_device = 0; in usb_reset_and_verify_device()
6123 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
6125 desc->bInterfaceNumber, in usb_reset_and_verify_device()
6126 desc->bAlternateSetting, in usb_reset_and_verify_device()
6131 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
6132 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
6136 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
6141 udev->bos = bos; in usb_reset_and_verify_device()
6146 udev->bos = bos; in usb_reset_and_verify_device()
6148 return -ENODEV; in usb_reset_and_verify_device()
6152 * usb_reset_device - warn interface drivers and perform a USB port reset
6162 * being unbound or re-bound during the ongoing reset its disconnect()
6164 * routine returns -EINPROGRESS.
6183 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6184 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6186 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6187 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6188 udev->state); in usb_reset_device()
6189 return -EINVAL; in usb_reset_device()
6192 if (!udev->parent) { in usb_reset_device()
6193 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
6194 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6195 return -EISDIR; in usb_reset_device()
6198 if (udev->reset_in_progress) in usb_reset_device()
6199 return -EINPROGRESS; in usb_reset_device()
6200 udev->reset_in_progress = 1; in usb_reset_device()
6202 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6219 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
6220 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6224 if (cintf->dev.driver) { in usb_reset_device()
6225 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6226 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
6227 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
6228 else if (cintf->condition == in usb_reset_device()
6242 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
6243 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6245 int rebind = cintf->needs_binding; in usb_reset_device()
6247 if (!rebind && cintf->dev.driver) { in usb_reset_device()
6248 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6249 if (drv->post_reset) in usb_reset_device()
6250 rebind = (drv->post_reset)(cintf); in usb_reset_device()
6251 else if (cintf->condition == in usb_reset_device()
6255 cintf->needs_binding = 1; in usb_reset_device()
6266 udev->reset_in_progress = 0; in usb_reset_device()
6273 * usb_queue_reset_device - Reset a USB device from an atomic context
6286 * - Scheduling two resets at the same time from two different drivers
6289 * handles ->pre_reset(), the second reset might happen or not.
6291 * - If the reset is delayed so long that the interface is unbound from
6294 * - This function can be called during .probe(). It can also be called
6297 * .disconnect(), call usb_reset_device() directly -- but watch out
6302 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6308 * usb_hub_find_child - Get the pointer of child device
6318 * child's usb_device pointer if non-NULL.
6325 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6327 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6342 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6343 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6345 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6349 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6350 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6351 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6356 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6358 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6359 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6361 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6366 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6372 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6378 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6393 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()