Skip to contentSkip to conversation

nbl driver for Nebulamatrix NICs

PATCH Superseded illusion.wang 2 participants 27 messages Jul 23 – Jul 31

Subsystems (4)

v22 of 35 Superseded Latest is v35 →

lore
Share & tools
lore

illusion.wang

author maintainer
#0 lore raw

v22 cover nbl driver for Nebulamatrix NICs

From: illusion wang <[email protected]>

This patch series represents the first phase. We plan to integrate it in two phases: the first phase covers mailbox and chip configuration, while the second phase involves net dev configuration. Together, they will provide basic PF-based Ethernet port transmission and reception capabilities.

After that, we will consider other features, such as ethtool support, flow management, adminq messaging, VF support, debugfs support, etc.

To ensure compatibility, our architecture is divided into the following layers:

1. Dev Layer (Device Layer)
The top-level business logic layer where all operations are device-centric. Every operation is performed relative to the device context. The intergration of base functions encompasses:
management(ctrl only for leonis pf0), network(net_dev,this time not contained),common.

2. Dispatch Layer
The distribution from services to specific data operations is mainly divided into two types: direct pass-through and handling by the management PF. It shields the upper layer from the differences in specific underlying locations.
It describes the processing locations and paths of the services.

3. Resource Layer
Handles tasks dispatched from Dispatch Layer. These tasks fall into two categories:
3.1 Hardware control
The Resource Layer further invokes the HW Layer when hardware access is needed, as only the HW Layer has OS-level privileges.
3.2 Software resource management
Operations like packet statistics collection that don't require hardware access.

4. HW Layer (Hardware Layer)
Serves the Resource Layer by interacting with different hardware chipsets.Writes to hardware registers to drive the hardware based on Resource Layer directives.

5. Channel Layer

Handle communication between PF0(has ctrl func) and other PF,and provide basic interaction channels.

6. Common Layer
Provides fundamental services

chages v21->v22
Link to v21:https://lore.kernel.org/netdev/[email protected]/ AI review issues

changes v20->v21
Link to v20:https://lore.kernel.org/netdev/[email protected]/ I have dropped the old Patch 2 titled "add our driver architecture"
Add new Patch 2 "add core driver architecture and HW layer initialization".
Split original patch8 into three separate patches as suggested

changes v19->v20
Link to v19:https://lore.kernel.org/netdev/[email protected]/ Starting from V20, I have dropped the old Patch 3 titled "P4
configuration invoked during chip initialization". This functionality
will be reimplemented in next phase using the request_firmware() API
with an external firmware blob.
changes v18->v19
Link to v18:https://lore.kernel.org/netdev/[email protected]/ changes v17->v18
Link to v17:https://lore.kernel.org/netdev/[email protected]/ changes v16->v17
Link to v16:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v15->v16
Link to v15:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v14->v15
Link to v14:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v13->v14
Link to v13:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v12->v13
Link to v12:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v11->v12
Link to v11:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v10->v11
Link to v10:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Mohsin
2.AI review issues
changes v9->v10
Link to v9:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Jakub
2.AI review issue
changes v8->v9
Link to v8:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Jakub
2.AI review issue
Changes v7→v8
Link to v7:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Paolo
Changes v6->v7
Link to v6:https://lore.kernel.org/netdev/[email protected]/ 1.Issue found by Jakub
2.AI review issue
Changes v5->v6
Link to V5:https://lore.kernel.org/netdev/[email protected]/ 1.put all standard linux includes files the .c file which needs it & others --Andrew
2.AI review issue
Changes v4->v5
Link to V4:https://lore.kernel.org/netdev/[email protected]/ 1.change nbl_core to nbl & change ** pointers to *pointers & others
--Andrew
2.AI review issue
Changes v3->v4
Link to v3: https://lore.kernel.org/netdev/[email protected]
1.cut down to part of a mini driver(mailbox and chip init)
--Jakub Kicinski Simon Horman(some sort of staged approached)
2.modify issues found by ai.
3. Reverse Christmas tree/nbl_err/devm_kfree/remove some macros/
void type to real type/others
--Andrew Lunn
4.change deprecated pci_enable_msix_range to pci_alloc_irq_vectors
5.delete service layer
6.the style of kconfig---Randy Dunlap
7.add to Documentation/networking/device_drivers/ethernet/index.rst
--Simon Horman
Changes v2 →v3
Link to v2: https://lore.kernel.org/netdev/[email protected]/
1.cut down to a mini driver:
delete vf support
use promisc mode to cut down flow management
drop patch15 in v2
delete adminq msg
delete abnormal handling
delete some unimportant interfaces
2.modify issues found by ai review
Changes v1->v2
Link to v1: https://lore.kernel.org/netdev/[email protected]/
1.Format Issues and Compilation Issues
- Paolo Abeni
2.add sysfs patch and drop coexisting patch
- Andrew Lunn
3.delete some unimportant ndo operations
4.add machine generated headers patch
5.Modify the issues found in patch1-2 and apply the same fixes to other
patches
6.modify issues found by nipa

illusion wang (12):
net/nebula-matrix: add minimum nbl build framework net/nebula-matrix: add core driver architecture and HW layer
initialization
net/nebula-matrix: add channel wire opcode enum definitions net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add chip-wide hardware init/deinit implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: add cross-version channel message
framework
net/nebula-matrix: dispatch: add mutual exclusion lock for shared
hardware resource ops
net/nebula-matrix: add common/ctrl dev init/remove operation net/nebula-matrix: add common dev start/stop operation

 .../device_drivers/ethernet/index.rst         |    1 +
 .../ethernet/nebula-matrix/nbl.rst            |   28 +
 MAINTAINERS                                   |   10 +
 drivers/net/ethernet/Kconfig                  |    1 +
 drivers/net/ethernet/Makefile                 |    1 +
 drivers/net/ethernet/nebula-matrix/Kconfig    |   34 +
 drivers/net/ethernet/nebula-matrix/Makefile   |    6 +
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   15 +
 .../nbl/nbl_channel/nbl_channel.c             | 1095 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  174 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  209 ++++
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   29 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   56 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      |  491 ++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |   57 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c |  597 +++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |   42 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |   26 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |   12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 1015 +++++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  367 ++++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  295 +++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   12 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   73 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  |  335 +++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |   21 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   |  148 +++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  108 ++
 .../nbl/nbl_include/nbl_def_channel.h         |  372 ++++++
 .../nbl/nbl_include/nbl_def_common.h          |   71 ++
 .../nbl/nbl_include/nbl_def_dev.h             |   16 +
 .../nbl/nbl_include/nbl_def_dispatch.h        |   42 +
 .../nbl/nbl_include/nbl_def_hw.h              |   53 +
 .../nbl/nbl_include/nbl_def_resource.h        |   38 +
 .../nbl/nbl_include/nbl_include.h             |   70 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  255 ++++
 36 files changed, 6175 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst
 create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig
 create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v22 1/12 net/nebula-matrix: add minimum nbl build framework

From: illusion wang <[email protected]>

This patch adds the minimum build infrastructure:
1. Add Kconfig, Makefile and MAINTAINERS entries;
2. Add corresponding driver documentation;
3. Add PCI driver skeleton with empty stubs for nbl driver.

---
 .../device_drivers/ethernet/index.rst         |   1 +
 .../ethernet/nebula-matrix/nbl.rst            |  28 +++++
 MAINTAINERS                                   |  10 ++
 drivers/net/ethernet/Kconfig                  |   1 +
 drivers/net/ethernet/Makefile                 |   1 +
 drivers/net/ethernet/nebula-matrix/Kconfig    |  34 ++++++
 drivers/net/ethernet/nebula-matrix/Makefile   |   6 ++
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   6 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |  14 +++
 .../nbl/nbl_include/nbl_include.h             |  14 +++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 100 ++++++++++++++++++
 11 files changed, 215 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst
 create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig
 create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
index 786a23c84b90..4d74b954b0ba 100644
@@ -47,6 +47,7 @@ Contents:
    meta/fbnic
    microsoft/netvsc
    mucse/rnpgbe
+   nebula-matrix/nbl
    netronome/nfp
    pensando/ionic
    pensando/ionic_rdma
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +28 -0
new file mode 100644
index 000000000000..ff38302968c5
@@ -0,0 +1,28 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+================================================================
+Linux Base Driver for Nebula-matrix m18110-NIC/m18000-NIC family
+================================================================
+
+Overview:
+=========
+The m18110-NIC/m18000-NIC is a series of network interface cards for the Data
+Center Area.
+
+The driver supports link-speed 100GbE/25GE/10GE.
+
+m18110-NIC/m18000-NIC devices support MSI-X interrupt vector for each Tx/Rx
+queue and interrupt moderation.
+
+m18110-NIC/m18000-NIC devices support also various offload features such as
+checksum offload, Receive-Side Scaling(RSS).
+
+Support
+=======
+
+For more information about m18110-NIC/m18000-NIC, please visit the following URL:
+https://www.nebula-matrix.com/snic_s1000_en
+
+If an issue is identified with the released source code on the supported kernel
+with a supported adapter, email the specific information related to the issue to
[email protected].
MAINTAINERS +10 -0
index 00e7b26e0a23..ab0910a6836d 100644
@@ -18597,6 +18597,16 @@ F:	Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml
 F:	Documentation/hwmon/nct7363.rst
 F:	drivers/hwmon/nct7363.c
 
+NEBULA-MATRIX ETHERNET DRIVER (nebula-matrix)
+M:	Illusion Wang <[email protected]>
+M:	Dimon Zhao <[email protected]>
+M:	Alvin Wang <[email protected]>
+M:	Sam Chen <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/networking/device_drivers/ethernet/nebula-matrix/
+F:	drivers/net/ethernet/nebula-matrix/
+
 NETCONSOLE
 M:	Breno Leitao <[email protected]>
 S:	Maintained
drivers/net/ethernet/Kconfig +1 -0
index 78c79ad7bba5..5c21d02c4e11 100644
@@ -130,6 +130,7 @@ config FEALNX
 
 source "drivers/net/ethernet/ni/Kconfig"
 source "drivers/net/ethernet/natsemi/Kconfig"
+source "drivers/net/ethernet/nebula-matrix/Kconfig"
 source "drivers/net/ethernet/netronome/Kconfig"
 source "drivers/net/ethernet/8390/Kconfig"
 source "drivers/net/ethernet/nvidia/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index bba55d9af387..accce62a79a6 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_NET_VENDOR_MUCSE) += mucse/
 obj-$(CONFIG_NET_VENDOR_MYRI) += myricom/
 obj-$(CONFIG_FEALNX) += fealnx.o
 obj-$(CONFIG_NET_VENDOR_NATSEMI) += natsemi/
+obj-$(CONFIG_NET_VENDOR_NEBULA_MATRIX) += nebula-matrix/
 obj-$(CONFIG_NET_VENDOR_NETRONOME) += netronome/
 obj-$(CONFIG_NET_VENDOR_NI) += ni/
 obj-$(CONFIG_NET_VENDOR_NVIDIA) += nvidia/
drivers/net/ethernet/nebula-matrix/Kconfig new file +34 -0
new file mode 100644
index 000000000000..99cd53fcc52e
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Nebula-matrix network device configuration
+#
+
+config NET_VENDOR_NEBULA_MATRIX
+	bool "Nebula-matrix devices"
+	default y
+	help
+	  If you have a network (Ethernet) card belonging to this class, say Y.
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Nebula-matrix cards. If you say Y, you will be asked
+	  for your specific card in the following questions.
+
+if NET_VENDOR_NEBULA_MATRIX
+
+config NBL
+	tristate "Nebula-matrix Ethernet Controller m18110/m18000 support"
+	depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN
+	help
+	  This driver supports Nebula-matrix Ethernet Controller m18110/m18000
+	  Family of devices.  For more information about this product, go to
+	  the product description with smart NIC:
+
+	  <http://www.nebula-matrix.com>
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst>.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called nbl.
+
+endif # NET_VENDOR_NEBULA_MATRIX
drivers/net/ethernet/nebula-matrix/Makefile new file +6 -0
new file mode 100644
index 000000000000..42cdf2db8f0c
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Nebula-matrix network device drivers.
+#
+
+obj-$(CONFIG_NBL) += nbl/
drivers/net/ethernet/nebula-matrix/nbl/Makefile new file +6 -0
new file mode 100644
index 000000000000..b90fba239401
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Nebula Matrix Limited.
+
+obj-$(CONFIG_NBL) := nbl.o
+
+nbl-objs +=      nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +14 -0
new file mode 100644
index 000000000000..ef083956c695
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_CORE_H_
+#define _NBL_CORE_H_
+
+enum {
+	NBL_CAP_HAS_CTRL_BIT,
+	NBL_CAP_HAS_NET_BIT,
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h new file +14 -0
new file mode 100644
index 000000000000..cd99f96e1568
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_INCLUDE_H_
+#define _NBL_INCLUDE_H_
+
+#include <linux/types.h>
+
+/*  ------  Basic definitions  -------  */
+#define NBL_DRIVER_NAME					"nbl"
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer
#2 lore raw

Re: [PATCH v22 net-next 01/12] net/nebula-matrix: add minimum nbl build framework

Quoted 11 lines · On Thu, 23 Jul 2026 12:00:53 +0800 illusion.wang wrote:
drivers/net/ethernet/nebula-matrix/Kconfig new file +11 -0
+config NET_VENDOR_NEBULA_MATRIX
+	bool "Nebula-matrix devices"
+	default y
+	help
+	  If you have a network (Ethernet) card belonging to this class, say Y.
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Nebula-matrix cards. If you say Y, you will be asked
+	  for your specific card in the following questions.
+
+if NET_VENDOR_NEBULA_MATRIX

drivers/net/ethernet/nebula-matrix/Kconfig line 26

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +10 -0
+
+config NBL
+	tristate "Nebula-matrix Ethernet Controller m18110/m18000 support"
+	depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN
+	help
+	  This driver supports Nebula-matrix Ethernet Controller m18110/m18000
+	  Family of devices.  For more information about this product, go to
+	  the product description with smart NIC:
+
+	  <http://www.nebula-matrix.com>

Let's skip the "For more information.. " and the link the sentence below pointing to Documentation is enough.

drivers/net/ethernet/nebula-matrix/Kconfig

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +9 -0
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst>.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called nbl.
 
+enum {
+	NBL_CAP_HAS_CTRL_BIT,
+	NBL_CAP_HAS_NET_BIT,
+};

This enum is unused in the patch.
Please don't add unused code, it makes the submission hard to review.

author maintainer
#3 lore raw

PATCH v22 2/12 net/nebula-matrix: add core driver architecture and HW layer initialization

In reply to illusion.wang

From: illusion wang <[email protected]>

Add the fundamental driver architecture framework and Leonis hardware layer initialization for NBL NIC family.

- nbl_adapter/nbl_core/nbl_common_info core device context
- PCI probe/remove entry and basic device capability parsing
- 64/32-bit DMA mask fallback and PCI master setup
- Leonis hardware BAR resource request and ioremap logic

This patch establishes the lowest HW layer and core infrastructure, preparing for subsequent device implementations.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   3 +-
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |  19 +++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 150 ++++++++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  14 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |  28 ++++
 .../nbl/nbl_include/nbl_def_common.h          |  32 ++++
 .../nbl/nbl_include/nbl_def_hw.h              |  21 +++
 .../nbl/nbl_include/nbl_include.h             |   9 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 106 ++++++++++++-
 9 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -1
index b90fba239401..caa863d3a582 100644
@@ -3,4 +3,5 @@
 
 obj-$(CONFIG_NBL) := nbl.o
 
-nbl-objs +=      nbl_main.o
+nbl-objs +=       nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
+				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +19 -0
index ef083956c695..7ae331959ca1 100644
@@ -6,9 +6,28 @@
 #ifndef _NBL_CORE_H_
 #define _NBL_CORE_H_
 
+#include <linux/pci.h>
+#include "nbl_include/nbl_include.h"
+#include "nbl_include/nbl_def_common.h"
+
+struct nbl_hw_mgt;
+
 enum {
 	NBL_CAP_HAS_CTRL_BIT,
 	NBL_CAP_HAS_NET_BIT,
 };
 
+struct nbl_core {
+	struct nbl_hw_mgt *hw_mgt;
+};
+
+struct nbl_adapter {
+	struct pci_dev *pdev;
+	struct nbl_core core;
+	struct nbl_common_info common;
+};
+
+struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
+				  struct nbl_init_param *param);
+void nbl_core_remove(struct nbl_adapter *adapter);
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +150 -0

150 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h new file +14 -0
new file mode 100644
index 000000000000..77c67b67ba31
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_HW_LEONIS_H_
+#define _NBL_HW_LEONIS_H_
+
+#include <linux/types.h>
+
+#include "../../nbl_include/nbl_include.h"
+#include "../nbl_hw_reg.h"
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +28 -0
new file mode 100644
index 000000000000..af9706ebbc73
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_HW_REG_H_
+#define _NBL_HW_REG_H_
+
+#include <linux/types.h>
+
+#include "../nbl_include/nbl_def_hw.h"
+#include "../nbl_include/nbl_def_common.h"
+#include "../nbl_core.h"
+
+#define NBL_MEMORY_BAR				0
+#define NBL_MAILBOX_BAR				2
+#define NBL_RDMA_NOTIFY_LEN			(8ULL << 10)
+#define NBL_REG_NET_ONLY_LEN			(8ULL << 10)
+#define NBL_HW_REG_SPACE_SIZE			(16ULL << 20)
+
+struct nbl_hw_mgt {
+	struct nbl_common_info *common;
+	u8 __iomem *hw_addr;
+	u8 __iomem *mailbox_bar_hw_addr;
+	resource_size_t hw_size;
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +32 -0
new file mode 100644
index 000000000000..5b7ec68d620b
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_COMMON_H_
+#define _NBL_DEF_COMMON_H_
+
+#include <linux/types.h>
+#include <linux/pci.h>
+#include <linux/device.h>
+#include "nbl_include.h"
+
+struct nbl_common_info {
+	struct pci_dev *pdev;
+	struct device *dev;
+	u32 msg_enable;
+	u16 vsi_id;
+	u8 eth_id;
+	u8 logic_eth_id;
+	u8 eth_num;
+
+	u8 function;
+	u8 devid;
+	u8 bus;
+	u8 hw_bus;
+
+	u8 has_ctrl;
+	u8 has_net;
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file +21 -0
new file mode 100644
index 000000000000..ab97956582b4
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_HW_H_
+#define _NBL_DEF_HW_H_
+
+#include <linux/types.h>
+
+struct nbl_hw_mgt;
+struct nbl_adapter;
+
+struct nbl_hw_ops_tbl {
+	struct nbl_hw_mgt *priv;
+};
+
+int nbl_hw_init_leonis(struct nbl_adapter *adapter);
+void nbl_hw_remove_leonis(struct nbl_adapter *adapter);
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +9 -0
index cd99f96e1568..70f4f4b4c49c 100644
@@ -10,5 +10,14 @@
 
 /*  ------  Basic definitions  -------  */
 #define NBL_DRIVER_NAME					"nbl"
+struct nbl_func_caps {
+	u32 has_ctrl:1;
+	u32 has_net:1;
+	u32 rsv:30;
+};
+
+struct nbl_init_param {
+	struct nbl_func_caps caps;
+};
 
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +105 -1

121 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#4 lore raw

回复:[PATCH v22 net-next 02/12] net/nebula-matrix: add core driver architecture and HW layer initialization

(https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260723040110.91410-1-illusion.wang%40nebula-matrix.com)
One comment asks:

Quoted 11 lines

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 150

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +6 -0
+void nbl_hw_remove_leonis(struct nbl_adapter *adapter)
+{
+	/* All BAR mappings & PCI regions are managed by pcim/devres,
+	 * no manual iounmap / release required
+	 */
+}

since nbl_hw_remove_leonis is an empty stub function with no implementation, is there a valid reason to retain it (along with its prototype in nbl_def_h.h), or should we delete both until a subsequent patch adds actual cleanup logic to it?

(https://lore.kernel.org/netdev/[email protected]/)
The other comment questions whether our initialization and teardown paths should maintain strict symmetry—every successfully initialized layer must have a matching remove callback invoked both in runtime device removal (nbl_core_remove) and all early error unwind branches of the init flow.

I'm a bit confused about the two Sashiko review comments on Patch 2 of this patchset:
Which piece of feedback should I follow?

maintainer
#5 lore raw

Re: [PATCH v22 net-next 02/12] net/nebula-matrix: add core driver architecture and HW layer initialization

In reply to illusion.wang

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 90

Quoted 6 lines · On Thu, 23 Jul 2026 12:00:54 +0800 illusion.wang wrote:
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6 -0
+	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
+	if (err) {
+		dev_dbg(dev, "Configure DMA 64 bit mask failed, err = %d\n",
+			err);
+		dma_32_err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
+		if (dma_32_err) {

Read the documentation for the DMA API, dma_set_mask_and_coherent() is guaranteed to succeed in some cases..

maintainer
#6 lore raw

Re: [PATCH v22 net-next 02/12] net/nebula-matrix: add core driver architecture and HW layer initialization

In reply to illusion.wang

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [2]: [PATCH v22 net-next 02/12] net/nebula-matrix: add core driver architecture and HW layer initialization --- commit b4e4638b25f9e82d490889327022a039dbb63644
Author: illusion wang <[email protected]>

net/nebula-matrix: add core driver architecture and HW layer initialization

This commit adds the core driver framework and hardware layer initialization for the NBL NIC family. It handles basic device capability parsing, DMA mask fallback, and Leonis hardware BAR resource requests and mappings.

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +0 -0
new file mode 100644
index 0000000000000..79a4b15c01a90

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +2 -0
+int nbl_hw_init_leonis(struct nbl_adapter *adapter)
+{

[ ... ]

Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +17 -0
+	if (common->has_ctrl) {
+		/*
+		 * The fixed 16MiB MEMORY BAR of PF0 contains both control
+		 * register region and the 8KiB RDMA notify partition inside
+		 * this single 16MiB window. The RDMA notify area does not
+		 * occupy extra space outside the BAR range.
+		 * We only map the front part of BAR by cutting off the last
+		 * NBL_RDMA_NOTIFY_LEN bytes for hardware exclusive RDMA
+		 * notification use,
+		 * so the mapping length equals bar_len - NBL_RDMA_NOTIFY_LEN.
+		 * Since the RDMA notify region is internal to the 16MiB BAR,
+		 * the minimum BAR size check remains bar_len >=
+		 * NBL_HW_REG_SPACE_SIZE to ensure full register space is
+		 * available.
+		 */
+		if (bar_len < NBL_HW_REG_SPACE_SIZE) {
+			dev_err(&pdev->dev,

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 99

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +10 -0
+				"MEMORY BAR len %pa too small for ctrl reg space\n",
+				&bar_len);
+			ret = -EINVAL;
+			goto setup_mgt_fail;
+		}
+
+		hw_mgt->hw_size = bar_len - NBL_RDMA_NOTIFY_LEN;
+		hw_mgt->hw_addr =
+			pcim_iomap(pdev, NBL_MEMORY_BAR,
+				   hw_mgt->hw_size);

[Severity: Medium]
Will this map the hardware-exclusive RDMA notify region if the platform or hypervisor assigns a BAR larger than 16 MiB (NBL_HW_REG_SPACE_SIZE)?

If bar_len > NBL_HW_REG_SPACE_SIZE, hw_size will span beyond the front part of the fixed 16 MiB window and cover the RDMA notify region.

If an RDMA driver later attempts to map this same region with Write-Combining (WC) attributes, could it conflict with the Ethernet driver's Uncacheable (UC) mapping and cause x86 PAT attribute aliasing issues?

Should this calculation use NBL_HW_REG_SPACE_SIZE instead of bar_len?

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +2 -0
+	} else {
+		if (bar_len < NBL_REG_NET_ONLY_LEN) {

[ ... ]

Signature · 1 line
pw-bot: cr
author maintainer
#7 lore raw

PATCH v22 3/12 net/nebula-matrix: add channel wire opcode enum definitions

In reply to illusion.wang

From: illusion wang <[email protected]>

Add enum nbl_chan_msg_type into nbl_def_channel.h, defining all PF/VF/firmware channel wire opcodes used for inter-component mailbox communication.

Each enumerator carries an explicit fixed numeric value, acting as stable wire-format message ID shared between driver and firmware.

ABI constraint: New opcodes must only be appended before NBL_CHAN_MSG_MAILBOX_MAX.
Reordering, inserting or deleting existing entries will break cross-version driver-firmware interoperability. Any modification to existing opcode assignments requires coordinated firmware ABI change.

This commit introduces the opcode ID enumeration. Message payload structures and complete channel layer logic will be added in subsequent separate patches.

---
 .../nbl/nbl_include/nbl_def_channel.h         | 242 ++++++++++++++++++
 1 file changed, 242 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +242 -0
new file mode 100644
index 000000000000..be374667c338
@@ -0,0 +1,242 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_CHANNEL_H_
+#define _NBL_DEF_CHANNEL_H_
+
+/*
+ * Mailbox wire opcodes
+ * Every opcode is assigned explicit fixed numeric value, stable wire ABI
+ * shared between driver and firmware.
+ * Firmware/driver wire compatibility rule:
+ * New entries must only be appended before NBL_CHAN_MSG_MAILBOX_MAX.
+ * Reordering / inserting / deleting existing items will break cross-version
+ * interoperability. Any change to existing enumerators requires matching
+ * firmware ABI adjustment.
+ */
+enum nbl_chan_msg_type {
+	NBL_CHAN_MSG_ACK = 0,
+	NBL_CHAN_MSG_ADD_MACVLAN = 1,
+	NBL_CHAN_MSG_DEL_MACVLAN = 2,
+	NBL_CHAN_MSG_ADD_MULTI_RULE = 3,
+	NBL_CHAN_MSG_DEL_MULTI_RULE = 4,
+	NBL_CHAN_MSG_SETUP_MULTI_GROUP = 5,
+	NBL_CHAN_MSG_REMOVE_MULTI_GROUP = 6,
+	NBL_CHAN_MSG_REGISTER_NET = 7,
+	NBL_CHAN_MSG_UNREGISTER_NET = 8,
+	NBL_CHAN_MSG_ALLOC_TXRX_QUEUES = 9,
+	NBL_CHAN_MSG_FREE_TXRX_QUEUES = 10,
+	NBL_CHAN_MSG_SETUP_QUEUE = 11,
+	NBL_CHAN_MSG_REMOVE_ALL_QUEUES = 12,
+	NBL_CHAN_MSG_CFG_DSCH = 13,
+	NBL_CHAN_MSG_SETUP_CQS = 14,
+	NBL_CHAN_MSG_REMOVE_CQS = 15,
+	NBL_CHAN_MSG_CFG_QDISC_MQPRIO = 16,
+	NBL_CHAN_MSG_CONFIGURE_MSIX_MAP = 17,
+	NBL_CHAN_MSG_DESTROY_MSIX_MAP = 18,
+	NBL_CHAN_MSG_MAILBOX_SET_IRQ = 19,
+	NBL_CHAN_MSG_GET_GLOBAL_VECTOR = 20,
+	NBL_CHAN_MSG_GET_VSI_ID = 21,
+	NBL_CHAN_MSG_SET_PROMISC_MODE = 22,
+	NBL_CHAN_MSG_GET_FIRMWARE_VERSION = 23,
+	NBL_CHAN_MSG_GET_QUEUE_ERR_STATS = 24,
+	NBL_CHAN_MSG_GET_COALESCE = 25,
+	NBL_CHAN_MSG_SET_COALESCE = 26,
+	NBL_CHAN_MSG_SET_SPOOF_CHECK_ADDR = 27,
+	NBL_CHAN_MSG_SET_VF_SPOOF_CHECK = 28,
+	NBL_CHAN_MSG_GET_RXFH_INDIR_SIZE = 29,
+	NBL_CHAN_MSG_GET_RXFH_INDIR = 30,
+	NBL_CHAN_MSG_GET_RXFH_RSS_KEY = 31,
+	NBL_CHAN_MSG_GET_RXFH_RSS_ALG_SEL = 32,
+	NBL_CHAN_MSG_GET_HW_CAPS = 33,
+	NBL_CHAN_MSG_GET_HW_STATE = 34,
+	NBL_CHAN_MSG_REGISTER_RDMA = 35,
+	NBL_CHAN_MSG_UNREGISTER_RDMA = 36,
+	NBL_CHAN_MSG_GET_REAL_HW_ADDR = 37,
+	NBL_CHAN_MSG_GET_REAL_BDF = 38,
+	NBL_CHAN_MSG_GRC_PROCESS = 39,
+	NBL_CHAN_MSG_SET_SFP_STATE = 40,
+	NBL_CHAN_MSG_SET_ETH_LOOPBACK = 41,
+	NBL_CHAN_MSG_CHECK_ACTIVE_VF = 42,
+	NBL_CHAN_MSG_GET_PRODUCT_FLEX_CAP = 43,
+	NBL_CHAN_MSG_ALLOC_KTLS_TX_INDEX = 44,
+	NBL_CHAN_MSG_FREE_KTLS_TX_INDEX = 45,
+	NBL_CHAN_MSG_CFG_KTLS_TX_KEYMAT = 46,
+	NBL_CHAN_MSG_ALLOC_KTLS_RX_INDEX = 47,
+	NBL_CHAN_MSG_FREE_KTLS_RX_INDEX = 48,
+	NBL_CHAN_MSG_CFG_KTLS_RX_KEYMAT = 49,
+	NBL_CHAN_MSG_CFG_KTLS_RX_RECORD = 50,
+	NBL_CHAN_MSG_ADD_KTLS_RX_FLOW = 51,
+	NBL_CHAN_MSG_DEL_KTLS_RX_FLOW = 52,
+	NBL_CHAN_MSG_ALLOC_IPSEC_TX_INDEX = 53,
+	NBL_CHAN_MSG_FREE_IPSEC_TX_INDEX = 54,
+	NBL_CHAN_MSG_ALLOC_IPSEC_RX_INDEX = 55,
+	NBL_CHAN_MSG_FREE_IPSEC_RX_INDEX = 56,
+	NBL_CHAN_MSG_CFG_IPSEC_TX_SAD = 57,
+	NBL_CHAN_MSG_CFG_IPSEC_RX_SAD = 58,
+	NBL_CHAN_MSG_ADD_IPSEC_TX_FLOW = 59,
+	NBL_CHAN_MSG_DEL_IPSEC_TX_FLOW = 60,
+	NBL_CHAN_MSG_ADD_IPSEC_RX_FLOW = 61,
+	NBL_CHAN_MSG_DEL_IPSEC_RX_FLOW = 62,
+	NBL_CHAN_MSG_NOTIFY_IPSEC_HARD_EXPIRE = 63,
+	NBL_CHAN_MSG_GET_MBX_IRQ_NUM = 64,
+	NBL_CHAN_MSG_CLEAR_FLOW = 65,
+	NBL_CHAN_MSG_CLEAR_QUEUE = 66,
+	NBL_CHAN_MSG_GET_ETH_ID = 67,
+	NBL_CHAN_MSG_SET_OFFLOAD_STATUS = 68,
+	NBL_CHAN_MSG_INIT_OFLD = 69,
+	NBL_CHAN_MSG_INIT_CMDQ = 70,
+	NBL_CHAN_MSG_DESTROY_CMDQ = 71,
+	NBL_CHAN_MSG_RESET_CMDQ = 72,
+	NBL_CHAN_MSG_INIT_FLOW = 73,
+	NBL_CHAN_MSG_DEINIT_FLOW = 74,
+	NBL_CHAN_MSG_OFFLOAD_FLOW_RULE = 75,
+	NBL_CHAN_MSG_GET_ACL_SWITCH = 76,
+	NBL_CHAN_MSG_GET_VSI_GLOBAL_QUEUE_ID = 77,
+	NBL_CHAN_MSG_INIT_REP = 78,
+	NBL_CHAN_MSG_GET_LINE_RATE_INFO = 79,
+	NBL_CHAN_MSG_REGISTER_NET_REP = 80,
+	NBL_CHAN_MSG_UNREGISTER_NET_REP = 81,
+	NBL_CHAN_MSG_REGISTER_ETH_REP = 82,
+	NBL_CHAN_MSG_UNREGISTER_ETH_REP = 83,
+	NBL_CHAN_MSG_REGISTER_UPCALL_PORT = 84,
+	NBL_CHAN_MSG_UNREGISTER_UPCALL_PORT = 85,
+	NBL_CHAN_MSG_GET_PORT_STATE = 86,
+	NBL_CHAN_MSG_SET_PORT_ADVERTISING = 87,
+	NBL_CHAN_MSG_GET_MODULE_INFO = 88,
+	NBL_CHAN_MSG_GET_MODULE_EEPROM = 89,
+	NBL_CHAN_MSG_GET_LINK_STATE = 90,
+	NBL_CHAN_MSG_NOTIFY_LINK_STATE = 91,
+	NBL_CHAN_MSG_GET_QUEUE_CXT = 92,
+	NBL_CHAN_MSG_CFG_LOG = 93,
+	NBL_CHAN_MSG_INIT_VDPAQ = 94,
+	NBL_CHAN_MSG_DESTROY_VDPAQ = 95,
+	NBL_CHAN_MSG_GET_UPCALL_PORT = 96,
+	NBL_CHAN_MSG_NOTIFY_ETH_REP_LINK_STATE = 97,
+	NBL_CHAN_MSG_SET_ETH_MAC_ADDR = 98,
+	NBL_CHAN_MSG_GET_FUNCTION_ID = 99,
+	NBL_CHAN_MSG_GET_CHIP_TEMPERATURE = 100,
+	NBL_CHAN_MSG_DISABLE_HW_FLOW = 101,
+	NBL_CHAN_MSG_ENABLE_HW_FLOW = 102,
+	NBL_CHAN_MSG_SET_UPCALL_RULE = 103,
+	NBL_CHAN_MSG_UNSET_UPCALL_RULE = 104,
+	NBL_CHAN_MSG_GET_REG_DUMP = 105,
+	NBL_CHAN_MSG_GET_REG_DUMP_LEN = 106,
+	NBL_CHAN_MSG_CFG_LAG_HASH_ALGORITHM = 107,
+	NBL_CHAN_MSG_CFG_LAG_MEMBER_FWD = 108,
+	NBL_CHAN_MSG_CFG_LAG_MEMBER_LIST = 109,
+	NBL_CHAN_MSG_CFG_LAG_MEMBER_UP_ATTR = 110,
+	NBL_CHAN_MSG_ADD_LAG_FLOW = 111,
+	NBL_CHAN_MSG_DEL_LAG_FLOW = 112,
+	NBL_CHAN_MSG_SWITCHDEV_INIT_CMDQ = 113,
+	NBL_CHAN_MSG_SWITCHDEV_DEINIT_CMDQ = 114,
+	NBL_CHAN_MSG_SET_TC_FLOW_INFO = 115,
+	NBL_CHAN_MSG_UNSET_TC_FLOW_INFO = 116,
+	NBL_CHAN_MSG_INIT_ACL = 117,
+	NBL_CHAN_MSG_UNINIT_ACL = 118,
+	NBL_CHAN_MSG_CFG_LAG_MCC = 119,
+	NBL_CHAN_MSG_REGISTER_VSI2Q = 120,
+	NBL_CHAN_MSG_SETUP_Q2VSI = 121,
+	NBL_CHAN_MSG_REMOVE_Q2VSI = 122,
+	NBL_CHAN_MSG_SETUP_RSS = 123,
+	NBL_CHAN_MSG_REMOVE_RSS = 124,
+	NBL_CHAN_MSG_GET_REP_QUEUE_INFO = 125,
+	NBL_CHAN_MSG_CTRL_PORT_LED = 126,
+	NBL_CHAN_MSG_NWAY_RESET = 127,
+	NBL_CHAN_MSG_SET_INTL_SUPPRESS_LEVEL = 128,
+	NBL_CHAN_MSG_GET_ETH_STATS = 129,
+	NBL_CHAN_MSG_GET_MODULE_TEMPERATURE = 130,
+	NBL_CHAN_MSG_GET_BOARD_INFO = 131,
+	NBL_CHAN_MSG_GET_P4_USED = 132,
+	NBL_CHAN_MSG_GET_VF_BASE_VSI_ID = 133,
+	NBL_CHAN_MSG_ADD_LLDP_FLOW = 134,
+	NBL_CHAN_MSG_DEL_LLDP_FLOW = 135,
+	NBL_CHAN_MSG_CFG_ETH_BOND_INFO = 136,
+	NBL_CHAN_MSG_CFG_DUPPKT_MCC = 137,
+	NBL_CHAN_MSG_ADD_ND_UPCALL_FLOW = 138,
+	NBL_CHAN_MSG_DEL_ND_UPCALL_FLOW = 139,
+	NBL_CHAN_MSG_GET_BOARD_ID = 140,
+	NBL_CHAN_MSG_SET_SHAPING_DPORT_VLD = 141,
+	NBL_CHAN_MSG_SET_DPORT_FC_TH_VLD = 142,
+	NBL_CHAN_MSG_REGISTER_RDMA_BOND = 143,
+	NBL_CHAN_MSG_UNREGISTER_RDMA_BOND = 144,
+	NBL_CHAN_MSG_RESTORE_NETDEV_QUEUE = 145,
+	NBL_CHAN_MSG_RESTART_NETDEV_QUEUE = 146,
+	NBL_CHAN_MSG_RESTORE_HW_QUEUE = 147,
+	NBL_CHAN_MSG_KEEP_ALIVE = 148,
+	NBL_CHAN_MSG_GET_BASE_MAC_ADDR = 149,
+	NBL_CHAN_MSG_CFG_BOND_SHAPING = 150,
+	NBL_CHAN_MSG_CFG_BGID_BACK_PRESSURE = 151,
+	NBL_CHAN_MSG_ALLOC_KT_BLOCK = 152,
+	NBL_CHAN_MSG_FREE_KT_BLOCK = 153,
+	NBL_CHAN_MSG_GET_USER_QUEUE_INFO = 154,
+	NBL_CHAN_MSG_GET_ETH_BOND_INFO = 155,
+	NBL_CHAN_MSG_CLEAR_ACCEL_FLOW = 156,
+	NBL_CHAN_MSG_SET_BRIDGE_MODE = 157,
+	NBL_CHAN_MSG_GET_VF_FUNCTION_ID = 158,
+	NBL_CHAN_MSG_NOTIFY_LINK_FORCED = 159,
+	NBL_CHAN_MSG_SET_PMD_DEBUG = 160,
+	NBL_CHAN_MSG_REGISTER_FUNC_MAC = 161,
+	NBL_CHAN_MSG_SET_TX_RATE = 162,
+	NBL_CHAN_MSG_REGISTER_FUNC_LINK_FORCED = 163,
+	NBL_CHAN_MSG_GET_LINK_FORCED = 164,
+	NBL_CHAN_MSG_REGISTER_FUNC_VLAN = 165,
+	NBL_CHAN_MSG_GET_FD_FLOW = 166,
+	NBL_CHAN_MSG_GET_FD_FLOW_CNT = 167,
+	NBL_CHAN_MSG_GET_FD_FLOW_ALL = 168,
+	NBL_CHAN_MSG_GET_FD_FLOW_MAX = 169,
+	NBL_CHAN_MSG_REPLACE_FD_FLOW = 170,
+	NBL_CHAN_MSG_REMOVE_FD_FLOW = 171,
+	NBL_CHAN_MSG_CFG_FD_FLOW_STATE = 172,
+	NBL_CHAN_MSG_REGISTER_FUNC_RATE = 173,
+	NBL_CHAN_MSG_NOTIFY_VLAN = 174,
+	NBL_CHAN_MSG_GET_XDP_QUEUE_INFO = 175,
+	NBL_CHAN_MSG_STOP_ABNORMAL_SW_QUEUE = 176,
+	NBL_CHAN_MSG_STOP_ABNORMAL_HW_QUEUE = 177,
+	NBL_CHAN_MSG_NOTIFY_RESET_EVENT = 178,
+	NBL_CHAN_MSG_ACK_RESET_EVENT = 179,
+	NBL_CHAN_MSG_GET_VF_VSI_ID = 180,
+	NBL_CHAN_MSG_CONFIGURE_QOS = 181,
+	NBL_CHAN_MSG_GET_PFC_BUFFER_SIZE = 182,
+	NBL_CHAN_MSG_SET_PFC_BUFFER_SIZE = 183,
+	NBL_CHAN_MSG_GET_VF_STATS = 184,
+	NBL_CHAN_MSG_REGISTER_FUNC_TRUST = 185,
+	NBL_CHAN_MSG_NOTIFY_TRUST = 186,
+	NBL_CHAN_MSG_CHECK_VF_IS_ACTIVE = 187,
+	NBL_CHAN_MSG_GET_ETH_ABNORMAL_STATS = 188,
+	NBL_CHAN_MSG_GET_ETH_CTRL_STATS = 189,
+	NBL_CHAN_MSG_GET_PAUSE_STATS = 190,
+	NBL_CHAN_MSG_GET_ETH_MAC_STATS = 191,
+	NBL_CHAN_MSG_GET_FEC_STATS = 192,
+	NBL_CHAN_MSG_CFG_MULTI_MCAST_RULE = 193,
+	NBL_CHAN_MSG_GET_LINK_DOWN_COUNT = 194,
+	NBL_CHAN_MSG_GET_LINK_STATUS_OPCODE = 195,
+	NBL_CHAN_MSG_GET_RMON_STATS = 196,
+	NBL_CHAN_MSG_REGISTER_PF_NAME = 197,
+	NBL_CHAN_MSG_GET_PF_NAME = 198,
+	NBL_CHAN_MSG_CONFIGURE_RDMA_BW = 199,
+	NBL_CHAN_MSG_SET_RATE_LIMIT = 200,
+	NBL_CHAN_MSG_SET_TC_WGT = 201,
+	NBL_CHAN_MSG_REMOVE_QUEUE = 202,
+	NBL_CHAN_MSG_GET_MIRROR_TABLE_ID = 203,
+	NBL_CHAN_MSG_CONFIGURE_MIRROR = 204,
+	NBL_CHAN_MSG_CONFIGURE_MIRROR_TABLE = 205,
+	NBL_CHAN_MSG_CLEAR_MIRROR_CFG = 206,
+	NBL_CHAN_MSG_MIRROR_OUTPUTPORT_NOTIFY = 207,
+	NBL_CHAN_MSG_CHECK_FLOWTABLE_SPEC = 208,
+	NBL_CHAN_MSG_CHECK_VF_IS_VDPA = 209,
+	NBL_CHAN_MSG_GET_VDPA_VF_STATS = 210,
+	NBL_CHAN_MSG_SET_RX_RATE = 211,
+	NBL_CHAN_MSG_GET_UVN_PKT_DROP_STATS = 212,
+	NBL_CHAN_MSG_GET_USTORE_PKT_DROP_STATS = 213,
+	NBL_CHAN_MSG_GET_USTORE_TOTAL_PKT_DROP_STATS = 214,
+	NBL_CHAN_MSG_SET_WOL = 215,
+	NBL_CHAN_MSG_INIT_VF_MSIX_MAP = 216,
+	NBL_CHAN_MSG_GET_ST_NAME = 217,
+	/* mailbox msg end */
+	NBL_CHAN_MSG_MAILBOX_MAX,
+};
+
+#endif
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH v22 4/12 net/nebula-matrix: add channel layer

In reply to illusion.wang

From: illusion wang <[email protected]>

A channel management layer provides a structured approach to handle communication between different components and drivers. Here's a summary of its key functionalities:

1. Message Handling Framework
Message Registration: Functions (nbl_chan_register_msg) allow dynamic registration of message handlers for specific message types, enabling extensible communication protocols.

Message Sending/Acknowledgment: Core functions (nbl_chan_send_msg, nbl_chan_send_ack) handle message transmission. It supports two modes:
fire-and-forget transmission, and synchronous send with ACK waiting. Received ACK messages are processed via nbl_chan_recv_ack_msg. TX slot allocation logic is implemented to limit concurrent outstanding messages; returns -EAGAIN when all waiting slots are occupied.

Hash-Based Handler Lookup: A hash table (handle_hash_tbl) stores message handlers for efficient O(1) lookup by message type. The entire table is removed via nbl_chan_remove_msg_handler during driver teardown; per-message-type unregister is not implemented in this version.

Tx descriptor supports two data formats: small embedded payload inside descriptor, and large payload via external DMA buffer.

2. Channel Types and Queue Management
Mailbox Channel: implemented for inter-PF communication (PF0 <-> other PFs).

Queue Initialization: Functions (nbl_chan_init_queue, nbl_chan_init_tx_queue) allocate resources:
- TX/RX descriptors: dmam_alloc_coherent()
- TX/RX buffer metadata arrays (txq->buf, rxq->buf): devm_kcalloc()

Queue Teardown: nbl_chan_teardown_queue() stops hardware queues, cancels pending work items (clean_task), and waits for in-flight send threads to drain. It does NOT free DMA memory, which is released automatically via devm on driver remove.

IMPORTANT - Resource Lifecycle Design:
DMA memory allocated with dmam_alloc_coherent() is intentionally NOT freed in nbl_chan_teardown_queue(). The queues are allocated once during driver probe and freed only during driver remove. Dynamic per-PF queue teardown and re-creation during runtime is not supported.

Queue Configuration: Hardware-specific queue parameters (e.g., buffer sizes, entry counts) are set via nbl_chan_config_queue, with hardware interactions delegated to hw_ops.

RX completion relies on work_struct clean_task for descriptor processing.

3. Hardware Abstraction Layer (HW Ops)
Hardware-Specific Operations: The nbl_hw_ops structure abstracts hardware interactions: queue configuration (config_mailbox_txq/rxq), tail pointer doorbell updates (update_mailbox_queue_tail_ptr), and PF mailbox routing table configuration.

NOTE: This initial implementation provides interrupt-driven receive path, where actual RX message processing is scheduled into workqueue after interrupt notification. Polling-based mailbox receive is not supported in this patch and will be added in subsequent series.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |    4 +-
 .../nbl/nbl_channel/nbl_channel.c             | 1047 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  171 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  172 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   29 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   11 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  173 +++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |   56 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   45 +
 .../nbl/nbl_include/nbl_def_channel.h         |  104 ++
 .../nbl/nbl_include/nbl_def_common.h          |   17 +
 .../nbl/nbl_include/nbl_def_hw.h              |   15 +
 .../nbl/nbl_include/nbl_include.h             |    6 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |    7 +
 14 files changed, 1856 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
index caa863d3a582..6dc1539cee1f 100644
@@ -3,5 +3,7 @@
 
 obj-$(CONFIG_NBL) := nbl.o
 
-nbl-objs +=       nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
+nbl-objs +=       nbl_common/nbl_common.o \
+				nbl_channel/nbl_channel.o \
+				nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +1047 -0

1,047 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +171 -0

171 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +172 -0

172 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +29 -0
new file mode 100644
index 000000000000..ad8fb7ec9f45
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_COMMON_H_
+#define _NBL_COMMON_H_
+
+#include <linux/types.h>
+
+#include "../nbl_include/nbl_include.h"
+#include "../nbl_include/nbl_def_common.h"
+
+/* list only need one bucket size */
+#define NBL_HASH_TBL_LIST_BUCKET_SIZE 1
+
+struct nbl_hash_tbl_mgt {
+	struct nbl_hash_tbl_key tbl_key;
+	struct hlist_head *hash;
+	u16 node_num;
+};
+
+struct nbl_hash_entry_node {
+	struct hlist_node node;
+	void *key;
+	void *data;
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +11 -0
index 7ae331959ca1..d6b7bfff3cc6 100644
@@ -11,23 +11,34 @@
 #include "nbl_include/nbl_def_common.h"
 
 struct nbl_hw_mgt;
+struct nbl_hw_ops_tbl;
+struct nbl_channel_ops_tbl;
+struct nbl_channel_mgt;
 
 enum {
 	NBL_CAP_HAS_CTRL_BIT,
 	NBL_CAP_HAS_NET_BIT,
 };
 
+struct nbl_interface {
+	struct nbl_hw_ops_tbl *hw_ops_tbl;
+	struct nbl_channel_ops_tbl *channel_ops_tbl;
+};
+
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
+	struct nbl_channel_mgt *chan_mgt;
 };
 
 struct nbl_adapter {
 	struct pci_dev *pdev;
 	struct nbl_core core;
+	struct nbl_interface intf;
 	struct nbl_common_info common;
 };
 
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param);
 void nbl_core_remove(struct nbl_adapter *adapter);
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +173 -0

197 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +56 -0

60 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +45 -0

63 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +104 -0

114 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +17 -0
index 5b7ec68d620b..282377bad257 100644
@@ -11,6 +11,8 @@
 #include <linux/device.h>
 #include "nbl_include.h"
 
+struct nbl_hash_tbl_mgt;
+
 struct nbl_common_info {
 	struct pci_dev *pdev;
 	struct device *dev;
@@ -29,4 +31,19 @@ struct nbl_common_info {
 	u8 has_net;
 };
 
+struct nbl_hash_tbl_key {
+	struct device *dev;
+	u16 key_size;
+	u16 data_size; /* no include key or node member */
+	u16 bucket_size;
+	u16 resv;
+};
+
+struct nbl_hash_tbl_mgt *
+nbl_common_init_hash_table(struct nbl_hash_tbl_key *key);
+void nbl_common_remove_hash_table(struct nbl_hash_tbl_mgt *tbl_mgt);
+int nbl_common_alloc_hash_node(struct nbl_hash_tbl_mgt *tbl_mgt, void *key,
+			       void *data, void **out_data);
+void *nbl_common_get_hash_node(struct nbl_hash_tbl_mgt *tbl_mgt, void *key);
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +15 -0
index ab97956582b4..08be57631453 100644
@@ -10,8 +10,23 @@
 
 struct nbl_hw_mgt;
 struct nbl_adapter;
+struct nbl_hw_ops {
+	void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,
+					      u16 tail_ptr, u8 txrx);
+	void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
+				   dma_addr_t dma_addr, int size_bwid);
+	void (*config_mailbox_txq)(struct nbl_hw_mgt *hw_mgt,
+				   dma_addr_t dma_addr, int size_bwid);
+	void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt);
+	void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt);
+	u32 (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt);
+
+	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+				  u8 bus, u8 devid, u8 function);
+};
 
 struct nbl_hw_ops_tbl {
+	struct nbl_hw_ops *ops;
 	struct nbl_hw_mgt *priv;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +6 -0
index 70f4f4b4c49c..0ea3e8551660 100644
@@ -10,6 +10,12 @@
 
 /*  ------  Basic definitions  -------  */
 #define NBL_DRIVER_NAME					"nbl"
+#define NBL_MAX_PF					8
+#define NBL_NEXT_ID(id, max)				\
+	({						\
+		typeof(id) _id = (id);			\
+		((_id) == (max) ? 0 : (_id) + 1);	\
+	})
 struct nbl_func_caps {
 	u32 has_ctrl:1;
 	u32 has_net:1;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +7 -0
index aa14b827abea..94884f388115 100644
@@ -8,6 +8,7 @@
 #include <linux/module.h>
 #include <linux/bits.h>
 #include "nbl_include/nbl_include.h"
+#include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
@@ -38,13 +39,19 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	if (ret)
 		goto hw_init_fail;
 
+	ret = nbl_chan_init_common(adapter);
+	if (ret)
+		goto chan_init_fail;
 	return adapter;
+chan_init_fail:
+	nbl_hw_remove_leonis(adapter);
 hw_init_fail:
 	return ERR_PTR(ret);
 }
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
 }
 
Signature · 1 line
2.47.3
maintainer
#9 lore raw

Re: [PATCH v22 net-next 04/12] net/nebula-matrix: add channel layer

Quoted 11 lines · On Thu, 23 Jul 2026 12:00:56 +0800 illusion.wang wrote:
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +11 -0
+#define FNV_PRIME_32 0x01000193
+#define FNV_OFFSET_32 0x811C9DC5
+static u32 nbl_common_calc_hash_key(void *key, u32 key_size, u32 bucket_size)
+{
+	u32 hash = FNV_OFFSET_32;
+	u8 *p = (u8 *)key;
+	u32 i;
+
+	if (bucket_size == 0 || bucket_size == NBL_HASH_TBL_LIST_BUCKET_SIZE)
+		return 0;
+

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 29

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +10 -0
+	for (i = 0; i < key_size; i++) {
+		hash ^= p[i];
+		hash *= FNV_PRIME_32;
+	}
+	/* Use bitmask if bucket_size is a power of 2 */
+	if ((bucket_size & (bucket_size - 1)) == 0)
+		return hash & (bucket_size - 1);
+	else
+		return hash % bucket_size;
+}

Why are you implementing your own hashing function and your own hash table? Can't one of existing implementations in the kernel be used?

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 85

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +10 -0
+int nbl_common_alloc_hash_node(struct nbl_hash_tbl_mgt *tbl_mgt, void *key,
+			       void *data, void **out_data)
+{
+	struct nbl_hash_entry_node *hash_node;
+	u16 data_size;
+	u32 hash_val;
+	u16 key_size;
+
+	hash_node = devm_kzalloc(tbl_mgt->tbl_key.dev, sizeof(*hash_node),
+				 GFP_KERNEL);

Don't use devm_ for inherently dynamically allocated memory...

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 152

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +7 -0
+static void nbl_common_detach_hash_node(struct nbl_hash_tbl_mgt *tbl_mgt,
+					struct nbl_hash_entry_node *hash_node)
+{
+	hlist_del(&hash_node->node);
+	devm_kfree(tbl_mgt->tbl_key.dev, hash_node->key);
+	devm_kfree(tbl_mgt->tbl_key.dev, hash_node->data);
+	devm_kfree(tbl_mgt->tbl_key.dev, hash_node);

... if you ever have to explicitly free something, chances are you shouldn't be using devm_ in the first place.

drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h line 17

Quoted 11 lines

index 7ae331959ca1..d6b7bfff3cc6 100644

drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +3 -0
@@ -11,23 +11,34 @@
 #include "nbl_include/nbl_def_common.h"
 
 struct nbl_hw_mgt;
+struct nbl_hw_ops_tbl;
+struct nbl_channel_ops_tbl;
+struct nbl_channel_mgt;
 

Lots of unnecessary forward declarations. Using type as a member implicitly forward declares.

drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h line 44

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +1 -0
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param);
 void nbl_core_remove(struct nbl_adapter *adapter);
+
 #endif

This chunk should be squashed into an earlier patch

Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +15 -0
+#define NBL_CHAN_SEND(chan_send, dst_id, mesg_type, argument, arg_length,\
+		      response, resp_length, need_ack)			\
+do {									\
+	typeof(chan_send)	*__chan_send = &(chan_send);		\
+	__chan_send->dstid	= (dst_id);				\
+	__chan_send->msg_type	= (mesg_type);				\
+	__chan_send->arg	= (argument);				\
+	__chan_send->arg_len	= (arg_length);				\
+	__chan_send->resp	= (response);				\
+	__chan_send->resp_len	= (resp_length);			\
+	__chan_send->ack	= (need_ack);				\
+} while (0)
+
+#define NBL_CHAN_ACK(chan_ack, dst_id, mesg_type, msg_id, err_code, ack_data, \
+		     data_length)					\

drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +10 -0
+do {									\
+	typeof(chan_ack)	*__chan_ack = &(chan_ack);		\
+	__chan_ack->dstid	= (dst_id);				\
+	__chan_ack->msg_type	= (mesg_type);				\
+	__chan_ack->msgid	= (msg_id);				\
+	__chan_ack->err		= (err_code);				\
+	__chan_ack->data	= (ack_data);				\
+	__chan_ack->data_len	= (data_length);			\
+} while (0)
+

Why are these macros and not C code?
You only seem to pass struct nbl_chan_ack_info into NBL_CHAN_ACK()

Quoted 1 line

+struct nbl_hash_tbl_mgt;

This forward declaration here makes no sense.
Please look at your patches before you post them.

Quoted 8 lines

struct nbl_common_info {

drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +1 -0
 	struct pci_dev *pdev;
 	struct device *dev;
@@ -29,4 +31,19 @@ struct nbl_common_info {
 	u8 has_net;
 };
 
+struct nbl_hash_tbl_key {
maintainer
#10 lore raw

Re: [PATCH v22 net-next 04/12] net/nebula-matrix: add channel layer

In reply to illusion.wang

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
--- Patch [4]: [PATCH v22 net-next 04/12] net/nebula-matrix: add channel layer --- commit 52547754390ebdc264a4b6a5c891b4ecfbcd56a7
Author: illusion wang <[email protected]>

net/nebula-matrix: add channel layer

This patch introduces a channel management layer for the Nebula Matrix driver to handle communication between different components and drivers. It adds support for mailbox channels, queue initialization, hardware abstraction, and interrupt-driven receive paths with waitqueues for transmission.

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0 -0
new file mode 100644
index 0000000000000..85218f826f59d

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3 -0
+static void nbl_chan_clean_queue(struct nbl_channel_mgt *chan_mgt,
+				 struct nbl_chan_info *chan_info)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 664

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5 -0
+	rxq->next_to_clean = next_to_clean;
+	/* add READ_ONCE check to avoid UAF when clean_task is null*/
+	if (more_work && READ_ONCE(chan_info->clean_task))
+		schedule_work(chan_info->clean_task);
+}

[Severity: High]
Can this result in a NULL pointer dereference if chan_info->clean_task is cleared concurrently?

When calling schedule_work(chan_info->clean_task), the compiler fetches the pointer from memory a second time. If nbl_chan_teardown_queue() sets chan_info->clean_task = NULL right after the READ_ONCE() check but before the schedule_work() call, wouldn't a NULL pointer be passed to the workqueue API? Could a local variable be used to cache the pointer to avoid this?

[ ... ]

Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +19 -0
+static int nbl_chan_teardown_queue(struct nbl_channel_mgt *chan_mgt,
+				   u8 chan_type)
+{
+	struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type];
+	struct nbl_chan_waitqueue_head *wait_head;
+	u16 i;
+
+	/* Step 1: Mark shutdown flag, reject all new send requests */
+	WRITE_ONCE(chan_info->shutdown, true);
+
+	/* Stop hardware queues */
+	nbl_chan_stop_queue(chan_mgt);
+
+	/* Cancel any pending cleanup work */
+	if (chan_info->clean_task) {
+		cancel_work_sync(chan_info->clean_task);
+		chan_info->clean_task = NULL;
+	}
+	for (i = 0; i < chan_info->num_txq_entries; i++) {

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 304

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+	}
+
+	/* Step 2: Wait all in-flight send_msg threads exit via counter */
+	while (atomic_read(&chan_info->inflight_tx_cnt) != 0) {
+		/* synchronize atomic counter load with other CPUs */
+		smp_rmb();
+		usleep_range(100, 1000);
+	}
+	return 0;
+}

[Severity: High]
Is cancel_work_sync() called too early here?

Since cancel_work_sync() is called before waiting for inflight_tx_cnt to drain, could an in-flight sender thread currently executing its polling loop call queue_work() concurrently after the cancellation is finished? This might leave pending work in the queue that executes after the device has been torn down, causing a use-after-free regression.

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3 -0
+static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,
+			     struct nbl_chan_send_info *chan_send)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 746

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6 -0
+	/* Reject new send if shutdown already triggered */
+	if (READ_ONCE(chan_info->shutdown))
+		return -ESHUTDOWN;
+	/* Ensure shutdown load is ordered before inflight counter increment */
+	smp_rmb();
+	atomic_inc(&chan_info->inflight_tx_cnt);

[Severity: High]
Does this sequence create a TOCTOU race with nbl_chan_teardown_queue()?

If a sender thread checks READ_ONCE(chan_info->shutdown) and it is false, but the thread is then preempted before incrementing inflight_tx_cnt, could nbl_chan_teardown_queue() set shutdown = true, observe the counter is 0, and proceed to free resources? When the sender resumes, wouldn't it increment the counter and access destroyed queues?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 821

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +13 -0
+	if (test_bit(NBL_CHAN_INTERRUPT_READY, chan_info->state)) {
+		spin_lock_irq(&wait_head->status_lock);
+		while (!READ_ONCE(wait_head->acked)) {
+			spin_unlock_irq(&wait_head->status_lock);
+			ret = wait_event_timeout(wait_head->wait_queue,
+						 READ_ONCE(wait_head->acked),
+						 NBL_CHAN_ACK_WAIT_TIME);
+			spin_lock_irq(&wait_head->status_lock);
+
+			if (READ_ONCE(chan_info->shutdown)) {
+				ret = -ESHUTDOWN;
+				goto inflight_dec_out;
+			}

[Severity: Critical]
Does this error path leak the spinlock and leave interrupts disabled?

Since spin_lock_irq(&wait_head->status_lock) was called right before this check, and the inflight_dec_out label simply decrements the counter and returns, shouldn't spin_unlock_irq() be called before taking this goto?

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5 -0
+			if (ret == 0) {
+				if (READ_ONCE(wait_head->status) ==
+				    NBL_MBX_STATUS_WAITING) {
+					wait_head->status =
+						NBL_MBX_STATUS_TIMEOUT;

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 836

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+					wait_head->acked = 0;
+					wait_head->ack_data = NULL;
+					wait_head->ack_data_len = 0;
+				}
+				spin_unlock_irq(&wait_head->status_lock);
+				dev_err(dev,
+					"Channel waiting ack failed, message type: %d, msg id: %u\n",
+					chan_send->msg_type, msgid);
+				goto inflight_dec_out;
+			}

[Severity: High]
When wait_event_timeout() times out, it returns 0. If this path is taken, will the function incorrectly return 0 (success) instead of -ETIMEDOUT to the caller? This might lead callers to believe the transmission succeeded and read uninitialized response buffers.

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+	/* Polling: only init/deinit, add shutdown detect to avoid deadlock */
+	while (i--) {
+		if (READ_ONCE(chan_info->shutdown)) {
+			ret = -ESHUTDOWN;
+			goto inflight_dec_out;
+		}
+		/* Order shutdown read before accessing clean_task/workqueue */
+		smp_rmb();
+		if (READ_ONCE(chan_info->clean_task) && common->wq)
+			queue_work(common->wq, chan_info->clean_task);

[Severity: High]
Could this suffer from the same double-read TOCTOU race as in nbl_chan_clean_queue()?

If chan_info->clean_task is set to NULL after the READ_ONCE() check but before queue_work() evaluates its arguments, could this pass a NULL pointer to the workqueue core?

author maintainer
#11 lore raw

PATCH v22 5/12 net/nebula-matrix: add common resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

The Resource layer processes the entries/data of various modules within the processing chip to accomplish specific entry management operations, this describes the module business capabilities of the chip and the data it manages.
The resource layer comprises the following sub-modules: common, interrupt, and vsi(txrx,queue not contained this time)

This patch provides the common part, including the conversion relationships among vsi_id, func_id, eth_id, and pf_id. These relationships may be utilized in the upper layer or the resource layer.

Key Assumptions:
- nbl_res_start() initializes VSI/Eth/PF data structures **only for control devices** (common->has_ctrl == true).
- APIs like nbl_res_func_id_to_vsi_id() **are guaranteed to be called only on control devices** by the framework's dispatch layer.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   2 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  16 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   4 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  47 +++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  14 +
 .../nbl_hw_leonis/nbl_resource_leonis.c       | 284 ++++++++++++++++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |  10 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   | 148 +++++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  75 +++++
 .../nbl/nbl_include/nbl_def_common.h          |  19 ++
 .../nbl/nbl_include/nbl_def_hw.h              |   4 +
 .../nbl/nbl_include/nbl_def_resource.h        |  29 ++
 .../nbl/nbl_include/nbl_include.h             |   9 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 14 files changed, 670 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
index 6dc1539cee1f..831b6cb51c37 100644
@@ -6,4 +6,6 @@ obj-$(CONFIG_NBL) := nbl.o
 nbl-objs +=       nbl_common/nbl_common.o \
 				nbl_channel/nbl_channel.o \
 				nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
+				nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
+				nbl_hw/nbl_resource.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +16 -0
index ba6f94a36cde..f1cd8e7d8a7f 100644
@@ -6,6 +6,22 @@
 #include <linux/device.h>
 #include "nbl_common.h"
 
+u32 nbl_common_pf_id_subtraction_mgtpf_id(struct nbl_common_info *common,
+					  u32 pf_id)
+{
+	u32 diff = U32_MAX;
+
+	/*
+	 * Leonis hardware uses fixed mgt_pf=0, this range check + U32_MAX
+	 * sentinel are reserved for future hardware platforms which may
+	 * adopt non-zero management PF offset, keep unified conversion logic.
+	 */
+	if (pf_id >= common->mgt_pf)
+		diff = pf_id - common->mgt_pf;
+
+	return diff;
+}
+
 #define FNV_PRIME_32 0x01000193
 #define FNV_OFFSET_32 0x811C9DC5
 static u32 nbl_common_calc_hash_key(void *key, u32 key_size, u32 bucket_size)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +4 -0
index d6b7bfff3cc6..319d105436a1 100644
@@ -12,6 +12,8 @@
 
 struct nbl_hw_mgt;
 struct nbl_hw_ops_tbl;
+struct nbl_resource_mgt;
+struct nbl_resource_ops_tbl;
 struct nbl_channel_ops_tbl;
 struct nbl_channel_mgt;
 
@@ -22,11 +24,13 @@ enum {
 
 struct nbl_interface {
 	struct nbl_hw_ops_tbl *hw_ops_tbl;
+	struct nbl_resource_ops_tbl *resource_ops_tbl;
 	struct nbl_channel_ops_tbl *channel_ops_tbl;
 };
 
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
+	struct nbl_resource_mgt *res_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +47 -0

79 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +14 -0
index 1d2dd10e6239..1dee07cb7156 100644
@@ -67,4 +67,18 @@ struct nbl_mailbox_qinfo_cfg_table {
 #define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004)
 #define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040)
 
+#define NBL_PCIE_BUS_MASK	GENMASK(12, 5)
+#define NBL_FW_BOARD_CONFIG			0x200
+#define NBL_FW_BOARD_DW3_OFFSET			(NBL_FW_BOARD_CONFIG + 12)
+#define NBL_FW_BOARD_DW6_OFFSET			(NBL_FW_BOARD_CONFIG + 24)
+
+#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0)
+#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1)
+#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8)
+#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10)
+#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13)
+
+#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0)
+#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8)
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +284 -0

284 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +10 -0
new file mode 100644
index 000000000000..4e61a5c141e5
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_RESOURCE_LEONIS_H_
+#define _NBL_RESOURCE_LEONIS_H_
+
+#include "../nbl_resource.h"
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +148 -0

148 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +75 -0

75 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +19 -0
index 282377bad257..0e0ea10e20c7 100644
@@ -12,6 +12,21 @@
 #include "nbl_include.h"
 
 struct nbl_hash_tbl_mgt;
+#define NBL_TWO_ETHERNET_PORT			2
+#define NBL_FOUR_ETHERNET_PORT			4
+#define NBL_DEFAULT_VSI_ID_GAP			1024
+#define NBL_TWO_ETHERNET_VSI_ID_GAP		512
+#define NBL_FOUR_ETHERNET_VSI_ID_GAP		256
+
+#define NBL_VSI_ID_GAP(m)					\
+	({							\
+		typeof(m) _m = (m);				\
+		_m == NBL_FOUR_ETHERNET_PORT ?			\
+			NBL_FOUR_ETHERNET_VSI_ID_GAP :		\
+			(_m == NBL_TWO_ETHERNET_PORT ?		\
+				 NBL_TWO_ETHERNET_VSI_ID_GAP :	\
+				 NBL_DEFAULT_VSI_ID_GAP);	\
+	})
 
 struct nbl_common_info {
 	struct pci_dev *pdev;
@@ -26,6 +41,7 @@ struct nbl_common_info {
 	u8 devid;
 	u8 bus;
 	u8 hw_bus;
+	u16 mgt_pf;
 
 	u8 has_ctrl;
 	u8 has_net;
@@ -39,6 +55,9 @@ struct nbl_hash_tbl_key {
 	u16 resv;
 };
 
+u32 nbl_common_pf_id_subtraction_mgtpf_id(struct nbl_common_info *common,
+					  u32 pf_id);
+
 struct nbl_hash_tbl_mgt *
 nbl_common_init_hash_table(struct nbl_hash_tbl_key *key);
 void nbl_common_remove_hash_table(struct nbl_hash_tbl_mgt *tbl_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +4 -0
index 08be57631453..b56b3c230c58 100644
@@ -20,9 +20,13 @@ struct nbl_hw_ops {
 	void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt);
 	void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt);
 	u32 (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt);
+	u8 (*get_real_bus)(struct nbl_hw_mgt *hw_mgt);
 
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);
+	u32 (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt);
+	void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,
+			       struct nbl_board_port_info *board);
 };
 
 struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
new file mode 100644
index 000000000000..cf034ab589fd
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_RESOURCE_H_
+#define _NBL_DEF_RESOURCE_H_
+
+#include <linux/types.h>
+
+struct nbl_resource_mgt;
+struct nbl_adapter;
+
+struct nbl_resource_ops {
+	int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			  u16 type, u16 *vsi_id);
+	int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			  u16 vsi_id, u8 *eth_num, u8 *eth_id,
+			  u8 *logic_eth_id);
+};
+
+struct nbl_resource_ops_tbl {
+	struct nbl_resource_ops *ops;
+	struct nbl_resource_mgt *priv;
+};
+
+int nbl_res_init_leonis(struct nbl_adapter *adapter);
+void nbl_res_remove_leonis(struct nbl_adapter *adapter);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +9 -0
index 0ea3e8551660..b0abbb2b58d2 100644
@@ -16,6 +16,15 @@
 		typeof(id) _id = (id);			\
 		((_id) == (max) ? 0 : (_id) + 1);	\
 	})
+
+#define NBL_MAX_FUNC					520
+#define NBL_MAX_ETHERNET				4
+
+enum {
+	NBL_VSI_DATA = 0,
+	NBL_VSI_MAX,
+};
+
 struct nbl_func_caps {
 	u32 has_ctrl:1;
 	u32 has_net:1;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
index 94884f388115..0e51dd65ee48 100644
@@ -10,6 +10,7 @@
 #include "nbl_include/nbl_include.h"
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
+#include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -27,6 +28,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	adapter->pdev = pdev;
 	common = &adapter->common;
 
+	common->mgt_pf = 0;
 	common->pdev = pdev;
 	common->dev = &pdev->dev;
 	common->has_ctrl = param->caps.has_ctrl;
@@ -42,7 +44,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_chan_init_common(adapter);
 	if (ret)
 		goto chan_init_fail;
+
+	ret = nbl_res_init_leonis(adapter);
+	if (ret)
+		goto res_init_fail;
 	return adapter;
+res_init_fail:
+	nbl_chan_remove_common(adapter);
 chan_init_fail:
 	nbl_hw_remove_leonis(adapter);
 hw_init_fail:
@@ -51,6 +59,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
 }
Signature · 1 line
2.47.3
maintainer
#12 lore raw

Re: [PATCH v22 net-next 05/12] net/nebula-matrix: add common resource implementation

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [5]: [PATCH v22 net-next 05/12] net/nebula-matrix: add common resource implementation --- commit d40e580d6fb636a87bb6f2eb1a3079e1e85c78a0
Author: illusion wang <[email protected]>

net/nebula-matrix: add common resource implementation

The patch introduces the common resource implementation for the Nebula Matrix driver. It provides conversions among vsi_id, func_id, eth_id, and pf_id, and sets up initialization for the control devices.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0 -0
index b37df49f86c80..4c7eea24c70ed 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static u32 nbl_hw_get_host_pf_mask(struct nbl_hw_mgt *hw_mgt) · line 161

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5 -0
@@ -133,6 +154,14 @@ static u32 nbl_hw_get_host_pf_mask(struct nbl_hw_mgt *hw_mgt)
 	return data;
 }
 
