diff mbox series

[v5,07/16] dma/idxd: add configure and info_get functions

Message ID 20210917152437.3270330-8-kevin.laatz@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series add dmadev driver for idxd devices | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Kevin Laatz Sept. 17, 2021, 3:24 p.m. UTC
Add functions for device configuration. The info_get function is included
here since it can be useful for checking successful configuration.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Reviewed-by: Conor Walsh <conor.walsh@intel.com>

---
v2:
   - fix reconfigure bug in idxd_vchan_setup()
   - add literal include comment for the docs to pick up
v3:
   - fixes needed after changes from rebasing
---
 app/test/test_dmadev.c           |  2 +
 doc/guides/dmadevs/idxd.rst      | 30 +++++++++++++
 drivers/dma/idxd/idxd_bus.c      |  3 ++
 drivers/dma/idxd/idxd_common.c   | 72 ++++++++++++++++++++++++++++++++
 drivers/dma/idxd/idxd_internal.h |  6 +++
 drivers/dma/idxd/idxd_pci.c      |  3 ++
 6 files changed, 116 insertions(+)

Comments

Bruce Richardson Sept. 20, 2021, 10:27 a.m. UTC | #1
On Fri, Sep 17, 2021 at 03:24:28PM +0000, Kevin Laatz wrote:
> Add functions for device configuration. The info_get function is included
> here since it can be useful for checking successful configuration.
>
Since this patch makes a change in the test code to enable use in the docs,
that should be called out here too, I think, for example: "When providing
an example of the function's use in the documentation, use code snippet
from the unit tests".
Fengchengwen Sept. 22, 2021, 2:31 a.m. UTC | #2
On 2021/9/17 23:24, Kevin Laatz wrote:
> Add functions for device configuration. The info_get function is included
> here since it can be useful for checking successful configuration.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> Reviewed-by: Conor Walsh <conor.walsh@intel.com>
> 
> ---
> v2:
>    - fix reconfigure bug in idxd_vchan_setup()
>    - add literal include comment for the docs to pick up
> v3:
>    - fixes needed after changes from rebasing
> ---
>  app/test/test_dmadev.c           |  2 +
>  doc/guides/dmadevs/idxd.rst      | 30 +++++++++++++
>  drivers/dma/idxd/idxd_bus.c      |  3 ++
>  drivers/dma/idxd/idxd_common.c   | 72 ++++++++++++++++++++++++++++++++
>  drivers/dma/idxd/idxd_internal.h |  6 +++
>  drivers/dma/idxd/idxd_pci.c      |  3 ++
>  6 files changed, 116 insertions(+)
> 
> diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c
> index 98fcab67f3..5bbe4250e0 100644
> --- a/app/test/test_dmadev.c
> +++ b/app/test/test_dmadev.c
> @@ -739,6 +739,7 @@ test_dmadev_instance(uint16_t dev_id)
>  {
>  #define TEST_RINGSIZE 512
>  #define CHECK_ERRS    true
> +	/* Setup of the dmadev device. 8< */
>  	struct rte_dma_stats stats;
>  	struct rte_dma_info info;
>  	const struct rte_dma_conf conf = { .nb_vchans = 1};
> @@ -759,6 +760,7 @@ test_dmadev_instance(uint16_t dev_id)
>  
>  	if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0)
>  		ERR_RETURN("Error with queue configuration\n");
> +	/* >8 End of setup of the dmadev device. */
>  
>  	rte_dma_info_get(dev_id, &info);
>  	if (info.nb_vchans != 1)
> diff --git a/doc/guides/dmadevs/idxd.rst b/doc/guides/dmadevs/idxd.rst
> index ce33e2857a..abfa5be9ea 100644
> --- a/doc/guides/dmadevs/idxd.rst
> +++ b/doc/guides/dmadevs/idxd.rst
> @@ -120,3 +120,33 @@ use a subset of configured queues.
>  Once probed successfully, irrespective of kernel driver, the device will appear as a ``dmadev``,
>  that is a "DMA device type" inside DPDK, and can be accessed using APIs from the
>  ``rte_dmadev`` library.
> +
> +Using IDXD DMAdev Devices
> +--------------------------
> +
> +To use the devices from an application, the dmadev API can be used.
> +
> +Getting Device Information
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +Basic information about each dmadev device can be queried using the
> +``rte_dma_info_get()`` API. This will return basic device information such as
> +the ``rte_device`` structure, device capabilities and other device specific values.

