Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by "illusion.wang"
Thu, 19 Nov 2026 11:35
[PATCH v35 net-next 0/8] nbl driver for Nebulamatrix NICs
Author: "illusion.wang"
Date: Thu, 19 Nov 2026 11:35
Date: Thu, 19 Nov 2026 11:35
117 lines
13589 bytes
13589 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 v34->v35
Link to v34:https://lore.kernel.org/netdev/20261112094925.6098-1-illusion.wang@nebula-matrix.com/
1.AI review issues
2.Issue found by Leitao
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 | 1568 +++++++++++++++++
.../nbl/nbl_channel/nbl_channel.h | 196 +++
.../nebula-matrix/nbl/nbl_common/nbl_common.c | 51 +
.../nebula-matrix/nbl/nbl_common/nbl_common.h | 14 +
.../net/ethernet/nebula-matrix/nbl/nbl_core.h | 22 +
.../nebula-matrix/nbl/nbl_core/nbl_dev.c | 757 ++++++++
.../nebula-matrix/nbl/nbl_core/nbl_dev.h | 55 +
.../nebula-matrix/nbl/nbl_core/nbl_dispatch.c | 623 +++++++
.../nebula-matrix/nbl/nbl_core/nbl_dispatch.h | 23 +
.../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 +
.../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 +
.../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 1314 +++++++++++++-
.../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 342 ++++
.../nbl_hw_leonis/nbl_resource_leonis.c | 346 ++++
.../nbl_hw_leonis/nbl_resource_leonis.h | 12 +
.../nebula-matrix/nbl/nbl_hw/nbl_hw_reg.h | 33 +
.../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 859 +++++++++
.../nebula-matrix/nbl/nbl_hw/nbl_interrupt.h | 21 +
.../nebula-matrix/nbl/nbl_hw/nbl_resource.c | 157 ++
.../nebula-matrix/nbl/nbl_hw/nbl_resource.h | 158 ++
.../nbl/nbl_include/nbl_def_channel.h | 175 ++
.../nbl/nbl_include/nbl_def_common.h | 23 +
.../nbl/nbl_include/nbl_def_dev.h | 16 +
.../nbl/nbl_include/nbl_def_dispatch.h | 92 +
.../nbl/nbl_include/nbl_def_hw.h | 81 +
.../nbl/nbl_include/nbl_def_resource.h | 16 +
.../nbl/nbl_include/nbl_include.h | 28 +
.../net/ethernet/nebula-matrix/nbl/nbl_main.c | 306 +++-
29 files changed, 7318 insertions(+), 24 deletions(-)
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_common/nbl_common.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dev.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_core/nbl_dispatch.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_resource.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_channel.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dev.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_resource.h
--
2.51.0.windows.1
[PATCH v35 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Author: "illusion.wang"
Date: Thu, 19 Nov 2026 11:35
Date: Thu, 19 Nov 2026 11:35
1324 lines
59866 bytes
59866 bytes
From: illusion wang <illusion.wang@nebula-matrix.com>
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().
Signed-off-by: illusion wang <illusion.wang@nebula-matrix.com>
---
.../net/ethernet/nebula-matrix/nbl/Makefile | 1 +
.../nebula-matrix/nbl/nbl_hw/nbl_chip.c | 32 +
.../nebula-matrix/nbl/nbl_hw/nbl_chip.h | 12 +
.../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c | 787 ++++++++++++++++++
.../nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h | 242 ++++++
.../nbl_hw_leonis/nbl_resource_leonis.h | 1 +
.../nbl/nbl_include/nbl_def_hw.h | 3 +
.../nbl/nbl_include/nbl_include.h | 19 +
8 files changed, 1097 insertions(+)
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
create mode 100644 drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/Makefile b/drivers/net/ethernet/nebula-matrix/nbl/Makefile
index 5aec8e44f..be314b909 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/Makefile
+++ b/drivers/net/ethernet/nebula-matrix/nbl/Makefile
@@ -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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
new file mode 100644
index 000000000..419eb6392
--- /dev/null
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.c
@@ -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);
+}
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
new file mode 100644
index 000000000..d14093ba9
--- /dev/null
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_chip.h
@@ -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
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
index 1def2374c..76a561c7c 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
@@ -5,11 +5,36 @@
#include <linux/device.h>
#include <linux/pci.h>
#include <linux/bits.h>
+#include <linux/delay.h>
#include <linux/io.h>
#include <linux/spinlock.h>
#include <linux/bitfield.h>
#include "nbl_hw_leonis.h"
+/*
+ * Firmware cleanup after driver_status=false is asynchronous and the
+ * current hardware revision exposes no cleanup-complete status bit, so
+ * this delay is best-effort only: it gives the firmware pass time to
+ * settle before the caller returns, but cannot prove that it has.
+ * Bounding the wait keeps a later probe from re-programming the per-PF
+ * registers that pass reclaims (mailbox QINFO routing, qinfo registers)
+ * while firmware is realistically still wiping them. The chip-wide
+ * datapath registers init_module() writes are not part of that pass and
+ * stay programmed until chip reset. The hard teardown ordering comes
+ * from the device-link relationship between the sibling PFs and the
+ * control PF.
+ *
+ * These bounds are empirical, not derived from a documented firmware
+ * latency. There is nothing to poll for 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 firmware pass
+ * that takes longer than this window - an ECPU still busy right after
+ * kexec, say - can therefore still race a later probe.
+ */
+#define NBL_FW_CLEANUP_SYNC_MIN_US 2000
+#define NBL_FW_CLEANUP_SYNC_MAX_US 3000
+
static void nbl_hw_read_mbx_regs(struct nbl_hw_mgt *hw_mgt, u64 reg, u32 *data,
u32 len)
{
@@ -150,6 +175,756 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
*eth_map = FIELD_GET(NBL_FW_BOARD_DW6_ETH_BITMAP_MASK, data);
}
+static u32 nbl_hw_get_quirks(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 quirks = 0;
+
+ /*
+ * Read quirk bits from mailbox register.
+ * All supported firmware implement the quirk ABI,
+ * firmware always populates NBL_LEONIS_QUIRKS_OFFSET.
+ * Value ~0U indicates no active quirks.
+ *
+ * There is no firmware version field in this ABI to gate the read
+ * on: the quirk word itself is the capability advertisement. A
+ * word firmware never populated reads as zero (or is rejected by
+ * the mailbox-bar bounds check, leaving the zero initialiser), and
+ * zero selects the same sel=1 prefetch default as ~0U, which is
+ * what firmware predating the quirk needs.
+ */
+ nbl_hw_read_mbx_regs(hw_mgt, NBL_LEONIS_QUIRKS_OFFSET, &quirks,
+ sizeof(u32));
+
+ if (quirks == ~0u)
+ return 0;
+
+ return quirks;
+}
+
+static void nbl_configure_dped_checksum(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 data = 0;
+
+ /* DPED dped_l4_ck_cmd_40 for sctp */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DPED_L4_CK_CMD_40_ADDR, &data, sizeof(data));
+ data |= FIELD_PREP(NBL_DPED_L4_CK_CMD_40_EN_MASK, 1);
+ nbl_hw_wr_regs(hw_mgt, NBL_DPED_L4_CK_CMD_40_ADDR, &data, sizeof(data));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static void nbl_dped_init(struct nbl_hw_mgt *hw_mgt)
+{
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr32(hw_mgt, NBL_DPED_VLAN_OFFSET, 0xC);
+ nbl_hw_wr32(hw_mgt, NBL_DPED_DSCP_OFFSET_0, 0x8);
+ nbl_hw_wr32(hw_mgt, NBL_DPED_DSCP_OFFSET_1, 0x4);
+ spin_unlock(&hw_mgt->reg_lock);
+ /* dped checksum offload */
+ nbl_configure_dped_checksum(hw_mgt);
+}
+
+static void nbl_uped_init(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 hw_edit = 0;
+
+ /* V4 TCP: l3_len = 0 */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_UPED_HW_EDT_PROF_TABLE(NBL_UPED_V4_TCP_IDX),
+ &hw_edit, sizeof(hw_edit));
+ hw_edit &= ~NBL_PED_HW_EDIT_PROFILE_L3_LEN_MASK;
+ nbl_hw_wr_regs(hw_mgt, NBL_UPED_HW_EDT_PROF_TABLE(NBL_UPED_V4_TCP_IDX),
+ &hw_edit, sizeof(hw_edit));
+
+ /* V6 TCP: l3_len = 1 */
+ nbl_hw_rd_regs(hw_mgt, NBL_UPED_HW_EDT_PROF_TABLE(NBL_UPED_V6_TCP_IDX),
+ &hw_edit, sizeof(hw_edit));
+ hw_edit = (hw_edit & ~NBL_PED_HW_EDIT_PROFILE_L3_LEN_MASK) |
+ FIELD_PREP(NBL_PED_HW_EDIT_PROFILE_L3_LEN_MASK, 1);
+ nbl_hw_wr_regs(hw_mgt, NBL_UPED_HW_EDT_PROF_TABLE(NBL_UPED_V6_TCP_IDX),
+ &hw_edit, sizeof(hw_edit));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static int nbl_shaping_eth_init(struct nbl_hw_mgt *hw_mgt, u8 eth_id, u8 speed)
+{
+ struct nbl_shaping_dvn_dport_u dvn_dport = { 0 };
+ struct nbl_shaping_dport_u dport = { 0 };
+ u32 rate, half_rate;
+ u32 depth;
+ u64 low_val, high_val;
+
+ switch (speed) {
+ case NBL_FW_PORT_SPEED_100G:
+ rate = 100000;
+ break;
+ case NBL_FW_PORT_SPEED_50G:
+ rate = 50000;
+ break;
+ case NBL_FW_PORT_SPEED_25G:
+ rate = 25000;
+ break;
+ case NBL_FW_PORT_SPEED_10G:
+ rate = 10000;
+ break;
+ default:
+ dev_err(hw_mgt->common->dev,
+ "Unsupported port speed %u for eth%u\n", speed, eth_id);
+ return -EINVAL;
+ }
+
+ half_rate = rate / 2;
+ depth = max_t(u32, rate * 2, NBL_LR_LEONIS_NET_BUCKET_DEPTH);
+
+ /* 1. clear valid first
+ * dport and dvn_dport are zero-initialised above, so VALID=0 already
+ */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DPORT_REG(eth_id), dport.data,
+ sizeof(dport));
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DVN_DPORT_REG(eth_id),
+ dvn_dport.data, sizeof(dvn_dport));
+
+ /* 2. write config words (valid=0, safe) */
+ low_val = FIELD_PREP(NBL_DPORT_CIR_MASK, rate) |
+ FIELD_PREP(NBL_DPORT_PIR_MASK, rate) |
+ FIELD_PREP(NBL_DPORT_DEPTH_MASK, depth) |
+ FIELD_PREP(NBL_DPORT_CBS_MASK_LOW, depth & 0x3F);
+ high_val = FIELD_PREP(NBL_DPORT_CBS_MASK_HIGH, depth >> 6) |
+ FIELD_PREP(NBL_DPORT_PBS_MASK, depth);
+ /* Fixed split, independent of host endian */
+ dport.data[0] = lower_32_bits(low_val);
+ dport.data[1] = upper_32_bits(low_val);
+ dport.data[2] = lower_32_bits(high_val);
+ dport.data[3] = upper_32_bits(high_val);
+
+ low_val = FIELD_PREP(NBL_DPORT_CIR_MASK, half_rate) |
+ FIELD_PREP(NBL_DPORT_PIR_MASK, rate) |
+ FIELD_PREP(NBL_DPORT_DEPTH_MASK, depth) |
+ FIELD_PREP(NBL_DPORT_CBS_MASK_LOW, depth & 0x3F);
+ high_val = FIELD_PREP(NBL_DPORT_CBS_MASK_HIGH, depth >> 6) |
+ FIELD_PREP(NBL_DPORT_PBS_MASK, depth);
+ dvn_dport.data[0] = lower_32_bits(low_val);
+ dvn_dport.data[1] = upper_32_bits(low_val);
+ dvn_dport.data[2] = lower_32_bits(high_val);
+ dvn_dport.data[3] = upper_32_bits(high_val);
+
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DPORT_REG(eth_id), dport.data,
+ sizeof(dport));
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DVN_DPORT_REG(eth_id),
+ dvn_dport.data, sizeof(dvn_dport));
+
+ /* 3. commit: set valid last */
+ low_val = FIELD_PREP(NBL_DPORT_VALID_MASK, 1);
+ dport.data[0] |= lower_32_bits(low_val);
+
+ low_val = FIELD_PREP(NBL_DPORT_VALID_MASK, 1);
+ dvn_dport.data[0] |= lower_32_bits(low_val);
+
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DPORT_REG(eth_id), dport.data,
+ sizeof(dport));
+ nbl_hw_wr_regs(hw_mgt, NBL_SHAPING_DVN_DPORT_REG(eth_id),
+ dvn_dport.data, sizeof(dvn_dport));
+ spin_unlock(&hw_mgt->reg_lock);
+ return 0;
+}
+
+static int nbl_shaping_init(struct nbl_hw_mgt *hw_mgt, u8 speed)
+{
+ struct nbl_shaping_net_u net_shaping = { 0 };
+ u32 eth_bitmap = 0;
+ u32 reg_val;
+ int ret;
+ int i;
+
+ nbl_hw_get_fw_eth_map(hw_mgt, ð_bitmap);
+ for (i = 0; i < NBL_MAX_ETHERNET; i++) {
+ if (!(eth_bitmap & BIT(i)))
+ continue;
+ ret = nbl_shaping_eth_init(hw_mgt, i, speed);
+ if (ret)
+ return ret;
+ }
+ /*
+ * Read-modify-write as one critical section: reg_lock is dropped
+ * between the two _lock() helpers, which would let another writer
+ * of this register land in the middle of the update. Nothing
+ * else touches NBL_DSCH_PSHA_EN_ADDR today, but the RMW has to be
+ * atomic for that to stay true.
+ */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DSCH_PSHA_EN_ADDR, ®_val,
+ sizeof(reg_val));
+ reg_val &= ~NBL_DSCH_PSHA_EN_MASK;
+ reg_val |= FIELD_PREP(NBL_DSCH_PSHA_EN_MASK,
+ eth_bitmap & GENMASK(3, 0));
+ nbl_hw_wr_regs(hw_mgt, NBL_DSCH_PSHA_EN_ADDR, ®_val,
+ sizeof(reg_val));
+ spin_unlock(&hw_mgt->reg_lock);
+
+ for (i = 0; i < NBL_MAX_PF; i++) {
+ nbl_hw_wr_regs_lock(hw_mgt, NBL_SHAPING_NET_REG(i),
+ net_shaping.data,
+ sizeof(net_shaping));
+ }
+ nbl_flush_writes(hw_mgt);
+ return 0;
+}
+
+static void nbl_dsch_qid_max_init(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 quanta = 0;
+ u32 qid_max = 0;
+
+ quanta = FIELD_PREP(NBL_DSCH_VN_QUANTA_H_QUA_MASK, NBL_HOST_QUANTA) |
+ FIELD_PREP(NBL_DSCH_VN_QUANTA_E_QUA_MASK, NBL_ECPU_QUANTA);
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr_regs(hw_mgt, NBL_DSCH_VN_QUANTA_ADDR, &quanta,
+ sizeof(quanta));
+ nbl_hw_rd_regs(hw_mgt, NBL_DSCH_HOST_QID_MAX, &qid_max,
+ sizeof(qid_max));
+ qid_max &= ~NBL_DSCH_HOST_QID_MAX_MASK;
+ qid_max |= FIELD_PREP(NBL_DSCH_HOST_QID_MAX_MASK, NBL_MAX_QUEUE_ID);
+ nbl_hw_wr_regs(hw_mgt, NBL_DSCH_HOST_QID_MAX, &qid_max,
+ sizeof(qid_max));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static int nbl_ustore_init(struct nbl_hw_mgt *hw_mgt, u8 eth_num)
+{
+ u32 eth_bitmap = 0;
+ u32 drop_th = 0;
+ u32 pkt_len = 0;
+ u32 reg_val = 0;
+ int i;
+
+ /*
+ * eth_num is validated in the resource layer:
+ * nbl_res_init_pf_num() requires 1/2/4 PFs, and
+ * nbl_res_ctrl_dev_setup_eth_info() requires max_pf == eth_num.
+ * This is a defensive check only; if it triggers, the resource
+ * layer validation was bypassed, which is a bug.
+ */
+ if (WARN_ON(eth_num != 1 && eth_num != 2 && eth_num != 4))
+ return -EINVAL;
+ /* Read current packet length config
+ *(to preserve other fields while updating 'min')
+ */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_USTORE_PKT_LEN_ADDR, &pkt_len,
+ sizeof(pkt_len));
+ /* min arp packet length 42 (14 + 28) */
+ pkt_len &= ~NBL_USTORE_PKT_LEN_MIN_MASK;
+ pkt_len |= FIELD_PREP(NBL_USTORE_PKT_LEN_MIN_MASK, 42);
+ nbl_hw_wr_regs(hw_mgt, NBL_USTORE_PKT_LEN_ADDR, &pkt_len,
+ sizeof(pkt_len));
+
+ drop_th |= FIELD_PREP(NBL_USTORE_PORT_DROP_TH_EN_MASK, 1);
+ if (eth_num == 1)
+ drop_th |= FIELD_PREP(NBL_USTORE_PORT_DROP_TH_DISC_TH_MASK,
+ NBL_USTORE_SINGLE_ETH_DROP_TH);
+ else if (eth_num == 2)
+ drop_th |= FIELD_PREP(NBL_USTORE_PORT_DROP_TH_DISC_TH_MASK,
+ NBL_USTORE_DUAL_ETH_DROP_TH);
+ else
+ drop_th |= FIELD_PREP(NBL_USTORE_PORT_DROP_TH_DISC_TH_MASK,
+ NBL_USTORE_QUAD_ETH_DROP_TH);
+ nbl_hw_get_fw_eth_map(hw_mgt, ð_bitmap);
+ for (i = 0; i < NBL_MAX_ETHERNET; i++) {
+ if (!(eth_bitmap & BIT(i)))
+ continue;
+ nbl_hw_rd_regs(hw_mgt, NBL_USTORE_PORT_DROP_TH_REG_ARR(i),
+ ®_val, sizeof(reg_val));
+ reg_val &= ~(NBL_USTORE_PORT_DROP_TH_EN_MASK |
+ NBL_USTORE_PORT_DROP_TH_DISC_TH_MASK);
+ reg_val |= drop_th;
+ nbl_hw_wr_regs(hw_mgt, NBL_USTORE_PORT_DROP_TH_REG_ARR(i),
+ ®_val, sizeof(reg_val));
+ }
+
+ /* Clear port drop/truncate counters by reading them
+ * (hardware has read-to-clear behavior for these registers)
+ */
+ for (i = 0; i < NBL_MAX_ETHERNET; i++) {
+ if (!(eth_bitmap & BIT(i)))
+ continue;
+ nbl_hw_rd32(hw_mgt, NBL_USTORE_BUF_PORT_DROP_PKT(i));
+ nbl_hw_rd32(hw_mgt, NBL_USTORE_BUF_PORT_TRUN_PKT(i));
+ }
+ spin_unlock(&hw_mgt->reg_lock);
+ return 0;
+}
+
+static void nbl_dstore_init(struct nbl_hw_mgt *hw_mgt, u8 speed)
+{
+ u32 eth_bitmap = 0;
+ u32 drop_th = 0;
+ u32 fc_th = 0;
+ u32 bp_th = 0;
+ int i;
+
+ for (i = 0; i < NBL_DSTORE_PORT_DROP_TH_DEPTH; i++) {
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DSTORE_PORT_DROP_TH_REG(i), &drop_th,
+ sizeof(drop_th));
+ drop_th &= ~NBL_DSTORE_PORT_DROP_EN_MASK;
+ nbl_hw_wr_regs(hw_mgt, NBL_DSTORE_PORT_DROP_TH_REG(i), &drop_th,
+ sizeof(drop_th));
+ spin_unlock(&hw_mgt->reg_lock);
+ }
+
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DSTORE_DISC_BP_TH, &bp_th, sizeof(bp_th));
+ bp_th |= FIELD_PREP(NBL_DSTORE_DISC_BP_TH_EN_MASK, 1);
+ nbl_hw_wr_regs(hw_mgt, NBL_DSTORE_DISC_BP_TH, &bp_th, sizeof(bp_th));
+ spin_unlock(&hw_mgt->reg_lock);
+
+ nbl_hw_get_fw_eth_map(hw_mgt, ð_bitmap);
+ for (i = 0; i < NBL_MAX_ETHERNET; i++) {
+ if (!(eth_bitmap & BIT(i)))
+ continue;
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DSTORE_D_DPORT_FC_TH_REG(i), &fc_th,
+ sizeof(fc_th));
+ fc_th &= ~(NBL_DSTORE_D_DPORT_FC_XOFF_TH_MASK |
+ NBL_DSTORE_D_DPORT_FC_XON_TH_MASK);
+ if (speed == NBL_FW_PORT_SPEED_100G) {
+ fc_th |=
+ FIELD_PREP(NBL_DSTORE_D_DPORT_FC_XOFF_TH_MASK,
+ NBL_DSTORE_DROP_XOFF_TH_100G) |
+ FIELD_PREP(NBL_DSTORE_D_DPORT_FC_XON_TH_MASK,
+ NBL_DSTORE_DROP_XON_TH_100G);
+ } else {
+ fc_th |=
+ FIELD_PREP(NBL_DSTORE_D_DPORT_FC_XOFF_TH_MASK,
+ NBL_DSTORE_DROP_XOFF_TH) |
+ FIELD_PREP(NBL_DSTORE_D_DPORT_FC_XON_TH_MASK,
+ NBL_DSTORE_DROP_XON_TH);
+ }
+
+ fc_th |= FIELD_PREP(NBL_DSTORE_D_DPORT_FC_FC_EN_MASK, 1);
+ nbl_hw_wr_regs(hw_mgt, NBL_DSTORE_D_DPORT_FC_TH_REG(i), &fc_th,
+ sizeof(fc_th));
+ spin_unlock(&hw_mgt->reg_lock);
+ }
+}
+
+static void nbl_dvn_descreq_num_cfg(struct nbl_hw_mgt *hw_mgt, u8 descreq_num)
+{
+ u8 split_ring_num = (descreq_num >> 3) & 0x1;
+ u8 ring_num = descreq_num & 0x7;
+ u32 num_cfg;
+ u32 reg_val;
+
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_DVN_DESCREQ_NUM_CFG, ®_val,
+ sizeof(reg_val));
+
+ num_cfg = FIELD_PREP(NBL_DVN_DESCREQ_NUM_CFG_AVRING_DESREQ_NUM_CFG_MASK,
+ split_ring_num) |
+ FIELD_PREP(NBL_DVN_DESCREQ_NUM_CFG_PACKED_L1_NUM_MASK,
+ ring_num);
+ reg_val &= ~(NBL_DVN_DESCREQ_NUM_CFG_AVRING_DESREQ_NUM_CFG_MASK |
+ NBL_DVN_DESCREQ_NUM_CFG_PACKED_L1_NUM_MASK);
+ reg_val |= num_cfg;
+ nbl_hw_wr_regs(hw_mgt, NBL_DVN_DESCREQ_NUM_CFG, ®_val,
+ sizeof(reg_val));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+/*
+ * Relaxed ordering policy, shared by nbl_dvn_init() and nbl_uvn_init().
+ *
+ * NBL_DVN_DIF_REQ_RD_RO_FLAG and NBL_UVN_DIF_REQ_RO_FLAG are chip-wide DP
+ * registers, but the bits in them only allow the RO attribute on the DMA
+ * the block issues on behalf of a queue. Which function a given request
+ * belongs to is known to the datapath, not to these registers, so the
+ * per-requester DEVCTL En RO bit is still applied on top of them - PCIe
+ * requires it, a Function must not set the RO attribute while its own
+ * En RO bit is clear. A sibling PF that has RO disabled in its DEVCTL
+ * therefore keeps getting non-RO requests even though these bits are set
+ * chip-wide.
+ *
+ * That is also why the value is sampled from the control PF: it is the
+ * only function this probe can be sure about, and siblings only bind
+ * after func 0 has finished init_module().
+ *
+ * The bits are written once, here. A later DEVCTL change on any function
+ * - setpci, a guest taking the PF over through vfio-pci, an erratum
+ * workaround - is not picked up; the hardware gate above is what keeps
+ * such a change correct, not a re-read.
+ */
+static void nbl_dvn_init(struct nbl_hw_mgt *hw_mgt, u8 speed)
+{
+ u32 timeout = 0;
+ u32 ro_flag = 0;
+
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr32(hw_mgt, NBL_DVN_ECPU_QUEUE_NUM, 0);
+ spin_unlock(&hw_mgt->reg_lock);
+
+ timeout = FIELD_PREP(NBL_DVN_DESC_WR_MERGE_TIMEOUT_CFG_CYCLE_MASK,
+ DEFAULT_DVN_DESC_WR_MERGE_TIMEOUT_MAX);
+ nbl_hw_wr_regs_lock(hw_mgt, NBL_DVN_DESC_WR_MERGE_TIMEOUT, &timeout,
+ sizeof(timeout));
+ 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 {
+ 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));
+ }
+ nbl_hw_wr_regs(hw_mgt, NBL_DVN_DIF_REQ_RD_RO_FLAG, &ro_flag,
+ sizeof(ro_flag));
+ spin_unlock(&hw_mgt->reg_lock);
+ if (speed == NBL_FW_PORT_SPEED_100G)
+ nbl_dvn_descreq_num_cfg(hw_mgt,
+ DEFAULT_DVN_100G_DESCREQ_NUMCFG);
+ else
+ nbl_dvn_descreq_num_cfg(hw_mgt, DEFAULT_DVN_DESCREQ_NUMCFG);
+}
+
+static void nbl_uvn_init(struct nbl_hw_mgt *hw_mgt)
+{
+ u16 wr_timeout = NBL_UVN_DESC_WR_TIMEOUT_VAL;
+ u32 timeout = NBL_UVN_DESC_RD_WAIT_TICKS;
+ u32 prefetch_init = 0;
+ bool ro_enabled;
+ u32 flag = 0;
+ u32 mask = 0;
+ u32 quirks;
+ u32 reg_val;
+
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr32(hw_mgt, NBL_UVN_ECPU_QUEUE_NUM, 0);
+ nbl_hw_wr32(hw_mgt, NBL_UVN_DESC_RD_WAIT, timeout);
+ nbl_hw_rd_regs(hw_mgt, NBL_UVN_DESC_WR_TIMEOUT,
+ ®_val, sizeof(reg_val));
+ reg_val &= ~NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK;
+ reg_val |= FIELD_PREP(NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK, wr_timeout);
+ nbl_hw_wr_regs(hw_mgt, NBL_UVN_DESC_WR_TIMEOUT, ®_val,
+ sizeof(reg_val));
+ /* See the relaxed ordering policy above nbl_dvn_init() */
+ 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 {
+ 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) |
+ FIELD_PREP(NBL_UVN_DIF_REQ_RO_FLAG_DESC_WR_MASK, 1));
+ }
+ nbl_hw_wr_regs(hw_mgt, NBL_UVN_DIF_REQ_RO_FLAG, &flag, sizeof(flag));
+
+ nbl_hw_rd_regs(hw_mgt, NBL_UVN_QUEUE_ERR_MASK, &mask, sizeof(mask));
+ mask |= FIELD_PREP(NBL_UVN_QUEUE_ERR_MASK_DIF_ERR_MASK, 1);
+
+ nbl_hw_wr_regs(hw_mgt, NBL_UVN_QUEUE_ERR_MASK, &mask, sizeof(mask));
+
+ spin_unlock(&hw_mgt->reg_lock);
+ quirks = nbl_hw_get_quirks(hw_mgt);
+ /*
+ * sel=0: use configured num; sel=1: use internal calc (max 32)
+ * Default is sel=1, unless NBL_QUIRK_UVN_PREFETCH_ALIGN is set,
+ * in which case override to sel=0.
+ */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_rd_regs(hw_mgt, NBL_UVN_DESC_PREFETCH_INIT, ®_val,
+ sizeof(reg_val));
+ prefetch_init =
+ FIELD_PREP(NBL_UVN_DESC_PREFETCH_INIT_NUM_MASK,
+ NBL_UVN_DESC_PREFETCH_NUM) |
+ FIELD_PREP(NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK,
+ (quirks & NBL_QUIRK_UVN_PREFETCH_ALIGN) ? 0 : 1);
+ reg_val &= ~(NBL_UVN_DESC_PREFETCH_INIT_NUM_MASK |
+ NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK);
+ reg_val |= prefetch_init;
+ nbl_hw_wr_regs(hw_mgt, NBL_UVN_DESC_PREFETCH_INIT, ®_val,
+ sizeof(reg_val));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static void nbl_uqm_init(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 que_type = 0;
+ u32 cnt = 0;
+ int i;
+
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_FWD_DROP_CNT, &cnt, sizeof(cnt));
+
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_DROP_PKT_CNT, &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_DROP_PKT_SLICE_CNT, &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_DROP_PKT_LEN_ADD_CNT, &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_DROP_HEAD_PNTR_ADD_CNT, &cnt,
+ sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_DROP_WEIGHT_ADD_CNT, &cnt, sizeof(cnt));
+
+ for (i = 0; i < NBL_UQM_PORT_DROP_DEPTH; i++) {
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_PORT_DROP_PKT_CNT + (sizeof(cnt) * i),
+ &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_PORT_DROP_PKT_SLICE_CNT +
+ (sizeof(cnt) * i),
+ &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_PORT_DROP_PKT_LEN_ADD_CNT +
+ (sizeof(cnt) * i),
+ &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_PORT_DROP_HEAD_PNTR_ADD_CNT +
+ (sizeof(cnt) * i),
+ &cnt, sizeof(cnt));
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_PORT_DROP_WEIGHT_ADD_CNT +
+ (sizeof(cnt) * i),
+ &cnt, sizeof(cnt));
+ }
+
+ for (i = 0; i < NBL_UQM_DPORT_DROP_DEPTH; i++)
+ nbl_hw_wr_regs(hw_mgt,
+ NBL_UQM_DPORT_DROP_CNT + (sizeof(cnt) * i), &cnt,
+ sizeof(cnt));
+ /* bit0: 0=bp mode, 1=drop mode, resv bit1-31 */
+ nbl_hw_wr_regs(hw_mgt, NBL_UQM_QUE_TYPE, &que_type, sizeof(que_type));
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static int nbl_dp_init(struct nbl_hw_mgt *hw_mgt, u8 speed, u8 eth_num)
+{
+ int ret;
+
+ nbl_dped_init(hw_mgt);
+ nbl_uped_init(hw_mgt);
+ ret = nbl_shaping_init(hw_mgt, speed);
+ if (ret)
+ return ret;
+ nbl_dsch_qid_max_init(hw_mgt);
+ ret = nbl_ustore_init(hw_mgt, eth_num);
+ if (ret)
+ return ret;
+ nbl_dstore_init(hw_mgt, speed);
+ nbl_dvn_init(hw_mgt, speed);
+ nbl_uvn_init(hw_mgt);
+ nbl_uqm_init(hw_mgt);
+ return 0;
+}
+
+static void nbl_host_padpt_init(struct nbl_hw_mgt *hw_mgt)
+{
+ /* padpt flow control register */
+ spin_lock(&hw_mgt->reg_lock);
+ nbl_hw_wr32(hw_mgt, NBL_HOST_PADPT_HOST_CFG_FC_CPLH_UP,
+ NBL_HOST_PADPT_CFG_FC_CPLH_UP_VAL);
+ nbl_hw_wr32(hw_mgt, NBL_HOST_PADPT_HOST_CFG_FC_PD_DN,
+ NBL_HOST_PADPT_CFG_FC_PD_DN_VAL);
+ nbl_hw_wr32(hw_mgt, NBL_HOST_PADPT_HOST_CFG_FC_PH_DN,
+ NBL_HOST_PADPT_CFG_FC_PH_DN_VAL);
+ nbl_hw_wr32(hw_mgt, NBL_HOST_PADPT_HOST_CFG_FC_NPH_DN,
+ NBL_HOST_PADPT_CFG_FC_NPH_DN_VAL);
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+static void nbl_intf_init(struct nbl_hw_mgt *hw_mgt)
+{
+ nbl_host_padpt_init(hw_mgt);
+}
+
+/*
+ * Read-modify-write under reg_lock: NBL_DRIVER_STATUS_BIT is the only
+ * bit the driver owns, and the RMW writes back every other bit exactly
+ * as it read it, so firmware state in those bits survives.
+ *
+ * That only holds against concurrent CPU writers. reg_lock cannot
+ * serialise against firmware, and the register has no documented
+ * W1S/W1C form that would let the driver flip bit 16 without the
+ * read-modify-write; see NBL_DRIVER_STATUS_REG.
+ */
+static void nbl_hw_set_driver_status(struct nbl_hw_mgt *hw_mgt, bool active)
+{
+ u32 status;
+
+ spin_lock(&hw_mgt->reg_lock);
+ status = nbl_hw_rd32(hw_mgt, NBL_DRIVER_STATUS_REG);
+
+ status &= ~BIT(NBL_DRIVER_STATUS_BIT);
+ status |= FIELD_PREP(BIT(NBL_DRIVER_STATUS_BIT), active);
+
+ nbl_hw_wr32(hw_mgt, NBL_DRIVER_STATUS_REG, status);
+ spin_unlock(&hw_mgt->reg_lock);
+}
+
+/*
+ * Setting driver status to false notifies firmware to clean up per-PF
+ * hardware state such as qinfo registers.
+ *
+ * Note: firmware does NOT automatically revert chip-wide registers
+ * configured in this init flow. Those chip-wide settings remain valid
+ * until chip reset or explicitly overwritten by driver.
+ *
+ * This deinit_module only clears driver active status and flush writes.
+ * It does NOT reset or restore chip-wide datapath registers.
+ *
+ * Firmware cleanup is asynchronous with no completion status register.
+ * The flush only guarantees the status write reached the device; the
+ * bounded delay after it (NBL_FW_CLEANUP_SYNC_MIN_US) is best-effort and
+ * does not guarantee that the firmware pass has finished. The ordering
+ * this relies on is the device-link one: the siblings are consumers of
+ * the control PF, so they are unbound first, and that link is created
+ * with DL_FLAG_AUTOPROBE_CONSUMER. AUTOPROBE only re-probes consumers,
+ * never the control PF itself, so a later init_module() needs an admin
+ * (or a driver rebind) to bind this PF again, and only then does the
+ * core re-probe the siblings. Both steps are far slower than the
+ * firmware pass, but there is no hard firmware handshake.
+ *
+ * Caller must ensure no new DMA is initiated after this point.
+ * The mailbox channel is stopped by nbl_chan_teardown_queue()
+ * before this function is called, so no in-flight mailbox DMA
+ * remains.
+ */
+static void nbl_hw_deinit_module(struct nbl_hw_mgt *hw_mgt)
+{
+ nbl_hw_set_driver_status(hw_mgt, false);
+ /* ensure driver_status reaches the chip */
+ nbl_flush_writes(hw_mgt);
+ /*
+ * Give the asynchronous firmware cleanup pass time to settle
+ * before returning; best-effort, see NBL_FW_CLEANUP_SYNC_MIN_US.
+ */
+ usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US, NBL_FW_CLEANUP_SYNC_MAX_US);
+}
+
+static bool nbl_hw_eth_speed_valid(u8 speed)
+{
+ switch (speed) {
+ case NBL_FW_PORT_SPEED_10G:
+ case NBL_FW_PORT_SPEED_25G:
+ case NBL_FW_PORT_SPEED_50G:
+ case NBL_FW_PORT_SPEED_100G:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool nbl_hw_eth_num_valid(u8 eth_num)
+{
+ return eth_num == 1 || eth_num == 2 || eth_num == 4;
+}
+
+/*
+ * Clear a stale driver_status active bit before this probe programs any
+ * per-PF state.
+ *
+ * A previous kernel instance can leave the bit set (kexec, or an unload
+ * that never reached deinit_module()) and firmware then never ran the
+ * per-PF cleanup it drives off the 1 -> 0 transition. That cleanup
+ * reclaims the mailbox QINFO routing and the qinfo registers, which is
+ * exactly what nbl_dev_setup_chan_qinfo() and nbl_chan_setup_queue()
+ * write later in this probe.
+ *
+ * So the ordering this has to guarantee is: clear the bit before any of
+ * that per-PF state is programmed, and before the mailbox queue is live
+ * so the cleanup cannot reclaim routing under an in-flight transfer.
+ * Clearing it later - once nbl_dev_init() has programmed the routing and
+ * enabled the queue - wipes those registers and leaves the inter-PF
+ * mailbox dead, so sibling PFs' RPCs time out in nbl_dev_start() and
+ * their probes fail. That is why init_module() must not do it.
+ *
+ * Only the control PF owns this chip-wide handshake. The bounded wait
+ * after the clear is best-effort, see NBL_FW_CLEANUP_SYNC_MIN_US.
+ */
+static void nbl_hw_clear_stale_status(struct nbl_hw_mgt *hw_mgt)
+{
+ u32 status;
+
+ if (!hw_mgt->common->has_ctrl)
+ return;
+
+ /*
+ * Unlocked read: this runs only from the serialized control-PF probe,
+ * and the driver is the only writer of NBL_DRIVER_STATUS_BIT. A stale
+ * sample at worst causes one redundant clear plus sleep; the
+ * authoritative update happens under reg_lock in
+ * nbl_hw_set_driver_status().
+ *
+ * A clear bit takes the early return instead of another sleep: it
+ * means there is no cleanup pass of ours to wait for, either because
+ * firmware is idle or because the previous unbind's deinit_module()
+ * started the pass and already waited it out after the transition,
+ * before this PF could be probed again. Nothing here can poll for
+ * the end of the pass, so the unbind path is where the wait lives.
+ */
+ status = nbl_hw_rd32(hw_mgt, NBL_DRIVER_STATUS_REG);
+ if (!(status & BIT(NBL_DRIVER_STATUS_BIT)))
+ return;
+
+ dev_warn(hw_mgt->common->dev,
+ "driver_status already set, stale cleanup forced\n");
+ nbl_hw_set_driver_status(hw_mgt, false);
+ nbl_flush_writes(hw_mgt);
+ usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US, NBL_FW_CLEANUP_SYNC_MAX_US);
+}
+
+/*
+ * Firmware brings the chip up at power-up, but the chip-wide datapath
+ * registers this programs (SHAPING, DSCH, USTORE/DSTORE, DVN/UVN, UQM,
+ * PADPT) are not part of that: the driver owns them from here until chip
+ * reset, and firmware does not revert them when driver_status goes low -
+ * see nbl_hw_deinit_module().
+ *
+ * The driver_status handshake is entered from a known state: a stale
+ * active bit is cleared earlier, in nbl_hw_init_leonis(), before this
+ * probe programs any per-PF state. It must not be cleared here, because
+ * the mailbox QINFO routing and the mailbox queue registers are already
+ * programmed by then and the cleanup the 1 -> 0 transition starts would
+ * reclaim them; see nbl_hw_clear_stale_status().
+ */
+static int nbl_hw_init_module(struct nbl_hw_mgt *hw_mgt, u8 eth_speed,
+ u8 eth_num)
+{
+ int ret;
+
+ if (!nbl_hw_eth_speed_valid(eth_speed)) {
+ dev_err(hw_mgt->common->dev, "Invalid eth_speed %u\n",
+ eth_speed);
+ return -EINVAL;
+ }
+ if (!nbl_hw_eth_num_valid(eth_num)) {
+ dev_err(hw_mgt->common->dev, "Invalid eth_num %u\n", eth_num);
+ return -EINVAL;
+ }
+
+ ret = nbl_dp_init(hw_mgt, eth_speed, eth_num);
+ if (ret)
+ return ret;
+ nbl_intf_init(hw_mgt);
+ nbl_hw_set_driver_status(hw_mgt, true);
+ /* ensure registers written */
+ nbl_flush_writes(hw_mgt);
+
+ return 0;
+}
+
/*
* nbl_hw_set_mailbox_irq - read-modify-write NBL_MAILBOX_QINFO_MAP_REG_ARR
*
@@ -471,6 +1246,9 @@ static void nbl_hw_get_board_info(struct nbl_hw_mgt *hw_mgt,
}
static struct nbl_hw_ops hw_ops = {
+ .init_module = nbl_hw_init_module,
+ .deinit_module = nbl_hw_deinit_module,
+
.cfg_msix_map = nbl_hw_cfg_msix_map,
.cfg_msix_info = nbl_hw_cfg_msix_info,
.flush_write = nbl_flush_writes,
@@ -637,6 +1415,15 @@ int nbl_hw_init_leonis(struct nbl_adapter *adapter)
hw_mgt->mailbox_bar_size = bar_len;
spin_lock_init(&hw_mgt->reg_lock);
+ /*
+ * Clear a stale driver_status now, while this is the only register
+ * access this probe has done: the firmware cleanup the 1 -> 0
+ * transition starts reclaims the mailbox QINFO routing and qinfo
+ * registers that nbl_dev_init() programs later, so it must not be
+ * deferred to init_module(); see nbl_hw_clear_stale_status().
+ */
+ nbl_hw_clear_stale_status(hw_mgt);
+
hw_ops_tbl = nbl_hw_setup_ops(common, hw_mgt);
if (IS_ERR(hw_ops_tbl)) {
ret = PTR_ERR(hw_ops_tbl);
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
index b7c0a87c1..7d27ab198 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.h
@@ -11,12 +11,45 @@
#include "../../nbl_include/nbl_include.h"
#include "../nbl_hw_reg.h"
+/*
+ * Chip-wide driver-present handshake with firmware.
+ *
+ * NBL_DRIVER_STATUS_BIT is the only bit the driver owns: setting it tells
+ * firmware that a driver is bound, and the 1 -> 0 transition starts the
+ * firmware pass that reclaims per-PF state (mailbox QINFO routing, qinfo
+ * registers). Every other bit of this register belongs to firmware and
+ * the driver must leave it as it read it.
+ *
+ * Because the register is shared, bit 16 can only be changed with a
+ * read-modify-write: it has no documented W1S/W1C semantics that would
+ * let the driver set or clear that one bit atomically. reg_lock makes
+ * the read-modify-write atomic with respect to other CPU writers, but it
+ * cannot serialise against firmware, so a firmware update to another bit
+ * landing between the read and the write would be written back stale.
+ * No such firmware update is known to race the three driver callers
+ * (the probe-time clear, init_module() and deinit_module()), but that is
+ * an observation about this hardware revision, not a guarantee the
+ * driver can enforce.
+ */
+#define NBL_DRIVER_STATUS_REG 0x1300444
+#define NBL_DRIVER_STATUS_BIT 16
+
/* ---------- REG BASE ADDR ---------- */
/* Interface modules base addr */
#define NBL_INTF_HOST_PCOMPLETER_BASE 0x00f08000
#define NBL_INTF_HOST_PADPT_BASE 0x00f4c000
#define NBL_INTF_HOST_MAILBOX_BASE 0x00fb0000
#define NBL_INTF_HOST_PCIE_BASE 0X01504000
+/* DP modules base addr */
+#define NBL_DP_USTORE_BASE 0x00104000
+#define NBL_DP_UQM_BASE 0x00114000
+#define NBL_DP_UPED_BASE 0x0015c000
+#define NBL_DP_UVN_BASE 0x00244000
+#define NBL_DP_DSCH_BASE 0x00404000
+#define NBL_DP_SHAPING_BASE 0x00504000
+#define NBL_DP_DVN_BASE 0x00514000
+#define NBL_DP_DSTORE_BASE 0x00704000
+#define NBL_DP_DPED_BASE 0x0075c000
/* -------- MAILBOX BAR2 ----- */
#define NBL_MAILBOX_NOTIFY_ADDR 0x00000000
#define NBL_MAILBOX_QINFO_CFG_RX_TABLE_ADDR 0x10
@@ -56,6 +89,17 @@ struct nbl_mailbox_qinfo_cfg_table {
#define NBL_PCIE_BUS_MASK GENMASK(12, 5)
/* -------- HOST_PADPT -------- */
+#define NBL_HOST_PADPT_HOST_CFG_FC_PD_DN (NBL_INTF_HOST_PADPT_BASE + 0x00000160)
+#define NBL_HOST_PADPT_HOST_CFG_FC_PH_DN (NBL_INTF_HOST_PADPT_BASE + 0x00000164)
+#define NBL_HOST_PADPT_HOST_CFG_FC_NPH_DN \
+ (NBL_INTF_HOST_PADPT_BASE + 0x0000016C)
+#define NBL_HOST_PADPT_HOST_CFG_FC_CPLH_UP \
+ (NBL_INTF_HOST_PADPT_BASE + 0x00000170)
+
+#define NBL_HOST_PADPT_CFG_FC_CPLH_UP_VAL 0x10400
+#define NBL_HOST_PADPT_CFG_FC_PD_DN_VAL 0x10080
+#define NBL_HOST_PADPT_CFG_FC_PH_DN_VAL 0x10010
+#define NBL_HOST_PADPT_CFG_FC_NPH_DN_VAL 0x10010
/* host_padpt host_msix_info */
#define NBL_PADPT_HOST_MSIX_INFO_REG_ARR(vector_id) \
(NBL_INTF_HOST_PADPT_BASE + 0x00010000 + \
@@ -98,6 +142,203 @@ struct nbl_function_msix_map {
u32 data[NBL_FUNC_MSIX_MAP_DWLEN];
};
+/* ---------- DPED ---------- */
+#define NBL_DPED_VLAN_OFFSET (NBL_DP_DPED_BASE + 0x000003F4)
+#define NBL_DPED_DSCP_OFFSET_0 (NBL_DP_DPED_BASE + 0x000003F8)
+#define NBL_DPED_DSCP_OFFSET_1 (NBL_DP_DPED_BASE + 0x000003FC)
+/* DPED hw_edt_prof/ UPED hw_edt_prof */
+
+#define NBL_DPED_L4_CK_CMD_40_ADDR (NBL_DP_DPED_BASE + 0x00000338)
+
+#define NBL_DPED_L4_CK_CMD_40_EN_MASK BIT(31)
+
+/* ---------- UPED ---------- */
+/* UPED uped_hw_edt_prof */
+#define NBL_UPED_HW_EDT_PROF_TABLE(i) \
+ (NBL_DP_UPED_BASE + 0x00001000 + (i) * sizeof(u32))
+#define NBL_UPED_V4_TCP_IDX 5
+#define NBL_UPED_V6_TCP_IDX 6
+#define NBL_PED_HW_EDIT_PROFILE_L3_LEN_MASK GENMASK(3, 2)
+
+/* ---------- DSCH ---------- */
+#define NBL_DSCH_PSHA_EN_MASK GENMASK(3, 0)
+/* DSCH dsch maxqid */
+#define NBL_DSCH_HOST_QID_MAX (NBL_DP_DSCH_BASE + 0x00000118)
+#define NBL_DSCH_HOST_QID_MAX_MASK GENMASK(10, 0)
+#define NBL_DSCH_VN_QUANTA_ADDR (NBL_DP_DSCH_BASE + 0x00000134)
+
+#define NBL_MAX_QUEUE_ID 0x7ff
+#define NBL_HOST_QUANTA 0x8000
+#define NBL_ECPU_QUANTA 0x1000
+
+#define NBL_DSCH_VN_QUANTA_H_QUA_MASK GENMASK(15, 0)
+#define NBL_DSCH_VN_QUANTA_E_QUA_MASK GENMASK(31, 16)
+
+/* ---------- DVN ---------- */
+/* DVN dvn_queue_table */
+#define NBL_DVN_ECPU_QUEUE_NUM (NBL_DP_DVN_BASE + 0x0000041C)
+#define NBL_DVN_DESCREQ_NUM_CFG (NBL_DP_DVN_BASE + 0x00000430)
+#define NBL_DVN_DESC_WR_MERGE_TIMEOUT (NBL_DP_DVN_BASE + 0x00000480)
+#define NBL_DVN_DIF_REQ_RD_RO_FLAG (NBL_DP_DVN_BASE + 0x0000045C)
+
+#define DEFAULT_DVN_DESCREQ_NUMCFG 0x03
+#define DEFAULT_DVN_100G_DESCREQ_NUMCFG 0x07
+
+#define DEFAULT_DVN_DESC_WR_MERGE_TIMEOUT_MAX 0x3FF
+
+/* spilit ring descreq_num 0:8,1:16 */
+#define NBL_DVN_DESCREQ_NUM_CFG_AVRING_DESREQ_NUM_CFG_MASK BIT(0)
+/* packet ring descreq_num
+ * 0:8,1:12,2:16;3:20,4:24,5:26;6:32,7:32
+ */
+#define NBL_DVN_DESCREQ_NUM_CFG_PACKED_L1_NUM_MASK GENMASK(6, 4)
+
+#define NBL_DVN_DESC_WR_MERGE_TIMEOUT_CFG_CYCLE_MASK GENMASK(9, 0)
+
+#define NBL_DVN_DIF_REQ_RD_RO_FLAG_DESC_RO_EN_MASK BIT(0)
+#define NBL_DVN_DIF_REQ_RD_RO_FLAG_DATA_RO_EN_MASK BIT(1)
+#define NBL_DVN_DIF_REQ_RD_RO_FLAG_AVRING_RO_EN_MASK BIT(2)
+
+/* ---------- UVN ---------- */
+/* UVN uvn_queue_table */
+
+#define NBL_UVN_DESC_RD_WAIT (NBL_DP_UVN_BASE + 0x0000020C)
+#define NBL_UVN_QUEUE_ERR_MASK (NBL_DP_UVN_BASE + 0x00000224)
+#define NBL_UVN_ECPU_QUEUE_NUM (NBL_DP_UVN_BASE + 0x0000023C)
+#define NBL_UVN_DESC_WR_TIMEOUT (NBL_DP_UVN_BASE + 0x00000214)
+#define NBL_UVN_DIF_REQ_RO_FLAG (NBL_DP_UVN_BASE + 0x00000250)
+#define NBL_UVN_DESC_PREFETCH_INIT (NBL_DP_UVN_BASE + 0x00000204)
+#define NBL_UVN_DESC_PREFETCH_NUM 4
+
+#define NBL_UVN_DIF_REQ_RO_FLAG_AVAIL_RD_MASK BIT(0)
+#define NBL_UVN_DIF_REQ_RO_FLAG_DESC_RD_MASK BIT(1)
+#define NBL_UVN_DIF_REQ_RO_FLAG_PKT_WR_MASK BIT(2)
+#define NBL_UVN_DIF_REQ_RO_FLAG_DESC_WR_MASK BIT(3)
+
+#define NBL_UVN_DESC_WR_TIMEOUT_NUM_MASK GENMASK(14, 0)
+
+#define NBL_UVN_QUEUE_ERR_MASK_DIF_ERR_MASK BIT(5)
+
+#define NBL_UVN_DESC_PREFETCH_INIT_NUM_MASK GENMASK(7, 0)
+#define NBL_UVN_DESC_PREFETCH_INIT_SEL_MASK BIT(16)
+
+#define NBL_UVN_DESC_WR_TIMEOUT_VAL 0x12c
+/* 200us = 200000ns / 1.67ns per tick = 119760 ticks */
+#define NBL_UVN_DESC_RD_WAIT_TICKS 119760
+
+/* -------- USTORE -------- */
+#define NBL_USTORE_PKT_LEN_ADDR (NBL_DP_USTORE_BASE + 0x00000108)
+#define NBL_USTORE_PORT_DROP_TH_REG_ARR(port_id) \
+ (NBL_DP_USTORE_BASE + 0x00000150 + (port_id) * sizeof(u32))
+#define NBL_USTORE_BUF_PORT_DROP_PKT(eth_id) \
+ (NBL_DP_USTORE_BASE + 0x00002500 + (eth_id) * sizeof(u32))
+#define NBL_USTORE_BUF_PORT_TRUN_PKT(eth_id) \
+ (NBL_DP_USTORE_BASE + 0x00002540 + (eth_id) * sizeof(u32))
+
+#define NBL_USTORE_SINGLE_ETH_DROP_TH 0xC80
+#define NBL_USTORE_DUAL_ETH_DROP_TH 0x640
+#define NBL_USTORE_QUAD_ETH_DROP_TH 0x320
+
+/* USTORE pkt_len */
+#define NBL_USTORE_PKT_LEN_MIN_MASK GENMASK(6, 0)
+
+/* USTORE port_drop_th */
+#define NBL_USTORE_PORT_DROP_TH_DISC_TH_MASK GENMASK(11, 0)
+#define NBL_USTORE_PORT_DROP_TH_EN_MASK BIT(31)
+
+/* UQM*/
+#define NBL_UQM_QUE_TYPE (NBL_DP_UQM_BASE + 0x0000013c)
+#define NBL_UQM_DROP_PKT_CNT (NBL_DP_UQM_BASE + 0x000009C0)
+#define NBL_UQM_DROP_PKT_SLICE_CNT (NBL_DP_UQM_BASE + 0x000009C4)
+#define NBL_UQM_DROP_PKT_LEN_ADD_CNT (NBL_DP_UQM_BASE + 0x000009C8)
+#define NBL_UQM_DROP_HEAD_PNTR_ADD_CNT (NBL_DP_UQM_BASE + 0x000009CC)
+#define NBL_UQM_DROP_WEIGHT_ADD_CNT (NBL_DP_UQM_BASE + 0x000009D0)
+#define NBL_UQM_PORT_DROP_PKT_CNT (NBL_DP_UQM_BASE + 0x000009D4)
+#define NBL_UQM_PORT_DROP_PKT_SLICE_CNT (NBL_DP_UQM_BASE + 0x000009F4)
+#define NBL_UQM_PORT_DROP_PKT_LEN_ADD_CNT (NBL_DP_UQM_BASE + 0x00000A14)
+#define NBL_UQM_PORT_DROP_HEAD_PNTR_ADD_CNT (NBL_DP_UQM_BASE + 0x00000A34)
+#define NBL_UQM_PORT_DROP_WEIGHT_ADD_CNT (NBL_DP_UQM_BASE + 0x00000A54)
+#define NBL_UQM_FWD_DROP_CNT (NBL_DP_UQM_BASE + 0x00000A80)
+#define NBL_UQM_DPORT_DROP_CNT (NBL_DP_UQM_BASE + 0x00000B74)
+
+#define NBL_UQM_PORT_DROP_DEPTH 6
+#define NBL_UQM_DPORT_DROP_DEPTH 16
+
+/* --------- SHAPING --------- */
+
+/* Shaping rate unit: 1 = 1 Mbit/s.
+ * e.g. 100000 = 100 Gbit/s, 25000 = 25 Gbit/s.
+ */
+#define NBL_LR_LEONIS_NET_BUCKET_DEPTH 9600
+#define NBL_SHAPING_DPORT_ADDR (NBL_DP_SHAPING_BASE + 0x700)
+#define NBL_SHAPING_DPORT_DWLEN 4
+#define NBL_SHAPING_DPORT_REG(r) \
+ (NBL_SHAPING_DPORT_ADDR + (NBL_SHAPING_DPORT_DWLEN * 4) * (r))
+#define NBL_SHAPING_DVN_DPORT_ADDR (NBL_DP_SHAPING_BASE + 0x750)
+#define NBL_SHAPING_DVN_DPORT_DWLEN 4
+#define NBL_SHAPING_DVN_DPORT_REG(r) \
+ (NBL_SHAPING_DVN_DPORT_ADDR + (NBL_SHAPING_DVN_DPORT_DWLEN * 4) * (r))
+#define NBL_DSCH_PSHA_EN_ADDR (NBL_DP_DSCH_BASE + 0x00000314)
+#define NBL_SHAPING_NET_ADDR (NBL_DP_SHAPING_BASE + 0x1800)
+#define NBL_SHAPING_NET_DWLEN 4
+#define NBL_SHAPING_NET_REG(r) \
+ (NBL_SHAPING_NET_ADDR + (NBL_SHAPING_NET_DWLEN * 4) * (r))
+
+#define NBL_DPORT_VALID_MASK GENMASK_ULL(0, 0)
+#define NBL_DPORT_DEPTH_MASK GENMASK_ULL(19, 1)
+#define NBL_DPORT_CIR_MASK GENMASK_ULL(38, 20)
+#define NBL_DPORT_PIR_MASK GENMASK_ULL(57, 39)
+#define NBL_DPORT_CBS_MASK_LOW GENMASK_ULL(63, 58)
+#define NBL_DPORT_CBS_MASK_HIGH GENMASK_ULL(14, 0)
+#define NBL_DPORT_PBS_MASK GENMASK_ULL(35, 15)
+
+/* SHAPING shaping_net */
+struct nbl_shaping_net_u {
+ u32 data[NBL_SHAPING_NET_DWLEN];
+};
+
+struct nbl_shaping_dport_u {
+ u32 data[NBL_SHAPING_DPORT_DWLEN];
+};
+
+struct nbl_shaping_dvn_dport_u {
+ u32 data[NBL_SHAPING_DVN_DPORT_DWLEN];
+};
+
+/* -------- DSTORE -------- */
+#define NBL_DSTORE_D_DPORT_FC_TH_ADDR (NBL_DP_DSTORE_BASE + 0x00000600)
+#define NBL_DSTORE_D_DPORT_FC_TH_DEPTH 5
+#define NBL_DSTORE_D_DPORT_FC_TH_WIDTH 32
+#define NBL_DSTORE_D_DPORT_FC_TH_DWLEN 1
+
+#define NBL_DSTORE_D_DPORT_FC_XOFF_TH_MASK GENMASK(10, 0)
+#define NBL_DSTORE_D_DPORT_FC_XON_TH_MASK GENMASK(26, 16)
+#define NBL_DSTORE_D_DPORT_FC_FC_EN_MASK BIT(31)
+
+#define NBL_DSTORE_D_DPORT_FC_TH_REG(r) \
+ (NBL_DSTORE_D_DPORT_FC_TH_ADDR + \
+ (NBL_DSTORE_D_DPORT_FC_TH_DWLEN * 4) * (r))
+#define NBL_DSTORE_PORT_DROP_TH_ADDR (NBL_DP_DSTORE_BASE + 0x00000150)
+#define NBL_DSTORE_PORT_DROP_TH_DEPTH 6
+#define NBL_DSTORE_PORT_DROP_TH_WIDTH 32
+#define NBL_DSTORE_PORT_DROP_TH_DWLEN 1
+
+#define NBL_DSTORE_PORT_DROP_EN_MASK BIT(31)
+
+#define NBL_DSTORE_DROP_XOFF_TH 0xC8
+#define NBL_DSTORE_DROP_XON_TH 0x64
+
+#define NBL_DSTORE_DROP_XOFF_TH_100G 0x1F4
+#define NBL_DSTORE_DROP_XON_TH_100G 0x12C
+
+#define NBL_DSTORE_DISC_BP_TH (NBL_DP_DSTORE_BASE + 0x00000630)
+
+#define NBL_DSTORE_DISC_BP_TH_EN_MASK BIT(31)
+
+#define NBL_DSTORE_PORT_DROP_TH_REG(r) \
+ (NBL_DSTORE_PORT_DROP_TH_ADDR + \
+ (NBL_DSTORE_PORT_DROP_TH_DWLEN * 4) * (r))
+
#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)
@@ -111,5 +352,6 @@ struct nbl_function_msix_map {
#define NBL_FW_BOARD_DW6_LANE_BITMAP_MASK GENMASK(7, 0)
#define NBL_FW_BOARD_DW6_ETH_BITMAP_MASK GENMASK(15, 8)
+#define NBL_LEONIS_QUIRKS_OFFSET 0x00000140
#define NBL_BAR2_MAX_LEN 0x300
#endif
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
index 6eb4dc9e6..f1cb0f232 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.h
@@ -8,4 +8,5 @@
#include "../nbl_resource.h"
#include "../nbl_interrupt.h"
+#include "../nbl_chip.h"
#endif
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
index 72e469b67..f8c97e266 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
@@ -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);
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h
index 59e44feab..efc4c79a0 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_include.h
@@ -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
--
2.51.0.windows.1
[PATCH v35 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Author: "illusion.wang"
Date: Thu, 19 Nov 2026 11:35
Date: Thu, 19 Nov 2026 11:35
733 lines
38724 bytes
38724 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: it is kept for the function's lifetime and
reused in place, and nbl_intr_mgt_stop() is the only place a table the
pcompleter has been given is released - the rollback inside
nbl_res_intr_cfg_msix_map() only frees a table that the same call
allocated, before its map entry is armed.
That is also what keeps the stop ordering safe. nbl_remove() calls
nbl_core_stop() before pci_clear_master(), so the control PF destroys
its own map entry while its Bus Master Enable is still set. That is
deliberate: nbl_core_stop() cannot run after pci_clear_master(), because
on a non-control PF it is a mailbox RPC, which needs bus mastering for
the ring DMA. The destroy only clears the VALID bit and keeps the
coherent table, so the actual free still happens later, in
nbl_intr_mgt_stop(), after pci_clear_master(). nbl_probe()'s
start-failure unwind uses the same order. pci_clear_master() remains no
safety net for a non-control PF: it cannot stop DMA issued with the
management PF's BDF.
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 | 454 +++++++++++++++++-
.../nebula-matrix/nbl/nbl_hw/nbl_interrupt.c | 4 +-
.../nbl/nbl_include/nbl_def_dev.h | 2 +
.../net/ethernet/nebula-matrix/nbl/nbl_main.c | 49 +-
5 files changed, 512 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
index 4f3bc1f08..ff55d0015 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_core.h
@@ -39,4 +39,15 @@ struct nbl_adapter *nbl_core_init(struct pci_dev *pdev,
struct nbl_init_param *param);
void nbl_core_remove(struct nbl_adapter *adapter);
+/*
+ * Single-shot start/stop pair, called once each from PCI probe/remove.
+ * Not repeatable, but not because the MSI-X core would refuse a second
+ * start: nbl_dev_stop() releases the vectors with pci_free_irq_vectors().
+ * What the pair brackets is the device's active lifetime, and
+ * nbl_core_stop() is only ever followed by nbl_core_remove(), which
+ * destroys the mailbox channel and the resource state that start needs.
+ */
+int nbl_core_start(struct nbl_adapter *adapter);
+void nbl_core_stop(struct nbl_adapter *adapter);
+
#endif
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 b20747d47..de6a30996 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,247 @@ 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.
+ *
+ * No handler is registered when this runs. nbl_dev_stop() frees the
+ * mailbox IRQ before calling it, and on the nbl_dev_start() error path
+ * every exit that lands on err_destroy_map happens before request_irq()
+ * succeeded - including the failure of the request itself - while the
+ * only failure after the handler was installed, enable, goes through
+ * err_free_irq, which frees it 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 +338,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work)
NBL_CHAN_TYPE_MAILBOX);
}
+static void nbl_dev_clean_mailbox_schedule(struct nbl_dev_mgt *dev_mgt)
+{
+ struct nbl_dev_common *common_dev = dev_mgt->common_dev;
+ struct nbl_common_info *common = dev_mgt->common;
+
+ queue_work(common->wq, &common_dev->clean_mbx_task);
+}
+
/* ---------- Dev init process ---------- */
static int nbl_dev_setup_common_dev(struct nbl_adapter *adapter)
{
@@ -260,15 +520,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
@@ -277,9 +538,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;
}
@@ -309,3 +569,189 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
if (common->has_ctrl)
nbl_dev_remove_ctrl_dev(adapter);
}
+
+/* ---------- Dev start process ---------- */
+int nbl_dev_start(struct nbl_adapter *adapter)
+{
+ 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 the only release of a table the
+ * pcompleter has been given is the one in nbl_intr_mgt_stop(). The
+ * rollback inside nbl_res_intr_cfg_msix_map() frees a table only
+ * when that same call allocated it, i.e. before its map entry is
+ * armed, so it never releases memory the device has fetched from.
+ * 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 that release 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_hw/nbl_interrupt.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
index 9e5376d21..3d0e0a1e4 100644
--- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
+++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_interrupt.c
@@ -359,8 +359,8 @@ int nbl_res_intr_destroy_msix_map(struct nbl_resource_mgt *res_mgt,
* configuration intact). The bitmap pools are therefore sized for peak,
* not maximum, concurrent use: a reconfigure of the same or a smaller
* size still fails with -EAGAIN when the pool is nearly exhausted. The
- * in-tree caller asks for one non-net vector per PF, far below
- * NBL_MAX_OTHER_INTERRUPT.
+ * in-tree caller (nbl_dev_cfg_msix_map(), from nbl_dev_start()) asks for
+ * one non-net vector per PF, far below NBL_MAX_OTHER_INTERRUPT.
*
* Serialization: this function takes intr_mgt->lock internally to
* protect the global vector bitmaps and per-function state against
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 454e76184..3957c67e3 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)
{
@@ -272,6 +282,27 @@ static int nbl_probe(struct pci_dev *pdev,
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;
+ }
+
/*
* Resolve the chip-wide dependency before the device is enabled or
* bus mastering is turned on: a sibling PF waiting for its
@@ -321,8 +352,16 @@ static int nbl_probe(struct pci_dev *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)
@@ -333,6 +372,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.
@@ -345,6 +385,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 v35 net-next 4/8] net/nebula-matrix: add chip-wide hardware init/deinit implementation
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 12:52
Date: Mon, 23 Nov 2026 12:52
215 lines
16419 bytes
16419 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] When nbl_hw_clear_stale_status() finds bit 16 of
NBL_DRIVER_STATUS_REG already set (after kexec, or after a previous…
- [Low] The commit message says: "The two hooks are only checked for non-
NULL by nbl_hw_setup_ops() and nbl_res_setup_ops() at this point".
- [Low] The comment in nbl_hw_get_quirks() describes a fallback that can
never run, and it contradicts itself.
- [Low] The WARN_ON(eth_num != 1 && eth_num != 2 && eth_num != 4) in
nbl_ustore_init() can never fire, so its comment is wrong to say it…
--
net/nebula-matrix: add chip-wide hardware init/deinit implementation
This adds the Leonis chip-wide init_module() and deinit_module() hooks in
the hw and resource layers. On the control PF they program the DPED, UPED,
SHAPING, DSCH, USTORE, DSTORE, DVN, UVN, UQM and PADPT datapath registers.
The commit also adds a firmware quirk word read at mailbox offset 0x140,
and a probe-time clear of a stale driver_status bit before any per-PF
state is programmed.
> 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().
[Severity: Low]
Is this description accurate? nbl_hw_setup_ops() in nbl_hw_leonis.c only
allocates the table and assigns the pointers:
hw_ops_tbl = devm_kzalloc(dev, sizeof(*hw_ops_tbl), GFP_KERNEL);
if (!hw_ops_tbl)
return ERR_PTR(-ENOMEM);
hw_ops_tbl->ops = &hw_ops;
hw_ops_tbl->priv = hw_mgt;
It never checks ops->init_module or ops->deinit_module.
nbl_res_setup_ops() doesn't appear to exist anywhere under
drivers/net/ethernet/nebula-matrix/, either at this commit or at the end
of the series.
The rest of the paragraph holds up. "net/nebula-matrix: dispatch: add
control-level routing core infrastructure" wires
nbl_disp_init_module()/nbl_disp_deinit_module() to nbl_res_chip_*().
"net/nebula-matrix: add common/ctrl dev init/remove operation" adds the
calls from nbl_dev_setup_ctrl_dev()/nbl_dev_remove_ctrl_dev().
The nbl_hw_deinit_module() precondition also holds by the end of the
series, because nbl_dev_remove() calls nbl_dev_remove_common_dev() before
nbl_dev_remove_ctrl_dev().
Could the NULL-check sentence be corrected?
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> index f7cdb0fecf442..dafac13916739 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
[ ... ]
> @@ -150,6 +175,756 @@ static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
> *eth_map = FIELD_GET(NBL_FW_BOARD_DW6_ETH_BITMAP_MASK, data);
> }
>
> +static u32 nbl_hw_get_quirks(struct nbl_hw_mgt *hw_mgt)
> +{
> + u32 quirks = 0;
> +
> + /*
> + * Read quirk bits from mailbox register.
> + * All supported firmware implement the quirk ABI,
> + * firmware always populates NBL_LEONIS_QUIRKS_OFFSET.
> + * Value ~0U indicates no active quirks.
> + *
> + * There is no firmware version field in this ABI to gate the read
> + * on: the quirk word itself is the capability advertisement. A
> + * word firmware never populated reads as zero (or is rejected by
> + * the mailbox-bar bounds check, leaving the zero initialiser), and
> + * zero selects the same sel=1 prefetch default as ~0U, which is
> + * what firmware predating the quirk needs.
> + */
> + nbl_hw_read_mbx_regs(hw_mgt, NBL_LEONIS_QUIRKS_OFFSET, &quirks,
> + sizeof(u32));
[Severity: Low]
Can the bounds-check fallback in this comment ever run? nbl_hw_init_leonis()
fails probe when the mailbox BAR is shorter than NBL_BAR2_MAX_LEN (0x300),
and then sets mailbox_bar_size = bar_len:
if (bar_len < NBL_BAR2_MAX_LEN) {
dev_err(&pdev->dev, "MAILBOX BAR length %pa too small\n",
&bar_len);
ret = -EINVAL;
return ret;
}
This read covers 0x140..0x143, so the reg + len > mailbox_bar_size check
in nbl_hw_read_mbx_regs() can't reject it.
The comment also contradicts itself. It first says all supported firmware
always populates the word, then relies on firmware predating the quirk
leaving it as zero. Which one is intended?
The ABI note for NBL_QUIRK_UVN_PREFETCH_ALIGN in nbl_include.h defines only
~0U and BIT(1). It doesn't say that 0 means no quirks, so older firmware
works only if mailbox offset 0x140 reads as zero.
If such firmware leaves BIT(1) set at that offset, would UVN prefetch
silently switch to sel=0?
[ ... ]
> +static int nbl_ustore_init(struct nbl_hw_mgt *hw_mgt, u8 eth_num)
> +{
> + u32 eth_bitmap = 0;
> + u32 drop_th = 0;
> + u32 pkt_len = 0;
> + u32 reg_val = 0;
> + int i;
> +
> + /*
> + * eth_num is validated in the resource layer:
> + * nbl_res_init_pf_num() requires 1/2/4 PFs, and
> + * nbl_res_ctrl_dev_setup_eth_info() requires max_pf == eth_num.
> + * This is a defensive check only; if it triggers, the resource
> + * layer validation was bypassed, which is a bug.
> + */
> + if (WARN_ON(eth_num != 1 && eth_num != 2 && eth_num != 4))
> + return -EINVAL;
[Severity: Low]
Can this WARN_ON() ever fire? nbl_ustore_init() is static and is only
reached through nbl_hw_init_module()->nbl_dp_init(). nbl_hw_init_module()
already rejects the same values before it calls nbl_dp_init():
if (!nbl_hw_eth_num_valid(eth_num)) {
dev_err(hw_mgt->common->dev, "Invalid eth_num %u\n", eth_num);
return -EINVAL;
}
If the resource-layer validation were bypassed, that dev_err() path would
catch it first, so the warning this comment promises would never appear.
The same check now exists in three places, but the comment names only two.
Could the duplicate check be removed, or the comment updated?
[ ... ]
> +static void nbl_hw_clear_stale_status(struct nbl_hw_mgt *hw_mgt)
> +{
[ ... ]
> + status = nbl_hw_rd32(hw_mgt, NBL_DRIVER_STATUS_REG);
> + if (!(status & BIT(NBL_DRIVER_STATUS_BIT)))
> + return;
> +
> + dev_warn(hw_mgt->common->dev,
> + "driver_status already set, stale cleanup forced\n");
> + nbl_hw_set_driver_status(hw_mgt, false);
> + nbl_flush_writes(hw_mgt);
> + usleep_range(NBL_FW_CLEANUP_SYNC_MIN_US, NBL_FW_CLEANUP_SYNC_MAX_US);
> +}
[Severity: Medium]
What happens on this stale path if the firmware reclaim pass takes longer
than the 2-3 ms window? Probe goes on regardless:
nbl_hw_init_leonis()
nbl_hw_clear_stale_status()
usleep_range(2000, 3000)
nbl_core_init()
nbl_dev_init()
nbl_dev_setup_chan_qinfo()
mailbox queue setup
A pass that is still running could wipe the QINFO routing and qinfo
QUEUE_EN state this probe has just programmed. The control PF would report
no error. The inter-PF mailbox would stop working, though, and sibling PFs
would later fail with RPC timeouts in nbl_dev_start() until the control
PF is rebound.
The commit message names this case ("an ECPU still busy right after
kexec") as the one most likely to overrun the window.
The comments justify the fixed sleep by saying "the reclaimed entries read
back the same before and after the pass, so there is no observable side
effect to wait on". Does that hold here? The comment above this function
says the pass "wipes those registers".
After kexec or an unclean unload, the previous instance has programmed
NBL_MAILBOX_QINFO_MAP_REG_ARR (BDF, MSIX_IDX, MSIX_IDX_VALID) and set
NBL_MAILBOX_QINFO_CFG_QUEUE_EN_MASK through config_mailbox_rxq/txq. No
.shutdown callback undoes that before kexec. Those entries should
therefore hold non-reset values before the pass and change once it runs.
Would a bounded poll on those entries work here instead of the fixed
sleep? Another option is a read-back check after
nbl_dev_setup_chan_qinfo().
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
Re: [PATCH v35 net-next 8/8] net/nebula-matrix: add common dev start/stop operation
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 12:52
Date: Mon, 23 Nov 2026 12:52
208 lines
15764 bytes
15764 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message and the new comments argue against earlier
review feedback more than they describe this change.
- [Low] This patch adds a third queue_work() site for the mailbox clean
task: the hardirq handler nbl_dev_clean_mailbox() calls…
- [Low] A comment in nbl_dev_setup_common_dev() (added earlier in this
series by commit "net/nebula-matrix: add common/ctrl dev init/remove…
--
net/nebula-matrix: add common dev start/stop operation
This commit adds nbl_dev_start() and nbl_dev_stop(). They are called
from nbl_probe() and nbl_remove() through nbl_core_start() and
nbl_core_stop().
Start configures the MSI-X map, fetches the VSI/ETH ids, allocates the
MSI-X vectors and arms the mailbox interrupt. Stop undoes these steps.
nbl_probe() now also rejects a function that has neither the ctrl nor
the net capability.
> 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 b20747d47fde2..de6a30996bb32 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
[ ... ]
> @@ -19,6 +30,247 @@ static void nbl_dev_init_msix_cnt(struct nbl_dev_mgt *dev_mgt)
[ ... ]
> +static int nbl_dev_disable_mailbox_irq(struct nbl_dev_mgt *dev_mgt)
> +{
[ ... ]
> + 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.
> + *
[ ... ]
> + * This does NOT preserve in-flight ACKs, and must not be described
> + * as doing so: the woken sender gives up and resets its slot to
> + * IDLE, so an ACK arriving afterwards finds a non-WAITING slot and
> + * is dropped by the receive path ("Skip ack invalid status").
> + * Interrupt mode is being torn down here; the guarantee is a
> + * bounded, deterministic failure, not delivery. In this driver
> + * every ACK-requesting sender runs from probe/remove and the clean
> + * task only sends ACK-less replies, so nothing depends on the
> + * stronger claim today.
[Severity: Low]
This isn't a bug, but could this comment be cut down to just the
invariant? Wording like "must not be described as doing so" reads like
a reply to earlier review, not documentation of the code.
The same thing happens in a few other places in this patch.
The comment at the top of nbl_dev_start() repeats the commit message's
argument for -ETIMEDOUT over -EPROBE_DEFER.
The lifetime of the control PF's MSI-X resources is explained three
times: in the commit message, at the err_destroy_map label in
nbl_dev_start(), and again in nbl_dev_stop(). This covers the
had_config path, the coherent table being kept, and nbl_intr_mgt_stop()
being the only release.
Those comments also describe the internals of functions in
nbl_interrupt.c:
__nbl_res_intr_prepare_destroy_msix_map()
__nbl_res_intr_complete_destroy_msix_map()
the rollback in nbl_res_intr_cfg_msix_map()
nbl_intr_mgt_stop()
Won't these comments go stale without anyone noticing when those
functions change?
Most of the commit message is also about alternatives that were not
taken, for example:
Relaxing the dependency to
"func 0 finished nbl_dev_init()" would therefore let every sibling RPC
sit out the full 5-6s polling wait. Converting the timeout to
-EPROBE_DEFER would only hide it behind dev_dbg() and make every later
bind pay that wait again.
The same goes for the pcim_msi_release double free discussion and the
driver_override paths. Could the changelog focus on what start and stop
actually do?
The label rename in nbl_dev_init() (setup_ctrl_dev_fail becomes
out_remove_common_dev, and setup_err is dropped) is not related to
start/stop. Would it fit better in a separate patch?
[ ... ]
> @@ -86,6 +338,14 @@ static void nbl_dev_clean_mailbox_task(struct work_struct *work)
> NBL_CHAN_TYPE_MAILBOX);
> }
>
> +static void nbl_dev_clean_mailbox_schedule(struct nbl_dev_mgt *dev_mgt)
> +{
> + struct nbl_dev_common *common_dev = dev_mgt->common_dev;
> + struct nbl_common_info *common = dev_mgt->common;
> +
> + queue_work(common->wq, &common_dev->clean_mbx_task);
> +}
[Severity: Low]
This adds a third queue_work() site for clean_mbx_task, called from the
nbl_dev_clean_mailbox() hardirq handler. The invariant comment in the
channel layer still says there are only two:
drivers/net/ethernet/nebula-matrix/nbl/nbl_channel/nbl_channel.c:nbl_chan_teardown_queue() {
...
* Nothing can be queued once Step 1 has run: both queue_work()
* sites (the sender's ACK poll and the worker's own self-requeue)
* check shutdn and clean_task under state_lock, and Step 1 cleared
* both.
...
}
The new site checks neither shutdn nor clean_task, and it cannot take
the state_lock mutex from hardirq context. It also skips the common->wq
check that nbl_chan_send_msg() makes before calling queue_work().
The invariant still holds today, but only because the device layer
frees the mailbox IRQ first. nbl_dev_stop() calls
nbl_dev_free_mailbox_irq() before the channel is torn down in
nbl_core_remove()->nbl_dev_remove_common_dev(). The nbl_dev_start()
rollback frees the IRQ at err_free_irq.
Should the comment in nbl_chan_teardown_queue() list the hardirq site?
Should it also say that the invariant depends on the IRQ being freed
before teardown_queue() runs? This patch's commit message already
lists three sources ("queued by the mailbox hardirq, by the task's own
self-requeue, or by this function's polling sends").
[ ... ]
> @@ -309,3 +569,189 @@ void nbl_dev_remove(struct nbl_adapter *adapter)
> if (common->has_ctrl)
> nbl_dev_remove_ctrl_dev(adapter);
> }
> +
> +/* ---------- Dev start process ---------- */
> +int nbl_dev_start(struct nbl_adapter *adapter)
> +{
[ ... ]
> + ret = nbl_dev_cfg_msix_map(dev_mgt);
> + if (ret)
> + goto err_destroy_map;
> +
> + /* Fetch VSI/ETH identity after cfg_msix_map */
> + ret = disp_ops->get_vsi_id(priv, NBL_VSI_DATA, &common->vsi_id);
> + if (ret)
> + goto err_destroy_map;
> + ret = disp_ops->get_eth_id(priv, common->vsi_id, &common->eth_num,
> + &common->eth_id, &common->logic_eth_id);
> + if (ret)
> + goto err_destroy_map;
[Severity: Low]
Does this match the comment that an earlier patch in this series added
to nbl_dev_setup_common_dev()?
/*
* VSI/ETH identity is deliberately not fetched here but in the
* start path, which is where it is used: the IDs only feed MSI-X
* and queue setup.
Here the IDs are fetched after nbl_dev_cfg_msix_map(), and the
cfg_msix_map dispatch op takes no VSI/ETH input:
drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_dispatch.h:
int (*cfg_msix_map)(struct nbl_dispatch_mgt *disp_mgt,
u16 num_net_msix, u16 num_others_msix,
bool net_msix_mask_en);
The series has no queue setup yet either. As far as I can tell,
common->vsi_id, eth_id, eth_num and logic_eth_id are written here and
never read. The one exception is vsi_id, which is passed to get_eth_id.
Even so, a failure from either RPC still aborts probe through
err_destroy_map. For example, nbl_res_get_eth_id() can return an error
for a PF/VSI mismatch or when rel_pf_id >= eth_num.
Should the fetch move to the patch that uses these IDs? If not, should
the comment in nbl_dev_setup_common_dev() be corrected?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com
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