[PATCH v4 13/14] thunderbolt: Decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP

From: Chunfeng Yun

Date: Sat Dec 05 2026 - 03:34:50 EST


When a USB4 router wakes up due to a device disconnect, there is no need
to wait the full 2 seconds in TB_PORT_UNPLUGGED.

Although the USB4 specification does not define an overall timeout for
Phases 2-4 (before the port transitions from CLd/TB_PORT_UNPLUGGED to
Training/TB_PORT_CONNECTING), empirical testing across various devices
shows that Phases 2-4 typically take at most ~200ms after router resume.

Wait at most 400ms (2x margin) for the port to leave TB_PORT_UNPLUGGED;
if it remains in TB_PORT_UNPLUGGED after that, treat it as disconnected
and return early.

Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
---
v4: modify commit message
v3: fix code style
v2: new patch
---
drivers/thunderbolt/switch.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index e0bbdc5fb2f6..f25c358181dd 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -489,8 +489,9 @@ int tb_port_state(struct tb_port *port)
* Wait up to 2 seconds for a port to reach state TB_PORT_UP. If
* wait_if_unplugged is set then we also wait if the port is in state
* TB_PORT_UNPLUGGED (it takes a while for the device to be registered after
- * switch resume). Otherwise we only wait if a device is registered but the link
- * has not yet been established.
+ * router resume, Wait at most 400 ms for link to start connecting,
+ * if timeout, means the device is disconnected). Otherwise we only wait
+ * if a device is registered but the link has not yet been established.
*
* Return:
* * %0 - If the port is not connected or failed to reach
@@ -500,6 +501,7 @@ int tb_port_state(struct tb_port *port)
*/
int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
{
+ int unplugged_retries = 4;
int retries = 20;
int state;
if (!port->cap_phy) {
@@ -519,7 +521,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
return 0;

case TB_PORT_UNPLUGGED:
- if (wait_if_unplugged) {
+ if (wait_if_unplugged && unplugged_retries--) {
/* used during resume */
tb_port_dbg(port,
"is unplugged (state: 7), retrying...\n");
--
2.45.2