Skip to contentSkip to conversation

Introducing Broadcom BNG_RE RoCE Driver

PATCH In review Siva Reddy Kallam 3 participants 14 messages Nov 17, 2025 – Nov 25, 2025

Subsystems (5)
lore
Share & tools
lore

Siva Reddy Kallam

author maintainer
#0 lore raw

v3 cover Introducing Broadcom BNG_RE RoCE Driver

This patch series introduces the Next generation RoCE driver for Broadcom’s BCM5770X chip family, which supports 50/100/200/400/800G link speeds. The driver is built as the bng_re.ko kernel module.

To keep the series within a reviewable size (~3.5K lines of code), this initial submission focuses on the core infrastructure and hardware initialization, including:

1) bng_en: Auxiliary device support
2) Auxiliary device support (probe/remove)
3) Get the required resources from bng_en
4) Firmware communication mechanism
5) Allocation of ib device
6) Basic debugfs infrastructure support
7) Get the device capability (QPs, CQs, SRQs, etc.)
8) Initialize the Hardware

Support for Verbs, User library and additional features will be built on top of this patchset. hence, they will be introduced in the subsequent patch series.

The bng_re driver shares the roce_hsi.h file with the bnxt_re driver, as the bng_re driver leverages the hardware communication protocol used by the bnxt_re driver.
======================================================================
Changes from:
v2->v3
Rebased the patchseries to rdma-next

v1->v2
Addressed the following comments by Simon Horman and Leon Romanovsky:
Patch 2/8:
  - Remove rdev_to_dev check in bng_re_add_device.
Patch 5/8:
  - Remove uninitalized variable rc in bng_re_process_func_event.
- Remove unused variable in creq bng_re_enable_fw_channel.
- Modified the switch case as suggested by Leon in bng_re_process_func_event.
Patch 6/8:
  - Remove unused variable cctx in bng_re_get_dev_attr.

Thanks,
Siva

Siva Reddy Kallam (7):
RDMA/bng_re: Add Auxiliary interface
RDMA/bng_re: Register and get the resources from bnge driver RDMA/bng_re: Allocate required memory resources for Firmware channel RDMA/bng_re: Add infrastructure for enabling Firmware channel RDMA/bng_re: Enable Firmware channel and query device attributes RDMA/bng_re: Add basic debugfs infrastructure RDMA/bng_re: Initialize the Firmware and Hardware

Vikas Gupta (1):
bng_en: Add RoCE aux device support

 MAINTAINERS                                   |   7 +
 drivers/infiniband/Kconfig                    |   1 +
 drivers/infiniband/hw/Makefile                |   1 +
 drivers/infiniband/hw/bng_re/Kconfig          |  10 +
 drivers/infiniband/hw/bng_re/Makefile         |   8 +
 drivers/infiniband/hw/bng_re/bng_debugfs.c    |  39 +
 drivers/infiniband/hw/bng_re/bng_debugfs.h    |  12 +
 drivers/infiniband/hw/bng_re/bng_dev.c        | 539 ++++++++++++
 drivers/infiniband/hw/bng_re/bng_fw.c         | 767 ++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_fw.h         | 211 +++++
 drivers/infiniband/hw/bng_re/bng_re.h         |  86 ++
 drivers/infiniband/hw/bng_re/bng_res.c        | 279 +++++++
 drivers/infiniband/hw/bng_re/bng_res.h        | 215 +++++
 drivers/infiniband/hw/bng_re/bng_sp.c         | 131 +++
 drivers/infiniband/hw/bng_re/bng_sp.h         |  47 ++
 drivers/infiniband/hw/bng_re/bng_tlv.h        | 128 +++
 drivers/net/ethernet/broadcom/bnge/Makefile   |   3 +-
 drivers/net/ethernet/broadcom/bnge/bnge.h     |  10 +
 .../net/ethernet/broadcom/bnge/bnge_auxr.c    | 258 ++++++
 .../net/ethernet/broadcom/bnge/bnge_auxr.h    |  84 ++
 .../net/ethernet/broadcom/bnge/bnge_core.c    |  18 +-
 .../net/ethernet/broadcom/bnge/bnge_hwrm.c    |  40 +
 .../net/ethernet/broadcom/bnge/bnge_hwrm.h    |   2 +
 .../net/ethernet/broadcom/bnge/bnge_resc.c    |  12 +
 .../net/ethernet/broadcom/bnge/bnge_resc.h    |   1 +
 25 files changed, 2907 insertions(+), 2 deletions(-)
 create mode 100644 drivers/infiniband/hw/bng_re/Kconfig
 create mode 100644 drivers/infiniband/hw/bng_re/Makefile
 create mode 100644 drivers/infiniband/hw/bng_re/bng_debugfs.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_debugfs.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_dev.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_fw.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_fw.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_re.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_res.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_res.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_sp.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_sp.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_tlv.h
 create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_auxr.c
 create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_auxr.h
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v3 1/8 bng_en: Add RoCE aux device support

From: Vikas Gupta <[email protected]>

Add an auxiliary (aux) device to support RoCE. The base driver is responsible for creating the auxiliary device and allocating the required resources to it, which will be owned by the bnge RoCE driver in future patches.

---
 drivers/net/ethernet/broadcom/bnge/Makefile   |   3 +-
 drivers/net/ethernet/broadcom/bnge/bnge.h     |  10 +
 .../net/ethernet/broadcom/bnge/bnge_auxr.c    | 258 ++++++++++++++++++
 .../net/ethernet/broadcom/bnge/bnge_auxr.h    |  84 ++++++
 .../net/ethernet/broadcom/bnge/bnge_core.c    |  18 +-
 .../net/ethernet/broadcom/bnge/bnge_hwrm.c    |  40 +++
 .../net/ethernet/broadcom/bnge/bnge_hwrm.h    |   2 +
 .../net/ethernet/broadcom/bnge/bnge_resc.c    |  12 +
 .../net/ethernet/broadcom/bnge/bnge_resc.h    |   1 +
 9 files changed, 426 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_auxr.c
 create mode 100644 drivers/net/ethernet/broadcom/bnge/bnge_auxr.h
drivers/net/ethernet/broadcom/bnge/Makefile +2 -1
index 6142d9c57f49..ea6596854e5c 100644
@@ -9,4 +9,5 @@ bng_en-y := bnge_core.o \
 	    bnge_rmem.o \
 	    bnge_resc.o \
 	    bnge_netdev.o \
-	    bnge_ethtool.o
+	    bnge_ethtool.o \
+	    bnge_auxr.o
drivers/net/ethernet/broadcom/bnge/bnge.h +10 -0
index 7aed5f81cd51..411744894349 100644
@@ -11,6 +11,7 @@
 #include <linux/bnxt/hsi.h>
 #include "bnge_rmem.h"
 #include "bnge_resc.h"
+#include "bnge_auxr.h"
 
 #define DRV_VER_MAJ	1
 #define DRV_VER_MIN	15
@@ -22,6 +23,12 @@ enum board_idx {
 	BCM57708,
 };
 
