Lines Matching +full:multiply +full:- +full:accumulate
1 // SPDX-License-Identifier: GPL-2.0
77 /* Protect struct usb_device->state and ->children members
78 * Note: Both are also protected by ->dev.sem, except that ->state can
86 /* synchronize hub-port add/remove and peering operations */
96 * 10 seconds to send reply for the initial 64-byte descriptor request.
98 /* define initial 64-byte descriptor request timeout in milliseconds */
102 "initial 64-byte descriptor request timeout in milliseconds "
103 "(default 5000 - 5.0 seconds)");
147 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
149 if (hub_is_superspeed(hub->hdev)) in portspeed()
162 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
164 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
170 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
174 if (!udev->bos) in usb_device_supports_lpm()
180 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
181 if (udev->bos->ext_cap && in usb_device_supports_lpm()
183 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
193 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
194 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
198 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
199 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
200 if (udev->parent) in usb_device_supports_lpm()
201 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
203 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
207 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
233 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
235 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
241 * Multiply by 2 to include it as well. in usb_set_lpm_mel()
243 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
254 if (!hub->hdev->parent) in usb_set_lpm_mel()
257 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
291 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
294 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
298 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
300 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
304 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
309 * - t1: device PEL
310 * - t2: time for the ERDY to make it from the device to the host.
311 * - t3: a host-specific delay to process the ERDY.
312 * - t4: time for the packet to make it from the host to the device.
326 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
328 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
329 parent = parent->parent) in usb_set_lpm_sel()
331 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
333 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
338 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
350 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
354 if (!udev->bos) in usb_set_lpm_parameters()
357 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
364 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
365 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
366 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
367 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
369 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
370 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
372 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
373 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
385 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
394 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
395 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
399 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
403 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
404 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
408 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
409 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
437 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
439 return -EMSGSIZE; in get_hub_descriptor()
443 return -EINVAL; in get_hub_descriptor()
492 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
497 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
500 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
502 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
512 struct usb_device *hdev = hub->hdev; in led_work()
515 int cursor = -1; in led_work()
517 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
520 for (i = 0; i < hdev->maxchild; i++) { in led_work()
523 /* 30%-50% duty cycle */ in led_work()
525 switch (hub->indicator[i]) { in led_work()
565 hub->indicator[i] = mode; in led_work()
569 cursor %= hdev->maxchild; in led_work()
571 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
576 &hub->leds, LED_CYCLE_PERIOD); in led_work()
589 int i, status = -ETIMEDOUT; in get_hub_status()
592 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
607 int i, status = -ETIMEDOUT; in get_port_status()
610 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
627 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
628 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
630 if (ret != -ENODEV) in hub_ext_port_status()
631 dev_err(hub->intfdev, in hub_ext_port_status()
634 ret = -EIO; in hub_ext_port_status()
636 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
637 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
640 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
643 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
647 * protects hub->status, and the phy driver only checks the port in hub_ext_port_status()
651 struct usb_device *hdev = hub->hdev; in hub_ext_port_status()
659 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_ext_port_status()
666 usb_phy_roothub_notify_connect(hcd->phy_roothub, port1 - 1); in hub_ext_port_status()
668 usb_phy_roothub_notify_disconnect(hcd->phy_roothub, port1 - 1); in hub_ext_port_status()
687 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
689 if (hub->quiescing) { in hub_resubmit_irq_urb()
690 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
694 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
695 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
696 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
697 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
698 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
701 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
716 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
727 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
731 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
766 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
767 if (port_dev && port_dev->child) in usb_wakeup_notification()
768 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
770 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
779 struct usb_hub *hub = urb->context; in hub_irq()
780 int status = urb->status; in hub_irq()
785 case -ENOENT: /* synchronous unlink */ in hub_irq()
786 case -ECONNRESET: /* async unlink */ in hub_irq()
787 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
792 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
793 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
795 hub->error = status; in hub_irq()
801 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
802 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
804 hub->event_bits[0] = bits; in hub_irq()
808 hub->nerrors = 0; in hub_irq()
847 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
848 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
851 struct usb_device *hdev = hub->hdev; in hub_tt_work()
855 next = hub->tt.clear_list.next; in hub_tt_work()
857 list_del(&clear->clear_list); in hub_tt_work()
860 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
861 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
862 if (status && status != -ENODEV) in hub_tt_work()
863 dev_err(&hdev->dev, in hub_tt_work()
865 clear->tt, clear->devinfo, status); in hub_tt_work()
868 drv = clear->hcd->driver; in hub_tt_work()
869 if (drv->clear_tt_buffer_complete) in hub_tt_work()
870 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
873 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
875 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
879 * usb_hub_set_port_power - control hub port's power state
904 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
906 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
911 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
926 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
927 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
928 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
938 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
940 return -ENOMEM; in usb_hub_clear_tt_buffer()
944 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
945 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
946 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
947 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
951 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
954 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
955 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
958 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
959 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
960 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
961 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
972 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
977 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
979 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
980 "non-switchable hub\n"); in hub_power_on()
981 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
982 if (test_bit(port1, hub->power_bits)) in hub_power_on()
983 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
985 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
996 mutex_lock(&hub->status_mutex); in hub_hub_status()
997 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
999 if (ret != -ENODEV) in hub_hub_status()
1000 dev_err(hub->intfdev, in hub_hub_status()
1003 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
1004 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
1007 mutex_unlock(&hub->status_mutex); in hub_hub_status()
1014 return set_port_feature(hub->hdev, in hub_set_port_link_state()
1020 * Disable a port and mark a logical connect-change event, so that some
1022 * and will re-enumerate if there actually is a device attached.
1026 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
1030 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
1031 * - SRP saves power that way in hub_port_logical_disconnect()
1032 * - ... new call, TBD ... in hub_port_logical_disconnect()
1033 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1038 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1043 * usb_remove_device - disable a device's port on its parent hub
1060 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1061 return -EINVAL; in usb_remove_device()
1062 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1063 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1069 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1070 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1085 struct usb_device *hdev = hub->hdev; in hub_activate()
1095 device_lock(&hdev->dev); in hub_activate()
1098 if (hub->disconnected) in hub_activate()
1118 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1121 hdev->level - 1, 0, NULL, 0, in hub_activate()
1124 dev_err(hub->intfdev, in hub_activate()
1129 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1130 * and the implementation looks like a home-brewed sort of in hub_activate()
1144 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1146 &hub->init_work, in hub_activate()
1151 to_usb_interface(hub->intfdev)); in hub_activate()
1158 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1159 if (hcd->driver->update_hub_device) { in hub_activate()
1160 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1161 &hub->tt, GFP_NOIO); in hub_activate()
1163 dev_err(hub->intfdev, in hub_activate()
1165 dev_err(hub->intfdev, in hub_activate()
1174 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1180 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1183 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1184 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1185 struct usb_device *udev = port_dev->child; in hub_activate()
1194 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1207 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1220 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1223 set_bit(port1, hub->event_bits); in hub_activate()
1235 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1238 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1243 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1248 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1252 hub_is_superspeed(hub->hdev)) { in hub_activate()
1254 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1262 clear_bit(port1, hub->removed_bits); in hub_activate()
1264 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1275 set_bit(port1, hub->change_bits); in hub_activate()
1287 * bit on device-initiated resume. in hub_activate()
1289 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1291 set_bit(port1, hub->event_bits); in hub_activate()
1293 } else if (udev->persist_enabled) { in hub_activate()
1295 udev->reset_resume = 1; in hub_activate()
1300 if (test_bit(port1, hub->power_bits)) in hub_activate()
1301 set_bit(port1, hub->change_bits); in hub_activate()
1306 set_bit(port1, hub->change_bits); in hub_activate()
1310 /* If no port-status-change flags were set, we don't need any in hub_activate()
1315 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1323 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1325 &hub->init_work, in hub_activate()
1327 device_unlock(&hdev->dev); in hub_activate()
1334 hub->quiescing = 0; in hub_activate()
1336 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1338 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1339 if (hub->has_indicators && blinkenlights) in hub_activate()
1341 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1349 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1350 device_unlock(&hdev->dev); in hub_activate()
1353 if (type == HUB_RESUME && hub_is_superspeed(hub->hdev)) { in hub_activate()
1356 to_usb_interface(hub->intfdev)); in hub_activate()
1359 &hub->post_resume_work, in hub_activate()
1386 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_post_resume()
1396 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1400 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1401 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1402 hub->quiescing = 1; in hub_quiesce()
1403 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1407 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1408 if (hub->ports[i]->child) in hub_quiesce()
1409 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1414 timer_delete_sync(&hub->irq_urb_retry); in hub_quiesce()
1415 flush_delayed_work(&hub->post_resume_work); in hub_quiesce()
1416 usb_kill_urb(hub->urb); in hub_quiesce()
1417 if (hub->has_indicators) in hub_quiesce()
1418 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1419 if (hub->tt.hub) in hub_quiesce()
1420 flush_work(&hub->tt.clear_work); in hub_quiesce()
1427 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1428 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1437 hub->in_reset = 1; in hub_pre_reset()
1447 hub->in_reset = 0; in hub_post_reset()
1457 struct usb_device *hdev = hub->hdev; in hub_configure()
1458 struct device *hub_dev = hub->intfdev; in hub_configure()
1468 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1469 if (!hub->buffer) { in hub_configure()
1470 ret = -ENOMEM; in hub_configure()
1474 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1475 if (!hub->status) { in hub_configure()
1476 ret = -ENOMEM; in hub_configure()
1479 mutex_init(&hub->status_mutex); in hub_configure()
1481 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1482 if (!hub->descriptor) { in hub_configure()
1483 ret = -ENOMEM; in hub_configure()
1488 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1489 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1491 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1501 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1503 ret = -ENODEV; in hub_configure()
1505 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1507 ret = -ENODEV; in hub_configure()
1512 * Accumulate wHubDelay + 40ns for every hub in the tree of devices. in hub_configure()
1516 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1518 if (hdev->parent) in hub_configure()
1519 delay += hdev->parent->hub_delay; in hub_configure()
1522 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1525 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1529 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1530 if (!hub->ports) { in hub_configure()
1531 ret = -ENOMEM; in hub_configure()
1535 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1550 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1573 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1576 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1580 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1584 spin_lock_init(&hub->tt.lock); in hub_configure()
1585 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1586 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1587 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1592 hub->tt.hub = hdev; in hub_configure()
1598 hub->tt.multi = 1; in hub_configure()
1602 hub->tt.hub = hdev; in hub_configure()
1609 hdev->descriptor.bDeviceProtocol); in hub_configure()
1616 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1617 hub->tt.think_time = 666; in hub_configure()
1620 8, hub->tt.think_time); in hub_configure()
1624 hub->tt.think_time = 666 * 2; in hub_configure()
1627 16, hub->tt.think_time); in hub_configure()
1630 hub->tt.think_time = 666 * 3; in hub_configure()
1633 24, hub->tt.think_time); in hub_configure()
1636 hub->tt.think_time = 666 * 4; in hub_configure()
1639 32, hub->tt.think_time); in hub_configure()
1643 /* probe() zeroes hub->indicator[] */ in hub_configure()
1645 hub->has_indicators = 1; in hub_configure()
1650 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1652 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1653 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1660 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1661 if (hdev == hdev->bus->root_hub) { in hub_configure()
1662 if (hcd->power_budget > 0) in hub_configure()
1663 hdev->bus_mA = hcd->power_budget; in hub_configure()
1665 hdev->bus_mA = full_load * maxchild; in hub_configure()
1666 if (hdev->bus_mA >= full_load) in hub_configure()
1667 hub->mA_per_port = full_load; in hub_configure()
1669 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1670 hub->limited_power = 1; in hub_configure()
1673 int remaining = hdev->bus_mA - in hub_configure()
1674 hub->descriptor->bHubContrCurrent; in hub_configure()
1677 hub->descriptor->bHubContrCurrent); in hub_configure()
1678 hub->limited_power = 1; in hub_configure()
1684 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1686 } else { /* Self-powered external hub */ in hub_configure()
1687 /* FIXME: What about battery-powered external hubs that in hub_configure()
1689 hub->mA_per_port = full_load; in hub_configure()
1691 if (hub->mA_per_port < full_load) in hub_configure()
1693 hub->mA_per_port); in hub_configure()
1702 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1708 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1717 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1720 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1721 maxp = sizeof(*hub->buffer); in hub_configure()
1723 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1724 if (!hub->urb) { in hub_configure()
1725 ret = -ENOMEM; in hub_configure()
1729 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1730 hub, endpoint->bInterval); in hub_configure()
1733 if (hub->has_indicators && blinkenlights) in hub_configure()
1734 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1740 dev_err(hub->intfdev, in hub_configure()
1745 hdev->maxchild = i; in hub_configure()
1746 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1747 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1749 pm_runtime_put(&port_dev->dev); in hub_configure()
1759 if (hcd->driver->update_hub_device) { in hub_configure()
1760 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1761 &hub->tt, GFP_KERNEL); in hub_configure()
1768 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1784 usb_put_dev(hub->hdev); in hub_release()
1785 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1791 kref_get(&hub->kref); in hub_get()
1796 kref_put(&hub->kref, hub_release); in hub_put()
1811 hub->disconnected = 1; in hub_disconnect()
1814 hub->error = 0; in hub_disconnect()
1821 port1 = hdev->maxchild; in hub_disconnect()
1822 hdev->maxchild = 0; in hub_disconnect()
1826 for (; port1 > 0; --port1) in hub_disconnect()
1831 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1832 highspeed_hubs--; in hub_disconnect()
1834 usb_free_urb(hub->urb); in hub_disconnect()
1835 kfree(hub->ports); in hub_disconnect()
1836 kfree(hub->descriptor); in hub_disconnect()
1837 kfree(hub->status); in hub_disconnect()
1838 kfree(hub->buffer); in hub_disconnect()
1840 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1842 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1845 onboard_dev_destroy_pdevs(&hub->onboard_devs); in hub_disconnect()
1854 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1855 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1858 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1859 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1863 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1875 desc = intf->cur_altsetting; in hub_probe()
1883 if (hdev->descriptor.bNumConfigurations > 1 || in hub_probe()
1884 hdev->actconfig->desc.bNumInterfaces > 1) { in hub_probe()
1885 dev_err(&intf->dev, "Invalid hub with more than one config or interface\n"); in hub_probe()
1886 return -EINVAL; in hub_probe()
1893 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1898 * - The patch might cause one or more auto supend/resume for in hub_probe()
1914 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1918 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1922 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1923 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1926 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1927 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1935 if (hdev->parent) { /* normal device */ in hub_probe()
1938 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1940 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1944 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1945 dev_err(&intf->dev, in hub_probe()
1947 return -E2BIG; in hub_probe()
1951 if (hdev->parent) { in hub_probe()
1952 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1953 return -ENODEV; in hub_probe()
1958 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1959 return -EIO; in hub_probe()
1963 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1967 return -ENOMEM; in hub_probe()
1969 kref_init(&hub->kref); in hub_probe()
1970 hub->intfdev = &intf->dev; in hub_probe()
1971 hub->hdev = hdev; in hub_probe()
1972 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1973 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1974 INIT_DELAYED_WORK(&hub->post_resume_work, hub_post_resume); in hub_probe()
1975 INIT_WORK(&hub->events, hub_event); in hub_probe()
1976 INIT_LIST_HEAD(&hub->onboard_devs); in hub_probe()
1977 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1978 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1983 intf->needs_remote_wakeup = 1; in hub_probe()
1984 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1986 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1989 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1990 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1992 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { in hub_probe()
1993 hub->quirk_disable_autosuspend = 1; in hub_probe()
1997 if ((id->driver_info & HUB_QUIRK_REDUCE_FRAME_INTR_BINTERVAL) && in hub_probe()
1998 desc->endpoint[0].desc.bInterval > USB_REDUCE_FRAME_INTR_BINTERVAL) { in hub_probe()
1999 desc->endpoint[0].desc.bInterval = in hub_probe()
2005 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
2006 onboard_dev_create_pdevs(hdev, &hub->onboard_devs); in hub_probe()
2012 return -ENODEV; in hub_probe()
2028 if (hdev->devnum <= 0) in hub_ioctl()
2029 info->nports = 0; in hub_ioctl()
2031 info->nports = hdev->maxchild; in hub_ioctl()
2032 for (i = 0; i < info->nports; i++) { in hub_ioctl()
2033 if (hub->ports[i]->child == NULL) in hub_ioctl()
2034 info->port[i] = 0; in hub_ioctl()
2036 info->port[i] = in hub_ioctl()
2037 hub->ports[i]->child->devnum; in hub_ioctl()
2042 return info->nports + 1; in hub_ioctl()
2046 return -ENOSYS; in hub_ioctl()
2059 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
2060 return -ENODEV; in find_port_owner()
2061 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
2062 return -EINVAL; in find_port_owner()
2067 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2082 return -EBUSY; in usb_hub_claim_port()
2098 return -ENOENT; in usb_hub_release_port()
2109 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
2110 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2111 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2121 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2123 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2124 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2132 if (udev->parent) { in update_port_device_state()
2133 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2143 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2144 WRITE_ONCE(port_dev->state, udev->state); in update_port_device_state()
2145 sysfs_notify_dirent(port_dev->state_kn); in update_port_device_state()
2155 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2156 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2157 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2159 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2160 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2161 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2166 * usb_set_device_state - change a device's current state (usbcore, hcds)
2170 * udev->state is _not_ fully protected by the device lock. Although
2181 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2182 * Otherwise udev->state is set to new_state, and if new_state is
2190 int wakeup = -1; in usb_set_device_state()
2193 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2197 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2200 if (udev->parent) { in usb_set_device_state()
2201 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2205 wakeup = (udev->quirks & in usb_set_device_state()
2207 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2212 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2214 udev->active_duration -= jiffies; in usb_set_device_state()
2216 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2217 udev->active_duration += jiffies; in usb_set_device_state()
2218 udev->state = new_state; in usb_set_device_state()
2224 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2231 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2232 * USB-2.0 buses they are also used as device addresses, however on
2233 * USB-3.0 buses the address is assigned by the controller hardware
2244 struct usb_bus *bus = udev->bus; in choose_devnum()
2247 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2249 /* Try to allocate the next devnum beginning at bus->devnum_next. */ in choose_devnum()
2250 devnum = find_next_zero_bit(bus->devmap, 128, bus->devnum_next); in choose_devnum()
2252 devnum = find_next_zero_bit(bus->devmap, 128, 1); in choose_devnum()
2253 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2255 set_bit(devnum, bus->devmap); in choose_devnum()
2256 udev->devnum = devnum; in choose_devnum()
2258 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2263 if (udev->devnum > 0) { in release_devnum()
2264 clear_bit(udev->devnum, udev->bus->devmap); in release_devnum()
2265 udev->devnum = -1; in release_devnum()
2271 udev->devnum = devnum; in update_devnum()
2272 if (!udev->devaddr) in update_devnum()
2273 udev->devaddr = (u8)devnum; in update_devnum()
2278 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2281 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2282 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2291 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2292 if (hub->ports[i]->child) in hub_disconnect_children()
2293 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2298 * usb_disconnect - disconnect a device (usbcore-internal)
2326 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2327 udev->devnum); in usb_disconnect()
2333 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2343 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2347 if (udev->parent) { in usb_disconnect()
2348 port1 = udev->portnum; in usb_disconnect()
2349 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2350 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2352 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2353 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2356 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2359 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2360 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2362 typec_deattach(port_dev->connector, &udev->dev); in usb_disconnect()
2365 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2368 if (udev->usb4_link) in usb_disconnect()
2369 device_link_del(udev->usb4_link); in usb_disconnect()
2372 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2375 device_del(&udev->dev); in usb_disconnect()
2387 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2388 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2392 put_device(&udev->dev); in usb_disconnect()
2400 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2405 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2407 dev_info(&udev->dev, in announce_device()
2409 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2410 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2412 dev_info(&udev->dev, in announce_device()
2414 udev->descriptor.iManufacturer, in announce_device()
2415 udev->descriptor.iProduct, in announce_device()
2416 udev->descriptor.iSerialNumber); in announce_device()
2417 show_string(udev, "Product", udev->product); in announce_device()
2418 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2419 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2427 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2430 * Finish enumeration for On-The-Go devices
2440 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2444 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2445 && udev->config in usb_enumerate_device_otg()
2446 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2448 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2449 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2452 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2453 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2455 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2458 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2459 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2462 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2463 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2475 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2477 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2479 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2487 if (bus->otg_port != 0) { in usb_enumerate_device_otg()
2496 dev_err(&udev->dev, in usb_enumerate_device_otg()
2508 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2511 * This is only called by usb_new_device() -- all comments that apply there
2523 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2525 if (udev->config == NULL) { in usb_enumerate_device()
2528 if (err != -ENODEV) in usb_enumerate_device()
2529 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2536 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2537 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2538 udev->descriptor.iManufacturer); in usb_enumerate_device()
2539 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2545 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2550 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2551 || udev->bus->is_b_host)) { in usb_enumerate_device()
2554 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2556 return -ENOTSUPP; in usb_enumerate_device()
2566 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2568 u8 port = udev->portnum; in set_usb_port_removable()
2572 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2577 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2583 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2585 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2589 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2599 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2605 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2609 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2614 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2616 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2621 * usb_new_device - perform initial device setup (usbcore-internal)
2634 * Only the hub driver or root-hub registrar should ever call this.
2645 if (udev->parent) { in usb_new_device()
2646 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2650 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2653 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2654 pm_runtime_set_active(&udev->dev); in usb_new_device()
2655 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2656 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2657 pm_runtime_enable(&udev->dev); in usb_new_device()
2667 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2668 udev->devnum, udev->bus->busnum, in usb_new_device()
2669 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2670 /* export the usbdev device-node for libusb */ in usb_new_device()
2671 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2672 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2677 if (udev->serial) in usb_new_device()
2678 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2679 if (udev->product) in usb_new_device()
2680 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2681 if (udev->manufacturer) in usb_new_device()
2682 add_device_randomness(udev->manufacturer, in usb_new_device()
2683 strlen(udev->manufacturer)); in usb_new_device()
2685 device_enable_async_suspend(&udev->dev); in usb_new_device()
2687 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2691 * for configuring the device and invoking the add-device in usb_new_device()
2694 err = device_add(&udev->dev); in usb_new_device()
2696 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2701 if (udev->parent) { in usb_new_device()
2702 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2703 int port1 = udev->portnum; in usb_new_device()
2704 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2706 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2707 &port_dev->dev.kobj, "port"); in usb_new_device()
2711 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2712 &udev->dev.kobj, "device"); in usb_new_device()
2714 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2718 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2719 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2721 typec_attach(port_dev->connector, &udev->dev); in usb_new_device()
2724 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2726 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2730 device_del(&udev->dev); in usb_new_device()
2733 pm_runtime_disable(&udev->dev); in usb_new_device()
2734 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2740 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2754 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2757 usb_dev->authorized = 0; in usb_deauthorize_device()
2758 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2771 if (usb_dev->authorized == 1) in usb_authorize_device()
2776 dev_err(&usb_dev->dev, in usb_authorize_device()
2781 usb_dev->authorized = 1; in usb_authorize_device()
2789 dev_err(&usb_dev->dev, in usb_authorize_device()
2795 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2805 * get_port_ssp_rate - Match the extended port status to SSP rate
2823 if (!hdev->bos) in get_port_ssp_rate()
2826 ssp_cap = hdev->bos->ssp_cap; in get_port_ssp_rate()
2833 ssac = le32_to_cpu(ssp_cap->bmAttributes) & in get_port_ssp_rate()
2839 attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in get_port_ssp_rate()
2910 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2920 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2941 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2944 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2967 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2982 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2983 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2993 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2999 return -EBUSY; in hub_port_wait_reset()
3002 return -ENOTCONN; in hub_port_wait_reset()
3006 return -ENOTCONN; in hub_port_wait_reset()
3010 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
3012 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
3014 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
3016 return -EAGAIN; in hub_port_wait_reset()
3020 return -EBUSY; in hub_port_wait_reset()
3025 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
3027 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
3028 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
3029 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
3031 udev->rx_lanes = 1; in hub_port_wait_reset()
3032 udev->tx_lanes = 1; in hub_port_wait_reset()
3033 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
3035 if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
3036 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
3037 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
3038 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
3040 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
3042 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
3044 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
3054 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
3057 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
3059 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
3061 return -EINVAL; in hub_port_reset()
3078 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3082 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3085 if (status == -ENODEV) { in hub_port_reset()
3088 dev_err(&port_dev->dev, in hub_port_reset()
3094 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
3095 dev_dbg(hub->intfdev, in hub_port_reset()
3104 if (status == 0 || status == -ENOTCONN || status == -ENODEV || in hub_port_reset()
3105 (status == -EBUSY && i == PORT_RESET_TRIES - 1)) { in hub_port_reset()
3106 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3109 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3112 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3114 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3118 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3123 * state, re-issue the warm reset. in hub_port_reset()
3138 dev_dbg(&port_dev->dev, in hub_port_reset()
3144 dev_dbg(&port_dev->dev, in hub_port_reset()
3150 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
3154 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
3161 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3168 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3174 if (hcd->driver->reset_device) in hub_port_reset()
3175 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3184 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3191 * hub_port_stop_enumerate - stop USB enumeration or ignore port events
3210 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3212 if (port_dev->early_stop) { in hub_port_stop_enumerate()
3213 if (port_dev->ignore_event) in hub_port_stop_enumerate()
3225 port_dev->ignore_event = 1; in hub_port_stop_enumerate()
3227 port_dev->ignore_event = 0; in hub_port_stop_enumerate()
3229 return port_dev->ignore_event; in hub_port_stop_enumerate()
3237 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3249 __acquires(&port_dev->status_lock) in usb_lock_port()
3251 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3252 __acquire(&port_dev->status_lock); in usb_lock_port()
3256 __releases(&port_dev->status_lock) in usb_unlock_port()
3258 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3259 __release(&port_dev->status_lock); in usb_unlock_port()
3269 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3282 * is ready for a reset-resume, or should be disconnected.
3288 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3293 if (status == 0 && udev->reset_resume in check_port_resume_type()
3301 status = -ENODEV; in check_port_resume_type()
3303 if (retries--) { in check_port_resume_type()
3309 status = -ENODEV; in check_port_resume_type()
3313 * so try a reset-resume instead. in check_port_resume_type()
3315 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3316 if (udev->persist_enabled) in check_port_resume_type()
3317 udev->reset_resume = 1; in check_port_resume_type()
3319 status = -ENODEV; in check_port_resume_type()
3323 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3325 } else if (udev->reset_resume) { in check_port_resume_type()
3327 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3329 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3332 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3336 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3337 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3338 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3340 * following the reset-resume. in check_port_resume_type()
3342 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3350 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3353 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3360 if (!udev->actconfig) in usb_disable_ltm()
3372 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3375 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3382 if (!udev->actconfig) in usb_enable_ltm()
3393 * usb_enable_remote_wakeup - enable remote wakeup for a device
3396 * For USB-2 devices: Set the device's remote wakeup feature.
3398 * For USB-3 devices: Assume there's only one function on the device and
3404 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3419 * usb_disable_remote_wakeup - disable remote wakeup for a device
3422 * For USB-2 devices: Clear the device's remote wakeup feature.
3424 * For USB-3 devices: Assume there's only one function on the device and
3430 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3442 /* Count of wakeup-enabled devices at or below udev */
3447 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3448 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3453 * usb_port_suspend - suspend a usb device's upstream port
3476 * between a pair of dual-role devices. That will change roles, such
3477 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3483 * - suspend, resume ... when the VBUS power link stays live
3484 * - suspend, disconnect ... VBUS lost
3487 * normal re-enumeration procedures, starting with enabling VBUS power.
3488 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3492 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3494 * hub is suspended). Nevertheless, we change @udev->state to
3496 * upstream port setting is stored in @udev->port_is_suspended.
3502 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3503 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3504 int port1 = udev->portnum; in usb_port_suspend()
3516 if (udev->do_remote_wakeup) { in usb_port_suspend()
3519 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3531 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3532 status = -ENOMEM; in usb_port_suspend()
3538 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3543 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3553 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3563 if (status == -ETIMEDOUT) { in usb_port_suspend()
3571 dev_dbg(&port_dev->dev, in usb_port_suspend()
3580 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3588 if (udev->do_remote_wakeup) in usb_port_suspend()
3597 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3598 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3599 udev->do_remote_wakeup); in usb_port_suspend()
3601 udev->port_is_suspended = 1; in usb_port_suspend()
3609 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3610 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3611 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3613 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3627 * If @udev->reset_resume is set then the device is reset before the
3636 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3637 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3644 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3653 if (udev->reset_resume) { in finish_port_resume()
3656 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3661 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3662 status = -ENODEV; in finish_port_resume()
3675 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3676 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3677 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3678 udev->reset_resume = 1; in finish_port_resume()
3684 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3690 * udev->reset_resume in finish_port_resume()
3692 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3693 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3705 dev_dbg(&udev->dev, in finish_port_resume()
3747 status = -ENODEV; in wait_for_connected()
3754 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3759 * usb_port_resume - re-activate a suspended usb device's upstream port
3760 * @udev: device to re-activate, not a root hub
3763 * This will re-activate the suspended device, increasing power usage
3769 * If @udev->reset_resume is set then this routine won't check that the
3777 * for mass-storage devices containing mounted filesystems, since the
3794 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3795 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3796 int port1 = udev->portnum; in usb_port_resume()
3800 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3801 status = pm_runtime_resume_and_get(&port_dev->dev); in usb_port_resume()
3803 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3811 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3815 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3820 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3823 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3826 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3829 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3830 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3842 udev->port_is_suspended = 0; in usb_port_resume()
3843 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3845 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3849 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3857 if (udev->persist_enabled) in usb_port_resume()
3866 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3886 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3887 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3901 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3903 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3910 hdev = hub->hdev; in hub_handle_remote_wakeup()
3911 udev = port_dev->child; in hub_handle_remote_wakeup()
3918 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3935 ret = -ENODEV; in hub_handle_remote_wakeup()
3938 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3946 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3960 struct usb_device *hdev = hub->hdev; in hub_suspend()
3965 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3967 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3968 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3969 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3970 struct usb_device *udev = port_dev->child; in hub_suspend()
3972 if (udev && udev->can_submit) { in hub_suspend()
3973 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3974 dev_name(&udev->dev)); in hub_suspend()
3976 return -EBUSY; in hub_suspend()
3979 hub->wakeup_enabled_descendants += in hub_suspend()
3983 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3987 return -EBUSY; in hub_suspend()
3988 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3992 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3994 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
4004 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
4014 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
4020 if (hdev->parent) in report_wakeup_requests()
4023 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
4024 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
4034 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
4035 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
4037 udev = hub->ports[i]->child; in report_wakeup_requests()
4039 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
4049 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
4066 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
4072 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
4079 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
4084 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4085 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
4098 * device-initiated U1 or U2. This lets the device know the exit latencies from
4114 if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) in usb_req_set_sel()
4118 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
4119 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
4120 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
4121 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
4128 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
4135 dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); in usb_req_set_sel()
4136 return -EINVAL; in usb_req_set_sel()
4146 return -ENOMEM; in usb_req_set_sel()
4148 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
4149 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
4150 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
4151 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
4162 udev->lpm_devinit_allow = 1; in usb_req_set_sel()
4168 * Enable or disable device-initiated U1 or U2 transitions.
4184 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4186 return -EINVAL; in usb_set_device_initiated_lpm()
4189 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4190 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4194 return -EINVAL; in usb_set_device_initiated_lpm()
4199 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
4217 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4219 return -EBUSY; in usb_set_device_initiated_lpm()
4238 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4240 return -EINVAL; in usb_set_lpm_timeout()
4245 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4248 return -EINVAL; in usb_set_lpm_timeout()
4251 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4252 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4255 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4258 return -EBUSY; in usb_set_lpm_timeout()
4261 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4263 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4278 if (!udev->lpm_devinit_allow || !udev->actconfig) in usb_device_may_initiate_lpm()
4282 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4284 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4288 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4293 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4297 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) { in usb_device_may_initiate_lpm()
4298 desc = &intf->cur_altsetting->endpoint[j].desc; in usb_device_may_initiate_lpm()
4302 interval = (1 << (desc->bInterval - 1)) * 125; in usb_device_may_initiate_lpm()
4312 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4316 * control transfers to set the hub timeout or enable device-initiated U1/U2
4319 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4320 * hub-initiated U1/U2 will be disabled.
4334 if (!udev->bos) in usb_enable_link_state()
4335 return -EINVAL; in usb_enable_link_state()
4337 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4338 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4346 return -EINVAL; in usb_enable_link_state()
4353 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4357 return -EINVAL; in usb_enable_link_state()
4360 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4368 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4371 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4372 return -EBUSY; in usb_enable_link_state()
4376 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4378 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4383 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4386 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4389 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4391 * still disallow device-initiated U1/U2 entry.
4405 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4407 return -EINVAL; in usb_disable_link_state()
4411 return -EBUSY; in usb_disable_link_state()
4413 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4414 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4421 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4425 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4427 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4433 * Disable hub-initiated and device-initiated U1 and U2 entry.
4437 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4444 if (!udev || !udev->parent || in usb_disable_lpm()
4445 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4446 !udev->lpm_capable || in usb_disable_lpm()
4447 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4450 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4451 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4454 udev->lpm_disable_count++; in usb_disable_lpm()
4455 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4471 udev->lpm_disable_count--; in usb_disable_lpm()
4473 return -EBUSY; in usb_disable_lpm()
4480 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4484 return -EINVAL; in usb_unlocked_disable_lpm()
4486 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4488 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4495 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4508 if (!udev || !udev->parent || in usb_enable_lpm()
4509 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4510 !udev->lpm_capable || in usb_enable_lpm()
4511 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4514 udev->lpm_disable_count--; in usb_enable_lpm()
4515 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4519 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4520 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4523 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4526 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4530 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4532 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4536 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4557 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4562 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4564 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4572 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4575 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4576 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4583 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4585 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4639 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4640 * a connection with a plugged-in cable but will signal the host when the cable
4641 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4645 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4646 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4649 if (!hub->error) { in hub_port_disable()
4650 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4652 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4659 if (port_dev->child && set_state) in hub_port_disable()
4660 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4661 if (ret && ret != -ENODEV) in hub_port_disable()
4662 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4667 * usb_port_disable - disable a usb device's upstream port
4675 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4677 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4680 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4683 * of 100ms at least for debounce and power-settling. The corresponding
4686 * Apparently there are some bluetooth and irda-dongles and a number of
4687 * low-speed devices for which this debounce period may last over a second.
4688 * Not covered by the spec - but easy to deal with.
4691 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4701 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4721 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4730 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4734 return -ETIMEDOUT; in hub_port_debounce()
4742 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4750 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4751 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address()
4753 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4760 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4761 return -EINVAL; in hub_set_address()
4762 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4764 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4765 return -EINVAL; in hub_set_address()
4766 if (hcd->driver->address_device) in hub_set_address()
4767 retval = hcd->driver->address_device(hcd, udev, timeout_ms); in hub_set_address()
4792 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4795 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4799 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4801 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4803 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4810 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4812 if (!hcd->driver->enable_device) in hub_enable_device()
4814 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4816 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4817 return -EINVAL; in hub_enable_device()
4819 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4849 buf->bDescriptorType = buf->bMaxPacketSize0 = 0; in get_bMaxPacketSize0()
4855 switch (buf->bMaxPacketSize0) { in get_bMaxPacketSize0()
4857 if (buf->bDescriptorType == USB_DT_DEVICE) { in get_bMaxPacketSize0()
4858 rc = buf->bMaxPacketSize0; in get_bMaxPacketSize0()
4864 rc = -EPROTO; in get_bMaxPacketSize0()
4872 * attempt, lest we get into a time-out/reset loop. in get_bMaxPacketSize0()
4874 if (rc > 0 || (rc == -ETIMEDOUT && first_time && in get_bMaxPacketSize0()
4875 udev->speed > USB_SPEED_FULL)) in get_bMaxPacketSize0()
4887 * If this is called for an already-existing device (as part of
4895 * @udev->descriptor. For an already existing device, @dev_descr
4896 * must be non-NULL. The device descriptor will be stored there,
4897 * not in @udev->descriptor, because descriptors for registered
4904 struct usb_device *hdev = hub->hdev; in hub_port_init()
4905 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4906 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4909 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4911 int devnum = udev->devnum; in hub_port_init()
4920 return -ENOMEM; in hub_port_init()
4925 if (!hdev->parent) { in hub_port_init()
4927 if (port1 == hdev->bus->otg_port) in hub_port_init()
4928 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4943 retval = -ENODEV; in hub_port_init()
4946 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4947 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4948 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4951 oldspeed = udev->speed; in hub_port_init()
4957 switch (udev->speed) { in hub_port_init()
4960 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4963 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4970 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4973 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4980 speed = usb_speed_string(udev->speed); in hub_port_init()
4987 * platform device is usually a dual-role USB controller device. in hub_port_init()
4989 if (udev->bus->controller->driver) in hub_port_init()
4990 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4992 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4994 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4995 dev_info(&udev->dev, in hub_port_init()
5002 if (hdev->tt) { in hub_port_init()
5003 udev->tt = hdev->tt; in hub_port_init()
5004 udev->ttport = hdev->ttport; in hub_port_init()
5005 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
5006 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
5007 if (!hub->tt.hub) { in hub_port_init()
5008 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
5009 retval = -EINVAL; in hub_port_init()
5012 udev->tt = &hub->tt; in hub_port_init()
5013 udev->ttport = port1; in hub_port_init()
5023 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
5024 * so it may help with some non-standards-compliant devices. in hub_port_init()
5033 retval = -ENODEV; in hub_port_init()
5040 dev_err(&udev->dev, in hub_port_init()
5049 maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5050 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5051 retval = -ENODEV; in hub_port_init()
5058 if (oldspeed != udev->speed) { in hub_port_init()
5059 dev_dbg(&udev->dev, in hub_port_init()
5061 retval = -ENODEV; in hub_port_init()
5065 if (maxp0 != -ENODEV) in hub_port_init()
5066 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
5080 if (retval != -ENODEV) in hub_port_init()
5081 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
5085 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5086 devnum = udev->devnum; in hub_port_init()
5087 dev_info(&udev->dev, in hub_port_init()
5089 (udev->config) ? "reset" : "new", in hub_port_init()
5090 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
5092 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
5094 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
5096 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
5103 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
5104 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
5114 if (retval != -ENODEV) in hub_port_init()
5115 dev_err(&udev->dev, in hub_port_init()
5121 if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5122 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5123 retval = -ENODEV; in hub_port_init()
5127 delay = udev->parent->hub_delay; in hub_port_init()
5128 udev->hub_delay = min_t(u32, delay, in hub_port_init()
5132 dev_dbg(&udev->dev, in hub_port_init()
5149 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5155 if (usb_endpoint_maxp(&udev->ep0.desc) == i) { in hub_port_init()
5157 } else if (((udev->speed == USB_SPEED_FULL || in hub_port_init()
5158 udev->speed == USB_SPEED_HIGH) && in hub_port_init()
5160 (udev->speed >= USB_SPEED_SUPER && i > 0)) { in hub_port_init()
5162 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
5163 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
5165 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
5166 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
5170 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); in hub_port_init()
5171 retval = -EMSGSIZE; in hub_port_init()
5178 if (retval != -ENODEV) in hub_port_init()
5179 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
5184 udev->descriptor = *descr; in hub_port_init()
5195 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
5196 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
5197 dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); in hub_port_init()
5199 retval = -EINVAL; in hub_port_init()
5205 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5208 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5209 udev->lpm_disable_count = 1; in hub_port_init()
5217 if (hcd->driver->update_device) in hub_port_init()
5218 hcd->driver->update_device(hcd, udev); in hub_port_init()
5235 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5245 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5248 if (hub->has_indicators) { in check_highspeed()
5249 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5251 &hub->leds, 0); in check_highspeed()
5260 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5264 if (!hub->limited_power) in hub_power_remaining()
5267 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5268 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
5269 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5270 struct usb_device *udev = port_dev->child; in hub_power_remaining()
5285 if (udev->actconfig) in hub_power_remaining()
5286 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5287 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5291 if (delta > hub->mA_per_port) in hub_power_remaining()
5292 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
5293 delta, hub->mA_per_port); in hub_power_remaining()
5294 remaining -= delta; in hub_power_remaining()
5297 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5298 -remaining); in hub_power_remaining()
5317 if (memcmp(&udev->descriptor, new_device_descriptor, in descriptors_changed()
5321 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5323 if (udev->bos) { in descriptors_changed()
5324 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5325 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5327 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5337 if (udev->serial) in descriptors_changed()
5338 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5341 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5342 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5351 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5352 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5356 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5361 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5363 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5365 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5373 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5376 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5379 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5380 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5392 int status = -ENODEV; in hub_port_connect()
5395 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5396 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5397 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5398 struct usb_device *udev = port_dev->child; in hub_port_connect()
5399 static int unreliable_port = -1; in hub_port_connect()
5404 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5405 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5406 usb_disconnect(&port_dev->child); in hub_port_connect()
5414 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5420 if (status != -ENODEV && in hub_port_connect()
5423 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5435 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5443 && !port_dev->port_owner) in hub_port_connect()
5450 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5459 status = -ENODEV; in hub_port_connect()
5464 mutex_lock(hcd->address0_mutex); in hub_port_connect()
5469 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5471 dev_err(&port_dev->dev, in hub_port_connect()
5473 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5479 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5480 udev->level = hdev->level + 1; in hub_port_connect()
5483 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5484 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5486 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5489 if (udev->devnum <= 0) { in hub_port_connect()
5490 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5494 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5499 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5503 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5506 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5509 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5512 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5513 && udev->bus_mA <= unit_load) { in hub_port_connect()
5519 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5523 dev_err(&udev->dev, in hub_port_connect()
5524 "can't connect bus-powered hub " in hub_port_connect()
5526 if (hub->has_indicators) { in hub_port_connect()
5527 hub->indicator[port1-1] = in hub_port_connect()
5531 &hub->leds, 0); in hub_port_connect()
5533 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5539 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5540 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5557 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5558 status = -ENOTCONN; in hub_port_connect()
5560 port_dev->child = udev; in hub_port_connect()
5570 port_dev->child = NULL; in hub_port_connect()
5574 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5575 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5576 udev->speed); in hub_port_connect()
5585 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5596 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5600 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5603 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5604 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5605 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5612 if (hub->hdev->parent || in hub_port_connect()
5613 !hcd->driver->port_handed_over || in hub_port_connect()
5614 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5615 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5616 dev_err(&port_dev->dev, in hub_port_connect()
5622 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5623 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5624 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5630 * a port connection-change occurs;
5631 * a port enable-change occurs (often caused by EMI);
5638 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5640 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5641 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5643 int status = -ENODEV; in hub_port_connect_change()
5645 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5648 if (hub->has_indicators) { in hub_port_connect_change()
5650 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5655 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5662 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5665 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5672 dev_dbg(&udev->dev, in hub_port_connect_change()
5677 udev->bos)) { in hub_port_connect_change()
5678 dev_dbg(&udev->dev, in hub_port_connect_change()
5686 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5687 udev->persist_enabled) { in hub_port_connect_change()
5699 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5710 /* Handle notifying userspace about hub over-current events */
5717 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5719 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5724 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5733 port_dev->over_current_count); in port_over_current_notify()
5737 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5746 __must_hold(&port_dev->status_lock) in port_event()
5749 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5750 struct usb_device *udev = port_dev->child; in port_event()
5751 struct usb_device *hdev = hub->hdev; in port_event()
5756 connect_change = test_bit(port1, hub->change_bits); in port_event()
5757 clear_bit(port1, hub->event_bits); in port_event()
5758 clear_bit(port1, hub->wakeup_bits); in port_event()
5770 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5781 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5788 port_dev->over_current_count++; in port_event()
5791 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5792 port_dev->over_current_count); in port_event()
5799 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5803 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5808 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5813 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5818 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5824 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5828 if (port_dev->ignore_event && port_dev->early_stop) in port_event()
5846 dev_dbg(&port_dev->dev, "Wait for inactive link disconnect detect\n"); in port_event()
5849 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5850 dev_dbg(&port_dev->dev, "do warm reset, port only\n"); in port_event()
5853 if (!udev && err == -ENOTCONN) in port_event()
5858 dev_dbg(&port_dev->dev, "do warm reset, full device\n"); in port_event()
5884 hdev = hub->hdev; in hub_event()
5885 hub_dev = hub->intfdev; in hub_event()
5888 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5891 hdev->state, hdev->maxchild, in hub_event()
5893 (u16) hub->change_bits[0], in hub_event()
5894 (u16) hub->event_bits[0]); in hub_event()
5899 if (unlikely(hub->disconnected)) in hub_event()
5903 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5904 hub->error = -ENODEV; in hub_event()
5917 if (hub->quiescing) in hub_event()
5920 if (hub->error) { in hub_event()
5921 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5929 hub->nerrors = 0; in hub_event()
5930 hub->error = 0; in hub_event()
5934 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5935 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5937 if (test_bit(i, hub->event_bits) in hub_event()
5938 || test_bit(i, hub->change_bits) in hub_event()
5939 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5946 * (powered-off), we leave it in that state, run in hub_event()
5949 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5950 pm_runtime_barrier(&port_dev->dev); in hub_event()
5954 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5959 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5969 hub->limited_power = 1; in hub_event()
5971 hub->limited_power = 0; in hub_event()
5977 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5983 dev_err(hub_dev, "over-current condition\n"); in hub_event()
6071 return -1; in usb_hub_init()
6076 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
6078 * over to the companion full-speed controller. in usb_hub_init()
6088 return -1; in usb_hub_init()
6100 * individual hub resources. -greg in usb_hub_cleanup()
6106 * hub_hc_release_resources - clear resources used by host controller
6116 * flag udev->reset_resume is set.
6123 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_hc_release_resources()
6127 for (i = 0; i < udev->maxchild; i++) in hub_hc_release_resources()
6128 if (hub->ports[i]->child) in hub_hc_release_resources()
6129 hub_hc_release_resources(hub->ports[i]->child); in hub_hc_release_resources()
6131 if (hcd->driver->reset_device) in hub_hc_release_resources()
6132 hcd->driver->reset_device(hcd, udev); in hub_hc_release_resources()
6136 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
6139 * WARNING - don't use this routine to reset a composite device
6148 * re-connected. All drivers will be unbound, and the device will be
6149 * re-enumerated and probed all over again.
6151 * Return: 0 if the reset succeeded, -ENODEV if the device has been
6171 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
6173 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
6178 int port1 = udev->portnum; in usb_reset_and_verify_device()
6180 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
6181 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
6182 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
6183 udev->state); in usb_reset_and_verify_device()
6184 return -EINVAL; in usb_reset_and_verify_device()
6188 return -EISDIR; in usb_reset_and_verify_device()
6193 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
6197 bos = udev->bos; in usb_reset_and_verify_device()
6198 udev->bos = NULL; in usb_reset_and_verify_device()
6200 if (udev->reset_resume) in usb_reset_and_verify_device()
6203 mutex_lock(hcd->address0_mutex); in usb_reset_and_verify_device()
6207 ret = -ENODEV; in usb_reset_and_verify_device()
6212 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
6215 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
6218 mutex_unlock(hcd->address0_mutex); in usb_reset_and_verify_device()
6225 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
6230 if (!udev->actconfig) in usb_reset_and_verify_device()
6235 * Set-Interface request. Disable host-side endpoints of those in usb_reset_and_verify_device()
6239 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6240 intf = udev->actconfig->interface[i]; in usb_reset_and_verify_device()
6241 if (intf->cur_altsetting->desc.bAlternateSetting == 0) in usb_reset_and_verify_device()
6245 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6246 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
6248 dev_warn(&udev->dev, in usb_reset_and_verify_device()
6251 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6256 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
6259 dev_err(&udev->dev, in usb_reset_and_verify_device()
6261 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
6262 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6265 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6269 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
6271 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
6274 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6275 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
6278 intf = config->interface[i]; in usb_reset_and_verify_device()
6279 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
6280 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
6288 intf->resetting_device = 1; in usb_reset_and_verify_device()
6289 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
6290 desc->bAlternateSetting); in usb_reset_and_verify_device()
6291 intf->resetting_device = 0; in usb_reset_and_verify_device()
6294 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
6296 desc->bInterfaceNumber, in usb_reset_and_verify_device()
6297 desc->bAlternateSetting, in usb_reset_and_verify_device()
6302 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
6303 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
6307 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
6312 udev->bos = bos; in usb_reset_and_verify_device()
6317 udev->bos = bos; in usb_reset_and_verify_device()
6319 return -ENODEV; in usb_reset_and_verify_device()
6323 * usb_reset_device - warn interface drivers and perform a USB port reset
6333 * being unbound or re-bound during the ongoing reset its disconnect()
6335 * routine returns -EINPROGRESS.
6354 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6355 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6357 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6358 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6359 udev->state); in usb_reset_device()
6360 return -EINVAL; in usb_reset_device()
6363 if (!udev->parent) { in usb_reset_device()
6364 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
6365 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6366 return -EISDIR; in usb_reset_device()
6369 if (udev->reset_in_progress) in usb_reset_device()
6370 return -EINPROGRESS; in usb_reset_device()
6371 udev->reset_in_progress = 1; in usb_reset_device()
6373 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6390 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
6391 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6395 if (cintf->dev.driver) { in usb_reset_device()
6396 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6397 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
6398 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
6399 else if (cintf->condition == in usb_reset_device()
6413 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
6414 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6416 int rebind = cintf->needs_binding; in usb_reset_device()
6418 if (!rebind && cintf->dev.driver) { in usb_reset_device()
6419 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6420 if (drv->post_reset) in usb_reset_device()
6421 rebind = (drv->post_reset)(cintf); in usb_reset_device()
6422 else if (cintf->condition == in usb_reset_device()
6426 cintf->needs_binding = 1; in usb_reset_device()
6437 udev->reset_in_progress = 0; in usb_reset_device()
6444 * usb_queue_reset_device - Reset a USB device from an atomic context
6457 * - Scheduling two resets at the same time from two different drivers
6460 * handles ->pre_reset(), the second reset might happen or not.
6462 * - If the reset is delayed so long that the interface is unbound from
6465 * - This function can be called during .probe(). It can also be called
6468 * .disconnect(), call usb_reset_device() directly -- but watch out
6473 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6479 * usb_hub_find_child - Get the pointer of child device
6489 * child's usb_device pointer if non-NULL.
6496 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6498 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6513 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6514 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6516 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6520 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6521 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6522 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6527 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6529 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6530 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6532 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6537 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6543 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6549 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6564 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()