[PATCH 074/108] drm/i915/dp_link_training: Use config iterator for BW-order fallback

Imre Deak
2026-04-28T12:55:27Z

Switch the BW-order fallback loop to look up an allowed configuration by
its iteration position rather than by its configuration index. Currently
the index and iteration position match for BW-order used by the
fallback, but future changes will make iteration positions key- and
direction-specific. For now, use the BW / ascending iteration order so
iteration positions match the config index as expected by the current
code.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
.../gpu/drm/i915/display/intel_dp_link_caps.c | 17 -----------
.../gpu/drm/i915/display/intel_dp_link_caps.h | 2 --
.../drm/i915/display/intel_dp_link_training.c | 29 ++++++++++++++++++-
3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
index 284d28f9d98d7..103490eec3d23 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.c
@@ -878,23 +878,6 @@ bool intel_dp_link_caps_update(struct intel_dp_link_caps *link_caps,
return link_params_changed;
}

-void intel_dp_link_config_get(struct intel_dp_link_caps *link_caps,
- int idx, int *link_rate, int *lane_count)
-{
- struct intel_display *display = to_intel_display(link_caps->dp);
- const struct intel_dp_link_caps_config_table *table =
- &link_caps->config_table;
- struct intel_dp_link_config config;
-
- if (drm_WARN_ON(display->drm, idx < 0 || idx >= table->num_configs))
- idx = 0;
-
- to_intel_dp_link_config(table, idx, &config);
-
- *link_rate = config.rate;
- *lane_count = config.lane_count;
-}
-
int intel_dp_link_config_index(struct intel_dp_link_caps *link_caps,
int link_rate, int lane_count)
{
diff --git a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
index cacdda15a36af..b380beedd8990 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_caps.h
@@ -107,8 +107,6 @@ intel_dp_link_caps_get_config_by_pos(struct intel_dp_link_caps *link_caps,
struct intel_dp_link_caps_config_order config_order,
int iter_pos,
struct intel_dp_link_config *config, int *config_idx);
-void intel_dp_link_config_get(struct intel_dp_link_caps *link_caps,
- int idx, int *link_rate, int *lane_count);
int intel_dp_link_caps_find_allowed_config_pos(struct intel_dp_link_caps *link_caps,
struct intel_dp_link_caps_config_order order,
enum intel_dp_link_caps_config_match_type match_type,
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 69396dbb94b2e..9dd302bb4968b 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_link_training.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_link_training.c
@@ -1760,10 +1760,20 @@ static bool reduce_link_params_in_bw_order(struct intel_dp *intel_dp,
const struct intel_crtc_state *crtc_state,
int *new_link_rate, int *new_lane_count)
{
+ struct intel_display *display = to_intel_display(intel_dp);
struct intel_dp_link_caps *link_caps = intel_dp->link.caps;
+ struct intel_dp_link_caps_config_order bw_asc_order = {
+ .key = INTEL_DP_LINK_CAPS_CONFIG_ORDER_KEY_BW,
+ .dir = INTEL_DP_LINK_CAPS_CONFIG_ORDER_DIR_ASC,
+ };
+ struct intel_dp_link_config link_config = {
+ .rate = crtc_state->port_clock,
+ .lane_count = crtc_state->lane_count,
+ };
struct intel_dp_link_config forced_params;
int forced_lane_count;
int forced_rate;
+ int link_config_idx;
int link_rate;
int lane_count;
int i;
@@ -1775,7 +1785,24 @@ static bool reduce_link_params_in_bw_order(struct intel_dp *intel_dp,
i = intel_dp_link_config_index(intel_dp->link.caps,
crtc_state->port_clock, crtc_state->lane_count);
for (i--; i >= 0; i--) {
- intel_dp_link_config_get(intel_dp->link.caps, i, &link_rate, &lane_count);
+ bool config_found;
+
+ config_found = intel_dp_link_caps_get_config_by_pos(link_caps,
+ bw_asc_order, i,
+ &link_config,
+ &link_config_idx);
+ if (drm_WARN_ON(display->drm, !config_found))
+ return false;
+
+ /*
+ * Atm, the index of the configuration must match its
+ * iteration position.
+ */
+ if (drm_WARN_ON(display->drm, link_config_idx != i))
+ return false;
+
+ link_rate = link_config.rate;
+ lane_count = link_config.lane_count;

if ((forced_rate &&
forced_rate != link_rate) ||
--
2.49.1