Skip to contentSkip to conversation

Handle link training failure during modeset

PATCH In review Manasi Navare 4 participants 24 messages Nov 15, 2016 – Nov 17, 2016

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

cover Handle link training failure during modeset

Submitting new series that adds proper commit messages/cover letter and kernel documentation. It also moved the set_link_status function to drm core so other kernel drivers can make use of it.

The idea presented in these patches is 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.

The solution is to add a "link status" connector property. 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", prune the mode list based on new information as necessary, and send a hotplug uevent for userspace to have it re-check the valid modes through getconnector, and try again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

If the userspace is not aware of the property, the user experience is the same as it currently is. If the userspace is aware of the property, it has a chance to improve user experience. If a drm driver does not modify the property (it stays "good"), the user experience is the same as it currently is. A drm driver can also choose to try to handle more of the failures in kernel, hardware not limiting, or it can choose to involve userspace more. Up to the drivers.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Finally, while DP CTS compliance is advertized (which is great, and could be made to work similarly for all drm drivers), this can be used for the more important goal of improving user experience on link training failures, by avoiding black screens.

Manasi Navare (5):
drm: Add a new connector property for link status
drm: Set DRM connector link status property
drm/i915: Update CRTC state if connector link status property changed drm/i915: Find fallback link rate/lane count
drm/i915: Implement Link Rate fallback on Link training failure

 drivers/gpu/drm/drm_atomic_helper.c           |   7 ++
 drivers/gpu/drm/drm_connector.c               |  55 ++++++++++
 drivers/gpu/drm/i915/intel_ddi.c              |  21 +++-
 drivers/gpu/drm/i915/intel_dp.c               | 144 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |  10 +-
 include/drm/drm_connector.h                   |   9 +-
 include/drm/drm_crtc.h                        |   5 +
 include/uapi/drm/drm_mode.h                   |   4 +
 9 files changed, 257 insertions(+), 10 deletions(-)
Signature · 6 lines
1.9.1

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

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

A new default connector property is added for keeping
track of whether the link is good (link training passed) or link is bad (link training failed). If the link status property is not good, then userspace should fire off a new modeset at the current mode even if there have not been any changes in the mode list or connector status.
Also add link status connector member corersponding to the decoded value of link status property.

v3:
* Drop "link training" from description since this is not specific to DP (Jani Nikula)
* Add link status member to store property value locally (Ville Syrjala)
v2:
* Make this a default connector property (Daniel Vetter)

---
 drivers/gpu/drm/drm_connector.c | 17 +++++++++++++++++
 include/drm/drm_connector.h     |  7 ++++++-
 include/drm/drm_crtc.h          |  5 +++++
 include/uapi/drm/drm_mode.h     |  4 ++++
 4 files changed, 32 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_connector.c +17 -0
index 2db7fb5..d4e852f 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
@@ -622,6 +632,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;
 }
 
include/drm/drm_connector.h +6 -1
index 3e97272..ad5c8b0 100644
@@ -695,6 +695,12 @@ struct drm_connector {
 	uint8_t num_h_tile, num_v_tile;
 	uint8_t tile_h_loc, tile_v_loc;
 	uint16_t tile_h_size, tile_v_size;
+
+	/* Connector Link status
+	 * 0: If the link is Good
+	 * 1: If the link is Bad
+	 */
+	int link_status;
 };
 
 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
@@ -767,7 +773,6 @@ int drm_mode_create_tv_properties(struct drm_device *dev,
 int drm_mode_create_scaling_mode_property(struct drm_device *dev);
 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
-
 int drm_mode_connector_set_path_property(struct drm_connector *connector,
 					 const char *path);
 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
include/drm/drm_crtc.h +5 -0
index 8cca2a8..a93148b 100644
@@ -1164,6 +1164,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 01000c9..66b145b 100644
@@ -129,6 +129,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
#2 lore raw

PATCH 2/5 drm: Set DRM connector link status property

In reply to Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
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 2/5] drm: Set DRM connector link status property

None of the other functions that set the connector property hold the mode config locks while setting the connector property, I am following the same convention.
Also we dont need to grab and release the locks in i915_modeset_work_func that first validates the modes and then sets this link status property.

Manasi

Quoted 90 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 1 line
1.9.1

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

#4 lore raw

Re: [PATCH 2/5] drm: Set DRM connector link status property

Quoted 5 lines · Manasi Navare

None of the other functions that set the connector property hold the mode config locks while setting the connector property, I am following the same convention.
Also we dont need to grab and release the locks in i915_modeset_work_func that first validates the modes and then sets this link status property.

Which other functions don't hold the mode_config.mutex? -Daniel

Quoted 98 lines

Manasi

Quoted 90 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 1 line
1.9.1

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

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
#5 lore raw

Re: [Intel-gfx] [PATCH 2/5] drm: Set DRM connector link status property

In reply to Manasi Navare
Quoted 30 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +0 -0
index d4e852f..09f4093 100644

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

Quoted 6 lines
drivers/gpu/drm/drm_connector.c +3 -0
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.

iirc this continuation upsets kernel-doc. Did you build the docs and review them? You need to indent the 2nd line.

Also, might just shorten it to "set link status for a connector", details are for the text below.

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

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ * @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".

Unecessary linebbreak. Either make a full paragraph (empty line) or reflow, this here won't survivie kernel-doc formatting.

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ * If something fails during or after a mode set, the kernel driver can set this
+ * link status to "BAD", prune the mode list based on new information and send a

First need to prune the mode list, then set the property. Please reorder in your text.

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.

s/Get_connector/GET_CONNECTOR IOCTL/ is the more usual style.

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

Quoted 6 lines
drivers/gpu/drm/drm_connector.c +6 -0
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.

Imo this paragraph isn't needed. Maybe just mention that old userspace exists:

"Note that a lot of existing userspace doesn't handle this property. Drivers can therefore not rely on userspace to fix up everything and should try to handle issues (like just re-training a link) without userspace's intervention. This should only be used when the current mode doesn't work any more, and userspace must select a different display mode."

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

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +4 -0
+ *
+ * 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 reportany failures in that.

s/reportany/report/

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ *
+ * This function must be called from asynchronous work item.

This isn't true - it doesn't require an asynchronous work item, but the locking rules mean that it.

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

Quoted 1 line
drivers/gpu/drm/drm_connector.c +1 -0
+ * Returns zero on success and negative errrno on failure.

Hm, why can this ever fail? Intuitively this should never fail, and hence we shouldn't need an error return value.

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

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);

