All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kunal Joshi <kunal1.joshi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Kunal Joshi <kunal1.joshi@intel.com>
Subject: [PATCH i-g-t 01/13] lib/i915/i915_dp: Add helpers for the allowed link configs debugfs
Date: Wed, 16 Sep 2026 10:17:49 +0530	[thread overview]
Message-ID: <20260916044801.1279102-2-kunal1.joshi@intel.com> (raw)
In-Reply-To: <20260916044801.1279102-1-kunal1.joshi@intel.com>

i915_dp_get_max_supported_rate() parses i915_dp_force_link_rate, which
lists the source rates only. Writing back a rate from that list which
the sink never advertised still succeeds, and the kernel silently
clamps the effective rate, so a test built on it reports a rate the
link was never trained at.

The kernel already exports the set the driver actually picks from, the
intersection of the source rates, the rates the sink advertises and the
current link limits, as space separated "<lanes>x<rate>" entries in
the per-connector intel_dp_allowed_link_configs debugfs file.

Add i915_dp_get_allowed_link_configs() to read that set into an array
of struct i915_dp_link_config, and
i915_dp_has_allowed_link_configs_debugfs() so a test can skip on a
kernel without the file.

i915_dp_get_next_lower_rate() already reads this file, but only for the
rate; the lane count of each entry is discarded. Keep both, so callers
that want a single rate do not have to handle the whole set.

The driver lists the configurations in its own preference order, which
differs between SST and MST, so callers must treat the result as an
unordered set.

Assisted-by: GitHub_Copilot:claude-opus-5
Signed-off-by: Kunal Joshi <kunal1.joshi@intel.com>
---
 lib/i915/i915_dp.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/i915/i915_dp.h | 17 ++++++++++
 2 files changed, 98 insertions(+)

diff --git a/lib/i915/i915_dp.c b/lib/i915/i915_dp.c
index 3d570f7cc..aba6aa8d5 100644
--- a/lib/i915/i915_dp.c
+++ b/lib/i915/i915_dp.c
@@ -37,6 +37,12 @@
 #include "igt_core.h"
 #include "igt_kms.h"
 
+/*
+ * The driver allows at most 10 link rates over 3 lane counts, i.e. 30 entries
+ * of at most "4x2000000 ", so 1024 has plenty of room to spare.
+ */
+#define LINK_CONFIGS_BUF_SIZE	1024
+
 /**
  * i915_dp_parse_marked_value:
  * @buf: Buffer containing the content to parse
@@ -391,6 +397,81 @@ int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output)
 	return max_rate;
 }
 
+/**
+ * i915_dp_has_allowed_link_configs_debugfs:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ *
+ * Checks if the allowed link configs debugfs is available for a specific
+ * output.
+ *
+ * Returns: True if the debugfs is available, false otherwise
+ */
+bool i915_dp_has_allowed_link_configs_debugfs(int drm_fd, igt_output_t *output)
+{
+	char buf[LINK_CONFIGS_BUF_SIZE];
+
+	return igt_debugfs_read_connector_file(drm_fd, igt_output_name(output),
+					       "intel_dp_allowed_link_configs",
+					       buf, sizeof(buf)) == 0;
+}
+
+/**
+ * i915_dp_get_allowed_link_configs:
+ * @drm_fd: A drm file descriptor
+ * @output: Target output
+ * @configs: Array to store the allowed link configurations in
+ * @max_configs: Number of entries in @configs
+ *
+ * Read the link configurations the driver currently allows on @output, i.e.
+ * the intersection of the source rates, the rates the sink advertises and the
+ * current link limits.
+ *
+ * The driver lists them in the order it would pick them, which differs between
+ * SST and MST and depends on earlier link training results, so callers have to
+ * treat the result as an unordered set.
+ *
+ * Returns: The number of configurations stored in @configs
+ */
+int i915_dp_get_allowed_link_configs(int drm_fd, igt_output_t *output,
+				     struct i915_dp_link_config *configs,
+				     int max_configs)
+{
+	char buf[LINK_CONFIGS_BUF_SIZE];
+	char *token, *saveptr = NULL;
+	int count = 0;
+	int res;
+
+	res = igt_debugfs_read_connector_file(drm_fd, igt_output_name(output),
+					      "intel_dp_allowed_link_configs",
+					      buf, sizeof(buf));
+	igt_assert_f(res == 0, "Unable to read %s/intel_dp_allowed_link_configs\n",
+		     igt_output_name(output));
+
+	/* An empty set of allowed configurations reads back as a bare newline. */
+	buf[strcspn(buf, "\n")] = '\0';
+
+	for (token = strtok_r(buf, " ", &saveptr); token;
+	     token = strtok_r(NULL, " ", &saveptr)) {
+		int lane_count, link_rate;
+		char extra;
+
+		igt_assert_f(count < max_configs,
+			     "More than %d link configs on %s\n",
+			     max_configs, igt_output_name(output));
+		igt_assert_f(sscanf(token, "%dx%d%c", &lane_count, &link_rate,
+				    &extra) == 2 && lane_count > 0 &&
+			     link_rate > 0,
+			     "Failed to parse link config '%s'\n", token);
+
+		configs[count].lane_count = lane_count;
+		configs[count].link_rate = link_rate;
+		count++;
+	}
+
+	return count;
+}
+
 /**
  * i915_dp_get_next_lower_rate:
  * @drm_fd: A drm file descriptor
diff --git a/lib/i915/i915_dp.h b/lib/i915/i915_dp.h
index 5d17713e2..c818b3937 100644
--- a/lib/i915/i915_dp.h
+++ b/lib/i915/i915_dp.h
@@ -10,6 +10,19 @@
 /* DP link rates are in 10 kbit/s units; UHBR10 is 10 Gbps. */
 #define I915_DP_UHBR10_LINK_RATE	1000000
 
