From patchwork Thu Nov 25 07:37:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 517784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB71FC433EF for ; Thu, 25 Nov 2021 07:39:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348674AbhKYHmy (ORCPT ); Thu, 25 Nov 2021 02:42:54 -0500 Received: from mga11.intel.com ([192.55.52.93]:7215 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236705AbhKYHky (ORCPT ); Thu, 25 Nov 2021 02:40:54 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10178"; a="232957911" X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="232957911" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2021 23:37:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="457764817" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 24 Nov 2021 23:37:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 3688D2CC; Thu, 25 Nov 2021 09:37:34 +0200 (EET) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Gil Fine , Lukas Wunner , "Rafael J. Wysocki" , Andreas Noever , Mika Westerberg Subject: [PATCH 3/6] thunderbolt: Runtime resume USB4 port when retimers are scanned Date: Thu, 25 Nov 2021 10:37:30 +0300 Message-Id: <20211125073733.74902-4-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211125073733.74902-1-mika.westerberg@linux.intel.com> References: <20211125073733.74902-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Sometimes when plugging in a USB4 device we might see following error: thunderbolt 1-0:3.1: runtime PM trying to activate child device 1-0:3.1 but parent (usb4_port3) is not active This happens because the parent USB4 port was still runtime suspended. Fix this by runtime resuming the USB4 port before scanning the retimers below it. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/retimer.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c index 722694052f4a..8c29bd556ae0 100644 --- a/drivers/thunderbolt/retimer.c +++ b/drivers/thunderbolt/retimer.c @@ -324,15 +324,10 @@ struct device_type tb_retimer_type = { static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status) { - struct usb4_port *usb4; struct tb_retimer *rt; u32 vendor, device; int ret; - usb4 = port->usb4; - if (!usb4) - return -EINVAL; - ret = usb4_port_retimer_read(port, index, USB4_SB_VENDOR_ID, &vendor, sizeof(vendor)); if (ret) { @@ -374,7 +369,7 @@ static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status) rt->port = port; rt->tb = port->sw->tb; - rt->dev.parent = &usb4->dev; + rt->dev.parent = &port->usb4->dev; rt->dev.bus = &tb_bus_type; rt->dev.type = &tb_retimer_type; dev_set_name(&rt->dev, "%s:%u.%u", dev_name(&port->sw->dev), @@ -453,6 +448,13 @@ int tb_retimer_scan(struct tb_port *port, bool add) { u32 status[TB_MAX_RETIMER_INDEX + 1] = {}; int ret, i, last_idx = 0; + struct usb4_port *usb4; + + usb4 = port->usb4; + if (!usb4) + return 0; + + pm_runtime_get_sync(&usb4->dev); /* * Send broadcast RT to make sure retimer indices facing this @@ -460,7 +462,7 @@ int tb_retimer_scan(struct tb_port *port, bool add) */ ret = usb4_port_enumerate_retimers(port); if (ret) - return ret; + goto out; /* * Enable sideband channel for each retimer. We can do this @@ -490,8 +492,10 @@ int tb_retimer_scan(struct tb_port *port, bool add) break; } - if (!last_idx) - return 0; + if (!last_idx) { + ret = 0; + goto out; + } /* Add on-board retimers if they do not exist already */ for (i = 1; i <= last_idx; i++) { @@ -507,7 +511,11 @@ int tb_retimer_scan(struct tb_port *port, bool add) } } - return 0; +out: + pm_runtime_mark_last_busy(&usb4->dev); + pm_runtime_put_autosuspend(&usb4->dev); + + return ret; } static int remove_retimer(struct device *dev, void *data) From patchwork Thu Nov 25 07:37:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 517783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 220A5C433F5 for ; Thu, 25 Nov 2021 07:41:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232798AbhKYHos (ORCPT ); Thu, 25 Nov 2021 02:44:48 -0500 Received: from mga11.intel.com ([192.55.52.93]:7786 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236679AbhKYHms (ORCPT ); Thu, 25 Nov 2021 02:42:48 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10178"; a="232957921" X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="232957921" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2021 23:37:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="591927302" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 24 Nov 2021 23:37:33 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 4D2FA348; Thu, 25 Nov 2021 09:37:34 +0200 (EET) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Gil Fine , Lukas Wunner , "Rafael J. Wysocki" , Andreas Noever , Mika Westerberg Subject: [PATCH 5/6] thunderbolt: Do not program path HopIDs for USB4 routers Date: Thu, 25 Nov 2021 10:37:32 +0300 Message-Id: <20211125073733.74902-6-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211125073733.74902-1-mika.westerberg@linux.intel.com> References: <20211125073733.74902-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org These fields are marked read-only for USB4 routers so do not touch them in that case. Update the kernel-doc of tb_dp_port_set_hops() to reflect this too. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 463cfdc0b42f..e00f4b878b56 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -1322,7 +1322,9 @@ int tb_dp_port_hpd_clear(struct tb_port *port) * @aux_tx: AUX TX Hop ID * @aux_rx: AUX RX Hop ID * - * Programs specified Hop IDs for DP IN/OUT port. + * Programs specified Hop IDs for DP IN/OUT port. Can be called for USB4 + * router DP adapters too but does not program the values as the fields + * are read-only. */ int tb_dp_port_set_hops(struct tb_port *port, unsigned int video, unsigned int aux_tx, unsigned int aux_rx) @@ -1330,6 +1332,9 @@ int tb_dp_port_set_hops(struct tb_port *port, unsigned int video, u32 data[2]; int ret; + if (tb_switch_is_usb4(port->sw)) + return 0; + ret = tb_port_read(port, data, TB_CFG_PORT, port->cap_adap + ADP_DP_CS_0, ARRAY_SIZE(data)); if (ret) From patchwork Thu Nov 25 07:37:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 517782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22344C433EF for ; Thu, 25 Nov 2021 07:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239374AbhKYHs5 (ORCPT ); Thu, 25 Nov 2021 02:48:57 -0500 Received: from mga06.intel.com ([134.134.136.31]:8101 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234579AbhKYHq4 (ORCPT ); Thu, 25 Nov 2021 02:46:56 -0500 X-IronPort-AV: E=McAfee;i="6200,9189,10178"; a="296269515" X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="296269515" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Nov 2021 23:37:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,262,1631602800"; d="scan'208";a="741094662" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 24 Nov 2021 23:37:33 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 58A1453E; Thu, 25 Nov 2021 09:37:34 +0200 (EET) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Gil Fine , Lukas Wunner , "Rafael J. Wysocki" , Andreas Noever , Mika Westerberg Subject: [PATCH 6/6] thunderbolt: Add debug logging of DisplayPort resource allocation Date: Thu, 25 Nov 2021 10:37:33 +0300 Message-Id: <20211125073733.74902-7-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211125073733.74902-1-mika.westerberg@linux.intel.com> References: <20211125073733.74902-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add more debugging around DP resource allocation/de-allocation. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index e00f4b878b56..13f9230104d7 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -3056,9 +3056,20 @@ bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) */ int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) { + int ret; + if (tb_switch_is_usb4(sw)) - return usb4_switch_alloc_dp_resource(sw, in); - return tb_lc_dp_sink_alloc(sw, in); + ret = usb4_switch_alloc_dp_resource(sw, in); + else + ret = tb_lc_dp_sink_alloc(sw, in); + + if (ret) + tb_sw_warn(sw, "failed to allocate DP resource for port %d\n", + in->port); + else + tb_sw_dbg(sw, "allocated DP resource for port %d\n", in->port); + + return ret; } /** @@ -3081,6 +3092,8 @@ void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) if (ret) tb_sw_warn(sw, "failed to de-allocate DP resource for port %d\n", in->port); + else + tb_sw_dbg(sw, "released DP resource for port %d\n", in->port); } struct tb_sw_lookup {