From patchwork Fri Jun 2 09:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 688998 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 D4E1FC7EE29 for ; Fri, 2 Jun 2023 09:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234767AbjFBJMq (ORCPT ); Fri, 2 Jun 2023 05:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234759AbjFBJMV (ORCPT ); Fri, 2 Jun 2023 05:12:21 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C15AE42 for ; Fri, 2 Jun 2023 02:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685697054; x=1717233054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nH1RBF2R2VS+X/Zddkgn87XcgZAEUQrPe7PidUdIfqE=; b=WxPpu8RGAMxNo1tItQgDLLOm4LZzoMAoHFG116H0l0yYuFg56m6lwDYH cfn+eJopEm5ohRSvR0lydPWMEuNcVVqoipRbEnodKimE4y2uk7uHu/r89 QV8xiGpIuMMeX6lFM1KuopPYetDPSFx1BfA839cBQ6BaNumSXUgS8TTXq HAB9YjD5R8kOZSD+ZhofXJHINbBqSyZVVSYkrOA8WGRWpP8b7+eEzth01 apiIkxyXpBXkVLXTT8gxN/aBFOwESnWTLybOdrDwFPDhU8T8yAs5PRI7X he3bzXXDdbQwGVUlAOEmXwbqpnaSrDPN2x0F5ODL90IukHYGucwa4K5ii w==; X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="345402021" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="345402021" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 02:10:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="820211855" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="820211855" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 02 Jun 2023 02:10:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 2F47A53A; Fri, 2 Jun 2023 12:10:56 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Utkarsh H Patel , Mika Westerberg Subject: [PATCH 1/3] thunderbolt: Read retimer NVM authentication status prior tb_retimer_set_inbound_sbtx() Date: Fri, 2 Jun 2023 12:10:53 +0300 Message-Id: <20230602091055.65049-2-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230602091055.65049-1-mika.westerberg@linux.intel.com> References: <20230602091055.65049-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org According to the USB4 retimer guide the correct order is immediately after sending ENUMERATE_RETIMERS so update the code to follow this. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/retimer.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c index ccc2f0e7adba..fb8e113488db 100644 --- a/drivers/thunderbolt/retimer.c +++ b/drivers/thunderbolt/retimer.c @@ -187,6 +187,21 @@ static ssize_t nvm_authenticate_show(struct device *dev, return ret; } +static void tb_retimer_nvm_authenticate_status(struct tb_port *port, u32 *status) +{ + int i; + + tb_port_dbg(port, "reading NVM authentication status of retimers\n"); + + /* + * Before doing anything else, read the authentication status. + * If the retimer has it set, store it for the new retimer + * device instance. + */ + for (i = 1; i <= TB_MAX_RETIMER_INDEX; i++) + usb4_port_retimer_nvm_authenticate_status(port, i, &status[i]); +} + static void tb_retimer_set_inbound_sbtx(struct tb_port *port) { int i; @@ -449,18 +464,16 @@ int tb_retimer_scan(struct tb_port *port, bool add) return ret; /* - * Enable sideband channel for each retimer. We can do this - * regardless whether there is device connected or not. + * Immediately after sending enumerate retimers read the + * authentication status of each retimer. */ - tb_retimer_set_inbound_sbtx(port); + tb_retimer_nvm_authenticate_status(port, status); /* - * Before doing anything else, read the authentication status. - * If the retimer has it set, store it for the new retimer - * device instance. + * Enable sideband channel for each retimer. We can do this + * regardless whether there is device connected or not. */ - for (i = 1; i <= TB_MAX_RETIMER_INDEX; i++) - usb4_port_retimer_nvm_authenticate_status(port, i, &status[i]); + tb_retimer_set_inbound_sbtx(port); for (i = 1; i <= TB_MAX_RETIMER_INDEX; i++) { /* From patchwork Fri Jun 2 09:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 688997 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 9F512C7EE2F for ; Fri, 2 Jun 2023 09:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234885AbjFBJMu (ORCPT ); Fri, 2 Jun 2023 05:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234843AbjFBJMX (ORCPT ); Fri, 2 Jun 2023 05:12:23 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC21E40 for ; Fri, 2 Jun 2023 02:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685697060; x=1717233060; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+Oc1Zb6KojX8fhfI7CsukUHq3VSTswZBs9dQ+qW3Zo4=; b=kzeS2Vz15s54b2NQaedV61Ke9RBcqXHlVYdJ9uvgVm3XgWrhZuJWuTbp mr6K194nU9Dzd7Fr5oa1FVI2bOJtHrfZh7RtR1yv4na1DbMNxprtj37kl 2pI+CfOUZa3ojyh2LQoCLwx68hauZMJ8CXFCm0soO61Bc+y0pewEXMyN/ 1VWkgzMjYvsXtp2CBrbdap8eILT/JglEOicutbQk70gq2X4WEuZp0Ht0P FaVP5EtNge9XBD93FVPDq3teuMv/mgiqcCiS9n1L+4k4alYYjW71y21Rg LW+8dzebqV5wiQ/56s+VocGNFbKVVVtZoUotRAfyq6U7AQapqaft7ew00 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="353317766" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="353317766" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 02:10:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="852083458" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="852083458" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 02 Jun 2023 02:10:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 3CB945E2; Fri, 2 Jun 2023 12:10:56 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Utkarsh H Patel , Mika Westerberg Subject: [PATCH 2/3] thunderbolt: Do not send UNSET_INBOUND_SBTX when retimer NVM authentication started Date: Fri, 2 Jun 2023 12:10:54 +0300 Message-Id: <20230602091055.65049-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230602091055.65049-1-mika.westerberg@linux.intel.com> References: <20230602091055.65049-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Once retimer NVM authentication is started, sending UNSET_INBOUND_SBTX will fail so avoid doing that. Only send it when we are writing an image with not authentication or when the authentication failed early. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/retimer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c index fb8e113488db..a273fb02a02c 100644 --- a/drivers/thunderbolt/retimer.c +++ b/drivers/thunderbolt/retimer.c @@ -244,6 +244,13 @@ static ssize_t nvm_authenticate_store(struct device *dev, rt->auth_status = 0; if (val) { + /* + * When NVM authentication starts the retimer is not + * accessible so calling tb_retimer_unset_inbound_sbtx() + * will fail and therefore we do not call it. Exception + * is when the validation fails or we only write the new + * NVM image without authentication. + */ tb_retimer_set_inbound_sbtx(rt->port); if (val == AUTHENTICATE_ONLY) { ret = tb_retimer_nvm_authenticate(rt, true); @@ -264,7 +271,8 @@ static ssize_t nvm_authenticate_store(struct device *dev, } exit_unlock: - tb_retimer_unset_inbound_sbtx(rt->port); + if (ret || val == WRITE_ONLY) + tb_retimer_unset_inbound_sbtx(rt->port); mutex_unlock(&rt->tb->lock); exit_rpm: pm_runtime_mark_last_busy(&rt->dev); From patchwork Fri Jun 2 09:10:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 688690 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 23711C7EE2C for ; Fri, 2 Jun 2023 09:12:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234882AbjFBJMu (ORCPT ); Fri, 2 Jun 2023 05:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234840AbjFBJMX (ORCPT ); Fri, 2 Jun 2023 05:12:23 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B36AE5C for ; Fri, 2 Jun 2023 02:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685697059; x=1717233059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d7BQiQPPt9qOL4dHuwJEiNs75vqof6eRnLvJK1odEy0=; b=Z6zcPGPiounJvn9slBmsNNhg/SwGBR1QRoiCzRMaqX5ZFxGw+6/tjyi0 fI+Ga8DGXrospI+dO8DPvqlt8C99lfZrs+lqmsfGHPey7xiCG/JITN5yp 4QyTP016kwlluYydcl3hE3JkDzkEn2dXvn70cp7IK2/7Bh1TxTFqd56W/ Ft1SO/PVRGrZN7Pa0BaBS/8DDjfoZ90P+oIcZidsFhuAVJXrikp8RMgeD HIRB375jA0Ra/Uyh7k4wp9DlaFA5w7rJjiIm2FP35xjdwvZiw/cX1pvLv 5QKWBsZLIS2jDnpk+VU8Bh/PiHJMStKZmthj1W7XBELKTB9ZUNep+l6Lo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="353317763" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="353317763" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 02:10:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="852083459" X-IronPort-AV: E=Sophos;i="6.00,212,1681196400"; d="scan'208";a="852083459" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 02 Jun 2023 02:10:50 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 43DFF5FD; Fri, 2 Jun 2023 12:10:56 +0300 (EEST) From: Mika Westerberg To: linux-usb@vger.kernel.org Cc: Yehezkel Bernat , Michael Jamet , Lukas Wunner , Andreas Noever , Utkarsh H Patel , Mika Westerberg Subject: [PATCH 3/3] thunderbolt: Enable/disable sideband depending on USB4 port offline mode Date: Fri, 2 Jun 2023 12:10:55 +0300 Message-Id: <20230602091055.65049-4-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230602091055.65049-1-mika.westerberg@linux.intel.com> References: <20230602091055.65049-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When USB4 port is in offline mode (this mean there is no device attached) we want to keep the sideband up to make it possible to communicate with the retimers. In the same way there is no need to enable sideband transactions when the USB4 port is not offline as they are already up. For this reason make the enabling/disabling depend on the USB4 port offline status. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/retimer.c | 19 +++++++++++++++++++ drivers/thunderbolt/tb.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c index a273fb02a02c..47becb363ada 100644 --- a/drivers/thunderbolt/retimer.c +++ b/drivers/thunderbolt/retimer.c @@ -206,6 +206,15 @@ static void tb_retimer_set_inbound_sbtx(struct tb_port *port) { int i; + /* + * When USB4 port is online sideband communications are + * already up. + */ + if (!usb4_port_device_is_offline(port->usb4)) + return; + + tb_port_dbg(port, "enabling sideband transactions\n"); + for (i = 1; i <= TB_MAX_RETIMER_INDEX; i++) usb4_port_retimer_set_inbound_sbtx(port, i); } @@ -214,6 +223,16 @@ static void tb_retimer_unset_inbound_sbtx(struct tb_port *port) { int i; + /* + * When USB4 port is offline we need to keep the sideband + * communications up to make it possible to communicate with + * the connected retimers. + */ + if (usb4_port_device_is_offline(port->usb4)) + return; + + tb_port_dbg(port, "disabling sideband transactions\n"); + for (i = TB_MAX_RETIMER_INDEX; i >= 1; i--) usb4_port_retimer_unset_inbound_sbtx(port, i); } diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index a89e0eb399b0..71ca6d500032 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -1326,6 +1326,11 @@ struct usb4_port *usb4_port_device_add(struct tb_port *port); void usb4_port_device_remove(struct usb4_port *usb4); int usb4_port_device_resume(struct usb4_port *usb4); +static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4) +{ + return usb4->offline; +} + void tb_check_quirks(struct tb_switch *sw); #ifdef CONFIG_ACPI