[RDMA v2 06/13] RDMA/bng_re: Add PD verbs

From: Siva Reddy Kallam

Date: Fri Dec 04 2026 - 11:02:10 EST


From: Suresh Rupanagudi <suresh.rupanagudi@xxxxxxxxxxxx>

This patch adds below verbs.
- bng_re_alloc_pd
- bng_re_dealloc_pd

Signed-off-by: Suresh Rupanagudi <suresh.rupanagudi@xxxxxxxxxxxx>
Signed-off-by: Siva Reddy Kallam <siva.kallam@xxxxxxxxxxxx>
Signed-off-by: Sachin Holla <sachin.holla@xxxxxxxxxxxx>
---
drivers/infiniband/hw/bng_re/bng_dev.c | 3 ++
drivers/infiniband/hw/bng_re/bng_res.c | 7 +++-
drivers/infiniband/hw/bng_re/bng_res.h | 3 ++
drivers/infiniband/hw/bng_re/bng_sp.c | 27 ++++++++++++++-
drivers/infiniband/hw/bng_re/bng_sp.h | 8 +++++
drivers/infiniband/hw/bng_re/bng_verbs.c | 43 ++++++++++++++++++++++++
drivers/infiniband/hw/bng_re/bng_verbs.h | 8 +++++
include/uapi/rdma/bng_re-abi.h | 5 +++
8 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/bng_re/bng_dev.c b/drivers/infiniband/hw/bng_re/bng_dev.c
index 34b65b52e7a2..cec881c28640 100644
--- a/drivers/infiniband/hw/bng_re/bng_dev.c
+++ b/drivers/infiniband/hw/bng_re/bng_dev.c
@@ -42,6 +42,9 @@ static const struct ib_device_ops bng_re_dev_ops = {
.mmap_free = bng_re_mmap_free,
.add_gid = bng_re_add_gid,
.del_gid = bng_re_del_gid,
+ .alloc_pd = bng_re_alloc_pd,
+ .dealloc_pd = bng_re_dealloc_pd,
+ INIT_RDMA_OBJ_SIZE(ib_pd, bng_re_pd, ib_pd),
INIT_RDMA_OBJ_SIZE(ib_ucontext, bng_re_ucontext, ib_uctx),
};

diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/hw/bng_re/bng_res.c
index 08ac4d62fd57..471f3bfb71f7 100644
--- a/drivers/infiniband/hw/bng_re/bng_res.c
+++ b/drivers/infiniband/hw/bng_re/bng_res.c
@@ -409,6 +409,7 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res,

void bng_res_free_tbls(struct bng_re_res *res)
{
+ ida_destroy(&res->pd_ida);
mutex_lock(&res->dpi_tbl_lock);
bng_res_free_dpi_tbl(&res->dpi_tbl);
mutex_unlock(&res->dpi_tbl_lock);
@@ -419,10 +420,12 @@ int bng_res_alloc_init_tbls(struct bng_re_res *res)
{
int rc;

+ ida_init(&res->pd_ida);
+
rc = bng_res_alloc_dpi_tbl(res, res->dattr);
if (rc) {
dev_err(&res->pdev->dev, "DPI tbl alloc failed\n");
- return rc;
+ goto free_pd_ida;
}

rc = bng_sp_alloc_sgid_tbl(&res->sgid_tbl,
@@ -436,6 +439,8 @@ int bng_res_alloc_init_tbls(struct bng_re_res *res)

free_dpi_tbl:
bng_res_free_dpi_tbl(&res->dpi_tbl);
+free_pd_ida:
+ ida_destroy(&res->pd_ida);

return rc;
}
diff --git a/drivers/infiniband/hw/bng_re/bng_res.h b/drivers/infiniband/hw/bng_re/bng_res.h
index 77e7c5569833..0c7b7c286a35 100644
--- a/drivers/infiniband/hw/bng_re/bng_res.h
+++ b/drivers/infiniband/hw/bng_re/bng_res.h
@@ -8,6 +8,7 @@
#include "xid_allocator.h"
#include <linux/bnge/hsi.h>
#include <linux/sizes.h>
+#include <linux/idr.h>

#define BNG_NQE_MAX_CNT (128 * 1024)

@@ -226,6 +227,8 @@ struct bng_re_res {
struct xid_manager *qp_xids;
struct xid_manager *ah_xids;
struct bng_re_sgid_tbl sgid_tbl;
+ /* PD ids, 0 .. dattr->max_pd - 1 */
+ struct ida pd_ida;
};

#define to_bng_re_res(ptr, member) container_of(ptr, struct bng_re_res, member)
diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/hw/bng_re/bng_sp.c
index 83921f23a423..786d591a91b3 100644
--- a/drivers/infiniband/hw/bng_re/bng_sp.c
+++ b/drivers/infiniband/hw/bng_re/bng_sp.c
@@ -98,7 +98,7 @@ int bng_re_get_dev_attr(struct bng_re_rcfw *rcfw)
attr->max_mw = le32_to_cpu(sb->max_mw);

attr->max_mr_size = le64_to_cpu(sb->max_mr_size);
- attr->max_pd = 64 * 1024;
+ attr->max_pd = le32_to_cpu(sb->max_pd);
attr->max_raw_ethy_qp = le32_to_cpu(sb->max_raw_eth_qp);
attr->max_ah = le32_to_cpu(sb->max_ah);

@@ -329,3 +329,28 @@ int bng_sp_del_sgid(struct bng_re_sgid_tbl *sgid_tbl, u32 index, bool update)
index, hw_id, sgid_tbl->active);
return 0;
}
+
+/*
+ * PD ids are software only, no firmware command is involved. They are
+ * handed out by an IDA and range over 0 .. max_pd - 1.
+ */
+int bng_sp_alloc_pd(struct bng_re_res *res, struct bng_sp_pd *pd)
+{
+ u32 max_pd = res->dattr->max_pd;
+ int id;
+
+ if (!max_pd)
+ return -ENOSPC;
+
+ id = ida_alloc_max(&res->pd_ida, max_pd - 1, GFP_KERNEL);
+ if (id < 0)
+ return id;
+
+ pd->id = id;
+ return 0;
+}
+
+void bng_sp_dealloc_pd(struct bng_re_res *res, struct bng_sp_pd *pd)
+{
+ ida_free(&res->pd_ida, pd->id);
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_sp.h b/drivers/infiniband/hw/bng_re/bng_sp.h
index c93fe6ec0bcc..e3fa2bcbeae2 100644
--- a/drivers/infiniband/hw/bng_re/bng_sp.h
+++ b/drivers/infiniband/hw/bng_re/bng_sp.h
@@ -52,6 +52,10 @@ static inline bool bng_re_is_internal_queue_memory(u16 dev_cap_flags)
return dev_cap_flags & CREQ_QUERY_FUNC_RESP_SB_INTERNAL_QUEUE_MEMORY;
}

