Netdev List
 help / color / mirror / Atom feed
From: Siva Reddy Kallam <siva.kallam@broadcom.com>
To: leonro@nvidia.com, jgg@nvidia.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rdma@vger.kernel.org, vikas.gupta@broadcom.com,
	ajit.khaparde@broadcom.com, dharmender.garg@broadcom.com,
	sachin.holla@broadcom.com,
	Siva Reddy Kallam <siva.kallam@broadcom.com>,
	Shyam Mohan <shyam.mohan@broadcom.com>
Subject: [RDMA v2 04/13] RDMA/bng_re: Add ucontext/mmap verbs
Date: Fri,  4 Dec 2026 07:47:56 -0800	[thread overview]
Message-ID: <20261204155249.1002019-5-siva.kallam@broadcom.com> (raw)
In-Reply-To: <20261204155249.1002019-1-siva.kallam@broadcom.com>

This patch adds below verbs.
- bng_re_alloc_ucontext
- bng_re_dealloc_ucontext
- bng_re_mmap
- bng_re_mmap_free

Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>
Signed-off-by: Shyam Mohan <shyam.mohan@broadcom.com>
Signed-off-by: Sachin Holla <sachin.holla@broadcom.com>
---
 drivers/infiniband/hw/bng_re/bng_dev.c   |  14 ++
 drivers/infiniband/hw/bng_re/bng_re.h    |  14 ++
 drivers/infiniband/hw/bng_re/bng_res.c   | 151 ++++++++++++++++-
 drivers/infiniband/hw/bng_re/bng_res.h   |  34 ++++
 drivers/infiniband/hw/bng_re/bng_sp.h    |   5 +
 drivers/infiniband/hw/bng_re/bng_verbs.c | 199 +++++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_verbs.h |  25 +++
 include/uapi/rdma/bng_re-abi.h           |  30 ++++
 8 files changed, 469 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/bng_re/bng_dev.c b/drivers/infiniband/hw/bng_re/bng_dev.c
index bb29c0f0b2ba..174d0523709e 100644
--- a/drivers/infiniband/hw/bng_re/bng_dev.c
+++ b/drivers/infiniband/hw/bng_re/bng_dev.c
@@ -35,6 +35,12 @@ static const struct ib_device_ops bng_re_dev_ops = {
 	.get_link_layer		= bng_re_get_link_layer,
 	.get_port_immutable	= bng_re_get_port_immutable,
 	.query_pkey		= bng_re_query_pkey,
+	.alloc_ucontext		= bng_re_alloc_ucontext,
+	.dealloc_ucontext	= bng_re_dealloc_ucontext,
+	.disassociate_ucontext	= bng_re_disassociate_ucontext,
+	.mmap			= bng_re_mmap,
+	.mmap_free		= bng_re_mmap_free,
+	INIT_RDMA_OBJ_SIZE(ib_ucontext, bng_re_ucontext, ib_uctx),
 };
 
 static struct bng_re_dev *bng_re_dev_add(struct auxiliary_device *adev,
@@ -55,6 +61,9 @@ static struct bng_re_dev *bng_re_dev_add(struct auxiliary_device *adev,
 	rdev->adev = adev;
 	rdev->fn_id = rdev->aux_dev->pdev->devfn;
 
+	/* Valid for the whole lifetime of rdev, independent of table alloc */
+	mutex_init(&rdev->bng_res.dpi_tbl_lock);
+
 	return rdev;
 }
 
@@ -283,6 +292,9 @@ static int bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 	if (!cctx->hwrm_cmd_max_timeout)
 		cctx->hwrm_cmd_max_timeout = BNG_ROCE_FW_MAX_TIMEOUT;
 
+	cctx->chip_rev = ver_get_resp.chip_rev;
+	cctx->chip_metal = ver_get_resp.chip_metal;
+
 	return 0;
 }
 
@@ -557,6 +569,7 @@ static int bng_re_add_device(struct auxiliary_device *adev)
 	return 0;
 
 re_dev_dealloc:
+	mutex_destroy(&rdev->bng_res.dpi_tbl_lock);
 	ib_dealloc_device(&rdev->ibdev);
 exit:
 	return rc;
