[dpdk-dev] [PATCH v3 2/8] net/virtio: introduce DMA ops

Xia, Chenbo chenbo.xia at intel.com
Wed Sep 30 07:47:27 CEST 2020


> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin at redhat.com>
> Sent: Wednesday, September 30, 2020 12:14 AM
> To: dev at dpdk.org; Xia, Chenbo <chenbo.xia at intel.com>; Fu, Patrick
> <patrick.fu at intel.com>; amorenoz at redhat.com
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Subject: [PATCH v3 2/8] net/virtio: introduce DMA ops
> 
> Add DMA map/unmap callbacks to the virtio_user pmd, which could
> be leveraged by vdev bus driver to map memory for backend
> devices with DMA capability.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
>  drivers/net/virtio/virtio_user/vhost.h  |  4 ++
>  drivers/net/virtio/virtio_user_ethdev.c | 54 +++++++++++++++++++++++++
>  2 files changed, 58 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost.h
> b/drivers/net/virtio/virtio_user/vhost.h
> index 8f49ef4574..2e71995a79 100644
> --- a/drivers/net/virtio/virtio_user/vhost.h
> +++ b/drivers/net/virtio/virtio_user/vhost.h
> @@ -105,6 +105,10 @@ struct virtio_user_backend_ops {
>  	int (*enable_qp)(struct virtio_user_dev *dev,
>  			 uint16_t pair_idx,
>  			 int enable);
> +	int (*dma_map)(struct virtio_user_dev *dev, void *addr,
> +				  uint64_t iova, size_t len);
> +	int (*dma_unmap)(struct virtio_user_dev *dev, void *addr,
> +				  uint64_t iova, size_t len);
>  };
> 
>  extern struct virtio_user_backend_ops virtio_ops_user;
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index 87f6cb6950..60d17af888 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -818,9 +818,63 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev)
>  	return 0;
>  }
> 
> +static int virtio_user_pmd_dma_map(struct rte_vdev_device *vdev, void
> *addr,
> +		uint64_t iova, size_t len)
> +{
> +	const char *name;
> +	struct rte_eth_dev *eth_dev;
> +	struct virtio_user_dev *dev;
> +	struct virtio_hw *hw;
> +
> +	if (!vdev)
> +		return -EINVAL;
> +
> +	name = rte_vdev_device_name(vdev);
> +	eth_dev = rte_eth_dev_allocated(name);
> +	/* Port has already been released by close. */
> +	if (!eth_dev)
> +		return 0;
> +
> +	hw = (struct virtio_hw *)eth_dev->data->dev_private;
> +	dev = hw->virtio_user_dev;
> +
> +	if (dev->ops->dma_map)
> +		return dev->ops->dma_map(dev, addr, iova, len);
> +
> +	return 0;
> +}
> +
> +static int virtio_user_pmd_dma_unmap(struct rte_vdev_device *vdev, void
> *addr,
> +		uint64_t iova, size_t len)
> +{
> +	const char *name;
> +	struct rte_eth_dev *eth_dev;
> +	struct virtio_user_dev *dev;
> +	struct virtio_hw *hw;
> +
> +	if (!vdev)
> +		return -EINVAL;
> +
> +	name = rte_vdev_device_name(vdev);
> +	eth_dev = rte_eth_dev_allocated(name);
> +	/* Port has already been released by close. */
> +	if (!eth_dev)
> +		return 0;
> +
> +	hw = (struct virtio_hw *)eth_dev->data->dev_private;
> +	dev = hw->virtio_user_dev;
> +
> +	if (dev->ops->dma_unmap)
> +		return dev->ops->dma_unmap(dev, addr, iova, len);
> +
> +	return 0;
> +}
> +
>  static struct rte_vdev_driver virtio_user_driver = {
>  	.probe = virtio_user_pmd_probe,
>  	.remove = virtio_user_pmd_remove,
> +	.dma_map = virtio_user_pmd_dma_map,
> +	.dma_unmap = virtio_user_pmd_dma_unmap,
>  };
> 
>  RTE_PMD_REGISTER_VDEV(net_virtio_user, virtio_user_driver);
> --
> 2.26.2

Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>


More information about the dev mailing list