31
31
#define TB_USB3_PATH_UP 1
32
32
33
33
#define TB_USB3_PRIORITY 3
34
- #define TB_USB3_WEIGHT 3
34
+ #define TB_USB3_WEIGHT 2
35
35
36
36
/* DP adapters use HopID 8 for AUX and 9 for Video */
37
37
#define TB_DP_AUX_TX_HOPID 8
61
61
#define TB_DMA_PRIORITY 5
62
62
#define TB_DMA_WEIGHT 1
63
63
64
+ /*
65
+ * Reserve additional bandwidth for USB 3.x and PCIe bulk traffic
66
+ * according to USB4 v2 Connection Manager guide. This ends up reserving
67
+ * 1500 Mb/s for PCIe and 3000 Mb/s for USB 3.x taking weights into
68
+ * account.
69
+ */
70
+ #define USB4_V2_PCI_MIN_BANDWIDTH (1500 * TB_PCI_WEIGHT)
71
+ #define USB4_V2_USB3_MIN_BANDWIDTH (1500 * TB_USB3_WEIGHT)
72
+
64
73
static unsigned int dma_credits = TB_DMA_CREDITS ;
65
74
module_param (dma_credits , uint , 0444 );
66
75
MODULE_PARM_DESC (dma_credits , "specify custom credits for DMA tunnels (default: "
@@ -150,11 +159,11 @@ static struct tb_tunnel *tb_tunnel_alloc(struct tb *tb, size_t npaths,
150
159
151
160
static int tb_pci_set_ext_encapsulation (struct tb_tunnel * tunnel , bool enable )
152
161
{
162
+ struct tb_port * port = tb_upstream_port (tunnel -> dst_port -> sw );
153
163
int ret ;
154
164
155
165
/* Only supported of both routers are at least USB4 v2 */
156
- if (usb4_switch_version (tunnel -> src_port -> sw ) < 2 ||
157
- usb4_switch_version (tunnel -> dst_port -> sw ) < 2 )
166
+ if (tb_port_get_link_generation (port ) < 4 )
158
167
return 0 ;
159
168
160
169
ret = usb4_pci_port_set_ext_encapsulation (tunnel -> src_port , enable );
@@ -370,6 +379,51 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
370
379
return NULL ;
371
380
}
372
381
382
+ /**
383
+ * tb_tunnel_reserved_pci() - Amount of bandwidth to reserve for PCIe
384
+ * @port: Lane 0 adapter
385
+ * @reserved_up: Upstream bandwidth in Mb/s to reserve
386
+ * @reserved_down: Downstream bandwidth in Mb/s to reserve
387
+ *
388
+ * Can be called to any connected lane 0 adapter to find out how much
389
+ * bandwidth needs to be left in reserve for possible PCIe bulk traffic.
390
+ * Returns true if there is something to be reserved and writes the
391
+ * amount to @reserved_down/@reserved_up. Otherwise returns false and
392
+ * does not touch the parameters.
393
+ */
394
+ bool tb_tunnel_reserved_pci (struct tb_port * port , int * reserved_up ,
395
+ int * reserved_down )
396
+ {
397
+ if (WARN_ON_ONCE (!port -> remote ))
398
+ return false;
399
+
400
+ if (!tb_acpi_may_tunnel_pcie ())
401
+ return false;
402
+
403
+ if (tb_port_get_link_generation (port ) < 4 )
404
+ return false;
405
+
406
+ /* Must have PCIe adapters */
407
+ if (tb_is_upstream_port (port )) {
408
+ if (!tb_switch_find_port (port -> sw , TB_TYPE_PCIE_UP ))
409
+ return false;
410
+ if (!tb_switch_find_port (port -> remote -> sw , TB_TYPE_PCIE_DOWN ))
411
+ return false;
412
+ } else {
413
+ if (!tb_switch_find_port (port -> sw , TB_TYPE_PCIE_DOWN ))
414
+ return false;
415
+ if (!tb_switch_find_port (port -> remote -> sw , TB_TYPE_PCIE_UP ))
416
+ return false;
417
+ }
418
+
419
+ * reserved_up = USB4_V2_PCI_MIN_BANDWIDTH ;
420
+ * reserved_down = USB4_V2_PCI_MIN_BANDWIDTH ;
421
+
422
+ tb_port_dbg (port , "reserving %u/%u Mb/s for PCIe\n" , * reserved_up ,
423
+ * reserved_down );
424
+ return true;
425
+ }
426
+
373
427
static bool tb_dp_is_usb4 (const struct tb_switch * sw )
374
428
{
375
429
/* Titan Ridge DP adapters need the same treatment as USB4 */
@@ -1747,6 +1801,7 @@ static int tb_usb3_activate(struct tb_tunnel *tunnel, bool activate)
1747
1801
static int tb_usb3_consumed_bandwidth (struct tb_tunnel * tunnel ,
1748
1802
int * consumed_up , int * consumed_down )
1749
1803
{
1804
+ struct tb_port * port = tb_upstream_port (tunnel -> dst_port -> sw );
1750
1805
int pcie_weight = tb_acpi_may_tunnel_pcie () ? TB_PCI_WEIGHT : 0 ;
1751
1806
1752
1807
/*
@@ -1758,6 +1813,11 @@ static int tb_usb3_consumed_bandwidth(struct tb_tunnel *tunnel,
1758
1813
* consumed_down = tunnel -> allocated_down *
1759
1814
(TB_USB3_WEIGHT + pcie_weight ) / TB_USB3_WEIGHT ;
1760
1815
1816
+ if (tb_port_get_link_generation (port ) >= 4 ) {
1817
+ * consumed_up = max (* consumed_up , USB4_V2_USB3_MIN_BANDWIDTH );
1818
+ * consumed_down = max (* consumed_down , USB4_V2_USB3_MIN_BANDWIDTH );
1819
+ }
1820
+
1761
1821
return 0 ;
1762
1822
}
1763
1823
0 commit comments