drivers/net/ethernet/mellanox/mlx4/cq.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx4/cq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx4/cq.c- Extension
.c- Size
- 13412 bytes
- Lines
- 490
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- 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/hardirq.hlinux/export.hlinux/mlx4/cmd.hlinux/mlx4/cq.hmlx4.hicm.h
Detected Declarations
function Copyrightfunction list_for_each_entry_safefunction mlx4_add_cq_to_taskletfunction mlx4_cq_completionfunction mlx4_cq_eventfunction mlx4_SW2HW_CQfunction mlx4_MODIFY_CQfunction mlx4_HW2SW_CQfunction mlx4_cq_modifyfunction mlx4_cq_resizefunction __mlx4_cq_alloc_icmfunction mlx4_cq_alloc_icmfunction __mlx4_cq_free_icmfunction mlx4_cq_free_icmfunction mlx4_init_user_cqesfunction mlx4_init_kernel_cqesfunction mlx4_cq_allocfunction mlx4_cq_freefunction mlx4_init_cq_tablefunction mlx4_cleanup_cq_tableexport mlx4_cq_modifyexport mlx4_cq_resizeexport mlx4_cq_allocexport mlx4_cq_free
Annotated Snippet
if (WARN_ON_ONCE(copy_bytes > PAGE_SIZE)) {
err = -EINVAL;
goto out;
}
err = copy_to_user((void __user *)buf, init_ents,
copy_bytes) ?
-EFAULT : 0;
}
out:
kfree(init_ents);
return err;
}
static void mlx4_init_kernel_cqes(struct mlx4_buf *buf,
int entries,
int cqe_size)
{
int i;
if (buf->nbufs == 1)
memset(buf->direct.buf, 0xcc, entries * cqe_size);
else
for (i = 0; i < buf->npages; i++)
memset(buf->page_list[i].buf, 0xcc,
1UL << buf->page_shift);
}
int mlx4_cq_alloc(struct mlx4_dev *dev, int nent,
struct mlx4_mtt *mtt, struct mlx4_uar *uar, u64 db_rec,
struct mlx4_cq *cq, unsigned vector, int collapsed,
int timestamp_en, void *buf_addr, bool user_cq)
{
bool sw_cq_init = dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SW_CQ_INIT;
struct mlx4_priv *priv = mlx4_priv(dev);
struct mlx4_cq_table *cq_table = &priv->cq_table;
struct mlx4_cmd_mailbox *mailbox;
struct mlx4_cq_context *cq_context;
u64 mtt_addr;
int err;
if (vector >= dev->caps.num_comp_vectors)
return -EINVAL;
cq->vector = vector;
err = mlx4_cq_alloc_icm(dev, &cq->cqn, cq->usage);
if (err)
return err;
spin_lock(&cq_table->lock);
err = radix_tree_insert(&cq_table->tree, cq->cqn, cq);
spin_unlock(&cq_table->lock);
if (err)
goto err_icm;
mailbox = mlx4_alloc_cmd_mailbox(dev);
if (IS_ERR(mailbox)) {
err = PTR_ERR(mailbox);
goto err_radix;
}
cq_context = mailbox->buf;
cq_context->flags = cpu_to_be32(!!collapsed << 18);
if (timestamp_en)
cq_context->flags |= cpu_to_be32(1 << 19);
cq_context->logsize_usrpage =
cpu_to_be32((ilog2(nent) << 24) |
mlx4_to_hw_uar_index(dev, uar->index));
cq_context->comp_eqn = priv->eq_table.eq[MLX4_CQ_TO_EQ_VECTOR(vector)].eqn;
cq_context->log_page_size = mtt->page_shift - MLX4_ICM_PAGE_SHIFT;
mtt_addr = mlx4_mtt_addr(dev, mtt);
cq_context->mtt_base_addr_h = mtt_addr >> 32;
cq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
cq_context->db_rec_addr = cpu_to_be64(db_rec);
if (sw_cq_init) {
if (user_cq) {
err = mlx4_init_user_cqes(buf_addr, nent,
dev->caps.cqe_size);
if (err)
sw_cq_init = false;
} else {
mlx4_init_kernel_cqes(buf_addr, nent,
dev->caps.cqe_size);
}
Annotation
- Immediate include surface: `linux/hardirq.h`, `linux/export.h`, `linux/mlx4/cmd.h`, `linux/mlx4/cq.h`, `mlx4.h`, `icm.h`.
- Detected declarations: `function Copyright`, `function list_for_each_entry_safe`, `function mlx4_add_cq_to_tasklet`, `function mlx4_cq_completion`, `function mlx4_cq_event`, `function mlx4_SW2HW_CQ`, `function mlx4_MODIFY_CQ`, `function mlx4_HW2SW_CQ`, `function mlx4_cq_modify`, `function mlx4_cq_resize`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.
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.