drivers/infiniband/hw/hns/hns_roce_pd.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_pd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_pd.c- Extension
.c- Size
- 4825 bytes
- Lines
- 172
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
rdma/uverbs_ioctl.hhns_roce_device.h
Detected Declarations
function Copyrightfunction hns_roce_alloc_pdfunction hns_roce_dealloc_pdfunction hns_roce_uar_allocfunction hns_roce_init_uar_tablefunction hns_roce_xrcd_allocfunction hns_roce_init_xrcd_tablefunction hns_roce_alloc_xrcdfunction hns_roce_dealloc_xrcd
Annotated Snippet
#include <rdma/uverbs_ioctl.h>
#include "hns_roce_device.h"
void hns_roce_init_pd_table(struct hns_roce_dev *hr_dev)
{
struct hns_roce_ida *pd_ida = &hr_dev->pd_ida;
ida_init(&pd_ida->ida);
pd_ida->max = hr_dev->caps.num_pds - 1;
pd_ida->min = hr_dev->caps.reserved_pds;
}
int hns_roce_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
{
struct ib_device *ib_dev = ibpd->device;
struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev);
struct hns_roce_ida *pd_ida = &hr_dev->pd_ida;
struct hns_roce_pd *pd = to_hr_pd(ibpd);
int ret = 0;
int id;
id = ida_alloc_range(&pd_ida->ida, pd_ida->min, pd_ida->max,
GFP_KERNEL);
if (id < 0) {
ibdev_err(ib_dev, "failed to alloc pd, id = %d.\n", id);
return -ENOMEM;
}
pd->pdn = (unsigned long)id;
if (udata) {
struct hns_roce_ib_alloc_pd_resp resp = {.pdn = pd->pdn};
ret = ib_respond_udata(udata, resp);
if (ret)
ida_free(&pd_ida->ida, id);
}
return ret;
}
int hns_roce_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata)
{
struct hns_roce_dev *hr_dev = to_hr_dev(pd->device);
ida_free(&hr_dev->pd_ida.ida, (int)to_hr_pd(pd)->pdn);
return 0;
}
int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
{
struct hns_roce_ida *uar_ida = &hr_dev->uar_ida;
int id;
/* Using bitmap to manager UAR index */
id = ida_alloc_range(&uar_ida->ida, uar_ida->min, uar_ida->max,
GFP_KERNEL);
if (id < 0) {
ibdev_err(&hr_dev->ib_dev, "failed to alloc uar id(%d).\n", id);
return -ENOMEM;
}
uar->logic_idx = (unsigned long)id;
if (uar->logic_idx > 0 && hr_dev->caps.phy_num_uars > 1)
uar->index = (uar->logic_idx - 1) %
(hr_dev->caps.phy_num_uars - 1) + 1;
else
uar->index = 0;
uar->pfn = ((pci_resource_start(hr_dev->pci_dev, 2)) >> PAGE_SHIFT);
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_DIRECT_WQE)
hr_dev->dwqe_page = pci_resource_start(hr_dev->pci_dev, 4);
return 0;
}
void hns_roce_init_uar_table(struct hns_roce_dev *hr_dev)
{
struct hns_roce_ida *uar_ida = &hr_dev->uar_ida;
ida_init(&uar_ida->ida);
uar_ida->max = hr_dev->caps.num_uars - 1;
uar_ida->min = hr_dev->caps.reserved_uars;
}
static int hns_roce_xrcd_alloc(struct hns_roce_dev *hr_dev, u32 *xrcdn)
{
struct hns_roce_ida *xrcd_ida = &hr_dev->xrcd_ida;
int id;
Annotation
- Immediate include surface: `rdma/uverbs_ioctl.h`, `hns_roce_device.h`.
- Detected declarations: `function Copyright`, `function hns_roce_alloc_pd`, `function hns_roce_dealloc_pd`, `function hns_roce_uar_alloc`, `function hns_roce_init_uar_table`, `function hns_roce_xrcd_alloc`, `function hns_roce_init_xrcd_table`, `function hns_roce_alloc_xrcd`, `function hns_roce_dealloc_xrcd`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: source implementation candidate.
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.