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.
- 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.
- 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/debugfs.hlinux/mlx5/qp.hlinux/mlx5/cq.hlinux/mlx5/driver.hmlx5_core.hlib/eq.h
Detected Declarations
function mlx5_register_debugfsfunction mlx5_unregister_debugfsfunction mlx5_qp_debugfs_initfunction mlx5_qp_debugfs_cleanupfunction mlx5_eq_debugfs_initfunction mlx5_eq_debugfs_cleanupfunction average_readfunction reset_writefunction slots_readfunction mlx5_cmdif_alloc_statsfunction mlx5_cmdif_debugfs_initfunction mlx5_cmdif_debugfs_cleanupfunction mlx5_cq_debugfs_initfunction mlx5_cq_debugfs_cleanupfunction mlx5_pages_debugfs_initfunction mlx5_pages_debugfs_cleanupfunction mlx5_pages_by_func_type_debugfs_initfunction mlx5_pages_by_func_type_debugfs_cleanupfunction qp_read_fieldfunction eq_read_fieldfunction cq_read_fieldfunction dbg_readfunction add_res_treefunction rem_res_treefunction mlx5_debug_qp_addfunction mlx5_debug_qp_removefunction mlx5_debug_eq_addfunction mlx5_debug_eq_removefunction mlx5_debug_cq_addfunction mlx5_debug_cq_removefunction vhca_id_showfunction mlx5_vhca_debugfs_initexport mlx5_debugfs_rootexport mlx5_debugfs_get_dev_rootexport mlx5_qp_debugfs_initexport mlx5_qp_debugfs_cleanupexport mlx5_debug_qp_addexport mlx5_debug_qp_remove
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
- Immediate include surface: `linux/debugfs.h`, `linux/mlx5/qp.h`, `linux/mlx5/cq.h`, `linux/mlx5/driver.h`, `mlx5_core.h`, `lib/eq.h`.
- Detected declarations: `function mlx5_register_debugfs`, `function mlx5_unregister_debugfs`, `function mlx5_qp_debugfs_init`, `function mlx5_qp_debugfs_cleanup`, `function mlx5_eq_debugfs_init`, `function mlx5_eq_debugfs_cleanup`, `function average_read`, `function reset_write`, `function slots_read`, `function mlx5_cmdif_alloc_stats`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern 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.