This misses the hotplug_event call from my proposal. Intentionally? Why?

Also: With the current code you require that mode_config.mutex is held by the caller. Every time you add a library/core function which requires certain locks to be held, please check that with something like lockdep_assert_held or similar. Leaking locking rules to callers like this should be the exception, not the rule.

But with my proposal this function here would grab all necessary locks, solving that problem, too.
-Daniel

Quoted 26 lines
drivers/gpu/drm/drm_connector.c +3 -0
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
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
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [PATCH 2/5] drm: Set DRM connector link status property

Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +0 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
 
Quoted 7 lines

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

Quoted 3 lines
drivers/gpu/drm/drm_connector.c +3 -0
+/**
+ * drm_mode_connector_set_link_status_property - Set the link status property of
+ * a connector to indicate status of link as a result of link training.

iirc this continuation upsets kernel-doc. Did you build the docs and review them? You need to indent the 2nd line.

I built the docs and didnt see any issue with the docs, but I will shorten the description.

Quoted 12 lines

Also, might just shorten it to "set link status for a connector", details are for the text below.

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

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +5 -0
+ * @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".

Unecessary linebbreak. Either make a full paragraph (empty line) or reflow, this here won't survivie kernel-doc formatting.

Agree, will fix this.

Quoted 18 lines

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ * If something fails during or after a mode set, the kernel driver can set this
+ * link status to "BAD", prune the mode list based on new information and send a

First need to prune the mode list, then set the property. Please reorder in your text.

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.

s/Get_connector/GET_CONNECTOR IOCTL/ is the more usual style.

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

Quoted 6 lines
drivers/gpu/drm/drm_connector.c +6 -0
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
Quoted 3 lines

Imo this paragraph isn't needed. Maybe just mention that old userspace exists:

I think keeping this paragraph is important to give the readers good idea of how this will affect the user experience.

Quoted 7 lines

"Note that a lot of existing userspace doesn't handle this property. Drivers can therefore not rely on userspace to fix up everything and should try to handle issues (like just re-training a link) without userspace's intervention. This should only be used when the current mode doesn't work any more, and userspace must select a different display mode."

But atleast the way i915 uses this is in both cases where current mode does not get pruned but need sto be retried and also when current mode is no longer valid and gets pruned and modeset is done at a lower mode. But in either case if link training fails, this property is set to BAD.

Manasi

Quoted 10 lines

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

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +4 -0
+ *
+ * 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 reportany failures in that.

s/reportany/report/

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

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +2 -0
+ *
+ * This function must be called from asynchronous work item.
Quoted 8 lines

This isn't true - it doesn't require an asynchronous work item, but the locking rules mean that it.

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

Quoted 1 line
drivers/gpu/drm/drm_connector.c +1 -0
+ * Returns zero on success and negative errrno on failure.

Hm, why can this ever fail? Intuitively this should never fail, and hence we shouldn't need an error return value.

Ok, yes agree will change it to return void.

Quoted 19 lines

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

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);

This misses the hotplug_event call from my proposal. Intentionally? Why?

Also: With the current code you require that mode_config.mutex is held by the caller. Every time you add a library/core function which requires certain locks to be held, please check that with something like lockdep_assert_held or similar. Leaking locking rules to callers like this should be the exception, not the rule.

Quoted 4 lines

But with my proposal this function here would grab all necessary locks, solving that problem, too.
-Daniel

As per our IRC chat, I am going to leave ueventc calling to the caller of this function.

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/drm_connector.c +3 -0
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 1 line
1.9.1
Quoted 9 lines
Quoted 4 lines

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

Signature · 3 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

#7 lore raw

Re: [Intel-gfx] [PATCH 2/5] drm: Set DRM connector link status property

Quoted 8 lines · Manasi Navare
Quoted 7 lines · Daniel Vetter
Quoted 5 lines · Manasi Navare

+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.

Quoted 6 lines
Quoted 3 lines

Imo this paragraph isn't needed. Maybe just mention that old userspace exists:

I think keeping this paragraph is important to give the readers good idea of how this will affect the user experience.

Well generally the kernel is _really_ far away from the user experience. I guess that's what makes this paragraph look strange to me, and why I reworded it. Generally the next thing that matters from the kernel pov is the compositor and it's display driver, hence why I used "userspace" instead of "user experience". What userspace (the code) is supposed to do is imo really important for new uabi, what the user experience ends up being, that depends upon the entire stack (of which we control very little, e.g. on Xorg we'll only send a hotplug event over Xrandr and let some desktop thing handle the real mode change), and it's also fairly abstract.

Quoted 8 lines
Quoted 7 lines

"Note that a lot of existing userspace doesn't handle this property. Drivers can therefore not rely on userspace to fix up everything and should try to handle issues (like just re-training a link) without userspace's intervention. This should only be used when the current mode doesn't work any more, and userspace must select a different display mode."

Quoted 4 lines

But atleast the way i915 uses this is in both cases where current mode does not get pruned but need sto be retried and also when current mode is no longer valid and gets pruned and modeset is done at a lower mode. But in either case if link training fails, this property is set to BAD.

Yeah, hence "should" and not "must", and even i915 does handle some situations itself: E.g. if just retraining works out with different training settings, then we don't need to involve userspace, despite that the link went bad for a bit.
-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
#8 lore raw

Re: [Intel-gfx] [PATCH 2/5] drm: Set DRM connector link status property

In reply to Manasi Navare
Quoted 15 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Quoted 5 lines
Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>

One more thing I've forgotten: Just adding the kernel-doc isn't enough yet, we need to link this new property into the overall property documentations.

We already have a section "KMS Properties" in Documentation/gpu/drm-kms.rst, I think adding a new sub-section called "Standard Connector Properties" there with a definition list pointing to this function here would be best.
-Daniel

Quoted 74 lines
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
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
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

Re: [Intel-gfx] [PATCH 2/5] drm: Set DRM connector link status property

Quoted 26 lines · Daniel Vetter
Quoted 15 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Quoted 5 lines
Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>

One more thing I've forgotten: Just adding the kernel-doc isn't enough yet, we need to link this new property into the overall property documentations.

Quoted 6 lines

We already have a section "KMS Properties" in Documentation/gpu/drm-kms.rst, I think adding a new sub-section called "Standard Connector Properties" there with a definition list pointing to this function here would be best.
-Daniel

What about other standard proprties like EDID etc? And could you give an example for writing out a definition list there pointing to this function? This .rst file currently consists of kernel::doc:: and paths for .h files

Manasi

Quoted 70 lines
Quoted 70 lines
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 1 line
1.9.1
Quoted 9 lines
Quoted 4 lines

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

Signature · 3 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

#10 lore raw

Re: [Intel-gfx] [PATCH 2/5] drm: Set DRM connector link status property

Quoted 34 lines · Manasi Navare
Quoted 26 lines · Daniel Vetter
Quoted 15 lines · Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Quoted 5 lines
Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>

One more thing I've forgotten: Just adding the kernel-doc isn't enough yet, we need to link this new property into the overall property documentations.

Quoted 6 lines

We already have a section "KMS Properties" in Documentation/gpu/drm-kms.rst, I think adding a new sub-section called "Standard Connector Properties" there with a definition list pointing to this function here would be best.
-Daniel

Quoted 3 lines

What about other standard proprties like EDID etc? And could you give an example for writing out a definition list there pointing to this function? This .rst file currently consists of kernel::doc:: and paths for .h files

Yeah, none of the standard connector properties are currently documented. I'll write a quick patch that you can then base yours on. -Daniel

Quoted 81 lines

Manasi

Quoted 79 lines
Quoted 74 lines
---
 drivers/gpu/drm/drm_connector.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_connector.c +38 -0
index d4e852f..09f4093 100644
@@ -968,6 +968,44 @@ 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 the link status property of
+ * a connector to indicate status of link as a result of link training.
+ * @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 can set this
+ * link status to "BAD", prune the mode list based on new information and send a
+ * hotplug uevent for userspace to have it re-check the valid modes through
+ * Get_connector and try again.
+ *
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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 reportany failures in that.
+ *
+ * This function must be called from asynchronous work item.
+ * Returns zero on success and negative errrno on failure.
+ */
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status)
+{
+	struct drm_device *dev = connector->dev;
+
+	connector->link_status = link_status;
+	return drm_object_property_set_value(&connector->base,
+					     dev->mode_config.link_status_property,
+					     link_status);
+}
+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 +2 -0
index ad5c8b0..ac76469 100644
@@ -778,6 +778,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);
+int drm_mode_connector_set_link_status_property(struct drm_connector *connector,
+						uint64_t link_status);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 6 lines
1.9.1

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

PATCH v2 2/5 drm: Set DRM connector link status property

In reply to Manasi Navare

In the usual working scenarios, this property is "Good". If something fails during modeset, the DRM driver can set the link status to "Bad", prune the mode list based on the link rate/lane count fallback values and send hotplug uevent so that userspace that is aware of this property can take an appropriate action by reprobing connectors and re triggering a modeset to improve user experience and avoid black screens. In case of userspace that is not aware of this link status property, the user experience will be unchanged.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

v2:
* Update kernel doc, add lockdep_assert_held (Daniel Vetter)

Cc Jani Nikula <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Ville Syrjala <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 36 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_connector.h     |  2 ++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_connector.c +36 -0
index d4e852f..b942d67 100644
@@ -968,6 +968,42 @@ 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 should
+ * prune the mode list based on new information, 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 that a lot of existing userspace do not handle this property.
+ * If userspace is not aware of this property, the user experience is the same
+ * as it currently is. If the userspace is aware of the property, it has a chance
+ * to improve user experience by handling link training failures, avoiding black
+ * screens. The DRM driver can chose to not modify property and keep link status
+ * as "GOOD" always to keep the user experience same as it currently is.
+ *
+ * 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;
+
+	/* Make sure the mutex is grabbed */
+	lockdep_assert_held(&dev->mode_config.mutex);
+	connector->link_status = link_status;
+	drm_object_property_set_value(&connector->base,
+				      dev->mode_config.link_status_property,
+				      link_status);
+}
+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 +2 -0
index ad5c8b0..b7e2658 100644
@@ -778,6 +778,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);
 
 /**
  * drm_for_each_connector - iterate over all connectors
Signature · 6 lines
1.9.1

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

PATCH 3/5 drm/i915: Update CRTC state if connector link status property changed

In reply to Manasi Navare

CRTC state connector_changed needs to be set to true
if connector link status property has changed. This will tell the driver to do a complete modeset due to change in connector property.

---
 drivers/gpu/drm/drm_atomic_helper.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +7 -0
index 5007796..aeecf2f 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->link_status == DRM_MODE_LINK_STATUS_BAD)
+				crtc_state->connectors_changed = true;
+		}
 	}
 
 	/*
Signature · 6 lines
1.9.1

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

PATCH 4/5 drm/i915: Find fallback link rate/lane count

In reply to Manasi Navare

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.

v2:
Squash the patch that returns the link rate index (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c  | 42 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  6 ++++++
 2 files changed, 48 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +42 -0
index a1b0181..e87b451 100644
@@ -288,6 +288,48 @@ 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_index = link_rate_index - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		intel_dp->fallback_lane_count = intel_dp_max_lane_count(intel_dp);
+	} else if (lane_count > 1) {
+		intel_dp->fallback_link_rate_index = common_len - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		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 +6 -0
index 75252ec..55ceb44 100644
@@ -887,6 +887,10 @@ struct intel_dp {
 	uint32_t DP;
 	int link_rate;
 	uint8_t lane_count;
+	int fallback_link_rate;
+	uint8_t fallback_lane_count;
+	int fallback_link_rate_index;
+	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1383,6 +1387,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

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

Re: [PATCH 4/5] drm/i915: Find fallback link rate/lane count

Jani/Ville , could you please review this patch?
Jani, you had mentioned it looks good and we were only waiting for ACKs from DRM, so now from the DRM point of view all these patches are ACKed and it looks good.
But I need r-b for these two i915 specific patches to get them merged.

Regards
Manasi

Quoted 100 lines · Manasi Navare

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.

v2:
Squash the patch that returns the link rate index (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c  | 42 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  6 ++++++
 2 files changed, 48 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +42 -0
index a1b0181..e87b451 100644
@@ -288,6 +288,48 @@ 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_index = link_rate_index - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		intel_dp->fallback_lane_count = intel_dp_max_lane_count(intel_dp);
+	} else if (lane_count > 1) {
+		intel_dp->fallback_link_rate_index = common_len - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		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 +6 -0
index 75252ec..55ceb44 100644
@@ -887,6 +887,10 @@ struct intel_dp {
 	uint32_t DP;
 	int link_rate;
 	uint8_t lane_count;
+	int fallback_link_rate;
+	uint8_t fallback_lane_count;
+	int fallback_link_rate_index;
+	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1383,6 +1387,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 · 1 line
1.9.1

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

maintainer
#15 lore raw

Re: [PATCH 4/5] drm/i915: Find fallback link rate/lane count

In reply to Manasi Navare
Quoted 47 lines · Manasi Navare

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.

v2:
Squash the patch that returns the link rate index (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c  | 42 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  6 ++++++
 2 files changed, 48 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +19 -0
index a1b0181..e87b451 100644
@@ -288,6 +288,48 @@ 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] = {};

drivers/gpu/drm/i915/intel_dp.c static int intel_dp_common_rates(struct intel_dp *intel_dp, · line 319

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+	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_index = link_rate_index - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];

fallback_link_rate_index and fallback_link_rate are two ways to express the same thing, and you can derive one from the other. When you have two, you run the risk of having them out of sync. I thought I'd mentioned this in earlier review.

Please do not store fallback_link_rate_index in intel_dp. Only store fallback_link_rate. You can use your intel_dp_link_rate_index() function when you need to convert rate to index.

Moreover, resetting the state becomes more clear when all can be set to 0.

BR,
Jani.

Quoted 40 lines
drivers/gpu/drm/i915/intel_dp.c +13 -0
+		intel_dp->fallback_lane_count = intel_dp_max_lane_count(intel_dp);
+	} else if (lane_count > 1) {
+		intel_dp->fallback_link_rate_index = common_len - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		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 +6 -0
index 75252ec..55ceb44 100644
@@ -887,6 +887,10 @@ struct intel_dp {
 	uint32_t DP;
 	int link_rate;
 	uint8_t lane_count;
+	int fallback_link_rate;
+	uint8_t fallback_lane_count;
+	int fallback_link_rate_index;
+	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1383,6 +1387,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 · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#16 lore raw

Re: [PATCH 4/5] drm/i915: Find fallback link rate/lane count

Quoted 68 lines · Jani Nikula
Quoted 47 lines · Manasi Navare

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.

v2:
Squash the patch that returns the link rate index (Jani Nikula)

---
 drivers/gpu/drm/i915/intel_dp.c  | 42 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h |  6 ++++++
 2 files changed, 48 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +19 -0
index a1b0181..e87b451 100644
@@ -288,6 +288,48 @@ 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] = {};

drivers/gpu/drm/i915/intel_dp.c static int intel_dp_common_rates(struct intel_dp *intel_dp, · line 319

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+	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_index = link_rate_index - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];

fallback_link_rate_index and fallback_link_rate are two ways to express the same thing, and you can derive one from the other. When you have two, you run the risk of having them out of sync. I thought I'd mentioned this in earlier review.

Please do not store fallback_link_rate_index in intel_dp. Only store fallback_link_rate. You can use your intel_dp_link_rate_index() function when you need to convert rate to index.

Quoted 6 lines

Moreover, resetting the state becomes more clear when all can be set to 0.

BR,
Jani.

Thanks Jani.
From the previous feedback, I removed the redundant link_train_failed variable stored in intel_dp, but retained the link_rate_index. I will look at this and see if this can be optimized.

Manasi

Quoted 32 lines
Quoted 32 lines
drivers/gpu/drm/i915/intel_dp.c +13 -0
+		intel_dp->fallback_lane_count = intel_dp_max_lane_count(intel_dp);
+	} else if (lane_count > 1) {
+		intel_dp->fallback_link_rate_index = common_len - 1;
+		intel_dp->fallback_link_rate = common_rates[intel_dp->fallback_link_rate_index];
+		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 75252ec..55ceb44 100644
@@ -887,6 +887,10 @@ struct intel_dp {
 	uint32_t DP;
 	int link_rate;
 	uint8_t lane_count;
+	int fallback_link_rate;
+	uint8_t fallback_lane_count;
+	int fallback_link_rate_index;
+	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1383,6 +1387,8 @@ bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
Quoted 11 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_drv.h +2 -0
 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 · 1 line
Jani Nikula, Intel Open Source Technology Center

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

#17 lore raw

PATCH 5/5 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.

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_ddi.c              |  21 +++++-
 drivers/gpu/drm/i915/intel_dp.c               | 102 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |   6 +-
 4 files changed, 131 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_ddi.c +20 -1
index 0ad4e16..57b7ee9 100644
@@ -1684,6 +1684,8 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	enum port port = intel_ddi_get_encoder_port(encoder);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	intel_dp_set_link_params(intel_dp, link_rate, lane_count,
 				 link_mst);
@@ -1694,7 +1696,24 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	intel_prepare_dp_ddi_buffers(encoder);
 	intel_ddi_init_dp_buf_reg(encoder);
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+			      link_rate, lane_count);
+		if (!intel_dp_get_link_train_fallback_values(intel_dp,
+							     link_rate,
+							     lane_count))
+			/* Schedule a Hotplug Uevent to userspace to start modeset */
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+			      link_rate, lane_count);
+		intel_dp->fallback_link_rate_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}
+
 	if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
 		intel_dp_stop_link_train(intel_dp);
 }
drivers/gpu/drm/i915/intel_dp.c +98 -4

168 lines not on this page · raw message

drivers/gpu/drm/i915/intel_dp_link_training.c +9 -3
index 0048b52..10f81ab 100644
@@ -310,9 +310,15 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 				DP_TRAINING_PATTERN_DISABLE);
 }
 
-void
+bool
 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);
+	bool ret;
+
+	if (intel_dp_link_training_clock_recovery(intel_dp)) {
+		ret = intel_dp_link_training_channel_equalization(intel_dp);
+		if (ret)
+			return true;
+	}
+	return false;
 }
drivers/gpu/drm/i915/intel_drv.h +4 -2
index 55ceb44..88918f4 100644
@@ -312,6 +312,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 {
@@ -890,7 +893,6 @@ struct intel_dp {
 	int fallback_link_rate;
 	uint8_t fallback_lane_count;
 	int fallback_link_rate_index;
-	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1389,7 +1391,7 @@ void intel_dp_set_link_params(struct intel_dp *intel_dp,
 			      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);
+bool 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);
 void intel_dp_encoder_reset(struct drm_encoder *encoder);
Signature · 6 lines
1.9.1

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

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

Jani/Ville could you please review this patch?
This has been ACKed by DRM and is good from DRM point fo view. But I need r-b from either of you for this to get merged.

Regards
Manasi

Quoted 317 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.

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_ddi.c              |  21 +++++-
 drivers/gpu/drm/i915/intel_dp.c               | 102 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |   6 +-
 4 files changed, 131 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_ddi.c +20 -1
index 0ad4e16..57b7ee9 100644
@@ -1684,6 +1684,8 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	enum port port = intel_ddi_get_encoder_port(encoder);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	intel_dp_set_link_params(intel_dp, link_rate, lane_count,
 				 link_mst);
@@ -1694,7 +1696,24 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	intel_prepare_dp_ddi_buffers(encoder);
 	intel_ddi_init_dp_buf_reg(encoder);
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+			      link_rate, lane_count);
+		if (!intel_dp_get_link_train_fallback_values(intel_dp,
+							     link_rate,
+							     lane_count))
+			/* Schedule a Hotplug Uevent to userspace to start modeset */
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+			      link_rate, lane_count);
+		intel_dp->fallback_link_rate_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}
+
 	if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
 		intel_dp_stop_link_train(intel_dp);
 }