+static u8 nbl_hw_get_real_bus(struct nbl_hw_mgt *hw_mgt)
+{
+	u32 data;
+
+	data = nbl_hw_rd32(hw_mgt, NBL_PCIE_HOST_TL_CFG_BUSDEV);

[Severity: High]
Will this cause a kernel panic due to an out-of-bounds MMIO read?

During device initialization, nbl_res_ctrl_dev_sriov_info_init() calls hw_ops->get_real_bus(), which performs an MMIO read on NBL_PCIE_HOST_TL_CFG_BUSDEV.

Since NBL_PCIE_HOST_TL_CFG_BUSDEV is defined using NBL_INTF_HOST_PCIE_BASE (which is roughly a 21 MiB offset), and the driver only maps a 16 MiB PCI BAR during nbl_hw_init_leonis(), this appears to read from an unmapped physical address.

Similarly, the call to hw_ops->get_host_pf_mask() from nbl_res_init_pf_num() will read from NBL_PCIE_HOST_K_PF_MASK_REG, which also evaluates to an out-of-bounds register address.

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +3 -0
+	return FIELD_GET(NBL_PCIE_BUS_MASK, data);
+}
+
author maintainer
#13 lore raw

PATCH v22 6/12 net/nebula-matrix: add intr resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add nbl_interrupt module to manage driver global MSI-X vector indices, and extend hw_ops with callbacks to program vendor-specific internal MSI-X mapping registers, configure MSI-X metadata, and bind interrupts to PF mailbox channels.

Key interfaces:
- configure_msix_map:
Allocates driver global MSI-X indices via separate net/other interrupt bitmaps (interrupt_net_bitmap / interrupt_others_bitmap). Preallocates all required coherent DMA resources first; only tears down old hardware configuration after all new allocations succeed. Programs NBL_PCOMPLETER_FUNCTION_MSIX_MAP with the MSI-X table DMA address and function BDF info. PCI MSI-X vector allocation itself is performed via nbl_dev_alloc_msix_intr() at upper layer.

- destroy_msix_map:
Releases allocated global vector indices, clears hardware MSI-X mappings, frees DMA buffer and interrupt array. A delay is inserted before releasing DMA memory to mitigate potential IOMMU faults caused by in-flight hardware DMA access after MMIO disable.

- set_mailbox_irq:
Enables or disables MSI-X routing for a given PF mailbox by updating NBL_MAILBOX_QINFO_MAP_REG_ARR with the target global vector id.

- configure_msix_info:
Programs PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE to record function BDF and MSI-X mask enable attribute for each global interrupt vector.

This module manages chip-internal MSI-X routing table and global vector index space. It does NOT invoke kernel PCI MSI-X allocation helpers (pci_alloc_irq_vectors, pci_msix_alloc_irq_at, irq_domain); physical PCI MSI-X vector allocation belongs to separate device layer.

Interrupt manager instance is created during resource startup (nbl_intr_mgt_start) and attached to resource management context.

Note: Mutual exclusion for configure_msix_map, destroy_msix_map, and set_mailbox_irq is enforced by dispatch layer. These routines assume caller holds required locks.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 121 +++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  42 +++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |   9 +
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  | 335 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |  21 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  33 ++
 .../nbl/nbl_include/nbl_def_hw.h              |  10 +
 .../nbl/nbl_include/nbl_def_resource.h        |   6 +
 10 files changed, 579 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index 831b6cb51c37..bcedf278bab2 100644
@@ -8,4 +8,5 @@ nbl-objs +=       nbl_common/nbl_common.o \
 				nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
 				nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
 				nbl_hw/nbl_resource.o \
+				nbl_hw/nbl_interrupt.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +121 -0

145 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +42 -0

48 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +9 -0
index cd2d960df24b..e070ade09fee 100644
@@ -10,6 +10,9 @@
 static struct nbl_resource_ops res_ops = {
 	.get_vsi_id = nbl_res_func_id_to_vsi_id,
 	.get_eth_id = nbl_res_get_eth_id,
+	.configure_msix_map = nbl_res_intr_configure_msix_map,
+	.destroy_msix_map = nbl_res_intr_destroy_msix_map,
+	.set_mailbox_irq = nbl_res_intr_set_mailbox_irq,
 };
 
 static struct nbl_resource_mgt *
@@ -243,7 +246,12 @@ static int nbl_res_start(struct nbl_resource_mgt *res_mgt)
 		ret = nbl_res_ctrl_dev_vsi_info_init(res_mgt);
 		if (ret)
 			return ret;
+
+		ret = nbl_intr_mgt_start(res_mgt);
+		if (ret)
+			return ret;
 	}
+
 	return 0;
 }
 
@@ -276,6 +284,7 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)
 	}
 	adap->intf.resource_ops_tbl = res_ops_tbl;
 	adap->core.res_mgt = res_mgt;
+
 	return 0;
 }
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index 4e61a5c141e5..1da2abcaf00f 100644
@@ -7,4 +7,5 @@
 #define _NBL_RESOURCE_LEONIS_H_
 
 #include "../nbl_resource.h"
+#include "../nbl_interrupt.h"
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +335 -0

335 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +21 -0
new file mode 100644
index 000000000000..5aa46a4fce4c
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_INTERRUPT_H_
+#define _NBL_INTERRUPT_H_
+
+#include "nbl_resource.h"
+
+#define NBL_MSIX_MAP_TABLE_MAX_ENTRIES	1024
+int nbl_res_intr_destroy_msix_map(struct nbl_resource_mgt *res_mgt,
+				  u16 func_id);
+int nbl_res_intr_configure_msix_map(struct nbl_resource_mgt *res_mgt,
+				    u16 func_id, u16 num_net_msix,
+				    u16 num_others_msix,
+				    bool net_msix_mask_en);
+int nbl_res_intr_set_mailbox_irq(struct nbl_resource_mgt *res_mgt,
+				 u16 func_id, u16 vector_id,
+				 bool enable_msix);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +33 -0
index cd3fe480e5bc..49e6a817542e 100644
@@ -17,6 +17,38 @@
 
 struct nbl_resource_mgt;
 
+/* --------- INTERRUPT ---------- */
+#define NBL_MAX_OTHER_INTERRUPT			1024
+#define NBL_MAX_NET_INTERRUPT			4096
+#define NBL_NET_INTR_BASE		NBL_MAX_OTHER_INTERRUPT
+
+#define NBL_MSIX_MAP_VALID_MASK		BIT(0)
+#define NBL_MSIX_MAP_INDEX_MASK		GENMASK(13, 1)
+#define NBL_MSIX_MAP_RSV_MASK		GENMASK(15, 14)
+
+struct nbl_msix_map {
+	__le16 data;
+};
+
+struct nbl_msix_map_table {
+	struct nbl_msix_map *base_addr;
+	dma_addr_t dma;
+	size_t size;
+};
+
+struct nbl_func_interrupt_resource_mng {
+	u16 num_interrupts;
+	u16 num_net_interrupts;
+	u16 *interrupts;
+	struct nbl_msix_map_table msix_map_table;
+};
+
+struct nbl_interrupt_mgt {
+	DECLARE_BITMAP(interrupt_net_bitmap, NBL_MAX_NET_INTERRUPT);
+	DECLARE_BITMAP(interrupt_others_bitmap, NBL_MAX_OTHER_INTERRUPT);
+	struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC];
+};
+
 /* --------- INFO ---------- */
 struct nbl_sriov_info {
 	unsigned int bdf;
@@ -70,6 +102,7 @@ int nbl_res_func_id_to_bdf(struct nbl_resource_mgt *res_mgt, u16 func_id,
 			   u8 *bus, u8 *dev, u8 *function);
 int nbl_res_get_eth_id(struct nbl_resource_mgt *res_mgt, u16 func_id,
 		       u16 vsi_id, u8 *eth_num, u8 *eth_id, u8 *logic_eth_id);
+int nbl_intr_mgt_start(struct nbl_resource_mgt *res_mgt);
 int nbl_res_pf_dev_vsi_type_to_hw_vsi_type(u16 src_type,
 					   enum nbl_vsi_serv_type *dst_type);
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10 -0
index b56b3c230c58..57ea3c64648d 100644
@@ -11,6 +11,14 @@
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	void (*configure_msix_map)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+				   bool valid, dma_addr_t dma_addr, u8 bus,
+				   u8 devid, u8 function);
+	void (*configure_msix_info)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+				    bool valid, u16 interrupt_id, u8 bus,
+				    u8 devid, u8 function,
+				    bool net_msix_mask_en);
+	void (*flush_write)(struct nbl_hw_mgt *hw_mgt);
 	void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,
 					      u16 tail_ptr, u8 txrx);
 	void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
@@ -24,6 +32,8 @@ struct nbl_hw_ops {
 
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);
+	void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+				bool enable_msix, u16 global_vec_id);
 	u32 (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt);
 	void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,
 			       struct nbl_board_port_info *board);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
index cf034ab589fd..9e6995ff6c6f 100644
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;
 struct nbl_adapter;
 
 struct nbl_resource_ops {
+	int (*configure_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+				  u16 num_net_msix, u16 num_others_msix,
+				  bool net_msix_mask_en);
+	int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id);
+	int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			       u16 vector_id, bool enable_msix);
 	int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
 			  u16 type, u16 *vsi_id);
 	int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
Signature · 1 line
2.47.3
maintainer
#14 lore raw

Re: [PATCH v22 net-next 06/12] net/nebula-matrix: add intr resource implementation

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [6]: [PATCH v22 net-next 06/12] net/nebula-matrix: add intr resource implementation --- commit 32d01aebd4d29040305943012638ac9e59c45fb8
Author: illusion wang <[email protected]>

net/nebula-matrix: add intr resource implementation

This commit adds the nbl_interrupt module to manage driver global MSI-X vector indices. It extends hw_ops with callbacks to program vendor-specific internal MSI-X mapping registers, configure MSI-X metadata, and bind interrupts to PF mailbox channels.

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0 -0
new file mode 100644
index 0000000000000..cb6874d13a88f

[ ... ]

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0 -0
@@ -0,0 +1,335 @@

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 272

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +13 -0
+release_net_bits:
+	while (i--) {
+		intr_index = tmp_interrupts[i];
+		if (intr_index >= NBL_NET_INTR_BASE)
+			clear_bit(intr_index - NBL_NET_INTR_BASE,
+				  intr_mgt->interrupt_net_bitmap);
+		else
+			clear_bit(intr_index,
+				  intr_mgt->interrupt_others_bitmap);
+	}
+	i = num_net_msix;
+release_all_bits:
+	while (i--) {

[Severity: High]
Does this fall-through inadvertently corrupt the global interrupt bitmaps?

If resource allocation fails in the first loop for net interrupts, the code jumps to release_net_bits, loops i down to 0, sets i = num_net_msix, and then falls through into release_all_bits.

Because tmp_interrupts was allocated with devm_kcalloc, any uninitialized entries are 0. When the second loop evaluates these uninitialized zero values, 0 < NBL_NET_INTR_BASE, meaning the code will clear bit 0 in interrupt_others_bitmap and also doubly clear the already-released net bits.

Should there be a jump to free_prealloc right before release_all_bits to avoid evaluating the array twice?

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10 -0
+		intr_index = tmp_interrupts[i];
+		if (intr_index >= NBL_NET_INTR_BASE)
+			clear_bit(intr_index - NBL_NET_INTR_BASE,
+				  intr_mgt->interrupt_net_bitmap);
+		else
+			clear_bit(intr_index,
+				  intr_mgt->interrupt_others_bitmap);
+	}
+	goto free_prealloc;
+}
author maintainer
#15 lore raw

PATCH v22 7/12 net/nebula-matrix: add chip-wide hardware init/deinit implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add Leonis chip-wide hardware initialization and deinitialization logic to setup the full datapath pipeline, including packet engines, scheduler, buffer stores, queue manager, port traffic shaping, and flow control, and the driver_status hardware flag consumed by firmware.

HW layer overview:
The HW layer code is highly chip-specific and may benefit from additional review since it cannot be cross-checked against other implementations.

DP sub-init modules (called from nbl_dp_init()):
- dped, uped: Data/User Packet Engine Driver
- dsch: Scheduler core (qid limit init, PSHA enable inside shaping init)
- ustore, dstore: Buffer Store modules
- dvn, uvn: Virtual Descriptor Network modules
- uqm: Queue Manager
- nbl_shaping_init(): Per-port traffic shaping + DSCH PSHA config

Chip init sequence (nbl_hw_init_chip_module()):
1. nbl_dp_init() — All DP sub-modules listed above
2. nbl_intf_init() — Host adapter padpt flow control
- nbl_host_padpt_init() — Host padpt flow control registers
3. nbl_hw_set_driver_status() + nbl_flush_writes()

Chip deinit logic relies on firmware cleanup: only driver_status flag is cleared and flushed; FW releases partial hardware state automatically.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |  26 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |  12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 524 ++++++++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  | 241 ++++++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |   2 +
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   1 +
 .../nbl/nbl_include/nbl_def_hw.h              |   3 +
 .../nbl/nbl_include/nbl_def_resource.h        |   3 +
 .../nbl/nbl_include/nbl_include.h             |  12 +
 10 files changed, 825 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index bcedf278bab2..ef5b6ada70e5 100644
@@ -9,4 +9,5 @@ nbl-objs +=       nbl_common/nbl_common.o \
 				nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
 				nbl_hw/nbl_resource.o \
 				nbl_hw/nbl_interrupt.o \
+				nbl_hw/nbl_chip.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +26 -0
new file mode 100644
index 000000000000..c079cde24966
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+#include <linux/device.h>
+#include "nbl_chip.h"
+
+void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt)
+{
+	struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;
+
+	hw_ops->deinit_module(res_mgt->hw_ops_tbl->priv);
+}
+
+int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt)
+{
+	u8 eth_speed = res_mgt->resource_info->board_info.eth_speed;
+	u8 eth_num = res_mgt->resource_info->board_info.eth_num;
+	struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;
+	struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv;
+	int ret;
+
+	ret = hw_ops->init_module(p, eth_speed, eth_num);
+
+	return ret;
+}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h new file +12 -0
new file mode 100644
index 000000000000..5acc7bce2b11
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_VSI_H_
+#define _NBL_VSI_H_
+
+#include "nbl_resource.h"
+int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt);
+void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +524 -0

536 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +241 -0

263 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +2 -0
index e070ade09fee..c4a465c3c7af 100644
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = {
 	.configure_msix_map = nbl_res_intr_configure_msix_map,
 	.destroy_msix_map = nbl_res_intr_destroy_msix_map,
 	.set_mailbox_irq = nbl_res_intr_set_mailbox_irq,
+	.init_module = nbl_res_chip_init_module,
+	.deinit_module = nbl_res_chip_deinit_module,
 };
 
 static struct nbl_resource_mgt *
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index 1da2abcaf00f..f9a53b5d4627 100644
@@ -8,4 +8,5 @@
 
 #include "../nbl_resource.h"
 #include "../nbl_interrupt.h"
+#include "../nbl_chip.h"
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +3 -0
index 57ea3c64648d..4f4a23c95c1b 100644
@@ -11,6 +11,9 @@
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	int (*init_module)(struct nbl_hw_mgt *hw_mgt, u8 eth_speed, u8 eth_num);
+	void (*deinit_module)(struct nbl_hw_mgt *hw_mgt);
+
 	void (*configure_msix_map)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				   bool valid, dma_addr_t dma_addr, u8 bus,
 				   u8 devid, u8 function);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +3 -0
index 9e6995ff6c6f..6aa1342a93c8 100644
@@ -12,6 +12,9 @@ struct nbl_resource_mgt;
 struct nbl_adapter;
 
 struct nbl_resource_ops {
+	int (*init_module)(struct nbl_resource_mgt *res_mgt);
+	void (*deinit_module)(struct nbl_resource_mgt *res_mgt);
+
 	int (*configure_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id,
 				  u16 num_net_msix, u16 num_others_msix,
 				  bool net_msix_mask_en);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +12 -0
index b0abbb2b58d2..5cd0dac5a776 100644
@@ -35,4 +35,16 @@ struct nbl_init_param {
 	struct nbl_func_caps caps;
 };
 
+enum nbl_fw_port_speed {
+	NBL_FW_PORT_SPEED_10G,
+	NBL_FW_PORT_SPEED_25G,
+	NBL_FW_PORT_SPEED_50G,
+	NBL_FW_PORT_SPEED_100G,
+};
+
+enum nbl_performance_mode {
+	NBL_QUIRKS_NO_TOE,
+	NBL_QUIRKS_UVN_PREFETCH_ALIGN,
+};
+
 #endif
Signature · 1 line
2.47.3
maintainer
#16 lore raw

Re: [PATCH v22 net-next 07/12] net/nebula-matrix: add chip-wide hardware init/deinit implementation

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [7]: [PATCH v22 net-next 07/12] net/nebula-matrix: add chip-wide hardware init/deinit implementation --- commit c620485c32e37b926b2895bd18463f304a29e084
Author: illusion wang <[email protected]>

net/nebula-matrix: add chip-wide hardware init/deinit implementation

This commit adds Leonis chip-wide hardware initialization and deinitialization logic to setup the full datapath pipeline.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0 -0
index 1c136b9e30b2a..22690cb9cc32b 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +4 -0
+static int nbl_shaping_eth_init(struct nbl_hw_mgt *hw_mgt, u8 eth_id, u8 speed)
+{
+	union nbl_shaping_dvn_dport_u dvn_dport = { 0 };
+	union nbl_shaping_dport_u dport = { 0 };

[ ... ]

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +7 -0
+	/* 2. write config words (valid=0, safe) */
+	dport.info.low = FIELD_PREP(DPORT_CIR_MASK, rate) |
+			 FIELD_PREP(DPORT_PIR_MASK, rate) |
+			 FIELD_PREP(DPORT_DEPTH_MASK, depth) |
+			 FIELD_PREP(DPORT_CBS_MASK_LOW, depth & 0x3F);
+	dport.info.high = FIELD_PREP(DPORT_CBS_MASK_HIGH, depth >> 6) |
+			  FIELD_PREP(DPORT_PBS_MASK, depth);

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2 -0
+	nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DPORT_REG(eth_id), dport.data,
+		       sizeof(dport));

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0 -0
index 1d6d614be7d69..8e59b9d2ab3b0 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h struct nbl_function_msix_map { · line 307

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +7 -0
+union nbl_shaping_dport_u {
+	struct nbl_shaping_dport {
+		u64 low;
+		u64 high;
+	} info;
+	u32 data[NBL_SHAPING_DPORT_DWLEN];
+};

[Severity: High]
Will this union alias cause corrupted hardware writes on big-endian architectures?

When fields are populated using native u64 in nbl_shaping_eth_init(), for example:

dport.info.low = FIELD_PREP(DPORT_CIR_MASK, rate) | ...

And then written via the u32 array alias:

nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DPORT_REG(eth_id), dport.data,
sizeof(dport));

On big-endian systems, the upper 32 bits of the 64-bit integer will map to data[0] instead of the lower 32 bits. Does this result in malformed hardware configuration for traffic shaping?

author maintainer
#17 lore raw

PATCH v22 8/12 net/nebula-matrix: dispatch: add control-level routing core infrastructure

In reply to illusion.wang

From: illusion wang <[email protected]>

Add base dispatch layer infrastructure for control-level routing:
1. Dispatch management & ops table structures allocation
2. X-macro op table template for uniform dispatch entry registration
3. Control PF / regular PF routing logic via ctrl_lvl bitmask
4. Local chip init/deinit dispatch wrappers (no channel dependency)

Document constraint: init_module/deinit_module only valid on Control PF, caller must guard with has_ctrl to avoid NULL deref.

This patch only provides core routing skeleton, no channel message handling or resource locking logic.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nbl/nbl_channel/nbl_channel.c             |   4 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   4 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 137 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |  24 +++
 .../nbl/nbl_include/nbl_def_channel.h         |  26 ++++
 .../nbl/nbl_include/nbl_def_dispatch.h        |  42 ++++++
 .../nbl/nbl_include/nbl_include.h             |  20 +++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   8 +
 9 files changed, 266 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index ef5b6ada70e5..56464f576cbe 100644
@@ -10,4 +10,5 @@ nbl-objs +=       nbl_common/nbl_common.o \
 				nbl_hw/nbl_resource.o \
 				nbl_hw/nbl_interrupt.o \
 				nbl_hw/nbl_chip.o \
+				nbl_core/nbl_dispatch.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +4 -0
index 85218f826f59..eb0d55dad944 100644
@@ -1004,6 +1004,10 @@ int nbl_chan_init_common(struct nbl_adapter *adap)
 	struct nbl_channel_mgt *chan_mgt;
 	int ret;
 
+	BUILD_BUG_ON(sizeof(struct nbl_chan_param_cfg_msix_map) != 8);
+	BUILD_BUG_ON(sizeof(struct nbl_chan_param_set_mailbox_irq) != 4);
+	BUILD_BUG_ON(sizeof(struct nbl_chan_param_get_vsi_id) != 4);
+	BUILD_BUG_ON(sizeof(struct nbl_chan_param_get_eth_id) != 8);
 	chan_mgt = nbl_chan_setup_chan_mgt(adap);
 	if (IS_ERR(chan_mgt)) {
 		ret = PTR_ERR(chan_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +4 -0
index 319d105436a1..a1f874bb03c6 100644
@@ -14,6 +14,8 @@ struct nbl_hw_mgt;
 struct nbl_hw_ops_tbl;
 struct nbl_resource_mgt;
 struct nbl_resource_ops_tbl;
+struct nbl_dispatch_mgt;
+struct nbl_dispatch_ops_tbl;
 struct nbl_channel_ops_tbl;
 struct nbl_channel_mgt;
 
@@ -25,12 +27,14 @@ enum {
 struct nbl_interface {
 	struct nbl_hw_ops_tbl *hw_ops_tbl;
 	struct nbl_resource_ops_tbl *resource_ops_tbl;
+	struct nbl_dispatch_ops_tbl *dispatch_ops_tbl;
 	struct nbl_channel_ops_tbl *channel_ops_tbl;
 };
 
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
 	struct nbl_resource_mgt *res_mgt;
+	struct nbl_dispatch_mgt *disp_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +137 -0

137 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +24 -0
new file mode 100644
index 000000000000..f06b90075af4
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DISPATCH_H_
+#define _NBL_DISPATCH_H_
+#include "../nbl_include/nbl_include.h"
+#include "../nbl_include/nbl_def_channel.h"
+#include "../nbl_include/nbl_def_hw.h"
+#include "../nbl_include/nbl_def_resource.h"
+#include "../nbl_include/nbl_def_dispatch.h"
+#include "../nbl_include/nbl_def_common.h"
+#include "../nbl_core.h"
+
+struct nbl_dispatch_mgt {
+	struct nbl_common_info *common;
+	struct nbl_resource_ops_tbl *res_ops_tbl;
+	struct nbl_channel_ops_tbl *chan_ops_tbl;
+	struct nbl_dispatch_ops_tbl *disp_ops_tbl;
+	DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX);
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +26 -0
index e581524888e5..fddceac94b8f 100644
@@ -282,6 +282,32 @@ enum nbl_chan_state {
 	NBL_CHAN_STATE_NBITS
 };
 
+struct nbl_chan_param_cfg_msix_map {
+	__le16 num_net_msix;
+	__le16 num_others_msix;
+	__le16 msix_mask_en;
+	__le16 rsvd;
+};
+
+struct nbl_chan_param_set_mailbox_irq {
+	__le16 vector_id;
+	u8 enable_msix;
+	u8 rsvd;
+};
+
+struct nbl_chan_param_get_vsi_id {
+	__le16 vsi_id;
+	__le16 type;
+};
+
+struct nbl_chan_param_get_eth_id {
+	__le16 vsi_id;
+	u8 eth_num;
+	u8 eth_id;
+	u8 logic_eth_id;
+	u8 rsvd[3];
+};
+
 struct nbl_board_port_info {
 	u8 eth_num;
 	u8 eth_speed;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +42 -0

42 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +20 -0
index 5cd0dac5a776..35fdb4a631c5 100644
@@ -19,6 +19,8 @@
 
 #define NBL_MAX_FUNC					520
 #define NBL_MAX_ETHERNET				4
+/* Used for macros to pass checkpatch */
+#define NBL_NAME(x)					x
 
 enum {
 	NBL_VSI_DATA = 0,
@@ -35,6 +37,10 @@ struct nbl_init_param {
 	struct nbl_func_caps caps;
 };
 
+/*
+ * Firmware ABI defines port speed enum fixed, value 0 represents 10G, cannot
+ * reassign 0 to INVALID for compatibility
+ */
 enum nbl_fw_port_speed {
 	NBL_FW_PORT_SPEED_10G,
 	NBL_FW_PORT_SPEED_25G,
@@ -42,6 +48,20 @@ enum nbl_fw_port_speed {
 	NBL_FW_PORT_SPEED_100G,
 };
 
+#define NBL_OPS_CALL(func, para)		\
+do {						\
+	typeof(func) _func = (func);		\
+	if (_func)				\
+		_func para;			\
+} while (0)
+
+/* Optional ops: NULL means not implemented, return 0 = no-op (not an error) */
+#define NBL_OPS_CALL_RET(func, para)		\
+({						\
+	typeof(func) _func = (func);		\
+	_func ? _func para : 0;			\
+})
+
 enum nbl_performance_mode {
 	NBL_QUIRKS_NO_TOE,
 	NBL_QUIRKS_UVN_PREFETCH_ALIGN,
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
index 0e51dd65ee48..d2ea55f5d568 100644
@@ -11,6 +11,7 @@
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
+#include "nbl_include/nbl_def_dispatch.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -48,7 +49,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_res_init_leonis(adapter);
 	if (ret)
 		goto res_init_fail;
+
+	ret = nbl_disp_init(adapter);
+	if (ret)
+		goto disp_init_fail;
 	return adapter;
+disp_init_fail:
+	nbl_res_remove_leonis(adapter);
 res_init_fail:
 	nbl_chan_remove_common(adapter);
 chan_init_fail:
@@ -59,6 +66,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
Signature · 1 line
2.47.3
author maintainer
#18 lore raw

PATCH v22 9/12 net/nebula-matrix: dispatch: add cross-version channel message framework

In reply to illusion.wang

From: illusion wang <[email protected]>

Implement bidirectional channel request/response RPC handlers for 5 dispatch resource operations: get_vsi_id, get_eth_id, configure_msix_map, destroy_msix_map, set_mailbox_irq.

- Extend X-macro NBL_DISP_OPS_TBL to pair local dispatch entry points with cross-PF mailbox request/response callbacks.
- Add registration helper nbl_disp_setup_msg() to auto-register channel response handlers for ops with valid msg_type.
- Introduce NBL_CHAN_RESP_UNIMPLEMENTED dedicated error code for missing resource ops implementation on remote PF.
- Add dev_err logging when sending RPC ACK back to remote PF fails.

The existing init_module/deinit_module dispatch entries use msg_type = -1, so they do not register any mailbox channel handlers and are excluded from RPC logic.

- Separate local channel transmission errors and remote RPC wire response codes:
The channel layer returns ACK header err via nbl_chan_send_msg() when wait_ack=1. Translate wire protocol defined remote codes NBL_CHAN_RESP_* to standard kernel errno at dispatch request wrapper to avoid semantic confusion between wire handshake values and system error numbers exposed to upper layers.
- Collapse all fine-grained resource operation sub-errors into generic NBL_CHAN_RESP_ERR on wire to keep message payload layout unchanged and maintain backward compatibility with legacy firmware.
- Fix unimplemented ops check order in response handler to prevent NULL pointer invocation of resource ops.

---
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 445 ++++++++++++++++++
 1 file changed, 445 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +445 -0
index 8116643859c7..c82c336f50e5 100644
@@ -6,6 +6,149 @@
 #include <linux/pci.h>
 #include "nbl_dispatch.h"
 
+static int nbl_disp_chan_get_vsi_id_req(struct nbl_dispatch_mgt *disp_mgt,
+					u16 type, u16 *vsi_id)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_get_vsi_id result = { 0 };
+	struct nbl_chan_param_get_vsi_id param = { 0 };
+	struct nbl_chan_send_info chan_send;
+	int ret;
+
+	param.type = cpu_to_le16(type);
+
+	NBL_CHAN_SEND(chan_send, common->mgt_pf, NBL_CHAN_MSG_GET_VSI_ID,
+		      &param, sizeof(param), &result, sizeof(result), 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_OK:
+		break;
+	default:
+		return ret;
+	}
+	*vsi_id = le16_to_cpu(result.vsi_id);
+	return 0;
+}
+
+static void nbl_disp_chan_get_vsi_id_resp(void *priv, u16 src_id, u16 msg_id,
+					  void *data, u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_param_get_vsi_id result = { 0 };
+	struct nbl_chan_param_get_vsi_id param = { 0 };
+	struct nbl_chan_ack_info chan_ack;
+	int err = NBL_CHAN_RESP_OK;
+	u16 vsi_id = 0;
+	int copy_len;
+	int ret;
+
+	copy_len = min_t(size_t, data_len, sizeof(param));
+	memcpy(&param, data, copy_len);
+	if (!res_ops->get_vsi_id) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->get_vsi_id,
+				       (p, src_id, le16_to_cpu(param.type),
+					&vsi_id));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	}
+	result.vsi_id = cpu_to_le16(vsi_id);
+	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_GET_VSI_ID, msg_id, err,
+		     &result, sizeof(result));
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_GET_VSI_ID);
+}
+
+static int nbl_disp_chan_get_eth_id_req(struct nbl_dispatch_mgt *disp_mgt,
+					u16 vsi_id, u8 *eth_num, u8 *eth_id,
+					u8 *logic_eth_id)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_get_eth_id result = { 0 };
+	struct nbl_chan_param_get_eth_id param = { 0 };
+	struct nbl_chan_send_info chan_send;
+	int ret;
+
+	param.vsi_id = cpu_to_le16(vsi_id);
+
+	NBL_CHAN_SEND(chan_send, common->mgt_pf, NBL_CHAN_MSG_GET_ETH_ID,
+		      &param, sizeof(param), &result, sizeof(result), 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_OK:
+		break;
+	default:
+		return ret;
+	}
+	*eth_num = result.eth_num;
+	*eth_id = result.eth_id;
+	*logic_eth_id = result.logic_eth_id;
+
+	return 0;
+}
+
+static void nbl_disp_chan_get_eth_id_resp(void *priv, u16 src_id, u16 msg_id,
+					  void *data, u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_chan_param_get_eth_id result = { 0 };
+	struct nbl_chan_param_get_eth_id param = { 0 };
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = NBL_CHAN_RESP_OK;
+	int copy_len;
+	int ret;
+
+	/*
+	 * The responder may run an older version than the requestor, so
+	 * data_len < sizeof(param) is expected and handled by min-copy +
+	 * zero-fill. Rejecting short responses would break cross-version
+	 * interop
+	 */
+	copy_len = min_t(size_t, data_len, sizeof(param));
+	memcpy(&param, data, copy_len);
+
+	if (!res_ops->get_eth_id) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->get_eth_id,
+				       (p, src_id, le16_to_cpu(param.vsi_id),
+					&result.eth_num, &result.eth_id,
+					&result.logic_eth_id));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	}
+
+	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_GET_ETH_ID, msg_id, err,
+		     &result, sizeof(result));
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_GET_ETH_ID);
+}
+
 static void nbl_disp_deinit_module(struct nbl_dispatch_mgt *disp_mgt)
 {
 	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
@@ -22,6 +165,244 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
 	return NBL_OPS_CALL_RET(res_ops->init_module, (p));
 }
 
+static int nbl_disp_configure_msix_map(struct nbl_dispatch_mgt *disp_mgt,
+				       u16 num_net_msix, u16 num_others_msix,
+				       bool net_msix_mask_en)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->configure_msix_map, (p,
+				common->mgt_pf, num_net_msix,
+				num_others_msix, net_msix_mask_en));
+}
+
+static int
+nbl_disp_chan_configure_msix_map_req(struct nbl_dispatch_mgt *disp_mgt,
+				     u16 num_net_msix, u16 num_others_msix,
+				     bool net_msix_mask_en)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_cfg_msix_map param = { 0 };
+	struct nbl_chan_send_info chan_send;
+	int ret;
+
+	param.num_net_msix = cpu_to_le16(num_net_msix);
+	param.num_others_msix = cpu_to_le16(num_others_msix);
+	param.msix_mask_en = cpu_to_le16(!!net_msix_mask_en);
+
+	NBL_CHAN_SEND(chan_send, common->mgt_pf,
+		      NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, &param, sizeof(param),
+		      NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	default:
+		return ret;
+	}
+}
+
+static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id,
+						  u16 msg_id, void *data,
+						  u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_param_cfg_msix_map param = { 0 };
+	struct nbl_chan_ack_info chan_ack;
+	int err = NBL_CHAN_RESP_OK;
+	int copy_len;
+	int ret;
+
+	copy_len = min_t(size_t, data_len, sizeof(param));
+	memcpy(&param, data, copy_len);
+	if (!res_ops->configure_msix_map) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->configure_msix_map,
+				       (p, src_id,
+					le16_to_cpu(param.num_net_msix),
+					le16_to_cpu(param.num_others_msix),
+					le16_to_cpu(param.msix_mask_en)));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+		}
+
+	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, msg_id,
+		     err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP);
+}
+
+static int nbl_disp_chan_destroy_msix_map_req(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_send_info chan_send;
+	int ret;
+
+	NBL_CHAN_SEND(chan_send, common->mgt_pf, NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+		      NULL, 0, NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	default:
+		return ret;
+	}
+}
+
+static void nbl_disp_chan_destroy_msix_map_resp(void *priv, u16 src_id,
+						u16 msg_id, void *data,
+						u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = NBL_CHAN_RESP_OK;
+	int ret;
+
+	if (!res_ops->destroy_msix_map) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->destroy_msix_map, (p, src_id));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	}
+
+	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_DESTROY_MSIX_MAP, msg_id,
+		     err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_DESTROY_MSIX_MAP);
+}
+
+static int nbl_disp_chan_set_mailbox_irq_req(struct nbl_dispatch_mgt *disp_mgt,
+					     u16 vector_id, bool enable_msix)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_chan_param_set_mailbox_irq param = { 0 };
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_send_info chan_send;
+	int ret;
+
+	param.vector_id = cpu_to_le16(vector_id);
+	param.enable_msix = enable_msix;
+
+	NBL_CHAN_SEND(chan_send, common->mgt_pf, NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+		      &param, sizeof(param), NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	default:
+		return ret;
+	}
+}
+
+static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,
+					       u16 msg_id, void *data,
+					       u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_chan_param_set_mailbox_irq param = { 0 };
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = NBL_CHAN_RESP_OK;
+	bool enable_msix;
+	u16 vector_id;
+	int copy_len;
+	int ret;
+
+	copy_len = min_t(size_t, data_len, sizeof(param));
+	memcpy(&param, data, copy_len);
+	vector_id = le16_to_cpu(param.vector_id);
+	enable_msix = !!param.enable_msix;
+	if (!res_ops->set_mailbox_irq) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->set_mailbox_irq,
+				       (p, src_id, vector_id, enable_msix));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	}
+
+	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_MAILBOX_SET_IRQ, msg_id,
+		     err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_MAILBOX_SET_IRQ);
+}
+
+static int nbl_disp_destroy_msix_map(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->destroy_msix_map, (p,
+				     common->mgt_pf));
+}
+
+static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
+				    u16 vector_id, bool enable_msix)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->set_mailbox_irq, (p,
+				common->mgt_pf, vector_id, enable_msix));
+}
+
+static int nbl_disp_get_vsi_id(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+			       u16 *vsi_id)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->get_vsi_id,
+				(p, common->mgt_pf, type, vsi_id));
+}
+
+static int nbl_disp_get_eth_id(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+			       u8 *eth_num, u8 *eth_id, u8 *logic_eth_id)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->get_eth_id,
+				(p, common->mgt_pf, vsi_id, eth_num, eth_id,
+				 logic_eth_id));
+}
+
 /* NBL_DISP_SET_OPS(disp_op_name, func, ctrl_lvl, msg_type, msg_req, msg_resp)
  * ctrl_lvl is to define when this disp_op should go directly to res_op,
  * not sending a channel msg.
@@ -38,7 +419,62 @@ do {									\
 	NBL_DISP_SET_OPS(deinit_module,				\
 			 nbl_disp_deinit_module,			\
 			 NBL_DISP_CTRL_LVL_MGT, -1, NULL, NULL);	\
+	NBL_DISP_SET_OPS(configure_msix_map,				\
+			 nbl_disp_configure_msix_map,			\
+			 NBL_DISP_CTRL_LVL_MGT,				\
+			 NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,		\
+			 nbl_disp_chan_configure_msix_map_req,		\
+			 nbl_disp_chan_configure_msix_map_resp);	\
+	NBL_DISP_SET_OPS(destroy_msix_map, nbl_disp_destroy_msix_map,	\
+			 NBL_DISP_CTRL_LVL_MGT,				\
+			 NBL_CHAN_MSG_DESTROY_MSIX_MAP,			\
+			 nbl_disp_chan_destroy_msix_map_req,		\
+			 nbl_disp_chan_destroy_msix_map_resp);		\
+	NBL_DISP_SET_OPS(set_mailbox_irq,				\
+			 nbl_disp_set_mailbox_irq,			\
+			 NBL_DISP_CTRL_LVL_MGT,				\
+			 NBL_CHAN_MSG_MAILBOX_SET_IRQ,		\
+			 nbl_disp_chan_set_mailbox_irq_req,		\
+			 nbl_disp_chan_set_mailbox_irq_resp);	\
+	NBL_DISP_SET_OPS(get_vsi_id, nbl_disp_get_vsi_id,		\
+			 NBL_DISP_CTRL_LVL_MGT, NBL_CHAN_MSG_GET_VSI_ID,\
+			 nbl_disp_chan_get_vsi_id_req,			\
+			 nbl_disp_chan_get_vsi_id_resp);		\
+	NBL_DISP_SET_OPS(get_eth_id, nbl_disp_get_eth_id,		\
+			 NBL_DISP_CTRL_LVL_MGT, NBL_CHAN_MSG_GET_ETH_ID,\
+			 nbl_disp_chan_get_eth_id_req,			\
+			 nbl_disp_chan_get_eth_id_resp);		\
+} while (0)
+
+/* Structure starts here, adding an op should not modify anything below */
+static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv;
+	int ret = 0;
+	int _ret;
+
+#define NBL_DISP_SET_OPS(disp_op, func, ctrl, msg_type, msg_req, resp) \
+do {									\
+	typeof(msg_type) _msg_type = (msg_type);			\
+	typeof(ctrl) _ctrl_lvl = (ctrl);				\
+	(void)(disp_ops->NBL_NAME(disp_op));				\
+	(void)(func);							\
+	(void)(msg_req);						\
+	(void)_ctrl_lvl;						\
+	if (_msg_type >= 0) {						\
+		_ret = chan_ops->register_msg(p, _msg_type, resp, disp_mgt);\
+		if (_ret < 0 && !ret)					\
+			ret = _ret;					\
+	}								\
 } while (0)
+	NBL_DISP_OPS_TBL;
+#undef  NBL_DISP_SET_OPS
+	if (ret)
+		chan_ops->unregister_all_msg(p);
+	return ret;
+}
 
 /* Ctrl lvl means that if a certain level is set, then all disp_ops that
  * declared this lvl will go directly to res_ops, rather than send a
@@ -126,6 +562,10 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 	adapter->core.disp_mgt = disp_mgt;
 	adapter->intf.dispatch_ops_tbl = disp_ops_tbl;
 
+	ret = nbl_disp_setup_msg(disp_mgt);
+	if (ret)
+		return ret;
+
 	if (common->has_ctrl)
 		nbl_disp_setup_ctrl_lvl(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
@@ -134,4 +574,9 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 
 void nbl_disp_remove(struct nbl_adapter *adapter)
 {
+	struct nbl_dispatch_mgt *disp_mgt = adapter->core.disp_mgt;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv;
+
+	chan_ops->unregister_all_msg(p);
 }
Signature · 1 line
2.47.3
maintainer
#19 lore raw

Re: [PATCH v22 net-next 09/12] net/nebula-matrix: dispatch: add cross-version channel message framework

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [9]: [PATCH v22 net-next 09/12] net/nebula-matrix: dispatch: add cross-version channel message framework --- commit d32035d9a9bd3114eb253cf0283172847c233d7d
Author: illusion wang <[email protected]>

net/nebula-matrix: dispatch: add cross-version channel message framework

Implement bidirectional channel request/response RPC handlers for 5 dispatch resource operations: get_vsi_id, get_eth_id, configure_msix_map, destroy_msix_map, set_mailbox_irq.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -0
index 8116643859c79..c82c336f50e5e 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 179

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +12 -0
+static int nbl_disp_configure_msix_map(struct nbl_dispatch_mgt *disp_mgt,
+				       u16 num_net_msix, u16 num_others_msix,
+				       bool net_msix_mask_en)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	return NBL_OPS_CALL_RET(res_ops->configure_msix_map, (p,
+				common->mgt_pf, num_net_msix,
+				num_others_msix, net_msix_mask_en));
+}

[Severity: High]
Does nbl_disp_configure_msix_map() need to take a mutex lock before invoking res_ops->configure_msix_map()?

Calling this resource operation without synchronization might lead to data races and hardware state corruption if multiple requests arrive simultaneously.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4 -0
+static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id,
+						  u16 msg_id, void *data,
+						  u32 data_len)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 237

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11 -0
+	if (!res_ops->configure_msix_map) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->configure_msix_map,
+				       (p, src_id,
+					le16_to_cpu(param.num_net_msix),
+					le16_to_cpu(param.num_others_msix),
+					le16_to_cpu(param.msix_mask_en)));
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+		}

[Severity: High]
Should nbl_disp_chan_configure_msix_map_resp() also use locking when invoking res_ops->configure_msix_map()?

Since this response handler can run from a workqueue context concurrently with other operations, this might also lead to hardware state corruption.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4 -0
+static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,
+					       u16 msg_id, void *data,
+					       u32 data_len)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 349

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +6 -0
+	if (!res_ops->set_mailbox_irq) {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	} else {
+		ret = NBL_OPS_CALL_RET(res_ops->set_mailbox_irq,
+				       (p, src_id, vector_id, enable_msix));
+		if (ret)

[Severity: High]
Similarly, should nbl_disp_chan_set_mailbox_irq_resp() be protected by a lock when modifying the mailbox IRQ hardware state?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 571

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4 -0
@@ -126,6 +562,10 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 	adapter->core.disp_mgt = disp_mgt;
 	adapter->intf.dispatch_ops_tbl = disp_ops_tbl;
 
+	ret = nbl_disp_setup_msg(disp_mgt);
+	if (ret)
+		return ret;
+
 	if (common->has_ctrl)
 		nbl_disp_setup_ctrl_lvl(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 

[Severity: High]
Does the dispatch operations table remain uninitialized for non-control PFs here?

Since nbl_disp_setup_ctrl_lvl() is responsible for populating the disp_ops table (including setting up the remote message request handlers as fallbacks when testing control levels), skipping this step when common->has_ctrl is false might leave the function pointers as NULL.

Could this lead to a NULL pointer dereference when a regular non-control PF subsequently attempts to invoke a dispatch operation like get_vsi_id or get_eth_id?

author maintainer
#20 lore raw

PATCH v22 10/12 net/nebula-matrix: dispatch: add mutual exclusion lock for shared hardware resource ops

In reply to illusion.wang

From: illusion wang <[email protected]>

Add ops_mutex_lock to serialize concurrent hardware-modifying dispatch resource operations, preventing race conditions between PF local calls and remote mailbox message handlers that manipulate MSI-X mapping and mailbox IRQ state.

1. Introduce disp_mgt->ops_mutex_lock, initialized via devm_mutex_init at disp_mgt allocation time; symmetrically destroyed automatically by devres on device detach, eliminating double mutex_destroy risk.
2. Add NBL_OPS_CALL_LOCK_RET macro to wrap hardware-modifying ops with exclusive lock protection for unified locking semantics.
3. Wrap configure_msix_map / destroy_msix_map / set_mailbox_irq with ops_mutex_lock; these ops mutate shared MSI-X and IRQ hardware state and can race between local PF control paths and cross-PF mailbox RPCs.
4. Fix cleanup ordering: unregister all channel message handlers before hardware resource teardown to avoid lockdep splats and invalid mutex access after destruction.
5. Complete message handler cleanup on nbl_disp_setup_msg() failure path to avoid leaked callback registrations.

The read-only get_vsi_id / get_eth_id routines only consume static init-time metadata with no concurrent writers, so they require no locking.

Functional note: Enable NBL_DISP_CTRL_LVL_NET for adapters with common->has_net set, ensuring net-level dispatch operation handlers are properly wired into the dispatch op table.

---
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 47 ++++++++++++-------
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 18 +++++++
 2 files changed, 49 insertions(+), 16 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +31 -16
index c82c336f50e5..175250f95250 100644
@@ -3,6 +3,7 @@
  * Copyright (c) 2025 Nebula Matrix Limited.
  */
 #include <linux/device.h>
+#include <linux/mutex.h>
 #include <linux/pci.h>
 #include "nbl_dispatch.h"
 
@@ -173,9 +174,9 @@ static int nbl_disp_configure_msix_map(struct nbl_dispatch_mgt *disp_mgt,
 	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
 	struct nbl_common_info *common = disp_mgt->common;
 
-	return NBL_OPS_CALL_RET(res_ops->configure_msix_map, (p,
-				common->mgt_pf, num_net_msix,
-				num_others_msix, net_msix_mask_en));
+	return NBL_OPS_CALL_LOCK_RET(disp_mgt, res_ops->configure_msix_map, p,
+				     common->mgt_pf, num_net_msix,
+				     num_others_msix, net_msix_mask_en);
 }
 
 static int
@@ -227,14 +228,15 @@ static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id,
 	if (!res_ops->configure_msix_map) {
 		err = NBL_CHAN_RESP_UNIMPLEMENTED;
 	} else {
-		ret = NBL_OPS_CALL_RET(res_ops->configure_msix_map,
-				       (p, src_id,
-					le16_to_cpu(param.num_net_msix),
-					le16_to_cpu(param.num_others_msix),
-					le16_to_cpu(param.msix_mask_en)));
+		ret = NBL_OPS_CALL_LOCK_RET(disp_mgt,
+					    res_ops->configure_msix_map, p,
+					    src_id,
+					    le16_to_cpu(param.num_net_msix),
+					    le16_to_cpu(param.num_others_msix),
+					    le16_to_cpu(param.msix_mask_en));
 		if (ret)
 			err = NBL_CHAN_RESP_ERR;
-		}
+	}
 
 	NBL_CHAN_ACK(chan_ack, src_id, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, msg_id,
 		     err, NULL, 0);
@@ -281,7 +283,8 @@ static void nbl_disp_chan_destroy_msix_map_resp(void *priv, u16 src_id,
 	if (!res_ops->destroy_msix_map) {
 		err = NBL_CHAN_RESP_UNIMPLEMENTED;
 	} else {
-		ret = NBL_OPS_CALL_RET(res_ops->destroy_msix_map, (p, src_id));
+		ret = NBL_OPS_CALL_LOCK_RET(disp_mgt, res_ops->destroy_msix_map,
+					    p, src_id);
 		if (ret)
 			err = NBL_CHAN_RESP_ERR;
 	}
@@ -344,8 +347,8 @@ static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,
 	if (!res_ops->set_mailbox_irq) {
 		err = NBL_CHAN_RESP_UNIMPLEMENTED;
 	} else {
-		ret = NBL_OPS_CALL_RET(res_ops->set_mailbox_irq,
-				       (p, src_id, vector_id, enable_msix));
+		ret = NBL_OPS_CALL_LOCK_RET(disp_mgt, res_ops->set_mailbox_irq,
+					    p, src_id, vector_id, enable_msix);
 		if (ret)
 			err = NBL_CHAN_RESP_ERR;
 	}
@@ -365,8 +368,8 @@ static int nbl_disp_destroy_msix_map(struct nbl_dispatch_mgt *disp_mgt)
 	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
 	struct nbl_common_info *common = disp_mgt->common;
 
-	return NBL_OPS_CALL_RET(res_ops->destroy_msix_map, (p,
-				     common->mgt_pf));
+	return NBL_OPS_CALL_LOCK_RET(disp_mgt, res_ops->destroy_msix_map, p,
+				     common->mgt_pf);
 }
 
 static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
@@ -376,8 +379,8 @@ static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
 	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
 	struct nbl_common_info *common = disp_mgt->common;
 
-	return NBL_OPS_CALL_RET(res_ops->set_mailbox_irq, (p,
-				common->mgt_pf, vector_id, enable_msix));
+	return NBL_OPS_CALL_LOCK_RET(disp_mgt, res_ops->set_mailbox_irq, p,
+				     common->mgt_pf, vector_id, enable_msix);
 }
 
 static int nbl_disp_get_vsi_id(struct nbl_dispatch_mgt *disp_mgt, u16 type,
@@ -503,12 +506,16 @@ nbl_disp_setup_disp_mgt(struct nbl_common_info *common)
 {
 	struct nbl_dispatch_mgt *disp_mgt;
 	struct device *dev = common->dev;
+	int err;
 
 	disp_mgt = devm_kzalloc(dev, sizeof(*disp_mgt), GFP_KERNEL);
 	if (!disp_mgt)
 		return ERR_PTR(-ENOMEM);
 
 	disp_mgt->common = common;
+	err = devm_mutex_init(common->dev, &disp_mgt->ops_mutex_lock);
+	if (err)
+		return ERR_PTR(err);
 	return disp_mgt;
 }
 
@@ -569,6 +576,14 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 	if (common->has_ctrl)
 		nbl_disp_setup_ctrl_lvl(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
+	/*
+	 * This flag must be enabled for adapters with network capability;
+	 * otherwise NET-layer dispatch operation handlers will not be
+	 * registered.
+	 */
+	if (common->has_net)
+		nbl_disp_setup_ctrl_lvl(disp_mgt, NBL_DISP_CTRL_LVL_NET);
+
 	return 0;
 }
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +18 -0
index f06b90075af4..722758354ff2 100644
@@ -13,12 +13,30 @@
 #include "../nbl_include/nbl_def_common.h"
 #include "../nbl_core.h"
 
+#define NBL_OPS_CALL_LOCK_RET(disp_mgt, func, ...)			\
+({									\
+	typeof(disp_mgt) _disp_mgt = (disp_mgt);			\
+	typeof(func) _func = (func);					\
+	typeof(_func(__VA_ARGS__)) _ret = 0;				\
+									\
+	mutex_lock(&_disp_mgt->ops_mutex_lock);				\
+									\
+	if (_func)							\
+		_ret = _func(__VA_ARGS__);				\
+									\
+	mutex_unlock(&_disp_mgt->ops_mutex_lock);			\
+									\
+	_ret;								\
+})
+
 struct nbl_dispatch_mgt {
 	struct nbl_common_info *common;
 	struct nbl_resource_ops_tbl *res_ops_tbl;
 	struct nbl_channel_ops_tbl *chan_ops_tbl;
 	struct nbl_dispatch_ops_tbl *disp_ops_tbl;
 	DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX);
+	/* use for the caller not in interrupt */
+	struct mutex ops_mutex_lock;
 };
 
 #endif
Signature · 1 line
2.47.3
maintainer
#21 lore raw

Re: [PATCH v22 net-next 10/12] net/nebula-matrix: dispatch: add mutual exclusion lock for shared hardware resource ops

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [10]: [PATCH v22 net-next 10/12] net/nebula-matrix: dispatch: add mutual exclusion lock for shared hardware resource ops --- commit 629ed395b64ead7623f563c4a19ea0794f996cf1
Author: illusion wang <[email protected]>

net/nebula-matrix: dispatch: add mutual exclusion lock for shared hardware resource ops

Add ops_mutex_lock to serialize concurrent hardware-modifying dispatch resource operations, preventing race conditions between PF local calls and remote mailbox message handlers that manipulate MSI-X mapping and mailbox IRQ state.

Quoted 3 lines

4. Fix cleanup ordering: unregister all channel message handlers before hardware resource teardown to avoid lockdep splats and invalid mutex access after destruction.

Does this cleanup ordering actually prevent the invalid mutex access?

Looking at the driver teardown path in nbl_core_remove() and nbl_chan_remove_common(), it appears the channel workqueue is never cancelled via teardown_queue().

