* [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions
@ 2026-12-03 20:57 Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
Hi,
This series by Shahar introduces mlx5_nodnic, a Linux driver for the
NODNIC (No-DRAM NIC) hardware interface present in Mellanox/NVIDIA
ConnectX-family ASICs since 2015.
NODNIC is a first-class hardware capability.
It defines a lightweight NIC function intended for contexts where local
DRAM is unavailable or too costly: embedded controllers, management
planes, pre-boot environments, or any resource-constrained instantiation
of a ConnectX NIC. The hardware sends and receives ordinary Ethernet
frames via SQs, RQs and CQs. There is no encapsulation, no private
protocol, and no FW interposition: packets are forwarded as standard
Ethernet between whatever peers are connected to the function. The
interface is documented in the HW spec and has been in production in
non-Linux OS drivers for over a decade.
Where it is used today:
- Embedded management controllers on ConnectX-class ASICs that need a
network path to the host without consuming a data-path PF.
- Resource-constrained SoC integrations (no local DRAM) where a
minimal-footprint driver is required.
- Pre-boot / early-OS environments (PXE, iSCSI boot) that need a NIC
without a full mlx5e stack.
- BF4 management PFs (one concrete deployment): on BlueField-4 the
firmware exposes a NODNIC PF on the host side and a peer PF on the ARM
side, using standard vport forwarding to connect them. This provides
in-band Ethernet connectivity between the host and the DPU OS - SSH,
PXE, and any standard networking application work over it without any
special handling.
Design notes:
- The driver is separate from mlx5e rather than a mode within it.
NODNIC uses PCI Vendor Specific Capability (VSC) for command
operations - reads and writes over PCI config space - instead of the
DMA-based command interface used by mlx5_core. This is what makes
NODNIC usable in environments without reliable DMA access, and it
makes the two command paths fundamentally incompatible. Folding this
into mlx5e would mean carrying a second command transport and a second
resource model through code that is already dense.
- A single SQ, RQ and shared CQ are exposed per function, with two MSI-X
vectors: the data vector fires on CQEs and drives both TX and RX
completions, and the event vector notifies on port state changes.
This is the hardware's model, not a driver simplification.
- The driver exposes a plain netdev with no private uAPI, no ioctls and
no vendor-specific configuration surface. Everything is driven through
standard netdev and ethtool interfaces.
- The code lives under drivers/net/ethernet/mellanox/mlx5/nodnic/ and
shares no paths with mlx5e, keeping the footprint small and the blast
radius of changes contained.
for Sashiko:
- Where possible we keep the design close to mlx5 (checksum, VSC API, RX
refill and else).
- We don't implement suspend/resume flows at the moment.
- We don't implement SW timestamps at the moment.
- RX modes aren't needed and the driver doesn't implement
ndo_set_rx_mode.
- For sizes and values reported by the device, we trust it to provide
reasonable values.
- This series only wires the basic netdev stats (packets, bytes, and TX
drops).
Regards,
Tariq
V4:
Address the Sashiko AI review comments:
- Fixed the working buffer allocation size and document the units of
device-reported sizes in nodnic_ifc.h.
- Fixed incorrect ifc reserved_at_* fields.
- Fix comment about tunnel checksum.
V3:
https://lore.kernel.org/all/20261126182448.707782-1-tariqt@nvidia.com/
Address the Sashiko AI review comments:
- Convert PCIBIOS error codes returned by the config space accessors to
errno.
- Preserve the FW-reported CQ log_size when programming the CQ address.
- Compute the UAR offset in 64 bits.
- Enable NAPI only after the RQ is set up, fixing the open error unwind.
- Disable the port when open fails. If the port cannot be disabled,
clear bus mastering before freeing DMA memory.
- Use netif_txq_maybe_stop()/netif_txq_completed_wake() for TX flow
control.
- NAPI poll: handle budget == 0, return budget when the TX limit is hit,
and update the CQ doorbell record on every poll.
- Rate-limit the error CQE prints.
- Use u64_stats_t for the counters, and read the TX byte count before
releasing the WQE slot. Also count error TX CQEs in the stats.
- Restore the trailing newline in the Makefile.
- Check pci_save_state() return value.
- Change 1 << log_uar_page_size to 1U <<.
- Add NET_IP_ALIGN to the RX headroom, so the IP header is 4-byte
aligned.
- Restore bus mastering in mlx5_nodnic_enable_port(), just before
setting dma_en.
- Return send slots to xmit (sq->cc update and queue wake) only after
the CQ consumer index has been written to the device at the end of
each poll.
- Count received packets and bytes before the skb allocation, so packets
dropped on allocation failure are still included.
- Restore PCI state even if FLR failed.
- Remove the redundant CQ consumer index write from the arm function to
prevent overwriting a newer value after NAPI ownership is released.
- Disable NAPI before stopping the TX queue to prevent completions from
waking it again, then quiesce the port after TX submissions have
stopped. Reorder activation to mirror the deactivation sequence in
reverse.
- Fail queues opening if the device in fatal state.
- In health polling, check first if the PCI channel is offline.
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "pcie_flr failed with error code %d\n",
> + err);
> + return err;
> + }
> + pci_restore_state(dev->pdev);
Could mlx5_nodnic_dev_init() in
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c restore saved PCI state
on a reset error as well?
[SS] A device that fails to come out of FLR is treated as failed and probe aborts,
so there is nothing to restore it for.
Would it be appropriate to hold pci_cfg_access_lock() across the
save/reset/restore transaction in mlx5_nodnic_dev_init(), in
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c?
[SS] pci_save_state() does not require the caller to hold pci_cfg_access_lock().
> + dseg->byte_count = cpu_to_be32(skb->len & 0x7FFFFFFF);
> + dseg->lkey = cpu_to_be32(sq->ring.lkey);
> + dma_addr = dma_map_single(sq->device, skb->data, skb->len,
> + DMA_TO_DEVICE);
Could mlx5_nodnic_tx_build_wqe_ds(), in
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c, handle or reject nonlinear
skbs before mapping the total length as one contiguous buffer?
Pktgen with a positive fragment count and start_xmit mode constructs a
fragmented payload and calls netdev_start_xmit() directly. This bypasses
the ordinary feature-validation linearization despite scatter-gather
offload not being advertised.
Pktgen allocates full-packet linear capacity, so the demonstrated
regression is not necessarily an out-of-allocation read. Instead, the
device reads the unfilled linear payload region rather than the fragments,
sending incorrect bytes and potentially uninitialized allocation contents.
Could this path linearize the packet or map its fragments separately?
[SS] The driver doesn't advertise NETIF_F_SG, so the stack linearizes skbs
before they reach ndo_start_xmit. Only pktgen's start_xmit mode with frags
set can hand us a fragmented skb, which bypasses that validation. That is
a root-only test configuration, so we don't handle this case.
> + fatal_error = mlx5_nodnic_health_check_fatal_sensors(dev);
> +
> + if (fatal_error && !health->fatal_error) {
> + mlx5_nodnic_core_err(dev, "fatal error detected: %s (%u)\n",
> + mlx5_nodnic_fatal_error_str(fatal_error),
> + fatal_error);
> + priv->health.fatal_error = fatal_error;
> + dev->state = NODNIC_DEVICE_STATE_INTERNAL_ERROR;
> + mlx5_nodnic_print_health_info(dev);
> + return;
> + }
Can this fatal transition in mlx5_nodnic_poll_health(), in
drivers/net/ethernet/mellanox/mlx5/nodnic/health.c, also exclude subsequent
interface activation?
If polling detects a fatal condition while the registered interface is
down, an administrative interface-up request still reaches
mlx5_nodnic_open() -> mlx5_nodnic_open_locked() in
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c. Neither function checks
the fatal health state before mapping the UAR and programming the queues.
mlx5_nodnic_activate_queues() in the same file can then restore bus
mastering and enable the port if the hardware operations succeed. The
VSC offline check does not reject firmware reset requests, NIC
disablement, or NIC software reset based on the recorded health state.
The open path holds priv->state_lock, but the timer does not participate
in that serialization. Could the fatal transition be coordinated with
open through process-context work and an activation guard, so this
regression cannot permit hardware programming after fatal detection?
[SS] Health monitoring here only detects and prints. Fatal-error handling is planned for a follow-up.
What establishes completion of device DMA before cleanup releases the
buffers after this fallback? pci_clear_master() neither reports PCI
configuration-access failure nor explicitly waits for outstanding
transactions, yet cleanup proceeds unconditionally.
[SS] fallback is best effort.
How will netpoll reclaim TX descriptors when an RX CQE is ahead of the
send completions? Every zero-budget poll stops at the same RX CQE.
During panic netconsole output, ordinary NAPI cannot be relied on to
clear it. Once the SQ fills, diagnostic packets remain unsent; netpoll's
bounded retries only defer them to a worker. This needs a TX progress
mechanism that does not perform RX processing with a zero budget.
[SS] RX and TX share a single CQ and the ring is consumed in order,
so a zero-budget poll cannot reach TX CQEs behind an RX CQE without doing RX work
V2:
https://lore.kernel.org/all/20261008171821.660739-1-tariqt@nvidia.com/
- Fix sparse warnings in the VSC accessors: use __be32 for the
big-endian accessors and drop the redundant le32 conversions, which
were also wrong on big-endian hosts (Simon Horman).
- Cover letter: drop the devlink mention (Simon Horman).
- Replace the open-coded bitfield macros in the VSC code with
GENMASK/BIT and FIELD_GET/u32_replace_bits, and turn the config space
accessor macros into functions.
- Fix line wrapping reported by checkpatch --strict.
- Add a MAINTAINERS entry for the driver.
- Kconfig: select PAGE_POOL, fixing the build when it is not otherwise
enabled.
- Drop inline from a function in a .c file.
V1:
https://lore.kernel.org/all/20260930125708.144767-1-tariqt@nvidia.com/
Shahar Shitrit (5):
net/mlx5: nodnic: Introduce the mlx5_nodnic driver
net/mlx5: nodnic: Implement data path
net/mlx5: nodnic: Add TX/RX statistics
net/mlx5: nodnic: Add ethtool driver info
net/mlx5: nodnic: Add health monitoring
MAINTAINERS | 9 +
drivers/net/ethernet/mellanox/Kconfig | 1 +
drivers/net/ethernet/mellanox/Makefile | 1 +
.../net/ethernet/mellanox/mlx5/nodnic/Kconfig | 19 +
.../ethernet/mellanox/mlx5/nodnic/Makefile | 8 +
.../net/ethernet/mellanox/mlx5/nodnic/en.c | 295 +++++
.../net/ethernet/mellanox/mlx5/nodnic/en.h | 168 +++
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 1159 +++++++++++++++++
.../ethernet/mellanox/mlx5/nodnic/health.c | 303 +++++
.../net/ethernet/mellanox/mlx5/nodnic/main.c | 869 ++++++++++++
.../ethernet/mellanox/mlx5/nodnic/nodnic.h | 131 ++
.../mellanox/mlx5/nodnic/nodnic_ifc.h | 306 +++++
.../mellanox/mlx5/nodnic/nodnic_pci_vsc.c | 347 +++++
.../mellanox/mlx5/nodnic/nodnic_pci_vsc.h | 45 +
.../net/ethernet/mellanox/mlx5/nodnic/rx.c | 174 +++
.../net/ethernet/mellanox/mlx5/nodnic/rx.h | 25 +
.../net/ethernet/mellanox/mlx5/nodnic/tx.c | 265 ++++
.../net/ethernet/mellanox/mlx5/nodnic/tx.h | 65 +
18 files changed, 4190 insertions(+)
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
base-commit: c1165beb053a652299b1503b2dd7674ced0b1596
--
2.44.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
@ 2026-12-03 20:57 ` Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path Tariq Toukan
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
From: Shahar Shitrit <shshitrit@nvidia.com>
Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC
functions.
It defines a lightweight NIC function intended for contexts where local
DRAM is unavailable or too costly: embedded controllers, management
planes, pre-boot environments, or any resource-constrained instantiation
of a ConnectX NIC. The hardware sends and receives ordinary Ethernet
frames via SQs, RQs and CQs. There is no encapsulation, no private
protocol, and no FW interposition: packets are forwarded as standard
Ethernet between whatever peers are connected to the function. The
interface is documented in the HW spec and has been in production in
non-Linux OS drivers for over a decade.
This patch implements the PCI probe and remove flows, including FLR,
firmware readiness, interface negotiation and capability discovery,
followed by port and ring configuration.
It also adds the VSC access layer for PCI configuration-space accesses
to the initialization segment and to the NODNIC configuration registers.
Set up the event IRQ for link-state notifications, retrieve the port MAC
address, and implement the netdev lifecycle, including ndo_open and
ndo_stop.
Signed-off-by: Shahar Shitrit <shshitrit@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
MAINTAINERS | 9 +
drivers/net/ethernet/mellanox/Kconfig | 1 +
drivers/net/ethernet/mellanox/Makefile | 1 +
.../net/ethernet/mellanox/mlx5/nodnic/Kconfig | 18 +
.../ethernet/mellanox/mlx5/nodnic/Makefile | 8 +
.../net/ethernet/mellanox/mlx5/nodnic/en.h | 97 ++
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 841 +++++++++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/main.c | 867 ++++++++++++++++++
.../ethernet/mellanox/mlx5/nodnic/nodnic.h | 105 +++
.../mellanox/mlx5/nodnic/nodnic_ifc.h | 306 +++++++
.../mellanox/mlx5/nodnic/nodnic_pci_vsc.c | 347 +++++++
.../mellanox/mlx5/nodnic/nodnic_pci_vsc.h | 45 +
12 files changed, 2645 insertions(+)
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 9336fa93ce38..e4026b2c2f39 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17409,6 +17409,15 @@ F: drivers/infiniband/hw/mlx5/
F: include/linux/mlx5/
F: include/uapi/rdma/mlx5-abi.h
+MELLANOX MLX5 NODNIC DRIVER
+M: Shahar Shitrit <shshitrit@nvidia.com>
+M: Tariq Toukan <tariqt@nvidia.com>
+L: netdev@vger.kernel.org
+S: Maintained
+W: https://www.nvidia.com/networking/
+Q: https://patchwork.kernel.org/project/netdevbpf/list/
+F: drivers/net/ethernet/mellanox/mlx5/nodnic/
+
MELLANOX MLX5 VDPA DRIVER
M: Dragos Tatulea <dtatulea@nvidia.com>
L: virtualization@lists.linux.dev
diff --git a/drivers/net/ethernet/mellanox/Kconfig b/drivers/net/ethernet/mellanox/Kconfig
index b4f66eb9ddb9..979a029c0171 100644
--- a/drivers/net/ethernet/mellanox/Kconfig
+++ b/drivers/net/ethernet/mellanox/Kconfig
@@ -23,5 +23,6 @@ source "drivers/net/ethernet/mellanox/mlx5/core/Kconfig"
source "drivers/net/ethernet/mellanox/mlxsw/Kconfig"
source "drivers/net/ethernet/mellanox/mlxfw/Kconfig"
source "drivers/net/ethernet/mellanox/mlxbf_gige/Kconfig"
+source "drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig"
endif # NET_VENDOR_MELLANOX
diff --git a/drivers/net/ethernet/mellanox/Makefile b/drivers/net/ethernet/mellanox/Makefile
index d4b5f547a727..ec46837fa729 100644
--- a/drivers/net/ethernet/mellanox/Makefile
+++ b/drivers/net/ethernet/mellanox/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_MLX5_CORE) += mlx5/core/
obj-$(CONFIG_MLXSW_CORE) += mlxsw/
obj-$(CONFIG_MLXFW) += mlxfw/
obj-$(CONFIG_MLXBF_GIGE) += mlxbf_gige/
+obj-$(CONFIG_MLX5_NODNIC) += mlx5/nodnic/
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig b/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
new file mode 100644
index 000000000000..461750a9c97c
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config MLX5_NODNIC
+ tristate "Mellanox NODNIC core driver"
+ depends on PCI
+ depends on NETDEVICES && ETHERNET
+ help
+ This driver provides core support for Mellanox NODNIC (NO DRAM NIC)
+ devices. NODNIC is a lightweight network
+ interface driver that uses Vendor Specific Capability (VSC) for
+ PCI communication with Mellanox network adapters.
+
+ This driver enables basic Ethernet networking functionality for
+ supported Mellanox NODNIC hardware.
+
+ To compile this driver as a module, choose M here: the module
+ will be called mlx5_nodnic.
+
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
new file mode 100644
index 000000000000..4955f0427c79
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for Mellanox NODNIC driver
+#
+
+obj-$(CONFIG_MLX5_NODNIC) += mlx5_nodnic.o
+
+mlx5_nodnic-y := main.o en_cfg.o nodnic_pci_vsc.o
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
new file mode 100644
index 000000000000..90dc57695e1b
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#ifndef __MLX5_NODNIC_EN_H__
+#define __MLX5_NODNIC_EN_H__
+
+#include <linux/if_vlan.h>
+#include <linux/mlx5/device.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/timer.h>
+#include <linux/types.h>
+
+#define MLX5_NODNIC_RING_ENTRIES 1024
+#define MLX5_NODNIC_CQE_SIZE_B 64
+#define MLX5_NODNIC_SQ_WQEBB_B 64
+#define MLX5_NODNIC_RQ_STRIDE_BYTES 16
+
+enum {
+ MLX5_NODNIC_STATE_OPENED,
+};
+
+enum {
+ MLX5_NODNIC_RCV_DBR,
+ MLX5_NODNIC_SND_DBR,
+ MLX5_NODNIC_DBR_WORDS,
+};
+
+struct mlx5_nodnic_ring {
+ void *wq;
+ dma_addr_t dma_handle;
+ u32 size;
+ u32 num_entries;
+ u32 qn;
+ u32 lkey;
+};
+
+struct mlx5_nodnic_sq {
+ struct device *device;
+ struct net_device *netdev;
+ struct mlx5_nodnic_ring ring;
+
+ u16 pc;
+ u16 cc;
+};
+
+struct mlx5_nodnic_rq {
+ struct mlx5_nodnic_ring ring;
+ u16 pc;
+ u16 cc;
+};
+
+struct mlx5_nodnic_dbr {
+ __be32 *db;
+ dma_addr_t dma_handle;
+ u32 alloc_size;
+};
+
+struct mlx5_nodnic_cq {
+ struct mlx5_nodnic_ring ring;
+ int cqn;
+ int num_entries;
+ int log_num_entries;
+
+ struct mlx5_nodnic_dbr dbr;
+
+ int cc;
+};
+
+/* for FW use only */
+struct mlx5_nodnic_working_buffer {
+ dma_addr_t dma_handle;
+ u32 alloc_size;
+};
+
+struct mlx5_nodnic_priv {
+ struct mlx5_nodnic_core_dev *core_dev;
+ struct net_device *netdev;
+
+ struct mutex state_lock; /* protects Interface state */
+ unsigned long state;
+
+ struct mlx5_nodnic_sq sq;
+ struct mlx5_nodnic_rq rq;
+ struct mlx5_nodnic_dbr dbr; /* one shared dbr for TX and RX */
+ struct mlx5_nodnic_cq cq;
+ struct mlx5_nodnic_ring working_buffer;
+};
+
+void mlx5_nodnic_build_netdev(struct net_device *netdev);
+struct net_device *mlx5_nodnic_create_netdev(struct mlx5_nodnic_core_dev *dev);
+void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv);
+void mlx5_nodnic_cleanup_netdev(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_open(struct net_device *netdev);
+int mlx5_nodnic_close(struct net_device *netdev);
+
+#endif /* __MLX5_NODNIC_EN_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
new file mode 100644
index 000000000000..738722671090
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
@@ -0,0 +1,841 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/bitops.h>
+#include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/interrupt.h>
+#include <linux/log2.h>
+#include <linux/pci.h>
+#include <linux/sizes.h>
+#include <net/netdev_lock.h>
+#include <net/net_namespace.h>
+
+#include "en.h"
+#include "nodnic_ifc.h"
+#include "nodnic.h"
+#include "nodnic_pci_vsc.h"
+
+#define MLX5_NODNIC_CQ_INIT_CMD_SN cpu_to_be32(2 << 28)
+
+static int mlx5_nodnic_write_ring_addr(struct mlx5_nodnic_core_dev *dev,
+ dma_addr_t dma_handle, u32 offset_h,
+ u32 offset_l)
+{
+ __be32 addr_h, addr_l;
+ int err;
+
+ addr_h = cpu_to_be32(upper_32_bits(dma_handle));
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_h, addr_h);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write ring addr high: %d\n",
+ err);
+ return err;
+ }
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset_l, &addr_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read ring addr low: %d\n",
+ err);
+ return err;
+ }
+
+ MLX5_SET(nodnic_q_addr_l, &addr_l, q_addr_l,
+ lower_32_bits(dma_handle) >> 12);
+
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_l, addr_l);
+ if (err)
+ mlx5_nodnic_core_err(dev, "failed to write ring addr low: %d\n",
+ err);
+ return err;
+}
+
+static u32 mlx5_nodnic_calc_ring_size(struct mlx5_nodnic_core_dev *dev,
+ int stride)
+{
+ u32 ring_size = MLX5_NODNIC_RING_ENTRIES * stride;
+ u32 max_supported = 1U << dev->log_max_ring_size;
+
+ return min(ring_size, max_supported);
+}
+
+static int mlx5_nodnic_write_ring_size(struct mlx5_nodnic_core_dev *dev,
+ int offset, int size)
+{
+ __be32 addr_l;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &addr_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read ring size: %d\n",
+ err);
+ return err;
+ }
+
+ MLX5_SET(nodnic_q_addr_l, &addr_l, log_size, ilog2(size));
+
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset, addr_l);
+ if (err)
+ mlx5_nodnic_core_err(dev, "failed to write ring size: %d\n",
+ err);
+ return err;
+}
+
+static int mlx5_nodnic_read_qn(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_ring *ring, u32 offset)
+{
+ __be32 qn_dword;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &qn_dword);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read queue number: %d\n",
+ err);
+ return err;
+ }
+
+ ring->qn = MLX5_GET(nodnic_ring_q_number, &qn_dword, queue_number);
+
+ return 0;
+}
+
+static int mlx5_nodnic_write_ring_dbr_addr(struct mlx5_nodnic_core_dev *dev,
+ u32 ring_offset)
+{
+ int off_h = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_H;
+ int off_l = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_L;
+ struct mlx5_nodnic_dbr *dbr = &dev->priv->dbr;
+ __be32 dbr_h, dbr_l;
+ int err;
+
+ dbr_l = 0;
+ MLX5_SET(nodnic_ring_dbr_addr_l, &dbr_l, db_record_addr_l,
+ (u32)(dbr->dma_handle >> 2));
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_l, dbr_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write ring DBR addr low: %d\n",
+ err);
+ return err;
+ }
+
+ dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_h, dbr_h);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write ring DBR addr high: %d\n",
+ err);
+ return err;
+ }
+
+ return 0;
+}
+
+static int mlx5_nodnic_alloc_ring(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_ring *ring, int size)
+{
+ dma_addr_t dma_handle;
+ void *buf;
+
+ buf = dma_alloc_coherent(dev->device, size, &dma_handle, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ *ring = (struct mlx5_nodnic_ring) {
+ .wq = buf,
+ .dma_handle = dma_handle,
+ .size = size,
+ };
+
+ return 0;
+}
+
+static void mlx5_nodnic_free_ring(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_ring *ring)
+{
+ dma_free_coherent(dev->device, ring->size, ring->wq,
+ ring->dma_handle);
+ memset(ring, 0, sizeof(*ring));
+}
+
+static int mlx5_nodnic_init_ring(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_ring *ring, u32 ring_offset,
+ int stride)
+{
+ int ring_addr_h = ring_offset + MLX5_NODNIC_RING_ADDR_H;
+ int ring_addr_l = ring_offset + MLX5_NODNIC_RING_ADDR_L;
+ int size, err;
+
+ size = mlx5_nodnic_calc_ring_size(dev, stride);
+
+ err = mlx5_nodnic_alloc_ring(dev, ring, size);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle, ring_addr_h,
+ ring_addr_l);
+ if (err)
+ goto err_ring_free;
+
+ err = mlx5_nodnic_write_ring_size(dev, ring_addr_l, size);
+ if (err)
+ goto err_ring_free;
+
+ ring->num_entries = size / stride;
+
+ err = mlx5_nodnic_read_qn(dev, ring,
+ ring_offset + MLX5_NODNIC_RING_QUEUE_NUMBER);
+ if (err)
+ goto err_ring_free;
+
+ err = mlx5_nodnic_write_ring_dbr_addr(dev, ring_offset);
+ if (err)
+ goto err_ring_free;
+
+ return 0;
+
+err_ring_free:
+ mlx5_nodnic_free_ring(dev, ring);
+ return err;
+}
+
+static int mlx5_nodnic_alloc_dbr(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_dbr *dbr)
+{
+ const u32 bytes = MLX5_NODNIC_DBR_WORDS * sizeof(__be32);
+ dma_addr_t dma_handle;
+ void *buf;
+
+ buf = dma_alloc_coherent(dev->device, bytes, &dma_handle, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ *dbr = (struct mlx5_nodnic_dbr) {
+ .db = (__be32 *)buf,
+ .alloc_size = bytes,
+ .dma_handle = dma_handle,
+ };
+
+ return 0;
+}
+
+static void mlx5_nodnic_free_dbr(struct mlx5_nodnic_core_dev *dev,
+ struct mlx5_nodnic_dbr *dbr)
+{
+ if (!dbr->db)
+ return;
+
+ dma_free_coherent(dev->device, dbr->alloc_size, dbr->db,
+ dbr->dma_handle);
+}
+
+static int mlx5_nodnic_init_cq_dbr(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_dbr *dbr = &dev->priv->cq.dbr;
+ __be32 dbr_h, dbr_l;
+ int err;
+
+ err = mlx5_nodnic_alloc_dbr(dev, dbr);
+ if (err)
+ return err;
+
+ dbr_l = cpu_to_be32(lower_32_bits(dbr->dma_handle));
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
+ MLX5_NODNIC_CQ_DBR_ADDR_L,
+ dbr_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write CQ DBR addr low: %d\n",
+ err);
+ goto err_free_dbr;
+ }
+
+ dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
+ err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
+ MLX5_NODNIC_CQ_DBR_ADDR_H,
+ dbr_h);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write CQ DBR addr high: %d\n",
+ err);
+ goto err_free_dbr;
+ }
+
+ dev->priv->cq.dbr.db[1] = MLX5_NODNIC_CQ_INIT_CMD_SN;
+
+ return 0;
+
+err_free_dbr:
+ mlx5_nodnic_free_dbr(dev, &dev->priv->cq.dbr);
+ return err;
+}
+
+static void mlx5_nodnic_cleanup_cq_dbr(struct mlx5_nodnic_core_dev *dev)
+{
+ mlx5_nodnic_free_dbr(dev, &dev->priv->cq.dbr);
+}
+
+/* log_cq_size should be read after rq and sq ring sizes were set. */
+static int mlx5_nodnic_read_cq_ring_size(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_cq *cq = &dev->priv->cq;
+ __be32 cq_addr_l;
+ u32 log_cq_size;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_PORT_CQ_ADDR_L,
+ &cq_addr_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read CQ ring size: %d\n",
+ err);
+ return err;
+ }
+
+ log_cq_size = MLX5_GET(nodnic_q_addr_l, &cq_addr_l, log_size);
+ cq->num_entries = 1ULL << log_cq_size;
+ cq->log_num_entries = log_cq_size;
+
+ return 0;
+}
+
+static int mlx5_nodnic_init_cq_ring(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_cq *cq = &dev->priv->cq;
+ struct mlx5_nodnic_ring *ring;
+ int err;
+
+ ring = &cq->ring;
+
+ err = mlx5_nodnic_read_cq_ring_size(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_alloc_ring(dev, ring,
+ cq->num_entries * MLX5_NODNIC_CQE_SIZE_B);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle,
+ MLX5_NODNIC_PORT_CQ_ADDR_H,
+ MLX5_NODNIC_PORT_CQ_ADDR_L);
+ if (err)
+ goto err_free_cq;
+
+ return 0;
+
+err_free_cq:
+ mlx5_nodnic_free_ring(dev, &cq->ring);
+ return err;
+}
+
+static void mlx5_nodnic_cleanup_cq_ring(struct mlx5_nodnic_core_dev *dev)
+{
+ mlx5_nodnic_free_ring(dev, &dev->priv->cq.ring);
+}
+
+static int mlx5_nodnic_read_cq_n(struct mlx5_nodnic_core_dev *dev)
+{
+ __be32 cq_n;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, MLX5_NODNIC_CQ_N,
+ &cq_n);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read CQ number: %d\n",
+ err);
+ return err;
+ }
+
+ dev->priv->cq.cqn = MLX5_GET(nodnic_cqn, &cq_n, cq_n);
+
+ return 0;
+}
+
+int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
+ u32 size = SZ_1K << dev->log_working_buffer_size;
+ int err;
+
+ err = mlx5_nodnic_alloc_ring(dev, work_buf, size);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_write_ring_addr(dev, work_buf->dma_handle,
+ MLX5_NODNIC_PORT_WORK_BUF_ADDR_H,
+ MLX5_NODNIC_PORT_WORK_BUF_ADDR_L);
+ if (err)
+ goto err_free_working_buffer;
+
+ return 0;
+
+err_free_working_buffer:
+ mlx5_nodnic_free_ring(dev, work_buf);
+ return err;
+}
+
+int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_cq *cq = &dev->priv->cq;
+ int err;
+
+ cq->cc = 0;
+
+ err = mlx5_nodnic_init_cq_ring(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_init_cq_dbr(dev);
+ if (err)
+ goto err_cleanup_ring;
+
+ err = mlx5_nodnic_read_cq_n(dev);
+ if (err)
+ goto err_cleanup_dbr;
+
+ return 0;
+
+err_cleanup_dbr:
+ mlx5_nodnic_cleanup_cq_dbr(dev);
+err_cleanup_ring:
+ mlx5_nodnic_cleanup_cq_ring(dev);
+ return err;
+}
+
+static void mlx5_nodnic_close_cq(struct mlx5_nodnic_cq *cq)
+{
+ struct mlx5_nodnic_core_dev *dev =
+ container_of(cq, struct mlx5_nodnic_priv, cq)->core_dev;
+
+ mlx5_nodnic_cleanup_cq_dbr(dev);
+ mlx5_nodnic_cleanup_cq_ring(dev);
+}
+
+int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv = dev->priv;
+ struct mlx5_nodnic_sq *sq = &priv->sq;
+ struct mlx5_nodnic_ring *ring;
+ int err;
+
+ sq->netdev = priv->netdev;
+ sq->device = dev->device;
+ sq->pc = 0;
+ sq->cc = 0;
+ ring = &sq->ring;
+
+ err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_SEND_RING_OFFSET,
+ MLX5_NODNIC_SQ_WQEBB_B);
+ if (err)
+ return err;
+
+ ring->lkey = dev->lkey;
+
+ return 0;
+}
+
+static void mlx5_nodnic_close_sq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_sq *sq = &dev->priv->sq;
+
+ mlx5_nodnic_free_ring(dev, &sq->ring);
+}
+
+int mlx5_nodnic_open_rq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_rq *rq = &dev->priv->rq;
+ struct mlx5_nodnic_ring *ring;
+ int err;
+
+ rq->pc = 0;
+ rq->cc = 0;
+ ring = &rq->ring;
+
+ err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_RECEIVE_RING_OFFSET,
+ MLX5_NODNIC_RQ_STRIDE_BYTES);
+ if (err)
+ return err;
+
+ ring->lkey = dev->lkey;
+
+ return 0;
+}
+
+static void mlx5_nodnic_close_rq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_rq *rq = &dev->priv->rq;
+
+ mlx5_nodnic_free_ring(dev, &rq->ring);
+}
+
+static int mlx5_nodnic_open_queues(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
+ int err;
+
+ /* one doorbell record shared by both SQ and RQ */
+ err = mlx5_nodnic_alloc_dbr(dev, &dev->priv->dbr);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
+ if (err)
+ goto err_free_dbr;
+
+ err = mlx5_nodnic_open_sq(dev);
+ if (err)
+ goto err_release_vsc;
+
+ err = mlx5_nodnic_open_rq(dev);
+ if (err)
+ goto err_close_sq;
+
+ err = mlx5_nodnic_open_cq(dev);
+ if (err)
+ goto err_close_rq;
+
+ err = mlx5_nodnic_init_working_buffer(dev);
+ if (err)
+ goto err_close_cq;
+
+ mlx5_nodnic_vsc_context_release(vsc_ctx);
+
+ return 0;
+
+err_close_cq:
+ mlx5_nodnic_close_cq(&dev->priv->cq);
+err_close_rq:
+ mlx5_nodnic_close_rq(dev);
+err_close_sq:
+ mlx5_nodnic_close_sq(dev);
+err_release_vsc:
+ mlx5_nodnic_vsc_context_release(vsc_ctx);
+err_free_dbr:
+ mlx5_nodnic_free_dbr(dev, &dev->priv->dbr);
+
+ return err;
+}
+
+static void mlx5_nodnic_close_queues(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv = dev->priv;
+
+ mlx5_nodnic_free_ring(dev, &priv->working_buffer);
+ mlx5_nodnic_close_cq(&priv->cq);
+ mlx5_nodnic_close_rq(dev);
+ mlx5_nodnic_close_sq(dev);
+ mlx5_nodnic_free_dbr(dev, &priv->dbr);
+}
+
+static void mlx5_nodnic_update_carrier(struct mlx5_nodnic_priv *priv,
+ __be32 event)
+{
+ u32 port_state = MLX5_GET(nodnic_port_event, &event, port_state);
+ bool up = port_state == MLX5_NODNIC_PORT_STATE_ACTIVE;
+
+ /* Force re-notification if state is unchanged */
+ if (up == netif_carrier_ok(priv->netdev)) {
+ netif_carrier_event(priv->netdev);
+ return;
+ }
+ if (up) {
+ netif_carrier_on(priv->netdev);
+ netdev_info(priv->netdev, "Link up\n");
+ } else {
+ netif_carrier_off(priv->netdev);
+ netdev_info(priv->netdev, "Link down\n");
+ }
+}
+
+static int mlx5_nodnic_refresh_carrier_locked(struct mlx5_nodnic_priv *priv)
+{
+ struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx;
+ __be32 event;
+ int err;
+
+ vsc_ctx = dev->vsc_ctx;
+ err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_EVENT,
+ &event);
+ mlx5_nodnic_vsc_context_release(vsc_ctx);
+
+ if (!err)
+ mlx5_nodnic_update_carrier(priv, event);
+
+ return err;
+}
+
+void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
+{
+ mutex_lock(&priv->state_lock);
+ if (test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state))
+ mlx5_nodnic_refresh_carrier_locked(priv);
+ mutex_unlock(&priv->state_lock);
+}
+
+int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
+ __be32 val = 0;
+ int err;
+
+ /* data_msix_en, event_msix_en must be set before activating port */
+ MLX5_SET(nodnic_port_network, &val, data_msix_en, 1);
+ MLX5_SET(nodnic_port_network, &val, event_msix_en, 1);
+ err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ val);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write port network (msix): %d\n",
+ err);
+ return err;
+ }
+
+ MLX5_SET(nodnic_port_network, &val, network_en, 1);
+ MLX5_SET(nodnic_port_network, &val, receive_filter_en, BIT(0));
+
+ err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ val);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to write port network (enable): %d\n",
+ err);
+ return err;
+ }
+
+ /* Enable bus mastering only now, after the writes above, so the
+ * device can't resume DMA with stale state.
+ */
+ pci_set_master(dev->pdev);
+
+ /* dma enabling requires a separate write */
+ MLX5_SET(nodnic_port_network, &val, dma_en, 1);
+
+ err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ val);
+ if (err)
+ mlx5_nodnic_core_err(dev,
+ "failed to write port network (dma): %d\n",
+ err);
+
+ return err;
+}
+
+void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
+ __be32 val;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ &val);
+ if (err)
+ goto out;
+
+ MLX5_SET(nodnic_port_network, &val, dma_en, 0);
+ MLX5_SET(nodnic_port_network, &val, network_en, 0);
+ err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ val);
+ if (err)
+ goto out;
+
+ /* data_msix_en, event_msix_en can't be modified while port is active */
+ MLX5_SET(nodnic_port_network, &val, data_msix_en, 0);
+ MLX5_SET(nodnic_port_network, &val, event_msix_en, 0);
+ err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
+ val);
+
+out:
+ if (err)
+ mlx5_nodnic_core_warn(dev,
+ "failed to read/write to vsc err %d\n",
+ err);
+}
+
+static int mlx5_nodnic_init_uar_map(struct mlx5_nodnic_core_dev *dev)
+{
+ void __iomem *base;
+ phys_addr_t paddr;
+ u32 uar_page_size;
+
+ uar_page_size = 1U << dev->log_uar_page_size;
+
+ paddr = dev->bar_addr +
+ ((phys_addr_t)dev->send_ring0_uar_index * uar_page_size);
+
+ base = ioremap(paddr, uar_page_size);
+ if (!base) {
+ mlx5_nodnic_core_err(dev, "failed to map UAR\n");
+ return -ENOMEM;
+ }
+
+ dev->uar_base = base;
+
+ return 0;
+}
+
+static void mlx5_nodnic_cleanup_uar_map(struct mlx5_nodnic_core_dev *dev)
+{
+ if (!dev->uar_base)
+ return;
+
+ iounmap(dev->uar_base);
+ dev->uar_base = NULL;
+}
+
+static int mlx5_nodnic_open_locked(struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+ int err;
+
+ err = mlx5_nodnic_init_uar_map(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_open_queues(dev);
+ if (err)
+ goto err_uar;
+
+ set_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
+
+ err = mlx5_nodnic_refresh_carrier_locked(priv);
+ if (err)
+ netdev_err(netdev, "Failed to query carrier, err=%d\n", err);
+
+ return 0;
+
+err_uar:
+ mlx5_nodnic_cleanup_uar_map(dev);
+ return err;
+}
+
+int mlx5_nodnic_open(struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ int err;
+
+ mutex_lock(&priv->state_lock);
+ err = mlx5_nodnic_open_locked(netdev);
+ mutex_unlock(&priv->state_lock);
+
+ return err;
+}
+
+static int mlx5_nodnic_close_locked(struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+
+ clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
+ netif_carrier_off(netdev);
+ netdev_info(netdev, "Link down\n");
+ mlx5_nodnic_close_queues(dev);
+
+ return 0;
+}
+
+int mlx5_nodnic_close(struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ int err = 0;
+
+ mutex_lock(&priv->state_lock);
+ if (!test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state)) {
+ mutex_unlock(&priv->state_lock);
+ return 0;
+ }
+
+ err = mlx5_nodnic_close_locked(netdev);
+ mutex_unlock(&priv->state_lock);
+
+ mlx5_nodnic_cleanup_uar_map(priv->core_dev);
+
+ return err;
+}
+
+static const struct net_device_ops mlx5_nodnic_netdev_ops = {
+ .ndo_open = mlx5_nodnic_open,
+ .ndo_stop = mlx5_nodnic_close,
+};
+
+void mlx5_nodnic_build_netdev(struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ struct mlx5_nodnic_core_dev *core_dev;
+
+ core_dev = priv->core_dev;
+
+ SET_NETDEV_DEV(netdev, core_dev->device);
+
+ netdev->netdev_ops = &mlx5_nodnic_netdev_ops;
+ netdev->request_ops_lock = true;
+
+ eth_hw_addr_set(netdev, core_dev->mac_address);
+}
+
+static void mlx5_nodnic_init_priv(struct mlx5_nodnic_priv *priv,
+ struct net_device *netdev,
+ struct mlx5_nodnic_core_dev *core_dev)
+{
+ priv->netdev = netdev;
+ priv->core_dev = core_dev;
+ mutex_init(&priv->state_lock);
+}
+
+static void mlx5_nodnic_cleanup_priv(struct mlx5_nodnic_priv *priv)
+{
+ mutex_destroy(&priv->state_lock);
+}
+
+struct net_device *mlx5_nodnic_create_netdev(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv;
+ struct net_device *netdev;
+
+ netdev = alloc_etherdev_mqs(sizeof(struct mlx5_nodnic_priv), 1, 1);
+ if (!netdev)
+ return NULL;
+
+ priv = netdev_priv(netdev);
+ mlx5_nodnic_init_priv(priv, netdev, dev);
+ dev->priv = priv;
+
+ netif_carrier_off(netdev);
+ netif_tx_disable(netdev);
+ dev_net_set(netdev, &init_net);
+
+ return netdev;
+}
+
+void mlx5_nodnic_cleanup_netdev(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv;
+ struct net_device *netdev;
+
+ if (!dev->priv)
+ return;
+
+ priv = dev->priv;
+ netdev = priv->netdev;
+ if (!netdev)
+ return;
+
+ if (dev->netdev_registered) {
+ netif_device_detach(netdev);
+ unregister_netdev(netdev);
+ dev->netdev_registered = false;
+ }
+
+ mlx5_nodnic_cleanup_priv(priv);
+ dev->priv = NULL;
+
+ free_netdev(netdev);
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
new file mode 100644
index 000000000000..b905deda56dc
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
@@ -0,0 +1,867 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/dma-mapping.h>
+#include <linux/etherdevice.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "en.h"
+#include "nodnic_ifc.h"
+#include "nodnic.h"
+#include "nodnic_pci_vsc.h"
+
+MODULE_DESCRIPTION("Nvidia Mellanox MLX5_NODNIC core driver");
+MODULE_LICENSE("Dual BSD/GPL");
+
+#define MLX5_NODNIC_FW_INIT_TIMEOUT_MS 120000
+#define MLX5_NODNIC_FW_INIT_WARN_MS 20000
+#define MLX5_NODNIC_FW_PRE_INIT_WAIT_MS 2
+
+static int mlx5_nodnic_pci_enable_device(struct mlx5_nodnic_core_dev *dev)
+{
+ struct pci_dev *pdev = dev->pdev;
+ int err = 0;
+
+ mutex_lock(&dev->pci_status_mutex);
+ if (dev->pci_status == MLX5_NODNIC_PCI_STATUS_DISABLED) {
+ err = pci_enable_device(pdev);
+ if (!err)
+ dev->pci_status = MLX5_NODNIC_PCI_STATUS_ENABLED;
+ }
+ mutex_unlock(&dev->pci_status_mutex);
+
+ return err;
+}
+
+static void mlx5_nodnic_pci_disable_device(struct mlx5_nodnic_core_dev *dev)
+{
+ struct pci_dev *pdev = dev->pdev;
+
+ mutex_lock(&dev->pci_status_mutex);
+ if (dev->pci_status == MLX5_NODNIC_PCI_STATUS_ENABLED) {
+ pci_disable_device(pdev);
+ dev->pci_status = MLX5_NODNIC_PCI_STATUS_DISABLED;
+ }
+ mutex_unlock(&dev->pci_status_mutex);
+}
+
+static int request_bar(struct pci_dev *pdev)
+{
+ int err;
+
+ if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
+ dev_err(&pdev->dev, "Missing registers BAR, aborting\n");
+ return -ENODEV;
+ }
+
+ err = pci_request_regions(pdev, KBUILD_MODNAME);
+ if (err)
+ dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
+
+ return err;
+}
+
+static void release_bar(struct pci_dev *pdev)
+{
+ pci_release_regions(pdev);
+}
+
+static int set_dma_caps(struct pci_dev *pdev)
+{
+ if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
+ int err;
+
+ dev_warn(&pdev->dev,
+ "couldn't set 64-bit PCI DMA mask\n");
+ err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+ if (err) {
+ dev_err(&pdev->dev,
+ "can't set PCI DMA mask, aborting\n");
+ return err;
+ }
+ }
+
+ dma_set_max_seg_size(&pdev->dev, 2u * 1024 * 1024 * 1024);
+
+ return 0;
+}
+
+static void mlx5_nodnic_pci_close(struct mlx5_nodnic_core_dev *dev)
+{
+ pci_free_irq_vectors(dev->pdev);
+ iounmap(dev->iseg);
+ release_bar(dev->pdev);
+ mlx5_nodnic_pci_disable_device(dev);
+ mlx5_nodnic_vsc_cleanup(dev->vsc_ctx);
+}
+
+static int
+mlx5_nodnic_pci_init(struct mlx5_nodnic_core_dev *dev, struct pci_dev *pdev)
+{
+ int err;
+
+ mutex_init(&dev->pci_status_mutex);
+ pci_set_drvdata(dev->pdev, dev);
+
+ dev->bar_addr = pci_resource_start(pdev, 0);
+
+ err = mlx5_nodnic_pci_enable_device(dev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "cannot enable PCI device, aborting\n");
+ return err;
+ }
+
+ err = request_bar(pdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "error requesting BARs, aborting\n");
+ goto err_disable;
+ }
+
+ err = set_dma_caps(pdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed setting DMA capabilities mask, aborting\n");
+ goto err_release_bar;
+ }
+
+ dev->iseg = ioremap(dev->bar_addr, sizeof(*dev->iseg));
+ if (!dev->iseg) {
+ err = -ENOMEM;
+ mlx5_nodnic_core_err(dev,
+ "failed mapping initialization segment, aborting\n");
+ goto err_release_bar;
+ }
+
+ dev->vsc_ctx = mlx5_nodnic_vsc_init(dev->pdev);
+ if (!dev->vsc_ctx) {
+ err = -EINVAL;
+ goto err_unmap;
+ }
+
+ if (!pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
+ mlx5_nodnic_core_err(dev,
+ "msi-x support is not supported in pci, aborting\n");
+ err = -EOPNOTSUPP;
+ goto err_vsc_cleanup;
+ }
+
+ err = pci_alloc_irq_vectors(pdev,
+ MLX5_NODNIC_NUM_MSIX, MLX5_NODNIC_NUM_MSIX,
+ PCI_IRQ_MSIX);
+ if (err < 0) {
+ mlx5_nodnic_core_err(dev, "pci_alloc_irq_vectors failed: %d\n",
+ err);
+ goto err_vsc_cleanup;
+ }
+
+ return 0;
+
+err_vsc_cleanup:
+ mlx5_nodnic_vsc_cleanup(dev->vsc_ctx);
+err_unmap:
+ iounmap(dev->iseg);
+err_release_bar:
+ release_bar(dev->pdev);
+err_disable:
+ mlx5_nodnic_pci_disable_device(dev);
+ return err;
+}
+
+int mlx5_nodnic_get_fw_initializing(struct mlx5_nodnic_core_dev *dev,
+ u8 *initializing)
+{
+ __be32 data;
+ int err;
+
+ err = mlx5_nodnic_vsc_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_ISEG_INITIALIZING,
+ &data);
+ if (err)
+ return err;
+
+ *initializing = MLX5_GET(nodnic_iseg_initializing_word, &data,
+ initializing);
+
+ return 0;
+}
+
+static int mlx5_nodnic_wait_fw_init(struct mlx5_nodnic_core_dev *dev,
+ const char *init_state)
+{
+ unsigned long timeout =
+ msecs_to_jiffies(MLX5_NODNIC_FW_INIT_TIMEOUT_MS);
+ unsigned long warn_interval =
+ msecs_to_jiffies(MLX5_NODNIC_FW_INIT_WARN_MS);
+ unsigned long warn = jiffies + warn_interval;
+ unsigned long end = jiffies + timeout;
+ u8 fw_initializing;
+ int err;
+
+ do {
+ err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_get_fw_initializing(dev, &fw_initializing);
+ mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to read FW initializing state: %d\n",
+ err);
+ return err;
+ }
+
+ if (!fw_initializing)
+ break;
+
+ if (time_after(jiffies, end)) {
+ mlx5_nodnic_core_err(dev,
+ "timeout waiting for FW to exit %s state (%u ms)\n",
+ init_state,
+ MLX5_NODNIC_FW_INIT_TIMEOUT_MS);
+ return -ETIMEDOUT;
+ }
+ if (time_after(jiffies, warn)) {
+ mlx5_nodnic_core_warn(dev,
+ "FW still in %s state, %u ms remaining (state=0x%x)\n",
+ init_state,
+ jiffies_to_msecs(end - jiffies),
+ fw_initializing);
+
+ warn = jiffies + warn_interval;
+ }
+ msleep(MLX5_NODNIC_FW_PRE_INIT_WAIT_MS);
+ } while (true);
+
+ return 0;
+}
+
+int mlx5_nodnic_check_supported(struct mlx5_nodnic_core_dev *dev)
+{
+ __be32 initializing_word;
+ int err;
+
+ err = mlx5_nodnic_vsc_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_ISEG_INITIALIZING,
+ &initializing_word);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed reading NODNIC initializing word: %d\n",
+ err);
+ return err;
+ }
+
+ if (!(MLX5_GET(nodnic_iseg_initializing_word, &initializing_word,
+ nic_interface_supported) &
+ BIT(MLX5_NODNIC_ISEG_NIC_INTERFACE_NO_DRAM_NIC))) {
+ mlx5_nodnic_core_err(dev,
+ "NODNIC is not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+int mlx5_nodnic_write_nic_interface(struct mlx5_nodnic_core_dev *dev,
+ int interface)
+{
+ __be32 dword;
+ int err;
+
+ err = mlx5_nodnic_vsc_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_ISEG_NIC_INTERFACE,
+ &dword);
+ if (err)
+ return err;
+
+ MLX5_SET(nodnic_iseg_cmdq_addr_l, &dword, nic_interface, interface);
+
+ err = mlx5_nodnic_vsc_write_be32(dev->vsc_ctx,
+ MLX5_NODNIC_ISEG_NIC_INTERFACE,
+ dword);
+
+ return err;
+}
+
+int mlx5_nodnic_set_nic_interface(struct mlx5_nodnic_core_dev *dev)
+{
+ int interface = MLX5_NODNIC_ISEG_NIC_INTERFACE_NO_DRAM_NIC;
+ int err;
+
+ err = mlx5_nodnic_check_supported(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_write_nic_interface(dev, interface);
+ if (err)
+ mlx5_nodnic_core_err(dev,
+ "failed to write nic_interface err %d\n",
+ err);
+
+ return err;
+}
+
+static int mlx5_nodnic_read_general_caps(struct mlx5_nodnic_core_dev *dev)
+{
+ u8 hardware_format, revision;
+ bool support_receive_filters;
+ __be32 caps;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_GENERAL_CONFIG_CAPS,
+ &caps);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read general caps: %d\n",
+ err);
+ return err;
+ }
+
+ revision = MLX5_GET(nodnic_gen_cfg_caps, &caps, revision);
+ hardware_format = MLX5_GET(nodnic_gen_cfg_caps, &caps, hardware_format);
+ if (revision != 1) {
+ mlx5_nodnic_core_err(dev, "revision is not 1, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (hardware_format != 1) {
+ mlx5_nodnic_core_err(dev,
+ "hardware format is not 1, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ dev->log_working_buffer_size = MLX5_GET(nodnic_gen_cfg_caps, &caps,
+ log_working_buffer_size);
+ support_receive_filters = MLX5_GET(nodnic_gen_cfg_caps, &caps,
+ support_receive_filter);
+ if (!support_receive_filters) {
+ mlx5_nodnic_core_err(dev,
+ "receive filters are not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+static int mlx5_nodnic_read_ring_config(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 addr = MLX5_NODNIC_GENERAL_CONFIG_LOG_MAX_RING_SIZE;
+ __be32 data;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, addr, &data);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read ring config: %d\n",
+ err);
+ return err;
+ }
+
+ dev->log_max_ring_size = MLX5_GET(nodnic_gen_cfg_log_max_ring_size,
+ &data, log_max_ring_size);
+
+ return 0;
+}
+
+static int mlx5_nodnic_read_lkey(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 lkey;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_cpu32(dev->vsc_ctx,
+ MLX5_NODNIC_GENERAL_CONFIG_LKEY,
+ &lkey);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read lkey: %d\n", err);
+ return err;
+ }
+
+ dev->lkey = lkey;
+
+ return 0;
+}
+
+static int mlx5_nodnic_read_cqe_format(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 addr = MLX5_NODNIC_GENERAL_CONFIG_CQE_FORMAT;
+ u8 cqe_format;
+ __be32 data;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, addr, &data);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read CQE format: %d\n",
+ err);
+ return err;
+ }
+
+ cqe_format = MLX5_GET(nodnic_gen_cfg_cqe_format, &data, cqe_format);
+ if (cqe_format != 0) {
+ mlx5_nodnic_core_err(dev,
+ "cqe format is not legacy (0x0), aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+static int mlx5_nodnic_read_uar_index(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 addr = MLX5_NODNIC_PORT_SEND_RING0_UAR_INDEX;
+ u32 uar_index;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_cpu32(dev->vsc_ctx, addr, &uar_index);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read UAR index: %d\n",
+ err);
+ return err;
+ }
+
+ dev->send_ring0_uar_index = uar_index;
+
+ return 0;
+}
+
+static int mlx5_nodnic_read_uar_size(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 addr = MLX5_NODNIC_GENERAL_CONFIG_LOG_UAR_PAGE_SIZE;
+ __be32 uar_size;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, addr, &uar_size);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read UAR size: %d\n", err);
+ return err;
+ }
+
+ dev->log_uar_page_size = MLX5_GET(nodnic_gen_cfg_log_uar_page_size,
+ &uar_size, log_uar_page_size);
+
+ return 0;
+}
+
+static int mlx5_nodnic_validate_feature_caps(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 addr = MLX5_NODNIC_GENERAL_CONFIG_FEATURE_CAPS;
+ u8 support_uar_tx_doorbell, support_bar_cq_ctrl;
+ u8 data_msix_support, event_msix_support;
+ __be32 data;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, addr, &data);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read feature caps: %d\n",
+ err);
+ return err;
+ }
+
+ support_uar_tx_doorbell = MLX5_GET(nodnic_gen_cfg_feature_caps, &data,
+ support_uar_tx_doorbell);
+ if (!support_uar_tx_doorbell) {
+ mlx5_nodnic_core_err(dev,
+ "UAR tx doorbell is not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ support_bar_cq_ctrl = MLX5_GET(nodnic_gen_cfg_feature_caps, &data,
+ support_bar_cq_ctrl);
+ if (!support_bar_cq_ctrl) {
+ mlx5_nodnic_core_err(dev,
+ "UAR cq arming is not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ data_msix_support = MLX5_GET(nodnic_gen_cfg_feature_caps, &data,
+ data_msix_support);
+ if (!data_msix_support) {
+ mlx5_nodnic_core_err(dev,
+ "data MSI-X is not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ event_msix_support = MLX5_GET(nodnic_gen_cfg_feature_caps, &data,
+ event_msix_support);
+ if (!event_msix_support) {
+ mlx5_nodnic_core_err(dev,
+ "event MSI-X is not supported, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+int mlx5_nodnic_read_config(struct mlx5_nodnic_core_dev *dev)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_read_offset(dev->vsc_ctx);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to read VSC offset, err=%d\n",
+ err);
+ return err;
+ }
+
+ err = mlx5_nodnic_read_general_caps(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_read_ring_config(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_read_lkey(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_read_cqe_format(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_validate_feature_caps(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_read_uar_size(dev);
+ if (err)
+ return err;
+
+ return mlx5_nodnic_read_uar_index(dev);
+}
+
+static void mlx5_nodnic_dev_cleanup(struct mlx5_nodnic_core_dev *dev)
+{
+ int interface = MLX5_NODNIC_ISEG_NIC_INTERFACE_DISABLED;
+ int err;
+
+ err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
+ if (err)
+ return;
+
+ err = mlx5_nodnic_write_nic_interface(dev, interface);
+ mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
+ if (err)
+ return;
+
+ mlx5_nodnic_wait_fw_init(dev, "teardown");
+}
+
+static int mlx5_nodnic_dev_init(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
+ int err;
+
+ err = mlx5_nodnic_wait_fw_init(dev, "pre-FLR");
+ if (err)
+ return err;
+
+ err = pci_save_state(dev->pdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "pci_save_state failed: %d\n", err);
+ return err;
+ }
+
+ err = pcie_flr(dev->pdev);
+ pci_restore_state(dev->pdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "pcie_flr failed with error code %d\n",
+ err);
+ return err;
+ }
+
+ err = mlx5_nodnic_wait_fw_init(dev, "post-FLR");
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_set_nic_interface(dev);
+ mlx5_nodnic_vsc_context_release(vsc_ctx);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_set_nic_interface failed with error code %d\n",
+ err);
+ goto disable_nic;
+ }
+
+ err = mlx5_nodnic_wait_fw_init(dev, "post-MLX5_NODNIC setup");
+ if (err)
+ goto disable_nic;
+
+ err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
+ if (err)
+ goto disable_nic;
+
+ err = mlx5_nodnic_read_config(dev);
+ if (err)
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_read_config failed with error code %d\n",
+ err);
+
+ mlx5_nodnic_vsc_context_release(vsc_ctx);
+ if (err)
+ goto disable_nic;
+
+ return 0;
+
+disable_nic:
+ mlx5_nodnic_dev_cleanup(dev);
+ return err;
+}
+
+int mlx5_nodnic_validate_port_link_type(struct mlx5_nodnic_core_dev *dev)
+{
+ u8 link_type;
+ __be32 event;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx,
+ MLX5_NODNIC_PORT_EVENT,
+ &event);
+ if (err) {
+ mlx5_nodnic_core_err(dev, "failed to read port event: %d\n",
+ err);
+ return err;
+ }
+
+ link_type = MLX5_GET(nodnic_port_event, &event, link_type);
+ if (!link_type) {
+ mlx5_nodnic_core_err(dev, "port is not Ethernet, aborting\n");
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+int mlx5_nodnic_read_mac_address(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 mac_h, mac_l;
+ u64 mac;
+ int err;
+
+ err = mlx5_nodnic_vsc_cfg_read_cpu32(dev->vsc_ctx,
+ MLX5_NODNIC_PORT_MAC_ADDR_H,
+ &mac_h);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to read MAC address high: %d\n",
+ err);
+ return err;
+ }
+
+ err = mlx5_nodnic_vsc_cfg_read_cpu32(dev->vsc_ctx,
+ MLX5_NODNIC_PORT_MAC_ADDR_L,
+ &mac_l);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "failed to read MAC address low: %d\n",
+ err);
+ return err;
+ }
+
+ mac = ((u64)mac_h << 32) | mac_l;
+
+ u64_to_ether_addr(mac, dev->mac_address);
+
+ return 0;
+}
+
+static int mlx5_nodnic_port_init(struct mlx5_nodnic_core_dev *dev)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_validate_port_link_type(dev);
+ if (err)
+ goto release;
+
+ err = mlx5_nodnic_read_mac_address(dev);
+ if (err)
+ goto release;
+
+release:
+ mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
+ return err;
+}
+
+static irqreturn_t mlx5_nodnic_event_irq_thread(int irq, void *data)
+{
+ struct mlx5_nodnic_priv *priv = data;
+
+ if (!netif_device_present(priv->netdev))
+ return IRQ_HANDLED;
+
+ mlx5_nodnic_refresh_carrier(priv);
+
+ return IRQ_HANDLED;
+}
+
+static int mlx5_nodnic_event_irq_setup(struct mlx5_nodnic_core_dev *dev)
+{
+ int irqn, err;
+
+ irqn = pci_irq_vector(dev->pdev, MLX5_NODNIC_EVENT_MSIX);
+ if (irqn < 0) {
+ mlx5_nodnic_core_err(dev,
+ "pci_irq_vector for event failed: %d\n",
+ irqn);
+ return irqn;
+ }
+
+ err = request_threaded_irq(irqn, NULL, mlx5_nodnic_event_irq_thread,
+ IRQF_ONESHOT, "mlx5_nodnic-event",
+ dev->priv);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "request_threaded_irq for event failed\n");
+ return err;
+ }
+
+ dev->event_irqn = irqn;
+
+ return 0;
+}
+
+static void mlx5_nodnic_event_irq_cleanup(struct mlx5_nodnic_core_dev *dev)
+{
+ if (dev->event_irqn < 0)
+ return;
+ free_irq(dev->event_irqn, dev->priv);
+ dev->event_irqn = -1;
+}
+
+static int mlx5_nodnic_probe_one(struct pci_dev *pdev,
+ const struct pci_device_id *id)
+{
+ struct mlx5_nodnic_core_dev *dev;
+ struct net_device *netdev;
+ int err;
+
+ dev = kzalloc_obj(struct mlx5_nodnic_core_dev, GFP_KERNEL);
+ if (!dev)
+ return -ENOMEM;
+
+ dev->device = &pdev->dev;
+ dev->pdev = pdev;
+ dev->event_irqn = -1;
+
+ err = mlx5_nodnic_pci_init(dev, pdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_pci_init failed with error code %d\n",
+ err);
+ goto err;
+ }
+
+ err = mlx5_nodnic_dev_init(dev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_dev_init failed with error code %d\n",
+ err);
+ goto err_pci_cleanup;
+ }
+
+ err = mlx5_nodnic_port_init(dev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_port_init failed with error code %d\n",
+ err);
+ goto err_dev_cleanup;
+ }
+
+ netdev = mlx5_nodnic_create_netdev(dev);
+ if (!netdev) {
+ err = -ENOMEM;
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_create_netdev failed with error code %d\n",
+ err);
+ goto err_dev_cleanup;
+ }
+
+ mlx5_nodnic_build_netdev(netdev);
+
+ err = mlx5_nodnic_event_irq_setup(dev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "mlx5_nodnic_event_irq_setup failed with error code %d\n",
+ err);
+ goto err_netdev_cleanup;
+ }
+
+ err = register_netdev(netdev);
+ if (err) {
+ mlx5_nodnic_core_err(dev,
+ "register_netdev failed with error code %d\n",
+ err);
+ goto err_irq_cleanup;
+ }
+ dev->netdev_registered = true;
+
+ dev->state = NODNIC_DEVICE_STATE_UP;
+
+ pci_save_state(pdev);
+
+ return 0;
+
+err_irq_cleanup:
+ mlx5_nodnic_event_irq_cleanup(dev);
+err_netdev_cleanup:
+ mlx5_nodnic_cleanup_netdev(dev);
+err_dev_cleanup:
+ mlx5_nodnic_dev_cleanup(dev);
+err_pci_cleanup:
+ mlx5_nodnic_pci_close(dev);
+err:
+ kfree(dev);
+ return err;
+}
+
+static void mlx5_nodnic_remove_one(struct pci_dev *pdev)
+{
+ struct mlx5_nodnic_core_dev *dev = pci_get_drvdata(pdev);
+
+ if (!dev)
+ return;
+
+ mlx5_nodnic_event_irq_cleanup(dev);
+ mlx5_nodnic_cleanup_netdev(dev);
+ mlx5_nodnic_dev_cleanup(dev);
+ mlx5_nodnic_pci_close(dev);
+ kfree(dev);
+}
+
+static const struct pci_device_id mlx5_nodnic_core_pci_table[] = {
+ { PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField-4 nodnic rshim PF */
+ { }
+};
+
+MODULE_DEVICE_TABLE(pci, mlx5_nodnic_core_pci_table);
+
+static struct pci_driver mlx5_nodnic_core_driver = {
+ .name = KBUILD_MODNAME,
+ .id_table = mlx5_nodnic_core_pci_table,
+ .probe = mlx5_nodnic_probe_one,
+ .remove = mlx5_nodnic_remove_one,
+};
+
+static int __init mlx5_nodnic_init(void)
+{
+ return pci_register_driver(&mlx5_nodnic_core_driver);
+}
+
+static void __exit mlx5_nodnic_cleanup(void)
+{
+ pci_unregister_driver(&mlx5_nodnic_core_driver);
+}
+
+module_init(mlx5_nodnic_init);
+module_exit(mlx5_nodnic_cleanup);
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
new file mode 100644
index 000000000000..2fcae95988d8
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#ifndef __MLX5_NODNIC_H__
+#define __MLX5_NODNIC_H__
+
+#include <linux/mlx5/device.h>
+#include <linux/pci.h>
+#include <linux/sched.h>
+
+struct mlx5_nodnic_priv;
+
+#define mlx5_nodnic_core_dbg(__dev, format, ...) \
+ dev_dbg((__dev)->device, "%s:%d:(pid %d): " format, \
+ __func__, __LINE__, current->pid, \
+ ##__VA_ARGS__)
+
+#define mlx5_nodnic_core_err(__dev, format, ...) \
+ dev_err((__dev)->device, "%s:%d:(pid %d): " format, \
+ __func__, __LINE__, current->pid, \
+ ##__VA_ARGS__)
+
+#define mlx5_nodnic_core_warn(__dev, format, ...) \
+ dev_warn((__dev)->device, "%s:%d:(pid %d): " format, \
+ __func__, __LINE__, current->pid, \
+ ##__VA_ARGS__)
+
+enum {
+ MLX5_NODNIC_PORT_STATE_DOWN,
+ MLX5_NODNIC_PORT_STATE_INITIALIZE,
+ MLX5_NODNIC_PORT_STATE_ARMED,
+ MLX5_NODNIC_PORT_STATE_ACTIVE,
+};
+
+enum mlx5_nodnic_pci_status {
+ MLX5_NODNIC_PCI_STATUS_DISABLED,
+ MLX5_NODNIC_PCI_STATUS_ENABLED,
+};
+
+enum mlx5_nodnic_device_state {
+ NODNIC_DEVICE_STATE_UP = 1,
+ NODNIC_DEVICE_STATE_INTERNAL_ERROR,
+};
+
+enum mlx5_nodnic_msix {
+ MLX5_NODNIC_DATA_MSIX,
+ MLX5_NODNIC_EVENT_MSIX,
+ MLX5_NODNIC_NUM_MSIX,
+};
+
+struct mlx5_nodnic_vsc_ctx;
+
+struct mlx5_nodnic_core_dev {
+ struct mlx5_nodnic_priv *priv;
+ struct device *device;
+ struct pci_dev *pdev;
+ bool netdev_registered;
+
+ /* sync pci state */
+ struct mutex pci_status_mutex;
+ enum mlx5_nodnic_pci_status pci_status;
+
+ struct mlx5_init_seg __iomem *iseg;
+ phys_addr_t bar_addr;
+ struct mlx5_nodnic_vsc_ctx *vsc_ctx;
+ void __iomem *uar_base;
+
+ u8 log_working_buffer_size;
+ u8 log_max_ring_size;
+ u8 log_uar_page_size;
+ u32 send_ring0_uar_index;
+
+ u8 mac_address[6];
+ u32 lkey;
+
+ int event_irqn;
+
+ enum mlx5_nodnic_device_state state;
+};
+
+void mlx5_nodnic_start_health_poll(struct mlx5_nodnic_core_dev *dev);
+void mlx5_nodnic_stop_health_poll(struct mlx5_nodnic_core_dev *dev);
+
+/*
+ * VSC-gated helpers: the caller must hold the VSC context across these calls.
+ */
+int mlx5_nodnic_open_rq(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev);
+void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_get_fw_initializing(struct mlx5_nodnic_core_dev *dev,
+ u8 *initializing);
+int mlx5_nodnic_set_nic_interface(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_check_supported(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_write_nic_interface(struct mlx5_nodnic_core_dev *dev,
+ int interface);
+int mlx5_nodnic_read_config(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_validate_port_link_type(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_read_mac_address(struct mlx5_nodnic_core_dev *dev);
+
+/* end of VSC-gated helpers */
+
+#endif /* __MLX5_NODNIC_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h
new file mode 100644
index 000000000000..18dc8f326def
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h
@@ -0,0 +1,306 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#ifndef __MLX5_IFC_NODNIC_H__
+#define __MLX5_IFC_NODNIC_H__
+
+#include <linux/mlx5/device.h>
+#include <linux/types.h>
+
+enum {
+ MLX5_NODNIC_ISEG_NIC_INTERFACE_FULL_DRIVER,
+ MLX5_NODNIC_ISEG_NIC_INTERFACE_DISABLED,
+ MLX5_NODNIC_ISEG_NIC_INTERFACE_NO_DRAM_NIC,
+ MLX5_NODNIC_ISEG_NIC_INTERFACE_SW_RESET = 0x7,
+};
+
+enum {
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FW_INTERNAL_ERR = 0x1,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_DEAD_IRISC = 0x7,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_HW_FATAL_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FW_CRC_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_FETCH_PCI_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_PAGE_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ASYNCHRONOUS_EQ_BUF_OVERRUN,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_EQ_IN_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_EQ_INV,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FFSER_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_HIGH_TEMP_ERR,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_PCI_POISONED_ERR = 0x12,
+ MLX5_NODNIC_ISEG_HEALTH_SYNDROME_TRUST_LOCKDOWN_ERR,
+};
+
+/* ISEG */
+#define MLX5_NODNIC_ISEG_NIC_INTERFACE MLX5_BYTE_OFF(nodnic_iseg, cmdq_addr_l)
+#define MLX5_NODNIC_ISEG_INITIALIZING \
+ MLX5_BYTE_OFF(nodnic_iseg, initializing_word)
+#define MLX5_NODNIC_ISEG_NO_DRAM_NIC_OFFSET \
+ MLX5_BYTE_OFF(nodnic_iseg, no_dram_nic_offset)
+
+/* General configuration */
+#define MLX5_NODNIC_GENERAL_CONFIG_CAPS MLX5_BYTE_OFF(nodnic_gen_cfg, caps)
+#define MLX5_NODNIC_GENERAL_CONFIG_LOG_MAX_RING_SIZE \
+ MLX5_BYTE_OFF(nodnic_gen_cfg, log_max_ring_size)
+#define MLX5_NODNIC_GENERAL_CONFIG_LKEY MLX5_BYTE_OFF(nodnic_gen_cfg, lkey)
+#define MLX5_NODNIC_GENERAL_CONFIG_CQE_FORMAT \
+ MLX5_BYTE_OFF(nodnic_gen_cfg, cqe_format)
+#define MLX5_NODNIC_GENERAL_CONFIG_FEATURE_CAPS \
+ MLX5_BYTE_OFF(nodnic_gen_cfg, feature_caps)
+#define MLX5_NODNIC_GENERAL_CONFIG_LOG_UAR_PAGE_SIZE \
+ MLX5_BYTE_OFF(nodnic_gen_cfg, log_uar_page_size)
+
+/* Port */
+#define MLX5_NODNIC_PORT_OFFSET \
+ MLX5_BYTE_OFF(nodnic_config_seg, port)
+#define MLX5_NODNIC_PORT_FIELD_OFFSET(field) \
+ (MLX5_NODNIC_PORT_OFFSET + MLX5_BYTE_OFF(nodnic_port_settings, field))
+
+#define MLX5_NODNIC_PORT_EVENT MLX5_NODNIC_PORT_FIELD_OFFSET(event)
+#define MLX5_NODNIC_RECEIVE_RING_OFFSET \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(receive_ring0)
+#define MLX5_NODNIC_SEND_RING_OFFSET MLX5_NODNIC_PORT_FIELD_OFFSET(send_ring0)
+#define MLX5_NODNIC_PORT_NETWORK MLX5_NODNIC_PORT_FIELD_OFFSET(network)
+#define MLX5_NODNIC_PORT_MAC_ADDR_H MLX5_NODNIC_PORT_FIELD_OFFSET(mac_h)
+#define MLX5_NODNIC_PORT_MAC_ADDR_L MLX5_NODNIC_PORT_FIELD_OFFSET(mac_l)
+#define MLX5_NODNIC_PORT_CQ_ADDR_H MLX5_NODNIC_PORT_FIELD_OFFSET(cq_addr_h)
+#define MLX5_NODNIC_PORT_CQ_ADDR_L MLX5_NODNIC_PORT_FIELD_OFFSET(cq_addr_l)
+#define MLX5_NODNIC_PORT_WORK_BUF_ADDR_H \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(working_buffer_addr_h)
+#define MLX5_NODNIC_PORT_WORK_BUF_ADDR_L \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(working_buffer_addr_l)
+#define MLX5_NODNIC_PORT_ARM_CQ MLX5_NODNIC_PORT_FIELD_OFFSET(arm_cq)
+#define MLX5_NODNIC_PORT_SEND_RING0_UAR_INDEX \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(send_ring0_uar_index)
+#define MLX5_NODNIC_CQ_DBR_ADDR_H \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(cq_dbr_addr_h)
+#define MLX5_NODNIC_CQ_DBR_ADDR_L \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(cq_dbr_addr_l)
+#define MLX5_NODNIC_CQ_N \
+ MLX5_NODNIC_PORT_FIELD_OFFSET(cqn)
+
+/* Port ring */
+#define MLX5_NODNIC_RING_ADDR_H MLX5_BYTE_OFF(nodnic_ring_config, q_addr_h)
+#define MLX5_NODNIC_RING_ADDR_L MLX5_BYTE_OFF(nodnic_ring_config, q_addr_l)
+#define MLX5_NODNIC_RING_QUEUE_NUMBER \
+ MLX5_BYTE_OFF(nodnic_ring_config, q_number)
+#define MLX5_NODNIC_RING_DBR_ADDR_H \
+ MLX5_BYTE_OFF(nodnic_ring_config, dbr_addr_h)
+#define MLX5_NODNIC_RING_DBR_ADDR_L \
+ MLX5_BYTE_OFF(nodnic_ring_config, dbr_addr_l)
+
+/* mlx5_nodnic configurations are read and written from VSC
+ * in a dword granularity
+ */
+
+struct mlx5_ifc_nodnic_iseg_cmdq_addr_l_bits {
+ u8 cmdq_addr_l[0x14];
+ u8 reserved_at_14[0x1];
+ u8 nic_interface[0x3];
+ u8 log_cmdq_size[0x4];
+ u8 log_cmdq_stride[0x4];
+};
+
+struct mlx5_ifc_nodnic_iseg_initializing_word_bits {
+ u8 initializing[0x1];
+ u8 nic_interface_supported[0x7];
+ u8 embedded_cpu[0x1];
+ u8 driver_reset_ack[0x1];
+ u8 recovery[0x1];
+ u8 pre_boot_bios_hold[0x1];
+ u8 initializing_state[0x4];
+ u8 reset_state_machine[0x4];
+ u8 reserved_at_14[0x1];
+ u8 pre_boot_action[0x3];
+ u8 reserved_at_18[0x8];
+};
+
+struct mlx5_ifc_nodnic_iseg_health_buffer_bits {
+ u8 reserved_at_0[0x100];
+ u8 assert_existptr[0x20];
+ u8 assert_callra[0x20];
+ u8 reserved_at_140[0x20];
+ u8 time[0x20];
+ u8 fw_version[0x20];
+ u8 hw_id[0x20];
+ u8 rfr[0x1];
+ u8 crr[0x1];
+ u8 reserved_at_1c2[0x2];
+ u8 valid[0x1];
+ u8 severity[0x3];
+ u8 reserved_at_1c8[0x18];
+ u8 irisc_index[0x8];
+ u8 synd[0x8];
+ u8 ext_synd[0x10];
+};
+
+struct mlx5_ifc_nodnic_iseg_bits {
+ u8 fw_rev[0x20];
+ u8 cmdif_rev[0x20];
+ u8 reserved_at_40[0x40];
+ u8 cmdq_addr_h[0x20];
+ struct mlx5_ifc_nodnic_iseg_cmdq_addr_l_bits cmdq_addr_l;
+ u8 command_doorbell_vector[0x20];
+ u8 reserved_at_e0[0xefe];
+ u8 traffic_state[0x2];
+ struct mlx5_ifc_nodnic_iseg_initializing_word_bits initializing_word;
+ struct mlx5_ifc_nodnic_iseg_health_buffer_bits health_buffer;
+ u8 no_dram_nic_offset[0x20];
+ u8 reserved_at_1220[0x6e60];
+};
+
+struct mlx5_ifc_nodnic_q_addr_l_bits {
+ u8 q_addr_l[0x14];
+ u8 reserved_at_14[0x6];
+ u8 log_size[0x6]; /* SQ/RQ: in bytes; CQ: in entries */
+};
+
+struct mlx5_ifc_nodnic_ring_db_reg_bits {
+ u8 reserved_at_0[0x8];
+ u8 ring_pi[0x10];
+ u8 reserved_at_18[0x8];
+};
+
+struct mlx5_ifc_nodnic_ring_q_number_bits {
+ u8 reserved_at_0[0x8];
+ u8 queue_number[0x18];
+};
+
+struct mlx5_ifc_nodnic_ring_dbr_addr_l_bits {
+ u8 db_record_addr_l[0x1e];
+ u8 reserved_at_1e[0x2];
+};
+
+struct mlx5_ifc_nodnic_ring_config_bits {
+ u8 q_addr_h[0x20];
+ struct mlx5_ifc_nodnic_q_addr_l_bits q_addr_l;
+ struct mlx5_ifc_nodnic_ring_db_reg_bits db_reg;
+ struct mlx5_ifc_nodnic_ring_q_number_bits q_number;
+ u8 q_key[0x20];
+ u8 pkey[0x20];
+ u8 dbr_addr_h[0x20];
+ u8 dbr_addr_l[0x20];
+};
+
+struct mlx5_ifc_nodnic_port_event_bits {
+ u8 driver_reset_needed[0x1];
+ u8 port_management_change[0x1];
+ u8 reserved_at_2[0x19];
+ u8 link_type[0x1];
+ u8 port_state[0x4];
+};
+
+struct mlx5_ifc_nodnic_port_network_bits {
+ u8 network_en[0x1];
+ u8 dma_en[0x1];
+ u8 promisc_en[0x1];
+ u8 promisc_multicast_en[0x1];
+ u8 vlan_stripping_en[0x1];
+ u8 protocol_filter_ip_ver[0x1];
+ u8 data_msix_en[0x1];
+ u8 event_msix_en[0x1];
+ u8 reserved_at_8[0x8];
+ u8 protocol_filter_en[0x8];
+ u8 reserved_at_18[0x3];
+ u8 receive_filter_en[0x5];
+};
+
+struct mlx5_ifc_nodnic_port_mac_h_bits {
+ u8 reserved_at_0[0x10];
+ u8 mac_h[0x10];
+};
+
+struct mlx5_ifc_nodnic_port_arm_cq_bits {
+ u8 cq_ci[0x18];
+ u8 reserved_at_18[0x8];
+};
+
+struct mlx5_ifc_nodnic_cqn_bits {
+ u8 reserved_at_0[0x8];
+ u8 cq_n[0x18];
+};
+
+struct mlx5_ifc_nodnic_port_settings_bits {
+ struct mlx5_ifc_nodnic_port_event_bits event;
+ struct mlx5_ifc_nodnic_port_network_bits network;
+ struct mlx5_ifc_nodnic_port_mac_h_bits mac_h;
+ u8 mac_l[0x20];
+ u8 mac_filters[0x200];
+ u8 gid[0x80];
+ u8 reserved_at_300[0x20];
+ u8 sm_sl_lid[0x20];
+ u8 cq_addr_h[0x20];
+ struct mlx5_ifc_nodnic_q_addr_l_bits cq_addr_l;
+ u8 working_buffer_addr_h[0x20];
+ u8 working_buffer_addr_l[0x20];
+ struct mlx5_ifc_nodnic_port_arm_cq_bits arm_cq;
+ u8 pkey[0x20];
+ struct mlx5_ifc_nodnic_ring_config_bits send_ring0;
+ u8 reserved_at_500[0x100];
+ struct mlx5_ifc_nodnic_ring_config_bits receive_ring0;
+ u8 reserved_at_700[0x100];
+ u8 protocol_filter_tftp_port[0x20];
+ u8 reserved_at_820[0x20];
+ u8 send_ring0_uar_index[0x20];
+ u8 send_ring1_uar_index[0x20];
+ u8 cq_dbr_addr_h[0x20];
+ u8 cq_dbr_addr_l[0x20];
+ struct mlx5_ifc_nodnic_cqn_bits cqn;
+ u8 reserved_at_8e0[0x320];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_caps_bits {
+ u8 revision[0x8];
+ u8 hardware_format[0x8];
+ u8 support_receive_filter[0x1];
+ u8 support_promisc_filter[0x1];
+ u8 support_promisc_multicast[0x1];
+ u8 support_protocol_filter[0x1];
+ u8 reserved_at_14[0x1];
+ u8 log_working_buffer_size[0x3]; /* given in kB */
+ u8 log_pkey_table_size[0x4]; /* IB */
+ u8 reserved_at_1c[0x4];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_log_max_ring_size_bits {
+ u8 reserved_at_0[0x2];
+ u8 log_max_ring_size[0x6]; /* given in bytes */
+ u8 reserved_at_8[0x18];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_cqe_format_bits {
+ u8 cqe_format[0x4];
+ u8 reserved_at_4[0x1c];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_feature_caps_bits {
+ u8 reserved_at_0[0x2];
+ u8 support_uar_tx_doorbell[0x1];
+ u8 support_bar_dma_en[0x1];
+ u8 support_bar_cq_ctrl[0x1];
+ u8 vlan_stripping_supported[0x1];
+ u8 data_msix_support[0x1];
+ u8 event_msix_support[0x1];
+ u8 reserved_at_8[0x18];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_log_uar_page_size_bits {
+ u8 reserved_at_0[0x18];
+ u8 log_uar_page_size[0x8];
+};
+
+struct mlx5_ifc_nodnic_gen_cfg_bits {
+ struct mlx5_ifc_nodnic_gen_cfg_caps_bits caps;
+ struct mlx5_ifc_nodnic_gen_cfg_log_max_ring_size_bits log_max_ring_size;
+ u8 lkey[0x20];
+ struct mlx5_ifc_nodnic_gen_cfg_cqe_format_bits cqe_format;
+ u8 reserved_at_80[3][0x20];
+ struct mlx5_ifc_nodnic_gen_cfg_feature_caps_bits feature_caps;
+ struct mlx5_ifc_nodnic_gen_cfg_log_uar_page_size_bits log_uar_page_size;
+};
+
+struct mlx5_ifc_nodnic_config_seg_bits {
+ struct mlx5_ifc_nodnic_gen_cfg_bits general;
+ u8 reserved_at_120[55][0x20];
+ struct mlx5_ifc_nodnic_port_settings_bits port;
+};
+
+#endif /* __MLX5_IFC_NODNIC_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c
new file mode 100644
index 000000000000..6312380e0e7e
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c
@@ -0,0 +1,347 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+
+#include "nodnic_ifc.h"
+#include "nodnic_pci_vsc.h"
+
+struct mlx5_nodnic_vsc_ctx {
+ struct pci_dev *pdev;
+ u32 addr; /* VSC init segment address */
+ u32 offset; /* NODNIC config offset */
+};
+
+#define VSC_MAX_RETRIES 2048
+
+enum {
+ MLX5_NODNIC_VSC_CTRL_OFFSET = 0x4,
+ MLX5_NODNIC_VSC_COUNTER_OFFSET = 0x8,
+ MLX5_NODNIC_VSC_SEM_OFFSET = 0xc,
+ MLX5_NODNIC_VSC_ADDR_OFFSET = 0x10,
+ MLX5_NODNIC_VSC_DATA_OFFSET = 0x14,
+};
+
+/* MLX5_NODNIC_VSC_CTRL_OFFSET fields */
+#define MLX5_NODNIC_VSC_CTRL_SPACE GENMASK(15, 0)
+#define MLX5_NODNIC_VSC_CTRL_STATUS GENMASK(31, 29)
+
+/* MLX5_NODNIC_VSC_ADDR_OFFSET fields */
+#define MLX5_NODNIC_VSC_ADDR_SYND BIT(30)
+#define MLX5_NODNIC_VSC_ADDR_FLAG BIT(31)
+
+static int mlx5_nodnic_vsc_pci_read(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int offset, u32 *val)
+{
+ int ret = pci_read_config_dword(ctx->pdev, ctx->addr + offset, val);
+
+ return pcibios_err_to_errno(ret);
+}
+
+static int mlx5_nodnic_vsc_pci_write(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int offset, u32 val)
+{
+ int ret = pci_write_config_dword(ctx->pdev, ctx->addr + offset, val);
+
+ return pcibios_err_to_errno(ret);
+}
+
+struct mlx5_nodnic_vsc_ctx *mlx5_nodnic_vsc_init(struct pci_dev *pdev)
+{
+ struct mlx5_nodnic_vsc_ctx *ctx;
+
+ ctx = kzalloc_obj(struct mlx5_nodnic_vsc_ctx, GFP_KERNEL);
+ if (!ctx)
+ return NULL;
+
+ ctx->pdev = pdev;
+ ctx->addr = pci_find_capability(ctx->pdev, PCI_CAP_ID_VNDR);
+ if (!ctx->addr) {
+ dev_err(&ctx->pdev->dev,
+ "failed to get valid vendor specific ID\n");
+ kfree(ctx);
+ return NULL;
+ }
+
+ return ctx;
+}
+
+void mlx5_nodnic_vsc_cleanup(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ kfree(ctx);
+}
+
+int mlx5_nodnic_vsc_read_offset(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ u32 offset;
+ int err;
+
+ err = mlx5_nodnic_vsc_read_cpu32(ctx,
+ MLX5_NODNIC_ISEG_NO_DRAM_NIC_OFFSET,
+ &offset);
+ if (err) {
+ dev_warn(&ctx->pdev->dev,
+ "failed to read no_dram_nic_offset err %d\n", err);
+ return err;
+ }
+
+ ctx->offset = offset;
+ return 0;
+}
+
+static int mlx5_nodnic_vsc_gw_lock(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ struct pci_dev *pdev = ctx->pdev;
+ u32 lock_val, counter = 0;
+ int err, retries = 0;
+
+ pci_cfg_access_lock(pdev);
+
+ do {
+ if (retries > VSC_MAX_RETRIES) {
+ err = -EBUSY;
+ goto pci_unlock;
+ }
+ if (pci_channel_offline(pdev)) {
+ err = -EACCES;
+ goto pci_unlock;
+ }
+
+ /* Check if semaphore is already locked */
+ err = mlx5_nodnic_vsc_pci_read(ctx, MLX5_NODNIC_VSC_SEM_OFFSET,
+ &lock_val);
+ if (err)
+ goto pci_unlock;
+
+ if (lock_val) {
+ retries++;
+ usleep_range(1000, 2000);
+ continue;
+ }
+
+ /* Read and write counter value, if written value is
+ * the same, semaphore was acquired successfully.
+ */
+ err = mlx5_nodnic_vsc_pci_read(ctx,
+ MLX5_NODNIC_VSC_COUNTER_OFFSET,
+ &counter);
+ if (err)
+ goto pci_unlock;
+
+ err = mlx5_nodnic_vsc_pci_write(ctx, MLX5_NODNIC_VSC_SEM_OFFSET,
+ counter);
+ if (err)
+ goto pci_unlock;
+
+ err = mlx5_nodnic_vsc_pci_read(ctx, MLX5_NODNIC_VSC_SEM_OFFSET,
+ &lock_val);
+ if (err)
+ goto pci_unlock;
+
+ retries++;
+ } while (counter != lock_val);
+
+ return 0;
+
+pci_unlock:
+ pci_cfg_access_unlock(pdev);
+ return err;
+}
+
+static int mlx5_nodnic_vsc_gw_unlock(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_pci_write(ctx, MLX5_NODNIC_VSC_SEM_OFFSET,
+ MLX5_NODNIC_VSC_UNLOCK);
+ pci_cfg_access_unlock(ctx->pdev);
+
+ return err;
+}
+
+static int
+mlx5_nodnic_vsc_gw_set_space(struct mlx5_nodnic_vsc_ctx *ctx, u16 space)
+{
+ u32 val;
+ int err;
+
+ err = mlx5_nodnic_vsc_pci_read(ctx, MLX5_NODNIC_VSC_CTRL_OFFSET, &val);
+ if (err)
+ return err;
+
+ val = u32_replace_bits(val, space, MLX5_NODNIC_VSC_CTRL_SPACE);
+ err = mlx5_nodnic_vsc_pci_write(ctx, MLX5_NODNIC_VSC_CTRL_OFFSET, val);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_vsc_pci_read(ctx, MLX5_NODNIC_VSC_CTRL_OFFSET, &val);
+ if (err)
+ return err;
+
+ if (!FIELD_GET(MLX5_NODNIC_VSC_CTRL_STATUS, val))
+ return -EINVAL;
+
+ return 0;
+}
+
+int mlx5_nodnic_vsc_context_acquire(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_gw_lock(ctx);
+ if (err) {
+ dev_warn(&ctx->pdev->dev, "failed to lock vsc, err %d\n", err);
+ return err;
+ }
+
+ err = mlx5_nodnic_vsc_gw_set_space(ctx, MLX5_NODNIC_VSC_SPACE_NODNIC);
+ if (err) {
+ dev_warn(&ctx->pdev->dev,
+ "failed to set vsc space, err %d\n", err);
+ mlx5_nodnic_vsc_gw_unlock(ctx);
+ return err;
+ }
+
+ return err;
+}
+
+void mlx5_nodnic_vsc_context_release(struct mlx5_nodnic_vsc_ctx *ctx)
+{
+ mlx5_nodnic_vsc_gw_unlock(ctx);
+}
+
+static int mlx5_nodnic_vsc_wait_on_flag(struct mlx5_nodnic_vsc_ctx *ctx,
+ u8 expected_val)
+{
+ int err, retries = 0;
+ u32 flag;
+
+ do {
+ if (retries > VSC_MAX_RETRIES)
+ return -EBUSY;
+
+ err = mlx5_nodnic_vsc_pci_read(ctx,
+ MLX5_NODNIC_VSC_ADDR_OFFSET,
+ &flag);
+ if (err)
+ return err;
+ flag = FIELD_GET(MLX5_NODNIC_VSC_ADDR_FLAG, flag);
+ retries++;
+
+ if ((retries & 0xf) == 0)
+ usleep_range(1000, 2000);
+
+ } while (flag != expected_val);
+
+ return 0;
+}
+
+static int mlx5_nodnic_vsc_read(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 *data)
+{
+ int err;
+
+ /* Write the address with the flag and syndrome bits cleared */
+ address &= ~(MLX5_NODNIC_VSC_ADDR_FLAG | MLX5_NODNIC_VSC_ADDR_SYND);
+
+ err = mlx5_nodnic_vsc_pci_write(ctx,
+ MLX5_NODNIC_VSC_ADDR_OFFSET,
+ address);
+ if (err)
+ goto out;
+
+ err = mlx5_nodnic_vsc_wait_on_flag(ctx, 1);
+ if (err)
+ goto out;
+
+ err = mlx5_nodnic_vsc_pci_read(ctx, MLX5_NODNIC_VSC_DATA_OFFSET, data);
+out:
+ return err;
+}
+
+static int mlx5_nodnic_vsc_write(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 data)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_pci_write(ctx, MLX5_NODNIC_VSC_DATA_OFFSET, data);
+ if (err)
+ goto out;
+
+ /* Write the address with the flag bit set and the syndrome bit
+ * cleared.
+ */
+ address &= ~(MLX5_NODNIC_VSC_ADDR_FLAG | MLX5_NODNIC_VSC_ADDR_SYND);
+ address |= MLX5_NODNIC_VSC_ADDR_FLAG;
+
+ err = mlx5_nodnic_vsc_pci_write(ctx,
+ MLX5_NODNIC_VSC_ADDR_OFFSET,
+ address);
+ if (err)
+ return err;
+
+ /* Wait for the hardware to clear the flag to 0x0,
+ * indicating the write operation has completed.
+ */
+ err = mlx5_nodnic_vsc_wait_on_flag(ctx, 0);
+
+out:
+ return err;
+}
+
+/* The PCI config space accessors already convert between the little-endian
+ * bus and CPU byte order. The *_cpu32 accessors hold the dword value in CPU
+ * byte order. The *_be32 accessors hold it in the big-endian layout used by
+ * MLX5_GET() and MLX5_SET().
+ */
+int mlx5_nodnic_vsc_read_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 *data)
+{
+ u32 val;
+ int err;
+
+ err = mlx5_nodnic_vsc_read(ctx, address, &val);
+ if (!err)
+ *data = cpu_to_be32(val);
+
+ return err;
+}
+
+int mlx5_nodnic_vsc_read_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 *data)
+{
+ return mlx5_nodnic_vsc_read(ctx, address, data);
+}
+
+int mlx5_nodnic_vsc_write_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 data)
+{
+ return mlx5_nodnic_vsc_write(ctx, address, be32_to_cpu(data));
+}
+
+int mlx5_nodnic_vsc_cfg_read_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 *data)
+{
+ return mlx5_nodnic_vsc_read_be32(ctx, ctx->offset + address, data);
+}
+
+int mlx5_nodnic_vsc_cfg_write_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 data)
+{
+ return mlx5_nodnic_vsc_write_be32(ctx, ctx->offset + address, data);
+}
+
+int mlx5_nodnic_vsc_cfg_read_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 *data)
+{
+ return mlx5_nodnic_vsc_read(ctx, ctx->offset + address, data);
+}
+
+int mlx5_nodnic_vsc_cfg_write_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 data)
+{
+ return mlx5_nodnic_vsc_write(ctx, ctx->offset + address, data);
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h
new file mode 100644
index 000000000000..b56d7abc4a90
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#ifndef __MLX5_NODNIC_PCI_VSC_H__
+#define __MLX5_NODNIC_PCI_VSC_H__
+
+#include <linux/pci.h>
+#include <linux/types.h>
+
+struct mlx5_nodnic_vsc_ctx;
+
+enum mlx5_nodnic_vsc_state {
+ MLX5_NODNIC_VSC_UNLOCK,
+ MLX5_NODNIC_VSC_LOCK,
+};
+
+enum {
+ MLX5_NODNIC_VSC_SPACE_NODNIC = 0x4,
+};
+
+struct mlx5_nodnic_vsc_ctx *mlx5_nodnic_vsc_init(struct pci_dev *pdev);
+void mlx5_nodnic_vsc_cleanup(struct mlx5_nodnic_vsc_ctx *ctx);
+int mlx5_nodnic_vsc_read_offset(struct mlx5_nodnic_vsc_ctx *ctx);
+int mlx5_nodnic_vsc_context_acquire(struct mlx5_nodnic_vsc_ctx *ctx);
+void mlx5_nodnic_vsc_context_release(struct mlx5_nodnic_vsc_ctx *ctx);
+
+/* base address - init segment copy in VSC */
+int mlx5_nodnic_vsc_read_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 *data);
+int mlx5_nodnic_vsc_write_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 data);
+int mlx5_nodnic_vsc_read_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 *data);
+
+/* base address - nodnic configuration registers in VSC */
+int mlx5_nodnic_vsc_cfg_read_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 *data);
+int mlx5_nodnic_vsc_cfg_write_be32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, __be32 data);
+int mlx5_nodnic_vsc_cfg_read_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 *data);
+int mlx5_nodnic_vsc_cfg_write_cpu32(struct mlx5_nodnic_vsc_ctx *ctx,
+ unsigned int address, u32 data);
+
+#endif /* __MLX5_NODNIC_PCI_VSC_H__ */
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
@ 2026-12-03 20:57 ` Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics Tariq Toukan
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
From: Shahar Shitrit <shshitrit@nvidia.com>
Implement the TX and RX data paths for the mlx5_nodnic driver.
Add TX handling to build and post WQEs, DMA-map packets, ring the
BlueFlame doorbell, and process send completions. Handle SQ exhaustion
by stopping and waking the TX queue as needed.
Add page pool backed RX handling to allocate and post receive buffers,
process receive completions, build SKBs, and deliver packets through
NAPI/GRO.
Implement NAPI polling and CQE dispatch for TX and RX completions,
including RX WQE reposting and CQ re-arming.
Wire up ndo_start_xmit and ndo_features_check, and enable TX/RX
checksum offload support.
Signed-off-by: Shahar Shitrit <shshitrit@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/nodnic/Kconfig | 1 +
.../ethernet/mellanox/mlx5/nodnic/Makefile | 2 +-
.../net/ethernet/mellanox/mlx5/nodnic/en.c | 290 ++++++++++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/en.h | 41 +++
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 242 ++++++++++++++-
.../ethernet/mellanox/mlx5/nodnic/nodnic.h | 2 +-
.../net/ethernet/mellanox/mlx5/nodnic/rx.c | 169 ++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/rx.h | 25 ++
.../net/ethernet/mellanox/mlx5/nodnic/tx.c | 252 +++++++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/tx.h | 62 ++++
10 files changed, 1081 insertions(+), 5 deletions(-)
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig b/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
index 461750a9c97c..f53f68a98228 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig
@@ -4,6 +4,7 @@ config MLX5_NODNIC
tristate "Mellanox NODNIC core driver"
depends on PCI
depends on NETDEVICES && ETHERNET
+ select PAGE_POOL
help
This driver provides core support for Mellanox NODNIC (NO DRAM NIC)
devices. NODNIC is a lightweight network
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
index 4955f0427c79..25865d7244d8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
@@ -5,4 +5,4 @@
obj-$(CONFIG_MLX5_NODNIC) += mlx5_nodnic.o
-mlx5_nodnic-y := main.o en_cfg.o nodnic_pci_vsc.o
+mlx5_nodnic-y := main.o en.o en_cfg.o tx.o rx.o nodnic_pci_vsc.o
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
new file mode 100644
index 000000000000..6cbdfaf7cc01
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/interrupt.h>
+#include <linux/mlx5/cq.h>
+
+#include "en.h"
+#include "nodnic.h"
+#include "rx.h"
+#include "tx.h"
+
+#define MLX5_NODNIC_TX_CQ_POLL_BUDGET 128
+
+enum mlx5_nodnic_cqe_result {
+ MLX5_NODNIC_CQE_TX,
+ MLX5_NODNIC_CQE_RX,
+ MLX5_NODNIC_CQE_IGNORED,
+};
+
+static const char *mlx5_nodnic_cqe_err_syndrome_str(u8 syndrome)
+{
+ switch (syndrome) {
+ case MLX5_CQE_SYNDROME_LOCAL_LENGTH_ERR:
+ return "LOCAL_LENGTH_ERR";
+ case MLX5_CQE_SYNDROME_LOCAL_QP_OP_ERR:
+ return "LOCAL_QP_OP_ERR";
+ case MLX5_CQE_SYNDROME_LOCAL_PROT_ERR:
+ return "LOCAL_PROT_ERR";
+ case MLX5_CQE_SYNDROME_WR_FLUSH_ERR:
+ return "WR_FLUSH_ERR";
+ case MLX5_CQE_SYNDROME_MW_BIND_ERR:
+ return "MW_BIND_ERR";
+ case MLX5_CQE_SYNDROME_BAD_RESP_ERR:
+ return "BAD_RESP_ERR";
+ case MLX5_CQE_SYNDROME_LOCAL_ACCESS_ERR:
+ return "LOCAL_ACCESS_ERR";
+ case MLX5_CQE_SYNDROME_REMOTE_INVAL_REQ_ERR:
+ return "REMOTE_INVAL_REQ_ERR";
+ case MLX5_CQE_SYNDROME_REMOTE_ACCESS_ERR:
+ return "REMOTE_ACCESS_ERR";
+ case MLX5_CQE_SYNDROME_REMOTE_OP_ERR:
+ return "REMOTE_OP_ERR";
+ case MLX5_CQE_SYNDROME_TRANSPORT_RETRY_EXC_ERR:
+ return "TRANSPORT_RETRY_EXC_ERR";
+ case MLX5_CQE_SYNDROME_RNR_RETRY_EXC_ERR:
+ return "RNR_RETRY_EXC_ERR";
+ case MLX5_CQE_SYNDROME_REMOTE_ABORTED_ERR:
+ return "REMOTE_ABORTED_ERR";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static void mlx5_nodnic_handle_err_cqe(struct mlx5_nodnic_cq *cq,
+ struct mlx5_cqe64 *cqe64,
+ int napi_budget)
+{
+ struct mlx5_nodnic_priv *priv = container_of(cq,
+ struct mlx5_nodnic_priv,
+ cq);
+ struct mlx5_err_cqe *err_cqe = (struct mlx5_err_cqe *)cqe64;
+ u8 vendor_syndrome, syndrome;
+ const char *queue_type;
+ u16 wqe_counter;
+ u8 opcode;
+
+ opcode = err_cqe->op_own >> 4;
+ syndrome = err_cqe->syndrome;
+ vendor_syndrome = err_cqe->vendor_err_synd;
+ wqe_counter = be16_to_cpu(err_cqe->wqe_counter);
+
+ queue_type = (opcode == OPCODE_CQ_SEND_ERR) ? "SQ" : "RQ";
+
+ if (net_ratelimit()) {
+ netdev_err(priv->netdev,
+ "%s CQE error: syndrome=0x%02x (%s), vendor_syndrome=0x%02x, wqe_counter=%u, cq_ci=%d\n",
+ queue_type,
+ syndrome, mlx5_nodnic_cqe_err_syndrome_str(syndrome),
+ vendor_syndrome, wqe_counter, cq->cc);
+
+ print_hex_dump(KERN_ERR, "mlx5_nodnic err CQE: ",
+ DUMP_PREFIX_OFFSET, 16, 1, err_cqe,
+ sizeof(*err_cqe), false);
+ }
+
+ if (opcode == OPCODE_CQ_SEND_ERR) {
+ struct mlx5_nodnic_sq *sq = &priv->sq;
+ u16 sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
+
+ mlx5_nodnic_complete_send_wqe(sq, &sq->wqe_info[sq_pi],
+ napi_budget);
+ } else {
+ struct mlx5_nodnic_rq *rq = &priv->rq;
+ u16 ci = wqe_counter & (rq->ring.num_entries - 1);
+
+ mlx5_nodnic_release_rx_wqe(rq, ci);
+ }
+}
+
+static u32 mlx5_nodnic_cq_get_ci(struct mlx5_nodnic_cq *cq)
+{
+ return cq->cc & (cq->num_entries - 1);
+}
+
+static u8 mlx5_nodnic_cq_get_sw_ownership_val(struct mlx5_nodnic_cq *cq)
+{
+ return (cq->cc >> cq->log_num_entries) & 1;
+}
+
+static struct mlx5_cqe64 *mlx5_nodnic_cq_get_cqe(struct mlx5_nodnic_cq *cq)
+{
+ u8 cqe_ownership_bit, sw_ownership_val;
+ struct mlx5_cqe64 *cqe;
+ u32 ci;
+
+ ci = mlx5_nodnic_cq_get_ci(cq);
+ cqe = (struct mlx5_cqe64 *)cq->ring.wq + ci;
+
+ cqe_ownership_bit = cqe->op_own & MLX5_NODNIC_CQE_OWNER_MASK;
+ sw_ownership_val = mlx5_nodnic_cq_get_sw_ownership_val(cq);
+ if (cqe_ownership_bit != sw_ownership_val)
+ return NULL;
+
+ /* ensure cqe content is read after cqe ownership bit */
+ dma_rmb();
+
+ return cqe;
+}
+
+static u8 mlx5_nodnic_cq_get_opcode(struct mlx5_cqe64 *cqe)
+{
+ return cqe->op_own >> 4;
+}
+
+static bool mlx5_nodnic_cqe_is_rx(struct mlx5_cqe64 *cqe)
+{
+ u8 opcode = mlx5_nodnic_cq_get_opcode(cqe);
+
+ return opcode == OPCODE_CQ_RECV || opcode == OPCODE_CQ_RECV_ERR;
+}
+
+static enum mlx5_nodnic_cqe_result
+mlx5_nodnic_handle_cqe(struct mlx5_nodnic_cq *cq, struct mlx5_cqe64 *cqe,
+ int budget)
+{
+ struct net_device *netdev =
+ container_of(cq, struct mlx5_nodnic_priv, cq)->netdev;
+ u8 opcode = mlx5_nodnic_cq_get_opcode(cqe);
+ enum mlx5_nodnic_cqe_result result;
+
+ switch (opcode) {
+ case OPCODE_CQ_SEND:
+ mlx5_nodnic_handle_send_cqe(cq, cqe, budget);
+ result = MLX5_NODNIC_CQE_TX;
+ break;
+
+ case OPCODE_CQ_RECV:
+ mlx5_nodnic_handle_recv_cqe(cq, cqe);
+ result = MLX5_NODNIC_CQE_RX;
+ break;
+
+ case OPCODE_CQ_SEND_ERR:
+ mlx5_nodnic_handle_err_cqe(cq, cqe, budget);
+ result = MLX5_NODNIC_CQE_TX;
+ break;
+
+ case OPCODE_CQ_RECV_ERR:
+ mlx5_nodnic_handle_err_cqe(cq, cqe, budget);
+ result = MLX5_NODNIC_CQE_RX;
+ break;
+
+ case OPCODE_CQ_INVALID:
+ /* Invalid/stale CQE - silently consume it.
+ * This can occur after device restart when stale CQEs
+ * from the previous session are still in the hardware CQ.
+ */
+ result = MLX5_NODNIC_CQE_IGNORED;
+ break;
+
+ default:
+ netdev_err(netdev,
+ "unexpected CQE opcode 0x%02x at cq_ci=%d\n",
+ opcode, cq->cc);
+ result = MLX5_NODNIC_CQE_IGNORED;
+ break;
+ }
+
+ cq->cc++;
+ return result;
+}
+
+void mlx5_nodnic_arm_cq(struct mlx5_nodnic_cq *cq)
+{
+ struct mlx5_nodnic_core_dev *dev =
+ container_of(cq, struct mlx5_nodnic_priv, cq)->core_dev;
+ __be32 doorbell[2];
+ u32 sn, ci, val;
+
+ sn = cq->arm_sn & 3;
+ ci = cq->cc & 0xffffff;
+ val = sn << 28 | MLX5_CQ_DB_REQ_NOT | ci;
+
+ /* arm_db is the second dword of the CQ doorbell record */
+ cq->dbr.db[1] = cpu_to_be32(val);
+
+ /* Make sure that the doorbell record in host memory is
+ * written before ringing the doorbell via PCI MMIO.
+ */
+ wmb();
+
+ doorbell[0] = cpu_to_be32(val);
+ doorbell[1] = cpu_to_be32(cq->cqn);
+
+ mlx5_write64(doorbell, dev->uar_base + MLX5_CQ_DOORBELL);
+}
+
+int mlx5_nodnic_napi_poll(struct napi_struct *napi, int budget)
+{
+ struct mlx5_nodnic_cq *cq = container_of(napi,
+ struct mlx5_nodnic_cq, napi);
+ struct mlx5_nodnic_priv *priv = container_of(cq,
+ struct mlx5_nodnic_priv,
+ cq);
+ int tx_work_done = 0, rx_work_done = 0;
+ enum mlx5_nodnic_cqe_result result;
+ struct mlx5_cqe64 *cqe;
+
+ while (true) {
+ cqe = mlx5_nodnic_cq_get_cqe(cq);
+ if (!cqe)
+ break;
+
+ /* RX and TX share the CQ. With budget == 0 (netpoll) only TX
+ * completions may be processed, leave RX CQEs in place.
+ */
+ if (unlikely(!budget) && mlx5_nodnic_cqe_is_rx(cqe))
+ break;
+
+ result = mlx5_nodnic_handle_cqe(cq, cqe, budget);
+ switch (result) {
+ case MLX5_NODNIC_CQE_TX:
+ if (++tx_work_done >= MLX5_NODNIC_TX_CQ_POLL_BUDGET)
+ goto poll_done;
+ break;
+ case MLX5_NODNIC_CQE_RX:
+ if (++rx_work_done >= budget)
+ goto poll_done;
+ break;
+ case MLX5_NODNIC_CQE_IGNORED:
+ break;
+ }
+ }
+
+poll_done:
+ cq->dbr.db[0] = cpu_to_be32(cq->cc & 0xffffff);
+
+ /* The CQ consumer index must be visible to the device before send
+ * slots become reusable, otherwise a CQ overrun may occur.
+ */
+ dma_wmb();
+ mlx5_nodnic_sq_publish_cc(&priv->sq);
+
+ if (unlikely(!budget))
+ return 0;
+
+ if (!mlx5_nodnic_rq_post_wqes(priv))
+ return budget;
+
+ if (rx_work_done >= budget ||
+ tx_work_done >= MLX5_NODNIC_TX_CQ_POLL_BUDGET)
+ return budget;
+
+ if (napi_complete_done(napi, rx_work_done))
+ mlx5_nodnic_arm_cq(cq);
+
+ return rx_work_done;
+}
+
+netdev_features_t
+mlx5_nodnic_check_features(struct sk_buff *skb, struct net_device *netdev,
+ netdev_features_t features)
+{
+ features = vlan_features_check(skb, features);
+
+ /* Tunnel checksum offload isn't supported, use software checksum */
+ if (skb->encapsulation && (features & NETIF_F_CSUM_MASK))
+ return features & ~NETIF_F_CSUM_MASK;
+
+ return features;
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
index 90dc57695e1b..f2d52cfe91c0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
@@ -4,10 +4,12 @@
#ifndef __MLX5_NODNIC_EN_H__
#define __MLX5_NODNIC_EN_H__
+#include <net/page_pool/helpers.h>
#include <linux/if_vlan.h>
#include <linux/mlx5/device.h>
#include <linux/mutex.h>
#include <linux/netdevice.h>
+#include <linux/skbuff.h>
#include <linux/timer.h>
#include <linux/types.h>
@@ -16,16 +18,32 @@
#define MLX5_NODNIC_SQ_WQEBB_B 64
#define MLX5_NODNIC_RQ_STRIDE_BYTES 16
+#define MLX5_NODNIC_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
+#define MLX5_NODNIC_HW_MTU (ETH_DATA_LEN + MLX5_NODNIC_ETH_HARD_MTU)
+#define MLX5_NODNIC_SKB_HEADROOM_BYTES (NET_SKB_PAD + NET_IP_ALIGN)
+
enum {
MLX5_NODNIC_STATE_OPENED,
};
+enum {
+ MLX5_NODNIC_CQE_OWNER_MASK = 1,
+};
+
enum {
MLX5_NODNIC_RCV_DBR,
MLX5_NODNIC_SND_DBR,
MLX5_NODNIC_DBR_WORDS,
};
+enum mlx5_nodnic_cqe_opcode {
+ OPCODE_CQ_SEND,
+ OPCODE_CQ_RECV = 0x2,
+ OPCODE_CQ_SEND_ERR = 0xD,
+ OPCODE_CQ_RECV_ERR,
+ OPCODE_CQ_INVALID,
+};
+
struct mlx5_nodnic_ring {
void *wq;
dma_addr_t dma_handle;
@@ -35,17 +53,30 @@ struct mlx5_nodnic_ring {
u32 lkey;
};
+struct mlx5_nodnic_tx_wqe_info;
+
struct mlx5_nodnic_sq {
struct device *device;
struct net_device *netdev;
+ struct netdev_queue *txq;
struct mlx5_nodnic_ring ring;
+ struct mlx5_nodnic_tx_wqe_info *wqe_info;
+
u16 pc;
u16 cc;
+
+ /* Completions released in the current NAPI poll, not yet returned
+ * to xmit through cc. Touched by NAPI only.
+ */
+ u16 cc_pending_pkts;
+ u32 cc_pending_bytes;
};
struct mlx5_nodnic_rq {
+ struct page_pool *page_pool;
struct mlx5_nodnic_ring ring;
+ struct page **pages;
u16 pc;
u16 cc;
};
@@ -62,9 +93,13 @@ struct mlx5_nodnic_cq {
int num_entries;
int log_num_entries;
+ int irqn;
struct mlx5_nodnic_dbr dbr;
+ unsigned int arm_sn;
int cc;
+
+ struct napi_struct napi;
};
/* for FW use only */
@@ -94,4 +129,10 @@ void mlx5_nodnic_cleanup_netdev(struct mlx5_nodnic_core_dev *dev);
int mlx5_nodnic_open(struct net_device *netdev);
int mlx5_nodnic_close(struct net_device *netdev);
+void mlx5_nodnic_arm_cq(struct mlx5_nodnic_cq *cq);
+int mlx5_nodnic_napi_poll(struct napi_struct *napi, int budget);
+netdev_features_t mlx5_nodnic_check_features(struct sk_buff *skb,
+ struct net_device *netdev,
+ netdev_features_t features);
+
#endif /* __MLX5_NODNIC_EN_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
index 738722671090..b6adec5fc50d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
@@ -16,6 +16,8 @@
#include "nodnic_ifc.h"
#include "nodnic.h"
#include "nodnic_pci_vsc.h"
+#include "rx.h"
+#include "tx.h"
#define MLX5_NODNIC_CQ_INIT_CMD_SN cpu_to_be32(2 << 28)
@@ -354,6 +356,46 @@ static int mlx5_nodnic_read_cq_n(struct mlx5_nodnic_core_dev *dev)
return 0;
}
+static irqreturn_t mlx5_nodnic_cq_irq_handler(int irq, void *data)
+{
+ struct mlx5_nodnic_cq *cq = data;
+
+ cq->arm_sn++;
+ napi_schedule_irqoff(&cq->napi);
+
+ return IRQ_HANDLED;
+}
+
+static int mlx5_nodnic_setup_data_irq(struct mlx5_nodnic_cq *cq)
+{
+ struct mlx5_nodnic_priv *priv = container_of(cq,
+ struct mlx5_nodnic_priv,
+ cq);
+ struct net_device *netdev = priv->netdev;
+ int irqn, err;
+
+ irqn = pci_irq_vector(priv->core_dev->pdev, MLX5_NODNIC_DATA_MSIX);
+ if (irqn < 0) {
+ netdev_err(netdev, "pci_irq_vector failed: %d\n", irqn);
+ return irqn;
+ }
+
+ err = request_irq(irqn, mlx5_nodnic_cq_irq_handler, 0,
+ "mlx5_nodnic-cq", cq);
+ if (err) {
+ netdev_err(netdev, "request_irq failed\n");
+ return err;
+ }
+ cq->irqn = irqn;
+
+ return 0;
+}
+
+static void mlx5_nodnic_cleanup_data_irq(struct mlx5_nodnic_cq *cq)
+{
+ free_irq(cq->irqn, cq);
+}
+
int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
{
struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
@@ -383,6 +425,7 @@ int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev)
int err;
cq->cc = 0;
+ cq->arm_sn = 0;
err = mlx5_nodnic_init_cq_ring(dev);
if (err)
@@ -396,8 +439,19 @@ int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev)
if (err)
goto err_cleanup_dbr;
+ netif_napi_add_config_locked(dev->priv->netdev, &cq->napi,
+ mlx5_nodnic_napi_poll, 0);
+
+ err = mlx5_nodnic_setup_data_irq(cq);
+ if (err)
+ goto err_napi_del;
+
+ netif_napi_set_irq_locked(&cq->napi, cq->irqn);
+
return 0;
+err_napi_del:
+ netif_napi_del_locked(&cq->napi);
err_cleanup_dbr:
mlx5_nodnic_cleanup_cq_dbr(dev);
err_cleanup_ring:
@@ -410,6 +464,8 @@ static void mlx5_nodnic_close_cq(struct mlx5_nodnic_cq *cq)
struct mlx5_nodnic_core_dev *dev =
container_of(cq, struct mlx5_nodnic_priv, cq)->core_dev;
+ mlx5_nodnic_cleanup_data_irq(cq);
+ netif_napi_del_locked(&cq->napi);
mlx5_nodnic_cleanup_cq_dbr(dev);
mlx5_nodnic_cleanup_cq_ring(dev);
}
@@ -434,14 +490,28 @@ int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev)
ring->lkey = dev->lkey;
+ sq->wqe_info = kvcalloc(ring->num_entries,
+ sizeof(struct mlx5_nodnic_tx_wqe_info),
+ GFP_KERNEL);
+ if (!sq->wqe_info) {
+ err = -ENOMEM;
+ goto err_free_ring;
+ }
+
return 0;
+
+err_free_ring:
+ mlx5_nodnic_free_ring(dev, ring);
+ return err;
}
static void mlx5_nodnic_close_sq(struct mlx5_nodnic_core_dev *dev)
{
struct mlx5_nodnic_sq *sq = &dev->priv->sq;
+ mlx5_nodnic_sq_free_pending(sq);
mlx5_nodnic_free_ring(dev, &sq->ring);
+ kvfree(sq->wqe_info);
}
int mlx5_nodnic_open_rq(struct mlx5_nodnic_core_dev *dev)
@@ -580,6 +650,156 @@ void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
mutex_unlock(&priv->state_lock);
}
+static int mlx5_nodnic_activate_rq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv = dev->priv;
+ struct net_device *netdev = priv->netdev;
+ struct mlx5_nodnic_rq *rq = &priv->rq;
+ struct page_pool_params pp_params = {
+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
+ .order = 0,
+ .pool_size = rq->ring.num_entries,
+ .nid = dev_to_node(dev->device),
+ .dev = dev->device,
+ .napi = &priv->cq.napi,
+ .netdev = netdev,
+ .dma_dir = DMA_FROM_DEVICE,
+ .offset = MLX5_NODNIC_SKB_HEADROOM_BYTES,
+ .max_len = MLX5_NODNIC_HW_MTU,
+ };
+ int err;
+
+ rq->page_pool = page_pool_create(&pp_params);
+ if (IS_ERR(rq->page_pool)) {
+ err = PTR_ERR(rq->page_pool);
+ return err;
+ }
+
+ err = mlx5_nodnic_rq_alloc_pages(rq);
+ if (err) {
+ netdev_err(netdev, "failed to alloc RX pages, err=%d\n", err);
+ goto err_destroy_page_pool;
+ }
+
+ netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_RX, &priv->cq.napi);
+
+ return 0;
+
+err_destroy_page_pool:
+ page_pool_destroy(rq->page_pool);
+
+ return err;
+}
+
+static void mlx5_nodnic_deactivate_rq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct net_device *netdev = dev->priv->netdev;
+ struct mlx5_nodnic_rq *rq = &dev->priv->rq;
+
+ netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_RX, NULL);
+
+ mlx5_nodnic_rq_free_pages(rq);
+ page_pool_destroy(rq->page_pool);
+}
+
+static void mlx5_nodnic_tx_disable_queue(struct netdev_queue *txq)
+{
+ __netif_tx_lock_bh(txq);
+ netif_tx_stop_queue(txq);
+ __netif_tx_unlock_bh(txq);
+}
+
+static void mlx5_nodnic_activate_sq(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_priv *priv = dev->priv;
+ struct mlx5_nodnic_sq *sq = &priv->sq;
+
+ sq->txq = netdev_get_tx_queue(priv->netdev, 0);
+ netdev_tx_reset_queue(sq->txq);
+ netif_tx_start_queue(sq->txq);
+ netif_queue_set_napi(sq->netdev, 0, NETDEV_QUEUE_TYPE_TX,
+ &priv->cq.napi);
+}
+
+static void mlx5_nodnic_deactivate_sq(struct mlx5_nodnic_sq *sq)
+{
+ netif_queue_set_napi(sq->netdev, 0, NETDEV_QUEUE_TYPE_TX, NULL);
+ mlx5_nodnic_tx_disable_queue(sq->txq);
+}
+
+static void mlx5_nodnic_init_cqes_ownership(struct mlx5_nodnic_cq *cq)
+{
+ struct mlx5_cqe64 *cqe;
+
+ for (int i = 0; i < cq->num_entries; i++) {
+ cqe = (struct mlx5_cqe64 *)
+ ((u8 *)cq->ring.wq + i * MLX5_NODNIC_CQE_SIZE_B);
+ cqe->op_own = 0xf1;
+ }
+}
+
+/* If the port can't be disabled, stop the device from mastering the bus,
+ * so it can't DMA into the buffers that are about to be freed.
+ * Bus mastering is restored on the next open.
+ */
+static void mlx5_nodnic_quiesce_port(struct mlx5_nodnic_core_dev *dev)
+{
+ int err;
+
+ err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
+ if (!err) {
+ err = mlx5_nodnic_disable_port(dev);
+ mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
+ }
+
+ if (err)
+ pci_clear_master(dev->pdev);
+}
+
+static int mlx5_nodnic_activate_queues(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_cq *cq = &dev->priv->cq;
+ int err;
+
+ mlx5_nodnic_init_cqes_ownership(cq);
+
+ err = mlx5_nodnic_activate_rq(dev);
+ if (err)
+ return err;
+
+ err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
+ if (err)
+ goto err_rq;
+
+ err = mlx5_nodnic_enable_port(dev);
+ mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
+ if (err)
+ goto err_port;
+
+ mlx5_nodnic_activate_sq(dev);
+
+ napi_enable_locked(&cq->napi);
+ mlx5_nodnic_arm_cq(cq);
+ napi_schedule(&cq->napi);
+
+ return 0;
+
+err_port:
+ mlx5_nodnic_quiesce_port(dev);
+err_rq:
+ mlx5_nodnic_deactivate_rq(dev);
+
+ return err;
+}
+
+static void mlx5_nodnic_deactivate_queues(struct mlx5_nodnic_core_dev *dev)
+{
+ napi_disable_locked(&dev->priv->cq.napi);
+ mlx5_nodnic_deactivate_sq(&dev->priv->sq);
+ mlx5_nodnic_quiesce_port(dev);
+ mlx5_nodnic_deactivate_rq(dev);
+}
+
int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
{
struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
@@ -610,8 +830,10 @@ int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
return err;
}
- /* Enable bus mastering only now, after the writes above, so the
- * device can't resume DMA with stale state.
+ /* Bus mastering may have been cleared by mlx5_nodnic_quiesce_port().
+ * Restore it only now, after the writes above cleared any dma_en left
+ * set by a failed close, so the device can't resume DMA with stale
+ * state.
*/
pci_set_master(dev->pdev);
@@ -628,7 +850,7 @@ int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
return err;
}
-void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
+int mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
{
struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
__be32 val;
@@ -657,6 +879,7 @@ void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
mlx5_nodnic_core_warn(dev,
"failed to read/write to vsc err %d\n",
err);
+ return err;
}
static int mlx5_nodnic_init_uar_map(struct mlx5_nodnic_core_dev *dev)
@@ -706,12 +929,19 @@ static int mlx5_nodnic_open_locked(struct net_device *netdev)
set_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
+ err = mlx5_nodnic_activate_queues(dev);
+ if (err)
+ goto err_close;
+
err = mlx5_nodnic_refresh_carrier_locked(priv);
if (err)
netdev_err(netdev, "Failed to query carrier, err=%d\n", err);
return 0;
+err_close:
+ clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
+ mlx5_nodnic_close_queues(dev);
err_uar:
mlx5_nodnic_cleanup_uar_map(dev);
return err;
@@ -734,6 +964,7 @@ static int mlx5_nodnic_close_locked(struct net_device *netdev)
struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+ mlx5_nodnic_deactivate_queues(dev);
clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
netif_carrier_off(netdev);
netdev_info(netdev, "Link down\n");
@@ -764,6 +995,8 @@ int mlx5_nodnic_close(struct net_device *netdev)
static const struct net_device_ops mlx5_nodnic_netdev_ops = {
.ndo_open = mlx5_nodnic_open,
.ndo_stop = mlx5_nodnic_close,
+ .ndo_start_xmit = mlx5_nodnic_xmit,
+ .ndo_features_check = mlx5_nodnic_check_features,
};
void mlx5_nodnic_build_netdev(struct net_device *netdev)
@@ -778,6 +1011,9 @@ void mlx5_nodnic_build_netdev(struct net_device *netdev)
netdev->netdev_ops = &mlx5_nodnic_netdev_ops;
netdev->request_ops_lock = true;
+ netdev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
+ netdev->features = netdev->hw_features;
+
eth_hw_addr_set(netdev, core_dev->mac_address);
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
index 2fcae95988d8..c44b0fdbe601 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
@@ -89,7 +89,7 @@ int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev);
int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev);
int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev);
int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev);
-void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev);
+int mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev);
int mlx5_nodnic_get_fw_initializing(struct mlx5_nodnic_core_dev *dev,
u8 *initializing);
int mlx5_nodnic_set_nic_interface(struct mlx5_nodnic_core_dev *dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
new file mode 100644
index 000000000000..7736a1f24ea5
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
@@ -0,0 +1,169 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/errno.h>
+#include <linux/if_vlan.h>
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/types.h>
+
+#include "en.h"
+#include "nodnic.h"
+#include "rx.h"
+
+int mlx5_nodnic_rq_alloc_pages(struct mlx5_nodnic_rq *rq)
+{
+ int entries = rq->ring.num_entries;
+ struct page *page;
+
+ rq->pages = kvcalloc(rq->ring.num_entries, sizeof(*rq->pages),
+ GFP_KERNEL);
+ if (!rq->pages)
+ return -ENOMEM;
+
+ for (int i = 0; i < entries; i++) {
+ page = page_pool_dev_alloc_pages(rq->page_pool);
+ if (unlikely(!page))
+ goto err_free_pages;
+
+ rq->pages[i] = page;
+ }
+
+ return 0;
+
+err_free_pages:
+ mlx5_nodnic_rq_free_pages(rq);
+ return -ENOMEM;
+}
+
+void mlx5_nodnic_rq_free_pages(struct mlx5_nodnic_rq *rq)
+{
+ u32 i;
+
+ for (i = 0; i < rq->ring.num_entries; i++) {
+ if (!rq->pages[i])
+ continue;
+
+ page_pool_put_full_page(rq->page_pool,
+ rq->pages[i], false);
+ }
+
+ kvfree(rq->pages);
+}
+
+static void mlx5_nodnic_rq_push_db(struct mlx5_nodnic_priv *priv)
+{
+ struct mlx5_nodnic_rq *rq = &priv->rq;
+
+ /* ensure wqes are visible to device before updating dbr */
+ dma_wmb();
+
+ /* update local DB record */
+ priv->dbr.db[MLX5_NODNIC_RCV_DBR] = cpu_to_be32(rq->pc & 0xffff);
+}
+
+static u16 mlx5_nodnic_rq_get_pi(struct mlx5_nodnic_rq *rq)
+{
+ return rq->pc & (rq->ring.num_entries - 1);
+}
+
+static int mlx5_nodnic_rq_post_one(struct mlx5_nodnic_rq *rq)
+{
+ u16 pi = mlx5_nodnic_rq_get_pi(rq);
+ struct mlx5_nodnic_rx_wqe *wqe;
+
+ if (!rq->pages[pi]) {
+ rq->pages[pi] = page_pool_dev_alloc_pages(rq->page_pool);
+ if (unlikely(!rq->pages[pi]))
+ return -ENOMEM;
+ }
+
+ wqe = (struct mlx5_nodnic_rx_wqe *)
+ ((u8 *)rq->ring.wq + pi * MLX5_NODNIC_RQ_STRIDE_BYTES);
+ wqe->byte_count = cpu_to_be32(MLX5_NODNIC_HW_MTU);
+ wqe->lkey = cpu_to_be32(rq->ring.lkey);
+ wqe->addr = cpu_to_be64(page_pool_get_dma_addr(rq->pages[pi]) +
+ MLX5_NODNIC_SKB_HEADROOM_BYTES);
+ rq->pc++;
+
+ return 0;
+}
+
+bool mlx5_nodnic_rq_post_wqes(struct mlx5_nodnic_priv *priv)
+{
+ struct mlx5_nodnic_rq *rq = &priv->rq;
+ u32 avail;
+ int i;
+
+ avail = rq->ring.num_entries - (u16)(rq->pc - rq->cc);
+ for (i = 0; i < avail; i++) {
+ if (mlx5_nodnic_rq_post_one(rq))
+ break;
+ }
+
+ if (i)
+ mlx5_nodnic_rq_push_db(priv);
+
+ return i == avail;
+}
+
+static void nodnic_handle_rx_csum(struct net_device *netdev,
+ const struct mlx5_cqe64 *cqe,
+ struct sk_buff *skb)
+{
+ skb->ip_summed = CHECKSUM_NONE;
+
+ if (unlikely(!(netdev->features & NETIF_F_RXCSUM)))
+ return;
+
+ if (likely((cqe->hds_ip_ext & CQE_L3_OK) &&
+ (cqe->hds_ip_ext & CQE_L4_OK)))
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+}
+
+void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
+ struct mlx5_cqe64 *cqe)
+{
+ struct mlx5_nodnic_priv *priv = container_of(cq,
+ struct mlx5_nodnic_priv,
+ cq);
+ u32 byte_count = be32_to_cpu(cqe->byte_cnt);
+ struct mlx5_nodnic_rq *rq = &priv->rq;
+ u16 wqe_counter, ci;
+ struct sk_buff *skb;
+ struct page *page;
+
+ wqe_counter = be16_to_cpu(cqe->wqe_counter);
+ ci = wqe_counter & (rq->ring.num_entries - 1);
+ page = rq->pages[ci];
+
+ page_pool_dma_sync_for_cpu(rq->page_pool, page, 0, byte_count);
+
+ skb = napi_build_skb(page_address(page), PAGE_SIZE);
+ if (unlikely(!skb))
+ goto err_recycle;
+
+ skb_mark_for_recycle(skb);
+ rq->pages[ci] = NULL;
+
+ skb_reserve(skb, MLX5_NODNIC_SKB_HEADROOM_BYTES);
+ skb_put(skb, byte_count);
+ skb->protocol = eth_type_trans(skb, priv->netdev);
+ nodnic_handle_rx_csum(priv->netdev, cqe, skb);
+
+ napi_gro_receive(&cq->napi, skb);
+ rq->cc++;
+
+ return;
+
+err_recycle:
+ mlx5_nodnic_release_rx_wqe(rq, ci);
+}
+
+void mlx5_nodnic_release_rx_wqe(struct mlx5_nodnic_rq *rq, u16 ci)
+{
+ page_pool_put_full_page(rq->page_pool, rq->pages[ci], true);
+ rq->pages[ci] = NULL;
+ rq->cc++;
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
new file mode 100644
index 000000000000..ccdfa3e69824
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#ifndef __MLX5_NODNIC_RX_H__
+#define __MLX5_NODNIC_RX_H__
+
+struct mlx5_nodnic_priv;
+struct mlx5_nodnic_cq;
+struct mlx5_nodnic_rq;
+struct mlx5_cqe64;
+
+struct mlx5_nodnic_rx_wqe {
+ __be32 byte_count;
+ __be32 lkey;
+ __be64 addr;
+};
+
+int mlx5_nodnic_rq_alloc_pages(struct mlx5_nodnic_rq *rq);
+void mlx5_nodnic_rq_free_pages(struct mlx5_nodnic_rq *rq);
+bool mlx5_nodnic_rq_post_wqes(struct mlx5_nodnic_priv *priv);
+void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
+ struct mlx5_cqe64 *cqe);
+void mlx5_nodnic_release_rx_wqe(struct mlx5_nodnic_rq *rq, u16 ci);
+
+#endif /* __MLX5_NODNIC_RX_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
new file mode 100644
index 000000000000..c0dba88b49e0
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/dma-mapping.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/mlx5/doorbell.h>
+#include <linux/net.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/types.h>
+#include <net/netdev_queues.h>
+
+#include "en.h"
+#include "nodnic.h"
+#include "tx.h"
+
+#define MLX5_NODNIC_OPCODE_SEND 0x0a
+#define MLX5_NODNIC_DS_COUNT 3
+#define MLX5_NODNIC_CE_ALWAYS 0x2
+#define MLX5_NODNIC_SQ_STOP_ROOM 1
+
+static void mlx5_nodnic_tx_build_wqe_eseg(struct sk_buff *skb,
+ struct mlx5_nodnic_wqe_eth_seg *eseg)
+{
+ u8 flags = 0;
+
+ if (likely(skb->ip_summed == CHECKSUM_PARTIAL))
+ flags |= MLX5_NODNIC_ETH_WQE_L3_CSUM |
+ MLX5_NODNIC_ETH_WQE_L4_CSUM;
+
+ eseg->cs_flags_mss = cpu_to_be32((u32)flags << 24);
+ eseg->inline_hdr_sz = 0;
+}
+
+static void
+mlx5_nodnic_tx_build_wqe_ctrl(struct mlx5_nodnic_sq *sq,
+ struct mlx5_nodnic_wqe_ctrl_seg *ctrl)
+{
+ ctrl->opmod_idx_opcode = cpu_to_be32((sq->pc << 8) |
+ MLX5_NODNIC_OPCODE_SEND);
+ ctrl->qpn_ds = cpu_to_be32((sq->ring.qn << 8) | MLX5_NODNIC_DS_COUNT);
+ ctrl->fm_ce_se = cpu_to_be32(MLX5_NODNIC_CE_ALWAYS << 2);
+ ctrl->general_id = 0;
+}
+
+static void mlx5_nodnic_tx_fill_wqe_info(struct mlx5_nodnic_sq *sq,
+ struct sk_buff *skb,
+ dma_addr_t dma_addr)
+{
+ u16 pi = mlx5_nodnic_sq_get_pi(sq, sq->pc);
+
+ sq->wqe_info[pi].skb = skb;
+ sq->wqe_info[pi].num_bytes = skb->len;
+ sq->wqe_info[pi].dma = dma_addr;
+}
+
+static int
+mlx5_nodnic_tx_build_wqe_ds(struct mlx5_nodnic_sq *sq, struct sk_buff *skb,
+ struct mlx5_nodnic_wqe_data_seg *dseg)
+{
+ dma_addr_t dma_addr = 0;
+
+ dseg->byte_count = cpu_to_be32(skb->len & 0x7FFFFFFF);
+ dseg->lkey = cpu_to_be32(sq->ring.lkey);
+ dma_addr = dma_map_single(sq->device, skb->data, skb->len,
+ DMA_TO_DEVICE);
+ if (unlikely(dma_mapping_error(sq->device, dma_addr)))
+ return -ENOMEM;
+
+ dseg->addr = cpu_to_be64(dma_addr);
+
+ mlx5_nodnic_tx_fill_wqe_info(sq, skb, dma_addr);
+
+ return 0;
+}
+
+static __always_inline int
+mlx5_nodnic_tx_write_wqe(struct mlx5_nodnic_sq *sq, struct sk_buff *skb,
+ struct mlx5_nodnic_tx_wqe *wqe)
+{
+ int err;
+
+ memset(wqe, 0, MLX5_NODNIC_SQ_WQEBB_B);
+ mlx5_nodnic_tx_build_wqe_ctrl(sq, &wqe->ctrl);
+ mlx5_nodnic_tx_build_wqe_eseg(skb, &wqe->eth);
+ err = mlx5_nodnic_tx_build_wqe_ds(sq, skb, &wqe->data);
+ if (err)
+ return err;
+
+ /* Ensure WQE stores are visible to the device before ringing the db */
+ dma_wmb();
+
+ return 0;
+}
+
+/* pc is written by xmit and cc by NAPI, see the barriers in
+ * netif_txq_maybe_stop() and netif_txq_completed_wake().
+ */
+static u16 mlx5_nodnic_sq_room(struct mlx5_nodnic_sq *sq)
+{
+ return sq->ring.num_entries -
+ (u16)(READ_ONCE(sq->pc) - READ_ONCE(sq->cc));
+}
+
+static int mlx5_nodnic_tx_get_next_sq_offset(struct mlx5_nodnic_sq *sq)
+{
+ u16 pi;
+
+ pi = mlx5_nodnic_sq_get_pi(sq, sq->pc);
+ return pi * MLX5_NODNIC_SQ_WQEBB_B;
+}
+
+static void mlx5_nodnic_tx_notify_hw(struct mlx5_nodnic_priv *priv,
+ void __iomem *uar_base, u16 pc,
+ struct mlx5_nodnic_wqe_ctrl_seg *ctrl)
+{
+ /* ensure wqe is visible to device before updating doorbell record */
+ dma_wmb();
+
+ priv->dbr.db[MLX5_NODNIC_SND_DBR] = cpu_to_be32(pc);
+
+ /* ensure doorbell record is visible to device before ringing the
+ * doorbell
+ */
+ wmb();
+
+ mlx5_write64((__be32 *)ctrl, uar_base + MLX5_BF_OFFSET);
+}
+
+netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *netdev)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+ struct mlx5_nodnic_sq *sq = &priv->sq;
+ struct mlx5_nodnic_tx_wqe *wqe;
+ u16 next_offset;
+ int err;
+
+ /* netif_txq_completed_wake can falsely wake while the ring is full, so
+ * check for room before touching the next descriptor.
+ */
+ if (unlikely(!netif_txq_maybe_stop(sq->txq, mlx5_nodnic_sq_room(sq),
+ MLX5_NODNIC_SQ_STOP_ROOM,
+ MLX5_NODNIC_SQ_STOP_ROOM)))
+ return NETDEV_TX_BUSY;
+
+ next_offset = mlx5_nodnic_tx_get_next_sq_offset(sq);
+
+ wqe = (struct mlx5_nodnic_tx_wqe *)((u8 *)sq->ring.wq + next_offset);
+
+ err = mlx5_nodnic_tx_write_wqe(sq, skb, wqe);
+ if (err) {
+ dev_kfree_skb_any(skb);
+
+ return NETDEV_TX_OK;
+ }
+
+ WRITE_ONCE(sq->pc, sq->pc + 1);
+
+ netdev_tx_sent_queue(sq->txq, skb->len);
+
+ mlx5_nodnic_tx_notify_hw(priv, dev->uar_base, sq->pc, &wqe->ctrl);
+
+ netif_txq_maybe_stop(sq->txq, mlx5_nodnic_sq_room(sq),
+ MLX5_NODNIC_SQ_STOP_ROOM,
+ MLX5_NODNIC_SQ_STOP_ROOM);
+
+ return NETDEV_TX_OK;
+}
+
+u16 mlx5_nodnic_sq_get_pi(struct mlx5_nodnic_sq *sq, u16 pc)
+{
+ return pc & (sq->ring.num_entries - 1);
+}
+
+void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
+ struct mlx5_cqe64 *cqe, int napi_budget)
+{
+ struct mlx5_nodnic_priv *priv = container_of(cq,
+ struct mlx5_nodnic_priv,
+ cq);
+ struct mlx5_nodnic_sq *sq = &priv->sq;
+ struct mlx5_nodnic_tx_wqe_info *wi;
+ u16 pi;
+
+ pi = mlx5_nodnic_sq_get_pi(sq, be16_to_cpu(cqe->wqe_counter));
+ wi = &sq->wqe_info[pi];
+
+ mlx5_nodnic_complete_send_wqe(sq, wi, napi_budget);
+}
+
+void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
+ struct mlx5_nodnic_tx_wqe_info *wi,
+ int napi_budget)
+{
+ u32 num_bytes = wi->num_bytes;
+
+ dma_unmap_single(sq->device, wi->dma, num_bytes, DMA_TO_DEVICE);
+ napi_consume_skb(wi->skb, napi_budget);
+
+ /* The slot is handed back to xmit by mlx5_nodnic_sq_publish_cc(),
+ * after the CQ consumer index has reached the device.
+ */
+ sq->cc_pending_pkts++;
+ sq->cc_pending_bytes += num_bytes;
+}
+
+void mlx5_nodnic_sq_publish_cc(struct mlx5_nodnic_sq *sq)
+{
+ if (!sq->cc_pending_pkts)
+ return;
+
+ WRITE_ONCE(sq->cc, sq->cc + sq->cc_pending_pkts);
+
+ netif_txq_completed_wake(sq->txq, sq->cc_pending_pkts,
+ sq->cc_pending_bytes,
+ mlx5_nodnic_sq_room(sq),
+ MLX5_NODNIC_SQ_STOP_ROOM);
+
+ sq->cc_pending_pkts = 0;
+ sq->cc_pending_bytes = 0;
+}
+
+void mlx5_nodnic_sq_free_pending(struct mlx5_nodnic_sq *sq)
+{
+ struct mlx5_nodnic_tx_wqe_info *wi;
+ unsigned int completed_bytes = 0;
+ unsigned int completed_pkts = 0;
+ u16 sqcc = sq->cc;
+ u16 ci;
+
+ while (sqcc != sq->pc) {
+ ci = mlx5_nodnic_sq_get_pi(sq, sqcc);
+ wi = &sq->wqe_info[ci];
+
+ dma_unmap_single(sq->device, wi->dma,
+ wi->num_bytes, DMA_TO_DEVICE);
+
+ completed_pkts++;
+ completed_bytes += wi->num_bytes;
+
+ dev_kfree_skb_any(wi->skb);
+
+ sqcc++;
+ }
+
+ if (completed_pkts)
+ netdev_tx_completed_queue(sq->txq, completed_pkts,
+ completed_bytes);
+ sq->cc = sqcc;
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
new file mode 100644
index 000000000000..baffa6f2b92b
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#ifndef __MLX5_NODNIC_TX_H__
+#define __MLX5_NODNIC_TX_H__
+
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/skbuff.h>
+
+struct mlx5_nodnic_sq;
+struct mlx5_nodnic_cq;
+struct mlx5_cqe64;
+
+struct mlx5_nodnic_tx_wqe_info {
+ struct sk_buff *skb;
+ u32 num_bytes;
+ dma_addr_t dma;
+};
+
+enum {
+ MLX5_NODNIC_ETH_WQE_L3_CSUM = 1 << 6,
+ MLX5_NODNIC_ETH_WQE_L4_CSUM = 1 << 7,
+};
+
+struct mlx5_nodnic_wqe_ctrl_seg {
+ __be32 opmod_idx_opcode;
+ __be32 qpn_ds;
+ __be32 fm_ce_se;
+ __be32 general_id;
+} __packed;
+
+struct mlx5_nodnic_wqe_eth_seg {
+ __be32 swp_offsets;
+ __be32 cs_flags_mss;
+ __be32 flow_metadata;
+ __be32 inline_hdr_sz;
+} __packed;
+
+struct mlx5_nodnic_wqe_data_seg {
+ __be32 byte_count;
+ __be32 lkey;
+ __be64 addr;
+} __packed;
+
+struct mlx5_nodnic_tx_wqe {
+ struct mlx5_nodnic_wqe_ctrl_seg ctrl;
+ struct mlx5_nodnic_wqe_eth_seg eth;
+ struct mlx5_nodnic_wqe_data_seg data;
+} __packed;
+
+netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *dev);
+u16 mlx5_nodnic_sq_get_pi(struct mlx5_nodnic_sq *sq, u16 pc);
+void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
+ struct mlx5_cqe64 *cqe, int napi_budget);
+void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
+ struct mlx5_nodnic_tx_wqe_info *wi,
+ int napi_budget);
+void mlx5_nodnic_sq_publish_cc(struct mlx5_nodnic_sq *sq);
+void mlx5_nodnic_sq_free_pending(struct mlx5_nodnic_sq *sq);
+
+#endif /* __MLX5_NODNIC_TX_H__ */
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path Tariq Toukan
@ 2026-12-03 20:57 ` Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 4/5] net/mlx5: nodnic: Add ethtool driver info Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring Tariq Toukan
4 siblings, 1 reply; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
From: Shahar Shitrit <shshitrit@nvidia.com>
Add TX and RX packet and byte statistics, as well as TX drop
accounting.
Update the counters from the data path and expose them through
ndo_get_stats64.
Signed-off-by: Shahar Shitrit <shshitrit@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/nodnic/en.c | 11 +++--
.../net/ethernet/mellanox/mlx5/nodnic/en.h | 18 ++++++++
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 42 +++++++++++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/rx.c | 5 +++
.../net/ethernet/mellanox/mlx5/nodnic/tx.c | 13 ++++++
.../net/ethernet/mellanox/mlx5/nodnic/tx.h | 3 ++
6 files changed, 89 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
index 6cbdfaf7cc01..a8f5ce5507d5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
@@ -85,10 +85,15 @@ static void mlx5_nodnic_handle_err_cqe(struct mlx5_nodnic_cq *cq,
if (opcode == OPCODE_CQ_SEND_ERR) {
struct mlx5_nodnic_sq *sq = &priv->sq;
- u16 sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
+ struct mlx5_nodnic_tx_wqe_info *wi;
+ u16 sq_pi;
- mlx5_nodnic_complete_send_wqe(sq, &sq->wqe_info[sq_pi],
- napi_budget);
+ sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
+ wi = &sq->wqe_info[sq_pi];
+
+ mlx5_nodnic_sq_stats_inc(&priv->sq_stats, wi);
+
+ mlx5_nodnic_complete_send_wqe(sq, wi, napi_budget);
} else {
struct mlx5_nodnic_rq *rq = &priv->rq;
u16 ci = wqe_counter & (rq->ring.num_entries - 1);
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
index f2d52cfe91c0..a5812a2205d6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
@@ -12,6 +12,7 @@
#include <linux/skbuff.h>
#include <linux/timer.h>
#include <linux/types.h>
+#include <linux/u64_stats_sync.h>
#define MLX5_NODNIC_RING_ENTRIES 1024
#define MLX5_NODNIC_CQE_SIZE_B 64
@@ -44,6 +45,20 @@ enum mlx5_nodnic_cqe_opcode {
OPCODE_CQ_INVALID,
};
+struct mlx5_nodnic_sq_stats {
+ struct u64_stats_sync syncp; /* NAPI */
+ u64_stats_t packets;
+ u64_stats_t bytes;
+ struct u64_stats_sync xmit_syncp; /* ndo_start_xmit */
+ u64_stats_t dropped;
+};
+
+struct mlx5_nodnic_rq_stats {
+ struct u64_stats_sync syncp;
+ u64_stats_t packets;
+ u64_stats_t bytes;
+};
+
struct mlx5_nodnic_ring {
void *wq;
dma_addr_t dma_handle;
@@ -115,6 +130,9 @@ struct mlx5_nodnic_priv {
struct mutex state_lock; /* protects Interface state */
unsigned long state;
+ struct mlx5_nodnic_sq_stats sq_stats;
+ struct mlx5_nodnic_rq_stats rq_stats;
+
struct mlx5_nodnic_sq sq;
struct mlx5_nodnic_rq rq;
struct mlx5_nodnic_dbr dbr; /* one shared dbr for TX and RX */
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
index b6adec5fc50d..68cdb074448d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
@@ -992,10 +992,49 @@ int mlx5_nodnic_close(struct net_device *netdev)
return err;
}
+static void mlx5_nodnic_update_sq_stats(const struct mlx5_nodnic_sq_stats *sq,
+ struct rtnl_link_stats64 *s)
+{
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin(&sq->syncp);
+ s->tx_packets = u64_stats_read(&sq->packets);
+ s->tx_bytes = u64_stats_read(&sq->bytes);
+ } while (u64_stats_fetch_retry(&sq->syncp, start));
+
+ do {
+ start = u64_stats_fetch_begin(&sq->xmit_syncp);
+ s->tx_dropped = u64_stats_read(&sq->dropped);
+ } while (u64_stats_fetch_retry(&sq->xmit_syncp, start));
+}
+
+static void mlx5_nodnic_update_rq_stats(const struct mlx5_nodnic_rq_stats *rq,
+ struct rtnl_link_stats64 *s)
+{
+ unsigned int start;
+
+ do {
+ start = u64_stats_fetch_begin(&rq->syncp);
+ s->rx_packets = u64_stats_read(&rq->packets);
+ s->rx_bytes = u64_stats_read(&rq->bytes);
+ } while (u64_stats_fetch_retry(&rq->syncp, start));
+}
+
+static void mlx5_nodnic_get_stats64(struct net_device *netdev,
+ struct rtnl_link_stats64 *stats)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+
+ mlx5_nodnic_update_sq_stats(&priv->sq_stats, stats);
+ mlx5_nodnic_update_rq_stats(&priv->rq_stats, stats);
+}
+
static const struct net_device_ops mlx5_nodnic_netdev_ops = {
.ndo_open = mlx5_nodnic_open,
.ndo_stop = mlx5_nodnic_close,
.ndo_start_xmit = mlx5_nodnic_xmit,
+ .ndo_get_stats64 = mlx5_nodnic_get_stats64,
.ndo_features_check = mlx5_nodnic_check_features,
};
@@ -1024,6 +1063,9 @@ static void mlx5_nodnic_init_priv(struct mlx5_nodnic_priv *priv,
priv->netdev = netdev;
priv->core_dev = core_dev;
mutex_init(&priv->state_lock);
+ u64_stats_init(&priv->sq_stats.syncp);
+ u64_stats_init(&priv->sq_stats.xmit_syncp);
+ u64_stats_init(&priv->rq_stats.syncp);
}
static void mlx5_nodnic_cleanup_priv(struct mlx5_nodnic_priv *priv)
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
index 7736a1f24ea5..58d6b033f5f6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
@@ -140,6 +140,11 @@ void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
page_pool_dma_sync_for_cpu(rq->page_pool, page, 0, byte_count);
+ u64_stats_update_begin(&priv->rq_stats.syncp);
+ u64_stats_inc(&priv->rq_stats.packets);
+ u64_stats_add(&priv->rq_stats.bytes, byte_count);
+ u64_stats_update_end(&priv->rq_stats.syncp);
+
skb = napi_build_skb(page_address(page), PAGE_SIZE);
if (unlikely(!skb))
goto err_recycle;
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
index c0dba88b49e0..c7910998f53e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
@@ -151,6 +151,9 @@ netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *netdev)
err = mlx5_nodnic_tx_write_wqe(sq, skb, wqe);
if (err) {
+ u64_stats_update_begin(&priv->sq_stats.xmit_syncp);
+ u64_stats_inc(&priv->sq_stats.dropped);
+ u64_stats_update_end(&priv->sq_stats.xmit_syncp);
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
@@ -174,6 +177,15 @@ u16 mlx5_nodnic_sq_get_pi(struct mlx5_nodnic_sq *sq, u16 pc)
return pc & (sq->ring.num_entries - 1);
}
+void mlx5_nodnic_sq_stats_inc(struct mlx5_nodnic_sq_stats *stats,
+ const struct mlx5_nodnic_tx_wqe_info *wi)
+{
+ u64_stats_update_begin(&stats->syncp);
+ u64_stats_inc(&stats->packets);
+ u64_stats_add(&stats->bytes, wi->num_bytes);
+ u64_stats_update_end(&stats->syncp);
+}
+
void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
struct mlx5_cqe64 *cqe, int napi_budget)
{
@@ -187,6 +199,7 @@ void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
pi = mlx5_nodnic_sq_get_pi(sq, be16_to_cpu(cqe->wqe_counter));
wi = &sq->wqe_info[pi];
+ mlx5_nodnic_sq_stats_inc(&priv->sq_stats, wi);
mlx5_nodnic_complete_send_wqe(sq, wi, napi_budget);
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
index baffa6f2b92b..a072654c1ba5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h
@@ -8,6 +8,7 @@
#include <linux/types.h>
#include <linux/skbuff.h>
+struct mlx5_nodnic_sq_stats;
struct mlx5_nodnic_sq;
struct mlx5_nodnic_cq;
struct mlx5_cqe64;
@@ -51,6 +52,8 @@ struct mlx5_nodnic_tx_wqe {
netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *dev);
u16 mlx5_nodnic_sq_get_pi(struct mlx5_nodnic_sq *sq, u16 pc);
+void mlx5_nodnic_sq_stats_inc(struct mlx5_nodnic_sq_stats *stats,
+ const struct mlx5_nodnic_tx_wqe_info *wi);
void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
struct mlx5_cqe64 *cqe, int napi_budget);
void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next V4 4/5] net/mlx5: nodnic: Add ethtool driver info
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
` (2 preceding siblings ...)
2026-12-03 20:57 ` [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics Tariq Toukan
@ 2026-12-03 20:57 ` Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring Tariq Toukan
4 siblings, 0 replies; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
From: Shahar Shitrit <shshitrit@nvidia.com>
Implement the get_drvinfo ethtool operation to report the driver name,
firmware version, and PCI bus information.
Read the firmware revision from the initialization segment and expose
it together with the driver information through ethtool.
Signed-off-by: Shahar Shitrit <shshitrit@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
index 68cdb074448d..8eebd86e7a74 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
@@ -1030,6 +1030,39 @@ static void mlx5_nodnic_get_stats64(struct net_device *netdev,
mlx5_nodnic_update_rq_stats(&priv->rq_stats, stats);
}
+static u16 mlx5_nodnic_fw_rev_maj(struct mlx5_nodnic_core_dev *dev)
+{
+ return ioread32be(&dev->iseg->fw_rev) & 0xffff;
+}
+
+static u16 mlx5_nodnic_fw_rev_min(struct mlx5_nodnic_core_dev *dev)
+{
+ return ioread32be(&dev->iseg->fw_rev) >> 16;
+}
+
+static u16 mlx5_nodnic_fw_rev_sub(struct mlx5_nodnic_core_dev *dev)
+{
+ return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
+}
+
+static void mlx5_nodnic_get_drvinfo(struct net_device *netdev,
+ struct ethtool_drvinfo *drvinfo)
+{
+ struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
+ struct mlx5_nodnic_core_dev *mdev = priv->core_dev;
+
+ strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
+ snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
+ "%d.%d.%04d", mlx5_nodnic_fw_rev_maj(mdev),
+ mlx5_nodnic_fw_rev_min(mdev), mlx5_nodnic_fw_rev_sub(mdev));
+ strscpy(drvinfo->bus_info, dev_name(mdev->device),
+ sizeof(drvinfo->bus_info));
+}
+
+static const struct ethtool_ops mlx5_nodnic_ethtool_ops = {
+ .get_drvinfo = mlx5_nodnic_get_drvinfo,
+};
+
static const struct net_device_ops mlx5_nodnic_netdev_ops = {
.ndo_open = mlx5_nodnic_open,
.ndo_stop = mlx5_nodnic_close,
@@ -1048,6 +1081,7 @@ void mlx5_nodnic_build_netdev(struct net_device *netdev)
SET_NETDEV_DEV(netdev, core_dev->device);
netdev->netdev_ops = &mlx5_nodnic_netdev_ops;
+ netdev->ethtool_ops = &mlx5_nodnic_ethtool_ops;
netdev->request_ops_lock = true;
netdev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
` (3 preceding siblings ...)
2026-12-03 20:57 ` [PATCH net-next V4 4/5] net/mlx5: nodnic: Add ethtool driver info Tariq Toukan
@ 2026-12-03 20:57 ` Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
4 siblings, 1 reply; 10+ messages in thread
From: Tariq Toukan @ 2026-12-03 20:57 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Willem de Bruijn
Cc: Carolina Jubran, Gal Pressman, open list, Shahar Shitrit,
Tariq Toukan
From: Shahar Shitrit <shshitrit@nvidia.com>
Monitor firmware health by periodically polling the health buffer from
the initialization segment.
Detect fatal device conditions, firmware health counter stalls, and
syndrome changes. Report health errors together with their severity
and mark the device as unhealthy on fatal conditions.
Start and stop health polling as part of the device probe and remove
flows.
Signed-off-by: Shahar Shitrit <shshitrit@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/nodnic/Makefile | 2 +-
.../net/ethernet/mellanox/mlx5/nodnic/en.h | 12 +
.../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 6 +
.../ethernet/mellanox/mlx5/nodnic/health.c | 303 ++++++++++++++++++
.../net/ethernet/mellanox/mlx5/nodnic/main.c | 2 +
.../ethernet/mellanox/mlx5/nodnic/nodnic.h | 26 ++
6 files changed, 350 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
index 25865d7244d8..c60418875e2c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile
@@ -5,4 +5,4 @@
obj-$(CONFIG_MLX5_NODNIC) += mlx5_nodnic.o
-mlx5_nodnic-y := main.o en.o en_cfg.o tx.o rx.o nodnic_pci_vsc.o
+mlx5_nodnic-y := main.o en.o en_cfg.o tx.o rx.o nodnic_pci_vsc.o health.o
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
index a5812a2205d6..24258bfb2217 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.h
@@ -123,6 +123,16 @@ struct mlx5_nodnic_working_buffer {
u32 alloc_size;
};
+struct mlx5_nodnic_health {
+ struct health_buffer __iomem *health;
+ __be32 __iomem *health_counter;
+ struct timer_list timer;
+ u32 prev_counter;
+ int miss_counter;
+ u8 synd;
+ u32 fatal_error;
+};
+
struct mlx5_nodnic_priv {
struct mlx5_nodnic_core_dev *core_dev;
struct net_device *netdev;
@@ -138,6 +148,8 @@ struct mlx5_nodnic_priv {
struct mlx5_nodnic_dbr dbr; /* one shared dbr for TX and RX */
struct mlx5_nodnic_cq cq;
struct mlx5_nodnic_ring working_buffer;
+
+ struct mlx5_nodnic_health health;
};
void mlx5_nodnic_build_netdev(struct net_device *netdev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
index 8eebd86e7a74..a45f651ed9ac 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
@@ -919,6 +919,12 @@ static int mlx5_nodnic_open_locked(struct net_device *netdev)
struct mlx5_nodnic_core_dev *dev = priv->core_dev;
int err;
+ if (READ_ONCE(dev->state) == NODNIC_DEVICE_STATE_INTERNAL_ERROR) {
+ netdev_err(netdev,
+ "Cannot open: device is in a fatal error state\n");
+ return -EIO;
+ }
+
err = mlx5_nodnic_init_uar_map(dev);
if (err)
return err;
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
new file mode 100644
index 000000000000..a2038eea9717
--- /dev/null
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
@@ -0,0 +1,303 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+#include <linux/kernel.h>
+#include <linux/random.h>
+#include <linux/timer.h>
+#include <linux/types.h>
+
+#include "en.h"
+#include "nodnic_ifc.h"
+#include "nodnic.h"
+
+#define MLX5_NODNIC_HEALTH_POLL_INTERVAL_MS 2000
+#define MLX5_NODNIC_MAX_MISSES 3
+
+enum nodnic_rfr_severity_bit_offsets {
+ NODNIC_CRR_BIT_OFFSET = 0x6,
+ NODNIC_RFR_BIT_OFFSET = 0x7,
+};
+
+enum {
+ MLX5_NODNIC_SEVERITY_MASK = 0x7,
+ MLX5_NODNIC_SEVERITY_VALID_MASK = 0x8,
+};
+
+enum {
+ MLX5_NODNIC_SENSOR_NO_ERR,
+ MLX5_NODNIC_SENSOR_PCI_COMM_ERR,
+ MLX5_NODNIC_SENSOR_PCI_ERR,
+ MLX5_NODNIC_SENSOR_NIC_DISABLED,
+ MLX5_NODNIC_SENSOR_NIC_SW_RESET,
+ MLX5_NODNIC_SENSOR_FW_SYND_RFR,
+};
+
+static unsigned long get_next_poll_jiffies(void)
+{
+ return jiffies + msecs_to_jiffies(MLX5_NODNIC_HEALTH_POLL_INTERVAL_MS) +
+ get_random_u32_below(HZ);
+}
+
+static bool sensor_pci_not_working(struct mlx5_nodnic_health *health)
+{
+ struct health_buffer __iomem *h = health->health;
+
+ return (ioread32be(&h->fw_ver) == 0xffffffff);
+}
+
+static u8 mlx5_nodnic_get_nic_state(struct mlx5_nodnic_core_dev *dev)
+{
+ return (ioread32be(&dev->iseg->cmdq_addr_l_sz) >> 8) & 7;
+}
+
+static int mlx5_nodnic_health_get_rfr(u8 rfr_severity)
+{
+ return rfr_severity >> NODNIC_RFR_BIT_OFFSET;
+}
+
+static bool sensor_fw_synd_rfr(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_health *health = &dev->priv->health;
+ struct health_buffer __iomem *h = health->health;
+ u8 synd = ioread8(&h->synd);
+ u8 rfr;
+
+ rfr = mlx5_nodnic_health_get_rfr(ioread8(&h->rfr_severity));
+
+ if (rfr && synd)
+ mlx5_nodnic_core_dbg(dev, "FW requests reset, synd: %d\n",
+ synd);
+
+ return rfr && synd;
+}
+
+static
+u32 mlx5_nodnic_health_check_fatal_sensors(struct mlx5_nodnic_core_dev *dev)
+{
+ u32 nic_state;
+
+ if (pci_channel_offline(dev->pdev))
+ return MLX5_NODNIC_SENSOR_PCI_ERR;
+ if (sensor_pci_not_working(&dev->priv->health))
+ return MLX5_NODNIC_SENSOR_PCI_COMM_ERR;
+
+ nic_state = mlx5_nodnic_get_nic_state(dev);
+ if (nic_state == MLX5_NODNIC_ISEG_NIC_INTERFACE_DISABLED)
+ return MLX5_NODNIC_SENSOR_NIC_DISABLED;
+ if (nic_state == MLX5_NODNIC_ISEG_NIC_INTERFACE_SW_RESET)
+ return MLX5_NODNIC_SENSOR_NIC_SW_RESET;
+
+ if (sensor_fw_synd_rfr(dev))
+ return MLX5_NODNIC_SENSOR_FW_SYND_RFR;
+
+ return MLX5_NODNIC_SENSOR_NO_ERR;
+}
+
+static const char *mlx5_nodnic_fatal_error_str(u32 err)
+{
+ switch (err) {
+ case MLX5_NODNIC_SENSOR_PCI_COMM_ERR: return "PCI communication error";
+ case MLX5_NODNIC_SENSOR_PCI_ERR: return "PCI error";
+ case MLX5_NODNIC_SENSOR_NIC_DISABLED: return "NIC disabled";
+ case MLX5_NODNIC_SENSOR_NIC_SW_RESET: return "NIC SW reset";
+ case MLX5_NODNIC_SENSOR_FW_SYND_RFR: return "FW synd RFR";
+ default: return "unknown";
+ }
+}
+
+static int mlx5_nodnic_health_get_crr(u8 rfr_severity)
+{
+ return (rfr_severity >> NODNIC_CRR_BIT_OFFSET) & 0x01;
+}
+
+static int mlx5_nodnic_health_get_severity(u8 rfr_severity)
+{
+ return rfr_severity & MLX5_NODNIC_SEVERITY_VALID_MASK ?
+ rfr_severity & MLX5_NODNIC_SEVERITY_MASK : LOGLEVEL_ERR;
+}
+
+/* Syndrome values from health buffer (same as mlx5_ifc.h) */
+static const char *mlx5_nodnic_hsynd_str(u8 synd)
+{
+ switch (synd) {
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FW_INTERNAL_ERR:
+ return "firmware internal error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_DEAD_IRISC:
+ return "irisc not responding";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_HW_FATAL_ERR:
+ return "unrecoverable hardware error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FW_CRC_ERR:
+ return "firmware CRC error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_FETCH_PCI_ERR:
+ return "ICM fetch PCI error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_PAGE_ERR:
+ return "HW fatal error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ASYNCHRONOUS_EQ_BUF_OVERRUN:
+ return "async EQ buffer overrun";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_EQ_IN_ERR:
+ return "EQ error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_EQ_INV:
+ return "Invalid EQ referenced";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_FFSER_ERR:
+ return "FFSER error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_HIGH_TEMP_ERR:
+ return "High temperature";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_ICM_PCI_POISONED_ERR:
+ return "ICM fetch PCI data poisoned error";
+ case MLX5_NODNIC_ISEG_HEALTH_SYNDROME_TRUST_LOCKDOWN_ERR:
+ return "Trust lockdown error";
+ default:
+ return "unrecognized error";
+ }
+}
+
+static const char *mlx5_nodnic_loglevel_str(int level)
+{
+ switch (level) {
+ case LOGLEVEL_EMERG:
+ return "EMERGENCY";
+ case LOGLEVEL_ALERT:
+ return "ALERT";
+ case LOGLEVEL_CRIT:
+ return "CRITICAL";
+ case LOGLEVEL_ERR:
+ return "ERROR";
+ case LOGLEVEL_WARNING:
+ return "WARNING";
+ case LOGLEVEL_NOTICE:
+ return "NOTICE";
+ case LOGLEVEL_INFO:
+ return "INFO";
+ case LOGLEVEL_DEBUG:
+ return "DEBUG";
+ }
+ return "Unknown log level";
+}
+
+static void mlx5_nodnic_print_health_info(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_health *health = &dev->priv->health;
+ struct health_buffer __iomem *h = health->health;
+ u8 synd = ioread8(&h->synd);
+ u8 rfr_severity;
+ int severity;
+ int i;
+
+ if (!synd)
+ return;
+
+ if (sensor_pci_not_working(&dev->priv->health)) {
+ mlx5_nodnic_core_err(dev, "PCI slot is unavailable\n");
+ return;
+ }
+
+ rfr_severity = ioread8(&h->rfr_severity);
+ severity = mlx5_nodnic_health_get_severity(rfr_severity);
+
+ mlx5_nodnic_log(dev, severity,
+ "Health issue observed, %s, severity(%d) %s:\n",
+ mlx5_nodnic_hsynd_str(synd), severity,
+ mlx5_nodnic_loglevel_str(severity));
+
+ for (i = 0; i < ARRAY_SIZE(h->assert_var); i++)
+ mlx5_nodnic_log(dev, severity, "assert_var[%d] 0x%08x\n", i,
+ ioread32be(h->assert_var + i));
+
+ mlx5_nodnic_log(dev, severity, "assert_exit_ptr 0x%08x\n",
+ ioread32be(&h->assert_exit_ptr));
+ mlx5_nodnic_log(dev, severity, "assert_callra 0x%08x\n",
+ ioread32be(&h->assert_callra));
+ mlx5_nodnic_log(dev, severity, "raw fw_ver 0x%08x\n",
+ ioread32be(&h->fw_ver));
+ mlx5_nodnic_log(dev, severity, "time %u\n", ioread32be(&h->time));
+ mlx5_nodnic_log(dev, severity, "hw_id 0x%08x\n",
+ ioread32be(&h->hw_id));
+ mlx5_nodnic_log(dev, severity, "rfr %d\n",
+ mlx5_nodnic_health_get_rfr(rfr_severity));
+ mlx5_nodnic_log(dev, severity, "crr %d\n",
+ mlx5_nodnic_health_get_crr(rfr_severity));
+ mlx5_nodnic_log(dev, severity, "severity %d (%s)\n", severity,
+ mlx5_nodnic_loglevel_str(severity));
+ mlx5_nodnic_log(dev, severity, "irisc_index %d\n",
+ ioread8(&h->irisc_index));
+ mlx5_nodnic_log(dev, severity, "synd 0x%x: %s\n", synd,
+ mlx5_nodnic_hsynd_str(synd));
+ mlx5_nodnic_log(dev, severity, "ext_synd 0x%04x\n",
+ ioread16be(&h->ext_synd));
+
+ if (mlx5_nodnic_health_get_crr(rfr_severity))
+ mlx5_nodnic_core_warn(dev, "Cold reset is required\n");
+}
+
+static void mlx5_nodnic_poll_health(struct timer_list *t)
+{
+ struct mlx5_nodnic_priv *priv = timer_container_of(priv, t,
+ health.timer);
+ struct mlx5_nodnic_core_dev *dev = priv->core_dev;
+ struct mlx5_nodnic_health *health = &priv->health;
+ struct health_buffer __iomem *h = health->health;
+ u32 fatal_error, count;
+ u8 prev_synd;
+
+ if (READ_ONCE(dev->state) == NODNIC_DEVICE_STATE_INTERNAL_ERROR)
+ return;
+
+ fatal_error = mlx5_nodnic_health_check_fatal_sensors(dev);
+
+ if (fatal_error && !health->fatal_error) {
+ mlx5_nodnic_core_err(dev, "fatal error detected: %s (%u)\n",
+ mlx5_nodnic_fatal_error_str(fatal_error),
+ fatal_error);
+ priv->health.fatal_error = fatal_error;
+ WRITE_ONCE(dev->state, NODNIC_DEVICE_STATE_INTERNAL_ERROR);
+ if (fatal_error != MLX5_NODNIC_SENSOR_PCI_COMM_ERR &&
+ fatal_error != MLX5_NODNIC_SENSOR_PCI_ERR)
+ mlx5_nodnic_print_health_info(dev);
+ return;
+ }
+
+ count = ioread32be(health->health_counter);
+ if (count == health->prev_counter)
+ ++health->miss_counter;
+ else
+ health->miss_counter = 0;
+
+ health->prev_counter = count;
+ if (health->miss_counter == MLX5_NODNIC_MAX_MISSES) {
+ mlx5_nodnic_core_err(dev,
+ "device's health compromised - reached miss count\n");
+ health->synd = ioread8(&h->synd);
+ mlx5_nodnic_print_health_info(dev);
+ }
+
+ prev_synd = health->synd;
+ health->synd = ioread8(&h->synd);
+ if (health->synd && health->synd != prev_synd)
+ mlx5_nodnic_print_health_info(dev);
+
+ mod_timer(&health->timer, get_next_poll_jiffies());
+}
+
+void mlx5_nodnic_start_health_poll(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_health *health = &dev->priv->health;
+
+ timer_setup(&health->timer, mlx5_nodnic_poll_health, 0);
+ health->fatal_error = MLX5_NODNIC_SENSOR_NO_ERR;
+ health->miss_counter = 0;
+ health->prev_counter = 0;
+ health->synd = 0;
+ health->health = &dev->iseg->health;
+ health->health_counter = &dev->iseg->health_counter;
+
+ health->timer.expires = jiffies +
+ msecs_to_jiffies(MLX5_NODNIC_HEALTH_POLL_INTERVAL_MS);
+ add_timer(&health->timer);
+}
+
+void mlx5_nodnic_stop_health_poll(struct mlx5_nodnic_core_dev *dev)
+{
+ struct mlx5_nodnic_health *health = &dev->priv->health;
+
+ timer_delete_sync(&health->timer);
+}
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
index b905deda56dc..0e511970402a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
@@ -807,6 +807,7 @@ static int mlx5_nodnic_probe_one(struct pci_dev *pdev,
dev->netdev_registered = true;
dev->state = NODNIC_DEVICE_STATE_UP;
+ mlx5_nodnic_start_health_poll(dev);
pci_save_state(pdev);
@@ -832,6 +833,7 @@ static void mlx5_nodnic_remove_one(struct pci_dev *pdev)
if (!dev)
return;
+ mlx5_nodnic_stop_health_poll(dev);
mlx5_nodnic_event_irq_cleanup(dev);
mlx5_nodnic_cleanup_netdev(dev);
mlx5_nodnic_dev_cleanup(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
index c44b0fdbe601..65747b560320 100644
--- a/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
+++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h
@@ -78,6 +78,32 @@ struct mlx5_nodnic_core_dev {
enum mlx5_nodnic_device_state state;
};
+static inline void mlx5_nodnic_printk(struct mlx5_nodnic_core_dev *dev,
+ int level, const char *format, ...)
+{
+ struct device *device = dev->device;
+ struct va_format vaf;
+ va_list args;
+
+ if (WARN_ONCE(level < LOGLEVEL_EMERG || level > LOGLEVEL_DEBUG,
+ "Level %d is out of range, set to default level\n",
+ level))
+ level = LOGLEVEL_DEFAULT;
+
+ va_start(args, format);
+ vaf.fmt = format;
+ vaf.va = &args;
+
+ dev_printk_emit(level, device, "%s %s: %pV", dev_driver_string(device),
+ dev_name(device), &vaf);
+ va_end(args);
+}
+
+#define mlx5_nodnic_log(__dev, level, format, ...) \
+ mlx5_nodnic_printk(__dev, level, "%s:%d:(pid %d): " format, \
+ __func__, __LINE__, current->pid, \
+ ##__VA_ARGS__)
+
void mlx5_nodnic_start_health_poll(struct mlx5_nodnic_core_dev *dev);
void mlx5_nodnic_stop_health_poll(struct mlx5_nodnic_core_dev *dev);
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
@ 2026-12-04 21:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 21:45 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
cjubran, gal, linux-kernel, shshitrit
Thank you for your contribution! Sashiko AI review found 10 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 6 · Low: 4
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] mlx5_core's fw_reset.c already lists PCI device 0xc2d6 in
mgt_ifc_device_ids as "BlueField4 MGT interface device ID".
- [Medium] mlx5_nodnic_update_carrier() calls netif_carrier_event()
whenever the queried port state matches the current carrier state.
- [Medium] In this patch, mlx5_nodnic_close_locked() ->
mlx5_nodnic_close_queues() frees the FW working buffer, CQ ring, CQ…
- [Medium] net/mlx5: unvalidated log_max_ring_size shift in
mlx5_nodnic_calc_ring_size()
- [Medium] net/mlx5: unvalidated log_cq_size overflow in
mlx5_nodnic_init_cq_ring()
- [Medium] net/mlx5: unvalidated UAR shift and BAR0 bounds in
mlx5_nodnic_init_uar_map()
- [Low] nodnic_ifc.h declares working_buffer_addr_l in
mlx5_ifc_nodnic_port_settings_bits as a plain 32-bit address dword (u8…
- [Low] mlx5_nodnic_wait_fw_init() is meant to tolerate up to
MLX5_NODNIC_FW_INIT_TIMEOUT_MS (120 s) of FW initialization ('pre-…
- [Low] mlx5_nodnic_read_mac_address() combines two FW-provided dwords
(MLX5_NODNIC_PORT_MAC_ADDR_H/L) with u64_to_ether_addr(), and…
- [Low] net/mlx5: nodnic: unused definitions and over-exported local
helpers
--
net/mlx5: nodnic: Introduce the mlx5_nodnic driver
This adds mlx5_nodnic, a PCI netdev driver for DRAM-less ConnectX NIC
functions. The device is configured through a VSC config-space gateway.
The patch implements probe/remove (FLR, FW readiness, interface
negotiation, caps discovery), ring/CQ/working-buffer setup, a link event
IRQ, and ndo_open/ndo_stop.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> new file mode 100644
> index 0000000000000..738722671090b
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
[ ... ]
> +int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
> + u32 size = SZ_1K << dev->log_working_buffer_size;
> + int err;
> +
> + err = mlx5_nodnic_alloc_ring(dev, work_buf, size);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_write_ring_addr(dev, work_buf->dma_handle,
> + MLX5_NODNIC_PORT_WORK_BUF_ADDR_H,
> + MLX5_NODNIC_PORT_WORK_BUF_ADDR_L);
[Severity: Low]
Does this use the right layout for working_buffer_addr_l? In
nodnic_ifc.h it is declared as a plain 32-bit dword:
u8 working_buffer_addr_l[0x20];
mlx5_nodnic_write_ring_addr() treats it as nodnic_q_addr_l instead. It
reads the register back, sets only the top 20 bits:
MLX5_SET(nodnic_q_addr_l, &addr_l, q_addr_l,
lower_32_bits(dma_handle) >> 12);
and then writes back whatever the device returned in the low 12 bits.
cq_dbr_addr_l is also a plain dword, and mlx5_nodnic_init_cq_dbr()
writes it as a full lower_32_bits() value.
Is either the register definition or the accessor wrong here? If the low
12 bits read back as nonzero, the working buffer address given to FW
would not match the buffer that was allocated.
> + if (err)
> + goto err_free_working_buffer;
[ ... ]
> +static void mlx5_nodnic_close_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_priv *priv = dev->priv;
> +
> + mlx5_nodnic_free_ring(dev, &priv->working_buffer);
> + mlx5_nodnic_close_cq(&priv->cq);
> + mlx5_nodnic_close_rq(dev);
> + mlx5_nodnic_close_sq(dev);
> + mlx5_nodnic_free_dbr(dev, &priv->dbr);
> +}
[Severity: Medium]
Can the device still DMA into these buffers after they are freed? This
frees the working buffer, CQ ring, CQ DBR, SQ/RQ rings and the shared DBR
while their bus addresses are still programmed in the NODNIC config
registers. In this patch nothing disables the port or clears bus
mastering first.
Later in the series, "net/mlx5: nodnic: Implement data path" adds
mlx5_nodnic_deactivate_queues() -> mlx5_nodnic_quiesce_port(). That
clears dma_en/network_en, or calls pci_clear_master() if that fails,
before close_queues(). This covers the rings, CQ and DBRs.
The working buffer is still an open question at the end of the series.
It is the FW's own backing store ("for FW use only"). It is freed on
every ndo_stop while the function stays in NO_DRAM_NIC mode with bus
mastering still enabled.
The remove path has the same ordering:
mlx5_nodnic_remove_one()
mlx5_nodnic_cleanup_netdev()
unregister_netdev() -> ndo_stop -> mlx5_nodnic_close_queues()
mlx5_nodnic_free_ring(dev, &priv->working_buffer)
mlx5_nodnic_dev_cleanup()
mlx5_nodnic_write_nic_interface(dev, ..._INTERFACE_DISABLED)
mlx5_nodnic_wait_fw_init(dev, "teardown")
So FW runs its NODNIC teardown, and also spends the time between close
and the next open, with working_buffer_addr pointing at memory that has
already gone back to the allocator.
Is FW access to the working buffer gated by the port dma_en bit, or by
the NODNIC interface state? If it is the interface state, should the
working buffer be freed only after the interface is disabled and FW
teardown has completed?
> +
> +static void mlx5_nodnic_update_carrier(struct mlx5_nodnic_priv *priv,
> + __be32 event)
> +{
> + u32 port_state = MLX5_GET(nodnic_port_event, &event, port_state);
> + bool up = port_state == MLX5_NODNIC_PORT_STATE_ACTIVE;
> +
> + /* Force re-notification if state is unchanged */
> + if (up == netif_carrier_ok(priv->netdev)) {
> + netif_carrier_event(priv->netdev);
> + return;
> + }
[Severity: Medium]
Will this report a link flap on every ifup while the link is down?
This function is also reached from the synchronous open path:
mlx5_nodnic_open_locked()
mlx5_nodnic_refresh_carrier_locked()
mlx5_nodnic_update_carrier()
Carrier is always off at that point, because both
mlx5_nodnic_create_netdev() and mlx5_nodnic_close_locked() call
netif_carrier_off(). If port_state is not active, up is false and equals
netif_carrier_ok(), so netif_carrier_event() runs. That increments both
carrier_up_count and carrier_down_count and fires a linkwatch event,
although the link never changed.
The forced re-notification only seems meaningful for the async event IRQ
path. This behaviour is the same at the end of the series.
> + if (up) {
> + netif_carrier_on(priv->netdev);
> + netdev_info(priv->netdev, "Link up\n");
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
> new file mode 100644
> index 0000000000000..b905deda56dcd
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/main.c
[ ... ]
> +static int mlx5_nodnic_wait_fw_init(struct mlx5_nodnic_core_dev *dev,
> + const char *init_state)
> +{
[ ... ]
> + do {
> + err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
> + if (err)
> + return err;
[Severity: Low]
Should an acquire failure here be retried until end, rather than ending
the wait? The loop is meant to allow up to
MLX5_NODNIC_FW_INIT_TIMEOUT_MS (120 s), but any failure from
mlx5_nodnic_vsc_context_acquire() returns immediately.
mlx5_nodnic_vsc_gw_lock() gives up with -EBUSY after VSC_MAX_RETRIES
iterations of usleep_range(1000, 2000), which is roughly 2-4 seconds.
mlx5_nodnic_vsc_gw_set_space() returns -EINVAL if the control status
field reads 0.
Suppose the VSC gateway is briefly busy or unavailable while FW is still
initializing, for example right after pcie_flr(). Then
mlx5_nodnic_dev_init(), and so probe, would fail after a few seconds
rather than waiting out the full timeout.
In the "teardown" call from mlx5_nodnic_dev_cleanup(), the error is
ignored. mlx5_nodnic_pci_close() then runs without confirming that FW
has left the initializing state.
> +
> + err = mlx5_nodnic_get_fw_initializing(dev, &fw_initializing);
> + mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
[ ... ]
> +int mlx5_nodnic_read_mac_address(struct mlx5_nodnic_core_dev *dev)
> +{
[ ... ]
> + mac = ((u64)mac_h << 32) | mac_l;
> +
> + u64_to_ether_addr(mac, dev->mac_address);
> +
> + return 0;
> +}
[Severity: Low]
What happens if FW reports an all-zero, multicast or broadcast address
here? The value goes straight to eth_hw_addr_set() in
mlx5_nodnic_build_netdev() and is never checked with
is_valid_ether_addr(). The netdev ops also lack an ndo_validate_addr,
so dev_open() will not reject it either.
mlx5e already expects zero MACs from FW and falls back to
eth_hw_addr_random() in mlx5e_set_netdev_dev_addr(). Would something
similar fit here, or should probe fail instead?
[ ... ]
> +static const struct pci_device_id mlx5_nodnic_core_pci_table[] = {
> + { PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField-4 nodnic rshim PF */
> + { }
> +};
[Severity: Medium]
How does this interact with mlx5_core sync FW reset? mlx5_core already
lists this ID in mgt_ifc_device_ids in
drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c:
{ PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField4 MGT interface device ID */
When mlx5_check_dev_ids() checks that every function under the bridge
is a PF of the device, it skips this ID. So mlx5_core will ack and run
a sync FW reset with this function present:
mlx5_sync_reset_request_event()
mlx5_is_reset_now_capable()
mlx5_check_dev_ids() <- skips 0xc2d6
mlx5_sync_pci_reset()
mlx5_pci_link_toggle()
pci_save_state() / pci_cfg_access_lock() on each sibling
pcie_capability_set_word(bridge, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_LD)
...
pci_restore_state()
The link toggle resets every function below the bridge, including the
one mlx5_nodnic drives. Restoring config space does not bring back the
device-internal NODNIC state:
- nic_interface set to NO_DRAM_NIC
- the ring, CQ, DBR and working buffer addresses written through VSC
- the port network enable bits
mlx5_nodnic_core_driver only has probe and remove, with no err_handler
and no reset_prepare/reset_done. The driver is not told about the reset
and keeps MLX5_NODNIC_STATE_OPENED set.
Reset notification hooks alone would not cover this either. The link
toggle writes LNKCTL directly and never calls the PCI core reset
callbacks.
Later in the series, "net/mlx5: nodnic: Add health monitoring" makes
this worse. During the toggle, iseg MMIO reads return 0xffffffff, or
nic_state reads as disabled or sw reset. dev->state then latches
NODNIC_DEVICE_STATE_INTERNAL_ERROR and nothing clears it. After that,
mlx5_nodnic_open_locked() fails with -EIO until the driver is unbound
and rebound.
With this driver bound, does the assumption in mlx5_core that nothing
in the kernel drives 0xc2d6 still hold? Is some coordination needed
between fw_reset.c and this driver across a sync reset?
> +
> +MODULE_DEVICE_TABLE(pci, mlx5_nodnic_core_pci_table);
[ ... ]
> @@ -0,0 +1,841 @@
> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> +// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +
> +#include <linux/bitops.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/etherdevice.h>
> +#include <linux/ethtool.h>
> +#include <linux/interrupt.h>
> +#include <linux/log2.h>
> +#include <linux/pci.h>
> +#include <linux/sizes.h>
> +#include <net/netdev_lock.h>
> +#include <net/net_namespace.h>
> +
> +#include "en.h"
> +#include "nodnic_ifc.h"
> +#include "nodnic.h"
> +#include "nodnic_pci_vsc.h"
> +
> +#define MLX5_NODNIC_CQ_INIT_CMD_SN cpu_to_be32(2 << 28)
> +
> +static int mlx5_nodnic_write_ring_addr(struct mlx5_nodnic_core_dev *dev,
> + dma_addr_t dma_handle, u32 offset_h,
> + u32 offset_l)
> +{
> + __be32 addr_h, addr_l;
> + int err;
> +
> + addr_h = cpu_to_be32(upper_32_bits(dma_handle));
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_h, addr_h);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write ring addr high: %d\n",
> + err);
> + return err;
> + }
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset_l, &addr_l);
> + if (err) {
> + mlx5_nodnic_core_err(dev, "failed to read ring addr low: %d\n",
> + err);
> + return err;
> + }
> +
> + MLX5_SET(nodnic_q_addr_l, &addr_l, q_addr_l,
> + lower_32_bits(dma_handle) >> 12);
> +
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset_l, addr_l);
> + if (err)
> + mlx5_nodnic_core_err(dev, "failed to write ring addr low: %d\n",
> + err);
> + return err;
> +}
> +
> +static u32 mlx5_nodnic_calc_ring_size(struct mlx5_nodnic_core_dev *dev,
> + int stride)
> +{
> + u32 ring_size = MLX5_NODNIC_RING_ENTRIES * stride;
> + u32 max_supported = 1U << dev->log_max_ring_size;
> +
> + return min(ring_size, max_supported);
> +}
> +
> +static int mlx5_nodnic_write_ring_size(struct mlx5_nodnic_core_dev *dev,
> + int offset, int size)
> +{
> + __be32 addr_l;
> + int err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &addr_l);
> + if (err) {
> + mlx5_nodnic_core_err(dev, "failed to read ring size: %d\n",
> + err);
> + return err;
> + }
> +
> + MLX5_SET(nodnic_q_addr_l, &addr_l, log_size, ilog2(size));
> +
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, offset, addr_l);
> + if (err)
> + mlx5_nodnic_core_err(dev, "failed to write ring size: %d\n",
> + err);
> + return err;
> +}
> +
> +static int mlx5_nodnic_read_qn(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_ring *ring, u32 offset)
> +{
> + __be32 qn_dword;
> + int err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, offset, &qn_dword);
> + if (err) {
> + mlx5_nodnic_core_err(dev, "failed to read queue number: %d\n",
> + err);
> + return err;
> + }
> +
> + ring->qn = MLX5_GET(nodnic_ring_q_number, &qn_dword, queue_number);
> +
> + return 0;
> +}
> +
> +static int mlx5_nodnic_write_ring_dbr_addr(struct mlx5_nodnic_core_dev *dev,
> + u32 ring_offset)
> +{
> + int off_h = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_H;
> + int off_l = ring_offset + MLX5_NODNIC_RING_DBR_ADDR_L;
> + struct mlx5_nodnic_dbr *dbr = &dev->priv->dbr;
> + __be32 dbr_h, dbr_l;
> + int err;
> +
> + dbr_l = 0;
> + MLX5_SET(nodnic_ring_dbr_addr_l, &dbr_l, db_record_addr_l,
> + (u32)(dbr->dma_handle >> 2));
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_l, dbr_l);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write ring DBR addr low: %d\n",
> + err);
> + return err;
> + }
> +
> + dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx, off_h, dbr_h);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write ring DBR addr high: %d\n",
> + err);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static int mlx5_nodnic_alloc_ring(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_ring *ring, int size)
> +{
> + dma_addr_t dma_handle;
[Severity: Low]
Some code in this patch is dead, and some has wider scope than it
needs. Both stay that way through the end of the series.
struct mlx5_nodnic_working_buffer is never used.
mlx5_nodnic_priv::working_buffer is a struct mlx5_nodnic_ring, and
nothing else refers to this type.
mlx5_nodnic_vsc_cfg_write_cpu32() is defined, and declared in
nodnic_pci_vsc.h, but nothing in the series calls it.
The helpers listed under the VSC-gated helpers comment in nodnic.h are
only called from the file that defines them. In en_cfg.c these are
mlx5_nodnic_open_rq(), mlx5_nodnic_open_sq(), mlx5_nodnic_open_cq(),
mlx5_nodnic_init_working_buffer(), mlx5_nodnic_enable_port() and
mlx5_nodnic_disable_port(). In main.c they are
mlx5_nodnic_get_fw_initializing(), mlx5_nodnic_set_nic_interface(),
mlx5_nodnic_check_supported(), mlx5_nodnic_write_nic_interface(),
mlx5_nodnic_read_config(), mlx5_nodnic_validate_port_link_type() and
mlx5_nodnic_read_mac_address().
Could these be made static and the declarations dropped? The note that
the caller must hold the VSC context could stay as a comment on the
definitions. mlx5_nodnic_enable_port() and mlx5_nodnic_disable_port()
have no callers at all in this patch. They would fit better in the
patch that first uses them.
> + void *buf;
> +
> + buf = dma_alloc_coherent(dev->device, size, &dma_handle, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + *ring = (struct mlx5_nodnic_ring) {
> + .wq = buf,
> + .dma_handle = dma_handle,
> + .size = size,
> + };
> +
> + return 0;
> +}
> +
> +static void mlx5_nodnic_free_ring(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_ring *ring)
> +{
> + dma_free_coherent(dev->device, ring->size, ring->wq,
> + ring->dma_handle);
> + memset(ring, 0, sizeof(*ring));
> +}
> +
> +static int mlx5_nodnic_init_ring(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_ring *ring, u32 ring_offset,
> + int stride)
> +{
> + int ring_addr_h = ring_offset + MLX5_NODNIC_RING_ADDR_H;
> + int ring_addr_l = ring_offset + MLX5_NODNIC_RING_ADDR_L;
> + int size, err;
> +
> + size = mlx5_nodnic_calc_ring_size(dev, stride);
> +
> + err = mlx5_nodnic_alloc_ring(dev, ring, size);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle, ring_addr_h,
> + ring_addr_l);
> + if (err)
> + goto err_ring_free;
> +
> + err = mlx5_nodnic_write_ring_size(dev, ring_addr_l, size);
> + if (err)
> + goto err_ring_free;
> +
> + ring->num_entries = size / stride;
> +
> + err = mlx5_nodnic_read_qn(dev, ring,
> + ring_offset + MLX5_NODNIC_RING_QUEUE_NUMBER);
> + if (err)
> + goto err_ring_free;
> +
> + err = mlx5_nodnic_write_ring_dbr_addr(dev, ring_offset);
> + if (err)
> + goto err_ring_free;
> +
> + return 0;
> +
> +err_ring_free:
> + mlx5_nodnic_free_ring(dev, ring);
> + return err;
> +}
> +
> +static int mlx5_nodnic_alloc_dbr(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_dbr *dbr)
> +{
> + const u32 bytes = MLX5_NODNIC_DBR_WORDS * sizeof(__be32);
> + dma_addr_t dma_handle;
> + void *buf;
> +
> + buf = dma_alloc_coherent(dev->device, bytes, &dma_handle, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + *dbr = (struct mlx5_nodnic_dbr) {
> + .db = (__be32 *)buf,
> + .alloc_size = bytes,
> + .dma_handle = dma_handle,
> + };
> +
> + return 0;
> +}
> +
> +static void mlx5_nodnic_free_dbr(struct mlx5_nodnic_core_dev *dev,
> + struct mlx5_nodnic_dbr *dbr)
> +{
> + if (!dbr->db)
> + return;
> +
> + dma_free_coherent(dev->device, dbr->alloc_size, dbr->db,
> + dbr->dma_handle);
> +}
> +
> +static int mlx5_nodnic_init_cq_dbr(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_dbr *dbr = &dev->priv->cq.dbr;
> + __be32 dbr_h, dbr_l;
> + int err;
> +
> + err = mlx5_nodnic_alloc_dbr(dev, dbr);
> + if (err)
> + return err;
> +
> + dbr_l = cpu_to_be32(lower_32_bits(dbr->dma_handle));
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
> + MLX5_NODNIC_CQ_DBR_ADDR_L,
> + dbr_l);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write CQ DBR addr low: %d\n",
> + err);
> + goto err_free_dbr;
> + }
> +
> + dbr_h = cpu_to_be32(upper_32_bits(dbr->dma_handle));
> + err = mlx5_nodnic_vsc_cfg_write_be32(dev->vsc_ctx,
> + MLX5_NODNIC_CQ_DBR_ADDR_H,
> + dbr_h);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write CQ DBR addr high: %d\n",
> + err);
> + goto err_free_dbr;
> + }
> +
> + dev->priv->cq.dbr.db[1] = MLX5_NODNIC_CQ_INIT_CMD_SN;
> +
> + return 0;
> +
> +err_free_dbr:
> + mlx5_nodnic_free_dbr(dev, &dev->priv->cq.dbr);
> + return err;
> +}
> +
> +static void mlx5_nodnic_cleanup_cq_dbr(struct mlx5_nodnic_core_dev *dev)
> +{
> + mlx5_nodnic_free_dbr(dev, &dev->priv->cq.dbr);
> +}
> +
> +/* log_cq_size should be read after rq and sq ring sizes were set. */
> +static int mlx5_nodnic_read_cq_ring_size(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> + __be32 cq_addr_l;
> + u32 log_cq_size;
> + int err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx,
> + MLX5_NODNIC_PORT_CQ_ADDR_L,
> + &cq_addr_l);
> + if (err) {
> + mlx5_nodnic_core_err(dev, "failed to read CQ ring size: %d\n",
> + err);
> + return err;
> + }
> +
> + log_cq_size = MLX5_GET(nodnic_q_addr_l, &cq_addr_l, log_size);
> + cq->num_entries = 1ULL << log_cq_size;
[Severity: Medium]
Can the CQ size computed here overflow? log_size is a 6-bit field, and
mlx5_nodnic_read_cq_ring_size() does not check it before shifting.
cq->num_entries is a signed int. A log_cq_size of 31 makes it INT_MIN,
and for 32 and above the 64-bit result is truncated to 0.
The multiplication in mlx5_nodnic_init_cq_ring() overflows even
earlier. cq->num_entries * MLX5_NODNIC_CQE_SIZE_B is a signed int
product, so log_cq_size == 25 already gives 2^31. That is undefined,
and in practice it becomes INT_MIN. The negative int is then passed as
the size to mlx5_nodnic_alloc_ring() and sign-extended to a huge size_t
in dma_alloc_coherent(). For larger values the product wraps to 0. We
then get either a zero-size allocation or a CQ with zero entries
programmed into the device.
This does not need misbehaving FW. Suppose the device drops off the bus
during ndo_open. Config reads then return 0xffffffff, which
mlx5_nodnic_vsc_wait_on_flag(ctx, 1) accepts as a completed read, and
log_size reads as 63.
What is the largest CQ size the device can legitimately report? Should
log_cq_size be range-checked here? Should num_entries and the size
argument to mlx5_nodnic_alloc_ring() also be unsigned?
> + cq->log_num_entries = log_cq_size;
> +
> + return 0;
> +}
> +
> +static int mlx5_nodnic_init_cq_ring(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> + struct mlx5_nodnic_ring *ring;
> + int err;
> +
> + ring = &cq->ring;
> +
> + err = mlx5_nodnic_read_cq_ring_size(dev);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_alloc_ring(dev, ring,
> + cq->num_entries * MLX5_NODNIC_CQE_SIZE_B);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_write_ring_addr(dev, ring->dma_handle,
> + MLX5_NODNIC_PORT_CQ_ADDR_H,
> + MLX5_NODNIC_PORT_CQ_ADDR_L);
> + if (err)
> + goto err_free_cq;
> +
> + return 0;
> +
> +err_free_cq:
> + mlx5_nodnic_free_ring(dev, &cq->ring);
> + return err;
> +}
> +
> +static void mlx5_nodnic_cleanup_cq_ring(struct mlx5_nodnic_core_dev *dev)
> +{
> + mlx5_nodnic_free_ring(dev, &dev->priv->cq.ring);
> +}
> +
> +static int mlx5_nodnic_read_cq_n(struct mlx5_nodnic_core_dev *dev)
> +{
> + __be32 cq_n;
> + int err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(dev->vsc_ctx, MLX5_NODNIC_CQ_N,
> + &cq_n);
> + if (err) {
> + mlx5_nodnic_core_err(dev, "failed to read CQ number: %d\n",
> + err);
> + return err;
> + }
> +
> + dev->priv->cq.cqn = MLX5_GET(nodnic_cqn, &cq_n, cq_n);
> +
> + return 0;
> +}
> +
> +int mlx5_nodnic_init_working_buffer(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_ring *work_buf = &dev->priv->working_buffer;
> + u32 size = SZ_1K << dev->log_working_buffer_size;
> + int err;
> +
> + err = mlx5_nodnic_alloc_ring(dev, work_buf, size);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_write_ring_addr(dev, work_buf->dma_handle,
> + MLX5_NODNIC_PORT_WORK_BUF_ADDR_H,
> + MLX5_NODNIC_PORT_WORK_BUF_ADDR_L);
> + if (err)
> + goto err_free_working_buffer;
> +
> + return 0;
> +
> +err_free_working_buffer:
> + mlx5_nodnic_free_ring(dev, work_buf);
> + return err;
> +}
> +
> +int mlx5_nodnic_open_cq(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_cq *cq = &dev->priv->cq;
> + int err;
> +
> + cq->cc = 0;
> +
> + err = mlx5_nodnic_init_cq_ring(dev);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_init_cq_dbr(dev);
> + if (err)
> + goto err_cleanup_ring;
> +
> + err = mlx5_nodnic_read_cq_n(dev);
> + if (err)
> + goto err_cleanup_dbr;
> +
> + return 0;
> +
> +err_cleanup_dbr:
> + mlx5_nodnic_cleanup_cq_dbr(dev);
> +err_cleanup_ring:
> + mlx5_nodnic_cleanup_cq_ring(dev);
> + return err;
> +}
> +
> +static void mlx5_nodnic_close_cq(struct mlx5_nodnic_cq *cq)
> +{
> + struct mlx5_nodnic_core_dev *dev =
> + container_of(cq, struct mlx5_nodnic_priv, cq)->core_dev;
> +
> + mlx5_nodnic_cleanup_cq_dbr(dev);
> + mlx5_nodnic_cleanup_cq_ring(dev);
> +}
> +
> +int mlx5_nodnic_open_sq(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_priv *priv = dev->priv;
> + struct mlx5_nodnic_sq *sq = &priv->sq;
> + struct mlx5_nodnic_ring *ring;
> + int err;
> +
> + sq->netdev = priv->netdev;
> + sq->device = dev->device;
> + sq->pc = 0;
> + sq->cc = 0;
> + ring = &sq->ring;
> +
> + err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_SEND_RING_OFFSET,
> + MLX5_NODNIC_SQ_WQEBB_B);
> + if (err)
> + return err;
> +
> + ring->lkey = dev->lkey;
> +
> + return 0;
> +}
> +
> +static void mlx5_nodnic_close_sq(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_sq *sq = &dev->priv->sq;
> +
> + mlx5_nodnic_free_ring(dev, &sq->ring);
> +}
> +
> +int mlx5_nodnic_open_rq(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_rq *rq = &dev->priv->rq;
> + struct mlx5_nodnic_ring *ring;
> + int err;
> +
> + rq->pc = 0;
> + rq->cc = 0;
> + ring = &rq->ring;
> +
> + err = mlx5_nodnic_init_ring(dev, ring, MLX5_NODNIC_RECEIVE_RING_OFFSET,
> + MLX5_NODNIC_RQ_STRIDE_BYTES);
> + if (err)
> + return err;
> +
> + ring->lkey = dev->lkey;
> +
> + return 0;
> +}
> +
> +static void mlx5_nodnic_close_rq(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_rq *rq = &dev->priv->rq;
> +
> + mlx5_nodnic_free_ring(dev, &rq->ring);
> +}
> +
> +static int mlx5_nodnic_open_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> + int err;
> +
> + /* one doorbell record shared by both SQ and RQ */
> + err = mlx5_nodnic_alloc_dbr(dev, &dev->priv->dbr);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
> + if (err)
> + goto err_free_dbr;
> +
> + err = mlx5_nodnic_open_sq(dev);
> + if (err)
> + goto err_release_vsc;
> +
> + err = mlx5_nodnic_open_rq(dev);
> + if (err)
> + goto err_close_sq;
> +
> + err = mlx5_nodnic_open_cq(dev);
> + if (err)
> + goto err_close_rq;
> +
> + err = mlx5_nodnic_init_working_buffer(dev);
> + if (err)
> + goto err_close_cq;
> +
> + mlx5_nodnic_vsc_context_release(vsc_ctx);
> +
> + return 0;
> +
> +err_close_cq:
> + mlx5_nodnic_close_cq(&dev->priv->cq);
> +err_close_rq:
> + mlx5_nodnic_close_rq(dev);
> +err_close_sq:
> + mlx5_nodnic_close_sq(dev);
> +err_release_vsc:
> + mlx5_nodnic_vsc_context_release(vsc_ctx);
> +err_free_dbr:
> + mlx5_nodnic_free_dbr(dev, &dev->priv->dbr);
> +
> + return err;
> +}
> +
> +static void mlx5_nodnic_close_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_priv *priv = dev->priv;
> +
> + mlx5_nodnic_free_ring(dev, &priv->working_buffer);
> + mlx5_nodnic_close_cq(&priv->cq);
> + mlx5_nodnic_close_rq(dev);
> + mlx5_nodnic_close_sq(dev);
> + mlx5_nodnic_free_dbr(dev, &priv->dbr);
> +}
> +
> +static void mlx5_nodnic_update_carrier(struct mlx5_nodnic_priv *priv,
> + __be32 event)
> +{
> + u32 port_state = MLX5_GET(nodnic_port_event, &event, port_state);
> + bool up = port_state == MLX5_NODNIC_PORT_STATE_ACTIVE;
> +
> + /* Force re-notification if state is unchanged */
> + if (up == netif_carrier_ok(priv->netdev)) {
> + netif_carrier_event(priv->netdev);
> + return;
> + }
> + if (up) {
> + netif_carrier_on(priv->netdev);
> + netdev_info(priv->netdev, "Link up\n");
> + } else {
> + netif_carrier_off(priv->netdev);
> + netdev_info(priv->netdev, "Link down\n");
> + }
> +}
> +
> +static int mlx5_nodnic_refresh_carrier_locked(struct mlx5_nodnic_priv *priv)
> +{
> + struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> + struct mlx5_nodnic_vsc_ctx *vsc_ctx;
> + __be32 event;
> + int err;
> +
> + vsc_ctx = dev->vsc_ctx;
> + err = mlx5_nodnic_vsc_context_acquire(vsc_ctx);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_EVENT,
> + &event);
> + mlx5_nodnic_vsc_context_release(vsc_ctx);
> +
> + if (!err)
> + mlx5_nodnic_update_carrier(priv, event);
> +
> + return err;
> +}
> +
> +void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
> +{
> + mutex_lock(&priv->state_lock);
> + if (test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state))
> + mlx5_nodnic_refresh_carrier_locked(priv);
> + mutex_unlock(&priv->state_lock);
> +}
> +
> +int mlx5_nodnic_enable_port(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> + __be32 val = 0;
> + int err;
> +
> + /* data_msix_en, event_msix_en must be set before activating port */
> + MLX5_SET(nodnic_port_network, &val, data_msix_en, 1);
> + MLX5_SET(nodnic_port_network, &val, event_msix_en, 1);
> + err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + val);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write port network (msix): %d\n",
> + err);
> + return err;
> + }
> +
> + MLX5_SET(nodnic_port_network, &val, network_en, 1);
> + MLX5_SET(nodnic_port_network, &val, receive_filter_en, BIT(0));
> +
> + err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + val);
> + if (err) {
> + mlx5_nodnic_core_err(dev,
> + "failed to write port network (enable): %d\n",
> + err);
> + return err;
> + }
> +
> + /* Enable bus mastering only now, after the writes above, so the
> + * device can't resume DMA with stale state.
> + */
> + pci_set_master(dev->pdev);
> +
> + /* dma enabling requires a separate write */
> + MLX5_SET(nodnic_port_network, &val, dma_en, 1);
> +
> + err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + val);
> + if (err)
> + mlx5_nodnic_core_err(dev,
> + "failed to write port network (dma): %d\n",
> + err);
> +
> + return err;
> +}
> +
> +void mlx5_nodnic_disable_port(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_vsc_ctx *vsc_ctx = dev->vsc_ctx;
> + __be32 val;
> + int err;
> +
> + err = mlx5_nodnic_vsc_cfg_read_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + &val);
> + if (err)
> + goto out;
> +
> + MLX5_SET(nodnic_port_network, &val, dma_en, 0);
> + MLX5_SET(nodnic_port_network, &val, network_en, 0);
> + err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + val);
> + if (err)
> + goto out;
> +
> + /* data_msix_en, event_msix_en can't be modified while port is active */
> + MLX5_SET(nodnic_port_network, &val, data_msix_en, 0);
> + MLX5_SET(nodnic_port_network, &val, event_msix_en, 0);
> + err = mlx5_nodnic_vsc_cfg_write_be32(vsc_ctx, MLX5_NODNIC_PORT_NETWORK,
> + val);
> +
> +out:
> + if (err)
> + mlx5_nodnic_core_warn(dev,
> + "failed to read/write to vsc err %d\n",
> + err);
> +}
> +
> +static int mlx5_nodnic_init_uar_map(struct mlx5_nodnic_core_dev *dev)
> +{
> + void __iomem *base;
> + phys_addr_t paddr;
> + u32 uar_page_size;
> +
> + uar_page_size = 1U << dev->log_uar_page_size;
> +
> + paddr = dev->bar_addr +
> + ((phys_addr_t)dev->send_ring0_uar_index * uar_page_size);
> +
> + base = ioremap(paddr, uar_page_size);
[Severity: Medium]
Are the FW-supplied values checked before they are used to build this
mapping? log_uar_page_size is an 8-bit field that
mlx5_nodnic_read_uar_size() stores without any check. So
1U << dev->log_uar_page_size is undefined for values of 32 and above.
send_ring0_uar_index is a full 32-bit value, also unchecked, from
mlx5_nodnic_read_uar_index().
paddr is computed as dev->bar_addr plus index * page size. It goes to
ioremap() without a check for overflow, and without a check that the
range lies inside BAR 0. A bad value maps whatever sits at that
physical address, outside the region claimed by pci_request_regions().
dev->uar_base is also where the TX doorbell is meant to be written.
A surprise link drop can produce such values. In
mlx5_nodnic_read_config(), suppose reads start returning 0xffffffff
after mlx5_nodnic_read_cqe_format(). mlx5_nodnic_validate_feature_caps()
then passes, because every required capability bit reads as set.
log_uar_page_size becomes 0xff and send_ring0_uar_index 0xffffffff.
The iseg mapping in mlx5_nodnic_pci_init() has a similar gap.
ioremap(dev->bar_addr, sizeof(*dev->iseg)) never checks that
pci_resource_len(pdev, 0) is at least sizeof(*dev->iseg).
Would it make sense to validate the UAR offset and size against
pci_resource_len(dev->pdev, 0) in mlx5_nodnic_read_config()? A bad
value would then fail probe rather than the first ndo_open.
> + if (!base) {
> + mlx5_nodnic_core_err(dev, "failed to map UAR\n");
> + return -ENOMEM;
> + }
> +
> + dev->uar_base = base;
> +
> + return 0;
> +}
> +
> +static void mlx5_nodnic_cleanup_uar_map(struct mlx5_nodnic_core_dev *dev)
> +{
> + if (!dev->uar_base)
> + return;
> +
> + iounmap(dev->uar_base);
> + dev->uar_base = NULL;
> +}
> +
> +static int mlx5_nodnic_open_locked(struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> + int err;
> +
> + err = mlx5_nodnic_init_uar_map(dev);
> + if (err)
> + return err;
> +
> + err = mlx5_nodnic_open_queues(dev);
> + if (err)
> + goto err_uar;
> +
> + set_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
> +
> + err = mlx5_nodnic_refresh_carrier_locked(priv);
> + if (err)
> + netdev_err(netdev, "Failed to query carrier, err=%d\n", err);
> +
> + return 0;
> +
> +err_uar:
> + mlx5_nodnic_cleanup_uar_map(dev);
> + return err;
> +}
> +
> +int mlx5_nodnic_open(struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + int err;
> +
> + mutex_lock(&priv->state_lock);
> + err = mlx5_nodnic_open_locked(netdev);
> + mutex_unlock(&priv->state_lock);
> +
> + return err;
> +}
> +
> +static int mlx5_nodnic_close_locked(struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> +
> + clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state);
> + netif_carrier_off(netdev);
> + netdev_info(netdev, "Link down\n");
> + mlx5_nodnic_close_queues(dev);
> +
> + return 0;
> +}
> +
> +int mlx5_nodnic_close(struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + int err = 0;
> +
> + mutex_lock(&priv->state_lock);
> + if (!test_bit(MLX5_NODNIC_STATE_OPENED, &priv->state)) {
> + mutex_unlock(&priv->state_lock);
> + return 0;
> + }
> +
> + err = mlx5_nodnic_close_locked(netdev);
> + mutex_unlock(&priv->state_lock);
> +
> + mlx5_nodnic_cleanup_uar_map(priv->core_dev);
> +
> + return err;
> +}
> +
> +static const struct net_device_ops mlx5_nodnic_netdev_ops = {
> + .ndo_open = mlx5_nodnic_open,
> + .ndo_stop = mlx5_nodnic_close,
> +};
> +
> +void mlx5_nodnic_build_netdev(struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + struct mlx5_nodnic_core_dev *core_dev;
> +
> + core_dev = priv->core_dev;
> +
> + SET_NETDEV_DEV(netdev, core_dev->device);
> +
> + netdev->netdev_ops = &mlx5_nodnic_netdev_ops;
> + netdev->request_ops_lock = true;
> +
> + eth_hw_addr_set(netdev, core_dev->mac_address);
> +}
> +
> +static void mlx5_nodnic_init_priv(struct mlx5_nodnic_priv *priv,
> + struct net_device *netdev,
> + struct mlx5_nodnic_core_dev *core_dev)
> +{
> + priv->netdev = netdev;
> + priv->core_dev = core_dev;
> + mutex_init(&priv->state_lock);
> +}
> +
> +static void mlx5_nodnic_cleanup_priv(struct mlx5_nodnic_priv *priv)
> +{
> + mutex_destroy(&priv->state_lock);
> +}
> +
> +struct net_device *mlx5_nodnic_create_netdev(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_priv *priv;
> + struct net_device *netdev;
> +
> + netdev = alloc_etherdev_mqs(sizeof(struct mlx5_nodnic_priv), 1, 1);
> + if (!netdev)
> + return NULL;
> +
> + priv = netdev_priv(netdev);
> + mlx5_nodnic_init_priv(priv, netdev, dev);
> + dev->priv = priv;
> +
> + netif_carrier_off(netdev);
> + netif_tx_disable(netdev);
> + dev_net_set(netdev, &init_net);
> +
> + return netdev;
> +}
> +
> +void mlx5_nodnic_cleanup_netdev(struct mlx5_nodnic_core_dev *dev)
> +{
> + struct mlx5_nodnic_priv *priv;
> + struct net_device *netdev;
> +
> + if (!dev->priv)
> + return;
> +
> + priv = dev->priv;
> + netdev = priv->netdev;
> + if (!netdev)
> + return;
> +
> + if (dev->netdev_registered) {
> + netif_device_detach(netdev);
> + unregister_netdev(netdev);
> + dev->netdev_registered = false;
> + }
> +
> + mlx5_nodnic_cleanup_priv(priv);
> + dev->priv = NULL;
> +
> + free_netdev(netdev);
> +}
[Severity: Medium]
Is log_max_ring_size bounded anywhere? It is a 6-bit field, and
mlx5_nodnic_read_ring_config() stores it into dev->log_max_ring_size
without any check. Here it becomes the shift count for a 32-bit value,
so 1U << dev->log_max_ring_size is undefined for any value of 32 or
above. On x86 the shift count is masked, so a reported 32 gives
max_supported = 1.
Values inside the valid shift range can also go wrong. Anything below
ilog2(stride), which is 6 for the SQ and 4 for the RQ, makes size
smaller than one stride. mlx5_nodnic_init_ring() then sets
ring->num_entries = size / stride = 0 and does not fail. If size ends
up 0, we also pass 0 to dma_alloc_coherent() and call ilog2(0) in
mlx5_nodnic_write_ring_size().
A zero-entry ring breaks any num_entries - 1 masking once the data path
is added. Nothing later in the series validates this value.
What range does the spec allow for log_max_ring_size? Should
mlx5_nodnic_read_config() reject values outside it? That way a bad
capability fails probe instead of producing a broken ring on ndo_open.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203205721.4090361-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path
2026-12-03 20:57 ` [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path Tariq Toukan
@ 2026-12-04 21:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 21:45 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
cjubran, gal, linux-kernel, shshitrit
Thank you for your contribution! Sashiko AI review found 14 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 7 · Low: 7
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] This patch is the first to call mlx5_nodnic_enable_port(), so
its fixed RX filter setup now takes effect.
- [Medium] Error CQEs are never recovered.
- [Medium] mlx5_nodnic_handle_recv_cqe() takes `byte_count =
be32_to_cpu(cqe->byte_cnt)` straight from the device CQE and passes it…
- [Medium] On close, mlx5_nodnic_deactivate_queues() calls
mlx5_nodnic_quiesce_port(), which goes through…
- [Medium] net/mlx5: unratelimited log and unbudgeted loop in
mlx5_nodnic_napi_poll()
- [Medium] net/mlx5: nodnic advertises NETIF_F_HW_CSUM without generic
checksum offload
- [Medium] net/mlx5: nodnic: full-page RX buffers bloat ring and truesize
on 64K pages
- [Low] The commit message talks only about the TX/RX/NAPI data path, but
the patch also changes device-level control-path behaviour.
- [Low] mlx5_nodnic_xmit() never calls skb_tx_timestamp().
- [Low] In netpoll mode, poll_one_napi() calls napi->poll(napi, 0)
(net/core/netpoll.c).
- [Low] mlx5_nodnic_activate_queues() calls napi_enable_locked(), then
mlx5_nodnic_arm_cq(cq) from process context, then napi_schedule().
- [Low] mlx5_nodnic_tx_build_wqe_ds() assumes every skb is linear.
- [Low] net/mlx5: nodnic: duplicate dma_wmb() on TX path in
mlx5_nodnic_xmit()
- [Low] net/mlx5: nodnic: missing linux/types.h include in rx.h
--
net/mlx5: nodnic: Implement data path
This commit adds the TX and RX data paths for the mlx5_nodnic driver. It
covers WQE posting, BlueFlame doorbells, page pool backed RX and a NAPI
poll loop over a CQ shared by TX and RX. It also wires up ndo_start_xmit
and ndo_features_check and enables TX/RX checksum offload.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
> new file mode 100644
> index 0000000000000..6cbdfaf7cc01d
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
> @@ -0,0 +1,290 @@
[ ... ]
> +static void mlx5_nodnic_handle_err_cqe(struct mlx5_nodnic_cq *cq,
> + struct mlx5_cqe64 *cqe64,
> + int napi_budget)
> +{
[ ... ]
> + if (opcode == OPCODE_CQ_SEND_ERR) {
> + struct mlx5_nodnic_sq *sq = &priv->sq;
> + u16 sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
> +
> + mlx5_nodnic_complete_send_wqe(sq, &sq->wqe_info[sq_pi],
> + napi_budget);
> + } else {
> + struct mlx5_nodnic_rq *rq = &priv->rq;
> + u16 ci = wqe_counter & (rq->ring.num_entries - 1);
> +
> + mlx5_nodnic_release_rx_wqe(rq, ci);
> + }
> +}
[Severity: Medium]
Is there a recovery path for error CQEs? This releases only the single WQE
named by wqe_counter. Nothing marks the queue as errored, schedules
recovery work, or resets the SQ, RQ or port.
The syndrome table above decodes WR_FLUSH_ERR, LOCAL_QP_OP_ERR and
LOCAL_PROT_ERR. In the mlx5 CQE format these mean the queue has moved to
an error state and later WQEs get flushed.
On RX, mlx5_nodnic_napi_poll() reposts the freed slots unconditionally:
if (!mlx5_nodnic_rq_post_wqes(priv))
return budget;
If the device flushes those WQEs, each flush CQE counts as RX work. The
poll returns budget, so NAPI keeps cycling and printing rate-limited
errors. If the device doesn't flush them, RX stays dead.
On TX, every later packet would complete as a flush error and be freed,
and BQL would credit it as sent. The later "Add TX/RX statistics" commit
also counts these completions as transmitted packets in
mlx5_nodnic_sq_stats_inc().
There is no .ndo_tx_timeout either, so netdev_watchdog_up() returns early
and a stalled SQ is never detected. The carrier stays up while traffic is
dead until the interface is cycled. The later "Add health monitoring"
commit only polls firmware health, so it doesn't change this.
[ ... ]
> +int mlx5_nodnic_napi_poll(struct napi_struct *napi, int budget)
> +{
[ ... ]
> + while (true) {
> + cqe = mlx5_nodnic_cq_get_cqe(cq);
> + if (!cqe)
> + break;
> +
> + /* RX and TX share the CQ. With budget == 0 (netpoll) only TX
> + * completions may be processed, leave RX CQEs in place.
> + */
> + if (unlikely(!budget) && mlx5_nodnic_cqe_is_rx(cqe))
> + break;
[Severity: Medium]
The default case in mlx5_nodnic_handle_cqe() logs every unexpected
opcode with a plain netdev_err(). mlx5_nodnic_napi_poll() also doesn't
count MLX5_NODNIC_CQE_IGNORED against the RX budget or against
MLX5_NODNIC_TX_CQ_POLL_BUDGET.
Suppose buggy firmware or a faulty device fills the CQ with unexpected
opcodes. One poll can then walk all cq->num_entries entries in softirq
context and print an error for each, which can stall a slow console.
If the device keeps producing such CQEs with a matching owner bit, the
loop never exits at all. The netpoll budget == 0 check doesn't stop it
either, since mlx5_nodnic_cqe_is_rx() only matches the RECV and
RECV_ERR opcodes.
mlx5_nodnic_handle_err_cqe() in the same file already wraps its output
in net_ratelimit(). Should this message be rate limited as well? And
should ignored CQEs count toward some per-poll limit, so the loop is
always bounded?
[Severity: Low]
TX and RX share one in-order CQ. Doesn't breaking at the first RX CQE
here block every TX completion queued behind it?
Netpoll reaches this through poll_one_napi()->napi->poll(napi, 0). In
that case cc_pending_pkts stays 0 and mlx5_nodnic_sq_publish_cc() frees
no SQ slots.
Suppose NAPI can't run, for example netconsole during a panic or oops,
while RX traffic keeps arriving. Each netpoll retry would hit the same RX
CQE. Once the TX ring fills, the queue stays stopped and netconsole
output is dropped.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> index 738722671090b..b6adec5fc50d7 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
[ ... ]
> @@ -580,6 +650,156 @@ void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
> mutex_unlock(&priv->state_lock);
> }
>
[ ... ]
> +/* If the port can't be disabled, stop the device from mastering the bus,
> + * so it can't DMA into the buffers that are about to be freed.
> + * Bus mastering is restored on the next open.
> + */
> +static void mlx5_nodnic_quiesce_port(struct mlx5_nodnic_core_dev *dev)
> +{
> + int err;
> +
> + err = mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx);
> + if (!err) {
> + err = mlx5_nodnic_disable_port(dev);
> + mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
> + }
> +
> + if (err)
> + pci_clear_master(dev->pdev);
> +}
[Severity: Low]
This isn't a bug, but the commit message only describes the TX/RX/NAPI
data path. The patch also changes control-path behaviour:
- It adds the first callers of mlx5_nodnic_enable_port() and
mlx5_nodnic_disable_port(). ndo_open now enables network, DMA and
MSI-X on the port, and ndo_stop disables them.
- It changes mlx5_nodnic_disable_port() from void to int.
- It adds this pci_clear_master() fallback, which relies on
mlx5_nodnic_enable_port() to restore bus mastering.
- It requests a new data MSI-X IRQ in mlx5_nodnic_open_cq().
- It adds a new open error-unwind path.
Could the commit message mention these changes?
> +static int mlx5_nodnic_activate_queues(struct mlx5_nodnic_core_dev *dev)
> +{
[ ... ]
> + mlx5_nodnic_activate_sq(dev);
> +
> + napi_enable_locked(&cq->napi);
> + mlx5_nodnic_arm_cq(cq);
> + napi_schedule(&cq->napi);
[Severity: Low]
Can this mlx5_nodnic_arm_cq() call race with one from NAPI context on
another CPU?
After napi_enable_locked() the NAPI instance is live again and keeps its
persistent napi_config ID. A busy-polling socket holding the old
sk_napi_id can therefore run busy_poll_stop()->napi->poll(), and
mlx5_nodnic_napi_poll() calls mlx5_nodnic_arm_cq() after
napi_complete_done().
Neither path synchronizes with the other. Both read cq->cc and
cq->arm_sn, both write cq->dbr.db[1], and both issue mlx5_write64() to
the CQ doorbell. On 32-bit, mlx5_write64() is two __raw_writel() calls,
and include/linux/mlx5/doorbell.h says callers must serialize it.
The napi_schedule() that follows already arms the CQ when the poll
completes. Is the direct arm here needed?
[ ... ]
> +static void mlx5_nodnic_deactivate_queues(struct mlx5_nodnic_core_dev *dev)
> +{
> + napi_disable_locked(&dev->priv->cq.napi);
> + mlx5_nodnic_deactivate_sq(&dev->priv->sq);
> + mlx5_nodnic_quiesce_port(dev);
> + mlx5_nodnic_deactivate_rq(dev);
> +}
[Severity: Medium]
Is the device guaranteed to have stopped DMA before
mlx5_nodnic_deactivate_rq() returns every posted RX page to the page
pool?
mlx5_nodnic_disable_port() writes dma_en=0 and network_en=0 through the
VSC gateway. That write only waits for the gateway flag to clear.
Nothing reads back a DMA-idle or port-inactive status, and
pci_clear_master() is only used when the VSC access itself fails.
After that, mlx5_nodnic_rq_free_pages() puts the pages back and
page_pool_destroy() runs. Later, mlx5_nodnic_sq_free_pending() unmaps and
frees the in-flight TX skbs.
Firmware may guarantee that acknowledging dma_en=0 means all outstanding
DMA has drained. If it doesn't, could a frame written during close land
in a page already returned to the page allocator? Could TX DMA read
freed skb data?
[ ... ]
> @@ -764,6 +995,8 @@ int mlx5_nodnic_close(struct net_device *netdev)
> static const struct net_device_ops mlx5_nodnic_netdev_ops = {
> .ndo_open = mlx5_nodnic_open,
> .ndo_stop = mlx5_nodnic_close,
> + .ndo_start_xmit = mlx5_nodnic_xmit,
> + .ndo_features_check = mlx5_nodnic_check_features,
> };
[Severity: Medium]
This patch is the first to call mlx5_nodnic_enable_port(), which only
enables receive filter 0:
MLX5_SET(nodnic_port_network, &val, network_en, 1);
MLX5_SET(nodnic_port_network, &val, receive_filter_en, BIT(0));
The patch never sets promisc_en or promisc_multicast_en and never
programs the mac_filters table. There is also no .ndo_set_rx_mode, so
changes to the multicast list and to IFF_PROMISC or IFF_ALLMULTI never
reach the hardware.
If the receive filter drops frames that match no entry, will this
interface still receive IPv6 solicited-node multicast for neighbour
discovery, router advertisements, joined IGMP/MLD groups, or mDNS?
Promiscuous mode would also be silently ignored, which affects tcpdump,
bridge and macvlan setups. No later patch in the series appears to add
rx-mode handling.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
> new file mode 100644
> index 0000000000000..7736a1f24ea5b
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
> @@ -0,0 +1,169 @@
[ ... ]
> +void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
> + struct mlx5_cqe64 *cqe)
> +{
> + struct mlx5_nodnic_priv *priv = container_of(cq,
> + struct mlx5_nodnic_priv,
> + cq);
> + u32 byte_count = be32_to_cpu(cqe->byte_cnt);
[ ... ]
> + page_pool_dma_sync_for_cpu(rq->page_pool, page, 0, byte_count);
> +
> + skb = napi_build_skb(page_address(page), PAGE_SIZE);
> + if (unlikely(!skb))
> + goto err_recycle;
> +
> + skb_mark_for_recycle(skb);
> + rq->pages[ci] = NULL;
> +
> + skb_reserve(skb, MLX5_NODNIC_SKB_HEADROOM_BYTES);
> + skb_put(skb, byte_count);
> + skb->protocol = eth_type_trans(skb, priv->netdev);
[Severity: Medium]
Each RX WQE gets its own order-0 page, and napi_build_skb() is passed
PAGE_SIZE as the frag size. Frames are at most MLX5_NODNIC_HW_MTU
(1522) bytes.
On 4K pages that is about a 2x overhead. 64K page kernels are common on
the ARM64 hosts this BlueField device is paired with. There, a
1024-entry ring pins 64 MiB of DMA mapped memory, and every packet is
charged roughly 64K of skb->truesize.
That truesize hurts the stack:
- In tcp_measure_rcv_mss() the scaling_ratio drops to about 5/256,
which clamps the initial window to a couple of MSS.
- A few GRO-coalesced segments push the socket past sk_rcvbuf and into
tcp_prune_queue() and tcp_collapse().
- A UDP socket with the default rmem starts dropping after about three
queued packets.
Could the RX buffers instead be carved from a page with
page_pool_dev_alloc_frag() or page_pool_dev_alloc()? Each fragment
would be sized for the MTU plus headroom and skb_shared_info, and that
size passed to napi_build_skb(). The page pool offset and max_len for
PP_FLAG_DMA_SYNC_DEV would need adjusting to match.
[Severity: Medium]
byte_count comes straight from the device CQE. It is used for the DMA
sync and for skb_put() without being checked against the posted buffer
size (MLX5_NODNIC_HW_MTU) or the skb tailroom.
If a corrupted CQE or a misbehaving device reports a larger value, could
skb_put() hit skb_over_panic()?
A value below ETH_HLEN has a different problem: eth_type_trans() would
parse stale recycled page pool memory as the Ethernet header.
Would it be appropriate to recycle the page and drop the frame when a
check like this fails?
if (unlikely(byte_count < ETH_HLEN || byte_count > MLX5_NODNIC_HW_MTU))
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
> new file mode 100644
> index 0000000000000..c0dba88b49e01
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c
> @@ -0,0 +1,252 @@
[ ... ]
> +static int
> +mlx5_nodnic_tx_build_wqe_ds(struct mlx5_nodnic_sq *sq, struct sk_buff *skb,
> + struct mlx5_nodnic_wqe_data_seg *dseg)
> +{
> + dma_addr_t dma_addr = 0;
> +
> + dseg->byte_count = cpu_to_be32(skb->len & 0x7FFFFFFF);
> + dseg->lkey = cpu_to_be32(sq->ring.lkey);
> + dma_addr = dma_map_single(sq->device, skb->data, skb->len,
> + DMA_TO_DEVICE);
[Severity: Low]
This assumes the skb is linear. The driver doesn't advertise NETIF_F_SG,
so validate_xmit_skb() linearizes skbs on the normal dev_queue_xmit()
path.
pktgen is an exception. It accepts frags without checking device
features and transmits through netdev_start_xmit() directly.
For such an skb, skb->len is headlen + data_len. Would this mapping then
run past the linear head into skb_shared_info and adjacent slab memory,
and send those kernel bytes on the wire?
Would a skb_is_nonlinear() check (linearize or drop), or mapping only
skb_headlen(), be safer here?
[ ... ]
> +netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *netdev)
> +{
[ ... ]
> + WRITE_ONCE(sq->pc, sq->pc + 1);
> +
> + netdev_tx_sent_queue(sq->txq, skb->len);
> +
> + mlx5_nodnic_tx_notify_hw(priv, dev->uar_base, sq->pc, &wqe->ctrl);
[Severity: Low]
Should skb_tx_timestamp() be called here, before the doorbell is rung?
Without it, software TX timestamps requested through SO_TIMESTAMPING
(SOF_TIMESTAMPING_TX_SOFTWARE) are never generated for this interface.
No later patch in the series appears to add it.
[ ... ]
> @@ -0,0 +1,252 @@
> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> +// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +
> +#include <linux/dma-mapping.h>
> +#include <linux/errno.h>
> +#include <linux/kernel.h>
> +#include <linux/mlx5/doorbell.h>
> +#include <linux/net.h>
> +#include <linux/netdevice.h>
> +#include <linux/skbuff.h>
> +#include <linux/types.h>
> +#include <net/netdev_queues.h>
> +
> +#include "en.h"
> +#include "nodnic.h"
> +#include "tx.h"
> +
> +#define MLX5_NODNIC_OPCODE_SEND 0x0a
> +#define MLX5_NODNIC_DS_COUNT 3
> +#define MLX5_NODNIC_CE_ALWAYS 0x2
> +#define MLX5_NODNIC_SQ_STOP_ROOM 1
> +
> +static void mlx5_nodnic_tx_build_wqe_eseg(struct sk_buff *skb,
[Severity: Medium]
NETIF_F_HW_CSUM tells the stack the device can compute a generic ones'
complement checksum. The checksum starts at skb->csum_start and is
stored at skb->csum_start + skb->csum_offset.
mlx5_nodnic_tx_build_wqe_eseg() ignores both fields. It only sets the
L3/L4 checksum flags, which ask the hardware to parse the headers and
fill in the IPv4 and TCP/UDP checksums itself.
With NETIF_F_HW_CSUM set, skb_csum_hwoffload_help() returns early and
can_checksum_protocol() accepts any ethertype. The software fallback
therefore never runs for packets the hardware can't handle, and they
would go out with a wrong checksum. Examples:
- GRE with checksum. gre_build_header() points csum_start at the GRE
header, and iptunnel_handle_offloads() clears skb->encapsulation for
non-offloaded inner packets.
- IPv6 packets with extension headers.
- Arbitrary CHECKSUM_PARTIAL frames injected through PACKET_VNET_HDR
or tun.
mlx5_nodnic_check_features() doesn't catch these, because it only looks
at skb->encapsulation. Since hw_enc_features is 0,
__netif_skb_features() already strips checksum offload for
encapsulated skbs before it is called, so that check adds nothing.
Would NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM be a better match for what
the hardware does? The mlx5e representor and mlx5i netdevs use those.
Otherwise, mlx5_nodnic_check_features() would need to drop checksum
offload for anything that isn't plain TCP/UDP over IPv4/IPv6.
> + struct mlx5_nodnic_wqe_eth_seg *eseg)
> +{
> + u8 flags = 0;
> +
> + if (likely(skb->ip_summed == CHECKSUM_PARTIAL))
> + flags |= MLX5_NODNIC_ETH_WQE_L3_CSUM |
> + MLX5_NODNIC_ETH_WQE_L4_CSUM;
> +
> + eseg->cs_flags_mss = cpu_to_be32((u32)flags << 24);
> + eseg->inline_hdr_sz = 0;
> +}
> +
> +static void
> +mlx5_nodnic_tx_build_wqe_ctrl(struct mlx5_nodnic_sq *sq,
> + struct mlx5_nodnic_wqe_ctrl_seg *ctrl)
> +{
> + ctrl->opmod_idx_opcode = cpu_to_be32((sq->pc << 8) |
> + MLX5_NODNIC_OPCODE_SEND);
> + ctrl->qpn_ds = cpu_to_be32((sq->ring.qn << 8) | MLX5_NODNIC_DS_COUNT);
> + ctrl->fm_ce_se = cpu_to_be32(MLX5_NODNIC_CE_ALWAYS << 2);
> + ctrl->general_id = 0;
> +}
> +
> +static void mlx5_nodnic_tx_fill_wqe_info(struct mlx5_nodnic_sq *sq,
> + struct sk_buff *skb,
> + dma_addr_t dma_addr)
> +{
> + u16 pi = mlx5_nodnic_sq_get_pi(sq, sq->pc);
> +
> + sq->wqe_info[pi].skb = skb;
> + sq->wqe_info[pi].num_bytes = skb->len;
> + sq->wqe_info[pi].dma = dma_addr;
> +}
> +
> +static int
> +mlx5_nodnic_tx_build_wqe_ds(struct mlx5_nodnic_sq *sq, struct sk_buff *skb,
> + struct mlx5_nodnic_wqe_data_seg *dseg)
> +{
> + dma_addr_t dma_addr = 0;
> +
> + dseg->byte_count = cpu_to_be32(skb->len & 0x7FFFFFFF);
> + dseg->lkey = cpu_to_be32(sq->ring.lkey);
> + dma_addr = dma_map_single(sq->device, skb->data, skb->len,
> + DMA_TO_DEVICE);
> + if (unlikely(dma_mapping_error(sq->device, dma_addr)))
> + return -ENOMEM;
> +
> + dseg->addr = cpu_to_be64(dma_addr);
> +
> + mlx5_nodnic_tx_fill_wqe_info(sq, skb, dma_addr);
> +
> + return 0;
> +}
> +
> +static __always_inline int
> +mlx5_nodnic_tx_write_wqe(struct mlx5_nodnic_sq *sq, struct sk_buff *skb,
> + struct mlx5_nodnic_tx_wqe *wqe)
> +{
> + int err;
> +
> + memset(wqe, 0, MLX5_NODNIC_SQ_WQEBB_B);
> + mlx5_nodnic_tx_build_wqe_ctrl(sq, &wqe->ctrl);
> + mlx5_nodnic_tx_build_wqe_eseg(skb, &wqe->eth);
> + err = mlx5_nodnic_tx_build_wqe_ds(sq, skb, &wqe->data);
> + if (err)
> + return err;
> +
> + /* Ensure WQE stores are visible to the device before ringing the db */
> + dma_wmb();
> +
> + return 0;
> +}
> +
> +/* pc is written by xmit and cc by NAPI, see the barriers in
> + * netif_txq_maybe_stop() and netif_txq_completed_wake().
> + */
> +static u16 mlx5_nodnic_sq_room(struct mlx5_nodnic_sq *sq)
> +{
> + return sq->ring.num_entries -
> + (u16)(READ_ONCE(sq->pc) - READ_ONCE(sq->cc));
> +}
> +
> +static int mlx5_nodnic_tx_get_next_sq_offset(struct mlx5_nodnic_sq *sq)
> +{
> + u16 pi;
> +
> + pi = mlx5_nodnic_sq_get_pi(sq, sq->pc);
> + return pi * MLX5_NODNIC_SQ_WQEBB_B;
> +}
> +
> +static void mlx5_nodnic_tx_notify_hw(struct mlx5_nodnic_priv *priv,
> + void __iomem *uar_base, u16 pc,
> + struct mlx5_nodnic_wqe_ctrl_seg *ctrl)
> +{
> + /* ensure wqe is visible to device before updating doorbell record */
> + dma_wmb();
> +
> + priv->dbr.db[MLX5_NODNIC_SND_DBR] = cpu_to_be32(pc);
> +
> + /* ensure doorbell record is visible to device before ringing the
> + * doorbell
> + */
> + wmb();
> +
> + mlx5_write64((__be32 *)ctrl, uar_base + MLX5_BF_OFFSET);
> +}
> +
> +netdev_tx_t mlx5_nodnic_xmit(struct sk_buff *skb, struct net_device *netdev)
> +{
> + struct mlx5_nodnic_priv *priv = netdev_priv(netdev);
> + struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> + struct mlx5_nodnic_sq *sq = &priv->sq;
> + struct mlx5_nodnic_tx_wqe *wqe;
> + u16 next_offset;
> + int err;
> +
> + /* netif_txq_completed_wake can falsely wake while the ring is full, so
> + * check for room before touching the next descriptor.
> + */
> + if (unlikely(!netif_txq_maybe_stop(sq->txq, mlx5_nodnic_sq_room(sq),
> + MLX5_NODNIC_SQ_STOP_ROOM,
> + MLX5_NODNIC_SQ_STOP_ROOM)))
> + return NETDEV_TX_BUSY;
> +
> + next_offset = mlx5_nodnic_tx_get_next_sq_offset(sq);
> +
> + wqe = (struct mlx5_nodnic_tx_wqe *)((u8 *)sq->ring.wq + next_offset);
> +
> + err = mlx5_nodnic_tx_write_wqe(sq, skb, wqe);
> + if (err) {
> + dev_kfree_skb_any(skb);
> +
> + return NETDEV_TX_OK;
> + }
> +
> + WRITE_ONCE(sq->pc, sq->pc + 1);
> +
> + netdev_tx_sent_queue(sq->txq, skb->len);
> +
> + mlx5_nodnic_tx_notify_hw(priv, dev->uar_base, sq->pc, &wqe->ctrl);
> +
> + netif_txq_maybe_stop(sq->txq, mlx5_nodnic_sq_room(sq),
> + MLX5_NODNIC_SQ_STOP_ROOM,
> + MLX5_NODNIC_SQ_STOP_ROOM);
> +
> + return NETDEV_TX_OK;
> +}
> +
> +u16 mlx5_nodnic_sq_get_pi(struct mlx5_nodnic_sq *sq, u16 pc)
> +{
> + return pc & (sq->ring.num_entries - 1);
> +}
> +
> +void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq,
> + struct mlx5_cqe64 *cqe, int napi_budget)
> +{
> + struct mlx5_nodnic_priv *priv = container_of(cq,
> + struct mlx5_nodnic_priv,
> + cq);
> + struct mlx5_nodnic_sq *sq = &priv->sq;
> + struct mlx5_nodnic_tx_wqe_info *wi;
> + u16 pi;
> +
> + pi = mlx5_nodnic_sq_get_pi(sq, be16_to_cpu(cqe->wqe_counter));
> + wi = &sq->wqe_info[pi];
> +
> + mlx5_nodnic_complete_send_wqe(sq, wi, napi_budget);
> +}
> +
> +void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
> + struct mlx5_nodnic_tx_wqe_info *wi,
> + int napi_budget)
> +{
> + u32 num_bytes = wi->num_bytes;
> +
> + dma_unmap_single(sq->device, wi->dma, num_bytes, DMA_TO_DEVICE);
> + napi_consume_skb(wi->skb, napi_budget);
> +
> + /* The slot is handed back to xmit by mlx5_nodnic_sq_publish_cc(),
> + * after the CQ consumer index has reached the device.
> + */
> + sq->cc_pending_pkts++;
> + sq->cc_pending_bytes += num_bytes;
> +}
> +
> +void mlx5_nodnic_sq_publish_cc(struct mlx5_nodnic_sq *sq)
> +{
> + if (!sq->cc_pending_pkts)
> + return;
> +
> + WRITE_ONCE(sq->cc, sq->cc + sq->cc_pending_pkts);
> +
> + netif_txq_completed_wake(sq->txq, sq->cc_pending_pkts,
> + sq->cc_pending_bytes,
> + mlx5_nodnic_sq_room(sq),
> + MLX5_NODNIC_SQ_STOP_ROOM);
> +
> + sq->cc_pending_pkts = 0;
> + sq->cc_pending_bytes = 0;
> +}
> +
> +void mlx5_nodnic_sq_free_pending(struct mlx5_nodnic_sq *sq)
> +{
> + struct mlx5_nodnic_tx_wqe_info *wi;
> + unsigned int completed_bytes = 0;
> + unsigned int completed_pkts = 0;
> + u16 sqcc = sq->cc;
> + u16 ci;
> +
> + while (sqcc != sq->pc) {
> + ci = mlx5_nodnic_sq_get_pi(sq, sqcc);
> + wi = &sq->wqe_info[ci];
> +
> + dma_unmap_single(sq->device, wi->dma,
> + wi->num_bytes, DMA_TO_DEVICE);
> +
> + completed_pkts++;
> + completed_bytes += wi->num_bytes;
> +
> + dev_kfree_skb_any(wi->skb);
> +
> + sqcc++;
> + }
> +
> + if (completed_pkts)
> + netdev_tx_completed_queue(sq->txq, completed_pkts,
> + completed_bytes);
> + sq->cc = sqcc;
> +}
[Severity: Low]
mlx5_nodnic_tx_write_wqe() ends with a dma_wmb(). Its only caller,
mlx5_nodnic_xmit(), then calls mlx5_nodnic_tx_notify_hw(), which
starts with a second dma_wmb() for the same WQE-before-doorbell-record
ordering. In between, xmit only does the WRITE_ONCE() of sq->pc and
netdev_tx_sent_queue(), and neither of those touches the WQE.
So every transmitted packet pays for two identical barriers. Could the
one at the end of mlx5_nodnic_tx_write_wqe() be dropped? That would
keep the one right before the priv->dbr.db[MLX5_NODNIC_SND_DBR] store.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
> +// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +
> +#ifndef __MLX5_NODNIC_RX_H__
> +#define __MLX5_NODNIC_RX_H__
> +
> +struct mlx5_nodnic_priv;
> +struct mlx5_nodnic_cq;
> +struct mlx5_nodnic_rq;
> +struct mlx5_cqe64;
> +
> +struct mlx5_nodnic_rx_wqe {
> + __be32 byte_count;
> + __be32 lkey;
> + __be64 addr;
> +};
> +
> +int mlx5_nodnic_rq_alloc_pages(struct mlx5_nodnic_rq *rq);
> +void mlx5_nodnic_rq_free_pages(struct mlx5_nodnic_rq *rq);
> +bool mlx5_nodnic_rq_post_wqes(struct mlx5_nodnic_priv *priv);
> +void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
> + struct mlx5_cqe64 *cqe);
> +void mlx5_nodnic_release_rx_wqe(struct mlx5_nodnic_rq *rq, u16 ci);
> +
> +#endif /* __MLX5_NODNIC_RX_H__ */
[Severity: Low]
This isn't a bug, but rx.h uses __be32, __be64, u16 and bool without
including any header. It only builds because en.c, en_cfg.c and rx.c
pull in linux/types.h, directly or through en.h, before rx.h.
tx.h, added in the same patch, includes linux/types.h. Could rx.h do
the same so it is self-contained?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203205721.4090361-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics
2026-12-03 20:57 ` [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics Tariq Toukan
@ 2026-12-04 21:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 21:45 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
cjubran, gal, linux-kernel, shshitrit
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] When the device reports a send error,
`mlx5_nodnic_handle_err_cqe()`…
- [Low] RX accounting is incomplete.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
`mlx5_nodnic_handle_recv_cqe()` (rx.c) takes `byte_count` straight…
--
net/mlx5: nodnic: Add TX/RX statistics
This commit adds u64_stats based TX and RX packet and byte counters and a
TX drop counter to the nodnic driver. The counters are updated from the
NAPI completion paths and from ndo_start_xmit, and are exposed through
ndo_get_stats64.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
> index 6cbdfaf7cc01d..a8f5ce5507d54 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en.c
> @@ -85,10 +85,15 @@ static void mlx5_nodnic_handle_err_cqe(struct mlx5_nodnic_cq *cq,
>
> if (opcode == OPCODE_CQ_SEND_ERR) {
> struct mlx5_nodnic_sq *sq = &priv->sq;
> - u16 sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
> + struct mlx5_nodnic_tx_wqe_info *wi;
> + u16 sq_pi;
>
> - mlx5_nodnic_complete_send_wqe(sq, &sq->wqe_info[sq_pi],
> - napi_budget);
> + sq_pi = mlx5_nodnic_sq_get_pi(sq, wqe_counter);
> + wi = &sq->wqe_info[sq_pi];
> +
> + mlx5_nodnic_sq_stats_inc(&priv->sq_stats, wi);
[Severity: Medium]
Should an error completion count as a successfully transmitted packet here?
mlx5_nodnic_sq_stats_inc() always increments the same packets and bytes
counters that mlx5_nodnic_handle_send_cqe() uses for a good OPCODE_CQ_SEND
completion. mlx5_nodnic_update_sq_stats() then reports them as tx_packets
and tx_bytes.
Every TX WQE is posted with CE_ALWAYS in mlx5_nodnic_tx_build_wqe_ctrl():
ctrl->fm_ce_se = cpu_to_be32(MLX5_NODNIC_CE_ALWAYS << 2);
So each WQE produces either a SEND or a SEND_ERR CQE. Errors such as
LOCAL_PROT_ERR or LOCAL_LENGTH_ERR land here. Once the SQ enters the error
state, every outstanding WQE is flushed with WR_FLUSH_ERR. That could add up
to ring.num_entries (1024) failed packets and their bytes to tx_packets and
tx_bytes, while tx_errors and tx_dropped stay at zero.
The rtnl_link_stats64 kernel-doc in include/uapi/linux/if_link.h describes
tx_packets as packets successfully transmitted. It says transmit problems
belong in tx_errors. For comparison, mlx5e counts MLX5_CQE_REQ_ERR in a
separate cqe_err counter.
Could this path skip mlx5_nodnic_sq_stats_inc()? It could instead increment
an error counter under the NAPI syncp, reported as tx_errors (or
tx_dropped). It would still need to call mlx5_nodnic_complete_send_wqe() for
the unmap and free.
> +
> + mlx5_nodnic_complete_send_wqe(sq, wi, napi_budget);
> } else {
> struct mlx5_nodnic_rq *rq = &priv->rq;
> u16 ci = wqe_counter & (rq->ring.num_entries - 1);
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
> index 7736a1f24ea5b..58d6b033f5f67 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c
> @@ -140,6 +140,11 @@ void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq,
>
> page_pool_dma_sync_for_cpu(rq->page_pool, page, 0, byte_count);
>
> + u64_stats_update_begin(&priv->rq_stats.syncp);
> + u64_stats_inc(&priv->rq_stats.packets);
> + u64_stats_add(&priv->rq_stats.bytes, byte_count);
[Severity: Medium]
This isn't a bug introduced by this patch, but byte_count comes straight
from the device-written CQE and is never checked against the posted buffer
size:
u32 byte_count = be32_to_cpu(cqe->byte_cnt);
mlx5_nodnic_rq_post_one() posts each RX buffer with:
wqe->byte_count = cpu_to_be32(MLX5_NODNIC_HW_MTU);
Later in mlx5_nodnic_handle_recv_cqe() the value is used directly:
skb_reserve(skb, MLX5_NODNIC_SKB_HEADROOM_BYTES);
skb_put(skb, byte_count);
If faulty firmware reports a byte_cnt larger than the remaining tailroom,
could skb_put() hit skb_over_panic()? For values between
MLX5_NODNIC_HW_MTU and the tailroom, could stale page_pool contents end up
in the skb?
A correctly working device should not report more than the posted length.
The unchecked skb_put() came from the earlier commit "net/mlx5: nodnic:
Implement data path". This patch only adds rx_bytes as another consumer of
the value.
Would it be worth checking byte_count against MLX5_NODNIC_HW_MTU?
> + u64_stats_update_end(&priv->rq_stats.syncp);
> +
> skb = napi_build_skb(page_address(page), PAGE_SIZE);
> if (unlikely(!skb))
> goto err_recycle;
[Severity: Low]
This isn't really a bug, but should RX drops and errors be counted as well?
Counting rx_packets before napi_build_skb() is fine. The if_link.h
kernel-doc allows rx_packets to include packets the driver dropped. But
when napi_build_skb() fails, the frame is recycled through err_recycle and
mlx5_nodnic_release_rx_wqe(), and no drop counter is incremented.
The same goes for OPCODE_CQ_RECV_ERR completions. They take the else branch
of mlx5_nodnic_handle_err_cqe(), which only calls
mlx5_nodnic_release_rx_wqe().
struct mlx5_nodnic_rq_stats has no dropped or errors field, so
mlx5_nodnic_get_stats64() never fills rx_dropped or rx_errors.
Would it make sense to add these alongside the new TX drop counter?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203205721.4090361-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring
2026-12-03 20:57 ` [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring Tariq Toukan
@ 2026-12-04 21:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 21:45 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, willemb,
cjubran, gal, linux-kernel, shshitrit
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] On a fatal condition the new health monitor marks the device
as unhealthy, but the only thing that ever acts on that mark is the…
--
net/mlx5: nodnic: Add health monitoring
This adds a timer that polls the firmware health buffer in the
initialization segment every two seconds. It detects fatal device
conditions, health counter stalls and syndrome changes, logs them with
their severity, and marks the device as being in an internal error
state. Probe starts the polling and remove stops it.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> index 8eebd86e7a747..a45f651ed9ac2 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c
> @@ -919,6 +919,12 @@ static int mlx5_nodnic_open_locked(struct net_device *netdev)
> struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> int err;
>
> + if (READ_ONCE(dev->state) == NODNIC_DEVICE_STATE_INTERNAL_ERROR) {
> + netdev_err(netdev,
> + "Cannot open: device is in a fatal error state\n");
> + return -EIO;
> + }
> +
> err = mlx5_nodnic_init_uar_map(dev);
> if (err)
> return err;
> diff --git a/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c b/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
> new file mode 100644
> index 0000000000000..a2038eea9717f
> --- /dev/null
> +++ b/drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
[ ... ]
> +static void mlx5_nodnic_poll_health(struct timer_list *t)
> +{
> + struct mlx5_nodnic_priv *priv = timer_container_of(priv, t,
> + health.timer);
> + struct mlx5_nodnic_core_dev *dev = priv->core_dev;
> + struct mlx5_nodnic_health *health = &priv->health;
> + struct health_buffer __iomem *h = health->health;
> + u32 fatal_error, count;
> + u8 prev_synd;
> +
> + if (READ_ONCE(dev->state) == NODNIC_DEVICE_STATE_INTERNAL_ERROR)
> + return;
> +
> + fatal_error = mlx5_nodnic_health_check_fatal_sensors(dev);
> +
> + if (fatal_error && !health->fatal_error) {
> + mlx5_nodnic_core_err(dev, "fatal error detected: %s (%u)\n",
> + mlx5_nodnic_fatal_error_str(fatal_error),
> + fatal_error);
> + priv->health.fatal_error = fatal_error;
> + WRITE_ONCE(dev->state, NODNIC_DEVICE_STATE_INTERNAL_ERROR);
> + if (fatal_error != MLX5_NODNIC_SENSOR_PCI_COMM_ERR &&
> + fatal_error != MLX5_NODNIC_SENSOR_PCI_ERR)
> + mlx5_nodnic_print_health_info(dev);
> + return;
> + }
[Severity: Medium]
Is setting the state flag enough when the netdev is already open? Any of
the five fatal sensors (PCI error, PCI comm error, NIC disabled, NIC SW
reset, FW RFR) takes this branch. It logs, sets dev->state to
NODNIC_DEVICE_STATE_INTERNAL_ERROR, and returns without re-arming the
timer.
This branch calls none of netif_carrier_off(), netif_device_detach(),
napi_disable() or mlx5_nodnic_deactivate_queues(). Carrier stays up, NAPI
keeps re-arming the CQ, and ndo_start_xmit keeps ringing UAR doorbells on
a device that is reset, disabled or unreachable.
In the nodnic directory, dev->state is written in only two places:
mlx5_nodnic_probe_one() sets it to UP and this branch sets it to
INTERNAL_ERROR. It is read in only two places: the early return at the
top of mlx5_nodnic_poll_health() and the new check in
mlx5_nodnic_open_locked().
Nothing resets the state to UP, and the timer is not re-armed after this
branch. The pci_driver also has no err_handler or
reset_prepare/reset_done hooks.
Given that, can a single transient trigger make every later open fail
with -EIO until the driver is unbound and rebound? One example would be
sensor_pci_not_working() reading fw_ver == 0xffffffff once.
The close and remove paths also ignore the new state. These calls still
run VSC handshakes against a device already known to be dead:
mlx5_nodnic_close_locked()->mlx5_nodnic_deactivate_queues()
mlx5_nodnic_dev_cleanup()->mlx5_nodnic_write_nic_interface()
mlx5_nodnic_dev_cleanup()->mlx5_nodnic_wait_fw_init()
The waits are bounded by MLX5_NODNIC_FW_INIT_TIMEOUT_MS, and this
teardown behaviour predates the patch. Should these paths skip the
handshake once INTERNAL_ERROR is set?
For comparison, mlx5 core pairs these same sensors with
mlx5_enter_error_state() and health recovery work.
The commit message says:
"Report health errors together with their severity and mark the
device as unhealthy on fatal conditions."
Could it state that the only visible effect of the mark is a permanent
-EIO from ndo_open? The new mlx5_nodnic_printk() and mlx5_nodnic_log()
helpers in nodnic.h are not mentioned in the commit message either.
> +
> + count = ioread32be(health->health_counter);
> + if (count == health->prev_counter)
> + ++health->miss_counter;
> + else
> + health->miss_counter = 0;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203205721.4090361-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-04 21:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:57 [PATCH net-next V4 0/5] net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 2/5] net/mlx5: nodnic: Implement data path Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 3/5] net/mlx5: nodnic: Add TX/RX statistics Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
2026-12-03 20:57 ` [PATCH net-next V4 4/5] net/mlx5: nodnic: Add ethtool driver info Tariq Toukan
2026-12-03 20:57 ` [PATCH net-next V4 5/5] net/mlx5: nodnic: Add health monitoring Tariq Toukan
2026-12-04 21:45 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox