[PATCH net-next 10/10] net/mlx5e: Enable the data direct netdev feature
From: Tariq Toukan
Date: Thu Oct 08 2026 - 09:39:51 EST
From: Dragos Tatulea <dtatulea@xxxxxxxxxx>
Add the implementation of the data direct private flag.
This enables the feature altogether.
Do not allow state changes while dmabufs are still bound
to the netdev.
Signed-off-by: Dragos Tatulea <dtatulea@xxxxxxxxxx>
Signed-off-by: Tariq Toukan <tariqt@xxxxxxxxxx>
---
.../ethernet/mellanox/mlx5/core/en_ethtool.c | 36 ++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index b3eced1dd43f..8ab1150ce3f2 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"
@@ -2402,7 +2403,40 @@ 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;
+
+ 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_data_direct_get_dev(mdev->data_direct)) {
+ netdev_err(netdev, "data_direct device not bound\n");
+ return -ENODEV;
+ }
+ }
+
+ /* Changing the flag reopens the channels with a different DMA device,
+ * which would break any dmabuf currently bound to this netdev.
+ */
+ 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] = {
--
2.44.0