+/**
+ * struct i915_dp_link_config:
+ * @lane_count: Number of lanes
+ * @link_rate: Link rate in 10 kbit/s units
+ *
+ * A single link configuration, as listed by the intel_dp_allowed_link_configs
+ * connector debugfs file.
+ */
+struct i915_dp_link_config {
+	int lane_count;
+	int link_rate;
+};
+
 /**
  * i915_dp_is_uhbr_rate:
  * @link_rate: DP link rate in 10 kbit/s units, as reported by the
@@ -40,6 +53,10 @@ void i915_dp_reset_link_params(int drm_fd, igt_output_t *output);
 void i915_dp_set_link_params(int drm_fd, igt_output_t *output,
 			     const char *link_rate, const char *lane_count);
 int i915_dp_get_max_supported_rate(int drm_fd, const igt_output_t *output);
+bool i915_dp_has_allowed_link_configs_debugfs(int drm_fd, igt_output_t *output);
+int i915_dp_get_allowed_link_configs(int drm_fd, igt_output_t *output,
+				     struct i915_dp_link_config *configs,
+				     int max_configs);
 int i915_dp_get_next_lower_rate(int drm_fd, igt_output_t *output, int rate);
 
 #endif
-- 
2.25.1


  reply	other threads:[~2026-09-16  4:33 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  4:47 [PATCH i-g-t 00/13] Expand kms_dp_link_training coverage Kunal Joshi
2026-09-16  4:47 ` Kunal Joshi [this message]
2026-09-21  8:37   ` [PATCH i-g-t 01/13] lib/i915/i915_dp: Add helpers for the allowed link configs debugfs S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 02/13] tests/intel/kms_dp_link_training: Use the UHBR helpers from lib Kunal Joshi
2026-09-21  8:38   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 03/13] tests/intel/kms_dp_link_training: Extract train_link_config() Kunal Joshi
2026-09-22 11:51   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 04/13] tests/intel/kms_dp_link_training: Check the config survived training Kunal Joshi
2026-09-22  5:25   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 05/13] tests/intel/kms_dp_link_training: Drive the smallest mode the sink offers Kunal Joshi
2026-09-22 11:59   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 06/13] tests/intel/kms_dp_link_training: Train every allowed link config Kunal Joshi
2026-09-22 13:51   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 07/13] lib/i915/i915_dp: Add a Type-C port mode query Kunal Joshi
2026-09-22 14:55   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 08/13] tests/intel/kms_dp_link_training: Log the DP link inventory in the fixture Kunal Joshi
2026-09-23 12:46   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 09/13] tests/intel/kms_dp_link_training: Group the outputs into links Kunal Joshi
2026-09-23 13:10   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 10/13] tests/intel/kms_dp_link_training: Add per connector mode subtests Kunal Joshi
2026-09-23 13:29   ` S, Sowmiya
2026-09-16  4:47 ` [PATCH i-g-t 11/13] lib/igt_dp: Add DPCD read helpers Kunal Joshi
2026-09-23 13:34   ` S, Sowmiya
2026-09-16  4:48 ` [PATCH i-g-t 12/13] lib/igt_dp: Add link status predicates for both channel codings Kunal Joshi
2026-09-23 13:55   ` S, Sowmiya
2026-09-16  4:48 ` [PATCH i-g-t 13/13] tests/intel/kms_dp_link_training: Verify the trained link from the sink side Kunal Joshi
2026-09-23 14:00   ` S, Sowmiya
2026-09-16  5:08 ` ✓ Xe.CI.BAT: success for Expand kms_dp_link_training coverage Patchwork
2026-09-16  5:25 ` ✓ i915.CI.BAT: " Patchwork
2026-09-16  6:15 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-16 11:59 ` ✗ i915.CI.Full: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-10-01  7:36 [PATCH i-g-t 00/13] " Kunal Joshi
2026-10-01  7:36 ` [PATCH i-g-t 01/13] lib/i915/i915_dp: add helpers for the allowed link configs debugfs Kunal Joshi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916044801.1279102-2-kunal1.joshi@intel.com \
    --to=kunal1.joshi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.