drivers/infiniband/hw/hns/hns_roce_mr.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hns/hns_roce_mr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hns/hns_roce_mr.c- Extension
.c- Size
- 27449 bytes
- Lines
- 1109
- 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.
- 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/vmalloc.hlinux/count_zeros.hrdma/ib_umem.hlinux/math.hhns_roce_device.hhns_roce_cmd.hhns_roce_hem.hhns_roce_trace.h
Detected Declarations
function Copyrightfunction key_to_hw_indexfunction alloc_mr_keyfunction free_mr_keyfunction alloc_mr_pblfunction free_mr_pblfunction hns_roce_mr_freefunction hns_roce_mr_enablefunction hns_roce_init_mr_tablefunction hns_roce_dereg_mrfunction hns_roce_set_pagefunction hns_roce_map_mr_sgfunction mtr_map_regionfunction mtr_has_mttfunction mtr_bufs_sizefunction mtr_check_direct_pagesfunction mtr_free_bufsfunction mtr_alloc_bufsfunction cal_mtr_pg_cntfunction need_split_huge_pagefunction mtr_map_bufsfunction hns_roce_mtr_mapfunction hns_roce_get_direct_addr_mttfunction hns_roce_get_mhop_mttfunction hns_roce_mtr_findfunction get_best_page_shiftfunction get_best_hop_numfunction is_buf_attr_validfunction mtr_init_buf_cfgfunction cal_pages_per_l1bafunction cal_best_bt_pg_szfunction for_each_set_bit_fromfunction mtr_alloc_mttfunction mtr_free_mttfunction hns_roce_mtr_createfunction hns_roce_mtr_destroy
Annotated Snippet
if (ret) {
ibdev_err(ib_dev, "failed to alloc mr PBL, ret = %d.\n",
ret);
goto free_cmd_mbox;
}
}
ret = hr_dev->hw->rereg_write_mtpt(hr_dev, mr, flags, mailbox->buf);
if (ret) {
ibdev_err(ib_dev, "failed to write mtpt, ret = %d.\n", ret);
goto free_cmd_mbox;
}
ret = hns_roce_create_hw_ctx(hr_dev, mailbox, HNS_ROCE_CMD_CREATE_MPT,
mtpt_idx);
if (ret) {
ibdev_err_ratelimited(ib_dev, "failed to create MPT, ret = %d.\n", ret);
goto free_cmd_mbox;
}
mr->enabled = 1;
free_cmd_mbox:
hns_roce_free_cmd_mailbox(hr_dev, mailbox);
err_out:
if (ret) {
atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_MR_REREG_ERR_CNT]);
return ERR_PTR(ret);
}
return NULL;
}
int hns_roce_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
{
struct hns_roce_dev *hr_dev = to_hr_dev(ibmr->device);
struct hns_roce_mr *mr = to_hr_mr(ibmr);
if (hr_dev->hw->dereg_mr)
hr_dev->hw->dereg_mr(hr_dev);
hns_roce_mr_free(hr_dev, mr);
kfree(mr);
return 0;
}
struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
u32 max_num_sg)
{
struct hns_roce_dev *hr_dev = to_hr_dev(pd->device);
struct device *dev = hr_dev->dev;
struct hns_roce_mr *mr;
int ret;
if (mr_type != IB_MR_TYPE_MEM_REG)
return ERR_PTR(-EINVAL);
if (max_num_sg > HNS_ROCE_FRMR_MAX_PA) {
dev_err(dev, "max_num_sg larger than %d\n",
HNS_ROCE_FRMR_MAX_PA);
return ERR_PTR(-EINVAL);
}
mr = kzalloc_obj(*mr);
if (!mr)
return ERR_PTR(-ENOMEM);
mr->type = MR_TYPE_FRMR;
mr->pd = to_hr_pd(pd)->pdn;
mr->size = max_num_sg * (1 << PAGE_SHIFT);
/* Allocate memory region key */
ret = alloc_mr_key(hr_dev, mr);
if (ret)
goto err_free;
ret = alloc_mr_pbl(hr_dev, mr, NULL, 0);
if (ret)
goto err_key;
ret = hns_roce_mr_enable(hr_dev, mr);
if (ret)
goto err_pbl;
mr->ibmr.rkey = mr->ibmr.lkey = mr->key;
mr->ibmr.length = mr->size;
return &mr->ibmr;
Annotation
- Immediate include surface: `linux/vmalloc.h`, `linux/count_zeros.h`, `rdma/ib_umem.h`, `linux/math.h`, `hns_roce_device.h`, `hns_roce_cmd.h`, `hns_roce_hem.h`, `hns_roce_trace.h`.
- Detected declarations: `function Copyright`, `function key_to_hw_index`, `function alloc_mr_key`, `function free_mr_key`, `function alloc_mr_pbl`, `function free_mr_pbl`, `function hns_roce_mr_free`, `function hns_roce_mr_enable`, `function hns_roce_init_mr_table`, `function hns_roce_dereg_mr`.
- 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.