Skip to content

Commit 43e53eb

Browse files
matnymangregkh
authored andcommitted
usb: hub: fix detection of high tier USB3 devices behind suspended hubs
commit 8f5b7e2bec1c36578fdaa74a6951833541103e27 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 d717325 commit 43e53eb

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
@@ -66,6 +66,12 @@
6666
*/
6767
#define USB_SHORT_SET_ADDRESS_REQ_TIMEOUT 500 /* ms */
6868

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

10391045
enum hub_activation_type {
10401046
HUB_INIT, HUB_INIT2, HUB_INIT3, /* INITs must come first */
1041-
HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME,
1047+
HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME, HUB_POST_RESUME,
10421048
};
10431049

10441050
static void hub_init_func2(struct work_struct *ws);
10451051
static void hub_init_func3(struct work_struct *ws);
1052+
static void hub_post_resume(struct work_struct *ws);
10461053

10471054
static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
10481055
{
@@ -1065,6 +1072,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
10651072
goto init2;
10661073
goto init3;
10671074
}
1075+
1076+
if (type == HUB_POST_RESUME) {
1077+
usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
1078+
hub_put(hub);
1079+
return;
1080+
}
1081+
10681082
hub_get(hub);
10691083

10701084
/* The superspeed hub except for root hub has to use Hub Depth
@@ -1313,6 +1327,16 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
13131327
device_unlock(&hdev->dev);
13141328
}
13151329

1330+
if (type == HUB_RESUME && hub_is_superspeed(hub->hdev)) {
1331+
/* give usb3 downstream links training time after hub resume */
1332+
INIT_DELAYED_WORK(&hub->init_work, hub_post_resume);
1333+
queue_delayed_work(system_power_efficient_wq, &hub->init_work,
1334+
msecs_to_jiffies(USB_SS_PORT_U0_WAKE_TIME));
1335+
usb_autopm_get_interface_no_resume(
1336+
to_usb_interface(hub->intfdev));
1337+
return;
1338+
}
1339+
13161340
hub_put(hub);
13171341
}
13181342

@@ -1331,6 +1355,13 @@ static void hub_init_func3(struct work_struct *ws)
13311355
hub_activate(hub, HUB_INIT3);
13321356
}
13331357

1358+
static void hub_post_resume(struct work_struct *ws)
1359+
{
1360+
struct usb_hub *hub = container_of(ws, struct usb_hub, init_work.work);
1361+
1362+
hub_activate(hub, HUB_POST_RESUME);
1363+
}
1364+
13341365
enum hub_quiescing_type {
13351366
HUB_DISCONNECT, HUB_PRE_RESET, HUB_SUSPEND
13361367
};

0 commit comments

Comments
 (0)