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 | 65 +++++++++++++++- drivers/gpu/drm/i915/intel_dp.c | 103 +++++++++++++++++++++++++- drivers/gpu/drm/i915/intel_dp_link_training.c | 28 ++++++- drivers/gpu/drm/i915/intel_drv.h | 7 ++ include/drm/drm_connector.h | 9 ++- include/drm/drm_mode_config.h | 5 ++ include/uapi/drm/drm_mode.h | 4 + 8 files changed, 221 insertions(+), 7 deletions(-)
At the time userspace does setcrtc, we've already promised the mode would work. The promise is based on the theoretical capabilities of the link, but it's possible we can't reach this in practice. The DP spec describes how the link should be reduced, but we can't reduce the link below the requirements of the mode. Black screen follows.
One idea would be to have setcrtc return a failure. However, it already should not fail as the atomic checks have passed. It would also conflict with the idea of making setcrtc asynchronous in the future, returning before the actual mode setting and link training.
Another idea is to train the link "upfront" at hotplug time, before pruning the mode list, so that we can do the pruning based on practical not theoretical capabilities. However, the changes for link training are pretty drastic, all for the sake of error handling and DP compliance, when the most common happy day scenario is the current approach of link training at mode setting time, using the optimal parameters for the mode. It is also not certain all hardware could do this without the pipe on; not even all our hardware can do this. Some of this can be solved, but not trivially.
Both of the above ideas also fail to address link degradation *during* operation.
The solution is to add a new "link-status" connector property in order to address link training failure in a way that: a) changes the current happy day scenario as little as possible, to avoid regressions, b) can be implemented the same way by all drm drivers, c) is still opt-in for the drivers and userspace, and opting out doesn't regress the user experience, d) doesn't prevent drivers from implementing better or alternate approaches, possibly without userspace involvement. And, of course, handles all the issues presented. In the usual happy day scenario, this is always "good". If something fails during or after a mode set, the kernel driver can set the link status to "bad" , 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 GET_CONNECTOR IOCTL, and try again. If the theoretical capabilities of the link can't be reached, the mode list is trimmed based on that.
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.
v5: * Added kernel doc for connector standard properties (Daniel Vetter) v4: * Rebase on drm-nightly * Add a detailed commit message (Jani Nikula) 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)
Reviewed-by: Harry Wentland harry.wentland@amd.com Cc: dri-devel@lists.freedesktop.org Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Chris Wilson chris@chris-wilson.co.uk Signed-off-by: Manasi Navare manasi.d.navare@intel.com --- drivers/gpu/drm/drm_connector.c | 28 ++++++++++++++++++++++++++-- include/drm/drm_connector.h | 7 ++++++- include/drm/drm_mode_config.h | 5 +++++ include/uapi/drm/drm_mode.h | 4 ++++ 4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 5a45262..cfb5cf7 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -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 @@ -616,7 +626,7 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info, * path property the MST manager created. Userspace cannot change this * property. * TILE: - * Connector tile group property to indicate how a set of DRM connector + * Connector tile group property to indicate how a set of DRM connector * compose together into one logical screen. This is used by both high-res * external screens (often only using a single cable, but exposing multiple * DP MST sinks), or high-res integrated panels (like dual-link DSI) which @@ -625,7 +635,14 @@ int drm_display_info_set_bus_formats(struct drm_display_info *info, * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers * should update this value using drm_mode_connector_set_tile_property(). * Userspace cannot change this property. - * + * link-status: + * Connector link-status property to indicate the status of link during + * the modeset. The default value of link-status is "GOOD". If something + * fails during modeset, the kernel driver can set this to "BAD", prune + * the mode list based on new link parameters and send a hotplug uevent + * to notify userspace to re-check the valid modes through GET_CONNECTOR + * IOCTL and redo a modeset. Drivers should update this value using + * drm_mode_connector_set_link_status_property(). * Connectors also have one standardized atomic property: * * CRTC_ID: @@ -666,6 +683,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; }
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 34f9741..ab564e6 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -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); diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index bf9991b..86faee4 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -431,6 +431,11 @@ struct drm_mode_config { */ struct drm_property *tile_property; /** + * @link_status_property: Default connector property for link status + * of a connector + */ + struct drm_property *link_status_property; + /** * @plane_type_property: Default plane property to differentiate * CURSOR, PRIMARY and OVERLAY legacy uses of planes. */ diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index 728790b..309c478 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -123,6 +123,10 @@ #define DRM_MODE_DIRTY_ON 1 #define DRM_MODE_DIRTY_ANNOTATE 2
+/* Link Status options */ +#define DRM_MODE_LINK_STATUS_GOOD 0 +#define DRM_MODE_LINK_STATUS_BAD 1 + struct drm_mode_modeinfo { __u32 clock; __u16 hdisplay;
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.
v3: * Updated kernel doc even more (Daniel Vetter) v2: * Update kernel doc, add lockdep_assert_held (Daniel Vetter) Cc: dri-devel@lists.freedesktop.org Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Signed-off-by: Manasi Navare manasi.d.navare@intel.com --- drivers/gpu/drm/drm_connector.c | 37 +++++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 2 ++ 2 files changed, 39 insertions(+)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index cfb5cf7..b5ca70f 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -1019,6 +1019,43 @@ 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 + * set this link status property to "BAD" and prune the mode list based on new + * information. 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. + * 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 + * fails and userspace must select a different display mode. + * 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) diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index ab564e6..f47b345 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -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);
/** * struct drm_tile_group - Tile group metadata
On Fri, Nov 18, 2016 at 06:58:59PM -0800, Manasi Navare wrote:
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.
v3:
- Updated kernel doc even more (Daniel Vetter)
v2:
- Update kernel doc, add lockdep_assert_held (Daniel Vetter)
Cc: dri-devel@lists.freedesktop.org Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Signed-off-by: Manasi Navare manasi.d.navare@intel.com
drivers/gpu/drm/drm_connector.c | 37 +++++++++++++++++++++++++++++++++++++ include/drm/drm_connector.h | 2 ++ 2 files changed, 39 insertions(+)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index cfb5cf7..b5ca70f 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -1019,6 +1019,43 @@ 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
- set this link status property to "BAD" and prune the mode list based on new
- information. 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.
- 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
- fails and userspace must select a different display mode.
- 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);
The comment is just duplicating the code; (i++; /* post-increment i */). Comments are about why the code exists.
Common practice is to leave a blank line between function preconditions and the body of actual code.
For example it might be worth explaining why link_status is duplicated on the connector and in its property (i.e. that is near impossible to retrieve the value from the property).
- 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);
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.
Acked-by: Harry Wentland harry.wentland@amd.com Acked-by: Tony Cheng tony.cheng@amd.com Cc: dri-devel@lists.freedesktop.org Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Signed-off-by: Manasi Navare manasi.d.navare@intel.com --- drivers/gpu/drm/drm_atomic_helper.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 0b16587..2125fd1 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -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; + } }
/*
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.
v5: * Start the fallback at the lane count value passed not the max lane count (Jani Nikula) v4: * Remove the redundant variable link_train_failed v3: * Remove fallback_link_rate_index variable, just obtain that using the helper intel_dp_link_rate_index (Jani Nikula) v2: Squash the patch that returns the link rate index (Jani Nikula)
Acked-by: Tony Cheng tony.cheng@amd.com Acked-by: Harry Wentland harry.wentland@amd.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Signed-off-by: Manasi Navare manasi.d.navare@intel.com --- drivers/gpu/drm/i915/intel_dp.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_drv.h | 4 ++++ 2 files changed, 44 insertions(+)
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c index 90283ed..3a72014 100644 --- a/drivers/gpu/drm/i915/intel_dp.c +++ b/drivers/gpu/drm/i915/intel_dp.c @@ -288,6 +288,46 @@ static int intel_dp_common_rates(struct intel_dp *intel_dp, common_rates); }
+static int intel_dp_link_rate_index(struct intel_dp *intel_dp, + int *common_rates, int link_rate) +{ + int common_len; + int index; + + common_len = intel_dp_common_rates(intel_dp, common_rates); + for (index = 0; index < common_len; index++) { + if (link_rate == common_rates[common_len - index - 1]) + return common_len - index - 1; + } + + return -1; +} + +int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp, + int link_rate, uint8_t lane_count) +{ + int common_rates[DP_MAX_SUPPORTED_RATES] = {}; + int common_len; + int link_rate_index = -1; + + common_len = intel_dp_common_rates(intel_dp, common_rates); + link_rate_index = intel_dp_link_rate_index(intel_dp, + common_rates, + link_rate); + if (link_rate_index > 0) { + intel_dp->fallback_link_rate = common_rates[link_rate_index - 1]; + intel_dp->fallback_lane_count = lane_count; + } else if (lane_count > 1) { + intel_dp->fallback_link_rate = common_rates[common_len - 1]; + 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) diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index cd132c2..e1c43a9 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -887,6 +887,8 @@ struct intel_dp { uint32_t DP; int link_rate; uint8_t lane_count; + int fallback_link_rate; + uint8_t fallback_lane_count; uint8_t sink_count; bool link_mst; bool has_audio; @@ -1383,6 +1385,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);
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.
v8: * Set link_status to BAD first and then call mode_valid (Jani Nikula) v7: Remove the redundant variable in previous patch itself v6: * Obtain link rate index from fallback_link_rate using the helper intel_dp_link_rate_index (Jani Nikula) * Include fallback within intel_dp_start_link_train (Jani Nikula) v5: * Move set link status to drm core (Daniel Vetter, Jani Nikula) v4: * Add fallback support for non DDI platforms too * Set connector->link status inside set_link_status function (Jani Nikula) v3: * Set link status property to BAd unconditionally (Jani Nikula) * Dont use two separate variables link_train_failed and link_status to indicate same thing (Jani Nikula) v2: * Squashed a few patches (Jani Nikula)
Acked-by: Tony Cheng tony.cheng@amd.com Acked-by: Harry Wentland Harry.wentland@amd.com Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Daniel Vetter daniel.vetter@intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Signed-off-by: Manasi Navare manasi.d.navare@intel.com --- drivers/gpu/drm/i915/intel_dp.c | 63 ++++++++++++++++++++++++++- drivers/gpu/drm/i915/intel_dp_link_training.c | 28 +++++++++++- drivers/gpu/drm/i915/intel_drv.h | 3 ++ 3 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c index 3a72014..747a2ba 100644 --- a/drivers/gpu/drm/i915/intel_dp.c +++ b/drivers/gpu/drm/i915/intel_dp.c @@ -351,8 +351,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); @@ -1588,6 +1594,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); @@ -1635,6 +1642,14 @@ 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_link_rate_index(intel_dp, + common_rates, + intel_dp->fallback_link_rate); + } + 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], @@ -4415,6 +4430,10 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv, intel_dp->compliance_test_active = 0; intel_dp->compliance_test_type = 0; intel_dp->compliance_test_data = 0; + intel_dp->fallback_link_rate = 0; + intel_dp->fallback_lane_count = 0; + 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", @@ -4506,6 +4525,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); @@ -5671,6 +5695,37 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp, return false; }
+static void intel_dp_modeset_retry_work_fn(struct work_struct *work) +{ + struct intel_connector *intel_connector; + struct drm_connector *connector; + struct drm_display_mode *mode; + bool verbose_prune = true; + + intel_connector = container_of(work, typeof(*intel_connector), + modeset_retry_work); + connector = &intel_connector->base; + DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, + connector->name); + + /* Grab the locks before changing connector property*/ + mutex_lock(&connector->dev->mode_config.mutex); + /* Set connector link status to BAD and send a Uevent to notify + * userspace to do a modeset. + */ + drm_mode_connector_set_link_status_property(connector, + DRM_MODE_LINK_STATUS_BAD); + list_for_each_entry(mode, &connector->modes, head) { + mode->status = intel_dp_mode_valid(connector, + mode); + } + drm_mode_prune_invalid(connector->dev, &connector->modes, + verbose_prune); + mutex_unlock(&connector->dev->mode_config.mutex); + /* Send Hotplug uevent so userspace can reprobe */ + drm_kms_helper_hotplug_event(connector->dev); +} + bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port, struct intel_connector *intel_connector) @@ -5683,6 +5738,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))) diff --git a/drivers/gpu/drm/i915/intel_dp_link_training.c b/drivers/gpu/drm/i915/intel_dp_link_training.c index 0048b52..cc243db 100644 --- a/drivers/gpu/drm/i915/intel_dp_link_training.c +++ b/drivers/gpu/drm/i915/intel_dp_link_training.c @@ -313,6 +313,30 @@ void intel_dp_stop_link_train(struct intel_dp *intel_dp) void intel_dp_start_link_train(struct intel_dp *intel_dp) { - intel_dp_link_training_clock_recovery(intel_dp); - intel_dp_link_training_channel_equalization(intel_dp); + struct intel_connector *intel_connector = intel_dp->attached_connector; + struct drm_connector *connector = &intel_connector->base; + + if (!intel_dp_link_training_clock_recovery(intel_dp)) + goto failure_handling; + if (!intel_dp_link_training_channel_equalization(intel_dp)) + goto failure_handling; + + /* Reset the Link Train Values */ + DRM_DEBUG_KMS("Link Training Passed at Link Rate = %d, Lane count = %d", + intel_dp->link_rate, intel_dp->lane_count); + intel_dp->fallback_link_rate = 0; + intel_dp->fallback_lane_count = 0; + drm_mode_connector_set_link_status_property(connector, + DRM_MODE_LINK_STATUS_GOOD); + return; + + failure_handling: + DRM_DEBUG_KMS("Link Training failed at link rate = %d, lane count = %d", + intel_dp->link_rate, intel_dp->lane_count); + if (!intel_dp_get_link_train_fallback_values(intel_dp, + intel_dp->link_rate, + intel_dp->lane_count)) + /* Schedule a Hotplug Uevent to userspace to start modeset */ + schedule_work(&intel_connector->modeset_retry_work); + return; } diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index e1c43a9..33be66f 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -315,6 +315,9 @@ struct intel_connector { void *port; /* store this opaque as its illegal to dereference it */
struct intel_dp *mst_port; + + /* Work struct to schedule a uevent on link train failure */ + struct work_struct modeset_retry_work; };
struct dpll {
dri-devel@lists.freedesktop.org