[PATCH i-g-t 05/10] lib/igt_kms: add function to force link retrain

Kunal Joshi kunal1.joshi at intel.com
Tue Jul 30 21:13:36 UTC 2024


[1] exposes interface which can be utilized to apply previously
set link rate/lane count or force link training failures

[1] https://patchwork.freedesktop.org/patch/594772/?series=133624&rev=3

Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
---
 lib/igt_kms.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  2 ++
 2 files changed, 46 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index dd43d655a..a5bc0adff 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -6825,6 +6825,50 @@ bool kmstest_force_connector_link_training_failure(int drm_fd, drmModeConnector
 	return true;
 }
 
+static bool force_connector_retrain(int drm_fd,
+					  drmModeConnector *connector,
+					  const char *value)
+{
+	return connector_attr_set_debugfs(drm_fd, connector,
+					  "i915_dp_force_link_retrain",
+					  value, "0");
+}
+
+/**
+ * kmstest_force_connector_force_retrain:
+ * @fd: drm file descriptor
+ * @connector: connector
+ *
+ * Force retraining on the specified connector
+ * and install exit handler for resetting
+ *
+ * Returns: True on success
+ */
+bool kmstest_force_connector_retrain(int drm_fd, drmModeConnector *connector, int retrain_count)
+{
+	char value[2];
+	drmModeConnector *temp;
+
+	if (!is_intel_device(drm_fd))
+		return false;
+
+	snprintf(value, sizeof(value), "%d", retrain_count);
+	if (!force_connector_retrain(drm_fd, connector, value))
+		return false;
+
+	dump_connector_attrs();
+	igt_install_exit_handler(reset_connectors_at_exit);
+
+	/*
+	 * To allow callers to always use GetConnectorCurrent we need to force a
+	 * redetection here.
+	 */
+	temp = drmModeGetConnector(drm_fd, connector->connector_id);
+	drmModeFreeConnector(temp);
+
+	return true;
+}
+
 /**
  * igt_get_dp_link_rate_set_for_output:
  * @drm_fd: A drm file descriptor
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index f5b3017d3..310b835f6 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -294,6 +294,8 @@ bool kmstest_force_connector_link_rate(int drm_fd, drmModeConnector *connector,
 				       int link_rate);
 bool kmstest_force_connector_link_training_failure(int drm_fd, drmModeConnector *connector,
 						   int train_count);
+bool kmstest_force_connector_retrain(int drm_fd, drmModeConnector *connector,
+				     int retrain_count);
 
 bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
 					drmModeModeInfo *mode);
-- 
2.43.0



More information about the igt-dev mailing list