thunderbolt: Add retimer NVM upgrade support
Subsystems (3)
cover thunderbolt: Add retimer NVM upgrade support
Hi all,
USB4 added standard means for accessing retimers on the link. This access is done through the side-band channel (two side-band wires in Type-C cable). The retimer specification is part of USB4 spec and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_5.zip
On-board retimers are represented as devices and added under the router they belong to with names like <device>:<port>.<index>. We re-use some of the current NVM upgrade code for routers for retimers as well. Also we only expose these when software connection manager is used. It is not clear if firmware connection manager is going to support this (and what kind of messaging it needs).
The user-space interface is the same we have for routers so that should allow code re-use for tools such as fwupd.
Currently only Intel NVM format is supported but this will be relaxed once we learn format of other vendors.
This series applies on top of the tunneling improvements series here:
https://lore.kernel.org/linux-usb/[email protected]/
Kranthi Kuntala (1):
thunderbolt: Add support for on-board retimers
Mika Westerberg (4):
thunderbolt: Add Intel USB-IF ID to the NVM upgrade supported list
thunderbolt: Split common NVM functionality into a separate file
thunderbolt: Generalize usb4_switch_do_[read|write]_data()
thunderbolt: Retry USB4 block read operation
Rajmohan Mani (1):
thunderbolt: Implement USB4 port sideband operations for retimer access
.../ABI/testing/sysfs-bus-thunderbolt | 33 ++ Documentation/admin-guide/thunderbolt.rst | 11 +- drivers/thunderbolt/Makefile | 1 + drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/nvm.c | 169 ++++++ drivers/thunderbolt/retimer.c | 485 +++++++++++++++++ drivers/thunderbolt/sb_regs.h | 33 ++ drivers/thunderbolt/switch.c | 122 +---- drivers/thunderbolt/tb.c | 10 + drivers/thunderbolt/tb.h | 85 ++- drivers/thunderbolt/tb_regs.h | 10 + drivers/thunderbolt/usb4.c | 505 +++++++++++++++++- 12 files changed, 1338 insertions(+), 128 deletions(-) create mode 100644 drivers/thunderbolt/nvm.c create mode 100644 drivers/thunderbolt/retimer.c create mode 100644 drivers/thunderbolt/sb_regs.h
Signature · 1 line
2.27.0.rc2
PATCH 1/6 thunderbolt: Add Intel USB-IF ID to the NVM upgrade supported list
With USB4 Intel is also using its USB-IF ID (0x8087) with the new devices. The NVM format is the same. Add this to the driver so NVM upgrade is possible with these devices as well.
--- drivers/thunderbolt/switch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thunderbolt/switch.c +2 -1
@@ -423,7 +423,8 @@ static int tb_switch_nvm_add(struct tb_switch *sw)* currently restrict NVM upgrade for Intel hardware. We may * relax this in the future when we learn other NVM formats. */ -if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL ) { +if (sw->config.vendor_id !=PCI_VENDOR_ID_INTEL && + sw->config.vendor_id !=0x8087 ) {dev_info (&sw->dev,"NVM format of vendor %#x is not known, disabling NVM upgrade\n" , sw->config.vendor_id);
Signature · 1 line
2.27.0.rc2
PATCH 2/6 thunderbolt: Split common NVM functionality into a separate file
In reply to Mika WesterbergWe are going to reuse some of this functionality to implement retimer NVM upgrade so move common NVM functionality into its own file. We also rename the structure from tb_switch_nvm to tb_nvm to make it clear that it is not just for switches.
--- drivers/thunderbolt/Makefile | 1 + drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/nvm.c | 169 +++++++++++++++++++++++++++++++++++ drivers/thunderbolt/switch.c | 116 +++++------------------- drivers/thunderbolt/tb.h | 31 +++++-- 5 files changed, 220 insertions(+), 99 deletions(-) create mode 100644 drivers/thunderbolt/nvm.c
drivers/thunderbolt/Makefile +1 -0
@@ -2,5 +2,6 @@ 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 tmu.o usb4.o +thunderbolt-objs += nvm.o obj-${CONFIG_USB4_KUNIT_TEST} += test.o
drivers/thunderbolt/domain.c +1 -1
@@ -812,6 +812,6 @@ void tb_domain_exit(void) {bus_unregister (&tb_bus_type);ida_destroy (&tb_domain_ida); -tb_switch_exit (); +tb_nvm_exit ();tb_xdomain_exit (); }
drivers/thunderbolt/nvm.c new file +169 -0
169 lines not on this page · raw message
drivers/thunderbolt/switch.c +23 -93
197 lines not on this page · raw message
drivers/thunderbolt/tb.h +26 -5
@@ -18,8 +18,17 @@#include "ctl.h" #include "dma_port.h" +#define NVM_MIN_SIZE SZ_32K +#define NVM_MAX_SIZE SZ_512K + +/* Intel specific NVM offsets */ +#define NVM_DEVID 0x05 +#define NVM_VERSION 0x08 +#define NVM_FLASH_SIZE 0x45 +/** -* struct tb_switch_nvm - Structure holding switch NVM information +* struct tb_nvm - Structure holding NVM information +* @dev: Owner of the NVM * @major: Major version number of the active NVM portion * @minor: Minor version number of the active NVM portion * @id: Identifier used with both NVM portions
@@ -29,9 +38,13 @@* the actual NVM flash device * @buf_data_size: Number of bytes actually consumed by the new NVM * image -* @authenticating: The switch is authenticating the new NVM +* @authenticating: The device is authenticating the new NVM +* +* The user of this structure needs to handle serialization of possible +* concurrent access. */ -struct tb_switch_nvm { +struct tb_nvm { +struct device *dev;u8 major;u8 minor;int id;
@@ -143,7 +156,7 @@ struct tb_switch {int cap_lc;bool is_unplugged;u8 *drom; -struct tb_switch_nvm *nvm; +struct tb_nvm *nvm;bool no_nvm_upgrade;bool safe_mode;bool boot;
@@ -544,7 +557,6 @@ extern struct device_type tb_switch_type;int tb_domain_init (void );void tb_domain_exit (void ); -void tb_switch_exit (void );int tb_xdomain_init (void );void tb_xdomain_exit (void );
@@ -577,6 +589,15 @@ static inline void tb_domain_put(struct tb *tb)put_device (&tb->dev); } +struct tb_nvm *tb_nvm_alloc (struct device *dev); +int tb_nvm_add_active (struct tb_nvm *nvm,size_t size,nvmem_reg_read_t reg_read); +int tb_nvm_write_buf (struct tb_nvm *nvm,unsigned int offset,void *val, +size_t bytes); +int tb_nvm_add_non_active (struct tb_nvm *nvm,size_t size, +nvmem_reg_write_t reg_write); +void tb_nvm_free (struct tb_nvm *nvm); +void tb_nvm_exit (void ); +struct tb_switch *tb_switch_alloc (struct tb *tb,struct device *parent,u64 route); struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb,
Signature · 1 line
2.27.0.rc2
PATCH 3/6 thunderbolt: Generalize usb4_switch_do_[read|write]_data()
In reply to Mika WesterbergCurrently these functions operate on struct tb_switch but we are going to need the same functionality with retimers as well so make the two functions work with an arbitrary object that gets passed as parameter to the callbacks.
--- drivers/thunderbolt/usb4.c | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-)
drivers/thunderbolt/usb4.c +21 -18
@@ -42,8 +42,8 @@ enum usb4_switch_op {#define USB4_NVM_SECTOR_SIZE_MASK GENMASK(23, 0) -typedef int (*read_block_fn )(struct tb_switch *,unsigned int ,void *,size_t ); -typedef int (*write_block_fn )(struct tb_switch *,const void *,size_t ); +typedef int (*read_block_fn )(void *,unsigned int ,void *,size_t ); +typedef int (*write_block_fn )(void *,const void *,size_t );static int usb4_switch_wait_for_bit (struct tb_switch *sw,u32 offset,u32 bit,u32 value,int timeout_msec)
@@ -95,8 +95,8 @@ static int usb4_switch_op_write_metadata(struct tb_switch *sw, u32 metadata)return tb_sw_write (sw, &metadata,TB_CFG_SWITCH ,ROUTER_CS_25 ,1 ); } -static int usb4_switch_do_read_data (struct tb_switch *sw,u16 address, -void *buf,size_t size,read_block_fn read_block) +static int usb4_do_read_data (u16 address,void *buf,size_t size, +read_block_fn read_block,void *read_block_data) {unsigned int retries =USB4_DATA_RETRIES ;unsigned int offset;
@@ -113,7 +113,7 @@ static int usb4_switch_do_read_data(struct tb_switch *sw, u16 address, dwaddress = address /4 ; dwords =ALIGN (nbytes,4 ) /4 ; - ret =read_block (sw, dwaddress, data, dwords); + ret =read_block (read_block_data, dwaddress, data, dwords);if (ret) {if (ret == -ETIMEDOUT ) {if (retries--)
@@ -133,8 +133,8 @@ static int usb4_switch_do_read_data(struct tb_switch *sw, u16 address,return 0 ; } -static int usb4_switch_do_write_data (struct tb_switch *sw,u16 address, -const void *buf,size_t size,write_block_fn write_next_block) +static int usb4_do_write_data (unsigned int address,const void *buf,size_t size, +write_block_fn write_next_block,void *write_block_data) {unsigned int retries =USB4_DATA_RETRIES ;unsigned int offset;
@@ -149,7 +149,7 @@ static int usb4_switch_do_write_data(struct tb_switch *sw, u16 address,memcpy (data + offset, buf, nbytes); - ret =write_next_block (sw, data, nbytes /4 ); + ret =write_next_block (write_block_data, data, nbytes /4 );if (ret) {if (ret == -ETIMEDOUT ) {if (retries--)
@@ -289,10 +289,11 @@ int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid)return tb_sw_read (sw, uid,TB_CFG_SWITCH ,ROUTER_CS_7 ,2 ); } -static int usb4_switch_drom_read_block (struct tb_switch *sw, +static int usb4_switch_drom_read_block (void *data,unsigned int dwaddress,void *buf,size_t dwords) { +struct tb_switch *sw = data;u8 status =0 ;u32 metadata;int ret;
@@ -329,8 +330,8 @@ static int usb4_switch_drom_read_block(struct tb_switch *sw,int usb4_switch_drom_read (struct tb_switch *sw,unsigned int address,void *buf,size_t size) { -return usb4_switch_do_read_data (sw, address, buf, size, - usb4_switch_drom_read_block); +return usb4_do_read_data (address, buf, size, + usb4_switch_drom_read_block, sw); }static int usb4_set_port_configured (struct tb_port *port,bool configured)
@@ -463,9 +464,10 @@ int usb4_switch_nvm_sector_size(struct tb_switch *sw)return metadata &USB4_NVM_SECTOR_SIZE_MASK ; } -static int usb4_switch_nvm_read_block (struct tb_switch *sw, +static int usb4_switch_nvm_read_block (void *data,unsigned int dwaddress,void *buf,size_t dwords) { +struct tb_switch *sw = data;u8 status =0 ;u32 metadata;int ret;
@@ -502,8 +504,8 @@ static int usb4_switch_nvm_read_block(struct tb_switch *sw,int usb4_switch_nvm_read (struct tb_switch *sw,unsigned int address,void *buf,size_t size) { -return usb4_switch_do_read_data (sw, address, buf, size, - usb4_switch_nvm_read_block); +return usb4_do_read_data (address, buf, size, + usb4_switch_nvm_read_block, sw); } static int usb4_switch_nvm_set_offset(struct tb_switch *sw,
@@ -528,9 +530,10 @@ static int usb4_switch_nvm_set_offset(struct tb_switch *sw,return status ? -EIO :0 ; } -static int usb4_switch_nvm_write_next_block (struct tb_switch *sw, -const void *buf,size_t dwords) +static int usb4_switch_nvm_write_next_block (void *data,const void *buf, +size_t dwords) { +struct tb_switch *sw = data;u8 status;int ret;
@@ -564,8 +567,8 @@ int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address,if (ret)return ret; -return usb4_switch_do_write_data (sw, address, buf, size, - usb4_switch_nvm_write_next_block); +return usb4_do_write_data (address, buf, size, + usb4_switch_nvm_write_next_block, sw); }/**
Signature · 1 line
2.27.0.rc2
PATCH 4/6 thunderbolt: Retry USB4 block read operation
In reply to Mika WesterbergEspecially when accessing retimers over USB4 sideband operations the possibility to get read errors seems to be higher so make the usb4_do_read_data() retry a couple of times if it sees any other error than -ENODEV (device is gone). We can only do this for read side because it carries the offset as part of metadata (as opposed to writes).
--- drivers/thunderbolt/usb4.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/thunderbolt/usb4.c +2 -5
@@ -115,11 +115,8 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size, ret =read_block (read_block_data, dwaddress, data, dwords);if (ret) { -if (ret == -ETIMEDOUT ) { -if (retries--) -continue ; - ret = -EIO ; - } +if (ret != -ENODEV && retries--) +continue ;return ret; }
Signature · 1 line
2.27.0.rc2
PATCH 5/6 thunderbolt: Implement USB4 port sideband operations for retimer access
In reply to Mika WesterbergFrom: Rajmohan Mani <[email protected]>
USB4 spec specifies standard set of sideband operations that are send over the low speed link to access either retimers on the link or the link parter (the other router). The USB4 retimer spec extends these and adds operations for retimer NVM upgrade.
This implements the retimer access and NVM upgrade USB4 port sideband operations which we need for retimer support in the patch that follows.
--- drivers/thunderbolt/sb_regs.h | 31 +++ drivers/thunderbolt/tb.h | 16 ++ drivers/thunderbolt/tb_regs.h | 10 + drivers/thunderbolt/usb4.c | 459 ++++++++++++++++++++++++++++++++++ 4 files changed, 516 insertions(+) create mode 100644 drivers/thunderbolt/sb_regs.h
drivers/thunderbolt/sb_regs.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* USB4 port sideband registers found on routers and retimers +* +* Copyright (C) 2020, Intel Corporation +* Authors: Mika Westerberg <[email protected]> +* Rajmohan Mani <[email protected]> +*/ + +#ifndef _SB_REGS +#define _SB_REGS + +#define USB4_SB_OPCODE 0x08 + +enum usb4_sb_opcode { +USB4_SB_OPCODE_ERR =0x20525245 ,/* "ERR " */ +USB4_SB_OPCODE_ONS =0x444d4321 ,/* "!CMD" */ +USB4_SB_OPCODE_ENUMERATE_RETIMERS =0x4d554e45 ,/* "ENUM" */ +USB4_SB_OPCODE_QUERY_LAST_RETIMER =0x5453414c ,/* "LAST" */ +USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE =0x53534e47 ,/* "GNSS" */ +USB4_SB_OPCODE_NVM_SET_OFFSET =0x53504f42 ,/* "BOPS" */ +USB4_SB_OPCODE_NVM_BLOCK_WRITE =0x574b4c42 ,/* "BLKW" */ +USB4_SB_OPCODE_NVM_AUTH_WRITE =0x48545541 ,/* "AUTH" */ +USB4_SB_OPCODE_NVM_READ =0x52524641 ,/* "AFRR" */ +}; + +#define USB4_SB_METADATA 0x09 +#define USB4_SB_METADATA_NVM_AUTH_WRITE_MASK GENMASK(5, 0) +#define USB4_SB_DATA 0x12 + +#endif
drivers/thunderbolt/tb.h +16 -0
@@ -876,6 +876,22 @@ 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); +int usb4_port_enumerate_retimers (struct tb_port *port); + +int usb4_port_retimer_read (struct tb_port *port,u8 index,u8 reg,void *buf, +u8 size); +int usb4_port_retimer_write (struct tb_port *port,u8 index,u8 reg, +const void *buf,u8 size); +int usb4_port_retimer_is_last (struct tb_port *port,u8 index); +int usb4_port_retimer_nvm_sector_size (struct tb_port *port,u8 index); +int usb4_port_retimer_nvm_write (struct tb_port *port,u8 index, +unsigned int address,const void *buf, +size_t size); +int usb4_port_retimer_nvm_authenticate (struct tb_port *port,u8 index); +int usb4_port_retimer_nvm_authenticate_status (struct tb_port *port,u8 index, +u32 *status); +int usb4_port_retimer_nvm_read (struct tb_port *port,u8 index, +unsigned int address,void *buf,size_t size);int usb4_usb3_port_max_link_rate (struct tb_port *port);int usb4_usb3_port_actual_link_rate (struct tb_port *port);
drivers/thunderbolt/tb_regs.h +10 -0
@@ -288,6 +288,16 @@ struct tb_regs_port_header {#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20/* USB4 port registers */ +#define PORT_CS_1 0x01 +#define PORT_CS_1_LENGTH_SHIFT 8 +#define PORT_CS_1_TARGET_MASK GENMASK(18, 16) +#define PORT_CS_1_TARGET_SHIFT 16 +#define PORT_CS_1_RETIMER_INDEX_SHIFT 20 +#define PORT_CS_1_WNR_WRITE BIT(24) +#define PORT_CS_1_NR BIT(25) +#define PORT_CS_1_RC BIT(26) +#define PORT_CS_1_PND BIT(31) +#define PORT_CS_2 0x02#define PORT_CS_18 0x12#define PORT_CS_18_BE BIT(8)#define PORT_CS_18_TCM BIT(9)
drivers/thunderbolt/usb4.c +459 -0
477 lines not on this page · raw message
Signature · 1 line
2.27.0.rc2
PATCH 6/6 thunderbolt: Add support for on-board retimers
In reply to Mika WesterbergFrom: Kranthi Kuntala <[email protected]>
USB4 spec specifies standard access to retimers (both on-board and cable) through USB4 port sideband access. This makes it possible to upgrade their firmware in the same way than we already do with the routers.
This enumerates on-board retimers under each USB4 port when the link comes up and adds them to the bus under the router the retimer belongs to. Retimers are exposed in sysfs with name like <device>:<port>.<index> where device is the router the retimer belongs to, port is the USB4 port the retimer is connected to and index is the retimer index under that port (starting from 1). This applies to the upstream USB4 port as well so if there is on-board retimer between the port and the router it is also added accordingly.
At this time we do not add cable retimers but there is no techincal restriction to do so in the future if needed. It is not clear whether it makes sense to upgrade their firmwares and at least Thunderbolt 3 cables it has not been done outside of lab environments.
The sysfs interface is made to follow the router NVM upgrade to make it easy to extend the existing userspace (fwupd) to handle these as well.
--- .../ABI/testing/sysfs-bus-thunderbolt | 33 ++ Documentation/admin-guide/thunderbolt.rst | 11 +- drivers/thunderbolt/Makefile | 2 +- drivers/thunderbolt/retimer.c | 485 ++++++++++++++++++ drivers/thunderbolt/sb_regs.h | 2 + drivers/thunderbolt/switch.c | 3 + drivers/thunderbolt/tb.c | 10 + drivers/thunderbolt/tb.h | 38 ++ 8 files changed, 578 insertions(+), 6 deletions(-) create mode 100644 drivers/thunderbolt/retimer.c
Documentation/ABI/testing/sysfs-bus-thunderbolt +33 -0
@@ -236,3 +236,36 @@ KernelVersion: 4.15 Contact: [email protected] Description: This contains XDomain service specific settings as bitmask. Format: %x + +What: /sys/bus/thunderbolt/devices/<device>:<port>.<index>/device +Date: Oct 2020 +KernelVersion: v5.9 +Contact: Mika Westerberg <[email protected]> +Description: Retimer device identifier read from the hardware. + +What: /sys/bus/thunderbolt/devices/<device>:<port>.<index>/nvm_authenticate +Date: Oct 2020 +KernelVersion: v5.9 +Contact: Mika Westerberg <[email protected]> +Description: When new NVM image is written to the non-active NVM + area (through non_activeX NVMem device), the + authentication procedure is started by writing 1 to + this file. If everything goes well, the device is + restarted with the new NVM firmware. If the image + verification fails an error code is returned instead. + + When read holds status of the last authentication + operation if an error occurred during the process. + Format: %x. + +What: /sys/bus/thunderbolt/devices/<device>:<port>.<index>/nvm_version +Date: Oct 2020 +KernelVersion: v5.9 +Contact: Mika Westerberg <[email protected]> +Description: Holds retimer NVM version number. Format: %x.%x, major.minor. + +What: /sys/bus/thunderbolt/devices/<device>:<port>.<index>/vendor +Date: Oct 2020 +KernelVersion: v5.9 +Contact: Mika Westerberg <[email protected]> +Description: Retimer vendor identifier read from the hardware.
Documentation/admin-guide/thunderbolt.rst +6 -5
@@ -173,8 +173,8 @@ following ``udev`` rule:: ACTION=="add", SUBSYSTEM=="thunderbolt", ATTRS{iommu_dma_protection}=="1", ATTR{authorized}=="0", ATTR{authorized}="1" -Upgrading NVM on Thunderbolt device or host -------------------------------------------- +Upgrading NVM on Thunderbolt device, host or retimer +---------------------------------------------------- Since most of the functionality is handled in firmware running on a host controller or a device, it is important that the firmware can be upgraded to the latest where possible bugs in it have been fixed.
@@ -185,9 +185,10 @@ for some machines: `Thunderbolt Updates <https://thunderbolttechnology.net/updates>`_ -Before you upgrade firmware on a device or host, please make sure it is a -suitable upgrade. Failing to do that may render the device (or host) in a -state where it cannot be used properly anymore without special tools! +Before you upgrade firmware on a device, host or retimer, please make +sure it is a suitable upgrade. Failing to do that may render the device +in a state where it cannot be used properly anymore without special +tools! Host NVM upgrade on Apple Macs is not supported.
drivers/thunderbolt/Makefile +1 -1
@@ -2,6 +2,6 @@ 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 tmu.o usb4.o -thunderbolt-objs += nvm.o +thunderbolt-objs += nvm.o retimer.o obj-${CONFIG_USB4_KUNIT_TEST} += test.o
drivers/thunderbolt/retimer.c new file +485 -0
485 lines not on this page · raw message
drivers/thunderbolt/sb_regs.h +2 -0
@@ -10,6 +10,8 @@#ifndef _SB_REGS#define _SB_REGS +#define USB4_SB_VENDOR_ID 0x00 +#define USB4_SB_PRODUCT_ID 0x01#define USB4_SB_OPCODE 0x08 enum usb4_sb_opcode {
drivers/thunderbolt/switch.c +3 -0
@@ -2392,6 +2392,9 @@ void tb_switch_remove(struct tb_switch *sw)tb_xdomain_remove (port->xdomain); port->xdomain =NULL ; } + +/* Remove any downstream retimers */ +tb_retimer_remove_all (port); }if (!sw->is_unplugged)
drivers/thunderbolt/tb.c +10 -0
@@ -539,6 +539,9 @@ static void tb_scan_port(struct tb_port *port)tb_port_dbg (port,"port already has a remote\n" );return ; } + +tb_retimer_scan (port); + sw =tb_switch_alloc (port->sw->tb, &port->sw->dev,tb_downstream_route (port));if (IS_ERR (sw)) {
@@ -595,6 +598,9 @@ static void tb_scan_port(struct tb_port *port)if (tb_enable_tmu (sw))tb_sw_warn (sw,"failed to enable TMU\n" ); +/* Scan upstream retimers */ +tb_retimer_scan (upstream_port); +/* * Create USB 3.x tunnels only when the switch is plugged to the * domain. This is because we scan the domain also during discovery
@@ -674,6 +680,7 @@ static void tb_free_unplugged_children(struct tb_switch *sw)continue ;if (port->remote->sw->is_unplugged) { +tb_retimer_remove_all (port);tb_remove_dp_resources (port->remote->sw);tb_switch_lane_bonding_disable (port->remote->sw);tb_switch_remove (port->remote->sw);
@@ -1039,6 +1046,8 @@ static void tb_handle_hotplug(struct work_struct *work) goto put_sw; }if (ev->unplug) { +tb_retimer_remove_all (port); +if (tb_port_has_remote (port)) {tb_port_dbg (port,"switch unplugged\n" );tb_sw_set_unplugged (port->remote->sw);
@@ -1283,6 +1292,7 @@ static int tb_free_unplugged_xdomains(struct tb_switch *sw)if (tb_is_upstream_port (port))continue ;if (port->xdomain && port->xdomain->is_unplugged) { +tb_retimer_remove_all (port);tb_xdomain_remove (port->xdomain); port->xdomain =NULL ; ret++;
drivers/thunderbolt/tb.h +38 -0
@@ -210,6 +210,28 @@ struct tb_port {struct list_head list; }; +/** +* tb_retimer: Thunderbolt retimer +* @dev: Device for the retimer +* @tb: Pointer to the domain the retimer belongs to +* @index: Retimer index facing the router USB4 port +* @vendor: Vendor ID of the retimer +* @device: Device ID of the retimer +* @port: Pointer to the lane 0 adapter +* @nvm: Pointer to the NVM if the retimer has one (%NULL otherwise) +* @auth_status: Status of last NVM authentication +*/ +struct tb_retimer { +struct device dev; +struct tb *tb; +u8 index; +u32 vendor; +u32 device; +struct tb_port *port; +struct tb_nvm *nvm; +u32 auth_status; +}; +/** * struct tb_path_hop - routing information for a tb_path * @in_port: Ingress port of a switch
@@ -553,6 +575,7 @@ struct tb *icm_probe(struct tb_nhi *nhi);struct tb *tb_probe (struct tb_nhi *nhi);extern struct device_type tb_domain_type; +extern struct device_type tb_retimer_type;extern struct device_type tb_switch_type;int tb_domain_init (void );
@@ -853,6 +876,21 @@ 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 tb_retimer_scan (struct tb_port *port); +void tb_retimer_remove_all (struct tb_port *port); + +static inline bool tb_is_retimer (const struct device *dev) +{ +return dev->type == &tb_retimer_type; +} + +static inline struct tb_retimer *tb_to_retimer (struct device *dev) +{ +if (tb_is_retimer (dev)) + return container_of(dev, struct tb_retimer, dev); +return NULL ; +} +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,
Signature · 1 line
2.27.0.rc2
Quoted 29 lines · Mika Westerberg
Hi all,
USB4 added standard means for accessing retimers on the link. This access is done through the side-band channel (two side-band wires in Type-C cable). The retimer specification is part of USB4 spec and can be downloaded here:
https://www.usb.org/sites/default/files/USB4%20Specification_5.zip
On-board retimers are represented as devices and added under the router they belong to with names like <device>:<port>.<index>. We re-use some of the current NVM upgrade code for routers for retimers as well. Also we only expose these when software connection manager is used. It is not clear if firmware connection manager is going to support this (and what kind of messaging it needs).
The user-space interface is the same we have for routers so that should allow code re-use for tools such as fwupd.
Currently only Intel NVM format is supported but this will be relaxed once we learn format of other vendors.
This series applies on top of the tunneling improvements series here:
https://lore.kernel.org/linux-usb/[email protected]/
Kranthi Kuntala (1):
thunderbolt: Add support for on-board retimers
Quoted 8 lines
Mika Westerberg (4):
thunderbolt: Add Intel USB-IF ID to the NVM upgrade supported list
thunderbolt: Split common NVM functionality into a separate file
thunderbolt: Generalize usb4_switch_do_[read|write]_data()
thunderbolt: Retry USB4 block read operationRajmohan Mani (1):
thunderbolt: Implement USB4 port sideband operations for retimer access
Queued for v5.9.