Skip to contentSkip to conversation

drm: Add a new connector atomic property for link status

PATCH In review Manasi Navare 6 participants 15 messages Nov 30, 2016 – Dec 6, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm: Add a new connector atomic property for link status

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +8 -0
index 494680c..962ed66 100644
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}
 	}
 
 	/*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
 								NULL);
 			if (ret)
 				return ret;
+			conn_state->link_status = DRM_LINK_STATUS_GOOD;
 		}
 	}
 
drivers/gpu/drm/drm_connector.c +53 -1

84 lines not on this page · raw message

include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
 	struct drm_encoder *best_encoder;
 
+	/**
+	 * @link_status: Connector link_status to keep track of whether link is
+	 * GOOD or BAD to notify userspace if retraining is necessary.
+	 */
+	enum drm_link_status link_status;
+
 	struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 					    const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
 	 */
 	struct drm_property *tile_property;
 	/**
+	 * @link_status_property: Default connector property for link status
+	 * of a connector
+	 */
+	struct drm_property *link_status_property;
+	/**
 	 * @plane_type_property: Default plane property to differentiate
 	 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
 	 */
include/uapi/drm/drm_mode.h +4 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD	0
+#define DRM_MODE_LINK_STATUS_BAD	1
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/3 drm/i915: Find fallback link rate/lane count

If link training fails, then we need to fallback to lower link rate first and if link training fails at RBR, then fallback to lower lane count.
This function finds the next lower link rate/lane count value after link training failure and limits the max link_rate and lane_count values to these fallback values.

v6:
* Cap the max link rate and lane count to the max values obtained during fallback link training (Daniel Vetter) v5:
* Start the fallback at the lane count value passed not the max lane count (Jani Nikula)
v4:
* Remove the redundant variable link_train_failed
v3:
* Remove fallback_link_rate_index variable, just obtain that using the helper intel_dp_link_rate_index (Jani Nikula) v2:
Squash the patch that returns the link rate index (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c  | 59 ++++++++++++++++++++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_drv.h |  4 +++
 2 files changed, 61 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +57 -2
index 8026a83..bc1268c 100644
@@ -153,12 +153,18 @@ static void vlv_steal_power_sequencer(struct drm_device *dev,
 static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
 {
 	struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-	u8 source_max, sink_max;
+	u8 temp, source_max, sink_max;
 
 	source_max = intel_dig_port->max_lanes;
 	sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
+	temp = min(source_max, sink_max);
+	/* Limit the max value to max fallback value during link train
+	 * failure handling.
+	 */
+	if (intel_dp->fallback_lane_count)
+		return min(temp, intel_dp->fallback_lane_count);
 
-	return min(source_max, sink_max);
+	return temp;
 }
 
 /*
@@ -281,6 +287,15 @@ static int intel_dp_common_rates(struct intel_dp *intel_dp,
 	int source_len, sink_len;
 
 	sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
+	/* Limit the max sink rate to the max fallback link rate
+	 * found during link training failure handling.
+	 */
+	if (intel_dp->fallback_link_rate) {
+		int len = sink_len - 1;
+		while (len > 0 && sink_rates[len] > intel_dp->fallback_link_rate)
+			len--;
+		sink_len = len + 1;
+	}
 	source_len = intel_dp_source_rates(intel_dp, &source_rates);
 
 	return intersect_rates(source_rates, source_len,
@@ -288,6 +303,46 @@ static int intel_dp_common_rates(struct intel_dp *intel_dp,
 			       common_rates);
 }
 
+static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
+				    int *common_rates, int link_rate)
+{
+	int common_len;
+	int index;
+
+	common_len = intel_dp_common_rates(intel_dp, common_rates);
+	for (index = 0; index < common_len; index++) {
+		if (link_rate == common_rates[common_len - index - 1])
+			return common_len - index - 1;
+	}
+
+	return -1;
+}
+
+int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
+					    int link_rate, uint8_t lane_count)
+{
+	int common_rates[DP_MAX_SUPPORTED_RATES] = {};
+	int common_len;
+	int link_rate_index = -1;
+
+	common_len = intel_dp_common_rates(intel_dp, common_rates);
+	link_rate_index = intel_dp_link_rate_index(intel_dp,
+						   common_rates,
+						   link_rate);
+	if (link_rate_index > 0) {
+		intel_dp->fallback_link_rate = common_rates[link_rate_index - 1];
+		intel_dp->fallback_lane_count = lane_count;
+	} else if (lane_count > 1) {
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = lane_count >> 1;
+	} else {
+		DRM_ERROR("Link Training Unsuccessful\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static enum drm_mode_status
 intel_dp_mode_valid(struct drm_connector *connector,
 		    struct drm_display_mode *mode)
drivers/gpu/drm/i915/intel_drv.h +4 -0
index 9bbe5c5..2da3b40 100644
@@ -891,6 +891,8 @@ struct intel_dp {
 	uint32_t DP;
 	int link_rate;
 	uint8_t lane_count;
+	int fallback_link_rate;
+	uint8_t fallback_lane_count;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1393,6 +1395,8 @@ bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
 void intel_dp_set_link_params(struct intel_dp *intel_dp,
 			      int link_rate, uint8_t lane_count,
 			      bool link_mst);
+int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
+					    int link_rate, uint8_t lane_count);
 void intel_dp_start_link_train(struct intel_dp *intel_dp);
 void intel_dp_stop_link_train(struct intel_dp *intel_dp);
 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode);
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 3/3 drm/i915: Implement Link Rate fallback on Link training failure

In reply to Manasi Navare

If link training at a link rate optimal for a particular mode fails during modeset's atomic commit phase, then we let the modeset complete and then retry. We save the link rate value at which link training failed, update the link status property to "BAD" and use a lower link rate to prune the modes. It will redo the modeset on the current mode at lower link rate or if the current mode gets pruned due to lower link constraints then, it will send a hotplug uevent for userspace to handle it.

This is also required to pass DP CTS tests 4.3.1.3, 4.3.1.4, 4.3.1.6.

v9:
* Use the trimmed max values of link rate/lane count based on link train fallback (Daniel Vetter)
v8:
* Set link_status to BAD first and then call mode_valid (Jani Nikula) v7:
Remove the redundant variable in previous patch itself
v6:
* Obtain link rate index from fallback_link_rate using
the helper intel_dp_link_rate_index (Jani Nikula)
* Include fallback within intel_dp_start_link_train (Jani Nikula) v5:
* Move set link status to drm core (Daniel Vetter, Jani Nikula) v4:
* Add fallback support for non DDI platforms too
* Set connector->link status inside set_link_status function (Jani Nikula)
v3:
* Set link status property to BAd unconditionally (Jani Nikula)
* Dont use two separate variables link_train_failed and link_status to indicate same thing (Jani Nikula)
v2:
* Squashed a few patches (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c               | 44 +++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_dp_link_training.c | 25 +++++++++++++--
 drivers/gpu/drm/i915/intel_drv.h              |  3 ++
 3 files changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +44 -0
index bc1268c..a50b6cd 100644
@@ -4435,6 +4435,8 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 		intel_dp->compliance_test_active = 0;
 		intel_dp->compliance_test_type = 0;
 		intel_dp->compliance_test_data = 0;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
 
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4526,6 +4528,13 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
 		      connector->base.id, connector->name);
 
+	/* If this is a retry due to link training failure
+	 * then do no do a full detect
+	 */
+	if (status == connector_status_connected &&
+	    intel_dp->fallback_lane_count)
+		return status;
+
 	/* If full detect is not performed yet, do a full detect */
 	if (!intel_dp->detect_done)
 		status = intel_dp_long_pulse(intel_dp->attached_connector);
@@ -5690,6 +5699,37 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	return false;
 }
 
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
+{
+	struct intel_connector *intel_connector;
+	struct drm_connector *connector;
+	struct drm_display_mode *mode;
+	bool verbose_prune = true;
+
+	intel_connector = container_of(work, typeof(*intel_connector),
+				       modeset_retry_work);
+	connector = &intel_connector->base;
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	/* Set connector link status to BAD and send a Uevent to notify
+	 * userspace to do a modeset.
+	 */
+	drm_mode_connector_set_link_status_property(connector,
+						    DRM_MODE_LINK_STATUS_BAD);
+	list_for_each_entry(mode, &connector->modes, head) {
+		mode->status = intel_dp_mode_valid(connector,
+						   mode);
+	}
+	drm_mode_prune_invalid(connector->dev, &connector->modes,
+			       verbose_prune);
+	mutex_unlock(&connector->dev->mode_config.mutex);
+	/* Send Hotplug uevent so userspace can reprobe */
+	drm_kms_helper_hotplug_event(connector->dev);
+}
+
 bool
 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
 			struct intel_connector *intel_connector)