+struct bnge_auxr_priv {
+	struct auxiliary_device aux_dev;
+	struct bnge_auxr_dev *auxr_dev;
+	int id;
+};
+
 struct bnge_pf_info {
 	u16	fw_fid;
 	u16	port_id;
@@ -197,6 +204,9 @@ struct bnge_dev {
 
 	struct bnge_irq		*irq_tbl;
 	u16			irqs_acquired;
+
+	struct bnge_auxr_priv	*aux_priv;
+	struct bnge_auxr_dev	*auxr_dev;
 };
 
 static inline bool bnge_is_roce_en(struct bnge_dev *bd)
drivers/net/ethernet/broadcom/bnge/bnge_auxr.c new file +258 -0

258 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnge/bnge_auxr.h new file +84 -0

84 lines not on this page · raw message

drivers/net/ethernet/broadcom/bnge/bnge_core.c +17 -1
index 2c72dd34d50d..c94e132bebc8 100644
@@ -41,6 +41,11 @@ static void bnge_print_device_info(struct pci_dev *pdev, enum board_idx idx)
 
 bool bnge_aux_registered(struct bnge_dev *bd)
 {
+	struct bnge_auxr_dev *ba_dev = bd->auxr_dev;
+
+	if (ba_dev && ba_dev->auxr_info->msix_requested)
+		return true;
+
 	return false;
 }
 
@@ -312,16 +317,20 @@ static int bnge_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	spin_lock_init(&bd->db_lock);
 #endif
 
+	bnge_rdma_aux_device_init(bd);
+
 	rc = bnge_alloc_irqs(bd);
 	if (rc) {
 		dev_err(&pdev->dev, "Error IRQ allocation rc = %d\n", rc);
-		goto err_config_uninit;
+		goto err_uninit_auxr;
 	}
 
 	rc = bnge_netdev_alloc(bd, max_irqs);
 	if (rc)
 		goto err_free_irq;
 
+	bnge_rdma_aux_device_add(bd);
+
 	pci_save_state(pdev);
 
 	return 0;
@@ -329,6 +338,9 @@ static int bnge_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 err_free_irq:
 	bnge_free_irqs(bd);
 
+err_uninit_auxr:
+	bnge_rdma_aux_device_uninit(bd);
+
 err_config_uninit:
 	bnge_net_uninit_dflt_config(bd);
 
@@ -354,10 +366,14 @@ static void bnge_remove_one(struct pci_dev *pdev)
 {
 	struct bnge_dev *bd = pci_get_drvdata(pdev);
 
+	bnge_rdma_aux_device_del(bd);
+
 	bnge_netdev_free(bd);
 
 	bnge_free_irqs(bd);
 
+	bnge_rdma_aux_device_uninit(bd);
+
 	bnge_net_uninit_dflt_config(bd);
 
 	bnge_devlink_unregister(bd);
drivers/net/ethernet/broadcom/bnge/bnge_hwrm.c +40 -0
index 0f971af24142..c3087e5cd875 100644
@@ -98,6 +98,46 @@ void bnge_hwrm_req_alloc_flags(struct bnge_dev *bd, void *req, gfp_t gfp)
 		ctx->gfp = gfp;
 }
 
+int bnge_hwrm_req_replace(struct bnge_dev *bd, void *req, void *new_req,
+			  u32 len)
+{
+	struct bnge_hwrm_ctx *ctx = __hwrm_ctx_get(bd, req);
+	struct input *internal_req = req;
+	u16 req_type;
+
+	if (!ctx)
+		return -EINVAL;
+
+	if (len > BNGE_HWRM_CTX_OFFSET)
+		return -E2BIG;
+
+	/* free any existing slices */
+	ctx->allocated = BNGE_HWRM_DMA_SIZE - BNGE_HWRM_CTX_OFFSET;
+	if (ctx->slice_addr) {
+		dma_free_coherent(bd->dev, ctx->slice_size,
+				  ctx->slice_addr, ctx->slice_handle);
+		ctx->slice_addr = NULL;
+	}
+	ctx->gfp = GFP_KERNEL;
+
+	if ((bd->fw_cap & BNGE_FW_CAP_SHORT_CMD) || len > BNGE_HWRM_MAX_REQ_LEN) {
+		memcpy(internal_req, new_req, len);
+	} else {
+		internal_req->req_type = ((struct input *)new_req)->req_type;
+		ctx->req = new_req;
+	}
+
+	ctx->req_len = len;
+	ctx->req->resp_addr = cpu_to_le64(ctx->dma_handle +
+					  BNGE_HWRM_RESP_OFFSET);
+
+	/* update sentinel for potentially new request type */
+	req_type = le16_to_cpu(internal_req->req_type);
+	ctx->sentinel = bnge_cal_sentinel(ctx, req_type);
+
+	return 0;
+}
+
 void bnge_hwrm_req_flags(struct bnge_dev *bd, void *req,
 			 enum bnge_hwrm_ctx_flags flags)
 {
drivers/net/ethernet/broadcom/bnge/bnge_hwrm.h +2 -0
index 83794a12cc81..6df629761d95 100644
@@ -107,4 +107,6 @@ int bnge_hwrm_req_send_silent(struct bnge_dev *bd, void *req);
 void bnge_hwrm_req_alloc_flags(struct bnge_dev *bd, void *req, gfp_t flags);
 void *bnge_hwrm_req_dma_slice(struct bnge_dev *bd, void *req, u32 size,
 			      dma_addr_t *dma);
+int bnge_hwrm_req_replace(struct bnge_dev *bd, void *req, void *new_req,
+			  u32 len);
 #endif /* _BNGE_HWRM_H_ */
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +12 -0
index 62ebe03a0dcf..943df5f60f01 100644
@@ -34,6 +34,18 @@ static unsigned int bnge_get_max_func_stat_ctxs(struct bnge_dev *bd)
 	return bd->hw_resc.max_stat_ctxs;
 }
 
+bool bnge_aux_has_enough_resources(struct bnge_dev *bd)
+{
+	unsigned int max_stat_ctxs;
+
+	max_stat_ctxs = bnge_get_max_func_stat_ctxs(bd);
+	if (max_stat_ctxs <= BNGE_MIN_ROCE_STAT_CTXS ||
+	    bd->nq_nr_rings == max_stat_ctxs)
+		return false;
+
+	return true;
+}
+
 static unsigned int bnge_get_max_func_cp_rings(struct bnge_dev *bd)
 {
 	return bd->hw_resc.max_cp_rings;
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +1 -0
index 0d6213b27580..b62a634669f6 100644
@@ -74,6 +74,7 @@ void bnge_net_uninit_dflt_config(struct bnge_dev *bd);
 void bnge_aux_init_dflt_config(struct bnge_dev *bd);
 u32 bnge_get_rxfh_indir_size(struct bnge_dev *bd);
 int bnge_cal_nr_rss_ctxs(u16 rx_rings);
+bool bnge_aux_has_enough_resources(struct bnge_dev *bd);
 
 static inline u32
 bnge_adjust_pow_two(u32 total_ent, u16 ent_per_blk)
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v3 2/8 RDMA/bng_re: Add Auxiliary interface

In reply to Siva Reddy Kallam

Add basic Auxiliary interface to the driver which supports the BCM5770X NIC family.

---
 MAINTAINERS                            |   7 ++
 drivers/infiniband/Kconfig             |   1 +
 drivers/infiniband/hw/Makefile         |   1 +
 drivers/infiniband/hw/bng_re/Kconfig   |  10 ++
 drivers/infiniband/hw/bng_re/Makefile  |   7 ++
 drivers/infiniband/hw/bng_re/bng_dev.c | 142 +++++++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_re.h  |  27 +++++
 7 files changed, 195 insertions(+)
 create mode 100644 drivers/infiniband/hw/bng_re/Kconfig
 create mode 100644 drivers/infiniband/hw/bng_re/Makefile
 create mode 100644 drivers/infiniband/hw/bng_re/bng_dev.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_re.h
MAINTAINERS +7 -0
index 46126ce2f968..1f7aa2a3bec1 100644
@@ -5191,6 +5191,13 @@ W:	http://www.broadcom.com
 F:	drivers/infiniband/hw/bnxt_re/
 F:	include/uapi/rdma/bnxt_re-abi.h
 
+BROADCOM 800 GIGABIT ROCE DRIVER
+M:	Siva Reddy Kallam <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	http://www.broadcom.com
+F:	drivers/infiniband/hw/bng_re/
+
 BROADCOM NVRAM DRIVER
 M:	Rafał Miłecki <[email protected]>
 L:	[email protected]
drivers/infiniband/Kconfig +1 -0
index f0323f1d6f01..794b9778816b 100644
@@ -80,6 +80,7 @@ config INFINIBAND_VIRT_DMA
 if INFINIBAND_USER_ACCESS || !INFINIBAND_USER_ACCESS
 if !UML
 source "drivers/infiniband/hw/bnxt_re/Kconfig"
+source "drivers/infiniband/hw/bng_re/Kconfig"
 source "drivers/infiniband/hw/cxgb4/Kconfig"
 source "drivers/infiniband/hw/efa/Kconfig"
 source "drivers/infiniband/hw/erdma/Kconfig"
drivers/infiniband/hw/Makefile +1 -0
index b706dc0d0263..c42b22ac3303 100644
@@ -13,5 +13,6 @@ obj-$(CONFIG_INFINIBAND_HFI1)		+= hfi1/
 obj-$(CONFIG_INFINIBAND_HNS_HIP08)	+= hns/
 obj-$(CONFIG_INFINIBAND_QEDR)		+= qedr/
 obj-$(CONFIG_INFINIBAND_BNXT_RE)	+= bnxt_re/
+obj-$(CONFIG_INFINIBAND_BNG_RE)		+= bng_re/
 obj-$(CONFIG_INFINIBAND_ERDMA)		+= erdma/
 obj-$(CONFIG_INFINIBAND_IONIC)		+= ionic/
drivers/infiniband/hw/bng_re/Kconfig new file +10 -0
new file mode 100644
index 000000000000..85845f72c64d
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config INFINIBAND_BNG_RE
+	tristate "Broadcom Next generation RoCE HCA support"
+	depends on 64BIT
+	depends on INET && DCB && BNGE
+	help
+	  This driver supports Broadcom Next generation
+	  50/100/200/400/800 gigabit RoCE HCAs. The module
+	  will be called bng_re. To compile this driver
+	  as a module, choose M here.
drivers/infiniband/hw/bng_re/Makefile new file +7 -0
new file mode 100644
index 000000000000..f854dae25b1c
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnge
+
+obj-$(CONFIG_INFINIBAND_BNG_RE) += bng_re.o
+
+bng_re-y := bng_dev.o
drivers/infiniband/hw/bng_re/bng_dev.c new file +142 -0

142 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_re.h new file +27 -0
new file mode 100644
index 000000000000..bd3aacdc05c4
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (c) 2025 Broadcom.
+
+#ifndef __BNG_RE_H__
+#define __BNG_RE_H__
+
+#define BNG_ROCE_DRV_MODULE_NAME	"bng_re"
+#define BNG_RE_ADEV_NAME		"bng_en"
+
+#define BNG_RE_DESC	"Broadcom 800G RoCE Driver"
+
+#define	rdev_to_dev(rdev)	((rdev) ? (&(rdev)->ibdev.dev) : NULL)
+
+struct bng_re_en_dev_info {
+	struct bng_re_dev *rdev;
+	struct bnge_auxr_dev *auxr_dev;
+};
+
+struct bng_re_dev {
+	struct ib_device		ibdev;
+	struct net_device		*netdev;
+	struct auxiliary_device         *adev;
+	struct bnge_auxr_dev		*aux_dev;
+	int				fn_id;
+};
+
+#endif
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v3 3/8 RDMA/bng_re: Register and get the resources from bnge driver

In reply to Siva Reddy Kallam

Register and get the basic required resources from bnge driver.

---
 drivers/infiniband/hw/bng_re/bng_dev.c | 149 +++++++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_re.h  |   5 +
 drivers/infiniband/hw/bng_re/bng_res.h |  16 +++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_res.h
drivers/infiniband/hw/bng_re/bng_dev.c +149 -0
index 08aba72a26f7..cad065df2032 100644
@@ -7,8 +7,10 @@
 
 #include <rdma/ib_verbs.h>
 
+#include "bng_res.h"
 #include "bng_re.h"
 #include "bnge.h"
+#include "bnge_hwrm.h"
 #include "bnge_auxr.h"
 
 static char version[] =
@@ -40,6 +42,144 @@ static struct bng_re_dev *bng_re_dev_add(struct auxiliary_device *adev,
 	return rdev;
 }
 
+
+static int bng_re_register_netdev(struct bng_re_dev *rdev)
+{
+	struct bnge_auxr_dev *aux_dev;
+
+	aux_dev = rdev->aux_dev;
+	return bnge_register_dev(aux_dev, rdev->adev);
+}
+
+static void bng_re_destroy_chip_ctx(struct bng_re_dev *rdev)
+{
+	struct bng_re_chip_ctx *chip_ctx;
+
+	if (!rdev->chip_ctx)
+		return;
+
+	chip_ctx = rdev->chip_ctx;
+	rdev->chip_ctx = NULL;
+	kfree(chip_ctx);
+}
+
+static int bng_re_setup_chip_ctx(struct bng_re_dev *rdev)
+{
+	struct bng_re_chip_ctx *chip_ctx;
+	struct bnge_auxr_dev *aux_dev;
+
+	aux_dev = rdev->aux_dev;
+
+	chip_ctx = kzalloc(sizeof(*chip_ctx), GFP_KERNEL);
+	if (!chip_ctx)
+		return -ENOMEM;
+	chip_ctx->chip_num = aux_dev->chip_num;
+	chip_ctx->hw_stats_size = aux_dev->hw_ring_stats_size;
+
+	rdev->chip_ctx = chip_ctx;
+
+	return 0;
+}
+
+static void bng_re_init_hwrm_hdr(struct input *hdr, u16 opcd)
+{
+	hdr->req_type = cpu_to_le16(opcd);
+	hdr->cmpl_ring = cpu_to_le16(-1);
+	hdr->target_id = cpu_to_le16(-1);
+}
+
+static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg,
+			       int msg_len, void *resp, int resp_max_len,
+			       int timeout)
+{
+	fw_msg->msg = msg;
+	fw_msg->msg_len = msg_len;
+	fw_msg->resp = resp;
+	fw_msg->resp_max_len = resp_max_len;
+	fw_msg->timeout = timeout;
+}
+
+static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+	struct hwrm_ver_get_output ver_get_resp = {};
+	struct hwrm_ver_get_input ver_get_req = {};
+	struct bng_re_chip_ctx *cctx;
+	struct bnge_fw_msg fw_msg = {};
+	int rc;
+
+	bng_re_init_hwrm_hdr((void *)&ver_get_req, HWRM_VER_GET);
+	ver_get_req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
+	ver_get_req.hwrm_intf_min = HWRM_VERSION_MINOR;
+	ver_get_req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
+	bng_re_fill_fw_msg(&fw_msg, (void *)&ver_get_req, sizeof(ver_get_req),
+			    (void *)&ver_get_resp, sizeof(ver_get_resp),
+			    BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (rc) {
+		ibdev_err(&rdev->ibdev, "Failed to query HW version, rc = 0x%x",
+			  rc);
+		return;
+	}
+
+	cctx = rdev->chip_ctx;
+	cctx->hwrm_intf_ver =
+		(u64)le16_to_cpu(ver_get_resp.hwrm_intf_major) << 48 |
+		(u64)le16_to_cpu(ver_get_resp.hwrm_intf_minor) << 32 |
+		(u64)le16_to_cpu(ver_get_resp.hwrm_intf_build) << 16 |
+		le16_to_cpu(ver_get_resp.hwrm_intf_patch);
+
+	cctx->hwrm_cmd_max_timeout = le16_to_cpu(ver_get_resp.max_req_timeout);
+
+	if (!cctx->hwrm_cmd_max_timeout)
+		cctx->hwrm_cmd_max_timeout = BNG_ROCE_FW_MAX_TIMEOUT;
+}
+
+static int bng_re_dev_init(struct bng_re_dev *rdev)
+{
+	int rc;
+
+	/* Registered a new RoCE device instance to netdev */
+	rc = bng_re_register_netdev(rdev);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+				"Failed to register with netedev: %#x\n", rc);
+		return -EINVAL;
+	}
+
+	set_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
+
+	if (rdev->aux_dev->auxr_info->msix_requested < BNG_RE_MIN_MSIX) {
+		ibdev_err(&rdev->ibdev,
+			  "RoCE requires minimum 2 MSI-X vectors, but only %d reserved\n",
+			  rdev->aux_dev->auxr_info->msix_requested);
+		bnge_unregister_dev(rdev->aux_dev);
+		clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
+		return -EINVAL;
+	}
+	ibdev_dbg(&rdev->ibdev, "Got %d MSI-X vectors\n",
+		  rdev->aux_dev->auxr_info->msix_requested);
+
+	rc = bng_re_setup_chip_ctx(rdev);
+	if (rc) {
+		bnge_unregister_dev(rdev->aux_dev);
+		clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
+		ibdev_err(&rdev->ibdev, "Failed to get chip context\n");
+		return -EINVAL;
+	}
+
+	bng_re_query_hwrm_version(rdev);
+
+	return 0;
+}
+
+static void bng_re_dev_uninit(struct bng_re_dev *rdev)
+{
+	bng_re_destroy_chip_ctx(rdev);
+	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
+		bnge_unregister_dev(rdev->aux_dev);
+}
+
 static int bng_re_add_device(struct auxiliary_device *adev)
 {
 	struct bnge_auxr_priv *auxr_priv =
@@ -58,7 +198,14 @@ static int bng_re_add_device(struct auxiliary_device *adev)
 
 	dev_info->rdev = rdev;
 
+	rc = bng_re_dev_init(rdev);
+	if (rc)
+		goto re_dev_dealloc;
+
 	return 0;
+
+re_dev_dealloc:
+	ib_dealloc_device(&rdev->ibdev);
 exit:
 	return rc;
 }
@@ -67,6 +214,7 @@ static int bng_re_add_device(struct auxiliary_device *adev)
 static void bng_re_remove_device(struct bng_re_dev *rdev,
 				 struct auxiliary_device *aux_dev)
 {
+	bng_re_dev_uninit(rdev);
 	ib_dealloc_device(&rdev->ibdev);
 }
 
@@ -90,6 +238,7 @@ static int bng_re_probe(struct auxiliary_device *adev,
 	rc = bng_re_add_device(adev);
 	if (rc)
 		kfree(en_info);
+
 	return rc;
 }
 
drivers/infiniband/hw/bng_re/bng_re.h +5 -0
index bd3aacdc05c4..db692ad8db0e 100644
@@ -11,6 +11,8 @@
 
 #define	rdev_to_dev(rdev)	((rdev) ? (&(rdev)->ibdev.dev) : NULL)
 
+#define BNG_RE_MIN_MSIX		2
+
 struct bng_re_en_dev_info {
 	struct bng_re_dev *rdev;
 	struct bnge_auxr_dev *auxr_dev;
@@ -18,9 +20,12 @@ struct bng_re_en_dev_info {
 
 struct bng_re_dev {
 	struct ib_device		ibdev;
+	unsigned long			flags;
+#define BNG_RE_FLAG_NETDEV_REGISTERED		0
 	struct net_device		*netdev;
 	struct auxiliary_device         *adev;
 	struct bnge_auxr_dev		*aux_dev;
+	struct bng_re_chip_ctx		*chip_ctx;
 	int				fn_id;
 };
 
drivers/infiniband/hw/bng_re/bng_res.h new file +16 -0
new file mode 100644
index 000000000000..d64833498e2a
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (c) 2025 Broadcom.
+
+#ifndef __BNG_RES_H__
+#define __BNG_RES_H__
+
+#define BNG_ROCE_FW_MAX_TIMEOUT	60
+
+struct bng_re_chip_ctx {
+	u16	chip_num;
+	u16	hw_stats_size;
+	u64	hwrm_intf_ver;
+	u16	hwrm_cmd_max_timeout;
+};
+
+#endif
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH v3 4/8 RDMA/bng_re: Allocate required memory resources for Firmware channel

In reply to Siva Reddy Kallam

Allocate required memory resources for Firmware channel.

---
 drivers/infiniband/hw/bng_re/Makefile  |   6 +-
 drivers/infiniband/hw/bng_re/bng_dev.c |  32 +++-
 drivers/infiniband/hw/bng_re/bng_fw.c  |  70 +++++++
 drivers/infiniband/hw/bng_re/bng_fw.h  |  69 +++++++
 drivers/infiniband/hw/bng_re/bng_re.h  |   2 +
 drivers/infiniband/hw/bng_re/bng_res.c | 250 +++++++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_res.h |  76 ++++++++
 7 files changed, 495 insertions(+), 10 deletions(-)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_fw.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_fw.h
 create mode 100644 drivers/infiniband/hw/bng_re/bng_res.c
drivers/infiniband/hw/bng_re/Makefile +3 -3
index f854dae25b1c..1b957defbabc 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
-
-ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnge
+ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnge -I $(srctree)/drivers/infiniband/hw/bnxt_re
 
 obj-$(CONFIG_INFINIBAND_BNG_RE) += bng_re.o
 
-bng_re-y := bng_dev.o
+bng_re-y := bng_dev.o bng_fw.o \
+	    bng_res.o
drivers/infiniband/hw/bng_re/bng_dev.c +25 -7
index cad065df2032..1506f32fb550 100644
@@ -8,6 +8,7 @@
 #include <rdma/ib_verbs.h>
 
 #include "bng_res.h"
+#include "bng_fw.h"
 #include "bng_re.h"
 #include "bnge.h"
 #include "bnge_hwrm.h"
@@ -60,6 +61,9 @@ static void bng_re_destroy_chip_ctx(struct bng_re_dev *rdev)
 
 	chip_ctx = rdev->chip_ctx;
 	rdev->chip_ctx = NULL;
+	rdev->rcfw.res = NULL;
+	rdev->bng_res.cctx = NULL;
+	rdev->bng_res.pdev = NULL;
 	kfree(chip_ctx);
 }
 
@@ -69,7 +73,8 @@ static int bng_re_setup_chip_ctx(struct bng_re_dev *rdev)
 	struct bnge_auxr_dev *aux_dev;
 
 	aux_dev = rdev->aux_dev;
-
+	rdev->bng_res.pdev = aux_dev->pdev;
+	rdev->rcfw.res = &rdev->bng_res;
 	chip_ctx = kzalloc(sizeof(*chip_ctx), GFP_KERNEL);
 	if (!chip_ctx)
 		return -ENOMEM;
@@ -77,6 +82,7 @@ static int bng_re_setup_chip_ctx(struct bng_re_dev *rdev)
 	chip_ctx->hw_stats_size = aux_dev->hw_ring_stats_size;
 
 	rdev->chip_ctx = chip_ctx;
+	rdev->bng_res.cctx = rdev->chip_ctx;
 
 	return 0;
 }
@@ -135,6 +141,14 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 		cctx->hwrm_cmd_max_timeout = BNG_ROCE_FW_MAX_TIMEOUT;
 }
 
+static void bng_re_dev_uninit(struct bng_re_dev *rdev)
+{
+	bng_re_free_rcfw_channel(&rdev->rcfw);
+	bng_re_destroy_chip_ctx(rdev);
+	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
+		bnge_unregister_dev(rdev->aux_dev);
+}
+
 static int bng_re_dev_init(struct bng_re_dev *rdev)
 {
 	int rc;
@@ -170,14 +184,18 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 
 	bng_re_query_hwrm_version(rdev);
 
+	rc = bng_re_alloc_fw_channel(&rdev->bng_res, &rdev->rcfw);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+			  "Failed to allocate RCFW Channel: %#x\n", rc);
+		goto fail;
+	}
+
 	return 0;
-}
 
-static void bng_re_dev_uninit(struct bng_re_dev *rdev)
-{
-	bng_re_destroy_chip_ctx(rdev);
-	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
-		bnge_unregister_dev(rdev->aux_dev);
+fail:
+	bng_re_dev_uninit(rdev);
+	return rc;
 }
 
 static int bng_re_add_device(struct auxiliary_device *adev)
drivers/infiniband/hw/bng_re/bng_fw.c new file +70 -0

70 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_fw.h new file +69 -0

69 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_re.h +2 -0
index db692ad8db0e..18f80e2a1a46 100644
@@ -27,6 +27,8 @@ struct bng_re_dev {
 	struct bnge_auxr_dev		*aux_dev;
 	struct bng_re_chip_ctx		*chip_ctx;
 	int				fn_id;
+	struct bng_re_res		bng_res;
+	struct bng_re_rcfw		rcfw;
 };
 
 #endif
drivers/infiniband/hw/bng_re/bng_res.c new file +250 -0

250 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_res.h +76 -0

86 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer
#5 lore raw

Re: [PATCH v3 4/8] RDMA/bng_re: Allocate required memory resources for Firmware channel

On Mon, Nov 17, 2025 at 05:11:22PM +0000, Siva Reddy Kallam wrote:

...

Quoted 23 lines
drivers/infiniband/hw/bng_re/bng_dev.c +15 -0
+static void bng_re_dev_uninit(struct bng_re_dev *rdev)
+{
+	bng_re_free_rcfw_channel(&rdev->rcfw);
+	bng_re_destroy_chip_ctx(rdev);
+	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
+		bnge_unregister_dev(rdev->aux_dev);
+}
+
 static int bng_re_dev_init(struct bng_re_dev *rdev)
 {
 	int rc;
@@ -170,14 +184,18 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 
 	bng_re_query_hwrm_version(rdev);
 
+	rc = bng_re_alloc_fw_channel(&rdev->bng_res, &rdev->rcfw);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+			  "Failed to allocate RCFW Channel: %#x\n", rc);
+		goto fail;
+	}
+
 	return 0;

drivers/infiniband/hw/bng_re/bng_dev.c static int bng_re_dev_init(struct bng_re_dev *rdev) · line 198

Quoted 10 lines
drivers/infiniband/hw/bng_re/bng_dev.c +3 -6
-}
 
-static void bng_re_dev_uninit(struct bng_re_dev *rdev)
-{
-	bng_re_destroy_chip_ctx(rdev);
-	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
-		bnge_unregister_dev(rdev->aux_dev);
+fail:
+	bng_re_dev_uninit(rdev);
+	return rc;

Hi Siva,

IMHO, I think that it would best to handle unwind using a ladder of goto statements, that reverse the order of the incremental initialisation performed by this function.

As is, this may not have much effect, other than seeming to duplicate bng_re_dev_uninit(). But I think that as bng_re_dev_init() grows, as it does in this patch-set, this will lead to clearer error handling (and ideally a lower chance of bugs later).

I would also suggest that it would be best to name the label after what tit does, rather than somewhat general name 'fail'.

Quoted 3 lines
drivers/infiniband/hw/bng_re/bng_dev.c +0 -0
 }
 
 static int bng_re_add_device(struct auxiliary_device *adev)

...

author maintainer
#6 lore raw

Re: [PATCH v3 4/8] RDMA/bng_re: Allocate required memory resources for Firmware channel

Quoted 45 lines · Simon Horman

On Mon, Nov 17, 2025 at 05:11:22PM +0000, Siva Reddy Kallam wrote:

...

Quoted 23 lines
drivers/infiniband/hw/bng_re/bng_dev.c +15 -0
+static void bng_re_dev_uninit(struct bng_re_dev *rdev)
+{
+     bng_re_free_rcfw_channel(&rdev->rcfw);
+     bng_re_destroy_chip_ctx(rdev);
+     if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
+             bnge_unregister_dev(rdev->aux_dev);
+}
+
 static int bng_re_dev_init(struct bng_re_dev *rdev)
 {
      int rc;
@@ -170,14 +184,18 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 
      bng_re_query_hwrm_version(rdev);
 
+     rc = bng_re_alloc_fw_channel(&rdev->bng_res, &rdev->rcfw);
+     if (rc) {
+             ibdev_err(&rdev->ibdev,
+                       "Failed to allocate RCFW Channel: %#x\n", rc);
+             goto fail;
+     }
+
      return 0;

drivers/infiniband/hw/bng_re/bng_dev.c static int bng_re_dev_init(struct bng_re_dev *rdev) · line 198

Quoted 10 lines
drivers/infiniband/hw/bng_re/bng_dev.c +3 -6
-}
 
-static void bng_re_dev_uninit(struct bng_re_dev *rdev)
-{
-     bng_re_destroy_chip_ctx(rdev);
-     if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
-             bnge_unregister_dev(rdev->aux_dev);
+fail:
+     bng_re_dev_uninit(rdev);
+     return rc;

Hi Siva,

IMHO, I think that it would best to handle unwind using a ladder of goto statements, that reverse the order of the incremental initialisation performed by this function.

Quoted 7 lines

As is, this may not have much effect, other than seeming to duplicate bng_re_dev_uninit(). But I think that as bng_re_dev_init() grows, as it does in this patch-set, this will lead to clearer error handling (and ideally a lower chance of bugs later).

I would also suggest that it would be best to name the label after what tit does, rather than somewhat general name 'fail'.

Thanks Simon. I will send a patch to fix this.

Quoted 6 lines
Quoted 4 lines
drivers/infiniband/hw/bng_re/bng_dev.c +0 -0
 }
 
 static int bng_re_add_device(struct auxiliary_device *adev)

...

author maintainer
#7 lore raw

PATCH v3 5/8 RDMA/bng_re: Add infrastructure for enabling Firmware channel

In reply to Siva Reddy Kallam

Add infrastructure for enabling Firmware channel.

---
 drivers/infiniband/hw/bng_re/bng_dev.c | 120 +++++++-
 drivers/infiniband/hw/bng_re/bng_fw.c  | 361 ++++++++++++++++++++++++-
 drivers/infiniband/hw/bng_re/bng_fw.h  | 133 ++++++++-
 drivers/infiniband/hw/bng_re/bng_re.h  |  45 +++
 drivers/infiniband/hw/bng_re/bng_res.c |   2 +
 drivers/infiniband/hw/bng_re/bng_res.h | 102 +++++++
 drivers/infiniband/hw/bng_re/bng_tlv.h | 128 +++++++++
 7 files changed, 885 insertions(+), 6 deletions(-)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_tlv.h
drivers/infiniband/hw/bng_re/bng_dev.c +117 -3
index 1506f32fb550..a0fba30187ff 100644
@@ -9,10 +9,10 @@
 
 #include "bng_res.h"
 #include "bng_fw.h"
-#include "bng_re.h"
 #include "bnge.h"
-#include "bnge_hwrm.h"
 #include "bnge_auxr.h"
+#include "bng_re.h"
+#include "bnge_hwrm.h"
 
 static char version[] =
 		BNG_RE_DESC "\n";
@@ -105,6 +105,69 @@ static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg,
 	fw_msg->timeout = timeout;
 }
 
+static int bng_re_net_ring_free(struct bng_re_dev *rdev,
+				u16 fw_ring_id, int type)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+	struct hwrm_ring_free_input req = {};
+	struct hwrm_ring_free_output resp;
+	struct bnge_fw_msg fw_msg = {};
+	int rc = -EINVAL;
+
+	if (!rdev)
+		return rc;
+
+	if (!aux_dev)
+		return rc;
+
+	bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_FREE);
+	req.ring_type = type;
+	req.ring_id = cpu_to_le16(fw_ring_id);
+	bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+			    sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (rc)
+		ibdev_err(&rdev->ibdev, "Failed to free HW ring:%d :%#x",
+			  req.ring_id, rc);
+	return rc;
+}
+
+static int bng_re_net_ring_alloc(struct bng_re_dev *rdev,
+				 struct bng_re_ring_attr *ring_attr,
+				 u16 *fw_ring_id)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+	struct hwrm_ring_alloc_input req = {};
+	struct hwrm_ring_alloc_output resp;
+	struct bnge_fw_msg fw_msg = {};
+	int rc = -EINVAL;
+
+	if (!aux_dev)
+		return rc;
+
+	bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_ALLOC);
+	req.enables = 0;
+	req.page_tbl_addr =  cpu_to_le64(ring_attr->dma_arr[0]);
+	if (ring_attr->pages > 1) {
+		/* Page size is in log2 units */
+		req.page_size = BNGE_PAGE_SHIFT;
+		req.page_tbl_depth = 1;
+	}
+	req.fbo = 0;
+	/* Association of ring index with doorbell index and MSIX number */
+	req.logical_id = cpu_to_le16(ring_attr->lrid);
+	req.length = cpu_to_le32(ring_attr->depth + 1);
+	req.ring_type = ring_attr->type;
+	req.int_mode = ring_attr->mode;
+	bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+			   sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (!rc)
+		*fw_ring_id = le16_to_cpu(resp.ring_id);
+
+	return rc;
+}
+
 static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 {
 	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
@@ -143,7 +206,13 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 
 static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 {
+	bng_re_disable_rcfw_channel(&rdev->rcfw);
+	bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
+			     RING_ALLOC_REQ_RING_TYPE_NQ);
 	bng_re_free_rcfw_channel(&rdev->rcfw);
+
+	kfree(rdev->nqr);
+	rdev->nqr = NULL;
 	bng_re_destroy_chip_ctx(rdev);
 	if (test_and_clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags))
 		bnge_unregister_dev(rdev->aux_dev);
@@ -151,6 +220,11 @@ static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 
 static int bng_re_dev_init(struct bng_re_dev *rdev)
 {
+	struct bng_re_ring_attr rattr = {};
+	struct bng_re_creq_ctx *creq;
+	u32 db_offt;
+	int vid;
+	u8 type;
 	int rc;
 
 	/* Registered a new RoCE device instance to netdev */
@@ -191,8 +265,48 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 		goto fail;
 	}
 
-	return 0;
+	/* Allocate nq record memory */
+	rdev->nqr = kzalloc(sizeof(*rdev->nqr), GFP_KERNEL);
+	if (!rdev->nqr) {
+		bng_re_destroy_chip_ctx(rdev);
+		bnge_unregister_dev(rdev->aux_dev);
+		clear_bit(BNG_RE_FLAG_NETDEV_REGISTERED, &rdev->flags);
+		return -ENOMEM;
+	}
 
+	rdev->nqr->num_msix = rdev->aux_dev->auxr_info->msix_requested;
+	memcpy(rdev->nqr->msix_entries, rdev->aux_dev->msix_info,
+	       sizeof(struct bnge_msix_info) * rdev->nqr->num_msix);
+
+	type = RING_ALLOC_REQ_RING_TYPE_NQ;
+	creq = &rdev->rcfw.creq;
+	rattr.dma_arr = creq->hwq.pbl[BNG_PBL_LVL_0].pg_map_arr;
+	rattr.pages = creq->hwq.pbl[creq->hwq.level].pg_count;
+	rattr.type = type;
+	rattr.mode = RING_ALLOC_REQ_INT_MODE_MSIX;
+	rattr.depth = BNG_FW_CREQE_MAX_CNT - 1;
+	rattr.lrid = rdev->nqr->msix_entries[BNG_RE_CREQ_NQ_IDX].ring_idx;
+	rc = bng_re_net_ring_alloc(rdev, &rattr, &creq->ring_id);
+	if (rc) {
+		ibdev_err(&rdev->ibdev, "Failed to allocate CREQ: %#x\n", rc);
+		goto free_rcfw;
+	}
+	db_offt = rdev->nqr->msix_entries[BNG_RE_CREQ_NQ_IDX].db_offset;
+	vid = rdev->nqr->msix_entries[BNG_RE_CREQ_NQ_IDX].vector;
+
+	rc = bng_re_enable_fw_channel(&rdev->rcfw,
+					vid, db_offt);
+	if (rc) {
+		ibdev_err(&rdev->ibdev, "Failed to enable RCFW channel: %#x\n",
+			  rc);
+		goto free_ring;
+	}
+
+	return 0;
+free_ring:
+	bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id, type);
+free_rcfw:
+	bng_re_free_rcfw_channel(&rdev->rcfw);
 fail:
 	bng_re_dev_uninit(rdev);
 	return rc;
drivers/infiniband/hw/bng_re/bng_fw.c +360 -1

376 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_fw.h +131 -2

175 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_re.h +45 -0

69 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_res.c +2 -0
index 2119d1f39b65..cb42c0fd2cdf 100644
@@ -5,6 +5,7 @@
 #include <linux/vmalloc.h>
 #include <rdma/ib_umem.h>
 
+#include <linux/bnxt/hsi.h>
 #include "bng_res.h"
 #include "roce_hsi.h"
 
@@ -235,6 +236,7 @@ int bng_re_alloc_init_hwq(struct bng_re_hwq *hwq,
 	hwq->depth = hwq_attr->depth;
 	hwq->max_elements = hwq->depth;
 	hwq->element_size = stride;
+	hwq->qe_ppg = pg_size / stride;
 	/* For direct access to the elements */
 	lvl = hwq->level;
 	if (hwq_attr->sginfo->nopte && hwq->level)
drivers/infiniband/hw/bng_re/bng_res.h +102 -0

132 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_tlv.h new file +128 -0

128 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#8 lore raw

Re: [PATCH v3 5/8] RDMA/bng_re: Add infrastructure for enabling Firmware channel

Quoted 14 lines · Siva Reddy Kallam

Add infrastructure for enabling Firmware channel.

---
 drivers/infiniband/hw/bng_re/bng_dev.c | 120 +++++++-
 drivers/infiniband/hw/bng_re/bng_fw.c  | 361 ++++++++++++++++++++++++-
 drivers/infiniband/hw/bng_re/bng_fw.h  | 133 ++++++++-
 drivers/infiniband/hw/bng_re/bng_re.h  |  45 +++
 drivers/infiniband/hw/bng_re/bng_res.c |   2 +
 drivers/infiniband/hw/bng_re/bng_res.h | 102 +++++++
 drivers/infiniband/hw/bng_re/bng_tlv.h | 128 +++++++++
 7 files changed, 885 insertions(+), 6 deletions(-)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_tlv.h

<...>

Quoted 8 lines
drivers/infiniband/hw/bng_re/bng_fw.c +8 -0
+int bng_re_rcfw_start_irq(struct bng_re_rcfw *rcfw, int msix_vector,
+			  bool need_init)
+{
+	struct bng_re_creq_ctx *creq;
+	struct bng_re_res *res;
+	int rc;
+
+	creq = &rcfw->creq;

drivers/infiniband/hw/bng_re/bng_fw.c int bng_re_alloc_fw_channel(struct bng_re_res *res, · line 302

Quoted 10 lines
drivers/infiniband/hw/bng_re/bng_fw.c +10 -0
+	res = rcfw->res;
+
+	if (creq->irq_handler_avail)
+		return -EFAULT;
+
+	creq->msix_vec = msix_vector;
+	if (need_init)
+		tasklet_setup(&creq->creq_tasklet, bng_re_service_creq);
+	else
+		tasklet_enable(&creq->creq_tasklet);

I wonder if new drivers need to use workqueues instead.
https://lwn.net/Articles/966894/

Thanks

reviewer
#9 lore raw

Re: [PATCH v3 5/8] RDMA/bng_re: Add infrastructure for enabling Firmware channel

In reply to Siva Reddy Kallam

On Mon, Nov 17, 2025 at 05:11:23PM +0000, Siva Reddy Kallam wrote:

...

Quoted 1 line
drivers/infiniband/hw/bng_re/bng_dev.c +0 -0

...

drivers/infiniband/hw/bng_re/bng_dev.c static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg, · line 111

Quoted 8 lines
drivers/infiniband/hw/bng_re/bng_dev.c +4 -0
@@ -105,6 +105,69 @@ static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg,
 	fw_msg->timeout = timeout;
 }
 
+static int bng_re_net_ring_free(struct bng_re_dev *rdev,
+				u16 fw_ring_id, int type)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;

Hi Siva,

rdev is dereferenced unconditionally here...

drivers/infiniband/hw/bng_re/bng_dev.c static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg, · line 118

Quoted 7 lines
drivers/infiniband/hw/bng_re/bng_dev.c +7 -0
+	struct hwrm_ring_free_input req = {};
+	struct hwrm_ring_free_output resp;
+	struct bnge_fw_msg fw_msg = {};
+	int rc = -EINVAL;
+
+	if (!rdev)
+		return rc;

... but it is assumed that rdev may be NULL here.

This does not seem consistent.

IMHO a good approach would be to drop this check, and the one below, and only call bng_re_net_ring_free() in contexts where rdev and aux_dev are not NULL.

But I didn't look carefully to see if that idea matches the rest of the code.

Flagged by Smatch.

Quoted 15 lines
drivers/infiniband/hw/bng_re/bng_dev.c +15 -0
+
+	if (!aux_dev)
+		return rc;
+
+	bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_FREE);
+	req.ring_type = type;
+	req.ring_id = cpu_to_le16(fw_ring_id);
+	bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+			    sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (rc)
+		ibdev_err(&rdev->ibdev, "Failed to free HW ring:%d :%#x",
+			  req.ring_id, rc);
+	return rc;
+}

...

Quoted 1 line
drivers/infiniband/hw/bng_re/bng_fw.c +0 -0

...

drivers/infiniband/hw/bng_re/bng_fw.c int bng_re_alloc_fw_channel(struct bng_re_res *res, · line 83

Quoted 12 lines
drivers/infiniband/hw/bng_re/bng_fw.c +12 -0
+static int bng_re_process_qp_event(struct bng_re_rcfw *rcfw,
+				   struct creq_qp_event *qp_event,
+				   u32 *num_wait)
+{
+	struct bng_re_hwq *hwq = &rcfw->cmdq.hwq;
+	struct bng_re_crsqe *crsqe;
+	u32 req_size;
+	u16 cookie;
+	bool is_waiter_alive;
+	struct pci_dev *pdev;
+	u32 wait_cmds = 0;
+	int rc = 0;

rc is always 0, so it may be slightly nicer to remove this variable and simply return 0.

Flagged by Coccinelle.

Quoted 60 lines
drivers/infiniband/hw/bng_re/bng_fw.c +60 -0
+
+	pdev = rcfw->pdev;
+	switch (qp_event->event) {
+	case CREQ_QP_EVENT_EVENT_QP_ERROR_NOTIFICATION:
+		dev_err(&pdev->dev, "Received QP error notification\n");
+		break;
+	default:
+		/*
+		 * Command Response
+		 * cmdq->lock needs to be acquired to synchronie
+		 * the command send and completion reaping. This function
+		 * is always called with creq->lock held. Using
+		 * the nested variant of spin_lock.
+		 *
+		 */
+
+		spin_lock_nested(&hwq->lock, SINGLE_DEPTH_NESTING);
+		cookie = le16_to_cpu(qp_event->cookie);
+		cookie &= BNG_FW_MAX_COOKIE_VALUE;
+		crsqe = &rcfw->crsqe_tbl[cookie];
+
+		if (WARN_ONCE(test_bit(FIRMWARE_STALL_DETECTED,
+				       &rcfw->cmdq.flags),
+		    "Unreponsive rcfw channel detected.!!")) {
+			dev_info(&pdev->dev,
+				 "rcfw timedout: cookie = %#x, free_slots = %d",
+				 cookie, crsqe->free_slots);
+			spin_unlock(&hwq->lock);
+			return rc;
+		}
+
+		if (crsqe->is_waiter_alive) {
+			if (crsqe->resp) {
+				memcpy(crsqe->resp, qp_event, sizeof(*qp_event));
+				/* Insert write memory barrier to ensure that
+				 * response data is copied before clearing the
+				 * flags
+				 */
+				smp_wmb();
+			}
+		}
+
+		wait_cmds++;
+
+		req_size = crsqe->req_size;
+		is_waiter_alive = crsqe->is_waiter_alive;
+
+		crsqe->req_size = 0;
+		if (!is_waiter_alive)
+			crsqe->resp = NULL;
+
+		crsqe->is_in_used = false;
+
+		hwq->cons += req_size;
+
+		spin_unlock(&hwq->lock);
+	}
+	*num_wait += wait_cmds;
+	return rc;
+}

...

author maintainer
#10 lore raw

Re: [PATCH v3 5/8] RDMA/bng_re: Add infrastructure for enabling Firmware channel

Quoted 34 lines · Simon Horman

On Mon, Nov 17, 2025 at 05:11:23PM +0000, Siva Reddy Kallam wrote:

...

Quoted 1 line
drivers/infiniband/hw/bng_re/bng_dev.c +0 -0

...

drivers/infiniband/hw/bng_re/bng_dev.c static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg, · line 111

Quoted 8 lines
drivers/infiniband/hw/bng_re/bng_dev.c +4 -0
@@ -105,6 +105,69 @@ static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg,
      fw_msg->timeout = timeout;
 }
 
+static int bng_re_net_ring_free(struct bng_re_dev *rdev,
+                             u16 fw_ring_id, int type)
+{
+     struct bnge_auxr_dev *aux_dev = rdev->aux_dev;

Hi Siva,

rdev is dereferenced unconditionally here...

drivers/infiniband/hw/bng_re/bng_dev.c static void bng_re_fill_fw_msg(struct bnge_fw_msg *fw_msg, void *msg, · line 118

Quoted 7 lines
drivers/infiniband/hw/bng_re/bng_dev.c +7 -0
+     struct hwrm_ring_free_input req = {};
+     struct hwrm_ring_free_output resp;
+     struct bnge_fw_msg fw_msg = {};
+     int rc = -EINVAL;
+
+     if (!rdev)
+             return rc;

... but it is assumed that rdev may be NULL here.

This does not seem consistent.

Quoted 8 lines

IMHO a good approach would be to drop this check, and the one below, and only call bng_re_net_ring_free() in contexts where rdev and aux_dev are not NULL.

But I didn't look carefully to see if that idea matches the rest of the code.

Flagged by Smatch.

Thanks Simon, it is a good catch. I will send a patch to fix this.

Quoted 39 lines
Quoted 16 lines
drivers/infiniband/hw/bng_re/bng_dev.c +15 -0
+
+     if (!aux_dev)
+             return rc;
+
+     bng_re_init_hwrm_hdr((void *)&req, HWRM_RING_FREE);
+     req.ring_type = type;
+     req.ring_id = cpu_to_le16(fw_ring_id);
+     bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+                         sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+     rc = bnge_send_msg(aux_dev, &fw_msg);
+     if (rc)
+             ibdev_err(&rdev->ibdev, "Failed to free HW ring:%d :%#x",
+                       req.ring_id, rc);
+     return rc;
+}

...

Quoted 1 line
drivers/infiniband/hw/bng_re/bng_fw.c +0 -0

...

drivers/infiniband/hw/bng_re/bng_fw.c int bng_re_alloc_fw_channel(struct bng_re_res *res, · line 83

Quoted 12 lines
drivers/infiniband/hw/bng_re/bng_fw.c +12 -0
+static int bng_re_process_qp_event(struct bng_re_rcfw *rcfw,
+                                struct creq_qp_event *qp_event,
+                                u32 *num_wait)
+{
+     struct bng_re_hwq *hwq = &rcfw->cmdq.hwq;
+     struct bng_re_crsqe *crsqe;
+     u32 req_size;
+     u16 cookie;
+     bool is_waiter_alive;
+     struct pci_dev *pdev;
+     u32 wait_cmds = 0;
+     int rc = 0;

rc is always 0, so it may be slightly nicer to remove this variable and simply return 0.

Quoted 1 line

Flagged by Coccinelle.

Thanks Simon. I will send a patch to fix this.

Quoted 63 lines
Quoted 61 lines
drivers/infiniband/hw/bng_re/bng_fw.c +60 -0
+
+     pdev = rcfw->pdev;
+     switch (qp_event->event) {
+     case CREQ_QP_EVENT_EVENT_QP_ERROR_NOTIFICATION:
+             dev_err(&pdev->dev, "Received QP error notification\n");
+             break;
+     default:
+             /*
+              * Command Response
+              * cmdq->lock needs to be acquired to synchronie
+              * the command send and completion reaping. This function
+              * is always called with creq->lock held. Using
+              * the nested variant of spin_lock.
+              *
+              */
+
+             spin_lock_nested(&hwq->lock, SINGLE_DEPTH_NESTING);
+             cookie = le16_to_cpu(qp_event->cookie);
+             cookie &= BNG_FW_MAX_COOKIE_VALUE;
+             crsqe = &rcfw->crsqe_tbl[cookie];
+
+             if (WARN_ONCE(test_bit(FIRMWARE_STALL_DETECTED,
+                                    &rcfw->cmdq.flags),
+                 "Unreponsive rcfw channel detected.!!")) {
+                     dev_info(&pdev->dev,
+                              "rcfw timedout: cookie = %#x, free_slots = %d",
+                              cookie, crsqe->free_slots);
+                     spin_unlock(&hwq->lock);
+                     return rc;
+             }
+
+             if (crsqe->is_waiter_alive) {
+                     if (crsqe->resp) {
+                             memcpy(crsqe->resp, qp_event, sizeof(*qp_event));
+                             /* Insert write memory barrier to ensure that
+                              * response data is copied before clearing the
+                              * flags
+                              */
+                             smp_wmb();
+                     }
+             }
+
+             wait_cmds++;
+
+             req_size = crsqe->req_size;
+             is_waiter_alive = crsqe->is_waiter_alive;
+
+             crsqe->req_size = 0;
+             if (!is_waiter_alive)
+                     crsqe->resp = NULL;
+
+             crsqe->is_in_used = false;
+
+             hwq->cons += req_size;
+
+             spin_unlock(&hwq->lock);
+     }
+     *num_wait += wait_cmds;
+     return rc;
+}

...

author maintainer
#11 lore raw

PATCH v3 6/8 RDMA/bng_re: Enable Firmware channel and query device attributes

In reply to Siva Reddy Kallam

Enable Firmware channel and query device attributes

---
 drivers/infiniband/hw/bng_re/Makefile  |   2 +-
 drivers/infiniband/hw/bng_re/bng_dev.c |  18 ++
 drivers/infiniband/hw/bng_re/bng_fw.c  | 279 ++++++++++++++++++++++++-
 drivers/infiniband/hw/bng_re/bng_fw.h  |   9 +
 drivers/infiniband/hw/bng_re/bng_re.h  |   2 +
 drivers/infiniband/hw/bng_re/bng_res.h |   7 +
 drivers/infiniband/hw/bng_re/bng_sp.c  | 131 ++++++++++++
 drivers/infiniband/hw/bng_re/bng_sp.h  |  47 +++++
 8 files changed, 491 insertions(+), 4 deletions(-)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_sp.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_sp.h
drivers/infiniband/hw/bng_re/Makefile +1 -1
index 1b957defbabc..556b763b43f9 100644
@@ -4,4 +4,4 @@ ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnge -I $(srctree)/driv
 obj-$(CONFIG_INFINIBAND_BNG_RE) += bng_re.o
 
 bng_re-y := bng_dev.o bng_fw.o \
-	    bng_res.o
+	    bng_res.o bng_sp.o
drivers/infiniband/hw/bng_re/bng_dev.c +18 -0
index a0fba30187ff..cdebe408f50f 100644
@@ -8,6 +8,7 @@
 #include <rdma/ib_verbs.h>
 
 #include "bng_res.h"
+#include "bng_sp.h"
 #include "bng_fw.h"
 #include "bnge.h"
 #include "bnge_auxr.h"
@@ -59,6 +60,9 @@ static void bng_re_destroy_chip_ctx(struct bng_re_dev *rdev)
 	if (!rdev->chip_ctx)
 		return;
 
+	kfree(rdev->dev_attr);
+	rdev->dev_attr = NULL;
+
 	chip_ctx = rdev->chip_ctx;
 	rdev->chip_ctx = NULL;
 	rdev->rcfw.res = NULL;
@@ -71,6 +75,7 @@ static int bng_re_setup_chip_ctx(struct bng_re_dev *rdev)
 {
 	struct bng_re_chip_ctx *chip_ctx;
 	struct bnge_auxr_dev *aux_dev;
+	int rc = -ENOMEM;
 
 	aux_dev = rdev->aux_dev;
 	rdev->bng_res.pdev = aux_dev->pdev;
@@ -83,8 +88,16 @@ static int bng_re_setup_chip_ctx(struct bng_re_dev *rdev)
 
 	rdev->chip_ctx = chip_ctx;
 	rdev->bng_res.cctx = rdev->chip_ctx;
+	rdev->dev_attr = kzalloc(sizeof(*rdev->dev_attr), GFP_KERNEL);
+	if (!rdev->dev_attr)
+		goto free_chip_ctx;
+	rdev->bng_res.dattr = rdev->dev_attr;
 
 	return 0;
+free_chip_ctx:
+	kfree(rdev->chip_ctx);
+	rdev->chip_ctx = NULL;
+	return rc;
 }
 
 static void bng_re_init_hwrm_hdr(struct input *hdr, u16 opcd)
@@ -302,7 +315,12 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 		goto free_ring;
 	}
 
+	rc = bng_re_get_dev_attr(&rdev->rcfw);
+	if (rc)
+		goto disable_rcfw;
 	return 0;
+disable_rcfw:
+	bng_re_disable_rcfw_channel(&rdev->rcfw);
 free_ring:
 	bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id, type);
 free_rcfw:
drivers/infiniband/hw/bng_re/bng_fw.c +276 -3

314 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_fw.h +9 -0
index d1773832b592..88476d6c1d07 100644
@@ -136,6 +136,13 @@ struct bng_re_cmdqmsg {
 	u8			block;
 };
 
+static inline void bng_re_rcfw_cmd_prep(struct cmdq_base *req,
+					u8 opcode, u8 cmd_size)
+{
+	req->opcode = opcode;
+	req->cmd_size = cmd_size;
+}
+
 static inline void bng_re_fill_cmdqmsg(struct bng_re_cmdqmsg *msg,
 				       void *req, void *resp, void *sb,
 				       u32 req_sz, u32 res_sz, u8 block)
@@ -195,4 +202,6 @@ void bng_re_disable_rcfw_channel(struct bng_re_rcfw *rcfw);
 int bng_re_rcfw_start_irq(struct bng_re_rcfw *rcfw, int msix_vector,
 			  bool need_init);
 void bng_re_rcfw_stop_irq(struct bng_re_rcfw *rcfw, bool kill);
+int bng_re_rcfw_send_message(struct bng_re_rcfw *rcfw,
+			     struct bng_re_cmdqmsg *msg);
 #endif
drivers/infiniband/hw/bng_re/bng_re.h +2 -0
index 033ca94d5164..7598dd91043b 100644
@@ -74,6 +74,8 @@ struct bng_re_dev {
 	struct bng_re_res		bng_res;
 	struct bng_re_rcfw		rcfw;
 	struct bng_re_nq_record		*nqr;
+	/* Device Resources */
+	struct bng_re_dev_attr		*dev_attr;
 };
 
 #endif
drivers/infiniband/hw/bng_re/bng_res.h +7 -0
index f40f3477125f..7315db347aa6 100644
@@ -30,6 +30,7 @@
 #define BNG_RE_DBR_EPOCH_SHIFT	24
 #define BNG_RE_DBR_TOGGLE_SHIFT	25
 
+#define BNG_MAX_TQM_ALLOC_REQ	48
 
 struct bng_re_reg_desc {
 	u8		bar_id;
@@ -127,6 +128,7 @@ struct bng_re_hwq {
 struct bng_re_res {
 	struct pci_dev			*pdev;
 	struct bng_re_chip_ctx		*cctx;
+	struct bng_re_dev_attr		*dattr;
 };
 
 static inline void *bng_re_get_qe(struct bng_re_hwq *hwq,
@@ -186,6 +188,11 @@ static inline void bng_re_hwq_incr_cons(u32 max_elements, u32 *cons, u32 cnt,
 	}
 }
 
+static inline bool _is_max_srq_ext_supported(u16 dev_cap_ext_flags_2)
+{
+	return !!(dev_cap_ext_flags_2 & CREQ_QUERY_FUNC_RESP_SB_MAX_SRQ_EXTENDED);
+}
+
 void bng_re_free_hwq(struct bng_re_res *res,
 		     struct bng_re_hwq *hwq);
 
drivers/infiniband/hw/bng_re/bng_sp.c new file +131 -0

131 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_sp.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#12 lore raw

PATCH v3 7/8 RDMA/bng_re: Add basic debugfs infrastructure

In reply to Siva Reddy Kallam

Add basic debugfs infrastructure for Broadcom next generation controller.

---
 drivers/infiniband/hw/bng_re/Makefile      |  3 +-
 drivers/infiniband/hw/bng_re/bng_debugfs.c | 39 ++++++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_debugfs.h | 12 +++++++
 drivers/infiniband/hw/bng_re/bng_dev.c     | 12 +++++++
 drivers/infiniband/hw/bng_re/bng_re.h      |  1 +
 5 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 drivers/infiniband/hw/bng_re/bng_debugfs.c
 create mode 100644 drivers/infiniband/hw/bng_re/bng_debugfs.h
drivers/infiniband/hw/bng_re/Makefile +2 -1
index 556b763b43f9..c6aaaf853c77 100644
@@ -4,4 +4,5 @@ ccflags-y := -I $(srctree)/drivers/net/ethernet/broadcom/bnge -I $(srctree)/driv
 obj-$(CONFIG_INFINIBAND_BNG_RE) += bng_re.o
 
 bng_re-y := bng_dev.o bng_fw.o \
-	    bng_res.o bng_sp.o
+	    bng_res.o bng_sp.o \
+	    bng_debugfs.o
drivers/infiniband/hw/bng_re/bng_debugfs.c new file +39 -0
new file mode 100644
index 000000000000..9ec5a8785250
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2025 Broadcom.
+#include <linux/debugfs.h>
+#include <linux/pci.h>
+
+#include <rdma/ib_verbs.h>
+
+#include "bng_res.h"
+#include "bng_fw.h"
+#include "bnge.h"
+#include "bnge_auxr.h"
+#include "bng_re.h"
+#include "bng_debugfs.h"
+
+static struct dentry *bng_re_debugfs_root;
+
+void bng_re_debugfs_add_pdev(struct bng_re_dev *rdev)
+{
+	struct pci_dev *pdev = rdev->aux_dev->pdev;
+
+	rdev->dbg_root =
+		debugfs_create_dir(dev_name(&pdev->dev), bng_re_debugfs_root);
+}
+
+void bng_re_debugfs_rem_pdev(struct bng_re_dev *rdev)
+{
+	debugfs_remove_recursive(rdev->dbg_root);
+	rdev->dbg_root = NULL;
+}
+
+void bng_re_register_debugfs(void)
+{
+	bng_re_debugfs_root = debugfs_create_dir("bng_re", NULL);
+}
+
+void bng_re_unregister_debugfs(void)
+{
+	debugfs_remove(bng_re_debugfs_root);
+}
drivers/infiniband/hw/bng_re/bng_debugfs.h new file +12 -0
new file mode 100644
index 000000000000..baef71df4242
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (c) 2025 Broadcom.
+
+#ifndef __BNG_RE_DEBUGFS__
+#define __BNG_RE_DEBUGFS__
+
+void bng_re_debugfs_add_pdev(struct bng_re_dev *rdev);
+void bng_re_debugfs_rem_pdev(struct bng_re_dev *rdev);
+
+void bng_re_register_debugfs(void);
+void bng_re_unregister_debugfs(void);
+#endif
drivers/infiniband/hw/bng_re/bng_dev.c +12 -0
index cdebe408f50f..9dbd8837457d 100644
@@ -14,6 +14,7 @@
 #include "bnge_auxr.h"
 #include "bng_re.h"
 #include "bnge_hwrm.h"
+#include "bng_debugfs.h"
 
 static char version[] =
 		BNG_RE_DESC "\n";
@@ -219,6 +220,7 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 
 static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 {
+	bng_re_debugfs_rem_pdev(rdev);
 	bng_re_disable_rcfw_channel(&rdev->rcfw);
 	bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
 			     RING_ALLOC_REQ_RING_TYPE_NQ);
@@ -318,6 +320,9 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 	rc = bng_re_get_dev_attr(&rdev->rcfw);
 	if (rc)
 		goto disable_rcfw;
+
+	bng_re_debugfs_add_pdev(rdev);
+
 	return 0;
 disable_rcfw:
 	bng_re_disable_rcfw_channel(&rdev->rcfw);
@@ -424,17 +429,24 @@ static int __init bng_re_mod_init(void)
 
 	pr_info("%s: %s", BNG_ROCE_DRV_MODULE_NAME, version);
 
+	bng_re_register_debugfs();
+
 	rc = auxiliary_driver_register(&bng_re_driver);
 	if (rc) {
 		pr_err("%s: Failed to register auxiliary driver\n",
 		       BNG_ROCE_DRV_MODULE_NAME);
+		goto unreg_debugfs;
 	}
+	return 0;
+unreg_debugfs:
+	bng_re_unregister_debugfs();
 	return rc;
 }
 
 static void __exit bng_re_mod_exit(void)
 {
 	auxiliary_driver_unregister(&bng_re_driver);
+	bng_re_unregister_debugfs();
 }
 
 module_init(bng_re_mod_init);
drivers/infiniband/hw/bng_re/bng_re.h +1 -0
index 7598dd91043b..76837f17f12d 100644
@@ -76,6 +76,7 @@ struct bng_re_dev {
 	struct bng_re_nq_record		*nqr;
 	/* Device Resources */
 	struct bng_re_dev_attr		*dev_attr;
+	struct dentry			*dbg_root;
 };
 
 #endif
Signature · 1 line
2.43.0
author maintainer
#13 lore raw

PATCH v3 8/8 RDMA/bng_re: Initialize the Firmware and Hardware

In reply to Siva Reddy Kallam

Initialize the firmware and hardware with HWRM command.

---
 drivers/infiniband/hw/bng_re/bng_dev.c | 92 +++++++++++++++++++++++++-
 drivers/infiniband/hw/bng_re/bng_fw.c  | 65 ++++++++++++++++++
 drivers/infiniband/hw/bng_re/bng_fw.h  |  4 ++
 drivers/infiniband/hw/bng_re/bng_re.h  |  4 ++
 drivers/infiniband/hw/bng_re/bng_res.c | 27 ++++++++
 drivers/infiniband/hw/bng_re/bng_res.h | 14 ++++
 6 files changed, 203 insertions(+), 3 deletions(-)
drivers/infiniband/hw/bng_re/bng_dev.c +89 -3
index 9dbd8837457d..454789432178 100644
@@ -182,6 +182,56 @@ static int bng_re_net_ring_alloc(struct bng_re_dev *rdev,
 	return rc;
 }
 
+static int bng_re_stats_ctx_free(struct bng_re_dev *rdev)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+	struct hwrm_stat_ctx_free_input req = {};
+	struct hwrm_stat_ctx_free_output resp = {};
+	struct bnge_fw_msg fw_msg = {};
+	int rc = -EINVAL;
+
+	if (!aux_dev)
+		return rc;
+
+	bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_FREE);
+	req.stat_ctx_id = cpu_to_le32(rdev->stats_ctx.fw_id);
+	bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+			   sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (rc)
+		ibdev_err(&rdev->ibdev, "Failed to free HW stats context %#x",
+			  rc);
+
+	return rc;
+}
+
+static int bng_re_stats_ctx_alloc(struct bng_re_dev *rdev)
+{
+	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
+	struct bng_re_stats *stats = &rdev->stats_ctx;
+	struct hwrm_stat_ctx_alloc_output resp = {};
+	struct hwrm_stat_ctx_alloc_input req = {};
+	struct bnge_fw_msg fw_msg = {};
+	int rc = -EINVAL;
+
+	stats->fw_id = BNGE_INVALID_STATS_CTX_ID;
+
+	if (!aux_dev)
+		return rc;
+
+	bng_re_init_hwrm_hdr((void *)&req, HWRM_STAT_CTX_ALLOC);
+	req.update_period_ms = cpu_to_le32(1000);
+	req.stats_dma_addr = cpu_to_le64(stats->dma_map);
+	req.stats_dma_length = cpu_to_le16(rdev->chip_ctx->hw_stats_size);
+	req.stat_ctx_flags = STAT_CTX_ALLOC_REQ_STAT_CTX_FLAGS_ROCE;
+	bng_re_fill_fw_msg(&fw_msg, (void *)&req, sizeof(req), (void *)&resp,
+			   sizeof(resp), BNGE_DFLT_HWRM_CMD_TIMEOUT);
+	rc = bnge_send_msg(aux_dev, &fw_msg);
+	if (!rc)
+		stats->fw_id = le32_to_cpu(resp.stat_ctx_id);
+	return rc;
+}
+
 static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 {
 	struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
@@ -220,11 +270,21 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
 
 static void bng_re_dev_uninit(struct bng_re_dev *rdev)
 {
+	int rc;
 	bng_re_debugfs_rem_pdev(rdev);
-	bng_re_disable_rcfw_channel(&rdev->rcfw);
-	bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
+
+	if (test_and_clear_bit(BNG_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags)) {
+		rc = bng_re_deinit_rcfw(&rdev->rcfw);
+		if (rc)
+			ibdev_warn(&rdev->ibdev,
+				   "Failed to deinitialize RCFW: %#x", rc);
+		bng_re_stats_ctx_free(rdev);
+		bng_re_free_stats_ctx_mem(rdev->bng_res.pdev, &rdev->stats_ctx);
+		bng_re_disable_rcfw_channel(&rdev->rcfw);
+		bng_re_net_ring_free(rdev, rdev->rcfw.creq.ring_id,
 			     RING_ALLOC_REQ_RING_TYPE_NQ);
-	bng_re_free_rcfw_channel(&rdev->rcfw);
+		bng_re_free_rcfw_channel(&rdev->rcfw);
+	}
 
 	kfree(rdev->nqr);
 	rdev->nqr = NULL;
@@ -322,8 +382,34 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
 		goto disable_rcfw;
 
 	bng_re_debugfs_add_pdev(rdev);
+	rc = bng_re_alloc_stats_ctx_mem(rdev->bng_res.pdev, rdev->chip_ctx,
+					&rdev->stats_ctx);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+			  "Failed to allocate stats context: %#x\n", rc);
+		goto disable_rcfw;
+	}
+
+	rc = bng_re_stats_ctx_alloc(rdev);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+			  "Failed to allocate QPLIB context: %#x\n", rc);
+		goto free_stats_ctx;
+	}
+
+	rc = bng_re_init_rcfw(&rdev->rcfw, &rdev->stats_ctx);
+	if (rc) {
+		ibdev_err(&rdev->ibdev,
+			  "Failed to initialize RCFW: %#x\n", rc);
+		goto free_sctx;
+	}
+	set_bit(BNG_RE_FLAG_RCFW_CHANNEL_EN, &rdev->flags);
 
 	return 0;
+free_sctx:
+	bng_re_stats_ctx_free(rdev);
+free_stats_ctx:
+	bng_re_free_stats_ctx_mem(rdev->bng_res.pdev, &rdev->stats_ctx);
 disable_rcfw:
 	bng_re_disable_rcfw_channel(&rdev->rcfw);
 free_ring:
drivers/infiniband/hw/bng_re/bng_fw.c +65 -0

74 lines not on this page · raw message

drivers/infiniband/hw/bng_re/bng_fw.h +4 -0
index 88476d6c1d07..c89c926ec2fc 100644
@@ -10,6 +10,7 @@
 #define BNG_FW_CMDQ_TRIG_VAL		1
 #define BNG_FW_COMM_PCI_BAR_REGION	0
 #define BNG_FW_COMM_CONS_PCI_BAR_REGION	2
+#define BNG_FW_DBR_BASE_PAGE_SHIFT	12
 #define BNG_FW_COMM_SIZE		0x104
 #define BNG_FW_COMM_BASE_OFFSET		0x600
 #define BNG_FW_COMM_TRIG_OFFSET		0x100
@@ -204,4 +205,7 @@ int bng_re_rcfw_start_irq(struct bng_re_rcfw *rcfw, int msix_vector,
 void bng_re_rcfw_stop_irq(struct bng_re_rcfw *rcfw, bool kill);
 int bng_re_rcfw_send_message(struct bng_re_rcfw *rcfw,
 			     struct bng_re_cmdqmsg *msg);
+int bng_re_init_rcfw(struct bng_re_rcfw *rcfw,
+		     struct bng_re_stats *stats_ctx);
+int bng_re_deinit_rcfw(struct bng_re_rcfw *rcfw);
 #endif
drivers/infiniband/hw/bng_re/bng_re.h +4 -0
index 76837f17f12d..f63791d716b7 100644
@@ -17,6 +17,8 @@
 #define BNG_RE_MAX_MSIX		BNGE_MAX_ROCE_MSIX
 
 #define BNG_RE_CREQ_NQ_IDX	0
+
+#define BNGE_INVALID_STATS_CTX_ID	-1
 /* NQ specific structures  */
 struct bng_re_nq_db {
 	struct bng_re_reg_desc	reg;
@@ -66,6 +68,7 @@ struct bng_re_dev {
 	struct ib_device		ibdev;
 	unsigned long			flags;
 #define BNG_RE_FLAG_NETDEV_REGISTERED		0
+#define BNG_RE_FLAG_RCFW_CHANNEL_EN		1
 	struct net_device		*netdev;
 	struct auxiliary_device         *adev;
 	struct bnge_auxr_dev		*aux_dev;
@@ -77,6 +80,7 @@ struct bng_re_dev {
 	/* Device Resources */
 	struct bng_re_dev_attr		*dev_attr;
 	struct dentry			*dbg_root;
+	struct bng_re_stats		stats_ctx;
 };
 
 #endif
drivers/infiniband/hw/bng_re/bng_res.c +27 -0
index cb42c0fd2cdf..c50823758b53 100644
@@ -9,6 +9,33 @@
 #include "bng_res.h"
 #include "roce_hsi.h"
 
+/* Stats */
+void bng_re_free_stats_ctx_mem(struct pci_dev *pdev,
+			       struct bng_re_stats *stats)
+{
+	if (stats->dma) {
+		dma_free_coherent(&pdev->dev, stats->size,
+				  stats->dma, stats->dma_map);
+	}
+	memset(stats, 0, sizeof(*stats));
+	stats->fw_id = -1;
+}
+
+int bng_re_alloc_stats_ctx_mem(struct pci_dev *pdev,
+			       struct bng_re_chip_ctx *cctx,
+			       struct bng_re_stats *stats)
+{
+	memset(stats, 0, sizeof(*stats));
+	stats->fw_id = -1;
+	stats->size = cctx->hw_stats_size;
+	stats->dma = dma_alloc_coherent(&pdev->dev, stats->size,
+					&stats->dma_map, GFP_KERNEL);
+	if (!stats->dma)
+		return -ENOMEM;
+
+	return 0;
+}
+
 static void bng_free_pbl(struct bng_re_res  *res, struct bng_re_pbl *pbl)
 {
 	struct pci_dev *pdev = res->pdev;
drivers/infiniband/hw/bng_re/bng_res.h +14 -0
index 7315db347aa6..9997f86d6a0e 100644
@@ -125,6 +125,13 @@ struct bng_re_hwq {
 	u16				qe_ppg;
 };
 
+struct bng_re_stats {
+	dma_addr_t			dma_map;
+	void				*dma;
+	u32				size;
+	u32				fw_id;
+};
+
 struct bng_re_res {
 	struct pci_dev			*pdev;
 	struct bng_re_chip_ctx		*cctx;
@@ -198,4 +205,11 @@ void bng_re_free_hwq(struct bng_re_res *res,
 
 int bng_re_alloc_init_hwq(struct bng_re_hwq *hwq,
 			  struct bng_re_hwq_attr *hwq_attr);
+
+void bng_re_free_stats_ctx_mem(struct pci_dev *pdev,
+			       struct bng_re_stats *stats);
+
+int bng_re_alloc_stats_ctx_mem(struct pci_dev *pdev,
+			       struct bng_re_chip_ctx *cctx,
+			       struct bng_re_stats *stats);
 #endif
Signature · 1 line
2.43.0