[PATCH 017/108] drm/i915/dp_link_training: Add helper to mark link training failure

Imre Deak
2026-04-28T12:53:16Z

Add link_recovery_mark_train_failure() to record the failure and make
the link recovery state transition explicit after a link training
failure: recovery can continue with an autoretrain, or must be handed
over to userspace after fallback selection.

This also prepares for replacing the sequential link training failure
counter with an enum in a follow-up change.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
.../drm/i915/display/intel_dp_link_training.c | 33 +++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)

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 1c2cef7d61f37..eb922dca69c5b 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -1277,6 +1277,33 @@ link_recovery_autoretrain_allowed(struct intel_dp_link_training *link_training)
return link_training->seq_train_failures < MAX_SEQ_TRAIN_FAILURES;
}

+/**
+ * link_recovery_mark_train_failure - record a link training failure
+ * @link_training: link training state
+ *
+ * Record a link training failure and advance the recovery state to
+ * indicate the next required recovery step.
+ *
+ * The caller must proceed with recovery as instructed by the return
+ * value, either via automatic retraining or, once automatic retraining
+ * is no longer possible, via userspace modesets after fallback
+ * selection.
+ *
+ * Return:
+ * - %true if recovery should continue via automatic retraining.
+ * - %false if automatic retraining is no longer possible and recovery
+ * must be delegated to userspace.
+ */
+static bool
+link_recovery_mark_train_failure(struct intel_dp_link_training *link_training)
+{
+ if (link_recovery_autoretrain_allowed(link_training))
+ /* Move to autoretrain pending or autoretrain disabled state. */
+ link_training->seq_train_failures++;
+
+ return link_recovery_autoretrain_allowed(link_training);
+}
+
/**
* intel_dp_stop_link_train - stop link training
* @intel_dp: DP struct
@@ -1813,6 +1840,7 @@ void intel_dp_start_link_train(struct intel_atomic_state *state,
struct intel_encoder *encoder = &dig_port->base;
struct intel_dp_link_training *link_training =
intel_dp->link.training;
+ bool can_autoretrain;
bool passed;
/*
* Reinit the LTTPRs here to ensure that they are switched to
@@ -1844,8 +1872,7 @@ void intel_dp_start_link_train(struct intel_atomic_state *state,
return;
}

- if (link_recovery_autoretrain_allowed(link_training))
- link_training->seq_train_failures++;
+ can_autoretrain = link_recovery_mark_train_failure(link_training);

/*
* Ignore the link failure in CI
@@ -1864,7 +1891,7 @@ void intel_dp_start_link_train(struct intel_atomic_state *state,
return;
}

- if (link_recovery_autoretrain_allowed(link_training))
+ if (can_autoretrain)
return;

if (intel_dp_schedule_fallback_link_training(state, intel_dp, crtc_state))
--
2.49.1