@@ -5702,6 +5742,10 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	enum port port = intel_dig_port->port;
 	int type;
 
+	/* Initialize the work for modeset in case of link train failure */
+	INIT_WORK(&intel_connector->modeset_retry_work,
+		  intel_dp_modeset_retry_work_fn);
+
 	if (WARN(intel_dig_port->max_lanes < 1,
 		 "Not enough lanes (%d) for DP on port %c\n",
 		 intel_dig_port->max_lanes, port_name(port)))
drivers/gpu/drm/i915/intel_dp_link_training.c +23 -2
index 0048b52..cb28788 100644
@@ -313,6 +313,27 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 void
 intel_dp_start_link_train(struct intel_dp *intel_dp)
 {
-	intel_dp_link_training_clock_recovery(intel_dp);
-	intel_dp_link_training_channel_equalization(intel_dp);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+
+	if (!intel_dp_link_training_clock_recovery(intel_dp))
+		goto failure_handling;
+	if (!intel_dp_link_training_channel_equalization(intel_dp))
+		goto failure_handling;
+
+	/* Reset the Link Train Values */
+	DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+		      intel_dp->link_rate, intel_dp->lane_count);
+	intel_dp->fallback_link_rate = 0;
+	intel_dp->fallback_lane_count = 0;
+	return;
+
+ failure_handling:
+	DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+		      intel_dp->link_rate, intel_dp->lane_count);
+	if (!intel_dp_get_link_train_fallback_values(intel_dp,
+						     intel_dp->link_rate,
+						     intel_dp->lane_count))
+		/* Schedule a Hotplug Uevent to userspace to start modeset */
+		schedule_work(&intel_connector->modeset_retry_work);
+	return;
 }
drivers/gpu/drm/i915/intel_drv.h +3 -0
index 2da3b40..d95a51e 100644
@@ -315,6 +315,9 @@ struct intel_connector {
 	void *port; /* store this opaque as its illegal to dereference it */
 
 	struct intel_dp *mst_port;
+
+	/* Work struct to schedule a uevent on link train failure */
+	struct work_struct modeset_retry_work;
 };
 
 struct dpll {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

Re: [PATCH 3/3] drm/i915: Implement Link Rate fallback on Link training failure

Quoted 53 lines · Manasi Navare

If link training at a link rate optimal for a particular mode fails during modeset's atomic commit phase, then we let the modeset complete and then retry. We save the link rate value at which link training failed, update the link status property to "BAD" and use a lower link rate to prune the modes. It will redo the modeset on the current mode at lower link rate or if the current mode gets pruned due to lower link constraints then, it will send a hotplug uevent for userspace to handle it.

This is also required to pass DP CTS tests 4.3.1.3, 4.3.1.4, 4.3.1.6.

v9:
* Use the trimmed max values of link rate/lane count based on link train fallback (Daniel Vetter)
v8:
* Set link_status to BAD first and then call mode_valid (Jani Nikula) v7:
Remove the redundant variable in previous patch itself
v6:
* Obtain link rate index from fallback_link_rate using
the helper intel_dp_link_rate_index (Jani Nikula)
* Include fallback within intel_dp_start_link_train (Jani Nikula) v5:
* Move set link status to drm core (Daniel Vetter, Jani Nikula) v4:
* Add fallback support for non DDI platforms too
* Set connector->link status inside set_link_status function (Jani Nikula)
v3:
* Set link status property to BAd unconditionally (Jani Nikula)
* Dont use two separate variables link_train_failed and link_status to indicate same thing (Jani Nikula)
v2:
* Squashed a few patches (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c               | 44 +++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_dp_link_training.c | 25 +++++++++++++--
 drivers/gpu/drm/i915/intel_drv.h              |  3 ++
 3 files changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +0 -0
index bc1268c..a50b6cd 100644

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4439

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
@@ -4435,6 +4435,8 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 		intel_dp->compliance_test_active = 0;
 		intel_dp->compliance_test_type = 0;
 		intel_dp->compliance_test_data = 0;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;

Hm, I thought we agreed on irc to just track the max link rate/lane count at all times, instead of fallback values that sometimes are valid and sometimes reset to 0.

Also, resetting to 0 here is wrong, since this is not the long-pulse hpd handler. That probably also explains why you need the hack below, but not sure.

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4536

Quoted 13 lines
drivers/gpu/drm/i915/intel_dp.c +6 -0
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4526,6 +4528,13 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
 		      connector->base.id, connector->name);
 
+	/* If this is a retry due to link training failure
+	 * then do no do a full detect
+	 */
+	if (status == connector_status_connected &&
+	    intel_dp->fallback_lane_count)
+		return status;

That sounds very wrong. Why do we need it?

Quoted 24 lines
drivers/gpu/drm/i915/intel_dp.c +17 -0
+
 	/* If full detect is not performed yet, do a full detect */
 	if (!intel_dp->detect_done)
 		status = intel_dp_long_pulse(intel_dp->attached_connector);
@@ -5690,6 +5699,37 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	return false;
 }
 
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
+{
+	struct intel_connector *intel_connector;
+	struct drm_connector *connector;
+	struct drm_display_mode *mode;
+	bool verbose_prune = true;
+
+	intel_connector = container_of(work, typeof(*intel_connector),
+				       modeset_retry_work);
+	connector = &intel_connector->base;
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	/* Set connector link status to BAD and send a Uevent to notify

drivers/gpu/drm/i915/intel_dp.c static bool intel_edp_init_connector(struct intel_dp *intel_dp, · line 5727

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+	 * userspace to do a modeset.
+	 */
+	drm_mode_connector_set_link_status_property(connector,
+						    DRM_MODE_LINK_STATUS_BAD);
+	list_for_each_entry(mode, &connector->modes, head) {
+		mode->status = intel_dp_mode_valid(connector,
+						   mode);
+	}
+	drm_mode_prune_invalid(connector->dev, &connector->modes,
+			       verbose_prune);

This call to drm_mode_prune_invalid is probably just to paper over a bug in SNA - SNA violates the hotplug handling uabi by not unconditionally reprobing. Inconsistently paper over that bug in the kernel is not good, userspace interfaces need to be well defined. Please remove this call and test with either UXA or -modesetting until SNA is fixed. -Daniel

Quoted 74 lines
drivers/gpu/drm/i915/intel_dp.c +9 -0
+	mutex_unlock(&connector->dev->mode_config.mutex);
+	/* Send Hotplug uevent so userspace can reprobe */
+	drm_kms_helper_hotplug_event(connector->dev);
+}
+
 bool
 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
 			struct intel_connector *intel_connector)
@@ -5702,6 +5742,10 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	enum port port = intel_dig_port->port;
 	int type;
 
+	/* Initialize the work for modeset in case of link train failure */
+	INIT_WORK(&intel_connector->modeset_retry_work,
+		  intel_dp_modeset_retry_work_fn);
+
 	if (WARN(intel_dig_port->max_lanes < 1,
 		 "Not enough lanes (%d) for DP on port %c\n",
 		 intel_dig_port->max_lanes, port_name(port)))
