drivers/net/ethernet/mellanox/mlx5/core/cmd.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/cmd.c- Extension
.c- Size
- 72413 bytes
- Lines
- 2580
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/highmem.hlinux/errno.hlinux/pci.hlinux/dma-mapping.hlinux/slab.hlinux/delay.hlinux/random.hlinux/mlx5/driver.hlinux/mlx5/eq.hlinux/debugfs.hmlx5_core.hlib/eq.hlib/tout.hdiag/cmd_tracepoint.h
Detected Declarations
struct mlx5_ifc_mbox_out_bitsstruct mlx5_ifc_mbox_in_bitsfunction in_to_opcodefunction in_to_uidfunction mlx5_cmd_is_throttle_opcodefunction cmd_alloc_entfunction cmd_free_entfunction alloc_tokenfunction cmd_alloc_indexfunction cmd_free_indexfunction cmd_ent_getfunction cmd_ent_putfunction mlx5_calc_cmd_blocksfunction xor8_buffunction verify_block_sigfunction calc_block_sigfunction calc_chain_sigfunction set_signaturefunction poll_timeoutfunction verify_signaturefunction dump_buffunction mlx5_internal_err_ret_valuefunction cmd_status_to_errfunction mlx5_cmd_out_errfunction cmd_status_printfunction mlx5_cmd_checkfunction dump_commandfunction cb_timeout_handlerfunction opcode_allowedfunction mlx5_cmd_is_downfunction cmd_work_handlerfunction deliv_status_to_errfunction wait_func_handle_exec_timeoutfunction flowfunction wait_funcfunction otherwisefunction for_each_clear_bitfunction dbg_writefunction mlx5_copy_to_msgfunction mlx5_copy_from_msgfunction free_cmd_boxfunction mlx5_free_cmd_msgfunction data_writefunction data_readfunction outlen_readfunction outlen_writefunction set_wqnamefunction clean_debug_files
Annotated Snippet
static const struct file_operations fops = {
.owner = THIS_MODULE,
.open = simple_open,
.write = dbg_write,
};
static int mlx5_copy_to_msg(struct mlx5_cmd_msg *to, void *from, int size,
u8 token)
{
struct mlx5_cmd_prot_block *block;
struct mlx5_cmd_mailbox *next;
int copy;
if (!to || !from)
return -ENOMEM;
copy = min_t(int, size, sizeof(to->first.data));
memcpy(to->first.data, from, copy);
size -= copy;
from += copy;
next = to->next;
while (size) {
if (!next) {
/* this is a BUG */
return -ENOMEM;
}
copy = min_t(int, size, MLX5_CMD_DATA_BLOCK_SIZE);
block = next->buf;
memcpy(block->data, from, copy);
from += copy;
size -= copy;
block->token = token;
next = next->next;
}
return 0;
}
static int mlx5_copy_from_msg(void *to, struct mlx5_cmd_msg *from, int size)
{
struct mlx5_cmd_prot_block *block;
struct mlx5_cmd_mailbox *next;
int copy;
if (!to || !from)
return -ENOMEM;
copy = min_t(int, size, sizeof(from->first.data));
memcpy(to, from->first.data, copy);
size -= copy;
to += copy;
next = from->next;
while (size) {
if (!next) {
/* this is a BUG */
return -ENOMEM;
}
copy = min_t(int, size, MLX5_CMD_DATA_BLOCK_SIZE);
block = next->buf;
memcpy(to, block->data, copy);
to += copy;
size -= copy;
next = next->next;
}
return 0;
}
static struct mlx5_cmd_mailbox *alloc_cmd_box(struct mlx5_core_dev *dev,
gfp_t flags)
{
struct mlx5_cmd_mailbox *mailbox;
mailbox = kmalloc_obj(*mailbox, flags);
if (!mailbox)
return ERR_PTR(-ENOMEM);
mailbox->buf = dma_pool_zalloc(dev->cmd.pool, flags,
&mailbox->dma);
if (!mailbox->buf) {
mlx5_core_dbg(dev, "failed allocation\n");
kfree(mailbox);
return ERR_PTR(-ENOMEM);
}
mailbox->next = NULL;
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/errno.h`, `linux/pci.h`, `linux/dma-mapping.h`, `linux/slab.h`, `linux/delay.h`, `linux/random.h`, `linux/mlx5/driver.h`.
- Detected declarations: `struct mlx5_ifc_mbox_out_bits`, `struct mlx5_ifc_mbox_in_bits`, `function in_to_opcode`, `function in_to_uid`, `function mlx5_cmd_is_throttle_opcode`, `function cmd_alloc_ent`, `function cmd_free_ent`, `function alloc_token`, `function cmd_alloc_index`, `function cmd_free_index`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.