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.
- 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/kref.hlinux/slab.hlinux/sched/mm.hrdma/ib_umem.hmlx5_ib.h
Detected Declarations
struct mlx5_ib_user_db_pagefunction mlx5_ib_db_map_user_descfunction list_for_each_entryfunction mlx5_ib_db_map_userfunction mlx5_ib_db_unmap_user
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
- Immediate include surface: `linux/kref.h`, `linux/slab.h`, `linux/sched/mm.h`, `rdma/ib_umem.h`, `mlx5_ib.h`.
- Detected declarations: `struct mlx5_ib_user_db_page`, `function mlx5_ib_db_map_user_desc`, `function list_for_each_entry`, `function mlx5_ib_db_map_user`, `function mlx5_ib_db_unmap_user`.
- 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.