Linux USB
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
	Lukas Wunner <lukas@wunner.de>,
	Andreas Noever <andreas.noever@gmail.com>,
	Gil Fine <gil.fine@linux.intel.com>,
	Rene Sapiens <rene.sapiens@linux.intel.com>,
	Pooja Katiyar <pooja.katiyar@intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 10/18] thunderbolt: Split host router port reset into a separate function
Date: Thu, 19 Nov 2026 18:12:24 +0100	[thread overview]
Message-ID: <20261119171232.1616316-11-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20261119171232.1616316-1-mika.westerberg@linux.intel.com>

From: "Mika Westerberg (Intel)" <westeri@kernel.org>

Move the part of tb_switch_reset_host() that resets the host router
lane adapters and cleans up the protocol adapter path config spaces into
a separate function tb_switch_reset_host_ports(). This makes it easier
to extend tb_switch_reset_host() in subsequent patches. No functional
changes.

Signed-off-by: Mika Westerberg (Intel) <westeri@kernel.org>
---
 drivers/thunderbolt/switch.c | 88 ++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index 26a4363f94f8..85a2aa67cbec 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -1649,53 +1649,63 @@ static int tb_plug_events_active(struct tb_switch *sw, bool active)
 			   sw->cap_plug_events + 1, 1);
 }
 
-static int tb_switch_reset_host(struct tb_switch *sw)
+static int tb_switch_reset_host_ports(struct tb_switch *sw)
 {
-	if (sw->generation > 1) {
-		struct tb_port *port;
+	struct tb_port *port;
 
-		tb_switch_for_each_port(sw, port) {
-			int i, ret;
+	tb_switch_for_each_port(sw, port) {
+		int i, ret;
 
+		/*
+		 * For lane adapters we issue downstream port reset and
+		 * clear up path config spaces.
+		 *
+		 * For protocol adapters we disable the path and clear
+		 * path config space one by one (from 8 to Max Input
+		 * HopID of the adapter).
+		 */
+		if (tb_port_is_null(port) && !tb_is_upstream_port(port)) {
+			ret = tb_port_reset(port);
+			if (ret)
+				return ret;
 			/*
-			 * For lane adapters we issue downstream port
-			 * reset and clear up path config spaces.
-			 *
-			 * For protocol adapters we disable the path and
-			 * clear path config space one by one (from 8 to
-			 * Max Input HopID of the adapter).
+			 * USB4 Lane 1 adapters do not have accessible
+			 * path config space.
 			 */
-			if (tb_port_is_null(port) && !tb_is_upstream_port(port)) {
-				ret = tb_port_reset(port);
-				if (ret)
-					return ret;
-				/*
-				 * USB4 Lane 1 adapters do not have accessible
-				 * path config space.
-				 */
-				if (tb_switch_is_usb4(sw) && !port->usb4)
-					continue;
-			} else if (tb_port_is_usb3_down(port) ||
-				   tb_port_is_usb3_up(port)) {
-				tb_usb3_port_enable(port, false);
-			} else if (tb_port_is_dpin(port) ||
-				   tb_port_is_dpout(port)) {
-				tb_dp_port_enable(port, false);
-			} else if (tb_port_is_pcie_down(port) ||
-				   tb_port_is_pcie_up(port)) {
-				tb_pci_port_enable(port, false);
-			} else {
+			if (tb_switch_is_usb4(sw) && !port->usb4)
 				continue;
-			}
+		} else if (tb_port_is_usb3_down(port) ||
+			   tb_port_is_usb3_up(port)) {
+			tb_usb3_port_enable(port, false);
+		} else if (tb_port_is_dpin(port) || tb_port_is_dpout(port)) {
+			tb_dp_port_enable(port, false);
+		} else if (tb_port_is_pcie_down(port) ||
+			   tb_port_is_pcie_up(port)) {
+			tb_pci_port_enable(port, false);
+		} else {
+			continue;
+		}
 
-			/* Cleanup path config space of protocol adapter */
-			for (i = TB_PATH_MIN_HOPID;
-			     i <= port->config.max_in_hop_id; i++) {
-				ret = tb_path_deactivate_hop(port, i);
-				if (ret)
-					return ret;
-			}
+		/* Cleanup path config space of protocol adapter */
+		for (i = TB_PATH_MIN_HOPID;
+		     i <= port->config.max_in_hop_id; i++) {
+			ret = tb_path_deactivate_hop(port, i);
+			if (ret)
+				return ret;
 		}
+	}
+
+	return 0;
+}
+
+static int tb_switch_reset_host(struct tb_switch *sw)
+{
+	if (sw->generation > 1) {
+		int ret;
+
+		ret = tb_switch_reset_host_ports(sw);
+		if (ret)
+			return ret;
 	} else {
 		struct tb_cfg_result res;
 
-- 
2.50.1


  parent reply	other threads:[~2026-11-19 17:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 17:12 [PATCH 00/18] thunderbolt: Add support for shared buffering Mika Westerberg
2026-11-19 17:12 ` [PATCH 01/18] thunderbolt: Avoid leaking of DMA tunnel after XDomain removal Mika Westerberg
2026-11-19 17:12 ` [PATCH 02/18] thunderbolt: Tear down DMA tunnels on every " Mika Westerberg
2026-11-19 17:12 ` [PATCH 03/18] thunderbolt: Delay re-pairing DP IN/OUT if DPRX negotiation fails Mika Westerberg
2026-11-19 17:12 ` [PATCH 04/18] thunderbolt: Call DP tunnel activation callback with tb->lock held Mika Westerberg
2026-11-19 17:12 ` [PATCH 05/18] thunderbolt: Re-apply Alpine/Titan Ridge flow on resume Mika Westerberg
2026-11-19 17:12 ` [PATCH 06/18] thunderbolt: Return -ESHUTDOWN when control channel is not running Mika Westerberg
2026-11-19 17:12 ` [PATCH 07/18] thunderbolt: Add usb4_port_hotplug_disable() Mika Westerberg
2026-11-19 17:12 ` [PATCH 08/18] thunderbolt: Move tb_plug_events_active() before tb_switch_reset_host() Mika Westerberg
2026-11-19 17:12 ` [PATCH 09/18] thunderbolt: Add tb_port_state_is_up() Mika Westerberg
2026-11-19 17:12 ` Mika Westerberg [this message]
2026-11-19 17:12 ` [PATCH 11/18] thunderbolt: Reset topology after suspend-to-disk Mika Westerberg
2026-11-19 17:12 ` [PATCH 12/18] thunderbolt: Drop tunnel discovery without HopID allocation Mika Westerberg
2026-11-19 17:12 ` [PATCH 13/18] thunderbolt: Always take domain lock when tb_tunnel_put() is called Mika Westerberg
2026-11-19 17:12 ` [PATCH 14/18] thunderbolt: Assign domain to the routers in KUnit tests Mika Westerberg
2026-11-19 17:12 ` [PATCH 15/18] thunderbolt: Rework tunnel credit allocation Mika Westerberg
2026-11-19 17:12 ` [PATCH 16/18] thunderbolt: Add support for shared flow control Mika Westerberg
2026-11-19 17:12 ` [PATCH 17/18] thunderbolt: Use restricted shared flow control for DMA tunnels on intra-domain links Mika Westerberg
2026-11-19 17:12 ` [PATCH 18/18] thunderbolt: Add KUnit tests for shared buffering Mika Westerberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119171232.1616316-11-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=gil.fine@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=pooja.katiyar@intel.com \
    --cc=rene.sapiens@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox