drivers/thunderbolt/switch.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/switch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/switch.c- Extension
.c- Size
- 96917 bytes
- Lines
- 4039
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/hex.hlinux/idr.hlinux/module.hlinux/nvmem-provider.hlinux/pm_runtime.hlinux/sched/signal.hlinux/sizes.hlinux/slab.hlinux/string_helpers.htb.h
Detected Declarations
struct nvm_auth_statusstruct tb_sw_lookupfunction list_for_each_entryfunction nvm_get_auth_statusfunction nvm_set_auth_statusfunction nvm_clear_auth_statusfunction nvm_validate_and_writefunction nvm_authenticate_host_dma_portfunction firstfunction nvm_authenticate_device_dma_portfunction nvm_authenticate_start_dma_portfunction nvm_authenticate_complete_dma_portfunction nvm_readablefunction nvm_upgradeablefunction nvm_authenticatefunction tb_switch_nvm_readfunction nvm_readfunction nvm_writefunction tb_switch_nvm_initfunction tb_switch_nvm_addfunction tb_switch_nvm_removefunction tb_dump_portfunction tb_port_statefunction tb_wait_for_portfunction tb_port_add_nfc_creditsfunction tb_port_clear_counterfunction tb_port_unlockfunction __tb_port_enablefunction tb_port_enablefunction tb_port_disablefunction tb_port_resetfunction tb_init_portfunction tb_port_alloc_hopidfunction tb_port_alloc_in_hopidfunction tb_port_alloc_out_hopidfunction tb_port_release_in_hopidfunction tb_port_release_out_hopidfunction tb_switch_is_reachablefunction tb_next_port_on_pathfunction tb_port_get_link_speedfunction tb_port_get_link_generationfunction tb_port_get_link_widthfunction tb_port_width_supportedfunction tb_port_set_link_widthfunction tb_port_set_lane_bondingfunction tb_port_lane_bonding_enablefunction tb_port_lane_bonding_disablefunction tb_port_wait_for_link_width
Annotated Snippet
ret = device_add(&sw->dev);
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",
sw->vendor, sw->device);
if (sw->vendor_name && sw->device_name)
dev_info(&sw->dev, "%s %s\n", sw->vendor_name,
sw->device_name);
}
ret = usb4_switch_add_ports(sw);
if (ret) {
dev_err(&sw->dev, "failed to add USB4 ports\n");
goto err_del;
}
ret = tb_switch_nvm_add(sw);
if (ret) {
dev_err(&sw->dev, "failed to add NVM devices\n");
goto err_ports;
}
/*
* Thunderbolt routers do not generate wakeups themselves but
* they forward wakeups from tunneled protocols, so enable it
* here.
*/
device_init_wakeup(&sw->dev, true);
pm_runtime_set_active(&sw->dev);
if (sw->rpm) {
pm_runtime_set_autosuspend_delay(&sw->dev, TB_AUTOSUSPEND_DELAY);
pm_runtime_use_autosuspend(&sw->dev);
pm_runtime_mark_last_busy(&sw->dev);
pm_runtime_enable(&sw->dev);
pm_request_autosuspend(&sw->dev);
}
tb_switch_debugfs_init(sw);
return 0;
err_ports:
usb4_switch_remove_ports(sw);
err_del:
device_del(&sw->dev);
return ret;
}
/**
* tb_switch_remove() - Remove and release a switch
* @sw: Switch to remove
*
* This will remove the switch from the domain and release it after last
* reference count drops to zero. If there are switches connected below
* this switch, they will be removed as well.
*/
void tb_switch_remove(struct tb_switch *sw)
{
struct tb_port *port;
tb_switch_debugfs_remove(sw);
if (sw->rpm) {
pm_runtime_get_sync(&sw->dev);
pm_runtime_disable(&sw->dev);
}
/* port 0 is the switch itself and never has a remote */
tb_switch_for_each_port(sw, port) {
if (tb_port_has_remote(port)) {
tb_switch_remove(port->remote->sw);
port->remote = NULL;
} else if (port->xdomain) {
port->xdomain->is_unplugged = true;
tb_xdomain_remove(port->xdomain);
port->xdomain = NULL;
}
/* Remove any downstream retimers */
tb_retimer_remove_all(port);
}
if (!sw->is_unplugged)
tb_plug_events_active(sw, false);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/hex.h`, `linux/idr.h`, `linux/module.h`, `linux/nvmem-provider.h`, `linux/pm_runtime.h`, `linux/sched/signal.h`, `linux/sizes.h`.
- Detected declarations: `struct nvm_auth_status`, `struct tb_sw_lookup`, `function list_for_each_entry`, `function nvm_get_auth_status`, `function nvm_set_auth_status`, `function nvm_clear_auth_status`, `function nvm_validate_and_write`, `function nvm_authenticate_host_dma_port`, `function first`, `function nvm_authenticate_device_dma_port`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.