All of lore.kernel.org
 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 12/17] thunderbolt: Report consumed bandwidth in both directions
Date: Mon, 15 Jun 2020 17:26:40 +0300	[thread overview]
Message-ID: <20200615142645.56209-13-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20200615142645.56209-1-mika.westerberg@linux.intel.com>

Whereas DisplayPort bandwidth is consumed only in one direction (from DP
IN adapter to DP OUT adapter), USB3 adds separate bandwidth for both
upstream and downstream directions.

For this reason extend the tunnel consumed bandwidth routines to support
both directions and implement this for DP.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/thunderbolt/tb.c     |  9 ++++---
 drivers/thunderbolt/tunnel.c | 47 +++++++++++++++++++++++++++++-------
 drivers/thunderbolt/tunnel.h |  6 +++--
 3 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 9dbdb11685fa..53f9673c1395 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -535,7 +535,7 @@ static int tb_available_bw(struct tb_cm *tcm, struct tb_port *in,
 {
 	struct tb_switch *sw = out->sw;
 	struct tb_tunnel *tunnel;
-	int bw, available_bw = 40000;
+	int ret, bw, available_bw = 40000;
 
 	while (sw && sw != in->sw) {
 		bw = sw->link_speed * sw->link_width * 1000; /* Mb/s */
@@ -553,9 +553,10 @@ static int tb_available_bw(struct tb_cm *tcm, struct tb_port *in,
 			if (!tb_tunnel_switch_on_path(tunnel, sw))
 				continue;
 
-			consumed_bw = tb_tunnel_consumed_bandwidth(tunnel);
-			if (consumed_bw < 0)
-				return consumed_bw;
+			ret = tb_tunnel_consumed_bandwidth(tunnel, NULL,
+							   &consumed_bw);
+			if (ret)
+				return ret;
 
 			bw -= consumed_bw;
 		}
diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index 5bdb8b11345e..45f7a50a48ff 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -536,7 +536,8 @@ static int tb_dp_activate(struct tb_tunnel *tunnel, bool active)
 	return 0;
 }
 
-static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel)
+static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
+				    int *consumed_down)
 {
 	struct tb_port *in = tunnel->src_port;
 	const struct tb_switch *sw = in->sw;
@@ -580,10 +581,20 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel)
 		lanes = tb_dp_cap_get_lanes(val);
 	} else {
 		/* No bandwidth management for legacy devices  */
+		*consumed_up = 0;
+		*consumed_down = 0;
 		return 0;
 	}
 
-	return tb_dp_bandwidth(rate, lanes);
+	if (in->sw->config.depth < tunnel->dst_port->sw->config.depth) {
+		*consumed_up = 0;
+		*consumed_down = tb_dp_bandwidth(rate, lanes);
+	} else {
+		*consumed_up = tb_dp_bandwidth(rate, lanes);
+		*consumed_down = 0;
+	}
+
+	return 0;
 }
 
 static void tb_dp_init_aux_path(struct tb_path *path)
@@ -1174,21 +1185,39 @@ static bool tb_tunnel_is_active(const struct tb_tunnel *tunnel)
 /**
  * tb_tunnel_consumed_bandwidth() - Return bandwidth consumed by the tunnel
  * @tunnel: Tunnel to check
+ * @consumed_up: Consumed bandwidth in Mb/s from @dst_port to @src_port.
+ *		 Can be %NULL.
+ * @consumed_down: Consumed bandwidth in Mb/s from @src_port to @dst_port.
+ *		   Can be %NULL.
  *
- * Returns bandwidth currently consumed by @tunnel and %0 if the @tunnel
- * is not active or does consume bandwidth.
+ * Stores the amount of isochronous bandwidth @tunnel consumes in
+ * @consumed_up and @consumed_down. In case of success returns %0,
+ * negative errno otherwise.
  */
-int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel)
+int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
+				 int *consumed_down)
 {
+	int up_bw = 0, down_bw = 0;
+
 	if (!tb_tunnel_is_active(tunnel))
-		return 0;
+		goto out;
 
 	if (tunnel->consumed_bandwidth) {
-		int ret = tunnel->consumed_bandwidth(tunnel);
+		int ret;
 
-		tb_tunnel_dbg(tunnel, "consumed bandwidth %d Mb/s\n", ret);
-		return ret;
+		ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw);
+		if (ret)
+			return ret;
+
+		tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw,
+			      down_bw);
 	}
 
+out:
+	if (consumed_up)
+		*consumed_up = up_bw;
+	if (consumed_down)
+		*consumed_down = down_bw;
+
 	return 0;
 }
diff --git a/drivers/thunderbolt/tunnel.h b/drivers/thunderbolt/tunnel.h
index 3f5ba93225e7..cc952b2be792 100644
--- a/drivers/thunderbolt/tunnel.h
+++ b/drivers/thunderbolt/tunnel.h
@@ -42,7 +42,8 @@ struct tb_tunnel {
 	size_t npaths;
 	int (*init)(struct tb_tunnel *tunnel);
 	int (*activate)(struct tb_tunnel *tunnel, bool activate);
-	int (*consumed_bandwidth)(struct tb_tunnel *tunnel);
+	int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
+				  int *consumed_down);
 	struct list_head list;
 	enum tb_tunnel_type type;
 	unsigned int max_bw;
@@ -69,7 +70,8 @@ void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
 bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
 			      const struct tb_switch *sw);
-int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel);
+int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
+				 int *consumed_down);
 
 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
 {
-- 
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 ` [PATCH 09/17] thunderbolt: Do not tunnel USB3 if link is not USB4 Mika Westerberg
2020-07-17  6:16   ` 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 ` Mika Westerberg [this message]
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-13-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.