drivers/gpu/drm/i915/intel_dp_link_training.c +23 -2
index 0048b52..cb28788 100644
@@ -313,6 +313,27 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 void
 intel_dp_start_link_train(struct intel_dp *intel_dp)
 {
-	intel_dp_link_training_clock_recovery(intel_dp);
-	intel_dp_link_training_channel_equalization(intel_dp);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+
+	if (!intel_dp_link_training_clock_recovery(intel_dp))
+		goto failure_handling;
+	if (!intel_dp_link_training_channel_equalization(intel_dp))
+		goto failure_handling;
+
+	/* Reset the Link Train Values */
+	DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+		      intel_dp->link_rate, intel_dp->lane_count);
+	intel_dp->fallback_link_rate = 0;
+	intel_dp->fallback_lane_count = 0;
+	return;
+
+ failure_handling:
+	DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+		      intel_dp->link_rate, intel_dp->lane_count);
+	if (!intel_dp_get_link_train_fallback_values(intel_dp,
+						     intel_dp->link_rate,
+						     intel_dp->lane_count))
+		/* Schedule a Hotplug Uevent to userspace to start modeset */
+		schedule_work(&intel_connector->modeset_retry_work);
+	return;
 }
drivers/gpu/drm/i915/intel_drv.h +3 -0
index 2da3b40..d95a51e 100644
@@ -315,6 +315,9 @@ struct intel_connector {
 	void *port; /* store this opaque as its illegal to dereference it */
 
 	struct intel_dp *mst_port;
+
+	/* Work struct to schedule a uevent on link train failure */
+	struct work_struct modeset_retry_work;
 };
 
 struct dpll {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

Re: [PATCH 3/3] drm/i915: Implement Link Rate fallback on Link training failure

Quoted 116 lines · Daniel Vetter
Quoted 53 lines · Manasi Navare

If link training at a link rate optimal for a particular mode fails during modeset's atomic commit phase, then we let the modeset complete and then retry. We save the link rate value at which link training failed, update the link status property to "BAD" and use a lower link rate to prune the modes. It will redo the modeset on the current mode at lower link rate or if the current mode gets pruned due to lower link constraints then, it will send a hotplug uevent for userspace to handle it.

This is also required to pass DP CTS tests 4.3.1.3, 4.3.1.4, 4.3.1.6.

v9:
* Use the trimmed max values of link rate/lane count based on link train fallback (Daniel Vetter)
v8:
* Set link_status to BAD first and then call mode_valid (Jani Nikula) v7:
Remove the redundant variable in previous patch itself
v6:
* Obtain link rate index from fallback_link_rate using
the helper intel_dp_link_rate_index (Jani Nikula)
* Include fallback within intel_dp_start_link_train (Jani Nikula) v5:
* Move set link status to drm core (Daniel Vetter, Jani Nikula) v4:
* Add fallback support for non DDI platforms too
* Set connector->link status inside set_link_status function (Jani Nikula)
v3:
* Set link status property to BAd unconditionally (Jani Nikula)
* Dont use two separate variables link_train_failed and link_status to indicate same thing (Jani Nikula)
v2:
* Squashed a few patches (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c               | 44 +++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_dp_link_training.c | 25 +++++++++++++--
 drivers/gpu/drm/i915/intel_drv.h              |  3 ++
 3 files changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +0 -0
index bc1268c..a50b6cd 100644

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4439

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
@@ -4435,6 +4435,8 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 		intel_dp->compliance_test_active = 0;
 		intel_dp->compliance_test_type = 0;
 		intel_dp->compliance_test_data = 0;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;

Hm, I thought we agreed on irc to just track the max link rate/lane count at all times, instead of fallback values that sometimes are valid and sometimes reset to 0.

Also, resetting to 0 here is wrong, since this is not the long-pulse hpd handler. That probably also explains why you need the hack below, but not sure.

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4536

Quoted 13 lines
drivers/gpu/drm/i915/intel_dp.c +6 -0
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4526,6 +4528,13 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
 		      connector->base.id, connector->name);
 
+	/* If this is a retry due to link training failure
+	 * then do no do a full detect
+	 */
+	if (status == connector_status_connected &&
+	    intel_dp->fallback_lane_count)
+		return status;

That sounds very wrong. Why do we need it?

Quoted 32 lines
drivers/gpu/drm/i915/intel_dp.c +25 -0
+
 	/* If full detect is not performed yet, do a full detect */
 	if (!intel_dp->detect_done)
 		status = intel_dp_long_pulse(intel_dp->attached_connector);
@@ -5690,6 +5699,37 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	return false;
 }
 
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
+{
+	struct intel_connector *intel_connector;
+	struct drm_connector *connector;
+	struct drm_display_mode *mode;
+	bool verbose_prune = true;
+
+	intel_connector = container_of(work, typeof(*intel_connector),
+				       modeset_retry_work);
+	connector = &intel_connector->base;
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	/* Set connector link status to BAD and send a Uevent to notify
+	 * userspace to do a modeset.
+	 */
+	drm_mode_connector_set_link_status_property(connector,
+						    DRM_MODE_LINK_STATUS_BAD);
+	list_for_each_entry(mode, &connector->modes, head) {
+		mode->status = intel_dp_mode_valid(connector,
+						   mode);
+	}
Quoted 8 lines

drivers/gpu/drm/i915/intel_dp.c static bool intel_edp_init_connector(struct intel_dp *intel_dp, · line 5727

Quoted 2 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
+	drm_mode_prune_invalid(connector->dev, &connector->modes,
+			       verbose_prune);

This call to drm_mode_prune_invalid is probably just to paper over a bug in SNA - SNA violates the hotplug handling uabi by not unconditionally reprobing. Inconsistently paper over that bug in the kernel is not good, userspace interfaces need to be well defined. Please remove this call and test with either UXA or -modesetting until SNA is fixed.

This is not required for link retraining in userspace, since userspace's response to seeing the link-status == BAD property is to retrain the current mode (and then it checks link-status again to see if the modeset worked because returning an error from the modeset seems troublesome). After that it reprobes. However, the kernel must still fail the modeset following link-status = BAD if it decides that the mode is no longer valid.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

Re: [Intel-gfx] [PATCH 3/3] drm/i915: Implement Link Rate fallback on Link training failure

In reply to Daniel Vetter
Quoted 25 lines · Daniel Vetter
Quoted 24 lines · Manasi Navare
drivers/gpu/drm/i915/intel_dp.c +24 -0
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
+{
+	struct intel_connector *intel_connector;
+	struct drm_connector *connector;
+	struct drm_display_mode *mode;
+	bool verbose_prune = true;
+
+	intel_connector = container_of(work, typeof(*intel_connector),
+				       modeset_retry_work);
+	connector = &intel_connector->base;
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	/* Set connector link status to BAD and send a Uevent to notify
+	 * userspace to do a modeset.
+	 */
+	drm_mode_connector_set_link_status_property(connector,
+						    DRM_MODE_LINK_STATUS_BAD);
+	list_for_each_entry(mode, &connector->modes, head) {
+		mode->status = intel_dp_mode_valid(connector,
+						   mode);
+	}
Quoted 8 lines

drivers/gpu/drm/i915/intel_dp.c static bool intel_edp_init_connector(struct intel_dp *intel_dp, · line 5727

Quoted 2 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
+	drm_mode_prune_invalid(connector->dev, &connector->modes,
+			       verbose_prune);

This call to drm_mode_prune_invalid is probably just to paper over a bug in SNA - SNA violates the hotplug handling uabi by not unconditionally reprobing. Inconsistently paper over that bug in the kernel is not good, userspace interfaces need to be well defined. Please remove this call and test with either UXA or -modesetting until SNA is fixed.

Then you should also categorically state that (once again) misusing the HOTPLUG uevent for notification of a property update is wrong. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [PATCH 3/3] drm/i915: Implement Link Rate fallback on Link training failure

In reply to Daniel Vetter
Quoted 114 lines · Daniel Vetter
Quoted 53 lines · Manasi Navare

If link training at a link rate optimal for a particular mode fails during modeset's atomic commit phase, then we let the modeset complete and then retry. We save the link rate value at which link training failed, update the link status property to "BAD" and use a lower link rate to prune the modes. It will redo the modeset on the current mode at lower link rate or if the current mode gets pruned due to lower link constraints then, it will send a hotplug uevent for userspace to handle it.

This is also required to pass DP CTS tests 4.3.1.3, 4.3.1.4, 4.3.1.6.

v9:
* Use the trimmed max values of link rate/lane count based on link train fallback (Daniel Vetter)
v8:
* Set link_status to BAD first and then call mode_valid (Jani Nikula) v7:
Remove the redundant variable in previous patch itself
v6:
* Obtain link rate index from fallback_link_rate using
the helper intel_dp_link_rate_index (Jani Nikula)
* Include fallback within intel_dp_start_link_train (Jani Nikula) v5:
* Move set link status to drm core (Daniel Vetter, Jani Nikula) v4:
* Add fallback support for non DDI platforms too
* Set connector->link status inside set_link_status function (Jani Nikula)
v3:
* Set link status property to BAd unconditionally (Jani Nikula)
* Dont use two separate variables link_train_failed and link_status to indicate same thing (Jani Nikula)
v2:
* Squashed a few patches (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c               | 44 +++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_dp_link_training.c | 25 +++++++++++++--
 drivers/gpu/drm/i915/intel_drv.h              |  3 ++
 3 files changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +0 -0
index bc1268c..a50b6cd 100644

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4439

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
@@ -4435,6 +4435,8 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 		intel_dp->compliance_test_active = 0;
 		intel_dp->compliance_test_type = 0;
 		intel_dp->compliance_test_data = 0;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;

Hm, I thought we agreed on irc to just track the max link rate/lane count at all times, instead of fallback values that sometimes are valid and sometimes reset to 0.

Also, resetting to 0 here is wrong, since this is not the long-pulse hpd handler. That probably also explains why you need the hack below, but not sure.

drivers/gpu/drm/i915/intel_dp.c static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, · line 4536

Quoted 13 lines
drivers/gpu/drm/i915/intel_dp.c +6 -0
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4526,6 +4528,13 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
 	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
 		      connector->base.id, connector->name);
 
+	/* If this is a retry due to link training failure
+	 * then do no do a full detect
+	 */
+	if (status == connector_status_connected &&
+	    intel_dp->fallback_lane_count)
+		return status;

That sounds very wrong. Why do we need it?

Quoted 30 lines
drivers/gpu/drm/i915/intel_dp.c +23 -0
+
 	/* If full detect is not performed yet, do a full detect */
 	if (!intel_dp->detect_done)
 		status = intel_dp_long_pulse(intel_dp->attached_connector);
@@ -5690,6 +5699,37 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
 	return false;
 }
 
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
+{
+	struct intel_connector *intel_connector;
+	struct drm_connector *connector;
+	struct drm_display_mode *mode;
+	bool verbose_prune = true;
+
+	intel_connector = container_of(work, typeof(*intel_connector),
+				       modeset_retry_work);
+	connector = &intel_connector->base;
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	/* Set connector link status to BAD and send a Uevent to notify
+	 * userspace to do a modeset.
+	 */
+	drm_mode_connector_set_link_status_property(connector,
+						    DRM_MODE_LINK_STATUS_BAD);
+	list_for_each_entry(mode, &connector->modes, head) {
+		mode->status = intel_dp_mode_valid(connector,
Quoted 8 lines

drivers/gpu/drm/i915/intel_dp.c static bool intel_edp_init_connector(struct intel_dp *intel_dp, · line 5727

Quoted 4 lines
drivers/gpu/drm/i915/intel_dp.c +4 -0
+						   mode);
+	}
+	drm_mode_prune_invalid(connector->dev, &connector->modes,
+			       verbose_prune);

This call to drm_mode_prune_invalid is probably just to paper over a bug in SNA - SNA violates the hotplug handling uabi by not unconditionally reprobing. Inconsistently paper over that bug in the kernel is not good,

I would categorize pruning here as "avoid pointless work later". Of course with the current uabi that might not happen anyway. Would be nice if it eventually did however.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

✗ Fi.CI.BAT: warning for series starting with [1/3] drm: Add a new connector atomic property for link status

In reply to Manasi Navare
== Series Details ==

== Series Details ==

Series: series starting with [1/3] drm: Add a new connector atomic property for link status
URL : https://patchwork.freedesktop.org/series/16150/
State : warning

== Summary ==

Series 16150v1 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/16150/revisions/1/mbox/

Test gem_exec_suspend:

        Subgroup basic-s3:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_busy:
        Subgroup basic-flip-default-a:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-default-b:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-default-c:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_cursor_legacy:
        Subgroup basic-busy-flip-before-cursor-legacy:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-busy-flip-before-cursor-varying-size:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-after-cursor-legacy:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-after-cursor-varying-size:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-before-cursor-legacy:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-before-cursor-varying-size:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_flip:
        Subgroup basic-flip-vs-dpms:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-vs-modeset:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-flip-vs-wf_vblank:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-plain-flip:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_frontbuffer_tracking:
        Subgroup basic:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_pipe_crc_basic:
        Subgroup hang-read-crc-pipe-a:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup hang-read-crc-pipe-b:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup hang-read-crc-pipe-c:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-a:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-a-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-b:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-b-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-c:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup nonblocking-crc-pipe-c-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-a:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-a-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-b:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-b-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-c:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup read-crc-pipe-c-frame-sequence:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup suspend-read-crc-pipe-a:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup suspend-read-crc-pipe-b:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup suspend-read-crc-pipe-c:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test kms_setmode:
        Subgroup basic-clone-single-crtc:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test pm_rpm:
        Subgroup basic-pci-d3-state:
                pass       -> DMESG-WARN (fi-skl-6700k)
        Subgroup basic-rte:
                pass       -> DMESG-WARN (fi-skl-6700k)
Test prime_vgem:
        Subgroup basic-fence-flip:
                pass       -> DMESG-WARN (fi-skl-6700k)
fi-bdw-5557u     total:245  pass:230  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:245  pass:205  dwarn:0   dfail:0   fail:0   skip:40 
fi-bxt-t5700     total:245  pass:217  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-j1900     total:245  pass:217  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-n2820     total:245  pass:213  dwarn:0   dfail:0   fail:0   skip:32 
fi-hsw-4770      total:245  pass:225  dwarn:0   dfail:0   fail:0   skip:20 
fi-hsw-4770r     total:245  pass:225  dwarn:0   dfail:0   fail:0   skip:20 
fi-ilk-650       total:245  pass:192  dwarn:0   dfail:0   fail:0   skip:53 
fi-ivb-3520m     total:245  pass:223  dwarn:0   dfail:0   fail:0   skip:22 
fi-ivb-3770      total:245  pass:223  dwarn:0   dfail:0   fail:0   skip:22 
fi-kbl-7500u     total:245  pass:223  dwarn:0   dfail:0   fail:0   skip:22 
fi-skl-6260u     total:245  pass:231  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:245  pass:224  dwarn:0   dfail:0   fail:0   skip:21 

WARNING: Long output truncated

41799fbb771e82427273492bfad8f2e2ae3027ef drm-tip: 2016y-11m-29d-20h-54m-07s UTC integration manifest 9eedb94 drm/i915: Implement Link Rate fallback on Link training failure
4b05a48 drm/i915: Find fallback link rate/lane count
96d4eab drm: Add a new connector atomic property for link status

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3149/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw
In reply to Manasi Navare

Sean, could you please review this patch, I have tried to address all the comments from you.

Regards
Manasi

Quoted 294 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +8 -0
index 494680c..962ed66 100644
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}
 	}
 
 	/*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
 								NULL);
 			if (ret)
 				return ret;
+			conn_state->link_status = DRM_LINK_STATUS_GOOD;
 		}
 	}
 
drivers/gpu/drm/drm_connector.c +53 -1
index 5a45262..8902367 100644
@@ -243,6 +243,10 @@ int drm_connector_init(struct drm_device *dev,
 	drm_object_attach_property(&connector->base,
 				      config->dpms_property, 0);
 
+	drm_object_attach_property(&connector->base,
+				   config->link_status_property,
+				   0);
+
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
 	}
@@ -506,6 +510,12 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 };
 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 
+static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
+	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
+	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
+};
+DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list)
+
 /**
  * drm_display_info_set_bus_formats - set the supported bus formats
  * @info: display info to store bus formats in
@@ -625,7 +635,11 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  * 	should update this value using drm_mode_connector_set_tile_property().
  * 	Userspace cannot change this property.
- *
+ * link-status:
+ *      Connector link-status property to indicate the status of link. The default
+ *      value of link-status is "GOOD". If something fails during or after modeset,
+ *      the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
+ *      should update this value using drm_mode_connector_set_link_status_property().
  * Connectors also have one standardized atomic property:
  *
  * CRTC_ID:
@@ -666,6 +680,13 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.tile_property = prop;
 
+	prop = drm_property_create_enum(dev, 0, "link-status",
+					drm_link_status_enum_list,
+					ARRAY_SIZE(drm_link_status_enum_list));
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.link_status_property = prop;
+
 	return 0;
 }
 
@@ -995,6 +1016,37 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+/**
+ * drm_mode_connector_set_link_status_property - Set link status property of a connector
+ * @connector: drm connector
+ * @link_status: new value of link status property (0: Good, 1: Bad)
+ *
+ * In usual working scenario, this link status property will always be set to
+ * "GOOD". If something fails during or after a mode set, the kernel driver
+ * may set this link status property to "BAD". The caller then needs to send a
+ * hotplug uevent for userspace to re-check the valid modes through
+ * GET_CONNECTOR_IOCTL and retry modeset.
+ *
+ * Note: Drivers cannot rely on userspace to support this property and
+ * issue a modeset. As such, they may choose to handle issues (like
+ * re-training a link) without userspace's intervention.
+ *
+ * The reason for adding this property is to handle link training failures, but
+ * it is not limited to DP or link training. For example, if we implement
+ * asynchronous setcrtc, this property can be used to report any failures in that.
+ */
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+	connector->state->link_status = link_status;
+	drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+}
+EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
+
 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
 	struct drm_encoder *best_encoder;
 
+	/**
+	 * @link_status: Connector link_status to keep track of whether link is
+	 * GOOD or BAD to notify userspace if retraining is necessary.
+	 */
+	enum drm_link_status link_status;
+
 	struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 					    const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
 	 */
 	struct drm_property *tile_property;
 	/**
+	 * @link_status_property: Default connector property for link status
+	 * of a connector
+	 */
+	struct drm_property *link_status_property;
+	/**
 	 * @plane_type_property: Default plane property to differentiate
 	 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
 	 */
include/uapi/drm/drm_mode.h +4 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD	0
+#define DRM_MODE_LINK_STATUS_BAD	1
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
Signature · 1 line
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#9 lore raw
Quoted 3 lines · Manasi Navare

Sean, could you please review this patch, I have tried to address all the comments from you.

Comments look good to me.

Sean

Quoted 288 lines

Regards
Manasi

Quoted 284 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
               * now?) atomic writes to DPMS property:
               */
              return -EINVAL;
+     } else if (property == config->link_status_property) {
+             /* Never downgrade from GOOD to BAD on userspace's request here,
+              * only hw issues can do that.
+              */
+             if (state->link_status == DRM_LINK_STATUS_GOOD)
+                     return 0;
+             state->link_status = val;
+             return 0;
      } else if (connector->funcs->atomic_set_property) {
              return connector->funcs->atomic_set_property(connector,
                              state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
              *val = (state->crtc) ? state->crtc->base.id : 0;
      } else if (property == config->dpms_property) {
              *val = connector->dpms;
+     } else if (property == config->link_status_property) {
+             *val = state->link_status;
      } else if (connector->funcs->atomic_get_property) {
              return connector->funcs->atomic_get_property(connector,
                              state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +8 -0
index 494680c..962ed66 100644
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
                                             connector_state);
              if (ret)
                      return ret;
+             if (connector->state->crtc) {
+                     crtc_state = drm_atomic_get_existing_crtc_state(state,
+                                                                     connector->state->crtc);
+                     if (connector->state->link_status !=
+                         connector_state->link_status)
+                             crtc_state->connectors_changed = true;
+             }
      }
 
      /*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
                                                              NULL);
                      if (ret)
                              return ret;
+                     conn_state->link_status = DRM_LINK_STATUS_GOOD;
              }
      }
 
drivers/gpu/drm/drm_connector.c +53 -1
index 5a45262..8902367 100644
@@ -243,6 +243,10 @@ int drm_connector_init(struct drm_device *dev,
      drm_object_attach_property(&connector->base,
                                    config->dpms_property, 0);
 
+     drm_object_attach_property(&connector->base,
+                                config->link_status_property,
+                                0);
+
      if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
              drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
      }
@@ -506,6 +510,12 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 };
 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 
+static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
+     { DRM_MODE_LINK_STATUS_GOOD, "Good" },
+     { DRM_MODE_LINK_STATUS_BAD, "Bad" },
+};
+DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list)
+
 /**
  * drm_display_info_set_bus_formats - set the supported bus formats
  * @info: display info to store bus formats in
@@ -625,7 +635,11 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  *   tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  *   should update this value using drm_mode_connector_set_tile_property().
  *   Userspace cannot change this property.
- *
+ * link-status:
+ *      Connector link-status property to indicate the status of link. The default
+ *      value of link-status is "GOOD". If something fails during or after modeset,
+ *      the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
+ *      should update this value using drm_mode_connector_set_link_status_property().
  * Connectors also have one standardized atomic property:
  *
  * CRTC_ID:
@@ -666,6 +680,13 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
              return -ENOMEM;
      dev->mode_config.tile_property = prop;
 
+     prop = drm_property_create_enum(dev, 0, "link-status",
+                                     drm_link_status_enum_list,
+                                     ARRAY_SIZE(drm_link_status_enum_list));
+     if (!prop)
+             return -ENOMEM;
+     dev->mode_config.link_status_property = prop;
+
      return 0;
 }
 
@@ -995,6 +1016,37 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+/**
+ * drm_mode_connector_set_link_status_property - Set link status property of a connector
+ * @connector: drm connector
+ * @link_status: new value of link status property (0: Good, 1: Bad)
+ *
+ * In usual working scenario, this link status property will always be set to
+ * "GOOD". If something fails during or after a mode set, the kernel driver
+ * may set this link status property to "BAD". The caller then needs to send a
+ * hotplug uevent for userspace to re-check the valid modes through
+ * GET_CONNECTOR_IOCTL and retry modeset.
+ *
+ * Note: Drivers cannot rely on userspace to support this property and
+ * issue a modeset. As such, they may choose to handle issues (like
+ * re-training a link) without userspace's intervention.
+ *
+ * The reason for adding this property is to handle link training failures, but
+ * it is not limited to DP or link training. For example, if we implement
+ * asynchronous setcrtc, this property can be used to report any failures in that.
+ */
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+                                              uint64_t link_status)
+{
+     struct drm_device *dev = connector->dev;
+
+     drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+     connector->state->link_status = link_status;
+     drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+}
+EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
+
 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
                                  struct drm_property *property,
                                  uint64_t value)
include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+     DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+     DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
      struct drm_encoder *best_encoder;
 
+     /**
+      * @link_status: Connector link_status to keep track of whether link is
+      * GOOD or BAD to notify userspace if retraining is necessary.
+      */
+     enum drm_link_status link_status;
+
      struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
                                          const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+                                              uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
       */
      struct drm_property *tile_property;
      /**
+      * @link_status_property: Default connector property for link status
+      * of a connector
+      */
+     struct drm_property *link_status_property;
+     /**
       * @plane_type_property: Default plane property to differentiate
       * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
       */
include/uapi/drm/drm_mode.h +0 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
Quoted 10 lines
Quoted 10 lines
include/uapi/drm/drm_mode.h +4 -1
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD    0
+#define DRM_MODE_LINK_STATUS_BAD     1
+
 struct drm_mode_modeinfo {
      __u32 clock;
      __u16 hdisplay;
--

1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw
In reply to Manasi Navare
Quoted 102 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 494680c..962ed66 100644

drivers/gpu/drm/drm_atomic_helper.c static int handle_conflicting_encoders(struct drm_atomic_state *state, · line 528

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +7 -0
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}

See my previous review, this looks should imo be moved to a more obvious place than hidden deep down in the callchain.

drivers/gpu/drm/drm_atomic_helper.c static int update_output_state(struct drm_atomic_state *state, · line 2268

Quoted 8 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -0
 	}
 
 	/*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
 								NULL);
 			if (ret)
 				return ret;
+			conn_state->link_status = DRM_LINK_STATUS_GOOD;

Iirc in our discussion we said a small comment here would be good, like

			/* Make sure legacy setCrtc always re-trains. */

Might also be good to update the kernel-doc of
drm_atomic_helper_set_config(). Something like

* NOTE: For backwards compatibility with old userspace this automatically
* resets the "link-status" property to GOOD, to force any link
* re-training. The SETCRTC ioctl does not define whether an update does
* need a full modeset or just a plane update, hence we're allowed to do
* that. See also drm_mode_connector_set_link_status_property(). *

Quoted 32 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 		}
 	}
 
drivers/gpu/drm/drm_connector.c +10 -0
index 5a45262..8902367 100644
@@ -243,6 +243,10 @@ int drm_connector_init(struct drm_device *dev,
 	drm_object_attach_property(&connector->base,
 				      config->dpms_property, 0);
 
+	drm_object_attach_property(&connector->base,
+				   config->link_status_property,
+				   0);
+
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
 	}
@@ -506,6 +510,12 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 };
 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 
+static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
+	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
+	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
+};
+DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list)
+
 /**
  * drm_display_info_set_bus_formats - set the supported bus formats
  * @info: display info to store bus formats in

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 628

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0 -1
@@ -625,7 +635,11 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  * 	should update this value using drm_mode_connector_set_tile_property().
  * 	Userspace cannot change this property.
- *

One more from last round: Please leave this whitespace intact ...

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 642

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ * link-status:
+ *      Connector link-status property to indicate the status of link. The default
+ *      value of link-status is "GOOD". If something fails during or after modeset,
+ *      the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
+ *      should update this value using drm_mode_connector_set_link_status_property().

... and add an empty line here.

Quoted 31 lines
drivers/gpu/drm/drm_connector.c +17 -0
  * Connectors also have one standardized atomic property:
  *
  * CRTC_ID:
@@ -666,6 +680,13 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.tile_property = prop;
 
+	prop = drm_property_create_enum(dev, 0, "link-status",
+					drm_link_status_enum_list,
+					ARRAY_SIZE(drm_link_status_enum_list));
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.link_status_property = prop;
+
 	return 0;
 }
 
@@ -995,6 +1016,37 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+/**
+ * drm_mode_connector_set_link_status_property - Set link status property of a connector
+ * @connector: drm connector
+ * @link_status: new value of link status property (0: Good, 1: Bad)
+ *
+ * In usual working scenario, this link status property will always be set to
+ * "GOOD". If something fails during or after a mode set, the kernel driver
+ * may set this link status property to "BAD". The caller then needs to send a
+ * hotplug uevent for userspace to re-check the valid modes through
+ * GET_CONNECTOR_IOCTL and retry modeset.

drivers/gpu/drm/drm_connector.c int drm_mode_connector_update_edid_property(struct drm_connector *connector, · line 1038

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *
+ * Note: Drivers cannot rely on userspace to support this property and
+ * issue a modeset. As such, they may choose to handle issues (like
+ * re-training a link) without userspace's intervention.
+ *
+ * The reason for adding this property is to handle link training failures, but
+ * it is not limited to DP or link training. For example, if we implement
+ * asynchronous setcrtc, this property can be used to report any failures in that.
+ */
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,

Hm, tiny new bikeshed: I'd drop the _property postfix here. The function name is already really long as-is, and the fact that the link status is exposed as a property is kinda irrelevant for kernel driver writers. But up to you.
-Daniel

Quoted 96 lines
drivers/gpu/drm/drm_connector.c +11 -0
+						 uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+	connector->state->link_status = link_status;
+	drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+}
+EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
+
 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
 	struct drm_encoder *best_encoder;
 
+	/**
+	 * @link_status: Connector link_status to keep track of whether link is
+	 * GOOD or BAD to notify userspace if retraining is necessary.
+	 */
+	enum drm_link_status link_status;
+
 	struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 					    const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
 	 */
 	struct drm_property *tile_property;
 	/**
+	 * @link_status_property: Default connector property for link status
+	 * of a connector
+	 */
+	struct drm_property *link_status_property;
+	/**
 	 * @plane_type_property: Default plane property to differentiate
 	 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
 	 */
include/uapi/drm/drm_mode.h +4 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD	0
+#define DRM_MODE_LINK_STATUS_BAD	1
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
Quoted 108 lines · Daniel Vetter
Quoted 107 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +2 -0
index 494680c..962ed66 100644
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
Quoted 10 lines

drivers/gpu/drm/drm_atomic_helper.c static int handle_conflicting_encoders(struct drm_atomic_state *state, · line 528

Quoted 5 lines
drivers/gpu/drm/drm_atomic_helper.c +5 -0
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}

See my previous review, this looks should imo be moved to a more obvious place than hidden deep down in the callchain.

Quoted 1 line
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 	}

Yes I have looked at your previous review and this is inside drm_atomic_helper_check_modeset() function just inside the connectors loop. Its not in the handle_conflicting_encoders function. Its weird that in the diff it is showing up here.
If you pull the patch you will see that it is written as follows:

for_each_connector_in_state(state, connector, connector_state, i) {
                /*
                 * This only sets crtc->connectors_changed for routing changes,
                 * drivers must set crtc->connectors_changed themselves when
                 * connector properties need to be updated.
                 */
                ret = update_connector_routing(state, connector,
                                               connector_state);
                if (ret)
                        return ret;
                if (connector->state->crtc) {
                        crtc_state = drm_atomic_get_existing_crtc_state(state,
                                                                        connector->state->crtc);
                        if (connector->state->link_status !=
                            connector_state->link_status)
                                crtc_state->connectors_changed = true;
                }
        }

Is this correct?

Manasi

Quoted 209 lines

drivers/gpu/drm/drm_atomic_helper.c static int update_output_state(struct drm_atomic_state *state, · line 2268

Quoted 7 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -0
 	/*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
 								NULL);
 			if (ret)
 				return ret;
+			conn_state->link_status = DRM_LINK_STATUS_GOOD;

Iirc in our discussion we said a small comment here would be good, like

			/* Make sure legacy setCrtc always re-trains. */

Might also be good to update the kernel-doc of
drm_atomic_helper_set_config(). Something like

* NOTE: For backwards compatibility with old userspace this automatically
* resets the "link-status" property to GOOD, to force any link
* re-training. The SETCRTC ioctl does not define whether an update does
* need a full modeset or just a plane update, hence we're allowed to do
* that. See also drm_mode_connector_set_link_status_property(). *

Quoted 32 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 		}
 	}
 
