nbl driver for Nebulamatrix NICs
illusion.wang
maintainerv30 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 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 | 1467 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 181 ++ .../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 | 625 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 680 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 25 + .../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 | 1094 ++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 320 ++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 359 ++++ .../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 | 703 ++++++++ .../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 | 121 ++ .../nbl/nbl_include/nbl_def_channel.h | 174 ++ .../nbl/nbl_include/nbl_def_common.h | 23 + .../nbl/nbl_include/nbl_def_dev.h | 16 + .../nbl/nbl_include/nbl_def_dispatch.h | 61 + .../nbl/nbl_include/nbl_def_hw.h | 62 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 32 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 138 ++ 29 files changed, 6536 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
illusion.wang
maintainerPATCH v30 1/8 net/nebula-matrix: add channel layer
From: illusion wang <[email protected]>
Add dedicated mailbox-based generic channel management layer for Nebula Matrix Ethernet adapter, implementing core inter-PF control communication capability between PF0 and other auxiliary PFs.
This patch builds fundamental inter-PF communication infrastructure for multi-PF control plane interaction scenarios. It decouples hardware register operations from business control logic, with complete hardware abstraction and robust error recovery capabilities.
Key features of the new channel layer include:
- Thread-safe message handling based on xarray, supporting O(1) message lookup and duplicate handler protection. Both fire-and-forget and synchronous ACK-based transmission modes are supported.
- TX slot concurrency control, returning -EAGAIN when slots are full to avoid congestion and resource exhaustion. Supports 16B inline small payload and 4KB max DMA-based large payload transmission.
- Devm-managed mailbox queue resources, with one-time DMA allocation during probe. Full hardware queue lifecycle management covers init, runtime configuration, start, stop and teardown.
- Dual interrupt/polling RX processing, offloading cleanup work to dedicated workqueue to reduce IRQ latency. Reliable teardown logic prevents invalid DMA access and message loss.
- Isolated hw_ops layer decouples low-level hardware implementation from upper channel logic. Fine-grained register locking optimizes BAR0/BAR2 access for stability under high stress.
- Complete auxiliary infrastructure including per-channel state control, timeout/retry recovery, and unified message pack/parse helpers for consistent upper-layer calling.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1467 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 181 ++ .../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 | 35 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 2184 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
@@ -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 +1467 -0
1,467 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +181 -0
181 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +31 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +35 -0
@@ -10,6 +10,41 @@struct nbl_hw_mgt ;struct nbl_adapter ; +struct nbl_hw_ops { +void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt, +u16 tail_ptr,u8 txrx); +void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*config_mailbox_txq)(struct nbl_hw_mgt *hw_mgt, +dma_addr_t dma_addr,int size_bwid); +void (*stop_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt); +void (*stop_mailbox_txq)(struct nbl_hw_mgt *hw_mgt); +/** +* get_host_pf_mask - Fetch host PF mask from firmware k_pf_mask reg +* @hw_mgt: hardware management context +* @pf_mask: output pointer for PF mask value +* +* k_pf_mask register rule: +* bit N == 0 -> PF#N enabled; bit N == 1 -> PF#N masked out. +* bit0 is PF0's mask bit (not reserved); PF0 can be masked but +* the driver requires at least PF0 enabled. +* Only 1/2/4 PFs are supported: +* 1 PF (PF0): mask = 0xfe +* 2 PFs (PF0,PF1): mask = 0xfc +* 4 PFs (PF0~PF3): mask = 0xf0 +* All-zero mask (0x00) means all 8 PFs enabled, which is +* unsupported by the driver and rejected with -EINVAL. +*/ +void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask); + +void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +u8 bus,u8 devid,u8 function); +}; + +struct nbl_hw_ops_tbl { +struct nbl_hw_ops *ops; +struct nbl_hw_mgt *priv; +};int nbl_hw_init_leonis (struct nbl_adapter *adapter);void nbl_hw_remove_leonis (struct nbl_adapter *adapter);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +3 -0
@@ -10,6 +10,9 @@/* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl" +#define NBL_MAX_PF 8 +#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +7 -0
@@ -8,6 +8,7 @@#include <linux/module.h> #include <linux/bits.h> #include "nbl_include/nbl_include.h" +#include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -38,13 +39,19 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,if (ret) goto hw_init_fail; + ret =nbl_chan_init_common (adapter); +if (ret) + goto chan_init_fail;return adapter; +chan_init_fail: +nbl_hw_remove_leonis (adapter); hw_init_fail:return ERR_PTR (ret); }void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 net-next 1/8] net/nebula-matrix: add channel layer
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: 0 · Medium: 1 · Low: 6
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_chan_alloc_all_tx_bufs() and nbl_chan_alloc_all_rx_bufs() make a separate dmam_alloc_coherent(dev, 4096, ...) call for each of…
- [Low] Most of the channel layer (setup_queue, teardown_queue, send_msg, cfg_chan_qinfo_map_table, clean_queue_subtask, register_chan_task,…
- [Low] Some specific claims in the commit message don't match the code.
- [Low] The get_host_pf_mask kernel-doc says unsupported masks are 'rejected with -EINVAL', and nbl_chan_cfg_qinfo_map_table() defers…
- [Low] The lock comments in struct nbl_chan_info are wrong.
- [Low] send_msg, clean_queue and set_queue_state do not check chan_info->active.
- [Low] If setup fails partway, its devres/dmam allocations are orphaned when setup is retried.
--
net/nebula-matrix: add channel layer
This adds a mailbox-based channel layer to the nbl driver. It carries control messages between PF0 and the other PFs. The patch adds the channel ops table, TX/RX ring handling with ACK tracking, a workqueue for RX cleanup, and the BAR0/BAR2 hw_ops that program the mailbox queues.
Quoted 3 lines
- TX slot concurrency control, returning
-EAGAINwhen slots are full to avoid congestion and resource exhaustion. Supports 16B inline small payload and 4KB max DMA-based large payload transmission.
[ ... ]
Quoted 3 lines
- Isolated
hw_opslayer decouples low-level hardware implementation from upper channel logic. Fine-grained register locking optimizes BAR0/BAR2 access for stability under high stress.
[Severity: Low]
Do these claims match the code?
nbl_chan_get_msg_id() returns -EAGAIN when the ACK wait slots run out. When the descriptor ring is full, though, nbl_chan_update_txqueue() returns -EBUSY:
if (nbl_chan_txq_full(txq, chan_info->num_txq_entries)) return -EBUSY; if (param->arg_len > NBL_CHAN_BUF_LEN - sizeof(*tx_desc)) return -EINVAL;
That same check caps the payload at 4096 - 64 = 4032 bytes, not 4KB. nbl_chan_send_ack() allows 12 bytes less than that.
On locking, the patch adds only one reg_lock spinlock, and only the BAR0 helpers take it (nbl_hw_rd_regs_lock() and nbl_hw_cfg_mailbox_qinfo()). nbl_hw_read_mbx_regs(), nbl_hw_write_mbx_regs() and the doorbell write in nbl_hw_update_mailbox_queue_tail_ptr() go through BAR2 without any register lock.
Could the commit message be updated to match?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1467 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 193
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +12
-0+static int nbl_chan_alloc_all_tx_bufs (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *txq = &chan_info->txq; +struct device *dev = chan_mgt->common->dev; +struct nbl_chan_buf *buf; +u16 i; + +for (i =0 ; i < chan_info->num_txq_entries; i++) { + buf = &txq->buf[i]; + buf->va =dmam_alloc_coherent (dev, chan_info->txq_buf_size, + &buf->pa,GFP_KERNEL );
[Severity: Medium]
Is one coherent allocation per ring entry intended here? nbl_chan_alloc_all_rx_bufs() does the same, so each PF makes 512 separate dmam_alloc_coherent(dev, 4096, ...) calls.
Coherent allocations are rounded up to whole pages. On 16K or 64K page kernels (arm64, ppc64le), one PF's mailbox uses 8 MiB or 32 MiB of coherent memory, not the ~2 MiB the comment in nbl_chan_setup_queue() assumes. The driver can build for these, since Kconfig only requires 64BIT and !CPU_BIG_ENDIAN. A 4-PF card with 64K pages would use 128 MiB. Each call also adds its own devres node and IOMMU mapping.
Could this be one contiguous allocation split into 4K slots, or a dma_pool?
[ ... ]
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +17
-0+/* +* DMA resources are allocated once and released only by devres +* at device detach. A teardown does not free them, so a second +* setup would orphan ~2 MiB of coherent DMA per channel. +*/ +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 ); + err =nbl_chan_init_queue (common, chan_info); +if (err) +return err; + err =nbl_chan_alloc_all_bufs (chan_mgt, chan_info);
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 498
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+if (err) +return err; +nbl_chan_config_queue (chan_mgt, chan_info, true);/* tx */ +nbl_chan_config_queue (chan_mgt, chan_info, false);/* rx */ +nbl_chan_update_tail_ptr (hw_ops, chan_mgt->hw_ops_tbl->priv, + rxq->tail_ptr,NBL_MB_RX_QID ); +WRITE_ONCE (chan_info->active, true); + chan_info->dma_allocated = true; +return 0 ; +}
[Severity: Low]
What happens if nbl_chan_setup_queue() fails partway, for example in nbl_chan_alloc_all_rx_bufs()? At that point active and dma_allocated are both still false. A second call would get past both checks and allocate everything again. The first set of dmam buffers would stay allocated until detach.
In the rest of the series, setup_queue runs once per probe from nbl_dev_setup_common_dev(), and a failure fails the probe. So no retry path exists today.
Should dma_allocated be set before the first allocation, so the guard does what its comment says?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static int nbl_chan_send_msg (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_send_info *chan_send) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 1038
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +7
-0+mutex_lock (&chan_info->state_lock); +if (READ_ONCE (chan_info->shutdn)) { +mutex_unlock (&chan_info->state_lock); +return -ESHUTDOWN ; + } +atomic_inc (&chan_info->inflight_tx_cnt); +mutex_unlock (&chan_info->state_lock);
[Severity: Low]
Can nbl_chan_send_msg() be called on a channel that hasn't gone through setup_queue? Nothing here checks chan_info->active.
Before setup, num_txq_entries is 0, so this path divides by zero:
nbl_chan_update_txqueue()->nbl_chan_txq_full()
NBL_NEXT_ID(next_to_use, num_entries - 1)
nbl_chan_clean_queue() has a similar problem: before setup it reads through rxq->desc.rx_desc, which is still NULL. nbl_chan_set_queue_state() walks wait[], which can be NULL after a partial setup failure.
In the rest of the series, every caller runs after nbl_dev_setup_common_dev(), so this doesn't look reachable today. Would it be worth checking active in these entry points anyway?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 1354
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +12
-0+static struct nbl_channel_ops chan_ops = { + .send_msg = nbl_chan_send_msg, + .send_ack = nbl_chan_send_ack, + .register_msg = nbl_chan_register_msg, + .cfg_chan_qinfo_map_table = nbl_chan_cfg_qinfo_map_table, + .check_queue_exist = nbl_chan_check_queue_exist, + .setup_queue = nbl_chan_setup_queue, + .teardown_queue = nbl_chan_teardown_queue, + .clean_queue_subtask = nbl_chan_clean_queue_subtask, + .register_chan_task = nbl_chan_register_chan_task, + .set_queue_state = nbl_chan_set_queue_state, +};
[Severity: Low]
This isn't a bug on its own, but most of these ops have no caller in this patch: setup_queue, teardown_queue, send_msg, cfg_chan_qinfo_map_table, clean_queue_subtask, register_chan_task and set_queue_state. nbl_core_init() only calls nbl_chan_init_common().
The commit message describes probe-time DMA allocation and IRQ/polling RX as if they already work here. Later patches in the series add the callers in nbl_dev.c and nbl_dispatch.c.
Could the commit message say that queue setup and the RX paths are wired up in later patches?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +0
-0@@ -0,0 +1,181 @@
[ ... ]
Quoted 1 line
+struct
nbl_chan_info{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h line 145
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +4
-0+/* Guards channel state bitmap and shutdn flag */ +struct mutex state_lock; +/* Guards pending requests and pending work list operations */ +struct mutex pending_lock;
[Severity: Low]
Are these lock comments accurate? The state bitmap is never accessed under state_lock. nbl_chan_set_queue_state() changes it without the lock:
if (set) set_bit(state, chan_info->state); else clear_bit(state, chan_info->state);
nbl_chan_send_msg() also tests NBL_CHAN_IRQ_RDY without the lock. The code relies on atomic bitops instead.
There is also no pending work list. pending_lock seems to guard the wait[] slot array.
Could the comments be updated to say what each lock actually protects?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0
-0@@ -10,6 +10,41 @@
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +7
-0+/** +* get_host_pf_mask - Fetch host PF mask from firmware k_pf_mask reg +* @hw_mgt: hardware management context +* @pf_mask: output pointer for PF mask value +* +* k_pf_mask register rule: +* bit N == 0 -> PF#N enabled; bit N == 1 -> PF#N masked out.
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h line 38
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +10
-0+* bit0 is PF0's mask bit (not reserved); PF0 can be masked but +* the driver requires at least PF0 enabled. +* Only 1/2/4 PFs are supported: +* 1 PF (PF0): mask = 0xfe +* 2 PFs (PF0,PF1): mask = 0xfc +* 4 PFs (PF0~PF3): mask = 0xf0 +* All-zero mask (0x00) means all 8 PFs enabled, which is +* unsupported by the driver and rejected with -EINVAL. +*/ +void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask);
[Severity: Low]
Where does the -EINVAL rejection described here happen? The comment in nbl_chan_cfg_qinfo_map_table() also defers to a check this patch doesn't contain:
* Non-contiguous or unsupported PF count
* will be rejected in resource initialization logic.
Later in the series, "net/nebula-matrix: add common resource implementation" adds nbl_res_init_pf_num(), which does this check. It runs before cfg_chan_qinfo_map_table is called, so at the end of the series only these comments are affected.
Could the comments point to where the check lives, or be added in the same patch as the check?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 2/8 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: 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 | 67 +++- .../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 | 15 + .../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, 728 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
@@ -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
@@ -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
@@ -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 +65 -2
102 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +15 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +15 -0
@@ -8,9 +8,11 @@#include <linux/types.h> +struct nbl_board_port_info ;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +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,
@@ -36,9 +38,22 @@ struct nbl_hw_ops {* unsupported by the driver and rejected with -EINVAL. */ 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
@@ -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
@@ -13,6 +13,12 @@#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +#define NBL_MAX_ETHERNET 4 + +enum { +NBL_VSI_DATA =0 , +}; +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
@@ -10,6 +10,7 @@#include "nbl_include/nbl_include.h" #include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" +#include "nbl_include/nbl_def_resource.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -27,6 +28,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, adapter->pdev = pdev; common = &adapter->common; + common->mgt_pf =0 ; common->pdev = pdev; common->dev = &pdev->dev; common->has_ctrl = param->caps.has_ctrl;
@@ -42,7 +44,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_chan_init_common (adapter);if (ret) goto chan_init_fail; + + ret =nbl_res_init_leonis (adapter); +if (ret) + goto res_init_fail;return adapter; +res_init_fail: +nbl_chan_remove_common (adapter); chan_init_fail:nbl_hw_remove_leonis (adapter); hw_init_fail:
@@ -51,6 +59,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 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] Baseline: the out-of-bounds MMIO hazard is not reachable, but the comment is wrong.
--
net/nebula-matrix: add common resource implementation
This patch adds a chip-agnostic resource layer for the Nebula Matrix driver. It builds read-only PF topology, SR-IOV BDF, Ethernet port and VSI tables on the control PF at probe time. It also adds several new hw_ops, including flush_write, get_real_bus, get_fw_eth_map and get_board_info.
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -97,6 +97,32 @@ static void nbl_hw_rd_regs_lock(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 *data,spin_unlock (&hw_mgt->reg_lock); }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c static void nbl_hw_rd_regs_lock(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 *data, · line 109
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+/* +* Only call this when has_ctrl=true, which maps enough space +* (bar_len - 8192) to cover NBL_HW_DUMMY_REG (0x1300904). +* The flow/design guarantees this is only called in the +* has_ctrl path. +*/ +static void nbl_flush_writes (struct nbl_hw_mgt *hw_mgt) +{ +nbl_hw_rd32 (hw_mgt,NBL_HW_DUMMY_REG ); +}
[Severity: Low]
Is the "(bar_len - 8192)" part of this comment accurate? The has_ctrl path in nbl_hw_init_leonis() does not size the mapping from bar_len:
hw_size = PAGE_ALIGN_DOWN(NBL_MEM_BAR_TOTAL_SIZE -
NBL_RDMA_NOTIFY_LEN);
hw_mgt->hw_addr =
pcim_iomap(pdev, NBL_MEMORY_BAR,
hw_size);The size is fixed and does not depend on bar_len. It is also smaller than 64 MiB - 8 KiB when PAGE_SIZE is larger than 8 KiB.
The has_ctrl-only rule is also written only in this comment. The flush_write member of struct nbl_hw_ops in nbl_def_hw.h says nothing about it, and nbl_hw_setup_ops() installs the op for every PF. That includes net-only PFs, which map only NBL_REG_NET_ONLY_LEN (8 KiB). For those PFs, NBL_HW_DUMMY_REG (0x1300904) is well outside the mapping.
This patch adds no callers. Later in the series, the flush_write callers in nbl_interrupt.c all seem to sit behind has_ctrl checks, so the out-of-bounds read does not look reachable. Could the comment be corrected? Could the has_ctrl requirement also be documented on the flush_write op in nbl_def_hw.h, or enforced in the code?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 3/8 net/nebula-matrix: add intr resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add dedicated nbl_interrupt module to manage chip-internal MSI-X interrupt resource and hardware mapping for Nebula Matrix Ethernet driver.
This module manages driver-wide global hardware MSI-X vector index space, split into independent network and control interrupt bitmaps (intr_net_bmap/ intr_other_bmap), and handles programming of chip-internal MSI-X mapping registers. It explicitly does not manage physical PCI MSI-X entries; physical vector allocation via pci_alloc_irq_vectors() will be implemented in a follow-up patch via nbl_dev_init_interrupt_scheme().
Core functional interfaces:
1. cfg_msix_map: Allocate global hardware MSI-X vectors from separate net/other interrupt bitmaps. Reuse per-function coherent DMA map table on reconfig, eliminating free/realloc cycles, DMA race windows and redundant quiesce sleeps. Only tear down old hardware state after new allocation succeeds to avoid interrupt loss, and program MSI-X table DMA address + control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP.
2. destroy_msix_map: Recycle global vector indices, clear hardware MSI-X mappings, and release DMA/descriptor resources. Implements two-stage teardown:
disable mailbox IRQ routing first, mask vectors, clear hardware VALID bits while retaining live DMA addresses, wait ~1ms for hardware DMA quiescence, then zero table entries and free coherent memory to prevent torn reads.
3. set_mailbox_irq: Toggle PF-specific mailbox MSI-X routing by updating NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured MSI-X map, enabling safe routing cleanup before vector release.
4. cfg_msix_info: Program PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with strict hardware-defined programming order (forward for enable, reverse for teardown) to avoid inconsistent hardware state.
Key design & safety features:
- Self-contained intr_mgt->lock protects global bitmaps and per-function state; all public APIs internally hold the lock, no upper-layer locking required by callers.
- Global cleanup via nbl_intr_mgt_stop(): iterate all function IDs to clean up leftover MSI-X maps. Remote PF maps are originally created via mailbox RPC in later patches; cleanup uses local MMIO writes.
- PF-only support: explicitly reject VF function IDs with -EOPNOTSUPP.
Instantiate the interrupt manager via nbl_intr_mgt_start() during device resource initialization, and attach it to the resource management context.
Add corresponding hardware register definitions, helper functions, resource ops callbacks, and Makefile entries to wire up the new module. The new resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq) are hooked into resource_ops but have no in-tree callers within this patch; invocation will be added in subsequent patches in this series.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 155 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 ++ .../nbl_hw_leonis/nbl_resource_leonis.c | 33 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 703 ++++++++++++++++++ .../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 | 52 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../nbl/nbl_include/nbl_include.h | 4 + 12 files changed, 1054 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
@@ -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 +153 -2
188 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +42 -0
48 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +30 -3
@@ -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,26 @@ 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, which may hold +* maps for remote PFs that are still bound. +*/ +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
@@ -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 +703 -0
703 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 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
@@ -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 +52 -0
72 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
@@ -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);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);
@@ -42,6 +49,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
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id); +int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vector_id,bool en_msix);int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 type,u16 *vsi_id); int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +4 -0
@@ -11,8 +11,12 @@/* ------ Basic definitions ------- */ #define NBL_DRIVER_NAME "nbl"#define NBL_MAX_PF 8 +/* Chip-wide VF budget shared across all PFs */ +#define NBL_MAX_VF 512#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +/* Total PCI functions: PFs plus the chip-wide VF budget */ +#define NBL_MAX_FUNC (NBL_MAX_PF + NBL_MAX_VF)#define NBL_MAX_ETHERNET 4enum {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 net-next 3/8] net/nebula-matrix: add intr resource 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: 0 · Medium: 1 · Low: 6
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] Nothing clears the chip-internal MSI-X routing tables at init:
NBL_PCOMPLETER_FUNCTION_MSIX_MAP (per-function VALID, table DMA…
- [Low] In nbl_res_intr_cfg_msix_map(), a reconfiguration allocates the whole new vector set from intr_net_bmap/intr_other_bmap (the…
- [Low] In nbl_hw_cfg_msix_map(), the valid branch has the comment "clear VALID first, prevent torn read of partial entry", but the code writes…
- [Low] Several comments describe teardown synchronization the code does not implement.
- [Low] struct nbl_interrupt_mgt (nbl_resource.h) embeds func_intr_res[NBL_MAX_FUNC] with NBL_MAX_FUNC = NBL_MAX_PF +…
- [Low] The public entry points nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq() read res_mgt->intr_mgt without a lock,…
- [Low] Before dma_free_coherent() of the MSI-X map table (__nbl_res_intr_destroy_msix_map ->…
--
net/nebula-matrix: add intr resource implementation
This patch adds an nbl_interrupt module. For the control PF, it manages the chip-internal MSI-X vector index space with separate net and other bitmaps, and it programs the chip MSI-X map, info and FID tables. It also adds the cfg_msix_map, destroy_msix_map and set_mailbox_irq resource ops, and a global nbl_intr_mgt_stop() teardown called from nbl_res_remove_leonis().
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -123,6 +137,139 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6
-0+static void nbl_hw_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) +{ +struct nbl_function_msix_map function_msix_map; +
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 188
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+memset (&function_msix_map,0 ,sizeof (function_msix_map)); +if (valid) { +/* clear VALID first, prevent torn read of partial entry */ + function_msix_map.data[0 ] =0 ; + function_msix_map.data[1 ] =0 ; + function_msix_map.data[2 ] =0 ; +nbl_hw_wr_regs_lock (hw_mgt, +NBL_PCOMPLETER_FUNCTION_MSIX_MAP (func_id), + function_msix_map.data, +sizeof (function_msix_map));
[Severity: Low]
Does this write actually clear VALID first? nbl_hw_wr_regs_lock() writes data[0] through data[3] in ascending order, and the VALID bit is in data[2]:
nbl_hw_leonis.h:
/* data[2] */
...
#define NBL_FUNCTION_MSIX_MAP_VALID_MASK BIT(16)
If the entry is already VALID when this branch runs, the two DMA address words get zeroed while the old VALID bit is still set. VALID is cleared third, not first.
That leaves a window where the hardware could see VALID=1 with a zero or half-written address, which is the torn state the comment says it prevents. The teardown branch below avoids this by keeping the live address while it clears VALID.
This needs the entry to be VALID on entry. After prepare/Phase 2 that only happens with stale state from a previous kernel (kexec or forced unload).
Would the comment hold if data[2] were cleared on its own first, or if this first write kept the old address?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+ +/* program full entry and set VALID */
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0@@ -0,0 +1,703 @@
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +15
-0+static int __nbl_res_intr_destroy_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +int ret; + +lockdep_assert_held (&intr_mgt->lock); + +if (intr_mgt->stopping) +return -ESHUTDOWN ; + + ret =__nbl_res_intr_prepare_destroy_msix_map (res_mgt, func_id); +if (ret) +return ret; +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 278
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+* prepare() only transitions CONFIGURED functions; an IDLE func +* has nothing to wait for or complete. +*/ +if (intr_mgt->func_intr_res[func_id].state != +NBL_INTR_FUNC_DESTROYING ) +return 0 ; + +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); + +return __nbl_res_intr_complete_destroy_msix_map (res_mgt, func_id);
[Severity: Low]
Is a fixed 1ms sleep enough to guarantee that the pcompleter has stopped fetching from the table before __nbl_res_intr_complete_destroy_msix_map() calls dma_free_coherent() on it?
The only ordering here is: clear FUNCTION_MSIX_MAP VALID, call flush_write(), then call usleep_range(1000, 1200). Nothing polls a hardware idle or completion status.
nbl_intr_mgt_stop() uses the same wait and calls it "Best-effort only". The reconfig path in nbl_res_intr_cfg_msix_map() also relies on it before recycling vectors and rewriting the live table.
If a table fetch is still in flight after the window, could it hit an unmapped IOVA or reused memory? Is there a status register that could be polled instead?
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 291
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +13
-0+} + +int nbl_res_intr_destroy_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +int ret; + +if (!intr_mgt) +return -EINVAL ; + +mutex_lock (&intr_mgt->lock); + ret =__nbl_res_intr_destroy_msix_map (res_mgt, func_id);
[Severity: Low]
This reads res_mgt->intr_mgt without a lock and then locks the captured object. __nbl_res_intr_destroy_msix_map() above does not use that pointer; it loads res_mgt->intr_mgt again, then dereferences it for lockdep_assert_held() and intr_mgt->stopping. __nbl_res_intr_set_mailbox_irq() does the same, and its enable path dereferences intr_mgt->stopping.
nbl_intr_mgt_stop() clears the pointer while it holds the mutex:
res_mgt->intr_mgt = NULL; mutex_unlock(&intr_mgt->lock);
Suppose a caller was blocked on the mutex during stop's Phase 2. Wouldn't it take the lock, read NULL in the helper, and dereference it?
And if a caller captured the pointer before nbl_res_remove_leonis() returned, wouldn't it lock a mutex in devres-freed memory?
With the teardown ordering at the end of the series, no concurrent caller seems possible. nbl_dev_remove() tears down the mailbox and cancels clean_mbx_task before nbl_res_remove_leonis() runs, and device links unbind sibling PFs first. The stop() comment does expect racing callers, though.
Could the helpers take intr_mgt as a parameter from the locked caller?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+mutex_unlock (&intr_mgt->lock); + +return ret; +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 432
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+/* Allocate net interrupt vectors */ +for (i =0 ; i < num_net_msix; i++) { + intr_index =find_first_zero_bit (intr_mgt->intr_net_bmap, +NBL_MAX_NET_INTERRUPT ); +if (intr_index ==NBL_MAX_NET_INTERRUPT ) { +dev_err (dev,"No free net interrupt vectors left\n" ); + ret = -EAGAIN ; + goto release_vecs_unlock; + }
[Severity: Low]
On reconfiguration, the whole new vector set is taken from intr_net_bmap and intr_other_bmap here while the function's old vectors are still set. The old ones are only released later, in the had_config block:
nbl_intr_release_bitmap(res_mgt, old_interrupts, old_num);
A reconfig therefore needs free room for the whole new request on top of the old one. When the pool is nearly full, even a reconfig of the same size or smaller fails with -EAGAIN, although the old config stays intact.
This follows from the "Only tear down old hardware state after new allocation succeeds" design. In-tree callers at the end of the series ask for one other vector per PF (nbl_dev_init_msix_cnt()), so they can't use up the pool. Is this capacity limit intended?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +6
-0+static struct nbl_interrupt_mgt *nbl_intr_setup_mgt (struct device *dev) +{ +struct nbl_interrupt_mgt *intr_mgt; +int err; + + intr_mgt =devm_kzalloc (dev,sizeof (*intr_mgt),GFP_KERNEL );
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 625
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+if (!intr_mgt) +return ERR_PTR (-ENOMEM ); + + err =devm_mutex_init (dev, &intr_mgt->lock); +if (err) +return ERR_PTR (err); + + intr_mgt->stopping = false; +bitmap_zero (intr_mgt->intr_net_bmap,NBL_MAX_NET_INTERRUPT ); +bitmap_zero (intr_mgt->intr_other_bmap,NBL_MAX_OTHER_INTERRUPT );
[Severity: Medium]
Only software state is reset here. Does anything clear the chip-internal tables at init, namely NBL_PCOMPLETER_FUNCTION_MSIX_MAP, NBL_PADPT_HOST_MSIX_INFO and NBL_PCOMPLETER_HOST_MSIX_FID_TABLE?
The comment above nbl_hw_set_mailbox_irq() says this chip state survives kexec/forced unload without FLR. The pci_driver also has no .shutdown callback.
After kexec or kdump, the old kernel's VALID map entries would still point at DMA table addresses the new kernel no longer owns. INFO/FID entries would also remain for gvecs that the new bitmaps treat as free.
nbl_intr_mgt_stop() only cleans functions whose software state is CONFIGURED, so this stale state is never cleaned up.
On a fresh config (had_config == false), nbl_res_intr_cfg_msix_map() also arms the new INFO/FID entries before it overwrites the map entry, which may still be VALID from the old kernel:
for (i = 0; i < requested; i++) {
...
hw_ops->cfg_msix_info(res_mgt->hw_ops_tbl->priv,
func_id, true, gvec, ...);
}
...
hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
true, official_tbl->dma, ...);That doesn't match the "not yet valid (on fresh config)" comment above it.
Could the pcompleter then DMA-read a map table at an old-kernel address, or route a stale map into gvecs that were just given to another function?
In this series, nbl_hw_cfg_mailbox_qinfo() disarms mailbox routing, so whether this triggers depends on how the hardware fetches and on future interrupt sources.
Would it make sense to invalidate these tables for all functions during control-PF init, the same way the mailbox MSIX fields are scrubbed?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +3
-0+ +return intr_mgt; +}
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+/* +* Phase 1: batch invalidate all hardware MSIX map entries. +* stopping is set under the lock, so any caller racing with the +* quiesce window below either holds the lock and sees stopping +* at its next checkpoint, or acquires it after this phase and +* fails (-ESHUTDOWN/-EBUSY/-ENODEV) before issuing MMIO. +*/ +mutex_lock (&intr_mgt->lock); + intr_mgt->stopping = true;
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +11
-0+mutex_unlock (&intr_mgt->lock); + +/* +* Global quiesce: wait for straggler DMA table reads after all +* MSIX map entries have been invalidated in hardware, before +* freeing coherent memory. Best-effort only. +*/ +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); + +/* Phase2: safely release MSIX coherent memory and intr resources */ +mutex_lock (&intr_mgt->lock);
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 703
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+/* Clear the published pointer under the lock, last */ + res_mgt->intr_mgt =NULL ; +mutex_unlock (&intr_mgt->lock); +}
[Severity: Low]
Some comments here and in nbl_resource.h don't seem to match the code.
The enum nbl_intr_func_state comment says:
* the hardware-DMA quiesce window of a teardown; the lock is held across
* that window so a concurrent configuration cannot install a map that
However, nbl_intr_mgt_stop() drops the lock after Phase 1, sleeps, and takes it again for Phase 2. In that window, correctness depends on the stopping flag, which the comment doesn't mention.
The Phase 1 comment says racing callers fail with -ESHUTDOWN/-EBUSY/-ENODEV "before issuing MMIO". But the en_msix=false branch of __nbl_res_intr_set_mailbox_irq() runs 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;
}So that branch writes NBL_MAILBOX_QINFO_MAP_REG_ARR and returns 0. After stop completes, callers get -EINVAL, which the comment doesn't list either.
"Clear the published pointer under the lock, last" suggests that readers synchronize on intr_mgt->lock. Every public entry point reads res_mgt->intr_mgt without holding it, though.
Could these comments be updated to describe the actual contract?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +0
-0@@ -17,6 +17,53 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h line 65
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +7
-0+struct nbl_interrupt_mgt { +struct mutex lock;/* Protects bitmap + func_intr_res[] */ + DECLARE_BITMAP(intr_net_bmap, NBL_MAX_NET_INTERRUPT); + DECLARE_BITMAP(intr_other_bmap, NBL_MAX_OTHER_INTERRUPT); +bool stopping;/* set on teardown, rejects new configurations */ +struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC ]; +};
[Severity: Low]
This isn't a bug, but func_intr_res[] is sized by NBL_MAX_FUNC (NBL_MAX_PF + NBL_MAX_VF = 520). Each entry is about 48 bytes on 64-bit, so struct nbl_interrupt_mgt comes to about 25 KB. That makes the devm_kzalloc() in nbl_intr_setup_mgt() a physically contiguous order-3 allocation.
Only PF entries can ever be used. nbl_res_func_id_to_bdf() returns -EOPNOTSUPP for rel_pf_id >= max_pf before func_intr_res[] is touched. nbl_intr_mgt_stop() also walks all 520 entries twice.
Could this be sized by NBL_MAX_PF, or allocated with devm_kvzalloc()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 4/8 net/nebula-matrix: add chip-wide hardware init/deinit implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add Leonis chip-wide hardware init/deinit support for the Nebula Matrix Ethernet driver, implementing full datapath pipeline initialization and ordered chip-level resource teardown. This patch establishes complete chip hardware lifecycle management and driver/firmware state synchronization via the driver_status flag.
Core changes:
1. Add hw_ops.init_module/deinit_module and corresponding resource_ops entry points for chip-level lifecycle management (caller hooks added later).
2. Enforce deterministic teardown order by adding device link dependencies:
all non-management PFs depend on function 0 management PF, ensuring safe chip-global firmware deinit without race conditions.
3. Implement firmware quirk parsing to enable hardware-specific tuning, such as UVN descriptor prefetch alignment optimization.
Initialize all core datapath modules with speed/port-count tailored settings:
- dped/uped: packet engine config, L4 checksum offload, IPv4/IPv6 TCP profiles
- dsch: scheduler quanta and host QID max threshold configuration
- ustore/dstore: Tx/Rx buffer drop thresholds and speed-adaptive flow control
- dvn/uvn: descriptor timeout, PCIe relaxed ordering and prefetch parameters
- uqm: queue counter reset and default queue mode initialization
- shaping: per-port rate shaping and PSHA scheduler configuration
Standard chip init flow:
1. Full datapath initialization via unified nbl_dp_init()
2. Host PADPT layer flow control initialization via nbl_intf_init()
3. Mark driver_status active and flush all hardware register writes
Safety & design rules:
- All chip-global operations are restricted to management PF via has_ctrl
- Driver programs registers only; full chip reset is firmware-managed
- Explicit register flushing synchronizes with asynchronous firmware cleanup
- Teardown ordering blocks new DMA and in-flight mailbox transactions
- Strict validation for port speed and ethernet port count parameters
Deinit note: firmware does not restore chip-wide datapath registers on deinit. The deinit path only clears driver_status and flushes writes. Hardware state persists until chip reset or explicit reconfiguration to avoid redundant reinit.
Also add required register definitions, firmware ABI enums, helper routines, resource callbacks and Makefile entries for the new chip management logic.
--- .../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 | 648 +++++++++++++++++- .../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 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 87 +++ 11 files changed, 1031 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -9,4 +9,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ + nbl_hw/nbl_chip.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +32 -0
@@ -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
@@ -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 +647 -1
677 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
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = { .cfg_msix_map = nbl_res_intr_cfg_msix_map, .destroy_msix_map = nbl_res_intr_destroy_msix_map, .set_mailbox_irq = nbl_res_intr_set_mailbox_irq, + .init_module = nbl_res_chip_init_module, + .deinit_module = nbl_res_chip_deinit_module, }; static struct nbl_resource_mgt *
@@ -46,7 +48,8 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)return ERR_PTR (-ENOMEM );if (!res_ops.get_vsi_id || !res_ops.get_eth_id || !res_ops.cfg_msix_map || !res_ops.destroy_msix_map || - !res_ops.set_mailbox_irq) + !res_ops.set_mailbox_irq || !res_ops.init_module || + !res_ops.deinit_module)return ERR_PTR (-EINVAL ); res_ops_tbl->ops = &res_ops; res_ops_tbl->priv = res_mgt;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -8,4 +8,5 @@#include "../nbl_resource.h" #include "../nbl_interrupt.h" +#include "../nbl_chip.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +3 -0
@@ -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
@@ -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
@@ -33,4 +33,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
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +87 -0
111 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 · Low: 1
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_chip_deps() (drivers/net/ethernet/nebula- matrix/nbl/nbl_main.c:113) adds a managed device link from each non-…
- [Medium] nbl_hw_deinit_module() (nbl_hw_leonis.c:721) clears driver_status, which starts asynchronous firmware cleanup, then…
- [Medium] nbl_probe_chip_deps() checks the supplier state without holding the device-links lock (READ_ONCE(mgt->dev.links.status) !=…
- [Medium] nbl_probe_chip_deps() dereferences the managed link returned by device_link_add() (READ_ONCE(link->status), nbl_main.c:161) without…
- [Low] nbl_probe_chip_deps() treats func 0 as a ready nbl management PF as soon as READ_ONCE(mgt->dev.links.status) == DL_DEV_DRIVER_BOUND…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This commit adds Leonis chip-wide datapath init/deinit hooks (init_module/deinit_module) in the hw and resource layers. The hooks use a driver_status flag handshake with firmware. It also adds a device link from each non-management PF to func 0, so that sibling PFs are unbound before the management PF.
Quoted 24 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +11
-0@@ -5,11 +5,23 @@#include <linux/device.h> #include <linux/pci.h> #include <linux/bits.h> +#include <linux/delay.h> #include <linux/io.h> #include <linux/spinlock.h> #include <linux/bitfield.h> #include "nbl_hw_leonis.h" +/* +* Firmware cleanup after driver_status=false is asynchronous and the +* current hardware revision exposes no cleanup-complete status bit. +* Wait a bounded window so the firmware pass finishes before this +* function returns, establishing an explicit boundary against a later +* init_module() that would otherwise reprogram per-PF/chip-wide +* registers while firmware is still wiping them. Best-effort only. +*/ +#define NBL_FW_CLEANUP_SYNC_MIN_US 2000 +#define NBL_FW_CLEANUP_SYNC_MAX_US 3000
[ ... ]
Quoted 4 lines
+/*
+ * Setting driver status to false notifies firmware to clean up per-PF
+ * hardware state such as qinfo registers.
+ *
[ ... ]
Quoted 4 lines
+ * Firmware cleanup is asynchronous with no completion status register,
+ * so a bounded sync delay follows the flush. On return the firmware
+ * pass has settled, so a subsequentinit_module()cannot race 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 732
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +12
-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); +/* +* Allow the asynchronous firmware cleanup pass to finish before +* returning, so this function is the boundary between firmware +* per-PF teardown and any later driver reprogramming. +*/ +usleep_range (NBL_FW_CLEANUP_SYNC_MIN_US ,NBL_FW_CLEANUP_SYNC_MAX_US ); +}
[Severity: Medium]
Is the guarantee in the nbl_hw_deinit_module() kernel-doc accurate? It says "On return the firmware pass has settled, so a subsequent init_module() cannot race it". But the comment above NBL_FW_CLEANUP_SYNC_MIN_US says there is no cleanup-complete status bit and calls the wait "Best-effort only".
The only synchronisation here is a fixed 2-3 ms sleep. There is no firmware acknowledgement.
If firmware cleanup takes longer than that, could a quick PF0 unbind/rebind reprogram qinfo in nbl_dev_setup_chan_qinfo() and the datapath in nbl_hw_init_module(), and then have firmware wipe that state?
nbl_hw_init_module() also sets driver_status again without checking that firmware is idle. It does not handle a driver_status bit left set by a previous instance that crashed or was kexec'd.
The commit message also says:
- Explicit register flushing synchronizes with asynchronous firmware cleanup
and:
The deinit path only clears driver_status and flushes writes.
The read of NBL_HW_DUMMY_REG only ensures the posted write reached the device. It can't observe firmware completion. The deinit path also sleeps, which the message doesn't mention.
Could the commit message and both comments match what the code actually guarantees? This is still present at the end of the series.
[ ... ]
Quoted 16 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8
-0@@ -83,6 +83,87 @@ static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, param->caps.has_ctrl =1 ; } +/* +* Establish chip-wide dependencies for this PF: +* - for every non-management PF, add a consumer->management PF device +* link. The driver core then guarantees (sysfs unbind, driver +* unregister, hot-unplug alike) that this consumer is released +* BEFORE the func 0 supplier, which is the only teardown order in +* which the chip-global firmware deinit is safe. +*
[ ... ]
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +20
-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) +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 ; + } + +/* +* The management PF must have COMPLETED probing, not merely +* have a driver assigned. While func 0 is still PROBING, its
[ ... ]
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 143
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +5
-0+*/ +if (READ_ONCE (mgt->dev.links.status) !=DL_DEV_DRIVER_BOUND ) { +pci_dev_put (mgt); +return -EPROBE_DEFER ; + }
[Severity: Low]
Does this check confirm that func 0 is bound to nbl specifically? links.status is DL_DEV_DRIVER_BOUND for any bound driver. If func 0 is bound to vfio-pci or pci-stub through driver_override, the check passes and the sibling creates a link to that other driver.
nbl_core_init() would then run on the non-management PF even though nbl never did the func 0 chip-global setup. That includes the mailbox QINFO map from nbl_dev_setup_chan_qinfo() under has_ctrl.
The comment above says "The management PF must have COMPLETED probing", which reads as the nbl probe. The check doesn't enforce that.
Later in the series, nbl_dev_start()->nbl_dev_rpc_timeout() turns the mailbox RPC timeout into -EPROBE_DEFER. The sibling would then likely keep deferring, with an RPC timeout on every retry.
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 146
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+ + link =device_link_add (&pdev->dev, &mgt->dev, +DL_FLAG_AUTOREMOVE_CONSUMER );
[Severity: Medium]
What happens to the sibling PFs when func 0 is unbound and then bound again?
On a func 0 unbind, device_links_unbind_consumers() releases every sibling PF driver. device_links_driver_cleanup() then deletes the AUTOREMOVE_CONSUMER link.
When func 0 binds again, device_links_driver_bound() re-queues consumers only through AUTOPROBE links:
drivers/base/core.c:device_links_driver_bound() {
...
if (device_link_test(link, DL_FLAG_AUTOPROBE_CONSUMER))
driver_deferred_probe_add(link->consumer);
...
}device_link_add() also returns NULL when DL_FLAG_AUTOPROBE_CONSUMER is combined with DL_FLAG_AUTOREMOVE_CONSUMER.
So would PF1..PF3 and their Ethernet ports stay unbound until an admin rebinds each one by hand?
The commit message ("ensuring safe chip-global firmware deinit") and the comment above nbl_probe_chip_deps() describe only the teardown ordering. Neither mentions that the ports are not restored. Would a persistent managed link with DL_FLAG_AUTOPROBE_CONSUMER work better here?
At this commit, nbl_res_chip_deinit_module() has no caller yet. The later commit "net/nebula-matrix: add common/ctrl dev init/remove operation" wires deinit_module into nbl_dev_remove_ctrl_dev(). The missing re-probe is still there at the end of the series.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0+pci_dev_put (mgt); +if (!link) { +dev_err (&pdev->dev, +"failed to create device link to management PF\n" ); +return -ENOMEM ; + }
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 162
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+ +/* +* If func 0 began unbinding between the driver check above and +* link creation, the core's unbind-consumers pass has already +* run and missed this new link, which starts SUPPLIER_UNBIND. +* Fail the probe: the managed link is auto-purged and the core +* retries after func 0 is bound again. +*/ +if (READ_ONCE (link->status) ==DL_STATE_SUPPLIER_UNBIND ) +return -EPROBE_DEFER ;
[Severity: Medium]
Can func 0 change state between the lockless check of mgt->dev.links.status and device_link_add()? Func 0 unbind and func N probe hold different device locks. In that window func 0 can go UNBINDING -> NO_DRIVER, and possibly back to PROBING.
device_link_init_status() would then set the new link to one of:
supplier NO_DRIVER -> DL_STATE_DORMANT
supplier PROBING, consumer probing -> DL_STATE_CONSUMER_PROBE
This check rejects neither state.
In the DORMANT case, the sibling finishes probe with no bound management PF. device_links_driver_bound() then hits:
WARN_ON(link->status != DL_STATE_CONSUMER_PROBE); WRITE_ONCE(link->status, DL_STATE_ACTIVE);
In the CONSUMER_PROBE case, the sibling's mailbox setup races func 0's chip-global init. The comment above the links.status check is meant to prevent exactly that.
If func 0's probe then fails, device_links_no_driver() moves the link to DORMANT without unbinding the sibling. A later func 0 bind makes the link AVAILABLE. device_links_unbind_consumers() only force-unbinds ACTIVE consumers, so a later func 0 unbind would run deinit_module while the sibling is still bound and doing mailbox DMA.
Is there a way to close this window, rather than rejecting only DL_STATE_SUPPLIER_UNBIND after the fact? This is still present at the end of the series.
[Severity: Medium]
Is it safe to dereference link here? The device_link_add() kernel-doc says that for a managed link the caller "is handing the management of the link over to the driver core entirely and its return value can only be used to check whether or not the link is present".
Suppose func 0 is being removed and has already passed device_links_busy(). The new link starts in SUPPLIER_UNBIND and does not block the removal.
If this probe thread is preempted after device_link_add() returns, func 0 removal can continue:
device_del()
device_links_purge()
__device_link_del()
...device_link_release_fn()
device_link_synchronize_removal()
kfree(link)
Would READ_ONCE(link->status) then read freed memory? Nothing here holds the device-links SRCU read lock or a reference on the link. This is still present at the end of the series.
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+ +return 0 ; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 5/8 net/nebula-matrix: dispatch: add control-level routing core infrastructure
In reply to illusion.wangFrom: 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 | 45 +++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 6 files changed, 196 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -10,4 +10,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_chip.o \ + nbl_core/nbl_dispatch.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -17,12 +17,14 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_ops_tbl;struct nbl_resource_ops_tbl *resource_ops_tbl; +struct nbl_dispatch_ops_tbl *dispatch_ops_tbl;struct nbl_channel_ops_tbl *channel_ops_tbl; };struct nbl_core {struct nbl_hw_mgt *hw_mgt;struct nbl_resource_mgt *res_mgt; +struct nbl_dispatch_mgt *disp_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +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
@@ -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 +45 -0
45 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
@@ -11,6 +11,7 @@#include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" #include "nbl_include/nbl_def_resource.h" +#include "nbl_include/nbl_def_dispatch.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -48,7 +49,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_res_init_leonis (adapter);if (ret) goto res_init_fail; + + ret =nbl_disp_init (adapter); +if (ret) + goto disp_init_fail;return adapter; +disp_init_fail: +nbl_res_remove_leonis (adapter); res_init_fail:nbl_chan_remove_common (adapter); chan_init_fail:
@@ -59,6 +66,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 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 of "net/nebula-matrix: dispatch: add control- level routing core infrastructure" says the patch will "Add wire ABI…
- [Low] At this commit, the kernel-doc Warning paragraph for struct nbl_dispatch_ops (nbl_def_dispatch.h lines 25-31) describes five…
- [Low] The kernel-doc for struct nbl_dispatch_ops (nbl_def_dispatch.h) calls @init_module "dispatch layer initialization" and @deinit_module…
--
net/nebula-matrix: dispatch: add control-level routing core infrastructure
This commit adds the nbl dispatch layer. It allocates a devm-managed nbl_dispatch_mgt, an ops table and a ctrl_lvl bitmap. When has_ctrl is set, it enables the MGT level and installs init_module/deinit_module wrappers that forward to the resource ops.
Quoted 3 lines
MGT level is only enabled for Control PF. Add kerneldoc for caller permission constraints. Add wire ABI structures with
static_assertfor upcoming mailbox RPC.
[Severity: Low]
Is the last sentence accurate for this patch? The diff touches the Makefile, nbl_core.h, nbl_dispatch.c, nbl_dispatch.h, nbl_def_dispatch.h and nbl_main.c. None of these files gets a mailbox wire-format struct or a static_assert.
At this commit, the driver has one static_assert, for struct nbl_board_port_info in nbl_def_channel.h. It was already there, and this patch does not change it.
The RPC payload structs and their size checks (nbl_chan_param_cfg_msix_map, nbl_chan_param_set_mailbox_irq, nbl_chan_param_get_vsi_id, nbl_chan_param_get_eth_id) first appear in the next patch, "net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops".
Could this sentence be dropped here, or moved to that patch's commit message?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +0
-0@@ -0,0 +1,45 @@
[ ... ]
Quoted 6 lines
+/**
+ * structnbl_dispatch_ops- dispatch control plane operation callbacks
+ * @init_module: dispatch layer initialization, control-PF exclusive,
+ * caller must checkhas_ctrlguard
+ * @deinit_module: dispatch layer cleanup, control-PF exclusive,
+ * caller must checkhas_ctrlguard
[Severity: Low]
Do "dispatch layer initialization" and "dispatch layer cleanup" describe these callbacks correctly? All dispatch-layer setup happens in nbl_disp_init(), and nbl_disp_remove() is empty. The installed callbacks only forward to the resource ops:
nbl_disp_init_module()
res_ops->init_module(p) /* nbl_res_chip_init_module() */
hw_ops->init_module(p, eth_speed, eth_num)nbl_disp_deinit_module()
res_ops->deinit_module(p) /* nbl_res_chip_deinit_module() */
hw_ops->deinit_module(res_mgt->hw_ops_tbl->priv)On leonis, these calls program the chip-wide datapath and set or clear driver_status. Clearing driver_status starts asynchronous firmware cleanup. nbl_dev.c notes that mailbox DMA must be drained before deinit_module is called.
Would it be clearer to call these chip/firmware init and deinit, and to mention the ordering requirement? That way later callers won't treat deinit_module as software-only cleanup. The same wording is still there at the end of the series.
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h line 36
Quoted 13 lines
+ *
+ * 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 neitherhas_ctrlnorhas_netleaves 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 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]
Is this paragraph describing code that isn't in this patch yet? Here, struct nbl_dispatch_ops has only init_module and deinit_module, and the enum has only NBL_DISP_CTRL_LVL_MGT. nbl_disp_init() never checks has_net, and nbl_disp_refresh_ctrl_ops() installs only the MGT pointers:
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;
}The five ops, NBL_DISP_CTRL_LVL_NET, the has_net routing and the -EPERM responders all come in the next patch, "net/nebula-matrix: dispatch:
implement channel RPC framework and serialize hardware ops". By the end of the series, the doc matches the code.
Could this paragraph be added in that patch instead, so the documentation in each commit matches its code?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 6/8 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
In reply to illusion.wangFrom: illusion wang <[email protected]>
Implement bidirectional mailbox RPC framework for cross-PF resource management, adding request/response handlers for five core dispatch operations:configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id.
Dispatch operations are dynamically resolved based on PF capability level:
- Management PF: invokes local hardware resource ops directly.
- Net-capable non-management PF: forwards operations to manager PF via RPC.
- Other functions: all dispatch ops are null and return -EOPNOTSUPP.
Add per-dispatch mutex to serialize mutable hardware operations including MSIX map configuration/destruction and mailbox IRQ setup. The mutex covers both local PF call paths and remote RPC response handlers to eliminate concurrent modification race conditions. Read-only VSI/ETH ID lookup APIs access static init metadata without serialization requirements.
Register five non-contiguous mailbox message handlers for the new RPC operations, preserving backward compatibility with reserved message IDs. All responders enforce strict runtime validation:
- Reject VF/out-of-range PF IDs with -EPERM;
- Validate incoming payload length before parsing;
- Check function pointer existence before invoking resource ops.
Fix error propagation by forwarding native Linux errnos from remote resource operations instead of unconditionally returning -EREMOTEIO. Only truncated ACK responses return -EREMOTEIO to distinguish protocol errors from legitimate operation failures. Transport layer errors are passed through unchanged from channel send routines.
For MSIX map reconfiguration, pre-allocate DMA buffers and vector indices prior to tearing down old configurations to prevent interrupt loss. Destroy path clears mailbox MSIX routing entries upfront to avoid stale interrupt triggers from recycled hardware vectors.
Document RPC caller preconditions for MSIX map operations: disable mailbox IRQ_RDY flag and use polling send path, as responders modify mailbox MSIX routing and cannot rely on interrupt-based ACK wakeup. Extend the same implicit precondition to set_mailbox_irq for future caller safety.
Clarify module teardown semantics in comment: dispatch message handlers are owned by the channel layer and unregistered in nbl_chan_remove_common(), with strict stop ordering preventing use-after-free or stale execution. Narrow kernel-doc warning to clarify new ops are PF-capability bounded, not available for VF functions.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 565 +++++++++++++++++- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 2 + .../nbl/nbl_include/nbl_def_channel.h | 39 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 16 + 4 files changed, 621 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +564 -1
@@ -3,9 +3,178 @@* Copyright (c) 2026 Nebula Matrix Limited. */ #include <linux/device.h> +#include <linux/mutex.h> #include <linux/pci.h> #include "nbl_dispatch.h" +static int nbl_disp_chan_get_vsi_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 type,u16 *vsi_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_send_info chan_send = {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 , + ¶m,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 (¶m, 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 , + ¶m,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 (¶m, 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 +194,357 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return -EOPNOTSUPP ; } +static int nbl_disp_cfg_msix_map (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; +int ret; + +if (!res_ops->cfg_msix_map) +return -EOPNOTSUPP ; +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->cfg_msix_map (p, common->mgt_pf, num_net_msix, + num_others_msix, net_msix_mask_en); +mutex_unlock (&disp_mgt->ops_mutex_lock); +return ret; +} + +/* +* 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 , + ¶m,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 (¶m, data,sizeof (param)); + +if (res_ops->cfg_msix_map) { +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->cfg_msix_map (p, src_id, +le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), + !!le16_to_cpu (param.msix_mask_en)); +mutex_unlock (&disp_mgt->ops_mutex_lock); +/* 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) { +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->destroy_msix_map (p, src_id); +mutex_unlock (&disp_mgt->ops_mutex_lock); +/* 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 , + ¶m,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 (¶m, data,sizeof (param)); + vector_id =le16_to_cpu (param.vector_id); + en_msix = !!param.en_msix; + +if (res_ops->set_mailbox_irq) { +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->set_mailbox_irq (p, src_id, vector_id, en_msix); +mutex_unlock (&disp_mgt->ops_mutex_lock); +/* 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; +int ret; + +if (!res_ops->destroy_msix_map) +return -EOPNOTSUPP ; +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->destroy_msix_map (p, common->mgt_pf); +mutex_unlock (&disp_mgt->ops_mutex_lock); +return ret; +} + +static int nbl_disp_set_mailbox_irq (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; +int ret; + +if (!res_ops->set_mailbox_irq) +return -EOPNOTSUPP ; +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->set_mailbox_irq (p, common->mgt_pf, vector_id, en_msix); +mutex_unlock (&disp_mgt->ops_mutex_lock); +return ret; +} + +static int nbl_disp_get_vsi_id (struct nbl_dispatch_mgt *disp_mgt,u16 type, +u16 *vsi_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (res_ops->get_vsi_id) +return res_ops->get_vsi_id (p, common->mgt_pf, type, vsi_id); +return -EOPNOTSUPP ; +} + +static int nbl_disp_get_eth_id (struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (res_ops->get_eth_id) +return res_ops->get_eth_id (p, common->mgt_pf, vsi_id, + eth_num, eth_id, logic_eth_id); +return -EOPNOTSUPP ; +} + +static int nbl_disp_setup_msg (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; +int ret =0 ; +int _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + nbl_disp_chan_cfg_msix_map_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_DESTROY_MSIX_MAP , + nbl_disp_chan_destroy_msix_map_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_MAILBOX_SET_IRQ , + nbl_disp_chan_set_mailbox_irq_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_GET_VSI_ID , + nbl_disp_chan_get_vsi_id_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_GET_ETH_ID , + nbl_disp_chan_get_eth_id_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + +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 +554,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; } }
@@ -45,12 +578,16 @@ nbl_disp_setup_disp_mgt(struct nbl_common_info *common) {struct nbl_dispatch_mgt *disp_mgt;struct device *dev = common->dev; +int err; disp_mgt =devm_kzalloc (dev,sizeof (*disp_mgt),GFP_KERNEL );if (!disp_mgt)return ERR_PTR (-ENOMEM ); disp_mgt->common = common; + err =devm_mutex_init (common->dev, &disp_mgt->ops_mutex_lock); +if (err) +return ERR_PTR (err);return disp_mgt; }
@@ -104,14 +641,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_core/nbl_dispatch.h +2 -0
@@ -18,6 +18,8 @@ struct nbl_dispatch_mgt {struct nbl_channel_ops_tbl *chan_ops_tbl;struct nbl_dispatch_ops_tbl *disp_ops_tbl;DECLARE_BITMAP (ctrl_lvl,NBL_DISP_CTRL_LVL_MAX ); +/* use for the caller not in interrupt */ + struct mutex ops_mutex_lock; };#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +39 -0
@@ -30,6 +30,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 +44,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 +77,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 +16 -0
@@ -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 , };
@@ -21,6 +22,11 @@ enum {* caller must check has_ctrl guard * @deinit_module: dispatch layer cleanup, control-PF exclusive, * caller must check has_ctrl guard +* @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 * * Warning: init_module/deinit_module are control-PF exclusive. The five * resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq,
@@ -33,6 +39,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
[email protected]
AI reviewRe: [PATCH v30 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 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] The commit message describes three changes that are not in this patch.
- [Low] The commit message contradicts the error codes the patch actually returns.
- [Low] Concern (baseline: not a valid finding at end of series):
nbl_disp_remove()'s new comment describes a teardown sequence that…
- [Low] The new disp_mgt->ops_mutex_lock is redundant with the resource layer's own locking, which contradicts the commit message's claim that…
- [Low] Concern (baseline: not a valid finding):
nbl_disp_chan_cfg_msix_map_resp() passes the peer's num_net_msix and…
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This patch adds mailbox RPC request and response handlers for five dispatch operations: cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. The management PF calls the resource ops directly, and net-capable non-management PFs forward them to the management PF over the channel. It also adds a per-dispatch mutex around the MSI-X and mailbox IRQ operations, which change hardware state.
Quoted 5 lines
Fix error propagation by forwarding native Linux errnos from remote resource operations instead of unconditionally returning
-EREMOTEIO. Only truncated ACK responses return-EREMOTEIOto distinguish protocol errors from legitimate operation failures. Transport layer errors are passed through unchanged from channel send routines.
[Severity: Low]
Does this paragraph match the code? Both new ACK length checks, in nbl_disp_chan_get_vsi_id_req() and nbl_disp_chan_get_eth_id_req(), return -EBADMSG, not -EREMOTEIO:
if (chan_send.ack_len != sizeof(result)) {
...
return -EBADMSG;
}The only -EREMOTEIO in the driver appears to be in nbl_chan_recv_ack_msg() in nbl_channel/nbl_channel.c. There it replaces an out-of-range remote errno, so it has nothing to do with a truncated ACK:
if (raw_err > 0 || raw_err < -MAX_ERRNO)
raw_err = -EREMOTEIO;The parent commit also has no RPC request or response code. So there is no earlier "unconditionally returning -EREMOTEIO" behaviour for this patch to fix.
Was this paragraph left over from an earlier revision?
Quoted 1 line
- Other functions: all dispatch ops are null and return
-EOPNOTSUPP.
[ ... ]
Quoted 4 lines
For MSIX map reconfiguration, pre-allocate DMA buffers and vector indices prior to tearing down old configurations to prevent interrupt loss. Destroy path clears mailbox MSIX routing entries upfront to avoid stale interrupt triggers from recycled hardware vectors.
[ ... ]
Quoted 2 lines
Narrow kernel-doc warning to clarify new ops are PF-capability bounded, not available for VF functions.
[Severity: Medium]
Several parts of the commit message describe changes that this patch does not contain.
For a function with neither the MGT bit nor the NET bit set, nbl_disp_refresh_ctrl_ops() memsets disp_ops and assigns nothing, so the pointers stay NULL. Calling one of those ops is a NULL function pointer call, not an -EOPNOTSUPP return. The kernel-doc in nbl_def_dispatch.h already says callers must not invoke them, which matches the code.
The MSI-X pre-allocation, and the clearing of the mailbox routing at the start of destroy, live in nbl_res_intr_cfg_msix_map() and __nbl_res_intr_prepare_destroy_msix_map() in nbl_hw/nbl_interrupt.c. The earlier commit "net/nebula-matrix: add intr resource implementation" added that code, and this patch does not touch nbl_hw/.
The "Warning:" paragraph in the struct nbl_dispatch_ops kernel-doc is identical in the parent commit, which already listed the five ops and the VF restriction. This patch only adds the @member lines.
Could the commit message describe only what this patch changes?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +7
-0@@ -25,6 +194,357 @@ 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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 213
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+int ret; + +if (!res_ops->cfg_msix_map) +return -EOPNOTSUPP ; +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->cfg_msix_map (p, common->mgt_pf, num_net_msix, + num_others_msix, net_msix_mask_en); +mutex_unlock (&disp_mgt->ops_mutex_lock); +return ret; +}
[Severity: Low]
Is ops_mutex_lock needed here? The resource ops already serialize themselves under intr_mgt->lock. The documentation of nbl_res_intr_cfg_msix_map() says:
* Serialization: this function takes intr_mgt->lock internally to
* protect the global vector bitmaps and per-function state against
* concurrent callers.
nbl_res_intr_set_mailbox_irq() also takes intr_mgt->lock internally. nbl_res_intr_destroy_msix_map() takes it around __nbl_res_intr_destroy_msix_map(). The "add intr resource implementation" commit also says callers need no upper-layer locking.
This wrapper makes a single resource call. So do nbl_disp_destroy_msix_map(), nbl_disp_set_mailbox_irq() and the three matching *_resp handlers. None of them has a multi-step sequence that needs an outer lock.
The field comment in nbl_dispatch.h, "use for the caller not in interrupt", does not say what the mutex protects. That makes the commit message's claim that the mutex eliminates concurrent modification races hard to square with the code.
Could the mutex be dropped? If it covers state that intr_mgt->lock does not, could that state be documented?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +3
-0+static void nbl_disp_chan_cfg_msix_map_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 282
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +7
-0+if (res_ops->cfg_msix_map) { +mutex_lock (&disp_mgt->ops_mutex_lock); + ret = res_ops->cfg_msix_map (p, src_id, +le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), + !!le16_to_cpu (param.msix_mask_en)); +mutex_unlock (&disp_mgt->ops_mutex_lock);
[Severity: Low]num_net_msix and num_others_msix come straight from the peer PF and go to nbl_res_intr_cfg_msix_map(). The only bound there appears to be the table size:
if (num_net_msix > NBL_MSIX_MAP_TABLE_MAX_ENTRIES ||
num_others_msix > NBL_MSIX_MAP_TABLE_MAX_ENTRIES) {NBL_MSIX_MAP_TABLE_MAX_ENTRIES (1024) equals the size of the other interrupt pool (NBL_MAX_OTHER_INTERRUPT). Could one PF request nearly all of the other vectors and leave the remaining PFs with -EAGAIN?
This probably can't be reached in practice:
- The rel_pf_id < max_pf check rejects VFs.
- nbl_get_func_param() in nbl_main.c says the hardware and firmware forbid PF passthrough to guests. Every peer PF therefore runs this same host driver.
- The in-tree requester nbl_dev_cfg_msix_map() only asks for the counts from nbl_dev_init_msix_cnt(): one mailbox vector and no net vectors.
Is a per-function limit worth adding anyway, or is a peer PF always treated as trusted?
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0@@ -104,14 +641,40 @@ int nbl_disp_init(struct nbl_adapter *adapter)
[ ... ]
Quoted 15 lines
void
nbl_disp_remove(struct nbl_adapter *adapter){drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +12
-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 +* 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,
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 680
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +9
-0+* // 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. +*/ }
[Severity: Low]
Does this teardown sequence exist at this commit? clean_mbx_task is not defined yet, and nothing calls the channel setup_queue or teardown_queue ops. So the "cancel_work_sync(clean_mbx_task) -> nbl_chan_teardown_queue()" chain refers to code that doesn't exist yet at this point in the series.
This is not a reachable race here, because the mailbox queue is never set up and the responders can't run.
The next patch, "net/nebula-matrix: add common/ctrl dev init/remove operation", makes the comment accurate. It adds nbl_dev_remove() ahead of nbl_disp_remove() in nbl_core_remove(). Its nbl_dev_remove_common_dev() calls cancel_work_sync(&common_dev->clean_mbx_task) and then nbl_chan_teardown_queue(), both before nbl_res_remove_leonis() calls nbl_intr_mgt_stop().
Would it make sense to move this comment into that patch, so the comment matches the code at each point in the series?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 7/8 net/nebula-matrix: add common/ctrl dev init/remove operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev core device infrastructure for nebula-matrix NIC lifecycle management. Create 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.
Implement common device setup helper to allocate per-device state, initialize mailbox cleanup work, create mailbox channel queue, and pre-populate MSI-X service vector counts. Defer VSI/ETH identity lookup and MSI-X vector allocation to the subsequent start routine, to guarantee a fully ready control PF mailbox responder before any cross-PF RPC access and keep intermediate commits bisectable.
Implement control-PF-only device setup to invoke chip-level module initialization and program mailbox QINFO routing table entries for PF bus/devid mapping.
Enforce hardware-aware init/teardown ordering: initialize common mailbox channel state before control device hardware setup, and teardown mailbox channel and drain in-flight DMA prior to firmware de-initialization notification, to avoid invalid DMA writes.
The firmware handles global hardware cleanup and QINFO routing state reclamation asynchronously after driver status is marked inactive. Device link dependency established during non-control PF probe ensures sibling PFs are unbound 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 | 253 ++++++++++++++++++ .../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, 333 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -11,4 +11,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_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
@@ -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 +253 -0
253 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +55 -0
55 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 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
@@ -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
[email protected]
AI reviewRe: [PATCH v30 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: 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 control-PF teardown and init added here rely on nbl_probe_chip_deps() to guarantee that no sibling PF probes unless…
- [Low] The commit message says 'The firmware handles global hardware cleanup and QINFO routing state reclamation asynchronously after…
- [Low] The new callers disagree with how nbl_chan_teardown_queue() actually behaves.
- [Low] Two comments on the same control-PF remove sequence contradict each other.
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This commit adds nbl_dev.c with nbl_dev_init() and nbl_dev_remove(). They set up the mailbox channel queue and cleanup work, program mailbox QINFO routing on the control PF, and call chip-level init_module/deinit_module. Teardown destroys the mailbox queue before notifying firmware through deinit_module.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,253 @@
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +3
-0+/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter) +{
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +3
-0+ ret =nbl_dev_setup_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +if (ret) + goto err_cleanup;
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +11
-0+return 0 ; +err_cleanup: +cancel_work_sync (&common_dev->clean_mbx_task); +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +return ret; +} + +static void nbl_dev_remove_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 140
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+struct nbl_dev_common *common_dev = dev_mgt->common_dev; +int ret; + +if (!common_dev) +return ; +cancel_work_sync (&common_dev->clean_mbx_task); + ret =nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +if (ret) +dev_warn (&adapter->pdev->dev,"mailbox queue teardown failed, inflight DMA may exist: %d\n" , + ret);
[Severity: Low]
Can nbl_dev_remove_chan_queue() return non-zero here? Both exits of nbl_chan_teardown_queue() return 0: the early return when the channel is not active, and the normal path after draining. That makes this dev_warn() unreachable.
The message also suggests teardown can fail with DMA still in flight. If it could, nbl_dev_remove() would still go on to call deinit_module, and nbl_hw_deinit_module() assumes no mailbox DMA is left at that point. Does this warning cover a real failure mode, or can it be dropped?
There is a related issue on the err_cleanup path of nbl_dev_setup_common_dev() above. That path only runs when setup_queue failed, and chan_info->active is only set to true when setup succeeds. So the teardown lands here:
nbl_chan_teardown_queue() {
if (!READ_ONCE(chan_info->active)) {
dev_warn(chan_mgt->common->dev, "channel not active, skip duplicate teardown\n");
return 0;
}
...
}Won't this log "skip duplicate teardown" on the first cleanup after a failed setup, when no duplicate teardown has happened?
[ ... ]
Quoted 11 lines
+/*
+ * Tear down control device:deinit_modulesets driver_status=false
+ * to notify firmware to clean all per-PF hardware state (including
+ * qinfo registers). The qinfo map programmed innbl_dev_init()via
+ *nbl_dev_setup_chan_qinfo()is not explicitly cleared; firmware
+ * handles it ondriver_statuschange.
+ *
+ * Teardown ordering guarantee: every non-management PF creates a
+ *consumer->controlPF device link in its probe path, so the driver
+ * core always unbinds all siblings before allowing the control PF to
+ * be detached (sysfs unbind, driver unregister and hot-unplug alike).
[Severity: Low]
This comment conflicts with the one in nbl_res_remove_leonis(), which nbl_core_remove() calls right after nbl_dev_remove():
nbl_res_remove_leonis() {
...
/*
* Tear down all MSI-X maps before destroying coherent tables.
* This is critical on the control PF, which may hold
* maps for remote PFs that are still bound.
*/
...
}If the driver core always unbinds all siblings before the control PF, no remote PF can still be bound at that point. Which of these does the teardown actually rely on? One of the two comments probably needs updating.
This patch relies on the stronger claim to justify calling deinit_module unconditionally. The next comment describes a case where it does not fully hold.
Quoted 3 lines
+ *
nbl_probe_chip_deps()defers a sibling's probe until the control PF
+ * is fully bound (DL_DEV_DRIVER_BOUND), so no sibling can race its
+ * mailbox setup against this deinit.
[Severity: Medium]
Is this exclusion guaranteed? nbl_probe_chip_deps() in nbl_main.c checks the supplier state without a lock, then creates the link, and rejects only one link state:
if (READ_ONCE(mgt->dev.links.status) != DL_DEV_DRIVER_BOUND) {
pci_dev_put(mgt);
return -EPROBE_DEFER;
}
link = device_link_add(&pdev->dev, &mgt->dev,
DL_FLAG_AUTOREMOVE_CONSUMER);
...
if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND)
return -EPROBE_DEFER;device_link_init_status() in drivers/base/core.c sets DL_STATE_SUPPLIER_UNBIND only while the supplier is DL_DEV_UNBINDING:
case DL_DEV_UNBINDING: link->status = DL_STATE_SUPPLIER_UNBIND; break; default: link->status = DL_STATE_DORMANT;
Two cases seem to get past the check:
(a) The control PF finishes unbinding, including nbl_dev_remove() -> deinit_module, between the check and device_link_add(). It is then DL_DEV_NO_DRIVER, so the link starts as DL_STATE_DORMANT and passes.
(b) The control PF has started re-probing (DL_DEV_PROBING) while the sibling is probing. The link starts as DL_STATE_CONSUMER_PROBE and also passes.
In both cases the sibling goes on to nbl_core_init() -> nbl_dev_init() and sets up its mailbox queue. In (a) this happens right after the control PF set driver_status=false, while the firmware's asynchronous per-PF cleanup may still be running. In (b) it races the control PF's nbl_dev_setup_chan_qinfo() and init_module programming.
The sibling and the control PF hold separate device_lock()s, so the driver core does not serialize these paths.
The commit message makes the same claim:
Device link dependency established during non-control PF probe ensures sibling PFs are unbound before the control PF is removed.
Should nbl_probe_chip_deps() re-check the supplier state after device_link_add() and also reject DORMANT links and links to a supplier that is still probing?
[ ... ]
Quoted 8 lines
+/*
+ * Teardown order: Stop mailbox channel and drain all inflight DMA first,
+ * then invokedeinit_moduleto notify firmware.
+ *
+ * This intentionally breaks strict init/teardown mirror symmetry due to
+ * hardware constraint: firmware may perform asynchronous global hardware
+ * cleanup once driver_status=false is set. We must guarantee no ongoing
+ * mailbox DMA beforedeinit_moduleto avoid invalid DMA write.
[Severity: Low]
The commit message says:
The firmware handles global hardware cleanup and QINFO routing state reclamation asynchronously after driver status is marked inactive.
This comment likewise refers to "asynchronous global hardware cleanup". Is that accurate? This path reaches nbl_hw_deinit_module() in nbl_hw_leonis.c through deinit_module, and that function documents a narrower contract:
* 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.
The earlier "add chip-wide hardware init/deinit implementation" commit also says that firmware does not restore chip-wide datapath registers on deinit.
So after the control PF is removed, the registers programmed by nbl_dp_init() and nbl_intf_init() stay in place until chip reset. Could the commit message and this comment say per-PF cleanup instead of global cleanup?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v30 8/8 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Implement nbl_dev_start() and nbl_dev_stop() to manage MSI-X hardware mapping and mailbox interrupt setup/teardown.
nbl_dev_start() performs device startup in strict order: configure hardware MSI-X mapping table, fetch VSI/ETH identity via dispatch RPC, allocate MSI-X IRQ vectors with mailbox vector affinity isolation, request and attach mailbox interrupt handler, then enable hardware mailbox interrupt and mark channel interrupt ready.
Convert mailbox RPC timeouts to -EPROBE_DEFER for non-control PFs on all startup RPC paths to trigger deferred probing when the control PF is not ready. Isolate mailbox administrative vector from CPU affinity management to avoid mailbox RPC stalls caused by CPU offline.
Skip redundant MSI-X map destroy RPC on unconfigured state during probe rollback to eliminate unnecessary polling timeouts. Adjust interrupt teardown ordering to clear channel IRQ ready state before masking hardware interrupts, preventing in-flight ACK discard and "Channel waiting ack failed" errors.
nbl_dev_stop() tears down resources in reverse startup order. Switch channel to polling mode and clear IRQ ready state before masking hardware interrupts to preserve ACK integrity. Release mailbox IRQ handlers and destroy device-side MSI-X mapping while leaving kernel MSI-X vectors managed by devres/pcim to avoid double-free. Drain pending mailbox cleanup work to ensure consistent teardown.
Teardown is best-effort: failed MSI-X destroy RPC leaves stale hardware entries which are reclaimed by firmware on chip reset, with pci_clear_master() serving as the final safety net. The start/stop pair is single-shot and non-repeatable, tied strictly to PCI probe/remove device lifecycle.
Add thin nbl_core_start()/nbl_core_stop() wrappers and hook them into PCI probe and remove paths to complete the device lifecycle management series.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 8 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 372 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 18 + 4 files changed, 400 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +8 -0
@@ -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 +372 -0
393 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
@@ -10,5 +10,7 @@ struct nbl_adapter;int nbl_dev_init (struct nbl_adapter *adapter);void nbl_dev_remove (struct nbl_adapter *adapter); +int nbl_dev_start (struct nbl_adapter *adapter); +void nbl_dev_stop (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +18 -0
@@ -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) {
@@ -212,7 +222,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);
@@ -227,6 +243,8 @@ static void nbl_remove(struct pci_dev *pdev)return ;pci_set_drvdata (pdev,NULL ); + +nbl_core_stop (adapter);nbl_core_remove (adapter);pci_clear_master (pdev);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v30 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] nbl_dev_rpc_timeout() in drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c (lines 85-90) turns every -ETIMEDOUT…
- [Medium] In nbl_dev_start() (nbl_dev.c:513-516), map_ready is set only after cfg_msix_map returns success.
- [Low] The commit message says teardown is best-effort 'with pci_clear_master() serving as the final safety net' when the MSI-X…
- [Low] Two problems here.
- [Low] The commit message says clearing NBL_CHAN_IRQ_RDY before masking the hardware interrupt is done 'preventing in-flight ACK discard and…
--
net/nebula-matrix: add common dev start/stop operation
This patch adds nbl_dev_start() and nbl_dev_stop(). Start configures the device MSI-X map, fetches the VSI/ETH ids, allocates MSI-X vectors and sets up the mailbox interrupt; stop does the matching teardown. Startup RPC timeouts on non-control PFs become -EPROBE_DEFER, and both functions are called from nbl_probe()/nbl_remove() through nbl_core_start()/nbl_core_stop().
Quoted 5 lines
Teardown is best-effort: failed MSI-X destroy RPC leaves stale hardware entries which are reclaimed by firmware on chip reset, with
pci_clear_master()serving as the final safety net. The start/stop pair is single-shot and non-repeatable, tied strictly to PCI probe/remove device lifecycle.
[Severity: Low]
Is the pci_clear_master() safety net claim accurate for non-control PFs? The comments this patch adds in nbl_dev_start() and nbl_dev_stop() say the opposite:
* pci_clear_master() on a non-control PF cannot stop DMA using the
* management PF's BDF.
nbl_res_intr_cfg_msix_map() programs the PCOMPLETER map with the control PF's common->hw_bus/devid/function. If destroy_msix_map fails, clearing bus mastering on the departing PF would not stop those map-table fetches.
Could the commit message be changed to match the code comments?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -18,6 +29,233 @@ static void nbl_dev_init_msix_cnt(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 90
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +12
-0+/* +* Translate a mailbox RPC timeout on a non-control PF into deferred +* probing: the management PF/firmware is not responsive yet and the +* driver core should retry once PF0 is ready. Other errors, and all +* errors on the control PF itself, pass through unchanged. +*/ +static int nbl_dev_rpc_timeout (struct nbl_common_info *common,int ret) +{ +if (!common->has_ctrl && ret == -ETIMEDOUT ) +return -EPROBE_DEFER ; +return ret; +}
[Severity: Medium]
Can the "management PF/firmware is not responsive yet" case still happen when these RPCs are sent? nbl_probe() calls nbl_probe_chip_deps() before nbl_core_init()/nbl_core_start(), and that function already defers until func 0 is bound:
nbl_probe_chip_deps() {
...
if (READ_ONCE(mgt->dev.links.status) != DL_DEV_DRIVER_BOUND) {
pci_dev_put(mgt);
return -EPROBE_DEFER;
}
...
}DL_DEV_DRIVER_BOUND is set only after PF0's nbl_probe() returns 0. With this patch, that probe includes PF0's own nbl_core_start() (cfg_msix_map, request_irq and set_mailbox_irq(true)). The managed device link also stops PF0 from unbinding while a consumer is probing.
So on a sibling PF, a -ETIMEDOUT from cfg_msix_map, get_vsi_id, get_eth_id or set_mailbox_irq(true) comes after a 5-6 second polling wait. That looks like a real failure, not PF0 still starting up.
Will returning -EPROBE_DEFER here actually cause a retry? really_probe() only reports the deferral with dev_dbg(). Deferred devices are retried from driver_bound()->driver_deferred_probe_trigger() when some other device binds, and PF0's bind trigger has already fired by this point.
If nothing else binds later (the last sibling PF, or a module loaded after boot), could the PF stay unbound with no probe failure printed at the default log level? If other devices do bind, does each retry pay another multi-second timeout for every startup RPC?
If this changes, the commit message wording "to trigger deferred probing when the control PF is not ready" would need updating too.
[ ... ]
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) +{
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +14
-0+/* +* Disable sequence invariant: update software state first, then mask +* hardware interrupt. Must not reverse the order. +* +* If hardware interrupt is masked before clearing INTERRUPT_READY, +* the hardware may still transmit outstanding ACK packets for in-flight +* messages. Subsequent switch to polling mode discards pending ACK +* processing, triggering "Channel waiting ack failed" and "Skip ack +* with invalid status" errors. +* +* By entering polling mode first, any late hardware interrupts are +* ignored without pending ACK expectations, then hardware interrupt +* can be safely disabled. +*
[ ... ]
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 164
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +8
-0+*/ + chan_ops->set_queue_state (dev_mgt->chan_ops_tbl->priv, +NBL_CHAN_IRQ_RDY , +NBL_CHAN_TYPE_MAILBOX , false); + +return disp_ops->set_mailbox_irq (dev_mgt->disp_ops_tbl->priv, + lvec, false); +}
[Severity: Low]
Does clearing NBL_CHAN_IRQ_RDY first actually keep in-flight ACKs? When IRQ_RDY is cleared, nbl_chan_set_queue_state() wakes every waiter:
nbl_chan_set_queue_state() {
...
if (!set && state == NBL_CHAN_IRQ_RDY) {
for (i = 0; i < chan_info->num_txq_entries; i++)
wake_up_all(&chan_info->wait[i].wait_queue);
}
}An interrupt-mode waiter in nbl_chan_send_msg() then gives up:
if (!test_bit(NBL_CHAN_IRQ_RDY, chan_info->state)) {
ret = -EIO;
goto out_clear_wait_slot;
}The slot goes back to IDLE. When the peer's ACK arrives later, nbl_chan_recv_ack_msg() sees w_status != NBL_MBX_STATUS_WAITING, logs "Skip ack invalid status" and drops it. The comment says this ordering prevents exactly that; the only difference is that the sender gets -EIO instead of -ETIMEDOUT.
In this patch every ACK-requesting sender runs from probe/remove, and the clean task only sends replies without ACKs, so nothing hits this today.
Should the comment and the commit message ("preventing in-flight ACK discard and "Channel waiting ack failed" errors", "to preserve ACK integrity") be corrected before later patches rely on this invariant? Only draining in-flight waiters before clearing IRQ_RDY would provide that guarantee.
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -251,3 +497,129 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +3
-0+/* ---------- Dev start process ---------- */ +int nbl_dev_start (struct nbl_adapter *adapter) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+ ret =nbl_dev_rpc_timeout (common,nbl_dev_cfg_msix_map (dev_mgt)); +if (ret) + goto err_destroy_map; + map_ready = true;
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 551
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +13
-0+ ret =nbl_dev_enable_mailbox_irq (dev_mgt); +if (ret) + goto err_disable_irq; + +return 0 ; + +err_disable_irq: + cleanup_ret =nbl_dev_disable_mailbox_irq (dev_mgt); +if (cleanup_ret) +dev_err (dev_mgt->common->dev, +"rollback: disable mailbox IRQ failed: %d\n" , + cleanup_ret); +nbl_dev_free_mailbox_irq (dev_mgt);
[Severity: Low]
Is the set_mailbox_irq(false) RPC needed on this rollback path? If nbl_dev_enable_mailbox_irq() failed, NBL_CHAN_IRQ_RDY was never set, yet nbl_dev_disable_mailbox_irq() still sends a polling-mode RPC that requests an ACK.
Control then falls through to err_destroy_map. On the control PF, the destroy path already turns off mailbox routing:
__nbl_res_intr_prepare_destroy_msix_map() {
...
/* Step 0: disable mailbox IRQ routing before tearing down map */
ret = __nbl_res_intr_set_mailbox_irq(res_mgt, func, 0, false);
...
}With an unresponsive peer, this adds another polling timeout of about 5-6 seconds, and every deferred retry repeats it. That works against the stated goal of removing unnecessary polling timeouts during probe rollback.
Separately, some commit message wording seems to describe changes from an earlier revision:
"Skip redundant MSI-X map destroy RPC on unconfigured state during probe rollback to eliminate unnecessary polling timeouts. Adjust interrupt teardown ordering to ..."
This patch introduces nbl_dev_start()/nbl_dev_stop(), so should these version notes go below the --- line instead?
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +8
-0+err_destroy_map: +/* +* Destroy the device-side MSI-X map only when it was configured. +* On a cfg RPC failure there is no known-good remote map; when +* the failure is a timeout against an unready/unresponsive +* management PF, issuing the destroy RPC would just burn another +* multi-second ACK timeout. Partial remote state is best-effort +* and reclaimed by firmware on chip reset.
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 575
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +3
-0+*/ +if (map_ready) { + cleanup_ret =nbl_dev_destroy_msix_map (dev_mgt);
[Severity: Medium]
If cfg_msix_map times out, can skipping destroy here leave control-PF resources held for a function that has no driver? A -ETIMEDOUT from the polling send only means the ACK did not arrive in time. nbl_chan_send_msg() explicitly handles ACKs that arrive after the sender has timed out, and the request may still be in the control PF's RX ring.
On the control PF, nbl_disp_chan_cfg_msix_map_resp()-> nbl_res_intr_cfg_msix_map() finishes all of its work before it sends the ACK:
- kcalloc() for the interrupts array
- dma_alloc_coherent() for the map table
- set_bit() in intr_net_bmap/intr_other_bmap
- setting the PCOMPLETER map to VALID
and finally:
intr_mgt->func_intr_res[func_id].state = NBL_INTR_FUNC_CONFIGURED;
With map_ready false, the sibling returns -EPROBE_DEFER without sending destroy. The resources are then freed only when the same PF later re-probes successfully (the had_config path) or when the control PF unbinds (nbl_res_remove_leonis()->nbl_intr_mgt_stop()). A re-probe after deferral is not guaranteed.
The comment "Partial remote state is best-effort and reclaimed by firmware on chip reset" also looks inaccurate, as does the similar comment in nbl_dev_stop(). This is host memory and bitmap state owned by the control PF driver, and nothing requests a chip reset.
Would it be safer to always send destroy after a cfg timeout? __nbl_res_intr_prepare_destroy_msix_map() returns 0 when the function is not NBL_INTR_FUNC_CONFIGURED, so it looks harmless in the unconfigured case.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928123237.88994-1-illusion.wang%40nebula-matrix.com