drivers/infiniband/hw/hns/hns_roce_srq.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_srq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_srq.c- Extension
.c- Size
- 12865 bytes
- Lines
- 526
- 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
rdma/ib_umem.hrdma/uverbs_ioctl.hhns_roce_device.hhns_roce_cmd.hhns_roce_hem.h
Detected Declarations
function Copyrightfunction hns_roce_ib_srq_eventfunction alloc_srqnfunction free_srqnfunction hns_roce_create_srqcfunction alloc_srqcfunction free_srqcfunction alloc_srq_idxfunction free_srq_idxfunction alloc_srq_wqe_buffunction free_srq_wqe_buffunction alloc_srq_wridfunction free_srq_wridfunction proc_srq_sgefunction set_srq_basic_paramfunction set_srq_ext_paramfunction set_srq_paramfunction alloc_srq_buffunction free_srq_buffunction free_srq_dbfunction alloc_srq_dbfunction hns_roce_create_srqfunction hns_roce_destroy_srqfunction hns_roce_init_srq_table
Annotated Snippet
switch (event_type) {
case HNS_ROCE_EVENT_TYPE_SRQ_LIMIT_REACH:
event.event = IB_EVENT_SRQ_LIMIT_REACHED;
break;
case HNS_ROCE_EVENT_TYPE_SRQ_CATAS_ERROR:
event.event = IB_EVENT_SRQ_ERR;
break;
default:
dev_err(hr_dev->dev,
"hns_roce:Unexpected event type %d on SRQ %06lx\n",
event_type, srq->srqn);
return;
}
ibsrq->event_handler(&event, ibsrq->srq_context);
}
}
static int alloc_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{
struct hns_roce_ida *srq_ida = &hr_dev->srq_table.srq_ida;
int id;
id = ida_alloc_range(&srq_ida->ida, srq_ida->min, srq_ida->max,
GFP_KERNEL);
if (id < 0) {
ibdev_err(&hr_dev->ib_dev, "failed to alloc srq(%d).\n", id);
return -ENOMEM;
}
srq->srqn = id;
return 0;
}
static void free_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{
ida_free(&hr_dev->srq_table.srq_ida.ida, (int)srq->srqn);
}
static int hns_roce_create_srqc(struct hns_roce_dev *hr_dev,
struct hns_roce_srq *srq)
{
struct ib_device *ibdev = &hr_dev->ib_dev;
struct hns_roce_cmd_mailbox *mailbox;
int ret;
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
if (IS_ERR(mailbox)) {
ibdev_err(ibdev, "failed to alloc mailbox for SRQC.\n");
return PTR_ERR(mailbox);
}
ret = hr_dev->hw->write_srqc(srq, mailbox->buf);
if (ret) {
ibdev_err(ibdev, "failed to write SRQC.\n");
goto err_mbox;
}
ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_SRQ,
srq->srqn);
if (ret)
ibdev_err_ratelimited(ibdev, "failed to config SRQC, ret = %d.\n", ret);
err_mbox:
hns_roce_free_cmd_mailbox(hr_dev, mailbox);
return ret;
}
static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
{
struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
struct ib_device *ibdev = &hr_dev->ib_dev;
int ret;
ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn);
if (ret) {
ibdev_err(ibdev, "failed to get SRQC table, ret = %d.\n", ret);
return ret;
}
ret = xa_err(xa_store_irq(&srq_table->xa, srq->srqn, srq, GFP_KERNEL));
if (ret) {
ibdev_err(ibdev, "failed to store SRQC, ret = %d.\n", ret);
goto err_put;
}
ret = hns_roce_create_srqc(hr_dev, srq);
if (ret)
goto err_xa;
Annotation
- Immediate include surface: `rdma/ib_umem.h`, `rdma/uverbs_ioctl.h`, `hns_roce_device.h`, `hns_roce_cmd.h`, `hns_roce_hem.h`.
- Detected declarations: `function Copyright`, `function hns_roce_ib_srq_event`, `function alloc_srqn`, `function free_srqn`, `function hns_roce_create_srqc`, `function alloc_srqc`, `function free_srqc`, `function alloc_srq_idx`, `function free_srq_idx`, `function alloc_srq_wqe_buf`.
- 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.