Skip to contentSkip to conversation

nbl driver for Nebulamatrix NICs

PATCH Superseded illusion.wang 2 participants 20 messages Aug 31 – Sep 3

Subsystems (4)

v26 of 35 Superseded Latest is v35 →

lore
Share & tools
lore

illusion.wang

author maintainer
#0 lore raw

v26 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

changes v25->v26
Link to v25:https://lore.kernel.org/netdev/[email protected]/ AI review issues

changes v24->v25
Link to v24:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.Issues found by Jakub

changes v23->v24
Link to v23:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.Issues found by Jakub

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

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 (10):
net/nebula-matrix: add minimum nbl build framework net/nebula-matrix: add core driver architecture and HW layer
initialization
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: implement channel RPC framework and
serialize hardware 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    |   31 +
 drivers/net/ethernet/nebula-matrix/Makefile   |    6 +
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   15 +
 .../nbl/nbl_channel/nbl_channel.c             | 1220 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  170 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  231 ++++
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   32 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   45 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      |  504 +++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |   55 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c |  650 +++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |   25 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |   23 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |   12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 1093 +++++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  352 +++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  346 +++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   12 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   77 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  |  402 ++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |   21 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   |  150 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  109 ++
 .../nbl/nbl_include/nbl_def_channel.h         |  182 +++
 .../nbl/nbl_include/nbl_def_common.h          |   69 +
 .../nbl/nbl_include/nbl_def_dev.h             |   16 +
 .../nbl/nbl_include/nbl_def_dispatch.h        |   56 +
 .../nbl/nbl_include/nbl_def_hw.h              |   68 +
 .../nbl/nbl_include/nbl_def_resource.h        |   38 +
 .../nbl/nbl_include/nbl_include.h             |   56 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  243 ++++
 36 files changed, 6350 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 v26 1/10 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    |  31 ++++++
 drivers/net/ethernet/nebula-matrix/Makefile   |   6 ++
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   6 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |  13 +++
 .../nbl/nbl_include/nbl_include.h             |  14 +++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 100 ++++++++++++++++++
 11 files changed, 211 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 d9980c84487a..403ae9c2b06a 100644
@@ -48,6 +48,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 460cb7268845..ab55ba0da0a2 100644
@@ -18654,6 +18654,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 8581ccba1505..c2b0161d0bec 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 2b1153d35b52..a306dae23bcb 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 +31 -0
new file mode 100644
index 000000000000..f16e9663eaed
@@ -0,0 +1,31 @@
+# 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.
+
+	  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..6c14d1071c0c
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Nebula Matrix Limited.
+
+obj-$(CONFIG_NBL) := nbl.o
+
+nbl-objs +=	nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +13 -0
new file mode 100644
index 000000000000..a3d63c698aea
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_CORE_H_
+#define _NBL_CORE_H_
+
+enum {
+	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..16b10bcf1d36
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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
#2 lore raw

Re: [v26,net-next,01/10] net/nebula-matrix: add minimum nbl build framework

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 0 · Low: 1

- [Low] The documentation file added by this patch, Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst…

--

net/nebula-matrix: add minimum nbl build framework

This adds the Kconfig/Makefile/MAINTAINERS entries for a new drivers/net/ethernet/nebula-matrix/ vendor directory, a driver documentation file, and a PCI driver skeleton (nbl_main.c) whose probe and remove callbacks are stubs.

Quoted 14 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +8 -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:
+=========

Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 18

Quoted 10 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +10 -0
+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).

[Severity: Low]
Do these three statements describe what the driver actually does, either at this commit or at the end of the series?

Grepping the vendor directory at the last patch of the series ("net/nebula-matrix: add common dev start/stop operation", 9b90629960395de83faaf5146e29ffc3cb854c5b) finds nothing for any of the netdev or offload plumbing these sentences describe:

  git grep -E 'register_netdev|netdev_ops|alloc_etherdev|ethtool_ops|NETIF_F_' \
      drivers/net/ethernet/nebula-matrix/
  (no matches)

The directory at that point contains only nbl_main.c plus nbl_channel/, nbl_common/, nbl_core/, nbl_hw/ and nbl_include/, so the code binds the PCI function, maps the BARs and brings up the PF mailbox, but never registers a net_device, never programs per-queue Tx/Rx MSI-X vectors, and has no RSS, checksum offload, interrupt moderation or link-speed reporting.

Would it make sense to describe only what is implemented, and add the link speed / per-queue MSI-X / moderation / RSS / checksum text in the patches that introduce those features?

Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 24

Quoted 6 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +6 -0
+
+Support
+=======
+
+For more information about m18110-NIC/m18000-NIC, please visit the following URL:
+https://www.nebula-matrix.com/snic_s1000_en

Is this the right product page? The URL names snic_s1000, while nbl_main.c documents the matched IDs as "SNIC v3r1 product Device IDs
range: 0x3403-0x3412" for m18110/m18000.

Quoted 4 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +4 -0
+
+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].

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +0 -0
new file mode 100644
index 000000000000..f16e9663eaed

[ ... ]

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

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +9 -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.
+
+	  More specific information on configuring the driver is in
+	  <file:Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst>.

The help text points users at the .rst above as the description of the option's capabilities, so the same over-claim reaches anyone selecting
CONFIG_NBL: the prompt says "Ethernet Controller m18110/m18000 support", but no network interface is created by any commit in this series.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#3 lore raw

PATCH v26 2/10 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
- 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 |  18 +++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 152 ++++++++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  14 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |  32 ++++
 .../nbl/nbl_include/nbl_def_common.h          |  32 ++++
 .../nbl/nbl_include/nbl_def_hw.h              |  17 ++
 .../nbl/nbl_include/nbl_include.h             |   9 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  94 ++++++++++-
 9 files changed, 369 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 6c14d1071c0c..cc060cf8bf75 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 +18 -0
index a3d63c698aea..1cd6587a8fcb 100644
@@ -6,8 +6,26 @@
 #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"
+
 enum {
 	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 +152 -0

152 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..a3397f5be353
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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 +32 -0
new file mode 100644
index 000000000000..5e9823e01d39
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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)
+/*
+ * PCI MEMORY BAR total size: 64MiB.
+ */
+#define NBL_MEM_BAR_TOTAL_SIZE			(64ULL << 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;
+	resource_size_t mailbox_bar_size;
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +32 -0
new file mode 100644
index 000000000000..da30244fe75d
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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 +17 -0
new file mode 100644
index 000000000000..ecbf440e4366
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_HW_H_
+#define _NBL_DEF_HW_H_
+
+#include <linux/types.h>
+
+struct nbl_hw_mgt;
+struct nbl_adapter;
+
+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 16b10bcf1d36..14e7b19f9a4c 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 +93 -1

109 lines not on this page · raw message

Signature · 1 line
2.47.3
#4 lore raw

Re: [v26,net-next,02/10] net/nebula-matrix: add core driver architecture and HW layer initialization

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 1 · Low: 0

- [Medium] In nbl_hw_init_leonis() (drivers/net/ethernet/nebula- matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c) two error paths print…

--

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

This adds the nbl_adapter/nbl_core/nbl_common_info device context, the PCI probe/remove entry points with basic capability parsing, and the Leonis hardware layer that requests the BARs and ioremaps them. One question below about the BAR size error paths.

Quoted 6 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 000000000000..a67d1a674466
@@ -0,0 +1,152 @@

[ ... ]

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +7 -0
+int nbl_hw_init_leonis(struct nbl_adapter *adapter)
+{
+	resource_size_t expect_sz = NBL_MEM_BAR_TOTAL_SIZE;
+	struct nbl_common_info *common = &adapter->common;
+	struct pci_dev *pdev = common->pdev;
+	struct nbl_hw_mgt *hw_mgt = NULL;
+	resource_size_t bar_len;

[ ... ]

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

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +4 -0
+		if (bar_len < NBL_MEM_BAR_TOTAL_SIZE) {
+			dev_err(&pdev->dev,
+				"MEMORY BAR len %pr smaller than expected %pr\n",
+				&bar_len, &expect_sz);

[Severity: Medium]
Should these two be %pa rather than %pr?

Both bar_len and expect_sz are plain resource_size_t locals on the stack, but %pr is the struct resource specifier. vsprintf hands it to resource_string(), which dereferences the argument as a struct resource:

lib/vsprintf.c:resource_string() {
	...
	if (res->flags & IORESOURCE_IO) {
	...
		p = hex_range(p, pend, res->start, res->end, *specp);
	...
}

struct resource places flags at offset 24 on 64-bit, so does this read roughly 32 bytes past the end of each 8-byte local and print adjacent kernel stack contents (both the decoded resource type and the second hex value) into dmesg?

Nothing warns at build time because every %p variant just consumes a void *. Documentation/core-api/printk-formats.rst lists %pa[p] for phys_addr_t / resource_size_t, so %pa &bar_len (or a cast to unsigned long long with %llu) would seem to be what is wanted here.

The path is reached from nbl_probe() -> nbl_core_init() -> nbl_hw_init_leonis() whenever common->has_ctrl is set (function 0, not a VF) and pci_resource_len(pdev, NBL_MEMORY_BAR) is below 64MiB.

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +3 -0
+			ret = -EINVAL;
+			goto setup_mgt_fail;
+		}

[ ... ]

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

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +5 -0
+	} else {
+		if (bar_len < NBL_REG_NET_ONLY_LEN) {
+			dev_err(&pdev->dev,
+				"MEMORY BAR len %pr too small for net only reg space\n",
+				&bar_len);

[Severity: Medium]
Same %pr versus %pa question on this second site in nbl_hw_init_leonis(), which fires on a non-ctrl function when the MEMORY BAR is reported smaller than 8KiB.

This one still appears unchanged at the end of the series, so no later patch in the set seems to address it.

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +3 -0
+			ret = -EINVAL;
+			goto setup_mgt_fail;
+		}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#5 lore raw

PATCH v26 3/10 net/nebula-matrix: add channel layer

In reply to illusion.wang

From: illusion wang <[email protected]>

Add generic channel management layer for Nebula Matrix network adapter, which serves as the core inter-PF communication component, providing standardized message transmission, queue management and hardware abstraction capabilities.

The new channel layer implements mailbox-based inter-PF(PF0 <-> other PFs) communication framework with the following core features:
1. Dynamic Message Handling Framework
- Implement hash-table-based message handler management with O(1) lookup by message type, supporting dynamic message handler registration
- Support two transmission modes: fire-and-forget and synchronous send with ACK waiting
- Implement dedicated ACK message processing path to match synchronous request-response semantics
- Add TX slot concurrency control, return -EAGAIN when all outstanding slots are occupied under high load
- Dual data transmission format: small embedded payload in TX descriptor, large payload via external DMA buffer
- Support full cleanup of message handlers during driver teardown
2. Mailbox Queue Management
- Initialize TX/RX descriptor rings and data buffers via coherent DMA allocation and devm managed memory
- Complete queue lifecycle management: hardware queue init/config/stop/ teardown
- Support dual RX processing modes: interrupt-driven and mailbox polling path, offload heavy RX descriptor cleanup work to dedicated workqueue to reduce interrupt latency
- Implement inflight TX traffic draining and pending ACK request abortion during queue teardown
- Queue resource lifecycle design: DMA buffers are allocated once in probe phase and released automatically by devm on driver remove, dynamic runtime queue reinit is not supported
- Maintain accurate RX ring empty/full state differentiation via reserved hole entry mechanism, avoiding ring overflow and repeated reception
3. Hardware Abstraction Layer(HW OPS)
- Abstract hardware-specific mailbox operations into independent hw_ops layer, decouple channel logic from hardware implementation
- Provide hardware queue configuration, tail pointer doorbell update, PF mailbox routing table configuration interfaces
- Add register lock protection for hardware register read/write to ensure concurrent access safety
4. Common Utility & Infrastructure
- Implement generic thread-safe hash table management for message handler storage
- Create dedicated device-bound workqueue for RX cleanup task scheduling
- Supplement core data structures, state management and bitmask state control interfaces

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |    4 +-
 .../nbl/nbl_channel/nbl_channel.c             | 1220 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  170 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  209 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   32 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |    7 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  179 +++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |   56 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   34 +
 .../nbl/nbl_include/nbl_def_channel.h         |  126 ++
 .../nbl/nbl_include/nbl_def_common.h          |   18 +
 .../nbl/nbl_include/nbl_def_hw.h              |   33 +
 .../nbl/nbl_include/nbl_include.h             |    3 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |    7 +
 14 files changed, 2097 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
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
index cc060cf8bf75..04e1aa1fb4bd 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 +1220 -0

1,220 lines not on this page · raw message

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

170 lines not on this page · raw message

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

209 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +32 -0
new file mode 100644
index 000000000000..159421e53902
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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"
+
+struct nbl_hash_tbl_mgt {
+	struct nbl_hash_tbl_key tbl_key;
+	struct hlist_head *hash;
+	/**
+	 * bucket_locks: per-bucket spinlock array
+	 * Each hash bucket corresponds to an independent spinlock.
+	 * Protects concurrent hash list modification
+	 */
+	spinlock_t *bucket_locks;
+	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 +7 -0
index 1cd6587a8fcb..f998a2b44e5c 100644
@@ -14,13 +14,20 @@ enum {
 	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;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +179 -0

204 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 +34 -0
index 5e9823e01d39..35604bdff2ae 100644
@@ -8,6 +8,7 @@
 
 #include <linux/types.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"
@@ -16,6 +17,7 @@
 #define NBL_MAILBOX_BAR				2
 #define NBL_RDMA_NOTIFY_LEN			(8ULL << 10)
 #define NBL_REG_NET_ONLY_LEN			(8ULL << 10)
+#define NBL_HW_DUMMY_REG			0x1300904
 /*
  * PCI MEMORY BAR total size: 64MiB.
  */
@@ -27,6 +29,38 @@ struct nbl_hw_mgt {
 	u8 __iomem *mailbox_bar_hw_addr;
 	resource_size_t hw_size;
 	resource_size_t mailbox_bar_size;
+	spinlock_t reg_lock; /* Protect reg access */
 };
 
+static inline u32 rd32(u8 __iomem *addr, u64 reg)
+{
+	return readl(addr + reg);
+}
+
+static inline void wr32(u8 __iomem *addr, u64 reg, u32 value)
+{
+	writel(value, addr + reg);
+}
+
+static inline void nbl_hw_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
+{
+	/* Used for emu, make sure that we won't write too frequently */
+	wr32(hw_mgt->hw_addr, reg, value);
+}
+
+static inline u32 nbl_hw_rd32(struct nbl_hw_mgt *hw_mgt, u64 reg)
+{
+	return rd32(hw_mgt->hw_addr, reg);
+}
+
+static inline void nbl_mbx_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
+{
+	writel(value, hw_mgt->mailbox_bar_hw_addr + reg);
+}
+
+static inline u32 nbl_mbx_rd32(struct nbl_hw_mgt *hw_mgt, u64 reg)
+{
+	return readl(hw_mgt->mailbox_bar_hw_addr + reg);
+}
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +126 -0

126 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +18 -0
index da30244fe75d..4916c384611b 100644
@@ -12,6 +12,7 @@
 #include "nbl_include.h"
 
 struct nbl_common_info {
+	struct workqueue_struct *wq;
 	struct pci_dev *pdev;
 	struct device *dev;
 	u32 msg_enable;
@@ -29,4 +30,21 @@ 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;
+};
+
+void nbl_common_destroy_wq(struct nbl_common_info *common);
+int nbl_common_create_wq(struct nbl_common_info *common);
+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 +33 -0
index ecbf440e4366..587ac0c58c24 100644
@@ -10,6 +10,39 @@
 
 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);
+	/**
+	 * get_host_pf_mask - Fetch host PF mask from firmware k_pf_mask reg
+	 * @priv: hw ops private context
+	 * @pf_mask: output pointer for PF mask value
+	 *
+	 * Mask: bit N == 0 → PF#N enabled; bit N == 1 → PF#N masked out.
+	 * PF0 cannot be masked, bit0 is reserved and has no hardware effect.
+	 * All-zero mask indicates all supported PFs are present and enabled.
+	 * This mask value is NOT an indicator of firmware readiness.
+	 *
+	 * Product limitation: firmware shall only produce configurations with
+	 * 1 PF(PF0), 2 PFs(PF0+PF1), or 4 PFs(PF0~PF3). Sparse PF layout
+	 * or other PF counts are unsupported by driver resource management.
+	 */
+	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);
+
+	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;
+};
 
 int nbl_hw_init_leonis(struct nbl_adapter *adapter);
 void nbl_hw_remove_leonis(struct nbl_adapter *adapter);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +3 -0
index 14e7b19f9a4c..f2d802397d98 100644
@@ -10,6 +10,9 @@
 
 /*  ------  Basic definitions  -------  */
 #define NBL_DRIVER_NAME					"nbl"
+#define NBL_MAX_PF					8
+#define NBL_NEXT_ID(id, max) (((id) + 1) % ((max) + 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 f2552bc73293..b7c80ea54c8d 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
#6 lore raw

Re: [v26,net-next,03/10] net/nebula-matrix: add channel layer

Thank you for your contribution! Sashiko AI review found 22 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 22 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 2 · Low: 20

- [Medium] nbl_chan_get_msg_id() treats a wait slot in NBL_MBX_STATUS_TIMEOUT as free, but the timed-out owner has not…
- [Medium] nbl_chan_kick_tx_ring() rings the TX doorbell and polls for NBL_CHAN_TX_DESC_USED; on timeout it executes 'txq->next_to_clean =…
- [Low] Commit message describes an operational mailbox framework (queue lifecycle, dual RX modes, DMA buffers "allocated once in probe phase")…
- [Low] nbl_chan_setup_queue() re-runs all dmam_alloc_coherent()/devm_kcalloc() allocations (~2 MB per cycle)…
- [Low] The data paths (nbl_chan_send_msg(), nbl_chan_clean_queue()) gate only on chan_info->shutdn and never on chan_info->active, so a send or…
- [Low] The commit message claims the patch adds "register lock protection for hardware register read/write to ensure concurrent…
- [Low] The comment in nbl_chan_cfg_qinfo_map_table() justifies iterating raw hardware PF func_ids by claiming nbl_res_init_pf_num() already…
- [Low] nbl_hw_rd_regs_lock()/nbl_hw_wr_regs_lock() perform readl()/writel() at BAR0 offsets 0x1505004 (k_pf_mask) and 0xfb1000+…
- [Low] nbl_chan_cfg_qinfo_map_table() consumes the raw k_pf_mask value without honouring the driver's own documented contract (bit0 reserved…
- [Low] The kernel-doc block for struct nbl_hw_ops::get_host_pf_mask documents '@priv: hw ops private context', but the documented member's…
- [Low] The drain-strategy comment in nbl_chan_teardown_queue() justifies the 5 s inflight-drain timeout by asserting that every sender has 'its…
- [Low] nbl_chan_get_msg_id() stores the slot it just claimed back into chan_info->wait_head_index under a comment saying 'Advance starting…
- [Low] nbl_hw_wr32() in nbl_hw_reg.h carries the comment 'Used for emu, make sure that we won't write too frequently' although the body is a…
- [Low] nbl_chan_teardown_queue() returns the raw wait_event_timeout() result, so on success it returns a positive jiffies count (up to…
- [Low] The device-removal path never tears down an active mailbox queue before releasing channel resources: nbl_chan_remove_common() destroys…
- [Low] nbl_common_get_hash_node() returns hash_node->data after dropping the per-bucket spin_lock_bh with no reference count or RCU, and…
- [Low] chan_info->active/shutdn, the state bitmap, inflight_wait and inflight_tx_cnt are documented as guarded by state_lock, but…
- [Low] nbl_chan_set_queue_state() clears NBL_CHAN_IRQ_RDY, which is part of the wait condition used by the interrupt-mode ACK waiter in…
- [Low] In nbl_chan_update_txqueue() the external-buffer path copies the payload only 'if (param->arg)' but unconditionally programs…
- [Low] Every channel op taking a u8 chan_type indexes chan_mgt->chan_info[chan_type] (array size NBL_CHAN_TYPE_MAX == 1)…
- [Low] In nbl_chan_kick_tx_ring()'s completion-poll loop, dma_rmb() is issued before the load of tx_desc->flags with the comment 'Order…
- [Low] nbl_hw_init_leonis() accepts any non-zero mailbox BAR length, while nbl_hw_write_mbx_regs() silently drops out-of-range register…

--

net/nebula-matrix: add channel layer

This adds the mailbox based inter-PF channel layer for the nbl driver, including the message handler hash table, TX/RX descriptor ring management with coherent DMA buffers, and a hardware abstraction layer for the mailbox queue registers. A few questions below about the channel state machine, the TX completion poll and some comments that do not appear to match the code.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0 -0
new file mode 100644
index 000000000000..c29ff76a75ae
@@ -0,0 +1,1220 @@

[ ... ]

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

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5 -0
+	/*
+	 * Step3:
+	 * wait all sender exit
+	 *
+	 * Drain strategy mirrors mlx5 command interface teardown:

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+	 * set shutdown flag first, abort all pending waiters, then
+	 * block until inflight_tx_cnt reaches zero.
+	 *
+	 * A timeout here is treated as an exceptional condition rather
+	 * than a fatal error, following the same rationale as mlx5:
+	 *   - shutdn is already set, so every sender path observes it
+	 *     at its next checkpoint and exits;
+	 *   - each sender has its own bounded timeout (3s ACK wait,
+	 *     12ms max TX ring poll), all far shorter than this 5s
+	 *     drain window, so stalling beyond 5s should never happen

[Severity: Low]
Is the "3s ACK wait" bound accurate for both wait modes? The 3 * HZ bound (NBL_CHAN_ACK_WAIT_TIME) applies only to the interrupt branch of nbl_chan_send_msg(). The polling branch loops NBL_CHAN_TX_WAIT_ACK_TIMES times with usleep_range():

	int i = NBL_CHAN_TX_WAIT_ACK_TIMES;
	...
		while (i--) {
			...
			usleep_range(NBL_CHAN_TX_WAIT_ACK_US_MIN,
				     NBL_CHAN_TX_WAIT_ACK_US_MAX);

With NBL_CHAN_TX_WAIT_ACK_TIMES = 5000 and 1000-1200 us per iteration that is roughly 5-6 s, which is longer than the 5 s drain window the comment says every sender bound is "far shorter" than. Should the comment be corrected, or the constants adjusted?

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

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +12 -0
+	 *   - in that hardware-dead case proceeding with teardown cannot
+	 *     make the situation worse, and avoids hanging rmmod forever.
+	 */
+	ret = wait_event_timeout(chan_info->inflight_wait,
+				 atomic_read(&chan_info->inflight_tx_cnt) == 0,
+				 msecs_to_jiffies(5000));
+
+	if (!ret) {
+		dev_warn(chan_mgt->common->dev,
+			 "teardown: inflight tx drain timeout\n");
+		ret = -ETIMEDOUT;
+	}

[Severity: Low]
On the success path this returns the raw wait_event_timeout() value, i.e. the remaining jiffies (up to ~5000), through

	int (*teardown_queue)(struct nbl_channel_mgt *chan_mgt, u8 chan_type);

while the early "channel not active" path of the same function returns
0. Would it be better to normalise the success case to 0 so a caller doing "if (ret) goto err;" does not treat a fully drained queue as a failure?

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +13 -0
+
+	/* After all TX drained, stop hardware queue */
+	nbl_chan_stop_queue(chan_mgt);
+
+	/* All send paths drained, safely cancel cleanup work */
+	if (task)
+		cancel_work_sync(task);
+	WRITE_ONCE(chan_info->active, false);
+	return ret;
+}
+
+static int nbl_chan_setup_queue(struct nbl_channel_mgt *chan_mgt, u8 chan_type)
+{

[ ... ]

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

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +7 -0
+	nbl_chan_config_queue(chan_mgt, chan_info, true); /* tx */
+	nbl_chan_config_queue(chan_mgt, chan_info, false); /* rx */
+	nbl_chan_update_tail_ptr(hw_ops, chan_mgt->hw_ops_tbl->priv,
+				 rxq->tail_ptr, NBL_MB_RX_QID);
+	WRITE_ONCE(chan_info->active, true);
+	return 0;
+}

[Severity: Low]
Can this mark the channel active when the hardware queues were never programmed? nbl_chan_config_queue() calls config_mailbox_txq/rxq, which are void and end up in nbl_hw_write_mbx_regs(); that helper drops out-of-range writes after a dev_err_once() and returns void, so the failure cannot reach here.

nbl_hw_init_leonis() only rejects a mailbox BAR of length zero, while the queue configuration tables are written at NBL_MAILBOX_QINFO_CFG_RX_TABLE_ADDR (0x10) and NBL_MAILBOX_QINFO_CFG_TX_TABLE_ADDR (0x20) plus 16 bytes each. On a BAR2 smaller than 0x30 the writes are silently skipped, the RX doorbell is still rung and active is set to true.

Would it make sense to validate the mailbox BAR against the highest register offset the driver uses at probe time, and/or let the config ops return an error?

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +2 -0
+
+static int nbl_chan_update_txqueue(struct nbl_channel_mgt *chan_mgt,

[ ... ]

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

[ ... ]

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+	while (retry_count < max_retries) {
+		if (READ_ONCE(chan_info->shutdn))
+			return -ESHUTDOWN;
+
+		/* Order descriptor read after hardware DMA completion */
+		dma_rmb();
+		if (le16_to_cpu(READ_ONCE(tx_desc->flags)) &
+		    BIT(NBL_CHAN_TX_DESC_USED)) {
+			break;
+		}

[Severity: Low]
Does the dma_rmb() here provide the ordering the comment describes? It is issued before the load of tx_desc->flags, so it cannot order later reads of device-written descriptor fields against observing USED. The RX side in nbl_chan_clean_queue() uses the other order:

	while (le16_to_cpu(READ_ONCE(rx_desc->flags)) &
	       BIT(NBL_CHAN_RX_DESC_USED)) {
		...
		/* Make sure hardware written descriptor visible to CPU */
		dma_rmb();
		nbl_chan_recv_msg(chan_mgt, rx_buf->va);

Should the TX poll follow the same pattern, loading flags first and placing dma_rmb() between the USED test and any other descriptor field?

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

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11 -0
+
+		retry_count++;
+		if (retry_count == max_retries) {
+			msg_type = le16_to_cpu(READ_ONCE(tx_desc->msg_type));
+			dev_err_ratelimited(dev, "chan send msg type: %d timeout\n",
+					    msg_type);
+			txq->next_to_clean = txq->next_to_use;
+			return -ETIMEDOUT;
+		}
+		usleep_range(NBL_CHAN_TX_WAIT_US, NBL_CHAN_TX_WAIT_US_MAX);
+	}

[Severity: Medium]
On the timeout path the descriptor is still marked AVAIL, i.e. owned by the device, but next_to_clean is force-synced to next_to_use and the mailbox TX queue is left enabled with no reset. The -ESHUTDOWN early return leaves next_to_clean behind next_to_use with a device-owned descriptor outstanding.

nbl_chan_update_txqueue() then republishes slots with no producer / consumer fullness or ownership test:

	struct nbl_chan_tx_desc *tx_desc =
		NBL_CHAN_TX_RING_TO_DESC(txq, txq->next_to_use);
	struct nbl_chan_buf *tx_buf =
		NBL_CHAN_TX_RING_TO_BUF(txq, txq->next_to_use);
	...
		if (param->arg)
			memcpy(tx_buf->va, param->arg, param->arg_len);
	...
	tx_desc->flags = cpu_to_le16(BIT(NBL_CHAN_TX_DESC_AVAIL));

After NBL_CHAN_QUEUE_LEN further sends the ring wraps onto that slot. Can this rewrite a descriptor and its coherent tx_buf while the device is still fetching or DMAing them? Would quiescing the queue with stop_mailbox_txq() (or rolling tail_ptr back) on the timeout path, plus a fullness check in nbl_chan_update_txqueue(), be needed here?

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5 -0
+
+	txq->next_to_clean = txq->next_to_use;
+
+	return 0;
+}

[ ... ]

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

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +13 -0
+static int nbl_chan_get_msg_id(struct nbl_chan_info *chan_info,
+			       u16 *msgid)
+{
+	int search_loc = READ_ONCE(chan_info->wait_head_index), i;
+	struct nbl_chan_waitqueue_head *wait = NULL;
+	int status;
+
+	lockdep_assert_held(&chan_info->pending_lock);
+	for (i = 0; i < chan_info->num_txq_entries; i++) {
+		wait = &chan_info->wait[search_loc];
+		status = READ_ONCE(wait->status);
+		if (status == NBL_MBX_STATUS_IDLE ||
+		    status == NBL_MBX_STATUS_TIMEOUT) {

[Severity: Medium]
Is a slot in NBL_MBX_STATUS_TIMEOUT really free at this point? The timed-out owner sets that status under pending_lock and then drops the lock before it releases the slot:

nbl_chan_send_msg()

	mutex_lock(&chan_info->pending_lock);
	if (READ_ONCE(wait_head->status) == NBL_MBX_STATUS_WAITING) {
		WRITE_ONCE(wait_head->status, NBL_MBX_STATUS_TIMEOUT);
		...
	}
	mutex_unlock(&chan_info->pending_lock);
	dev_err_ratelimited(...);
	ret = -ETIMEDOUT;
	goto out_clear_wait_slot;

out_clear_wait_slot:

	mutex_lock(&chan_info->pending_lock);
	nbl_chan_reset_wait_head(chan_info, wait_head);

If a second sender claims the same slot in that window, the reset then clears the new owner's state, since nbl_chan_reset_wait_head() has no ownership check:

	WRITE_ONCE(wait_head->status, NBL_MBX_STATUS_IDLE);
	WRITE_ONCE(wait_head->ack_data, NULL);
	WRITE_ONCE(wait_head->ack_data_len, 0);

The second sender can then be woken on the shared wait_queue and consume another request's ack_data_len / ack_err:

		if (READ_ONCE(wait_head->acked)) {
			smp_rmb();
			chan_send->ack_len = READ_ONCE(wait_head->ack_data_len);
			ret = READ_ONCE(wait_head->ack_err);

Can that return success with a non-zero ack_len while chan_send->resp was never written, so the caller reads uninitialised memory as a mailbox reply? Would releasing the slot to IDLE in the same critical section that sets TIMEOUT, or adding a generation/ownership check in nbl_chan_reset_wait_head(), close this?

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

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11 -0
+			WRITE_ONCE(wait->msg_index,
+				   NBL_NEXT_ID(wait->msg_index,
+					       NBL_CHAN_MSG_INDEX_MAX));
+
+			*msgid = FIELD_PREP(NBL_CHAN_MSGID_INDEX_MASK,
+					    wait->msg_index) |
+				 FIELD_PREP(NBL_CHAN_MSGID_LOC_MASK,
+					    search_loc);
+
+			/* Advance starting search position for next caller */
+			WRITE_ONCE(chan_info->wait_head_index, search_loc);

[Severity: Low]
The comment says the search position is advanced, but the slot that was just claimed is stored back, so the next caller starts at the same index. Was NBL_NEXT_ID(search_loc, chan_info->num_txq_entries - 1) intended?

As written, a single sender keeps reusing wait[0], so the 6-bit generation field NBL_CHAN_MSGID_INDEX_MASK wraps every 64 requests instead of the msgid space being spread over the 256 slots. That is the field nbl_chan_recv_ack_msg() uses to reject stale ACKs:

	if (FIELD_GET(NBL_CHAN_MSGID_INDEX_MASK, ack_msgid) != w_msgidx) {
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +2 -0
+			return 0;
+		}

[ ... ]

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

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11 -0
+static void nbl_chan_set_queue_state(struct nbl_channel_mgt *chan_mgt,
+				     enum nbl_chan_state state, u8 chan_type,
+				     u8 set)
+{
+	struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type];
+
+	if (set)
+		set_bit(state, chan_info->state);
+	else
+		clear_bit(state, chan_info->state);
+}

[Severity: Low]
Clearing NBL_CHAN_IRQ_RDY makes the wait condition in nbl_chan_send_msg() true:

			ret = wait_event_timeout(wait_head->wait_queue,
						 READ_ONCE(wait_head->acked) ||
						 READ_ONCE(chan_info->shutdn) ||
						 !test_bit(NBL_CHAN_IRQ_RDY,
							   chan_info->state),
						 NBL_CHAN_ACK_WAIT_TIME);

but no wake_up() of the per-slot wait queues follows the clear_bit(). Should the waiters be woken here? Otherwise a sleeping sender only notices the mode change when the 3 s timeout expires and then reports -ETIMEDOUT rather than the -EIO the !test_bit() branch is meant to return.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +0 -0
new file mode 100644
index 000000000000..e6d96768a5b5
@@ -0,0 +1,170 @@

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +3 -0
+#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

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +4 -0
+#define NBL_CHAN_MSG_INDEX_MAX 63
+
+#define NBL_CHAN_MSGID_INDEX_MASK GENMASK(5, 0)
+#define NBL_CHAN_MSGID_LOC_MASK GENMASK(13, 6)

[ ... ]

Quoted 31 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +23 -0
index a67d1a674466..24b15418e601 100644
@@ -10,6 +10,156 @@
 #include <linux/bitfield.h>
 #include "nbl_hw_leonis.h"
 
+static void nbl_hw_write_mbx_regs(struct nbl_hw_mgt *hw_mgt, u64 reg,
+				  const u32 *data, u32 len)
+{
+	u32 i;
+
+	if (len % 4)
+		return;
+	if (reg >= (u64)hw_mgt->mailbox_bar_size ||
+	    reg + len > (u64)hw_mgt->mailbox_bar_size) {
+		dev_err_once(hw_mgt->common->dev,
+			     "mbx write out of range: reg=0x%llx len=%u bar_size=%pa\n",
+			     reg, len, &hw_mgt->mailbox_bar_size);
+		return;
+	}
+	for (i = 0; i < len / 4; i++)
+		nbl_mbx_wr32(hw_mgt, reg + i * sizeof(u32), data[i]);
+}
+
+static void nbl_hw_rd_regs_lock(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 *data,
+				u32 len)
+{
+	u32 size = len / 4;
+	u32 i;

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+
+	if (len % 4)
+		return;
+
+	spin_lock(&hw_mgt->reg_lock);
+
+	for (i = 0; i < size; i++)
+		data[i] = rd32(hw_mgt->hw_addr, reg + i * sizeof(u32));
+	spin_unlock(&hw_mgt->reg_lock);
+}

[Severity: Low]
The changelog says:

- Add register lock protection for hardware register read/write to ensure concurrent access safety

Does that cover the mailbox path? Only nbl_hw_rd_regs_lock() and nbl_hw_wr_regs_lock() take hw_mgt->reg_lock. nbl_hw_write_mbx_regs() above takes no lock, and it is the only writer used by config_mailbox_rxq/txq and stop_mailbox_rxq/txq for the four dword QINFO configuration sequence, which looks like it wants to be one atomic programming step. nbl_hw_update_mailbox_queue_tail_ptr() is also unlocked. Should the changelog be narrowed, or should the mailbox BAR helpers take the same lock?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +0 -0
index 5e9823e01d39..35604bdff2ae 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h struct nbl_hw_mgt { · line 49

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +5 -0
+static inline void nbl_hw_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
+{
+	/* Used for emu, make sure that we won't write too frequently */
+	wr32(hw_mgt->hw_addr, reg, value);
+}

[Severity: Low]
The comment promises rate limiting, but the body is a plain writel() with no delay or throttling. Should the comment be dropped?

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0 -0
index ecbf440e4366..587ac0c58c24 100644
@@ -10,6 +10,39 @@

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h line 25

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +4 -0
+	/**
+	 * get_host_pf_mask - Fetch host PF mask from firmware k_pf_mask reg
+	 * @priv: hw ops private context
+	 * @pf_mask: output pointer for PF mask value

[Severity: Low]
The documented member has no priv parameter:

	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);

kernel-doc will report an excess parameter priv and a missing hw_mgt. Should the tag be renamed to @hw_mgt?

[ ... ]

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +1 -0
+	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#7 lore raw

PATCH v26 4/10 net/nebula-matrix: add common resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

The Resource layer processes entries and data of chip modules to implement entry management operations.

This patch provides the common part of resource layer, including conversion helpers between vsi_id, func_id, eth_id, and pf_id. These mappings are used by upper layers and the resource layer itself.

nbl_res_start() initializes VSI/Eth/PF data structures only for control devices (common->has_ctrl == true). Framework dispatch layer ensures resource mapping APIs such as nbl_res_func_id_to_vsi_id() are only invoked on control devices.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   2 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  22 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  70 +++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  14 +
 .../nbl_hw_leonis/nbl_resource_leonis.c       | 334 ++++++++++++++++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |  10 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   | 120 +++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  73 ++++
 .../nbl/nbl_include/nbl_def_channel.h         |  10 +
 .../nbl/nbl_include/nbl_def_common.h          |  19 +
 .../nbl/nbl_include/nbl_def_hw.h              |   5 +
 .../nbl/nbl_include/nbl_def_resource.h        |  29 ++
 .../nbl/nbl_include/nbl_include.h             |   6 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 15 files changed, 724 insertions(+), 1 deletion(-)
 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 04e1aa1fb4bd..3dab9519a277 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 +22 -0
index 38abf41d9bb0..597c11ed7fd8 100644
@@ -30,6 +30,28 @@ int nbl_common_create_wq(struct nbl_common_info *common)
 	return 0;
 }
 
+/**
+ * nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id
+ * @common: common device info
+ * @pf_id: absolute PF identifier
+ * @rel_pf_id: output relative pf id
+ *
+ * Leonis uses fixed mgt_pf = 0. Support future non-zero management PF.
+ *
+ * Return: 0 on success, -EINVAL on invalid arguments.
+ */
+int nbl_common_func_id_to_rel_pf_id(struct nbl_common_info *common, u32 pf_id,
+				    u32 *rel_pf_id)
+{
+	if (!rel_pf_id)
+		return -EINVAL;
+
+	if (pf_id < common->mgt_pf)
+		return -EINVAL;
+	*rel_pf_id = pf_id - common->mgt_pf;
+	return 0;
+}
+
 static u32 nbl_common_calc_hash_key(void *key, u32 key_size, u32 bucket_size)
 {
 	u32 hash;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index f998a2b44e5c..dd24ebec0171 100644
@@ -16,11 +16,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 +69 -1

108 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 99ee126db9dc..88772a11124a 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 +334 -0

334 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..b9355262c00d
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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 +120 -0

120 lines not on this page · raw message

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

73 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +10 -0
index 4fc987c0e56d..61dd97c779ef 100644
@@ -39,6 +39,16 @@ enum nbl_chan_state {
 	NBL_CHAN_STATE_NBITS
 };
 
+struct nbl_board_port_info {
+	u8 eth_num;
+	u8 eth_speed;
+	u8 p4_version;
+	u8 rsv[5];
+};
+
+static_assert(sizeof(struct nbl_board_port_info) == 8,
+	      "nbl_board_port_info size must be 8 bytes");
+
 struct nbl_chan_send_info {
 	void *arg;
 	size_t arg_len;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +19 -0
index 4916c384611b..b3bdecb23b47 100644
@@ -11,6 +11,22 @@
 #include <linux/device.h>
 #include "nbl_include.h"
 
+#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
+
+static inline u32 nbl_vsi_id_gap(u32 m)
+{
+	if (m == NBL_FOUR_ETHERNET_PORT)
+		return NBL_FOUR_ETHERNET_VSI_ID_GAP;
+	else if (m == NBL_TWO_ETHERNET_PORT)
+		return NBL_TWO_ETHERNET_VSI_ID_GAP;
+
+	return NBL_DEFAULT_VSI_ID_GAP;
+}
+
 struct nbl_common_info {
 	struct workqueue_struct *wq;
 	struct pci_dev *pdev;
@@ -25,6 +41,7 @@ struct nbl_common_info {
 	u8 devid;
 	u8 bus;
 	u8 hw_bus;
+	u16 mgt_pf;
 
 	u8 has_ctrl;
 	u8 has_net;
@@ -40,6 +57,8 @@ struct nbl_hash_tbl_key {
 
 void nbl_common_destroy_wq(struct nbl_common_info *common);
 int nbl_common_create_wq(struct nbl_common_info *common);
+int nbl_common_func_id_to_rel_pf_id(struct nbl_common_info *common, u32 pf_id,
+				    u32 *rel_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 +5 -0
index 587ac0c58c24..ee53f9e10a8e 100644
@@ -8,6 +8,7 @@
 
 #include <linux/types.h>
 
+struct nbl_board_port_info;
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
@@ -34,9 +35,13 @@ struct nbl_hw_ops {
 	 * or other PF counts are unsupported by driver resource management.
 	 */
 	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);
+	void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt, u8 *bus);
 
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);
+	void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
+	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..7136b282fb80
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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 +6 -0
index f2d802397d98..59e44feab44f 100644
@@ -13,6 +13,12 @@
 #define NBL_MAX_PF					8
 #define NBL_NEXT_ID(id, max) (((id) + 1) % ((max) + 1))
 
+#define NBL_MAX_ETHERNET				4
+
+enum {
+	NBL_VSI_DATA = 0,
+};
+
 struct nbl_func_caps {
 	u32 has_ctrl:1;
 	u32 has_net:1;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
index b7c80ea54c8d..1aafed2d46d7 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
#8 lore raw

Re: [v26,net-next,04/10] net/nebula-matrix: add common resource implementation

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 2 · Low: 4

- [Medium] New, undisclosed fatal probe conditions derived purely from firmware/register content.
- [Medium] The kernel-doc contract of nbl_hw_ops::get_host_pf_mask in nbl_include/nbl_def_hw.h states 'PF0 cannot be masked, bit0 is…
- [Low] The commit message and a new code comment describe consumers and an execution-order guarantee that do not exist at this commit, and the…
- [Low] nbl_include/nbl_def_channel.h newly uses static_assert() but is not self-contained: its only include is <linux/types.h> (which pulls…
- [Low] The kernel-doc block for nbl_hw_ops::get_host_pf_mask documents '@priv: hw ops private context', but the declared first parameter is…
- [Low] Comment/implementation mismatch in nbl_res_ctrl_dev_setup_eth_info(): the comment states 'Code accepts…

--

net/nebula-matrix: add common resource implementation

This patch adds the common resource layer for the nbl driver, with helpers converting between vsi_id, func_id, eth_id and pf_id, plus new hw ops to read the board info, the FW eth bitmap and the real bus number. nbl_res_init_leonis() is now called from nbl_core_init() and initializes the VSI/Eth/PF data only for control devices.

A few questions below about the new firmware topology checks, the ops documentation and some of the new comments.

Quoted 4 lines

nbl_res_start() initializes VSI/Eth/PF data structures only for control devices (common->has_ctrl == true). Framework dispatch layer ensures resource mapping APIs such as nbl_res_func_id_to_vsi_id() are only invoked on control devices.

[Severity: Low]
Which dispatch layer is meant here? At this commit nbl_core_init() returns right after nbl_res_init_leonis():

	ret = nbl_res_init_leonis(adapter);
	if (ret)
		goto res_init_fail;
	return adapter;

adap->intf.resource_ops_tbl is published but has no consumer yet, and nbl_res_vsi_id_to_pf_id() and nbl_res_pf_dev_vsi_type_to_hw_vsi_type() are non-static with no users outside nbl_resource.c.

Could the commit message describe the guarantee that exists at this point in the series, i.e. the has_ctrl checks inside the helpers themselves?

The same concern applies to the ordering comment in nbl_res_ctrl_dev_sriov_info_init(), see below.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +0 -0
new file mode 100644
index 000000000000..a719cc8fbf8a
@@ -0,0 +1,334 @@

[ ... ]

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

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +11 -0
+	eth_info->eth_num = fw_port_num;
+	/* Intentional design constraint: each PF maps to exactly one
+	 * Ethernet port. This couples PF identity to port identity
+	 * and is required by nbl_res_get_eth_id() which indexes
+	 * eth_info->eth_id[] by relative PF id.
+	 */
+	if (res_mgt->resource_info->max_pf != eth_info->eth_num) {
+		dev_err(dev, "Invalid PF-to-port topology: max_pf=%u, eth_num=%u\n",
+			res_mgt->resource_info->max_pf, eth_info->eth_num);
+		return -EINVAL;
+	}

[Severity: Medium]
Is the equality of these two values actually guaranteed by the hardware?

max_pf comes from the k_pf_mask register via nbl_res_init_pf_num(), while eth_num comes from NBL_FW_BOARD_DW3 port_num via nbl_hw_get_board_info(). The two quantities are reported independently by firmware, and the only statement that they must match is this comment.

The consequence is a probe failure: nbl_probe() -> nbl_core_init() -> nbl_res_init_leonis() -> nbl_res_start() -> nbl_res_ctrl_dev_setup_eth_info() returns -EINVAL, and nbl_core_init() turns that into ERR_PTR(ret), so the control PF does not bind at all.

Would it make sense to document this firmware contract in nbl_def_hw.h next to get_host_pf_mask/get_board_info, and to mention in the changelog that this patch introduces new fatal probe conditions?

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +5 -0
+
+	/*
+	 * Original comment said dual-port board eth_id fixed to 0,2;
+	 * Code accepts any contiguous valid bitmap bits (0/1 or 0/2 etc).
+	 * Firmware only needs to report correct count of active ports,

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +10 -0
+	 * no hard-coded fixed bit positions required.
+	 */
+	for (i = 0; i < NBL_MAX_ETHERNET; i++) {
+		if ((1 << i) & eth_bitmap) {
+			set_bit(i, eth_info->eth_bitmap);
+			eth_info->eth_id[eth_num] = i;
+			eth_info->logic_eth_id[i] = eth_num;
+			eth_num++;
+		}
+	}

[Severity: Low]
This isn't a bug, but the word "contiguous" in the comment does not match the loop, and the example given (0/2) is not contiguous either.

The loop imposes no contiguity rule: any subset of bits 0..3 whose population count equals board_info.eth_num (and equals max_pf) is accepted, so eth_bitmap = 0b1010 is mapped to PF0/PF1 as well.

Should the word be dropped, or should the bitmap actually be checked for contiguity?

[ ... ]

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

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +8 -0
+	res_mgt->resource_info->sriov_info = sriov_info;
+	/*
+	 * common->hw_bus supplies bus number for channel mailbox QINFO mapping.
+	 * Execution order guarantee: this assignment runs before
+	 * cfg_chan_qinfo_map_table() in nbl_dev_start(), only executed
+	 * on control PF path.
+	 */
+	common->hw_bus = hw_bus;

[Severity: Low]
Where is nbl_dev_start()? It does not exist at this commit, and later in the series cfg_chan_qinfo_map_table() is reached from nbl_dev_setup_ctrl_dev() via nbl_dev_setup_chan_qinfo():

nbl_dev_setup_ctrl_dev()
nbl_dev_setup_chan_qinfo(dev_mgt, NBL_CHAN_TYPE_MAILBOX)
cfg_chan_qinfo_map_table()

so the function named in the ordering comment is wrong even at the end of the series. Could the comment name the actual caller?

[ ... ]

Quoted 30 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +30 -0
+static int nbl_res_init_pf_num(struct nbl_resource_mgt *res_mgt)
+{
+	struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;
+	u32 exp_contiguous_mask = 0;
+	u32 pf_mask = 0;
+	u32 pf_num = 0;
+	int i;
+
+	hw_ops->get_host_pf_mask(res_mgt->hw_ops_tbl->priv, &pf_mask);
+
+	/*
+	 * k_pf_mask register rule:
+	 * bit N == 0  -> PF#N enabled; bit N == 1 -> PF#N masked out.
+	 * Hardware constraint: bit0 is reserved, PF0 cannot be masked.
+	 * All-zero pf_mask means all PF0~PF7 are enabled.
+	 *
+	 * Product firmware constraint: only 3 valid configurations supported:
+	 * 1 PF  (PF0 only): pf_num = 1, mask = 0xfe
+	 * 2 PFs (PF0,PF1):  pf_num = 2, mask = 0xfc
+	 * 4 PFs (PF0~PF3): pf_num = 4, mask = 0xf0
+	 * No other PF count or sparse/non-contiguous PF layout is allowed.
+	 */
+	for (i = 0; i < NBL_MAX_PF; i++) {
+		if (!(pf_mask & (1 << i)))
+			pf_num++;
+	}
+
+	/*
+	 * Sanity check: enabled PFs must be contiguous starting from PF0.
+	 * Current resource framework uses relative PF id, sparse PF layout

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +10 -0
+	 * will cause mismatch between resource layer and hardware func_id.
+	 */
+	for (i = 0; i < pf_num; i++)
+		exp_contiguous_mask |= BIT(i);
+	if ((pf_mask & exp_contiguous_mask) != 0) {
+		dev_err(res_mgt->common->dev,
+			"pf_mask 0x%08x: non-contiguous enabled PF, unsupported\n",
+			pf_mask);
+		return -EINVAL;
+	}

[Severity: Medium]
Does this treatment of bit0 agree with the ops documentation?

nbl_def_hw.h says of the same register:

* PF0 cannot be masked, bit0 is reserved and has no hardware effect.
* All-zero mask indicates all supported PFs are present and enabled.

but here bit0 is counted as a normal PF enable bit, and the contiguity test then requires it to be clear: exp_contiguous_mask always contains BIT(0) for any accepted pf_num >= 1, so a pf_mask with bit0 set fails.

Two examples: mask 0xff (PF0 only, with the documented-as-reserved bit0 also set) gives pf_num == 0, and mask 0xfd gives pf_num == 1 with bit0 set and trips the contiguity check. Both end in -EINVAL and an aborted probe.

Should nbl_res_init_pf_num() ignore bit0, or should the header comment be corrected to say bit0 is a real enable bit?

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

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +8 -0
+
+	/* Only allow product-specified PF count: 1 / 2 / 4 */
+	if (pf_num != 1 && pf_num != 2 && pf_num != 4) {
+		dev_err(res_mgt->common->dev,
+			"Invalid pf_num=%u (mask=0x%08x), only 1/2/4 PFs supported\n",
+			pf_num, pf_mask);
+		return -EINVAL;
+	}

[Severity: Medium]
What happens on a board where the k_pf_mask register still reads its reset value of zero? nbl_def_hw.h describes an all-zero mask as "all supported PFs are present and enabled", which yields pf_num == 8 here and is then rejected with -EINVAL, failing probe.

Is the all-zero case expected to be rejected, and if so should the header comment say so?

[ ... ]

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +0 -0
index 4fc987c0e56d..61dd97c779ef 100644
@@ -39,6 +39,16 @@ enum nbl_chan_state {
 	NBL_CHAN_STATE_NBITS
 };
 

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h enum nbl_chan_state { · line 51

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +10 -0
+struct nbl_board_port_info {
+	u8 eth_num;
+	u8 eth_speed;
+	u8 p4_version;
+	u8 rsv[5];
+};
+
+static_assert(sizeof(struct nbl_board_port_info) == 8,
+	      "nbl_board_port_info size must be 8 bytes");
+

[Severity: Low]
Should this header include linux/build_bug.h? static_assert is defined there, while the only include in nbl_def_channel.h is linux/types.h.

It builds today because every current translation unit pulls in linux/device.h or linux/pci.h before the nbl headers, but nbl_hw_reg.h already includes nbl_def_channel.h before linux/pci.h arrives via nbl_core.h, so a future .c or .h that includes nbl_def_channel.h first would fail with an implicit declaration of static_assert.

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h struct nbl_hw_ops { · line 38

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +1 -0
index 587ac0c58c24..ee53f9e10a8e 100644
@@ -34,9 +35,13 @@ struct nbl_hw_ops {
 	 * or other PF counts are unsupported by driver resource management.
 	 */
 	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);
+	void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt, u8 *bus);

[Severity: Low]
This isn't a bug, but the kernel-doc block just above get_host_pf_mask documents "@priv: hw ops private context" while the declared first parameter is struct nbl_hw_mgt *hw_mgt, so scripts/kernel-doc -Wall reports an undescribed parameter hw_mgt plus an excess @priv description.

Since this patch extends the same ops structure and its new resource-layer consumer relies on that comment block for the pf_mask contract, could the parameter name be fixed here?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, · line 51

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +4 -0
index b7c80ea54c8d..1aafed2d46d7 100644
@@ -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;

[Severity: Medium]
This is the point where the new firmware topology validations become probe
failures: any -EINVAL from nbl_res_init_pf_num() or nbl_res_ctrl_dev_setup_eth_info() propagates here and nbl_core_init() returns ERR_PTR(ret), so nbl_probe() reports "Nbl adapter init fail" and the device does not bind.

Could the changelog mention that this patch alone can turn a previously successful probe into -EINVAL depending on register content?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#9 lore raw

PATCH v26 5/10 net/nebula-matrix: add intr resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Introduce nbl_interrupt module to manage driver-wide global MSI-X vector index space, and extend hw_ops with hardware callbacks to program vendor-specific internal MSI-X mapping registers, populate MSI-X metadata, and bind interrupt vectors to PF mailbox channels.
Core interfaces:
1. cfg_msix_map
Allocates global MSI-X indices from independent network/other interrupt bitmaps (intr_net_bmap, intr_other_bmap). All coherent DMA buffers for new configuration are allocated upfront; old hardware state is torn down only after new allocation succeeds to avoid interrupt loss. Writes MSI-X table DMA address and PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP. Physical PCI MSI-X vector allocation lives in device layer via nbl_dev_init_interrupt_scheme().
2. destroy_msix_map
Recycle global MSI-X vectors, clear hardware MSI-X mappings, release coherent DMA memory and interrupt descriptor array. A bounded sleep is inserted prior to DMA deallocation to prevent IOMMU faults from lingering hardware DMA access after MMIO disables the mapping. Two-stage teardown avoids torn hardware read states by retaining valid DMA addresses before clearing hardware valid bits.
3. set_mailbox_irq
Toggle mailbox MSI-X routing for a specific PF by updating NBL_MAILBOX_QINFO_MAP_REG_ARR with the assigned global vector ID. All register RMW operations are serialized by per-device reg_lock to prevent concurrent hardware register corruption.
4. cfg_msix_info
Program PADPT_HOST_MSIX_INFO & PCOMPLETER_HOST_MSIX_FID_TABLE to record each vector's PF BDF and MSI-X enable mask attributes, with strict programming/teardown order to avoid inconsistent hardware state. This module solely manages the chip's internal MSI-X routing table and software vector allocator. It never calls kernel PCI MSI-X allocation APIs (pci_alloc_irq_vectors() etc.); physical PCI MSI-X vector allocation is handled separately by the device layer.
The interrupt manager is instantiated via nbl_intr_mgt_start() during resource initialization and attached to the resource management context. Locking note: exclusive serialization of cfg_msix_map / destroy_msix_map / set_mailbox_irq is guaranteed by the dispatch-layer mutex introduced in a subsequent RPC framework patch. Callers must hold the corresponding lock.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 152 ++++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  42 ++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  11 +-
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |  11 +
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  | 402 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |  21 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   |  30 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  36 ++
 .../nbl/nbl_include/nbl_def_hw.h              |  10 +
 .../nbl/nbl_include/nbl_def_resource.h        |   6 +
 .../nbl/nbl_include/nbl_include.h             |   1 +
 13 files changed, 721 insertions(+), 3 deletions(-)
 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 3dab9519a277..5aec8e44f5d7 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 +150 -2

185 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 +10 -1
index a719cc8fbf8a..4b6a5bc8715a 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,
+	.cfg_msix_map = nbl_res_intr_cfg_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 *
@@ -41,7 +44,9 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)
 	res_ops_tbl = devm_kzalloc(dev, sizeof(*res_ops_tbl), GFP_KERNEL);
 	if (!res_ops_tbl)
 		return ERR_PTR(-ENOMEM);
-	if (!res_ops.get_vsi_id || !res_ops.get_eth_id)
+	if (!res_ops.get_vsi_id || !res_ops.get_eth_id ||
+	    !res_ops.cfg_msix_map || !res_ops.destroy_msix_map ||
+	    !res_ops.set_mailbox_irq)
 		return ERR_PTR(-EINVAL);
 	res_ops_tbl->ops = &res_ops;
 	res_ops_tbl->priv = res_mgt;
@@ -287,6 +292,10 @@ 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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index b9355262c00d..6eb4dc9e695a 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_hw_reg.h +11 -0
index 35604bdff2ae..6b4e513e6c48 100644
@@ -58,6 +58,17 @@ static inline void nbl_mbx_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
 	writel(value, hw_mgt->mailbox_bar_hw_addr + reg);
 }
 
+/*
+ * Only call this when has_ctrl=true, which maps enough space
+ * (bar_len - 8192) to cover NBL_HW_DUMMY_REG (0x1300904).
+ * The flow/design guarantees this is only called in the
+ * has_ctrl path.
+ */
+static inline void nbl_flush_writes(struct nbl_hw_mgt *hw_mgt)
+{
+	nbl_hw_rd32(hw_mgt, NBL_HW_DUMMY_REG);
+}
+
 static inline u32 nbl_mbx_rd32(struct nbl_hw_mgt *hw_mgt, u64 reg)
 {
 	return readl(hw_mgt->mailbox_bar_hw_addr + reg);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +402 -0

402 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..9f66f5e19c98
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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_cfg_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 en_msix);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +30 -0
index 6fa0e0d550f4..48d727718f0b 100644
@@ -68,6 +68,36 @@ int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id)
 	return -ENOENT;
 }
 
+int nbl_res_func_id_to_bdf(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			   u8 *bus, u8 *dev, u8 *function)
+{
+	struct nbl_common_info *common = res_mgt->common;
+	struct nbl_sriov_info *sriov_info;
+	int pfid = func_id;
+	u8 pf_bus, devfn;
+	u32 rel_pf_id;
+	int ret;
+
+	if (!common->has_ctrl || !bus || !dev || !function)
+		return -EINVAL;
+	ret = nbl_common_func_id_to_rel_pf_id(common, pfid, &rel_pf_id);
+	if (ret)
+		return ret;
+	if (rel_pf_id >= res_mgt->resource_info->max_pf) {
+		dev_err(common->dev, "PF ID %u exceeds maximum supported PF count %u\n",
+			pfid, res_mgt->resource_info->max_pf);
+		return -ERANGE;
+	}
+	sriov_info = res_mgt->resource_info->sriov_info + rel_pf_id;
+	pf_bus = PCI_BUS_NUM(sriov_info->bdf);
+	devfn = sriov_info->bdf & 0xff;
+	*bus = pf_bus;
+	*dev = PCI_SLOT(devfn);
+	*function = PCI_FUNC(devfn);
+
+	return 0;
+}
+
 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)
 {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +36 -0
index 226903be080f..e2d0f04fdfb7 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(intr_net_bmap, NBL_MAX_NET_INTERRUPT);
+	DECLARE_BITMAP(intr_other_bmap, NBL_MAX_OTHER_INTERRUPT);
+	struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC];
+};
+
 /* --------- INFO ---------- */
 struct nbl_sriov_info {
 	unsigned int bdf;
@@ -60,13 +92,17 @@ struct nbl_resource_mgt {
 	struct nbl_resource_info *resource_info;
 	struct nbl_channel_ops_tbl *chan_ops_tbl;
 	struct nbl_hw_ops_tbl *hw_ops_tbl;
+	struct nbl_interrupt_mgt *intr_mgt;
 };
 
 int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id);
 int nbl_res_func_id_to_vsi_id(struct nbl_resource_mgt *res_mgt, u16 func_id,
 			      u16 type, u16 *vsi_id);
+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(struct nbl_resource_mgt *res_mgt,
 					   u16 src_type,
 					   enum nbl_vsi_serv_type *dst_type);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10 -0
index ee53f9e10a8e..fd86eef4a0d3 100644
@@ -12,6 +12,14 @@ struct nbl_board_port_info;
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	void (*cfg_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 (*cfg_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,
@@ -39,6 +47,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 en_msix, u16 global_vec_id);
 	void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
 	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 7136b282fb80..e718ea41a816 100644
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;
 struct nbl_adapter;
 
 struct nbl_resource_ops {
+	int (*cfg_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 en_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,
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +1 -0
index 59e44feab44f..2c959832c32f 100644
@@ -13,6 +13,7 @@
 #define NBL_MAX_PF					8
 #define NBL_NEXT_ID(id, max) (((id) + 1) % ((max) + 1))
 
+#define NBL_MAX_FUNC					520
 #define NBL_MAX_ETHERNET				4
 
 enum {
Signature · 1 line
2.47.3
#10 lore raw

Re: [v26,net-next,05/10] net/nebula-matrix: add intr resource implementation

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:

Critical: 0 · High: 2 · Medium: 1 · Low: 5

- [High] Teardown asymmetry in the interrupt manager:
nbl_intr_mgt_start() has no counterpart, and nothing ever walks…
- [High] nbl_res_func_id_to_bdf explicitly treats all func_ids as PF IDs, causing MSI-X configuration to fail for all VFs.
- [Medium] nbl_res_intr_destroy_msix_map() releases the coherent MSI-X map table with dmam_free_coherent() after only a fixed…
- [Low] The kernel-doc of nbl_res_intr_set_mailbox_irq() states "Return:
0 on success, negative errno on parameter check or hw failure", but…
- [Low] (Retained for policy reasons; my verification indicates this is NOT a defect.) Concern: nbl_res_intr_destroy_msix_map() recycles the…
- [Low] (Retained for policy reasons; my verification indicates this is NOT a defect.) Concern: the commit message credits…
- [Low] (Retained for policy reasons; my verification indicates this is resolved later in the series.) Concern: nbl_res_intr_cfg_msix_map()…
- [Low] (Retained for policy reasons; my verification indicates this is resolved later in the series.) Concern: per-function interrupt…

--

net/nebula-matrix: add intr resource implementation

This adds the nbl_interrupt module, which owns the driver-wide global MSI-X index space (intr_net_bmap / intr_other_bmap) and programs the chip-internal MSI-X mapping registers. It exposes cfg_msix_map, destroy_msix_map and set_mailbox_irq through the resource ops, and instantiates the manager from nbl_res_start() via nbl_intr_mgt_start().

A few questions below, mostly around teardown.

Physical PCI MSI-X vector allocation lives in device layer via nbl_dev_init_interrupt_scheme().

[Severity: Low]
This isn't a bug, but nbl_dev_init_interrupt_scheme() does not exist in the tree at this commit, and neither does any caller of cfg_msix_map, destroy_msix_map or set_mailbox_irq. Both arrive later in the series ("dispatch: implement channel RPC framework and serialize hardware ops" and "add common dev start/stop operation").

Could the message say the symbol is added later in the series, so a reader bisecting to this commit does not go looking for it?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0 -0
new file mode 100644
index 000000000000..52872264e906
@@ -0,0 +1,402 @@

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +3 -0
+int nbl_res_intr_destroy_msix_map(struct nbl_resource_mgt *res_mgt,
+				  u16 func_id)
+{

[ ... ]

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

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +8 -0
+	/* Step 1: mask each MSIX vector in hardware first */
+	for (i = 0; i < intr_num; i++) {
+		hw_ops->cfg_msix_info(res_mgt->hw_ops_tbl->priv,
+				      func_id, false, interrupts[i],
+				      0, 0, 0, false);
+	}
+
+	nbl_intr_release_bitmap(res_mgt, interrupts, intr_num);

[Severity: Low]
This isn't a bug in the final series, but the resource layer here looks self-inconsistent. nbl_res_intr_destroy_msix_map() returns the global vector ids to intr_net_bmap / intr_other_bmap and clears PADPT_HOST_MSIX_INFO, PCOMPLETER_HOST_MSIX_FID_TABLE and FUNCTION_MSIX_MAP, but it never clears the MSIX_IDX / MSIX_IDX_VALID fields in NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id) that nbl_hw_set_mailbox_irq() programmed.

Afterwards the repair path is closed too, because nbl_res_intr_set_mailbox_irq() rejects the disable case once the array is gone:

	if (!intr_mgt->func_intr_res[func_id].interrupts) {
		dev_err(dev, "func %u MSIX map not configured\n", func_id);
		return -ENODEV;
	}

even though nbl_hw_set_mailbox_irq() ignores global_vec_id when en_msix is false.

I checked the end of the series and nothing reaches that state:
nbl_dev_stop() calls nbl_dev_disable_mailbox_irq() before nbl_dev_destroy_msix_map(), nbl_dev_start() configures the map before enabling the mailbox irq, and cfg_msix_map() has a single caller. So the ordering happens to be correct everywhere.

The ordering requirement is only prose though, and the RPC handler nbl_disp_chan_destroy_msix_map_resp() accepts a destroy request from a peer without requiring a prior set_mailbox_irq(false). Would it be worth having destroy_msix_map() clear the mailbox route it owns, and letting the disable path succeed when no map is configured?

Quoted 25 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +25 -0
+
+	/*
+	 * Stage 1 tear down: retain valid DMA address, ONLY clear VALID bit
+	 * avoid hardware torn read (VALID=1 & dma_addr=0)
+	 */
+	hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
+			     false, live_dma, 0, 0, 0);
+	hw_ops->flush_write(res_mgt->hw_ops_tbl->priv);
+
+	/*
+	 * Hardware provides no idle status register for MSIX map DMA engine.
+	 * Use bounded sleep to mitigate race between posted MMIO disable writes
+	 * and ongoing in-flight table read DMA access.
+	 * After sleep, hardware no longer performs DMA access to MSIX table.
+	 */
+	usleep_range(NBL_MSIX_DMA_SYNC_MIN_US, NBL_MSIX_DMA_SYNC_MAX_US);
+
+	/*
+	 * Stage 2: hardware has quiesced MSIX table DMA access,
+	 * fully zero MSIX map entry safely now
+	 */
+	hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
+			     false, 0, 0, 0, 0);
+	hw_ops->flush_write(res_mgt->hw_ops_tbl->priv);
+

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10 -0
+	/*
+	 * Now safe to release old MSIX DMA memory, prevents devres accumulation
+	 * leak Since hardware DMA has quiesced after sleep, no IOMMU fault risk
+	 * anymore.
+	 */
+	if (msix_map_table->base_addr) {
+		dmam_free_coherent(dev, msix_map_table->size,
+				   msix_map_table->base_addr,
+				   msix_map_table->dma);
+	}

[Severity: Medium]
Can the 100-120 us sleep be relied on here? The comment states "After sleep, hardware no longer performs DMA access to MSIX table", but as the changelog itself says there is no idle status register for this engine, so there is no device-observable handshake backing that claim.

The sequence is:

cfg_msix_map(valid=false, live_dma) /* posted MMIO */
flush_write()
usleep_range(100, 120)
dmam_free_coherent(...) /* IOVA torn down */

A table fetch already issued before the VALID clear was observed can complete after dmam_free_coherent() has unmapped the buffer. PCIe bounds read completion only by the completion timeout range (tens of microseconds up to tens of milliseconds), not by 100 us, and a switch, congested link or an IOMMU in the path can push past it.

The outcome would be exactly what this code is trying to avoid: an IOMMU translation fault, or a fetch of memory already handed to another owner followed by an MSI-X raised with a garbage global index.

Is there any status bit, or a read-back of a register the engine updates, that could be polled instead? Failing that, would retaining the buffer (freeing it only at detach, or after a much longer bound) be safer than a fixed sleep?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +6 -0
+
+	/* Release runtime allocated interrupt vector buffer */
+	kfree(intr_mgt->func_intr_res[func_id].interrupts);
+	intr_mgt->func_intr_res[func_id].interrupts = NULL;
+	intr_mgt->func_intr_res[func_id].num_interrupts = 0;
+	intr_mgt->func_intr_res[func_id].num_net_interrupts = 0;

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +5 -0
+int nbl_res_intr_cfg_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_hw/nbl_interrupt.c line 248

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12 -0
+	/* Allocate net interrupt vectors */
+	for (i = 0; i < num_net_msix; i++) {
+		intr_index = find_first_zero_bit(intr_mgt->intr_net_bmap,
+						 NBL_MAX_NET_INTERRUPT);
+		if (intr_index == NBL_MAX_NET_INTERRUPT) {
+			dev_err(dev, "No free net interrupt vectors left\n");
+			ret = -EAGAIN;
+			goto release_vecs;
+		}
+		tmp_interrupts[i] = intr_index + NBL_NET_INTR_BASE;
+		set_bit(intr_index, intr_mgt->intr_net_bmap);
+	}

[Severity: Low]
The find_first_zero_bit() plus separate set_bit() on the driver-wide intr_net_bmap / intr_other_bmap is not atomic, so at this commit two concurrent calls for different func_ids could hand the same global index to two functions.

I checked the rest of the series and this is covered: the later dispatch patch wraps every entry point (nbl_disp_cfg_msix_map(), nbl_disp_destroy_msix_map(), nbl_disp_set_mailbox_irq() and the three matching nbl_disp_chan_*_resp() handlers) in disp_mgt->ops_mutex_lock, and there is one disp_mgt per adapter, so the allocations end up serialized.

Since the requirement lives only in the comment, would a lockdep_assert_held() on that mutex, or a double-underscore name for these helpers, make the contract checkable?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +6 -0
+
+	/* Allocate other interrupt vectors */
+	for (; i < requested; i++) {
+		intr_index =
+			find_first_zero_bit(intr_mgt->intr_other_bmap,
+					    NBL_MAX_OTHER_INTERRUPT);

[ ... ]

Quoted 4 lines

+/**
+ * nbl_res_intr_set_mailbox_irq - bind mailbox IRQ to specified vector
+ * @res_mgt: resource management instance
+ * @func_id: target function identifier

Quoted 8 lines

+ * @vector_id: index inside local interrupt array
+ * @en_msix: enable/disable mailbox interrupt
+ *
+ * Caller note: this function has no internal locking. Serialization
+ * must be guaranteed at upper dispatch layer.
+ *
+ * Return: 0 on success, negative errno on parameter check or hw failure
+ */

[Severity: Low]
Can this function ever report a hardware failure? The only hardware call it makes is hw_ops->set_mailbox_irq(), which is declared void in struct nbl_hw_ops (nbl_def_hw.h), and its only implementation nbl_hw_set_mailbox_irq() returns nothing:

	void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
				bool en_msix, u16 global_vec_id);

So every non-zero return comes from the three parameter and state checks. Should the "or hw failure" wording be dropped, or should the hw op return a status?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4 -0
+int nbl_res_intr_set_mailbox_irq(struct nbl_resource_mgt *res_mgt,
+				 u16 func_id, u16 vector_id,
+				 bool en_msix)
+{

[ ... ]

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

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12 -0
+	if (!intr_mgt->func_intr_res[func_id].interrupts) {
+		dev_err(dev, "func %u MSIX map not configured\n", func_id);
+		return -ENODEV;
+	}
+	if (vector_id >= intr_mgt->func_intr_res[func_id].num_interrupts) {
+		dev_err(dev, "vector_id %u out of range (max %u)\n",
+			vector_id,
+			intr_mgt->func_intr_res[func_id].num_interrupts - 1);
+		return -EINVAL;
+	}
+
+	global_vec_id = intr_mgt->func_intr_res[func_id].interrupts[vector_id];

[Severity: Low]
Same observation for the per-function state. At this commit func_intr_res[].interrupts is validated and then dereferenced here while nbl_res_intr_destroy_msix_map() may kfree() it, and two concurrent destroys would snapshot the same interrupts and msix_map_table->base_addr pointers and free them twice.

The later dispatch patch closes both by taking the same per-adapter ops_mutex_lock around all six entry points into these three functions, and nbl_intr_mgt_start() is the only other toucher and runs single-threaded during probe, so no in-tree path hits either case.

The resource layer still relies on prose only ("Serialization must be guaranteed at upper dispatch layer") with nothing asserting it.

[ ... ]

Quoted 18 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +18 -0
+static struct nbl_interrupt_mgt *nbl_intr_setup_mgt(struct device *dev)
+{
+	struct nbl_interrupt_mgt *intr_mgt;
+
+	intr_mgt = devm_kzalloc(dev, sizeof(*intr_mgt), GFP_KERNEL);
+	if (!intr_mgt)
+		return ERR_PTR(-ENOMEM);
+
+	bitmap_zero(intr_mgt->intr_net_bmap, NBL_MAX_NET_INTERRUPT);
+	bitmap_zero(intr_mgt->intr_other_bmap, NBL_MAX_OTHER_INTERRUPT);
+
+	return intr_mgt;
+}
+
+int nbl_intr_mgt_start(struct nbl_resource_mgt *res_mgt)
+{
+	struct device *dev = res_mgt->common->dev;
+	struct nbl_interrupt_mgt *intr_mgt;

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10 -0
+	int ret;
+
+	intr_mgt = nbl_intr_setup_mgt(dev);
+	if (IS_ERR(intr_mgt)) {
+		ret = PTR_ERR(intr_mgt);
+		return ret;
+	}
+	res_mgt->intr_mgt = intr_mgt;
+	return 0;
+}

[Severity: High]
This helper treats func_id as a PF id throughout, but the callers hand it the whole function id space. nbl_res_intr_cfg_msix_map(), nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq() all bound func_id by NBL_MAX_FUNC, which this patch defines as 520, and intr_mgt->func_intr_res[] is sized the same way, so the interrupt manager is clearly meant to track VFs as well as the 8 PFs.

For any func_id past the PF range nbl_common_func_id_to_rel_pf_id() subtracts common->mgt_pf and the resulting rel_pf_id then trips this check against resource_info->max_pf, so nbl_res_func_id_to_bdf() returns -ERANGE and nbl_res_intr_cfg_msix_map() aborts before it allocates anything. A VF whose map is programmed on its behalf by the ctrl PF (the CONFIGURE_MSIX_MAP RPC handler added later in the series passes the peer's src_id straight through as func_id) can therefore never get an MSI-X mapping, and the failure is silent apart from a dev_err that reports the value as "PF ID".

The lookup itself has no VF support either: sriov_info[rel_pf_id].bdf only records the PF bdf, and there is nothing here that applies the SR-IOV VF offset/stride to derive a VF's bus/dev/func.

Is VF handling intended to land in a later patch? If so, would it be clearer to reject the out-of-PF-range func_id in nbl_res_intr_cfg_msix_map() with an explicit "VF not supported yet" path, rather than having it surface as -ERANGE from a BDF lookup that reports it as a bad PF id? Or should nbl_res_func_id_to_bdf() learn to map a VF func_id to its owning PF and compute the VF bdf from the capability offset and stride?

[Severity: High]
Does nbl_intr_mgt_start() need a counterpart? Nothing in the series walks intr_mgt->func_intr_res[] at detach, and nbl_res_remove_leonis() is still an empty function whose comment says:

	/*
	 * No resource release here because all memory uses devm managed
	 * allocation
	 */

That comment no longer holds after this patch, since the per-function vector array is kcalloc()'d in nbl_res_intr_cfg_msix_map() and only freed in nbl_res_intr_destroy_msix_map().

The part I am unsure about is the remote PFs. On a 2 or 4 PF card, PF1..PF3 configure their maps over the mailbox RPC, so nbl_disp_chan_cfg_msix_map_resp() -> nbl_res_intr_cfg_msix_map(res_mgt, src_id) allocates both the kcalloc()'d interrupts array and a dmam_alloc_coherent() MSI-X table on the ctrl PF's device, recorded in the ctrl PF's func_intr_res[1..3].

Later in the series nbl_dev_stop() only destroys its own function's map:

	ret = nbl_dev_destroy_msix_map(dev_mgt);

so when the ctrl PF detaches first (plain rmmod nbl detaches in bind order, and unbinding PF0 alone through sysfs is a normal admin action) the path is:

nbl_core_stop() /* destroys only func_id == common->mgt_pf */
nbl_core_remove()
nbl_res_remove_leonis() /* empty */
devres release

Two things follow from that. Does this leak func_intr_res[1..3].interrupts, since kfree() on those arrays only ever runs from nbl_res_intr_destroy_msix_map()?

And can devres release the remote PFs' coherent MSI-X tables while NBL_PCOMPLETER_FUNCTION_MSIX_MAP(func), NBL_PADPT_HOST_MSIX_INFO and NBL_PCOMPLETER_HOST_MSIX_FID_TABLE for those functions still hold VALID=1 and the live bus address? That skips the two-stage clear plus quiesce sleep that destroy_msix_map() documents as required before freeing the table. The remaining PFs cannot repair it later either, because their nbl_dev_stop() RPCs go to a mailbox that is already gone.

Would an nbl_intr_mgt_stop() in nbl_res_remove_leonis(), iterating func_intr_res[] and calling nbl_res_intr_destroy_msix_map() for each configured func_id, cover this?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +0 -0
index a719cc8fbf8a..4b6a5bc8715a 100644

[ ... ]

Quoted 16 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -0
@@ -287,6 +292,10 @@ 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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0 -0
index ee53f9e10a8e..fd86eef4a0d3 100644

[ ... ]

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +2 -0
@@ -39,6 +47,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 en_msix, u16 global_vec_id);
 	void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
 	void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,
 			       struct nbl_board_port_info *board);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#11 lore raw

PATCH v26 6/10 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, plus the driver_status hardware flag consumed by firmware.

This patch introduces hw_ops.init_module/deinit_module and corresponding resource_ops entry points. The actual invocation path for these callbacks lands in a subsequent control device initialization patch; only the ops registration is added here.

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_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()

Introduce firmware quirk interface at mailbox offset NBL_LEONIS_QUIRKS_OFFSET. Read value ~0u indicates no active quirks. Currently defined quirk:
NBL_QUIRK_UVN_PREFETCH_ALIGN (BIT(1)), BIT(0) is reserved for future use.

Chip deinit design relies on firmware cleanup: only driver_status flag is cleared and flushed; FW releases all chip hardware state automatically. The caller guarantees init_module/deinit_module only runs on control PF, so no extra has_ctrl check is placed inside these entry points.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |  23 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |  12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 548 +++++++++++++++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  | 226 ++++++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |   5 +-
 .../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             |  21 +
 10 files changed, 841 insertions(+), 2 deletions(-)
 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 5aec8e44f5d7..be314b909d66 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 +23 -0
new file mode 100644
index 000000000000..e1ba7b7e36ca
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 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;
+
+	return hw_ops->init_module(p, eth_speed, eth_num);
+}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h new file +12 -0
new file mode 100644
index 000000000000..d14093ba916c
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_CHIP_H_
+#define _NBL_CHIP_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 +547 -1

566 lines not on this page · raw message

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

248 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -1
index 4b6a5bc8715a..5080c25dc554 100644
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = {
 	.cfg_msix_map = nbl_res_intr_cfg_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 *
@@ -46,7 +48,8 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)
 		return ERR_PTR(-ENOMEM);
 	if (!res_ops.get_vsi_id || !res_ops.get_eth_id ||
 	    !res_ops.cfg_msix_map || !res_ops.destroy_msix_map ||
-	    !res_ops.set_mailbox_irq)
+	    !res_ops.set_mailbox_irq || !res_ops.init_module ||
+	    !res_ops.deinit_module)
 		return ERR_PTR(-EINVAL);
 	res_ops_tbl->ops = &res_ops;
 	res_ops_tbl->priv = res_mgt;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index 6eb4dc9e695a..f1cb0f23240b 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 fd86eef4a0d3..e1623b5702d6 100644
@@ -12,6 +12,9 @@ struct nbl_board_port_info;
 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 (*cfg_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 e718ea41a816..8dc64e806c1e 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 (*cfg_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 +21 -0
index 2c959832c32f..ebf85702cef6 100644
@@ -30,4 +30,25 @@ 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,
+	NBL_FW_PORT_SPEED_50G,
+	NBL_FW_PORT_SPEED_100G,
+};
+
+/*
+ * Firmware quirk word @ NBL_LEONIS_QUIRKS_OFFSET (0x140)
+ * Sentinel value: ~0U (0xFFFFFFFF) = firmware reports no active quirks
+ * BIT(0): NBL_QUIRKS_NO_TOE – ABI defined, driver implementation pending
+ * BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch
+ * selection
+ */
+#define NBL_QUIRKS_NO_TOE		BIT(0)
+#define NBL_QUIRK_UVN_PREFETCH_ALIGN	BIT(1)
+
 #endif
Signature · 1 line
2.47.3
#12 lore raw

Re: [v26,net-next,06/10] net/nebula-matrix: add chip-wide hardware init/deinit implementation

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 2 · Low: 7

- [Medium] nbl_dp_init() programs DPED, UPED, shaping and DSCH into hardware before nbl_ustore_init() validates the firmware-reported…
- [Medium] Within nbl_uvn_init() the driver read-modify-writes NBL_UVN_DIF_REQ_RO_FLAG and NBL_UVN_QUEUE_ERR_MASK to preserve…
- [Low] hw_ops->init_module / hw_ops->deinit_module (and the resource wrappers nbl_res_chip_init_module / nbl_res_chip_deinit_module)…
- [Low] New firmware quirk ABI is described inconsistently.
- [Low] nbl_hw_deinit_module() clears the driver_status bit and issues a dummy-register read, with no acknowledgement or completion polling for…
- [Low] New register definitions mix conventions and pollute the global macro namespace: NBL_SHAPING_DPORT_ADDR 0x504700 /…
- [Low] nbl_uvn_init() is declared static void yet its last statement is `return nbl_hw_wr_regs_lock(hw_mgt, NBL_UVN_DESC_PREFETCH_INIT,…
- [Low] The shaping register block documents two incompatible units for a CIR value of 1: nbl_hw_leonis.h:264 says "cir 1, bandwidth 1kB/s in…
- [Low] The only documentation of the UQM que_type register added by this patch contradicts itself: `/* bit 0: bp mode , bit1: drop mode, resv…

--

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

This adds the Leonis chip-wide init/deinit path, programming the DP sub-modules (dped, uped, dsch, ustore, dstore, dvn, uvn, uqm), per-port shaping and host padpt flow control, plus the driver_status flag consumed by firmware. It also registers hw_ops.init_module/deinit_module and the matching resource_ops entry points, and introduces a firmware quirk word read from the mailbox. A few questions below.

Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +13 -0
new file mode 100644
index 000000000000..e1ba7b7e36ca
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 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);
+}

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c line 23

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +10 -0
+
+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;
+
+	return hw_ops->init_module(p, eth_speed, eth_num);
+}

[Severity: Low]
This isn't a bug, but would it be worth adding the has_ctrl check here for consistency with the sibling resource ops?

Every other resource op added so far starts with:

	if (!common->has_ctrl)
		return -EINVAL;

(see nbl_res_intr_cfg_msix_map() and friends in nbl_interrupt.c and the helpers in nbl_resource.c), while nbl_res_chip_init_module() and nbl_res_chip_deinit_module() go straight into chip-global register programming.

The registers touched by that path are well outside the mapping a non-control function gets, for example NBL_DRIVER_STATUS_REG 0x1300444 and the dummy register used by nbl_flush_writes() at 0x1300904, while nbl_hw_init_leonis() only ioremaps NBL_REG_NET_ONLY_LEN when has_ctrl is not set, and nbl_hw_wr32()/nbl_hw_rd32() do not bound-check against hw_size.

I checked and this is not reachable: nbl_dev_init() only calls nbl_dev_setup_ctrl_dev() under if (common->has_ctrl), and disp_ops->init_module/deinit_module are only assigned for NBL_DISP_CTRL_LVL_MGT, which is only set when common->has_ctrl. So this is purely a defense-in-depth remark, matching what the commit message already says about the caller guarantee.

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2 -0
index fd6bc992fa0f..7f2626db731a 100644
@@ -115,6 +115,548 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
 	*eth_map = FIELD_GET(NBL_FW_BOARD_DW6_ETH_BITMAP_MASK, data);
 }
 
+static u32 nbl_hw_get_quirks(struct nbl_hw_mgt *hw_mgt)
+{

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 129

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+	u32 quirks = 0;
+
+	nbl_hw_read_mbx_regs(hw_mgt, NBL_LEONIS_QUIRKS_OFFSET, &quirks,
+			     sizeof(u32));
+
+	if (quirks == ~0u)
+		return 0;
+
+	return quirks;
+}

[Severity: Low]
The quirk interface is described in three places and the three descriptions do not agree.

The commit message says:

NBL_QUIRK_UVN_PREFETCH_ALIGN (BIT(1)), BIT(0) is reserved for future use.

but nbl_include.h defines BIT(0) as a named quirk:

	#define NBL_QUIRKS_NO_TOE		BIT(0)
	#define NBL_QUIRK_UVN_PREFETCH_ALIGN	BIT(1)

with the comment "ABI defined, driver implementation pending". NBL_QUIRKS_NO_TOE has no user anywhere in the driver at the end of the series. Should the commit message say BIT(0) is defined but unused, or should the define be dropped until it is used?

The two prefixes also differ (NBL_QUIRKS_NO_TOE versus NBL_QUIRK_UVN_PREFETCH_ALIGN), and the explanatory comment in nbl_uvn_init() names a macro that does not exist in the tree:

* Default is sel=1, unless NBL_QUIRKS_UVN_PREFETCH_ALIGN is set,

while the code a few lines below uses NBL_QUIRK_UVN_PREFETCH_ALIGN.

One more question on the sentinel above: only ~0u is treated as "no quirks", so on firmware predating this ABI, any other stale non-zero content at mailbox offset 0x140 is taken as live quirk bits and can flip NBL_UVN_DESC_PREFETCH_INIT_SEL. Is there a version or magic word that could gate the read instead? I cannot inspect firmware images, so this part is speculative.

[ ... ]

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +12 -0
+static int nbl_shaping_eth_init(struct nbl_hw_mgt *hw_mgt, u8 eth_id, u8 speed)
+{
+	struct nbl_shaping_dvn_dport_u dvn_dport = { 0 };
+	struct nbl_shaping_dport_u dport = { 0 };
+	u32 rate, half_rate;
+	u32 depth;
+	u64 low_val, high_val;
+
+	switch (speed) {
+	case NBL_FW_PORT_SPEED_100G:
+		rate = 100000;
+		break;

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 217

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +3 -0
+	/* 2. write config words (valid=0, safe) */
+	low_val = FIELD_PREP(DPORT_CIR_MASK, rate) |
+		  FIELD_PREP(DPORT_PIR_MASK, rate) |

[Severity: Low]
This isn't a bug, but which unit do these fields actually use? The header documents two incompatible ones right above the shaping defines:

	/* cir 1, bandwidth 1kB/s in protol environment */
	/* cir 1, bandwidth 1Mb/s */

The code here writes 10000/25000/50000/100000 for 10/25/50/100 Gbit/s, which matches only the 1 Mb/s reading; under the 1 kB/s reading a 100G port would be shaped to roughly 0.8 Gbit/s. Could the stale comment be deleted or qualified?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 316

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +9 -0
+static int nbl_ustore_init(struct nbl_hw_mgt *hw_mgt, u8 eth_num)
+{
+	u32 eth_bitmap = 0;
+	u32 drop_th = 0;
+	u32 pkt_len = 0;
+	int i;
+
+	if (eth_num != 1 && eth_num != 2 && eth_num != 4)
+		return -EINVAL;

[Severity: Medium]
Is it intended that eth_num is validated only here, after several sub-modules have already been committed to the chip?

nbl_dp_init() programs DPED, UPED, shaping and DSCH before reaching this check:

	nbl_dped_init(hw_mgt);
	nbl_uped_init(hw_mgt);
	ret = nbl_shaping_init(hw_mgt, speed);
	if (ret)
		return ret;
	nbl_dsch_qid_max_init(hw_mgt);
	ret = nbl_ustore_init(hw_mgt, eth_num);
	if (ret)
		return ret;

eth_num comes straight from firmware. nbl_hw_get_board_info() does:

	board_info->eth_num = FIELD_GET(NBL_FW_BOARD_DW3_PORT_NUM_MASK, data);

and nbl_res_init_board_info() does not validate it, so a board reporting 0, 3 or 8 (or a mailbox read that returns early on its own bounds check, leaving eth_num 0) fails here with the shaping DPORT/DVN_DPORT VALID bits already set, DSCH quanta and QID_MAX applied, DPED L4 checksum enabled and the UPED profiles edited.

There is also no unwind, and nbl_hw_init_module() returns the error before nbl_hw_set_driver_status(hw_mgt, true), so the firmware cleanup the commit message relies on ("FW releases all chip hardware state automatically") is never armed for a failed init, and nbl_hw_deinit_module() only clears a bit that was never set.

Could eth_num be validated before the first register write?

[ ... ]

Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +14 -0
+static void nbl_dvn_descreq_num_cfg(struct nbl_hw_mgt *hw_mgt, u8 descreq_num)
+{
+	u8 split_ring_num = (descreq_num >> 3) & 0x1;
+	u8 ring_num = descreq_num & 0x7;
+	u32 num_cfg = 0;
+
+	num_cfg = FIELD_PREP(NBL_DVN_DESCREQ_NUM_CFG_AVRING_DESREQ_NUM_CFG_MASK,
+			     split_ring_num) |
+		  FIELD_PREP(NBL_DVN_DESCREQ_NUM_CFG_PACKED_L1_NUM_MASK,
+			     ring_num);
+
+	nbl_hw_wr_regs_lock(hw_mgt, NBL_DVN_DESCREQ_NUM_CFG, &num_cfg,
+			    sizeof(num_cfg));
+}

[ ... ]

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +7 -0
+static void nbl_uvn_init(struct nbl_hw_mgt *hw_mgt)
+{
+	u16 wr_timeout = NBL_UVN_DESC_WR_TIMEOUT_VAL;
+	u32 timeout = NBL_UVN_DESC_RD_WAIT_TICKS;
+	u32 desc_wr_timeout = 0;
+	u32 prefetch_init = 0;
+	bool ro_enabled;

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 484

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+	u32 flag = 0;
+	u32 mask = 0;
+	u32 quirks;
+
+	spin_lock(&hw_mgt->reg_lock);
+	nbl_hw_wr32(hw_mgt, NBL_UVN_DESC_RD_WAIT, timeout);
+	desc_wr_timeout =
+		FIELD_PREP(NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK, wr_timeout);
+	nbl_hw_wr_regs(hw_mgt, NBL_UVN_DESC_WR_TIMEOUT, &desc_wr_timeout,
+		       sizeof(desc_wr_timeout));

[Severity: Medium]
Does this write clear NBL_UVN_DESC_WR_TIMEOUT_MASK_MASK? The patch itself declares that bit as a live field of the same register:

	#define NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK GENMASK(14, 0)
	#define NBL_UVN_DESC_WR_TIMEOUT_MASK_MASK BIT(15)

but desc_wr_timeout starts at 0 and only NUM is filled in, so BIT(15) is written back as 0 whatever firmware programmed. A few lines below, this same function read-modify-writes NBL_UVN_DIF_REQ_RO_FLAG and NBL_UVN_QUEUE_ERR_MASK precisely to preserve the other bits, so the inconsistency is internal to the function.

The same pattern applies to two other registers in this patch:

- NBL_UVN_DESC_PREFETCH_INIT is written from scratch with only NUM[7:0] and

    SEL[16]

- NBL_DVN_DESCREQ_NUM_CFG in nbl_dvn_descreq_num_cfg() above is written with only BIT(0) and GENMASK(6, 4)

Since deinit relies entirely on firmware cleanup, whatever gets zeroed here stays zeroed for the life of the chip. Should these be read-modify-writes too? I could not find the reset defaults of those bits documented in the tree, so this is based on the field definitions the patch adds.

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +1 -0
+	ro_enabled = pcie_relaxed_ordering_enabled(hw_mgt->common->pdev);

[ ... ]

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6 -0
+	spin_unlock(&hw_mgt->reg_lock);
+	quirks = nbl_hw_get_quirks(hw_mgt);
+	/*
+	 * sel=0: use configured num; sel=1: use internal calc (max 32)
+	 * Default is sel=1, unless NBL_QUIRKS_UVN_PREFETCH_ALIGN is set,
+	 * in which case override to sel=0.

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 521

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+	 */
+	prefetch_init =
+		FIELD_PREP(NBL_UVN_DESC_PREFETCH_INIT_NUM_MASK,
+			   NBL_UVN_DESC_PREFETCH_NUM) |
+		FIELD_PREP(NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK,
+			   (quirks & NBL_QUIRK_UVN_PREFETCH_ALIGN) ? 0 : 1);
+
+	return nbl_hw_wr_regs_lock(hw_mgt, NBL_UVN_DESC_PREFETCH_INIT,
+				   &prefetch_init, sizeof(prefetch_init));
+}

[Severity: Low]
Was this return intended? nbl_uvn_init() is declared static void and nbl_hw_wr_regs_lock() also returns void, so this is a return with an expression in a void function, which ISO C forbids and -Wpedantic diagnoses. Every other sub-init helper in this patch calls the write helper as a plain statement, and nbl_dp_init() calls nbl_uvn_init() as a statement too, so nothing is propagated.

While on that topic, only nbl_shaping_init() and nbl_ustore_init() can report failure to the int-returning nbl_hw_init_module(); the rest are void. Is the mixed failure model deliberate?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 566

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6 -0
+	for (i = 0; i < NBL_UQM_DPORT_DROP_DEPTH; i++)
+		nbl_hw_wr_regs(hw_mgt,
+			       NBL_UQM_DPORT_DROP_CNT + (sizeof(cnt) * i), &cnt,
+			       sizeof(cnt));
+	/* bit 0: bp mode , bit1: drop mode, resv bit1-31 */
+	nbl_hw_wr_regs(hw_mgt, NBL_UQM_QUE_TYPE, &que_type, sizeof(que_type));

[Severity: Low]
This comment gives bit1 two meanings: "drop mode" and part of the reserved range. Should the reserved range read bit2-31?

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5 -0
+/*
+ * This design is intentional. Setting driver status to false is the
+ * official teardown mechanism: it notifies firmware to perform full
+ * cleanup of all per-PF hardware state, including qinfo registers.
+ * An inverse helper would duplicate work that the firmware already

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 638

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+ * does, and would add error-path complexity for no benefit. We keep
+ * the deinit path minimal and rely on firmware cleanup for correctness,
+ * including abnormal hardware reset scenarios.
+ */
+static void nbl_hw_deinit_module(struct nbl_hw_mgt *hw_mgt)
+{
+	nbl_hw_set_driver_status(hw_mgt, false);
+	/* ensure registers written */
+	nbl_flush_writes(hw_mgt);
+}

[Severity: Low]
This isn't a bug, but is there any way for the driver to observe that the firmware cleanup completed? nbl_flush_writes() only reads the dummy register to push the posted write out, it is not an acknowledgement, and everything init armed stays set on return: shaper VALID bits, DSCH PSHA, USTORE port-drop, DSTORE flow control, DVN/UVN RO and error-mask bits, DPED L4 checksum.

I could not construct a failure path from this in the current series. The only DMA engine set up so far is the mailbox channel, and nbl_chan_teardown_queue() calls nbl_chan_stop_queue(), which stops the queues in hardware:

	hw_ops->stop_mailbox_rxq(chan_mgt->hw_ops_tbl->priv);
	hw_ops->stop_mailbox_txq(chan_mgt->hw_ops_tbl->priv);

before the buffers are released, and nbl_dev_remove() runs the ctrl-dev teardown before the common-dev teardown. So this is only a remark: a defined "cleanup complete" indication with a timeout would make the firmware contract verifiable from the driver side.

[ ... ]

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0 -0
index fed2fb16bff8..95d8a12bdcb5 100644
@@ -110,6 +124,216 @@ struct nbl_function_msix_map {
 	u32 data[NBL_FUNC_MSIX_MAP_DWLEN];
 };
 

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +2 -0
+#define NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK GENMASK(14, 0)
+#define NBL_UVN_DESC_WR_TIMEOUT_MASK_MASK BIT(15)

[ ... ]

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +10 -0
+/*  ---------  SHAPING  ---------  */
+
+/* cir 1, bandwidth 1kB/s in protol environment */
+/* cir 1, bandwidth 1Mb/s */
+#define NBL_LR_LEONIS_NET_BUCKET_DEPTH		9600
+#define NBL_SHAPING_DPORT_ADDR 0x504700
+#define NBL_SHAPING_DPORT_DWLEN 4
+#define NBL_SHAPING_DPORT_REG(r) \
+	(NBL_SHAPING_DPORT_ADDR + (NBL_SHAPING_DPORT_DWLEN * 4) * (r))
+#define NBL_SHAPING_DVN_DPORT_ADDR 0x504750

[ ... ]

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

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +7 -0
+#define DPORT_VALID_MASK (0x1ULL << 0)
+#define DPORT_DEPTH_MASK (0x7FFFFULL << 1)	// [19:1]
+#define DPORT_CIR_MASK (0x7FFFFULL << 20)	// [38:20]
+#define DPORT_PIR_MASK (0x7FFFFULL << 39)	// [57:39]
+#define DPORT_CBS_MASK_LOW (0x3FULL << 58)		// [63:58]
+#define DPORT_CBS_MASK_HIGH (0x7FFFULL << (0)) // [78:64] -> high[14:0]
+#define DPORT_PBS_MASK (0x1FFFFFULL << (79 - 64)) // [99:79] -> high[35:15]

[Severity: Low]
This isn't a bug, but the new register defines mix several conventions.

The C99 // comments above are a checkpatch error, and the masks are hand-rolled shifts where the rest of this header uses GENMASK()/ GENMASK_ULL(). The DPORT_* and DEFAULT_DVN_* macros also lack the NBL_ prefix used by everything else, so they land in the global macro namespace.

Several of the new addresses are spelled out numerically even though the matching base already exists in this header:

	NBL_SHAPING_DPORT_ADDR     0x504700
	NBL_SHAPING_DVN_DPORT_ADDR 0x504750
	NBL_SHAPING_NET_ADDR       0x505800

all sit inside NBL_DP_SHAPING_BASE (0x00504000), which is now left with no user at all in the tree. Same for NBL_DSCH_PSHA_EN_ADDR 0x404314 (NBL_DP_DSCH_BASE + 0x314), NBL_DSTORE_D_DPORT_FC_TH_ADDR 0x704600 and NBL_DSTORE_PORT_DROP_TH_ADDR 0x704150 (NBL_DP_DSTORE_BASE + 0x600 / + 0x150), and NBL_DPED_L4_CK_CMD_40_ADDR 0x75c338 (NBL_DP_DPED_BASE + 0x338).

Finally, a number of the added defines have no user at the end of the series, for example the NBL_DPED_L4_CK_CMD_40_* field masks other than EN, NBL_DSTORE_PORT_DROP_DISC_TH_MASK, NBL_UVN_DESC_WR_TIMEOUT_MASK_MASK and the _DEPTH/_WIDTH/_DWLEN triplets. Could the unused ones be dropped until they are needed?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#13 lore raw

PATCH v26 7/10 net/nebula-matrix: dispatch: add control-level routing core infrastructure

In reply to illusion.wang

From: illusion wang <[email protected]>

Implement core dispatch layer infrastructure for control-plane routing:
Allocate dispatch management structure and dispatch ops table Provide init_module/deinit_module wrapper callbacks for chip resource ops Introduce ctrl_lvl bitmask tracking; enable MGT level only for Control PF

Regular PF NET level routing will be added in a subsequent patch. Kerneldoc on nbl_dispatch_ops documents that init_module/deinit_module must only be invoked on Control PF behind has_ctrl guard.

This skeleton establishes dispatch management flow. It adds forward definitions of channel wire ABI structures and response enums required for later channel RPC framework, without implementing message handling.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 117 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |  23 ++++
 .../nbl/nbl_include/nbl_def_channel.h         |  40 ++++++
 .../nbl/nbl_include/nbl_def_dispatch.h        |  40 ++++++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   8 ++
 7 files changed, 231 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 be314b909d66..b7eebd89b4d1 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_core.h +2 -0
index dd24ebec0171..4d8cea8d8ab3 100644
@@ -17,12 +17,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 +117 -0

117 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +23 -0
new file mode 100644
index 000000000000..a7e5802344b4
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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_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 +40 -0
index 61dd97c779ef..42d2dc1ebede 100644
@@ -13,6 +13,12 @@ struct nbl_adapter;
 
 typedef void (*nbl_chan_resp)(void *, u16, u16, void *, u32);
 
+enum {
+	NBL_CHAN_RESP_OK = 0,
+	NBL_CHAN_RESP_ERR = 1,
+	NBL_CHAN_RESP_UNIMPLEMENTED = 2,
+};
+
 /*
  * Mailbox wire opcodes, stable wire ABI shared between driver and firmware.
  * Each opcode has a fixed assigned number to preserve compatibility.
@@ -39,6 +45,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 en_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;
@@ -46,6 +78,14 @@ struct nbl_board_port_info {
 	u8 rsv[5];
 };
 
+static_assert(sizeof(struct nbl_chan_param_cfg_msix_map) == 8,
+	      "nbl_chan_param_cfg_msix_map size must be 8 bytes");
+static_assert(sizeof(struct nbl_chan_param_set_mailbox_irq) == 4,
+	      "nbl_chan_param_set_mailbox_irq size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_vsi_id) == 4,
+	      "nbl_chan_param_get_vsi_id size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_eth_id) == 8,
+	      "nbl_chan_param_get_eth_id size must be 8 bytes");
 static_assert(sizeof(struct nbl_board_port_info) == 8,
 	      "nbl_board_port_info size must be 8 bytes");
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +40 -0
new file mode 100644
index 000000000000..d5e7da0fef6e
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_DISPATCH_H_
+#define _NBL_DEF_DISPATCH_H_
+
+#include <linux/types.h>
+
+struct nbl_dispatch_mgt;
+struct nbl_adapter;
+enum {
+	NBL_DISP_CTRL_LVL_MGT,
+	NBL_DISP_CTRL_LVL_NET,
+	NBL_DISP_CTRL_LVL_MAX,
+};
+
+/**
+ * struct nbl_dispatch_ops - dispatch control plane operation callbacks
+ * @init_module: dispatch layer initialization, ONLY valid on Control PF,
+ *               caller must check has_ctrl guard
+ * @deinit_module: dispatch layer cleanup, ONLY valid on Control PF,
+ *                 caller must check has_ctrl guard
+ * Warning: All ops except init_module/deinit_module can be safely called
+ * on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr.
+ */
+struct nbl_dispatch_ops {
+	int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);
+	void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt);
+};
+
+struct nbl_dispatch_ops_tbl {
+	struct nbl_dispatch_ops *ops;
+	struct nbl_dispatch_mgt *priv;
+};
+
+int nbl_disp_init(struct nbl_adapter *adapter);
+void nbl_disp_remove(struct nbl_adapter *adapter);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
index 1aafed2d46d7..5d5c0bbf418c 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
#14 lore raw

PATCH v26 8/10 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

In reply to illusion.wang

From: illusion wang <[email protected]>

Add bidirectional mailbox RPC for cross-PF resource coordination, implement request/response handlers for these operations:
configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id.

Dispatch operations are resolved dynamically based on PF control capability:
- Control PF invokes local hardware operations directly.
- Non-control PF forwards requests via mailbox RPC to the manager PF.

Introduce per-dispatch mutex ops_mutex_lock to serialize mutable hardware operations including MSI-X map and mailbox IRQ setup. This eliminates race windows between local control paths and asynchronous remote mailbox RPC response handlers.

Read-only get_vsi_id() / get_eth_id() only access static init-time metadata without concurrent modifications, so they require no locking.

Add helper to register channel response callbacks; extend wire protocol with new message types and NBL_CHAN_RESP_PERM_DENY error code. Translate channel wire status codes to standard Linux errnos to unify error semantics for upper dispatch consumers.

Improve message payload validation for forward compatibility:
reject requests with insufficient payload length, enforce bounds checks before parsing incoming RPC parameters. Fix unimplemented operation check ordering to avoid potential NULL pointer dereferences.

---
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 535 +++++++++++++++++-
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |   2 +
 .../nbl/nbl_include/nbl_def_channel.h         |   6 +
 .../nbl/nbl_include/nbl_def_dispatch.h        |  16 +
 .../nbl/nbl_include/nbl_include.h             |   2 +
 5 files changed, 560 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +534 -1
index 3da5f8351fa4..239d8317a9c5 100644
@@ -3,9 +3,170 @@
  * Copyright (c) 2026 Nebula Matrix Limited.
  */
 #include <linux/device.h>
+#include <linux/mutex.h>
 #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 = {0};
+	int ret;
+
+	param.type = cpu_to_le16(type);
+
+	nbl_chan_fill_send_info(&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_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	default:
+		return -EREMOTEIO;
+	}
+	*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 ret;
+
+	if (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = NBL_CHAN_RESP_ERR;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->get_vsi_id) {
+		ret = res_ops->get_vsi_id(p, src_id, le16_to_cpu(param.type),
+					  &vsi_id);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}
+
+	result.vsi_id = cpu_to_le16(vsi_id);
+ack_out:
+	nbl_chan_fill_ack_info(&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 = {0};
+	int ret;
+
+	param.vsi_id = cpu_to_le16(vsi_id);
+
+	nbl_chan_fill_send_info(&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_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	default:
+		return -EREMOTEIO;
+	}
+	*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 ret;
+
+	if (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = NBL_CHAN_RESP_ERR;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->get_eth_id) {
+		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;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&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;
@@ -25,6 +186,346 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
 	return -EOPNOTSUPP;
 }
 
+static int nbl_disp_cfg_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;
+	int ret;
+
+	if (!res_ops->cfg_msix_map)
+		return -EOPNOTSUPP;
+	mutex_lock(&disp_mgt->ops_mutex_lock);
+	ret = res_ops->cfg_msix_map(p, common->mgt_pf, num_net_msix,
+					  num_others_msix, net_msix_mask_en);
+	mutex_unlock(&disp_mgt->ops_mutex_lock);
+	return ret;
+}
+
+static int
+nbl_disp_chan_cfg_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 = {0};
+	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_fill_send_info(&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_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	default:
+		return -EREMOTEIO;
+	}
+	return 0;
+}
+
+static void nbl_disp_chan_cfg_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 ret;
+
+	if (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = NBL_CHAN_RESP_ERR;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->cfg_msix_map) {
+		mutex_lock(&disp_mgt->ops_mutex_lock);
+		ret = res_ops->cfg_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));
+		mutex_unlock(&disp_mgt->ops_mutex_lock);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&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 = {0};
+	int ret;
+
+	nbl_chan_fill_send_info(&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_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	default:
+		return -EREMOTEIO;
+	}
+	return 0;
+}
+
+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 (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (res_ops->destroy_msix_map) {
+		mutex_lock(&disp_mgt->ops_mutex_lock);
+		ret = res_ops->destroy_msix_map(p, src_id);
+		mutex_unlock(&disp_mgt->ops_mutex_lock);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&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 en_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 = {0};
+	int ret;
+
+	param.vector_id = cpu_to_le16(vector_id);
+	param.en_msix = !!en_msix;
+
+	nbl_chan_fill_send_info(&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_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	default:
+		return -EREMOTEIO;
+	}
+	return 0;
+}
+
+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 en_msix;
+	u16 vector_id;
+	int ret;
+
+	if (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = NBL_CHAN_RESP_ERR;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+	vector_id = le16_to_cpu(param.vector_id);
+	en_msix = !!param.en_msix;
+
+	if (res_ops->set_mailbox_irq) {
+		mutex_lock(&disp_mgt->ops_mutex_lock);
+		ret = res_ops->set_mailbox_irq(p, src_id, vector_id, en_msix);
+		mutex_unlock(&disp_mgt->ops_mutex_lock);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}
+
+ack_out:
+	nbl_chan_fill_ack_info(&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;
+	int ret;
+
+	if (!res_ops->destroy_msix_map)
+		return -EOPNOTSUPP;
+	mutex_lock(&disp_mgt->ops_mutex_lock);
+	ret = res_ops->destroy_msix_map(p, common->mgt_pf);
+	mutex_unlock(&disp_mgt->ops_mutex_lock);
+	return ret;
+}
+
+static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
+				    u16 vector_id, bool en_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;
+	int ret;
+
+	if (!res_ops->set_mailbox_irq)
+		return -EOPNOTSUPP;
+	mutex_lock(&disp_mgt->ops_mutex_lock);
+	ret = res_ops->set_mailbox_irq(p, common->mgt_pf, vector_id, en_msix);
+	mutex_unlock(&disp_mgt->ops_mutex_lock);
+	return ret;
+}
+
+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;
+
+	if (res_ops->get_vsi_id)
+		return res_ops->get_vsi_id(p, common->mgt_pf, type, vsi_id);
+	return -EOPNOTSUPP;
+}
+
+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;
+
+	if (res_ops->get_eth_id)
+		return res_ops->get_eth_id(p, common->mgt_pf, vsi_id,
+					   eth_num, eth_id, logic_eth_id);
+	return -EOPNOTSUPP;
+}
+
+static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *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;
+	int ret = 0;
+	int _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+				      nbl_disp_chan_cfg_msix_map_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+				      nbl_disp_chan_destroy_msix_map_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+				      nbl_disp_chan_set_mailbox_irq_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_VSI_ID,
+				      nbl_disp_chan_get_vsi_id_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_ETH_ID,
+				      nbl_disp_chan_get_eth_id_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	if (ret)
+		chan_ops->unregister_all_msg(p);
+	return ret;
+}
+
 static void nbl_disp_set_ctrl_bit(struct nbl_dispatch_mgt *disp_mgt, u32 lvl)
 {
 	set_bit(lvl, disp_mgt->ctrl_lvl);
@@ -37,6 +538,18 @@ static void nbl_disp_refresh_ctrl_ops(struct nbl_dispatch_mgt *disp_mgt)
 	if (test_bit(NBL_DISP_CTRL_LVL_MGT, disp_mgt->ctrl_lvl)) {
 		disp_ops->init_module = nbl_disp_init_module;
 		disp_ops->deinit_module = nbl_disp_deinit_module;
+		disp_ops->cfg_msix_map = nbl_disp_cfg_msix_map;
+		disp_ops->destroy_msix_map = nbl_disp_destroy_msix_map;
+		disp_ops->set_mailbox_irq = nbl_disp_set_mailbox_irq;
+		disp_ops->get_vsi_id = nbl_disp_get_vsi_id;
+		disp_ops->get_eth_id = nbl_disp_get_eth_id;
+	} else {
+		disp_ops->cfg_msix_map =
+			nbl_disp_chan_cfg_msix_map_req;
+		disp_ops->destroy_msix_map = nbl_disp_chan_destroy_msix_map_req;
+		disp_ops->set_mailbox_irq = nbl_disp_chan_set_mailbox_irq_req;
+		disp_ops->get_vsi_id = nbl_disp_chan_get_vsi_id_req;
+		disp_ops->get_eth_id = nbl_disp_chan_get_eth_id_req;
 	}
 }
 
@@ -45,12 +558,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;
 }
 
@@ -104,14 +621,30 @@ 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_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
+	/*
+	 * For non-control PF with network capability, enable net control
+	 * level.
+	 * All dispatch ops declared with NBL_DISP_CTRL_LVL_MGT fall back
+	 * to remote mailbox msg_req handlers when MGT bit is not set.
+	 */
+	if (common->has_net)
+		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_NET);
 	nbl_disp_refresh_ctrl_ops(disp_mgt);
 	return 0;
 }
 
 void nbl_disp_remove(struct nbl_adapter *adapter)
 {
-	/* All dispatch objects allocated via devm */
+	/*
+	 * All dispatch objects allocated via devm
+	 * All message handlers will be cleaned up inside channel layer
+	 * nbl_chan_remove_common() at final device tear-down
+	 */
 }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +2 -0
index a7e5802344b4..8549048f76e9 100644
@@ -18,6 +18,8 @@ struct nbl_dispatch_mgt {
 	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
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +6 -0
index 42d2dc1ebede..e5bc79e13fac 100644
@@ -17,6 +17,7 @@ enum {
 	NBL_CHAN_RESP_OK = 0,
 	NBL_CHAN_RESP_ERR = 1,
 	NBL_CHAN_RESP_UNIMPLEMENTED = 2,
+	NBL_CHAN_RESP_PERM_DENY = 3,
 };
 
 /*
@@ -36,6 +37,11 @@ enum {
  */
 enum nbl_chan_msg_type {
 	NBL_CHAN_MSG_ACK = 0,
+	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_VSI_ID = 21,
+	NBL_CHAN_MSG_GET_ETH_ID = 67,
 	/* mailbox msg end */
 	NBL_CHAN_MSG_MAILBOX_MAX,
 };
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +16 -0
index d5e7da0fef6e..61083a750da4 100644
@@ -22,12 +22,28 @@ enum {
  *               caller must check has_ctrl guard
  * @deinit_module: dispatch layer cleanup, ONLY valid on Control PF,
  *                 caller must check has_ctrl guard
+ * @cfg_msix_map: configure function msix mapping table
+ * @destroy_msix_map: tear down msix mapping resource
+ * @set_mailbox_irq: bind mailbox interrupt to specified msix vector
+ * @get_vsi_id: resolve VSI ID by type
+ * @get_eth_id: resolve eth port info from VSI ID
+ *
  * Warning: All ops except init_module/deinit_module can be safely called
  * on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr.
  */
 struct nbl_dispatch_ops {
 	int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);
 	void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt,
+			    u16 num_net_msix, u16 num_others_msix,
+			    bool net_msix_mask_en);
+	int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*set_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt,
+			       u16 vector_id, bool en_msix);
+	int (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+			  u16 *vsi_id);
+	int (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+			  u8 *eth_num, u8 *eth_id, u8 *logic_eth_id);
 };
 
 struct nbl_dispatch_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +2 -0
index ebf85702cef6..a53138530c54 100644
@@ -15,6 +15,8 @@
 
 #define NBL_MAX_FUNC					520
 #define NBL_MAX_ETHERNET				4
+/* Product firmware only supports 1/2/4 contiguous PFs (ID 0~3) */
+#define NBL_MAX_PF_SRC_ID				3
 
 enum {
 	NBL_VSI_DATA = 0,
Signature · 1 line
2.47.3
#15 lore raw

Re: [v26,net-next,08/10] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 4 · Low: 4

- [Medium] All five new *_req() helpers translate the return value of chan_ops->send_msg() with a switch that only enumerates the four wire…
- [Medium] nbl_disp_setup_msg()'s rollback calls chan_ops->unregister_all_msg(), which is…
- [Medium] nbl_disp_chan_get_vsi_id_req() and nbl_disp_chan_get_eth_id_req() consume the ACK payload without…
- [Medium] The newly exposed destroy_msix_map op (local nbl_disp_destroy_msix_map(), remote…
- [Low] The commit message describes work the diff does not contain.
- [Low] nbl_disp_init() sets NBL_DISP_CTRL_LVL_NET whenever common->has_net, with a comment claiming this enables the 'net control…
- [Low] The kernel-doc block that this patch extends states 'Warning: All ops except init_module/deinit_module can be safely called on PF/VF',…
- [Low] The newly exposed NBL_CHAN_MSG_CONFIGURE_MSIX_MAP handler forwards peer-supplied vector counts straight to the global allocator…

--

net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

This adds mailbox RPC request/response handlers for configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id, resolving the dispatch ops to either local hardware calls (control PF) or remote requests to the manager PF. It also adds a per-dispatch mutex to serialize the mutable hardware ops, plus new wire message types and a permission-denied status code.

A few questions below about the commit message and about the new handlers.

The commit message says:

Improve message payload validation for forward compatibility:
reject requests with insufficient payload length, enforce bounds checks before parsing incoming RPC parameters. Fix unimplemented operation check ordering to avoid potential NULL pointer dereferences.

and:

Add helper to register channel response callbacks; extend wire protocol with new message types and NBL_CHAN_RESP_PERM_DENY error code.

[Severity: Low]
Which pre-existing code do the words "Improve", "Fix ... ordering" and "Add helper" refer to?

At the parent commit the only helpers in nbl_dispatch.c are nbl_disp_init_module() and nbl_disp_deinit_module(), and both already had the guard:

	if (res_ops->init_module)
		return res_ops->init_module(p);
	return -EOPNOTSUPP;

Neither is touched by this patch, so no check ordering appears to change. Likewise, every handler containing a data_len < sizeof(param) test is introduced by this patch, so there is no earlier validation being improved.

register_msg() and unregister_all_msg() also already exist in struct nbl_channel_ops, and nbl_chan_setup_ops() already registers NBL_CHAN_MSG_ACK; what this patch adds is a dispatch-layer setup function, nbl_disp_setup_msg(), not a channel helper.

Could the wording be changed to describe the new code as new, so readers do not look for a Fixes: tag and a previously broken commit?

Quoted 31 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +20 -0
index 3da5f8351fa4..239d8317a9c5 100644
@@ -3,9 +3,170 @@
  * Copyright (c) 2026 Nebula Matrix Limited.
  */
 #include <linux/device.h>
+#include <linux/mutex.h>
 #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 = {0};
+	int ret;
+
+	param.type = cpu_to_le16(type);
+
+	nbl_chan_fill_send_info(&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_OK:

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 38

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10 -0
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_PERM_DENY:
+		return -EPERM;
+	default:
+		return -EREMOTEIO;
+	}

[Severity: Medium]
Does this switch turn every local transport error into -EREMOTEIO?

nbl_chan_send_msg() only returns a wire status code when an ACK actually arrives. Otherwise it returns a negative Linux errno:

nbl_channel/nbl_channel.c:nbl_chan_send_msg() {
	...
	if (READ_ONCE(chan_info->shutdn)) { ... return -ESHUTDOWN; }
	...
	ret = -ETIMEDOUT;
	...
	ret = READ_ONCE(wait_head->ack_err);
}

plus -EINVAL for oversized arg_len/resp_len, -EAGAIN when all TX wait slots are busy, and -EIO when the mailbox IRQ is disabled mid-wait.

All of those land in the default arm, so a caller cannot tell a retryable or teardown condition from a genuine remote hardware failure, and nbl_dev_stop() ends up logging a remote I/O error for what was really -ESHUTDOWN or -ETIMEDOUT. The same switch is repeated in nbl_disp_chan_get_eth_id_req(), nbl_disp_chan_cfg_msix_map_req(), nbl_disp_chan_destroy_msix_map_req() and nbl_disp_chan_set_mailbox_irq_req().

Would an early "if (ret < 0) return ret;" before the switch preserve the error semantics the changelog aims for?

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +3 -0
+	*vsi_id = le16_to_cpu(result.vsi_id);
+	return 0;
+}

[ ... ]

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +9 -0
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	switch (ret) {
+	case NBL_CHAN_RESP_OK:
+		break;
+	case NBL_CHAN_RESP_UNIMPLEMENTED:
+		return -EOPNOTSUPP;
+	case NBL_CHAN_RESP_ERR:
+		return -EREMOTEIO;
+	case NBL_CHAN_RESP_PERM_DENY:

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 124

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10 -0
+		return -EPERM;
+	default:
+		return -EREMOTEIO;
+	}
+	*eth_num = result.eth_num;
+	*eth_id = result.eth_id;
+	*logic_eth_id = result.logic_eth_id;
+
+	return 0;
+}

