nbl driver for Nebulamatrix NICs
Subsystems (4)
illusion.wang
maintainerv24 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 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 (11):
net/nebula-matrix: add minimum nbl build framework net/nebula-matrix: add core driver architecture and HW layer
initialization
net/nebula-matrix: add channel wire opcode enum definitions net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add chip-wide hardware init/deinit implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: add channel RPC framework & shared hw ops
mutex
net/nebula-matrix: add common/ctrl dev init/remove operation net/nebula-matrix: add common dev start/stop operation
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 + MAINTAINERS | 10 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 31 + drivers/net/ethernet/nebula-matrix/Makefile | 6 + .../net/ethernet/nebula-matrix/nbl/Makefile | 15 + .../nbl/nbl_channel/nbl_channel.c | 1142 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 173 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 206 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 29 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 45 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 499 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 57 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 633 +++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 26 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 23 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 1086 ++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 355 +++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 321 +++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 78 ++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 405 ++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 150 +++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 109 ++ .../nbl/nbl_include/nbl_def_channel.h | 379 ++++++ .../nbl/nbl_include/nbl_def_common.h | 69 + .../nbl/nbl_include/nbl_def_dev.h | 16 + .../nbl/nbl_include/nbl_def_dispatch.h | 42 + .../nbl/nbl_include/nbl_def_hw.h | 53 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 49 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 247 ++++ 36 files changed, 6368 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 v24 1/11 net/nebula-matrix: add minimum nbl build framework
From: illusion wang <[email protected]>
This patch adds the minimum build infrastructure:
1. Add Kconfig, Makefile and MAINTAINERS entries;
2. Add corresponding driver documentation;
3. Add PCI driver skeleton with empty stubs for nbl driver.
--- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 +++++ MAINTAINERS | 10 ++ drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 31 ++++++ drivers/net/ethernet/nebula-matrix/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 13 +++ .../nbl/nbl_include/nbl_include.h | 14 +++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 100 ++++++++++++++++++ 11 files changed, 211 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -47,6 +47,7 @@ Contents: meta/fbnic microsoft/netvsc mucse/rnpgbe + nebula-matrix/nbl netronome/nfp pensando/ionic pensando/ionic_rdma
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +28 -0
@@ -0,0 +1,28 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================================================ +Linux Base Driver for Nebula-matrix m18110-NIC/m18000-NIC family +================================================================ + +Overview: +========= +The m18110-NIC/m18000-NIC is a series of network interface cards for the Data +Center Area. + +The driver supports link-speed 100GbE/25GE/10GE. + +m18110-NIC/m18000-NIC devices support MSI-X interrupt vector for each Tx/Rx +queue and interrupt moderation. + +m18110-NIC/m18000-NIC devices support also various offload features such as +checksum offload, Receive-Side Scaling(RSS). + +Support +======= + +For more information about m18110-NIC/m18000-NIC, please visit the following URL: +https://www.nebula-matrix.com/snic_s1000_en + +If an issue is identified with the released source code on the supported kernel +with a supported adapter, email the specific information related to the issue to [email protected].
MAINTAINERS +10 -0
@@ -18597,6 +18597,16 @@ F: Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml F: Documentation/hwmon/nct7363.rst F: drivers/hwmon/nct7363.c +NEBULA-MATRIX ETHERNET DRIVER (nebula-matrix) +M: Illusion Wang <[email protected]> +M: Dimon Zhao <[email protected]> +M: Alvin Wang <[email protected]> +M: Sam Chen <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/networking/device_drivers/ethernet/nebula-matrix/ +F: drivers/net/ethernet/nebula-matrix/ + NETCONSOLE M: Breno Leitao <[email protected]> S: Maintained
drivers/net/ethernet/Kconfig +1 -0
@@ -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 +31 -0
@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Nebula-matrix network device configuration +# + +config NET_VENDOR_NEBULA_MATRIX + bool "Nebula-matrix devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Nebula-matrix cards. If you say Y, you will be asked + for your specific card in the following questions. + +if NET_VENDOR_NEBULA_MATRIX + +config NBL + tristate "Nebula-matrix Ethernet Controller m18110/m18000 support" + depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN + help + This driver supports Nebula-matrix Ethernet Controller m18110/m18000 + Family of devices. + + More specific information on configuring the driver is in + <file:Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst>. + + To compile this driver as a module, choose M here. The module + will be called nbl. + +endif # NET_VENDOR_NEBULA_MATRIX
drivers/net/ethernet/nebula-matrix/Makefile new file +6 -0
@@ -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) 2025 Nebula Matrix Limited. + +obj-$(CONFIG_NBL) := nbl.o + +nbl-objs += nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 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) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_INCLUDE_H_ +#define _NBL_INCLUDE_H_ + +#include <linux/types.h> + +/* ------ Basic definitions ------- */ +#define NBL_DRIVER_NAME "nbl" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v24 2/11 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
- 64/32-bit DMA mask fallback and PCI master setup
- Leonis hardware BAR resource request and ioremap logic
This patch establishes the lowest HW layer and core infrastructure, preparing for subsequent device implementations.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 3 +- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 18 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 152 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 33 ++++ .../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 | 97 ++++++++++- 9 files changed, 373 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 +152 -0
152 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_HW_LEONIS_H_ +#define _NBL_HW_LEONIS_H_ + +#include <linux/types.h> + +#include "../../nbl_include/nbl_include.h" +#include "../nbl_hw_reg.h" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_HW_REG_H_ +#define _NBL_HW_REG_H_ + +#include <linux/types.h> + +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +#define NBL_MEMORY_BAR 0 +#define NBL_MAILBOX_BAR 2 +#define NBL_RDMA_NOTIFY_LEN (8ULL << 10) +#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +/* +* PCI MEMORY BAR total size: 64MiB. +* First 32MiB: module registers + table entry address range. +* Region after 32MiB is unused for ethernet driver. +*/ +#define NBL_HW_REG_SPACE_SIZE (32ULL << 20) + +struct nbl_hw_mgt { +struct nbl_common_info *common; +u8 __iomem *hw_addr; +u8 __iomem *mailbox_bar_hw_addr; +resource_size_t hw_size; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_COMMON_H_ +#define _NBL_DEF_COMMON_H_ + +#include <linux/types.h> +#include <linux/pci.h> +#include <linux/device.h> +#include "nbl_include.h" + +struct nbl_common_info { +struct pci_dev *pdev; +struct device *dev; +u32 msg_enable; +u16 vsi_id; +u8 eth_id; +u8 logic_eth_id; +u8 eth_num; + +u8 function; +u8 devid; +u8 bus; +u8 hw_bus; + +u8 has_ctrl; +u8 has_net; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_HW_H_ +#define _NBL_DEF_HW_H_ + +#include <linux/types.h> + +struct nbl_hw_mgt ; +struct nbl_adapter ; + +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 +96 -1
112 lines not on this page · raw message
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [PATCH v24 net-next 02/11] net/nebula-matrix: add core driver architecture and HW layer initialization
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 80
Quoted 1 line · On Fri, 7 Aug 2026 12:44:06 +0800 illusion.wang wrote:
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1
-0+ err =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));
Documentation says:
dma_set_mask_and_coherent() never return fail when DMA_BIT_MASK(64)
Please, don't error check this :/
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9
-0+if (err) { +dev_dbg (dev,"Configure DMA 64 bit mask failed, err = %d\n" , + err); + err =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (32 )); +if (err) { +dev_err (dev, +"Configure DMA 32 bit mask failed, err = %d\n" , + err); + goto configure_dma_err;
illusion.wang
maintainerPATCH v24 3/11 net/nebula-matrix: add channel wire opcode enum definitions
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add enum nbl_chan_msg_type into nbl_def_channel.h, defining all PF/VF/firmware channel wire opcodes used for inter-component mailbox communication.
Each enumerator carries an explicit fixed numeric value, acting as stable wire-format message ID shared between driver and firmware.
ABI constraint: New opcodes must only be appended before NBL_CHAN_MSG_MAILBOX_MAX.
Reordering, inserting or deleting existing entries will break cross-version driver-firmware interoperability. Any modification to existing opcode assignments requires coordinated firmware ABI change.
This commit introduces the opcode ID enumeration. Message payload structures and complete channel layer logic will be added in subsequent separate patches.
--- .../nbl/nbl_include/nbl_def_channel.h | 242 ++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +242 -0
@@ -0,0 +1,242 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_CHANNEL_H_ +#define _NBL_DEF_CHANNEL_H_ + +/* +* Mailbox wire opcodes +* Every opcode is assigned explicit fixed numeric value, stable wire ABI +* shared between driver and firmware. +* Firmware/driver wire compatibility rule: +* New entries must only be appended before NBL_CHAN_MSG_MAILBOX_MAX. +* Reordering / inserting / deleting existing items will break cross-version +* interoperability. Any change to existing enumerators requires matching +* firmware ABI adjustment. +*/ +enum nbl_chan_msg_type { +NBL_CHAN_MSG_ACK =0 , +NBL_CHAN_MSG_ADD_MACVLAN =1 , +NBL_CHAN_MSG_DEL_MACVLAN =2 , +NBL_CHAN_MSG_ADD_MULTI_RULE =3 , +NBL_CHAN_MSG_DEL_MULTI_RULE =4 , +NBL_CHAN_MSG_SETUP_MULTI_GROUP =5 , +NBL_CHAN_MSG_REMOVE_MULTI_GROUP =6 , +NBL_CHAN_MSG_REGISTER_NET =7 , +NBL_CHAN_MSG_UNREGISTER_NET =8 , +NBL_CHAN_MSG_ALLOC_TXRX_QUEUES =9 , +NBL_CHAN_MSG_FREE_TXRX_QUEUES =10 , +NBL_CHAN_MSG_SETUP_QUEUE =11 , +NBL_CHAN_MSG_REMOVE_ALL_QUEUES =12 , +NBL_CHAN_MSG_CFG_DSCH =13 , +NBL_CHAN_MSG_SETUP_CQS =14 , +NBL_CHAN_MSG_REMOVE_CQS =15 , +NBL_CHAN_MSG_CFG_QDISC_MQPRIO =16 , +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP =17 , +NBL_CHAN_MSG_DESTROY_MSIX_MAP =18 , +NBL_CHAN_MSG_MAILBOX_SET_IRQ =19 , +NBL_CHAN_MSG_GET_GLOBAL_VECTOR =20 , +NBL_CHAN_MSG_GET_VSI_ID =21 , +NBL_CHAN_MSG_SET_PROMISC_MODE =22 , +NBL_CHAN_MSG_GET_FIRMWARE_VERSION =23 , +NBL_CHAN_MSG_GET_QUEUE_ERR_STATS =24 , +NBL_CHAN_MSG_GET_COALESCE =25 , +NBL_CHAN_MSG_SET_COALESCE =26 , +NBL_CHAN_MSG_SET_SPOOF_CHECK_ADDR =27 , +NBL_CHAN_MSG_SET_VF_SPOOF_CHECK =28 , +NBL_CHAN_MSG_GET_RXFH_INDIR_SIZE =29 , +NBL_CHAN_MSG_GET_RXFH_INDIR =30 , +NBL_CHAN_MSG_GET_RXFH_RSS_KEY =31 , +NBL_CHAN_MSG_GET_RXFH_RSS_ALG_SEL =32 , +NBL_CHAN_MSG_GET_HW_CAPS =33 , +NBL_CHAN_MSG_GET_HW_STATE =34 , +NBL_CHAN_MSG_REGISTER_RDMA =35 , +NBL_CHAN_MSG_UNREGISTER_RDMA =36 , +NBL_CHAN_MSG_GET_REAL_HW_ADDR =37 , +NBL_CHAN_MSG_GET_REAL_BDF =38 , +NBL_CHAN_MSG_GRC_PROCESS =39 , +NBL_CHAN_MSG_SET_SFP_STATE =40 , +NBL_CHAN_MSG_SET_ETH_LOOPBACK =41 , +NBL_CHAN_MSG_CHECK_ACTIVE_VF =42 , +NBL_CHAN_MSG_GET_PRODUCT_FLEX_CAP =43 , +NBL_CHAN_MSG_ALLOC_KTLS_TX_INDEX =44 , +NBL_CHAN_MSG_FREE_KTLS_TX_INDEX =45 , +NBL_CHAN_MSG_CFG_KTLS_TX_KEYMAT =46 , +NBL_CHAN_MSG_ALLOC_KTLS_RX_INDEX =47 , +NBL_CHAN_MSG_FREE_KTLS_RX_INDEX =48 , +NBL_CHAN_MSG_CFG_KTLS_RX_KEYMAT =49 , +NBL_CHAN_MSG_CFG_KTLS_RX_RECORD =50 , +NBL_CHAN_MSG_ADD_KTLS_RX_FLOW =51 , +NBL_CHAN_MSG_DEL_KTLS_RX_FLOW =52 , +NBL_CHAN_MSG_ALLOC_IPSEC_TX_INDEX =53 , +NBL_CHAN_MSG_FREE_IPSEC_TX_INDEX =54 , +NBL_CHAN_MSG_ALLOC_IPSEC_RX_INDEX =55 , +NBL_CHAN_MSG_FREE_IPSEC_RX_INDEX =56 , +NBL_CHAN_MSG_CFG_IPSEC_TX_SAD =57 , +NBL_CHAN_MSG_CFG_IPSEC_RX_SAD =58 , +NBL_CHAN_MSG_ADD_IPSEC_TX_FLOW =59 , +NBL_CHAN_MSG_DEL_IPSEC_TX_FLOW =60 , +NBL_CHAN_MSG_ADD_IPSEC_RX_FLOW =61 , +NBL_CHAN_MSG_DEL_IPSEC_RX_FLOW =62 , +NBL_CHAN_MSG_NOTIFY_IPSEC_HARD_EXPIRE =63 , +NBL_CHAN_MSG_GET_MBX_IRQ_NUM =64 , +NBL_CHAN_MSG_CLEAR_FLOW =65 , +NBL_CHAN_MSG_CLEAR_QUEUE =66 , +NBL_CHAN_MSG_GET_ETH_ID =67 , +NBL_CHAN_MSG_SET_OFFLOAD_STATUS =68 , +NBL_CHAN_MSG_INIT_OFLD =69 , +NBL_CHAN_MSG_INIT_CMDQ =70 , +NBL_CHAN_MSG_DESTROY_CMDQ =71 , +NBL_CHAN_MSG_RESET_CMDQ =72 , +NBL_CHAN_MSG_INIT_FLOW =73 , +NBL_CHAN_MSG_DEINIT_FLOW =74 , +NBL_CHAN_MSG_OFFLOAD_FLOW_RULE =75 , +NBL_CHAN_MSG_GET_ACL_SWITCH =76 , +NBL_CHAN_MSG_GET_VSI_GLOBAL_QUEUE_ID =77 , +NBL_CHAN_MSG_INIT_REP =78 , +NBL_CHAN_MSG_GET_LINE_RATE_INFO =79 , +NBL_CHAN_MSG_REGISTER_NET_REP =80 , +NBL_CHAN_MSG_UNREGISTER_NET_REP =81 , +NBL_CHAN_MSG_REGISTER_ETH_REP =82 , +NBL_CHAN_MSG_UNREGISTER_ETH_REP =83 , +NBL_CHAN_MSG_REGISTER_UPCALL_PORT =84 , +NBL_CHAN_MSG_UNREGISTER_UPCALL_PORT =85 , +NBL_CHAN_MSG_GET_PORT_STATE =86 , +NBL_CHAN_MSG_SET_PORT_ADVERTISING =87 , +NBL_CHAN_MSG_GET_MODULE_INFO =88 , +NBL_CHAN_MSG_GET_MODULE_EEPROM =89 , +NBL_CHAN_MSG_GET_LINK_STATE =90 , +NBL_CHAN_MSG_NOTIFY_LINK_STATE =91 , +NBL_CHAN_MSG_GET_QUEUE_CXT =92 , +NBL_CHAN_MSG_CFG_LOG =93 , +NBL_CHAN_MSG_INIT_VDPAQ =94 , +NBL_CHAN_MSG_DESTROY_VDPAQ =95 , +NBL_CHAN_MSG_GET_UPCALL_PORT =96 , +NBL_CHAN_MSG_NOTIFY_ETH_REP_LINK_STATE =97 , +NBL_CHAN_MSG_SET_ETH_MAC_ADDR =98 , +NBL_CHAN_MSG_GET_FUNCTION_ID =99 , +NBL_CHAN_MSG_GET_CHIP_TEMPERATURE =100 , +NBL_CHAN_MSG_DISABLE_HW_FLOW =101 , +NBL_CHAN_MSG_ENABLE_HW_FLOW =102 , +NBL_CHAN_MSG_SET_UPCALL_RULE =103 , +NBL_CHAN_MSG_UNSET_UPCALL_RULE =104 , +NBL_CHAN_MSG_GET_REG_DUMP =105 , +NBL_CHAN_MSG_GET_REG_DUMP_LEN =106 , +NBL_CHAN_MSG_CFG_LAG_HASH_ALGORITHM =107 , +NBL_CHAN_MSG_CFG_LAG_MEMBER_FWD =108 , +NBL_CHAN_MSG_CFG_LAG_MEMBER_LIST =109 , +NBL_CHAN_MSG_CFG_LAG_MEMBER_UP_ATTR =110 , +NBL_CHAN_MSG_ADD_LAG_FLOW =111 , +NBL_CHAN_MSG_DEL_LAG_FLOW =112 , +NBL_CHAN_MSG_SWITCHDEV_INIT_CMDQ =113 , +NBL_CHAN_MSG_SWITCHDEV_DEINIT_CMDQ =114 , +NBL_CHAN_MSG_SET_TC_FLOW_INFO =115 , +NBL_CHAN_MSG_UNSET_TC_FLOW_INFO =116 , +NBL_CHAN_MSG_INIT_ACL =117 , +NBL_CHAN_MSG_UNINIT_ACL =118 , +NBL_CHAN_MSG_CFG_LAG_MCC =119 , +NBL_CHAN_MSG_REGISTER_VSI2Q =120 , +NBL_CHAN_MSG_SETUP_Q2VSI =121 , +NBL_CHAN_MSG_REMOVE_Q2VSI =122 , +NBL_CHAN_MSG_SETUP_RSS =123 , +NBL_CHAN_MSG_REMOVE_RSS =124 , +NBL_CHAN_MSG_GET_REP_QUEUE_INFO =125 , +NBL_CHAN_MSG_CTRL_PORT_LED =126 , +NBL_CHAN_MSG_NWAY_RESET =127 , +NBL_CHAN_MSG_SET_INTL_SUPPRESS_LEVEL =128 , +NBL_CHAN_MSG_GET_ETH_STATS =129 , +NBL_CHAN_MSG_GET_MODULE_TEMPERATURE =130 , +NBL_CHAN_MSG_GET_BOARD_INFO =131 , +NBL_CHAN_MSG_GET_P4_USED =132 , +NBL_CHAN_MSG_GET_VF_BASE_VSI_ID =133 , +NBL_CHAN_MSG_ADD_LLDP_FLOW =134 , +NBL_CHAN_MSG_DEL_LLDP_FLOW =135 , +NBL_CHAN_MSG_CFG_ETH_BOND_INFO =136 , +NBL_CHAN_MSG_CFG_DUPPKT_MCC =137 , +NBL_CHAN_MSG_ADD_ND_UPCALL_FLOW =138 , +NBL_CHAN_MSG_DEL_ND_UPCALL_FLOW =139 , +NBL_CHAN_MSG_GET_BOARD_ID =140 , +NBL_CHAN_MSG_SET_SHAPING_DPORT_VLD =141 , +NBL_CHAN_MSG_SET_DPORT_FC_TH_VLD =142 , +NBL_CHAN_MSG_REGISTER_RDMA_BOND =143 , +NBL_CHAN_MSG_UNREGISTER_RDMA_BOND =144 , +NBL_CHAN_MSG_RESTORE_NETDEV_QUEUE =145 , +NBL_CHAN_MSG_RESTART_NETDEV_QUEUE =146 , +NBL_CHAN_MSG_RESTORE_HW_QUEUE =147 , +NBL_CHAN_MSG_KEEP_ALIVE =148 , +NBL_CHAN_MSG_GET_BASE_MAC_ADDR =149 , +NBL_CHAN_MSG_CFG_BOND_SHAPING =150 , +NBL_CHAN_MSG_CFG_BGID_BACK_PRESSURE =151 , +NBL_CHAN_MSG_ALLOC_KT_BLOCK =152 , +NBL_CHAN_MSG_FREE_KT_BLOCK =153 , +NBL_CHAN_MSG_GET_USER_QUEUE_INFO =154 , +NBL_CHAN_MSG_GET_ETH_BOND_INFO =155 , +NBL_CHAN_MSG_CLEAR_ACCEL_FLOW =156 , +NBL_CHAN_MSG_SET_BRIDGE_MODE =157 , +NBL_CHAN_MSG_GET_VF_FUNCTION_ID =158 , +NBL_CHAN_MSG_NOTIFY_LINK_FORCED =159 , +NBL_CHAN_MSG_SET_PMD_DEBUG =160 , +NBL_CHAN_MSG_REGISTER_FUNC_MAC =161 , +NBL_CHAN_MSG_SET_TX_RATE =162 , +NBL_CHAN_MSG_REGISTER_FUNC_LINK_FORCED =163 , +NBL_CHAN_MSG_GET_LINK_FORCED =164 , +NBL_CHAN_MSG_REGISTER_FUNC_VLAN =165 , +NBL_CHAN_MSG_GET_FD_FLOW =166 , +NBL_CHAN_MSG_GET_FD_FLOW_CNT =167 , +NBL_CHAN_MSG_GET_FD_FLOW_ALL =168 , +NBL_CHAN_MSG_GET_FD_FLOW_MAX =169 , +NBL_CHAN_MSG_REPLACE_FD_FLOW =170 , +NBL_CHAN_MSG_REMOVE_FD_FLOW =171 , +NBL_CHAN_MSG_CFG_FD_FLOW_STATE =172 , +NBL_CHAN_MSG_REGISTER_FUNC_RATE =173 , +NBL_CHAN_MSG_NOTIFY_VLAN =174 , +NBL_CHAN_MSG_GET_XDP_QUEUE_INFO =175 , +NBL_CHAN_MSG_STOP_ABNORMAL_SW_QUEUE =176 , +NBL_CHAN_MSG_STOP_ABNORMAL_HW_QUEUE =177 , +NBL_CHAN_MSG_NOTIFY_RESET_EVENT =178 , +NBL_CHAN_MSG_ACK_RESET_EVENT =179 , +NBL_CHAN_MSG_GET_VF_VSI_ID =180 , +NBL_CHAN_MSG_CONFIGURE_QOS =181 , +NBL_CHAN_MSG_GET_PFC_BUFFER_SIZE =182 , +NBL_CHAN_MSG_SET_PFC_BUFFER_SIZE =183 , +NBL_CHAN_MSG_GET_VF_STATS =184 , +NBL_CHAN_MSG_REGISTER_FUNC_TRUST =185 , +NBL_CHAN_MSG_NOTIFY_TRUST =186 , +NBL_CHAN_MSG_CHECK_VF_IS_ACTIVE =187 , +NBL_CHAN_MSG_GET_ETH_ABNORMAL_STATS =188 , +NBL_CHAN_MSG_GET_ETH_CTRL_STATS =189 , +NBL_CHAN_MSG_GET_PAUSE_STATS =190 , +NBL_CHAN_MSG_GET_ETH_MAC_STATS =191 , +NBL_CHAN_MSG_GET_FEC_STATS =192 , +NBL_CHAN_MSG_CFG_MULTI_MCAST_RULE =193 , +NBL_CHAN_MSG_GET_LINK_DOWN_COUNT =194 , +NBL_CHAN_MSG_GET_LINK_STATUS_OPCODE =195 , +NBL_CHAN_MSG_GET_RMON_STATS =196 , +NBL_CHAN_MSG_REGISTER_PF_NAME =197 , +NBL_CHAN_MSG_GET_PF_NAME =198 , +NBL_CHAN_MSG_CONFIGURE_RDMA_BW =199 , +NBL_CHAN_MSG_SET_RATE_LIMIT =200 , +NBL_CHAN_MSG_SET_TC_WGT =201 , +NBL_CHAN_MSG_REMOVE_QUEUE =202 , +NBL_CHAN_MSG_GET_MIRROR_TABLE_ID =203 , +NBL_CHAN_MSG_CONFIGURE_MIRROR =204 , +NBL_CHAN_MSG_CONFIGURE_MIRROR_TABLE =205 , +NBL_CHAN_MSG_CLEAR_MIRROR_CFG =206 , +NBL_CHAN_MSG_MIRROR_OUTPUTPORT_NOTIFY =207 , +NBL_CHAN_MSG_CHECK_FLOWTABLE_SPEC =208 , +NBL_CHAN_MSG_CHECK_VF_IS_VDPA =209 , +NBL_CHAN_MSG_GET_VDPA_VF_STATS =210 , +NBL_CHAN_MSG_SET_RX_RATE =211 , +NBL_CHAN_MSG_GET_UVN_PKT_DROP_STATS =212 , +NBL_CHAN_MSG_GET_USTORE_PKT_DROP_STATS =213 , +NBL_CHAN_MSG_GET_USTORE_TOTAL_PKT_DROP_STATS =214 , +NBL_CHAN_MSG_SET_WOL =215 , +NBL_CHAN_MSG_INIT_VF_MSIX_MAP =216 , +NBL_CHAN_MSG_GET_ST_NAME =217 , +/* mailbox msg end */ +NBL_CHAN_MSG_MAILBOX_MAX , +}; + +#endif
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v24 4/11 net/nebula-matrix: add channel layer
In reply to illusion.wangFrom: illusion wang <[email protected]>
A channel management layer provides a structured approach to handle communication between different components and drivers. Here's a summary of its key functionalities:
1. Message Handling Framework
Message Registration: Functions (nbl_chan_register_msg) allow dynamic registration of message handlers for specific message types, enabling extensible communication protocols.
Message Sending/Acknowledgment: Core functions (nbl_chan_send_msg, nbl_chan_send_ack) handle message transmission. It supports two modes:
fire-and-forget transmission, and synchronous send with ACK waiting. Received ACK messages are processed via nbl_chan_recv_ack_msg. TX slot allocation logic is implemented to limit concurrent outstanding messages; returns -EAGAIN when all waiting slots are occupied.
Hash-Based Handler Lookup: A hash table (handle_hash_tbl) stores message handlers for efficient O(1) lookup by message type. The entire table is removed via nbl_chan_remove_msg_handler during driver teardown; per-message-type unregister is not implemented in this version.
Tx descriptor supports two data formats: small embedded payload inside descriptor, and large payload via external DMA buffer.
2. Channel Types and Queue Management
Mailbox Channel: implemented for inter-PF communication (PF0 <-> other PFs).
Queue Initialization: Functions (nbl_chan_init_queue, nbl_chan_init_tx_queue) allocate resources:
- TX/RX descriptors: dmam_alloc_coherent()
- TX/RX buffer metadata arrays (txq->buf, rxq->buf): devm_kcalloc()
Queue Teardown: nbl_chan_teardown_queue() stops hardware queues, cancels pending work items (clean_task), and waits for in-flight send threads to drain. It does NOT free DMA memory, which is released automatically via devm on driver remove.
IMPORTANT - Resource Lifecycle Design:
DMA memory allocated with dmam_alloc_coherent() is intentionally NOT freed in nbl_chan_teardown_queue(). The queues are allocated once during driver probe and freed only during driver remove. Dynamic per-PF queue teardown and re-creation during runtime is not supported.
Queue Configuration: Hardware-specific queue parameters (e.g., buffer sizes, entry counts) are set via nbl_chan_config_queue, with hardware interactions delegated to hw_ops.
RX completion relies on work_struct clean_task for descriptor processing.
3. Hardware Abstraction Layer (HW Ops)
Hardware-Specific Operations: The nbl_hw_ops structure abstracts hardware interactions: queue configuration (config_mailbox_txq/rxq), tail pointer doorbell updates (update_mailbox_queue_tail_ptr), and PF mailbox routing table configuration.
NOTE: This initial implementation provides interrupt-driven receive path, where actual RX message processing is scheduled into workqueue after interrupt notification. Polling-based mailbox receive is not supported in this patch and will be added in subsequent series.
And the optimization to requeue clean_task inside nbl_chan_clean_queue() when processing budget is exhausted is deferred to follow-up patches.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1068 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 170 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 166 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 29 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 7 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 174 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 56 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 45 + .../nbl/nbl_include/nbl_def_channel.h | 104 ++ .../nbl/nbl_include/nbl_def_common.h | 15 + .../nbl/nbl_include/nbl_def_hw.h | 19 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 1866 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
@@ -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 +1068 -0
1,068 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 +166 -0
166 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_COMMON_H_ +#define _NBL_COMMON_H_ + +#include <linux/types.h> + +#include "../nbl_include/nbl_include.h" +#include "../nbl_include/nbl_def_common.h" + +/* list only need one bucket size */ +#define NBL_HASH_TBL_LIST_BUCKET_SIZE 1 + +struct nbl_hash_tbl_mgt { +struct nbl_hash_tbl_key tbl_key; +struct hlist_head *hash; +u16 node_num; +}; + +struct nbl_hash_entry_node { +struct hlist_node node; +void *key; +void *data; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +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 +174 -0
198 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +56 -0
60 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +45 -0
63 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +104 -0
114 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +15 -0
@@ -29,4 +29,19 @@ struct nbl_common_info { u8 has_net; }; +struct nbl_hash_tbl_key { +struct device *dev; +u16 key_size; +u16 data_size;/* no include key or node member */ +u16 bucket_size; +u16 resv; +}; + +struct nbl_hash_tbl_mgt * +nbl_common_init_hash_table (struct nbl_hash_tbl_key *key); +void nbl_common_remove_hash_table (struct nbl_hash_tbl_mgt *tbl_mgt); +int nbl_common_alloc_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key, +void *data,void **out_data); +void *nbl_common_get_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +19 -0
@@ -10,6 +10,25 @@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); +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
Jakub Kicinski
maintainerRe: [PATCH v24 net-next 04/11] net/nebula-matrix: add channel layer
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---net/nebula-matrix: add channel layer
This adds a mailbox based channel layer for the nbl driver, with message registration through a hash table, synchronous send-with-ack and fire-and-forget send, and TX/RX ring setup and teardown backed by devm and dmam allocations. A leonis hardware operations table is added for mailbox queue configuration and doorbell updates.
A few questions on the locking, barriers and teardown ordering below.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1068 @@
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+static int nbl_chan_teardown_queue (struct nbl_channel_mgt *chan_mgt, +u8 chan_type) +{ +struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type]; +struct nbl_chan_waitqueue_head *wait_head; +unsigned long wait_start, wait_timeout; +int ret =0 ; +u16 i; + +/* Step 1: Mark shutdown flag, reject all new send requests */ +WRITE_ONCE (chan_info->shutdown, true);
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 311
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+/* Stop hardware queues */ +nbl_chan_stop_queue (chan_mgt); + +/* +* Step 2: Wait all in-flight send_msg threads exit FIRST. +* Guarantee no further queue_work() can be triggered during cleanup. +* Add timeout to avoid permanent blocking. +*/ + wait_start = jiffies; + wait_timeout =msecs_to_jiffies (5000 ); +while (atomic_read (&chan_info->inflight_tx_cnt) !=0 ) {
[Severity: Low]
The comment says "Step 2: Wait all in-flight send_msg threads exit FIRST", but nbl_chan_stop_queue() runs before the inflight_tx_cnt drain loop. Is that ordering intended?
nbl_chan_stop_queue() -> nbl_hw_stop_mailbox_txq()/rxq() asserts NBL_MAILBOX_QINFO_CFG_QUEUE_RST_MASK and clears QUEUE_EN, so a sender that already passed the early shutdown check can still publish a descriptor and ring the doorbell into a queue that is held in reset:
nbl_chan_send_msg()
nbl_chan_update_txqueue() /* no shutdown check at all */
tx_desc->flags = cpu_to_le16(BIT(NBL_CHAN_TX_DESC_AVAIL));
txq->tail_ptr++; nbl_chan_kick_tx_ring()
nbl_chan_update_tail_ptr(...) /* doorbell, before the shutdown re-check */
Would draining inflight_tx_cnt before nbl_chan_stop_queue() avoid the driver tail pointer diverging from the device consumer pointer?
Quoted 18 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +18
-0+if (time_after (jiffies, wait_start + wait_timeout)) { +dev_warn (chan_mgt->common->dev, +"teardown: wait inflight_tx_cnt timeout, force continue\n" ); + ret = -ETIMEDOUT ; +break ; + } +cpu_relax (); +usleep_range (1000 ,2000 ); + } + +/* Step3: All send paths drained, safely cancel cleanup work */ +if (chan_info->clean_task) { +cancel_work_sync (chan_info->clean_task); + chan_info->clean_task =NULL ; + } +return ret; +} +
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 339
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+static int nbl_chan_setup_queue (struct nbl_channel_mgt *chan_mgt,u8 chan_type) +{ +struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type]; +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = chan_mgt->common; +struct nbl_chan_ring *rxq = &chan_info->rxq; +int err; + +if (READ_ONCE (chan_info->init_done)) +return 0 ;
[Severity: Low]
Are .setup_queue and .teardown_queue meant to be a symmetric pair?
nbl_chan_teardown_queue() leaves chan_info->init_done true and chan_info->shutdown true, and does not reset txq/rxq next_to_use, next_to_clean or tail_ptr. With the init_done early return above, a setup_queue() after a teardown_queue() returns 0 without re-running nbl_chan_config_queue() (the only code that deasserts QUEUE_RST and sets QUEUE_EN), without re-ringing the RX doorbell, and without clearing shutdown, since only nbl_chan_init_queue_param() does that and it sits behind the guard:
if (READ_ONCE(chan_info->init_done)) return 0; ... nbl_chan_init_queue_param(chan_info, ...); /* clears shutdown */
Today both ops are only reached from probe and remove with a freshly devm_kzalloc'ed chan_info, so nothing hits this. Should teardown clear init_done and the ring indices so a later stop/restart cycle (device reset, PF down/up) does not silently succeed on a channel whose queues are still in reset?
[ ... ]
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) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 375
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+ tx_desc->dstid =cpu_to_le16 (param->dstid); + tx_desc->msg_type =cpu_to_le16 (param->msg_type); + tx_desc->msgid =cpu_to_le16 (param->msgid);
[Severity: Low]
Who writes tx_desc->srcid? This is the only producer of the descriptor and it sets dstid, msg_type, msgid, the data/buf fields and flags, but never assigns or clears srcid, while both receive paths consume it:
nbl_chan_recv_msg()
srcid = le16_to_cpu(READ_ONCE(tx_desc->srcid)); ... msg_handler->func(msg_handler->priv, srcid, msgid, payload, payload_len);
nbl_chan_recv_ack_msg()
if (srcid != READ_ONCE(wait_head->dstid)) {
... "ACK srcid=%u != dstid=%u, rejecting"If the mailbox engine populates srcid in the copy delivered to the peer, could a comment say so? Otherwise the field is whatever the reused ring slot held.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static int nbl_chan_send_msg (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_send_info *chan_send) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+atomic_inc (&chan_info->inflight_tx_cnt); + inflight_inc = true; +/* +* Ensure reading chan_info->shutdown happens
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 758
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+* strictly after inflight_tx_cnt increment above on this CPU. +* Prevent compiler/cpu reordering: read shutdown before incrementing +* inflight counter, which would cause missing shutdown check and leak +* tx inflight count. +*/ +smp_rmb (); +if (READ_ONCE (chan_info->shutdown)) { +atomic_dec (&chan_info->inflight_tx_cnt); +return -ESHUTDOWN ; + }
[Severity: Medium]
Does smp_rmb() give the ordering the comment claims here? This is a store followed by a load, and smp_rmb() only orders load-load pairs; the non-value-returning atomic_inc() provides no ordering of its own.
The peer half in nbl_chan_teardown_queue() uses a full barrier and so depends on the sender mirroring it:
CPU0 nbl_chan_send_msg() CPU1 nbl_chan_teardown_queue()
atomic_inc(&inflight_tx_cnt); WRITE_ONCE(shutdown, true); smp_rmb(); smp_mb(); load shutdown -> false atomic_read(&inflight_tx_cnt) -> 0
Can the shutdown load be satisfied before the increment is visible, so that teardown concludes the drain, calls nbl_chan_stop_queue() and cancel_work_sync() and returns while CPU0 goes on to take txq_lock, write a descriptor and ring the doorbell? Since teardown_queue() is the last thing guarding the rings before devres releases the dmam_alloc_coherent() descriptor rings and the devm_kcalloc() wait array, would smp_mb() (or atomic_fetch_inc()) be the right primitive here?
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 764
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+ +mutex_lock (&chan_info->txq_lock); +if (test_bit (NBL_CHAN_ABNORMAL , chan_info->state)) { + ret = -EIO ; + goto unlock_out; + }
[Severity: Low]
Is anything expected to set NBL_CHAN_ABNORMAL? This test_bit() is its only user in the tree; the only writer would be nbl_chan_set_queue_state(), and its callers pass NBL_CHAN_INTERRUPT_READY, so this branch cannot be taken.
Related, the patch defines NBL_MAILBOX_QINFO_CFG_DIF_ERR_MASK and NBL_MAILBOX_QINFO_CFG_PTR_ERR_MASK in nbl_hw_leonis.h, but the qinfo cfg table is only ever written (nbl_hw_write_mbx_regs has no read-back counterpart), so those status bits are never sampled. With no reader, a queue the hardware has flagged as errored is never detected, and nbl_chan_kick_tx_ring() just logs and advances next_to_clean:
dev_err_ratelimited(dev, "chan send msg type: %d timeout\n", msg_type); txq->next_to_clean = txq->next_to_use; return -ETIMEDOUT;
Is the error-bit sampling and queue reconfigure planned for a follow-up?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +2
-0+ ret =nbl_chan_kick_tx_ring (chan_mgt, chan_info); +if (ret) {
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 821
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +12
-0+ goto unlock_out; + } +mutex_unlock (&chan_info->txq_lock); +if (!chan_send->ack) { + tmp =FIELD_GET (NBL_CHAN_MSGID_LOC_MASK , msgid); + wait_head = &chan_info->wait[tmp]; +spin_lock_irq (&wait_head->status_lock); +WRITE_ONCE (wait_head->status,NBL_MBX_STATUS_IDLE ); +spin_unlock_irq (&wait_head->status_lock); +atomic_dec (&chan_info->inflight_tx_cnt); +return 0 ; + }
[Severity: Medium]
Can this write to a slot the caller no longer owns? txq_lock is what serializes TX slot ownership, and it is dropped just above. The slot was already set to IDLE inside the earlier status_lock block:
WRITE_ONCE(wait_head->status, chan_send->ack ? NBL_MBX_STATUS_WAITING : NBL_MBX_STATUS_IDLE);
so this second write looks redundant. In the gap, another sender can be handed the same slot, and nbl_chan_get_msg_id() starts its search exactly there because wait_head_index was just pointed at it:
int search_loc = chan_info->wait_head_index, i;
...
if (status == NBL_MBX_STATUS_IDLE ||
status == NBL_MBX_STATUS_TIMEOUT) {
...
WRITE_ONCE(chan_info->wait_head_index, search_loc);Sender B then arms the slot WAITING and blocks, sender A forces it back to IDLE, and the ACK is dropped:
nbl_chan_recv_ack_msg()
if (READ_ONCE(wait_head->status) != NBL_MBX_STATUS_WAITING) {
spin_unlock_irq(&wait_head->status_lock);
dev_err_ratelimited(dev, "Skip ack with invalid status, ...");B then fails with -ETIMEDOUT after NBL_CHAN_ACK_WAIT_TIME. The interrupt mode timeout path only cleans up when it still sees NBL_MBX_STATUS_WAITING, so it can instead clobber a third sender's freshly armed slot, setting it to TIMEOUT and NULLing its ack_data while that sender waits. Note nbl_chan_send_ack() is exactly a chan_send->ack == 0 sender, so both participants are the workqueue ACK sender and a synchronous RPC. Can this write simply be dropped?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static int nbl_chan_send_ack (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_ack_info *chan_ack) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 902
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+ len = head_len + data_len; + tmp =kzalloc (len,GFP_ATOMIC ); +if (!tmp) +return -ENOMEM ;
[Severity: Low]
Is GFP_ATOMIC needed here? This path cannot be atomic: nbl_chan_send_msg() below takes mutex_lock(&chan_info->txq_lock) and nbl_chan_kick_tx_ring() calls usleep_range(). The only caller chain is the clean_task work item (the mailbox IRQ handler just schedules work), so GFP_KERNEL would match the actual context, and the GFP_ATOMIC here documents a contract the code cannot honour.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +0
-0@@ -0,0 +1,170 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h line 130
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +8
-0+/* +* Spinlock protecting all fields. +* Must be held when reading/writing: status, acked, ack_err, +* ack_data_len, etc. +* The lock ensures atomic updates of these fields and +* proper memory ordering with smp_wmb()/smp_rmb(). +*/ +spinlock_t status_lock;
[Severity: Low]
Does this comment match the code? Two readers of acked run with status_lock dropped:
nbl_chan_send_msg()
ret = wait_event_timeout(wait_head->wait_queue, READ_ONCE(wait_head->acked) || ...
nbl_chan_recv_ack_msg()
spin_unlock_irq(&wait_head->status_lock); if (READ_ONCE(wait_head->acked)) wake_up(&wait_head->wait_queue);
There is also no smp_wmb() anywhere in the driver, so the documented barrier pairing does not exist. Could the comment be narrowed to the fields the lock actually serializes?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +0
-0@@ -0,0 +1,166 @@
[ ... ]
Quoted 9 lines
+/*
+ * Allocate a hash node and add to the hash table.
+ *
+ * Note: The hash table is protected by the caller's mutex (txq_lock),
+ * not lock-free. The "single context" comment refers to: this function
+ * is only called during init fromnbl_chan_init_msg_handler, so there
+ * is no concurrent mutation during init.
+ * After init, the table is read-only (no unregister API), so no lock is needed
+ * for lookups either.
[Severity: Low]
Both claims in this note look inaccurate.
nbl_chan_init_msg_handler() only creates the table via nbl_common_init_hash_table(); the caller of this function is nbl_chan_add_msg_handler() reached through the exported op:
static int nbl_chan_register_msg(struct nbl_channel_mgt *chan_mgt, u16 msg_type,
nbl_chan_resp func, void *callback)
{
return nbl_chan_add_msg_handler(chan_mgt, msg_type, func, callback);
}and chan_info->txq_lock is taken only by nbl_chan_send_msg(), never on the registration path. Insertion is a plain hlist_add_head() plus a non-atomic node_num++, while nbl_common_get_hash_node() traverses with the non-RCU hlist_for_each_entry() from the clean_task work item.
Today all registrations complete before the RX queue is programmed, so nothing races. Could the note instead state that requirement, since the current wording points at a mutex that is not involved?
[ ... ]
Cross-instance finding from sashiko-gemini (b71ef5b11f4458a07533fdf4c44ce80b1dc5c6eaa0b8f201e2c68859763e947e):
[Severity: Medium]
The code implements the clean_task requeue optimization, directly contradicting the commit message.
Cross-instance finding from sashiko-gemini (f61ba5020ca4df734e90e4522b80858df46b2e1c1ebb7645f42be89a01ba9a4a):
[Severity: Critical]
Wait slot leak and stack corruption when interrupts are not ready in nbl_chan_send_msg.
Signature · 1 line
pw-bot: cr
illusion.wang
maintainerPATCH v24 5/11 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
The Resource layer processes the entries/data of various modules within the processing chip to accomplish specific entry management operations, this describes the module business capabilities of the chip and the data it manages.
The resource layer comprises the following sub-modules: common, interrupt, and vsi(txrx,queue not contained this time)
This patch provides the common part, including the conversion relationships among vsi_id, func_id, eth_id, and pf_id. These relationships may be utilized in the upper layer or the resource layer.
Key Assumptions:
- nbl_res_start() initializes VSI/Eth/PF data structures **only for control devices** (common->has_ctrl == true).
- APIs like nbl_res_func_id_to_vsi_id() **are guaranteed to be called only on control devices** by the framework's dispatch layer.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 2 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 19 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 62 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 + .../nbl_hw_leonis/nbl_resource_leonis.c | 311 ++++++++++++++++++ .../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 | 74 +++++ .../nbl/nbl_include/nbl_def_common.h | 19 ++ .../nbl/nbl_include/nbl_def_hw.h | 4 + .../nbl/nbl_include/nbl_def_resource.h | 29 ++ .../nbl/nbl_include/nbl_include.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 14 files changed, 680 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
@@ -6,4 +6,6 @@ obj-$(CONFIG_NBL) := nbl.o nbl-objs += nbl_common/nbl_common.o \ nbl_channel/nbl_channel.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ + nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ + nbl_hw/nbl_resource.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +19 -0
@@ -7,6 +7,25 @@#include <linux/jhash.h> #include "nbl_common.h" +/* +* nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id +* +* Leonis currently uses fixed mgt_pf = 0. This helper maintains unified +* conversion logic for future platforms supporting non-zero management PF. +* Return: 0 on success, -EINVAL if pf_id < common->mgt_pf or rel_pf_id is NULL. +*/ +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 +61 -1
100 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,4 +67,18 @@ struct nbl_mailbox_qinfo_cfg_table {#define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004)#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040) +#define NBL_PCIE_BUS_MASK GENMASK(12, 5) +#define NBL_FW_BOARD_CONFIG 0x200 +#define NBL_FW_BOARD_DW3_OFFSET (NBL_FW_BOARD_CONFIG + 12) +#define NBL_FW_BOARD_DW6_OFFSET (NBL_FW_BOARD_CONFIG + 24) + +#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0) +#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1) +#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8) +#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10) +#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13) + +#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0) +#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8) +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +311 -0
311 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) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_RESOURCE_LEONIS_H_ +#define _NBL_RESOURCE_LEONIS_H_ + +#include "../nbl_resource.h" +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +120 -0
120 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +74 -0
74 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +19 -0
@@ -11,6 +11,22 @@#include <linux/device.h> #include "nbl_include.h" +#define NBL_TWO_ETHERNET_PORT 2 +#define NBL_FOUR_ETHERNET_PORT 4 +#define NBL_DEFAULT_VSI_ID_GAP 1024 +#define NBL_TWO_ETHERNET_VSI_ID_GAP 512 +#define NBL_FOUR_ETHERNET_VSI_ID_GAP 256 + +static inline u32 nbl_vsi_id_gap (u32 m) +{ +if (m ==NBL_FOUR_ETHERNET_PORT ) +return NBL_FOUR_ETHERNET_VSI_ID_GAP ; +else if (m ==NBL_TWO_ETHERNET_PORT ) +return NBL_TWO_ETHERNET_VSI_ID_GAP ; + +return NBL_DEFAULT_VSI_ID_GAP ; +} +struct nbl_common_info {struct pci_dev *pdev;struct device *dev;
@@ -24,6 +40,7 @@ struct nbl_common_info {u8 devid;u8 bus;u8 hw_bus; +u16 mgt_pf;u8 has_ctrl;u8 has_net;
@@ -37,6 +54,8 @@ struct nbl_hash_tbl_key {u16 resv; }; +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 +4 -0
@@ -20,9 +20,13 @@ struct nbl_hw_ops {void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt);void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt);void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask); +void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt,u8 *bus);void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map); +void (*get_board_info)(struct nbl_hw_mgt *hw_mgt, +struct nbl_board_port_info *board); };struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_RESOURCE_H_ +#define _NBL_DEF_RESOURCE_H_ + +#include <linux/types.h> + +struct nbl_resource_mgt ; +struct nbl_adapter ; + +struct nbl_resource_ops { +int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 type,u16 *vsi_id); +int (*get_eth_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id); +}; + +struct nbl_resource_ops_tbl { +struct nbl_resource_ops *ops; +struct nbl_resource_mgt *priv; +}; + +int nbl_res_init_leonis (struct nbl_adapter *adapter); +void nbl_res_remove_leonis (struct nbl_adapter *adapter); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +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
illusion.wang
maintainerPATCH v24 6/11 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_interrupt module to manage driver global MSI-X vector indices, and extend hw_ops with callbacks to program vendor-specific internal MSI-X mapping registers, configure MSI-X metadata, and bind interrupts to PF mailbox channels.
Key interfaces:
- configure_msix_map:
Allocates driver global MSI-X indices via separate net/other interrupt bitmaps (interrupt_net_bitmap / interrupt_others_bitmap). Preallocates all required coherent DMA resources first; only tears down old hardware configuration after all new allocations succeed. Programs NBL_PCOMPLETER_FUNCTION_MSIX_MAP with the MSI-X table DMA address and function BDF info. PCI MSI-X vector allocation itself is performed via nbl_dev_alloc_msix_intr() at upper layer.
- destroy_msix_map:
Releases allocated global vector indices, clears hardware MSI-X mappings, frees DMA buffer and interrupt array. A delay is inserted before releasing DMA memory to mitigate potential IOMMU faults caused by in-flight hardware DMA access after MMIO disable.
- set_mailbox_irq:
Enables or disables MSI-X routing for a given PF mailbox by updating NBL_MAILBOX_QINFO_MAP_REG_ARR with the target global vector id.
- configure_msix_info:
Programs PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE to record function BDF and MSI-X mask enable attribute for each global interrupt vector.
This module manages chip-internal MSI-X routing table and global vector index space. It does NOT invoke kernel PCI MSI-X allocation helpers (pci_alloc_irq_vectors, pci_msix_alloc_irq_at, irq_domain); physical PCI MSI-X vector allocation belongs to separate device layer.
Interrupt manager instance is created during resource startup (nbl_intr_mgt_start) and attached to resource management context.
Note: Mutual exclusion for configure_msix_map, destroy_msix_map, and set_mailbox_irq is enforced by dispatch layer. These routines assume caller holds required locks.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 149 ++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 ++ .../nbl_hw_leonis/nbl_resource_leonis.c | 21 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 405 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 30 ++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 35 ++ .../nbl/nbl_include/nbl_def_hw.h | 10 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../nbl/nbl_include/nbl_include.h | 1 + 12 files changed, 713 insertions(+), 9 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 +147 -2
182 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 +14 -7
@@ -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,10 @@ 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 || + !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;
@@ -65,7 +71,6 @@ static int nbl_res_ctrl_dev_setup_eth_info(struct nbl_resource_mgt *res_mgt) res_mgt->resource_info->eth_info = eth_info; fw_port_num = res_mgt->resource_info->board_info.eth_num; - hw_ops->get_fw_eth_map (res_mgt->hw_ops_tbl->priv, ð_bitmap);if (eth_bitmap & ~((1 <<NBL_MAX_ETHERNET ) -1 )) { dev_err(dev, "FW reported invalid eth_bitmap 0x%x\n",
@@ -207,8 +212,7 @@ static int nbl_res_init_pf_num(struct nbl_resource_mgt *res_mgt)u32 pf_num =0 ;int i; -if (hw_ops->get_host_pf_mask) - hw_ops->get_host_pf_mask (res_mgt->hw_ops_tbl->priv, &pf_mask); + hw_ops->get_host_pf_mask (res_mgt->hw_ops_tbl->priv, &pf_mask);if (pf_mask ==0 ) {dev_warn (res_mgt->common->dev,"FW not ready, defer probe\n" );return -EPROBE_DEFER ;
@@ -236,9 +240,8 @@ static void nbl_res_init_board_info(struct nbl_resource_mgt *res_mgt) {struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; -if (hw_ops->get_board_info) - hw_ops->get_board_info (res_mgt->hw_ops_tbl->priv, - &res_mgt->resource_info->board_info); + hw_ops->get_board_info (res_mgt->hw_ops_tbl->priv, + &res_mgt->resource_info->board_info); }static int nbl_res_start (struct nbl_resource_mgt *res_mgt)
@@ -264,6 +267,10 @@ static int nbl_res_start(struct nbl_resource_mgt *res_mgt) ret =nbl_res_ctrl_dev_vsi_info_init (res_mgt);if (ret)return ret; + + ret =nbl_intr_mgt_start (res_mgt); +if (ret) +return ret; }return 0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -7,4 +7,5 @@#define _NBL_RESOURCE_LEONIS_H_#include "../nbl_resource.h" +#include "../nbl_interrupt.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +405 -0
405 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) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_INTERRUPT_H_ +#define _NBL_INTERRUPT_H_ + +#include "nbl_resource.h" + +#define NBL_MSIX_MAP_TABLE_MAX_ENTRIES 1024 +int nbl_res_intr_destroy_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id); +int nbl_res_intr_cfg_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 num_net_msix, +u16 num_others_msix, +bool net_msix_mask_en); +int nbl_res_intr_set_mailbox_irq (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 vector_id, +bool en_msix); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +30 -0
@@ -68,6 +68,36 @@ int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id)return -ENOENT ; } +int nbl_res_func_id_to_bdf (struct nbl_resource_mgt *res_mgt,u16 func_id, +u8 *bus,u8 *dev,u8 *function) +{ +struct nbl_common_info *common = res_mgt->common; +struct nbl_sriov_info *sriov_info; +int pfid = func_id; +u8 pf_bus, devfn; +u32 rel_pf_id; +int ret; + +if (!common->has_ctrl || !bus || !dev || !function) +return -EINVAL ; + ret =nbl_common_func_id_to_rel_pf_id (common, pfid, &rel_pf_id); +if (ret) +return ret; +if (rel_pf_id >= res_mgt->resource_info->max_pf) { +dev_err (common->dev,"PF ID %u exceeds maximum supported PF count %u\n" , + pfid, res_mgt->resource_info->max_pf); +return -ERANGE ; + } + sriov_info = res_mgt->resource_info->sriov_info + rel_pf_id; + pf_bus =PCI_BUS_NUM (sriov_info->bdf); + devfn = sriov_info->bdf &0xff ; + *bus = pf_bus; + *dev =PCI_SLOT (devfn); + *function =PCI_FUNC (devfn); + +return 0 ; +} +int nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 vsi_id,u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +35 -0
@@ -17,6 +17,38 @@struct nbl_resource_mgt ; +/* --------- INTERRUPT ---------- */ +#define NBL_MAX_OTHER_INTERRUPT 1024 +#define NBL_MAX_NET_INTERRUPT 4096 +#define NBL_NET_INTR_BASE NBL_MAX_OTHER_INTERRUPT + +#define NBL_MSIX_MAP_VALID_MASK BIT(0) +#define NBL_MSIX_MAP_INDEX_MASK GENMASK(13, 1) +#define NBL_MSIX_MAP_RSV_MASK GENMASK(15, 14) + +struct nbl_msix_map { +__le16 data; +}; + +struct nbl_msix_map_table { +struct nbl_msix_map *base_addr; +dma_addr_t dma; +size_t size; +}; + +struct nbl_func_interrupt_resource_mng { +u16 num_interrupts; +u16 num_net_interrupts; +u16 *interrupts; +struct nbl_msix_map_table msix_map_table; +}; + +struct nbl_interrupt_mgt { + DECLARE_BITMAP(intr_net_bmap, NBL_MAX_NET_INTERRUPT); + DECLARE_BITMAP(intr_other_bmap, NBL_MAX_OTHER_INTERRUPT); +struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC ]; +}; +/* --------- INFO ---------- */ struct nbl_sriov_info {unsigned int bdf;
@@ -66,8 +98,11 @@ struct nbl_resource_mgt {int nbl_res_vsi_id_to_pf_id (struct nbl_resource_mgt *res_mgt,u16 vsi_id);int nbl_res_func_id_to_vsi_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 type,u16 *vsi_id); +int nbl_res_func_id_to_bdf (struct nbl_resource_mgt *res_mgt,u16 func_id, +u8 *bus,u8 *dev,u8 *function);int nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 vsi_id,u8 *eth_num,u8 *eth_id,u8 *logic_eth_id); +int nbl_intr_mgt_start (struct nbl_resource_mgt *res_mgt);int nbl_res_pf_dev_vsi_type_to_hw_vsi_type (struct nbl_resource_mgt *res_mgt,u16 src_type,enum nbl_vsi_serv_type *dst_type);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10 -0
@@ -11,6 +11,14 @@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,
@@ -24,6 +32,8 @@ struct nbl_hw_ops {void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool en_msix,u16 global_vec_id);void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map);void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,struct nbl_board_port_info *board);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
@@ -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
illusion.wang
maintainerPATCH v24 7/11 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, and the driver_status hardware flag consumed by firmware.
HW layer overview:
The HW layer code is highly chip-specific and may benefit from additional review since it cannot be cross-checked against other implementations.
DP sub-init modules (called from nbl_dp_init()):
- dped, uped: Data/User Packet Engine Driver
- dsch: Scheduler core (qid limit init, PSHA enable inside shaping init)
- ustore, dstore: Buffer Store modules
- dvn, uvn: Virtual Descriptor Network modules
- uqm: Queue Manager
- nbl_shaping_init(): Per-port traffic shaping + DSCH PSHA config
Chip init sequence (nbl_hw_init_chip_module()):
1. nbl_dp_init() — All DP sub-modules listed above
2. nbl_intf_init() — Host adapter padpt flow control
- nbl_host_padpt_init() — Host padpt flow control registers
3. nbl_hw_set_driver_status() + nbl_flush_writes()
Chip deinit logic relies on firmware cleanup: only driver_status flag is cleared and flushed; FW releases partial hardware state automatically.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 26 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 557 +++++++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 229 +++++++ .../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 | 13 + 10 files changed, 848 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 +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include "nbl_chip.h" + +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; + +if (hw_ops->deinit_module) + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +} + +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt) +{ +u8 eth_speed = res_mgt->resource_info->board_info.eth_speed; +u8 eth_num = res_mgt->resource_info->board_info.eth_num; +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv; + +if (hw_ops->init_module) +return hw_ops->init_module (p, eth_speed, eth_num); +return -EOPNOTSUPP ; +}
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) 2025 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 +556 -1
575 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +229 -0
251 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
@@ -11,6 +11,9 @@struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +int (*init_module)(struct nbl_hw_mgt *hw_mgt,u8 eth_speed,u8 eth_num); +void (*deinit_module)(struct nbl_hw_mgt *hw_mgt); +void (*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 +13 -0
@@ -30,4 +30,17 @@ 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 , +}; + +#define NBL_QUIRK_UVN_PREFETCH_ALIGN BIT(1) +#endif
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v24 8/11 net/nebula-matrix: dispatch: add control-level routing core infrastructure
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add base dispatch layer infrastructure for control-level routing:
1. Dispatch management & ops table structures allocation
2. X-macro op table template for uniform dispatch entry registration
3. Control PF / regular PF routing logic via ctrl_lvl bitmask
4. Local chip init/deinit dispatch wrappers (no channel dependency)
Document constraint: init_module/deinit_module only valid on Control PF, caller must guard with has_ctrl to avoid NULL deref.
This patch only provides core routing skeleton, no channel message handling or resource locking logic.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_channel/nbl_channel.c | 4 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 112 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 24 ++++ .../nbl/nbl_include/nbl_def_channel.h | 32 +++++ .../nbl/nbl_include/nbl_def_dispatch.h | 42 +++++++ .../nbl/nbl_include/nbl_include.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 9 files changed, 227 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_channel/nbl_channel.c +4 -0
@@ -1030,6 +1030,10 @@ int nbl_chan_init_common(struct nbl_adapter *adap)struct nbl_channel_mgt *chan_mgt;int ret; +BUILD_BUG_ON (sizeof (struct nbl_chan_param_cfg_msix_map ) !=8 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_set_mailbox_irq ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_vsi_id ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_eth_id ) !=8 ); chan_mgt =nbl_chan_setup_chan_mgt (adap);if (IS_ERR (chan_mgt)) { ret =PTR_ERR (chan_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +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 +112 -0
112 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DISPATCH_H_ +#define _NBL_DISPATCH_H_ +#include "../nbl_include/nbl_include.h" +#include "../nbl_include/nbl_def_channel.h" +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_resource.h" +#include "../nbl_include/nbl_def_dispatch.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +struct nbl_dispatch_mgt { +struct nbl_common_info *common; +struct nbl_resource_ops_tbl *res_ops_tbl; +struct nbl_channel_ops_tbl *chan_ops_tbl; +struct nbl_dispatch_ops_tbl *disp_ops_tbl; + DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX); +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +32 -0
@@ -13,6 +13,12 @@ struct nbl_adapter;typedef void (*nbl_chan_resp )(void *,u16 ,u16 ,void *,u32 ); +enum { +NBL_CHAN_RESP_OK =0 , +NBL_CHAN_RESP_ERR =1 , +NBL_CHAN_RESP_UNIMPLEMENTED =2 , +}; +/* * Mailbox wire opcodes * Every opcode is assigned explicit fixed numeric value, stable wire ABI
@@ -252,6 +258,32 @@ enum nbl_chan_state {NBL_CHAN_STATE_NBITS }; +struct nbl_chan_param_cfg_msix_map { +__le16 num_net_msix; +__le16 num_others_msix; +__le16 msix_mask_en; +__le16 rsvd; +}; + +struct nbl_chan_param_set_mailbox_irq { +__le16 vector_id; +u8 en_msix; +u8 rsvd; +}; + +struct nbl_chan_param_get_vsi_id { +__le16 vsi_id; +__le16 type; +}; + +struct nbl_chan_param_get_eth_id { +__le16 vsi_id; +u8 eth_num; +u8 eth_id; +u8 logic_eth_id; +u8 rsvd[3 ]; +}; +struct nbl_board_port_info {u8 eth_num;u8 eth_speed;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +42 -0
42 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +2 -0
@@ -15,6 +15,8 @@#define NBL_MAX_FUNC 520#define NBL_MAX_ETHERNET 4 +/* Used for macros to pass checkpatch */ +#define NBL_NAME (x) xenum {NBL_VSI_DATA =0 ,
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
Jakub Kicinski
maintainerRe: [PATCH v24 net-next 08/11] net/nebula-matrix: dispatch: add control-level routing core infrastructure
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---net/nebula-matrix: dispatch: add control-level routing core infrastructure
This adds the nbl dispatch layer: a dispatch mgt struct, an ops table allocated with devm_kzalloc(), a ctrl_lvl bitmask, and local wrappers for the resource layer init_module/deinit_module calls. nbl_disp_init() is wired into nbl_core_init() and nbl_disp_remove() into nbl_core_remove().
A few questions about the changelog and the new code below.
Quoted 8 lines
Add base dispatch layer infrastructure for control-level routing:
1. Dispatch management & ops table structures allocation
2. X-macro op table template for uniform dispatch entry registration
3. Control PF / regular PF routing logic viactrl_lvlbitmask
4. Local chip init/deinit dispatch wrappers (no channel dependency)Document constraint: init_module/deinit_module only valid on Control PF, caller must guard with
has_ctrlto avoid NULL deref.
[Severity: Medium]
Do bullets 2 and 3 and the "Document constraint" paragraph match what the patch contains?
For bullet 2, there is no X-macro anywhere in the patch. The only related artifact is the identity macro added to nbl_include.h:
/* Used for macros to pass checkpatch */
#define NBL_NAME(x) xand the two ops that do get registered are registered by plain pointer assignment in nbl_disp_setup_ctrl_lvl():
disp_ops->init_module = nbl_disp_init_module;
disp_ops->deinit_module = nbl_disp_deinit_module;A grep for NBL_NAME( under drivers/net/ethernet/nebula-matrix/ returns a single hit, the definition itself, both at this commit and at the end of the series, so no X-macro registration table is introduced later either.
For bullet 3, only the control PF direction is installed here:
if (common->has_ctrl)
nbl_disp_setup_ctrl_lvl(disp_mgt, NBL_DISP_CTRL_LVL_MGT);NBL_DISP_CTRL_LVL_NET matches only its own enum declaration at this commit, and the non-ctrl route appears later in "net/nebula-matrix:
dispatch: add channel RPC framework & shared hw ops mutex". Could the bullet be deferred to that patch?
For the "Document constraint" paragraph, no comment describing the has_ctrl requirement appears in nbl_dispatch.c, nbl_dispatch.h or nbl_def_dispatch.h. Would it make sense to put that constraint next to the init_module/deinit_module declarations in struct nbl_dispatch_ops so a future caller can see it?
Quoted 2 lines
This patch only provides core routing skeleton, no channel message handling or resource locking logic.
[Severity: Low]
This statement seems to conflict with the nbl_channel.c and nbl_def_channel.h hunks below: the patch adds a new on-wire response code enum (NBL_CHAN_RESP_OK/ERR/UNIMPLEMENTED), four mailbox payload layouts, and four BUILD_BUG_ON() assertions inside nbl_chan_init_common(). Could the changelog mention that this patch establishes a peer/firmware facing wire contract?
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c int nbl_chan_init_common(struct nbl_adapter *adap) · line 1036
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +4
-0@@ -1030,6 +1030,10 @@ int nbl_chan_init_common(struct nbl_adapter *adap)struct nbl_channel_mgt *chan_mgt;int ret; +BUILD_BUG_ON (sizeof (struct nbl_chan_param_cfg_msix_map ) !=8 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_set_mailbox_irq ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_vsi_id ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_eth_id ) !=8 );
[Severity: Low]
The four sizes are numerically correct (2+2+2+2, 2+1+1, 2+2 and 2+1+1+1+3), so there is no functional problem here.
These are dispatch layer message structs though, and the assertions are placed in the channel layer's runtime init function. Would static_assert() next to each struct definition in nbl_def_channel.h keep the wire format check with the format it describes?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +0
-0chan_mgt =nbl_chan_setup_chan_mgt (adap);if (IS_ERR (chan_mgt)) { ret =PTR_ERR (chan_mgt);
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +0
-0@@ -0,0 +1,112 @@
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +8
-0+static void nbl_disp_deinit_module (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; + +if (res_ops->deinit_module) + res_ops->deinit_module (p); +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 26
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +10
-0+ +static int nbl_disp_init_module (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; + +if (res_ops->init_module) +return res_ops->init_module (p); +return -EOPNOTSUPP ; +}
[Severity: Low]
Can these NULL tests ever be false, and can -EOPNOTSUPP ever be returned?
nbl_res_setup_ops() already refuses to publish an incomplete table:
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.init_module ||
!res_ops.deinit_module)
return ERR_PTR(-EINVAL);and nbl_core_init() -> nbl_res_init_leonis() propagates that failure, so nbl_disp_init() only runs with both pointers set.
That makes the guards and the -EOPNOTSUPP path unreachable while advertising a return value a caller may try to handle. This is still the case at the end of the series. Would it be cleaner to keep the validation in one layer only?
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +12
-0+ +static void nbl_disp_setup_ctrl_lvl (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) +{ +struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; + +set_bit (lvl, disp_mgt->ctrl_lvl); + +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; + } +}
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +6
-0+static struct nbl_dispatch_ops_tbl * +nbl_disp_setup_ops (struct device *dev,struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_dispatch_ops_tbl *disp_ops_tbl; +struct nbl_dispatch_ops *disp_ops; +
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c line 69
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +10
-0+ disp_ops_tbl =devm_kzalloc (dev,sizeof (*disp_ops_tbl),GFP_KERNEL ); +if (!disp_ops_tbl) +return ERR_PTR (-ENOMEM ); + + disp_ops =devm_kzalloc (dev,sizeof (*disp_ops),GFP_KERNEL ); +if (!disp_ops) +return ERR_PTR (-ENOMEM ); + + disp_ops_tbl->ops = disp_ops; + disp_ops_tbl->priv = disp_mgt;
[Severity: Low]
This publishes a zeroed struct nbl_dispatch_ops through adapter->intf.dispatch_ops_tbl, and at this commit only init_module and deinit_module are ever filled, and only when common->has_ctrl is set. The other five declared ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id) stay NULL for every PF.
Unlike the sibling constructors nbl_res_setup_ops() and nbl_hw_setup_ops(), which return ERR_PTR(-EINVAL) when any op is NULL, the dispatch layer never validates the table it hands out.
To be clear about reachability: I could not find a consumer that would hit a NULL op. By the end of the series nbl_disp_setup_ctrl_lvl() fills the remaining five ops in both the MGT branch and the new else branch, and the only call sites of init_module/deinit_module, nbl_dev_setup_ctrl_dev() and nbl_dev_remove_ctrl_dev(), are reached only under if (common->has_ctrl) in nbl_dev_init()/nbl_dev_remove().
Would adding the same completeness check the resource and hw layers use, and documenting the has_ctrl-only validity of init_module/deinit_module in the header, be worth doing here?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +3
-0+ +return disp_ops_tbl; +}
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +0
-0
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h struct nbl_adapter; · line 21
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +6
-0@@ -13,6 +13,12 @@ struct nbl_adapter;typedef void (*nbl_chan_resp )(void *,u16 ,u16 ,void *,u32 ); +enum { +NBL_CHAN_RESP_OK =0 , +NBL_CHAN_RESP_ERR =1 , +NBL_CHAN_RESP_UNIMPLEMENTED =2 , +}; +
[Severity: Low]
These response codes and the four nbl_chan_param_* layouts below have no producer or consumer at this commit; they gain users in the following patch "net/nebula-matrix: dispatch: add channel RPC framework & shared hw ops mutex", which is fine for a staged series. The point is only that the changelog says this patch has no channel message handling while it defines the channel response ABI.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +0
-0@@ -0,0 +1,42 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h line 18
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +6
-0+enum { +NBL_DISP_CTRL_LVL_NEVER =0 , +NBL_DISP_CTRL_LVL_MGT , +NBL_DISP_CTRL_LVL_NET , +NBL_DISP_CTRL_LVL_MAX , +};
[Severity: Medium]NBL_DISP_CTRL_LVL_NET is declared here but never set or tested at this commit, which is the enumerator the changelog's "Control PF / regular PF routing logic via ctrl_lvl bitmask" would rely on.
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h line 19
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +2
-0@@ -15,6 +15,8 @@#define NBL_MAX_FUNC 520#define NBL_MAX_ETHERNET 4 +/* Used for macros to pass checkpatch */ +#define NBL_NAME (x) x
[Severity: Low]
This identity macro has no users. A grep for NBL_NAME( under drivers/net/ethernet/nebula-matrix/ returns only this definition, both at this commit and at the end of the series, and the X-macro table given as its justification is never added.
Also, what exactly does checkpatch object to? The comment says the macro exists so later constructs pass checkpatch rather than to address the underlying complaint. Could this define be dropped?
illusion.wang
maintainerPATCH v24 9/11 net/nebula-matrix: dispatch: add channel RPC framework & shared hw ops mutex
In reply to illusion.wangFrom: illusion wang <[email protected]>
Implement bidirectional channel request/response RPC handlers for 5 dispatch resource operations: get_vsi_id, get_eth_id, configure_msix_map, destroy_msix_map, set_mailbox_irq.
- Extend X-macro NBL_DISP_OPS_TBL to pair local dispatch entry points with cross-PF mailbox request/response callbacks.
- Add registration helper nbl_disp_setup_msg() to auto-register channel response handlers for ops with valid msg_type.
- Introduce NBL_CHAN_RESP_UNIMPLEMENTED dedicated error code for missing resource ops implementation on remote PF.
- Add dev_err logging when sending RPC ACK back to remote PF fails.
The existing init_module/deinit_module dispatch entries use msg_type = -1, so they do not register any mailbox channel handlers and are excluded from RPC logic.
- Separate local channel transmission errors and remote RPC wire response codes:
The channel layer returns ACK header err via nbl_chan_send_msg() when wait_ack=1. Translate wire protocol defined remote codes NBL_CHAN_RESP_* to standard kernel errno at dispatch request wrapper to avoid semantic confusion between wire handshake values and system error numbers exposed to upper layers.
- Collapse all fine-grained resource operation sub-errors into generic NBL_CHAN_RESP_ERR on wire to keep message payload layout unchanged and maintain backward compatibility with legacy firmware.
- Fix unimplemented ops check order in response handler to prevent NULL pointer invocation of resource ops.
Add input sanitization for mailbox response handlers:
The driver maintains cross-version interoperability; older peers may send truncated payloads. Existing min_t() + zero-init local param logic absorbs partial messages and zero-fills missing fields. To mitigate risk:
1. Allow truncated payloads (0 < data_len < sizeof(param)) for backward compatibility, continue zero-filling missing fields.
2. Reject data_len == 0 messages entirely, avoid invoking resource ops with all-zero initialized parameters.nbl_disp_chan_destroy_msix_map_resp carries no input payload and skips payload length validation.
Add ops_mutex_lock to serialize concurrent hardware-modifying dispatch resource operations, preventing race conditions between PF local calls and remote mailbox message handlers that manipulate MSI-X mapping and mailbox IRQ state.
1. Introduce disp_mgt->ops_mutex_lock, initialized via devm_mutex_init at disp_mgt allocation time; symmetrically destroyed automatically by devres on device detach, eliminating double mutex_destroy risk.
2. Add NBL_OPS_CALL_LOCK_RET macro to wrap hardware-modifying ops with exclusive lock protection for unified locking semantics.
3. Wrap configure_msix_map / destroy_msix_map / set_mailbox_irq with ops_mutex_lock; these ops mutate shared MSI-X and IRQ hardware state and can race between local PF control paths and cross-PF mailbox RPCs.
The read-only get_vsi_id / get_eth_id routines only consume static init-time metadata with no concurrent writers, so they require no locking.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 521 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 2 + .../nbl/nbl_include/nbl_def_channel.h | 1 + .../nbl/nbl_include/nbl_include.h | 1 + 4 files changed, 525 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +521 -0
@@ -3,9 +3,162 @@* Copyright (c) 2025 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; +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); +switch (ret) { +case NBL_CHAN_RESP_UNIMPLEMENTED : +return -EOPNOTSUPP ; +case NBL_CHAN_RESP_ERR : +return -EREMOTEIO ; +case NBL_CHAN_RESP_OK : +break ; +default : +return ret; + } + *vsi_id =le16_to_cpu (result.vsi_id); +return 0 ; +} + +static void nbl_disp_chan_get_vsi_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +u16 vsi_id =0 ; +int copy_len; +int ret; + +if (data_len ==0 ) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } + copy_len =min_t (size_t, data_len,sizeof (param)); +memcpy (¶m, data, copy_len); + +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; +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); +switch (ret) { +case NBL_CHAN_RESP_UNIMPLEMENTED : +return -EOPNOTSUPP ; +case NBL_CHAN_RESP_ERR : +return -EREMOTEIO ; +case NBL_CHAN_RESP_OK : +break ; +default : +return ret; + } + *eth_num = result.eth_num; + *eth_id = result.eth_id; + *logic_eth_id = result.logic_eth_id; + +return 0 ; +} + +static void nbl_disp_chan_get_eth_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int copy_len; +int ret; + +if (data_len ==0 ) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } + copy_len =min_t (size_t, data_len,sizeof (param)); +memcpy (¶m, data, copy_len); + +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 +178,341 @@ 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; +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); +switch (ret) { +case NBL_CHAN_RESP_UNIMPLEMENTED : +return -EOPNOTSUPP ; +case NBL_CHAN_RESP_PERM_DENY : +return -EPERM ; +case NBL_CHAN_RESP_ERR : +return -EREMOTEIO ; +case NBL_CHAN_RESP_OK : +return ret; +default : +return ret; + } +} + +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 copy_len; +int ret; + +if (src_id >NBL_MAX_PF_SRC_ID ) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (data_len ==0 ) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } + copy_len =min_t (size_t, data_len,sizeof (param)); +memcpy (¶m, data, copy_len); + +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; +int ret; + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , +NULL ,0 ,NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +switch (ret) { +case NBL_CHAN_RESP_UNIMPLEMENTED : +return -EOPNOTSUPP ; +case NBL_CHAN_RESP_PERM_DENY : +return -EPERM ; +case NBL_CHAN_RESP_ERR : +return -EREMOTEIO ; +case NBL_CHAN_RESP_OK : +return ret; +default : +return ret; + } +} + +static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret; + +if (src_id >NBL_MAX_PF_SRC_ID ) { + err =NBL_CHAN_RESP_PERM_DENY ; + goto ack_out; + } +if (res_ops->destroy_msix_map) { +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->destroy_msix_map (p, src_id); +mutex_unlock (&disp_mgt->ops_mutex_lock); +if (ret) + err =NBL_CHAN_RESP_ERR ; + }else { + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + } +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_DESTROY_MSIX_MAP ); +} + +static int nbl_disp_chan_set_mailbox_irq_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send; +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); +switch (ret) { +case NBL_CHAN_RESP_UNIMPLEMENTED : +return -EOPNOTSUPP ; +case NBL_CHAN_RESP_ERR : +return -EREMOTEIO ; +case NBL_CHAN_RESP_OK : +return ret; +default : +return ret; + } +} + +static void nbl_disp_chan_set_mailbox_irq_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +bool en_msix; +u16 vector_id; +int copy_len; +int ret; + +if (data_len ==0 ) { + err =NBL_CHAN_RESP_ERR ; + goto ack_out; + } + copy_len =min_t (size_t, data_len,sizeof (param)); +memcpy (¶m, data, copy_len); + 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_setup_ctrl_lvl (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) {struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops;
@@ -34,6 +522,18 @@ static void nbl_disp_setup_ctrl_lvl(struct nbl_dispatch_mgt *disp_mgt, u32 lvl)if (test_bit (NBL_DISP_CTRL_LVL_MGT , disp_mgt->ctrl_lvl)) { disp_ops->init_module = nbl_disp_init_module; disp_ops->deinit_module = nbl_disp_deinit_module; + disp_ops->cfg_msix_map = nbl_disp_cfg_msix_map; + disp_ops->destroy_msix_map = nbl_disp_destroy_msix_map; + disp_ops->set_mailbox_irq = nbl_disp_set_mailbox_irq; + disp_ops->get_vsi_id = nbl_disp_get_vsi_id; + disp_ops->get_eth_id = nbl_disp_get_eth_id; + }else { + disp_ops->cfg_msix_map = + nbl_disp_chan_cfg_msix_map_req; + disp_ops->destroy_msix_map = nbl_disp_chan_destroy_msix_map_req; + disp_ops->set_mailbox_irq = nbl_disp_chan_set_mailbox_irq_req; + disp_ops->get_vsi_id = nbl_disp_chan_get_vsi_id_req; + disp_ops->get_eth_id = nbl_disp_chan_get_eth_id_req; } }
@@ -42,12 +542,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; }
@@ -101,12 +605,29 @@ int nbl_disp_init(struct nbl_adapter *adapter) adapter->core.disp_mgt = disp_mgt; adapter->intf.dispatch_ops_tbl = disp_ops_tbl; + ret =nbl_disp_setup_msg (disp_mgt); +if (ret) +return ret; +if (common->has_ctrl)nbl_disp_setup_ctrl_lvl (disp_mgt,NBL_DISP_CTRL_LVL_MGT ); +/* +* For non-control PF with network capability, enable net control +* level. +* All dispatch ops declared with NBL_DISP_CTRL_LVL_MGT fall back +* to remote mailbox msg_req handlers when MGT bit is not set. +*/ +if (common->has_net) +nbl_disp_setup_ctrl_lvl (disp_mgt,NBL_DISP_CTRL_LVL_NET ); +return 0 ; }void nbl_disp_remove (struct nbl_adapter *adapter) { +/* +* 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
@@ -19,6 +19,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 +1 -0
@@ -17,6 +17,7 @@ enum {NBL_CHAN_RESP_OK =0 ,NBL_CHAN_RESP_ERR =1 ,NBL_CHAN_RESP_UNIMPLEMENTED =2 , + NBL_CHAN_RESP_PERM_DENY = 3, };/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +1 -0
@@ -15,6 +15,7 @@#define NBL_MAX_FUNC 520#define NBL_MAX_ETHERNET 4 +#define NBL_MAX_PF_SRC_ID 3/* Used for macros to pass checkpatch */ #define NBL_NAME (x) x
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v24 10/11 net/nebula-matrix: add common/ctrl dev init/remove operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() initialization helpers with paired teardown routines, and hook them into nbl_dev_init / nbl_dev_remove.
Mailbox message processing is implemented via work_struct. This task registration framework is reused for interrupt-driven receive now, and can be shared with polling receive mode introduced in follow-up patches.
Extend channel send logic with polling ACK fallback path. During early device initialization before interrupts are enabled, synchronous mailbox requests rely on polling to wait for firmware ACK, avoiding silent success and uninitialized variable reads when NBL_CHAN_INTERRUPT_READY is not yet set.
Chip core hardware initialization is fully handled by firmware during power-on; the driver only configures functional table entries and registers after hardware is ready. Thus invoking nbl_dev_setup_common_dev() before ctrl dev setup does not trigger hardware faults, all register accesses are safe.
Teardown order explanation:
1. Remove ctrl dev first: notify firmware to clean all per-PF hardware state including qinfo registers via driver status flag.
2. Then tear down common device queue resources.
Firmware cleanup ensures qinfo registers are valid during subsequent common dev deinit writes, avoiding PCIe master abort or hardware access panics.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_channel/nbl_channel.c | 72 +++++- .../nbl/nbl_channel/nbl_channel.h | 3 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 21 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 240 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 57 +++++ .../nbl/nbl_include/nbl_def_common.h | 3 + .../nbl/nbl_include/nbl_def_dev.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 10 files changed, 420 insertions(+), 1 deletion(-) 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_channel/nbl_channel.c +71 -1
108 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h +3 -0
@@ -24,6 +24,9 @@#define NBL_CHAN_TX_WAIT_US 100#define NBL_CHAN_TX_WAIT_US_MAX 120#define NBL_CHAN_TX_WAIT_TIMES 100 +#define NBL_CHAN_TX_WAIT_ACK_US_MIN 1000 +#define NBL_CHAN_TX_WAIT_ACK_US_MAX 1200 +#define NBL_CHAN_TX_WAIT_ACK_TIMES 5000#define NBL_CHAN_QUEUE_LEN 256#define NBL_CHAN_BUF_LEN 4096#define NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN 16
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +21 -0
@@ -7,6 +7,27 @@#include <linux/jhash.h> #include "nbl_common.h" +void nbl_common_destroy_wq (struct nbl_common_info *common) +{ +destroy_workqueue (common->wq); +} + +int nbl_common_create_wq (struct nbl_common_info *common) +{ +char wq_name[32 ]; + +snprintf (wq_name,sizeof (wq_name),"nbl_wq_%s" ,pci_name (common->pdev)); + common->wq =alloc_workqueue ("%s" ,WQ_UNBOUND ,0 , wq_name); +if (!common->wq) { +pr_err ("Failed to create workqueue nbl_wq\n" ); + goto alloc_wq_failed; + } + +return 0 ; +alloc_wq_failed: +return -ENOMEM ; +} +/* * nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id *
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 +240 -0
240 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +57 -0
57 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +3 -0
@@ -28,6 +28,7 @@ static inline u32 nbl_vsi_id_gap(u32 m) }struct nbl_common_info { +struct workqueue_struct *wq;struct pci_dev *pdev;struct device *dev;u32 msg_enable;
@@ -54,6 +55,8 @@ struct nbl_hash_tbl_key {u16 resv; }; +void nbl_common_destroy_wq (struct nbl_common_info *common); +int nbl_common_create_wq (struct nbl_common_info *common);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 *
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) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_DEV_H_ +#define _NBL_DEF_DEV_H_ + +struct nbl_adapter ; + +int nbl_dev_init (struct nbl_adapter *adapter); +void nbl_dev_remove (struct nbl_adapter *adapter); + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
@@ -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
Jakub Kicinski
maintainerRe: [PATCH v24 net-next 10/11] net/nebula-matrix: add common/ctrl dev init/remove operation
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---net/nebula-matrix: add common/ctrl dev init/remove operation
This adds nbl_dev.c with nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() plus their teardown paths, hooks them into nbl_core_init()/nbl_core_remove(), adds a per-adapter workqueue helper, and extends nbl_chan_send_msg() with a polling ACK path used when NBL_CHAN_INTERRUPT_READY is not set.
A few questions on the changelog and on the new code below.
[Severity: Low]
Is this paragraph describing the state of the tree at this commit?
Quoted 3 lines
Mailbox message processing is implemented via
work_struct. This task registration framework is reused for interrupt-driven receive now, and can be shared with polling receive mode introduced in follow-up patches.
At this commit NBL_CHAN_INTERRUPT_READY is only ever tested, in nbl_chan_send_msg(); nothing sets it, and there is no request_irq() or pci_alloc_irq_vectors() anywhere under drivers/net/ethernet/nebula-matrix/. The bit is first set (and the mailbox IRQ first requested) by the later "net/nebula-matrix: add common dev start/stop operation" patch.
So the relationship looks inverted: polling is what is live now, and the wait_event_timeout() branch of nbl_chan_send_msg() is unreachable here. Every synchronous request issued by this patch (get_vsi_id/get_eth_id from nbl_dev_setup_common_dev()) goes through the new polling loop, which can run NBL_CHAN_TX_WAIT_ACK_TIMES (5000) iterations of roughly 1 ms, i.e. up to about 5 seconds per message during probe. Would it be worth saying that explicitly?
Also on this sentence:
Quoted 3 lines
requests rely on polling to wait for firmware ACK, avoiding silent success and uninitialized variable reads when
NBL_CHAN_INTERRUPT_READYis not yet set.
Before this patch, ret still held 0 from nbl_chan_kick_tx_ring() when the if/else fell through, so the old behaviour was returning success with an unpopulated response buffer rather than reading an uninitialized variable. Could the wording be adjusted?
Quoted 21 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +3
-0@@ -636,10 +636,13 @@ static void nbl_chan_advance_rx_ring(struct nbl_channel_mgt *chan_mgt,static void nbl_chan_clean_queue (struct nbl_channel_mgt *chan_mgt,struct nbl_chan_info *chan_info) { +struct nbl_common_info *common = chan_mgt->common;struct nbl_chan_ring *rxq = &chan_info->rxq;struct device *dev = chan_mgt->common->dev;struct nbl_chan_rx_desc *rx_desc;struct nbl_chan_buf *rx_buf; +struct work_struct *task; +bool more_work = false;u16 next_to_clean;u32 budget =64 ;u16 flags;@@ -666,11 +669,22 @@ static void nbl_chan_clean_queue(struct nbl_channel_mgt *chan_mgt, next_to_clean =0 ; rx_desc =NBL_CHAN_RX_RING_TO_DESC (rxq, next_to_clean);
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static void nbl_chan_clean_queue(struct nbl_channel_mgt *chan_mgt, · line 679
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +4
-1rx_buf =NBL_CHAN_RX_RING_TO_BUF (rxq, next_to_clean); -if (--budget ==0 ) +if (--budget ==0 ) { + more_work = true;break ; + }cond_resched (); } rxq->next_to_clean = next_to_clean; +
[Severity: Low]
Should the changelog mention that nbl_chan_clean_queue() becomes a self-rearming worker here? The changelog only says "Mailbox message processing is implemented via work_struct" and describes the polling ACK fallback, but this hunk also changes the semantics of an existing function in nbl_channel.c: it now re-queues its own work item on budget exhaustion and returns early on shutdown.
Small related point: more_work is set purely on budget exhaustion, so a ring holding exactly 64 used descriptors re-arms the work once with nothing left to clean. Is that intended?
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static void nbl_chan_clean_queue(struct nbl_channel_mgt *chan_mgt, · line 682
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +3
-0+/* Prevent queue_work after teardown clears clean_task */ +if (READ_ONCE (chan_info->shutdown)) +return ;
[Severity: Low]
Does this comment hold? The guard is two independent unordered loads followed by queue_work(), with nothing serializing them against nbl_chan_teardown_queue().
Looking at nbl_chan_teardown_queue():
while (atomic_read(&chan_info->inflight_tx_cnt) != 0) {
if (time_after(jiffies, wait_start + wait_timeout)) {
dev_warn(chan_mgt->common->dev,
"teardown: wait inflight_tx_cnt timeout, force continue\n");
ret = -ETIMEDOUT;
break;
}
...
}
/* Step3: All send paths drained, safely cancel cleanup work */
if (chan_info->clean_task) {
cancel_work_sync(chan_info->clean_task);
chan_info->clean_task = NULL;
}The drain is bounded at 5 s and teardown continues regardless, so a context that has already observed shutdown == false and a non-NULL clean_task can still call queue_work() after teardown finished. The flag check narrows the window but does not close it, and the same pattern is repeated in the new polling loop of nbl_chan_send_msg(). Could the comment be reworded, or the publish/clear of clean_task be made to actually interlock with the readers?
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +5
-0+if (common->wq && more_work) { + task =READ_ONCE (chan_info->clean_task); +if (task) +queue_work (common->wq, task); + } } static void nbl_chan_clean_queue_subtask(struct nbl_channel_mgt *chan_mgt,
[ ... ]
Quoted 28 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +24
-0@@ -869,6 +885,60 @@ static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt,WRITE_ONCE (wait_head->ack_data_len,0 );spin_unlock_irq (&wait_head->status_lock); goto inflight_dec_out; + }else { +/* Polling wait path for synchronous ACK */ +while (i--) { +if (READ_ONCE (chan_info->shutdown)) { + ret = -ESHUTDOWN ; +/* +* Shutdown happens during polling wait, +* reclaim slot +*/ +spin_lock_irq (&wait_head->status_lock); +WRITE_ONCE (wait_head->acked,0 ); +WRITE_ONCE (wait_head->ack_data,NULL ); +WRITE_ONCE (wait_head->ack_data_len,0 ); +WRITE_ONCE (wait_head->status, +NBL_MBX_STATUS_TIMEOUT ); +spin_unlock_irq (&wait_head->status_lock); + goto inflight_dec_out; + } + + task =READ_ONCE (chan_info->clean_task); +if (common->wq && task && + !READ_ONCE (chan_info->shutdown)) +queue_work (common->wq, task); +
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt, · line 921
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +10
-0+spin_lock_irq (&wait_head->status_lock); +if (READ_ONCE (wait_head->acked)) { + chan_send->ack_len = wait_head->ack_data_len; + ret = wait_head->ack_err; +WRITE_ONCE (wait_head->acked,0 ); +WRITE_ONCE (wait_head->status, +NBL_MBX_STATUS_IDLE ); +spin_unlock_irq (&wait_head->status_lock); + goto inflight_dec_out; + }
[Severity: Low]
Is it intentional that this success path leaves wait_head->ack_data and wait_head->ack_data_len set while publishing the slot as NBL_MBX_STATUS_IDLE?
Every other exit of nbl_chan_send_msg() clears both, for example the interrupt-wait success path just above:
WRITE_ONCE(wait_head->acked, 0); WRITE_ONCE(wait_head->status, NBL_MBX_STATUS_IDLE); WRITE_ONCE(wait_head->ack_data, NULL); WRITE_ONCE(wait_head->ack_data_len, 0);
and so do the new polling shutdown and polling timeout blocks. Here the slot is released as IDLE with ack_data still pointing at the caller's stack response buffer (for instance the local result struct in nbl_disp_chan_get_vsi_id_req()) and a non-zero ack_data_len.
Today nothing dereferences it, because nbl_chan_recv_ack_msg() only writes through ack_data when status == NBL_MBX_STATUS_WAITING, and the send path re-assigns both fields before re-arming a slot as WAITING. The visible effect is a stale length in the "Skip ack with invalid status" diagnostic. Should this path clear them anyway to keep the slot-release contract uniform?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +4
-0+spin_unlock_irq (&wait_head->status_lock); + +usleep_range (NBL_CHAN_TX_WAIT_ACK_US_MIN , +NBL_CHAN_TX_WAIT_ACK_US_MAX );
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c static int nbl_chan_send_msg(struct nbl_channel_mgt *chan_mgt, · line 935
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +10
-0+cond_resched (); + } + +/* Polling loop exhausted, reclaim slot */ +spin_lock_irq (&wait_head->status_lock); +WRITE_ONCE (wait_head->acked,0 ); +WRITE_ONCE (wait_head->ack_data,NULL ); +WRITE_ONCE (wait_head->ack_data_len,0 ); +WRITE_ONCE (wait_head->status,NBL_MBX_STATUS_TIMEOUT ); +spin_unlock_irq (&wait_head->status_lock);
[Severity: Low]
Can this block throw away an ACK that arrived during the last sleep?
The final iteration tests acked before its usleep_range(1000, 1200), and this cleanup then clears acked and forces NBL_MBX_STATUS_TIMEOUT without re-testing it. An ACK delivered in that last window is processed by the clean work item, which reaches nbl_chan_recv_ack_msg():
ack_done: WRITE_ONCE(wait_head->acked, 1); spin_unlock_irq(&wait_head->status_lock);
That only sets acked/ack_err/ack_data_len and leaves status at NBL_MBX_STATUS_WAITING, so the cleanup here cannot distinguish "never acked" from "just acked". The caller gets -ETIMEDOUT even though the response was already copied into its buffer, and in nbl_dev_setup_common_dev() that aborts nbl_dev_init() and the whole probe. The interrupt path re-tests the status before overwriting it; should this one do the same?
Quoted 28 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +6
-0+ +dev_err_ratelimited (dev, +"Channel polling ack failed, message type: %d msg id: %u\n" , + chan_send->msg_type, msgid); + ret = -ETIMEDOUT ; + goto inflight_dec_out; } inflight_dec_out:drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h +3
-0@@ -24,6 +24,9 @@#define NBL_CHAN_TX_WAIT_US 100#define NBL_CHAN_TX_WAIT_US_MAX 120#define NBL_CHAN_TX_WAIT_TIMES 100 +#define NBL_CHAN_TX_WAIT_ACK_US_MIN 1000 +#define NBL_CHAN_TX_WAIT_ACK_US_MAX 1200 +#define NBL_CHAN_TX_WAIT_ACK_TIMES 5000#define NBL_CHAN_QUEUE_LEN 256#define NBL_CHAN_BUF_LEN 4096#define NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN 16drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +0
-0
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 13
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +4
-0@@ -7,6 +7,27 @@#include <linux/jhash.h> #include "nbl_common.h" +void nbl_common_destroy_wq (struct nbl_common_info *common) +{ +destroy_workqueue (common->wq); +}
[Severity: Medium]
Should this set common->wq = NULL after destroy_workqueue()?
Both new queue_work() sites use the pointer itself as the liveness test:
nbl_chan_clean_queue():
if (common->wq && more_work) {
task = READ_ONCE(chan_info->clean_task);
if (task)
queue_work(common->wq, task);
}nbl_chan_send_msg() polling loop:
task = READ_ONCE(chan_info->clean_task); if (common->wq && task && !READ_ONCE(chan_info->shutdown)) queue_work(common->wq, task);
Can this end up as a use-after-free of the workqueue? nbl_dev_remove() runs nbl_dev_remove_common_dev() (which reaches nbl_chan_teardown_queue(), whose inflight drain is explicitly best-effort: after 5 s it prints "teardown: wait inflight_tx_cnt timeout, force continue", sets -ETIMEDOUT and proceeds to cancel_work_sync() plus clean_task = NULL), then calls nbl_common_destroy_wq(common) unconditionally, ignoring that result.
Meanwhile the polling loop itself can run 5000 iterations of 1.0-1.2 ms, which is longer than the 5 s drain bound. A sender preempted between its shutdown check and queue_work(common->wq, task) would then queue onto a freed workqueue and re-arm a work item after cancel_work_sync(). Would clearing common->wq under the same ordering that clears clean_task, plus a NULL guard here, close that?
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +17
-0+ +int nbl_common_create_wq (struct nbl_common_info *common) +{ +char wq_name[32 ]; + +snprintf (wq_name,sizeof (wq_name),"nbl_wq_%s" ,pci_name (common->pdev)); + common->wq =alloc_workqueue ("%s" ,WQ_UNBOUND ,0 , wq_name); +if (!common->wq) { +pr_err ("Failed to create workqueue nbl_wq\n" ); + goto alloc_wq_failed; + } + +return 0 ; +alloc_wq_failed: +return -ENOMEM ; +} +
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 28
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +12
-0+/* ---------- Channel config ---------- */ +static void nbl_dev_setup_chan_qinfo (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv; +struct nbl_common_info *common = dev_mgt->common; + +if (!chan_ops->check_queue_exist (priv, chan_type)) +return ; + + chan_ops->cfg_chan_qinfo_map_table (priv, common->hw_bus, common->devid); +}
[Severity: Low]
This isn't a bug introduced here, but this patch adds the only caller of cfg_chan_qinfo_map_table(), which makes an existing comment checkable and wrong. In nbl_res_ctrl_dev_sriov_info_init() the hw_bus assignment carries:
/*
* common->hw_bus supplies bus number for channel mailbox QINFO mapping.
* Execution order guarantee: this assignment runs before
* cfg_chan_qinfo_map_table() in nbl_dev_start(), only executed
* on control PF path.
*/
There is no nbl_dev_start() at this commit, and even after "net/nebula-matrix: add common dev start/stop operation" adds one, it does not call cfg_chan_qinfo_map_table(); the call lives in nbl_dev_setup_chan_qinfo() from nbl_dev_setup_ctrl_dev(). The ordering claim itself holds, only the named consumer is wrong. Could the comment be updated to name nbl_dev_setup_ctrl_dev()?
[Severity: Medium]
Can this write clobber the mailbox MSI-X fields of other PFs?
nbl_chan_cfg_qinfo_map_table() loops over every host PF:
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 nbl_hw_cfg_mailbox_qinfo() is a full-word write built from zero:
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));
so NBL_MAILBOX_QINFO_MAP_MSIX_IDX and MSIX_IDX_VALID are zeroed. Those are exactly the fields nbl_hw_set_mailbox_irq() programs in the same register, and that function already warns about this:
/*
* Note: This RMW is currently safe because the two callers are strictly
* sequential: nbl_hw_cfg_mailbox_qinfo() runs at init, nbl_hw_set_mailbox_irq()
* runs at start. Future reset/hot-add/VF-reinit paths must preserve this
* ordering; ...
*/
This patch puts the clobbering write on the ctrl-PF probe path, and it rewrites entries belonging to other functions. If PF0 is unbound and rebound while other PF instances stay bound with their mailbox MSI-X already programmed on their behalf by the ctrl PF, do those functions lose MSIX_IDX_VALID in hardware while their drivers still have NBL_CHAN_INTERRUPT_READY set and keep waiting on interrupts? Would making this write an RMW under reg_lock, or limiting it to func_ids owned by this PF, be preferable?
Quoted 24 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +24
-0+ +static int nbl_dev_setup_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->setup_queue (priv, chan_type); + +return ret; +} + +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; +}
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +3
-0+/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 98
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +7
-0+ ret =nbl_dev_setup_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +if (ret) +return ret; + +INIT_WORK (&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX , + &common_dev->clean_mbx_task);
[Severity: Low]
Should the publication of clean_task here be annotated? The store side is a plain assignment in nbl_chan_register_chan_task():
chan_info->clean_task = task;
and the clearing side in nbl_chan_teardown_queue() is likewise a plain chan_info->clean_task = NULL, while all consumers added by this patch read it with READ_ONCE() and immediately queue_work() the result. The asymmetry is an unmarked-write/marked-read race that KCSAN would flag, and in principle a cross-CPU reader could observe the pointer before the INIT_WORK() stores to work->func. I could not find such a remote reader at this commit or at the end of the series, so this looks latent rather than live. Would WRITE_ONCE() or smp_store_release() here match the readers?
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +12
-0+/* +* Even if has_ctrl=false (no dedicated control PF channel), we fetch +* VSI/ETH info via regular mailbox message instead of +* dedicated control command. +*/ + ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); +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;
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 133
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +11
-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 ; +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +}
[Severity: Low]nbl_chan_teardown_queue() and nbl_chan_setup_queue() came from the earlier "net/nebula-matrix: add channel layer" patch, so this isn't introduced here, but this patch adds the first callers, so it becomes reachable.
Teardown puts both mailbox queues into hardware reset via stop_mailbox_rxq()/stop_mailbox_txq() but leaves chan_info->init_done true, chan_info->shutdown true, and all ring indices (txq->next_to_use, txq->tail_ptr, rxq->next_to_clean/next_to_use/tail_ptr) at stale values. Since nbl_chan_setup_queue() starts with:
if (READ_ONCE(chan_info->init_done)) return 0;
would a later re-init silently report success without re-programming the queue base/size/QUEUE_EN registers, re-arming RX descriptors, or clearing shutdown? Today the only setup caller is nbl_dev_setup_common_dev() and chan_info is freshly devm_kzalloc()'d per probe, so nothing re-inits within one adapter lifetime, but the reset/recovery paths the changelog mentions would hit it. Should teardown clear init_done/shutdown and reset the ring indices?
Related ordering question in the same function: nbl_chan_stop_queue() runs before the inflight-sender drain, so a sender that already passed its shutdown check can still publish an AVAIL descriptor, bump txq->tail_ptr and ring the doorbell of an already-reset queue. At the end of the series the mailbox worker sends ACKs via nbl_chan_send_ack() concurrently with removal, so this is reachable; the effect looks like a dropped ACK plus a tail counter permanently ahead of the zeroed hardware tail. Would draining before stopping the queues be safer?
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +15
-0+ +static int nbl_dev_setup_ctrl_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +int ret; + + ret = disp_ops->init_module (dev_mgt->disp_ops_tbl->priv); +if (ret) +return ret; + +nbl_dev_setup_chan_qinfo (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); + +return 0 ; +}
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+int nbl_dev_init (struct nbl_adapter *adapter) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +4
-0+/* +* Chip hardware initialization is completed by firmware at power-up. +* Only driver functional table/register config follows here, safe to +* access hardware registers before ctrl dev setup.
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 216
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+*/ + ret =nbl_dev_setup_common_dev (adapter); +if (ret) + goto setup_err; + +if (common->has_ctrl) { + ret =nbl_dev_setup_ctrl_dev (adapter); +if (ret) + goto setup_ctrl_dev_fail; + }
[Severity: Medium]
Does the firmware really cover everything this ordering depends on?
nbl_dev_setup_common_dev() reaches nbl_chan_setup_queue(), which enables mailbox DMA before nbl_dev_setup_ctrl_dev() has run:
nbl_chan_config_queue(chan_mgt, chan_info, true); /* tx */ nbl_chan_config_queue(chan_mgt, chan_info, false); /* rx */ nbl_chan_update_tail_ptr(hw_ops, chan_mgt->hw_ops_tbl->priv, rxq->tail_ptr, NBL_MB_RX_QID);
Only afterwards does nbl_dev_setup_ctrl_dev() call init_module(), which goes to nbl_hw_init_module() -> nbl_intf_init() -> nbl_host_padpt_init() writing NBL_HOST_PADPT_HOST_CFG_FC_CPLH_UP and the other flow-control credit registers, plus nbl_hw_set_driver_status(true); and then nbl_dev_setup_chan_qinfo() programs the per-function routing map NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id). Those are driver writes, not firmware ones, so the changelog statement
Quoted 3 lines
Chip core hardware initialization is fully handled by firmware during power-on; the driver only configures functional table entries and registers after hardware is ready.
does not seem to cover them. Per the driver's own comment in nbl_hw_get_board_info(), these registers read zero after cold boot, FLR or bus reset, so between queue enable and the qinfo write the mailbox block is armed with an all-zero (00:00.0) routing entry.
For a PF with has_ctrl == false, nbl_dev_setup_ctrl_dev() is skipped entirely, yet nbl_dev_setup_common_dev() deliberately issues real mailbox transactions (get_vsi_id/get_eth_id resolve to the request variants). Does that leave such a PF depending on a separate ctrl PF instance having already programmed its qinfo entry, with nothing in the code enforcing or checking it? If the ctrl PF is unbound or assigned to vfio-pci, the new polling fallback turns this into a silent multi-second stall before -ETIMEDOUT. Would it be safer to program the credits, driver status and qinfo map before enabling the mailbox queues?
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +8
-0+ +return 0 ; +setup_ctrl_dev_fail: +nbl_dev_remove_common_dev (adapter); +setup_err: +nbl_common_destroy_wq (common); +return ret; +}
[ ... ]
illusion.wang
maintainerPATCH v24 11/11 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add device start/stop helper functions to manage MSI-X vector mapping, mailbox interrupt resource initialization and deinitialization. Create unbound global workqueue for mailbox task scheduling; this shared work infrastructure supports both current interrupt-driven receive and future polling receive path.
This patch implements complete startup and shutdown flow for common device resources:
1. Add nbl_dev_start() to finish device startup procedure:
- Configure hardware MSI-X mapping table for different interrupt types
- Allocate required MSI-X irq vectors via pci_alloc_irq_vectors
- Request mailbox IRQ; interrupt handler schedules mailbox processing work
- Enable hardware mailbox interrupt and mark channel interrupt ready
2. Add nbl_dev_stop() to tear down device resources safely in strict order:
- Update software channel state first to switch to polling, then mask hardware interrupt to avoid stale ACK handling
- Free mailbox IRQ handler and release MSI-X vector resources
- Destroy hardware MSI-X mapping table
Extend channel TX waiting logic with polling fallback and shutdown detection. When interrupt path is disabled, send routines rely on active polling to wait for message ACK, preventing deadlock during device stop.
Hook nbl_core_start() / nbl_core_stop() into PCI probe and remove paths.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 259 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 7 +- .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 21 +- 5 files changed, 285 insertions(+), 6 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 +259 -0
280 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c +2 -5
@@ -9,8 +9,7 @@ void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt) {struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; -if (hw_ops->deinit_module) - hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); }int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt)
@@ -20,7 +19,5 @@ int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt)struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv; -if (hw_ops->init_module) -return hw_ops->init_module (p, eth_speed, eth_num); -return -EOPNOTSUPP ; +return hw_ops->init_module (p, eth_speed, eth_num); }
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 +20 -1
@@ -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) {
@@ -131,7 +141,14 @@ static int nbl_probe(struct pci_dev *pdev, goto adapter_init_err; }pci_set_drvdata (pdev, adapter); + err =nbl_core_start (adapter); +if (err) + goto core_start_err; +return 0 ; +core_start_err: +pci_set_drvdata (pdev,NULL ); +nbl_core_remove (adapter); adapter_init_err:pci_clear_master (pdev); configure_dma_err:
@@ -142,8 +159,10 @@ static void nbl_remove(struct pci_dev *pdev) {struct nbl_adapter *adapter =pci_get_drvdata (pdev); -if (adapter) +if (adapter) { +nbl_core_stop (adapter);nbl_core_remove (adapter); + }pci_clear_master (pdev); }
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [PATCH v24 net-next 11/11] net/nebula-matrix: add common dev start/stop operation
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---net/nebula-matrix: add common dev start/stop operation
Adds nbl_dev_start()/nbl_dev_stop() to configure the hardware MSI-X map, allocate MSI-X vectors, request/free the mailbox IRQ and enable/disable the mailbox interrupt, and hooks nbl_core_start()/nbl_core_stop() into the PCI probe and remove paths. Also drops the NULL checks around the chip init_module/deinit_module ops.
A few questions below.
Quoted 7 lines
net/nebula-matrix: add common dev start/stop operationAdd device start/stop helper functions to manage MSI-X vector mapping, mailbox interrupt resource initialization and deinitialization. Create unbound global workqueue for mailbox task scheduling; this shared work infrastructure supports both current interrupt-driven receive and future polling receive path.
[ ... ]
Quoted 3 lines
Extend channel TX waiting logic with polling fallback and shutdown detection. When interrupt path is disabled, send routines rely on active polling to wait for message ACK, preventing deadlock during device stop.
[Severity: Low]
Do these two paragraphs describe changes that are in this patch?
Diffing this commit against its parent for nbl_common/ and nbl_channel/ gives an empty diff. The workqueue is created by the pre-existing nbl_common_create_wq():
common->wq = alloc_workqueue("%s", WQ_UNBOUND, 0, wq_name);which is per-PCI-device rather than global, and the polling/shutdown-aware ACK wait already exists in nbl_chan_send_msg() from the preceding "add common/ctrl dev init/remove operation" commit.
This patch only consumes both, via queue_work() in nbl_dev_clean_mailbox_schedule() and chan_ops->set_queue_state(). Could the changelog be adjusted so bisection and backporting point at the commit that actually adds them?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0@@ -14,6 +25,187 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; } +static int nbl_dev_request_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +9
-0+snprintf (dev_common->mailbox_name,sizeof (dev_common->mailbox_name), +"nbl_mailbox@pci:%s" ,pci_name (common->pdev)); + err =request_irq (irq_num, nbl_dev_clean_mailbox,0 , + dev_common->mailbox_name, dev_mgt); +if (err) +return err; + +return 0 ; +}
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+static int nbl_dev_disable_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{
[ ... ]
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 134
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* This helper is invoked in two paths: +* 1. Error unwind path of nbl_dev_start(): immediately followed by +* nbl_dev_free_mailbox_irq(), channel resources +* are fully torn down afterwards, no stale descriptors remain. +* 2. Normal device stop path nbl_dev_stop(): free_irq() synchronously +* waits for any in-flight threaded irq bottom-half handler to +* finish execution, all pending mailbox cleanup work completes +* before channel teardown in late remove stage. No stuck +* descriptors will linger in either scenario. +*/
[Severity: Low]
Is there actually a threaded IRQ bottom half here for free_irq() to wait on?
nbl_dev_request_mailbox_irq() uses request_irq(), which passes thread_fn == NULL to request_threaded_irq(), so nbl_dev_clean_mailbox() runs entirely in hardirq context.
The real bottom half is a workqueue item:
static irqreturn_t nbl_dev_clean_mailbox(int irq, void *data)
{
nbl_dev_clean_mailbox_schedule(dev_mgt); /* queue_work(common->wq, ...) */
return IRQ_HANDLED;}
free_irq() has no knowledge of that work item. And nbl_dev_stop() follows free_irq() with cancel_work_sync(&common_dev->clean_mbx_task), which dequeues a queued-but-not-yet-started item so it never runs, rather than letting "all pending mailbox cleanup work complete".
Could the comment be reworded to match what the code does?
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 141
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +7
-0+ chan_ops->set_queue_state (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_INTERRUPT_READY , +NBL_CHAN_TYPE_MAILBOX , false); + +return disp_ops->set_mailbox_irq (dev_mgt->disp_ops_tbl->priv, + local_vec_id, false); +}
[Severity: Low]
This isn't a bug today, but the wait strategy in nbl_chan_send_msg() is picked once from an unlocked test_bit():
if (test_bit(NBL_CHAN_INTERRUPT_READY, chan_info->state)) {
... wait_event_timeout(wait_head->wait_queue,
READ_ONCE(wait_head->acked) || READ_ONCE(chan_info->shutdown),
NBL_CHAN_ACK_WAIT_TIME);A sender that already sampled the bit as set and committed to that branch would not be released by nbl_dev_stop(), since the stop path never sets chan_info->shutdown (only nbl_chan_teardown_queue() does, and it runs later) and never wakes the wait queues, so it would burn the full ack timeout and report a spurious failure.
Enumerating the ack=1 senders, all of them are the dispatch request wrappers called only from nbl_dev_init()/nbl_dev_start()/nbl_dev_stop(), i.e. probe/remove for that device, which the driver core serialises, and the mailbox RX path only sends acks with ack=0. So no second waiter can exist for a given chan_info at the moment. Is it worth re-checking the bit inside the wait, or setting shutdown/waking the waiters here, for future concurrent users?
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -238,3 +438,62 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 452
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +11
-0+/* ---------- Dev start process ---------- */ +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) +return ret;
[Severity: Medium]
Should this return jump to init_interrupt_scheme_err instead, so that nbl_dev_destroy_msix_map() runs?
Every other step in the sequence has an unwind label, and this one can fail after the hardware side already committed. On a non-control PF (has_ctrl == 0, i.e. any function other than PF0), cfg_msix_map is nbl_disp_chan_cfg_msix_map_req(), a mailbox RPC that returns whatever nbl_chan_send_msg() returns, including -ETIMEDOUT when the ack is lost or late, while the control PF responder already ran res_ops->cfg_msix_map() successfully.
On the control PF that call reaches the point of no return:
/* Phase2: All new resource allocation succeeded. */ ret = nbl_res_intr_destroy_msix_map(res_mgt, func_id); ... intr_mgt->func_intr_res[func_id].interrupts = tmp_interrupts;
after which the kcalloc'ed interrupts[] array, the dmam_alloc_coherent MSI-X map table and the bits set in intr_net_bmap/intr_other_bmap are only released by nbl_res_intr_destroy_msix_map(), reachable only through destroy_msix_map.
Combined with the probe error path below clearing drvdata, nbl_dev_stop() never runs afterwards, so destroy_msix_map is never issued. Does this leak the control PF's interrupts[] array, the MSI-X map DMA table and the vector bitmap bits?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+ + ret =nbl_dev_init_interrupt_scheme (dev_mgt); +if (ret) + goto init_interrupt_scheme_err;
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 495
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+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); +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_clear_interrupt_scheme (dev_mgt); + ret =nbl_dev_destroy_msix_map (dev_mgt);
[Severity: Low]
Does this cancel_work_sync() achieve anything, given what the next call does?
nbl_dev_disable_mailbox_irq() has just cleared NBL_CHAN_INTERRUPT_READY, so on a non-control PF nbl_dev_destroy_msix_map() -> nbl_disp_chan_destroy_msix_map_req() -> send_msg(..., ack=1) takes the polling branch of nbl_chan_send_msg(), which re-arms the same work item on each poll iteration:
task = READ_ONCE(chan_info->clean_task);
if (common->wq && task && !READ_ONCE(chan_info->shutdown))
queue_work(common->wq, task);
clean_task is &common_dev->clean_mbx_task, registered by nbl_dev_register_chan_task(), so clean_mbx_task is pending or running again by the time nbl_dev_stop() returns.
It is harmless today because nbl_dev_remove_chan_queue() -> nbl_chan_teardown_queue() later drains inflight senders, cancel_work_sync()s clean_task and NULLs it before nbl_common_destroy_wq(). Would moving the cancel after destroy_msix_map(), or dropping it, be clearer?
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c +1
-2@@ -9,8 +9,7 @@ void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt) {struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; -if (hw_ops->deinit_module) - hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); }int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt)
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt) · line 23
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c +1
-3@@ -20,7 +19,5 @@ int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt)struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv; -if (hw_ops->init_module) -return hw_ops->init_module (p, eth_speed, eth_num); -return -EOPNOTSUPP ; +return hw_ops->init_module (p, eth_speed, eth_num); }
[Severity: Low]
Is this hunk related to dev start/stop? Nothing in the changelog mentions removing the NULL guards or the -EOPNOTSUPP fallback.
The removal looks safe today, since the single hw_ops instance statically initialises both callbacks and nbl_hw_setup_ops() rejects a table with NULL init_module/deinit_module, but none of that is visible from the changelog. Could this go into its own patch, or at least be mentioned?
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1
-0@@ -131,7 +141,14 @@ static int nbl_probe(struct pci_dev *pdev, goto adapter_init_err; }pci_set_drvdata (pdev, adapter); + err =nbl_core_start (adapter);
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 154
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0+if (err) + goto core_start_err; +return 0 ; +core_start_err: +pci_set_drvdata (pdev,NULL ); +nbl_core_remove (adapter); adapter_init_err:pci_clear_master (pdev); configure_dma_err:
This is the path referenced above: clearing drvdata here means nbl_remove() sees a NULL adapter, so nbl_core_stop() and therefore nbl_dev_destroy_msix_map() can never run for a probe that failed inside nbl_dev_start().