drivers/thunderbolt/usb4.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/usb4.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/usb4.c- Extension
.c- Size
- 77343 bytes
- Lines
- 3148
- Domain
- Driver Families
- Bucket
- drivers/thunderbolt
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/ktime.hlinux/string_choices.hlinux/units.hsb_regs.htb.h
Detected Declarations
struct retimer_infoenum usb4_ba_indexfunction usb4_native_switch_opfunction __usb4_switch_opfunction usb4_switch_opfunction usb4_switch_op_datafunction usb4_switch_check_wakesfunction link_is_usb4function usb4_switch_setupfunction tb_switch_find_portfunction usb4_switch_configuration_validfunction usb4_switch_read_uidfunction usb4_switch_drom_read_blockfunction usb4_switch_drom_readfunction usb4_switch_lane_bonding_possiblefunction usb4_switch_set_wakefunction portsfunction usb4_switch_set_sleepfunction usb4_switch_nvm_sector_sizefunction usb4_switch_nvm_read_blockfunction usb4_switch_nvm_readfunction usb4_switch_nvm_set_offsetfunction usb4_switch_nvm_write_next_blockfunction usb4_switch_nvm_writefunction usb4_switch_nvm_authenticatefunction usb4_switch_nvm_authenticate_statusfunction usb4_switch_credits_initfunction tb_switch_for_each_portfunction usb4_switch_query_dp_resourcefunction usb4_switch_alloc_dp_resourcefunction usb4_switch_dealloc_dp_resourcefunction usb4_port_indexfunction usb4_switch_map_pcie_downfunction usb4_switch_map_usb3_downfunction usb4_switch_add_portsfunction tb_switch_for_each_portfunction usb4_switch_remove_portsfunction tb_switch_for_each_portfunction usb4_port_unlockfunction usb4_port_hotplug_enablefunction usb4_port_resetfunction usb4_port_set_configuredfunction usb4_port_configurefunction usb4_port_unconfigurefunction usb4_set_xdomain_configuredfunction usb4_port_configure_xdomainfunction usb4_port_unconfigure_xdomainfunction usb4_port_wait_for_bit
Annotated Snippet
struct retimer_info {
struct tb_port *port;
u8 index;
};
static int usb4_port_retimer_nvm_write_next_block(void *data,
unsigned int dwaddress, const void *buf, size_t dwords)
{
const struct retimer_info *info = data;
struct tb_port *port = info->port;
u8 index = info->index;
int ret;
ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index,
USB4_SB_DATA, buf, dwords * 4);
if (ret)
return ret;
return usb4_port_retimer_op(port, index,
USB4_SB_OPCODE_NVM_BLOCK_WRITE, 1000);
}
/**
* usb4_port_retimer_nvm_write() - Write to retimer NVM
* @port: USB4 port
* @index: Retimer index
* @address: Byte address where to start the write
* @buf: Data to write
* @size: Size in bytes how much to write
*
* Writes @size bytes from @buf to the retimer NVM. Used for NVM
* upgrade.
*
* Return:
* * %0 - If the data was written successfully.
* * %-ENODEV - If there is no retimer at @index.
* * Negative errno - In case of an error.
*/
int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address,
const void *buf, size_t size)
{
struct retimer_info info = { .port = port, .index = index };
int ret;
ret = usb4_port_retimer_nvm_set_offset(port, index, address);
if (ret)
return ret;
return tb_nvm_write_data(address, buf, size, USB4_DATA_RETRIES,
usb4_port_retimer_nvm_write_next_block, &info);
}
/**
* usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
* @port: USB4 port
* @index: Retimer index
*
* After the new NVM image has been written via usb4_port_retimer_nvm_write()
* this function can be used to trigger the NVM upgrade process. If
* successful the retimer restarts with the new NVM and may not have the
* index set so one needs to call usb4_port_enumerate_retimers() to
* force index to be assigned.
*
* Return: %0 on success, negative errno otherwise.
*/
int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index)
{
u32 val;
/*
* We need to use the raw operation here because once the
* authentication completes the retimer index is not set anymore
* so we do not get back the status now.
*/
val = USB4_SB_OPCODE_NVM_AUTH_WRITE;
return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index,
USB4_SB_OPCODE, &val, sizeof(val));
}
/**
* usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
* @port: USB4 port
* @index: Retimer index
* @status: Raw status code read from metadata
*
* This can be called after usb4_port_retimer_nvm_authenticate() and
* usb4_port_enumerate_retimers() to fetch status of the NVM upgrade.
*
* Return: %0 if the authentication status was successfully read. The
Annotation
- Immediate include surface: `linux/delay.h`, `linux/ktime.h`, `linux/string_choices.h`, `linux/units.h`, `sb_regs.h`, `tb.h`.
- Detected declarations: `struct retimer_info`, `enum usb4_ba_index`, `function usb4_native_switch_op`, `function __usb4_switch_op`, `function usb4_switch_op`, `function usb4_switch_op_data`, `function usb4_switch_check_wakes`, `function link_is_usb4`, `function usb4_switch_setup`, `function tb_switch_find_port`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.