nbl driver for Nebulamatrix NICs
Subsystems (4)
illusion.wang
maintainerv27 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 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 | 1314 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 170 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 231 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 32 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 45 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 529 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 667 +++++++++ .../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 | 1132 ++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 338 +++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 363 +++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 76 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 544 +++++++ .../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, 6695 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 v27 1/10 net/nebula-matrix: add minimum nbl build framework
From: illusion wang <[email protected]>
This patch adds the minimum build infrastructure:
1. Add Kconfig, Makefile and MAINTAINERS entries;
2. Add corresponding driver documentation;
3. Add PCI driver skeleton with empty stubs for nbl driver.
--- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 +++++ MAINTAINERS | 10 ++ drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 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 v27 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] Documentation/Kconfig prose added by this patch describes functionality that does not exist at this commit:…
--
net/nebula-matrix: add minimum nbl build framework
This patch adds the Kconfig, Makefile and MAINTAINERS entries for a new nebula-matrix ethernet vendor directory, a documentation file for the nbl driver, and a PCI driver skeleton whose probe and remove callbacks are stubs.
Quoted 14 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +8
-0@@ -0,0 +1,28 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================================================ +Linux Base Driver for Nebula-matrix m18110-NIC/m18000-NIC family +================================================================ + +Overview: +=========
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 18
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +10
-0+The m18110-NIC/m18000-NIC (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
[Severity: Low]
This isn't a bug, but does the documentation added here describe code that exists at this commit? The only C file added is nbl_main.c, where nbl_probe() returns -ENODEV and nbl_remove() is empty, so there is no BAR management, no PF mailbox command interface, no channel communication and no device init/teardown yet.
The same wording appears in the CONFIG_NBL help text below.
All four items are implemented by the end of the series (nbl_probe() ends up calling nbl_core_init(), which chains nbl_hw_init_leonis(), nbl_chan_init_common(), nbl_res_init_leonis(), nbl_disp_init() and nbl_dev_init()), and the .rst text is not touched again, so this is only a skew within the series.
Would it be preferable to word the first patch's doc and help text to match the stub state, or to add this prose together with the code it describes?
[ ... ]
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.
This is the menuconfig text mentioned above; at this commit selecting CONFIG_NBL=m builds a module that only registers a pci_driver with an always-failing probe.
[ ... ]
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) +{ +}
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +3
-0+static const struct pci_device_id nbl_id_table[] = { + {PCI_DEVICE (NBL_VENDOR_ID ,NBL_DEVICE_ID_M18110 ), + .driver_data =BIT (NBL_CAP_HAS_NET_BIT ) },
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 87
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +4
-0+/* required as sentinel */ + { } +}; +MODULE_DEVICE_TABLE (pci, nbl_id_table);
Since MODULE_DEVICE_TABLE() publishes all 16 IDs in the 0x1F0F:0x3403-0x3412 range, udev will autoload nbl on matching hardware at this commit and the device stays unbound because of the -ENODEV above. Is that the intended intermediate state for a bisect point?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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.
--- .../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 | 154 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 15 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 32 ++++ .../nbl/nbl_include/nbl_def_common.h | 32 ++++ .../nbl/nbl_include/nbl_def_hw.h | 17 ++ .../nbl/nbl_include/nbl_include.h | 9 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 94 ++++++++++- 9 files changed, 372 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 +154 -0
154 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 +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_HW_REG_H_ +#define _NBL_HW_REG_H_ + +#include <linux/types.h> + +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +#define NBL_MEMORY_BAR 0 +#define NBL_MAILBOX_BAR 2 +#define NBL_RDMA_NOTIFY_LEN (8ULL << 10) +#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +/* +* PCI MEMORY BAR total size: 64MiB. +*/ +#define NBL_MEM_BAR_TOTAL_SIZE (64ULL << 20) + +struct nbl_hw_mgt { +struct nbl_common_info *common; +u8 __iomem *hw_addr; +u8 __iomem *mailbox_bar_hw_addr; +resource_size_t hw_size; +resource_size_t mailbox_bar_size; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_COMMON_H_ +#define _NBL_DEF_COMMON_H_ + +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/device.h> +#include "nbl_include.h" + +struct nbl_common_info { +struct pci_dev *pdev; +struct device *dev; +u32 msg_enable; +u16 vsi_id; +u8 eth_id; +u8 logic_eth_id; +u8 eth_num; + +u8 function; +u8 devid; +u8 bus; +u8 hw_bus; + +u8 has_ctrl; +u8 has_net; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file +17 -0
@@ -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 v27 net-next 02/10] net/nebula-matrix: add core driver architecture and HW layer initialization
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] Series-structure remark (validated as NOT a defect): nbl_probe() changes from an unconditional -ENODEV to a success path that enables…
- [Low] Dead code introduced by this patch: (a) nbl_hw_leonis.c includes <linux/spinlock.h> and <linux/bitfield.h> although the file at this…
--
net/nebula-matrix: add core driver architecture and HW layer initialization
This adds the nbl_adapter/nbl_core/nbl_common_info device context, turns the previously stubbed nbl_probe() into a working PCI probe path, and adds the Leonis hardware layer that requests BAR0/BAR2 and ioremaps them via pcim helpers.
A couple of small questions below about unused code added by this patch and about the point in the series where the device starts being claimed.
Quoted 18 lines
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.odrivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +1
-0@@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 11
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +10
-0+/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include <linux/pci.h> +#include <linux/bits.h> +#include <linux/io.h> +#include <linux/spinlock.h> +#include <linux/bitfield.h> +#include "nbl_hw_leonis.h"
[Severity: Low]
This isn't a bug, but are linux/spinlock.h and linux/bitfield.h needed here yet? Grepping nbl_hw_leonis.c at this commit for spin_lock or FIELD_ returns no matches, so both look like leftovers from splitting a larger file (the spinlock and FIELD_*() users appear only in later patches). Could they be added in the patch that first uses them?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 100
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +5
-0+ hw_mgt->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_mgt->hw_size);
[Severity: Low]
Is hw_mgt->hw_size read anywhere? It is stored in both branches but never used to bound a register access, here or later in the series, where only mailbox_bar_size ends up being checked. Passing the size straight to pcim_iomap() and dropping the field would work too.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +0
-0@@ -0,0 +1,32 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h line 18
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +5
-0+struct nbl_common_info { +struct pci_dev *pdev; +struct device *dev; +u32 msg_enable; +u16 vsi_id;
[Severity: Low]
What uses msg_enable? At this commit the only occurrence in the whole nbl directory is this declaration, and by the end of the series struct nbl_common_info no longer has the member at all, so it is added and then silently removed within the same series. Should it just be dropped here?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 23 lines
static int nbl_probe(struct
pci_dev*pdev,drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +19
-1const struct pci_device_id *id) { -return -ENODEV ; +struct nbl_init_param param = { {0 } }; +struct device *dev = &pdev->dev; +struct nbl_adapter *adapter; +int err; + + err =pcim_enable_device (pdev); +if (err) { +dev_err (&pdev->dev,"Failed to enable PCI dev, err=%d\n" , err); +return err; + } + +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)) {
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 101
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9
-0+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 ; +adapter_init_err: +pci_clear_master (pdev); +return err; }
[Severity: Low]
This isn't a bug, but from this commit on nbl_probe() returns success after pcim_enable_device(), dma_set_mask_and_coherent(), pci_set_master() and the BAR mappings, while no network interface is created.
Grepping the nbl directory for register_netdev or alloc_etherdev at the end of the series finds no matches either, so the module claims every ID in nbl_id_table[] and exposes no netdev at any point in the series.
The commit message does describe this as "preparing for subsequent device implementations", so the only question is placement: would it be preferable to keep probe returning -ENODEV until the netdev registration lands, so that bisecting between these patches does not leave the hardware bound to a driver that offers nothing?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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 | 1314 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 170 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 209 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 32 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 7 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 179 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 56 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 33 + .../nbl/nbl_include/nbl_def_channel.h | 126 ++ .../nbl/nbl_include/nbl_def_common.h | 18 + .../nbl/nbl_include/nbl_def_hw.h | 36 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 2193 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 +1314 -0
1,314 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +170 -0
170 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +209 -0
209 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +32 -0
@@ -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 +179 -0
204 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +56 -0
61 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +33 -0
@@ -8,6 +8,7 @@#include <linux/types.h> +#include "../nbl_include/nbl_def_channel.h" #include "../nbl_include/nbl_def_hw.h" #include "../nbl_include/nbl_def_common.h" #include "../nbl_core.h"
@@ -16,6 +17,7 @@#define NBL_MAILBOX_BAR 2#define NBL_RDMA_NOTIFY_LEN (8ULL << 10)#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +#define NBL_HW_DUMMY_REG 0x1300904/* * PCI MEMORY BAR total size: 64MiB. */
@@ -27,6 +29,37 @@ struct nbl_hw_mgt {u8 __iomem *mailbox_bar_hw_addr;resource_size_t hw_size;resource_size_t mailbox_bar_size; +spinlock_t reg_lock;/* Protect reg access */ }; +static inline u32 rd32 (u8 __iomem *addr,u64 reg) +{ +return readl (addr + reg); +} + +static inline void wr32 (u8 __iomem *addr,u64 reg,u32 value) +{ +writel (value, addr + reg); +} + +static inline void nbl_hw_wr32 (struct nbl_hw_mgt *hw_mgt,u64 reg,u32 value) +{ +wr32 (hw_mgt->hw_addr, reg, value); +} + +static inline u32 nbl_hw_rd32 (struct nbl_hw_mgt *hw_mgt,u64 reg) +{ +return rd32 (hw_mgt->hw_addr, reg); +} + +static inline void nbl_mbx_wr32 (struct nbl_hw_mgt *hw_mgt,u64 reg,u32 value) +{ +writel (value, hw_mgt->mailbox_bar_hw_addr + reg); +} + +static inline u32 nbl_mbx_rd32 (struct nbl_hw_mgt *hw_mgt,u64 reg) +{ +return readl (hw_mgt->mailbox_bar_hw_addr + reg); +} +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +126 -0
126 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +18 -0
@@ -12,6 +12,7 @@#include "nbl_include.h" struct nbl_common_info { +struct workqueue_struct *wq;struct pci_dev *pdev;struct device *dev;u32 msg_enable;
@@ -29,4 +30,21 @@ struct nbl_common_info { u8 has_net; }; +struct nbl_hash_tbl_key { +struct device *dev; +u16 key_size; +u16 data_size;/* no include key or node member */ +u16 bucket_size; +u16 resv; +}; + +void nbl_common_destroy_wq (struct nbl_common_info *common); +int nbl_common_create_wq (struct nbl_common_info *common); +struct nbl_hash_tbl_mgt * +nbl_common_init_hash_table (struct nbl_hash_tbl_key *key); +void nbl_common_remove_hash_table (struct nbl_hash_tbl_mgt *tbl_mgt); +int nbl_common_alloc_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key, +void *data,void **out_data); +void *nbl_common_get_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +36 -0
@@ -10,6 +10,42 @@struct nbl_hw_mgt ;struct nbl_adapter ; +struct nbl_hw_ops { +void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt, +u16 tail_ptr,u8 txrx); +void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*config_mailbox_txq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt); +void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt); +/** +* get_host_pf_mask - Fetch host PF mask from firmware k_pf_mask reg +* @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. +* +*/ +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 v27 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: 1 · Medium: 4 · Low: 7
- [High] nbl_chan_quiesce_and_reclaim_tx() (TX timeout recovery) resets the software doorbell counter txq->tail_ptr to 0 to match the…
- [Medium] The commit message justifies leaving the mailbox BAR2 register path unlocked by asserting that the multi-dword QINFO config sequences…
- [Medium] nbl_chan_recv_ack_msg() completes a request slot (copies the response, sets wait_head->acked = 1) but never transitions…
- [Medium] nbl_chan_quiesce_and_reclaim_tx() uses wmb() with the comment "Ensure reset write is posted before reclaiming descriptors" and then…
- [Medium] nbl_hw_cfg_mailbox_qinfo() builds the QINFO map dword from scratch (FUNCTION/DEVID/BUS only) and writes it, unconditionally…
- [Low] Concern (verified FALSE POSITIVE): nbl_chan_send_msg() never checks chan_info->active, so a send issued before…
- [Low] Concern (verified FALSE POSITIVE): nbl_chan_teardown_queue() frees nothing but clears chan_info->active, so a subsequent…
- [Low] Concern (verified FALSE POSITIVE): the commit message advertises working capabilities (dual RX modes, complete queue lifecycle, PF…
- [Low] Concern (verified FALSE POSITIVE): nbl_common_get_hash_node() returns hash_node->data after dropping the per-bucket spinlock while…
- [Low] Concern (verified FALSE POSITIVE): setup_queue/teardown_queue check and modify chan_info->active, shutdn, the state bitmap,…
- [Low] Concern (verified FALSE POSITIVE): nbl_chan_update_txqueue() accepts arg_len > 0 with arg == NULL; in the external-buffer branch it…
- [Low] Concern (verified FALSE POSITIVE): nbl_chan_remove_common() destroys the workqueue and frees the handler table but never tears…
--
net/nebula-matrix: add channel layer
This adds the mailbox-based inter-PF channel layer for the Nebula Matrix adapter, including the TX/RX descriptor ring management, a hash table of message handlers, and the hardware ops that program the mailbox QINFO tables and the tail pointer doorbell.
A few questions about the TX timeout recovery path, the ACK completion handshake, and the QINFO map table write.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static int nbl_chan_alloc_all_tx_bufs (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+ txq->next_to_clean =0 ; + txq->next_to_use =0 ; + txq->tail_ptr =0 ; + +return 0 ; +}
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+static int nbl_chan_update_txqueue (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info, +struct nbl_chan_tx_param *param) +{
[ ... ]
Quoted 24 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +24
-0+/* Ensure descriptor data visible to device before AVAIL flag */ +dma_wmb (); + tx_desc->flags =cpu_to_le16 (BIT (NBL_CHAN_TX_DESC_AVAIL )); + + txq->next_to_use = +NBL_NEXT_ID (txq->next_to_use, chan_info->num_txq_entries -1 ); + txq->tail_ptr++; + +return 0 ; +} + +/* +* Quiesce the TX mailbox queue and reclaim all outstanding +* descriptors. Called from the timeout path of nbl_chan_kick_tx_ring() +* with txq_lock held. +* +* The device failed to fetch/complete the current descriptor within the +* polling window. We assert QUEUE_RST to stop further DMA fetches, +* reclaim every descriptor between next_to_clean and next_to_use, +* reset the software tail_ptr counter to match the hardware reset state, +* and re-enable the queue so subsequent sends can proceed. +*/ +static void nbl_chan_quiesce_and_reclaim_tx (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info)
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 485
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+{ +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); +/* Ensure reset write is posted before reclaiming descriptors */ +wmb ();
[Severity: Medium]
Does this wmb() actually guarantee the posted QUEUE_RST write has reached the device before the descriptor flags below are rewritten?
writel() already contains the MMIO ordering barriers (__io_bw() and __io_aw() in include/asm-generic/io.h), so the extra wmb() adds nothing with respect to the device. nbl_hw_stop_mailbox_txq() only performs posted BAR2 writes with no read-back, and nbl_chan_config_queue() below de-asserts RST and sets EN in the immediately following writes:
cfg_tbl.data[3] = FIELD_PREP(NBL_MAILBOX_QINFO_CFG_QUEUE_RST_MASK, 0) | FIELD_PREP(NBL_MAILBOX_QINFO_CFG_QUEUE_EN_MASK, 1);
The QINFO_CFG layout added in this patch exposes RST/EN/DIF_ERR/PTR_ERR but no reset-done bit, and nothing reads the register back.
Would a read from the same BAR, or a device status poll, be needed before mutating descriptors the device may still own and before re-enabling the queue?
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+ +/* +* Reclaim all outstanding descriptors between next_to_clean and +* next_to_use. Under txq_lock there is at most one in-flight +* descriptor, but iterate the full range for robustness. +*/ +while (txq->next_to_clean != txq->next_to_use) { + tx_desc =NBL_CHAN_TX_RING_TO_DESC (txq, + txq->next_to_clean); +WRITE_ONCE (tx_desc->flags,0 ); + txq->next_to_clean =
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 506
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+NBL_NEXT_ID (txq->next_to_clean, + chan_info->num_txq_entries -1 ); + } + +/* +* Hardware tail_ptr counter is cleared by QUEUE_RST. Reset +* software counter to match so the next doorbell update does +* not produce a false 16-bit wrap delta. +*/ + txq->tail_ptr =0 ;
[Severity: High]tail_ptr is reset to 0 here, but next_to_use and next_to_clean keep their pre-timeout values. Can this leave the ring index and the doorbell counter permanently out of step?
Everywhere else the two advance together:
nbl_chan_alloc_all_tx_bufs():
txq->next_to_clean = 0; txq->next_to_use = 0; txq->tail_ptr = 0;
nbl_chan_update_txqueue():
txq->next_to_use = NBL_NEXT_ID(txq->next_to_use, chan_info->num_txq_entries - 1); txq->tail_ptr++;
After a timeout on slot X the reclaim loop above leaves next_to_use == next_to_clean == X + 1 while tail_ptr == 0.
The next send then writes descriptor X + 1 and rings the doorbell with tail_ptr == 1. If QUEUE_RST cleared the hardware fetch pointer as the comment states, the device looks at slot 0, whose flags the reclaim loop just zeroed, while nbl_chan_kick_tx_ring() polls descriptor X + 1 for NBL_CHAN_TX_DESC_USED, times out again and re-enters this same recovery. Would that make every subsequent nbl_chan_send_msg() return -ETIMEDOUT?
And if QUEUE_RST does not clear the hardware counter, does writing tail_ptr = 0 produce exactly the bogus 16-bit delta the comment is trying to avoid?
Should next_to_use and next_to_clean be reset to 0 here as well?
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 510
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+ +/* Re-enable queue with current ring base and size */ +nbl_chan_config_queue (chan_mgt, chan_info, true); +}
[Severity: Medium]
The commit message states:
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.
Does this recovery path match that description? It issues stop_mailbox_txq() and config_mailbox_txq() at runtime from the send path, and chan_info->active is only cleared at the very end of nbl_chan_teardown_queue(), so active is true throughout.
Related to that, nbl_chan_teardown_queue() calls nbl_chan_stop_queue() without taking txq_lock, and it does so even when the drain times out:
if (!ret) {
dev_warn(chan_mgt->common->dev,
"teardown: inflight tx drain timeout\n");
ret = -ETIMEDOUT;
}
...
/* After all TX drained, stop hardware queue */
nbl_chan_stop_queue(chan_mgt);Can teardown's 4-dword QINFO sequence then interleave with a sender still executing the stop + config sequence above, leaving QUEUE_EN=1 on a ring the driver considers torn down?
Quoted 16 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +16
-0+ +static int nbl_chan_kick_tx_ring (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_chan_ring *txq = &chan_info->txq; +struct device *dev = chan_mgt->common->dev; +int max_retries =NBL_CHAN_TX_WAIT_TIMES ; +struct nbl_chan_tx_desc *tx_desc; +int retry_count =0 ; +u16 msg_type; + +nbl_chan_update_tail_ptr (hw_ops, chan_mgt->hw_ops_tbl->priv, + txq->tail_ptr,NBL_MB_TX_QID ); + + tx_desc =NBL_CHAN_TX_RING_TO_DESC (txq, txq->next_to_clean);
[ ... ]
Quoted 22 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +22
-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 ; + } +usleep_range (NBL_CHAN_TX_WAIT_US ,NBL_CHAN_TX_WAIT_US_MAX ); + } + + txq->next_to_clean = txq->next_to_use; + +return 0 ; +}
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static void nbl_chan_recv_ack_msg (void *priv,u16 srcid,u16 msgid,void *data, +u32 data_len) +{
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +8
-0+if (w_status !=NBL_MBX_STATUS_WAITING ) { +mutex_unlock (&chan_info->pending_lock); +dev_err_ratelimited (dev, +"Skip ack invalid status, wait msgtype:%u idx:%u status:%d ack msgtype:%u msgid:%u datalen:%u\n" , + w_msgtype, w_msgidx, w_status, + ack_msgtype, ack_msgid, ack_datalen); +return ; + }
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 671
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +7
-0+ack_done: +/* Guarantee payload data finished before acked flag visible */ +smp_wmb (); +WRITE_ONCE (wait_head->acked,1 ); +mutex_unlock (&chan_info->pending_lock); +wake_up (&wait_head->wait_queue); +}
[Severity: Medium]
This completes the slot by setting acked = 1 but leaves wait_head->status at NBL_MBX_STATUS_WAITING. Can that make the timeout paths in nbl_chan_send_msg() discard a delivered ACK?
The interrupt path tests only status:
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);So if the RX cleanup work runs the code above in the window between wait_event_timeout() evaluating its condition for the last time and the sender taking pending_lock, the sender sees WAITING, clears acked and returns -ETIMEDOUT for a request that was answered.
The polling path has a similar window: it checks acked, then sleeps NBL_CHAN_TX_WAIT_ACK_US_MIN..MAX, and after the last iteration falls straight through to ret = -ETIMEDOUT with no further locked check, so an ACK arriving during that final ~1 ms sleep is dropped.
Since status also stays WAITING, would a duplicate ACK for the same msgid still pass all the validation above and memcpy into the requester's response buffer a second time?
Should the ACK handler move the slot to a completed state (or should the timeout transitions re-check acked under pending_lock)?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+ +static int nbl_chan_send_msg (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_send_info *chan_send) +{
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -10,6 +10,156 @@
[ ... ]
Quoted 18 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +18
-0+static void nbl_hw_stop_mailbox_txq (struct nbl_hw_mgt *hw_mgt) +{ +struct nbl_mailbox_qinfo_cfg_table cfg_tbl; + +memset (&cfg_tbl,0 ,sizeof (cfg_tbl)); + cfg_tbl.data[3 ] =FIELD_PREP (NBL_MAILBOX_QINFO_CFG_QUEUE_RST_MASK ,1 ); +nbl_hw_write_mbx_regs (hw_mgt,NBL_MAILBOX_QINFO_CFG_TX_TABLE_ADDR , + cfg_tbl.data,sizeof (cfg_tbl)); +} + +static void nbl_hw_get_host_pf_mask (struct nbl_hw_mgt *hw_mgt,u32 *pf_mask) +{ +nbl_hw_rd_regs_lock (hw_mgt,NBL_PCIE_HOST_K_PF_MASK_REG , pf_mask, +sizeof (*pf_mask)); +} + +static void nbl_hw_cfg_mailbox_qinfo (struct nbl_hw_mgt *hw_mgt,u16 func_id, +u8 bus,u8 devid,u8 function)
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 150
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+{ +u32 data =0 ; + + 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); +nbl_hw_wr_regs_lock (hw_mgt,NBL_MAILBOX_QINFO_MAP_REG_ARR (func_id), + &data, +sizeof (data)); +}
[Severity: Medium]
This builds the whole dword from FUNCTION/DEVID/BUS and writes it, but the MSI-X fields share the same dword:
#define NBL_MAILBOX_QINFO_MAP_MSIX_IDX_MASK GENMASK(28, 16)
#define NBL_MAILBOX_QINFO_MAP_MSIX_IDX_VALID_MASK BIT(29)
Does this zero the mailbox MSI-X routing of the entries it rewrites?
nbl_chan_cfg_qinfo_map_table() programs an entry for every unmasked PF, not just the local function:
for (func_id = 0; func_id < NBL_MAX_PF; func_id++) {
if (!(pf_mask & (1 << func_id)))
hw_ops->cfg_mailbox_qinfo(p, func_id, bus,
devid, func_id);
}so re-probing one PF would clear MSIX_IDX and MSIX_IDX_VALID for its already-bound siblings. Those siblings keep NBL_CHAN_IRQ_RDY set, so each synchronous send would wait out NBL_CHAN_ACK_WAIT_TIME and fail with -ETIMEDOUT until they are re-bound.
The commit message also says:
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
Where is the read-modify-write on the QINFO map entry? This helper only writes. Should it read the entry first and preserve the MSI-X fields?
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +11
-0+ +static struct nbl_hw_ops hw_ops = { + .update_mailbox_queue_tail_ptr = nbl_hw_update_mailbox_queue_tail_ptr, + .config_mailbox_rxq = nbl_hw_config_mailbox_rxq, + .config_mailbox_txq = nbl_hw_config_mailbox_txq, + .stop_mailbox_rxq = nbl_hw_stop_mailbox_rxq, + .stop_mailbox_txq = nbl_hw_stop_mailbox_txq, + .get_host_pf_mask = nbl_hw_get_host_pf_mask, + .cfg_mailbox_qinfo = nbl_hw_cfg_mailbox_qinfo, + +};
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0
-0@@ -11,5 +11,61 @@
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +6
-0+/* MAILBOX qinfo_map_table */ +#define NBL_MAILBOX_QINFO_MAP_FUNCTION_MASK GENMASK(2, 0) +#define NBL_MAILBOX_QINFO_MAP_DEVID_MASK GENMASK(7, 3) +#define NBL_MAILBOX_QINFO_MAP_BUS_MASK GENMASK(15, 8) +#define NBL_MAILBOX_QINFO_MAP_MSIX_IDX_MASK GENMASK(28, 16) +#define NBL_MAILBOX_QINFO_MAP_MSIX_IDX_VALID_MASK BIT(29)
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 4/10 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
The Resource layer owns chip-module 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_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 (gap 1024/512/256 for 1/2/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). The dispatch layer serializes all resource ops through ops_mutex_lock and routes non-control PF requests to the control PF via mailbox RPC, so these helpers are never invoked directly on a non-control device.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 2 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 22 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 70 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 + .../nbl_hw_leonis/nbl_resource_leonis.c | 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 | 21 +- .../nbl/nbl_include/nbl_def_hw.h | 16 + .../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, 736 insertions(+), 2 deletions(-) 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 +69 -1
108 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +14 -0
@@ -67,5 +67,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 -1
@@ -11,11 +11,26 @@#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;struct device *dev; -u32 msg_enable;u16 vsi_id;u8 eth_id;u8 logic_eth_id;
@@ -25,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 {
@@ -40,6 +57,8 @@ struct nbl_hash_tbl_key {void nbl_common_destroy_wq (struct nbl_common_info *common);int nbl_common_create_wq (struct nbl_common_info *common); +int nbl_common_func_id_to_rel_pf_id (struct nbl_common_info *common,u32 pf_id, +u32 *rel_pf_id);struct nbl_hash_tbl_mgt *nbl_common_init_hash_table (struct nbl_hash_tbl_key *key);void nbl_common_remove_hash_table (struct nbl_hash_tbl_mgt *tbl_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +16 -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 {
@@ -35,11 +36,26 @@ struct nbl_hw_ops {* 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 (*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); };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 v27 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] DISCARDED (baseline decision false): claim that the commit message's statement 'The dispatch layer serializes all resource ops…
- [Low] Kernel-doc/declaration mismatch for the new hw op: in drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h the…
--
net/nebula-matrix: add common resource implementation
This adds the chip-independent resource layer for the nbl driver, which owns the PF/eth/vsi identity tables and the lookup helpers between vsi_id, func_id, eth_id and pf_id. It also adds two new hardware ops, get_fw_eth_map() and get_board_info(), plus get_real_bus(), used during control-PF initialization.
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/Makefile +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +5
-0@@ -35,11 +36,26 @@ struct nbl_hw_ops {* 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 (*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); +/**
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h struct nbl_hw_ops { · line 58
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10
-0+* 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);
[Severity: Low]
This isn't a bug, but the kernel-doc block for get_board_info in nbl_def_hw.h documents @board_info while the callback is declared with the parameter named board:
* @board_info: output pointer for board info structure ... void (*get_board_info)(struct nbl_hw_mgt *hw_mgt, struct nbl_board_port_info *board);
Would make W=1 warn here with "Excess function parameter 'board_info' description" and "Function parameter or struct member 'board' not described"?
The implementation in nbl_hw_leonis.c uses the documented name:
static void nbl_hw_get_board_info(struct nbl_hw_mgt *hw_mgt,
struct nbl_board_port_info *board_info)
so renaming the declared parameter to board_info would keep the three consistent. The mismatch is still present at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 5/10 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Introduce nbl_interrupt module to manage the driver-wide global MSI-X vector index space (intr_net_bmap / intr_other_bmap) and program the chip-internal MSI-X mapping registers.
Core interfaces:
1. cfg_msix_map
Allocates global MSI-X indices from independent net/other interrupt bitmaps. All coherent DMA buffers for the new configuration are allocated upfront; old hardware state is torn down only after all allocations succeed to avoid interrupt loss. Writes the MSI-X table DMA address and control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP.
Physical PCI MSI-X vector allocation (pci_alloc_irq_vectors etc.) is handled separately by the device layer; the corresponding nbl_dev_init_interrupt_scheme() entry point is added in a later patch in this series.
2. destroy_msix_map
Recycles global MSI-X vectors, clears hardware MSI-X mappings, releases coherent DMA memory and the interrupt descriptor array. Step 0 disables mailbox IRQ routing before teardown; Step 1 masks each vector. A two-stage hardware teardown retains the live DMA address while clearing VALID, sleeps 1 ms to allow in-flight table fetch DMA to quiesce (best-effort; no idle status register exists), then zeroes the entry before freeing 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 does not require a configured MSI-X map, so destroy_msix_map can always clear the route before releasing vectors.
4. cfg_msix_info
Programs PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with strict enable/teardown ordering to avoid 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 the coherent tables.
VF func_ids are not supported: nbl_res_func_id_to_bdf() returns -EOPNOTSUPP for IDs beyond the 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 | 153 ++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 ++ .../nbl_hw_leonis/nbl_resource_leonis.c | 31 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 11 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 544 ++++++++++++++++++ .../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 | 10 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../nbl/nbl_include/nbl_include.h | 1 + 13 files changed, 885 insertions(+), 6 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 +150 -3
192 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 +28 -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,24 @@ 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 ; + +/* +* 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); +/* -* No resource release here because all memory uses devm managed -* allocation +* Note: the per-function interrupts arrays (kcalloc) are freed +* by nbl_intr_mgt_stop() above. The coherent MSI-X tables +* (dmam_alloc_coherent) and intr_mgt itself (devm_kzalloc) are +* 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_hw_reg.h +11 -0
@@ -57,6 +57,17 @@ static inline void nbl_mbx_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)writel (value, hw_mgt->mailbox_bar_hw_addr + reg); } +/* +* Only call this when has_ctrl=true, which maps enough space +* (bar_len - 8192) to cover NBL_HW_DUMMY_REG (0x1300904). +* The flow/design guarantees this is only called in the +* has_ctrl path. +*/ +static inline void nbl_flush_writes (struct nbl_hw_mgt *hw_mgt) +{ +nbl_hw_rd32 (hw_mgt,NBL_HW_DUMMY_REG ); +} +static inline u32 nbl_mbx_rd32 (struct nbl_hw_mgt *hw_mgt,u64 reg) {return readl (hw_mgt->mailbox_bar_hw_addr + reg);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +544 -0
544 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 +10 -0
@@ -12,6 +12,14 @@ struct nbl_board_port_info;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,dma_addr_t dma_addr,u8 bus, +u8 devid,u8 function); +void (*cfg_msix_info)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,u16 interrupt_id,u8 bus, +u8 devid,u8 function, +bool net_msix_mask_en); +void (*flush_write)(struct nbl_hw_mgt *hw_mgt);void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,u16 tail_ptr,u8 txrx); void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
@@ -44,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 global_vec_id);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 v27 net-next 05/10] net/nebula-matrix: add intr resource implementation
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: 0 · Medium: 1 · Low: 3
- [Medium] Coherent MSI-X map table is released based on a timed guess, not on proven device quiescence.
- [Low] Two in-tree comments state mutually exclusive ownership models for the coherent MSI-X tables.
- [Low] The 'Step 1' comment in __nbl_res_intr_destroy_msix_map() says 'mask each MSIX vector in hardware first', but the call it annotates…
- [Low] Reported concern: nbl_intr_mgt_stop() publishes the 'dead' state with a plain store 'res_mgt->intr_mgt = NULL' outside intr_mgt->lock,…
--
net/nebula-matrix: add intr resource implementation
This adds the nbl_interrupt module which owns the driver-wide global MSI-X index space and programs the chip-internal MSI-X map/info registers. It adds cfg_msix_map, destroy_msix_map, set_mailbox_irq and cfg_msix_info, plus nbl_intr_mgt_start()/nbl_intr_mgt_stop() wired into the leonis resource layer.
A few questions about the teardown path and about some of the comments below.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -91,6 +115,124 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
[ ... ]
Quoted 25 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +25
-0+static void nbl_hw_cfg_msix_info (struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,u16 interrupt_id,u8 bus, +u8 devid,u8 function,bool msix_mask_en) +{ +u32 host_msix_fid =0 ; +struct nbl_host_msix_info msix_info; + +memset (&msix_info,0 ,sizeof (msix_info)); +if (valid) { + host_msix_fid = +FIELD_PREP (NBL_PCOMPLETER_HOST_MSIX_FID_TABLE_FID_MASK , + func_id) | +FIELD_PREP (NBL_PCOMPLETER_HOST_MSIX_FID_TABLE_VLD_MASK , +1 ); + + msix_info.data[1 ] = +FIELD_PREP (NBL_HOST_MSIX_INFO_FUNCTION_MASK , function) | +FIELD_PREP (NBL_HOST_MSIX_INFO_DEVID_MASK , devid) | +FIELD_PREP (NBL_HOST_MSIX_INFO_BUS_MASK , bus) | +FIELD_PREP (NBL_HOST_MSIX_INFO_VALID_MASK ,1 ); + +if (msix_mask_en) + msix_info.data[1 ] |= +FIELD_PREP (NBL_HOST_MSIX_INFO_MSIX_MASK_EN_MASK ,1 ); + }
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +0
-0
[ ... ]
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +13
-0@@ -328,8 +337,24 @@ 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 ; + +/* +* 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 360
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +5
-2+/* -* No resource release here because all memory uses devm managed -* allocation +* Note: the per-function interrupts arrays (kcalloc) are freed +* by nbl_intr_mgt_stop() above. The coherent MSI-X tables +* (dmam_alloc_coherent) and intr_mgt itself (devm_kzalloc) are +* released by devres after this function returns. */ }
[Severity: Low]
Is this comment still accurate?
nbl_intr_mgt_stop() loops over every function id and calls __nbl_res_intr_destroy_msix_map(), which itself calls dmam_free_coherent() on msix_map_table->base_addr and then sets it to NULL. So by the time nbl_res_remove_leonis() returns, there should be no devres-managed coherent MSI-X table left for devres to release.
The kernel-doc on nbl_res_intr_cfg_msix_map() states the opposite ownership model:
* Old MSIX table memory is explicitly freed inside the locked
* destroy path after a bounded DMA quiesce sleep (best-effort;
* hardware provides no idle status register), so repeated
* reconfiguration does not accumulate devres-managed DMA memory.
The commit message carries the same wording as the comment here, "It is called from nbl_res_remove_leonis() before devres releases the coherent tables."
Could these be reconciled so a later change does not drop the explicit dmam_free_coherent() on the assumption devres still owns the tables?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0@@ -0,0 +1,544 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 144
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+/* Step 0: disable mailbox IRQ routing before tearing down map */ +__nbl_res_intr_set_mailbox_irq (res_mgt, func_id,0 , false); + +/* Step 1: mask each MSIX vector in hardware first */ +for (i =0 ; i < intr_num; i++) { + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, false, interrupts[i], +0 ,0 ,0 , false); + } + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv);
[Severity: Low]
Does this loop actually mask anything?
The call passes valid=false and msix_mask_en=false, and nbl_hw_cfg_msix_info() starts with:
memset(&msix_info, 0, sizeof(msix_info));
if (valid) {
...
}so for valid=false both host_msix_fid and msix_info.data[] stay zero and the writes to NBL_PCOMPLETER_HOST_MSIX_FID_TABLE() and NBL_PADPT_HOST_MSIX_INFO_REG_ARR() drive NBL_HOST_MSIX_INFO_MSIX_MASK_EN_MASK (BIT(17)) and NBL_HOST_MSIX_INFO_VALID_MASK (BIT(16)) to 0 and clear the FID VLD bit.
That invalidates the entry and turns mask-enable off rather than masking the vector. Would "invalidate each MSIX info entry" describe the step more accurately? The commit message has the same wording, "Step 1 masks each vector."
Quoted 38 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +38
-0+/* +* Stage 1 tear down: retain valid DMA address, ONLY clear +* VALID bit to avoid hardware torn read (VALID=1 & dma_addr=0). +*/ + hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func_id, + false, msix_map_table->dma,0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +/* +* Hardware provides no idle status register for the MSIX map +* DMA engine. Use a bounded sleep to mitigate the race between +* posted MMIO disable writes and an ongoing in-flight table +* read DMA. +* +* This is best-effort, not a guarantee: a table fetch already +* issued before the VALID clear was observed can complete after +* this sleep. On the normal teardown path the mailbox channel +* is stopped before this function runs, so no new interrupts +* can trigger table fetches. On the residual cleanup path in +* nbl_intr_mgt_stop(), a longer global quiesce is applied +* after all functions are torn down. +*/ +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); + +/* safe to release global vector IDs, pcompler no longer reads table */ +nbl_intr_release_bitmap (res_mgt, interrupts, intr_num); + +/* +* Stage 2: hardware has quiesced MSIX table DMA access, fully +* zero the MSIX map entry safely now. +*/ + hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func_id, + false,0 ,0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +/* +* Now safe to release the MSIX DMA coherent memory. Hardware +* DMA has quiesced after the sleep above, so no IOMMU fault
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 193
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+* risk remains. +*/ +if (msix_map_table->base_addr) { +dmam_free_coherent (dev, msix_map_table->size, + msix_map_table->base_addr, + msix_map_table->dma); + msix_map_table->base_addr =NULL ; + msix_map_table->dma =0 ; + msix_map_table->size =0 ; + }
[Severity: Medium]
Can the coherent table be freed here while the pcompleter still has a table fetch outstanding?
The two comments in __nbl_res_intr_destroy_msix_map() disagree with each other. The first says:
* This is best-effort, not a guarantee: a table fetch already
* issued before the VALID clear was observed can complete after
* this sleep.
and a few lines later:
* Hardware DMA has quiesced after the sleep above, so no IOMMU
* fault risk remains.
followed by dmam_free_coherent() on the buffer the device DMA-reads.
If a fetch does land after the free, with an IOMMU the read hits an unmapped IOVA and produces a DMAR/SMMU fault; without one it reads recycled memory whose bytes are interpreted as an MSI-X map entry (NBL_MSIX_MAP_VALID_MASK plus the 13-bit NBL_MSIX_MAP_INDEX_MASK), which could steer an interrupt to a global vector now owned by a different function.
The table size does not depend on the request:
tmp_msix_tbl->size = sizeof(struct nbl_msix_map) * NBL_MSIX_MAP_TABLE_MAX_ENTRIES;
Since the allocation is a fixed 2 KiB regardless of num_net_msix / num_others_msix, would it be simpler to allocate the table once per function and rewrite the entries in place, so the free/realloc cycle, the timed sleeps and the admitted race all go away?
The commit message describes the same mechanism, "sleeps 1 ms to allow in-flight table fetch DMA to quiesce (best-effort; no idle status register exists), then zeroes the entry before freeing memory."
[ ... ]
Quoted 24 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +24
-0+void nbl_intr_mgt_stop (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +u16 func_id; +int ret; + +if (!intr_mgt) +return ; + +mutex_lock (&intr_mgt->lock); +for (func_id =0 ; func_id <NBL_MAX_FUNC ; func_id++) { +if (intr_mgt->func_intr_res[func_id].interrupts) { +dev_info (res_mgt->common->dev, +"intr_mgt_stop: destroying leftover map for func %u\n" , + func_id); + ret =__nbl_res_intr_destroy_msix_map (res_mgt, + func_id); +if (ret) +dev_warn (res_mgt->common->dev, +"intr_mgt_stop: destroy map for func %u failed: %d\n" , + func_id, ret); + } + } +mutex_unlock (&intr_mgt->lock);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 541
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+ +/* +* Global quiesce after all functions are torn down. Each +* destroy has an internal 1ms sleep between Stage 1 (clear +* VALID) and Stage 2 (zero dma_addr), but Stage 2 itself has +* no trailing sleep. This final wait covers the last +* function's Stage 2 and any straggler DMA from +* concurrently-torndown functions. +*/ +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US );
[Severity: Medium]
Does this final usleep_range() still cover anything?
The loop above has already called __nbl_res_intr_destroy_msix_map() for every func_id, and each of those calls ends with dmam_free_coherent() on that function's table. By the time this sleep runs there is no coherent table left that a straggler DMA could safely land in, so the wait appears to be after the window the comment says it protects.
Should this wait happen before the per-function dmam_free_coherent() instead, or is it simply not needed?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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 setup the full datapath pipeline, including packet engines, scheduler, buffer stores, queue manager, port traffic shaping, and flow control, plus the driver_status hardware flag consumed by firmware.
This patch introduces hw_ops.init_module/deinit_module and corresponding resource_ops entry points. The actual invocation path for these callbacks lands in a subsequent control device initialization patch; only the ops registration is added here.
DP sub-init modules (called from nbl_dp_init()):
- dped, uped: Data/User Packet Engine Driver
- dsch: Scheduler core (qid limit, 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
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() carry an explicit has_ctrl guard for defense-in-depth, matching the sibling resource ops, even though the dispatch layer only assigns these ops to NBL_DISP_CTRL_LVL_MGT.
--- .../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 | 586 +++++++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 211 +++++++ .../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, 873 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 +585 -1
610 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +211 -0
234 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 v27 net-next 06/10] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 0
- [Medium] No hardware unwind path exists for the chip-wide state armed by nbl_hw_init_module() (nbl_hw_leonis.c:681), neither on init failure…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds the Leonis chip-wide init/deinit implementation, programming the datapath pipeline (packet engines, scheduler, buffer stores, queue manager, port shaping and flow control) plus the driver_status flag read by firmware. The new hw_ops.init_module/deinit_module and the matching resource_ops entry points are registered here, with the invocation path landing in a later patch.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -115,6 +115,585 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
[ ... ]
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +12
-0+static int nbl_shaping_eth_init (struct nbl_hw_mgt *hw_mgt,u8 eth_id,u8 speed) +{ +struct nbl_shaping_dvn_dport_u dvn_dport = {0 }; +struct nbl_shaping_dport_u dport = {0 }; +u32 rate, half_rate; +u32 depth; +u64 low_val, high_val; + +switch (speed) { +case NBL_FW_PORT_SPEED_100G : + rate =100000 ; +break ;
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5
-0+default : +dev_err (hw_mgt->common->dev, +"Unsupported port speed %u for eth%u\n" , speed, eth_id); +return -EINVAL ; + }
[ ... ]
Quoted 36 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +36
-0+/* 3. commit: set valid last */ + low_val =FIELD_PREP (NBL_DPORT_VALID_MASK ,1 ); + dport.data[0 ] |=lower_32_bits (low_val); + + low_val =FIELD_PREP (NBL_DPORT_VALID_MASK ,1 ); + dvn_dport.data[0 ] |=lower_32_bits (low_val); + +nbl_hw_wr_regs (hw_mgt,NBL_SHAPING_DPORT_REG (eth_id), dport.data, +sizeof (dport)); +nbl_hw_wr_regs (hw_mgt,NBL_SHAPING_DVN_DPORT_REG (eth_id), + dvn_dport.data,sizeof (dvn_dport)); +spin_unlock (&hw_mgt->reg_lock); +return 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++) { +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));
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static int nbl_ustore_init (struct nbl_hw_mgt *hw_mgt,u8 eth_num) +{
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+if (WARN_ON (eth_num !=1 && eth_num !=2 && eth_num !=4 )) +return -EINVAL ;
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6
-0+ fc_th |=FIELD_PREP (NBL_DSTORE_D_DPORT_FC_FC_EN_MASK ,1 ); +nbl_hw_wr_regs (hw_mgt,NBL_DSTORE_D_DPORT_FC_TH_REG (i), &fc_th, +sizeof (fc_th)); +spin_unlock (&hw_mgt->reg_lock); + } +}
[ ... ]
Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +19
-0+static int nbl_dp_init (struct nbl_hw_mgt *hw_mgt,u8 speed,u8 eth_num) +{ +int ret; + +nbl_dped_init (hw_mgt); +nbl_uped_init (hw_mgt); + ret =nbl_shaping_init (hw_mgt, speed); +if (ret) +return ret; +nbl_dsch_qid_max_init (hw_mgt); + ret =nbl_ustore_init (hw_mgt, eth_num); +if (ret) +return ret; +nbl_dstore_init (hw_mgt, speed); +nbl_dvn_init (hw_mgt, speed); +nbl_uvn_init (hw_mgt); +nbl_uqm_init (hw_mgt); +return 0 ; +}
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +14
-0+/* +* This design is intentional. Setting driver status to false is the +* official teardown mechanism: it notifies firmware to perform full +* cleanup of all per-PF hardware state, including qinfo registers. +* An inverse helper would duplicate work that the firmware already +* does, and would add error-path complexity for no benefit. We keep +* the deinit path minimal and rely on firmware cleanup for correctness, +* including abnormal hardware reset scenarios. +*/ +static void nbl_hw_deinit_module (struct nbl_hw_mgt *hw_mgt) +{ +nbl_hw_set_driver_status (hw_mgt, false); +/* ensure registers written */ +nbl_flush_writes (hw_mgt);
[ ... ]
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 690
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+static int nbl_hw_init_module (struct nbl_hw_mgt *hw_mgt,u8 eth_speed, +u8 eth_num) +{ +int ret; + + ret =nbl_dp_init (hw_mgt, eth_speed, eth_num); +if (ret) +return ret; +nbl_intf_init (hw_mgt); +nbl_hw_set_driver_status (hw_mgt, true);
[Severity: Medium]
nbl_hw_init_module() can return an error after a good part of the chip has already been programmed, and nothing puts those registers back. There are two failure points inside nbl_dp_init():
nbl_shaping_init() -> nbl_shaping_eth_init() returns -EINVAL from the switch default for any speed outside 10/25/50/100G. By then the ports earlier in the eth_bitmap loop have already been committed with VALID=1, and NBL_DSCH_PSHA_EN plus the NBL_SHAPING_NET_REG() clearing loop are skipped.
nbl_ustore_init() returns -EINVAL fromWARN_ON(eth_num != 1 && eth_num != 2 && eth_num != 4) after DPED, UPED, shaping and DSCH were already programmed.
The speed comes from firmware, read by nbl_hw_get_board_info() out of NBL_FW_BOARD_DW3, so a value outside enum nbl_fw_port_speed reaches nbl_shaping_eth_init() without any earlier check.
In both cases the error is propagated before nbl_hw_set_driver_status(hw_mgt, true), so firmware is never told a driver attached and the firmware-side cleanup that deinit relies on is not triggered either.
Should nbl_dp_init() unwind the sub-modules it has already programmed, or should eth_speed and eth_num be validated before the first register write?
On the teardown side, the comment above nbl_hw_deinit_module() says setting driver status to false makes firmware "perform full cleanup of all per-PF hardware state, including qinfo registers", but the state this patch programs is chip-wide rather than per-PF:
shaping DPORT/DVN_DPORT entries with VALID=1 NBL_DSCH_PSHA_EN
USTORE per-port drop threshold EN DSTORE DISC_BP_TH EN and per-port FC_EN DVN/UVN relaxed-ordering flags
UVN prefetch init and queue err mask UQM que_type
Most of those are programmed read-modify-write, for example:
nbl_hw_rd_regs(hw_mgt, NBL_DSTORE_DISC_BP_TH, &bp_th, sizeof(bp_th)); bp_th |= FIELD_PREP(NBL_DSTORE_DISC_BP_TH_EN_MASK, 1); nbl_hw_wr_regs(hw_mgt, NBL_DSTORE_DISC_BP_TH, &bp_th, sizeof(bp_th));
so after an unbind or a failed control PF probe, do these enables stay armed and get carried into the next attach, or into another consumer such as vfio-pci? Also, the relaxed-ordering bits are derived from the PCIe DEVCTL value observed at init time only.
Could the commit message or the comment state which of these chip-wide registers firmware actually reverts, so the claim can be checked against the register list above?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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 | 117 ++++++++++++++++++ .../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, 231 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -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 +117 -0
117 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +23 -0
@@ -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
illusion.wang
maintainerPATCH v27 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). This eliminates race windows between local control paths and asynchronous remote mailbox RPC response handlers. Read-only get_vsi_id() / get_eth_id() only access static init-time metadata without concurrent modifications, so they require no locking.
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.
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.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 552 +++++++++++++++++- .../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, 576 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +551 -1
@@ -3,9 +3,186 @@* 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 ; +int ret; + +if (src_id >= disp_mgt->common->max_pf) { + 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 ; +int ret; + +if (src_id >= disp_mgt->common->max_pf) { + 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 +202,352 @@ 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 ; +} + +static void nbl_disp_chan_cfg_msix_map_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret; + +if (src_id >= disp_mgt->common->max_pf) { + 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 ; +} + +static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret; + +if (src_id >= disp_mgt->common->max_pf) { + 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 ; +bool en_msix; +u16 vector_id; +int ret; + +if (src_id >= disp_mgt->common->max_pf) { + 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; + +if (ret) + chan_ops->unregister_all_msg (p); +return ret; +} +static void nbl_disp_set_ctrl_bit (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) {set_bit (lvl, disp_mgt->ctrl_lvl);
@@ -34,9 +557,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 +581,16 @@ nbl_disp_setup_disp_mgt(struct nbl_common_info *common) {struct nbl_dispatch_mgt *disp_mgt;struct device *dev = common->dev; +int err; disp_mgt =devm_kzalloc (dev,sizeof (*disp_mgt),GFP_KERNEL );if (!disp_mgt)return ERR_PTR (-ENOMEM ); disp_mgt->common = common; + err =devm_mutex_init (common->dev, &disp_mgt->ops_mutex_lock); +if (err) +return ERR_PTR (err);return disp_mgt; }
@@ -104,14 +644,24 @@ 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 ; }void nbl_disp_remove (struct nbl_adapter *adapter) { -/* All dispatch objects allocated via devm */ +/* +* All dispatch objects allocated via devm +* All message handlers will be cleaned up inside channel layer +* nbl_chan_remove_common() at final device tear-down +*/ }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +2 -0
@@ -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 v27 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 7 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
Critical: 0 · High: 0 · Medium: 1 · Low: 6
- [Medium] All five new request helpers do 'ret = chan_ops->send_msg(...); if (ret < 0) return ret;' before the…
- [Low] Commit message attributes pre-existing resource-layer behaviour to this patch.
- [Low] The commit message justifies the new per-dispatch ops_mutex_lock with "This eliminates race windows between local control paths and…
- [Low] Over-broad error-path cleanup: on any partial registration failure, nbl_disp_setup_msg() calls chan_ops->unregister_all_msg(p),…
- [Low] Claimed namespace inconsistency: the five new responders validate the requester with 'src_id >= disp_mgt->common->max_pf' and pass…
- [Low] Claimed teardown race / use-after-teardown: the five responders registered by nbl_disp_setup_msg() are never unregistered…
- [Low] Claimed self-defeating RPC: destroy_msix_map (and cfg_msix_map, which internally destroys first) tear down the *requesting* function's…
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This adds mailbox RPC request/response handlers for five dispatch operations (configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id), resolves the dispatch ops table based on the PF control level, and introduces a per-dispatch mutex around the mutable hardware ops.
A few questions on the changelog and on the new code below.
Two paragraphs of the changelog describe behaviour that lives in nbl_hw/nbl_interrupt.c, which this patch does not touch:
Quoted 9 lines
destroy_msix_mapresponder 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_mappre-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.
[Severity: Low]
Are these two paragraphs describing this patch?
nbl_disp_chan_destroy_msix_map_resp() only validates src_id and calls res_ops->destroy_msix_map(), and nbl_disp_chan_cfg_msix_map_resp() only forwards to res_ops->cfg_msix_map().
The "Step 0" comment and the pre-allocate/swap sequence are in __nbl_res_intr_destroy_msix_map() and nbl_res_intr_cfg_msix_map() in nbl_hw/nbl_interrupt.c:
/* Step 0: disable mailbox IRQ routing before tearing down map */
__nbl_res_intr_set_mailbox_irq(res_mgt, func_id, 0, false);That file is unchanged here, and the earlier series commit that added the intr resource implementation already documents both behaviours. Could these two paragraphs be dropped or reworded to describe only the forwarding the responders do?
Quoted 22 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11
-0@@ -3,9 +3,186 @@* 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; +
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 29
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+ 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) {
[Severity: Medium]
The changelog says the early return here only passes through local transport errors:
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 32
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0Local transport errors (-ETIMEDOUT, -ESHUTDOWN, -EAGAIN, -EIO, -EINVAL) are passed through unchanged via an early "if (ret < 0) return ret" before the status switch.
Can this early return also pass through a value taken straight off the wire? On a successful ACK, nbl_chan_send_msg() returns READ_ONCE(wait_head->ack_err), and nbl_chan_recv_ack_msg() fills that field without any validation:
WRITE_ONCE(wait_head->ack_err,
(s32)le32_to_cpu(*(__le32 *)&payload[NBL_CHAN_ACK_RET_POS]));So any negative 32-bit value the peer puts in the ACK is returned to the caller as if it were a locally generated errno, bypassing the NBL_CHAN_RESP_* translation switch that follows. The same pattern is 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().
For get_vsi_id()/get_eth_id() the value reaches ERR_PTR():
nbl_dev_setup_common_dev() -> nbl_dev_init() -> nbl_core_init()
return ERR_PTR(ret);
nbl_probe() then only recognises the range [-4095,-1]:
adapter = nbl_core_init(pdev, ¶m);
if (IS_ERR(adapter)) { ... }
err = nbl_core_start(adapter);With a magnitude larger than MAX_ERRNO, IS_ERR() is false and nbl_core_start() runs on a bogus pointer. Would it make sense to clamp or reject out-of-range ack_err values in nbl_chan_recv_ack_msg(), or to sanitize the return in these helpers rather than passing it through?
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11
-0+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 ; + }
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +3
-0+static void nbl_disp_chan_get_vsi_id_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 line 69
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+if (src_id >= disp_mgt->common->max_pf) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + }
[Severity: Low]
This isn't a bug today, but the five responders check src_id against [0, max_pf) and then hand src_id to res_ops->* as a func_id, while the resource layer defines the PF func_id space relative to common->mgt_pf:
nbl_common_func_id_to_rel_pf_id() {
if (pf_id < common->mgt_pf)
return -EINVAL;
*rel_pf_id = pf_id - common->mgt_pf;
...
}Since nbl_core_init() sets common->mgt_pf = 0 unconditionally and nothing else writes it, the two ranges are identical, so there is no divergence at the moment. Would using nbl_common_func_id_to_rel_pf_id() in the responders keep the two layers in agreement if the "future non-zero management PF" mentioned in the kernel-doc is ever implemented?
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 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +7
-0@@ -25,6 +202,352 @@ 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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 221
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+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; +}
[Severity: Low]
The changelog says of ops_mutex_lock:
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 223
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0This eliminates race windows between local control paths and asynchronous remote mailbox RPC response handlers.
Is there a race window left to eliminate? The three wrapped ops already serialize themselves in nbl_interrupt.c:
nbl_res_intr_destroy_msix_map() {
mutex_lock(&intr_mgt->lock);
ret = __nbl_res_intr_destroy_msix_map(res_mgt, func_id);
mutex_unlock(&intr_mgt->lock);
}nbl_res_intr_set_mailbox_irq() does the same, and nbl_res_intr_cfg_msix_map() holds intr_mgt->lock across its allocate/destroy/swap sequence. The earlier series commit states "All public entry points (cfg/destroy/set_irq) take this lock internally; callers need not hold any upper-layer lock."
So this nests a second mutex around calls that are already mutually exclusive (in a consistent order, so no deadlock). Could the rationale be reworded, or the outer mutex dropped, if the intent is only defensive serialization?
[ ... ]
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) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+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);
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 364
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+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);
[Severity: Low]
Does the ACK here still reach the requester? This tears down the requesting function's map, and __nbl_res_intr_destroy_msix_map() disables that function's mailbox MSI-X route first:
/* Step 0: disable mailbox IRQ routing before tearing down map */
__nbl_res_intr_set_mailbox_irq(res_mgt, func_id, 0, false);The ACK is then sent over the mailbox whose interrupt was just disarmed, and the NBL_CHAN_IRQ_RDY branch of nbl_chan_send_msg() only waits on wait_event_timeout(). The same applies to cfg_msix_map, which destroys before reconfiguring.
Looking at the callers added later in the series, this appears to be
avoided: nbl_dev_disable_mailbox_irq() clears NBL_CHAN_IRQ_RDY before issuing the RPC, nbl_dev_stop() and the err_destroy_map path of nbl_dev_start() only call destroy_msix_map() after that, and nbl_dev_cfg_msix_map() runs before nbl_dev_enable_mailbox_irq() ever sets IRQ_RDY, so send_msg() takes the polling branch and consumes the ACK without an interrupt. Is that ordering an invariant worth documenting next to these responders, since it is what keeps them from timing out on an operation that succeeded?
[ ... ]
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +12
-0+static int nbl_disp_setup_msg (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; +int ret =0 ; +int _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + nbl_disp_chan_cfg_msix_map_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret;
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 549
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+if (ret) + chan_ops->unregister_all_msg (p); +return ret; +}
[Severity: Low]
Does this rollback destroy state the dispatch layer does not own? unregister_all_msg is nbl_chan_remove_msg_handler():
nbl_channel.c:nbl_chan_remove_msg_handler() {
if (!chan_mgt->handle_hash_tbl)
return;
nbl_common_remove_hash_table(chan_mgt->handle_hash_tbl);
chan_mgt->handle_hash_tbl = NULL;
}That frees the whole per-adapter handler table, including the channel layer's own NBL_CHAN_MSG_ACK handler registered in nbl_chan_setup_ops():
ret = nbl_chan_register_msg(chan_mgt, NBL_CHAN_MSG_ACK,
nbl_chan_recv_ack_msg, chan_mgt);
and leaves chan_mgt (alive until nbl_chan_remove_common()) with handle_hash_tbl == NULL, which nbl_chan_recv_msg() would pass into nbl_common_get_hash_node(), whose first statement is:
key_size = tbl_mgt->tbl_key.key_size;
with no NULL check. The failure itself is reachable, since nbl_chan_add_msg_handler() -> nbl_common_alloc_hash_node() can return -ENOMEM. Today nothing can crash, because on failure nbl_disp_init() returns the error and probe is aborted before the mailbox RX ring is ever set up, so no frame is received and no ACK is awaited.
There is no per-msg-type unregister in struct nbl_channel_ops, so a correct partial rollback cannot be expressed with the current interface. Would adding an unregister for a single msg_type, or simply leaving the already-registered handlers in place on failure, be preferable to tearing down the shared table?
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0@@ -104,14 +644,24 @@ 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; +
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 667
Quoted 9 lines
void
nbl_disp_remove(struct nbl_adapter *adapter){drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +5
-1-/* All dispatch objects allocated via devm */ +/* +* All dispatch objects allocated via devm +* All message handlers will be cleaned up inside channel layer +* nbl_chan_remove_common() at final device tear-down +*/ }
[Severity: Low]
Since the five responders registered by nbl_disp_setup_msg() are never unregistered, can one of them run after the resource layer has been stopped? In nbl_core_remove() the order is nbl_disp_remove() -> nbl_res_remove_leonis() (nbl_intr_mgt_stop() frees the per-function interrupt arrays and clears res_mgt->intr_mgt) -> nbl_chan_remove_common().
Reading the later commits in the series, this looks closed:nbl_dev_remove() runs first in nbl_core_remove(), and nbl_dev_remove_common_dev() does
cancel_work_sync(&common_dev->clean_mbx_task);
nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);which sets chan_info->shutdn, and nbl_chan_recv_msg() bails out on
if (READ_ONCE(chan_info->shutdn))
return;so no responder can execute once the mailbox queue is torn down. Is that dependency worth spelling out in the comment, i.e. that the safety of the no-op relies on the dev layer quiescing the channel before nbl_res_remove_leonis() runs, rather than on nbl_chan_remove_common()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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. Introduce 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() 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)
- 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 init (datapath pipeline, 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 first, then common dev. 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; the caller must ensure no new DMA is initiated after deinit (the mailbox channel is stopped first).
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 233 ++++++++++++++++++ .../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, 313 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 +233 -0
233 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 v27 net-next 09/10] net/nebula-matrix: add common/ctrl dev init/remove operation
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] nbl_dev_remove() (drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c) calls nbl_dev_remove_ctrl_dev() ->…
- [Medium] nbl_dev_remove_ctrl_dev() -> deinit_module() clears driver_status, which per nbl_hw_deinit_module()'s own documentation…
- [Low] If disp_ops->init_module() fails, nbl_dev_setup_ctrl_dev() returns the error and nbl_dev_init() unwinds only the common dev (goto…
- [Low] The int return of nbl_dev_remove_chan_queue() - which propagates nbl_chan_teardown_queue()'s -ETIMEDOUT, documented as 'callers must…
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This adds the nbl_dev core layer with nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() plus their teardown counterparts, and wires nbl_dev_init() / nbl_dev_remove() into nbl_core_init() / nbl_core_remove(). A few questions about the teardown ordering and the error paths below.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,233 @@
[ ... ]
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 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +11
-0+static int nbl_dev_remove_chan_queue (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; +int ret =0 ; + +if (chan_ops->check_queue_exist (priv, chan_type)) + ret = chan_ops->teardown_queue (priv, chan_type); + +return ret; +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 133
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9
-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 );
[Severity: Low]nbl_dev_remove_chan_queue() returns int, and it propagates the -ETIMEDOUT that nbl_chan_teardown_queue() reports when the inflight drain does not complete:
ret = wait_event_timeout(chan_info->inflight_wait,
atomic_read(&chan_info->inflight_tx_cnt) == 0,
msecs_to_jiffies(5000));
if (!ret) { ... ret = -ETIMEDOUT; }Both new callers, here and the err_cleanup path in nbl_dev_setup_common_dev(), discard that status, and nbl_dev_remove() is void, so nbl_core_remove() goes on to destroy the workqueue and the message handler table while devres later frees the dmam_alloc_coherent() mailbox rings.
As far as I can tell this is not reachable in the current tree: every nbl_chan_send_msg() caller in the series runs either in the probe/remove thread itself or inside clean_mbx_task, and cancel_work_sync() runs just above, so inflight_tx_cnt is always 0 here today. Is the intent to keep the status unchecked once asynchronous senders (netdev/ethtool paths) are added, or should the timeout at least be logged?
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 145
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +12
-0+nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +} + +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;
[Severity: Low]
When init_module() fails there is no hardware rollback here, and nbl_dev_init() only unwinds the common dev (goto setup_ctrl_dev_fail -> nbl_dev_remove_common_dev()), so deinit_module() is never called.
nbl_hw_init_module() can fail partway through:
ret = nbl_dp_init(hw_mgt, eth_speed, eth_num); if (ret) return ret; nbl_intf_init(hw_mgt); nbl_hw_set_driver_status(hw_mgt, true);
and nbl_dp_init() programs nbl_dped_init()/nbl_uped_init() before the first call that can return an error (nbl_shaping_init(), and later nbl_ustore_init()).
Since nbl_hw_set_driver_status(hw_mgt, true) is only reached at the end, the driver_status true->false transition that the patch relies on for cleanup can never fire for this partially programmed chip-wide datapath state. Should this path either roll back explicitly or call deinit_module()?
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9
-0+ +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
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 164
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+* qinfo registers). The qinfo map programmed in setup_ctrl_dev is +* not explicitly cleared; firmware handles it on driver_status change. +*/ +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]
What happens to sibling PFs that are still bound when only the control PF is unbound?
nbl_dev_setup_chan_qinfo() -> nbl_chan_cfg_qinfo_map_table() programs the mailbox routing for every hardware-active func_id, i.e. chip-global state shared with the other PF driver instances.
Per the comment above, deinit_module() then makes firmware clean all per-PF hardware state including those qinfo registers, but only this adapter's mailbox queue is stopped afterwards by nbl_dev_remove_common_dev().
The resource layer already acknowledges that remote PFs can still be bound at this point:
/*
* 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.
*/
There is no refcount or cross-instance exclusion here, so after "echo <control PF BDF> > /sys/bus/pci/drivers/nbl/unbind" the sibling instances keep their mailbox rings armed and their software state marked active while their routing entries are gone; their next dispatch RPC (get_vsi_id, cfg/destroy_msix_map, set_mailbox_irq) can then only fail by ACK timeout. Is that intentional, or should control-PF teardown be serialized against still-bound siblings?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+int nbl_dev_init (struct nbl_adapter *adapter) +{
[ ... ]
Quoted 21 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +21
-0+ ret =nbl_dev_setup_common_dev (adapter); +if (ret) + goto setup_err; + +if (common->has_ctrl) { + ret =nbl_dev_setup_ctrl_dev (adapter); +if (ret) + goto setup_ctrl_dev_fail; + } + +return 0 ; +setup_ctrl_dev_fail: +nbl_dev_remove_common_dev (adapter); +setup_err: +return ret; +} + +/* +* Teardown order: ctrl dev first, then common dev. +* nbl_dev_remove_ctrl_dev() notifies firmware to clean all per-PF state +* (including qinfo registers), so subsequent common dev queue cleanup
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 233
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+* will not trigger PCIe master abort or invalid register access. +*/ +void nbl_dev_remove (struct nbl_adapter *adapter) +{ +struct nbl_common_info *common = &adapter->common; + +if (common->has_ctrl) +nbl_dev_remove_ctrl_dev (adapter); +nbl_dev_remove_common_dev (adapter); +}
[Severity: High]
Is this ordering the inverse of what the hardware layer asks for?
nbl_hw_deinit_module() documents the precondition:
/* 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. */
nbl_hw_set_driver_status(hw_mgt, false);
But nbl_chan_teardown_queue() is the only place the mailbox hardware queues are actually stopped and senders drained:
WRITE_ONCE(chan_info->shutdn, true); ... /* After all TX drained, stop hardware queue */ nbl_chan_stop_queue(chan_mgt);
and it runs after deinit_module() in this path:
nbl_dev_remove()
nbl_dev_remove_ctrl_dev()
disp_ops->deinit_module() /* driver_status = false */
nbl_dev_remove_common_dev()
nbl_dev_remove_chan_queue()
nbl_chan_teardown_queue() /* shutdn, drain, stop queue */
At the end of the series the remove path is nbl_remove() -> nbl_core_stop() -> nbl_core_remove() -> nbl_dev_remove(), and nbl_dev_stop() only frees the IRQ and the MSI-X map, so the mailbox rings are still enabled with posted RX descriptors when driver_status is cleared. Can firmware then wipe the routing/queue state while the chip can still DMA into those rings, for example for a message another PF sends to the control PF?
The commit message also states the opposite of the code:
No completion handshake exists in the
current hardware revision; the caller must ensure no new DMA is initiated after deinit (the mailbox channel is stopped first).
The mailbox channel is stopped last here, not first. Should the common dev teardown run before deinit_module(), or should nbl_dev_remove_ctrl_dev() stop the channel itself before calling deinit_module()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v27 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. Allocate MSI-X IRQ vectors via pci_alloc_irq_vectors()
3. Request mailbox interrupt and attach handler
(nbl_dev_clean_mailbox -> schedule cleanup work)
4. Enable hardware mailbox interrupt and mark channel interrupt ready (NBL_CHAN_IRQ_RDY)
On non-control PFs, VSI/ETH identity is fetched via mailbox RPC in nbl_dev_setup_common_dev() during probe, before start runs. The control PF's responder is reachable once its own probe has completed and the mailbox queue is operational.
nbl_dev_stop() tears down resources in the reverse order, with the 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. Free kernel-side MSI-X vectors via pci_free_irq_vectors()
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 -> err_cancel_work), so a failure at any stage leaves the device and kernel in a consistent state. Rollback failures are logged; 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.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 318 +++++++++++++++++- .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 18 + 4 files changed, 329 insertions(+), 11 deletions(-)
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 +307 -11
345 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 v27 net-next 10/10] net/nebula-matrix: add common dev start/stop operation
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: 5 · Low: 3
- [Medium] nbl_dev_setup_common_dev() (drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c:304-314) drops the `if…
- [Medium] nbl_dev_stop() (nbl_dev.c:510-521) and the nbl_dev_start() err_destroy_map unwind (nbl_dev.c:472-488) only log a failed…
- [Medium] nbl_dev_enable_mailbox_irq() (nbl_dev.c:80-99) publishes the software interrupt-mode flag before the hardware interrupt exists: it…
- [Medium] In nbl_dev_start() (nbl_dev.c:446-448) a failure of nbl_dev_cfg_msix_map() jumps to err_cancel_work, deliberately skipping…
- [Medium] The device is enabled with pcim_enable_device() in nbl_probe(), which makes MSI/MSI-X vector release devres-managed:…
- [Low] The err_destroy_map comment added to nbl_dev_start() (nbl_dev.c:480-481) states "If the RPC fails the device may remain…
- [Low] The comment in nbl_dev_init_msix_cnt() (nbl_dev.c:22-24) states that the mailbox vector is "allocated in nbl_dev_start() via…
- [Low] Several newly added call sites in nbl_dev.c have continuation lines that do not line up with the open parenthesis (checkpatch CHECK:…
--
net/nebula-matrix: add common dev start/stop operation
This adds nbl_dev_start() and nbl_dev_stop() to configure the hardware MSI-X map, allocate MSI-X vectors, request the mailbox interrupt and tear all of that down again. Thin nbl_core_start() / nbl_core_stop() wrappers are hooked into nbl_probe() and nbl_remove(). The VSI/ETH identity fetch in nbl_dev_setup_common_dev() is also changed to run unconditionally.
A few questions below on the interrupt enable ordering, the rollback paths and some of the new comments.
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@@ -17,6 +28,189 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; }
[ ... ]
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+static int nbl_dev_enable_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +u16 local_vec_id; + +if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num) +return 0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 99
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+ + local_vec_id = + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; + chan_ops->set_queue_state (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_IRQ_RDY , +NBL_CHAN_TYPE_MAILBOX , true); + +return disp_ops->set_mailbox_irq (dev_mgt->disp_ops_tbl->priv, + local_vec_id, true); +}
[Severity: Medium]
Is this ordering the reverse of the invariant documented a few lines below in nbl_dev_disable_mailbox_irq()? NBL_CHAN_IRQ_RDY is published here before the hardware interrupt is armed, and on a non-control PF set_mailbox_irq() is itself an ack-requesting mailbox RPC (nbl_disp_chan_set_mailbox_irq_req()).
With IRQ_RDY already set, nbl_chan_send_msg() takes the sleeping branch:
if (test_bit(NBL_CHAN_IRQ_RDY, chan_info->state)) {
while (!READ_ONCE(wait_head->acked)) {
ret = wait_event_timeout(wait_head->wait_queue, ...);That branch has no queue_work(clean_task) fallback, unlike the polling else-branch, so the ring is only drained by the very mailbox MSI-X this RPC is supposed to arm. nbl_hw_cfg_mailbox_qinfo() clears MSIX_IDX and MSIX_IDX_VALID at init and only nbl_hw_set_mailbox_irq() sets them again.
If the responder's nbl_disp_chan_set_mailbox_irq_resp() takes an error branch, it still sends the ack without arming the requester's routing:
if (src_id >= disp_mgt->common->max_pf) { err = NBL_CHAN_RESP_PERM_DENY; goto ack_out; }
...
ack_out:
nbl_chan_fill_ack_info(&chan_ack, src_id, NBL_CHAN_MSG_MAILBOX_SET_IRQ, msg_id, err, NULL, 0);Can that wakeup then be lost, so the sender burns the full NBL_CHAN_ACK_WAIT_TIME and reports -ETIMEDOUT instead of the remote error, with the late ack later hitting a slot already marked NBL_MBX_STATUS_TIMEOUT? That looks like exactly the "Channel waiting ack failed" / "Skip ack with invalid status" class of message the disable-path comment says it wants to avoid.
Would arming the hardware while still in polling mode and setting NBL_CHAN_IRQ_RDY afterwards be the mirror of the disable path?
[Severity: Low]
This isn't a bug, but the continuation line here is indented past the open parenthesis, which checkpatch flags as "Alignment should match open parenthesis". The same applies to the set_mailbox_irq() call in nbl_dev_disable_mailbox_irq(), the cfg_msix_map() call in nbl_dev_cfg_msix_map(), and the reworked get_eth_id() call in nbl_dev_setup_common_dev().
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+static int nbl_dev_init_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 197
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_common_info *common = dev_mgt->common; +int needed =0 ; +int err; +int i; + +for (i =0 ; i <NBL_MSIX_TYPE_MAX ; i++) + needed += msix_info->serv_info[i].num; + + err =pci_alloc_irq_vectors (common->pdev, needed, needed, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY );
[Severity: Low]
With this function added, is the existing comment in nbl_dev_init_msix_cnt() still accurate?
/* mailbox vector allocated in nbl_dev_start() via * nbl_dev_request_mailbox_irq() */
The vectors are allocated here by pci_alloc_irq_vectors(), while nbl_dev_request_mailbox_irq() only resolves an already allocated vector via pci_irq_vector() and attaches a handler with request_irq(). The matching release is likewise in nbl_dev_clear_interrupt_scheme(), not in nbl_dev_free_mailbox_irq(). The commit message itself lists allocation as step 2 and the IRQ request as step 3, so should that comment be updated to point at nbl_dev_init_interrupt_scheme()?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +5
-0+if (err <0 ) { +dev_err (common->dev, +"pci_alloc_irq_vectors failed, err = %d\n" , err); +return err; + }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 212
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+ +return 0 ; +} + +static void nbl_dev_clear_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_common_info *common = dev_mgt->common; + +pci_free_irq_vectors (common->pdev); +}
[Severity: Medium]nbl_probe() enables the device with pcim_enable_device(), which makes MSI-X release devres-managed: pci_alloc_irq_vectors() -> __pci_enable_msix_range() -> pci_setup_msi_context() -> pcim_setup_msi_release() registers pcim_msi_release(), and that action calls pci_free_irq_vectors() itself on detach.
Is the explicit call here safe in that case? The kernel-doc of pci_free_irq_vectors() in drivers/pci/msi/api.c says:
* WARNING: Do not call this function if the device has been enabled
* with pcim_enable_device(). In that case, IRQ vectors are automatically
* managed via pcim_msi_release() and calling pci_free_irq_vectors() can
* lead to double-free issues.
Today the second call appears to be absorbed by the !dev->msix_enabled early return in pci_disable_msix(), but should the driver either use unmanaged pci_enable_device() with explicit cleanup, or leave the release to the managed lifecycle?
[ ... ]
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-11@@ -99,17 +301,18 @@ static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)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); -if (common->has_ctrl) { - ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); -if (ret) - goto err_cleanup; - ret = disp_ops->get_eth_id (priv, common->vsi_id, - &common->eth_num, - &common->eth_id, - &common->logic_eth_id); -if (ret) - goto err_cleanup; - } +/* +* Even if has_ctrl=false (no dedicated control PF channel), we fetch
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter) · line 315
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* VSI/ETH info via regular mailbox message instead of dedicated +* control command. +*/ + ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); +if (ret) + goto err_cleanup; + ret = disp_ops->get_eth_id (priv, common->vsi_id, &common->eth_num, + &common->eth_id, &common->logic_eth_id); +if (ret) + goto err_cleanup;
[Severity: Medium]
Dropping the has_ctrl guard makes every non-control PF issue two synchronous mailbox RPCs from inside its own probe():
nbl_probe() -> nbl_core_init() -> nbl_dev_init() -> nbl_dev_setup_common_dev() -> nbl_disp_chan_get_vsi_id_req() -> nbl_chan_send_msg(dstid = common->mgt_pf = 0)
and the transport error propagates straight out:
ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send); if (ret < 0) return ret;
What happens if function 0 is not bound yet? The mailbox QINFO entries used to route a non-control PF's traffic are programmed only by the control PF:
nbl_chan_cfg_qinfo_map_table() {
hw_ops->get_host_pf_mask(p, &pf_mask);
for (func_id = 0; func_id < NBL_MAX_PF; func_id++)
if (!(pf_mask & (1 << func_id)))
hw_ops->cfg_mailbox_qinfo(p, func_id, bus, devid, func_id);
}and that is only reached from nbl_dev_setup_ctrl_dev(). So before PF0's probe has run, does the non-control PF get -ETIMEDOUT here and fail probe permanently, with no -EPROBE_DEFER and no retry?
This is reachable without special hardware, for example unbinding PF0 and then binding another PF, PF0 probe failing for an unrelated reason, or async_probe making PF1 race ahead of PF0.
The commit message says:
The control PF's responder is reachable once its own probe has completed and the mailbox queue is operational.
Should the identity fetch be deferred to a later point such as nbl_dev_start() or ndo_open(), or should probe return -EPROBE_DEFER when the manager PF has not answered? This cross-PF probe dependency also looks unrelated to the patch subject.
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0dev_mgt->common_dev = common_dev;nbl_dev_init_msix_cnt (dev_mgt);@@ -231,3 +434,96 @@ void nbl_dev_remove(struct nbl_adapter *adapter)nbl_dev_remove_ctrl_dev (adapter);nbl_dev_remove_common_dev (adapter); } + +/* ---------- Dev start process ---------- */
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 448
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+int nbl_dev_start (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +int cleanup_ret; +int ret; + + ret =nbl_dev_cfg_msix_map (dev_mgt); +if (ret) + goto err_cancel_work;
[Severity: Medium]
Does skipping nbl_dev_destroy_msix_map() on this branch leak resources on the manager PF?
On a non-control PF, cfg_msix_map is an ack-requesting RPC (nbl_disp_chan_cfg_msix_map_req()), and if (ret < 0) return ret; cannot tell "remote never configured" from "remote configured but the ack was lost or timed out". On the responder side the commit point has no rollback:
nbl_res_intr_cfg_msix_map() {
intr_mgt->func_intr_res[func_id].interrupts = tmp_interrupts;
...
hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
true, official_tbl->dma, common->hw_bus,
common->devid, common->function);
}so the coherent MSI-X map table, the interrupts[] array, the global vector IDs taken from intr_net_bmap/intr_other_bmap and an armed FUNCTION_MSIX_MAP entry all stay committed for the requesting function.
The requester never sends NBL_CHAN_MSG_DESTROY_MSIX_MAP afterwards, since nbl_probe() only runs nbl_core_remove() when nbl_core_start() fails:
core_start_err: nbl_core_remove(adapter);
Calling nbl_dev_destroy_msix_map() on this path looks harmless, as __nbl_res_intr_destroy_msix_map() returns 0 immediately when interrupts is NULL. Would jumping to err_destroy_map here be more consistent with the commit message claim that "a failure at any stage leaves the device and kernel in a consistent state"?
Quoted 24 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +24
-0+ + ret =nbl_dev_init_interrupt_scheme (dev_mgt); +if (ret) + goto err_destroy_map; + + ret =nbl_dev_request_mailbox_irq (dev_mgt); +if (ret) + goto err_destroy_map; + + ret =nbl_dev_enable_mailbox_irq (dev_mgt); +if (ret) + goto err_disable_irq; + +return 0 ; + +err_disable_irq: + cleanup_ret =nbl_dev_disable_mailbox_irq (dev_mgt); +if (cleanup_ret) +dev_err (dev_mgt->common->dev, +"rollback: disable mailbox IRQ failed: %d\n" , + cleanup_ret); +nbl_dev_free_mailbox_irq (dev_mgt); +err_destroy_map: +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 482
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* Destroy device-side MSI-X map BEFORE releasing kernel-side +* vectors. This masks all hardware vectors and clears the +* pcompleter map entry, so no MSI-X message can fire after +* pci_free_irq_vectors() releases the vectors. +* +* For non-control PFs this is a polling-mode mailbox RPC +* (IRQ_RDY already cleared by disable above, or never set). +* If the RPC fails the device may remain armed; pci_clear_master() +* in nbl_remove() is the final safety net. +*/
[Severity: Low]
Is nbl_remove() actually reached on this path? A nbl_dev_start() failure propagates through nbl_core_start() into nbl_probe(), which does goto core_start_err and falls through to the adapter_init_err label:
core_start_err: nbl_core_remove(adapter); adapter_init_err: pci_clear_master(pdev); return err;
The PCI core does not call .remove after a failed probe, so the safety net described here appears to live in nbl_probe()'s error label rather than in nbl_remove(). Could the comment name the label that really runs?
Quoted 29 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +29
-0+ cleanup_ret =nbl_dev_destroy_msix_map (dev_mgt); +if (cleanup_ret) +dev_err (dev_mgt->common->dev, +"rollback: destroy MSI-X map failed: %d\n" , + cleanup_ret); +nbl_dev_clear_interrupt_scheme (dev_mgt); +err_cancel_work: +/* +* destroy_msix_map() polling send may requeue clean_mbx_task. +* Drain before returning on all rollback paths. +*/ +cancel_work_sync (&common_dev->clean_mbx_task); +return ret; +} + +void nbl_dev_stop (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +int ret; + + ret =nbl_dev_disable_mailbox_irq (dev_mgt); +if (ret) +dev_err (dev_mgt->common->dev, +"Failed to disable mailbox IRQ: %d\n" , ret); +nbl_dev_free_mailbox_irq (dev_mgt); + +/* +* Destroy hardware MSI-X map BEFORE releasing kernel-side
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 521
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* vectors. Masks all device vectors and clears pcompleter +* map entry first; pci_free_irq_vectors() then runs with no +* possibility of a stale MSI-X message arriving. +*/ + ret =nbl_dev_destroy_msix_map (dev_mgt); +if (ret) +dev_err (dev_mgt->common->dev, +"Failed to destroy MSI-X map: %d\n" , ret); + +nbl_dev_clear_interrupt_scheme (dev_mgt);
[Severity: Medium]
Does the code above match the comment when nbl_dev_destroy_msix_map() fails? The failure is only logged and pci_free_irq_vectors() runs anyway, so the device-side pcompleter map entry stays valid and the vectors stay armed while the host side releases them. The same applies to the err_destroy_map path in nbl_dev_start().
On a non-control PF that RPC can return -ETIMEDOUT, -EREMOTEIO or -EPERM whenever the manager PF cannot answer (PF0 unbound first, lost ack, responder error).
The fallback named in both the comment and the changelog also looks like it runs too late. In nbl_remove():
nbl_core_stop(adapter); nbl_core_remove(adapter); pci_clear_master(pdev);
pci_clear_master() only executes after the vectors are already freed. And nbl_res_intr_cfg_msix_map() tags the map-table DMA with the control PF's BDF:
/* * cfg_msix_map uses the control PF's own BDF (common->hw_bus etc.), * not the target function's BDF. ... */ hw_ops->cfg_msix_map(..., true, official_tbl->dma, common->hw_bus, common->devid, common->function);
so can clearing bus mastering on the departing non-control PF quiesce that DMA at all? Should the teardown either retry or keep the vectors until the device-side map is confirmed destroyed, and should the comment and the changelog sentence "pci_clear_master() in nbl_remove() provides the final safety net if a teardown RPC to the manager PF cannot complete" be adjusted?
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +8
-0+ +/* +* destroy_msix_map() sends ack-requested messages which may +* requeue clean_mbx_task via polling send path. Drain work +* after the operation. +*/ +cancel_work_sync (&common_dev->clean_mbx_task); +}drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0@@ -127,7 +137,13 @@ static int nbl_probe(struct pci_dev *pdev, goto adapter_init_err; }pci_set_drvdata (pdev, adapter);
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 149
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0+ 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;
[ ... ]
Thanks for considering these.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260907123848.30256-1-illusion.wang%40nebula-matrix.com