drivers/thunderbolt/retimer.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/retimer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/retimer.c- Extension
.c- Size
- 13654 bytes
- Lines
- 601
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/pm_runtime.hlinux/sched/signal.hsb_regs.htb.h
Detected Declarations
struct tb_retimer_lookupfunction Copyrightfunction nvm_readfunction nvm_writefunction tb_retimer_nvm_addfunction tb_retimer_nvm_validate_and_writefunction tb_retimer_nvm_authenticatefunction device_showfunction nvm_authenticate_showfunction tb_retimer_nvm_authenticate_statusfunction tb_retimer_set_inbound_sbtxfunction tb_retimer_unset_inbound_sbtxfunction nvm_authenticate_storefunction nvm_version_showfunction vendor_showfunction retimer_is_visiblefunction tb_retimer_releasefunction tb_retimer_addfunction tb_retimer_removefunction retimer_matchfunction tb_retimer_scanfunction remove_retimerfunction tb_retimer_remove_all
Annotated Snippet
struct tb_retimer_lookup {
const struct tb_port *port;
u8 index;
};
static int retimer_match(struct device *dev, const void *data)
{
const struct tb_retimer_lookup *lookup = data;
struct tb_retimer *rt = tb_to_retimer(dev);
return rt && rt->port == lookup->port && rt->index == lookup->index;
}
static struct tb_retimer *tb_port_find_retimer(struct tb_port *port, u8 index)
{
struct tb_retimer_lookup lookup = { .port = port, .index = index };
struct device *dev;
dev = device_find_child(&port->usb4->dev, &lookup, retimer_match);
if (dev)
return tb_to_retimer(dev);
return NULL;
}
/**
* tb_retimer_scan() - Scan for on-board retimers under port
* @port: USB4 port to scan
* @add: If true also registers found retimers
*
* Brings the sideband into a state where retimers can be accessed.
* Then tries to enumerate on-board retimers connected to @port. Found
* retimers are registered as children of @port if @add is set. Does
* not scan for cable retimers for now.
*
* Return: %0 on success, negative errno otherwise.
*/
int tb_retimer_scan(struct tb_port *port, bool add)
{
u32 status[TB_MAX_RETIMER_INDEX + 1] = {};
int ret, i, max, last_idx = 0;
/*
* Send broadcast RT to make sure retimer indices facing this
* port are set.
*/
ret = usb4_port_enumerate_retimers(port);
if (ret)
return ret;
/*
* Immediately after sending enumerate retimers read the
* authentication status of each retimer.
*/
tb_retimer_nvm_authenticate_status(port, status);
/*
* Enable sideband channel for each retimer. We can do this
* regardless whether there is device connected or not.
*/
tb_retimer_set_inbound_sbtx(port);
for (max = 1, i = 1; i <= TB_MAX_RETIMER_INDEX; i++) {
/*
* Last retimer is true only for the last on-board
* retimer (the one connected directly to the Type-C
* port).
*/
ret = usb4_port_retimer_is_last(port, i);
if (ret > 0)
last_idx = i;
else if (ret < 0)
break;
max = i;
}
ret = 0;
if (!IS_ENABLED(CONFIG_USB4_DEBUGFS_MARGINING))
max = min(last_idx, max);
/* Add retimers if they do not exist already */
for (i = 1; i <= max; i++) {
struct tb_retimer *rt;
/* Skip cable retimers */
if (usb4_port_retimer_is_cable(port, i))
continue;
rt = tb_port_find_retimer(port, i);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/pm_runtime.h`, `linux/sched/signal.h`, `sb_regs.h`, `tb.h`.
- Detected declarations: `struct tb_retimer_lookup`, `function Copyright`, `function nvm_read`, `function nvm_write`, `function tb_retimer_nvm_add`, `function tb_retimer_nvm_validate_and_write`, `function tb_retimer_nvm_authenticate`, `function device_show`, `function nvm_authenticate_show`, `function tb_retimer_nvm_authenticate_status`.
- 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.