Skip to contentSkip to conversation

nbl driver for Nebulamatrix NICs

PATCH Superseded illusion.wang 3 participants 18 messages Oct 10 – Oct 20

Subsystems (3)

v31 of 35 Superseded Latest is v35 →

lore
Share & tools
lore

illusion.wang

author maintainer
#0 lore raw

v31 cover nbl driver for Nebulamatrix NICs

From: illusion wang <[email protected]>

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 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             | 1486 +++++++++++++++++
 .../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      |  667 ++++++++
 .../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  | 1140 +++++++++++++
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  |  322 ++++
 .../nbl_hw_leonis/nbl_resource_leonis.c       |  364 ++++
 .../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  |  801 +++++++++
 .../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   |  146 ++
 .../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        |   77 +
 .../nbl/nbl_include/nbl_def_hw.h              |   79 +
 .../nbl/nbl_include/nbl_def_resource.h        |   38 +
 .../nbl/nbl_include/nbl_include.h             |   28 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  159 ++
 29 files changed, 6828 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_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.47.3
author maintainer
#1 lore raw

PATCH v31 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. This patch also hooks channel init/cleanup into the PF probe/remove paths in nbl_main.c.

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).
- Each ring uses one contiguous coherent DMA block sliced into fixed-size slots, so a channel costs one devres node and one IOMMU mapping per ring instead of one per slot.
- Mailbox queue resources are devm-managed and the DMA is allocated once during setup; the queue lifecycle covers init, configuration, start, stop and teardown.
- 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.

---
 .../net/ethernet/nebula-matrix/nbl/Makefile   |    4 +-
 .../nbl/nbl_channel/nbl_channel.c             | 1486 +++++++++++++++++
 .../nbl/nbl_channel/nbl_channel.h             |  196 +++
 .../nebula-matrix/nbl/nbl_common/nbl_common.c |   31 +
 .../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  |  234 +++
 .../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          |    4 +
 .../nbl/nbl_include/nbl_def_hw.h              |   41 +
 .../nbl/nbl_include/nbl_include.h             |    3 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  115 ++
 14 files changed, 2332 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
index cc060cf8bf75..04e1aa1fb4bd 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 +1486 -0

1,486 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 +31 -0
new file mode 100644
index 000000000000..ce0ed2869af4
@@ -0,0 +1,31 @@
+// 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 000000000000..129073b08eb9
@@ -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 1cd6587a8fcb..f998a2b44e5c 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 +234 -0

261 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 e281109f502e..4c1bb789c465 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 +4 -0
index ea646d1efc2d..26a364e3a194 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,7 @@ 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 +41 -0

47 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +3 -0
index 14e7b19f9a4c..f2d802397d98 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 +115 -0

152 lines not on this page · raw message

Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH v31 net-next 1/8] net/nebula-matrix: add channel layer

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 5 · Low: 3

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] Lock-order inversion (ABBA) between nbl_probe_chip_deps() and the PCI core's bus/slot locking.
- [Medium] nbl_probe_chip_deps() in drivers/net/ethernet/nebula- matrix/nbl/nbl_main.c changes how every non-function-0 PF probes, but…
- [Medium] nbl_chan_setup_queue() sets chan_info->dma_allocated = true before allocating, and the comment says this is so that "a retry must…
- [Medium] nbl_probe_chip_deps() can self-deadlock when the probing device is an SR-IOV VF whose devfn has function number 0.
- [Medium] In nbl_probe_chip_deps(), the PF0 checks and the device-link creation are not atomic, and the second check does not close the race.
- [Medium] nbl_hw_stop_mailbox_rxq() and nbl_hw_stop_mailbox_txq() write the whole 4-dword QINFO_CFG entry through nbl_hw_write_mbx_regs(), one…
- [Low] A comment in nbl_chan_send_msg() says active "is published last in setup and cleared last in teardown, so a false value here means the…
- [Low] nbl_chan_teardown_queue() waits for inflight_tx_cnt to reach 0 and then does one mutex_lock()/mutex_unlock() of state_lock.
- [Low] (Baseline: not a defect.) In the external-buffer branch of nbl_chan_update_txqueue(), buf_addr and buf_len are programmed even…

--

net/nebula-matrix: add channel layer

This adds a mailbox-based channel layer that carries control messages between PF0 and the other PFs. It has xarray handler lookup, ACK-based sends, coherent DMA rings and a quiescing teardown. It also hooks channel init/cleanup into probe/remove, and adds a device link from each PF other than function 0 to function 0.

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0 -0
new file mode 100644
index 0000000000000..ac3115a3ab55f
@@ -0,0 +1,1486 @@

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3 -0
+static int nbl_chan_teardown_queue(struct nbl_channel_mgt *chan_mgt,
+				   u8 chan_type)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 428

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +12 -0
+	/*
+	 * Join the last exiting sender through state_lock: it drops
+	 * inflight_tx_cnt and wakes this drain while still holding
+	 * state_lock, so observing the counter reach zero does not prove
+	 * the sender has finished its mutex_unlock(). Acquiring the lock
+	 * once here guarantees no sender still holds it - mutex_unlock()
+	 * is the sender's last touch of chan_info - before returning lets
+	 * devres free chan_info. shutdn blocks new senders, so one
+	 * acquire/release pair is sufficient.
+	 */
+	mutex_lock(&chan_info->state_lock);
+	mutex_unlock(&chan_info->state_lock);

[Severity: Low]
Does one lock/unlock pair give the guarantee this comment claims?

Documentation/locking/mutex-design.rst says:

mutex_unlock() may access the mutex structure even after it has internally released the lock already - so it's not safe for another context to acquire the mutex and assume that the mutex_unlock() context is not using the structure anymore.

The last sender exits nbl_chan_send_msg() at out_clean_inflight like this:

	mutex_lock(&chan_info->state_lock);
	if (atomic_dec_and_test(&chan_info->inflight_tx_cnt))
		wake_up(&chan_info->inflight_wait);
	mutex_unlock(&chan_info->state_lock);

The unlock slowpath of that sender can still be touching state_lock after teardown has acquired the lock, released it and returned.

