thunderbolt: Add support for USB4
Subsystems (4)
cover thunderbolt: Add support for USB4
Hi,
USB4 is the public specification of Thunderbolt 3 protocol and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_1.zip
USB4 is about tunneling different protocols over a single cable (in the same way as Thunderbolt). The current USB4 spec supports PCIe, Display Port and USB 3.x, and also software based protocols such as networking between domains (hosts).
So far PCs have been using firmware based Connection Manager (FW CM, ICM) and Apple systems have been using software based one (SW CM, ECM). A Connection Manager is the entity that handles creation of different tunnel types through the USB4 (and Thunderbolt) fabric. With USB4 the plan is to have software based Connection Manager everywhere but some early systems will also support firmware to allow OS downgrade for example.
Current Linux Thunderbolt driver supports both "modes" and can detect which one to use dynamically.
This series first adds support for Thunderbolt 3 devices to the software connection manager and then extends that to support USB4 compliant hosts and devices (this applies to both firmware and software based connection managers). With this series the following features are supported also for USB4 compliant devices:
- PCIe tunneling
- Display Port tunneling
- USB 3.x tunneling
- P2P networking (implemented in drivers/net/thunderbolt.c)
- Host and device NVM firmware upgrade
The previous RFC version of the series can be seen here:
https://lore.kernel.org/lkml/[email protected]/
Changes from the RFC version:
* Spelled out what are ICM, and SW CM (and ECM)
* Log warning in tb_switch_add() instead of the caller
* Use Lukas' suggestion in port walk helper macro and also drop tb_switch_for_each_remote_port() and tb_switch_for_each_connected_port()
* Rework icm.c::add_switch() so that we don't need to pass huge amount of parameters to it
* Add rx/tx versions of link width/speed attributes following convention used in USB bus (with the exception that we provide rx_speed and tx_speed as well).
* Spell out DROM and try to clarify what linking in patch [11/25] means.
* Add a new patch that expands controller name in existing tb_switch_is_xy() functions and do the same for tb_switch_is_ar()/tr().
* Move register name conversion pathes up in the series so that we can apply them for v5.5 already.
* Update changelog of patch [14/25] so that it only mentions Titan Ridge.
* Rename CONFIG_THUNDERBOLT to CONFIG_USB4, this should be more future proof.
* Check if TMU is enabled in tb_switch_tmu_enable().
* Use "usb3" and "USB3" in USB 3.x tunneling functionality instead of plain "usb".
* Reword documentation patch [25/25] according to received comments.
* Introduce icm_firmware_running().
I did not yet add the hw_vendor_id and hw_product_id attributes because I clocked that 'dd if=nvm_activeX/nvmem of=/dev/null bs=64 count=2' (that's what fwupd does) takes typically less than 10 ms when the controller is powered on. That should not slow down fwupd. We can add them later if it is really a problem (I'm just trying to avoid adding too much attributes that we need to maintain forever).
I think patches 1 to 17 can be applied for v5.5 already since they are pretty much about adding support for existing Thunderbolt 3 devices to the software connection manager. This allows Apple systems with Alpine or Titan Ridge controller to work without need to start the firmware. Please let me know if there are objections.
USB4 support patches 18 - 25 have been tested on development hardware but since it is rather early stage hardware we have not been able to properly test all features such as power management (which is why it is currently missing in this series).
Mika Westerberg (22):
thunderbolt: Introduce tb_switch_is_icm()
thunderbolt: Log switch route string on config read/write timeout
thunderbolt: Log error if adding switch fails
thunderbolt: Convert basic adapter register names to follow the USB4 spec
thunderbolt: Convert PCIe adapter register names to follow the USB4 spec
thunderbolt: Convert DP adapter register names to follow the USB4 spec
thunderbolt: Make tb_sw_write() take const parameter
thunderbolt: Add helper macro to iterate over switch ports
thunderbolt: Refactor add_switch() into two functions
thunderbolt: Add support for lane bonding
thunderbolt: Add default linking between lane adapters if not provided by DROM
thunderbolt: Expand controller name in tb_switch_is_xy()
thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
thunderbolt: Add Display Port CM handshake for Titan Ridge devices
thunderbolt: Add Display Port adapter pairing and resource management
thunderbolt: Add bandwidth management for Display Port tunnels
thunderbolt: Do not start firmware unless asked by the user
thunderbolt: Make tb_find_port() available to other files
thunderbolt: Call tb_eeprom_get_drom_offset() from tb_eeprom_read_n()
thunderbolt: Add initial support for USB4
thunderbolt: Update Kconfig entry to USB4
thunderbolt: Update documentation with the USB4 information
Rajmohan Mani (3):
thunderbolt: Make tb_switch_find_cap() available to other files
thunderbolt: Add support for Time Management Unit
thunderbolt: Add support for USB 3.x tunnels
.../ABI/testing/sysfs-bus-thunderbolt | 28 + Documentation/admin-guide/thunderbolt.rst | 25 +- drivers/Makefile | 2 +- drivers/net/Kconfig | 2 +- drivers/thunderbolt/Kconfig | 11 +- drivers/thunderbolt/Makefile | 4 +- drivers/thunderbolt/cap.c | 17 +- drivers/thunderbolt/ctl.c | 8 +- drivers/thunderbolt/eeprom.c | 146 +-- drivers/thunderbolt/icm.c | 157 +-- drivers/thunderbolt/lc.c | 193 +++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/path.c | 52 +- drivers/thunderbolt/switch.c | 943 +++++++++++++++--- drivers/thunderbolt/tb.c | 536 ++++++++-- drivers/thunderbolt/tb.h | 182 +++- drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 160 ++- drivers/thunderbolt/tmu.c | 383 +++++++ drivers/thunderbolt/tunnel.c | 527 +++++++++- drivers/thunderbolt/tunnel.h | 19 +- drivers/thunderbolt/usb4.c | 763 ++++++++++++++ drivers/thunderbolt/xdomain.c | 11 +- 24 files changed, 3718 insertions(+), 458 deletions(-) create mode 100644 drivers/thunderbolt/tmu.c create mode 100644 drivers/thunderbolt/usb4.c
Signature · 1 line
2.23.0
PATCH 1/25 thunderbolt: Introduce tb_switch_is_icm()
We currently differentiate between SW CM (Software Connection Manager, sometimes also called External Connection Manager) and ICM (Firmware based Connection Manager, Internal Connection Manager) by looking directly at the sw->config.enabled field which may be rather hard to understand for the casual reader. For this reason introduce a wrapper function with documentation that should make the intention more clear.
--- drivers/thunderbolt/lc.c | 4 ++-- drivers/thunderbolt/switch.c | 4 ++-- drivers/thunderbolt/tb.h | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
drivers/thunderbolt/lc.c +2 -2
@@ -94,7 +94,7 @@ int tb_lc_configure_link(struct tb_switch *sw)struct tb_port *up, *down;int ret; -if (!sw->config.enabled || !tb_route (sw)) +if (!tb_route (sw) ||tb_switch_is_icm (sw))return 0 ; up =tb_upstream_port (sw);
@@ -124,7 +124,7 @@ void tb_lc_unconfigure_link(struct tb_switch *sw) {struct tb_port *up, *down; -if (sw->is_unplugged || !sw->config.enabled || !tb_route (sw)) +if (sw->is_unplugged || !tb_route (sw) ||tb_switch_is_icm (sw))return ; up =tb_upstream_port (sw);
drivers/thunderbolt/switch.c +2 -2
@@ -986,7 +986,7 @@ static int tb_plug_events_active(struct tb_switch *sw, bool active)u32 data;int res; -if (!sw->config.enabled) +if (tb_switch_is_icm (sw))return 0 ; sw->config.plug_events_delay =0xff ;
@@ -1710,7 +1710,7 @@ static int tb_switch_add_dma_port(struct tb_switch *sw) }/* Root switch DMA port requires running firmware */ -if (!tb_route (sw) && sw->config.enabled) +if (!tb_route (sw) && !tb_switch_is_icm (sw))return 0 ; sw->dma_port =dma_port_alloc (sw);
drivers/thunderbolt/tb.h +14 -0
@@ -591,6 +591,20 @@ static inline bool tb_switch_is_fr(const struct tb_switch *sw) } } +/** +* tb_switch_is_icm() - Is the switch handled by ICM firmware +* @sw: Switch to check +* +* In case there is a need to differentiate whether ICM firmware or SW CM +* is handling @sw this function can be called. It is valid to call this +* after tb_switch_alloc() and tb_switch_configure() has been called +* (latter only for SW CM case). +*/ +static inline bool tb_switch_is_icm (const struct tb_switch *sw) +{ +return !sw->config.enabled; +} +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
Signature · 1 line
2.23.0
PATCH 2/25 thunderbolt: Log switch route string on config read/write timeout
In reply to Mika WesterbergThis helps to point out which switch config read/write triggered the timeout.
--- drivers/thunderbolt/ctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thunderbolt/ctl.c +4 -4
@@ -962,8 +962,8 @@ int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port,return tb_cfg_get_error (ctl, space, &res);case -ETIMEDOUT : -tb_ctl_warn (ctl,"timeout reading config space %u from %#x\n" , - space, offset); +tb_ctl_warn (ctl,"%llx: timeout reading config space %u from %#x\n" , + route, space, offset);break ;default :
@@ -988,8 +988,8 @@ int tb_cfg_write(struct tb_ctl *ctl, const void *buffer, u64 route, u32 port,return tb_cfg_get_error (ctl, space, &res);case -ETIMEDOUT : -tb_ctl_warn (ctl,"timeout writing config space %u to %#x\n" , - space, offset); +tb_ctl_warn (ctl,"%llx: timeout writing config space %u to %#x\n" , + route, space, offset);break ;default :
Signature · 1 line
2.23.0
PATCH 3/25 thunderbolt: Log error if adding switch fails
In reply to Mika WesterbergIf we fail to add a switch for some reason log an error instead of keeping silent. This is useful for debugging.
--- drivers/thunderbolt/switch.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/thunderbolt/switch.c +14 -5
@@ -1775,21 +1775,25 @@ int tb_switch_add(struct tb_switch *sw)* configuration based mailbox. */ ret =tb_switch_add_dma_port (sw); -if (ret) +if (ret) { +dev_err (&sw->dev,"failed to add DMA port\n" );return ret; + }if (!sw->safe_mode) {/* read drom */ ret =tb_drom_read (sw);if (ret) { -tb_sw_warn (sw,"tb_eeprom_read_rom failed\n" ); +dev_err (&sw->dev,"reading DROM failed\n" );return ret; }tb_sw_dbg (sw,"uid: %#llx\n" , sw->uid); ret =tb_switch_set_uuid (sw); -if (ret) +if (ret) { +dev_err (&sw->dev,"failed to set UUID\n" );return ret; + }for (i =0 ; i <= sw->config.max_port_number; i++) {if (sw->ports[i].disabled) {
@@ -1797,14 +1801,18 @@ int tb_switch_add(struct tb_switch *sw)continue ; } ret =tb_init_port (&sw->ports[i]); -if (ret) +if (ret) { +dev_err (&sw->dev,"failed to initialize port %d\n" , i);return ret; + } } } ret =device_add (&sw->dev); -if (ret) +if (ret) { +dev_err (&sw->dev,"failed to add device: %d\n" , ret);return ret; + }if (tb_route (sw)) { dev_info(&sw->dev, "new device found, vendor=%#x device=%#x\n",
@@ -1816,6 +1824,7 @@ int tb_switch_add(struct tb_switch *sw) ret =tb_switch_nvm_add (sw);if (ret) { +dev_err (&sw->dev,"failed to add NVM devices\n" );device_del (&sw->dev);return ret; }
Signature · 1 line
2.23.0
PATCH 4/25 thunderbolt: Convert basic adapter register names to follow the USB4 spec
In reply to Mika WesterbergNow that USB4 spec has names for these basic registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 18 +++++++++--------- drivers/thunderbolt/tb_regs.h | 15 ++++++++------- drivers/thunderbolt/tunnel.c | 10 +++++----- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/thunderbolt/switch.c +9 -9
@@ -553,17 +553,17 @@ int tb_port_add_nfc_credits(struct tb_port *port, int credits)if (credits ==0 || port->sw->is_unplugged)return 0 ; - nfc_credits = port->config.nfc_credits &TB_PORT_NFC_CREDITS_MASK ; + nfc_credits = port->config.nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ; nfc_credits += credits; -tb_port_dbg (port,"adding %d NFC credits to %lu" , - credits, port->config.nfc_credits &TB_PORT_NFC_CREDITS_MASK ); +tb_port_dbg (port,"adding %d NFC credits to %lu" , credits, + port->config.nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ); - port->config.nfc_credits &= ~TB_PORT_NFC_CREDITS_MASK ; + port->config.nfc_credits &= ~ADP_CS_4_NFC_BUFFERS_MASK ; port->config.nfc_credits |= nfc_credits;return tb_port_write (port, &port->config.nfc_credits, -TB_CFG_PORT ,4 ,1 ); +TB_CFG_PORT ,ADP_CS_4 ,1 ); }/**
@@ -578,14 +578,14 @@ int tb_port_set_initial_credits(struct tb_port *port, u32 credits)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT ,5 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT ,ADP_CS_5 ,1 );if (ret)return ret; - data &= ~TB_PORT_LCA_MASK ; - data |= (credits <<TB_PORT_LCA_SHIFT ) &TB_PORT_LCA_MASK ; + data &= ~ADP_CS_5_LCA_MASK ; + data |= (credits <<ADP_CS_5_LCA_SHIFT ) &ADP_CS_5_LCA_MASK ; -return tb_port_write (port, &data,TB_CFG_PORT ,5 ,1 ); +return tb_port_write (port, &data,TB_CFG_PORT ,ADP_CS_5 ,1 ); }/**
drivers/thunderbolt/tb_regs.h +8 -7
@@ -211,13 +211,14 @@ struct tb_regs_port_header { } __packed; -/* DWORD 4 */ -#define TB_PORT_NFC_CREDITS_MASK GENMASK(19, 0) -#define TB_PORT_MAX_CREDITS_SHIFT 20 -#define TB_PORT_MAX_CREDITS_MASK GENMASK(26, 20) -/* DWORD 5 */ -#define TB_PORT_LCA_SHIFT 22 -#define TB_PORT_LCA_MASK GENMASK(28, 22) +/* Basic adapter configuration registers */ +#define ADP_CS_4 0x04 +#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0) +#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20) +#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20 +#define ADP_CS_5 0x05 +#define ADP_CS_5_LCA_MASK GENMASK(28, 22) +#define ADP_CS_5_LCA_SHIFT 22/* Display Port adapter registers */
drivers/thunderbolt/tunnel.c +5 -5
@@ -324,12 +324,12 @@ static void tb_dp_init_video_path(struct tb_path *path, bool discover) path->weight =1 ;if (discover) { - path->nfc_credits = nfc_credits &TB_PORT_NFC_CREDITS_MASK ; + path->nfc_credits = nfc_credits &ADP_CS_4_NFC_BUFFERS_MASK ; }else {u32 max_credits; - max_credits = (nfc_credits &TB_PORT_MAX_CREDITS_MASK ) >> -TB_PORT_MAX_CREDITS_SHIFT ; + max_credits = (nfc_credits &ADP_CS_4_TOTAL_BUFFERS_MASK ) >> +ADP_CS_4_TOTAL_BUFFERS_SHIFT ;/* Leave some credits for AUX path */ path->nfc_credits =min (max_credits -2 ,12U ); }
@@ -478,8 +478,8 @@ static u32 tb_dma_credits(struct tb_port *nhi) {u32 max_credits; - max_credits = (nhi->config.nfc_credits &TB_PORT_MAX_CREDITS_MASK ) >> -TB_PORT_MAX_CREDITS_SHIFT ; + max_credits = (nhi->config.nfc_credits &ADP_CS_4_TOTAL_BUFFERS_MASK ) >> +ADP_CS_4_TOTAL_BUFFERS_SHIFT ;return min (max_credits,13U ); }
Signature · 1 line
2.23.0
PATCH 5/25 thunderbolt: Convert PCIe adapter register names to follow the USB4 spec
In reply to Mika WesterbergNow that USB4 spec has names for these PCIe adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 10 ++++++---- drivers/thunderbolt/tb_regs.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/thunderbolt/switch.c +6 -4
@@ -803,10 +803,11 @@ bool tb_pci_port_is_enabled(struct tb_port *port) {u32 data; -if (tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap,1 )) +if (tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_PCIE_CS_0 ,1 ))return false; -return !!(data &TB_PCI_EN ); +return !!(data &ADP_PCIE_CS_0_PE ); }/**
@@ -816,10 +817,11 @@ bool tb_pci_port_is_enabled(struct tb_port *port)*/ int tb_pci_port_enable (struct tb_port *port,bool enable) { -u32 word = enable ?TB_PCI_EN :0x0 ; +u32 word = enable ?ADP_PCIE_CS_0_PE :0x0 ;if (!port->cap_adap)return -ENXIO ; -return tb_port_write (port, &word,TB_CFG_PORT , port->cap_adap,1 ); +return tb_port_write (port, &word,TB_CFG_PORT , + port->cap_adap +ADP_PCIE_CS_0 ,1 ); }/**
drivers/thunderbolt/tb_regs.h +2 -2
@@ -241,8 +241,8 @@ struct tb_regs_port_header {#define TB_DP_REMOTE_CAP 0x5/* PCIe adapter registers */ - -#define TB_PCI_EN BIT(31) +#define ADP_PCIE_CS_0 0x00 +#define ADP_PCIE_CS_0_PE BIT(31)/* Hop register from TB_CFG_HOPS. 8 byte per entry. */ struct tb_regs_hop {
Signature · 1 line
2.23.0
PATCH 6/25 thunderbolt: Convert DP adapter register names to follow the USB4 spec
In reply to Mika WesterbergNow that USB4 spec has names for these DP adapter registers we can use them instead. This makes it easier to match certain register to the spec.
No functional changes.
--- drivers/thunderbolt/switch.c | 50 ++++++++++++++++++++--------------- drivers/thunderbolt/tb_regs.h | 32 ++++++++++------------ drivers/thunderbolt/tunnel.c | 8 +++--- 3 files changed, 46 insertions(+), 44 deletions(-)
drivers/thunderbolt/switch.c +28 -22
@@ -835,11 +835,12 @@ int tb_dp_port_hpd_is_active(struct tb_port *port)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap +2 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_2 ,1 );if (ret)return ret; -return !!(data &TB_DP_HDP ); +return !!(data &ADP_DP_CS_2_HDP ); }/**
@@ -853,12 +854,14 @@ int tb_dp_port_hpd_clear(struct tb_port *port)u32 data;int ret; - ret =tb_port_read (port, &data,TB_CFG_PORT , port->cap_adap +3 ,1 ); + ret =tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_3 ,1 );if (ret)return ret; - data |=TB_DP_HPDC ; -return tb_port_write (port, &data,TB_CFG_PORT , port->cap_adap +3 ,1 ); + data |=ADP_DP_CS_3_HDPC ; +return tb_port_write (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_3 ,1 ); }/**
@@ -876,20 +879,23 @@ int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,u32 data[2 ];int ret; - ret =tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); + ret =tb_port_read (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data));if (ret)return ret; - data[0 ] &= ~TB_DP_VIDEO_HOPID_MASK ; - data[1 ] &= ~(TB_DP_AUX_RX_HOPID_MASK |TB_DP_AUX_TX_HOPID_MASK ); + data[0 ] &= ~ADP_DP_CS_0_VIDEO_HOPID_MASK ; + data[1 ] &= ~ADP_DP_CS_1_AUX_RX_HOPID_MASK ; + data[1 ] &= ~ADP_DP_CS_1_AUX_RX_HOPID_MASK ; - data[0 ] |= (video <<TB_DP_VIDEO_HOPID_SHIFT ) &TB_DP_VIDEO_HOPID_MASK ; - data[1 ] |= aux_tx &TB_DP_AUX_TX_HOPID_MASK ; - data[1 ] |= (aux_rx <<TB_DP_AUX_RX_HOPID_SHIFT ) &TB_DP_AUX_RX_HOPID_MASK ; + data[0 ] |= (video <<ADP_DP_CS_0_VIDEO_HOPID_SHIFT ) & +ADP_DP_CS_0_VIDEO_HOPID_MASK ; + data[1 ] |= aux_tx &ADP_DP_CS_1_AUX_TX_HOPID_MASK ; + data[1 ] |= (aux_rx <<ADP_DP_CS_1_AUX_RX_HOPID_SHIFT ) & +ADP_DP_CS_1_AUX_RX_HOPID_MASK ; -return tb_port_write (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); +return tb_port_write (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)); }/**
@@ -900,11 +906,11 @@ bool tb_dp_port_is_enabled(struct tb_port *port) {u32 data[2 ]; -if (tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, +if (tb_port_read (port, data,TB_CFG_PORT , port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)))return false; -return !!(data[0 ] & (TB_DP_VIDEO_EN |TB_DP_AUX_EN )); +return !!(data[0 ] & (ADP_DP_CS_0_VE |ADP_DP_CS_0_AE )); }/**
@@ -920,18 +926,18 @@ int tb_dp_port_enable(struct tb_port *port, bool enable)u32 data[2 ];int ret; - ret =tb_port_read (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); + ret =tb_port_read (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data));if (ret)return ret;if (enable) - data[0 ] |=TB_DP_VIDEO_EN |TB_DP_AUX_EN ; + data[0 ] |=ADP_DP_CS_0_VE |ADP_DP_CS_0_AE ;else - data[0 ] &= ~(TB_DP_VIDEO_EN |TB_DP_AUX_EN ); + data[0 ] &= ~(ADP_DP_CS_0_VE |ADP_DP_CS_0_AE ); -return tb_port_write (port, data,TB_CFG_PORT , port->cap_adap, -ARRAY_SIZE (data)); +return tb_port_write (port, data,TB_CFG_PORT , + port->cap_adap +ADP_DP_CS_0 ,ARRAY_SIZE (data)); }/* switch utility functions */
drivers/thunderbolt/tb_regs.h +14 -18
@@ -221,24 +221,20 @@ struct tb_regs_port_header {#define ADP_CS_5_LCA_SHIFT 22/* Display Port adapter registers */ - -/* DWORD 0 */ -#define TB_DP_VIDEO_HOPID_SHIFT 16 -#define TB_DP_VIDEO_HOPID_MASK GENMASK(26, 16) -#define TB_DP_AUX_EN BIT(30) -#define TB_DP_VIDEO_EN BIT(31) -/* DWORD 1 */ -#define TB_DP_AUX_TX_HOPID_MASK GENMASK(10, 0) -#define TB_DP_AUX_RX_HOPID_SHIFT 11 -#define TB_DP_AUX_RX_HOPID_MASK GENMASK(21, 11) -/* DWORD 2 */ -#define TB_DP_HDP BIT(6) -/* DWORD 3 */ -#define TB_DP_HPDC BIT(9) -/* DWORD 4 */ -#define TB_DP_LOCAL_CAP 0x4 -/* DWORD 5 */ -#define TB_DP_REMOTE_CAP 0x5 +#define ADP_DP_CS_0 0x00 +#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16) +#define ADP_DP_CS_0_VIDEO_HOPID_SHIFT 16 +#define ADP_DP_CS_0_AE BIT(30) +#define ADP_DP_CS_0_VE BIT(31) +#define ADP_DP_CS_1_AUX_TX_HOPID_MASK GENMASK(10, 0) +#define ADP_DP_CS_1_AUX_RX_HOPID_MASK GENMASK(21, 11) +#define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11 +#define ADP_DP_CS_2 0x02 +#define ADP_DP_CS_2_HDP BIT(6) +#define ADP_DP_CS_3 0x03 +#define ADP_DP_CS_3_HDPC BIT(9) +#define DP_LOCAL_CAP 0x04 +#define DP_REMOTE_CAP 0x05/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +4 -4
@@ -241,23 +241,23 @@ static int tb_dp_xchg_caps(struct tb_tunnel *tunnel)/* Read both DP_LOCAL_CAP registers */ ret =tb_port_read (in, &in_dp_cap,TB_CFG_PORT , - in->cap_adap +TB_DP_LOCAL_CAP ,1 ); + in->cap_adap +DP_LOCAL_CAP ,1 );if (ret)return ret; ret =tb_port_read (out, &out_dp_cap,TB_CFG_PORT , - out->cap_adap +TB_DP_LOCAL_CAP ,1 ); + out->cap_adap +DP_LOCAL_CAP ,1 );if (ret)return ret;/* Write IN local caps to OUT remote caps */ ret =tb_port_write (out, &in_dp_cap,TB_CFG_PORT , - out->cap_adap +TB_DP_REMOTE_CAP ,1 ); + out->cap_adap +DP_REMOTE_CAP ,1 );if (ret)return ret;return tb_port_write (in, &out_dp_cap,TB_CFG_PORT , - in->cap_adap +TB_DP_REMOTE_CAP ,1 ); + in->cap_adap +DP_REMOTE_CAP ,1 ); }static int tb_dp_activate (struct tb_tunnel *tunnel,bool active)
Signature · 1 line
2.23.0
PATCH 7/25 thunderbolt: Make tb_sw_write() take const parameter
In reply to Mika WesterbergThe function does not modify the argument in any way so make it const.
--- drivers/thunderbolt/tb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/tb.h +1 -1
@@ -399,7 +399,7 @@ static inline int tb_sw_read(struct tb_switch *sw, void *buffer, length); } -static inline int tb_sw_write (struct tb_switch *sw,void *buffer, +static inline int tb_sw_write (struct tb_switch *sw,const void *buffer,enum tb_cfg_space space,u32 offset,u32 length) {if (sw->is_unplugged)
Signature · 1 line
2.23.0
PATCH 8/25 thunderbolt: Add helper macro to iterate over switch ports
In reply to Mika WesterbergThere are quite many places in the driver where we iterate over each port in the switch. To make it bit more convenient, add a macro that can be used to iterate over each port and convert existing call sites to use it.
This is based on code by Lukas Wunner.
No functional changes.
--- drivers/thunderbolt/icm.c | 12 +++----- drivers/thunderbolt/switch.c | 57 ++++++++++++++++++----------------- drivers/thunderbolt/tb.c | 54 ++++++++++++++++----------------- drivers/thunderbolt/tb.h | 11 +++++++ drivers/thunderbolt/xdomain.c | 5 ++- 5 files changed, 74 insertions(+), 65 deletions(-)
drivers/thunderbolt/icm.c +4 -8
@@ -1893,14 +1893,12 @@ static int icm_suspend(struct tb *tb)*/ static void icm_unplug_children (struct tb_switch *sw) { -unsigned int i; +struct tb_port *port;if (tb_route (sw)) sw->is_unplugged = true; -for (i =1 ; i <= sw->config.max_port_number; i++) { -struct tb_port *port = &sw->ports[i]; - +tb_switch_for_each_port (sw, port) {if (port->xdomain) port->xdomain->is_unplugged = true;else if (tb_port_has_remote (port))
@@ -1936,11 +1934,9 @@ static void remove_unplugged_switch(struct tb_switch *sw)static void icm_free_unplugged_children (struct tb_switch *sw) { -unsigned int i; - -for (i =1 ; i <= sw->config.max_port_number; i++) { -struct tb_port *port = &sw->ports[i]; +struct tb_port *port; +tb_switch_for_each_port (sw, port) {if (port->xdomain && port->xdomain->is_unplugged) {tb_xdomain_remove (port->xdomain); port->xdomain =NULL ;
drivers/thunderbolt/switch.c +30 -27
111 lines not on this page · raw message
drivers/thunderbolt/tb.c +27 -27
106 lines not on this page · raw message
drivers/thunderbolt/tb.h +11 -0
@@ -530,6 +530,17 @@ struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,struct tb_switch *tb_switch_find_by_uuid (struct tb *tb,const uuid_t *uuid);struct tb_switch *tb_switch_find_by_route (struct tb *tb,u64 route); +/** +* tb_switch_for_each_port() - Iterate over each switch port +* @sw: Switch whose ports to iterate +* @p: Port used as iterator +* +* Iterates over each switch port skipping the control port (port %0). +*/ +#define tb_switch_for_each_port (sw, p) \ + for ((p) = &(sw)->ports[1]; \ + (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++) +static inline struct tb_switch *tb_switch_get (struct tb_switch *sw) {if (sw)
drivers/thunderbolt/xdomain.c +2 -3
@@ -1404,10 +1404,9 @@ struct tb_xdomain_lookup {static struct tb_xdomain *switch_find_xdomain (struct tb_switch *sw,const struct tb_xdomain_lookup *lookup) { -int i; +struct tb_port *port; -for (i =1 ; i <= sw->config.max_port_number; i++) { -struct tb_port *port = &sw->ports[i]; +tb_switch_for_each_port (sw, port) {struct tb_xdomain *xd;if (port->xdomain) {
Signature · 1 line
2.23.0
PATCH 9/25 thunderbolt: Refactor add_switch() into two functions
In reply to Mika WesterbergCurrently add_switch() takes a huge amount of parameters that makes it hard to maintain. Instead of passing all those parameters we can split the function into two parts (alloc and add) and fill the additional switch fields directly in the functions calling those.
While there remove redundant error logging in case kmemdup() fails.
No functional changes.
--- drivers/thunderbolt/icm.c | 110 +++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 43 deletions(-)
drivers/thunderbolt/icm.c +67 -43
@@ -147,6 +147,17 @@ static const struct intel_vss *parse_intel_vss(const void *ep_name, size_t size)return NULL ; } +static bool intel_vss_is_rtd3 (const void *ep_name,size_t size) +{ +const struct intel_vss *vss; + + vss =parse_intel_vss (ep_name, size); +if (vss) +return !!(vss->flags &INTEL_VSS_FLAGS_RTD3 ); + +return false; +} +static inline struct tb *icm_to_tb (struct icm *icm) {return ((void *)icm -sizeof (struct tb ));
@@ -562,58 +573,42 @@ static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)return 0 ; } -static struct tb_switch *add_switch (struct tb_switch *parent_sw,u64 route, -const uuid_t *uuid,const u8 *ep_name, -size_t ep_name_size,u8 connection_id, -u8 connection_key,u8 link,u8 depth, -enum tb_security_level security_level, -bool authorized,bool boot) +static struct tb_switch *alloc_switch (struct tb_switch *parent_sw,u64 route, +const uuid_t *uuid) { -const struct intel_vss *vss; +struct tb *tb = parent_sw->tb;struct tb_switch *sw; -int ret; -pm_runtime_get_sync (&parent_sw->dev); - - sw =tb_switch_alloc (parent_sw->tb, &parent_sw->dev, route); -if (IS_ERR (sw)) - goto out; + sw =tb_switch_alloc (tb, &parent_sw->dev, route); +if (IS_ERR (sw)) { +tb_warn (tb,"failed to allocate switch at %llx\n" , route); +return sw; + } sw->uuid =kmemdup (uuid,sizeof (*uuid),GFP_KERNEL );if (!sw->uuid) { -tb_sw_warn (sw,"cannot allocate memory for switch\n" );tb_switch_put (sw); - goto out; +return ERR_PTR (-ENOMEM ); } - sw->connection_id = connection_id; - sw->connection_key = connection_key; - sw->link = link; - sw->depth = depth; - sw->authorized = authorized; - sw->security_level = security_level; - sw->boot = boot; +init_completion (&sw->rpm_complete); +return sw; +} - vss =parse_intel_vss (ep_name, ep_name_size); -if (vss) - sw->rpm = !!(vss->flags &INTEL_VSS_FLAGS_RTD3 ); +static int add_switch (struct tb_switch *parent_sw,struct tb_switch *sw) +{ +u64 route =tb_route (sw); +int ret;/* Link the two switches now */ tb_port_at (route, parent_sw)->remote =tb_upstream_port (sw);tb_upstream_port (sw)->remote =tb_port_at (route, parent_sw); ret =tb_switch_add (sw); -if (ret) { +if (ret)tb_port_at (tb_route (sw), parent_sw)->remote =NULL ; -tb_switch_put (sw); - sw =ERR_PTR (ret); - } -out: -pm_runtime_mark_last_busy (&parent_sw->dev); -pm_runtime_put_autosuspend (&parent_sw->dev); - -return sw; +return ret; } static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,
@@ -811,10 +806,25 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)return ; } -add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name, -sizeof (pkg->ep_name), pkg->connection_id, - pkg->connection_key, link, depth, security_level, - authorized, boot); +pm_runtime_get_sync (&parent_sw->dev); + + sw =alloc_switch (parent_sw, route, &pkg->ep_uuid); +if (!IS_ERR (sw)) { + sw->connection_id = pkg->connection_id; + sw->connection_key = pkg->connection_key; + sw->link = link; + sw->depth = depth; + sw->authorized = authorized; + sw->security_level = security_level; + sw->boot = boot; + sw->rpm =intel_vss_is_rtd3 (pkg->ep_name,sizeof (pkg->ep_name)); + +if (add_switch (parent_sw, sw)) +tb_switch_put (sw); + } + +pm_runtime_mark_last_busy (&parent_sw->dev); +pm_runtime_put_autosuspend (&parent_sw->dev);tb_switch_put (parent_sw); }
@@ -1205,11 +1215,25 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr,return ; } - sw =add_switch (parent_sw, route, &pkg->ep_uuid, (const u8 *)pkg->ep_name, -sizeof (pkg->ep_name), pkg->connection_id,0 ,0 ,0 , - security_level, authorized, boot); -if (!IS_ERR (sw) && force_rtd3) - sw->rpm = true; +pm_runtime_get_sync (&parent_sw->dev); + + sw =alloc_switch (parent_sw, route, &pkg->ep_uuid); +if (!IS_ERR (sw)) { + sw->connection_id = pkg->connection_id; + sw->authorized = authorized; + sw->security_level = security_level; + sw->boot = boot; + sw->rpm = force_rtd3; +if (!sw->rpm) + sw->rpm =intel_vss_is_rtd3 (pkg->ep_name, +sizeof (pkg->ep_name)); + +if (add_switch (parent_sw, sw)) +tb_switch_put (sw); + } + +pm_runtime_mark_last_busy (&parent_sw->dev); +pm_runtime_put_autosuspend (&parent_sw->dev);tb_switch_put (parent_sw); }
Signature · 1 line
2.23.0
PATCH 10/25 thunderbolt: Add support for lane bonding
In reply to Mika WesterbergLane bonding allows aggregating two 10/20 Gb/s (depending on the generation) lanes into a single 20/40 Gb/s bonded link. This allows sharing the full bandwidth more efficiently. In order to establish lane bonding we need to check that lane bonding is possible through link controller and that both ends of the link actually supports 2x widths. This also means that all the paths should be established through the primary port so update tb_path_alloc() to handle this as well.
Lane bonding is supported starting from Falcon Ridge (2nd generation) controllers.
We also expose the current speed and number of lanes under each device except the host router following similar attribute naming than USB bus. Expose speed and number of lanes for both directions to allow possibility of asymmetric link in the future.
--- .../ABI/testing/sysfs-bus-thunderbolt | 28 ++ drivers/thunderbolt/icm.c | 12 +- drivers/thunderbolt/lc.c | 28 ++ drivers/thunderbolt/path.c | 30 +- drivers/thunderbolt/switch.c | 288 ++++++++++++++++++ drivers/thunderbolt/tb.c | 22 ++ drivers/thunderbolt/tb.h | 10 + drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tunnel.c | 19 +- 10 files changed, 452 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-bus-thunderbolt +28 -0
@@ -104,6 +104,34 @@ Contact: [email protected] Description: This attribute contains name of this device extracted from the device DROM. +What: /sys/bus/thunderbolt/devices/.../rx_speed +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the device RX speed per lane. + All RX lanes run at the same speed. + +What: /sys/bus/thunderbolt/devices/.../rx_lanes +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports number of RX lanes the device is + using simultaneusly through its upstream port. + +What: /sys/bus/thunderbolt/devices/.../tx_speed +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports the TX speed per lane. + All TX lanes run at the same speed. + +What: /sys/bus/thunderbolt/devices/.../tx_lanes +Date: Apr 2020 +KernelVersion: 5.6 +Contact: Mika Westerberg <[email protected]> +Description: This attribute reports number of TX lanes the device is + using simultaneusly through its upstream port. + What: /sys/bus/thunderbolt/devices/.../vendor Date: Sep 2017 KernelVersion: 4.13
drivers/thunderbolt/icm.c +10 -2
@@ -692,11 +692,11 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) (const struct icm_fr_event_device_connected *)hdr;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw; +bool boot, dual_lane, speed_gen3;struct icm *icm =tb_priv (tb);bool authorized = false;struct tb_xdomain *xd;u8 link, depth; -bool boot;u64 route;int ret;
@@ -709,6 +709,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %u.%u was rejected by ICM firmware because topology limit exceeded\n",
@@ -817,6 +819,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr) sw->authorized = authorized; sw->security_level = security_level; sw->boot = boot; + sw->link_speed = speed_gen3 ?20 :10 ; + sw->link_width = dual_lane ?2 :1 ; sw->rpm =intel_vss_is_rtd3 (pkg->ep_name,sizeof (pkg->ep_name));if (add_switch (parent_sw, sw))
@@ -1152,10 +1156,10 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, {const struct icm_tr_event_device_connected *pkg = (const struct icm_tr_event_device_connected *)hdr; +bool authorized, boot, dual_lane, speed_gen3;enum tb_security_level security_level;struct tb_switch *sw, *parent_sw;struct tb_xdomain *xd; -bool authorized, boot;u64 route;icm_postpone_rescan (tb);
@@ -1173,6 +1177,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, security_level = (pkg->hdr.flags &ICM_FLAGS_SLEVEL_MASK ) >>ICM_FLAGS_SLEVEL_SHIFT ; boot = pkg->link_info &ICM_LINK_INFO_BOOT ; + dual_lane = pkg->hdr.flags &ICM_FLAGS_DUAL_LANE ; + speed_gen3 = pkg->hdr.flags &ICM_FLAGS_SPEED_GEN3 ;if (pkg->link_info &ICM_LINK_INFO_REJECTED ) { tb_info(tb, "switch at %llx was rejected by ICM firmware because topology limit exceeded\n",
@@ -1223,6 +1229,8 @@ __icm_tr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr, sw->authorized = authorized; sw->security_level = security_level; sw->boot = boot; + sw->link_speed = speed_gen3 ?20 :10 ; + sw->link_width = dual_lane ?2 :1 ; sw->rpm = force_rtd3;if (!sw->rpm) sw->rpm = intel_vss_is_rtd3(pkg->ep_name,
drivers/thunderbolt/lc.c +28 -0
@@ -177,3 +177,31 @@ int tb_lc_set_sleep(struct tb_switch *sw)return 0 ; } + +/** +* tb_lc_lane_bonding_possible() - Is lane bonding possible towards switch +* @sw: Switch to check +* +* Checks whether conditions for lane bonding from parent to @sw are +* possible. +*/ +bool tb_lc_lane_bonding_possible (struct tb_switch *sw) +{ +struct tb_port *up; +int cap, ret; +u32 val; + +if (sw->generation <2 ) +return false; + + up =tb_upstream_port (sw); + cap =find_port_lc_cap (up); +if (cap <0 ) +return false; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , cap +TB_LC_PORT_ATTR ,1 ); +if (ret) +return false; + +return !!(val &TB_LC_PORT_ATTR_BE ); +}
drivers/thunderbolt/path.c +26 -4
@@ -220,7 +220,8 @@ struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,* Creates path between two ports starting with given @src_hopid. Reserves * HopIDs for each port (they can be different from @src_hopid depending on * how many HopIDs each port already have reserved). If there are dual -* links on the path, prioritizes using @link_nr. +* links on the path, prioritizes using @link_nr but takes into account +* that the lanes may be bonded. * * Return: Returns a tb_path on success or NULL on failure. */
@@ -259,7 +260,9 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!in_port) goto err; -if (in_port->dual_link_port && in_port->link_nr != link_nr) +/* When lanes are bonded primary link must be used */ +if (!in_port->bonded && in_port->dual_link_port && + in_port->link_nr != link_nr) in_port = in_port->dual_link_port; ret =tb_port_alloc_in_hopid (in_port, in_hopid, in_hopid);
@@ -271,8 +274,27 @@ struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,if (!out_port) goto err; -if (out_port->dual_link_port && out_port->link_nr != link_nr) - out_port = out_port->dual_link_port; +/* +* Pick up right port when going from non-bonded to +* bonded or from bonded to non-bonded. +*/ +if (out_port->dual_link_port) { +if (!in_port->bonded && out_port->bonded && + out_port->link_nr) { +/* +* Use primary link when going from +* non-bonded to bonded. +*/ + out_port = out_port->dual_link_port; + }else if (!out_port->bonded && + out_port->link_nr != link_nr) { +/* +* If out port is not bonded follow +* link_nr. +*/ + out_port = out_port->dual_link_port; + } + }if (i == num_hops -1 ) ret = tb_port_alloc_out_hopid(out_port, dst_hopid,
drivers/thunderbolt/switch.c +288 -0
324 lines not on this page · raw message
drivers/thunderbolt/tb.c +22 -0
@@ -216,6 +216,10 @@ static void tb_scan_port(struct tb_port *port) upstream_port->dual_link_port->remote = port->dual_link_port; } +/* Enable lane bonding if supported */ +if (tb_switch_lane_bonding_enable (sw)) +tb_sw_warn (sw,"failed to enable lane bonding\n" ); +tb_scan_switch (sw); }
@@ -269,6 +273,7 @@ static void tb_free_unplugged_children(struct tb_switch *sw)continue ;if (port->remote->sw->is_unplugged) { +tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;if (port->dual_link_port)
@@ -534,6 +539,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_port_dbg (port,"switch unplugged\n" );tb_sw_set_unplugged (port->remote->sw);tb_free_invalid_tunnels (tb); +tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;if (port->dual_link_port)
@@ -703,6 +709,21 @@ static int tb_suspend_noirq(struct tb *tb)return 0 ; } +static void tb_restore_children (struct tb_switch *sw) +{ +struct tb_port *port; + +tb_switch_for_each_port (sw, port) { +if (!tb_port_has_remote (port)) +continue ; + +if (tb_switch_lane_bonding_enable (port->remote->sw)) +dev_warn (&sw->dev,"failed to restore lane bonding\n" ); + +tb_restore_children (port->remote->sw); + } +} +static int tb_resume_noirq (struct tb *tb) {struct tb_cm *tcm =tb_priv (tb);
@@ -716,6 +737,7 @@ static int tb_resume_noirq(struct tb *tb)tb_switch_resume (tb->root_switch);tb_free_invalid_tunnels (tb);tb_free_unplugged_children (tb->root_switch); +tb_restore_children (tb->root_switch);list_for_each_entry_safe (tunnel, n, &tcm->tunnel_list, list)tb_tunnel_restart (tunnel);if (!list_empty (&tcm->tunnel_list)) {
drivers/thunderbolt/tb.h +10 -0
@@ -61,6 +61,8 @@ struct tb_switch_nvm {* @device: Device ID of the switch * @vendor_name: Name of the vendor (or %NULL if not known) * @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) * @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)
@@ -97,6 +99,8 @@ struct tb_switch {u16 device;const char *vendor_name;const char *device_name; +unsigned int link_speed; +unsigned int link_width;unsigned int generation;int cap_plug_events;int cap_lc;
@@ -127,6 +131,7 @@ struct tb_switch {* @cap_adap: Offset of the adapter specific capability (%0 if not present) * @port: Port number on switch * @disabled: Disabled by eeprom +* @bonded: true if the port is bonded (two lanes combined as one) * @dual_link_port: If the switch is connected using two ports, points * to the other port. * @link_nr: Is this primary or secondary port on the dual_link.
@@ -142,6 +147,7 @@ struct tb_port {int cap_adap;u8 port;bool disabled; +bool bonded;struct tb_port *dual_link_port; u8 link_nr:1;struct ida in_hopids;
@@ -616,6 +622,9 @@ static inline bool tb_switch_is_icm(const struct tb_switch *sw)return !sw->config.enabled; } +int tb_switch_lane_bonding_enable (struct tb_switch *sw); +void tb_switch_lane_bonding_disable (struct tb_switch *sw); +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
@@ -659,6 +668,7 @@ int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);int tb_lc_configure_link (struct tb_switch *sw);void tb_lc_unconfigure_link (struct tb_switch *sw);int tb_lc_set_sleep (struct tb_switch *sw); +bool tb_lc_lane_bonding_possible (struct tb_switch *sw);static inline int tb_route_length (u64 route) {
drivers/thunderbolt/tb_msgs.h +2 -0
@@ -122,6 +122,8 @@ struct icm_pkg_header {#define ICM_FLAGS_NO_KEY BIT(1)#define ICM_FLAGS_SLEVEL_SHIFT 3#define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3) +#define ICM_FLAGS_DUAL_LANE BIT(5) +#define ICM_FLAGS_SPEED_GEN3 BIT(7)#define ICM_FLAGS_WRITE BIT(7)struct icm_pkg_driver_ready {
drivers/thunderbolt/tb_regs.h +20 -0
@@ -220,6 +220,23 @@ struct tb_regs_port_header {#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22 +/* Lane adapter registers */ +#define LANE_ADP_CS_0 0x00 +#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20) +#define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20 +#define LANE_ADP_CS_1 0x01 +#define LANE_ADP_CS_1_TARGET_WIDTH_MASK GENMASK(9, 4) +#define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT 4 +#define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE 0x1 +#define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3 +#define LANE_ADP_CS_1_LB BIT(15) +#define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16) +#define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT 16 +#define LANE_ADP_CS_1_CURRENT_SPEED_GEN2 0x8 +#define LANE_ADP_CS_1_CURRENT_SPEED_GEN3 0x4 +#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20) +#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20 +/* Display Port adapter registers */ #define ADP_DP_CS_0 0x00#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16)
@@ -277,6 +294,9 @@ struct tb_regs_hop {#define TB_LC_FUSE 0x03/* Link controller registers */ +#define TB_LC_PORT_ATTR 0x8d +#define TB_LC_PORT_ATTR_BE BIT(12) +#define TB_LC_SX_CTRL 0x96#define TB_LC_SX_CTRL_L1C BIT(16)#define TB_LC_SX_CTRL_L2C BIT(20)
drivers/thunderbolt/tunnel.c +18 -1
@@ -90,6 +90,22 @@ static int tb_pci_activate(struct tb_tunnel *tunnel, bool activate)return 0 ; } +static int tb_initial_credits (const struct tb_switch *sw) +{ +/* If the path is complete sw is not NULL */ +if (sw) { +/* More credits for faster link */ +switch (sw->link_speed * sw->link_width) { +case 40 : +return 32 ; +case 20 : +return 24 ; + } + } + +return 16 ; +} +static void tb_pci_init_path (struct tb_path *path) { path->egress_fc_enable =TB_PATH_SOURCE |TB_PATH_INTERNAL ;
@@ -101,7 +117,8 @@ static void tb_pci_init_path(struct tb_path *path) path->drop_packages =0 ; path->nfc_credits =0 ; path->hops[0 ].initial_credits =7 ; - path->hops[1 ].initial_credits =16 ; + path->hops[1 ].initial_credits = +tb_initial_credits (path->hops[1 ].in_port->sw); }/**
Signature · 1 line
2.23.0
PATCH 11/25 thunderbolt: Add default linking between lane adapters if not provided by DROM
In reply to Mika WesterbergWe currently read how sibling lane adapter ports relate each other from DROM (Device ROM). If the two lane adapter ports go through the same physical connector these lanes can then be bonded together. However, some cases DROM does not provide this information or it is missing completely (host routers typically do not have DROM). In this case we have hard-coded the relationship.
Expand this to work with both legacy devices where lane adapter ports 1 and 2, and 3 and 4 are always linked together, and with USB4 devices where lane adapter 1 is always following lane adapter 0 or is disabled completely (see USB4 section 5.2.1 for more information).
--- drivers/thunderbolt/eeprom.c | 11 ----------- drivers/thunderbolt/switch.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-)
drivers/thunderbolt/eeprom.c +0 -11
@@ -514,17 +514,6 @@ int tb_drom_read(struct tb_switch *sw)* no entries). Hardcode the configuration here. */ tb_drom_read_uid_only (sw, &sw->uid); - - sw->ports[1 ].link_nr =0 ; - sw->ports[2 ].link_nr =1 ; - sw->ports[1 ].dual_link_port = &sw->ports[2 ]; - sw->ports[2 ].dual_link_port = &sw->ports[1 ]; - - sw->ports[3 ].link_nr =0 ; - sw->ports[4 ].link_nr =1 ; - sw->ports[3 ].dual_link_port = &sw->ports[4 ]; - sw->ports[4 ].dual_link_port = &sw->ports[3 ]; -return 0 ; }
drivers/thunderbolt/switch.c +32 -0
@@ -1926,6 +1926,36 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)return -ESHUTDOWN ; } +static void tb_switch_default_link_ports (struct tb_switch *sw) +{ +int i; + +for (i =1 ; i <= sw->config.max_port_number; i +=2 ) { +struct tb_port *port = &sw->ports[i]; +struct tb_port *subordinate; + +if (!tb_port_is_null (port)) +continue ; + +/* Check for the subordinate port */ +if (i == sw->config.max_port_number || + !tb_port_is_null (&sw->ports[i +1 ])) +continue ; + +/* Link them if not already done so (by DROM) */ + subordinate = &sw->ports[i +1 ]; +if (!port->dual_link_port && !subordinate->dual_link_port) { + port->link_nr =0 ; + port->dual_link_port = subordinate; + subordinate->link_nr =1 ; + subordinate->dual_link_port = port; + +tb_sw_dbg (sw,"linked ports %d <-> %d\n" , + port->port, subordinate->port); + } + } +} +static bool tb_switch_lane_bonding_possible (struct tb_switch *sw) {const struct tb_port *up =tb_upstream_port (sw);
@@ -2099,6 +2129,8 @@ int tb_switch_add(struct tb_switch *sw) } } +tb_switch_default_link_ports (sw); + ret =tb_switch_update_link_attributes (sw);if (ret)return ret;
Signature · 1 line
2.23.0
PATCH 12/25 thunderbolt: Expand controller name in tb_switch_is_xy()
In reply to Mika WesterbergFor a casual reader tb_switch_is_cr() does not tell much so instead spell out the full controller name in the function name. For example tb_switch_is_cr() becomes tb_switch_is_cactus_ridge() which is easier to understand.
--- drivers/thunderbolt/cap.c | 6 +++--- drivers/thunderbolt/tb.c | 4 ++-- drivers/thunderbolt/tb.h | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/thunderbolt/cap.c +3 -3
@@ -33,9 +33,9 @@ static int tb_port_enable_tmu(struct tb_port *port, bool enable)* Legacy devices need to have TMU access enabled before port * space can be fully accessed. */ -if (tb_switch_is_lr (sw)) +if (tb_switch_is_light_ridge (sw)) offset =0x26 ; -else if (tb_switch_is_er (sw)) +else if (tb_switch_is_eagle_ridge (sw)) offset =0x2a ;else return 0 ;
@@ -60,7 +60,7 @@ static void tb_port_dummy_read(struct tb_port *port)* reading stale data on next read perform one dummy read after * port capabilities are walked. */ -if (tb_switch_is_lr (port->sw)) { +if (tb_switch_is_light_ridge (port->sw)) {u32 dummy;tb_port_read (port, &dummy,TB_CFG_PORT ,0 ,1 );
drivers/thunderbolt/tb.c +2 -2
@@ -342,9 +342,9 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,* Hard-coded Thunderbolt port to PCIe down port mapping * per controller. */ -if (tb_switch_is_cr (sw)) +if (tb_switch_is_cactus_ridge (sw)) index = !phy_port ?6 :7 ; -else if (tb_switch_is_fr (sw)) +else if (tb_switch_is_falcon_ridge (sw)) index = !phy_port ?6 :8 ;else goto out;
drivers/thunderbolt/tb.h +4 -4
@@ -576,17 +576,17 @@ static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw)return tb_to_switch (sw->dev.parent); } -static inline bool tb_switch_is_lr (const struct tb_switch *sw) +static inline bool tb_switch_is_light_ridge (const struct tb_switch *sw) {return sw->config.device_id ==PCI_DEVICE_ID_INTEL_LIGHT_RIDGE ; } -static inline bool tb_switch_is_er (const struct tb_switch *sw) +static inline bool tb_switch_is_eagle_ridge (const struct tb_switch *sw) {return sw->config.device_id ==PCI_DEVICE_ID_INTEL_EAGLE_RIDGE ; } -static inline bool tb_switch_is_cr (const struct tb_switch *sw) +static inline bool tb_switch_is_cactus_ridge (const struct tb_switch *sw) {switch (sw->config.device_id) {case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C :
@@ -597,7 +597,7 @@ static inline bool tb_switch_is_cr(const struct tb_switch *sw) } } -static inline bool tb_switch_is_fr (const struct tb_switch *sw) +static inline bool tb_switch_is_falcon_ridge (const struct tb_switch *sw) {switch (sw->config.device_id) {case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE :
Signature · 1 line
2.23.0
PATCH 13/25 thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
In reply to Mika WesterbergIn order to keep PCIe hierarchies consistent across hotplugs, add hard-coded PCIe downstream port to Thunderbolt port for Alpine Ridge and Titan Ridge as well.
--- drivers/thunderbolt/tb.c | 5 ++++- drivers/thunderbolt/tb.h | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/thunderbolt/tb.c +4 -1
@@ -342,10 +342,13 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,* Hard-coded Thunderbolt port to PCIe down port mapping * per controller. */ -if (tb_switch_is_cactus_ridge (sw)) +if (tb_switch_is_cactus_ridge (sw) || +tb_switch_is_alpine_ridge (sw)) index = !phy_port ?6 :7 ;else if (tb_switch_is_falcon_ridge (sw)) index = !phy_port ?6 :8 ; +else if (tb_switch_is_titan_ridge (sw)) + index = !phy_port ?8 :9 ;else goto out;
drivers/thunderbolt/tb.h +25 -0
@@ -608,6 +608,31 @@ static inline bool tb_switch_is_falcon_ridge(const struct tb_switch *sw) } } +static inline bool tb_switch_is_alpine_ridge (const struct tb_switch *sw) +{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE : +return true; +default : +return false; + } +} + +static inline bool tb_switch_is_titan_ridge (const struct tb_switch *sw) +{ +switch (sw->config.device_id) { +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE : +return true; +default : +return false; + } +} +/** * tb_switch_is_icm() - Is the switch handled by ICM firmware * @sw: Switch to check
Signature · 1 line
2.23.0
PATCH 14/25 thunderbolt: Add Display Port CM handshake for Titan Ridge devices
In reply to Mika WesterbergTitan Ridge needs an additional connection manager handshake in order to do proper Display Port tunneling so implement it here.
--- drivers/thunderbolt/tb_regs.h | 3 +++ drivers/thunderbolt/tunnel.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
drivers/thunderbolt/tb_regs.h +3 -0
@@ -252,6 +252,9 @@ struct tb_regs_port_header {#define ADP_DP_CS_3_HDPC BIT(9)#define DP_LOCAL_CAP 0x04#define DP_REMOTE_CAP 0x05 +#define DP_STATUS_CTRL 0x06 +#define DP_STATUS_CTRL_CMHS BIT(25) +#define DP_STATUS_CTRL_UF BIT(26)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 15/25 thunderbolt: Add Display Port adapter pairing and resource management
In reply to Mika WesterbergTo perform proper Display Port tunneling for Thunderbolt 3 devices we need to allocate DP resources for DP IN port before they can be used. The reason for this is that the user can also connect a monitor directly to the Type-C ports in which case the Thunderbolt controller acts as re-driver for Display Port (no tunneling takes place) taking the DP sinks away from the connection manager. This allocation is done using special sink allocation registers available through the link controller.
We can pair DP IN to DP OUT only if
* DP IN has sink allocated via link controller
* DP OUT port receives hotplug event
For DP IN adapters (only for the host router) we first query whether there is DP resource available (it may be the previous instance of the driver for example already allocated it) and if it is we add it to the list. We then update the list when after each plug/unplug event to a DP IN/OUT adapter. Each time the list is updated we try to find additional DP IN <-> DP OUT pairs for tunnel establishment. This strategy also makes it possible to establish another tunnel in case there are 3 monitors connected and one gets unplugged releasing the DP IN adapter for the new tunnel.
--- drivers/thunderbolt/lc.c | 161 +++++++++++++++++++++++++++ drivers/thunderbolt/switch.c | 44 ++++++++ drivers/thunderbolt/tb.c | 201 ++++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 9 ++ drivers/thunderbolt/tb_regs.h | 6 + 5 files changed, 387 insertions(+), 34 deletions(-)
drivers/thunderbolt/lc.c +161 -0
@@ -205,3 +205,164 @@ bool tb_lc_lane_bonding_possible(struct tb_switch *sw)return !!(val &TB_LC_PORT_ATTR_BE ); } + +static int tb_lc_dp_sink_from_port (const struct tb_switch *sw, +struct tb_port *in) +{ +struct tb_port *port; + +/* The first DP IN port is sink 0 and second is sink 1 */ +tb_switch_for_each_port (sw, port) { +if (tb_port_is_dpin (port)) +return in != port; + } + +return -EINVAL ; +} + +static int tb_lc_dp_sink_available (struct tb_switch *sw,int sink) +{ +u32 val, alloc; +int ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +/* +* Sink is available for CM/SW to use if the allocation valie is +* either 0 or 1. +*/ +if (!sink) { + alloc = val &TB_LC_SNK_ALLOCATION_SNK0_MASK ; +if (!alloc || alloc ==TB_LC_SNK_ALLOCATION_SNK0_CM ) +return 0 ; + }else { + alloc = (val &TB_LC_SNK_ALLOCATION_SNK1_MASK ) >> +TB_LC_SNK_ALLOCATION_SNK1_SHIFT ; +if (!alloc || alloc ==TB_LC_SNK_ALLOCATION_SNK1_CM ) +return 0 ; + } + +return -EBUSY ; +} + +/** +* tb_lc_dp_sink_query() - Is DP sink available for DP IN port +* @sw: Switch whose DP sink is queried +* @in: DP IN port to check +* +* Queries through LC SNK_ALLOCATION registers whether DP sink is available +* for the given DP IN port or not. +*/ +bool tb_lc_dp_sink_query (struct tb_switch *sw,struct tb_port *in) +{ +int sink; + +/* +* For older generations sink is always available as there is no +* allocation mechanism. +*/ +if (sw->generation <3 ) +return true; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return false; + +return !tb_lc_dp_sink_available (sw, sink); +} + +/** +* tb_lc_dp_sink_alloc() - Allocate DP sink +* @sw: Switch whose DP sink is allocated +* @in: DP IN port the DP sink is allocated for +* +* Allocate DP sink for @in via LC SNK_ALLOCATION registers. If the +* resource is available and allocation is successful returns %0. In all +* other cases returs negative errno. In particular %-EBUSY is returned if +* the resource was not available. +*/ +int tb_lc_dp_sink_alloc (struct tb_switch *sw,struct tb_port *in) +{ +int ret, sink; +u32 val; + +if (sw->generation <3 ) +return 0 ; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return sink; + + ret =tb_lc_dp_sink_available (sw, sink); +if (ret) +return ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +if (!sink) { + val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK ; + val |=TB_LC_SNK_ALLOCATION_SNK0_CM ; + }else { + val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK ; + val |=TB_LC_SNK_ALLOCATION_SNK1_CM << +TB_LC_SNK_ALLOCATION_SNK1_SHIFT ; + } + + ret =tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); + +if (ret) +return ret; + +tb_port_dbg (in,"sink %d allocated\n" , sink); +return 0 ; +} + +/** +* tb_lc_dp_sink_dealloc() - De-allocate DP sink +* @sw: Switch whose DP sink is de-allocated +* @in: DP IN port whose DP sink is de-allocated +* +* De-allocate DP sink from @in using LC SNK_ALLOCATION registers. +*/ +int tb_lc_dp_sink_dealloc (struct tb_switch *sw,struct tb_port *in) +{ +int ret, sink; +u32 val; + +if (sw->generation <3 ) +return 0 ; + + sink =tb_lc_dp_sink_from_port (sw, in); +if (sink <0 ) +return sink; + +/* Needs to be owned by CM/SW */ + ret =tb_lc_dp_sink_available (sw, sink); +if (ret) +return ret; + + ret =tb_sw_read (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +if (!sink) + val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK ; +else + val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK ; + + ret =tb_sw_write (sw, &val,TB_CFG_SWITCH , + sw->cap_lc +TB_LC_SNK_ALLOCATION ,1 ); +if (ret) +return ret; + +tb_port_dbg (in,"sink %d de-allocated\n" , sink); +return 0 ; +}
drivers/thunderbolt/switch.c +44 -0
56 lines not on this page · raw message
drivers/thunderbolt/tb.c +167 -34
318 lines not on this page · raw message
drivers/thunderbolt/tb.h +9 -0
@@ -137,6 +137,7 @@ struct tb_switch {* @link_nr: Is this primary or secondary port on the dual_link. * @in_hopids: Currently allocated input HopIDs * @out_hopids: Currently allocated output HopIDs +* @list: Used to link ports to DP resources list */ struct tb_port {struct tb_regs_port_header config;
@@ -152,6 +153,7 @@ struct tb_port { u8 link_nr:1;struct ida in_hopids;struct ida out_hopids; +struct list_head list; };/**
@@ -650,6 +652,10 @@ static inline bool tb_switch_is_icm(const struct tb_switch *sw)int tb_switch_lane_bonding_enable (struct tb_switch *sw);void tb_switch_lane_bonding_disable (struct tb_switch *sw); +bool tb_switch_query_dp_resource (struct tb_switch *sw,struct tb_port *in); +int tb_switch_alloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +void tb_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +int tb_wait_for_port (struct tb_port *port,bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);
@@ -694,6 +700,9 @@ int tb_lc_configure_link(struct tb_switch *sw);void tb_lc_unconfigure_link (struct tb_switch *sw);int tb_lc_set_sleep (struct tb_switch *sw);bool tb_lc_lane_bonding_possible (struct tb_switch *sw); +bool tb_lc_dp_sink_query (struct tb_switch *sw,struct tb_port *in); +int tb_lc_dp_sink_alloc (struct tb_switch *sw,struct tb_port *in); +int tb_lc_dp_sink_dealloc (struct tb_switch *sw,struct tb_port *in);static inline int tb_route_length (u64 route) {
drivers/thunderbolt/tb_regs.h +6 -0
@@ -295,6 +295,12 @@ struct tb_regs_hop {#define TB_LC_DESC_PORT_SIZE_SHIFT 16#define TB_LC_DESC_PORT_SIZE_MASK GENMASK(27, 16)#define TB_LC_FUSE 0x03 +#define TB_LC_SNK_ALLOCATION 0x10 +#define TB_LC_SNK_ALLOCATION_SNK0_MASK GENMASK(3, 0) +#define TB_LC_SNK_ALLOCATION_SNK0_CM 0x1 +#define TB_LC_SNK_ALLOCATION_SNK1_SHIFT 4 +#define TB_LC_SNK_ALLOCATION_SNK1_MASK GENMASK(7, 4) +#define TB_LC_SNK_ALLOCATION_SNK1_CM 0x1/* Link controller registers */ #define TB_LC_PORT_ATTR 0x8d
Signature · 1 line
2.23.0
PATCH 16/25 thunderbolt: Add bandwidth management for Display Port tunnels
In reply to Mika WesterbergTitan Ridge supports Display Port 1.4 which adds HBR3 (High Bit Rate) rates that may be up to 8.1 Gb/s over 4 lanes. This translates to effective data bandwidth of 25.92 Gb/s (as 8/10 encoding is removed by the DP adapters when going over Thunderbolt fabric). If another high rate monitor is connected we may need to reduce the bandwidth it consumes so that it fits into the total 40 Gb/s available on the Thunderbolt fabric.
--- drivers/thunderbolt/path.c | 22 +++ drivers/thunderbolt/tb.c | 52 ++++++- drivers/thunderbolt/tb.h | 2 + drivers/thunderbolt/tb_regs.h | 17 ++ drivers/thunderbolt/tunnel.c | 282 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 10 +- 6 files changed, 381 insertions(+), 4 deletions(-)
drivers/thunderbolt/path.c +22 -0
@@ -557,3 +557,25 @@ bool tb_path_is_invalid(struct tb_path *path) }return false; } + +/** +* tb_path_switch_on_path() - Does the path go through certain switch +* @path: Path to check +* @sw: Switch to check +* +* Goes over all hops on path and checks if @sw is any of them. +* Direction does not matter. +*/ +bool tb_path_switch_on_path (const struct tb_path *path, +const struct tb_switch *sw) +{ +int i; + +for (i =0 ; i < path->path_length; i++) { +if (path->hops[i].in_port->sw == sw || + path->hops[i].out_port->sw == sw) +return true; + } + +return false; +}
drivers/thunderbolt/tb.c +51 -1
69 lines not on this page · raw message
drivers/thunderbolt/tb.h +2 -0
@@ -691,6 +691,8 @@ void tb_path_free(struct tb_path *path);int tb_path_activate (struct tb_path *path);void tb_path_deactivate (struct tb_path *path);bool tb_path_is_invalid (struct tb_path *path); +bool tb_path_switch_on_path (const struct tb_path *path, +const struct tb_switch *sw);int tb_drom_read (struct tb_switch *sw);int tb_drom_read_uid_only (struct tb_switch *sw,u64 *uid);
drivers/thunderbolt/tb_regs.h +17 -0
@@ -255,6 +255,23 @@ struct tb_regs_port_header {#define DP_STATUS_CTRL 0x06#define DP_STATUS_CTRL_CMHS BIT(25)#define DP_STATUS_CTRL_UF BIT(26) +#define DP_COMMON_CAP 0x07 +/* +* DP_COMMON_CAP offsets work also for DP_LOCAL_CAP and DP_REMOTE_CAP +* with exception of DPRX done. +*/ +#define DP_COMMON_CAP_RATE_MASK GENMASK(11, 8) +#define DP_COMMON_CAP_RATE_SHIFT 8 +#define DP_COMMON_CAP_RATE_RBR 0x0 +#define DP_COMMON_CAP_RATE_HBR 0x1 +#define DP_COMMON_CAP_RATE_HBR2 0x2 +#define DP_COMMON_CAP_RATE_HBR3 0x3 +#define DP_COMMON_CAP_LANES_MASK GENMASK(14, 12) +#define DP_COMMON_CAP_LANES_SHIFT 12 +#define DP_COMMON_CAP_1_LANE 0x0 +#define DP_COMMON_CAP_2_LANES 0x1 +#define DP_COMMON_CAP_4_LANES 0x2 +#define DP_COMMON_CAP_DPRX_DONE BIT(31)/* PCIe adapter registers */ #define ADP_PCIE_CS_0 0x00
drivers/thunderbolt/tunnel.c +280 -2
333 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +9 -1
@@ -27,8 +27,11 @@ enum tb_tunnel_type {* @npaths: Number of paths in @paths * @init: Optional tunnel specific initialization * @activate: Optional tunnel specific activation/deactivation +* @consumed_bandwidth: Return how much bandwidth the tunnel consumes * @list: Tunnels are linked using this field * @type: Type of the tunnel +* @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP). +* Only set if the bandwidth needs to be limited. */ struct tb_tunnel {struct tb *tb;
@@ -38,8 +41,10 @@ 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);struct list_head list;enum tb_tunnel_type type; +unsigned int max_bw; };struct tb_tunnel *tb_tunnel_discover_pci (struct tb *tb,struct tb_port *down);
@@ -47,7 +52,7 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up, struct tb_port *down);struct tb_tunnel *tb_tunnel_discover_dp (struct tb *tb,struct tb_port *in);struct tb_tunnel *tb_tunnel_alloc_dp (struct tb *tb,struct tb_port *in, -struct tb_port *out); +struct tb_port *out,int max_bw); struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, struct tb_port *dst, int transmit_ring, int transmit_path, int receive_ring,
@@ -58,6 +63,9 @@ int tb_tunnel_activate(struct tb_tunnel *tunnel);int tb_tunnel_restart (struct tb_tunnel *tunnel);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);static inline bool tb_tunnel_is_pci (const struct tb_tunnel *tunnel) {
Signature · 1 line
2.23.0
PATCH 17/25 thunderbolt: Do not start firmware unless asked by the user
In reply to Mika WesterbergSince now we can do pretty much the same thing in the software connection manager than the firmware would do, there is no point starting it by default. Instead we can just continue using the software connection manager.
Make it possible for user to switch between the two by adding a module pararameter (start_icm) which is by default false. Having this ability to enable the firmware may be useful at least when debugging possible issues with the software connection manager implementation.
--- drivers/thunderbolt/icm.c | 23 +++++++++++++++++++---- drivers/thunderbolt/tb.c | 4 ---- 2 files changed, 19 insertions(+), 8 deletions(-)
drivers/thunderbolt/icm.c +19 -4
@@ -11,6 +11,7 @@#include <linux/delay.h> #include <linux/mutex.h> +#include <linux/moduleparam.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/platform_data/x86/apple.h>
@@ -43,6 +44,10 @@#define ICM_APPROVE_TIMEOUT 10000/* ms */ #define ICM_MAX_LINK 4 +static bool start_icm; +module_param (start_icm, bool,0444 ); +MODULE_PARM_DESC (start_icm,"start ICM firmware if it is not running (default: false)" ); +/** * struct icm - Internal connection manager private data * @request_lock: Makes sure only one message is send to ICM at time
@@ -350,6 +355,14 @@ static void icm_veto_end(struct tb *tb) } } +static bool icm_firmware_running (const struct tb_nhi *nhi) +{ +u32 val; + + val =ioread32 (nhi->iobase +REG_FW_STS ); +return !!(val ®_FW_STS_ICM_EN ); +} +static bool icm_fr_is_supported (struct tb *tb) {return !x86_apple_machine;
@@ -1381,9 +1394,12 @@ static bool icm_ar_is_supported(struct tb *tb)/* * Starting from Alpine Ridge we can use ICM on Apple machines * as well. We just need to reset and re-enable it first. +* However, only start it if explicitly asked by the user. */ -if (!x86_apple_machine) +if (icm_firmware_running (tb->nhi))return true; +if (!start_icm) +return false;/* * Find the upstream PCIe port in case we need to do reset
@@ -1736,8 +1752,7 @@ static int icm_firmware_start(struct tb *tb, struct tb_nhi *nhi)u32 val;/* Check if the ICM firmware is already running */ - val =ioread32 (nhi->iobase +REG_FW_STS ); -if (val ®_FW_STS_ICM_EN ) +if (icm_firmware_running (nhi))return 0 ;dev_dbg (&nhi->pdev->dev,"starting ICM firmware\n" );
@@ -2244,7 +2259,7 @@ struct tb *icm_probe(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_ICL_NHI0 :case PCI_DEVICE_ID_INTEL_ICL_NHI1 : - icm->is_supported = icm_ar_is_supported; + icm->is_supported = icm_fr_is_supported; icm->driver_ready = icm_icl_driver_ready; icm->set_uuid = icm_icl_set_uuid; icm->device_connected = icm_icl_device_connected;
drivers/thunderbolt/tb.c +0 -4
@@ -9,7 +9,6 @@#include <linux/slab.h> #include <linux/errno.h> #include <linux/delay.h> -#include <linux/platform_data/x86/apple.h> #include "tb.h" #include "tb_regs.h"
@@ -990,9 +989,6 @@ struct tb *tb_probe(struct tb_nhi *nhi)struct tb_cm *tcm;struct tb *tb; -if (!x86_apple_machine) -return NULL ; - tb =tb_domain_alloc (nhi,sizeof (*tcm));if (!tb)return NULL ;
Signature · 1 line
2.23.0
PATCH 18/25 thunderbolt: Make tb_find_port() available to other files
In reply to Mika WesterbergWe will be needing this when adding initial USB4 support so make it available to other files in the driver as well. We also rename it to tb_switch_find_port() to follow conventions used in switch.c.
No functional changes.
--- drivers/thunderbolt/switch.c | 18 ++++++++++++++++++ drivers/thunderbolt/tb.c | 22 ++-------------------- drivers/thunderbolt/tb.h | 2 ++ 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/thunderbolt/switch.c +18 -0
@@ -2477,6 +2477,24 @@ struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route)return NULL ; } +/** +* tb_switch_find_port() - return the first port of @type on @sw or NULL +* @sw: Switch to find the port from +* @type: Port type to look for +*/ +struct tb_port *tb_switch_find_port (struct tb_switch *sw, +enum tb_port_type type) +{ +struct tb_port *port; + +tb_switch_for_each_port (sw, port) { +if (port->config.type == type) +return port; + } + +return NULL ; +} +void tb_switch_exit (void ) {ida_destroy (&nvm_ida);
drivers/thunderbolt/tb.c +2 -20
@@ -338,24 +338,6 @@ static void tb_free_unplugged_children(struct tb_switch *sw) } } -/** -* tb_find_port() - return the first port of @type on @sw or NULL -* @sw: Switch to find the port from -* @type: Port type to look for -*/ -static struct tb_port *tb_find_port (struct tb_switch *sw, -enum tb_port_type type) -{ -struct tb_port *port; - -tb_switch_for_each_port (sw, port) { -if (port->config.type == type) -return port; - } - -return NULL ; -} -/** * tb_find_unused_port() - return the first inactive port on @sw * @sw: Switch to find the port on
@@ -586,7 +568,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)struct tb_switch *parent_sw;struct tb_tunnel *tunnel; - up =tb_find_port (sw,TB_TYPE_PCIE_UP ); + up =tb_switch_find_port (sw,TB_TYPE_PCIE_UP );if (!up)return 0 ;
@@ -624,7 +606,7 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd) sw =tb_to_switch (xd->dev.parent); dst_port =tb_port_at (xd->route, sw); - nhi_port =tb_find_port (tb->root_switch,TB_TYPE_NHI ); + nhi_port =tb_switch_find_port (tb->root_switch,TB_TYPE_NHI );mutex_lock (&tb->lock); tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, xd->transmit_ring,
drivers/thunderbolt/tb.h +2 -0
@@ -533,6 +533,8 @@ void tb_switch_suspend(struct tb_switch *sw);int tb_switch_resume (struct tb_switch *sw);int tb_switch_reset (struct tb *tb,u64 route);void tb_sw_set_unplugged (struct tb_switch *sw); +struct tb_port *tb_switch_find_port (struct tb_switch *sw, +enum tb_port_type type);struct tb_switch *tb_switch_find_by_link_depth (struct tb *tb,u8 link,u8 depth);struct tb_switch *tb_switch_find_by_uuid (struct tb *tb,const uuid_t *uuid);
Signature · 1 line
2.23.0
PATCH 19/25 thunderbolt: Call tb_eeprom_get_drom_offset() from tb_eeprom_read_n()
In reply to Mika WesterbergWe are going to re-use tb_drom_read() for USB4 DROM reading as well. USB4 has separate router operations for this which does not need the drom_offset. Therefore we move call to tb_eeprom_get_drom_offset() into tb_eeprom_read_n() where it is needed.
While there change return -ENOSYS to -ENODEV because the former is only supposed to be used with system calls (invalid syscall nr).
--- drivers/thunderbolt/eeprom.c | 88 ++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 45 deletions(-)
drivers/thunderbolt/eeprom.c +43 -45
@@ -130,13 +130,52 @@ static int tb_eeprom_in(struct tb_switch *sw, u8 *val)return 0 ; } +/** +* tb_eeprom_get_drom_offset - get drom offset within eeprom +*/ +static int tb_eeprom_get_drom_offset (struct tb_switch *sw,u16 *offset) +{ +struct tb_cap_plug_events cap; +int res; + +if (!sw->cap_plug_events) { +tb_sw_warn (sw,"no TB_CAP_PLUG_EVENTS, cannot read eeprom\n" ); +return -ENODEV ; + } + res =tb_sw_read (sw, &cap,TB_CFG_SWITCH , sw->cap_plug_events, +sizeof (cap) /4 ); +if (res) +return res; + +if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) { +tb_sw_warn (sw,"no NVM\n" ); +return -ENODEV ; + } + +if (cap.drom_offset >0xffff ) { +tb_sw_warn (sw,"drom offset is larger than 0xffff: %#x\n" , + cap.drom_offset); +return -ENXIO ; + } + *offset = cap.drom_offset; +return 0 ; +} +/** * tb_eeprom_read_n - read count bytes from offset into val */ static int tb_eeprom_read_n (struct tb_switch *sw,u16 offset,u8 *val,size_t count) { +u16 drom_offset;int i, res; + + res =tb_eeprom_get_drom_offset (sw, &drom_offset); +if (res) +return res; + + offset += drom_offset; + res =tb_eeprom_active (sw, true);if (res)return res;
@@ -238,36 +277,6 @@ struct tb_drom_entry_port { } __packed; -/** -* tb_eeprom_get_drom_offset - get drom offset within eeprom -*/ -static int tb_eeprom_get_drom_offset (struct tb_switch *sw,u16 *offset) -{ -struct tb_cap_plug_events cap; -int res; -if (!sw->cap_plug_events) { -tb_sw_warn (sw,"no TB_CAP_PLUG_EVENTS, cannot read eeprom\n" ); -return -ENOSYS ; - } - res =tb_sw_read (sw, &cap,TB_CFG_SWITCH , sw->cap_plug_events, -sizeof (cap) /4 ); -if (res) -return res; - -if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) { -tb_sw_warn (sw,"no NVM\n" ); -return -ENOSYS ; - } - -if (cap.drom_offset >0xffff ) { -tb_sw_warn (sw,"drom offset is larger than 0xffff: %#x\n" , - cap.drom_offset); -return -ENXIO ; - } - *offset = cap.drom_offset; -return 0 ; -} -/** * tb_drom_read_uid_only - read uid directly from drom *
@@ -277,17 +286,11 @@ static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)int tb_drom_read_uid_only (struct tb_switch *sw,u64 *uid) {u8 data[9 ]; -u16 drom_offset;u8 crc; -int res =tb_eeprom_get_drom_offset (sw, &drom_offset); -if (res) -return res; - -if (drom_offset ==0 ) -return -ENODEV ; +int res;/* read uid */ - res =tb_eeprom_read_n (sw, drom_offset, data,9 ); + res =tb_eeprom_read_n (sw,0 , data,9 );if (res)return res;
@@ -489,7 +492,6 @@ static int tb_drom_copy_nvm(struct tb_switch *sw, u16 *size)*/ int tb_drom_read (struct tb_switch *sw) { -u16 drom_offset;u16 size;u32 crc;struct tb_drom_header *header;
@@ -517,11 +519,7 @@ int tb_drom_read(struct tb_switch *sw)return 0 ; } - res =tb_eeprom_get_drom_offset (sw, &drom_offset); -if (res) -return res; - - res =tb_eeprom_read_n (sw, drom_offset +14 , (u8 *) &size,2 ); + res =tb_eeprom_read_n (sw,14 , (u8 *) &size,2 );if (res)return res; size &=0x3ff ;
@@ -535,7 +533,7 @@ int tb_drom_read(struct tb_switch *sw) sw->drom =kzalloc (size,GFP_KERNEL );if (!sw->drom)return -ENOMEM ; - res =tb_eeprom_read_n (sw, drom_offset, sw->drom, size); + res =tb_eeprom_read_n (sw,0 , sw->drom, size);if (res) goto err;
Signature · 1 line
2.23.0
PATCH 20/25 thunderbolt: Add initial support for USB4
In reply to Mika WesterbergUSB4 is a public spec based on Thunderbolt protocol. There are some differences in register layouts and flows. In addition to PCIe and DP tunneling, USB4 supports tunneling of USB 3.x. USB4 is also backward compatible with Thunderbolt 3 (and older generations but the spec only talks about 3rd generation). USB4 compliant devices can be identified by checking USB4 version field in router configuration space.
This patch adds initial support for USB4 compliant hosts and devices which enables following features provided by the existing functionality in the driver:
- PCIe tunneling
- Display Port tunneling
- Host and device NVM firmware upgrade
- P2P networking
This brings the USB4 support to the same level that we already have for Thunderbolt 1, 2 and 3 devices.
Note the spec talks about host and device "routers" but in the driver we still use term "switch" in most places. Both can be used interchangeably.
--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/eeprom.c | 53 ++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/switch.c | 384 +++++++++++++----- drivers/thunderbolt/tb.c | 20 +- drivers/thunderbolt/tb.h | 36 ++ drivers/thunderbolt/tb_regs.h | 36 +- drivers/thunderbolt/tunnel.c | 11 +- drivers/thunderbolt/usb4.c | 723 ++++++++++++++++++++++++++++++++++ drivers/thunderbolt/xdomain.c | 6 + 11 files changed, 1158 insertions(+), 118 deletions(-) create mode 100644 drivers/thunderbolt/usb4.c
drivers/thunderbolt/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-${CONFIG_THUNDERBOLT} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o
drivers/thunderbolt/eeprom.c +48 -5
75 lines not on this page · raw message
drivers/thunderbolt/nhi.c +3 -0
@@ -1271,6 +1271,9 @@ static struct pci_device_id nhi_ids[] = { { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_ICL_NHI1), .driver_data = (kernel_ulong_t)&icl_nhi_ops }, +/* Any USB4 compliant host */ + { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_USB4, ~0) }, + { 0,} };
drivers/thunderbolt/nhi.h +2 -0
@@ -74,4 +74,6 @@ extern const struct tb_nhi_ops icl_nhi_ops;#define PCI_DEVICE_ID_INTEL_ICL_NHI1 0x8a0d#define PCI_DEVICE_ID_INTEL_ICL_NHI0 0x8a17 +#define PCI_CLASS_SERIAL_USB_USB4 0x0c0340 +#endif
drivers/thunderbolt/switch.c +282 -102
611 lines not on this page · raw message
drivers/thunderbolt/tb.c +14 -6
@@ -365,12 +365,15 @@ static struct tb_port *tb_find_unused_port(struct tb_switch *sw,static struct tb_port *tb_find_pcie_down (struct tb_switch *sw,const struct tb_port *port) { +struct tb_port *down =NULL ; +/* * To keep plugging devices consistently in the same PCIe -* hierarchy, do mapping here for root switch downstream PCIe -* ports. +* hierarchy, do mapping here for switch downstream PCIe ports. */ -if (!tb_route (sw)) { +if (tb_switch_is_usb4 (sw)) { + down =usb4_switch_map_pcie_down (sw, port); + }else if (!tb_route (sw)) {int phy_port =tb_phy_port_from_link (port->port);int index;
@@ -391,12 +394,17 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,/* Validate the hard-coding */ if (WARN_ON (index > sw->config.max_port_number)) goto out; -if (WARN_ON (!tb_port_is_pcie_down (&sw->ports[index]))) + + down = &sw->ports[index]; + } + +if (down) { +if (WARN_ON (!tb_port_is_pcie_down (down))) goto out; -if (WARN_ON (tb_pci_port_is_enabled (&sw->ports[index]))) +if (WARN_ON (tb_pci_port_is_enabled (down))) goto out; -return &sw->ports[index]; +return down; } out:
drivers/thunderbolt/tb.h +36 -0
@@ -44,6 +44,7 @@ struct tb_switch_nvm {#define TB_SWITCH_KEY_SIZE 32#define TB_SWITCH_MAX_DEPTH 6 +#define USB4_SWITCH_MAX_DEPTH 5/** * struct tb_switch - a thunderbolt switch
@@ -129,6 +130,7 @@ struct tb_switch {* @xdomain: Remote host (%NULL if not connected) * @cap_phy: Offset, zero if not found * @cap_adap: Offset of the adapter specific capability (%0 if not present) +* @cap_usb4: Offset to the USB4 port capability (%0 if not present) * @port: Port number on switch * @disabled: Disabled by eeprom * @bonded: true if the port is bonded (two lanes combined as one)
@@ -146,6 +148,7 @@ struct tb_port {struct tb_xdomain *xdomain;int cap_phy;int cap_adap; +int cap_usb4;u8 port;bool disabled;bool bonded;
@@ -637,6 +640,17 @@ static inline bool tb_switch_is_titan_ridge(const struct tb_switch *sw) } } +/** +* tb_switch_is_usb4() - Is the switch USB4 compliant +* @sw: Switch to check +* +* Returns true if the @sw is USB4 compliant router, false otherwise. +*/ +static inline bool tb_switch_is_usb4 (const struct tb_switch *sw) +{ +return sw->config.thunderbolt_version ==USB4_VERSION_1_0 ; +} +/** * tb_switch_is_icm() - Is the switch handled by ICM firmware * @sw: Switch to check
@@ -662,6 +676,7 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);int tb_port_add_nfc_credits (struct tb_port *port,int credits);int tb_port_set_initial_credits (struct tb_port *port,u32 credits);int tb_port_clear_counter (struct tb_port *port,int counter); +int tb_port_unlock (struct tb_port *port);int tb_port_alloc_in_hopid (struct tb_port *port,int hopid,int max_hopid);void tb_port_release_in_hopid (struct tb_port *port,int hopid);int tb_port_alloc_out_hopid (struct tb_port *port,int hopid,int max_hopid);
@@ -736,4 +751,25 @@ void tb_xdomain_remove(struct tb_xdomain *xd);struct tb_xdomain *tb_xdomain_find_by_link_depth (struct tb *tb,u8 link,u8 depth); +int usb4_switch_setup (struct tb_switch *sw); +int usb4_switch_read_uid (struct tb_switch *sw,u64 *uid); +int usb4_switch_drom_read (struct tb_switch *sw,unsigned int address,void *buf, +size_t size); +int usb4_switch_configure_link (struct tb_switch *sw); +void usb4_switch_unconfigure_link (struct tb_switch *sw); +bool usb4_switch_lane_bonding_possible (struct tb_switch *sw); +int usb4_switch_set_sleep (struct tb_switch *sw); +int usb4_switch_nvm_sector_size (struct tb_switch *sw); +int usb4_switch_nvm_read (struct tb_switch *sw,unsigned int address,void *buf, +size_t size); +int usb4_switch_nvm_write (struct tb_switch *sw,unsigned int address, +const void *buf,size_t size); +int usb4_switch_nvm_authenticate (struct tb_switch *sw); +bool usb4_switch_query_dp_resource (struct tb_switch *sw,struct tb_port *in); +int usb4_switch_alloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +int usb4_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in); +struct tb_port *usb4_switch_map_pcie_down (struct tb_switch *sw, +const struct tb_port *port); + +int usb4_port_unlock (struct tb_port *port);#endif
drivers/thunderbolt/tb_regs.h +35 -1
@@ -41,6 +41,7 @@ enum tb_port_cap {TB_PORT_CAP_TIME1 =0x03 ,TB_PORT_CAP_ADAP =0x04 ,TB_PORT_CAP_VSE =0x05 , + TB_PORT_CAP_USB4 = 0x06, }; enum tb_port_state {
@@ -164,10 +165,36 @@ struct tb_regs_switch_header {* milliseconds. Writing 0x00 is interpreted * as 255ms. */ - u32 __unknown4:16; + u32 cmuv:8; + u32 __unknown4:8; u32 thunderbolt_version:8; } __packed; +/* USB4 version 1.0 */ +#define USB4_VERSION_1_0 0x20 + +#define ROUTER_CS_1 0x01 +#define ROUTER_CS_4 0x04 +#define ROUTER_CS_5 0x05 +#define ROUTER_CS_5_SLP BIT(0) +#define ROUTER_CS_5_C3S BIT(23) +#define ROUTER_CS_5_PTO BIT(24) +#define ROUTER_CS_5_HCO BIT(26) +#define ROUTER_CS_5_CV BIT(31) +#define ROUTER_CS_6 0x06 +#define ROUTER_CS_6_SLPR BIT(0) +#define ROUTER_CS_6_TNS BIT(1) +#define ROUTER_CS_6_HCI BIT(18) +#define ROUTER_CS_6_CR BIT(25) +#define ROUTER_CS_7 0x07 +#define ROUTER_CS_9 0x09 +#define ROUTER_CS_25 0x19 +#define ROUTER_CS_26 0x1a +#define ROUTER_CS_26_STATUS_MASK GENMASK(29, 24) +#define ROUTER_CS_26_STATUS_SHIFT 24 +#define ROUTER_CS_26_ONS BIT(30) +#define ROUTER_CS_26_OV BIT(31) +enum tb_port_type {TB_TYPE_INACTIVE =0x000000 ,TB_TYPE_PORT =0x000001 ,
@@ -216,6 +243,7 @@ struct tb_regs_port_header {#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0)#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20)#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20 +#define ADP_CS_4_LCK BIT(31)#define ADP_CS_5 0x05#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22
@@ -237,6 +265,12 @@ struct tb_regs_port_header {#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20)#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20 +/* USB4 port registers */ +#define PORT_CS_18 0x12 +#define PORT_CS_18_BE BIT(8) +#define PORT_CS_19 0x13 +#define PORT_CS_19_PC BIT(3) +/* Display Port adapter registers */ #define ADP_DP_CS_0 0x00#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16)
drivers/thunderbolt/tunnel.c +8 -3
@@ -243,6 +243,12 @@ struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,return tunnel; } +static bool tb_dp_is_usb4 (const struct tb_switch *sw) +{ +/* Titan Ridge DP adapters need the same treatment as USB4 */ +return tb_switch_is_usb4 (sw) ||tb_switch_is_titan_ridge (sw); +} +static int tb_dp_cm_handshake (struct tb_port *in,struct tb_port *out) {int timeout =10 ;
@@ -250,8 +256,7 @@ static int tb_dp_cm_handshake(struct tb_port *in, struct tb_port *out)int ret;/* Both ends need to support this */ -if (!tb_switch_is_titan_ridge (in->sw) || - !tb_switch_is_titan_ridge (out->sw)) +if (!tb_dp_is_usb4 (in->sw) || !tb_dp_is_usb4 (out->sw))return 0 ; ret = tb_port_read(out, &val, TB_CFG_PORT,
@@ -531,7 +536,7 @@ static int tb_dp_consumed_bandwidth(struct tb_tunnel *tunnel)u32 val, rate =0 , lanes =0 ;int ret; -if (tb_switch_is_titan_ridge (sw)) { +if (tb_dp_is_usb4 (sw)) {int timeout =10 ;/*
drivers/thunderbolt/usb4.c new file +723 -0
723 lines not on this page · raw message
drivers/thunderbolt/xdomain.c +6 -0
@@ -1220,7 +1220,13 @@ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent, u64 route, const uuid_t *local_uuid, const uuid_t *remote_uuid) { + struct tb_switch *parent_sw = tb_to_switch(parent);struct tb_xdomain *xd; +struct tb_port *down; + +/* Make sure the downstream domain is accessible */ + down =tb_port_at (route, parent_sw); +tb_port_unlock (down); xd =kzalloc (sizeof (*xd),GFP_KERNEL );if (!xd)
Signature · 1 line
2.23.0
PATCH 21/25 thunderbolt: Update Kconfig entry to USB4
In reply to Mika WesterbergSince the driver now supports USB4 which is the standard going forward, update the Kconfig entry to mention this and rename the entry from CONFIG_THUNDERBOLT to CONFIG_USB4 instead to help people to find the correct option if they want to enable USB4.
Also update Thunderbolt network driver dependency accordingly.
--- drivers/Makefile | 2 +- drivers/net/Kconfig | 2 +- drivers/thunderbolt/Kconfig | 11 ++++++----- drivers/thunderbolt/Makefile | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-)
drivers/Makefile +1 -1
@@ -171,7 +171,7 @@ obj-$(CONFIG_POWERCAP) += powercap/ obj-$(CONFIG_MCB) += mcb/ obj-$(CONFIG_PERF_EVENTS) += perf/ obj-$(CONFIG_RAS) += ras/ -obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ +obj-$(CONFIG_USB4) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-y += hwtracing/intel_th/ obj-$(CONFIG_STM) += hwtracing/stm/
drivers/net/Kconfig +1 -1
@@ -491,7 +491,7 @@ config FUJITSU_ES config THUNDERBOLT_NET tristate "Networking over Thunderbolt cable" - depends on THUNDERBOLT && INET + depends on USB4 && INET help Select this if you want to create network between two computers over a Thunderbolt cable. The driver supports Apple
drivers/thunderbolt/Kconfig +6 -5
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -menuconfig THUNDERBOLT - tristate "Thunderbolt support" +menuconfig USB4 + tristate "Unified support for USB4 and Thunderbolt" depends on PCI depends on X86 || COMPILE_TEST select APPLE_PROPERTIES if EFI_STUB && X86
@@ -9,9 +9,10 @@ menuconfig THUNDERBOLT select CRYPTO_HASH select NVMEM help - Thunderbolt Controller driver. This driver is required if you - want to hotplug Thunderbolt devices on Apple hardware or on PCs - with Intel Falcon Ridge or newer. + USB4/Thunderbolt driver. USB4 is the public spec based on + Thunderbolt 3 protocol. This driver is required if you want to + hotplug Thunderbolt and USB4 compliant devices on Apple hardware + or on PCs with Intel Falcon Ridge or newer. To compile this driver a module, choose M here. The module will be called thunderbolt.
drivers/thunderbolt/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-${CONFIG_THUNDERBOLT} := thunderbolt.o +obj-${CONFIG_USB4} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o
Signature · 1 line
2.23.0
PATCH 22/25 thunderbolt: Make tb_switch_find_cap() available to other files
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
We need to find switch capabilities in order to implement TMU support so make it available to other files as well.
--- drivers/thunderbolt/cap.c | 11 ++++++++++- drivers/thunderbolt/tb.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/thunderbolt/cap.c +10 -1
@@ -113,7 +113,16 @@ int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap)return ret; } -static int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap) +/** +* tb_switch_find_cap() - Find switch capability +* @sw Switch to find the capability for +* @cap: Capability to look +* +* Returns offset to start of capability or %-ENOENT if no such +* capability was found. Negative errno is returned if there was an +* error. +*/ +int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap) {int offset = sw->config.first_cap_offset;
drivers/thunderbolt/tb.h +1 -0
@@ -685,6 +685,7 @@ struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, struct tb_port *prev);int tb_switch_find_vse_cap (struct tb_switch *sw,enum tb_switch_vse_cap vsec); +int tb_switch_find_cap (struct tb_switch *sw,enum tb_switch_cap cap);int tb_port_find_cap (struct tb_port *port,enum tb_port_cap cap);bool tb_port_is_enabled (struct tb_port *port);
Signature · 1 line
2.23.0
PATCH 23/25 thunderbolt: Add support for Time Management Unit
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
Time Management Unit (TMU) is included in each USB4 router. It is used to synchronize time across the USB4 fabric. By default when USB4 router is plugged to the domain, its TMU is turned off. This differs from Thunderbolt (1, 2 and 3) devices whose TMU is by default configured to bi-directional HiFi mode. Since time synchronization is needed for proper Display Port tunneling this means we need to configure the TMU on USB4 compliant devices.
The USB4 spec allows some flexibility on how the TMU can be configured. This makes it possible to enable link power management states (CLx) in certain topologies, where for example DP tunneling is not used. TMU can also be re-configured dynamicaly depending on types of tunnels created over the USB4 fabric.
In this patch we simply configure the TMU to be in bi-directional HiFi mode. This way we can tunnel any kind of traffic without need to perform complex steps to re-configure the domain dynamically. We can add more fine-grained TMU configuration later on when we start enabling CLx states.
--- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/switch.c | 4 + drivers/thunderbolt/tb.c | 28 +++ drivers/thunderbolt/tb.h | 47 +++++ drivers/thunderbolt/tb_regs.h | 20 ++ drivers/thunderbolt/tmu.c | 383 ++++++++++++++++++++++++++++++++++ 6 files changed, 483 insertions(+), 1 deletion(-) create mode 100644 drivers/thunderbolt/tmu.c
drivers/thunderbolt/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-${CONFIG_USB4} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o -thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o usb4.o +thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
drivers/thunderbolt/switch.c +4 -0
@@ -2298,6 +2298,10 @@ int tb_switch_add(struct tb_switch *sw) ret =tb_switch_update_link_attributes (sw);if (ret)return ret; + + ret =tb_switch_tmu_init (sw); +if (ret) +return ret; } ret =device_add (&sw->dev);
drivers/thunderbolt/tb.c +28 -0
@@ -158,6 +158,25 @@ static void tb_scan_xdomain(struct tb_port *port) } } +static int tb_enable_tmu (struct tb_switch *sw) +{ +int ret; + +/* If it is already enabled in correct mode, don't touch it */ +if (tb_switch_tmu_is_enabled (sw)) +return 0 ; + + ret =tb_switch_tmu_disable (sw); +if (ret) +return ret; + + ret =tb_switch_tmu_post_time (sw); +if (ret) +return ret; + +return tb_switch_tmu_enable (sw); +} +static void tb_scan_port (struct tb_port *port);/**
@@ -257,6 +276,9 @@ static void tb_scan_port(struct tb_port *port)if (tb_switch_lane_bonding_enable (sw))tb_sw_warn (sw,"failed to enable lane bonding\n" ); +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to enable TMU\n" ); +tb_scan_switch (sw); }
@@ -709,6 +731,7 @@ static void tb_handle_hotplug(struct work_struct *work)tb_sw_set_unplugged (port->remote->sw);tb_free_invalid_tunnels (tb);tb_remove_dp_resources (port->remote->sw); +tb_switch_tmu_disable (port->remote->sw);tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw); port->remote =NULL ;
@@ -856,6 +879,8 @@ static int tb_start(struct tb *tb)return ret; } +/* Enable TMU if it is off */ +tb_switch_tmu_enable (tb->root_switch);/* Full scan to discover devices added before the driver was loaded. */ tb_scan_switch (tb->root_switch);/* Find out tunnels created by the boot firmware */
@@ -887,6 +912,9 @@ static void tb_restore_children(struct tb_switch *sw) {struct tb_port *port; +if (tb_enable_tmu (sw)) +tb_sw_warn (sw,"failed to restore TMU configuration\n" ); +tb_switch_for_each_port (sw, port) {if (!tb_port_has_remote (port))continue ;
drivers/thunderbolt/tb.h +47 -0
83 lines not on this page · raw message
drivers/thunderbolt/tb_regs.h +20 -0
@@ -26,6 +26,7 @@#define TB_MAX_CONFIG_RW_LENGTH 60enum tb_switch_cap { +TB_SWITCH_CAP_TMU =0x03 ,TB_SWITCH_CAP_VSE =0x05 , };
@@ -195,6 +196,21 @@ struct tb_regs_switch_header {#define ROUTER_CS_26_ONS BIT(30)#define ROUTER_CS_26_OV BIT(31) +/* Router TMU configuration */ +#define TMU_RTR_CS_0 0x00 +#define TMU_RTR_CS_0_TD BIT(27) +#define TMU_RTR_CS_0_UCAP BIT(30) +#define TMU_RTR_CS_1 0x01 +#define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16) +#define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16 +#define TMU_RTR_CS_2 0x02 +#define TMU_RTR_CS_3 0x03 +#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16) +#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16 +#define TMU_RTR_CS_22 0x16 +#define TMU_RTR_CS_24 0x18 +enum tb_port_type {TB_TYPE_INACTIVE =0x000000 ,TB_TYPE_PORT =0x000001 ,
@@ -248,6 +264,10 @@ struct tb_regs_port_header {#define ADP_CS_5_LCA_MASK GENMASK(28, 22)#define ADP_CS_5_LCA_SHIFT 22 +/* TMU adapter registers */ +#define TMU_ADP_CS_3 0x03 +#define TMU_ADP_CS_3_UDM BIT(29) +/* Lane adapter registers */ #define LANE_ADP_CS_0 0x00#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)
drivers/thunderbolt/tmu.c new file +383 -0
383 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 24/25 thunderbolt: Add support for USB 3.x tunnels
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
USB4 added a capability to tunnel USB 3.x protocol over the USB4 fabric. USB4 device routers may include integrated SuperSpeed HUB or a function or both. USB tunneling follows PCIe so that the tunnel is created between the parent and the child router from USB3 downstream adapter port to USB3 upstream adapter port over a single USB4 link.
This adds support for USB 3.x tunneling and also capability to discover existing USB 3.x tunnels (for example created by connection manager in boot firmware).
--- drivers/thunderbolt/switch.c | 35 ++++++++ drivers/thunderbolt/tb.c | 154 +++++++++++++++++++++++++++------ drivers/thunderbolt/tb.h | 15 ++++ drivers/thunderbolt/tb_regs.h | 9 +- drivers/thunderbolt/tunnel.c | 158 +++++++++++++++++++++++++++++++++- drivers/thunderbolt/tunnel.h | 9 ++ drivers/thunderbolt/usb4.c | 42 ++++++++- 7 files changed, 395 insertions(+), 27 deletions(-)
drivers/thunderbolt/switch.c +35 -0
@@ -1025,11 +1025,46 @@ bool tb_port_is_enabled(struct tb_port *port)case TB_TYPE_DP_HDMI_OUT :return tb_dp_port_is_enabled (port); +case TB_TYPE_USB3_UP : +case TB_TYPE_USB3_DOWN : +return tb_usb3_port_is_enabled (port); +default :return false; } } +/** +* tb_usb3_port_is_enabled() - Is the USB3 adapter port enabled +* @port: USB3 adapter port to check +*/ +bool tb_usb3_port_is_enabled (struct tb_port *port) +{ +u32 data; + +if (tb_port_read (port, &data,TB_CFG_PORT , + port->cap_adap +ADP_USB3_CS_0 ,1 )) +return false; + +return !!(data &ADP_USB3_CS_0_PE ); +} + +/** +* tb_usb3_port_enable() - Enable USB3 adapter port +* @port: USB3 adapter port to enable +* @enable: Enable/disable the USB3 adapter +*/ +int tb_usb3_port_enable (struct tb_port *port,bool enable) +{ +u32 word = enable ? (ADP_USB3_CS_0_PE |ADP_USB3_CS_0_V ) + :ADP_USB3_CS_0_V ; + +if (!port->cap_adap) +return -ENXIO ; +return tb_port_write (port, &word,TB_CFG_PORT , + port->cap_adap +ADP_USB3_CS_0 ,1 ); +} +/** * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled * @port: PCIe port to check
drivers/thunderbolt/tb.c +130 -24
184 lines not on this page · raw message
drivers/thunderbolt/tb.h +15 -0
@@ -432,6 +432,16 @@ static inline bool tb_port_is_dpout(const struct tb_port *port)return port && port->config.type ==TB_TYPE_DP_HDMI_OUT ; } +static inline bool tb_port_is_usb3_down (const struct tb_port *port) +{ +return port && port->config.type ==TB_TYPE_USB3_DOWN ; +} + +static inline bool tb_port_is_usb3_up (const struct tb_port *port) +{ +return port && port->config.type ==TB_TYPE_USB3_UP ; +} +static inline int tb_sw_read (struct tb_switch *sw,void *buffer,enum tb_cfg_space space,u32 offset,u32 length) {
@@ -736,6 +746,9 @@ int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);int tb_port_find_cap (struct tb_port *port,enum tb_port_cap cap);bool tb_port_is_enabled (struct tb_port *port); +bool tb_usb3_port_is_enabled (struct tb_port *port); +int tb_usb3_port_enable (struct tb_port *port,bool enable); +bool tb_pci_port_is_enabled (struct tb_port *port);int tb_pci_port_enable (struct tb_port *port,bool enable);
@@ -818,6 +831,8 @@ int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);int usb4_switch_dealloc_dp_resource (struct tb_switch *sw,struct tb_port *in);struct tb_port *usb4_switch_map_pcie_down (struct tb_switch *sw,const struct tb_port *port); +struct tb_port *usb4_switch_map_usb3_down (struct tb_switch *sw, +const struct tb_port *port);int usb4_port_unlock (struct tb_port *port);#endif
drivers/thunderbolt/tb_regs.h +8 -1
@@ -180,6 +180,7 @@ struct tb_regs_switch_header {#define ROUTER_CS_5_SLP BIT(0)#define ROUTER_CS_5_C3S BIT(23)#define ROUTER_CS_5_PTO BIT(24) +#define ROUTER_CS_5_UTO BIT(25)#define ROUTER_CS_5_HCO BIT(26)#define ROUTER_CS_5_CV BIT(31)#define ROUTER_CS_6 0x06
@@ -221,7 +222,8 @@ enum tb_port_type {TB_TYPE_DP_HDMI_OUT =0x0e0102 ,TB_TYPE_PCIE_DOWN =0x100101 ,TB_TYPE_PCIE_UP =0x100102 , - /* TB_TYPE_USB = 0x200000, lower order bits are not known */ +TB_TYPE_USB3_DOWN =0x200101 , + TB_TYPE_USB3_UP = 0x200102, };/* Present on every port in TB_CF_PORT at address zero. */
@@ -331,6 +333,11 @@ struct tb_regs_port_header {#define ADP_PCIE_CS_0 0x00#define ADP_PCIE_CS_0_PE BIT(31) +/* USB adapter registers */ +#define ADP_USB3_CS_0 0x00 +#define ADP_USB3_CS_0_V BIT(30) +#define ADP_USB3_CS_0_PE BIT(31) +/* Hop register from TB_CFG_HOPS. 8 byte per entry. */ struct tb_regs_hop {/* DWORD 0 */
drivers/thunderbolt/tunnel.c +157 -1
176 lines not on this page · raw message
drivers/thunderbolt/tunnel.h +9 -0
@@ -15,6 +15,7 @@ enum tb_tunnel_type {TB_TUNNEL_PCI ,TB_TUNNEL_DP ,TB_TUNNEL_DMA , + TB_TUNNEL_USB3, };/**
@@ -57,6 +58,9 @@ struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, struct tb_port *dst, int transmit_ring, int transmit_path, int receive_ring, int receive_path); +struct tb_tunnel *tb_tunnel_discover_usb3 (struct tb *tb,struct tb_port *down); +struct tb_tunnel *tb_tunnel_alloc_usb3 (struct tb *tb,struct tb_port *up, +struct tb_port *down);void tb_tunnel_free (struct tb_tunnel *tunnel);int tb_tunnel_activate (struct tb_tunnel *tunnel);
@@ -82,5 +86,10 @@ static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel) return tunnel->type == TB_TUNNEL_DMA; } +static inline bool tb_tunnel_is_usb3 (const struct tb_tunnel *tunnel) +{ +return tunnel->type ==TB_TUNNEL_USB3 ; +} +#endif
drivers/thunderbolt/usb4.c +41 -1
57 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 25/25 thunderbolt: Update documentation with the USB4 information
In reply to Mika WesterbergUpdate user's and administrator's guide to mention USB4, how it relates to Thunderbolt (it is public spec of Thunderbolt 3) and and how it is supported in Linux.
--- Documentation/admin-guide/thunderbolt.rst | 25 ++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
Documentation/admin-guide/thunderbolt.rst +20 -5
@@ -1,6 +1,23 @@ -============= - Thunderbolt -============= +====================== + Thunderbolt and USB4 +====================== +USB4 is a public spec based on Thunderbolt 3 with some differences at the +register level among other things. There are two different implementations +available: firmware connection manager and software connection manager. +Typically PCs come with a firmware connection manager for Thunderbolt 3 and +early USB4 capable systems. Apple systems on the other hand use software +connection manager and the later USB4 compliant devices follow the suit. + +The Linux Thunderbolt driver supports both and can detect at runtime which +connection manager implementation is to be used. To be on the safe side the +software connection manager in Linux also advertises security level +``user`` which means PCIe tunneling is disabled by default. The +documentation below applies to both implementations with the exception that +the software connection manager only supports ``user`` security level and +is expected to be accompanied with an IOMMU based DMA protection. + +Security levels and how to use them +----------------------------------- The interface presented here is not meant for end users. Instead there should be a userspace tool that handles all the low-level details, keeps a database of the authorized devices and prompts users for new connections.
@@ -18,8 +35,6 @@ This will authorize all devices automatically when they appear. However, keep in mind that this bypasses the security levels and makes the system vulnerable to DMA attacks. -Security levels and how to use them ------------------------------------ Starting with Intel Falcon Ridge Thunderbolt controller there are 4 security levels available. Intel Titan Ridge added one more security level (usbonly). The reason for these is the fact that the connected devices can
Signature · 1 line
2.23.0
Quoted 7 lines
I did not yet add the
hw_vendor_idandhw_product_idattributes because I clocked that 'dd if=nvm_activeX/nvmem of=/dev/null bs=64 count=2' (that's what fwupd does) takes typically less than 10 ms when the controller is powered on. That should not slow down fwupd. We can add them later if it is really a problem (I'm just trying to avoid adding too much attributes that we need to maintain forever).
Maybe the controller going into D3 is the key to why it measured slow for me when I checked.
Quoted 71 lines
I think patches 1 to 17 can be applied for v5.5 already since they are pretty much about adding support for existing Thunderbolt 3 devices to the software connection manager. This allows Apple systems with Alpine or Titan Ridge controller to work without need to start the firmware. Please let me know if there are objections.
USB4 support patches 18 - 25 have been tested on development hardware but since it is rather early stage hardware we have not been able to properly test all features such as power management (which is why it is currently missing in this series).
Mika Westerberg (22):
thunderbolt: Introducetb_switch_is_icm()
thunderbolt: Log switch route string on config read/write timeout
thunderbolt: Log error if adding switch fails
thunderbolt: Convert basic adapter register names to follow the USB4 spec
thunderbolt: Convert PCIe adapter register names to follow the USB4 spec
thunderbolt: Convert DP adapter register names to follow the USB4 spec
thunderbolt: Maketb_sw_write()take const parameter
thunderbolt: Add helper macro to iterate over switch ports
thunderbolt: Refactoradd_switch()into two functions
thunderbolt: Add support for lane bonding
thunderbolt: Add default linking between lane adapters if not provided by
DROM
thunderbolt: Expand controller name intb_switch_is_xy()
thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
thunderbolt: Add Display Port CM handshake for Titan Ridge devices
thunderbolt: Add Display Port adapter pairing and resource management
thunderbolt: Add bandwidth management for Display Port tunnels
thunderbolt: Do not start firmware unless asked by the user
thunderbolt: Maketb_find_port()available to other files
thunderbolt: Calltb_eeprom_get_drom_offset()fromtb_eeprom_read_n()
thunderbolt: Add initial support for USB4
thunderbolt: UpdateKconfigentry to USB4
thunderbolt: Update documentation with the USB4 informationRajmohan Mani (3):
thunderbolt: Maketb_switch_find_cap()available to other files
thunderbolt: Add support for Time Management Unit
thunderbolt: Add support for USB 3.x tunnels.../ABI/testing/sysfs-bus-thunderbolt | 28 + Documentation/admin-guide/thunderbolt.rst | 25 +- drivers/Makefile | 2 +- drivers/net/Kconfig | 2 +- drivers/thunderbolt/Kconfig | 11 +- drivers/thunderbolt/Makefile | 4 +- drivers/thunderbolt/cap.c | 17 +- drivers/thunderbolt/ctl.c | 8 +- drivers/thunderbolt/eeprom.c | 146 +-- drivers/thunderbolt/icm.c | 157 +-- drivers/thunderbolt/lc.c | 193 +++- drivers/thunderbolt/nhi.c | 3 + drivers/thunderbolt/nhi.h | 2 + drivers/thunderbolt/path.c | 52 +- drivers/thunderbolt/switch.c | 943 +++++++++++++++--- drivers/thunderbolt/tb.c | 536 ++++++++-- drivers/thunderbolt/tb.h | 182 +++- drivers/thunderbolt/tb_msgs.h | 2 + drivers/thunderbolt/tb_regs.h | 160 ++- drivers/thunderbolt/tmu.c | 383 +++++++ drivers/thunderbolt/tunnel.c | 527 +++++++++- drivers/thunderbolt/tunnel.h | 19 +- drivers/thunderbolt/usb4.c | 763 ++++++++++++++ drivers/thunderbolt/xdomain.c | 11 +- 24 files changed, 3718 insertions(+), 458 deletions(-) create mode 100644
drivers/thunderbolt/tmu.ccreate mode 100644drivers/thunderbolt/usb4.c--
2.23.0
Quoted 9 lines · On Wed, Oct 23, 2019 at 03:55:48PM +0000, [email protected] wrote:
Quoted 6 lines
I did not yet add the
hw_vendor_idandhw_product_idattributes because I clocked that 'dd if=nvm_activeX/nvmem of=/dev/null bs=64 count=2' (that's what fwupd does) takes typically less than 10 ms when the controller is powered on. That should not slow down fwupd. We can add them later if it is really a problem (I'm just trying to avoid adding too much attributes that we need to maintain forever).Maybe the controller going into D3 is the key to why it measured slow for me when I checked.
Yeah, that's most likely the case.
Quoted 24 lines · Mika Westerberg
Mika Westerberg (22):
thunderbolt: Introducetb_switch_is_icm()
thunderbolt: Log switch route string on config read/write timeout
thunderbolt: Log error if adding switch fails
thunderbolt: Convert basic adapter register names to follow the USB4 spec
thunderbolt: Convert PCIe adapter register names to follow the USB4 spec
thunderbolt: Convert DP adapter register names to follow the USB4 spec
thunderbolt: Maketb_sw_write()take const parameter
thunderbolt: Add helper macro to iterate over switch ports
thunderbolt: Refactoradd_switch()into two functions
thunderbolt: Add support for lane bonding
thunderbolt: Add default linking between lane adapters if not provided by DROM
thunderbolt: Expand controller name intb_switch_is_xy()
thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
thunderbolt: Add Display Port CM handshake for Titan Ridge devices
thunderbolt: Add Display Port adapter pairing and resource management
thunderbolt: Add bandwidth management for Display Port tunnels
thunderbolt: Do not start firmware unless asked by the user
thunderbolt: Maketb_find_port()available to other files
thunderbolt: Calltb_eeprom_get_drom_offset()fromtb_eeprom_read_n()
thunderbolt: Add initial support for USB4
thunderbolt: UpdateKconfigentry to USB4
thunderbolt: Update documentation with the USB4 information
Quoted 5 lines
Rajmohan Mani (3):
thunderbolt: Maketb_switch_find_cap()available to other files
thunderbolt: Add support for Time Management Unit
thunderbolt: Add support for USB 3.x tunnels
I queued patches 1-17 for v5.5. I'll leave the rest of USB4 patches to cook for a while and hopefully we can get them in for v5.6.
Greg Kroah-Hartman
maintainerQuoted 25 lines · Mika Westerberg
Quoted 24 lines · Mika Westerberg
Mika Westerberg (22):
thunderbolt: Introducetb_switch_is_icm()
thunderbolt: Log switch route string on config read/write timeout
thunderbolt: Log error if adding switch fails
thunderbolt: Convert basic adapter register names to follow the USB4 spec
thunderbolt: Convert PCIe adapter register names to follow the USB4 spec
thunderbolt: Convert DP adapter register names to follow the USB4 spec
thunderbolt: Maketb_sw_write()take const parameter
thunderbolt: Add helper macro to iterate over switch ports
thunderbolt: Refactoradd_switch()into two functions
thunderbolt: Add support for lane bonding
thunderbolt: Add default linking between lane adapters if not provided by DROM
thunderbolt: Expand controller name intb_switch_is_xy()
thunderbolt: Add downstream PCIe port mappings for Alpine and Titan Ridge
thunderbolt: Add Display Port CM handshake for Titan Ridge devices
thunderbolt: Add Display Port adapter pairing and resource management
thunderbolt: Add bandwidth management for Display Port tunnels
thunderbolt: Do not start firmware unless asked by the user
thunderbolt: Maketb_find_port()available to other files
thunderbolt: Calltb_eeprom_get_drom_offset()fromtb_eeprom_read_n()
thunderbolt: Add initial support for USB4
thunderbolt: UpdateKconfigentry to USB4
thunderbolt: Update documentation with the USB4 information
Quoted 8 lines
Quoted 5 lines
Rajmohan Mani (3):
thunderbolt: Maketb_switch_find_cap()available to other files
thunderbolt: Add support for Time Management Unit
thunderbolt: Add support for USB 3.x tunnelsI queued patches 1-17 for v5.5. I'll leave the rest of USB4 patches to cook for a while and hopefully we can get them in for v5.6.
No objection from me, nice work!
greg k-h