drivers/infiniband/hw/mlx4/cq.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mlx4/cq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/mlx4/cq.c- Extension
.c- Size
- 26361 bytes
- Lines
- 1028
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/mlx4/cq.hlinux/mlx4/qp.hlinux/mlx4/srq.hlinux/slab.hmlx4_ib.hrdma/mlx4-abi.hrdma/uverbs_ioctl.h
Detected Declarations
function Copyrightfunction mlx4_ib_cq_eventfunction mlx4_ib_modify_cqfunction mlx4_ib_alloc_cq_buffunction mlx4_ib_free_cq_buffunction mlx4_ib_create_user_cqfunction mlx4_ib_create_cqfunction mlx4_alloc_resize_buffunction mlx4_alloc_resize_umemfunction mlx4_ib_get_outstanding_cqesfunction mlx4_ib_cq_resize_copy_cqesfunction mlx4_ib_resize_cqfunction mlx4_ib_destroy_cqfunction dump_cqefunction mlx4_ib_handle_error_cqefunction mlx4_ib_ipoib_csum_okfunction use_tunnel_datafunction mlx4_ib_qp_sw_compfunction mlx4_ib_poll_sw_compfunction list_for_each_entryfunction mlx4_ib_poll_onefunction mlx4_ib_poll_cqfunction mlx4_ib_arm_cqfunction __mlx4_ib_cq_cleanfunction mlx4_ib_cq_clean
Annotated Snippet
if (dev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SW_CQ_INIT) {
err = -EOPNOTSUPP;
goto err_umem;
}
} else {
cq->umem = ib_umem_get_va(&dev->ib_dev, ucmd.buf_addr,
entries * cqe_size,
IB_ACCESS_LOCAL_WRITE);
if (IS_ERR(cq->umem)) {
err = PTR_ERR(cq->umem);
goto err_cq;
}
}
buf_addr = (void *)(unsigned long)ucmd.buf_addr;
shift = mlx4_ib_umem_calc_optimal_mtt_size(cq->umem, 0, &n);
if (shift < 0) {
err = shift;
goto err_umem;
}
err = mlx4_mtt_init(dev->dev, n, shift, &cq->buf.mtt);
if (err)
goto err_umem;
err = mlx4_ib_umem_write_mtt(dev, &cq->buf.mtt, cq->umem);
if (err)
goto err_mtt;
err = mlx4_ib_db_map_user(udata, ucmd.db_addr, &cq->db);
if (err)
goto err_mtt;
if (dev->eq_table)
vector = dev->eq_table[vector % ibdev->num_comp_vectors];
err = mlx4_cq_alloc(dev->dev, entries, &cq->buf.mtt, &context->uar,
cq->db.dma, &cq->mcq, vector, 0,
attr->flags & IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION,
buf_addr, true);
if (err)
goto err_dbmap;
cq->mcq.tasklet_ctx.comp = mlx4_ib_cq_comp;
cq->mcq.event = mlx4_ib_cq_event;
cq->mcq.usage = MLX4_RES_USAGE_USER_VERBS;
uresp.cqn = cq->mcq.cqn;
err = ib_respond_udata(udata, uresp);
if (err)
goto err_cq_free;
return 0;
err_cq_free:
mlx4_cq_free(dev->dev, &cq->mcq);
err_dbmap:
mlx4_ib_db_unmap_user(context, &cq->db);
err_mtt:
mlx4_mtt_cleanup(dev->dev, &cq->buf.mtt);
err_umem:
ib_umem_release(cq->umem);
err_cq:
return err;
}
int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
struct uverbs_attr_bundle *attrs)
{
struct ib_device *ibdev = ibcq->device;
int entries = attr->cqe;
int vector = attr->comp_vector;
struct mlx4_ib_dev *dev = to_mdev(ibdev);
struct mlx4_ib_cq *cq = to_mcq(ibcq);
void *buf_addr;
int err;
if (attr->cqe > dev->dev->caps.max_cqes)
return -EINVAL;
entries = roundup_pow_of_two(entries + 1);
cq->ibcq.cqe = entries - 1;
mutex_init(&cq->resize_mutex);
spin_lock_init(&cq->lock);
INIT_LIST_HEAD(&cq->send_qp_list);
Annotation
- Immediate include surface: `linux/mlx4/cq.h`, `linux/mlx4/qp.h`, `linux/mlx4/srq.h`, `linux/slab.h`, `mlx4_ib.h`, `rdma/mlx4-abi.h`, `rdma/uverbs_ioctl.h`.
- Detected declarations: `function Copyright`, `function mlx4_ib_cq_event`, `function mlx4_ib_modify_cq`, `function mlx4_ib_alloc_cq_buf`, `function mlx4_ib_free_cq_buf`, `function mlx4_ib_create_user_cq`, `function mlx4_ib_create_cq`, `function mlx4_alloc_resize_buf`, `function mlx4_alloc_resize_umem`, `function mlx4_ib_get_outstanding_cqes`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source 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.