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); } /**