When the HDMI link of a PCON goes down while the stream is active, the
HDMI link status change handler restarts the FRL training, or falls back
to TMDS mode, directly from the short pulse handling. That runs without
any modeset lock, so it can race with a modeset that trains the link as
well, and it has no access to the state of the active stream.

Queue the link check work instead, as it is done for the DP link
retraining, and restart the FRL training there, with the modeset locks
held and only if a stream is active. The work restarts the training only
if the FRL link is not trained and the HDMI link is not active, so it
does nothing after a fallback to TMDS mode.

This allows to use the state of the active stream for the training in
the following changes.

Signed-off-by: Ankit Nautiyal <[email protected]>
---
 drivers/gpu/drm/i915/display/intel_dp.c       | 43 ++++++++++++++++++-
 drivers/gpu/drm/i915/display/intel_dp.h       |  2 +
 .../drm/i915/display/intel_dp_link_training.c |  5 ++-
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp.c 
b/drivers/gpu/drm/i915/display/intel_dp.c
index 272837cc6efa..2e92e4898ee6 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.c
+++ b/drivers/gpu/drm/i915/display/intel_dp.c
@@ -4637,6 +4637,42 @@ void intel_dp_check_frl_training(struct intel_dp 
*intel_dp)
        }
 }
 
+/*
+ * Restart FRL training after the HDMI link went down while the stream is
+ * active, or fall back to TMDS mode.
+ */
+int intel_dp_pcon_frl_recover(struct intel_encoder *encoder,
+                             struct drm_modeset_acquire_ctx *ctx)
+{
+       struct intel_display *display = to_intel_display(encoder);
+       struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+       u8 pipe_mask;
+       int ret;
+
+       if (!(intel_dp->downstream_ports[2] & DP_PCON_SOURCE_CTL_MODE) ||
+           !intel_dp_is_hdmi_2_1_sink(intel_dp) ||
+           intel_dp->frl.is_trained ||
+           drm_dp_pcon_hdmi_link_active(&intel_dp->aux))
+               return 0;
+
+       /* The connection mutex may be held already by the link retraining */
+       ret = drm_modeset_lock(&display->drm->mode_config.connection_mutex, 
ctx);
+       if (ret && ret != -EALREADY)
+               return ret;
+
+       ret = intel_dp_get_active_pipes(intel_dp, ctx, &pipe_mask);
+       if (ret)
+               return ret;
+
+       /* Without an active stream the next enable trains the link */
+       if (pipe_mask == 0)
+               return 0;
+
+       intel_dp_check_frl_training(intel_dp);
+
+       return 0;
+}
+
 void
 intel_dp_pcon_dsc_configure(struct intel_dp *intel_dp,
                            const struct intel_crtc_state *crtc_state)
@@ -6060,8 +6096,11 @@ intel_dp_handle_hdmi_link_status_change(struct intel_dp 
*intel_dp)
 
                intel_dp->frl.is_trained = false;
 
-               /* Restart FRL training or fall back to TMDS mode */
-               intel_dp_check_frl_training(intel_dp);
+               /*
+                * Restart FRL training or fall back to TMDS mode, from the link
+                * check work, where the modeset locks can be taken.
+                */
+               
intel_encoder_link_check_queue_work(&dp_to_dig_port(intel_dp)->base, 0);
        }
 }
 
diff --git a/drivers/gpu/drm/i915/display/intel_dp.h 
b/drivers/gpu/drm/i915/display/intel_dp.h
index 1f4a3aff9abe..070f6229cc39 100644
--- a/drivers/gpu/drm/i915/display/intel_dp.h
+++ b/drivers/gpu/drm/i915/display/intel_dp.h
@@ -188,6 +188,8 @@ void intel_dp_sync_state(struct intel_encoder *encoder,
                         const struct intel_crtc_state *crtc_state);
 
 void intel_dp_check_frl_training(struct intel_dp *intel_dp);
+int intel_dp_pcon_frl_recover(struct intel_encoder *encoder,
+                             struct drm_modeset_acquire_ctx *ctx);
 void intel_dp_pcon_dsc_configure(struct intel_dp *intel_dp,
                                 const struct intel_crtc_state *crtc_state);
 
diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_training.c 
b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
index 1efc78b329a6..2c18590bcbff 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -2635,8 +2635,11 @@ void intel_dp_link_check(struct intel_encoder *encoder)
        struct drm_modeset_acquire_ctx ctx;
        int ret;
 
-       intel_modeset_lock_ctx_retry(&ctx, NULL, 0, ret)
+       intel_modeset_lock_ctx_retry(&ctx, NULL, 0, ret) {
                ret = intel_dp_retrain_link(encoder, &ctx);
+               if (!ret)
+                       ret = intel_dp_pcon_frl_recover(encoder, &ctx);
+       }
 }
 
 void intel_dp_check_link_state(struct intel_dp *intel_dp)
-- 
2.50.1

Reply via email to