nbl driver for Nebulamatrix NICs
Subsystems (4)
illusion.wang
maintainerv28 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 v27->v28
Link to v27:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v26->v27
Link to v26:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v25->v26
Link to v25:https://lore.kernel.org/netdev/[email protected]/ 1.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 | 32 + drivers/net/ethernet/nebula-matrix/Makefile | 6 + .../net/ethernet/nebula-matrix/nbl/Makefile | 15 + .../nbl/nbl_channel/nbl_channel.c | 1331 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 171 +++ .../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 | 571 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 695 +++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 25 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 1172 +++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 334 +++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 365 +++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 75 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 591 ++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 152 ++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 110 ++ .../nbl/nbl_include/nbl_def_channel.h | 183 +++ .../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 | 82 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 54 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 243 +++ 36 files changed, 6867 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
illusion.wang
maintainerPATCH v28 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.
Note: the documentation describes the final full driver features; implementation will be added in subsequent patches of this series.
--- .../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 | 32 ++++++ 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, 212 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
@@ -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
@@ -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 (marketed as SNIC s1000) is a series +of network interface cards for the Data Center Area. + +This driver provides the core infrastructure for m18110/m18000-NIC +devices, including: + +- PCI device enumeration and resource (BAR) management +- Firmware command interface via PF mailbox +- Channel-based communication between driver and firmware +- Device initialization and teardown + +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
@@ -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
@@ -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
@@ -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 +32 -0
@@ -0,0 +1,32 @@ +# 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 provides the core infrastructure for Nebula-matrix + Ethernet Controller m18110/m18000 Family of devices, including + PCI enumeration, firmware mailbox and channel communication. + + 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
@@ -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
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 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] At this commit only, the user-facing artifacts describe functionality that the added code does not contain: CONFIG_NBL help…
--
net/nebula-matrix: add minimum nbl build framework
This adds the Kconfig, Makefile, MAINTAINERS entry and documentation for a new nebula-matrix ethernet driver, plus a PCI driver skeleton whose probe and remove callbacks are empty stubs. The commit message notes that the real implementation follows in later patches of the series.
Quoted 6 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +0
-0@@ -0,0 +1,28 @@
[ ... ]
Quoted 7 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +7
-0+This driver provides the core infrastructure for m18110/m18000-NIC +devices, including: + +- PCI device enumeration and resource (BAR) management +- Firmware command interface via PF mailbox +- Channel-based communication between driver and firmware +- Device initialization and teardown
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +0
-0@@ -0,0 +1,32 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/Kconfig line 24
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +7
-0+config NBL + tristate "Nebula-matrix Ethernet Controller m18110/m18000 support" + depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN + help + This driver provides the core infrastructure for Nebula-matrix + Ethernet Controller m18110/m18000 Family of devices, including + PCI enumeration, firmware mailbox and channel communication.
[Severity: Low]
This isn't a bug, but the commit message says:
Note: the documentation describes the final full driver features; implementation will be added in subsequent patches of this series.
That disclaimer covers nbl.rst, but the CONFIG_NBL help text makes the same claims ("PCI enumeration, firmware mailbox and channel communication") and isn't mentioned. At this commit nbl_probe() just returns -ENODEV and nbl_remove() is empty, so none of the described infrastructure exists yet.
Would it make sense to either extend the note to cover the Kconfig help text, or move the feature list into the patch that actually adds the enumeration, mailbox and channel code?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +0
-0@@ -0,0 +1,100 @@
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +9
-0+static int nbl_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +return -ENODEV ; +} + +static void nbl_remove (struct pci_dev *pdev) +{ +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 87
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +6
-0+ { PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18000_LX_BASE_T_OCP), + .driver_data = BIT(NBL_CAP_HAS_NET_BIT) }, +/* required as sentinel */ + { } +}; +MODULE_DEVICE_TABLE (pci, nbl_id_table);
[Severity: Low]
This isn't a bug either, just an observation about the intermediate state. The full 16-entry nbl_id_table plus MODULE_DEVICE_TABLE(pci, nbl_id_table) publishes udev autoload aliases for 1f0f:3403-3412 at a point where every match is rejected:
nbl_probe()
return -ENODEV;
So a kernel built exactly at this commit with CONFIG_NBL=m will autoload nbl on a present m18110/m18000 card and log a probe failure for each matching function, with the device left unbound. Nothing is allocated before the -ENODEV return, so there is no leak, but it is visible during a bisect of this series.
Would it be cleaner to add the id table (or the driver registration) in the patch where nbl_probe() gains a working implementation, keeping every commit in the series functional?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 2/10 net/nebula-matrix: add core driver architecture and HW layer initialization
In reply to illusion.wangFrom: 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.
Note:
This commit binds the PCI device during probe, but does not create or register netdev. Netdev support will be added in later patches of this series. This intermediate state is safe: hardware BARs are mapped. Chip configuration and the mailbox control path are brought up by this series, and Ethernet data path RX/TX queues plus data-plane interrupts remain unconfigured and disabled at this stage.
--- .../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 | 153 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 15 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 31 ++++ .../nbl/nbl_include/nbl_def_common.h | 31 ++++ .../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
@@ -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
@@ -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 +153 -0
153 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h new file +15 -0
@@ -0,0 +1,15 @@ +/* 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" + +#define NBL_BAR2_MAX_LEN 0x300 +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +31 -0
@@ -0,0 +1,31 @@ +/* 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 mailbox_bar_size; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +31 -0
@@ -0,0 +1,31 @@ +/* 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; +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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 net-next 02/10] net/nebula-matrix: add core driver architecture and HW layer initialization
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: 0 · Medium: 2 · Low: 1
- [Medium] nbl_probe() starts claiming every device in nbl_id_table() from this patch onwards (patch 1 of the series deliberately returned…
- [Medium] nbl_get_func_param() grants the chip-global management role solely from host/guest-visible PCI topology: `if…
- [Low] The constant NBL_BAR2_MAX_LEN (nbl_hw_leonis.h) is named as the *maximum* mailbox BAR length (0x300) but nbl_hw_init_leonis() uses it…
--
net/nebula-matrix: add core driver architecture and HW layer initialization
This patch adds the nbl_adapter/nbl_core/nbl_common_info device context, turns nbl_probe() into a real probe that enables the device and maps the Leonis BARs, and adds the capability parsing that decides whether a function gets the chip-global control role.
A few questions below about the commit message wording and about how has_ctrl and NBL_BAR2_MAX_LEN are used.
Quoted 4 lines
Note:
This commit binds the PCI device during probe, but does not create or register netdev. Netdev support will be added in later patches of this series.
[Severity: Medium]
Is this accurate for the series as posted? Grepping the driver directory at the tip of the series for register_netdev, alloc_etherdev or netdev returns no matches, so no network interface appears to be created in any of the following patches.
Quoted 1 line
From this patch onward
nbl_probe()claims every ID innbl_id_table(),
enables bus mastering, maps the BARs, and (on the control function) programs chip-global registers, but returns success without providing a netdev or any other user-visible interface:
adapter = nbl_core_init(pdev, ¶m); ... pci_set_drvdata(pdev, adapter); return 0;
Would it be better to either keep the -ENODEV stub until the netdev patch lands, or reword this note so it does not promise a netdev that the series does not add?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +0
-0@@ -0,0 +1,153 @@
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +3
-0+if (common->has_ctrl) { +/* +* Hardware layout: MEMORY BAR total size is 64M.
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +7
-0+ hw_size =PAGE_ALIGN_DOWN (NBL_MEM_BAR_TOTAL_SIZE - +NBL_RDMA_NOTIFY_LEN ); + hw_mgt->hw_addr = +pcim_iomap (pdev,NBL_MEMORY_BAR , + hw_size); + }else { +if (bar_len <NBL_REG_NET_ONLY_LEN ) {
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +4
-0+ hw_size =NBL_REG_NET_ONLY_LEN ; + hw_mgt->hw_addr =pcim_iomap (pdev,NBL_MEMORY_BAR , + hw_size); + }
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 131
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +8
-0+if (bar_len <NBL_BAR2_MAX_LEN ) { +dev_err (&pdev->dev,"MAILBOX BAR length %pa too small\n" , + &bar_len); + ret = -EINVAL ; + goto setup_mgt_fail; + } + hw_mgt->mailbox_bar_hw_addr =pcim_iomap (pdev,NBL_MAILBOX_BAR , + bar_len);
[Severity: Low]
This isn't a bug, but the constant name and its use disagree. NBL_BAR2_MAX_LEN reads as a maximum, while the test here treats it as the minimum required register extent:
if (bar_len < NBL_BAR2_MAX_LEN) ... -EINVAL;
The mapping and the recorded window size then use the full advertised BAR length rather than the constant:
hw_mgt->mailbox_bar_hw_addr = pcim_iomap(pdev, NBL_MAILBOX_BAR, bar_len); ... hw_mgt->mailbox_bar_size = bar_len;
Could the constant be renamed to something like NBL_BAR2_MIN_LEN or NBL_BAR2_REG_LEN, or alternatively the pcim_iomap() length and mailbox_bar_size clamped to it?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0@@ -8,16 +8,108 @@
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8
-0+static void nbl_get_func_param (struct pci_dev *pdev,kernel_ulong_t driver_data, +struct nbl_init_param *param) +{ + param->caps.has_net = !!(driver_data &BIT (NBL_CAP_HAS_NET_BIT )); + +/* +* Hardware fixed rule: physical PF0 is the only management PF with +* global ctrl capability. All PFs share identical PCI device ID, so
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 68
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+* distinguish control PF via physical function ID. +* +* Hardware & firmware design FORBID passing any PF through to virtual +* machines, there is no scenario where a non-management PF appears +* as Func 0 inside guest. Thus using PCI_FUNC(pdev->devfn) to identify +* control PF is safe on our platform. +*/ +if ((PCI_FUNC (pdev->devfn) ==0 ) && !pdev->is_virtfn) + param->caps.has_ctrl =1 ; +}
[Severity: Medium]
Is PCI topology a sufficient source for the chip-global control role?
The comment states that hardware and firmware forbid passing a PF through to a VM, but nothing in the kernel enforces that. A host admin can bind vfio-pci to any of these PFs; inside the guest pdev->is_virtfn is 0 and VMMs commonly place the first assigned function at devfn 0x00, so:
if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn) param->caps.has_ctrl = 1;
is satisfied for a non-management PF.
has_ctrl then selects privileged, chip-wide behaviour. In nbl_hw_init_leonis() it picks the ~64 MiB global register window instead of the 8 KiB net-only window:
if (common->has_ctrl) {
...
hw_size = PAGE_ALIGN_DOWN(NBL_MEM_BAR_TOTAL_SIZE -
NBL_RDMA_NOTIFY_LEN);Later in the series it also gates nbl_res_start() -> nbl_res_init_pf_num() / nbl_intr_mgt_start(), which read global registers and own MSI-X map entries of remote PFs, and nbl_dev_init() -> nbl_dev_setup_ctrl_dev(), which programs chip-wide datapath registers and the mailbox qinfo routing table for every PF. nbl_res_remove_leonis() acknowledges this with "the control PF, which may hold maps for remote PFs that are still bound".
Could the control role be derived from a firmware/hardware identity read (and default to non-ctrl when that read is unavailable), rather than from devfn? Whether the ASIC actually filters BAR0 writes from a non-management function to the global blocks is not visible from the source here, so it would help to have that stated explicitly.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +2
-1+static int nbl_probe (struct pci_dev *pdev,const struct pci_device_id *id) { -return -ENODEV ; +struct nbl_init_param param = { {0 } };
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +14
-0+nbl_get_func_param (pdev, id->driver_data, ¶m); +/* never return fail when DMA_BIT_MASK(64) */ +dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 )); + +pci_set_master (pdev); + + adapter =nbl_core_init (pdev, ¶m); +if (IS_ERR (adapter)) { +dev_err (dev,"Nbl adapter init fail: %pe\n" , adapter); + err =PTR_ERR (adapter); + goto adapter_init_err; + } +pci_set_drvdata (pdev, adapter); +return 0 ;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 3/10 net/nebula-matrix: add channel layer
In reply to illusion.wangFrom: 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 per-hw_mgt reg_lock to protect read-modify-write sequences on the general-purpose register BAR (hw_addr, BAR0), such as QINFO map table entries and k_pf_mask reads
- Mailbox BAR2 register access is intentionally left unlocked: single dword mailbox writes are atomic, and the multi-dword QINFO config sequence (config_mailbox_txq/rxq, stop_mailbox_txq/rxq) only runs during queue setup/teardown when chan_info->active is false, with no concurrent producers. TX tail_ptr doorbell updates are serialized by the per-queue txq_lock. Adding a global lock to the mailbox fast path was measured to cause CPU soft lockup under re-probe stress.
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 | 1331 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 171 +++ .../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 | 198 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 44 + .../nbl/nbl_include/nbl_def_channel.h | 126 ++ .../nbl/nbl_include/nbl_def_common.h | 18 + .../nbl/nbl_include/nbl_def_hw.h | 39 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 2230 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
@@ -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 +1331 -0
1,331 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +171 -0
171 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +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
@@ -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
@@ -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 +198 -0
225 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +42 -0
47 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +44 -0
62 lines not on this page · raw message
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
@@ -12,6 +12,7 @@#include "nbl_include.h" struct nbl_common_info { +struct workqueue_struct *wq;struct pci_dev *pdev;struct device *dev;u16 vsi_id;
@@ -28,4 +29,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 +39 -0
@@ -10,6 +10,45 @@struct nbl_hw_mgt ;struct nbl_adapter ; +struct nbl_hw_ops { +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, +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 +* @hw_mgt: hardware management context +* @pf_mask: output pointer for PF mask value +* +* k_pf_mask register rule: +* bit N == 0 -> PF#N enabled; bit N == 1 -> PF#N masked out. +* bit0 is PF0's mask bit (not reserved); PF0 can be masked but +* the driver requires at least PF0 enabled. +* Only 1/2/4 PFs are supported: +* 1 PF (PF0): mask = 0xfe +* 2 PFs (PF0,PF1): mask = 0xfc +* 4 PFs (PF0~PF3): mask = 0xf0 +* All-zero mask (0x00) means all 8 PFs enabled, which is +* unsupported by the driver and rejected with -EINVAL. +* +* Firmware contract: number of unmasked PFs MUST equal +* get_board_info()->eth_num. +*/ +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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 net-next 03/10] net/nebula-matrix: add channel layer
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 12 potential issue(s) to consider:
Critical: 0 · High: 2 · Medium: 3 · Low: 7
- [High] nbl_chan_quiesce_and_reclaim_tx() calls hw_ops->flush_write() unconditionally from the generic channel layer.
- [High] In the interrupt-driven ACK wait of nbl_chan_send_msg(), when wait_event_timeout() returns 0 the code takes pending_lock and only…
- [Medium] The commit message justifies leaving the mailbox BAR2 register path unlocked with the invariant "the multi-dword QINFO config…
- [Medium] nbl_chan_teardown_queue() converts a failed inflight-TX drain into a return value (-ETIMEDOUT) but continues the teardown…
- [Medium] nbl_chan_teardown_queue() never acquires chan_info->txq_lock; it relies solely on atomic_read(&chan_info->inflight_tx_cnt) == 0 for…
- [Low] Reported concern: nbl_chan_setup_queue() re-allocates all ring/wait/buffer memory (dmam_alloc_coherent + devm_kcalloc, ~2 MiB of…
- [Low] Reported concern: at this commit none of the published channel ops (setup_queue, teardown_queue, send_msg, send_ack,…
- [Low] Reported concern: the exported ops do not validate chan_info->active, so a send before (or after a failed)…
- [Low] Reported concern: nbl_common_get_hash_node() returns the handler data pointer after dropping the per-bucket spinlock and…
- [Low] Reported concern: nbl_chan_remove_common() never asserts QUEUE_RST, so the mailbox TX/RX queues could stay enabled (QUEUE_EN)…
- [Low] Reported concern: chan_info->active/shutdn and the state bitmap are documented as guarded by state_lock, but…
- [Low] Reported concern: in nbl_chan_update_txqueue()'s external-buffer path (arg_len > NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN) the payload copy…
--
net/nebula-matrix: add channel layer
This adds the generic mailbox channel layer for the Nebula Matrix adapter:
message handler hash table, TX/RX descriptor ring setup and teardown, the synchronous send-and-wait-for-ACK path, and a small hardware abstraction layer for the mailbox registers. A few questions below, mostly around the TX timeout recovery path and the interrupt-driven ACK wait.
Quoted 7 lines
From the changelog:
- Mailbox BAR2 register access is intentionally left unlocked: single dword mailbox writes are atomic, and the multi-dword QINFO config sequence (config_mailbox_txq/rxq, stop_mailbox_txq/rxq) only runs during queue setup/teardown when
chan_info->activeis false, with no concurrent producers.
[Severity: Medium]
Does the code still match this description?
nbl_chan_quiesce_and_reclaim_tx() runs stop_mailbox_txq() followed by the full 4-dword config_mailbox_txq() sequence (through nbl_chan_config_queue()) from the TX timeout path of nbl_chan_kick_tx_ring(), which is only reachable from nbl_chan_send_msg() on a channel where active is true.
nbl_chan_teardown_queue() also calls nbl_chan_stop_queue() while active is still true; it is cleared only afterwards.
Should the changelog also describe the new TX timeout recovery behaviour? nbl_chan_quiesce_and_reclaim_tx() resets next_to_use, next_to_clean and tail_ptr to 0 on a live queue and re-enables it, which is not mentioned anywhere in the commit message.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1331 @@
[ ... ]
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 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+ 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 ; + }else { + ret =0 ; + }
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 373
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-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; +}
[Severity: Medium]
When the drain times out, teardown continues anyway: it stops the hardware, cancels the cleanup work and clears active even though inflight_tx_cnt is still non-zero.
The comment above this wait says "callers must not access queue resources while an inflight sender may still be active", but is there anything that enforces it? Later in the series the only caller, nbl_dev_remove_chan_queue() from nbl_dev_remove_common_dev(), discards the return value and the remove path proceeds to detach, where devres releases the dmam_alloc_coherent() descriptor rings and buffers and the devm_kcalloc() wait array.
A surviving sender is still polling that memory:
nbl_chan_kick_tx_ring()
if (le16_to_cpu(READ_ONCE(tx_desc->flags)) & BIT(NBL_CHAN_TX_DESC_USED))
and nbl_chan_send_msg() still reads wait_head->acked / ack_data_len. Can this end up as a use-after-free of the coherent ring and the wait array, with the device still writing into freed pages?
[Severity: Medium]
A second question about the same path: teardown never takes chan_info->txq_lock, it relies only on inflight_tx_cnt reaching zero. After the drain timeout, can this interleave?
CPU0, in nbl_chan_send_msg() holding txq_lock:
nbl_chan_kick_tx_ring() /* 100 polling iterations expired */ nbl_chan_quiesce_and_reclaim_tx() hw_ops->stop_mailbox_txq(hw_priv); ... nbl_chan_config_queue(chan_mgt, chan_info, true); /* QUEUE_EN=1 */
CPU1, in nbl_chan_teardown_queue() after the 5s wait expired:
nbl_chan_stop_queue(chan_mgt); /* no txq_lock */ WRITE_ONCE(chan_info->active, false);
If CPU1's stop lands before CPU0's re-config, does the mailbox TX queue end up armed again after teardown declared the channel inactive, pointing at rings that devres is about to free? This is also two concurrent writers of the same BAR2 QINFO block, which is the case the changelog says cannot occur.
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+static int nbl_chan_setup_queue (struct nbl_channel_mgt *chan_mgt,u8 chan_type) +{ +struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type]; +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = chan_mgt->common; +struct nbl_chan_ring *rxq = &chan_info->rxq; +int err; + +if (READ_ONCE (chan_info->active)) { +dev_warn (common->dev,"channel already active, reject duplicate setup\n" ); +return -EBUSY ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 395
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+ } +nbl_chan_init_queue_param (chan_info,NBL_CHAN_QUEUE_LEN , +NBL_CHAN_QUEUE_LEN ,NBL_CHAN_BUF_LEN , +NBL_CHAN_BUF_LEN ); + err =nbl_chan_init_queue (common, chan_info); +if (err) +return err; + err =nbl_chan_alloc_all_bufs (chan_mgt, chan_info); +if (err) +return err;
[Severity: Low]
This isn't reachable today, but the one-shot lifecycle the changelog describes ("DMA buffers are allocated once in probe phase ... dynamic runtime queue reinit is not supported") does not seem to be enforced by anything except the active flag.
nbl_chan_teardown_queue() releases none of the dmam_alloc_coherent() or devm_kcalloc() allocations and only clears active, so a
setup -> teardown -> setup sequence on the same chan_info would redo every allocation (roughly 2 MiB of coherent DMA) and orphan the previous set until device detach. Would it be worth making teardown_queue refuse to re-open the setup path, or documenting the constraint in the ops prototypes?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 484
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+static void nbl_chan_quiesce_and_reclaim_tx (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *hw_priv = chan_mgt->hw_ops_tbl->priv; +struct nbl_chan_ring *txq = &chan_info->txq; +struct nbl_chan_tx_desc *tx_desc; + +/* Assert QUEUE_RST to stop hardware fetching new descriptors */ + hw_ops->stop_mailbox_txq (hw_priv); + hw_ops->flush_write (hw_priv);
[Severity: High]
Is this flush_write() safe on functions other than PF0?
flush_write() is nbl_flush_writes(), which reads NBL_HW_DUMMY_REG (0x1300904, about 19.9 MiB into BAR0):
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h /*
* 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);
}But nbl_hw_init_leonis() only maps 8 KiB of BAR0 when has_ctrl is clear:
hw_size = NBL_REG_NET_ONLY_LEN; hw_mgt->hw_addr = pcim_iomap(pdev, NBL_MEMORY_BAR, hw_size);
and nbl_get_func_param() sets has_ctrl only forPCI_FUNC(pdev->devfn) == 0 && !pdev->is_virtfn.
So on PF1..PF3 (which do send mailbox messages later in the series), does nbl_chan_send_msg() -> nbl_chan_kick_tx_ring() -> quiesce path perform a readl() roughly 20 MiB past the end of the ioremap mapping when the device fails to set NBL_CHAN_TX_DESC_USED within NBL_CHAN_TX_WAIT_TIMES iterations (around 10 ms)? That is exactly the precondition the comment on nbl_flush_writes() states.
Should flush_write() be gated on common->has_ctrl, or bounds-checked the way nbl_hw_write_mbx_regs() already checks mailbox_bar_size?
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +15
-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); +/* +* Device failed to complete this descriptor. +* Quiesce the queue, reclaim the timed-out +* descriptor, and re-enable so future sends can +* proceed instead of stalling the ring full. +*/ +nbl_chan_quiesce_and_reclaim_tx (chan_mgt, + chan_info); +return -ETIMEDOUT ; + }
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +1
-0+while (!READ_ONCE (wait_head->acked)) {
[ ... ]
Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +19
-0+if (ret ==0 ) { +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 ); +WRITE_ONCE (wait_head->acked,0 ); +WRITE_ONCE (wait_head->ack_data,NULL ); +WRITE_ONCE (wait_head->ack_data_len,0 ); +/* +* Ensure all status/ack slot +* updates are visible before subsequent +* readers observe acked == 0 +*/ +smp_wmb (); + } +mutex_unlock (&chan_info->pending_lock); + dev_err_ratelimited(dev, + "Channel waiting ack failed, message type: %d, msg id: %u\n",
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 1046
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+ chan_send->msg_type, msgid); + ret = -ETIMEDOUT ; +/* +* TIMEOUT slots can be reused by another +* sender. The current sender no longer +* owns the slot after transitioning it to +* TIMEOUT. +*/ + goto out_clean_inflight; + }
[Severity: High]
What happens to the wait slot when the ACK arrives just as the 3s wait_event_timeout() expires?
wait_event_timeout() returns 0 only after its last condition check saw acked == 0. Between that check and the pending_lock acquisition here, nbl_chan_recv_ack_msg() can take pending_lock and publish:
WRITE_ONCE(wait_head->acked, 1); WRITE_ONCE(wait_head->status, NBL_MBX_STATUS_ACKD);
The sender then sees status == NBL_MBX_STATUS_ACKD, skips the WAITING-only fixup, sets ret = -ETIMEDOUT and jumps to out_clean_inflight, so out_clear_wait_slot / nbl_chan_reset_wait_head() is never reached for that slot.
nbl_chan_get_msg_id() only hands out slots in IDLE or TIMEOUT state:
if (status == NBL_MBX_STATUS_IDLE ||
status == NBL_MBX_STATUS_TIMEOUT) {Does that leak the slot permanently out of the 256-entry pool, so repeated occurrences eventually make every synchronous send return -EAGAIN? The caller also gets -ETIMEDOUT for a request whose ACK payload was already copied into its response buffer.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h struct nbl_hw_mgt { · line 68
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +10
-0+/* +* 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 ); +}
See the question above at nbl_chan_quiesce_and_reclaim_tx(): the new unconditional flush_write() call comes from the generic channel layer, which runs on every PF, so the has_ctrl precondition stated here no longer holds.
Thanks for looking at these.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
Jakub Kicinski
maintainerRe: [PATCH v28 net-next 03/10] net/nebula-matrix: add channel layer
In reply to illusion.wangQuoted 4 lines · On Mon, 14 Sep 2026 20:34:17 +0800 illusion.wang wrote:
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +4
-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_common/nbl_common.c line 46
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +10
-0+if (bucket_size ==0 || bucket_size ==1 ) +return 0 ; + + hash =jhash (key, key_size,0 ); + +/* Use bitmask if bucket_size is a power of 2 */ +if ((bucket_size & (bucket_size -1 )) ==0 ) +return hash & (bucket_size -1 ); +return hash % bucket_size; +}
I asked you to remove the hash table implementation, I think you only removed the hashing function. You should probably use Xarray here. Maybe rhashtable, but I don't really see why.
I will apply the first 2 patches to make the series a little shorter. Please don't take that as an invitation to add more patches to the series.
Also, if you have a good LLM you can try these prompts:
https://github.com/kuba-moo/ai-prompts/blob/main/driver-upstreaming-prompts.md
to generate the code for you. I used them with Opus 5 recently and the patches it produced only needed minor modifications. The split was excellent.
illusion.wang
maintainerPATCH v28 4/10 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
The Resource layer owns chip-agnostic resource entries and identity mappings, providing lookup and conversion helpers between VSI ID, func ID, eth ID and PF ID for upper dispatch and device layers.
This patch adds the common (chip-independent) resource layer:
- nbl_res_init_pf_num(): reads firmware k_pf_mask and validates the enabled PF topology. Only 1/2/4 contiguous PFs starting from PF0 are accepted; non-contiguous layouts, unsupported counts (0, 3, 5-8) and the all-zero mask (all 8 PFs enabled) are rejected with -EINVAL, causing probe to fail early.
- nbl_common_func_id_to_rel_pf_id(): translate absolute PF ID to relative PF index for resource table lookup.
- nbl_res_ctrl_dev_sriov_info_init(): derives each PF's BDF from the hardware bus number (read via get_real_bus) and the function offset, stored in sriov_info[] for MSI-X map programming.
- nbl_res_ctrl_dev_setup_eth_info(): validates that firmware port count (get_board_info()->eth_num) matches max_pf and the eth bitmap reported by get_fw_eth_map(), then builds the per-PF eth_id / logic_eth_id lookup tables.
- nbl_res_ctrl_dev_vsi_info_init(): assigns per-PF VSI base IDs. VSI ID gap is 1024 for 1 port, 512 for 2 ports, 256 for 4 ports respectively.
- Conversion helpers nbl_res_func_id_to_vsi_id(), nbl_res_vsi_id_to_pf_id() and nbl_res_get_eth_id() with full range and has_ctrl guards.
All initialization above runs only on the control PF (common->has_ctrl == true). Resource tables are built once during control PF probe and remain read-only afterwards, so lookup helpers require no internal locking.
The resource conversion helpers themselves do not include locking; all resource operations must be serialized by upper dispatch layer via ops_mutex_lock. Non-control PF requests are routed to control PF via mailbox RPC, and these helpers are only executed on control PF.
All resource allocations use devm managed memory, no explicit cleanup needed in remove path.
--- .../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 | 71 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 + .../nbl_hw_leonis/nbl_resource_leonis.c | 335 ++++++++++++++++++ .../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 | 72 ++++ .../nbl/nbl_include/nbl_def_channel.h | 10 + .../nbl/nbl_include/nbl_def_common.h | 20 ++ .../nbl/nbl_include/nbl_def_hw.h | 14 + .../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, 735 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
@@ -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
@@ -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
@@ -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 +70 -1
111 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +14 -0
@@ -53,5 +53,19 @@ 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) +#define NBL_BAR2_MAX_LEN 0x300#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +335 -0
335 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
@@ -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 +72 -0
72 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +10 -0
@@ -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 +20 -0
@@ -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;
@@ -24,9 +40,11 @@ struct nbl_common_info {u8 devid;u8 bus;u8 hw_bus; +u16 mgt_pf;u8 has_ctrl;u8 has_net; +u8 max_pf; };struct nbl_hash_tbl_key {
@@ -39,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 +14 -0
@@ -8,6 +8,7 @@#include <linux/types.h> +struct nbl_board_port_info ;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops {
@@ -40,9 +41,22 @@ struct nbl_hw_ops {* get_board_info()->eth_num. */ 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); +/** +* get_board_info - Fetch board info from firmware +* @hw_mgt: hardware management context +* @board_info: output pointer for board info structure +* +* Firmware contract: board_info.eth_num MUST equal the number of +* unmasked PFs from get_host_pf_mask(). See get_host_pf_mask for +* details. +*/ +void (*get_board_info)(struct nbl_hw_mgt *hw_mgt, +struct nbl_board_port_info *board_info); };struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 net-next 04/10] net/nebula-matrix: add common resource implementation
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 0 · Low: 2
- [Low] Misleading comment and (at this commit) write-only shared state in nbl_res_ctrl_dev_sriov_info_init(): the comment asserts that…
- [Low] Dead state in struct nbl_eth_info:
nbl_res_ctrl_dev_setup_eth_info() (drivers/net/ethernet/nebula-…
--
net/nebula-matrix: add common resource implementation
This patch adds the chip-independent resource layer for the nbl driver, including PF-count validation from the firmware k_pf_mask, per-PF BDF and VSI base-id tables, eth port discovery, and the VSI/func/eth/PF conversion helpers. All of the table setup runs only on the control PF during probe.
Two small observations below, both about state that has no reader at this point in the series.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +0
-0@@ -0,0 +1,335 @@
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +8
-0+/* +* Any subset of valid bitmap bits is accepted (e.g. 0/1, 0/2, +* 1/3, etc.). Firmware only needs to report the correct count +* of active ports; 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);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 121
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +10
-0+ eth_info->eth_id[eth_num] = i; + eth_info->logic_eth_id[i] = eth_num; + eth_num++; + } + } + +for (i =0 ; i < res_mgt->common->max_pf; i++) { + eth_id = eth_info->eth_id[i]; + eth_info->pf_bitmap[eth_id] |=BIT (i); + }
[Severity: Low]
This isn't a bug, but are eth_info->eth_bitmap, eth_info->logic_eth_id[] and eth_info->pf_bitmap[] ever read?
Grepping the driver with the whole series applied, the only appearances of these three members are the writes above plus the declaration in struct nbl_eth_info. eth_info->eth_id[] is the only member of the three tables that gets consumed, via nbl_res_get_eth_id().
The commit message describes this as building "the per-PF eth_id / logic_eth_id lookup tables", but nbl_res_get_eth_id() recomputes the logical id instead of reading the table it just built:
*eth_num = eth_info->eth_num; *eth_id = eth_info->eth_id[rel_pf_id]; *logic_eth_id = rel_pf_id;
The two derivations agree for every layout the code accepts, because max_pf == eth_num is enforced earlier, so the values are identical today. Would it be clearer to either return eth_info->logic_eth_id[*eth_id] here, or drop the unused members and the loops that fill them until a consumer shows up?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +2
-0+static int nbl_res_ctrl_dev_sriov_info_init (struct nbl_resource_mgt *res_mgt) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 154
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(), only executed +* on control PF path. +*/ + common->hw_bus = hw_bus;
[Severity: Low]
Can this comment be verified at this point in the series?
At this commit nothing reads common->hw_bus outside of the loop just below, and cfg_chan_qinfo_map_table() has no caller yet, so the ordering contract the comment documents cannot be checked against the tree here. The readers do arrive in the later patches of the series (nbl_res_intr_cfg_msix_map() passes common->hw_bus to cfg_msix_map(), and nbl_dev_setup_chan_qinfo() passes it to cfg_chan_qinfo_map_table()), and nbl_core_init() does call nbl_res_init_leonis() before nbl_disp_init() and nbl_dev_init(), so the ordering claim holds once the series is complete.
Would it make sense to move this comment to the patch that adds the cfg_chan_qinfo_map_table() call, so the referenced consumer exists in the same commit?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +0
-0@@ -0,0 +1,72 @@
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +8
-0+struct nbl_eth_info { + DECLARE_BITMAP(eth_bitmap, NBL_MAX_ETHERNET); +u8 pf_bitmap[NBL_MAX_ETHERNET ]; +u8 eth_num; +u8 resv[3 ]; +u8 eth_id[NBL_MAX_ETHERNET ]; +u8 logic_eth_id[NBL_MAX_ETHERNET ]; +};
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 5/10 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Introduce nbl_interrupt module to manage driver-wide global chip-internal MSI-X vector index space (intr_net_bmap / intr_other_bmap) and program the chip-internal MSI-X mapping registers.
This module manages hardware global vector indices, not the physical PCI MSI-X entries. Physical PCI MSI-X vector allocation via pci_alloc_irq_vectors is handled separately by the device layer; the corresponding entry point nbl_dev_init_interrupt_scheme() will be added in a later patch in this series.
Core interfaces:
1. cfg_msix_map
Allocates global hardware MSI-X indices from independent net/other interrupt bitmaps. The coherent DMA buffer for the function MSI-X map table is allocated once per function. Subsequent reconfigurations reuse the existing DMA buffer and avoid free/realloc cycles, removing the associated DMA race window and quiesce sleep on reconfigure.
Old hardware state is torn down only after all new allocations succeed to avoid interrupt loss. Writes the MSI-X table DMA address and control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP.
2. destroy_msix_map
Recycles global hardware vector indices, clears hardware MSI-X mappings, releases coherent DMA memory and interrupt descriptor array.
Step 0 disables mailbox IRQ routing before teardown; Step 1 masks each vector. Two-stage hardware teardown retains live DMA address while clearing VALID bit, then waits ~1ms for in-flight hardware DMA table fetch to quiesce (best-effort, no idle status register available). After quiesce, zero the table entry before freeing coherent memory.
3. set_mailbox_irq
Toggles mailbox MSI-X routing for a specific PF by updating NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured MSI-X map, so destroy_msix_map can safely clear routing before releasing vectors.
4. cfg_msix_info
Programs PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE. Hardware requires strict programming ordering: enable path writes MSIX_INFO then FID table; teardown uses reverse order to prevent inconsistent hardware state.
The interrupt manager owns a self-contained mutex (intr_mgt->lock) that protects the global vector bitmaps and per-function state. All public entry points (cfg/destroy/set_irq) take this lock internally; callers need not hold any upper-layer lock.
nbl_intr_mgt_stop() iterates all 520 function IDs and destroys any leftover MSI-X map (including maps for remote PFs configured via mailbox RPC), followed by a final global quiesce sleep. It is called from nbl_res_remove_leonis() before devres releases coherent tables.
This interrupt manager only supports PF; VF func_ids are not supported. nbl_res_func_id_to_bdf() returns -EOPNOTSUPP for function IDs outside PF range.
The manager is instantiated via nbl_intr_mgt_start() during resource initialization and attached to the resource management context.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 140 ++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 ++ .../nbl_hw_leonis/nbl_resource_leonis.c | 33 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 591 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 38 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../nbl/nbl_include/nbl_include.h | 1 + 12 files changed, 910 insertions(+), 5 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
@@ -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 +138 -2
173 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 +30 -3
@@ -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;
@@ -288,6 +293,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 ;
@@ -328,8 +337,26 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)void nbl_res_remove_leonis (struct nbl_adapter *adap) { +struct nbl_resource_mgt *res_mgt = adap->core.res_mgt; +struct nbl_common_info *common = &adap->common; + +if (!res_mgt) +return ; +/* -* No resource release here because all memory uses devm managed -* allocation +* Tear down all MSI-X maps before devres releases the coherent +* tables. This is critical on the control PF, which may hold +* maps for remote PFs that are still bound. +*/ +if (common->has_ctrl && res_mgt->intr_mgt) +nbl_intr_mgt_stop (res_mgt); + +/* Note: +* per-function interrupts arrays (kcalloc) are freed by +* nbl_intr_mgt_stop(). +* MSIX coherent tables are explicitly freed by dmam_free_coherent() +* inside the intr destroy path, before nbl_intr_mgt_stop() returns. +* intr_mgt itself (devm_kzalloc) is released by devres after this +* function returns */ }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -7,4 +7,5 @@#define _NBL_RESOURCE_LEONIS_H_#include "../nbl_resource.h" +#include "../nbl_interrupt.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +591 -0
591 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +21 -0
@@ -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 +32 -0
@@ -68,6 +68,38 @@ 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 >= common->max_pf) { +dev_err (common->dev, +"func_id=%u rel_pf_id=%u exceeds max_pf=%u, VF BDF unsupported\n" , + pfid, rel_pf_id, + common->max_pf); +return -EOPNOTSUPP ; + } + 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 +38 -0
@@ -17,6 +17,39 @@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 { +struct mutex lock;/* Protects bitmap + func_intr_res[] */ + 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;
@@ -59,14 +92,19 @@ 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); +void nbl_intr_mgt_stop (struct nbl_resource_mgt *res_mgt);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
@@ -12,6 +12,13 @@ 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);
@@ -45,6 +52,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 gvec);void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map);/** * get_board_info - Fetch board info from firmware
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
@@ -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
@@ -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 4enum {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v28 net-next 05/10] net/nebula-matrix: add intr resource implementation
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 6 · Low: 4
- [Medium] The changelog and the in-tree comment added by this patch both claim devres/managed ownership of the MSI-X map coherent buffer that…
- [Medium] The two-stage MSI-X map teardown does not implement the sequence the commit message and the hw-layer comment describe.
- [Medium] The comment added above nbl_hw_set_mailbox_irq() (nbl_hw_leonis.c:118-126) states that "nbl_hw_cfg_mailbox_qinfo()…
- [Medium] nbl_res_intr_cfg_msix_map() allocates the per-function coherent MSI-X map table (2 KiB: sizeof(struct nbl_msix_map) * 1024)…
- [Medium] On the reconfigure branch of nbl_res_intr_cfg_msix_map() (taken when func_intr_res[func_id].interrupts is already non-NULL) the…
- [Medium] In the reconfigure branch of nbl_res_intr_cfg_msix_map(), the old global hardware vector indices are returned to the shared…
- [Low] For a patch that creates drivers/net/ethernet/nebula- matrix/nbl/nbl_hw/nbl_interrupt.c from scratch, the changelog and the…
- [Low] In nbl_hw_leonis.h the descriptive comment "/* pcompleter_host pcompleter_host_virtio_qid_map_table */" is attached to…
- [Low] __nbl_res_intr_destroy_msix_map() drops intr_mgt->lock for a 1000-1200 us sleep between the prepare and complete teardown phases…
- [Low] nbl_intr_mgt_stop() clears res_mgt->intr_mgt with a plain store outside intr_mgt->lock (nbl_interrupt.c:590), while every public entry…
--
net/nebula-matrix: add intr resource implementation
This patch adds a new nbl_interrupt module that manages the chip-internal global MSI-X vector index space (intr_net_bmap / intr_other_bmap) and programs the related pcompleter/padpt mapping registers. It also adds the hardware helpers cfg_msix_map, cfg_msix_info and set_mailbox_irq, plus nbl_intr_mgt_start() / nbl_intr_mgt_stop() wiring into the leonis resource layer.
A few questions below about the teardown sequencing, an error path, and some comments that appear to describe something other than what the code does.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-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 126
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +9
-0@@ -101,6 +115,124 @@ 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); } +/* +* nbl_hw_set_mailbox_irq - read-modify-write NBL_MAILBOX_QINFO_MAP_REG_ARR +* +* The full RMW sequence is wrapped by reg_lock, so concurrent register +* access from different CPUs is already serialized safely. +* nbl_hw_cfg_mailbox_qinfo() overwrites the entire register during init, +* which unconditionally clears MSIX_IDX and MSIX_IDX_VALID bits, disabling +* mailbox MSIX interrupt routing for this PF. +*/
[Severity: Medium]
Does nbl_hw_cfg_mailbox_qinfo() really overwrite the entire register? As implemented in this same file it is a read-modify-write that clears only the BDF fields:
data &= ~(NBL_MAILBOX_QINFO_MAP_FUNCTION_MASK | NBL_MAILBOX_QINFO_MAP_DEVID_MASK | NBL_MAILBOX_QINFO_MAP_BUS_MASK);
NBL_MAILBOX_QINFO_MAP_MSIX_IDX_MASK is GENMASK(28, 16) and NBL_MAILBOX_QINFO_MAP_MSIX_IDX_VALID_MASK is BIT(29), i.e. they live in the same 32-bit word and are preserved rather than cleared.
If a previous driver instance never reached nbl_intr_mgt_stop() (crash, kexec, forced unload with no FLR), wouldn't MSIX_IDX_VALID survive init, so mailbox interrupts stay routed to a global vector index that this instance can hand to a different function via nbl_res_intr_cfg_msix_map()?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +3
-0+static void nbl_hw_set_mailbox_irq (struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool en_msix,u16 gvec) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +4
-0+static void nbl_hw_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) +{
[ ... ]
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +17
-0+ }else { +/* +* reg_lock prevents concurrent CPU writes to the same +* function's MSIX entry, but cannot synchronize hardware DMA +* reads. Upper layer uses two-stage destruction + sync sleep +* to avoid torn hardware read of partial MSIX entry. +* Keep valid live dma address here, only clear VALID flag. +*/ + function_msix_map.data[0 ] =lower_32_bits (dma_addr); + function_msix_map.data[1 ] =upper_32_bits (dma_addr); + function_msix_map.data[2 ] =0 ; + } + +nbl_hw_wr_regs_lock (hw_mgt, +NBL_PCOMPLETER_FUNCTION_MSIX_MAP_REG_ARR (func_id), + function_msix_map.data,sizeof (function_msix_map)); +}
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0
-0@@ -54,6 +54,48 @@ struct nbl_mailbox_qinfo_cfg_table {
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h struct nbl_mailbox_qinfo_cfg_table { · line 82
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +5
-0+/* -------- HOST_PCOMPLETER -------- */ +/* pcompleter_host pcompleter_host_virtio_qid_map_table */ +#define NBL_PCOMPLETER_FUNCTION_MSIX_MAP_REG_ARR (i) \ + (NBL_INTF_HOST_PCOMPLETER_BASE + 0x00004000 + \ + (i) * sizeof(struct nbl_function_msix_map))
[Severity: Low]
This isn't a bug, but the label says virtio_qid_map_table while the macro and struct describe the per-function MSI-X map table, and its only consumer nbl_hw_cfg_msix_map() writes the MSI-X table DMA address, control-PF BDF and VALID bit there. Is the comment a leftover from the virtio QID map block?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +0
-0
[ ... ]
Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +12
-2@@ -328,8 +337,26 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)void nbl_res_remove_leonis (struct nbl_adapter *adap) { +struct nbl_resource_mgt *res_mgt = adap->core.res_mgt; +struct nbl_common_info *common = &adap->common; + +if (!res_mgt) +return ; +/* -* No resource release here because all memory uses devm managed -* allocation +* Tear down all MSI-X maps before devres releases the coherent +* tables. This is critical on the control PF, which may hold +* maps for remote PFs that are still bound. +*/ +if (common->has_ctrl && res_mgt->intr_mgt) +nbl_intr_mgt_stop (res_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c int nbl_res_init_leonis(struct nbl_adapter *adap) · line 362
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +8
-0+ +/* Note: +* per-function interrupts arrays (kcalloc) are freed by +* nbl_intr_mgt_stop(). +* MSIX coherent tables are explicitly freed by dmam_free_coherent() +* inside the intr destroy path, before nbl_intr_mgt_stop() returns. +* intr_mgt itself (devm_kzalloc) is released by devres after this +* function returns */ }
[Severity: Medium]
Is the dmam_free_coherent() claim accurate? nbl_res_intr_cfg_msix_map() allocates the table with plain dma_alloc_coherent() and __nbl_res_intr_complete_destroy_msix_map() releases it with plain dma_free_coherent(). A grep for dmam_ in drivers/net/ethernet/nebula-matrix/ only turns up nbl_channel.c, so there does not appear to be any devres backstop for the MSI-X map table at all.
The changelog wording has the same assumption:
"It is called from nbl_res_remove_leonis() before devres releases
coherent tables."
Could both the comment and the changelog be reworded to say the table is unmanaged, since that distinction matters for the error path noted further down?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0@@ -0,0 +1,591 @@
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+/* Step 1: invalidate each MSIX info entry in hardware first */ +for (i =0 ; i < intr_num; i++) { + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func, false, interrupts[i], +0 ,0 ,0 , false); + } + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +/* Stage1 tear down: retain DMA address, only clear VALID bit */
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 156
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+ hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func, + false, + intr_mgt->func_intr_res[func].msix_map_table.dma, +0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +/* Stage2: zero MSIX map entry */ + hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func, + false,0 ,0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv);
[Severity: Medium]
The commit message describes this sequence as:
"Two-stage hardware teardown retains live DMA address while clearing
VALID bit, then waits ~1ms for in-flight hardware DMA table fetch to quiesce (best-effort, no idle status register available). After quiesce, zero the table entry before freeing coherent memory."
Here Stage1 and Stage2 are issued back-to-back with only a posted-write flush between them, and the usleep_range() runs afterwards in __nbl_res_intr_destroy_msix_map() and in nbl_intr_mgt_stop().
Does the "retain live DMA address" stage have any duration in practice? If a table fetch already latched VALID=1, would it not re-read the address words after Stage2 zeroed them, since nbl_hw_wr_regs_lock() writes data[0] and data[1] before data[2], and issue a DMA read at address 0 instead of the still-allocated table?
The same ordering applies to the hw layer comment in nbl_hw_cfg_msix_map(), which states the upper layer uses "two-stage destruction + sync sleep".
[ ... ]
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +13
-0+ interrupts = intr_mgt->func_intr_res[func_id].interrupts; +if (!interrupts) +return 0 ; + + intr_num = intr_mgt->func_intr_res[func_id].num_interrupts; + msix_map_table = &intr_mgt->func_intr_res[func_id].msix_map_table; + +nbl_intr_release_bitmap (res_mgt, interrupts, intr_num); + +if (msix_map_table->base_addr) { +dma_free_coherent (dev, msix_map_table->size, + msix_map_table->base_addr, + msix_map_table->dma);
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +7
-0+static int __nbl_res_intr_destroy_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +int ret; + +lockdep_assert_held (&intr_mgt->lock);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 231
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+ + ret =__nbl_res_intr_prepare_destroy_msix_map (res_mgt, func_id); +if (ret) +return ret; +mutex_unlock (&intr_mgt->lock); +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); +mutex_lock (&intr_mgt->lock); + +return __nbl_res_intr_complete_destroy_msix_map (res_mgt, func_id); +}
[Severity: Low]
The lock is dropped here for 1000-1200 us while __nbl_res_intr_prepare_destroy_msix_map() has deliberately left func_intr_res[func_id].interrupts, num_interrupts and msix_map_table populated, so the intermediate state looks identical to a live configuration. nbl_intr_mgt_stop() has the same split with the lock dropped across the global quiesce.
If nbl_res_intr_cfg_msix_map() could run for the same func_id inside that window, the completion phase would release the newly installed vectors back to the bitmaps and dma_free_coherent() a still-armed table.
Checking the callers, that does not seem reachable today: every res_ops->cfg_msix_map / destroy_msix_map / set_mailbox_irq call in nbl_dispatch.c is wrapped in mutex_lock(&disp_mgt->ops_mutex_lock) for the whole resource call, and nbl_intr_mgt_stop() runs from nbl_res_remove_leonis() only after nbl_dev_remove_common_dev() has done cancel_work_sync(&common_dev->clean_mbx_task) and removed the mailbox queue.
So the question is about the documented contract rather than a live race:
the kdoc of nbl_res_intr_cfg_msix_map() says this module "takes intr_mgt->lock internally to protect ... against concurrent callers" and the changelog says "callers need not hold any upper-layer lock", yet the teardown drops that lock mid-operation and correctness depends on disp_mgt->ops_mutex_lock. Could the dependency on the dispatch mutex be stated explicitly, or the intermediate state be marked so the completion phase can detect it?
[ ... ]
Quoted 5 lines
+/**
+ *nbl_res_intr_cfg_msix_map- allocate & program MSI-X mapping table
+ * @res_mgt: resource management instance
+ * @func_id: target function identifier
+ * @num_net_msix: required net data interrupt vectors
Quoted 8 lines
+ * @num_others_msix: required control interrupt vectors
+ * @net_msix_mask_en: enable mask for net interrupt entries
+ *
+ * Allocate interrupt vectors; MSIX coherent DMA table is allocated once
+ * per function on first configuration, entries are updated in-place on
+ * subsequent reconfigurations. No free/realloc of DMA table on vector
+ * count changes. This removes the DMA table free/realloc cycle,
+ * per-reconfig timed sleep and the in-flight DMA race window.
[Severity: Low]
This isn't a bug, but this file is created by this patch, so what does "This removes the DMA table free/realloc cycle, per-reconfig timed sleep and the in-flight DMA race window" refer to? The changelog has the same phrasing:
"Subsequent reconfigurations reuse the existing DMA buffer and avoid
free/realloc cycles, removing the associated DMA race window and quiesce sleep on reconfigure."
Since there is no earlier in-tree implementation, could both be reworded as a plain description of the new behaviour rather than a delta? As written a reader may go looking for the commit being fixed.
Quoted 7 lines
+ *
+ * Serialization: this function takesintr_mgt->lockinternally to
+ * protect the global vector bitmaps and per-function state against
+ * concurrent callers.
+ *
+ * Return: 0 on success, negative errno on failure
+ */
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +15
-0+/* Allocate MSIX DMA table once per function */ +if (!official_tbl->base_addr) { + official_tbl->size = +sizeof (struct nbl_msix_map ) * +NBL_MSIX_MAP_TABLE_MAX_ENTRIES ; + official_tbl->base_addr =dma_alloc_coherent (dev, + official_tbl->size, + &official_tbl->dma, +GFP_KERNEL ); +if (!official_tbl->base_addr) { +dev_err (dev,"Failed to allocate DMA memory for MSIX table\n" ); + ret = -ENOMEM ; + goto release_vecs_unlock; + } + }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 366
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-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_unlock; + }
[Severity: Medium]
Does this path leak the coherent MSI-X map table? The 2 KiB buffer (sizeof(struct nbl_msix_map) * 1024) is stored in func_intr_res[func_id].msix_map_table before the vector loops run, but .interrupts is only swapped in on the success path. On the -EAGAIN branches release_vecs_unlock only releases the bitmap and frees tmp_interrupts:
release_vecs_unlock:
nbl_intr_release_bitmap(res_mgt, tmp_interrupts, allocated_cnt); kfree(tmp_interrupts); out_unlock: mutex_unlock(&intr_mgt->lock);
and both teardown helpers skip func_ids whose .interrupts is NULL:
__nbl_res_intr_complete_destroy_msix_map()
interrupts = intr_mgt->func_intr_res[func_id].interrupts; if (!interrupts) return 0; /* dma_free_coherent() never reached */
nbl_intr_mgt_stop()
if (intr_mgt->func_intr_res[func_id].interrupts) {Combined with the unmanaged dma_alloc_coherent() noted earlier, wouldn't that buffer stay allocated across unbind and module unload?
The bitmap exhaustion branch looks reachable from a peer PF:nbl_disp_chan_cfg_msix_map_resp() passes num_net_msix / num_others_msix straight from the mailbox payload, each bounded only by NBL_MSIX_MAP_TABLE_MAX_ENTRIES (1024), while NBL_MAX_OTHER_INTERRUPT is also 1024, so two large "others" requests exhaust intr_other_bmap.
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+if (intr_mgt->func_intr_res[func_id].interrupts) { + old_interrupts = intr_mgt->func_intr_res[func_id].interrupts; + old_num = intr_mgt->func_intr_res[func_id].num_interrupts; + + ret =__nbl_res_intr_set_mailbox_irq (res_mgt, func_id,0 , + false); +if (ret) { +dev_err (dev,"%s: disable old mailbox irq failed, keep old config\n" , + __func__);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 411
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+ goto release_vecs_unlock; + } +for (j =0 ; j < old_num; j++) { + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, false, old_interrupts[j], +0 ,0 ,0 , false); + } + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); +nbl_intr_release_bitmap (res_mgt, old_interrupts, old_num); +kfree (old_interrupts);
[Severity: Medium]
The old global vector indices go straight back into the shared intr_net_bmap / intr_other_bmap here, with no quiesce, while NBL_PCOMPLETER_FUNCTION_MSIX_MAP for this func_id is still VALID and its coherent table still contains those old indices (the table is only rewritten a few lines further down).
The destroy path treats the wait as mandatory before releasing anything ("waits ~1ms for in-flight hardware DMA table fetch to quiesce"). If the next cfg_msix_map() for a different func_id picks up one of these indices and programs NBL_PADPT_HOST_MSIX_INFO / NBL_PCOMPLETER_HOST_MSIX_FID_TABLE with that other function's BDF and FID, can a straggler fetch on behalf of the reconfigured func_id end up delivering into the other PF's vector space?
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +20
-0+ } + +/* Swap new vector array into func state */ + intr_mgt->func_intr_res[func_id].interrupts = tmp_interrupts; + intr_mgt->func_intr_res[func_id].num_interrupts = requested; + intr_mgt->func_intr_res[func_id].num_net_interrupts = num_net_msix; + tmp_interrupts =NULL ; + +/* +* Fill MSIX map table IN-PLACE in the pre-allocated DMA buffer. +* Only zero entries beyond requested count to avoid full table +* memset overhead. +*/ + msix_map_entries = official_tbl->base_addr; +memset (msix_map_entries + requested,0 , + (NBL_MSIX_MAP_TABLE_MAX_ENTRIES - requested) * +sizeof (*msix_map_entries)); + +for (i =0 ; i < requested; i++) { + gvec = intr_mgt->func_intr_res[func_id].interrupts[i];
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 444
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+ msix_map_entries[i].data = +cpu_to_le16 (FIELD_PREP (NBL_MSIX_MAP_VALID_MASK ,1 ) | +FIELD_PREP (NBL_MSIX_MAP_INDEX_MASK , + gvec)); + entry_masked = (i < num_net_msix && net_msix_mask_en); + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, true, gvec, + bus, devid, function, + entry_masked); + }
[Severity: Medium]
On the reconfigure branch this rewrites the coherent table while NBL_PCOMPLETER_FUNCTION_MSIX_MAP for func_id is still programmed VALID=1 with the same DMA address, since Phase2 above says:
* NOTE: NO DMA table free here, only invalidate HW entries and
* release vec bitmap.
The memset() and the per-entry stores go into that still-armed buffer, and dma_wmb() only comes afterwards. Also, for each i the entry is published pointing at gvec before cfg_msix_info() makes NBL_PADPT_HOST_MSIX_INFO[gvec] / NBL_PCOMPLETER_HOST_MSIX_FID_TABLE[gvec] valid, so a fetch in that window resolves entry i to a global vector whose info/FID entry was just zeroed in Phase2.
Should this path clear VALID and quiesce first, the way __nbl_res_intr_prepare_destroy_msix_map() does, given the hw layer comment says reg_lock "cannot synchronize hardware DMA reads"?
The reconfigure branch does look reachable: nbl_dev_stop() / nbl_dev_start() treat destroy_msix_map as best-effort, so a peer PF whose destroy RPC fails leaves the map installed and the next bind re-enters here with func_intr_res[func_id].interrupts non-NULL.
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +2
-0+void nbl_intr_mgt_stop (struct nbl_resource_mgt *res_mgt) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 591
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+mutex_unlock (&intr_mgt->lock); + + res_mgt->intr_mgt =NULL ; +}
[Severity: Low]res_mgt->intr_mgt is cleared with a plain store outside intr_mgt->lock, while every public entry point loads that pointer unsynchronized and only then locks the object it points at, for example in nbl_res_intr_cfg_msix_map():
struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; ... if (!intr_mgt) return -EINVAL; ... mutex_lock(&intr_mgt->lock);
No "stopping" state is published before the lock is dropped for the global quiesce, and there is no refcount or operation drain, so structurally a caller could latch the old pointer and then work on a stopped manager whose devm memory is released once remove returns.
I could not build a reachable case: all entry points run under disp_mgt->ops_mutex_lock, and nbl_intr_mgt_stop() is only reached from nbl_res_remove_leonis() after nbl_dev_remove_common_dev() has done cancel_work_sync(&common_dev->clean_mbx_task) and removed the mailbox queue, including on the nbl_core_init() failure paths. Is that external ordering the intended guarantee, and could it be noted next to the NULL store?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 6/10 net/nebula-matrix: add chip-wide hardware init/deinit implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add Leonis chip-wide hardware initialization and deinitialization logic to configure the datapath pipeline: packet processing engines, scheduler, buffer stores, queue manager, per-port traffic shaping and flow control. Also set 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
- dsch: Scheduler core (qid limit, VN quanta)
- ustore, dstore: Buffer Store modules
- dvn, uvn: Virtual Descriptor Network modules
- uqm: Queue Manager
- nbl_shaping_init(): Per-port traffic shaping + DSCH PSHA config
These routines only program datapath registers; full chip reset is handled by firmware.
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
3. nbl_hw_set_driver_status() + nbl_flush_writes()
Both nbl_res_chip_init_module() and nbl_res_chip_deinit_module() include an explicit has_ctrl guard for defense-in-depth, matching other resource ops. The dispatch layer only assigns these ops to NBL_DISP_CTRL_LVL_MGT.
Deinit notes:
Firmware cleanup is asynchronous and there is no cleanup-done status register. Chip-wide registers programmed here are not automatically restored by firmware on deinit; they remain active until chip reset or explicitly overwritten. Callers must ensure no new DMA is started after deinit_module returns.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 618 +++++++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 221 +++++++ .../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, 915 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
@@ -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 +32 -0
@@ -0,0 +1,32 @@ +// 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; +struct nbl_common_info *common = res_mgt->common; + +if (!common->has_ctrl) +return ; + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +} + +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_common_info *common = res_mgt->common; +struct nbl_hw_ops *hw_ops; +u8 eth_speed, eth_num; +struct nbl_hw_mgt *p; + +if (!common->has_ctrl) +return -EINVAL ; + eth_speed = res_mgt->resource_info->board_info.eth_speed; + eth_num = res_mgt->resource_info->board_info.eth_num; + hw_ops = res_mgt->hw_ops_tbl->ops; + 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
@@ -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 +617 -1
636 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +221 -0
250 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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_QUIRK_NO_TOE – ABI defined, driver implementation pending +* BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch +* selection +*/ +#define NBL_QUIRK_NO_TOE BIT(0) +#define NBL_QUIRK_UVN_PREFETCH_ALIGN BIT(1) +#endif
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v28 net-next 06/10] net/nebula-matrix: add chip-wide hardware init/deinit 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: 0 · Medium: 3 · Low: 5
- [Medium] The doc comment above nbl_hw_deinit_module() (drivers/net/ethernet/nebula-…
- [Medium] Chip-wide teardown is tied to a single PF's unbind with no interlock.
- [Medium] Three chip registers whose only documented fields are narrow bitfields are programmed with a blind full-word write built from zero,…
- [Low] The patch introduces an entirely new firmware ABI word (nbl_hw_get_quirks(), NBL_LEONIS_QUIRKS_OFFSET 0x140,…
- [Low] Concern that the ~600 lines of hardware programming and the two new ops in nbl_hw_ops/nbl_resource_ops have no caller at this commit,…
- [Low] nbl_dsch_qid_max_init() (nbl_hw_leonis.c:298-312), described in the changelog as "dsch: Scheduler core (qid limit, VN quanta)", also…
- [Low] In nbl_shaping_eth_init() (nbl_hw_leonis.c:210) depth = max_t(u32, rate * 2, NBL_LR_LEONIS_NET_BUCKET_DEPTH); can never…
- [Low] Two of the new register configuration sequences perform a read- modify-write while dropping hw_mgt->reg_lock between the read and the…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds the Leonis chip-wide init/deinit routines that program the datapath pipeline (packet editors, scheduler, buffer stores, queue manager, shaping and flow control) and the driver_status flag consumed by firmware. The new hw_ops.init_module/deinit_module and the matching resource_ops entries are registered here; the invocation path arrives in a later patch.
A few questions about the new code below.
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +6
-0@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include "nbl_chip.h"
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c line 16
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +10
-0+ +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = res_mgt->common; + +if (!common->has_ctrl) +return ; + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +}
[Severity: Medium]
This teardown is chip-wide but is triggered by a single PF instance unbinding. has_ctrl is set only for PCI function 0 in nbl_init_func_caps():
if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn)
param->caps.has_ctrl = 1;and nbl_res_chip_deinit_module() then reaches nbl_hw_set_driver_status(hw_mgt, false), which by this patch's own comment "notifies firmware to clean up per-PF hardware state such as qinfo registers" for every PF on the chip.
Each PF is an independent driver instance, so what happens when PF0 is unbound (or fails probe) while PF1..PF3 are still bound with live mailbox queues? Is there anything that keeps firmware from cleaning up their qinfo state underneath them?
The commit message says:
Callers must ensure no new DMA is started after deinit_module returns.
Can a per-PF caller actually enforce that on its siblings? A refcount over the chip-wide state, an ordering check, or at minimum a warning when siblings are still bound would make this enforceable in code rather than by convention.
Quoted 16 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +8
-0@@ -115,6 +115,618 @@ 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) +{ +u32 quirks =0 ; + +/* +* Read quirk bits from mailbox register. +* All supported firmware implement the quirk ABI, +* firmware always populates NBL_LEONIS_QUIRKS_OFFSET.
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 135
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+* Value ~0U indicates no active quirks. +*/ +nbl_hw_read_mbx_regs (hw_mgt,NBL_LEONIS_QUIRKS_OFFSET , &quirks, +sizeof (u32)); + +if (quirks == ~0u ) +return 0 ; + +return quirks; +}
[Severity: Low]
The changelog does not mention this new firmware ABI word at all, even though it changes chip-wide datapath programming. Could the quirk word be described in the commit message?
How is the claim "All supported firmware implement the quirk ABI" verified? There is no firmware version gating here, and only ~0U is treated as "no quirks", so any image that leaves something else at offset 0x140 with bit 1 set silently selects a different UVN prefetch mode in nbl_uvn_init():
FIELD_PREP(NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK,
(quirks & NBL_QUIRK_UVN_PREFETCH_ALIGN) ? 0 : 1);There is no log message when a quirk is applied, so an operator has no way to tell which prefetch mode the chip ended up in.
Also, NBL_QUIRK_NO_TOE has no consumer anywhere in the driver, including at the end of this series. Would it be better to add that define together with the code that uses it?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static int nbl_shaping_eth_init (struct nbl_hw_mgt *hw_mgt,u8 eth_id,u8 speed) +{
[ ... ]
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 210
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+ half_rate = rate /2 ; + depth =max_t (u32, rate *2 ,NBL_LR_LEONIS_NET_BUCKET_DEPTH );
[Severity: Low]
Can the NBL_LR_LEONIS_NET_BUCKET_DEPTH operand ever be selected here? nbl_hw_init_module() rejects anything outside {10G, 25G, 50G, 100G} through nbl_hw_eth_speed_valid(), so rate is one of 10000/25000/50000/100000 and rate * 2 is always at least 20000, which is greater than 9600.
Was a cap (min_t) intended instead, or is the 9600 constant expressed in a different unit than the "1 = 1 Mbit/s" rate unit documented in the header? depth feeds NBL_DPORT_DEPTH_MASK, the CBS halves and NBL_DPORT_PBS_MASK, so a unit mismatch here mis-programs the shaper silently.
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +11
-0+static int nbl_shaping_init (struct nbl_hw_mgt *hw_mgt,u8 speed) +{ +#define NBL_SHAPING_FLUSH_INTERVAL 128 +struct nbl_shaping_net_u net_shaping = {0 }; +u32 eth_bitmap =0 ; +u32 psha_en =0 ; +int ret; +int i; + +nbl_hw_get_fw_eth_map (hw_mgt, ð_bitmap); +for (i =0 ; i <NBL_MAX_ETHERNET ; i++) {
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 285
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+if (!(eth_bitmap &BIT (i))) +continue ; + ret =nbl_shaping_eth_init (hw_mgt, i, speed); +if (ret) +return ret; + } + psha_en = eth_bitmap &GENMASK (3 ,0 ); + psha_en =FIELD_PREP (NBL_DSCH_PSHA_EN_MASK , psha_en); +nbl_hw_wr_regs_lock (hw_mgt,NBL_DSCH_PSHA_EN_ADDR , &psha_en, +sizeof (psha_en));
[Severity: Medium]psha_en starts at 0 and only bits 3:0 are set (NBL_DSCH_PSHA_EN_MASK is GENMASK(3, 0)), yet the full 32-bit word is written without a prior read. Does this clobber bits 31:4 of NBL_DSCH_PSHA_EN_ADDR?
The same pattern shows up twice more in this patch:
nbl_dsch_qid_max_init():
nbl_hw_wr32(hw_mgt, NBL_DSCH_HOST_QID_MAX, NBL_MAX_QUEUE_ID);
nbl_ustore_init():
drop_th |= FIELD_PREP(NBL_USTORE_PORT_DROP_TH_EN_MASK, 1);
...
nbl_hw_wr_regs(hw_mgt, NBL_USTORE_PORT_DROP_TH_REG_ARR(i),
&drop_th, sizeof(drop_th));drop_th is built from 0 with only GENMASK(11, 0) and BIT(31) set, so bits 30:12 go to zero. That is in the same function that read-modify-writes NBL_USTORE_PKT_LEN_ADDR with the comment "(to preserve other fields while updating 'min')".
NBL_DSTORE_PORT_DROP_TH_REG(), NBL_DSTORE_DISC_BP_TH, NBL_DSTORE_D_DPORT_FC_TH_REG(), NBL_DPED_L4_CK_CMD_40_ADDR, NBL_UVN_DESC_WR_TIMEOUT and NBL_UVN_DIF_REQ_RO_FLAG are all read-modify- written in this patch. Should these three be as well, or do those words really contain nothing else?
Since deinit does not reprogram these registers, any firmware default destroyed here stays destroyed until chip reset.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5
-0+static void nbl_dsch_qid_max_init (struct nbl_hw_mgt *hw_mgt) +{ +u32 quanta =0 ; + + quanta = FIELD_PREP(NBL_DSCH_VN_QUANTA_H_QUA_MASK, NBL_HOST_QUANTA) |
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 312
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+FIELD_PREP (NBL_DSCH_VN_QUANTA_E_QUA_MASK ,NBL_ECPU_QUANTA ); +spin_lock (&hw_mgt->reg_lock); +nbl_hw_wr_regs (hw_mgt,NBL_DSCH_VN_QUANTA_ADDR , &quanta, +sizeof (quanta)); +nbl_hw_wr32 (hw_mgt,NBL_DSCH_HOST_QID_MAX ,NBL_MAX_QUEUE_ID ); + +nbl_hw_wr32 (hw_mgt,NBL_DVN_ECPU_QUEUE_NUM ,0 ); +nbl_hw_wr32 (hw_mgt,NBL_UVN_ECPU_QUEUE_NUM ,0 ); +spin_unlock (&hw_mgt->reg_lock); +}
[Severity: Low]
The changelog describes this helper as:
- dsch: Scheduler core (qid limit, VN quanta)
but it also programs NBL_DVN_ECPU_QUEUE_NUM and NBL_UVN_ECPU_QUEUE_NUM, which belong to the DVN and UVN blocks. nbl_dvn_init() and nbl_uvn_init() never touch them.
Would these two writes fit better in nbl_dvn_init() and nbl_uvn_init(), so that the per-module decomposition in the changelog matches the code?
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-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; +u32 reg_val; + +nbl_hw_rd_regs_lock (hw_mgt,NBL_DVN_DESCREQ_NUM_CFG , ®_val, +sizeof (reg_val)); +
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 446
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-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); + reg_val &= ~(NBL_DVN_DESCREQ_NUM_CFG_AVRING_DESREQ_NUM_CFG_MASK | +NBL_DVN_DESCREQ_NUM_CFG_PACKED_L1_NUM_MASK ); + reg_val |= num_cfg; +nbl_hw_wr_regs_lock (hw_mgt,NBL_DVN_DESCREQ_NUM_CFG , ®_val, +sizeof (reg_val)); +}
[Severity: Low]
Is reg_lock meant to cover this read-modify-write? Both helpers take and drop the lock themselves:
static void nbl_hw_rd_regs_lock(...)
{
...
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);
}so the sequence is lock/read/unlock ... lock/write/unlock and no lock is held while reg_val is modified. The same split appears in nbl_uvn_init() for NBL_UVN_DESC_PREFETCH_INIT.
Every other read-modify-write added by this patch holds reg_lock across the whole sequence (nbl_configure_dped_checksum(), nbl_uped_init(), nbl_dstore_init(), the first half of nbl_uvn_init(), nbl_hw_set_driver_status()), and the comment above nbl_hw_set_mailbox_irq() states "The full RMW sequence is wrapped by reg_lock". Since both writes preserve the register's other bits, would an interleaved writer lose its update here?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static void nbl_uvn_init (struct nbl_hw_mgt *hw_mgt) +{
[ ... ]
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +20
-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_QUIRK_UVN_PREFETCH_ALIGN is set, +* in which case override to sel=0. +*/ +nbl_hw_rd_regs_lock (hw_mgt,NBL_UVN_DESC_PREFETCH_INIT , + ®_val,sizeof (reg_val)); + 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 ); + reg_val &= ~(NBL_UVN_DESC_PREFETCH_INIT_NUM_MASK | +NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK ); + reg_val |= prefetch_init; +nbl_hw_wr_regs_lock (hw_mgt,NBL_UVN_DESC_PREFETCH_INIT , + ®_val,sizeof (reg_val)); +}
[ ... ]
Quoted 23 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +23
-0+static void nbl_hw_set_driver_status (struct nbl_hw_mgt *hw_mgt,bool active) +{ +u32 status; + +spin_lock (&hw_mgt->reg_lock); + status =nbl_hw_rd32 (hw_mgt,NBL_DRIVER_STATUS_REG ); + + status &= ~BIT (NBL_DRIVER_STATUS_BIT ); + status |=FIELD_PREP (BIT (NBL_DRIVER_STATUS_BIT ), active); + +nbl_hw_wr32 (hw_mgt,NBL_DRIVER_STATUS_REG , status); +spin_unlock (&hw_mgt->reg_lock); +} + +/* +* Setting driver status to false notifies firmware to clean up per-PF +* hardware state such as qinfo registers. +* +* Note: firmware does NOT automatically revert chip-wide registers +* configured in this init flow. Those chip-wide settings remain valid +* until chip reset or explicitly cleared by driver. +* +* For normal successful probe, driver will reset these chip-wide
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 667
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+* resources in subsequent deinit. For failed probe before +* driver_status is set to true, hardware may stay in partial +* programmed state. We validate all input parameters before touching +* hardware registers to avoid this scenario. +*/ +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: Medium]
Where does the reset promised by this comment happen?
For normal successful probe, driver will reset these chip-wide resources in subsequent deinit.
nbl_hw_deinit_module() only clears the driver_status bit and flushes posted writes. Nothing here or elsewhere in the series reverts what nbl_hw_init_module() programmed: the shaping DPORT/DVN_DPORT VALID bits, the USTORE pkt_len and port drop threshold enables, the DSTORE XON/XOFF plus FC_EN bits, the DSCH qid max and quanta, the DVN/UVN relaxed-ordering and prefetch fields, and the host padpt flow-control values.
This also reads the opposite way from the commit message:
Chip-wide registers programmed here are not automatically restored by firmware on deinit; they remain active until chip reset or explicitly overwritten.
Could the comment be corrected to match what the code does, so that the datapath being left programmed and enabled after unbind is documented rather than described as reset?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0
-0@@ -96,6 +120,202 @@ struct nbl_function_msix_map {
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +6
-0+/* --------- SHAPING --------- */ + +/* Shaping rate unit: 1 = 1 Mbit/s. +* e.g. 100000 = 100 Gbit/s, 25000 = 25 Gbit/s. +*/ +#define NBL_LR_LEONIS_NET_BUCKET_DEPTH 9600
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +0
-0@@ -30,4 +30,25 @@ struct nbl_init_param {
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +10
-0+/* +* Firmware quirk word @ NBL_LEONIS_QUIRKS_OFFSET (0x140) +* Sentinel value: ~0U (0xFFFFFFFF) = firmware reports no active quirks +* BIT(0): NBL_QUIRK_NO_TOE – ABI defined, driver implementation pending +* BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch +* selection +*/ +#define NBL_QUIRK_NO_TOE BIT(0) +#define NBL_QUIRK_UVN_PREFETCH_ALIGN BIT(1) +#endif
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 7/10 net/nebula-matrix: dispatch: add control-level routing core infrastructure
In reply to illusion.wangFrom: 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 | 124 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 ++++ .../nbl/nbl_include/nbl_def_channel.h | 41 ++++++ .../nbl/nbl_include/nbl_def_dispatch.h | 39 ++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 7 files changed, 238 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
@@ -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
@@ -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 +124 -0
124 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +23 -0
@@ -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 +41 -0
65 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +39 -0
@@ -0,0 +1,39 @@ +/* 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_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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 net-next 07/10] net/nebula-matrix: dispatch: add control-level routing core infrastructure
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 1
- [Medium] New channel response enum (NBL_CHAN_RESP_OK/ERR/UNIMPLEMENTED, extended with PERM_DENY later in the series) uses positive wire…
- [Low] The comment in the (empty) nbl_disp_remove() bases dispatch teardown safety on facts that do not exist at this commit: it says…
--
net/nebula-matrix: dispatch: add control-level routing core infrastructure
This adds the dispatch layer skeleton: allocation of the dispatch management structure and ops table, init_module/deinit_module wrappers around the resource ops, and a ctrl_lvl bitmask that enables the MGT level on the Control PF only. It also adds forward declarations of channel wire structures and a channel response enum for a later RPC framework.
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +1
-0@@ -7,12 +7,19 @@#define _NBL_DEF_CHANNEL_H_#include <linux/types.h> +#include <linux/build_bug.h> struct nbl_channel_mgt ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h line 22
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +6
-0struct 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 , +}; +
[Severity: Medium]
Can these positive response codes ever be observed by a sender? The ACK receive path in nbl_chan_recv_ack_msg() rewrites any positive remote status:
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c:
raw_err = (s32)le32_to_cpu(*(__le32 *)&payload[NBL_CHAN_ACK_RET_POS]); if (raw_err > 0 || raw_err < -MAX_ERRNO) raw_err = -EREMOTEIO; WRITE_ONCE(wait_head->ack_err, raw_err);
nbl_chan_send_msg() returns exactly that clamped value, so a caller can only ever see 0 or a negative errno, never NBL_CHAN_RESP_ERR (1) or NBL_CHAN_RESP_UNIMPLEMENTED (2).
The follow-up patch in the series ("net/nebula-matrix: dispatch:
implement channel RPC framework and serialize hardware ops") both puts these codes on the wire via nbl_disp_chan_*_resp() -> nbl_chan_fill_ack_info(..., err, ...) and then switches on them after send_msg(), for example in nbl_disp_chan_get_eth_id_req():
ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
if (ret < 0)
return ret;
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;Are all the non-OK arms dead code, given "if (ret < 0) return ret;" fires first for the clamped -EREMOTEIO? A peer answering "unimplemented" or "permission denied" would then be reported to the requester as -EREMOTEIO instead of -EOPNOTSUPP / -EPERM.
Would it make sense to either encode these response codes as non-positive values (or in a dedicated payload field), or to let the clamp in nbl_chan_recv_ack_msg() pass the defined response codes through?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +0
-0@@ -0,0 +1,124 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 124
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +11
-0+void nbl_disp_remove (struct nbl_adapter *adapter) +{ +/* +* All dispatch objects are allocated via devm. +* Dispatch message handlers are not explicitly unregistered here. +* Safety relies on dev layer shutting down mailbox channel queue +* before nbl_res_remove_leonis(), so responders cannot run after +* resource layer is torn down. Channel layer nbl_chan_remove_common() +* finalizes cleanup at device teardown. +*/ +}
[Severity: Low]
This isn't a bug, but does this comment describe code that exists at this commit?
There is no dev layer yet (no nbl_core/nbl_dev.o in the Makefile and no nbl_dev_init()/nbl_dev_remove() call in nbl_main.c), so nothing shuts down the mailbox channel queue before nbl_res_remove_leonis().
This patch also registers no channel handlers at all (no chan_ops->register_msg() call in nbl_dispatch.c), so there are no responders that the "not explicitly unregistered here" sentence could refer to.
Both premises do hold at the end of the series, where nbl_core_remove() calls nbl_dev_remove() first and nbl_dev_remove_common_dev() tears down the mailbox queue before the resource layer, and nbl_disp_setup_msg() registers the responders. Would it be clearer to move this comment to the patch that actually registers the handlers?
Related to the same staging question: nbl_disp_refresh_ctrl_ops() installs init_module/deinit_module
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 40
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +4
-0+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; + }
but is there any caller of these ops at this commit? The first callers, nbl_dev_setup_ctrl_dev() and nbl_dev_remove_ctrl_dev(), arrive with the later dev-layer patch, so the "dispatch management flow" the commit message mentions appears inert here.
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, · line 72
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1
-0@@ -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);
Here the channel layer is removed after the resource layer, which is the opposite order from the one the nbl_disp_remove() comment relies on.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 8/10 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add bidirectional mailbox RPC for cross-PF resource coordination, implementing request/response handlers for five 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 via nbl_disp_refresh_ctrl_ops():
- Control PF (NBL_DISP_CTRL_LVL_MGT): invokes local hardware ops directly.
- Non-control PF with net capability (NBL_DISP_CTRL_LVL_NET):
forwards requests via mailbox RPC to the manager PF.
- Neither level set: all dispatch ops are NULL.
Introduce per-dispatch mutex ops_mutex_lock to serialize mutable hardware operations (cfg_msix_map, destroy_msix_map, set_mailbox_irq). The mutex protects both local control-PF call paths and asynchronous remote mailbox RPC response handlers to eliminate race windows. Read-only get_vsi_id() / get_eth_id() access static init-time metadata; disp_ops table updates only happen during probe, so no runtime concurrent modification.
nbl_disp_setup_msg() registers five dispatch-layer wire message response handlers with the channel layer:NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, NBL_CHAN_MSG_DESTROY_MSIX_MAP, NBL_CHAN_MSG_MAILBOX_SET_IRQ, NBL_CHAN_MSG_GET_VSI_ID, NBL_CHAN_MSG_GET_ETH_ID.
Message IDs are non-contiguous to preserve compatibility with reserved and deprecated message entries.
Extend wire protocol with new message types andNBL_CHAN_RESP_PERM_DENY error code.
Every responder validates:
- src_id against common->max_pf at runtime; rejects VF and out-of-range function IDs with PERM_DENY;
- incoming payload length against the expected parameter struct size before parsing;
- unimplemented operation via NULL function pointer check before dispatch.
Request-side helpers translate channel wire status codes to standard Linux errnos: OK->0, UNIMPLEMENTED->-EOPNOTSUPP, ERR->-EREMOTEIO, PERM_DENY->-EPERM. Local transport errors (-ETIMEDOUT, -ESHUTDOWN, -EAGAIN, -EIO, -EINVAL) are passed through unchanged via an early "if (ret < 0) return ret" before the status switch.
get_vsi_id_req() and get_eth_id_req() verify chan_send.ack_len matches sizeof(result) before dereferencing the response, rejecting truncated ACKs with -EREMOTEIO to prevent adoption of zeroed identifiers from a short reply.
destroy_msix_map responder clears the mailbox QINFO MSIX routing (MSIX_IDX / MSIX_IDX_VALID) as Step 0 before tearing down the MSI-X map, ensuring a recycled global vector cannot trigger an interrupt owned by a different function.
cfg_msix_map pre-allocates all coherent DMA buffers and global vector indices before destroying the old configuration, then swaps the new resources into the per-function entry to avoid interrupt loss during reconfiguration.
RPC caller precondition: disable mailbox IRQ_RDY and switch send_msg to polling path before invoking cfg_msix_map / destroy_msix_map RPC, because responder modifies mailbox MSIX routing and ACK cannot rely on interrupt wakeup.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 571 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 2 + .../nbl/nbl_include/nbl_def_channel.h | 6 + .../nbl/nbl_include/nbl_def_dispatch.h | 17 + 4 files changed, 596 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +571 -0
@@ -3,9 +3,192 @@* 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 , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret <0 ) +return ret; +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 ; + } +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_vsi_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +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 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } +memcpy (¶m, 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 , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret <0 ) +return ret; +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 ; + } +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_eth_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +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 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } +memcpy (¶m, 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 +208,371 @@ 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 , + ¶m,sizeof (param), +NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret <0 ) +return ret; +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 ; +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to polling path before issuing cfg_msix_map RPC. +* The responder will disable mailbox MSIX routing during resource ops, +* so ACK cannot rely on interrupt wakeup. +*/ +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 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } +memcpy (¶m, 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); +if (ret <0 ) +return ret; +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 ; +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to polling path before issuing destroy_msix_map. +* The responder will disable mailbox MSIX routing during resource ops, +* so ACK cannot rely on interrupt wakeup. +*/ +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 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + 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 , + ¶m,sizeof (param),NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret <0 ) +return ret; +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 ; +u16 vector_id; +u32 rel_pf_id; +bool en_msix; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } +memcpy (¶m, 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; + +return ret; +} +static void nbl_disp_set_ctrl_bit (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) {set_bit (lvl, disp_mgt->ctrl_lvl);
@@ -34,9 +582,22 @@ static void nbl_disp_refresh_ctrl_ops(struct nbl_dispatch_mgt *disp_mgt) {struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; +memset (disp_ops,0 ,sizeof (*disp_ops));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 if (test_bit (NBL_DISP_CTRL_LVL_NET , disp_mgt->ctrl_lvl)) { + 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 +606,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,9 +669,15 @@ 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 ); +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 ; }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +2 -0
@@ -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
@@ -18,6 +18,7 @@ enum {NBL_CHAN_RESP_OK =0 ,NBL_CHAN_RESP_ERR =1 ,NBL_CHAN_RESP_UNIMPLEMENTED =2 , + NBL_CHAN_RESP_PERM_DENY = 3, };/*
@@ -37,6 +38,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 +17 -0
@@ -12,6 +12,7 @@ struct nbl_dispatch_mgt;struct nbl_adapter ;enum {NBL_DISP_CTRL_LVL_MGT , +NBL_DISP_CTRL_LVL_NET ,NBL_DISP_CTRL_LVL_MAX , };
@@ -21,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 {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v28 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 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Critical: 0 · High: 1 · Medium: 1 · Low: 2
- [High] The five new mailbox responders in nbl_dispatch.c perform no authorization of the requesting function, contradicting the commit…
- [Medium] The five new request helpers switch on chan_ops->send_msg()'s return value as if it were a positive NBL_CHAN_RESP_* wire status, but…
- [Low] Claim: nbl_disp_setup_msg() registers five mailbox responders with no matching unregistration, and nbl_disp_remove() is empty, so in…
- [Low] Claim: the NBL_CHAN_MSG_MAILBOX_SET_IRQ RPC reprograms the requesting function's own mailbox MSI-X routing on the responder side…
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This adds bidirectional mailbox RPC to the dispatch layer for five operations (configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id), resolving the dispatch ops at probe time depending on whether the PF is the control PF or a net-only PF. It also introduces disp_mgt->ops_mutex_lock to serialize the mutable hardware ops and extends the wire protocol with new message types and NBL_CHAN_RESP_PERM_DENY.
Quoted 33 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +22
-0@@ -3,9 +3,192 @@* 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 , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret <0 ) +return ret; +switch (ret) { +case NBL_CHAN_RESP_OK :
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 40
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]
Can this switch ever observe a value other than 0?
nbl_chan_send_msg() returns READ_ONCE(wait_head->ack_err), and nbl_chan_recv_ack_msg() clamps every positive wire status before storing it:
nbl_channel.c:nbl_chan_recv_ack_msg() {
raw_err = (s32)le32_to_cpu(*(__le32 *)&payload[NBL_CHAN_ACK_RET_POS]);
if (raw_err > 0 || raw_err < -MAX_ERRNO)
raw_err = -EREMOTEIO;
WRITE_ONCE(wait_head->ack_err, raw_err);
}The responders put the raw positive status on the wire unchanged (nbl_chan_send_ack() does tmp[NBL_CHAN_ACK_RET_POS] = cpu_to_le32(chan_ack->err)), so NBL_CHAN_RESP_ERR(1), NBL_CHAN_RESP_UNIMPLEMENTED(2) and NBL_CHAN_RESP_PERM_DENY(3) all arrive as -EREMOTEIO and are consumed by the preceding "if (ret < 0) return ret;".
That would make the UNIMPLEMENTED / ERR / PERM_DENY arms here (and the identical arms 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()) unreachable.
The commit message states:
"Request-side helpers translate channel wire status codes to standard
Linux errnos: OK->0, UNIMPLEMENTED->-EOPNOTSUPP, ERR->-EREMOTEIO, PERM_DENY->-EPERM."
Does that translation actually happen, given the clamp above? A remote UNIMPLEMENTED (returned whenever a res_ops pointer is NULL) would surface as -EREMOTEIO rather than -EOPNOTSUPP.
Quoted 22 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +22
-0+if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_vsi_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +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 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 72
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+u16 vsi_id =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + }
[Severity: High]
Can this gate ever reject anything? The commit message says:
"Every responder validates:
- src_id against common->max_pf at runtime; rejects VF and out-of-range function IDs with PERM_DENY;"
but the helper only does a lower-bound test and then throws the result away:
nbl_common.c:nbl_common_func_id_to_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;
}With common->mgt_pf = 0 (nbl_core_init() in nbl_main.c hard-codes it), "pf_id < common->mgt_pf" is never true for the unsigned src_id, so the helper always returns 0. rel_pf_id is then unused, and there is no comparison against common->max_pf in any of the five responders.
Should these responders carry the same rejection that the other caller of this helper, nbl_res_func_id_to_bdf() in nbl_resource.c, performs?
if (rel_pf_id >= common->max_pf) {
dev_err(common->dev,
"func_id=%u rel_pf_id=%u exceeds max_pf=%u, VF BDF unsupported\n",
pfid, rel_pf_id, common->max_pf);
return -EOPNOTSUPP;
}As written, can NBL_CHAN_RESP_PERM_DENY be produced by any responder in this patch?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +5
-0+if (data_len <sizeof (param)) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param));
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 378
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+ ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + 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);
[Severity: High]
Following on from the missing max_pf rejection above, src_id is forwarded here as func_id with no PF/VF distinction. The downstream ops do not add one either:
nbl_res_intr_destroy_msix_map() only rejects func_id >= NBL_MAX_FUNC (520), and __nbl_res_intr_set_mailbox_irq() in the en_msix == false case writes mailbox routing for any func_id below that:
nbl_interrupt.c:__nbl_res_intr_set_mailbox_irq() {
if (!en_msix) {
hw_ops->set_mailbox_irq(res_mgt->hw_ops_tbl->priv,
func_id, false, 0);
hw_ops->flush_write(res_mgt->hw_ops_tbl->priv);
return 0;
}Should a VF function id (8..519) be able to reach destroy_msix_map and set_mailbox_irq on the control PF?
There is also a cost per message here: __nbl_res_intr_destroy_msix_map() sleeps unconditionally, even when the function had nothing configured:
nbl_interrupt.c:__nbl_res_intr_destroy_msix_map() {
ret = __nbl_res_intr_prepare_destroy_msix_map(res_mgt, func_id);
if (ret)
return ret;
mutex_unlock(&intr_mgt->lock);
usleep_range(NBL_MSIX_DMA_SYNC_MIN_US, NBL_MSIX_DMA_SYNC_MAX_US);
mutex_lock(&intr_mgt->lock);Since this runs from the mailbox RX work item with disp_mgt->ops_mutex_lock held, does each unauthorized NBL_CHAN_MSG_DESTROY_MSIX_MAP message hold up the cross-PF control path for a millisecond?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h enum { · line 22
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +1
-0@@ -18,6 +18,7 @@ enum {NBL_CHAN_RESP_OK =0 ,NBL_CHAN_RESP_ERR =1 ,NBL_CHAN_RESP_UNIMPLEMENTED =2 , + NBL_CHAN_RESP_PERM_DENY = 3, };
[Severity: Medium]
Given the clamp in nbl_chan_recv_ack_msg() and the always-succeeding authorization helper, is this new enumerator reachable in either direction - can a responder set it, and can a requester ever see it?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 9/10 net/nebula-matrix: add common/ctrl dev init/remove operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev core infrastructure. Create nbl_dev.c / nbl_dev.h and nbl_def_dev.h, introducing nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() initialization helpers with their teardown counterparts, and wire them into nbl_dev_init() / nbl_dev_remove() called from nbl_core_init() / nbl_core_remove().
Common device setup (nbl_dev_setup_common_dev):
- Allocate per-device state (nbl_dev_common)
- Set up mailbox channel queue and register cleanup work
- Initialize MSI-X service counts (mailbox = 1 vector; actual allocation deferred to nbl_dev_start() in the next patch; this patch only populates service vector counts)
- On the control PF only: fetch VSI/ETH identity via local dispatch ops. Non-control PFs defer this to nbl_dev_start(), when the mailbox channel is fully operational and the control PF's responder is running; this keeps every intermediate commit bisect-bootable on multi-PF systems.
Control device setup (nbl_dev_setup_ctrl_dev, control PF only):
- disp_ops->init_module(): chip-wide hardware initialization callback (datapath pipeline setup, driver_status flag)
- Program mailbox QINFO routing map (bus/devid for each PF)
Chip core hardware initialization is handled by firmware at power-on. The driver only configures functional table entries after hardware becomes ready, so common_dev setup before ctrl_dev setup is safe.
Deinit order: ctrl dev cleanup after common dev teardown. nbl_dev_remove_ctrl_dev() calls deinit_module(), which sets driver_status=false to notify firmware to asynchronously clean all per-PF hardware state including qinfo registers. The qinfo map is not explicitly cleared by the driver; firmware handles it on driver_status change. No completion handshake exists in the current hardware revision.
Important constraint: caller must ensure no new DMA is initiated after deinit. The mailbox channel is stopped first. Unbinding the control PF while sibling non-control PFs are still bound is NOT supported; this leaves remaining PFs with broken mailbox RPC and causes RPC ACK timeouts. Driver does not block this unsafe sequence.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 235 ++++++++++++++++++ .../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, 315 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -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
@@ -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 +235 -0
235 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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 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: 5 · Low: 0
- [Medium] Commit message contradicts the code: it states that common device setup does "On the control PF only: fetch VSI/ETH identity via…
- [Medium] nbl_dev_setup_common_dev() calls cancel_work_sync(&common_dev->clean_mbx_task) on a work_struct that…
- [Medium] The patch introduces an unguarded chip-global cross-PF
dependency: nbl_dev_setup_ctrl_dev() -> nbl_dev_setup_chan_qinfo() ->…
- [Medium] nbl_dev_remove_common_dev() (nbl_dev.c:115-125) discards the int return value of nbl_dev_remove_chan_queue() ->…
- [Medium] Hardware sequencing bug: the mailbox TX/RX rings are armed in hardware before the chip-side mailbox routing entry that identifies…
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This adds the nbl_dev layer with nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() plus their teardown counterparts, wired into nbl_dev_init() / nbl_dev_remove() from nbl_core_init() / nbl_core_remove(). Common dev setup brings up the mailbox channel queue and registers the mailbox cleanup work; ctrl dev setup calls init_module() and programs the mailbox QINFO routing map.
A few questions below.
Quoted 11 lines
Common device setup (
nbl_dev_setup_common_dev):
- Allocate per-device state (nbl_dev_common)
- Set up mailbox channel queue and register cleanup work
- Initialize MSI-X service counts (mailbox = 1 vector; actual allocation deferred tonbl_dev_start()in the next patch; this patch only populates service vector counts)
- On the control PF only: fetch VSI/ETH identity via local dispatch ops. Non-control PFs defer this tonbl_dev_start(), when the mailbox channel is fully operational and the control PF's responder is running; this keeps every intermediate commit bisect-bootable on multi-PF systems.
[Severity: Medium]
Does the code match this description? nbl_dev_setup_common_dev() only allocates nbl_dev_common, sets up the mailbox channel queue, does INIT_WORK() plus nbl_dev_register_chan_task(), stores common_dev and calls nbl_dev_init_msix_cnt(). There is no get_vsi_id()/get_eth_id() call in nbl_dev.c at all, and the in-code comment says the opposite of the changelog:
/* * VSI/ETH identity fetch moved to nbl_dev_start(). * This avoids cross-PF probe race when manager PF is not ready. */
So common->vsi_id / common->eth_id / common->eth_num stay zero after nbl_dev_init() on every PF, including the control PF.
Should the changelog say the identity fetch is deferred to nbl_dev_start() for all PFs rather than "On the control PF only: fetch VSI/ETH identity via local dispatch ops"?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,235 @@
[ ... ]
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); +}
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +6
-0+/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev; +int ret;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 95
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+ + common_dev =devm_kzalloc (&adapter->pdev->dev,sizeof (*common_dev), +GFP_KERNEL ); +if (!common_dev) +return -ENOMEM ; + common_dev->dev_mgt = dev_mgt; + + ret =nbl_dev_setup_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +if (ret) + goto err_cleanup;
[Severity: Medium]
Is the hardware ordering here safe with respect to the mailbox routing map? This call arms the mailbox rings:
nbl_dev_setup_chan_queue() -> nbl_chan_setup_queue()
nbl_hw_config_mailbox_txq() / nbl_hw_config_mailbox_rxq() (QUEUE_EN=1)
nbl_chan_update_tail_ptr() (rx doorbell)
but the per-function BUS/DEVID/FUNCTION routing entry is only written later, and only when common->has_ctrl:
nbl_dev_init()
nbl_dev_setup_common_dev() <- queues enabled here
if (common->has_ctrl)
nbl_dev_setup_ctrl_dev()
nbl_dev_setup_chan_qinfo() <- QINFO_MAP written here
nbl_chan_cfg_qinfo_map_table() -> 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);A non-control PF never programs its own entry, and this patch states firmware clears those chip-global entries when the control PF sets driver_status=false.
Can a PF then run with mailbox queues enabled while its QINFO_MAP entry is zero or stale, for example when a non-control PF is bound while function 0 is not bound, or in the window on control PF re-probe between arming its rings and writing QINFO_MAP for function 0? Would mailbox DMA in that window be tagged with 00:00.0 or a stale bus?
Would it be safer to program a function's QINFO routing entry before enabling that function's mailbox queue?
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +8
-0+ +INIT_WORK (&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX , + &common_dev->clean_mbx_task); +/* +* VSI/ETH identity fetch moved to nbl_dev_start(). +* This avoids cross-PF probe race when manager PF is not ready. +*/
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 113
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+ dev_mgt->common_dev = common_dev; +nbl_dev_init_msix_cnt (dev_mgt); + +return 0 ; +err_cleanup: +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +return ret; +}
[Severity: Medium]
Can this warn on an uninitialized work item? The only jump to err_cleanup is the nbl_dev_setup_chan_queue() failure, which is before the INIT_WORK(), so clean_mbx_task is still all zeros from devm_kzalloc() (work->func == NULL, no lockdep map) when cancel_work_sync() runs:
cancel_work_sync() -> __cancel_work_sync() -> __flush_work(work, true)
kernel/workqueue.c:__flush_work() {
...
if (WARN_ON(!work->func))
return false;
...
}That gives a WARNING backtrace (panic with panic_on_warn) instead of a clean probe failure.
The same label also tears down a queue that was never brought up (nbl_chan_teardown_queue() then logs "channel not active, skip duplicate teardown") and unregisters a task that was never registered.
Would moving INIT_WORK() above nbl_dev_setup_chan_queue(), or just returning ret directly on that path, be preferable?
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 125
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +12
-0+ +static void nbl_dev_remove_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; + +if (!common_dev) +return ; +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +}
[Severity: Medium]
Should the return value of nbl_dev_remove_chan_queue() be checked here? It propagates -ETIMEDOUT from the drain in nbl_chan_teardown_queue():
nbl_channel.c:nbl_chan_teardown_queue() {
...
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;
...
}whose comment says callers must not access queue resources while an inflight sender may still be active. nbl_dev_remove() then proceeds to nbl_dev_remove_ctrl_dev() -> deinit_module() -> nbl_hw_deinit_module(), which documents a premise nobody verifies:
nbl_hw_leonis.c:nbl_hw_deinit_module() {
* Caller must ensure no new DMA is initiated after this point.
* The mailbox channel is stopped by nbl_chan_teardown_queue()
* before this function is called, so no in-flight mailbox DMA
* remains.
}
On the timeout path that premise does not hold: driver_status=false starts the asynchronous firmware cleanup while a sender may still be writing descriptors into the dmam_alloc_coherent() rings, which devres frees right after remove() returns.
Can this at least log or bail out on the -ETIMEDOUT case rather than discarding it?
Quoted 25 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +25
-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 ; +} + +/* +* Tear down control device: deinit_module sets driver_status=false +* to notify firmware to clean all per-PF hardware state (including +* qinfo registers). The qinfo map programmed in setup_ctrl_dev is +* not explicitly cleared; firmware handles it on driver_status change. +* +* NOTE: Firmware clears chip-global qinfo routing entries when control PF +* deinit runs. MUST unbind all sibling non-control PFs on the same chip +* BEFORE unbinding the control PF. Unbinding control PF while siblings are
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 160
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+* still bound will leave those sibling PFs with broken mailbox RPC, +* causing RPC ACK timeouts. This operation sequence is NOT supported. +*/ +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: Medium]
Can anything stop the unbind order that this comment says is unsupported?
nbl_dev_setup_ctrl_dev() -> nbl_dev_setup_chan_qinfo() -> nbl_chan_cfg_qinfo_map_table() programs NBL_MAILBOX_QINFO_MAP_REG_ARR() for every hardware-active PF, and nbl_dev_remove_ctrl_dev() calls deinit_module() -> nbl_hw_deinit_module() (driver_status=false) unconditionally.
nbl_remove() runs per PCI function with no cross-function coordination:
nbl_remove()
pci_set_drvdata(pdev, NULL);
nbl_core_remove(adapter);
nbl_dev_remove()
if (common->has_ctrl)
nbl_dev_remove_ctrl_dev() <- chip-global deinitSo a plain
echo <pf0-bdf> > /sys/bus/pci/drivers/nbl/unbind
silently breaks every still-bound sibling PF: their mailbox RPCs are no longer routed, so each dispatch RPC ends in an ACK timeout (3s ACK wait, 5s drain), and their own later teardown RPCs fail too.
Would a refusal or a reference count on the control PF be better than documenting the hazard, or can the chip-global dependency be avoided?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v28 10/10 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangFrom: 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 in strict order:
1. Configure hardware MSI-X mapping table (cfg_msix_map)
2. Fetch VSI and ETH identity information via dispatch RPC
3. Allocate MSI-X IRQ vectors via pci_alloc_irq_vectors()
4. Request mailbox interrupt and attach handler
(nbl_dev_clean_mailbox -> schedule cleanup work)
5. Enable hardware mailbox interrupt and mark channel interrupt ready (NBL_CHAN_IRQ_RDY)
The VSI/ETH identity fetch for all PFs happens inside nbl_dev_start(), after the MSI-X mapping is configured. Non-control PFs rely on the control PF's mailbox responder being fully operational when this RPC runs.
nbl_dev_stop() tears down resources in reverse order, with device-side mapping destroyed before kernel-side vectors are released:
1. Switch channel to polling mode (clear NBL_CHAN_IRQ_RDY) before masking hardware mailbox interrupt. This ordering avoids discarding in-flight ACKs that would trigger "Channel waiting ack failed" errors.
2. Release mailbox IRQ via free_irq()
3. Destroy hardware MSI-X mapping table (masks all device vectors and clears the pcompleter map entry)
4. Kernel MSI-X vectors are managed by devres/pcim, so explicit pci_free_irq_vectors() is skipped to prevent double-free.
5. Drain mailbox cleanup work via cancel_work_sync()
The start error-unwind path uses the same reverse ordering (err_disable_irq -> err_destroy_map -> cancel_work_sync), so a failure at any stage leaves the device and kernel in a consistent state. Rollback failures are logged.
This teardown is best-effort: destroy_msix_map uses mailbox RPC and may fail. Stale hardware MSI-X entries are reclaimed by firmware on chip reset. pci_clear_master() in nbl_remove() provides the final safety net if a teardown RPC to the manager PF cannot complete.
Add thin wrappers nbl_core_start() / nbl_core_stop() and hook them into PCI probe and remove paths to control the device lifecycle. This patch completes the dev lifecycle series.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 336 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 18 + 4 files changed, 358 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -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 +336 -0
357 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH v28 net-next 10/10] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 2 · Low: 0
- [Medium] A non-control PF's nbl_dev_start() (nbl_dev.c:457-492) issues three mailbox RPCs to the manager PF (cfg_msix_map at line 467,…
- [Medium] nbl_dev_setup_common_dev() (nbl_dev.c:300-332) calls cancel_work_sync(&common_dev->clean_mbx_task) at its err_cleanup label…
--
net/nebula-matrix: add common dev start/stop operation
This adds nbl_dev_start()/nbl_dev_stop() to configure the hardware MSI-X map, fetch VSI/ETH identity, allocate MSI-X vectors and request/release the mailbox interrupt. Thin wrappers nbl_core_start()/nbl_core_stop() are hooked into nbl_probe() and nbl_remove().
A couple of questions below.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -77,6 +288,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work) NBL_CHAN_TYPE_MAILBOX); }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_clean_mailbox_task(struct work_struct *work) · line 300
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +8
-0+static void nbl_dev_clean_mailbox_schedule (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +struct nbl_common_info *common = dev_mgt->common; + +queue_work (common->wq, &common_dev->clean_mbx_task); +} +/* ---------- Dev init process ---------- */ static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter)
[Severity: Medium]
Now that clean_mbx_task is driven from the mailbox hardirq handler, can we also take a look at the error path in nbl_dev_setup_common_dev()? The work is cancelled there before it is ever initialized:
common_dev = devm_kzalloc(&adapter->pdev->dev, sizeof(*common_dev),
GFP_KERNEL);
...
ret = nbl_dev_setup_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
if (ret)
goto err_cleanup;
INIT_WORK(&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task);
...
err_cleanup:
cancel_work_sync(&common_dev->clean_mbx_task);If nbl_dev_setup_chan_queue() fails (its ring allocations can return -ENOMEM), clean_mbx_task is still the all-zero devm_kzalloc content, so work->func is NULL when cancel_work_sync() runs:
kernel/workqueue.c:__flush_work() {
...
if (WARN_ON(!work->func))
return false;
...
}Does this produce a workqueue warning backtrace on that path? The zeroed work->data also decodes to pool_id 0 rather than WORK_OFFQ_POOL_NONE, so start_flush_work() would look at an unrelated worker pool. Would moving INIT_WORK() up to right after the devm_kzalloc(), or dropping the cancel from a path where the work was never initialized, be preferable?
[ ... ]
Quoted 18 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +14
-0@@ -233,3 +452,120 @@ void nbl_dev_remove(struct nbl_adapter *adapter)if (common->has_ctrl)nbl_dev_remove_ctrl_dev (adapter); } + +/* ---------- Dev start process ---------- */ +int nbl_dev_start (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; +struct nbl_dispatch_mgt *priv = dev_mgt->disp_ops_tbl->priv; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +struct nbl_common_info *common = dev_mgt->common; +int cleanup_ret; +int ret; + + ret =nbl_dev_cfg_msix_map (dev_mgt); +if (ret)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 478
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+ goto err_destroy_map; + +/* Fetch VSI/ETH identity after cfg_msix_map */ + ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); +if (ret) + goto err_destroy_map; + ret = disp_ops->get_eth_id (priv, common->vsi_id, &common->eth_num, + &common->eth_id, &common->logic_eth_id); +if (ret) + goto err_destroy_map;
[Severity: Medium]
On a non-control PF, all three of these calls are mailbox RPCs to the manager PF, since nbl_disp_refresh_ctrl_ops() installs the NBL_DISP_CTRL_LVL_NET request variants:
nbl_dispatch.c:nbl_disp_refresh_ctrl_ops() {
...
} else if (test_bit(NBL_DISP_CTRL_LVL_NET, disp_mgt->ctrl_lvl)) {
disp_ops->cfg_msix_map =
...
}What happens if PF0 has not finished its own init/start yet? The send goes through the polling path and comes back as a bounded failure:
nbl_channel.c:nbl_chan_send_msg() {
...
dev_err_ratelimited(dev,
"Channel polling ack failed, message type: %d msg id: %u\n",
chan_send->msg_type, msgid);
ret = -ETIMEDOUT;
...
}nbl_dev_start() then returns -ETIMEDOUT to nbl_probe(), which turns it into a plain probe failure rather than -EPROBE_DEFER, so the PF stays unbound with no retry once PF0 does come up.
This looks reachable with asynchronous probing enabled (driver_async_probe=nbl or nbl.async_probe=1), where PF1..PF3 can run these RPCs before PF0 has programmed the mailbox QINFO routing and registered the responders, and also when an administrator binds a non-control PF via /sys/bus/pci/drivers/nbl/bind while PF0 is unbound.
The commit message notes the dependency:
Non-control PFs rely on the control PF's mailbox responder being fully operational when this RPC runs.
Should the code enforce that, either by checking control-PF readiness or by returning -EPROBE_DEFER so the bind is retried?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0@@ -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;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914123429.56596-1-illusion.wang%40nebula-matrix.com
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 14 Sep 2026 20:34:14 +0800 you wrote:
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.
[...]
Here is the summary with links:
- [v28,net-next,01/10] net/nebula-matrix: add minimum nbl build framework
https://git.kernel.org/netdev/net-next/c/cffde9e49e86 - [v28,net-next,02/10] net/nebula-matrix: add core driver architecture and HW layer initialization https://git.kernel.org/netdev/net-next/c/825e6d230163
- [v28,net-next,03/10] net/nebula-matrix: add channel layer
(no matching commit)
- [v28,net-next,04/10] net/nebula-matrix: add common resource implementation
(no matching commit)
- [v28,net-next,05/10] net/nebula-matrix: add intr resource implementation
(no matching commit)
- [v28,net-next,06/10] net/nebula-matrix: add chip-wide hardware init/deinit implementation (no matching commit)
- [v28,net-next,07/10] net/nebula-matrix: dispatch: add control-level routing core infrastructure (no matching commit)
- [v28,net-next,08/10] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops (no matching commit)
- [v28,net-next,09/10] net/nebula-matrix: add common/ctrl dev init/remove operation
(no matching commit)
- [v28,net-next,10/10] net/nebula-matrix: add common dev start/stop operation
(no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html