[Severity: Medium]
Can a short ACK make these two helpers report success with zeroed identifiers?

nbl_chan_recv_ack_msg() takes the status straight from the wire and only clamps the payload copy, reporting the effective length back through chan_send->ack_len:

nbl_channel/nbl_channel.c:nbl_chan_recv_ack_msg() {
	...
	copy_len = min_t(u32, READ_ONCE(wait_head->ack_data_len), ack_datalen);
	if (READ_ONCE(wait_head->ack_err) >= 0 && copy_len > 0) {
		...
		WRITE_ONCE(wait_head->ack_data_len, (u16)copy_len);
	}
}

nbl_disp_chan_get_vsi_id_req() and nbl_disp_chan_get_eth_id_req() never look at chan_send.ack_len, so a peer answering status OK with a truncated or empty payload leaves the "= { 0 }" initialiser values in place and the caller gets vsi_id 0, eth_id 0, logic_eth_id 0, eth_num 0 and a 0 return. Per nbl_res_ctrl_dev_vsi_info_init() ("pf0,pf1,pf2,pf3 vsi is 0,256,512,768") vsi_id 0 and eth_id 0 are valid identifiers belonging to PF0, so a non-control PF would silently adopt another function's VSI/port identity.

There is also no range check on the returned values, unlike the local producer:

nbl_hw/nbl_resource.c:nbl_res_get_eth_id() {
	...
	if (rel_pf_id >= eth_info->eth_num) {
		dev_err(dev, "rel_pf_id %d out of range [0, %u)\n", ...);
		return -ERANGE;
	}
}

Should these helpers check chan_send.ack_len against sizeof(result) and bound eth_num/eth_id/logic_eth_id against NBL_MAX_ETHERNET before handing the values to the caller?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -0
@@ -25,6 +186,346 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
 	return -EOPNOTSUPP;
 }
 

[ ... ]

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

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +12 -0
+	if (res_ops->cfg_msix_map) {
+		mutex_lock(&disp_mgt->ops_mutex_lock);
+		ret = res_ops->cfg_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));
+		mutex_unlock(&disp_mgt->ops_mutex_lock);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}

[Severity: Low]
Should there be a per-function limit on the requested vector counts here?

After the coarse src_id check the peer-supplied counts go straight to the global allocator, which only enforces device-wide maxima:

nbl_hw/nbl_interrupt.c:nbl_res_intr_cfg_msix_map() {
	...
	if (num_net_msix > NBL_MSIX_MAP_TABLE_MAX_ENTRIES ||
	    num_others_msix > NBL_MSIX_MAP_TABLE_MAX_ENTRIES) { ... }
}

The accepted maximum for num_others_msix equals the whole shared pool (NBL_MAX_OTHER_INTERRUPT is 1024), so a single request for 1024 drains intr_other_bmap and every later allocation for any function, including the control PF's own mailbox and misc vectors, then fails with -EAGAIN.

Each request also does a full 1024-entry coherent DMA table allocation and the usleep_range(100, 120) quiesce inside nbl_res_intr_destroy_msix_map() while ops_mutex_lock is held, which stalls the control PF's mailbox work item.

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

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +13 -0
+	if (src_id > NBL_MAX_PF_SRC_ID) {
+		err = NBL_CHAN_RESP_PERM_DENY;
+		goto ack_out;
+	}
+	if (res_ops->destroy_msix_map) {
+		mutex_lock(&disp_mgt->ops_mutex_lock);
+		ret = res_ops->destroy_msix_map(p, src_id);
+		mutex_unlock(&disp_mgt->ops_mutex_lock);
+		if (ret)
+			err = NBL_CHAN_RESP_ERR;
+	} else {
+		err = NBL_CHAN_RESP_UNIMPLEMENTED;
+	}

[Severity: Medium]
Does making destroy_msix_map remotely invokable leave the requester's mailbox interrupt routing armed on a recycled vector?

nbl_res_intr_destroy_msix_map() masks the per-vector entries, returns the global vector numbers to the bitmaps and frees the per-function array:

nbl_hw/nbl_interrupt.c:nbl_res_intr_destroy_msix_map() {
	...
	nbl_intr_release_bitmap(res_mgt, interrupts, intr_num);
	...
	kfree(intr_mgt->func_intr_res[func_id].interrupts);
	intr_mgt->func_intr_res[func_id].interrupts = NULL;
}

but MSIX_IDX/MSIX_IDX_VALID in NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id), written only by nbl_hw_set_mailbox_irq(), is left pointing at the vector that was just released. It cannot be cleared afterwards either:

nbl_hw/nbl_interrupt.c:nbl_res_intr_set_mailbox_irq() {
	if (!intr_mgt->func_intr_res[func_id].interrupts) {
		dev_err(dev, "func %u MSIX map not configured\n", func_id);
		return -ENODEV;
	}
}

A later nbl_res_intr_cfg_msix_map() for another function re-validates the same global vector with the new owner's BDF, so a mailbox event for the old function would raise an interrupt owned by a different PF. nbl_res_intr_cfg_msix_map() also calls the same teardown internally, so a peer sending CONFIGURE_MSIX_MAP twice, or DESTROY_MSIX_MAP while its mailbox IRQ is still armed, reaches this from the wire.

Would it be better to clear the mailbox QINFO mapping as part of destroy_msix_map, or at least document the required ordering against set_mailbox_irq in nbl_def_dispatch.h?

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +12 -0
+static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *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;
+	int ret = 0;
+	int _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+				      nbl_disp_chan_cfg_msix_map_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;

[ ... ]

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

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4 -0
+	if (ret)
+		chan_ops->unregister_all_msg(p);
+	return ret;
+}

[Severity: Medium]
Does this rollback destroy state owned by the channel layer?

unregister_all_msg is nbl_chan_remove_msg_handler():

nbl_channel/nbl_channel.c:nbl_chan_remove_msg_handler() {
	if (!chan_mgt->handle_hash_tbl)
		return;
	nbl_common_remove_hash_table(chan_mgt->handle_hash_tbl);
	chan_mgt->handle_hash_tbl = NULL;
}

That frees every handler node, including the channel's own ACK handler registered by nbl_chan_setup_ops():

	ret = nbl_chan_register_msg(chan_mgt, NBL_CHAN_MSG_ACK,
				    nbl_chan_recv_ack_msg, chan_mgt);

and then NULLs the shared table pointer with no re-init path, since nbl_chan_init_msg_handler() is only called from nbl_chan_setup_chan_mgt(). Neither accessor tolerates a NULL table:

nbl_common/nbl_common.c:nbl_common_get_hash_node() {
	...
	key_size = tbl_mgt->tbl_key.key_size;
}

Registration is also unpaired at this layer: nbl_disp_remove() is empty and delegates handler teardown to nbl_chan_remove_common(). As far as I can tell no crash is reachable today, because the only failure mode of nbl_chan_register_msg() is -ENOMEM during nbl_disp_init(), and at that point no mailbox queue, IRQ or clean_mbx_task exists yet, so nothing looks the table up during the unwind. Would it be more robust to unregister only the five message types this function registered, and to do it from nbl_disp_remove()?

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4 -0
@@ -104,14 +621,30 @@ 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)

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +8 -0
 		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
+	/*
+	 * For non-control PF with network capability, enable net control
+	 * level.
+	 * All dispatch ops declared with NBL_DISP_CTRL_LVL_MGT fall back
+	 * to remote mailbox msg_req handlers when MGT bit is not set.
+	 */
+	if (common->has_net)
+		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_NET);

[Severity: Low]
Is anything reading NBL_DISP_CTRL_LVL_NET?

Grepping the nbl driver at this commit, the symbol appears only in its enum definition in nbl_def_dispatch.h and in this new set_bit(). The single consumer of ctrl_lvl only tests the MGT bit:

nbl_core/nbl_dispatch.c:nbl_disp_refresh_ctrl_ops() {
	if (test_bit(NBL_DISP_CTRL_LVL_MGT, disp_mgt->ctrl_lvl)) {
	...
}

so the NET bit is write-only state.

The comment also says "For non-control PF with network capability", but the condition is just common->has_net, and every entry in nbl_id_table sets BIT(NBL_CAP_HAS_NET_BIT), so the control PF takes this branch too. Should the condition and the comment be reconciled, or the bit dropped until a reader exists?

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -0
 	nbl_disp_refresh_ctrl_ops(disp_mgt);
 	return 0;
 }

