Skip to contentSkip to conversation

thunderbolt: Check for ring 0 in tb_tunnel_alloc_dma()

PATCH In review Mika Westerberg 1 participant 8 messages May 17, 2023 – May 24, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/7 thunderbolt: Check for ring 0 in tb_tunnel_alloc_dma()

Ring 0 cannot be used for anything else than control channel messages. For this reason add a check to tb_tunnel_alloc_dma() and fail if someone tries to do that.

---
 drivers/thunderbolt/tunnel.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/thunderbolt/tunnel.c +4 -0
index 9099ae73e78f..dd3b5613ad2c 100644
@@ -1452,6 +1452,10 @@ struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
 	struct tb_path *path;
 	int credits;
 
+	/* Ring 0 is reserved for control channel */
+	if (WARN_ON(!receive_ring || !transmit_ring))
+		return NULL;
+
 	if (receive_ring > 0)
 		npaths++;
 	if (transmit_ring > 0)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 2/7 thunderbolt: Log function name of the called quirk

This is useful when debugging whether a quirk has been matched or not.

---
 drivers/thunderbolt/quirks.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/quirks.c +1 -0
index 1157b8869bcc..928689b66126 100644
@@ -105,6 +105,7 @@ void tb_check_quirks(struct tb_switch *sw)
 		if (q->device && q->device != sw->device)
 			continue;
 
+		tb_sw_dbg(sw, "running %ps\n", q->hook);
 		q->hook(sw);
 	}
 }
Signature · 1 line
2.39.2
#4 lore raw

PATCH 5/7 thunderbolt: Add MODULE_DESCRIPTION

In reply to Mika Westerberg

Add description about the driver to the module. No functional changes.

---
 drivers/thunderbolt/nhi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/nhi.c +1 -0
index d76e923fbc6a..e5a8f9861f9b 100644
@@ -1464,6 +1464,7 @@ static struct pci_device_id nhi_ids[] = {
 };
 
 MODULE_DEVICE_TABLE(pci, nhi_ids);
+MODULE_DESCRIPTION("Thunderbolt/USB4 core driver");
 MODULE_LICENSE("GPL");
 
 static struct pci_driver nhi_driver = {
Signature · 1 line
2.39.2
#2 lore raw

PATCH 3/7 thunderbolt: Add debug log for link controller power quirk

In reply to Mika Westerberg

Add a debug log to this quirk as well so we can see what quirks have been applied when debugging.

---
 drivers/thunderbolt/quirks.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thunderbolt/quirks.c +1 -0
index 928689b66126..854d84148850 100644
@@ -10,6 +10,7 @@
 static void quirk_force_power_link(struct tb_switch *sw)
 {
 	sw->quirks |= QUIRK_FORCE_POWER_LINK_CONTROLLER;
+	tb_sw_dbg(sw, "forcing power to link controller\n");
 }
 
 static void quirk_dp_credit_allocation(struct tb_switch *sw)
Signature · 1 line
2.39.2
#3 lore raw

PATCH 4/7 thunderbolt: Allow specifying custom credits for DMA tunnels

In reply to Mika Westerberg

The default ones should be find but this allows the user to tweak the credits to get more performance out of the P2P connection.

---
 drivers/thunderbolt/tunnel.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/thunderbolt/tunnel.c +9 -4
index dd3b5613ad2c..3bf2628a5dcd 100644
@@ -41,9 +41,14 @@
  * Number of credits we try to allocate for each DMA path if not limited
  * by the host router baMaxHI.
  */
-#define TB_DMA_CREDITS			14U
+#define TB_DMA_CREDITS			14
 /* Minimum number of credits for DMA path */
-#define TB_MIN_DMA_CREDITS		1U
+#define TB_MIN_DMA_CREDITS		1
+
+static unsigned int dma_credits = TB_DMA_CREDITS;
+module_param(dma_credits, uint, 0444);
+MODULE_PARM_DESC(dma_credits, "specify custom credits for DMA tunnels (default: "
+                __MODULE_STRING(TB_DMA_CREDITS) ")");
 
 static bool bw_alloc_mode = true;
 module_param(bw_alloc_mode, bool, 0444);
@@ -95,7 +100,7 @@ static unsigned int tb_available_credits(const struct tb_port *port,
 	pcie = tb_acpi_may_tunnel_pcie() ? sw->max_pcie_credits : 0;
 
 	if (tb_acpi_is_xdomain_allowed()) {
-		spare = min_not_zero(sw->max_dma_credits, TB_DMA_CREDITS);
+		spare = min_not_zero(sw->max_dma_credits, dma_credits);
 		/* Add some credits for potential second DMA tunnel */
 		spare += TB_MIN_DMA_CREDITS;
 	} else {
@@ -1472,7 +1477,7 @@ struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
 	tunnel->dst_port = dst;
 	tunnel->deinit = tb_dma_deinit;
 
-	credits = min_not_zero(TB_DMA_CREDITS, nhi->sw->max_dma_credits);
+	credits = min_not_zero(dma_credits, nhi->sw->max_dma_credits);
 
 	if (receive_ring > 0) {
 		path = tb_path_alloc(tb, dst, receive_path, nhi, receive_ring, 0,
Signature · 1 line
2.39.2
#5 lore raw

PATCH 6/7 thunderbolt: dma_test: Update MODULE_DESCRIPTION

In reply to Mika Westerberg

Make the description match the core driver and the networking with Thunderbolt/USB4 prefix. No functional changes.

---
 drivers/thunderbolt/dma_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/dma_test.c +1 -1
index 14bb6dec6c4b..58496f889d03 100644
@@ -756,5 +756,5 @@ module_exit(dma_test_exit);
 
 MODULE_AUTHOR("Isaac Hazan <[email protected]>");
 MODULE_AUTHOR("Mika Westerberg <[email protected]>");
-MODULE_DESCRIPTION("DMA traffic test driver");
+MODULE_DESCRIPTION("Thunderbolt/USB4 DMA traffic test driver");
 MODULE_LICENSE("GPL v2");
Signature · 1 line
2.39.2
#6 lore raw

PATCH 7/7 thunderbolt: Drop retimer vendor check

In reply to Mika Westerberg

This is not needed anymore as we already handle unknown vendor in NVM functions.

---
 drivers/thunderbolt/retimer.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/thunderbolt/retimer.c +0 -6
index 9cc28197dbc4..ccc2f0e7adba 100644
@@ -341,12 +341,6 @@ static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status)
 		return ret;
 	}
 
-	if (vendor != PCI_VENDOR_ID_INTEL && vendor != 0x8087) {
-		tb_port_info(port, "retimer NVM format of vendor %#x is not supported\n",
-			     vendor);
-		return -EOPNOTSUPP;
-	}
-
 	/*
 	 * Check that it supports NVM operations. If not then don't add
 	 * the device at all.
Signature · 1 line
2.39.2