linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>,
	Michael Jamet <michael.jamet@intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rajmohan Mani <rajmohan.mani@intel.com>,
	Lukas Wunner <lukas@wunner.de>
Subject: [PATCH 09/17] thunderbolt: Do not tunnel USB3 if link is not USB4
Date: Mon, 15 Jun 2020 17:26:37 +0300	[thread overview]
Message-ID: <20200615142645.56209-10-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20200615142645.56209-1-mika.westerberg@linux.intel.com>

USB3 tunneling is possible only over USB4 link so don't create USB3
tunnels if that's not the case.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/tb.c      |  3 +++
 drivers/thunderbolt/tb.h      |  2 ++
 drivers/thunderbolt/tb_regs.h |  1 +
 drivers/thunderbolt/usb4.c    | 24 +++++++++++++++++++++---
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 55daa7f1a87d..2da82259e77c 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -235,6 +235,9 @@ static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)
 	if (!up)
 		return 0;
 
+	if (!sw->link_usb4)
+		return 0;
+
 	/*
 	 * Look up available down port. Since we are chaining it should
 	 * be found right above this switch.
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index b53ef5be7263..de8124949eaf 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -97,6 +97,7 @@ struct tb_switch_tmu {
  * @device_name: Name of the device (or %NULL if not known)
  * @link_speed: Speed of the link in Gb/s
  * @link_width: Width of the link (1 or 2)
+ * @link_usb4: Upstream link is USB4
  * @generation: Switch Thunderbolt generation
  * @cap_plug_events: Offset to the plug events capability (%0 if not found)
  * @cap_lc: Offset to the link controller capability (%0 if not found)
@@ -136,6 +137,7 @@ struct tb_switch {
 	const char *device_name;
 	unsigned int link_speed;
 	unsigned int link_width;
+	bool link_usb4;
 	unsigned int generation;
 	int cap_plug_events;
 	int cap_lc;
diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h
index c29c5075525a..77d4b8598835 100644
--- a/drivers/thunderbolt/tb_regs.h
+++ b/drivers/thunderbolt/tb_regs.h
@@ -290,6 +290,7 @@ struct tb_regs_port_header {
 /* USB4 port registers */
 #define PORT_CS_18				0x12
 #define PORT_CS_18_BE				BIT(8)
+#define PORT_CS_18_TCM				BIT(9)
 #define PORT_CS_19				0x13
 #define PORT_CS_19_PC				BIT(3)
 
diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
index 50c7534ba31e..393771d50962 100644
--- a/drivers/thunderbolt/usb4.c
+++ b/drivers/thunderbolt/usb4.c
@@ -192,6 +192,20 @@ static int usb4_switch_op(struct tb_switch *sw, u16 opcode, u8 *status)
 	return 0;
 }
 
+static bool link_is_usb4(struct tb_port *port)
+{
+	u32 val;
+
+	if (!port->cap_usb4)
+		return false;
+
+	if (tb_port_read(port, &val, TB_CFG_PORT,
+			 port->cap_usb4 + PORT_CS_18, 1))
+		return false;
+
+	return !(val & PORT_CS_18_TCM);
+}
+
 /**
  * usb4_switch_setup() - Additional setup for USB4 device
  * @sw: USB4 router to setup
@@ -205,6 +219,7 @@ static int usb4_switch_op(struct tb_switch *sw, u16 opcode, u8 *status)
  */
 int usb4_switch_setup(struct tb_switch *sw)
 {
+	struct tb_port *downstream_port;
 	struct tb_switch *parent;
 	bool tbt3, xhci;
 	u32 val = 0;
@@ -217,6 +232,11 @@ int usb4_switch_setup(struct tb_switch *sw)
 	if (ret)
 		return ret;
 
+	parent = tb_switch_parent(sw);
+	downstream_port = tb_port_at(tb_route(sw), parent);
+	sw->link_usb4 = link_is_usb4(downstream_port);
+	tb_sw_dbg(sw, "link: %s\n", sw->link_usb4 ? "USB4" : "TBT3");
+
 	xhci = val & ROUTER_CS_6_HCI;
 	tbt3 = !(val & ROUTER_CS_6_TNS);
 
@@ -227,9 +247,7 @@ int usb4_switch_setup(struct tb_switch *sw)
 	if (ret)
 		return ret;
 
-	parent = tb_switch_parent(sw);
-
-	if (tb_switch_find_port(parent, TB_TYPE_USB3_DOWN)) {
+	if (sw->link_usb4 && tb_switch_find_port(parent, TB_TYPE_USB3_DOWN)) {
 		val |= ROUTER_CS_5_UTO;
 		xhci = false;
 	}
-- 
2.27.0.rc2


  parent reply	other threads:[~2020-06-15 14:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 14:26 [PATCH 00/17] thunderbolt: Tunneling improvements Mika Westerberg
2020-06-15 14:26 ` [PATCH 01/17] thunderbolt: Fix path indices used in USB3 tunnel discovery Mika Westerberg
2020-06-25 12:51   ` Mika Westerberg
2020-06-15 14:26 ` [PATCH 02/17] thunderbolt: Make tb_next_port_on_path() work with tree topologies Mika Westerberg
2020-06-15 14:26 ` [PATCH 03/17] thunderbolt: Make tb_path_alloc() " Mika Westerberg
2020-06-15 14:26 ` [PATCH 04/17] thunderbolt: Check that both ports are reachable when allocating path Mika Westerberg
2020-06-15 14:26 ` [PATCH 05/17] thunderbolt: Handle incomplete PCIe/USB3 paths correctly in discovery Mika Westerberg
2020-06-15 14:26 ` [PATCH 06/17] thunderbolt: Increase path length " Mika Westerberg
2020-06-15 14:26 ` [PATCH 07/17] thunderbolt: Add KUnit tests for path walking Mika Westerberg
2020-06-15 14:26 ` [PATCH 08/17] thunderbolt: Add DP IN resources for all routers Mika Westerberg
2020-06-15 14:26 ` Mika Westerberg [this message]
2020-07-17  6:16   ` [PATCH 09/17] thunderbolt: Do not tunnel USB3 if link is not USB4 Prashant Malani
2020-07-20  9:02     ` Mika Westerberg
2020-07-22  5:45       ` Prashant Malani
2020-06-15 14:26 ` [PATCH 10/17] thunderbolt: Make usb4_switch_map_usb3_down() also return enabled ports Mika Westerberg
2020-06-15 14:26 ` [PATCH 11/17] thunderbolt: Make usb4_switch_map_pcie_down() " Mika Westerberg
2020-06-15 14:26 ` [PATCH 12/17] thunderbolt: Report consumed bandwidth in both directions Mika Westerberg
2020-06-15 14:26 ` [PATCH 13/17] thunderbolt: Increase DP DPRX wait timeout Mika Westerberg
2020-06-15 14:26 ` [PATCH 14/17] thunderbolt: Implement USB3 bandwidth negotiation routines Mika Westerberg
2020-06-15 14:26 ` [PATCH 15/17] thunderbolt: Make tb_port_get_link_speed() available to other files Mika Westerberg
2020-06-15 14:26 ` [PATCH 16/17] thunderbolt: Add USB3 bandwidth management Mika Westerberg
2020-06-15 14:26 ` [PATCH 17/17] thunderbolt: Add KUnit tests for tunneling Mika Westerberg
2020-06-29 15:39 ` [PATCH 00/17] thunderbolt: Tunneling improvements 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=20200615142645.56209-10-mika.westerberg@linux.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=michael.jamet@intel.com \
    --cc=rajmohan.mani@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;
as well as URLs for NNTP newsgroup(s).