nbl driver for Nebulamatrix NICs
Subsystems (4)
illusion.wang
maintainerv4 cover nbl driver for Nebulamatrix NICs
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.
ps:The "nbl_core" issue has not been modified yet as it is still under discussion.
(https://lore.kernel.org/netdev/[email protected]/)
We will make the modification once a conclusion is reached.
Excluding patch 3,4, the total comes to about 5000 lines.
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
chanages v2 →v3
Link to v2: https://lore.kernel.org/netdev/[email protected]/
1.cut down to a mini driver:
delete vf support
use promisc mode to cut down flow management
drop patch15 in v2
delete adminq msg
delete abnormal handling
delete some unimportant interfaces
2.modify issues found by ai review
Changes v1->v2
Link to v1: https://lore.kernel.org/netdev/[email protected]/
1.Format Issues and Compilation Issues
- Paolo Abeni
2.add sysfs patch and drop coexisting patch
- Andrew Lunn
3.delete some unimportant ndo operations
4.add machine generated headers patch
5.Modify the issues found in patch1-2 and apply the same fixes to other
patches
6.modify issues found by nipa
illusion.wang (11):
net/nebula-matrix: add minimum nbl build framework net/nebula-matrix: add our driver architecture net/nebula-matrix: add chip related definitions net/nebula-matrix: channel msg value and msg struct 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: add Dispatch layer implementation net/nebula-matrix: add common/ctrl dev init/reinit operation net/nebula-matrix: add common dev start/stop operation
.../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/m18100.rst | 47 + MAINTAINERS | 10 + drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 36 + drivers/net/ethernet/nebula-matrix/Makefile | 6 + .../net/ethernet/nebula-matrix/nbl/Makefile | 22 + .../nbl/nbl_channel/nbl_channel.c | 872 +++++ .../nbl/nbl_channel/nbl_channel.h | 159 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 227 ++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 28 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 84 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 472 +++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 53 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 492 +++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 51 + .../nebula-matrix/nbl/nbl_hw/nbl_hw.h | 128 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 765 +++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 1183 +++++++ .../nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.c | 2902 +++++++++++++++++ .../nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h | 12 + .../nbl_hw_leonis/nbl_resource_leonis.c | 292 ++ .../nbl_hw_leonis/nbl_resource_leonis.h | 11 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 131 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 233 ++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 13 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 142 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 128 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.c | 54 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.h | 12 + .../nbl/nbl_include/nbl_def_channel.h | 363 +++ .../nbl/nbl_include/nbl_def_common.h | 122 + .../nbl/nbl_include/nbl_def_dev.h | 12 + .../nbl/nbl_include/nbl_def_dispatch.h | 40 + .../nbl/nbl_include/nbl_def_hw.h | 50 + .../nbl/nbl_include/nbl_def_resource.h | 34 + .../nbl/nbl_include/nbl_include.h | 81 + .../nbl/nbl_include/nbl_product_base.h | 20 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 320 ++ 40 files changed, 9610 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/m18100.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.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_hw_leonis_regs.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.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_include/nbl_product_base.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v4 1/11 net/nebula-matrix: add minimum nbl build framework
1.Add nbl min build infrastructure for nbl driver.
2.Implemented the framework of pci device initialization.
--- .../device_drivers/ethernet/index.rst | 1 + .../ethernet/nebula-matrix/m18100.rst | 47 ++++++++ MAINTAINERS | 10 ++ drivers/net/ethernet/Kconfig | 1 + drivers/net/ethernet/Makefile | 1 + drivers/net/ethernet/nebula-matrix/Kconfig | 36 ++++++ drivers/net/ethernet/nebula-matrix/Makefile | 6 + .../net/ethernet/nebula-matrix/nbl/Makefile | 11 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 27 +++++ .../nbl/nbl_include/nbl_include.h | 23 ++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 109 ++++++++++++++++++ 11 files changed, 272 insertions(+) create mode 100644 Documentation/networking/device_drivers/ethernet/nebula-matrix/m18100.rst create mode 100644 drivers/net/ethernet/nebula-matrix/Kconfig create mode 100644 drivers/net/ethernet/nebula-matrix/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/Makefile create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
@@ -48,6 +48,7 @@ Contents: meta/fbnic microsoft/netvsc mucse/rnpgbe + nebula-matrix/nbl netronome/nfp pensando/ionic pensando/ionic_rdma
Documentation/networking/device_drivers/ethernet/nebula-matrix/m18100.rst new file +47 -0
47 lines not on this page · raw message
MAINTAINERS +10 -0
@@ -18015,6 +18015,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: llusion.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
@@ -131,6 +131,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
@@ -68,6 +68,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 +36 -0
@@ -0,0 +1,36 @@ +# 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_CORE + tristate "Nebula-matrix Ethernet Controller m18100 Family support" + depends on 64BIT && PCI + default m + select PAGE_POOL + help + This driver supports Nebula-matrix Ethernet Controller m18100 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/m18100.rst>. + + To compile this driver as a module, choose M here. The module + will be called nbl_core. + +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_CORE) += nbl/
drivers/net/ethernet/nebula-matrix/nbl/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 Nebula Matrix Limited. +# Author: + +obj-$(CONFIG_NBL_CORE) := nbl_core.o + +nbl_core-objs += nbl_main.o + +# Provide include files +ccflags-y += -I$(srctree)/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/ +ccflags-y += -I$(srctree)/drivers/net/ethernet/nebula-matrix/nbl/
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_CORE_H_ +#define _NBL_CORE_H_ + +#include <linux/pci.h> +#include "nbl_include.h" +#define NBL_CAP_TEST_BIT (val, loc) (((val) >> (loc)) & 0x1) + +#define NBL_CAP_IS_CTRL (val) NBL_CAP_TEST_BIT(val, NBL_CAP_HAS_CTRL_BIT) +#define NBL_CAP_IS_NET (val) NBL_CAP_TEST_BIT(val, NBL_CAP_HAS_NET_BIT) +#define NBL_CAP_IS_NIC (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_NIC_BIT) +#define NBL_CAP_IS_OCP (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_OCP_BIT) +#define NBL_CAP_IS_LEONIS (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_LEONIS_BIT) + +enum { +NBL_CAP_HAS_CTRL_BIT =0 , +NBL_CAP_HAS_NET_BIT , +NBL_CAP_IS_NIC_BIT , +NBL_CAP_IS_LEONIS_BIT , +NBL_CAP_IS_OCP_BIT , +}; +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_INCLUDE_H_ +#define _NBL_INCLUDE_H_ + +#include <linux/types.h> + +/* ------ Basic definitions ------- */ +#define NBL_DRIVER_NAME "nbl_core" + +struct nbl_func_caps { +u32 has_ctrl:1 ; +u32 has_net:1 ; +u32 is_nic:1 ; +u32 is_ocp:1 ; +u32 rsv:28 ; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH v4 net-next 01/11] net/nebula-matrix: add minimum nbl build framework
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +13
-0+#define NBL_CAP_TEST_BIT (val, loc) (((val) >> (loc)) & 0x1) + +#define NBL_CAP_IS_CTRL (val) NBL_CAP_TEST_BIT(val, NBL_CAP_HAS_CTRL_BIT) +#define NBL_CAP_IS_NET (val) NBL_CAP_TEST_BIT(val, NBL_CAP_HAS_NET_BIT) +#define NBL_CAP_IS_NIC (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_NIC_BIT) +#define NBL_CAP_IS_OCP (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_OCP_BIT) +#define NBL_CAP_IS_LEONIS (val) NBL_CAP_TEST_BIT(val, NBL_CAP_IS_LEONIS_BIT) + +enum { +NBL_CAP_HAS_CTRL_BIT =0 , +NBL_CAP_HAS_NET_BIT , +NBL_CAP_IS_NIC_BIT , +NBL_CAP_IS_LEONIS_BIT ,
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h new file +9
-0+ NBL_CAP_IS_OCP_BIT, +}; +static const struct pci_device_id nbl_id_table[] = { + {PCI_DEVICE (NBL_VENDOR_ID ,NBL_DEVICE_ID_M18110 ), + .driver_data =BIT (NBL_CAP_HAS_NET_BIT ) |BIT (NBL_CAP_IS_NIC_BIT ) | +BIT (NBL_CAP_IS_LEONIS_BIT ) }, + {PCI_DEVICE (NBL_VENDOR_ID ,NBL_DEVICE_ID_M18110_LX ), + .driver_data =BIT (NBL_CAP_HAS_NET_BIT ) |BIT (NBL_CAP_IS_NIC_BIT ) | +BIT (NBL_CAP_IS_LEONIS_BIT ) },
This seems overly complicated. Maybe NBL_CAP_* should be directly BIT() values?
NBL_CAP_TEST_BIT then goes away:
#define NBL_CAP_IS_CTRL(val) (val & NBL_CAP_HAS_CTRL_BIT)
which is simple enough you can have it inline, macro not needed.
It is however hard to say, because you add these macros here, but don't have any uses of them.
Andrew
Jakub Kicinski
maintainerRe: [v4,net-next,01/11] net/nebula-matrix: add minimum nbl build framework
In reply to illusion.wangThis is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add minimum nbl build framework
This commit adds the minimal build infrastructure for the Nebula-Matrix M18100-NIC family driver, including Kconfig, Makefiles, documentation, and stub PCI driver functions.
Documentation/networking/device_drivers/ethernet/index.rst line 52
Quoted 9 lines
Documentation/networking/device_drivers/ethernet/index.rst +1
-0@@ -48,6 +48,7 @@ meta/fbnic microsoft/netvsc mucse/rnpgbe + nebula-matrix/nbl netronome/nfp
The documentation index references 'nebula-matrix/nbl' but the actual file created is 'nebula-matrix/m18100.rst'. This will cause 'make htmldocs' to fail with a broken reference.
Simon Horman flagged this in v3 review:
https://lore.kernel.org/netdev/[email protected]/
Should this be 'nebula-matrix/m18100' instead?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/Kconfig line 19
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/Kconfig new file +2
-0+config NBL_CORE + tristate "Nebula-matrix Ethernet Controller m18100 Family support"
Andrew Lunn raised concerns about the NBL_CORE naming in multiple versions of this patch series. The "_CORE" suffix is typically reserved for libraries shared by multiple drivers that use 'select' rather than having a tristate prompt.
If this module provides Ethernet functionality directly, the naming convention would be to call it an Ethernet driver rather than "core".
See v1 and v3 review comments:
https://lore.kernel.org/netdev/[email protected]/
Is there a reason to keep the _CORE suffix, or could this follow standard driver naming conventions?
illusion.wang
maintainerPATCH v4 2/11 net/nebula-matrix: add our driver architecture
In reply to illusion.wangour driver architecture:
Hardware (HW), Channel, Resource, Dispatch, and Device Layer Struct Initialization/Deinitialization, and Operation Set Registration/ Unregistration
Our driver architecture is relatively complex because the code is highly reusable and designed to support multiple features. Additionally, the codebase supports multiple chip variants, each with distinct hardware-software interactions.
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
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 8 +- .../nbl/nbl_channel/nbl_channel.c | 82 ++++++++ .../nbl/nbl_channel/nbl_channel.h | 37 ++++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 59 +++++- .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 55 ++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 18 ++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 75 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 22 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 143 ++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 13 ++ .../nbl_hw_leonis/nbl_resource_leonis.c | 90 +++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 ++ .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 131 +++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 30 +++ .../nbl/nbl_include/nbl_def_channel.h | 26 +++ .../nbl/nbl_include/nbl_def_common.h | 33 ++++ .../nbl/nbl_include/nbl_def_dev.h | 12 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 28 +++ .../nbl/nbl_include/nbl_def_hw.h | 20 ++ .../nbl/nbl_include/nbl_def_resource.h | 21 ++ .../nbl/nbl_include/nbl_include.h | 13 +- .../nbl/nbl_include/nbl_product_base.h | 20 ++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 180 ++++++++++++++++++ 23 files changed, 1125 insertions(+), 3 deletions(-) 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_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_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_product_base.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +7 -1
@@ -4,8 +4,14 @@ obj-$(CONFIG_NBL_CORE) := nbl_core.o -nbl_core-objs += nbl_main.o +nbl_core-objs += nbl_channel/nbl_channel.o \ + nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ + nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ + nbl_core/nbl_dispatch.o \ + nbl_core/nbl_dev.o \ + nbl_main.o # Provide include files ccflags-y += -I$(srctree)/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/ +ccflags-y += -I$(srctree)/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw ccflags-y += -I$(srctree)/drivers/net/ethernet/nebula-matrix/nbl/
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +82 -0
82 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_CHANNEL_H_ +#define _NBL_CHANNEL_H_ + +#include "nbl_core.h" + +#define NBL_CHAN_MGT_TO_MBX (chan_mgt) \ + ((chan_mgt)->chan_info[NBL_CHAN_TYPE_MAILBOX]) +#define NBL_CHAN_MGT_TO_CHAN_INFO (chan_mgt, chan_type) \ + ((chan_mgt)->chan_info[chan_type]) + +struct nbl_chan_info { +u8 chan_type; + +}; + +struct nbl_channel_mgt { +struct nbl_common_info *common; +struct nbl_hw_ops_tbl *hw_ops_tbl; +struct nbl_chan_info *chan_info[NBL_CHAN_TYPE_MAX ]; +struct nbl_hash_tbl_mgt *handle_hash_tbl; +}; + +/* Mgt structure for each product. +* Every indivisual mgt must have the common mgt as its first member, and +* contains its unique data structure in the reset of it. +*/ +struct nbl_channel_mgt_leonis { +struct nbl_channel_mgt chan_mgt; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +58 -1
69 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +55 -0
55 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEV_H_ +#define _NBL_DEV_H_ + +#include "nbl_core.h" + +struct nbl_dev_mgt { +struct nbl_common_info *common; +struct nbl_dispatch_ops_tbl *disp_ops_tbl; +struct nbl_channel_ops_tbl *chan_ops_tbl; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +75 -0
75 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DISPATCH_H_ +#define _NBL_DISPATCH_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); +/* use for the caller not in interrupt */ +struct mutex ops_mutex_lock; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +143 -0
143 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_HW_LEONIS_H_ +#define _NBL_HW_LEONIS_H_ + +#include "nbl_include.h" +#include "nbl_hw_reg.h" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +90 -0
90 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_RESOURCE_LEONIS_H_ +#define _NBL_RESOURCE_LEONIS_H_ + +#include "nbl_resource.h" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +131 -0
131 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_RESOURCE_H_ +#define _NBL_RESOURCE_H_ + +#include "nbl_core.h" + +struct nbl_resource_info { +}; + +struct nbl_resource_mgt { +struct nbl_common_info *common; +struct nbl_resource_info *resource_info; +struct nbl_channel_ops_tbl *chan_ops_tbl; +struct nbl_hw_ops_tbl *hw_ops_tbl; +struct nbl_interrupt_mgt *intr_mgt; +}; + +/* Mgt structure for each product. +* Every indivisual mgt must have the common mgt as its first member, and +* contains its unique data structure in the reset of it. +*/ +struct nbl_resource_mgt_leonis { +struct nbl_resource_mgt res_mgt; +}; +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_CHANNEL_H_ +#define _NBL_DEF_CHANNEL_H_ + +#include <linux/if_ether.h> +#include "nbl_include.h" + +enum nbl_channel_type { +NBL_CHAN_TYPE_MAILBOX , +NBL_CHAN_TYPE_MAX +}; + +struct nbl_channel_ops { +}; + +struct nbl_channel_ops_tbl { +struct nbl_channel_ops *ops; +struct nbl_channel_mgt *priv; +}; + +#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. +* Author: +*/ + +#ifndef _NBL_DEF_COMMON_H_ +#define _NBL_DEF_COMMON_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_mode; + +u8 function; +u8 devid; +u8 bus; +u8 hw_bus; +u16 mgt_pf; + +bool pci_using_dac; +u8 is_ocp; +enum nbl_product_type product_type; +u8 is_ctrl; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_DEV_H_ +#define _NBL_DEF_DEV_H_ + +#include "nbl_include.h" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_DISPATCH_H_ +#define _NBL_DEF_DISPATCH_H_ + +#include "nbl_include.h" +struct nbl_dispatch_mgt ; +enum { +NBL_DISP_CTRL_LVL_NEVER =0 , +NBL_DISP_CTRL_LVL_MGT , +NBL_DISP_CTRL_LVL_NET , +NBL_DISP_CTRL_LVL_ALWAYS , +NBL_DISP_CTRL_LVL_MAX , +}; + +struct nbl_dispatch_ops { +}; + +struct nbl_dispatch_ops_tbl { +struct nbl_dispatch_ops *ops; +struct nbl_dispatch_mgt *priv; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_HW_H_ +#define _NBL_DEF_HW_H_ + +#include "nbl_include.h" +struct nbl_hw_mgt ; +struct nbl_hw_ops { +}; + +struct nbl_hw_ops_tbl { +struct nbl_hw_ops *ops; +struct nbl_hw_mgt *priv; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_RESOURCE_H_ +#define _NBL_DEF_RESOURCE_H_ + +#include "nbl_include.h" +struct nbl_resource_mgt ; + +struct nbl_resource_ops { +}; + +struct nbl_resource_ops_tbl { +struct nbl_resource_ops *ops; +struct nbl_resource_mgt *priv; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +12 -1
@@ -8,10 +8,15 @@#define _NBL_INCLUDE_H_#include <linux/types.h> - +#include <linux/netdevice.h> /* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl_core" +enum nbl_product_type { +NBL_LEONIS_TYPE , +NBL_PRODUCT_MAX , +}; +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
@@ -20,4 +25,10 @@ struct nbl_func_caps { u32 rsv:28; }; +struct nbl_init_param { +struct nbl_func_caps caps; +enum nbl_product_type product_type; +bool pci_using_dac; +}; +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_product_base.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_DEF_PRODUCT_BASE_H_ +#define _NBL_DEF_PRODUCT_BASE_H_ + +#include "nbl_include.h" +struct nbl_adapter ; +struct nbl_product_base_ops { +int (*hw_init)(struct nbl_adapter *p,struct nbl_init_param *param); +void (*hw_remove)(struct nbl_adapter *p); +int (*res_init)(struct nbl_adapter *p,struct nbl_init_param *param); +int (*chan_init)(struct nbl_adapter *p,struct nbl_init_param *param); +void (*chan_remove)(struct nbl_adapter *p); +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +180 -0
194 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: [PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 15
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+static int +nbl_chan_setup_chan_mgt (struct nbl_adapter *adapter, +struct nbl_init_param *param, +struct nbl_channel_mgt_leonis **chan_mgt_leonis)
It is pretty unusual to pass ** pointers. More normal would be
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 18
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+static struct nbl_channel_mgt_leonis * +nbl_chan_setup_chan_mgt (struct nbl_adapter *adapter, +struct nbl_init_param *param) +{ +struct nbl_hw_ops_tbl *hw_ops_tbl = adapter->intf.hw_ops_tbl; +struct nbl_common_info *common = &adapter->common;
struct nbl_channel_mgt_leonis *chan_mgt_leonis;
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +9
-0+struct device *dev = &adapter->pdev->dev; +struct nbl_chan_info *mailbox; + + chan_mgt_leonis =devm_kzalloc (dev, +sizeof (struct nbl_channel_mgt_leonis ), +GFP_KERNEL ); +if (!chan_mgt_leonis) + goto alloc_channel_mgt_leonis_fail; +
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 37
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+ chan_mgt_leonis->chan_mgt->common = common; + chan_mgt_leonis->chan_mgt.hw_ops_tbl = hw_ops_tbl; + + mailbox =devm_kzalloc (dev,sizeof (struct nbl_chan_info ),GFP_KERNEL ); +if (!mailbox) + goto alloc_mailbox_fail; + mailbox->chan_type =NBL_CHAN_TYPE_MAILBOX ; + chan_mgt_leonis->chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX ] = + mailbox; +
return chan_mgt_leonis;
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+alloc_mailbox_fail: +alloc_channel_mgt_leonis_fail: +return ERR_PTR (-ENOMEM );
This is starting to look like Linux driver code now. Lots of () have been removed. Your aim is to make the driver look like all other drivers in linux, by copying the common patterns.
I would probably also remove the two labels, and just due the return ERR_PTR() inline.
Please spend some time reading other drivers. Learn from them, and make your driver look like them.
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h line 22
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +5
-0+#define NBL_ADAP_TO_HW_MGT (adapter) ((adapter)->core.hw_mgt) +#define NBL_ADAP_TO_RES_MGT (adapter) ((adapter)->core.res_mgt) +#define NBL_ADAP_TO_DISP_MGT (adapter) ((adapter)->core.disp_mgt) +#define NBL_ADAP_TO_DEV_MGT (adapter) ((adapter)->core.dev_mgt) +#define NBL_ADAP_TO_CHAN_MGT (adapter) ((adapter)->core.chan_mgt)
I would suggest removing these. Just use adapter->core.chan_mgt directly in the code. Using macros normally means there is some magic involved, but this is just plain pointers, nothing magical.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 58
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +13
-0+int nbl_hw_init_leonis (struct nbl_adapter *adapter, +struct nbl_init_param *param) +{ +struct nbl_hw_ops_tbl **hw_ops_tbl = &adapter->intf.hw_ops_tbl; +struct nbl_common_info *common = &adapter->common; +struct nbl_hw_mgt_leonis **hw_mgt_leonis; +struct pci_dev *pdev = common->pdev; +struct nbl_hw_mgt *hw_mgt; +int bar_mask; +int ret =0 ; + + hw_mgt_leonis = + (struct nbl_hw_mgt_leonis **)&NBL_ADAP_TO_HW_MGT (adapter);
Why the cast? Cast like this suggest your data structure design is not correct.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 35
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +9
-0+static inline u32 rd32 (u8 __iomem *addr,u64 reg) +{ +return readl (addr + (reg)); +} + +static inline void wr32_barrier (u8 __iomem *addr,u64 reg,u32 value) +{ +writel ((value), (addr + (reg))); +}
Why _barrier here for write, but not for rd32()? readl() has a barrier same as writel()? Should rd32 actually be using readl_relaxed()?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 44
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +8
-0+static inline void nbl_hw_rd_regs (struct nbl_hw_mgt *hw_mgt,u64 reg,u8 *data, +u32 len) +{ +u32 size = len /4 ; +u32 i =0 ; + +if (len %4 ) +return ;
It is actually a bug?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 52
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +8
-0+ +spin_lock (&hw_mgt->reg_lock); + +for (i =0 ; i < size; i++) + *(u32 *)(data + i *sizeof (u32)) = +rd32 (hw_mgt->hw_addr, reg + i *sizeof (u32)); +spin_unlock (&hw_mgt->reg_lock); +}
This function is a bit big for inline. Have you used bloat-o-meter to look at the size with this and the next as functions vs inline?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +5
-0+static inline void nbl_hw_wr_regs (struct nbl_hw_mgt *hw_mgt,u64 reg, +const u8 *data,u32 len) +{ +u32 size = len /4 ; +u32 i =0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 68
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +10
-0+ +if (len %4 ) +return ; +spin_lock (&hw_mgt->reg_lock); +for (i =0 ; i < size; i++) +/* Used for emu, make sure that we won't write too frequently */ +wr32_barrier (hw_mgt->hw_addr, reg + i *sizeof (u32), + *(u32 *)(data + i *sizeof (u32))); +spin_unlock (&hw_mgt->reg_lock); +}
Andrew
Illusion Wang
maintainer回复:[PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture
Last time sam had a question
"
Thank you for your feedback. You might have misunderstood me. Our difficulties lie in the following:
1. Assuming only the mainline version changes the name (Assume name "nbl"), and our regularly released driver doesn't change its name, then when customers upgrade to a new kernel (containing the "nbl" driver), and then want to update our regularly released driver (named "nbl_core"), the module (ko) conflict will occur.
2. If both our mainline and regularly released drivers change their names, then customers who are already using the "nbl_core" driver will also encounter conflict issues when updating to the new driver "nbl".
Is it possible to do this: our net driver is also modified to be a driver based on the auxiliary bus, while the PCIe driver only handles PCIe-related processing, and these two drivers share a single kernel module (ko), namely "nbl_core"?"
There's no conclusion to this issue yet, so I haven't modified the 'core' parts for now (as mentioned in patch0)
--illusion.wang
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h line 22
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +5
-0+#define NBL_ADAP_TO_HW_MGT (adapter) ((adapter)->core.hw_mgt) +#define NBL_ADAP_TO_RES_MGT (adapter) ((adapter)->core.res_mgt) +#define NBL_ADAP_TO_DISP_MGT (adapter) ((adapter)->core.disp_mgt) +#define NBL_ADAP_TO_DEV_MGT (adapter) ((adapter)->core.dev_mgt) +#define NBL_ADAP_TO_CHAN_MGT (adapter) ((adapter)->core.chan_mgt)
I would suggest removing these. Just use adapter->core.chan_mgt directly in the code. Using macros normally means there is some magic involved, but this is just plain pointers, nothing magical.
------------------------------------------------------------------
发件人:Andrew Lunn <[email protected]>
发送时间:2026年2月6日(周五) 11:39
收件人:Illusion Wang<[email protected]>
抄 送:Dimon<[email protected]>; Alvin<[email protected]>; Sam<[email protected]>; netdev<[email protected]>; "andrew+netdev"<[email protected]>; corbet<[email protected]>; kuba<[email protected]>; "linux-doc"<[email protected]>; lorenzo<[email protected]>; pabeni<[email protected]>; horms<[email protected]>; "vadim.fedorenko"<[email protected]>; "lukas.bulwahn"<[email protected]>; edumazet<[email protected]>; open list<[email protected]> 主 题:Re: [PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 15
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+static int +nbl_chan_setup_chan_mgt (struct nbl_adapter *adapter, + struct nbl_init_param *param, + struct nbl_channel_mgt_leonis **chan_mgt_leonis)
It is pretty unusual to pass ** pointers. More normal would be
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 18
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+static struct nbl_channel_mgt_leonis * +nbl_chan_setup_chan_mgt (struct nbl_adapter *adapter, + struct nbl_init_param *param) +{ +struct nbl_hw_ops_tbl *hw_ops_tbl = adapter->intf.hw_ops_tbl; +struct nbl_common_info *common = &adapter->common;
struct nbl_channel_mgt_leonis *chan_mgt_leonis;
Quoted 9 lines
+ struct device *dev =
&adapter->pdev->dev;
+ structnbl_chan_info*mailbox;drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +7
-0+ + chan_mgt_leonis =devm_kzalloc (dev, + sizeof(struct nbl_channel_mgt_leonis), + GFP_KERNEL); +if (!chan_mgt_leonis) + goto alloc_channel_mgt_leonis_fail; +
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 37
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+ chan_mgt_leonis->chan_mgt->common = common; + chan_mgt_leonis->chan_mgt.hw_ops_tbl = hw_ops_tbl; + + mailbox =devm_kzalloc (dev,sizeof (struct nbl_chan_info ),GFP_KERNEL ); +if (!mailbox) + goto alloc_mailbox_fail; + mailbox->chan_type =NBL_CHAN_TYPE_MAILBOX ; + chan_mgt_leonis->chan_mgt->chan_info[NBL_CHAN_TYPE_MAILBOX ] = + mailbox; +
return chan_mgt_leonis;
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+alloc_mailbox_fail: +alloc_channel_mgt_leonis_fail: +return ERR_PTR (-ENOMEM );
This is starting to look like Linux driver code now. Lots of () have been removed. Your aim is to make the driver look like all other drivers in linux, by copying the common patterns.
I would probably also remove the two labels, and just due the return ERR_PTR() inline.
Please spend some time reading other drivers. Learn from them, and make your driver look like them.
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h line 22
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +5
-0+#define NBL_ADAP_TO_HW_MGT (adapter) ((adapter)->core.hw_mgt) +#define NBL_ADAP_TO_RES_MGT (adapter) ((adapter)->core.res_mgt) +#define NBL_ADAP_TO_DISP_MGT (adapter) ((adapter)->core.disp_mgt) +#define NBL_ADAP_TO_DEV_MGT (adapter) ((adapter)->core.dev_mgt) +#define NBL_ADAP_TO_CHAN_MGT (adapter) ((adapter)->core.chan_mgt)
I would suggest removing these. Just use adapter->core.chan_mgt directly in the code. Using macros normally means there is some magic involved, but this is just plain pointers, nothing magical.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 58
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c new file +13
-0+int nbl_hw_init_leonis (struct nbl_adapter *adapter, + struct nbl_init_param *param) +{ +struct nbl_hw_ops_tbl **hw_ops_tbl = &adapter->intf.hw_ops_tbl; +struct nbl_common_info *common = &adapter->common; +struct nbl_hw_mgt_leonis **hw_mgt_leonis; +struct pci_dev *pdev = common->pdev; +struct nbl_hw_mgt *hw_mgt; +int bar_mask; +int ret =0 ; + + hw_mgt_leonis = + (struct nbl_hw_mgt_leonis **)&NBL_ADAP_TO_HW_MGT(adapter);
Why the cast? Cast like this suggest your data structure design is not correct.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 35
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +9
-0+static inline u32 rd32 (u8 __iomem *addr,u64 reg) +{ +return readl (addr + (reg)); +} + +static inline void wr32_barrier (u8 __iomem *addr,u64 reg,u32 value) +{ +writel ((value), (addr + (reg))); +}
Why _barrier here for write, but not for rd32()? readl() has a barrier same as writel()? Should rd32 actually be using readl_relaxed()?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 44
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +8
-0+static inline void nbl_hw_rd_regs (struct nbl_hw_mgt *hw_mgt,u64 reg,u8 *data, + u32 len) +{ +u32 size = len /4 ; +u32 i =0 ; + +if (len %4 ) + return;
It is actually a bug?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 52
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +8
-0+ +spin_lock (&hw_mgt->reg_lock); + +for (i =0 ; i < size; i++) + *(u32 *)(data + i * sizeof(u32)) = + rd32(hw_mgt->hw_addr, reg + i * sizeof(u32)); +spin_unlock (&hw_mgt->reg_lock); +}
This function is a bit big for inline. Have you used bloat-o-meter to look at the size with this and the next as functions vs inline?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +5
-0+static inline void nbl_hw_wr_regs (struct nbl_hw_mgt *hw_mgt,u64 reg, + const u8 *data, u32 len) +{ +u32 size = len /4 ; +u32 i =0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h line 68
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h new file +10
-0+ +if (len %4 ) + return; +spin_lock (&hw_mgt->reg_lock); +for (i =0 ; i < size; i++) + /* Used for emu, make sure that we won't write too frequently */ + wr32_barrier(hw_mgt->hw_addr, reg + i * sizeof(u32), + *(u32 *)(data + i * sizeof(u32))); +spin_unlock (&hw_mgt->reg_lock); +}
Andrew
Re: 回复:[PATCH v4 net-next 02/11] net/nebula-matrix: add our driver architecture
Quoted 13 lines · Illusion Wang
Last time sam had a question
"
Thank you for your feedback. You might have misunderstood me. Our difficulties lie in the following:
1. Assuming only the mainline version changes the name (Assume name "nbl"), and our regularly released driver doesn't change its name, then when customers upgrade to a new kernel (containing the "nbl" driver), and then want to update our regularly released driver (named "nbl_core"), the module (ko) conflict will occur.
2. If both our mainline and regularly released drivers change their names, then customers who are already using the "nbl_core" driver will also encounter conflict issues when updating to the new driver "nbl".
Quoted 6 lines
Is it possible to do this: our net driver is also modified to be a driver based on the auxiliary bus, while the PCIe driver only handles PCIe-related processing, and these two drivers share a single kernel module (ko), namely "
nbl_core"?"There's no conclusion to this issue yet, so I haven't modified the 'core' parts for now (as mentioned in patch0)
This is all open source, you can do whatever you want with a fork of Linux and out of tree drivers. Mainline has no influence about what you do in your out of tree driver. So for Mainline, your out of tree vendor driver does not really exist, any problems with it are yours to solve.
However, Mainline cares about Mainline. We expect drivers which get merged follow Mainline design principles, look like other mainline drivers, and use naming consistent with other Mainline drivers.
You should also think about how this driver is going to be merged. It is going to be in small pieces. It is very unlikely the first merged patchset is actually useful for customers. You probably need quite a few patchset merged before the driver is useful. If you have customers who use Linus releases, they are going to have to deal with these WIP driver. Such customers will be building the kernel themselves, so can leave the in tree module out of the build. However, do most of your customers use a distribution? A distribution is not going to update its kernel until the next LTS kernel is release, sometime in December. By then, you might have something usable in Mainline, and the vendor driver is not needed. Or you might still be in the process of rewriting the driver to Mainline standards and it is not usable. Your customers then need to handle removing the mainline driver and use the vendor driver. Again, that is not Mainlines problem.
So, if your "core" driver is purely core, you can call it core, and give it an empty tristate. The other drivers which are layered on top of it can then select it.
If your "core" driver is actually an Ethernet driver, please drop the name core.
Andrew
Jakub Kicinski
maintainerRe: [v4,net-next,02/11] net/nebula-matrix: add our driver architecture
In reply to illusion.wangThis is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add our driver architecture
This commit introduces the nebula-matrix network driver architecture, consisting of multiple layers: Device, Dispatch, Resource, Hardware, Channel, and Common. The architecture is designed for code reusability across multiple chip variants.
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+static void nbl_get_func_param (struct pci_dev *pdev,kernel_ulong_t driver_data, +struct nbl_init_param *param) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c line 129
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+/* +* Leonis only PF0 has ctrl capability, but PF0's pcie device_id +* is same with other PF.So hanle it special.
^^^^^
This isn't a bug, but there's a typo: "hanle" should be "handle".
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1
-0+*/
illusion.wang
maintainerPATCH v4 3/11 net/nebula-matrix: add chip related definitions
In reply to illusion.wang1. nbl_hw.h/nbl_hw_leonis.h
chip-related reg definitions
2. nbl_hw_leonis_regs.c
P4 configuration that will be invoked during chip initialization
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_hw.h | 128 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 1172 ++++++- .../nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.c | 2902 +++++++++++++++++ .../nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h | 12 + 5 files changed, 4214 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_NBL_CORE) := nbl_core.o nbl_core-objs += 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_hw_leonis/nbl_hw_leonis_regs.o \ nbl_core/nbl_dispatch.o \ nbl_core/nbl_dev.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw.h new file +128 -0
128 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +1171 -1
1,178 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.c new file +2902 -0
1,687 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h new file +12 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.47.3
Part of the diff is not shown here. View the raw message.
Jakub Kicinski
maintainerRe: [v4,net-next,03/11] net/nebula-matrix: add chip related definitions
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add chip related definitions
This commit adds hardware register definitions for the Leonis chip, including PPE, DP, and interface module base addresses, as well as P4 configuration data used during chip initialization.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw.h line 1
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw.h new file +1
-0@@ -0,0 +1,128 @@ +/* SPDX-License-Identifier: GPL-2.0*/
This isn't a bug, but the SPDX license identifier is missing a space before the closing comment. The kernel standard format is:
/* SPDX-License-Identifier: GPL-2.0 */
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +0
-0
[ ... ]
Quoted 1 line
+#define
NBL_DP_UL4S_BASE(0x00204000)
[ ... ]
Quoted 1 line
+#define
NBL_DP_DL4S_BASE(0x00614000)
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +2
-0+#define NBL_DP_DL4S_BASE (0x00614000) +#define NBL_DP_UL4S_BASE (0x00204000)
NBL_DP_DL4S_BASE and NBL_DP_UL4S_BASE are defined twice in this file. While the values are identical, would it make sense to remove the duplicate definitions?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h line 414
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +6
-0+/* ---------- DSCH ---------- */ +/* DSCH vn_host_qid_max */ +#define NBL_DSCH_NOTIFY_BITMAP_ARR (i) \ + (NBL_DP_DSCH_BASE + 0x00003000 + (i) * BYTES_PER_DWORD) +#define NBL_DSCH_FLY_BITMAP_ARR (i) \ + (NBL_DP_DSCH_BASE + 0x00004000 + (i) * BYTES_PER_DWORD)
BYTES_PER_DWORD is not defined in this driver. Will this cause compilation errors when these macros are expanded? Consider defining BYTES_PER_DWORD or using the already-defined NBL_BYTES_IN_REG.
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h line 416
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +2
-0+#define NBL_DSCH_PORT_MAP_REG_ARR (i) \ + (NBL_DP_DSCH_BASE + 0x00005000 + (i) * sizeof(struct nbl_port_map))
struct nbl_port_map is referenced but not defined anywhere in the nebula-matrix driver. Is this type defined elsewhere, or is a definition missing?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h line 871
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +4
-0+/* epro epro_kgen_ft table */ +#define NBL_EPRO_KGEN_FT_TABLE (i) \ + (NBL_PPE_EPRO_BASE + 0x00001980 + \ + (i) * sizeof(struct nbl_epro_kgen_ft_tbl))
struct nbl_epro_kgen_ft_tbl is referenced but not defined in this driver. Is a definition missing for this type?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h line 1
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.h new file +1
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0*/
This isn't a bug, but the SPDX license identifier is missing a space before the closing comment. The kernel standard format is:
/* SPDX-License-Identifier: GPL-2.0 */
illusion.wang
maintainerPATCH v4 4/11 net/nebula-matrix: channel msg value and msg struct
In reply to illusion.wangFor compatibility, the msg id value is fixed, and each msg struct can only have fields added (not removed).
--- .../nbl/nbl_include/nbl_def_channel.h | 249 ++++++++++++++++++ 1 file changed, 249 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +249 -0
@@ -10,6 +10,255 @@#include <linux/if_ether.h> #include "nbl_include.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_ENABLE_IRQ , +NBL_CHAN_MSG_GET_GLOBAL_VECTOR , +NBL_CHAN_MSG_GET_VSI_ID , +NBL_CHAN_MSG_SET_PROSISC_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_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_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_CHECK_VF_IS_VDPA , +NBL_CHAN_MSG_GET_VDPA_VF_STATS , +NBL_CHAN_MSG_SET_RX_RATE , +NBL_CHAN_GET_UVN_PKT_DROP_STATS , +NBL_CHAN_GET_USTORE_PKT_DROP_STATS , +NBL_CHAN_GET_USTORE_TOTAL_PKT_DROP_STATS , +NBL_CHAN_MSG_SET_WOL , +NBL_CHAN_MSG_INIT_VF_MSIX_MAP , +NBL_CHAN_MSG_GET_ST_NAME , +NBL_CHAN_MSG_MTU_SET =501 , +NBL_CHAN_MSG_SET_RXFH_INDIR =506 , +NBL_CHAN_MSG_SET_RXFH_RSS_ALG_SEL =508 , +/* mailbox msg end */ +NBL_CHAN_MSG_MAILBOX_MAX , +}; + +struct nbl_chan_param_cfg_msix_map { +u16 num_net_msix; +u16 num_others_msix; +u16 msix_mask_en; +}; + +struct nbl_chan_param_enable_mailbox_irq { +u16 vector_id; +bool enable_msix; +}; + +struct nbl_chan_param_get_vsi_id { +u16 vsi_id; +u16 type; +}; + +struct nbl_chan_param_get_eth_id { +u16 vsi_id; +u8 eth_mode; +u8 eth_id; +u8 logic_eth_id; +}; +enum nbl_channel_type {NBL_CHAN_TYPE_MAILBOX ,NBL_CHAN_TYPE_MAX
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v4 5/11 net/nebula-matrix: add channel layer
In reply to illusion.wanga channel management layer provides structured approach to handle communication between different components and drivers. Here's a summary of its key functionalities:
1. Message Handling Framework
Message Registration/Unregistration: Functions (nbl_chan_register_msg, nbl_chan_unregister_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.
2. Channel Types and Queue Management
Mailbox Channel: For direct communication between PF0 and Other PF. Queue Initialization/Teardown: Functions (nbl_chan_init_queue, nbl_chan_teardown_queue) manage transmit (TX) and receive (RX) queues.
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 | 3 +- .../nbl/nbl_channel/nbl_channel.c | 790 ++++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 122 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 227 +++++ .../nebula-matrix/nbl/nbl_common/nbl_common.h | 28 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 101 +++ .../nbl/nbl_include/nbl_def_channel.h | 88 ++ .../nbl/nbl_include/nbl_def_common.h | 73 ++ .../nbl/nbl_include/nbl_def_hw.h | 26 + .../nbl/nbl_include/nbl_include.h | 7 +- 10 files changed, 1463 insertions(+), 2 deletions(-) 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 +2 -1
@@ -4,7 +4,8 @@ obj-$(CONFIG_NBL_CORE) := nbl_core.o -nbl_core-objs += nbl_channel/nbl_channel.o \ +nbl_core-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_hw_leonis/nbl_hw_leonis_regs.o \
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c +790 -0
842 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h +122 -0
133 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +227 -0
227 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_COMMON_H_ +#define _NBL_COMMON_H_ + +#include "nbl_def_common.h" + +/* list only need one bucket size */ +#define NBL_HASH_TBL_LIST_BUCKET_SIZE 1 + +struct nbl_hash_tbl_mgt { +struct nbl_hash_tbl_key tbl_key; +struct hlist_head *hash; +u16 node_num; +}; + +/* it used for y_axis no necessay */ +struct nbl_hash_entry_node { +struct hlist_node node; +void *key; +void *data; +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +101 -0
108 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +88 -0
112 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +73 -0
83 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +26 -0
@@ -10,6 +10,32 @@#include "nbl_include.h" struct nbl_hw_mgt ;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 (*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); +u32 (*get_real_bus)(struct nbl_hw_mgt *hw_mgt); + +void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +u16 bus,u16 devid,u16 function); +void (*enable_mailbox_irq)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool enable_msix,u16 global_vec_id); +u32 (*get_fw_eth_num)(struct nbl_hw_mgt *hw_mgt); +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_include.h +6 -1
@@ -11,7 +11,12 @@#include <linux/netdevice.h> /* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl_core" - +#define NBL_MAX_PF 8 +#define NBL_NEXT_ID (id, max) \ + ({ \ + typeof(id) _id = (id); \ + ((_id) == (max) ? 0 : (_id) + 1); \ + })enum nbl_product_type {NBL_LEONIS_TYPE ,NBL_PRODUCT_MAX ,
Signature · 1 line
2.47.3
Re: [PATCH v4 net-next 05/11] net/nebula-matrix: add channel layer
Quoted 11 lines
(quoted diff) +9
-0+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; + int ret = 0; + + NBL_HASH_TBL_KEY_INIT(&tbl_key, common->dev, sizeof(u16), + sizeof(struct nbl_chan_msg_node_data), + NBL_CHAN_HANDLER_TBL_BUCKET_SIZE);
Review
Quoted 10 lines
(quoted diff) +10
-0+#define NBL_HASH_TBL_KEY_INIT(key, dev_arg, key_size_arg, data_size_arg,\ + bucket_size_arg) \ +do { \ + typeof(key) __key = key; \ + __key->dev = dev_arg; \ + __key->key_size = key_size_arg; \ + __key->data_size = data_size_arg; \ + __key->bucket_size = bucket_size_arg; \ + __key->resv = 0; \ +} while (0)
Why a macro? This could be a function. I don't see anything magical here.
Andrew
Jakub Kicinski
maintainerRe: [v4,net-next,05/11] net/nebula-matrix: add channel layer
In reply to illusion.wangThis is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
Commit: cd2f89c6d9811cbe52e9e20513431e156bba29be
Author: illusion.wang <[email protected]>
Subject: net/nebula-matrix: add channel layer
This commit adds a channel management layer for communication between PFs including message handling framework, queue management, and hardware abstraction.
================================================================================
HIGH SEVERITY ISSUES
================================================================================
1. Buffer overflow risk in nbl_chan_recv_ack_msg
File: drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
Function: nbl_chan_recv_ack_msg
The ack_msgid.info.loc field is a 10-bit value with range 0-1023, but it's used directly as an array index into wait[] which only has 256 entries (NBL_CHAN_QUEUE_LEN). Can you add bounds checking before using this value as an array index?
Quoted 1 line
wait_head = &chan_info->wait[ack_msgid.info.loc];
Consider adding:
if (ack_msgid.info.loc >= NBL_CHAN_QUEUE_LEN) {
/* handle error */
return;
}2. Use-after-free in nbl_chan_delete_msg_handler
File: drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
Function: nbl_chan_delete_msg_handler
The hash node is freed before calling flush_work(), but the work function (chan_info->clean_task) may still be accessing this memory. Should the flush_work() call be moved before freeing the hash node?
Quoted 3 lines
nbl_common_free_hash_node(chan_mgt->handle_hash_tbl, &msg_type); [ ... ] flush_work(chan_info->clean_task);
The work function could be reading from the freed hash node, causing a use-after-free condition.
================================================================================
MEDIUM SEVERITY ISSUES
================================================================================
3. Inconsistent error handling in nbl_chan_send_msg
File: drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
Function: nbl_chan_send_msg
In polling mode, when a timeout occurs, the function sets the status to NBL_MBX_STATUS_TIMEOUT, logs an error, but returns 0 (success). This is inconsistent with interrupt mode which returns -EFAULT on timeout. Should polling mode also return an error code?
Quoted 3 lines
wait_head->status = NBL_MBX_STATUS_TIMEOUT; dev_err(dev, "Channel polling ack failed..."); return 0;
Consider returning -ETIMEDOUT or -EFAULT instead of 0.
4. Resource leak in nbl_common_alloc_hash_node
File: drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
Function: nbl_common_alloc_hash_node
On error paths, the function uses devm_kzalloc but doesn't free the allocated memory before returning. While devm_kzalloc memory is freed on device removal, this can cause memory to accumulate if this function fails repeatedly. Should the error paths explicitly free the allocated memory?
Quoted 3 lines
alloc_data_failed:alloc_key_failed:return -1;
Consider using devm_kfree() or switching to regular kzalloc/kfree if early cleanup is needed.
================================================================================
LOW SEVERITY ISSUES
================================================================================
5. Comment inaccuracy in nbl_common_calc_hash_key
File: drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
Function: nbl_common_calc_hash_key
The comment states "if bucket size little than 1" but the code checks for equality to 1, not less than 1. Should the comment be updated to match the actual check?
Quoted 2 lines
/* if bucket size little than 1, the hash value always 0 */ if (bucket_size == NBL_HASH_TBL_LIST_BUCKET_SIZE)
Perhaps the comment should read "if bucket size equals 1" or the check should be "bucket_size < 1" if that was the intent?
================================================================================
END OF REVIEW
================================================================================
illusion.wang
maintainerPATCH v4 6/11 net/nebula-matrix: add common resource implementation
In reply to illusion.wangThe 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.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 43 ++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 183 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 1 - .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 142 ++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 64 ++++++ .../nbl/nbl_include/nbl_def_common.h | 16 ++ .../nbl/nbl_include/nbl_def_resource.h | 13 ++ .../nbl/nbl_include/nbl_include.h | 7 + 9 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -9,6 +9,7 @@ nbl_core-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_hw_leonis/nbl_hw_leonis_regs.o \ + nbl_hw/nbl_resource.o \ nbl_core/nbl_dispatch.o \ nbl_core/nbl_dev.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +43 -0
63 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +183 -0
206 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +0 -1
@@ -8,5 +8,4 @@#define _NBL_RESOURCE_LEONIS_H_#include "nbl_resource.h" -#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +142 -0
142 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +64 -0
76 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +16 -0
@@ -9,6 +9,22 @@#include "nbl_include.h" struct nbl_hash_tbl_mgt ; +#define NBL_ONE_ETHERNET_PORT (1) +#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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +13 -0
@@ -11,6 +11,19 @@struct nbl_resource_mgt ;struct nbl_resource_ops { +int (*init_chip_module)(struct nbl_resource_mgt *res_mgt); +void (*deinit_chip_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); +int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id); +int (*enable_mailbox_irq)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vector_id,bool enable_msix); +u16 (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 type); +void (*get_eth_id)(struct nbl_resource_mgt *res_mgt,u16 vsi_id, +u8 *eth_mode,u8 *eth_id,u8 *logic_eth_id); };struct nbl_resource_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +7 -0
@@ -11,17 +11,24 @@#include <linux/netdevice.h> /* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl_core" +#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) \ ({ \ typeof(id) _id = (id); \ ((_id) == (max) ? 0 : (_id) + 1); \ }) +#define NBL_MAX_FUNC (520)enum nbl_product_type {NBL_LEONIS_TYPE ,NBL_PRODUCT_MAX , }; +enum { +NBL_VSI_DATA =0 , +NBL_VSI_MAX , +}; +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [v4,net-next,06/11] net/nebula-matrix: add common resource implementation
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add common resource implementation
This patch adds the common resource layer for the nebula-matrix network driver, implementing conversion relationships among vsi_id, func_id, eth_id, and pf_id.
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 26
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +12
-0+static void nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 vsi_id, +u8 *eth_mode,u8 *eth_id,u8 *logic_eth_id) +{ +struct nbl_eth_info *eth_info =NBL_RES_MGT_TO_ETH_INFO (res_mgt); +u16 pf_id =nbl_res_vsi_id_to_pf_id (res_mgt, vsi_id); + + *eth_mode = eth_info->eth_num; +if (pf_id < eth_info->eth_num) { + *eth_id = eth_info->eth_id[pf_id]; + *logic_eth_id = pf_id; +/* if pf_id > eth_num, use eth_id 0 */ + }else {
This isn't a bug, but the comment appears to be misplaced. It describes what happens in the else branch but is located inside the if branch. Should it be moved above the else?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +2
-0+static int nbl_res_ctrl_dev_setup_eth_info (struct nbl_resource_mgt *res_mgt) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c static int nbl_res_setup_ops(struct device *dev, · line 105
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +3
-0+for (i =0 ; i <NBL_RES_MGT_TO_PF_NUM (res_mgt); i++) { +/* if pf_id <= eth_num, the pf relate corresponding eth_id*/ +if (i < eth_num) {
This isn't a bug, but the comment says "pf_id <= eth_num" while the code checks "i < eth_num". Should the comment say "<" instead of "<="?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c static int nbl_res_setup_ops(struct device *dev, · line 110
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +5
-0+ eth_id = eth_info->eth_id[i]; + eth_info->pf_bitmap[eth_id] |=BIT (i); + } +/* if pf_id > eth_num, the pf relate eth 0*/ +else
Similarly, the comment says "pf_id > eth_num" but the else handles the case where "i >= eth_num". Should the comment say ">=" instead of ">"?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +2
-0+ eth_info->pf_bitmap[0 ] |=BIT (i); + }
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +0
-0
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +15
-0+static int vsi_id_to_pf_id (struct nbl_resource_mgt *res_mgt,u16 vsi_id) +{ +struct nbl_vsi_info *vsi_info =NBL_RES_MGT_TO_VSI_INFO (res_mgt); +struct nbl_common_info *common = res_mgt->common; +bool vsi_find = false; +u32 pf_id =U32_MAX ; +int i, j; + +for (i =0 ; i < vsi_info->num; i++) { +for (j =0 ; j <NBL_VSI_SERV_MAX_TYPE ; j++) +if (vsi_id >= vsi_info->serv_info[i][j].base_id && + (vsi_id < vsi_info->serv_info[i][j].base_id + + vsi_info->serv_info[i][j].num)) { + vsi_find = true; +break ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c line 67
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +10
-0+ } + +if (vsi_find) +break ; + } + +if (vsi_find) { +/* if pf_id < eth_num */ +if (j >=NBL_VSI_SERV_PF_DATA_TYPE && + j <=NBL_VSI_SERV_PF_DATA_TYPE )
This isn't a bug, but the comment says "if pf_id < eth_num" while the code checks if j equals NBL_VSI_SERV_PF_DATA_TYPE (which is 0). The comment does not seem to describe the actual condition being tested. Could it be updated to reflect what the code is checking?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +5
-0+ pf_id = i + common->mgt_pf; + } + +return pf_id; +}
illusion.wang
maintainerPATCH v4 7/11 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangMSI-X Interrupt Configuration:
Dynamically allocate and manage MSI-X interrupt vectors, including network interrupts and other types of interrupts. Interrupt Mapping Table Management: Maintain the MSI-X mapping table (msix_map_table) to establish interrupt associations between hardware and software.
Interrupt Enabling/Disabling:
Support enabling or disabling specific interrupts through hardware operations.
Interrupt Information Query: Provide interfaces to obtain the hardware register addresses and data of interrupts.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 71 ++++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 17 ++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 233 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 13 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 33 +++ .../nbl/nbl_include/nbl_include.h | 6 +- 7 files changed, 373 insertions(+), 1 deletion(-) 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
@@ -10,6 +10,7 @@ nbl_core-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.o \ nbl_hw/nbl_resource.o \ + nbl_hw/nbl_interrupt.o \ nbl_core/nbl_dispatch.o \ nbl_core/nbl_dev.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +71 -0
89 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +17 -0
@@ -34,6 +34,7 @@ static struct nbl_resource_ops res_ops = { .get_eth_id = nbl_res_get_eth_id, }; +static bool is_ops_inited;static int nbl_res_setup_res_mgt (struct nbl_common_info *common,struct nbl_resource_mgt_leonis **res_mgt_leonis)
@@ -61,15 +62,27 @@ static int nbl_res_setup_ops(struct device *dev,struct nbl_resource_ops_tbl **res_ops_tbl, struct nbl_resource_mgt_leonis *res_mgt_leonis) { + int ret = 0; + *res_ops_tbl =devm_kzalloc (dev,sizeof (struct nbl_resource_ops_tbl ),GFP_KERNEL );if (!*res_ops_tbl)return -ENOMEM ; +if (!is_ops_inited) { + ret =nbl_intr_setup_ops (&res_ops); +if (ret) + goto setup_fail; + is_ops_inited = true; + } + (*res_ops_tbl)->ops = &res_ops; (*res_ops_tbl)->priv = &res_mgt_leonis->res_mgt;return 0 ; + +setup_fail: +return -EAGAIN ; }static int nbl_res_ctrl_dev_setup_eth_info (struct nbl_resource_mgt *res_mgt)
@@ -228,6 +241,10 @@ static int nbl_res_start(struct nbl_resource_mgt_leonis *res_mgt_leonis, ret =nbl_res_ctrl_dev_vsi_info_init (res_mgt);if (ret) goto start_fail; + + ret =nbl_intr_mgt_start (res_mgt); +if (ret) + goto start_fail; }return 0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +233 -0
233 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0*/ +/* +* Copyright (c) 2025 Nebula Matrix Limited. +* Author: +*/ + +#ifndef _NBL_INTERRUPT_H_ +#define _NBL_INTERRUPT_H_ + +#include "nbl_resource.h" + +#define NBL_MSIX_MAP_TABLE_MAX_ENTRIES (1024) +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +33 -0
@@ -22,6 +22,37 @@ struct nbl_resource_mgt;#define NBL_RES_MGT_TO_PF_NUM (res_mgt) \ (NBL_RES_MGT_TO_RES_INFO(res_mgt)->max_pf) +/* --------- INTERRUPT ---------- */ +#define NBL_MAX_OTHER_INTERRUPT 1024 +#define NBL_MAX_NET_INTERRUPT 4096 + +struct nbl_msix_map { +u16 valid:1 ; +u16 global_msix_index:13 ; +u16 rsv:2 ; +}; + +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 msix_base; +u16 msix_max; +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;
@@ -89,6 +120,8 @@ int nbl_res_func_id_to_pfvfid(struct nbl_resource_mgt *res_mgt, u16 func_id, int *pfid, int *vfid);int nbl_res_func_id_to_bdf (struct nbl_resource_mgt *res_mgt,u16 func_id,u8 *bus,u8 *dev,u8 *function); +int nbl_intr_mgt_start (struct nbl_resource_mgt *res_mgt); +int nbl_intr_setup_ops (struct nbl_resource_ops *resource_ops);void 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_include.h +5 -1
@@ -11,14 +11,18 @@#include <linux/netdevice.h> /* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl_core" -#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) \ ({ \ typeof(id) _id = (id); \ ((_id) == (max) ? 0 : (_id) + 1); \ }) +#define NBL_MAX_FUNC (520) + +/* Used for macros to pass checkpatch */ +#define NBL_NAME (x) x +enum nbl_product_type {NBL_LEONIS_TYPE ,NBL_PRODUCT_MAX ,
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [v4,net-next,07/11] net/nebula-matrix: add intr resource implementation
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add intr resource implementation
This commit adds MSI-X interrupt resource management for the Nebula Matrix network driver, including interrupt vector allocation, mapping table maintenance, and hardware interrupt enable/disable operations.
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0
[ ... ]
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12
-0+static 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) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = res_mgt->common; +struct nbl_msix_map_table *msix_map_table; +struct nbl_msix_map *msix_map_entries; +struct device *dev = common->dev; +u16 requested, intr_index;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 75
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+u8 bus, devid, function; +bool msix_mask_en; +u16 *interrupts; +int ret =0 ; +u16 i; + +if (intr_mgt->func_intr_res[func_id].interrupts) +nbl_res_intr_destroy_msix_map (res_mgt, func_id); + +nbl_res_func_id_to_bdf (res_mgt, func_id, &bus, &devid, &function);
Should the return value of nbl_res_func_id_to_bdf() be checked here?
Looking at nbl_res_func_id_to_bdf(), it returns U32_MAX when func_id is invalid:
if (func_id >= NBL_RES_MGT_TO_PF_NUM(res_mgt) + ...)
return U32_MAX;When that happens, the output parameters bus, devid, and function are not written, leaving them uninitialized. These values are then passed to hw_ops->configure_msix_info() further down in the function.
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +2
-0+ + msix_map_table = &intr_mgt->func_intr_res[func_id].msix_map_table;
[ ... ]
illusion.wang
maintainerPATCH v4 8/11 net/nebula-matrix: add vsi resource implementation
In reply to illusion.wangThe HW (Hardware) layer code can have a quick review since it is highly chip-specific.
Chip initialization includes the initialization of the DP module, the intf module, and the P4 registers.
The initialization of the DP module encompasses the initialization of the dped(downstream pkt edit), uped(upstream pkt edit), dsch(downstream schedule), ustore, dstore, dvn, uvn, and uqm modules.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 407 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 6 +- .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_vsi.c | 54 +++ .../nebula-matrix/nbl/nbl_hw/nbl_vsi.h | 12 + .../nbl/nbl_include/nbl_def_hw.h | 4 + .../nbl/nbl_include/nbl_include.h | 31 ++ 8 files changed, 514 insertions(+), 2 deletions(-) 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
@@ -11,6 +11,7 @@ nbl_core-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis_regs.o \ nbl_hw/nbl_resource.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_hw/nbl_hw_leonis/nbl_hw_leonis.c +407 -0
419 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -2
@@ -71,6 +71,10 @@ static int nbl_res_setup_ops(struct device *dev,if (!is_ops_inited) { ret =nbl_intr_setup_ops (&res_ops); +if (ret) + goto setup_fail; + + ret =nbl_vsi_setup_ops (&res_ops);if (ret) goto setup_fail; is_ops_inited = true;
@@ -262,7 +266,6 @@ int nbl_res_init_leonis(struct nbl_adapter *adap, struct nbl_init_param *param)struct nbl_resource_mgt_leonis **mgt = (struct nbl_resource_mgt_leonis **)&NBL_ADAP_TO_RES_MGT (adap);struct device *dev = &adap->pdev->dev; -int ret =0 ; ret =nbl_res_setup_res_mgt (common, mgt);
@@ -279,7 +282,6 @@ int nbl_res_init_leonis(struct nbl_adapter *adap, struct nbl_init_param *param) ret =nbl_res_setup_ops (dev, res_ops_tbl, *mgt);if (ret) goto setup_ops_fail; -return 0 ; setup_ops_fail:
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +1 -0
@@ -122,6 +122,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_intr_mgt_start (struct nbl_resource_mgt *res_mgt);int nbl_intr_setup_ops (struct nbl_resource_ops *resource_ops); +int nbl_vsi_setup_ops (struct nbl_resource_ops *resource_ops);void 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_hw/nbl_vsi.c new file +54 -0
54 lines not on this page · raw message
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. +* Author: +*/ + +#ifndef _NBL_VSI_H_ +#define _NBL_VSI_H_ + +#include "nbl_resource.h" + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +4 -0
@@ -10,6 +10,10 @@#include "nbl_include.h" struct nbl_hw_mgt ;struct nbl_hw_ops { +int (*init_chip_module)(struct nbl_hw_mgt *hw_mgt,u8 eth_speed, +u8 eth_num); +void (*deinit_chip_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_include.h +31 -0
@@ -47,4 +47,35 @@ struct nbl_init_param { bool pci_using_dac; }; +enum nbl_fw_port_speed { +NBL_FW_PORT_SPEED_10G , +NBL_FW_PORT_SPEED_25G , +NBL_FW_PORT_SPEED_50G , +NBL_FW_PORT_SPEED_100G , +}; + +#define NBL_OPS_CALL (func, para) \ +do { \ + typeof(func) _func = (func); \ + if (_func) \ + _func para; \ +} while (0) + +#define NBL_OPS_CALL_RET (func, para) \ +({ \ + typeof(func) _func = (func); \ + _func ? _func para : 0; \ +}) + +#define NBL_OPS_CALL_RET_PTR (func, para) \ +({ \ + typeof(func) _func = (func); \ + _func ? _func para : NULL; \ +}) + +enum nbl_performance_mode { +NBL_QUIRKS_NO_TOE , +NBL_QUIRKS_UVN_PREFETCH_ALIGN , +}; +#endif
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [v4,net-next,08/11] net/nebula-matrix: add vsi resource implementation
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add vsi resource implementation
This patch adds vsi (virtual station interface) resource implementation to the nebula-matrix driver, including initialization for various chip modules such as dped, uped, dsch, ustore, dstore, dvn, uvn, and uqm.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +14
-0+static int nbl_ustore_init (struct nbl_hw_mgt *hw_mgt,u8 eth_num) +{ +struct nbl_ustore_port_drop_th drop_th; +struct ustore_pkt_len pkt_len; +int i; + +nbl_hw_rd_regs (hw_mgt,NBL_USTORE_PKT_LEN_ADDR , (u8 *)&pkt_len, +sizeof (pkt_len)); +/* min arp packet length 42 (14 + 28) */ + pkt_len.min =42 ; +nbl_hw_wr_regs (hw_mgt,NBL_USTORE_PKT_LEN_ADDR , (u8 *)&pkt_len, +sizeof (pkt_len)); + + drop_th.en =1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 163
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+if (eth_num ==1 ) + drop_th.disc_th =NBL_USTORE_SIGNLE_ETH_DROP_TH ; +else if (eth_num ==2 ) + drop_th.disc_th =NBL_USTORE_DUAL_ETH_DROP_TH ; +else + drop_th.disc_th =NBL_USTORE_QUAD_ETH_DROP_TH ; + +for (i =0 ; i <4 ; i++) +nbl_hw_wr_regs (hw_mgt,NBL_USTORE_PORT_DROP_TH_REG_ARR (i), + (u8 *)&drop_th,sizeof (drop_th));
Is the drop_th structure fully initialized before writing to hardware? The structure declaration doesn't initialize its fields, and only 'en' and 'disc_th' fields are set before the entire structure is written to hardware registers. Looking at the structure definition in nbl_hw_leonis.h:775, nbl_ustore_port_drop_th has a 19-bit reserved field 'rsv':
struct nbl_ustore_port_drop_th {
u32 disc_th : 12;
u32 rsv : 19;
u32 en : 1;
} __packed;The uninitialized 'rsv' field would contain undefined stack values when written to hardware.
Other similar structures in this patch use zero-initialization (e.g., nbl_shaping_dport, nbl_shaping_dvn_dport, dsch_vn_quanta). Would it be safer to initialize drop_th with '= { 0 }' to ensure all fields, including reserved bits, are zeroed?
[ ... ]
Andrew Lunn raised a concern in v3 about the NBL_CORE naming in the Kconfig (not modified in this commit):
https://lore.kernel.org/netdev/[email protected]/
"_CORE is a bit unusual for a driver. CORE is generally a library which is shared by a number of drivers. It does not have a tristate string, it is just selected by the drivers which need it."
The author acknowledged this feedback but indicated it is still under discussion. Will this naming issue be addressed in a follow-up patch?
illusion.wang
maintainerPATCH v4 9/11 net/nebula-matrix: add Dispatch layer implementation
In reply to illusion.wangThis patch can have a quick review, function is similar
The primary issue in the Dispatch layer is how to determine the routing approach
Two routing ways:
Dispatch Layer-> Resource Layer -> HW layer
The Dispatch Layer routes tasks to Resource Layer, which may interact with the HW Layer for hardware writes.
Dispatch Layer->Channel Layer
The Dispatch Layers redirects hooks to the Channel Layer.
The primary challenge at the Dispatch layer lies in determining the routing approach, namely, how to decide which interfaces should directly invoke the Resource layer's interfaces and which should transmit requests via channels to the management PF for processing.
To address this, a ctrl_lvl (control level) mechanism is established, which comprises two parts: the control level declared by each interface and the control level configured by the upper layer. The effect is that when the upper layer configures a specific control level, all interfaces declaring this level will directly call the Resource layer's interfaces; otherwise, they will send requests via channels.
For instance, consider a regular PF that possesses network (net) capabilities but lacks control (ctrl) capabilities. It will only configure NET_LVL at the Dispatch layer. In this scenario, all interfaces declaring NET_LVL will directly invoke the Resource layer's interfaces, while those declaring CTRL_LVL will send requests via channels to the management PF. Conversely, if it is the management PF, it will configure both NET_LVL and CTRL_LVL at the Dispatch layer. Consequently, interfaces declaring CTRL_LVL will also directly call the Resource layer's interfaces without sending requests via channels. This configuration logic can be dynamic.(nbl_disp_setup_ctrl_lvl)
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 417 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 29 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 12 + 3 files changed, 458 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +417 -0
@@ -6,6 +6,400 @@#include "nbl_dispatch.h" +static u16 nbl_disp_chan_get_vsi_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 func_id,u16 type) +{ +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; + + param.type = type; + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_GET_VSI_ID , + ¶m,sizeof (param), &result,sizeof (result),1 ); + chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); + +return result.vsi_id; +} + +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 *param; +struct nbl_chan_param_get_vsi_id result; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret =0 ; + + param = (struct nbl_chan_param_get_vsi_id *)data; + + result.vsi_id = +NBL_OPS_CALL_RET (res_ops->get_vsi_id, (p, src_id, param->type)); + +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 void nbl_disp_chan_get_eth_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vsi_id,u8 *eth_mode,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; + + param.vsi_id = vsi_id; + +NBL_CHAN_SEND (chan_send, common->mgt_pf,NBL_CHAN_MSG_GET_ETH_ID , + ¶m,sizeof (param), &result,sizeof (result),1 ); + chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); + + *eth_mode = result.eth_mode; + *eth_id = result.eth_id; + *logic_eth_id = result.logic_eth_id; +} + +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 device *dev = disp_mgt->common->dev; +struct nbl_chan_param_get_eth_id *param; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret =0 ; + + param = (struct nbl_chan_param_get_eth_id *)data; + +NBL_OPS_CALL (res_ops->get_eth_id, + (p, param->vsi_id, &result.eth_mode, &result.eth_id, + &result.logic_eth_id)); + +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_chip_module (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; + +NBL_OPS_CALL (res_ops->deinit_chip_module, (p)); +} + +static int nbl_disp_init_chip_module (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; + +return NBL_OPS_CALL_RET (res_ops->init_chip_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; + +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->configure_msix_map, p, +0 , 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 = num_net_msix; + param.num_others_msix = num_others_msix; + param.msix_mask_en = 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; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret; + + param = (struct nbl_chan_param_cfg_msix_map *)data; + + ret =NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->configure_msix_map, p, + src_id, param->num_net_msix, + param->num_others_msix, + param->msix_mask_en); +if (ret) + err =NBL_CHAN_RESP_ERR ; + +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_LOCK_RET (disp_mgt, res_ops->destroy_msix_map, p, + src_id); +if (ret) + err =NBL_CHAN_RESP_ERR ; + +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_enable_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_enable_mailbox_irq param = {0 }; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send; + + param.vector_id = vector_id; + param.enable_msix = enable_msix; + +NBL_CHAN_SEND (chan_send, common->mgt_pf, +NBL_CHAN_MSG_MAILBOX_ENABLE_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_enable_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_enable_mailbox_irq *param; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =NBL_CHAN_RESP_OK ; +int ret; + + param = (struct nbl_chan_param_enable_mailbox_irq *)data; + + ret =NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->enable_mailbox_irq, p, + src_id, param->vector_id, + param->enable_msix); +if (ret) + err =NBL_CHAN_RESP_ERR ; + +NBL_CHAN_ACK (chan_ack, src_id,NBL_CHAN_MSG_MAILBOX_ENABLE_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_ENABLE_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; + +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->destroy_msix_map, p,0 ); +} + +static int nbl_disp_enable_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; + +return NBL_OPS_CALL_LOCK_RET (disp_mgt, res_ops->enable_mailbox_irq, p, +0 , vector_id, enable_msix); +} + +static u16 nbl_disp_get_vsi_id (struct nbl_dispatch_mgt *disp_mgt,u16 func_id, +u16 type) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; + +return NBL_OPS_CALL_RET (res_ops->get_vsi_id, (p, func_id, type)); +} + +static void nbl_disp_get_eth_id (struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_mode,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; + +NBL_OPS_CALL (res_ops->get_eth_id, + (p, vsi_id, eth_mode, 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. +* Use X Macros to reduce codes in channel_op and disp_op setup/remove +*/ +#define NBL_DISP_OPS_TBL \ +do { \ + NBL_DISP_SET_OPS(init_chip_module, nbl_disp_init_chip_module, \ + NBL_DISP_CTRL_LVL_MGT, -1, NULL, NULL); \ + NBL_DISP_SET_OPS(deinit_chip_module, \ + nbl_disp_deinit_chip_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(enable_mailbox_irq, \ + nbl_disp_enable_mailbox_irq, \ + NBL_DISP_CTRL_LVL_MGT, \ + NBL_CHAN_MSG_MAILBOX_ENABLE_IRQ, \ + nbl_disp_chan_enable_mailbox_irq_req, \ + nbl_disp_chan_enable_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 ; + +if (!chan_ops->check_queue_exist (disp_mgt->chan_ops_tbl->priv, +NBL_CHAN_TYPE_MAILBOX )) +return 0 ; + +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); \ + 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);\ +} while (0) +NBL_DISP_OPS_TBL ; +#undef NBL_DISP_SET_OPS + +return ret; +} + +/* Ctrl lvl means that if a certain level is set, then all disp_ops that +* decleared this lvl will go directly to res_ops, rather than send a +* channel msg, and vice versa. +*/ +static int nbl_disp_setup_ctrl_lvl (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) +{ +struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; + +set_bit (lvl, disp_mgt->ctrl_lvl); + +#define NBL_DISP_SET_OPS (disp_op, func, ctrl, msg_type, msg_req, msg_resp) \ +do { \ + typeof(msg_type) _msg_type = (msg_type); \ + (void)(_msg_type); \ + (void)(msg_resp); \ + disp_ops->NBL_NAME(disp_op) = \ + test_bit(ctrl, disp_mgt->ctrl_lvl) ? func : msg_req; \ +} while (0) +NBL_DISP_OPS_TBL ; +#undef NBL_DISP_SET_OPS + +return 0 ; +} +static int nbl_disp_setup_disp_mgt (struct nbl_common_info *common,struct nbl_dispatch_mgt **disp_mgt) {
@@ -67,7 +461,30 @@ int nbl_disp_init(struct nbl_adapter *adapter, struct nbl_init_param *param) (*disp_mgt)->res_ops_tbl = res_ops_tbl; (*disp_mgt)->chan_ops_tbl = chan_ops_tbl; (*disp_mgt)->disp_ops_tbl = *disp_ops_tbl; + + ret =nbl_disp_setup_msg (*disp_mgt); +if (ret) + goto setup_msg_fail; + +if (param->caps.has_ctrl) { + ret =nbl_disp_setup_ctrl_lvl (*disp_mgt,NBL_DISP_CTRL_LVL_MGT ); +if (ret) + goto setup_msg_fail; + } + +if (param->caps.has_net) { + ret =nbl_disp_setup_ctrl_lvl (*disp_mgt,NBL_DISP_CTRL_LVL_NET ); +if (ret) + goto setup_msg_fail; + } + + ret =nbl_disp_setup_ctrl_lvl (*disp_mgt,NBL_DISP_CTRL_LVL_ALWAYS ); +if (ret) + goto setup_msg_fail; +return 0 ; + +setup_msg_fail: setup_ops_fail: setup_mgt_fail:return ret;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h +29 -0
@@ -9,6 +9,35 @@#include "nbl_core.h" +#define NBL_OPS_CALL_LOCK (disp_mgt, func, ...) \ +do { \ + typeof(disp_mgt) _disp_mgt = (disp_mgt); \ + typeof(func) _func = (func); \ + \ + mutex_lock(&_disp_mgt->ops_mutex_lock); \ + \ + if (_func) \ + _func(__VA_ARGS__); \ + \ + mutex_unlock(&_disp_mgt->ops_mutex_lock); \ +} while (0) + +#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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +12 -0
@@ -18,6 +18,18 @@ enum { };struct nbl_dispatch_ops { +int (*init_chip_module)(struct nbl_dispatch_mgt *disp_mgt); +void (*deinit_chip_module)(struct nbl_dispatch_mgt *disp_mgt); +int (*configure_msix_map)(struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt); +int (*enable_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool enable_msix); +u16 (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt,u16 func_id, +u16 type); +void (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_mode,u8 *eth_id,u8 *logic_eth_id); };struct nbl_dispatch_ops_tbl {
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v4 10/11 net/nebula-matrix: add common/ctrl dev init/reinit operation
In reply to illusion.wangCommon Device Setup: nbl_dev_setup_common_dev configures mailbox queues, registers cleanup tasks, and requests IRQs.
Control Device Setup (optional): nbl_dev_setup_ctrl_dev initializes the chip and configures all channel queues.
--- .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 178 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 35 ++++ 2 files changed, 213 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +178 -0
@@ -6,6 +6,164 @@#include "nbl_dev.h" +static void nbl_dev_register_common_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; + + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; +} + +/* ---------- Channel config ---------- */ +static int nbl_dev_setup_chan_qinfo (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv; +struct device *dev = dev_mgt->common->dev; +int ret =0 ; + +if (!chan_ops->check_queue_exist (priv, chan_type)) +return 0 ; + + ret = chan_ops->cfg_chan_qinfo_map_table (priv, chan_type); +if (ret) +dev_err (dev,"setup chan:%d, qinfo map table failed\n" , + chan_type); + +return ret; +} + +static int nbl_dev_setup_chan_queue (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv; +int ret =0 ; + +if (chan_ops->check_queue_exist (priv, chan_type)) + ret = chan_ops->setup_queue (priv, chan_type); + +return ret; +} + +static int nbl_dev_remove_chan_queue (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv; +int ret =0 ; + +if (chan_ops->check_queue_exist (priv, chan_type)) + ret = chan_ops->teardown_queue (priv, chan_type); + +return ret; +} + +static void nbl_dev_register_chan_task (struct nbl_dev_mgt *dev_mgt, +u8 chan_type,struct work_struct *task) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; + +if (chan_ops->check_queue_exist (dev_mgt->chan_ops_tbl->priv, chan_type)) + chan_ops->register_chan_task (dev_mgt->chan_ops_tbl->priv, + chan_type, task); +} + +/* ---------- Tasks config ---------- */ +static void nbl_dev_clean_mailbox_task (struct work_struct *work) +{ +struct nbl_dev_common *common_dev = + container_of(work, struct nbl_dev_common, clean_mbx_task); +struct nbl_dev_mgt *dev_mgt = common_dev->dev_mgt; +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; + + chan_ops->clean_queue_subtask (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_TYPE_MAILBOX ); +} + +/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter, +struct nbl_init_param *param) +{ +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dispatch_mgt *priv = dev_mgt->disp_ops_tbl->priv; +struct nbl_common_info *common = dev_mgt->common; +struct nbl_dev_common *common_dev; + + common_dev =devm_kzalloc (&adapter->pdev->dev, +sizeof (struct nbl_dev_common ),GFP_KERNEL ); +if (!common_dev) +return -ENOMEM ; + common_dev->dev_mgt = dev_mgt; + +if (nbl_dev_setup_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX )) + goto setup_chan_fail; + +INIT_WORK (&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task); + common->vsi_id = disp_ops->get_vsi_id (priv,0 ,NBL_VSI_DATA ); + disp_ops->get_eth_id (priv, common->vsi_id, + &common->eth_mode, &common->eth_id, + &common->logic_eth_id); + +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX , + &common_dev->clean_mbx_task); + + dev_mgt->common_dev = common_dev; +nbl_dev_register_common_irq (dev_mgt); +return 0 ; + +setup_chan_fail: +return -EFAULT ; +} + +static void nbl_dev_remove_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); +struct nbl_dev_common *common_dev = dev_mgt->common_dev; + +if (!common_dev) +return ; + +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +} + +static int nbl_dev_setup_ctrl_dev (struct nbl_adapter *adapter, +struct nbl_init_param *param) +{ +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +int i, ret =0 ; + + ret = disp_ops->init_chip_module (dev_mgt->disp_ops_tbl->priv); +if (ret) + goto chip_init_fail; + +for (i =0 ; i <NBL_CHAN_TYPE_MAX ; i++) { + ret =nbl_dev_setup_chan_qinfo (dev_mgt, i); +if (ret) + goto setup_chan_q_fail; + } + +return 0 ; +setup_chan_q_fail: + disp_ops->deinit_chip_module (dev_mgt->disp_ops_tbl->priv); +chip_init_fail: +return ret; +} + +static void nbl_dev_remove_ctrl_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; + + disp_ops->deinit_chip_module (dev_mgt->disp_ops_tbl->priv); +} +static int nbl_dev_setup_dev_mgt (struct nbl_common_info *common,struct nbl_dev_mgt **dev_mgt) {
@@ -35,13 +193,33 @@ int nbl_dev_init(struct nbl_adapter *adapter, struct nbl_init_param *param) (*dev_mgt)->disp_ops_tbl = disp_ops_tbl; (*dev_mgt)->chan_ops_tbl = chan_ops_tbl; + + ret =nbl_dev_setup_common_dev (adapter, param); +if (ret) + goto setup_common_dev_fail; + +if (common->is_ctrl) { + ret =nbl_dev_setup_ctrl_dev (adapter, param); +if (ret) + goto setup_ctrl_dev_fail; + } +return 0 ; + +setup_ctrl_dev_fail: +nbl_dev_remove_common_dev (adapter); +setup_common_dev_fail: setup_mgt_fail:return ret; }void nbl_dev_remove (struct nbl_adapter *adapter) { +struct nbl_common_info *common = &adapter->common; + +if (common->is_ctrl) +nbl_dev_remove_ctrl_dev (adapter); +nbl_dev_remove_common_dev (adapter); }/* ---------- Dev start process ---------- */
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h +35 -0
@@ -9,10 +9,45 @@#include "nbl_core.h" +#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | \ + NETIF_MSG_LINK | NETIF_MSG_IFDOWN | \ + NETIF_MSG_IFUP) + +#define NBL_STRING_NAME_LEN 32 + +enum nbl_msix_serv_type { +/* virtio_dev has a config vector_id, and the vector_id need is 0 */ +NBL_MSIX_VIRTIO_TYPE =0 , +NBL_MSIX_NET_TYPE , +NBL_MSIX_MAILBOX_TYPE , +NBL_MSIX_TYPE_MAX +}; + +struct nbl_msix_serv_info { +char irq_name[NBL_STRING_NAME_LEN ]; +u16 num; +u16 base_vector_id; +/* true: hw report msix, hw need to mask actively */ +bool hw_self_mask_en; +}; + +struct nbl_msix_info { +struct nbl_msix_serv_info serv_info[NBL_MSIX_TYPE_MAX ]; +}; + +struct nbl_dev_common { +struct nbl_dev_mgt *dev_mgt; +struct nbl_msix_info msix_info; +char mailbox_name[NBL_STRING_NAME_LEN ]; +// for ctrl-dev/net-dev mailbox recv msg +struct work_struct clean_mbx_task; +}; +struct nbl_dev_mgt {struct nbl_common_info *common;struct nbl_dispatch_ops_tbl *disp_ops_tbl;struct nbl_channel_ops_tbl *chan_ops_tbl; +struct nbl_dev_common *common_dev; };#endif
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [v4,net-next,10/11] net/nebula-matrix: add common/ctrl dev init/reinit operation
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add common/ctrl dev init/reinit operation
This commit adds initialization and teardown operations for common and control devices, including mailbox queue setup, cleanup task registration, and chip module initialization.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 15
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +7
-0@@ -6,6 +6,164 @@#include "nbl_dev.h" +static void nbl_dev_register_common_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; + + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; +}
This isn't a bug, but the commit message states "registers cleanup tasks, and requests IRQs." The function nbl_dev_register_common_irq() only sets msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num = 1, which is MSI-X configuration, not IRQ registration. No request_irq(), devm_request_irq(), or similar calls appear in the patch. The function name is also misleading as it suggests IRQ registration but only performs counter initialization.
[ ... ]
illusion.wang
maintainerPATCH v4 11/11 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangstart common dev: config msix map table, alloc and enable msix vectors, register mailbox ISR and enable mailbox irq
--- .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 241 +++++++++++++++++- .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 33 ++- 2 files changed, 272 insertions(+), 2 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +240 -1
@@ -6,6 +6,17 @@#include "nbl_dev.h" +static int nbl_dev_clean_mailbox_schedule (struct nbl_dev_mgt *dev_mgt); + +/* ---------- Interrupt config ---------- */ +static irqreturn_t nbl_dev_clean_mailbox (int __always_unused irq,void *data) +{ +struct nbl_dev_mgt *dev_mgt = (struct nbl_dev_mgt *)data; + +nbl_dev_clean_mailbox_schedule (dev_mgt); +return IRQ_HANDLED ; +} +static void nbl_dev_register_common_irq (struct nbl_dev_mgt *dev_mgt) {struct nbl_dev_common *dev_common = dev_mgt->common_dev;
@@ -14,6 +25,179 @@ static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; } +static int nbl_dev_request_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +struct nbl_common_info *common = dev_mgt->common; +u16 local_vec_id; +u32 irq_num; +int err; + +if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num) +return 0 ; + + local_vec_id = + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; + irq_num =pci_irq_vector (common->pdev, local_vec_id); + +snprintf (dev_common->mailbox_name,sizeof (dev_common->mailbox_name), +"nbl_mailbox@pci:%s" ,pci_name (common->pdev)); + err =request_irq (irq_num, nbl_dev_clean_mailbox,0 , + dev_common->mailbox_name, dev_mgt); +if (err) +return err; + +return 0 ; +} + +static void nbl_dev_free_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +struct nbl_common_info *common = dev_mgt->common; +u16 local_vec_id; +u32 irq_num; + +if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num) +return ; + + local_vec_id = + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; + irq_num =pci_irq_vector (common->pdev, local_vec_id); + +free_irq (irq_num, dev_mgt); +} + +static int nbl_dev_enable_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +u16 local_vec_id; + +if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num) +return 0 ; + + local_vec_id = + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; + chan_ops->set_queue_state (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_INTERRUPT_READY , +NBL_CHAN_TYPE_MAILBOX , true); + +return disp_ops->enable_mailbox_irq (dev_mgt->disp_ops_tbl->priv, + local_vec_id, true); +} + +static int nbl_dev_disable_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +u16 local_vec_id; + +if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num) +return 0 ; + +flush_work (&dev_common->clean_mbx_task); + local_vec_id = + msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; + chan_ops->set_queue_state (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_INTERRUPT_READY , +NBL_CHAN_TYPE_MAILBOX , false); + +return disp_ops->enable_mailbox_irq (dev_mgt->disp_ops_tbl->priv, + local_vec_id, false); +} + +static int nbl_dev_configure_msix_map (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +bool mask_en = msix_info->serv_info[NBL_MSIX_NET_TYPE ].hw_self_mask_en; +u16 msix_net_num = msix_info->serv_info[NBL_MSIX_NET_TYPE ].num; +u16 msix_not_net_num =0 ; +int err, i; + +for (i =NBL_MSIX_NET_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) + msix_info->serv_info[i].base_vector_id = + msix_info->serv_info[i -1 ].base_vector_id + + msix_info->serv_info[i -1 ].num; + +for (i =NBL_MSIX_MAILBOX_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) { +if (i ==NBL_MSIX_NET_TYPE ) +continue ; + + msix_not_net_num += msix_info->serv_info[i].num; + } + + err = disp_ops->configure_msix_map (dev_mgt->disp_ops_tbl->priv, + msix_net_num, msix_not_net_num, + mask_en); + +return err; +} + +static int nbl_dev_destroy_msix_map (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; + +return disp_ops->destroy_msix_map (dev_mgt->disp_ops_tbl->priv); +} + +static int nbl_dev_alloc_msix_intr (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +struct nbl_common_info *common = dev_mgt->common; +int needed =0 ; +int err; +int i; + +for (i =0 ; i <NBL_MSIX_TYPE_MAX ; i++) + needed += msix_info->serv_info[i].num; + + err =pci_alloc_irq_vectors (common->pdev, needed, needed, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); +if (err <0 ) { +pr_err ("pci_enable_msix_range failed, err = %d.\n" , err); + goto enable_msix_failed; + } + +return needed; + +enable_msix_failed: +return err; +} + +static void nbl_dev_free_msix_intr (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_common_info *common = dev_mgt->common; + +pci_free_irq_vectors (common->pdev); +} + +static int nbl_dev_init_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +int err =0 ; + + err =nbl_dev_alloc_msix_intr (dev_mgt); +if (err <0 ) { +dev_err (dev_mgt->common->dev, +"Failed to enable MSI-X vectors\n" ); +return err; + } +return 0 ; +} + +static void nbl_dev_clear_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +nbl_dev_free_msix_intr (dev_mgt); +} +/* ---------- Channel config ---------- */ static int nbl_dev_setup_chan_qinfo (struct nbl_dev_mgt *dev_mgt,u8 chan_type) {
@@ -79,6 +263,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work) NBL_CHAN_TYPE_MAILBOX); } +static int nbl_dev_clean_mailbox_schedule (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *common_dev = dev_mgt->common_dev; + +nbl_common_queue_work (&common_dev->clean_mbx_task); +return 0 ; +} +/* ---------- Dev init process ---------- */ static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter,struct nbl_init_param *param)
@@ -223,11 +415,58 @@ void nbl_dev_remove(struct nbl_adapter *adapter) }/* ---------- Dev start process ---------- */ -int nbl_dev_start (struct nbl_adapter *adapter,struct nbl_init_param *param) + +static int nbl_dev_start_common_dev (struct nbl_adapter *adapter, +struct nbl_init_param *param) { +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); +int ret; + + ret =nbl_dev_configure_msix_map (dev_mgt); +if (ret) + goto config_msix_map_err; + + ret =nbl_dev_init_interrupt_scheme (dev_mgt); +if (ret) + goto init_interrupt_scheme_err; + ret =nbl_dev_request_mailbox_irq (dev_mgt); +if (ret) + goto mailbox_request_irq_err; + ret =nbl_dev_enable_mailbox_irq (dev_mgt); +if (ret) + goto enable_mailbox_irq_err;return 0 ; +enable_mailbox_irq_err: +nbl_dev_free_mailbox_irq (dev_mgt); +mailbox_request_irq_err: +nbl_dev_clear_interrupt_scheme (dev_mgt); +init_interrupt_scheme_err: +nbl_dev_destroy_msix_map (dev_mgt); +config_msix_map_err: +return ret; +} + +static void nbl_dev_stop_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = + (struct nbl_dev_mgt *)NBL_ADAP_TO_DEV_MGT (adapter); + +nbl_dev_disable_mailbox_irq (dev_mgt); +nbl_dev_free_mailbox_irq (dev_mgt); +nbl_dev_clear_interrupt_scheme (dev_mgt); +nbl_dev_destroy_msix_map (dev_mgt); +} + +int nbl_dev_start (struct nbl_adapter *adapter,struct nbl_init_param *param) +{ +int ret; + + ret =nbl_dev_start_common_dev (adapter, param); +return ret; }void nbl_dev_stop (struct nbl_adapter *adapter) { +nbl_dev_stop_common_dev (adapter); }
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +32 -1
@@ -283,7 +283,38 @@ static struct pci_driver nbl_driver = { .remove = nbl_remove, }; -module_pci_driver (nbl_driver); +static int __init nbl_module_init (void ) +{ +int status; + + status =nbl_common_create_wq (); +if (status) { +pr_err ("Failed to create wq, err = %d\n" , status); + goto wq_create_failed; + } + status =pci_register_driver (&nbl_driver); +if (status) { +pr_err ("Failed to register PCI driver, err = %d\n" , status); + goto pci_register_driver_failed; + } +pr_info ("nbl module loaded\n" ); +return 0 ; + +pci_register_driver_failed: +nbl_common_destroy_wq (); +wq_create_failed: +return status; +} + +static void __exit nbl_module_exit(void) +{ +pci_unregister_driver (&nbl_driver); +nbl_common_destroy_wq (); + +pr_info ("nbl module unloaded\n" ); +} +module_init (nbl_module_init); +module_exit (nbl_module_exit);MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Nebula Matrix Network Driver" );
Signature · 1 line
2.47.3
Jakub Kicinski
maintainerRe: [v4,net-next,11/11] net/nebula-matrix: add common dev start/stop operation
This is an AI-generated review of your patch. The human sending this email says "This is an automated AI code reviewer, please treat what it says with a grain of salt."
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---net/nebula-matrix: add common dev start/stop operation
This commit adds MSI-X interrupt initialization for the common device layer, including configuring MSI-X vector mappings, allocating interrupt resources, and registering mailbox interrupt handlers.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +1
-0@@ -14,6 +25,179 @@ static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; } +static int nbl_dev_request_mailbox_irq (struct nbl_dev_mgt *dev_mgt)
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+static int nbl_dev_configure_msix_map (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) · line 128
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_msix_info *msix_info = &dev_common->msix_info; +bool mask_en = msix_info->serv_info[NBL_MSIX_NET_TYPE ].hw_self_mask_en; +u16 msix_net_num = msix_info->serv_info[NBL_MSIX_NET_TYPE ].num; +u16 msix_not_net_num =0 ; +int err, i; + +for (i =NBL_MSIX_NET_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) + msix_info->serv_info[i].base_vector_id = + msix_info->serv_info[i -1 ].base_vector_id + + msix_info->serv_info[i -1 ].num;
^^^^^^
Does this loop cause an array underflow? NBL_MSIX_NET_TYPE equals 0 (from the enum in nbl_dev.h), so on the first iteration i=0 and the code accesses serv_info[-1].
The serv_info array is declared with NBL_MSIX_TYPE_MAX (2) elements in struct nbl_msix_info, giving valid indices [0,1]. Accessing index -1 reads uninitialized memory before the array start.
Call chain: nbl_core_start()->nbl_dev_start()->nbl_dev_start_common_dev() ->nbl_dev_configure_msix_map() guarantees this occurs during device start.
Should the loop start at i=1 (NBL_MSIX_MAILBOX_TYPE) instead, or should serv_info[0].base_vector_id be initialized before the loop?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+ +for (i =NBL_MSIX_MAILBOX_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) {
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +6
-0+static int nbl_dev_alloc_msix_intr (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; +struct nbl_common_info *common = dev_mgt->common; +int needed =0 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) · line 166
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+int err; +int i; + +for (i =0 ; i <NBL_MSIX_TYPE_MAX ; i++) + needed += msix_info->serv_info[i].num; + + err =pci_alloc_irq_vectors (common->pdev, needed, needed, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); +if (err <0 ) { +pr_err ("pci_enable_msix_range failed, err = %d.\n" , err);
^^^^^^^^
This isn't a bug, but the error message says "pci_enable_msix_range failed" while the actual function being called is pci_alloc_irq_vectors.
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+ goto enable_msix_failed; + }
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-1@@ -283,7 +283,38 @@ static struct pci_driver nbl_driver = { .remove = nbl_remove, }; -module_pci_driver (nbl_driver); +static int __init nbl_module_init (void ) +{ +int status; + + status =nbl_common_create_wq (); +if (status) {
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static struct pci_driver nbl_driver = { · line 301
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+pr_err ("Failed to create wq, err = %d\n" , status); + goto wq_create_failed; + } + status =pci_register_driver (&nbl_driver); +if (status) { +pr_err ("Failed to register PCI driver, err = %d\n" , status); + goto pci_register_driver_failed; + } +pr_info ("nbl module loaded\n" ); +return 0 ;
Previous review feedback from Andrew Lunn on v3 noted that the config is named 'NBL_CORE' and the module is named 'nbl_core'. He pointed out that '_CORE' naming is unusual for a driver - CORE is typically a library shared by multiple drivers. The Kconfig still shows:
config NBL_CORE
tristate "Nebula-matrix Ethernet Controller m18100 Family support"
Should this be renamed to follow the naming convention for standalone drivers?
Andrew Lunn also noted in v3 that variable declarations should follow reverse Christmas tree ordering (longest line first). Looking at functions in this commit like nbl_dev_request_mailbox_irq():
struct nbl_dev_common *dev_common = dev_mgt->common_dev; struct nbl_msix_info *msix_info = &dev_common->msix_info; struct nbl_common_info *common = dev_mgt->common;
the declarations are not in reverse Christmas tree order.
Illusion Wang
maintainer回复:[v4,net-next,11/11] net/nebula-matrix: add common dev start/stop operation
Thank you for your feedback
But
enum nbl_msix_serv_type {
/* virtio_dev has a config vector_id, and the vector_id need is 0 */
NBL_MSIX_VIRTIO_TYPE = 0,
NBL_MSIX_NET_TYPE,
NBL_MSIX_MAILBOX_TYPE,
NBL_MSIX_TYPE_MAX
};NBL_MSIX_NET_TYPE equals 1,so this function has no problem?
--illusion.wang
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+static int nbl_dev_configure_msix_map (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) · line 128
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_msix_info *msix_info = &dev_common->msix_info; +bool mask_en = msix_info->serv_info[NBL_MSIX_NET_TYPE ].hw_self_mask_en; +u16 msix_net_num = msix_info->serv_info[NBL_MSIX_NET_TYPE ].num; +u16 msix_not_net_num =0 ; +int err, i; + +for (i =NBL_MSIX_NET_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) + msix_info->serv_info[i].base_vector_id = + msix_info->serv_info[i - 1].base_vector_id + + msix_info->serv_info[i - 1].num;
^^^^^^
Does this loop cause an array underflow? NBL_MSIX_NET_TYPE equals 0 (from the enum in nbl_dev.h), so on the first iteration i=0 and the code accesses serv_info[-1].
The serv_info array is declared with NBL_MSIX_TYPE_MAX (2) elements in struct nbl_msix_info, giving valid indices [0,1]. Accessing index -1 reads uninitialized memory before the array start.
Call chain: nbl_core_start()->nbl_dev_start()->nbl_dev_start_common_dev() ->nbl_dev_configure_msix_map() guarantees this occurs during device start.
Should the loop start at i=1 (NBL_MSIX_MAILBOX_TYPE) instead, or should serv_info[0].base_vector_id be initialized before the loop?
Quoted 2 lines
+
+ for (i =NBL_MSIX_MAILBOX_TYPE; i <NBL_MSIX_TYPE_MAX; i++) {
[ ... ]
Thank you for pointing this out! Upon reviewing the code again, I believe the variable declarations in nbl_dev_request_mailbox_irq() already follow the reverse Christmas tree convention:
dev_common (longest identifier) is declared first, as it is required for subsequent declarations.
The remaining variables (msix_info and common) are ordered by decreasing dentifier length, aligning with the style guide.
However, I appreciate the clarification opportunity—if there’s a nuance I’m missing (e.g., stricter adherence to identifier length over dependency order), I’d be happy to adjust the code accordingly.creasing identifier length, aligning with the style guide.
---illusion.wang
Andrew Lunn also noted in v3 that variable declarations should follow reverse Christmas tree ordering (longest line first). Looking at functions in this commit like nbl_dev_request_mailbox_irq():
struct nbl_dev_common *dev_common = dev_mgt->common_dev; struct nbl_msix_info *msix_info = &dev_common->msix_info; struct nbl_common_info *common = dev_mgt->common;
the declarations are not in reverse Christmas tree order.
Re: 回复:[v4,net-next,11/11] net/nebula-matrix: add common dev start/stop operation
Quoted 10 lines · Illusion Wang
Thank you for your feedback
Butenum nbl_msix_serv_type { /* virtio_dev has a config vector_id, and the vector_id need is 0 */ NBL_MSIX_VIRTIO_TYPE = 0, NBL_MSIX_NET_TYPE, NBL_MSIX_MAILBOX_TYPE, NBL_MSIX_TYPE_MAX };
NBL_MSIX_NET_TYPEequals 1,so this function has no problem?
Please don't top post.
Quoted 18 lines
--illusion.wang
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+static int nbl_dev_configure_msix_map (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dev_common *dev_common = dev_mgt->common_dev;drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_register_common_irq(struct nbl_dev_mgt *dev_mgt) · line 128
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_msix_info *msix_info = &dev_common->msix_info; +bool mask_en = msix_info->serv_info[NBL_MSIX_NET_TYPE ].hw_self_mask_en; +u16 msix_net_num = msix_info->serv_info[NBL_MSIX_NET_TYPE ].num; +u16 msix_not_net_num =0 ; +int err, i; + +for (i =NBL_MSIX_NET_TYPE ; i <NBL_MSIX_TYPE_MAX ; i++) + msix_info->serv_info[i].base_vector_id = + msix_info->serv_info[i - 1].base_vector_id + + msix_info->serv_info[i - 1].num;^^^^^^
Quoted 7 lines
Does this loop cause an array underflow?
NBL_MSIX_NET_TYPEequals 0 (from the enum innbl_dev.h), so on the first iteration i=0 and the code accesses serv_info[-1].The
serv_infoarray is declared withNBL_MSIX_TYPE_MAX(2) elements in structnbl_msix_info, giving valid indices [0,1]. Accessing index -1 reads uninitialized memory before the array start.
It is interesting it has the enum wrong. Given what you show, NBL_MSIX_NET_TYPE is 1, NBL_MSIX_TYPE_MAX 3. But it seems to be missing NBL_MSIX_VIRTIO_TYPE.
The tool does go backwards and forwards with the different patches. Does nbl_msix_serv_type always have the values you show, or does it start with less members and more are added in later patches? That might of confused it, or you as you broke the driver up any less big parts.
However, this code does look error prone. What would happen if a new value was added between _VIRTIO_TYPE an _NET_TYPE?
Safer would be:
for (i = NBL_MSIX_NET_TYPE; i < NBL_MSIX_TYPE_MAX; i++) msix_info->serv_info[i].base_vector_id = msix_info->serv_info[i - NBL_MSIX_NET_TYPE].base_vector_id + msix_info->serv_info[i - NBL_MSIX_NET_TYPE].num;
But i also wounder why your design needs to do this shuffling? It seems like a bad design.
Andrew