drivers/ntb/test/ntb_tool.c
Source file repositories/reference/linux-study-clean/drivers/ntb/test/ntb_tool.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/ntb/test/ntb_tool.c- Extension
.c- Size
- 43426 bytes
- Lines
- 1688
- Domain
- Driver Families
- Bucket
- drivers/ntb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/init.hlinux/kernel.hlinux/module.hlinux/debugfs.hlinux/dma-mapping.hlinux/pci.hlinux/slab.hlinux/uaccess.hlinux/ntb.h
Detected Declarations
struct tool_mwstruct tool_mw_wrapstruct tool_msgstruct tool_spadstruct tool_peerstruct tool_ctxfunction tool_link_eventfunction tool_db_eventfunction tool_msg_eventfunction tool_fn_readfunction tool_fn_writefunction tool_port_readfunction tool_peer_port_readfunction tool_init_peersfunction tool_link_writefunction tool_peer_link_readfunction tool_peer_link_event_writefunction tool_mw_readfunction tool_mw_writefunction tool_setup_mwfunction tool_free_mwfunction tool_mw_trans_readfunction tool_mw_trans_writefunction tool_peer_mw_readfunction tool_peer_mw_writefunction tool_setup_peer_mwfunction tool_free_peer_mwfunction tool_peer_mw_trans_readfunction tool_peer_mw_trans_writefunction tool_init_mwsfunction tool_clear_mwsfunction tool_db_readfunction tool_db_writefunction tool_db_valid_mask_readfunction tool_db_mask_readfunction tool_db_mask_writefunction tool_peer_db_readfunction tool_peer_db_writefunction tool_peer_db_mask_readfunction tool_peer_db_mask_writefunction tool_db_event_writefunction tool_spad_readfunction tool_spad_writefunction tool_peer_spad_readfunction tool_peer_spad_writefunction tool_init_spadsfunction tool_inmsg_readfunction tool_outmsg_write
Annotated Snippet
const struct file_operations __name = { \
.owner = THIS_MODULE, \
.open = simple_open, \
.read = __read, \
.write = __write, \
}
#define TOOL_BUF_LEN 32
static struct dentry *tool_dbgfs_topdir;
/*==============================================================================
* NTB events handlers
*==============================================================================
*/
static void tool_link_event(void *ctx)
{
struct tool_ctx *tc = ctx;
enum ntb_speed speed;
enum ntb_width width;
int up;
up = ntb_link_is_up(tc->ntb, &speed, &width);
dev_dbg(&tc->ntb->dev, "link is %s speed %d width %d\n",
up ? "up" : "down", speed, width);
wake_up(&tc->link_wq);
}
static void tool_db_event(void *ctx, int vec)
{
struct tool_ctx *tc = ctx;
u64 db_bits, db_mask;
db_mask = ntb_db_vector_mask(tc->ntb, vec);
db_bits = ntb_db_read(tc->ntb);
dev_dbg(&tc->ntb->dev, "doorbell vec %d mask %#llx bits %#llx\n",
vec, db_mask, db_bits);
wake_up(&tc->db_wq);
}
static void tool_msg_event(void *ctx)
{
struct tool_ctx *tc = ctx;
u64 msg_sts;
msg_sts = ntb_msg_read_sts(tc->ntb);
dev_dbg(&tc->ntb->dev, "message bits %#llx\n", msg_sts);
wake_up(&tc->msg_wq);
}
static const struct ntb_ctx_ops tool_ops = {
.link_event = tool_link_event,
.db_event = tool_db_event,
.msg_event = tool_msg_event
};
/*==============================================================================
* Common read/write methods
*==============================================================================
*/
static ssize_t tool_fn_read(struct tool_ctx *tc, char __user *ubuf,
size_t size, loff_t *offp,
u64 (*fn_read)(struct ntb_dev *))
{
size_t buf_size;
char buf[TOOL_BUF_LEN];
ssize_t pos;
if (!fn_read)
return -EINVAL;
buf_size = min(size, sizeof(buf));
pos = scnprintf(buf, buf_size, "%#llx\n", fn_read(tc->ntb));
return simple_read_from_buffer(ubuf, size, offp, buf, pos);
}
static ssize_t tool_fn_write(struct tool_ctx *tc,
const char __user *ubuf,
size_t size, loff_t *offp,
int (*fn_set)(struct ntb_dev *, u64),
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/debugfs.h`, `linux/dma-mapping.h`, `linux/pci.h`, `linux/slab.h`, `linux/uaccess.h`.
- Detected declarations: `struct tool_mw`, `struct tool_mw_wrap`, `struct tool_msg`, `struct tool_spad`, `struct tool_peer`, `struct tool_ctx`, `function tool_link_event`, `function tool_db_event`, `function tool_msg_event`, `function tool_fn_read`.
- Atlas domain: Driver Families / drivers/ntb.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.