Lines Matching +full:autosuspend +full:- +full:delay
1 // SPDX-License-Identifier: GPL-2.0
45 /* Protect struct usb_device->state and ->children members
46 * Note: Both are also protected by ->dev.sem, except that ->state can
54 /* synchronize hub-port add/remove and peering operations */
64 * 10 seconds to send reply for the initial 64-byte descriptor request.
66 /* define initial 64-byte descriptor request timeout in milliseconds */
70 "initial 64-byte descriptor request timeout in milliseconds "
71 "(default 5000 - 5.0 seconds)");
116 if (hub_is_superspeedplus(hub->hdev)) in portspeed()
118 if (hub_is_superspeed(hub->hdev)) in portspeed()
131 if (!hdev || !hdev->actconfig || !hdev->maxchild) in usb_hub_to_struct_hub()
133 return usb_get_intfdata(hdev->actconfig->interface[0]); in usb_hub_to_struct_hub()
139 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
145 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
146 if (udev->bos->ext_cap && in usb_device_supports_lpm()
148 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
158 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
159 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
163 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
164 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
165 if (udev->parent) in usb_device_supports_lpm()
166 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
168 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
172 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
201 total_mel = hub_lpm_params->mel + in usb_set_lpm_mel()
202 (hub->descriptor->u.ss.bHubHdrDecLat * 100); in usb_set_lpm_mel()
219 udev_lpm_params->mel = total_mel; in usb_set_lpm_mel()
248 * When the hub starts to receive the LFPS, there is a slight delay for in usb_set_lpm_pel()
251 * delay, plus the PEL that we calculated for this hub. in usb_set_lpm_pel()
253 hub_pel = port_to_port_exit_latency * 1000 + hub_lpm_params->pel; in usb_set_lpm_pel()
256 * According to figure C-7 in the USB 3.0 spec, the PEL for this device in usb_set_lpm_pel()
260 udev_lpm_params->pel = first_link_pel; in usb_set_lpm_pel()
262 udev_lpm_params->pel = hub_pel; in usb_set_lpm_pel()
266 * Set the System Exit Latency (SEL) to indicate the total worst-case time from
271 * - t1: device PEL
272 * - t2: time for the ERDY to make it from the device to the host.
273 * - t3: a host-specific delay to process the ERDY.
274 * - t4: time for the packet to make it from the host to the device.
288 total_sel = udev_lpm_params->pel; in usb_set_lpm_sel()
290 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
291 parent = parent->parent) in usb_set_lpm_sel()
293 /* t2 = 2.1us + 250ns * (num_hubs - 1) */ in usb_set_lpm_sel()
295 total_sel += 2100 + 250 * (num_hubs - 1); in usb_set_lpm_sel()
300 udev_lpm_params->sel = total_sel; in usb_set_lpm_sel()
312 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
315 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
322 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
323 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
324 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
325 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
327 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
328 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
330 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
331 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
334 * Appendix C, section C.2.2.2, says that there is a slight delay from in usb_set_lpm_parameters()
341 * about the same delays. Use the maximum delay calculations from those in usb_set_lpm_parameters()
343 * U2, it's tHubPort2PortExitLat + U2DevExitLat - U1DevExitLat. I in usb_set_lpm_parameters()
352 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
353 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
357 port_to_port_delay = 1 + hub_u2_del - hub_u1_del; in usb_set_lpm_parameters()
361 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
362 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
366 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
367 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
395 size = USB_DT_HUB_NONVAR_SIZE + desc->bNbrPorts / 8 + 1; in get_hub_descriptor()
397 return -EMSGSIZE; in get_hub_descriptor()
401 return -EINVAL; in get_hub_descriptor()
450 * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7
455 struct usb_port *port_dev = hub->ports[port1 - 1]; in set_port_led()
458 status = set_port_feature(hub->hdev, (selector << 8) | port1, in set_port_led()
460 dev_dbg(&port_dev->dev, "indicator %s status %d\n", in set_port_led()
470 struct usb_device *hdev = hub->hdev; in led_work()
473 int cursor = -1; in led_work()
475 if (hdev->state != USB_STATE_CONFIGURED || hub->quiescing) in led_work()
478 for (i = 0; i < hdev->maxchild; i++) { in led_work()
481 /* 30%-50% duty cycle */ in led_work()
483 switch (hub->indicator[i]) { in led_work()
523 hub->indicator[i] = mode; in led_work()
527 cursor %= hdev->maxchild; in led_work()
529 hub->indicator[cursor] = INDICATOR_CYCLE; in led_work()
534 &hub->leds, LED_CYCLE_PERIOD); in led_work()
547 int i, status = -ETIMEDOUT; in get_hub_status()
550 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_hub_status()
565 int i, status = -ETIMEDOUT; in get_port_status()
568 (status == -ETIMEDOUT || status == -EPIPE); i++) { in get_port_status()
585 mutex_lock(&hub->status_mutex); in hub_ext_port_status()
586 ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len); in hub_ext_port_status()
588 if (ret != -ENODEV) in hub_ext_port_status()
589 dev_err(hub->intfdev, in hub_ext_port_status()
592 ret = -EIO; in hub_ext_port_status()
594 *status = le16_to_cpu(hub->status->port.wPortStatus); in hub_ext_port_status()
595 *change = le16_to_cpu(hub->status->port.wPortChange); in hub_ext_port_status()
598 hub->status->port.dwExtPortStatus); in hub_ext_port_status()
601 mutex_unlock(&hub->status_mutex); in hub_ext_port_status()
617 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
619 if (hub->quiescing) { in hub_resubmit_irq_urb()
620 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
624 status = usb_submit_urb(hub->urb, GFP_ATOMIC); in hub_resubmit_irq_urb()
625 if (status && status != -ENODEV && status != -EPERM && in hub_resubmit_irq_urb()
626 status != -ESHUTDOWN) { in hub_resubmit_irq_urb()
627 dev_err(hub->intfdev, "resubmit --> %d\n", status); in hub_resubmit_irq_urb()
628 mod_timer(&hub->irq_urb_retry, jiffies + HZ); in hub_resubmit_irq_urb()
631 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_resubmit_irq_urb()
646 if (hub->disconnected || work_pending(&hub->events)) in kick_hub_wq()
650 * Suppress autosuspend until the event is proceed. in kick_hub_wq()
657 intf = to_usb_interface(hub->intfdev); in kick_hub_wq()
659 kref_get(&hub->kref); in kick_hub_wq()
661 if (queue_work(hub_wq, &hub->events)) in kick_hub_wq()
666 kref_put(&hub->kref, hub_release); in kick_hub_wq()
696 port_dev = hub->ports[portnum - 1]; in usb_wakeup_notification()
697 if (port_dev && port_dev->child) in usb_wakeup_notification()
698 pm_wakeup_event(&port_dev->child->dev, 0); in usb_wakeup_notification()
700 set_bit(portnum, hub->wakeup_bits); in usb_wakeup_notification()
709 struct usb_hub *hub = urb->context; in hub_irq()
710 int status = urb->status; in hub_irq()
715 case -ENOENT: /* synchronous unlink */ in hub_irq()
716 case -ECONNRESET: /* async unlink */ in hub_irq()
717 case -ESHUTDOWN: /* hardware going away */ in hub_irq()
722 dev_dbg(hub->intfdev, "transfer --> %d\n", status); in hub_irq()
723 if ((++hub->nerrors < 10) || hub->error) in hub_irq()
725 hub->error = status; in hub_irq()
731 for (i = 0; i < urb->actual_length; ++i) in hub_irq()
732 bits |= ((unsigned long) ((*hub->buffer)[i])) in hub_irq()
734 hub->event_bits[0] = bits; in hub_irq()
738 hub->nerrors = 0; in hub_irq()
777 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
778 while (!list_empty(&hub->tt.clear_list)) { in hub_tt_work()
781 struct usb_device *hdev = hub->hdev; in hub_tt_work()
785 next = hub->tt.clear_list.next; in hub_tt_work()
787 list_del(&clear->clear_list); in hub_tt_work()
790 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
791 status = hub_clear_tt_buffer(hdev, clear->devinfo, clear->tt); in hub_tt_work()
792 if (status && status != -ENODEV) in hub_tt_work()
793 dev_err(&hdev->dev, in hub_tt_work()
795 clear->tt, clear->devinfo, status); in hub_tt_work()
798 drv = clear->hcd->driver; in hub_tt_work()
799 if (drv->clear_tt_buffer_complete) in hub_tt_work()
800 (drv->clear_tt_buffer_complete)(clear->hcd, clear->ep); in hub_tt_work()
803 spin_lock_irqsave(&hub->tt.lock, flags); in hub_tt_work()
805 spin_unlock_irqrestore(&hub->tt.lock, flags); in hub_tt_work()
809 * usb_hub_set_port_power - control hub port's power state
834 set_bit(port1, hub->power_bits); in usb_hub_set_port_power()
836 clear_bit(port1, hub->power_bits); in usb_hub_set_port_power()
841 * usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub
856 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer()
857 int pipe = urb->pipe; in usb_hub_clear_tt_buffer()
858 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
868 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
870 return -ENOMEM; in usb_hub_clear_tt_buffer()
874 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
875 clear->devinfo = usb_pipeendpoint (pipe); in usb_hub_clear_tt_buffer()
876 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
877 clear->devinfo |= usb_pipecontrol(pipe) in usb_hub_clear_tt_buffer()
881 clear->devinfo |= 1 << 15; in usb_hub_clear_tt_buffer()
884 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
885 clear->ep = urb->ep; in usb_hub_clear_tt_buffer()
888 spin_lock_irqsave(&tt->lock, flags); in usb_hub_clear_tt_buffer()
889 list_add_tail(&clear->clear_list, &tt->clear_list); in usb_hub_clear_tt_buffer()
890 schedule_work(&tt->clear_work); in usb_hub_clear_tt_buffer()
891 spin_unlock_irqrestore(&tt->lock, flags); in usb_hub_clear_tt_buffer()
902 * USB 2.0 hubs. Some hubs do not implement port-power switching in hub_power_on()
907 dev_dbg(hub->intfdev, "enabling power on all ports\n"); in hub_power_on()
909 dev_dbg(hub->intfdev, "trying to enable port power on " in hub_power_on()
910 "non-switchable hub\n"); in hub_power_on()
911 for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) in hub_power_on()
912 if (test_bit(port1, hub->power_bits)) in hub_power_on()
913 set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); in hub_power_on()
915 usb_clear_port_feature(hub->hdev, port1, in hub_power_on()
926 mutex_lock(&hub->status_mutex); in hub_hub_status()
927 ret = get_hub_status(hub->hdev, &hub->status->hub); in hub_hub_status()
929 if (ret != -ENODEV) in hub_hub_status()
930 dev_err(hub->intfdev, in hub_hub_status()
933 *status = le16_to_cpu(hub->status->hub.wHubStatus); in hub_hub_status()
934 *change = le16_to_cpu(hub->status->hub.wHubChange); in hub_hub_status()
937 mutex_unlock(&hub->status_mutex); in hub_hub_status()
944 return set_port_feature(hub->hdev, in hub_set_port_link_state()
950 * Disable a port and mark a logical connect-change event, so that some
952 * and will re-enumerate if there actually is a device attached.
956 dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); in hub_port_logical_disconnect()
960 * - some devices won't enumerate without a VBUS power cycle in hub_port_logical_disconnect()
961 * - SRP saves power that way in hub_port_logical_disconnect()
962 * - ... new call, TBD ... in hub_port_logical_disconnect()
963 * That's easy if this hub can switch power per-port, and in hub_port_logical_disconnect()
968 set_bit(port1, hub->change_bits); in hub_port_logical_disconnect()
973 * usb_remove_device - disable a device's port on its parent hub
989 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
990 return -EINVAL; in usb_remove_device()
991 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
992 intf = to_usb_interface(hub->intfdev); in usb_remove_device()
995 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
996 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1011 struct usb_device *hdev = hub->hdev; in hub_activate()
1017 unsigned delay; in hub_activate() local
1021 device_lock(&hdev->dev); in hub_activate()
1024 if (hub->disconnected) in hub_activate()
1030 kref_get(&hub->kref); in hub_activate()
1043 if (hdev->parent && hub_is_superspeed(hdev)) { in hub_activate()
1046 hdev->level - 1, 0, NULL, 0, in hub_activate()
1049 dev_err(hub->intfdev, in hub_activate()
1054 * hub's initial power-up delays. This is pretty awkward in hub_activate()
1055 * and the implementation looks like a home-brewed sort of in hub_activate()
1066 delay = hub_power_on_good_delay(hub); in hub_activate()
1069 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); in hub_activate()
1071 &hub->init_work, in hub_activate()
1072 msecs_to_jiffies(delay)); in hub_activate()
1074 /* Suppress autosuspend until init is done */ in hub_activate()
1076 to_usb_interface(hub->intfdev)); in hub_activate()
1083 hcd = bus_to_hcd(hdev->bus); in hub_activate()
1084 if (hcd->driver->update_hub_device) { in hub_activate()
1085 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_activate()
1086 &hub->tt, GFP_NOIO); in hub_activate()
1088 dev_err(hub->intfdev, in hub_activate()
1090 dev_err(hub->intfdev, in hub_activate()
1102 * Check each port and set hub->change_bits to let hub_wq know in hub_activate()
1105 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_activate()
1106 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_activate()
1107 struct usb_device *udev = port_dev->child; in hub_activate()
1116 dev_dbg(&port_dev->dev, "status %04x change %04x\n", in hub_activate()
1129 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1142 /* Make sure a warm-reset request is handled by port_event */ in hub_activate()
1145 set_bit(port1, hub->event_bits); in hub_activate()
1157 /* Clear status-change flags; we'll debounce later */ in hub_activate()
1160 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1165 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1170 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1174 hub_is_superspeed(hub->hdev)) { in hub_activate()
1176 usb_clear_port_feature(hub->hdev, port1, in hub_activate()
1184 clear_bit(port1, hub->removed_bits); in hub_activate()
1186 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1196 set_bit(port1, hub->change_bits); in hub_activate()
1208 * bit on device-initiated resume. in hub_activate()
1210 if (portchange || (hub_is_superspeed(hub->hdev) && in hub_activate()
1212 set_bit(port1, hub->change_bits); in hub_activate()
1214 } else if (udev->persist_enabled) { in hub_activate()
1216 udev->reset_resume = 1; in hub_activate()
1221 if (test_bit(port1, hub->power_bits)) in hub_activate()
1222 set_bit(port1, hub->change_bits); in hub_activate()
1227 set_bit(port1, hub->change_bits); in hub_activate()
1231 /* If no port-status-change flags were set, we don't need any in hub_activate()
1236 * If any port-status changes do occur during this delay, hub_wq in hub_activate()
1240 delay = HUB_DEBOUNCE_STABLE; in hub_activate()
1244 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3); in hub_activate()
1246 &hub->init_work, in hub_activate()
1247 msecs_to_jiffies(delay)); in hub_activate()
1248 device_unlock(&hdev->dev); in hub_activate()
1251 msleep(delay); in hub_activate()
1255 hub->quiescing = 0; in hub_activate()
1257 status = usb_submit_urb(hub->urb, GFP_NOIO); in hub_activate()
1259 dev_err(hub->intfdev, "activate --> %d\n", status); in hub_activate()
1260 if (hub->has_indicators && blinkenlights) in hub_activate()
1262 &hub->leds, LED_CYCLE_PERIOD); in hub_activate()
1268 /* Allow autosuspend if it was suppressed */ in hub_activate()
1270 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev)); in hub_activate()
1271 device_unlock(&hdev->dev); in hub_activate()
1274 kref_put(&hub->kref, hub_release); in hub_activate()
1298 struct usb_device *hdev = hub->hdev; in hub_quiesce()
1302 /* hub_wq and related activity won't re-trigger */ in hub_quiesce()
1303 spin_lock_irqsave(&hub->irq_urb_lock, flags); in hub_quiesce()
1304 hub->quiescing = 1; in hub_quiesce()
1305 spin_unlock_irqrestore(&hub->irq_urb_lock, flags); in hub_quiesce()
1309 for (i = 0; i < hdev->maxchild; ++i) { in hub_quiesce()
1310 if (hub->ports[i]->child) in hub_quiesce()
1311 usb_disconnect(&hub->ports[i]->child); in hub_quiesce()
1316 del_timer_sync(&hub->irq_urb_retry); in hub_quiesce()
1317 usb_kill_urb(hub->urb); in hub_quiesce()
1318 if (hub->has_indicators) in hub_quiesce()
1319 cancel_delayed_work_sync(&hub->leds); in hub_quiesce()
1320 if (hub->tt.hub) in hub_quiesce()
1321 flush_work(&hub->tt.clear_work); in hub_quiesce()
1328 for (i = 0; i < hub->hdev->maxchild; ++i) in hub_pm_barrier_for_all_ports()
1329 pm_runtime_barrier(&hub->ports[i]->dev); in hub_pm_barrier_for_all_ports()
1338 hub->in_reset = 1; in hub_pre_reset()
1348 hub->in_reset = 0; in hub_post_reset()
1358 struct usb_device *hdev = hub->hdev; in hub_configure()
1359 struct device *hub_dev = hub->intfdev; in hub_configure()
1369 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); in hub_configure()
1370 if (!hub->buffer) { in hub_configure()
1371 ret = -ENOMEM; in hub_configure()
1375 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); in hub_configure()
1376 if (!hub->status) { in hub_configure()
1377 ret = -ENOMEM; in hub_configure()
1380 mutex_init(&hub->status_mutex); in hub_configure()
1382 hub->descriptor = kzalloc(sizeof(*hub->descriptor), GFP_KERNEL); in hub_configure()
1383 if (!hub->descriptor) { in hub_configure()
1384 ret = -ENOMEM; in hub_configure()
1389 * hub->descriptor can handle USB_MAXCHILDREN ports, in hub_configure()
1390 * but a (non-SS) hub can/will return fewer bytes here. in hub_configure()
1392 ret = get_hub_descriptor(hdev, hub->descriptor); in hub_configure()
1402 if (hub->descriptor->bNbrPorts > maxchild) { in hub_configure()
1404 ret = -ENODEV; in hub_configure()
1406 } else if (hub->descriptor->bNbrPorts == 0) { in hub_configure()
1408 ret = -ENODEV; in hub_configure()
1417 u32 delay = __le16_to_cpu(hub->descriptor->u.ss.wHubDelay); in hub_configure() local
1419 if (hdev->parent) in hub_configure()
1420 delay += hdev->parent->hub_delay; in hub_configure()
1422 delay += USB_TP_TRANSMISSION_DELAY; in hub_configure()
1423 hdev->hub_delay = min_t(u32, delay, USB_TP_TRANSMISSION_DELAY_MAX); in hub_configure()
1426 maxchild = hub->descriptor->bNbrPorts; in hub_configure()
1430 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); in hub_configure()
1431 if (!hub->ports) { in hub_configure()
1432 ret = -ENOMEM; in hub_configure()
1436 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in hub_configure()
1451 portstr[i] = hub->descriptor->u.hs.DeviceRemovable in hub_configure()
1474 dev_dbg(hub_dev, "global over-current protection\n"); in hub_configure()
1477 dev_dbg(hub_dev, "individual port over-current protection\n"); in hub_configure()
1481 dev_dbg(hub_dev, "no over-current protection\n"); in hub_configure()
1485 spin_lock_init(&hub->tt.lock); in hub_configure()
1486 INIT_LIST_HEAD(&hub->tt.clear_list); in hub_configure()
1487 INIT_WORK(&hub->tt.clear_work, hub_tt_work); in hub_configure()
1488 switch (hdev->descriptor.bDeviceProtocol) { in hub_configure()
1493 hub->tt.hub = hdev; in hub_configure()
1499 hub->tt.multi = 1; in hub_configure()
1503 hub->tt.hub = hdev; in hub_configure()
1510 hdev->descriptor.bDeviceProtocol); in hub_configure()
1517 if (hdev->descriptor.bDeviceProtocol != 0) { in hub_configure()
1518 hub->tt.think_time = 666; in hub_configure()
1521 8, hub->tt.think_time); in hub_configure()
1525 hub->tt.think_time = 666 * 2; in hub_configure()
1528 16, hub->tt.think_time); in hub_configure()
1531 hub->tt.think_time = 666 * 3; in hub_configure()
1534 24, hub->tt.think_time); in hub_configure()
1537 hub->tt.think_time = 666 * 4; in hub_configure()
1540 32, hub->tt.think_time); in hub_configure()
1544 /* probe() zeroes hub->indicator[] */ in hub_configure()
1546 hub->has_indicators = 1; in hub_configure()
1551 hub->descriptor->bPwrOn2PwrGood * 2); in hub_configure()
1553 /* power budgeting mostly matters with bus-powered hubs, in hub_configure()
1554 * and battery-powered root hubs (may provide just 8 mA). in hub_configure()
1561 hcd = bus_to_hcd(hdev->bus); in hub_configure()
1562 if (hdev == hdev->bus->root_hub) { in hub_configure()
1563 if (hcd->power_budget > 0) in hub_configure()
1564 hdev->bus_mA = hcd->power_budget; in hub_configure()
1566 hdev->bus_mA = full_load * maxchild; in hub_configure()
1567 if (hdev->bus_mA >= full_load) in hub_configure()
1568 hub->mA_per_port = full_load; in hub_configure()
1570 hub->mA_per_port = hdev->bus_mA; in hub_configure()
1571 hub->limited_power = 1; in hub_configure()
1574 int remaining = hdev->bus_mA - in hub_configure()
1575 hub->descriptor->bHubContrCurrent; in hub_configure()
1578 hub->descriptor->bHubContrCurrent); in hub_configure()
1579 hub->limited_power = 1; in hub_configure()
1585 hub->mA_per_port = unit_load; /* 7.2.1 */ in hub_configure()
1587 } else { /* Self-powered external hub */ in hub_configure()
1588 /* FIXME: What about battery-powered external hubs that in hub_configure()
1590 hub->mA_per_port = full_load; in hub_configure()
1592 if (hub->mA_per_port < full_load) in hub_configure()
1594 hub->mA_per_port); in hub_configure()
1603 if (hdev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER) in hub_configure()
1609 dev_dbg(hub_dev, "%sover-current condition exists\n", in hub_configure()
1618 pipe = usb_rcvintpipe(hdev, endpoint->bEndpointAddress); in hub_configure()
1621 if (maxp > sizeof(*hub->buffer)) in hub_configure()
1622 maxp = sizeof(*hub->buffer); in hub_configure()
1624 hub->urb = usb_alloc_urb(0, GFP_KERNEL); in hub_configure()
1625 if (!hub->urb) { in hub_configure()
1626 ret = -ENOMEM; in hub_configure()
1630 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, in hub_configure()
1631 hub, endpoint->bInterval); in hub_configure()
1634 if (hub->has_indicators && blinkenlights) in hub_configure()
1635 hub->indicator[0] = INDICATOR_CYCLE; in hub_configure()
1641 dev_err(hub->intfdev, in hub_configure()
1646 hdev->maxchild = i; in hub_configure()
1647 for (i = 0; i < hdev->maxchild; i++) { in hub_configure()
1648 struct usb_port *port_dev = hub->ports[i]; in hub_configure()
1650 pm_runtime_put(&port_dev->dev); in hub_configure()
1660 if (hcd->driver->update_hub_device) { in hub_configure()
1661 ret = hcd->driver->update_hub_device(hcd, hdev, in hub_configure()
1662 &hub->tt, GFP_KERNEL); in hub_configure()
1669 usb_hub_adjust_deviceremovable(hdev, hub->descriptor); in hub_configure()
1685 usb_put_dev(hub->hdev); in hub_release()
1686 usb_put_intf(to_usb_interface(hub->intfdev)); in hub_release()
1702 hub->disconnected = 1; in hub_disconnect()
1705 hub->error = 0; in hub_disconnect()
1712 port1 = hdev->maxchild; in hub_disconnect()
1713 hdev->maxchild = 0; in hub_disconnect()
1717 for (; port1 > 0; --port1) in hub_disconnect()
1722 if (hub->hdev->speed == USB_SPEED_HIGH) in hub_disconnect()
1723 highspeed_hubs--; in hub_disconnect()
1725 usb_free_urb(hub->urb); in hub_disconnect()
1726 kfree(hub->ports); in hub_disconnect()
1727 kfree(hub->descriptor); in hub_disconnect()
1728 kfree(hub->status); in hub_disconnect()
1729 kfree(hub->buffer); in hub_disconnect()
1731 pm_suspend_ignore_children(&intf->dev, false); in hub_disconnect()
1732 kref_put(&hub->kref, hub_release); in hub_disconnect()
1739 if (desc->desc.bInterfaceSubClass != 0 && in hub_descriptor_is_sane()
1740 desc->desc.bInterfaceSubClass != 1) in hub_descriptor_is_sane()
1743 /* Multiple endpoints? What kind of mutant ninja-hub is this? */ in hub_descriptor_is_sane()
1744 if (desc->desc.bNumEndpoints != 1) in hub_descriptor_is_sane()
1748 if (!usb_endpoint_is_int_in(&desc->endpoint[0].desc)) in hub_descriptor_is_sane()
1760 desc = intf->cur_altsetting; in hub_probe()
1764 * Set default autosuspend delay as 0 to speedup bus suspend, in hub_probe()
1767 * - Unlike other drivers, the hub driver does not rely on the in hub_probe()
1768 * autosuspend delay to provide enough time to handle a wakeup in hub_probe()
1772 * - The patch might cause one or more auto supend/resume for in hub_probe()
1784 * autosuspend delay of their parent hub in the probe() to one in hub_probe()
1788 * - The patch may cause one or more auto suspend/resume on in hub_probe()
1792 * - Change autosuspend delay of hub can avoid unnecessary auto in hub_probe()
1796 * - If user has indicated to prevent autosuspend by passing in hub_probe()
1797 * usbcore.autosuspend = -1 then keep autosuspend disabled. in hub_probe()
1800 if (hdev->dev.power.autosuspend_delay >= 0) in hub_probe()
1801 pm_runtime_set_autosuspend_delay(&hdev->dev, 0); in hub_probe()
1809 if (hdev->parent) { /* normal device */ in hub_probe()
1812 const struct hc_driver *drv = bus_to_hcd(hdev->bus)->driver; in hub_probe()
1814 if (drv->bus_suspend && drv->bus_resume) in hub_probe()
1818 if (hdev->level == MAX_TOPO_LEVEL) { in hub_probe()
1819 dev_err(&intf->dev, in hub_probe()
1821 return -E2BIG; in hub_probe()
1825 if (hdev->parent) { in hub_probe()
1826 dev_warn(&intf->dev, "ignoring external hub\n"); in hub_probe()
1827 return -ENODEV; in hub_probe()
1832 dev_err(&intf->dev, "bad descriptor, ignoring hub\n"); in hub_probe()
1833 return -EIO; in hub_probe()
1837 dev_info(&intf->dev, "USB hub found\n"); in hub_probe()
1841 return -ENOMEM; in hub_probe()
1843 kref_init(&hub->kref); in hub_probe()
1844 hub->intfdev = &intf->dev; in hub_probe()
1845 hub->hdev = hdev; in hub_probe()
1846 INIT_DELAYED_WORK(&hub->leds, led_work); in hub_probe()
1847 INIT_DELAYED_WORK(&hub->init_work, NULL); in hub_probe()
1848 INIT_WORK(&hub->events, hub_event); in hub_probe()
1849 spin_lock_init(&hub->irq_urb_lock); in hub_probe()
1850 timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0); in hub_probe()
1855 intf->needs_remote_wakeup = 1; in hub_probe()
1856 pm_suspend_ignore_children(&intf->dev, true); in hub_probe()
1858 if (hdev->speed == USB_SPEED_HIGH) in hub_probe()
1861 if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) in hub_probe()
1862 hub->quirk_check_port_auto_suspend = 1; in hub_probe()
1864 if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) in hub_probe()
1868 return -ENODEV; in hub_probe()
1884 if (hdev->devnum <= 0) in hub_ioctl()
1885 info->nports = 0; in hub_ioctl()
1887 info->nports = hdev->maxchild; in hub_ioctl()
1888 for (i = 0; i < info->nports; i++) { in hub_ioctl()
1889 if (hub->ports[i]->child == NULL) in hub_ioctl()
1890 info->port[i] = 0; in hub_ioctl()
1892 info->port[i] = in hub_ioctl()
1893 hub->ports[i]->child->devnum; in hub_ioctl()
1898 return info->nports + 1; in hub_ioctl()
1902 return -ENOSYS; in hub_ioctl()
1915 if (hdev->state == USB_STATE_NOTATTACHED) in find_port_owner()
1916 return -ENODEV; in find_port_owner()
1917 if (port1 == 0 || port1 > hdev->maxchild) in find_port_owner()
1918 return -EINVAL; in find_port_owner()
1923 *ppowner = &(hub->ports[port1 - 1]->port_owner); in find_port_owner()
1938 return -EBUSY; in usb_hub_claim_port()
1954 return -ENOENT; in usb_hub_release_port()
1965 for (n = 0; n < hdev->maxchild; n++) { in usb_hub_release_all_ports()
1966 if (hub->ports[n]->port_owner == owner) in usb_hub_release_all_ports()
1967 hub->ports[n]->port_owner = NULL; in usb_hub_release_all_ports()
1977 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
1979 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
1980 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
1988 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
1989 if (hub->ports[i]->child) in recursively_mark_NOTATTACHED()
1990 recursively_mark_NOTATTACHED(hub->ports[i]->child); in recursively_mark_NOTATTACHED()
1992 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
1993 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
1994 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
1998 * usb_set_device_state - change a device's current state (usbcore, hcds)
2002 * udev->state is _not_ fully protected by the device lock. Although
2013 * If udev->state is already USB_STATE_NOTATTACHED then no change is made.
2014 * Otherwise udev->state is set to new_state, and if new_state is
2022 int wakeup = -1; in usb_set_device_state()
2025 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2029 /* root hub wakeup capabilities are managed out-of-band in usb_set_device_state()
2032 if (udev->parent) { in usb_set_device_state()
2033 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2037 wakeup = (udev->quirks & in usb_set_device_state()
2039 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2044 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2046 udev->active_duration -= jiffies; in usb_set_device_state()
2048 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2049 udev->active_duration += jiffies; in usb_set_device_state()
2050 udev->state = new_state; in usb_set_device_state()
2055 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2062 * Device numbers are used as filenames in usbfs. On USB-1.1 and
2063 * USB-2.0 buses they are also used as device addresses, however on
2064 * USB-3.0 buses the address is assigned by the controller hardware
2068 * device <-> virtual port number becomes 1:1. Why? to simplify the
2077 * We add 1 as an offset to the one-based USB-stack port number
2078 * (zero-based wusb virtual port index) for two reasons: (a) dev addr
2081 * port #1, which is wusb virtual-port #0 has address #2.
2091 struct usb_bus *bus = udev->bus; in choose_devnum()
2094 mutex_lock(&bus->devnum_next_mutex); in choose_devnum()
2095 if (udev->wusb) { in choose_devnum()
2096 devnum = udev->portnum + 1; in choose_devnum()
2097 BUG_ON(test_bit(devnum, bus->devmap.devicemap)); in choose_devnum()
2100 * bus->devnum_next. */ in choose_devnum()
2101 devnum = find_next_zero_bit(bus->devmap.devicemap, 128, in choose_devnum()
2102 bus->devnum_next); in choose_devnum()
2104 devnum = find_next_zero_bit(bus->devmap.devicemap, in choose_devnum()
2106 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1); in choose_devnum()
2109 set_bit(devnum, bus->devmap.devicemap); in choose_devnum()
2110 udev->devnum = devnum; in choose_devnum()
2112 mutex_unlock(&bus->devnum_next_mutex); in choose_devnum()
2117 if (udev->devnum > 0) { in release_devnum()
2118 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2119 udev->devnum = -1; in release_devnum()
2126 if (!udev->wusb) in update_devnum()
2127 udev->devnum = devnum; in update_devnum()
2128 if (!udev->devaddr) in update_devnum()
2129 udev->devaddr = (u8)devnum; in update_devnum()
2134 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2137 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2138 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2147 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2148 if (hub->ports[i]->child) in hub_disconnect_children()
2149 usb_disconnect(&hub->ports[i]->child); in hub_disconnect_children()
2154 * usb_disconnect - disconnect a device (usbcore-internal)
2181 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2182 udev->devnum); in usb_disconnect()
2188 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2198 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2202 if (udev->parent) { in usb_disconnect()
2203 port1 = udev->portnum; in usb_disconnect()
2204 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2205 port_dev = hub->ports[port1 - 1]; in usb_disconnect()
2207 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2208 sysfs_remove_link(&port_dev->dev.kobj, "device"); in usb_disconnect()
2211 * As usb_port_runtime_resume() de-references udev, make in usb_disconnect()
2214 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2215 pm_runtime_get_sync(&port_dev->dev); in usb_disconnect()
2218 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2222 * for de-configuring the device and invoking the remove-device in usb_disconnect()
2225 device_del(&udev->dev); in usb_disconnect()
2237 if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_disconnect()
2238 pm_runtime_put(&port_dev->dev); in usb_disconnect()
2242 put_device(&udev->dev); in usb_disconnect()
2250 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2255 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2257 dev_info(&udev->dev, in announce_device()
2259 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2260 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2262 dev_info(&udev->dev, in announce_device()
2264 udev->descriptor.iManufacturer, in announce_device()
2265 udev->descriptor.iProduct, in announce_device()
2266 udev->descriptor.iSerialNumber); in announce_device()
2267 show_string(udev, "Product", udev->product); in announce_device()
2268 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2269 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2277 * usb_enumerate_device_otg - FIXME (usbcore-internal)
2280 * Finish enumeration for On-The-Go devices
2290 * OTG-aware devices on OTG-capable root hubs may be able to use SRP, in usb_enumerate_device_otg()
2294 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2295 && udev->config in usb_enumerate_device_otg()
2296 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2298 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2299 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2302 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2303 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2305 if (err || !(desc->bmAttributes & USB_OTG_HNP)) in usb_enumerate_device_otg()
2308 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2309 (port1 == bus->otg_port) ? "" : "non-"); in usb_enumerate_device_otg()
2312 if (port1 == bus->otg_port) { in usb_enumerate_device_otg()
2313 bus->b_hnp_enable = 1; in usb_enumerate_device_otg()
2325 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2327 bus->b_hnp_enable = 0; in usb_enumerate_device_otg()
2329 } else if (desc->bLength == sizeof in usb_enumerate_device_otg()
2339 dev_err(&udev->dev, in usb_enumerate_device_otg()
2350 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
2354 * and FIXME -- all comments that apply to them apply here wrt to
2366 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2368 if (udev->config == NULL) { in usb_enumerate_device()
2371 if (err != -ENODEV) in usb_enumerate_device()
2372 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2379 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2380 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2381 udev->descriptor.iManufacturer); in usb_enumerate_device()
2382 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2388 if (IS_ENABLED(CONFIG_USB_OTG_WHITELIST) && hcd->tpl_support && in usb_enumerate_device()
2393 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2394 || udev->bus->is_b_host)) { in usb_enumerate_device()
2397 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2399 return -ENOTSUPP; in usb_enumerate_device()
2409 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2411 u8 port = udev->portnum; in set_usb_port_removable()
2418 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2424 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2426 udev->removable = USB_DEVICE_REMOVABLE; in set_usb_port_removable()
2430 udev->removable = USB_DEVICE_FIXED; in set_usb_port_removable()
2440 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); in set_usb_port_removable()
2446 if (le16_to_cpu(hub->descriptor->u.ss.DeviceRemovable) in set_usb_port_removable()
2450 if (hub->descriptor->u.hs.DeviceRemovable[port / 8] & (1 << (port % 8))) in set_usb_port_removable()
2455 udev->removable = USB_DEVICE_REMOVABLE; in set_usb_port_removable()
2457 udev->removable = USB_DEVICE_FIXED; in set_usb_port_removable()
2462 * usb_new_device - perform initial device setup (usbcore-internal)
2475 * Only the hub driver or root-hub registrar should ever call this.
2486 if (udev->parent) { in usb_new_device()
2487 /* Initialize non-root-hub device wakeup to disabled; in usb_new_device()
2491 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2494 /* Tell the runtime-PM framework the device is active */ in usb_new_device()
2495 pm_runtime_set_active(&udev->dev); in usb_new_device()
2496 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2497 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2498 pm_runtime_enable(&udev->dev); in usb_new_device()
2500 /* By default, forbid autosuspend for all devices. It will be in usb_new_device()
2508 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2509 udev->devnum, udev->bus->busnum, in usb_new_device()
2510 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2511 /* export the usbdev device-node for libusb */ in usb_new_device()
2512 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2513 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2518 if (udev->serial) in usb_new_device()
2519 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2520 if (udev->product) in usb_new_device()
2521 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2522 if (udev->manufacturer) in usb_new_device()
2523 add_device_randomness(udev->manufacturer, in usb_new_device()
2524 strlen(udev->manufacturer)); in usb_new_device()
2526 device_enable_async_suspend(&udev->dev); in usb_new_device()
2528 /* check whether the hub or firmware marks this port as non-removable */ in usb_new_device()
2529 if (udev->parent) in usb_new_device()
2533 * for configuring the device and invoking the add-device in usb_new_device()
2536 err = device_add(&udev->dev); in usb_new_device()
2538 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2543 if (udev->parent) { in usb_new_device()
2544 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2545 int port1 = udev->portnum; in usb_new_device()
2546 struct usb_port *port_dev = hub->ports[port1 - 1]; in usb_new_device()
2548 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2549 &port_dev->dev.kobj, "port"); in usb_new_device()
2553 err = sysfs_create_link(&port_dev->dev.kobj, in usb_new_device()
2554 &udev->dev.kobj, "device"); in usb_new_device()
2556 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2560 if (!test_and_set_bit(port1, hub->child_usage_bits)) in usb_new_device()
2561 pm_runtime_get_sync(&port_dev->dev); in usb_new_device()
2564 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2566 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2571 pm_runtime_disable(&udev->dev); in usb_new_device()
2572 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2578 * usb_deauthorize_device - deauthorize a device (usbcore-internal)
2592 if (usb_dev->authorized == 0) in usb_deauthorize_device()
2595 usb_dev->authorized = 0; in usb_deauthorize_device()
2596 usb_set_configuration(usb_dev, -1); in usb_deauthorize_device()
2609 if (usb_dev->authorized == 1) in usb_authorize_device()
2614 dev_err(&usb_dev->dev, in usb_authorize_device()
2619 if (usb_dev->wusb) { in usb_authorize_device()
2620 result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor)); in usb_authorize_device()
2622 dev_err(&usb_dev->dev, "can't re-read device descriptor for " in usb_authorize_device()
2628 usb_dev->authorized = 1; in usb_authorize_device()
2636 dev_err(&usb_dev->dev, in usb_authorize_device()
2642 dev_info(&usb_dev->dev, "authorized to connect\n"); in usb_authorize_device()
2663 struct usb_ssp_cap_descriptor *ssp_cap = hdev->bos->ssp_cap; in port_speed_is_ssp()
2668 ssa_count = le32_to_cpu(ssp_cap->bmAttributes) & in port_speed_is_ssp()
2672 ss_attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]); in port_speed_is_ssp()
2683 if (hub->hdev->parent != NULL) /* not a root hub? */ in hub_is_wusb()
2685 hcd = bus_to_hcd(hub->hdev->bus); in hub_is_wusb()
2686 return hcd->wireless; in hub_is_wusb()
2713 port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME; in use_new_scheme()
2714 int quick_enumeration = (udev->speed == USB_SPEED_HIGH); in use_new_scheme()
2716 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2731 if (!hub_is_superspeed(hub->hdev)) in hub_port_warm_reset_required()
2734 if (test_bit(port1, hub->warm_reset_bits)) in hub_port_warm_reset_required()
2743 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_wait_reset() argument
2752 delay_time += delay) { in hub_port_wait_reset()
2754 msleep(delay); in hub_port_wait_reset()
2757 if (hub_is_superspeedplus(hub->hdev)) in hub_port_wait_reset()
2772 * to re-establish a connection after the reset is complete, in hub_port_wait_reset()
2773 * so also wait for the connection to be re-established. in hub_port_wait_reset()
2779 /* switch to the long delay after two short delay failures */ in hub_port_wait_reset()
2781 delay = HUB_LONG_RESET_TIME; in hub_port_wait_reset()
2783 dev_dbg(&hub->ports[port1 - 1]->dev, in hub_port_wait_reset()
2785 warm ? "warm " : "", delay); in hub_port_wait_reset()
2789 return -EBUSY; in hub_port_wait_reset()
2792 return -ENOTCONN; in hub_port_wait_reset()
2796 return -ENOTCONN; in hub_port_wait_reset()
2800 * but the device may have successfully re-connected. Ignore it. in hub_port_wait_reset()
2802 if (!hub_is_superspeed(hub->hdev) && in hub_port_wait_reset()
2804 usb_clear_port_feature(hub->hdev, port1, in hub_port_wait_reset()
2806 return -EAGAIN; in hub_port_wait_reset()
2810 return -EBUSY; in hub_port_wait_reset()
2815 if (hub_is_superspeedplus(hub->hdev)) { in hub_port_wait_reset()
2817 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2818 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2820 udev->rx_lanes = 1; in hub_port_wait_reset()
2821 udev->tx_lanes = 1; in hub_port_wait_reset()
2824 udev->speed = USB_SPEED_WIRELESS; in hub_port_wait_reset()
2825 else if (hub_is_superspeedplus(hub->hdev) && in hub_port_wait_reset()
2826 port_speed_is_ssp(hub->hdev, ext_portstatus & in hub_port_wait_reset()
2828 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2829 else if (hub_is_superspeed(hub->hdev)) in hub_port_wait_reset()
2830 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2832 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2834 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2836 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2842 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_reset() argument
2846 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_reset()
2849 if (!hub_is_superspeed(hub->hdev)) { in hub_port_reset()
2851 dev_err(hub->intfdev, "only USB3 hub support " in hub_port_reset()
2853 return -EINVAL; in hub_port_reset()
2869 clear_bit(port1, hub->warm_reset_bits); in hub_port_reset()
2873 status = set_port_feature(hub->hdev, port1, (warm ? in hub_port_reset()
2876 if (status == -ENODEV) { in hub_port_reset()
2879 dev_err(&port_dev->dev, in hub_port_reset()
2883 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
2885 if (status && status != -ENOTCONN && status != -ENODEV) in hub_port_reset()
2886 dev_dbg(hub->intfdev, in hub_port_reset()
2892 if (status == 0 || status == -ENOTCONN || status == -ENODEV) { in hub_port_reset()
2893 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2896 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2899 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2901 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2905 usb_clear_port_feature(hub->hdev, port1, in hub_port_reset()
2910 * state, re-issue the warm reset. in hub_port_reset()
2925 dev_dbg(&port_dev->dev, in hub_port_reset()
2931 dev_dbg(&port_dev->dev, in hub_port_reset()
2934 delay = HUB_LONG_RESET_TIME; in hub_port_reset()
2937 dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); in hub_port_reset()
2941 if (port_dev->quirks & USB_PORT_QUIRK_FAST_ENUM) in hub_port_reset()
2947 /* Hub needs extra delay after resetting its port. */ in hub_port_reset()
2948 if (hub->hdev->quirks & USB_QUIRK_HUB_SLOW_RESET) in hub_port_reset()
2955 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
2961 if (hcd->driver->reset_device) in hub_port_reset()
2962 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
2971 if (!hub_is_superspeed(hub->hdev)) in hub_port_reset()
2982 if (hub_is_superspeed(hub->hdev)) { in port_is_power_on()
2994 __acquires(&port_dev->status_lock) in usb_lock_port()
2996 mutex_lock(&port_dev->status_lock); in usb_lock_port()
2997 __acquire(&port_dev->status_lock); in usb_lock_port()
3001 __releases(&port_dev->status_lock) in usb_unlock_port()
3003 mutex_unlock(&port_dev->status_lock); in usb_unlock_port()
3004 __release(&port_dev->status_lock); in usb_unlock_port()
3014 if (hub_is_superspeed(hub->hdev)) { in port_is_suspended()
3027 * is ready for a reset-resume, or should be disconnected.
3033 struct usb_port *port_dev = hub->ports[port1 - 1]; in check_port_resume_type()
3038 if (status == 0 && udev->reset_resume in check_port_resume_type()
3046 status = -ENODEV; in check_port_resume_type()
3048 if (retries--) { in check_port_resume_type()
3054 status = -ENODEV; in check_port_resume_type()
3058 * so try a reset-resume instead. in check_port_resume_type()
3060 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3061 if (udev->persist_enabled) in check_port_resume_type()
3062 udev->reset_resume = 1; in check_port_resume_type()
3064 status = -ENODEV; in check_port_resume_type()
3068 dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", in check_port_resume_type()
3070 } else if (udev->reset_resume) { in check_port_resume_type()
3072 /* Late port handoff can set status-change bits */ in check_port_resume_type()
3074 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3077 usb_clear_port_feature(hub->hdev, port1, in check_port_resume_type()
3086 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3089 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_disable_ltm()
3096 if (!udev->actconfig) in usb_disable_ltm()
3108 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3111 if (!usb_device_supports_ltm(hcd->self.root_hub) || in usb_enable_ltm()
3118 if (!udev->actconfig) in usb_enable_ltm()
3129 * usb_enable_remote_wakeup - enable remote wakeup for a device
3132 * For USB-2 devices: Set the device's remote wakeup feature.
3134 * For USB-3 devices: Assume there's only one function on the device and
3140 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3155 * usb_disable_remote_wakeup - disable remote wakeup for a device
3158 * For USB-2 devices: Clear the device's remote wakeup feature.
3160 * For USB-3 devices: Assume there's only one function on the device and
3166 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3178 /* Count of wakeup-enabled devices at or below udev */
3183 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3184 (hub ? hub->wakeup_enabled_descendants : 0); in usb_wakeup_enabled_descendants()
3189 * usb_port_suspend - suspend a usb device's upstream port
3212 * between a pair of dual-role devices. That will change roles, such
3213 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
3219 * - suspend, resume ... when the VBUS power link stays live
3220 * - suspend, disconnect ... VBUS lost
3223 * normal re-enumeration procedures, starting with enabling VBUS power.
3224 * Other than re-initializing the hub (plug/unplug, except for root hubs),
3228 * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get
3230 * hub is suspended). Nevertheless, we change @udev->state to
3232 * upstream port setting is stored in @udev->port_is_suspended.
3238 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3239 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3240 int port1 = udev->portnum; in usb_port_suspend()
3252 if (udev->do_remote_wakeup) { in usb_port_suspend()
3255 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3257 /* bail if autosuspend is requested */ in usb_port_suspend()
3267 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3268 status = -ENOMEM; in usb_port_suspend()
3274 if (hub_is_superspeed(hub->hdev)) in usb_port_suspend()
3279 * on individual USB-2 ports. The devices will automatically go in usb_port_suspend()
3289 status = set_port_feature(hub->hdev, port1, in usb_port_suspend()
3296 dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); in usb_port_suspend()
3304 if (udev->do_remote_wakeup) in usb_port_suspend()
3312 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3313 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in usb_port_suspend()
3314 udev->do_remote_wakeup); in usb_port_suspend()
3316 udev->port_is_suspended = 1; in usb_port_suspend()
3324 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3325 && test_and_clear_bit(port1, hub->child_usage_bits)) in usb_port_suspend()
3326 pm_runtime_put_sync(&port_dev->dev); in usb_port_suspend()
3328 usb_mark_last_busy(hub->hdev); in usb_port_suspend()
3342 * If @udev->reset_resume is set then the device is reset before the
3351 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3352 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3359 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3368 if (udev->reset_resume) { in finish_port_resume()
3371 * we don't want to perform a reset-resume. We'll fail the in finish_port_resume()
3376 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3377 status = -ENODEV; in finish_port_resume()
3390 /* If a normal resume failed, try doing a reset-resume */ in finish_port_resume()
3391 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3392 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3393 udev->reset_resume = 1; in finish_port_resume()
3399 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3405 * udev->reset_resume in finish_port_resume()
3407 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3408 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3420 dev_dbg(&udev->dev, in finish_port_resume()
3434 * device switch on the RX termination after long delay of host enabling
3462 status = -ENODEV; in wait_for_connected()
3469 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3474 * usb_port_resume - re-activate a suspended usb device's upstream port
3475 * @udev: device to re-activate, not a root hub
3478 * This will re-activate the suspended device, increasing power usage
3484 * If @udev->reset_resume is set then this routine won't check that the
3492 * for mass-storage devices containing mounted filesystems, since the
3509 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3510 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3511 int port1 = udev->portnum; in usb_port_resume()
3515 if (!test_and_set_bit(port1, hub->child_usage_bits)) { in usb_port_resume()
3516 status = pm_runtime_get_sync(&port_dev->dev); in usb_port_resume()
3518 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3526 /* Skip the initial Clear-Suspend step for a remote wakeup */ in usb_port_resume()
3530 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3535 if (hub_is_superspeed(hub->hdev)) in usb_port_resume()
3538 status = usb_clear_port_feature(hub->hdev, in usb_port_resume()
3541 dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3544 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3545 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in usb_port_resume()
3560 udev->port_is_suspended = 0; in usb_port_resume()
3561 if (hub_is_superspeed(hub->hdev)) { in usb_port_resume()
3563 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3567 usb_clear_port_feature(hub->hdev, port1, in usb_port_resume()
3572 if (udev->persist_enabled) in usb_port_resume()
3581 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3601 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3602 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3616 __must_hold(&port_dev->status_lock) in hub_handle_remote_wakeup()
3618 struct usb_port *port_dev = hub->ports[port - 1]; in hub_handle_remote_wakeup()
3625 hdev = hub->hdev; in hub_handle_remote_wakeup()
3626 udev = port_dev->child; in hub_handle_remote_wakeup()
3633 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3650 ret = -ENODEV; in hub_handle_remote_wakeup()
3653 dev_dbg(&port_dev->dev, "resume, status %d\n", ret); in hub_handle_remote_wakeup()
3661 for (port1 = 1; port1 <= hub->hdev->maxchild; ++port1) { in check_ports_changed()
3675 struct usb_device *hdev = hub->hdev; in hub_suspend()
3680 * Also, add up the number of wakeup-enabled descendants. in hub_suspend()
3682 hub->wakeup_enabled_descendants = 0; in hub_suspend()
3683 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3684 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_suspend()
3685 struct usb_device *udev = port_dev->child; in hub_suspend()
3687 if (udev && udev->can_submit) { in hub_suspend()
3688 dev_warn(&port_dev->dev, "device %s not suspended yet\n", in hub_suspend()
3689 dev_name(&udev->dev)); in hub_suspend()
3691 return -EBUSY; in hub_suspend()
3694 hub->wakeup_enabled_descendants += in hub_suspend()
3698 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { in hub_suspend()
3702 return -EBUSY; in hub_suspend()
3703 pm_wakeup_event(&hdev->dev, 2000); in hub_suspend()
3707 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { in hub_suspend()
3709 for (port1 = 1; port1 <= hdev->maxchild; port1++) { in hub_suspend()
3719 dev_dbg(&intf->dev, "%s\n", __func__); in hub_suspend()
3729 struct usb_device *hdev = hub->hdev; in report_wakeup_requests()
3735 if (hdev->parent) in report_wakeup_requests()
3738 hcd = bus_to_hcd(hdev->bus); in report_wakeup_requests()
3739 if (hcd->driver->get_resuming_ports) { in report_wakeup_requests()
3749 resuming_ports = hcd->driver->get_resuming_ports(hcd); in report_wakeup_requests()
3750 for (i = 0; i < hdev->maxchild; ++i) { in report_wakeup_requests()
3752 udev = hub->ports[i]->child; in report_wakeup_requests()
3754 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
3764 dev_dbg(&intf->dev, "%s\n", __func__); in hub_resume()
3781 dev_dbg(&intf->dev, "%s\n", __func__); in hub_reset_resume()
3787 * usb_root_hub_lost_power - called by HCD if the root hub lost Vbus power
3794 * power-session recovery for all the "USB-PERSIST"-enabled child devices;
3799 dev_notice(&rhdev->dev, "root hub lost power or was reset\n"); in usb_root_hub_lost_power()
3800 rhdev->reset_resume = 1; in usb_root_hub_lost_power()
3813 * device-initiated U1 or U2. This lets the device know the exit latencies from
3829 if (udev->state != USB_STATE_CONFIGURED) in usb_req_set_sel()
3833 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
3834 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
3835 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
3836 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
3843 * latency for the link state, and could start a device-initiated in usb_req_set_sel()
3852 dev_dbg(&udev->dev, "Device-initiated %s disabled due to long SEL %llu us or PEL %llu us\n", in usb_req_set_sel()
3854 return -EINVAL; in usb_req_set_sel()
3858 * If we're enabling device-initiated LPM for one link state, in usb_req_set_sel()
3881 return -ENOMEM; in usb_req_set_sel()
3883 sel_values->u1_sel = u1_sel; in usb_req_set_sel()
3884 sel_values->u1_pel = u1_pel; in usb_req_set_sel()
3885 sel_values->u2_sel = cpu_to_le16(u2_sel); in usb_req_set_sel()
3886 sel_values->u2_pel = cpu_to_le16(u2_pel); in usb_req_set_sel()
3899 * Enable or disable device-initiated U1 or U2 transitions.
3915 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
3917 return -EINVAL; in usb_set_device_initiated_lpm()
3920 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
3921 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
3930 * Now send the control transfer to enable device-initiated LPM in usb_set_device_initiated_lpm()
3948 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
3951 return -EBUSY; in usb_set_device_initiated_lpm()
3970 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
3972 return -EINVAL; in usb_set_lpm_timeout()
3977 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
3980 return -EINVAL; in usb_set_lpm_timeout()
3983 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
3984 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
3987 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
3990 return -EBUSY; in usb_set_lpm_timeout()
3993 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
3995 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4000 * Enable the hub-initiated U1/U2 idle timeouts, and enable device-initiated
4004 * control transfers to set the hub timeout or enable device-initiated U1/U2
4007 * If the control transfer to enable device-initiated U1/U2 entry fails, then
4008 * hub-initiated U1/U2 will be disabled.
4018 __u8 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4019 __le16 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4035 dev_warn(&udev->dev, "Set SEL for device-initiated %s failed.\n", in usb_enable_link_state()
4045 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4052 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4060 * device-initiated LPM won't be allowed either, so let the xHCI in usb_enable_link_state()
4063 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4070 if (udev->actconfig && in usb_enable_link_state()
4073 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4075 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4081 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4086 * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated
4089 * If this function returns -EBUSY, the parent hub will still allow U1/U2 entry.
4092 * If zero is returned, device-initiated U1/U2 entry may still be enabled, but
4094 * still disallow device-initiated U1/U2 entry.
4108 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4110 return -EINVAL; in usb_disable_link_state()
4114 return -EBUSY; in usb_disable_link_state()
4118 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4119 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4126 * timeout set to 0, no matter device-initiated LPM is disabled or in usb_disable_link_state()
4130 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4132 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4138 * Disable hub-initiated and device-initiated U1 and U2 entry.
4142 * lpm_disable_count, and will re-enable LPM if lpm_disable_count reaches zero.
4148 if (!udev || !udev->parent || in usb_disable_lpm()
4149 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4150 !udev->lpm_capable || in usb_disable_lpm()
4151 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4154 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4155 if (!hcd || !hcd->driver->disable_usb3_lpm_timeout) in usb_disable_lpm()
4158 udev->lpm_disable_count++; in usb_disable_lpm()
4159 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4172 return -EBUSY; in usb_disable_lpm()
4179 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4183 return -EINVAL; in usb_unlocked_disable_lpm()
4185 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4187 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_disable_lpm()
4194 * Attempt to enable device-initiated and hub-initiated U1 and U2 entry. The
4207 if (!udev || !udev->parent || in usb_enable_lpm()
4208 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4209 !udev->lpm_capable || in usb_enable_lpm()
4210 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4213 udev->lpm_disable_count--; in usb_enable_lpm()
4214 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4218 if (!hcd || !hcd->driver->enable_usb3_lpm_timeout || in usb_enable_lpm()
4219 !hcd->driver->disable_usb3_lpm_timeout) in usb_enable_lpm()
4222 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4225 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4229 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4231 if (port_dev->usb3_lpm_u1_permit) in usb_enable_lpm()
4234 if (port_dev->usb3_lpm_u2_permit) in usb_enable_lpm()
4242 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4247 mutex_lock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4249 mutex_unlock(hcd->bandwidth_mutex); in usb_unlocked_enable_lpm()
4257 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable()
4260 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4261 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_usb3_port_prepare_disable()
4268 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4270 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4319 * USB-3 does not have a similar link state as USB-2 that will avoid negotiating
4320 * a connection with a plugged-in cable but will signal the host when the cable
4321 * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices
4325 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_disable()
4326 struct usb_device *hdev = hub->hdev; in hub_port_disable()
4329 if (!hub->error) { in hub_port_disable()
4330 if (hub_is_superspeed(hub->hdev)) { in hub_port_disable()
4332 ret = hub_set_port_link_state(hub, port_dev->portnum, in hub_port_disable()
4339 if (port_dev->child && set_state) in hub_port_disable()
4340 usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); in hub_port_disable()
4341 if (ret && ret != -ENODEV) in hub_port_disable()
4342 dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); in hub_port_disable()
4347 * usb_port_disable - disable a usb device's upstream port
4355 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4357 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4360 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
4362 * Between connect detection and reset signaling there must be a delay
4363 * of 100ms at least for debounce and power-settling. The corresponding
4366 * Apparently there are some bluetooth and irda-dongles and a number of
4367 * low-speed devices for which this debounce period may last over a second.
4368 * Not covered by the spec - but easy to deal with.
4371 * connection isn't stable by then it returns -ETIMEDOUT. It checks
4381 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_debounce()
4401 usb_clear_port_feature(hub->hdev, port1, in hub_port_debounce()
4410 dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", in hub_port_debounce()
4414 return -ETIMEDOUT; in hub_port_debounce()
4422 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4432 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4438 if (!hcd->driver->address_device && devnum <= 1) in hub_set_address()
4439 return -EINVAL; in hub_set_address()
4440 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4442 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4443 return -EINVAL; in hub_set_address()
4444 if (hcd->driver->address_device) in hub_set_address()
4445 retval = hcd->driver->address_device(hcd, udev); in hub_set_address()
4470 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4473 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4477 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4479 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4481 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4488 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4490 if (!hcd->driver->enable_device) in hub_enable_device()
4492 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4494 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4495 return -EINVAL; in hub_enable_device()
4497 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4504 * If this is called for an already-existing device (as part of
4514 struct usb_device *hdev = hub->hdev; in hub_port_init()
4515 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_init()
4516 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_init()
4518 unsigned delay = HUB_SHORT_RESET_TIME; in hub_port_init() local
4519 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4521 int devnum = udev->devnum; in hub_port_init()
4527 if (!hdev->parent) { in hub_port_init()
4528 delay = HUB_ROOT_RESET_TIME; in hub_port_init()
4529 if (port1 == hdev->bus->otg_port) in hub_port_init()
4530 hdev->bus->b_hnp_enable = 0; in hub_port_init()
4533 /* Some low speed devices have problems with the quick delay, so */ in hub_port_init()
4536 delay = HUB_LONG_RESET_TIME; in hub_port_init()
4538 mutex_lock(hcd->address0_mutex); in hub_port_init()
4542 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4547 retval = -ENODEV; in hub_port_init()
4550 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4551 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4552 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4555 oldspeed = udev->speed; in hub_port_init()
4562 switch (udev->speed) { in hub_port_init()
4566 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4569 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4576 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4579 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4585 if (udev->speed == USB_SPEED_WIRELESS) in hub_port_init()
4588 speed = usb_speed_string(udev->speed); in hub_port_init()
4595 * platform device is usually a dual-role USB controller device. in hub_port_init()
4597 if (udev->bus->controller->driver) in hub_port_init()
4598 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4600 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4602 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4603 dev_info(&udev->dev, in hub_port_init()
4605 (udev->config) ? "reset" : "new", speed, in hub_port_init()
4609 if (hdev->tt) { in hub_port_init()
4610 udev->tt = hdev->tt; in hub_port_init()
4611 udev->ttport = hdev->ttport; in hub_port_init()
4612 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4613 && hdev->speed == USB_SPEED_HIGH) { in hub_port_init()
4614 if (!hub->tt.hub) { in hub_port_init()
4615 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4616 retval = -EINVAL; in hub_port_init()
4619 udev->tt = &hub->tt; in hub_port_init()
4620 udev->ttport = port1; in hub_port_init()
4629 * a 64-byte GET_DESCRIPTOR request. This is what Windows does, in hub_port_init()
4630 * so it may help with some non-standards-compliant devices. in hub_port_init()
4645 dev_err(&udev->dev, in hub_port_init()
4654 retval = -ENOMEM; in hub_port_init()
4663 buf->bMaxPacketSize0 = 0; in hub_port_init()
4669 switch (buf->bMaxPacketSize0) { in hub_port_init()
4671 if (buf->bDescriptorType == in hub_port_init()
4679 r = -EPROTO; in hub_port_init()
4688 if (r == 0 || (r == -ETIMEDOUT && in hub_port_init()
4690 udev->speed > USB_SPEED_FULL)) in hub_port_init()
4693 udev->descriptor.bMaxPacketSize0 = in hub_port_init()
4694 buf->bMaxPacketSize0; in hub_port_init()
4697 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4700 if (oldspeed != udev->speed) { in hub_port_init()
4701 dev_dbg(&udev->dev, in hub_port_init()
4703 retval = -ENODEV; in hub_port_init()
4707 if (r != -ENODEV) in hub_port_init()
4708 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4710 retval = -EMSGSIZE; in hub_port_init()
4721 if (udev->wusb == 0) { in hub_port_init()
4729 if (retval != -ENODEV) in hub_port_init()
4730 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
4734 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
4735 devnum = udev->devnum; in hub_port_init()
4736 dev_info(&udev->dev, in hub_port_init()
4738 (udev->config) ? "reset" : "new", in hub_port_init()
4739 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
4741 (udev->rx_lanes == 2 && udev->tx_lanes == 2) ? in hub_port_init()
4747 * - let SET_ADDRESS settle, some device hardware wants it in hub_port_init()
4748 * - read ep0 maxpacket even for high and low speed, in hub_port_init()
4761 if (retval != -ENODEV) in hub_port_init()
4762 dev_err(&udev->dev, in hub_port_init()
4766 retval = -EMSGSIZE; in hub_port_init()
4768 u32 delay; in hub_port_init() local
4772 delay = udev->parent->hub_delay; in hub_port_init()
4773 udev->hub_delay = min_t(u32, delay, in hub_port_init()
4777 dev_dbg(&udev->dev, in hub_port_init()
4778 "Failed set isoch delay, error %d\n", in hub_port_init()
4794 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
4795 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
4796 dev_err(&udev->dev, "got a wrong device descriptor, " in hub_port_init()
4800 retval = -EINVAL; in hub_port_init()
4804 if (udev->descriptor.bMaxPacketSize0 == 0xff || in hub_port_init()
4805 udev->speed >= USB_SPEED_SUPER) in hub_port_init()
4808 i = udev->descriptor.bMaxPacketSize0; in hub_port_init()
4809 if (usb_endpoint_maxp(&udev->ep0.desc) != i) { in hub_port_init()
4810 if (udev->speed == USB_SPEED_LOW || in hub_port_init()
4812 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); in hub_port_init()
4813 retval = -EMSGSIZE; in hub_port_init()
4816 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
4817 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
4819 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
4820 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
4825 if (retval < (signed)sizeof(udev->descriptor)) { in hub_port_init()
4826 if (retval != -ENODEV) in hub_port_init()
4827 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
4830 retval = -ENOMSG; in hub_port_init()
4836 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
4839 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
4846 if (hcd->driver->update_device) in hub_port_init()
4847 hcd->driver->update_device(hcd, udev); in hub_port_init()
4854 mutex_unlock(hcd->address0_mutex); in hub_port_init()
4864 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
4874 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
4877 if (hub->has_indicators) { in check_highspeed()
4878 hub->indicator[port1-1] = INDICATOR_GREEN_BLINK; in check_highspeed()
4880 &hub->leds, 0); in check_highspeed()
4889 struct usb_device *hdev = hub->hdev; in hub_power_remaining()
4893 if (!hub->limited_power) in hub_power_remaining()
4896 remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; in hub_power_remaining()
4897 for (port1 = 1; port1 <= hdev->maxchild; ++port1) { in hub_power_remaining()
4898 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_power_remaining()
4899 struct usb_device *udev = port_dev->child; in hub_power_remaining()
4914 if (udev->actconfig) in hub_power_remaining()
4915 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
4916 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
4920 if (delta > hub->mA_per_port) in hub_power_remaining()
4921 dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", in hub_power_remaining()
4922 delta, hub->mA_per_port); in hub_power_remaining()
4923 remaining -= delta; in hub_power_remaining()
4926 dev_warn(hub->intfdev, "%dmA over power budget!\n", in hub_power_remaining()
4927 -remaining); in hub_power_remaining()
4936 int status = -ENODEV; in hub_port_connect()
4939 struct usb_device *hdev = hub->hdev; in hub_port_connect()
4940 struct usb_hcd *hcd = bus_to_hcd(hdev->bus); in hub_port_connect()
4941 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect()
4942 struct usb_device *udev = port_dev->child; in hub_port_connect()
4943 static int unreliable_port = -1; in hub_port_connect()
4947 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
4948 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
4949 usb_disconnect(&port_dev->child); in hub_port_connect()
4957 clear_bit(port1, hub->removed_bits); in hub_port_connect()
4963 if (status != -ENODEV && in hub_port_connect()
4966 dev_err(&port_dev->dev, "connect-debounce failed\n"); in hub_port_connect()
4978 test_bit(port1, hub->removed_bits)) { in hub_port_connect()
4986 && !port_dev->port_owner) in hub_port_connect()
4993 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5004 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5006 dev_err(&port_dev->dev, in hub_port_connect()
5012 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5013 udev->level = hdev->level + 1; in hub_port_connect()
5014 udev->wusb = hub_is_wusb(hub); in hub_port_connect()
5017 if (hub_is_superspeed(hub->hdev)) in hub_port_connect()
5018 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5020 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5023 if (udev->devnum <= 0) { in hub_port_connect()
5024 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5028 /* reset (non-USB 3.0 devices) and get descriptor */ in hub_port_connect()
5035 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5038 /* consecutive bus-powered hubs aren't reliable; they can in hub_port_connect()
5041 * (without reading syslog), even without per-port LEDs in hub_port_connect()
5044 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5045 && udev->bus_mA <= unit_load) { in hub_port_connect()
5051 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5055 dev_err(&udev->dev, in hub_port_connect()
5056 "can't connect bus-powered hub " in hub_port_connect()
5058 if (hub->has_indicators) { in hub_port_connect()
5059 hub->indicator[port1-1] = in hub_port_connect()
5063 &hub->leds, 0); in hub_port_connect()
5065 status = -ENOTCONN; /* Don't retry */ in hub_port_connect()
5071 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5072 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5089 if (hdev->state == USB_STATE_NOTATTACHED) in hub_port_connect()
5090 status = -ENOTCONN; in hub_port_connect()
5092 port_dev->child = udev; in hub_port_connect()
5102 port_dev->child = NULL; in hub_port_connect()
5106 if (hcd->usb_phy && !hdev->parent) in hub_port_connect()
5107 usb_phy_notify_connect(hcd->usb_phy, in hub_port_connect()
5108 udev->speed); in hub_port_connect()
5117 dev_dbg(hub->intfdev, "%dmA power budget left\n", status); in hub_port_connect()
5128 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) in hub_port_connect()
5131 /* When halfway through our retry count, power-cycle the port */ in hub_port_connect()
5132 if (i == (SET_CONFIG_TRIES / 2) - 1) { in hub_port_connect()
5133 dev_info(&port_dev->dev, "attempt power cycle\n"); in hub_port_connect()
5140 if (hub->hdev->parent || in hub_port_connect()
5141 !hcd->driver->port_handed_over || in hub_port_connect()
5142 !(hcd->driver->port_handed_over)(hcd, port1)) { in hub_port_connect()
5143 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5144 dev_err(&port_dev->dev, in hub_port_connect()
5150 if (hcd->driver->relinquish_port && !hub->hdev->parent) { in hub_port_connect()
5151 if (status != -ENOTCONN && status != -ENODEV) in hub_port_connect()
5152 hcd->driver->relinquish_port(hcd, port1); in hub_port_connect()
5158 * a port connection-change occurs;
5159 * a port enable-change occurs (often caused by EMI);
5166 __must_hold(&port_dev->status_lock) in hub_port_connect_change()
5168 struct usb_port *port_dev = hub->ports[port1 - 1]; in hub_port_connect_change()
5169 struct usb_device *udev = port_dev->child; in hub_port_connect_change()
5170 int status = -ENODEV; in hub_port_connect_change()
5172 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, in hub_port_connect_change()
5175 if (hub->has_indicators) { in hub_port_connect_change()
5177 hub->indicator[port1-1] = INDICATOR_AUTO; in hub_port_connect_change()
5182 if (hub->hdev->bus->is_b_host) in hub_port_connect_change()
5189 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5193 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5194 udev->persist_enabled) { in hub_port_connect_change()
5206 clear_bit(port1, hub->change_bits); in hub_port_connect_change()
5217 /* Handle notifying userspace about hub over-current events */
5224 sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count"); in port_over_current_notify()
5226 hub_dev = port_dev->dev.parent; in port_over_current_notify()
5231 port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL); in port_over_current_notify()
5240 port_dev->over_current_count); in port_over_current_notify()
5245 kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp); in port_over_current_notify()
5255 __must_hold(&port_dev->status_lock) in port_event()
5258 struct usb_port *port_dev = hub->ports[port1 - 1]; in port_event()
5259 struct usb_device *udev = port_dev->child; in port_event()
5260 struct usb_device *hdev = hub->hdev; in port_event()
5263 connect_change = test_bit(port1, hub->change_bits); in port_event()
5264 clear_bit(port1, hub->event_bits); in port_event()
5265 clear_bit(port1, hub->wakeup_bits); in port_event()
5277 dev_dbg(&port_dev->dev, "enable change, status %08x\n", in port_event()
5288 dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); in port_event()
5295 port_dev->over_current_count++; in port_event()
5298 dev_dbg(&port_dev->dev, "over-current change #%u\n", in port_event()
5299 port_dev->over_current_count); in port_event()
5306 dev_err(&port_dev->dev, "over-current condition\n"); in port_event()
5310 dev_dbg(&port_dev->dev, "reset change\n"); in port_event()
5315 dev_dbg(&port_dev->dev, "warm reset change\n"); in port_event()
5320 dev_dbg(&port_dev->dev, "link state change\n"); in port_event()
5325 dev_warn(&port_dev->dev, "config error\n"); in port_event()
5331 if (!pm_runtime_active(&port_dev->dev)) in port_event()
5342 dev_dbg(&port_dev->dev, "do warm reset\n"); in port_event()
5344 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5373 hdev = hub->hdev; in hub_event()
5374 hub_dev = hub->intfdev; in hub_event()
5378 hdev->state, hdev->maxchild, in hub_event()
5380 (u16) hub->change_bits[0], in hub_event()
5381 (u16) hub->event_bits[0]); in hub_event()
5386 if (unlikely(hub->disconnected)) in hub_event()
5390 if (hdev->state == USB_STATE_NOTATTACHED) { in hub_event()
5391 hub->error = -ENODEV; in hub_event()
5404 if (hub->quiescing) in hub_event()
5407 if (hub->error) { in hub_event()
5408 dev_dbg(hub_dev, "resetting for error %d\n", hub->error); in hub_event()
5416 hub->nerrors = 0; in hub_event()
5417 hub->error = 0; in hub_event()
5421 for (i = 1; i <= hdev->maxchild; i++) { in hub_event()
5422 struct usb_port *port_dev = hub->ports[i - 1]; in hub_event()
5424 if (test_bit(i, hub->event_bits) in hub_event()
5425 || test_bit(i, hub->change_bits) in hub_event()
5426 || test_bit(i, hub->wakeup_bits)) { in hub_event()
5433 * (powered-off), we leave it in that state, run in hub_event()
5436 pm_runtime_get_noresume(&port_dev->dev); in hub_event()
5437 pm_runtime_barrier(&port_dev->dev); in hub_event()
5441 pm_runtime_put_sync(&port_dev->dev); in hub_event()
5446 if (test_and_clear_bit(0, hub->event_bits) == 0) in hub_event()
5456 hub->limited_power = 1; in hub_event()
5458 hub->limited_power = 0; in hub_event()
5464 dev_dbg(hub_dev, "over-current change\n"); in hub_event()
5470 dev_err(hub_dev, "over-current condition\n"); in hub_event()
5480 /* Balance the stuff in kick_hub_wq() and allow autosuspend */ in hub_event()
5482 kref_put(&hub->kref, hub_release); in hub_event()
5519 return -1; in usb_hub_init()
5524 * USB-PERSIST port handover. Otherwise it might see that a full-speed in usb_hub_init()
5526 * over to the companion full-speed controller. in usb_hub_init()
5536 return -1; in usb_hub_init()
5548 * individual hub resources. -greg in usb_hub_cleanup()
5565 if (memcmp(&udev->descriptor, old_device_descriptor, in descriptors_changed()
5569 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5571 if (udev->bos) { in descriptors_changed()
5572 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5573 if (len != le16_to_cpu(old_bos->desc->wTotalLength)) in descriptors_changed()
5575 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5585 if (udev->serial) in descriptors_changed()
5586 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5589 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5590 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5599 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5600 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5604 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5609 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5611 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5613 ((struct usb_config_descriptor *) buf)-> in descriptors_changed()
5621 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5624 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5627 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5628 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5638 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
5641 * WARNING - don't use this routine to reset a composite device
5650 * re-connected. All drivers will be unbound, and the device will be
5651 * re-enumerated and probed all over again.
5653 * Return: 0 if the reset succeeded, -ENODEV if the device has been
5673 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
5675 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
5676 struct usb_device_descriptor descriptor = udev->descriptor; in usb_reset_and_verify_device()
5679 int port1 = udev->portnum; in usb_reset_and_verify_device()
5681 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
5682 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
5683 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
5684 udev->state); in usb_reset_and_verify_device()
5685 return -EINVAL; in usb_reset_and_verify_device()
5689 return -EISDIR; in usb_reset_and_verify_device()
5694 * It will be re-enabled by the enumeration process. in usb_reset_and_verify_device()
5699 * Device-initiated LPM, and system exit latency settings are cleared in usb_reset_and_verify_device()
5704 dev_err(&udev->dev, "%s Failed to disable LPM\n", __func__); in usb_reset_and_verify_device()
5708 bos = udev->bos; in usb_reset_and_verify_device()
5709 udev->bos = NULL; in usb_reset_and_verify_device()
5714 * Other endpoints will be handled by re-enumeration. */ in usb_reset_and_verify_device()
5717 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) in usb_reset_and_verify_device()
5726 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
5727 udev->descriptor = descriptor; /* for disconnect() calls */ in usb_reset_and_verify_device()
5732 if (!udev->actconfig) in usb_reset_and_verify_device()
5735 mutex_lock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5736 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
5738 dev_warn(&udev->dev, in usb_reset_and_verify_device()
5741 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5746 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
5749 dev_err(&udev->dev, in usb_reset_and_verify_device()
5751 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
5752 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5755 mutex_unlock(hcd->bandwidth_mutex); in usb_reset_and_verify_device()
5759 * Don't bother to send the Set-Interface request for interfaces in usb_reset_and_verify_device()
5761 * many devices can't handle it. Instead just reset the host-side in usb_reset_and_verify_device()
5764 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
5765 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
5766 struct usb_interface *intf = config->interface[i]; in usb_reset_and_verify_device()
5769 desc = &intf->cur_altsetting->desc; in usb_reset_and_verify_device()
5770 if (desc->bAlternateSetting == 0) { in usb_reset_and_verify_device()
5779 intf->resetting_device = 1; in usb_reset_and_verify_device()
5780 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
5781 desc->bAlternateSetting); in usb_reset_and_verify_device()
5782 intf->resetting_device = 0; in usb_reset_and_verify_device()
5785 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
5787 desc->bInterfaceNumber, in usb_reset_and_verify_device()
5788 desc->bAlternateSetting, in usb_reset_and_verify_device()
5793 for (j = 0; j < intf->cur_altsetting->desc.bNumEndpoints; j++) in usb_reset_and_verify_device()
5794 intf->cur_altsetting->endpoint[j].streams = 0; in usb_reset_and_verify_device()
5798 /* Now that the alt settings are re-installed, enable LTM and LPM. */ in usb_reset_and_verify_device()
5803 udev->bos = bos; in usb_reset_and_verify_device()
5808 udev->bos = bos; in usb_reset_and_verify_device()
5812 return -ENODEV; in usb_reset_and_verify_device()
5816 * usb_reset_device - warn interface drivers and perform a USB port reset
5842 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
5843 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
5845 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_device()
5846 udev->state == USB_STATE_SUSPENDED) { in usb_reset_device()
5847 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
5848 udev->state); in usb_reset_device()
5849 return -EINVAL; in usb_reset_device()
5852 if (!udev->parent) { in usb_reset_device()
5853 /* this requires hcd-specific logic; see ohci_restart() */ in usb_reset_device()
5854 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
5855 return -EISDIR; in usb_reset_device()
5858 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
5871 /* Prevent autosuspend during the reset */ in usb_reset_device()
5875 for (i = 0; i < config->desc.bNumInterfaces; ++i) { in usb_reset_device()
5876 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
5880 if (cintf->dev.driver) { in usb_reset_device()
5881 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
5882 if (drv->pre_reset && drv->post_reset) in usb_reset_device()
5883 unbind = (drv->pre_reset)(cintf); in usb_reset_device()
5884 else if (cintf->condition == in usb_reset_device()
5898 for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { in usb_reset_device()
5899 struct usb_interface *cintf = config->interface[i]; in usb_reset_device()
5901 int rebind = cintf->needs_binding; in usb_reset_device()
5903 if (!rebind && cintf->dev.driver) { in usb_reset_device()
5904 drv = to_usb_driver(cintf->dev.driver); in usb_reset_device()
5905 if (drv->post_reset) in usb_reset_device()
5906 rebind = (drv->post_reset)(cintf); in usb_reset_device()
5907 else if (cintf->condition == in usb_reset_device()
5911 cintf->needs_binding = 1; in usb_reset_device()
5928 * usb_queue_reset_device - Reset a USB device from an atomic context
5941 * - Scheduling two resets at the same time from two different drivers
5944 * handles ->pre_reset(), the second reset might happen or not.
5946 * - If the reset is delayed so long that the interface is unbound from
5949 * - This function can be called during .probe(). It can also be called
5952 * .disconnect(), call usb_reset_device() directly -- but watch out
5957 if (schedule_work(&iface->reset_ws)) in usb_queue_reset_device()
5963 * usb_hub_find_child - Get the pointer of child device
5973 * child's usb_device pointer if non-NULL.
5980 if (port1 < 1 || port1 > hdev->maxchild) in usb_hub_find_child()
5982 return hub->ports[port1 - 1]->child; in usb_hub_find_child()
5997 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
5998 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6000 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6004 if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { in usb_hub_adjust_deviceremovable()
6005 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6006 desc->u.hs.DeviceRemovable[i/8] |= mask; in usb_hub_adjust_deviceremovable()
6011 u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); in usb_hub_adjust_deviceremovable()
6013 for (i = 1; i <= hdev->maxchild; i++) { in usb_hub_adjust_deviceremovable()
6014 struct usb_port *port_dev = hub->ports[i - 1]; in usb_hub_adjust_deviceremovable()
6016 connect_type = port_dev->connect_type; in usb_hub_adjust_deviceremovable()
6021 … dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); in usb_hub_adjust_deviceremovable()
6027 desc->u.ss.DeviceRemovable = cpu_to_le16(port_removable); in usb_hub_adjust_deviceremovable()
6033 * usb_get_hub_port_acpi_handle - Get the usb port's acpi handle
6048 return ACPI_HANDLE(&hub->ports[port1 - 1]->dev); in usb_get_hub_port_acpi_handle()