drivers/thunderbolt/ctl.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/ctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/ctl.c- Extension
.c- Size
- 30371 bytes
- Lines
- 1185
- 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/crc32.hlinux/delay.hlinux/slab.hlinux/pci.hlinux/dmapool.hlinux/workqueue.hctl.htrace.h
Detected Declarations
struct tb_ctlfunction tb_cfg_request_allocfunction tb_cfg_request_getfunction tb_cfg_request_destroyfunction tb_cfg_request_putfunction tb_cfg_request_enqueuefunction tb_cfg_request_dequeuefunction tb_cfg_request_is_activefunction tb_cfg_request_findfunction check_headerfunction check_config_addressfunction decode_errorfunction parse_headerfunction tb_cfg_print_errorfunction tb_crcfunction tb_ctl_pkg_freefunction tb_ctl_tx_callbackfunction tb_cfg_txfunction tb_ctl_handle_eventfunction tb_ctl_rx_submitfunction tb_async_errorfunction tb_ctl_rx_callbackfunction tb_cfg_request_workfunction tb_cfg_requestfunction tb_cfg_request_cancelfunction tb_cfg_request_completefunction tb_cfg_request_syncfunction tb_ctl_allocfunction tb_ctl_freefunction tb_ctl_startfunction tb_ctl_stopfunction tb_cfg_ack_notificationfunction tb_cfg_ack_plugfunction tb_cfg_matchfunction tb_cfg_copyfunction tb_cfg_resetfunction tb_cfg_read_rawfunction tb_cfg_write_rawfunction tb_cfg_get_errorfunction tb_cfg_readfunction tb_cfg_writefunction tb_cfg_get_upstream_port
Annotated Snippet
struct tb_ctl {
struct tb_nhi *nhi;
struct tb_ring *tx;
struct tb_ring *rx;
struct dma_pool *frame_pool;
struct ctl_pkg *rx_packets[TB_CTL_RX_PKG_COUNT];
struct mutex request_queue_lock;
struct list_head request_queue;
bool running;
int timeout_msec;
event_cb callback;
void *callback_data;
int index;
};
#define tb_ctl_WARN(ctl, format, arg...) \
dev_WARN(&(ctl)->nhi->pdev->dev, format, ## arg)
#define tb_ctl_err(ctl, format, arg...) \
dev_err(&(ctl)->nhi->pdev->dev, format, ## arg)
#define tb_ctl_warn(ctl, format, arg...) \
dev_warn(&(ctl)->nhi->pdev->dev, format, ## arg)
#define tb_ctl_info(ctl, format, arg...) \
dev_info(&(ctl)->nhi->pdev->dev, format, ## arg)
#define tb_ctl_dbg(ctl, format, arg...) \
dev_dbg(&(ctl)->nhi->pdev->dev, format, ## arg)
#define tb_ctl_dbg_once(ctl, format, arg...) \
dev_dbg_once(&(ctl)->nhi->pdev->dev, format, ## arg)
static DECLARE_WAIT_QUEUE_HEAD(tb_cfg_request_cancel_queue);
/* Serializes access to request kref_get/put */
static DEFINE_MUTEX(tb_cfg_request_lock);
/**
* tb_cfg_request_alloc() - Allocates a new config request
*
* This is refcounted object so when you are done with this, call
* tb_cfg_request_put() to it.
*
* Return: &struct tb_cfg_request on success, %NULL otherwise.
*/
struct tb_cfg_request *tb_cfg_request_alloc(void)
{
struct tb_cfg_request *req;
req = kzalloc_obj(*req);
if (!req)
return NULL;
kref_init(&req->kref);
return req;
}
/**
* tb_cfg_request_get() - Increase refcount of a request
* @req: Request whose refcount is increased
*/
void tb_cfg_request_get(struct tb_cfg_request *req)
{
mutex_lock(&tb_cfg_request_lock);
kref_get(&req->kref);
mutex_unlock(&tb_cfg_request_lock);
}
static void tb_cfg_request_destroy(struct kref *kref)
{
struct tb_cfg_request *req = container_of(kref, typeof(*req), kref);
kfree(req);
}
/**
* tb_cfg_request_put() - Decrease refcount and possibly release the request
* @req: Request whose refcount is decreased
*
* Call this function when you are done with the request. When refcount
* goes to %0 the object is released.
*/
void tb_cfg_request_put(struct tb_cfg_request *req)
{
mutex_lock(&tb_cfg_request_lock);
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/delay.h`, `linux/slab.h`, `linux/pci.h`, `linux/dmapool.h`, `linux/workqueue.h`, `ctl.h`, `trace.h`.
- Detected declarations: `struct tb_ctl`, `function tb_cfg_request_alloc`, `function tb_cfg_request_get`, `function tb_cfg_request_destroy`, `function tb_cfg_request_put`, `function tb_cfg_request_enqueue`, `function tb_cfg_request_dequeue`, `function tb_cfg_request_is_active`, `function tb_cfg_request_find`, `function check_header`.
- 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.