@@ -566,6 +579,7 @@ static void bng_re_remove_device(struct bng_re_dev *rdev,
 				 struct auxiliary_device *aux_dev)
 {
 	bng_re_dev_uninit(rdev);
+	mutex_destroy(&rdev->bng_res.dpi_tbl_lock);
 	ib_dealloc_device(&rdev->ibdev);
 }
 
diff --git a/drivers/infiniband/hw/bng_re/bng_re.h b/drivers/infiniband/hw/bng_re/bng_re.h
index d073ccf104e7..b55658f3ab8e 100644
--- a/drivers/infiniband/hw/bng_re/bng_re.h
+++ b/drivers/infiniband/hw/bng_re/bng_re.h
@@ -182,6 +182,20 @@ struct bng_mpc_db {
 	struct bng_re_db_info	dbinfo;
 };
 
+enum bng_re_mmap_flag {
+	BNG_RE_MMAP_UC_DB,
+};
+
+static inline char *bng_re_mmap_str(enum bng_re_mmap_flag mmap_flag)
+{
+	switch (mmap_flag) {
+	case BNG_RE_MMAP_UC_DB:
+		return "BNG_RE_MMAP_UC_DB";
+	default:
+		return "Unknown";
+	}
+}
+
 /* NQ specific structures  */
 struct bng_re_nq_db {
 	struct bng_re_reg_desc	reg;
diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/hw/bng_re/bng_res.c
index c5f9fff56726..6fbe88001eba 100644
--- a/drivers/infiniband/hw/bng_re/bng_res.c
+++ b/drivers/infiniband/hw/bng_re/bng_res.c
@@ -337,11 +337,28 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res,
 {
 	struct bng_re_dpi_tbl *dpit;
 	struct bng_re_reg_desc *reg;
-	unsigned long bar_len;
+	unsigned long bar_len, first_dpi, fw_max;
 
 	dpit = &res->dpi_tbl;
 	reg = &dpit->wcreg;
 
+	/*
+	 * User doorbell pages are mapped one CPU page at a time starting at
+	 * the WC offset, while DPI numbers count HW doorbell pages from the
+	 * UC offset. bnge page-aligns the WC offset but the UC offset only
+	 * has 1KB granularity, so require only HW doorbell page alignment
+	 * of the delta.
+	 */
+	if (reg->offset < dpit->ucreg.offset ||
+	    !IS_ALIGNED(reg->offset, PAGE_SIZE) ||
+	    !IS_ALIGNED(reg->offset - dpit->ucreg.offset,
+			BNG_RE_DB_PAGE_SIZE)) {
+		dev_err(&res->pdev->dev,
+			"Invalid WC DB offset 0x%lx (UC DB offset 0x%lx)\n",
+			reg->offset, dpit->ucreg.offset);
+		return -EINVAL;
+	}
+
 	bar_len = pci_resource_len(res->pdev, reg->bar_id);
 
 	if (reg->offset >= bar_len) {
@@ -353,8 +370,20 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res,
 
 	dpit->max = min_t(unsigned long, (bar_len - reg->offset) / PAGE_SIZE,
 			  U32_MAX);
-	if (dev_attr->max_dpi)
-		dpit->max = min_t(u32, dpit->max, dev_attr->max_dpi);
+	if (dev_attr->max_dpi) {
+		/*
+		 * User DPI values start at first_dpi and step by
+		 * PAGE_SIZE / BNG_RE_DB_PAGE_SIZE per table entry. Keep the
+		 * highest DPI value handed out below the FW max_dpi limit.
+		 */
+		first_dpi = (reg->offset - dpit->ucreg.offset) /
+			    BNG_RE_DB_PAGE_SIZE;
+		fw_max = 0;
+		if (first_dpi < dev_attr->max_dpi)
+			fw_max = (dev_attr->max_dpi - 1 - first_dpi) /
+				 (PAGE_SIZE / BNG_RE_DB_PAGE_SIZE) + 1;
+		dpit->max = min_t(unsigned long, dpit->max, fw_max);
+	}
 	if (!dpit->max) {
 		dev_err(&res->pdev->dev, "No DPIs available in doorbell BAR\n");
 		return -EINVAL;
@@ -380,7 +409,9 @@ static int bng_res_alloc_dpi_tbl(struct bng_re_res *res,
 
 void bng_res_free_tbls(struct bng_re_res *res)
 {
+	mutex_lock(&res->dpi_tbl_lock);
 	bng_res_free_dpi_tbl(&res->dpi_tbl);
+	mutex_unlock(&res->dpi_tbl_lock);
 }
 
 int bng_res_alloc_init_tbls(struct bng_re_res *res)
@@ -393,3 +424,117 @@ int bng_res_alloc_init_tbls(struct bng_re_res *res)
 
 	return rc;
 }
+
+int bng_re_alloc_dpi(struct bng_re_res *res,
+		     struct bng_re_dpi *dpi,
+		     void *app, enum bng_re_dpi_type type)
+{
+	struct bng_re_dpi_tbl *dpit = &res->dpi_tbl;
+	struct bng_re_reg_desc *reg;
+	u32 bit_num;
+	u64 umaddr;
+	int rc = 0;
+
+	reg = &dpit->wcreg;
+	mutex_lock(&res->dpi_tbl_lock);
+	if (!dpit->tbl) {
+		rc = -ENOMEM;
+		goto unlock;
+	}
+	bit_num = find_first_bit(dpit->tbl, dpit->max);
+	if (bit_num >= dpit->max) {
+		rc = -ENOMEM;
+		goto unlock;
+	}
+	clear_bit(bit_num, dpit->tbl);
+	dpit->app_tbl[bit_num] = app;
+	dpi->bit = bit_num;
+	dpi->dpi = (reg->offset - dpit->ucreg.offset +
+		    (unsigned long)bit_num * PAGE_SIZE) / BNG_RE_DB_PAGE_SIZE;
+	umaddr = reg->bar_base + reg->offset + bit_num * PAGE_SIZE;
+	dpi->umdbr = umaddr;
+	switch (type) {
+	case BNG_RE_DPI_TYPE_KERNEL:
+		dpi->umdbr = dpit->ucreg.bar_base +
+			     dpit->ucreg.offset + bit_num * PAGE_SIZE;
+		dpi->dbr = dpit->priv_db;
+		dpi->dpi = dpi->bit;
+		break;
+	case BNG_RE_DPI_TYPE_WC:
+		dpi->dbr = ioremap_wc(umaddr, PAGE_SIZE);
+		if (!dpi->dbr) {
+			dev_err(&res->pdev->dev, "WC DB remap failed\n");
+			rc = -ENOMEM;
+		}
+		break;
+	case BNG_RE_DPI_TYPE_UC:
+		/*
+		 * User space rings this page through its own mmap of umdbr.
+		 * The kernel mapping is kept so that the driver can also ring
+		 * doorbells of user objects on this page; future patches use
+		 * it for doorbell drop recovery and for driver-managed rings
+		 * of user QPs.
+		 */
+		dpi->dbr = ioremap(umaddr, PAGE_SIZE);
+		if (!dpi->dbr) {
+			dev_err(&res->pdev->dev, "UC DB remap failed\n");
+			rc = -ENOMEM;
+		}
+		break;
+	default:
+		rc = -EINVAL;
+		break;
+	}
+
+	if (rc) {
+		set_bit(bit_num, dpit->tbl);
+		dpit->app_tbl[bit_num] = NULL;
+		goto unlock;
+	}
+	dpi->type = type;
+unlock:
+	mutex_unlock(&res->dpi_tbl_lock);
+	return rc;
+}
+
+int bng_re_dealloc_dpi(struct bng_re_res *res,
+		       struct bng_re_dpi *dpi)
+{
+	struct bng_re_dpi_tbl *dpit = &res->dpi_tbl;
+	int rc = 0;
+
+	mutex_lock(&res->dpi_tbl_lock);
+	if (dpi->bit >= dpit->max) {
+		dev_warn(&res->pdev->dev,
+			 "Invalid DPI? dpi = %d, bit = %d\n",
+			 dpi->dpi, dpi->bit);
+		rc = -EINVAL;
+		goto release;
+	}
+
+	/* Check ownership first so a repeated free cannot unmap anything */
+	if (test_and_set_bit(dpi->bit, dpit->tbl)) {
+		dev_warn(&res->pdev->dev,
+			 "Freeing an unused DPI? dpi = %d, bit = %d\n",
+			 dpi->dpi, dpi->bit);
+		dev_warn(&res->pdev->dev,
+			 "umdbr = %lld, dbr = %p, type = %d\n",
+			 dpi->umdbr, dpi->dbr, dpi->type);
+		dev_warn(&res->pdev->dev,
+			 "dpit max = %d, priv_db = %p\n",
+			 dpit->max, dpit->priv_db);
+		rc = -EINVAL;
+		goto unlock;
+	}
+	if (dpit->app_tbl)
+		dpit->app_tbl[dpi->bit] = NULL;
+release:
+	if (dpi->dbr && dpi->type != BNG_RE_DPI_TYPE_KERNEL)
+		iounmap(dpi->dbr);
+	memset(dpi, 0, sizeof(*dpi));
+	/* Bit 0 is a valid index: make a stale dpi fail the range check */
+	dpi->bit = U32_MAX;
+unlock:
+	mutex_unlock(&res->dpi_tbl_lock);
+	return rc;
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_res.h b/drivers/infiniband/hw/bng_re/bng_res.h
index cc1872f3ab54..b43827ee1b18 100644
--- a/drivers/infiniband/hw/bng_re/bng_res.h
+++ b/drivers/infiniband/hw/bng_re/bng_res.h
@@ -7,6 +7,7 @@
 #include "bng_roce_hsi.h"
 #include "xid_allocator.h"
 #include <linux/bnge/hsi.h>
+#include <linux/sizes.h>
 
 #define BNG_NQE_MAX_CNT		(128 * 1024)
 
@@ -91,6 +92,8 @@ struct bng_re_chip_ctx {
 	u64	hwrm_intf_ver;
 	u16	hwrm_cmd_max_timeout;
 	struct bng_re_drv_modes modes;
+	u8	chip_rev;
+	u8	chip_metal;
 };
 
 struct bng_re_pbl {
@@ -156,6 +159,30 @@ struct bng_re_stats {
 	u32				fw_id;
 };
 
+/* DPI types */
+enum bng_re_dpi_type {
+	BNG_RE_DPI_TYPE_KERNEL	= 0,
+	BNG_RE_DPI_TYPE_UC	= 1,
+	BNG_RE_DPI_TYPE_WC	= 2
+};
+
+/* DPI structure */
+struct bng_re_dpi {
+	u32			dpi;
+	u32			bit;
+	u64			umdbr;
+	void __iomem		*dbr;
+	enum bng_re_dpi_type	type;
+};
+
+/*
+ * HW doorbell page size. bnge does not program db_page_size through
+ * HWRM_FUNC_CFG, so firmware uses its 4KB default. DPI numbers are in
+ * units of this size, independent of the CPU PAGE_SIZE; each DPI handed
+ * to user space still owns a full CPU page so mappings never overlap.
+ */
+#define BNG_RE_DB_PAGE_SIZE	SZ_4K
+
 /* DPI table */
 struct bng_re_dpi_tbl {
 	void			**app_tbl;
@@ -171,6 +198,8 @@ struct bng_re_res {
 	struct bng_re_chip_ctx		*cctx;
 	struct bng_re_dev_attr		*dattr;
 	struct bng_re_dpi_tbl		dpi_tbl;
+	/* Serialize access to DPI table */
+	struct mutex			dpi_tbl_lock;
 	struct xid_manager		*qp_xids;
 	struct xid_manager		*ah_xids;
 };
@@ -286,4 +315,9 @@ void bng_res_unmap_db_bar(struct bng_re_res *res);
 int bng_res_map_db_bar(struct bng_re_res *res);
 void bng_res_free_tbls(struct bng_re_res *res);
 int bng_res_alloc_init_tbls(struct bng_re_res *res);
+int bng_re_alloc_dpi(struct bng_re_res *res,
+		     struct bng_re_dpi *dpi,
+		     void *app, enum bng_re_dpi_type type);
+int bng_re_dealloc_dpi(struct bng_re_res *res,
+		       struct bng_re_dpi *dpi);
 #endif
diff --git a/drivers/infiniband/hw/bng_re/bng_sp.h b/drivers/infiniband/hw/bng_re/bng_sp.h
index 2b19b65ae550..d1a93affa22c 100644
--- a/drivers/infiniband/hw/bng_re/bng_sp.h
+++ b/drivers/infiniband/hw/bng_re/bng_sp.h
@@ -47,5 +47,10 @@ struct bng_re_dev_attr {
 	u32                             max_dpi;
 };
 
+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;
+}
+
 int bng_re_get_dev_attr(struct bng_re_rcfw *rcfw);
 #endif
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
index 6750dfa4a168..45ade397342a 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.c
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.c
@@ -191,3 +191,202 @@ int bng_re_query_pkey(struct ib_device *ibdev, u32 port_num,
 
 	return 0;
 }
+
+static struct bng_re_user_mmap_entry*
+bng_re_mmap_entry_insert(struct bng_re_ucontext *uctx, u64 cpu_addr,
+			 u8 user_mmap_hint, u64 *offset)
+{
+	struct bng_re_user_mmap_entry *entry;
+	int ret;
+
+	entry = kzalloc_obj(*entry, GFP_KERNEL);
+	if (!entry)
+		return NULL;
+
+	entry->cpu_addr = cpu_addr;
+	entry->mmap_flag = user_mmap_hint;
+
+	switch (user_mmap_hint) {
+	case BNG_RE_MMAP_UC_DB:
+		ret = rdma_user_mmap_entry_insert_range(&uctx->ib_uctx,
+							&entry->rdma_entry,
+							PAGE_SIZE, 0xF, U32_MAX);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	if (ret) {
+		kfree(entry);
+		return NULL;
+	}
+
+	dev_dbg(rdev_to_dev(uctx->rdev),
+		"mmap entry inserted: hint %s offset 0x%lx\n",
+		bng_re_mmap_str(user_mmap_hint),
+		(unsigned long)rdma_user_mmap_get_offset(&entry->rdma_entry));
+
+	if (offset)
+		*offset = rdma_user_mmap_get_offset(&entry->rdma_entry);
+
+	return entry;
+}
+
+static int bng_re_get_user_dpi(struct bng_re_dev *rdev,
+			       struct bng_re_ucontext *cntx)
+{
+	int ret = 0;
+	u8 type;
+
+	type = BNG_RE_DPI_TYPE_UC;
+	ret = bng_re_alloc_dpi(&rdev->bng_res, &cntx->dpi, cntx, type);
+	if (ret)
+		dev_err(rdev_to_dev(rdev), "Alloc doorbell page failed!");
+
+	return ret;
+}
+
+int bng_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
+{
+	struct ib_device *ibdev = ctx->device;
+	struct bng_re_ucontext *uctx =
+		container_of(ctx, struct bng_re_ucontext, ib_uctx);
+	struct bng_re_dev *rdev = to_bng_re_dev(ibdev, ibdev);
+	struct bng_re_dev_attr *dev_attr = rdev->dev_attr;
+	struct bng_re_user_mmap_entry *is_entry;
+	struct bng_re_uctx_resp resp = {};
+	struct bng_re_uctx_req ureq = {};
+	u32 chip_met_rev_num = 0;
+	int rc;
+
+	uctx->rdev = rdev;
+
+	if (udata->inlen >= sizeof(ureq)) {
+		rc = ib_copy_from_udata(&ureq, udata, sizeof(ureq));
+		if (rc)
+			return rc;
+		if (udata->inlen > sizeof(ureq) &&
+		    !ib_is_udata_cleared(udata, sizeof(ureq),
+					 udata->inlen - sizeof(ureq)))
+			return -EOPNOTSUPP;
+		if (ureq.comp_mask & ~BNG_RE_COMP_MASK_REQ_UCNTX_SUPPORTED)
+			return -EOPNOTSUPP;
+	}
+
+	rc = bng_re_get_user_dpi(rdev, uctx);
+	if (rc) {
+		ibdev_dbg(ibdev, "user DPI alloc failed");
+		return rc;
+	}
+
+	resp.dpi = uctx->dpi.dpi;
+	is_entry = bng_re_mmap_entry_insert(uctx,
+					    (u64)uctx->dpi.umdbr,
+					    BNG_RE_MMAP_UC_DB,
+					    &resp.uc_db_mmap_key);
+	if (!is_entry) {
+		rc = -ENOMEM;
+		goto err_entry_insert;
+	}
+	uctx->uc_db_mmap = &is_entry->rdma_entry;
+
+	resp.comp_mask = BNG_RE_UCNTX_CMASK_HAVE_CCTX;
+	if (bng_re_is_internal_queue_memory(dev_attr->dev_cap_flags))
+		resp.comp_mask |= BNG_RE_UCNTX_CMASK_INTERNAL_QUEUE_MEMORY;
+	chip_met_rev_num = rdev->chip_ctx->chip_num;
+	chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_rev & 0xFF) <<
+			     BNG_RE_CHIP_REV_SFT;
+	chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_metal & 0xFF) <<
+			     BNG_RE_CHIP_MET_SFT;
+	resp.chip_id = chip_met_rev_num;
+	resp.dev_id = rdev->aux_dev->pdev->devfn;
+	resp.max_qp = rdev->dev_attr->max_qp;
+	resp.cqe_sz = sizeof(struct cq_base);
+	resp.max_cqd = dev_attr->max_cq_wqes;
+
+	if (ureq.comp_mask & BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT)
+		resp.comp_mask |= BNG_RE_UCNTX_CMASK_POW2_DISABLED;
+	if (ureq.comp_mask & BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE)
+		resp.comp_mask |= BNG_RE_UCNTX_CMASK_RSVD_WQE_DISABLED;
+
+	uctx->cmask = (uint64_t)resp.comp_mask;
+
+	rc = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp)));
+	if (rc) {
+		ibdev_err(ibdev, "Failed to copy user context");
+		rc = -EFAULT;
+		goto copy_udata_fail;
+	}
+
+	return 0;
+
+copy_udata_fail:
+	rdma_user_mmap_entry_remove(uctx->uc_db_mmap);
+	uctx->uc_db_mmap = NULL;
+err_entry_insert:
+	bng_re_dealloc_dpi(&rdev->bng_res, &uctx->dpi);
+	return rc;
+}
+
+void bng_re_dealloc_ucontext(struct ib_ucontext *ib_uctx)
+{
+	struct bng_re_ucontext *uctx = container_of(ib_uctx,
+						    struct bng_re_ucontext,
+						    ib_uctx);
+	struct bng_re_dev *rdev = uctx->rdev;
+	int rc;
+
+	rdma_user_mmap_entry_remove(uctx->uc_db_mmap);
+	uctx->uc_db_mmap = NULL;
+	rc = bng_re_dealloc_dpi(&rdev->bng_res, &uctx->dpi);
+	if (rc)
+		dev_err(rdev_to_dev(rdev), "Deallocate DPI failed");
+}
+
+void bng_re_disassociate_ucontext(struct ib_ucontext *ib_uctx)
+{
+}
+
+int bng_re_mmap(struct ib_ucontext *ib_uctx, struct vm_area_struct *vma)
+{
+	struct bng_re_user_mmap_entry *bng_entry;
+	struct rdma_user_mmap_entry *rdma_entry;
+	int ret = 0;
+	u64 pfn;
+
+	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
+		return -EINVAL;
+
+	rdma_entry = rdma_user_mmap_entry_get(ib_uctx, vma);
+	if (!rdma_entry)
+		return -EINVAL;
+
+	bng_entry = container_of(rdma_entry, struct bng_re_user_mmap_entry,
+				 rdma_entry);
+
+	switch (bng_entry->mmap_flag) {
+	case BNG_RE_MMAP_UC_DB:
+		pfn = bng_entry->cpu_addr >> PAGE_SHIFT;
+		ret = rdma_user_mmap_io(ib_uctx, vma, pfn, PAGE_SIZE,
+					pgprot_noncached(vma->vm_page_prot),
+					rdma_entry);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	rdma_user_mmap_entry_put(rdma_entry);
+	return ret;
+}
+
+void bng_re_mmap_free(struct rdma_user_mmap_entry *rdma_entry)
+{
+	struct bng_re_user_mmap_entry *bng_entry;
+
+	bng_entry = container_of(rdma_entry, struct bng_re_user_mmap_entry,
+				 rdma_entry);
+
+	kfree(bng_entry);
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.h b/drivers/infiniband/hw/bng_re/bng_verbs.h
index fd00a3a0f7e8..c72b94e10d78 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.h
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.h
@@ -10,6 +10,24 @@
 #include "bng_sp.h"
 #include "bng_re.h"
 
+#define BNG_RE_COMP_MASK_REQ_UCNTX_SUPPORTED		\
+	(BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT |	\
+	 BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE)
+
+struct bng_re_ucontext {
+	struct ib_ucontext      ib_uctx;
+	struct bng_re_dev	*rdev;
+	struct bng_re_dpi	dpi;
+	struct rdma_user_mmap_entry *uc_db_mmap;
+	u64			cmask;
+};
+
+struct bng_re_user_mmap_entry {
+	struct rdma_user_mmap_entry rdma_entry;
+	u64 cpu_addr;
+	u8 mmap_flag;
+};
+
 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,
@@ -21,4 +39,11 @@ int bng_re_get_port_immutable(struct ib_device *ibdev, u32 port_num,
 			      struct ib_port_immutable *immutable);
 int bng_re_query_pkey(struct ib_device *ibdev, u32 port_num, u16 index, u16 *pkey);
 enum rdma_link_layer bng_re_get_link_layer(struct ib_device *ibdev, u32 port_num);
+
+int bng_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata);
+void bng_re_dealloc_ucontext(struct ib_ucontext *context);
+void bng_re_disassociate_ucontext(struct ib_ucontext *context);
+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);
+
 #endif /* __BNG_RE_VERBS_H__ */
diff --git a/include/uapi/rdma/bng_re-abi.h b/include/uapi/rdma/bng_re-abi.h
index cea056dc8610..d5cda958b0f8 100644
--- a/include/uapi/rdma/bng_re-abi.h
+++ b/include/uapi/rdma/bng_re-abi.h
@@ -9,4 +9,34 @@
 
 #define BNG_RE_ABI_VERSION	1
 
+#define BNG_RE_CHIP_REV_SFT		0x10
+#define BNG_RE_CHIP_MET_SFT		0x18
+
+enum {
+	BNG_RE_UCNTX_CMASK_HAVE_CCTX = 0x1,
+	BNG_RE_UCNTX_CMASK_POW2_DISABLED = 0x02,
+	BNG_RE_UCNTX_CMASK_RSVD_WQE_DISABLED = 0x04,
+	BNG_RE_UCNTX_CMASK_INTERNAL_QUEUE_MEMORY = 0x08,
+};
+
+enum {
+	BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT = 0x01,
+	BNG_RE_COMP_MASK_REQ_UCNTX_RSVD_WQE = 0x02,
+};
+
+struct bng_re_uctx_req {
+	__aligned_u64 comp_mask;
+};
+
+struct bng_re_uctx_resp {
+	__u32 dev_id;
+	__u32 max_qp;
+	__u32 cqe_sz;
+	__u32 max_cqd;
+	__aligned_u64 comp_mask;
+	__u32 chip_id;
+	__u32 dpi;
+	__aligned_u64 uc_db_mmap_key;
+};
+
 #endif /* __BNG_RE_UVERBS_ABI_H__*/
-- 
2.43.5


  parent reply	other threads:[~2026-12-04 16:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:47 [RDMA v2 00/13] Add BNG_RE control path verbs Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 01/13] bnge: Keep the RoCE MSI-X minimum for the MPC vector Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 02/13] RDMA/bng_re: Add MPC, XID management, doorbell infrastructure Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 03/13] RDMA/bng_re: Add support verbs Siva Reddy Kallam
2026-12-04 15:47 ` Siva Reddy Kallam [this message]
2026-12-04 15:47 ` [RDMA v2 05/13] RDMA/bng_re: Add GID verbs Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 06/13] RDMA/bng_re: Add PD verbs Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 07/13] RDMA/bng_re: Add MR verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 08/13] RDMA/bng_re: Add CQ verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 09/13] RDMA/bng_re: Add SRQ verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 10/13] RDMA/bng_re: Add Stats verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 11/13] RDMA/bng_re: Add AH verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 12/13] RDMA/bng_re: Add QP verbs Siva Reddy Kallam
2026-12-04 15:48 ` [RDMA v2 13/13] RDMA/bng_re: Register with ib-core Siva Reddy Kallam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204155249.1002019-5-siva.kallam@broadcom.com \
    --to=siva.kallam@broadcom.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dharmender.garg@broadcom.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sachin.holla@broadcom.com \
    --cc=shyam.mohan@broadcom.com \
    --cc=vikas.gupta@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox