Skip to contentSkip to conversation

fwctl/bnxt_fwctl: fwctl for Broadcom Netxtreme devices

PATCH Superseded Pavan Chebbi 5 participants 28 messages Jan 29 – Feb 17

Subsystems (7)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Pavan Chebbi

author maintainer
#0 lore raw

v3 cover fwctl/bnxt_fwctl: fwctl for Broadcom Netxtreme devices

Introducing bnxt_fwctl which follows along Jason's work [1]. It is an aux bus driver that enables fwctl for Broadcom NetXtreme 574xx, 575xx and 576xx series chipsets by using bnxt driver's capability to talk to devices' firmware.

The first patch moves the ULP definitions to a common place inside include/linux/bnxt/. The second and third patches refactor and extend the existing bnxt aux bus functions to be able to add more than one auxiliary device. The last three patches create an additional bnxt aux device, add bnxt_fwctl, and the documentation.

v3: Addressed Leon's comment on patch#2 to have the lock cover entire lifespan of the auxdevice, so that it is 100pc synchronized with auxdev removing.

v2: Addressed Leon's comments as below:
Patch #2: Converted atomic_t based aux device state handling to lock based functions. Drop passing 'err' to bnxt_ulp_start() Patch #4: Zero-initialized the fw rpc variable making unwind safer

v1: Based on the feedback received on v5 here:
https://lore.kernel.org/netdev/[email protected]/ , posting this series to fwctl tree.
This series has the below changes from v5 that was posted to netdev:
Patch #2: Addressed Leon's comment for defensive prograaming style
for aux dev functions
Patch #4: Removed support for commands that don't comply with fwctl guidelines. Also addressed additional comments from Jonathan
Patch #5: Added info for example python3 program

v5: Addressed the v4's review comments as below:
Patch #2 and #3: Simplified aux bus device creation logic by having the core maintain arrays of pointers to aux devices and their contexts, thereby avoiding function calls from aux dev. [thanks Leon]
Patch #4: Used memdup_user() as suggested by cocci. Addressed additional review comments from Jonathon and Dave. Collected Rb tags from Dave.

v4: In patch #4, added the missing kfree on error for response buffer. Improved documentation in patch #5 based on comments from Dave.

v3: Addressed the review comments as below
Patch #1: Removed redundant common.h [thanks Saeed] Patch #2 and #3 merged into a single patch [thanks Jonathan] Patch #3: Addressed comments from Jonathan
Patch #4 and #5: Addressed comments from Jonathan and Dave

v2: In patch #5, fixed a sparse warning where a __le16 was degraded to an integer. Also addressed kdoc warnings for include/uapi/fwctl/bnxt.h in the same patch.

[1] https://lore.kernel.org/netdev/[email protected]/

The following are changes since commit 8dfce8991b95d8625d0a1d2896e42f93b9d7f68d:
Merge tag 'pinctrl-v6.19-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl
and are available in the git repository at:
https://github.com/pavanchebbi/linux/tree/fwctl-bnxt-v3

Pavan Chebbi (5):
fwctl/bnxt_en: Move common definitions to include/linux/bnxt/ fwctl/bnxt_en: Refactor aux bus functions to be more generic fwctl/bnxt_en: Create an aux device for fwctl fwctl/bnxt_fwctl: Add bnxt fwctl device fwctl/bnxt_fwctl: Add documentation entries

 .../userspace-api/fwctl/bnxt_fwctl.rst        |  83 ++++
 Documentation/userspace-api/fwctl/fwctl.rst   |   1 +
 Documentation/userspace-api/fwctl/index.rst   |   1 +
 MAINTAINERS                                   |   6 +
 drivers/fwctl/Kconfig                         |  11 +
 drivers/fwctl/Makefile                        |   1 +
 drivers/fwctl/bnxt/Makefile                   |   4 +
 drivers/fwctl/bnxt/main.c                     | 416 ++++++++++++++++++
 drivers/infiniband/hw/bnxt_re/debugfs.c       |   2 +-
 drivers/infiniband/hw/bnxt_re/main.c          |   2 +-
 drivers/infiniband/hw/bnxt_re/qplib_fp.c      |   2 +-
 drivers/infiniband/hw/bnxt_re/qplib_res.h     |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  49 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  19 +-
 .../net/ethernet/broadcom/bnxt/bnxt_devlink.c |  10 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |   4 +-
 .../net/ethernet/broadcom/bnxt/bnxt_sriov.c   |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 349 +++++++++------
 .../bnxt_ulp.h => include/linux/bnxt/ulp.h    |  26 +-
 include/uapi/fwctl/bnxt.h                     |  64 +++
 include/uapi/fwctl/fwctl.h                    |   1 +
 21 files changed, 879 insertions(+), 176 deletions(-)
 create mode 100644 Documentation/userspace-api/fwctl/bnxt_fwctl.rst
 create mode 100644 drivers/fwctl/bnxt/Makefile
 create mode 100644 drivers/fwctl/bnxt/main.c
 rename drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h => include/linux/bnxt/ulp.h (86%)
 create mode 100644 include/uapi/fwctl/bnxt.h
Signature · 1 line
2.39.1
author maintainer
#1 lore raw

PATCH v3 1/5 fwctl/bnxt_en: Move common definitions to include/linux/bnxt/

We have common definitions that are now going to be used by more than one component outside of bnxt (bnxt_re and fwctl)

Move bnxt_ulp.h to include/linux/bnxt/ as ulp.h.

---
 drivers/infiniband/hw/bnxt_re/debugfs.c                         | 2 +-
 drivers/infiniband/hw/bnxt_re/main.c                            | 2 +-
 drivers/infiniband/hw/bnxt_re/qplib_fp.c                        | 2 +-
 drivers/infiniband/hw/bnxt_re/qplib_res.h                       | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c                       | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c               | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c               | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c                 | 2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c                   | 2 +-
 .../broadcom/bnxt/bnxt_ulp.h => include/linux/bnxt/ulp.h        | 0
 10 files changed, 9 insertions(+), 9 deletions(-)
 rename drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h => include/linux/bnxt/ulp.h (100%)
drivers/infiniband/hw/bnxt_re/debugfs.c +1 -1
index 88817c86ae24..c57bbe3492a8 100644
@@ -10,8 +10,8 @@
 #include <linux/pci.h>
 #include <linux/seq_file.h>
 #include <rdma/ib_addr.h>
+#include <linux/bnxt/ulp.h>
 
-#include "bnxt_ulp.h"
 #include "roce_hsi.h"
 #include "qplib_res.h"
 #include "qplib_sp.h"
drivers/infiniband/hw/bnxt_re/main.c +1 -1
index 73003ad25ee8..79ca734a1377 100644
@@ -55,8 +55,8 @@
 #include <rdma/ib_umem.h>
 #include <rdma/ib_addr.h>
 #include <linux/hashtable.h>
+#include <linux/bnxt/ulp.h>
 
-#include "bnxt_ulp.h"
 #include "roce_hsi.h"
 #include "qplib_res.h"
 #include "qplib_sp.h"
drivers/infiniband/hw/bnxt_re/qplib_fp.c +1 -1
index c88f049136fc..5a28946e4668 100644
@@ -46,6 +46,7 @@
 #include <linux/delay.h>
 #include <linux/prefetch.h>
 #include <linux/if_ether.h>
+#include <linux/bnxt/ulp.h>
 #include <rdma/ib_mad.h>
 
 #include "roce_hsi.h"
@@ -55,7 +56,6 @@
 #include "qplib_sp.h"
 #include "qplib_fp.h"
 #include <rdma/ib_addr.h>
-#include "bnxt_ulp.h"
 #include "bnxt_re.h"
 #include "ib_verbs.h"
 
drivers/infiniband/hw/bnxt_re/qplib_res.h +1 -1
index 2ea3b7f232a3..ebe8893937f6 100644
@@ -39,7 +39,7 @@
 #ifndef __BNXT_QPLIB_RES_H__
 #define __BNXT_QPLIB_RES_H__
 
-#include "bnxt_ulp.h"
+#include <linux/bnxt/ulp.h>
 
 extern const struct bnxt_qplib_gid bnxt_qplib_gid_zero;
 
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
index d17d0ea89c36..4481d80cdfc2 100644
@@ -59,10 +59,10 @@
 #include <net/netdev_rx_queue.h>
 #include <linux/pci-tph.h>
 #include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
 
 #include "bnxt.h"
 #include "bnxt_hwrm.h"
-#include "bnxt_ulp.h"
 #include "bnxt_sriov.h"
 #include "bnxt_ethtool.h"
 #include "bnxt_dcb.h"
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +1 -1
index 15de802bbac4..230cd95d30a2 100644
@@ -13,12 +13,12 @@
 #include <net/devlink.h>
 #include <net/netdev_lock.h>
 #include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
 #include "bnxt.h"
 #include "bnxt_hwrm.h"
 #include "bnxt_vfr.h"
 #include "bnxt_devlink.h"
 #include "bnxt_ethtool.h"
-#include "bnxt_ulp.h"
 #include "bnxt_ptp.h"
 #include "bnxt_coredump.h"
 #include "bnxt_nvm_defs.h"
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -1
index 068e191ede19..8cad7b982664 100644
@@ -27,9 +27,9 @@
 #include <net/netdev_queues.h>
 #include <net/netlink.h>
 #include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
 #include "bnxt.h"
 #include "bnxt_hwrm.h"
-#include "bnxt_ulp.h"
 #include "bnxt_xdp.h"
 #include "bnxt_ptp.h"
 #include "bnxt_ethtool.h"
drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c +1 -1
index be7deb9cc410..83884af32249 100644
@@ -17,9 +17,9 @@
 #include <linux/etherdevice.h>
 #include <net/dcbnl.h>
 #include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
 #include "bnxt.h"
 #include "bnxt_hwrm.h"
-#include "bnxt_ulp.h"
 #include "bnxt_sriov.h"
 #include "bnxt_vfr.h"
 #include "bnxt_ethtool.h"
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -1
index 927971c362f1..fa513892db50 100644
@@ -22,10 +22,10 @@
 #include <linux/auxiliary_bus.h>
 #include <net/netdev_lock.h>
 #include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
 
 #include "bnxt.h"
 #include "bnxt_hwrm.h"
-#include "bnxt_ulp.h"
 
 static DEFINE_IDA(bnxt_aux_dev_ids);
 
include/linux/bnxt/ulp.h renamed from drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h +0 -0
similarity index 100%
rename from drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h
rename to include/linux/bnxt/ulp.h
Signature · 1 line
2.39.1
author maintainer
#2 lore raw

PATCH v3 2/5 fwctl/bnxt_en: Refactor aux bus functions to be more generic

In reply to Pavan Chebbi

Up until now there was only one auxiliary device that bnxt created and that was for RoCE driver. bnxt fwctl is also going to use an aux bus device that bnxt should create. This requires some nomenclature changes and refactoring of the existing bnxt aux dev functions.

Convert 'aux_priv' and 'edev' members of struct bnxt into arrays where each element contains supported auxbus device's data. Move struct bnxt_aux_priv from bnxt.h to ulp.h because that is where it belongs. Make aux bus init/uninit/add/del functions more generic which will loop through all the aux device types. Make bnxt_ulp_start/stop functions (the only other common functions applicable to any aux device) loop through the aux devices to update their config and states. Make callers of bnxt_ulp_start() call it only when there are no errors.

Also, as an improvement in code, bnxt_register_dev() can skip unnecessary dereferencing of edev from bp, instead use the edev pointer from the function parameter.

Future patches will reuse these functions to add an aux bus device for fwctl.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  47 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  19 +-
 .../net/ethernet/broadcom/bnxt/bnxt_devlink.c |   8 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 339 +++++++++++-------
 include/linux/bnxt/ulp.h                      |  25 +-
 6 files changed, 273 insertions(+), 167 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +28 -19
index 4481d80cdfc2..a9bfbfabf121 100644
@@ -6859,7 +6859,8 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 #endif
 	if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
 		req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
-	if (vnic->vnic_id == BNXT_VNIC_DEFAULT && bnxt_ulp_registered(bp->edev))
+	if (vnic->vnic_id == BNXT_VNIC_DEFAULT &&
+	    bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA]))
 		req->flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
 
 	return hwrm_req_send(bp, req);
@@ -7974,6 +7975,7 @@ static int bnxt_get_avail_msix(struct bnxt *bp, int num);
 
 static int __bnxt_reserve_rings(struct bnxt *bp)
 {
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	struct bnxt_hw_rings hwr = {0};
 	int rx_rings, old_rx_rings, rc;
 	int cp = bp->cp_nr_rings;
@@ -7984,7 +7986,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	if (!bnxt_need_reserve_rings(bp))
 		return 0;
 
-	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
+	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
 		ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
 		if (!ulp_msix)
 			bnxt_set_ulp_stat_ctxs(bp, 0);
@@ -8035,8 +8037,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	}
 	rx_rings = min_t(int, rx_rings, hwr.grp);
 	hwr.cp = min_t(int, hwr.cp, bp->cp_nr_rings);
-	if (bnxt_ulp_registered(bp->edev) &&
-	    hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
+	if (bnxt_ulp_registered(edev) && hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
 		hwr.stat -= bnxt_get_ulp_stat_ctxs(bp);
 	hwr.cp = min_t(int, hwr.cp, hwr.stat);
 	rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh);
@@ -8075,7 +8076,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	    !netif_is_rxfh_configured(bp->dev))
 		bnxt_set_dflt_rss_indir_tbl(bp, NULL);
 
-	if (!bnxt_ulp_registered(bp->edev) && BNXT_NEW_RM(bp)) {
+	if (!bnxt_ulp_registered(edev) && BNXT_NEW_RM(bp)) {
 		int resv_msix, resv_ctx, ulp_ctxs;
 		struct bnxt_hw_resc *hw_resc;
 
@@ -11430,6 +11431,7 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
 
 int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 {
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	bool irq_cleared = false;
 	bool irq_change = false;
 	int tcs = bp->num_tc;
@@ -11439,7 +11441,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 	if (!bnxt_need_reserve_rings(bp))
 		return 0;
 
-	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
+	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
 		int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
 
 		if (ulp_msix > bp->ulp_num_msix_want)
@@ -14522,7 +14524,7 @@ static void bnxt_fw_echo_reply(struct bnxt *bp)
 static void bnxt_ulp_restart(struct bnxt *bp)
 {
 	bnxt_ulp_stop(bp);
-	bnxt_ulp_start(bp, 0);
+	bnxt_ulp_start(bp);
 }
 
 static void bnxt_sp_task(struct work_struct *work)
@@ -14679,7 +14681,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
 		hwr.cp_p5 = hwr.tx + rx;
 	rc = bnxt_hwrm_check_rings(bp, &hwr);
 	if (!rc && pci_msix_can_alloc_dyn(bp->pdev)) {
-		if (!bnxt_ulp_registered(bp->edev)) {
+		if (!bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
 			hwr.cp += bnxt_get_ulp_msix_num(bp);
 			hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp));
 		}
@@ -15199,7 +15201,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)
 			bnxt_dl_health_fw_status_update(bp, true);
 		}
 		netdev_unlock(bp->dev);
-		bnxt_ulp_start(bp, 0);
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
 		netdev_lock(bp->dev);
 		bnxt_vf_reps_alloc(bp);
@@ -15221,7 +15223,8 @@ static void bnxt_fw_reset_task(struct work_struct *work)
 	bnxt_fw_reset_abort(bp, rc);
 	netdev_unlock(bp->dev);
 ulp_start:
-	bnxt_ulp_start(bp, rc);
+	if (!rc)
+		bnxt_ulp_start(bp);
 }
 
 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
@@ -16211,12 +16214,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)
 	if (BNXT_PF(bp))
 		__bnxt_sriov_disable(bp);
 
-	bnxt_rdma_aux_device_del(bp);
+	bnxt_aux_devices_del(bp);
 
 	unregister_netdev(dev);
 	bnxt_ptp_clear(bp);
 
-	bnxt_rdma_aux_device_uninit(bp);
+	bnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);
 
 	bnxt_free_l2_filters(bp, true);
 	bnxt_free_ntp_fltrs(bp, true);
@@ -16802,7 +16806,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	bnxt_set_tpa_flags(bp);
 	bnxt_init_ring_params(bp);
 	bnxt_set_ring_params(bp);
-	bnxt_rdma_aux_device_init(bp);
+	mutex_init(&bp->auxdev_lock);
+	if (!bnxt_auxdev_id_alloc(bp))
+		bnxt_aux_devices_init(bp);
 	rc = bnxt_set_dflt_rings(bp, true);
 	if (rc) {
 		if (BNXT_VF(bp) && rc == -ENODEV) {
@@ -16866,7 +16872,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	bnxt_dl_fw_reporters_create(bp);
 
-	bnxt_rdma_aux_device_add(bp);
+	bnxt_aux_devices_add(bp);
 
 	bnxt_print_device_info(bp);
 
@@ -16874,7 +16880,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;
 init_err_cleanup:
-	bnxt_rdma_aux_device_uninit(bp);
+	bnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);
 	bnxt_dl_unregister(bp);
 init_err_dl:
 	bnxt_shutdown_tc(bp);
@@ -17008,9 +17015,10 @@ static int bnxt_resume(struct device *device)
 
 resume_exit:
 	netdev_unlock(bp->dev);
-	bnxt_ulp_start(bp, rc);
-	if (!rc)
+	if (!rc) {
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
+	}
 	return rc;
 }
 
@@ -17190,9 +17198,10 @@ static void bnxt_io_resume(struct pci_dev *pdev)
 		netif_device_attach(netdev);
 
 	netdev_unlock(netdev);
-	bnxt_ulp_start(bp, err);
-	if (!err)
+	if (!err) {
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
+	}
 }
 
 static const struct pci_error_handlers bnxt_err_handler = {
drivers/net/ethernet/broadcom/bnxt/bnxt.h +10 -9
index f5f07a7e6b29..a739e7d52bdc 100644
@@ -24,12 +24,12 @@
 #include <linux/interrupt.h>
 #include <linux/rhashtable.h>
 #include <linux/crash_dump.h>
-#include <linux/auxiliary_bus.h>
 #include <net/devlink.h>
 #include <net/dst_metadata.h>
 #include <net/xdp.h>
 #include <linux/dim.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/bnxt/ulp.h>
 #ifdef CONFIG_TEE_BNXT_FW
 #include <linux/firmware/broadcom/tee_bnxt_fw.h>
 #endif
@@ -2076,12 +2076,6 @@ struct bnxt_fw_health {
 #define BNXT_FW_IF_RETRY		10
 #define BNXT_FW_SLOT_RESET_RETRY	4
 
-struct bnxt_aux_priv {
-	struct auxiliary_device aux_dev;
-	struct bnxt_en_dev *edev;
-	int id;
-};
-
 enum board_idx {
 	BCM57301,
 	BCM57302,
@@ -2341,8 +2335,8 @@ struct bnxt {
 #define BNXT_CHIP_P5_AND_MINUS(bp)		\
 	(BNXT_CHIP_P3(bp) || BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp))
 
-	struct bnxt_aux_priv	*aux_priv;
-	struct bnxt_en_dev	*edev;
+	struct bnxt_aux_priv	*aux_priv[__BNXT_AUXDEV_MAX];
+	struct bnxt_en_dev	*edev[__BNXT_AUXDEV_MAX];
 
 	struct bnxt_napi	**bnapi;
 
@@ -2751,6 +2745,13 @@ struct bnxt {
 	struct bnxt_ctx_pg_info	*fw_crash_mem;
 	u32			fw_crash_len;
 	struct bnxt_bs_trace_info bs_trace[BNXT_TRACE_MAX];
+	int			auxdev_id;
+	/* synchronize validity checks of available aux devices */
+	struct mutex		auxdev_lock;
+	u8			auxdev_state[__BNXT_AUXDEV_MAX];
+#define	BNXT_ADEV_STATE_NONE	0
+#define	BNXT_ADEV_STATE_INIT	1
+#define	BNXT_ADEV_STATE_ADD	2
 };
 
 #define BNXT_NUM_RX_RING_STATS			8
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -4
index 230cd95d30a2..835f2b413931 100644
@@ -440,13 +440,13 @@ static int bnxt_dl_reload_down(struct devlink *dl, bool netns_change,
 					   "reload is unsupported while VFs are allocated or being configured");
 			netdev_unlock(bp->dev);
 			rtnl_unlock();
-			bnxt_ulp_start(bp, 0);
+			bnxt_ulp_start(bp);
 			return -EOPNOTSUPP;
 		}
 		if (bp->dev->reg_state == NETREG_UNREGISTERED) {
 			netdev_unlock(bp->dev);
 			rtnl_unlock();
-			bnxt_ulp_start(bp, 0);
+			bnxt_ulp_start(bp);
 			return -ENODEV;
 		}
 		if (netif_running(bp->dev))
@@ -578,8 +578,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
 	}
 	netdev_unlock(bp->dev);
 	rtnl_unlock();
-	if (action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
-		bnxt_ulp_start(bp, rc);
+	if (!rc && action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
+		bnxt_ulp_start(bp);
 	return rc;
 }
 
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -1
index 8cad7b982664..064d7bc4ce8d 100644
@@ -5100,7 +5100,7 @@ static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
 
 	memset(buf, 0, sizeof(u64) * bp->num_tests);
 	if (etest->flags & ETH_TEST_FL_OFFLINE &&
-	    bnxt_ulp_registered(bp->edev)) {
+	    bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
 		etest->flags |= ETH_TEST_FL_FAILED;
 		netdev_warn(dev, "Offline tests cannot be run with RoCE driver loaded\n");
 		return;
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +210 -129

499 lines not on this page · raw message

include/linux/bnxt/ulp.h +20 -5
index 3c5b8a53f715..1a4643c46f86 100644
@@ -10,6 +10,8 @@
 #ifndef BNXT_ULP_H
 #define BNXT_ULP_H
 
+#include <linux/auxiliary_bus.h>
+
 #define BNXT_MIN_ROCE_CP_RINGS	2
 #define BNXT_MIN_ROCE_STAT_CTXS	1
 
@@ -20,6 +22,17 @@
 struct hwrm_async_event_cmpl;
 struct bnxt;
 
+enum bnxt_auxdev_type {
+	BNXT_AUXDEV_RDMA = 0,
+	__BNXT_AUXDEV_MAX
+};
+
+struct bnxt_aux_priv {
+	struct auxiliary_device aux_dev;
+	struct bnxt_en_dev *edev;
+	int id;
+};
+
 struct bnxt_msix_entry {
 	u32	vector;
 	u32	ring_idx;
@@ -110,19 +123,21 @@ void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ctxs);
 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp);
 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp);
 void bnxt_ulp_stop(struct bnxt *bp);
-void bnxt_ulp_start(struct bnxt *bp, int err);
+void bnxt_ulp_start(struct bnxt *bp);
 void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
 void bnxt_ulp_irq_stop(struct bnxt *bp);
 void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
-void bnxt_rdma_aux_device_uninit(struct bnxt *bp);
-void bnxt_rdma_aux_device_del(struct bnxt *bp);
-void bnxt_rdma_aux_device_add(struct bnxt *bp);
-void bnxt_rdma_aux_device_init(struct bnxt *bp);
+void bnxt_aux_devices_uninit(struct bnxt *bp);
+void bnxt_aux_devices_del(struct bnxt *bp);
+void bnxt_aux_devices_add(struct bnxt *bp);
+void bnxt_aux_devices_init(struct bnxt *bp);
 int bnxt_register_dev(struct bnxt_en_dev *edev, struct bnxt_ulp_ops *ulp_ops,
 		      void *handle);
 void bnxt_unregister_dev(struct bnxt_en_dev *edev);
 int bnxt_send_msg(struct bnxt_en_dev *edev, struct bnxt_fw_msg *fw_msg);
 void bnxt_register_async_events(struct bnxt_en_dev *edev,
 				unsigned long *events_bmap, u16 max_id);
+int bnxt_auxdev_id_alloc(struct bnxt *bp);
+void bnxt_auxdev_id_free(struct bnxt *bp, int id);
 #endif
Signature · 1 line
2.39.1
#3 lore raw

Re: [PATCH v3 fwctl 2/5] fwctl/bnxt_en: Refactor aux bus functions to be more generic

Quoted 5 lines · On Thu, 29 Jan 2026 07:54:50 -0800 Pavan Chebbi <[email protected]>…

Up until now there was only one auxiliary device that bnxt created and that was for RoCE driver. bnxt fwctl is also going to use an aux bus device that bnxt should create. This requires some nomenclature changes and refactoring of the existing bnxt aux dev functions.

Minor thing but why wrap to 60 ish chars? Convention for much of the kernel is 75 (to give a bit of room for git tools deciding to indent it a little).

Quoted 16 lines

Convert 'aux_priv' and 'edev' members of struct bnxt into arrays where each element contains supported auxbus device's data. Move struct bnxt_aux_priv from bnxt.h to ulp.h because that is where it belongs. Make aux bus init/uninit/add/del functions more generic which will loop through all the aux device types. Make bnxt_ulp_start/stop functions (the only other common functions applicable to any aux device) loop through the aux devices to update their config and states. Make callers of bnxt_ulp_start() call it only when there are no errors.

Also, as an improvement in code, bnxt_register_dev() can skip unnecessary dereferencing of edev from bp, instead use the edev pointer from the function parameter.

Quoted 5 lines

Future patches will reuse these functions to add an aux bus device for fwctl.

Hi Pavan,

Various comments inline. Please also make sure to run a few static analysis tools over the code. There seems to be a use after free that is pretty obvious in here, so I'd expect that to be picked up. That stuff is easier for tooling that humans!

Jonathan

Quoted 18 lines
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  47 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  19 +-
 .../net/ethernet/broadcom/bnxt/bnxt_devlink.c |   8 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 339 +++++++++++-------
 include/linux/bnxt/ulp.h                      |  25 +-
 6 files changed, 273 insertions(+), 167 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index 4481d80cdfc2..a9bfbfabf121 100644
 
 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
@@ -16211,12 +16214,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)
 	if (BNXT_PF(bp))
 		__bnxt_sriov_disable(bp);

drivers/net/ethernet/broadcom/bnxt/bnxt.c static void bnxt_remove_one(struct pci_dev *pdev) · line 16223

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -2
 
-	bnxt_rdma_aux_device_del(bp);
+	bnxt_aux_devices_del(bp);
 
 	unregister_netdev(dev);
 	bnxt_ptp_clear(bp);
 
-	bnxt_rdma_aux_device_uninit(bp);
+	bnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);

I'm not following why there is a mix of devices and single device ID freeing going on here.
If we have a set of devices, how come there is only one of those ids?

Maybe it's just a naming thing and auxdev_id is only meant to be used for this one auxdev that is already in the driver?

Quoted 64 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +12 -7
 	bnxt_free_l2_filters(bp, true);
 	bnxt_free_ntp_fltrs(bp, true);
@@ -16802,7 +16806,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	bnxt_set_tpa_flags(bp);
 	bnxt_init_ring_params(bp);
 	bnxt_set_ring_params(bp);
-	bnxt_rdma_aux_device_init(bp);
+	mutex_init(&bp->auxdev_lock);
+	if (!bnxt_auxdev_id_alloc(bp))
+		bnxt_aux_devices_init(bp);
 	rc = bnxt_set_dflt_rings(bp, true);
 	if (rc) {
 		if (BNXT_VF(bp) && rc == -ENODEV) {
@@ -16866,7 +16872,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	bnxt_dl_fw_reporters_create(bp);
 
-	bnxt_rdma_aux_device_add(bp);
+	bnxt_aux_devices_add(bp);
 
 	bnxt_print_device_info(bp);
 
@@ -16874,7 +16880,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;
 init_err_cleanup:
-	bnxt_rdma_aux_device_uninit(bp);
+	bbnxt_aux_devices_uninitnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);
 	bnxt_dl_unregister(bp);
 init_err_dl:
 	bnxt_shutdown_tc(bp);
@@ -17008,9 +17015,10 @@ static int bnxt_resume(struct device *device)
 
 resume_exit:
 	netdev_unlock(bp->dev);
-	bnxt_ulp_start(bp, rc);
-	if (!rc)
+	if (!rc) {
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
+	}
 	return rc;
 }
 
@@ -17190,9 +17198,10 @@ static void bnxt_io_resume(struct pci_dev *pdev)
 		netif_device_attach(netdev);
 
 	netdev_unlock(netdev);
-	bnxt_ulp_start(bp, err);
-	if (!err)
+	if (!err) {
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
+	}
 }
 
 static const struct pci_error_handlers bnxt_err_handler = {
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +0 -0
index fa513892db50..3097fc5755e6 100644

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c line 51

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -0
 
+
+static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{

const? If not I'd be concerned that this will break badly if there are multiple devices.

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c EXPORT_SYMBOL(bnxt_send_msg); · line 267

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -2
+	.name		= "rdma",
+}};
@@ -227,20 +264,27 @@ EXPORT_SYMBOL(bnxt_send_msg);
 
 void bnxt_ulp_stop(struct bnxt *bp)
 {
-	struct bnxt_aux_priv *aux_priv = bp->aux_priv;
-	struct bnxt_en_dev *edev = bp->edev;
+	int i;

Similar to later comment, could move that into the loop init. (assuming not some local netdev thing about not doing that?)

Quoted 13 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -10
-	if (!edev)
-		return;
-
-	mutex_lock(&edev->en_dev_lock);
-	if (!bnxt_ulp_registered(edev) ||
-	    (edev->flags & BNXT_EN_FLAG_ULP_STOPPED))
-		goto ulp_stop_exit;
-
-	edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
-	if (aux_priv) {
+	mutex_lock(&bp->auxdev_lock);
+	for (i = 0; i < __BNXT_AUXDEV_MAX; i++) {

...

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_aux_dev_release(struct device *dev) · line 469

Quoted 13 lines

static void bnxt_aux_dev_release(struct device *dev)

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -3
@@ -408,20 +462,25 @@ static void bnxt_aux_dev_release(struct device *dev)
 		container_of(dev, struct bnxt_aux_priv, aux_dev.dev);
 	struct bnxt *bp = netdev_priv(aux_priv->edev->net);
 
-	ida_free(&bnxt_aux_dev_ids, aux_priv->id);
 	kfree(aux_priv->edev->ulp_tbl);
-	bp->edev = NULL;
+	bp->edev[aux_priv->id] = NULL;
 	kfree(aux_priv->edev);
 	kfree(aux_priv);
-	bp->aux_priv = NULL;
+	bp->aux_priv[aux_priv->id] = NULL;

UAF of aux_priv.
You'll need a local copy of aux_priv->id.

Quoted 35 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +11 -11
 }
 
-void bnxt_rdma_aux_device_del(struct bnxt *bp)
+void bnxt_aux_devices_del(struct bnxt *bp)
 {
-	if (!bp->edev)
-		return;
+	int idx;
 
-	auxiliary_device_delete(&bp->aux_priv->aux_dev);
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		if (bnxt_auxdev_is_active(bp, idx)) {
+			auxiliary_device_delete(&bp->aux_priv[idx]->aux_dev);
+			bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);
+		}
+	}
+	mutex_unlock(&bp->auxdev_lock);
 }
 
 static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
@@ -451,83 +510,105 @@ static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
 	edev->bar0 = bp->bar0;
 }
 
-void bnxt_rdma_aux_device_add(struct bnxt *bp)
+void bnxt_aux_devices_add(struct bnxt *bp)
 {
 	struct auxiliary_device *aux_dev;
-	int rc;
-
-	if (!bp->edev)
-		return;
-
-	aux_dev = &bp->aux_priv->aux_dev;

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 520

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -5
-	rc = auxiliary_device_add(aux_dev);
-	if (rc) {
-		netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
-		auxiliary_device_uninit(aux_dev);
-		bp->flags &= ~BNXT_FLAG_ROCE_CAP;
+	int rc, idx;
+
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		if (bnxt_auxdev_is_init(bp, idx)) {

I haven't checked later patches, but if you can I'd do

		if (!bnxt_auxdev_is_init(bp, idx))
			continue;

		aux_dev = ..

Just to reduce indent without it making much different otherwise to readability.

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 527

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +7 -0
+			aux_dev = &bp->aux_priv[idx]->aux_dev;
+			rc = auxiliary_device_add(aux_dev);
+			if (rc) {
+				netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
+				auxiliary_device_uninit(aux_dev);
+				if (idx == BNXT_AUXDEV_RDMA)
+					bp->flags &= ~BNXT_FLAG_ROCE_CAP;

Similar to below. I'd like this type specific stuff wrapped up in callbacks or data.

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -0
+				continue;
+			}
+			bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_ADD);
+		}
 	}
+	mutex_unlock(&bp->auxdev_lock);
 }

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 542

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -2
 
-void bnxt_rdma_aux_device_init(struct bnxt *bp)
+void bnxt_aux_devices_init(struct bnxt *bp)
 {
 	struct auxiliary_device *aux_dev;
 	struct bnxt_aux_priv *aux_priv;
 	struct bnxt_en_dev *edev;
 	struct bnxt_ulp *ulp;
-	int rc;
+	int rc, idx;

I'm not certain for net, but for most of the kernel it's now acceptable to do

	for (int idx = 0; ...

to limit the scope of idx.

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c void bnxt_register_async_events(struct bnxt_en_dev *edev, · line 449

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -0
+
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {

It might be worth considering a precursor patch to factor out a bnxt_aux_devices_init_one()
that would be a no operation changes patch, then do this on top. Would make things a lot easier to follow than this diff.

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 550

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -0
+		bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_NONE);
+
+		if (idx == BNXT_AUXDEV_RDMA &&
+		    !(bp->flags & BNXT_FLAG_ROCE_CAP))
+			continue;

I'd find the code easier to read if the few bits of device specific stuff are via callbacks or even better data in struct bnxt_aux_device. Having a mix of stuff that is in there and checks against specific IDs in the code just tends to end up messy if more devices get added over time.

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 560

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +10 -0
+
+		aux_priv = kzalloc(sizeof(*aux_priv), GFP_KERNEL);
+		if (!aux_priv)
+			goto next_auxdev;
+
+		aux_dev = &aux_priv->aux_dev;
+		aux_dev->id = bp->auxdev_id;
+		aux_dev->name = bnxt_aux_devices[idx].name;
+		aux_dev->dev.parent = &bp->pdev->dev;
+		aux_dev->dev.release = bnxt_aux_dev_release;
		Could skip the zeroing at allocation in favor of the follow.
		For me this is easier to read but that's just personal preference
		so up to you.

		
		aux_priv = (struct bnxt_aux_priv) {
			.aux_dev = {
				.id = bp->auxdev_id,
				.name = bnxt_aux_devices[idx].name,
				.dev = {
					.parent = &bp->pdev->dev,
					.release = bnxt_aux_dev_release,
				},
			},
		};
Quoted 33 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +18 -12
+
+		rc = auxiliary_device_init(aux_dev);
+		if (rc) {
+			kfree(aux_priv);
+			goto next_auxdev;
+		}
+		bp->aux_priv[idx] = aux_priv;
 
-	if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
-		return;
+		/* From this point, all cleanup will happen via the .release
+		 * callback & any error unwinding will need to include a call
+		 * to auxiliary_device_uninit.
+		 */
+		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+		if (!edev)
+			goto aux_dev_uninit;
 
-	aux_priv = kzalloc(sizeof(*bp->aux_priv), GFP_KERNEL);
-	if (!aux_priv)
-		goto exit;
+		aux_priv->edev = edev;
+		bnxt_set_edev_info(edev, bp);
 
-	aux_priv->id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL);
-	if (aux_priv->id < 0) {
-		netdev_warn(bp->dev,
-			    "ida alloc failed for ROCE auxiliary device\n");
-		kfree(aux_priv);
-		goto exit;
-	}
+		ulp = kzalloc(sizeof(*ulp), GFP_KERNEL);
+		if (!ulp)

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 586

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +4 -5
+			goto aux_dev_uninit;
 
-	aux_dev = &aux_priv->aux_dev;
-	aux_dev->id = aux_priv->id;
-	aux_dev->name = "rdma";
-	aux_dev->dev.parent = &bp->pdev->dev;
-	aux_dev->dev.release = bnxt_aux_dev_release;
+		edev->ulp_tbl = ulp;
+		bp->edev[idx] = edev;
+		if (idx == BNXT_AUXDEV_RDMA)

Another thing I'd like to see as a callback registered in the per auxdev type data alongside the name etc.

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -1
+			bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp);
+		aux_priv->id = idx;
+		bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);
 
