Skip to content

Commit aec11e5

Browse files
matnymangregkh
authored andcommitted
usb: hub: fix detection of high tier USB3 devices behind suspended hubs
commit 8f5b7e2 upstream. USB3 devices connected behind several external suspended hubs may not be detected when plugged in due to aggressive hub runtime pm suspend. The hub driver immediately runtime-suspends hubs if there are no active children or port activity. There is a delay between the wake signal causing hub resume, and driver visible port activity on the hub downstream facing ports. Most of the LFPS handshake, resume signaling and link training done on the downstream ports is not visible to the hub driver until completed, when device then will appear fully enabled and running on the port. This delay between wake signal and detectable port change is even more significant with chained suspended hubs where the wake signal will propagate upstream first. Suspended hubs will only start resuming downstream ports after upstream facing port resumes. The hub driver may resume a USB3 hub, read status of all ports, not yet see any activity, and runtime suspend back the hub before any port activity is visible. This exact case was seen when conncting USB3 devices to a suspended Thunderbolt dock. USB3 specification defines a 100ms tU3WakeupRetryDelay, indicating USB3 devices expect to be resumed within 100ms after signaling wake. if not then device will resend the wake signal. Give the USB3 hubs twice this time (200ms) to detect any port changes after resume, before allowing hub to runtime suspend again. Cc: stable <[email protected]> Fixes: 2839f5b ("USB: Turn on auto-suspend for USB 3.0 hubs.") Acked-by: Alan Stern <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ee56da9 commit aec11e5

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

drivers/usb/core/hub.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
*/
6868
#define USB_SHORT_SET_ADDRESS_REQ_TIMEOUT 500 /* ms */
6969

70+
/*
71+
* Give SS hubs 200ms time after wake to train downstream links before
72+
* assuming no port activity and allowing hub to runtime suspend back.
73+
*/
74+
#define USB_SS_PORT_U0_WAKE_TIME 200 /* ms */
75+
7076
/* Protect struct usb_device->state and ->children members
7177
* Note: Both are also protected by ->dev.sem, except that ->state can
7278
* change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */
@@ -1067,11 +1073,12 @@ int usb_remove_device(struct usb_device *udev)
10671073

10681074
enum hub_activation_type {
10691075
HUB_INIT, HUB_INIT2, HUB_INIT3, /* INITs must come first */
1070-
HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME,
1076+
HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME, HUB_POST_RESUME,
10711077
};
10721078

10731079
static void hub_init_func2(struct work_struct *ws);
10741080
static void hub_init_func3(struct work_struct *ws);
1081+
static void hub_post_resume(struct work_struct *ws);
10751082

10761083
static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
10771084
{
@@ -1094,6 +1101,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
10941101
goto init2;
10951102
goto init3;
10961103
}
1104+
1105+
if (type == HUB_POST_RESUME) {
1106+
usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1107+
hub_put(hub);
1108+
return;
1109+
}
1110+
10971111
hub_get(hub);
10981112

10991113
/* The superspeed hub except for root hub has to use Hub Depth
@@ -1342,6 +1356,16 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
13421356
device_unlock(&hdev->dev);
13431357
}
13441358

1359+
if (type == HUB_RESUME && hub_is_superspeed(hub->hdev)) {
1360+
/* give usb3 downstream links training time after hub resume */
1361+
INIT_DELAYED_WORK(&hub->init_work, hub_post_resume);
1362+
queue_delayed_work(system_power_efficient_wq, &hub->init_work,
1363+
msecs_to_jiffies(USB_SS_PORT_U0_WAKE_TIME));
1364+
usb_autopm_get_interface_no_resume(
1365+
to_usb_interface(hub->intfdev));
1366+
return;
1367+
}
1368+
13451369
hub_put(hub);
13461370
}
13471371

@@ -1360,6 +1384,13 @@ static void hub_init_func3(struct work_struct *ws)
13601384
hub_activate(hub, HUB_INIT3);
13611385
}
13621386

1387+
static void hub_post_resume(struct work_struct *ws)
1388+
{
1389+
struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1390+
1391+
hub_activate(hub, HUB_POST_RESUME);
1392+
}
1393+
13631394
enum hub_quiescing_type {
13641395
HUB_DISCONNECT, HUB_PRE_RESET, HUB_SUSPEND
13651396
};

0 commit comments

Comments
 (0)