drivers/gpu/drm/drm_connector.c +10 -0
index 5a45262..8902367 100644
@@ -243,6 +243,10 @@ int drm_connector_init(struct drm_device *dev,
 	drm_object_attach_property(&connector->base,
 				      config->dpms_property, 0);
 
+	drm_object_attach_property(&connector->base,
+				   config->link_status_property,
+				   0);
+
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
 	}
@@ -506,6 +510,12 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 };
 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 
+static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
+	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
+	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
+};
+DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list)
+
 /**
  * drm_display_info_set_bus_formats - set the supported bus formats
  * @info: display info to store bus formats in

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 628

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0 -1
@@ -625,7 +635,11 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  * 	should update this value using drm_mode_connector_set_tile_property().
  * 	Userspace cannot change this property.
- *

One more from last round: Please leave this whitespace intact ...

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 642

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ * link-status:
+ *      Connector link-status property to indicate the status of link. The default
+ *      value of link-status is "GOOD". If something fails during or after modeset,
+ *      the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
+ *      should update this value using drm_mode_connector_set_link_status_property().

... and add an empty line here.

Quoted 31 lines
drivers/gpu/drm/drm_connector.c +17 -0
  * Connectors also have one standardized atomic property:
  *
  * CRTC_ID:
@@ -666,6 +680,13 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.tile_property = prop;
 
+	prop = drm_property_create_enum(dev, 0, "link-status",
+					drm_link_status_enum_list,
+					ARRAY_SIZE(drm_link_status_enum_list));
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.link_status_property = prop;
+
 	return 0;
 }
 
@@ -995,6 +1016,37 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+/**
+ * drm_mode_connector_set_link_status_property - Set link status property of a connector
+ * @connector: drm connector
+ * @link_status: new value of link status property (0: Good, 1: Bad)
+ *
+ * In usual working scenario, this link status property will always be set to
+ * "GOOD". If something fails during or after a mode set, the kernel driver
+ * may set this link status property to "BAD". The caller then needs to send a
+ * hotplug uevent for userspace to re-check the valid modes through
+ * GET_CONNECTOR_IOCTL and retry modeset.

drivers/gpu/drm/drm_connector.c int drm_mode_connector_update_edid_property(struct drm_connector *connector, · line 1038

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ *
+ * Note: Drivers cannot rely on userspace to support this property and
+ * issue a modeset. As such, they may choose to handle issues (like
+ * re-training a link) without userspace's intervention.
+ *
+ * The reason for adding this property is to handle link training failures, but
+ * it is not limited to DP or link training. For example, if we implement
+ * asynchronous setcrtc, this property can be used to report any failures in that.
+ */
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,

Hm, tiny new bikeshed: I'd drop the _property postfix here. The function name is already really long as-is, and the fact that the link status is exposed as a property is kinda irrelevant for kernel driver writers. But up to you.
-Daniel

Quoted 92 lines
drivers/gpu/drm/drm_connector.c +11 -0
+						 uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+	connector->state->link_status = link_status;
+	drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+}
+EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
+
 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
 	struct drm_encoder *best_encoder;
 
+	/**
+	 * @link_status: Connector link_status to keep track of whether link is
+	 * GOOD or BAD to notify userspace if retraining is necessary.
+	 */
+	enum drm_link_status link_status;
+
 	struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 					    const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
 	 */
 	struct drm_property *tile_property;
 	/**
+	 * @link_status_property: Default connector property for link status
+	 * of a connector
+	 */
+	struct drm_property *link_status_property;
+	/**
 	 * @plane_type_property: Default plane property to differentiate
 	 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
 	 */
include/uapi/drm/drm_mode.h +4 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD	0
+#define DRM_MODE_LINK_STATUS_BAD	1
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
Signature · 1 line
1.9.1
Quoted 13 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw
Quoted 144 lines · Manasi Navare
Quoted 108 lines · Daniel Vetter
Quoted 107 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +2 -0
index 494680c..962ed66 100644
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
Quoted 10 lines

drivers/gpu/drm/drm_atomic_helper.c static int handle_conflicting_encoders(struct drm_atomic_state *state, · line 528

Quoted 5 lines
drivers/gpu/drm/drm_atomic_helper.c +5 -0
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}

See my previous review, this looks should imo be moved to a more obvious place than hidden deep down in the callchain.

Quoted 1 line
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 	}

Yes I have looked at your previous review and this is inside drm_atomic_helper_check_modeset() function just inside the connectors loop. Its not in the handle_conflicting_encoders function. Its weird that in the diff it is showing up here.
If you pull the patch you will see that it is written as follows:

for_each_connector_in_state(state, connector, connector_state, i) {
                /*
                 * This only sets crtc->connectors_changed for routing changes,
                 * drivers must set crtc->connectors_changed themselves when
                 * connector properties need to be updated.
                 */
                ret = update_connector_routing(state, connector,
                                               connector_state);
                if (ret)
                        return ret;
                if (connector->state->crtc) {
                        crtc_state = drm_atomic_get_existing_crtc_state(state,
                                                                        connector->state->crtc);
                        if (connector->state->link_status !=
                            connector_state->link_status)
                                crtc_state->connectors_changed = true;
                }
        }
Quoted 1 line

Is this correct?

Yup, double checked myself, no idea what git diff is doing here thinking it's in a different function ...
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw
In reply to Daniel Vetter
Quoted 226 lines · Daniel Vetter
Quoted 102 lines · Manasi Navare

At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.

One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.

Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.

Both of the above ideas also fail to address link degradation *during* operation.

The solution is to add a new "link-status" connector property in order to address link training failure in a way that:
a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" and issue a hotplug uevent for userspace to have it re-check the valid modes through GET_CONNECTOR IOCTL, and try modeset again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

v4:
* Add comments in kernel-doc format (Daniel Vetter)
* Update the kernel-doc for link-status (Sean Paul)
v3:
* Fixed a build error (Jani Saarinen)
v2:
* Removed connector->link_status (Daniel Vetter)
* Set connector->state->link_status in drm_mode_connector_set_link_status_property (Daniel Vetter)
* Set the connector_changed flag to true if connector->state->link_status changed.
* Reset link_status to GOOD in update_output_state (Daniel Vetter)
* Never allow userspace to set link status from Good To Bad (Daniel Vetter)

---
 drivers/gpu/drm/drm_atomic.c        | 10 +++++++
 drivers/gpu/drm/drm_atomic_helper.c |  8 ++++++
 drivers/gpu/drm/drm_connector.c     | 54 ++++++++++++++++++++++++++++++++++++-
 include/drm/drm_connector.h         | 19 +++++++++++++
 include/drm/drm_mode_config.h       |  5 ++++
 include/uapi/drm/drm_mode.h         |  4 +++
 6 files changed, 99 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -0
index 89737e4..990f013 100644
@@ -1087,6 +1087,14 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
 		 * now?) atomic writes to DPMS property:
 		 */
 		return -EINVAL;