Today chan_info is devm-allocated and freed only at detach, so this series cannot reach a use-after-free. Still, the claim would no longer hold if chan_info were freed, or mutex_destroy() were called, right after teardown.

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +2 -0
+static int nbl_chan_setup_queue(struct nbl_channel_mgt *chan_mgt, u8 chan_type)
+{

[ ... ]

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11 -0
+	if (chan_info->dma_allocated) {
+		dev_warn(common->dev,
+			 "channel DMA already allocated, re-setup not supported\n");
+		return -EBUSY;
+	}
+
+	nbl_chan_init_queue_param(chan_info, NBL_CHAN_QUEUE_LEN,
+				  NBL_CHAN_QUEUE_LEN, NBL_CHAN_BUF_LEN,
+				  NBL_CHAN_BUF_LEN);
+	/*
+	 * Set the flag before the first allocation: if setup fails halfway,

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 490

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10 -0
+	 * the buffers allocated so far already live until detach, so a retry
+	 * must be rejected instead of allocating a second set and orphaning
+	 * the first one.
+	 */
+	chan_info->dma_allocated = true;
+	err = nbl_chan_init_queue(common, chan_info);
+	if (err) {
+		chan_info->dma_allocated = false;
+		return err;
+	}

[Severity: Medium]
Clearing dma_allocated here seems to allow the very retry that the comment above says must be rejected. Is that intended?

nbl_chan_init_tx_queue() and nbl_chan_init_rx_queue() allocate with dmam_alloc_coherent() and devm_kcalloc(). Anything allocated before a failure part-way through stays allocated until detach.

A second setup_queue() call would then pass the dma_allocated check and allocate a whole new set: about 2 MiB of coherent DMA, plus the descriptor rings and wait[]. It would overwrite txq/rxq/wait and leave the first set unreferenced.

A later patch in the series ("add common/ctrl dev init/remove operation") depends on this guard. Its comment in nbl_dev_setup_common_dev() says "chan_info->dma_allocated blocks a re-setup".

Also, nbl_chan_teardown_queue() never clears dma_allocated, so the channel cannot be set up again after teardown. Does that fit the "init, configuration, start, stop and teardown" lifecycle described in the commit message?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 536

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5 -0
+	if (param->arg_len > NBL_CHAN_TX_DESC_EMBEDDED_DATA_LEN) {
+		if (param->arg)
+			memcpy(tx_buf->va, param->arg, param->arg_len);
+		tx_desc->buf_addr = cpu_to_le64(tx_buf->pa);
+		tx_desc->buf_len = cpu_to_le16(param->arg_len);

[Severity: Low]
This isn't a bug, but in nbl_chan_update_txqueue() buf_addr and buf_len are programmed even when param->arg is NULL. A NULL arg with a non-zero arg_len would send whatever is left in the slot from before. No caller in the series passes that combination today. Would it be simpler to reject it up front?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 1045

Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11 -0
+	/*
+	 * Entry points are only reached after a successful setup_queue()
+	 * (probe path), but the channel is a dynamic object: fail cleanly
+	 * instead of dereferencing rings/wait[] that were never allocated
+	 * (num_txq_entries == 0).  active is published last in setup and
+	 * cleared last in teardown, so a false value here means the channel
+	 * was never set up; the teardown window itself is covered by the
+	 * shutdn check below.
+	 */
+	if (!READ_ONCE(chan_info->active))
+		return -ENODEV;

[Severity: Low]
Is this comment still true once teardown has completed?

nbl_chan_teardown_queue() ends with WRITE_ONCE(chan_info->active, false) and leaves shutdn set. dma_allocated then stops setup from running again.

A sender that arrives after teardown takes this branch and gets -ENODEV instead of -ESHUTDOWN, even though the channel was set up.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0 -0
index cf40ddc451921..eeff6216e4aa5 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c line 159

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +8 -0
+static void nbl_hw_stop_mailbox_rxq(struct nbl_hw_mgt *hw_mgt)
+{
+	struct nbl_mailbox_qinfo_cfg_table cfg_tbl;
+
+	memset(&cfg_tbl, 0, sizeof(cfg_tbl));
+	cfg_tbl.data[3] = FIELD_PREP(NBL_MAILBOX_QINFO_CFG_QUEUE_RST_MASK, 1);
+	nbl_hw_write_mbx_regs(hw_mgt, NBL_MAILBOX_QINFO_CFG_RX_TABLE_ADDR,
+			      cfg_tbl.data, sizeof(cfg_tbl));

[Severity: Medium]
Is it safe to zero the ring base and size before QUEUE_RST takes effect?

nbl_hw_write_mbx_regs() writes the entry one dword at a time, data[0] through data[3]:

	for (i = 0; i < len / 4; i++)
		nbl_mbx_wr32(hw_mgt, reg + i * sizeof(u32), data[i]);

data[0..2] (base low/high and QUEUE_SIZE_BWID) are therefore written as zero while QUEUE_EN is still set. QUEUE_RST arrives only with data[3].

Teardown calls nbl_chan_stop_rx_queue() while the peer can still send. nbl_chan_quiesce_and_reclaim_tx() stops TX while a descriptor is still outstanding.

If the device applies each dword as it is written, could a transfer in that window DMA to IOVA 0 or raise PTR_ERR/DIF_ERR? The same applies to nbl_hw_stop_mailbox_txq(), and to the first {0, 0, 0, RST} write in nbl_hw_config_mailbox_rxq() and nbl_hw_config_mailbox_txq().

If the hardware does not commit the entry on the data[3] write, would writing only data[3] with QUEUE_RST set first avoid this?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0 -0
index f2552bc732937..62484fbf1fef6 100644

[ ... ]

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6 -0
+static int nbl_probe_chip_deps(struct pci_dev *pdev, bool has_ctrl)
+{
+	struct device_link *link;
+	struct pci_dev *mgt;
+
+	if (has_ctrl)

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, · line 128

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10 -0
+		return 0;
+
+	mgt = pci_get_domain_bus_and_slot(pci_domain_nr(pdev->bus),
+					  pdev->bus->number,
+					  PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
+	if (!mgt) {
+		dev_err(&pdev->dev,
+			"management PF (func 0) not found on this chip\n");
+		return -ENODEV;
+	}

[Severity: Medium]
The commit message only says:

This patch also hooks channel init/cleanup into the PF probe/remove paths in nbl_main.c.

nbl_probe_chip_deps() also changes how every PF with PCI_FUNC != 0 probes:

- if function 0 is missing from the slot, probe fails with -ENODEV
- if function 0 is unbound, or bound to vfio-pci or pci-stub, probe returns -EPROBE_DEFER indefinitely
- a persistent DL_FLAG_AUTOPROBE_CONSUMER link is created, so unbinding function 0 force-unbinds every sibling PF

Nothing in this patch uses that ordering yet, because setup_queue and cfg_chan_qinfo_map_table have no callers. Later patches ("add common/ctrl dev init/remove operation", "add common dev start/stop operation") rely on the link but only mention it in passing.

Could this go in its own patch, or at least be described and justified in this commit message? A setup with PF0 on vfio-pci and PF1..3 on nbl would now leave the sibling PFs deferred forever.

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, · line 137

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
+
+	/*
+	 * The management PF must have COMPLETED probing with this driver.
+	 * While func 0 is still PROBING, its chip-global init (mailbox
+	 * QINFO map programming) can race a sibling's mailbox setup, and a
+	 * func 0 bound to another driver never ran it at all.  Defer until
+	 * func 0 is bound to nbl; this also covers the unbound case.
+	 */
+	device_lock(&mgt->dev);

[Severity: Medium]
Can this self-deadlock when the probing device is an SR-IOV VF whose devfn decodes to function 0?

nbl_get_func_param() sets has_ctrl only for a function 0 that is not a VF:

	if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn)
		param->caps.has_ctrl = 1;

Such a VF therefore gets has_ctrl == 0 and reaches the lookup. With ARI, for example, a VF at devfn 0x08 decodes to slot 1, function 0, so pci_get_domain_bus_and_slot() returns pdev itself.

device_lock(&mgt->dev) then takes the same dev->mutex that the driver core already holds across really_probe(). The probe task would block forever on a lock it owns. Later unbind, VF removal when SR-IOV is disabled, and anything else that takes that device lock would then hang too.

VFs can be created through another PF driver and bound to nbl with driver_override. Should there be an is_virtfn or mgt == pdev check before taking the lock?

[Severity: High]
Is there a lock ordering inversion here with the PCI core?

During funcN's probe the driver core holds device_lock(funcN), and this code then takes device_lock(func0). That is the order N -> 0.

__pci_bus_lock() in drivers/pci/pci.c takes them in the opposite order. It walks bus->devices in devfn order with the blocking pci_dev_lock():

	if (bridge)
		pci_dev_lock(bridge);
	list_for_each_entry(dev, &bus->devices, bus_list) {
		...
		else
			pci_dev_lock(dev);
	}

AER recovery reaches that blocking path:

aer_root_reset()
pci_bus_error_reset()

    pci_reset_bridge(bridge, PCI_RESET_NO_RESTORE)
      pci_bus_reset(bus, PCI_RESET_DO_RESET)
        pci_bus_lock()

pci_slot_reset()->pci_slot_lock() reaches it as well.

Suppose the AER thread holds func0's lock and waits for funcN's. At the same time funcN's probe, for example a deferred probe triggered when func0 binds, holds funcN's lock and waits here for func0's. Wouldn't both sides block forever?

dev->mutex uses lockdep_set_novalidate_class(), so lockdep would not report this.

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10 -0
+	if (mgt->dev.driver != &nbl_driver.driver ||
+	    mgt->dev.links.status != DL_DEV_DRIVER_BOUND) {
+		device_unlock(&mgt->dev);
+		pci_dev_put(mgt);
+		return -EPROBE_DEFER;
+	}
+	device_unlock(&mgt->dev);
+
+	link = device_link_add(&pdev->dev, &mgt->dev,
+			       DL_FLAG_AUTOPROBE_CONSUMER);

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, · line 173

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6 -0
+	device_lock(&mgt->dev);
+	if (mgt->dev.links.status != DL_DEV_DRIVER_BOUND) {
+		device_unlock(&mgt->dev);
+		pci_dev_put(mgt);
+		return -EPROBE_DEFER;
+	}

[Severity: Medium]
Does this second check close the race described in the comment above it?

device_lock(func0) is dropped before device_link_add(). If func0 unbinds in that gap, device_link_init_status() creates the managed link in DL_STATE_DORMANT. If func0 then rebinds before this check, device_links_driver_bound() on the supplier moves the link to DL_STATE_AVAILABLE, not DL_STATE_CONSUMER_PROBE.

This check reads only mgt->dev.links.status == DL_DEV_DRIVER_BOUND, so it accepts that state. device_links_busy() does not treat AVAILABLE as busy, so another func0 unbind can run during the sibling's probe. When the consumer finishes binding, device_links_driver_bound() hits:

	WARN_ON(link->status != DL_STATE_CONSUMER_PROBE);

In a related interleaving func0 is rebound to pci-stub or vfio-pci. This check does not re-test mgt->dev.driver against &nbl_driver.driver, so the sibling carries on against a PF0 that never ran nbl's chip-global setup.

Should this check also verify the bound driver, as the first check does?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
maintainer
#3 lore raw

Re: [PATCH v31 net-next 1/8] net/nebula-matrix: add channel layer

In reply to illusion.wang

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 214

Quoted 3 lines · On Sat, 10 Oct 2026 17:59:24 +0800 illusion.wang wrote:

adapter_init_err:

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1 -0
+chip_deps_err:
 	pci_clear_master(pdev);

The error labels should be named after the target, not the source of the jump The latter leads to a lot of bugs and confusion. please see the kernel coding style guide

Signature · 1 line
pw-bot: cr
author maintainer
#4 lore raw

PATCH v31 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 |  21 ++
 .../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       | 329 ++++++++++++++++++
 .../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          |  21 +-
 .../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, 752 insertions(+), 3 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 04e1aa1fb4bd..3dab9519a277 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 +21 -0
index ce0ed2869af4..302c3c48dc4d 100644
@@ -29,3 +29,24 @@ 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 f998a2b44e5c..dd24ebec0171 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 93e5c7518288..251dd68d0721 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 +329 -0

329 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 000000000000..b9355262c00d
@@ -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 4c1bb789c465..00fa33eeabaa 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 d6faa0bc4026..bf971121d2ec 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 -1
index 26a364e3a194..3e18a2a97850 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,12 +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 58d1b669b8cb..4b420db91963 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,
@@ -42,9 +55,22 @@ struct nbl_hw_ops {
 	 * op only returns the raw register value.
 	 */
 	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 000000000000..7136b282fb80
@@ -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 f2d802397d98..59e44feab44f 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 62484fbf1fef..cd3774691bf4 100644
@@ -10,6 +10,7 @@
 #include "nbl_include/nbl_include.h"
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
+#include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -27,6 +28,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	adapter->pdev = pdev;
 	common = &adapter->common;
 
+	common->mgt_pf = 0;
 	common->pdev = pdev;
 	common->dev = &pdev->dev;
 	common->has_ctrl = param->caps.has_ctrl;
@@ -42,7 +44,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_chan_init_common(adapter);
 	if (ret)
 		goto chan_init_fail;
+
+	ret = nbl_res_init_leonis(adapter);
+	if (ret)
+		goto res_init_fail;
 	return adapter;
+res_init_fail:
+	nbl_chan_remove_common(adapter);
 chan_init_fail:
 	nbl_hw_remove_leonis(adapter);
 hw_init_fail:
@@ -51,6 +59,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
 }
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH v31 net-next 2/8] net/nebula-matrix: add common resource implementation

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The get_host_pf_mask kernel-doc in nbl_def_hw.h says nbl_res_init_pf_num() "always runs before this op's only consumer,…

--

net/nebula-matrix: add common resource implementation

This commit adds a chip-agnostic resource layer for the Nebula Matrix driver. On the control PF it builds the PF topology, SR-IOV BDF, Ethernet port and VSI identity tables once at probe time. It also adds new hw ops (flush_write, get_real_bus, get_fw_eth_map, get_board_info) and the VSI/PF/Eth ID conversion helpers.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0 -0
index 58d1b669b8cbb..4b420db91963d 100644

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h struct nbl_hw_ops { · line 58

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +1 -0
@@ -42,9 +55,22 @@ struct nbl_hw_ops {
 	 * op only returns the raw register value.
 	 */
 	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);

[Severity: Low]
This isn't a bug, but the kernel-doc for get_host_pf_mask just above this hunk now looks stale:

* The mask is validated in the resource layer:
* nbl_res_init_pf_num() rejects an all-zero mask and any
* non-contiguous layout with -EINVAL, and it always runs before
* this op's only consumer, nbl_chan_cfg_qinfo_map_table(). This
* op only returns the raw register value.

This patch adds nbl_res_init_pf_num() in nbl_resource_leonis.c, and that function calls the op itself:

	hw_ops->get_host_pf_mask(res_mgt->hw_ops_tbl->priv, &pf_mask);

That means nbl_chan_cfg_qinfo_map_table() is no longer the only consumer. The same is still true at the end of the series, where the op is called from both nbl_resource_leonis.c and nbl_channel.c.

The ordering claim does hold by the end of the series. In "net/nebula-matrix:
add common/ctrl dev init/remove operation", nbl_dev_init() calls nbl_dev_setup_chan_qinfo() only under common->has_ctrl, and it does so after nbl_res_init_leonis().

Could the "only consumer" wording be changed to list both callers?

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0 -0
 	void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
 				  u8 bus, u8 devid, u8 function);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#6 lore raw

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

In reply to illusion.wang

From: illusion wang <[email protected]>

Add an nbl_interrupt module that manages the driver-wide, chip-internal MSI-X vector index space and the chip MSI-X mapping tables. It does not manage the physical PCI MSI-X entries; those are set up in a follow-up patch by nbl_dev_init_interrupt_scheme().

The global vector space is split into separate net and control bitmaps (intr_net_bmap/intr_other_bmap). A single intr_mgt->lock protects the bitmaps and the per-function state and is taken internally by every public API, so callers need no extra locking. Only PFs are supported; VF ids are rejected with -EOPNOTSUPP.

The module provides three resource ops:
- cfg_msix_map: allocate global vectors from the two bitmaps and program NBL_PCOMPLETER_FUNCTION_MSIX_MAP with the table DMA address and the control PF's BDF. The per-function coherent table is allocated once and reused on later reconfigurations, which removes the table free/realloc cycle. The new vector set is allocated before the old hardware state is torn down, so a failed reconfiguration leaves the old configuration intact.
- destroy_msix_map: two-stage teardown. Disable mailbox IRQ routing, invalidate the per-vector INFO entries, clear the map VALID bit while keeping the live DMA address, wait ~1 ms for in-flight table fetches, then zero the entry and free the coherent table. The wait is best-effort, as the chip exposes no fetch completion status.
- set_mailbox_irq: bind or unbind a PF's mailbox routing via NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured map, so routing can be cleaned up before vectors are released.

The hardware helpers program PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE in forward order on enable and reverse order on teardown, to avoid inconsistent hardware state.

The module also adds register definitions and resource ops callbacks, and instantiates the manager via nbl_intr_mgt_start() during resource init. nbl_intr_mgt_stop() is the global teardown, called from nbl_res_remove_leonis().

The new resource ops are hooked into resource_ops but have no in-tree caller in this patch; invocation is added in later patches of the 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  | 801 ++++++++++++++++++
 .../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   |  77 ++
 .../nbl/nbl_include/nbl_def_hw.h              |   9 +
 .../nbl/nbl_include/nbl_def_resource.h        |   6 +
 11 files changed, 1189 insertions(+), 5 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 3dab9519a277..5aec8e44f5d7 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 7804762a96e0..72b5b889dedb 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;
@@ -282,6 +287,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;
@@ -322,8 +331,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 b9355262c00d..6eb4dc9e695a 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 +801 -0

801 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 000000000000..9f66f5e19c98
@@ -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 b316fb8e7051..635f34312c56 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, VF BDF unsupported\n",
+			pfid, rel_pf_id,
+			common->max_pf);
+		return -EOPNOTSUPP;
+	}
+	sriov_info = res_mgt->resource_info->sriov_info + rel_pf_id;
+	pf_bus = PCI_BUS_NUM(sriov_info->bdf);
+	devfn = sriov_info->bdf & 0xff;
+	*bus = pf_bus;
+	*dev = PCI_SLOT(devfn);
+	*function = PCI_FUNC(devfn);
+
+	return 0;
+}
+
 int nbl_res_get_eth_id(struct nbl_resource_mgt *res_mgt, u16 func_id,
 		       u16 vsi_id, u8 *eth_num, u8 *eth_id, u8 *logic_eth_id)
 {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +77 -0

97 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
index 4b420db91963..89b979e2cdb5 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
@@ -59,6 +66,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 7136b282fb80..e718ea41a816 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,
Signature · 1 line
2.47.3
#7 lore raw

Re: [PATCH v31 net-next 3/8] net/nebula-matrix: add intr resource implementation

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The comments in nbl_intr_setup_mgt() and nbl_res_intr_cfg_msix_map() say the chip MSI-X tables…
- [Low] The commit message says "Only PFs are supported; VF ids are rejected with -EOPNOTSUPP".
- [Low] Several comments describe error semantics the code does not have.
- [Low] Concern (not confirmed): the public entry points read res_mgt->intr_mgt without a lock and then take intr_mgt->lock.

--

net/nebula-matrix: add intr resource implementation

This patch adds an nbl_interrupt module. It manages the chip-internal MSI-X vector index space using separate net and control bitmaps, and it programs the per-PF chip MSI-X mapping tables. It adds the cfg_msix_map, destroy_msix_map and set_mailbox_irq resource ops plus the hw helpers behind them, and calls nbl_intr_mgt_start()/nbl_intr_mgt_stop() from resource init and remove.

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0 -0
new file mode 100644
index 0000000000000..3048af5bfeed3

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +5 -0
+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)
+{

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4 -0
+	if (func_id >= NBL_MAX_PF) {
+		dev_err(dev, "Invalid func_id %u\n", func_id);
+		return -EINVAL;
+	}

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 420

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +8 -0
+	ret = nbl_res_func_id_to_bdf(res_mgt, func_id, &bus, &devid, &function);
+	if (ret) {
+		if (ret == -EOPNOTSUPP)
+			dev_err(dev,
+				"MSI-X mapping for VF func_id=%u is not supported\n",
+				func_id);
+		return ret;
+	}

[Severity: Low]
The commit message says "Only PFs are supported; VF ids are rejected with -EOPNOTSUPP." Does the code do that?

NBL_MAX_PF is 8, so any VF id fails the func_id >= NBL_MAX_PF check above. It gets -EINVAL before nbl_res_func_id_to_bdf() is ever called.

nbl_res_func_id_to_bdf() returns -EOPNOTSUPP only when rel_pf_id >= common->max_pf. That is a PF that does not exist on this board, for example PF 3 on a 2-port card. Even so, its message ("VF BDF unsupported") and the message here ("MSI-X mapping for VF func_id=%u") both call it a VF.

The comment on func_intr_res[] in struct nbl_interrupt_mgt has a related problem. It says "nbl_res_func_id_to_bdf() rejects VF ids before any func_intr_res[] access". However, nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq() never call nbl_res_func_id_to_bdf(). They only check func_id >= NBL_MAX_PF.

So an absent-PF id in [max_pf, NBL_MAX_PF) is accepted on those paths, and the en_msix=false path writes NBL_MAILBOX_QINFO_MAP_REG_ARR(func_id) for it. For the same reason, the "VFs are rejected earlier" comment in __nbl_res_intr_set_mailbox_irq() is inaccurate.

Later in the series, the dispatch responders reject rel_pf_id >= max_pf with -EPERM before calling these ops, and local callers pass common->mgt_pf. This therefore looks limited to the documentation and the diagnostics.

Could the commit message, comments and error strings be updated to match? Alternatively, should destroy_msix_map and set_mailbox_irq check against max_pf as well?

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 682

Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12 -0
+/*
+ * Only software state is reset here.  The chip-internal MSI-X tables
+ * (FUNCTION_MSIX_MAP, PADPT_HOST_MSIX_INFO, HOST_MSIX_FID_TABLE) can
+ * survive a kexec or a forced unload without FLR, and there is no
+ * .shutdown callback to scrub them.  They are not cleared here because
+ * the INFO/FID tables are indexed by global vector id, which would mean
+ * rewriting every entry; instead the map entry that the pcompleter
+ * actually fetches is invalidated by nbl_res_intr_cfg_msix_map() before
+ * it is programmed, and by the teardown paths.
+ */
+static struct nbl_interrupt_mgt *nbl_intr_setup_mgt(struct device *dev)
+{

[Severity: Medium]
After a kexec or forced unload without FLR, what happens to the FUNCTION_MSIX_MAP entries of PFs that the new kernel has not configured yet?

The only stale-map invalidation is the !had_config block in nbl_res_intr_cfg_msix_map(), and it covers only the func_id being configured:

	if (!had_config) {
		hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
				     false, 0, 0, 0, 0);

The bitmaps start empty here. The first PF the new kernel configures therefore gets gvecs from the bottom of each pool and arms INFO/FID for them.

Meanwhile, a sibling PF's map entry from the previous kernel can still be VALID. It still points at an old-kernel DMA address and maps into those same gvecs. Bus mastering is already enabled by pci_set_master() in nbl_probe() at this point.

Could the pcompleter then fetch that stale table, read memory now owned by the new kernel, or route an interrupt into a gvec now owned by another function? This looks like the same hazard the fresh-config comment in nbl_res_intr_cfg_msix_map() describes, but for a different function.

nbl_intr_mgt_stop() and the destroy path only act on CONFIGURED functions. A stale entry for a PF that stays IDLE would therefore never be cleared.

FUNCTION_MSIX_MAP is indexed by func_id, not by gvec, so the reason given above for not scrubbing doesn't seem to apply to it. Would it be possible to invalidate all NBL_MAX_PF map entries at init, followed by one flush and one quiesce wait?

[ ... ]

Quoted 5 lines

+/*
+ * nbl_intr_mgt_stop - global control-PF interrupt teardown
+ *
+ * Phase 1 sets the stopping latch and invalidates every configured
+ * function's hardware map entry while holding the lock. The lock is

Quoted 8 lines

+ * dropped for the global quiesce window, so a caller that races the
+ * window is rejected by the latch (checked under the lock), not by the
+ * lock being held.
+ *
+ * After this returns res_mgt->intr_mgt is NULL, so the public entry
+ * points report -EINVAL. -ESHUTDOWN/-EBUSY/-ENODEV are only observed
+ * by a caller that latched the pointer before it was cleared.
+ */

[Severity: Low]
This isn't a bug, but are these error code descriptions accurate?

The -EBUSY branch in nbl_res_intr_cfg_msix_map() looks unreachable:

	if (intr_mgt->func_intr_res[func_id].state ==
	    NBL_INTR_FUNC_DESTROYING) {
		ret = -EBUSY;

__nbl_res_intr_destroy_msix_map() holds the lock from prepare through complete, and it always leaves the function IDLE. The only other time DESTROYING is visible under the lock is the quiesce window in nbl_intr_mgt_stop(). By then stopping is already true, so the -ESHUTDOWN check just above fires first.

Also, __nbl_res_intr_set_mailbox_irq() returns -ENODEV whenever en_msix is true and the function is not CONFIGURED, whether or not stop has run.

The comment on nbl_resource_mgt::intr_mgt in nbl_resource.h has a similar mismatch. It says a caller that latched the pointer early "sees stopping == true and fails with -ESHUTDOWN". But the en_msix=false path returns 0 before any stopping check:

	if (!en_msix) {
		hw_ops->set_mailbox_irq(res_mgt->hw_ops_tbl->priv,
					func_id, false, 0);
		hw_ops->flush_write(res_mgt->hw_ops_tbl->priv);
		return 0;
	}

Could these comments be adjusted, and the dead -EBUSY branch dropped?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#8 lore raw

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

In reply to illusion.wang

From: illusion wang <[email protected]>

Add Leonis chip-wide datapath init/deinit hooks (init_module and deinit_module) in the hw and resource layers. The hooks use the driver_status register as a handshake with firmware.

deinit_module clears driver_status, flushes the write so it reaches the device, then waits a bounded 2-3 ms window for the firmware cleanup pass to run. Firmware cleanup is asynchronous and the hardware exposes no completion status, so the flush only guarantees the write was posted and the wait is best-effort; it does not prove the firmware pass finished. init_module checks the driver_status bit on entry and, if a previous instance left it set (kexec or a forced unload), clears it and waits the same window before re-initializing.

---
 .../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  | 672 +++++++++++++++++-
 .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h  | 222 ++++++
 .../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, 968 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 5aec8e44f5d7..be314b909d66 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 000000000000..419eb6392ada
@@ -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 000000000000..d14093ba916c
@@ -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 +671 -1

701 lines not on this page · raw message

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

251 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -1
index 72b5b889dedb..6cb9302af7bc 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 6eb4dc9e695a..f1cb0f23240b 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 89b979e2cdb5..fe6771be1eb8 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 e718ea41a816..8dc64e806c1e 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 59e44feab44f..efc4c79a082d 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.47.3
#9 lore raw

Re: [PATCH v31 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 4

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The stale-state recovery in nbl_hw_init_module() can wipe the per-PF mailbox state the driver has just programmed.
- [Medium] The only synchronization between the driver and firmware's asynchronous driver_status cleanup is a fixed usleep_range(2000,…
- [Medium] nbl_shaping_init() clears the shaping_net table (NBL_SHAPING_NET_REG(i)) only for i < NBL_MAX_PF (8), yet the loop…
- [Low] The comment on nbl_hw_deinit_module() (lines 730-734) says the safety of a later init_module() rests on the device link, and that the…
- [Low] The commit message covers only the driver_status handshake and the 2-3 ms best-effort wait.
- [Low] Baseline decision: false positive, because the series fixes it.
- [Low] Baseline decision: false positive.

--

net/nebula-matrix: add chip-wide hardware init/deinit implementation

This adds Leonis chip-wide init_module and deinit_module hooks in the hw and resource layers. deinit_module clears the driver_status bit, flushes and sleeps 2-3 ms to give the asynchronous firmware cleanup time to run. init_module programs the datapath registers. If it finds driver_status already set by a previous instance, it first clears the bit and waits for the same window.

Quoted 3 lines

Add Leonis chip-wide datapath init/deinit hooks (init_module and deinit_module) in the hw and resource layers. The hooks use the driver_status register as a handshake with firmware.

[Severity: Low]
This isn't a bug, but the commit message only describes the driver_status handshake and the 2-3 ms wait. Most of the patch is chip-wide datapath programming in nbl_dp_init() and nbl_intf_init(), and several of those writes change device behaviour:

- SCTP L4 checksum enable in DPED
- UPED TCP L3-length edit profiles
- per-port CIR/PIR shaping from the firmware speed (DVN dport CIR at half rate), and PSHA enable
- DSCH host QID max (0x7ff) and quanta
- USTORE min packet length 42 and drop thresholds
- DSTORE drop-enable clear and XON/XOFF thresholds
- relaxed ordering bits taken from DEVCTL
- UQM counter clearing and que_type forced to backpressure mode
- PADPT flow control credits

The patch also adds a new firmware ABI dependency in nbl_hw_get_quirks(). It reads a quirk word at mailbox offset 0x140, where ~0U means no quirks and BIT(1) selects the UVN prefetch mode.

deinit_module also doesn't revert any of these datapath registers. They stay programmed until chip reset, even if the control PF is later bound to another driver.

Could the commit message describe these?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +0 -0
new file mode 100644
index 0000000000000..419eb6392ada1
@@ -0,0 +1,32 @@

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +2 -0
+int nbl_res_chip_init_module(struct nbl_resource_mgt *res_mgt)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c line 32

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +4 -0
+	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);
+}

[Severity: Low]
This isn't a bug, but nothing calls init_module or deinit_module at this point in the series. nbl_hw_setup_ops() and nbl_res_setup_ops() only check the new hooks for NULL.

Two later commits wire them up:

- "net/nebula-matrix: dispatch: add control-level routing core infrastructure" adds nbl_disp_init_module() and nbl_disp_deinit_module()
- "net/nebula-matrix: add common/ctrl dev init/remove operation" calls them from nbl_dev_setup_ctrl_dev() and nbl_dev_remove_ctrl_dev()

So the final state of the series looks fine. nbl_hw_init_module() also validates eth_num with nbl_hw_eth_num_valid().

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0 -0
index 1712cdbc5fe74..bd1216265036b 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0 -0
@@ -150,6 +164,658 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +3 -0
+static int nbl_shaping_init(struct nbl_hw_mgt *hw_mgt, u8 speed)
+{
+#define NBL_SHAPING_FLUSH_INTERVAL 128

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 348

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10 -0
+	for (i = 0; i < NBL_MAX_PF; i++) {
+		nbl_hw_wr_regs_lock(hw_mgt, NBL_SHAPING_NET_REG(i),
+				    net_shaping.data,
+				    sizeof(net_shaping));
+		if ((i + 1) % NBL_SHAPING_FLUSH_INTERVAL == 0)
+			nbl_flush_writes(hw_mgt);
+	}
+	nbl_flush_writes(hw_mgt);
+	return 0;
+}

[Severity: Medium]
Is NBL_MAX_PF the right bound for the shaping_net table here?

NBL_MAX_PF is 8 and NBL_SHAPING_FLUSH_INTERVAL is 128, so (i + 1) % 128 == 0 is never true and the periodic flush is dead code. Flushing every 128 writes suggests a table with hundreds of entries.

The other tables this patch sweeps have depth macros (NBL_DSTORE_PORT_DROP_TH_DEPTH, NBL_UQM_PORT_DROP_DEPTH and NBL_UQM_DPORT_DROP_DEPTH). shaping_net has none, so the bound can't be checked against the register map.

If the table is deeper than 8, would entries above index 7 keep whatever a previous instance or firmware left there across kexec or rebind? That could include VALID set with stale CIR/PIR.

[ ... ]

Quoted 7 lines

+/*
+ * Setting driver status to false notifies firmware to clean up per-PF
+ * hardware state such as qinfo registers.
+ *
+ * Note: firmware does NOT automatically revert chip-wide registers
+ * configured in this init flow. Those chip-wide settings remain valid
+ * until chip reset or explicitly overwritten by driver.

[ ... ]

Quoted 5 lines

+ * does not guarantee that the firmware pass has finished. The ordering
+ * this relies on is the device-link one: sibling PFs are unbound before
+ * the control PF, so a later init_module() requires an admin (or the
+ * core's AUTOPROBE re-probe) to bind this PF again, which is not
+ * instantaneous - but there is no hard firmware handshake.

[Severity: Low]
Is the AUTOPROBE part of this comment accurate?

init_module and deinit_module only run on the control PF, because of the has_ctrl checks in nbl_chip.c. nbl_probe_chip_deps() in nbl_main.c returns early when has_ctrl is set. For the siblings it does:

    link = device_link_add(&pdev->dev, &mgt->dev,
                           DL_FLAG_AUTOPROBE_CONSUMER);

This makes the siblings consumers and func 0 the supplier. DL_FLAG_AUTOPROBE_CONSUMER only re-probes consumers, so it never rebinds the control PF.

The link also doesn't order the control PF's own deinit against its next init. Only the 2-3 ms sleep does that.

The two comments in this file also disagree. The one above NBL_FW_CLEANUP_SYNC_MIN_US says:

Bounding the wait keeps a later init_module() from reprogramming per-PF/chip-wide registers while firmware is realistically still wiping them

This comment says firmware does not automatically revert chip-wide registers. Which one describes what firmware actually cleans?

Quoted 17 lines

+ *
+ * Caller must ensure no new DMA is initiated after this point.
+ * The mailbox channel is stopped by nbl_chan_teardown_queue()
+ * before this function is called, so no in-flight mailbox DMA
+ * remains.
+ */

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +11 -0
+static void nbl_hw_deinit_module(struct nbl_hw_mgt *hw_mgt)
+{
+	nbl_hw_set_driver_status(hw_mgt, false);
+	/* ensure driver_status reaches the chip */
+	nbl_flush_writes(hw_mgt);
+	/*
+	 * Give the asynchronous firmware cleanup pass time to settle
+	 * before returning; best-effort, see NBL_FW_CLEANUP_SYNC_MIN_US.
+	 */
+	usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US, NBL_FW_CLEANUP_SYNC_MAX_US);
+}

[ ... ]

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +3 -0
+static int nbl_hw_init_module(struct nbl_hw_mgt *hw_mgt, u8 eth_speed,
+			      u8 eth_num)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +1 -0
+	status = nbl_hw_rd32(hw_mgt, NBL_DRIVER_STATUS_REG);

[Severity: Low]
This probably isn't an issue in practice, but bit 16 is tested here with an unlocked read. The clear below is a separate read-modify-write under reg_lock in nbl_hw_set_driver_status().

On the driver side, both only run from the serialized control PF probe and remove paths. Only the driver sets bit 16, so a stale read at worst causes a redundant clear and sleep.

Does firmware ever write other bits of NBL_DRIVER_STATUS_REG? If it does, could the read-modify-write in nbl_hw_set_driver_status() lose those updates?

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 806

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +8 -0
+	if (status & BIT(NBL_DRIVER_STATUS_BIT)) {
+		dev_warn(hw_mgt->common->dev,
+			 "driver_status already set at init, cleanup forced\n");
+		nbl_hw_set_driver_status(hw_mgt, false);
+		nbl_flush_writes(hw_mgt);
+		usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US,
+			     NBL_FW_CLEANUP_SYNC_MAX_US);
+	}

