drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
Extension
.c
Size
15651 bytes
Lines
666
Domain
Driver Families
Bucket
drivers/net
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

static const struct file_operations reset_fops = {
	.owner	= THIS_MODULE,
	.open	= simple_open,
	.write	= reset_write,
};

static const struct file_operations average_fops = {
	.owner	= THIS_MODULE,
	.open	= simple_open,
	.read	= average_read,
};

static ssize_t slots_read(struct file *filp, char __user *buf, size_t count,
			  loff_t *pos)
{
	struct mlx5_cmd *cmd;
	char tbuf[6];
	int weight;
	int field;
	int ret;

	cmd = filp->private_data;
	weight = bitmap_weight(&cmd->vars.bitmask, cmd->vars.max_reg_cmds);
	field = cmd->vars.max_reg_cmds - weight;
	ret = snprintf(tbuf, sizeof(tbuf), "%d\n", field);
	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
}

static const struct file_operations slots_fops = {
	.owner	= THIS_MODULE,
	.open	= simple_open,
	.read	= slots_read,
};

static struct mlx5_cmd_stats *
mlx5_cmdif_alloc_stats(struct xarray *stats_xa, int opcode)
{
	struct mlx5_cmd_stats *stats = kzalloc_obj(*stats);
	int err;

	if (!stats)
		return NULL;

	err = xa_insert(stats_xa, opcode, stats, GFP_KERNEL);
	if (err) {
		kfree(stats);
		return NULL;
	}
	spin_lock_init(&stats->lock);
	return stats;
}

void mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev)
{
	struct mlx5_cmd_stats *stats;
	struct dentry **cmd;
	const char *namep;
	int i;

	cmd = &dev->priv.dbg.cmdif_debugfs;
	*cmd = debugfs_create_dir("commands", dev->priv.dbg.dbg_root);

	debugfs_create_file("slots_inuse", 0400, *cmd, &dev->cmd, &slots_fops);

	xa_init(&dev->cmd.stats);

	for (i = 0; i < MLX5_CMD_OP_MAX; i++) {
		namep = mlx5_command_str(i);
		if (strcmp(namep, "unknown command opcode")) {
			stats = mlx5_cmdif_alloc_stats(&dev->cmd.stats, i);
			if (!stats)
				continue;
			stats->root = debugfs_create_dir(namep, *cmd);

			debugfs_create_file("reset", 0200, stats->root, stats,
					    &reset_fops);
			debugfs_create_file("average", 0400, stats->root, stats,
					    &average_fops);
			debugfs_create_u64("n", 0400, stats->root, &stats->n);
			debugfs_create_u64("failed", 0400, stats->root, &stats->failed);
			debugfs_create_u64("failed_mbox_status", 0400, stats->root,
					   &stats->failed_mbox_status);
			debugfs_create_u32("last_failed_errno", 0400, stats->root,
					   &stats->last_failed_errno);
			debugfs_create_u8("last_failed_mbox_status", 0400, stats->root,
					  &stats->last_failed_mbox_status);
			debugfs_create_x32("last_failed_syndrome", 0400, stats->root,
					   &stats->last_failed_syndrome);
		}
	}

Annotation

Implementation Notes