net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions
Subsystems (2)
v2 cover net/mlx5: Introduce mlx5_nodnic, a driver for DRAM-less NVIDIA Mellanox NIC functions
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.
Regards,
Tariq
V2:
- 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/[email protected]/
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 | 263 ++++ .../net/ethernet/mellanox/mlx5/nodnic/en.h | 158 +++ .../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 1107 +++++++++++++++++ .../ethernet/mellanox/mlx5/nodnic/health.c | 315 +++++ .../net/ethernet/mellanox/mlx5/nodnic/main.c | 866 +++++++++++++ .../ethernet/mellanox/mlx5/nodnic/nodnic.h | 105 ++ .../mellanox/mlx5/nodnic/nodnic_ifc.h | 318 +++++ .../mellanox/mlx5/nodnic/nodnic_pci_vsc.c | 343 +++++ .../mellanox/mlx5/nodnic/nodnic_pci_vsc.h | 45 + .../net/ethernet/mellanox/mlx5/nodnic/rx.c | 172 +++ .../net/ethernet/mellanox/mlx5/nodnic/rx.h | 25 + .../net/ethernet/mellanox/mlx5/nodnic/tx.c | 230 ++++ .../net/ethernet/mellanox/mlx5/nodnic/tx.h | 61 + 18 files changed, 4046 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: 8df0638138d3e0344fd1fb36cf2d1ca1cf5028f0
Signature · 1 line
2.44.0
PATCH v2 1/5 net/mlx5: nodnic: Introduce the mlx5_nodnic driver
From: Shahar Shitrit <[email protected]>
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.
--- 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 | 828 +++++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/main.c | 864 ++++++++++++++++++ .../ethernet/mellanox/mlx5/nodnic/nodnic.h | 105 +++ .../mellanox/mlx5/nodnic/nodnic_ifc.h | 318 +++++++ .../mellanox/mlx5/nodnic/nodnic_pci_vsc.c | 343 +++++++ .../mellanox/mlx5/nodnic/nodnic_pci_vsc.h | 45 + 12 files changed, 2637 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
MAINTAINERS +9 -0
@@ -16998,6 +16998,15 @@ F: drivers/infiniband/hw/mlx5/ F: include/linux/mlx5/ F: include/uapi/rdma/mlx5-abi.h +MELLANOX MLX5 NODNIC DRIVER +M: Shahar Shitrit <[email protected]> +M: Tariq Toukan <[email protected]> +L: [email protected] +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 <[email protected]> L: [email protected]
drivers/net/ethernet/mellanox/Kconfig +1 -0
@@ -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
drivers/net/ethernet/mellanox/Makefile +1 -0
@@ -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/
drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig new file +18 -0
@@ -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. +
drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile new file +8 -0
@@ -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
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h new file +97 -0
97 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +828 -0
828 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c new file +864 -0
864 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic.h new file +105 -0
105 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_ifc.h new file +318 -0
318 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +343 -0
343 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V2 1/5] net/mlx5: nodnic: Introduce the mlx5_nodnic driver
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider.
Critical: 1 · High: 4 · Medium: 1 · Low: 4
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Critical] mlx5: Fatal SQ/RQ size calculation mismatch causes DMA buffer overflow
- [High] Raw positive PCIBIOS_* codes from config-space accessors reach the PCI probe return, leading to use-after-free and double kfree.
- [High] Device DMA buffers can be freed while the device still has DMA enabled.
- [High] mlx5: CQ log_size hardware register is overwritten with zero during init
- [High] mlx5: 32-bit multiplication overflow in UAR physical address calculation
- [Medium] The only device this driver binds, 0x15b3:0xc2d6, is already listed by mlx5_core in mgt_ifc_device_ids[] (fw_reset.c:394,…
- [Low] mlx5_nodnic_build_netdev() installs the MAC that mlx5_nodnic_read_mac_address() read from device registers…
- [Low] (Baseline: not valid; fixed later in the series.) This patch registers a netdev whose ops have no ndo_start_xmit and no RX/NAPI…
- [Low] (Baseline: not valid.) The device-supplied size exponents (log_cq_size, log_max_ring_size, log_uar_page_size) are used in shifts…
- [Low] (Baseline: not valid.) The VSC read/write helpers mask address bits 31:30 instead of rejecting them, and do not check the syndrome…
--
net/mlx5: nodnic: Introduce the mlx5_nodnic driver
This commit adds mlx5_nodnic, a PCI driver for DRAM-less ConnectX NIC functions. It covers probe and remove (FLR, firmware readiness polling, interface negotiation and capability discovery). It also adds a VSC layer for config-space access to the init segment and the NODNIC registers, and a netdev with ndo_open/ndo_stop and a link-event IRQ.
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +0
-0@@ -0,0 +1,828 @@
[ ... ]
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +3
-0+/* 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) +{
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c line 292
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +3
-0+ 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;
[Severity: Low]
This isn't a bug, but log_cq_size comes straight from a device register. The same is true of log_max_ring_size in mlx5_nodnic_calc_ring_size() and log_uar_page_size in mlx5_nodnic_init_uar_map(). All three are used in shifts and size calculations with no range check.
mlx5_core also trusts FW-reported exponents, so this is only a hardening question. Would a sanity check on these values be worth adding?
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c line 524
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +10
-0+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: High]
Can the device still DMA into these buffers after they are freed?
mlx5_nodnic_open_queues() writes the ring, CQ, doorbell record and working buffer addresses to the device. Nothing here clears those registers before dma_free_coherent().
This patch doesn't call mlx5_nodnic_enable_port() yet. Later in the series, "net/mlx5: nodnic: Implement data path" adds mlx5_nodnic_deactivate_queues(), but it only disables the port if the VSC acquire succeeds:
if (!mlx5_nodnic_vsc_context_acquire(dev->vsc_ctx)) {
mlx5_nodnic_disable_port(dev);
mlx5_nodnic_vsc_context_release(dev->vsc_ctx);
}
mlx5_nodnic_deactivate_sq(&dev->priv->sq);
napi_disable_locked(&dev->priv->cq.napi);
mlx5_nodnic_deactivate_rq(dev);The acquire can fail with -EBUSY after VSC_MAX_RETRIES, with -EACCES, or on a set_space failure. A write inside mlx5_nodnic_disable_port() can also fail, and that only produces a warning. In any of these cases the RX pages go back to the page pool and the coherent buffers are freed. At that point network_en and dma_en are still set and bus mastering is still on.
The error paths in mlx5_nodnic_init_ring(), mlx5_nodnic_init_cq_ring() and mlx5_nodnic_init_working_buffer() follow the same pattern. Each one frees a buffer after its address has already been written to the device.
In mlx5_nodnic_remove_one(), mlx5_nodnic_cleanup_netdev() frees all of these buffers first. Only after that does mlx5_nodnic_dev_cleanup() set the interface to DISABLED and pci_disable_device() clear bus mastering.
Should the device side be shut down, or pci_clear_master() called as a fallback, before these buffers are freed?
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c line 754
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +4
-0+static const struct net_device_ops mlx5_nodnic_netdev_ops = { + .ndo_open = mlx5_nodnic_open, + .ndo_stop = mlx5_nodnic_close, +};
[Severity: Low]
This isn't a bug, but this patch registers a netdev with no ndo_start_xmit and no RX path. netif_tx_disable() in mlx5_nodnic_create_netdev() keeps the TX queue stopped, so the core never calls the missing callback.
The data path is added later in the series by "net/mlx5: nodnic:
Implement data path". Is it intended that this patch registers an interface that can't pass traffic yet?
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +4
-0+ +void mlx5_nodnic_build_netdev (struct net_device *netdev) +{ +struct mlx5_nodnic_priv *priv =netdev_priv (netdev);
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c line 768
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c new file +10
-0+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);
[Severity: Low]
Should the MAC from mlx5_nodnic_read_mac_address() be checked with is_valid_ether_addr() before it is installed here? If the device reports an all-zero or multicast address, that address is registered as the interface's unicast address.
For comparison, mlx5e_set_netdev_dev_addr() in mlx5_core falls back to eth_hw_addr_random() when the FW MAC is zero.
[ ... ]
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c new file +0
-0@@ -0,0 +1,864 @@
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c line 851
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c new file +13
-0+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, +};
[Severity: Medium]
How is this driver meant to interact with mlx5_core's sync FW reset? mlx5_core already lists 0xc2d6 in mgt_ifc_device_ids[] in drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c:
{ PCI_VDEVICE(MELLANOX, 0xc2d6) }, /* BlueField4 MGT interface device ID */Because of that entry, mlx5_check_dev_ids() lets the reset go ahead with this function present. mlx5_pci_link_toggle() then saves and locks every function on the bus, toggles the link and restores config space:
list_for_each_entry(sdev, &bridge_bus->devices, bus_list) {
pci_save_state(sdev);
pci_cfg_access_lock(sdev);
}This driver has no .err_handler and no reset_prepare/reset_done hooks, and none are added later in the series. Take a devlink reload with action fw_activate on the PF as an example. Afterwards, the device-side state this driver programmed would be gone: nic_interface=NO_DRAM_NIC, the ring/CQ/DBR/working buffer addresses, and the port and MSI-X enables. The netdev would stay registered with stale software state.
The commit message doesn't mention this coupling with mlx5_core's reset flow. Is it expected?
[ ... ]
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +0
-0@@ -0,0 +1,343 @@
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c line 46
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +11
-0+static int mlx5_nodnic_vsc_pci_read (struct mlx5_nodnic_vsc_ctx *ctx, +unsigned int offset,u32 *val) +{ +return pci_read_config_dword (ctx->pdev, ctx->addr + offset, val); +} + +static int mlx5_nodnic_vsc_pci_write (struct mlx5_nodnic_vsc_ctx *ctx, +unsigned int offset,u32 val) +{ +return pci_write_config_dword (ctx->pdev, ctx->addr + offset, val); +}
[Severity: High]
Should these convert the return value with pcibios_err_to_errno()?
pci_read_config_dword() and pci_write_config_dword() return positive PCIBIOS_* codes, for example PCIBIOS_DEVICE_NOT_FOUND once the device is disconnected. Every caller up the stack only checks if (err) and passes the value up unchanged, so mlx5_nodnic_probe_one() can end up returning a positive value:
mlx5_nodnic_probe_one()
mlx5_nodnic_dev_init()
mlx5_nodnic_wait_fw_init()
mlx5_nodnic_vsc_context_acquire()
mlx5_nodnic_vsc_gw_lock()
mlx5_nodnic_vsc_pci_read()On that path, probe calls kfree(dev) and returns the positive value. drvdata, set in mlx5_nodnic_pci_init(), still points at dev. local_pci_probe() treats a positive return as success:
if (rc < 0) {
pci_dev->driver = NULL;
pm_runtime_put_sync(dev);
return rc;
}
...
pci_warn(pci_dev, "Driver probe function unexpectedly returned %d\n",
rc);
return 0;So the driver stays bound, and the next unbind calls mlx5_nodnic_remove_one(). It gets the freed dev from pci_get_drvdata(), releases the IRQ vectors, the iseg mapping, the regions and vsc_ctx a second time, and then calls kfree(dev) again.
mlx5_nodnic_vsc_gw_lock() checks pci_channel_offline() only at the top of each loop iteration. Probe can also spend minutes in mlx5_nodnic_wait_fw_init(). A surprise removal or DPC event in that window looks like enough to hit this.
ndo_open can return the same kind of value through mlx5_nodnic_open()->mlx5_nodnic_open_locked()->mlx5_nodnic_open_queues() ->mlx5_nodnic_vsc_context_acquire(). netif_open() only checks for ret < 0:
ret = __dev_open(dev, extack); if (ret < 0) return ret; rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP | IFF_RUNNING, GFP_KERNEL, 0, NULL); call_netdevice_notifiers(NETDEV_UP, dev);
That would send RTM_NEWLINK and NETDEV_UP for an interface that __dev_open() left down.
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c line 244
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +7
-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 );
[Severity: Low]
This isn't a bug, but this masks off bits 31:30 of the address instead of rejecting it. Neither mlx5_nodnic_vsc_read() nor mlx5_nodnic_vsc_write() checks the syndrome bit after the flag changes.
Those address bits can only be set if the FW-supplied ctx->offset is 1 GiB or more. mlx5_vsc_gw_read() and mlx5_vsc_gw_write() in mlx5_core skip the syndrome check as well.
Should an out-of-range address or a reported syndrome be returned as an error here?
[ ... ]
Quoted 305 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +304
-0@@ -0,0 +1,828 @@ +// 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 <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; + } + + addr_l =0 ; +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; +
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c line 314
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +10
-0+ 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,
[Severity: High]
Does this leave the CQ log_size field set to zero?
mlx5_nodnic_read_cq_ring_size() reads log_size out of MLX5_NODNIC_PORT_CQ_ADDR_L and sizes the CQ from it. Right after that, mlx5_nodnic_write_ring_addr() starts from addr_l = 0, sets only q_addr_l and writes the whole dword back to the same register. That clears the log_size bits that were just read.
For the SQ and RQ, mlx5_nodnic_init_ring() follows the address write with mlx5_nodnic_write_ring_size(), which does a read-modify-write and puts log_size back. mlx5_nodnic_init_cq_ring() has no equivalent step, and nothing else in mlx5_nodnic_open_cq() writes the CQ size.
FW might stop looking at log_size in this register once it has set it. If it doesn't, the device would see a single-entry CQ while cq->num_entries in the driver says otherwise. Completions would then keep landing on the first CQE.
Should mlx5_nodnic_write_ring_addr() preserve the other bits of the low dword with a read-modify-write? Or should the CQ path rewrite log_size after the address, the way the SQ/RQ path does?
Quoted 333 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +333
-0+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) +{ +return 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 =1U << 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; + } + +/* 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); +}
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c line 657
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +10
-0+ +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 =1 << dev->log_uar_page_size; + + paddr = dev->bar_addr + (dev->send_ring0_uar_index * uar_page_size);
[Severity: High]
Can this multiplication wrap?
dev->send_ring0_uar_index and uar_page_size are both u32, so the product is computed in 32 bits and only widened to phys_addr_t for the addition to dev->bar_addr. With a 4 KiB UAR page, any index of 0x100000 or more wraps. ioremap() then maps a page at the wrong offset in BAR 0, possibly overlapping the init segment or other device registers.
dev->uar_base is meant to be the TX doorbell page; probe insists on support_uar_tx_doorbell. With a wrapped offset, doorbell writes would go to whatever register happens to sit at that offset.
Should the product be computed as (phys_addr_t)dev->send_ring0_uar_index * uar_page_size? Both values come from FW, so it also seems worth checking that the mapped range fits inside pci_resource_len(pdev, 0) before calling ioremap().
Quoted 161 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +161
-0+ + 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 (dev->priv); +if (err) +netdev_err (dev->priv->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 (priv->netdev); +netdev_info (priv->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) {
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c line 828
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/nodnic_pci_vsc.c new file +10
-0+netif_device_detach (netdev); +unregister_netdev (netdev); + dev->netdev_registered = false; + } + +mlx5_nodnic_cleanup_priv (priv); + dev->priv =NULL ; + +free_netdev (netdev); +}
[Severity: Critical]
Is the log_size written here meant to be in bytes or in entries?
mlx5_nodnic_calc_ring_size() returns a byte count, MLX5_NODNIC_RING_ENTRIES * stride. That is 1024 * 64 = 64 KiB for the SQ and 1024 * 16 = 16 KiB for the RQ. mlx5_nodnic_write_ring_size() then programs ilog2() of that byte count into the log_size field of nodnic_q_addr_l.
The CQ path reads the same log_size field of nodnic_q_addr_l and treats it as an entry count. mlx5_nodnic_read_cq_ring_size() sets cq->num_entries to 1 << log_cq_size, and mlx5_nodnic_init_cq_ring() allocates num_entries * MLX5_NODNIC_CQE_SIZE_B bytes.
If the SQ/RQ field has the same meaning, the device is told the SQ has 65536 WQEBBs and the RQ has 16384 entries. Only 1024 of each were allocated with dma_alloc_coherent(). Once the device's view of the ring goes past the allocation, it would read or write beyond the end of the coherent buffer.
The clamp in mlx5_nodnic_calc_ring_size() has the same problem. It compares the byte count against 1U << dev->log_max_ring_size, so if log_max_ring_size is in entries, the cap is off by a factor of stride. log_max_ring_size is also a 6-bit FW field, so a value of 32 or more makes the shift undefined.
Could you confirm which units the HW spec uses for log_size and log_max_ring_size, and make the SQ, RQ and CQ paths agree on them?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008171821.660739-1-tariqt%40nvidia.com
PATCH v2 2/5 net/mlx5: nodnic: Implement data path
In reply to Tariq ToukanFrom: Shahar Shitrit <[email protected]>
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.
--- .../net/ethernet/mellanox/mlx5/nodnic/Kconfig | 1 + .../ethernet/mellanox/mlx5/nodnic/Makefile | 2 +- .../net/ethernet/mellanox/mlx5/nodnic/en.c | 263 ++++++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/en.h | 35 +++ .../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 220 +++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/rx.c | 169 +++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/rx.h | 25 ++ .../net/ethernet/mellanox/mlx5/nodnic/tx.c | 226 +++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/tx.h | 61 ++++ 9 files changed, 1001 insertions(+), 1 deletion(-) 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
drivers/net/ethernet/mellanox/mlx5/nodnic/Kconfig +1 -0
@@ -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
drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile +1 -1
@@ -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
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +263 -0
263 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h +35 -0
@@ -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 +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,24 @@ 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; };struct mlx5_nodnic_rq { +struct page_pool *page_pool;struct mlx5_nodnic_ring ring; +struct page **pages;u16 pc;u16 cc; };
@@ -62,9 +87,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 +123,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__ */
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +220 -0
302 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c new file +169 -0
169 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.h new file +25 -0
@@ -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__ */
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c new file +226 -0
226 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V2 2/5] net/mlx5: nodnic: Implement data path
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 3 · Medium: 6 · 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).
- [High] mlx5_nodnic_activate_queues() (en_cfg.c) calls napi_enable_locked() first.
- [High] mlx5_nodnic_deactivate_queues() (en_cfg.c, added in this patch) calls mlx5_nodnic_disable_port() only if…
- [High] TX stop/wake between mlx5_nodnic_xmit() and mlx5_nodnic_complete_send_wqe() uses plain, unannotated sq->cc/sq->pc…
- [Medium] mlx5_nodnic_handle_err_cqe() (drivers/net/ethernet/mellanox/mlx5/nodnic/en.c) handles…
- [Medium] mlx5_nodnic_napi_poll() (en.c) does not handle budget == 0.
- [Medium] In mlx5_nodnic_napi_poll() (en.c), when '++tx_work_done >= MLX5_NODNIC_TX_CQ_POLL_BUDGET' (128) the loop jumps to poll_done while…
- [Medium] The CQ consumer-index doorbell record (cq->dbr.db[0], set_ci) is written only in mlx5_nodnic_arm_cq(), which runs only after…
- [Medium] mlx5_nodnic_handle_recv_cqe() (rx.c) passes the device- reported byte_cnt to page_pool_dma_sync_for_cpu() and skb_put()…
- [Medium] mlx5_nodnic_enable_port() makes three separate PORT_NETWORK
writes: data/event MSI-X enable, then network_en plus…
--
net/mlx5: nodnic: Implement data path
This commit implements the TX and RX data paths for the mlx5_nodnic driver. It adds WQE posting with a BlueFlame doorbell, page pool backed RX, and a single NAPI context that dispatches TX and RX CQEs. It also wires up ndo_start_xmit and ndo_features_check and enables TX/RX checksum offload.
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +4
-0+static void mlx5_nodnic_handle_err_cqe (struct mlx5_nodnic_cq *cq, +struct mlx5_cqe64 *cqe64, +int napi_budget) +{
[ ... ]
Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +12
-0+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);
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c line 95
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +10
-0+ +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 the SQ or RQ after an error CQE?
mlx5_nodnic_handle_err_cqe() calls netdev_err() and does a 64 byte print_hex_dump() at KERN_ERR. Neither is rate limited. It then completes or releases the one WQE named by wqe_counter and carries on. Nothing stops, resets or recovers the queue.
The driver decodes MLX5_CQE_SYNDROME_WR_FLUSH_ERR, so it seems to expect mlx5 flush-after-error behaviour. If so, one non-flush error (for example LOCAL_LENGTH_ERR) would make every later TX WQE come back as a flush error.
mlx5_nodnic_napi_poll() also reposts every released RX WQE through mlx5_nodnic_rq_post_wqes(). An errored RQ would flush them straight back.
Could one hardware error then become a flood of KERN_ERR output from softirq context? TX and RX would stay dead until the interface is bounced, while the queue and carrier still look up.
[ ... ]
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +2
-0+int mlx5_nodnic_napi_poll (struct napi_struct *napi,int budget) +{
[ ... ]
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +5
-0+while (true) { + cqe =mlx5_nodnic_cq_get_cqe (cq); +if (!cqe) +break ; +
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c line 233
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +10
-0+ 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 ;
[Severity: Medium]
Does this poll handle budget == 0? netpoll calls it with a zero budget:
net/core/netpoll.c:poll_one_napi() {
...
work = napi->poll(napi, 0);
...
}The next CQE is fully handled before the budget is checked.
For an RX CQE, mlx5_nodnic_handle_recv_cqe() calls page_pool_dma_sync_for_cpu(), napi_build_skb() and napi_gro_receive(). For an RX error CQE, mlx5_nodnic_release_rx_wqe() calls page_pool_put_full_page() with allow_direct set to true.
Only after that does ++rx_work_done >= budget exit the loop. poll_done then always calls mlx5_nodnic_rq_post_wqes(), which allocates from the page pool.
Documentation/networking/napi.rst says that with a zero budget only TX completions should be processed, and page pool and RX APIs must not be used.
With netconsole on this netdev, netpoll can run from hardirq or printk context. Can this path then touch the page pool's lockless cache, the per-CPU NAPI skb cache and GRO? Could those get corrupted if it interrupts a softirq user on the same CPU?
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c line 244
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +11
-0+case MLX5_NODNIC_CQE_IGNORED : +break ; + } + } + +poll_done: +if (!mlx5_nodnic_rq_post_wqes (priv)) +return budget; + +if (rx_work_done >= budget) +return budget;
[Severity: Medium]
On both return budget paths, does the device ever see an updated CQ consumer index?
The CQ doorbell record consumer index is only written in mlx5_nodnic_arm_cq():
cq->dbr.db[0] = cpu_to_be32(ci);
That only runs after napi_complete_done() succeeds.
Under sustained RX that fills the budget on every pass, NAPI never completes. cq->cc keeps advancing in software, but db[0] keeps the value from the last arm.
Meanwhile mlx5_nodnic_rq_post_wqes() keeps reposting RX WQEs based on the software rq->cc. mlx5_nodnic_complete_send_wqe() keeps freeing SQ slots and waking TX.
Suppose the device uses set_ci for CQ overrun detection like other mlx5 devices. Could it then see more outstanding CQEs than the CQ size and report an overrun or stall, even though software has consumed every entry?
For comparison, mlx5e updates the CQ doorbell record with mlx5_cqwq_update_db_record() at the end of every poll pass.
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c line 250
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.c new file +6
-0+ +if (napi_complete_done (napi, rx_work_done)) +mlx5_nodnic_arm_cq (cq); + +return rx_work_done; +}
[Severity: Medium]
When the loop exits because tx_work_done reached MLX5_NODNIC_TX_CQ_POLL_BUDGET, more CQEs may still be pending:
case MLX5_NODNIC_CQE_TX: if (++tx_work_done >= MLX5_NODNIC_TX_CQ_POLL_BUDGET) goto poll_done;
Suppose the RQ refill succeeds and rx_work_done < budget. This path then calls napi_complete_done(), re-arms the CQ and returns less than budget, even though polling stopped with work left.
Should this return budget instead, as mlx5e does when its TX poll hits its limit?
As written, the remaining TX completions, and any RX CQEs behind them, depend on the device raising an event when armed with unconsumed CQEs. If it only signals on new CQE writes, TX completions could stall with the SQ stopped. There is no ndo_tx_timeout to recover.
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +0
-0@@ -573,6 +643,143 @@ void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv)
[ ... ]
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +11
-0+static int mlx5_nodnic_activate_queues (struct mlx5_nodnic_core_dev *dev) +{ +struct mlx5_nodnic_cq *cq = &dev->priv->cq; +int err; + +napi_enable_locked (&cq->napi); + +mlx5_nodnic_init_cqes_ownership (cq); + + err =mlx5_nodnic_activate_rq (dev); +if (err)
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv) · line 754
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +10
-0+ goto err_napi; + + 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_rq;
[Severity: Medium]
If mlx5_nodnic_enable_port() fails after its first or second write, is the port left partly enabled?
mlx5_nodnic_enable_port() makes three separate PORT_NETWORK writes: MSI-X enable, then network_en plus receive_filter_en, then dma_en. It returns early on failure and does not roll back.
This unwind goes to err_rq without calling mlx5_nodnic_disable_port(). mlx5_nodnic_open_locked() then reaches:
err_close:
clear_bit(MLX5_NODNIC_STATE_OPENED, &priv->state); mlx5_nodnic_close_queues(dev);
That frees the rings, DBRs and working buffer, but their addresses are still programmed in the device.
The dma_en write might take effect but still be reported as failed, for example on a VSC flag-wait timeout. Could the device then DMA into freed memory?
mlx5_nodnic_disable_port() also notes that data_msix_en and event_msix_en can't be modified while the port is active. Could the leftover state make the first enable_port write on the next open ineffective?
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +5
-0+ +mlx5_nodnic_arm_cq (cq); +napi_schedule (&cq->napi); + +mlx5_nodnic_activate_sq (dev);
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv) · line 769
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +10
-0+ +return 0 ; + +err_rq: +mlx5_nodnic_deactivate_rq (dev); +err_napi: +napi_disable_locked (&cq->napi); + +return err; +}
[Severity: High]
Is this unwind order safe?
mlx5_nodnic_activate_rq() creates the page pool with
.napi = &priv->cq.napi. On the err_rq path, mlx5_nodnic_deactivate_rq() frees rq->pages and calls page_pool_destroy() while NAPI is still enabled. Only after that does err_napi call napi_disable_locked(). The err_destroy_page_pool path inside mlx5_nodnic_activate_rq() has the same problem.
page_pool_destroy() reaches this check through page_pool_disable_direct_recycling()->napi_assert_will_not_race():
WARN_ON(!test_bit(NAPI_STATE_SCHED, &napi->state));
napi_enable_locked() has already cleared that bit. So wouldn't any open failure after page_pool_create() hit this WARN? That covers RX page allocation, VSC acquire and enable_port failures. The pool is also torn down without synchronizing against a running poll.
mlx5_nodnic_deactivate_queues() uses the other order: it calls napi_disable_locked() before mlx5_nodnic_deactivate_rq().
A related question is why napi_enable_locked() runs first. It comes before mlx5_nodnic_init_cqes_ownership(), before mlx5_nodnic_activate_rq() sets up rq->page_pool and rq->pages, and before mlx5_nodnic_activate_sq() sets sq->txq.
napi_enable_locked()->napi_restore_config() re-hashes the napi_id kept from the previous session. A busy-polling socket can then call mlx5_nodnic_napi_poll() straight away, without the netdev or state lock.
On reopen, rq->pages still points at the array freed by mlx5_nodnic_rq_free_pages() during the previous close:
kvfree(rq->pages);
rq->page_pool still points at the pool destroyed then, and open_rq has reset rq->pc and rq->cc to 0. Can mlx5_nodnic_rq_post_wqes()->mlx5_nodnic_rq_post_one() then read rq->pages[pi] and call page_pool_dev_alloc_pages(rq->page_pool) on freed memory?
Before the ownership init runs, the zeroed CQ ring has op_own == 0. That matches software ownership 0 and opcode OPCODE_CQ_SEND. Would a poll in that window complete a bogus send through wqe_info[0] and push sq->cc past sq->pc?
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c void mlx5_nodnic_refresh_carrier(struct mlx5_nodnic_priv *priv) · line 781
Quoted 12 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +12
-0+ +static void mlx5_nodnic_deactivate_queues (struct mlx5_nodnic_core_dev *dev) +{ +if (!mlx5_nodnic_vsc_context_acquire (dev->vsc_ctx)) { +mlx5_nodnic_disable_port (dev); +mlx5_nodnic_vsc_context_release (dev->vsc_ctx); + } + +mlx5_nodnic_deactivate_sq (&dev->priv->sq); +napi_disable_locked (&dev->priv->cq.napi); +mlx5_nodnic_deactivate_rq (dev); +}
[Severity: High]
What happens to the device if mlx5_nodnic_vsc_context_acquire() fails here?
Acquire can fail with -EBUSY when the gateway semaphore is still held after VSC_MAX_RETRIES in mlx5_nodnic_vsc_gw_lock(). It can also fail with -EACCES, or when setting the space fails. In all of these cases mlx5_nodnic_disable_port() is skipped. Even when it is called, it returns void and only warns if its read or write of PORT_NETWORK fails.
Either way teardown continues. mlx5_nodnic_deactivate_rq() returns the device-owned RX pages to the page pool and destroys it. mlx5_nodnic_close_queues() then frees the coherent memory:
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);
At that point the device still has network_en and dma_en set and the ring and DBR addresses programmed. Its RX WQEs still point at the freed pages.
Can an incoming packet then be DMA-written into pages that are back in the page allocator? Can the device keep fetching the freed SQ ring and doorbell records?
Even when the disable write succeeds, nothing reads back or waits for in-flight DMA to drain.
[ ... ]
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c new file +3
-0+void mlx5_nodnic_handle_recv_cqe (struct mlx5_nodnic_cq *cq, +struct mlx5_cqe64 *cqe) +{
[ ... ]
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c new file +1
-0+u32 byte_count =be32_to_cpu (cqe->byte_cnt);
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c line 151
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c new file +11
-0+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);
[Severity: Medium]
This is mostly a hardening question. byte_count comes straight from the CQE and is passed to page_pool_dma_sync_for_cpu() and skb_put(). It is never checked against the posted buffer size (MLX5_NODNIC_HW_MTU) or the skb tailroom.
A CQE with byte_cnt above roughly PAGE_SIZE - NET_SKB_PAD minus the skb_shared_info size would hit skb_over_panic()->BUG().
This needs a buggy or misbehaving device. Every RX WQE is posted with byte_count = MLX5_NODNIC_HW_MTU, mlx5-family hardware normally reports oversize frames as LOCAL_LENGTH_ERR, and the mlx5e linear RX path doesn't check this either. Would a cheap bound check here still be worthwhile?
[ ... ]
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c new file +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c new file +6
-0+static int mlx5_nodnic_tx_is_sq_full (struct mlx5_nodnic_sq *sq) +{ +u16 pending = (u16)(sq->pc - sq->cc); + +return pending == sq->ring.num_entries -MLX5_NODNIC_SQ_STOP_ROOM ; +}
[ ... ]
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c new file +2
-0+netdev_tx_t mlx5_nodnic_xmit (struct sk_buff *skb,struct net_device *netdev) +{
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c line 149
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c new file +13
-0+if (unlikely (mlx5_nodnic_tx_is_sq_full (sq))) +netif_tx_stop_queue (sq->txq); + + 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 ; + }
[Severity: High]
Is the stop/wake handshake between mlx5_nodnic_xmit() and mlx5_nodnic_complete_send_wqe() safe on weakly ordered CPUs?
sq->pc and sq->cc use plain loads and stores with no barriers. xmit does not re-check after stopping, and the full test only matches pending == num_entries - 1.
When pending == N - 1, xmit stops the queue and still posts, which leaves the ring full (pending == N). NAPI then does:
sq->cc++; if (netif_tx_queue_stopped(txq)) netif_tx_wake_queue(txq);
On the next xmit, nothing orders the load of sq->cc after the observation that XOFF was cleared. On arm64 or POWER that load can return the old cc. pending is then N, the == N - 1 check fails, and the queue is not stopped. That post uses the slot just freed, so the ring is now truly full with the queue still running.
The xmit after that again sees pending == N and does not stop. It writes the WQE and wqe_info at pc & (N - 1), the slot of the oldest WQE the hardware still owns.
Can this corrupt an in-flight descriptor, lose its skb and DMA mapping, and let pc run past cc + N?
On the completion side, cc++ followed by test_bit() of XOFF has no full barrier to pair with xmit's load of cc followed by set_bit().
The dma mapping failure path above also returns after netif_tx_stop_queue() without posting anything. With that path in the mix, could the queue end up stopped with nothing outstanding to wake it?
netif_txq_maybe_stop() and netif_txq_completed_wake() in include/net/netdev_queues.h provide the smp_mb(), a >= test and the re-check. Would they fit here?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008171821.660739-1-tariqt%40nvidia.com
PATCH v2 3/5 net/mlx5: nodnic: Add TX/RX statistics
In reply to Tariq ToukanFrom: Shahar Shitrit <[email protected]>
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.
--- .../net/ethernet/mellanox/mlx5/nodnic/en.h | 14 +++++++++++ .../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 25 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/rx.c | 3 +++ .../net/ethernet/mellanox/mlx5/nodnic/tx.c | 4 +++ 4 files changed, 46 insertions(+)
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h +14 -0
@@ -44,6 +44,17 @@ enum mlx5_nodnic_cqe_opcode { OPCODE_CQ_INVALID, }; +struct mlx5_nodnic_sq_stats { +u64 packets; +u64 bytes; +u64 dropped; +}; + +struct mlx5_nodnic_rq_stats { +u64 packets; +u64 bytes; +}; +struct mlx5_nodnic_ring {void *wq;dma_addr_t dma_handle;
@@ -109,6 +120,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 */
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +25 -0
@@ -963,10 +963,35 @@ 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) +{ + s->tx_packets = sq->packets; + s->tx_bytes = sq->bytes; + s->tx_dropped = sq->dropped; +} + +static void mlx5_nodnic_update_rq_stats (const struct mlx5_nodnic_rq_stats *rq, +struct rtnl_link_stats64 *s) +{ + s->rx_packets = rq->packets; + s->rx_bytes = rq->bytes; +} + +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, };
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c +3 -0
@@ -152,6 +152,9 @@ void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq, skb->protocol =eth_type_trans (skb, priv->netdev);nodnic_handle_rx_csum (priv->netdev, cqe, skb); + priv->rq_stats.packets++; + priv->rq_stats.bytes += byte_count; +napi_gro_receive (&cq->napi, skb); rq->cc++;
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c +4 -0
@@ -143,6 +143,7 @@ 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) { + priv->sq_stats.dropped++;dev_kfree_skb_any (skb);return NETDEV_TX_OK ;
@@ -176,6 +177,9 @@ void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq, wi = &sq->wqe_info[pi];mlx5_nodnic_complete_send_wqe (sq, wi, napi_budget); + + priv->sq_stats.packets++; + priv->sq_stats.bytes += wi->num_bytes; } void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V2 3/5] net/mlx5: nodnic: Add TX/RX statistics
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] mlx5_nodnic_handle_send_cqe() reads wi->num_bytes for the tx_bytes update (tx.c:182) after mlx5_nodnic_complete_send_wqe() has…
- [Medium] The new 64-bit counters in struct mlx5_nodnic_sq_stats and struct mlx5_nodnic_rq_stats (en.h:47-56) are plain u64 with no…
- [Low] The new RX packet and byte counters in mlx5_nodnic_handle_recv_cqe() (rx.c:155-156) are incremented only…
--
net/mlx5: nodnic: Add TX/RX statistics
This commit adds TX and RX packet and byte counters to the nodnic driver, plus a TX drop counter. The data path updates the counters, and ndo_get_stats64 exposes them.
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h +0
-0@@ -44,6 +44,17 @@ enum mlx5_nodnic_cqe_opcode { OPCODE_CQ_INVALID, };
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h enum mlx5_nodnic_cqe_opcode { · line 56
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h +10
-0+struct mlx5_nodnic_sq_stats { +u64 packets; +u64 bytes; +u64 dropped; +}; + +struct mlx5_nodnic_rq_stats { +u64 packets; +u64 bytes; +};
[Severity: Medium]
Can these counters tear when they are read on a 32-bit kernel?
They are plain u64 fields. There is no u64_stats_sync and no READ_ONCE()/WRITE_ONCE(). Three places write them with plain ++ and +=:
mlx5_nodnic_handle_recv_cqe() - rq_stats packets/bytes, NAPI mlx5_nodnic_handle_send_cqe() - sq_stats packets/bytes, NAPI mlx5_nodnic_xmit() - sq_stats dropped, ndo_start_xmit
mlx5_nodnic_get_stats64() reads them with plain loads from process context through dev_get_stats(). It shares no lock with the writers.
MLX5_NODNIC in Kconfig does not depend on 64BIT, and include/linux/mlx5/doorbell.h has a BITS_PER_LONG != 64 fallback, so 32-bit builds look supported. On 32-bit, a u64 add is two 32-bit stores. A reader such as ip -s link or /proc/net/dev could then see rx_bytes or tx_bytes jump by about 2^32. On 64-bit these are still unannotated data races that KCSAN would report.
Should these use u64_stats_t, with u64_stats_update_begin()/end() in the writers and u64_stats_fetch_begin()/retry() in mlx5_nodnic_get_stats64()?
dropped is written from xmit context, while packets and bytes are written from NAPI. So the TX side would need separate syncp instances, or separate handling for dropped, so that each syncp has only one writer.
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq, · line 157
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c +3
-0@@ -152,6 +152,9 @@ void mlx5_nodnic_handle_recv_cqe(struct mlx5_nodnic_cq *cq, skb->protocol =eth_type_trans (skb, priv->netdev);nodnic_handle_rx_csum (priv->netdev, cqe, skb); + priv->rq_stats.packets++; + priv->rq_stats.bytes += byte_count; +
[Severity: Low]
Should good frames that are dropped because napi_build_skb() failed also be counted? Earlier in mlx5_nodnic_handle_recv_cqe():
skb = napi_build_skb(page_address(page), PAGE_SIZE); if (unlikely(!skb)) goto err_recycle;
This jumps past both counter updates. The rtnl_link_stats64 kernel-doc says @rx_packets includes "packets which host had to drop at various stages of processing (even in the driver)", and that @rx_bytes corresponds to @rx_packets.
Could the counters be incremented before the allocation? The failure could also be counted in rx_dropped.
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/rx.c +0
-0napi_gro_receive (&cq->napi, skb); rq->cc++;drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c +0
-0
[ ... ]
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq, · line 182
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c +3
-0@@ -176,6 +177,9 @@ void mlx5_nodnic_handle_send_cqe(struct mlx5_nodnic_cq *cq, wi = &sq->wqe_info[pi];mlx5_nodnic_complete_send_wqe (sq, wi, napi_budget); + + priv->sq_stats.packets++; + priv->sq_stats.bytes += wi->num_bytes;
[Severity: Medium]
Could wi->num_bytes already belong to a different packet when it is read here?
mlx5_nodnic_complete_send_wqe() gives the slot back to the producer before it returns:
sq->cc++; if (netif_tx_queue_stopped(txq)) netif_tx_wake_queue(txq);
mlx5_nodnic_xmit() stops the queue when the ring is one entry short of full, but it still posts the current packet:
if (unlikely(mlx5_nodnic_tx_is_sq_full(sq))) netif_tx_stop_queue(sq->txq);
So the ring can become completely full (pc - cc == num_entries). Once this completion increments cc and wakes the queue, mlx5_nodnic_xmit() on another CPU computes pi = pc & mask, which is the slot that was just completed. That CPU holds only the tx queue lock, which NAPI does not take. mlx5_nodnic_tx_fill_wqe_info() then does:
sq->wqe_info[pi].num_bytes = skb->len;
If that write lands before the read above, tx_bytes gets the new packet's length. The new packet is then counted again when it completes.
Could wi->num_bytes be saved in a local variable before calling mlx5_nodnic_complete_send_wqe()? Another option is to update the stats before cc is advanced and the queue is woken.
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/tx.c +0
-0} void mlx5_nodnic_complete_send_wqe(struct mlx5_nodnic_sq *sq,
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008171821.660739-1-tariqt%40nvidia.com
PATCH v2 4/5 net/mlx5: nodnic: Add ethtool driver info
In reply to Tariq ToukanFrom: Shahar Shitrit <[email protected]>
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.
--- .../ethernet/mellanox/mlx5/nodnic/en_cfg.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/net/ethernet/mellanox/mlx5/nodnic/en_cfg.c +34 -0
@@ -987,6 +987,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,
@@ -1005,6 +1038,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 ;
Signature · 1 line
2.44.0
PATCH v2 5/5 net/mlx5: nodnic: Add health monitoring
In reply to Tariq ToukanFrom: Shahar Shitrit <[email protected]>
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.
--- .../ethernet/mellanox/mlx5/nodnic/Makefile | 2 +- .../net/ethernet/mellanox/mlx5/nodnic/en.h | 12 + .../ethernet/mellanox/mlx5/nodnic/health.c | 315 ++++++++++++++++++ .../net/ethernet/mellanox/mlx5/nodnic/main.c | 2 + 4 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/nodnic/health.c
drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile +1 -1
@@ -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
drivers/net/ethernet/mellanox/mlx5/nodnic/en.h +12 -0
@@ -113,6 +113,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;
@@ -128,6 +138,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);
drivers/net/ethernet/mellanox/mlx5/nodnic/health.c new file +315 -0
315 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/nodnic/main.c +2 -0
@@ -804,6 +804,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);
@@ -829,6 +830,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);
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net-next V2 5/5] net/mlx5: nodnic: Add health monitoring
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch removes the trailing newline from drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile.
--
net/mlx5: nodnic: Add health monitoring
This commit adds firmware health monitoring to the nodnic driver. A timer periodically polls the health buffer in the initialization segment. It detects fatal sensors, stalls in the health counter, and syndrome changes. Polling is started from probe and stopped in remove.
drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile line 8
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/nodnic/Makefile +1
-1@@ -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
[Severity: Low]
This isn't a bug, but the trailing newline at the end of the nodnic Makefile has been dropped. Before this patch the mlx5_nodnic-y line ended with a newline. Could it be put back so that checkpatch doesn't warn and the next change to this file doesn't show an unrelated whitespace hunk?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008171821.660739-1-tariqt%40nvidia.com