nbl driver for Nebulamatrix NICs
illusion.wang
maintainerv32 cover nbl driver for Nebulamatrix NICs
From: illusion wang <[email protected]>
This series continues and refines the previous v28 NBL NIC driver patch set for Nebula-matrix m18110/m18000 (SNIC s1000) Ethernet adapters.
The first two foundational patches of v28 have been merged into net-next main branch:
- net/nebula-matrix: add minimum nbl build framework (cffde9e49e86)
- net/nebula-matrix: add core driver architecture and HW layer initialization (825e6d230163)
Following maintainer feedback to shorten the patch series, this iteration drops the two merged commits, reorganizes and polishes the remaining functionality into a standalone 8-patch sequence. No new features are added; this series only completes the pending core infrastructure.
The overall driver development plan remains consistent with the v28 two-phase roadmap:
1) Complete hardware initialization, mailbox/channel communication and control-plane infrastructure (this series)
2) Implement netdev registration and TX/RX data-path functionality (follow-up series)
This patch set supplements the merged foundational code, covering channel layer abstraction, resource management, interrupt handling, chip-level initialization, control dispatch routing, channel RPC framework, and device lifecycle init/remove/start/stop logic.
changes v31->v32
Link to v31:https://lore.kernel.org/netdev/[email protected]/ changes v30->v31
Link to v30:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v29->v30
Link to v29:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
changes v28->v29
Link to v28:https://lore.kernel.org/netdev/[email protected]/ 1.AI review issues
2.remove the hash table implementation
illusion wang (8):
net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation net/nebula-matrix: add intr resource implementation net/nebula-matrix: add chip-wide hardware init/deinit implementation net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: implement channel RPC framework and
serialize hardware ops
net/nebula-matrix: add common/ctrl dev init/remove operation net/nebula-matrix: add common dev start/stop operation
.../net/ethernet/nebula-matrix/nbl/Makefile | 10 +- .../nbl/nbl_channel/nbl_channel.c | 1522 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 196 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 52 + .../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 20 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 686 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 671 ++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 1254 +++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 322 ++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 364 ++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 12 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 33 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 826 +++++++++ .../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 | 151 ++ .../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 | 79 + .../nbl/nbl_include/nbl_def_hw.h | 82 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 28 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 206 ++- 29 files changed, 7062 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_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v32 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).
- Each ring uses one contiguous coherent DMA block sliced into fixed-size slots, so a channel costs one devres node and one IOMMU mapping per ring instead of one per slot.
- Mailbox queue resources are devm-managed and the DMA is allocated once during setup. There is no free path, so a channel is set up exactly once per device lifetime and teardown is terminal for it; a re-setup is rejected with -EBUSY.
- RX is driven either from the interrupt or by polling, with cleanup offloaded to a workqueue. Teardown quiesces both queues before the rings can be freed.
- Register access goes through hw_ops. The reg_lock spinlock covers BAR0 register access only; BAR2 mailbox registers and the doorbell write do not take it.
This patch also adds nbl_probe_chip_deps() and calls it from nbl_probe() before nbl_core_init(). For every PF that is not the physical function 0 (has_ctrl == 0) it resolves function 0 in the same slot and:
- fails the probe with -ENODEV if function 0 is absent, and also when the lookup resolves to this device itself: a VF is never the management PF, yet under ARI its devfn decodes to function 0 of a slot;
- returns -EPROBE_DEFER unless function 0 is bound to *this* driver with its probe completed. Testing links.status == DL_DEV_DRIVER_BOUND alone would also accept function 0 on vfio-pci or pci-stub through driver_override, where the chip-global setup this PF depends on never ran, so the bound driver is compared as well;
- creates a persistent DL_FLAG_AUTOPROBE_CONSUMER device link, so the driver core unbinds every sibling PF before function 0 goes away and re-probes them when function 0 binds again.
Function 0's device lock is only ever taken with device_trylock(): this probe already runs under device_lock(funcN), so a blocking device_lock(func0) would establish the N -> 0 order while __pci_bus_lock() (AER recovery, slot reset) walks the bus in devfn order, 0 -> N, and dev->mutex is lockdep_set_novalidate_class() so lockdep cannot report the inversion. A failed trylock defers the probe. The link is created while that lock is still held, so function 0 can neither bind nor unbind in between.
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 | 1522 +++++++++++++++++ .../nbl/nbl_channel/nbl_channel.h | 196 +++ .../nebula-matrix/nbl/nbl_common/nbl_common.c | 30 + .../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 7 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 299 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 41 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 32 + .../nbl/nbl_include/nbl_def_channel.h | 125 ++ .../nbl/nbl_include/nbl_def_common.h | 3 + .../nbl/nbl_include/nbl_def_hw.h | 44 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 148 +- 14 files changed, 2450 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 +1522 -0
1,522 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h new file +196 -0
196 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#include <linux/device.h> +#include "nbl_common.h" + +void nbl_common_destroy_wq (struct nbl_common_info *common) +{ +if (!common || !common->wq) +return ; + +destroy_workqueue (common->wq); + common->wq =NULL ; +} + +int nbl_common_create_wq (struct nbl_common_info *common) +{ +char wq_name[32 ]; + +snprintf (wq_name,sizeof (wq_name),"nbl_wq_%s" ,pci_name (common->pdev)); + common->wq =alloc_workqueue (wq_name,WQ_UNBOUND ,0 ); +if (!common->wq) { +dev_err (common->dev,"Failed to alloc workqueue %s\n" , wq_name); +return -ENOMEM ; + } + +return 0 ; +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h new file +14 -0
@@ -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 +44 -0
50 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 +143 -5
197 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 1/8] net/nebula-matrix: add channel layer
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] In nbl_probe_chip_deps(), a failed device_trylock(&mgt->dev) is turned into -EPROBE_DEFER, on the assumption that a later bind of…
- [Low] The comments in nbl_chan_cfg_qinfo_map_table() and the get_host_pf_mask kernel-doc say pf_mask is validated by…
- [Low] The commit message says 'a channel costs one devres node and one IOMMU mapping per ring', and the code comment in…
--
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 rings backed by coherent DMA, an xarray of message handlers and ACK wait slots. It also adds nbl_probe_chip_deps(), which defers non-management PFs until function 0 is bound to this driver, and links each of them to function 0 with a device link.
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0@@ -0,0 +1,1522 @@
[ ... ]
Quoted 26 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +26
-0+static int nbl_chan_init_tx_queue (struct nbl_common_info *common, +struct nbl_chan_info *chan_info) +{ +struct nbl_chan_ring *txq = &chan_info->txq; +struct device *dev = common->dev; +dma_addr_t base_dma; +size_t size = + chan_info->num_txq_entries *sizeof (struct nbl_chan_tx_desc ); +void *base; +u16 i; + + txq->desc.tx_desc =dmam_alloc_coherent (dev, size, &txq->dma, +GFP_KERNEL ); +if (!txq->desc.tx_desc) +return -ENOMEM ; + +/* +* All per-entry buffers come from one contiguous coherent block, so a +* ring costs exactly one allocation, one devres node and one IOMMU +* mapping whatever the page size is. Per-entry dmam_alloc_coherent() +* instead rounds every NBL_CHAN_BUF_LEN buffer up to a whole page +* (8 MiB per PF on 16 KiB pages, 32 MiB on 64 KiB pages), and a +* dma_pool only fixes the large-page case: with NBL_CHAN_BUF_LEN equal +* to PAGE_SIZE it still degenerates to one allocation per buffer on +* 4 KiB pages. NBL_CHAN_BUF_LEN is a power of two, so the block +* always divides evenly into per-entry slots.
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 118
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+*/ + base =dmam_alloc_coherent (dev, + chan_info->num_txq_entries * + chan_info->txq_buf_size, + &base_dma,GFP_KERNEL ); +if (!base) +return -ENOMEM ; + + chan_info->wait =devm_kcalloc (dev, chan_info->num_txq_entries, +sizeof (*chan_info->wait),GFP_KERNEL );
[Severity: Low]
This isn't a bug, but is the "exactly one allocation, one devres node and one IOMMU mapping" wording accurate for a ring?
This function calls dmam_alloc_coherent() twice, once for the descriptor ring and once for the buffer block. It also makes devm_kcalloc() calls for chan_info->wait and txq->buf. nbl_chan_init_rx_queue() likewise makes two dmam_alloc_coherent() calls plus a devm_kcalloc() for rxq->buf.
The commit message makes the same claim:
Each ring uses one contiguous coherent DMA block sliced into fixed-size slots, so a channel costs one devres node and one IOMMU mapping per ring instead of one per slot.
Could both say that this only applies to the per-slot data buffers?
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +9
-0+static void nbl_chan_cfg_qinfo_map_table (struct nbl_channel_mgt *chan_mgt, +u8 bus,u8 devid) +{ +struct nbl_hw_ops *hw_ops = chan_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *p = chan_mgt->hw_ops_tbl->priv; +u32 pf_mask =0 ; +u8 func_id; + +/*
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 273
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+* k_pf_mask rule: bit N == 0 means PF#N enabled, bit N == 1 masked out. +* Program mailbox QINFO entry for each hardware-active PF func_id. +* +* Note: This loop iterates over the raw hardware PF func_id. +* Product constraints limit supported PF counts to the contiguous +* sets PF0, PF0~1 and PF0~3. The mask is validated by +* nbl_res_init_pf_num() in the resource layer, which runs before +* this call and rejects any other mask with -EINVAL, so pf_mask +* here is always one of 0xfe/0xfc/0xf0. +*/
[Severity: Low]
This isn't a bug, but nbl_res_init_pf_num() and the resource layer do not exist yet at this commit. They arrive later in the series. The get_host_pf_mask kernel-doc added to nbl_def_hw.h makes the same ordering claim.
cfg_chan_qinfo_map_table() has no caller here yet, and once the whole series is applied the described ordering does hold. Could these comments move into the patch that adds nbl_res_init_pf_num(), or be reworded so they are accurate at this point in the series?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9
-0+/* +* func 0's device lock is taken with a trylock. This probe already +* runs under device_lock(funcN), so a blocking device_lock(func0) +* would establish the N -> 0 order, while __pci_bus_lock() (AER +* recovery, slot reset) walks the bus in devfn order, i.e. 0 -> N, +* and dev->mutex is lockdep_set_novalidate_class(), so lockdep +* cannot report that inversion. A trylock never blocks, so it +* cannot take part in a deadlock cycle; failing it defers this +* probe.
[ ... ]
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 157
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +4
-0+if (!device_trylock (&mgt->dev)) { +pci_dev_put (mgt); +return -EPROBE_DEFER ; + }
[Severity: Medium]
Can a failed trylock here leave the sibling PF deferred with nothing to retry it later?
When func 0 binds, really_probe()->driver_bound() runs with device_lock(func0) held. device_links_driver_bound() puts the AUTOPROBE consumer on the pending list. After that:
drivers/base/dd.c:driver_bound() {
...
driver_deferred_probe_trigger();
bus_notify(dev, BUS_NOTIFY_BOUND_DRIVER);
kobject_uevent(&dev->kobj, KOBJ_BIND);
}So deferred_probe_work_func() can re-probe funcN on another CPU while func 0's lock is still held. The trylock then fails and funcN returns -EPROBE_DEFER again.
driver_probe_device() only retriggers when deferred_trigger_count changed during the probe:
if (trigger_count != atomic_read(&deferred_trigger_count) && !defer_all_probes) driver_deferred_probe_trigger();
Here the increment happened before funcN's probe read trigger_count. So nothing retriggers, and funcN stays on deferred_probe_pending_list.
Other holders of func 0's device lock that never bind a driver seem to have the same effect. Examples are __pci_bus_lock() during AER recovery or a bus/slot reset, a reset through sysfs, or a write to sriov_numvfs. No bind event follows any of these.
In both cases the sibling PF and its ports stay unbound until some unrelated driver binds elsewhere in the system. Doesn't that break the "re-probes them when function 0 binds again" behaviour described in the commit message?
Quoted 14 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +14
-0+ +/* +* The management PF must be bound to *this* driver, with its probe +* completed. links.status == DL_DEV_DRIVER_BOUND alone only says +* "bound to some driver", so func 0 on vfio-pci or pci-stub +* (driver_override) would pass it and this PF would run with func +* 0's chip-global init never performed. pdev->dev.driver is our +* own driver, set by the core before ->probe() is called. +* +* Deferring is enough to recover: a successful bind re-triggers +* deferred probing for every pending device (driver_bound() -> +* driver_deferred_probe_trigger()), so this PF is retried once func +* 0 is bound to this driver. +*/
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v32 2/8 net/nebula-matrix: add common resource implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add chip-agnostic resource layer to manage PF topology, SR-IOV BDF, Ethernet port and VSI identity mappings, providing reusable conversion helpers for the Nebula Matrix driver control plane.
This patch implements core resource initialization and lookup logic, running exclusively on the control PF and building read-only resource tables once during probe:
- nbl_res_init_pf_num(): parse firmware PF mask and validate supported topologies. Only contiguous 1/2/4 PFs starting from PF0 are permitted, rejecting invalid/sparse configurations with early probe failure.
- nbl_common_func_id_to_rel_pf_id(): convert absolute PF function ID to relative PF index for consistent resource table indexing.
- nbl_res_ctrl_dev_sriov_info_init(): calculate and store per-PF BDF entries based on hardware PCI bus number for MSI-X programming.
- nbl_res_ctrl_dev_setup_eth_info(): verify firmware port count and Ethernet bitmap consistency, then construct per-PF eth_id lookup table. logic_eth_id is computed on-the-fly from relative PF ID instead of table lookup.
- nbl_res_ctrl_dev_vsi_info_init(): assign staggered per-PF VSI base IDs with gaps of 1024, 512 and 256 for 1, 2 and 4 port modes.
- Implement VSI/PF/Eth ID conversion helpers with strict control PF validity and range guards.
All resource tables are initialized once at control PF probe time and remain read-only afterwards, so lookup helpers require no internal locking. Upper-layer serialization via mutex and non-control PF mailbox RPC routing will be introduced in later series patches.
All resource memory allocations use devm managed semantics, requiring no explicit cleanup in the remove path.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 2 + .../nebula-matrix/nbl/nbl_common/nbl_common.c | 22 ++ .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 80 ++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 15 + .../nbl_hw_leonis/nbl_resource_leonis.c | 329 ++++++++++++++++++ .../nbl_hw_leonis/nbl_resource_leonis.h | 10 + .../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 125 +++++++ .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 69 ++++ .../nbl/nbl_include/nbl_def_channel.h | 10 + .../nbl/nbl_include/nbl_def_common.h | 20 ++ .../nbl/nbl_include/nbl_def_hw.h | 26 ++ .../nbl/nbl_include/nbl_def_resource.h | 29 ++ .../nbl/nbl_include/nbl_include.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 16 files changed, 753 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +2 -0
@@ -6,4 +6,6 @@ obj-$(CONFIG_NBL) := nbl.o nbl-objs += nbl_common/nbl_common.o \ nbl_channel/nbl_channel.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ + nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ + nbl_hw/nbl_resource.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c +22 -0
@@ -28,3 +28,25 @@ int nbl_common_create_wq(struct nbl_common_info *common)return 0 ; } + +/** +* nbl_common_func_id_to_rel_pf_id - convert absolute PF id to relative PF id +* @common: common device info +* @pf_id: absolute PF identifier +* @rel_pf_id: output relative pf id +* +* Leonis uses fixed mgt_pf = 0. Support future non-zero management PF. +* +* Return: 0 on success, -EINVAL on invalid arguments. +*/ +int nbl_common_func_id_to_rel_pf_id (struct nbl_common_info *common,u32 pf_id, +u32 *rel_pf_id) +{ +if (!rel_pf_id) +return -EINVAL ; + +if (pf_id < common->mgt_pf) +return -EINVAL ; + *rel_pf_id = pf_id - common->mgt_pf; +return 0 ; +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -16,11 +16,13 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_ops_tbl; +struct nbl_resource_ops_tbl *resource_ops_tbl;struct nbl_channel_ops_tbl *channel_ops_tbl; };struct nbl_core {struct nbl_hw_mgt *hw_mgt; +struct nbl_resource_mgt *res_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +78 -2
115 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +15 -0
@@ -51,6 +51,21 @@ struct nbl_mailbox_qinfo_cfg_table {/* -------- HOST_PCIE -------- */ #define NBL_PCIE_HOST_K_PF_MASK_REG (NBL_INTF_HOST_PCIE_BASE + 0x00001004) +#define NBL_PCIE_HOST_TL_CFG_BUSDEV (NBL_INTF_HOST_PCIE_BASE + 0x11040) + +#define NBL_PCIE_BUS_MASK GENMASK(12, 5) +#define NBL_FW_BOARD_CONFIG 0x200 +#define NBL_FW_BOARD_DW3_OFFSET (NBL_FW_BOARD_CONFIG + 12) +#define NBL_FW_BOARD_DW6_OFFSET (NBL_FW_BOARD_CONFIG + 24) + +#define NBL_FW_BOARD_DW3_PORT_TYPE_MASK BIT(0) +#define NBL_FW_BOARD_DW3_PORT_NUM_MASK GENMASK(7, 1) +#define NBL_FW_BOARD_DW3_PORT_SPEED_MASK GENMASK(9, 8) +#define NBL_FW_BOARD_DW3_GPIO_TYPE_MASK GENMASK(12, 10) +#define NBL_FW_BOARD_DW3_P4_VERSION_MASK GENMASK(13, 13) + +#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0) +#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8)#define NBL_BAR2_MAX_LEN 0x300#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +329 -0
329 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_RESOURCE_LEONIS_H_ +#define _NBL_RESOURCE_LEONIS_H_ + +#include "../nbl_resource.h" +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h +1 -0
@@ -17,6 +17,7 @@#define NBL_MAILBOX_BAR 2#define NBL_RDMA_NOTIFY_LEN (8ULL << 10)#define NBL_REG_NET_ONLY_LEN (8ULL << 10) +#define NBL_HW_DUMMY_REG 0x1300904/* * PCI MEMORY BAR total size: 64MiB. */
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c new file +125 -0
125 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h new file +69 -0
69 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +10 -0
@@ -39,6 +39,16 @@ enum nbl_chan_state {NBL_CHAN_STATE_NBITS }; +struct nbl_board_port_info { +u8 eth_num; +u8 eth_speed; +u8 p4_version; +u8 rsv[5 ]; +}; + +static_assert (sizeof (struct nbl_board_port_info ) ==8 , +"nbl_board_port_info size must be 8 bytes" ); +struct nbl_chan_send_info {void *arg;size_t arg_len;
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_common.h +20 -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,
@@ -45,9 +58,22 @@ struct nbl_hw_ops {* happens before the channel layer uses the mask. */ void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask); +void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt,u8 *bus);void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map); +/** +* get_board_info - Fetch board info from firmware +* @hw_mgt: hardware management context +* @board_info: output pointer for board info structure +* +* Firmware contract: board_info.eth_num MUST equal the number of +* unmasked PFs from get_host_pf_mask(). See get_host_pf_mask for +* details. +*/ +void (*get_board_info)(struct nbl_hw_mgt *hw_mgt, +struct nbl_board_port_info *board_info); };struct nbl_hw_ops_tbl {
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_RESOURCE_H_ +#define _NBL_DEF_RESOURCE_H_ + +#include <linux/types.h> + +struct nbl_resource_mgt ; +struct nbl_adapter ; + +struct nbl_resource_ops { +int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 type,u16 *vsi_id); +int (*get_eth_id)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id); +}; + +struct nbl_resource_ops_tbl { +struct nbl_resource_ops *ops; +struct nbl_resource_mgt *priv; +}; + +int nbl_res_init_leonis (struct nbl_adapter *adapter); +void nbl_res_remove_leonis (struct nbl_adapter *adapter); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +6 -0
@@ -13,6 +13,12 @@#define NBL_MAX_PF 8#define NBL_NEXT_ID (id, max) (((id) + 1) % ((max) + 1)) +#define NBL_MAX_ETHERNET 4 + +enum { +NBL_VSI_DATA =0 , +}; +struct nbl_func_caps {u32 has_ctrl:1 ;u32 has_net:1 ;
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
@@ -10,6 +10,7 @@#include "nbl_include/nbl_include.h" #include "nbl_include/nbl_def_channel.h" #include "nbl_include/nbl_def_hw.h" +#include "nbl_include/nbl_def_resource.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -27,6 +28,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, adapter->pdev = pdev; common = &adapter->common; + common->mgt_pf =0 ; common->pdev = pdev; common->dev = &pdev->dev; common->has_ctrl = param->caps.has_ctrl;
@@ -42,7 +44,13 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_chan_init_common (adapter);if (ret) goto 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 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter); }
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v32 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 ops reject calls when common->has_ctrl is not set.
Core functional interfaces:
1. cfg_msix_map: Allocate global hardware MSI-X vectors from the separate net/other interrupt bitmaps. Reuse the per-function coherent DMA map table on reconfig, eliminating free/realloc cycles, DMA race windows and redundant quiesce sleeps. Only tear down the old hardware state after the new allocation succeeds, to avoid interrupt loss, and program the MSI-X table DMA address plus the control-PF BDF into NBL_PCOMPLETER_FUNCTION_MSIX_MAP.
2. destroy_msix_map: Recycle global vector indices, clear hardware MSI-X mappings, and release DMA/descriptor resources. Implements two-stage
teardown: disable mailbox IRQ routing first, mask vectors, clear hardware VALID bits while retaining the live DMA addresses, wait ~1ms for hardware DMA quiescence, then zero the table entries and free the coherent memory to prevent torn reads.
3. set_mailbox_irq: Toggle PF-specific mailbox MSI-X routing by updating NBL_MAILBOX_QINFO_MAP_REG_ARR. The disable path works without a configured MSI-X map, enabling safe routing cleanup before vector release.
4. cfg_msix_info: Program PADPT_HOST_MSIX_INFO and PCOMPLETER_HOST_MSIX_FID_TABLE with the strict hardware-defined programming order (forward for enable, reverse for teardown) to avoid inconsistent hardware state.
Key design & safety features:
- Self-contained intr_mgt->lock protects the global bitmaps and the per-function state; all public APIs hold the lock internally, so callers need no upper-layer locking.
- Global cleanup via nbl_intr_mgt_stop(): under the lock it latches the manager stopping and invalidates the hardware map entry of every function still left CONFIGURED, then takes a single global quiesce window before the coherent tables and vector indices are released. Remote PF maps are created via mailbox RPC in later patches; the cleanup itself uses local MMIO writes.
- Only PFs are supported: every op rejects a func_id outside the PF range (a VF id) with -EINVAL, and cfg_msix_map additionally rejects a func_id that maps to a PF which is not present on this board with -EOPNOTSUPP, via nbl_res_func_id_to_bdf().
- FUNCTION_MSIX_MAP survives a kexec or a forced unload without FLR and there is no .shutdown callback to scrub it, so nbl_intr_mgt_start() invalidates all NBL_MAX_PF map entries once, followed by one flush and one quiesce window, before any function is configured. The gvec-indexed INFO/FID tables are not scrubbed; their entries are rewritten before a map entry is armed again.
Instantiate the interrupt manager via nbl_intr_mgt_start() during device resource initialization, and attach it to the resource management context.
Add corresponding hardware register definitions, helper functions, resource ops callbacks, and Makefile entries to wire up the new module. The new resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq) are hooked into resource_ops but have no in-tree callers within this patch; invocation will be added in subsequent patches in this series.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 164 +++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 44 + .../nbl_hw_leonis/nbl_resource_leonis.c | 38 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 826 ++++++++++++++++++ .../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 | 82 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../nbl/nbl_include/nbl_def_resource.h | 6 + 11 files changed, 1219 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -8,4 +8,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_hw_leonis.o \ nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ nbl_hw/nbl_resource.o \ + nbl_hw/nbl_interrupt.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +162 -2
197 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +44 -0
50 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +35 -3
@@ -10,6 +10,9 @@static struct nbl_resource_ops res_ops = { .get_vsi_id = nbl_res_func_id_to_vsi_id, .get_eth_id = nbl_res_get_eth_id, + .cfg_msix_map = nbl_res_intr_cfg_msix_map, + .destroy_msix_map = nbl_res_intr_destroy_msix_map, + .set_mailbox_irq = nbl_res_intr_set_mailbox_irq, }; static struct nbl_resource_mgt *
@@ -41,7 +44,9 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt) res_ops_tbl =devm_kzalloc (dev,sizeof (*res_ops_tbl),GFP_KERNEL );if (!res_ops_tbl)return ERR_PTR (-ENOMEM ); -if (!res_ops.get_vsi_id || !res_ops.get_eth_id) +if (!res_ops.get_vsi_id || !res_ops.get_eth_id || + !res_ops.cfg_msix_map || !res_ops.destroy_msix_map || + !res_ops.set_mailbox_irq)return ERR_PTR (-EINVAL ); res_ops_tbl->ops = &res_ops; res_ops_tbl->priv = res_mgt;
@@ -282,6 +287,10 @@ static int nbl_res_start(struct nbl_resource_mgt *res_mgt) ret =nbl_res_ctrl_dev_vsi_info_init (res_mgt);if (ret)return ret; + + ret =nbl_intr_mgt_start (res_mgt); +if (ret) +return ret; }return 0 ;
@@ -322,8 +331,31 @@ int nbl_res_init_leonis(struct nbl_adapter *adap)void nbl_res_remove_leonis (struct nbl_adapter *adap) { +struct nbl_resource_mgt *res_mgt = adap->core.res_mgt; +struct nbl_common_info *common = &adap->common; + +if (!res_mgt) +return ; +/* -* No resource release here because all memory uses devm managed -* allocation +* Tear down all MSI-X maps before destroying coherent tables. +* This is critical on the control PF, whose table carries the map +* entries installed for every configured function: they must be +* invalidated in hardware before the tables backing them are +* freed, otherwise the device keeps DMA-reading released pages. +* Sibling PFs are already unbound by the device-link ordering +* so no remote PF still has a live map entry or a running +* mailbox RPC at this point. +*/ +if (common->has_ctrl && res_mgt->intr_mgt) +nbl_intr_mgt_stop (res_mgt); + +/* Note: +* per-function interrupts arrays (kcalloc) are freed by +* nbl_intr_mgt_stop(). +* MSIX coherent tables are explicitly freed by dma_free_coherent() +* inside the intr destroy path, before nbl_intr_mgt_stop() returns. +* intr_mgt itself (devm_kzalloc) is released by devres after this +* function returns */ }
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -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 +826 -0
826 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_INTERRUPT_H_ +#define _NBL_INTERRUPT_H_ + +#include "nbl_resource.h" + +#define NBL_MSIX_MAP_TABLE_MAX_ENTRIES 1024 +int nbl_res_intr_destroy_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id); +int nbl_res_intr_cfg_msix_map (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 num_net_msix, +u16 num_others_msix, +bool net_msix_mask_en); +int nbl_res_intr_set_mailbox_irq (struct nbl_resource_mgt *res_mgt, +u16 func_id,u16 vector_id, +bool en_msix); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c +32 -0
@@ -68,6 +68,38 @@ int nbl_res_vsi_id_to_pf_id(struct nbl_resource_mgt *res_mgt, u16 vsi_id)return -ENOENT ; } +int nbl_res_func_id_to_bdf (struct nbl_resource_mgt *res_mgt,u16 func_id, +u8 *bus,u8 *dev,u8 *function) +{ +struct nbl_common_info *common = res_mgt->common; +struct nbl_sriov_info *sriov_info; +int pfid = func_id; +u8 pf_bus, devfn; +u32 rel_pf_id; +int ret; + +if (!common->has_ctrl || !bus || !dev || !function) +return -EINVAL ; + ret =nbl_common_func_id_to_rel_pf_id (common, pfid, &rel_pf_id); +if (ret) +return ret; +if (rel_pf_id >= common->max_pf) { +dev_err (common->dev, +"func_id=%u rel_pf_id=%u exceeds max_pf=%u, no such PF on this board\n" , + pfid, rel_pf_id, + common->max_pf); +return -EOPNOTSUPP ; + } + sriov_info = res_mgt->resource_info->sriov_info + rel_pf_id; + pf_bus =PCI_BUS_NUM (sriov_info->bdf); + devfn = sriov_info->bdf &0xff ; + *bus = pf_bus; + *dev =PCI_SLOT (devfn); + *function =PCI_FUNC (devfn); + +return 0 ; +} +int nbl_res_get_eth_id (struct nbl_resource_mgt *res_mgt,u16 func_id,u16 vsi_id,u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) {
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +82 -0
102 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
@@ -62,6 +69,8 @@ struct nbl_hw_ops {void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool en_msix,u16 gvec);void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map);/** * get_board_info - Fetch board info from firmware
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id); +int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vector_id,bool en_msix);int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 type,u16 *vsi_id); int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 3/8] net/nebula-matrix: add intr resource implementation
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 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] Nothing waits for the device's in-flight MSI-X map table fetches to finish before the coherent tables are freed or their…
- [Medium] The new kexec/no-FLR scrub runs too late to do its job.
- [Low] The commit message overstates what the quiesce delay guarantees.
- [Low] The header comment of nbl_intr_mgt_stop() (nbl_interrupt.c:748-753) describes a caller that read the intr_mgt…
- [Low] Claimed use-after-free: a caller that read res_mgt->intr_mgt without the lock could lock a mutex that devres has already freed…
--
net/nebula-matrix: add intr resource implementation
This patch adds an nbl_interrupt module. The module manages the chip-internal MSI-X vector index space and programs the MSI-X map, info and FID tables from the control PF. It also adds the cfg_msix_map, destroy_msix_map and set_mailbox_irq resource ops, plus a global teardown in nbl_intr_mgt_stop() that waits a fixed ~1ms before freeing the coherent tables.
Quoted 4 lines
1.
cfg_msix_map: Allocate global hardware MSI-X vectors from the separate net/other interrupt bitmaps. Reuse the per-function coherent DMA map table on reconfig, eliminating free/realloc cycles, DMA race windows and redundant quiesce sleeps. Only tear down the old hardware state
[ ... ]
Quoted 6 lines
2.
destroy_msix_map: Recycle global vector indices, clear hardware MSI-X mappings, and release DMA/descriptor resources. Implements two-stage
teardown: disable mailbox IRQ routing first, mask vectors, clear hardware VALID bits while retaining the live DMA addresses, wait ~1ms for hardware DMA quiescence, then zero the table entries and free the coherent memory to prevent torn reads.
[Severity: Low]
Do these descriptions match the code?
The comment above nbl_intr_quiesce_wait() says the chip exposes no idle/completion status and that the window "is not a guarantee". nbl_intr_mgt_stop() calls the same wait "Best-effort only". The ~1ms wait makes the window smaller but does not close it.
The fresh configuration path of nbl_res_intr_cfg_msix_map() also still does an extra invalidate, flush and quiesce sleep on every call:
if (!had_config) {
hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func_id,
false, 0, 0, 0, 0);
hw_ops->flush_write(res_mgt->hw_ops_tbl->priv);
nbl_intr_quiesce_wait();
}Its own comment calls this defensive, because nbl_intr_setup_mgt() has already invalidated the entry.
Could the commit message be adjusted to match what the code does?
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0
[ ... ]
Quoted 4 lines
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 ); +}
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 268
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +9
-0+/* +* Release the coherent table independently of interrupts so a +* partially built config (table allocated, vectors never +* published) cannot leak coherent DMA memory. +*/ +if (msix_map_table->base_addr) { +dma_free_coherent (dev, msix_map_table->size, + msix_map_table->base_addr, + msix_map_table->dma);
[Severity: Medium]
Could the device still be fetching this table when it is freed here?
The only fence between clearing VALID and this dma_free_coherent() is the fixed usleep_range() in nbl_intr_quiesce_wait(), and the chip offers no completion status. If a table fetch is still outstanding after ~1ms, does it end up reading freed or reused pages?
On removal, bus mastering is still enabled when the tables are freed:
nbl_remove()
nbl_core_remove()
nbl_res_remove_leonis()
nbl_intr_mgt_stop()
nbl_intr_quiesce_wait()
__nbl_res_intr_complete_destroy_msix_map()
dma_free_coherent() pci_clear_master()
The map entry is programmed with the control PF's BDF. Later in the series, sibling PF maps are destroyed at runtime through mailbox RPC. For those, pci_clear_master() on the sibling would not stop these fetches either. nbl_dev.c later in the series calls this a known limitation.
The reconfiguration path in nbl_res_intr_cfg_msix_map() relies on the same timed wait before it recycles the old vectors and rewrites the live table:
nbl_intr_quiesce_wait();
nbl_intr_release_bitmap(intr_mgt, res_mgt, old_interrupts,
old_num);Can a late fetch there resolve to vectors that have already been given to another function?
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 719
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+/* +* Invalidate any map entry left VALID by a previous kernel. One +* flush plus one quiesce window covers the outstanding table +* fetches, same as the teardown paths do. +*/ +for (func_id =0 ; func_id <NBL_MAX_PF ; func_id++) + hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func_id, + false,0 ,0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); +nbl_intr_quiesce_wait ();
[Severity: Medium]
Does this scrub run early enough for the kexec case?
During kexec shutdown the PCI core clears bus mastering, which blocks any fetch from a stale VALID entry. nbl_probe() turns bus mastering back on before hw and channel init, but the stale entries are only cleared here:
nbl_probe()
pci_set_master()
nbl_probe_chip_deps()
nbl_core_init()
nbl_hw_init_leonis()
nbl_chan_init_common()
nbl_res_init_leonis()
nbl_res_start()
nbl_intr_mgt_start()
nbl_intr_setup_mgt()In that window, could a FUNCTION_MSIX_MAP entry that is still VALID make the pcompleter DMA-read an old-kernel table address that this kernel has already reused?
The scrub is only MMIO writes. Could it run before pci_set_master()?
[ ... ]
Quoted 3 lines
+/*
+ *nbl_intr_mgt_stop- global control-PF interrupt teardown
+ *
[ ... ]
Quoted 7 lines
+ * After this returns
res_mgt->intr_mgtis NULL, so the public entry
+ * points report-EINVAL. A caller that latched the pointer before that
+ * instead runs into the stopping latch: the config path and the enable
+ * path ofnbl_res_intr_set_mailbox_irq()report-ESHUTDOWN, the latter
+ * reporting-ENODEVwhen the function was never configured, while the
+ * en_msix=false disable path returns 0 without consulting the latch.
+ */
[Severity: Low]
Can the enable path actually return -ENODEV here?
__nbl_res_intr_set_mailbox_irq() checks the latch before the state:
if (intr_mgt->stopping)
return -ESHUTDOWN;
func_res = &intr_mgt->func_intr_res[func_id];
if (func_res->state != NBL_INTR_FUNC_CONFIGURED) {
...
return -ENODEV;
}So once stopping is set, the enable path always returns -ESHUTDOWN.
This comment and the one on nbl_resource_mgt::intr_mgt also leave out nbl_res_intr_destroy_msix_map(). It returns -ESHUTDOWN after stop, because __nbl_res_intr_destroy_msix_map() checks the latch first.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +0
-0
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +3
-0@@ -56,14 +122,30 @@ struct nbl_resource_mgt {struct nbl_resource_info *resource_info;struct nbl_channel_ops_tbl *chan_ops_tbl;struct nbl_hw_ops_tbl *hw_ops_tbl; +/* +* Published interrupt manager, control PF only. The public entry +* points read this pointer without the manager lock (the object is
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h struct nbl_resource_mgt { · line 137
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h +9
-0+* devres-owned, so it outlives them) and then pass the value they +* read down to the internal helpers; nbl_intr_mgt_stop() clears it +* under the manager lock as its last step. A caller that reads it +* after gets -EINVAL. A caller that latched it before runs into the +* stopping latch instead: the config path and the mailbox-enable +* path report -ESHUTDOWN, while the mailbox-disable path +* (en_msix == false) returns 0 without consulting the latch. +*/ +struct nbl_interrupt_mgt *intr_mgt; };
[Severity: Low]
This isn't a bug, but is "devres-owned, so it outlives them" the right reason here?
devres frees intr_mgt and its mutex once nbl_remove() returns. A caller that had already read the pointer and was still running at that point would lock freed memory, and the stopping latch would not help.
As far as I can tell, nothing in the final series can race this. nbl_core_remove() runs nbl_dev_remove() before nbl_res_remove_leonis(), and nbl_dev_remove() cancels clean_mbx_task and tears down the mailbox channel. Sibling PFs are unbound first through the device link.
Would the comment be clearer if it said that removal ordering is what keeps callers out?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v32 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 pci_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.
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 | 721 +++++++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 222 ++++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 5 +- .../nbl_hw_leonis/nbl_resource_leonis.h | 1 + .../nbl/nbl_include/nbl_def_hw.h | 3 + .../nbl/nbl_include/nbl_def_resource.h | 3 + .../nbl/nbl_include/nbl_include.h | 19 + 10 files changed, 1017 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -9,4 +9,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_hw_leonis/nbl_resource_leonis.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ + nbl_hw/nbl_chip.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include "nbl_chip.h" + +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_common_info *common = res_mgt->common; + +if (!common->has_ctrl) +return ; + hw_ops->deinit_module (res_mgt->hw_ops_tbl->priv); +} + +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_common_info *common = res_mgt->common; +struct nbl_hw_ops *hw_ops; +u8 eth_speed, eth_num; +struct nbl_hw_mgt *p; + +if (!common->has_ctrl) +return -EINVAL ; + eth_speed = res_mgt->resource_info->board_info.eth_speed; + eth_num = res_mgt->resource_info->board_info.eth_num; + hw_ops = res_mgt->hw_ops_tbl->ops; + p = res_mgt->hw_ops_tbl->priv; +return hw_ops->init_module (p, eth_speed, eth_num); +}
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_CHIP_H_ +#define _NBL_CHIP_H_ + +#include "nbl_resource.h" +int nbl_res_chip_init_module (struct nbl_resource_mgt *res_mgt); +void nbl_res_chip_deinit_module (struct nbl_resource_mgt *res_mgt); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +720 -1
756 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +222 -0
251 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c +4 -1
@@ -13,6 +13,8 @@ static struct nbl_resource_ops res_ops = { .cfg_msix_map = nbl_res_intr_cfg_msix_map, .destroy_msix_map = nbl_res_intr_destroy_msix_map, .set_mailbox_irq = nbl_res_intr_set_mailbox_irq, + .init_module = nbl_res_chip_init_module, + .deinit_module = nbl_res_chip_deinit_module, }; static struct nbl_resource_mgt *
@@ -46,7 +48,8 @@ nbl_res_setup_ops(struct device *dev, struct nbl_resource_mgt *res_mgt)return ERR_PTR (-ENOMEM );if (!res_ops.get_vsi_id || !res_ops.get_eth_id || !res_ops.cfg_msix_map || !res_ops.destroy_msix_map || - !res_ops.set_mailbox_irq) + !res_ops.set_mailbox_irq || !res_ops.init_module || + !res_ops.deinit_module)return ERR_PTR (-EINVAL ); res_ops_tbl->ops = &res_ops; res_ops_tbl->priv = res_mgt;
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h +1 -0
@@ -8,4 +8,5 @@#include "../nbl_resource.h" #include "../nbl_interrupt.h" +#include "../nbl_chip.h" #endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +3 -0
@@ -12,6 +12,9 @@ struct nbl_board_port_info;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +int (*init_module)(struct nbl_hw_mgt *hw_mgt,u8 eth_speed,u8 eth_num); +void (*deinit_module)(struct nbl_hw_mgt *hw_mgt); +void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id,bool valid,dma_addr_t dma_addr,u8 bus,u8 devid,u8 function);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +3 -0
@@ -12,6 +12,9 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*init_module)(struct nbl_resource_mgt *res_mgt); +void (*deinit_module)(struct nbl_resource_mgt *res_mgt); +int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 num_net_msix,u16 num_others_msix,bool net_msix_mask_en);
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h +19 -0
@@ -29,4 +29,23 @@ struct nbl_init_param { struct nbl_func_caps caps; }; +/* +* Firmware ABI defines port speed enum fixed, value 0 represents 10G, cannot +* reassign 0 to INVALID for compatibility +*/ +enum nbl_fw_port_speed { +NBL_FW_PORT_SPEED_10G , +NBL_FW_PORT_SPEED_25G , +NBL_FW_PORT_SPEED_50G , +NBL_FW_PORT_SPEED_100G , +}; + +/* +* Firmware quirk word @ NBL_LEONIS_QUIRKS_OFFSET (0x140) +* Sentinel value: ~0U (0xFFFFFFFF) = firmware reports no active quirks +* BIT(1): NBL_QUIRK_UVN_PREFETCH_ALIGN – control UVN descriptor prefetch +* selection +*/ +#define NBL_QUIRK_UVN_PREFETCH_ALIGN BIT(1) +#endif
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 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_hw_clear_stale_status() and nbl_hw_deinit_module() only wait a fixed 2-3 ms before going on, and nothing confirms the firmware…
- [Medium] nbl_hw_set_driver_status() does a host-side read-modify-write of NBL_DRIVER_STATUS_REG (0x1300444): rd32, clear and set BIT(16),…
- [Low] The commit message and one code comment do not match the code.
- [Low] The header comment on nbl_hw_init_module() says 'Full chip hardware initialization is handled by firmware.
- [Low] Concern (baseline decision: false positive): nbl_shaping_init() does a read-modify-write of NBL_DSCH_PSHA_EN_ADDR with…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This patch adds the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers, gated on has_ctrl. init_module() programs the DPED/UPED/SHAPING/DSCH/USTORE/DSTORE/DVN/UVN/UQM/PADPT datapath registers and sets the driver_status bit. deinit_module() clears that bit and sleeps 2-3 ms for the asynchronous firmware cleanup, and a stale driver_status bit is cleared early in nbl_hw_init_leonis().
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +0
-0@@ -150,6 +167,695 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static int nbl_shaping_init (struct nbl_hw_mgt *hw_mgt,u8 speed) +{
[ ... ]
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 339
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +7
-0+nbl_hw_rd_regs_lock (hw_mgt,NBL_DSCH_PSHA_EN_ADDR , ®_val, +sizeof (reg_val)); + reg_val &= ~NBL_DSCH_PSHA_EN_MASK ; + reg_val |=FIELD_PREP (NBL_DSCH_PSHA_EN_MASK , + eth_bitmap &GENMASK (3 ,0 )); +nbl_hw_wr_regs_lock (hw_mgt,NBL_DSCH_PSHA_EN_ADDR , ®_val, +sizeof (reg_val));
[Severity: Low]
This isn't a bug, but this read-modify-write of NBL_DSCH_PSHA_EN_ADDR drops reg_lock between nbl_hw_rd_regs_lock() and nbl_hw_wr_regs_lock(). Right now nbl_shaping_init() is the only code that touches this register, and it only runs from the serialized control-PF probe, so no update can be lost.
nbl_dvn_init() also writes NBL_DVN_ECPU_QUEUE_NUM without the lock:
nbl_hw_wr32(hw_mgt, NBL_DVN_ECPU_QUEUE_NUM, 0);
nbl_uvn_init(), by contrast, writes NBL_UVN_ECPU_QUEUE_NUM under reg_lock.
To match the rest of the file, would it make sense to hold reg_lock across the whole read-modify-write here, and to take it in nbl_dvn_init() too?
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +8
-0+/* +* Read-modify-write under reg_lock: NBL_DRIVER_STATUS_BIT is the only +* bit the driver owns, and the RMW leaves every other bit of the +* register untouched. +*/ +static void nbl_hw_set_driver_status (struct nbl_hw_mgt *hw_mgt,bool active) +{ +u32 status;
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 719
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +10
-0+ +spin_lock (&hw_mgt->reg_lock); + status =nbl_hw_rd32 (hw_mgt,NBL_DRIVER_STATUS_REG ); + + status &= ~BIT (NBL_DRIVER_STATUS_BIT ); + status |=FIELD_PREP (BIT (NBL_DRIVER_STATUS_BIT ), active); + +nbl_hw_wr32 (hw_mgt,NBL_DRIVER_STATUS_REG , status); +spin_unlock (&hw_mgt->reg_lock); +}
[Severity: Medium]
The comment says bit 16 is the only bit the driver owns. That suggests the other bits of NBL_DRIVER_STATUS_REG (0x1300444) belong to some other agent, most likely firmware, which already consumes this register.
reg_lock only serializes accesses from the CPU. If firmware updates another bit of this register between the nbl_hw_rd32() and the nbl_hw_wr32(), can the driver write back a stale value and undo that firmware update?
All three callers can hit this: the stale-status clear in probe, nbl_hw_init_module() and nbl_hw_deinit_module().
Is this register driver-exclusive? Or does it have W1S/W1C semantics that would let the driver set and clear bit 16 without a read-modify-write? Could the semantics be documented next to NBL_DRIVER_STATUS_REG?
[ ... ]
Quoted 11 lines
+/*
+ * Clear a staledriver_statusactive bit before this probe programs any
+ * per-PF state.
+ *
+ * A previous kernel instance can leave the bit set (kexec, or an unload
+ * that never reacheddeinit_module()) and firmware then never ran the
+ * per-PF cleanup it drives off the 1 -> 0 transition. That cleanup
+ * reclaims the mailbox QINFO routing and the qinfo registers, which is
+ * exactly whatnbl_dev_setup_chan_qinfo()andnbl_chan_setup_queue()
+ * write later in this probe. Clearing it there - as the chip init path
+ * used to - wipes those registers and leaves the inter-PF mailbox dead,
[Severity: Low]
This isn't a bug, but "as the chip init path used to" seems to describe an earlier revision of this patch, not code in the tree. Could the comment just state the current ordering requirement?
Also, the commit message says:
The relaxed-ordering bits in
both DVN and UVN are derived from the PCIe DEVCTL state through pci_relaxed_ordering_enabled().
There is no pci_relaxed_ordering_enabled(). nbl_dvn_init() and nbl_uvn_init() both call pcie_relaxed_ordering_enabled(). Should the commit message use that name?
Quoted 9 lines
+ * so sibling PFs' RPCs time out in
nbl_dev_start()and their probes
+ * fail. It also has to happen before the mailbox queue is live, so the
+ * cleanup cannot reclaim routing under an in-flight transfer.
+ *
+ * Only the control PF owns this chip-wide handshake. The bounded wait
+ * after the clear is best-effort, seeNBL_FW_CLEANUP_SYNC_MIN_US.
+ */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 820
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +6
-0+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]
Is a fixed 2-3 ms sleep enough to keep the firmware cleanup pass from racing with the rest of this probe?
nbl_flush_writes() only shows that the status write reached the device. The comments also say the hardware has no cleanup-complete bit.
With the later patches in the series applied, the probe order is roughly:
nbl_core_init()
nbl_hw_init_leonis()
nbl_hw_clear_stale_status() /* clear bit 16, sleep 2-3 ms */
...
nbl_dev_init()
nbl_dev_setup_chan_qinfo() /* programs mailbox QINFO routing */
nbl_dev_setup_common_dev()
nbl_chan_setup_queue() /* programs qinfo, sets QUEUE_EN */
Suppose firmware takes longer than about 2-3 ms, for example because the ECPU is busy right after kexec. Can it then reclaim the routing and qinfo registers that were just programmed?
That would leave the inter-PF mailbox dead, and sibling PF RPCs would time out in nbl_dev_start(). That is the failure the comment above describes. It could also reclaim routing under a live queue.
nbl_hw_deinit_module() relies on the same unverified delay. On a later rebind driver_status is already 0, so nbl_hw_clear_stale_status() returns at once without knowing whether the earlier pass has finished.
The NBL_FW_CLEANUP_SYNC_MIN_US value does not appear to come from any documented firmware latency.
Could the driver poll for an observable side effect of the cleanup with a timeout, such as the QINFO/qinfo entries reading back as reclaimed? Or could it check the registers after programming them?
Quoted 4 lines
+/*
+ * Full chip hardware initialization is handled by firmware.
+ * This function only configures driver-level table entries and registers.
+ *
[Severity: Low]
This isn't a bug, but does this comment match what the function does?
Through nbl_dp_init() and nbl_intf_init() it programs chip-wide datapath registers that every PF shares (SHAPING, DSCH, USTORE/DSTORE, DVN/UVN, UQM, PADPT). The commit message also says "none of which firmware sets up on the driver's behalf".
The comment on nbl_hw_deinit_module() describes the same registers differently:
* Note: firmware does NOT automatically revert chip-wide registers
* configured in this init flow.
The nbl_dev_init() comment added later in the series repeats the "Chip hardware initialization is completed by firmware at power-up" wording.
Could these comments agree on who owns this state?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v32 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 ops. Add a ctrl_lvl bitmap to track control privileges; only the MGT level is defined, and it is enabled only on the control PF.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 2 + .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 117 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 ++++ .../nbl/nbl_include/nbl_def_dispatch.h | 54 ++++++++ .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 8 ++ 6 files changed, 205 insertions(+) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -10,4 +10,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_resource.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_chip.o \ + nbl_core/nbl_dispatch.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2 -0
@@ -17,12 +17,14 @@ enum {struct nbl_interface {struct nbl_hw_ops_tbl *hw_ops_tbl;struct nbl_resource_ops_tbl *resource_ops_tbl; +struct nbl_dispatch_ops_tbl *dispatch_ops_tbl;struct nbl_channel_ops_tbl *channel_ops_tbl; };struct nbl_core {struct nbl_hw_mgt *hw_mgt;struct nbl_resource_mgt *res_mgt; +struct nbl_dispatch_mgt *disp_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c new file +117 -0
117 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DISPATCH_H_ +#define _NBL_DISPATCH_H_ +#include "../nbl_include/nbl_include.h" +#include "../nbl_include/nbl_def_channel.h" +#include "../nbl_include/nbl_def_resource.h" +#include "../nbl_include/nbl_def_dispatch.h" +#include "../nbl_include/nbl_def_common.h" +#include "../nbl_core.h" + +struct nbl_dispatch_mgt { +struct nbl_common_info *common; +struct nbl_resource_ops_tbl *res_ops_tbl; +struct nbl_channel_ops_tbl *chan_ops_tbl; +struct nbl_dispatch_ops_tbl *disp_ops_tbl; + DECLARE_BITMAP(ctrl_lvl, NBL_DISP_CTRL_LVL_MAX); +}; + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h new file +54 -0
54 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 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter);
Signature · 1 line
2.47.3
illusion.wang
maintainerPATCH v32 6/8 net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add mailbox RPC requests and responses for five dispatch operations:cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Each op is resolved by capability level: a function with has_ctrl calls the resource op locally, a function with has_net forwards it to the management PF over the channel, and a function with neither leaves the op pointer NULL, so the caller must not invoke it.
A request builds the payload, sends it synchronously and checks the ACK length before parsing; a short ACK returns -EBADMSG. A responder rejects VFs and out-of-range source PF ids with -EPERM, checks the payload length before parsing, and forwards the resource layer's errno verbatim so the requester can tell a protocol error from a failed operation. If the resource op is not installed the responder answers -EOPNOTSUPP. A peer PF is treated as trusted: hardware and firmware forbid PF passthrough to guests, so every peer runs this host driver, and the resource layer bounds the requested vector counts by the global pool.
The cfg_msix_map, destroy_msix_map and set_mailbox_irq requests carry a caller precondition: disable the mailbox IRQ_RDY flag and use the polling send path, because the responder changes mailbox MSI-X routing and an interrupt-driven ACK wakeup cannot be relied on while routing is in flux.
No dispatch-layer lock is taken around these ops. The resource layer serializes concurrent callers itself (intr_mgt->lock) and the dispatch layer has no mutable state of its own to protect; the read-only get_vsi_id/get_eth_id paths only touch static init metadata.
nbl_disp_remove() documents why the five responders, which are owned by the channel layer, need no explicit unregistration.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 534 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_channel.h | 40 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 27 +- 3 files changed, 600 insertions(+), 1 deletion(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +534 -0
@@ -6,6 +6,174 @@#include <linux/pci.h> #include "nbl_dispatch.h" +static int nbl_disp_chan_get_vsi_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 type,u16 *vsi_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.type =cpu_to_le16 (type); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_GET_VSI_ID , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_vsi_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +return -EBADMSG ; + } + *vsi_id =le16_to_cpu (result.vsi_id); +return 0 ; +} + +static void nbl_disp_chan_get_vsi_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_get_vsi_id result = {0 }; +struct nbl_chan_param_get_vsi_id param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u16 vsi_id =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + +if (res_ops->get_vsi_id) { + ret = res_ops->get_vsi_id (p, src_id,le16_to_cpu (param.type), + &vsi_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + }else { + err = -EOPNOTSUPP ; + } + + result.vsi_id =cpu_to_le16 (vsi_id); +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_GET_VSI_ID , msg_id, err, + &result,sizeof (result)); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_GET_VSI_ID ); +} + +static int nbl_disp_chan_get_eth_id_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vsi_id,u8 *eth_num,u8 *eth_id, +u8 *logic_eth_id) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.vsi_id =cpu_to_le16 (vsi_id); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_GET_ETH_ID , + ¶m,sizeof (param), &result, +sizeof (result),1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +if (chan_send.ack_len !=sizeof (result)) { +dev_err (disp_mgt->common->dev, +"get_eth_id: short ACK, ack_len=%u expected %zu\n" , + chan_send.ack_len,sizeof (result)); +return -EBADMSG ; + } + *eth_num = result.eth_num; + *eth_id = result.eth_id; + *logic_eth_id = result.logic_eth_id; + +return 0 ; +} + +static void nbl_disp_chan_get_eth_id_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_get_eth_id result = {0 }; +struct nbl_chan_param_get_eth_id param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + +if (res_ops->get_eth_id) { + ret = res_ops->get_eth_id (p, src_id,le16_to_cpu (param.vsi_id), + &result.eth_num, &result.eth_id, + &result.logic_eth_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + }else { + err = -EOPNOTSUPP ; + } +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_GET_ETH_ID , msg_id, err, + &result,sizeof (result)); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_GET_ETH_ID ); +} +static void nbl_disp_deinit_module (struct nbl_dispatch_mgt *disp_mgt) {struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops;
@@ -25,6 +193,353 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return -EOPNOTSUPP ; } +static int nbl_disp_cfg_msix_map (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (!res_ops->cfg_msix_map) +return -EOPNOTSUPP ; +/* +* No core-layer lock is taken here: the resource layer serializes +* concurrent callers itself (intr_mgt->lock), and the dispatch +* layer has no mutable state of its own for this op to protect. +*/ +return res_ops->cfg_msix_map (p, common->mgt_pf, num_net_msix, + num_others_msix, net_msix_mask_en); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int +nbl_disp_chan_cfg_msix_map_req (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.num_net_msix =cpu_to_le16 (num_net_msix); + param.num_others_msix =cpu_to_le16 (num_others_msix); + param.msix_mask_en =cpu_to_le16 (!!net_msix_mask_en); + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + ¶m,sizeof (param), +NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_cfg_msix_map_resp (void *priv,u16 src_id,u16 msg_id, +void *data,u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_param_cfg_msix_map param = {0 }; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + +if (res_ops->cfg_msix_map) { +/* +* The vector counts come from the peer PF. A peer is +* trusted: hardware and firmware forbid PF passthrough to +* guests (see nbl_get_func_param()), so every peer runs this +* same host driver, and the resource layer bounds the counts +* by the global vector pool. A peer asking for the whole +* pool can starve the others with -EAGAIN, but it cannot +* corrupt state. +*/ + ret = res_ops->cfg_msix_map (p, src_id, +le16_to_cpu (param.num_net_msix), +le16_to_cpu (param.num_others_msix), + !!le16_to_cpu (param.msix_mask_en)); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + }else { + err = -EOPNOTSUPP ; + } +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP ); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder retargets +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int nbl_disp_chan_destroy_msix_map_req (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , +NULL ,0 ,NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u32 rel_pf_id; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (res_ops->destroy_msix_map) { + ret = res_ops->destroy_msix_map (p, src_id); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + }else { + err = -EOPNOTSUPP ; + } +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_DESTROY_MSIX_MAP , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_DESTROY_MSIX_MAP ); +} + +/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's own mailbox MSI-X routing (MSIX_IDX / MSIX_IDX_VALID) +* before the ACK is sent, so the ACK cannot rely on interrupt wakeup +* while routing is in flux. +*/ +static int nbl_disp_chan_set_mailbox_irq_req (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct nbl_common_info *common = disp_mgt->common; +struct nbl_chan_send_info chan_send = {0 }; +int ret; + + param.vector_id =cpu_to_le16 (vector_id); + param.en_msix = !!en_msix; + +nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_MAILBOX_SET_IRQ , + ¶m,sizeof (param),NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send); +if (ret) +return ret; +return 0 ; +} + +static void nbl_disp_chan_set_mailbox_irq_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{ +struct nbl_dispatch_mgt *disp_mgt = (struct nbl_dispatch_mgt *)priv; +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_chan_param_set_mailbox_irq param = {0 }; +struct device *dev = disp_mgt->common->dev; +struct nbl_chan_ack_info chan_ack; +int err =0 ; +u16 vector_id; +u32 rel_pf_id; +bool en_msix; +int ret; + + ret =nbl_common_func_id_to_rel_pf_id (disp_mgt->common, src_id, + &rel_pf_id); +if (ret) { + err = -EPERM ; + goto ack_out; + } +if (rel_pf_id >= disp_mgt->common->max_pf) { + err = -EPERM ; + goto ack_out; + } +if (data_len <sizeof (param)) { + err = -EBADMSG ; + goto ack_out; + } +memcpy (¶m, data,sizeof (param)); + vector_id =le16_to_cpu (param.vector_id); + en_msix = !!param.en_msix; + +if (res_ops->set_mailbox_irq) { + ret = res_ops->set_mailbox_irq (p, src_id, vector_id, en_msix); +/* Forward the resource errno verbatim to the requester */ +if (ret) + err = ret; + }else { + err = -EOPNOTSUPP ; + } + +ack_out: +nbl_chan_fill_ack_info (&chan_ack, src_id, +NBL_CHAN_MSG_MAILBOX_SET_IRQ , msg_id, + err,NULL ,0 ); + ret = chan_ops->send_ack (disp_mgt->chan_ops_tbl->priv, &chan_ack); +if (ret) +dev_err (dev, +"channel send ack failed with ret: %d, msg_type: %d\n" , + ret,NBL_CHAN_MSG_MAILBOX_SET_IRQ ); +} + +static int nbl_disp_destroy_msix_map (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (!res_ops->destroy_msix_map) +return -EOPNOTSUPP ; +return res_ops->destroy_msix_map (p, common->mgt_pf); +} + +static int nbl_disp_set_mailbox_irq (struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (!res_ops->set_mailbox_irq) +return -EOPNOTSUPP ; +return res_ops->set_mailbox_irq (p, common->mgt_pf, vector_id, en_msix); +} + +static int nbl_disp_get_vsi_id (struct nbl_dispatch_mgt *disp_mgt,u16 type, +u16 *vsi_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (res_ops->get_vsi_id) +return res_ops->get_vsi_id (p, common->mgt_pf, type, vsi_id); +return -EOPNOTSUPP ; +} + +static int nbl_disp_get_eth_id (struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_num,u8 *eth_id,u8 *logic_eth_id) +{ +struct nbl_resource_ops *res_ops = disp_mgt->res_ops_tbl->ops; +struct nbl_resource_mgt *p = disp_mgt->res_ops_tbl->priv; +struct nbl_common_info *common = disp_mgt->common; + +if (res_ops->get_eth_id) +return res_ops->get_eth_id (p, common->mgt_pf, vsi_id, + eth_num, eth_id, logic_eth_id); +return -EOPNOTSUPP ; +} + +static int nbl_disp_setup_msg (struct nbl_dispatch_mgt *disp_mgt) +{ +struct nbl_channel_ops *chan_ops = disp_mgt->chan_ops_tbl->ops; +struct nbl_channel_mgt *p = disp_mgt->chan_ops_tbl->priv; +int ret =0 ; +int _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + nbl_disp_chan_cfg_msix_map_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_DESTROY_MSIX_MAP , + nbl_disp_chan_destroy_msix_map_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_MAILBOX_SET_IRQ , + nbl_disp_chan_set_mailbox_irq_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_GET_VSI_ID , + nbl_disp_chan_get_vsi_id_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + + _ret = chan_ops->register_msg (p,NBL_CHAN_MSG_GET_ETH_ID , + nbl_disp_chan_get_eth_id_resp, + disp_mgt); +if (_ret <0 && !ret) + ret = _ret; + +return ret; +} +static void nbl_disp_set_ctrl_bit (struct nbl_dispatch_mgt *disp_mgt,u32 lvl) {set_bit (lvl, disp_mgt->ctrl_lvl);
@@ -34,9 +549,22 @@ static void nbl_disp_refresh_ctrl_ops(struct nbl_dispatch_mgt *disp_mgt) {struct nbl_dispatch_ops *disp_ops = disp_mgt->disp_ops_tbl->ops; +memset (disp_ops,0 ,sizeof (*disp_ops));if (test_bit (NBL_DISP_CTRL_LVL_MGT , disp_mgt->ctrl_lvl)) { disp_ops->init_module = nbl_disp_init_module; disp_ops->deinit_module = nbl_disp_deinit_module; + disp_ops->cfg_msix_map = nbl_disp_cfg_msix_map; + disp_ops->destroy_msix_map = nbl_disp_destroy_msix_map; + disp_ops->set_mailbox_irq = nbl_disp_set_mailbox_irq; + disp_ops->get_vsi_id = nbl_disp_get_vsi_id; + disp_ops->get_eth_id = nbl_disp_get_eth_id; + }else if (test_bit (NBL_DISP_CTRL_LVL_NET , disp_mgt->ctrl_lvl)) { + disp_ops->cfg_msix_map = + nbl_disp_chan_cfg_msix_map_req; + disp_ops->destroy_msix_map = nbl_disp_chan_destroy_msix_map_req; + disp_ops->set_mailbox_irq = nbl_disp_chan_set_mailbox_irq_req; + disp_ops->get_vsi_id = nbl_disp_chan_get_vsi_id_req; + disp_ops->get_eth_id = nbl_disp_chan_get_eth_id_req; } }
@@ -104,9 +632,15 @@ int nbl_disp_init(struct nbl_adapter *adapter) adapter->core.disp_mgt = disp_mgt; adapter->intf.dispatch_ops_tbl = disp_ops_tbl; + ret =nbl_disp_setup_msg (disp_mgt); +if (ret) +return ret; +if (common->has_ctrl)nbl_disp_set_ctrl_bit (disp_mgt,NBL_DISP_CTRL_LVL_MGT ); +if (common->has_net) +nbl_disp_set_ctrl_bit (disp_mgt,NBL_DISP_CTRL_LVL_NET );nbl_disp_refresh_ctrl_ops (disp_mgt);return 0 ; }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h +40 -0
@@ -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 +26 -1
@@ -12,6 +12,7 @@ struct nbl_dispatch_mgt;struct nbl_adapter ;enum {NBL_DISP_CTRL_LVL_MGT , +NBL_DISP_CTRL_LVL_NET ,NBL_DISP_CTRL_LVL_MAX , };
@@ -32,16 +33,40 @@ enum {* mailbox DMA before calling it, see nbl_dev_remove(). * Returns void. Control-PF exclusive, same NULL rule as * @init_module. +* @cfg_msix_map: configure function msix mapping table +* @destroy_msix_map: tear down msix mapping resource +* @set_mailbox_irq: bind mailbox interrupt to specified msix vector +* @get_vsi_id: resolve VSI ID by type +* @get_eth_id: resolve eth port info from VSI ID * * These callbacks are not dispatch-layer setup/teardown: the dispatch * structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove() * only documents why no explicit teardown is needed. They forward * chip/firmware control down to the layers below instead: a control-PF -* function calls the resource ops directly. +* function calls the resource ops directly, a non-control function sends a +* mailbox request over the channel layer. +* +* Warning: init_module/deinit_module are control-PF exclusive. The five +* resource ops (cfg_msix_map, destroy_msix_map, set_mailbox_irq, +* get_vsi_id, get_eth_id) are PF-only and resolve to either a local +* resource call (control PF) or a mailbox RPC (non-control PF with +* has_net). A function with neither has_ctrl nor has_net leaves these +* pointers NULL; callers must not invoke them on such functions. VFs are +* rejected by the responders with -EPERM. */ struct nbl_dispatch_ops {int (*init_module)(struct nbl_dispatch_mgt *disp_mgt);void (*deinit_module)(struct nbl_dispatch_mgt *disp_mgt); +int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_dispatch_mgt *disp_mgt); +int (*set_mailbox_irq)(struct nbl_dispatch_mgt *disp_mgt, +u16 vector_id,bool en_msix); +int (*get_vsi_id)(struct nbl_dispatch_mgt *disp_mgt,u16 type, +u16 *vsi_id); +int (*get_eth_id)(struct nbl_dispatch_mgt *disp_mgt,u16 vsi_id, +u8 *eth_num,u8 *eth_id,u8 *logic_eth_id); };struct nbl_dispatch_ops_tbl {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 6/8] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Baseline decision: false (resolved later in the series, retained only because requires_validation=true).
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This patch adds mailbox RPC requests and responders for cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Each op resolves to a local resource call when has_ctrl is set, or to a channel RPC to the management PF when has_net is set. The five responders are registered with the channel layer from nbl_disp_setup_msg().
Quoted 2 lines
nbl_disp_remove()documents why the five responders, which are owned by the channel layer, need no explicit unregistration.
[Severity: Low]
Is this paragraph accurate for this patch? The patch does not change nbl_disp_remove() in nbl_dispatch.c, and at this commit it still reads:
void nbl_disp_remove(struct nbl_adapter *adapter)
{
/* Dispatch structures are allocated via devm */
}There is nothing there about the responders that nbl_disp_setup_msg() registers.
The kernel-doc for struct nbl_dispatch_ops in nbl_def_dispatch.h also sends readers to nbl_disp_remove() for that explanation:
* structures are devm-allocated in nbl_disp_init(), and nbl_disp_remove()
* only documents why no explicit teardown is needed.
The full comment arrives in the next patch in the series, "net/nebula-matrix:
add common/ctrl dev init/remove operation". It explains the teardown order cancel_work_sync -> nbl_chan_teardown_queue -> nbl_chan_remove_common -> nbl_chan_remove_msg_handler.
Could this paragraph be dropped from this commit message, or the comment moved into this patch, so each commit matches its own message?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v32 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, so that the control PF mailbox responder is fully ready before any cross-PF RPC is issued and each commit in the series can be probed on its own.
Control-PF-only setup invokes chip-level module initialization and programs the mailbox QINFO routing table entries that map PF bus/devid to the mailbox queue.
Init/teardown ordering is dictated by a hardware constraint rather than by strict symmetry. Init: program mailbox QINFO (control PF only), create the mailbox queue, then run control device init_module. Teardown:
stop the mailbox channel and drain all in-flight DMA first, then call deinit_module(). This ordering prevents the firmware from reclaiming the routing under a live transfer, which would leave the device DMAing into released memory.
The firmware reclaims per-PF state (mailbox QINFO routing, qinfo registers and the like) asynchronously once driver status is marked inactive. It does not revert the chip-wide datapath registers configured by init_module; those stay valid until chip reset (see nbl_hw_deinit_module()). The device link created during non-control PF probe makes the driver core unbind all sibling PFs before the control PF is removed.
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 295 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 ++++ .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 22 +- .../nbl/nbl_include/nbl_def_dev.h | 14 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 9 + 7 files changed, 396 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
drivers/net/ethernet/nebula-matrix/nbl/Makefile +1 -0
@@ -11,4 +11,5 @@ nbl-objs += nbl_common/nbl_common.o \ nbl_hw/nbl_interrupt.o \ nbl_hw/nbl_chip.o \ nbl_core/nbl_dispatch.o \ + nbl_core/nbl_dev.o \ nbl_main.o
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +1 -0
@@ -25,6 +25,7 @@ struct nbl_core {struct nbl_hw_mgt *hw_mgt;struct nbl_resource_mgt *res_mgt;struct nbl_dispatch_mgt *disp_mgt; +struct nbl_dev_mgt *dev_mgt;struct nbl_channel_mgt *chan_mgt; };
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +295 -0
295 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
@@ -647,5 +647,25 @@ int nbl_disp_init(struct nbl_adapter *adapter)void nbl_disp_remove (struct nbl_adapter *adapter) { -/* Dispatch structures are allocated via devm */ +/* +* Dispatch structures are devm-allocated and freed at detach. +* +* The five responders registered by nbl_disp_setup_msg() are +* owned by the channel layer (xarray of handlers) and are never +* unregistered here. This is safe because the teardown order +* guarantees no responder can run after this point: +* +* mailbox teardown +* -> cancel_work_sync(clean_mbx_task) // drain RX work +* -> nbl_chan_teardown_queue() // stop HW queue, +* // join clean task, +* // active=false +* -> nbl_chan_remove_common() +* -> nbl_common_destroy_wq() // no new work +* -> nbl_chan_remove_msg_handler() // free handler nodes +* +* By the time devres frees disp_mgt, the mailbox queue is stopped +* and the handler xarray is empty, so no responder can touch +* res_mgt->intr_mgt after nbl_intr_mgt_stop() has cleared it. +*/ }
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ + +#ifndef _NBL_DEF_DEV_H_ +#define _NBL_DEF_DEV_H_ + +struct nbl_adapter ; + +int nbl_dev_init (struct nbl_adapter *adapter); +void nbl_dev_remove (struct nbl_adapter *adapter); + +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9 -0
@@ -12,6 +12,7 @@#include "nbl_include/nbl_def_hw.h" #include "nbl_include/nbl_def_resource.h" #include "nbl_include/nbl_def_dispatch.h" +#include "nbl_include/nbl_def_dev.h" #include "nbl_include/nbl_def_common.h" #include "nbl_core.h"
@@ -53,7 +54,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, ret =nbl_disp_init (adapter);if (ret) goto out_res_remove; + + ret =nbl_dev_init (adapter); +if (ret) + goto out_disp_remove;return adapter; + +out_disp_remove: +nbl_disp_remove (adapter); out_res_remove:nbl_res_remove_leonis (adapter); out_chan_remove:
@@ -66,6 +74,7 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_dev_remove (adapter);nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove 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] At this commit, several new comments in nbl_dev.c (and one existing comment in nbl_hw_leonis.c) mention functions that are not…
- [Low] The teardown-ordering comment above nbl_dev_remove_ctrl_dev() (nbl_dev.c lines 180-183) says that nbl_probe_chip_deps() 're-checks…
- [Low] In nbl_dev_remove_common_dev() (nbl_dev.c lines 151-156), the comment says 'A register_chan_task(..., NULL) from here would be a no-…
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This adds nbl_dev.c with nbl_dev_init() and nbl_dev_remove(). They set up the mailbox channel queue and its clean work. On the control PF they also program the mailbox QINFO routing and run init_module/deinit_module, and the new entry points are wired into nbl_core_init() and nbl_core_remove().
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,295 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 17
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9
-0+static void nbl_dev_init_msix_cnt (struct nbl_dev_mgt *dev_mgt) +{ +struct nbl_dev_common *dev_common = dev_mgt->common_dev; +struct nbl_msix_info *msix_info = &dev_common->msix_info; + +/* mailbox vector allocated in nbl_dev_start() via +* nbl_dev_init_interrupt_scheme(); nbl_dev_request_mailbox_irq() +* only attaches the irq handler to pre-allocated vectors. +*/
[Severity: Low]
Are nbl_dev_start(), nbl_dev_init_interrupt_scheme() and nbl_dev_request_mailbox_irq() defined anywhere at this commit? They only seem to appear in comments: here, in the nbl_dev_setup_common_dev() note further down, and in the comment above nbl_hw_clear_stale_status() in nbl_hw_leonis.c.
The comment above INIT_WORK in nbl_dev_setup_common_dev() has a similar problem:
* INIT_WORK must precede nbl_dev_register_chan_task() below: the
* registration hands the work item to the channel and the IRQ
* path may queue it as soon as setup_queue() completes.
This commit doesn't request any mailbox IRQ, and nbl_probe() ends after nbl_core_init()->nbl_dev_init().
The next patch in the series, "net/nebula-matrix: add common dev start/stop operation", adds these functions and wires up nbl_probe()->nbl_core_start()->nbl_dev_start(). That makes the references valid.
Two wording problems remain after that patch. The INIT_WORK note still refers to an IRQ path, but the IRQ is only requested later, in nbl_dev_start(). This note also reads like development history in a newly added file:
* VSI/ETH identity fetch moved to nbl_dev_start().
Could these comments be reworded to describe the code as it stands?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+ msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; +}
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +8
-0+static void nbl_dev_remove_common_dev (struct nbl_adapter *adapter) +{ +struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt; +struct nbl_dev_common *common_dev = dev_mgt->common_dev; + +if (!common_dev) +return ; +cancel_work_sync (&common_dev->clean_mbx_task);
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 159
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +9
-0+* Unregistering the clean task is the channel layer's job too: +* teardown_queue() clears clean_task under state_lock and then +* cancel_work_sync()es it, after shutdn has blocked new queues. A +* register_chan_task(..., NULL) from here would be a no-op anyway, +* because nbl_chan_register_chan_task() ignores writes once shutdn +* is set. +*/ +nbl_dev_remove_chan_queue (dev_mgt,NBL_CHAN_TYPE_MAILBOX ); +}
[Severity: Low]
Is shutdn actually set at this point? It only becomes true in nbl_chan_teardown_queue(), which runs from nbl_dev_remove_chan_queue() after this comment:
nbl_chan_teardown_queue() {
...
mutex_lock(&chan_info->state_lock);
WRITE_ONCE(chan_info->shutdn, true);
task = READ_ONCE(chan_info->clean_task);
WRITE_ONCE(chan_info->clean_task, NULL);
...
}Until then, nbl_chan_register_chan_task() still accepts writes:
mutex_lock(&chan_info->state_lock); if (!READ_ONCE(chan_info->shutdn)) WRITE_ONCE(chan_info->clean_task, task); mutex_unlock(&chan_info->state_lock);
So a register_chan_task(..., NULL) at this point would clear clean_task, not do nothing. It is still true that no explicit unregister is needed, but the reason is that teardown_queue() clears clean_task itself.
Could the last sentence of the comment be corrected? The comment is unchanged at the end of the series.
[ ... ]
Quoted 8 lines
+ * Teardown ordering guarantee: every non-management PF creates a
+ *consumer->controlPF device link in its probe path, so the driver
+ * core always unbinds all siblings before allowing the control PF to
+ * be detached (sysfs unbind, driver unregister and hot-unplug alike).
+ *nbl_probe_chip_deps()defers a sibling's probe until the control PF
+ * is fully bound (DL_DEV_DRIVER_BOUND), and re-checks that state after
+ *device_link_add()so a supplier that slipped toDL_DEV_NO_DRIVERor
+ *DL_DEV_PROBINGin between also defers. A sibling therefore cannot
[Severity: Low]
Does nbl_probe_chip_deps() actually do this re-check? In nbl_main.c it checks the state once under device_trylock(). It then creates the link with the lock still held and unlocks without checking the state again:
if (mgt->dev.driver != pdev->dev.driver ||
mgt->dev.links.status != DL_DEV_DRIVER_BOUND) {
device_unlock(&mgt->dev);
pci_dev_put(mgt);
return -EPROBE_DEFER;
}
...
if (!device_link_add(&pdev->dev, &mgt->dev,
DL_FLAG_AUTOPROBE_CONSUMER)) {
...
}
device_unlock(&mgt->dev);
pci_dev_put(mgt);
return 0;The comment in that function says the guarantee comes from holding the lock:
* Holding the lock is what makes the check and the link creation
* below atomic with respect to func 0: ...
Is this sentence left over from an earlier version of nbl_probe_chip_deps()? The mismatch is still there at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v32 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.
The start/stop pair is single-shot and non-repeatable, tied strictly to the PCI probe/remove lifecycle: kernel vectors are released only by the pcim_msi_release devres at detach, so a second start is rejected.
Startup RPC errors are propagated unchanged. A -ETIMEDOUT here is a real failure, not a "supplier not ready yet" condition: nbl_probe() already deferred this PF in nbl_probe_chip_deps() until the control PF completed probing, and that completion includes the control PF's own start, whose mailbox responder has been live since nbl_dev_init(). Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay the multi-second wait again.
Teardown is best-effort. The MSI-X map is torn down even when the configure RPC failed: a timeout only means the ACK never arrived, while the responder runs to completion before ACKing, so the entry, the intr_net/other_bmap bits and the coherent map table stay owned by the control PF. Those are host resources of that driver, freed by a later successful configuration of this function or by nbl_intr_mgt_stop() - not firmware state. pci_clear_master() is not a safety net for this: on a non-control PF it cannot stop DMA issued with the management PF's BDF.
--- .../net/ethernet/nebula-matrix/nbl/nbl_core.h | 8 + .../nebula-matrix/nbl/nbl_core/nbl_dev.c | 399 +++++++++++++++++- .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 32 ++ 4 files changed, 437 insertions(+), 4 deletions(-)
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +8 -0
@@ -40,4 +40,12 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, struct nbl_init_param *param);void nbl_core_remove (struct nbl_adapter *adapter); +/* +* Single-shot start/stop pair, called once each from PCI probe/remove. +* Not repeatable: MSI-X vectors stay allocated until device detach, so +* a second start on a bound device is rejected by the MSI-X core. +*/ +int nbl_core_start (struct nbl_adapter *adapter); +void nbl_core_stop (struct nbl_adapter *adapter); +#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +395 -4
440 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h +2 -0
@@ -10,5 +10,7 @@ struct nbl_adapter;int nbl_dev_init (struct nbl_adapter *adapter);void nbl_dev_remove (struct nbl_adapter *adapter); +int nbl_dev_start (struct nbl_adapter *adapter); +void nbl_dev_stop (struct nbl_adapter *adapter);#endif
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +32 -0
@@ -16,6 +16,16 @@#include "nbl_include/nbl_def_common.h" #include "nbl_core.h" +int nbl_core_start (struct nbl_adapter *adapter) +{ +return nbl_dev_start (adapter); +} + +void nbl_core_stop (struct nbl_adapter *adapter) +{ +nbl_dev_stop (adapter); +} +struct nbl_adapter *nbl_core_init (struct pci_dev *pdev,struct nbl_init_param *param) {
@@ -235,6 +245,21 @@ static int nbl_probe(struct pci_dev *pdev,int err;nbl_get_func_param (pdev, id->driver_data, ¶m); +/* +* Reject a function with neither capability before touching any +* hardware. nbl_disp_refresh_ctrl_ops() leaves every dispatch op NULL +* for such a function, while nbl_dev_start() reaches cfg_msix_map, +* get_vsi_id, get_eth_id and (on unwind) destroy_msix_map through +* those pointers. The state is reachable through driver_override: +* binding this driver to a function that is not in nbl_id_table (a VF, +* or a non-func-0 PF) makes pci_match_device() pass the dummy ID whose +* driver_data 0 leaves has_ctrl and has_net both clear. +*/ +if (!param.caps.has_ctrl && !param.caps.has_net) { +dev_err (dev,"Function has neither ctrl nor net capability\n" ); +return -EOPNOTSUPP ; + } + err =pcim_enable_device (pdev);if (err) {dev_err (&pdev->dev,"Failed to enable PCI dev, err=%d\n" , err);
@@ -257,8 +282,13 @@ static int nbl_probe(struct pci_dev *pdev, goto out_clear_master; }pci_set_drvdata (pdev, adapter); + err =nbl_core_start (adapter); +if (err) + goto out_core_remove;return 0 ; +out_core_remove: +nbl_core_remove (adapter); out_clear_master:pci_clear_master (pdev);return err;
@@ -271,6 +301,8 @@ static void nbl_remove(struct pci_dev *pdev)if (!adapter)return ;pci_set_drvdata (pdev,NULL ); + +nbl_core_stop (adapter);nbl_core_remove (adapter);pci_clear_master (pdev);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v32 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] nbl_dev_stop() calls nbl_dev_destroy_msix_map() (nbl_dev.c:673) to tear down the per-function pcompleter…
- [Low] Commit message omits a user-visible change in nbl_probe().
- [Low] The comment in nbl_dev_start() (drivers/net/ethernet/nebula- matrix/nbl/nbl_core/nbl_dev.c, around lines 550-560) says the control…
- [Low] The best-effort comment in nbl_dev_stop() (drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c:661-668)…
--
net/nebula-matrix: add common dev start/stop operation
This patch adds nbl_dev_start() and nbl_dev_stop(), 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 tears these down on a best-effort basis.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0@@ -293,3 +534,153 @@ 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 555
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +7
-0+/* +* Startup RPC failures are reported as they are, including the +* -ETIMEDOUT of a 5-6s polling wait against an unresponsive peer. +* nbl_probe() already deferred this PF until the control PF had +* completed probing (nbl_probe_chip_deps()), and that completion +* includes the control PF's own nbl_core_start(); its mailbox +* responder has been live since nbl_dev_init(). A timeout here
[Severity: Low]
Is the part saying the responder "has been live since nbl_dev_init()" accurate? The commit message makes the same claim:
"and that completion includes the control PF's own start, whose mailbox responder has been live since nbl_dev_init()."
On the control PF, received mailbox messages are only processed by clean_mbx_task. That work item gets queued from three places:
nbl_dev_clean_mailbox() -> nbl_dev_clean_mailbox_schedule()
the hardirq handler, registered by nbl_dev_request_mailbox_irq() inside nbl_dev_start()
nbl_chan_clean_queue_subtask()
a self-requeue, which only runs if the task is already running
nbl_chan_send_msg()
the polling send path, which only runs when this function sends an ACK-requested RPC itself
The control PF uses the local management dispatch ops, so it never sends through nbl_chan_send_msg() here. Mailbox routing is first armed by set_mailbox_irq(true) in nbl_dev_enable_mailbox_irq(), and that is the last step of nbl_dev_start().
So doesn't the responder only become live at the end of nbl_dev_start(), and not at nbl_dev_init()?
Keeping -ETIMEDOUT instead of -EPROBE_DEFER still looks right. The reason is that nbl_probe_chip_deps() waits for func 0 to reach DL_DEV_DRIVER_BOUND, which only happens after its whole probe, including nbl_core_start(), has returned. Could the comment and the commit message give that reason instead?
If the dependency were later relaxed to "func 0 finished nbl_dev_init()" because of the current wording, sibling RPCs would hit the multi-second polling timeout.
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+void nbl_dev_stop (struct nbl_adapter *adapter) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +4
-0+/* +* Destroy the hardware MSI-X map now, before the kernel vectors +* are released at device detach (they deliberately stay +* allocated until then - see nbl_dev_clear_interrupt_scheme).
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 668
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* Masks all device vectors and clears the pcompleter map entry. +* +* Best-effort: if the destroy RPC fails, the control PF still owns +* this function's map entry, its intr_net/other_bmap bits and its +* coherent map table. Those are host resources of that driver, +* released either by a later successful configuration of this +* function (reconfiguration recycles them) or by +* nbl_intr_mgt_stop() when the control PF is removed; nothing else +* collects them, so the hardware entry stays as it is until chip +* reset - and nothing requests one.
[Severity: Low]
This isn't a bug, but does "the hardware entry stays as it is until chip reset" match the code? Both recovery paths named just above it rewrite the hardware entry without a chip reset.
nbl_intr_mgt_stop() walks every NBL_INTR_FUNC_CONFIGURED function and calls __nbl_res_intr_prepare_destroy_msix_map(). That disables mailbox routing, invalidates the MSI-X info entries and clears the FUNCTION_MSIX_MAP valid bit:
hw_ops->cfg_msix_map(res_mgt->hw_ops_tbl->priv, func,
false, func_res->msix_map_table.dma,
0, 0, 0);__nbl_res_intr_complete_destroy_msix_map() then zeroes the DMA address.
A later nbl_res_intr_cfg_msix_map() for the same function also invalidates and rewrites the entry on its had_config path.
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 678
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +10
-0+* +* pci_clear_master() on a non-control PF cannot stop DMA using the +* management PF's BDF. +*/ + ret =nbl_dev_destroy_msix_map (dev_mgt); +if (ret) +dev_err (dev_mgt->common->dev, +"Failed to destroy MSI-X map: %d\n" , ret); + +nbl_dev_clear_interrupt_scheme (dev_mgt);
[Severity: Medium]
Is it safe to leave the PCI core's MSI-X shutdown until after the pcompleter FUNCTION_MSIX_MAP has been destroyed here?
nbl_dev_clear_interrupt_scheme() is empty, so the pcim_msi_release devres releases the vectors later, at detach:
pcim_msi_release()
pci_free_irq_vectors()
pci_disable_msix()
pci_msix_shutdown()
pci_msix_mask() for every descriptor
pci_msix_mask() writes the vector control word in the MSI-X table and then does readl(desc->pci.mask_base) to flush the write. Those MMIO writes and non-posted reads reach the function after destroy_msix_map has cleared the valid bit, invalidated the info entries and freed the map table. How the device responds to them depends on the hardware.
nbl_dev_start() uses the opposite order: cfg_msix_map runs before pci_alloc_irq_vectors_affinity().
The rollback in nbl_dev_start() has the same order as stop. That path runs when nbl_dev_init_interrupt_scheme() succeeded and then nbl_dev_request_mailbox_irq() or nbl_dev_enable_mailbox_irq() failed.
The comment above nbl_dev_clear_interrupt_scheme() says that freeing the vectors here "would double-free that callback". Is that the case? pcim_msi_release() only calls pci_free_irq_vectors(), and pci_disable_msix() returns early once MSI-X is already disabled:
if (!pci_msi_enabled() || !dev || !dev->msix_enabled)
return;Would calling pci_free_irq_vectors() before nbl_dev_destroy_msix_map(), in nbl_dev_stop() and in the nbl_dev_start() rollback, let the PCI core finish its table accesses while the mapping is still valid?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +4
-0@@ -235,6 +245,21 @@ static int nbl_probe(struct pci_dev *pdev,int err;nbl_get_func_param (pdev, id->driver_data, ¶m); +/* +* Reject a function with neither capability before touching any +* hardware. nbl_disp_refresh_ctrl_ops() leaves every dispatch op NULL +* for such a function, while nbl_dev_start() reaches cfg_msix_map,
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 261
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +10
-0+* get_vsi_id, get_eth_id and (on unwind) destroy_msix_map through +* those pointers. The state is reachable through driver_override: +* binding this driver to a function that is not in nbl_id_table (a VF, +* or a non-func-0 PF) makes pci_match_device() pass the dummy ID whose +* driver_data 0 leaves has_ctrl and has_net both clear. +*/ +if (!param.caps.has_ctrl && !param.caps.has_net) { +dev_err (dev,"Function has neither ctrl nor net capability\n" ); +return -EOPNOTSUPP ; + }
[Severity: Low]
This isn't a bug, but should the commit message mention this new rejection?
Before this patch, a driver_override bind to a function with driver_data 0 (a VF, or a non-func-0 device) completed probe. Now it fails with -EOPNOTSUPP.
The check itself looks necessary. nbl_disp_refresh_ctrl_ops() leaves every op NULL in that case, and nbl_dev_start() calls disp_ops->cfg_msix_map unconditionally.
The commit message also leaves out the label renames in nbl_dev_init(), where setup_ctrl_dev_fail and setup_err become out_remove_common_dev.
One small note on the comment: it lists only "a VF, or a non-func-0 PF". A foreign device at func 0 still gets has_ctrl = 1 from nbl_get_func_param(), passes this check and runs nbl_core_init() with the local control ops. This patch doesn't change that behaviour.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021062113.2158-1-illusion.wang%40nebula-matrix.com
Jakub Kicinski
maintainerQuoted 2 lines · On Wed, 21 Oct 2026 14:20:59 +0800 illusion.wang wrote:
This series continues and refines the previous v28 NBL NIC driver patch set for Nebula-matrix m18110/m18000 (SNIC s1000) Ethernet adapters.
## Form letter - net-next-closed
The merge window for Linux v7.4 has begun, and the net-next tree is now closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.
Please repost when net-next reopens. There is some uncertainty about how long this merge window will last, so please check
https://netdev.bots.linux.dev/net-next.html
before reposting. net-next _may_ reopen on Nov 2nd.
See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
Signature · 2 lines
pw-bot: defer pv-bot: closed