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.

Dependency Surface

Detected Declarations

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

Implementation Notes