* [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct
@ 2026-11-10 18:38 Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping Tariq Toukan
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
Hi,
This patch series by Dragos adds data direct support for netdev devices,
allowing a mlx5 netdev to issue DMA commands through multiple paths.
This feature is critical for improving performance and reaching line
rate in certain environments where issuing PCI transactions over one
path may be significantly faster than over another. These differences
can arise from various PCI generations in the system or the specific
system topology.
Data direct for netdev will work with devmem by returning the data
direct DMA device instead of the DMA device of the NIC. Each PF netdev
registers its own data direct device and support for RX and TX datapath
is added.
The feature is enabled though a ethtool private flag. When this flag
is enabled, the driver will return the data direct device in the
ndo_queue_get_dma_dev op.
When the data direct device is unbound, the netdev is closed, the
memory providers and TX dmabuf bindings mapped against the device are
unmapped through the new netdev_unbind_dma_dev() core helper, the flag
is disabled and the netdev is reopened. The helper does not care which
memory provider is installed: devmem and io_uring zcrx are both
uninstalled through their mp_ops->uninstall callback, like on netdev
unregister.
Regards,
Tariq
V2:
- Patch 2 (new): Detach auxiliary devices on attach failure during load
in mlx5_load_one_devl_locked().
- Patch 3: Move the data direct notifier unregister to after
mlx5e_nic_set_rx_mode() in mlx5e_nic_disable(), alongside the other
NIC-disable cleanups.
- Patch 4: Reword the commit message.
- Patch 6: Size the ICOSQ for the UMR mode of the RQ, since KSM UMR WQEs
map half the pages of MTT ones.
- Patch 6: Initialize umr_mkey to avoid a maybe-uninitialized warning.
- Patch 7 (new): Use the page_pool DMA sync helper for SHAMPO SKB frags,
as unreadable netmem is mapped against the data direct device rather
than rq->pdev.
- Patch 8: Document why the data_direct private flag is not propagated
to PTP SQs.
- Patch 9: Return the data direct device from ndo_queue_get_dma_dev and
use it for the page_pool of data direct RQs. Fail with -ENODEV if the
device is gone. Reject leased RX queues in data direct mode.
Bound-check queue_index.
- Patch 10: Walk the bindings xarray and report only bindings that are
still mapped, instead of tracking them on a separate list.
- Patch 11 (new): Add the netdev_unbind_dma_dev() core helper, which
uninstalls the memory providers (devmem and io_uring zcrx) and unmaps
TX bindings of the departing DMA device.
- Patch 12: Replace the channel re-creation on unbind with closing the
netdev, calling netdev_unbind_dma_dev(), disabling the flag and
reopening. Also release the providers on suspend. This addresses the
dmabuf binding limitation noted in V1.
- Patch 13: Reject enabling data direct on uplink representors and in
socket direct mode. Block flag changes while a memory provider is
installed on an RX queue or RX queues are leased.
- Add Reviewed-by tags from Cosmin where applicable.
- Drop the "SHAMPO required" gap: only enable data direct on an RX queue
with an unreadable memory provider when SHAMPO is active.
V1:
https://lore.kernel.org/all/20261008132815.654147-1-tariqt@nvidia.com/
Dragos Tatulea (13):
net/mlx5: Log the data direct to PF device mapping
net/mlx5: Detach auxiliary devices on attach failure during load
net/mlx5e: Register supported netdevs as data direct users
net/mlx5e: Pre-calculate UMR padding and entry size
net/mlx5e: Add data direct ethtool private flag
net/mlx5e: Add data direct RX infrastructure
net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags
net/mlx5e: Add data direct TX infrastructure
net/mlx5e: Use the correct DMA dev when data_direct is enabled
net: devmem: add netdev_has_dmabuf_binding() helper
net: add netdev_unbind_dma_dev() helper
net/mlx5e: Disable data direct on data direct device unbind
net/mlx5e: Enable the data direct netdev feature
.../ethernet/mellanox/mlx5/core/data_direct.c | 9 +-
drivers/net/ethernet/mellanox/mlx5/core/en.h | 14 +
.../ethernet/mellanox/mlx5/core/en/params.c | 18 +-
.../ethernet/mellanox/mlx5/core/en/params.h | 2 +
.../mellanox/mlx5/core/en/reporter_rx.c | 1 +
.../mellanox/mlx5/core/en/reporter_tx.c | 1 +
.../ethernet/mellanox/mlx5/core/en_common.c | 38 ++-
.../ethernet/mellanox/mlx5/core/en_ethtool.c | 67 +++++
.../net/ethernet/mellanox/mlx5/core/en_main.c | 253 +++++++++++++++++-
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 33 +--
.../net/ethernet/mellanox/mlx5/core/en_tx.c | 4 +-
.../net/ethernet/mellanox/mlx5/core/main.c | 1 +
include/linux/mlx5/driver.h | 1 +
include/net/netdev_queues.h | 1 +
include/net/netmem.h | 24 ++
net/core/devmem.c | 85 ++++++
net/core/devmem.h | 6 +
net/core/netdev_queues.c | 51 ++++
18 files changed, 573 insertions(+), 36 deletions(-)
base-commit: fa5196392691051963726787944db872420dfa75
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 02/13] net/mlx5: Detach auxiliary devices on attach failure during load Tariq Toukan
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Emit an informational message when a data direct device is bound to a
PF, showing the data direct BDF alongside the PF BDF (the mlx5_core log
prefix), to make the mapping observable from dmesg.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/data_direct.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
index 5afb11a2a9f0..7db94b8a5b79 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
@@ -21,6 +21,7 @@ static LIST_HEAD(mlx5_data_direct_reg_list);
static DEFINE_MUTEX(mlx5_data_direct_mutex);
struct mlx5_data_direct_registration {
+ struct mlx5_core_dev *mdev;
char vuid[MLX5_ST_SZ_BYTES(array1024_auto) + 1];
struct list_head list;
struct blocking_notifier_head users;
@@ -189,6 +190,9 @@ static void mlx5_data_direct_bind(struct mlx5_data_direct_registration *reg,
struct mlx5_data_direct_dev *dev)
{
WRITE_ONCE(reg->dd.dev, dev);
+
+ mlx5_core_info(reg->mdev, "bound data direct device %s\n",
+ pci_name(dev->pdev));
}
static void
@@ -212,6 +216,7 @@ int mlx5_data_direct_init(struct mlx5_core_dev *mdev)
if (!reg)
return -ENOMEM;
+ reg->mdev = mdev;
BLOCKING_INIT_NOTIFIER_HEAD(®->users);
err = mlx5_data_direct_query_vuid(mdev, reg->vuid);
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 02/13] net/mlx5: Detach auxiliary devices on attach failure during load
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 03/13] net/mlx5e: Register supported netdevs as data direct users Tariq Toukan
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
The device attach phase fails in mlx5_load_one_devl_locked() when
the first device fails to attach. The error path doesn't detach
the remaining devices that successfully attached.
Fix the above condition by properly calling detach on the error
path.
This issue was found during code inspection and was not reproduced.
Hence it doesn't deserve a Fixes tag.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 1a45474ce03d..7e762f72b19e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1547,6 +1547,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery)
return 0;
err_attach:
+ mlx5_detach_device(dev, true);
clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state);
mlx5_unload(dev);
err_load:
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 03/13] net/mlx5e: Register supported netdevs as data direct users
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 02/13] net/mlx5: Detach auxiliary devices on attach failure during load Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 04/13] net/mlx5e: Pre-calculate UMR padding and entry size Tariq Toukan
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Register the netdev as a data direct user so it is notified when the
affiliated data direct device is unbound.
Register during NIC enable and unregister during disable so suspend
and resume follow the data direct registration lifetime in mlx5_core.
The notifier callback only traces the unbind event for now; tearing down
the data direct datapath is wired up together with that datapath in
later patches.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 +
.../net/ethernet/mellanox/mlx5/core/en_main.c | 20 +++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index a3945195f454..78cf6aedd04d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -984,6 +984,7 @@ struct mlx5e_priv {
struct mlx5e_mqprio_rl *mqprio_rl;
struct dentry *dfs_root;
struct mlx5_devcom_comp_dev *devcom;
+ struct notifier_block data_direct_nb;
};
static inline u16 mlx5e_stats_nch_read(const struct mlx5e_priv *priv)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index c3c2c5720c6f..1993da0fdb91 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -33,6 +33,7 @@
#include <linux/dim.h>
#include <net/tc_act/tc_gact.h>
#include <linux/mlx5/fs.h>
+#include <linux/mlx5/data_direct.h>
#include <net/vxlan.h>
#include <net/geneve.h>
#include <linux/bpf.h>
@@ -6022,6 +6023,18 @@ void mlx5e_destroy_q_counters(struct mlx5e_priv *priv)
}
}
+static int mlx5e_data_direct_event(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv,
+ data_direct_nb);
+
+ if (action == MLX5_DATA_DIRECT_UNBIND)
+ mlx5_core_dbg(priv->mdev, "data direct device unbound\n");
+
+ return NOTIFY_OK;
+}
+
static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
struct net_device *netdev)
{
@@ -6224,6 +6237,12 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv)
mlx5e_pcie_cong_event_init(priv);
mlx5e_hv_vhca_stats_create(priv);
+
+ if (mlx5_data_direct_supported(mdev)) {
+ priv->data_direct_nb.notifier_call = mlx5e_data_direct_event;
+ mlx5_data_direct_register(mdev, &priv->data_direct_nb);
+ }
+
if (netdev->reg_state != NETREG_REGISTERED)
return 0;
mlx5e_dcbnl_init_app(priv);
@@ -6268,6 +6287,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
mlx5e_nic_set_rx_mode(priv);
+ mlx5_data_direct_unregister(mdev, &priv->data_direct_nb);
mlx5e_pcie_cong_event_cleanup(priv);
mlx5e_hv_vhca_stats_destroy(priv);
if (mlx5e_monitor_counter_supported(priv))
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 04/13] net/mlx5e: Pre-calculate UMR padding and entry size
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (2 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 03/13] net/mlx5e: Register supported netdevs as data direct users Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 05/13] net/mlx5e: Add data direct ethtool private flag Tariq Toukan
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
A future patch will add KSM UMRs alongside MTT UMRs for data direct. To
avoid additional ifs in the datapath, pre-calculate the UMR padding and
entry size based on the UMR mode of the RQ.
An additional side benefit is that the padding check from
mlx5e_alloc_rx_mpwqe() is no longer needed.
This patch doesn't introduce any functional changes. The mlx5e_rq struct
doesn't grow because the new members were added in a hole.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 3 +++
.../net/ethernet/mellanox/mlx5/core/en_main.c | 11 +++++++++++
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 16 ++++++----------
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 78cf6aedd04d..000493f42912 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -696,6 +696,9 @@ struct mlx5e_rq {
u8 umr_wqebbs;
u8 mtts_per_wqe;
u8 umr_mode;
+ u8 umr_entry_size;
+ u8 umr_pad_bytes;
+ u16 umr_pad_offset;
struct mlx5e_mpw_linear_info *linear_info;
struct mlx5e_shampo_hd *shampo;
} mpwqe;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 1993da0fdb91..96b521d8bed3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -901,6 +901,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
void *rqc_wq = MLX5_ADDR_OF(rqc, rq_param->rqc, wq);
struct mlx5_core_dev *mdev = rq->mdev;
u32 pool_order = 0;
+ u16 entries_bytes;
u32 pool_size;
int wq_sz;
int err;
@@ -947,6 +948,16 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
mlx5e_mpwrq_mtts_per_wqe(mdev, rq->mpwqe.page_shift,
rq->mpwqe.umr_mode);
+ rq->mpwqe.umr_entry_size =
+ mlx5e_mpwrq_umr_entry_size(rq->mpwqe.umr_mode);
+ entries_bytes = rq->mpwqe.pages_per_wqe *
+ rq->mpwqe.umr_entry_size;
+ rq->mpwqe.umr_pad_offset = entries_bytes;
+ /* padding can be 0 when no padding is needed */
+ rq->mpwqe.umr_pad_bytes =
+ ALIGN(entries_bytes, MLX5_UMR_FLEX_ALIGNMENT) -
+ entries_bytes;
+
pool_size = rq->mpwqe.pages_per_wqe <<
mlx5e_mpwqe_get_log_rq_size(mdev, params, rqo);
pool_order = rq->mpwqe.page_shift - PAGE_SHIFT;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 22fea4739a2c..a9392ee5376e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -675,16 +675,11 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
};
}
- /* Pad if needed, in case the value set to ucseg->xlt_octowords
- * in mlx5e_build_umr_wqe() needed alignment.
+ /* Pad when the value set to ucseg->xlt_octowords in
+ * mlx5e_build_umr_wqe() needed alignment.
*/
- if (rq->mpwqe.pages_per_wqe & (MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT - 1)) {
- int pad = ALIGN(rq->mpwqe.pages_per_wqe, MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT) -
- rq->mpwqe.pages_per_wqe;
-
- memset(&umr_wqe->inline_mtts[rq->mpwqe.pages_per_wqe], 0,
- sizeof(*umr_wqe->inline_mtts) * pad);
- }
+ memset((u8 *)umr_wqe->inline_mtts + rq->mpwqe.umr_pad_offset, 0,
+ rq->mpwqe.umr_pad_bytes);
bitmap_zero(wi->skip_release_bitmap, rq->mpwqe.pages_per_wqe);
wi->consumed_strides = 0;
@@ -693,7 +688,8 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
cpu_to_be32((sq->pc << MLX5_WQE_CTRL_WQE_INDEX_SHIFT) |
MLX5_OPCODE_UMR);
- offset = (ix * rq->mpwqe.mtts_per_wqe) * sizeof(struct mlx5_mtt) / MLX5_OCTWORD;
+ offset = ix * rq->mpwqe.mtts_per_wqe *
+ rq->mpwqe.umr_entry_size / MLX5_OCTWORD;
umr_wqe->hdr.uctrl.xlt_offset = cpu_to_be16(offset);
sq->db.wqe_info[pi] = (struct mlx5e_icosq_wqe_info) {
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 05/13] net/mlx5e: Add data direct ethtool private flag
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (3 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 04/13] net/mlx5e: Pre-calculate UMR padding and entry size Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 06/13] net/mlx5e: Add data direct RX infrastructure Tariq Toukan
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
This patch adds the data direct private flag infrastructure.
The MLX5E_PFLAG_DATA_DIRECT flag is needed in the follow-up patches to
detect the configuration of data direct from the user side.
For now the flag can't be actually set. This will be implemented in a
follow-up patch once all pieces are put together.
This patch doesn't introduce any functional changes.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 +
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 000493f42912..c5bbe5adea45 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -264,6 +264,7 @@ enum mlx5e_priv_flag {
MLX5E_PFLAG_XDP_TX_MPWQE,
MLX5E_PFLAG_SKB_TX_MPWQE,
MLX5E_PFLAG_TX_PORT_TS,
+ MLX5E_PFLAG_DATA_DIRECT,
MLX5E_NUM_PFLAGS, /* Keep last */
};
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 1f534051cdfe..26f76449af35 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -2405,6 +2405,11 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
return err;
}
+static int set_pflag_data_direct(struct net_device *netdev, bool enable)
+{
+ return -EOPNOTSUPP;
+}
+
static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = {
{ "rx_cqe_moder", set_pflag_rx_cqe_based_moder },
{ "tx_cqe_moder", set_pflag_tx_cqe_based_moder },
@@ -2414,6 +2419,7 @@ static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = {
{ "xdp_tx_mpwqe", set_pflag_xdp_tx_mpwqe },
{ "skb_tx_mpwqe", set_pflag_skb_tx_mpwqe },
{ "tx_port_ts", set_pflag_tx_port_ts },
+ { "data_direct", set_pflag_data_direct },
};
static int mlx5e_handle_pflag(struct net_device *netdev,
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 06/13] net/mlx5e: Add data direct RX infrastructure
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (4 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 05/13] net/mlx5e: Add data direct ethtool private flag Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 07/13] net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags Tariq Toukan
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Data direct is a HW feature that allows a type of peer-to-peer DMA
between the NIC and another device (e.g. GPU) going through a specific
PCIe topology.
For data direct to work on the RX path, the RQ will use a KSM mkey whose
entries will point to the crossed mkey. This is necessary to enable DMA
from the NIC to the other device.
This commit adds the necessary infrastructure on RX side:
- New RQ state flag for the data direct state.
- Create crossing mkey.
- Create KSM mkey and in data direct PD and make it point to the
crossed mkey.
- Size the ICOSQ for the UMR mode of the RQ: KSM UMR WQEs map half the
pages of MTT ones, so a data direct RQ needs twice as many of them.
This commit has no functional changes. data direct mode will be
enabled in a subsequent commit and mlx5e_queue_get_dma_dev() will then
point to the right device.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 6 +
.../ethernet/mellanox/mlx5/core/en/params.c | 18 ++-
.../ethernet/mellanox/mlx5/core/en/params.h | 2 +
.../mellanox/mlx5/core/en/reporter_rx.c | 1 +
.../net/ethernet/mellanox/mlx5/core/en_main.c | 104 ++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 12 +-
6 files changed, 130 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index c5bbe5adea45..d716e70c6d47 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -342,6 +342,7 @@ enum {
MLX5E_RQ_STATE_SHAMPO, /* set when SHAMPO cap is used */
MLX5E_RQ_STATE_MINI_CQE_ENHANCED, /* set when enhanced mini_cqe_cap is used */
MLX5E_RQ_STATE_XSK, /* set to indicate an xsk rq */
+ MLX5E_RQ_STATE_DATA_DIRECT, /* set when the rq maps data through data direct */
MLX5E_NUM_RQ_STATES, /* Must be kept last */
};
@@ -685,6 +686,8 @@ struct mlx5e_rq {
struct mlx5e_mpw_info *info;
mlx5e_fp_skb_from_cqe_mpwrq skb_from_cqe_mpwrq;
__be32 umr_mkey_be;
+ __be32 ksm_child_mkey_be;
+ u32 crossing_mkey;
u16 num_strides;
u16 actual_wq_head;
u8 log_stride_sz;
@@ -1202,6 +1205,9 @@ static inline bool mlx5_tx_swp_supported(struct mlx5_core_dev *mdev)
extern const struct ethtool_ops mlx5e_ethtool_ops;
int mlx5e_create_mkey(struct mlx5_core_dev *mdev, u32 pdn, u32 *mkey);
+int mlx5e_create_crossing_vhca_mkey(struct mlx5_core_dev *mdev,
+ u32 crossed_mkey, u64 crossed_len,
+ u32 *crossing_mkey);
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev, bool create_tises);
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
int mlx5e_modify_tirs_lb(struct mlx5_core_dev *mdev, bool enable_uc_lb,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
index 5caf7820a136..61a77ee77244 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c
@@ -62,6 +62,9 @@ mlx5e_mpwrq_umr_mode(struct mlx5_core_dev *mdev,
bool unaligned = xsk ? xsk->unaligned : false;
bool oversized = false;
+ if (rqo && rqo->data_direct)
+ return MLX5E_MPWRQ_UMR_MODE_UNALIGNED;
+
if (xsk) {
oversized = xsk->chunk_size < (1 << page_shift);
WARN_ON_ONCE(xsk->chunk_size > (1 << page_shift));
@@ -1213,8 +1216,14 @@ static u32 mlx5e_max_xsk_wqebbs(struct mlx5_core_dev *mdev,
static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,
struct mlx5e_params *params,
- struct mlx5e_rq_param *rq_param)
+ struct mlx5e_rq_opt_param *rqo)
{
+ /* Only the UMR mode matters here. Leave qcfg out: sizing for
+ * PAGE_SIZE is an upper bound for larger RX page sizes.
+ */
+ struct mlx5e_rq_opt_param umr_rqo = {
+ .data_direct = rqo && rqo->data_direct,
+ };
u32 wqebbs, total_pages, useful_space;
/* MLX5_WQ_TYPE_CYCLIC */
@@ -1222,7 +1231,7 @@ static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,
return MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
/* UMR WQEs for the regular RQ. */
- wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, NULL);
+ wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, &umr_rqo);
wqebbs += mlx5e_max_xsk_wqebbs(mdev, params);
@@ -1296,18 +1305,21 @@ void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev,
int mlx5e_build_channel_param(struct mlx5_core_dev *mdev,
struct mlx5e_params *params,
struct netdev_queue_config *qcfg,
+ bool data_direct,
struct mlx5e_channel_param *cparam)
{
u8 icosq_log_wq_sz, async_icosq_log_wq_sz;
int err;
cparam->rq_opt.qcfg = qcfg;
+ cparam->rq_opt.data_direct = data_direct;
err = mlx5e_build_rq_param(mdev, params, &cparam->rq_opt, &cparam->rq);
if (err)
return err;
- icosq_log_wq_sz = mlx5e_build_icosq_log_wq_sz(mdev, params, &cparam->rq);
+ icosq_log_wq_sz = mlx5e_build_icosq_log_wq_sz(mdev, params,
+ &cparam->rq_opt);
async_icosq_log_wq_sz = mlx5e_build_async_icosq_log_wq_sz(mdev);
mlx5e_build_sq_param(mdev, params, &cparam->txq_sq);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.h b/drivers/net/ethernet/mellanox/mlx5/core/en/params.h
index 275f9be53a34..43332015f445 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.h
@@ -15,6 +15,7 @@ struct mlx5e_xsk_param {
struct mlx5e_rq_opt_param {
struct mlx5e_xsk_param *xsk;
struct netdev_queue_config *qcfg;
+ bool data_direct;
};
struct mlx5e_cq_param {
@@ -146,6 +147,7 @@ void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev,
int mlx5e_build_channel_param(struct mlx5_core_dev *mdev,
struct mlx5e_params *params,
struct netdev_queue_config *qcfg,
+ bool data_direct,
struct mlx5e_channel_param *cparam);
void mlx5e_build_xsk_channel_param(struct mlx5_core_dev *mdev,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c
index 6efb626b5506..f9fce1d0e9e7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c
@@ -21,6 +21,7 @@ static const char * const rq_sw_state_type_name[] = {
[MLX5E_RQ_STATE_SHAMPO] = "shampo",
[MLX5E_RQ_STATE_MINI_CQE_ENHANCED] = "mini_cqe_enhanced",
[MLX5E_RQ_STATE_XSK] = "xsk",
+ [MLX5E_RQ_STATE_DATA_DIRECT] = "data_direct",
};
static int mlx5e_query_rq_state(struct mlx5_core_dev *dev, u32 rqn, u8 *state)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 96b521d8bed3..cee73f3b7a99 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -425,7 +425,7 @@ static u8 mlx5e_mpwrq_access_mode(enum mlx5e_mpwrq_umr_mode umr_mode)
static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev,
u32 npages, u8 page_shift, u32 *umr_mkey,
dma_addr_t filler_addr,
- enum mlx5e_mpwrq_umr_mode umr_mode,
+ enum mlx5e_mpwrq_umr_mode umr_mode, u32 pdn,
u32 xsk_chunk_size)
{
struct mlx5_mtt *mtt;
@@ -465,7 +465,7 @@ static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev,
MLX5_SET(mkc, mkc, access_mode_1_0, mlx5e_mpwrq_access_mode(umr_mode));
mlx5e_mkey_set_relaxed_ordering(mdev, mkc);
MLX5_SET(mkc, mkc, qpn, 0xffffff);
- MLX5_SET(mkc, mkc, pd, mdev->mlx5e_res.hw_objs.pdn);
+ MLX5_SET(mkc, mkc, pd, pdn);
MLX5_SET64(mkc, mkc, len, npages << page_shift);
MLX5_SET(mkc, mkc, translations_octword_size, octwords);
if (umr_mode == MLX5E_MPWRQ_UMR_MODE_TRIPLE)
@@ -531,9 +531,11 @@ static int mlx5e_create_umr_mkey(struct mlx5_core_dev *mdev,
static int mlx5e_create_rq_umr_mkey(struct mlx5_core_dev *mdev, struct mlx5e_rq *rq)
{
u32 xsk_chunk_size = rq->xsk_pool ? rq->xsk_pool->chunk_size : 0;
+ bool dd = test_bit(MLX5E_RQ_STATE_DATA_DIRECT, &rq->state);
u32 wq_size = mlx5_wq_ll_get_size(&rq->mpwqe.wq);
u32 num_entries, max_num_entries;
- u32 umr_mkey;
+ u32 umr_mkey = 0;
+ u32 pdn;
int err;
max_num_entries = mlx5e_mpwrq_max_num_entries(mdev, rq->mpwqe.umr_mode);
@@ -546,13 +548,80 @@ static int mlx5e_create_rq_umr_mkey(struct mlx5_core_dev *mdev, struct mlx5e_rq
__func__, wq_size, rq->mpwqe.mtts_per_wqe,
max_num_entries);
+ pdn = dd ? mdev->data_direct->pdn : mdev->mlx5e_res.hw_objs.pdn;
err = mlx5e_create_umr_mkey(mdev, num_entries, rq->mpwqe.page_shift,
&umr_mkey, rq->wqe_overflow.addr,
- rq->mpwqe.umr_mode, xsk_chunk_size);
+ rq->mpwqe.umr_mode, pdn,
+ xsk_chunk_size);
rq->mpwqe.umr_mkey_be = cpu_to_be32(umr_mkey);
return err;
}
+int mlx5e_create_crossing_vhca_mkey(struct mlx5_core_dev *mdev,
+ u32 crossed_mkey, u64 crossed_len,
+ u32 *crossing_mkey)
+{
+ int inlen = MLX5_ST_SZ_BYTES(create_mkey_in);
+ int access_mode = MLX5_MKC_ACCESS_MODE_CROSSING;
+ void *mkc;
+ u32 *in;
+ int err;
+
+ if (!MLX5_CAP_GEN(mdev, crossing_vhca_mkey))
+ return -EOPNOTSUPP;
+
+ in = kvzalloc(inlen, GFP_KERNEL);
+ if (!in)
+ return -ENOMEM;
+
+ mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
+ MLX5_SET(mkc, mkc, access_mode_1_0, access_mode & 0x3);
+ MLX5_SET(mkc, mkc, access_mode_4_2, (access_mode >> 2) & 0x7);
+ MLX5_SET(mkc, mkc, crossing_target_vhca_id,
+ MLX5_CAP_GEN(mdev, vhca_id));
+ MLX5_SET(mkc, mkc, translations_octword_size, crossed_mkey);
+ MLX5_SET(mkc, mkc, pd, mdev->mlx5e_res.hw_objs.pdn);
+ MLX5_SET(mkc, mkc, qpn, 0xffffff);
+ MLX5_SET(mkc, mkc, lr, 1);
+ MLX5_SET(mkc, mkc, lw, 1);
+ MLX5_SET64(mkc, mkc, start_addr, 0);
+ MLX5_SET64(mkc, mkc, len, crossed_len);
+
+ err = mlx5_core_create_mkey(mdev, crossing_mkey, in, inlen);
+ kvfree(in);
+ return err;
+}
+
+static int mlx5e_rq_alloc_data_direct_mkey(struct mlx5e_rq *rq)
+{
+ struct mlx5_core_dev *mdev = rq->mdev;
+ u32 umr_mkey;
+ u64 umr_len;
+ int wq_sz;
+
+ if (!test_bit(MLX5E_RQ_STATE_DATA_DIRECT, &rq->state))
+ return 0;
+
+ wq_sz = mlx5_wq_ll_get_size(&rq->mpwqe.wq);
+ umr_mkey = be32_to_cpu(rq->mpwqe.umr_mkey_be);
+ umr_len = (u64)wq_sz * rq->mpwqe.mtts_per_wqe << rq->mpwqe.page_shift;
+
+ rq->mpwqe.ksm_child_mkey_be =
+ cpu_to_be32(mdev->data_direct->mkey_ro_valid ?
+ mdev->data_direct->mkey_ro :
+ mdev->data_direct->mkey);
+
+ return mlx5e_create_crossing_vhca_mkey(mdev, umr_mkey,
+ umr_len,
+ &rq->mpwqe.crossing_mkey);
+}
+
+static void mlx5e_rq_free_data_direct_mkey(struct mlx5e_rq *rq)
+{
+ if (test_bit(MLX5E_RQ_STATE_DATA_DIRECT, &rq->state))
+ mlx5_core_destroy_mkey(rq->mdev, rq->mpwqe.crossing_mkey);
+}
+
static void mlx5e_init_frags_partition(struct mlx5e_rq *rq)
{
struct mlx5e_wqe_frag_info next_frag = {};
@@ -900,6 +969,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
{
void *rqc_wq = MLX5_ADDR_OF(rqc, rq_param->rqc, wq);
struct mlx5_core_dev *mdev = rq->mdev;
+ bool data_direct = false;
u32 pool_order = 0;
u16 entries_bytes;
u32 pool_size;
@@ -937,6 +1007,11 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
if (err)
goto err_rq_wq_destroy;
+ data_direct = rqo && rqo->data_direct;
+
+ if (data_direct)
+ set_bit(MLX5E_RQ_STATE_DATA_DIRECT, &rq->state);
+
rq->mpwqe.umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
rq->mpwqe.pages_per_wqe =
mlx5e_mpwrq_pages_per_wqe(mdev, rq->mpwqe.page_shift,
@@ -975,10 +1050,14 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
if (err)
goto err_rq_drop_page;
- err = mlx5e_rq_alloc_mpwqe_info(rq, node);
+ err = mlx5e_rq_alloc_data_direct_mkey(rq);
if (err)
goto err_rq_mkey;
+ err = mlx5e_rq_alloc_mpwqe_info(rq, node);
+ if (err)
+ goto err_rq_free_dd_mkey;
+
err = mlx5e_rq_alloc_mpwqe_linear_info(rq, node, params, rqo);
if (err)
goto err_free_mpwqe_info;
@@ -1071,7 +1150,9 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
wqe->data[0].addr = cpu_to_be64(dma_offset + headroom);
wqe->data[0].byte_count = cpu_to_be32(byte_count);
- wqe->data[0].lkey = rq->mpwqe.umr_mkey_be;
+ wqe->data[0].lkey = data_direct ?
+ cpu_to_be32(rq->mpwqe.crossing_mkey) :
+ rq->mpwqe.umr_mkey_be;
} else {
struct mlx5e_rx_wqe_cyc *wqe =
mlx5_wq_cyc_get_wqe(&rq->wqe.wq, i);
@@ -1105,6 +1186,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
kvfree(rq->mpwqe.linear_info);
err_free_mpwqe_info:
kvfree(rq->mpwqe.info);
+err_rq_free_dd_mkey:
+ mlx5e_rq_free_data_direct_mkey(rq);
err_rq_mkey:
mlx5_core_destroy_mkey(mdev, be32_to_cpu(rq->mpwqe.umr_mkey_be));
err_rq_drop_page:
@@ -1132,6 +1215,7 @@ static void mlx5e_free_rq(struct mlx5e_rq *rq)
mlx5e_rq_free_shampo(rq);
kvfree(rq->mpwqe.linear_info);
kvfree(rq->mpwqe.info);
+ mlx5e_rq_free_data_direct_mkey(rq);
mlx5_core_destroy_mkey(rq->mdev, be32_to_cpu(rq->mpwqe.umr_mkey_be));
mlx5e_free_mpwqe_rq_drop_page(rq);
break;
@@ -2849,6 +2933,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
struct mlx5e_xsk_param xsk;
bool async_icosq_needed;
struct mlx5e_channel *c;
+ bool data_direct;
unsigned int irq;
int vec_ix;
int cpu;
@@ -2873,7 +2958,12 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
goto err_free;
}
- err = mlx5e_build_channel_param(mdev, params, qcfg, cparam);
+ data_direct = MLX5E_GET_PFLAG(params, MLX5E_PFLAG_DATA_DIRECT) &&
+ params->packet_merge.type == MLX5E_PACKET_MERGE_SHAMPO &&
+ netif_rxq_has_unreadable_mp(netdev, ix);
+
+ err = mlx5e_build_channel_param(mdev, params, qcfg, data_direct,
+ cparam);
if (err)
goto err_free;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index a9392ee5376e..0f9a946aef41 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -670,9 +670,15 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
goto err_unmap;
addr = page_pool_get_dma_addr_netmem(frag_page->netmem);
- umr_wqe->inline_mtts[i] = (struct mlx5_mtt) {
- .ptag = cpu_to_be64(addr | MLX5_EN_WR),
- };
+ if (test_bit(MLX5E_RQ_STATE_DATA_DIRECT, &rq->state))
+ umr_wqe->inline_ksms[i] = (struct mlx5_ksm) {
+ .key = rq->mpwqe.ksm_child_mkey_be,
+ .va = cpu_to_be64(addr),
+ };
+ else
+ umr_wqe->inline_mtts[i] = (struct mlx5_mtt) {
+ .ptag = cpu_to_be64(addr | MLX5_EN_WR),
+ };
}
/* Pad when the value set to ucseg->xlt_octowords in
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 07/13] net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (5 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 06/13] net/mlx5e: Add data direct RX infrastructure Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 08/13] net/mlx5e: Add data direct TX infrastructure Tariq Toukan
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Switch to the page_pool DMA API which takes care of not calling
dma_sync_* for unreadable netmem. Do it only for the place where it
makes sense: SHAMPO payloads, the only RX buffers that can be
unreadable.
Until now it was ok to call the dma_sync_* API directly. But with the
introduction of data direct it will no longer be correct: the payload
netmem of a data direct RQ is mapped against the data direct device,
not rq->pdev.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 0f9a946aef41..9db3db5246ab 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -560,12 +560,11 @@ mlx5e_add_skb_frag(struct mlx5e_rq *rq, struct sk_buff *skb,
u32 frag_offset, u32 len,
unsigned int truesize)
{
- dma_addr_t addr = page_pool_get_dma_addr_netmem(frag_page->netmem);
u8 next_frag = skb_shinfo(skb)->nr_frags;
netmem_ref netmem = frag_page->netmem;
- dma_sync_single_for_cpu(rq->pdev, addr + frag_offset, len,
- rq->buff.map_dir);
+ page_pool_dma_sync_netmem_for_cpu(rq->page_pool, netmem, frag_offset,
+ len);
if (skb_can_coalesce_netmem(skb, next_frag, netmem, frag_offset)) {
skb_coalesce_rx_frag(skb, next_frag - 1, len, truesize);
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 08/13] net/mlx5e: Add data direct TX infrastructure
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (6 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 07/13] net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled Tariq Toukan
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Data direct is a HW feature that allows a type of peer-to-peer DMA
between the NIC and another device (e.g. GPU) going through a specific
PCIe topology.
For data direct to work on the TX path, a crossing mkey is necessary
which is created as a mlx5e resource. This mkey is used by all SQs.
For simplicity always create this resource and link it to the SQ
if data direct is supported.
An SQ state flag is added as well to signal to the TX data path that
data direct is enabled.
This commit has no functional changes. data direct mode will be
enabled in a subsequent commit and mlx5e_queue_get_dma_dev() will then
point to the right device.
The data_direct private flag is not propagated to PTP SQs because
the queue selector will direct devmem net_iovs to regular SQs.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +
.../mellanox/mlx5/core/en/reporter_tx.c | 1 +
.../ethernet/mellanox/mlx5/core/en_common.c | 38 ++++++++++++++++++-
.../net/ethernet/mellanox/mlx5/core/en_main.c | 6 +++
.../net/ethernet/mellanox/mlx5/core/en_tx.c | 4 +-
include/linux/mlx5/driver.h | 1 +
6 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index d716e70c6d47..23e45e87cdee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -397,6 +397,7 @@ enum {
MLX5E_SQ_STATE_PENDING_XSK_TX,
MLX5E_SQ_STATE_PENDING_TLS_RX_RESYNC,
MLX5E_SQ_STATE_LOCK_NEEDED,
+ MLX5E_SQ_STATE_DATA_DIRECT, /* set when the sq maps net_iov frags through data direct */
MLX5E_NUM_SQ_STATES, /* Must be kept last */
};
@@ -453,6 +454,7 @@ struct mlx5e_txqsq {
u8 min_inline_mode;
struct device *pdev;
__be32 mkey_be;
+ __be32 crossing_mkey_be;
unsigned long state;
unsigned int hw_mtu;
struct mlx5_clock *clock;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c
index 8409ae73768f..b4a4ff877bbc 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c
@@ -18,6 +18,7 @@ static const char * const sq_sw_state_type_name[] = {
[MLX5E_SQ_STATE_PENDING_XSK_TX] = "pending_xsk_tx",
[MLX5E_SQ_STATE_PENDING_TLS_RX_RESYNC] = "pending_tls_rx_resync",
[MLX5E_SQ_STATE_LOCK_NEEDED] = "lock_needed",
+ [MLX5E_SQ_STATE_DATA_DIRECT] = "data_direct",
};
static int mlx5e_wait_for_sq_flush(struct mlx5e_txqsq *sq)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_common.c b/drivers/net/ethernet/mellanox/mlx5/core/en_common.c
index c2d4bae533de..c1d3b2ba1864 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_common.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_common.c
@@ -30,6 +30,8 @@
* SOFTWARE.
*/
+#include <linux/mlx5/data_direct.h>
+
#include "devlink.h"
#include "en.h"
#include "lib/crypto.h"
@@ -153,6 +155,30 @@ mlx5e_get_devlink_param_num_doorbells(struct mlx5_core_dev *dev)
return err ? MLX5_DEFAULT_NUM_DOORBELLS : val.vu32;
}
+static int mlx5e_create_data_direct_crossing_mkey(struct mlx5_core_dev *mdev)
+{
+ struct mlx5e_hw_objs *res = &mdev->mlx5e_res.hw_objs;
+
+ if (!mdev->data_direct ||
+ !MLX5_CAP_GEN(mdev, crossing_vhca_mkey))
+ return 0;
+
+ return mlx5e_create_crossing_vhca_mkey(mdev, mdev->data_direct->mkey,
+ U64_MAX,
+ &res->data_direct_crossing_mkey);
+}
+
+static void mlx5e_destroy_data_direct_crossing_mkey(struct mlx5_core_dev *mdev)
+{
+ struct mlx5e_hw_objs *res = &mdev->mlx5e_res.hw_objs;
+
+ if (!mdev->data_direct ||
+ !MLX5_CAP_GEN(mdev, crossing_vhca_mkey))
+ return;
+
+ mlx5_core_destroy_mkey(mdev, res->data_direct_crossing_mkey);
+}
+
int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev, bool create_tises)
{
struct mlx5e_hw_objs *res = &mdev->mlx5e_res.hw_objs;
@@ -177,12 +203,19 @@ int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev, bool create_tises)
goto err_dealloc_transport_domain;
}
+ err = mlx5e_create_data_direct_crossing_mkey(mdev);
+ if (err) {
+ mlx5_core_err(mdev, "create data direct crossing mkey failed, %d\n",
+ err);
+ goto err_destroy_mkey;
+ }
+
num_doorbells = min(mlx5e_get_devlink_param_num_doorbells(mdev),
mlx5e_get_max_num_channels(mdev));
res->bfregs = kzalloc_objs(*res->bfregs, num_doorbells);
if (!res->bfregs) {
err = -ENOMEM;
- goto err_destroy_mkey;
+ goto err_destroy_crossing_mkey;
}
for (i = 0; i < num_doorbells; i++) {
@@ -221,6 +254,8 @@ int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev, bool create_tises)
for (i = 0; i < res->num_bfregs; i++)
mlx5_free_bfreg(mdev, res->bfregs + i);
kfree(res->bfregs);
+err_destroy_crossing_mkey:
+ mlx5e_destroy_data_direct_crossing_mkey(mdev);
err_destroy_mkey:
mlx5_core_destroy_mkey(mdev, res->mkey);
err_dealloc_transport_domain:
@@ -241,6 +276,7 @@ void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev)
for (unsigned int i = 0; i < res->num_bfregs; i++)
mlx5_free_bfreg(mdev, res->bfregs + i);
kfree(res->bfregs);
+ mlx5e_destroy_data_direct_crossing_mkey(mdev);
mlx5_core_destroy_mkey(mdev, res->mkey);
mlx5_core_dealloc_transport_domain(mdev, res->td.tdn);
mlx5_core_dealloc_pd(mdev, res->pdn);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index cee73f3b7a99..5b99099e4ed0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -1825,6 +1825,12 @@ static int mlx5e_alloc_txqsq(struct mlx5e_channel *c,
set_bit(MLX5E_SQ_STATE_IPSEC, &sq->state);
if (param->is_mpw)
set_bit(MLX5E_SQ_STATE_MPWQE, &sq->state);
+ if (MLX5E_GET_PFLAG(params, MLX5E_PFLAG_DATA_DIRECT)) {
+ u32 mkey = mdev->mlx5e_res.hw_objs.data_direct_crossing_mkey;
+
+ sq->crossing_mkey_be = cpu_to_be32(mkey);
+ set_bit(MLX5E_SQ_STATE_DATA_DIRECT, &sq->state);
+ }
sq->stop_room = param->stop_room;
sq->ptp_cyc2time = mlx5_sq_ts_translator(mdev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
index 14479da98f42..62ffb41a64df 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
@@ -182,6 +182,7 @@ mlx5e_txwqe_build_dsegs(struct mlx5e_txqsq *sq, struct sk_buff *skb,
unsigned char *skb_data, u16 headlen,
struct mlx5_wqe_data_seg *dseg)
{
+ bool dd = test_bit(MLX5E_SQ_STATE_DATA_DIRECT, &sq->state);
dma_addr_t dma_addr = 0;
u8 num_dma = 0;
int i;
@@ -211,7 +212,8 @@ mlx5e_txwqe_build_dsegs(struct mlx5e_txqsq *sq, struct sk_buff *skb,
goto dma_unmap_wqe_err;
dseg->addr = cpu_to_be64(dma_addr);
- dseg->lkey = sq->mkey_be;
+ dseg->lkey = dd && skb_frag_is_net_iov(frag) ?
+ sq->crossing_mkey_be : sq->mkey_be;
dseg->byte_count = cpu_to_be32(fsz);
mlx5e_dma_push_netmem(sq, skb_frag_netmem(frag), dma_addr, fsz);
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index abb99371ff13..4c8b447337f1 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -678,6 +678,7 @@ struct mlx5e_resources {
u32 pdn;
struct mlx5_td td;
u32 mkey;
+ u32 data_direct_crossing_mkey;
struct mlx5_sq_bfreg *bfregs;
unsigned int num_bfregs;
#define MLX5_MAX_NUM_TC 8
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (7 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 08/13] net/mlx5e: Add data direct TX infrastructure Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 10/13] net: devmem: add netdev_has_dmabuf_binding() helper Tariq Toukan
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
When the data_direct private flag is enabled, return the data direct
device instead of the NIC PF PCI device in .ndo_queue_get_dma_dev.
The memory provider maps the payload buffers against that device, so
the page_pool of a data direct RQ has to use it as well. Add
mlx5e_get_dma_dev() which returns the DMA device of an mlx5_core_dev for
either mode and use it in both places.
Running .ndo_queue_get_dma_dev while the data direct device is going
away returns NULL because the device pointer is already cleared.
Opening a data direct RQ fails with -ENODEV for the same reason.
Leased queues are not supported in data-direct mode because there is
currently no mechanism to revoke leased queues from the leaser.
Rename the dev argument to netdev because there are too many confusing
"dev"-based names in this function.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/en_main.c | 49 ++++++++++++++++---
1 file changed, 42 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 5b99099e4ed0..ebd41f24330d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -962,6 +962,19 @@ static void mlx5e_rq_free_shampo(struct mlx5e_rq *rq)
kvfree(shampo);
}
+static struct device *mlx5e_get_dma_dev(struct mlx5_core_dev *mdev,
+ bool data_direct)
+{
+ struct mlx5_data_direct_dev *dd_dev;
+
+ if (!data_direct)
+ return mlx5_core_dma_dev(mdev);
+
+ dd_dev = mlx5_data_direct_get_dev(mdev->data_direct);
+
+ return dd_dev ? dd_dev->device : NULL;
+}
+
static int mlx5e_alloc_rq(struct mlx5e_params *params,
struct mlx5e_rq_param *rq_param,
struct mlx5e_rq_opt_param *rqo,
@@ -1105,7 +1118,11 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,
pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
pp_params.pool_size = pool_size;
pp_params.nid = node;
- pp_params.dev = rq->pdev;
+ pp_params.dev = mlx5e_get_dma_dev(mdev, data_direct);
+ if (!pp_params.dev) {
+ err = -ENODEV;
+ goto err_free_by_rq_type;
+ }
pp_params.napi = rq->cq.napi;
pp_params.netdev = rq->netdev;
pp_params.dma_dir = rq->buff.map_dir;
@@ -5897,27 +5914,45 @@ static int mlx5e_queue_start(struct net_device *dev,
return 0;
}
-static struct device *mlx5e_queue_get_dma_dev(struct net_device *dev,
+static bool mlx5e_has_leased_rxqs(struct net_device *netdev)
+{
+ for (u32 i = 0; i < netdev->real_num_rx_queues; i++)
+ if (READ_ONCE(__netif_get_rx_queue(netdev, i)->lease))
+ return true;
+
+ return false;
+}
+
+static struct device *mlx5e_queue_get_dma_dev(struct net_device *netdev,
int queue_index)
{
- struct mlx5e_priv *priv = netdev_priv(dev);
+ struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5e_channels *channels;
- struct device *pdev = NULL;
+ struct device *dma_dev = NULL;
struct mlx5e_channel *ch;
+ bool dd;
channels = &priv->channels;
mutex_lock(&priv->state_lock);
- if (queue_index >= channels->num)
+ /* Allow only opened channels. */
+ if (queue_index < 0 || queue_index >= channels->num)
+ goto out;
+
+ dd = MLX5E_GET_PFLAG(&channels->params, MLX5E_PFLAG_DATA_DIRECT);
+ if (dd && mlx5e_has_leased_rxqs(netdev)) {
+ mlx5_core_err_rl(priv->mdev,
+ "Can't get queue DMA device: leased RX queues are not supported in data-direct mode\n");
goto out;
+ }
ch = channels->c[queue_index];
- pdev = ch->pdev;
+ dma_dev = mlx5e_get_dma_dev(ch->mdev, dd);
out:
mutex_unlock(&priv->state_lock);
- return pdev;
+ return dma_dev;
}
static const struct netdev_queue_mgmt_ops mlx5e_queue_mgmt_ops = {
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 10/13] net: devmem: add netdev_has_dmabuf_binding() helper
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (8 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 11/13] net: add netdev_unbind_dma_dev() helper Tariq Toukan
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu,
Bobby Eshleman
From: Dragos Tatulea <dtatulea@nvidia.com>
Currently there is no way to check whether a dmabuf is bound on a TX
queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint
of it.
To help with that, add a helper to check whether a devmem dmabuf
binding may still be in use on a given netdev, optionally filtered by
the DMA device the dmabuf was mapped against.
A binding can outlive the user's unbind: it can still be referenced by
in-flight TX skbs, whose DMA mappings are only valid for the device the
dmabuf was attached to. Reporting such a binding as gone would let a
driver swap the DMA device out from under those skbs. Bindings stay in
the bindings xarray until they are freed, so walk it and report every
binding of the netdev that is still mapped. Bindings that were already
unmapped are not reported.
This API is necessary for the upcoming support of data direct in mlx5e.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Cc: Bobby Eshleman <bobbyeshleman@gmail.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
include/net/netmem.h | 24 ++++++++++++++++++++++++
net/core/devmem.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index fb693bc1702a..35bb6fa0f719 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -397,16 +397,40 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
return netmem_to_nmdesc(netmem)->dma_addr;
}
+struct net_device;
+
#if defined(CONFIG_NET_DEVMEM)
static inline bool net_is_devmem_iov(const struct net_iov *niov)
{
return niov->type == NET_IOV_DMABUF;
}
+
+/**
+ * netdev_has_dmabuf_binding - is there a dmabuf binding for a
+ * given @dev and @dma_dev
+ *
+ * @dev: netdev to check bindings
+ * @dma_dev: dma device to check, when NULL it will not be checked
+ *
+ * A binding is reported for as long as it is mapped, which can be long
+ * after the user unbound it: net_iovs of a TX binding can still be queued
+ * in flight, with DMA mappings that are only valid for the device the dmabuf
+ * was attached to.
+ *
+ * Return: true if a binding is found under @dev and possibly @dma_dev
+ */
+bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
#else
static inline bool net_is_devmem_iov(const struct net_iov *niov)
{
return false;
}
+
+static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
+ struct device *dma_dev)
+{
+ return false;
+}
#endif
void net_iov_inc_ref(struct net_iov *niov);
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 5c7d9640e9d1..dd3987bbd9f6 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -513,6 +513,49 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
return binding;
}
+/* The attachment is cleared once the binding has been unmapped. */
+static bool
+net_devmem_binding_mapped_to(struct net_devmem_dmabuf_binding *binding,
+ struct device *dma_dev)
+{
+ lockdep_assert_held(&binding->lock);
+
+ return binding->attachment &&
+ (!dma_dev || binding->attachment->dev == dma_dev);
+}
+
+bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
+{
+ struct net_devmem_dmabuf_binding *binding;
+ unsigned long xa_idx;
+ bool found = false;
+
+ netdev_assert_locked(dev);
+
+ /* A binding stays in the xarray until it is freed. binding->dev is
+ * only cleared under the instance lock of that netdev, and the free
+ * takes it before erasing the binding, so a binding found under @dev
+ * stays alive while the xarray lock is dropped.
+ */
+ xa_lock(&net_devmem_dmabuf_bindings);
+ xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+ if (READ_ONCE(binding->dev) != dev)
+ continue;
+
+ xa_unlock(&net_devmem_dmabuf_bindings);
+ mutex_lock(&binding->lock);
+ found = net_devmem_binding_mapped_to(binding, dma_dev);
+ mutex_unlock(&binding->lock);
+ xa_lock(&net_devmem_dmabuf_bindings);
+ if (found)
+ break;
+ }
+ xa_unlock(&net_devmem_dmabuf_bindings);
+
+ return found;
+}
+EXPORT_SYMBOL_GPL(netdev_has_dmabuf_binding);
+
void net_devmem_net_iov_inc_ref(struct net_iov *niov)
{
net_devmem_dmabuf_binding_get(net_devmem_iov_binding(niov));
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 11/13] net: add netdev_unbind_dma_dev() helper
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (9 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 10/13] net: devmem: add netdev_has_dmabuf_binding() helper Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 12/13] net/mlx5e: Disable data direct on data direct device unbind Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 13/13] net/mlx5e: Enable the data direct netdev feature Tariq Toukan
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Currently the netdev code that binds dmabufs to a DMA device assumes
that the device is the netdev's own PCI device, and the unbind cleanup
is done under that assumption.
With the introduction of data direct in mlx5, this assumption no longer
holds: the DMA device is not the netdev's PCI device. When the data
direct DMA device is unbound, there is no way to clean up the bindings.
Add a helper that unbinds the dmabufs of a closed or detached netdev
from a DMA device, independent of the memory provider in use:
- RX: uninstall the memory provider of every RX queue whose DMA device
is the departing one or is gone. The uninstall callback unmaps the
buffers, for devmem and io_uring zcrx alike. The queues get regular
page pools on the next open.
- devmem TX: detach and unmap the TX bindings of the netdev mapped
against the device, as netdev unregister does. New sends fail and
in-flight skbs are dropped at xmit.
The netdev must be closed or detached so that the hardware no longer
accesses the mappings and the qdiscs hold no validated skbs. A detached
netdev also works because the driver has already torn down the queues
and new bindings can't be added.
For now leased queues owned by virtual netdevs are not supported by this
API. mlx5 refuses zero-copy while RX queues are leased in data direct
mode.
The helper only unmaps. The providers and bindings stay allocated until
their users release them.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
include/net/netdev_queues.h | 1 +
net/core/devmem.c | 42 ++++++++++++++++++++++++++++++
net/core/devmem.h | 6 +++++
net/core/netdev_queues.c | 51 +++++++++++++++++++++++++++++++++++++
4 files changed, 100 insertions(+)
diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h
index c5335e935b7d..f3f174f342b9 100644
--- a/include/net/netdev_queues.h
+++ b/include/net/netdev_queues.h
@@ -235,6 +235,7 @@ void netdev_queue_config(struct net_device *dev, int rxq,
struct netdev_queue_config *qcfg);
bool netif_rxq_has_unreadable_mp(struct net_device *dev, unsigned int rxq_idx);
+int netdev_unbind_dma_dev(struct net_device *dev, struct device *dma_dev);
/**
* DOC: Lockless queue stopping / waking helpers.
diff --git a/net/core/devmem.c b/net/core/devmem.c
index dd3987bbd9f6..bc8ae12b2318 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -556,6 +556,48 @@ bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
}
EXPORT_SYMBOL_GPL(netdev_has_dmabuf_binding);
+/* Unmap the bindings of a closed @dev that use @dma_dev, the way netdev
+ * unregister does. Senders that raced the detach drop their skbs at xmit.
+ */
+void net_devmem_unbind_dma_dev(struct net_device *dev, struct device *dma_dev)
+{
+ struct net_devmem_dmabuf_binding *binding;
+ unsigned long xa_idx;
+ bool match, live;
+
+ netdev_assert_locked(dev);
+
+ xa_lock(&net_devmem_dmabuf_bindings);
+ xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
+ if (READ_ONCE(binding->dev) != dev)
+ continue;
+
+ /* Hide the binding from TX lookups while it is checked. */
+ live = xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
+ NET_DEVMEM_BINDING_LIVE);
+ if (live)
+ __xa_clear_mark(&net_devmem_dmabuf_bindings, xa_idx,
+ NET_DEVMEM_BINDING_LIVE);
+ xa_unlock(&net_devmem_dmabuf_bindings);
+
+ mutex_lock(&binding->lock);
+ match = net_devmem_binding_mapped_to(binding, dma_dev);
+ mutex_unlock(&binding->lock);
+ if (match)
+ net_devmem_dmabuf_binding_unmap(binding);
+
+ xa_lock(&net_devmem_dmabuf_bindings);
+ if (match) {
+ WRITE_ONCE(binding->vdev, NULL);
+ WRITE_ONCE(binding->dev, NULL);
+ } else if (live) {
+ __xa_set_mark(&net_devmem_dmabuf_bindings, xa_idx,
+ NET_DEVMEM_BINDING_LIVE);
+ }
+ }
+ xa_unlock(&net_devmem_dmabuf_bindings);
+}
+
void net_devmem_net_iov_inc_ref(struct net_iov *niov)
{
net_devmem_dmabuf_binding_get(net_devmem_iov_binding(niov));
diff --git a/net/core/devmem.h b/net/core/devmem.h
index c4f476947dfa..06a86efc807d 100644
--- a/net/core/devmem.h
+++ b/net/core/devmem.h
@@ -106,6 +106,7 @@ void net_devmem_unlock_dev(struct net_device *dev,
netdevice_tracker *dev_tracker);
void net_devmem_unbind_dmabuf(struct net_devmem_dmabuf_binding *binding);
void net_devmem_dev_unregister(struct net_device *dev);
+void net_devmem_unbind_dma_dev(struct net_device *dev, struct device *dma_dev);
int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
struct net_devmem_dmabuf_binding *binding,
struct netlink_ext_ack *extack);
@@ -209,6 +210,11 @@ static inline void net_devmem_dev_unregister(struct net_device *dev)
{
}
+static inline void net_devmem_unbind_dma_dev(struct net_device *dev,
+ struct device *dma_dev)
+{
+}
+
static inline int
net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
struct net_devmem_dmabuf_binding *binding,
diff --git a/net/core/netdev_queues.c b/net/core/netdev_queues.c
index 27cb6397bdd4..71cc7bfc087d 100644
--- a/net/core/netdev_queues.c
+++ b/net/core/netdev_queues.c
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#include <net/netdev_lock.h>
#include <net/netdev_queues.h>
#include <net/netdev_rx_queue.h>
#include <net/xdp_sock_drv.h>
#include "dev.h"
+#include "devmem.h"
static struct device *
__netdev_queue_get_dma_dev(struct net_device *dev, unsigned int idx)
@@ -58,6 +60,55 @@ struct device *netdev_queue_get_dma_dev(struct net_device *dev,
return dma_dev;
}
+/**
+ * netdev_unbind_dma_dev() - drop the memory providers of a departing DMA device
+ * @dev: net_device, closed or detached by the caller
+ * @dma_dev: DMA device the driver is about to lose
+ *
+ * Uninstalls the memory provider of every RX queue of @dev that maps
+ * against @dma_dev. Unmaps the devmem bindings of @dev that use @dma_dev.
+ * The bindings stay allocated until their users release them.
+ *
+ * The provider of a leased RX queue is owned by the virtual netdev and
+ * can't be torn down here. Drivers must not report a DMA device they can
+ * lose for leased queues; such queues are skipped with a warning.
+ *
+ * Return: 0 on success, -EBUSY if @dev is running and present.
+ */
+int netdev_unbind_dma_dev(struct net_device *dev, struct device *dma_dev)
+{
+ unsigned int i;
+
+ netdev_assert_locked(dev);
+
+ if (netif_running(dev) && netif_device_present(dev))
+ return -EBUSY;
+
+ for (i = 0; i < dev->real_num_rx_queues; i++) {
+ struct netdev_rx_queue *rxq = __netif_get_rx_queue(dev, i);
+ struct pp_memory_provider_params p = rxq->mp_params;
+ struct device *queue_dev;
+
+ if (!p.mp_ops)
+ continue;
+
+ queue_dev = __netdev_queue_get_dma_dev(dev, i);
+ if (queue_dev && queue_dev != dma_dev)
+ continue;
+
+ if (WARN_ON_ONCE(rxq->lease))
+ continue;
+
+ memset(&rxq->mp_params, 0, sizeof(rxq->mp_params));
+ __netif_mp_uninstall_rxq(rxq, &p);
+ }
+
+ net_devmem_unbind_dma_dev(dev, dma_dev);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(netdev_unbind_dma_dev);
+
bool netdev_can_create_queue(const struct net_device *dev,
struct netlink_ext_ack *extack)
{
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 12/13] net/mlx5e: Disable data direct on data direct device unbind
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (10 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 11/13] net: add netdev_unbind_dma_dev() helper Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 13/13] net/mlx5e: Enable the data direct netdev feature Tariq Toukan
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
To prevent invalid accesses after the data direct device is unbound,
stop the netdev and drop the providers using the unbound DMA device. To
prevent further use disable the private flag.
Also release the providers during suspend because the notifier
is disabled at that point and a data direct device unbind would
go unnoticed. This would result in dangling references to the
unbound DMA device.
FW reset, devlink reload and health recovery are not affected: they
unregister the netdev, which releases the memory providers and dmabuf
bindings.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/data_direct.c | 4 +-
.../net/ethernet/mellanox/mlx5/core/en_main.c | 67 ++++++++++++++++++-
2 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
index 7db94b8a5b79..246a03f44afd 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/data_direct.c
@@ -198,9 +198,11 @@ static void mlx5_data_direct_bind(struct mlx5_data_direct_registration *reg,
static void
mlx5_data_direct_do_unbind(struct mlx5_data_direct_registration *reg)
{
+ struct mlx5_data_direct_dev *dev = reg->dd.dev;
+
WRITE_ONCE(reg->dd.dev, NULL);
blocking_notifier_call_chain(®->users, MLX5_DATA_DIRECT_UNBIND,
- NULL);
+ dev);
}
int mlx5_data_direct_init(struct mlx5_core_dev *mdev)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index ebd41f24330d..63d91ef0dda8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -6170,9 +6170,53 @@ static int mlx5e_data_direct_event(struct notifier_block *nb,
{
struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv,
data_direct_nb);
+ struct mlx5_data_direct_dev *dd_dev = data;
+ struct net_device *netdev = priv->netdev;
+ struct mlx5e_params new_params;
+ bool enabled, reopen;
+ int err;
+
+ if (action != MLX5_DATA_DIRECT_UNBIND)
+ return NOTIFY_DONE;
+
+ rtnl_lock();
+ netdev_lock(netdev);
+
+ mutex_lock(&priv->state_lock);
+ enabled = MLX5E_GET_PFLAG(&priv->channels.params,
+ MLX5E_PFLAG_DATA_DIRECT);
+ mutex_unlock(&priv->state_lock);
+ if (!enabled)
+ goto out;
+
+ reopen = netif_running(netdev);
+ netif_close(netdev);
+
+ err = netdev_unbind_dma_dev(netdev, dd_dev->device);
+ if (WARN_ON_ONCE(err)) {
+ netdev_err(netdev, "Failed to unbind dma device, won't reopen netdev, err=%d\n",
+ err);
+ goto out;
+ }
+
+ mutex_lock(&priv->state_lock);
+ new_params = priv->channels.params;
+ MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_DATA_DIRECT, false);
+ mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, false);
+ mutex_unlock(&priv->state_lock);
+
+ netdev_info(netdev, "data_direct device unbound, disabled data_direct\n");
- if (action == MLX5_DATA_DIRECT_UNBIND)
- mlx5_core_dbg(priv->mdev, "data direct device unbound\n");
+ if (reopen) {
+ err = netif_open(netdev, NULL);
+ if (err)
+ netdev_err(netdev, "Failed to reopen after data_direct unbind, err=%d\n",
+ err);
+ }
+
+out:
+ netdev_unlock(netdev);
+ rtnl_unlock();
return NOTIFY_OK;
}
@@ -6407,6 +6451,24 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv)
return err;
}
+static void mlx5e_data_direct_unbind_dev(struct mlx5e_priv *priv)
+{
+ struct mlx5_data_direct_dev *dd_dev;
+ bool enabled;
+
+ dd_dev = mlx5_data_direct_get_dev(priv->mdev->data_direct);
+ if (!dd_dev)
+ return;
+
+ mutex_lock(&priv->state_lock);
+ enabled = MLX5E_GET_PFLAG(&priv->channels.params,
+ MLX5E_PFLAG_DATA_DIRECT);
+ mutex_unlock(&priv->state_lock);
+ if (enabled)
+ WARN_ON_ONCE(netdev_unbind_dma_dev(priv->netdev,
+ dd_dev->device));
+}
+
static void mlx5e_nic_disable(struct mlx5e_priv *priv)
{
struct mlx5_core_dev *mdev = priv->mdev;
@@ -6424,6 +6486,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
mlx5e_close_trap(priv->en_trap);
priv->en_trap = NULL;
}
+ mlx5e_data_direct_unbind_dev(priv);
netdev_unlock(priv->netdev);
rtnl_unlock();
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net-next V2 13/13] net/mlx5e: Enable the data direct netdev feature
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
` (11 preceding siblings ...)
2026-11-10 18:38 ` [PATCH net-next V2 12/13] net/mlx5e: Disable data direct on data direct device unbind Tariq Toukan
@ 2026-11-10 18:38 ` Tariq Toukan
12 siblings, 0 replies; 14+ messages in thread
From: Tariq Toukan @ 2026-11-10 18:38 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Bobby Eshleman, Carolina Jubran, Cosmin Ratiu, Daniel Borkmann,
David Wei, Dragos Tatulea, Erfan Sharafzadeh, Gal Pressman,
Jacob Keller, Kaifeng Wang, Leon Romanovsky, open list,
linux-rdma, Mark Bloch, Matt Fleming, Mina Almasry,
Nikolay Aleksandrov, Saeed Mahameed, Simon Horman,
Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan, William Tu
From: Dragos Tatulea <dtatulea@nvidia.com>
Add the implementation of the data direct private flag.
This enables the feature altogether.
Do not allow state changes while a memory provider (devmem or io_uring
zcrx) is installed on an RX queue or while dmabufs are still bound to
the netdev for TX: their buffers are mapped against the DMA device of
the current mode. Same for leased rx queues.
Reject enabling the flag on uplink representors or in socket direct
mode.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 +
.../ethernet/mellanox/mlx5/core/en_ethtool.c | 63 ++++++++++++++++++-
.../net/ethernet/mellanox/mlx5/core/en_main.c | 2 +-
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 23e45e87cdee..cc7cf23b5c56 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -1155,6 +1155,7 @@ int fn##_ctx(struct mlx5e_priv *priv, void *context) \
return fn(priv); \
}
int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv);
+bool mlx5e_has_leased_rxqs(struct net_device *netdev);
int mlx5e_safe_switch_params(struct mlx5e_priv *priv,
struct mlx5e_params *new_params,
mlx5e_fp_preactivate preactivate,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 26f76449af35..2204b370f439 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -32,6 +32,7 @@
#include <linux/dim.h>
#include <linux/ethtool_netlink.h>
+#include <linux/mlx5/data_direct.h>
#include <net/netdev_queues.h>
#include "en.h"
@@ -40,7 +41,9 @@
#include "en/port.h"
#include "en/params.h"
#include "en/ptp.h"
+#include "en_rep.h"
#include "lib/clock.h"
+#include "lib/mlx5.h"
#include "en/fs_ethtool.h"
#define LANES_UNKNOWN 0
@@ -2407,7 +2410,65 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
static int set_pflag_data_direct(struct net_device *netdev, bool enable)
{
- return -EOPNOTSUPP;
+ struct mlx5e_priv *priv = netdev_priv(netdev);
+ struct mlx5_core_dev *mdev = priv->mdev;
+ struct mlx5e_params new_params;
+ unsigned int i;
+
+ if (enable) {
+ if (!mlx5_data_direct_supported(mdev) ||
+ !MLX5_CAP_GEN(mdev, crossing_vhca_mkey)) {
+ netdev_err(netdev, "data_direct is not supported by the device\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!MLX5_CAP_GEN(mdev, shampo)) {
+ netdev_err(netdev, "data_direct requires SHAMPO (Header-Data Split) support\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (mlx5_get_sd(mdev)) {
+ netdev_err(netdev, "data_direct is not supported with socket direct\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (mlx5e_is_uplink_rep(priv)) {
+ netdev_err(netdev, "data_direct is not supported for uplink representors\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!mlx5_data_direct_get_dev(mdev->data_direct)) {
+ netdev_err(netdev, "data_direct device not bound\n");
+ return -ENODEV;
+ }
+
+ if (mlx5e_has_leased_rxqs(netdev)) {
+ netdev_err(netdev, "data_direct is not supported with leased RX queues\n");
+ return -EBUSY;
+ }
+ }
+
+ /* Changing the flag reopens the channels with a different DMA device,
+ * which would break the memory providers installed on the RX queues
+ * (devmem or io_uring zcrx) and the dmabufs bound for TX.
+ */
+ for (i = 0; i < netdev->real_num_rx_queues; i++) {
+ if (netif_rxq_has_unreadable_mp(netdev, i)) {
+ netdev_err(netdev, "Can't change data_direct while rxq %u has a memory provider\n",
+ i);
+ return -EBUSY;
+ }
+ }
+
+ if (netdev_has_dmabuf_binding(netdev, NULL)) {
+ netdev_err(netdev, "Can't change data_direct while dmabufs are bound\n");
+ return -EBUSY;
+ }
+
+ new_params = priv->channels.params;
+ MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_DATA_DIRECT, enable);
+
+ return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
}
static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 63d91ef0dda8..ba4b09ab2d70 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -5914,7 +5914,7 @@ static int mlx5e_queue_start(struct net_device *dev,
return 0;
}
-static bool mlx5e_has_leased_rxqs(struct net_device *netdev)
+bool mlx5e_has_leased_rxqs(struct net_device *netdev)
{
for (u32 i = 0; i < netdev->real_num_rx_queues; i++)
if (READ_ONCE(__netif_get_rx_queue(netdev, i)->lease))
--
2.44.0
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-11-10 18:40 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 18:38 [PATCH net-next V2 00/13] net/mlx5e: Add netdev support for data direct Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 01/13] net/mlx5: Log the data direct to PF device mapping Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 02/13] net/mlx5: Detach auxiliary devices on attach failure during load Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 03/13] net/mlx5e: Register supported netdevs as data direct users Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 04/13] net/mlx5e: Pre-calculate UMR padding and entry size Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 05/13] net/mlx5e: Add data direct ethtool private flag Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 06/13] net/mlx5e: Add data direct RX infrastructure Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 07/13] net/mlx5e: SHAMPO, Use page_pool DMA sync helper for SKB frags Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 08/13] net/mlx5e: Add data direct TX infrastructure Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 10/13] net: devmem: add netdev_has_dmabuf_binding() helper Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 11/13] net: add netdev_unbind_dma_dev() helper Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 12/13] net/mlx5e: Disable data direct on data direct device unbind Tariq Toukan
2026-11-10 18:38 ` [PATCH net-next V2 13/13] net/mlx5e: Enable the data direct netdev feature Tariq Toukan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®