The info_get cannot obtains 'rte_device' now.

> +
> +Device Configuration
> +~~~~~~~~~~~~~~~~~~~~~
> +
> +Configuring an IDXD dmadev device is done using the ``rte_dma_configure()`` and
> +``rte_dma_vchan_setup`` APIs. The configurations are passed to these APIs using
> +the ``rte_dma_conf`` and ``rte_dma_vchan_conf`` structures, respectively. For
> +example, these can be used to configure the number of ``vchans`` per device, the
> +ring size, etc. The ring size must be a power of two, between 64 and 4096.
> +
> +The following code shows how the device is configured in
> +``test_dmadev.c``:
> +
> +.. literalinclude:: ../../../app/test/test_dmadev.c
> +   :language: c
> +   :start-after: Setup of the dmadev device. 8<
> +   :end-before: >8 End of setup of the dmadev device.
> +   :dedent: 1
> diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
> index 3c0837ec52..b2acdac4f9 100644
> --- a/drivers/dma/idxd/idxd_bus.c
> +++ b/drivers/dma/idxd/idxd_bus.c
> @@ -96,6 +96,9 @@ idxd_dev_close(struct rte_dma_dev *dev)
>  static const struct rte_dma_dev_ops idxd_bus_ops = {
>  		.dev_close = idxd_dev_close,
>  		.dev_dump = idxd_dump,
> +		.dev_configure = idxd_configure,
> +		.vchan_setup = idxd_vchan_setup,
> +		.dev_info_get = idxd_info_get,
>  };
>  
>  static void *
> diff --git a/drivers/dma/idxd/idxd_common.c b/drivers/dma/idxd/idxd_common.c
> index 45cde78e88..2c222708cf 100644
> --- a/drivers/dma/idxd/idxd_common.c
> +++ b/drivers/dma/idxd/idxd_common.c
> @@ -39,6 +39,78 @@ idxd_dump(const struct rte_dma_dev *dev, FILE *f)
>  	return 0;
>  }
>  
> +int
> +idxd_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *info, uint32_t size)
> +{
> +	struct idxd_dmadev *idxd = dev->dev_private;
> +
> +	if (size < sizeof(*info))
> +		return -EINVAL;
> +
> +	*info = (struct rte_dma_info) {
> +			.dev_capa = RTE_DMA_CAPA_MEM_TO_MEM |
> +				RTE_DMA_CAPA_OPS_COPY | RTE_DMA_CAPA_OPS_FILL,
> +			.max_vchans = 1,
> +			.max_desc = 4096,
> +			.min_desc = 64,
> +			.nb_vchans = (idxd->desc_ring != NULL), /* returns 1 or 0 */

The nb_vchans field was filled by lib.

> +	};
> +	if (idxd->sva_support)
> +		info->dev_capa |= RTE_DMA_CAPA_SVA;
> +	return 0;
> +}
> +
> +int
> +idxd_configure(struct rte_dma_dev *dev __rte_unused, const struct rte_dma_conf *dev_conf,
> +		uint32_t conf_sz)
> +{
> +	if (sizeof(struct rte_dma_conf) != conf_sz)
> +		return -EINVAL;
> +
> +	if (dev_conf->nb_vchans != 1)
> +		return -EINVAL;
> +	return 0;
> +}
> +
> +int
> +idxd_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan __rte_unused,
> +		const struct rte_dma_vchan_conf *qconf, uint32_t qconf_sz)
> +{
> +	struct idxd_dmadev *idxd = dev->dev_private;
> +	uint16_t max_desc = qconf->nb_desc;
> +
> +	if (sizeof(struct rte_dma_vchan_conf) != qconf_sz)
> +		return -EINVAL;
> +
> +	idxd->qcfg = *qconf;
> +
> +	if (!rte_is_power_of_2(max_desc))
> +		max_desc = rte_align32pow2(max_desc);
> +	IDXD_PMD_DEBUG("DMA dev %u using %u descriptors", dev->data->dev_id, max_desc);
> +	idxd->desc_ring_mask = max_desc - 1;
> +	idxd->qcfg.nb_desc = max_desc;
> +
> +	/* in case we are reconfiguring a device, free any existing memory */
> +	rte_free(idxd->desc_ring);
> +
> +	/* allocate the descriptor ring at 2x size as batches can't wrap */
> +	idxd->desc_ring = rte_zmalloc(NULL, sizeof(*idxd->desc_ring) * max_desc * 2, 0);
> +	if (idxd->desc_ring == NULL)
> +		return -ENOMEM;
> +	idxd->desc_iova = rte_mem_virt2iova(idxd->desc_ring);
> +
> +	idxd->batch_idx_read = 0;
> +	idxd->batch_idx_write = 0;
> +	idxd->batch_start = 0;
> +	idxd->batch_size = 0;
> +	idxd->ids_returned = 0;
> +	idxd->ids_avail = 0;
> +
> +	memset(idxd->batch_comp_ring, 0, sizeof(*idxd->batch_comp_ring) *
> +			(idxd->max_batches + 1));
> +	return 0;
> +}
> +
>  int
>  idxd_dmadev_create(const char *name, struct rte_device *dev,
>  		   const struct idxd_dmadev *base_idxd,
> diff --git a/drivers/dma/idxd/idxd_internal.h b/drivers/dma/idxd/idxd_internal.h
> index 99c8e04302..fdd018ca35 100644
> --- a/drivers/dma/idxd/idxd_internal.h
> +++ b/drivers/dma/idxd/idxd_internal.h
> @@ -82,5 +82,11 @@ struct idxd_dmadev {
>  int idxd_dmadev_create(const char *name, struct rte_device *dev,
>  		const struct idxd_dmadev *base_idxd, const struct rte_dma_dev_ops *ops);
>  int idxd_dump(const struct rte_dma_dev *dev, FILE *f);
> +int idxd_configure(struct rte_dma_dev *dev, const struct rte_dma_conf *dev_conf,
> +		uint32_t conf_sz);
> +int idxd_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,
> +		const struct rte_dma_vchan_conf *qconf, uint32_t qconf_sz);
> +int idxd_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *dev_info,
> +		uint32_t size);
>  
>  #endif /* _IDXD_INTERNAL_H_ */
> diff --git a/drivers/dma/idxd/idxd_pci.c b/drivers/dma/idxd/idxd_pci.c
> index 33cf76adfb..0216ab80d9 100644
> --- a/drivers/dma/idxd/idxd_pci.c
> +++ b/drivers/dma/idxd/idxd_pci.c
> @@ -61,6 +61,9 @@ idxd_is_wq_enabled(struct idxd_dmadev *idxd)
>  
>  static const struct rte_dma_dev_ops idxd_pci_ops = {
>  	.dev_dump = idxd_dump,
> +	.dev_configure = idxd_configure,
> +	.vchan_setup = idxd_vchan_setup,
> +	.dev_info_get = idxd_info_get,
>  };
>  
>  /* each portal uses 4 x 4k pages */
>
diff mbox series

