From: Alfonso Villalobos Ulate <alfonsocvu@gmail.com>
To: westeri@kernel.org
Cc: andreas.noever@gmail.com, YehezkelShB@gmail.com,
linux-usb@vger.kernel.org,
Alfonso Villalobos Ulate <alfonsocvu@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure
Date: Sat, 21 Nov 2026 01:08:04 -0600 [thread overview]
Message-ID: <20261121070804.26185-1-alfonsocvu@gmail.com> (raw)
When DPRX negotiation fails, the DP IN adapter is removed from the DP
resources and is only added back on a hotplug event for that adapter.
Host router DP IN adapters never get such events, so after one failure
(for example when the GPU feeding it is runtime suspended) the adapter
stays unused until the driver is reloaded.
Re-check the host router DP IN adapters when a DP OUT adapter appears
or a device router is plugged in, and skip adapters already on the
list. Keep host DP IN adapters in adapter order so a re-added one is
paired with the same DP OUT as before, instead of swapping monitors
with the other host DP IN.
Tested on an ASM4242 host with a CalDigit TS5 Plus dock.
Written with assistance from Claude Code (Claude Opus 5.5), which
proposed the code changes and drafted this message.
Fixes: d6d458d42e1e ("thunderbolt: Handle DisplayPort tunnel activation asynchronously")
Cc: stable@vger.kernel.org
Signed-off-by: Alfonso Villalobos Ulate <alfonsocvu@gmail.com>
---
drivers/thunderbolt/tb.c | 52 +++++++++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 57c11ba13459..4a43da6817a2 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -109,6 +109,29 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
/* enumeration & hot plug handling */
+/*
+ * Insert a host router DP IN adapter so that host DP IN adapters stay
+ * in adapter number order. A DP IN that is re-added after it was
+ * dropped (for example because DPRX negotiation failed) then gets
+ * paired with the same DP OUT as before, instead of swapping DP OUT
+ * adapters (and therefore monitors) with the other host DP IN.
+ */
+static void tb_add_host_dp_in(struct tb_cm *tcm, struct tb_port *port)
+{
+ struct tb_port *p;
+
+ list_for_each_entry(p, &tcm->dp_resources, list) {
+ if (tb_port_is_dpin(p) && !tb_route(p->sw) &&
+ p->port > port->port) {
+ /* Insert before the first higher numbered one */
+ list_add_tail(&port->list, &p->list);
+ return;
+ }
+ }
+
+ list_add_tail(&port->list, &tcm->dp_resources);
+}
+
static void tb_add_dp_resources(struct tb_switch *sw)
{
struct tb_cm *tcm = tb_priv(sw->tb);
@@ -118,6 +141,9 @@ static void tb_add_dp_resources(struct tb_switch *sw)
if (!tb_port_is_dpin(port))
continue;
+ if (!list_empty(&port->list))
+ continue;
+
if (!tb_switch_query_dp_resource(sw, port))
continue;
@@ -130,7 +156,7 @@ static void tb_add_dp_resources(struct tb_switch *sw)
if (tb_route(sw))
list_add(&port->list, &tcm->dp_resources);
else
- list_add_tail(&port->list, &tcm->dp_resources);
+ tb_add_host_dp_in(tcm, port);
tb_port_dbg(port, "DP IN resource available\n");
}
@@ -1421,6 +1447,16 @@ static void tb_scan_port(struct tb_port *port)
tb_sw_warn(sw, "USB3 tunnel creation failed\n");
tb_add_dp_resources(sw);
+
+ /*
+ * Host router DP IN adapters may have been dropped earlier
+ * (for example because DPRX negotiation failed) and they do
+ * not get hotplug events of their own, so re-check them now
+ * that there is potentially a new DP OUT to pair with.
+ */
+ if (tcm->hotplug_active)
+ tb_add_dp_resources(sw->tb->root_switch);
+
tb_scan_switch(sw);
out_rpm_put:
@@ -1971,8 +2007,10 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)
* also tear down the tunnel and try to re-use the
* released DP OUT.
*
- * It will be added back only if there is hotplug for
- * the DP IN again.
+ * It will be added back if there is hotplug for the
+ * DP IN again. Host router DP IN adapters do not get
+ * such events, so they are re-checked whenever a new
+ * DP OUT or device router appears instead.
*/
tb_tunnel_warn(tunnel, "not active, tearing down\n");
tb_dp_resource_unavailable(tb, in, "DPRX negotiation failed");
@@ -2234,6 +2272,14 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)
list_add_tail(&port->list, &tcm->dp_resources);
tb_exit_redrive(port);
+ /*
+ * Host router DP IN adapters removed because DPRX negotiation
+ * failed never get a hotplug event of their own. Give them
+ * another chance now that a DP OUT became available.
+ */
+ if (tb_port_is_dpout(port))
+ tb_add_dp_resources(tb->root_switch);
+
/* Look for suitable DP IN <-> DP OUT pairs now */
tb_tunnel_dp(tb);
}
--
2.53.0
next reply other threads:[~2026-11-21 7:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 7:08 Alfonso Villalobos Ulate [this message]
2026-11-21 7:25 ` [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121070804.26185-1-alfonsocvu@gmail.com \
--to=alfonsocvu@gmail.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=westeri@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.