DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: "Xia, Chenbo" <chenbo.xia@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"Fu, Patrick" <patrick.fu@intel.com>,
	"amorenoz@redhat.com" <amorenoz@redhat.com>
Subject: Re: [dpdk-dev] [PATCH 1/7] bus/vdev: add DMA mapping ops
Date: Thu, 24 Sep 2020 09:40:45 +0200	[thread overview]
Message-ID: <f8ec747c-8f49-e5af-12a6-8961aab0c474@redhat.com> (raw)
In-Reply-To: <MN2PR11MB40635D1B321D95BFE074B8599C390@MN2PR11MB4063.namprd11.prod.outlook.com>



On 9/24/20 7:25 AM, Xia, Chenbo wrote:
> Hi Maxime,
> 
>> -----Original Message-----
>> From: dev <dev-bounces@dpdk.org> On Behalf Of Maxime Coquelin
>> Sent: Friday, September 11, 2020 11:08 PM
>> To: dev@dpdk.org; Fu, Patrick <patrick.fu@intel.com>; amorenoz@redhat.com
>> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Subject: [dpdk-dev] [PATCH 1/7] bus/vdev: add DMA mapping ops
>>
>> Add DMA map/unmap operation callbacks to the vdev bus, which
>> could be used by DMA capable vdev drivers.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>  drivers/bus/vdev/rte_bus_vdev.h | 46 +++++++++++++++++++++++++++--
>>  drivers/bus/vdev/vdev.c         | 52 +++++++++++++++++++++++++++++++++
>>  2 files changed, 95 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/bus/vdev/rte_bus_vdev.h
>> b/drivers/bus/vdev/rte_bus_vdev.h
>> index 78a032cea8..3fe0b35a82 100644
>> --- a/drivers/bus/vdev/rte_bus_vdev.h
>> +++ b/drivers/bus/vdev/rte_bus_vdev.h
>> @@ -63,14 +63,54 @@ typedef int (rte_vdev_probe_t)(struct rte_vdev_device
>> *dev);
>>   */
>>  typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
>>
>> +/**
>> + * Driver-specific DMA mapping. After a successful call the device
>> + * will be able to read/write from/to this segment.
>> + *
>> + * @param dev
>> + *   Pointer to the Virtual device.
>> + * @param addr
>> + *   Starting virtual address of memory to be mapped.
>> + * @param iova
>> + *   Starting IOVA address of memory to be mapped.
>> + * @param len
>> + *   Length of memory segment being mapped.
>> + * @return
>> + *   - 0 On success.
>> + *   - Negative value and rte_errno is set otherwise.
>> + */
>> +typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
>> +			    uint64_t iova, size_t len);
>> +
>> +/**
>> + * Driver-specific DMA un-mapping. After a successful call the device
>> + * will not be able to read/write from/to this segment.
>> + *
>> + * @param dev
>> + *   Pointer to the Virtual device.
>> + * @param addr
>> + *   Starting virtual address of memory to be unmapped.
>> + * @param iova
>> + *   Starting IOVA address of memory to be unmapped.
>> + * @param len
>> + *   Length of memory segment being unmapped.
>> + * @return
>> + *   - 0 On success.
>> + *   - Negative value and rte_errno is set otherwise.
>> + */
>> +typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void
>> *addr,
>> +			      uint64_t iova, size_t len);
>> +
>>  /**
>>   * A virtual device driver abstraction.
>>   */
>>  struct rte_vdev_driver {
>>  	TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
>> -	struct rte_driver driver;      /**< Inherited general driver. */
>> -	rte_vdev_probe_t *probe;       /**< Virtual device probe function.
>> */
>> -	rte_vdev_remove_t *remove;     /**< Virtual device remove function.
>> */
>> +	struct rte_driver driver;        /**< Inherited general driver. */
>> +	rte_vdev_probe_t *probe;         /**< Virtual device probe function.
>> */
>> +	rte_vdev_remove_t *remove;       /**< Virtual device remove function.
>> */
>> +	rte_vdev_dma_map_t *dma_map;     /**< vdev DMA map function. */
>> +	rte_vdev_dma_unmap_t *dma_unmap; /**< vdev DMA unmap function. */
>>  };
> 
> I think we'd better unify the term 'Virtual device' or 'vdev'? Maybe just
> use Virtual device.