drivers/gpu/drm/i915/intel_dp.c +98 -4
index e87b451..af2f8b2 100644
@@ -353,8 +353,14 @@ int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
 		target_clock = fixed_mode->clock;
 	}
 
-	max_link_clock = intel_dp_max_link_rate(intel_dp);
-	max_lanes = intel_dp_max_lane_count(intel_dp);
+	/* Prune the modes using the fallback link rate/lane count */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		max_link_clock = intel_dp->fallback_link_rate;
+		max_lanes = intel_dp->fallback_lane_count;
+	} else {
+		max_link_clock = intel_dp_max_link_rate(intel_dp);
+		max_lanes = intel_dp_max_lane_count(intel_dp);
+	}
 
 	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
 	mode_rate = intel_dp_link_required(target_clock, 18);
@@ -1591,6 +1597,7 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	enum port port = dp_to_dig_port(intel_dp)->port;
 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
 	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	int lane_count, clock;
 	int min_lane_count = 1;
 	int max_lane_count = intel_dp_max_lane_count(intel_dp);
@@ -1638,6 +1645,12 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return false;
 
+	/* Fall back to lower link rate in case of failure in previous modeset */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		min_lane_count = max_lane_count = intel_dp->fallback_lane_count;
+		min_clock = max_clock = intel_dp->fallback_link_rate_index;
+	}
+
 	DRM_DEBUG_KMS("DP link computation with max lane count %i "
 		      "max bw %d pixel clock %iKHz\n",
 		      max_lane_count, common_rates[max_clock],
@@ -2781,6 +2794,8 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	struct drm_device *dev = encoder->base.dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	uint32_t dp_reg = I915_READ(intel_dp->output_reg);
 	enum pipe pipe = crtc->pipe;
 
@@ -2811,7 +2826,23 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	}
 
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}
 	intel_dp_stop_link_train(intel_dp);
 
 	if (pipe_config->has_audio) {
@@ -4018,6 +4049,8 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	/* Suppress underruns caused by re-training */
 	intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
@@ -4025,7 +4058,23 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 		intel_set_pch_fifo_underrun_reporting(dev_priv,
 						      intel_crtc_pch_transcoder(crtc), false);
 
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}
 	intel_dp_stop_link_train(intel_dp);
 
 	/* Keep underrun reporting disabled until things are stable */
@@ -4419,6 +4468,11 @@ 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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
 
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4510,6 +4564,11 @@ 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 trianing failure */
+	if (status == connector_status_connected &&
+	    connector->link_status == DRM_MODE_LINK_STATUS_BAD)
+		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);
@@ -5677,6 +5736,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;
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+	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);
+	/* 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);
+	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)
@@ -5689,6 +5779,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 +9 -3
index 0048b52..10f81ab 100644
@@ -310,9 +310,15 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 				DP_TRAINING_PATTERN_DISABLE);
 }
 
-void
+bool
 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);
+	bool ret;
+
+	if (intel_dp_link_training_clock_recovery(intel_dp)) {
+		ret = intel_dp_link_training_channel_equalization(intel_dp);
+		if (ret)
+			return true;
+	}
+	return false;
 }
drivers/gpu/drm/i915/intel_drv.h +4 -2
index 55ceb44..88918f4 100644
@@ -312,6 +312,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 {
@@ -890,7 +893,6 @@ struct intel_dp {
 	int fallback_link_rate;
 	uint8_t fallback_lane_count;
 	int fallback_link_rate_index;
-	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1389,7 +1391,7 @@ void intel_dp_set_link_params(struct intel_dp *intel_dp,
 			      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);
+bool 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);
 void intel_dp_encoder_reset(struct drm_encoder *encoder);
Signature · 1 line
1.9.1

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

maintainer
#19 lore raw

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

In reply to Manasi Navare
Quoted 63 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.

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_ddi.c              |  21 +++++-
 drivers/gpu/drm/i915/intel_dp.c               | 102 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |   6 +-
 4 files changed, 131 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_ddi.c +9 -1
index 0ad4e16..57b7ee9 100644
@@ -1684,6 +1684,8 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	enum port port = intel_ddi_get_encoder_port(encoder);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	intel_dp_set_link_params(intel_dp, link_rate, lane_count,
 				 link_mst);
@@ -1694,7 +1696,24 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	intel_prepare_dp_ddi_buffers(encoder);
 	intel_ddi_init_dp_buf_reg(encoder);
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+			      link_rate, lane_count);
+		if (!intel_dp_get_link_train_fallback_values(intel_dp,
+							     link_rate,
+							     lane_count))
+			/* Schedule a Hotplug Uevent to userspace to start modeset */

drivers/gpu/drm/i915/intel_ddi.c static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder, · line 1715

Quoted 10 lines
drivers/gpu/drm/i915/intel_ddi.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+			      link_rate, lane_count);
+		intel_dp->fallback_link_rate_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Code block with intel_dp_start_link_train() failure handling. Okay.

Quoted 67 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -0
+
 	if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
 		intel_dp_stop_link_train(intel_dp);
 }
drivers/gpu/drm/i915/intel_dp.c +24 -3
index e87b451..af2f8b2 100644
@@ -353,8 +353,14 @@ int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
 		target_clock = fixed_mode->clock;
 	}
 
-	max_link_clock = intel_dp_max_link_rate(intel_dp);
-	max_lanes = intel_dp_max_lane_count(intel_dp);
+	/* Prune the modes using the fallback link rate/lane count */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		max_link_clock = intel_dp->fallback_link_rate;
+		max_lanes = intel_dp->fallback_lane_count;
+	} else {
+		max_link_clock = intel_dp_max_link_rate(intel_dp);
+		max_lanes = intel_dp_max_lane_count(intel_dp);
+	}
 
 	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
 	mode_rate = intel_dp_link_required(target_clock, 18);
