Skip to contentSkip to conversation

nbl driver for Nebulamatrix NICs

PATCH Superseded illusion.wang 2 participants 10 messages Nov 2 – Nov 5

Subsystems (3)

v33 of 35 Superseded Latest is v35 →

lore
Share & tools
lore

illusion.wang

author maintainer
#0 lore raw

v33 cover nbl driver for Nebulamatrix NICs

This series continues and refines the previous v28 NBL NIC driver patch set for Nebula-matrix m18110/m18000 (SNIC s1000) Ethernet adapters.

The first two foundational patches of v28 have been merged into net-next main branch:
- net/nebula-matrix: add minimum nbl build framework (cffde9e49e86)
- net/nebula-matrix: add core driver architecture and HW layer initialization (825e6d230163)

Following maintainer feedback to shorten the patch series, this iteration drops the two merged commits, reorganizes and polishes the remaining functionality into a standalone 8-patch sequence. No new features are added; this series only completes the pending core infrastructure.

The overall driver development plan remains consistent with the v28 two-phase roadmap:
1) Complete hardware initialization, mailbox/channel communication and control-plane infrastructure (this series)
2) Implement netdev registration and TX/RX data-path functionality (follow-up series)

This patch set supplements the merged foundational code, covering channel layer abstraction, resource management, interrupt handling, chip-level initialization, control dispatch routing, channel RPC framework, and device lifecycle init/remove/start/stop logic.

changes v32->v33
Link to v32:https://lore.kernel.org/netdev/[email protected]/ changes v31->v32
Link to v31:https://lore.kernel.org/netdev/[email protected]/ changes v30->v31
Link to v30:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v29->v30
Link to v29:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v28->v29
Link to v28:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.remove the hash table implementation

illusion wang (8):
net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add chip-wide hardware init/deinit implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: implement channel RPC framework and
serialize hardware ops
net/nebula-matrix: add common/ctrl dev init/remove operation net/nebula-matrix: add common dev start/stop operation

 .../net/ethernet/nebula-matrix/nbl/Makefile   |   10 +-
 .../nbl/nbl_channel/nbl_channel.c             | 1528 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  196 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |   52 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   14 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   20 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      |  727 ++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |   55 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c |  671 ++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |   23 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |   32 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |   12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 1286 +++++++++++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  342 ++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  370 ++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   12 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   33 +
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  |  851 +++++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |   21 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   |  157 ++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  159 ++
 .../nbl/nbl_include/nbl_def_channel.h         |  175 ++
 .../nbl/nbl_include/nbl_def_common.h          |   23 +
 .../nbl/nbl_include/nbl_def_dev.h             |   16 +
 .../nbl/nbl_include/nbl_def_dispatch.h        |   83 +
 .../nbl/nbl_include/nbl_def_hw.h              |   80 +
 .../nbl/nbl_include/nbl_def_resource.h        |   38 +
 .../nbl/nbl_include/nbl_include.h             |   28 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  289 +++-
 29 files changed, 7280 insertions(+), 23 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_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/nbl_dev.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_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_interrupt.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_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_resource.h
Signature · 1 line
2.51.0.windows.1
author maintainer
#1 lore raw

PATCH v33 1/8 net/nebula-matrix: add channel layer

From: illusion wang <[email protected]>

Add a mailbox-based channel layer that carries control messages between PF0 and the other PFs, providing the inter-PF control transport the rest of the driver builds on.

The channel ops table is defined here; queue setup, RX interrupt/polling processing and the upper-layer callers are wired up in later patches of this series.

Implementation notes:
- Message handlers live in an xarray, giving lockless lookup and duplicate-registration rejection (xa_insert returns -EBUSY). Both fire-and-forget and synchronous ACK-based sends are supported.
- ACK wait-slot exhaustion returns -EAGAIN; a full TX descriptor ring returns -EBUSY. Payloads are inline (up to 16 B) or DMA-based (up to 4032 B).
- The per-slot data buffers of each ring are carved out of one contiguous coherent DMA block, so those buffers cost one devres node and one IOMMU mapping per ring instead of one per slot. That is the only part of the ring which is collapsed: the descriptor ring is a second coherent allocation of its own, and the buf[]/wait[] bookkeeping arrays are devm_kcalloc() nodes.
- Mailbox queue resources are devm-managed and the DMA is allocated once during setup. There is no free path, so a channel is set up exactly once per device lifetime and teardown is terminal for it; a re-setup is rejected with -EBUSY.
- RX is driven either from the interrupt or by polling, with cleanup offloaded to a workqueue. Teardown quiesces both queues before the rings can be freed.
- Register access goes through hw_ops. The reg_lock spinlock covers BAR0 register access only; BAR2 mailbox registers and the doorbell write do not take it.

This patch also adds nbl_probe_chip_deps() and calls it from nbl_probe() before nbl_core_init(). For every PF that is not the physical function 0 (has_ctrl == 0) it resolves function 0 in the same slot and:

- fails the probe with -ENODEV if function 0 is absent, and also when the lookup resolves to this device itself: a VF is never the management PF, yet under ARI its devfn decodes to function 0 of a slot;
- returns -EPROBE_DEFER unless function 0 is bound to *this* driver with its probe completed. Testing links.status == DL_DEV_DRIVER_BOUND alone would also accept function 0 on vfio-pci or pci-stub through driver_override, where the chip-global setup this PF depends on never ran, so the bound driver is compared as well;
- creates a persistent DL_FLAG_AUTOPROBE_CONSUMER device link, so the driver core unbinds every sibling PF before function 0 goes away and re-probes them when function 0 binds again.

Function 0's device lock is only ever taken with device_trylock(): this probe already runs under device_lock(funcN), so a blocking device_lock(func0) would establish the N -> 0 order while __pci_bus_lock() (AER recovery, slot reset) walks the bus in devfn order, 0 -> N, and dev->mutex is lockdep_set_novalidate_class() so lockdep cannot report the inversion. The link is created while that lock is still held, so function 0 can neither bind nor unbind in between.

A failed trylock is retried a bounded number of times before the probe is deferred. The retry is needed because a single failure is not
self-healing: function 0 binds with device_lock(func0) held and driver_bound() calls driver_deferred_probe_trigger() before releasing it, so the deferred probe work can reach this probe while the lock is still taken. driver_probe_device() only re-arms that work when deferred_trigger_count changes during the probe, and it does not here, so a bare -EPROBE_DEFER would leave this PF on deferred_probe_pending_list with nothing scheduled to run it again. The wait is bounded rather than a plain device_lock() because device_lock(funcN) is held throughout, so waiting indefinitely would deadlock against __pci_bus_lock(); giving up and deferring releases it and lets the other side make progress. A holder that is not part of a bind - __pci_bus_lock() during AER recovery or a bus/slot reset, pci_reset_function() through sysfs, an sriov_numvfs write - can outlast the budget and no bind event follows those, so the sibling PF then stays deferred until some unrelated driver binding elsewhere re-triggers deferred probing.

Nothing here consumes the ordering yet - setup_queue() and cfg_chan_qinfo_map_table() still have no callers - but the later init/remove and start/stop patches do. Note the cost: with function 0 bound to another driver (e.g. vfio-pci) a sibling PF stays deferred for as long as that holds, with only a dev_dbg() record, and a function 0 that is simply absent fails the probe outright.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |    4 +-
 .../nbl/nbl_channel/nbl_channel.c             | 1528 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  196 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |   30 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.h |   14 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |    7 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  299 +++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |   41 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   32 +
 .../nbl/nbl_include/nbl_def_channel.h         |  125 ++
 .../nbl/nbl_include/nbl_def_common.h          |    3 +
 .../nbl/nbl_include/nbl_def_hw.h              |   42 +
 .../nbl/nbl_include/nbl_include.h             |    3 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  190 +-
 14 files changed, 2496 insertions(+), 18 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_common/nbl_common.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
index cc060cf8..04e1aa1f 100644
@@ -3,5 +3,7 @@
 
 obj-$(CONFIG_NBL) := nbl.o
 
-nbl-objs +=	nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
+nbl-objs +=	nbl_common/nbl_common.o \
+		nbl_channel/nbl_channel.o \
+		nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +1528 -0

1,528 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +196 -0

196 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +30 -0
new file mode 100644
index 00000000..181da46b
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#include <linux/device.h>
+#include "nbl_common.h"
+
+void nbl_common_destroy_wq(struct nbl_common_info *common)
+{
+	if (!common || !common->wq)
+		return;
+
+	destroy_workqueue(common->wq);
+	common->wq = NULL;
+}
+
+int nbl_common_create_wq(struct nbl_common_info *common)
+{
+	char wq_name[32];
+
+	snprintf(wq_name, sizeof(wq_name), "nbl_wq_%s", pci_name(common->pdev));
+	common->wq = alloc_workqueue(wq_name, WQ_UNBOUND, 0);
+	if (!common->wq) {
+		dev_err(common->dev, "Failed to alloc workqueue %s\n", wq_name);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +14 -0
new file mode 100644
index 00000000..129073b0
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_COMMON_H_
+#define _NBL_COMMON_H_
+
+#include <linux/types.h>
+
+#include "../nbl_include/nbl_include.h"
+#include "../nbl_include/nbl_def_common.h"
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +7 -0
index 1cd6587a..f998a2b4 100644
@@ -14,13 +14,20 @@ enum {
 	NBL_CAP_HAS_NET_BIT,
 };
 
+struct nbl_interface {
+	struct nbl_hw_ops_tbl *hw_ops_tbl;
+	struct nbl_channel_ops_tbl *channel_ops_tbl;
+};
+
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
+	struct nbl_channel_mgt *chan_mgt;
 };
 
 struct nbl_adapter {
 	struct pci_dev *pdev;
 	struct nbl_core core;
+	struct nbl_interface intf;
 	struct nbl_common_info common;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +287 -12

379 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +41 -0

46 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +32 -0
index e281109f..4c1bb789 100644
@@ -8,6 +8,7 @@
 
 #include <linux/types.h>
 
+#include "../nbl_include/nbl_def_channel.h"
 #include "../nbl_include/nbl_def_hw.h"
 #include "../nbl_include/nbl_def_common.h"
 #include "../nbl_core.h"
@@ -26,6 +27,37 @@ struct nbl_hw_mgt {
 	u8 __iomem *hw_addr;
 	u8 __iomem *mailbox_bar_hw_addr;
 	resource_size_t mailbox_bar_size;
+	spinlock_t reg_lock; /* Protect reg access */
 };
 
+static inline u32 rd32(u8 __iomem *addr, u64 reg)
+{
+	return readl(addr + reg);
+}
+
+static inline void wr32(u8 __iomem *addr, u64 reg, u32 value)
+{
+	writel(value, addr + reg);
+}
+
+static inline void nbl_hw_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
+{
+	wr32(hw_mgt->hw_addr, reg, value);
+}
+
+static inline u32 nbl_hw_rd32(struct nbl_hw_mgt *hw_mgt, u64 reg)
+{
+	return rd32(hw_mgt->hw_addr, reg);
+}
+
+static inline void nbl_mbx_wr32(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 value)
+{
+	writel(value, hw_mgt->mailbox_bar_hw_addr + reg);
+}
+
+static inline u32 nbl_mbx_rd32(struct nbl_hw_mgt *hw_mgt, u64 reg)
+{
+	return readl(hw_mgt->mailbox_bar_hw_addr + reg);
+}
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +125 -0

125 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +3 -0
index ea646d1e..fda11330 100644
@@ -12,6 +12,7 @@
 #include "nbl_include.h"
 
 struct nbl_common_info {
+	struct workqueue_struct *wq;
 	struct pci_dev *pdev;
 	struct device *dev;
 	u16 vsi_id;
@@ -28,4 +29,6 @@ struct nbl_common_info {
 	u8 has_net;
 };
 
+void nbl_common_destroy_wq(struct nbl_common_info *common);
+int nbl_common_create_wq(struct nbl_common_info *common);
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +42 -0

48 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +3 -0
index 14e7b19f..f2d80239 100644
@@ -10,6 +10,9 @@
 
 /*  ------  Basic definitions  -------  */
 #define NBL_DRIVER_NAME					"nbl"
+#define NBL_MAX_PF					8
+#define NBL_NEXT_ID(id, max) (((id) + 1) % ((max) + 1))
+
 struct nbl_func_caps {
 	u32 has_ctrl:1;
 	u32 has_net:1;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +185 -5

244 lines not on this page · raw message

Signature · 1 line
2.51.0.windows.1
author maintainer
#2 lore raw

PATCH v33 2/8 net/nebula-matrix: add common resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add chip-agnostic resource layer to manage PF topology, SR-IOV BDF, Ethernet port and VSI identity mappings, providing reusable conversion helpers for the Nebula Matrix driver control plane.
This patch implements core resource initialization and lookup logic, running exclusively on the control PF and building read-only resource tables once during probe:
- nbl_res_init_pf_num(): parse firmware PF mask and validate supported topologies. Only contiguous 1/2/4 PFs starting from PF0 are permitted, rejecting invalid/sparse configurations with early probe failure.
- nbl_common_func_id_to_rel_pf_id(): convert absolute PF function ID to relative PF index for consistent resource table indexing.
- nbl_res_ctrl_dev_sriov_info_init(): calculate and store per-PF BDF entries based on hardware PCI bus number for MSI-X programming.
- nbl_res_ctrl_dev_setup_eth_info(): verify firmware port count and Ethernet bitmap consistency, then construct per-PF eth_id lookup table. logic_eth_id is computed on-the-fly from relative PF ID instead of table lookup.
- nbl_res_ctrl_dev_vsi_info_init(): assign staggered per-PF VSI base IDs with gaps of 1024, 512 and 256 for 1, 2 and 4 port modes.
- Implement VSI/PF/Eth ID conversion helpers with strict control PF validity and range guards.
All resource tables are initialized once at control PF probe time and remain read-only afterwards, so lookup helpers require no internal locking. Upper-layer serialization via mutex and non-control PF mailbox RPC routing will be introduced in later series patches.
All resource memory allocations use devm managed semantics, requiring no explicit cleanup in the remove path.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   2 +
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |  22 ++
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  |  80 ++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  15 +
 .../nbl_hw_leonis/nbl_resource_leonis.c       | 335 ++++++++++++++++++
 .../nbl_hw_leonis/nbl_resource_leonis.h       |  10 +
 .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h     |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   | 125 +++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  69 ++++
 .../nbl/nbl_include/nbl_def_channel.h         |  10 +
 .../nbl/nbl_include/nbl_def_common.h          |  20 ++
 .../nbl/nbl_include/nbl_def_hw.h              |  26 ++
 .../nbl/nbl_include/nbl_def_resource.h        |  29 ++
 .../nbl/nbl_include/nbl_include.h             |   6 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 16 files changed, 759 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
index 04e1aa1f..3dab9519 100644
@@ -6,4 +6,6 @@ obj-$(CONFIG_NBL) := nbl.o
 nbl-objs +=	nbl_common/nbl_common.o \
 		nbl_channel/nbl_channel.o \
 		nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
+		nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
+		nbl_hw/nbl_resource.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +22 -0
index 181da46b..302c3c48 100644
@@ -28,3 +28,25 @@ int nbl_common_create_wq(struct nbl_common_info *common)
 
 	return 0;
 }
+
+/**
+ * nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id
+ * @common: common device info
+ * @pf_id: absolute PF identifier
+ * @rel_pf_id: output relative pf id
+ *
+ * Leonis uses fixed mgt_pf = 0. Support future non-zero management PF.
+ *
+ * Return: 0 on success, -EINVAL on invalid arguments.
+ */
+int nbl_common_func_id_to_rel_pf_id(struct nbl_common_info *common, u32 pf_id,
+				    u32 *rel_pf_id)
+{
+	if (!rel_pf_id)
+		return -EINVAL;
+
+	if (pf_id < common->mgt_pf)
+		return -EINVAL;
+	*rel_pf_id = pf_id - common->mgt_pf;
+	return 0;
+}
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index f998a2b4..dd24ebec 100644
@@ -16,11 +16,13 @@ enum {
 
 struct nbl_interface {
 	struct nbl_hw_ops_tbl *hw_ops_tbl;
+	struct nbl_resource_ops_tbl *resource_ops_tbl;
 	struct nbl_channel_ops_tbl *channel_ops_tbl;
 };
 
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
+	struct nbl_resource_mgt *res_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +78 -2

115 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +15 -0
index 93e5c751..251dd68d 100644
@@ -51,6 +51,21 @@ struct nbl_mailbox_qinfo_cfg_table {
 
 /*  --------  HOST_PCIE  --------  */
 #define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004)
+#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040)
+
+#define NBL_PCIE_BUS_MASK	GENMASK(12, 5)
+#define NBL_FW_BOARD_CONFIG			0x200
+#define NBL_FW_BOARD_DW3_OFFSET			(NBL_FW_BOARD_CONFIG + 12)
+#define NBL_FW_BOARD_DW6_OFFSET			(NBL_FW_BOARD_CONFIG + 24)
+
+#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0)
+#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1)
+#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8)
+#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10)
+#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13)
+
+#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0)
+#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8)
 
 #define NBL_BAR2_MAX_LEN		0x300
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +335 -0

335 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +10 -0
new file mode 100644
index 00000000..b9355262
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_RESOURCE_LEONIS_H_
+#define _NBL_RESOURCE_LEONIS_H_
+
+#include "../nbl_resource.h"
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +1 -0
index 4c1bb789..00fa33ee 100644
@@ -17,6 +17,7 @@
 #define NBL_MAILBOX_BAR				2
 #define NBL_RDMA_NOTIFY_LEN			(8ULL << 10)
 #define NBL_REG_NET_ONLY_LEN			(8ULL << 10)
+#define NBL_HW_DUMMY_REG			0x1300904
 /*
  * PCI MEMORY BAR total size: 64MiB.
  */
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +125 -0

125 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +69 -0

69 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +10 -0
index d6faa0bc..bf971121 100644
@@ -39,6 +39,16 @@ enum nbl_chan_state {
 	NBL_CHAN_STATE_NBITS
 };
 
+struct nbl_board_port_info {
+	u8 eth_num;
+	u8 eth_speed;
+	u8 p4_version;
+	u8 rsv[5];
+};
+
+static_assert(sizeof(struct nbl_board_port_info) == 8,
+	      "nbl_board_port_info size must be 8 bytes");
+
 struct nbl_chan_send_info {
 	void *arg;
 	size_t arg_len;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +20 -0
index fda11330..3e18a2a9 100644
@@ -11,6 +11,22 @@
 #include <linux/device.h>
 #include "nbl_include.h"
 
+#define NBL_TWO_ETHERNET_PORT			2
+#define NBL_FOUR_ETHERNET_PORT			4
+#define NBL_DEFAULT_VSI_ID_GAP			1024
+#define NBL_TWO_ETHERNET_VSI_ID_GAP		512
+#define NBL_FOUR_ETHERNET_VSI_ID_GAP		256
+
+static inline u32 nbl_vsi_id_gap(u32 m)
+{
+	if (m == NBL_FOUR_ETHERNET_PORT)
+		return NBL_FOUR_ETHERNET_VSI_ID_GAP;
+	else if (m == NBL_TWO_ETHERNET_PORT)
+		return NBL_TWO_ETHERNET_VSI_ID_GAP;
+
+	return NBL_DEFAULT_VSI_ID_GAP;
+}
+
 struct nbl_common_info {
 	struct workqueue_struct *wq;
 	struct pci_dev *pdev;
@@ -24,11 +40,15 @@ struct nbl_common_info {
 	u8 devid;
 	u8 bus;
 	u8 hw_bus;
+	u16 mgt_pf;
 
 	u8 has_ctrl;
 	u8 has_net;
+	u8 max_pf;
 };
 
 void nbl_common_destroy_wq(struct nbl_common_info *common);
 int nbl_common_create_wq(struct nbl_common_info *common);
+int nbl_common_func_id_to_rel_pf_id(struct nbl_common_info *common, u32 pf_id,
+				    u32 *rel_pf_id);
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +26 -0
index 6cb84371..08ce19b0 100644
@@ -8,9 +8,22 @@
 
 #include <linux/types.h>
 
+struct nbl_board_port_info;
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	/**
+	 * flush_write - Flush posted MEMORY-BAR writes
+	 * @hw_mgt: hardware management context
+	 *
+	 * Only valid on the control PF (common->has_ctrl != 0).  The
+	 * register read back to order the writes, NBL_HW_DUMMY_REG
+	 * (0x1300904), is covered by the ~64 MiB MEMORY-BAR mapping the
+	 * control PF gets, but sits outside the NBL_REG_NET_ONLY_LEN
+	 * (8 KiB) mapping a net-only PF gets.  The leonis implementation
+	 * enforces this with a WARN_ON_ONCE().
+	 */
+	void (*flush_write)(struct nbl_hw_mgt *hw_mgt);
 	void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,
 					      u16 tail_ptr, u8 txrx);
 	void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
@@ -43,9 +56,22 @@ struct nbl_hw_ops {
 	 * reads the mask.
 	 */
 	void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);
+	void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt, u8 *bus);
 
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);
+	void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
+	/**
+	 * get_board_info - Fetch board info from firmware
+	 * @hw_mgt: hardware management context
+	 * @board_info: output pointer for board info structure
+	 *
+	 * Firmware contract: board_info.eth_num MUST equal the number of
+	 * unmasked PFs from get_host_pf_mask(). See get_host_pf_mask for
+	 * details.
+	 */
+	void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,
+			       struct nbl_board_port_info *board_info);
 };
 
 struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
new file mode 100644
index 00000000..7136b282
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_RESOURCE_H_
+#define _NBL_DEF_RESOURCE_H_
+
+#include <linux/types.h>
+
+struct nbl_resource_mgt;
+struct nbl_adapter;
+
+struct nbl_resource_ops {
+	int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			  u16 type, u16 *vsi_id);
+	int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			  u16 vsi_id, u8 *eth_num, u8 *eth_id,
+			  u8 *logic_eth_id);
+};
+
+struct nbl_resource_ops_tbl {
+	struct nbl_resource_ops *ops;
+	struct nbl_resource_mgt *priv;
+};
+
+int nbl_res_init_leonis(struct nbl_adapter *adapter);
+void nbl_res_remove_leonis(struct nbl_adapter *adapter);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +6 -0
index f2d80239..59e44fea 100644
@@ -13,6 +13,12 @@
 #define NBL_MAX_PF					8
 #define NBL_NEXT_ID(id, max) (((id) + 1) % ((max) + 1))
 
+#define NBL_MAX_ETHERNET				4
+
+enum {
+	NBL_VSI_DATA = 0,
+};
+
 struct nbl_func_caps {
 	u32 has_ctrl:1;
 	u32 has_net:1;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
index 9a24af5d..d11b68be 100644
@@ -11,6 +11,7 @@
 #include "nbl_include/nbl_include.h"
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
+#include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -37,6 +38,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	adapter->pdev = pdev;
 	common = &adapter->common;
 
+	common->mgt_pf = 0;
 	common->pdev = pdev;
 	common->dev = &pdev->dev;
 	common->has_ctrl = param->caps.has_ctrl;
@@ -52,7 +54,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_chan_init_common(adapter);
 	if (ret)
 		goto out_hw_remove;
+
+	ret = nbl_res_init_leonis(adapter);
+	if (ret)
+		goto out_chan_remove;
 	return adapter;
+out_chan_remove:
+	nbl_chan_remove_common(adapter);
 out_hw_remove:
 	nbl_hw_remove_leonis(adapter);
 out:
@@ -61,6 +69,7 @@ out:
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
 }
Signature · 1 line
2.51.0.windows.1
author maintainer
#3 lore raw

PATCH v33 3/8 net/nebula-matrix: add intr resource implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add dedicated nbl_interrupt module to manage chip-internal MSI-X interrupt resource and hardware mapping for the Nebula Matrix Ethernet driver.

This module manages the driver-wide global hardware MSI-X vector index space, split into independent network and control interrupt bitmaps (intr_net_bmap/intr_other_bmap), and handles programming of the chip-internal MSI-X mapping registers. It explicitly does not manage physical PCI MSI-X entries; physical vector allocation via pci_alloc_irq_vectors() will be implemented in a follow-up patch via nbl_dev_init_interrupt_scheme().

The published manager is control-PF only: the resource ops reject calls when common->has_ctrl is not set.

Core functional interfaces:
1. cfg_msix_map: Allocate global hardware MSI-X vectors from the separate net/other interrupt bitmaps. Reuse the per-function coherent DMA map table on reconfig, so a reconfiguration neither frees and reallocates the table nor has to take the destroy-path quiesce window before the old vectors are recycled. The first configuration of a function still takes one invalidate + flush + quiesce window before the table is written; that window belongs to the first configuration only and is not part of the reconfiguration path. Only tear down the old hardware state after the new allocation succeeds, to avoid interrupt loss, and program the MSI-X table DMA address plus the control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP.

2. destroy_msix_map: Recycle global vector indices, clear hardware MSI-X mappings, and release DMA/descriptor resources. Implements two-stage
teardown: disable mailbox IRQ routing first, mask vectors, clear hardware VALID bits while retaining the live DMA addresses, take a bounded best-effort ~1ms hardware DMA quiescence window, then zero the table entries and free the coherent memory to prevent torn reads.

3. set_mailbox_irq: Toggle PF-specific mailbox MSI-X routing by updating NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured MSI-X map, enabling safe routing cleanup before vector release.

4. cfg_msix_info: Program PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with the strict hardware-defined programming order (forward for enable, reverse for teardown) to avoid inconsistent hardware state.

Key design & safety features:
- Self-contained intr_mgt->lock protects the global bitmaps and the per-function state; all public APIs hold the lock internally, so callers need no upper-layer locking.
- Global cleanup via nbl_intr_mgt_stop(): under the lock it latches the manager stopping and invalidates the hardware map entry of every function still left CONFIGURED, then takes a single global quiesce window before the coherent tables and vector indices are released. Remote PF maps are created via mailbox RPC in later patches; the cleanup itself uses local MMIO writes.
- Only PFs are supported: every op rejects a func_id outside the PF range (a VF id) with -EINVAL, and cfg_msix_map additionally rejects a func_id that maps to a PF which is not present on this board with -EOPNOTSUPP, via nbl_res_func_id_to_bdf().
- FUNCTION_MSIX_MAP survives a kexec or a forced unload without FLR and there is no .shutdown callback to scrub it, so nbl_intr_mgt_start() invalidates all NBL_MAX_PF map entries once, followed by one flush and one quiesce window, before any function is configured. nbl_probe() now leaves bus mastering disabled until nbl_core_init() has returned, so this scrub runs before the device can issue a single fetch against a stale VALID entry - those fetches are bus-master reads, and a stale entry points at memory this kernel may already have reallocated. Everything between pci_set_master() and the scrub is host-side setup plus MMIO and does not wait for the device. The gvec-indexed INFO/FID tables are not scrubbed; their entries are rewritten before a map entry is armed again.

Known limitation - MSI-X map table DMA quiescence:
The chip exposes no idle or completion status for a pcompleter fetch of a map table, so the only ordering available anywhere in this module is "clear VALID -> flush_write() -> bounded delay". The delay is sized well above the tables' worst-case fetch/response latency, but it is a best-effort approximation and not a guarantee; a caller that cannot tolerate the residual risk must keep the table allocated for the lifetime of the function rather than rely on it.
Two things narrow the window rather than close it. Tables are freed only after that delay, and nbl_remove() now clears Bus Master Enable before any teardown runs, so the device cannot start a new fetch once teardown has begun and the residual window covers in-flight requests only. Neither helps a sibling PF's map destroyed at runtime: those fetches are tagged with the control PF's BDF, so clearing bus mastering on the sibling does not stop them. Runtime destroys of sibling maps only become reachable with the mailbox RPC added later in this series.

Instantiate the interrupt manager via nbl_intr_mgt_start() during device resource initialization, and attach it to the resource management context.

Add corresponding hardware register definitions, helper functions, resource ops callbacks, and Makefile entries to wire up the new module. The new resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq) are hooked into resource_ops but have no in-tree callers within this patch; invocation will be added in subsequent patches in this series.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 164 +++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  44 +
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  38 +-
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c  | 851 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h  |  21 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.c   |  32 +
 .../nebula-matrix/nbl/nbl_hw/nbl_resource.h   |  90 ++
 .../nbl/nbl_include/nbl_def_hw.h              |   9 +
 .../nbl/nbl_include/nbl_def_resource.h        |   6 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  48 +-
 12 files changed, 1291 insertions(+), 14 deletions(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index 3dab9519..5aec8e44 100644
@@ -8,4 +8,5 @@ nbl-objs +=	nbl_common/nbl_common.o \
 		nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \
 		nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
 		nbl_hw/nbl_resource.o \
+		nbl_hw/nbl_interrupt.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +162 -2

197 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +44 -0

50 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +35 -3
index dd8cf9e5..da4258cf 100644
@@ -10,6 +10,9 @@
 static struct nbl_resource_ops res_ops = {
 	.get_vsi_id = nbl_res_func_id_to_vsi_id,
 	.get_eth_id = nbl_res_get_eth_id,
+	.cfg_msix_map = nbl_res_intr_cfg_msix_map,
+	.destroy_msix_map = nbl_res_intr_destroy_msix_map,
+	.set_mailbox_irq = nbl_res_intr_set_mailbox_irq,
 };
 
 static struct nbl_resource_mgt *
@@ -41,7 +44,9 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)
 	res_ops_tbl = devm_kzalloc(dev, sizeof(*res_ops_tbl), GFP_KERNEL);
 	if (!res_ops_tbl)
 		return ERR_PTR(-ENOMEM);
-	if (!res_ops.get_vsi_id || !res_ops.get_eth_id)
+	if (!res_ops.get_vsi_id || !res_ops.get_eth_id ||
+	    !res_ops.cfg_msix_map || !res_ops.destroy_msix_map ||
+	    !res_ops.set_mailbox_irq)
 		return ERR_PTR(-EINVAL);
 	res_ops_tbl->ops = &res_ops;
 	res_ops_tbl->priv = res_mgt;
@@ -288,6 +293,10 @@ static int nbl_res_start(struct nbl_resource_mgt *res_mgt)
 		ret = nbl_res_ctrl_dev_vsi_info_init(res_mgt);
 		if (ret)
 			return ret;
+
+		ret = nbl_intr_mgt_start(res_mgt);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
@@ -328,8 +337,31 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)
 
 void nbl_res_remove_leonis(struct nbl_adapter *adap)
 {
+	struct nbl_resource_mgt *res_mgt = adap->core.res_mgt;
+	struct nbl_common_info *common = &adap->common;
+
+	if (!res_mgt)
+		return;
+
 	/*
-	 * No resource release here because all memory uses devm managed
-	 * allocation
+	 * Tear down all MSI-X maps before destroying coherent tables.
+	 * This is critical on the control PF, whose table carries the map
+	 * entries installed for every configured function: they must be
+	 * invalidated in hardware before the tables backing them are
+	 * freed, otherwise the device keeps DMA-reading released pages.
+	 * Sibling PFs are already unbound by the device-link ordering
+	 * so no remote PF still has a live map entry or a running
+	 * mailbox RPC at this point.
+	 */
+	if (common->has_ctrl && res_mgt->intr_mgt)
+		nbl_intr_mgt_stop(res_mgt);
+
+	/* Note:
+	 * per-function interrupts arrays (kcalloc) are freed by
+	 * nbl_intr_mgt_stop().
+	 * MSIX coherent tables are explicitly freed by dma_free_coherent()
+	 * inside the intr destroy path, before nbl_intr_mgt_stop() returns.
+	 * intr_mgt itself (devm_kzalloc) is released by devres after this
+	 * function returns
 	 */
 }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index b9355262..6eb4dc9e 100644
@@ -7,4 +7,5 @@
 #define _NBL_RESOURCE_LEONIS_H_
 
 #include "../nbl_resource.h"
+#include "../nbl_interrupt.h"
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +851 -0

851 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +21 -0
new file mode 100644
index 00000000..9f66f5e1
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_INTERRUPT_H_
+#define _NBL_INTERRUPT_H_
+
+#include "nbl_resource.h"
+
+#define NBL_MSIX_MAP_TABLE_MAX_ENTRIES	1024
+int nbl_res_intr_destroy_msix_map(struct nbl_resource_mgt *res_mgt,
+				  u16 func_id);
+int nbl_res_intr_cfg_msix_map(struct nbl_resource_mgt *res_mgt,
+			      u16 func_id, u16 num_net_msix,
+			      u16 num_others_msix,
+			      bool net_msix_mask_en);
+int nbl_res_intr_set_mailbox_irq(struct nbl_resource_mgt *res_mgt,
+				 u16 func_id, u16 vector_id,
+				 bool en_msix);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +32 -0
index b316fb8e..49c7d441 100644
@@ -68,6 +68,38 @@ int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id)
 	return -ENOENT;
 }
 
+int nbl_res_func_id_to_bdf(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			   u8 *bus, u8 *dev, u8 *function)
+{
+	struct nbl_common_info *common = res_mgt->common;
+	struct nbl_sriov_info *sriov_info;
+	int pfid = func_id;
+	u8 pf_bus, devfn;
+	u32 rel_pf_id;
+	int ret;
+
+	if (!common->has_ctrl || !bus || !dev || !function)
+		return -EINVAL;
+	ret = nbl_common_func_id_to_rel_pf_id(common, pfid, &rel_pf_id);
+	if (ret)
+		return ret;
+	if (rel_pf_id >= common->max_pf) {
+		dev_err(common->dev,
+			"func_id=%u rel_pf_id=%u exceeds max_pf=%u, no such PF on this board\n",
+			pfid, rel_pf_id,
+			common->max_pf);
+		return -EOPNOTSUPP;
+	}
+	sriov_info = res_mgt->resource_info->sriov_info + rel_pf_id;
+	pf_bus = PCI_BUS_NUM(sriov_info->bdf);
+	devfn = sriov_info->bdf & 0xff;
+	*bus = pf_bus;
+	*dev = PCI_SLOT(devfn);
+	*function = PCI_FUNC(devfn);
+
+	return 0;
+}
+
 int nbl_res_get_eth_id(struct nbl_resource_mgt *res_mgt, u16 func_id,
 		       u16 vsi_id, u8 *eth_num, u8 *eth_id, u8 *logic_eth_id)
 {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +90 -0

110 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
index 08ce19b0..ca131e43 100644
@@ -12,6 +12,13 @@ struct nbl_board_port_info;
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+			     bool valid, dma_addr_t dma_addr, u8 bus,
+			     u8 devid, u8 function);
+	void (*cfg_msix_info)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+			      bool valid, u16 interrupt_id, u8 bus,
+			      u8 devid, u8 function,
+			      bool net_msix_mask_en);
 	/**
 	 * flush_write - Flush posted MEMORY-BAR writes
 	 * @hw_mgt: hardware management context
@@ -60,6 +67,8 @@ struct nbl_hw_ops {
 
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);
+	void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
+				bool en_msix, u16 gvec);
 	void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
 	/**
 	 * get_board_info - Fetch board info from firmware
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
index 7136b282..e718ea41 100644
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;
 struct nbl_adapter;
 
 struct nbl_resource_ops {
+	int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			    u16 num_net_msix, u16 num_others_msix,
+			    bool net_msix_mask_en);
+	int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id);
+	int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt, u16 func_id,
+			       u16 vector_id, bool en_msix);
 	int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
 			  u16 type, u16 *vsi_id);
 	int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +39 -9

72 lines not on this page · raw message

Signature · 1 line
2.51.0.windows.1
author maintainer
#4 lore raw

PATCH v33 4/8 net/nebula-matrix: add chip-wide hardware init/deinit implementation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers. The resource layer gates both on has_ctrl, so they only run on the control PF.

init_module() programs the chip-wide datapath registers, none of which firmware sets up on the driver's behalf:

- DPED: VLAN/DSCP offsets and the SCTP L4 checksum enable.
- UPED: V4/V6 TCP L3-length edit profiles.
- SHAPING: per-port CIR/PIR from the firmware-reported speed (the DVN dport entry carries PIR at the full rate and CIR at half rate), a bucket depth derived from the rate, PSHA enable for the ports present, and a clear of the PF-indexed shaping_net table.
- DSCH: host QID max (0x7ff) and the host/ECPU quanta.
- USTORE: minimum packet length 42 and the per-port drop threshold, scaled by the PF count, plus a clear of the port drop/truncate counters by reading them back.
- DSTORE: clear the per-port drop enable, program the XON/XOFF flow-control thresholds (a larger pair at 100G), and enable the discard backpressure threshold.
- DVN: ECPU queue count, descriptor-write merge timeout, descriptor request count (by speed), and the relaxed-ordering bits.
- UVN: ECPU queue count, descriptor read-wait/write-timeout, the error mask, and the relaxed-ordering bits. The relaxed-ordering bits in both DVN and UVN are derived from the PCIe DEVCTL state through pcie_relaxed_ordering_enabled().
- UQM: clear the drop counters and force que_type to backpressure.
- PADPT: the host flow-control credits.

This also adds a firmware ABI dependency: nbl_hw_get_quirks() reads a quirk word at mailbox offset NBL_LEONIS_QUIRKS_OFFSET (0x140), where ~0U means "no quirks" and BIT(1) selects the UVN prefetch mode (sel=0, use the configured descriptor count) instead of the internal calculation.

deinit_module() clears the driver_status bit, flushes writes and sleeps 2-3 ms to give the asynchronous firmware cleanup pass time to run. It deliberately reverts none of the above: that pass covers per-PF state only (qinfo registers and mailbox routing), so the chip-wide datapath registers stay programmed until chip reset or until a later init_module() overwrites them, even if the control PF is later bound to another driver. The hardware exposes no cleanup-complete status bit, so the sleep is best-effort and cannot prove the pass has finished.

A stale driver_status bit (kexec, or an unload that never reached deinit_module()) is cleared in nbl_hw_init_leonis(), before this probe programs any per-PF state. The 1 -> 0 transition makes firmware reclaim the mailbox QINFO routing and qinfo registers, so clearing it from init_module() instead - after nbl_dev_setup_chan_qinfo() has programmed them - would leave the inter-PF mailbox dead and make sibling probes time out.

Two known limitations of that handshake, neither of which the driver can close on this hardware:

- NBL_DRIVER_STATUS_REG is shared with firmware. Bit 16 is the only bit the driver owns, and the register has no documented W1S/W1C form, so changing bit 16 has to be a read-modify-write. reg_lock makes the read-modify-write atomic against other CPU writers but cannot serialise against firmware, so a firmware update to a different bit landing between the read and the write would be written back stale. All three callers (the probe-time stale clear, init_module() and deinit_module()) could in principle hit that; no such firmware update is known to race them, but that is an observation about this hardware revision, not a guarantee.

- The 2-3 ms wait is an empirical bound, not a documented firmware latency. There is nothing to poll instead: the hardware exposes no cleanup-complete bit, and the reclaimed entries read back the same before and after the pass, so there is no observable side effect to wait on and nothing to validate the delay against. A pass that takes longer than the window - an ECPU still busy right after kexec, say - can therefore still race a later probe and reclaim routing that probe has already programmed. What actually protects the per-PF state is the ordering around the clear, not the delay, and on teardown that ordering comes from the device link between the sibling PFs and the control PF.

The two hooks are only checked for non-NULL by nbl_hw_setup_ops() and nbl_res_setup_ops() at this point; nothing calls them yet. They gain callers later in the series, from the dispatch init_module()/ deinit_module() and from nbl_dev_setup_ctrl_dev()/ nbl_dev_remove_ctrl_dev().

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.c       |  32 +
 .../nebula-matrix/nbl/nbl_hw/nbl_chip.h       |  12 +
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c  | 753 +++++++++++++++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  | 242 ++++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |   5 +-
 .../nbl_hw_leonis/nbl_resource_leonis.h       |   1 +
 .../nbl/nbl_include/nbl_def_hw.h              |   3 +
 .../nbl/nbl_include/nbl_def_resource.h        |   3 +
 .../nbl/nbl_include/nbl_include.h             |  19 +
 10 files changed, 1069 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index 5aec8e44..be314b90 100644
@@ -9,4 +9,5 @@ nbl-objs +=	nbl_common/nbl_common.o \
 		nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \
 		nbl_hw/nbl_resource.o \
 		nbl_hw/nbl_interrupt.o \
+		nbl_hw/nbl_chip.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +32 -0
new file mode 100644
index 00000000..419eb639
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+#include <linux/device.h>
+#include "nbl_chip.h"
+
+void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt)
+{
+	struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops;
+	struct nbl_common_info *common = res_mgt->common;
+
+	if (!common->has_ctrl)
+		return;
+	hw_ops->deinit_module(res_mgt->hw_ops_tbl->priv);
+}
+
+int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt)
+{
+	struct nbl_common_info *common = res_mgt->common;
+	struct nbl_hw_ops *hw_ops;
+	u8 eth_speed, eth_num;
+	struct nbl_hw_mgt *p;
+
+	if (!common->has_ctrl)
+		return -EINVAL;
+	eth_speed = res_mgt->resource_info->board_info.eth_speed;
+	eth_num = res_mgt->resource_info->board_info.eth_num;
+	hw_ops = res_mgt->hw_ops_tbl->ops;
+	p = res_mgt->hw_ops_tbl->priv;
+	return hw_ops->init_module(p, eth_speed, eth_num);
+}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h new file +12 -0
new file mode 100644
index 00000000..d14093ba
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_CHIP_H_
+#define _NBL_CHIP_H_
+
+#include "nbl_resource.h"
+int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt);
+void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt);
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +752 -1

788 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +242 -0

271 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -1
index da4258cf..ba589af5 100644
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = {
 	.cfg_msix_map = nbl_res_intr_cfg_msix_map,
 	.destroy_msix_map = nbl_res_intr_destroy_msix_map,
 	.set_mailbox_irq = nbl_res_intr_set_mailbox_irq,
+	.init_module = nbl_res_chip_init_module,
+	.deinit_module = nbl_res_chip_deinit_module,
 };
 
 static struct nbl_resource_mgt *
@@ -46,7 +48,8 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)
 		return ERR_PTR(-ENOMEM);
 	if (!res_ops.get_vsi_id || !res_ops.get_eth_id ||
 	    !res_ops.cfg_msix_map || !res_ops.destroy_msix_map ||
-	    !res_ops.set_mailbox_irq)
+	    !res_ops.set_mailbox_irq || !res_ops.init_module ||
+	    !res_ops.deinit_module)
 		return ERR_PTR(-EINVAL);
 	res_ops_tbl->ops = &res_ops;
 	res_ops_tbl->priv = res_mgt;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
index 6eb4dc9e..f1cb0f23 100644
@@ -8,4 +8,5 @@
 
 #include "../nbl_resource.h"
 #include "../nbl_interrupt.h"
+#include "../nbl_chip.h"
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +3 -0
index ca131e43..e9cd3136 100644
@@ -12,6 +12,9 @@ struct nbl_board_port_info;
 struct nbl_hw_mgt;
 struct nbl_adapter;
 struct nbl_hw_ops {
+	int (*init_module)(struct nbl_hw_mgt *hw_mgt, u8 eth_speed, u8 eth_num);
+	void (*deinit_module)(struct nbl_hw_mgt *hw_mgt);
+
 	void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 			     bool valid, dma_addr_t dma_addr, u8 bus,
 			     u8 devid, u8 function);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +3 -0
index e718ea41..8dc64e80 100644
@@ -12,6 +12,9 @@ struct nbl_resource_mgt;
 struct nbl_adapter;
 
 struct nbl_resource_ops {
+	int (*init_module)(struct nbl_resource_mgt *res_mgt);
+	void (*deinit_module)(struct nbl_resource_mgt *res_mgt);
+
 	int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt, u16 func_id,
 			    u16 num_net_msix, u16 num_others_msix,
 			    bool net_msix_mask_en);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +19 -0
index 59e44fea..efc4c79a 100644
@@ -29,4 +29,23 @@ struct nbl_init_param {
 	struct nbl_func_caps caps;
 };
 
+/*
+ * Firmware ABI defines port speed enum fixed, value 0 represents 10G, cannot
+ * reassign 0 to INVALID for compatibility
+ */
+enum nbl_fw_port_speed {
+	NBL_FW_PORT_SPEED_10G,
+	NBL_FW_PORT_SPEED_25G,
+	NBL_FW_PORT_SPEED_50G,
+	NBL_FW_PORT_SPEED_100G,
+};
+
+/*
+ * Firmware quirk word @ NBL_LEONIS_QUIRKS_OFFSET (0x140)
+ * Sentinel value: ~0U (0xFFFFFFFF) = firmware reports no active quirks
+ * BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch
+ * selection
+ */
+#define NBL_QUIRK_UVN_PREFETCH_ALIGN	BIT(1)
+
 #endif
Signature · 1 line
2.51.0.windows.1
author maintainer
#5 lore raw

PATCH v33 5/8 net/nebula-matrix: dispatch: add control-level routing core infrastructure

In reply to illusion.wang

From: illusion wang <[email protected]>

Allocate the dispatch management state and ops table and wire the init_module and deinit_module wrappers to the resource ops. Add a ctrl_lvl bitmap to track control privileges; only the MGT level is defined, and it is enabled only on the control PF.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   2 +
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 117 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h |  23 ++++
 .../nbl/nbl_include/nbl_def_dispatch.h        |  54 ++++++++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   8 ++
 6 files changed, 205 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index be314b90..b7eebd89 100644
@@ -10,4 +10,5 @@ nbl-objs +=	nbl_common/nbl_common.o \
 		nbl_hw/nbl_resource.o \
 		nbl_hw/nbl_interrupt.o \
 		nbl_hw/nbl_chip.o \
+		nbl_core/nbl_dispatch.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
index dd24ebec..4d8cea8d 100644
@@ -17,12 +17,14 @@ enum {
 struct nbl_interface {
 	struct nbl_hw_ops_tbl *hw_ops_tbl;
 	struct nbl_resource_ops_tbl *resource_ops_tbl;
+	struct nbl_dispatch_ops_tbl *dispatch_ops_tbl;
 	struct nbl_channel_ops_tbl *channel_ops_tbl;
 };
 
 struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
 	struct nbl_resource_mgt *res_mgt;
+	struct nbl_dispatch_mgt *disp_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +117 -0

117 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +23 -0
new file mode 100644
index 00000000..a7e58023
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DISPATCH_H_
+#define _NBL_DISPATCH_H_
+#include "../nbl_include/nbl_include.h"
+#include "../nbl_include/nbl_def_channel.h"
+#include "../nbl_include/nbl_def_resource.h"
+#include "../nbl_include/nbl_def_dispatch.h"
+#include "../nbl_include/nbl_def_common.h"
+#include "../nbl_core.h"
+
+struct nbl_dispatch_mgt {
+	struct nbl_common_info *common;
+	struct nbl_resource_ops_tbl *res_ops_tbl;
+	struct nbl_channel_ops_tbl *chan_ops_tbl;
+	struct nbl_dispatch_ops_tbl *disp_ops_tbl;
+	DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX);
+};
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
index 3c711f9d..fc4488fb 100644
@@ -12,6 +12,7 @@
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
+#include "nbl_include/nbl_def_dispatch.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -58,7 +59,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_res_init_leonis(adapter);
 	if (ret)
 		goto out_chan_remove;
+
+	ret = nbl_disp_init(adapter);
+	if (ret)
+		goto out_res_remove;
 	return adapter;
+out_res_remove:
+	nbl_res_remove_leonis(adapter);
 out_chan_remove:
 	nbl_chan_remove_common(adapter);
 out_hw_remove:
@@ -69,6 +76,7 @@ out:
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
Signature · 1 line
2.51.0.windows.1
author maintainer
#6 lore raw

PATCH v33 6/8 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

In reply to illusion.wang

From: illusion wang <[email protected]>

Add mailbox RPC requests and responses for five dispatch operations:
cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Each op is resolved by capability level: a function with has_ctrl calls the resource op locally, a function with has_net forwards it to the management PF over the channel, and a function with neither leaves the op pointer NULL, so the caller must not invoke it.

A request builds the payload, sends it synchronously and checks the ACK length before parsing; a short ACK returns -EBADMSG. A responder rejects VFs and out-of-range source PF ids with -EPERM, checks the payload length before parsing, and forwards the resource layer's errno verbatim so the requester can tell a protocol error from a failed operation. If the resource op is not installed the responder answers -EOPNOTSUPP. A peer PF is treated as trusted: hardware and firmware forbid PF passthrough to guests, so every peer runs this host driver, and the resource layer bounds the requested vector counts by the global pool.

The cfg_msix_map, destroy_msix_map and set_mailbox_irq requests carry a caller precondition: disable the mailbox IRQ_RDY flag and use the polling send path, because the responder changes mailbox MSI-X routing and an interrupt-driven ACK wakeup cannot be relied on while routing is in flux.

No dispatch-layer lock is taken around these ops. The resource layer serializes concurrent callers itself (intr_mgt->lock) and the dispatch layer has no mutable state of its own to protect; the read-only get_vsi_id/get_eth_id paths only touch static init metadata.

The five responders are registered with the channel layer and owned by it, so they are removed when the channel is torn down and need no explicit unregistration: nbl_disp_remove() stays empty here. The teardown order that makes that safe is documented with the code that performs it, in the next patch in this series.

---
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 534 ++++++++++++++++++
 .../nbl/nbl_include/nbl_def_channel.h         |  40 ++
 .../nbl/nbl_include/nbl_def_dispatch.h        |  37 +-
 3 files changed, 607 insertions(+), 4 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +534 -0
index 966fee2d..cb68544e 100644
@@ -6,6 +6,174 @@
 #include <linux/pci.h>
 #include "nbl_dispatch.h"
 
+static int nbl_disp_chan_get_vsi_id_req(struct nbl_dispatch_mgt *disp_mgt,
+					u16 type, u16 *vsi_id)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_get_vsi_id result = { 0 };
+	struct nbl_chan_param_get_vsi_id param = { 0 };
+	struct nbl_chan_send_info chan_send = {0};
+	int ret;
+
+	param.type = cpu_to_le16(type);
+
+	nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+				NBL_CHAN_MSG_GET_VSI_ID,
+				&param, sizeof(param), &result,
+				sizeof(result), 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	if (ret)
+		return ret;
+	if (chan_send.ack_len != sizeof(result)) {
+		dev_err(disp_mgt->common->dev,
+			"get_vsi_id: short ACK, ack_len=%u expected %zu\n",
+			chan_send.ack_len, sizeof(result));
+		return -EBADMSG;
+	}
+	*vsi_id = le16_to_cpu(result.vsi_id);
+	return 0;
+}
+
+static void nbl_disp_chan_get_vsi_id_resp(void *priv, u16 src_id, u16 msg_id,
+					  void *data, u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_param_get_vsi_id result = { 0 };
+	struct nbl_chan_param_get_vsi_id param = { 0 };
+	struct nbl_chan_ack_info chan_ack;
+	int err = 0;
+	u16 vsi_id = 0;
+	u32 rel_pf_id;
+	int ret;
+
+	ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+					      &rel_pf_id);
+	if (ret) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (rel_pf_id >= disp_mgt->common->max_pf) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = -EBADMSG;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->get_vsi_id) {
+		ret = res_ops->get_vsi_id(p, src_id, le16_to_cpu(param.type),
+					  &vsi_id);
+		/* Forward the resource errno verbatim to the requester */
+		if (ret)
+			err = ret;
+	} else {
+		err = -EOPNOTSUPP;
+	}
+
+	result.vsi_id = cpu_to_le16(vsi_id);
+ack_out:
+	nbl_chan_fill_ack_info(&chan_ack, src_id,
+			       NBL_CHAN_MSG_GET_VSI_ID, msg_id, err,
+			       &result, sizeof(result));
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_GET_VSI_ID);
+}
+
+static int nbl_disp_chan_get_eth_id_req(struct nbl_dispatch_mgt *disp_mgt,
+					u16 vsi_id, u8 *eth_num, u8 *eth_id,
+					u8 *logic_eth_id)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_get_eth_id result = { 0 };
+	struct nbl_chan_param_get_eth_id param = { 0 };
+	struct nbl_chan_send_info chan_send = {0};
+	int ret;
+
+	param.vsi_id = cpu_to_le16(vsi_id);
+
+	nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+				NBL_CHAN_MSG_GET_ETH_ID,
+				&param, sizeof(param), &result,
+				sizeof(result), 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	if (ret)
+		return ret;
+	if (chan_send.ack_len != sizeof(result)) {
+		dev_err(disp_mgt->common->dev,
+			"get_eth_id: short ACK, ack_len=%u expected %zu\n",
+			chan_send.ack_len, sizeof(result));
+		return -EBADMSG;
+	}
+	*eth_num = result.eth_num;
+	*eth_id = result.eth_id;
+	*logic_eth_id = result.logic_eth_id;
+
+	return 0;
+}
+
+static void nbl_disp_chan_get_eth_id_resp(void *priv, u16 src_id, u16 msg_id,
+					  void *data, u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_chan_param_get_eth_id result = { 0 };
+	struct nbl_chan_param_get_eth_id param = { 0 };
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = 0;
+	u32 rel_pf_id;
+	int ret;
+
+	ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+					      &rel_pf_id);
+	if (ret) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (rel_pf_id >= disp_mgt->common->max_pf) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = -EBADMSG;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->get_eth_id) {
+		ret = res_ops->get_eth_id(p, src_id, le16_to_cpu(param.vsi_id),
+					  &result.eth_num, &result.eth_id,
+					  &result.logic_eth_id);
+		/* Forward the resource errno verbatim to the requester */
+		if (ret)
+			err = ret;
+	} else {
+		err = -EOPNOTSUPP;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&chan_ack, src_id,
+			       NBL_CHAN_MSG_GET_ETH_ID, msg_id, err,
+			       &result, sizeof(result));
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_GET_ETH_ID);
+}
+
 static void nbl_disp_deinit_module(struct nbl_dispatch_mgt *disp_mgt)
 {
 	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
@@ -25,6 +193,353 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)
 	return -EOPNOTSUPP;
 }
 
+static int nbl_disp_cfg_msix_map(struct nbl_dispatch_mgt *disp_mgt,
+				 u16 num_net_msix, u16 num_others_msix,
+				 bool net_msix_mask_en)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	if (!res_ops->cfg_msix_map)
+		return -EOPNOTSUPP;
+	/*
+	 * No core-layer lock is taken here: the resource layer serializes
+	 * concurrent callers itself (intr_mgt->lock), and the dispatch
+	 * layer has no mutable state of its own for this op to protect.
+	 */
+	return res_ops->cfg_msix_map(p, common->mgt_pf, num_net_msix,
+				     num_others_msix, net_msix_mask_en);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder rewrites
+ * the requester's mailbox MSI-X routing during the resource op, so the
+ * ACK cannot rely on interrupt wakeup while routing is in flux.
+ */
+static int
+nbl_disp_chan_cfg_msix_map_req(struct nbl_dispatch_mgt *disp_mgt,
+			       u16 num_net_msix, u16 num_others_msix,
+			       bool net_msix_mask_en)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_param_cfg_msix_map param = { 0 };
+	struct nbl_chan_send_info chan_send = {0};
+	int ret;
+
+	param.num_net_msix = cpu_to_le16(num_net_msix);
+	param.num_others_msix = cpu_to_le16(num_others_msix);
+	param.msix_mask_en = cpu_to_le16(!!net_msix_mask_en);
+
+	nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+				NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+				&param, sizeof(param),
+				NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+static void nbl_disp_chan_cfg_msix_map_resp(void *priv, u16 src_id, u16 msg_id,
+					    void *data, u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_param_cfg_msix_map param = { 0 };
+	struct nbl_chan_ack_info chan_ack;
+	int err = 0;
+	u32 rel_pf_id;
+	int ret;
+
+	ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+					      &rel_pf_id);
+	if (ret) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (rel_pf_id >= disp_mgt->common->max_pf) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = -EBADMSG;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+
+	if (res_ops->cfg_msix_map) {
+		/*
+		 * The vector counts come from the peer PF.  A peer is
+		 * trusted: hardware and firmware forbid PF passthrough to
+		 * guests (see nbl_get_func_param()), so every peer runs this
+		 * same host driver, and the resource layer bounds the counts
+		 * by the global vector pool.  A peer asking for the whole
+		 * pool can starve the others with -EAGAIN, but it cannot
+		 * corrupt state.
+		 */
+		ret = res_ops->cfg_msix_map(p, src_id,
+					    le16_to_cpu(param.num_net_msix),
+					    le16_to_cpu(param.num_others_msix),
+					    !!le16_to_cpu(param.msix_mask_en));
+		/* Forward the resource errno verbatim to the requester */
+		if (ret)
+			err = ret;
+	} else {
+		err = -EOPNOTSUPP;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&chan_ack, src_id,
+			       NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, msg_id,
+			       err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder retargets
+ * the requester's mailbox MSI-X routing during the resource op, so the
+ * ACK cannot rely on interrupt wakeup while routing is in flux.
+ */
+static int nbl_disp_chan_destroy_msix_map_req(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_send_info chan_send = {0};
+	int ret;
+
+	nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+				NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+				NULL, 0, NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+static void nbl_disp_chan_destroy_msix_map_resp(void *priv, u16 src_id,
+						u16 msg_id, void *data,
+						u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = 0;
+	u32 rel_pf_id;
+	int ret;
+
+	ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+					      &rel_pf_id);
+	if (ret) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (rel_pf_id >= disp_mgt->common->max_pf) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (res_ops->destroy_msix_map) {
+		ret = res_ops->destroy_msix_map(p, src_id);
+		/* Forward the resource errno verbatim to the requester */
+		if (ret)
+			err = ret;
+	} else {
+		err = -EOPNOTSUPP;
+	}
+ack_out:
+	nbl_chan_fill_ack_info(&chan_ack, src_id,
+			       NBL_CHAN_MSG_DESTROY_MSIX_MAP, msg_id,
+			       err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_DESTROY_MSIX_MAP);
+}
+
+/*
+ * Precondition: caller must disable mailbox IRQ_RDY and switch send_msg
+ * to the polling path before issuing this RPC. The responder rewrites
+ * the requester's own mailbox MSI-X routing (MSIX_IDX / MSIX_IDX_VALID)
+ * before the ACK is sent, so the ACK cannot rely on interrupt wakeup
+ * while routing is in flux.
+ */
+static int nbl_disp_chan_set_mailbox_irq_req(struct nbl_dispatch_mgt *disp_mgt,
+					     u16 vector_id, bool en_msix)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_chan_param_set_mailbox_irq param = { 0 };
+	struct nbl_common_info *common = disp_mgt->common;
+	struct nbl_chan_send_info chan_send = {0};
+	int ret;
+
+	param.vector_id = cpu_to_le16(vector_id);
+	param.en_msix = !!en_msix;
+
+	nbl_chan_fill_send_info(&chan_send, common->mgt_pf,
+				NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+				&param, sizeof(param), NULL, 0, 1);
+	ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+static void nbl_disp_chan_set_mailbox_irq_resp(void *priv, u16 src_id,
+					       u16 msg_id, void *data,
+					       u32 data_len)
+{
+	struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv;
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_chan_param_set_mailbox_irq param = { 0 };
+	struct device *dev = disp_mgt->common->dev;
+	struct nbl_chan_ack_info chan_ack;
+	int err = 0;
+	u16 vector_id;
+	u32 rel_pf_id;
+	bool en_msix;
+	int ret;
+
+	ret = nbl_common_func_id_to_rel_pf_id(disp_mgt->common, src_id,
+					      &rel_pf_id);
+	if (ret) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (rel_pf_id >= disp_mgt->common->max_pf) {
+		err = -EPERM;
+		goto ack_out;
+	}
+	if (data_len < sizeof(param)) {
+		err = -EBADMSG;
+		goto ack_out;
+	}
+	memcpy(&param, data, sizeof(param));
+	vector_id = le16_to_cpu(param.vector_id);
+	en_msix = !!param.en_msix;
+
+	if (res_ops->set_mailbox_irq) {
+		ret = res_ops->set_mailbox_irq(p, src_id, vector_id, en_msix);
+		/* Forward the resource errno verbatim to the requester */
+		if (ret)
+			err = ret;
+	} else {
+		err = -EOPNOTSUPP;
+	}
+
+ack_out:
+	nbl_chan_fill_ack_info(&chan_ack, src_id,
+			       NBL_CHAN_MSG_MAILBOX_SET_IRQ, msg_id,
+			       err, NULL, 0);
+	ret = chan_ops->send_ack(disp_mgt->chan_ops_tbl->priv, &chan_ack);
+	if (ret)
+		dev_err(dev,
+			"channel send ack failed with ret: %d, msg_type: %d\n",
+			ret, NBL_CHAN_MSG_MAILBOX_SET_IRQ);
+}
+
+static int nbl_disp_destroy_msix_map(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	if (!res_ops->destroy_msix_map)
+		return -EOPNOTSUPP;
+	return res_ops->destroy_msix_map(p, common->mgt_pf);
+}
+
+static int nbl_disp_set_mailbox_irq(struct nbl_dispatch_mgt *disp_mgt,
+				    u16 vector_id, bool en_msix)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	if (!res_ops->set_mailbox_irq)
+		return -EOPNOTSUPP;
+	return res_ops->set_mailbox_irq(p, common->mgt_pf, vector_id, en_msix);
+}
+
+static int nbl_disp_get_vsi_id(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+			       u16 *vsi_id)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	if (res_ops->get_vsi_id)
+		return res_ops->get_vsi_id(p, common->mgt_pf, type, vsi_id);
+	return -EOPNOTSUPP;
+}
+
+static int nbl_disp_get_eth_id(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+			       u8 *eth_num, u8 *eth_id, u8 *logic_eth_id)
+{
+	struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
+	struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv;
+	struct nbl_common_info *common = disp_mgt->common;
+
+	if (res_ops->get_eth_id)
+		return res_ops->get_eth_id(p, common->mgt_pf, vsi_id,
+					   eth_num, eth_id, logic_eth_id);
+	return -EOPNOTSUPP;
+}
+
+static int nbl_disp_setup_msg(struct nbl_dispatch_mgt *disp_mgt)
+{
+	struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops;
+	struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv;
+	int ret = 0;
+	int _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_CONFIGURE_MSIX_MAP,
+				      nbl_disp_chan_cfg_msix_map_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_DESTROY_MSIX_MAP,
+				      nbl_disp_chan_destroy_msix_map_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_MAILBOX_SET_IRQ,
+				      nbl_disp_chan_set_mailbox_irq_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_VSI_ID,
+				      nbl_disp_chan_get_vsi_id_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	_ret = chan_ops->register_msg(p, NBL_CHAN_MSG_GET_ETH_ID,
+				      nbl_disp_chan_get_eth_id_resp,
+				      disp_mgt);
+	if (_ret < 0 && !ret)
+		ret = _ret;
+
+	return ret;
+}
+
 static void nbl_disp_set_ctrl_bit(struct nbl_dispatch_mgt *disp_mgt, u32 lvl)
 {
 	set_bit(lvl, disp_mgt->ctrl_lvl);
@@ -34,9 +549,22 @@ static void nbl_disp_refresh_ctrl_ops(struct nbl_dispatch_mgt *disp_mgt)
 {
 	struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops;
 
+	memset(disp_ops, 0, sizeof(*disp_ops));
 	if (test_bit(NBL_DISP_CTRL_LVL_MGT, disp_mgt->ctrl_lvl)) {
 		disp_ops->init_module = nbl_disp_init_module;
 		disp_ops->deinit_module = nbl_disp_deinit_module;
+		disp_ops->cfg_msix_map = nbl_disp_cfg_msix_map;
+		disp_ops->destroy_msix_map = nbl_disp_destroy_msix_map;
+		disp_ops->set_mailbox_irq = nbl_disp_set_mailbox_irq;
+		disp_ops->get_vsi_id = nbl_disp_get_vsi_id;
+		disp_ops->get_eth_id = nbl_disp_get_eth_id;
+	} else if (test_bit(NBL_DISP_CTRL_LVL_NET, disp_mgt->ctrl_lvl)) {
+		disp_ops->cfg_msix_map =
+			nbl_disp_chan_cfg_msix_map_req;
+		disp_ops->destroy_msix_map = nbl_disp_chan_destroy_msix_map_req;
+		disp_ops->set_mailbox_irq = nbl_disp_chan_set_mailbox_irq_req;
+		disp_ops->get_vsi_id = nbl_disp_chan_get_vsi_id_req;
+		disp_ops->get_eth_id = nbl_disp_chan_get_eth_id_req;
 	}
 }
 
@@ -104,9 +632,15 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 	adapter->core.disp_mgt = disp_mgt;
 	adapter->intf.dispatch_ops_tbl = disp_ops_tbl;
 
+	ret = nbl_disp_setup_msg(disp_mgt);
+	if (ret)
+		return ret;
+
 	if (common->has_ctrl)
 		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
+	if (common->has_net)
+		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_NET);
 	nbl_disp_refresh_ctrl_ops(disp_mgt);
 	return 0;
 }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +40 -0
index bf971121..5aa16d4c 100644
@@ -7,6 +7,7 @@
 #define _NBL_DEF_CHANNEL_H_
 
 #include <linux/types.h>
+#include <linux/build_bug.h>
 
 struct nbl_channel_mgt;
 struct nbl_adapter;
@@ -30,6 +31,11 @@ typedef void (*nbl_chan_resp)(void *, u16, u16, void *, u32);
  */
 enum nbl_chan_msg_type {
 	NBL_CHAN_MSG_ACK = 0,
+	NBL_CHAN_MSG_CONFIGURE_MSIX_MAP = 17,
+	NBL_CHAN_MSG_DESTROY_MSIX_MAP = 18,
+	NBL_CHAN_MSG_MAILBOX_SET_IRQ = 19,
+	NBL_CHAN_MSG_GET_VSI_ID = 21,
+	NBL_CHAN_MSG_GET_ETH_ID = 67,
 	/* mailbox msg end */
 	NBL_CHAN_MSG_MAILBOX_MAX,
 };
@@ -39,6 +45,32 @@ enum nbl_chan_state {
 	NBL_CHAN_STATE_NBITS
 };
 
+struct nbl_chan_param_cfg_msix_map {
+	__le16 num_net_msix;
+	__le16 num_others_msix;
+	__le16 msix_mask_en;
+	__le16 rsvd;
+};
+
+struct nbl_chan_param_set_mailbox_irq {
+	__le16 vector_id;
+	u8 en_msix;
+	u8 rsvd;
+};
+
+struct nbl_chan_param_get_vsi_id {
+	__le16 vsi_id;
+	__le16 type;
+};
+
+struct nbl_chan_param_get_eth_id {
+	__le16 vsi_id;
+	u8 eth_num;
+	u8 eth_id;
+	u8 logic_eth_id;
+	u8 rsvd[3];
+};
+
 struct nbl_board_port_info {
 	u8 eth_num;
 	u8 eth_speed;
@@ -46,6 +78,14 @@ struct nbl_board_port_info {
 	u8 rsv[5];
 };
 
+static_assert(sizeof(struct nbl_chan_param_cfg_msix_map) == 8,
+	      "nbl_chan_param_cfg_msix_map size must be 8 bytes");
+static_assert(sizeof(struct nbl_chan_param_set_mailbox_irq) == 4,
+	      "nbl_chan_param_set_mailbox_irq size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_vsi_id) == 4,
+	      "nbl_chan_param_get_vsi_id size must be 4 bytes");
+static_assert(sizeof(struct nbl_chan_param_get_eth_id) == 8,
+	      "nbl_chan_param_get_eth_id size must be 8 bytes");
 static_assert(sizeof(struct nbl_board_port_info) == 8,
 	      "nbl_board_port_info size must be 8 bytes");
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +33 -4
index b5a69516..7da9e242 100644
@@ -12,6 +12,7 @@ struct nbl_dispatch_mgt;
 struct nbl_adapter;
 enum {
 	NBL_DISP_CTRL_LVL_MGT,
+	NBL_DISP_CTRL_LVL_NET,
 	NBL_DISP_CTRL_LVL_MAX,
 };
 
@@ -32,16 +33,44 @@ enum {
  *               mailbox DMA before calling it, see nbl_dev_remove().
  *               Returns void.  Control-PF exclusive, same NULL rule as
  *               @init_module.
+ * @cfg_msix_map: configure function msix mapping table
+ * @destroy_msix_map: tear down msix mapping resource
+ * @set_mailbox_irq: bind mailbox interrupt to specified msix vector
+ * @get_vsi_id: resolve VSI ID by type
+ * @get_eth_id: resolve eth port info from VSI ID
  *
  * These callbacks are not dispatch-layer setup/teardown: the dispatch
- * structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove()
- * only documents why no explicit teardown is needed. They forward
- * chip/firmware control down to the layers below instead: a control-PF
- * function calls the resource ops directly.
+ * structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove()
+ * has nothing to undo. The five responders registered by
+ * nbl_disp_setup_msg() are owned by the channel layer and go away with
+ * it, so they need no explicit unregistration either; the teardown order
+ * that makes that safe is documented with the code that performs it, in
+ * the next patch in this series. They forward chip/firmware control down
+ * to the layers below instead: a control-PF function calls the resource
+ * ops directly, a non-control function sends a mailbox request over the
+ * channel layer.
+ *
+ * Warning: init_module/deinit_module are control-PF exclusive. The five
+ * resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq,
+ * get_vsi_id, get_eth_id) are PF-only and resolve to either a local
+ * resource call (control PF) or a mailbox RPC (non-control PF with
+ * has_net). A function with neither has_ctrl nor has_net leaves these
+ * pointers NULL; callers must not invoke them on such functions. VFs are
+ * rejected by the responders with -EPERM.
  */
 struct nbl_dispatch_ops {
 	int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);
 	void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt,
+			    u16 num_net_msix, u16 num_others_msix,
+			    bool net_msix_mask_en);
+	int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*set_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt,
+			       u16 vector_id, bool en_msix);
+	int (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+			  u16 *vsi_id);
+	int (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+			  u8 *eth_num, u8 *eth_id, u8 *logic_eth_id);
 };
 
 struct nbl_dispatch_ops_tbl {
Signature · 1 line
2.51.0.windows.1
author maintainer
#7 lore raw

PATCH v33 7/8 net/nebula-matrix: add common/ctrl dev init/remove operation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add nbl_dev.c, nbl_dev.h and nbl_def_dev.h to host device-level initialization and teardown logic, and wire the new nbl_dev_init() / nbl_dev_remove() entry points into core init/remove.

Common device setup allocates per-device state, initializes the mailbox cleanup work and creates the mailbox channel queue. VSI/ETH identity lookup and MSI-X vector allocation are deferred to the subsequent start routine, so that the control PF mailbox responder is fully ready before any cross-PF RPC is issued and each commit in the series can be probed on its own.

Control-PF-only setup invokes chip-level module initialization and programs the mailbox QINFO routing table entries that map PF bus/devid to the mailbox queue.

Init/teardown ordering is dictated by a hardware constraint rather than by strict symmetry. Init: program mailbox QINFO (control PF only), create the mailbox queue, then run control device init_module. Teardown:
stop the mailbox channel and drain all in-flight DMA first, then call deinit_module(). This ordering prevents the firmware from reclaiming the routing under a live transfer, which would leave the device DMAing into released memory.

The firmware reclaims per-PF state (mailbox QINFO routing, qinfo registers and the like) asynchronously once driver status is marked inactive. It does not revert the chip-wide datapath registers configured by init_module; those stay valid until chip reset (see nbl_hw_deinit_module()). The device link created during non-control PF probe makes the driver core unbind all sibling PFs before the control PF is removed.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |   1 +
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   1 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 303 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |  55 ++++
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c |  22 +-
 .../nbl/nbl_include/nbl_def_dev.h             |  14 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 7 files changed, 404 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index b7eebd89..71fbe3ee 100644
@@ -11,4 +11,5 @@ nbl-objs +=	nbl_common/nbl_common.o \
 		nbl_hw/nbl_interrupt.o \
 		nbl_hw/nbl_chip.o \
 		nbl_core/nbl_dispatch.o \
+		nbl_core/nbl_dev.o \
 		nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +1 -0
index 4d8cea8d..c3c4dd68 100644
@@ -25,6 +25,7 @@ struct nbl_core {
 	struct nbl_hw_mgt *hw_mgt;
 	struct nbl_resource_mgt *res_mgt;
 	struct nbl_dispatch_mgt *disp_mgt;
+	struct nbl_dev_mgt *dev_mgt;
 	struct nbl_channel_mgt *chan_mgt;
 };
 
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +303 -0

303 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +55 -0

55 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +21 -1
index cb68544e..59d80066 100644
@@ -647,5 +647,25 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 
 void nbl_disp_remove(struct nbl_adapter *adapter)
 {
-	/* Dispatch structures are allocated via devm */
+	/*
+	 * Dispatch structures are devm-allocated and freed at detach.
+	 *
+	 * The five responders registered by nbl_disp_setup_msg() are
+	 * owned by the channel layer (xarray of handlers) and are never
+	 * unregistered here. This is safe because the teardown order
+	 * guarantees no responder can run after this point:
+	 *
+	 *   mailbox teardown
+	 *     -> cancel_work_sync(clean_mbx_task)   // drain RX work
+	 *     -> nbl_chan_teardown_queue()          // stop HW queue,
+	 *                                                 // join clean task,
+	 *                                                 // active=false
+	 *     -> nbl_chan_remove_common()
+	 *          -> nbl_common_destroy_wq()            // no new work
+	 *          -> nbl_chan_remove_msg_handler()      // free handler nodes
+	 *
+	 * By the time devres frees disp_mgt, the mailbox queue is stopped
+	 * and the handler xarray is empty, so no responder can touch
+	 * res_mgt->intr_mgt after nbl_intr_mgt_stop() has cleared it.
+	 */
 }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
new file mode 100644
index 00000000..51cf04e4
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEF_DEV_H_
+#define _NBL_DEF_DEV_H_
+
+struct nbl_adapter;
+
+int nbl_dev_init(struct nbl_adapter *adapter);
+void nbl_dev_remove(struct nbl_adapter *adapter);
+
+#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
index fc4488fb..a3e599f5 100644
@@ -13,6 +13,7 @@
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_dispatch.h"
+#include "nbl_include/nbl_def_dev.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -63,7 +64,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_disp_init(adapter);
 	if (ret)
 		goto out_res_remove;
+
+	ret = nbl_dev_init(adapter);
+	if (ret)
+		goto out_disp_remove;
 	return adapter;
+
+out_disp_remove:
+	nbl_disp_remove(adapter);
 out_res_remove:
 	nbl_res_remove_leonis(adapter);
 out_chan_remove:
@@ -76,6 +84,7 @@ out:
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_dev_remove(adapter);
 	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
Signature · 1 line
2.51.0.windows.1
author maintainer
#8 lore raw

PATCH v33 8/8 net/nebula-matrix: add common dev start/stop operation

In reply to illusion.wang

From: illusion wang <[email protected]>

Add nbl_dev_start() and nbl_dev_stop(), called from nbl_probe() and nbl_remove() via nbl_core_start() / nbl_core_stop().

Start configures the device MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt; stop performs the matching teardown.

nbl_probe() now rejects a function with neither the ctrl nor the net capability with -EOPNOTSUPP, before any hardware is touched. Such a function would reach nbl_dev_start() with every dispatch op left NULL by nbl_disp_refresh_ctrl_ops(). The state is only reachable through
driver_override: binding this driver to a function that is absent from nbl_id_table (a VF, or a non-func-0 PF of this device) makes pci_match_device() pass the dummy ID whose driver_data 0 leaves both capabilities clear. A foreign device at func 0 is unaffected - nbl_get_func_param() gives any func 0 device has_ctrl, so it is not rejected here and still runs nbl_core_init() with the local control dispatch ops, as it did before this check existed. nbl_dev_init()'s unwind labels change with it: setup_ctrl_dev_fail becomes out_remove_common_dev, and the setup_err path drops its label and returns directly, since a failed nbl_dev_setup_common_dev() has nothing to unwind.

Startup RPC errors are propagated unchanged. A -ETIMEDOUT here is a real failure, not a "supplier not ready yet" condition: nbl_probe() already deferred this PF in nbl_probe_chip_deps() until the control PF reached DL_DEV_DRIVER_BOUND, and the driver core only marks a device bound once its entire probe - including the control PF's own nbl_core_start() - has returned. That state is what bounds the wait, not nbl_dev_init(): on the control PF inbound mailbox work only runs from clean_mbx_task, which is queued by the mailbox hardirq, by the task's own self-requeue, or by this function's polling sends, and the control PF uses the local dispatch ops so it sends none. The responder is armed by set_mailbox_irq(true) at the end of the peer's nbl_dev_start(). Relaxing the dependency to "func 0 finished nbl_dev_init()" would therefore let every sibling RPC sit out the full 5-6s polling wait. Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay that wait again.

Teardown releases the kernel MSI-X vectors before destroying the hardware pcompleter map. pci_free_irq_vectors() ends in pci_msix_shutdown(), which masks every descriptor by writing the MSI-X table and reading it back to flush the write; those accesses should reach the function while FUNCTION_MSIX_MAP is still valid. This mirrors start, where cfg_msix_map runs before pci_alloc_irq_vectors_affinity(). It is not a double free of the pcim_msi_release devres registered alongside pci_alloc_irq_vectors(): that action only calls pci_free_irq_vectors() again, and pci_disable_msix() returns early once msix_enabled is clear. Start and stop still each run once, tied to probe and remove.

The rest of teardown is best-effort. The MSI-X map is torn down even when the configure RPC failed: a timeout only means the ACK never arrived, while the responder runs to completion before ACKing, so the entry, the intr_net/other_bmap bits and the coherent map table stay owned by the control PF. Those are host resources of that driver, not firmware state, and neither recovery path needs a chip reset: a later successful configuration of this function invalidates and rewrites the entry on its had_config path, and nbl_intr_mgt_stop() clears the FUNCTION_MSIX_MAP valid bit for every still-configured function when the control PF is removed. pci_clear_master() is not a safety net for this: on a non-control PF it cannot stop DMA issued with the management PF's BDF.

---
 .../net/ethernet/nebula-matrix/nbl/nbl_core.h |   8 +
 .../nebula-matrix/nbl/nbl_core/nbl_dev.c      | 432 +++++++++++++++++-
 .../nbl/nbl_include/nbl_def_dev.h             |   2 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  37 +-
 4 files changed, 473 insertions(+), 6 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +8 -0
index c3c4dd68..655dfb43 100644
@@ -40,4 +40,12 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param);
 void nbl_core_remove(struct nbl_adapter *adapter);
 
