nbl driver for Nebulamatrix NICs
illusion.wang
maintainerv29 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 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 | 1421 +++++++++++++++++ .../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 | 14 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 601 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 653 ++++++++ .../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 | 1082 +++++++++++++ .../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 | 742 +++++++++ .../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 | 135 ++ .../nbl/nbl_include/nbl_def_channel.h | 175 ++ .../nbl/nbl_include/nbl_def_common.h | 23 + .../nbl/nbl_include/nbl_def_dev.h | 16 + .../nbl/nbl_include/nbl_def_dispatch.h | 56 + .../nbl/nbl_include/nbl_def_hw.h | 65 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 29 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 107 ++ 29 files changed, 6439 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 v29 1/8 net/nebula-matrix: add channel layer
From: illusion wang <[email protected]>
Add generic channel management layer for Nebula Matrix network adapter to implement core inter-PF communication capability. This patch introduces a dedicated mailbox-based channel layer as the foundation of PF0 <-> other PFs inter-PF communication. It provides standardized message transmission, lifecycle-based queue management and hardware abstraction, supporting reliable control message interaction between physical functions. Core functional implementations:
1. Dynamic message handling framework
- Implement xarray-based dynamic message handler management with O(1) lookup by message type
- Support two transmission modes: fire-and-forget and synchronous send with ACK waiting
- Dedicated ACK message processing path to match request-response semantics
- TX slot concurrency control, return -EAGAIN under full slot pressure
- Dual transmission format: small embedded payload in TX descriptor, large payload via external DMA buffer
- Complete message handler cleanup logic in driver teardown
2. Mailbox queue lifecycle management
- Coherent DMA allocation for TX/RX descriptor rings and data buffers with devm automatic resource management
- Full queue lifecycle: hardware init/config/stop/teardown
- Dual RX processing mode (interrupt/polling), offload RX cleanup to dedicated workqueue to reduce IRQ latency
- Inflight TX traffic draining and pending ACK abortion during channel teardown
- Reserved hole mechanism to precisely distinguish RX ring empty/full state and avoid overflow
- One-shot DMA buffer allocation in probe phase, no dynamic runtime reinit
3. Hardware abstraction layer (hw_ops)
- Decouple channel business logic from hardware implementation via independent hw_ops layer
- Provide hardware queue config, tail pointer doorbell update and PF mailbox route table configuration interfaces
- Add reg_lock to protect BAR0 read-modify-write register operations
- Optimize BAR2 register access without lock for fast-path performance, avoid CPU soft lockup under stress test
4. Common infrastructure & utility
- Implement thread-safe xarray management for message handlers
- Create device-independent dedicated workqueue for RX cleanup tasks
- Supplement channel state management, bitmask control and auxiliary tool interfaces
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1421 +++++++++++++++++ .../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 | 250 +++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 42 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 33 + .../nbl/nbl_include/nbl_def_channel.h | 125 ++ .../nbl/nbl_include/nbl_def_common.h | 4 + .../nbl/nbl_include/nbl_def_hw.h | 38 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 7 + 14 files changed, 2159 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 +1421 -0
1,421 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 +250 -0
277 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +42 -0
47 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +33 -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"
@@ -16,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. */
@@ -26,6 +28,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 +38 -0
@@ -10,6 +10,44 @@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. +* +* Firmware contract: number of unmasked PFs MUST equal +* get_board_info()->eth_num. +*/ +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 v29 net-next 1/8] net/nebula-matrix: add channel layer
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 2 · Low: 5
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] In the "zombie" teardown path of nbl_chan_teardown_queue() (inflight-TX drain timeout followed by a failed…
- [High] nbl_chan_teardown_queue() uses mutex_trylock(&chan_info->txq_lock) with a fallback that skips the…
- [Medium] nbl_chan_teardown_queue() step 2 calls nbl_chan_reset_wait_head() on every wait slot under pending_lock,…
- [Medium] The inflight drain protocol lets the counter reach zero before the last sender has finished touching channel-owned objects.
- [Low] The comment block in nbl_chan_teardown_queue() that justifies the 5000 ms drain timeout states that 'polling senders re-check shutdn…
- [Low] Reported concern: the commit message presents an active inter-PF mailbox ('implement core inter-PF communication capability', 'One-shot…
- [Low] Reported concern: new comments and kerneldoc describe helpers and validation that do not exist at this commit -- nbl_channel.c…
- [Low] Reported concern: nbl_chan_send_msg() gates only on chan_info->shutdn, never on chan_info->active or num_txq_entries != 0.
- [Low] Reported concern: chan_info->active and chan_info->dma_allocated are used as check-then-set duplicate-call guards in…
--
net/nebula-matrix: add channel layer
This adds a mailbox-based channel layer for the nebula-matrix driver: an xarray of message handlers, TX/RX mailbox queue lifecycle management with devm/dmam allocated rings, and a small hw_ops layer for the mailbox queue registers. The channel ops are published into adapter->intf at probe; the callers arrive in later patches of the series.
No Link: tags were present in the commit header.
A few questions below, mostly around the teardown path.
First, one wording question about the changelog itself:
Quoted 1 line
- Create device-independent dedicated workqueue for RX cleanup tasks
[Severity: Low]
This isn't a bug, but is "device-independent" the right description? The workqueue created by nbl_common_create_wq() is named per device and stored in the per-device nbl_common_info:
snprintf(wq_name, sizeof(wq_name), "nbl_wq_%s", pci_name(common->pdev)); common->wq = alloc_workqueue(wq_name, WQ_UNBOUND, 0);
so it looks like one workqueue per adapter rather than a device-independent one.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1421 @@
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +7
-0+static void nbl_chan_stop_queue (struct nbl_channel_mgt *chan_mgt) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; + + hw_ops->stop_mailbox_rxq (chan_mgt->hw_ops_tbl->priv); + hw_ops->stop_mailbox_txq (chan_mgt->hw_ops_tbl->priv); +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 349
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +9
-0+mutex_lock (&chan_info->pending_lock); +for (i =0 ; i < chan_info->num_txq_entries; i++) { + wait_head = &chan_info->wait[i]; +nbl_chan_reset_wait_head (chan_info, wait_head); +WRITE_ONCE (wait_head->ack_err, (s32)-EIO ); +WRITE_ONCE (wait_head->acked,1 ); +wake_up (&wait_head->wait_queue); + } +mutex_unlock (&chan_info->pending_lock);
[Severity: Medium]
This loop resets every slot, including slots still owned by a live sender. Can that hand a wrong result back to that sender?
nbl_chan_reset_wait_head() publishes:
WRITE_ONCE(wait_head->ack_data_len, 0); WRITE_ONCE(wait_head->ack_err, 0);
while nbl_chan_send_msg() consumes its completion without pending_lock, in both the interrupt branch and the polling fast path:
if (READ_ONCE(wait_head->acked)) {
smp_rmb();
chan_send->ack_len = READ_ONCE(wait_head->ack_data_len);
ret = READ_ONCE(wait_head->ack_err);
}If the genuine ACK already landed (acked=1, status=ACKD) and teardown runs between those two loads, the sender can pair the real ack_data_len with the reset's ack_err == 0, reporting success for a remote failure, or the real ack_err with ack_data_len == 0. READ_ONCE()/smp_rmb() order the reads but do not exclude the concurrent overwrite.
The same reset also publishes status = NBL_MBX_STATUS_IDLE for a slot that still has an owner. nbl_chan_get_msg_id() allocates any IDLE or TIMEOUT slot and has no shutdn check, so can a sender that was admitted before shutdn was set be handed a slot that still belongs to another sender?
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 359
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+/* +* Drain strategy mirrors mlx5 command interface teardown: +* set shutdown flag first, abort all pending waiters, then +* block until inflight_tx_cnt reaches zero. +* +* After shutdn is set every sender exits promptly at its next +* checkpoint: +* - interrupt-driven senders wake on shutdn immediately +* (it is part of the wait_event condition); +* - polling senders re-check shutdn every 100-120us;
[Severity: Low]
The ACK-polling sender in nbl_chan_send_msg() sleeps:
usleep_range(NBL_CHAN_TX_WAIT_ACK_US_MIN, NBL_CHAN_TX_WAIT_ACK_US_MAX);
which is 1000-1200us, not 100-120us. The 100-120us figure is NBL_CHAN_TX_WAIT_US/NBL_CHAN_TX_WAIT_US_MAX, used only by the descriptor poll in nbl_chan_kick_tx_ring().
Worth noting that the polling sender's unshortened worst case is NBL_CHAN_TX_WAIT_ACK_TIMES (5000) x 1000-1200us = 5.0-6.0s, which equals or exceeds the msecs_to_jiffies(5000) drain window this comment is sizing. The shutdn check at the top of each iteration keeps that from mattering today.
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +8
-0+ err = !wait_event_timeout (chan_info->inflight_wait, +atomic_read (&chan_info->inflight_tx_cnt) ==0 , +msecs_to_jiffies (5000 )); +if (err) { +dev_warn (chan_mgt->common->dev, +"teardown: inflight tx drain timeout\n" ); + ret = -ETIMEDOUT ; + }
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 399
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+if (!err) { +mutex_lock (&chan_info->txq_lock); +nbl_chan_stop_queue (chan_mgt); +mutex_unlock (&chan_info->txq_lock); + }else if (mutex_trylock (&chan_info->txq_lock)) { +nbl_chan_stop_queue (chan_mgt); +mutex_unlock (&chan_info->txq_lock); + }else { +dev_crit (chan_mgt->common->dev, +"zombie channel: inflight sender holds txq_lock; HW stop skipped, queue left in QUEUE_RST; device requires reset before re-bind\n" ); + }
[Severity: High]
When the trylock fails, nbl_chan_stop_queue() is skipped for both queues. Can this leave the mailbox RX engine DMAing into freed coherent memory?
nbl_chan_stop_queue() is the only path to hw_ops->stop_mailbox_rxq(), and the sender-side recovery in nbl_chan_quiesce_and_reclaim_tx() only touches TX:
hw_ops->stop_mailbox_txq(hw_priv);
So after this branch the RX QINFO table still has QUEUE_EN=1 with 255 AVAIL descriptors whose buf_addr point at dmam_alloc_coherent() buffers:
nbl_chan_teardown_queue() returns -ETIMEDOUT
-> nbl_dev_remove_common_dev() only dev_warn()s the error -> nbl_core_remove() returns
-> devres frees rxq->desc.rx_desc and all 256 RX buffers
while the device can still write incoming peer messages and descriptor writeback into them.
Related, is the dev_crit() text accurate? It says "queue left in QUEUE_RST", but RX is never reset on this path, and for TX both shutdn checkpoints in nbl_chan_kick_tx_ring() return without emitting any register write:
if (READ_ONCE(chan_info->shutdn)) return -ESHUTDOWN;
Since nbl_hw_stop_mailbox_rxq() writes a different 16-byte QINFO region (NBL_MAILBOX_QINFO_CFG_RX_TABLE_ADDR) than any sender ever writes (NBL_MAILBOX_QINFO_CFG_TX_TABLE_ADDR), could the RX reset be issued unconditionally before the rings are released, rather than being gated on txq_lock?
[Severity: High]
The other half of this: teardown never waits for the lock holder, so can the surviving sender read freed memory?
A sender parked in nbl_chan_kick_tx_ring() holds txq_lock and polls the coherent TX descriptor ring:
if (le16_to_cpu(READ_ONCE(tx_desc->flags)) &
BIT(NBL_CHAN_TX_DESC_USED)) {Meanwhile teardown takes the trylock failure branch, runs cancel_work_sync(), sets active = false and returns -ETIMEDOUT, which is only dev_warn()ed, so nbl_core_remove() completes and devres frees the rings. The same sender then continues into its exit path and touches chan_info->state_lock and chan_info->wait[], which are devm allocated in nbl_chan_setup_chan_mgt() and freed at detach too:
mailbox = devm_kzalloc(dev, sizeof(*mailbox), GFP_KERNEL);
There is no bounded wait for the lock holder and no reference on chan_info, so nothing in the remove path joins it. Would a blocking wait for txq_lock (or a refcount/completion covering senders) be preferable to skipping the hardware stop here?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +2
-0+static int nbl_chan_setup_queue (struct nbl_channel_mgt *chan_mgt,u8 chan_type) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 423
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+if (READ_ONCE (chan_info->active)) { +dev_warn (common->dev,"channel already active, reject duplicate setup\n" ); +return -EBUSY ; + }
[Severity: Low]
This isn't a bug, since setup and teardown are only reachable from the probe and remove paths which the driver core serializes, but the header comment says otherwise:
/* Guards channel state bitmap, active and shutdn flags */ struct mutex state_lock;
active is read and written here and in nbl_chan_teardown_queue() without state_lock. Could the comment be narrowed to what state_lock actually guards?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 992
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]
This isn't a bug with the current call order, but the entry gate checks only shutdn, not active or num_txq_entries. send_msg is published in the ops table by nbl_chan_init_common() before setup_queue() runs, and with num_txq_entries still 0 this would reach:
return NBL_NEXT_ID(txq->next_to_use, num_entries - 1) == txq->next_to_clean;
which is a modulo by zero, followed by a NULL txq->desc.tx_desc. Every in-tree caller runs after a successful setup_queue(), so nothing hits it today. Would an active check here be worth adding as a guard?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 1211
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+out_clean_inflight: +mutex_lock (&chan_info->state_lock); +if (atomic_dec_and_test (&chan_info->inflight_tx_cnt)) +wake_up (&chan_info->inflight_wait); +mutex_unlock (&chan_info->state_lock); +return ret;
[Severity: Medium]
The counter reaches zero and teardown is woken before this sender has finished with state_lock. Can the mutex be freed under it?
sender:
mutex_lock(&chan_info->state_lock); atomic_dec_and_test(&chan_info->inflight_tx_cnt); /* true */ wake_up(&chan_info->inflight_wait); <preempted here> mutex_unlock(&chan_info->state_lock);
teardown only waits on the counter and never takes state_lock:
err = !wait_event_timeout(chan_info->inflight_wait, atomic_read(&chan_info->inflight_tx_cnt) == 0, msecs_to_jiffies(5000));
so it can proceed through nbl_chan_stop_queue(), cancel_work_sync() and return, and nbl_core_remove() can complete, letting devres release chan_info and run mutex_destroy() on a mutex that is still held. Does the wake_up() need to move after the unlock, or does the drain need to wait for the sender itself rather than the counter?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0
-0@@ -10,6 +10,44 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h line 41
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +7
-0+* All-zero mask (0x00) means all 8 PFs enabled, which is +* unsupported by the driver and rejected with -EINVAL. +* +* Firmware contract: number of unmasked PFs MUST equal +* get_board_info()->eth_num. +*/ +void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask);
[Severity: Low]
This isn't a bug, but several of the new comments describe code that only appears later in the series, which makes this patch hard to verify on its
own: this kerneldoc's -EINVAL rejection lives in nbl_res_init_pf_num(), the get_board_info() op does not exist yet, and nbl_chan_cfg_qinfo_map_table() defers to "resource initialization logic" that is not in the tree at this point. Likewise nbl_channel.c refers to hw_ops->flush_write() and nbl_hw_leonis.c refers to nbl_flush_writes(), cfg_msix_map(), set_mailbox_irq() and intr_mgt_stop, and NBL_HW_DUMMY_REG plus NBL_PCIE_HOST_TL_CFG_BUSDEV are added here with no user. Could the forward references be trimmed or the definitions land with their users?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 2/8 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
The Resource layer owns chip-agnostic resource entries and identity mappings, providing lookup and conversion helpers between VSI ID, func ID, eth ID and PF ID for upper dispatch and device layers.
This patch adds the common (chip-independent) resource layer:
- nbl_res_init_pf_num(): reads firmware k_pf_mask and validates the enabled PF topology. Only 1/2/4 contiguous PFs starting from PF0 are accepted; non-contiguous layouts, unsupported counts (0, 3, 5-8) and the all-zero mask (all 8 PFs enabled) are rejected with -EINVAL, causing probe to fail early.
- nbl_common_func_id_to_rel_pf_id(): translate absolute PF ID to relative PF index for resource table lookup.
- nbl_res_ctrl_dev_sriov_info_init(): derives each PF's BDF from the hardware bus number (read via get_real_bus) and the function offset, stored in sriov_info[] for MSI-X map programming.
- nbl_res_ctrl_dev_setup_eth_info(): validates that firmware port count (get_board_info()->eth_num) matches max_pf and the eth bitmap reported by get_fw_eth_map(), then builds the per-PF eth_id / logic_eth_id lookup tables.
- nbl_res_ctrl_dev_vsi_info_init(): assigns per-PF VSI base IDs. VSI ID gap is 1024 for 1 port, 512 for 2 ports, 256 for 4 ports respectively.
- Conversion helpers nbl_res_func_id_to_vsi_id(), nbl_res_vsi_id_to_pf_id() and nbl_res_get_eth_id() with full range and has_ctrl guards.
All initialization above runs only on the control PF (common->has_ctrl == true). Resource tables are built once during control PF probe and remain read-only afterwards, so lookup helpers require no internal locking.
The resource conversion helpers themselves do not include locking; all resource operations must be serialized by upper dispatch layer via ops_mutex_lock. Non-control PF requests are routed to control PF via mailbox RPC, and these helpers are only executed on control PF.
All resource allocations use devm managed memory, no explicit cleanup needed in remove path.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 2 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 22 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 67 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 14 + .../nbl_hw_leonis/nbl_resource_leonis.c | 329 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 10 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 125 +++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 69 ++++ .../nbl/nbl_include/nbl_def_channel.h | 10 + .../nbl/nbl_include/nbl_def_common.h | 20 ++ .../nbl/nbl_include/nbl_def_hw.h | 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 + 15 files changed, 727 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
@@ -6,4 +6,6 @@ obj-$(CONFIG_NBL) := nbl.o nbl-objs += nbl_common/nbl_common.o \ nbl_channel/nbl_channel.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ + nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ + nbl_hw/nbl_resource.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +22 -0
@@ -29,3 +29,25 @@ int nbl_common_create_wq(struct nbl_common_info *common)return 0 ; } +/** +* nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id +* @common: common device info +* @pf_id: absolute PF identifier +* @rel_pf_id: output relative pf id +* +* Leonis uses fixed mgt_pf = 0. Support future non-zero management PF. +* +* Return: 0 on success, -EINVAL on invalid arguments. +*/ +int nbl_common_func_id_to_rel_pf_id (struct nbl_common_info *common,u32 pf_id, +u32 *rel_pf_id) +{ +if (!rel_pf_id) +return -EINVAL ; + +if (pf_id < common->mgt_pf) +return -EINVAL ; + *rel_pf_id = pf_id - common->mgt_pf; +return 0 ; +} +
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -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 +14 -0
@@ -53,5 +53,19 @@ struct nbl_mailbox_qinfo_cfg_table {#define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004)#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040) +#define NBL_PCIE_BUS_MASK GENMASK(12, 5) +#define NBL_FW_BOARD_CONFIG 0x200 +#define NBL_FW_BOARD_DW3_OFFSET (NBL_FW_BOARD_CONFIG + 12) +#define NBL_FW_BOARD_DW6_OFFSET (NBL_FW_BOARD_CONFIG + 24) + +#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0) +#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1) +#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8) +#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10) +#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13) + +#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0) +#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8) +#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_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 -0
@@ -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,16 @@ 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,
@@ -39,9 +41,22 @@ struct nbl_hw_ops {* get_board_info()->eth_num. */ 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 v29 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] Commit message statements are not backed by the submitted code:
(a) it says nbl_res_ctrl_dev_setup_eth_info() builds "the per-PF…
--
net/nebula-matrix: add common resource implementation
This adds the chip-independent resource layer for the nbl driver: PF mask parsing, SR-IOV BDF table construction, eth info and VSI base id setup on the control PF, plus VSI/func/eth id conversion helpers.
Quoted 4 lines
-
nbl_res_ctrl_dev_setup_eth_info(): validates that firmware port count (get_board_info()->eth_num) matchesmax_pfand the eth bitmap reported byget_fw_eth_map(), then builds the per-PFeth_id/logic_eth_idlookup tables.
[Severity: Low]
Is there really a logic_eth_id lookup table? struct nbl_eth_info in nbl_hw/nbl_resource.h only carries eth_num and eth_id[]:
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h line 29
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +5
-0+struct nbl_eth_info { +u8 eth_num; +u8 resv[3 ]; +u8 eth_id[NBL_MAX_ETHERNET ]; +};
and nbl_res_get_eth_id() computes the logical id on the fly from the relative PF id rather than reading it from a table:
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c line 108
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +1
-0+ *logic_eth_id = rel_pf_id;
Would it be more accurate to say setup_eth_info() builds the per-PF eth_id table, and that logic_eth_id is derived from the relative PF id?
Quoted 4 lines
The resource conversion helpers themselves do not include locking; all resource operations must be serialized by upper dispatch layer via
ops_mutex_lock. Non-control PF requests are routed to control PF via mailbox RPC, and these helpers are only executed on control PF.
[Severity: Low]
Do ops_mutex_lock and the mailbox RPC routing exist at this commit? A grep over drivers/net/ethernet/nebula-matrix/ at this revision finds no ops_mutex_lock at all, and enum nbl_chan_msg_type in nbl_include/nbl_def_channel.h only defines the ack opcode:
enum nbl_chan_msg_type {
NBL_CHAN_MSG_ACK = 0,
/* mailbox msg end */
NBL_CHAN_MSG_MAILBOX_MAX,
};The newly registered res_ops (get_vsi_id, get_eth_id) also have no caller yet, and non-control callers are rejected locally instead of being forwarded:
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!common->has_ctrl || !eth_num || !eth_id || !logic_eth_id) + return -EINVAL;
Both the ops_mutex_lock serialization and the mailbox RPC routing appear only in the later patches "dispatch: add control-level routing core infrastructure" and "dispatch: implement channel RPC framework and serialize hardware ops". Could the message be reworded to describe those as coming later in the series, so the "lookup helpers require no internal locking" claim is justified by code that is actually present?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 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.
- Deferred vector recycling mechanism: retire reconfigured vectors to a timed list and recycle only after hardware pipeline quiesces.
- Global cleanup via nbl_intr_mgt_stop(): iterate all 520 function IDs to clean up leftover MSI-X maps (including remote PF maps via mailbox RPC) before devres releases coherent resources.
- 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.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 142 +++- .../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 | 742 ++++++++++++++++++ .../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 | 66 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../nbl/nbl_include/nbl_include.h | 1 + 12 files changed, 1091 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 +140 -2
175 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 devres releases the 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 dmam_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 +742 -0
742 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 +66 -0
92 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);
@@ -45,6 +52,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 +1 -0
@@ -13,6 +13,7 @@#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +#define NBL_MAX_FUNC 520#define NBL_MAX_ETHERNET 4enum {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v29 net-next 3/8] net/nebula-matrix: add intr resource implementation
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 5
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 deferred vector-recycling deadline in nbl_intr_retire_vectors_locked() is `retired->expires = jiffies +…
- [Medium] On reconfiguration, nbl_res_intr_cfg_msix_map() rewrites the coherent MSI-X map table in place while the hardware FUNCTION_MSIX_MAP…
- [Medium] The new interrupt module never invalidates the chip tables it owns at init, and nbl_hw_cfg_msix_map() programs them in an unsafe…
- [Low] Commit message says nbl_intr_mgt_stop() cleans up "leftover MSI-X maps (including remote PF maps via mailbox RPC)" and the new resource…
- [Low] The ownership note in nbl_res_remove_leonis() documents the wrong memory-management API family: it states "Tear down all MSI-X maps…
- [Low] struct nbl_interrupt_mgt embeds func_intr_res[NBL_MAX_FUNC] with NBL_MAX_FUNC == 520, but nbl_res_intr_cfg_msix_map() calls…
- [Low] Concern: __nbl_res_intr_destroy_msix_map() drops intr_mgt->lock and sleeps ~1 ms, then re-acquires the lock through a cached intr_mgt…
- [Low] Concern: __nbl_res_intr_set_mailbox_irq() validates only func_res->interrupts != NULL and vector_id < num_interrupts, but not…
--
net/nebula-matrix: add intr resource implementation
This adds a new nbl_interrupt module that owns the chip-internal MSI-X vector index space (split into net and control bitmaps) and programs the chip MSI-X mapping registers. It also adds the hardware register definitions and the resource/hw ops plumbing to reach the new code.
A few questions about the new module below.
Before the diff, one question about the commit message:
Quoted 3 lines
- Global cleanup via
nbl_intr_mgt_stop(): iterate all 520 function IDs to clean up leftover MSI-X maps (including remote PF maps via mailbox RPC) before devres releases coherent resources.
[Severity: Low]nbl_intr_mgt_stop() only walks its own intr_mgt->func_intr_res[] state and writes registers directly through hw_ops; there is no channel or mailbox call anywhere in the new module.
Is the "via mailbox RPC" part meant to describe how those remote PF maps were originally created (later in the series, nbl_disp_chan_cfg_msix_map_resp() calls res_ops->cfg_msix_map(p, src_id, ...)), rather than how they are cleaned up here?
Related: none of cfg_msix_map, destroy_msix_map or set_mailbox_irq has an in-tree caller in this patch; they are wired up by a later patch in the series. Would it help to say so explicitly, the same way the message already does for pci_alloc_irq_vectors()?
Quoted 22 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +14
-0@@ -104,6 +104,20 @@ static void nbl_hw_rd_regs_lock(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 *data,spin_unlock (&hw_mgt->reg_lock); } +static void nbl_hw_wr_regs_lock (struct nbl_hw_mgt *hw_mgt,u64 reg, +const u32 *data,u32 len) +{ +u32 size = len /4 ; +u32 i; + +if (len %4 ) +return ; +spin_lock (&hw_mgt->reg_lock); +for (i =0 ; i < size; i++) +wr32 (hw_mgt->hw_addr, reg + i *sizeof (u32), data[i]); +spin_unlock (&hw_mgt->reg_lock); +} +
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -130,6 +144,126 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map) *eth_map =FIELD_GET (NBL_FW_BOARD_DW6_ETH_BITMAP_MASK , data); }
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +9
-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; + +memset (&function_msix_map,0 ,sizeof (function_msix_map)); +if (valid) { + function_msix_map.data[0 ] =lower_32_bits (dma_addr);
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 198
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+ function_msix_map.data[1 ] =upper_32_bits (dma_addr); +/* use ctrl dev's bdf, because the dma memory was +* allocated by it +*/ + function_msix_map.data[2 ] = +FIELD_PREP (NBL_FUNCTION_MSIX_MAP_FUNCTION_MASK , + function) | +FIELD_PREP (NBL_FUNCTION_MSIX_MAP_DEVID_MASK , devid) | +FIELD_PREP (NBL_FUNCTION_MSIX_MAP_BUS_MASK , bus) | +FIELD_PREP (NBL_FUNCTION_MSIX_MAP_VALID_MASK ,1 );
[Severity: Medium]
This programs the map entry in ascending dword order through nbl_hw_wr_regs_lock(): low address dword, high address dword, then BDF plus VALID. If the entry is already VALID from a previous driver instance, can the pcompleter fetch the map with a spliced base address (new low dword, stale high dword) before data[2] is rewritten?
The teardown path in this same function deliberately does the opposite (keeps a live address, clears VALID) with the comment:
* Keep valid live dma address here, only clear VALID flag.
Would clearing VALID first, flushing, then writing the address and setting VALID last be the safer order here as well?
Related: nbl_intr_mgt_start() -> nbl_intr_setup_mgt() only allocates and zeroes software state; it does not invalidate NBL_PCOMPLETER_FUNCTION_MSIX_MAP, NBL_PADPT_HOST_MSIX_INFO or NBL_PCOMPLETER_HOST_MSIX_FID_TABLE at init. The comment added above nbl_hw_set_mailbox_irq() says these chip registers "survive kexec/forced unload without FLR", which is why nbl_hw_cfg_mailbox_qinfo() clears MSIX_IDX_VALID at init. Does the same reasoning apply to the tables added here, which additionally hold a host DMA address that the new kernel now owns?
Quoted 17 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +17
-0+ }else { +/* +* reg_lock prevents concurrent CPU writes to the same +* function's MSIX entry, but cannot synchronize hardware DMA +* reads. Upper layer uses two-stage destruction + sync sleep +* to avoid torn hardware read of partial MSIX entry. +* Keep valid live dma address here, only clear VALID flag. +*/ + function_msix_map.data[0 ] =lower_32_bits (dma_addr); + function_msix_map.data[1 ] =upper_32_bits (dma_addr); + function_msix_map.data[2 ] =0 ; + } + +nbl_hw_wr_regs_lock (hw_mgt, +NBL_PCOMPLETER_FUNCTION_MSIX_MAP_REG_ARR (func_id), + function_msix_map.data,sizeof (function_msix_map)); +}
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +0
-0
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +8
-2@@ -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 devres releases the coherent +* tables. This is critical on the control PF, which may hold
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c int nbl_res_init_leonis(struct nbl_adapter *adap) · line 352
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +10
-0+* 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 dmam_free_coherent() +* inside the intr destroy path, before nbl_intr_mgt_stop() returns.
[Severity: Low]
Does this note describe the wrong API family? The new module allocates with dma_alloc_coherent() in nbl_res_intr_cfg_msix_map() and frees with dma_free_coherent() in __nbl_res_intr_complete_destroy_msix_map() and in the release_vecs_unlock error path; dmam_ is never used, so there is no devres record for these tables and nothing for devres to release.
Either correcting the comment or switching to dmam_alloc_coherent() would make the ownership model match the code. As written, a future error path that skips the explicit free would leak the coherent table for the lifetime of the device with no devres safety net.
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +2
-0+* intr_mgt itself (devm_kzalloc) is released by devres after this +* function returns */ }drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0@@ -0,0 +1,742 @@
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +2
-0+#define NBL_MSIX_DMA_SYNC_MIN_US 1000/* us */ +#define NBL_MSIX_DMA_SYNC_MAX_US 1200/* us */
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 70
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12
-0+static void nbl_intr_retire_vectors_locked (struct nbl_resource_mgt *res_mgt, +u16 *vectors,u16 cnt) +{ +struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt; +struct nbl_intr_retired_vectors *retired; + + retired =kzalloc_obj (*retired,GFP_KERNEL ); +if (retired) { + retired->vectors = vectors; + retired->cnt = cnt; + retired->expires = jiffies + +usecs_to_jiffies (NBL_MSIX_DMA_SYNC_MIN_US );
[Severity: Medium]
Does this deadline actually deliver the ~1000 us quiesce window?
usecs_to_jiffies(1000) is 1 for the common HZ values, and adding a jiffy count to the current jiffies only guarantees (count - 1) full ticks of elapsed time. With count == 1 the guaranteed wait is ~0 us, since the current tick may be about to end.
nbl_intr_sweep_retired_locked() then releases the indices as soon as:
if (!time_after_eq(jiffies, retired->expires)) return;
holds, and nbl_res_intr_cfg_msix_map() calls the sweep immediately before allocating from the same bitmaps with find_first_zero_bit(). So a just retired global index can be reprogrammed into PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with a different function's BDF and FID microseconds later.
The synchronous path uses usleep_range(NBL_MSIX_DMA_SYNC_MIN_US, NBL_MSIX_DMA_SYNC_MAX_US) for exactly this purpose, and the struct field is documented as "jiffies at which recycling is safe". Would adding one extra jiffy, or using a ktime based deadline, keep the documented window?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +3
-0+list_add_tail (&retired->node, &intr_mgt->retired_list); +return ; + }
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+static int __nbl_res_intr_set_mailbox_irq (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 vector_id, +bool en_msix) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 165
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+if (!intr_mgt->func_intr_res[func_id].interrupts) { +dev_err (dev,"func %u MSIX map not configured\n" , func_id); +return -ENODEV ; + }
[Severity: Low]
This isn't reachable today, but should the enable path also test state == NBL_INTR_FUNC_CONFIGURED (and intr_mgt->stopping), the way nbl_res_intr_cfg_msix_map() rejects NBL_INTR_FUNC_DESTROYING with -EBUSY?
During the unlocked quiesce window of a teardown the function is in NBL_INTR_FUNC_DESTROYING but interrupts[] is still populated, so only the pointer and range checks here would pass. An en_msix=true call in that window would arm NBL_MAILBOX_QINFO_MAP MSIX_IDX/MSIX_IDX_VALID with a global vector that __nbl_res_intr_complete_destroy_msix_map() is about to release, and the complete phase never re-disables routing, so the routing would outlive the vector.
I could not build that race with the current callers: every caller of res_ops->set_mailbox_irq and res_ops->destroy_msix_map holds disp_mgt->ops_mutex_lock across the whole resource call, and nbl_intr_mgt_stop() runs only after the mailbox work item is cancelled. The asymmetry between the two entry points still looks worth closing.
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +2
-0+ +if (vector_id >= intr_mgt->func_intr_res[func_id].num_interrupts) {
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-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;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 335
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+int ret; + +lockdep_assert_held (&intr_mgt->lock); + + ret =__nbl_res_intr_prepare_destroy_msix_map (res_mgt, func_id); +if (ret) +return ret; +mutex_unlock (&intr_mgt->lock); +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); +mutex_lock (&intr_mgt->lock);
[Severity: Low]
This isn't reachable with the callers in this series, but the lock is dropped for ~1 ms and then retaken through the cached intr_mgt pointer, while nbl_intr_mgt_stop() can set res_mgt->intr_mgt = NULL outside the lock and let devres free the object:
nbl_intr_mgt_stop()
mutex_unlock(&intr_mgt->lock); res_mgt->intr_mgt = NULL;
A thread parked in the window above would then either take a freed mutex here, or dereference NULL when __nbl_res_intr_complete_destroy_msix_map() re-reads res_mgt->intr_mgt.
I traced the callers and could not construct the overlap: all three public ops are invoked under disp_mgt->ops_mutex_lock, the local path runs from nbl_core_stop() before nbl_core_remove(), and nbl_dev_remove_common_dev() does cancel_work_sync(&common_dev->clean_mbx_task) and tears down the mailbox queue before nbl_res_remove_leonis() calls nbl_intr_mgt_stop().
Since nbl_intr_mgt_stop() has no admission or drain protocol, would an explicit "no users in flight" guarantee (or clearing res_mgt->intr_mgt under the lock) be worth adding so this stays safe if a caller outside the dispatch mutex appears later?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +3
-0+ +return __nbl_res_intr_complete_destroy_msix_map (res_mgt, func_id); +}
[ ... ]
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +12
-0+/* +* Phase2: tear down old hardware MSIX config. Old vectors are +* moved to the retired list and recycled only after the +* hardware pipeline has quiesced. +* NOTE: NO DMA table free here, only invalidate HW entries. +*/ +if (intr_mgt->func_intr_res[func_id].interrupts) { + old_interrupts = intr_mgt->func_intr_res[func_id].interrupts; + old_num = intr_mgt->func_intr_res[func_id].num_interrupts; + + ret =__nbl_res_intr_set_mailbox_irq (res_mgt, func_id,0 , + false);
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 533
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+if (ret) { +dev_err (dev,"%s: disable old mailbox irq failed, keep old config\n" , + __func__); + goto release_vecs_unlock; + } +for (j =0 ; j < old_num; j++) { + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, false, old_interrupts[j], +0 ,0 ,0 , false); + }
[Severity: Medium]
On the reconfiguration path, only the per-vector PADPT_HOST_MSIX_INFO entries are invalidated here; cfg_msix_map(..., valid=false, ...) is never called, so NBL_FUNCTION_MSIX_MAP_VALID_MASK stays set for this function and the pcompleter can DMA-read the table at any point.
The code then rewrites that same live table in place below, one entry at a time, with the only barrier issued after the whole loop. Can the device observe a torn mix of old and new translations, for example a new gvec whose PADPT_HOST_MSIX_INFO and FID entries are not valid yet, or a cleared entry for a vector still in use?
__nbl_res_intr_prepare_destroy_msix_map() treats this as a real hazard and does clear the map VALID bit, flush, and wait ~1 ms before touching the table. Should the reconfiguration path follow the same sequence, or double-buffer the table?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +3
-0+ hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); +nbl_intr_retire_vectors_locked (res_mgt, old_interrupts, + old_num);
[ ... ]
Quoted 21 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +21
-0+ msix_map_entries = official_tbl->base_addr; +memset (msix_map_entries + requested,0 , + (NBL_MSIX_MAP_TABLE_MAX_ENTRIES - requested) * +sizeof (*msix_map_entries)); + +for (i =0 ; i < requested; i++) { + gvec = intr_mgt->func_intr_res[func_id].interrupts[i]; + msix_map_entries[i].data = +cpu_to_le16 (FIELD_PREP (NBL_MSIX_MAP_VALID_MASK ,1 ) | +FIELD_PREP (NBL_MSIX_MAP_INDEX_MASK , + gvec)); + entry_masked = (i < num_net_msix && net_msix_mask_en); + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, true, gvec, + bus, devid, function, + entry_masked); + } + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +/* Ensure coherent memory writes are visible before HW DMA fetch */ +dma_wmb ();
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +0
-0@@ -68,6 +68,38 @@ int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id)
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +7
-0+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 ; + }
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h line 79
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +8
-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); +struct list_head retired_list; +bool stopping;/* set on teardown, rejects new configurations */ +struct nbl_func_interrupt_resource_mng func_intr_res[NBL_MAX_FUNC ]; +};
[Severity: Low]
Can any func_id above max_pf ever occupy one of these 520 entries?
nbl_res_intr_cfg_msix_map() calls nbl_res_func_id_to_bdf() before recording any state, and that helper returns -EOPNOTSUPP whenever rel_pf_id >= common->max_pf, with max_pf bounded by NBL_MAX_PF (8). So at most 8 of the 520 entries can reach NBL_INTR_FUNC_CONFIGURED.
struct nbl_func_interrupt_resource_mng is 48 bytes after padding, so the array is roughly 25 KB embedded in the single devm_kzalloc for intr_mgt (an order-3 allocation), of which about 24.5 KB can never be used, and both nbl_intr_mgt_stop() loops scan 520 entries that can never leave NBL_INTR_FUNC_IDLE.
The commit message lists both "iterate all 520 function IDs" and "PF-only
support: explicitly reject VF function IDs with -EOPNOTSUPP" as features. Which of the two is the intended design?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +1
-0+/* --------- INFO ---------- */ struct nbl_sriov_info {unsigned int bdf;
[ ... ]
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +1
-0@@ -13,6 +13,7 @@#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +#define NBL_MAX_FUNC 520#define NBL_MAX_ETHERNET 4
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 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 logic for Nebula Matrix Ethernet driver, providing full datapath pipeline configuration and orderly chip-level resource teardown infrastructure.
This patch implements complete chip hardware lifecycle management to initialize core datapath components including packet engines, scheduler, buffer stores, queue manager, per-port traffic shaping and flow control. It also maintains the firmware-synced driver_status flag to coordinate driver-firmware state.
Core framework enhancements:
1. Add hw_ops.init_module/deinit_module and resource_ops entry points for chip-level hardware lifecycle management. Callback invocation path will be added in a subsequent patch, only ops registration here.
2. Implement PCI domain/bus/slot based chip-wide PF registry to track active driver-bound PFs, preventing premature chip-global firmware deinitialization.
3. Add device link dependency for non-management PFs to enforce deterministic teardown order, ensuring consumer PFs release before management PF (func 0).
Datapath sub-module initialization covers all core hardware units:
- dped/uped: Configure packet engine registers, checksum offload and TCP profiles
- dsch: Setup scheduler VN quanta and host QID maximum threshold
- ustore/dstore: Tune Tx/Rx buffer thresholds, drop control and flow control
- dvn/uvn: Configure descriptor timeout, PCIe RO and prefetch with firmware quirks
- uqm: Reset queue counters and initialize queue working mode
- shaping: Apply port-speed tailored rate shaping and PSHA scheduler config
Complete chip initialization flow:
1. Initialize all datapath sub-modules via unified nbl_dp_init() entry
2. Configure host adapter PADPT layer flow control via nbl_intf_init()
3. Set driver_status active flag and flush all hardware register writes
Key safety and design guarantees:
- Restrict all chip-global operations exclusively to management PF via has_ctrl
- Only driver register programming; full chip reset is managed by firmware
- Explicit register flushing ensures consistency with async firmware cleanup
- Strict teardown ordering blocks new DMA and in-flight mailbox transactions
- Support UVN descriptor prefetch alignment firmware quirk optimization
Deinit behavior note:
Chip-wide datapath registers are not auto-restored by firmware on deinit. The deinit path only clears driver_status and flushes writes, retaining hardware state until chip reset or explicit overwriting.
Add corresponding register definitions, firmware ABI enums, helper routines, resource callbacks and Makefile entries to wire up the new chip management.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 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 | 633 +++++++++++++++++- .../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_common.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 | 56 ++ 13 files changed, 985 insertions(+), 4 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_common/nbl_common.c +0 -1
@@ -50,4 +50,3 @@ int nbl_common_func_id_to_rel_pf_id(struct nbl_common_info *common, u32 pf_id, *rel_pf_id = pf_id - common->mgt_pf;return 0 ; } -
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 +632 -1
651 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_common.h +0 -1
@@ -51,5 +51,4 @@ 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 +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
@@ -30,4 +30,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 +56 -0
80 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v29 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · 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).
- [High] nbl_probe_chip_deps() creates a *managed* device link (DL_FLAG_AUTOREMOVE_CONSUMER, i.e. DL_FLAG_MANAGED, not…
- [Medium] Commit message bullet 2 ("Implement PCI domain/bus/slot based chip-wide PF registry to track active driver-bound PFs, preventing…
- [Low] nbl_hw_deinit_module() only clears the driver_status bit and issues a posted-write flush, and its own comment concedes that…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds Leonis chip-wide hardware init/deinit for the nbl driver, programming the datapath sub-modules (dped/uped, dsch, ustore/dstore, dvn/uvn, uqm, shaping) and maintaining the firmware-synced driver_status flag. It also registers the new hw_ops/resource_ops entry points and adds a device link from each non-management PF to func 0.
A few questions below.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 19 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +19
-0+/* +* 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. +* +* This deinit_module only clears driver active status and flush writes. +* It does NOT reset or restore chip-wide datapath registers. +* +* Caller must ensure no new DMA is initiated after this point. +* The mailbox channel is stopped by nbl_chan_teardown_queue() +* before this function is called, so no in-flight mailbox DMA +* remains. +*/ +static void nbl_hw_deinit_module (struct nbl_hw_mgt *hw_mgt) +{ +nbl_hw_set_driver_status (hw_mgt, false);
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 724
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+/* ensure registers written */ +nbl_flush_writes (hw_mgt); +/* +* Firmware cleanup is asynchronous: there is no cleanup-complete +* status register in the current hardware revision. The posted +* write flush above only ensures driver_status reaches the chip; +* firmware may still be performing per-PF state cleanup when this +* function returns. +*/ +}
[Severity: Low]
Is there any boundary that separates the asynchronous firmware cleanup started here from subsequent driver register programming?
nbl_hw_deinit_module() posts driver_status = 0 and flushes, and the comment states firmware may still be modifying per-PF state on return. There is no status poll, mailbox ack or bounded delay.
Could a later nbl_hw_init_module() on the same chip then reprogram per-PF and chip-wide registers while the previous cleanup pass is still running?
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 89
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +4
-0@@ -83,6 +83,56 @@ 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: +* - register it in the chip registry so control PF teardown can detect +* siblings that are still bound;
[Severity: Medium]
Where is the chip registry this comment refers to?
The commit message also says:
"2. Implement PCI domain/bus/slot based chip-wide PF registry to track active driver-bound PFs, preventing premature chip-global firmware deinitialization."
but nbl_probe_chip_deps() only does pci_get_domain_bus_and_slot() followed by device_link_add(), with no registry insertion, and the chip-global deinit entry point has no sibling check either:
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c:
void nbl_res_chip_deinit_module(struct nbl_resource_mgt *res_mgt)
{
...
if (!common->has_ctrl)
return;
hw_ops->deinit_module(res_mgt->hw_ops_tbl->priv);
}A later patch in the series repeats the claim: the comment above nbl_dev_remove_ctrl_dev() in nbl_dev.c says "Safety net: this registry check additionally blocks the chip-global deinit if a sibling PF is somehow still bound on the same chip", while that function body only calls deinit_module().
Was the registry code lost when the series was split, or should the commit message bullet and both comment blocks be dropped?
Quoted 27 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +27
-0+* - 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. +* +* The management PF is addressed by the deterministic identity +* (domain, bus, slot, func 0) instead of any name-based scan: hardware +* guarantees PFs are contiguous from func 0 in the same slot. +* +* The link uses DL_FLAG_AUTOREMOVE_CONSUMER, so it is dropped by the +* driver core when this PF detaches; it must not be removed manually. +* A DORMANT link (func 0 not bound yet) activates automatically once +* the management PF driver binds. +* +* Return: 0 on success, negative errno on failure. On failure the chip +* registry entry has already been rolled back. +*/ +static int nbl_probe_chip_deps (struct pci_dev *pdev,bool has_ctrl) +{ +struct pci_dev *mgt; +int err =0 ; + +if (has_ctrl) +return 0 ; + + mgt = pci_get_domain_bus_and_slot(pci_domain_nr(pdev->bus),
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 126
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+ 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 ; + } + +if (!device_link_add (&pdev->dev, &mgt->dev, +DL_FLAG_AUTOREMOVE_CONSUMER )) {
[Severity: High]
Can this trigger a WARN in the driver core when func 0 is not bound?
DL_FLAG_AUTOREMOVE_CONSUMER implies DL_FLAG_MANAGED, and the link is created from inside the consumer's own probe. If the supplier has no driver, device_link_init_status() picks the default case:
drivers/base/core.c:device_link_init_status() {
...
case DL_DEV_UNBINDING:
link->status = DL_STATE_SUPPLIER_UNBIND;
break;
default:
link->status = DL_STATE_DORMANT;
...
}and when this consumer's probe completes:
drivers/base/core.c:device_links_driver_bound() {
...
WARN_ON(link->status != DL_STATE_CONSUMER_PROBE);
WRITE_ONCE(link->status, DL_STATE_ACTIVE);
...
}so the link is force-promoted to ACTIVE from an illegal state with a backtrace, rather than the behaviour the comment describes ("A DORMANT link (func 0 not bound yet) activates automatically once the management PF driver binds").
There is also the DL_DEV_UNBINDING window: if func 0 is being unbound, __device_release_driver() has already run device_links_unbind_consumers() for it before this link existed. In that case does the ordering property the commit message relies on ("the driver core then guarantees ... 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") still hold, or can the newly bound consumer outlive the management PF's chip-global deinit?
Would returning -EPROBE_DEFER while func 0 is unbound, or using DL_FLAG_STATELESS with an explicit device_link_del(), fit better here?
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +13
-0+dev_err (&pdev->dev, +"failed to create device link to management PF %s\n" , +pci_name (mgt)); + err = -ENOMEM ; + } +pci_dev_put (mgt); +return err; +} +static int nbl_probe (struct pci_dev *pdev,const struct pci_device_id *id) {@@ -103,6 +153,10 @@ static int nbl_probe(struct pci_dev *pdev,pci_set_master (pdev); + err =nbl_probe_chip_deps (pdev, param.caps.has_ctrl); +if (err) + goto chip_deps_err; +
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 5/8 net/nebula-matrix: dispatch: add control-level routing core infrastructure
In reply to illusion.wangFrom: illusion wang <[email protected]>
Implement core dispatch layer infrastructure for control-plane routing:
Allocate dispatch management structure and dispatch ops table Provide init_module/deinit_module wrapper callbacks for chip resource ops Introduce ctrl_lvl bitmask tracking; enable MGT level only for Control PF
Regular PF NET level routing will be added in a subsequent patch. Kerneldoc on nbl_dispatch_ops documents that init_module/deinit_module must only be invoked on Control PF behind has_ctrl guard.
This skeleton establishes dispatch management flow. It adds forward definitions of channel wire ABI structures and response enums required for later channel RPC framework, without implementing message handling.
--- .../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_channel.h | 35 ++++++ .../nbl/nbl_include/nbl_def_dispatch.h | 39 ++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 7 files changed, 225 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_channel.h +35 -0
@@ -7,6 +7,7 @@#define _NBL_DEF_CHANNEL_H_#include <linux/types.h> +#include <linux/build_bug.h> struct nbl_channel_mgt ;struct nbl_adapter ;
@@ -39,6 +40,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 +73,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 new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_DISPATCH_H_ +#define _NBL_DEF_DISPATCH_H_ + +#include <linux/types.h> + +struct nbl_dispatch_mgt ; +struct nbl_adapter ; +enum { +NBL_DISP_CTRL_LVL_MGT , +NBL_DISP_CTRL_LVL_MAX , +}; + +/** +* struct nbl_dispatch_ops - dispatch control plane operation callbacks +* @init_module: dispatch layer initialization, ONLY valid on Control PF, +* caller must check has_ctrl guard +* @deinit_module: dispatch layer cleanup, ONLY valid on Control PF, +* caller must check has_ctrl guard +* Warning: All ops except init_module/deinit_module can be safely called +* on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr. +*/ +struct nbl_dispatch_ops { +int (*init_module)(struct nbl_dispatch_mgt *disp_mgt); +void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt); +}; + +struct nbl_dispatch_ops_tbl { +struct nbl_dispatch_ops *ops; +struct nbl_dispatch_mgt *priv; +}; + +int nbl_disp_init (struct nbl_adapter *adapter); +void nbl_disp_remove (struct nbl_adapter *adapter); +#endif
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 v29 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] Commit message describes content the patch does not contain: it claims the patch "adds forward definitions of channel wire ABI…
--
net/nebula-matrix: dispatch: add control-level routing core infrastructure
This patch adds the nbl dispatch layer skeleton: it allocates the dispatch management structure and ops table, wires init_module/deinit_module wrappers to the resource ops, and tracks control levels in a ctrl_lvl bitmap. It also adds four channel parameter structures with size assertions to nbl_def_channel.h.
Quoted 3 lines
This skeleton establishes dispatch management flow. It adds forward definitions of channel wire ABI structures and response enums required for later channel RPC framework, without implementing message handling.
[Severity: Low]
Could the "and response enums" part of this sentence be dropped or corrected? The patch does not appear to add or modify any enum.
The only additions to nbl_def_channel.h are the four structures nbl_chan_param_cfg_msix_map, nbl_chan_param_set_mailbox_irq, nbl_chan_param_get_vsi_id and nbl_chan_param_get_eth_id, plus their four static_assert() size checks:
Quoted 27 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +19
-0@@ -39,6 +40,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 {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h enum nbl_chan_state { · line 71
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +7
-0+__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;
[ ... ]
After this patch, enum nbl_chan_msg_type in the same header is still unchanged from the baseline:
enum nbl_chan_msg_type {
NBL_CHAN_MSG_ACK = 0,
/* mailbox msg end */
NBL_CHAN_MSG_MAILBOX_MAX,
};and there is no response or return-code enum added anywhere else in the patch.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 6/8 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add bidirectional mailbox RPC for cross-PF resource coordination, implementing request/response handlers for five operations:configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id.
Dispatch operations are resolved dynamically based on PF control capability via nbl_disp_refresh_ctrl_ops():
- Control PF (NBL_DISP_CTRL_LVL_MGT): invokes local hardware ops directly.
- Non-control PF with net capability (NBL_DISP_CTRL_LVL_NET):
forwards requests via mailbox RPC to the manager PF.
- Neither level set: all dispatch ops are NULL.
Introduce per-dispatch mutex ops_mutex_lock to serialize mutable hardware operations (cfg_msix_map, destroy_msix_map, set_mailbox_irq). The mutex protects both local control-PF call paths and asynchronous remote mailbox RPC response handlers to eliminate race windows. Read-only get_vsi_id() / get_eth_id() access static init-time metadata; disp_ops table updates only happen during probe, so no runtime concurrent modification.
nbl_disp_setup_msg() registers five dispatch-layer wire message response handlers with the channel layer:NBL_CHAN_MSG_CONFIGURE_MSIX_MAP, NBL_CHAN_MSG_DESTROY_MSIX_MAP, NBL_CHAN_MSG_MAILBOX_SET_IRQ, NBL_CHAN_MSG_GET_VSI_ID, NBL_CHAN_MSG_GET_ETH_ID.
Message IDs are non-contiguous to preserve compatibility with reserved and deprecated message entries.
Extend wire protocol with new message types.
Every responder validates:
- src_id against common->max_pf at runtime; rejects VF and out-of-range function IDs with -EPERM;
- incoming payload length against the expected parameter struct size before parsing;
- unimplemented operation via NULL function pointer check before dispatch.
Remote responders return standard Linux errnos directly on the wire. Transport errors are returned unchanged from chan_ops->send_msg(). get_vsi_id_req() and get_eth_id_req() verify chan_send.ack_len matches sizeof(result) before dereferencing the response, rejecting truncated ACKs with -EREMOTEIO to prevent adoption of zeroed identifiers from a short reply.
destroy_msix_map responder clears the mailbox QINFO MSIX routing (MSIX_IDX / MSIX_IDX_VALID) as Step 0 before tearing down the MSI-X map, ensuring a recycled global vector cannot trigger an interrupt owned by a different function.
cfg_msix_map pre-allocates all coherent DMA buffers and global vector indices before destroying the old configuration, then swaps the new resources into the per-function entry to avoid interrupt loss during reconfiguration.
RPC caller precondition: disable mailbox IRQ_RDY and switch send_msg to polling path before invoking cfg_msix_map / destroy_msix_map RPC, because responder modifies mailbox MSIX routing and ACK cannot rely on interrupt wakeup.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 538 +++++++++++++++++- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 2 + .../nbl/nbl_include/nbl_def_channel.h | 5 + .../nbl/nbl_include/nbl_def_dispatch.h | 17 + 4 files changed, 561 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +537 -1
@@ -3,9 +3,176 @@* 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 -EREMOTEIO ; + } + *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 = -EREMOTEIO ; + 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); +if (ret) + err = -EREMOTEIO ; + }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 -EREMOTEIO ; + } + *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 = -EREMOTEIO ; + 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); +if (ret) + err = -EREMOTEIO ; + }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 +192,347 @@ 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; +} + +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 ; +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to polling path before issuing cfg_msix_map RPC. +* The responder will disable mailbox MSIX routing during resource ops, +* so ACK cannot rely on interrupt wakeup. +*/ +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 = -EREMOTEIO ; + 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); +if (ret) + err = -EREMOTEIO ; + }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 ); +} + +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 ; +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to polling path before issuing destroy_msix_map. +* The responder will disable mailbox MSIX routing during resource ops, +* so ACK cannot rely on interrupt wakeup. +*/ +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); +if (ret) + err = -EREMOTEIO ; + }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 ); +} + +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 = -EREMOTEIO ; + 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); +if (ret) + err = -EREMOTEIO ; + }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 +542,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 +566,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 +629,25 @@ 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 allocated via devm. +* Message handlers registered by nbl_disp_setup_msg() are owned by +* channel layer; they are unregistered in nbl_chan_remove_common(), +* not here. +*/ }
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 +5 -0
@@ -31,6 +31,11 @@ typedef void (*nbl_chan_resp)(void *, u16, u16, void *, u32);*/ enum nbl_chan_msg_type {NBL_CHAN_MSG_ACK =0 , +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP =17 , +NBL_CHAN_MSG_DESTROY_MSIX_MAP =18 , +NBL_CHAN_MSG_MAILBOX_SET_IRQ =19 , +NBL_CHAN_MSG_GET_VSI_ID =21 , +NBL_CHAN_MSG_GET_ETH_ID =67 ,/* mailbox msg end */ NBL_CHAN_MSG_MAILBOX_MAX , };
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +17 -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,12 +22,28 @@ enum {* caller must check has_ctrl guard * @deinit_module: dispatch layer cleanup, ONLY valid on Control PF, * 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: All ops except init_module/deinit_module can be safely called * on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr. */ 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 v29 net-next 6/8] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The kernel-doc block for struct nbl_dispatch_ops (drivers/net/ethernet/nebula-…
- [Low] All five new responders collapse resource-layer errors into a single -EREMOTEIO on the wire (`ret = res_ops->...(); if (ret) err =…
- [Low] The two "Precondition: caller must disable mailbox IRQ_RDY and switch send_msg to polling path ..." comments are attached to the…
- [Low] Reported concern: nbl_disp_chan_set_mailbox_irq_req() is the only newly added mutating RPC without the polling-path precondition…
- [Low] Reported concern: the five mailbox responders registered by nbl_disp_setup_msg() are never quiesced or unregistered by the…
Pre-existing issues:
- [Low] Reported concern: on the reconfiguration path cfg_msix_map rewrites the function's coherent MSI-X map table in place while…
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This adds mailbox RPC request/response handlers for five dispatch operations (configure_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id, get_eth_id), resolves disp_ops dynamically from the PF control capability, and adds a per-dispatch mutex to serialize the mutating hardware ops.
A few questions below, mostly about the documented contracts and about error propagation on the wire.
On the commit message:
Quoted 4 lines
cfg_msix_mappre-allocates all coherent DMA buffers and global vector indices before destroying the old configuration, then swaps the new resources into the per-function entry to avoid interrupt loss during reconfiguration.
[Severity: Low]
This isn't a bug introduced by this patch, but does the resource layer actually match this description on the reconfiguration path?
In nbl_res_intr_cfg_msix_map() in nbl_hw/nbl_interrupt.c the existing coherent map table is rewritten in place:
msix_map_entries = official_tbl->base_addr; memset(msix_map_entries + requested, 0, ...); for (i = 0; i < requested; i++) msix_map_entries[i].data = ...;
while PCOMPLETER_FUNCTION_MSIX_MAP still has VALID=1 pointing at that buffer, i.e. without the clear-VALID/quiesce sequence the teardown path uses.
Each struct nbl_msix_map entry is a single __le16 so no torn entry is possible, and the old global vectors have already had their PCOMPLETER_HOST_MSIX_FID_TABLE / PADPT_HOST_MSIX_INFO entries invalidated, so interrupts arriving in that window are suppressed rather than misrouted. Also, no caller in this series reaches the reconfiguration branch, since it requires func_intr_res[func_id].interrupts != NULL and nbl_dev_start() destroys the map on every failure path (err_destroy_map), while nbl_dev_stop() destroys it on the normal path.
Would it be more accurate to drop or qualify the "avoid interrupt loss during reconfiguration" claim?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0@@ -3,9 +3,176 @@
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +9
-0+ 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 -EREMOTEIO ; + }
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0@@ -25,6 +192,347 @@ 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) +{
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +6
-0+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; +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 245
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +8
-0+/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to polling path before issuing cfg_msix_map RPC. +* The responder will disable mailbox MSIX routing during resource ops, +* so ACK cannot rely on interrupt wakeup. +*/ +static void nbl_disp_chan_cfg_msix_map_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len)
[Severity: Low]
Is this comment attached to the right function? The precondition talks about what the caller must do, but nbl_disp_chan_cfg_msix_map_resp() runs on the manager PF out of the mailbox RX work item and has no such caller.
The same applies to the identical comment abovenbl_disp_chan_destroy_msix_map_resp().
The functions whose callers need to honour this are nbl_disp_chan_cfg_msix_map_req() / nbl_disp_chan_destroy_msix_map_req(), and the @cfg_msix_map / @destroy_msix_map kernel-doc entries in nbl_def_dispatch.h that external callers read, none of which mention the requirement.
A future caller reading only the ops documentation could issue the RPC with NBL_CHAN_IRQ_RDY still set, so nbl_chan_send_msg() takes the wait_event_timeout() branch while the responder is retargeting mailbox MSI-X routing, and the call fails with a spurious timeout. Today nbl_dev_start() / nbl_dev_stop() do satisfy the precondition, so nothing misbehaves. Could the comment move to the req helpers and the ops kernel-doc instead?
Quoted 1 line
+{
[ ... ]
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 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +9
-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); +if (ret) + err = -EREMOTEIO ;
[Severity: Low]
Is the errno substitution here intentional? All five new responders collapse every resource-layer failure into -EREMOTEIO, while the local control-PF implementations of the same disp_ops entries return the resource errno verbatim:
nbl_disp_cfg_msix_map()
ret = res_ops->cfg_msix_map(p, common->mgt_pf, ...); return ret;
nbl_disp_chan_cfg_msix_map_resp()
ret = res_ops->cfg_msix_map(p, src_id, ...); if (ret) err = -EREMOTEIO;
nbl_res_intr_cfg_msix_map() in nbl_hw/nbl_interrupt.c distinguishes the cases:
dev_err(dev, "No free control interrupt vectors left\n"); ret = -EAGAIN;
and also produces -ESHUTDOWN while intr_mgt->stopping, -EBUSY, -EINVAL and -ENOMEM, all of which are lost on the wire.
-EREMOTEIO is also what nbl_disp_chan_get_vsi_id_req() and nbl_disp_chan_get_eth_id_req() return for a truncated ACK, so a caller cannot tell a protocol error from a remote operation failure.
The commit message says:
Quoted 1 line
Remote responders return standard Linux errnos directly on the wire.
which reads as pass-through. Could the responders forward ret instead?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +3
-0+ }else { + err = -EOPNOTSUPP ; + }
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +3
-0+static int nbl_disp_chan_set_mailbox_irq_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 378
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+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);
[Severity: Low]
This is the only newly added mutating RPC without the polling-path precondition documented for cfg_msix_map / destroy_msix_map, even though the responder rewrites the requester's own mailbox MSI-X routing (NBL_MAILBOX_QINFO_MAP MSIX_IDX / MSIX_IDX_VALID) before the ACK is sent.
Looking at the callers in nbl_core/nbl_dev.c, both directions do use the polling path, so the ACK does arrive:
nbl_dev_enable_mailbox_irq()
ret = disp_ops->set_mailbox_irq(..., lvec, true); if (ret) return ret; chan_ops->set_queue_state(..., NBL_CHAN_IRQ_RDY, ..., true);
nbl_dev_disable_mailbox_irq()
chan_ops->set_queue_state(..., NBL_CHAN_IRQ_RDY, ..., false); return disp_ops->set_mailbox_irq(..., lvec, false);
and nbl_chan_send_msg() selects the wait path solely on test_bit(NBL_CHAN_IRQ_RDY, chan_info->state), which is clear in both cases.
Would it still be worth documenting the same precondition on this req helper, so the requirement is visible to future callers?
[ ... ]
Quoted 22 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +13
-0@@ -34,9 +542,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; } }
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0@@ -104,14 +629,25 @@ 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; +
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 653
Quoted 10 lines
void
nbl_disp_remove(struct nbl_adapter *adapter){drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +6
-1-/* Dispatch structures are allocated via devm */ +/* +* Dispatch structures are allocated via devm. +* Message handlers registered by nbl_disp_setup_msg() are owned by +* channel layer; they are unregistered in nbl_chan_remove_common(), +* not here. +*/ }
[Severity: Low]
Since the five responders registered here are never quiesced by the dispatch layer, is the ordering on teardown guaranteed, i.e. can nbl_chan_remove_msg_handler() free a handler node while the RX dispatch path still holds it, or can a responder run after nbl_intr_mgt_stop() has cleared res_mgt->intr_mgt?
Tracing the remove path, it does look safe. nbl_core_remove() reaches nbl_dev_remove_common_dev() first:
cancel_work_sync(&common_dev->clean_mbx_task); ret = nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
which ends in nbl_chan_teardown_queue(), stopping the hardware mailbox queue and joining the clean task:
if (task) cancel_work_sync(task); WRITE_ONCE(chan_info->active, false);
and only afterwards does nbl_chan_remove_common() drain the workqueue before freeing the nodes:
nbl_common_destroy_wq(&adap->common); ... nbl_chan_remove_msg_handler(chan_mgt);
Would it be worth spelling out that ordering dependency in the comment, since it is what makes the empty nbl_disp_remove() correct?
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0
-0@@ -21,12 +22,28 @@ enum {* caller must check has_ctrl guard * @deinit_module: dispatch layer cleanup, ONLY valid on Control PF,
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 33
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +6
-0* 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: All ops except init_module/deinit_module can be safely called * on PF/VF; init/deinit hooks are control-PF exclusive to prevent NULL ptr. */
[Severity: Low]
This Warning now also covers the five ops being documented here, but does it still hold for them?
On the VF part, every new responder rejects a src_id whose relative PF id is at or above common->max_pf:
if (rel_pf_id >= disp_mgt->common->max_pf) {
err = -EPERM;
goto ack_out;
}With mgt_pf as the base, rel_pf_id equals src_id for the usual case and max_pf is 1, 2 or 4 from nbl_res_init_pf_num() while NBL_MAX_FUNC is 520, so the entire VF function-id range gets -EPERM. The commit message agrees:
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 35
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0
-0- src_id against common->max_pf at runtime; rejects VF and out-of-range function IDs with -EPERM;
On the NULL part, nbl_disp_refresh_ctrl_ops() now starts with memset(disp_ops, 0, sizeof(*disp_ops)) and fills the table only under MGT or NET, so a function with neither capability bit leaves all five pointers NULL, while callers such as nbl_dev_cfg_msix_map() and nbl_dev_enable_mailbox_irq() in nbl_dev.c dereference disp_ops->cfg_msix_map and disp_ops->set_mailbox_irq without a NULL test. That combination is not reachable today, since every entry in nbl_id_table[] sets BIT(NBL_CAP_HAS_NET_BIT) and no VF is probed.
Could the Warning be narrowed to say the five new ops are PF-only and depend on the has_ctrl/has_net capability?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 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 infrastructure. Create nbl_dev.c / nbl_dev.h and nbl_def_dev.h, introducing nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() initialization helpers with their teardown counterparts, and wire them into nbl_dev_init() / nbl_dev_remove() called from nbl_core_init() / nbl_core_remove().
Common device setup (nbl_dev_setup_common_dev):
- Allocate per-device state (nbl_dev_common)
- Set up mailbox channel queue and register cleanup work
- Initialize MSI-X service counts (mailbox = 1 vector; actual allocation deferred to nbl_dev_start() in the next patch; this patch only populates service vector counts)
- VSI/ETH identity fetch is deferred to nbl_dev_start() for both control and non-control PFs. This ensures mailbox channel and control PF responder are fully ready before RPC lookup, and keeps every intermediate commit bisect-bootable on multi-PF systems.
Control device setup (nbl_dev_setup_ctrl_dev, control PF only):
- disp_ops->init_module(): chip-wide hardware initialization callback (datapath pipeline setup, driver_status flag)
- Program mailbox QINFO routing map (bus/devid for each PF)
Chip core hardware initialization is done by firmware at power-on. The driver only programs functional table entries after hardware is ready; common_dev setup before ctrl_dev setup is safe.
Non-control PFs create device links to the control PF during probe. The device link guarantees the kernel unbinds all non-control PFs before the control PF can be removed, preventing broken cross-PF mailbox RPC. A registry check is added as defense-in-depth, to skip global chip deinit if sibling PFs remain bound.
Deinit order: ctrl dev cleanup after common dev teardown. nbl_dev_remove_ctrl_dev() calls deinit_module(), which sets driver_status=false to notify firmware to asynchronously clean all per-PF hardware state including qinfo registers. The qinfo map is not explicitly cleared by the driver; firmware handles it on driver_status change. No completion handshake exists in the current hardware revision.
Teardown ordering guarantee: stop mailbox channel and drain all inflight DMA first, then invoke deinit_module to 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 before deinit_module to avoid invalid DMA write.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 259 ++++++++++++++++++ .../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, 339 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 +259 -0
259 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 v29 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove 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: 2 · Medium: 2 · 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).
- [High] nbl_dev_remove_ctrl_dev() (drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c:177-183) calls disp_ops->deinit_module()…
- [High] There is no synchronization between the chip-global operations this patch adds and sibling (non-control) PFs that are concurrently…
- [Medium] The commit message lists "Program mailbox QINFO routing map (bus/devid for each PF)" under "Control device setup…
- [Medium] nbl_dev_remove_common_dev() (nbl_dev.c:128-142) reduces a failed mailbox queue teardown to dev_warn("mailbox queue teardown…
- [Low] nbl_dev_setup_ctrl_dev() (nbl_dev.c:144-155) contains a pointless round trip: `ret = disp_ops->init_module(...); if (ret) return ret;…
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This patch adds the nbl_dev layer with nbl_dev_setup_common_dev() and nbl_dev_setup_ctrl_dev() plus their teardown counterparts, and wires nbl_dev_init() / nbl_dev_remove() into nbl_core_init() / nbl_core_remove(). Common device setup creates the mailbox channel queue and the mailbox clean work, while control device setup runs the chip-wide init_module() callback.
A few questions below about the control-PF paths and about some commit message and comment text that does not seem to match the code.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,259 @@
[ ... ]
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +20
-0+/* ---------- Channel config ---------- */ +static void nbl_dev_setup_chan_qinfo (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{ +struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv; +struct nbl_common_info *common = dev_mgt->common; + +if (!chan_ops->check_queue_exist (priv, chan_type)) +return ; + +/* +* common->hw_bus is the control PF's real bus number, captured in +* nbl_res_ctrl_dev_sriov_info_init() during nbl_res_init_leonis(). +* nbl_core_init() runs resource init before nbl_dev_init(), so the +* value is always initialized when this control-PF-only path runs; +* nbl_res_intr_cfg_msix_map() consumes it for cfg_msix_map() the +* same way. +*/ + chan_ops->cfg_chan_qinfo_map_table (priv, common->hw_bus, common->devid); +}
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +5
-0+static void nbl_dev_remove_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +int ret;
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 142
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+ +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); +nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX ,NULL ); +}
[Severity: Medium]
Should the teardown failure be propagated instead of only warned about?
nbl_dev_remove_common_dev() returns void, so nbl_dev_remove() continues to nbl_dev_remove_ctrl_dev() -> deinit_module() even after this dev_warn() fires, and devres then releases the mailbox rings once remove() returns.
nbl_chan_teardown_queue() returns -ETIMEDOUT when the inflight TX drain times out, and on that same branch it can also fail the trylock and skip the hardware stop entirely:
nbl_channel.c:nbl_chan_teardown_queue() {
...
} else if (mutex_trylock(&chan_info->txq_lock)) {
nbl_chan_stop_queue(chan_mgt);
mutex_unlock(&chan_info->txq_lock);
} else {
dev_crit(... "zombie channel: ... HW stop skipped ...");
...
}nbl_chan_stop_queue() is what disables both the mailbox RX and TX queues, so on that path the RX queue stays enabled pointing at the dmam_alloc_coherent() rings that devres frees right after remove().
That also seems to conflict with the precondition documented in the hardware layer:
nbl_hw_leonis.c:nbl_hw_deinit_module() {
* Caller must ensure no new DMA is initiated after this point.
* The mailbox channel is stopped by nbl_chan_teardown_queue()
* before this function is called, so no in-flight mailbox DMA
* remains.
}
Can the device write into the freed coherent mailbox buffers in that case?
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 155
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +13
-0+ +static int nbl_dev_setup_ctrl_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +int ret; + + ret = disp_ops->init_module (dev_mgt->disp_ops_tbl->priv); +if (ret) +return ret; + +return 0 ; +}
[Severity: Medium]
The commit message lists, under "Control device setup (nbl_dev_setup_ctrl_dev, control PF only)":
- Program mailbox QINFO routing map (bus/devid for each PF)
and the teardown comment below says "The qinfo map programmed in setup_ctrl_dev". Does nbl_dev_setup_ctrl_dev() program the QINFO map?
The body above only calls disp_ops->init_module(); the QINFO map is programmed from nbl_dev_init() via nbl_dev_setup_chan_qinfo(), which runs before nbl_dev_setup_common_dev() creates the mailbox queue and before init_module():
if (common->has_ctrl) nbl_dev_setup_chan_qinfo(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
That call performs chip-wide register writes for every active PF:
nbl_channel.c:nbl_chan_cfg_qinfo_map_table() {
for (func_id = 0; func_id < NBL_MAX_PF; func_id++)
if (!(pf_mask & (1 << func_id)))
hw_ops->cfg_mailbox_qinfo(p, func_id, bus, devid, func_id);
}So the documented "Init order: create mailbox(common_dev) → ctrl dev init" does not seem to describe the order in which hardware writes actually happen, and this QINFO programming is also outside the setup_ctrl_dev_fail unwind path. Could the changelog and the comment be adjusted to match, or the call moved into nbl_dev_setup_ctrl_dev()?
[Severity: Low]
This isn't a bug, but there is nothing between the call and the return, so the local ret and the error check are redundant here:
return disp_ops->init_module(dev_mgt->disp_ops_tbl->priv);
Quoted 18 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +18
-0+ +/* +* Tear down control device: deinit_module sets driver_status=false +* to notify firmware to clean all per-PF hardware state (including +* qinfo registers). The qinfo map programmed in setup_ctrl_dev is +* not explicitly cleared; firmware handles it on driver_status change. +* +* Teardown ordering guarantee: every non-management PF creates a +* consumer->control PF 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). +* +* Safety net: this registry check additionally blocks the chip-global +* deinit if a sibling PF is somehow still bound on the same chip +* (defense in depth for paths that bypass device-link ordering). +* Skipping deinit leaves firmware/qinfo routing alive for the siblings; +* their control plane stays functional at the cost of deferring the +* global firmware cleanup until the next control PF init_module().
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 183
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-0+* Direct control-PF FLR (which never runs driver teardown) cannot be +* guarded here. +*/ +static void nbl_dev_remove_ctrl_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; + + disp_ops->deinit_module (dev_mgt->disp_ops_tbl->priv); +}
[Severity: High]
Where is the registry check that this comment and the commit message describe?
The commit message says:
A registry check is added as defense-in-depth, to skip global chip deinit if sibling PFs remain bound.
and the comment above says "this registry check additionally blocks the chip-global deinit if a sibling PF is somehow still bound on the same chip".
The function body is a single unconditional deinit_module() call, and the only condition below it is has_ctrl:
nbl_chip.c:nbl_res_chip_deinit_module() {
if (!common->has_ctrl)
return;
hw_ops->deinit_module(res_mgt->hw_ops_tbl->priv);
}The only chip-dependency code in the driver is nbl_probe_chip_deps() in nbl_main.c, and it just creates a device link:
if (!device_link_add(&pdev->dev, &mgt->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {There is no registry, sibling list or sibling-bound check anywhere for the teardown path to consult. Should the check be implemented, or should the changelog and the comment be corrected so reviewers do not assume a guard that is not there?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+ +static struct nbl_dev_mgt *nbl_dev_setup_dev_mgt (struct nbl_common_info *common)
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+int nbl_dev_init (struct nbl_adapter *adapter) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 217
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +5
-0+ dev_mgt->disp_ops_tbl = disp_ops_tbl; + dev_mgt->chan_ops_tbl = chan_ops_tbl; + adapter->core.dev_mgt = dev_mgt; +if (common->has_ctrl) +nbl_dev_setup_chan_qinfo (dev_mgt,NBL_CHAN_TYPE_MAILBOX );
[Severity: High]
What serializes these chip-global operations against sibling PFs that are already bound or still probing?
This call rewrites the shared mailbox QINFO entry of every hardware-active PF, clearing MSIX_IDX / MSIX_IDX_VALID in nbl_hw_cfg_mailbox_qinfo(), with no check for siblings that are already live. On the other side, nbl_dev_remove_ctrl_dev() -> deinit_module() sets driver_status=false, which per the comments makes firmware asynchronously wipe per-PF state including sibling QINFO registers.
The commit message states:
The device link guarantees the kernel unbinds all non-control PFs before the control PF can be removed, preventing broken cross-PF mailbox RPC.
Does the managed link created inside the consumer's own probe give that guarantee? In drivers/base/core.c, device_link_init_status() assigns DL_STATE_DORMANT when the supplier has no driver, device_links_driver_bound() later promotes DORMANT only to DL_STATE_AVAILABLE, and device_links_unbind_consumers() force-unbinds only ACTIVE links:
drivers/base/core.c:device_links_unbind_consumers() {
WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND);
if (status == DL_STATE_ACTIVE) { /* only then force-unbind consumer */
}So a sequence like "unbind func0; bind func1; bind func0; unbind func0" leaves func1 bound and live while the control PF runs deinit_module().
In the opposite direction, device_link_add() returns a valid link with status DL_STATE_SUPPLIER_UNBIND when the supplier is already unbinding, and nbl_probe_chip_deps() only checks for NULL, so a sibling can keep probing into nbl_dev_init() and enable its mailbox while func0 is inside nbl_dev_remove(). PCI does not set need_parent_lock, so no common device lock serializes the two. Can this leave a sibling PF with its mailbox routing torn down underneath it?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v29 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:
1. Configure hardware MSI-X mapping table (cfg_msix_map)
2. Fetch VSI and ETH identity information via dispatch RPC For non-control PF, if mailbox RPC times out because control PF is not ready yet, return -EPROBE_DEFER to trigger deferred probing, so kernel will retry later once PF0 comes up.
3. Allocate MSI-X IRQ vectors via pci_alloc_irq_vectors()
4. Request mailbox interrupt and attach handler
(nbl_dev_clean_mailbox -> schedule cleanup work)
5. Enable hardware mailbox interrupt and mark channel interrupt ready (NBL_CHAN_IRQ_RDY)
The VSI/ETH identity fetch for all PFs happens inside nbl_dev_start(), after the MSI-X mapping is configured. Non-control PFs rely on the control PF's mailbox responder being fully operational when this RPC runs. If control PF is not ready, return -EPROBE_DEFER for retry.
nbl_dev_stop() tears down resources in reverse order, with device-side mapping destroyed before kernel-side vectors are released:
1. Switch channel to polling mode (clear NBL_CHAN_IRQ_RDY) before masking hardware mailbox interrupt. This ordering avoids discarding in-flight ACKs that would trigger "Channel waiting ack failed" errors.
2. Release mailbox IRQ via free_irq()
3. Destroy hardware MSI-X mapping table (masks all device vectors and clears the completer map entry)
4. Kernel MSI-X vectors are managed by devres/pcim, so explicit pci_free_irq_vectors() is skipped to prevent double-free.
5. Drain mailbox cleanup work via cancel_work_sync()
The start error-unwind path uses reverse ordering:
disable mailbox IRQ and free IRQ handler, destroy MSI-X map, then drain work via cancel_work_sync, so a failure at any stage leaves the device and kernel in a consistent state. Rollback failures are logged.
This teardown is best-effort: destroy_msix_map uses mailbox RPC and may fail. Stale hardware MSI-X entries are reclaimed by firmware on chip reset. pci_clear_master() in nbl_remove() provides the final safety net if a teardown RPC to the manager PF cannot complete.
Add thin wrappers nbl_core_start() / nbl_core_stop() and hook them into PCI probe and remove paths to control the device lifecycle. This patch completes the dev lifecycle series.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 342 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 18 + 4 files changed, 364 insertions(+)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -39,5 +39,7 @@ struct nbl_adapter {struct nbl_adapter *nbl_core_init (struct pci_dev *pdev,struct nbl_init_param *param);void nbl_core_remove (struct nbl_adapter *adapter); +int nbl_core_start (struct nbl_adapter *adapter); +void nbl_core_stop (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +342 -0
363 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) {
@@ -181,7 +191,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);
@@ -196,6 +212,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 v29 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · 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).
- [High] nbl_dev_start() only translates -ETIMEDOUT into -EPROBE_DEFER for the get_vsi_id()/get_eth_id() RPCs, but the *first* mailbox RPC a…
- [Medium] nbl_dev_clear_interrupt_scheme() (nbl_dev.c:221-231) has an empty body, yet the two call sites assert that kernel-side MSI-X…
- [Low] Concern (validated as a false positive for the current code, retained for policy): nbl_dev_init_interrupt_scheme() (nbl_dev.c:206)…
--
net/nebula-matrix: add common dev start/stop operation
This adds nbl_dev_start() and nbl_dev_stop() to configure the hardware MSI-X map, fetch VSI/ETH identity, allocate MSI-X vectors and set up the mailbox interrupt, plus nbl_core_start()/nbl_core_stop() wrappers hooked into the PCI probe and remove paths.
A few questions about the start/stop paths below.
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,206 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+static int nbl_dev_init_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info;
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 207
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_common_info *common = dev_mgt->common; +int needed =0 ; +int err; +int i; + +for (i =0 ; i <NBL_MSIX_TYPE_MAX ; i++) + needed += msix_info->serv_info[i].num; + + err =pci_alloc_irq_vectors (common->pdev, needed, needed, +PCI_IRQ_MSIX |PCI_IRQ_AFFINITY );
[Severity: Low]
This isn't a bug in this patch, but PCI_IRQ_AFFINITY makes the mailbox vector an affinity-managed vector.
Today that is harmless: nbl_dev_init_msix_cnt() only sets serv_info[NBL_MSIX_MAILBOX_TYPE].num = 1, and with one group __group_cpus_evenly() takes the
if (numgrps <= nodes) {branch, which ORs every node's CPUs into masks[0], so the vector's mask covers all CPUs and can never lose its last online CPU.
Once net vectors are added and the spreading no longer degenerates, a managed mailbox vector can be shut down by CPU offline while NBL_CHAN_IRQ_RDY is still set, which would turn every mailbox RPC into a timeout. Would it be worth excluding the administrative vector up front via irq_affinity.pre_vectors?
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +13
-0+if (err <0 ) { +dev_err (common->dev, +"pci_alloc_irq_vectors failed, err = %d\n" , err); +return err; + } +if (err != needed) { +dev_err (common->dev,"pci_alloc_irq_vectors got %d vecs, need %d\n" , + err, needed); +return -ENOSPC ; + } +return 0 ; +} +
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 230
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+static void nbl_dev_clear_interrupt_scheme (struct nbl_dev_mgt *dev_mgt) +{ +/* +* pcim_enable_device() is used in nbl_probe(). +* pci_alloc_irq_vectors() registers pcim_msi_release devres callback, +* which invokes pci_free_irq_vectors() automatically on device detach. +* Do NOT call pci_free_irq_vectors() explicitly here to avoid +* double-free. +*/ +}
[Severity: Medium]nbl_dev_clear_interrupt_scheme() has an empty body, yet both call sites state that the kernel-side vectors are released at that point. In the err_destroy_map block of nbl_dev_start():
* Destroy device-side MSI-X map BEFORE releasing kernel-side
* vectors. This masks all hardware vectors and clears the
* pcompleter map entry, so no MSI-X message can fire after
* vector release.
...
* This is best-effort teardown: we still release kernel vectors
* even if remote RPC fails.
and in nbl_dev_stop():
* This is best-effort teardown: if destroy_msix_map RPC fails,
* hardware MSI-X map remains valid. We proceed to release
* kernel vectors anyway.
Nothing is released here, so pdev->msix_enabled is still set when nbl_dev_stop() returns, and the ordering invariant is only established later by pcim_msi_release() at device detach. Could these comments be reworded to say that the vectors deliberately stay allocated until detach?
Related to that, nbl_core_start()/nbl_core_stop() are exported in nbl_core.h as a pair, but the pair is not repeatable: a second nbl_dev_start() calls pci_alloc_irq_vectors() again on a device that still has MSI-X enabled, and __pci_enable_msix_range() starts with
if (WARN_ON_ONCE(dev->msix_enabled)) return -EINVAL;
Is only probe/remove ever expected to call these?
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +5
-0@@ -257,3 +476,126 @@ void nbl_dev_remove(struct nbl_adapter *adapter)if (common->has_ctrl)nbl_dev_remove_ctrl_dev (adapter); } + +/* ---------- Dev start process ---------- */ +int nbl_dev_start (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 void nbl_dev_remove(struct nbl_adapter *adapter) · line 493
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops; +struct nbl_dispatch_mgt *priv = dev_mgt->disp_ops_tbl->priv; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +struct nbl_common_info *common = dev_mgt->common; +int cleanup_ret; +int ret; + + ret =nbl_dev_cfg_msix_map (dev_mgt); +if (ret) + goto err_destroy_map;
[Severity: High]
The commit message says:
For non-control PF, if mailbox RPC times out because control PF is not ready yet, return -EPROBE_DEFER to trigger deferred probing, so kernel will retry later once PF0 comes up.
Does that cover the first RPC? On a non-control PF, nbl_dev_cfg_msix_map() is already a cross-PF mailbox call: disp_ops->cfg_msix_map is nbl_disp_chan_cfg_msix_map_req(), which sends an ack-requested message to common->mgt_pf:
ret = chan_ops->send_msg(disp_mgt->chan_ops_tbl->priv, &chan_send); if (ret) return ret;
NBL_CHAN_IRQ_RDY has not been set yet at this point, so nbl_chan_send_msg() takes the polling path and, if nobody answers, returns after NBL_CHAN_TX_WAIT_ACK_TIMES(5000) x ~1ms:
dev_err_ratelimited(dev, "Channel polling ack failed, message type: %d msg id: %u\n", chan_send->msg_type, msgid); ret = -ETIMEDOUT;
That -ETIMEDOUT reaches err_destroy_map unchanged, so nbl_probe() returns -ETIMEDOUT and the driver core treats it as a hard probe failure with no retry once PF0 binds. The -EPROBE_DEFER conversion below is unreachable in exactly the case the commit message describes. Should the conversion be applied to nbl_dev_cfg_msix_map() as well, and to set_mailbox_irq() in nbl_dev_enable_mailbox_irq(), which returns an untranslated timeout too?
Is nbl_probe_chip_deps() sufficient to order this? device_link_add() is called from the consumer's own probe, and an unbound func 0 gives a DORMANT link, so this probe attempt still continues into nbl_dev_start().
One more effect of the same path: err_destroy_map issues another ack-requested RPC (destroy_msix_map) to the same unresponsive control PF, so the failing probe spends a second ~5 s polling timeout and logs "rollback: destroy MSI-X map failed".
Quoted 29 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +29
-0+ +/* Fetch VSI/ETH identity after cfg_msix_map */ + ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); +if (ret) { +if (!common->has_ctrl && ret == -ETIMEDOUT ) + ret = -EPROBE_DEFER ; + goto err_destroy_map; + } + ret = disp_ops->get_eth_id (priv, common->vsi_id, &common->eth_num, + &common->eth_id, &common->logic_eth_id); +if (ret) { +if (!common->has_ctrl && ret == -ETIMEDOUT ) + ret = -EPROBE_DEFER ; + goto err_destroy_map; + } + + ret =nbl_dev_init_interrupt_scheme (dev_mgt); +if (ret) + goto err_destroy_map; + + ret =nbl_dev_request_mailbox_irq (dev_mgt); +if (ret) + goto err_destroy_map; + + ret =nbl_dev_enable_mailbox_irq (dev_mgt); +if (ret) + goto err_disable_irq; + +return 0 ;
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0@@ -181,7 +191,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);
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922120311.86593-2-illusion.wang%40nebula-matrix.com