nbl driver for Nebulamatrix NICs
Subsystems (4)
illusion.wang
maintainerv21 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 v20->v21
Link to v20:https://lore.kernel.org/netdev/[email protected]/ I have dropped the old Patch 2 titled "add our driver architecture"
Add new Patch 2 "add core driver architecture and HW layer initialization".
Split original patch8 into three separate patches as suggested
changes v19->v20
Link to v19:https://lore.kernel.org/netdev/[email protected]/ Starting from V20, I have dropped the old Patch 3 titled "P4
configuration invoked during chip initialization". This functionality
will be reimplemented in next phase using the request_firmware() API
with an external firmware blob.
changes v18->v19
Link to v18:https://lore.kernel.org/netdev/[email protected]/ changes v17->v18
Link to v17:https://lore.kernel.org/netdev/[email protected]/ changes v16->v17
Link to v16:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v15->v16
Link to v15:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v14->v15
Link to v14:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v13->v14
Link to v13:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v12->v13
Link to v12:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v11->v12
Link to v11:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v10->v11
Link to v10:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Mohsin
2.AI review issues
changes v9->v10
Link to v9:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Jakub
2.AI review issue
changes v8->v9
Link to v8:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Jakub
2.AI review issue
Changes v7→v8
Link to v7:https://lore.kernel.org/netdev/[email protected]/ 1.Issues found by Paolo
Changes v6->v7
Link to v6:https://lore.kernel.org/netdev/[email protected]/ 1.Issue found by Jakub
2.AI review issue
Changes v5->v6
Link to V5:https://lore.kernel.org/netdev/[email protected]/ 1.put all standard linux includes files the .c file which needs it & others --Andrew
2.AI review issue
Changes v4->v5
Link to V4:https://lore.kernel.org/netdev/[email protected]/ 1.change nbl_core to nbl & change ** pointers to *pointers & others
--Andrew
2.AI review issue
Changes v3->v4
Link to v3: https://lore.kernel.org/netdev/[email protected]
1.cut down to part of a mini driver(mailbox and chip init)
--Jakub Kicinski Simon Horman(some sort of staged approached)
2.modify issues found by ai.
3. Reverse Christmas tree/nbl_err/devm_kfree/remove some macros/
void type to real type/others
--Andrew Lunn
4.change deprecated pci_enable_msix_range to pci_alloc_irq_vectors
5.delete service layer
6.the style of kconfig---Randy Dunlap
7.add to Documentation/networking/device_drivers/ethernet/index.rst
--Simon Horman
Changes v2 →v3
Link to v2: https://lore.kernel.org/netdev/[email protected]/
1.cut down to a mini driver:
delete vf support
use promisc mode to cut down flow management
drop patch15 in v2
delete adminq msg
delete abnormal handling
delete some unimportant interfaces
2.modify issues found by ai review
Changes v1->v2
Link to v1: https://lore.kernel.org/netdev/[email protected]/
1.Format Issues and Compilation Issues
- Paolo Abeni
2.add sysfs patch and drop coexisting patch
- Andrew Lunn
3.delete some unimportant ndo operations
4.add machine generated headers patch
5.Modify the issues found in patch1-2 and apply the same fixes to other
patches
6.modify issues found by nipa
illusion wang (12):
net/nebula-matrix: add minimum nbl build framework net/nebula-matrix: add core driver architecture and HW layer
initialization
net/nebula-matrix: add channel wire opcode enum definitions net/nebula-matrix: add channel layer net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add vsi resource implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: add cross-version channel message
framework
net/nebula-matrix: dispatch: add resource ops lock protection net/nebula-matrix: add common/ctrl dev init/remove operation net/nebula-matrix: add common dev start/stop operation
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 + MAINTAINERS | 10 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 34 + drivers/net/ethernet/nebula-matrix/Makefile | 6 + .../net/ethernet/nebula-matrix/nbl/Makefile | 15 + .../nbl/nbl_channel/nbl_channel.c | 1098 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 168 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 183 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 33 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 56 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 464 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 540 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 42 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 982 +++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 368 ++++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 295 +++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 73 ++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 288 +++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 148 +++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 108 ++ .../nebula-matrix/nbl/nbl_hw/nbl_vsi.c | 26 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.h | 12 + .../nbl/nbl_include/nbl_def_channel.h | 371 ++++++ .../nbl/nbl_include/nbl_def_common.h | 68 + .../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 | 66 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 253 ++++ 36 files changed, 5975 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_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_hw/nbl_vsi.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_vsi.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 v21 1/12 net/nebula-matrix: add minimum nbl build framework
From: illusion wang <[email protected]>
This patch adds the minimum build infrastructure:
1. Add Kconfig, Makefile and MAINTAINERS entries;
2. Add corresponding driver documentation;
3. Add PCI driver skeleton with empty stubs for nbl driver.
--- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/nbl.rst | 28 +++++ MAINTAINERS | 10 ++ drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 34 ++++++ drivers/net/ethernet/nebula-matrix/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/Makefile | 6 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 14 +++ .../nbl/nbl_include/nbl_include.h | 14 +++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 100 ++++++++++++++++++ 11 files changed, 215 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -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/ + +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
@@ -18594,6 +18594,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 +34 -0
@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Nebula-matrix network device configuration +# + +config NET_VENDOR_NEBULA_MATRIX + bool "Nebula-matrix devices" + default y + help + If you have a network (Ethernet) card belonging to this class, say Y. + Note that the answer to this question doesn't directly affect the + kernel: saying N will just cause the configurator to skip all + the questions about Nebula-matrix cards. If you say Y, you will be asked + for your specific card in the following questions. + +if NET_VENDOR_NEBULA_MATRIX + +config NBL + tristate "Nebula-matrix Ethernet Controller m18110/m18000 support" + depends on PCI && (64BIT || COMPILE_TEST) && !CPU_BIG_ENDIAN + help + This driver supports Nebula-matrix Ethernet Controller m18110/m18000 + Family of devices. For more information about this product, go to + the product description with smart NIC: + + <http://www.nebula-matrix.com> + + More specific information on configuring the driver is in + <file:Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst>. + + To compile this driver as a module, choose M here. The module + will be called nbl. + +endif # NET_VENDOR_NEBULA_MATRIX
drivers/net/ethernet/nebula-matrix/Makefile new file +6 -0
@@ -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 +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_CORE_H_ +#define _NBL_CORE_H_ + +enum { +NBL_CAP_HAS_CTRL_BIT , +NBL_CAP_HAS_NET_BIT , +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h new file +14 -0
@@ -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
Re: [PATCH v21 net-next 01/12] net/nebula-matrix: add minimum nbl build framework
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 24
Quoted 6 lines · illusion.wang
From: illusion wang <[email protected]>
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +5
-0+Support +======= + +For more information about m18110-NIC/m18000-NIC, please visit the following URL: +https://www.nebula-matrix.com/
Do you have a link for the site in english?
Thanks
Illusion Wang
maintainer回复:[PATCH v21 net-next 01/12] net/nebula-matrix: add minimum nbl build framework
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 24
Quoted 6 lines
From: illusion wang <[email protected]>
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +5
-0+Support +======= + +For more information about m18110-NIC/m18000-NIC, please visit the following URL: +https://www.nebula-matrix.com/Do you have a link for the site in english?
Thanks
Sorry, I will fix this in the next revision of the patch series. Our official English product page is available at:
https://www.nebula-matrix.com/snic_s1000_en
The S1000 series products are based on the m18000 chip family, and you can find full NIC product introductions on this page.
Re: 回复:[PATCH v21 net-next 01/12] net/nebula-matrix: add minimum nbl build framework
Quoted 9 lines · Illusion Wang
Quoted 8 lines
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst line 24
Quoted 6 lines
From: illusion wang <[email protected]>
Documentation/networking/device_drivers/ethernet/nebula-matrix/nbl.rst new file +5
-0+Support +======= + +For more information about m18110-NIC/m18000-NIC, please visit the following URL: +https://www.nebula-matrix.com/Do you have a link for the site in english?
Quoted 7 lines
Quoted 1 line
Thanks
Sorry, I will fix this in the next revision of the patch series. Our official English product page is available at:
https://www.nebula-matrix.com/snic_s1000_en
The S1000 series products are based on the m18000 chip family, and you can find full NIC product introductions on this page.
Thanks, that is what I was looking for. Please use the english like above.
illusion.wang
maintainerPATCH v21 2/12 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 | 19 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 141 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 28 ++++ .../nbl/nbl_include/nbl_def_common.h | 33 ++++ .../nbl/nbl_include/nbl_def_hw.h | 21 +++ .../nbl/nbl_include/nbl_include.h | 9 ++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 105 ++++++++++++- 9 files changed, 371 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 +19 -0
@@ -6,9 +6,28 @@#ifndef _NBL_CORE_H_#define _NBL_CORE_H_ +#include <linux/pci.h> +#include "nbl_include/nbl_include.h" +#include "nbl_include/nbl_def_common.h" + +struct nbl_hw_mgt ; +enum {NBL_CAP_HAS_CTRL_BIT ,NBL_CAP_HAS_NET_BIT , }; +struct nbl_core { +struct nbl_hw_mgt *hw_mgt; +}; + +struct nbl_adapter { +struct pci_dev *pdev; +struct nbl_core core; +struct nbl_common_info common; +}; + +struct nbl_adapter *nbl_core_init (struct pci_dev *pdev, +struct nbl_init_param *param); +void nbl_core_remove (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +141 -0
141 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 +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_HW_REG_H_ +#define _NBL_HW_REG_H_ + +#include <linux/types.h> + +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +#define NBL_MEMORY_BAR 0 +#define NBL_MAILBOX_BAR 2 +#define NBL_RDMA_NOTIFY_LEN 8192 +#define NBL_REG_NET_ONLY_LEN 8192 +#define NBL_HW_REG_SPACE_SIZE (32 * 1024 * 1024) + +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 +33 -0
@@ -0,0 +1,33 @@ +/* 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; +u16 mgt_pf; + +u8 has_ctrl; +u8 has_net; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_HW_H_ +#define _NBL_DEF_HW_H_ + +#include <linux/types.h> + +struct nbl_hw_mgt ; +struct nbl_adapter ; + +struct nbl_hw_ops_tbl { +struct nbl_hw_mgt *priv; +}; + +int nbl_hw_init_leonis (struct nbl_adapter *adapter); +void nbl_hw_remove_leonis (struct nbl_adapter *adapter); + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +9 -0
@@ -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 +104 -1
120 lines not on this page · raw message
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 3/12 net/nebula-matrix: add channel wire opcode enum definitions
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add enum nbl_chan_msg_type to nbl_def_channel.h, which defines all PF/VF/firmware channel wire opcodes used for inter-component mailbox communication.
Each enumerator ordinal acts as the wire-format message ID. These opcodes are stable across firmware and driver versions; reordering or inserting new entries before NBL_CHAN_MSG_MAILBOX_MAX will break cross-version interoperability.
This commit only introduces the opcode ID enumeration. Message data structures and full channel layer logic are added in subsequent separate patches. Explicit fixed numeric values for each opcode will be assigned in a follow-up patch to avoid accidental opcode renumbering.
--- .../nbl/nbl_include/nbl_def_channel.h | 232 ++++++++++++++++++ 1 file changed, 232 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 +232 -0
@@ -0,0 +1,232 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_CHANNEL_H_ +#define _NBL_DEF_CHANNEL_H_ + +enum nbl_chan_msg_type { +NBL_CHAN_MSG_ACK , +NBL_CHAN_MSG_ADD_MACVLAN , +NBL_CHAN_MSG_DEL_MACVLAN , +NBL_CHAN_MSG_ADD_MULTI_RULE , +NBL_CHAN_MSG_DEL_MULTI_RULE , +NBL_CHAN_MSG_SETUP_MULTI_GROUP , +NBL_CHAN_MSG_REMOVE_MULTI_GROUP , +NBL_CHAN_MSG_REGISTER_NET , +NBL_CHAN_MSG_UNREGISTER_NET , +NBL_CHAN_MSG_ALLOC_TXRX_QUEUES , +NBL_CHAN_MSG_FREE_TXRX_QUEUES , +NBL_CHAN_MSG_SETUP_QUEUE , +NBL_CHAN_MSG_REMOVE_ALL_QUEUES , +NBL_CHAN_MSG_CFG_DSCH , +NBL_CHAN_MSG_SETUP_CQS , +NBL_CHAN_MSG_REMOVE_CQS , +NBL_CHAN_MSG_CFG_QDISC_MQPRIO , +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , +NBL_CHAN_MSG_DESTROY_MSIX_MAP , +NBL_CHAN_MSG_MAILBOX_SET_IRQ , +NBL_CHAN_MSG_GET_GLOBAL_VECTOR , +NBL_CHAN_MSG_GET_VSI_ID , +NBL_CHAN_MSG_SET_PROMISC_MODE , +NBL_CHAN_MSG_GET_FIRMWARE_VERSION , +NBL_CHAN_MSG_GET_QUEUE_ERR_STATS , +NBL_CHAN_MSG_GET_COALESCE , +NBL_CHAN_MSG_SET_COALESCE , +NBL_CHAN_MSG_SET_SPOOF_CHECK_ADDR , +NBL_CHAN_MSG_SET_VF_SPOOF_CHECK , +NBL_CHAN_MSG_GET_RXFH_INDIR_SIZE , +NBL_CHAN_MSG_GET_RXFH_INDIR , +NBL_CHAN_MSG_GET_RXFH_RSS_KEY , +NBL_CHAN_MSG_GET_RXFH_RSS_ALG_SEL , +NBL_CHAN_MSG_GET_HW_CAPS , +NBL_CHAN_MSG_GET_HW_STATE , +NBL_CHAN_MSG_REGISTER_RDMA , +NBL_CHAN_MSG_UNREGISTER_RDMA , +NBL_CHAN_MSG_GET_REAL_HW_ADDR , +NBL_CHAN_MSG_GET_REAL_BDF , +NBL_CHAN_MSG_GRC_PROCESS , +NBL_CHAN_MSG_SET_SFP_STATE , +NBL_CHAN_MSG_SET_ETH_LOOPBACK , +NBL_CHAN_MSG_CHECK_ACTIVE_VF , +NBL_CHAN_MSG_GET_PRODUCT_FLEX_CAP , +NBL_CHAN_MSG_ALLOC_KTLS_TX_INDEX , +NBL_CHAN_MSG_FREE_KTLS_TX_INDEX , +NBL_CHAN_MSG_CFG_KTLS_TX_KEYMAT , +NBL_CHAN_MSG_ALLOC_KTLS_RX_INDEX , +NBL_CHAN_MSG_FREE_KTLS_RX_INDEX , +NBL_CHAN_MSG_CFG_KTLS_RX_KEYMAT , +NBL_CHAN_MSG_CFG_KTLS_RX_RECORD , +NBL_CHAN_MSG_ADD_KTLS_RX_FLOW , +NBL_CHAN_MSG_DEL_KTLS_RX_FLOW , +NBL_CHAN_MSG_ALLOC_IPSEC_TX_INDEX , +NBL_CHAN_MSG_FREE_IPSEC_TX_INDEX , +NBL_CHAN_MSG_ALLOC_IPSEC_RX_INDEX , +NBL_CHAN_MSG_FREE_IPSEC_RX_INDEX , +NBL_CHAN_MSG_CFG_IPSEC_TX_SAD , +NBL_CHAN_MSG_CFG_IPSEC_RX_SAD , +NBL_CHAN_MSG_ADD_IPSEC_TX_FLOW , +NBL_CHAN_MSG_DEL_IPSEC_TX_FLOW , +NBL_CHAN_MSG_ADD_IPSEC_RX_FLOW , +NBL_CHAN_MSG_DEL_IPSEC_RX_FLOW , +NBL_CHAN_MSG_NOTIFY_IPSEC_HARD_EXPIRE , +NBL_CHAN_MSG_GET_MBX_IRQ_NUM , +NBL_CHAN_MSG_CLEAR_FLOW , +NBL_CHAN_MSG_CLEAR_QUEUE , +NBL_CHAN_MSG_GET_ETH_ID , +NBL_CHAN_MSG_SET_OFFLOAD_STATUS , +NBL_CHAN_MSG_INIT_OFLD , +NBL_CHAN_MSG_INIT_CMDQ , +NBL_CHAN_MSG_DESTROY_CMDQ , +NBL_CHAN_MSG_RESET_CMDQ , +NBL_CHAN_MSG_INIT_FLOW , +NBL_CHAN_MSG_DEINIT_FLOW , +NBL_CHAN_MSG_OFFLOAD_FLOW_RULE , +NBL_CHAN_MSG_GET_ACL_SWITCH , +NBL_CHAN_MSG_GET_VSI_GLOBAL_QUEUE_ID , +NBL_CHAN_MSG_INIT_REP , +NBL_CHAN_MSG_GET_LINE_RATE_INFO , +NBL_CHAN_MSG_REGISTER_NET_REP , +NBL_CHAN_MSG_UNREGISTER_NET_REP , +NBL_CHAN_MSG_REGISTER_ETH_REP , +NBL_CHAN_MSG_UNREGISTER_ETH_REP , +NBL_CHAN_MSG_REGISTER_UPCALL_PORT , +NBL_CHAN_MSG_UNREGISTER_UPCALL_PORT , +NBL_CHAN_MSG_GET_PORT_STATE , +NBL_CHAN_MSG_SET_PORT_ADVERTISING , +NBL_CHAN_MSG_GET_MODULE_INFO , +NBL_CHAN_MSG_GET_MODULE_EEPROM , +NBL_CHAN_MSG_GET_LINK_STATE , +NBL_CHAN_MSG_NOTIFY_LINK_STATE , +NBL_CHAN_MSG_GET_QUEUE_CXT , +NBL_CHAN_MSG_CFG_LOG , +NBL_CHAN_MSG_INIT_VDPAQ , +NBL_CHAN_MSG_DESTROY_VDPAQ , +NBL_CHAN_MSG_GET_UPCALL_PORT , +NBL_CHAN_MSG_NOTIFY_ETH_REP_LINK_STATE , +NBL_CHAN_MSG_SET_ETH_MAC_ADDR , +NBL_CHAN_MSG_GET_FUNCTION_ID , +NBL_CHAN_MSG_GET_CHIP_TEMPERATURE , +NBL_CHAN_MSG_DISABLE_HW_FLOW , +NBL_CHAN_MSG_ENABLE_HW_FLOW , +NBL_CHAN_MSG_SET_UPCALL_RULE , +NBL_CHAN_MSG_UNSET_UPCALL_RULE , +NBL_CHAN_MSG_GET_REG_DUMP , +NBL_CHAN_MSG_GET_REG_DUMP_LEN , +NBL_CHAN_MSG_CFG_LAG_HASH_ALGORITHM , +NBL_CHAN_MSG_CFG_LAG_MEMBER_FWD , +NBL_CHAN_MSG_CFG_LAG_MEMBER_LIST , +NBL_CHAN_MSG_CFG_LAG_MEMBER_UP_ATTR , +NBL_CHAN_MSG_ADD_LAG_FLOW , +NBL_CHAN_MSG_DEL_LAG_FLOW , +NBL_CHAN_MSG_SWITCHDEV_INIT_CMDQ , +NBL_CHAN_MSG_SWITCHDEV_DEINIT_CMDQ , +NBL_CHAN_MSG_SET_TC_FLOW_INFO , +NBL_CHAN_MSG_UNSET_TC_FLOW_INFO , +NBL_CHAN_MSG_INIT_ACL , +NBL_CHAN_MSG_UNINIT_ACL , +NBL_CHAN_MSG_CFG_LAG_MCC , +NBL_CHAN_MSG_REGISTER_VSI2Q , +NBL_CHAN_MSG_SETUP_Q2VSI , +NBL_CHAN_MSG_REMOVE_Q2VSI , +NBL_CHAN_MSG_SETUP_RSS , +NBL_CHAN_MSG_REMOVE_RSS , +NBL_CHAN_MSG_GET_REP_QUEUE_INFO , +NBL_CHAN_MSG_CTRL_PORT_LED , +NBL_CHAN_MSG_NWAY_RESET , +NBL_CHAN_MSG_SET_INTL_SUPPRESS_LEVEL , +NBL_CHAN_MSG_GET_ETH_STATS , +NBL_CHAN_MSG_GET_MODULE_TEMPERATURE , +NBL_CHAN_MSG_GET_BOARD_INFO , +NBL_CHAN_MSG_GET_P4_USED , +NBL_CHAN_MSG_GET_VF_BASE_VSI_ID , +NBL_CHAN_MSG_ADD_LLDP_FLOW , +NBL_CHAN_MSG_DEL_LLDP_FLOW , +NBL_CHAN_MSG_CFG_ETH_BOND_INFO , +NBL_CHAN_MSG_CFG_DUPPKT_MCC , +NBL_CHAN_MSG_ADD_ND_UPCALL_FLOW , +NBL_CHAN_MSG_DEL_ND_UPCALL_FLOW , +NBL_CHAN_MSG_GET_BOARD_ID , +NBL_CHAN_MSG_SET_SHAPING_DPORT_VLD , +NBL_CHAN_MSG_SET_DPORT_FC_TH_VLD , +NBL_CHAN_MSG_REGISTER_RDMA_BOND , +NBL_CHAN_MSG_UNREGISTER_RDMA_BOND , +NBL_CHAN_MSG_RESTORE_NETDEV_QUEUE , +NBL_CHAN_MSG_RESTART_NETDEV_QUEUE , +NBL_CHAN_MSG_RESTORE_HW_QUEUE , +NBL_CHAN_MSG_KEEP_ALIVE , +NBL_CHAN_MSG_GET_BASE_MAC_ADDR , +NBL_CHAN_MSG_CFG_BOND_SHAPING , +NBL_CHAN_MSG_CFG_BGID_BACK_PRESSURE , +NBL_CHAN_MSG_ALLOC_KT_BLOCK , +NBL_CHAN_MSG_FREE_KT_BLOCK , +NBL_CHAN_MSG_GET_USER_QUEUE_INFO , +NBL_CHAN_MSG_GET_ETH_BOND_INFO , +NBL_CHAN_MSG_CLEAR_ACCEL_FLOW , +NBL_CHAN_MSG_SET_BRIDGE_MODE , +NBL_CHAN_MSG_GET_VF_FUNCTION_ID , +NBL_CHAN_MSG_NOTIFY_LINK_FORCED , +NBL_CHAN_MSG_SET_PMD_DEBUG , +NBL_CHAN_MSG_REGISTER_FUNC_MAC , +NBL_CHAN_MSG_SET_TX_RATE , +NBL_CHAN_MSG_REGISTER_FUNC_LINK_FORCED , +NBL_CHAN_MSG_GET_LINK_FORCED , +NBL_CHAN_MSG_REGISTER_FUNC_VLAN , +NBL_CHAN_MSG_GET_FD_FLOW , +NBL_CHAN_MSG_GET_FD_FLOW_CNT , +NBL_CHAN_MSG_GET_FD_FLOW_ALL , +NBL_CHAN_MSG_GET_FD_FLOW_MAX , +NBL_CHAN_MSG_REPLACE_FD_FLOW , +NBL_CHAN_MSG_REMOVE_FD_FLOW , +NBL_CHAN_MSG_CFG_FD_FLOW_STATE , +NBL_CHAN_MSG_REGISTER_FUNC_RATE , +NBL_CHAN_MSG_NOTIFY_VLAN , +NBL_CHAN_MSG_GET_XDP_QUEUE_INFO , +NBL_CHAN_MSG_STOP_ABNORMAL_SW_QUEUE , +NBL_CHAN_MSG_STOP_ABNORMAL_HW_QUEUE , +NBL_CHAN_MSG_NOTIFY_RESET_EVENT , +NBL_CHAN_MSG_ACK_RESET_EVENT , +NBL_CHAN_MSG_GET_VF_VSI_ID , +NBL_CHAN_MSG_CONFIGURE_QOS , +NBL_CHAN_MSG_GET_PFC_BUFFER_SIZE , +NBL_CHAN_MSG_SET_PFC_BUFFER_SIZE , +NBL_CHAN_MSG_GET_VF_STATS , +NBL_CHAN_MSG_REGISTER_FUNC_TRUST , +NBL_CHAN_MSG_NOTIFY_TRUST , +NBL_CHAN_MSG_CHECK_VF_IS_ACTIVE , +NBL_CHAN_MSG_GET_ETH_ABNORMAL_STATS , +NBL_CHAN_MSG_GET_ETH_CTRL_STATS , +NBL_CHAN_MSG_GET_PAUSE_STATS , +NBL_CHAN_MSG_GET_ETH_MAC_STATS , +NBL_CHAN_MSG_GET_FEC_STATS , +NBL_CHAN_MSG_CFG_MULTI_MCAST_RULE , +NBL_CHAN_MSG_GET_LINK_DOWN_COUNT , +NBL_CHAN_MSG_GET_LINK_STATUS_OPCODE , +NBL_CHAN_MSG_GET_RMON_STATS , +NBL_CHAN_MSG_REGISTER_PF_NAME , +NBL_CHAN_MSG_GET_PF_NAME , +NBL_CHAN_MSG_CONFIGURE_RDMA_BW , +NBL_CHAN_MSG_SET_RATE_LIMIT , +NBL_CHAN_MSG_SET_TC_WGT , +NBL_CHAN_MSG_REMOVE_QUEUE , +NBL_CHAN_MSG_GET_MIRROR_TABLE_ID , +NBL_CHAN_MSG_CONFIGURE_MIRROR , +NBL_CHAN_MSG_CONFIGURE_MIRROR_TABLE , +NBL_CHAN_MSG_CLEAR_MIRROR_CFG , +NBL_CHAN_MSG_MIRROR_OUTPUTPORT_NOTIFY , +NBL_CHAN_MSG_CHECK_FLOWTABLE_SPEC , +NBL_CHAN_MSG_CHECK_VF_IS_VDPA , +NBL_CHAN_MSG_GET_VDPA_VF_STATS , +NBL_CHAN_MSG_SET_RX_RATE , +NBL_CHAN_MSG_GET_UVN_PKT_DROP_STATS , +NBL_CHAN_MSG_GET_USTORE_PKT_DROP_STATS , +NBL_CHAN_MSG_GET_USTORE_TOTAL_PKT_DROP_STATS , +NBL_CHAN_MSG_SET_WOL , +NBL_CHAN_MSG_INIT_VF_MSIX_MAP , +NBL_CHAN_MSG_GET_ST_NAME , +/* mailbox msg end */ +NBL_CHAN_MSG_MAILBOX_MAX , +}; + +#endif
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 4/12 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, including asynchronous operations with acknowledgment (ACK) support. Received ACKs are processed via nbl_chan_recv_ack_msg.
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 removal is not implemented in this version).
2. Channel Types and Queue Management
Mailbox Channel: For direct communication between PF0 and Other PF.
Queue Initialization: Functions (nbl_chan_init_queue, nbl_chan_init_tx_queue) allocate resources:
- TX descriptors: dmam_alloc_coherent()
- RX descriptors: dmam_alloc_coherent()
- TX/RX buffer metadata arrays (txq->buf, rxq->buf): devm_kcalloc()
Queue Teardown: nbl_chan_teardown_queue() stops queues, cancels pending work items (clean_task), and destroys mutexes. 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 (when all devm_ resources are released). This assumes queues are NOT dynamically torn down and recreated per-PF during normal operation.
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.
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 updates (update_mailbox_queue_tail_ptr).
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1094 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 168 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 172 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 33 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 11 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 173 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 56 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 45 + .../nbl/nbl_include/nbl_def_channel.h | 113 ++ .../nbl/nbl_include/nbl_def_common.h | 17 + .../nbl/nbl_include/nbl_def_hw.h | 15 + .../nbl/nbl_include/nbl_include.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 1913 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 +1094 -0
1,094 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +168 -0
168 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +172 -0
172 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +33 -0
@@ -0,0 +1,33 @@ +/* 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_common_wq_mgt { +struct workqueue_struct *ctrl_dev_wq; +}; + +struct nbl_hash_tbl_mgt { +struct nbl_hash_tbl_key tbl_key; +struct hlist_head *hash; +u16 node_num; +}; + +struct nbl_hash_entry_node { +struct hlist_node node; +void *key; +void *data; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +11 -0
@@ -11,23 +11,34 @@#include "nbl_include/nbl_def_common.h" struct nbl_hw_mgt ; +struct nbl_hw_ops_tbl ; +struct nbl_channel_ops_tbl ; +struct nbl_channel_mgt ;enum {NBL_CAP_HAS_CTRL_BIT ,NBL_CAP_HAS_NET_BIT , }; +struct nbl_interface { +struct nbl_hw_ops_tbl *hw_ops_tbl; +struct nbl_channel_ops_tbl *channel_ops_tbl; +}; +struct nbl_core {struct nbl_hw_mgt *hw_mgt; +struct nbl_channel_mgt *chan_mgt; };struct nbl_adapter {struct pci_dev *pdev;struct nbl_core core; +struct nbl_interface intf;struct nbl_common_info common; };struct nbl_adapter *nbl_core_init (struct pci_dev *pdev,struct nbl_init_param *param);void nbl_core_remove (struct nbl_adapter *adapter); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +173 -0
197 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +56 -0
60 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +45 -0
63 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +113 -0
123 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +17 -0
@@ -11,6 +11,8 @@#include <linux/device.h> #include "nbl_include.h" +struct nbl_hash_tbl_mgt ; +struct nbl_common_info {struct pci_dev *pdev;struct device *dev;
@@ -30,4 +32,19 @@ struct nbl_common_info { u8 has_net; }; +struct nbl_hash_tbl_key { +struct device *dev; +u16 key_size; +u16 data_size;/* no include key or node member */ +u16 bucket_size; +u16 resv; +}; + +struct nbl_hash_tbl_mgt * +nbl_common_init_hash_table (struct nbl_hash_tbl_key *key); +void nbl_common_remove_hash_table (struct nbl_hash_tbl_mgt *tbl_mgt); +int nbl_common_alloc_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key, +void *data,void **out_data); +void *nbl_common_get_hash_node (struct nbl_hash_tbl_mgt *tbl_mgt,void *key); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +15 -0
@@ -10,8 +10,23 @@struct nbl_hw_mgt ;struct nbl_adapter ; +struct nbl_hw_ops { +void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt, +u16 tail_ptr,u8 txrx); +void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*config_mailbox_txq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt); +void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt); +u32 (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt); + +void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +u8 bus,u8 devid,u8 function); +};struct nbl_hw_ops_tbl { +struct nbl_hw_ops *ops;struct nbl_hw_mgt *priv; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +6 -0
@@ -10,6 +10,12 @@/* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl" +#define NBL_MAX_PF 8 +#define NBL_NEXT_ID (id, max) \ + ({ \ + typeof(id) _id = (id); \ + ((_id) == (max) ? 0 : (_id) + 1); \ + })struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +7 -0
@@ -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
Paolo Abeni
maintainerRe: [PATCH v21 net-next 04/12] net/nebula-matrix: add channel layer
Quoted 896 lines · illusion.wang
From: illusion wang <[email protected]>
A channel management layer provides a structured approach to handle communication between different components and drivers. Here's a summary of its key functionalities:
1. Message Handling Framework
Message Registration: Functions (nbl_chan_register_msg) allow dynamic registration of message handlers for specific message types, enabling extensible communication protocols.Message Sending/Acknowledgment: Core functions (
nbl_chan_send_msg,nbl_chan_send_ack) handle message transmission, including asynchronous operations with acknowledgment (ACK) support. Received ACKs are processed vianbl_chan_recv_ack_msg.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 vianbl_chan_remove_msg_handlerduring driver teardown (per-message-type removal is not implemented in this version).2. Channel Types and Queue Management
Mailbox Channel: For direct communication between PF0 and Other PF.Queue Initialization: Functions (
nbl_chan_init_queue,nbl_chan_init_tx_queue) allocate resources:
- TX descriptors:dmam_alloc_coherent()
- RX descriptors:dmam_alloc_coherent()
- TX/RX buffer metadata arrays (txq->buf,rxq->buf):devm_kcalloc()Queue Teardown:
nbl_chan_teardown_queue()stops queues, cancels pending work items (clean_task), and destroys mutexes. It does NOT free DMA memory, which is released automatically via devm on driver remove.IMPORTANT - Resource Lifecycle Design:
DMA memory allocated withdmam_alloc_coherent()is intentionally NOT freed innbl_chan_teardown_queue(). The queues are allocated once during driver probe and freed only during driver remove (when alldevm_resources are released). This assumes queues are NOT dynamically torn down and recreated per-PF during normal operation.Queue Configuration: Hardware-specific queue parameters (e.g., buffer sizes, entry counts) are set via
nbl_chan_config_queue, with hardware interactions delegated tohw_ops.3. Hardware Abstraction Layer (HW Ops)
Hardware-Specific Operations: Thenbl_hw_opsstructure abstracts hardware interactions: queue configuration (config_mailbox_txq/rxq), tail pointer updates (update_mailbox_queue_tail_ptr).Signed-off-by illusion wang <[email protected]>--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1094 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 168 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 172 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 33 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 11 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 173 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 56 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 45 + .../nbl/nbl_include/nbl_def_channel.h | 113 ++ .../nbl/nbl_include/nbl_def_common.h | 17 + .../nbl/nbl_include/nbl_def_hw.h | 15 + .../nbl/nbl_include/nbl_include.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 1913 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.hdrivers/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.odrivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +803
-0@@ -0,0 +1,1094 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/bitfield.h> +#include <linux/pci.h> +#include <linux/bits.h> +#include <linux/dma-mapping.h> +#include <linux/atomic.h> +#include <linux/wait.h> +#include "nbl_channel.h" + +static int nbl_chan_add_msg_handler (struct nbl_channel_mgt *chan_mgt, +u16 msg_type,nbl_chan_resp func, +void *priv) +{ +struct nbl_chan_msg_node_data handler = {0 }; +int ret; + + handler.func = func; + handler.priv = priv; + ret =nbl_common_alloc_hash_node (chan_mgt->handle_hash_tbl, &msg_type, + &handler,NULL ); + +return ret; +} + +static int nbl_chan_init_msg_handler (struct nbl_channel_mgt *chan_mgt) +{ +struct nbl_common_info *common = chan_mgt->common; +struct nbl_hash_tbl_key tbl_key = {0 }; + + tbl_key.dev = common->dev; + tbl_key.key_size =sizeof (u16); + tbl_key.data_size =sizeof (struct nbl_chan_msg_node_data ); + tbl_key.bucket_size =NBL_CHAN_HANDLER_TBL_BUCKET_SIZE ; + + chan_mgt->handle_hash_tbl =nbl_common_init_hash_table (&tbl_key); +if (!chan_mgt->handle_hash_tbl) +return -ENOMEM ; + +return 0 ; +} + +static void nbl_chan_remove_msg_handler (struct nbl_channel_mgt *chan_mgt) +{ +if (!chan_mgt->handle_hash_tbl) +return ; +nbl_common_remove_hash_table (chan_mgt->handle_hash_tbl); + chan_mgt->handle_hash_tbl =NULL ; +} + +static void nbl_chan_init_queue_param (struct nbl_chan_info *chan_info, +u16 num_txq_entries,u16 num_rxq_entries, +u16 txq_buf_size,u16 rxq_buf_size) +{ +mutex_init (&chan_info->txq_lock); + chan_info->num_txq_entries = num_txq_entries; + chan_info->num_rxq_entries = num_rxq_entries; + chan_info->txq_buf_size = txq_buf_size; + chan_info->rxq_buf_size = rxq_buf_size; +atomic_set (&chan_info->inflight_tx_cnt,0 ); + chan_info->shutdown = false; +} + +static int nbl_chan_init_tx_queue (struct nbl_common_info *common, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *txq = &chan_info->txq; +struct device *dev = common->dev; +size_t size = + chan_info->num_txq_entries *sizeof (struct nbl_chan_tx_desc ); +int i; + + txq->desc.tx_desc = +dmam_alloc_coherent (dev, size, &txq->dma,GFP_KERNEL ); +if (!txq->desc.tx_desc) +return -ENOMEM ; + + chan_info->wait =devm_kcalloc (dev, chan_info->num_txq_entries, +sizeof (*chan_info->wait),GFP_KERNEL ); +if (!chan_info->wait) +return -ENOMEM ; +for (i =0 ; i < chan_info->num_txq_entries; i++) { +init_waitqueue_head (&chan_info->wait[i].wait_queue); + chan_info->wait[i].status =NBL_MBX_STATUS_IDLE ; +spin_lock_init (&chan_info->wait[i].status_lock); + } + + txq->buf =devm_kcalloc (dev, chan_info->num_txq_entries, +sizeof (*txq->buf),GFP_KERNEL ); +if (!txq->buf) +return -ENOMEM ; + +return 0 ; +} + +static int nbl_chan_init_rx_queue (struct nbl_common_info *common, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *rxq = &chan_info->rxq; +struct device *dev = common->dev; +size_t size = + chan_info->num_rxq_entries *sizeof (struct nbl_chan_rx_desc ); + + rxq->desc.rx_desc = +dmam_alloc_coherent (dev, size, &rxq->dma,GFP_KERNEL ); +if (!rxq->desc.rx_desc) { +dev_err (dev, +"Allocate DMA for chan rx descriptor ring failed\n" ); +return -ENOMEM ; + } + + rxq->buf =devm_kcalloc (dev, chan_info->num_rxq_entries, +sizeof (*rxq->buf),GFP_KERNEL ); +if (!rxq->buf) +return -ENOMEM ; + +return 0 ; +} + +static int nbl_chan_init_queue (struct nbl_common_info *common, +struct nbl_chan_info *chan_info) +{ +int err; + + err =nbl_chan_init_tx_queue (common, chan_info); +if (err) +return err; + + err =nbl_chan_init_rx_queue (common, chan_info); + +return err; +} + +static void nbl_chan_config_queue (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info,bool tx) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *p = chan_mgt->hw_ops_tbl->priv; +int size_bwid; +struct nbl_chan_ring *ring; +dma_addr_t dma_addr; + +if (tx) + ring = &chan_info->txq; +else + ring = &chan_info->rxq; + dma_addr = ring->dma; +if (tx) { + size_bwid =ilog2 (chan_info->num_txq_entries); + hw_ops->config_mailbox_txq (p, dma_addr, size_bwid); + }else { + size_bwid =ilog2 (chan_info->num_rxq_entries); + hw_ops->config_mailbox_rxq (p, dma_addr, size_bwid); + } +} + +static int nbl_chan_alloc_all_tx_bufs (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *txq = &chan_info->txq; +struct device *dev = chan_mgt->common->dev; +struct nbl_chan_buf *buf; +u16 i; + +for (i =0 ; i < chan_info->num_txq_entries; i++) { + buf = &txq->buf[i]; + buf->va =dmam_alloc_coherent (dev, chan_info->txq_buf_size, + &buf->pa,GFP_KERNEL ); +if (!buf->va) { +dev_err (dev, +"Allocate buffer for chan tx queue failed\n" ); +return -ENOMEM ; + } + } + + txq->next_to_clean =0 ; + txq->next_to_use =0 ; + txq->tail_ptr =0 ; + +return 0 ; +} + +static void nbl_chan_cfg_qinfo_map_table (struct nbl_channel_mgt *chan_mgt) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = chan_mgt->common; +struct nbl_hw_mgt *p = chan_mgt->hw_ops_tbl->priv; +u8 func_id; +u32 pf_mask; + + pf_mask = hw_ops->get_host_pf_mask (p); +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, common->hw_bus, + common->devid, + common->function + func_id); + } +} + +static inline void nbl_chan_update_tail_ptr (struct nbl_hw_ops *hw_ops, +void *hw_priv,u32 tail_ptr,u8 qid) +{ + hw_ops->update_mailbox_queue_tail_ptr (hw_priv, tail_ptr, qid); +} + +static int nbl_chan_alloc_all_rx_bufs (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *rxq = &chan_info->rxq; +struct device *dev = chan_mgt->common->dev; +struct nbl_chan_rx_desc *desc; +struct nbl_chan_buf *buf; +u16 i; + +for (i =0 ; i < chan_info->num_rxq_entries; i++) { + buf = &rxq->buf[i]; + buf->va =dmam_alloc_coherent (dev, chan_info->rxq_buf_size, + &buf->pa,GFP_KERNEL ); +if (!buf->va) { +dev_err (dev, +"Allocate buffer for chan rx queue failed\n" ); + goto err; + } + } + + desc = rxq->desc.rx_desc; +for (i =0 ; i < chan_info->num_rxq_entries -1 ; i++) { + buf = &rxq->buf[i]; + desc[i].buf_addr =cpu_to_le64 (buf->pa); + desc[i].buf_len =cpu_to_le32 (chan_info->rxq_buf_size); + desc[i].flags =cpu_to_le16 (BIT (NBL_CHAN_RX_DESC_AVAIL )); + } + + rxq->next_to_clean =0 ; + rxq->next_to_use = chan_info->num_rxq_entries -1 ; + rxq->tail_ptr = chan_info->num_rxq_entries -1 ; + +return 0 ; +err: +return -ENOMEM ; +} + +static int nbl_chan_alloc_all_bufs (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +int err; + + err =nbl_chan_alloc_all_tx_bufs (chan_mgt, chan_info); +if (err) +return err; + err =nbl_chan_alloc_all_rx_bufs (chan_mgt, chan_info); + +return err; +} + +static void nbl_chan_stop_queue (struct nbl_channel_mgt *chan_mgt) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; + + hw_ops->stop_mailbox_rxq (chan_mgt->hw_ops_tbl->priv); + hw_ops->stop_mailbox_txq (chan_mgt->hw_ops_tbl->priv); +} + +static int nbl_chan_teardown_queue (struct nbl_channel_mgt *chan_mgt, +u8 chan_type) +{ +struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type]; +struct nbl_chan_waitqueue_head *wait_head; +u16 i; + +/* Step 1: Mark shutdown flag, reject all new send requests */ +WRITE_ONCE (chan_info->shutdown, true); + +/* Stop hardware queues */ +nbl_chan_stop_queue (chan_mgt); + +/* Cancel any pending cleanup work */ +if (chan_info->clean_task) +cancel_work_sync (chan_info->clean_task); +for (i =0 ; i < chan_info->num_txq_entries; i++) { + wait_head = &chan_info->wait[i]; +spin_lock_irq (&wait_head->status_lock); +/* Only wake threads that are actually waiting */ +if (READ_ONCE (wait_head->status) ==NBL_MBX_STATUS_WAITING ) { +/* Mark as timeout so waking threads know to abort */ + wait_head->status =NBL_MBX_STATUS_TIMEOUT ; + wait_head->acked =1 ; + wait_head->ack_err = -EIO ; +/* Ensure status is written */ +smp_wmb (); + } +spin_unlock_irq (&wait_head->status_lock); +if (READ_ONCE (wait_head->status) ==NBL_MBX_STATUS_TIMEOUT ) +wake_up (&wait_head->wait_queue); + } + +/* Step 2: Wait all in-flight send_msg threads exit via counter */ +while (atomic_read (&chan_info->inflight_tx_cnt) !=0 ) { +/* synchronize atomic counter load with other CPUs */ +smp_rmb (); +usleep_range (100 ,1000 ); + } + +/* No concurrent thread holds txq_lock now, safe destroy mutex */ +mutex_destroy (&chan_info->txq_lock); + +return 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 (chan_info->init_done) +return 0 ; +nbl_chan_init_queue_param (chan_info,NBL_CHAN_QUEUE_LEN , +NBL_CHAN_QUEUE_LEN ,NBL_CHAN_BUF_LEN , +NBL_CHAN_BUF_LEN ); + err =nbl_chan_init_queue (common, chan_info); +if (err) + goto chan_setup_fail; + err =nbl_chan_alloc_all_bufs (chan_mgt, chan_info); +if (err) + goto chan_setup_fail; +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 ); + chan_info->init_done = true; +return 0 ; +chan_setup_fail: +mutex_destroy (&chan_info->txq_lock); +return err; +} + +static int nbl_chan_update_txqueue (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info, +struct nbl_chan_tx_param *param) +{ +struct nbl_chan_ring *txq = &chan_info->txq; +struct nbl_chan_tx_desc *tx_desc = +NBL_CHAN_TX_RING_TO_DESC (txq, txq->next_to_use); +struct nbl_chan_buf *tx_buf = +NBL_CHAN_TX_RING_TO_BUF (txq, txq->next_to_use); + +if (param->arg_len >NBL_CHAN_BUF_LEN -sizeof (*tx_desc)) +return -EINVAL ; + + 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); + +if (param->arg_len >NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN ) { +memcpy (tx_buf->va, param->arg, param->arg_len); + tx_desc->buf_addr =cpu_to_le64 (tx_buf->pa); + tx_desc->buf_len =cpu_to_le16 (param->arg_len); + tx_desc->data_len =0 ; +memset (tx_desc->data,0 ,sizeof (tx_desc->data)); + }else { +memset (tx_desc->data,0 ,sizeof (tx_desc->data)); +memset (&tx_desc->buf_addr,0 ,sizeof (tx_desc->buf_addr)); +memcpy (tx_desc->data, param->arg, param->arg_len); + tx_desc->buf_len =0 ; + tx_desc->data_len =cpu_to_le16 (param->arg_len); + } +dma_wmb (); + tx_desc->flags =cpu_to_le16 (BIT (NBL_CHAN_TX_DESC_AVAIL )); + + txq->next_to_use = +NBL_NEXT_ID (txq->next_to_use, chan_info->num_txq_entries -1 ); + txq->tail_ptr++; + +return 0 ; +} + +static int nbl_chan_kick_tx_ring (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_chan_ring *txq = &chan_info->txq; +struct device *dev = chan_mgt->common->dev; +int max_retries =NBL_CHAN_TX_WAIT_TIMES ; +struct nbl_chan_tx_desc *tx_desc; +int retry_count =0 ; + +nbl_chan_update_tail_ptr (hw_ops, chan_mgt->hw_ops_tbl->priv, + txq->tail_ptr,NBL_MB_TX_QID ); + + tx_desc =NBL_CHAN_TX_RING_TO_DESC (txq, txq->next_to_clean); +while (retry_count < max_retries) { +if (le16_to_cpu (READ_ONCE (tx_desc->flags)) & +BIT (NBL_CHAN_TX_DESC_USED )) { +dma_rmb (); +break ; + } + + retry_count++; +if (retry_count == max_retries) { +dev_err (dev,"chan send message type: %d timeout\n" , +le16_to_cpu (READ_ONCE (tx_desc->msg_type))); + txq->next_to_clean = txq->next_to_use; +return -ETIMEDOUT ; + } +usleep_range (NBL_CHAN_TX_WAIT_US ,NBL_CHAN_TX_WAIT_US_MAX ); + } + + txq->next_to_clean = txq->next_to_use; + +return 0 ; +} + +static void nbl_chan_recv_ack_msg (void *priv,u16 srcid,u16 msgid,void *data, +u32 data_len) +{ +struct nbl_channel_mgt *chan_mgt = (struct nbl_channel_mgt *)priv; +struct nbl_chan_waitqueue_head *wait_head =NULL ; +struct device *dev = chan_mgt->common->dev; +struct nbl_chan_info *chan_info = + chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX ]; +u32 ack_datalen, ack_msgtype =0 ; +u32 *payload = data; +u16 ack_msgid =0 ; +u32 copy_len; + +if (data_len >NBL_CHAN_BUF_LEN || + data_len <NBL_CHAN_ACK_HEAD_LEN *sizeof (u32)) { +dev_err (dev,"Invalid ACK data_len: %u\n" , data_len); +return ; + } + ack_datalen = data_len -NBL_CHAN_ACK_HEAD_LEN *sizeof (u32); + ack_msgtype =le16_to_cpu (*(__le16 *)(payload +NBL_CHAN_MSG_TYPE_POS )); + ack_msgid =le16_to_cpu (*(__le16 *)(payload +NBL_CHAN_MSG_ID_POS )); +if (FIELD_GET (NBL_CHAN_MSGID_LOC_MASK , ack_msgid) >= + chan_info->num_txq_entries) { +dev_err (dev,"chan recv msg id: %d err\n" , ack_msgid); +return ; + } + wait_head = + &chan_info->wait[FIELD_GET (NBL_CHAN_MSGID_LOC_MASK , ack_msgid)]; +spin_lock_irq (&wait_head->status_lock); +if (srcid != wait_head->dstid) { +/* Do not modify the status; the slot remains WAITING, +* and the sender will time out normally +*/ +spin_unlock_irq (&wait_head->status_lock); +dev_err (dev,"ACK srcid=%u != dstid=%u, rejecting\n" , srcid, + wait_head->dstid); +return ; + } +if (READ_ONCE (wait_head->status) !=NBL_MBX_STATUS_WAITING ) { +spin_unlock_irq (&wait_head->status_lock); +dev_err (dev, +"Skip ack with invalid status, wait_head msgtype:%u msg_index:%u status:%d ack_data_len:%d, ack msgtype:%u msgid:%u datalen:%d\n" , +READ_ONCE (wait_head->msg_type), +READ_ONCE (wait_head->msg_index), +READ_ONCE (wait_head->status), wait_head->ack_data_len, + ack_msgtype, ack_msgid, ack_datalen); +return ; + } + +if (READ_ONCE (wait_head->msg_type) != ack_msgtype) { +/* +* Mismatched ACK. Restore state to WAITING so the original +* sender will time out and not reuse the slot. +*/ + wait_head->status =NBL_MBX_STATUS_WAITING ; + +dev_err (dev, +"Skip ack msg type donot match, wait_head msgtype:%u msg_index:%u status:%d ack_data_len:%d, ack msgtype:%u msgid:%u datalen:%d\n" , +READ_ONCE (wait_head->msg_type), +READ_ONCE (wait_head->msg_index), +READ_ONCE (wait_head->status), wait_head->ack_data_len, + ack_msgtype, ack_msgid, ack_datalen); +spin_unlock_irq (&wait_head->status_lock); +/* Wake up the sender to let it know the ACK was invalid */ +wake_up (&wait_head->wait_queue); +return ; + } +if (FIELD_GET (NBL_CHAN_MSGID_INDEX_MASK , ack_msgid) != +READ_ONCE (wait_head->msg_index)) { +/* +* Stale ACK. Restore state to WAITING so the original +* sender will time out and not reuse the slot. +*/ + wait_head->status =NBL_MBX_STATUS_WAITING ; + +dev_err (dev, +"Stale ACK: expected index=%u, got msgid %u\n" , +READ_ONCE (wait_head->msg_index), ack_msgid); +spin_unlock_irq (&wait_head->status_lock); +/* Wake up the sender to let it know the ACK was stale */ +wake_up (&wait_head->wait_queue); +return ; + } + + wait_head->ack_err = +le32_to_cpu (*(__le32 *)(payload +NBL_CHAN_ACK_RET_POS )); + + copy_len =min_t (u32, wait_head->ack_data_len, ack_datalen); +if (wait_head->ack_err >=0 && copy_len >0 ) { +if (!wait_head->ack_data) { +dev_err (dev,"ACK payload dropped: ack_data is NULL\n" ); + wait_head->ack_data_len =0 ; + goto ack_done; + } +memcpy ((char *)wait_head->ack_data, + payload +NBL_CHAN_ACK_HEAD_LEN , copy_len); + wait_head->ack_data_len = (u16 )copy_len; + }else { + wait_head->ack_data_len =0 ; + } +ack_done: +/* +* Ensure all writes to ack_data and ack_data_len are completed +* before setting the 'acked' flag. This prevents other threads +* from observing stale or partially updated data. +*/ +smp_wmb (); + wait_head->acked =1 ; +spin_unlock_irq (&wait_head->status_lock); +if (READ_ONCE (wait_head->acked)) +wake_up (&wait_head->wait_queue); +} + +static void nbl_chan_recv_msg (struct nbl_channel_mgt *chan_mgt,void *data) +{ +struct device *dev = chan_mgt->common->dev; +struct nbl_chan_msg_node_data *msg_handler; +u16 msg_type, payload_len, srcid, msgid; +struct nbl_chan_tx_desc *tx_desc; +void *payload; + + tx_desc = data; + msg_type =le16_to_cpu (tx_desc->msg_type); +dev_dbg (dev,"recv msg_type: %d\n" , msg_type); + + srcid =le16_to_cpu (tx_desc->srcid); + msgid =le16_to_cpu (tx_desc->msgid); +/* Only check if the value exceeds the maximum, relying on the hash +* table to filter invalid message IDs. +* The gap values are reserved for future protocol extensions. +*/ +if (msg_type >=NBL_CHAN_MSG_MAILBOX_MAX ) +return ; + +if (tx_desc->data_len) { + payload_len =le16_to_cpu (tx_desc->data_len); +if (payload_len >NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN ) { +dev_err (dev, +"data_len=%u exceeds embedded buffer size=%u\n" , + payload_len, +NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN ); +return ; + } + payload = tx_desc->data; + }else { + payload_len =le16_to_cpu (tx_desc->buf_len); +if (payload_len >NBL_CHAN_BUF_LEN -sizeof (*tx_desc)) { +dev_err (dev, +"buf_len=%u exceeds external buffer size=%zu\n" , + payload_len, +NBL_CHAN_BUF_LEN -sizeof (*tx_desc)); +return ; + } + payload = tx_desc +1 ; + } + + msg_handler = +nbl_common_get_hash_node (chan_mgt->handle_hash_tbl, &msg_type); +if (!msg_handler || !msg_handler->func) { +dev_err (dev, +"No handler for msg_type: %u (srcid=%u, msgid=%u)\n" , + msg_type, srcid, msgid); +return ; + } + msg_handler->func (msg_handler->priv, srcid, msgid, payload, + payload_len); +} + +static void nbl_chan_advance_rx_ring (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info, +struct nbl_chan_ring *rxq) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_chan_rx_desc *rx_desc; +struct nbl_chan_buf *rx_buf; +u16 next_to_use; + + next_to_use = rxq->next_to_use; + rx_desc =NBL_CHAN_RX_RING_TO_DESC (rxq, next_to_use); + rx_buf =NBL_CHAN_RX_RING_TO_BUF (rxq, next_to_use); + + rx_desc->buf_addr =cpu_to_le64 (rx_buf->pa); + rx_desc->buf_len =cpu_to_le32 (chan_info->rxq_buf_size); + +/* +* DMA Write Memory Barrier: +* Ensures all previous DMA-mapped writes (buffer address/length) +* are completed before the descriptor flags are updated. +* This prevents hardware from seeing a partially updated descriptor +* where flags are set but buffer info isn't ready yet. +*/ +dma_wmb (); + + rx_desc->flags =cpu_to_le16 (BIT (NBL_CHAN_RX_DESC_AVAIL )); + +/* +* CPU Write Memory Barrier: +* Ensures the descriptor flags update is visible to other CPUs +* before we update the tail pointer. This is important for: +* 1. Software cleaning threads that might be checking the tail pointer +* 2. Maintaining proper memory ordering in multi-core systems +*/ +wmb (); + rxq->next_to_use++; +if (rxq->next_to_use == chan_info->num_rxq_entries) + rxq->next_to_use =0 ; + rxq->tail_ptr++; + +nbl_chan_update_tail_ptr (hw_ops, chan_mgt->hw_ops_tbl->priv, + rxq->tail_ptr,NBL_MB_RX_QID ); +} + +/* +* Since the channel operates in either polling mode or interrupt mode +* (mutually exclusive, configured via set_queue_state), nbl_chan_clean_queue +* is always called in a serialized manner: +* 1. In polling mode: nbl_chan_clean_queue is called directly within +* nbl_chan_send_msg, in the same thread after txq_lock has been released. +* No other thread can call it concurrently. +* 2. In interrupt mode: nbl_chan_clean_queue is called from a workqueue +* (nbl_dev_clean_mailbox_task). Linux workqueue guarantees that the same +* work item never runs concurrently on multiple CPUs. +* Therefore, at any given time, only one execution context can be inside +* nbl_chan_clean_queue. There is no concurrency, and thus no need for +* locking +*/ +static void nbl_chan_clean_queue (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +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; +bool more_work = false; +u16 next_to_clean; +u32 budget =64 ; + + next_to_clean = rxq->next_to_clean; + rx_desc =NBL_CHAN_RX_RING_TO_DESC (rxq, next_to_clean); + rx_buf =NBL_CHAN_RX_RING_TO_BUF (rxq, next_to_clean); +while (le16_to_cpu (rx_desc->flags) &BIT (NBL_CHAN_RX_DESC_USED )) { +if (!(le16_to_cpu (rx_desc->flags) & +BIT (NBL_CHAN_RX_DESC_WRITE ))) +dev_dbg (dev, +"mailbox rx flag 0x%x has no NBL_CHAN_RX_DESC_WRITE\n" , +le16_to_cpu (rx_desc->flags)); + +dma_rmb (); +nbl_chan_recv_msg (chan_mgt, rx_buf->va); +nbl_chan_advance_rx_ring (chan_mgt, chan_info, rxq); + next_to_clean++; +if (next_to_clean == chan_info->num_rxq_entries) + next_to_clean =0 ; + rx_desc =NBL_CHAN_RX_RING_TO_DESC (rxq, next_to_clean); + rx_buf =NBL_CHAN_RX_RING_TO_BUF (rxq, next_to_clean); +if (--budget ==0 ) { + more_work = true; +break ; + } + } + rxq->next_to_clean = next_to_clean; +/* If descriptors remain, reschedule work to avoid stalled RX ring */ +if (more_work) +schedule_work (chan_info->clean_task); +} + +static void nbl_chan_clean_queue_subtask (struct nbl_channel_mgt *chan_mgt, +u8 chan_type) +{ +struct nbl_chan_info *chan_info = chan_mgt->chan_info[chan_type]; + +if (!test_bit (NBL_CHAN_INTERRUPT_READY , chan_info->state)) +return ; + +nbl_chan_clean_queue (chan_mgt, chan_info); +} + +static int nbl_chan_get_msg_id (struct nbl_chan_info *chan_info, +u16 *msgid) +{ +int valid_loc = chan_info->wait_head_index, i; +struct nbl_chan_waitqueue_head *wait =NULL ; +int status; + +for (i =0 ; i <NBL_CHAN_QUEUE_LEN ; i++) { + wait = &chan_info->wait[valid_loc]; + status =READ_ONCE (wait->status); +if (status ==NBL_MBX_STATUS_IDLE || + status ==NBL_MBX_STATUS_TIMEOUT ) { + wait->msg_index =NBL_NEXT_ID (wait->msg_index, +NBL_CHAN_MSG_INDEX_MAX ); + *msgid = +FIELD_PREP (NBL_CHAN_MSGID_INDEX_MASK , + wait->msg_index) | +FIELD_PREP (NBL_CHAN_MSGID_LOC_MASK , valid_loc); + valid_loc =NBL_NEXT_ID (valid_loc, + chan_info->num_txq_entries -1 ); + chan_info->wait_head_index = valid_loc; +return 0 ; + } + + valid_loc = +NBL_NEXT_ID (valid_loc, chan_info->num_txq_entries -1 ); + } + +/* +* the current NBL_CHAN_QUEUE_LEN configuration meets the design +* requirements and theoretically should not return errors, the +* following scenarios may still cause the waiting queue to +* become full: +* High-concurrency scenarios: +* If the sender (calling nbl_chan_send_msg()) generates messages +* at a rate far exceeding the receiver's ability to process +* acknowledgments (ACKs),the waiting queue may become fully occupied. +* Delayed or failed ACK handling by the receiver: +* The receiver may fail to send ACKs in a timely manner due to +* processing delays, blocking, or faults, causing the sender's +* waiting queue slots to remain occupied for an extended period. +*/ +return -EAGAIN ; +} + +static int nbl_chan_send_msg (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_send_info *chan_send) +{ +struct nbl_common_info *common = chan_mgt->common; +struct nbl_chan_waitqueue_head *wait_head; +struct nbl_chan_tx_param tx_param = {0 }; +u16 msgid =0 ; +int i =NBL_CHAN_TX_WAIT_ACK_TIMES , ret; +struct nbl_chan_info *chan_info = + chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX ]; +struct device *dev = common->dev; + +if (chan_send->resp_len >NBL_CHAN_BUF_LEN ) { +dev_err (dev,"resp_len %zu exceeds max %d\n" , + chan_send->resp_len,NBL_CHAN_BUF_LEN ); +return -EINVAL ; + } + +/* Reject new send if shutdown already triggered */ +if (READ_ONCE (chan_info->shutdown)) +return -ESHUTDOWN ; +mutex_lock (&chan_info->txq_lock); + +if (test_bit (NBL_CHAN_ABNORMAL , chan_info->state)) { +mutex_unlock (&chan_info->txq_lock); +return -EIO ; + } + ret =nbl_chan_get_msg_id (chan_info, &msgid); +if (ret) { +mutex_unlock (&chan_info->txq_lock); +dev_err (dev, +"Channel tx wait head full, send msgtype:%u to dstid:%u failed\n" , + chan_send->msg_type, chan_send->dstid); +return ret; + } + + tx_param.msg_type = chan_send->msg_type; + tx_param.arg = chan_send->arg; + tx_param.arg_len = chan_send->arg_len; + tx_param.dstid = chan_send->dstid; + tx_param.msgid = msgid; + + ret =nbl_chan_update_txqueue (chan_mgt, chan_info, &tx_param); +if (ret) { +mutex_unlock (&chan_info->txq_lock); +dev_err (dev, +"Channel tx queue full, send msgtype:%u to dstid:%u failed\n" , + chan_send->msg_type, chan_send->dstid); +return ret; + } + + wait_head = + &chan_info->wait[FIELD_GET (NBL_CHAN_MSGID_LOC_MASK , msgid)]; +spin_lock_irq (&wait_head->status_lock); + wait_head->acked =0 ; + wait_head->ack_data = chan_send->resp; + wait_head->ack_data_len = chan_send->resp_len; + wait_head->msg_type = chan_send->msg_type; + wait_head->msg_index =FIELD_GET (NBL_CHAN_MSGID_INDEX_MASK , msgid); + wait_head->dstid = chan_send->dstid; +/* Ensure all fields above are visible before status update, so receiver +* won't see WAITING with stale data
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 813
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+*/ +smp_wmb (); + wait_head->status = chan_send->ack ?NBL_MBX_STATUS_WAITING : +NBL_MBX_STATUS_IDLE ; +spin_unlock_irq (&wait_head->status_lock); + +atomic_inc (&chan_info->inflight_tx_cnt); + ret =nbl_chan_kick_tx_ring (chan_mgt, chan_info); +if (ret) { +mutex_lock (&chan_info->txq_lock);
coccinelle says:
@@ -94,0 +95 @@ +/srv/nipa-builds-contest/testing/wt-cocci/drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c:763:1-11: second lock on line 813
this will deadlock.
Note that sashiko has more comments:
https://sashiko.dev/#/patchset/20260708064742.35391-1-illusion.wang%40nebula-matrix.com
/P
illusion.wang
maintainerPATCH v21 5/12 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 | 11 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 4 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 47 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 + .../nbl_hw_leonis/nbl_resource_leonis.c | 284 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 10 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 148 +++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 75 +++++ .../nbl/nbl_include/nbl_def_common.h | 18 ++ .../nbl/nbl_include/nbl_def_hw.h | 4 + .../nbl/nbl_include/nbl_def_resource.h | 29 ++ .../nbl/nbl_include/nbl_include.h | 9 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 + 14 files changed, 663 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
@@ -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 +11 -0
@@ -6,6 +6,17 @@#include <linux/device.h> #include "nbl_common.h" +u32 nbl_common_pf_id_subtraction_mgtpf_id (struct nbl_common_info *common, +u32 pf_id) +{ +u32 diff =U32_MAX ; + +if (pf_id >= common->mgt_pf) + diff = pf_id - common->mgt_pf; + +return diff; +} +#define FNV_PRIME_32 0x01000193#define FNV_OFFSET_32 0x811C9DC5static u32 nbl_common_calc_hash_key (void *key,u32 key_size,u32 bucket_size)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +4 -0
@@ -12,6 +12,8 @@struct nbl_hw_mgt ;struct nbl_hw_ops_tbl ; +struct nbl_resource_mgt ; +struct nbl_resource_ops_tbl ;struct nbl_channel_ops_tbl ;struct nbl_channel_mgt ;
@@ -22,11 +24,13 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_ops_tbl; +struct nbl_resource_ops_tbl *resource_ops_tbl;struct nbl_channel_ops_tbl *channel_ops_tbl; };struct nbl_core {struct nbl_hw_mgt *hw_mgt; +struct nbl_resource_mgt *res_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +47 -0
79 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +14 -0
@@ -67,4 +67,18 @@ struct nbl_mailbox_qinfo_cfg_table {#define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004)#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040) +#define NBL_PCIE_BUS_MASK GENMASK(12, 5) +#define NBL_FW_BOARD_CONFIG 0x200 +#define NBL_FW_BOARD_DW3_OFFSET (NBL_FW_BOARD_CONFIG + 12) +#define NBL_FW_BOARD_DW6_OFFSET (NBL_FW_BOARD_CONFIG + 24) + +#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0) +#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1) +#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8) +#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10) +#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13) + +#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0) +#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8) +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +284 -0
284 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_RESOURCE_LEONIS_H_ +#define _NBL_RESOURCE_LEONIS_H_ + +#include "../nbl_resource.h" +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +148 -0
148 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +75 -0
75 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +18 -0
@@ -12,6 +12,21 @@#include "nbl_include.h" struct nbl_hash_tbl_mgt ; +#define NBL_TWO_ETHERNET_PORT 2 +#define NBL_FOUR_ETHERNET_PORT 4 +#define NBL_DEFAULT_VSI_ID_GAP 1024 +#define NBL_TWO_ETHERNET_VSI_ID_GAP 512 +#define NBL_FOUR_ETHERNET_VSI_ID_GAP 256 + +#define NBL_VSI_ID_GAP (m) \ + ({ \ + typeof(m) _m = (m); \ + _m == NBL_FOUR_ETHERNET_PORT ? \ + NBL_FOUR_ETHERNET_VSI_ID_GAP : \ + (_m == NBL_TWO_ETHERNET_PORT ? \ + NBL_TWO_ETHERNET_VSI_ID_GAP : \ + NBL_DEFAULT_VSI_ID_GAP); \ + })struct nbl_common_info {struct pci_dev *pdev;
@@ -40,6 +55,9 @@ struct nbl_hash_tbl_key {u16 resv; }; +u32 nbl_common_pf_id_subtraction_mgtpf_id (struct nbl_common_info *common, +u32 pf_id); +struct nbl_hash_tbl_mgt *nbl_common_init_hash_table (struct nbl_hash_tbl_key *key);void nbl_common_remove_hash_table (struct nbl_hash_tbl_mgt *tbl_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +4 -0
@@ -20,9 +20,13 @@ struct nbl_hw_ops {void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt);void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt);u32 (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt); +u8 (*get_real_bus)(struct nbl_hw_mgt *hw_mgt);void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +u32 (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt); +void (*get_board_info)(struct nbl_hw_mgt *hw_mgt, +struct nbl_board_port_info *board); };struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_RESOURCE_H_ +#define _NBL_DEF_RESOURCE_H_ + +#include <linux/types.h> + +struct nbl_resource_mgt ; +struct nbl_adapter ; + +struct nbl_resource_ops { +int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 type,u16 *vsi_id); +int (*get_eth_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id); +}; + +struct nbl_resource_ops_tbl { +struct nbl_resource_ops *ops; +struct nbl_resource_mgt *priv; +}; + +int nbl_res_init_leonis (struct nbl_adapter *adapter); +void nbl_res_remove_leonis (struct nbl_adapter *adapter); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +9 -0
@@ -16,6 +16,15 @@typeof (id) _id = (id); \ ((_id) == (max) ?0 : (_id) +1 ); \ }) + +#define NBL_MAX_FUNC 520 +#define NBL_MAX_ETHERNET 4 + +enum { +NBL_VSI_DATA =0 , +NBL_VSI_MAX , +}; +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -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"
@@ -42,7 +43,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 +58,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 v21 6/12 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
This patch adds the nbl_interrupt module for management of driver-private MSI-X indices, plus hw_ops callbacks to program the function MSI-X mapping registers, configure MSI-X info, and enable mailbox interrupts.
Key interfaces:
- configure_msix_map: Allocates driver-private global MSI-X indices
(interrupt_net_bitmap / interrupt_others_bitmap) and programs the hardware MSI-X mapping registers (NBL_PCOMPLETER_FUNCTION_MSIX_MAP). The actual PCI MSI-X vector allocation is done by nbl_dev_alloc_msix_intr().
- destroy_msix_map: Releases MSI-X indices and tears down the mapping.
- set_mailbox_irq: Enables/disables a specific mailbox interrupt.
- configure_msix_info: Programs PADPT_HOST_MSIX_INFO and
PCOMPLETER_HOST_MSIX_FID_TABLE.
The patch does not use kernel MSI-X allocation primitives (pci_alloc_irq_vectors, pci_msix_alloc_irq_at, irq_domain). It manages a driver-private global index space and programs vendor-specific MSI-X mapping registers.
Note: Mutual exclusion for configure_msix_map, destroy_msix_map, and enable_mailbox_irq is handled by the dispatch layer; these functions assume the caller already holds the necessary lock.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 120 ++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 +++ .../nbl_hw_leonis/nbl_resource_leonis.c | 9 + .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 288 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 ++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 33 ++ .../nbl/nbl_include/nbl_def_hw.h | 10 + .../nbl/nbl_include/nbl_def_resource.h | 6 + 10 files changed, 531 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -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 +120 -0
144 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +42 -0
48 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +9 -0
@@ -10,6 +10,9 @@static struct nbl_resource_ops res_ops = { .get_vsi_id = nbl_res_func_id_to_vsi_id, .get_eth_id = nbl_res_get_eth_id, + .configure_msix_map = nbl_res_intr_configure_msix_map, + .destroy_msix_map = nbl_res_intr_destroy_msix_map, + .set_mailbox_irq = nbl_res_intr_set_mailbox_irq, }; static struct nbl_resource_mgt *
@@ -243,7 +246,12 @@ static int nbl_res_start(struct nbl_resource_mgt *res_mgt) ret =nbl_res_ctrl_dev_vsi_info_init (res_mgt);if (ret)return ret; + + ret =nbl_intr_mgt_start (res_mgt); +if (ret) +return ret; } +return 0 ; }
@@ -276,6 +284,7 @@ int nbl_res_init_leonis(struct nbl_adapter *adap) } adap->intf.resource_ops_tbl = res_ops_tbl; adap->core.res_mgt = res_mgt; +return 0 ; }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -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 +288 -0
288 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_configure_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 num_net_msix, +u16 num_others_msix, +bool net_msix_mask_en); +int nbl_res_intr_set_mailbox_irq (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 vector_id, +bool enable_msix); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +33 -0
@@ -17,6 +17,38 @@struct nbl_resource_mgt ; +/* --------- INTERRUPT ---------- */ +#define NBL_MAX_OTHER_INTERRUPT 1024 +#define NBL_MAX_NET_INTERRUPT 4096 +#define NBL_NET_INTR_BASE NBL_MAX_OTHER_INTERRUPT + +#define NBL_MSIX_MAP_VALID_MASK BIT(0) +#define NBL_MSIX_MAP_INDEX_MASK GENMASK(13, 1) +#define NBL_MSIX_MAP_RSV_MASK GENMASK(15, 14) + +struct nbl_msix_map { +__le16 data; +}; + +struct nbl_msix_map_table { +struct nbl_msix_map *base_addr; +dma_addr_t dma; +size_t size; +}; + +struct nbl_func_interrupt_resource_mng { +u16 num_interrupts; +u16 num_net_interrupts; +u16 *interrupts; +struct nbl_msix_map_table msix_map_table; +}; + +struct nbl_interrupt_mgt { + DECLARE_BITMAP(interrupt_net_bitmap, NBL_MAX_NET_INTERRUPT); + DECLARE_BITMAP(interrupt_others_bitmap, NBL_MAX_OTHER_INTERRUPT); +struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC ]; +}; +/* --------- INFO ---------- */ struct nbl_sriov_info {unsigned int bdf;
@@ -70,6 +102,7 @@ int nbl_res_func_id_to_bdf(struct nbl_resource_mgt *res_mgt, u16 func_id, u8 *bus, u8 *dev, u8 *function);int nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 vsi_id,u8 *eth_num,u8 *eth_id,u8 *logic_eth_id); +int nbl_intr_mgt_start (struct nbl_resource_mgt *res_mgt);int nbl_res_pf_dev_vsi_type_to_hw_vsi_type (u16 src_type,enum nbl_vsi_serv_type *dst_type);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10 -0
@@ -11,6 +11,14 @@struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +void (*configure_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,dma_addr_t dma_addr,u8 bus, +u8 devid,u8 function); +void (*configure_msix_info)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,u16 interrupt_id,u8 bus, +u8 devid,u8 function, +bool net_msix_mask_en); +void (*flush_write)(struct nbl_hw_mgt *hw_mgt);void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,u16 tail_ptr,u8 txrx); void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
@@ -24,6 +32,8 @@ struct nbl_hw_ops {void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool enable_msix,u16 global_vec_id);u32 (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt);void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,struct nbl_board_port_info *board);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*configure_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id); +int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vector_id,bool enable_msix);int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 type,u16 *vsi_id); int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 7/12 net/nebula-matrix: add vsi resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
net/nebula-matrix: add vsi resource implementation
This patch adds the VSI (Virtual Station Interface) resource implementation for the Nebula Matrix Leonis hardware, wiring up chip module init/deinit logic that configures data-path engines, traffic shaping, flow-control registers, and the driver_status hardware flag consumed by firmware.
This driver only supports little-endian architecture.
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 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 501 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 242 +++++++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 2 + .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.c | 26 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.h | 12 + .../nbl/nbl_include/nbl_def_hw.h | 3 + .../nbl/nbl_include/nbl_def_resource.h | 3 + .../nbl/nbl_include/nbl_include.h | 12 + 10 files changed, 803 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_vsi.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_vsi.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_vsi.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +501 -0
513 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +242 -0
264 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +2 -0
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = { .configure_msix_map = nbl_res_intr_configure_msix_map, .destroy_msix_map = nbl_res_intr_destroy_msix_map, .set_mailbox_irq = nbl_res_intr_set_mailbox_irq, + .init_module = nbl_res_vsi_init_module, + .deinit_module = nbl_res_vsi_deinit_module, }; static struct nbl_resource_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_vsi.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_vsi.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_vsi.h" + +void nbl_res_vsi_deinit_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; + + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +} + +int nbl_res_vsi_init_module (struct nbl_resource_mgt *res_mgt) +{ +u8 eth_speed = res_mgt->resource_info->board_info.eth_speed; +u8 eth_num = res_mgt->resource_info->board_info.eth_num; +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv; +int ret; + + ret = hw_ops->init_module (p, eth_speed, eth_num); + +return ret; +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_vsi.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_VSI_H_ +#define _NBL_VSI_H_ + +#include "nbl_resource.h" +int nbl_res_vsi_init_module (struct nbl_resource_mgt *res_mgt); +void nbl_res_vsi_deinit_module (struct nbl_resource_mgt *res_mgt); +#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 (*configure_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id,bool valid,dma_addr_t dma_addr,u8 bus,u8 devid,u8 function);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +3 -0
@@ -12,6 +12,9 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*init_module)(struct nbl_resource_mgt *res_mgt); +void (*deinit_module)(struct nbl_resource_mgt *res_mgt); +int (*configure_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 num_net_msix,u16 num_others_msix,bool net_msix_mask_en);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +12 -0
@@ -35,4 +35,16 @@ struct nbl_init_param { struct nbl_func_caps caps; }; +enum nbl_fw_port_speed { +NBL_FW_PORT_SPEED_10G , +NBL_FW_PORT_SPEED_25G , +NBL_FW_PORT_SPEED_50G , +NBL_FW_PORT_SPEED_100G , +}; + +enum nbl_performance_mode { +NBL_QUIRKS_NO_TOE , +NBL_QUIRKS_UVN_PREFETCH_ALIGN , +}; +#endif
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 8/12 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_chip_module/deinit_chip_module only valid on Control PF, caller must guard with has_ctrl to avoid NULL deref.
This patch only provides core routing skeleton, no channel message handling or resource locking logic.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_channel/nbl_channel.c | 4 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 4 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 137 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 24 +++ .../nbl/nbl_include/nbl_def_channel.h | 26 ++++ .../nbl/nbl_include/nbl_def_dispatch.h | 42 ++++++ .../nbl/nbl_include/nbl_include.h | 16 ++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 + 9 files changed, 262 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_vsi.o \ + nbl_core/nbl_dispatch.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +4 -0
@@ -1051,6 +1051,10 @@ int nbl_chan_init_common(struct nbl_adapter *adap)struct nbl_channel_mgt *chan_mgt;int ret; +BUILD_BUG_ON (sizeof (struct nbl_chan_param_cfg_msix_map ) !=8 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_set_mailbox_irq ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_vsi_id ) !=4 ); +BUILD_BUG_ON (sizeof (struct nbl_chan_param_get_eth_id ) !=8 ); chan_mgt =nbl_chan_setup_chan_mgt (adap);if (IS_ERR (chan_mgt)) { ret =PTR_ERR (chan_mgt);
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +4 -0
@@ -14,6 +14,8 @@ struct nbl_hw_mgt;struct nbl_hw_ops_tbl ;struct nbl_resource_mgt ;struct nbl_resource_ops_tbl ; +struct nbl_dispatch_mgt ; +struct nbl_dispatch_ops_tbl ;struct nbl_channel_ops_tbl ;struct nbl_channel_mgt ;
@@ -25,12 +27,14 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_ops_tbl;struct nbl_resource_ops_tbl *resource_ops_tbl; +struct nbl_dispatch_ops_tbl *dispatch_ops_tbl;struct nbl_channel_ops_tbl *channel_ops_tbl; };struct nbl_core {struct nbl_hw_mgt *hw_mgt;struct nbl_resource_mgt *res_mgt; +struct nbl_dispatch_mgt *disp_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +137 -0
137 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DISPATCH_H_ +#define _NBL_DISPATCH_H_ +#include "../nbl_include/nbl_include.h" +#include "../nbl_include/nbl_def_channel.h" +#include "../nbl_include/nbl_def_hw.h" +#include "../nbl_include/nbl_def_resource.h" +#include "../nbl_include/nbl_def_dispatch.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +struct nbl_dispatch_mgt { +struct nbl_common_info *common; +struct nbl_resource_ops_tbl *res_ops_tbl; +struct nbl_channel_ops_tbl *chan_ops_tbl; +struct nbl_dispatch_ops_tbl *disp_ops_tbl; + DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX); +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +26 -0
@@ -281,6 +281,32 @@ enum nbl_chan_state {NBL_CHAN_STATE_NBITS }; +struct nbl_chan_param_cfg_msix_map { +__le16 num_net_msix; +__le16 num_others_msix; +__le16 msix_mask_en; +__le16 rsvd; +}; + +struct nbl_chan_param_set_mailbox_irq { +__le16 vector_id; +u8 enable_msix; +u8 rsvd; +}; + +struct nbl_chan_param_get_vsi_id { +__le16 vsi_id; +__le16 type; +}; + +struct nbl_chan_param_get_eth_id { +__le16 vsi_id; +u8 eth_num; +u8 eth_id; +u8 logic_eth_id; +u8 rsvd[3 ]; +}; +struct nbl_board_port_info {u8 eth_num;u8 eth_speed;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +42 -0
42 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +16 -0
@@ -19,6 +19,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 ,
@@ -42,6 +44,20 @@ enum nbl_fw_port_speed { NBL_FW_PORT_SPEED_100G, }; +#define NBL_OPS_CALL (func, para) \ +do { \ + typeof(func) _func = (func); \ + if (_func) \ + _func para; \ +} while (0) + +/* Optional ops: NULL means not implemented, return 0 = no-op (not an error) */ +#define NBL_OPS_CALL_RET (func, para) \ +({ \ + typeof(func) _func = (func); \ + _func ? _func para : 0; \ +}) +enum nbl_performance_mode {NBL_QUIRKS_NO_TOE ,NBL_QUIRKS_UVN_PREFETCH_ALIGN ,
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
@@ -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"
@@ -47,7 +48,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:
@@ -58,6 +65,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter);
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 9/12 net/nebula-matrix: dispatch: add cross-version channel message framework
In reply to illusion.wangFrom: illusion wang <[email protected]>
Implement channel message request/response handlers for 7 dispatch ops:get_vsi_id, get_eth_id, configure_msix_map, destroy_msix_map, set_mailbox_irq.
Key features:
1. Cross firmware backward compat: min-copy + zero-fill for short incoming message payloads, no reject for older peer smaller message structures
2. Distinguish unimplemented resource ops from valid zero return value:
return dedicated NBL_CHAN_RESP_UNIMPLEMENTED error code when ops pointer is NULL, avoid ambiguous zero result on getter replies
3. Extend X-macro dispatch op table with channel msg metadata
4. Message registration helper nbl_disp_setup_msg()
5. Error logging for failed channel ack send
Depends: dispatch core routing infrastructure patch No resource locking mutex introduced in this patch.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 391 ++++++++++++++++++ 1 file changed, 391 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +391 -0
@@ -6,6 +6,129 @@#include <linux/pci.h> #include "nbl_dispatch.h" +static int nbl_disp_chan_get_vsi_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 type,u16 *vsi_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_send_info chan_send; +int ret; + + param.type =cpu_to_le16 (type); + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_GET_VSI_ID , + ¶m,sizeof (param), &result,sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; + + *vsi_id =le16_to_cpu (result.vsi_id); +return 0 ; +} + +static void nbl_disp_chan_get_vsi_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +u16 vsi_id =0 ; +int copy_len; +int ret; + + copy_len = data_len <sizeof (param) ? data_len :sizeof (param); +memcpy (¶m, data, copy_len); + ret =NBL_OPS_CALL_RET (res_ops->get_vsi_id, + (p, src_id,le16_to_cpu (param.type), &vsi_id)); +if (ret) + err =NBL_CHAN_RESP_ERR ; +if (!res_ops->get_vsi_id) + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + result.vsi_id =cpu_to_le16 (vsi_id); +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_GET_VSI_ID , msg_id, err, + &result,sizeof (result)); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_GET_VSI_ID ); +} + +static int nbl_disp_chan_get_eth_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct nbl_chan_send_info chan_send; +int ret; + + param.vsi_id =cpu_to_le16 (vsi_id); + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_GET_ETH_ID , + ¶m,sizeof (param), &result,sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; + *eth_num = result.eth_num; + *eth_id = result.eth_id; + *logic_eth_id = result.logic_eth_id; + +return 0 ; +} + +static void nbl_disp_chan_get_eth_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int copy_len; +int ret; + +/* +* The responder may run an older version than the requestor, so +* data_len < sizeof(param) is expected and handled by min-copy + +* zero-fill. Rejecting short responses would break cross-version +* interop +*/ + copy_len = data_len <sizeof (param) ? data_len :sizeof (param); +memcpy (¶m, data, copy_len); + + ret =NBL_OPS_CALL_RET (res_ops->get_eth_id, + (p, src_id,le16_to_cpu (param.vsi_id), + &result.eth_num, &result.eth_id, + &result.logic_eth_id)); +if (ret) + err =NBL_CHAN_RESP_ERR ; +if (!res_ops->get_eth_id) + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_GET_ETH_ID , msg_id, err, + &result,sizeof (result)); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_GET_ETH_ID ); +} +static void nbl_disp_deinit_module (struct nbl_dispatch_mgt *disp_mgt) {struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
@@ -22,6 +145,210 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return NBL_OPS_CALL_RET (res_ops->init_module, (p)); } +static int nbl_disp_configure_msix_map (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +return NBL_OPS_CALL_RET (res_ops->configure_msix_map, (p, + common->mgt_pf, num_net_msix, + num_others_msix, net_msix_mask_en)); +} + +static int +nbl_disp_chan_configure_msix_map_req (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_send_info chan_send; + + param.num_net_msix =cpu_to_le16 (num_net_msix); + param.num_others_msix =cpu_to_le16 (num_others_msix); + param.msix_mask_en =cpu_to_le16 (!!net_msix_mask_en); + +NBL_CHAN_SEND (chan_send, common->mgt_pf, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , ¶m,sizeof (param), +NULL ,0 ,1 ); +return chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +} + +static void nbl_disp_chan_configure_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int copy_len; +int ret; + + copy_len = data_len <sizeof (param) ? data_len :sizeof (param); +memcpy (¶m, data, copy_len); + ret =NBL_OPS_CALL_RET (res_ops->configure_msix_map, + (p, src_id,le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), +le16_to_cpu (param.msix_mask_en))); +if (ret) + err =NBL_CHAN_RESP_ERR ; +if (!res_ops->configure_msix_map) + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP ); +} + +static int nbl_disp_chan_destroy_msix_map_req (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send; + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_DESTROY_MSIX_MAP , +NULL ,0 ,NULL ,0 ,1 ); +return chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +} + +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; + + ret =NBL_OPS_CALL_RET (res_ops->destroy_msix_map, (p, src_id)); +if (ret) + err =NBL_CHAN_RESP_ERR ; +if (!res_ops->destroy_msix_map) + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_DESTROY_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_DESTROY_MSIX_MAP ); +} + +static int nbl_disp_chan_set_mailbox_irq_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool enable_msix) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send; + + param.vector_id =cpu_to_le16 (vector_id); + param.enable_msix = enable_msix; + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_MAILBOX_SET_IRQ , + ¶m,sizeof (param),NULL ,0 ,1 ); +return chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +} + +static void nbl_disp_chan_set_mailbox_irq_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +bool enable_msix; +u16 vector_id; +int copy_len; +int ret; + + copy_len = data_len <sizeof (param) ? data_len :sizeof (param); +memcpy (¶m, data, copy_len); + vector_id =le16_to_cpu (param.vector_id); + enable_msix = !!param.enable_msix; + ret =NBL_OPS_CALL_RET (res_ops->set_mailbox_irq, + (p, src_id, vector_id, enable_msix)); +if (ret) + err =NBL_CHAN_RESP_ERR ; +if (!res_ops->set_mailbox_irq) + err =NBL_CHAN_RESP_UNIMPLEMENTED ; + +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_MAILBOX_SET_IRQ , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_MAILBOX_SET_IRQ ); +} + +static int nbl_disp_destroy_msix_map (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +return NBL_OPS_CALL_RET (res_ops->destroy_msix_map, (p, + common->mgt_pf)); +} + +static int nbl_disp_set_mailbox_irq (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool enable_msix) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +return NBL_OPS_CALL_RET (res_ops->set_mailbox_irq, (p, + common->mgt_pf, vector_id, enable_msix)); +} + +static int nbl_disp_get_vsi_id (struct nbl_dispatch_mgt *disp_mgt,u16 type, +u16 *vsi_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +return NBL_OPS_CALL_RET (res_ops->get_vsi_id, + (p, common->mgt_pf, type, vsi_id)); +} + +static int nbl_disp_get_eth_id (struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +return NBL_OPS_CALL_RET (res_ops->get_eth_id, + (p, common->mgt_pf, vsi_id, eth_num, eth_id, + logic_eth_id)); +} +/* NBL_DISP_SET_OPS(disp_op_name, func, ctrl_lvl, msg_type, msg_req, msg_resp) * ctrl_lvl is to define when this disp_op should go directly to res_op, * not sending a channel msg.
@@ -38,7 +365,62 @@ do { \NBL_DISP_SET_OPS (deinit_module, \ nbl_disp_deinit_module, \NBL_DISP_CTRL_LVL_MGT ,-1 ,NULL ,NULL ); \ +NBL_DISP_SET_OPS (configure_msix_map, \ + nbl_disp_configure_msix_map, \ +NBL_DISP_CTRL_LVL_MGT , \ +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , \ + nbl_disp_chan_configure_msix_map_req, \ + nbl_disp_chan_configure_msix_map_resp); \ +NBL_DISP_SET_OPS (destroy_msix_map, nbl_disp_destroy_msix_map, \ +NBL_DISP_CTRL_LVL_MGT , \ +NBL_CHAN_MSG_DESTROY_MSIX_MAP , \ + nbl_disp_chan_destroy_msix_map_req, \ + nbl_disp_chan_destroy_msix_map_resp); \ +NBL_DISP_SET_OPS (set_mailbox_irq, \ + nbl_disp_set_mailbox_irq, \ +NBL_DISP_CTRL_LVL_MGT , \ +NBL_CHAN_MSG_MAILBOX_SET_IRQ , \ + nbl_disp_chan_set_mailbox_irq_req, \ + nbl_disp_chan_set_mailbox_irq_resp); \ +NBL_DISP_SET_OPS (get_vsi_id, nbl_disp_get_vsi_id, \ +NBL_DISP_CTRL_LVL_MGT ,NBL_CHAN_MSG_GET_VSI_ID ,\ + nbl_disp_chan_get_vsi_id_req, \ + nbl_disp_chan_get_vsi_id_resp); \ +NBL_DISP_SET_OPS (get_eth_id, nbl_disp_get_eth_id, \ +NBL_DISP_CTRL_LVL_MGT ,NBL_CHAN_MSG_GET_ETH_ID ,\ + nbl_disp_chan_get_eth_id_req, \ + nbl_disp_chan_get_eth_id_resp); \ +}while (0 ) + +/* Structure starts here, adding an op should not modify anything below */ +static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; +int ret =0 ; +int _ret; + +#define NBL_DISP_SET_OPS (disp_op, func, ctrl, msg_type, msg_req, resp) \ +do { \ + typeof(msg_type) _msg_type = (msg_type); \ + typeof(ctrl) _ctrl_lvl = (ctrl); \ + (void)(disp_ops->NBL_NAME(disp_op)); \ + (void)(func); \ + (void)(msg_req); \ + (void)_ctrl_lvl; \ + if (_msg_type >= 0) { \ + _ret = chan_ops->register_msg(p, _msg_type, resp, disp_mgt);\ + if (_ret < 0 && !ret) \ + ret = _ret; \ + } \ } while (0) +NBL_DISP_OPS_TBL ; +#undef NBL_DISP_SET_OPS +if (ret) + chan_ops->unregister_all_msg (p); +return ret; +}/* Ctrl lvl means that if a certain level is set, then all disp_ops that * declared this lvl will go directly to res_ops, rather than send a
@@ -126,6 +508,10 @@ int nbl_disp_init(struct nbl_adapter *adapter) adapter->core.disp_mgt = disp_mgt; adapter->intf.dispatch_ops_tbl = disp_ops_tbl; + ret =nbl_disp_setup_msg (disp_mgt); +if (ret) +return ret; +if (common->has_ctrl)nbl_disp_setup_ctrl_lvl (disp_mgt,NBL_DISP_CTRL_LVL_MGT );
@@ -134,4 +520,9 @@ int nbl_disp_init(struct nbl_adapter *adapter)void nbl_disp_remove (struct nbl_adapter *adapter) { +struct nbl_dispatch_mgt *disp_mgt = adapter->core.disp_mgt; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; + + chan_ops->unregister_all_msg (p); }
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 10/12 net/nebula-matrix: dispatch: add resource ops lock protection
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add mutual exclusion lock for resource ops that modify shared hardware state:
1. Introduce ops_mutex_lock, init/destroy in dispatch setup/remove paths
2. NBL_OPS_CALL_LOCK_RET wrapper to wrap resource ops with lock hold
3. Wrap configure_msix_map / destroy_msix_map / set_mailbox_irq with lock
4. Fix teardown order inversion bug: unregister all channel message handlers before mutex destroy, eliminate potential lockdep splat or mutex corruption
5. Cleanup registered message handlers on nbl_disp_setup_msg() failure path
Depends: dispatch core routing + channel message framework patches
The read-only get_vsi_id/get_eth_id ops access static init-time data without concurrent writer, so no lock required for them.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 40 ++++++++++++------- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 18 +++++++++ 2 files changed, 44 insertions(+), 14 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +26 -14
@@ -153,9 +153,9 @@ static int nbl_disp_configure_msix_map(struct nbl_dispatch_mgt *disp_mgt,struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;struct nbl_common_info *common = disp_mgt->common; -return NBL_OPS_CALL_RET (res_ops->configure_msix_map, (p, +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->configure_msix_map, p, common->mgt_pf, num_net_msix, - num_others_msix, net_msix_mask_en)); + num_others_msix, net_msix_mask_en); } static int
@@ -195,10 +195,10 @@ static void nbl_disp_chan_configure_msix_map_resp(void *priv, u16 src_id, copy_len = data_len <sizeof (param) ? data_len :sizeof (param);memcpy (¶m, data, copy_len); - ret =NBL_OPS_CALL_RET (res_ops->configure_msix_map, - (p, src_id,le16_to_cpu (param.num_net_msix), -le16_to_cpu (param.num_others_msix), -le16_to_cpu (param.msix_mask_en))); + ret =NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->configure_msix_map, p, + src_id,le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), +le16_to_cpu (param.msix_mask_en));if (ret) err =NBL_CHAN_RESP_ERR ;if (!res_ops->configure_msix_map)
@@ -237,7 +237,8 @@ static void nbl_disp_chan_destroy_msix_map_resp(void *priv, u16 src_id,int err =NBL_CHAN_RESP_OK ;int ret; - ret =NBL_OPS_CALL_RET (res_ops->destroy_msix_map, (p, src_id)); + ret =NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->destroy_msix_map, p, + src_id);if (ret) err =NBL_CHAN_RESP_ERR ;if (!res_ops->destroy_msix_map)
@@ -289,8 +290,8 @@ static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,memcpy (¶m, data, copy_len); vector_id =le16_to_cpu (param.vector_id); enable_msix = !!param.enable_msix; - ret =NBL_OPS_CALL_RET (res_ops->set_mailbox_irq, - (p, src_id, vector_id, enable_msix)); + ret =NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->set_mailbox_irq, p, + src_id, vector_id, enable_msix);if (ret) err =NBL_CHAN_RESP_ERR ;if (!res_ops->set_mailbox_irq)
@@ -311,8 +312,8 @@ static int nbl_disp_destroy_msix_map(struct nbl_dispatch_mgt *disp_mgt)struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;struct nbl_common_info *common = disp_mgt->common; -return NBL_OPS_CALL_RET (res_ops->destroy_msix_map, (p, - common->mgt_pf)); +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->destroy_msix_map, p, + common->mgt_pf); } static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
@@ -322,8 +323,8 @@ static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;struct nbl_common_info *common = disp_mgt->common; -return NBL_OPS_CALL_RET (res_ops->set_mailbox_irq, (p, - common->mgt_pf, vector_id, enable_msix)); +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->set_mailbox_irq, p, + common->mgt_pf, vector_id, enable_msix); } static int nbl_disp_get_vsi_id(struct nbl_dispatch_mgt *disp_mgt, u16 type,
@@ -401,6 +402,8 @@ static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *disp_mgt)int ret =0 ;int _ret; +mutex_init (&disp_mgt->ops_mutex_lock); +#define NBL_DISP_SET_OPS (disp_op, func, ctrl, msg_type, msg_req, resp) \ do { \ typeof(msg_type) _msg_type = (msg_type); \
@@ -417,8 +420,10 @@ do { \ }while (0 )NBL_DISP_OPS_TBL ;#undef NBL_DISP_SET_OPS -if (ret) +if (ret) { chan_ops->unregister_all_msg (p); +mutex_destroy (&disp_mgt->ops_mutex_lock); + }return ret; }
@@ -515,6 +520,12 @@ int nbl_disp_init(struct nbl_adapter *adapter)if (common->has_ctrl)nbl_disp_setup_ctrl_lvl (disp_mgt,NBL_DISP_CTRL_LVL_MGT ); +/* This bit must be set for adapters with net capability, +* otherwise dispatch ops will be not set.. +*/ +if (common->has_net) +nbl_disp_setup_ctrl_lvl (disp_mgt,NBL_DISP_CTRL_LVL_NET ); +return 0 ; }
@@ -525,4 +536,5 @@ void nbl_disp_remove(struct nbl_adapter *adapter)struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; chan_ops->unregister_all_msg (p); +mutex_destroy (&disp_mgt->ops_mutex_lock); }
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +18 -0
@@ -13,12 +13,30 @@#include "../nbl_include/nbl_def_common.h" #include "../nbl_core.h" +#define NBL_OPS_CALL_LOCK_RET (disp_mgt, func, ...) \ +({ \ + typeof(disp_mgt) _disp_mgt = (disp_mgt); \ + typeof(func) _func = (func); \ + typeof(_func(__VA_ARGS__)) _ret = 0; \ + \ + mutex_lock(&_disp_mgt->ops_mutex_lock); \ + \ + if (_func) \ + _ret = _func(__VA_ARGS__); \ + \ + mutex_unlock(&_disp_mgt->ops_mutex_lock); \ + \ + _ret; \ +}) +struct nbl_dispatch_mgt {struct nbl_common_info *common;struct nbl_resource_ops_tbl *res_ops_tbl;struct nbl_channel_ops_tbl *chan_ops_tbl;struct nbl_dispatch_ops_tbl *disp_ops_tbl; DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX); +/* use for the caller not in interrupt */ +struct mutex ops_mutex_lock; };#endif
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v21 11/12 net/nebula-matrix: add common/ctrl dev init/remove operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
This patch adds nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() init helpers, paired with corresponding teardown routines, and hooks them into nbl_dev_init / nbl_dev_remove.
Chip core hardware initialization is fully handled by firmware during power-on; the driver only configures functional table entries and registers after hardware is ready. Thus invoking nbl_dev_setup_common_dev() before ctrl dev setup does not trigger hardware faults, all register accesses are safe.
Teardown order explanation:
1. Remove ctrl dev first: notify firmware to clean all per-PF hardware state including qinfo registers via driver status flag.
2. Then tear down common device queue resources.
Firmware cleanup ensures qinfo registers are valid during subsequent common dev deinit writes, avoiding PCIe master abort or hardware access panics.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 200 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 +++++ .../nbl/nbl_include/nbl_def_dev.h | 14 ++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 6 files changed, 281 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -11,4 +11,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_vsi.o \ nbl_core/nbl_dispatch.o \ + nbl_core/nbl_dev.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -18,6 +18,7 @@ struct nbl_dispatch_mgt;struct nbl_dispatch_ops_tbl ;struct nbl_channel_ops_tbl ;struct nbl_channel_mgt ; +struct nbl_dev_mgt ;enum {NBL_CAP_HAS_CTRL_BIT ,
@@ -35,6 +36,7 @@ struct nbl_core {struct nbl_hw_mgt *hw_mgt;struct nbl_resource_mgt *res_mgt;struct nbl_dispatch_mgt *disp_mgt; +struct nbl_dev_mgt *dev_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +200 -0
200 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +55 -0
55 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 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"
@@ -52,7 +53,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:
@@ -65,6 +73,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
illusion.wang
maintainerPATCH v21 12/12 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.
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 threaded mailbox IRQ with top-half/bottom-half handler
- Enable hardware mailbox interrupt and mark channel interrupt ready
2. Add nbl_dev_stop() to tear down device resources safely in order:
- Software channel state cleared first, then hardware interrupt masked
- Free mailbox IRQ handler and release MSI-X vector resources
- Destroy hardware MSI-X mapping table
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 264 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 22 +- 4 files changed, 288 insertions(+), 2 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -50,5 +50,7 @@ struct nbl_adapter {struct nbl_adapter *nbl_core_init (struct pci_dev *pdev,struct nbl_init_param *param);void nbl_core_remove (struct nbl_adapter *adapter); +int nbl_core_start (struct nbl_adapter *adapter); +void nbl_core_stop (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +264 -0
285 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
@@ -10,5 +10,7 @@ struct nbl_adapter;int nbl_dev_init (struct nbl_adapter *adapter);void nbl_dev_remove (struct nbl_adapter *adapter); +int nbl_dev_start (struct nbl_adapter *adapter); +void nbl_dev_stop (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +20 -2
@@ -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) {
@@ -135,7 +145,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:
@@ -147,9 +164,10 @@ static void nbl_remove(struct pci_dev *pdev) {struct nbl_adapter *adapter =pci_get_drvdata (pdev); -if (adapter) +if (adapter) { +nbl_core_stop (adapter);nbl_core_remove (adapter); - + }pci_restore_state (pdev);pci_clear_master (pdev);pci_disable_device (pdev);
Signature · 1 line
2.47.3