If a remote PF sends mailbox messages while the local PF driver is being unloaded, won't the uncancelled work item still process it?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -0
index c82c336f50e5e..175250f952506 100644

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -1
@@ -227,14 +228,15 @@ static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id,
 	if (!res_ops->configure_msix_map) {
 		err = NBL_CHAN_RESP_UNIMPLEMENTED;
 	} else {
-		ret = NBL_OPS_CALL_RET(res_ops->configure_msix_map,

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id, · line 236

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +6 -4
-				       (p, src_id,
-					le16_to_cpu(param.num_net_msix),
-					le16_to_cpu(param.num_others_msix),
-					le16_to_cpu(param.msix_mask_en)));
+		ret = NBL_OPS_CALL_LOCK_RET(disp_mgt,
+					    res_ops->configure_msix_map, p,
+					    src_id,
+					    le16_to_cpu(param.num_net_msix),
+					    le16_to_cpu(param.num_others_msix),
+					    le16_to_cpu(param.msix_mask_en));

[Severity: High]
If the inflight work item runs after handler unregistration, will it attempt to acquire the newly added ops_mutex_lock here via NBL_OPS_CALL_LOCK_RET?

Since this mutex is initialized via devm_mutex_init and destroyed automatically on device detach, could this result in a use-after-free crash on the destroyed lock?

[ ... ]

This is a pre-existing issue, but while looking at the MSI-X resource operations I noticed a potential problem in nbl_res_intr_configure_msix_map() in drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c:

release_net_bits:

        while (i--) {
                intr_index = tmp_interrupts[i];
                ...
        }
        i = num_net_msix;
release_all_bits:
        while (i--) {

[Severity: High]
Does this error path intentionally fall through to release_all_bits?

When devm_kcalloc or find_first_zero_bit fails during net interrupt allocation, the code jumps to release_net_bits. Without a goto free_prealloc before the i = num_net_msix assignment, it falls through into release_all_bits.

Because tmp_interrupts is unpopulated and contains zeros, will this loop unconditionally clear bit 0 in interrupt_others_bitmap, corrupting the MSI-X allocator state?

author maintainer
#22 lore raw

PATCH v22 11/12 net/nebula-matrix: add common/ctrl dev init/remove operation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() initialization helpers with paired teardown routines, and hook them into nbl_dev_init / nbl_dev_remove.

Mailbox message processing is implemented via work_struct. This task registration framework is reused for interrupt-driven receive now, and can be shared with polling receive mode introduced in follow-up patches.

Chip core hardware initialization is fully handled by firmware during power-on; the driver only configures functional table entries and registers after hardware is ready. Thus invoking nbl_dev_setup_common_dev() before ctrl dev setup does not trigger hardware faults, all register accesses are safe.

Teardown order explanation:
1. Remove ctrl dev first: notify firmware to clean all per-PF hardware state including qinfo registers via driver status flag.
2. Then tear down common device queue resources.
Firmware cleanup ensures qinfo registers are valid during subsequent common dev deinit writes, avoiding PCIe master abort or hardware access panics.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 232 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |  57 +++++
 .../nbl/nbl_include/nbl_def_dev.h             |  14 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 6 files changed, 315 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index 56464f576cbe..0febda209865 100644
@@ -11,4 +11,5 @@ nbl-objs +=       nbl_common/nbl_common.o \
 				nbl_hw/nbl_interrupt.o \
 				nbl_hw/nbl_chip.o \
 				nbl_core/nbl_dispatch.o \
+				nbl_core/nbl_dev.o \
 				nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index a1f874bb03c6..beeabf627402 100644
@@ -18,6 +18,7 @@ struct nbl_dispatch_mgt;
 struct nbl_dispatch_ops_tbl;
 struct nbl_channel_ops_tbl;
 struct nbl_channel_mgt;
+struct nbl_dev_mgt;
 
 enum {
 	NBL_CAP_HAS_CTRL_BIT,
@@ -35,6 +36,7 @@ struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
 	struct nbl_resource_mgt *res_mgt;
 	struct nbl_dispatch_mgt *disp_mgt;
+	struct nbl_dev_mgt *dev_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +232 -0

232 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +57 -0

57 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
new file mode 100644
index 000000000000..b422a4edf0a9
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2025 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_DEV_H_
+#define _NBL_DEF_DEV_H_
+
+struct nbl_adapter;
+
+int nbl_dev_init(struct nbl_adapter *adapter);
+void nbl_dev_remove(struct nbl_adapter *adapter);
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
index d2ea55f5d568..24d9f7474e53 100644
@@ -12,6 +12,7 @@
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_dispatch.h"
+#include "nbl_include/nbl_def_dev.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -53,7 +54,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_disp_init(adapter);
 	if (ret)
 		goto disp_init_fail;
+
+	ret = nbl_dev_init(adapter);
+	if (ret)
+		goto dev_init_fail;
 	return adapter;
+
+dev_init_fail:
+	nbl_disp_remove(adapter);
 disp_init_fail:
 	nbl_res_remove_leonis(adapter);
 res_init_fail:
@@ -66,6 +74,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_dev_remove(adapter);
 	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
Signature · 1 line
2.47.3
maintainer
#23 lore raw

Re: [PATCH v22 net-next 11/12] net/nebula-matrix: add common/ctrl dev init/remove operation

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [11]: [PATCH v22 net-next 11/12] net/nebula-matrix: add common/ctrl dev init/remove operation --- commit 16bce0d3af6a82a0084a93157844e7c5875d3c59
Author: illusion wang <[email protected]>

net/nebula-matrix: add common/ctrl dev init/remove operation

This commit adds initialization and teardown helpers for common and control devices. It hooks these helpers into the main init/remove paths and configures mailbox message processing via a work_struct.

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0 -0
new file mode 100644
index 0000000000000..eae6a00e6fccb

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2 -0
+static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 103

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9 -0
+	INIT_WORK(&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task);
+	nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX,
+				   &common_dev->clean_mbx_task);
+	/*
+	 * Even if has_ctrl=false (no dedicated control PF channel), we fetch
+	 * VSI/ETH info via regular mailbox message  instead of
+	 * dedicated control command.
+	 */
+	ret = disp_ops->get_vsi_id(priv, NBL_VSI_DATA, &common->vsi_id);

[Severity: High]
Will this mailbox message fail silently and read uninitialized zeros?

Since get_vsi_id() is called here before interrupts are enabled, NBL_CHAN_INTERRUPT_READY is false. When nbl_chan_send_msg() processes this message, it checks the interrupt ready flag:

if (test_bit(NBL_CHAN_INTERRUPT_READY, chan_info->state)) {
        spin_lock_irq(&wait_head->status_lock);
        while (!READ_ONCE(wait_head->acked)) {
                ...
        }
}
...
inflight_dec_out:
        atomic_dec(&chan_info->inflight_tx_cnt);
        return ret;

Because the flag is false, does it skip waiting for the ACK and immediately return success (0)?

If so, this would leave the caller reading zeroed variables for the VSI and ETH IDs, resulting in incorrect initialization and potentially leaving a dangling pointer in the wait queue.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +6 -0
+	if (ret)
+		goto err_cleanup;
+	ret = disp_ops->get_eth_id(priv, common->vsi_id, &common->eth_num,
+			     &common->eth_id, &common->logic_eth_id);
+	if (ret)
+		goto err_cleanup;

[ ... ]

author maintainer
#24 lore raw

PATCH v22 12/12 net/nebula-matrix: add common dev start/stop operation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add device start/stop helper functions to manage MSI-X vector mapping, mailbox interrupt resource initialization and deinitialization. Create unbound global workqueue for mailbox task scheduling; this shared work infrastructure supports both current interrupt-driven receive and future polling receive path.

This patch implements complete startup and shutdown flow for common device resources:
1. Add nbl_dev_start() to finish device startup procedure:
- Configure hardware MSI-X mapping table for different interrupt types
- Allocate required MSI-X irq vectors via pci_alloc_irq_vectors
- Request mailbox IRQ; interrupt handler schedules mailbox processing work
- Enable hardware mailbox interrupt and mark channel interrupt ready

2. Add nbl_dev_stop() to tear down device resources safely in strict order:
- Update software channel state first to switch to polling, then mask hardware interrupt to avoid stale ACK handling
- Free mailbox IRQ handler and release MSI-X vector resources
- Destroy hardware MSI-X mapping table

Extend channel TX waiting logic with polling fallback and shutdown detection. When interrupt path is disabled, send routines rely on active polling to wait for message ACK, preventing deadlock during device stop.

Hook nbl_core_start() / nbl_core_stop() into PCI probe and remove paths.

---
 .../nbl/nbl_channel/nbl_channel.c             |  44 +++
 .../nbl/nbl_channel/nbl_channel.h             |   3 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  21 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 273 +++++++++++++++++-
 .../nbl/nbl_include/nbl_def_common.h          |   3 +
 .../nbl/nbl_include/nbl_def_dev.h             |   2 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  22 +-
 8 files changed, 361 insertions(+), 9 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +44 -0
index eb0d55dad944..762243a664b9 100644
@@ -725,6 +725,7 @@ static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,
 	struct nbl_common_info *common = chan_mgt->common;
 	struct nbl_chan_waitqueue_head *wait_head;
 	struct nbl_chan_tx_param tx_param = { 0 };
+	int i = NBL_CHAN_TX_WAIT_ACK_TIMES;
 	struct nbl_chan_info *chan_info =
 		chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX];
 	struct device *dev = common->dev;
@@ -852,6 +853,49 @@ static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,
 		goto inflight_dec_out;
 	}
 
+	/* Polling: only init/deinit, add shutdown detect to avoid deadlock */
+	while (i--) {
+		if (READ_ONCE(chan_info->shutdown)) {
+			ret = -ESHUTDOWN;
+			goto inflight_dec_out;
+		}
+		/* Order shutdown read before accessing clean_task/workqueue */
+		smp_rmb();
+		if (READ_ONCE(chan_info->clean_task) && common->wq)
+			queue_work(common->wq, chan_info->clean_task);
+
+		spin_lock_irq(&wait_head->status_lock);
+		if (READ_ONCE(wait_head->acked)) {
+			/*
+			 * Memory barrier: ensure ack_data/ack_err are fully
+			 * written before reading, avoid multi-core stale data
+			 * due to CPU out-of-order execution.
+			 */
+			smp_rmb();
+			chan_send->ack_len = wait_head->ack_data_len;
+			ret = wait_head->ack_err;
+			wait_head->acked = 0;
+			wait_head->status = NBL_MBX_STATUS_IDLE;
+			spin_unlock_irq(&wait_head->status_lock);
+			goto inflight_dec_out;
+		}
+		spin_unlock_irq(&wait_head->status_lock);
+
+		usleep_range(NBL_CHAN_TX_WAIT_ACK_US_MIN,
+			     NBL_CHAN_TX_WAIT_ACK_US_MAX);
+	}
+
+	spin_lock_irq(&wait_head->status_lock);
+	wait_head->acked = 0;
+	wait_head->ack_data = NULL;
+	wait_head->ack_data_len = 0;
+	wait_head->status = NBL_MBX_STATUS_TIMEOUT;
+	spin_unlock_irq(&wait_head->status_lock);
+
+	dev_err(dev,
+		"Channel polling ack failed, message type: %d msg id: %u\n",
+		chan_send->msg_type, msgid);
+	ret = -ETIMEDOUT;
 inflight_dec_out:
 	atomic_dec(&chan_info->inflight_tx_cnt);
 	return ret;
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h +3 -0
index 3ee84fc976c3..45a50844a4fa 100644
@@ -24,6 +24,9 @@
 #define NBL_CHAN_TX_WAIT_US			100
 #define NBL_CHAN_TX_WAIT_US_MAX			120
 #define NBL_CHAN_TX_WAIT_TIMES			100
+#define NBL_CHAN_TX_WAIT_ACK_US_MIN		1000
+#define NBL_CHAN_TX_WAIT_ACK_US_MAX		1200
+#define NBL_CHAN_TX_WAIT_ACK_TIMES		5000
 #define NBL_CHAN_QUEUE_LEN			256
 #define NBL_CHAN_CLEAN_BATCH_SIZE		32
 #define NBL_CHAN_BUF_LEN			4096
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +21 -0
index f1cd8e7d8a7f..d02b1f0365be 100644
@@ -6,6 +6,27 @@
 #include <linux/device.h>
 #include "nbl_common.h"
 
+void nbl_common_destroy_wq(struct nbl_common_info *common)
+{
+	destroy_workqueue(common->wq);
+}
+
+int nbl_common_create_wq(struct nbl_common_info *common)
+{
+	char wq_name[32];
+
+	snprintf(wq_name, sizeof(wq_name), "nbl_wq_%s", pci_name(common->pdev));
+	common->wq = alloc_workqueue(wq_name, WQ_UNBOUND, 0);
+	if (!common->wq) {
+		pr_err("Failed to create workqueue nbl_wq\n");
+		goto alloc_wq_failed;
+	}
+
+	return 0;
+alloc_wq_failed:
+	return -ENOMEM;
+}
+
 u32 nbl_common_pf_id_subtraction_mgtpf_id(struct nbl_common_info *common,
 					  u32 pf_id)
 {
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index beeabf627402..5ab8555cf91f 100644
@@ -50,5 +50,7 @@ struct nbl_adapter {
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param);
 void nbl_core_remove(struct nbl_adapter *adapter);
+int nbl_core_start(struct nbl_adapter *adapter);
+void nbl_core_stop(struct nbl_adapter *adapter);
 
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +266 -7

319 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +3 -0
index 0e0ea10e20c7..2816132b69d1 100644
@@ -29,6 +29,7 @@ struct nbl_hash_tbl_mgt;
 	})
 
 struct nbl_common_info {
+	struct workqueue_struct *wq;
 	struct pci_dev *pdev;
 	struct device *dev;
 	u32 msg_enable;
@@ -55,6 +56,8 @@ struct nbl_hash_tbl_key {
 	u16 resv;
 };
 
+void nbl_common_destroy_wq(struct nbl_common_info *common);
+int nbl_common_create_wq(struct nbl_common_info *common);
 u32 nbl_common_pf_id_subtraction_mgtpf_id(struct nbl_common_info *common,
 					  u32 pf_id);
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
index b422a4edf0a9..32e6cce38d39 100644
@@ -10,5 +10,7 @@ struct nbl_adapter;
 
 int nbl_dev_init(struct nbl_adapter *adapter);
 void nbl_dev_remove(struct nbl_adapter *adapter);
+int nbl_dev_start(struct nbl_adapter *adapter);
+void nbl_dev_stop(struct nbl_adapter *adapter);
 
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +20 -2
index 24d9f7474e53..4fa0b7a892d9 100644
@@ -16,6 +16,16 @@
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
+int nbl_core_start(struct nbl_adapter *adapter)
+{
+	return nbl_dev_start(adapter);
+}
+
+void nbl_core_stop(struct nbl_adapter *adapter)
+{
+	nbl_dev_stop(adapter);
+}
+
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param)
 {
@@ -137,7 +147,14 @@ static int nbl_probe(struct pci_dev *pdev,
 		goto adapter_init_err;
 	}
 	pci_set_drvdata(pdev, adapter);
+	err = nbl_core_start(adapter);
+	if (err)
+		goto core_start_err;
+
 	return 0;
+core_start_err:
+	pci_set_drvdata(pdev, NULL);
+	nbl_core_remove(adapter);
 adapter_init_err:
 	pci_clear_master(pdev);
 configure_dma_err:
@@ -149,9 +166,10 @@ static void nbl_remove(struct pci_dev *pdev)
 {
 	struct nbl_adapter *adapter = pci_get_drvdata(pdev);
 
-	if (adapter)
+	if (adapter) {
+		nbl_core_stop(adapter);
 		nbl_core_remove(adapter);
-
+	}
 	pci_restore_state(pdev);
 	pci_clear_master(pdev);
 	pci_disable_device(pdev);
Signature · 1 line
2.47.3
maintainer
#25 lore raw

Re: [PATCH v22 net-next 12/12] net/nebula-matrix: add common dev start/stop operation

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [12]: [PATCH v22 net-next 12/12] net/nebula-matrix: add common dev start/stop operation --- commit 87deb0868f9edbdb2f584ecc55b9f7839da1fb23
Author: illusion wang <[email protected]>

net/nebula-matrix: add common dev start/stop operation

This patch adds device start/stop helper functions for MSI-X mapping and mailbox interrupts. It creates an unbound global workqueue for mailbox tasks. It also extends channel TX logic with polling fallback.

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +0 -0

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 19

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +6 -0
+int nbl_common_create_wq(struct nbl_common_info *common)
+{
+	char wq_name[32];
+
+	snprintf(wq_name, sizeof(wq_name), "nbl_wq_%s", pci_name(common->pdev));
+	common->wq = alloc_workqueue(wq_name, WQ_UNBOUND, 0);

[Severity: Medium]
Is wq_name safely used as the format string here?

Since alloc_workqueue() takes a printf-style format string, passing the variable directly can cause a format string vulnerability if the PCI name contains format specifiers. Should this be updated to:
alloc_workqueue("%s", WQ_UNBOUND, 0, wq_name)?

[Severity: Medium]
This patch creates a dedicated workqueue for mailbox tasks, but does the cleanup task occasionally reschedule itself to the default system workqueue?

In nbl_chan_clean_queue():

    if (more_work && READ_ONCE(chan_info->clean_task))
        schedule_work(chan_info->clean_task);

Should this use queue_work(common->wq, ...) instead to ensure the task stays on the dedicated workqueue?

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +9 -0
+	if (!common->wq) {
+		pr_err("Failed to create workqueue nbl_wq\n");
+		goto alloc_wq_failed;
+	}
+
+	return 0;
+alloc_wq_failed:
+	return -ENOMEM;
+}

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt, · line 731

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +1 -0
@@ -725,6 +725,7 @@ static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,
 	struct nbl_common_info *common = chan_mgt->common;
 	struct nbl_chan_waitqueue_head *wait_head;
 	struct nbl_chan_tx_param tx_param = { 0 };
+	int i = NBL_CHAN_TX_WAIT_ACK_TIMES;
 	struct nbl_chan_info *chan_info =
 		chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX];
 	struct device *dev = common->dev;

[Severity: High]
Does checking the shutdown flag before incrementing the inflight counter create a race condition?

Earlier in nbl_chan_send_msg():

    if (READ_ONCE(chan_info->shutdown))
        return -ESHUTDOWN;
    /* Ensure shutdown load is ordered before inflight counter increment */
    smp_rmb();
    atomic_inc(&chan_info->inflight_tx_cnt);

If a thread is preempted after checking the shutdown flag but before incrementing the counter, could another thread set the shutdown flag, observe a zero counter, and free the queues? When the first thread resumes, it would operate on the freed queues. Should the counter be incremented before checking the flag?

[Severity: High]
When waiting for an interrupt ack in nbl_chan_send_msg(), does a timeout correctly return an error?

    if (ret == 0) {
        if (READ_ONCE(wait_head->status) ==
            NBL_MBX_STATUS_WAITING) {
            wait_head->status =
                NBL_MBX_STATUS_TIMEOUT;
            wait_head->acked = 0;
            wait_head->ack_data = NULL;
            wait_head->ack_data_len = 0;
        }
        spin_unlock_irq(&wait_head->status_lock);
        dev_err(dev,
            "Channel waiting ack failed, message type: %d, msg id: %u\n",
            chan_send->msg_type, msgid);
        goto inflight_dec_out;
    }

Because ret is 0 from wait_event_timeout() and isn't reassigned to an error code like -ETIMEDOUT, will the function return 0 and cause the caller to consume uninitialized or stale response data?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +0 -0
@@ -852,6 +853,49 @@ static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,
 		goto inflight_dec_out;
 	}
 

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt, · line 865

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +10 -0
+	/* Polling: only init/deinit, add shutdown detect to avoid deadlock */
+	while (i--) {
+		if (READ_ONCE(chan_info->shutdown)) {
+			ret = -ESHUTDOWN;
+			goto inflight_dec_out;
+		}
+		/* Order shutdown read before accessing clean_task/workqueue */
+		smp_rmb();
+		if (READ_ONCE(chan_info->clean_task) && common->wq)
+			queue_work(common->wq, chan_info->clean_task);

[Severity: High]
Can this sequence race with device teardown?

In nbl_dev_remove_common_dev(), the teardown sequence appears to set the task to NULL and cancels the work before the shutdown flag is set:

nbl_dev_remove_common_dev()

    nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX, NULL);
    cancel_work_sync(&common_dev->clean_mbx_task);
    nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);

If a sender bypasses the shutdown check and enters the polling loop, can the double read of chan_info->clean_task allow queue_work()
to be called with a NULL pointer, or to queue the work after it was already cancelled, leading to a use-after-free when the work accesses the freed queues?

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +3 -0
+
+		spin_lock_irq(&wait_head->status_lock);
+		if (READ_ONCE(wait_head->acked)) {

[ ... ]

maintainer
#26 lore raw
In reply to illusion.wang
Quoted 8 lines · On Thu, 23 Jul 2026 12:00:52 +0800 illusion.wang wrote:

This patch series represents the first phase. We plan to integrate it in two phases: the first phase covers mailbox and chip configuration, while the second phase involves net dev configuration. Together, they will provide basic PF-based Ethernet port transmission and reception capabilities.

After that, we will consider other features, such as ethtool support, flow management, adminq messaging, VF support, debugfs support, etc.

There's a large number of abstractions in this series with a single implementation. It'd help review if those were removed until they are actually needed.