+	} else if (property == config->link_status_property) {
+		/* Never downgrade from GOOD to BAD on userspace's request here,
+		 * only hw issues can do that.
+		 */
+		if (state->link_status == DRM_LINK_STATUS_GOOD)
+			return 0;
+		state->link_status = val;
+		return 0;
 	} else if (connector->funcs->atomic_set_property) {
 		return connector->funcs->atomic_set_property(connector,
 				state, property, val);
@@ -1135,6 +1143,8 @@ static void drm_atomic_connector_print_state(struct drm_printer *p,
 		*val = (state->crtc) ? state->crtc->base.id : 0;
 	} else if (property == config->dpms_property) {
 		*val = connector->dpms;
+	} else if (property == config->link_status_property) {
+		*val = state->link_status;
 	} else if (connector->funcs->atomic_get_property) {
 		return connector->funcs->atomic_get_property(connector,
 				state, property, val);
drivers/gpu/drm/drm_atomic_helper.c +0 -0
index 494680c..962ed66 100644

drivers/gpu/drm/drm_atomic_helper.c static int handle_conflicting_encoders(struct drm_atomic_state *state, · line 528

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +7 -0
@@ -519,6 +519,13 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
 					       connector_state);
 		if (ret)
 			return ret;
+		if (connector->state->crtc) {
+			crtc_state = drm_atomic_get_existing_crtc_state(state,
+									connector->state->crtc);
+			if (connector->state->link_status !=
+			    connector_state->link_status)
+				crtc_state->connectors_changed = true;
+		}

See my previous review, this looks should imo be moved to a more obvious place than hidden deep down in the callchain.

drivers/gpu/drm/drm_atomic_helper.c static int update_output_state(struct drm_atomic_state *state, · line 2268

Quoted 8 lines
drivers/gpu/drm/drm_atomic_helper.c +1 -0
 	}
 
 	/*
@@ -2258,6 +2265,7 @@ static int update_output_state(struct drm_atomic_state *state,
 								NULL);
 			if (ret)
 				return ret;
+			conn_state->link_status = DRM_LINK_STATUS_GOOD;

Iirc in our discussion we said a small comment here would be good, like

			/* Make sure legacy setCrtc always re-trains. */

Might also be good to update the kernel-doc of
drm_atomic_helper_set_config(). Something like

* NOTE: For backwards compatibility with old userspace this automatically
* resets the "link-status" property to GOOD, to force any link
* re-training. The SETCRTC ioctl does not define whether an update does
* need a full modeset or just a plane update, hence we're allowed to do
* that. See also drm_mode_connector_set_link_status_property(). *

Quoted 32 lines
drivers/gpu/drm/drm_atomic_helper.c +0 -0
 		}
 	}
 
drivers/gpu/drm/drm_connector.c +10 -0
index 5a45262..8902367 100644
@@ -243,6 +243,10 @@ int drm_connector_init(struct drm_device *dev,
 	drm_object_attach_property(&connector->base,
 				      config->dpms_property, 0);
 
+	drm_object_attach_property(&connector->base,
+				   config->link_status_property,
+				   0);
+
 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
 	}
@@ -506,6 +510,12 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 };
 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
 
+static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
+	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
+	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
+};
+DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list)
+
 /**
  * drm_display_info_set_bus_formats - set the supported bus formats
  * @info: display info to store bus formats in

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 628

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0 -1
@@ -625,7 +635,11 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info,
  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
  * 	should update this value using drm_mode_connector_set_tile_property().
  * 	Userspace cannot change this property.
- *

One more from last round: Please leave this whitespace intact ...

drivers/gpu/drm/drm_connector.c int drm_display_info_set_bus_formats(struct drm_display_info *info, · line 642

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ * link-status:
+ *      Connector link-status property to indicate the status of link. The default
+ *      value of link-status is "GOOD". If something fails during or after modeset,
+ *      the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
+ *      should update this value using drm_mode_connector_set_link_status_property().

... and add an empty line here.

Quoted 39 lines
drivers/gpu/drm/drm_connector.c +25 -0
  * Connectors also have one standardized atomic property:
  *
  * CRTC_ID:
@@ -666,6 +680,13 @@ int drm_connector_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.tile_property = prop;
 
+	prop = drm_property_create_enum(dev, 0, "link-status",
+					drm_link_status_enum_list,
+					ARRAY_SIZE(drm_link_status_enum_list));
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.link_status_property = prop;
+
 	return 0;
 }
 
@@ -995,6 +1016,37 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
+/**
+ * drm_mode_connector_set_link_status_property - Set link status property of a connector
+ * @connector: drm connector
+ * @link_status: new value of link status property (0: Good, 1: Bad)
+ *
+ * In usual working scenario, this link status property will always be set to
+ * "GOOD". If something fails during or after a mode set, the kernel driver
+ * may set this link status property to "BAD". The caller then needs to send a
+ * hotplug uevent for userspace to re-check the valid modes through
+ * GET_CONNECTOR_IOCTL and retry modeset.
+ *
+ * Note: Drivers cannot rely on userspace to support this property and
+ * issue a modeset. As such, they may choose to handle issues (like
+ * re-training a link) without userspace's intervention.
+ *
+ * The reason for adding this property is to handle link training failures, but
+ * it is not limited to DP or link training. For example, if we implement
+ * asynchronous setcrtc, this property can be used to report any failures in that.
Quoted 9 lines

drivers/gpu/drm/drm_connector.c int drm_mode_connector_update_edid_property(struct drm_connector *connector, · line 1038

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ */
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,

Hm, tiny new bikeshed: I'd drop the _property postfix here. The function name is already really long as-is, and the fact that the link status is exposed as a property is kinda irrelevant for kernel driver writers. But up to you.
-Daniel

I decided to name it as drm_mode_connector_set_link_status_property() looking at names of other set_property functions like drm_mode_connector_update_edid_property() or drm_mode_connector_set_path_property(). Thats why I think it makes sense to append it with property just to be consistent.

Manasi

Quoted 92 lines
Quoted 92 lines
drivers/gpu/drm/drm_connector.c +11 -0
+						 uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
+	connector->state->link_status = link_status;
+	drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+}
+EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
+
 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
 				    struct drm_property *property,
 				    uint64_t value)
include/drm/drm_connector.h +19 -0
index 34f9741..53c5f70 100644
@@ -90,6 +90,17 @@ enum subpixel_order {
 };
 
 /**
+ * enum drm_link_status - connector's link_status property value
+ *
+ * This enum is used as the connector's link status property value.
+ * It is set to the values defined in uapi.
+ */
+enum drm_link_status {
+	DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
+	DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
+};
+
+/**
  * struct drm_display_info - runtime data about the connected sink
  *
  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
@@ -213,6 +224,12 @@ struct drm_connector_state {
 
 	struct drm_encoder *best_encoder;
 
+	/**
+	 * @link_status: Connector link_status to keep track of whether link is
+	 * GOOD or BAD to notify userspace if retraining is necessary.
+	 */
+	enum drm_link_status link_status;
+
 	struct drm_atomic_state *state;
 };
 
@@ -773,6 +790,8 @@ int drm_mode_connector_set_path_property(struct drm_connector *connector,
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 					    const struct edid *edid);
+void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						 uint64_t link_status);
 
 /**
  * struct drm_tile_group - Tile group metadata
include/drm/drm_mode_config.h +5 -0
index bf9991b..86faee4 100644
@@ -431,6 +431,11 @@ struct drm_mode_config {
 	 */
 	struct drm_property *tile_property;
 	/**
+	 * @link_status_property: Default connector property for link status
+	 * of a connector
+	 */
+	struct drm_property *link_status_property;
+	/**
 	 * @plane_type_property: Default plane property to differentiate
 	 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
 	 */
include/uapi/drm/drm_mode.h +4 -0
index 728790b..309c478 100644
@@ -123,6 +123,10 @@
 #define DRM_MODE_DIRTY_ON       1
 #define DRM_MODE_DIRTY_ANNOTATE 2
 
+/* Link Status options */
+#define DRM_MODE_LINK_STATUS_GOOD	0
+#define DRM_MODE_LINK_STATUS_BAD	1
+
 struct drm_mode_modeinfo {
 	__u32 clock;
 	__u16 hdisplay;
Signature · 1 line
1.9.1
Quoted 13 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw
Quoted 8 lines · Manasi Navare
Quoted 6 lines · Daniel Vetter

Hm, tiny new bikeshed: I'd drop the _property postfix here. The function name is already really long as-is, and the fact that the link status is exposed as a property is kinda irrelevant for kernel driver writers. But up to you.
-Daniel

Quoted 4 lines

I decided to name it as drm_mode_connector_set_link_status_property() looking at names of other set_property functions like drm_mode_connector_update_edid_property() or drm_mode_connector_set_path_property(). Thats why I think it makes sense to append it with property just to be consistent.

Yeah it's fine either way, maybe we could just drop _property from all of them. Really doesn't add much, but these long function names make reasonable code layout a pain. Anyway, nothing that must be done here, agreed.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx