nbl driver for Nebulamatrix NICs
illusion.wang
maintainerv35 cover nbl driver for Nebulamatrix NICs
This series continues and refines the previous v28 NBL NIC driver patch set for Nebula-matrix m18110/m18000 (SNIC s1000) Ethernet adapters.
The first two foundational patches of v28 have been merged into net-next main branch:
- net/nebula-matrix: add minimum nbl build framework (cffde9e49e86)
- net/nebula-matrix: add core driver architecture and HW layer initialization (825e6d230163)
Following maintainer feedback to shorten the patch series, this iteration drops the two merged commits, reorganizes and polishes the remaining functionality into a standalone 8-patch sequence. No new features are added; this series only completes the pending core infrastructure.
The overall driver development plan remains consistent with the v28 two-phase roadmap:
1) Complete hardware initialization, mailbox/channel communication and control-plane infrastructure (this series)
2) Implement netdev registration and TX/RX data-path functionality (follow-up series)
This patch set supplements the merged foundational code, covering channel layer abstraction, resource management, interrupt handling, chip-level initialization, control dispatch routing, channel RPC framework, and device lifecycle init/remove/start/stop logic.
changes v34->v35
Link to v34:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.Issue found by Leitao
changes v33->v34
Link to v33:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v32->v33
Link to v32:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v31->v32
Link to v31:https://lore.kernel.org/netdev/[email protected]/ AI review issues
changes v30->v31
Link to v30:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v29->v30
Link to v29:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v28->v29
Link to v28:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.remove the hash table implementation
illusion wang (8):
net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add chip-wide hardware init/deinit implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox
irq and vsi/eth id
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 | 1568 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 196 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 51 + .../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 22 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 757 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 623 +++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 1314 +++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 342 ++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 346 ++++ .../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 | 859 +++++++++ .../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 | 158 ++ .../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 | 92 + .../nbl/nbl_include/nbl_def_hw.h | 81 + .../nbl/nbl_include/nbl_def_resource.h | 16 + .../nbl/nbl_include/nbl_include.h | 28 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 306 +++- 29 files changed, 7318 insertions(+), 24 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
Signature · 1 line
2.51.0.windows.1
illusion.wang
maintainerPATCH v35 1/8 net/nebula-matrix: add channel layer
From: illusion wang <[email protected]>
Add a mailbox-based channel layer that carries control messages between PF0 and the other PFs, providing the inter-PF control transport the rest of the driver builds on.
The channel ops table is defined here; queue setup, RX interrupt/polling processing and the upper-layer callers are wired up in later patches of this series.
Implementation notes:
- Message handlers live in an xarray, giving lockless lookup and duplicate-registration rejection (xa_insert returns -EBUSY). Both fire-and-forget and synchronous ACK-based sends are supported.
- ACK wait-slot exhaustion returns -EAGAIN; a full TX descriptor ring returns -EBUSY. Payloads are inline (up to 16 B) or DMA-based (up to 4032 B).
- The per-slot data buffers of each ring are carved out of one contiguous coherent DMA block, so those buffers cost one devres node and one IOMMU mapping per ring instead of one per slot. That is the only part of the ring which is collapsed: the descriptor ring is a second coherent allocation of its own, and the buf[]/wait[] bookkeeping arrays are devm_kcalloc() nodes.
- Mailbox queue resources are devm-managed and the DMA is allocated once during setup. There is no free path, so a channel is set up exactly once per device lifetime and teardown is terminal for it; a re-setup is rejected with -EBUSY.
- RX is driven either from the interrupt or by polling, with cleanup offloaded to a workqueue. Teardown quiesces both queues before the rings can be freed.
- Register access goes through hw_ops. The reg_lock spinlock covers BAR0 register access only; BAR2 mailbox registers and the doorbell write do not take it.
This patch also adds nbl_probe_chip_deps() and calls it from nbl_probe() before nbl_core_init(). For every PF that is not the physical function 0 (has_ctrl == 0) it resolves function 0 in the same slot and:
- fails the probe with -ENODEV if function 0 is absent, and also when the lookup resolves to this device itself: a VF is never the management PF, yet under ARI its devfn decodes to function 0 of a slot;
- returns -EPROBE_DEFER unless function 0 is bound to *this* driver and has finished probing (dev.links.status == DL_DEV_DRIVER_BOUND). The driver pointer is compared because links.status alone also accepts function 0 on vfio-pci or pci-stub through driver_override, where the chip-global setup this PF depends on never ran. links.status is used rather than device_is_bound() because driver_bound() adds knode_driver before it sets DL_DEV_DRIVER_BOUND, so device_is_bound() is already true while function 0 is still probing;
- creates a persistent DL_FLAG_AUTOPROBE_CONSUMER device link, so the driver core unbinds every sibling PF before function 0 goes away and re-probes them when function 0 binds again. It is deliberately not flagged AUTOREMOVE_SUPPLIER: the link is what re-queues the siblings after a rebind, so it has to survive function 0's unbind. Because the link outlives the nbl binding that created it, two effects outside nbl follow, both intended: while function 0 is not bound to this driver the link is DORMANT, so any other driver on a sibling PF (vfio-pci, pci-stub) is deferred by device_links_check_suppliers(); and unbinding function 0 from its driver force-unbinds the sibling through device_links_unbind_consumers(). A PF of this controller is only usable with this driver bound to the management PF.
Function 0's device lock is never taken: this probe already runs under device_lock(funcN) while __pci_bus_lock() (AER recovery, slot reset) walks the bus in devfn order, 0 -> N, and dev->mutex is lockdep_set_novalidate_class(), so lockdep could not report the resulting N -> 0 inversion. Neither state read needs the lock: a missed transition only costs a deferral, and that deferral is self-healing. driver_bound() sets dev->links.status to DL_DEV_DRIVER_BOUND, and driver_probe_device() re-arms deferred probing when that happened while a probe was in flight, so the retried probe sees the supplier bound.
function 0 can still start unbinding between that check and device_link_add(). Neither predicate above notices it: function 0's remove callback runs with dev->driver and knode_driver still set, and only the link reflects the transition, as DL_STATE_SUPPLIER_UNBIND. The probe therefore re-reads the state after creating the link and defers unless the link is DL_STATE_CONSUMER_PROBE and the supplier is still DL_DEV_DRIVER_BOUND. That link state is load-bearing rather than
incidental: device_links_busy() only makes function 0's unbind wait for consumers whose link is CONSUMER_PROBE or ACTIVE, so any other state has to be treated as "not ordered" instead of accepted. The link is kept on that path rather than deleted - it is managed and the consumer is registered, so device_link_del() would only trip device_link_put_kref()'s WARN and leave it behind - and the driver core re-queues this probe through device_links_no_driver() and DL_FLAG_AUTOPROBE_CONSUMER. All of these reads are lock-free for the reason above, so a stale read can miss a just-started unbind; that leaves a single memory access of exposure instead of the whole of nbl_remove(), and the WARN_ON in device_links_driver_bound() is the remaining safety net.
Nothing here consumes the ordering yet - setup_queue() and cfg_chan_qinfo_map_table() still have no callers - but the later init/remove and start/stop patches do. Note the cost: with function 0 bound to another driver (e.g. vfio-pci) a sibling PF stays deferred for as long as that holds, with only a dev_dbg() record, and a function 0 that is simply absent fails the probe outright.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 4 +- .../nbl/nbl_channel/nbl_channel.c | 1568 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 196 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 29 + .../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 7 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 299 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 41 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 32 + .../nbl/nbl_include/nbl_def_channel.h | 125 ++ .../nbl/nbl_include/nbl_def_common.h | 3 + .../nbl/nbl_include/nbl_def_hw.h | 43 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 178 +- 14 files changed, 2524 insertions(+), 18 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +3 -1
@@ -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 +1568 -0
1,568 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +196 -0
196 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +29 -0
@@ -0,0 +1,29 @@ +// 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) +{ + common->wq =alloc_workqueue ("nbl_wq_%s" ,WQ_UNBOUND ,0 , +pci_name (common->pdev)); +if (!common->wq) { +dev_err (common->dev,"Failed to alloc workqueue for %s\n" , +pci_name (common->pdev)); +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 +287 -12
379 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +41 -0
46 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +32 -0
@@ -8,6 +8,7 @@#include <linux/types.h> +#include "../nbl_include/nbl_def_channel.h" #include "../nbl_include/nbl_def_hw.h" #include "../nbl_include/nbl_def_common.h" #include "../nbl_core.h"
@@ -26,6 +27,37 @@ struct nbl_hw_mgt {u8 __iomem *hw_addr;u8 __iomem *mailbox_bar_hw_addr;resource_size_t mailbox_bar_size; +spinlock_t reg_lock;/* Protect reg access */ }; +static inline u32 rd32 (u8 __iomem *addr,u64 reg) +{ +return readl (addr + reg); +} + +static inline void wr32 (u8 __iomem *addr,u64 reg,u32 value) +{ +writel (value, addr + reg); +} + +static inline void nbl_hw_wr32 (struct nbl_hw_mgt *hw_mgt,u64 reg,u32 value) +{ +wr32 (hw_mgt->hw_addr, reg, value); +} + +static inline u32 nbl_hw_rd32 (struct nbl_hw_mgt *hw_mgt,u64 reg) +{ +return rd32 (hw_mgt->hw_addr, reg); +} + +static inline void nbl_mbx_wr32 (struct nbl_hw_mgt *hw_mgt,u64 reg,u32 value) +{ +writel (value, hw_mgt->mailbox_bar_hw_addr + reg); +} + +static inline u32 nbl_mbx_rd32 (struct nbl_hw_mgt *hw_mgt,u64 reg) +{ +return readl (hw_mgt->mailbox_bar_hw_addr + reg); +} +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h new file +125 -0
125 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +3 -0
@@ -12,6 +12,7 @@#include "nbl_include.h" struct nbl_common_info { +struct workqueue_struct *wq;struct pci_dev *pdev;struct device *dev;u16 vsi_id;
@@ -28,4 +29,6 @@ struct nbl_common_info { u8 has_net; }; +void nbl_common_destroy_wq (struct nbl_common_info *common); +int nbl_common_create_wq (struct nbl_common_info *common);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +43 -0
49 lines not on this page · raw message
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 +173 -5
224 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 1/8] net/nebula-matrix: add channel layer
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] nbl_probe_chip_deps() dereferences the struct device_link returned by device_link_add() (READ_ONCE(link->status)) with no link…
- [Medium] The TX timeout recovery in nbl_chan_quiesce_and_reclaim_tx() asserts QUEUE_RST, forces next_to_use/next_to_clean/tail_ptr to 0, and…
- [Low] The commit message (and the matching code comments) describe the effect of the persistent DL_FLAG_AUTOPROBE_CONSUMER link on other…
- [Low] nbl_probe_chip_deps() finds the management PF as (domain, bus, PCI_SLOT(devfn), function 0) of the probing device, and its only VF…
- [Low] The large comment in nbl_probe_chip_deps() justifies the lock- free design by referring to "the trylock-and-retry scheme necessary…
--
net/nebula-matrix: add channel layer
This adds a mailbox-based channel layer that carries control messages between PF0 and the other PFs. It uses TX/RX descriptor rings, ACK wait slots and an xarray of message handlers. It also adds nbl_probe_chip_deps(), which defers sibling PF probes until function 0 is bound to nbl, and creates a persistent device link from each sibling to function 0.
Quoted 4 lines
- creates a persistent
DL_FLAG_AUTOPROBE_CONSUMERdevice link, so the driver core unbinds every sibling PF before function 0 goes away and re-probes them when function 0 binds again. It is deliberately not flaggedAUTOREMOVE_SUPPLIER: the link is what re-queues the siblings
Quoted 8 lines
after a rebind, so it has to survive function 0's unbind. Because the link outlives the nbl binding that created it, two effects outside nbl follow, both intended: while function 0 is not bound to this driver the link is DORMANT, so any other driver on a sibling PF (vfio-pci, pci-stub) is deferred by
device_links_check_suppliers(); and unbinding function 0 from its driver force-unbinds the sibling throughdevice_links_unbind_consumers(). A PF of this controller is only usable with this driver bound to the management PF.
[Severity: Low]
Is this description of the link's effect on other drivers accurate?
When the supplier binds to any driver, device_links_driver_bound() moves DORMANT consumer links to AVAILABLE:
drivers/base/core.c:device_links_driver_bound() {
...
WARN_ON(link->status != DL_STATE_DORMANT);
WRITE_ONCE(link->status, DL_STATE_AVAILABLE);
...
}device_links_check_suppliers() only defers a consumer when the link is not AVAILABLE:
if (link->status != DL_STATE_AVAILABLE &&
!device_link_test(link, DL_FLAG_SYNC_STATE_ONLY)) {So with function 0 bound to vfio-pci, it looks like a sibling PF can bind vfio-pci or pci-stub normally. The link seems to be DORMANT only while function 0 has no driver at all. The "bound to this driver" restriction comes only from the mgt->dev.driver != pdev->dev.driver check in nbl_probe_chip_deps(), and that check only applies when nbl is the sibling's driver.
Could the commit message be updated to describe what the driver core actually enforces?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1568 @@
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static void nbl_chan_quiesce_and_reclaim_tx (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +11
-0+* The QINFO entry exposes no idle or reset-done status, so that +* proves the reset was accepted, not that DMA from the old run is +* gone: a late USED write-back for the descriptor that timed out +* can still land after the re-arm below. The ring cannot step +* around it either, because QUEUE_RST clears the hardware tail +* counter and the software indices have to restart with it at +* slot 0. The timed-out message has already failed, so the only +* remaining exposure is such a completion arriving while the next +* message is polled. +*/ + hw_ops->stop_mailbox_txq (hw_priv);
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+ txq->tail_ptr =0 ; + txq->next_to_use =0 ; + txq->next_to_clean =0 ;
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 675
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +6
-0+if (READ_ONCE (chan_info->shutdn)) +return ; + +/* Re-enable queue with current ring base and size */ +nbl_chan_config_queue (chan_mgt, chan_info, true); +}
[Severity: Medium]
What happens to the next message if the timed-out descriptor was in slot 0? That is the case for the first send after setup or after a previous reset. The indices restart at 0, so the next send reuses the abandoned slot.
nbl_chan_kick_tx_ring() decides completion only from the USED bit, with no msgid or generation check:
if (le16_to_cpu(READ_ONCE(tx_desc->flags)) &
BIT(NBL_CHAN_TX_DESC_USED)) {Could a late USED write-back from the old run, which the comment above says can land after the re-arm, make the new message look sent even though the device never fetched it? For non-ACK sends such as the nbl_chan_send_ack() replies, the message would be silently lost. ACK sends would end in a spurious ACK timeout.
For payloads over 16 bytes, nbl_chan_update_txqueue() also does a memcpy() into tx_buf[0]. Can that race a late device read of the same buffer for the abandoned descriptor, so the peer receives a mix of the two messages?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0@@ -67,6 +74,155 @@ static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data,
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +11
-0+static int nbl_probe_chip_deps (struct pci_dev *pdev,bool has_ctrl) +{ +struct device_link *link; +struct pci_dev *mgt; + +if (has_ctrl) +return 0 ; + + mgt =pci_get_domain_bus_and_slot (pci_domain_nr (pdev->bus), + pdev->bus->number, +PCI_DEVFN (PCI_SLOT (pdev->devfn),0 ));
[ ... ]
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 138
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +6
-0+if (mgt == pdev) { +dev_err (&pdev->dev, +"management PF lookup matched this device\n" ); +pci_dev_put (mgt); +return -ENODEV ; + }
[Severity: Low]
Does this guard cover only one of the VFs in a group?
nbl_get_func_param() only sets has_ctrl in this case:
if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn)
param->caps.has_ctrl = 1;so every VF that reaches nbl_probe() takes this lookup. For a VF, (domain, bus, slot, function 0) does not identify the owning PF.
Under ARI, the VF at function 0x11 resolves to the VF at 0x10. That VF matches itself here and always fails with -ENODEV, so it can never be bound to nbl. Wouldn't every other VF in the same 8-function group then fail the mgt->dev.driver != pdev->dev.driver check and return -EPROBE_DEFER forever, with only a dev_dbg() record?
At this commit a VF bound through driver_override can reach this path. A later patch in the series ("net/nebula-matrix: add common/ctrl dev init/remove operation") adds an -EOPNOTSUPP rejection for functions with neither capability, which closes the driver_override path. The lookup is still wrong for any VF whose device ID matches nbl_id_table.
Would rejecting pdev->is_virtfn up front, or using pci_physfn(), make the VF handling consistent?
[ ... ]
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 158
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +4
-0+* the supplier bound. Since nothing is held across the deferral, no +* retry can fail again on account of func 0's probe still being in +* flight, which is what made the trylock-and-retry scheme necessary +* before.
[Severity: Low]
This isn't a bug, but which trylock-and-retry scheme does this refer to? There doesn't seem to be one in the tree or in this series. Is this left over from an earlier revision of the patch?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+ link =device_link_add (&pdev->dev, &mgt->dev, +DL_FLAG_AUTOPROBE_CONSUMER ); +if (!link) {
[ ... ]
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 214
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +3
-0+if (READ_ONCE (link->status) !=DL_STATE_CONSUMER_PROBE || +READ_ONCE (mgt->dev.links.status) !=DL_DEV_DRIVER_BOUND || +READ_ONCE (mgt->dev.driver) != pdev->dev.driver) {
[Severity: Medium]
Is it safe to dereference link here?
The link is managed (there is no DL_FLAG_STATELESS), so the driver core owns it. The device_link_add() kerneldoc says the return value can only be used to check whether the link is present. An existing managed link gets no extra reference, and this read is not inside a device_links_read_lock() section.
Take the case the comment above describes, where function 0 starts unbinding between the readiness check and device_link_add():
func 0 sysfs remove sibling probedevice_links_busy()
links.status = DL_DEV_UNBINDING
device_link_add()
device_link_init_status()
status = DL_STATE_SUPPLIER_UNBINDdevice_links_unbind_consumers()
(only waits on CONSUMER_PROBE)
->remove()device_del()
device_links_purge()
__device_link_del()
...
device_link_release_fn()
device_link_synchronize_removal()
kfree(link)
READ_ONCE(link->status)The held pci_dev reference keeps mgt->dev alive but not the link. If the probe thread is preempted between device_link_add() and this READ_ONCE(), can it read freed memory?
Could the check rely only on state that the held reference protects, such as mgt->dev.links.status and mgt->dev.driver, or run under device_links_read_lock()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 2/8 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add chip-agnostic resource layer to manage PF topology, per-PF BDF, Ethernet port and VSI identity mappings, providing reusable conversion helpers for the Nebula Matrix driver control plane.
This patch implements core resource initialization and lookup logic, running exclusively on the control PF and building read-only resource tables once during probe:
- nbl_res_init_pf_num(): parse firmware PF mask and validate supported topologies. Only contiguous 1/2/4 PFs starting from PF0 are permitted, rejecting invalid/sparse configurations with early probe failure.
- nbl_common_func_id_to_rel_pf_id(): convert absolute PF function ID to relative PF index for consistent resource table indexing.
- nbl_res_ctrl_dev_pf_info_init(): calculate and store per-PF BDF entries based on hardware PCI bus number for MSI-X programming.
- nbl_res_ctrl_dev_setup_eth_info(): verify firmware port count and Ethernet bitmap consistency, then construct per-PF eth_id lookup table. logic_eth_id is computed on-the-fly from relative PF ID instead of table lookup.
- nbl_res_ctrl_dev_vsi_info_init(): assign staggered per-PF VSI base IDs with gaps of 1024, 512 and 256 for 1, 2 and 4 port modes.
- Implement VSI/PF/Eth ID conversion helpers with strict control PF validity and range guards.
The lookup helpers are plain functions taking the resource manager, so callers reach them directly. Hardware access is the only remaining ops table (nbl_hw_ops_tbl): it has a single implementation today - leonis - and is kept because draco is planned as the second chip family, with its own datapath register map and its own set of hardware helpers, while the resource logic in this commit (PF mask validation, BDF/Eth/VSI table construction, ID conversion) is what the two families share.
All resource tables are initialized once at control PF probe time and remain read-only afterwards, so lookup helpers require no internal locking. Upper-layer serialization via mutex and non-control PF mailbox RPC routing will be introduced in later series patches.
All resource memory allocations use devm managed semantics, requiring no explicit cleanup in the remove path.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 2 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 22 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 79 ++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 15 + .../nbl_hw_leonis/nbl_resource_leonis.c | 314 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 10 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 125 +++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 68 ++++ .../nbl/nbl_include/nbl_def_channel.h | 10 + .../nbl/nbl_include/nbl_def_common.h | 20 ++ .../nbl/nbl_include/nbl_def_hw.h | 26 ++ .../nbl/nbl_include/nbl_def_resource.h | 16 + .../nbl/nbl_include/nbl_include.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 16 files changed, 719 insertions(+), 5 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
@@ -27,3 +27,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 +1 -0
@@ -21,6 +21,7 @@ struct nbl_interface {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 +74 -5
112 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +15 -0
@@ -51,6 +51,21 @@ struct nbl_mailbox_qinfo_cfg_table {/* -------- HOST_PCIE -------- */ #define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004) +#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040) + +#define NBL_PCIE_BUS_MASK GENMASK(12, 5) +#define NBL_FW_BOARD_CONFIG 0x200 +#define NBL_FW_BOARD_DW3_OFFSET (NBL_FW_BOARD_CONFIG + 12) +#define NBL_FW_BOARD_DW6_OFFSET (NBL_FW_BOARD_CONFIG + 24) + +#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0) +#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1) +#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8) +#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10) +#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13) + +#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0) +#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8)#define NBL_BAR2_MAX_LEN 0x300#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +314 -0
314 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_RESOURCE_LEONIS_H_ +#define _NBL_RESOURCE_LEONIS_H_ + +#include "../nbl_resource.h" +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +1 -0
@@ -17,6 +17,7 @@#define NBL_MAILBOX_BAR 2#define NBL_RDMA_NOTIFY_LEN (8ULL << 10)#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +#define NBL_HW_DUMMY_REG 0x1300904/* * PCI MEMORY BAR total size: 64MiB. */
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +125 -0
125 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +68 -0
68 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,11 +40,15 @@ struct nbl_common_info {u8 devid;u8 bus;u8 hw_bus; +u16 mgt_pf;u8 has_ctrl;u8 has_net; + u8 max_pf; };void nbl_common_destroy_wq (struct nbl_common_info *common);int nbl_common_create_wq (struct nbl_common_info *common); +int nbl_common_func_id_to_rel_pf_id (struct nbl_common_info *common,u32 pf_id, +u32 *rel_pf_id);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +26 -0
@@ -8,9 +8,22 @@#include <linux/types.h> +struct nbl_board_port_info ;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +/** +* flush_write - Flush posted MEMORY-BAR writes +* @hw_mgt: hardware management context +* +* Only valid on the control PF (common->has_ctrl != 0). The +* register read back to order the writes, NBL_HW_DUMMY_REG +* (0x1300904), is covered by the ~64 MiB MEMORY-BAR mapping the +* control PF gets, but sits outside the NBL_REG_NET_ONLY_LEN +* (8 KiB) mapping a net-only PF gets. The leonis implementation +* enforces this with a WARN_ON_ONCE(). +*/ +void (*flush_write)(struct nbl_hw_mgt *hw_mgt);void (*update_mailbox_queue_tail_ptr)(struct nbl_hw_mgt *hw_mgt,u16 tail_ptr,u8 txrx); void (*config_mailbox_rxq)(struct nbl_hw_mgt *hw_mgt,
@@ -44,9 +57,22 @@ struct nbl_hw_ops {* PFs starting at PF0. */ 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 +16 -0
@@ -0,0 +1,16 @@ +/* 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 ; + +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 out_hw_remove; + + ret =nbl_res_init_leonis (adapter); +if (ret) + goto out_chan_remove;return adapter; +out_chan_remove: +nbl_chan_remove_common (adapter); out_hw_remove:nbl_hw_remove_leonis (adapter); out:
@@ -51,6 +59,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter); }
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 2/8] net/nebula-matrix: add common resource implementation
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · 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).
- [Medium] The control-PF probe reads firmware-written board configuration from the mailbox BAR exactly once: the DW3 port…
- [Low] net/nebula-matrix: single-implementation hw_ops and commit message mismatch
--
net/nebula-matrix: add common resource implementation
This adds a chip-agnostic resource layer for the Nebula Matrix driver. On the control PF it reads the PF topology, per-PF BDF, Ethernet port and VSI mappings from hardware and firmware registers once at probe time. It also adds plain lookup helpers that convert between VSI, PF and Ethernet IDs.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +14
-0+/* +* Registers reset to zero after cold boot / FLR / bus reset. Firmware +* programs valid values before driver probe, so zero is only seen on +* hardware fault or register read failure. Initialize data=0 to guard +* against nbl_hw_read_mbx_regs() early-return on bounds-check failure. +*/ +static void nbl_hw_get_fw_eth_map (struct nbl_hw_mgt *hw_mgt,u32 *eth_map) +{ +u32 data =0 ; + +nbl_hw_read_mbx_regs (hw_mgt,NBL_FW_BOARD_DW6_OFFSET , &data, +sizeof (data)); + *eth_map =FIELD_GET (NBL_FW_BOARD_DW6_ETH_BITMAP_MASK , data); +}
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +8
-0+static void nbl_hw_get_board_info (struct nbl_hw_mgt *hw_mgt, +struct nbl_board_port_info *board_info) +{ +u32 data =0 ; + +nbl_hw_read_mbx_regs (hw_mgt,NBL_FW_BOARD_DW3_OFFSET , &data, +sizeof (data)); + board_info->eth_num =FIELD_GET (NBL_FW_BOARD_DW3_PORT_NUM_MASK , data);
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +2
-0+static int nbl_res_ctrl_dev_setup_eth_info (struct nbl_resource_mgt *res_mgt) +{
[ ... ]
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +14
-0+ fw_port_num = res_mgt->resource_info->board_info.eth_num; + + hw_ops->get_fw_eth_map (res_mgt->hw_ops_tbl->priv, ð_bitmap); +if (eth_bitmap & ~((1 <<NBL_MAX_ETHERNET ) -1 )) { +dev_err (dev,"FW reported invalid eth_bitmap 0x%x\n" , + eth_bitmap); +return -EINVAL ; + } +if (fw_port_num !=hweight32 (eth_bitmap)) { +dev_err (dev,"FW inconsistency: port_num=%u, bitmap=0x%x\n" , + fw_port_num, eth_bitmap); +return -EINVAL ; + } +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 70
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +10
-0+* Firmware is ready before probe. Valid port counts are 1/2/4; +* 0 (invalid config), 3 (unsupported topology), and >4 (exceeds +* hardware max) are all rejected with -EINVAL. +*/ +if (fw_port_num ==0 || fw_port_num ==3 || + fw_port_num >NBL_MAX_ETHERNET ) { +dev_err (dev,"FW reports %u Ethernet ports, unsupported (valid: 1/2/4)\n" , + fw_port_num); +return -EINVAL ; + }
[Severity: Medium]
What happens if the control PF is probed before firmware has rewritten the DW3 and DW6 board words?
The comment above nbl_hw_get_fw_eth_map() and nbl_hw_get_board_info() says these registers reset to zero after cold boot, FLR or bus reset. It relies on firmware programming them before probe.
The probe path doesn't seem to check that this has happened. There is no ready bit, poll or -EPROBE_DEFER between nbl_hw_init_leonis() and these single reads:
nbl_probe()->nbl_core_init()->nbl_res_init_leonis()->nbl_res_start()
->nbl_res_init_board_info()
->nbl_res_ctrl_dev_setup_eth_info()If PF0 is bound shortly after an FLR or secondary bus reset, for example a sysfs reset followed by a bind, both reads could return 0. Then:
eth_bitmap == 0 passes the check for bits above NBL_MAX_ETHERNET
fw_port_num == 0 passes fw_port_num != hweight32(eth_bitmap)
fw_port_num == 0 returns -EINVALThe control PF probe would then fail for good. Later in the series the sibling PFs wait on function 0 via nbl_probe_chip_deps(). Would they stay in -EPROBE_DEFER until the management PF is rebound by hand?
Could the all-zero case be treated as "firmware not ready yet" instead of an invalid configuration? A bounded readiness poll in nbl_res_start(), or returning -EPROBE_DEFER for that case, would do it.
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +1
-0+ eth_info->eth_num = fw_port_num;
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +11
-0+static int nbl_res_start (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_common_info *common = res_mgt->common; +int ret =0 ; + +if (common->has_ctrl) { +nbl_res_init_board_info (res_mgt); + + ret =nbl_res_init_pf_num (res_mgt); +if (ret) +return ret;
[ ... ]
Quoted 16 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +6
-0@@ -44,9 +57,22 @@ struct nbl_hw_ops {* PFs starting at PF0. */ 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
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h struct nbl_hw_ops { · line 78
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +7
-0+* +* 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 {
[Severity: Low]
This patch adds four more callbacks to struct nbl_hw_ops (flush_write, get_real_bus, get_fw_eth_map and get_board_info), and nbl_hw_ops still has only one implementation, the static hw_ops in nbl_hw_leonis.c. v35 dropped nbl_resource_ops after the earlier request not to add ops tables until a second implementation exists. Does the same reasoning apply to nbl_hw_ops?
The callers in nbl_res_init_pf_num(), nbl_res_ctrl_dev_pf_info_init(), nbl_res_ctrl_dev_setup_eth_info() and nbl_res_init_board_info() are all in nbl_hw_leonis/nbl_resource_leonis.c, so this is Leonis code calling Leonis helpers through res_mgt->hw_ops_tbl->ops. nbl_hw_setup_ops() also devm-allocates a wrapper whose only job is to point at a static table. Could these be direct calls until draco actually lands?
The commit message also doesn't seem to match the code. It says nbl_hw_ops_tbl is the only remaining ops table, but struct nbl_channel_ops_tbl is already in struct nbl_interface, and a later patch in the series adds struct nbl_dispatch_ops_tbl. It also says the PF mask validation and the BDF/Eth/VSI table construction are shared between the two chip families. Those are static functions in nbl_resource_leonis.c, called only from nbl_res_init_leonis(). Only the ID conversion helpers in nbl_resource.c are chip-agnostic. Can the description be updated, or the shared code moved where the message says it is?
Finally, this patch removes the NULL checks on the static hw_ops members in nbl_hw_setup_ops() that the channel layer patch earlier in this series added. Those checks could never fire. Could they be left out of the patch that introduces nbl_hw_setup_ops(), so this one does not have to delete them?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 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 the Nebula Matrix Ethernet driver.
This module manages the driver-wide global hardware MSI-X vector index space, split into independent network and control interrupt bitmaps (intr_net_bmap/intr_other_bmap), and handles programming of the chip-internal MSI-X mapping registers. It explicitly does not manage physical PCI MSI-X entries; physical vector allocation via pci_alloc_irq_vectors() will be implemented in a follow-up patch via nbl_dev_init_interrupt_scheme().
The published manager is control-PF only: the resource helpers reject calls when common->has_ctrl is not set.
Core functional interfaces:
1. cfg_msix_map: Allocate global hardware MSI-X vectors from the separate net/other interrupt bitmaps. The per-function coherent DMA map table is allocated once and reused by every later reconfiguration, so a reconfiguration does not free and reallocate it. It does still take the destroy-path quiesce sequence before the old vectors are recycled
- disable mailbox routing, invalidate the per-vector INFO entries, clear map VALID, flush, wait for in-flight table fetches - because the old table is what the pcompleter may still be reading; only the DMA buffer itself survives. Only tear down the old hardware state after the new allocation succeeds, to avoid interrupt loss, and program the MSI-X table DMA address plus the control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP. No extra invalidate or quiesce window is needed before the first configuration either: every map entry is invalid at that point, since nbl_intr_mgt_start() scrubbed them all and nothing arms one before cfg_msix_map does.
2. destroy_msix_map: Recycle global vector indices, clear hardware MSI-X mappings, and release the descriptor resources. Implements two-stage
teardown: disable mailbox IRQ routing first, mask vectors, clear hardware VALID bits while retaining the live DMA addresses, take a bounded best-effort ~1ms hardware DMA quiescence window, then zero the table entries and release the vector bitmap and interrupt buffer. The coherent map table itself is deliberately not freed: a sibling PF can reach this teardown at runtime while the control PF is still bus master, the table fetches carry the control PF's BDF, and the quiesce window is best-effort, so a late fetch could read reused memory. The table is kept for the function's lifetime, reused by a later configuration, and released only by nbl_intr_mgt_stop().
3. set_mailbox_irq: Toggle PF-specific mailbox MSI-X routing by updating NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured MSI-X map, enabling safe routing cleanup before vector release.
4. cfg_msix_info: Program PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with the strict hardware-defined programming order (forward for enable, reverse for teardown) to avoid inconsistent hardware state.
Key design & safety features:
- Self-contained intr_mgt->lock protects the global bitmaps and the per-function state; all public APIs hold the lock internally, so callers need no upper-layer locking.
- Global cleanup via nbl_intr_mgt_stop(): under the lock it latches the manager stopping and invalidates the hardware map entry of every function still left CONFIGURED, then takes a single global quiesce window before the coherent tables and vector indices are released. Remote PF maps are created via mailbox RPC in later patches; the cleanup itself uses local MMIO writes.
- Only PFs are supported: every op rejects a func_id outside the PF range (a VF id) with -EINVAL, and cfg_msix_map additionally rejects a func_id that maps to a PF which is not present on this board with -EOPNOTSUPP, via nbl_res_func_id_to_bdf().
- FUNCTION_MSIX_MAP survives a kexec or a forced unload without FLR and there is no .shutdown callback to scrub it, so nbl_intr_mgt_start() invalidates all NBL_MAX_PF map entries once, followed by one flush and one quiesce window, before any function is configured. nbl_probe() now leaves bus mastering disabled until nbl_core_init() has returned, so this scrub runs before the device can issue a single fetch against a stale VALID entry - those fetches are bus-master reads, and a stale entry points at memory this kernel may already have reallocated. Everything up to the scrub is host-side setup plus MMIO and does not wait for the device, so keeping bus mastering off until nbl_core_init() has returned costs nothing on the probe path.
Known limitation - MSI-X map table DMA quiescence:
The chip exposes no idle or completion status for a pcompleter fetch of a map table, so the only ordering available anywhere in this module is "clear VALID -> flush_write() -> bounded delay". The delay is sized well above the tables' worst-case fetch/response latency, but it is a best-effort approximation and not a guarantee, which is why nothing in this module relies on it to make coherent memory freeable: a per-function destroy keeps its table. What the window does protect is the vector set that a reconfiguration hands to another function.
The tables are released only by nbl_intr_mgt_stop(), after one global window, and nbl_remove() clears Bus Master Enable before nbl_core_remove() reaches it, so the device cannot start a new fetch and the residual window covers in-flight requests only. Clearing bus mastering cannot help a sibling PF's map destroyed at runtime - those fetches are tagged with the control PF's BDF - which is exactly why the table is retained there.
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, and Makefile entries to wire up the new module.
The three new helpers (nbl_res_intr_cfg_msix_map(), nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq()) have no in-tree callers within this patch; invocation will be added in subsequent patches in this series.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 159 ++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 44 + .../nbl_hw_leonis/nbl_resource_leonis.c | 36 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 859 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 90 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 42 +- 11 files changed, 1284 insertions(+), 10 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 +159 -0
183 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +44 -0
50 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +34 -2
@@ -277,6 +277,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 ;
@@ -307,8 +311,36 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)void nbl_res_remove_leonis (struct nbl_adapter *adap) { +struct nbl_resource_mgt *res_mgt = adap->core.res_mgt; +struct nbl_common_info *common = &adap->common; + +if (!res_mgt) +return ; +/* -* No resource release here because all memory uses devm managed -* allocation +* Tear down all MSI-X maps before destroying coherent tables. +* This is critical on the control PF, whose table carries the map +* entries installed for every configured function: they must be +* invalidated in hardware before the tables backing them are +* freed, otherwise the device keeps DMA-reading released pages. +* +* Sibling PFs are unbound by the device-link ordering, but that +* does not mean their entries are gone: a destroy_msix_map RPC +* that timed out leaves the control PF owning that function's map +* entry, its net/other bitmap bits and its coherent table. That is +* why nbl_intr_mgt_stop() walks every configured function instead +* of relying on the siblings having cleaned up after themselves, +* and the walk must stay for that case. +*/ +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 freed by nbl_intr_mgt_stop() too, after +* the last quiesce window and with bus mastering already cleared. +* 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 +859 -0
859 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_pf_info *pf_info; +int pfid = func_id; +u8 pf_bus, devfn; +u32 rel_pf_id; +int ret; + +if (!common->has_ctrl || !bus || !dev || !function) +return -EINVAL ; + ret =nbl_common_func_id_to_rel_pf_id (common, pfid, &rel_pf_id); +if (ret) +return ret; +if (rel_pf_id >= common->max_pf) { +dev_err (common->dev, +"func_id=%u rel_pf_id=%u exceeds max_pf=%u, no such PF on this board\n" , + pfid, rel_pf_id, + common->max_pf); +return -EOPNOTSUPP ; + } + pf_info = res_mgt->resource_info->pf_info + rel_pf_id; + pf_bus =PCI_BUS_NUM (pf_info->bdf); + devfn = pf_info->bdf &0xff ; + *bus = pf_bus; + *dev =PCI_SLOT (devfn); + *function =PCI_FUNC (devfn); + +return 0 ; +} +int nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 vsi_id,u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +90 -0
110 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
@@ -12,6 +12,13 @@ struct nbl_board_port_info;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,dma_addr_t dma_addr,u8 bus, +u8 devid,u8 function); +void (*cfg_msix_info)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,u16 interrupt_id,u8 bus, +u8 devid,u8 function, +bool net_msix_mask_en);/** * flush_write - Flush posted MEMORY-BAR writes * @hw_mgt: hardware management context
@@ -61,6 +68,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_main.c +34 -8
63 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 3/8] net/nebula-matrix: add intr resource implementation
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The init scrub in nbl_intr_setup_mgt() invalidates only FUNCTION_MSIX_MAP.
- [Low] The commit message and the new nbl_probe() comment (nbl_main.c, "...Bus Master Enable, which the PCI core cleared on the way into this…
- [Low] At this commit, nbl_res_intr_cfg_msix_map(), nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq()…
- [Low] The header comment of nbl_intr_setup_mgt() justifies scrubbing only NBL_MAX_PF (8) FUNCTION_MSIX_MAP entries by saying the table "is…
- [Low] Two comments state as a safety invariant that nbl_intr_mgt_stop() is the only place a coherent MSI-X map table is freed.
- [Low] The public entry points load res_mgt->intr_mgt with a plain load and no lock, then call mutex_lock() on it.
--
net/nebula-matrix: add intr resource implementation
This adds an nbl_interrupt module that manages the chip-internal MSI-X vector index space. For the control PF it programs the FUNCTION_MSIX_MAP, PADPT_HOST_MSIX_INFO and HOST_MSIX_FID_TABLE registers. It also scrubs stale FUNCTION_MSIX_MAP entries at init, moves pci_set_master() after nbl_core_init(), and moves pci_clear_master() before nbl_core_remove().
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +1
-0@@ -136,6 +150,148 @@ 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); } +/*
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 163
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+* nbl_hw_set_mailbox_irq - read-modify-write NBL_MAILBOX_QINFO_MAP_REG_ARR +* +* The full RMW sequence is wrapped by reg_lock, so concurrent register +* access from different CPUs is already serialized safely. +* nbl_hw_cfg_mailbox_qinfo() programs the BDF fields during control-PF +* init and clears MSIX_IDX/MSIX_IDX_VALID at the same time (they survive +* kexec/forced unload without FLR), so mailbox MSIX routing for a PF +* starts disarmed at init and is armed only by an explicit en_msix=true +* call here. +*/
[Severity: Low]
Is this comment accurate at this commit? As far as I can tell, nbl_hw_cfg_mailbox_qinfo() has no caller yet. So nothing clears MSIX_IDX/MSIX_IDX_VALID during control-PF init, and the only scrub this patch adds, in nbl_intr_setup_mgt(), covers FUNCTION_MSIX_MAP and nothing else.
Later patches in the series fix this. "net/nebula-matrix: add common/ctrl dev init/remove operation" makes nbl_dev_init() call nbl_dev_setup_chan_qinfo() -> cfg_chan_qinfo_map_table() -> nbl_hw_cfg_mailbox_qinfo() for every active PF. "net/nebula-matrix: add chip-wide hardware init/deinit implementation" adds nbl_hw_clear_stale_status() for the kexec case.
Could the comment be worded so it is true at this point in the series, or say that the caller comes in a later patch?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 38
Quoted 11 lines
+ * Those are bus-master reads tagged with the control PF's BDF, so
+ *pci_clear_master()is the only other lever. The only place a table is
+ * freed isnbl_intr_mgt_stop(), whichnbl_remove()reaches through
+ *nbl_core_remove(), after it has cleared bus mastering. That is what
+ * makes the final free safe: the device cannot start a new fetch, and
+ * this window covers the ones already in flight.
+ */drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +4
-0+static void nbl_intr_quiesce_wait (void ) +{ +usleep_range (NBL_MSIX_DMA_SYNC_MIN_US ,NBL_MSIX_DMA_SYNC_MAX_US ); +}
[Severity: Low]
This isn't a bug, but is "The only place a table is freed is nbl_intr_mgt_stop()" accurate? The release_vecs_unlock error path in nbl_res_intr_cfg_msix_map() frees the table too:
if (tbl_alloc) {
dma_free_coherent(dev, official_tbl->size,
official_tbl->base_addr,
official_tbl->dma);That free is safe today. tbl_alloc is only set on a first configuration, and every goto release_vecs_unlock comes before cfg_msix_map(valid=true) is called. The free loop in nbl_intr_mgt_stop() makes the same claim ("so this is the only place they are released").
Could both comments mention the error-path free of a table that was never armed? Neither comment changes by the end of the series.
[ ... ]
Quoted 2 lines
+/**
+ *nbl_res_intr_cfg_msix_map- allocate & program MSI-X mapping table
[ ... ]
Quoted 4 lines
+ * not maximum, concurrent use: a reconfigure of the same or a smaller
+ * size still fails with-EAGAINwhen the pool is nearly exhausted. The
+ * in-tree caller asks for one non-net vector per PF, far below
+ *NBL_MAX_OTHER_INTERRUPT.
[Severity: Low]
Which in-tree caller does this mean? At this commit, nbl_res_intr_cfg_msix_map(), nbl_res_intr_destroy_msix_map() and nbl_res_intr_set_mailbox_irq() have no callers. That means the reconfiguration and teardown paths cannot be reached yet.
The new comment in nbl_res_remove_leonis() has the same problem:
* does not mean their entries are gone: a destroy_msix_map RPC
* that timed out leaves the control PF owning that function's map
That RPC is only added later.
Later patches add the callers: "net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id" and "net/nebula-matrix:
add common dev start/stop operation". The kernel-doc is then updated to name nbl_dev_cfg_msix_map().
Could these comments avoid describing callers that do not exist yet at this point in the series?
[ ... ]
Quoted 7 lines
+/*
+ * Reset the software state and invalidate every function's hardware MSI-X
+ * map entry once. The chip-internal tables (FUNCTION_MSIX_MAP,
+ *PADPT_HOST_MSIX_INFO,HOST_MSIX_FID_TABLE) can survive a kexec or a
+ * forced unload without FLR and there is no .shutdown callback to scrub
+ * them. OnlyFUNCTION_MSIX_MAPis scrubbed here: it is indexed by the
+ * 3-bit PCI function number (NBL_FUNCTION_MSIX_MAP_FUNCTION_MASK), so the
Quoted 8 lines
+ *
NBL_MAX_PF(8) entries are every entry the pcompleter can select - the
+ * 10-bit FID mask belongs toHOST_MSIX_FID_TABLE, a separate table
+ * indexed by FID. One register write each, after which the pcompleter
+ * can no longer fetch a stale table that points into memory this kernel
+ * may have reallocated. The INFO/FID tables are indexed by global vector
+ * id and are not cleared; instead a map entry is always invalidated by
+ *nbl_res_intr_cfg_msix_map()and by the teardown paths before it is
+ * armed for a new configuration.
[Severity: Low]
Does the register layout support this reason for scrubbing only NBL_MAX_PF entries?
NBL_FUNCTION_MSIX_MAP_FUNCTION_MASK is a field in data[2] of an entry. nbl_res_intr_cfg_msix_map() writes the control PF's own common->function into it for every func_id. The table index is func_id, through NBL_PCOMPLETER_FUNCTION_MSIX_MAP(i).
nbl_hw_cfg_msix_info() indexes HOST_MSIX_FID_TABLE by global vector id:
nbl_hw_wr_regs(hw_mgt, NBL_PCOMPLETER_HOST_MSIX_FID_TABLE(interrupt_id), &host_msix_fid, sizeof(host_msix_fid));
This comment says the same a few lines further down ("The INFO/FID tables are indexed by global vector id"). The 10-bit FID field of that table holds func_id. struct nbl_interrupt_mgt describes func_intr_res[] as indexed by the "raw hardware function id", and that range includes VFs.
How many entries does FUNCTION_MSIX_MAP actually have? If it has more than 8, can stale VALID entries for func_id >= 8 survive this scrub? Either way, could the comment be corrected? It is still the same at the end of the series.
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 859
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+/* +* Unpublish last. Readers do not synchronize on intr_mgt->lock, +* so this only has to happen after every hardware access and +* every free above; a caller that latched the pointer earlier is +* rejected by the stopping latch. +*/ + res_mgt->intr_mgt =NULL ; +mutex_unlock (&intr_mgt->lock); +}
[Severity: Low]
The public entry points read this pointer with a plain load and without the lock:
struct nbl_interrupt_mgt *intr_mgt = res_mgt->intr_mgt;
It is cleared here with a plain store, and devres frees the object after remove(). Could an in-flight caller reload a NULL pointer, or use intr_mgt after devres has freed it?
Looking at the rest of the series, there is no concurrent reader. The only asynchronous callers are the RPC responders, which run from clean_mbx_task. nbl_remove() -> nbl_core_stop() cancels that work. Then nbl_core_remove() -> nbl_dev_remove() -> nbl_dev_remove_common_dev() -> nbl_chan_teardown_queue() joins it with cancel_work_sync(). Only after that does nbl_res_remove_leonis() -> nbl_intr_mgt_stop() run. The local callers run on the probe/remove thread, and the device links unbind the sibling PFs first.
If that ordering is the real guarantee, would it be clearer to state in the struct nbl_resource_mgt comment that there are no concurrent readers, or to use READ_ONCE()/WRITE_ONCE()?
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +1
-2@@ -261,20 +261,32 @@ static int nbl_probe(struct pci_dev *pdev,/* never return fail when DMA_BIT_MASK(64) */ dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 )); -pci_set_master (pdev); - +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 274
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+* Bus mastering is enabled only after nbl_core_init() returns. +* +* FUNCTION_MSIX_MAP survives a kexec or a forced unload without +* FLR and there is no .shutdown callback to scrub it, so at this +* point every map entry left VALID by a previous kernel still +* holds a DMA address that this kernel has already reallocated. +* Those entries tag their table fetches as bus-master reads, and +* the only thing standing between such a fetch and a read of +* reused memory is Bus Master Enable, which the PCI core cleared +* on the way into this kernel. nbl_intr_setup_mgt() invalidates
[Severity: Low]
Does the PCI core always clear Bus Master Enable before the new kernel runs? pci_device_shutdown() calls pci_clear_master() only when kexec_in_progress is set. A crash kexec (kdump) does not run device_shutdown() at all. In that case the device enters the dump kernel with bus mastering still on, and it can fetch the stale FUNCTION_MSIX_MAP tables before nbl_probe() runs the scrub.
The comment in nbl_intr_setup_mgt() makes the same claim:
* This is the scrub that makes it safe to enable bus mastering:
* nbl_probe() calls it with bus mastering still disabled, so no
* new fetch can start while these entries are still VALID.
So does the commit message:
"nbl_probe() now leaves bus mastering disabled until nbl_core_init() has returned, so this scrub runs before the device can issue a single fetch against a stale VALID entry"
The practical impact looks small. The dump kernel runs inside the crashkernel reservation, so it will not have reused the first kernel's coherent tables.
Could the comments and the commit message be limited to the orderly kexec case? The .shutdown callback that the comments say is missing would cover kdump. The end of the series still has no .shutdown, and this comment is unchanged.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 4/8 net/nebula-matrix: add chip-wide hardware init/deinit implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers. The resource layer gates both on has_ctrl, so they only run on the control PF.
init_module() programs the chip-wide datapath registers, none of which firmware sets up on the driver's behalf:
- DPED: VLAN/DSCP offsets and the SCTP L4 checksum enable.
- UPED: V4/V6 TCP L3-length edit profiles.
- SHAPING: per-port CIR/PIR from the firmware-reported speed (the DVN dport entry carries PIR at the full rate and CIR at half rate), a bucket depth derived from the rate, PSHA enable for the ports present, and a clear of the PF-indexed shaping_net table.
- DSCH: host QID max (0x7ff) and the host/ECPU quanta.
- USTORE: minimum packet length 42 and the per-port drop threshold, scaled by the PF count, plus a clear of the port drop/truncate counters by reading them back.
- DSTORE: clear the per-port drop enable, program the XON/XOFF flow-control thresholds (a larger pair at 100G), and enable the discard backpressure threshold.
- DVN: ECPU queue count, descriptor-write merge timeout, descriptor request count (by speed), and the relaxed-ordering bits.
- UVN: ECPU queue count, descriptor read-wait/write-timeout, the error mask, and the relaxed-ordering bits. The relaxed-ordering bits in both DVN and UVN are derived from the PCIe DEVCTL state through pcie_relaxed_ordering_enabled().
- UQM: clear the drop counters and force que_type to backpressure.
- PADPT: the host flow-control credits.
This also adds a firmware ABI dependency: nbl_hw_get_quirks() reads a quirk word at mailbox offset NBL_LEONIS_QUIRKS_OFFSET (0x140), where ~0U means "no quirks" and BIT(1) selects the UVN prefetch mode (sel=0, use the configured descriptor count) instead of the internal calculation.
deinit_module() clears the driver_status bit, flushes writes and sleeps 2-3 ms to give the asynchronous firmware cleanup pass time to run. It deliberately reverts none of the above: that pass covers per-PF state only (qinfo registers and mailbox routing), so the chip-wide datapath registers stay programmed until chip reset or until a later init_module() overwrites them, even if the control PF is later bound to another driver. The hardware exposes no cleanup-complete status bit, so the sleep is best-effort and cannot prove the pass has finished.
A stale driver_status bit (kexec, or an unload that never reached deinit_module()) is cleared in nbl_hw_init_leonis(), before this probe programs any per-PF state. The 1 -> 0 transition makes firmware reclaim the mailbox QINFO routing and qinfo registers, so clearing it from init_module() instead - after nbl_dev_setup_chan_qinfo() has programmed them - would leave the inter-PF mailbox dead and make sibling probes time out.
Two known limitations of that handshake, neither of which the driver can close on this hardware:
- NBL_DRIVER_STATUS_REG is shared with firmware. Bit 16 is the only bit the driver owns, and the register has no documented W1S/W1C form, so changing bit 16 has to be a read-modify-write. reg_lock makes the read-modify-write atomic against other CPU writers but cannot serialise against firmware, so a firmware update to a different bit landing between the read and the write would be written back stale. All three callers (the probe-time stale clear, init_module() and deinit_module()) could in principle hit that; no such firmware update is known to race them, but that is an observation about this hardware revision, not a guarantee.
- The 2-3 ms wait is an empirical bound, not a documented firmware latency. There is nothing to poll instead: the hardware exposes no cleanup-complete bit, and the reclaimed entries read back the same before and after the pass, so there is no observable side effect to wait on and nothing to validate the delay against. A pass that takes longer than the window - an ECPU still busy right after kexec, say - can therefore still race a later probe and reclaim routing that probe has already programmed. What actually protects the per-PF state is the ordering around the clear, not the delay, and on teardown that ordering comes from the device link between the sibling PFs and the control PF.
The two hooks are only checked for non-NULL by nbl_hw_setup_ops() and nbl_res_setup_ops() at this point; nothing calls them yet. They gain callers later in the series, from the dispatch init_module()/ deinit_module() and from nbl_dev_setup_ctrl_dev()/ nbl_dev_remove_ctrl_dev().
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 787 ++++++++++++++++++ .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 242 ++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nbl/nbl_include/nbl_def_hw.h | 3 + .../nbl/nbl_include/nbl_include.h | 19 + 8 files changed, 1097 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -9,4 +9,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ + nbl_hw/nbl_chip.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include "nbl_chip.h" + +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = res_mgt->common; + +if (!common->has_ctrl) +return ; + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +} + +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_common_info *common = res_mgt->common; +struct nbl_hw_ops *hw_ops; +u8 eth_speed, eth_num; +struct nbl_hw_mgt *p; + +if (!common->has_ctrl) +return -EINVAL ; + eth_speed = res_mgt->resource_info->board_info.eth_speed; + eth_num = res_mgt->resource_info->board_info.eth_num; + hw_ops = res_mgt->hw_ops_tbl->ops; + p = res_mgt->hw_ops_tbl->priv; +return hw_ops->init_module (p, eth_speed, eth_num); +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_CHIP_H_ +#define _NBL_CHIP_H_ + +#include "nbl_resource.h" +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt); +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +787 -0
816 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +242 -0
271 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -8,4 +8,5 @@#include "../nbl_resource.h" #include "../nbl_interrupt.h" +#include "../nbl_chip.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +3 -0
@@ -12,6 +12,9 @@ struct nbl_board_port_info;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +int (*init_module)(struct nbl_hw_mgt *hw_mgt,u8 eth_speed,u8 eth_num); +void (*deinit_module)(struct nbl_hw_mgt *hw_mgt); +void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id,bool valid,dma_addr_t dma_addr,u8 bus,u8 devid,u8 function);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +19 -0
@@ -29,4 +29,23 @@ struct nbl_init_param { struct nbl_func_caps caps; }; +/* +* Firmware ABI defines port speed enum fixed, value 0 represents 10G, cannot +* reassign 0 to INVALID for compatibility +*/ +enum nbl_fw_port_speed { +NBL_FW_PORT_SPEED_10G , +NBL_FW_PORT_SPEED_25G , +NBL_FW_PORT_SPEED_50G , +NBL_FW_PORT_SPEED_100G , +}; + +/* +* Firmware quirk word @ NBL_LEONIS_QUIRKS_OFFSET (0x140) +* Sentinel value: ~0U (0xFFFFFFFF) = firmware reports no active quirks +* BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch +* selection +*/ +#define NBL_QUIRK_UVN_PREFETCH_ALIGN BIT(1) +#endif
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] When nbl_hw_clear_stale_status() finds bit 16 of NBL_DRIVER_STATUS_REG already set (after kexec, or after a previous…
- [Low] The commit message says: "The two hooks are only checked for non- NULL by nbl_hw_setup_ops() and nbl_res_setup_ops() at this point".
- [Low] The comment in nbl_hw_get_quirks() describes a fallback that can never run, and it contradicts itself.
- [Low] The WARN_ON(eth_num != 1 && eth_num != 2 && eth_num != 4) in nbl_ustore_init() can never fire, so its comment is wrong to say it…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers. On the control PF they program the DPED, UPED, SHAPING, DSCH, USTORE, DSTORE, DVN, UVN, UQM and PADPT datapath registers. The commit also adds a firmware quirk word read at mailbox offset 0x140, and a probe-time clear of a stale driver_status bit before any per-PF state is programmed.
Quoted 5 lines
The two hooks are only checked for non-NULL by
nbl_hw_setup_ops()andnbl_res_setup_ops()at this point; nothing calls them yet. They gain callers later in the series, from the dispatch init_module()/deinit_module()and from nbl_dev_setup_ctrl_dev()/nbl_dev_remove_ctrl_dev().
[Severity: Low]
Is this description accurate? nbl_hw_setup_ops() in nbl_hw_leonis.c only allocates the table and assigns the pointers:
hw_ops_tbl = devm_kzalloc(dev, sizeof(*hw_ops_tbl), GFP_KERNEL); if (!hw_ops_tbl) return ERR_PTR(-ENOMEM); hw_ops_tbl->ops = &hw_ops; hw_ops_tbl->priv = hw_mgt;
It never checks ops->init_module or ops->deinit_module.
nbl_res_setup_ops() doesn't appear to exist anywhere under drivers/net/ethernet/nebula-matrix/, either at this commit or at the end of the series.
The rest of the paragraph holds up. "net/nebula-matrix: dispatch: add control-level routing core infrastructure" wires nbl_disp_init_module()/nbl_disp_deinit_module() to nbl_res_chip_*(). "net/nebula-matrix: add common/ctrl dev init/remove operation" adds the calls from nbl_dev_setup_ctrl_dev()/nbl_dev_remove_ctrl_dev().
The nbl_hw_deinit_module() precondition also holds by the end of the series, because nbl_dev_remove() calls nbl_dev_remove_common_dev() before nbl_dev_remove_ctrl_dev().
Could the NULL-check sentence be corrected?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +9
-0@@ -150,6 +175,756 @@ 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); } +static u32 nbl_hw_get_quirks (struct nbl_hw_mgt *hw_mgt) +{ +u32 quirks =0 ; + +/* +* Read quirk bits from mailbox register. +* All supported firmware implement the quirk ABI, +* firmware always populates NBL_LEONIS_QUIRKS_OFFSET. +* Value ~0U indicates no active quirks.
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 196
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+* +* There is no firmware version field in this ABI to gate the read +* on: the quirk word itself is the capability advertisement. A +* word firmware never populated reads as zero (or is rejected by +* the mailbox-bar bounds check, leaving the zero initialiser), and +* zero selects the same sel=1 prefetch default as ~0U, which is +* what firmware predating the quirk needs. +*/ +nbl_hw_read_mbx_regs (hw_mgt,NBL_LEONIS_QUIRKS_OFFSET , &quirks, +sizeof (u32));
[Severity: Low]
Can the bounds-check fallback in this comment ever run? nbl_hw_init_leonis() fails probe when the mailbox BAR is shorter than NBL_BAR2_MAX_LEN (0x300), and then sets mailbox_bar_size = bar_len:
if (bar_len < NBL_BAR2_MAX_LEN) {
dev_err(&pdev->dev, "MAILBOX BAR length %pa too small\n",
&bar_len);
ret = -EINVAL;
return ret;
}This read covers 0x140..0x143, so the reg + len > mailbox_bar_size check in nbl_hw_read_mbx_regs() can't reject it.
The comment also contradicts itself. It first says all supported firmware always populates the word, then relies on firmware predating the quirk leaving it as zero. Which one is intended?
The ABI note for NBL_QUIRK_UVN_PREFETCH_ALIGN in nbl_include.h defines only ~0U and BIT(1). It doesn't say that 0 means no quirks, so older firmware works only if mailbox offset 0x140 reads as zero.
If such firmware leaves BIT(1) set at that offset, would UVN prefetch silently switch to sel=0?
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +7
-0+static int nbl_ustore_init (struct nbl_hw_mgt *hw_mgt,u8 eth_num) +{ +u32 eth_bitmap =0 ; +u32 drop_th =0 ; +u32 pkt_len =0 ; +u32 reg_val =0 ; +int i;
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 409
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+ +/* +* eth_num is validated in the resource layer: +* nbl_res_init_pf_num() requires 1/2/4 PFs, and +* nbl_res_ctrl_dev_setup_eth_info() requires max_pf == eth_num. +* This is a defensive check only; if it triggers, the resource +* layer validation was bypassed, which is a bug. +*/ +if (WARN_ON (eth_num !=1 && eth_num !=2 && eth_num !=4 )) +return -EINVAL ;
[Severity: Low]
Can this WARN_ON() ever fire? nbl_ustore_init() is static and is only reached through nbl_hw_init_module()->nbl_dp_init(). nbl_hw_init_module() already rejects the same values before it calls nbl_dp_init():
if (!nbl_hw_eth_num_valid(eth_num)) {
dev_err(hw_mgt->common->dev, "Invalid eth_num %u\n", eth_num);
return -EINVAL;
}If the resource-layer validation were bypassed, that dev_err() path would catch it first, so the warning this comment promises would never appear.
The same check now exists in three places, but the comment names only two. Could the duplicate check be removed, or the comment updated?
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static void nbl_hw_clear_stale_status (struct nbl_hw_mgt *hw_mgt) +{
[ ... ]
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 886
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+ status =nbl_hw_rd32 (hw_mgt,NBL_DRIVER_STATUS_REG ); +if (!(status &BIT (NBL_DRIVER_STATUS_BIT ))) +return ; + +dev_warn (hw_mgt->common->dev, +"driver_status already set, stale cleanup forced\n" ); +nbl_hw_set_driver_status (hw_mgt, false); +nbl_flush_writes (hw_mgt); +usleep_range (NBL_FW_CLEANUP_SYNC_MIN_US ,NBL_FW_CLEANUP_SYNC_MAX_US ); +}
[Severity: Medium]
What happens on this stale path if the firmware reclaim pass takes longer than the 2-3 ms window? Probe goes on regardless:
nbl_hw_init_leonis()
nbl_hw_clear_stale_status()
usleep_range(2000, 3000)
nbl_core_init()
nbl_dev_init()
nbl_dev_setup_chan_qinfo()
mailbox queue setup
A pass that is still running could wipe the QINFO routing and qinfo QUEUE_EN state this probe has just programmed. The control PF would report no error. The inter-PF mailbox would stop working, though, and sibling PFs would later fail with RPC timeouts in nbl_dev_start() until the control PF is rebound.
The commit message names this case ("an ECPU still busy right after kexec") as the one most likely to overrun the window.
The comments justify the fixed sleep by saying "the reclaimed entries read back the same before and after the pass, so there is no observable side effect to wait on". Does that hold here? The comment above this function says the pass "wipes those registers".
After kexec or an unclean unload, the previous instance has programmed NBL_MAILBOX_QINFO_MAP_REG_ARR (BDF, MSIX_IDX, MSIX_IDX_VALID) and set NBL_MAILBOX_QINFO_CFG_QUEUE_EN_MASK through config_mailbox_rxq/txq. No .shutdown callback undoes that before kexec. Those entries should therefore hold non-reset values before the pass and change once it runs.
Would a bounded poll on those entries work here instead of the fixed sleep? Another option is a read-back check after nbl_dev_setup_chan_qinfo().
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 5/8 net/nebula-matrix: dispatch: add control-level routing core infrastructure
In reply to illusion.wangFrom: illusion wang <[email protected]>
Allocate the dispatch management state and ops table and wire the init_module and deinit_module wrappers to the resource layer helpers. Add a ctrl_lvl bitmap to track control privileges; only the MGT level is defined, and it is enabled only on the control PF.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 107 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 ++++ .../nbl/nbl_include/nbl_def_dispatch.h | 53 +++++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 6 files changed, 194 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
@@ -16,12 +16,14 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_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 +107 -0
107 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_mgt *res_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); +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +53 -0
53 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8 -0
@@ -11,6 +11,7 @@#include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" #include "nbl_include/nbl_def_resource.h" +#include "nbl_include/nbl_def_dispatch.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -48,7 +49,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_res_init_leonis (adapter);if (ret) goto out_chan_remove; + + ret =nbl_disp_init (adapter); +if (ret) + goto out_res_remove;return adapter; +out_res_remove: +nbl_res_remove_leonis (adapter); out_chan_remove:nbl_chan_remove_common (adapter); out_hw_remove:
@@ -59,6 +66,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter);
Signature · 1 line
2.51.0.windows.1
illusion.wang
maintainerPATCH v35 6/8 net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add request and response handlers for five dispatch operations:cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Each op is resolved by capability level: a function with has_ctrl calls the resource op locally, a function with has_net forwards it to the management PF over the channel, and a function with neither leaves the op pointer NULL, so the caller must not invoke it. The channel framework itself - send_msg, the ACK plumbing and handler registration - is already in place from the channel layer patch; this one adds the five message handlers on top of it.
A request builds the payload, sends it synchronously and checks the ACK length before parsing; a short ACK returns -EBADMSG. A responder rejects VFs and out-of-range source PF ids with -EPERM, checks the payload length before parsing, and forwards the resource layer's errno verbatim so the requester can tell a protocol error from a failed operation. If the resource op is not installed the responder answers -EOPNOTSUPP. A peer PF is treated as trusted: hardware and firmware forbid PF passthrough to guests, so every peer runs this host driver, and the resource layer bounds the requested vector counts by the global pool.
The cfg_msix_map, destroy_msix_map and set_mailbox_irq requests carry a caller precondition: clear the mailbox IRQ_RDY flag and use the polling send path, because the responder changes mailbox MSI-X routing and an interrupt-driven ACK wakeup cannot be relied on while routing is in flux. The precondition is documented on struct nbl_dispatch_ops, which is what callers program against, not only next to the static helpers.
No serialization is added here. The resource layer serializes concurrent callers itself through intr_mgt->lock, and the dispatch layer has no mutable state of its own to protect; the read-only get_vsi_id/get_eth_id paths only touch static init metadata.
This is also the first path that lets a sibling PF tear its MSI-X map down on the control PF at runtime. That teardown runs while the control PF is still bus master, which is why the interrupt layer keeps each coherent map table for the function's lifetime and releases it only in nbl_intr_mgt_stop(), instead of relying on the per-destroy quiesce window.
The five responders are registered with the channel layer and owned by
it: they live in the channel's handler xarray and are freed with it, so nbl_disp_remove() has nothing to undo. Nothing can enter them in this patch because no mailbox queue is running yet. Once a queue is brought up, the invariant they rely on is that it must be torn down before nbl_res_remove_leonis() runs, so no responder can outlive the resource layer it forwards into.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 496 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_channel.h | 40 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 45 +- 3 files changed, 578 insertions(+), 3 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +496 -0
@@ -6,6 +6,163 @@#include <linux/pci.h> #include "nbl_dispatch.h" #include "../nbl_hw/nbl_chip.h" +#include "../nbl_hw/nbl_interrupt.h" + +static int nbl_disp_chan_get_vsi_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 type,u16 *vsi_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.type =cpu_to_le16 (type); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_GET_VSI_ID , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_vsi_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +return -EBADMSG ; + } + *vsi_id =le16_to_cpu (result.vsi_id); +return 0 ; +} + +static void nbl_disp_chan_get_vsi_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u16 vsi_id =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + + ret =nbl_res_func_id_to_vsi_id (disp_mgt->res_mgt, src_id, +le16_to_cpu (param.type), &vsi_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + + result.vsi_id =cpu_to_le16 (vsi_id); +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_GET_VSI_ID , msg_id, err, + &result,sizeof (result)); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_GET_VSI_ID ); +} + +static int nbl_disp_chan_get_eth_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.vsi_id =cpu_to_le16 (vsi_id); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_GET_ETH_ID , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_eth_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +return -EBADMSG ; + } + *eth_num = result.eth_num; + *eth_id = result.eth_id; + *logic_eth_id = result.logic_eth_id; + +return 0 ; +} + +static void nbl_disp_chan_get_eth_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + + ret =nbl_res_get_eth_id (disp_mgt->res_mgt, src_id, +le16_to_cpu (param.vsi_id), &result.eth_num, + &result.eth_id, &result.logic_eth_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; +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) {
@@ -17,6 +174,326 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return nbl_res_chip_init_module (disp_mgt->res_mgt); } +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_common_info *common = disp_mgt->common; + +/* +* No core-layer lock is taken here: the resource layer serializes +* concurrent callers itself (intr_mgt->lock), and the dispatch +* layer has no mutable state of its own for this op to protect. +*/ +return nbl_res_intr_cfg_msix_map (disp_mgt->res_mgt, common->mgt_pf, + num_net_msix, num_others_msix, + net_msix_mask_en); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int +nbl_disp_chan_cfg_msix_map_req (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.num_net_msix =cpu_to_le16 (num_net_msix); + param.num_others_msix =cpu_to_le16 (num_others_msix); + param.msix_mask_en =cpu_to_le16 (!!net_msix_mask_en); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + ¶m,sizeof (param), +NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_cfg_msix_map_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + +/* +* The vector counts come from the peer PF. A peer is +* trusted: hardware and firmware forbid PF passthrough to +* guests (see nbl_get_func_param()), so every peer runs this +* same host driver, and the resource layer bounds each count +* and their sum by the per-function map table size. +* +* No per-function quota is enforced: the mailbox is an +* internal interface between instances of this same driver, +* not a boundary against untrusted code. The only outcome of +* an oversized request within those bounds is -EAGAIN for the +* functions that configure afterwards; it cannot corrupt +* state. The request's slow path (an allocation plus a +* quiesce wait under intr_mgt->lock) is bounded per request +* and sits inside the same trust boundary. +*/ + ret =nbl_res_intr_cfg_msix_map (disp_mgt->res_mgt, src_id, +le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), + !!le16_to_cpu (param.msix_mask_en)); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP ); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder retargets +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int nbl_disp_chan_destroy_msix_map_req (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , +NULL ,0 ,NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct 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; + } + ret =nbl_res_intr_destroy_msix_map (disp_mgt->res_mgt, src_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_DESTROY_MSIX_MAP ); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's own mailbox MSI-X routing (MSIX_IDX / MSIX_IDX_VALID) +* before the ACK is sent, so the ACK cannot rely on interrupt wakeup +* while routing is in flux. +*/ +static int nbl_disp_chan_set_mailbox_irq_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.vector_id =cpu_to_le16 (vector_id); + param.en_msix = !!en_msix; + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_MAILBOX_SET_IRQ , + ¶m,sizeof (param),NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_set_mailbox_irq_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u16 vector_id; +u32 rel_pf_id; +bool en_msix; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + vector_id =le16_to_cpu (param.vector_id); + en_msix = !!param.en_msix; + + ret =nbl_res_intr_set_mailbox_irq (disp_mgt->res_mgt, src_id, vector_id, + en_msix); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + +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_common_info *common = disp_mgt->common; + +return nbl_res_intr_destroy_msix_map (disp_mgt->res_mgt, common->mgt_pf); +} + +static int nbl_disp_set_mailbox_irq (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_common_info *common = disp_mgt->common; + +return nbl_res_intr_set_mailbox_irq (disp_mgt->res_mgt, common->mgt_pf, + vector_id, en_msix); +} + +static int nbl_disp_get_vsi_id (struct nbl_dispatch_mgt *disp_mgt,u16 type, +u16 *vsi_id) +{ +struct nbl_common_info *common = disp_mgt->common; + +return nbl_res_func_id_to_vsi_id (disp_mgt->res_mgt, common->mgt_pf, + type, vsi_id); +} + +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_common_info *common = disp_mgt->common; + +return nbl_res_get_eth_id (disp_mgt->res_mgt, common->mgt_pf, vsi_id, + eth_num, eth_id, logic_eth_id); +} + +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);
@@ -26,9 +503,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; } }
@@ -94,9 +584,15 @@ int nbl_disp_init(struct nbl_adapter *adapter) adapter->core.disp_mgt = disp_mgt; adapter->intf.dispatch_ops_tbl = disp_ops_tbl; + ret =nbl_disp_setup_msg (disp_mgt); +if (ret) +return ret; +if (common->has_ctrl)nbl_disp_set_ctrl_bit (disp_mgt,NBL_DISP_CTRL_LVL_MGT ); +if (common->has_net) +nbl_disp_set_ctrl_bit (disp_mgt,NBL_DISP_CTRL_LVL_NET );nbl_disp_refresh_ctrl_ops (disp_mgt);return 0 ; }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +40 -0
@@ -7,6 +7,7 @@#define _NBL_DEF_CHANNEL_H_#include <linux/types.h> +#include <linux/build_bug.h> struct nbl_channel_mgt ;struct nbl_adapter ;
@@ -30,6 +31,11 @@ typedef void (*nbl_chan_resp)(void *, u16, u16, void *, u32);*/ enum nbl_chan_msg_type {NBL_CHAN_MSG_ACK =0 , +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP =17 , +NBL_CHAN_MSG_DESTROY_MSIX_MAP =18 , +NBL_CHAN_MSG_MAILBOX_SET_IRQ =19 , +NBL_CHAN_MSG_GET_VSI_ID =21 , +NBL_CHAN_MSG_GET_ETH_ID =67 ,/* mailbox msg end */ NBL_CHAN_MSG_MAILBOX_MAX , };
@@ -39,6 +45,32 @@ enum nbl_chan_state {NBL_CHAN_STATE_NBITS }; +struct nbl_chan_param_cfg_msix_map { +__le16 num_net_msix; +__le16 num_others_msix; +__le16 msix_mask_en; +__le16 rsvd; +}; + +struct nbl_chan_param_set_mailbox_irq { +__le16 vector_id; +u8 en_msix; +u8 rsvd; +}; + +struct nbl_chan_param_get_vsi_id { +__le16 vsi_id; +__le16 type; +}; + +struct nbl_chan_param_get_eth_id { +__le16 vsi_id; +u8 eth_num; +u8 eth_id; +u8 logic_eth_id; +u8 rsvd[3 ]; +}; +struct nbl_board_port_info {u8 eth_num;u8 eth_speed;
@@ -46,6 +78,14 @@ struct nbl_board_port_info {u8 rsv[5 ]; }; +static_assert (sizeof (struct nbl_chan_param_cfg_msix_map ) ==8 , +"nbl_chan_param_cfg_msix_map size must be 8 bytes" ); +static_assert (sizeof (struct nbl_chan_param_set_mailbox_irq ) ==4 , +"nbl_chan_param_set_mailbox_irq size must be 4 bytes" ); +static_assert (sizeof (struct nbl_chan_param_get_vsi_id ) ==4 , +"nbl_chan_param_get_vsi_id size must be 4 bytes" ); +static_assert (sizeof (struct nbl_chan_param_get_eth_id ) ==8 , +"nbl_chan_param_get_eth_id size must be 8 bytes" );static_assert (sizeof (struct nbl_board_port_info ) ==8 ,"nbl_board_port_info size must be 8 bytes" );
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +42 -3
64 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 6/8] net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message says "If the resource op is not installed the responder answers -EOPNOTSUPP." No code does this.
- [Low] The kernel-doc on struct nbl_dispatch_ops says the mailbox queue must be torn down before nbl_res_remove_leonis(), via…
- [Low] The concern was that when cfg_msix_map, set_mailbox_irq or destroy_msix_map fails with a lost ACK or timeout, the hardware stays…
- [Low] The concern was that on the control PF, local cfg_msix_map (reconfigure) and destroy_msix_map turn off the function's own mailbox…
--
net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id
This patch adds request and response handlers for five dispatch
operations: cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. A control PF calls the resource helpers locally, and a has_net PF forwards the op to the management PF over the mailbox channel. The five responders are registered with the channel layer from nbl_disp_setup_msg().
Quoted 2 lines
requester can tell a protocol error from a failed operation. If the resource op is not installed the responder answers
-EOPNOTSUPP. A peer
[Severity: Low]
Is this sentence accurate? None of the five responders has an "op not installed" branch, and none of them sets err = -EOPNOTSUPP. For example, nbl_disp_chan_cfg_msix_map_resp() calls the resource helper directly:
ret = nbl_res_intr_cfg_msix_map(disp_mgt->res_mgt, src_id, ...); /* Forward the resource errno verbatim to the requester */ if (ret) err = ret;
When the resource layer can't serve the request, the helpers return -EINVAL:
nbl_res_intr_destroy_msix_map() {
if (!intr_mgt)
return -EINVAL;
...
}On these paths, -EOPNOTSUPP only comes from nbl_res_func_id_to_bdf(), where it means the func_id is not a PF present on this board.
If a msg_type has no registered handler, nbl_chan_recv_msg() logs an error and returns without sending an ACK. The requester then times out and never sees -EOPNOTSUPP:
msg_handler = xa_load(&chan_mgt->handler_xa, msg_type);
if (!msg_handler || !msg_handler->func) {
dev_err_ratelimited(dev,
"No handler for msg_type: %u (srcid=%u, msgid=%u)\n",
msg_type, srcid, msgid);
return;
}If nbl_disp_setup_msg() fails, nbl_disp_init() fails the probe, so the device can never run with an op that is not installed. This is still true at the end of the series.
Should this sentence be dropped, or is the -EOPNOTSUPP behaviour meant to be implemented?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0@@ -17,6 +174,326 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return nbl_res_chip_init_module (disp_mgt->res_mgt); }
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11
-0+/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int +nbl_disp_chan_cfg_msix_map_req (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 222
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +9
-0+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 ; +}
[Severity: Low]
Suppose send_msg() returns -ETIMEDOUT because the ACK was lost. Could the responder already have committed the new map in nbl_res_intr_cfg_msix_map() and armed the hardware? This helper only passes the error up, so undoing the change is left to the caller. The set_mailbox_irq and destroy_msix_map requests have the same issue.
Nothing calls these helpers in this patch. Later in the series, "net/nebula-matrix: add common dev start/stop operation" handles this. nbl_dev_start() jumps to err_destroy_map on any cfg_msix_map, get_vsi_id or get_eth_id failure, and that path always calls nbl_dev_destroy_msix_map(). A failed set_mailbox_irq enable goes through err_free_irq -> err_destroy_map. So this looks resolved by the end of the series.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 42
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +8
-0@@ -31,16 +32,54 @@ enum {* mailbox DMA before calling it. * Returns void. Control-PF exclusive, same NULL rule as * @init_module. +* @cfg_msix_map: configure function msix mapping table. On a non-control +* PF this is an RPC, and the caller must have cleared +* NBL_CHAN_IRQ_RDY and switched the channel to its polling +* send path first: the responder rewrites this function's +* mailbox MSI-X routing, so the ACK cannot depend on the +* interrupt being reprogrammed. +* @destroy_msix_map: tear down msix mapping resource. Same caller +* precondition as @cfg_msix_map.
[Severity: Low]
As written, the IRQ_RDY/polling precondition seems to apply only to a non-control PF. On the control PF, nbl_disp_cfg_msix_map() and nbl_disp_destroy_msix_map() call the resource layer directly.
A reconfiguration (had_config) in nbl_res_intr_cfg_msix_map() turns off the function's own mailbox routing and does not restore it:
if (had_config) {
...
ret = __nbl_res_intr_set_mailbox_irq(intr_mgt, res_mgt, func_id,
0, false);Destroy does the same. If NBL_CHAN_IRQ_RDY were still set at that point, could the control PF stop receiving mailbox interrupts?
This isn't reached anywhere in the series:
- The control PF's only cfg_msix_map is the first configuration in nbl_dev_start(), where had_config is false.
- Its destroy_msix_map runs in nbl_dev_stop() after nbl_dev_disable_mailbox_irq() has cleared IRQ_RDY.
- When a peer is reconfigured, nbl_dev_start() calls set_mailbox_irq(true) to re-arm routing before IRQ_RDY is set.
Could the kernel-doc say that the precondition also applies to the local path? It could also say that mailbox routing stays disabled until set_mailbox_irq() re-arms it.
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 57
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +9
-2* These callbacks are not dispatch-layer setup/teardown: the dispatch -* structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove() -* only documents why no explicit teardown is needed. They forward +* structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove() +* has nothing to undo. The five responders registered by +* nbl_disp_setup_msg() live in the channel layer's handler xarray and go +* away with it, so they need no explicit unregistration either. Nothing +* can enter them until a mailbox queue is running, and a queue must be +* torn down before nbl_res_remove_leonis() runs: nbl_chan_teardown_queue() +* stops the RX path and nbl_chan_remove_common() frees the handler nodes, +* so once the resource layer starts disappearing there is no responder +* left that could still be running, or be entered. They forward
[Severity: Low]
This isn't a bug, but the ordering described here doesn't match nbl_core_remove(). The handler nodes are freed after the resource layer is removed:
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);
}Also, nothing calls ->teardown_queue in this patch.
The RX-stop part does hold at the end of the series. "net/nebula-matrix: add common/ctrl dev init/remove operation" makes nbl_dev_remove() the first step of nbl_core_remove(). That path calls nbl_dev_remove_common_dev()->nbl_dev_remove_chan_queue()->teardown_queue() before nbl_res_remove_leonis() runs.
Could the comment be reworded so it doesn't say nbl_chan_remove_common() runs before nbl_res_remove_leonis()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 7/8 net/nebula-matrix: add common/ctrl dev init/remove operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev.c, nbl_dev.h and nbl_def_dev.h to host device-level initialization and teardown logic, and wire the new nbl_dev_init() / nbl_dev_remove() entry points into core init/remove.
Common device setup allocates per-device state, initializes the mailbox cleanup work and creates the mailbox channel queue. VSI/ETH identity lookup and MSI-X vector allocation are deferred to the subsequent start routine, which is the only place that consumes them: the IDs feed the MSI-X and queue setup. Responder readiness is not the reason for the deferral - nbl_probe_chip_deps() already holds a sibling in -EPROBE_DEFER until function 0 has finished probing - but deferring does keep this commit probeable on its own, without depending on a peer's start path.
Control-PF-only setup invokes chip-level module initialization and programs the mailbox QINFO routing table entries that map PF bus/devid to the mailbox queue.
Init/teardown ordering is dictated by a hardware constraint rather than by strict symmetry. Init: program mailbox QINFO (control PF only), create the mailbox queue, then run control device init_module. Teardown:
stop the mailbox channel and drain all in-flight DMA first, then call deinit_module(). This ordering prevents the firmware from reclaiming the routing under a live transfer, which would leave the device DMAing into released memory.
The firmware reclaims per-PF state (mailbox QINFO routing, qinfo registers and the like) asynchronously once driver status is marked inactive. It does not revert the chip-wide datapath registers configured by init_module; those stay valid until chip reset (see nbl_hw_deinit_module()). The device link created during non-control PF probe makes the driver core unbind all sibling PFs before the control PF is removed.
Programming the mailbox queue hands DMA descriptors to the device, so bus mastering has to be enabled in this path rather than after nbl_core_init() returns. It must still stay off while the resource layer scrubs the stale FUNCTION_MSIX_MAP entries, so nbl_core_init() enables it between nbl_res_init_leonis() and nbl_dev_init().
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 311 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 ++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 22 +- .../nbl/nbl_include/nbl_def_dev.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 38 ++- 7 files changed, 436 insertions(+), 6 deletions(-) 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
@@ -24,6 +24,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 +311 -0
311 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h new file +55 -0
55 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +21 -1
@@ -599,5 +599,25 @@ int nbl_disp_init(struct nbl_adapter *adapter)void nbl_disp_remove (struct nbl_adapter *adapter) { -/* Dispatch structures are allocated via devm */ +/* +* Dispatch structures are devm-allocated and freed at detach. +* +* The five responders registered by nbl_disp_setup_msg() are +* owned by the channel layer (xarray of handlers) and are never +* unregistered here. This is safe because the teardown order +* guarantees no responder can run after this point: +* +* mailbox teardown +* -> cancel_work_sync(clean_mbx_task) // drain RX work +* -> nbl_chan_teardown_queue() // stop HW queue, +* // join clean task, +* // active=false +* -> nbl_chan_remove_common() +* -> nbl_common_destroy_wq() // no new work +* -> nbl_chan_remove_msg_handler() // free handler nodes +* +* By the time devres frees disp_mgt, the mailbox queue is stopped +* and the handler xarray is empty, so no responder can touch +* res_mgt->intr_mgt after nbl_intr_mgt_stop() has cleared it. +*/ }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
@@ -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 +33 -5
@@ -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,27 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_disp_init (adapter);if (ret) goto out_res_remove; + +/* +* Arm bus mastering before nbl_dev_init() hands the mailbox queues +* to the hardware: it writes the ring addresses, sets QUEUE_EN and +* rings the RX tail doorbell, and the device cannot fetch those +* descriptors with Bus Master Enable clear - nothing re-kicks the +* queue afterwards. This is the first point where it is safe to +* turn it on, because the MSI-X map scrub that must run with DMA +* off (nbl_intr_setup_mgt(), called from nbl_res_init_leonis() +* above) has already completed; see the comment in nbl_probe(). +*/ +pci_set_master (pdev); + + ret =nbl_dev_init (adapter); +if (ret) + goto out_clear_master;return adapter; + +out_clear_master: +pci_clear_master (pdev); +nbl_disp_remove (adapter); out_res_remove:nbl_res_remove_leonis (adapter); out_chan_remove:
@@ -66,6 +87,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_dev_remove (adapter);nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);
@@ -270,7 +292,9 @@ static int nbl_probe(struct pci_dev *pdev,dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));/* -* Bus mastering is enabled only after nbl_core_init() returns. +* Bus mastering stays off until the resource layer has scrubbed +* FUNCTION_MSIX_MAP; nbl_core_init() runs that scrub and only then +* enables it, right before the mailbox queues are armed. * * FUNCTION_MSIX_MAP survives a kexec or a forced unload without * FLR and there is no .shutdown callback to scrub it, so at this
@@ -281,17 +305,21 @@ static int nbl_probe(struct pci_dev *pdev,* reused memory is Bus Master Enable, which the PCI core cleared * on the way into this kernel. nbl_intr_setup_mgt() invalidates * the entries from inside nbl_core_init(); enabling bus mastering -* before that would re-open the window. Everything up to that -* point is host-side setup plus MMIO and nothing in it waits for -* the device, so it does not need bus mastering. +* before that would re-open the window. What must not run with it +* off either is nbl_dev_init(), which hands the mailbox rings to +* the device, so nbl_core_init() turns it on between the two. */ adapter =nbl_core_init (pdev, ¶m);if (IS_ERR (adapter)) {dev_err (dev,"Nbl adapter init fail: %pe\n" , adapter); +/* +* nbl_core_init() enables bus mastering before its last +* step, which is the one that failed. +*/ +pci_clear_master (pdev);return PTR_ERR (adapter); } -pci_set_master (pdev);pci_set_drvdata (pdev, adapter);return 0 ;
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove operation
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] nbl_core_init() turns on Bus Master Enable (pci_set_master(), nbl_main.c line 68) before anything quiesces the mailbox TX/RX…
- [Low] The comment and the extra pci_clear_master() in the nbl_core_init() error branch of nbl_probe()…
- [Low] Two comments describe the remove path in an order that nbl_core_remove() does not follow.
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This adds nbl_dev_init() and nbl_dev_remove(). They set up the mailbox clean work and channel queue, and on the control PF they also program the mailbox QINFO routing and run init_module. The patch wires them into nbl_core_init()/nbl_core_remove() and moves pci_set_master() from nbl_probe() into nbl_core_init(), just before nbl_dev_init().
Quoted 20 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11
-1@@ -599,5 +599,25 @@ int nbl_disp_init(struct nbl_adapter *adapter)void nbl_disp_remove (struct nbl_adapter *adapter) { -/* Dispatch structures are allocated via devm */ +/* +* Dispatch structures are devm-allocated and freed at detach. +* +* The five responders registered by nbl_disp_setup_msg() are +* owned by the channel layer (xarray of handlers) and are never +* unregistered here. This is safe because the teardown order +* guarantees no responder can run after this point: +* +* mailbox teardown +* -> cancel_work_sync(clean_mbx_task) // drain RX work +* -> nbl_chan_teardown_queue() // stop HW queue,
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c int nbl_disp_init(struct nbl_adapter *adapter) · line 622
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +10
-0+* // join clean task, +* // active=false +* -> nbl_chan_remove_common() +* -> nbl_common_destroy_wq() // no new work +* -> nbl_chan_remove_msg_handler() // free handler nodes +* +* By the time devres frees disp_mgt, the mailbox queue is stopped +* and the handler xarray is empty, so no responder can touch +* res_mgt->intr_mgt after nbl_intr_mgt_stop() has cleared it. +*/
[Severity: Low]
Is this the order nbl_core_remove() actually uses? The comment concludes that the handler xarray is empty, so no responder can touch res_mgt->intr_mgt after nbl_intr_mgt_stop() has cleared it.
Here is nbl_core_remove() after this patch:
nbl_dev_remove(adapter); nbl_disp_remove(adapter); nbl_res_remove_leonis(adapter); nbl_chan_remove_common(adapter);
nbl_res_remove_leonis()->nbl_intr_mgt_stop() sets res_mgt->intr_mgt to NULL. That happens before nbl_chan_remove_common() calls nbl_common_destroy_wq() and nbl_chan_remove_msg_handler(). So at that point all five responders are still in the handler xarray, and common->wq still exists.
What actually keeps responders from running is the stopped mailbox queue in nbl_chan_teardown_queue(): shutdn, RX QUEUE_RST and the cancelled clean_task. Nothing breaks today.
The struct nbl_dispatch_ops kernel-doc in nbl_def_dispatch.h makes the same claim:
* torn down before nbl_res_remove_leonis() runs: nbl_chan_teardown_queue()
* stops the RX path and nbl_chan_remove_common() frees the handler nodes,
* so once the resource layer starts disappearing there is no responder
* left that could still be running, or be entered.
Could both comments be changed to describe the real order? They are unchanged at the end of the series.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0}drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +2
-0@@ -53,7 +54,27 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_disp_init (adapter);if (ret) goto out_res_remove; + +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, · line 68
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+* Arm bus mastering before nbl_dev_init() hands the mailbox queues +* to the hardware: it writes the ring addresses, sets QUEUE_EN and +* rings the RX tail doorbell, and the device cannot fetch those +* descriptors with Bus Master Enable clear - nothing re-kicks the +* queue afterwards. This is the first point where it is safe to +* turn it on, because the MSI-X map scrub that must run with DMA +* off (nbl_intr_setup_mgt(), called from nbl_res_init_leonis() +* above) has already completed; see the comment in nbl_probe(). +*/ +pci_set_master (pdev);
[Severity: Medium]
Can a mailbox queue that a previous kernel left enabled start DMAing as soon as bus mastering is turned on here?
This comment only covers the FUNCTION_MSIX_MAP scrub. The mailbox TX/RX QINFO_CFG entries (ring base, size and QUEUE_EN) are the same kind of state. They survive kexec, or an unload that never reached deinit_module(), and there is no .shutdown callback.
During probe, QUEUE_RST is not asserted until later:
nbl_dev_init()
nbl_dev_setup_common_dev()
nbl_dev_setup_chan_queue()
nbl_chan_setup_queue()
nbl_chan_init_queue() <- coherent ring/buffer allocations
nbl_chan_config_queue(tx)
nbl_hw_config_mailbox_txq()
nbl_chan_config_queue(rx)
nbl_hw_config_mailbox_rxq()
The RX entry is only reset after the TX entry has been reprogrammed.
Before this point, the only stale-state handling is nbl_hw_clear_stale_status():
- it runs only on the control PF
- it runs only when driver_status is still set
- it then sleeps 2-3ms while firmware reclaims the state asynchronously
The comment above NBL_FW_CLEANUP_SYNC_MIN_US says:
A firmware pass that takes longer than this window - an ECPU still busy right after kexec, say - can therefore still race a later probe.
Suppose that reclaim has not finished, or does not cover an entry. Before QUEUE_RST lands, could the device then do any of these?
- fetch stale TX descriptors
- write an incoming message into an old RX buffer address
- write descriptor USED flags into memory the new kernel now owns
Would it make sense to assert QUEUE_RST and clear the base of both mailbox QINFO_CFG entries before pci_set_master()? That is what nbl_hw_stop_mailbox_rxq()/txq() do, with the read-back flush, and it is MMIO only, so it does not need bus mastering.
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +8
-0+ + ret =nbl_dev_init (adapter); +if (ret) + goto out_clear_master;return adapter; + +out_clear_master: +pci_clear_master (pdev); +nbl_disp_remove (adapter); out_res_remove:nbl_res_remove_leonis (adapter); out_chan_remove:
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0@@ -281,17 +305,21 @@ static int nbl_probe(struct pci_dev *pdev,
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 319
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +5
-0adapter =nbl_core_init (pdev, ¶m);if (IS_ERR (adapter)) {dev_err (dev,"Nbl adapter init fail: %pe\n" , adapter); +/* +* nbl_core_init() enables bus mastering before its last +* step, which is the one that failed. +*/ +pci_clear_master (pdev);
[Severity: Low]
Is this comment accurate? Five of the failure exits in nbl_core_init() return before pci_set_master() runs:
- devm_kzalloc_obj()
- nbl_hw_init_leonis()
- nbl_chan_init_common()
- nbl_res_init_leonis()
- nbl_disp_init()
The one remaining exit is an nbl_dev_init() failure. nbl_core_init() already clears bus mastering for it at its own out_clear_master label:
out_clear_master:
pci_clear_master(pdev); nbl_disp_remove(adapter);
So this pci_clear_master() either clears a bit that was never set or clears it a second time. That is harmless at runtime, but the comment suggests nbl_probe() owns the bus master unwind for nbl_core_init().
Could the comment and the extra call be removed? They are still present at the end of the series.
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0return PTR_ERR (adapter); }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v35 8/8 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev_start() and nbl_dev_stop(), called from nbl_probe() and nbl_remove() via nbl_core_start() / nbl_core_stop().
Start configures the device MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt; stop performs the matching teardown.
nbl_probe() now rejects a function with neither the ctrl nor the net capability with -EOPNOTSUPP, before any hardware is touched. Such a function would reach nbl_dev_start() with every dispatch op left NULL by nbl_disp_refresh_ctrl_ops(). The state is only reachable throughdriver_override: binding this driver to a function that is absent from nbl_id_table makes pci_match_device() pass the dummy ID whose driver_data 0 leaves both capabilities clear. That means a VF, or a foreign device at a function other than 0 - a PF of this device always matches nbl_id_table, and new_id rejects a driver_data the table does not contain. A foreign non-VF device at function 0 is unaffected:nbl_get_func_param() gives it has_ctrl, so it is not rejected here and still runs nbl_core_init() and nbl_core_start() with the local control dispatch ops. nbl_dev_init()'s unwind labels change with it:setup_ctrl_dev_fail becomes out_remove_common_dev, and the setup_err path drops its label and returns directly, since a failed nbl_dev_setup_common_dev() has nothing to unwind.
Startup RPC errors are propagated unchanged. A -ETIMEDOUT here is a real failure, not a "supplier not ready yet" condition: nbl_probe() already deferred this PF in nbl_probe_chip_deps() until the control PF reached DL_DEV_DRIVER_BOUND, and the driver core only marks a device bound once its entire probe - including the control PF's own nbl_core_start() - has returned. That state is what bounds the wait, not nbl_dev_init(): on the control PF inbound mailbox work only runs from clean_mbx_task, which is queued by the mailbox hardirq, by the task's own self-requeue, or by this function's polling sends, and the control PF uses the local dispatch ops so it sends none. The responder is armed by set_mailbox_irq(true) at the end of the peer's nbl_dev_start(). Relaxing the dependency to "func 0 finished nbl_dev_init()" would therefore let every sibling RPC sit out the full 5-6s polling wait. Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay that wait again.
Teardown releases the kernel MSI-X vectors before destroying the hardware pcompleter map. pci_free_irq_vectors() ends in pci_msix_shutdown(), which masks every descriptor by writing the MSI-X table and reading it back to flush the write; those accesses should reach the function while FUNCTION_MSIX_MAP is still valid. This mirrors start, where cfg_msix_map runs before pci_alloc_irq_vectors_affinity(). It is not a double free of the pcim_msi_release devres registered alongside pci_alloc_irq_vectors(): that action only calls pci_free_irq_vectors() again, and pci_disable_msix() returns early once msix_enabled is clear. Start and stop still each run once, tied to probe and remove.
The rest of teardown is best-effort. The MSI-X map is torn down even when the configure RPC failed: a timeout only means the ACK never arrived, while the responder runs to completion before ACKing, so the entry, the intr_net/other_bmap bits and the kcalloc()ed vector array stay owned by the control PF. Those are host resources of that driver, not firmware state, and neither recovery path needs a chip reset: a later successful configuration of this function releases the old bits, frees the old array, invalidates and rewrites the entry on its had_config path, and nbl_intr_mgt_stop() clears the FUNCTION_MSIX_MAP valid bit for every still-configured function when the control PF is removed. The coherent map table is different: it is kept for the function's lifetime and reused in place, and nbl_intr_mgt_stop() is the only place a table the pcompleter has been given is released - the rollback inside nbl_res_intr_cfg_msix_map() only frees a table that the same call allocated, before its map entry is armed.
That is also what keeps the stop ordering safe. nbl_remove() calls nbl_core_stop() before pci_clear_master(), so the control PF destroys its own map entry while its Bus Master Enable is still set. That is
deliberate: nbl_core_stop() cannot run after pci_clear_master(), because on a non-control PF it is a mailbox RPC, which needs bus mastering for the ring DMA. The destroy only clears the VALID bit and keeps the coherent table, so the actual free still happens later, in nbl_intr_mgt_stop(), after pci_clear_master(). nbl_probe()'s start-failure unwind uses the same order. pci_clear_master() remains no safety net for a non-control PF: it cannot stop DMA issued with the management PF's BDF.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 11 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 454 +++++++++++++++++- .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 4 +- .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 49 +- 5 files changed, 512 insertions(+), 8 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +11 -0
@@ -39,4 +39,15 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, struct nbl_init_param *param);void nbl_core_remove (struct nbl_adapter *adapter); +/* +* Single-shot start/stop pair, called once each from PCI probe/remove. +* Not repeatable, but not because the MSI-X core would refuse a second +* start: nbl_dev_stop() releases the vectors with pci_free_irq_vectors(). +* What the pair brackets is the device's active lifetime, and +* nbl_core_stop() is only ever followed by nbl_core_remove(), which +* destroys the mailbox channel and the resource state that start needs. +*/ +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 +450 -4
495 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c +2 -2
@@ -359,8 +359,8 @@ int nbl_res_intr_destroy_msix_map(struct nbl_resource_mgt *res_mgt,* configuration intact). The bitmap pools are therefore sized for peak, * not maximum, concurrent use: a reconfigure of the same or a smaller * size still fails with -EAGAIN when the pool is nearly exhausted. The -* in-tree caller asks for one non-net vector per PF, far below -* NBL_MAX_OTHER_INTERRUPT. +* in-tree caller (nbl_dev_cfg_msix_map(), from nbl_dev_start()) asks for +* one non-net vector per PF, far below NBL_MAX_OTHER_INTERRUPT. * * Serialization: this function takes intr_mgt->lock internally to * protect the global vector bitmaps and per-function state against
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 +47 -2
79 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v35 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message and the new comments argue against earlier review feedback more than they describe this change.
- [Low] This patch adds a third queue_work() site for the mailbox clean
task: the hardirq handler nbl_dev_clean_mailbox() calls…
- [Low] A comment in nbl_dev_setup_common_dev() (added earlier in this series by commit "net/nebula-matrix: add common/ctrl dev init/remove…
--
net/nebula-matrix: add common dev start/stop operation
This commit adds nbl_dev_start() and nbl_dev_stop(). They are called from nbl_probe() and nbl_remove() through nbl_core_start() and nbl_core_stop().
Start configures the MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt. Stop undoes these steps.
nbl_probe() now also rejects a function that has neither the ctrl nor the net capability.
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@@ -19,6 +30,247 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+static int nbl_dev_disable_mailbox_irq (struct nbl_dev_mgt *dev_mgt) +{
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +5
-0+ lvec = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].base_vector_id; +/* +* Disable sequence invariant: clear the software READY flag first, +* then mask the hardware interrupt. Must not reverse the order. +*
[ ... ]
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 141
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +9
-0+* This does NOT preserve in-flight ACKs, and must not be described +* as doing so: the woken sender gives up and resets its slot to +* IDLE, so an ACK arriving afterwards finds a non-WAITING slot and +* is dropped by the receive path ("Skip ack invalid status"). +* Interrupt mode is being torn down here; the guarantee is a +* bounded, deterministic failure, not delivery. In this driver +* every ACK-requesting sender runs from probe/remove and the clean +* task only sends ACK-less replies, so nothing depends on the +* stronger claim today.
[Severity: Low]
This isn't a bug, but could this comment be cut down to just the invariant? Wording like "must not be described as doing so" reads like a reply to earlier review, not documentation of the code.
The same thing happens in a few other places in this patch.
The comment at the top of nbl_dev_start() repeats the commit message's argument for -ETIMEDOUT over -EPROBE_DEFER.
The lifetime of the control PF's MSI-X resources is explained three
times: in the commit message, at the err_destroy_map label in nbl_dev_start(), and again in nbl_dev_stop(). This covers the had_config path, the coherent table being kept, and nbl_intr_mgt_stop() being the only release.
Those comments also describe the internals of functions in nbl_interrupt.c:
__nbl_res_intr_prepare_destroy_msix_map()
__nbl_res_intr_complete_destroy_msix_map()
the rollback in nbl_res_intr_cfg_msix_map()
nbl_intr_mgt_stop()
Won't these comments go stale without anyone noticing when those functions change?
Most of the commit message is also about alternatives that were not taken, for example:
Relaxing the dependency to
"func 0 finished nbl_dev_init()" would therefore let every sibling RPC sit out the full 5-6s polling wait. Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay that wait again.
The same goes for the pcim_msi_release double free discussion and the driver_override paths. Could the changelog focus on what start and stop actually do?
The label rename in nbl_dev_init() (setup_ctrl_dev_fail becomes out_remove_common_dev, and setup_err is dropped) is not related to start/stop. Would it fit better in a separate patch?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_clean_mailbox_task(struct work_struct *work) · line 347
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +7
-0@@ -86,6 +338,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work) NBL_CHAN_TYPE_MAILBOX); } +static void nbl_dev_clean_mailbox_schedule (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *common_dev = dev_mgt->common_dev; +struct nbl_common_info *common = dev_mgt->common; + +queue_work (common->wq, &common_dev->clean_mbx_task); +}
[Severity: Low]
This adds a third queue_work() site for clean_mbx_task, called from the nbl_dev_clean_mailbox() hardirq handler. The invariant comment in the channel layer still says there are only two:
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c:nbl_chan_teardown_queue() {
...
* Nothing can be queued once Step 1 has run: both queue_work()
* sites (the sender's ACK poll and the worker's own self-requeue)
* check shutdn and clean_task under state_lock, and Step 1 cleared
* both.
...
}
The new site checks neither shutdn nor clean_task, and it cannot take the state_lock mutex from hardirq context. It also skips the common->wq check that nbl_chan_send_msg() makes before calling queue_work().
The invariant still holds today, but only because the device layer frees the mailbox IRQ first. nbl_dev_stop() calls nbl_dev_free_mailbox_irq() before the channel is torn down in nbl_core_remove()->nbl_dev_remove_common_dev(). The nbl_dev_start() rollback frees the IRQ at err_free_irq.
Should the comment in nbl_chan_teardown_queue() list the hardirq site? Should it also say that the invariant depends on the IRQ being freed before teardown_queue() runs? This patch's commit message already lists three sources ("queued by the mailbox hardirq, by the task's own self-requeue, or by this function's polling sends").
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0@@ -309,3 +569,189 @@ 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) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 615
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +12
-0+ ret =nbl_dev_cfg_msix_map (dev_mgt); +if (ret) + goto err_destroy_map; + +/* Fetch VSI/ETH identity after cfg_msix_map */ + ret = disp_ops->get_vsi_id (priv,NBL_VSI_DATA , &common->vsi_id); +if (ret) + 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) + goto err_destroy_map;
[Severity: Low]
Does this match the comment that an earlier patch in this series added to nbl_dev_setup_common_dev()?
/*
* VSI/ETH identity is deliberately not fetched here but in the
* start path, which is where it is used: the IDs only feed MSI-X
* and queue setup.
Here the IDs are fetched after nbl_dev_cfg_msix_map(), and the cfg_msix_map dispatch op takes no VSI/ETH input:
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h:
int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt, u16 num_net_msix, u16 num_others_msix, bool net_msix_mask_en);
The series has no queue setup yet either. As far as I can tell, common->vsi_id, eth_id, eth_num and logic_eth_id are written here and never read. The one exception is vsi_id, which is passed to get_eth_id.
Even so, a failure from either RPC still aborts probe through err_destroy_map. For example, nbl_res_get_eth_id() can return an error for a PF/VSI mismatch or when rel_pf_id >= eth_num.
Should the fetch move to the patch that uses these IDs? If not, should the comment in nbl_dev_setup_common_dev() be corrected?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com