Lines Matching +full:debounce +full:- +full:enter

1 // SPDX-License-Identifier: GPL-2.0
69 /* Protect struct usb_device->state and ->children members
70 * Note: Both are also protected by ->dev.sem, except that ->state can
78 /* synchronize hub-port add/remove and peering operations */
88 * 10 seconds to send reply for the initial 64-byte descriptor request.
90 /* define initial 64-byte descriptor request timeout in milliseconds */
94 "initial 64-byte descriptor request timeout in milliseconds "
95 "(default 5000 - 5.0 seconds)");
139 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
141 if (hub_is_superspeed(hub->hdev)) in portspeed()
154 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
156 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
162 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
166 if (!udev->bos) in usb_device_supports_lpm()
172 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
173 if (udev->bos->ext_cap && in usb_device_supports_lpm()
175 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
185 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
186 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
190 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
191 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
192 if (udev->parent) in usb_device_supports_lpm()
193 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
195 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
199 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
225 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
227 hub->descriptor->u.ss.bHubHdrDecLat * 100; in usb_set_lpm_mel()
235 total_mel += (__le16_to_cpu(hub->descriptor->u.ss.wHubDelay) + in usb_set_lpm_mel()
246 if (!hub->hdev->parent) in usb_set_lpm_mel()
249 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
283 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
286 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
290 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
292 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
296 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
301 * - t1: device PEL
302 * - t2: time for the ERDY to make it from the device to the host.
303 * - t3: a host-specific delay to process the ERDY.
304 * - t4: time for the packet to make it from the host to the device.
318 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
320 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
321 parent = parent->parent) in usb_set_lpm_sel()
323 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
325 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
330 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
342 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
346 if (!udev->bos) in usb_set_lpm_parameters()
349 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
356 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
357 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
358 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
359 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
361 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
362 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
364 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
365 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
377 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
386 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
387 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
391 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
395 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
396 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
400 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
401 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
429 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
431 return -EMSGSIZE; in get_hub_descriptor()
435 return -EINVAL; in get_hub_descriptor()
484 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
489 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
492 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
494 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
504 struct usb_device *hdev = hub->hdev; in led_work()
507 int cursor = -1; in led_work()
509 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
512 for (i = 0; i < hdev->maxchild; i++) { in led_work()
515 /* 30%-50% duty cycle */ in led_work()
517 switch (hub->indicator[i]) { in led_work()
557 hub->indicator[i] = mode; in led_work()
561 cursor %= hdev->maxchild; in led_work()
563 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
568 &hub->leds, LED_CYCLE_PERIOD); in led_work()
581 int i, status = -ETIMEDOUT; in get_hub_status()
584 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
599 int i, status = -ETIMEDOUT; in get_port_status()
602 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
619 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
620 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
622 if (ret != -ENODEV) in hub_ext_port_status()
623 dev_err(hub->intfdev, in hub_ext_port_status()
626 ret = -EIO; in hub_ext_port_status()
628 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
629 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
632 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
635 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
651 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
653 if (hub->quiescing) { in hub_resubmit_irq_urb()
654 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
658 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
659 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
660 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
661 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
662 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
665 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
680 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
691 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
695 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
730 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
731 if (port_dev && port_dev->child) in usb_wakeup_notification()
732 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
734 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
743 struct usb_hub *hub = urb->context; in hub_irq()
744 int status = urb->status; in hub_irq()
749 case -ENOENT: /* synchronous unlink */ in hub_irq()
750 case -ECONNRESET: /* async unlink */ in hub_irq()
751 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
756 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
757 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
759 hub->error = status; in hub_irq()
765 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
766 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
768 hub->event_bits[0] = bits; in hub_irq()
772 hub->nerrors = 0; in hub_irq()
811 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
812 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
815 struct usb_device *hdev = hub->hdev; in hub_tt_work()
819 next = hub->tt.clear_list.next; in hub_tt_work()
821 list_del(&clear->clear_list); in hub_tt_work()
824 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
825 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
826 if (status && status != -ENODEV) in hub_tt_work()
827 dev_err(&hdev->dev, in hub_tt_work()
829 clear->tt, clear->devinfo, status); in hub_tt_work()
832 drv = clear->hcd->driver; in hub_tt_work()
833 if (drv->clear_tt_buffer_complete) in hub_tt_work()
834 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
837 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
839 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
843 * usb_hub_set_port_power - control hub port's power state
868 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
870 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
875 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
890 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
891 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
892 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
902 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
904 return -ENOMEM; in usb_hub_clear_tt_buffer()
908 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
909 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
910 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
911 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
915 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
918 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
919 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
922 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
923 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
924 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
925 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
936 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
941 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
943 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
944 "non-switchable hub\n"); in hub_power_on()
945 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
946 if (test_bit(port1, hub->power_bits)) in hub_power_on()
947 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
949 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
960 mutex_lock(&hub->status_mutex); in hub_hub_status()
961 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
963 if (ret != -ENODEV) in hub_hub_status()
964 dev_err(hub->intfdev, in hub_hub_status()
967 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
968 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
971 mutex_unlock(&hub->status_mutex); in hub_hub_status()
978 return set_port_feature(hub->hdev, in hub_set_port_link_state()
984 * Disable a port and mark a logical connect-change event, so that some
986 * and will re-enumerate if there actually is a device attached.
990 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
994 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
995 * - SRP saves power that way in hub_port_logical_disconnect()
996 * - ... new call, TBD ... in hub_port_logical_disconnect()
997 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
1002 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
1007 * usb_remove_device - disable a device's port on its parent hub
1024 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1025 return -EINVAL; in usb_remove_device()
1026 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1027 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
1033 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1034 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1049 struct usb_device *hdev = hub->hdev; in hub_activate()
1059 device_lock(&hdev->dev); in hub_activate()
1062 if (hub->disconnected) in hub_activate()
1081 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1084 hdev->level - 1, 0, NULL, 0, in hub_activate()
1087 dev_err(hub->intfdev, in hub_activate()
1092 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1093 * and the implementation looks like a home-brewed sort of in hub_activate()
1107 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1109 &hub->init_work, in hub_activate()
1114 to_usb_interface(hub->intfdev)); in hub_activate()
1121 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1122 if (hcd->driver->update_hub_device) { in hub_activate()
1123 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1124 &hub->tt, GFP_NOIO); in hub_activate()
1126 dev_err(hub->intfdev, in hub_activate()
1128 dev_err(hub->intfdev, in hub_activate()
1137 } else if (hub_is_superspeed(hub->hdev)) in hub_activate()
1143 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1146 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1147 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1148 struct usb_device *udev = port_dev->child; in hub_activate()
1157 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1170 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1183 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1186 set_bit(port1, hub->event_bits); in hub_activate()
1189 * Add debounce if USB3 link is in polling/link training state. in hub_activate()
1198 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1201 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1206 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1211 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1215 hub_is_superspeed(hub->hdev)) { in hub_activate()
1217 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1225 clear_bit(port1, hub->removed_bits); in hub_activate()
1227 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1238 set_bit(port1, hub->change_bits); in hub_activate()
1250 * bit on device-initiated resume. in hub_activate()
1252 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1254 set_bit(port1, hub->event_bits); in hub_activate()
1256 } else if (udev->persist_enabled) { in hub_activate()
1258 udev->reset_resume = 1; in hub_activate()
1263 if (test_bit(port1, hub->power_bits)) in hub_activate()
1264 set_bit(port1, hub->change_bits); in hub_activate()
1269 set_bit(port1, hub->change_bits); in hub_activate()
1273 /* If no port-status-change flags were set, we don't need any in hub_activate()
1274 * debouncing. If flags were set we can try to debounce the in hub_activate()
1278 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1286 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1288 &hub->init_work, in hub_activate()
1290 device_unlock(&hdev->dev); in hub_activate()
1297 hub->quiescing = 0; in hub_activate()
1299 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1301 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1302 if (hub->has_indicators && blinkenlights) in hub_activate()
1304 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1312 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1313 device_unlock(&hdev->dev); in hub_activate()
1340 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1344 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1345 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1346 hub->quiescing = 1; in hub_quiesce()
1347 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1351 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1352 if (hub->ports[i]->child) in hub_quiesce()
1353 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1358 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1359 usb_kill_urb(hub->urb); in hub_quiesce()
1360 if (hub->has_indicators) in hub_quiesce()
1361 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1362 if (hub->tt.hub) in hub_quiesce()
1363 flush_work(&hub->tt.clear_work); in hub_quiesce()
1370 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1371 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1380 hub->in_reset = 1; in hub_pre_reset()
1390 hub->in_reset = 0; in hub_post_reset()
1400 struct usb_device *hdev = hub->hdev; in hub_configure()
1401 struct device *hub_dev = hub->intfdev; in hub_configure()
1411 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1412 if (!hub->buffer) { in hub_configure()
1413 ret = -ENOMEM; in hub_configure()
1417 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1418 if (!hub->status) { in hub_configure()
1419 ret = -ENOMEM; in hub_configure()
1422 mutex_init(&hub->status_mutex); in hub_configure()
1424 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1425 if (!hub->descriptor) { in hub_configure()
1426 ret = -ENOMEM; in hub_configure()
1431 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1432 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1434 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1444 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1446 ret = -ENODEV; in hub_configure()
1448 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1450 ret = -ENODEV; in hub_configure()
1459 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure()
1461 if (hdev->parent) in hub_configure()
1462 delay += hdev->parent->hub_delay; in hub_configure()
1465 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1468 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1472 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1473 if (!hub->ports) { in hub_configure()
1474 ret = -ENOMEM; in hub_configure()
1478 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1493 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1516 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1519 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1523 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1527 spin_lock_init(&hub->tt.lock); in hub_configure()
1528 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1529 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1530 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1535 hub->tt.hub = hdev; in hub_configure()
1541 hub->tt.multi = 1; in hub_configure()
1545 hub->tt.hub = hdev; in hub_configure()
1552 hdev->descriptor.bDeviceProtocol); in hub_configure()
1559 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1560 hub->tt.think_time = 666; in hub_configure()
1563 8, hub->tt.think_time); in hub_configure()
1567 hub->tt.think_time = 666 * 2; in hub_configure()
1570 16, hub->tt.think_time); in hub_configure()
1573 hub->tt.think_time = 666 * 3; in hub_configure()
1576 24, hub->tt.think_time); in hub_configure()
1579 hub->tt.think_time = 666 * 4; in hub_configure()
1582 32, hub->tt.think_time); in hub_configure()
1586 /* probe() zeroes hub->indicator[] */ in hub_configure()
1588 hub->has_indicators = 1; in hub_configure()
1593 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1595 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1596 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1603 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1604 if (hdev == hdev->bus->root_hub) { in hub_configure()
1605 if (hcd->power_budget > 0) in hub_configure()
1606 hdev->bus_mA = hcd->power_budget; in hub_configure()
1608 hdev->bus_mA = full_load * maxchild; in hub_configure()
1609 if (hdev->bus_mA >= full_load) in hub_configure()
1610 hub->mA_per_port = full_load; in hub_configure()
1612 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1613 hub->limited_power = 1; in hub_configure()
1616 int remaining = hdev->bus_mA - in hub_configure()
1617 hub->descriptor->bHubContrCurrent; in hub_configure()
1620 hub->descriptor->bHubContrCurrent); in hub_configure()
1621 hub->limited_power = 1; in hub_configure()
1627 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1629 } else { /* Self-powered external hub */ in hub_configure()
1630 /* FIXME: What about battery-powered external hubs that in hub_configure()
1632 hub->mA_per_port = full_load; in hub_configure()
1634 if (hub->mA_per_port < full_load) in hub_configure()
1636 hub->mA_per_port); in hub_configure()
1645 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1651 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1660 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1663 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1664 maxp = sizeof(*hub->buffer); in hub_configure()
1666 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1667 if (!hub->urb) { in hub_configure()
1668 ret = -ENOMEM; in hub_configure()
1672 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1673 hub, endpoint->bInterval); in hub_configure()
1676 if (hub->has_indicators && blinkenlights) in hub_configure()
1677 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1683 dev_err(hub->intfdev, in hub_configure()
1688 hdev->maxchild = i; in hub_configure()
1689 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1690 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1692 pm_runtime_put(&port_dev->dev); in hub_configure()
1702 if (hcd->driver->update_hub_device) { in hub_configure()
1703 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1704 &hub->tt, GFP_KERNEL); in hub_configure()
1711 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1727 usb_put_dev(hub->hdev); in hub_release()
1728 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1734 kref_get(&hub->kref); in hub_get()
1739 kref_put(&hub->kref, hub_release); in hub_put()
1754 hub->disconnected = 1; in hub_disconnect()
1757 hub->error = 0; in hub_disconnect()
1764 port1 = hdev->maxchild; in hub_disconnect()
1765 hdev->maxchild = 0; in hub_disconnect()
1769 for (; port1 > 0; --port1) in hub_disconnect()
1774 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1775 highspeed_hubs--; in hub_disconnect()
1777 usb_free_urb(hub->urb); in hub_disconnect()
1778 kfree(hub->ports); in hub_disconnect()
1779 kfree(hub->descriptor); in hub_disconnect()
1780 kfree(hub->status); in hub_disconnect()
1781 kfree(hub->buffer); in hub_disconnect()
1783 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1785 if (hub->quirk_disable_autosuspend) in hub_disconnect()
1788 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs); in hub_disconnect()
1797 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1798 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1801 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1802 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1806 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1818 desc = intf->cur_altsetting; in hub_probe()
1826 if (hdev->descriptor.bNumConfigurations > 1 || in hub_probe()
1827 hdev->actconfig->desc.bNumInterfaces > 1) { in hub_probe()
1828 dev_err(&intf->dev, "Invalid hub with more than one config or interface\n"); in hub_probe()
1829 return -EINVAL; in hub_probe()
1836 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1841 * - The patch might cause one or more auto supend/resume for in hub_probe()
1857 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1861 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1865 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1866 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1869 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1870 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1878 if (hdev->parent) { /* normal device */ in hub_probe()
1881 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1883 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1887 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1888 dev_err(&intf->dev, in hub_probe()
1890 return -E2BIG; in hub_probe()
1894 if (hdev->parent) { in hub_probe()
1895 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1896 return -ENODEV; in hub_probe()
1901 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1902 return -EIO; in hub_probe()
1906 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1910 return -ENOMEM; in hub_probe()
1912 kref_init(&hub->kref); in hub_probe()
1913 hub->intfdev = &intf->dev; in hub_probe()
1914 hub->hdev = hdev; in hub_probe()
1915 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1916 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1917 INIT_WORK(&hub->events, hub_event); in hub_probe()
1918 INIT_LIST_HEAD(&hub->onboard_hub_devs); in hub_probe()
1919 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1920 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1925 intf->needs_remote_wakeup = 1; in hub_probe()
1926 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1928 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1931 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1932 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1934 if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) { in hub_probe()
1935 hub->quirk_disable_autosuspend = 1; in hub_probe()
1939 if ((id->driver_info & HUB_QUIRK_REDUCE_FRAME_INTR_BINTERVAL) && in hub_probe()
1940 desc->endpoint[0].desc.bInterval > USB_REDUCE_FRAME_INTR_BINTERVAL) { in hub_probe()
1941 desc->endpoint[0].desc.bInterval = in hub_probe()
1947 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) { in hub_probe()
1948 onboard_hub_create_pdevs(hdev, &hub->onboard_hub_devs); in hub_probe()
1954 return -ENODEV; in hub_probe()
1970 if (hdev->devnum <= 0) in hub_ioctl()
1971 info->nports = 0; in hub_ioctl()
1973 info->nports = hdev->maxchild; in hub_ioctl()
1974 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1975 if (hub->ports[i]->child == NULL) in hub_ioctl()
1976 info->port[i] = 0; in hub_ioctl()
1978 info->port[i] = in hub_ioctl()
1979 hub->ports[i]->child->devnum; in hub_ioctl()
1984 return info->nports + 1; in hub_ioctl()
1988 return -ENOSYS; in hub_ioctl()
2001 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
2002 return -ENODEV; in find_port_owner()
2003 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
2004 return -EINVAL; in find_port_owner()
2009 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
2024 return -EBUSY; in usb_hub_claim_port()
2040 return -ENOENT; in usb_hub_release_port()
2051 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
2052 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
2053 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
2063 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2065 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2066 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2074 if (udev->parent) { in update_port_device_state()
2075 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2085 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2086 WRITE_ONCE(port_dev->state, udev->state); in update_port_device_state()
2087 sysfs_notify_dirent(port_dev->state_kn); in update_port_device_state()
2097 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2098 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
2099 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
2101 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2102 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2103 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2108 * usb_set_device_state - change a device's current state (usbcore, hcds)
2112 * udev->state is _not_ fully protected by the device lock. Although
2123 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2124 * Otherwise udev->state is set to new_state, and if new_state is
2132 int wakeup = -1; in usb_set_device_state()
2135 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2139 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2142 if (udev->parent) { in usb_set_device_state()
2143 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2147 wakeup = (udev->quirks & in usb_set_device_state()
2149 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2154 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2156 udev->active_duration -= jiffies; in usb_set_device_state()
2158 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2159 udev->active_duration += jiffies; in usb_set_device_state()
2160 udev->state = new_state; in usb_set_device_state()
2166 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2173 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2174 * USB-2.0 buses they are also used as device addresses, however on
2175 * USB-3.0 buses the address is assigned by the controller hardware
2186 struct usb_bus *bus = udev->bus; in choose_devnum()
2189 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2191 /* Try to allocate the next devnum beginning at bus->devnum_next. */ in choose_devnum()
2192 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2193 bus->devnum_next); in choose_devnum()
2195 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, 1); in choose_devnum()
2196 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2198 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2199 udev->devnum = devnum; in choose_devnum()
2201 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2206 if (udev->devnum > 0) { in release_devnum()
2207 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2208 udev->devnum = -1; in release_devnum()
2214 udev->devnum = devnum; in update_devnum()
2215 if (!udev->devaddr) in update_devnum()
2216 udev->devaddr = (u8)devnum; in update_devnum()
2221 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2224 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2225 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2234 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2235 if (hub->ports[i]->child) in hub_disconnect_children()
2236 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2241 * usb_disconnect - disconnect a device (usbcore-internal)
2269 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2270 udev->devnum); in usb_disconnect()
2276 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2286 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2290 if (udev->parent) { in usb_disconnect()
2291 port1 = udev->portnum; in usb_disconnect()
2292 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2293 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2295 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2296 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2299 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2302 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2303 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2306 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2310 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2313 device_del(&udev->dev); in usb_disconnect()
2325 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2326 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2330 put_device(&udev->dev); in usb_disconnect()
2338 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2343 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2345 dev_info(&udev->dev, in announce_device()
2347 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2348 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2350 dev_info(&udev->dev, in announce_device()
2352 udev->descriptor.iManufacturer, in announce_device()
2353 udev->descriptor.iProduct, in announce_device()
2354 udev->descriptor.iSerialNumber); in announce_device()
2355 show_string(udev, "Product", udev->product); in announce_device()
2356 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2357 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2365 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2368 * Finish enumeration for On-The-Go devices
2378 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2382 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2383 && udev->config in usb_enumerate_device_otg()
2384 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2386 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2387 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2390 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2391 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2393 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2396 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2397 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2400 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2401 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2413 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2415 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2417 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2425 if (bus->otg_port != 0) { in usb_enumerate_device_otg()
2434 dev_err(&udev->dev, in usb_enumerate_device_otg()
2446 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2449 * This is only called by usb_new_device() -- all comments that apply there
2461 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2463 if (udev->config == NULL) { in usb_enumerate_device()
2466 if (err != -ENODEV) in usb_enumerate_device()
2467 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2474 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2475 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2476 udev->descriptor.iManufacturer); in usb_enumerate_device()
2477 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2483 if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && in usb_enumerate_device()
2488 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2489 || udev->bus->is_b_host)) { in usb_enumerate_device()
2492 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2494 return -ENOTSUPP; in usb_enumerate_device()
2504 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2506 u8 port = udev->portnum; in set_usb_port_removable()
2510 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2515 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2521 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2523 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2527 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2537 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2543 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2547 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2552 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2554 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2559 * usb_new_device - perform initial device setup (usbcore-internal)
2572 * Only the hub driver or root-hub registrar should ever call this.
2583 if (udev->parent) { in usb_new_device()
2584 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2588 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2591 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2592 pm_runtime_set_active(&udev->dev); in usb_new_device()
2593 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2594 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2595 pm_runtime_enable(&udev->dev); in usb_new_device()
2605 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2606 udev->devnum, udev->bus->busnum, in usb_new_device()
2607 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2608 /* export the usbdev device-node for libusb */ in usb_new_device()
2609 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2610 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2615 if (udev->serial) in usb_new_device()
2616 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2617 if (udev->product) in usb_new_device()
2618 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2619 if (udev->manufacturer) in usb_new_device()
2620 add_device_randomness(udev->manufacturer, in usb_new_device()
2621 strlen(udev->manufacturer)); in usb_new_device()
2623 device_enable_async_suspend(&udev->dev); in usb_new_device()
2625 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2629 * for configuring the device and invoking the add-device in usb_new_device()
2632 err = device_add(&udev->dev); in usb_new_device()
2634 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2639 if (udev->parent) { in usb_new_device()
2640 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2641 int port1 = udev->portnum; in usb_new_device()
2642 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2644 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2645 &port_dev->dev.kobj, "port"); in usb_new_device()
2649 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2650 &udev->dev.kobj, "device"); in usb_new_device()
2652 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2656 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2657 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2660 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2662 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2666 device_del(&udev->dev); in usb_new_device()
2669 pm_runtime_disable(&udev->dev); in usb_new_device()
2670 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2676 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2690 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2693 usb_dev->authorized = 0; in usb_deauthorize_device()
2694 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2707 if (usb_dev->authorized == 1) in usb_authorize_device()
2712 dev_err(&usb_dev->dev, in usb_authorize_device()
2717 usb_dev->authorized = 1; in usb_authorize_device()
2725 dev_err(&usb_dev->dev, in usb_authorize_device()
2731 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2741 * get_port_ssp_rate - Match the extended port status to SSP rate
2759 if (!hdev->bos) in get_port_ssp_rate()
2762 ssp_cap = hdev->bos->ssp_cap; in get_port_ssp_rate()
2769 ssac = le32_to_cpu(ssp_cap->bmAttributes) & in get_port_ssp_rate()
2775 attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in get_port_ssp_rate()
2846 (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) || in use_new_scheme()
2856 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2877 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2880 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2903 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2918 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2919 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2929 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2935 return -EBUSY; in hub_port_wait_reset()
2938 return -ENOTCONN; in hub_port_wait_reset()
2942 return -ENOTCONN; in hub_port_wait_reset()
2946 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
2948 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2950 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2952 return -EAGAIN; in hub_port_wait_reset()
2956 return -EBUSY; in hub_port_wait_reset()
2961 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2963 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2964 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2965 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2967 udev->rx_lanes = 1; in hub_port_wait_reset()
2968 udev->tx_lanes = 1; in hub_port_wait_reset()
2969 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
2971 if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
2972 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2973 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2974 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2976 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2978 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2980 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2990 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2993 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2995 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2997 return -EINVAL; in hub_port_reset()
3014 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
3018 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
3021 if (status == -ENODEV) { in hub_port_reset()
3024 dev_err(&port_dev->dev, in hub_port_reset()
3030 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
3031 dev_dbg(hub->intfdev, in hub_port_reset()
3040 if (status == 0 || status == -ENOTCONN || status == -ENODEV || in hub_port_reset()
3041 (status == -EBUSY && i == PORT_RESET_TRIES - 1)) { in hub_port_reset()
3042 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3045 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3048 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3050 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3054 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
3059 * state, re-issue the warm reset. in hub_port_reset()
3074 dev_dbg(&port_dev->dev, in hub_port_reset()
3080 dev_dbg(&port_dev->dev, in hub_port_reset()
3086 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
3090 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
3097 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
3104 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3110 if (hcd->driver->reset_device) in hub_port_reset()
3111 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3120 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
3127 * hub_port_stop_enumerate - stop USB enumeration or ignore port events
3146 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_stop_enumerate()
3148 if (port_dev->early_stop) { in hub_port_stop_enumerate()
3149 if (port_dev->ignore_event) in hub_port_stop_enumerate()
3161 port_dev->ignore_event = 1; in hub_port_stop_enumerate()
3163 port_dev->ignore_event = 0; in hub_port_stop_enumerate()
3165 return port_dev->ignore_event; in hub_port_stop_enumerate()
3173 if (hub_is_superspeed(hub->hdev)) { in usb_port_is_power_on()
3185 __acquires(&port_dev->status_lock) in usb_lock_port()
3187 mutex_lock(&port_dev->status_lock); in usb_lock_port()
3188 __acquire(&port_dev->status_lock); in usb_lock_port()
3192 __releases(&port_dev->status_lock) in usb_unlock_port()
3194 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3195 __release(&port_dev->status_lock); in usb_unlock_port()
3205 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3218 * is ready for a reset-resume, or should be disconnected.
3224 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3229 if (status == 0 && udev->reset_resume in check_port_resume_type()
3237 status = -ENODEV; in check_port_resume_type()
3239 if (retries--) { in check_port_resume_type()
3245 status = -ENODEV; in check_port_resume_type()
3249 * so try a reset-resume instead. in check_port_resume_type()
3251 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3252 if (udev->persist_enabled) in check_port_resume_type()
3253 udev->reset_resume = 1; in check_port_resume_type()
3255 status = -ENODEV; in check_port_resume_type()
3259 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3261 } else if (udev->reset_resume) { in check_port_resume_type()
3263 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3265 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3268 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3272 * Whatever made this reset-resume necessary may have in check_port_resume_type()
3273 * turned on the port1 bit in hub->change_bits. But after in check_port_resume_type()
3274 * a successful reset-resume we want the bit to be clear; in check_port_resume_type()
3276 * following the reset-resume. in check_port_resume_type()
3278 clear_bit(port1, hub->change_bits); in check_port_resume_type()
3286 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3289 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3296 if (!udev->actconfig) in usb_disable_ltm()
3308 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3311 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3318 if (!udev->actconfig) in usb_enable_ltm()
3329 * usb_enable_remote_wakeup - enable remote wakeup for a device
3332 * For USB-2 devices: Set the device's remote wakeup feature.
3334 * For USB-3 devices: Assume there's only one function on the device and
3340 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3355 * usb_disable_remote_wakeup - disable remote wakeup for a device
3358 * For USB-2 devices: Clear the device's remote wakeup feature.
3360 * For USB-3 devices: Assume there's only one function on the device and
3366 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3378 /* Count of wakeup-enabled devices at or below udev */
3383 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3384 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3389 * usb_port_suspend - suspend a usb device's upstream port
3412 * between a pair of dual-role devices. That will change roles, such
3413 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3419 * - suspend, resume ... when the VBUS power link stays live
3420 * - suspend, disconnect ... VBUS lost
3423 * normal re-enumeration procedures, starting with enabling VBUS power.
3424 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3428 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3430 * hub is suspended). Nevertheless, we change @udev->state to
3432 * upstream port setting is stored in @udev->port_is_suspended.
3438 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3439 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3440 int port1 = udev->portnum; in usb_port_suspend()
3452 if (udev->do_remote_wakeup) { in usb_port_suspend()
3455 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3467 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3468 status = -ENOMEM; in usb_port_suspend()
3474 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3479 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3489 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3499 if (status == -ETIMEDOUT) { in usb_port_suspend()
3507 dev_dbg(&port_dev->dev, in usb_port_suspend()
3516 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3524 if (udev->do_remote_wakeup) in usb_port_suspend()
3533 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3534 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3535 udev->do_remote_wakeup); in usb_port_suspend()
3537 udev->port_is_suspended = 1; in usb_port_suspend()
3545 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3546 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3547 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3549 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3563 * If @udev->reset_resume is set then the device is reset before the
3572 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3573 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3580 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3589 if (udev->reset_resume) { in finish_port_resume()
3592 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3597 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3598 status = -ENODEV; in finish_port_resume()
3611 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3612 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3613 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3614 udev->reset_resume = 1; in finish_port_resume()
3620 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3626 * udev->reset_resume in finish_port_resume()
3628 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3629 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3641 dev_dbg(&udev->dev, in finish_port_resume()
3683 status = -ENODEV; in wait_for_connected()
3690 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3695 * usb_port_resume - re-activate a suspended usb device's upstream port
3696 * @udev: device to re-activate, not a root hub
3699 * This will re-activate the suspended device, increasing power usage
3705 * If @udev->reset_resume is set then this routine won't check that the
3713 * for mass-storage devices containing mounted filesystems, since the
3730 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3731 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3732 int port1 = udev->portnum; in usb_port_resume()
3736 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3737 status = pm_runtime_resume_and_get(&port_dev->dev); in usb_port_resume()
3739 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3747 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3751 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3756 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3759 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3762 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3765 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3766 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3778 udev->port_is_suspended = 0; in usb_port_resume()
3779 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3781 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3785 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3793 if (udev->persist_enabled) in usb_port_resume()
3802 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3822 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3823 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3837 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3839 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3846 hdev = hub->hdev; in hub_handle_remote_wakeup()
3847 udev = port_dev->child; in hub_handle_remote_wakeup()
3854 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3871 ret = -ENODEV; in hub_handle_remote_wakeup()
3874 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3882 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3896 struct usb_device *hdev = hub->hdev; in hub_suspend()
3901 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3903 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3904 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3905 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3906 struct usb_device *udev = port_dev->child; in hub_suspend()
3908 if (udev && udev->can_submit) { in hub_suspend()
3909 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3910 dev_name(&udev->dev)); in hub_suspend()
3912 return -EBUSY; in hub_suspend()
3915 hub->wakeup_enabled_descendants += in hub_suspend()
3919 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3923 return -EBUSY; in hub_suspend()
3924 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3928 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3930 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3940 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3950 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3956 if (hdev->parent) in report_wakeup_requests()
3959 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3960 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3970 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3971 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3973 udev = hub->ports[i]->child; in report_wakeup_requests()
3975 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3985 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
4002 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
4008 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
4015 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
4020 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
4021 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
4034 * device-initiated U1 or U2. This lets the device know the exit latencies from
4050 if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) in usb_req_set_sel()
4054 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
4055 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
4056 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
4057 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
4064 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
4071 dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); in usb_req_set_sel()
4072 return -EINVAL; in usb_req_set_sel()
4082 return -ENOMEM; in usb_req_set_sel()
4084 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
4085 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
4086 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
4087 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
4098 udev->lpm_devinit_allow = 1; in usb_req_set_sel()
4104 * Enable or disable device-initiated U1 or U2 transitions.
4120 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4122 return -EINVAL; in usb_set_device_initiated_lpm()
4125 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4126 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4135 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
4153 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4156 return -EBUSY; in usb_set_device_initiated_lpm()
4175 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4177 return -EINVAL; in usb_set_lpm_timeout()
4182 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4185 return -EINVAL; in usb_set_lpm_timeout()
4188 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4189 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4192 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4195 return -EBUSY; in usb_set_lpm_timeout()
4198 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4200 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4215 if (!udev->lpm_devinit_allow) in usb_device_may_initiate_lpm()
4219 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4221 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4225 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4230 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4234 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) { in usb_device_may_initiate_lpm()
4235 desc = &intf->cur_altsetting->endpoint[j].desc; in usb_device_may_initiate_lpm()
4239 interval = (1 << (desc->bInterval - 1)) * 125; in usb_device_may_initiate_lpm()
4249 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4253 * control transfers to set the hub timeout or enable device-initiated U1/U2
4256 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4257 * hub-initiated U1/U2 will be disabled.
4271 if (!udev->bos) in usb_enable_link_state()
4274 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4275 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4290 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4297 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4305 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4308 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4315 if (udev->actconfig && in usb_enable_link_state()
4323 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4329 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4331 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4334 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4337 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4340 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4342 * still disallow device-initiated U1/U2 entry.
4356 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4358 return -EINVAL; in usb_disable_link_state()
4362 return -EBUSY; in usb_disable_link_state()
4366 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4367 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4372 * is disabled. Hub will disallows link to enter U1/U2 as well, in usb_disable_link_state()
4374 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4378 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4380 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4386 * Disable hub-initiated and device-initiated U1 and U2 entry.
4390 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4396 if (!udev || !udev->parent || in usb_disable_lpm()
4397 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4398 !udev->lpm_capable || in usb_disable_lpm()
4399 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4402 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4403 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4406 udev->lpm_disable_count++; in usb_disable_lpm()
4407 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4420 return -EBUSY; in usb_disable_lpm()
4427 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4431 return -EINVAL; in usb_unlocked_disable_lpm()
4433 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4435 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4442 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4455 if (!udev || !udev->parent || in usb_enable_lpm()
4456 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4457 !udev->lpm_capable || in usb_enable_lpm()
4458 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4461 udev->lpm_disable_count--; in usb_enable_lpm()
4462 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4466 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4467 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4470 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4473 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4477 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4479 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4482 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4490 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4495 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4497 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4505 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4508 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4509 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4516 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4518 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4572 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4573 * a connection with a plugged-in cable but will signal the host when the cable
4574 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4578 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4579 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4582 if (!hub->error) { in hub_port_disable()
4583 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4585 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4592 if (port_dev->child && set_state) in hub_port_disable()
4593 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4594 if (ret && ret != -ENODEV) in hub_port_disable()
4595 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4600 * usb_port_disable - disable a usb device's upstream port
4608 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4610 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4613 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4616 * of 100ms at least for debounce and power-settling. The corresponding
4619 * Apparently there are some bluetooth and irda-dongles and a number of
4620 * low-speed devices for which this debounce period may last over a second.
4621 * Not covered by the spec - but easy to deal with.
4623 * This implementation uses a 1500ms total debounce timeout; if the
4624 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4634 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4654 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4663 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4667 return -ETIMEDOUT; in hub_port_debounce()
4675 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4685 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4686 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_address()
4688 if (hub->hdev->quirks & USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT) in hub_set_address()
4695 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4696 return -EINVAL; in hub_set_address()
4697 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4699 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4700 return -EINVAL; in hub_set_address()
4701 if (hcd->driver->address_device) in hub_set_address()
4702 retval = hcd->driver->address_device(hcd, udev, timeout_ms); in hub_set_address()
4727 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4730 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4734 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4736 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4738 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4745 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4747 if (!hcd->driver->enable_device) in hub_enable_device()
4749 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4751 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4752 return -EINVAL; in hub_enable_device()
4754 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4784 buf->bDescriptorType = buf->bMaxPacketSize0 = 0; in get_bMaxPacketSize0()
4790 switch (buf->bMaxPacketSize0) { in get_bMaxPacketSize0()
4792 if (buf->bDescriptorType == USB_DT_DEVICE) { in get_bMaxPacketSize0()
4793 rc = buf->bMaxPacketSize0; in get_bMaxPacketSize0()
4799 rc = -EPROTO; in get_bMaxPacketSize0()
4807 * attempt, lest we get into a time-out/reset loop. in get_bMaxPacketSize0()
4809 if (rc > 0 || (rc == -ETIMEDOUT && first_time && in get_bMaxPacketSize0()
4810 udev->speed > USB_SPEED_FULL)) in get_bMaxPacketSize0()
4822 * If this is called for an already-existing device (as part of
4830 * @udev->descriptor. For an already existing device, @dev_descr
4831 * must be non-NULL. The device descriptor will be stored there,
4832 * not in @udev->descriptor, because descriptors for registered
4839 struct usb_device *hdev = hub->hdev; in hub_port_init()
4840 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4841 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4844 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4846 int devnum = udev->devnum; in hub_port_init()
4855 return -ENOMEM; in hub_port_init()
4860 if (!hdev->parent) { in hub_port_init()
4862 if (port1 == hdev->bus->otg_port) in hub_port_init()
4863 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4878 retval = -ENODEV; in hub_port_init()
4881 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4882 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4883 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4886 oldspeed = udev->speed; in hub_port_init()
4892 switch (udev->speed) { in hub_port_init()
4895 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4898 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4905 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4908 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4915 speed = usb_speed_string(udev->speed); in hub_port_init()
4922 * platform device is usually a dual-role USB controller device. in hub_port_init()
4924 if (udev->bus->controller->driver) in hub_port_init()
4925 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4927 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4929 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4930 dev_info(&udev->dev, in hub_port_init()
4937 if (hdev->tt) { in hub_port_init()
4938 udev->tt = hdev->tt; in hub_port_init()
4939 udev->ttport = hdev->ttport; in hub_port_init()
4940 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4941 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4942 if (!hub->tt.hub) { in hub_port_init()
4943 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4944 retval = -EINVAL; in hub_port_init()
4947 udev->tt = &hub->tt; in hub_port_init()
4948 udev->ttport = port1; in hub_port_init()
4958 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4959 * so it may help with some non-standards-compliant devices. in hub_port_init()
4968 retval = -ENODEV; in hub_port_init()
4975 dev_err(&udev->dev, in hub_port_init()
4984 maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
4985 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
4986 retval = -ENODEV; in hub_port_init()
4993 if (oldspeed != udev->speed) { in hub_port_init()
4994 dev_dbg(&udev->dev, in hub_port_init()
4996 retval = -ENODEV; in hub_port_init()
5000 if (maxp0 != -ENODEV) in hub_port_init()
5001 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
5015 if (retval != -ENODEV) in hub_port_init()
5016 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
5020 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5021 devnum = udev->devnum; in hub_port_init()
5022 dev_info(&udev->dev, in hub_port_init()
5024 (udev->config) ? "reset" : "new", in hub_port_init()
5025 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
5027 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
5029 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
5031 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
5038 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
5039 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
5049 if (retval != -ENODEV) in hub_port_init()
5050 dev_err(&udev->dev, in hub_port_init()
5056 if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5057 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5058 retval = -ENODEV; in hub_port_init()
5062 delay = udev->parent->hub_delay; in hub_port_init()
5063 udev->hub_delay = min_t(u32, delay, in hub_port_init()
5067 dev_dbg(&udev->dev, in hub_port_init()
5084 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5090 if (usb_endpoint_maxp(&udev->ep0.desc) == i) { in hub_port_init()
5092 } else if (((udev->speed == USB_SPEED_FULL || in hub_port_init()
5093 udev->speed == USB_SPEED_HIGH) && in hub_port_init()
5095 (udev->speed >= USB_SPEED_SUPER && i > 0)) { in hub_port_init()
5097 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
5098 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
5100 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
5101 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
5105 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); in hub_port_init()
5106 retval = -EMSGSIZE; in hub_port_init()
5113 if (retval != -ENODEV) in hub_port_init()
5114 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
5119 udev->descriptor = *descr; in hub_port_init()
5130 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
5131 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
5132 dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); in hub_port_init()
5134 retval = -EINVAL; in hub_port_init()
5140 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5143 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5144 udev->lpm_disable_count = 1; in hub_port_init()
5152 if (hcd->driver->update_device) in hub_port_init()
5153 hcd->driver->update_device(hcd, udev); in hub_port_init()
5170 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5180 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5183 if (hub->has_indicators) { in check_highspeed()
5184 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
5186 &hub->leds, 0); in check_highspeed()
5195 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
5199 if (!hub->limited_power) in hub_power_remaining()
5202 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
5203 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
5204 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
5205 struct usb_device *udev = port_dev->child; in hub_power_remaining()
5220 if (udev->actconfig) in hub_power_remaining()
5221 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5222 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5226 if (delta > hub->mA_per_port) in hub_power_remaining()
5227 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
5228 delta, hub->mA_per_port); in hub_power_remaining()
5229 remaining -= delta; in hub_power_remaining()
5232 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
5233 -remaining); in hub_power_remaining()
5252 if (memcmp(&udev->descriptor, new_device_descriptor, in descriptors_changed()
5256 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5258 if (udev->bos) { in descriptors_changed()
5259 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5260 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5262 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5272 if (udev->serial) in descriptors_changed()
5273 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5276 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5277 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5286 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5287 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5291 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5296 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5298 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5300 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5308 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5311 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5314 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5315 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5327 int status = -ENODEV; in hub_port_connect()
5330 struct usb_device *hdev = hub->hdev; in hub_port_connect()
5331 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
5332 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
5333 struct usb_device *udev = port_dev->child; in hub_port_connect()
5334 static int unreliable_port = -1; in hub_port_connect()
5339 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5340 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5341 usb_disconnect(&port_dev->child); in hub_port_connect()
5349 clear_bit(port1, hub->removed_bits); in hub_port_connect()
5355 if (status != -ENODEV && in hub_port_connect()
5358 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
5370 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
5378 && !port_dev->port_owner) in hub_port_connect()
5385 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5394 status = -ENODEV; in hub_port_connect()
5399 mutex_lock(hcd->address0_mutex); in hub_port_connect()
5404 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5406 dev_err(&port_dev->dev, in hub_port_connect()
5408 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5414 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5415 udev->level = hdev->level + 1; in hub_port_connect()
5418 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5419 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5421 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5424 if (udev->devnum <= 0) { in hub_port_connect()
5425 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5429 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5434 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5438 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5441 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5444 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5447 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5448 && udev->bus_mA <= unit_load) { in hub_port_connect()
5454 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5458 dev_err(&udev->dev, in hub_port_connect()
5459 "can't connect bus-powered hub " in hub_port_connect()
5461 if (hub->has_indicators) { in hub_port_connect()
5462 hub->indicator[port1-1] = in hub_port_connect()
5466 &hub->leds, 0); in hub_port_connect()
5468 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5474 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5475 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5492 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5493 status = -ENOTCONN; in hub_port_connect()
5495 port_dev->child = udev; in hub_port_connect()
5505 port_dev->child = NULL; in hub_port_connect()
5509 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5510 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5511 udev->speed); in hub_port_connect()
5520 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5531 mutex_unlock(hcd->address0_mutex); in hub_port_connect()
5535 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5538 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5539 if (i == (PORT_INIT_TRIES - 1) / 2) { in hub_port_connect()
5540 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5547 if (hub->hdev->parent || in hub_port_connect()
5548 !hcd->driver->port_handed_over || in hub_port_connect()
5549 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5550 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5551 dev_err(&port_dev->dev, in hub_port_connect()
5557 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5558 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5559 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5565 * a port connection-change occurs;
5566 * a port enable-change occurs (often caused by EMI);
5573 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5575 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5576 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5578 int status = -ENODEV; in hub_port_connect_change()
5580 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5583 if (hub->has_indicators) { in hub_port_connect_change()
5585 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5589 /* during HNP, don't repeat the debounce */ in hub_port_connect_change()
5590 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5597 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5600 * USB-3 connections are initialized automatically by in hub_port_connect_change()
5607 dev_dbg(&udev->dev, in hub_port_connect_change()
5612 udev->bos)) { in hub_port_connect_change()
5613 dev_dbg(&udev->dev, in hub_port_connect_change()
5621 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5622 udev->persist_enabled) { in hub_port_connect_change()
5634 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5645 /* Handle notifying userspace about hub over-current events */
5652 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5654 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5659 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5668 port_dev->over_current_count); in port_over_current_notify()
5672 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5681 __must_hold(&port_dev->status_lock) in port_event()
5684 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5685 struct usb_device *udev = port_dev->child; in port_event()
5686 struct usb_device *hdev = hub->hdev; in port_event()
5690 connect_change = test_bit(port1, hub->change_bits); in port_event()
5691 clear_bit(port1, hub->event_bits); in port_event()
5692 clear_bit(port1, hub->wakeup_bits); in port_event()
5704 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5715 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5722 port_dev->over_current_count++; in port_event()
5725 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5726 port_dev->over_current_count); in port_event()
5733 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5737 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5742 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5747 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5752 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5758 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5762 if (port_dev->ignore_event && port_dev->early_stop) in port_event()
5780 dev_dbg(&port_dev->dev, "Wait for inactive link disconnect detect\n"); in port_event()
5783 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5784 dev_dbg(&port_dev->dev, "do warm reset, port only\n"); in port_event()
5789 dev_dbg(&port_dev->dev, "do warm reset, full device\n"); in port_event()
5815 hdev = hub->hdev; in hub_event()
5816 hub_dev = hub->intfdev; in hub_event()
5819 kcov_remote_start_usb((u64)hdev->bus->busnum); in hub_event()
5822 hdev->state, hdev->maxchild, in hub_event()
5824 (u16) hub->change_bits[0], in hub_event()
5825 (u16) hub->event_bits[0]); in hub_event()
5830 if (unlikely(hub->disconnected)) in hub_event()
5834 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5835 hub->error = -ENODEV; in hub_event()
5848 if (hub->quiescing) in hub_event()
5851 if (hub->error) { in hub_event()
5852 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5860 hub->nerrors = 0; in hub_event()
5861 hub->error = 0; in hub_event()
5865 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5866 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5868 if (test_bit(i, hub->event_bits) in hub_event()
5869 || test_bit(i, hub->change_bits) in hub_event()
5870 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5877 * (powered-off), we leave it in that state, run in hub_event()
5880 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5881 pm_runtime_barrier(&port_dev->dev); in hub_event()
5885 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5890 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5900 hub->limited_power = 1; in hub_event()
5902 hub->limited_power = 0; in hub_event()
5908 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5914 dev_err(hub_dev, "over-current condition\n"); in hub_event()
6002 return -1; in usb_hub_init()
6007 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
6009 * over to the companion full-speed controller. in usb_hub_init()
6019 return -1; in usb_hub_init()
6031 * individual hub resources. -greg in usb_hub_cleanup()
6037 * hub_hc_release_resources - clear resources used by host controller
6047 * flag udev->reset_resume is set.
6054 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_hc_release_resources()
6058 for (i = 0; i < udev->maxchild; i++) in hub_hc_release_resources()
6059 if (hub->ports[i]->child) in hub_hc_release_resources()
6060 hub_hc_release_resources(hub->ports[i]->child); in hub_hc_release_resources()
6062 if (hcd->driver->reset_device) in hub_hc_release_resources()
6063 hcd->driver->reset_device(hcd, udev); in hub_hc_release_resources()
6067 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
6070 * WARNING - don't use this routine to reset a composite device
6079 * re-connected. All drivers will be unbound, and the device will be
6080 * re-enumerated and probed all over again.
6082 * Return: 0 if the reset succeeded, -ENODEV if the device has been
6102 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
6104 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
6108 int port1 = udev->portnum; in usb_reset_and_verify_device()
6110 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
6111 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
6112 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
6113 udev->state); in usb_reset_and_verify_device()
6114 return -EINVAL; in usb_reset_and_verify_device()
6118 return -EISDIR; in usb_reset_and_verify_device()
6123 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
6127 bos = udev->bos; in usb_reset_and_verify_device()
6128 udev->bos = NULL; in usb_reset_and_verify_device()
6130 if (udev->reset_resume) in usb_reset_and_verify_device()
6133 mutex_lock(hcd->address0_mutex); in usb_reset_and_verify_device()
6137 ret = -ENODEV; in usb_reset_and_verify_device()
6142 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
6145 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
6148 mutex_unlock(hcd->address0_mutex); in usb_reset_and_verify_device()
6155 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
6160 if (!udev->actconfig) in usb_reset_and_verify_device()
6163 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6164 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
6166 dev_warn(&udev->dev, in usb_reset_and_verify_device()
6169 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6174 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
6177 dev_err(&udev->dev, in usb_reset_and_verify_device()
6179 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
6180 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6183 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
6187 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
6189 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
6192 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6193 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
6194 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
6197 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
6198 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
6207 intf->resetting_device = 1; in usb_reset_and_verify_device()
6208 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
6209 desc->bAlternateSetting); in usb_reset_and_verify_device()
6210 intf->resetting_device = 0; in usb_reset_and_verify_device()
6213 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
6215 desc->bInterfaceNumber, in usb_reset_and_verify_device()
6216 desc->bAlternateSetting, in usb_reset_and_verify_device()
6221 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
6222 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
6226 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
6231 udev->bos = bos; in usb_reset_and_verify_device()
6236 udev->bos = bos; in usb_reset_and_verify_device()
6238 return -ENODEV; in usb_reset_and_verify_device()
6242 * usb_reset_device - warn interface drivers and perform a USB port reset
6252 * being unbound or re-bound during the ongoing reset its disconnect()
6254 * routine returns -EINPROGRESS.
6273 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6274 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6276 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6277 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6278 udev->state); in usb_reset_device()
6279 return -EINVAL; in usb_reset_device()
6282 if (!udev->parent) { in usb_reset_device()
6283 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
6284 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6285 return -EISDIR; in usb_reset_device()
6288 if (udev->reset_in_progress) in usb_reset_device()
6289 return -EINPROGRESS; in usb_reset_device()
6290 udev->reset_in_progress = 1; in usb_reset_device()
6292 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6309 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
6310 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6314 if (cintf->dev.driver) { in usb_reset_device()
6315 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6316 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
6317 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
6318 else if (cintf->condition == in usb_reset_device()
6332 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
6333 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
6335 int rebind = cintf->needs_binding; in usb_reset_device()
6337 if (!rebind && cintf->dev.driver) { in usb_reset_device()
6338 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
6339 if (drv->post_reset) in usb_reset_device()
6340 rebind = (drv->post_reset)(cintf); in usb_reset_device()
6341 else if (cintf->condition == in usb_reset_device()
6345 cintf->needs_binding = 1; in usb_reset_device()
6356 udev->reset_in_progress = 0; in usb_reset_device()
6363 * usb_queue_reset_device - Reset a USB device from an atomic context
6376 * - Scheduling two resets at the same time from two different drivers
6379 * handles ->pre_reset(), the second reset might happen or not.
6381 * - If the reset is delayed so long that the interface is unbound from
6384 * - This function can be called during .probe(). It can also be called
6387 * .disconnect(), call usb_reset_device() directly -- but watch out
6392 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
6398 * usb_hub_find_child - Get the pointer of child device
6408 * child's usb_device pointer if non-NULL.
6415 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
6417 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
6432 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6433 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6435 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6439 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6440 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6441 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6446 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6448 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6449 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6451 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6456 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6462 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6468 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6483 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()