From 52070a0673333c01f5a1965ad9b20d20cd7d4f6c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:40:57 +1100 Subject: [PATCH] drm/apple: dcp: give each Type-C reconnect request its whole budget dcp_typec_reconnect_work() connects the DPTX link of an attached Type-C display and, on failure, re-arms itself up to DPTX_RECONNECT_RETRIES (5) times, 1 s apart, before it reports "Type-C DPTX reconnect failed after N retries". The attempt counter, typec_reconnect_tries, was reset only by some of the paths that queue the work (an attach, a DPMS power-on, a port announced by a native external processor, a Thunderbolt tunnel, the bounded display retry), and not by others (component bind enabling the work with a cable already routed, an ext26 layout stop, a failed connect of an attached display). The work also counted without the hpd_mutex those resets are made under. A request from a path that does not reset after an earlier request had used up its attempts gets one attempt instead of five. That is what a J700 log shows after s2idle: a reconnect ladder ends with "after 5 retries: -110" before suspend, the first reconnect after the wake makes one attempt and gives up with "after 6 retries: -110". Reset the counter where every request is made, in dcp_queue_typec_reconnect_locked(), and have the work count its failures under hpd_mutex. The work still re-arms itself directly with mod_delayed_work(), so its own retries keep counting against the request that started them; nothing reachable from the work queues a new request, so the ladder stays bounded. The resets the callers did right before queueing are dropped. The message now counts what it counts: "failed after N attempts". Nothing changes for a request whose path already reset the counter, which covers all first connects. Sessionless (H17P) work now takes hpd_mutex once on failure, as the session path of the same work already does, so no new lock order is introduced. Fixes: ef24bbb1041d ("drm: apple: recover Type-C displays across link interruptions") Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7cde46e009096..ba79342925dcb 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2184,6 +2184,13 @@ static void dcp_queue_typec_reconnect_locked(struct apple_dcp *dcp, return; dcp->typec_reconnect_session = dcp_session_locked(dcp); } + /* + * Every request gets the whole budget of attempts: it comes from an + * event (an attach, a power-on, a bind, a port or tunnel coming up, + * the bounded display retry). The work arms its own retries directly, + * so they count against the request that started them. + */ + dcp->typec_reconnect_tries = 0; mod_delayed_work(system_freezable_wq, &dcp->typec_reconnect_wq, delay); } @@ -2740,7 +2747,6 @@ void dcp_external_ready(struct apple_dcp *dcp) { if (READ_ONCE(dcp->typec_cable_connected)) { guard(mutex)(&dcp->hpd_mutex); - dcp->typec_reconnect_tries = 0; dcp_queue_typec_reconnect_locked(dcp, 0); } else if (dcp->hdmi_hpd && dcp->active && gpiod_get_value_cansleep(dcp->hdmi_hpd)) { @@ -2873,7 +2879,6 @@ void dcp_external_retry_work(struct work_struct *work) if (ret) return; } - dcp->typec_reconnect_tries = 0; } guard(mutex)(&dcp->hpd_mutex); dcp_queue_typec_reconnect_locked(dcp, 0); @@ -3473,6 +3478,7 @@ static void dcp_typec_reconnect_work(struct work_struct *work) container_of(to_delayed_work(work), struct apple_dcp, typec_reconnect_wq); struct dcp_fabric_session session; + unsigned int tries, limit; int ret; /* @@ -3509,25 +3515,27 @@ static void dcp_typec_reconnect_work(struct work_struct *work) return; } } - if (!ret) { - dcp->typec_reconnect_tries = 0; + if (!ret) return; - } /* A display held for this link will not get ready. */ if (READ_ONCE(dcp->external_error)) dcp_announce_kick(dcp); /* A T8132 dcpext connects once per tunnel. */ - if (++dcp->typec_reconnect_tries < - (dcp_uses_t6020_tunnel_flow(dcp) || dcp_is_t8132_ext(dcp) ? - 1 : DPTX_RECONNECT_RETRIES)) { - mod_delayed_work(system_freezable_wq, &dcp->typec_reconnect_wq, - DPTX_RECONNECT_DELAY); - return; + limit = dcp_uses_t6020_tunnel_flow(dcp) || dcp_is_t8132_ext(dcp) ? + 1 : DPTX_RECONNECT_RETRIES; + /* Counted under the lock a new request resets it with. */ + scoped_guard(mutex, &dcp->hpd_mutex) { + tries = ++dcp->typec_reconnect_tries; + if (tries < limit) { + mod_delayed_work(system_freezable_wq, &dcp->typec_reconnect_wq, + DPTX_RECONNECT_DELAY); + return; + } } - dev_err(dcp->dev, "Type-C DPTX reconnect failed after %u retries: %d\n", - dcp->typec_reconnect_tries, ret); + dev_err(dcp->dev, "Type-C DPTX reconnect failed after %u attempts: %d\n", + tries, ret); } /**