-	rc = auxiliary_device_init(aux_dev);

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp) · line 596

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +6 -4
-	if (rc) {
-		ida_free(&bnxt_aux_dev_ids, aux_priv->id);
-		kfree(aux_priv);
-		goto exit;
+		continue;
+aux_dev_uninit:
+		auxiliary_device_uninit(aux_dev);
+next_auxdev:
+		if (idx == BNXT_AUXDEV_RDMA)
+			bp->flags &= ~BNXT_FLAG_ROCE_CAP;

Similar to above, I'd prefer this to be either data or a callback that is specific to the idx.

Quoted 23 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -19
 	}
-	bp->aux_priv = aux_priv;
-
-	/* From this point, all cleanup will happen via the .release callback &
-	 * any error unwinding will need to include a call to
-	 * auxiliary_device_uninit.
-	 */
-	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
-	if (!edev)
-		goto aux_dev_uninit;
-
-	aux_priv->edev = edev;
-
-	ulp = kzalloc(sizeof(*ulp), GFP_KERNEL);
-	if (!ulp)
-		goto aux_dev_uninit;
+	mutex_unlock(&bp->auxdev_lock);
+}
 
-	edev->ulp_tbl = ulp;
-	bp->edev = edev;
-	bnxt_set_edev_info(edev, bp);
-	bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp);
author maintainer
#4 lore raw

Re: [PATCH v3 fwctl 2/5] fwctl/bnxt_en: Refactor aux bus functions to be more generic

Quoted 6 lines

Hi Pavan,

Various comments inline. Please also make sure to run a few static analysis tools over the code. There seems to be a use after free that is pretty obvious in here, so I'd expect that to be picked up. That stuff is easier for tooling that humans!

Ok, I will respin for the UAF. I value your other comments, and I have addressed them all until this patch. Because the new ones are not code defects I am going to hold them off for a later time.
It seems like this auxdevice infra (which is not authored by me) can be improved and simplified. I will plan to do that.
I have tried to improve it as best as I can to accommodate fwctl which is the primary goal of the series.

maintainer
#5 lore raw

Re: [PATCH v3 fwctl 2/5] fwctl/bnxt_en: Refactor aux bus functions to be more generic

In reply to Pavan Chebbi
Quoted 643 lines · Pavan Chebbi

Up until now there was only one auxiliary device that bnxt created and that was for RoCE driver. bnxt fwctl is also going to use an aux bus device that bnxt should create. This requires some nomenclature changes and refactoring of the existing bnxt aux dev functions.

Convert 'aux_priv' and 'edev' members of struct bnxt into arrays where each element contains supported auxbus device's data. Move struct bnxt_aux_priv from bnxt.h to ulp.h because that is where it belongs. Make aux bus init/uninit/add/del functions more generic which will loop through all the aux device types. Make bnxt_ulp_start/stop functions (the only other common functions applicable to any aux device) loop through the aux devices to update their config and states. Make callers of bnxt_ulp_start() call it only when there are no errors.

Also, as an improvement in code, bnxt_register_dev() can skip unnecessary dereferencing of edev from bp, instead use the edev pointer from the function parameter.

Future patches will reuse these functions to add an aux bus device for fwctl.

---

drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  47 ++-
drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  19 +-
.../net/ethernet/broadcom/bnxt/bnxt_devlink.c |   8 +-
.../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |   2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 339 +++++++++++-------
include/linux/bnxt/ulp.h                      |  25 +-
6 files changed, 273 insertions(+), 167 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +11 -9
index 4481d80cdfc2..a9bfbfabf121 100644
@@ -6859,7 +6859,8 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 #endif
 	if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
 		req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
-	if (vnic->vnic_id == BNXT_VNIC_DEFAULT && bnxt_ulp_registered(bp->edev))
+	if (vnic->vnic_id == BNXT_VNIC_DEFAULT &&
+	    bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA]))
 		req->flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
 
 	return hwrm_req_send(bp, req);
@@ -7974,6 +7975,7 @@ static int bnxt_get_avail_msix(struct bnxt *bp, int num);
 
 static int __bnxt_reserve_rings(struct bnxt *bp)
 {
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	struct bnxt_hw_rings hwr = {0};
 	int rx_rings, old_rx_rings, rc;
 	int cp = bp->cp_nr_rings;
@@ -7984,7 +7986,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	if (!bnxt_need_reserve_rings(bp))
 		return 0;
 
-	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
+	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
 		ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
 		if (!ulp_msix)
 			bnxt_set_ulp_stat_ctxs(bp, 0);
@@ -8035,8 +8037,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	}
 	rx_rings = min_t(int, rx_rings, hwr.grp);
 	hwr.cp = min_t(int, hwr.cp, bp->cp_nr_rings);
-	if (bnxt_ulp_registered(bp->edev) &&
-	    hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
+	if (bnxt_ulp_registered(edev) && hwr.stat > bnxt_get_ulp_stat_ctxs(bp))
 		hwr.stat -= bnxt_get_ulp_stat_ctxs(bp);
 	hwr.cp = min_t(int, hwr.cp, hwr.stat);
 	rc = bnxt_trim_rings(bp, &rx_rings, &hwr.tx, hwr.cp, sh);
@@ -8075,7 +8076,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
 	    !netif_is_rxfh_configured(bp->dev))
 		bnxt_set_dflt_rss_indir_tbl(bp, NULL);
 
-	if (!bnxt_ulp_registered(bp->edev) && BNXT_NEW_RM(bp)) {
+	if (!bnxt_ulp_registered(edev) && BNXT_NEW_RM(bp)) {
 		int resv_msix, resv_ctx, ulp_ctxs;
 		struct bnxt_hw_resc *hw_resc;
 
@@ -11430,6 +11431,7 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
 
 int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 {
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	bool irq_cleared = false;
 	bool irq_change = false;
 	int tcs = bp->num_tc;
@@ -11439,7 +11441,7 @@ int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
 	if (!bnxt_need_reserve_rings(bp))
 		return 0;
 
-	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(bp->edev)) {
+	if (BNXT_NEW_RM(bp) && !bnxt_ulp_registered(edev)) {
 		int ulp_msix = bnxt_get_avail_msix(bp, bp->ulp_num_msix_want);
 
 		if (ulp_msix > bp->ulp_num_msix_want)
@@ -14522,7 +14524,7 @@ static void bnxt_fw_echo_reply(struct bnxt *bp)
 static void bnxt_ulp_restart(struct bnxt *bp)
 {
 	bnxt_ulp_stop(bp);
-	bnxt_ulp_start(bp, 0);
+	bnxt_ulp_start(bp);
 }
 
 static void bnxt_sp_task(struct work_struct *work)
@@ -14679,7 +14681,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
 		hwr.cp_p5 = hwr.tx + rx;
 	rc = bnxt_hwrm_check_rings(bp, &hwr);
 	if (!rc && pci_msix_can_alloc_dyn(bp->pdev)) {
-		if (!bnxt_ulp_registered(bp->edev)) {
+		if (!bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
 			hwr.cp += bnxt_get_ulp_msix_num(bp);
 			hwr.cp = min_t(int, hwr.cp, bnxt_get_max_func_irqs(bp));
 		}
@@ -15199,7 +15201,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)
 			bnxt_dl_health_fw_status_update(bp, true);
 		}
 		netdev_unlock(bp->dev);
-		bnxt_ulp_start(bp, 0);
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
 		netdev_lock(bp->dev);
 		bnxt_vf_reps_alloc(bp);
@@ -15221,7 +15223,8 @@ static void bnxt_fw_reset_task(struct work_struct *work)
 	bnxt_fw_reset_abort(bp, rc);
 	netdev_unlock(bp->dev);

ulp_start:

drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
-	bnxt_ulp_start(bp, rc);
+	if (!rc)
+		bnxt_ulp_start(bp);

}

static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)

drivers/net/ethernet/broadcom/bnxt/bnxt.c +7 -4
@@ -16211,12 +16214,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)
 	if (BNXT_PF(bp))
 		__bnxt_sriov_disable(bp);
 
-	bnxt_rdma_aux_device_del(bp);
+	bnxt_aux_devices_del(bp);
 
 	unregister_netdev(dev);
 	bnxt_ptp_clear(bp);
 
-	bnxt_rdma_aux_device_uninit(bp);
+	bnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);
 
 	bnxt_free_l2_filters(bp, true);
 	bnxt_free_ntp_fltrs(bp, true);
@@ -16802,7 +16806,9 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	bnxt_set_tpa_flags(bp);
 	bnxt_init_ring_params(bp);
 	bnxt_set_ring_params(bp);
-	bnxt_rdma_aux_device_init(bp);
+	mutex_init(&bp->auxdev_lock);
+	if (!bnxt_auxdev_id_alloc(bp))
+		bnxt_aux_devices_init(bp);
 	rc = bnxt_set_dflt_rings(bp, true);
 	if (rc) {
 		if (BNXT_VF(bp) && rc == -ENODEV) {
@@ -16866,7 +16872,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	bnxt_dl_fw_reporters_create(bp);
 
-	bnxt_rdma_aux_device_add(bp);
+	bnxt_aux_devices_add(bp);
 
 	bnxt_print_device_info(bp);
 
@@ -16874,7 +16880,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;

init_err_cleanup:

drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
-	bnxt_rdma_aux_device_uninit(bp);
+	bnxt_aux_devices_uninit(bp);
+	bnxt_auxdev_id_free(bp, bp->auxdev_id);
	bnxt_dl_unregister(bp);
init_err_dl:
	bnxt_shutdown_tc(bp);
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
@@ -17008,9 +17015,10 @@ static int bnxt_resume(struct device *device)
 

resume_exit:

	netdev_unlock(bp->dev);
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
-	bnxt_ulp_start(bp, rc);
-	if (!rc)
+	if (!rc) {
+		bnxt_ulp_start(bp);
		bnxt_reenable_sriov(bp);
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
+	}
	return rc;
}
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -2
@@ -17190,9 +17198,10 @@ static void bnxt_io_resume(struct pci_dev *pdev)
 		netif_device_attach(netdev);
 
 	netdev_unlock(netdev);
-	bnxt_ulp_start(bp, err);
-	if (!err)
+	if (!err) {
+		bnxt_ulp_start(bp);
 		bnxt_reenable_sriov(bp);
+	}
 }
 
 static const struct pci_error_handlers bnxt_err_handler = {
drivers/net/ethernet/broadcom/bnxt/bnxt.h +10 -9
index f5f07a7e6b29..a739e7d52bdc 100644
@@ -24,12 +24,12 @@
 #include <linux/interrupt.h>
 #include <linux/rhashtable.h>
 #include <linux/crash_dump.h>
-#include <linux/auxiliary_bus.h>
 #include <net/devlink.h>
 #include <net/dst_metadata.h>
 #include <net/xdp.h>
 #include <linux/dim.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/bnxt/ulp.h>
 #ifdef CONFIG_TEE_BNXT_FW
 #include <linux/firmware/broadcom/tee_bnxt_fw.h>
 #endif
@@ -2076,12 +2076,6 @@ struct bnxt_fw_health {
 #define BNXT_FW_IF_RETRY		10
 #define BNXT_FW_SLOT_RESET_RETRY	4
 
-struct bnxt_aux_priv {
-	struct auxiliary_device aux_dev;
-	struct bnxt_en_dev *edev;
-	int id;
-};
-
 enum board_idx {
 	BCM57301,
 	BCM57302,
@@ -2341,8 +2335,8 @@ struct bnxt {
 #define BNXT_CHIP_P5_AND_MINUS(bp)		\
 	(BNXT_CHIP_P3(bp) || BNXT_CHIP_P4(bp) || BNXT_CHIP_P5(bp))
 
-	struct bnxt_aux_priv	*aux_priv;
-	struct bnxt_en_dev	*edev;
+	struct bnxt_aux_priv	*aux_priv[__BNXT_AUXDEV_MAX];
+	struct bnxt_en_dev	*edev[__BNXT_AUXDEV_MAX];
 
 	struct bnxt_napi	**bnapi;
 
@@ -2751,6 +2745,13 @@ struct bnxt {
 	struct bnxt_ctx_pg_info	*fw_crash_mem;
 	u32			fw_crash_len;
 	struct bnxt_bs_trace_info bs_trace[BNXT_TRACE_MAX];
+	int			auxdev_id;
+	/* synchronize validity checks of available aux devices */
+	struct mutex		auxdev_lock;
+	u8			auxdev_state[__BNXT_AUXDEV_MAX];
+#define	BNXT_ADEV_STATE_NONE	0
+#define	BNXT_ADEV_STATE_INIT	1
+#define	BNXT_ADEV_STATE_ADD	2
 };
 
 #define BNXT_NUM_RX_RING_STATS			8
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +4 -4
index 230cd95d30a2..835f2b413931 100644
@@ -440,13 +440,13 @@ static int bnxt_dl_reload_down(struct devlink *dl, bool netns_change,
 					   "reload is unsupported while VFs are allocated or being configured");
 			netdev_unlock(bp->dev);
 			rtnl_unlock();
-			bnxt_ulp_start(bp, 0);
+			bnxt_ulp_start(bp);
 			return -EOPNOTSUPP;
 		}
 		if (bp->dev->reg_state == NETREG_UNREGISTERED) {
 			netdev_unlock(bp->dev);
 			rtnl_unlock();
-			bnxt_ulp_start(bp, 0);
+			bnxt_ulp_start(bp);
 			return -ENODEV;
 		}
 		if (netif_running(bp->dev))
@@ -578,8 +578,8 @@ static int bnxt_dl_reload_up(struct devlink *dl, enum devlink_reload_action acti
 	}
 	netdev_unlock(bp->dev);
 	rtnl_unlock();
-	if (action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
-		bnxt_ulp_start(bp, rc);
+	if (!rc && action == DEVLINK_RELOAD_ACTION_DRIVER_REINIT)
+		bnxt_ulp_start(bp);
 	return rc;
 }
 
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -1
index 8cad7b982664..064d7bc4ce8d 100644
@@ -5100,7 +5100,7 @@ static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
 
 	memset(buf, 0, sizeof(u64) * bp->num_tests);
 	if (etest->flags & ETH_TEST_FL_OFFLINE &&
-	    bnxt_ulp_registered(bp->edev)) {
+	    bnxt_ulp_registered(bp->edev[BNXT_AUXDEV_RDMA])) {
 		etest->flags |= ETH_TEST_FL_FAILED;
 		netdev_warn(dev, "Offline tests cannot be run with RoCE driver loaded\n");
 		return;
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +55 -18
index fa513892db50..3097fc5755e6 100644
@@ -29,9 +29,32 @@
 
 static DEFINE_IDA(bnxt_aux_dev_ids);
 
+struct bnxt_aux_device {
+	const char *name;
+};
+
+static void bnxt_auxdev_set_state(struct bnxt *bp, int idx, int state)
+{
+	bp->auxdev_state[idx] = state;
+}
+
+static bool bnxt_auxdev_is_init(struct bnxt *bp, int idx)
+{
+	return (bp->auxdev_state[idx] == BNXT_ADEV_STATE_INIT);
+}
+
+static bool bnxt_auxdev_is_active(struct bnxt *bp, int idx)
+{
+	return (bp->auxdev_state[idx] == BNXT_ADEV_STATE_ADD);
+}
+
+static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{
+	.name		= "rdma",
+}};
+
 static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)
 {
-	struct bnxt_en_dev *edev = bp->edev;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	int num_msix, i;
 
 	if (!edev->ulp_tbl->msix_requested) {
@@ -51,61 +74,75 @@ static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)
 
 int bnxt_get_ulp_msix_num(struct bnxt *bp)
 {
-	if (bp->edev)
-		return bp->edev->ulp_num_msix_vec;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (edev)
+		return edev->ulp_num_msix_vec;
 	return 0;
 }
 
 void bnxt_set_ulp_msix_num(struct bnxt *bp, int num)
 {
-	if (bp->edev)
-		bp->edev->ulp_num_msix_vec = num;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (edev)
+		edev->ulp_num_msix_vec = num;
 }
 
 int bnxt_get_ulp_msix_num_in_use(struct bnxt *bp)
 {
-	if (bnxt_ulp_registered(bp->edev))
-		return bp->edev->ulp_num_msix_vec;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (bnxt_ulp_registered(edev))
+		return edev->ulp_num_msix_vec;
 	return 0;
 }
 
 int bnxt_get_ulp_stat_ctxs(struct bnxt *bp)
 {
-	if (bp->edev)
-		return bp->edev->ulp_num_ctxs;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (edev)
+		return edev->ulp_num_ctxs;
 	return 0;
 }
 
 void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ulp_ctx)
 {
-	if (bp->edev)
-		bp->edev->ulp_num_ctxs = num_ulp_ctx;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (edev)
+		edev->ulp_num_ctxs = num_ulp_ctx;
 }
 
 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp)
 {
-	if (bnxt_ulp_registered(bp->edev))
-		return bp->edev->ulp_num_ctxs;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (bnxt_ulp_registered(edev))
+		return edev->ulp_num_ctxs;
 	return 0;
 }
 
 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp)
 {
-	if (bp->edev) {
-		bp->edev->ulp_num_ctxs = BNXT_MIN_ROCE_STAT_CTXS;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
+
+	if (edev) {
+		edev->ulp_num_ctxs = BNXT_MIN_ROCE_STAT_CTXS;
 		/* Reserve one additional stat_ctx for PF0 (except
 		 * on 1-port NICs) as it also creates one stat_ctx
 		 * for PF1 in case of RoCE bonding.
 		 */
 		if (BNXT_PF(bp) && !bp->pf.port_id &&
 		    bp->port_count > 1)
-			bp->edev->ulp_num_ctxs++;
+			edev->ulp_num_ctxs++;
 
 		/* Reserve one additional stat_ctx when the device is capable
 		 * of supporting port mirroring on RDMA device.
 		 */
 		if (BNXT_MIRROR_ON_ROCE_CAP(bp))
-			bp->edev->ulp_num_ctxs++;
+			edev->ulp_num_ctxs++;
 	}
 }
 
@@ -141,7 +178,7 @@ int bnxt_register_dev(struct bnxt_en_dev *edev,
 
 	edev->ulp_tbl->msix_requested = bnxt_get_ulp_msix_num(bp);
 
-	bnxt_fill_msix_vecs(bp, bp->edev->msix_entries);
+	bnxt_fill_msix_vecs(bp, edev->msix_entries);

exit:

	mutex_unlock(&edev->en_dev_lock);
	netdev_unlock(dev);
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +64 -48
@@ -227,20 +264,27 @@ EXPORT_SYMBOL(bnxt_send_msg);
 
 void bnxt_ulp_stop(struct bnxt *bp)
 {
-	struct bnxt_aux_priv *aux_priv = bp->aux_priv;
-	struct bnxt_en_dev *edev = bp->edev;
+	int i;
 
-	if (!edev)
-		return;
-
-	mutex_lock(&edev->en_dev_lock);
-	if (!bnxt_ulp_registered(edev) ||
-	    (edev->flags & BNXT_EN_FLAG_ULP_STOPPED))
-		goto ulp_stop_exit;
-
-	edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
-	if (aux_priv) {
+	mutex_lock(&bp->auxdev_lock);
+	for (i = 0; i < __BNXT_AUXDEV_MAX; i++) {
+		struct bnxt_aux_priv *aux_priv;
 		struct auxiliary_device *adev;
+		struct bnxt_en_dev *edev;
+
+		if (!bnxt_auxdev_is_active(bp, i))
+			continue;
+
+		aux_priv = bp->aux_priv[i];
+		edev = bp->edev[i];
+		mutex_lock(&edev->en_dev_lock);
+		if (!bnxt_ulp_registered(edev) ||
+		    (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
+			mutex_unlock(&edev->en_dev_lock);
+			continue;
+		}
+
+		edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
 
 		adev = &aux_priv->aux_dev;
 		if (adev->dev.driver) {
@@ -251,29 +295,35 @@ void bnxt_ulp_stop(struct bnxt *bp)
 			edev->en_state = bp->state;
 			adrv->suspend(adev, pm);
 		}
+		mutex_unlock(&edev->en_dev_lock);
 	}
-ulp_stop_exit:
-	mutex_unlock(&edev->en_dev_lock);
+	mutex_unlock(&bp->auxdev_lock);
 }
 
-void bnxt_ulp_start(struct bnxt *bp, int err)
+void bnxt_ulp_start(struct bnxt *bp)
 {
-	struct bnxt_aux_priv *aux_priv = bp->aux_priv;
-	struct bnxt_en_dev *edev = bp->edev;
+	int i;
 
-	if (!edev || err)
-		return;
+	mutex_lock(&bp->auxdev_lock);
+	for (i = 0; i < __BNXT_AUXDEV_MAX; i++) {
+		struct bnxt_aux_priv *aux_priv;
+		struct auxiliary_device *adev;
+		struct bnxt_en_dev *edev;
 
-	mutex_lock(&edev->en_dev_lock);
-	if (!bnxt_ulp_registered(edev) ||
-	    !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED))
-		goto ulp_start_exit;
+		if (!bnxt_auxdev_is_active(bp, i))
+			continue;
 
-	if (edev->ulp_tbl->msix_requested)
-		bnxt_fill_msix_vecs(bp, edev->msix_entries);
+		aux_priv = bp->aux_priv[i];
+		edev = bp->edev[i];
+		mutex_lock(&edev->en_dev_lock);
+		if (!bnxt_ulp_registered(edev) ||
+		    !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
+			goto clear_flag_continue;
+		}
+
+		if (edev->ulp_tbl->msix_requested)
+			bnxt_fill_msix_vecs(bp, edev->msix_entries);
 
-	if (aux_priv) {
-		struct auxiliary_device *adev;
 
 		adev = &aux_priv->aux_dev;
 		if (adev->dev.driver) {
@@ -283,22 +333,23 @@ void bnxt_ulp_start(struct bnxt *bp, int err)
 			edev->en_state = bp->state;
 			adrv->resume(adev);
 		}
+clear_flag_continue:
+		edev->flags &= ~BNXT_EN_FLAG_ULP_STOPPED;
+		mutex_unlock(&edev->en_dev_lock);
 	}
-ulp_start_exit:
-	edev->flags &= ~BNXT_EN_FLAG_ULP_STOPPED;
-	mutex_unlock(&edev->en_dev_lock);
+	mutex_unlock(&bp->auxdev_lock);
 }
 
 void bnxt_ulp_irq_stop(struct bnxt *bp)
 {
-	struct bnxt_en_dev *edev = bp->edev;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	struct bnxt_ulp_ops *ops;
 	bool reset = false;
 
 	if (!edev)
 		return;
 
-	if (bnxt_ulp_registered(bp->edev)) {
+	if (bnxt_ulp_registered(edev)) {
 		struct bnxt_ulp *ulp = edev->ulp_tbl;
 
 		if (!ulp->msix_requested)
@@ -315,13 +366,13 @@ void bnxt_ulp_irq_stop(struct bnxt *bp)
 
 void bnxt_ulp_irq_restart(struct bnxt *bp, int err)
 {
-	struct bnxt_en_dev *edev = bp->edev;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	struct bnxt_ulp_ops *ops;
 
 	if (!edev)
 		return;
 
-	if (bnxt_ulp_registered(bp->edev)) {
+	if (bnxt_ulp_registered(edev)) {
 		struct bnxt_ulp *ulp = edev->ulp_tbl;
 		struct bnxt_msix_entry *ent = NULL;
 
@@ -347,7 +398,7 @@ void bnxt_ulp_irq_restart(struct bnxt *bp, int err)
 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl)
 {
 	u16 event_id = le16_to_cpu(cmpl->event_id);
-	struct bnxt_en_dev *edev = bp->edev;
+	struct bnxt_en_dev *edev = bp->edev[BNXT_AUXDEV_RDMA];
 	struct bnxt_ulp_ops *ops;
 	struct bnxt_ulp *ulp;
 
@@ -388,18 +439,21 @@ void bnxt_register_async_events(struct bnxt_en_dev *edev,
 }
 EXPORT_SYMBOL(bnxt_register_async_events);
 
-void bnxt_rdma_aux_device_uninit(struct bnxt *bp)
+void bnxt_aux_devices_uninit(struct bnxt *bp)
 {
 	struct bnxt_aux_priv *aux_priv;
 	struct auxiliary_device *adev;
-
-	/* Skip if no auxiliary device init was done. */
-	if (!bp->aux_priv)
-		return;
-
-	aux_priv = bp->aux_priv;
-	adev = &aux_priv->aux_dev;
-	auxiliary_device_uninit(adev);
+	int idx;
+
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		if (bnxt_auxdev_is_init(bp, idx)) {
+			aux_priv = bp->aux_priv[idx];
+			adev = &aux_priv->aux_dev;
+			auxiliary_device_uninit(adev);
+		}
+	}
+	mutex_unlock(&bp->auxdev_lock);
 }
 
 static void bnxt_aux_dev_release(struct device *dev)
@@ -408,20 +462,25 @@ static void bnxt_aux_dev_release(struct device *dev)
 		container_of(dev, struct bnxt_aux_priv, aux_dev.dev);
 	struct bnxt *bp = netdev_priv(aux_priv->edev->net);
 
-	ida_free(&bnxt_aux_dev_ids, aux_priv->id);
 	kfree(aux_priv->edev->ulp_tbl);
-	bp->edev = NULL;
+	bp->edev[aux_priv->id] = NULL;
 	kfree(aux_priv->edev);
 	kfree(aux_priv);
-	bp->aux_priv = NULL;
+	bp->aux_priv[aux_priv->id] = NULL;
 }
 
-void bnxt_rdma_aux_device_del(struct bnxt *bp)
+void bnxt_aux_devices_del(struct bnxt *bp)
 {

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_aux_dev_release(struct device *dev) · line 480

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +6 -3
-	if (!bp->edev)
-		return;
+	int idx;
 
-	auxiliary_device_delete(&bp->aux_priv->aux_dev);
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		if (bnxt_auxdev_is_active(bp, idx)) {
+			auxiliary_device_delete(&bp->aux_priv[idx]->aux_dev);
+			bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);

I can't really follow why you need to maintain a dangling device state !

Why not completely remove and free an aux dev and then on probe/add init and add from scratch, simplified patch #3 which prompted me to come and look back here.

Quoted 233 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +85 -60
+		}
+	}
+	mutex_unlock(&bp->auxdev_lock);
 }
 
 static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
@@ -451,83 +510,105 @@ static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
 	edev->bar0 = bp->bar0;
 }
 
-void bnxt_rdma_aux_device_add(struct bnxt *bp)
+void bnxt_aux_devices_add(struct bnxt *bp)
 {
 	struct auxiliary_device *aux_dev;
-	int rc;
-
-	if (!bp->edev)
-		return;
-
-	aux_dev = &bp->aux_priv->aux_dev;
-	rc = auxiliary_device_add(aux_dev);
-	if (rc) {
-		netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
-		auxiliary_device_uninit(aux_dev);
-		bp->flags &= ~BNXT_FLAG_ROCE_CAP;
+	int rc, idx;
+
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		if (bnxt_auxdev_is_init(bp, idx)) {
+			aux_dev = &bp->aux_priv[idx]->aux_dev;
+			rc = auxiliary_device_add(aux_dev);
+			if (rc) {
+				netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
+				auxiliary_device_uninit(aux_dev);
+				if (idx == BNXT_AUXDEV_RDMA)
+					bp->flags &= ~BNXT_FLAG_ROCE_CAP;
+				continue;
+			}
+			bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_ADD);
+		}
 	}
+	mutex_unlock(&bp->auxdev_lock);
 }
 
-void bnxt_rdma_aux_device_init(struct bnxt *bp)
+void bnxt_aux_devices_init(struct bnxt *bp)
 {
 	struct auxiliary_device *aux_dev;
 	struct bnxt_aux_priv *aux_priv;
 	struct bnxt_en_dev *edev;
 	struct bnxt_ulp *ulp;
-	int rc;
+	int rc, idx;
+
+	mutex_lock(&bp->auxdev_lock);
+	for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+		bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_NONE);
+
+		if (idx == BNXT_AUXDEV_RDMA &&
+		    !(bp->flags & BNXT_FLAG_ROCE_CAP))
+			continue;
+
+		aux_priv = kzalloc(sizeof(*aux_priv), GFP_KERNEL);
+		if (!aux_priv)
+			goto next_auxdev;
+
+		aux_dev = &aux_priv->aux_dev;
+		aux_dev->id = bp->auxdev_id;
+		aux_dev->name = bnxt_aux_devices[idx].name;
+		aux_dev->dev.parent = &bp->pdev->dev;
+		aux_dev->dev.release = bnxt_aux_dev_release;
+
+		rc = auxiliary_device_init(aux_dev);
+		if (rc) {
+			kfree(aux_priv);
+			goto next_auxdev;
+		}
+		bp->aux_priv[idx] = aux_priv;
 
-	if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
-		return;
+		/* From this point, all cleanup will happen via the .release
+		 * callback & any error unwinding will need to include a call
+		 * to auxiliary_device_uninit.
+		 */
+		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+		if (!edev)
+			goto aux_dev_uninit;
 
-	aux_priv = kzalloc(sizeof(*bp->aux_priv), GFP_KERNEL);
-	if (!aux_priv)
-		goto exit;
+		aux_priv->edev = edev;
+		bnxt_set_edev_info(edev, bp);
 
-	aux_priv->id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL);
-	if (aux_priv->id < 0) {
-		netdev_warn(bp->dev,
-			    "ida alloc failed for ROCE auxiliary device\n");
-		kfree(aux_priv);
-		goto exit;
-	}
+		ulp = kzalloc(sizeof(*ulp), GFP_KERNEL);
+		if (!ulp)
+			goto aux_dev_uninit;
 
-	aux_dev = &aux_priv->aux_dev;
-	aux_dev->id = aux_priv->id;
-	aux_dev->name = "rdma";
-	aux_dev->dev.parent = &bp->pdev->dev;
-	aux_dev->dev.release = bnxt_aux_dev_release;
+		edev->ulp_tbl = ulp;
+		bp->edev[idx] = edev;
+		if (idx == BNXT_AUXDEV_RDMA)
+			bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp);
+		aux_priv->id = idx;
+		bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);
 
-	rc = auxiliary_device_init(aux_dev);
-	if (rc) {
-		ida_free(&bnxt_aux_dev_ids, aux_priv->id);
-		kfree(aux_priv);
-		goto exit;
+		continue;
+aux_dev_uninit:
+		auxiliary_device_uninit(aux_dev);
+next_auxdev:
+		if (idx == BNXT_AUXDEV_RDMA)
+			bp->flags &= ~BNXT_FLAG_ROCE_CAP;
 	}
-	bp->aux_priv = aux_priv;
-
-	/* From this point, all cleanup will happen via the .release callback &
-	 * any error unwinding will need to include a call to
-	 * auxiliary_device_uninit.
-	 */
-	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
-	if (!edev)
-		goto aux_dev_uninit;
-
-	aux_priv->edev = edev;
-
-	ulp = kzalloc(sizeof(*ulp), GFP_KERNEL);
-	if (!ulp)
-		goto aux_dev_uninit;
+	mutex_unlock(&bp->auxdev_lock);
+}
 
-	edev->ulp_tbl = ulp;
-	bp->edev = edev;
-	bnxt_set_edev_info(edev, bp);
-	bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp);
+int bnxt_auxdev_id_alloc(struct bnxt *bp)
+{
+	bp->auxdev_id = ida_alloc(&bnxt_aux_dev_ids, GFP_KERNEL);
+	if (bp->auxdev_id < 0)
+		return bp->auxdev_id;
 
-	return;
+	return 0;
+}
 
-aux_dev_uninit:
-	auxiliary_device_uninit(aux_dev);
-exit:
-	bp->flags &= ~BNXT_FLAG_ROCE_CAP;
+void bnxt_auxdev_id_free(struct bnxt *bp, int id)
+{
+	if (bp->auxdev_id >= 0)
+		ida_free(&bnxt_aux_dev_ids, id);
 }
include/linux/bnxt/ulp.h +20 -5
index 3c5b8a53f715..1a4643c46f86 100644
@@ -10,6 +10,8 @@
 #ifndef BNXT_ULP_H
 #define BNXT_ULP_H
 
+#include <linux/auxiliary_bus.h>
+
 #define BNXT_MIN_ROCE_CP_RINGS	2
 #define BNXT_MIN_ROCE_STAT_CTXS	1
 
@@ -20,6 +22,17 @@
 struct hwrm_async_event_cmpl;
 struct bnxt;
 
+enum bnxt_auxdev_type {
+	BNXT_AUXDEV_RDMA = 0,
+	__BNXT_AUXDEV_MAX
+};
+
+struct bnxt_aux_priv {
+	struct auxiliary_device aux_dev;
+	struct bnxt_en_dev *edev;
+	int id;
+};
+
 struct bnxt_msix_entry {
 	u32	vector;
 	u32	ring_idx;
@@ -110,19 +123,21 @@ void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ctxs);
 int bnxt_get_ulp_stat_ctxs_in_use(struct bnxt *bp);
 void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp);
 void bnxt_ulp_stop(struct bnxt *bp);
-void bnxt_ulp_start(struct bnxt *bp, int err);
+void bnxt_ulp_start(struct bnxt *bp);
 void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);
 void bnxt_ulp_irq_stop(struct bnxt *bp);
 void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
-void bnxt_rdma_aux_device_uninit(struct bnxt *bp);
-void bnxt_rdma_aux_device_del(struct bnxt *bp);
-void bnxt_rdma_aux_device_add(struct bnxt *bp);
-void bnxt_rdma_aux_device_init(struct bnxt *bp);
+void bnxt_aux_devices_uninit(struct bnxt *bp);
+void bnxt_aux_devices_del(struct bnxt *bp);
+void bnxt_aux_devices_add(struct bnxt *bp);
+void bnxt_aux_devices_init(struct bnxt *bp);
 int bnxt_register_dev(struct bnxt_en_dev *edev, struct bnxt_ulp_ops *ulp_ops,
 		      void *handle);
 void bnxt_unregister_dev(struct bnxt_en_dev *edev);
 int bnxt_send_msg(struct bnxt_en_dev *edev, struct bnxt_fw_msg *fw_msg);
 void bnxt_register_async_events(struct bnxt_en_dev *edev,
 				unsigned long *events_bmap, u16 max_id);
+int bnxt_auxdev_id_alloc(struct bnxt *bp);
+void bnxt_auxdev_id_free(struct bnxt *bp, int id);
 #endif
Signature · 1 line
2.39.1
author maintainer
#6 lore raw

Re: [PATCH v3 fwctl 2/5] fwctl/bnxt_en: Refactor aux bus functions to be more generic

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -1
-void bnxt_rdma_aux_device_del(struct bnxt *bp)
+void bnxt_aux_devices_del(struct bnxt *bp)

{

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -2
-      if (!bp->edev)
-              return;
+      int idx;
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_aux_dev_release(struct device *dev) · line 480

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -1
-      auxiliary_device_delete(&bp->aux_priv->aux_dev);
+      mutex_lock(&bp->auxdev_lock);
+      for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+              if (bnxt_auxdev_is_active(bp, idx)) {
+                      auxiliary_device_delete(&bp->aux_priv[idx]->aux_dev);
+                      bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);

I can't really follow why you need to maintain a dangling device state !

This is so because the init-add and del-uninit function pair in bnxt are not tightly coupled, possibly for some historic reason. I see it produces regressions trying to club them together. As of now, these states are going to be in use only during probe/remove.

Quoted 4 lines

Why not completely remove and free an aux dev and then on probe/add init and add from scratch, simplified patch #3 which prompted me to come and look back here.

I see what you are saying. This is a design carried over from pre-auxbus time between bnxt_en and RoCE drivers and I need a buy-in from our RoCE driver folks to make this change.
I am very certain I will endup touching RoCE driver code and it will increase the scope of the changes in this series. If not anything else, the regression tests will require a lot of time and effort. That said, it's a good change to make. Let me check with our RoCE team internally and get back.

Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -0
+              }
+      }
+      mutex_unlock(&bp->auxdev_lock);

}

author maintainer
#7 lore raw

Re: [PATCH v3 fwctl 2/5] fwctl/bnxt_en: Refactor aux bus functions to be more generic

Quoted 27 lines · Pavan Chebbi
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -1
-void bnxt_rdma_aux_device_del(struct bnxt *bp)
+void bnxt_aux_devices_del(struct bnxt *bp)

{

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -2
-      if (!bp->edev)
-              return;
+      int idx;
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c static void bnxt_aux_dev_release(struct device *dev) · line 480

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -1
-      auxiliary_device_delete(&bp->aux_priv->aux_dev);
+      mutex_lock(&bp->auxdev_lock);
+      for (idx = 0; idx < __BNXT_AUXDEV_MAX; idx++) {
+              if (bnxt_auxdev_is_active(bp, idx)) {
+                      auxiliary_device_delete(&bp->aux_priv[idx]->aux_dev);
+                      bnxt_auxdev_set_state(bp, idx, BNXT_ADEV_STATE_INIT);

I can't really follow why you need to maintain a dangling device state !

This is so because the init-add and del-uninit function pair in bnxt are not tightly coupled, possibly for some historic reason. I see it produces regressions trying to club them together. As of now, these states are going to be in use only during probe/remove.

Quoted 4 lines

Why not completely remove and free an aux dev and then on probe/add init and add from scratch, simplified patch #3 which prompted me to come and look back here.

Quoted 8 lines

I see what you are saying. This is a design carried over from pre-auxbus time between bnxt_en and RoCE drivers and I need a buy-in from our RoCE driver folks to make this change.
I am very certain I will endup touching RoCE driver code and it will increase the scope of the changes in this series. If not anything else, the regression tests will require a lot of time and effort. That said, it's a good change to make. Let me check with our RoCE team internally and get back.

I checked with our RoCE team. And yes, we feel time is ripe to move to a complete aux bus dependent design.
We want to get rid of ulp_start/stop entirely and replace it with aux device del/add. But this is going to need changes in the RoCE driver. Looking at the changes and the testing involved, we feel it is best suited to implement in our internal tree first.
RoCE team plans to start with this change and we anticipate it should land upstream for review by 6.22 timeframe.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -0
+              }
+      }
+      mutex_unlock(&bp->auxdev_lock);

}

author maintainer
#8 lore raw

PATCH v3 3/5 fwctl/bnxt_en: Create an aux device for fwctl

In reply to Pavan Chebbi

Create an additional auxiliary device to support fwctl. The next patch will create bnxt_fwctl and bind to this device.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 12 ++++++++++--
 include/linux/bnxt/ulp.h                      |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +10 -2
index 3097fc5755e6..9fd3c1e43224 100644
@@ -50,6 +50,8 @@ static bool bnxt_auxdev_is_active(struct bnxt *bp, int idx)
 
 static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{
 	.name		= "rdma",
+}, {
+	.name		= "fwctl",
 }};
 
 static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)
@@ -278,6 +280,11 @@ void bnxt_ulp_stop(struct bnxt *bp)
 		aux_priv = bp->aux_priv[i];
 		edev = bp->edev[i];
 		mutex_lock(&edev->en_dev_lock);
+		if (i == BNXT_AUXDEV_FWCTL) {
+			edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
+			mutex_unlock(&edev->en_dev_lock);
+			continue;
+		}
 		if (!bnxt_ulp_registered(edev) ||
 		    (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
 			mutex_unlock(&edev->en_dev_lock);
@@ -316,7 +323,7 @@ void bnxt_ulp_start(struct bnxt *bp)
 		aux_priv = bp->aux_priv[i];
 		edev = bp->edev[i];
 		mutex_lock(&edev->en_dev_lock);
-		if (!bnxt_ulp_registered(edev) ||
+		if (i == BNXT_AUXDEV_FWCTL || !bnxt_ulp_registered(edev) ||
 		    !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
 			goto clear_flag_continue;
 		}
@@ -521,7 +528,8 @@ void bnxt_aux_devices_add(struct bnxt *bp)
 			aux_dev = &bp->aux_priv[idx]->aux_dev;
 			rc = auxiliary_device_add(aux_dev);
 			if (rc) {
-				netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
+				netdev_warn(bp->dev, "Failed to add auxiliary device for auxdev type %d\n",
+					    idx);
 				auxiliary_device_uninit(aux_dev);
 				if (idx == BNXT_AUXDEV_RDMA)
 					bp->flags &= ~BNXT_FLAG_ROCE_CAP;
include/linux/bnxt/ulp.h +1 -0
index 1a4643c46f86..0851ad3394b0 100644
@@ -24,6 +24,7 @@ struct bnxt;
 
 enum bnxt_auxdev_type {
 	BNXT_AUXDEV_RDMA = 0,
+	BNXT_AUXDEV_FWCTL,
 	__BNXT_AUXDEV_MAX
 };
 
Signature · 1 line
2.39.1
#9 lore raw

Re: [PATCH v3 fwctl 3/5] fwctl/bnxt_en: Create an aux device for fwctl

Quoted 25 lines · On Thu, 29 Jan 2026 07:54:51 -0800 Pavan Chebbi <[email protected]>…

Create an additional auxiliary device to support fwctl. The next patch will create bnxt_fwctl and bind to this device.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 12 ++++++++++--
 include/linux/bnxt/ulp.h                      |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -0
index 3097fc5755e6..9fd3c1e43224 100644
@@ -50,6 +50,8 @@ static bool bnxt_auxdev_is_active(struct bnxt *bp, int idx)
 
 static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{
 	.name		= "rdma",
+}, {
+	.name		= "fwctl",
 }};
 
 static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c void bnxt_ulp_stop(struct bnxt *bp) · line 283

Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +1 -0
@@ -278,6 +280,11 @@ void bnxt_ulp_stop(struct bnxt *bp)
 		aux_priv = bp->aux_priv[i];
 		edev = bp->edev[i];
 		mutex_lock(&edev->en_dev_lock);
+		if (i == BNXT_AUXDEV_FWCTL) {

Similar to earlier. I'd like this stuff to be callbacks or data in bnxt_aux_devices to keep the code flow simpler.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -0
+			edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
+			mutex_unlock(&edev->en_dev_lock);
+			continue;
maintainer
#10 lore raw

Re: [PATCH v3 fwctl 3/5] fwctl/bnxt_en: Create an aux device for fwctl

In reply to Pavan Chebbi
Quoted 25 lines · Pavan Chebbi

Create an additional auxiliary device to support fwctl. The next patch will create bnxt_fwctl and bind to this device.

---
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 12 ++++++++++--
include/linux/bnxt/ulp.h | 1 +

2 files changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +2 -0
index 3097fc5755e6..9fd3c1e43224 100644
@@ -50,6 +50,8 @@ static bool bnxt_auxdev_is_active(struct bnxt *bp, int idx)
 
 static struct bnxt_aux_device bnxt_aux_devices[__BNXT_AUXDEV_MAX] = {{
 	.name		= "rdma",
+}, {
+	.name		= "fwctl",
 }};
 
 static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)

drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c void bnxt_ulp_stop(struct bnxt *bp) · line 287

Quoted 8 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +5 -0
@@ -278,6 +280,11 @@ void bnxt_ulp_stop(struct bnxt *bp)
 		aux_priv = bp->aux_priv[i];
 		edev = bp->edev[i];
 		mutex_lock(&edev->en_dev_lock);
+		if (i == BNXT_AUXDEV_FWCTL) {
+			edev->flags |= BNXT_EN_FLAG_ULP_STOPPED;
+			mutex_unlock(&edev->en_dev_lock);
+			continue;
+		}

This felt a bet off so I had to comment on patch 2. The fact that you need to maintain a edev flag for ULP state was before using aux bus for all upls which was kindof ok since it was unconditionally set on bnxt_stop/start, but now the state got pretty complex with the introduction of dangling aux devices as I mentioned in the previous patch. please see suggestion on that patch, I am sure this can be simplified a lot.

Quoted 37 lines
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c +3 -2
 		if (!bnxt_ulp_registered(edev) ||
 		    (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
 			mutex_unlock(&edev->en_dev_lock);
@@ -316,7 +323,7 @@ void bnxt_ulp_start(struct bnxt *bp)
 		aux_priv = bp->aux_priv[i];
 		edev = bp->edev[i];
 		mutex_lock(&edev->en_dev_lock);
-		if (!bnxt_ulp_registered(edev) ||
+		if (i == BNXT_AUXDEV_FWCTL || !bnxt_ulp_registered(edev) ||
 		    !(edev->flags & BNXT_EN_FLAG_ULP_STOPPED)) {
 			goto clear_flag_continue;
 		}
@@ -521,7 +528,8 @@ void bnxt_aux_devices_add(struct bnxt *bp)
 			aux_dev = &bp->aux_priv[idx]->aux_dev;
 			rc = auxiliary_device_add(aux_dev);
 			if (rc) {
-				netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
+				netdev_warn(bp->dev, "Failed to add auxiliary device for auxdev type %d\n",
+					    idx);
 				auxiliary_device_uninit(aux_dev);
 				if (idx == BNXT_AUXDEV_RDMA)
 					bp->flags &= ~BNXT_FLAG_ROCE_CAP;
include/linux/bnxt/ulp.h +1 -0
index 1a4643c46f86..0851ad3394b0 100644
@@ -24,6 +24,7 @@ struct bnxt;
 
 enum bnxt_auxdev_type {
 	BNXT_AUXDEV_RDMA = 0,
+	BNXT_AUXDEV_FWCTL,
 	__BNXT_AUXDEV_MAX
 };
 
Signature · 1 line
2.39.1
author maintainer
#11 lore raw

PATCH v3 4/5 fwctl/bnxt_fwctl: Add bnxt fwctl device

In reply to Pavan Chebbi

Create bnxt_fwctl device. This will bind to bnxt's aux device. On the upper edge, it will register with the fwctl subsystem. It will make use of bnxt's ULP functions to send FW commands.

---
 MAINTAINERS                 |   6 +
 drivers/fwctl/Kconfig       |  11 +
 drivers/fwctl/Makefile      |   1 +
 drivers/fwctl/bnxt/Makefile |   4 +
 drivers/fwctl/bnxt/main.c   | 416 ++++++++++++++++++++++++++++++++++++
 include/uapi/fwctl/bnxt.h   |  64 ++++++
 include/uapi/fwctl/fwctl.h  |   1 +
 7 files changed, 503 insertions(+)
 create mode 100644 drivers/fwctl/bnxt/Makefile
 create mode 100644 drivers/fwctl/bnxt/main.c
 create mode 100644 include/uapi/fwctl/bnxt.h
MAINTAINERS +6 -0
index 12f49de7fe03..38acd5d334b2 100644
@@ -10408,6 +10408,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/fwctl/pds/
 
+FWCTL BNXT DRIVER
+M:	Pavan Chebbi <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/fwctl/bnxt/
+
 GALAXYCORE GC0308 CAMERA SENSOR DRIVER
 M:	Sebastian Reichel <[email protected]>
 L:	[email protected]
drivers/fwctl/Kconfig +11 -0
index b5583b12a011..b3795a17f8f2 100644
@@ -29,5 +29,16 @@ config FWCTL_PDS
 	  to access the debug and configuration information of the AMD/Pensando
 	  DSC hardware family.
 
+	  If you don't know what to do here, say N.
+
+config FWCTL_BNXT
+	tristate "bnxt control fwctl driver"
+	depends on BNXT
+	help
+	  BNXT provides interface for the user process to access the debug and
+	  configuration registers of the Broadcom NIC hardware family.
+	  This will allow configuration and debug tools to work out of the box on
+	  mainstream kernel.
+
 	  If you don't know what to do here, say N.
 endif
drivers/fwctl/Makefile +1 -0
index c093b5f661d6..fdd46f3a0e4e 100644
@@ -2,5 +2,6 @@
 obj-$(CONFIG_FWCTL) += fwctl.o
 obj-$(CONFIG_FWCTL_MLX5) += mlx5/
 obj-$(CONFIG_FWCTL_PDS) += pds/
+obj-$(CONFIG_FWCTL_BNXT) += bnxt/
 
 fwctl-y += main.o
drivers/fwctl/bnxt/Makefile new file +4 -0
new file mode 100644
index 000000000000..b47172761f1e
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_FWCTL_BNXT) += bnxt_fwctl.o
+
+bnxt_fwctl-y += main.o
drivers/fwctl/bnxt/main.c new file +416 -0

416 lines not on this page · raw message

include/uapi/fwctl/bnxt.h new file +64 -0

64 lines not on this page · raw message

include/uapi/fwctl/fwctl.h +1 -0
index 716ac0eee42d..2d6d4049c205 100644
@@ -44,6 +44,7 @@ enum fwctl_device_type {
 	FWCTL_DEVICE_TYPE_ERROR = 0,
 	FWCTL_DEVICE_TYPE_MLX5 = 1,
 	FWCTL_DEVICE_TYPE_CXL = 2,
+	FWCTL_DEVICE_TYPE_BNXT = 3,
 	FWCTL_DEVICE_TYPE_PDS = 4,
 };
 
Signature · 1 line
2.39.1
#12 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 7 lines · On Thu, 29 Jan 2026 07:54:52 -0800 Pavan Chebbi <[email protected]>…

Create bnxt_fwctl device. This will bind to bnxt's aux device. On the upper edge, it will register with the fwctl subsystem. It will make use of bnxt's ULP functions to send FW commands.

Hi

Various comments inline,

Thanks,

Jonathan

Quoted 10 lines
drivers/fwctl/Kconfig +2 -0
index b5583b12a011..b3795a17f8f2 100644
@@ -29,5 +29,16 @@ config FWCTL_PDS
 	  to access the debug and configuration information of the AMD/Pensando
 	  DSC hardware family.
 
+	  If you don't know what to do here, say N.
+

drivers/fwctl/Kconfig config FWCTL_PDS · line 43

Quoted 10 lines
drivers/fwctl/Kconfig +9 -0
+config FWCTL_BNXT
+	tristate "bnxt control fwctl driver"
+	depends on BNXT
+	help
+	  BNXT provides interface for the user process to access the debug and
+	  configuration registers of the Broadcom NIC hardware family.
+	  This will allow configuration and debug tools to work out of the box on
+	  mainstream kernel.
+
 	  If you don't know what to do here, say N.

Same thing on ordering as for the make file. Just adding at the end doesn't make it easy to find entries once we have lots of them!

drivers/fwctl/Makefile line 5

Quoted 10 lines
drivers/fwctl/Kconfig +0 -0
 endif
drivers/fwctl/Makefile +1 -0
index c093b5f661d6..fdd46f3a0e4e 100644
@@ -2,5 +2,6 @@
 obj-$(CONFIG_FWCTL) += fwctl.o
 obj-$(CONFIG_FWCTL_MLX5) += mlx5/
 obj-$(CONFIG_FWCTL_PDS) += pds/
+obj-$(CONFIG_FWCTL_BNXT) += bnxt/

How are we ordering these? Alphabetical maybe?

Quoted 50 lines
drivers/fwctl/bnxt/main.c new file +42 -0
new file mode 100644
index 000000000000..67d65b36cb38
 
+static void *bnxtctl_fw_rpc(struct fwctl_uctx *uctx,
+			    enum fwctl_rpc_scope scope,
+			    void *in, size_t in_len, size_t *out_len)
+{
+	struct bnxtctl_dev *bnxtctl =
+		container_of(uctx->fwctl, struct bnxtctl_dev, fwctl);
+	struct bnxt_aux_priv *bnxt_aux_priv = bnxtctl->aux_priv;
+	void *dma_virt_addr[MAX_NUM_DMA_INDICATIONS];
+	dma_addr_t dma_addr[MAX_NUM_DMA_INDICATIONS];
+	struct fwctl_dma_info_bnxt *dma_buf = NULL;
+	struct device *dev = &uctx->fwctl->dev;
+	struct fwctl_rpc_bnxt *msg = in;
+	struct bnxt_fw_msg rpc_in = {0};
+	int i, rc, err = 0;
+
+	rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
+	if (IS_ERR(rpc_in.msg))
+		return rpc_in.msg;
+
+	if (!bnxtctl_validate_rpc(bnxt_aux_priv->edev, &rpc_in, scope)) {
+		err = -EPERM;
+		goto free_msg_out;
+	}
+
+	rpc_in.msg_len = msg->req_len;
+	rpc_in.resp = kzalloc(*out_len, GFP_KERNEL);
+	if (!rpc_in.resp) {
+		err = -ENOMEM;
+		goto free_msg_out;
+	}
+
+	rpc_in.resp_max_len = *out_len;
+	if (!msg->timeout)
+		rpc_in.timeout = DFLT_HWRM_CMD_TIMEOUT;
+	else
+		rpc_in.timeout = msg->timeout;
+
+	if (msg->num_dma) {
+		if (msg->num_dma > MAX_NUM_DMA_INDICATIONS) {
+			dev_err(dev, "DMA buffers exceed the number supported\n");
+			err = -EINVAL;
+			goto free_msg_out;

drivers/fwctl/bnxt/main.c line 298

Quoted 10 lines
drivers/fwctl/bnxt/main.c new file +10 -0
+		}
+
+		dma_buf = kcalloc(msg->num_dma, sizeof(*dma_buf), GFP_KERNEL);
+		if (!dma_buf) {
+			err = -ENOMEM;
+			goto free_msg_out;
+		}
+
+		if (copy_from_user(dma_buf, u64_to_user_ptr(msg->payload),
+				   msg->num_dma * sizeof(*dma_buf))) {

Why not memdup_user() for this one?

Quoted 35 lines
drivers/fwctl/bnxt/main.c new file +35 -0
+			dev_dbg(dev, "Failed to copy payload from user\n");
+			err = -EFAULT;
+			goto free_dmabuf_out;
+		}
+
+		err = bnxt_fw_setup_input_dma(bnxtctl, dev, dma_buf, &rpc_in,
+					      msg->num_dma, &dma_virt_addr[0],
+					      &dma_addr[0]);
+		if (err)
+			goto free_dmabuf_out;
+	}
+
+	rc = bnxt_send_msg(bnxt_aux_priv->edev, &rpc_in);
+	if (rc) {
+		struct output *resp = rpc_in.resp;
+
+		/* Copy the response to user always, as it contains
+		 * detailed status of the command failure
+		 */
+		if (!resp->error_code)
+			/* bnxt_send_msg() returned much before FW
+			 * received the command.
+			 */
+			resp->error_code = rc;
+
+		goto free_dma_out;
+	}
+
+	for (i = 0; i < msg->num_dma; i++) {
+		if (dma_buf[i].dma_direction != DEVICE_READ)
+			continue;
+		if (copy_to_user(u64_to_user_ptr(dma_buf[i].data),
+				 dma_virt_addr[i], dma_buf[i].len)) {
+			dev_dbg(dev, "Failed to copy resp to user\n");
+			err = -EFAULT;

drivers/fwctl/bnxt/main.c line 343

Quoted 10 lines
drivers/fwctl/bnxt/main.c new file +10 -0
+			break;
+		}
+	}
+free_dma_out:
+	/* Cleanup any dma memory that bnxt_fw_setup_input_dma() may have
+	 * allocated
+	 */
+	for (i = 0; i < msg->num_dma; i++)
+		dma_free_coherent(dev->parent, dma_buf[i].len, dma_virt_addr[i],
+				  dma_addr[i]);

I'd have a tear down function to undo what bnxt_fw_setup_input_dma() does so that the two functions can be easily matched against each other.

drivers/fwctl/bnxt/main.c line 347

Quoted 4 lines
drivers/fwctl/bnxt/main.c new file +4 -0
+free_dmabuf_out:
+	kfree(dma_buf);
+free_msg_out:
+	kfree(rpc_in.msg);

Free in reverse order of allocation. Even if that means a dance with multiple if (err).

Personally I'd probably split the good and bad paths so we can have a nice clean normal path and avoid if (err) dance when we know it is always set. The extra clarity would be worth duplicating a few lines. Would also allow extra labels to avoid kfree() of things that haven't been allocated (obviously that's safe but still not nice)

I think you could reorder the allocations to do rpc_in.resp first in which case this style would work better.

Quoted 21 lines
drivers/fwctl/bnxt/main.c new file +9 -0
+
+	if (err) {
+		kfree(rpc_in.resp);
+		return ERR_PTR(err);
+	}
+
+	return rpc_in.resp;
+}
 
+}
include/uapi/fwctl/bnxt.h new file +4 -0
new file mode 100644
index 000000000000..5620812d839c
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (c) 2026, Broadcom Inc
+ */

include/uapi/fwctl/bnxt.h line 14

Quoted 10 lines
include/uapi/fwctl/bnxt.h new file +10 -0
+
+#ifndef _UAPI_FWCTL_BNXT_H_
+#define _UAPI_FWCTL_BNXT_H_
+
+#include <linux/types.h>
+
+#define MAX_DMA_MEM_SIZE		0x10000 /*64K*/
+#define DFLT_HWRM_CMD_TIMEOUT		500
+#define DEVICE_WRITE			0
+#define DEVICE_READ			1

Those are very generic names to stick in a uapi header. Prefix them probably or maybe rename the structure field to something like dma_to_device.

Also, write and read seem a bit oddly aligned with the use in a direction field. Maybe FWCTL_BNXT_DIR_TO_DEVICE and DIR_FROM_DEVICE.

include/uapi/fwctl/bnxt.h line 18

Quoted 4 lines
include/uapi/fwctl/bnxt.h new file +4 -0
+
+enum fwctl_bnxt_commands {
+	FWCTL_BNXT_QUERY_COMMANDS = 0,
+	FWCTL_BNXT_SEND_COMMAND,

Seems like these need to have hardware /firmware matching numbers? If so I'd make the explicit by assigning them all. Just assigning 0 kind of gives the wrong impression.

include/uapi/fwctl/bnxt.h line 35

Quoted 5 lines
include/uapi/fwctl/bnxt.h new file +4 -0
+};
 
+/**
+ * struct fwctl_dma_info_bnxt - describe the buffer that should be DMAed
+ * @data: DMA-intended buffer

As below, I'd call out that's an address. The type obscures that.

Quoted 10 lines

+ * @len: length of the @data
+ * @offset: offset at which FW (HWRM) input structure needs DMA address
+ * @dma_direction: DMA direction, DEVICE_READ or DEVICE_WRITE
+ * @unused: pad
+ */

include/uapi/fwctl/bnxt.h new file +5 -0
+struct fwctl_dma_info_bnxt {
+	__aligned_u64 data;
+	__u32 len;
+	__u16 offset;
+	__u8 dma_direction;

include/uapi/fwctl/bnxt.h line 55

Quoted 10 lines
include/uapi/fwctl/bnxt.h new file +10 -0
+	__u8 unused;
+};
+
+/**
+ * struct fwctl_rpc_bnxt - describe the fwctl message for bnxt
+ * @req: FW (HWRM) command input structure
+ * @req_len: length of @req
+ * @timeout: if the user wants to override the driver's default, 0 otherwise
+ * @num_dma: number of DMA buffers to be added to @req
+ * @payload: DMA buffer details in struct fwctl_dma_info_bnxt format

That comment has me confused. If it's in that format, why not use that structure? Also it doesn't fit which confused me even more!
Ah. I checked the usage. It's a pointer. Say that in the comment. It's a bit of a pitty can't type it such that the pointer version of __counted_by will work on payload. Never mind...

Quoted 9 lines

+ */

include/uapi/fwctl/bnxt.h new file +8 -0
+struct fwctl_rpc_bnxt {
+	__aligned_u64 req;
+	__u32 req_len;
+	__u32 timeout;
+	__u32 num_dma;
+	__aligned_u64 payload;
+};
+#endif
#13 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 8 lines · Jonathan Cameron

drivers/fwctl/Makefile line 5

Quoted 7 lines
drivers/fwctl/Makefile +1 -0
@@ -2,5 +2,6 @@
 obj-$(CONFIG_FWCTL) += fwctl.o
 obj-$(CONFIG_FWCTL_MLX5) += mlx5/
 obj-$(CONFIG_FWCTL_PDS) += pds/
+obj-$(CONFIG_FWCTL_BNXT) += bnxt/

How are we ordering these? Alphabetical maybe?

Yes, please sort all the things, including the kconfig

Jason

maintainer
#14 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

In reply to Pavan Chebbi
Quoted 267 lines · Pavan Chebbi

Create bnxt_fwctl device. This will bind to bnxt's aux device. On the upper edge, it will register with the fwctl subsystem. It will make use of bnxt's ULP functions to send FW commands.

---

MAINTAINERS                 |   6 +
drivers/fwctl/Kconfig       |  11 +
drivers/fwctl/Makefile      |   1 +
drivers/fwctl/bnxt/Makefile |   4 +
drivers/fwctl/bnxt/main.c   | 416 ++++++++++++++++++++++++++++++++++++
include/uapi/fwctl/bnxt.h   |  64 ++++++
include/uapi/fwctl/fwctl.h  |   1 +
7 files changed, 503 insertions(+)

create mode 100644 drivers/fwctl/bnxt/Makefile
create mode 100644 drivers/fwctl/bnxt/main.c
create mode 100644 include/uapi/fwctl/bnxt.h

MAINTAINERS +0 -0
index 12f49de7fe03..38acd5d334b2 100644
@@ -10408,6 +10408,12 @@ L:	[email protected]

S: Maintained
F: drivers/fwctl/pds/

MAINTAINERS +6 -0
+FWCTL BNXT DRIVER
+M:	Pavan Chebbi <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/fwctl/bnxt/
+

GALAXYCORE GC0308 CAMERA SENSOR DRIVER
M: Sebastian Reichel <[email protected]>
L: [email protected]

drivers/fwctl/Kconfig +11 -0
index b5583b12a011..b3795a17f8f2 100644
@@ -29,5 +29,16 @@ config FWCTL_PDS
 	  to access the debug and configuration information of the AMD/Pensando
 	  DSC hardware family.
 
+	  If you don't know what to do here, say N.
+
+config FWCTL_BNXT
+	tristate "bnxt control fwctl driver"
+	depends on BNXT
+	help
+	  BNXT provides interface for the user process to access the debug and
+	  configuration registers of the Broadcom NIC hardware family.
+	  This will allow configuration and debug tools to work out of the box on
+	  mainstream kernel.
+
 	  If you don't know what to do here, say N.

endif

drivers/fwctl/Makefile +0 -0
index c093b5f661d6..fdd46f3a0e4e 100644
@@ -2,5 +2,6 @@

obj-$(CONFIG_FWCTL) += fwctl.o
obj-$(CONFIG_FWCTL_MLX5) += mlx5/
obj-$(CONFIG_FWCTL_PDS) += pds/
+obj-$(CONFIG_FWCTL_BNXT) += bnxt/

fwctl-y += main.o

drivers/fwctl/bnxt/Makefile new file +4 -0
new file mode 100644
index 000000000000..b47172761f1e
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_FWCTL_BNXT) += bnxt_fwctl.o
+
+bnxt_fwctl-y += main.o
drivers/fwctl/bnxt/main.c new file +182 -0
new file mode 100644
index 000000000000..67d65b36cb38
@@ -0,0 +1,416 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026, Broadcom Corporation
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+#include <linux/fwctl.h>
+#include <linux/bnxt/hsi.h>
+#include <linux/bnxt/ulp.h>
+#include <uapi/fwctl/fwctl.h>
+#include <uapi/fwctl/bnxt.h>
+
+struct bnxtctl_uctx {
+	struct fwctl_uctx uctx;
+	u32 uctx_caps;
+};
+
+struct bnxtctl_dev {
+	struct fwctl_device fwctl;
+	struct bnxt_aux_priv *aux_priv;
+};
+
+DEFINE_FREE(bnxtctl, struct bnxtctl_dev *, if (_T) fwctl_put(&_T->fwctl))
+
+static int bnxtctl_open_uctx(struct fwctl_uctx *uctx)
+{
+	struct bnxtctl_uctx *bnxtctl_uctx =
+		container_of(uctx, struct bnxtctl_uctx, uctx);
+
+	bnxtctl_uctx->uctx_caps = BIT(FWCTL_BNXT_QUERY_COMMANDS) |
+				  BIT(FWCTL_BNXT_SEND_COMMAND);
+	return 0;
+}
+
+static void bnxtctl_close_uctx(struct fwctl_uctx *uctx)
+{
+}
+
+static void *bnxtctl_info(struct fwctl_uctx *uctx, size_t *length)
+{
+	struct bnxtctl_uctx *bnxtctl_uctx =
+		container_of(uctx, struct bnxtctl_uctx, uctx);
+	struct fwctl_info_bnxt *info;
+
+	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return ERR_PTR(-ENOMEM);
+
+	info->uctx_caps = bnxtctl_uctx->uctx_caps;
+
+	*length = sizeof(*info);
+	return info;
+}
+
+static bool bnxtctl_validate_rpc(struct bnxt_en_dev *edev,
+				 struct bnxt_fw_msg *hwrm_in,
+				 enum fwctl_rpc_scope scope)
+{
+	struct input *req = (struct input *)hwrm_in->msg;
+
+	guard(mutex)(&edev->en_dev_lock);
+	if (edev->flags & BNXT_EN_FLAG_ULP_STOPPED)
+		return false;
+
+	switch (le16_to_cpu(req->req_type)) {
+	case HWRM_FUNC_RESET:
+	case HWRM_PORT_CLR_STATS:
+	case HWRM_FW_SET_STRUCTURED_DATA:
+	case HWRM_PORT_PRBS_TEST:
+	case HWRM_FW_LIVEPATCH:
+	case HWRM_FW_RESET:
+	case HWRM_FW_SYNC:
+	case HWRM_FW_SET_TIME:
+	case HWRM_MFG_TESTS:
+	case HWRM_DBG_SERDES_TEST:
+	case HWRM_DBG_LOG_BUFFER_FLUSH:
+	case HWRM_DBG_DUMP:
+	case HWRM_DBG_ERASE_NVM:
+	case HWRM_DBG_CFG:
+	case HWRM_DBG_COREDUMP_LIST:
+	case HWRM_DBG_COREDUMP_INITIATE:
+	case HWRM_DBG_COREDUMP_RETRIEVE:
+	case HWRM_DBG_CRASHDUMP_HEADER:
+	case HWRM_DBG_CRASHDUMP_ERASE:
+	case HWRM_DBG_PTRACE:
+	case HWRM_DBG_TOKEN_CFG:
+	case HWRM_NVM_DEFRAG:
+	case HWRM_NVM_FACTORY_DEFAULTS:
+	case HWRM_NVM_FLUSH:
+	case HWRM_NVM_INSTALL_UPDATE:
+	case HWRM_NVM_MODIFY:
+	case HWRM_NVM_VERIFY_UPDATE:
+	case HWRM_NVM_ERASE_DIR_ENTRY:
+	case HWRM_NVM_MOD_DIR_ENTRY:
+	case HWRM_NVM_FIND_DIR_ENTRY:
+	case HWRM_NVM_RAW_DUMP:
+		return scope >= FWCTL_RPC_CONFIGURATION;
+
+	case HWRM_VER_GET:
+	case HWRM_FW_GET_STRUCTURED_DATA:
+	case HWRM_ERROR_RECOVERY_QCFG:
+	case HWRM_FUNC_QCAPS:
+	case HWRM_FUNC_QCFG:
+	case HWRM_FUNC_QSTATS:
+	case HWRM_PORT_QSTATS:
+	case HWRM_PORT_PHY_QCFG:
+	case HWRM_PORT_MAC_QCFG:
+	case HWRM_PORT_PHY_QCAPS:
+	case HWRM_PORT_PHY_I2C_READ:
+	case HWRM_PORT_PHY_MDIO_READ:
+	case HWRM_QUEUE_PRI2COS_QCFG:
+	case HWRM_QUEUE_COS2BW_QCFG:
+	case HWRM_QUEUE_DSCP2PRI_QCFG:
+	case HWRM_VNIC_RSS_QCFG:
+	case HWRM_QUEUE_GLOBAL_QCFG:
+	case HWRM_QUEUE_ADPTV_QOS_RX_FEATURE_QCFG:
+	case HWRM_QUEUE_ADPTV_QOS_TX_FEATURE_QCFG:
+	case HWRM_QUEUE_QCAPS:
+	case HWRM_QUEUE_ADPTV_QOS_RX_TUNING_QCFG:
+	case HWRM_QUEUE_ADPTV_QOS_TX_TUNING_QCFG:
+	case HWRM_TUNNEL_DST_PORT_QUERY:
+	case HWRM_PORT_QSTATS_EXT:
+	case HWRM_PORT_TX_FIR_QCFG:
+	case HWRM_FW_LIVEPATCH_QUERY:
+	case HWRM_FW_QSTATUS:
+	case HWRM_FW_HEALTH_CHECK:
+	case HWRM_FW_GET_TIME:
+	case HWRM_PORT_DSC_DUMP:
+	case HWRM_PORT_EP_TX_QCFG:
+	case HWRM_PORT_QCFG:
+	case HWRM_PORT_MAC_QCAPS:
+	case HWRM_TEMP_MONITOR_QUERY:
+	case HWRM_REG_POWER_QUERY:
+	case HWRM_CORE_FREQUENCY_QUERY:
+	case HWRM_STAT_QUERY_ROCE_STATS:
+	case HWRM_STAT_QUERY_ROCE_STATS_EXT:
+	case HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE:
+	case HWRM_CFA_FLOW_INFO:
+	case HWRM_CFA_ADV_FLOW_MGNT_QCAPS:
+	case HWRM_FUNC_RESOURCE_QCAPS:
+	case HWRM_FUNC_BACKING_STORE_QCAPS:
+	case HWRM_FUNC_BACKING_STORE_QCFG:
+	case HWRM_FUNC_QSTATS_EXT:
+	case HWRM_FUNC_PTP_PIN_QCFG:
+	case HWRM_FUNC_PTP_EXT_QCFG:
+	case HWRM_FUNC_BACKING_STORE_QCFG_V2:
+	case HWRM_FUNC_BACKING_STORE_QCAPS_V2:
+	case HWRM_FUNC_SYNCE_QCFG:
+	case HWRM_FUNC_TTX_PACING_RATE_PROF_QUERY:
+	case HWRM_PCIE_QSTATS:
+	case HWRM_MFG_OTP_QCFG:
+	case HWRM_MFG_FRU_EEPROM_READ:
+	case HWRM_MFG_GET_NVM_MEASUREMENT:
+	case HWRM_STAT_GENERIC_QSTATS:
+	case HWRM_PORT_PHY_FDRSTAT:
+	case HWRM_QUEUE_ADPTV_QOS_RX_QCFG:
+	case HWRM_QUEUE_ADPTV_QOS_TX_QCFG:
+	case HWRM_DBG_READ_DIRECT:
+	case HWRM_DBG_READ_INDIRECT:
+	case HWRM_DBG_RING_INFO_GET:
+	case HWRM_DBG_QCAPS:
+	case HWRM_DBG_QCFG:
+	case HWRM_DBG_USEQ_FLUSH:
+	case HWRM_DBG_USEQ_QCAPS:
+	case HWRM_DBG_SIM_CABLE_STATE:
+	case HWRM_DBG_TOKEN_QUERY_AUTH_IDS:
+	case HWRM_NVM_GET_VARIABLE:
+	case HWRM_NVM_GET_DEV_INFO:
+	case HWRM_NVM_GET_DIR_ENTRIES:
+	case HWRM_NVM_GET_DIR_INFO:
+	case HWRM_NVM_READ:
+	case HWRM_SELFTEST_QLIST:
+	case HWRM_SELFTEST_RETRIEVE_SERDES_DATA:
+		return scope >= FWCTL_RPC_DEBUG_READ_ONLY;
+
+	case HWRM_PORT_PHY_I2C_WRITE:
+	case HWRM_MFG_FRU_WRITE_CONTROL:
+	case HWRM_MFG_FRU_EEPROM_WRITE:
+	case HWRM_DBG_WRITE_DIRECT:
+	case HWRM_NVM_SET_VARIABLE:

drivers/fwctl/bnxt/main.c line 192

Quoted 10 lines
drivers/fwctl/bnxt/main.c new file +10 -0
+	case HWRM_NVM_WRITE:
+	case HWRM_NVM_RAW_WRITE_BLK:
+	case HWRM_PORT_PHY_MDIO_WRITE:
+		return scope >= FWCTL_RPC_DEBUG_WRITE;
+
+	default:
+		return false;
+	}
+}
+

Can the DMA direction be derived from the scope of the command ? maybe this will simplify the command dma setup, see below comment.

Quoted 101 lines
drivers/fwctl/bnxt/main.c new file +101 -0
+static int bnxt_fw_setup_input_dma(struct bnxtctl_dev *bnxt_dev,
+				   struct device *dev,
+				   struct fwctl_dma_info_bnxt *msg,
+				   struct bnxt_fw_msg *fw_msg,
+				   int num_dma,
+				   void **dma_virt_addr,
+				   dma_addr_t *dma_addr)
+{
+	struct fwctl_dma_info_bnxt *dma_buf = msg;
+	u8 i, num_allocated = 0;
+	void *dma_ptr;
+	int rc;
+
+	for (i = 0; i < num_dma; i++) {
+		if (msg->len == 0 || msg->len > MAX_DMA_MEM_SIZE) {
+			rc = -EINVAL;
+			goto err;
+		}
+		dma_virt_addr[i] = dma_alloc_coherent(dev->parent, msg->len,
+						      &dma_addr[i], GFP_KERNEL);
+		if (!dma_virt_addr[i]) {
+			rc = -ENOMEM;
+			goto err;
+		}
+		num_allocated++;
+		if (msg->dma_direction == DEVICE_WRITE) {
+			if (copy_from_user(dma_virt_addr[i],
+					   u64_to_user_ptr(msg->data),
+					   msg->len)) {
+				rc = -EFAULT;
+				goto err;
+			}
+		}
+		dma_ptr = fw_msg->msg + msg->offset;
+
+		if (!(PTR_ALIGN(dma_ptr, 8) == dma_ptr) ||
+		    msg->offset >= fw_msg->msg_len) {
+			rc = -EINVAL;
+			goto err;
+		}
+
+		*(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);
+		msg++;
+	}
+
+	return 0;
+err:
+	for (i = 0; i < num_allocated; i++)
+		dma_free_coherent(dev->parent, dma_buf[i].len,
+				  dma_virt_addr[i], dma_addr[i]);
+
+	return rc;
+}
+
+static void *bnxtctl_fw_rpc(struct fwctl_uctx *uctx,
+			    enum fwctl_rpc_scope scope,
+			    void *in, size_t in_len, size_t *out_len)
+{
+	struct bnxtctl_dev *bnxtctl =
+		container_of(uctx->fwctl, struct bnxtctl_dev, fwctl);
+	struct bnxt_aux_priv *bnxt_aux_priv = bnxtctl->aux_priv;
+	void *dma_virt_addr[MAX_NUM_DMA_INDICATIONS];
+	dma_addr_t dma_addr[MAX_NUM_DMA_INDICATIONS];
+	struct fwctl_dma_info_bnxt *dma_buf = NULL;
+	struct device *dev = &uctx->fwctl->dev;
+	struct fwctl_rpc_bnxt *msg = in;
+	struct bnxt_fw_msg rpc_in = {0};
+	int i, rc, err = 0;
+
+	rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
+	if (IS_ERR(rpc_in.msg))
+		return rpc_in.msg;
+
+	if (!bnxtctl_validate_rpc(bnxt_aux_priv->edev, &rpc_in, scope)) {
+		err = -EPERM;
+		goto free_msg_out;
+	}
+
+	rpc_in.msg_len = msg->req_len;
+	rpc_in.resp = kzalloc(*out_len, GFP_KERNEL);
+	if (!rpc_in.resp) {
+		err = -ENOMEM;
+		goto free_msg_out;
+	}
+
+	rpc_in.resp_max_len = *out_len;
+	if (!msg->timeout)
+		rpc_in.timeout = DFLT_HWRM_CMD_TIMEOUT;
+	else
+		rpc_in.timeout = msg->timeout;
+
+	if (msg->num_dma) {
+		if (msg->num_dma > MAX_NUM_DMA_INDICATIONS) {
+			dev_err(dev, "DMA buffers exceed the number supported\n");
+			err = -EINVAL;
+			goto free_msg_out;
+		}
+
+		dma_buf = kcalloc(msg->num_dma, sizeof(*dma_buf), GFP_KERNEL);
+		if (!dma_buf) {
+			err = -ENOMEM;

drivers/fwctl/bnxt/main.c line 303

Quoted 10 lines
drivers/fwctl/bnxt/main.c new file +10 -0
+			goto free_msg_out;
+		}
+
+		if (copy_from_user(dma_buf, u64_to_user_ptr(msg->payload),
+				   msg->num_dma * sizeof(*dma_buf))) {
+			dev_dbg(dev, "Failed to copy payload from user\n");
+			err = -EFAULT;
+			goto free_dmabuf_out;
+		}
+

I find it a bit weird that the user needs to provide dma information and structure ! this is supposed to be completely hidden by the driver to simplify user space, the driver handles dma and access to HW, user space just provides the commands and payloads and driver carries the input/output for that user space.

Also setting up a large enough DMA buffer only initially on uctx open could be beneficial in your case and align better with fwctl usecases.

Quoted 121 lines
drivers/fwctl/bnxt/main.c new file +113 -0
+		err = bnxt_fw_setup_input_dma(bnxtctl, dev, dma_buf, &rpc_in,
+					      msg->num_dma, &dma_virt_addr[0],
+					      &dma_addr[0]);
+		if (err)
+			goto free_dmabuf_out;
+	}
+
+	rc = bnxt_send_msg(bnxt_aux_priv->edev, &rpc_in);
+	if (rc) {
+		struct output *resp = rpc_in.resp;
+
+		/* Copy the response to user always, as it contains
+		 * detailed status of the command failure
+		 */
+		if (!resp->error_code)
+			/* bnxt_send_msg() returned much before FW
+			 * received the command.
+			 */
+			resp->error_code = rc;
+
+		goto free_dma_out;
+	}
+
+	for (i = 0; i < msg->num_dma; i++) {
+		if (dma_buf[i].dma_direction != DEVICE_READ)
+			continue;
+		if (copy_to_user(u64_to_user_ptr(dma_buf[i].data),
+				 dma_virt_addr[i], dma_buf[i].len)) {
+			dev_dbg(dev, "Failed to copy resp to user\n");
+			err = -EFAULT;
+			break;
+		}
+	}
+free_dma_out:
+	/* Cleanup any dma memory that bnxt_fw_setup_input_dma() may have
+	 * allocated
+	 */
+	for (i = 0; i < msg->num_dma; i++)
+		dma_free_coherent(dev->parent, dma_buf[i].len, dma_virt_addr[i],
+				  dma_addr[i]);
+free_dmabuf_out:
+	kfree(dma_buf);
+free_msg_out:
+	kfree(rpc_in.msg);
+
+	if (err) {
+		kfree(rpc_in.resp);
+		return ERR_PTR(err);
+	}
+
+	return rpc_in.resp;
+}
+
+static const struct fwctl_ops bnxtctl_ops = {
+	.device_type = FWCTL_DEVICE_TYPE_BNXT,
+	.uctx_size = sizeof(struct bnxtctl_uctx),
+	.open_uctx = bnxtctl_open_uctx,
+	.close_uctx = bnxtctl_close_uctx,
+	.info = bnxtctl_info,
+	.fw_rpc = bnxtctl_fw_rpc,
+};
+
+static int bnxtctl_probe(struct auxiliary_device *adev,
+			 const struct auxiliary_device_id *id)
+{
+	struct bnxt_aux_priv *aux_priv =
+		container_of(adev, struct bnxt_aux_priv, aux_dev);
+	struct bnxtctl_dev *bnxtctl __free(bnxtctl) =
+		fwctl_alloc_device(&aux_priv->edev->pdev->dev, &bnxtctl_ops,
+				   struct bnxtctl_dev, fwctl);
+	int rc;
+
+	if (!bnxtctl)
+		return -ENOMEM;
+
+	bnxtctl->aux_priv = aux_priv;
+
+	rc = fwctl_register(&bnxtctl->fwctl);
+	if (rc)
+		return rc;
+
+	auxiliary_set_drvdata(adev, no_free_ptr(bnxtctl));
+	return 0;
+}
+
+static void bnxtctl_remove(struct auxiliary_device *adev)
+{
+	struct bnxtctl_dev *ctldev = auxiliary_get_drvdata(adev);
+
+	fwctl_unregister(&ctldev->fwctl);
+	fwctl_put(&ctldev->fwctl);
+}
+
+static const struct auxiliary_device_id bnxtctl_id_table[] = {
+	{ .name = "bnxt_en.fwctl", },
+	{}
+};
+MODULE_DEVICE_TABLE(auxiliary, bnxtctl_id_table);
+
+static struct auxiliary_driver bnxtctl_driver = {
+	.name = "bnxt_fwctl",
+	.probe = bnxtctl_probe,
+	.remove = bnxtctl_remove,
+	.id_table = bnxtctl_id_table,
+};
+
+module_auxiliary_driver(bnxtctl_driver);
+
+MODULE_IMPORT_NS("FWCTL");
+MODULE_DESCRIPTION("BNXT fwctl driver");
+MODULE_AUTHOR("Pavan Chebbi <[email protected]>");
+MODULE_AUTHOR("Andy Gospodarek <[email protected]>");
+MODULE_LICENSE("GPL");
include/uapi/fwctl/bnxt.h new file +2 -0
new file mode 100644
index 000000000000..5620812d839c
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*

include/uapi/fwctl/bnxt.h line 12

Quoted 10 lines
include/uapi/fwctl/bnxt.h new file +10 -0
+ * Copyright (c) 2026, Broadcom Inc
+ */
+
+#ifndef _UAPI_FWCTL_BNXT_H_
+#define _UAPI_FWCTL_BNXT_H_
+
+#include <linux/types.h>
+
+#define MAX_DMA_MEM_SIZE		0x10000 /*64K*/
+#define DFLT_HWRM_CMD_TIMEOUT		500  

unit?

Quoted 31 lines
include/uapi/fwctl/bnxt.h new file +31 -0
+#define DEVICE_WRITE			0
+#define DEVICE_READ			1
+
+enum fwctl_bnxt_commands {
+	FWCTL_BNXT_QUERY_COMMANDS = 0,
+	FWCTL_BNXT_SEND_COMMAND,
+};
+
+/**
+ * struct fwctl_info_bnxt - ioctl(FWCTL_INFO) out_device_data
+ * @uctx_caps: The command capabilities driver accepts.
+ *
+ * Return basic information about the FW interface available.
+ */
+struct fwctl_info_bnxt {
+	__u32 uctx_caps;
+};
+
+#define MAX_NUM_DMA_INDICATIONS 10
+
+/**
+ * struct fwctl_dma_info_bnxt - describe the buffer that should be DMAed
+ * @data: DMA-intended buffer
+ * @len: length of the @data
+ * @offset: offset at which FW (HWRM) input structure needs DMA address
+ * @dma_direction: DMA direction, DEVICE_READ or DEVICE_WRITE
+ * @unused: pad
+ */
+struct fwctl_dma_info_bnxt {
+	__aligned_u64 data;
+	__u32 len;

include/uapi/fwctl/bnxt.h line 53

Quoted 10 lines
include/uapi/fwctl/bnxt.h new file +10 -0
+	__u16 offset;
+	__u8 dma_direction;
+	__u8 unused;
+};
+
+/**
+ * struct fwctl_rpc_bnxt - describe the fwctl message for bnxt
+ * @req: FW (HWRM) command input structure
+ * @req_len: length of @req
+ * @timeout: if the user wants to override the driver's default, 0 otherwise

What unit ? Also there is a define in the driver (TIMOUT=500); not clear what unit.

include/uapi/fwctl/bnxt.h line 56

Quoted 3 lines
include/uapi/fwctl/bnxt.h new file +3 -0
+ * @num_dma: number of DMA buffers to be added to @req
+ * @payload: DMA buffer details in struct fwctl_dma_info_bnxt format
+ */

if payload is a well known format, why not inline ? or why not combine req and payload into one buffer and let the kernel handle the rest. Just not sure how you HW interface works, so maybe once you explain the previous comment this would make some sense ?

Quoted 23 lines
include/uapi/fwctl/bnxt.h new file +8 -0
+struct fwctl_rpc_bnxt {
+	__aligned_u64 req;
+	__u32 req_len;
+	__u32 timeout;
+	__u32 num_dma;
+	__aligned_u64 payload;
+};
+#endif
include/uapi/fwctl/fwctl.h +1 -0
index 716ac0eee42d..2d6d4049c205 100644
@@ -44,6 +44,7 @@ enum fwctl_device_type {
 	FWCTL_DEVICE_TYPE_ERROR = 0,
 	FWCTL_DEVICE_TYPE_MLX5 = 1,
 	FWCTL_DEVICE_TYPE_CXL = 2,
+	FWCTL_DEVICE_TYPE_BNXT = 3,
 	FWCTL_DEVICE_TYPE_PDS = 4,
 };
 
Signature · 1 line
2.39.1
author maintainer
#15 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 6 lines

I find it a bit weird that the user needs to provide dma information and structure ! this is supposed to be completely hidden by the driver to simplify user space, the driver handles dma and access to HW, user space just provides the commands and payloads and driver carries the input/output for that user space.

This is so because our FW commands require optional DMA-able buffers. The application is only giving us the information that the driver should encapsulate in additional DMA-able buffers.
There is a defined format for exchange of this information, because every command has a different number of additional buffers. Also the majority of the commands don't need any additional buffers. I hope this answers your next comments also.

Quoted 4 lines

Also setting up a large enough DMA buffer only initially on uctx open could be beneficial in your case and align better with fwctl usecases.

<-->

Quoted 8 lines
Quoted 5 lines

+/**
+ * struct fwctl_rpc_bnxt - describe the fwctl message for bnxt
+ * @req: FW (HWRM) command input structure
+ * @req_len: length of @req
+ * @timeout: if the user wants to override the driver's default, 0 otherwise

What unit ? Also there is a define in the driver (TIMOUT=500); not clear what unit.

Its milliseconds. I can update.

Quoted 10 lines
Quoted 4 lines

+ * @num_dma: number of DMA buffers to be added to @req
+ * @payload: DMA buffer details in struct fwctl_dma_info_bnxt format
+ */

if payload is a well known format, why not inline ? or why not combine req and payload into one buffer and let the kernel handle the rest. Just not sure how you HW interface works, so maybe once you explain the previous comment this would make some sense ?

author maintainer
#16 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 29 lines · Pavan Chebbi
Quoted 7 lines

I find it a bit weird that the user needs to provide dma information and structure ! this is supposed to be completely hidden by the driver to simplify user space, the driver handles dma and access to HW, user space just provides the commands and payloads and driver carries the input/output for that user space.

This is so because our FW commands require optional DMA-able buffers. The application is only giving us the information that the driver should encapsulate in additional DMA-able buffers.
There is a defined format for exchange of this information, because every command has a different number of additional buffers. Also the majority of the commands don't need any additional buffers. I hope this answers your next comments also.

Quoted 4 lines

Also setting up a large enough DMA buffer only initially on uctx open could be beneficial in your case and align better with fwctl usecases.

<-->

Quoted 6 lines
Quoted 5 lines

+/**
+ * struct fwctl_rpc_bnxt - describe the fwctl message for bnxt
+ * @req: FW (HWRM) command input structure
+ * @req_len: length of @req
+ * @timeout: if the user wants to override the driver's default, 0 otherwise

Quoted 4 lines
Quoted 2 lines

What unit ? Also there is a define in the driver (TIMOUT=500); not clear what unit.

Its milliseconds. I can update.

Saeed, if you are satisfied with my replies, can I make this comment update as a fix later?
If that is fine, I wish that this series be pulled in. (this email is on v3. There is v4)
The complete ulp callbacks cleanup, which are more roce driver centric, will be posted as a separate series as I explained in the other email.

Quoted 11 lines
Quoted 11 lines
Quoted 5 lines

+ * @num_dma: number of DMA buffers to be added to @req
+ * @payload: DMA buffer details in struct fwctl_dma_info_bnxt format
+ */

if payload is a well known format, why not inline ? or why not combine req and payload into one buffer and let the kernel handle the rest. Just not sure how you HW interface works, so maybe once you explain the previous comment this would make some sense ?

#17 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

In reply to Pavan Chebbi
Quoted 7 lines · Pavan Chebbi
Quoted 6 lines

I find it a bit weird that the user needs to provide dma information and structure ! this is supposed to be completely hidden by the driver to simplify user space, the driver handles dma and access to HW, user space just provides the commands and payloads and driver carries the input/output for that user space.

Quoted 7 lines

This is so because our FW commands require optional DMA-able buffers. The application is only giving us the information that the driver should encapsulate in additional DMA-able buffers.
There is a defined format for exchange of this information, because every command has a different number of additional buffers. Also the majority of the commands don't need any additional buffers. I hope this answers your next comments also.

Now I have questions, who allocates these buffers, how do they get DMA mapped, who does all the copying??

Jason

#18 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 4 lines · Jason Gunthorpe
Quoted 2 lines · Pavan Chebbi
Quoted 2 lines

I find it a bit weird that the user needs to provide dma information

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

structure ! this is supposed to be completely hidden by the driver to simplify user space, the driver handles dma and access to HW, user

space

Quoted 1 line
Quoted 1 line
Quoted 1 line

just provides the commands and payloads and driver carries the

input/output

Quoted 10 lines
Quoted 9 lines
Quoted 1 line

for that user space.

This is so because our FW commands require optional DMA-able buffers. The application is only giving us the information that the driver should encapsulate in additional DMA-able buffers.
There is a defined format for exchange of this information, because every command has a different number of additional buffers. Also the majority of the commands don't need any additional buffers. I hope this answers your next comments also.

Quoted 3 lines

Now I have questions, who allocates these buffers, how do they get DMA mapped, who does all the copying??

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

#19 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

+	rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg

+ dma_ptr = fw_msg->msg + msg->offset;
+ *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

IOW this is a *HUGE* security error!

You are going to struggle very much supporting this kind of ill suited FW API through this interface, I think you need to rework the FW protocol...

Or add some very complex kernel validation and do something about forward compatibility...

Or only support commands the FW promises will never have a DMA address in them.

Shouldn't you guys have caught this during your security review? "don't DMA to random memory" is a very clear fundamental thing in the fwctl rules!

Jason

#20 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 20 lines · Jason Gunthorpe
Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

drivers/fwctl/bnxt/main.c new file +3 -0
+       rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg
+               dma_ptr = fw_msg->msg + msg->offset;
+               *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Quoted 7 lines

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

IOW this is a *HUGE* security error!

I'll let Pavan chime in when he sees this, but I'm not sure that's correct. You might be right that we have a problem that is as bad as you describe, but it's also possible we could do a better job explaining how these DMA operations work and why they are needed.

Not every FW RPC will need to have chunks of data that is copied to or from userspace to FW. In the cases where data is copied, there is not a direct DMA from userspace to FW or vice-versa. All DMA operations should be done on buffers only allocated and mapped with dma_alloc_coherent -- never buffers or addresses that are straight from userspace.

As I read through these again, I realize that what might have made these easier to read would be simply changing the names of a few of these structures when they are really just buffers being copied between user and kernel space -- not buffers that are actually being DMAed from hardware to userspace.

#21 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 26 lines · Andy Gospodarek
Quoted 25 lines · Jason Gunthorpe
Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

(quoted diff) +3 -0
+       rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg
+               dma_ptr = fw_msg->msg + msg->offset;
+               *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

Quoted 7 lines
Quoted 2 lines

IOW this is a *HUGE* security error!

I'll let Pavan chime in when he sees this, but I'm not sure that's correct. You might be right that we have a problem that is as bad as you describe, but it's also possible we could do a better job explaining how these DMA operations work and why they are needed.

I think it is pretty clear, the DMA addreses are being read by FW from the same memory buffer that the userspace fully controls.

Look at the code, the design takes an offset list from userspace and patches in DMA addresses from the kernel into the same buffer that the userspace data was copied from.

NOTHING is checking that the offset list is security acceptable for the command!!

Quoted 5 lines

As I read through these again, I realize that what might have made these easier to read would be simply changing the names of a few of these structures when they are really just buffers being copied between user and kernel space -- not buffers that are actually being DMAed from hardware to userspace.

I understand how the buffer copying works on the happy path, I am pointing out that if the user submits a command that has

+struct fwctl_rpc_bnxt {
+ __aligned_u64 req;
+ __u32 req_len;
+ __u32 timeout;

+	__u32 num_dma;
          ^^^^^^^^^^^

=== 0

then the kernel doesn't even allocate any of these DMA buffers, it doesn't change the command buffer and it sends raw userspace data directly to FW.

Since that very same command buffer obviously contains the DMA addresses to use there is nothing blocking userspace from doing this.

Stated another way, the kernel must NOT take in

+struct fwctl_dma_info_bnxt {
+ __aligned_u64 data;
+ __u32 len;

+	__u16 offset;
            ^^^^^^^

This parameter from userspace! The kernel MUST know exactly where all DMA addresses lie in the message now and into the future to guarentee that it and only it writes a DMA address of the kernel controlled DMA bounce buffer.

Allowing a userspace controlled DMA address to pass into the device directly from userspace is a complete security fail.

Jason

author maintainer
#22 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 79 lines · Jason Gunthorpe
Quoted 26 lines · Andy Gospodarek
Quoted 25 lines · Jason Gunthorpe
Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

(quoted diff) +3 -0
+       rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg
+               dma_ptr = fw_msg->msg + msg->offset;
+               *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

Quoted 7 lines
Quoted 2 lines

IOW this is a *HUGE* security error!

I'll let Pavan chime in when he sees this, but I'm not sure that's correct. You might be right that we have a problem that is as bad as you describe, but it's also possible we could do a better job explaining how these DMA operations work and why they are needed.

I think it is pretty clear, the DMA addreses are being read by FW from the same memory buffer that the userspace fully controls.

Look at the code, the design takes an offset list from userspace and patches in DMA addresses from the kernel into the same buffer that the userspace data was copied from.

NOTHING is checking that the offset list is security acceptable for the command!!

Quoted 5 lines

As I read through these again, I realize that what might have made these easier to read would be simply changing the names of a few of these structures when they are really just buffers being copied between user and kernel space -- not buffers that are actually being DMAed from hardware to userspace.

I understand how the buffer copying works on the happy path, I am pointing out that if the user submits a command that has

(quoted diff) +5 -0
+struct fwctl_rpc_bnxt {
+       __aligned_u64 req;
+       __u32 req_len;
+       __u32 timeout;
+       __u32 num_dma;
          ^^^^^^^^^^^

=== 0

then the kernel doesn't even allocate any of these DMA buffers, it doesn't change the command buffer and it sends raw userspace data directly to FW.

Since that very same command buffer obviously contains the DMA addresses to use there is nothing blocking userspace from doing this.

Stated another way, the kernel must NOT take in

(quoted diff) +4 -0
+struct fwctl_dma_info_bnxt {
+       __aligned_u64 data;
+       __u32 len;
+       __u16 offset;
            ^^^^^^^
Quoted 7 lines

This parameter from userspace! The kernel MUST know exactly where all DMA addresses lie in the message now and into the future to guarentee that it and only it writes a DMA address of the kernel controlled DMA bounce buffer.

Allowing a userspace controlled DMA address to pass into the device directly from userspace is a complete security fail.

I think its important to quickly clarify the mechanism lest the whole thing adds more questions.
Let me explain with an example as to how its happening. I am sure its the case of naming the struct as *dma* info that is freaking everyone out.
When a user has no additional host buffers to add to a FW command, it just sets the num_dma = 0. At that time, req member of struct fwctl_rpc_bnxt has the entire user buffer to carry FW command i/p and o/p.

Sometimes a FW command needs a separate additional host buffers beyond the input message. The input message will carry the address at which additional host buffers are found.
Example is a command like below where FW will return additional data in a separate tx_stat_host_addr and rx_stat_host_addr

struct hwrm_port_qstats_input {
        __le16 req_type;
        __le16 cmpl_ring;
        __le16 seq_id;
        __le16 target_id;
        __le64 resp_addr;
        __le16 port_id;
        u8 flags;
        u8 unused_0[5];
        __le64 tx_stat_host_addr;
       __le64 rx_stat_host_addr;
};

Now the user will tell driver that this FW command has two additional host buffers that driver needs to supply to FW. So it will say num_dma = 2 in the rpc message. And describe each additional buffer so that driver can allocate dma_alloc_coherent memory for it.
FW command expects the DMA-able buffers' address be present at 'tx_stat_host_addr' and 'rx_stat_host_addr' fields of hwrm_port_qstats_input. Here is where 'offset' comes into the picture. In the above example, user is only telling the driver, offset of '__le64 tx_stat_host_addr' in the input structure, using the 'offset' field of the additional buffer description.

Does that make the mechanism clear...

Quoted 2 lines

Jason

#23 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 1 line · Pavan Chebbi

Does that make the mechanism clear...

Nothing you have explained is different than how I understand it.

You clearly haven't understood what I'm explaining, please read both my messages over several times until you get it.

I will help you one last time.

User uses this command:

struct hwrm_port_qstats_input {
        __le16 req_type;
        __le16 cmpl_ring;
        __le16 seq_id;
        __le16 target_id;
        __le64 resp_addr;
        __le16 port_id;
        u8 flags;
        u8 unused_0[5];
        __le64 tx_stat_host_addr;
       __le64 rx_stat_host_addr;
};

It sends the command buffer with tx_stat_host_addr set to 0xBAD

It sets num_dma = 0.

Explain what happens.

Jason

author maintainer
#24 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

In reply to Jason Gunthorpe
Quoted 17 lines · Jason Gunthorpe
Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

drivers/fwctl/bnxt/main.c new file +3 -0
+       rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg
+               dma_ptr = fw_msg->msg + msg->offset;
+               *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

Quoted 8 lines

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

Reading this while I am fully awake helps me grapple with the point you are making.
Yes, this hole does exist. Thanks for bringing this out.

Quoted 6 lines

IOW this is a *HUGE* security error!

You are going to struggle very much supporting this kind of ill suited FW API through this interface, I think you need to rework the FW protocol...

Quoted 6 lines

Or add some very complex kernel validation and do something about forward compatibility...

Or only support commands the FW promises will never have a DMA address in them.

Or have the driver maintain some sort of look up table where it validates num_dmas and their offsets for each command it supports, and reject user commands which don't map...

Quoted 5 lines

Shouldn't you guys have caught this during your security review? "don't DMA to random memory" is a very clear fundamental thing in the fwctl rules!

Jason

#25 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

Quoted 28 lines · Pavan Chebbi
Quoted 17 lines · Jason Gunthorpe
Quoted 2 lines · Andy Gospodarek

Jason, this is all done in bnxtctl_fw_rpc() and the functions it calls in this (or the v4 version) of this patch.

Oh.. No.. You can't do this:

(quoted diff) +3 -0
+       rpc_in.msg = memdup_user(u64_to_user_ptr(msg->req), msg->req_len);
         // ^^ eventually becomes fw_msg
+               dma_ptr = fw_msg->msg + msg->offset;
+               *(__le64 *)(dma_ptr) = cpu_to_le64(dma_addr[i]);

There is nothing in here which ensures that every DMA physical address in the mailbox given from userspace is *actually forced to a value by the kernel*

Quoted 8 lines

The kernel only overwrites values from the user controlled struct fwctl_dma_info_bnxt array.

Meaning userspace can just specify any physical address in the message, not include any fwctl_dma_info_bnxt list and it will happily send the user controlled physical address to the FW. Thus userspace can DMA to whatever memory it likes.

Quoted 4 lines

Reading this while I am fully awake helps me grapple with the point you are making.
Yes, this hole does exist. Thanks for bringing this out.

Totally agree with you, Pavan. Thanks for catching this, Jason.

Classic case of a vendor being 'too familiar' with their code. When working directly with hardware like fwctl allows, we all need to be careful with new operations as well as modifications to existing operations once they are upstream.

author maintainer
#26 lore raw

Re: [PATCH v3 fwctl 4/5] fwctl/bnxt_fwctl: Add bnxt fwctl device

In reply to Jason Gunthorpe
Quoted 10 lines

You are going to struggle very much supporting this kind of ill suited FW API through this interface, I think you need to rework the FW protocol...

Or add some very complex kernel validation and do something about forward compatibility...

Or only support commands the FW promises will never have a DMA address in them.

Hello Jason, I will send the next revision removing the support for any DMA capable commands.
We are working to add some infrastructure to our FW interface which we may use to validate and address the direct access concerns. I will add the DMA capable commands' support as a separate patch once that is ready and that will also be easy to review.

author maintainer
#27 lore raw

PATCH v3 5/5 fwctl/bnxt_fwctl: Add documentation entries

In reply to Pavan Chebbi

Add bnxt_fwctl to the driver and fwctl documentation pages.

---
 .../userspace-api/fwctl/bnxt_fwctl.rst        | 83 +++++++++++++++++++
 Documentation/userspace-api/fwctl/fwctl.rst   |  1 +
 Documentation/userspace-api/fwctl/index.rst   |  1 +
 3 files changed, 85 insertions(+)
 create mode 100644 Documentation/userspace-api/fwctl/bnxt_fwctl.rst
Documentation/userspace-api/fwctl/bnxt_fwctl.rst new file +83 -0
new file mode 100644
index 000000000000..41a74a085324
@@ -0,0 +1,83 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=================
+fwctl bnxt driver
+=================
+
+:Author: Pavan Chebbi
+
+Overview
+========
+
+BNXT driver makes a fwctl service available through an auxiliary_device.
+The bnxt_fwctl driver binds to this device and registers itself with the
+fwctl subsystem.
+
+The bnxt_fwctl driver is agnostic to the device firmware internals. It
+uses the Upper Layer Protocol (ULP) conduit provided by bnxt to send
+HardWare Resource Manager (HWRM) commands to firmware.
+
+These commands can query or change firmware driven device configurations
+and read/write registers that are useful for debugging.
+
+bnxt_fwctl User API
+===================
+
+Each RPC request contains a message request structure (HWRM input),
+its length, optional request timeout, and dma buffers' information
+if the command needs any DMA. The request is then put together with
+the request data and sent through bnxt's message queue to the firmware,
+and the results are returned to the caller.
+
+A typical user application can send a FWCTL_INFO command using ioctl()
+to discover bnxt_fwctl's RPC capabilities as shown below:
+
+        ioctl(fd, FWCTL_INFO, &fwctl_info_msg);
+
+where fwctl_info_msg (of type struct fwctl_info) describes bnxt_info_msg
+(of type struct fwctl_info_bnxt). fwctl_info_msg is set up as follows:
+
+        size = sizeof(struct fwctl_info);
+        flags = 0;
+        device_data_len = sizeof(bnxt_info_msg);
+        out_device_data = (__aligned_u64)&bnxt_info_msg;
+
+The uctx_caps of bnxt_info_msg represents the capabilities as described
+in fwctl_bnxt_commands of include/uapi/fwctl/bnxt.h
+
+The FW RPC itself, FWCTL_RPC can be sent using ioctl() as:
+
+        ioctl(fd, FWCTL_RPC, &fwctl_rpc_msg);
+
+where fwctl_rpc_msg (of type struct fwctl_rpc) encapsulates fwctl_rpc_bnxt
+(see bnxt_rpc_msg below). fwctl_rpc_bnxt members are set up as per the
+requirements of specific HWRM commands described in include/bnxt/hsi.h.
+An example for HWRM_VER_GET is shown below:
+
+        struct fwctl_rpc_bnxt bnxt_rpc_msg;
+        struct hwrm_ver_get_output resp;
+        struct fwctl_rpc fwctl_rpc_msg;
+        struct hwrm_ver_get_input req;
+
+        req.req_type = HWRM_VER_GET;
+        req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
+        req.hwrm_intf_min = HWRM_VERSION_MINOR;
+        req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
+        req.cmpl_ring = -1;
+        req.target_id = -1;
+
+        bnxt_rpc_msg.req_len = sizeof(struct hwrm_ver_get_input);
+        bnxt_rpc_msg.num_dma = 0;
+        bnxt_rpc_msg.req = (__aligned_u64)&req;
+
+        fwctl_rpc_msg.size = sizeof(struct fwctl_rpc);
+        fwctl_rpc_msg.scope = FWCTL_RPC_DEBUG_READ_ONLY;
+        fwctl_rpc_msg.in_len = sizeof(bnxt_rpc_msg) + sizeof(req);
+        fwctl_rpc_msg.out_len = sizeof(struct hwrm_ver_get_output);
+        fwctl_rpc_msg.in = (__aligned_u64)&bnxt_rpc_msg;
+        fwctl_rpc_msg.out = (__aligned_u64)&resp;
+
+An example python3 program that can exercise this interface can be found in
+the following git repository:
+
+https://github.com/Broadcom/fwctl-tools
Documentation/userspace-api/fwctl/fwctl.rst +1 -0
index a74eab8d14c6..826817bfd54d 100644
@@ -148,6 +148,7 @@ area resulting in clashes will be resolved in favour of a kernel implementation.
 fwctl User API
 ==============
 
+.. kernel-doc:: include/uapi/fwctl/bnxt.h
 .. kernel-doc:: include/uapi/fwctl/fwctl.h
 .. kernel-doc:: include/uapi/fwctl/mlx5.h
 .. kernel-doc:: include/uapi/fwctl/pds.h
Documentation/userspace-api/fwctl/index.rst +1 -0
index 316ac456ad3b..8062f7629654 100644
@@ -10,5 +10,6 @@ to securely construct and execute RPCs inside device firmware.
    :maxdepth: 1
 
    fwctl
+   bnxt_fwctl
    fwctl-cxl
    pds_fwctl
Signature · 1 line
2.39.1