Lines Matching refs:udev
127 static int usb_reset_and_verify_device(struct usb_device *udev);
154 int usb_device_supports_lpm(struct usb_device *udev) in usb_device_supports_lpm() argument
157 if (udev->quirks & USB_QUIRK_NO_LPM) in usb_device_supports_lpm()
161 if (!udev->bos) in usb_device_supports_lpm()
167 if (udev->speed == USB_SPEED_HIGH || udev->speed == USB_SPEED_FULL) { in usb_device_supports_lpm()
168 if (udev->bos->ext_cap && in usb_device_supports_lpm()
170 le32_to_cpu(udev->bos->ext_cap->bmAttributes))) in usb_device_supports_lpm()
180 if (!udev->bos->ss_cap) { in usb_device_supports_lpm()
181 dev_info(&udev->dev, "No LPM exit latency info found, disabling LPM.\n"); in usb_device_supports_lpm()
185 if (udev->bos->ss_cap->bU1devExitLat == 0 && in usb_device_supports_lpm()
186 udev->bos->ss_cap->bU2DevExitLat == 0) { in usb_device_supports_lpm()
187 if (udev->parent) in usb_device_supports_lpm()
188 dev_info(&udev->dev, "LPM exit latency is zeroed, disabling LPM.\n"); in usb_device_supports_lpm()
190 dev_info(&udev->dev, "We don't know the algorithms for LPM for this host, disabling LPM.\n"); in usb_device_supports_lpm()
194 if (!udev->parent || udev->parent->lpm_capable) in usb_device_supports_lpm()
204 static void usb_set_lpm_mel(struct usb_device *udev, in usb_set_lpm_mel() argument
251 static void usb_set_lpm_pel(struct usb_device *udev, in usb_set_lpm_pel() argument
305 static void usb_set_lpm_sel(struct usb_device *udev, in usb_set_lpm_sel() argument
315 for (parent = udev->parent, num_hubs = 0; parent->parent; in usb_set_lpm_sel()
328 static void usb_set_lpm_parameters(struct usb_device *udev) in usb_set_lpm_parameters() argument
337 if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER) in usb_set_lpm_parameters()
341 if (!udev->bos) in usb_set_lpm_parameters()
344 hub = usb_hub_to_struct_hub(udev->parent); in usb_set_lpm_parameters()
351 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
352 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
353 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; in usb_set_lpm_parameters()
354 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat); in usb_set_lpm_parameters()
356 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
357 hub, &udev->parent->u1_params, hub_u1_del); in usb_set_lpm_parameters()
359 usb_set_lpm_mel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
360 hub, &udev->parent->u2_params, hub_u2_del); in usb_set_lpm_parameters()
381 usb_set_lpm_pel(udev, &udev->u1_params, udev_u1_del, in usb_set_lpm_parameters()
382 hub, &udev->parent->u1_params, hub_u1_del, in usb_set_lpm_parameters()
390 usb_set_lpm_pel(udev, &udev->u2_params, udev_u2_del, in usb_set_lpm_parameters()
391 hub, &udev->parent->u2_params, hub_u2_del, in usb_set_lpm_parameters()
395 usb_set_lpm_sel(udev, &udev->u1_params); in usb_set_lpm_parameters()
396 usb_set_lpm_sel(udev, &udev->u2_params); in usb_set_lpm_parameters()
885 struct usb_device *udev = urb->dev; in usb_hub_clear_tt_buffer() local
887 struct usb_tt *tt = udev->tt; in usb_hub_clear_tt_buffer()
897 dev_err(&udev->dev, "can't save CLEAR_TT_BUFFER state\n"); in usb_hub_clear_tt_buffer()
903 clear->tt = tt->multi ? udev->ttport : 1; in usb_hub_clear_tt_buffer()
905 clear->devinfo |= ((u16)udev->devaddr) << 4; in usb_hub_clear_tt_buffer()
913 clear->hcd = bus_to_hcd(udev->bus); in usb_hub_clear_tt_buffer()
1013 int usb_remove_device(struct usb_device *udev) in usb_remove_device() argument
1019 if (!udev->parent) /* Can't remove a root hub */ in usb_remove_device()
1021 hub = usb_hub_to_struct_hub(udev->parent); in usb_remove_device()
1028 set_bit(udev->portnum, hub->removed_bits); in usb_remove_device()
1029 hub_port_logical_disconnect(hub, udev->portnum); in usb_remove_device()
1143 struct usb_device *udev = port_dev->child; in hub_activate() local
1151 if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) in hub_activate()
1164 !udev || in hub_activate()
1165 udev->state == USB_STATE_NOTATTACHED)) { in hub_activate()
1222 if (!udev || udev->state == USB_STATE_NOTATTACHED) { in hub_activate()
1229 if (udev || (portstatus & USB_PORT_STAT_CONNECTION) || in hub_activate()
1251 } else if (udev->persist_enabled) { in hub_activate()
1253 udev->reset_resume = 1; in hub_activate()
1263 usb_set_device_state(udev, USB_STATE_NOTATTACHED); in hub_activate()
2033 bool usb_device_is_owned(struct usb_device *udev) in usb_device_is_owned() argument
2037 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) in usb_device_is_owned()
2039 hub = usb_hub_to_struct_hub(udev->parent); in usb_device_is_owned()
2040 return !!hub->ports[udev->portnum - 1]->port_owner; in usb_device_is_owned()
2043 static void update_port_device_state(struct usb_device *udev) in update_port_device_state() argument
2048 if (udev->parent) { in update_port_device_state()
2049 hub = usb_hub_to_struct_hub(udev->parent); in update_port_device_state()
2059 port_dev = hub->ports[udev->portnum - 1]; in update_port_device_state()
2060 WRITE_ONCE(port_dev->state, udev->state); in update_port_device_state()
2066 static void recursively_mark_NOTATTACHED(struct usb_device *udev) in recursively_mark_NOTATTACHED() argument
2068 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in recursively_mark_NOTATTACHED()
2071 for (i = 0; i < udev->maxchild; ++i) { in recursively_mark_NOTATTACHED()
2075 if (udev->state == USB_STATE_SUSPENDED) in recursively_mark_NOTATTACHED()
2076 udev->active_duration -= jiffies; in recursively_mark_NOTATTACHED()
2077 udev->state = USB_STATE_NOTATTACHED; in recursively_mark_NOTATTACHED()
2078 update_port_device_state(udev); in recursively_mark_NOTATTACHED()
2102 void usb_set_device_state(struct usb_device *udev, in usb_set_device_state() argument
2109 if (udev->state == USB_STATE_NOTATTACHED) in usb_set_device_state()
2116 if (udev->parent) { in usb_set_device_state()
2117 if (udev->state == USB_STATE_SUSPENDED in usb_set_device_state()
2121 wakeup = (udev->quirks & in usb_set_device_state()
2123 udev->actconfig->desc.bmAttributes & in usb_set_device_state()
2128 if (udev->state == USB_STATE_SUSPENDED && in usb_set_device_state()
2130 udev->active_duration -= jiffies; in usb_set_device_state()
2132 udev->state != USB_STATE_SUSPENDED) in usb_set_device_state()
2133 udev->active_duration += jiffies; in usb_set_device_state()
2134 udev->state = new_state; in usb_set_device_state()
2135 update_port_device_state(udev); in usb_set_device_state()
2137 recursively_mark_NOTATTACHED(udev); in usb_set_device_state()
2140 device_set_wakeup_capable(&udev->dev, wakeup); in usb_set_device_state()
2157 static void choose_devnum(struct usb_device *udev) in choose_devnum() argument
2160 struct usb_bus *bus = udev->bus; in choose_devnum()
2173 udev->devnum = devnum; in choose_devnum()
2178 static void release_devnum(struct usb_device *udev) in release_devnum() argument
2180 if (udev->devnum > 0) { in release_devnum()
2181 clear_bit(udev->devnum, udev->bus->devmap.devicemap); in release_devnum()
2182 udev->devnum = -1; in release_devnum()
2186 static void update_devnum(struct usb_device *udev, int devnum) in update_devnum() argument
2188 udev->devnum = devnum; in update_devnum()
2189 if (!udev->devaddr) in update_devnum()
2190 udev->devaddr = (u8)devnum; in update_devnum()
2193 static void hub_free_dev(struct usb_device *udev) in hub_free_dev() argument
2195 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_free_dev()
2198 if (hcd->driver->free_dev && udev->parent) in hub_free_dev()
2199 hcd->driver->free_dev(hcd, udev); in hub_free_dev()
2202 static void hub_disconnect_children(struct usb_device *udev) in hub_disconnect_children() argument
2204 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in hub_disconnect_children()
2208 for (i = 0; i < udev->maxchild; i++) { in hub_disconnect_children()
2234 struct usb_device *udev = *pdev; in usb_disconnect() local
2242 usb_set_device_state(udev, USB_STATE_NOTATTACHED); in usb_disconnect()
2243 dev_info(&udev->dev, "USB disconnect, device number %d\n", in usb_disconnect()
2244 udev->devnum); in usb_disconnect()
2250 pm_runtime_barrier(&udev->dev); in usb_disconnect()
2252 usb_lock_device(udev); in usb_disconnect()
2254 hub_disconnect_children(udev); in usb_disconnect()
2260 dev_dbg(&udev->dev, "unregistering device\n"); in usb_disconnect()
2261 usb_disable_device(udev, 0); in usb_disconnect()
2262 usb_hcd_synchronize_unlinks(udev); in usb_disconnect()
2264 if (udev->parent) { in usb_disconnect()
2265 port1 = udev->portnum; in usb_disconnect()
2266 hub = usb_hub_to_struct_hub(udev->parent); in usb_disconnect()
2269 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_disconnect()
2280 usb_remove_ep_devs(&udev->ep0); in usb_disconnect()
2281 usb_unlock_device(udev); in usb_disconnect()
2287 device_del(&udev->dev); in usb_disconnect()
2292 release_devnum(udev); in usb_disconnect()
2302 hub_free_dev(udev); in usb_disconnect()
2304 put_device(&udev->dev); in usb_disconnect()
2308 static void show_string(struct usb_device *udev, char *id, char *string) in show_string() argument
2312 dev_info(&udev->dev, "%s: %s\n", id, string); in show_string()
2315 static void announce_device(struct usb_device *udev) in announce_device() argument
2317 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); in announce_device()
2319 dev_info(&udev->dev, in announce_device()
2321 le16_to_cpu(udev->descriptor.idVendor), in announce_device()
2322 le16_to_cpu(udev->descriptor.idProduct), in announce_device()
2324 dev_info(&udev->dev, in announce_device()
2326 udev->descriptor.iManufacturer, in announce_device()
2327 udev->descriptor.iProduct, in announce_device()
2328 udev->descriptor.iSerialNumber); in announce_device()
2329 show_string(udev, "Product", udev->product); in announce_device()
2330 show_string(udev, "Manufacturer", udev->manufacturer); in announce_device()
2331 show_string(udev, "SerialNumber", udev->serial); in announce_device()
2334 static inline void announce_device(struct usb_device *udev) { } in announce_device() argument
2346 static int usb_enumerate_device_otg(struct usb_device *udev) in usb_enumerate_device_otg() argument
2356 if (!udev->bus->is_b_host in usb_enumerate_device_otg()
2357 && udev->config in usb_enumerate_device_otg()
2358 && udev->parent == udev->bus->root_hub) { in usb_enumerate_device_otg()
2360 struct usb_bus *bus = udev->bus; in usb_enumerate_device_otg()
2361 unsigned port1 = udev->portnum; in usb_enumerate_device_otg()
2364 err = __usb_get_extra_descriptor(udev->rawdescriptors[0], in usb_enumerate_device_otg()
2365 le16_to_cpu(udev->config[0].desc.wTotalLength), in usb_enumerate_device_otg()
2370 dev_info(&udev->dev, "Dual-Role OTG device on %sHNP port\n", in usb_enumerate_device_otg()
2376 err = usb_control_msg(udev, in usb_enumerate_device_otg()
2377 usb_sndctrlpipe(udev, 0), in usb_enumerate_device_otg()
2387 dev_err(&udev->dev, "can't set HNP mode: %d\n", in usb_enumerate_device_otg()
2401 err = usb_control_msg(udev, in usb_enumerate_device_otg()
2402 usb_sndctrlpipe(udev, 0), in usb_enumerate_device_otg()
2408 dev_err(&udev->dev, in usb_enumerate_device_otg()
2432 static int usb_enumerate_device(struct usb_device *udev) in usb_enumerate_device() argument
2435 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enumerate_device()
2437 if (udev->config == NULL) { in usb_enumerate_device()
2438 err = usb_get_configuration(udev); in usb_enumerate_device()
2441 dev_err(&udev->dev, "can't read configurations, error %d\n", in usb_enumerate_device()
2448 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); in usb_enumerate_device()
2449 udev->manufacturer = usb_cache_string(udev, in usb_enumerate_device()
2450 udev->descriptor.iManufacturer); in usb_enumerate_device()
2451 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); in usb_enumerate_device()
2453 err = usb_enumerate_device_otg(udev); in usb_enumerate_device()
2458 !is_targeted(udev)) { in usb_enumerate_device()
2462 if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable in usb_enumerate_device()
2463 || udev->bus->is_b_host)) { in usb_enumerate_device()
2464 err = usb_port_suspend(udev, PMSG_AUTO_SUSPEND); in usb_enumerate_device()
2466 dev_dbg(&udev->dev, "HNP fail, %d\n", err); in usb_enumerate_device()
2471 usb_detect_interface_quirks(udev); in usb_enumerate_device()
2476 static void set_usb_port_removable(struct usb_device *udev) in set_usb_port_removable() argument
2478 struct usb_device *hdev = udev->parent; in set_usb_port_removable()
2480 u8 port = udev->portnum; in set_usb_port_removable()
2484 dev_set_removable(&udev->dev, DEVICE_REMOVABLE_UNKNOWN); in set_usb_port_removable()
2489 hub = usb_hub_to_struct_hub(udev->parent); in set_usb_port_removable()
2495 switch (hub->ports[udev->portnum - 1]->connect_type) { in set_usb_port_removable()
2497 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2501 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2526 dev_set_removable(&udev->dev, DEVICE_REMOVABLE); in set_usb_port_removable()
2528 dev_set_removable(&udev->dev, DEVICE_FIXED); in set_usb_port_removable()
2553 int usb_new_device(struct usb_device *udev) in usb_new_device() argument
2557 if (udev->parent) { in usb_new_device()
2562 device_init_wakeup(&udev->dev, 0); in usb_new_device()
2566 pm_runtime_set_active(&udev->dev); in usb_new_device()
2567 pm_runtime_get_noresume(&udev->dev); in usb_new_device()
2568 pm_runtime_use_autosuspend(&udev->dev); in usb_new_device()
2569 pm_runtime_enable(&udev->dev); in usb_new_device()
2574 usb_disable_autosuspend(udev); in usb_new_device()
2576 err = usb_enumerate_device(udev); /* Read descriptors */ in usb_new_device()
2579 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", in usb_new_device()
2580 udev->devnum, udev->bus->busnum, in usb_new_device()
2581 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2583 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, in usb_new_device()
2584 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); in usb_new_device()
2587 announce_device(udev); in usb_new_device()
2589 if (udev->serial) in usb_new_device()
2590 add_device_randomness(udev->serial, strlen(udev->serial)); in usb_new_device()
2591 if (udev->product) in usb_new_device()
2592 add_device_randomness(udev->product, strlen(udev->product)); in usb_new_device()
2593 if (udev->manufacturer) in usb_new_device()
2594 add_device_randomness(udev->manufacturer, in usb_new_device()
2595 strlen(udev->manufacturer)); in usb_new_device()
2597 device_enable_async_suspend(&udev->dev); in usb_new_device()
2600 set_usb_port_removable(udev); in usb_new_device()
2606 err = device_add(&udev->dev); in usb_new_device()
2608 dev_err(&udev->dev, "can't device_add, error %d\n", err); in usb_new_device()
2613 if (udev->parent) { in usb_new_device()
2614 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_new_device()
2615 int port1 = udev->portnum; in usb_new_device()
2618 err = sysfs_create_link(&udev->dev.kobj, in usb_new_device()
2624 &udev->dev.kobj, "device"); in usb_new_device()
2626 sysfs_remove_link(&udev->dev.kobj, "port"); in usb_new_device()
2634 (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); in usb_new_device()
2635 usb_mark_last_busy(udev); in usb_new_device()
2636 pm_runtime_put_sync_autosuspend(&udev->dev); in usb_new_device()
2640 usb_set_device_state(udev, USB_STATE_NOTATTACHED); in usb_new_device()
2641 pm_runtime_disable(&udev->dev); in usb_new_device()
2642 pm_runtime_set_suspended(&udev->dev); in usb_new_device()
2814 static bool use_new_scheme(struct usb_device *udev, int retry, in use_new_scheme() argument
2828 if (udev->speed >= USB_SPEED_SUPER) in use_new_scheme()
2861 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_wait_reset() argument
2930 if (!udev) in hub_port_wait_reset()
2935 udev->rx_lanes = USB_EXT_PORT_RX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2936 udev->tx_lanes = USB_EXT_PORT_TX_LANES(ext_portstatus) + 1; in hub_port_wait_reset()
2937 udev->ssp_rate = get_port_ssp_rate(hub->hdev, ext_portstatus); in hub_port_wait_reset()
2939 udev->rx_lanes = 1; in hub_port_wait_reset()
2940 udev->tx_lanes = 1; in hub_port_wait_reset()
2941 udev->ssp_rate = USB_SSP_GEN_UNKNOWN; in hub_port_wait_reset()
2943 if (udev->ssp_rate != USB_SSP_GEN_UNKNOWN) in hub_port_wait_reset()
2944 udev->speed = USB_SPEED_SUPER_PLUS; in hub_port_wait_reset()
2946 udev->speed = USB_SPEED_SUPER; in hub_port_wait_reset()
2948 udev->speed = USB_SPEED_HIGH; in hub_port_wait_reset()
2950 udev->speed = USB_SPEED_LOW; in hub_port_wait_reset()
2952 udev->speed = USB_SPEED_FULL; in hub_port_wait_reset()
2958 struct usb_device *udev, unsigned int delay, bool warm) in hub_port_reset() argument
3000 status = hub_port_wait_reset(hub, port1, udev, delay, in hub_port_reset()
3025 if (udev) in hub_port_reset()
3075 if (udev) { in hub_port_reset()
3076 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_port_reset()
3078 update_devnum(udev, 0); in hub_port_reset()
3083 hcd->driver->reset_device(hcd, udev); in hub_port_reset()
3085 usb_set_device_state(udev, USB_STATE_DEFAULT); in hub_port_reset()
3088 if (udev) in hub_port_reset()
3089 usb_set_device_state(udev, USB_STATE_NOTATTACHED); in hub_port_reset()
3192 static int check_port_resume_type(struct usb_device *udev, in check_port_resume_type() argument
3201 if (status == 0 && udev->reset_resume in check_port_resume_type()
3223 else if (!(portstatus & USB_PORT_STAT_ENABLE) && !udev->reset_resume) { in check_port_resume_type()
3224 if (udev->persist_enabled) in check_port_resume_type()
3225 udev->reset_resume = 1; in check_port_resume_type()
3233 } else if (udev->reset_resume) { in check_port_resume_type()
3256 int usb_disable_ltm(struct usb_device *udev) in usb_disable_ltm() argument
3258 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_disable_ltm()
3262 !usb_device_supports_ltm(udev)) in usb_disable_ltm()
3268 if (!udev->actconfig) in usb_disable_ltm()
3271 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_disable_ltm()
3278 void usb_enable_ltm(struct usb_device *udev) in usb_enable_ltm() argument
3280 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_enable_ltm()
3284 !usb_device_supports_ltm(udev)) in usb_enable_ltm()
3290 if (!udev->actconfig) in usb_enable_ltm()
3293 usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_enable_ltm()
3310 static int usb_enable_remote_wakeup(struct usb_device *udev) in usb_enable_remote_wakeup() argument
3312 if (udev->speed < USB_SPEED_SUPER) in usb_enable_remote_wakeup()
3313 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_enable_remote_wakeup()
3318 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_enable_remote_wakeup()
3336 static int usb_disable_remote_wakeup(struct usb_device *udev) in usb_disable_remote_wakeup() argument
3338 if (udev->speed < USB_SPEED_SUPER) in usb_disable_remote_wakeup()
3339 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_disable_remote_wakeup()
3344 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_disable_remote_wakeup()
3351 unsigned usb_wakeup_enabled_descendants(struct usb_device *udev) in usb_wakeup_enabled_descendants() argument
3353 struct usb_hub *hub = usb_hub_to_struct_hub(udev); in usb_wakeup_enabled_descendants()
3355 return udev->do_remote_wakeup + in usb_wakeup_enabled_descendants()
3408 int usb_port_suspend(struct usb_device *udev, pm_message_t msg) in usb_port_suspend() argument
3410 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_suspend()
3411 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_suspend()
3412 int port1 = udev->portnum; in usb_port_suspend()
3424 if (udev->do_remote_wakeup) { in usb_port_suspend()
3425 status = usb_enable_remote_wakeup(udev); in usb_port_suspend()
3427 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", in usb_port_suspend()
3436 usb_disable_usb2_hardware_lpm(udev); in usb_port_suspend()
3438 if (usb_disable_ltm(udev)) { in usb_port_suspend()
3439 dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); in usb_port_suspend()
3460 else if (PMSG_IS_AUTO(msg) || usb_wakeup_enabled_descendants(udev) > 0) in usb_port_suspend()
3491 usb_enable_ltm(udev); in usb_port_suspend()
3494 usb_enable_usb2_hardware_lpm(udev); in usb_port_suspend()
3496 if (udev->do_remote_wakeup) in usb_port_suspend()
3497 (void) usb_disable_remote_wakeup(udev); in usb_port_suspend()
3505 dev_dbg(&udev->dev, "usb %ssuspend, wakeup %d\n", in usb_port_suspend()
3507 udev->do_remote_wakeup); in usb_port_suspend()
3509 udev->port_is_suspended = 1; in usb_port_suspend()
3514 usb_set_device_state(udev, USB_STATE_SUSPENDED); in usb_port_suspend()
3517 if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled in usb_port_suspend()
3538 static int finish_port_resume(struct usb_device *udev) in finish_port_resume() argument
3544 dev_dbg(&udev->dev, "%s\n", in finish_port_resume()
3545 udev->reset_resume ? "finish reset-resume" : "finish resume"); in finish_port_resume()
3552 usb_set_device_state(udev, udev->actconfig in finish_port_resume()
3561 if (udev->reset_resume) { in finish_port_resume()
3569 if (udev->quirks & USB_QUIRK_RESET) in finish_port_resume()
3572 status = usb_reset_and_verify_device(udev); in finish_port_resume()
3581 status = usb_get_std_status(udev, USB_RECIP_DEVICE, 0, &devstatus); in finish_port_resume()
3584 if (status && !udev->reset_resume && udev->persist_enabled) { in finish_port_resume()
3585 dev_dbg(&udev->dev, "retry with reset-resume\n"); in finish_port_resume()
3586 udev->reset_resume = 1; in finish_port_resume()
3592 dev_dbg(&udev->dev, "gone after usb resume? status %d\n", in finish_port_resume()
3600 } else if (udev->actconfig && !udev->reset_resume) { in finish_port_resume()
3601 if (udev->speed < USB_SPEED_SUPER) { in finish_port_resume()
3603 status = usb_disable_remote_wakeup(udev); in finish_port_resume()
3605 status = usb_get_std_status(udev, USB_RECIP_INTERFACE, 0, in finish_port_resume()
3609 status = usb_disable_remote_wakeup(udev); in finish_port_resume()
3613 dev_dbg(&udev->dev, in finish_port_resume()
3645 static int wait_for_connected(struct usb_device *udev, in wait_for_connected() argument
3662 dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); in wait_for_connected()
3700 int usb_port_resume(struct usb_device *udev, pm_message_t msg) in usb_port_resume() argument
3702 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_resume()
3703 struct usb_port *port_dev = hub->ports[udev->portnum - 1]; in usb_port_resume()
3704 int port1 = udev->portnum; in usb_port_resume()
3711 dev_dbg(&udev->dev, "can't resume usb port, status %d\n", in usb_port_resume()
3723 pm_wakeup_event(&udev->dev, 0); in usb_port_resume()
3737 dev_dbg(&udev->dev, "usb %sresume\n", in usb_port_resume()
3750 udev->port_is_suspended = 0; in usb_port_resume()
3765 if (udev->persist_enabled) in usb_port_resume()
3766 status = wait_for_connected(udev, hub, port1, &portchange, in usb_port_resume()
3769 status = check_port_resume_type(udev, in usb_port_resume()
3772 status = finish_port_resume(udev); in usb_port_resume()
3774 dev_dbg(&udev->dev, "can't resume, status %d\n", status); in usb_port_resume()
3778 usb_enable_usb2_hardware_lpm(udev); in usb_port_resume()
3781 usb_enable_ltm(udev); in usb_port_resume()
3789 int usb_remote_wakeup(struct usb_device *udev) in usb_remote_wakeup() argument
3793 usb_lock_device(udev); in usb_remote_wakeup()
3794 if (udev->state == USB_STATE_SUSPENDED) { in usb_remote_wakeup()
3795 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); in usb_remote_wakeup()
3796 status = usb_autoresume_device(udev); in usb_remote_wakeup()
3799 usb_autosuspend_device(udev); in usb_remote_wakeup()
3802 usb_unlock_device(udev); in usb_remote_wakeup()
3813 struct usb_device *udev; in hub_handle_remote_wakeup() local
3819 udev = port_dev->child; in hub_handle_remote_wakeup()
3826 if (!udev || udev->state != USB_STATE_SUSPENDED || in hub_handle_remote_wakeup()
3833 if (udev) { in hub_handle_remote_wakeup()
3838 ret = usb_remote_wakeup(udev); in hub_handle_remote_wakeup()
3878 struct usb_device *udev = port_dev->child; in hub_suspend() local
3880 if (udev && udev->can_submit) { in hub_suspend()
3882 dev_name(&udev->dev)); in hub_suspend()
3886 if (udev) in hub_suspend()
3888 usb_wakeup_enabled_descendants(udev); in hub_suspend()
3923 struct usb_device *udev; in report_wakeup_requests() local
3945 udev = hub->ports[i]->child; in report_wakeup_requests()
3946 if (udev) in report_wakeup_requests()
3947 pm_wakeup_event(&udev->dev, 0); in report_wakeup_requests()
4013 static int usb_req_set_sel(struct usb_device *udev) in usb_req_set_sel() argument
4022 if (!udev->parent || udev->speed < USB_SPEED_SUPER || !udev->lpm_capable) in usb_req_set_sel()
4026 u1_sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_req_set_sel()
4027 u1_pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in usb_req_set_sel()
4028 u2_sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_req_set_sel()
4029 u2_pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in usb_req_set_sel()
4043 dev_dbg(&udev->dev, "Device-initiated U1/U2 disabled due to long SEL or PEL\n"); in usb_req_set_sel()
4061 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_req_set_sel()
4070 udev->lpm_devinit_allow = 1; in usb_req_set_sel()
4078 static int usb_set_device_initiated_lpm(struct usb_device *udev, in usb_set_device_initiated_lpm() argument
4092 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", in usb_set_device_initiated_lpm()
4097 if (udev->state != USB_STATE_CONFIGURED) { in usb_set_device_initiated_lpm()
4098 dev_dbg(&udev->dev, "%s: Can't %s %s state " in usb_set_device_initiated_lpm()
4110 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_set_device_initiated_lpm()
4117 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_set_device_initiated_lpm()
4125 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", in usb_set_device_initiated_lpm()
4133 static int usb_set_lpm_timeout(struct usb_device *udev, in usb_set_lpm_timeout() argument
4147 dev_warn(&udev->dev, "%s: Can't set timeout for non-U1 or U2 state.\n", in usb_set_lpm_timeout()
4154 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x, " in usb_set_lpm_timeout()
4160 ret = set_port_feature(udev->parent, in usb_set_lpm_timeout()
4161 USB_PORT_LPM_TIMEOUT(timeout) | udev->portnum, in usb_set_lpm_timeout()
4164 dev_warn(&udev->dev, "Failed to set %s timeout to 0x%x," in usb_set_lpm_timeout()
4170 udev->u1_params.timeout = timeout; in usb_set_lpm_timeout()
4172 udev->u2_params.timeout = timeout; in usb_set_lpm_timeout()
4181 static bool usb_device_may_initiate_lpm(struct usb_device *udev, in usb_device_may_initiate_lpm() argument
4187 if (!udev->lpm_devinit_allow) in usb_device_may_initiate_lpm()
4191 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in usb_device_may_initiate_lpm()
4193 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in usb_device_may_initiate_lpm()
4197 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_device_may_initiate_lpm()
4202 intf = udev->actconfig->interface[i]; in usb_device_may_initiate_lpm()
4235 static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, in usb_enable_link_state() argument
4243 if (!udev->bos) in usb_enable_link_state()
4246 u1_mel = udev->bos->ss_cap->bU1devExitLat; in usb_enable_link_state()
4247 u2_mel = udev->bos->ss_cap->bU2DevExitLat; in usb_enable_link_state()
4262 timeout = hcd->driver->enable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4269 dev_warn(&udev->dev, "Could not enable %s link state, " in usb_enable_link_state()
4275 if (usb_set_lpm_timeout(udev, state, timeout)) { in usb_enable_link_state()
4280 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4287 if (udev->actconfig && in usb_enable_link_state()
4288 usb_device_may_initiate_lpm(udev, state)) { in usb_enable_link_state()
4289 if (usb_set_device_initiated_lpm(udev, state, true)) { in usb_enable_link_state()
4294 usb_set_lpm_timeout(udev, state, 0); in usb_enable_link_state()
4295 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); in usb_enable_link_state()
4301 udev->usb3_lpm_u1_enabled = 1; in usb_enable_link_state()
4303 udev->usb3_lpm_u2_enabled = 1; in usb_enable_link_state()
4320 static int usb_disable_link_state(struct usb_hcd *hcd, struct usb_device *udev, in usb_disable_link_state() argument
4328 dev_warn(&udev->dev, "%s: Can't disable non-U1 or U2 state.\n", in usb_disable_link_state()
4333 if (usb_set_lpm_timeout(udev, state, 0)) in usb_disable_link_state()
4336 usb_set_device_initiated_lpm(udev, state, false); in usb_disable_link_state()
4338 if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) in usb_disable_link_state()
4339 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " in usb_disable_link_state()
4350 udev->usb3_lpm_u1_enabled = 0; in usb_disable_link_state()
4352 udev->usb3_lpm_u2_enabled = 0; in usb_disable_link_state()
4364 int usb_disable_lpm(struct usb_device *udev) in usb_disable_lpm() argument
4368 if (!udev || !udev->parent || in usb_disable_lpm()
4369 udev->speed < USB_SPEED_SUPER || in usb_disable_lpm()
4370 !udev->lpm_capable || in usb_disable_lpm()
4371 udev->state < USB_STATE_CONFIGURED) in usb_disable_lpm()
4374 hcd = bus_to_hcd(udev->bus); in usb_disable_lpm()
4378 udev->lpm_disable_count++; in usb_disable_lpm()
4379 if ((udev->u1_params.timeout == 0 && udev->u2_params.timeout == 0)) in usb_disable_lpm()
4383 if (usb_disable_link_state(hcd, udev, USB3_LPM_U1)) in usb_disable_lpm()
4385 if (usb_disable_link_state(hcd, udev, USB3_LPM_U2)) in usb_disable_lpm()
4391 usb_enable_lpm(udev); in usb_disable_lpm()
4397 int usb_unlocked_disable_lpm(struct usb_device *udev) in usb_unlocked_disable_lpm() argument
4399 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_disable_lpm()
4406 ret = usb_disable_lpm(udev); in usb_unlocked_disable_lpm()
4421 void usb_enable_lpm(struct usb_device *udev) in usb_enable_lpm() argument
4427 if (!udev || !udev->parent || in usb_enable_lpm()
4428 udev->speed < USB_SPEED_SUPER || in usb_enable_lpm()
4429 !udev->lpm_capable || in usb_enable_lpm()
4430 udev->state < USB_STATE_CONFIGURED) in usb_enable_lpm()
4433 udev->lpm_disable_count--; in usb_enable_lpm()
4434 hcd = bus_to_hcd(udev->bus); in usb_enable_lpm()
4442 if (udev->lpm_disable_count > 0) in usb_enable_lpm()
4445 hub = usb_hub_to_struct_hub(udev->parent); in usb_enable_lpm()
4449 port_dev = hub->ports[udev->portnum - 1]; in usb_enable_lpm()
4452 usb_enable_link_state(hcd, udev, USB3_LPM_U1); in usb_enable_lpm()
4455 usb_enable_link_state(hcd, udev, USB3_LPM_U2); in usb_enable_lpm()
4460 void usb_unlocked_enable_lpm(struct usb_device *udev) in usb_unlocked_enable_lpm() argument
4462 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_unlocked_enable_lpm()
4468 usb_enable_lpm(udev); in usb_unlocked_enable_lpm()
4477 struct usb_device *udev = port_dev->child; in hub_usb3_port_prepare_disable() local
4480 if (udev && udev->port_is_suspended && udev->do_remote_wakeup) { in hub_usb3_port_prepare_disable()
4485 ret = usb_disable_remote_wakeup(udev); in hub_usb3_port_prepare_disable()
4488 dev_warn(&udev->dev, in hub_usb3_port_prepare_disable()
4490 udev->do_remote_wakeup = 0; in hub_usb3_port_prepare_disable()
4503 int usb_disable_lpm(struct usb_device *udev) in usb_disable_lpm() argument
4509 void usb_enable_lpm(struct usb_device *udev) { } in usb_enable_lpm() argument
4512 int usb_unlocked_disable_lpm(struct usb_device *udev) in usb_unlocked_disable_lpm() argument
4518 void usb_unlocked_enable_lpm(struct usb_device *udev) { } in usb_unlocked_enable_lpm() argument
4521 int usb_disable_ltm(struct usb_device *udev) in usb_disable_ltm() argument
4527 void usb_enable_ltm(struct usb_device *udev) { } in usb_enable_ltm() argument
4536 static int usb_req_set_sel(struct usb_device *udev) in usb_req_set_sel() argument
4578 int usb_port_disable(struct usb_device *udev) in usb_port_disable() argument
4580 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_port_disable()
4582 return hub_port_disable(hub, udev->portnum, 0); in usb_port_disable()
4643 void usb_ep0_reinit(struct usb_device *udev) in usb_ep0_reinit() argument
4645 usb_disable_endpoint(udev, 0 + USB_DIR_IN, true); in usb_ep0_reinit()
4646 usb_disable_endpoint(udev, 0 + USB_DIR_OUT, true); in usb_ep0_reinit()
4647 usb_enable_endpoint(udev, &udev->ep0, true); in usb_ep0_reinit()
4654 static int hub_set_address(struct usb_device *udev, int devnum) in hub_set_address() argument
4657 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_set_address()
4665 if (udev->state == USB_STATE_ADDRESS) in hub_set_address()
4667 if (udev->state != USB_STATE_DEFAULT) in hub_set_address()
4670 retval = hcd->driver->address_device(hcd, udev); in hub_set_address()
4672 retval = usb_control_msg(udev, usb_sndaddr0pipe(), in hub_set_address()
4676 update_devnum(udev, devnum); in hub_set_address()
4678 usb_set_device_state(udev, USB_STATE_ADDRESS); in hub_set_address()
4679 usb_ep0_reinit(udev); in hub_set_address()
4693 static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) in hub_set_initial_usb2_lpm_policy() argument
4695 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in hub_set_initial_usb2_lpm_policy()
4698 if (!udev->usb2_hw_lpm_capable || !udev->bos) in hub_set_initial_usb2_lpm_policy()
4702 connect_type = hub->ports[udev->portnum - 1]->connect_type; in hub_set_initial_usb2_lpm_policy()
4704 if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || in hub_set_initial_usb2_lpm_policy()
4706 udev->usb2_hw_lpm_allowed = 1; in hub_set_initial_usb2_lpm_policy()
4707 usb_enable_usb2_hardware_lpm(udev); in hub_set_initial_usb2_lpm_policy()
4711 static int hub_enable_device(struct usb_device *udev) in hub_enable_device() argument
4713 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in hub_enable_device()
4717 if (udev->state == USB_STATE_ADDRESS) in hub_enable_device()
4719 if (udev->state != USB_STATE_DEFAULT) in hub_enable_device()
4722 return hcd->driver->enable_device(hcd, udev); in hub_enable_device()
4740 static int get_bMaxPacketSize0(struct usb_device *udev, in get_bMaxPacketSize0() argument
4753 rc = usb_control_msg(udev, usb_rcvaddr0pipe(), in get_bMaxPacketSize0()
4778 udev->speed > USB_SPEED_FULL)) in get_bMaxPacketSize0()
4804 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, in hub_port_init() argument
4812 enum usb_device_speed oldspeed = udev->speed; in hub_port_init()
4814 int devnum = udev->devnum; in hub_port_init()
4841 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4849 if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed && in hub_port_init()
4850 !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) { in hub_port_init()
4851 dev_dbg(&udev->dev, "device reset changed speed!\n"); in hub_port_init()
4854 oldspeed = udev->speed; in hub_port_init()
4860 switch (udev->speed) { in hub_port_init()
4863 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); in hub_port_init()
4866 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4873 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in hub_port_init()
4876 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); in hub_port_init()
4883 speed = usb_speed_string(udev->speed); in hub_port_init()
4892 if (udev->bus->controller->driver) in hub_port_init()
4893 driver_name = udev->bus->controller->driver->name; in hub_port_init()
4895 driver_name = udev->bus->sysdev->driver->name; in hub_port_init()
4897 if (udev->speed < USB_SPEED_SUPER) in hub_port_init()
4898 dev_info(&udev->dev, in hub_port_init()
4906 udev->tt = hdev->tt; in hub_port_init()
4907 udev->ttport = hdev->ttport; in hub_port_init()
4908 } else if (udev->speed != USB_SPEED_HIGH in hub_port_init()
4911 dev_err(&udev->dev, "parent hub has no TT\n"); in hub_port_init()
4915 udev->tt = &hub->tt; in hub_port_init()
4916 udev->ttport = port1; in hub_port_init()
4932 do_new_scheme = use_new_scheme(udev, retry_counter, port_dev); in hub_port_init()
4941 retval = hub_enable_device(udev); in hub_port_init()
4943 dev_err(&udev->dev, in hub_port_init()
4949 maxp0 = get_bMaxPacketSize0(udev, buf, in hub_port_init()
4952 maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
4953 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
4958 retval = hub_port_reset(hub, port1, udev, delay, false); in hub_port_init()
4961 if (oldspeed != udev->speed) { in hub_port_init()
4962 dev_dbg(&udev->dev, in hub_port_init()
4969 dev_err(&udev->dev, "device descriptor read/64, error %d\n", in hub_port_init()
4977 retval = hub_set_address(udev, devnum); in hub_port_init()
4984 dev_err(&udev->dev, "device not accepting address %d, error %d\n", in hub_port_init()
4988 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
4989 devnum = udev->devnum; in hub_port_init()
4990 dev_info(&udev->dev, in hub_port_init()
4992 (udev->config) ? "reset" : "new", in hub_port_init()
4993 (udev->speed == USB_SPEED_SUPER_PLUS) ? in hub_port_init()
4995 (udev->ssp_rate == USB_SSP_GEN_2x2) ? in hub_port_init()
4997 (udev->ssp_rate == USB_SSP_GEN_2x1) ? in hub_port_init()
4999 (udev->ssp_rate == USB_SSP_GEN_1x2) ? in hub_port_init()
5014 maxp0 = get_bMaxPacketSize0(udev, buf, 8, retries == 0); in hub_port_init()
5018 dev_err(&udev->dev, in hub_port_init()
5024 if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { in hub_port_init()
5025 dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); in hub_port_init()
5030 delay = udev->parent->hub_delay; in hub_port_init()
5031 udev->hub_delay = min_t(u32, delay, in hub_port_init()
5033 retval = usb_set_isoch_delay(udev); in hub_port_init()
5035 dev_dbg(&udev->dev, in hub_port_init()
5052 if (udev->speed >= USB_SPEED_SUPER) { in hub_port_init()
5058 if (usb_endpoint_maxp(&udev->ep0.desc) == i) { in hub_port_init()
5060 } else if ((udev->speed == USB_SPEED_FULL || in hub_port_init()
5061 udev->speed == USB_SPEED_HIGH) && in hub_port_init()
5064 if (udev->speed == USB_SPEED_FULL) in hub_port_init()
5065 dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); in hub_port_init()
5067 dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); in hub_port_init()
5068 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); in hub_port_init()
5069 usb_ep0_reinit(udev); in hub_port_init()
5072 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); in hub_port_init()
5077 descr = usb_get_device_descriptor(udev); in hub_port_init()
5081 dev_err(&udev->dev, "device descriptor read/all, error %d\n", in hub_port_init()
5086 udev->descriptor = *descr; in hub_port_init()
5097 if ((udev->speed >= USB_SPEED_SUPER) && in hub_port_init()
5098 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { in hub_port_init()
5099 dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); in hub_port_init()
5100 hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); in hub_port_init()
5105 usb_detect_quirks(udev); in hub_port_init()
5107 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) { in hub_port_init()
5108 retval = usb_get_bos_descriptor(udev); in hub_port_init()
5110 udev->lpm_capable = usb_device_supports_lpm(udev); in hub_port_init()
5111 udev->lpm_disable_count = 1; in hub_port_init()
5112 usb_set_lpm_parameters(udev); in hub_port_init()
5113 usb_req_set_sel(udev); in hub_port_init()
5120 hcd->driver->update_device(hcd, udev); in hub_port_init()
5121 hub_set_initial_usb2_lpm_policy(udev); in hub_port_init()
5125 update_devnum(udev, devnum); /* for disconnect processing */ in hub_port_init()
5132 check_highspeed(struct usb_hub *hub, struct usb_device *udev, int port1) in check_highspeed() argument
5137 if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) in check_highspeed()
5144 status = usb_get_descriptor(udev, USB_DT_DEVICE_QUALIFIER, 0, in check_highspeed()
5147 dev_info(&udev->dev, "not running at top speed; " in check_highspeed()
5172 struct usb_device *udev = port_dev->child; in hub_power_remaining() local
5176 if (!udev) in hub_power_remaining()
5178 if (hub_is_superspeed(udev)) in hub_power_remaining()
5187 if (udev->actconfig) in hub_power_remaining()
5188 delta = usb_get_max_power(udev, udev->actconfig); in hub_power_remaining()
5189 else if (port1 != udev->bus->otg_port || hdev->parent) in hub_power_remaining()
5207 static int descriptors_changed(struct usb_device *udev, in descriptors_changed() argument
5219 if (memcmp(&udev->descriptor, new_device_descriptor, in descriptors_changed()
5223 if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) in descriptors_changed()
5225 if (udev->bos) { in descriptors_changed()
5226 len = le16_to_cpu(udev->bos->desc->wTotalLength); in descriptors_changed()
5229 if (memcmp(udev->bos->desc, old_bos->desc, len)) in descriptors_changed()
5239 if (udev->serial) in descriptors_changed()
5240 serial_len = strlen(udev->serial) + 1; in descriptors_changed()
5243 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5244 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5253 for (index = 0; index < udev->descriptor.bNumConfigurations; index++) { in descriptors_changed()
5254 old_length = le16_to_cpu(udev->config[index].desc.wTotalLength); in descriptors_changed()
5255 length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf, in descriptors_changed()
5258 dev_dbg(&udev->dev, "config index %d, error %d\n", in descriptors_changed()
5263 if (memcmp(buf, udev->rawdescriptors[index], old_length) in descriptors_changed()
5265 dev_dbg(&udev->dev, "config index %d changed (#%d)\n", in descriptors_changed()
5275 length = usb_string(udev, udev->descriptor.iSerialNumber, in descriptors_changed()
5278 dev_dbg(&udev->dev, "serial string error %d\n", in descriptors_changed()
5281 } else if (memcmp(buf, udev->serial, length) != 0) { in descriptors_changed()
5282 dev_dbg(&udev->dev, "serial string changed\n"); in descriptors_changed()
5300 struct usb_device *udev = port_dev->child; in hub_port_connect() local
5305 if (udev) { in hub_port_connect()
5307 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); in hub_port_connect()
5371 udev = usb_alloc_dev(hdev, hdev->bus, port1); in hub_port_connect()
5372 if (!udev) { in hub_port_connect()
5380 usb_set_device_state(udev, USB_STATE_POWERED); in hub_port_connect()
5381 udev->bus_mA = hub->mA_per_port; in hub_port_connect()
5382 udev->level = hdev->level + 1; in hub_port_connect()
5386 udev->speed = USB_SPEED_SUPER; in hub_port_connect()
5388 udev->speed = USB_SPEED_UNKNOWN; in hub_port_connect()
5390 choose_devnum(udev); in hub_port_connect()
5391 if (udev->devnum <= 0) { in hub_port_connect()
5397 status = hub_port_init(hub, udev, port1, i, NULL); in hub_port_connect()
5405 if (udev->quirks & USB_QUIRK_DELAY_INIT) in hub_port_connect()
5414 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB in hub_port_connect()
5415 && udev->bus_mA <= unit_load) { in hub_port_connect()
5418 status = usb_get_std_status(udev, USB_RECIP_DEVICE, 0, in hub_port_connect()
5421 dev_dbg(&udev->dev, "get status %d ?\n", status); in hub_port_connect()
5425 dev_err(&udev->dev, in hub_port_connect()
5441 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 in hub_port_connect()
5442 && udev->speed == USB_SPEED_FULL in hub_port_connect()
5444 check_highspeed(hub, udev, port1); in hub_port_connect()
5462 port_dev->child = udev; in hub_port_connect()
5468 status = usb_new_device(udev); in hub_port_connect()
5478 udev->speed); in hub_port_connect()
5494 usb_ep0_reinit(udev); in hub_port_connect()
5495 release_devnum(udev); in hub_port_connect()
5496 hub_free_dev(udev); in hub_port_connect()
5501 usb_put_dev(udev); in hub_port_connect()
5543 struct usb_device *udev = port_dev->child; in hub_port_connect_change() local
5563 if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && in hub_port_connect_change()
5564 udev->state != USB_STATE_NOTATTACHED) { in hub_port_connect_change()
5572 descr = usb_get_device_descriptor(udev); in hub_port_connect_change()
5574 dev_dbg(&udev->dev, in hub_port_connect_change()
5578 if (descriptors_changed(udev, descr, in hub_port_connect_change()
5579 udev->bos)) { in hub_port_connect_change()
5580 dev_dbg(&udev->dev, in hub_port_connect_change()
5588 } else if (udev->state == USB_STATE_SUSPENDED && in hub_port_connect_change()
5589 udev->persist_enabled) { in hub_port_connect_change()
5594 status = usb_remote_wakeup(udev); in hub_port_connect_change()
5652 struct usb_device *udev = port_dev->child; in port_event() local
5681 && !connect_change && udev) { in port_event()
5742 if ((i++ < DETECT_DISCONNECT_TRIES) && udev) { in port_event()
5749 } else if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION) in port_event()
5750 || udev->state == USB_STATE_NOTATTACHED) { in port_event()
5758 usb_lock_device(udev); in port_event()
5759 usb_reset_device(udev); in port_event()
5760 usb_unlock_device(udev); in port_event()
6037 static int usb_reset_and_verify_device(struct usb_device *udev) in usb_reset_and_verify_device() argument
6039 struct usb_device *parent_hdev = udev->parent; in usb_reset_and_verify_device()
6041 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_reset_and_verify_device()
6045 int port1 = udev->portnum; in usb_reset_and_verify_device()
6047 if (udev->state == USB_STATE_NOTATTACHED || in usb_reset_and_verify_device()
6048 udev->state == USB_STATE_SUSPENDED) { in usb_reset_and_verify_device()
6049 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_and_verify_device()
6050 udev->state); in usb_reset_and_verify_device()
6062 usb_disable_usb2_hardware_lpm(udev); in usb_reset_and_verify_device()
6064 bos = udev->bos; in usb_reset_and_verify_device()
6065 udev->bos = NULL; in usb_reset_and_verify_device()
6077 usb_ep0_reinit(udev); in usb_reset_and_verify_device()
6078 ret = hub_port_init(parent_hub, udev, port1, i, &descriptor); in usb_reset_and_verify_device()
6088 if (descriptors_changed(udev, &descriptor, bos)) { in usb_reset_and_verify_device()
6089 dev_info(&udev->dev, "device firmware changed\n"); in usb_reset_and_verify_device()
6094 if (!udev->actconfig) in usb_reset_and_verify_device()
6098 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); in usb_reset_and_verify_device()
6100 dev_warn(&udev->dev, in usb_reset_and_verify_device()
6106 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), in usb_reset_and_verify_device()
6108 udev->actconfig->desc.bConfigurationValue, 0, in usb_reset_and_verify_device()
6111 dev_err(&udev->dev, in usb_reset_and_verify_device()
6113 udev->actconfig->desc.bConfigurationValue, ret); in usb_reset_and_verify_device()
6118 usb_set_device_state(udev, USB_STATE_CONFIGURED); in usb_reset_and_verify_device()
6126 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { in usb_reset_and_verify_device()
6127 struct usb_host_config *config = udev->actconfig; in usb_reset_and_verify_device()
6133 usb_disable_interface(udev, intf, true); in usb_reset_and_verify_device()
6134 usb_enable_interface(udev, intf, true); in usb_reset_and_verify_device()
6142 ret = usb_set_interface(udev, desc->bInterfaceNumber, in usb_reset_and_verify_device()
6147 dev_err(&udev->dev, "failed to restore interface %d " in usb_reset_and_verify_device()
6161 usb_enable_usb2_hardware_lpm(udev); in usb_reset_and_verify_device()
6162 usb_unlocked_enable_lpm(udev); in usb_reset_and_verify_device()
6163 usb_enable_ltm(udev); in usb_reset_and_verify_device()
6164 usb_release_bos_descriptor(udev); in usb_reset_and_verify_device()
6165 udev->bos = bos; in usb_reset_and_verify_device()
6169 usb_release_bos_descriptor(udev); in usb_reset_and_verify_device()
6170 udev->bos = bos; in usb_reset_and_verify_device()
6201 int usb_reset_device(struct usb_device *udev) in usb_reset_device() argument
6207 struct usb_host_config *config = udev->actconfig; in usb_reset_device()
6208 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); in usb_reset_device()
6210 if (udev->state == USB_STATE_NOTATTACHED) { in usb_reset_device()
6211 dev_dbg(&udev->dev, "device reset not allowed in state %d\n", in usb_reset_device()
6212 udev->state); in usb_reset_device()
6216 if (!udev->parent) { in usb_reset_device()
6218 dev_dbg(&udev->dev, "%s for root hub!\n", __func__); in usb_reset_device()
6222 if (udev->reset_in_progress) in usb_reset_device()
6224 udev->reset_in_progress = 1; in usb_reset_device()
6226 port_dev = hub->ports[udev->portnum - 1]; in usb_reset_device()
6240 usb_autoresume_device(udev); in usb_reset_device()
6262 ret = usb_reset_and_verify_device(udev); in usb_reset_device()
6285 usb_unbind_and_rebind_marked_interfaces(udev); in usb_reset_device()
6288 usb_autosuspend_device(udev); in usb_reset_device()
6290 udev->reset_in_progress = 0; in usb_reset_device()