drivers/infiniband/hw/mlx5/doorbell.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mlx5/doorbell.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/hw/mlx5/doorbell.c
Extension
.c
Size
4721 bytes
Lines
173
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

struct mlx5_ib_user_db_page {
	struct list_head	list;
	struct ib_umem	       *umem;
	struct ib_uverbs_buffer_desc desc;
	int			refcnt;
	struct mm_struct	*mm;
};

static int mlx5_ib_db_map_user_desc(struct mlx5_ib_ucontext *context,
				    const struct ib_uverbs_buffer_desc *desc,
				    struct mlx5_db *db)
{
	struct mlx5_ib_user_db_page *page;
	struct ib_umem *umem;
	int err = 0;

	if (desc->length < MLX5_IB_DBR_SIZE)
		return -EINVAL;
	/*
	 * For VA descriptors the umem is normalized to a single PAGE_SIZE
	 * region, so reject offsets that would place the 8-byte DBR
	 * straddling the page boundary.
	 */
	if (desc->type == IB_UVERBS_BUFFER_TYPE_VA &&
	    (desc->addr & ~PAGE_MASK) > PAGE_SIZE - MLX5_IB_DBR_SIZE)
		return -EINVAL;

	mutex_lock(&context->db_page_mutex);

	/*
	 * Only VA-typed descriptors are eligible to share a per-page
	 * doorbell umem; FD-typed descriptors are pinned individually.
	 */
	if (desc->type == IB_UVERBS_BUFFER_TYPE_VA) {
		list_for_each_entry(page, &context->db_page_list, list) {
			if (current->mm != page->mm)
				continue;
			if (page->desc.addr == (desc->addr & PAGE_MASK))
				goto found;
		}
	}

	page = kzalloc_obj(*page);
	if (!page) {
		err = -ENOMEM;
		goto out;
	}

	page->desc = *desc;

	/*
	 * Normalize VA descriptors to a page-aligned PAGE_SIZE region so
	 * multiple DBRs that fall in the same user page share one umem.
	 */
	if (page->desc.type == IB_UVERBS_BUFFER_TYPE_VA) {
		page->desc.addr &= PAGE_MASK;
		page->desc.length = PAGE_SIZE;
	}

	umem = ib_umem_get_desc(context->ibucontext.device, &page->desc, 0);
	if (IS_ERR(umem)) {
		err = PTR_ERR(umem);
		kfree(page);
		goto out;
	}

	/*
	 * The 8-byte DBR is programmed to the device as one DMA address,
	 * so it must live in a single contiguous DMA segment.
	 */
	if (!ib_umem_is_contiguous(umem)) {
		ib_umem_release(umem);
		kfree(page);
		err = -EINVAL;
		goto out;
	}

	page->umem = umem;
	if (page->desc.type == IB_UVERBS_BUFFER_TYPE_VA) {
		mmgrab(current->mm);
		page->mm = current->mm;
	}
	list_add(&page->list, &context->db_page_list);

found:
	db->dma = sg_dma_address(page->umem->sgt_append.sgt.sgl) +
		  (desc->addr & ~PAGE_MASK);
	db->u.user_page = page;
	++page->refcnt;

Annotation

Implementation Notes