Patch

diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c
index 98fcab67f3..5bbe4250e0 100644
--- a/app/test/test_dmadev.c
+++ b/app/test/test_dmadev.c
@@ -739,6 +739,7 @@  test_dmadev_instance(uint16_t dev_id)
 {
 #define TEST_RINGSIZE 512
 #define CHECK_ERRS    true
+	/* Setup of the dmadev device. 8< */
 	struct rte_dma_stats stats;
 	struct rte_dma_info info;
 	const struct rte_dma_conf conf = { .nb_vchans = 1};
@@ -759,6 +760,7 @@  test_dmadev_instance(uint16_t dev_id)
 
 	if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0)
 		ERR_RETURN("Error with queue configuration\n");
+	/* >8 End of setup of the dmadev device. */
 
 	rte_dma_info_get(dev_id, &info);
 	if (info.nb_vchans != 1)
diff --git a/doc/guides/dmadevs/idxd.rst b/doc/guides/dmadevs/idxd.rst
index ce33e2857a..abfa5be9ea 100644
--- a/doc/guides/dmadevs/idxd.rst
+++ b/doc/guides/dmadevs/idxd.rst
@@ -120,3 +120,33 @@  use a subset of configured queues.
 Once probed successfully, irrespective of kernel driver, the device will appear as a ``dmadev``,
 that is a "DMA device type" inside DPDK, and can be accessed using APIs from the
 ``rte_dmadev`` library.
