Thread View: linux.kernel.netdev
6 messages
6 total messages
Started by "illusion.wang"
Thu, 12 Nov 2026 09:49
[PATCH v34 net-next 0/8] nbl driver for Nebulamatrix NICs
Author: "illusion.wang"
Date: Thu, 12 Nov 2026 09:49
Date: Thu, 12 Nov 2026 09:49
113 lines
13366 bytes
13366 bytes
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 v33->v34
Link to v33:https://lore.kernel.org/netdev/20261106045631.2224-1-illusion.wang@nebula-matrix.com/
AI review issues
changes v32->v33
Link to v32:https://lore.kernel.org/netdev/20261021062113.2158-1-illusion.wang@nebula-matrix.com/
AI review issues
changes v31->v32
Link to v31:https://lore.kernel.org/netdev/20261010095939.2230-1-illusion.wang@nebula-matrix.com/
AI review issues
changes v30->v31
Link to v30:https://lore.kernel.org/netdev/20260928123237.88994-1-illusion.wang@nebula-matrix.com/
1.AI review issues
changes v29->v30
Link to v29:https://lore.kernel.org/netdev/20260922120311.86593-1-illusion.wang@nebula-matrix.com/
1.AI review issues
changes v28->v29
Link to v28:https://lore.kernel.org/netdev/20260914123429.56596-1-illusion.wang@nebula-matrix.com/
1.AI review issues
2.remove the hash table implementation
illusion wang (8):
net/nebula-matrix: add channel layer
net/nebula-matrix: add common resource implementation
net/nebula-matrix: add intr resource implementation
net/nebula-matrix: add chip-wide hardware init/deinit implementation
net/nebula-matrix: dispatch: add control-level routing core
infrastructure
net/nebula-matrix: dispatch: add mailbox RPCs for msix map, mailbox
irq and vsi/eth id
net/nebula-matrix: add common/ctrl dev init/remove operation
net/nebula-matrix: add common dev start/stop operation
.../net/ethernet/nebula-matrix/nbl/Makefile | 10 +-
.../nbl/nbl_channel/nbl_channel.c | 1546 +++++++++++++++++
.../nbl/nbl_channel/nbl_channel.h | 196 +++
.../nebula-matrix/nbl/nbl_common/nbl_common.c | 51 +
.../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 +
.../net/ethernet/nebula-matrix/nbl/nbl_core.h | 23 +
.../nebula-matrix/nbl/nbl_core/nbl_dev.c | 743 ++++++++
.../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 | 1309 +++++++++++++-
.../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 342 ++++
.../nbl_hw_leonis/nbl_resource_leonis.c | 373 ++++
.../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 | 853 +++++++++
.../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 | 93 +
.../nbl/nbl_include/nbl_def_hw.h | 81 +
.../nbl/nbl_include/nbl_def_resource.h | 38 +
.../nbl/nbl_include/nbl_include.h | 28 +
.../net/ethernet/nebula-matrix/nbl/nbl_main.c | 262 ++-
29 files changed, 7328 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
--
2.51.0.windows.1
[PATCH v34 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove operation
Author: "illusion.wang"
Date: Thu, 12 Nov 2026 09:49
Date: Thu, 12 Nov 2026 09:49
530 lines
27494 bytes
27494 bytes
From: illusion wang <illusion.wang@nebula-matrix.com>
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.
Signed-off-by: illusion wang <illusion.wang@nebula-matrix.com>
---
.../net/ethernet/nebula-matrix/nbl/Makefile | 1 +
.../net/ethernet/nebula-matrix/nbl/nbl_core.h | 1 +
.../nebula-matrix/nbl/nbl_core/nbl_dev.c | 305 ++++++++++++++++++
.../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, 406 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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/Makefile b/drivers/net/ethernet/nebula-matrix/nbl/Makefile
index b7eebd89b..71fbe3ee7 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/Makefile
+++ b/drivers/net/ethernet/nebula-matrix/nbl/Makefile
@@ -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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
index 4d8cea8d8..c3c4dd685 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
@@ -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;
};
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
new file mode 100644
index 000000000..0cc0c58ad
--- /dev/null
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
@@ -0,0 +1,305 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+#include <linux/device.h>
+#include <linux/pci.h>
+#include "nbl_dev.h"
+
+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: the start path, still inside probe,
+ * uses this count to allocate the vectors and attach the handler.
+ */
+ 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)
+{
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+ struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv;
+ struct nbl_common_info *common = dev_mgt->common;
+
+ if (!chan_ops->check_queue_exist(priv, chan_type))
+ return;
+
+ /*
+ * common->hw_bus is the control PF's real bus number, captured in
+ * nbl_res_ctrl_dev_sriov_info_init() during nbl_res_init_leonis().
+ * nbl_core_init() runs resource init before nbl_dev_init(), so the
+ * value is always initialized when this control-PF-only path runs;
+ * nbl_res_intr_cfg_msix_map() consumes it for cfg_msix_map() the
+ * same way.
+ */
+ chan_ops->cfg_chan_qinfo_map_table(priv, common->hw_bus, common->devid);
+}
+
+static int nbl_dev_setup_chan_queue(struct nbl_dev_mgt *dev_mgt, u8 chan_type)
+{
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+ struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv;
+ int ret = 0;
+
+ if (chan_ops->check_queue_exist(priv, chan_type))
+ ret = chan_ops->setup_queue(priv, chan_type);
+
+ return ret;
+}
+
+static int nbl_dev_remove_chan_queue(struct nbl_dev_mgt *dev_mgt, u8 chan_type)
+{
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+ struct nbl_channel_mgt *priv = dev_mgt->chan_ops_tbl->priv;
+ int ret = 0;
+
+ if (chan_ops->check_queue_exist(priv, chan_type))
+ ret = chan_ops->teardown_queue(priv, chan_type);
+
+ return ret;
+}
+
+static void nbl_dev_register_chan_task(struct nbl_dev_mgt *dev_mgt,
+ u8 chan_type, struct work_struct *task)
+{
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+
+ if (chan_ops->check_queue_exist(dev_mgt->chan_ops_tbl->priv, chan_type))
+ chan_ops->register_chan_task(dev_mgt->chan_ops_tbl->priv,
+ chan_type, task);
+}
+
+/* ---------- Tasks config ---------- */
+static void nbl_dev_clean_mailbox_task(struct work_struct *work)
+{
+ struct nbl_dev_common *common_dev =
+ container_of(work, struct nbl_dev_common, clean_mbx_task);
+ struct nbl_dev_mgt *dev_mgt = common_dev->dev_mgt;
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+
+ chan_ops->clean_queue_subtask(dev_mgt->chan_ops_tbl->priv,
+ NBL_CHAN_TYPE_MAILBOX);
+}
+
+/* ---------- Dev init process ---------- */
+static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dev_common *common_dev;
+ int ret;
+
+ common_dev = devm_kzalloc(&adapter->pdev->dev, sizeof(*common_dev),
+ GFP_KERNEL);
+ if (!common_dev)
+ return -ENOMEM;
+ common_dev->dev_mgt = dev_mgt;
+
+ /*
+ * INIT_WORK must precede nbl_dev_register_chan_task() below:
+ * registration publishes the work item to the channel, and the
+ * channel may queue it from its send and receive paths as soon
+ * as setup_queue() completes.
+ */
+ INIT_WORK(&common_dev->clean_mbx_task, nbl_dev_clean_mailbox_task);
+
+ ret = nbl_dev_setup_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+ if (ret) {
+ /*
+ * Nothing to unwind: chan_info->active is only set on a
+ * successful setup_queue(), so a failed one left no
+ * sender, no registered work item and no mailbox
+ * traffic. Calling teardown_queue() here would only
+ * take its "channel not active" early exit and emit a
+ * misleading duplicate-teardown warning. The partially
+ * allocated DMA rings are intentionally kept until devres
+ * releases them at detach (chan_info->dma_allocated
+ * blocks a re-setup).
+ */
+ return ret;
+ }
+
+ nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX,
+ &common_dev->clean_mbx_task);
+ /*
+ * VSI/ETH identity is deliberately not fetched here but in the
+ * start path, which is where it is used: the IDs only feed MSI-X
+ * and queue setup. Responder availability is not what defers it -
+ * nbl_probe_chip_deps() keeps a sibling in -EPROBE_DEFER until
+ * func 0 is bound, and driver_bound() only runs after func 0's
+ * whole probe, this function included, has returned.
+ */
+ dev_mgt->common_dev = common_dev;
+ nbl_dev_init_msix_cnt(dev_mgt);
+
+ return 0;
+}
+
+static void nbl_dev_remove_common_dev(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+
+ if (!common_dev)
+ return;
+ cancel_work_sync(&common_dev->clean_mbx_task);
+ /*
+ * nbl_chan_teardown_queue() never fails: it returns 0 both on the
+ * early exit for a channel that never became active and on the
+ * normal path, which drains every inflight sender before
+ * returning. There is therefore no partial-failure state that
+ * could leave mailbox DMA in flight and nothing to report here.
+ *
+ * Unregistering the clean task is the channel layer's job too:
+ * teardown_queue() clears clean_task under state_lock and then
+ * cancel_work_sync()es it, after shutdn has blocked new queues.
+ * No explicit unregistration is needed here precisely because
+ * teardown_queue() does that clearing itself. Passing NULL from
+ * here would not be a no-op either: shutdn is only set inside
+ * teardown_queue(), so nbl_chan_register_chan_task() would still
+ * accept the write - it would just be clearing the same pointer a
+ * second time.
+ */
+ nbl_dev_remove_chan_queue(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+}
+
+static int nbl_dev_setup_ctrl_dev(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+
+ return disp_ops->init_module(dev_mgt->disp_ops_tbl->priv);
+}
+
+/*
+ * Tear down control device: deinit_module sets driver_status=false
+ * to notify firmware to clean all per-PF hardware state (including
+ * qinfo registers). The qinfo map programmed in nbl_dev_init() via
+ * nbl_dev_setup_chan_qinfo() is not explicitly cleared; firmware
+ * handles it on driver_status change.
+ *
+ * Teardown ordering guarantee: every non-management PF creates a
+ * consumer->control PF device link in its probe path, so the driver
+ * core always unbinds all siblings before allowing the control PF to
+ * be detached (sysfs unbind, driver unregister and hot-unplug alike).
+ * nbl_probe_chip_deps() defers a sibling's probe until the control PF
+ * is fully bound (DL_DEV_DRIVER_BOUND), and holds the management PF's
+ * device lock across both that check and device_link_add(), so a
+ * supplier cannot slip to DL_DEV_NO_DRIVER or DL_DEV_PROBING in
+ * between. A sibling therefore cannot
+ * reach its mailbox setup before the control PF is fully probed, nor
+ * race this deinit afterwards - the link forces it to be unbound
+ * first. The link is a persistent managed link with
+ * DL_FLAG_AUTOPROBE_CONSUMER, so binding the control PF again makes
+ * the core re-probe the siblings; without it they would stay unbound
+ * until an admin rebound each one by hand.
+ *
+ * Direct control-PF FLR (which never runs driver teardown) cannot be
+ * guarded here.
+ */
+static void nbl_dev_remove_ctrl_dev(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+
+ disp_ops->deinit_module(dev_mgt->disp_ops_tbl->priv);
+}
+
+static struct nbl_dev_mgt *nbl_dev_setup_dev_mgt(struct nbl_common_info *common)
+{
+ struct nbl_dev_mgt *dev_mgt;
+
+ dev_mgt = devm_kzalloc(common->dev, sizeof(*dev_mgt), GFP_KERNEL);
+ if (!dev_mgt)
+ return ERR_PTR(-ENOMEM);
+
+ dev_mgt->common = common;
+ return dev_mgt;
+}
+
+int nbl_dev_init(struct nbl_adapter *adapter)
+{
+ struct nbl_common_info *common = &adapter->common;
+ struct nbl_dispatch_ops_tbl *disp_ops_tbl =
+ adapter->intf.dispatch_ops_tbl;
+ struct nbl_channel_ops_tbl *chan_ops_tbl =
+ adapter->intf.channel_ops_tbl;
+ struct nbl_dev_mgt *dev_mgt;
+ int ret;
+
+ dev_mgt = nbl_dev_setup_dev_mgt(common);
+ if (IS_ERR(dev_mgt)) {
+ ret = PTR_ERR(dev_mgt);
+ return ret;
+ }
+
+ dev_mgt->disp_ops_tbl = disp_ops_tbl;
+ dev_mgt->chan_ops_tbl = chan_ops_tbl;
+ adapter->core.dev_mgt = dev_mgt;
+ if (common->has_ctrl)
+ nbl_dev_setup_chan_qinfo(dev_mgt, NBL_CHAN_TYPE_MAILBOX);
+ /*
+ * Chip hardware initialization is completed by firmware at power-up.
+ * Only driver functional table/register config follows here, safe to
+ * access hardware registers before ctrl dev setup.
+ *
+ * The QINFO routing has to be programmed before the mailbox queue is
+ * enabled: nbl_dev_setup_common_dev() sets QUEUE_EN, and a queue that
+ * is live before its routing is in place would drop or misroute
+ * traffic.
+ */
+ ret = nbl_dev_setup_common_dev(adapter);
+ if (ret)
+ goto setup_err;
+
+ if (common->has_ctrl) {
+ ret = nbl_dev_setup_ctrl_dev(adapter);
+ if (ret)
+ goto setup_ctrl_dev_fail;
+ }
+
+ return 0;
+/*
+ * A failure after the QINFO routing was programmed leaves those entries
+ * in hardware: driver_status never goes 1 -> 0 on these paths, so
+ * firmware does not reclaim them. This is harmless - firmware only
+ * routes once driver_status announces the driver, and no sibling PF can
+ * bind until this probe succeeds. The next successful probe overwrites
+ * the entries, and a chip reset clears them.
+ */
+setup_ctrl_dev_fail:
+ nbl_dev_remove_common_dev(adapter);
+setup_err:
+ return ret;
+}
+
+/*
+ * Teardown order: Stop mailbox channel and drain all inflight DMA first,
+ * then invoke deinit_module to notify firmware.
+ *
+ * This intentionally breaks strict init/teardown mirror symmetry due to
+ * a hardware constraint: firmware performs asynchronous *per-PF* cleanup
+ * (mailbox QINFO routing, qinfo registers and the like) once
+ * driver_status=false is set. It does not revert the chip-wide
+ * datapath registers configured by init_module - those stay valid until
+ * chip reset (see nbl_hw_deinit_module()). We must guarantee no ongoing
+ * mailbox DMA before deinit_module so firmware cannot reclaim the
+ * routing under a live transfer and leave the device DMAing into
+ * released memory.
+ *
+ * Init order: program mailbox QINFO routing (ctrl PF only) ->
+ * create mailbox queue/common_dev -> ctrl dev init_module
+ * Teardown order: destroy mailbox queue/common_dev -> ctrl dev deinit_module
+ */
+void nbl_dev_remove(struct nbl_adapter *adapter)
+{
+ struct nbl_common_info *common = &adapter->common;
+
+ nbl_dev_remove_common_dev(adapter);
+ if (common->has_ctrl)
+ nbl_dev_remove_ctrl_dev(adapter);
+}
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
new file mode 100644
index 000000000..24e890fd8
--- /dev/null
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Nebula Matrix Limited.
+ */
+
+#ifndef _NBL_DEV_H_
+#define _NBL_DEV_H_
+
+#include <linux/types.h>
+
+#include "../nbl_include/nbl_include.h"
+#include "../nbl_include/nbl_def_channel.h"
+#include "../nbl_include/nbl_def_hw.h"
+#include "../nbl_include/nbl_def_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"
+
+#define NBL_STRING_NAME_LEN 32
+
+enum nbl_msix_serv_type {
+ NBL_MSIX_NET_TYPE,
+ NBL_MSIX_MAILBOX_TYPE,
+ NBL_MSIX_TYPE_MAX
+};
+
+struct nbl_msix_serv_info {
+ char irq_name[NBL_STRING_NAME_LEN];
+ u16 num;
+ u16 base_vector_id;
+ /* true: hw report msix, hw need to mask actively */
+ bool hw_self_mask_en;
+};
+
+struct nbl_msix_info {
+ struct nbl_msix_serv_info serv_info[NBL_MSIX_TYPE_MAX];
+};
+
+struct nbl_dev_common {
+ struct nbl_dev_mgt *dev_mgt;
+ struct nbl_msix_info msix_info;
+ char mailbox_name[NBL_STRING_NAME_LEN];
+ /* for ctrl-dev/net-dev mailbox recv msg */
+ struct work_struct clean_mbx_task;
+};
+
+struct nbl_dev_mgt {
+ struct nbl_common_info *common;
+ struct nbl_dispatch_ops_tbl *disp_ops_tbl;
+ struct nbl_channel_ops_tbl *chan_ops_tbl;
+ struct nbl_dev_common *common_dev;
+};
+
+#endif
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
index cb68544e0..59d80066f 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
@@ -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.
+ */
}
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
new file mode 100644
index 000000000..51cf04e4c
--- /dev/null
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
@@ -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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
index 830ef7ebe..dd81720df 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
@@ -12,6 +12,7 @@
#include "nbl_include/nbl_def_hw.h"
#include "nbl_include/nbl_def_resource.h"
#include "nbl_include/nbl_def_dispatch.h"
+#include "nbl_include/nbl_def_dev.h"
#include "nbl_include/nbl_def_common.h"
#include "nbl_core.h"
@@ -53,7 +54,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
ret = nbl_disp_init(adapter);
if (ret)
goto out_res_remove;
+
+ ret = nbl_dev_init(adapter);
+ if (ret)
+ goto out_disp_remove;
return adapter;
+
+out_disp_remove:
+ nbl_disp_remove(adapter);
out_res_remove:
nbl_res_remove_leonis(adapter);
out_chan_remove:
@@ -66,6 +74,7 @@ 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);
--
2.51.0.windows.1
[PATCH v34 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Author: "illusion.wang"
Date: Thu, 12 Nov 2026 09:49
Date: Thu, 12 Nov 2026 09:49
707 lines
37023 bytes
37023 bytes
From: illusion wang <illusion.wang@nebula-matrix.com>
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 through
driver_override: binding this driver to a function that is absent from
nbl_id_table makes pci_match_device() pass the dummy ID whose driver_data
0 leaves both capabilities clear. That means a VF, or a foreign device
at a function other than 0 - a PF of this device always matches
nbl_id_table, and new_id rejects a driver_data the table does not
contain. A foreign non-VF device at function 0 is unaffected:
nbl_get_func_param() gives it has_ctrl, so it is not rejected here and
still runs nbl_core_init() and nbl_core_start() with the local control
dispatch ops. nbl_dev_init()'s unwind labels change with it:
setup_ctrl_dev_fail becomes out_remove_common_dev, and the setup_err path
drops its label and returns directly, since a failed
nbl_dev_setup_common_dev() has nothing to unwind.
Startup RPC errors are propagated unchanged. A -ETIMEDOUT here is a real
failure, not a "supplier not ready yet" condition: nbl_probe() already
deferred this PF in nbl_probe_chip_deps() until the control PF reached
DL_DEV_DRIVER_BOUND, and the driver core only marks a device bound once
its entire probe - including the control PF's own nbl_core_start() - has
returned. That state is what bounds the wait, not nbl_dev_init(): on
the control PF inbound mailbox work only runs from clean_mbx_task, which
is queued by the mailbox hardirq, by the task's own self-requeue, or by
this function's polling sends, and the control PF uses the local dispatch
ops so it sends none. The responder is armed by set_mailbox_irq(true)
at the end of the peer's nbl_dev_start(). Relaxing the dependency to
"func 0 finished nbl_dev_init()" would therefore let every sibling RPC
sit out the full 5-6s polling wait. Converting the timeout to
-EPROBE_DEFER would only hide it behind dev_dbg() and make every later
bind pay that wait again.
Teardown releases the kernel MSI-X vectors before destroying the hardware
pcompleter map. pci_free_irq_vectors() ends in pci_msix_shutdown(),
which masks every descriptor by writing the MSI-X table and reading it
back to flush the write; those accesses should reach the function while
FUNCTION_MSIX_MAP is still valid. This mirrors start, where cfg_msix_map
runs before pci_alloc_irq_vectors_affinity(). It is not a double free of
the pcim_msi_release devres registered alongside
pci_alloc_irq_vectors(): that action only calls pci_free_irq_vectors()
again, and pci_disable_msix() returns early once msix_enabled is clear.
Start and stop still each run once, tied to probe and remove.
The rest of teardown is best-effort. The MSI-X map is torn down even
when the configure RPC failed: a timeout only means the ACK never
arrived, while the responder runs to completion before ACKing, so the
entry, the intr_net/other_bmap bits and the kcalloc()ed vector array stay
owned by the control PF. Those are host resources of that driver, not
firmware state, and neither recovery path needs a chip reset: a later
successful configuration of this function releases the old bits, frees
the old array, invalidates and rewrites the entry on its had_config path,
and nbl_intr_mgt_stop() clears the FUNCTION_MSIX_MAP valid bit for every
still-configured function when the control PF is removed. The coherent
map table is different: neither per-function path frees it, it is kept
for the function's lifetime and reused in place, and nbl_intr_mgt_stop()
is the only place it is released.
That is also what keeps the stop ordering safe. nbl_remove() calls
nbl_core_stop() before pci_clear_master(), so the control PF destroys
its own map entry while its Bus Master Enable is still set. That is
deliberate: nbl_core_stop() cannot run after pci_clear_master(), because
on a non-control PF it is a mailbox RPC, which needs bus mastering for
the ring DMA. The destroy only clears the VALID bit and keeps the
coherent table, so the actual free still happens later, in
nbl_intr_mgt_stop(), after pci_clear_master(). nbl_probe()'s
start-failure unwind uses the same order. pci_clear_master() remains no
safety net for a non-control PF: it cannot stop DMA issued with the
management PF's BDF.
Signed-off-by: illusion wang <illusion.wang@nebula-matrix.com>
---
.../net/ethernet/nebula-matrix/nbl/nbl_core.h | 11 +
.../nebula-matrix/nbl/nbl_core/nbl_dev.c | 446 +++++++++++++++++-
.../nbl/nbl_include/nbl_def_dev.h | 2 +
.../net/ethernet/nebula-matrix/nbl/nbl_main.c | 49 +-
4 files changed, 502 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
index c3c4dd685..051574810 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
@@ -40,4 +40,15 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
struct nbl_init_param *param);
void nbl_core_remove(struct nbl_adapter *adapter);
+/*
+ * Single-shot start/stop pair, called once each from PCI probe/remove.
+ * Not repeatable, but not because the MSI-X core would refuse a second
+ * start: nbl_dev_stop() releases the vectors with pci_free_irq_vectors().
+ * What the pair brackets is the device's active lifetime, and
+ * nbl_core_stop() is only ever followed by nbl_core_remove(), which
+ * destroys the mailbox channel and the resource state that start needs.
+ */
+int nbl_core_start(struct nbl_adapter *adapter);
+void nbl_core_stop(struct nbl_adapter *adapter);
+
#endif
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
index 0cc0c58ad..e91ec22e3 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
@@ -6,6 +6,17 @@
#include <linux/pci.h>
#include "nbl_dev.h"
+static void nbl_dev_clean_mailbox_schedule(struct nbl_dev_mgt *dev_mgt);
+
+/* ---------- Interrupt config ---------- */
+static irqreturn_t nbl_dev_clean_mailbox(int irq __always_unused, void *data)
+{
+ struct nbl_dev_mgt *dev_mgt = (struct nbl_dev_mgt *)data;
+
+ nbl_dev_clean_mailbox_schedule(dev_mgt);
+ return IRQ_HANDLED;
+}
+
static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)
{
struct nbl_dev_common *dev_common = dev_mgt->common_dev;
@@ -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;
}
+static int nbl_dev_request_mailbox_irq(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;
+ struct nbl_common_info *common = dev_mgt->common;
+ u16 lvec;
+ int irq_num;
+ int err;
+
+ if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num)
+ return 0;
+
+ lvec = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].base_vector_id;
+ irq_num = pci_irq_vector(common->pdev, lvec);
+ if (irq_num < 0) {
+ dev_err(common->dev, "Failed to get mailbox IRQ vector: %d\n",
+ irq_num);
+ return irq_num;
+ }
+
+ snprintf(dev_common->mailbox_name, sizeof(dev_common->mailbox_name),
+ "nbl_mailbox@pci:%s", pci_name(common->pdev));
+ err = request_irq(irq_num, nbl_dev_clean_mailbox, 0,
+ dev_common->mailbox_name, dev_mgt);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static void nbl_dev_free_mailbox_irq(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;
+ struct nbl_common_info *common = dev_mgt->common;
+ u16 lvec;
+ int irq_num;
+
+ if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num)
+ return;
+
+ lvec = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].base_vector_id;
+ irq_num = pci_irq_vector(common->pdev, lvec);
+ if (irq_num >= 0)
+ free_irq(irq_num, dev_mgt);
+}
+
+static int nbl_dev_enable_mailbox_irq(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+ struct nbl_dev_common *dev_common = dev_mgt->common_dev;
+ struct nbl_msix_info *msix_info = &dev_common->msix_info;
+ u16 lvec;
+ int ret;
+
+ if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num)
+ return 0;
+
+ lvec = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].base_vector_id;
+ /*
+ * Enable sequence: perform set_mailbox_irq RPC in polling mode first.
+ * Only set NBL_CHAN_IRQ_RDY after RPC succeeds, mirroring disable path.
+ * This avoids waiting for an interrupt which has not been armed yet.
+ */
+ ret = disp_ops->set_mailbox_irq(dev_mgt->disp_ops_tbl->priv,
+ lvec, true);
+ if (ret)
+ return ret;
+ chan_ops->set_queue_state(dev_mgt->chan_ops_tbl->priv,
+ NBL_CHAN_IRQ_RDY,
+ NBL_CHAN_TYPE_MAILBOX, true);
+ return 0;
+}
+
+static int nbl_dev_disable_mailbox_irq(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+ struct nbl_channel_ops *chan_ops = dev_mgt->chan_ops_tbl->ops;
+ struct nbl_dev_common *dev_common = dev_mgt->common_dev;
+ struct nbl_msix_info *msix_info = &dev_common->msix_info;
+ u16 lvec;
+
+ if (!msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num)
+ return 0;
+
+ lvec = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].base_vector_id;
+ /*
+ * Disable sequence invariant: clear the software READY flag first,
+ * then mask the hardware interrupt. Must not reverse the order.
+ *
+ * Clearing NBL_CHAN_IRQ_RDY is what makes an interrupt-mode sender
+ * fail fast: nbl_chan_set_queue_state() wakes every per-slot wait
+ * queue on the transition, and nbl_chan_send_msg() tests the flag
+ * ahead of its timeout branch, so the sender returns -EIO right
+ * away instead of waiting out NBL_CHAN_ACK_WAIT_TIME (3s) and
+ * reporting a bogus -ETIMEDOUT / "Channel waiting ack failed".
+ * Masking first would leave the sleeper blocked on an interrupt
+ * that is already masked, i.e. guaranteed to time out.
+ *
+ * This does NOT preserve in-flight ACKs, and must not be described
+ * as doing so: the woken sender gives up and resets its slot to
+ * IDLE, so an ACK arriving afterwards finds a non-WAITING slot and
+ * is dropped by the receive path ("Skip ack invalid status").
+ * Interrupt mode is being torn down here; the guarantee is a
+ * bounded, deterministic failure, not delivery. In this driver
+ * every ACK-requesting sender runs from probe/remove and the clean
+ * task only sends ACK-less replies, so nothing depends on the
+ * stronger claim today.
+ *
+ * The only caller is nbl_dev_stop(): free_irq() blocks until
+ * any in-flight hardirq handler completes and prevents new interrupts.
+ * cancel_work_sync() then waits for any already running mailbox cleanup
+ * work to finish, or cancels queued but unstarted work items before
+ * final channel destruction. No stuck descriptors linger.
+ *
+ * nbl_dev_start()'s unwind path does not reach here: err_free_irq runs
+ * before IRQ_RDY is set, so only nbl_dev_free_mailbox_irq() applies
+ * there and no set_mailbox_irq(false) is sent - see the comment on
+ * that label.
+ */
+ chan_ops->set_queue_state(dev_mgt->chan_ops_tbl->priv,
+ NBL_CHAN_IRQ_RDY,
+ NBL_CHAN_TYPE_MAILBOX, false);
+
+ return disp_ops->set_mailbox_irq(dev_mgt->disp_ops_tbl->priv,
+ lvec, false);
+}
+
+static int nbl_dev_cfg_msix_map(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+ struct nbl_dev_common *dev_common = dev_mgt->common_dev;
+ struct nbl_msix_info *msix_info = &dev_common->msix_info;
+ bool mask_en = msix_info->serv_info[NBL_MSIX_NET_TYPE].hw_self_mask_en;
+ u16 msix_net_num = msix_info->serv_info[NBL_MSIX_NET_TYPE].num;
+ u16 msix_not_net_num = 0;
+ int err, i;
+
+ msix_info->serv_info[NBL_MSIX_NET_TYPE].base_vector_id = 0;
+ /*
+ * Calculate base_vector_id for each MSIX service type.
+ * This relies on NBL_MSIX_TYPE enum being ordered sequentially,
+ * starting from NBL_MSIX_NET_TYPE.
+ */
+ for (i = NBL_MSIX_NET_TYPE + 1; i < NBL_MSIX_TYPE_MAX; i++)
+ msix_info->serv_info[i].base_vector_id =
+ msix_info->serv_info[i - 1].base_vector_id +
+ msix_info->serv_info[i - 1].num;
+
+ for (i = 0; i < NBL_MSIX_TYPE_MAX; i++) {
+ if (i == NBL_MSIX_NET_TYPE)
+ continue;
+ msix_not_net_num += msix_info->serv_info[i].num;
+ }
+
+ err = disp_ops->cfg_msix_map(dev_mgt->disp_ops_tbl->priv,
+ msix_net_num, msix_not_net_num,
+ mask_en);
+
+ return err;
+}
+
+static int nbl_dev_destroy_msix_map(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+
+ return disp_ops->destroy_msix_map(dev_mgt->disp_ops_tbl->priv);
+}
+
+static int nbl_dev_init_interrupt_scheme(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dev_common *dev_common = dev_mgt->common_dev;
+ struct nbl_msix_info *msix_info = &dev_common->msix_info;
+ struct nbl_common_info *common = dev_mgt->common;
+ struct irq_affinity affd = { 0 };
+ int needed = 0;
+ int err;
+ int i;
+
+ for (i = 0; i < NBL_MSIX_TYPE_MAX; i++)
+ needed += msix_info->serv_info[i].num;
+
+ /*
+ * The mailbox vector is the trailing administrative vector;
+ * reserve it via post_vectors so it is excluded from managed
+ * affinity spreading. A managed vector can be shut down when
+ * its last assigned CPU goes offline, which would stall every
+ * mailbox RPC while NBL_CHAN_IRQ_RDY stays set.
+ */
+ affd.post_vectors = msix_info->serv_info[NBL_MSIX_MAILBOX_TYPE].num;
+
+ err = pci_alloc_irq_vectors_affinity(common->pdev, needed, needed,
+ PCI_IRQ_MSIX | PCI_IRQ_AFFINITY,
+ &affd);
+ if (err < 0) {
+ dev_err(common->dev,
+ "pci_alloc_irq_vectors failed, err = %d\n", err);
+ return err;
+ }
+ if (err != needed) {
+ dev_err(common->dev, "pci_alloc_irq_vectors got %d vecs, need %d\n",
+ err, needed);
+ return -ENOSPC;
+ }
+ return 0;
+}
+
+/*
+ * Release the kernel-side MSI-X vectors here, before the hardware
+ * pcompleter map is destroyed. pci_free_irq_vectors() ends in
+ * pci_msix_shutdown(), which masks every descriptor by writing the
+ * vector control word in the MSI-X table and then reads mask_base
+ * back to flush that write; those MMIO accesses should reach the
+ * function while FUNCTION_MSIX_MAP is still valid. This mirrors
+ * nbl_dev_start(), where cfg_msix_map runs before
+ * pci_alloc_irq_vectors_affinity(): the opposite order leaves the
+ * core poking the MSI-X table after destroy_msix_map() has cleared
+ * the valid bit and invalidated the info entries, and how the device
+ * reacts to that is hardware-specific.
+ *
+ * This is not a double free of the devres action. probe uses
+ * pcim_enable_device(), so pci_alloc_irq_vectors() also registers
+ * pcim_msi_release, but that only calls pci_free_irq_vectors()
+ * again, and pci_disable_msix() returns early once msix_enabled is
+ * clear.
+ *
+ * The handler is expected to be gone by now: both callers run
+ * nbl_dev_free_mailbox_irq() first.
+ */
+static void nbl_dev_clear_interrupt_scheme(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_common_info *common = dev_mgt->common;
+
+ pci_free_irq_vectors(common->pdev);
+}
+
/* ---------- Channel config ---------- */
static void nbl_dev_setup_chan_qinfo(struct nbl_dev_mgt *dev_mgt, u8 chan_type)
{
@@ -86,6 +334,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work)
NBL_CHAN_TYPE_MAILBOX);
}
+static void nbl_dev_clean_mailbox_schedule(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+ struct nbl_common_info *common = dev_mgt->common;
+
+ queue_work(common->wq, &common_dev->clean_mbx_task);
+}
+
/* ---------- Dev init process ---------- */
static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)
{
@@ -254,15 +510,16 @@ int nbl_dev_init(struct nbl_adapter *adapter)
*/
ret = nbl_dev_setup_common_dev(adapter);
if (ret)
- goto setup_err;
+ return ret;
if (common->has_ctrl) {
ret = nbl_dev_setup_ctrl_dev(adapter);
if (ret)
- goto setup_ctrl_dev_fail;
+ goto out_remove_common_dev;
}
return 0;
+
/*
* A failure after the QINFO routing was programmed leaves those entries
* in hardware: driver_status never goes 1 -> 0 on these paths, so
@@ -271,9 +528,8 @@ int nbl_dev_init(struct nbl_adapter *adapter)
* bind until this probe succeeds. The next successful probe overwrites
* the entries, and a chip reset clears them.
*/
-setup_ctrl_dev_fail:
+out_remove_common_dev:
nbl_dev_remove_common_dev(adapter);
-setup_err:
return ret;
}
@@ -303,3 +559,185 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
if (common->has_ctrl)
nbl_dev_remove_ctrl_dev(adapter);
}
+
+/* ---------- Dev start process ---------- */
+int nbl_dev_start(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dispatch_ops *disp_ops = dev_mgt->disp_ops_tbl->ops;
+ struct nbl_dispatch_mgt *priv = dev_mgt->disp_ops_tbl->priv;
+ struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+ struct nbl_common_info *common = dev_mgt->common;
+ int cleanup_ret;
+ int ret;
+
+ /*
+ * Startup RPC failures are reported as they are, including the
+ * -ETIMEDOUT of a 5-6s polling wait against an unresponsive peer.
+ * nbl_probe() already deferred this PF in nbl_probe_chip_deps()
+ * until the control PF reached DL_DEV_DRIVER_BOUND, and the core
+ * only marks a device bound once its whole probe - including the
+ * control PF's own nbl_core_start() - has returned. That state,
+ * not nbl_dev_init(), is what makes a timeout here a real failure
+ * instead of a "supplier not ready yet" condition: on the control
+ * PF inbound mailbox work only runs from clean_mbx_task, 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 very end of the peer's
+ * nbl_dev_start(); relaxing the dependency to "func 0 finished
+ * nbl_dev_init()" would let every sibling RPC sit out the full
+ * 5-6s polling wait. Turning -ETIMEDOUT into -EPROBE_DEFER would
+ * hide it behind dev_dbg() and leave the retry to the next
+ * unrelated device bind, paying that wait again on every retry.
+ */
+ ret = nbl_dev_cfg_msix_map(dev_mgt);
+ if (ret)
+ goto err_destroy_map;
+
+ /* Fetch VSI/ETH identity after cfg_msix_map */
+ ret = disp_ops->get_vsi_id(priv, NBL_VSI_DATA, &common->vsi_id);
+ if (ret)
+ goto err_destroy_map;
+ ret = disp_ops->get_eth_id(priv, common->vsi_id, &common->eth_num,
+ &common->eth_id, &common->logic_eth_id);
+ if (ret)
+ goto err_destroy_map;
+
+ ret = nbl_dev_init_interrupt_scheme(dev_mgt);
+ if (ret)
+ goto err_destroy_map;
+
+ ret = nbl_dev_request_mailbox_irq(dev_mgt);
+ if (ret)
+ goto err_destroy_map;
+
+ ret = nbl_dev_enable_mailbox_irq(dev_mgt);
+ if (ret)
+ goto err_free_irq;
+
+ return 0;
+
+err_free_irq:
+ /*
+ * nbl_dev_enable_mailbox_irq() only fails before it sets
+ * NBL_CHAN_IRQ_RDY - the flag is set after its RPC returns - so
+ * there is no interrupt-mode sender to release and no software
+ * state to revoke. The peer-side mailbox routing, if the failed
+ * RPC did land, is switched off by the destroy_msix_map() below: its
+ * prepare phase, __nbl_res_intr_prepare_destroy_msix_map(), disables
+ * mailbox IRQ routing for any CONFIGURED function before the map is
+ * torn down. That is what makes skipping set_mailbox_irq(false)
+ * correct here, whatever way the enable failed - a local
+ * -ESHUTDOWN/-ENODEV/-EINVAL on the control PF as much as a
+ * polling-mode -ETIMEDOUT against an unresponsive peer.
+ */
+ nbl_dev_free_mailbox_irq(dev_mgt);
+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 and the
+ * kcalloc()ed vector array are all still owned by the control PF,
+ * i.e. host resources of its driver. They are not firmware state,
+ * so skipping the destroy would strand them for a PF that has no
+ * driver to ever ask for them again. A later successful
+ * configuration of this function collects them on its had_config
+ * path: it releases the old bitmap bits, kfree()s the old vector
+ * array, invalidates and rewrites the entry. The coherent map
+ * table is different - it is never freed there, because it is kept
+ * for the function's lifetime and reused in place, and
+ * nbl_intr_mgt_stop() is what finally releases it.
+ *
+ * Kernel vectors are released first, by the
+ * nbl_dev_clear_interrupt_scheme() below: the PCI core's MSI-X
+ * shutdown writes the MSI-X table and reads it back, and those
+ * accesses should land while this function's pcompleter map entry
+ * is still valid. The destroy then masks all hardware vectors
+ * and clears that entry.
+ *
+ * For non-control PFs this is a polling-mode mailbox RPC:
+ * NBL_CHAN_IRQ_RDY is never set on any rollback path, since
+ * enabling it is the last step of nbl_dev_start().
+ *
+ * pci_clear_master() has not run at this point: nbl_probe() clears
+ * it after this rollback returns, before nbl_core_remove() runs.
+ * This rollback does not need it - the coherent table is kept, not
+ * freed here (see __nbl_res_intr_complete_destroy_msix_map()) - and
+ * on a non-control PF it could not stop DMA issued with the
+ * management PF's BDF in any case.
+ */
+ nbl_dev_clear_interrupt_scheme(dev_mgt);
+ cleanup_ret = nbl_dev_destroy_msix_map(dev_mgt);
+ if (cleanup_ret)
+ dev_err(dev_mgt->common->dev,
+ "rollback: destroy MSI-X map failed: %d\n",
+ cleanup_ret);
+
+ cancel_work_sync(&common_dev->clean_mbx_task);
+ return ret;
+}
+
+void nbl_dev_stop(struct nbl_adapter *adapter)
+{
+ struct nbl_dev_mgt *dev_mgt = adapter->core.dev_mgt;
+ struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+ int ret;
+
+ ret = nbl_dev_disable_mailbox_irq(dev_mgt);
+ if (ret)
+ dev_err(dev_mgt->common->dev,
+ "Failed to disable mailbox IRQ: %d\n", ret);
+ nbl_dev_free_mailbox_irq(dev_mgt);
+
+ /*
+ * Release the kernel vectors before destroying the hardware map:
+ * the PCI core's MSI-X shutdown writes the MSI-X table and reads
+ * it back, and those accesses should land while this function's
+ * pcompleter map entry is still valid (see
+ * nbl_dev_clear_interrupt_scheme).
+ */
+ nbl_dev_clear_interrupt_scheme(dev_mgt);
+
+ /*
+ * Destroy the hardware MSI-X map: masks all device vectors and
+ * clears the pcompleter map entry.
+ *
+ * Best-effort: if the destroy RPC fails, the control PF still owns
+ * this function's map entry, its intr_net/other_bmap bits and its
+ * kcalloc()ed vector array. Those are host resources of that
+ * driver, released either by a later successful configuration of
+ * this function - nbl_res_intr_cfg_msix_map() invalidates and
+ * rewrites the entry, releases the old bits and frees the old array
+ * on its had_config path - or by nbl_intr_mgt_stop() when the
+ * control PF is removed, which walks every
+ * NBL_INTR_FUNC_CONFIGURED function through
+ * __nbl_res_intr_prepare_destroy_msix_map() and clears the
+ * FUNCTION_MSIX_MAP valid bit. The coherent map table is neither
+ * freed nor reallocated by reconfiguration: it is kept for the
+ * function's lifetime and released only by nbl_intr_mgt_stop().
+ * Both rewrite the hardware entry without a chip reset; nothing else
+ * collects it, so a stranded one just stays as it is, and nothing
+ * requests one.
+ *
+ * pci_clear_master() on a non-control PF cannot stop DMA using the
+ * management PF's BDF. It has not run yet on the control PF either,
+ * since nbl_remove() clears it after this function returns; what
+ * makes the only free - the one in nbl_intr_mgt_stop() - safe is
+ * that it runs after that point, with bus mastering off.
+ */
+ ret = nbl_dev_destroy_msix_map(dev_mgt);
+ if (ret)
+ dev_err(dev_mgt->common->dev,
+ "Failed to destroy MSI-X map: %d\n", ret);
+
+ /*
+ * destroy_msix_map() sends ack-requested messages which may
+ * requeue clean_mbx_task via polling send path. Drain work
+ * after the operation.
+ */
+ cancel_work_sync(&common_dev->clean_mbx_task);
+}
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
index 51cf04e4c..a66c633a0 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
@@ -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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
index dd81720df..93c8d3d86 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
@@ -16,6 +16,16 @@
#include "nbl_include/nbl_def_common.h"
#include "nbl_core.h"
+int nbl_core_start(struct nbl_adapter *adapter)
+{
+ return nbl_dev_start(adapter);
+}
+
+void nbl_core_stop(struct nbl_adapter *adapter)
+{
+ nbl_dev_stop(adapter);
+}
+
struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
struct nbl_init_param *param)
{
@@ -242,6 +252,27 @@ 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 absent from nbl_id_table
+ * makes pci_match_device() pass the dummy ID whose driver_data 0
+ * leaves has_ctrl and has_net both clear. That means a VF, or a
+ * foreign device at a function other than 0: a PF of this device
+ * always matches nbl_id_table, and new_id rejects a driver_data the
+ * table does not contain. A foreign non-VF device at function 0 is
+ * unaffected: nbl_get_func_param() gives it has_ctrl, so it is not
+ * rejected here and still runs nbl_core_init() and nbl_core_start()
+ * with the local control dispatch ops.
+ */
+ 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);
@@ -279,8 +310,16 @@ 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) {
+ /*
+ * Same order as nbl_remove(): stop bus mastering before the
+ * teardown that frees the MSI-X map tables.
+ */
+ pci_clear_master(pdev);
+ nbl_core_remove(adapter);
+ }
+ return err;
}
static void nbl_remove(struct pci_dev *pdev)
@@ -291,6 +330,7 @@ static void nbl_remove(struct pci_dev *pdev)
return;
pci_set_drvdata(pdev, NULL);
+ nbl_core_stop(adapter);
/*
* Stop bus mastering before the teardown in nbl_core_remove()
* releases the map tables.
@@ -303,6 +343,11 @@ static void nbl_remove(struct pci_dev *pdev)
* nbl_intr_quiesce_wait()). Clearing Bus Master Enable first
* keeps the device from starting a new fetch at all, so that
* residual window only covers requests already in flight.
+ *
+ * nbl_core_stop() above has already torn down this function's own
+ * map, so what is left to protect here is the control PF's table of
+ * per-function entries, freed from nbl_intr_mgt_stop() inside
+ * nbl_core_remove().
*/
pci_clear_master(pdev);
--
2.51.0.windows.1
Re: [PATCH v34 net-next 7/8] net/nebula-matrix: add common/ctrl dev init/remove operation
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:54
Date: Mon, 16 Nov 2026 13:54
259 lines
18363 bytes
18363 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · 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).
- [Medium] This patch's teardown ordering assumes that no sibling PF can
probe while the control PF runs nbl_dev_remove().
- [Medium] This patch adds nbl_dev_init() to nbl_core_init(), and
nbl_probe() calls pci_set_master() only after nbl_core_init() returns.
- [Low] The comment block added above nbl_dev_remove_ctrl_dev()
(drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c, lines…
- [Low] The commit message and the code comment added by the same patch
give opposite reasons for deferring the VSI/ETH identity lookup.
--
net/nebula-matrix: add common/ctrl dev init/remove operation
This commit adds nbl_dev.c and related headers that provide nbl_dev_init()
and nbl_dev_remove(), and wires them into nbl_core_init() and
nbl_core_remove(). Common setup creates the mailbox clean work and the
mailbox channel queue. The control PF also programs the mailbox QINFO
routing and runs init_module(), and calls deinit_module() after the
mailbox has been torn down.
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
> new file mode 100644
> index 0000000000000..0cc0c58ad6336
> --- /dev/null
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
[ ... ]
> + nbl_dev_register_chan_task(dev_mgt, NBL_CHAN_TYPE_MAILBOX,
> + &common_dev->clean_mbx_task);
> + /*
> + * VSI/ETH identity is deliberately not fetched here but in the
> + * start path, which is where it is used: the IDs only feed MSI-X
> + * and queue setup. Responder availability is not what defers it -
> + * nbl_probe_chip_deps() keeps a sibling in -EPROBE_DEFER until
> + * func 0 is bound, and driver_bound() only runs after func 0's
> + * whole probe, this function included, has returned.
> + */
[Severity: Low]
The commit message gives the opposite reason for deferring the VSI/ETH
lookup:
"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"
This comment, on the other hand, says responder availability is not why
the lookup is deferred.
Later in the series this comment is unchanged. The nbl_dev_start() comment
added there argues that responder readiness (func 0's set_mailbox_irq(true)
at the end of its start path) does matter.
Which of these is the real reason? Could the commit message and this
comment be made to agree?
[ ... ]
> +/*
> + * Tear down control device: deinit_module sets driver_status=false
> + * to notify firmware to clean all per-PF hardware state (including
> + * qinfo registers). The qinfo map programmed in nbl_dev_init() via
> + * nbl_dev_setup_chan_qinfo() is not explicitly cleared; firmware
> + * handles it on driver_status change.
> + *
> + * Teardown ordering guarantee: every non-management PF creates a
> + * consumer->control PF device link in its probe path, so the driver
> + * core always unbinds all siblings before allowing the control PF to
> + * be detached (sysfs unbind, driver unregister and hot-unplug alike).
> + * nbl_probe_chip_deps() defers a sibling's probe until the control PF
> + * is fully bound (DL_DEV_DRIVER_BOUND), and holds the management PF's
> + * device lock across both that check and device_link_add(), so a
> + * supplier cannot slip to DL_DEV_NO_DRIVER or DL_DEV_PROBING in
> + * between. A sibling therefore cannot
[Severity: Low]
Is this an accurate description of nbl_probe_chip_deps()? The function
itself says it does not take the management PF's device lock:
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c:nbl_probe_chip_deps() {
...
/*
* Deliberately lock-free. This probe already runs under
* device_lock(funcN), while __pci_bus_lock() (AER recovery, slot
* reset) walks the bus in devfn order, i.e. 0 -> N: taking
* device_lock(func0) here would establish the opposite order, and
...
if (READ_ONCE(mgt->dev.driver) != pdev->dev.driver ||
!device_is_bound(&mgt->dev)) {
...
link = device_link_add(&pdev->dev, &mgt->dev,
DL_FLAG_AUTOPROBE_CONSUMER);
...
if (READ_ONCE(mgt->dev.driver) != pdev->dev.driver ||
!device_is_bound(&mgt->dev)) {
...
}
There is no device_lock(&mgt->dev) call. The check reads dev.driver and
device_is_bound(), not links.status.
driver_bound() sets knode_driver with klist_add_tail() before
device_links_driver_bound() moves links.status to DL_DEV_DRIVER_BOUND. So
the check can accept a supplier that is still DL_DEV_PROBING.
This comment is still the same at the end of the series. Could it be
updated to match the lock-free implementation in nbl_main.c?
> + * reach its mailbox setup before the control PF is fully probed, nor
> + * race this deinit afterwards - the link forces it to be unbound
> + * first. The link is a persistent managed link with
[Severity: Medium]
Does the link really keep a sibling from racing this deinit? The commit
message makes the same claim:
"The device link created during non-control PF probe makes the driver
core unbind all sibling PFs before the control PF is removed."
The checks in nbl_probe_chip_deps() don't seem to catch a control PF that
is already unbinding. dev->driver and knode_driver both stay set for the
whole of ->remove():
drivers/base/dd.c:__device_release_driver() {
...
device_remove(dev);
...
device_unbind_cleanup(dev);
device_links_driver_cleanup(dev);
klist_remove(&dev->p->knode_driver);
...
}
Suppose func 0 is unbound through sysfs while a sibling with no link yet
probes (a first bind, a driver_override switch, or a deferred-probe retry):
func 0 (sysfs unbind)
__device_release_driver()
device_links_busy()
links.status = DL_DEV_UNBINDING /* no busy consumer link */
device_remove()
nbl_remove()->nbl_core_remove()->nbl_dev_remove()
nbl_dev_remove_common_dev()
nbl_dev_remove_ctrl_dev()->deinit_module()
sibling funcN (probing concurrently)
device_links_check_suppliers() /* no link yet, passes */
nbl_probe_chip_deps()
dev.driver / device_is_bound() check passes
device_link_add()
device_link_init_status()
link->status = DL_STATE_SUPPLIER_UNBIND
re-check with the same predicates passes
nbl_core_init()->nbl_dev_init()->nbl_dev_setup_common_dev()
nbl_dev_setup_chan_queue() /* sibling mailbox enabled */
The sibling's mailbox setup then overlaps func 0's mailbox teardown and
deinit_module(). deinit_module() sets driver_status=false, which lets
firmware reclaim the QINFO routing.
When the sibling's probe finishes, device_links_driver_bound() hits
WARN_ON(link->status != DL_STATE_CONSUMER_PROBE) and forces the link to
ACTIVE. func 0's device_links_driver_cleanup() then hits
WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND) and sets the link
DORMANT.
On the next bind of func 0 the link becomes AVAILABLE while the sibling
is still bound. A later unbind of func 0 then sees device_links_busy()
return false and removes the control PF with the sibling still bound.
A sibling that already has a link from an earlier probe is deferred by
device_links_check_suppliers() while the link is SUPPLIER_UNBIND, so this
seems limited to a sibling's first probe. nbl_probe_chip_deps() comes from
earlier in this series and is unchanged at the end of it.
Is there anything that orders a sibling's first probe against func 0's
unbind here?
[ ... ]
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
> index 830ef7ebea053..dd81720df9ff0 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c
[ ... ]
> @@ -53,7 +54,14 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
> ret = nbl_disp_init(adapter);
> if (ret)
> goto out_res_remove;
> +
> + ret = nbl_dev_init(adapter);
> + if (ret)
> + goto out_disp_remove;
> return adapter;
[Severity: Medium]
With nbl_dev_init() now called from nbl_core_init(), is the mailbox DMA
engine armed before bus mastering is enabled? nbl_probe() calls
pci_set_master() only after nbl_core_init() has returned:
drivers/net/ethernet/nebula-matrix/nbl/nbl_main.c:nbl_probe() {
...
* point is host-side setup plus MMIO and nothing in it waits for
* the device, so it does not need bus mastering.
*/
err = nbl_probe_chip_deps(pdev, param.caps.has_ctrl);
...
adapter = nbl_core_init(pdev, ¶m);
...
pci_set_master(pdev);
...
}
The chain nbl_dev_init()->nbl_dev_setup_common_dev()->
nbl_dev_setup_chan_queue()->nbl_chan_setup_queue() programs the ring
addresses with QUEUE_EN and gives the RX descriptors to the device:
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c:nbl_chan_setup_queue() {
...
nbl_chan_config_queue(chan_mgt, chan_info, true); /* tx */
nbl_chan_config_queue(chan_mgt, chan_info, false); /* rx */
nbl_chan_update_tail_ptr(hw_ops, chan_mgt->hw_ops_tbl->priv,
rxq->tail_ptr, NBL_MB_RX_QID);
WRITE_ONCE(chan_info->active, true);
...
}
This runs on both the control PF and the other PFs. The nbl_probe()
comment saying nothing before pci_set_master() needs bus mastering is no
longer true after this patch. The ordering is still the same at the end of
the series.
With Bus Master Enable clear, the function cannot issue memory requests.
Depending on the mailbox engine, an RX descriptor prefetch after the tail
doorbell could stall, be dropped, or latch an error. Nothing re-kicks or
re-validates the queue after pci_set_master().
Does this hardware hold such requests until bus mastering is enabled? If
it doesn't, can the queue state drift away from the driver's rings while
chan_info->active is already true?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112094925.6098-1-illusion.wang%40nebula-matrix.com
Re: [PATCH v34 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:54
Date: Mon, 16 Nov 2026 13:54
258 lines
18234 bytes
18234 bytes
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] net/nebula-matrix: unbind race and managed link del in
nbl_probe_chip_deps()
- [Low] This patch's commit message, and the new comment in
nbl_dev_stop() (around nbl_dev.c:729), say the coherent MSI-X map…
- [Low] The comment on nbl_dev_clear_interrupt_scheme() (nbl_dev.c:260)
says "The handler is expected to be gone by now: both callers run…
- [Low] A comment in nbl_res_remove_leonis()
(nbl_resource_leonis.c:358-360) says "Sibling PFs are already unbound…
- [Low] The kernel-doc of nbl_res_intr_cfg_msix_map()
(nbl_interrupt.c:361-363) says "The in-tree caller…
--
net/nebula-matrix: add common dev start/stop operation
This adds nbl_dev_start() and nbl_dev_stop(), which nbl_probe() and
nbl_remove() call through nbl_core_start() and nbl_core_stop(). Start
configures the MSI-X map, fetches the VSI/ETH ids, allocates the MSI-X
vectors and arms the mailbox interrupt, and stop undoes those steps.
nbl_probe() also now rejects a function that has neither the ctrl nor
the net capability.
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
> index 0cc0c58ad6336..e91ec22e3f76b 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
[ ... ]
> +static int nbl_dev_cfg_msix_map(struct nbl_dev_mgt *dev_mgt)
> +{
[ ... ]
> + err = disp_ops->cfg_msix_map(dev_mgt->disp_ops_tbl->priv,
> + msix_net_num, msix_not_net_num,
> + mask_en);
> +
> + return err;
> +}
[Severity: Low]
This isn't a bug, but nbl_dev_cfg_msix_map() is now the in-tree caller of
cfg_msix_map. The kernel-doc of nbl_res_intr_cfg_msix_map() in
nbl_interrupt.c names a different function:
* in-tree caller (nbl_dev_init_msix_cnt()) asks for one non-net vector
* per PF, far below NBL_MAX_OTHER_INTERRUPT.
nbl_dev_init_msix_cnt() only sets serv_info[NBL_MSIX_MAILBOX_TYPE].num = 1
and never calls cfg_msix_map.
Should the kernel-doc point to nbl_dev_cfg_msix_map(), reached from
nbl_dev_start(), instead?
[ ... ]
> + * The handler is expected to be gone by now: both callers run
> + * nbl_dev_free_mailbox_irq() first.
> + */
> +static void nbl_dev_clear_interrupt_scheme(struct nbl_dev_mgt *dev_mgt)
> +{
> + struct nbl_common_info *common = dev_mgt->common;
> +
> + pci_free_irq_vectors(common->pdev);
> +}
[Severity: Low]
Is this comment accurate for the nbl_dev_start() rollback? Five of the
error exits in nbl_dev_start() jump straight to err_destroy_map. That
label calls nbl_dev_clear_interrupt_scheme() without
nbl_dev_free_mailbox_irq():
ret = nbl_dev_cfg_msix_map(dev_mgt);
if (ret)
goto err_destroy_map;
...
ret = nbl_dev_request_mailbox_irq(dev_mgt);
if (ret)
goto err_destroy_map;
The same applies to the get_vsi_id, get_eth_id and
nbl_dev_init_interrupt_scheme() failures in between. Only the
nbl_dev_enable_mailbox_irq() failure goes through err_free_irq.
On those direct paths request_irq() was either never reached or failed,
so no handler is registered and nothing goes wrong today.
Could the comment describe that case instead of saying that both callers
free the IRQ first?
[ ... ]
> @@ -303,3 +559,185 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
[ ... ]
> +void nbl_dev_stop(struct nbl_adapter *adapter)
> +{
[ ... ]
> + /*
> + * Destroy the hardware MSI-X map: masks all device vectors and
> + * clears the pcompleter map entry.
> + *
> + * Best-effort: if the destroy RPC fails, the control PF still owns
> + * this function's map entry, its intr_net/other_bmap bits and its
> + * kcalloc()ed vector array. Those are host resources of that
> + * driver, released either by a later successful configuration of
> + * this function - nbl_res_intr_cfg_msix_map() invalidates and
> + * rewrites the entry, releases the old bits and frees the old array
> + * on its had_config path - or by nbl_intr_mgt_stop() when the
> + * control PF is removed, which walks every
> + * NBL_INTR_FUNC_CONFIGURED function through
> + * __nbl_res_intr_prepare_destroy_msix_map() and clears the
> + * FUNCTION_MSIX_MAP valid bit. The coherent map table is neither
> + * freed nor reallocated by reconfiguration: it is kept for the
> + * function's lifetime and released only by nbl_intr_mgt_stop().
> + * Both rewrite the hardware entry without a chip reset; nothing else
> + * collects it, so a stranded one just stays as it is, and nothing
> + * requests one.
> + *
> + * pci_clear_master() on a non-control PF cannot stop DMA using the
> + * management PF's BDF. It has not run yet on the control PF either,
> + * since nbl_remove() clears it after this function returns; what
> + * makes the only free - the one in nbl_intr_mgt_stop() - safe is
> + * that it runs after that point, with bus mastering off.
> + */
[Severity: Low]
Is "the only free" accurate here? The commit message makes the same
claim:
The coherent map table is different: neither per-function path frees
it, it is kept for the function's lifetime and reused in place, and
nbl_intr_mgt_stop() is the only place it is released.
nbl_res_intr_cfg_msix_map() is a per-function path. Its
release_vecs_unlock error label frees the table while the control PF is
still bus master:
if (!had_config && official_tbl->base_addr) {
dma_free_coherent(dev, official_tbl->size,
official_tbl->base_addr,
official_tbl->dma);
had_config is false on a first configuration. It is also false after a
destroy, because __nbl_res_intr_complete_destroy_msix_map() keeps
base_addr but resets the state:
func_res->state = NBL_INTR_FUNC_IDLE;
Suppose a sibling PF is configured again after an earlier destroy.
cfg_msix_map reuses the kept table, which the pcompleter has already
used. If a later vector allocation then fails with -EAGAIN, the error
path frees that table.
That contradicts the label's own comment ("release the DMA table
allocated during this call"). It also contradicts the keep-for-lifetime
rule documented in complete_destroy.
With the in-tree vector counts (one non-net vector per PF) the bitmap
pools can't run out, so the stop ordering added here is still safe
today.
Should the error path free the table only when this call allocated it?
Alternatively, should the commit message and this comment be adjusted?
> + ret = nbl_dev_destroy_msix_map(dev_mgt);
> + if (ret)
> + dev_err(dev_mgt->common->dev,
> + "Failed to destroy MSI-X map: %d\n", ret);
[Severity: Medium]
This patch doesn't change nbl_probe_chip_deps(), but with
nbl_core_start() a sibling PF now sends cfg_msix_map, get_vsi_id and
get_eth_id to func 0 from inside its own probe. The ordering that
nbl_probe_chip_deps() is meant to guarantee therefore matters more
now. Does it hold if func 0 is unbound while a sibling PF is probing?
In __device_release_driver(), device_links_busy() moves func 0's
links.status to DL_DEV_UNBINDING before device_remove() calls
nbl_remove(). Two things are only cleared after device_remove()
returns: mgt->dev.driver, by device_unbind_cleanup(), and
knode_driver, by klist_remove(). So for the whole of func 0's
nbl_core_stop() and nbl_core_remove(), the post-check in
nbl_probe_chip_deps() still passes:
if (READ_ONCE(mgt->dev.driver) != pdev->dev.driver ||
!device_is_bound(&mgt->dev)) {
In that window, device_link_add() sees the supplier in
DL_DEV_UNBINDING and creates the link in DL_STATE_SUPPLIER_UNBIND.
nbl_probe_chip_deps() returns 0 anyway. The sibling then runs
nbl_core_init() and nbl_dev_start() against a control PF that is
disabling its mailbox and heading into nbl_intr_mgt_stop().
device_links_unbind_consumers() has already run on func 0, so nothing
unbinds the sibling afterwards. If the sibling's probe does complete,
device_links_driver_bound() hits its
WARN_ON(link->status != DL_STATE_CONSUMER_PROBE).
The other outcome of the race is also wrong. If func 0 has finished
nbl_remove() by the time of the post-check, the check fires and calls
device_link_del() on a link created with DL_FLAG_AUTOPROBE_CONSUMER.
That is a managed link, and the consumer is registered, so
device_link_put_kref() takes its "Unable to drop a managed device
link reference" WARN branch and leaves the link in place.
Triggering this needs root to unbind func 0 while a sibling probes.
The window is all of nbl_remove(), though, which sleeps during the
mailbox and interrupt teardown.
Could nbl_probe_chip_deps() check link->status on the link it just
added, and defer unless it is DL_STATE_CONSUMER_PROBE? A link in that
state makes device_links_busy() wait for the sibling's probe before
func 0 is unbound.
And should the defer path keep the managed link instead of calling
device_link_del() on it? That would let the driver core reprobe the
sibling when func 0 binds again.
[Severity: Low]
This destroy RPC can fail, for example with a polling-mode -ETIMEDOUT.
The comment above says the sibling's entry then stays
NBL_INTR_FUNC_CONFIGURED until nbl_intr_mgt_stop() collects it.
Does that make the existing comment in nbl_res_remove_leonis()
inaccurate?
* 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.
After this patch, a sibling that unbound after a failed destroy still
has a valid map entry when nbl_res_remove_leonis() runs.
The code handles this, because nbl_intr_mgt_stop() walks every
CONFIGURED function. Could the leonis comment be updated so that a later
change doesn't drop that walk based on it?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112094925.6098-1-illusion.wang%40nebula-matrix.com
Re: [PATCH v34 net-next 0/8] nbl driver for Nebulamatrix NICs
Author: Jakub Kicinski
Date: Fri, 20 Nov 2026 00:42
Date: Fri, 20 Nov 2026 00:42
7 lines
7982 bytes
7982 bytes
On Thu, 12 Nov 2026 17:49:12 +0800 illusion.wang wrote: > This series continues and refines the previous v28 NBL NIC driver patch > set for Nebula-matrix m18110/m18000 (SNIC s1000) Ethernet adapters. Please wait for human review on v35. If you reach v40 we will ask you to go away with this driver..
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads