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.

Dependency Surface

Detected Declarations

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

Implementation Notes