+
+Using IDXD DMAdev Devices
+--------------------------
+
+To use the devices from an application, the dmadev API can be used.
+
+Getting Device Information
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Basic information about each dmadev device can be queried using the
+``rte_dma_info_get()`` API. This will return basic device information such as
+the ``rte_device`` structure, device capabilities and other device specific values.
+
+Device Configuration
+~~~~~~~~~~~~~~~~~~~~~
+
+Configuring an IDXD dmadev device is done using the ``rte_dma_configure()`` and
+``rte_dma_vchan_setup`` APIs. The configurations are passed to these APIs using
+the ``rte_dma_conf`` and ``rte_dma_vchan_conf`` structures, respectively. For
+example, these can be used to configure the number of ``vchans`` per device, the
+ring size, etc. The ring size must be a power of two, between 64 and 4096.
+
+The following code shows how the device is configured in
+``test_dmadev.c``:
+
+.. literalinclude:: ../../../app/test/test_dmadev.c
+   :language: c
+   :start-after: Setup of the dmadev device. 8<
+   :end-before: >8 End of setup of the dmadev device.
+   :dedent: 1
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index 3c0837ec52..b2acdac4f9 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -96,6 +96,9 @@  idxd_dev_close(struct rte_dma_dev *dev)
 static const struct rte_dma_dev_ops idxd_bus_ops = {
 		.dev_close = idxd_dev_close,
 		.dev_dump = idxd_dump,
+		.dev_configure = idxd_configure,
+		.vchan_setup = idxd_vchan_setup,
+		.dev_info_get = idxd_info_get,
 };
 
 static void *
diff --git a/drivers/dma/idxd/idxd_common.c b/drivers/dma/idxd/idxd_common.c
index 45cde78e88..2c222708cf 100644
--- a/drivers/dma/idxd/idxd_common.c
+++ b/drivers/dma/idxd/idxd_common.c
@@ -39,6 +39,78 @@  idxd_dump(const struct rte_dma_dev *dev, FILE *f)
 	return 0;
 }
 
