nbl driver for Nebulamatrix NICs
illusion.wang
maintainerv33 cover nbl driver for Nebulamatrix NICs
Note: This v33 series was previously deferred by pw-bot because net-next tree was closed at posting time. Resend now that net-next is open, no code changes.
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 v32->v33
Link to v32:https://lore.kernel.org/netdev/[email protected]/ 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 | 1528 +++++++++++++++++ .../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 | 727 ++++++++ .../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 | 1286 +++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 342 ++++ .../nbl_hw_leonis/nbl_resource_leonis.c | 370 ++++ .../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 | 851 +++++++++ .../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 | 159 ++ .../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 | 83 + .../nbl/nbl_include/nbl_def_hw.h | 80 + .../nbl/nbl_include/nbl_def_resource.h | 38 + .../nbl/nbl_include/nbl_include.h | 28 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 289 +++- 29 files changed, 7280 insertions(+), 23 deletions(-) create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
Signature · 1 line
2.51.0.windows.1
illusion.wang
maintainerPATCH v33 1/8 net/nebula-matrix: add channel layer
From: illusion wang <[email protected]>
Add a mailbox-based channel layer that carries control messages between PF0 and the other PFs, providing the inter-PF control transport the rest of the driver builds on.
The channel ops table is defined here; queue setup, RX interrupt/polling processing and the upper-layer callers are wired up in later patches of this series.
Implementation notes:
- Message handlers live in an xarray, giving lockless lookup and duplicate-registration rejection (xa_insert returns -EBUSY). Both fire-and-forget and synchronous ACK-based sends are supported.
- ACK wait-slot exhaustion returns -EAGAIN; a full TX descriptor ring returns -EBUSY. Payloads are inline (up to 16 B) or DMA-based (up to 4032 B).
- The per-slot data buffers of each ring are carved out of one contiguous coherent DMA block, so those buffers cost one devres node and one IOMMU mapping per ring instead of one per slot. That is the only part of the ring which is collapsed: the descriptor ring is a second coherent allocation of its own, and the buf[]/wait[] bookkeeping arrays are devm_kcalloc() nodes.
- Mailbox queue resources are devm-managed and the DMA is allocated once during setup. There is no free path, so a channel is set up exactly once per device lifetime and teardown is terminal for it; a re-setup is rejected with -EBUSY.
- RX is driven either from the interrupt or by polling, with cleanup offloaded to a workqueue. Teardown quiesces both queues before the rings can be freed.
- Register access goes through hw_ops. The reg_lock spinlock covers BAR0 register access only; BAR2 mailbox registers and the doorbell write do not take it.
This patch also adds nbl_probe_chip_deps() and calls it from nbl_probe() before nbl_core_init(). For every PF that is not the physical function 0 (has_ctrl == 0) it resolves function 0 in the same slot and:
- fails the probe with -ENODEV if function 0 is absent, and also when the lookup resolves to this device itself: a VF is never the management PF, yet under ARI its devfn decodes to function 0 of a slot;
- returns -EPROBE_DEFER unless function 0 is bound to *this* driver 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. The link is created while that lock is still held, so function 0 can neither bind nor unbind in between.
A failed trylock is retried a bounded number of times before the probe is deferred. The retry is needed because a single failure is not
self-healing: function 0 binds with device_lock(func0) held and driver_bound() calls driver_deferred_probe_trigger() before releasing it, so the deferred probe work can reach this probe while the lock is still taken. driver_probe_device() only re-arms that work when deferred_trigger_count changes during the probe, and it does not here, so a bare -EPROBE_DEFER would leave this PF on deferred_probe_pending_list with nothing scheduled to run it again. The wait is bounded rather than a plain device_lock() because device_lock(funcN) is held throughout, so waiting indefinitely would deadlock against __pci_bus_lock(); giving up and deferring releases it and lets the other side make progress. A holder that is not part of a bind - __pci_bus_lock() during AER recovery or a bus/slot reset, pci_reset_function() through sysfs, an sriov_numvfs write - can outlast the budget and no bind event follows those, so the sibling PF then stays deferred until some unrelated driver binding elsewhere re-triggers deferred probing.
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 | 1528 +++++++++++++++++ .../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 | 42 + .../nbl/nbl_include/nbl_include.h | 3 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 190 +- 14 files changed, 2496 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 +1528 -0
1,528 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 +42 -0
48 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 +185 -5
244 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 1/8] net/nebula-matrix: add channel layer
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · 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).
- [High] net/nebula-matrix: device_trylock() loop in nbl_probe_chip_deps()
- [Medium] Channel lifetime against teardown uses a hand-rolled reader count instead of a real lock or refcount primitive.
- [Medium] nbl_chan_clean_queue() treats NBL_CHAN_RX_DESC_USED alone as proof that the device delivered a message.
- [Low] The kernel-doc on nbl_hw_ops::get_host_pf_mask (nbl_def_hw.h) contradicts the code this patch adds.
- [Low] nbl_common_create_wq() formats the name with snprintf(wq_name, ..., "nbl_wq_%s", pci_name(common->pdev)) and then calls…
--
net/nebula-matrix: add channel layer
This commit adds a mailbox-based channel layer that carries control messages between PF0 and the other PFs. It also adds hw_ops for the mailbox queue registers, and nbl_probe_chip_deps() to order sibling PF probes behind function 0 using a device link.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static int nbl_chan_teardown_queue (struct nbl_channel_mgt *chan_mgt, +u8 chan_type) +{
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +9
-0+while (wait_event_timeout (chan_info->inflight_wait, +atomic_read (&chan_info->inflight_tx_cnt) ==0 , +msecs_to_jiffies (5000 )) ==0 ) +dev_warn (chan_mgt->common->dev, +"teardown: still waiting for %d inflight sender(s)\n" , +atomic_read (&chan_info->inflight_tx_cnt)); + +/* +* Join the last exiting sender through state_lock. A sender drops
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +5
-0+* That trailing unlock is why this is one acquire/release pair and +* not a handshake that ends the sender: mutex_unlock() may still be +* touching the mutex structure after it has released it, so this does +* not prove the sender has returned from it (see +* Documentation/locking/mutex-design.rst). It is safe only because
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 447
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+* chan_info - mutexes included - is devm-allocated and released at +* detach, long after this teardown, and because nothing frees it +* here. Freeing chan_info or calling mutex_destroy() at this point +* would need a sender-exit completion the channel does not have. +* +* shutdn blocks new senders, so one acquire/release pair is +* sufficient. +*/ +mutex_lock (&chan_info->state_lock); +mutex_unlock (&chan_info->state_lock);
[Severity: Medium]
Should this drain use a real lock or refcount primitive instead of a hand-rolled reader count?
nbl_chan_send_msg() checks shutdn and then calls atomic_inc(&chan_info->inflight_tx_cnt) on entry. On exit it calls atomic_dec_and_test() and wake_up() in out_clean_inflight. Teardown polls that counter in a loop with no upper bound, then uses an empty lock/unlock of state_lock as the join.
Lockdep cannot see the counter. As the comment above says, the join does not prove the last sender has left mutex_unlock(). If teardown ever freed chan_info or called mutex_destroy() here, that would become a use-after-free.
An rwsem held for read across nbl_chan_send_msg() and taken for write here would give the same semantics with lockdep coverage and a real exit handshake. So would a refcount plus a completion. Would either of those work here?
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +3
-0+static void nbl_chan_clean_queue (struct nbl_channel_mgt *chan_mgt, +struct nbl_chan_info *chan_info) +{
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +4
-0+while (le16_to_cpu (READ_ONCE (rx_desc->flags)) & +BIT (NBL_CHAN_RX_DESC_USED )) { + flags =le16_to_cpu (READ_ONCE (rx_desc->flags)); +
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c line 964
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c new file +10
-0+if (READ_ONCE (chan_info->shutdn)) +break ; +if (!(flags &BIT (NBL_CHAN_RX_DESC_WRITE ))) +dev_dbg (dev, +"mailbox rx flag 0x%x missing NBL_CHAN_RX_DESC_WRITE\n" , + flags); + +/* Make sure hardware written descriptor visible to CPU */ +dma_rmb (); +nbl_chan_recv_msg (chan_mgt, rx_buf->va);
[Severity: Medium]
What happens if the device completes a descriptor with NBL_CHAN_RX_DESC_USED set but NBL_CHAN_RX_DESC_WRITE clear?
This path only logs at dev_dbg and still passes rx_buf->va to nbl_chan_recv_msg(). The RX buffers are fixed slots in one coherent block, and nbl_chan_advance_rx_ring() does not clear a slot when it recycles it.
The driver would then parse the message left in the slot from the previous ring lap: the old msg_type, srcid and msgid, with the payload taken from the old data_len/buf_len. That message would go to its handler a second time. Would it be safer to recycle such a descriptor without dispatching it?
Also, nbl_chan_recv_msg() takes the message length only from the header inside the buffer. It never compares it with the length the device writes back into the RX descriptor. NBL_CHAN_BUF_LEN bounds both lengths, so there is no out-of-bounds access, but a short DMA would go unnoticed.
The tree does not document whether the hardware can post USED without WRITE.
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c line 23
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c new file +6
-0+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 );
[Severity: Low]alloc_workqueue_noprof() is declared __printf(1, 4), so wq_name is used as a format string here with no arguments. pci_name() never contains '%' today, so this works.
Could the format be passed directly instead?
common->wq = alloc_workqueue("nbl_wq_%s", WQ_UNBOUND, 0,
pci_name(common->pdev));That also removes the wq_name[] stack buffer and the snprintf() truncation step.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h line 45
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +8
-0+* This op only returns the raw register value and does not validate +* it. Neither consumer exists yet at the commit that introduces it: +* the resource layer, which validates the value, and the channel +* layer, which programs the mailbox QINFO table from it, both arrive +* later in this series, and validation runs before the channel layer +* reads the mask. +*/ +void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt,u32 *pf_mask);
[Severity: Low]
This isn't a bug, but is this kernel-doc accurate? This same commit adds the channel layer. nbl_chan_cfg_qinfo_map_table() already calls hw_ops->get_host_pf_mask() and calls cfg_mailbox_qinfo() for every clear bit. At this commit nothing validates the mask.
The comment in nbl_chan_cfg_qinfo_map_table() also says the validator and every caller "arrive in later patches of this series". Once the series is applied, nbl_res_init_pf_num() and nbl_dev_setup_chan_qinfo() both exist, so both comments will be out of date in the merged tree.
Could they describe the final code instead of the order of the series?
[ ... ]
Quoted 158 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +151
-0@@ -67,6 +84,164 @@ static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, param->caps.has_ctrl =1 ; } +/* +* Establish chip-wide dependencies for this PF: +* - for every non-management PF, add a consumer->management PF device +* link. The driver core then guarantees (sysfs unbind, driver +* unregister, hot-unplug alike) that this consumer is released +* BEFORE the func 0 supplier, which is the only teardown order in +* which the chip-global firmware deinit is safe. +* +* The management PF is addressed by the deterministic identity +* (domain, bus, slot, func 0) instead of any name-based scan: hardware +* guarantees PFs are contiguous from func 0 in the same slot. +* +* The func 0 device must already be bound to this driver. While func 0 +* is still probing, its chip-global init (mailbox QINFO map programming, +* datapath setup) can race a sibling's mailbox setup, and a link created +* while the supplier has no driver starts DORMANT and is force-promoted +* (with a WARN backtrace) by device_links_driver_bound() when this probe +* ends, so it never delivers the unbind-order guarantee. +* +* The link is a persistent managed link with DL_FLAG_AUTOPROBE_CONSUMER: +* the core force-unbinds this consumer when func 0 unbinds (keeping the +* teardown order) and re-queues it for probe when func 0 binds again, so +* the sibling PFs and their ports come back without a manual rebind. +* AUTOREMOVE_CONSUMER would delete the link on unbind and cannot be +* combined with AUTOPROBE_CONSUMER (device_link_add() returns NULL for +* that pair). The link is therefore not auto-purged on a failed probe: +* it lives with the two devices and is dropped when either is removed. +* The pointer device_link_add() returns is never dereferenced. +* +* Return: 0 on success, negative errno on failure. +*/ +static int nbl_probe_chip_deps (struct pci_dev *pdev,bool has_ctrl) +{ +struct pci_dev *mgt; +int retries; + +if (has_ctrl) +return 0 ; + + mgt =pci_get_domain_bus_and_slot (pci_domain_nr (pdev->bus), + pdev->bus->number, +PCI_DEVFN (PCI_SLOT (pdev->devfn),0 )); +if (!mgt) { +dev_err (&pdev->dev, +"management PF (func 0) not found on this chip\n" ); +return -ENODEV ; + } + +/* +* That identity is meaningless for a VF: under ARI a VF's devfn +* decodes to function 0 of a slot, so the lookup can resolve to the +* VF itself. A VF is never the management PF, so stop here instead +* of taking our own device lock below. +*/ +if (mgt == pdev) { +dev_err (&pdev->dev, +"management PF lookup matched this device\n" ); +pci_dev_put (mgt); +return -ENODEV ; + } + +/* +* 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. +* +* Holding the lock is what makes the check and the link creation +* below atomic with respect to func 0: it both gains its driver +* (driver_bound() -> device_links_driver_bound()) and loses it +* (__device_release_driver() -> device_links_driver_cleanup()) +* under device_lock(func0), so func 0 can change neither driver nor +* links.status while we hold it. +* +* One failed trylock is nevertheless not enough to defer on. Func 0 +* binds with device_lock(func0) held, and driver_bound() calls +* driver_deferred_probe_trigger() before it releases that lock, so +* the deferred probe work it queues can re-probe this PF while func +* 0's lock is still taken. driver_probe_device() only re-arms that +* work when deferred_trigger_count changes *during* the probe, which +* it does not here: func 0's increment happened before this probe +* read the count. A bare -EPROBE_DEFER would therefore leave this +* PF on deferred_probe_pending_list with nothing scheduled to run +* it again. Retrying closes that window - driver_bound() has only a +* bus_notify() and a kobject_uevent() left before it drops the lock. +* +* The retry budget is what keeps this safe. device_lock(funcN) is +* held for the whole loop, so waiting indefinitely would deadlock +* against __pci_bus_lock(); giving up and deferring releases it and +* lets the other side make progress. A holder that is not part of a +* bind - __pci_bus_lock() during AER recovery or a bus/slot reset, +* pci_reset_function() through sysfs, an sriov_numvfs write - can +* outlast the budget, and no bind event follows those, so this PF +* then stays deferred until some later deferred-probe trigger from +* anywhere in the system. There is no way to force one from here. +*/ +for (retries =0 ; !device_trylock (&mgt->dev); retries++) { +if (retries ==NBL_MGT_LOCK_MAX_RETRIES ) { +dev_dbg (&pdev->dev, +"management PF device lock busy after %u retries, deferring probe\n" , + retries); +pci_dev_put (mgt); +return -EPROBE_DEFER ; + } +usleep_range (NBL_MGT_LOCK_RETRY_MIN_US , +NBL_MGT_LOCK_RETRY_MAX_US ); + } + +/* +* 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 what recovers from this: 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. That covers a func 0 +* that is not bound yet. It does not cover a func 0 that is bound +* while something else holds its device lock, which is what the +* retry loop above is for and what its budget cannot fully rule out. +*/ +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 ; + } + +/* +* Create the link while func 0's lock is still held, so that func 0 +* cannot change state in between. With the supplier bound and this +* consumer PROBING, device_link_init_status() starts the link in +* DL_STATE_CONSUMER_PROBE: that is the state +* device_links_driver_bound() expects when this probe finishes, and +* it is what device_links_busy() reports to func 0's own unbind, so +* func 0 cannot be released underneath this PF. +*/ +if (!device_link_add (&pdev->dev, &mgt->dev, +DL_FLAG_AUTOPROBE_CONSUMER )) { +device_unlock (&mgt->dev); +dev_err (&pdev->dev, +"failed to create device link to management PF\n" ); +pci_dev_put (mgt); +return -ENOMEM ; + }
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static void nbl_get_func_param(struct pci_dev *pdev, kernel_ulong_t driver_data, · line 247
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +7
-0+ +device_unlock (&mgt->dev); +pci_dev_put (mgt); + +return 0 ; +} +static int nbl_probe (struct pci_dev *pdev,const struct pci_device_id *id) {
[Severity: High]
Is a sleeping trylock loop on another device's mutex the right way to order these probes?
nbl_probe_chip_deps() runs under device_lock(funcN). It polls device_trylock(&mgt->dev) up to NBL_MGT_LOCK_MAX_RETRIES times with usleep_range() in between, only to avoid the funcN -> func0 order against __pci_bus_lock(). A trylock retry loop that sidesteps a lock ordering problem usually means the locking design needs to change. Here it also does not fully close the window.
When the budget runs out, the probe returns -EPROBE_DEFER. Nothing guarantees a later driver_deferred_probe_trigger() after that. Func0's dev->mutex can be held for more than roughly 50-100 ms by something that is not a bind:
- __pci_bus_lock() during AER recovery or a slot reset
- a sysfs reset of func0
- an sriov_numvfs write
In that case the sibling PF is left on deferred_probe_pending_list with nothing scheduled to retry it. It stays unbound until some unrelated driver binds elsewhere in the system, and the only trace is a dev_dbg(). The commit message describes this case, but a PF that silently never comes back after a reset is still a user-visible failure.
The readiness check under that lock also reads mgt->dev.links.status. That is driver core internal state, not something a driver is expected to inspect.
Could the dependency be expressed without taking func0's lock from a sibling's probe at all? For example:
- func0 could set up the ordering from its own probe, once its chip-global init has finished, so the driver core's supplier handling does the deferral and re-probe;
- or the siblings could learn over the mailbox that func0 is ready.
Whichever approach fits, the sibling should not rely on a deferred-probe retrigger that may never come.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 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 | 335 ++++++++++++++++++ .../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, 759 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 +335 -0
335 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,
@@ -43,9 +56,22 @@ struct nbl_hw_ops {* reads 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
@@ -11,6 +11,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"
@@ -37,6 +38,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;
@@ -52,7 +54,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:
@@ -61,6 +69,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter); }
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 2/8] net/nebula-matrix: add common resource implementation
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This commit adds the k_pf_mask validator, nbl_res_init_pf_num(), but two comments about it are wrong.
- [Low] net/nebula-matrix: redundant single-implementation resource and hw ops tables
--
net/nebula-matrix: add common resource implementation
This commit adds a chip-agnostic resource layer to the Nebula Matrix driver. On the control PF at probe time it validates the firmware PF mask, builds per-PF BDF, Ethernet port and VSI tables, and provides VSI/PF/Eth ID conversion helpers.
The resource layer is hooked into nbl_core_init() after the channel layer.
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +2
-0+static int nbl_res_init_pf_num (struct nbl_resource_mgt *res_mgt) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 227
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +6
-0+* This is the only validation of the mask in the driver. The channel +* layer reads the same raw register value to program the mailbox +* QINFO table and assumes the layout checked here, so it depends on +* this running first: resource init completes before the channel +* layer is set up. +*/
[Severity: Low]
This isn't a bug, but is this ordering description accurate? In this same patch, nbl_core_init() sets up the channel layer before the resource layer:
nbl_core_init()
nbl_hw_init_leonis()
nbl_chan_init_common()
nbl_res_init_leonis()
nbl_res_start()
nbl_res_init_pf_num()The ordering that actually protects QINFO programming looks different. The only user of the raw mask is nbl_chan_cfg_qinfo_map_table(). Later in the series it is called from nbl_dev_setup_chan_qinfo(), inside nbl_dev_init(), on the control PF only. That happens after nbl_res_init_leonis(), but well after channel layer setup.
Would it be more accurate to say the validation has to run before QINFO is first programmed, rather than before the channel layer is set up?
Also, the existing comment in nbl_chan_cfg_qinfo_map_table() in nbl_channel.c still says:
* 0xfe/0xfc/0xf0. Nothing enforces that here: the resource layer
* that validates the mask, and every caller of this op, arrive in
* later patches of this series.
This patch adds that resource layer. Should this comment be updated as well?
The code behaves correctly as it stands, so this only concerns the comments. Both comments are still unchanged at the end of the series.
[ ... ]
Quoted 326 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +325
-0@@ -0,0 +1,335 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Nebula Matrix Limited. +*/ +#include <linux/device.h> +#include <linux/pci.h> +#include <linux/bits.h> +#include "nbl_resource_leonis.h" + +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, +}; + +static struct nbl_resource_mgt * +nbl_res_setup_res_mgt (struct nbl_common_info *common) +{ +struct nbl_resource_info *resource_info; +struct nbl_resource_mgt *res_mgt; +struct device *dev = common->dev; + + res_mgt =devm_kzalloc (dev,sizeof (*res_mgt),GFP_KERNEL ); +if (!res_mgt) +return ERR_PTR (-ENOMEM ); + res_mgt->common = common; + + resource_info = +devm_kzalloc (dev,sizeof (*resource_info),GFP_KERNEL ); +if (!resource_info) +return ERR_PTR (-ENOMEM ); + res_mgt->resource_info = resource_info; + +return res_mgt; +} + +static struct nbl_resource_ops_tbl * +nbl_res_setup_ops (struct device *dev,struct nbl_resource_mgt *res_mgt) +{ +struct nbl_resource_ops_tbl *res_ops_tbl; + + 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) +return ERR_PTR (-EINVAL ); + res_ops_tbl->ops = &res_ops; + res_ops_tbl->priv = res_mgt; + +return res_ops_tbl; +} + +static int nbl_res_ctrl_dev_setup_eth_info (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct device *dev = res_mgt->common->dev; +struct nbl_eth_info *eth_info; +u32 eth_bitmap =0 ; +u32 eth_num =0 ; +u32 fw_port_num; +int i; + + eth_info =devm_kzalloc (dev,sizeof (*eth_info),GFP_KERNEL ); +if (!eth_info) +return -ENOMEM ; + + res_mgt->resource_info->eth_info = eth_info; + + fw_port_num = res_mgt->resource_info->board_info.eth_num; + + hw_ops->get_fw_eth_map (res_mgt->hw_ops_tbl->priv, ð_bitmap); +if (eth_bitmap & ~((1 <<NBL_MAX_ETHERNET ) -1 )) { +dev_err (dev,"FW reported invalid eth_bitmap 0x%x\n" , + eth_bitmap); +return -EINVAL ; + } +if (fw_port_num !=hweight32 (eth_bitmap)) { +dev_err (dev,"FW inconsistency: port_num=%u, bitmap=0x%x\n" , + fw_port_num, eth_bitmap); +return -EINVAL ; + } +/* +* Firmware is ready before probe. Valid port counts are 1/2/4; +* 0 (invalid config), 3 (unsupported topology), and >4 (exceeds +* hardware max) are all rejected with -EINVAL. +*/ +if (fw_port_num ==0 || fw_port_num ==3 || + fw_port_num >NBL_MAX_ETHERNET ) { +dev_err (dev,"FW reports %u Ethernet ports, unsupported (valid: 1/2/4)\n" , + fw_port_num); +return -EINVAL ; + } + eth_info->eth_num = fw_port_num; +/* Intentional design constraint: each PF maps to exactly one +* Ethernet port. This couples PF identity to port identity +* and is required by nbl_res_get_eth_id() which indexes +* eth_info->eth_id[] by relative PF id. +*/ +if (res_mgt->common->max_pf != eth_info->eth_num) { +dev_err (dev,"Invalid PF-to-port topology: max_pf=%u, eth_num=%u\n" , + res_mgt->common->max_pf, eth_info->eth_num); +return -EINVAL ; + } + +/* +* Any subset of valid bitmap bits is accepted (e.g. 0/1, 0/2, +* 1/3, etc.). Firmware only needs to report the correct count +* of active ports; no hard-coded fixed bit positions required. +* eth_id[] is filled in ascending bitmap-bit order, so the Nth +* relative PF owns the Nth logical port (max_pf == eth_num is +* enforced above). +*/ +for (i =0 ; i <NBL_MAX_ETHERNET ; i++) { +if ((1 << i) & eth_bitmap) { + eth_info->eth_id[eth_num] = i; + eth_num++; + } + } + +return 0 ; +} + +static int nbl_res_ctrl_dev_sriov_info_init (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +struct nbl_hw_mgt *p = res_mgt->hw_ops_tbl->priv; +struct nbl_common_info *common = res_mgt->common; +struct nbl_sriov_info *sriov_info; +struct device *dev = common->dev; +u8 hw_bus =0 ; +u16 function; +u16 func_id; + + hw_ops->get_real_bus (p, &hw_bus); +if (common->function + common->max_pf >NBL_MAX_PF ) { +dev_err (dev,"PF count exceeds available function space\n" ); +return -EINVAL ; + } + sriov_info =devm_kcalloc (dev, common->max_pf, +sizeof (*sriov_info),GFP_KERNEL ); +if (!sriov_info) +return -ENOMEM ; + + res_mgt->resource_info->sriov_info = sriov_info; +/* +* Real bus number of the control PF; +* the BDF table below is built from it. +*/ + common->hw_bus = hw_bus; + +for (func_id =0 ; func_id < common->max_pf; func_id++) { + sriov_info = res_mgt->resource_info->sriov_info + func_id; + function = common->function + func_id; + sriov_info->bdf =PCI_DEVID (common->hw_bus, +PCI_DEVFN (common->devid, function)); + } + +return 0 ; +} + +static int nbl_res_ctrl_dev_vsi_info_init (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_eth_info *eth_info = res_mgt->resource_info->eth_info; +struct nbl_common_info *common = res_mgt->common; +struct device *dev = common->dev; +struct nbl_vsi_info *vsi_info; +int i; + + vsi_info =devm_kzalloc (dev,sizeof (*vsi_info),GFP_KERNEL ); +if (!vsi_info) +return -ENOMEM ; + + res_mgt->resource_info->vsi_info = vsi_info; +/* +* case 1 one port(1pf) +* pf0 (NBL_VSI_SERV_PF_DATA_TYPE) vsi is 0 +* case 2 two port(2pf) +* pf0,pf1(NBL_VSI_SERV_PF_DATA_TYPE) vsi is 0,512 +* case 3 four port(4pf) +* pf0,pf1,pf2,pf3(NBL_VSI_SERV_PF_DATA_TYPE) vsi is 0,256,512,768 +*/ + + vsi_info->num = eth_info->eth_num; +/* +* eth_num can be 1/2/4: +* - 2/4 ports use dedicated gap constants; +* - 1 port falls back to NBL_DEFAULT_VSI_ID_GAP (1024). +* All three values produce valid base_id offsets. +*/ +for (i =0 ; i < vsi_info->num; i++) { + vsi_info->serv_info[i][NBL_VSI_SERV_PF_DATA_TYPE ].base_id = + i *nbl_vsi_id_gap (vsi_info->num); + vsi_info->serv_info[i][NBL_VSI_SERV_PF_DATA_TYPE ].num =1 ; + } + +return 0 ; +} + +static int nbl_res_init_pf_num (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; +u32 exp_contiguous_mask =0 ; +u32 pf_mask =0 ; +u32 pf_num =0 ; +int i; + + hw_ops->get_host_pf_mask (res_mgt->hw_ops_tbl->priv, &pf_mask); + +/* +* k_pf_mask register rule: +* bit N == 0 -> PF#N enabled; bit N == 1 -> PF#N masked out. +* Hardware constraint: bit0 is PF0's mask bit; driver requires +* PF0 enabled as management PF, so bit0 must be clear. +* All-zero pf_mask means all PF0~PF7 are enabled, which is unsupported +* by the driver +* +* Product firmware constraint: only 3 valid configurations supported: +* 1 PF (PF0 only): pf_num = 1, mask = 0xfe +* 2 PFs (PF0,PF1): pf_num = 2, mask = 0xfc +* 4 PFs (PF0~PF3): pf_num = 4, mask = 0xf0 +* No other PF count or sparse/non-contiguous PF layout is allowed. +* +* This is the only validation of the mask in the driver. The channel +* layer reads the same raw register value to program the mailbox +* QINFO table and assumes the layout checked here, so it depends on +* this running first: resource init completes before the channel +* layer is set up. +*/ +for (i =0 ; i <NBL_MAX_PF ; i++) { +if (!(pf_mask & (1 << i))) + pf_num++; + } + +/* +* Sanity check: enabled PFs must be contiguous starting from PF0. +* Current resource framework uses relative PF id, sparse PF layout +* will cause mismatch between resource layer and hardware func_id. +*/ +for (i =0 ; i < pf_num; i++) + exp_contiguous_mask |=BIT (i); +if ((pf_mask & exp_contiguous_mask) !=0 ) { +dev_err (res_mgt->common->dev, +"pf_mask 0x%08x: non-contiguous enabled PF, unsupported\n" , + pf_mask); +return -EINVAL ; + } + +/* Only allow product-specified PF count: 1 / 2 / 4 */ +if (pf_num !=1 && pf_num !=2 && pf_num !=4 ) { +dev_err (res_mgt->common->dev, +"Invalid pf_num=%u (mask=0x%08x), only 1/2/4 PFs supported\n" , + pf_num, pf_mask); +return -EINVAL ; + } + + res_mgt->common->max_pf = pf_num; + +return 0 ; +} + +static void nbl_res_init_board_info (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_hw_ops *hw_ops = res_mgt->hw_ops_tbl->ops; + + hw_ops->get_board_info (res_mgt->hw_ops_tbl->priv, + &res_mgt->resource_info->board_info); +} + +static int nbl_res_start (struct nbl_resource_mgt *res_mgt) +{ +struct nbl_common_info *common = res_mgt->common; +int ret =0 ; + +if (common->has_ctrl) { +nbl_res_init_board_info (res_mgt); + + ret =nbl_res_init_pf_num (res_mgt); +if (ret) +return ret; + + ret =nbl_res_ctrl_dev_sriov_info_init (res_mgt); +if (ret) +return ret; + + ret =nbl_res_ctrl_dev_setup_eth_info (res_mgt); +if (ret) +return ret; + + ret =nbl_res_ctrl_dev_vsi_info_init (res_mgt); +if (ret) +return ret; + } + +return 0 ; +} + +int nbl_res_init_leonis (struct nbl_adapter *adap) +{ +struct nbl_channel_ops_tbl *chan_ops_tbl = adap->intf.channel_ops_tbl; +struct nbl_hw_ops_tbl *hw_ops_tbl = adap->intf.hw_ops_tbl; +struct nbl_common_info *common = &adap->common; +struct nbl_resource_ops_tbl *res_ops_tbl; +struct device *dev = &adap->pdev->dev; +struct nbl_resource_mgt *res_mgt; +int ret; + + res_mgt =nbl_res_setup_res_mgt (common); +if (IS_ERR (res_mgt)) { + ret =PTR_ERR (res_mgt); +return ret; + } + res_mgt->chan_ops_tbl = chan_ops_tbl; + res_mgt->hw_ops_tbl = hw_ops_tbl; + + ret =nbl_res_start (res_mgt); +if (ret) +return ret; + + res_ops_tbl =nbl_res_setup_ops (dev, res_mgt); +if (IS_ERR (res_ops_tbl)) { + ret =PTR_ERR (res_ops_tbl); +return ret; + } + adap->intf.resource_ops_tbl = res_ops_tbl; + adap->core.res_mgt = res_mgt; +
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c line 335
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c new file +10
-0+return 0 ; +} + +void nbl_res_remove_leonis (struct nbl_adapter *adap) +{ +/* +* No resource release here because all memory uses devm managed +* allocation +*/ +}
[Severity: Low]
Does the resource layer need its own ops table? struct nbl_resource_ops and struct nbl_resource_ops_tbl have exactly one implementation, res_ops in nbl_resource_leonis.c, and that is still the only one at the end of the series.
nbl_res_setup_ops() devm-allocates a wrapper whose only job is to hold &res_ops and res_mgt. It then checks get_vsi_id and get_eth_id for NULL, but both are statically initialized a few lines above in the same file, so the -EINVAL branch can never be taken.
The same applies to struct nbl_hw_ops, which this patch extends with flush_write, get_real_bus, get_fw_eth_map and get_board_info:
- hw_ops in nbl_hw_leonis.c is its only implementation.
- nbl_hw_setup_ops() adds more NULL checks on static callbacks.
- nbl_resource_leonis.c calls the leonis hardware helpers indirectly
through res_mgt->hw_ops_tbl->ops and ->priv instead of directly.
- res_mgt->chan_ops_tbl is stored but never used in this patch.
On v22 Jakub asked for abstractions with a single implementation to be removed until a second implementation actually exists:
https://lore.kernel.org/r/[email protected]
The dispatch layer later in the series does have two real backends. It makes local calls on the control PF and mailbox RPCs on the other PFs, so that indirection looks justified.
Could the series keep only that layer? The dispatch code would call nbl_res_func_id_to_vsi_id() and nbl_res_get_eth_id() directly, and the resource code would call the leonis hw helpers directly. That would drop nbl_resource_ops_tbl, nbl_hw_ops_tbl and the setup_ops() NULL checks.
If a second chip that needs these tables is planned, could the commit message say so?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 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, so a reconfiguration neither frees and reallocates the table nor has to take the destroy-path quiesce window before the old vectors are recycled. The first configuration of a function still takes one invalidate + flush + quiesce window before the table is written; that window belongs to the first configuration only and is not part of the reconfiguration path. 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, take a bounded best-effort ~1ms hardware DMA quiescence window, 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. nbl_probe() now leaves bus mastering disabled until nbl_core_init() has returned, so this scrub runs before the device can issue a single fetch against a stale VALID entry - those fetches are bus-master reads, and a stale entry points at memory this kernel may already have reallocated. Everything between pci_set_master() and the scrub is host-side setup plus MMIO and does not wait for the device. The gvec-indexed INFO/FID tables are not scrubbed; their entries are rewritten before a map entry is armed again.
Known limitation - MSI-X map table DMA quiescence:
The chip exposes no idle or completion status for a pcompleter fetch of a map table, so the only ordering available anywhere in this module is "clear VALID -> flush_write() -> bounded delay". The delay is sized well above the tables' worst-case fetch/response latency, but it is a best-effort approximation and not a guarantee; a caller that cannot tolerate the residual risk must keep the table allocated for the lifetime of the function rather than rely on it.
Two things narrow the window rather than close it. Tables are freed only after that delay, and nbl_remove() now clears Bus Master Enable before any teardown runs, so the device cannot start a new fetch once teardown has begun and the residual window covers in-flight requests only. Neither helps a sibling PF's map destroyed at runtime: those fetches are tagged with the control PF's BDF, so clearing bus mastering on the sibling does not stop them. Runtime destroys of sibling maps only become reachable with the mailbox RPC added later in this series.
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 | 851 ++++++++++++++++++ .../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 90 ++ .../nbl/nbl_include/nbl_def_hw.h | 9 + .../nbl/nbl_include/nbl_def_resource.h | 6 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 48 +- 12 files changed, 1291 insertions(+), 14 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;
@@ -288,6 +293,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 ;
@@ -328,8 +337,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 +851 -0
851 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 +90 -0
110 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h +9 -0
@@ -12,6 +12,13 @@ struct nbl_board_port_info;struct nbl_hw_mgt ;struct nbl_adapter ;struct nbl_hw_ops { +void (*cfg_msix_map)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,dma_addr_t dma_addr,u8 bus, +u8 devid,u8 function); +void (*cfg_msix_info)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool valid,u16 interrupt_id,u8 bus, +u8 devid,u8 function, +bool net_msix_mask_en);/** * flush_write - Flush posted MEMORY-BAR writes * @hw_mgt: hardware management context
@@ -60,6 +67,8 @@ struct nbl_hw_ops {void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt,u16 func_id,u8 bus,u8 devid,u8 function); +void (*set_mailbox_irq)(struct nbl_hw_mgt *hw_mgt,u16 func_id, +bool en_msix,u16 gvec);void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt,u32 *eth_map);/** * get_board_info - Fetch board info from firmware
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h +6 -0
@@ -12,6 +12,12 @@ struct nbl_resource_mgt;struct nbl_adapter ;struct nbl_resource_ops { +int (*cfg_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en); +int (*destroy_msix_map)(struct nbl_resource_mgt *res_mgt,u16 func_id); +int (*set_mailbox_irq)(struct nbl_resource_mgt *res_mgt,u16 func_id, +u16 vector_id,bool en_msix);int (*get_vsi_id)(struct nbl_resource_mgt *res_mgt,u16 func_id,u16 type,u16 *vsi_id); int (*get_eth_id)(struct nbl_resource_mgt *res_mgt, u16 func_id,
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +39 -9
72 lines not on this page · raw message
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 3/8] net/nebula-matrix: add intr resource implementation
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message and an in-code comment describe the reconfiguration path the opposite way from how the code behaves.
--
net/nebula-matrix: add intr resource implementation
This adds an nbl_interrupt module that manages the chip-internal MSI-X vector index space for the control PF. It also programs the FUNCTION_MSIX_MAP, HOST_MSIX_INFO and MSIX_FID tables, using a clear-VALID, flush, delay sequence for teardown. The patch also moves pci_set_master() to after nbl_core_init() and clears bus mastering before teardown in nbl_remove().
Quoted 8 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, so a reconfiguration neither frees and reallocates the table nor has to take the destroy-path quiesce window before the old vectors are recycled. The first configuration of a function still takes one invalidate + flush + quiesce window before the table is written; that window belongs to the first configuration only and is not part of the reconfiguration path.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +0
-0@@ -0,0 +1,851 @@
[ ... ]
Quoted 2 lines
+/**
+ *nbl_res_intr_cfg_msix_map- allocate & program MSI-X mapping table
[ ... ]
Quoted 7 lines
+ * Allocate interrupt vectors; MSIX coherent DMA table is allocated once
+ * per function on first configuration, entries are rewritten while the
+ * map is invalidated on subsequent reconfigurations. No free/realloc of
+ * DMA table on vector count changes. This removes the DMA table
+ * free/realloc cycle. On reconfiguration the map VALID bit is cleared
+ * and the hardware-DMA quiesce window is observed (lock held) before old
+ * vectors are recycled and the table is rewritten.
[ ... ]
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +7
-0+if (had_config) { + old_interrupts = + intr_mgt->func_intr_res[func_id].interrupts; + old_num = intr_mgt->func_intr_res[func_id].num_interrupts; + + ret =__nbl_res_intr_set_mailbox_irq (intr_mgt, res_mgt, func_id, +0 , false);
[ ... ]
Quoted 15 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +15
-0+for (j =0 ; j < old_num; j++) { + hw_ops->cfg_msix_info (res_mgt->hw_ops_tbl->priv, + func_id, false, + old_interrupts[j], +0 ,0 ,0 , false); + } + hw_ops->cfg_msix_map (res_mgt->hw_ops_tbl->priv, func_id, + false, official_tbl->dma, +0 ,0 ,0 ); + hw_ops->flush_write (res_mgt->hw_ops_tbl->priv); + +nbl_intr_quiesce_wait (); + +nbl_intr_release_bitmap (intr_mgt, res_mgt, old_interrupts, + old_num);
[ ... ]
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +8
-0+/* +* First configuration of this function. Re-invalidate the entry +* and take a quiesce window before the table below is rewritten: +* while the entry is VALID the pcompleter could fetch a table +* that is being written and route stale gvecs. +* +* This is a second, real quiesce window rather than part of the +* reconfiguration path, and it costs one delay per function on the
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c line 570
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c new file +10
-0+* first configuration only. Reusing the table removes the +* free/realloc cycle and the destroy-path quiesce window from +* every *re*configuration; it does not remove this one. +*/ +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 (); + }
[Severity: Medium]
The commit message says a reconfiguration does not "take the destroy-path quiesce window before the old vectors are recycled". The comment above the !had_config block in nbl_res_intr_cfg_msix_map() says the same thing.
The had_config branch above seems to do the opposite, though. It runs the destroy sequence:
__nbl_res_intr_set_mailbox_irq(..., false)
cfg_msix_info(false) for each old gvec
cfg_msix_map(false, official_tbl->dma)
flush_write()
It then calls nbl_intr_quiesce_wait(), the same usleep_range(1000, 1200) the destroy path uses. Only after that does it call nbl_intr_release_bitmap() on the old vectors.
The kerneldoc for nbl_res_intr_cfg_msix_map() matches the code: "On reconfiguration the map VALID bit is cleared and the hardware-DMA quiesce window is observed (lock held) before old vectors are recycled". So the two in-file comments contradict each other. The only quiesce a reconfiguration skips is the extra first-configuration one.
Could the commit message and the !had_config comment be updated to match the code?
The !had_config comment also justifies its extra invalidate and quiesce with "while the entry is VALID the pcompleter could fetch a table that is being written". Can the entry be VALID when had_config is false?
- nbl_intr_setup_mgt() clears VALID on all NBL_MAX_PF entries at start.
- A failed fresh configuration exits before any hardware write.
- __nbl_res_intr_complete_destroy_msix_map() leaves VALID cleared.
- DESTROYING can't be seen here, because the single-function destroy holds the lock and nbl_intr_mgt_stop() sets stopping.
Separately, the commit message says:
Everything between pci_set_master() and the scrub is host-side setup plus MMIO and does not wait for the device.
This patch moves pci_set_master() in nbl_probe() to after nbl_core_init(), so it now runs after the scrub in nbl_intr_setup_mgt(). Does this sentence describe the old ordering?
nbl_interrupt.c is not changed by the later patches in the series, so this mismatch is still there at the end of the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 4/8 net/nebula-matrix: add chip-wide hardware init/deinit implementation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers. The resource layer gates both on has_ctrl, so they only run on the control PF.
init_module() programs the chip-wide datapath registers, none of which firmware sets up on the driver's behalf:
- DPED: VLAN/DSCP offsets and the SCTP L4 checksum enable.
- UPED: V4/V6 TCP L3-length edit profiles.
- SHAPING: per-port CIR/PIR from the firmware-reported speed (the DVN dport entry carries PIR at the full rate and CIR at half rate), a bucket depth derived from the rate, PSHA enable for the ports present, and a clear of the PF-indexed shaping_net table.
- DSCH: host QID max (0x7ff) and the host/ECPU quanta.
- USTORE: minimum packet length 42 and the per-port drop threshold, scaled by the PF count, plus a clear of the port drop/truncate counters by reading them back.
- DSTORE: clear the per-port drop enable, program the XON/XOFF flow-control thresholds (a larger pair at 100G), and enable the discard backpressure threshold.
- DVN: ECPU queue count, descriptor-write merge timeout, descriptor request count (by speed), and the relaxed-ordering bits.
- UVN: ECPU queue count, descriptor read-wait/write-timeout, the error mask, and the relaxed-ordering bits. The relaxed-ordering bits in both DVN and UVN are derived from the PCIe DEVCTL state through pcie_relaxed_ordering_enabled().
- UQM: clear the drop counters and force que_type to backpressure.
- PADPT: the host flow-control credits.
This also adds a firmware ABI dependency: nbl_hw_get_quirks() reads a quirk word at mailbox offset NBL_LEONIS_QUIRKS_OFFSET (0x140), where ~0U means "no quirks" and BIT(1) selects the UVN prefetch mode (sel=0, use the configured descriptor count) instead of the internal calculation.
deinit_module() clears the driver_status bit, flushes writes and sleeps 2-3 ms to give the asynchronous firmware cleanup pass time to run. It deliberately reverts none of the above: that pass covers per-PF state only (qinfo registers and mailbox routing), so the chip-wide datapath registers stay programmed until chip reset or until a later init_module() overwrites them, even if the control PF is later bound to another driver. The hardware exposes no cleanup-complete status bit, so the sleep is best-effort and cannot prove the pass has finished.
A stale driver_status bit (kexec, or an unload that never reached deinit_module()) is cleared in nbl_hw_init_leonis(), before this probe programs any per-PF state. The 1 -> 0 transition makes firmware reclaim the mailbox QINFO routing and qinfo registers, so clearing it from init_module() instead - after nbl_dev_setup_chan_qinfo() has programmed them - would leave the inter-PF mailbox dead and make sibling probes time out.
Two known limitations of that handshake, neither of which the driver can close on this hardware:
- NBL_DRIVER_STATUS_REG is shared with firmware. Bit 16 is the only bit the driver owns, and the register has no documented W1S/W1C form, so changing bit 16 has to be a read-modify-write. reg_lock makes the read-modify-write atomic against other CPU writers but cannot serialise against firmware, so a firmware update to a different bit landing between the read and the write would be written back stale. All three callers (the probe-time stale clear, init_module() and deinit_module()) could in principle hit that; no such firmware update is known to race them, but that is an observation about this hardware revision, not a guarantee.
- The 2-3 ms wait is an empirical bound, not a documented firmware latency. There is nothing to poll instead: the hardware exposes no cleanup-complete bit, and the reclaimed entries read back the same before and after the pass, so there is no observable side effect to wait on and nothing to validate the delay against. A pass that takes longer than the window - an ECPU still busy right after kexec, say - can therefore still race a later probe and reclaim routing that probe has already programmed. What actually protects the per-PF state is the ordering around the clear, not the delay, and on teardown that ordering comes from the device link between the sibling PFs and the control PF.
The two hooks are only checked for non-NULL by nbl_hw_setup_ops() and nbl_res_setup_ops() at this point; nothing calls them yet. They gain callers later in the series, from the dispatch init_module()/ deinit_module() and from nbl_dev_setup_ctrl_dev()/ nbl_dev_remove_ctrl_dev().
--- .../net/ethernet/nebula-matrix/nbl/Makefile | 1 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 + .../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 + .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 753 +++++++++++++++++- .../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 242 ++++++ .../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, 1069 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 +752 -1
788 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h +242 -0
271 lines not on this page · raw message
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.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.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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_dvn_init() and nbl_uvn_init() in nbl_hw_leonis.c turn the relaxed-ordering (RO) enables in two chip-wide registers on or off:…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds the Leonis chip-wide init_module() and deinit_module() hooks in the hw and resource layers. They run only on the control PF. They program the DP datapath registers (DPED, UPED, SHAPING, DSCH, USTORE, DSTORE, DVN, UVN, UQM, PADPT) and drive the driver_status handshake with firmware.
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 +175,719 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
[ ... ]
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +5
-0+static void nbl_dvn_init (struct nbl_hw_mgt *hw_mgt,u8 speed) +{ +u32 timeout =0 ; +u32 ro_flag =0 ; +
[ ... ]
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +12
-0+spin_lock (&hw_mgt->reg_lock); +nbl_hw_rd_regs (hw_mgt,NBL_DVN_DIF_REQ_RD_RO_FLAG , &ro_flag, +sizeof (ro_flag)); +if (pcie_relaxed_ordering_enabled (hw_mgt->common->pdev)) { + ro_flag |= +FIELD_PREP (NBL_DVN_DIF_REQ_RD_RO_FLAG_DESC_RO_EN_MASK , +1 ) | +FIELD_PREP (NBL_DVN_DIF_REQ_RD_RO_FLAG_DATA_RO_EN_MASK , +1 ) | +FIELD_PREP (NBL_DVN_DIF_REQ_RD_RO_FLAG_AVRING_RO_EN_MASK , +1 ); + }else {
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +4
-0+ } +nbl_hw_wr_regs (hw_mgt,NBL_DVN_DIF_REQ_RD_RO_FLAG , &ro_flag, +sizeof (ro_flag)); +spin_unlock (&hw_mgt->reg_lock);
[ ... ]
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+static void nbl_uvn_init (struct nbl_hw_mgt *hw_mgt) +{
[ ... ]
Quoted 9 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +9
-0+ ro_enabled =pcie_relaxed_ordering_enabled (hw_mgt->common->pdev); + +nbl_hw_rd_regs (hw_mgt,NBL_UVN_DIF_REQ_RO_FLAG , &flag,sizeof (flag)); +if (ro_enabled) { + flag |=FIELD_PREP (NBL_UVN_DIF_REQ_RO_FLAG_AVAIL_RD_MASK ,1 ) | +FIELD_PREP (NBL_UVN_DIF_REQ_RO_FLAG_DESC_RD_MASK ,1 ) | +FIELD_PREP (NBL_UVN_DIF_REQ_RO_FLAG_PKT_WR_MASK ,1 ); + flag &= ~FIELD_PREP (NBL_UVN_DIF_REQ_RO_FLAG_DESC_WR_MASK ,1 ); + }else {
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c +2
-0+ } +nbl_hw_wr_regs (hw_mgt,NBL_UVN_DIF_REQ_RO_FLAG , &flag,sizeof (flag));
[Severity: Medium]
Both of these RO flag registers seem to be single chip-wide registers in the DP block, not per-function ones:
#define NBL_DVN_DIF_REQ_RD_RO_FLAG (NBL_DP_DVN_BASE + 0x0000045C)
#define NBL_UVN_DIF_REQ_RO_FLAG (NBL_DP_UVN_BASE + 0x00000250)
nbl_res_chip_init_module() in nbl_chip.c runs this only on the control PF:
if (!common->has_ctrl) return -EINVAL;
That means nbl_dvn_init() and nbl_uvn_init() check PCI_EXP_DEVCTL_RELAX_EN only on the control PF's pdev, and that one bit sets relaxed ordering for every function's queues on the chip.
In PCIe, Enable Relaxed Ordering is a per-function permission. Suppose a sibling PF has RO cleared in its own DEVCTL, for example by a guest that owns it through vfio-pci, by setpci, or by a driver applying an erratum. If the control PF has RO enabled, would the DVN/UVN engines still issue RO-tagged descriptor and avail-ring reads, and RO packet writes, for that sibling's queues?
The value is also read only once, here. deinit_module() leaves it programmed, so later DEVCTL changes on any function are never picked up.
Does the hardware also gate the RO attribute on each requester function's own DEVCTL? If not, could this use the AND of RO enable across all functions on the chip, or program RO per function if the hardware supports that? If the hardware does gate it per function, could a comment here say so?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 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
@@ -12,6 +12,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"
@@ -58,7 +59,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:
@@ -69,6 +76,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);nbl_hw_remove_leonis (adapter);
Signature · 1 line
2.51.0.windows.1
illusion.wang
maintainerPATCH v33 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.
The five responders are registered with the channel layer and owned by it, so they are removed when the channel is torn down and need no explicit unregistration: nbl_disp_remove() stays empty here. The teardown order that makes that safe is documented with the code that performs it, in the next patch in this series.
--- .../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 534 ++++++++++++++++++ .../nbl/nbl_include/nbl_def_channel.h | 40 ++ .../nbl/nbl_include/nbl_def_dispatch.h | 37 +- 3 files changed, 607 insertions(+), 4 deletions(-)
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 +33 -4
@@ -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,44 @@ 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. +* structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove() +* has nothing to undo. The five responders registered by +* nbl_disp_setup_msg() are owned by the channel layer and go away with +* it, so they need no explicit unregistration either; the teardown order +* that makes that safe is documented with the code that performs it, in +* the next patch in this series. They forward chip/firmware control down +* to the layers below instead: a control-PF 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.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 6/8] net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] This patch makes it possible for a sibling PF to trigger runtime teardown of its own MSI-X map on the control PF, and that…
- [Low] The subject line says "dispatch: implement channel RPC framework and serialize hardware ops", but the patch does neither of those…
- [Low] The struct nbl_dispatch_ops kernel-doc in nbl_def_dispatch.h justifies the empty nbl_disp_remove() like this: "the teardown order…
- [Low] nbl_disp_chan_cfg_msix_map_req(), nbl_disp_chan_destroy_msix_map_req() and…
- [Low] The commit message says cfg_msix_map, destroy_msix_map and set_mailbox_irq "carry a caller precondition": clear mailbox IRQ_RDY…
--
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
This patch adds mailbox RPC request and response handlers for five dispatch ops: cfg_msix_map, destroy_msix_map, set_mailbox_irq, get_vsi_id and get_eth_id. Based on has_ctrl/has_net, each op becomes either a local resource call or a channel RPC to the management PF. The five responders are registered with the channel layer.
Quoted 1 line
net/nebula-matrix: dispatch: implement channel RPC framework and serialize hardware ops
[Severity: Low]
This isn't a bug, but does the subject line match what the patch does?
The patch adds no lock, mutex or other serialization. The body says "No dispatch-layer lock is taken around these ops", and the comment in nbl_disp_cfg_msix_map() says the same thing. The only serialization is intr_mgt->lock, which an earlier patch, "net/nebula-matrix: add intr resource implementation", added to the resource layer.
The channel RPC framework (send_msg, send_ack, register_msg and the ACK errno plumbing) was also added earlier, in "net/nebula-matrix: add channel layer". This patch adds five request/response handlers on top of it.
Could the subject describe that instead, for example "dispatch: add mailbox RPCs for msix map, mailbox irq and vsi/eth id"?
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +0
-0@@ -25,6 +193,353 @@ static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt)return -EOPNOTSUPP ; }
[ ... ]
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +11
-0+/* +* Precondition: caller must disable mailbox IRQ_RDY and switch send_msg +* to the polling path before issuing this RPC. The responder rewrites +* the requester's mailbox MSI-X routing during the resource op, so the +* ACK cannot rely on interrupt wakeup while routing is in flux. +*/ +static int +nbl_disp_chan_cfg_msix_map_req (struct nbl_dispatch_mgt *disp_mgt, +u16 num_net_msix,u16 num_others_msix, +bool net_msix_mask_en) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 240
Quoted 5 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +5
-0+nbl_chan_fill_send_info (&chan_send, common->mgt_pf, +NBL_CHAN_MSG_CONFIGURE_MSIX_MAP , + ¶m,sizeof (param), +NULL ,0 ,1 ); + ret = chan_ops->send_msg (disp_mgt->chan_ops_tbl->priv, &chan_send);
[Severity: Low]
This precondition appears only as a comment, here and above nbl_disp_chan_destroy_msix_map_req() and nbl_disp_chan_set_mailbox_irq_req(). Could it be enforced in code instead?
Suppose one of these RPCs were sent with NBL_CHAN_IRQ_RDY set. The responder would rewrite the requester's mailbox MSI-X routing before it writes the ACK. The requester would then wait in the interrupt-mode path of nbl_chan_send_msg(), which has no RX polling fallback:
nbl_chan_send_msg() {
...
if (test_bit(NBL_CHAN_IRQ_RDY, chan_info->state)) {
while (!READ_ONCE(wait_head->acked)) {
...
ret = wait_event_timeout(wait_head->wait_queue,
...
}In that case the call would return -ETIMEDOUT even though the hardware state had already changed.
No in-tree caller later in the series does this. nbl_dev_start(), nbl_dev_enable_mailbox_irq(), nbl_dev_disable_mailbox_irq(), nbl_dev_stop() and the err_destroy_map rollback in nbl_dev_start() all follow the precondition. A check would only be defensive.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +4
-0+static void nbl_disp_chan_destroy_msix_map_resp (void *priv,u16 src_id, +u16 msg_id,void *data, +u32 data_len) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c static int nbl_disp_init_module(struct nbl_dispatch_mgt *disp_mgt) · line 354
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c +2
-0+if (res_ops->destroy_msix_map) { + ret = res_ops->destroy_msix_map (p, src_id);
[Severity: Medium]
Can this let the device fetch a sibling PF's MSI-X map table after the table has been freed?
This responder is the first way a sibling PF can trigger a runtime teardown of its map on the control PF:
nbl_dev_destroy_msix_map() (sibling PF)
-> NBL_CHAN_MSG_DESTROY_MSIX_MAP
-> nbl_disp_chan_destroy_msix_map_resp() (control PF)
-> nbl_res_intr_destroy_msix_map()
-> __nbl_res_intr_prepare_destroy_msix_map() clears VALID
-> nbl_intr_quiesce_wait() usleep_range()
-> __nbl_res_intr_complete_destroy_msix_map() dma_free_coherent()The comment above nbl_intr_quiesce_wait() in nbl_interrupt.c says the window "is not a guarantee", and continues:
* A future caller that cannot tolerate the residual risk must keep the
* table allocated for the lifetime of the function instead of relying on
* this delay.
...
* fetch inside this window. It cannot help a sibling PF's map destroyed
* at runtime, because those fetches carry the control PF's BDF and so
* are unaffected by clearing bus mastering on the sibling. Runtime
* destroys of sibling maps only become reachable with the mailbox RPC
* added later in this series.
This responder is that mailbox RPC, but the table is still freed right after the roughly 1ms delay. The control PF stays bus master the whole time. A pcompleter fetch that is still in flight would read freed or reused memory. With an IOMMU that is a fault. Without one, the device could use stale gvec routing and deliver an interrupt to the wrong function.
nbl_disp_chan_cfg_msix_map_resp() has the same exposure when it reaches the had_config path of nbl_res_intr_cfg_msix_map(). That path returns the old global vectors to the shared pool via nbl_intr_release_bitmap() after the same window.
Later in the series, the sibling frees its vectors with pci_free_irq_vectors() (via nbl_dev_clear_interrupt_scheme()) before it sends destroy_msix_map. That makes new fetches unlikely, but it still gives no hardware completion guarantee.
Would it be safer to keep sibling map tables allocated for the lifetime of the function, as the resource layer comment suggests?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 38
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +3
-0@@ -32,16 +33,44 @@ 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
[Severity: Low]
The commit message says cfg_msix_map, destroy_msix_map and set_mailbox_irq "carry a caller precondition": IRQ_RDY must be cleared and the polling send path used. That rule is only written above the static *_req functions in nbl_dispatch.c.
Should the precondition also go in this kernel-doc? Callers program against struct nbl_dispatch_ops, and from there they cannot tell whether an op will be a local call or an RPC.
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +2
-0+* @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
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h enum { · line 48
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h +6
-4-* 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. +* structures are devm-allocated in nbl_disp_init(), so nbl_disp_remove() +* has nothing to undo. The five responders registered by +* nbl_disp_setup_msg() are owned by the channel layer and go away with +* it, so they need no explicit unregistration either; the teardown order +* that makes that safe is documented with the code that performs it, in +* the next patch in this series. They forward chip/firmware control down
[Severity: Low]
This isn't a bug, but won't "the next patch in this series" be meaningless once this is merged?
At this commit, the code that performs the teardown is:
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);
}Neither this function nor the nbl_core_init() error unwind documents the ordering. Nothing breaks at runtime yet, because setup_queue() has no callers, so no responder can run.
Later, "net/nebula-matrix: add common/ctrl dev init/remove operation" makes nbl_core_remove() call nbl_dev_remove() first. That tears down the mailbox channel queue before the resource layer is removed.
Even so, this header comment is unchanged at the end of the series. The "Teardown order" comment in nbl_dev_remove() also never mentions the responders or handler_xa.
Could this comment name nbl_dev_remove() and state the invariant directly, i.e. that the channel queue is torn down before the resource layer is removed?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 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 | 303 ++++++++++++++++++ .../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, 404 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 +303 -0
303 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
@@ -13,6 +13,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"
@@ -63,7 +64,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:
@@ -76,6 +84,7 @@ out:void nbl_core_remove (struct nbl_adapter *adapter) { +nbl_dev_remove (adapter);nbl_disp_remove (adapter);nbl_res_remove_leonis (adapter);nbl_chan_remove_common (adapter);
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 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] The comment in nbl_dev_init_msix_cnt() (drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c) says the…
- [Low] nbl_dev_setup_common_dev() (nbl_dev.c) explains why VSI/ETH identity is not fetched at init: "the control PF's responder may still…
- [Low] This patch adds the first caller of cfg_chan_qinfo_map_table (nbl_dev_setup_chan_qinfo()) and puts the responder-teardown…
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This commit adds nbl_dev.c with nbl_dev_init() and nbl_dev_remove(). These set up the mailbox clean work and the mailbox channel queue. On the control PF they also program the mailbox QINFO routing and run init_module. The new entry points are called from nbl_core_init() and nbl_core_remove().
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +0
-0@@ -0,0 +1,303 @@
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 18
Quoted 10 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +10
-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; + +/* Reserve one MSI-X vector for the mailbox. Nothing here +* allocates or requests it: vectors are allocated and the handler +* attached when the device is started, after probe, from this +* count. +*/
[Severity: Low]
This isn't a bug, but is "after probe" accurate here?
nbl_dev_start() arrives later in the series, in "net/nebula-matrix: add common dev start/stop operation". By the end of the series it is called from inside nbl_probe():
nbl_probe() {
...
pci_set_master(pdev);
pci_set_drvdata(pdev, adapter);
err = nbl_core_start(adapter);
if (err) {
nbl_core_remove(adapter);
pci_clear_master(pdev);
}
return err;
}So if start fails, the probe fails. The comment above nbl_hw_clear_stale_status() in nbl_hw_leonis.c agrees: it says sibling PFs' RPCs "time out in nbl_dev_start() and their probes fail".
The "after probe" wording is still there at the end of the series. Should it say the vectors are allocated in the start path, during probe?
Quoted 6 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +6
-0+ msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; +} + +/* ---------- Channel config ---------- */ +static void nbl_dev_setup_chan_qinfo (struct nbl_dev_mgt *dev_mgt,u8 chan_type) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +2
-0+ chan_ops->cfg_chan_qinfo_map_table (priv, common->hw_bus, common->devid); +}
[Severity: Low]
This isn't a bug, but this patch adds the first caller of cfg_chan_qinfo_map_table, and that makes a few existing comments wrong. All three are unchanged at the end of the series.
nbl_chan_cfg_qinfo_map_table() in nbl_channel.c still says:
* 0xfe/0xfc/0xf0. Nothing enforces that here: the resource layer
* that validates the mask, and every caller of this op, arrive in
* later patches of this series.
But nbl_res_init_pf_num() already rejects non-contiguous masks and any pf_num outside {1, 2, 4}, and this patch adds the caller.
nbl_res_init_pf_num() in nbl_resource_leonis.c says:
* this running first: resource init completes before the channel
* layer is set up.
nbl_core_init() actually calls nbl_chan_init_common() before nbl_res_init_leonis(). The dependency only holds because the QINFO programming happens here in nbl_dev_init(), which runs after resource init.
The kernel-doc for struct nbl_dispatch_ops in nbl_def_dispatch.h says the teardown order "is documented with the code that performs it, in the next patch in this series". This is that patch, and the text went into nbl_disp_remove(), which does no teardown itself.
Could these three comments be updated? Could the "next patch in this series" reference also be removed before the code is merged?
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +3
-0+/* ---------- Dev init process ---------- */ +static int nbl_dev_setup_common_dev (struct nbl_adapter *adapter) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c line 133
Quoted 8 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c new file +8
-0+nbl_dev_register_chan_task (dev_mgt,NBL_CHAN_TYPE_MAILBOX , + &common_dev->clean_mbx_task); +/* +* VSI/ETH identity is deliberately not fetched here: it is only +* known to the control PF, so it has to come from a mailbox RPC, +* and the control PF's responder may still be probing while this +* function runs. The fetch is therefore left to the start path. +*/
[Severity: Low]
Can the control PF's responder still be probing when a sibling PF reaches this point?
nbl_probe() calls nbl_probe_chip_deps() before nbl_core_init(). For a non-control PF, nbl_probe_chip_deps() holds func 0's device lock and defers the probe:
nbl_probe_chip_deps() {
...
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;
}
...
}driver_bound() only sets DL_DEV_DRIVER_BOUND after func 0's entire ->probe() has returned, and that includes nbl_dev_init() and init_module.
The header comment for nbl_dev_remove_ctrl_dev() in this same file says the opposite:
* between. A sibling therefore cannot
* reach its mailbox setup before the control PF is fully probed, nor
The commit message of the last patch in the series says the same thing.
Should this comment give a different reason for deferring the fetch? It is still present at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com
illusion.wang
maintainerPATCH v33 8/8 net/nebula-matrix: add common dev start/stop operation
In reply to illusion.wangFrom: illusion wang <[email protected]>
Add nbl_dev_start() and nbl_dev_stop(), called from nbl_probe() and nbl_remove() via nbl_core_start() / nbl_core_stop().
Start configures the device MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt; stop performs the matching teardown.
nbl_probe() now rejects a function with neither the ctrl nor the net capability with -EOPNOTSUPP, before any hardware is touched. Such a function would reach nbl_dev_start() with every dispatch op left NULL by nbl_disp_refresh_ctrl_ops(). The state is only reachable throughdriver_override: binding this driver to a function that is absent from nbl_id_table (a VF, or a non-func-0 PF of this device) makes pci_match_device() pass the dummy ID whose driver_data 0 leaves both capabilities clear. A foreign device at func 0 is unaffected - nbl_get_func_param() gives any func 0 device has_ctrl, so it is not rejected here and still runs nbl_core_init() with the local control dispatch ops, as it did before this check existed. nbl_dev_init()'s unwind labels change with it: setup_ctrl_dev_fail becomes out_remove_common_dev, and the setup_err path drops its label and returns directly, since a failed nbl_dev_setup_common_dev() has nothing to unwind.
Startup RPC errors are propagated unchanged. A -ETIMEDOUT here is a real failure, not a "supplier not ready yet" condition: nbl_probe() already deferred this PF in nbl_probe_chip_deps() until the control PF reached DL_DEV_DRIVER_BOUND, and the driver core only marks a device bound once its entire probe - including the control PF's own nbl_core_start() - has returned. That state is what bounds the wait, not nbl_dev_init(): on the control PF inbound mailbox work only runs from clean_mbx_task, which is queued by the mailbox hardirq, by the task's own self-requeue, or by this function's polling sends, and the control PF uses the local dispatch ops so it sends none. The responder is armed by set_mailbox_irq(true) at the end of the peer's nbl_dev_start(). Relaxing the dependency to "func 0 finished nbl_dev_init()" would therefore let every sibling RPC sit out the full 5-6s polling wait. Converting the timeout to -EPROBE_DEFER would only hide it behind dev_dbg() and make every later bind pay that wait again.
Teardown releases the kernel MSI-X vectors before destroying the hardware pcompleter map. pci_free_irq_vectors() ends in pci_msix_shutdown(), which masks every descriptor by writing the MSI-X table and reading it back to flush the write; those accesses should reach the function while FUNCTION_MSIX_MAP is still valid. This mirrors start, where cfg_msix_map runs before pci_alloc_irq_vectors_affinity(). It is not a double free of the pcim_msi_release devres registered alongside pci_alloc_irq_vectors(): that action only calls pci_free_irq_vectors() again, and pci_disable_msix() returns early once msix_enabled is clear. Start and stop still each run once, tied to probe and remove.
The rest of teardown is best-effort. The MSI-X map is torn down even when the configure RPC failed: a timeout only means the ACK never arrived, while the responder runs to completion before ACKing, so the entry, the intr_net/other_bmap bits and the coherent map table stay owned by the control PF. Those are host resources of that driver, not firmware state, and neither recovery path needs a chip reset: a later successful configuration of this function invalidates and rewrites the entry on its had_config path, and nbl_intr_mgt_stop() clears the FUNCTION_MSIX_MAP valid bit for every still-configured function when the control PF is removed. 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 | 432 +++++++++++++++++- .../nbl/nbl_include/nbl_def_dev.h | 2 + .../net/ethernet/nebula-matrix/nbl/nbl_main.c | 37 +- 4 files changed, 473 insertions(+), 6 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 +428 -4
473 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 +35 -2
@@ -25,6 +25,15 @@#define NBL_MGT_LOCK_RETRY_MIN_US 1000#define NBL_MGT_LOCK_RETRY_MAX_US 2000#define NBL_MGT_LOCK_MAX_RETRIES 50 +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)
@@ -277,6 +286,25 @@ 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. A foreign +* device at func 0 is unaffected: nbl_get_func_param() gives any +* func 0 device has_ctrl, so it is not rejected here and still runs +* nbl_core_init() with the local control dispatch ops, as it did +* before this check existed. +*/ +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);
@@ -314,8 +342,12 @@ static int nbl_probe(struct pci_dev *pdev,pci_set_master (pdev);pci_set_drvdata (pdev, adapter); - -return 0 ; + err =nbl_core_start (adapter); +if (err) { +nbl_core_remove (adapter); +pci_clear_master (pdev); + } +return err; }static void nbl_remove (struct pci_dev *pdev)
@@ -326,6 +358,7 @@ static void nbl_remove(struct pci_dev *pdev)return ;pci_set_drvdata (pdev,NULL ); +nbl_core_stop (adapter);/* * Stop bus mastering before any teardown runs. *
Signature · 1 line
2.51.0.windows.1
[email protected]
AI reviewRe: [PATCH v33 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 6
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] On the control PF, this patch frees the PF's own coherent MSI-X map table while Bus Master Enable is still set.
- [Low] The new nbl_probe() error unwind calls nbl_core_remove() and then pci_clear_master().
- [Low] The new comment above nbl_core_start()/nbl_core_stop() in nbl_core.h says start/stop are not repeatable because 'MSI-X vectors…
- [Low] The commit message justifies the new -EOPNOTSUPP check by saying the neither-ctrl-nor-net state is reached by binding to a function…
- [Low] The comment in nbl_dev_init_msix_cnt() says vectors are allocated and the handler attached 'when the device is started, after probe,…
- [Low] The err_destroy_map comment in nbl_dev_start() says the map entry, the bitmap bits, the kcalloc()ed vector array and 'the coherent…
- [Low] The new nbl_probe() comment says 'nbl_get_func_param() gives any func 0 device has_ctrl'.
--
net/nebula-matrix: add common dev start/stop operation
This patch adds nbl_dev_start() and nbl_dev_stop(), which nbl_probe() and nbl_remove() call through nbl_core_start() and nbl_core_stop(). Start programs the MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X vectors and arms the mailbox interrupt; stop undoes these steps. nbl_probe() also now rejects a function that has neither the ctrl nor the net capability.
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h struct nbl_adapter *nbl_core_init(struct pci_dev *pdev, · line 47
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +5
-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. +*/
[Severity: Low]
Is this the right reason? nbl_dev_stop() and the nbl_dev_start() rollback both call nbl_dev_clear_interrupt_scheme(), which does:
pci_free_irq_vectors(common->pdev);
That frees the vectors and clears msix_enabled at stop time, not at detach. The commit message relies on the same thing when it explains why the pcim_msi_release devres action is harmless.
After stop, a second pci_alloc_irq_vectors_affinity() would not be rejected by the MSI-X core. Should this comment give a different reason for the pair being single-shot?
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h +2
-0+int nbl_core_start (struct nbl_adapter *adapter); +void nbl_core_stop (struct nbl_adapter *adapter);
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) · line 31
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -19,6 +30,243 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt) msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE ].num =1 ; }
[Severity: Low]
This patch makes the existing comment just above, in nbl_dev_init_msix_cnt(), out of date:
/* Reserve one MSI-X vector for the mailbox. Nothing here
* allocates or requests it: vectors are allocated and the handler
* attached when the device is started, after probe, from this
* count.
*/
nbl_core_start() is now called at the end of nbl_probe(). That means pci_alloc_irq_vectors_affinity() and request_irq() run inside probe, before it returns. Should "after probe" be updated?
[ ... ]
Quoted 1 line
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +0
-0@@ -301,3 +557,171 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
[ ... ]
Quoted 3 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +3
-0+/* ---------- Dev start process ---------- */ +int nbl_dev_start (struct nbl_adapter *adapter) +{
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c void nbl_dev_remove(struct nbl_adapter *adapter) · line 645
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +12
-0+err_destroy_map: +/* +* Always ask the peer to drop this function's MSI-X map, even when +* the cfg RPC above failed: the teardown prepare phase returns 0 +* for a function that is not NBL_INTR_FUNC_CONFIGURED, so it is a +* no-op when nothing landed, but a -ETIMEDOUT only means the ACK +* never arrived - the responder runs to completion before it ACKs. +* In that case the map entry, the intr_net/other_bmap bits, the +* kcalloc()ed vector array and the coherent map table are all +* still owned by the control PF, i.e. host resources of its +* driver, released only when this function is configured again or +* when nbl_intr_mgt_stop() tears the control PF down. They are not
[Severity: Low]
Does configuring the function again really release the coherent map table? nbl_res_intr_cfg_msix_map() allocates the table only when !official_tbl->base_addr, and its had_config branch says:
* NOTE: NO DMA table free here.
*/
if (had_config) {That path releases the old bitmap bits and kfree()s the old interrupts array. It then rewrites the existing table in place.
The coherent table is freed only by __nbl_res_intr_complete_destroy_msix_map(), which runs on a destroy or from nbl_intr_mgt_stop(). Could this comment be reworded to match? The version in nbl_dev_stop() ("invalidates and rewrites the entry") already describes this correctly.
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c +2
-0+* firmware state, so skipping the destroy would strand them for a +* PF that has no driver to ever ask for them again.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +0
-0
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 297
Quoted 13 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +9
-0@@ -277,6 +286,25 @@ 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. A foreign
[Severity: Low]
Can a non-func-0 PF of this device reach this state? All PFs share the same PCI device ID, and every nbl_id_table entry sets the net bit:
{ PCI_DEVICE(NBL_VENDOR_ID, NBL_DEVICE_ID_M18110),
.driver_data = BIT(NBL_CAP_HAS_NET_BIT) },pci_match_device() returns the matching static entry before it falls back to the dummy ID with driver_data 0. new_id also rejects driver_data that matches no table entry. So sibling PFs always get has_net. Only foreign devices, or VFs whose IDs are not in the table, end up with neither capability.
The commit message makes the same claim:
driver_override: binding this driver to a function that is absent from nbl_id_table (a VF, or a non-func-0 PF of this device) makes
The commit message also says a foreign func 0 device is "unaffected ... as it did before this check existed". That is true of the check itself. However, this same patch now runs nbl_dev_start() on such a device: MSI-X map programming, vector allocation and mailbox IRQ arming.
Should the comment and the commit message be updated?
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 299
Quoted 2 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +2
-0+* device at func 0 is unaffected: nbl_get_func_param() gives any +* func 0 device has_ctrl, so it is not rejected here and still runs
[Severity: Low]
Is this description of nbl_get_func_param() accurate? It only sets has_ctrl when the device is not a VF:
if ((PCI_FUNC(pdev->devfn) == 0) && !pdev->is_virtfn) param->caps.has_ctrl = 1;
As nbl_probe_chip_deps() notes, under ARI a VF's devfn can decode to function 0. A VF like that, bound through driver_override, gets neither capability and is rejected by this check. The code does the right thing; only the comment is wrong.
Quoted 7 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +7
-0+* nbl_core_init() with the local control dispatch ops, as it did +* before this check existed. +*/ +if (!param.caps.has_ctrl && !param.caps.has_net) { +dev_err (dev,"Function has neither ctrl nor net capability\n" ); +return -EOPNOTSUPP ; + }
[ ... ]
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static int nbl_probe(struct pci_dev *pdev, · line 349
Quoted 11 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +5
-2@@ -314,8 +342,12 @@ static int nbl_probe(struct pci_dev *pdev,pci_set_master (pdev);pci_set_drvdata (pdev, adapter); - -return 0 ; + err =nbl_core_start (adapter); +if (err) { +nbl_core_remove (adapter); +pci_clear_master (pdev); + }
[Severity: Low]
Should this unwind clear bus mastering before nbl_core_remove(), as nbl_remove() does? nbl_remove() uses the opposite order:
pci_clear_master(pdev); nbl_core_remove(adapter);
Its comment says bus mastering has to be stopped before nbl_core_remove() frees the MSI-X map tables.
I could not find a runtime effect in this unwind. After the nbl_dev_start() rollback, the control PF's own entry is already idle. Sibling PFs cannot be configured yet, because nbl_probe_chip_deps() defers them. The mailbox rings are devres managed. So this is mostly a consistency issue.
The new err_destroy_map comment in nbl_dev_start() also says:
* Note: pci_clear_master() runs in nbl_probe() core_start_err path;
There is no core_start_err label. This pci_clear_master() also only runs after nbl_dev_start() has freed the table and nbl_core_remove() has returned. Could that comment be corrected as well?
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c static void nbl_remove(struct pci_dev *pdev) · line 364
Quoted 12 lines
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c +2
-0+return err; }static void nbl_remove (struct pci_dev *pdev)@@ -326,6 +358,7 @@ static void nbl_remove(struct pci_dev *pdev)return ;pci_set_drvdata (pdev,NULL ); +nbl_core_stop (adapter);/* * Stop bus mastering before any teardown runs. *
[Severity: Medium]
On the control PF, does this free the PF's own coherent MSI-X map table while Bus Master Enable is still set?
nbl_core_stop() now runs before pci_clear_master(). On the control PF the call chain is:
nbl_remove()
nbl_core_stop()
nbl_dev_stop()
nbl_dev_destroy_msix_map()
nbl_disp_destroy_msix_map() /* local op */
nbl_res_intr_destroy_msix_map()
__nbl_res_intr_destroy_msix_map()
/* clear valid bit, flush */
nbl_intr_quiesce_wait() /* usleep_range(1000, 1200) */
__nbl_res_intr_complete_destroy_msix_map()
dma_free_coherent(dev, msix_map_table->size, ...)The map is programmed with the control PF's own BDF, so the pcompleter's table fetches are bus-master reads from this same PF.
The comment above nbl_intr_quiesce_wait() says the delay "is not a guarantee". It relies on this for extra protection:
* pci_clear_master() is the only other lever, and nbl_remove() pulls it
* before any teardown runs: that keeps the device from starting a new
* fetch inside this window.
The "Stop bus mastering before any teardown runs" comment just above no longer holds for the control PF either.
The err_destroy_map rollback in nbl_dev_start() has the same ordering on probe failure, because nbl_probe() calls pci_set_master() before nbl_core_start():
cleanup_ret = nbl_dev_destroy_msix_map(dev_mgt);
This can happen, for example, when pci_alloc_irq_vectors_affinity() or request_irq() fails after cfg_msix_map succeeded.
The commit message only says that pci_clear_master() is no safety net on a non-control PF. It does not mention that the control PF loses this protection.
The control PF's stop path uses local MMIO ops and does not need bus mastering. When has_ctrl is set, could bus mastering be cleared before the own-map destroy? Alternatively, could the free of this PF's own map be left to nbl_intr_mgt_stop(), after pci_clear_master()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106045631.2224-1-illusion.wang%40nebula-matrix.com