[Severity: High]
Can this forced 1 -> 0 transition wipe the mailbox state the driver has just programmed?

The deinit_module comment above says firmware reacts to driver_status going to 0 by cleaning per-PF state such as qinfo registers. Later in the series, nbl_dev_remove_ctrl_dev() relies on the same behaviour:

The qinfo map programmed in nbl_dev_init() via nbl_dev_setup_chan_qinfo() is not explicitly cleared; firmware handles it on driver_status change

In the final state of the series, nbl_dev_init() runs in this order:

nbl_dev_init()
nbl_dev_setup_chan_qinfo()
nbl_chan_cfg_qinfo_map_table()
hw_ops->cfg_mailbox_qinfo() /* for every PF */
nbl_dev_setup_common_dev() /* mailbox queue setup */
nbl_dev_setup_ctrl_dev()
nbl_disp_init_module()
nbl_res_chip_init_module()
nbl_hw_init_module()
nbl_hw_set_driver_status(hw_mgt, false)

So the stale clear happens after the mailbox QINFO map and queue registers are programmed, and nothing reprograms them afterwards. This function then sets driver_status back to 1 and returns 0.

The driver has no .shutdown callback, so every kexec reaches this path. The commit message names kexec as a case init_module handles.

If firmware clears the QINFO routing here, would the inter-PF mailbox stop working? The sibling PFs' cross-PF requests would then time out and their probes would fail.