+int
+idxd_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *info, uint32_t size)
+{
+	struct idxd_dmadev *idxd = dev->dev_private;
+
+	if (size < sizeof(*info))
+		return -EINVAL;
+
+	*info = (struct rte_dma_info) {
+			.dev_capa = RTE_DMA_CAPA_MEM_TO_MEM |
+				RTE_DMA_CAPA_OPS_COPY | RTE_DMA_CAPA_OPS_FILL,
+			.max_vchans = 1,
+			.max_desc = 4096,
+			.min_desc = 64,
+			.nb_vchans = (idxd->desc_ring != NULL), /* returns 1 or 0 */
+	};
+	if (idxd->sva_support)
+		info->dev_capa |= RTE_DMA_CAPA_SVA;
+	return 0;
+}
+
+int
+idxd_configure(struct rte_dma_dev *dev __rte_unused, const struct rte_dma_conf *dev_conf,
+		uint32_t conf_sz)
+{
+	if (sizeof(struct rte_dma_conf) != conf_sz)
+		return -EINVAL;
+
+	if (dev_conf->nb_vchans != 1)
+		return -EINVAL;
+	return 0;
+}
+
+int
+idxd_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan __rte_unused,
+		const struct rte_dma_vchan_conf *qconf, uint32_t qconf_sz)
+{
+	struct idxd_dmadev *idxd = dev->dev_private;
+	uint16_t max_desc = qconf->nb_desc;
+
+	if (sizeof(struct rte_dma_vchan_conf) != qconf_sz)
+		return -EINVAL;
+
+	idxd->qcfg = *qconf;
+
+	if (!rte_is_power_of_2(max_desc))
+		max_desc = rte_align32pow2(max_desc);
+	IDXD_PMD_DEBUG("DMA dev %u using %u descriptors", dev->data->dev_id, max_desc);
+	idxd->desc_ring_mask = max_desc - 1;
+	idxd->qcfg.nb_desc = max_desc;
+
+	/* in case we are reconfiguring a device, free any existing memory */
+	rte_free(idxd->desc_ring);
+
+	/* allocate the descriptor ring at 2x size as batches can't wrap */
+	idxd->desc_ring = rte_zmalloc(NULL, sizeof(*idxd->desc_ring) * max_desc * 2, 0);
+	if (idxd->desc_ring == NULL)
+		return -ENOMEM;
+	idxd->desc_iova = rte_mem_virt2iova(idxd->desc_ring);
+
+	idxd->batch_idx_read = 0;
+	idxd->batch_idx_write = 0;
+	idxd->batch_start = 0;
+	idxd->batch_size = 0;
+	idxd->ids_returned = 0;
+	idxd->ids_avail = 0;
+
+	memset(idxd->batch_comp_ring, 0, sizeof(*idxd->batch_comp_ring) *
+			(idxd->max_batches + 1));
+	return 0;
+}
+
 int
 idxd_dmadev_create(const char *name, struct rte_device *dev,
 		   const struct idxd_dmadev *base_idxd,
diff --git a/drivers/dma/idxd/idxd_internal.h b/drivers/dma/idxd/idxd_internal.h
index 99c8e04302..fdd018ca35 100644
--- a/drivers/dma/idxd/idxd_internal.h
+++ b/drivers/dma/idxd/idxd_internal.h
@@ -82,5 +82,11 @@  struct idxd_dmadev {
 int idxd_dmadev_create(const char *name, struct rte_device *dev,
 		const struct idxd_dmadev *base_idxd, const struct rte_dma_dev_ops *ops);
 int idxd_dump(const struct rte_dma_dev *dev, FILE *f);
+int idxd_configure(struct rte_dma_dev *dev, const struct rte_dma_conf *dev_conf,
+		uint32_t conf_sz);
+int idxd_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,
+		const struct rte_dma_vchan_conf *qconf, uint32_t qconf_sz);
+int idxd_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *dev_info,
+		uint32_t size);
 
 #endif /* _IDXD_INTERNAL_H_ */
diff --git a/drivers/dma/idxd/idxd_pci.c b/drivers/dma/idxd/idxd_pci.c
index 33cf76adfb..0216ab80d9 100644
--- a/drivers/dma/idxd/idxd_pci.c
+++ b/drivers/dma/idxd/idxd_pci.c
@@ -61,6 +61,9 @@  idxd_is_wq_enabled(struct idxd_dmadev *idxd)
 
 static const struct rte_dma_dev_ops idxd_pci_ops = {
 	.dev_dump = idxd_dump,
+	.dev_configure = idxd_configure,
+	.vchan_setup = idxd_vchan_setup,
+	.dev_info_get = idxd_info_get,
 };
 
 /* each portal uses 4 x 4k pages */