Received: by 10.223.185.111 with SMTP id b44csp779079wrg; Fri, 9 Mar 2018 13:36:04 -0800 (PST) X-Google-Smtp-Source: AG47ELv6NCUxvDKfcR4hRgOLD5CdeyRJrjA87abfi5fkKB3VoY9WlMvQmg7QIuJZ9B9SneqHC30U X-Received: by 10.99.159.10 with SMTP id g10mr25134910pge.407.1520631364559; Fri, 09 Mar 2018 13:36:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520631364; cv=none; d=google.com; s=arc-20160816; b=M9gxZyoJHCX3HglA/KjYu2UgOXbax0obTHi4+6GwbDNJVphAwZzNxpCwdC4wttNpbU X/P2kFwkWlb18LYjZwH/omTAoaRnQyR3BdPVbQeqdafGHCgsMZCGJUjcI48b3MIKNvRW 0PlOivJBKRwfbWbC80L1z/c4QFdGH3W4b2Hrv2YkIkthNRu/+GSPy9S6b7Vc4D3MRQn2 bIZWsGwreKddcXGQsqm3BJo558RmDv9TqzGxE3V1lVSoygbbyqGMrrxWiDrhQxa/zcF7 ZS+LrlFnKPfdWAaAD6PIQgm1ULwIMM9eR1gO1gz3Y/F/cos4OTHZaFe532AuMmKXlgjo SVDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1hK3Rhj+SgQNzoBCO43wXRALndB84fuEKFL8zou7OAk=; b=njRJL6Jy83JxgG0ZdBphmxuGm3Z36otG/Ou3/YD9sEjWnLx0jySLffnCkDapzdBTt8 +p8MKQOI9gAsNiZZnXeK699KJv8+RuVNTUuUSA7qxw37u2L5TW2v9OZULm1IXPrn2nIF K+0EWy5sjOHYuPNeL3yfmkg4Pd3gY0xSjL4tReFEfJOQoRDa+uYcg5zDb8KYx0p2HYaA K3y+WhNSO5h+TRTn8S17b5S4WKeOPxgomVEvBQpMweQ193V8MTlKpqk6R6rCw7XNi0h2 m6GwGqkedYlsVx7UTrzBEcKLvGhrgN0j90YG28UhkeUU7fF30o6xpzEx75jsXmfT3WRQ e4Pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w8-v6si1525379plq.641.2018.03.09.13.35.50; Fri, 09 Mar 2018 13:36:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932835AbeCIVe1 (ORCPT + 99 others); Fri, 9 Mar 2018 16:34:27 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36912 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932195AbeCIVdH (ORCPT ); Fri, 9 Mar 2018 16:33:07 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EBFF8163C5F; Fri, 9 Mar 2018 21:33:06 +0000 (UTC) Received: from malachite.bss.redhat.com (dhcp-10-20-1-30.bss.redhat.com [10.20.1.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E5739457F; Fri, 9 Mar 2018 21:33:06 +0000 (UTC) From: Lyude Paul To: intel-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, Manasi Navare , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] drm/dp_mst: Add drm_dp_mst_topology_mgr_lower_link_rate() Date: Fri, 9 Mar 2018 16:32:29 -0500 Message-Id: <20180309213232.19855-3-lyude@redhat.com> In-Reply-To: <20180309213232.19855-1-lyude@redhat.com> References: <20180308232421.14049-1-lyude@redhat.com> <20180309213232.19855-1-lyude@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 21:33:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 21:33:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lyude@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unlike SST, MST can have far more then a single display hooked up on a single port. What this also means however, is that if the DisplayPort link to the top-level MST branch device becomes unstable then every single branch device also has an unstable link. Additionally, MST has a few more steps that must be taken in order to properly retrain the entire topology under a lower link rate. Since the VCID allocations for each mstb is determined based off the link rate for the top of the topology, we also have to recalculate all of the VCID allocations for the downstream ports as well to ensure that we still have enough link bandwidth to drive each mstb. Additionally, since we have multiple downstream connectors per port, setting the link status of the parent mstb's port to bad isn't enough: all of the downstream mstb ports have to have their link status set to bad. This basically follows the same paradigm that our DP link status logic in DRM does, in that we simply tell userspace that all of the mstb ports need retraining and additionally applying the new lower bandwidth constraints to all of the atomic commits on the topology that follow. Since the work of figuring out which connectors live downstream on an MST topology and updating their link status is something that any driver supporting MST is going to need to do in order to retrain MST links properly, we add the drm_dp_mst_topology_mgr_lower_link_rate() helper which simply recalculates the pbn_div for a given mst topology, then marks the link status of all connectors living in that topology as bad. We'll make use of it in i915 later in this series. Signed-off-by: Lyude Paul Cc: Manasi Navare Cc: Ville Syrjälä --- drivers/gpu/drm/drm_dp_mst_topology.c | 73 ++++++++++++++++++++++++++++++++++- include/drm/drm_dp_mst_helper.h | 3 ++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c index 6fac4129e6a2..0d6604500b29 100644 --- a/drivers/gpu/drm/drm_dp_mst_topology.c +++ b/drivers/gpu/drm/drm_dp_mst_topology.c @@ -2076,7 +2076,7 @@ static bool drm_dp_get_vc_payload_bw(int dp_link_bw, { switch (dp_link_bw) { default: - DRM_DEBUG_KMS("invalid link bandwidth in DPCD: %x (link count: %d)\n", + DRM_DEBUG_KMS("invalid link bandwidth: %x (link count: %d)\n", dp_link_bw, dp_link_count); return false; @@ -2096,6 +2096,77 @@ static bool drm_dp_get_vc_payload_bw(int dp_link_bw, return true; } +static void drm_dp_set_mstb_link_status(struct drm_dp_mst_branch *mstb, + enum drm_link_status status) +{ + struct drm_dp_mst_branch *rmstb; + struct drm_dp_mst_port *port; + + list_for_each_entry(port, &mstb->ports, next) { + rmstb = drm_dp_get_validated_mstb_ref(mstb->mgr, port->mstb); + if (rmstb) { + drm_dp_set_mstb_link_status(rmstb, status); + drm_dp_put_mst_branch_device(rmstb); + } + + if (port->connector) + port->connector->state->link_status = status; + } +} + +/** + * drm_dp_mst_topology_mgr_lower_link_rate() - Override the DP link bw/count + * for all connectors in a given MST topology + * @mgr: manager to set state for + * @dp_link_bw: The new DP link bandwidth + * @dp_link_count: The new DP link count + * + * This is called by the driver when it detects that the current DP link for + * the given topology manager is unstable, and needs to be retrained at a + * lower link rate. + * + * This takes care of updating the link status on all downstream connectors + * along with recalculating the VC payloads. The driver should send a hotplug + * event after calling this function to notify userspace of the link status + * change. + * + * RETURNS: + * + * True for success, or negative error code on failure. + */ +int drm_dp_mst_topology_mgr_lower_link_rate(struct drm_dp_mst_topology_mgr *mgr, + int dp_link_bw, int dp_link_count) +{ + struct drm_device *dev = mgr->dev; + struct drm_dp_mst_branch *mst_primary; + int new_pbn_div; + int ret = 0; + + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); + + if (!drm_dp_get_vc_payload_bw(drm_dp_link_rate_to_bw_code(dp_link_bw), + dp_link_count, &new_pbn_div)) { + ret = -EINVAL; + goto out; + } + + mst_primary = drm_dp_get_validated_mstb_ref(mgr, mgr->mst_primary); + if (!mst_primary) + goto out; + + DRM_DEBUG_KMS("MST link failed to retrain, lowering pbn_div to %d\n", + new_pbn_div); + mgr->pbn_div = new_pbn_div; + + drm_dp_set_mstb_link_status(mst_primary, DRM_MODE_LINK_STATUS_BAD); + + drm_dp_put_mst_branch_device(mst_primary); +out: + drm_modeset_unlock(&dev->mode_config.connection_mutex); + return ret; +} +EXPORT_SYMBOL(drm_dp_mst_topology_mgr_lower_link_rate); + /** * drm_dp_mst_topology_mgr_set_mst() - Set the MST state for a topology manager * @mgr: manager to set state for diff --git a/include/drm/drm_dp_mst_helper.h b/include/drm/drm_dp_mst_helper.h index 7f78d26a0766..6261ec43a2c0 100644 --- a/include/drm/drm_dp_mst_helper.h +++ b/include/drm/drm_dp_mst_helper.h @@ -634,4 +634,7 @@ int drm_dp_atomic_release_vcpi_slots(struct drm_atomic_state *state, int drm_dp_send_power_updown_phy(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, bool power_up); +int drm_dp_mst_topology_mgr_lower_link_rate(struct drm_dp_mst_topology_mgr *mgr, + int dp_link_bw, int dp_link_count); + #endif -- 2.14.3