+/*
+ * Single-shot start/stop pair, called once each from PCI probe/remove.
+ * Not repeatable: MSI-X vectors stay allocated until device detach, so
+ * a second start on a bound device is rejected by the MSI-X core.
+ */
+int nbl_core_start(struct nbl_adapter *adapter);
+void nbl_core_stop(struct nbl_adapter *adapter);
+
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +428 -4

473 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
index 51cf04e4..a66c633a 100644
@@ -10,5 +10,7 @@ struct nbl_adapter;
 
 int nbl_dev_init(struct nbl_adapter *adapter);
 void nbl_dev_remove(struct nbl_adapter *adapter);
+int nbl_dev_start(struct nbl_adapter *adapter);
+void nbl_dev_stop(struct nbl_adapter *adapter);
 
 #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +35 -2
index a3e599f5..0bdc7f99 100644
@@ -25,6 +25,15 @@
 #define NBL_MGT_LOCK_RETRY_MIN_US	1000
 #define NBL_MGT_LOCK_RETRY_MAX_US	2000
 #define NBL_MGT_LOCK_MAX_RETRIES	50
+int nbl_core_start(struct nbl_adapter *adapter)
+{
+	return nbl_dev_start(adapter);
+}
+
+void nbl_core_stop(struct nbl_adapter *adapter)
+{
+	nbl_dev_stop(adapter);
+}
 
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param)
@@ -277,6 +286,25 @@ static int nbl_probe(struct pci_dev *pdev,
 	int err;
 
 	nbl_get_func_param(pdev, id->driver_data, &param);
+	/*
+	 * Reject a function with neither capability before touching any
+	 * hardware.  nbl_disp_refresh_ctrl_ops() leaves every dispatch op NULL
+	 * for such a function, while nbl_dev_start() reaches cfg_msix_map,
+	 * get_vsi_id, get_eth_id and (on unwind) destroy_msix_map through
+	 * those pointers.  The state is reachable through driver_override:
+	 * binding this driver to a function that is not in nbl_id_table (a VF,
+	 * or a non-func-0 PF) makes pci_match_device() pass the dummy ID whose
+	 * driver_data 0 leaves has_ctrl and has_net both clear.  A foreign
+	 * device at func 0 is unaffected: nbl_get_func_param() gives any
+	 * func 0 device has_ctrl, so it is not rejected here and still runs
+	 * nbl_core_init() with the local control dispatch ops, as it did
+	 * before this check existed.
+	 */
+	if (!param.caps.has_ctrl && !param.caps.has_net) {
+		dev_err(dev, "Function has neither ctrl nor net capability\n");
+		return -EOPNOTSUPP;
+	}
+
 	err = pcim_enable_device(pdev);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to enable PCI dev, err=%d\n", err);
@@ -314,8 +342,12 @@ static int nbl_probe(struct pci_dev *pdev,
 
 	pci_set_master(pdev);
 	pci_set_drvdata(pdev, adapter);
-
-	return 0;
+	err = nbl_core_start(adapter);
+	if (err) {
+		nbl_core_remove(adapter);
+		pci_clear_master(pdev);
+	}
+	return err;
 }
 
 static void nbl_remove(struct pci_dev *pdev)
@@ -326,6 +358,7 @@ static void nbl_remove(struct pci_dev *pdev)
 		return;
 	pci_set_drvdata(pdev, NULL);
 
+	nbl_core_stop(adapter);
 	/*
 	 * Stop bus mastering before any teardown runs.
 	 *
Signature · 1 line
2.51.0.windows.1