+struct bng_sp_pd {
+ u32 id;
+};
+
int bng_re_get_dev_attr(struct bng_re_rcfw *rcfw);

int bng_sp_alloc_sgid_tbl(struct bng_re_sgid_tbl *sgid_tbl, u16 size);
@@ -66,4 +70,8 @@ int bng_sp_add_sgid(struct bng_re_sgid_tbl *sgid_tbl,

int bng_sp_del_sgid(struct bng_re_sgid_tbl *sgid_tbl, u32 index, bool update);

+int bng_sp_alloc_pd(struct bng_re_res *res, struct bng_sp_pd *pd);
+
+void bng_sp_dealloc_pd(struct bng_re_res *res, struct bng_sp_pd *pd);
+
#endif
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
index 59fa84040476..95317907d612 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.c
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.c
@@ -459,3 +459,46 @@ int bng_re_del_gid(const struct ib_gid_attr *attr, void **context)

return rc;
}
+
+int bng_re_alloc_pd(struct ib_pd *ib_pd, struct ib_udata *udata)
+{
+ struct bng_re_pd *pd = container_of(ib_pd, struct bng_re_pd, ib_pd);
+ struct ib_device *ibdev = ib_pd->device;
+ struct bng_re_dev *rdev = container_of(ibdev, struct bng_re_dev, ibdev);
+ int rc;
+
+ pd->rdev = rdev;
+
+ rc = ib_is_udata_in_empty(udata);
+ if (rc)
+ return rc;
+
+ rc = bng_sp_alloc_pd(&rdev->bng_res, &pd->sp_pd);
+ if (rc) {
+ ibdev_err(&rdev->ibdev, "Failed to allocate PD: %d\n", rc);
+ return rc;
+ }
+
+ if (udata) {
+ struct bng_re_pd_resp resp = {};
+
+ resp.pdid = pd->sp_pd.id;
+ rc = ib_respond_udata(udata, resp);
+ if (rc) {
+ ibdev_err(&rdev->ibdev, "Failed to copy PD udata\n");
+ bng_sp_dealloc_pd(&rdev->bng_res, &pd->sp_pd);
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+int bng_re_dealloc_pd(struct ib_pd *ib_pd, struct ib_udata *udata)
+{
+ struct bng_re_pd *pd = container_of(ib_pd, struct bng_re_pd, ib_pd);
+ struct bng_re_dev *rdev = pd->rdev;
+
+ bng_sp_dealloc_pd(&rdev->bng_res, &pd->sp_pd);
+ return 0;
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.h b/drivers/infiniband/hw/bng_re/bng_verbs.h
index 0357ec9afda4..d73ffb34a56e 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.h
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.h
@@ -28,6 +28,12 @@ struct bng_re_user_mmap_entry {
u8 mmap_flag;
};

+struct bng_re_pd {
+ struct ib_pd ib_pd;
+ struct bng_re_dev *rdev;
+ struct bng_sp_pd sp_pd;
+};
+
int bng_re_query_device(struct ib_device *ibdev, struct ib_device_attr *ib_attr,
struct ib_udata *udata);
int bng_re_modify_device(struct ib_device *ibdev, int device_modify_mask,
@@ -47,4 +53,6 @@ int bng_re_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
void bng_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry);
int bng_re_add_gid(const struct ib_gid_attr *attr, void **context);
int bng_re_del_gid(const struct ib_gid_attr *attr, void **context);
+int bng_re_alloc_pd(struct ib_pd *ib_pd, struct ib_udata *udata);
+int bng_re_dealloc_pd(struct ib_pd *ib_pd, struct ib_udata *udata);
#endif /* __BNG_RE_VERBS_H__ */
diff --git a/include/uapi/rdma/bng_re-abi.h b/include/uapi/rdma/bng_re-abi.h
index d5cda958b0f8..3f571fd35a23 100644
--- a/include/uapi/rdma/bng_re-abi.h
+++ b/include/uapi/rdma/bng_re-abi.h
@@ -39,4 +39,9 @@ struct bng_re_uctx_resp {
__aligned_u64 uc_db_mmap_key;
};

+struct bng_re_pd_resp {
+ __u32 pdid;
+ __u32 comp_mask;
+};
+
#endif /* __BNG_RE_UVERBS_ABI_H__*/
--
2.43.5