[ ... ]

Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +6 -0
index d5e7da0fef6e..61083a750da4 100644
@@ -22,12 +22,28 @@ enum {
  *               caller must check has_ctrl guard
  * @deinit_module: dispatch layer cleanup, ONLY valid on Control PF,
  *                 caller must check has_ctrl guard
+ * @cfg_msix_map: configure function msix mapping table
+ * @destroy_msix_map: tear down msix mapping resource
+ * @set_mailbox_irq: bind mailbox interrupt to specified msix vector
+ * @get_vsi_id: resolve VSI ID by type
+ * @get_eth_id: resolve eth port info from VSI ID
+ *
  * Warning: All ops except init_module/deinit_module can be safely called
  * on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr.
  */

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h line 19

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +2 -0
index ebf85702cef6..a53138530c54 100644
@@ -15,6 +15,8 @@
 
 #define NBL_MAX_FUNC					520
 #define NBL_MAX_ETHERNET				4
+/* Product firmware only supports 1/2/4 contiguous PFs (ID 0~3) */
+#define NBL_MAX_PF_SRC_ID				3

[Severity: Low]
Does this constant contradict the documented contract just above?

The kernel-doc extended by this patch says the five new ops "can be safely called on PF/VF", but on a non-control function they resolve to the *_req() helpers, and every new responder starts with:

	if (src_id > NBL_MAX_PF_SRC_ID) {
		err = NBL_CHAN_RESP_PERM_DENY;
		goto ack_out;
	}

src_id is the mailbox descriptor srcid in a function-id space of NBL_MAX_FUNC (520), so any VF requester is denied by construction and its *_req() helper returns -EPERM.

The hardcoded 3 also disagrees with the runtime model used elsewhere:
nbl_common_func_id_to_rel_pf_id() computes pf_id - common->mgt_pf and is documented to "Support future non-zero management PF", while nbl_res_func_id_to_bdf() and nbl_res_get_eth_id() validate against resource_info->max_pf. With mgt_pf != 0 the legitimate absolute PF ids exceed 3 and would be denied as well.

No VF can bind this driver today, since nbl_id_table lists only PF device ids and mgt_pf is hardcoded to 0 in nbl_core_init(), so this is a documentation and future-proofing question rather than an active failure. Would validating src_id against mgt_pf plus max_pf be preferable to the new constant, or should the "PF/VF" wording be adjusted?

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +0 -0
 enum {
 	NBL_VSI_DATA = 0,
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#16 lore raw

PATCH v26 9/10 net/nebula-matrix: add common/ctrl dev init/remove operation

In reply to illusion.wang

From: illusion wang <[email protected]>

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

Add nbl_dev core infrastructure. Introduce nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() initialization helpers with paired teardown routines, and hook them into nbl_dev_init() and nbl_dev_remove().

Chip core hardware initialization is handled by firmware during power-on. The driver configures functional table entries after hardware becomes ready, so calling nbl_dev_setup_common_dev() before ctrl dev setup is safe.

Enforce the deinit sequence: remove ctrl dev first to notify firmware to clean all per-PF hardware state including qinfo registers. Afterwards tear down common device queue resources. Firmware cleanup ensures valid register access during common dev deinit and prevents PCIe master abort.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   1 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 236 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |  55 ++++
 .../nbl/nbl_include/nbl_def_dev.h             |  14 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 6 files changed, 316 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 b7eebd89b4d1..71fbe3ee7e62 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 +1 -0
index 4d8cea8d8ab3..c3c4dd685bf6 100644
@@ -25,6 +25,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 +236 -0

236 lines not on this page · raw message

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

55 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..51cf04e4c552
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 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 5d5c0bbf418c..9896c1b49be2 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
#17 lore raw

Re: [v26,net-next,09/10] net/nebula-matrix: add common/ctrl dev init/remove operation

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Critical: 0 · High: 0 · Medium: 3 · Low: 2

- [Medium] nbl_dev_setup_common_dev() issues two synchronous ACK-waiting mailbox requests (disp_ops->get_vsi_id(), disp_ops->get_eth_id())…
- [Medium] nbl_dev_setup_common_dev() enables the PF mailbox queue (nbl_chan_setup_queue(): config_mailbox_txq/rxq with QUEUE_EN=1,…
- [Medium] nbl_dev_remove() relies on nbl_dev_remove_ctrl_dev() -> disp_ops->deinit_module() -> nbl_hw_deinit_module(), which only does a…
- [Low] The justification comment block added above nbl_dev_remove_ctrl_dev() in nbl_core/nbl_dev.c is factually wrong and…
- [Low] The in-tree comment documenting the ordering contract for common->hw_bus in nbl_res_ctrl_dev_sriov_info_init()…

--

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

This adds the nbl_dev core layer with nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() plus their teardown counterparts, and wires them into nbl_dev_init()/nbl_dev_remove() from nbl_core_init()/nbl_core_remove(). A few questions below about the probe/remove ordering and about some of the new comments and the commit message.

Quoted 11 lines

Enforce the deinit sequence: remove ctrl dev first to notify firmware to clean all per-PF hardware state including qinfo registers. Afterwards tear down common device queue resources. Firmware cleanup ensures valid register access during common dev deinit and prevents PCIe master abort.

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0 -0
new file mode 100644
index 000000000000..4fc52cadf60f
@@ -0,0 +1,236 @@

[ ... ]

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

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +12 -0
+/* ----------  Channel config  ---------- */
+static void nbl_dev_setup_chan_qinfo(struct nbl_dev_mgt *dev_mgt, u8 chan_type)
+{
+	struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+	struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv;
+	struct nbl_common_info *common = dev_mgt->common;
+
+	if (!chan_ops->check_queue_exist(priv, chan_type))
+		return;
+
+	chan_ops->cfg_chan_qinfo_map_table(priv, common->hw_bus, common->devid);
+}

[Severity: Low]

This is the only in-tree caller of cfg_chan_qinfo_map_table(), and it is reached as nbl_dev_init() -> nbl_dev_setup_ctrl_dev() -> nbl_dev_setup_chan_qinfo(). The existing comment that documents the ordering contract for common->hw_bus names a different call site:

nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c:nbl_res_ctrl_dev_sriov_info_init() {
/*
* common->hw_bus supplies bus number for channel mailbox QINFO mapping.
* Execution order guarantee: this assignment runs before
* cfg_chan_qinfo_map_table() in nbl_dev_start(), only executed
* on control PF path.
*/
common->hw_bus = hw_bus;
}

There is no nbl_dev_start() at this commit, and the nbl_dev_start() added later in the series calls nbl_dev_cfg_msix_map(), nbl_dev_init_interrupt_scheme(), nbl_dev_request_mailbox_irq() and nbl_dev_enable_mailbox_irq() only, so it never programs the qinfo map. The ordering itself does hold today, since nbl_res_init_leonis() runs before nbl_dev_init() in nbl_core_init(). Could that comment be updated to point at nbl_dev_setup_ctrl_dev() instead?

[ ... ]

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

[ ... ]

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9 -0
+	ret = nbl_dev_setup_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+	if (ret)
+		return ret;
+
+	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

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+	 * 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);
+	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;

[Severity: Medium]

Can these two calls complete at this point in the series?

On a non-control PF, get_vsi_id()/get_eth_id() resolve to nbl_disp_chan_get_vsi_id_req()/nbl_disp_chan_get_eth_id_req(), i.e. real mailbox round trips to mgt_pf that wait for an ACK.

At this commit nothing in the tree requests a mailbox interrupt and NBL_CHAN_IRQ_RDY is never set, so in nbl_chan_send_msg() the polling branch only drains the sender's own RX ring:

nbl_channel/nbl_channel.c:nbl_chan_send_msg() {
	if (test_bit(NBL_CHAN_IRQ_RDY, chan_info->state)) { ... }
	else { /* Polling path for synchronous ACK */ }
}

The control PF has nothing driving nbl_chan_clean_queue() on its side, so the responder never runs and both requests appear to time out, failing probe on every non-control PF.

The later patch in this series ("net/nebula-matrix: add common dev start/stop operation") adds nbl_dev_request_mailbox_irq() and nbl_dev_enable_mailbox_irq(), and nbl_probe() then calls nbl_core_start() -> nbl_dev_start(), which is what makes the control PF drain its RX ring and answer. So the ACK path does exist at the end of the series and this looks limited to the intermediate tree state. Would it be possible to order the series so probe works at each step, or is the intermediate bisect state intentional here?

Also, nbl_dev_init_msix_cnt() records msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num = 1 in this patch while no vector is allocated or requested yet, which fits the same observation.

[ ... ]

Quoted 23 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +23 -0
+static int nbl_dev_setup_ctrl_dev(struct nbl_adapter *adapter)
+{
+	struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+	struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+	int ret;
+
+	ret = disp_ops->init_module(dev_mgt->disp_ops_tbl->priv);
+	if (ret)
+		return ret;
+
+	nbl_dev_setup_chan_qinfo(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+
+	return 0;
+}
+
+/*
+ * This is intentional.  The qinfo registers are managed by the chip
+ * firmware, not by the driver.  Setting driver status to false is the
+ * designed teardown mechanism — it notifies the firmware, which then
+ * performs its own cleanup of all per-PF state including the qinfo
+ * registers.
+ * An inverse helper would duplicate work that the firmware already
+ * does, and would add error-path complexity for no benefit.  We keep

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+ * the deinit path minimal and rely on the firmware cleanup for
+ * correctness, including in abnormal reset scenarios.
+ */
+static void nbl_dev_remove_ctrl_dev(struct nbl_adapter *adapter)
+{
+	struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+	struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+
+	disp_ops->deinit_module(dev_mgt->disp_ops_tbl->priv);
+}

[Severity: Low]

Is the claim that "The qinfo registers are managed by the chip firmware, not by the driver" accurate? The path added just above this comment programs them from the driver:

nbl_dev_setup_chan_qinfo()
chan_ops->cfg_chan_qinfo_map_table()

    nbl_chan_cfg_qinfo_map_table()
      hw_ops->cfg_mailbox_qinfo()
        nbl_hw_cfg_mailbox_qinfo()
nbl_channel/nbl_channel.c:nbl_chan_cfg_qinfo_map_table() {
	for (func_id = 0; func_id < NBL_MAX_PF; func_id++) {
		if (!(pf_mask & (1 << func_id)))
			hw_ops->cfg_mailbox_qinfo(p, func_id, bus, devid, func_id);
	}
}

Only the cleanup is delegated to firmware, so would something like "the qinfo registers are cleaned up by firmware on driver-status change" be closer to what happens?

Two more notes on the same block: it is a near-verbatim copy of the comment already sitting above nbl_hw_deinit_module() in nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c, which is where the described register write actually lives, and the opening "This is intentional." reads as a reply to review feedback rather than as documentation. Could it be dropped here and kept only at the hw layer?

Relatedly, the commit message says:

Quoted 3 lines

Introduce nbl_dev_setup_common_dev()
and nbl_dev_setup_ctrl_dev() initialization helpers with paired teardown routines

nbl_dev_setup_ctrl_dev() does init_module() plus qinfo map programming while nbl_dev_remove_ctrl_dev() does deinit_module() only, so the two are not symmetric.

[ ... ]

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

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +4 -0
+	/*
+	 * Chip hardware initialization is completed by firmware at power-up.
+	 * Only driver functional table/register config follows here, safe to
+	 * access hardware registers before ctrl dev setup.

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+	 */
+	ret = nbl_dev_setup_common_dev(adapter);
+	if (ret)
+		goto setup_err;
+
+	if (common->has_ctrl) {
+		ret = nbl_dev_setup_ctrl_dev(adapter);
+		if (ret)
+			goto setup_ctrl_dev_fail;
+	}

[Severity: Medium]

What guarantees the mailbox routing table entry for a non-control PF is programmed before that PF starts using its mailbox?

nbl_dev_setup_common_dev() enables the PF mailbox queue (nbl_chan_setup_queue() -> config_mailbox_txq/rxq with QUEUE_EN=1, RST=0, RX tail written) and then immediately sends mailbox messages, but NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id) is written only afterwards and only on the control PF:

nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c:nbl_hw_cfg_mailbox_qinfo() {
data = FIELD_PREP(NBL_MAILBOX_QINFO_MAP_FUNCTION_MASK, function) |
FIELD_PREP(NBL_MAILBOX_QINFO_MAP_DEVID_MASK, devid) | FIELD_PREP(NBL_MAILBOX_QINFO_MAP_BUS_MASK, bus);
}

has_ctrl is set only for PCI function 0 in nbl_get_func_param(), so PF1..PF3 never program that table themselves. Their probe path depends on PF0 having already done it, and nothing in nbl_dev_init() checks or enforces that.

Cases where the entry may not be programmed yet look reachable: PF0 unbound via sysfs, PF0 bound to a different driver, or concurrent probing when async probing is enabled. If the entry still holds zero, the mailbox ring BDF is also zero. Best case that means the two ACK timeouts above and a probe failure with no retry; is a write towards a zero BDF also possible on this chip, and if so what stops it?

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +4 -0
+/*
+ * Teardown order: ctrl dev first, then common dev.
+ * nbl_dev_remove_ctrl_dev() notifies firmware to clean all per-PF state
+ * (including qinfo registers), so subsequent common dev queue cleanup

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

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+ * will not trigger PCIe master abort or invalid register access.
+ */
+void nbl_dev_remove(struct nbl_adapter *adapter)
+{
+	struct nbl_common_info *common = &adapter->common;
+
+	if (common->has_ctrl)
+		nbl_dev_remove_ctrl_dev(adapter);
+	nbl_dev_remove_common_dev(adapter);
+}

[Severity: Medium]

How is the firmware cleanup serialized against the queue teardown that follows it? The notification is a bare register write plus a flush:

nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c:nbl_hw_deinit_module() {
	nbl_hw_set_driver_status(hw_mgt, false);
	/* ensure registers written */
	nbl_flush_writes(hw_mgt);
}

There is no completion poll, status read-back or delay before nbl_dev_remove_common_dev() -> nbl_chan_teardown_queue() writes the queue reset:

nbl_hw_stop_mailbox_rxq() / nbl_hw_stop_mailbox_txq() {
	cfg_tbl.data[3] = FIELD_PREP(NBL_MAILBOX_QINFO_CFG_QUEUE_RST_MASK, 1);
	nbl_hw_write_mbx_regs(hw_mgt, NBL_MAILBOX_QINFO_CFG_RX_TABLE_ADDR,
			      cfg_tbl.data, sizeof(cfg_tbl));
}

and the QUEUE_RST/QUEUE_EN state is never read back, so a firmware write landing after the driver's reset write would leave the queue enabled in hardware while the driver believes it is stopped, with no way to notice.

Could a driver-status handshake or a queue-reset read-back be added, or the claim in the commit message be dropped:

Quoted 2 lines

Firmware cleanup ensures valid
register access during common dev deinit and prevents PCIe master abort.

For what it is worth, the DMA-after-free variant of this does not seem to
apply: nbl_remove() calls pci_clear_master(pdev) before returning, and the dmam_alloc_coherent() rings are released by devres only after .remove() returns, so bus mastering is already off when the ring memory goes away.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com
author maintainer
#18 lore raw

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

In reply to illusion.wang

From: illusion wang <[email protected]>

Implement nbl_dev_start() and nbl_dev_stop() to manage MSI-X mapping, mailbox interrupt initialization and deinitialization.

nbl_dev_start() performs device startup steps:
- Configure hardware MSI-X mapping table
- Allocate required MSI-X IRQ vectors via pci_alloc_irq_vectors()
- Request mailbox interrupt and attach interrupt handler
- Enable hardware mailbox interrupt and mark channel interrupt ready

nbl_dev_stop() tears down resources with strict ordering to avoid stale message ACK handling:
- Switch channel software state to polling mode before masking hardware interrupt
- Release mailbox IRQ and free MSI-X vector resources
- Destroy hardware MSI-X mapping table

Add thin wrappers nbl_core_start() / nbl_core_stop() and hook them into PCI probe and remove paths to control the device lifecycle.

---
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 268 ++++++++++++++++++
 .../nbl/nbl_include/nbl_def_dev.h             |   2 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  18 ++
 4 files changed, 290 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index c3c4dd685bf6..56872c8ca9a7 100644
@@ -39,5 +39,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 +268 -0

289 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
index 51cf04e4c552..a66c633a0e7a 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 +18 -0
index 9896c1b49be2..02cb35d32012 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)
 {
@@ -127,7 +137,13 @@ 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:
+	nbl_core_remove(adapter);
 adapter_init_err:
 	pci_clear_master(pdev);
 	return err;
@@ -140,6 +156,8 @@ static void nbl_remove(struct pci_dev *pdev)
 	if (!adapter)
 		return;
 	pci_set_drvdata(pdev, NULL);
+
+	nbl_core_stop(adapter);
 	nbl_core_remove(adapter);
 
 	pci_clear_master(pdev);
Signature · 1 line
2.47.3
#19 lore raw

Re: [v26,net-next,10/10] net/nebula-matrix: add common dev start/stop operation

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Critical: 0 · High: 1 · Medium: 1 · Low: 1

- [High] This patch adds the first live callers of cfg_msix_map()/destroy_msix_map(), so the control PF (function 0) now…
- [Medium] In nbl_dev_stop() (nbl_core/nbl_dev.c:489-495) and in the identical unwind inside nbl_dev_start() (nbl_dev.c:465-472), a failure…
- [Low] Claim (assessed FALSE POSITIVE): nbl_dev_disable_mailbox_irq() clears NBL_CHAN_IRQ_RDY (nbl_core/nbl_dev.c:137-139) without waking…

--

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

This adds nbl_dev_start() and nbl_dev_stop() to configure the hardware MSI-X map, allocate MSI-X vectors, request the mailbox interrupt and tear all of that down again. Thin nbl_core_start() / nbl_core_stop() wrappers are hooked into the PCI probe and remove paths.

A few questions on the new start/stop paths below.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0 -0
index 4fc52cadf60f..26b785c9a05f 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0 -0
@@ -14,6 +25,189 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)
 	msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num = 1;
 }
 

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 110

Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +13 -0
+static int nbl_dev_disable_mailbox_irq(struct nbl_dev_mgt *dev_mgt)
+{
+	struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+	struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+	struct nbl_dev_common *dev_common = dev_mgt->common_dev;
+	struct nbl_msix_info *msix_info = &dev_common->msix_info;
+	u16 local_vec_id;
+
+	if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num)
+		return 0;
+
+	local_vec_id =
+		msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].base_vector_id;

[ ... comment block snipped ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 143

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +7 -0
+	chan_ops->set_queue_state(dev_mgt->chan_ops_tbl->priv,
+				  NBL_CHAN_IRQ_RDY,
+				  NBL_CHAN_TYPE_MAILBOX, false);
+
+	return disp_ops->set_mailbox_irq(dev_mgt->disp_ops_tbl->priv,
+					    local_vec_id, false);
+}

[Severity: Low]
This isn't a bug in the tree as it stands, but clearing NBL_CHAN_IRQ_RDY here does not wake the per-message ACK wait queues that test that same bit.

nbl_chan_send_msg() sleeps on it:

	ret = wait_event_timeout(wait_head->wait_queue,
				 READ_ONCE(wait_head->acked) ||
				 READ_ONCE(chan_info->shutdn) ||
				 !test_bit(NBL_CHAN_IRQ_RDY,
					   chan_info->state),
				 NBL_CHAN_ACK_WAIT_TIME);

At this point in the series every ack-requesting sender is one of the nbl_disp_chan_*_req() helpers, all reached only from nbl_dev_setup_common_dev(), nbl_dev_start() and nbl_dev_stop(), which the driver core serializes against this path, and nbl_chan_send_ack() sends with ack = 0 and never sleeps. So no waiter can be stranded today.

Once netdev or ethtool paths start sending mailbox messages, would this also need the WRITE_ONCE(wait_head->acked, 1) plus wake_up() sequence that nbl_chan_teardown_queue() already does?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2 -0
@@ -234,3 +436,69 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
 		nbl_dev_remove_ctrl_dev(adapter);
 	nbl_dev_remove_common_dev(adapter);
 }
+
+/* ----------  Dev start process  ---------- */

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 450

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10 -0
+int nbl_dev_start(struct nbl_adapter *adapter)
+{
+	struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+	struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+	int cleanup_ret;
+	int ret;
+
+	ret = nbl_dev_cfg_msix_map(dev_mgt);
+	if (ret)
+		goto cfg_msix_map_err;

[Severity: High]
This is the first live caller of cfg_msix_map() / destroy_msix_map(), so the control PF now allocates per-function MSI-X state on behalf of the other PFs. Is there anything on the control PF side that ever releases that state?

On the control PF, nbl_res_intr_cfg_msix_map() allocates:

	tmp_msix_tbl->base_addr = dmam_alloc_coherent(dev, tmp_msix_tbl->size,
						      &tmp_msix_tbl->dma,
						      GFP_KERNEL);
	...
	tmp_interrupts = kcalloc(requested, sizeof(tmp_interrupts[0]), GFP_KERNEL);

stores both in intr_mgt->func_intr_res[func_id] and programs the hardware map with VALID=1. The only release path is nbl_res_intr_destroy_msix_map(), which for a peer function runs only when that peer PF executes its own nbl_dev_stop() and its DESTROY_MSIX_MAP mailbox request succeeds.

On the control PF side, nbl_intr_mgt_start() has no stop counterpart, nbl_res_remove_leonis() is a stub:

void nbl_res_remove_leonis(struct nbl_adapter *adap)

{
	/*
	 * No resource release here because all memory uses devm managed
	 * allocation
	 */
}

and nbl_dev_remove_ctrl_dev() only calls disp_ops->deinit_module().

Does unbinding or hot-removing the control PF while another PF is still bound leak the kcalloc()'d func_intr_res[].interrupts arrays? intr_mgt itself is devm_kzalloc()'d, so the pointers to those arrays look unreachable once devres frees it, and the comment above claims everything is devm managed.

In the same scenario, can the peer function be left with NBL_PCOMPLETER_FUNCTION_MSIX_MAP still VALID=1 pointing at the coherent table that devres just reclaimed together with the control PF, so a later interrupt from that function makes the device DMA-read freed memory? The peer's own DESTROY_MSIX_MAP request has no manager left at that point, and nbl_dev_stop() only logs the failure.

Quoted 38 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +38 -0
+
+	ret = nbl_dev_init_interrupt_scheme(dev_mgt);
+	if (ret)
+		goto init_interrupt_scheme_err;
+	ret = nbl_dev_request_mailbox_irq(dev_mgt);
+	if (ret)
+		goto mailbox_request_irq_err;
+	ret = nbl_dev_enable_mailbox_irq(dev_mgt);
+	if (ret)
+		goto enable_mailbox_irq_err;
+
+	return 0;
+
+enable_mailbox_irq_err:
+	cleanup_ret = nbl_dev_disable_mailbox_irq(dev_mgt);
+	if (cleanup_ret)
+		dev_err(dev_mgt->common->dev,
+			"Failed to disable mailbox IRQ: %d\n", cleanup_ret);
+	nbl_dev_free_mailbox_irq(dev_mgt);
+	cancel_work_sync(&common_dev->clean_mbx_task);
+mailbox_request_irq_err:
+	nbl_dev_clear_interrupt_scheme(dev_mgt);
+init_interrupt_scheme_err:
+cfg_msix_map_err:
+	cleanup_ret = nbl_dev_destroy_msix_map(dev_mgt);
+	if (cleanup_ret)
+		dev_err(dev_mgt->common->dev,
+			"Failed to destroy MSI-X map: %d\n", cleanup_ret);
+	cancel_work_sync(&common_dev->clean_mbx_task);
+	return ret;
+}
+
+void nbl_dev_stop(struct nbl_adapter *adapter)
+{
+	struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+	struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+	int ret;
+

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 498

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10 -0
+	ret = nbl_dev_disable_mailbox_irq(dev_mgt);
+	if (ret)
+		dev_err(dev_mgt->common->dev,
+			"Failed to disable mailbox IRQ: %d\n", ret);
+	nbl_dev_free_mailbox_irq(dev_mgt);
+	nbl_dev_clear_interrupt_scheme(dev_mgt);
+	ret = nbl_dev_destroy_msix_map(dev_mgt);
+	if (ret)
+		dev_err(dev_mgt->common->dev,
+			"Failed to destroy MSI-X map: %d\n", ret);

[Severity: Medium]
Here a failure of nbl_dev_disable_mailbox_irq() is only logged and teardown carries on. On a non-control PF that helper is a mailbox RPC, nbl_disp_chan_set_mailbox_irq_req(), which can return -EREMOTEIO, -ETIMEDOUT or -ESHUTDOWN when the manager PF is unresponsive or already unbound.

It is also the only operation that clears MSIX_IDX and MSIX_IDX_VALID in NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id):

nbl_hw_leonis.c:nbl_hw_set_mailbox_irq() {
	data &= ~(NBL_MAILBOX_QINFO_MAP_MSIX_IDX_MASK |
		  NBL_MAILBOX_QINFO_MAP_MSIX_IDX_VALID_MASK);
}

So if that RPC fails, the mailbox queue stays armed to emit an MSI-X message while nbl_dev_free_mailbox_irq() and then pci_free_irq_vectors() run. Can that leave the device sending a vector with no handler behind it?

The remaining masking path is reached over the same mailbox channel:

nbl_interrupt.c:nbl_res_intr_destroy_msix_map() {
	for (i = 0; i < intr_num; i++) {
		hw_ops->cfg_msix_info(res_mgt->hw_ops_tbl->priv,
				      func_id, false, interrupts[i],
				      0, 0, 0, false);
	}
}

and its failure is likewise only logged, so when the channel is wedged nothing quiesces the interrupt source. Should stop fail loudly or use a local register write instead of the RPC for the masking step?

Separately, even on the success path nbl_dev_clear_interrupt_scheme() runs before nbl_dev_destroy_msix_map(), i.e. the kernel-side vectors are released while the device-side mapping is still valid. Was that ordering intended, given that only the (fallible) disable makes it safe?

The identical unwind in nbl_dev_start() under enable_mailbox_irq_err ignores both failures in the same way, so probe can fail with the MSI-X map and mailbox routing still armed on the device.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +6 -0
+	/*
+	 * destroy_msix_map() sends ack-requested messages which may requeue
+	 * clean_mbx_task via polling send path. Drain work after the operation.
+	 */
+	cancel_work_sync(&common_dev->clean_mbx_task);
+}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260831021408.2325-1-illusion.wang%40nebula-matrix.com