Would it work to do the stale driver_status clear before any per-PF programming in nbl_dev_init(), or to reprogram the mailbox state after it?

drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) · line 812

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6 -0
+
+	ret = nbl_dp_init(hw_mgt, eth_speed, eth_num);
+	if (ret)
+		return ret;
+	nbl_intf_init(hw_mgt);
+	nbl_hw_set_driver_status(hw_mgt, true);

[Severity: Medium]
The only synchronization with the asynchronous firmware cleanup is a fixed usleep_range(2000, 3000). It is used here and in nbl_hw_deinit_module().

On this stale path, the bit stays low only for that sleep plus the nbl_dp_init() and nbl_intf_init() register writes, and then it is set again here. If firmware samples driver_status less often than that, can it miss the 0 entirely? The per-PF cleanup this path is meant to trigger would then never run.

If firmware does see the 0 but its cleanup takes longer than the window, can the cleanup overlap the new instance's programming? That includes driver_status=1 here and the MSI-X map and mailbox IRQ setup later in nbl_dev_start(). Neither case would be reported.

On the deinit side, only elapsed time separates a quick unbind and rebind of the control PF from an unfinished firmware pass.

Does firmware provide an acknowledgement that could be polled here, or a documented upper bound on its polling period and cleanup latency?

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5 -0
+	/* ensure registers written */
+	nbl_flush_writes(hw_mgt);
+
+	return 0;
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#10 lore raw

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

In reply to illusion.wang

From: illusion wang <[email protected]>

Allocate dispatch management state and ops table, add ctrl_lvl bitmap to track control privileges, and hook init_module/deinit_module wrappers to resource ops.

MGT level is only enabled for Control PF. Add kerneldoc for caller permission constraints. Add wire ABI structures with static_assert for upcoming mailbox RPC.

Dispatch objects are devm-managed and require no explicit remove logic.

---
 .../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        |  56 +++++++++
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   8 ++
 6 files changed, 207 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 be314b909d66..b7eebd89b4d1 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 dd24ebec0171..4d8cea8d8ab3 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 000000000000..a7e5802344b4
@@ -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 +56 -0

56 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
index cd3774691bf4..86536d582d92 100644
@@ -11,6 +11,7 @@
 #include "nbl_include/nbl_def_channel.h"
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
+#include "nbl_include/nbl_def_dispatch.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -48,7 +49,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_res_init_leonis(adapter);
 	if (ret)
 		goto res_init_fail;
+
+	ret = nbl_disp_init(adapter);
+	if (ret)
+		goto disp_init_fail;
 	return adapter;
+disp_init_fail:
+	nbl_res_remove_leonis(adapter);
 res_init_fail:
 	nbl_chan_remove_common(adapter);
 chan_init_fail:
@@ -59,6 +66,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
 	nbl_hw_remove_leonis(adapter);
Signature · 1 line
2.47.3
#11 lore raw

Re: [PATCH v31 net-next 5/8] net/nebula-matrix: dispatch: add control-level routing core infrastructure

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says this patch will "Add wire ABI structures with static_assert for upcoming mailbox RPC", but the patch adds…
- [Low] At this commit, the kernel-doc on struct nbl_dispatch_ops in nbl_def_dispatch.h (lines 18-43) describes things that are not in the…

--

net/nebula-matrix: dispatch: add control-level routing core infrastructure

This commit allocates the dispatch management state and ops table, adds a ctrl_lvl bitmap to track control privileges, and wires init_module and deinit_module wrappers to the resource ops. The MGT level is enabled only on the control PF.

Quoted 3 lines

MGT level is only enabled for Control PF. Add kerneldoc for caller permission constraints. Add wire ABI structures with static_assert for upcoming mailbox RPC.

[Severity: Low]
This patch doesn't seem to add any wire ABI structures or static_assert checks. The diff only touches the Makefile, nbl_core.h, nbl_dispatch.c, nbl_dispatch.h, nbl_def_dispatch.h and nbl_main.c. None of those files adds a mailbox wire structure or a static_assert.

At this commit, enum nbl_chan_msg_type in nbl_def_channel.h still contains only:

enum nbl_chan_msg_type {
	NBL_CHAN_MSG_ACK = 0,
	/* mailbox msg end */
	NBL_CHAN_MSG_MAILBOX_MAX,
};

The only static_assert under drivers/net/ethernet/nebula-matrix/ is the existing one on struct nbl_board_port_info, which an earlier patch added.

The param structures and their asserts (nbl_chan_param_cfg_msix_map, nbl_chan_param_set_mailbox_irq, nbl_chan_param_get_vsi_id and nbl_chan_param_get_eth_id) first appear in the next patch, "dispatch:
implement channel RPC framework and serialize hardware ops".

Could this sentence be removed from this commit message, or moved to the patch that actually adds the structures?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +0 -0
new file mode 100644
index 0000000000000..08fef0f679268
@@ -0,0 +1,56 @@

[ ... ]

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +7 -0
+enum {
+	NBL_DISP_CTRL_LVL_MGT,
+	NBL_DISP_CTRL_LVL_MAX,
+};
+
+/**
+ * struct nbl_dispatch_ops - dispatch control plane operation callbacks

[ ... ]

Quoted 17 lines

+ * @deinit_module: chip-wide teardown, forwarded the same way; on leonis

+ *               it clears driver_status, which starts an asynchronous
+ *               firmware per-PF cleanup pass with no completion status
+ *               bit, waited for best-effort only.  The caller must have
+ *               stopped the mailbox channel and drained all in-flight
+ *               mailbox DMA before calling it, see nbl_dev_remove().
+ *               Returns void.  Control-PF exclusive, same NULL rule as
+ *               @init_module.

+ *
+ * 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.
+ */

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h line 47

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +4 -0
+struct nbl_dispatch_ops {
+	int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);
+	void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt);
+};

[Severity: Low]
This isn't a bug, but at this commit the kernel-doc for struct nbl_dispatch_ops describes code that isn't in the tree yet.

It refers callers to nbl_dev_remove(). That function doesn't exist yet, because nbl_dev.c hasn't been added at this point.

It also describes five PF-only ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id), has_net routing over mailbox RPC, and -EPERM responders. The struct itself has only init_module and deinit_module, and the enum has only NBL_DISP_CTRL_LVL_MGT and NBL_DISP_CTRL_LVL_MAX. nbl_disp_refresh_ctrl_ops() also installs only the two module ops, and only under the MGT level.

Later patches in the series fill this in. The next patch, "dispatch:
implement channel RPC framework and serialize hardware ops", adds NBL_DISP_CTRL_LVL_NET, the five ops and the responders. The patch after that, "add common/ctrl dev init/remove operation", adds nbl_dev_remove() in nbl_dev.c. At the end of the series the comment matches the code; it only runs ahead of the code at the intermediate commits.

Would it make sense to split this comment so each part lands with the code it documents?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#12 lore raw

PATCH v31 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.

nbl_disp_remove() documents why the five responders, which are owned by the channel layer, need no explicit unregistration.

---
 .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 556 +++++++++++++++++-
 .../nbl/nbl_include/nbl_def_channel.h         |  40 ++
 .../nbl/nbl_include/nbl_def_dispatch.h        |  21 +
 3 files changed, 616 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +555 -1
index 966fee2dec8b..e2d98b7c391b 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,14 +632,40 @@ int nbl_disp_init(struct nbl_adapter *adapter)
 	adapter->core.disp_mgt = disp_mgt;
 	adapter->intf.dispatch_ops_tbl = disp_ops_tbl;
 
+	ret = nbl_disp_setup_msg(disp_mgt);
+	if (ret)
+		return ret;
+
 	if (common->has_ctrl)
 		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_MGT);
 
+	if (common->has_net)
+		nbl_disp_set_ctrl_bit(disp_mgt, NBL_DISP_CTRL_LVL_NET);
 	nbl_disp_refresh_ctrl_ops(disp_mgt);
 	return 0;
 }
 
 void nbl_disp_remove(struct nbl_adapter *adapter)
 {
-	/* 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()
+	 *          -> 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_channel.h +40 -0
index bf971121d2ec..5aa16d4cd432 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 +21 -0
index 08fef0f67926..bcd74b9df827 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,6 +33,16 @@ 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 to the upper layers instead.
  *
  * Warning: init_module/deinit_module are control-PF exclusive. The five
  * resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq,
@@ -44,6 +55,16 @@ enum {
 struct nbl_dispatch_ops {
 	int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);
 	void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt,
+			    u16 num_net_msix, u16 num_others_msix,
+			    bool net_msix_mask_en);
+	int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt);
+	int (*set_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt,
+			       u16 vector_id, bool en_msix);
+	int (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt, u16 type,
+			  u16 *vsi_id);
+	int (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt, u16 vsi_id,
+			  u8 *eth_num, u8 *eth_id, u8 *logic_eth_id);
 };
 
 struct nbl_dispatch_ops_tbl {
Signature · 1 line
2.47.3
#13 lore raw

Re: [PATCH v31 net-next 6/8] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Baseline decision is false: in the final state of the series this is not a bug.
- [Low] The kernel-doc this patch adds for struct nbl_dispatch_ops in nbl_def_dispatch.h says the new callbacks 'forward chip/firmware…

--

net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops

This patch adds mailbox RPC requests and responders for five dispatch ops:
cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Each op is chosen by capability level. A has_ctrl function calls the resource layer locally, and a has_net function forwards the request to the management PF over the channel. nbl_disp_remove() gains a comment that explains why the registered responders are never unregistered.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0 -0
index 966fee2dec8b0..e2d98b7c391b4 100644

[ ... ]

Quoted 9 lines

void nbl_disp_remove(struct nbl_adapter *adapter) {

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +6 -1
-	/* 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

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 665

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10 -0
+	 * 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()
+	 *          -> destroy_wq()                       // no new work
+	 *          -> nbl_chan_remove_msg_handler()      // free handler nodes

[Severity: Low]
This isn't a bug, but does this comment describe code that exists at this commit?

clean_mbx_task doesn't appear anywhere in the tree yet. Nothing calls chan_ops->setup_queue at this point either, so the mailbox RX path that this sequence quiesces is never active.

The ordering the comment relies on is nbl_dev_remove() doing the mailbox teardown before nbl_disp_remove(), nbl_res_remove_leonis() and nbl_chan_remove_common(). That ordering only arrives with the later "net/nebula-matrix: add common/ctrl dev init/remove operation" patch.

Also, destroy_wq() looks like shorthand for nbl_common_destroy_wq().

Could this comment move to the patch that introduces that teardown ordering, and use the real function names?

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +5 -0
+	 *
+	 * 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.
+	 */
 }

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0 -0
index 08fef0f679268..bcd74b9df8275 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0 -0
@@ -32,6 +33,16 @@ enum {
  *               mailbox DMA before calling it, see nbl_dev_remove().
  *               Returns void.  Control-PF exclusive, same NULL rule as
  *               @init_module.

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 45

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +10 -0
+ * @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 to the upper layers instead.

[Severity: Low]
Is "upper layers" the right direction here? The new callbacks forward downward, for example:

nbl_disp_cfg_msix_map()

    return res_ops->cfg_msix_map(p, common->mgt_pf, num_net_msix,
                                 num_others_msix, net_msix_mask_en);

The nbl_disp_chan_*_req() variants call chan_ops->send_msg() instead.

The resource and channel layers both sit below dispatch, and nbl_dev is the caller. Later patches in the series don't change this text, so the wording stays as it is.

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0 -0
  *
  * Warning: init_module/deinit_module are control-PF exclusive. The five
  * resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq,

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#14 lore raw

PATCH v31 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      | 276 ++++++++++++++++++
 .../nebula-matrix/nbl/nbl_core/nbl_dev.h      |  55 ++++
 .../nbl/nbl_include/nbl_def_dev.h             |  14 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |   9 +
 6 files changed, 356 insertions(+)
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
 create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
index b7eebd89b4d1..71fbe3ee7e62 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 4d8cea8d8ab3..c3c4dd685bf6 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 +276 -0

276 lines not on this page · raw message

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

55 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
new file mode 100644
index 000000000000..51cf04e4c552
@@ -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 86536d582d92..6aacfadd8c0e 100644
@@ -12,6 +12,7 @@
 #include "nbl_include/nbl_def_hw.h"
 #include "nbl_include/nbl_def_resource.h"
 #include "nbl_include/nbl_def_dispatch.h"
+#include "nbl_include/nbl_def_dev.h"
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
@@ -53,7 +54,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 	ret = nbl_disp_init(adapter);
 	if (ret)
 		goto disp_init_fail;
+
+	ret = nbl_dev_init(adapter);
+	if (ret)
+		goto dev_init_fail;
 	return adapter;
+
+dev_init_fail:
+	nbl_disp_remove(adapter);
 disp_init_fail:
 	nbl_res_remove_leonis(adapter);
 res_init_fail:
@@ -66,6 +74,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 
 void nbl_core_remove(struct nbl_adapter *adapter)
 {
+	nbl_dev_remove(adapter);
 	nbl_disp_remove(adapter);
 	nbl_res_remove_leonis(adapter);
 	nbl_chan_remove_common(adapter);
Signature · 1 line
2.47.3
#15 lore raw

Re: [PATCH v31 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove operation

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 3

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] On the control PF, nbl_dev_init() runs its steps in an order that conflicts with the stale-status recovery in nbl_hw_init_module().
- [Low] On the control PF, nbl_dev_init() writes NBL_MAILBOX_QINFO_MAP_REG_ARR entries for every enabled PF (via…
- [Low] The error-path comment in nbl_dev_setup_common_dev() says no unwinding is needed after a failed setup_queue() because the partially…
- [Low] nbl_dev_remove_common_dev() calls nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX, NULL) right…

--

net/nebula-matrix: add common/ctrl dev init/remove operation

This adds nbl_dev.c with nbl_dev_init() and nbl_dev_remove(). On every PF they set up the mailbox channel queue and its clean work. On the control PF they also program the mailbox QINFO routing and run init_module. The new entry points are called from nbl_core_init() and nbl_core_remove().

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0 -0
new file mode 100644
index 0000000000000..390bc2b177e21

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2 -0
+static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)
+{

[ ... ]

Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +5 -0
+	ret = nbl_dev_setup_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+	if (ret) {
+		/*
+		 * Nothing to unwind: chan_info->active is only set on a
+		 * successful setup_queue(), so a failed one left no

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 122

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+		 * sender, no registered work item and no mailbox
+		 * traffic.  Calling teardown_queue() here would only
+		 * take its "channel not active" early exit and emit a
+		 * misleading duplicate-teardown warning.  The partially
+		 * allocated DMA rings are intentionally kept until devres
+		 * releases them at detach (chan_info->dma_allocated
+		 * blocks a re-setup).
+		 */
+		return ret;
+	}

[Severity: Low]
Is the "chan_info->dma_allocated blocks a re-setup" part of this comment accurate? nbl_chan_setup_queue() clears the flag again when nbl_chan_init_queue() fails:

nbl_channel/nbl_channel.c:nbl_chan_setup_queue() {
    ...
	chan_info->dma_allocated = true;
	err = nbl_chan_init_queue(common, chan_info);
	if (err) {
		chan_info->dma_allocated = false;
		return err;
	}
    ...
}

The TX and RX init helpers use dmam_alloc_coherent() and devm_kcalloc(). They free nothing on a partial failure, for example when the TX rings are allocated and the RX descriptor allocation then fails.

After such a failure, active and dma_allocated are both false. A second setup_queue() would get past both checks and allocate a second set of coherent rings, and the first set would be orphaned until detach.

The channel code has its own comment just above that reset ("a retry must be rejected instead of allocating a second set and orphaning the first one"), and the reset contradicts it as well.

Nothing retries today, so for now the comment just doesn't match the code.

Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +8 -0
+static void nbl_dev_remove_common_dev(struct nbl_adapter *adapter)
+{
+	struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+	struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+
+	if (!common_dev)
+		return;
+	cancel_work_sync(&common_dev->clean_mbx_task);

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 153

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +3 -0
+	nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+	nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX, NULL);
+}

[Severity: Low]
Does the nbl_dev_register_chan_task(..., NULL) call here have any effect?

common_dev is only set after setup_queue() succeeds, so the channel is always active by the time this runs. nbl_chan_teardown_queue() then sets shutdn and clears clean_task under state_lock. After that, nbl_chan_register_chan_task() ignores the write:

nbl_channel/nbl_channel.c:nbl_chan_register_chan_task() {
    ...
	mutex_lock(&chan_info->state_lock);
	if (!READ_ONCE(chan_info->shutdn))
		WRITE_ONCE(chan_info->clean_task, task);
	mutex_unlock(&chan_info->state_lock);
}

teardown_queue() does the real unregister and drain: it clears clean_task and calls cancel_work_sync() on it. The cancel_work_sync() above runs before teardown, while the sender poll paths can still re-queue the work.

This has no functional effect today. The problem is that this sequence reads as if the dev layer does the unregister and drain, when the channel layer actually does it. Could the NULL registration be dropped, or a comment added saying which layer is responsible?

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2 -0
+int nbl_dev_init(struct nbl_adapter *adapter)
+{

[ ... ]

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +7 -0
+	adapter->core.dev_mgt = dev_mgt;
+	if (common->has_ctrl)
+		nbl_dev_setup_chan_qinfo(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+	/*
+	 * Chip hardware initialization is completed by firmware at power-up.
+	 * Only driver functional table/register config follows here, safe to
+	 * access hardware registers before ctrl dev setup.

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 242

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10 -0
+	 */
+	ret = nbl_dev_setup_common_dev(adapter);
+	if (ret)
+		goto setup_err;
+
+	if (common->has_ctrl) {
+		ret = nbl_dev_setup_ctrl_dev(adapter);
+		if (ret)
+			goto setup_ctrl_dev_fail;
+	}

[Severity: High]
Can this ordering make firmware wipe the mailbox state that this probe has just programmed?

On the control PF the sequence is:

nbl_dev_init()
nbl_dev_setup_chan_qinfo() /* QINFO routing for all PFs */
nbl_dev_setup_common_dev()
nbl_chan_setup_queue() /* TX/RX queue config, active=true */
nbl_dev_setup_ctrl_dev()
init_module -> nbl_hw_init_module()

If the active bit in NBL_DRIVER_STATUS_REG is still set, nbl_hw_init_module() forces it from 1 to 0:

nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c:nbl_hw_init_module() {
    ...
	status = nbl_hw_rd32(hw_mgt, NBL_DRIVER_STATUS_REG);
	if (status & BIT(NBL_DRIVER_STATUS_BIT)) {
		dev_warn(hw_mgt->common->dev,
			 "driver_status already set at init, cleanup forced\n");
		nbl_hw_set_driver_status(hw_mgt, false);
		nbl_flush_writes(hw_mgt);
		usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US,
			     NBL_FW_CLEANUP_SYNC_MAX_US);
    ...
}

The bit can still be set after kexec or kdump, because nbl_pci_driver has no .shutdown callback. It can also be set after an unload that never reached deinit_module().

The commit message says firmware asynchronously reclaims "mailbox QINFO routing, qinfo registers and the like" when the bit goes from 1 to 0. Here that happens after the new routing and the live queue registers are in place. Nothing later in init, or in the start path, programs them again.

Wouldn't that leave the control PF mailbox dead, so that sibling-PF RPCs in nbl_dev_start() time out? Firmware could also reclaim the routing while a mailbox transfer is in flight, which is the hazard the teardown ordering is meant to avoid.

Should the stale-status cleanup run before nbl_dev_setup_chan_qinfo() and setup_queue()?

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 249

Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +7 -0
+
+	return 0;
+setup_ctrl_dev_fail:
+	nbl_dev_remove_common_dev(adapter);
+setup_err:
+	return ret;
+}

[Severity: Low]
Do these error paths leave the NBL_MAILBOX_QINFO_MAP_REG_ARR entries written by nbl_dev_setup_chan_qinfo() in hardware?

The comment above nbl_dev_remove_ctrl_dev() says the map "is not explicitly cleared; firmware handles it on driver_status change". But neither label clears the entries or calls deinit_module().

This applies in two cases:

- nbl_dev_setup_common_dev() fails.
- nbl_hw_init_module() fails, either in the eth_speed/eth_num checks or in nbl_dp_init(). Both return before nbl_hw_set_driver_status(true).

In both cases driver_status never goes from 1 to 0, so the firmware reclaim never runs. The routing entries stay until a later successful probe overwrites them or the chip is reset.

The practical impact looks small, since sibling PFs can't bind without the control PF. The hardware state still no longer matches what the driver thinks it is.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com
author maintainer
#16 lore raw

PATCH v31 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.

The start/stop pair is single-shot and non-repeatable, tied strictly to the PCI probe/remove lifecycle: kernel vectors are released only by the pcim_msi_release devres at detach, so a second start is rejected.

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 completed probing, and that completion includes the control PF's own start, whose mailbox responder has been live since nbl_dev_init(). Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay the multi-second wait again.

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, freed by a later successful configuration of this function or by nbl_intr_mgt_stop() - not firmware state. 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      | 391 ++++++++++++++++++
 .../nbl/nbl_include/nbl_def_dev.h             |   2 +
 .../net/ethernet/nebula-matrix/nbl/nbl_main.c |  18 +
 4 files changed, 419 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +8 -0
index c3c4dd685bf6..655dfb43e365 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 +391 -0

412 lines not on this page · raw message

drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
index 51cf04e4c552..a66c633a0e7a 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 +18 -0
index 6aacfadd8c0e..cacf4b680aad 100644
@@ -16,6 +16,16 @@
 #include "nbl_include/nbl_def_common.h"
 #include "nbl_core.h"
 
+int nbl_core_start(struct nbl_adapter *adapter)
+{
+	return nbl_dev_start(adapter);
+}
+
+void nbl_core_stop(struct nbl_adapter *adapter)
+{
+	nbl_dev_stop(adapter);
+}
+
 struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
 				  struct nbl_init_param *param)
 {
@@ -234,7 +244,13 @@ static int nbl_probe(struct pci_dev *pdev,
 		goto adapter_init_err;
 	}
 	pci_set_drvdata(pdev, adapter);
+	err = nbl_core_start(adapter);
+	if (err)
+		goto core_start_err;
+
 	return 0;
+core_start_err:
+	nbl_core_remove(adapter);
 adapter_init_err:
 chip_deps_err:
 	pci_clear_master(pdev);
@@ -248,6 +264,8 @@ static void nbl_remove(struct pci_dev *pdev)
 	if (!adapter)
 		return;
 	pci_set_drvdata(pdev, NULL);
+
+	nbl_core_stop(adapter);
 	nbl_core_remove(adapter);
 
 	pci_clear_master(pdev);
Signature · 1 line
2.47.3
#17 lore raw

Re: [PATCH v31 net-next 8/8] net/nebula-matrix: add common dev start/stop operation

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] nbl_probe() now calls nbl_core_start() -> nbl_dev_start() for every adapter that nbl_core_init() returns.
- [Low] In nbl_dev_disable_mailbox_irq() (drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c), the comment says the helper runs in…
- [Low] The err_free_irq comment in nbl_dev_start() (nbl_dev.c) explains skipping set_mailbox_irq(false) by saying it 'would only add one more…

--

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

This patch adds nbl_dev_start() and nbl_dev_stop(). They are called from nbl_probe() and nbl_remove() through nbl_core_start() and nbl_core_stop(). Start configures the MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt; stop does the matching best-effort teardown.

Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0 -0
index 390bc2b177e21..41754fd06ea36 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0 -0
@@ -18,6 +29,230 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2 -0
+static int nbl_dev_disable_mailbox_irq(struct nbl_dev_mgt *dev_mgt)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 147

Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +6 -0
+	 * This helper is invoked in two paths:
+	 * 1. Error unwind path of nbl_dev_start(): not reached with
+	 * IRQ_RDY set (nbl_dev_enable_mailbox_irq() sets it only after
+	 * its RPC succeeded), so only the hardware mask still applies,
+	 * followed by nbl_dev_free_mailbox_irq() and full channel
+	 * teardown.

[Severity: Low]
Is the description of the first path accurate? nbl_dev_start() never calls nbl_dev_disable_mailbox_irq(). Its err_free_irq label calls only nbl_dev_free_mailbox_irq() and then falls through to err_destroy_map:

err_free_irq:

	nbl_dev_free_mailbox_irq(dev_mgt);
err_destroy_map:
	cleanup_ret = nbl_dev_destroy_msix_map(dev_mgt);
	...
	nbl_dev_clear_interrupt_scheme(dev_mgt);

	cancel_work_sync(&common_dev->clean_mbx_task);

This patch also adds the err_free_irq comment, which says set_mailbox_irq(false) is not sent from that path on purpose. That contradicts this comment.

nbl_dev_start() does no channel teardown either. That only happens later, when nbl_probe() calls nbl_core_remove().

nbl_dev_stop() seems to be the only caller of this helper. The rollback path depends on the routing disable in __nbl_res_intr_prepare_destroy_msix_map(), not on this helper.

Could the comment list only nbl_dev_stop()?

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +1 -0
+	 * 2. Normal device stop path nbl_dev_stop(): free_irq() blocks until

[ ... ]

Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2 -0
+static int nbl_dev_cfg_msix_map(struct nbl_dev_mgt *dev_mgt)
+{

[ ... ]

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 192

Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +3 -0
+	err = disp_ops->cfg_msix_map(dev_mgt->disp_ops_tbl->priv,
+				     msix_net_num, msix_not_net_num,
+				     mask_en);

[Severity: Medium]
Can disp_ops->cfg_msix_map be NULL here?

nbl_probe() now calls nbl_core_start()->nbl_dev_start() for every adapter that nbl_core_init() returns. nbl_dev_start() then calls cfg_msix_map, get_vsi_id and get_eth_id without checking capabilities or NULL. On the unwind path it also calls destroy_msix_map.

nbl_disp_refresh_ctrl_ops() memsets the dispatch ops table. It fills the table only when NBL_DISP_CTRL_LVL_MGT (has_ctrl) or NBL_DISP_CTRL_LVL_NET (has_net) is set.

The struct nbl_dispatch_ops kerneldoc in nbl_def_dispatch.h says:

A function with neither has_ctrl nor has_net leaves these pointers NULL; callers must not invoke them on such functions.

That state looks reachable. Suppose root binds a VF, or a function other than func 0, whose ID is not in nbl_id_table, by writing driver_override=nbl. pci_match_device() then passes the dummy ID:

drivers/pci/pci-driver.c:pci_match_device() {
	...
	/* driver_override will always match, send a dummy id */
	if (ret > 0)
		return &pci_device_id_any;
	...
}

The dummy ID has driver_data 0. nbl_get_func_param() therefore sets has_net to 0, and has_ctrl stays 0:

	param->caps.has_net = !!(driver_data & BIT(NBL_CAP_HAS_NET_BIT));

new_id cannot produce this state, because new_id_store() rejects a driver_data value that matches no table entry.

Now assume func 0 of the same slot is bound to nbl, which nbl_probe_chip_deps() requires, and the init steps succeed. Wouldn't probe then call a NULL function pointer?

nbl_probe()
nbl_core_start()

    nbl_dev_start()
      nbl_dev_cfg_msix_map()
        disp_ops->cfg_msix_map()   <- NULL

Before this patch, nbl_dev_init() used disp_ops only under has_ctrl, so this path is new. Would it make sense to reject !has_ctrl && !has_net early in nbl_probe()?

[ ... ]

Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0 -0
@@ -274,3 +517,151 @@ void nbl_dev_remove(struct nbl_adapter *adapter)

[ ... ]

Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +9 -0
+	ret = nbl_dev_enable_mailbox_irq(dev_mgt);
+	if (ret)
+		goto err_free_irq;
+
+	return 0;
+
+err_free_irq:
+	/*
+	 * nbl_dev_enable_mailbox_irq() only fails before it sets

drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 583

Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10 -0
+	 * NBL_CHAN_IRQ_RDY - the flag is set after its RPC returns - so
+	 * there is no interrupt-mode sender to release and no software
+	 * state to revoke.  The peer-side mailbox routing, if the failed
+	 * RPC did land, is switched off by the destroy_msix_map() below,
+	 * whose prepare phase disables mailbox IRQ routing first.  Sending
+	 * set_mailbox_irq(false) from here would only add one more full
+	 * polling-mode ACK timeout against a peer that just proved
+	 * unresponsive.
+	 */
+	nbl_dev_free_mailbox_irq(dev_mgt);

[Severity: Low]
This isn't a bug, but does the last sentence of this comment hold for every failure? It assumes nbl_dev_enable_mailbox_irq() can only fail through an ACK timeout against an unresponsive peer.

On the control PF, disp_ops->set_mailbox_irq is nbl_disp_set_mailbox_irq(). That is a direct local call: no mailbox, no ACK and no timeout.

	if (!res_ops->set_mailbox_irq)
		return -EOPNOTSUPP;
	return res_ops->set_mailbox_irq(p, common->mgt_pf, vector_id, en_msix);

The resource layer, __nbl_res_intr_set_mailbox_irq(), can fail without touching hardware:

-ESHUTDOWN if intr_mgt->stopping is set -ENODEV if the function is not NBL_INTR_FUNC_CONFIGURED -EINVAL if vector_id is out of range

The responder passes these errors to non-control PFs unchanged.

Skipping set_mailbox_irq(false) still looks correct, because the routing disable in __nbl_res_intr_prepare_destroy_msix_map() covers a CONFIGURED function. Could the comment give that as the reason instead?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261010095939.2230-1-illusion.wang%40nebula-matrix.com