[PATCH net-next V2 09/13] net/mlx5e: Use the correct DMA dev when data_direct is enabled
From: Tariq Toukan
Date: Tue Nov 10 2026 - 13:57:04 EST
From: Dragos Tatulea <dtatulea@xxxxxxxxxx>
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@xxxxxxxxxx>
Reviewed-by: Cosmin Ratiu <cratiu@xxxxxxxxxx>
Signed-off-by: Tariq Toukan <tariqt@xxxxxxxxxx>
---
.../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