Commit 6e19d48e authored by Gil Fine's avatar Gil Fine Committed by Mika Westerberg

thunderbolt: Enable USB4 v2 PCIe TLP/DLLP extended encapsulation

USB4 v2 spec introduces modified encapsulation of PCIe TLP and DLLP
packets. This improves the PCIe tunneled traffic usage by reducing
overhead. Enable this if both sides of the link support it.
Signed-off-by: default avatarGil Fine <gil.fine@intel.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent 14200a26
...@@ -1301,6 +1301,8 @@ int usb4_dp_port_allocated_bw(struct tb_port *port); ...@@ -1301,6 +1301,8 @@ int usb4_dp_port_allocated_bw(struct tb_port *port);
int usb4_dp_port_allocate_bw(struct tb_port *port, int bw); int usb4_dp_port_allocate_bw(struct tb_port *port, int bw);
int usb4_dp_port_requested_bw(struct tb_port *port); int usb4_dp_port_requested_bw(struct tb_port *port);
int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable);
static inline bool tb_is_usb4_port_device(const struct device *dev) static inline bool tb_is_usb4_port_device(const struct device *dev)
{ {
return dev->type == &usb4_port_device_type; return dev->type == &usb4_port_device_type;
......
...@@ -451,6 +451,8 @@ struct tb_regs_port_header { ...@@ -451,6 +451,8 @@ struct tb_regs_port_header {
/* PCIe adapter registers */ /* PCIe adapter registers */
#define ADP_PCIE_CS_0 0x00 #define ADP_PCIE_CS_0 0x00
#define ADP_PCIE_CS_0_PE BIT(31) #define ADP_PCIE_CS_0_PE BIT(31)
#define ADP_PCIE_CS_1 0x01
#define ADP_PCIE_CS_1_EE BIT(0)
/* USB adapter registers */ /* USB adapter registers */
#define ADP_USB3_CS_0 0x00 #define ADP_USB3_CS_0 0x00
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/ktime.h> #include <linux/ktime.h>
#include <linux/string_helpers.h>
#include "tunnel.h" #include "tunnel.h"
#include "tb.h" #include "tb.h"
...@@ -153,18 +154,49 @@ static struct tb_tunnel *tb_tunnel_alloc(struct tb *tb, size_t npaths, ...@@ -153,18 +154,49 @@ static struct tb_tunnel *tb_tunnel_alloc(struct tb *tb, size_t npaths,
return tunnel; return tunnel;
} }
static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable)
{
int ret;
/* Only supported of both routers are at least USB4 v2 */
if (usb4_switch_version(tunnel->src_port->sw) < 2 ||
usb4_switch_version(tunnel->dst_port->sw) < 2)
return 0;
ret = usb4_pci_port_set_ext_encapsulation(tunnel->src_port, enable);
if (ret)
return ret;
ret = usb4_pci_port_set_ext_encapsulation(tunnel->dst_port, enable);
if (ret)
return ret;
tb_tunnel_dbg(tunnel, "extended encapsulation %s\n",
str_enabled_disabled(enable));
return 0;
}
static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate) static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate)
{ {
int res; int res;
if (activate) {
res = tb_pci_set_ext_encapsulation(tunnel, activate);
if (res)
return res;
}
res = tb_pci_port_enable(tunnel->src_port, activate); res = tb_pci_port_enable(tunnel->src_port, activate);
if (res) if (res)
return res; return res;
if (tb_port_is_pcie_up(tunnel->dst_port)) if (tb_port_is_pcie_up(tunnel->dst_port)) {
return tb_pci_port_enable(tunnel->dst_port, activate); res = tb_pci_port_enable(tunnel->dst_port, activate);
if (res)
return res;
}
return 0; return activate ? 0 : tb_pci_set_ext_encapsulation(tunnel, activate);
} }
static int tb_pci_init_credits(struct tb_path_hop *hop) static int tb_pci_init_credits(struct tb_path_hop *hop)
......
...@@ -2796,3 +2796,34 @@ int usb4_dp_port_requested_bw(struct tb_port *port) ...@@ -2796,3 +2796,34 @@ int usb4_dp_port_requested_bw(struct tb_port *port)
return (val & ADP_DP_CS_8_REQUESTED_BW_MASK) * granularity; return (val & ADP_DP_CS_8_REQUESTED_BW_MASK) * granularity;
} }
/**
* usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
* @port: PCIe adapter
* @enable: Enable/disable extended encapsulation
*
* Enables or disables extended encapsulation used in PCIe tunneling. Caller
* needs to make sure both adapters support this before enabling. Returns %0 on
* success and negative errno otherwise.
*/
int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable)
{
u32 val;
int ret;
if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port))
return -EINVAL;
ret = tb_port_read(port, &val, TB_CFG_PORT,
port->cap_adap + ADP_PCIE_CS_1, 1);
if (ret)
return ret;
if (enable)
val |= ADP_PCIE_CS_1_EE;
else
val &= ~ADP_PCIE_CS_1_EE;
return tb_port_write(port, &val, TB_CFG_PORT,
port->cap_adap + ADP_PCIE_CS_1, 1);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment