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,
	Mohammed Faraaz <mohammed.faraaz@broadcom.com>,
	Siva Reddy Kallam <siva.kallam@broadcom.com>
Subject: [RDMA v2 11/13] RDMA/bng_re: Add AH verbs
Date: Fri,  4 Dec 2026 07:48:03 -0800	[thread overview]
Message-ID: <20261204155249.1002019-12-siva.kallam@broadcom.com> (raw)
In-Reply-To: <20261204155249.1002019-1-siva.kallam@broadcom.com>

From: Mohammed Faraaz <mohammed.faraaz@broadcom.com>

This patch adds below verbs.
- bng_re_create_ah
- bng_re_destroy_ah
- bng_re_query_ah

Signed-off-by: Mohammed Faraaz <mohammed.faraaz@broadcom.com>
Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>
---
 drivers/infiniband/hw/bng_re/bng_dev.c      |  21 +++
 drivers/infiniband/hw/bng_re/bng_re.h       |   1 +
 drivers/infiniband/hw/bng_re/bng_roce_hsi.h |  73 ++++++++
 drivers/infiniband/hw/bng_re/bng_sp.c       | 126 +++++++++++++
 drivers/infiniband/hw/bng_re/bng_sp.h       |  19 ++
 drivers/infiniband/hw/bng_re/bng_verbs.c    | 189 ++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_verbs.h    |  23 +++
 include/uapi/rdma/bng_re-abi.h              |   5 +
 8 files changed, 457 insertions(+)

diff --git a/drivers/infiniband/hw/bng_re/bng_dev.c b/drivers/infiniband/hw/bng_re/bng_dev.c
index 33556edaf37c..2b6a4694a37e 100644
--- a/drivers/infiniband/hw/bng_re/bng_dev.c
+++ b/drivers/infiniband/hw/bng_re/bng_dev.c
@@ -65,6 +65,11 @@ static const struct ib_device_ops bng_re_dev_ops = {
 	.destroy_srq		= bng_re_destroy_srq,
 	.alloc_hw_port_stats	= bng_re_alloc_hw_port_stats,
 	.get_hw_stats		= bng_re_ib_get_hw_stats,
+	.create_ah		= bng_re_create_ah,
+	.create_user_ah		= bng_re_create_ah,
+	.destroy_ah		= bng_re_destroy_ah,
+	.query_ah		= bng_re_query_ah,
+	INIT_RDMA_OBJ_SIZE(ib_ah, bng_re_ah, ib_ah),
 	INIT_RDMA_OBJ_SIZE(ib_srq, bng_re_srq, ib_srq),
 	INIT_RDMA_OBJ_SIZE(ib_cq, bng_re_cq, ib_cq),
 	INIT_RDMA_OBJ_SIZE(ib_pd, bng_re_pd, ib_pd),
@@ -374,6 +379,16 @@ static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 	/* Remove debugfs first: its handlers dereference MPC/XID state freed below */
 	bng_re_debugfs_rem_pdev(rdev);
 
+	if (rdev->dest_ah_wq) {
+		/*
+		 * Deferred AH destroys are queued with no delay, so
+		 * destroy_workqueue() drains every pending one before the MPC
+		 * state and XID tables below are freed.
+		 */
+		destroy_workqueue(rdev->dest_ah_wq);
+		rdev->dest_ah_wq = NULL;
+	}
+
 	if (rdev->bng_res.dpi_tbl.max)
 		bng_re_dealloc_dpi(&rdev->bng_res,
 				   &rdev->dpi_privileged);
@@ -555,6 +570,12 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 	}
 	bng_re_debugfs_add_mpc(rdev);
 	bng_re_debugfs_add_mpctune(rdev);
+
+	rdev->dest_ah_wq = alloc_ordered_workqueue("bng_re_dest_ah", 0);
+	if (!rdev->dest_ah_wq) {
+		rc = -ENOMEM;
+		goto deinit_mpc;
+	}
 	return 0;
 
 deinit_mpc:
diff --git a/drivers/infiniband/hw/bng_re/bng_re.h b/drivers/infiniband/hw/bng_re/bng_re.h
index c492bc004612..78d16c3a0268 100644
--- a/drivers/infiniband/hw/bng_re/bng_re.h
+++ b/drivers/infiniband/hw/bng_re/bng_re.h
@@ -303,6 +303,7 @@ struct bng_re_dev {
 	struct bng_re_qpc_limit_info	qpc_limit_info;
 	struct bng_re_dpi		dpi_privileged;
 	struct bng_re_hw_stats		stats;
+	struct workqueue_struct		*dest_ah_wq;
 };
 
 #define to_bng_re_dev(ptr, member)	\
diff --git a/drivers/infiniband/hw/bng_re/bng_roce_hsi.h b/drivers/infiniband/hw/bng_re/bng_roce_hsi.h
index 68361e5812fa..79dea3bcb5ae 100644
--- a/drivers/infiniband/hw/bng_re/bng_roce_hsi.h
+++ b/drivers/infiniband/hw/bng_re/bng_roce_hsi.h
@@ -6543,4 +6543,77 @@ struct mpc_event_resp_cmpl {
 	__le32	resp_data;
 };
 
+#define AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_AH_CREATE      0x1UL
+#define AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_AH_DESTROY     0x2UL
+#define AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_XID_FIRST_USE  0x4UL
+
+struct ah_modify_data {
+	__le32	ah_modify_flags;
+	__le32	reserved_0;
+	u8	type;
+	u8	unused_1[3];
+	__le32	pd_id;
+	u8	hop_limit;
+	u8	traffic_class;
+	__le16	sgid_index;
+	__le32	dest_vlan_id_flow_label;
+	__le64	ah_handle;
+	__le32	dgid[4];
+	__le16	dest_mac[3];
+	u8	enable_cc;
+	u8	unused_2[1];
+	__le32	xid;
+	__le32	reserved_1;
+};
+
+struct mpc_ah_modify_cmd {
+	u8	req_type;
+	u8	req_subtype;
+	__le16	cookie;
+	__le16	target_id;
+	u8	resp_size;
+	u8	reserved;
+	__le64	resp_addr;
+	__le32	ah_modify_flags;
+	__le32	reserved_0;
+	u8	type;
+	u8	unused_1[3];
+	__le32	pd_id;
+	u8	hop_limit;
+	u8	traffic_class;
+	__le16	sgid_index;
+	__le32	dest_vlan_id_flow_label;
+	__le64	ah_handle;
+	__le32	dgid[4];
+	__le16	dest_mac[3];
+	u8	enable_cc;
+	u8	unused_2[1];
+	__le32	xid;
+	__le32	reserved_1;
+};
+
+struct mpc_ah_modify_cmpl {
+	u8	cmpl_type_reserved;
+	u8	error_code_mp_client;
+	u8	req_type;
+	u8	req_subtype;
+	__le32	opaque;
+	u8	v;
+	u8	reserved_0[7];
+	__le32	xid;
+	__le16	error_code;
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_SUCCESS           0x0UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_FAIL              0x1UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_RESOURCES         0x2UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_INVALID_CMD       0x3UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_NOT_IMPLEMENTED   0x4UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_INVALID_PARAMETER 0x5UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_HARDWARE_ERROR    0x6UL
+	#define MPC_AH_MODIFY_CMPL_ERROR_CODE_INTERNAL_ERROR    0x7UL
+	u8	reserved_1[2];
+	u8	v2;
+	u8	reserved_2[3];
+	__le32	reserved_3;
+};
+
 #endif /* _BNG_RE_HSI_H_ */
diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/hw/bng_re/bng_sp.c
index f2b3c0234b90..2e46742c335c 100644
--- a/drivers/infiniband/hw/bng_re/bng_sp.c
+++ b/drivers/infiniband/hw/bng_re/bng_sp.c
@@ -9,6 +9,8 @@
 #include "bng_sp.h"
 #include "bng_tlv.h"
 #include "bng_re.h"
+#include "bng_re_mpc_roce.h"
+#include "bng_fp.h"
 
 static const struct bng_re_gid bng_re_gid_zero = {{0,}};
 
@@ -1074,3 +1076,127 @@ int bng_re_qext_stat(struct bng_re_rcfw *rcfw, u32 fid,
 	bng_re_free_sbuf(rcfw, &sbuf, &msg, rc);
 	return rc;
 }
+
+static void bng_sp_fill_mpc_ah_modify_parms(struct bng_re_res *res,
+					    struct ah_modify_data *data,
+					    struct bng_sp_ah *ah,
+					    bool for_destroy)
+{
+	u32 flags = 0;
+
+	if (for_destroy) {
+		flags |= AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_AH_DESTROY;
+	} else {
+		flags |= AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_AH_CREATE;
+		flags |= AH_MODIFY_DATA_AH_MODIFY_FLAGS_AH_MODIFY_FLAGS_XID_FIRST_USE;
+	}
+	data->ah_modify_flags = cpu_to_le32(flags);
+	/*
+	 * Firmware does not interpret ah_handle; use the XID, which is
+	 * identical on create and destroy and does not expose a kernel pointer.
+	 */
+	data->ah_handle = cpu_to_le64(ah->id);
+	data->xid = cpu_to_le32(ah->id);
+
+	if (!for_destroy) {
+		if (ah->pd)
+			data->pd_id = cpu_to_le32(ah->pd->id);
+		data->type = ah->nw_type;
+		data->hop_limit = ah->hop_limit;
+		data->traffic_class = ah->traffic_class;
+		data->sgid_index = cpu_to_le16(ah->sgid_index);
+		/* vlan_id 0xfff (from an untagged 0xffff) means no VLAN to FW */
+		data->dest_vlan_id_flow_label = cpu_to_le32((ah->flow_label &
+							     CMDQ_CREATE_AH_FLOW_LABEL_MASK) |
+							    ((u32)(ah->vlan_id & 0x0fff) <<
+							     CMDQ_CREATE_AH_DEST_VLAN_ID_SFT));
+		memcpy(data->dgid, ah->dgid.data, sizeof(data->dgid));
+		memcpy(data->dest_mac, ah->dmac, sizeof(ah->dmac));
+	}
+
+	dev_dbg(&res->pdev->dev, "MPC: AH modify params - AH ID=%d, flags=0x%x, for_destroy=%s\n",
+		ah->id, flags, for_destroy ? "true" : "false");
+}
+
+int bng_sp_fill_and_send_mpc_ah_modify(struct bng_re_res *res,
+				       struct bng_sp_ah **ahs,
+				       int num_ahs, bool for_destroy, bool block)
+{
+	struct bng_re_dev *rdev = to_bng_re_dev(res, bng_res);
+	struct mpc_ah_modify_cmpl resp;
+	struct mpc_ah_modify_cmd cmd;
+	struct ah_modify_data *data;
+	struct bng_sp_ah *ah;
+	bool fw_rejected;
+	int rc;
+
+	if (!ahs || !*ahs)
+		return -EINVAL;
+
+	/* for 1st iteration, don't allow batch */
+	if (num_ahs != 1)
+		return -EINVAL;
+
+	ah = *ahs;
+
+	if (!for_destroy) {
+		int xid;
+
+		xid = bng_re_xm_alloc_range(res->ah_xids, 1, 0);
+		if (xid < 0) {
+			dev_err(&res->pdev->dev,
+				"%s - error allocating ah xid\n", __func__);
+			return -ENOMEM;
+		}
+		ah->id = xid;
+	}
+
+	memset(&cmd, 0, sizeof(cmd));
+	memset(&resp, 0, sizeof(resp));
+	data = (struct ah_modify_data *)&cmd.ah_modify_flags;
+
+	bng_sp_fill_mpc_ah_modify_parms(res, data, ah, for_destroy);
+
+	cmd.resp_size = sizeof(resp) / BNG_RE_MPC_CQ_STRIDE;
+	cmd.req_type = MPC_CMD_HDR_REQ_TYPE_RCA;
+	cmd.req_subtype = MPC_CMD_HDR_REQ_SUB_TYPE_RCA_AH_MODIFY;
+
+	dev_dbg(&res->pdev->dev, "MPC: %s - sending to mpc: AH ID=%d, block=%s\n",
+		__func__, ah->id, block ? "true" : "false");
+
+	rc = bng_re_roce_mpc_xmit(rdev, &cmd, sizeof(cmd), &resp, sizeof(resp), !block);
+
+	fw_rejected = !rc && le16_to_cpu(resp.error_code) !=
+			     MPC_AH_MODIFY_CMPL_ERROR_CODE_SUCCESS;
+	if (fw_rejected) {
+		dev_err(&res->pdev->dev, "%s - FW rejected AH %s, id=%d, error_code=%u\n",
+			__func__, for_destroy ? "destroy" : "create", ah->id,
+			le16_to_cpu(resp.error_code));
+		rc = -EIO;
+	} else if (rc) {
+		dev_err(&res->pdev->dev, "%s - error sending mpc: id=%d rc=%d\n",
+			__func__, ah->id, rc);
+	}
+
+	if (for_destroy) {
+		/*
+		 * Release the XID only once HW confirmed the destroy; otherwise
+		 * it may still be live and must not be handed to a new AH.
+		 */
+		if (!rc)
+			bng_re_xm_free_range(res->ah_xids, ah->id, true);
+		return rc;
+	}
+
+	/*
+	 * After a timeout, or a stall/detach abort (-EHOSTUNREACH) that can hit
+	 * once the command is posted, HW may still apply the create, so keep
+	 * the XID reserved. Any other failure means no AH was created.
+	 */
+	if (rc && rc != -ETIMEDOUT && rc != -EHOSTUNREACH)
+		bng_re_xm_free_range(res->ah_xids, ah->id, true);
+
+	dev_dbg(&res->pdev->dev, "MPC: AH create for AH ID=%d rc=%d\n",
+		ah->id, rc);
+	return rc;
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_sp.h b/drivers/infiniband/hw/bng_re/bng_sp.h
index 74375615146b..838566c0a4aa 100644
--- a/drivers/infiniband/hw/bng_re/bng_sp.h
+++ b/drivers/infiniband/hw/bng_re/bng_sp.h
@@ -207,6 +207,22 @@ struct bng_re_hw_stats {
 	struct bng_re_rstat            rstat;
 };
 
+struct bng_sp_ah {
+	struct bng_re_gid			dgid;
+	struct bng_sp_pd			*pd;
+	u32				id;
+	u8				sgid_index;
+	/* For Query AH if the hw table and SW table are different */
+	u8				host_sgid_index;
+	u8				traffic_class;
+	u32				flow_label;
+	u8				hop_limit;
+	u8				sl;
+	u8				dmac[6];
+	u16				vlan_id;
+	u8				nw_type;
+};
+
 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);
@@ -249,5 +265,8 @@ int bng_sp_destroy_srq(struct bng_re_res *res, struct bng_sp_srq *srq);
 int bng_re_qext_stat(struct bng_re_rcfw *rcfw, u32 fid,
 		     struct bng_re_ext_stat *estat);
 int bng_re_get_roce_stats(struct bng_re_rcfw *rcfw, struct bng_roce_stats *stats);
+int bng_sp_fill_and_send_mpc_ah_modify(struct bng_re_res *res,
+				       struct bng_sp_ah **ahs,
+				       int num_ahs, bool for_destroy, bool block);
 
 #endif
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
index 0f71740a254f..a54ab2b9b96f 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.c
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.c
@@ -500,6 +500,13 @@ 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;
 
+	/*
+	 * A non-sleepable AH destroy returns before HW has dropped the AH.
+	 * Wait for those so the PD id is not reused while an AH still carries it.
+	 */
+	if (rdev->dest_ah_wq)
+		flush_workqueue(rdev->dest_ah_wq);
+
 	bng_sp_dealloc_pd(&rdev->bng_res, &pd->sp_pd);
 	return 0;
 }
@@ -1568,3 +1575,185 @@ int bng_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata)
 
 	return 0;
 }
+
+void bng_re_posted_destroy_ah(struct work_struct *work)
+{
+	struct bng_destroy_ah *ah = container_of(work, struct bng_destroy_ah, work);
+	struct bng_re_dev *rdev = ah->rdev;
+	struct bng_sp_ah *ahs[1] = { &ah->sp_ah };
+	int rc;
+
+	rc = bng_sp_fill_and_send_mpc_ah_modify(&rdev->bng_res, ahs, 1, true, true);
+	if (rc)
+		dev_err_ratelimited(&rdev->ibdev.dev,
+				    "%s failed to destroy AH id = %d rc = %d\n",
+				    __func__, ah->sp_ah.id, rc);
+	kfree(ah);
+}
+
+static u8 bng_re_stack_to_dev_nw_type(enum rdma_network_type ntype)
+{
+	u8 nw_type;
+
+	switch (ntype) {
+	case RDMA_NETWORK_IPV4:
+		nw_type = CMDQ_CREATE_AH_TYPE_V2IPV4;
+		break;
+	case RDMA_NETWORK_IPV6:
+		nw_type = CMDQ_CREATE_AH_TYPE_V2IPV6;
+		break;
+	default:
+		nw_type = CMDQ_CREATE_AH_TYPE_V1;
+		break;
+	}
+	return nw_type;
+}
+
+int bng_re_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
+		     struct ib_udata *udata)
+{
+	struct ib_pd *ibpd = ibah->pd;
+	struct rdma_ah_attr *ah_attr = init_attr->ah_attr;
+	const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
+	struct bng_re_dev *rdev = to_bng_re_dev(ibpd->device, ibdev);
+	struct bng_re_pd *pd = container_of(ibpd, struct bng_re_pd, ib_pd);
+	struct bng_re_ah *ah = to_bng_re_ah(ibah);
+	bool block = !!(init_attr->flags & RDMA_CREATE_AH_SLEEPABLE);
+	const struct ib_gid_attr *sgid_attr;
+	struct bng_sp_ah *ahs[1];
+	struct bng_re_gid_ctx *ctx;
+	enum rdma_network_type nw_type;
+	int rc;
+
+	if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) {
+		ibdev_err(&rdev->ibdev, "Failed to create AH: GRH not set");
+		return -EINVAL;
+	}
+
+	ah->rdev = rdev;
+	ah->sp_ah.pd = &pd->sp_pd;
+
+	/* Supply the configuration for the HW */
+	memcpy(ah->sp_ah.dgid.data, grh->dgid.raw, sizeof(union ib_gid));
+	sgid_attr = grh->sgid_attr;
+	if (!sgid_attr) {
+		ibdev_err(&rdev->ibdev, "Failed to read GID attribute");
+		return -EINVAL;
+	}
+	/* Get the HW context of the GID. The reference
+	 * of GID table entry is already taken by the caller.
+	 */
+	ctx = rdma_read_gid_hw_context(sgid_attr);
+	if (!ctx) {
+		ibdev_err(&rdev->ibdev, "Failed to read GID HW context");
+		return -EINVAL;
+	}
+	/*
+	 * FW addresses GIDs by the id it returned at ADD_GID, which need not
+	 * equal the host table slot, so translate before programming the AH.
+	 */
+	if (ctx->idx >= rdev->bng_res.sgid_tbl.max ||
+	    rdev->bng_res.sgid_tbl.hw_id[ctx->idx] == 0xFFFF) {
+		ibdev_err(&rdev->ibdev, "GID index %u has no HW id", ctx->idx);
+		return -EINVAL;
+	}
+	ah->sp_ah.sgid_index = rdev->bng_res.sgid_tbl.hw_id[ctx->idx];
+	ah->sp_ah.host_sgid_index = grh->sgid_index;
+	ah->sp_ah.flow_label = grh->flow_label;
+	ah->sp_ah.hop_limit = grh->hop_limit;
+	ah->sp_ah.traffic_class = grh->traffic_class;
+	ah->sp_ah.sl = rdma_ah_get_sl(ah_attr);
+
+	/* Get network type from GID attribute */
+	nw_type = rdma_gid_attr_network_type(sgid_attr);
+	ah->sp_ah.nw_type = bng_re_stack_to_dev_nw_type(nw_type);
+
+	rc = rdma_read_gid_l2_fields(sgid_attr, &ah->sp_ah.vlan_id, NULL);
+	if (rc) {
+		ibdev_err(&rdev->ibdev, "Failed to read GID L2 fields");
+		return rc;
+	}
+
+	memcpy(ah->sp_ah.dmac, ah_attr->roce.dmac, ETH_ALEN);
+
+	ahs[0] = &ah->sp_ah;
+
+	dev_dbg(&rdev->ibdev.dev, "MPC: %s - sending AH modify(create) for: res:%p, ah:%p\n",
+		__func__, &rdev->bng_res, &ah->sp_ah);
+	rc = bng_sp_fill_and_send_mpc_ah_modify(&rdev->bng_res,
+						ahs, 1, false, block);
+	if (rc) {
+		ibdev_err(&rdev->ibdev, "Failed to create HW AH");
+		return rc;
+	}
+
+	if (udata) {
+		struct bng_re_ah_resp resp = {};
+
+		resp.ah_id = ah->sp_ah.id;
+		rc = ib_copy_to_udata(udata, &resp,
+				      min(udata->outlen, sizeof(resp)));
+		if (rc) {
+			ibdev_err(&rdev->ibdev, "Failed to copy AH response");
+			goto fail_destroy;
+		}
+	}
+
+	ibdev_dbg(&rdev->ibdev, "AH created with ID: %d", ah->sp_ah.id);
+	return 0;
+
+fail_destroy:
+	bng_sp_fill_and_send_mpc_ah_modify(&rdev->bng_res, ahs, 1, true, block);
+	return rc;
+}
+
+int bng_re_destroy_ah(struct ib_ah *ib_ah, u32 flags)
+{
+	struct bng_re_ah *ah = to_bng_re_ah(ib_ah);
+	struct bng_re_dev *rdev = ah->rdev;
+	bool block = !!(flags & RDMA_DESTROY_AH_SLEEPABLE);
+	struct bng_destroy_ah *pos_ah;
+	struct bng_sp_ah *ahs[1];
+	int rc;
+
+	if (!block) {
+		/* Atomic context: let a worker sleep on the MPC completion. */
+		pos_ah = kzalloc_obj(*pos_ah, GFP_ATOMIC);
+		if (pos_ah) {
+			INIT_WORK(&pos_ah->work, bng_re_posted_destroy_ah);
+			pos_ah->rdev = rdev;
+			memcpy(&pos_ah->sp_ah, &ah->sp_ah, sizeof(pos_ah->sp_ah));
+			queue_work(rdev->dest_ah_wq, &pos_ah->work);
+			return 0;
+		}
+	}
+
+	ahs[0] = &ah->sp_ah;
+	rc = bng_sp_fill_and_send_mpc_ah_modify(&rdev->bng_res, ahs, 1, true, block);
+	if (rc)
+		dev_err_ratelimited(&rdev->ibdev.dev,
+				    "%s id = %d dest_ah failed rc = %d\n",
+				    __func__, ah->sp_ah.id, rc);
+	/*
+	 * The ib_ah is released by the core regardless; returning an error
+	 * would make uverbs destroy the same AH a second time.
+	 */
+	return 0;
+}
+
+int bng_re_query_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr)
+{
+	struct bng_re_ah *ah = to_bng_re_ah(ib_ah);
+
+	ah_attr->type = ib_ah->type;
+	ah_attr->ah_flags = IB_AH_GRH;
+	rdma_ah_set_sl(ah_attr, ah->sp_ah.sl);
+	memcpy(ah_attr->roce.dmac, ah->sp_ah.dmac, ETH_ALEN);
+	rdma_ah_set_grh(ah_attr, NULL, ah->sp_ah.flow_label,
+			ah->sp_ah.host_sgid_index,
+			ah->sp_ah.hop_limit, ah->sp_ah.traffic_class);
+	rdma_ah_set_dgid_raw(ah_attr, ah->sp_ah.dgid.data);
+	rdma_ah_set_port_num(ah_attr, 1);
+	rdma_ah_set_static_rate(ah_attr, 0);
+	return 0;
+}
diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.h b/drivers/infiniband/hw/bng_re/bng_verbs.h
index 76263cf1b8a8..eb2b3da09fd5 100644
--- a/drivers/infiniband/hw/bng_re/bng_verbs.h
+++ b/drivers/infiniband/hw/bng_re/bng_verbs.h
@@ -68,6 +68,24 @@ struct bng_re_srq {
 	spinlock_t		lock;		/* protect srq */
 };
 
+/* AH destroy deferred out of atomic context */
+struct bng_destroy_ah {
+	struct work_struct	work;
+	struct bng_re_dev	*rdev;
+	struct bng_sp_ah	sp_ah;
+};
+
+struct bng_re_ah {
+	struct ib_ah		ib_ah;
+	struct bng_re_dev	*rdev;
+	struct bng_sp_ah	sp_ah;
+};
+
+static inline struct bng_re_ah *to_bng_re_ah(struct ib_ah *ibah)
+{
+	return container_of(ibah, struct bng_re_ah, ib_ah);
+}
+
 static inline u32 bng_re_init_depth(u32 ent, struct bng_re_ucontext *uctx)
 {
 	/* @ent must be non-zero: roundup_pow_of_two(0) is undefined */
@@ -137,5 +155,10 @@ int bng_re_modify_srq(struct ib_srq *ib_srq, struct ib_srq_attr *srq_attr,
 		      struct ib_udata *udata);
 int bng_re_query_srq(struct ib_srq *ib_srq, struct ib_srq_attr *srq_attr);
 int bng_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata);
+int bng_re_create_ah(struct ib_ah *ib_ah, struct rdma_ah_init_attr *init_attr,
+		     struct ib_udata *udata);
+int bng_re_destroy_ah(struct ib_ah *ib_ah, u32 flags);
+int bng_re_query_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr);
+void bng_re_posted_destroy_ah(struct work_struct *work);
 
 #endif /* __BNG_RE_VERBS_H__ */
diff --git a/include/uapi/rdma/bng_re-abi.h b/include/uapi/rdma/bng_re-abi.h
index dfba021bc69f..2506068ab053 100644
--- a/include/uapi/rdma/bng_re-abi.h
+++ b/include/uapi/rdma/bng_re-abi.h
@@ -73,4 +73,9 @@ struct bng_re_srq_resp {
 	__aligned_u64 comp_mask;
 };
 
+struct bng_re_ah_resp {
+	__u32 ah_id;
+	__u32 comp_mask;
+};
+
 #endif /* __BNG_RE_UVERBS_ABI_H__*/
-- 
2.43.5


  parent reply	other threads:[~2026-12-04 16:02 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 ` [RDMA v2 04/13] RDMA/bng_re: Add ucontext/mmap verbs Siva Reddy Kallam
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 ` Siva Reddy Kallam [this message]
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-12-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=mohammed.faraaz@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sachin.holla@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