Re: [Patch v2 2/2] thunderbolt: Teardown tunnels and reset downstream ports created by boot firmware

From: Mika Westerberg
Date: Wed Dec 13 2023 - 01:23:15 EST


On Wed, Dec 13, 2023 at 08:18:06AM +0200, Mika Westerberg wrote:
> On Wed, Dec 13, 2023 at 07:49:14AM +0200, Mika Westerberg wrote:
> > On Wed, Dec 13, 2023 at 12:46:35AM +0530, Sanath S wrote:
> > > Boot firmware might have created tunnels of its own. Since we cannot
> > > be sure they are usable for us. Tear them down and reset the ports
> > > to handle it as a new hotplug for USB3 routers.
> > >
> > > Suggested-by: Mario Limonciello <mario.limonciello@xxxxxxx>
> > > Signed-off-by: Sanath S <Sanath.S@xxxxxxx>
> > > ---
> > > drivers/thunderbolt/tb.c | 11 +++++++++++
> > > 1 file changed, 11 insertions(+)
> > >
> > > diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
> > > index fd49f86e0353..febd0b6972e3 100644
> > > --- a/drivers/thunderbolt/tb.c
> > > +++ b/drivers/thunderbolt/tb.c
> > > @@ -2598,6 +2598,17 @@ static int tb_start(struct tb *tb)
> > > tb_switch_tmu_enable(tb->root_switch);
> > > /* Full scan to discover devices added before the driver was loaded. */
> > > tb_scan_switch(tb->root_switch);
> > > + /*
> > > + * Boot firmware might have created tunnels of its own. Since we cannot
> > > + * be sure they are usable for us, Tear them down and reset the ports
> > > + * to handle it as new hotplug for USB4 routers.
> > > + */
> > > + if (tb_switch_is_usb4(tb->root_switch)) {
> > > + tb_switch_discover_tunnels(tb->root_switch,
> > > + &tcm->tunnel_list, false);
> >
> > Why this is needed?
> >
> > It should be enough, to do simply something like this:
> >
> > if (tb_switch_is_usb4(tb->root_switch))
> > tb_switch_reset(tb->root_switch);
>
> Actually this needs to be done only for USB4 v1 routers since we already
> reset USB4 v2 hosts so something like:
>
> /*
> * Reset USB4 v1 host router to get rid of possible tunnels the
> * boot firmware created. This makes sure all the tunnels are
> * created by us and thus have known configuration.
> *
> * For USB4 v2 and beyond we do this in nhi_reset() using the
> * host router reset interface.
> */
> if (usb4_switch_version(tb->root_switch) == 1)
> tb_switch_reset(tb->root_switch);
>
> (possibly add similar comment to the nhi_reset() to refer this one).

Oh, and would it be possible to tie this with the "host_reset" parameter
too somehow? I guess it could be moved to "tb.c" and "tb.h" and then
check it from nhi.c as already done and then here so this would become:

if (host_reset && usb4_switch_version(tb->root_switch) == 1)
tb_switch_reset(tb->root_switch);

With the idea that the user has a "chicken bit" to disable this
behaviour (and consistent one with USB4 v2). Feel free to make it look
nicer though.