drivers/infiniband/hw/mthca/mthca_srq.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mthca/mthca_srq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/mthca/mthca_srq.c- Extension
.c- Size
- 17457 bytes
- Lines
- 699
- 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/slab.hlinux/string.hlinux/sched.hasm/io.hrdma/uverbs_ioctl.hmthca_dev.hmthca_cmd.hmthca_memfree.hmthca_wqe.h
Detected Declarations
struct mthca_tavor_srq_contextstruct mthca_arbel_srq_contextfunction mthca_tavor_init_srq_contextfunction mthca_arbel_init_srq_contextfunction mthca_free_srq_buffunction mthca_alloc_srq_buffunction mthca_alloc_srqfunction get_srq_refcountfunction mthca_free_srqfunction mthca_modify_srqfunction mthca_query_srqfunction mthca_srq_eventfunction mthca_free_srq_wqefunction mthca_tavor_post_srq_recvfunction mthca_arbel_post_srq_recvfunction mthca_max_srq_sgefunction mthca_init_srq_tablefunction mthca_cleanup_srq_table
Annotated Snippet
struct mthca_tavor_srq_context {
__be64 wqe_base_ds; /* low 6 bits is descriptor size */
__be32 state_pd;
__be32 lkey;
__be32 uar;
__be16 limit_watermark;
__be16 wqe_cnt;
u32 reserved[2];
};
struct mthca_arbel_srq_context {
__be32 state_logsize_srqn;
__be32 lkey;
__be32 db_index;
__be32 logstride_usrpage;
__be64 wqe_base;
__be32 eq_pd;
__be16 limit_watermark;
__be16 wqe_cnt;
u16 reserved1;
__be16 wqe_counter;
u32 reserved2[3];
};
static void *get_wqe(struct mthca_srq *srq, int n)
{
if (srq->is_direct)
return srq->queue.direct.buf + (n << srq->wqe_shift);
else
return srq->queue.page_list[(n << srq->wqe_shift) >> PAGE_SHIFT].buf +
((n << srq->wqe_shift) & (PAGE_SIZE - 1));
}
/*
* Return a pointer to the location within a WQE that we're using as a
* link when the WQE is in the free list. We use the imm field
* because in the Tavor case, posting a WQE may overwrite the next
* segment of the previous WQE, but a receive WQE will never touch the
* imm field. This avoids corrupting our free list if the previous
* WQE has already completed and been put on the free list when we
* post the next WQE.
*/
static inline int *wqe_to_link(void *wqe)
{
return (int *) (wqe + offsetof(struct mthca_next_seg, imm));
}
static void mthca_tavor_init_srq_context(struct mthca_dev *dev,
struct mthca_pd *pd,
struct mthca_srq *srq,
struct mthca_tavor_srq_context *context,
struct ib_udata *udata)
{
struct mthca_ucontext *ucontext = rdma_udata_to_drv_context(
udata, struct mthca_ucontext, ibucontext);
memset(context, 0, sizeof *context);
context->wqe_base_ds = cpu_to_be64(1 << (srq->wqe_shift - 4));
context->state_pd = cpu_to_be32(pd->pd_num);
context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);
if (udata)
context->uar = cpu_to_be32(ucontext->uar.index);
else
context->uar = cpu_to_be32(dev->driver_uar.index);
}
static void mthca_arbel_init_srq_context(struct mthca_dev *dev,
struct mthca_pd *pd,
struct mthca_srq *srq,
struct mthca_arbel_srq_context *context,
struct ib_udata *udata)
{
struct mthca_ucontext *ucontext = rdma_udata_to_drv_context(
udata, struct mthca_ucontext, ibucontext);
int logsize, max;
memset(context, 0, sizeof *context);
/*
* Put max in a temporary variable to work around gcc bug
* triggered by ilog2() on sparc64.
*/
max = srq->max;
logsize = ilog2(max);
context->state_logsize_srqn = cpu_to_be32(logsize << 24 | srq->srqn);
context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);
context->db_index = cpu_to_be32(srq->db_index);
context->logstride_usrpage = cpu_to_be32((srq->wqe_shift - 4) << 29);
Annotation
- Immediate include surface: `linux/slab.h`, `linux/string.h`, `linux/sched.h`, `asm/io.h`, `rdma/uverbs_ioctl.h`, `mthca_dev.h`, `mthca_cmd.h`, `mthca_memfree.h`.
- Detected declarations: `struct mthca_tavor_srq_context`, `struct mthca_arbel_srq_context`, `function mthca_tavor_init_srq_context`, `function mthca_arbel_init_srq_context`, `function mthca_free_srq_buf`, `function mthca_alloc_srq_buf`, `function mthca_alloc_srq`, `function get_srq_refcount`, `function mthca_free_srq`, `function mthca_modify_srq`.
- 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.