Re: [PATCH v2 6/7] thunderbolt: decouple the waiting time of TB_PORT_UNPLUGGED and TB_PORT_UP
From: Chunfeng Yun (云春峰)
Date: Thu Nov 12 2026 - 03:10:58 EST
On 二, 2026-11-10 at 15:40 +0100, Mika Westerberg wrote:
> On Tue, Nov 10, 2026 at 07:48:54PM +0800, Chunfeng Yun wrote:
> > When usb4 is woke up by device disconnect, no need wait for 2s,
> > usually the phase2~4 takes at most about 200ms, and enters to
> > TB_PORT_CONNECTING, if it is still in TB_PORT_UNPLUGGED after
> > 400ms,
> > treat it as disconnected.
> >
> > Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
> > ---
> > new changes
> > ---
> > 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 7daee83c7ed8..e12546bfb869 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.
> > + * switch resume, Wait at most 400 ms for link to start
> > connecting,
>
> router
ACK
>
> > + * 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
> > @@ -501,6 +502,7 @@ int tb_port_state(struct tb_port *port)
> > int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged)
> > {
> > int retries = 20;
> > + int unplugged_retries = 4;
>
> Reverse-christmas tree
ACK
Thanks
>
> > int state;
> > if (!port->cap_phy) {
> > tb_port_WARN(port, "does not have PHY\n");
> > @@ -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