@@ -1591,6 +1597,7 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	enum port port = dp_to_dig_port(intel_dp)->port;
 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
 	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	int lane_count, clock;
 	int min_lane_count = 1;
 	int max_lane_count = intel_dp_max_lane_count(intel_dp);
@@ -1638,6 +1645,12 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return false;
 
+	/* Fall back to lower link rate in case of failure in previous modeset */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		min_lane_count = max_lane_count = intel_dp->fallback_lane_count;
+		min_clock = max_clock = intel_dp->fallback_link_rate_index;
+	}
+
 	DRM_DEBUG_KMS("DP link computation with max lane count %i "
 		      "max bw %d pixel clock %iKHz\n",
 		      max_lane_count, common_rates[max_clock],
@@ -2781,6 +2794,8 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	struct drm_device *dev = encoder->base.dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	uint32_t dp_reg = I915_READ(intel_dp->output_reg);
 	enum pipe pipe = crtc->pipe;
 
@@ -2811,7 +2826,23 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	}
 
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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 */

drivers/gpu/drm/i915/intel_dp.c static void intel_enable_dp(struct intel_encoder *encoder, · line 2845

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Second identical copy of intel_dp_start_link_train() failure handling.

Quoted 24 lines
drivers/gpu/drm/i915/intel_dp.c +9 -1
 	intel_dp_stop_link_train(intel_dp);
 
 	if (pipe_config->has_audio) {
@@ -4018,6 +4049,8 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	/* Suppress underruns caused by re-training */
 	intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
@@ -4025,7 +4058,23 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 		intel_set_pch_fifo_underrun_reporting(dev_priv,
 						      intel_crtc_pch_transcoder(crtc), false);
 
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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 */

drivers/gpu/drm/i915/intel_dp.c static void intel_dp_handle_test_request(struct intel_dp *intel_dp) · line 4077

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Third identical copy of intel_dp_start_link_train() failure handling. Please abstract.

Why don't all intel_dp_start_link_train() calls need this? Could the above code be *within* intel_dp_start_link_train()?

Quoted 88 lines
drivers/gpu/drm/i915/intel_dp.c +45 -0
 	intel_dp_stop_link_train(intel_dp);
 
 	/* Keep underrun reporting disabled until things are stable */
@@ -4419,6 +4468,11 @@ 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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
 
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4510,6 +4564,11 @@ 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 trianing failure */
+	if (status == connector_status_connected &&
+	    connector->link_status == DRM_MODE_LINK_STATUS_BAD)
+		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);
@@ -5677,6 +5736,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;
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+	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);
+	/* 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);
+	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)
@@ -5689,6 +5779,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 +1 -1
index 0048b52..10f81ab 100644
@@ -310,9 +310,15 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 				DP_TRAINING_PATTERN_DISABLE);
 }
 
-void
+bool
 intel_dp_start_link_train(struct intel_dp *intel_dp)
 {

drivers/gpu/drm/i915/intel_dp_link_training.c void intel_dp_stop_link_train(struct intel_dp *intel_dp) · line 323

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp_link_training.c +8 -2
-	intel_dp_link_training_clock_recovery(intel_dp);
-	intel_dp_link_training_channel_equalization(intel_dp);
+	bool ret;
+
+	if (intel_dp_link_training_clock_recovery(intel_dp)) {
+		ret = intel_dp_link_training_channel_equalization(intel_dp);
+		if (ret)
+			return true;
+	}
+	return false;

Usually happy day scenario goes at the top indentation level, and errors are handled in the nested cases with early returns. Compare with:

intel_dp_start_link_train(struct intel_dp *intel_dp)

{
	if (!intel_dp_link_training_clock_recovery(intel_dp))
        	return false;

	if (!intel_dp_link_training_channel_equalization(intel_dp))
		return false;

	return true;
}
Quoted 32 lines
drivers/gpu/drm/i915/intel_dp_link_training.c +0 -0
 }
drivers/gpu/drm/i915/intel_drv.h +4 -2
index 55ceb44..88918f4 100644
@@ -312,6 +312,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 {
@@ -890,7 +893,6 @@ struct intel_dp {
 	int fallback_link_rate;
 	uint8_t fallback_lane_count;
 	int fallback_link_rate_index;
-	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1389,7 +1391,7 @@ void intel_dp_set_link_params(struct intel_dp *intel_dp,
 			      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);
+bool 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);
 void intel_dp_encoder_reset(struct drm_encoder *encoder);
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#20 lore raw

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

Quoted 195 lines · Jani Nikula
Quoted 63 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.

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_ddi.c              |  21 +++++-
 drivers/gpu/drm/i915/intel_dp.c               | 102 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |   6 +-
 4 files changed, 131 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/intel_ddi.c +9 -1
index 0ad4e16..57b7ee9 100644
@@ -1684,6 +1684,8 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	enum port port = intel_ddi_get_encoder_port(encoder);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	intel_dp_set_link_params(intel_dp, link_rate, lane_count,
 				 link_mst);
@@ -1694,7 +1696,24 @@ static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
 	intel_prepare_dp_ddi_buffers(encoder);
 	intel_ddi_init_dp_buf_reg(encoder);
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d",
+			      link_rate, lane_count);
+		if (!intel_dp_get_link_train_fallback_values(intel_dp,
+							     link_rate,
+							     lane_count))
+			/* Schedule a Hotplug Uevent to userspace to start modeset */

drivers/gpu/drm/i915/intel_ddi.c static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder, · line 1715

Quoted 10 lines
drivers/gpu/drm/i915/intel_ddi.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d",
+			      link_rate, lane_count);
+		intel_dp->fallback_link_rate_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Code block with intel_dp_start_link_train() failure handling. Okay.

Quoted 67 lines
drivers/gpu/drm/i915/intel_ddi.c +1 -0
+
 	if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
 		intel_dp_stop_link_train(intel_dp);
 }
drivers/gpu/drm/i915/intel_dp.c +24 -3
index e87b451..af2f8b2 100644
@@ -353,8 +353,14 @@ int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
 		target_clock = fixed_mode->clock;
 	}
 
-	max_link_clock = intel_dp_max_link_rate(intel_dp);
-	max_lanes = intel_dp_max_lane_count(intel_dp);
+	/* Prune the modes using the fallback link rate/lane count */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		max_link_clock = intel_dp->fallback_link_rate;
+		max_lanes = intel_dp->fallback_lane_count;
+	} else {
+		max_link_clock = intel_dp_max_link_rate(intel_dp);
+		max_lanes = intel_dp_max_lane_count(intel_dp);
+	}
 
 	max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
 	mode_rate = intel_dp_link_required(target_clock, 18);
@@ -1591,6 +1597,7 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	enum port port = dp_to_dig_port(intel_dp)->port;
 	struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
 	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	int lane_count, clock;
 	int min_lane_count = 1;
 	int max_lane_count = intel_dp_max_lane_count(intel_dp);
@@ -1638,6 +1645,12 @@ static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
 		return false;
 
+	/* Fall back to lower link rate in case of failure in previous modeset */
+	if (connector->link_status == DRM_MODE_LINK_STATUS_BAD) {
+		min_lane_count = max_lane_count = intel_dp->fallback_lane_count;
+		min_clock = max_clock = intel_dp->fallback_link_rate_index;
+	}
+
 	DRM_DEBUG_KMS("DP link computation with max lane count %i "
 		      "max bw %d pixel clock %iKHz\n",
 		      max_lane_count, common_rates[max_clock],
@@ -2781,6 +2794,8 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	struct drm_device *dev = encoder->base.dev;
 	struct drm_i915_private *dev_priv = to_i915(dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 	uint32_t dp_reg = I915_READ(intel_dp->output_reg);
 	enum pipe pipe = crtc->pipe;
 
@@ -2811,7 +2826,23 @@ static void intel_enable_dp(struct intel_encoder *encoder,
 	}
 
 	intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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 */

drivers/gpu/drm/i915/intel_dp.c static void intel_enable_dp(struct intel_encoder *encoder, · line 2845

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Second identical copy of intel_dp_start_link_train() failure handling.

Quoted 24 lines
drivers/gpu/drm/i915/intel_dp.c +9 -1
 	intel_dp_stop_link_train(intel_dp);
 
 	if (pipe_config->has_audio) {
@@ -4018,6 +4049,8 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 	struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
 	struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	struct drm_connector *connector = &intel_connector->base;
 
 	/* Suppress underruns caused by re-training */
 	intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
@@ -4025,7 +4058,23 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
 		intel_set_pch_fifo_underrun_reporting(dev_priv,
 						      intel_crtc_pch_transcoder(crtc), false);
 
-	intel_dp_start_link_train(intel_dp);
+	if (!intel_dp_start_link_train(intel_dp)) {
+		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 */

drivers/gpu/drm/i915/intel_dp.c static void intel_dp_handle_test_request(struct intel_dp *intel_dp) · line 4077

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+			schedule_work(&intel_connector->modeset_retry_work);
+	} else {
+		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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
+	}

Third identical copy of intel_dp_start_link_train() failure handling. Please abstract.

Quoted 3 lines

Why don't all intel_dp_start_link_train() calls need this? Could the above code be *within* intel_dp_start_link_train()?

Actually the same codeblock got repeated since I expanded this failure handling to all DDI and non DDI platforms and to all cases where link training happens.
I think instead of adding to intel_dp_start_link_train, I can create another separate function for link_train_failure handling which can be called at all these places. Having it in a separate function would make it more intuitive that if start_linj_train failed then we are calling this failure handling code block.
Let me know what you think.

Regards
Manasi

Quoted 103 lines
Quoted 88 lines
drivers/gpu/drm/i915/intel_dp.c +45 -0
 	intel_dp_stop_link_train(intel_dp);
 
 	/* Keep underrun reporting disabled until things are stable */
@@ -4419,6 +4468,11 @@ 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_index = -1;
+		intel_dp->fallback_link_rate = 0;
+		intel_dp->fallback_lane_count = 0;
+		drm_mode_connector_set_link_status_property(connector,
+							    DRM_MODE_LINK_STATUS_GOOD);
 
 		if (intel_dp->is_mst) {
 			DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4510,6 +4564,11 @@ 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 trianing failure */
+	if (status == connector_status_connected &&
+	    connector->link_status == DRM_MODE_LINK_STATUS_BAD)
+		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);
@@ -5677,6 +5736,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;
+
+	/* Grab the locks before changing connector property*/
+	mutex_lock(&connector->dev->mode_config.mutex);
+	DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
+		      connector->name);
+	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);
+	/* 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);
+	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)
@@ -5689,6 +5779,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 +1 -1
index 0048b52..10f81ab 100644
@@ -310,9 +310,15 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp)
 				DP_TRAINING_PATTERN_DISABLE);
 }
 
-void
+bool
 intel_dp_start_link_train(struct intel_dp *intel_dp)
 {

drivers/gpu/drm/i915/intel_dp_link_training.c void intel_dp_stop_link_train(struct intel_dp *intel_dp) · line 323

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp_link_training.c +8 -2
-	intel_dp_link_training_clock_recovery(intel_dp);
-	intel_dp_link_training_channel_equalization(intel_dp);
+	bool ret;
+
+	if (intel_dp_link_training_clock_recovery(intel_dp)) {
+		ret = intel_dp_link_training_channel_equalization(intel_dp);
+		if (ret)
+			return true;
+	}
+	return false;

Usually happy day scenario goes at the top indentation level, and errors are handled in the nested cases with early returns. Compare with:

intel_dp_start_link_train(struct intel_dp *intel_dp)

Quoted 10 lines
{
	if (!intel_dp_link_training_clock_recovery(intel_dp))
        	return false;

	if (!intel_dp_link_training_channel_equalization(intel_dp))
		return false;

	return true;
}

Agreed.

Quoted 24 lines
Quoted 24 lines
drivers/gpu/drm/i915/intel_dp_link_training.c +0 -0
 }
drivers/gpu/drm/i915/intel_drv.h +3 -1
index 55ceb44..88918f4 100644
@@ -312,6 +312,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 {
@@ -890,7 +893,6 @@ struct intel_dp {
 	int fallback_link_rate;
 	uint8_t fallback_lane_count;
 	int fallback_link_rate_index;
-	bool link_train_failed;
 	uint8_t sink_count;
 	bool link_mst;
 	bool has_audio;
@@ -1389,7 +1391,7 @@ void intel_dp_set_link_params(struct intel_dp *intel_dp,
Quoted 11 lines
Quoted 8 lines
drivers/gpu/drm/i915/intel_drv.h +1 -1
 			      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);
+bool 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);
 void intel_dp_encoder_reset(struct drm_encoder *encoder);
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center

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

#21 lore raw

✓ Fi.CI.BAT: success for Handle Link Training Failure during modeset (rev2)

In reply to Manasi Navare
== Series Details ==

== Series Details ==

Series: Handle Link Training Failure during modeset (rev2)
URL : https://patchwork.freedesktop.org/series/15080/
State : success

== Summary ==

Series 15080v2 Handle Link Training Failure during modeset
https://patchwork.freedesktop.org/api/1.0/series/15080/revisions/2/mbox/

fi-bdw-5557u     total:244  pass:229  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:244  pass:204  dwarn:0   dfail:0   fail:0   skip:40 
fi-bxt-t5700     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-j1900     total:244  pass:216  dwarn:0   dfail:0   fail:0   skip:28 
fi-byt-n2820     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-hsw-4770      total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-hsw-4770r     total:244  pass:224  dwarn:0   dfail:0   fail:0   skip:20 
fi-ilk-650       total:244  pass:191  dwarn:0   dfail:0   fail:0   skip:53 
fi-ivb-3520m     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-ivb-3770      total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-kbl-7200u     total:244  pass:222  dwarn:0   dfail:0   fail:0   skip:22 
fi-skl-6260u     total:244  pass:230  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:244  pass:223  dwarn:0   dfail:0   fail:0   skip:21 
fi-snb-2520m     total:244  pass:212  dwarn:0   dfail:0   fail:0   skip:32 
fi-snb-2600      total:244  pass:211  dwarn:0   dfail:0   fail:0   skip:33 

2f21978cfd8984c79e4cbd77ce63d9f73fe226ef drm-intel-nightly: 2016y-11m-14d-21h-23m-10s UTC integration manifest 91a9d22 drm/i915: Implement Link Rate fallback on Link training failure
0b79f50 drm/i915: Find fallback link rate/lane count
f5c4dd7 drm/i915: Update CRTC state if connector link status property changed
79fe862 drm: Set DRM connector link status property
2f286cb drm: Add a new connector property for link status

== Logs ==

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

maintainer
#22 lore raw
In reply to Manasi Navare
Quoted 34 lines · Manasi Navare

Submitting new series that adds proper commit messages/cover letter and kernel documentation. It also moved the set_link_status function to drm core so other kernel drivers can make use of it.

The idea presented in these patches is 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.

The solution is to add a "link status" connector property. 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", prune the mode list based on new information as necessary, and send a hotplug uevent for userspace to have it re-check the valid modes through getconnector, and try again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

If the userspace is not aware of the property, the user experience is the same as it currently is. If the userspace is aware of the property, it has a chance to improve user experience. If a drm driver does not modify the property (it stays "good"), the user experience is the same as it currently is. A drm driver can also choose to try to handle more of the failures in kernel, hardware not limiting, or it can choose to involve userspace more. Up to the drivers.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Quoted 4 lines

Finally, while DP CTS compliance is advertized (which is great, and could be made to work similarly for all drm drivers), this can be used for the more important goal of improving user experience on link training failures, by avoiding black screens.

Since I went through the trouble of writing this, you might as well add it to patch 1/5 commit message so it benefits the posterity.

Quoted 2 lines

These must go to patch 1/5 commit message.

BR,
Jani.

Quoted 18 lines

Manasi Navare (5):
drm: Add a new connector property for link status
drm: Set DRM connector link status property
drm/i915: Update CRTC state if connector link status property changed drm/i915: Find fallback link rate/lane count
drm/i915: Implement Link Rate fallback on Link training failure

 drivers/gpu/drm/drm_atomic_helper.c           |   7 ++
 drivers/gpu/drm/drm_connector.c               |  55 ++++++++++
 drivers/gpu/drm/i915/intel_ddi.c              |  21 +++-
 drivers/gpu/drm/i915/intel_dp.c               | 144 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |  10 +-
 include/drm/drm_connector.h                   |   9 +-
 include/drm/drm_crtc.h                        |   5 +
 include/uapi/drm/drm_mode.h                   |   4 +
 9 files changed, 257 insertions(+), 10 deletions(-)
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#23 lore raw
Quoted 35 lines · Jani Nikula
Quoted 34 lines · Manasi Navare

Submitting new series that adds proper commit messages/cover letter and kernel documentation. It also moved the set_link_status function to drm core so other kernel drivers can make use of it.

The idea presented in these patches is 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.

The solution is to add a "link status" connector property. 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", prune the mode list based on new information as necessary, and send a hotplug uevent for userspace to have it re-check the valid modes through getconnector, and try again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.

If the userspace is not aware of the property, the user experience is the same as it currently is. If the userspace is aware of the property, it has a chance to improve user experience. If a drm driver does not modify the property (it stays "good"), the user experience is the same as it currently is. A drm driver can also choose to try to handle more of the failures in kernel, hardware not limiting, or it can choose to involve userspace more. Up to the drivers.

The reason for adding the property is to handle link training failures, but it is not limited to DP or link training. For example, if we implement asynchronous setcrtc, we can use this to report any failures in that.

Quoted 8 lines
Quoted 4 lines

Finally, while DP CTS compliance is advertized (which is great, and could be made to work similarly for all drm drivers), this can be used for the more important goal of improving user experience on link training failures, by avoiding black screens.

Since I went through the trouble of writing this, you might as well add it to patch 1/5 commit message so it benefits the posterity.

Yes, I have also added most of this to the kernel documentation
for the link status property. But I will also add this to Patch 1/5 commit message. Should we explain the alternative approaches as well over there?

Manasi

Quoted 18 lines
Quoted 2 lines

These must go to patch 1/5 commit message.

BR,
Jani.

Quoted 8 lines

Manasi Navare (5):
drm: Add a new connector property for link status
drm: Set DRM connector link status property
drm/i915: Update CRTC state if connector link status property changed drm/i915: Find fallback link rate/lane count
drm/i915: Implement Link Rate fallback on Link training failure

Quoted 13 lines
Quoted 10 lines
 drivers/gpu/drm/drm_atomic_helper.c           |   7 ++
 drivers/gpu/drm/drm_connector.c               |  55 ++++++++++
 drivers/gpu/drm/i915/intel_ddi.c              |  21 +++-
 drivers/gpu/drm/i915/intel_dp.c               | 144 +++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_dp_link_training.c |  12 ++-
 drivers/gpu/drm/i915/intel_drv.h              |  10 +-
 include/drm/drm_connector.h                   |   9 +-
 include/drm/drm_crtc.h                        |   5 +
 include/uapi/drm/drm_mode.h                   |   4 +
 9 files changed, 257 insertions(+), 10 deletions(-)
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center

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