]> www.infradead.org Git - users/hch/misc.git/commitdiff
net/mlx5e: add op for getting netdev DMA device
authorDragos Tatulea <dtatulea@nvidia.com>
Wed, 27 Aug 2025 14:39:58 +0000 (17:39 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 Aug 2025 23:05:31 +0000 (16:05 -0700)
For zero-copy (devmem, io_uring), the netdev DMA device used
is the parent device of the net device. However that is not
always accurate for mlx5 devices:
- SFs: The parent device is an auxdev.
- Multi-PF netdevs: The DMA device should be determined by
  the queue.

This change implements the DMA device queue API that returns the DMA
device appropriately for all cases.

Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Link: https://patch.msgid.link/20250827144017.1529208-6-dtatulea@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index 21bb88c5d3dcee48c6918743d630cfc48f349d34..0e48065a46eb96078b5ef0c8180a25636e9c6322 100644 (file)
@@ -5625,12 +5625,36 @@ static int mlx5e_queue_start(struct net_device *dev, void *newq,
        return 0;
 }
 
+static struct device *mlx5e_queue_get_dma_dev(struct net_device *dev,
+                                             int queue_index)
+{
+       struct mlx5e_priv *priv = netdev_priv(dev);
+       struct mlx5e_channels *channels;
+       struct device *pdev = NULL;
+       struct mlx5e_channel *ch;
+
+       channels = &priv->channels;
+
+       mutex_lock(&priv->state_lock);
+
+       if (queue_index >= channels->num)
+               goto out;
+
+       ch = channels->c[queue_index];
+       pdev = ch->pdev;
+out:
+       mutex_unlock(&priv->state_lock);
+
+       return pdev;
+}
+
 static const struct netdev_queue_mgmt_ops mlx5e_queue_mgmt_ops = {
        .ndo_queue_mem_size     =       sizeof(struct mlx5_qmgmt_data),
        .ndo_queue_mem_alloc    =       mlx5e_queue_mem_alloc,
        .ndo_queue_mem_free     =       mlx5e_queue_mem_free,
        .ndo_queue_start        =       mlx5e_queue_start,
        .ndo_queue_stop         =       mlx5e_queue_stop,
+       .ndo_queue_get_dma_dev  =       mlx5e_queue_get_dma_dev,
 };
 
 static void mlx5e_build_nic_netdev(struct net_device *netdev)