Right, fixing it in v2.

>>
>>  /**
>> diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
>> index d746149a2e..455d0bd0c2 100644
>> --- a/drivers/bus/vdev/vdev.c
>> +++ b/drivers/bus/vdev/vdev.c
>> @@ -134,6 +134,56 @@ vdev_parse(const char *name, void *addr)
>>  	return driver == NULL;
>>  }
>>
>> +static int
>> +vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t
>> len)
>> +{
>> +	struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
>> +	const struct rte_vdev_driver *driver;
>> +
>> +	if (!vdev) {
>> +		rte_errno = EINVAL;
>> +		return -1;
>> +	}
>> +
>> +	if (!vdev->device.driver) {
>> +		VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
>> +		return 1;
>> +	}
>> +
>> +	driver = container_of(vdev->device.driver, const struct
>> rte_vdev_driver,
>> +			driver);
>> +
>> +	if (driver->dma_map)
>> +		return driver->dma_map(vdev, addr, iova, len);
>> +
>> +	return 0;
>> +}
>> +
>> +static int
>> +vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t
>> len)
>> +{
>> +	struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
>> +	const struct rte_vdev_driver *driver;
>> +
>> +	if (!vdev) {
>> +		rte_errno = EINVAL;
>> +		return -1;
>> +	}
>> +
>> +	if (!vdev->device.driver) {
>> +		VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
>> +		return 1;
>> +	}
>> +
>> +	driver = container_of(vdev->device.driver, const struct
>> rte_vdev_driver,
>> +			driver);
>> +
>> +	if (driver->dma_unmap)
>> +		return driver->dma_unmap(vdev, addr, iova, len);
>> +
>> +	return 0;	return 0;
> 
> Duplicate return here 😊

Oops!

Maxime

> Thanks!
> Chenbo
> 
>> +}
>> +
>>  static int
>>  vdev_probe_all_drivers(struct rte_vdev_device *dev)
>>  {
>> @@ -551,6 +601,8 @@ static struct rte_bus rte_vdev_bus = {
>>  	.plug = vdev_plug,
>>  	.unplug = vdev_unplug,
>>  	.parse = vdev_parse,
>> +	.dma_map = vdev_dma_map,
>> +	.dma_unmap = vdev_dma_unmap,
>>  	.dev_iterate = rte_vdev_dev_iterate,
>>  };
>>
>> --
>> 2.26.2
> 


  reply	other threads:[~2020-09-24  7:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11 15:07 [dpdk-dev] [PATCH 0/7]virtio-user: introduce vhost-vdpa backend Maxime Coquelin
2020-09-11 15:07 ` [dpdk-dev] [PATCH 1/7] bus/vdev: add DMA mapping ops Maxime Coquelin
2020-09-24  5:25   ` Xia, Chenbo
2020-09-24  7:40     ` Maxime Coquelin [this message]
2020-09-11 15:08 ` [dpdk-dev] [PATCH 2/7] net/virtio: introduce DMA ops Maxime Coquelin
2020-09-11 15:08 ` [dpdk-dev] [PATCH 3/7] net/virtio: introduce Vhost-vDPA backend type Maxime Coquelin
2020-09-11 15:08 ` [dpdk-dev] [PATCH 4/7] net/virtio: adapt Virtio-user status size Maxime Coquelin
2020-09-24  5:25   ` Xia, Chenbo
2020-09-24  8:05     ` Maxime Coquelin
2020-09-11 15:08 ` [dpdk-dev] [PATCH 5/7] net/virtio: check protocol feature in user backend Maxime Coquelin
2020-09-11 15:08 ` [dpdk-dev] [PATCH 6/7] net/virtio: split virtio-user start Maxime Coquelin
2020-09-11 15:08 ` [dpdk-dev] [PATCH 7/7] net/virtio: introduce Vhost-vDPA backend Maxime Coquelin
2020-09-24  5:25   ` Xia, Chenbo
2020-09-24  5:43     ` Fu, Patrick
2020-09-24  5:52       ` Xia, Chenbo
2020-09-24  8:07     ` Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f8ec747c-8f49-e5af-12a6-8961aab0c474@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=amorenoz@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=patrick.fu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).