dmadev: introduce DMA device library
Subsystems (3)
PATCH 1/1 dmadev: introduce DMA device library
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
--- MAINTAINERS | 4 + config/rte_config.h | 3 + lib/dmadev/meson.build | 6 + lib/dmadev/rte_dmadev.c | 438 +++++++++++++++++++++ lib/dmadev/rte_dmadev.h | 919 +++++++++++++++++++++++++++++++++++++++++++ lib/dmadev/rte_dmadev_core.h | 98 +++++ lib/dmadev/rte_dmadev_pmd.h | 210 ++++++++++ lib/dmadev/version.map | 32 ++ lib/meson.build | 1 + 9 files changed, 1711 insertions(+) create mode 100644 lib/dmadev/meson.build create mode 100644 lib/dmadev/rte_dmadev.c create mode 100644 lib/dmadev/rte_dmadev.h create mode 100644 lib/dmadev/rte_dmadev_core.h create mode 100644 lib/dmadev/rte_dmadev_pmd.h create mode 100644 lib/dmadev/version.map
MAINTAINERS +4 -0
@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst +Dma device API +M: Chengwen Feng <[email protected]> +F: lib/dmadev/ + Memory Pool Drivers -------------------
config/rte_config.h +3 -0
@@ -81,6 +81,9 @@/* rawdev defines */ #define RTE_RAWDEV_MAX_DEVS 64 +/* dmadev defines */ +#define RTE_DMADEV_MAX_DEVS 64 +/* ip_fragmentation defines */ #define RTE_LIBRTE_IP_FRAG_MAX_FRAG 4#undef RTE_LIBRTE_IP_FRAG_TBL_STAT
lib/dmadev/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2021 HiSilicon Limited. + +sources = files('rte_dmadev.c') +headers = files('rte_dmadev.h', 'rte_dmadev_pmd.h') +indirect_headers += files('rte_dmadev_core.h')
lib/dmadev/rte_dmadev.c new file +438 -0
438 lines not on this page · raw message
lib/dmadev/rte_dmadev.h new file +919 -0
919 lines not on this page · raw message
lib/dmadev/rte_dmadev_core.h new file +98 -0
98 lines not on this page · raw message
lib/dmadev/rte_dmadev_pmd.h new file +210 -0
210 lines not on this page · raw message
lib/dmadev/version.map new file +32 -0
@@ -0,0 +1,32 @@ +EXPERIMENTAL { + global: + + rte_dmadev_count; + rte_dmadev_get_dev_id; + rte_dmadev_socket_id; + rte_dmadev_info_get; + rte_dmadev_configure; + rte_dmadev_start; + rte_dmadev_stop; + rte_dmadev_close; + rte_dmadev_reset; + rte_dmadev_queue_setup; + rte_dmadev_queue_release; + rte_dmadev_queue_info_get; + rte_dmadev_copy; + rte_dmadev_copy_sg; + rte_dmadev_fill; + rte_dmadev_fill_sg; + rte_dmadev_fence; + rte_dmadev_perform; + rte_dmadev_completed; + rte_dmadev_completed_fails; + rte_dmadev_stats_get; + rte_dmadev_stats_reset; + rte_dmadev_xstats_names_get; + rte_dmadev_xstats_get; + rte_dmadev_xstats_reset; + rte_dmadev_selftest; + + local: *; +};
lib/meson.build +1 -0
@@ -60,6 +60,7 @@ libraries = [ 'bpf', 'graph', 'node', + 'dmadev', ] if is_windows
Signature · 1 line
2.8.1
Quoted 8 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
Thanks for this new revision. We will try porting our driver implementations under this API and see how it performs. We'll send on feedback later based on that and based on code review.
/Bruce
Quoted 8 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>
Thanks for v1.
I would suggest finalizing lib/dmadev/rte_dmadev.h before doing the implementation so that you don't need
to waste time on rewoking the implementation.
Comments inline.
Quoted 9 lines
--- MAINTAINERS | 4 + config/rte_config.h | 3 + lib/dmadev/meson.build | 6 + lib/dmadev/rte_dmadev.c | 438 +++++++++++++++++++++ lib/dmadev/rte_dmadev.h | 919 +++++++++++++++++++++++++++++++++++++++++++ lib/dmadev/rte_dmadev_core.h | 98 +++++ lib/dmadev/rte_dmadev_pmd.h | 210 ++++++++++ lib/dmadev/version.map | 32 ++
Missed to update doxygen. See doc/api/doxy-api.conf.in Use meson -Denable_docs=true to verify the generated doxgen doc.
Quoted 14 lines
lib/meson.build | 1 + 9 files changed, 1711 insertions(+) create mode 100644 lib/dmadev/meson.build create mode 100644 lib/dmadev/rte_dmadev.c create mode 100644 lib/dmadev/rte_dmadev.h create mode 100644 lib/dmadev/rte_dmadev_core.h create mode 100644 lib/dmadev/rte_dmadev_pmd.h create mode 100644 lib/dmadev/version.mapMAINTAINERS +0
-0
MAINTAINERS F: drivers/raw/skeleton/ · line 498
Quoted 3 lines
MAINTAINERS +0
-0@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst
Add EXPERIMENTAL
Quoted 18 lines
MAINTAINERS +4
-0+Dma device API +M: Chengwen Feng <[email protected]> +F: lib/dmadev/ +new file mode 100644
index 0000000..a94e839lib/dmadev/rte_dmadev.c new file +7
-0@@ -0,0 +1,438 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#include <ctype.h> +#include <stdlib.h> +#include <string.h>
lib/dmadev/rte_dmadev.c line 17
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+#include <stdint.h> + +#include <rte_log.h> +#include <rte_debug.h> +#include <rte_dev.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_malloc.h> +#include <rte_errno.h> +#include <rte_string_fns.h>
Sort in alphabetical order.
lib/dmadev/rte_dmadev.c line 22
Quoted 5 lines
lib/dmadev/rte_dmadev.c new file +5
-0+ +#include "rte_dmadev.h" +#include "rte_dmadev_pmd.h" + +struct rte_dmadev rte_dmadevices[RTE_DMADEV_MAX_DEVS ];
# Please check have you missed any multiprocess angle. lib/regexdev/rte_regexdev.c is latest device class implemented in dpdk and please check *rte_regexdev_shared_data scheme.
# Missing dynamic log for this library.
lib/dmadev/rte_dmadev.h line 2
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +2
-0@@ -0,0 +1,919 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited.
It would be nice to add other companies' names who have contributed to the specification.
Quoted 15 lines
lib/dmadev/rte_dmadev.h new file +15
-0+*/ + +#ifndef _RTE_DMADEV_H_ +#define _RTE_DMADEV_H_ + +/** +* @file rte_dmadev.h +* +* RTE DMA (Direct Memory Access) device APIs. +* +* The generic DMA device diagram: +* +* ------------ ------------ +* | HW-queue | | HW-queue | +* ------------ ------------
lib/dmadev/rte_dmadev.h line 27
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* \ / +* \ / +* \ / +* ---------------- +* |dma-controller| +* ---------------- +* +* The DMA could have multiple HW-queues, each HW-queue could have multiple +* capabilities, e.g. whether to support fill operation, supported DMA +* transfter direction and etc.
typo
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+* +* The DMA framework is built on the following abstraction model: +* +* ------------ ------------ +* |virt-queue| |virt-queue| +* ------------ ------------ +* \ / +* \ /
lib/dmadev/rte_dmadev.h line 45
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* \ / +* ------------ ------------ +* | HW-queue | | HW-queue | +* ------------ ------------ +* \ / +* \ / +* \ / +* ---------- +* | dmadev | +* ----------
Continuing the discussion with @Morten Brørup , I think, we need to finalize the model.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+* a) The DMA operation request must be submitted to the virt queue, virt +* queues must be created based on HW queues, the DMA device could have +* multiple HW queues. +* b) The virt queues on the same HW-queue could represent different contexts, +* e.g. user could create virt-queue-0 on HW-queue-0 for mem-to-mem +* transfer scenario, and create virt-queue-1 on the same HW-queue for
lib/dmadev/rte_dmadev.h line 62
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* mem-to-dev transfer scenario. +* NOTE: user could also create multiple virt queues for mem-to-mem transfer +* scenario as long as the corresponding driver supports. +* +* The control plane APIs include configure/queue_setup/queue_release/start/ +* stop/reset/close, in order to start device work, the call sequence must be +* as follows: +* - rte_dmadev_configure() +* - rte_dmadev_queue_setup() +* - rte_dmadev_start()
Please add reconfigure behaviour etc, Please check the lib/regexdev/rte_regexdev.h
introduction. I have added similar ones so you could reuse as much as possible.
Quoted 24 lines
lib/dmadev/rte_dmadev.h new file +24
-0+* The dataplane APIs include two parts: +* a) The first part is the submission of operation requests: +* - rte_dmadev_copy() +* - rte_dmadev_copy_sg() - scatter-gather form of copy +* - rte_dmadev_fill() +* - rte_dmadev_fill_sg() - scatter-gather form of fill +* - rte_dmadev_fence() - add a fence force ordering between operations +* - rte_dmadev_perform() - issue doorbell to hardware +* These APIs could work with different virt queues which have different +* contexts. +* The first four APIs are used to submit the operation request to the virt +* queue, if the submission is successful, a cookie (as type +* 'dma_cookie_t') is returned, otherwise a negative number is returned. +* b) The second part is to obtain the result of requests: +* - rte_dmadev_completed() +* - return the number of operation requests completed successfully. +* - rte_dmadev_completed_fails() +* - return the number of operation requests failed to complete. +* +* The misc APIs include info_get/queue_info_get/stats/xstats/selftest, provide +* information query and self-test capabilities. +* +* About the dataplane APIs MT-safe, there are two dimensions: +* a) For one virt queue, the submit/completion API could be MT-safe,
lib/dmadev/rte_dmadev.h line 97
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* e.g. one thread do submit operation, another thread do completion +* operation. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VQ. +* If driver don't support it, it's up to the application to guarantee +* MT-safe. +* b) For multiple virt queues on the same HW queue, e.g. one thread do +* operation on virt-queue-0, another thread do operation on virt-queue-1. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MVQ. +* If driver don't support it, it's up to the application to guarantee +* MT-safe.
From an application PoV it may not be good to write portable applications. Please check
latest thread with @Morten Brørup
lib/dmadev/rte_dmadev.h line 107
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rte_common.h> +#include <rte_memory.h> +#include <rte_errno.h> +#include <rte_compat.h>
Sort in alphabetical order.
lib/dmadev/rte_dmadev.h line 110
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+ +/** +* dma_cookie_t - an opaque DMA cookie
Since we are defining the behaviour is not opaque any more. I think, it is better to call ring_idx or so.
lib/dmadev/rte_dmadev.h line 204
Quoted 1 line
lib/dmadev/rte_dmadev.h new file +1
-0+#define RTE_DMA_DEV_CAPA_MT_MVQ (1ull << 11)/**< Support MT-safe of multiple virt queues */
Please lot of @see for all symbols where it is being used. So that one can understand the full scope of
symbols. See below example.
#define RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F (1ULL << 0) /**< RegEx device does support compiling the rules at runtime unlike
* loading only the pre-built rule database using
* struct rte_regexdev_config::rule_db in rte_regexdev_configure() *
* @see struct rte_regexdev_config::rule_db, rte_regexdev_configure()
* @see struct rte_regexdev_info::regexdev_capa
*/
Quoted 9 lines
lib/dmadev/rte_dmadev.h new file +9
-0+* +* If dma_cookie_t is >=0 it's a DMA operation request cookie, <0 it's a error +* code. +* When using cookies, comply with the following rules: +* a) Cookies for each virtual queue are independent. +* b) For a virt queue, the cookie are monotonically incremented, when it reach +* the INT_MAX, it wraps back to zero. +* c) The initial cookie of a virt queue is zero, after the device is stopped or +* reset, the virt queue's cookie needs to be reset to zero.
lib/dmadev/rte_dmadev.h line 129
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Example: +* step-1: start one dmadev +* step-2: enqueue a copy operation, the cookie return is 0 +* step-3: enqueue a copy operation again, the cookie return is 1 +* ... +* step-101: stop the dmadev +* step-102: start the dmadev +* step-103: enqueue a copy operation, the cookie return is 0 +* ... +*/
Good explanation.
lib/dmadev/rte_dmadev.h line 135
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +6
-0+typedef int32_t dma_cookie_t ; + +/** +* dma_scatterlist - can hold scatter DMA operation request +*/ +struct dma_scatterlist {
I prefer to change scatterlist -> sg
i.e rte_dma_sg
Quoted 4 lines
lib/dmadev/rte_dmadev.h new file +4
-0+void *src; +void *dst; +uint32_t length; +};
lib/dmadev/rte_dmadev.h line 212
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +9
-0+ + +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok
typo.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/**
lib/dmadev/rte_dmadev.h line 228
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */
Please add max_nb_segs. i.e maximum number of segments supported.
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + i + +/** +* dma_address_type +*/
lib/dmadev/rte_dmadev.h line 270
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */
I think, there are 3 kinds of limitations/capabilities.
When the system is configured as IOVA as VA
1) Device supports any VA address like memory from rte_malloc(), rte_memzone(), malloc, stack memory
2) Device support only VA address from rte_malloc(), rte_memzone() i.e memory backed by hugepage and added to DMA map.
When the system is configured as IOVA as PA
1) Devices support only PA addresses .
IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.
lib/dmadev/rte_dmadev.h line 272
Quoted 2 lines
lib/dmadev/rte_dmadev.h new file +2
-0+uint16_t nb_hw_queues;/**< Number of HW-queues enable to use */ +uint16_t max_vqs;/**< Maximum number of virt queues to use */
You need to what is max value allowed etc i.e it is based on info_get() and mention the field
in info structure
lib/dmadev/rte_dmadev.h line 384
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* dma_transfer_direction +*/ +enum dma_transfer_direction {
rte_dma_transter_direction
Quoted 7 lines
lib/dmadev/rte_dmadev.h new file +7
-0+DMA_MEM_TO_MEM , +DMA_MEM_TO_DEV , +DMA_DEV_TO_MEM , + DMA_DEV_TO_DEV, +}; + +/**
lib/dmadev/rte_dmadev.h line 399
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +8
-0+* A structure used to configure a DMA virt queue. +*/ +struct rte_dmadev_queue_conf { +enum dma_transfer_direction direction; +/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */
Use of this? Need more comments on this.
Since it is in slowpath, We can have non opaque names here based on each driver capability.
Quoted 1 line
+ void
*dev_ctx; /**< Device specific context */
Use of this ? Need more comment ont this.
Please add some good amount of reserved bits and have API to init this structure for future ABI stability, say rte_dmadev_queue_config_init() or so.
lib/dmadev/rte_dmadev.h line 447
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction;
A queue may support all directions so I think it should be a bitfield.
lib/dmadev/rte_dmadev.h line 545
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +11
-0+/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)
I would like to change this as:
rte_dmadev_copy_sg(uint16_t dev_id, uint16_t vq_id, const struct rte_dma_sg *src, uint32_t nb_src,
const struct rte_dma_sg *dst, uint32_t nb_dst) or so allow the use case like src 30 MB copy can be splitted as written as 1 MB x 30 dst.
Quoted 16 lines
lib/dmadev/rte_dmadev.h new file +16
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy_sg)(dev, vq_id, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the DMA virt queue +* +* This queues up a fill operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device.
lib/dmadev/rte_dmadev.h line 571
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the destination buffer. +* @param flags +* An opaque flags for this operation.
PLEASE REMOVE opaque stuff from fastpath it will be a pain for application writers as
they need to write multiple combinations of fastpath. flags are OK, if we have a valid
generic flag now to control the transfer behavior.
Quoted 22 lines
lib/dmadev/rte_dmadev.h new file +22
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add a fence to force ordering between operations +* +* This adds a fence to a sequence of operations to enforce ordering, such that +* all operations enqueued before the fence must be completed before operations +* after the fence. +* NOTE: Since this fence may be added as a flag to the last operation enqueued, +* this API may not function correctly when called immediately after an +* "rte_dmadev_perform" call i.e. before any new operations are enqueued. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful add fence. +* - <0: Failure to add fence. +*
lib/dmadev/rte_dmadev.h line 657
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +}
Since HW submission is in a queue(FIFO) the ordering is always maintained. Right?
Could you share more details and use case of fence() from driver/application PoV?
Quoted 19 lines
lib/dmadev/rte_dmadev.h new file +19
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +*
lib/dmadev/rte_dmadev.h line 686
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +}
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successful completed. +* +* @param dev_id +* The identifier of the device. +* @param vq_id
lib/dmadev/rte_dmadev.h line 706
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* The identifier of virt queue. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] cookie +* The last completed operation's cookie. +* @param[out] has_error +* Indicates if there are transfer error. +* +* @return +* The number of operations that successful completed.
successfully
lib/dmadev/rte_dmadev.h line 718
Quoted 12 lines
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +8
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_cpls, +dma_cookie_t *cookie,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + has_error = false; +return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error);
It may be better to have cookie/ring_idx as third argument.
lib/dmadev/rte_dmadev.h line 731
Quoted 13 lines
lib/dmadev/rte_dmadev.h new file +13
-0+} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue.
(> + * @param nb_status
Quoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */
lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)
IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called after rte_dmadev_completed() hashas_error. Is it better to change
rte_dmadev_error_status((uint16_t dev_id, uint16_t vq_id, dma_cookie_t *cookie, uint32_t *status)
I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existing rte_flow_error
See
struct rte_flow_error {
enum rte_flow_error_type type; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} +
lib/dmadev/rte_dmadev.h line 764
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ +uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};
We need to have capability API to tell which items are updated/supported by the driver.
Quoted 18 lines
lib/dmadev/rte_dmadev_core.h new file +12
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +*
lib/dmadev/rte_dmadev_core.h line 22
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ + +struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */
To avoid namespace conflict(as it is public API) use rte_
Quoted 11 lines
lib/dmadev/rte_dmadev_core.h new file +11
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill;
lib/dmadev/rte_dmadev_core.h line 78
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence; +/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails;
We need to limit fastpath items in 1 CL
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+ +void *dev_private;/**< PMD-specific private data */ +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD */ +
lib/dmadev/rte_dmadev_core.h line 92
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+uint16_t dev_id;/**< Device ID for this instance */ +int socket_id;/**< Socket ID where memory is allocated */ +struct rte_device *device; +/**< Device info. supplied during device initialization */ +const char *driver_name;/**< Driver info. supplied by probing */ +char name[RTE_DMADEV_NAME_MAX_LEN ];/**< Device name */ + +RTE_STD_C11 + uint8_t attached : 1; /**< Flag indicating the device is attached */ + uint8_t started : 1; /**< Device state: STARTED(1)/STOPPED(0) */
Add a couple of reserved fields for future ABI stability.
Quoted 5 lines
lib/dmadev/rte_dmadev_core.h new file +5
-0+ +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; +
Quoted 8 lines · Jerin Jacob
Quoted 7 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Quoted 8 lines
Quoted 1 line
Signed-off-by Chengwen Feng <[email protected]>Thanks for v1.
I would suggest finalizing
lib/dmadev/rte_dmadev.hbefore doing the implementation so that you don't need
to waste time on rewoking the implementation.
I actually like having the .c file available too. Before we lock down the .h file and the API, I want to verify the performance of our drivers with the implementation, and having a working .c file is obviously necessary for that. So I appreciate having it as part of the RFC.
Quoted 3 lines
Comments inline.
Quoted 1 line
---
<snip>
Quoted 19 lines
Quoted 18 lines
+ *
+ * The DMA framework is built on the following abstraction model:
+ *+ * ------------ ------------ + * |virt-queue| |virt-queue| + * ------------ ------------ + * \ / + * \ / + * \ / + * ------------ ------------ + * | HW-queue | | HW-queue | + * ------------ ------------ + * \ / + * \ / + * \ / + * ---------- + * | dmadev | + * ----------
Quoted 3 lines
Continuing the discussion with @Morten Brørup , I think, we need to finalize the model.
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Quoted 74 lines
Quoted 13 lines
+ * a) The DMA operation request must be submitted to the virt queue, virt
+ * queues must be created based on HW queues, the DMA device could have
+ * multiple HW queues.
+ * b) The virt queues on the same HW-queue could represent different contexts,+ * e.g. user could create virt-queue-0 on HW-queue-0 for mem-to-mem + * transfer scenario, and create virt-queue-1 on the same HW-queue for + * mem-to-dev transfer scenario.+ * NOTE: user could also create multiple virt queues for mem-to-mem transfer
+ * scenario as long as the corresponding driver supports.
+ *
+ * The control plane APIs include configure/queue_setup/queue_release/start/
+ * stop/reset/close, in order to start device work, the call sequence must be
+ * as follows:Quoted 3 lines
+ * - rte_dmadev_configure() + * - rte_dmadev_queue_setup() + * - rte_dmadev_start()Please add reconfigure behaviour etc, Please check the
lib/regexdev/rte_regexdev.h
introduction. I have added similar ones so you could reuse as much as possible.Quoted 24 lines
+ * The dataplane APIs include two parts:
+ * a) The first part is the submission of operation requests:+ * - rte_dmadev_copy() + * - rte_dmadev_copy_sg() - scatter-gather form of copy + * - rte_dmadev_fill() + * - rte_dmadev_fill_sg() - scatter-gather form of fill + * - rte_dmadev_fence() - add a fence force ordering between operations + * - rte_dmadev_perform() - issue doorbell to hardware + * These APIs could work with different virt queues which have different + * contexts. + * The first four APIs are used to submit the operation request to the virt + * queue, if the submission is successful, a cookie (as type + * 'dma_cookie_t') is returned, otherwise a negative number is returned.+ * b) The second part is to obtain the result of requests:
+ * -rte_dmadev_completed()
+ * - return the number of operation requests completed successfully.
+ * -rte_dmadev_completed_fails()
+ * - return the number of operation requests failed to complete.
+ *
+ * The misc APIs include info_get/queue_info_get/stats/xstats/selftest, provide
+ * information query and self-test capabilities.
+ *
+ * About the dataplane APIs MT-safe, there are two dimensions:
+ * a) For one virt queue, the submit/completion API could be MT-safe,Quoted 10 lines
+ * e.g. one thread do submit operation, another thread do completion + * operation. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe. + * b) For multiple virt queues on the same HW queue, e.g. one thread do + * operation on virt-queue-0, another thread do operation on virt-queue-1. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MVQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe.From an application PoV it may not be good to write portable applications. Please check
latest thread with @Morten Brøruplib/dmadev/rte_dmadev.h line 107
Quoted 10 lines
+ */
lib/dmadev/rte_dmadev.h new file +9
-0+ +#ifdef __cplusplus +extern "C" { +#endif + +#include <rte_common.h> +#include <rte_memory.h> +#include <rte_errno.h> +#include <rte_compat.h> Sort in alphabetical order.
Quoted 7 lines
lib/dmadev/rte_dmadev.h line 110
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+ +/** +* dma_cookie_t - an opaque DMA cookie Since we are defining the behaviour is not opaque any more. I think, it is better to call
ring_idxor so.
+1 for ring index. We don't need a separate type for it though, just document the index as an unsigned return value.
Quoted 7 lines
Quoted 2 lines
+#define
RTE_DMA_DEV_CAPA_MT_MVQ(1ull << 11) /**< Support MT-safe of multiple virt queues */Please lot of @see for all symbols where it is being used. So that one can understand the full scope of
symbols. See below example.
Quoted 16 lines
#define
RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F(1ULL << 0) /**< RegEx device does support compiling the rules at runtime unlike
* loading only the pre-built rule database using
* structrte_regexdev_config::rule_dbinrte_regexdev_configure()*
* @see structrte_regexdev_config::rule_db,rte_regexdev_configure()
* @see structrte_regexdev_info::regexdev_capa
*/Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.
I disagree with the INT_MAX (or INT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for the INT_MAX value. Better to:
1. Specify that it wraps at UINT16_MAX which allows us to just use a uint16_t internally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >= UINT16_MAX, giving drivers the flexibility at what value to wrap around.
Quoted 13 lines
Quoted 11 lines
+ * c) The initial cookie of a virt queue is zero, after the device is stopped or
+ * reset, the virt queue's cookie needs to be reset to zero.
+ * Example:+ * step-1: start one dmadev + * step-2: enqueue a copy operation, the cookie return is 0 + * step-3: enqueue a copy operation again, the cookie return is 1 + * ... + * step-101: stop the dmadev + * step-102: start the dmadev + * step-103: enqueue a copy operation, the cookie return is 0 + * ...Quoted 1 line
+ */
Quoted 4 lines
Good explanation.
Quoted 1 line
+typedef
int32_tdma_cookie_t;
As I mentioned before, I'd just remove this, and use regular int types, with "ring_idx" as the name.
Quoted 77 lines
lib/dmadev/rte_dmadev.h line 135
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* dma_scatterlist - can hold scatter DMA operation request +*/ +struct dma_scatterlist {I prefer to change scatterlist -> sg
i.erte_dma_sgQuoted 4 lines
lib/dmadev/rte_dmadev.h new file +4
-0+void *src; +void *dst; +uint32_t length; +};lib/dmadev/rte_dmadev.h line 212
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +9
-0+ + +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok typo.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** lib/dmadev/rte_dmadev.h line 228
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */ Please add
max_nb_segs. i.e maximum number of segments supported.Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + i + +/** +* dma_address_type +*/ lib/dmadev/rte_dmadev.h line 270
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ I think, there are 3 kinds of limitations/capabilities.
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.
Quoted 8 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.
I don't think we need this level of detail for addressing capabilities. Unless I'm missing something, the hardware should behave exactly as other hardware does taking in iova's. If the user wants to check whether virtual addresses to pinned memory can be used directly, the user can call "rte_eal_iova_mode". We can't have a situation where some hardware uses one type of addresses and another hardware the other.
Therefore, the only additional addressing capability we should need to report is that the hardware can use SVM/SVA and use virtual addresses not in hugepage memory.
Quoted 35 lines
lib/dmadev/rte_dmadev.h line 272
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +2
-0+uint16_t nb_hw_queues;/**< Number of HW-queues enable to use */ +uint16_t max_vqs;/**< Maximum number of virt queues to use */ You need to what is max value allowed etc i.e it is based on
info_get()and mention the field
in info structurelib/dmadev/rte_dmadev.h line 384
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* dma_transfer_direction +*/ +enum dma_transfer_direction {
rte_dma_transter_directionQuoted 7 lines
lib/dmadev/rte_dmadev.h new file +7
-0+DMA_MEM_TO_MEM , +DMA_MEM_TO_DEV , +DMA_DEV_TO_MEM , + DMA_DEV_TO_DEV, +}; + +/** lib/dmadev/rte_dmadev.h line 399
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +8
-0+* A structure used to configure a DMA virt queue. +*/ +struct rte_dmadev_queue_conf { +enum dma_transfer_direction direction; +/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */
Quoted 9 lines
Use of this? Need more comments on this.
Since it is in slowpath, We can have non opaque names here based on each driver capability.Quoted 1 line
+ void
*dev_ctx; /**< Device specific context */Use of this ? Need more comment ont this.
I think this should be dropped. We should not have any opaque device-specific info in these structs, rather if a particular device needs parameters we should call them out. Drivers for which it's not relevant can ignore them (and report same in capability if necessary). Since this is not a dataplane API, we aren't concerned too much about perf and can size the struct appropriately.
Quoted 5 lines
Please add some good amount of reserved bits and have API to init this structure for future ABI stability, say
rte_dmadev_queue_config_init()or so.
I don't think that is necessary. Since the config struct is used only as parameter to the config function, any changes to it can be managed by versioning that single function. Padding would only be necessary if we had an array of these config structs somewhere.
Quoted 55 lines
lib/dmadev/rte_dmadev.h line 447
Quoted 7 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction;A queue may support all directions so I think it should be a bitfield.
lib/dmadev/rte_dmadev.h line 545
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +11
-0+/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)I would like to change this as:
rte_dmadev_copy_sg(uint16_tdev_id,uint16_tvq_id, const structrte_dma_sg*src,uint32_tnb_src,
const structrte_dma_sg*dst,uint32_tnb_dst) or so allow the use case like src 30 MB copy can be splitted as written as 1 MB x 30 dst.Quoted 24 lines
lib/dmadev/rte_dmadev.h new file +24
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy_sg)(dev, vq_id, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the DMA virt queue +* +* This queues up a fill operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the destination buffer.
Quoted 9 lines
Quoted 2 lines
+ * @param flags
+ * An opaque flags for this operation.PLEASE REMOVE opaque stuff from fastpath it will be a pain for application writers as
they need to write multiple combinations of fastpath. flags are OK, if we have a valid
generic flag now to control the transfer behavior.
+1. Flags need to be explicitly listed. If we don't have any flags for now, we can specify that the value must be given as zero and it's for future use.
Quoted 30 lines
Quoted 30 lines
lib/dmadev/rte_dmadev.h new file +29
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add a fence to force ordering between operations +* +* This adds a fence to a sequence of operations to enforce ordering, such that +* all operations enqueued before the fence must be completed before operations +* after the fence. +* NOTE: Since this fence may be added as a flag to the last operation enqueued, +* this API may not function correctly when called immediately after an +* "rte_dmadev_perform" call i.e. before any new operations are enqueued. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful add fence. +* - <0: Failure to add fence. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 657
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +}Since HW submission is in a queue(FIFO) the ordering is always maintained. Right?
Could you share more details and use case offence()from driver/application PoV?
There are different kinds of ordering to consider, ordering of completions and the ordering of operations. While jobs are reported as completed to the user in order, for performance hardware, may overlap individual jobs within a burst (or even across bursts). Therefore, we need a fence operation to inform hardware that one job should not be started until the other has fully completed.
Quoted 27 lines
Quoted 27 lines
lib/dmadev/rte_dmadev.h new file +26
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 686
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +}Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
Quoted 24 lines
Quoted 11 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successful completed. +* +* @param dev_id +* The identifier of the device. +* @param vq_id lib/dmadev/rte_dmadev.h line 706
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* The identifier of virt queue. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] cookie +* The last completed operation's cookie. +* @param[out] has_error +* Indicates if there are transfer error. +* +* @return +* The number of operations that successful completed. successfully
Quoted 15 lines
lib/dmadev/rte_dmadev.h line 718
Quoted 12 lines
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +8
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_cpls, +dma_cookie_t *cookie,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + has_error = false; +return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error);It may be better to have cookie/ring_idx as third argument.
No strong opinions here, but having it as in the code above means all input parameters come before all output, which makes sense to me.
Quoted 44 lines
lib/dmadev/rte_dmadev.h line 731
Quoted 13 lines
lib/dmadev/rte_dmadev.h new file +13
-0+} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. (> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_error
Quoted 7 lines
See
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};
I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 10 lines
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
I also would remove the enqueue fail counts, since they are better counted by the app. If a driver reports 20,000 failures we have no way of knowing if that is 20,000 unique operations which failed to enqueue or a single operation which failed to enqueue 20,000 times but succeeded on attempt 20,001.
Quoted 48 lines
Quoted 19 lines
lib/dmadev/rte_dmadev_core.h new file +12
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* lib/dmadev/rte_dmadev_core.h line 22
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ + +struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */ To avoid namespace conflict(as it is public API) use
rte_Quoted 15 lines
lib/dmadev/rte_dmadev_core.h new file +15
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence;
Quoted 9 lines
lib/dmadev/rte_dmadev_core.h line 78
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails;We need to limit fastpath items in 1 CL
I don't think that is going to be possible. I also would like to see numbers to check if we benefit much from having these fastpath ops separate from the regular ops.
Quoted 22 lines
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+ +void *dev_private;/**< PMD-specific private data */ +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD */ +lib/dmadev/rte_dmadev_core.h line 92
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+uint16_t dev_id;/**< Device ID for this instance */ +int socket_id;/**< Socket ID where memory is allocated */ +struct rte_device *device; +/**< Device info. supplied during device initialization */ +const char *driver_name;/**< Driver info. supplied by probing */ +char name[RTE_DMADEV_NAME_MAX_LEN ];/**< Device name */ + +RTE_STD_C11 + uint8_t attached : 1; /**< Flag indicating the device is attached */ + uint8_t started : 1; /**< Device state: STARTED(1)/STOPPED(0) */Add a couple of reserved fields for future ABI stability.
Quoted 5 lines
lib/dmadev/rte_dmadev_core.h new file +5
-0+ +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; +
Quoted 34 lines
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Monday, 5 July 2021 12.53Quoted 1 line · Jerin Jacob
On Fri, Jul 2, 2021 at 6:51 PM Chengwen Feng
Quoted 9 lines · <[email protected]> wrote:
lib/dmadev/rte_dmadev_core.h
Quoted 9 lines
lib/dmadev/rte_dmadev_core.h new file +8
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence; +/**< Trigger hardware to begin performing enqueued operations. */
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ dmadev_perform_t perform; + /**< Returns the number of operations that successfulcompleted. */
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ dmadev_completed_t completed; + /**< Returns the number of operations that failed tocomplete. */
Quoted 2 lines
Quoted 1 line
+
dmadev_completed_fails_tcompleted_fails;
Quoted 7 lines
Quoted 2 lines
We need to limit fastpath items in 1 CL
I don't think that is going to be possible. I also would like to see numbers to check if we benefit much from having these fastpath ops separate
from the regular ops.
The fastpath ops may not fit into 1 cache line, but it is a good design practice to separate hot data from cold data, and I do consider the fastpath function pointers hot and configuration function pointers cold.
The important point is keeping all the fastpath ops (of a dmadevice) together and spanning as few cache lines as possible.
Configuration ops and other slow data may follow in the same structure; that should make no performance difference. It might make a difference for memory consumption if the other data are very large and not dynamically allocated, as we are discussing regarding ethdev.
Quoted 42 lines · Morten Brørup
Quoted 34 lines
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Monday, 5 July 2021 12.53Quoted 1 line · Jerin Jacob
On Fri, Jul 2, 2021 at 6:51 PM Chengwen Feng
Quoted 9 lines · <[email protected]> wrote:
lib/dmadev/rte_dmadev_core.h
Quoted 9 lines
lib/dmadev/rte_dmadev_core.h new file +8
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence; +/**< Trigger hardware to begin performing enqueued operations. */
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ dmadev_perform_t perform; + /**< Returns the number of operations that successfulcompleted. */
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ dmadev_completed_t completed; + /**< Returns the number of operations that failed tocomplete. */
Quoted 2 lines
Quoted 1 line
+
dmadev_completed_fails_tcompleted_fails;Quoted 7 lines
Quoted 2 lines
We need to limit fastpath items in 1 CL
I don't think that is going to be possible. I also would like to see numbers to check if we benefit much from having these fastpath ops separate
from the regular ops.
Quoted 6 lines
The fastpath ops may not fit into 1 cache line, but it is a good design practice to separate hot data from cold data, and I do consider the fastpath function pointers hot and configuration function pointers cold.
The important point is keeping all the fastpath ops (of a dmadevice) together and spanning as few cache lines as possible.
Configuration ops and other slow data may follow in the same structure; that should make no performance difference. It might make a difference for memory consumption if the other data are very large and not dynamically allocated, as we are discussing regarding ethdev.
Yes, I agree if it can be done, it should be.
need
Quoted 19 lines · Bruce Richardson
Quoted 8 lines · Jerin Jacob
Quoted 7 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Quoted 8 lines
Quoted 1 line
Signed-off-by Chengwen Feng <[email protected]>Thanks for v1.
I would suggest finalizing
lib/dmadev/rte_dmadev.hbefore doing the implementation so that you don't need
to waste time on rewoking the implementation.
Quoted 4 lines
I actually like having the .c file available too. Before we lock down the .h file and the API, I want to verify the performance of our drivers with the implementation, and having a working .c file is obviously necessary for that. So I appreciate having it as part of the RFC.
Ack.
Quoted 24 lines
Quoted 4 lines
Comments inline.
Quoted 1 line
---
<snip>
Quoted 19 lines
Quoted 18 lines
+ *
+ * The DMA framework is built on the following abstraction model:
+ *+ * ------------ ------------ + * |virt-queue| |virt-queue| + * ------------ ------------ + * \ / + * \ / + * \ / + * ------------ ------------ + * | HW-queue | | HW-queue | + * ------------ ------------ + * \ / + * \ / + * \ / + * ---------- + * | dmadev | + * ----------
Quoted 6 lines
Quoted 3 lines
Continuing the discussion with @Morten Brørup , I think, we need to finalize the model.
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.
Quoted 110 lines
Quoted 75 lines
Quoted 14 lines
+ * a) The DMA operation request must be submitted to the virt queue, virt
+ * queues must be created based on HW queues, the DMA device could have
+ * multiple HW queues.
+ * b) The virt queues on the same HW-queue could represent different contexts,+ * e.g. user could create virt-queue-0 on HW-queue-0 for mem-to-mem + * transfer scenario, and create virt-queue-1 on the same HW-queue for + * mem-to-dev transfer scenario.+ * NOTE: user could also create multiple virt queues for mem-to-mem transfer
+ * scenario as long as the corresponding driver supports.
+ *
+ * The control plane APIs include configure/queue_setup/queue_release/start/
+ * stop/reset/close, in order to start device work, the call sequence must be
+ * as follows:Quoted 3 lines
+ * - rte_dmadev_configure() + * - rte_dmadev_queue_setup() + * - rte_dmadev_start()Please add reconfigure behaviour etc, Please check the
lib/regexdev/rte_regexdev.h
introduction. I have added similar ones so you could reuse as much as possible.Quoted 24 lines
+ * The dataplane APIs include two parts:
+ * a) The first part is the submission of operation requests:+ * - rte_dmadev_copy() + * - rte_dmadev_copy_sg() - scatter-gather form of copy + * - rte_dmadev_fill() + * - rte_dmadev_fill_sg() - scatter-gather form of fill + * - rte_dmadev_fence() - add a fence force ordering between operations + * - rte_dmadev_perform() - issue doorbell to hardware + * These APIs could work with different virt queues which have different + * contexts. + * The first four APIs are used to submit the operation request to the virt + * queue, if the submission is successful, a cookie (as type + * 'dma_cookie_t') is returned, otherwise a negative number is returned.+ * b) The second part is to obtain the result of requests:
+ * -rte_dmadev_completed()
+ * - return the number of operation requests completed successfully.
+ * -rte_dmadev_completed_fails()
+ * - return the number of operation requests failed to complete.
+ *
+ * The misc APIs include info_get/queue_info_get/stats/xstats/selftest, provide
+ * information query and self-test capabilities.
+ *
+ * About the dataplane APIs MT-safe, there are two dimensions:
+ * a) For one virt queue, the submit/completion API could be MT-safe,Quoted 10 lines
+ * e.g. one thread do submit operation, another thread do completion + * operation. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe. + * b) For multiple virt queues on the same HW queue, e.g. one thread do + * operation on virt-queue-0, another thread do operation on virt-queue-1. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MVQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe.From an application PoV it may not be good to write portable applications. Please check
latest thread with @Morten Brøruplib/dmadev/rte_dmadev.h line 107
Quoted 10 lines
+ */
lib/dmadev/rte_dmadev.h new file +9
-0+ +#ifdef __cplusplus +extern "C" { +#endif + +#include <rte_common.h> +#include <rte_memory.h> +#include <rte_errno.h> +#include <rte_compat.h> Sort in alphabetical order.
Quoted 7 lines
lib/dmadev/rte_dmadev.h line 110
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+ +/** +* dma_cookie_t - an opaque DMA cookie Since we are defining the behaviour is not opaque any more. I think, it is better to call
ring_idxor so.+1 for ring index. We don't need a separate type for it though, just document the index as an unsigned return value.
Quoted 7 lines
Quoted 2 lines
+#define
RTE_DMA_DEV_CAPA_MT_MVQ(1ull << 11) /**< Support MT-safe of multiple virt queues */Please lot of @see for all symbols where it is being used. So that one can understand the full scope of
symbols. See below example.Quoted 16 lines
#define
RTE_REGEXDEV_CAPA_RUNTIME_COMPILATION_F(1ULL << 0) /**< RegEx device does support compiling the rules at runtime unlike
* loading only the pre-built rule database using
* structrte_regexdev_config::rule_dbinrte_regexdev_configure()*
* @see structrte_regexdev_config::rule_db,rte_regexdev_configure()
* @see structrte_regexdev_info::regexdev_capa
*/Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.
Quoted 7 lines
I disagree with the
INT_MAX(orINT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for theINT_MAXvalue. Better to:
1. Specify that it wraps atUINT16_MAXwhich allows us to just use auint16_tinternally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >=UINT16_MAX, giving drivers the flexibility at what value to wrap around.
I think, (2) better than 1. I think, even better to wrap around the number of descriptors configured in dev_configure()(We cake make this as the power of 2),
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
+ * c) The initial cookie of a virt queue is zero, after the device is stopped or
+ * reset, the virt queue's cookie needs to be reset to zero.
+ * Example:+ * step-1: start one dmadev + * step-2: enqueue a copy operation, the cookie return is 0 + * step-3: enqueue a copy operation again, the cookie return is 1 + * ... + * step-101: stop the dmadev + * step-102: start the dmadev + * step-103: enqueue a copy operation, the cookie return is 0 + * ...+ */
Quoted 7 lines
Quoted 4 lines
Good explanation.
Quoted 1 line
+typedef
int32_tdma_cookie_t;As I mentioned before, I'd just remove this, and use regular int types, with "
ring_idx" as the name.
+1
Quoted 94 lines
Quoted 78 lines
lib/dmadev/rte_dmadev.h line 135
Quoted 7 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* dma_scatterlist - can hold scatter DMA operation request +*/ +struct dma_scatterlist {I prefer to change scatterlist -> sg
i.erte_dma_sgQuoted 4 lines
lib/dmadev/rte_dmadev.h new file +4
-0+void *src; +void *dst; +uint32_t length; +};lib/dmadev/rte_dmadev.h line 212
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +9
-0+ + +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok typo.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** lib/dmadev/rte_dmadev.h line 228
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */ Please add
max_nb_segs. i.e maximum number of segments supported.Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + i + +/** +* dma_address_type +*/ lib/dmadev/rte_dmadev.h line 270
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ I think, there are 3 kinds of limitations/capabilities.
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.Quoted 8 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.I don't think we need this level of detail for addressing capabilities. Unless I'm missing something, the hardware should behave exactly as other hardware does taking in iova's. If the user wants to check whether virtual addresses to pinned memory can be used directly, the user can call "
rte_eal_iova_mode". We can't have a situation where some hardware uses one type of addresses and another hardware the other.
Quoted 3 lines
Therefore, the only additional addressing capability we should need to report is that the hardware can use SVM/SVA and use virtual addresses not in hugepage memory.
+1.
Quoted 59 lines
Quoted 36 lines
lib/dmadev/rte_dmadev.h line 272
Quoted 4 lines
lib/dmadev/rte_dmadev.h new file +2
-0+uint16_t nb_hw_queues;/**< Number of HW-queues enable to use */ +uint16_t max_vqs;/**< Maximum number of virt queues to use */ You need to what is max value allowed etc i.e it is based on
info_get()and mention the field
in info structurelib/dmadev/rte_dmadev.h line 384
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* dma_transfer_direction +*/ +enum dma_transfer_direction {
rte_dma_transter_directionQuoted 7 lines
lib/dmadev/rte_dmadev.h new file +7
-0+DMA_MEM_TO_MEM , +DMA_MEM_TO_DEV , +DMA_DEV_TO_MEM , + DMA_DEV_TO_DEV, +}; + +/** lib/dmadev/rte_dmadev.h line 399
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +8
-0+* A structure used to configure a DMA virt queue. +*/ +struct rte_dmadev_queue_conf { +enum dma_transfer_direction direction; +/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ Quoted 9 lines
Use of this? Need more comments on this.
Since it is in slowpath, We can have non opaque names here based on each driver capability.Quoted 1 line
+ void
*dev_ctx; /**< Device specific context */Use of this ? Need more comment ont this.
I think this should be dropped. We should not have any opaque device-specific info in these structs, rather if a particular device needs parameters we should call them out. Drivers for which it's not relevant can ignore them (and report same in capability if necessary). Since this is not a dataplane API, we aren't concerned too much about perf and can size the struct appropriately.
Quoted 5 lines
Please add some good amount of reserved bits and have API to init this structure for future ABI stability, say
rte_dmadev_queue_config_init()or so.
Quoted 4 lines
I don't think that is necessary. Since the config struct is used only as parameter to the config function, any changes to it can be managed by versioning that single function. Padding would only be necessary if we had an array of these config structs somewhere.
OK.
For some reason, the versioning API looks ugly to me in code instead of keeping some rsvd fields look cool to me with init function.
But I agree. function versioning works in this case. No need to find other API if tt is not general DPDK API practice.
In other libraries, I have seen such _init or function that can use for this as well as filling default value
in some cases implementation values is not zero).
So that application can avoid memset for param structure. Added rte_event_queue_default_conf_get() in eventdev spec for this.
No strong opinion on this.
Quoted 66 lines
Quoted 56 lines
lib/dmadev/rte_dmadev.h line 447
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction;A queue may support all directions so I think it should be a bitfield.
lib/dmadev/rte_dmadev.h line 545
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +11
-0+/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)I would like to change this as:
rte_dmadev_copy_sg(uint16_tdev_id,uint16_tvq_id, const structrte_dma_sg*src,uint32_tnb_src,
const structrte_dma_sg*dst,uint32_tnb_dst) or so allow the use case like src 30 MB copy can be splitted as written as 1 MB x 30 dst.Quoted 24 lines
lib/dmadev/rte_dmadev.h new file +24
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy_sg)(dev, vq_id, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the DMA virt queue +* +* This queues up a fill operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the destination buffer. Quoted 9 lines
Quoted 2 lines
+ * @param flags
+ * An opaque flags for this operation.PLEASE REMOVE opaque stuff from fastpath it will be a pain for application writers as
they need to write multiple combinations of fastpath. flags are OK, if we have a valid
generic flag now to control the transfer behavior.
Quoted 3 lines
+1. Flags need to be explicitly listed. If we don't have any flags for now, we can specify that the value must be given as zero and it's for future use.
OK.
Quoted 41 lines
Quoted 31 lines
Quoted 31 lines
lib/dmadev/rte_dmadev.h new file +29
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add a fence to force ordering between operations +* +* This adds a fence to a sequence of operations to enforce ordering, such that +* all operations enqueued before the fence must be completed before operations +* after the fence. +* NOTE: Since this fence may be added as a flag to the last operation enqueued, +* this API may not function correctly when called immediately after an +* "rte_dmadev_perform" call i.e. before any new operations are enqueued. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful add fence. +* - <0: Failure to add fence. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{Quoted 9 lines
lib/dmadev/rte_dmadev.h line 657
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +}Since HW submission is in a queue(FIFO) the ordering is always maintained. Right?
Could you share more details and use case offence()from driver/application PoV?
Quoted 6 lines
There are different kinds of ordering to consider, ordering of completions and the ordering of operations. While jobs are reported as completed to the user in order, for performance hardware, may overlap individual jobs within a burst (or even across bursts). Therefore, we need a fence operation to inform hardware that one job should not be started until the other has fully completed.
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
lib/dmadev/rte_dmadev.h new file +26
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{Quoted 9 lines
lib/dmadev/rte_dmadev.h line 686
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +}Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
Quoted 5 lines
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
Quoted 41 lines
Quoted 25 lines
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successful completed. +* +* @param dev_id +* The identifier of the device. +* @param vq_id lib/dmadev/rte_dmadev.h line 706
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* The identifier of virt queue. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] cookie +* The last completed operation's cookie. +* @param[out] has_error +* Indicates if there are transfer error. +* +* @return +* The number of operations that successful completed. successfully
Quoted 15 lines
lib/dmadev/rte_dmadev.h line 718
Quoted 12 lines
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +8
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_cpls, +dma_cookie_t *cookie,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + has_error = false; +return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error);It may be better to have cookie/ring_idx as third argument.
Quoted 2 lines
No strong opinions here, but having it as in the code above means all input parameters come before all output, which makes sense to me.
+1
Quoted 63 lines
Quoted 45 lines
Quoted 4 lines
lib/dmadev/rte_dmadev.h new file +3
-0+} + +/** lib/dmadev/rte_dmadev.h line 731
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. (> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_errorQuoted 7 lines
See
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
If the former is scope, then we need to define the standard enum value for the error right?
ie. uint32_t *status needs to change to enum rte_dma_error or so.
Quoted 111 lines
Quoted 11 lines
Quoted 11 lines
lib/dmadev/rte_dmadev.h new file +10
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
I also would remove the enqueue fail counts, since they are better counted by the app. If a driver reports 20,000 failures we have no way of knowing if that is 20,000 unique operations which failed to enqueue or a single operation which failed to enqueue 20,000 times but succeeded on attempt 20,001.
Quoted 48 lines
Quoted 19 lines
lib/dmadev/rte_dmadev_core.h new file +12
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* lib/dmadev/rte_dmadev_core.h line 22
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ + +struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */ To avoid namespace conflict(as it is public API) use
rte_Quoted 15 lines
lib/dmadev/rte_dmadev_core.h new file +15
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence;Quoted 9 lines
lib/dmadev/rte_dmadev_core.h line 78
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails;We need to limit fastpath items in 1 CL
I don't think that is going to be possible. I also would like to see numbers to check if we benefit much from having these fastpath ops separate from the regular ops.
Quoted 22 lines
Quoted 4 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+ +void *dev_private;/**< PMD-specific private data */ +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD */ +lib/dmadev/rte_dmadev_core.h line 92
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+uint16_t dev_id;/**< Device ID for this instance */ +int socket_id;/**< Socket ID where memory is allocated */ +struct rte_device *device; +/**< Device info. supplied during device initialization */ +const char *driver_name;/**< Driver info. supplied by probing */ +char name[RTE_DMADEV_NAME_MAX_LEN ];/**< Device name */ + +RTE_STD_C11 + uint8_t attached : 1; /**< Flag indicating the device is attached */ + uint8_t started : 1; /**< Device state: STARTED(1)/STOPPED(0) */Add a couple of reserved fields for future ABI stability.
Quoted 5 lines
lib/dmadev/rte_dmadev_core.h new file +5
-0+ +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; +
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.
Fine for me.
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than dev_id + channel_id pair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?
Quoted 1 line
<snip>
Quoted 16 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.Quoted 7 lines
I disagree with the
INT_MAX(orINT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for theINT_MAXvalue. Better to:
1. Specify that it wraps atUINT16_MAXwhich allows us to just use auint16_tinternally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >=UINT16_MAX, giving drivers the flexibility at what value to wrap around.
Quoted 3 lines
I think, (2) better than 1. I think, even better to wrap around the number of descriptors configured in dev_configure()(We cake make this as the power of 2),
Interesting, I hadn't really considered that before. My only concern would be if an app wants to keep values in the app ring for a while after they have been returned from dmadev. I thought it easier to have the full 16-bit counter value returned to the user to give the most flexibility, given that going from that to any power-of-2 ring size smaller is a trivial operation.
Overall, while my ideal situation is to always have a 0..UINT16_MAX return value from the function, I can live with your suggestion of wrapping at ring_size, since drivers will likely do that internally anyway. I think wrapping at INT32_MAX is too awkward and will be error prone since we can't rely on hardware automatically wrapping to zero, nor on the driver having pre-masked the value.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+ * c) The initial cookie of a virt queue is zero, after the device is stopped or
+ * reset, the virt queue's cookie needs to be reset to zero.
<snip>
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Please add some good amount of reserved bits and have API to init this structure for future ABI stability, say
rte_dmadev_queue_config_init()or so.I don't think that is necessary. Since the config struct is used only as parameter to the config function, any changes to it can be managed by versioning that single function. Padding would only be necessary if we had an array of these config structs somewhere.
Quoted 8 lines
OK.
For some reason, the versioning API looks ugly to me in code instead of keeping some rsvd fields look cool to me with init function.
But I agree. function versioning works in this case. No need to find other API if tt is not general DPDK API practice.
The one thing I would suggest instead of the padding is for the internal APIS, to pass the struct size through, since we can't version those - and for padding we can't know whether any replaced padding should be used or not. Specifically:
typedef int (*rte_dmadev_configure_t)(struct rte_dmadev *dev, struct rte_dmadev_conf *cfg, size_t cfg_size);
but for the public function:
int
rte_dmadev_configure(struct rte_dmadev *dev, struct
rte_dmadev_conf *cfg)
{
...
ret = dev->ops.configure(dev, cfg, sizeof(*cfg));
...
}Then if we change the structure and version the config API, the driver can tell from the size what struct version it is and act accordingly. Without that, each time the struct changed, we'd have to add a new function pointer to the device ops.
Quoted 6 lines
In other libraries, I have seen such
_initor function that can use for this as well as filling default value
in some cases implementation values is not zero).
So that application can avoid memset for param structure. Addedrte_event_queue_default_conf_get()in eventdev spec for this.
I think that would largely have the same issues, unless it returned a pointer to data inside the driver - and which therefore could not be modified. Alternatively it would mean that the memory would have been allocated in the driver and we would need to ensure proper cleanup functions were called to free memory afterwards. Supporting having the config parameter as a local variable I think makes things a lot easier.
Quoted 34 lines
No strong opinion on this.
Quoted 30 lines
Quoted 30 lines
lib/dmadev/rte_dmadev.h line 447
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction;A queue may support all directions so I think it should be a bitfield.
lib/dmadev/rte_dmadev.h line 545
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +11
-0+/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)I would like to change this as:
rte_dmadev_copy_sg(uint16_tdev_id,uint16_tvq_id, const structrte_dma_sg*src,uint32_tnb_src,
const structrte_dma_sg*dst,uint32_tnb_dst) or so allow the use case like src 30 MB copy can be splitted as written as 1 MB x 30 dst.
Out of interest, do you see much benefit (and in what way) from having the scatter-gather support? Unlike sending 5 buffers in one packet rather than 5 buffers in 5 packets to a NIC, copying an array of memory in one op vs multiple is functionally identical.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
<snip>
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?
The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
<snip>
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
Quoted 9 lines
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<snip>
Quoted 69 lines
Quoted 61 lines
Quoted 43 lines
lib/dmadev/rte_dmadev.h line 731
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. (> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_errorQuoted 7 lines
See
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 2 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right?
ie.uint32_t*status needs to change to enumrte_dma_erroror so.
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Quoted 2 lines
<snip to end>
/Bruce
Quoted 21 lines · Bruce Richardson
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.
Quoted 6 lines
Fine for me.
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than
dev_id+channel_idpair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?
Yes. That will work. To confirm, the suggestion is to use, void * object instead of channel_id,
That will avoid one more indirection.(index -> pointer)
Quoted 30 lines
Quoted 2 lines
<snip>
Quoted 16 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.Quoted 7 lines
I disagree with the
INT_MAX(orINT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for theINT_MAXvalue. Better to:
1. Specify that it wraps atUINT16_MAXwhich allows us to just use auint16_tinternally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >=UINT16_MAX, giving drivers the flexibility at what value to wrap around.Quoted 3 lines
I think, (2) better than 1. I think, even better to wrap around the number of descriptors configured in dev_configure()(We cake make this as the power of 2),
Interesting, I hadn't really considered that before. My only concern would be if an app wants to keep values in the app ring for a while after they have been returned from dmadev. I thought it easier to have the full 16-bit counter value returned to the user to give the most flexibility, given that going from that to any power-of-2 ring size smaller is a trivial operation.
Quoted 6 lines
Overall, while my ideal situation is to always have a 0..UINT16_MAX return value from the function, I can live with your suggestion of wrapping at
ring_size, since drivers will likely do that internally anyway. I think wrapping atINT32_MAXis too awkward and will be error prone since we can't rely on hardware automatically wrapping to zero, nor on the driver having pre-masked the value.
OK. +1 for UINT16_MAX
Quoted 35 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+ * c) The initial cookie of a virt queue is zero, after the device is stopped or
+ * reset, the virt queue's cookie needs to be reset to zero.<snip>
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Please add some good amount of reserved bits and have API to init this structure for future ABI stability, say
rte_dmadev_queue_config_init()or so.I don't think that is necessary. Since the config struct is used only as parameter to the config function, any changes to it can be managed by versioning that single function. Padding would only be necessary if we had an array of these config structs somewhere.
Quoted 8 lines
OK.
For some reason, the versioning API looks ugly to me in code instead of keeping some rsvd fields look cool to me with init function.
But I agree. function versioning works in this case. No need to find other API if tt is not general DPDK API practice.
The one thing I would suggest instead of the padding is for the internal APIS, to pass the struct size through, since we can't version those - and for padding we can't know whether any replaced padding should be used or not. Specifically:
typedef int (*rte_dmadev_configure_t)(struct
rte_dmadev*dev, struct
rte_dmadev_conf*cfg,size_tcfg_size);but for the public function:
Quoted 8 lines
int
rte_dmadev_configure(struct rte_dmadev *dev, struct
rte_dmadev_conf *cfg)
{
...
ret = dev->ops.configure(dev, cfg, sizeof(*cfg));
...
}Makes sense.
Quoted 13 lines
Then if we change the structure and version the config API, the driver can tell from the size what struct version it is and act accordingly. Without that, each time the struct changed, we'd have to add a new function pointer to the device ops.
Quoted 6 lines
In other libraries, I have seen such
_initor function that can use for this as well as filling default value
in some cases implementation values is not zero).
So that application can avoid memset for param structure. Addedrte_event_queue_default_conf_get()in eventdev spec for this.
Quoted 39 lines
I think that would largely have the same issues, unless it returned a pointer to data inside the driver - and which therefore could not be modified. Alternatively it would mean that the memory would have been allocated in the driver and we would need to ensure proper cleanup functions were called to free memory afterwards. Supporting having the config parameter as a local variable I think makes things a lot easier.
Quoted 32 lines
No strong opinion on this.
Quoted 28 lines
Quoted 28 lines
lib/dmadev/rte_dmadev.h line 447
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction;A queue may support all directions so I think it should be a bitfield.
lib/dmadev/rte_dmadev.h line 545
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +11
-0+/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)I would like to change this as:
rte_dmadev_copy_sg(uint16_tdev_id,uint16_tvq_id, const structrte_dma_sg*src,uint32_tnb_src,
const structrte_dma_sg*dst,uint32_tnb_dst) or so allow the use case like
In the above syntax, @Chengchang Tangrte_dma_sg needs to contains only ptr and size.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
src 30 MB copy can be splitted as written as 1 MB x 30 dst.
Out of interest, do you see much benefit (and in what way) from having the scatter-gather support? Unlike sending 5 buffers in one packet rather than 5 buffers in 5 packets to a NIC, copying an array of memory in one op vs multiple is functionally identical.
Knowing upfront or in shot if such segments expressed can have better optimization
in drivers like
1) In one DMA job request HW can fill multiple segments vs multiple DMA job requests with each segment.
2) Single completion i.e less overhead system.
3) Less latency for the job requests.
Quoted 21 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<snip>
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
Quoted 8 lines
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Ack.
You may consider two flags, FENCE_THEN_JOB and JOB_THEN_FENCE( If there any use case for this or it makes sense for your HW)
For us, Fence is NOP for us as we have an implicit fence between each HW job descriptor.
Quoted 22 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<snip>
Quoted 18 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Quoted 7 lines
Quoted 3 lines
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait
I don't know, At least in our case, writes are write-back. so core does not need to wait.(If there is no read operation).
Quoted 9 lines
for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Linux kernel has xmit_more flag in skb to address similar thing. i.e enq job flag can have one more bit field to say update ring bell or not? Rather having yet another function overhead.IMO, it is the best of both worlds.
Quoted 88 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
<snip>
Quoted 69 lines
Quoted 61 lines
Quoted 43 lines
lib/dmadev/rte_dmadev.h line 731
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. (> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_errorQuoted 7 lines
See
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 2 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 6 lines
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right?
ie.uint32_t*status needs to change to enumrte_dma_erroror so.Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum rte_dma_error_type
2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).
Quoted 6 lines
Quoted 3 lines
<snip to end>
/Bruce
Quoted 25 lines · Jerin Jacob
Quoted 23 lines · Bruce Richardson
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.Fine for me.
Quoted 9 lines
Quoted 4 lines
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than
dev_id+channel_idpair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?Yes. That will work. To confirm, the suggestion is to use, void * object instead of
channel_id,
That will avoid one more indirection.(index -> pointer)
The proposal was to use it in place of "dev_id + channel_id", i.e.
copy(dev_id, ch_id, src, dst, len, flags) --> copy(ch_ptr, src, dst, len, flags)
Where the channel pointer implicitly indicates the device too. However, I realise now that this would be something completely transparent to the driver as it would all have to be implemented in the dmadev level, and lead to lots of duplication of function pointers, etc. Therefore, let's just go with original scheme. :-(
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
Quoted 8 lines
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Quoted 8 lines
Ack.
You may consider two flags,FENCE_THEN_JOBandJOB_THEN_FENCE( If there any use case for this or it makes sense for your HW)For us, Fence is NOP for us as we have an implicit fence between each HW job descriptor.
I actually still think that having a separate fence function in the "ops" section is the best approach here. It's unabiguous as to whether it's fence-before or fence-after, and if we have it in the ops, it doesn't use a "fast-path" slot.
However, if we *really* want to use a flag instead, I don't see the value in having two flags, it will be really confusing. Instead, if we do go with a flag, I think "RTE_DMA_PRE_FENCE" should be the name, indicating that the fence occurs before the job in question.
Quoted 44 lines
Quoted 23 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
<snip>
Quoted 18 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Quoted 7 lines
Quoted 3 lines
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait
I don't know, At least in our case, writes are write-back. so core does not need to wait.(If there is no read operation).
Quoted 9 lines
for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Quoted 4 lines
Linux kernel has
xmit_moreflag in skb to address similar thing. i.e enq job flag can have one more bit field to say update ring bell or not? Rather having yet another function overhead.IMO, it is the best of both worlds.
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
Quoted 81 lines
Quoted 81 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Quoted 55 lines
Quoted 47 lines
Quoted 26 lines
Quoted 6 lines
+ +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Returns the number of operations that failed to complete. + * NOTE: This API was used when
rte_dmadev_completedhas_errorwas set. + * + * @paramdev_id
+ * The identifier of the device. + * @paramvq_id+ * The
identifier of virt queue.(> + * @param
nb_statusQuoted 11 lines
+ * Indicates the size of status array. + * @param[out]
status + * The error code of operations that failed to
complete. + * @param[out] cookie + * The last failed
completed operation's cookie. + * + * @return + * The number
of operations that failed to complete. + * + * NOTE: The caller must ensure that the input parameter is valid and the +
* corresponding device supports the operation. + */(quoted diff) +2
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, +const
uint16_tnb_status,uint32_t*status, +dma_cookie_t*cookie)IMO, it is better to move cookie/rind_idx at 3. Why it would return any array of errors? since it called after
rte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)Quoted 9 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes of all the driver and return string from driver existing
rte_flow_errorSee struct
rte_flow_error{ enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */ };I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 3 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right? ie.
uint32_t*status needs to change to enumrte_dma_erroror so.
Quoted 9 lines
Quoted 2 lines
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum
rte_dma_error_type2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).
The only issue I have with that is that once we have driver specific information it is of little use to the application, since it can't know anything about it excepy maybe log it. I'd much rather have a set of error codes telling user that "source address is wrong", "dest address is wrong", and a generic "an address is wrong" in case driver/HW cannot distinguish source of error. Can we see how far we get with just error codes before we start into passing string messages around and all the memory management headaches that implies.
/Bruce
Quoted 39 lines · Bruce Richardson
Quoted 25 lines · Jerin Jacob
Quoted 23 lines · Bruce Richardson
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.Fine for me.
Quoted 9 lines
Quoted 4 lines
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than
dev_id+channel_idpair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?Yes. That will work. To confirm, the suggestion is to use, void * object instead of
channel_id,
That will avoid one more indirection.(index -> pointer)The proposal was to use it in place of "
dev_id+channel_id", i.e.
Quoted 7 lines
copy(dev_id, ch_id, src, dst, len, flags)-->copy(ch_ptr, src, dst, len, flags)Where the channel pointer implicitly indicates the device too. However, I realise now that this would be something completely transparent to the driver as it would all have to be implemented in the dmadev level, and lead to lots of duplication of function pointers, etc. Therefore, let's just go with original scheme. :-(
Yes. Just go with the original scheme.
Quoted 47 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
Quoted 8 lines
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Quoted 8 lines
Ack.
You may consider two flags,FENCE_THEN_JOBandJOB_THEN_FENCE( If there any use case for this or it makes sense for your HW)For us, Fence is NOP for us as we have an implicit fence between each HW job descriptor.
I actually still think that having a separate fence function in the "ops" section is the best approach here. It's unabiguous as to whether it's fence-before or fence-after, and if we have it in the ops, it doesn't use a "fast-path" slot.
Quoted 4 lines
However, if we *really* want to use a flag instead, I don't see the value in having two flags, it will be really confusing. Instead, if we do go with a flag, I think "
RTE_DMA_PRE_FENCE" should be the name, indicating that the fence occurs before the job in question.
IMO, We need to use flags and the name can be RTE_DMA_PRE_FENCE due to overhead of the driver implementation where the fence request can be NOP and
to save the first cache line occupancy.
Quoted 50 lines
Quoted 45 lines
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Quoted 18 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Quoted 7 lines
Quoted 3 lines
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait
I don't know, At least in our case, writes are write-back. so core does not need to wait.(If there is no read operation).
Quoted 9 lines
for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Quoted 4 lines
Linux kernel has
xmit_moreflag in skb to address similar thing. i.e enq job flag can have one more bit field to say update ring bell or not? Rather having yet another function overhead.IMO, it is the best of both worlds.
Quoted 6 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy() and rte_dma_perform()
b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
that rte_dma_copy() flag can be updated to fire the doorbell.
IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.
IMO, a single branch is most optimal from performance PoV.
Quoted 91 lines
Quoted 82 lines
Quoted 82 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
<snip>
Quoted 55 lines
Quoted 47 lines
Quoted 26 lines
Quoted 6 lines
+ +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Returns the number of operations that failed to complete. + * NOTE: This API was used when
rte_dmadev_completedhas_errorwas set. + * + * @paramdev_id
+ * The identifier of the device. + * @paramvq_id+ * The
identifier of virt queue.(> + * @param
nb_statusQuoted 11 lines
+ * Indicates the size of status array. + * @param[out]
status + * The error code of operations that failed to
complete. + * @param[out] cookie + * The last failed
completed operation's cookie. + * + * @return + * The number
of operations that failed to complete. + * + * NOTE: The caller must ensure that the input parameter is valid and the +
* corresponding device supports the operation. + */(quoted diff) +2
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, +const
uint16_tnb_status,uint32_t*status, +dma_cookie_t*cookie)IMO, it is better to move cookie/rind_idx at 3. Why it would return any array of errors? since it called after
rte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)Quoted 9 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes of all the driver and return string from driver existing
rte_flow_errorSee struct
rte_flow_error{ enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */ };I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 3 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right? ie.
uint32_t*status needs to change to enumrte_dma_erroror so.Quoted 9 lines
Quoted 2 lines
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum
rte_dma_error_type2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).
Quoted 8 lines
The only issue I have with that is that once we have driver specific information it is of little use to the application, since it can't know anything about it excepy maybe log it. I'd much rather have a set of error codes telling user that "source address is wrong", "dest address is wrong", and a generic "an address is wrong" in case driver/HW cannot distinguish source of error. Can we see how far we get with just error codes before we start into passing string messages around and all the memory management headaches that implies.
Works for me. It should be "enum rte_dma_error_type" then, which has a standard error type. Which is missing in the spec now.
Quoted 2 lines
/Bruce
Quoted 43 lines · Jerin Jacob
Quoted 41 lines · Bruce Richardson
Quoted 25 lines · Jerin Jacob
Quoted 23 lines · Bruce Richardson
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.Fine for me.
Quoted 9 lines
Quoted 4 lines
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than
dev_id+channel_idpair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?Yes. That will work. To confirm, the suggestion is to use, void * object instead of
channel_id,
That will avoid one more indirection.(index -> pointer)The proposal was to use it in place of "
dev_id+channel_id", i.e.
copy(dev_id, ch_id, src, dst, len, flags)-->copy(ch_ptr, src, dst, len, flags)
Quoted 8 lines
Quoted 5 lines
Where the channel pointer implicitly indicates the device too. However, I realise now that this would be something completely transparent to the driver as it would all have to be implemented in the dmadev level, and lead to lots of duplication of function pointers, etc. Therefore, let's just go with original scheme. :-(
Yes. Just go with the original scheme.
+1
Quoted 130 lines
Quoted 47 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
Quoted 8 lines
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Quoted 8 lines
Ack.
You may consider two flags,FENCE_THEN_JOBandJOB_THEN_FENCE( If there any use case for this or it makes sense for your HW)For us, Fence is NOP for us as we have an implicit fence between each HW job descriptor.
I actually still think that having a separate fence function in the "ops" section is the best approach here. It's unabiguous as to whether it's fence-before or fence-after, and if we have it in the ops, it doesn't use a "fast-path" slot.
Quoted 4 lines
However, if we *really* want to use a flag instead, I don't see the value in having two flags, it will be really confusing. Instead, if we do go with a flag, I think "
RTE_DMA_PRE_FENCE" should be the name, indicating that the fence occurs before the job in question.IMO, We need to use flags and the name can be
RTE_DMA_PRE_FENCEdue to overhead of the driver implementation where the fence request can be NOP and
to save the first cache line occupancy.Quoted 50 lines
Quoted 45 lines
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Quoted 18 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Quoted 7 lines
Quoted 3 lines
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait
I don't know, At least in our case, writes are write-back. so core does not need to wait.(If there is no read operation).
Quoted 9 lines
for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Quoted 4 lines
Linux kernel has
xmit_moreflag in skb to address similar thing. i.e enq job flag can have one more bit field to say update ring bell or not? Rather having yet another function overhead.IMO, it is the best of both worlds.Quoted 6 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has
data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy()andrte_dma_perform()b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
thatrte_dma_copy()flag can be updated to fire the doorbell.
Quoted 7 lines
IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.IMO, a single branch is most optimal from performance PoV.
Ok, let's try it and see how it goes.
Quoted 101 lines
Quoted 92 lines
Quoted 83 lines
Quoted 83 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
<snip>
Quoted 55 lines
Quoted 47 lines
Quoted 26 lines
Quoted 6 lines
+ +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Returns the number of operations that failed to complete. + * NOTE: This API was used when
rte_dmadev_completedhas_errorwas set. + * + * @paramdev_id
+ * The identifier of the device. + * @paramvq_id+ * The
identifier of virt queue.(> + * @param
nb_statusQuoted 11 lines
+ * Indicates the size of status array. + * @param[out]
status + * The error code of operations that failed to
complete. + * @param[out] cookie + * The last failed
completed operation's cookie. + * + * @return + * The number
of operations that failed to complete. + * + * NOTE: The caller must ensure that the input parameter is valid and the +
* corresponding device supports the operation. + */(quoted diff) +2
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, +const
uint16_tnb_status,uint32_t*status, +dma_cookie_t*cookie)IMO, it is better to move cookie/rind_idx at 3. Why it would return any array of errors? since it called after
rte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)Quoted 9 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes of all the driver and return string from driver existing
rte_flow_errorSee struct
rte_flow_error{ enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */ };I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 3 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right? ie.
uint32_t*status needs to change to enumrte_dma_erroror so.Quoted 9 lines
Quoted 2 lines
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum
rte_dma_error_type2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).Quoted 8 lines
The only issue I have with that is that once we have driver specific information it is of little use to the application, since it can't know anything about it excepy maybe log it. I'd much rather have a set of error codes telling user that "source address is wrong", "dest address is wrong", and a generic "an address is wrong" in case driver/HW cannot distinguish source of error. Can we see how far we get with just error codes before we start into passing string messages around and all the memory management headaches that implies.
Quoted 3 lines
Works for me. It should be "enum
rte_dma_error_type" then, which has a standard error type. Which is missing in the spec now.
+1
Quoted 184 lines · Bruce Richardson
Quoted 43 lines · Jerin Jacob
Quoted 41 lines · Bruce Richardson
Quoted 25 lines · Jerin Jacob
Quoted 23 lines · Bruce Richardson
Quoted 9 lines · Jerin Jacob
Quoted 6 lines · Bruce Richardson
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 8 lines
Quoted 3 lines
+1 and the terminology with regards to queues and channels. With our ioat hardware, each HW queue was called a channel for instance.
Looks like <dmadev> <> <channel> can cover all the use cases, if the HW has more than
1 queues it can be exposed as separate dmadev dev.Fine for me.
Quoted 9 lines
Quoted 4 lines
However, just to confirm that Morten's suggestion of using a (device-specific void *) channel pointer rather than
dev_id+channel_idpair of parameters won't work for you? You can't store a pointer or dev index in the channel struct in the driver?Yes. That will work. To confirm, the suggestion is to use, void * object instead of
channel_id,
That will avoid one more indirection.(index -> pointer)The proposal was to use it in place of "
dev_id+channel_id", i.e.
copy(dev_id, ch_id, src, dst, len, flags)-->copy(ch_ptr, src, dst, len, flags)Quoted 8 lines
Quoted 5 lines
Where the channel pointer implicitly indicates the device too. However, I realise now that this would be something completely transparent to the driver as it would all have to be implemented in the dmadev level, and lead to lots of duplication of function pointers, etc. Therefore, let's just go with original scheme. :-(
Yes. Just go with the original scheme.
+1
Quoted 130 lines
Quoted 47 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
<snip>
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
Got it. In order to save space if first CL size for fastpath(Saving 8B for the pointer) and to avoid
function overhead, Can we use one bit of flags of op function to enable the fence?The original ioat implementation did exactly that. However, I then discovered that because a fence logically belongs between two operations, does the fence flag on an operation mean "don't do any jobs after this until this job has completed" or does it mean "don't start this job until all previous jobs have completed". [Or theoretically does it mean both :-)] Naturally, some hardware does it the former way (i.e. fence flag goes on last op before fence), while other hardware the latter way (i.e. fence flag goes on first op after the fence). Therefore, since fencing is about ordering *between* two (sets of) jobs, I decided that it should do exactly that and go between two jobs, so there is no ambiguity!
Quoted 8 lines
However, I'm happy enough to switch to having a fence flag, but I think if we do that, it should be put in the "first job after fence" case, because it is always easier to modify a previously written job if we need to, than to save the flag for a future one.
Alternatively, if we keep the fence as a separate function, I'm happy enough for it not to be on the same cacheline as the "hot" operations, since fencing will always introduce a small penalty anyway.
Quoted 8 lines
Ack.
You may consider two flags,FENCE_THEN_JOBandJOB_THEN_FENCE( If there any use case for this or it makes sense for your HW)For us, Fence is NOP for us as we have an implicit fence between each HW job descriptor.
I actually still think that having a separate fence function in the "ops" section is the best approach here. It's unabiguous as to whether it's fence-before or fence-after, and if we have it in the ops, it doesn't use a "fast-path" slot.
Quoted 4 lines
However, if we *really* want to use a flag instead, I don't see the value in having two flags, it will be really confusing. Instead, if we do go with a flag, I think "
RTE_DMA_PRE_FENCE" should be the name, indicating that the fence occurs before the job in question.IMO, We need to use flags and the name can be
RTE_DMA_PRE_FENCEdue to overhead of the driver implementation where the fence request can be NOP and
to save the first cache line occupancy.Quoted 50 lines
Quoted 45 lines
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
<snip>
Quoted 18 lines
Quoted 11 lines
Quoted 5 lines
Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
In our benchmarks it's just faster. When we tested it, the overhead of the function calls was noticably less than the cost of building up the parameter array(s) for passing the jobs in as a burst. [We don't see this cost with things like NIC I/O since DPDK tends to already have the mbuf fully populated before the TX call anyway.]
OK. I agree with stack population.
My question was more on doing implicit doorbell update enq. Is doorbell write costly in other HW compare to a function call? In our HW, it is just write of the number of instructions written in a register.
Quoted 7 lines
Quoted 3 lines
Also, we need to again access the internal PMD memory structure to find where to write etc if it is a separate function.
The cost varies depending on a number of factors - even writing to a single HW register can be very slow if that register is mapped as device (uncacheable) memory, since (AFAIK) it will act as a full fence and wait
I don't know, At least in our case, writes are write-back. so core does not need to wait.(If there is no read operation).
Quoted 9 lines
for the write to go all the way to hardware. For more modern HW, the cost can be lighter. However, any cost of HW writes is going to be the same whether its a separate function call or not.
However, the main thing about the doorbell update is that it's a once-per-burst thing, rather than a once-per-job. Therefore, even if you have to re-read the struct memory (which is likely still somewhere in your cores' cache), any extra small cost of doing so is to be amortized over the cost of a whole burst of copies.
Quoted 4 lines
Linux kernel has
xmit_moreflag in skb to address similar thing. i.e enq job flag can have one more bit field to say update ring bell or not? Rather having yet another function overhead.IMO, it is the best of both worlds.Quoted 6 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has
data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy()andrte_dma_perform()b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
thatrte_dma_copy()flag can be updated to fire the doorbell.
Quoted 8 lines
Quoted 7 lines
IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.IMO, a single branch is most optimal from performance PoV.
Ok, let's try it and see how it goes.
Test result show:
1) For Kunpeng platform (ARMv8) could benefit very little with doorbell in flags
2) For Xeon E5-2690 v2 (X86) could benefit with separate function
3) Both platform could benefit with doorbell in flags if burst < 5
There is a performance gain in small bursts (<5). Given the extensive use of bursts in DPDK applications and users are accustomed to the concept, I do not recommend using the 'doorbell' in flags.
And also user may confuse about the doorbell operations.
Kunpeng platform test result:
[root@SZ tmp]# ./a1 1
burst = 1
perform_after_multiple_enqueue: burst:1 cost:0s.554422us
doorbell_for_every_enqueue: burst:1 cost:0s.450927us
last_enqueue_issue_doorbell: burst:1 cost:0s.450479us
[root@SZ tmp]#
[root@SZ tmp]# ./a1 2
burst = 2
perform_after_multiple_enqueue: burst:2 cost:0s.900884us
doorbell_for_every_enqueue: burst:2 cost:0s.866732us
last_enqueue_issue_doorbell: burst:2 cost:0s.732469us
[root@SZ tmp]# ./a1 5
burst = 5
perform_after_multiple_enqueue: burst:5 cost:1s.732410us
doorbell_for_every_enqueue: burst:5 cost:2s.115479us
last_enqueue_issue_doorbell: burst:5 cost:1s.759349us
[root@SZ tmp]# ./a1 10
burst = 10
perform_after_multiple_enqueue: burst:10 cost:3s.490716us
doorbell_for_every_enqueue: burst:10 cost:4s.194691us
last_enqueue_issue_doorbell: burst:10 cost:3s.331825us
[root@SZ tmp]# ./a1 30
burst = 30
perform_after_multiple_enqueue: burst:30 cost:9s.61761us
doorbell_for_every_enqueue: burst:30 cost:12s.517082us
last_enqueue_issue_doorbell: burst:30 cost:9s.614802usX86 platform test result:
fengchengwen@SZ:~/tmp$ ./a1 1
burst = 1
perform_after_multiple_enqueue: burst:1 cost:0s.406331us
doorbell_for_every_enqueue: burst:1 cost:0s.331109us
last_enqueue_issue_doorbell: burst:1 cost:0s.381782us
fengchengwen@SZ:~/tmp$ ./a1 2
burst = 2
perform_after_multiple_enqueue: burst:2 cost:0s.569024us
doorbell_for_every_enqueue: burst:2 cost:0s.643449us
last_enqueue_issue_doorbell: burst:2 cost:0s.486639us
fengchengwen@SZ:~/tmp$ ./a1 5
burst = 5
perform_after_multiple_enqueue: burst:5 cost:1s.166384us
doorbell_for_every_enqueue: burst:5 cost:1s.602369us
last_enqueue_issue_doorbell: burst:5 cost:1s.209392us
fengchengwen@SZ:~/tmp$ ./a1 10
burst = 10
perform_after_multiple_enqueue: burst:10 cost:2s.229901us
doorbell_for_every_enqueue: burst:10 cost:3s.754802us
last_enqueue_issue_doorbell: burst:10 cost:2s.328705us
fengchengwen@SZ:~/tmp$
fengchengwen@SZ:~/tmp$ ./a1 30
burst = 30
perform_after_multiple_enqueue: burst:30 cost:6s.132817us
doorbell_for_every_enqueue: burst:30 cost:9s.944619us
last_enqueue_issue_doorbell: burst:30 cost:7s.73551ustest-code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>
struct dmadev;
unsigned int dev_reg[10240];
volatile unsigned int *ring;
volatile unsigned int *doorbell;
void init_global(void)
{
ring = &dev_reg[100];
doorbell = &dev_reg[10000];
}#define rte_wmb() asm volatile("dmb oshst" : : : "memory") //#define rte_wmb() asm volatile ("" : : : "memory")
typedef int (*enqueue_t)(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags); typedef void (*perform_t)(struct dmadev *dev, int vchan);
struct dmadev {
enqueue_t enqueue;
perform_t perform;
char rsv[512];
};int hisi_dma_enqueue(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags)
{
*ring = 1;
}int hisi_dma_enqueue_doorbell(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags)
{
*ring = 1;
if (flags == 1) {
rte_wmb();
*doorbell = 1;
}
}void hisi_dma_perform(struct dmadev *dev, int vchan)
{
rte_wmb();
*doorbell = 1;
}struct dmadev devlist[64];
void init_devlist(bool enq_doorbell)
{
int i;
for (i = 0; i < 64; i++) {
devlist[i].enqueue = enq_doorbell ? hisi_dma_enqueue_doorbell : hisi_dma_enqueue;
devlist[i].perform = hisi_dma_perform;
}
}static inline int dma_enqueue(int dev_id, int vchan, void *src, void *dst, int len, int flags)
{
struct dmadev *dev = &devlist[dev_id];
return dev->enqueue(dev, vchan, src, dst, len, flags);
}static inline void dma_perform(int dev_id, int vchan)
{
struct dmadev *dev = &devlist[dev_id];
return dev->perform(dev, vchan);
}#define MAX_LOOPS 90000000
void test_for_perform_after_multiple_enqueue(int burst)
{
struct timeval start, end, delta;
unsigned int i, j;
init_devlist(false);
gettimeofday(&start, NULL);
for (i = 0; i < MAX_LOOPS; i++) {
for (j = 0; j < burst; j++)
(void)dma_enqueue(10, 0, NULL, NULL, 0, 0);
dma_perform(10, 0);
}
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("perform_after_multiple_enqueue: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec);
}void test_for_doorbell_for_every_enqueue(int burst)
{
struct timeval start, end, delta;
unsigned int i, j;
init_devlist(true);
gettimeofday(&start, NULL);
for (i = 0; i < MAX_LOOPS; i++) {
for (j = 0; j < burst; j++)
(void)dma_enqueue(10, 0, NULL, NULL, 0, 1);
}
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("doorbell_for_every_enqueue: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec);
}void test_for_last_enqueue_issue_doorbell(int burst)
{
struct timeval start, end, delta;
unsigned int i, j;
init_devlist(true);
gettimeofday(&start, NULL);
for (i = 0; i < MAX_LOOPS; i++) {
for (j = 0; j < burst - 1; j++)
(void)dma_enqueue(10, 0, NULL, NULL, 0, 0);
dma_enqueue(10, 0, NULL, NULL, 0, 1);
}
gettimeofday(&end, NULL);
timersub(&end, &start, &delta);
printf("last_enqueue_issue_doorbell: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec);
}void main(int argc, char *argv[])
{
if (argc < 2) {
printf("please input burst parameter!\n");
return;
}
init_global();
int burst = atol(argv[1]);
printf("burst = %d \n", burst);
test_for_perform_after_multiple_enqueue(burst);
test_for_doorbell_for_every_enqueue(burst);
test_for_last_enqueue_issue_doorbell(burst);
}Quoted 108 lines
Quoted 102 lines
Quoted 93 lines
Quoted 84 lines
Quoted 84 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
<snip>
Quoted 55 lines
Quoted 47 lines
Quoted 26 lines
Quoted 6 lines
+ +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Returns the number of operations that failed to complete. + * NOTE: This API was used when
rte_dmadev_completedhas_errorwas set. + * + * @paramdev_id
+ * The identifier of the device. + * @paramvq_id+ * The
identifier of virt queue.(> + * @param
nb_statusQuoted 11 lines
+ * Indicates the size of status array. + * @param[out]
status + * The error code of operations that failed to
complete. + * @param[out] cookie + * The last failed
completed operation's cookie. + * + * @return + * The number
of operations that failed to complete. + * + * NOTE: The caller must ensure that the input parameter is valid and the +
* corresponding device supports the operation. + */(quoted diff) +2
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, +const
uint16_tnb_status,uint32_t*status, +dma_cookie_t*cookie)IMO, it is better to move cookie/rind_idx at 3. Why it would return any array of errors? since it called after
rte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)Quoted 9 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes of all the driver and return string from driver existing
rte_flow_errorSee struct
rte_flow_error{ enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */ };I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 3 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right? ie.
uint32_t*status needs to change to enumrte_dma_erroror so.Quoted 9 lines
Quoted 2 lines
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum
rte_dma_error_type2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).Quoted 8 lines
The only issue I have with that is that once we have driver specific information it is of little use to the application, since it can't know anything about it excepy maybe log it. I'd much rather have a set of error codes telling user that "source address is wrong", "dest address is wrong", and a generic "an address is wrong" in case driver/HW cannot distinguish source of error. Can we see how far we get with just error codes before we start into passing string messages around and all the memory management headaches that implies.
Quoted 3 lines
Works for me. It should be "enum
rte_dma_error_type" then, which has a standard error type. Which is missing in the spec now.+1
.
Quoted 33 lines · fengchengwen
Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has
data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy()andrte_dma_perform()b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
thatrte_dma_copy()flag can be updated to fire the doorbell.IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.IMO, a single branch is most optimal from performance PoV.
Quoted 8 lines
Quoted 1 line
Ok, let's try it and see how it goes.
Test result show:
1) For Kunpeng platform (ARMv8) could benefit very little with doorbell in flags
2) For Xeon E5-2690 v2 (X86) could benefit with separate function
3) Both platform could benefit with doorbell in flags if burst < 5There is a performance gain in small bursts (<5). Given the extensive use of bursts
in DPDK applications and users are accustomed to the concept, I do
not recommend
Quoted 1 line
using the 'doorbell' in flags.
There is NO concept change between one option vs other option. Just argument differnet.
Also, _perform() scheme not used anywhere in DPDK. I
Regarding performance, I have added dummy instructions to simulate the real work load[1], now burst also has some gain in both x86 and arm64[3]
I have modified your application[2] to dpdk test application to use cpu isolation etc.
So this is gain in flag scheme ad code is checked in to Github[2[
[1]
static inline void
delay(void)
{
volatile int k;
for (k = 0; k < 16; k++) {
}}
__rte_noinline
inthisi_dma_enqueue(struct dmadev *dev, int vchan, void *src, void *dst, int len, const int flags)
{
delay();
*ring = 1;
return 0;
}__rte_noinline
inthisi_dma_enqueue_doorbell(struct dmadev *dev, int vchan, void *src, void *dst, int len, const int flags)
{
delay();
*ring = 1;
if (unlikely(flags == 1)) {
rte_wmb();
*doorbell = 1;
}
return 0;
}[2]
https://github.com/jerinjacobk/dpdk-dmatest/commit/4fc9bc3029543bbc4caaa5183d98bac93c34f588
Update results [3]
Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
echo "dma_perf_autotest" | ./build/app/test/dpdk-test --no-huge -c 0xf00
core=24 Timer running at 2600.00MHz
test_for_perform_after_multiple_enqueue: burst=1 cycles=46.000000
test_for_last_enqueue_issue_doorbell: burst=1 cycles=45.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=2 cycles=90.000000
test_for_last_enqueue_issue_doorbell: burst=2 cycles=89.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=3 cycles=134.000000
test_for_last_enqueue_issue_doorbell: burst=3 cycles=133.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=4 cycles=177.000000
test_for_last_enqueue_issue_doorbell: burst=4 cycles=176.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=5 cycles=221.000000
test_for_last_enqueue_issue_doorbell: burst=5 cycles=221.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=6 cycles=265.000000
test_for_last_enqueue_issue_doorbell: burst=6 cycles=265.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=7 cycles=333.000000
test_for_last_enqueue_issue_doorbell: burst=7 cycles=309.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=8 cycles=375.000000
test_for_last_enqueue_issue_doorbell: burst=8 cycles=373.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=9 cycles=418.000000
test_for_last_enqueue_issue_doorbell: burst=9 cycles=414.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=10 cycles=462.000000
test_for_last_enqueue_issue_doorbell: burst=10 cycles=458.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=11 cycles=507.000000
test_for_last_enqueue_issue_doorbell: burst=11 cycles=501.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=12 cycles=552.000000
test_for_last_enqueue_issue_doorbell: burst=12 cycles=546.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=13 cycles=593.000000
test_for_last_enqueue_issue_doorbell: burst=13 cycles=590.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=14 cycles=638.000000
test_for_last_enqueue_issue_doorbell: burst=14 cycles=634.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=15 cycles=681.000000
test_for_last_enqueue_issue_doorbell: burst=15 cycles=678.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=16 cycles=725.000000
test_for_last_enqueue_issue_doorbell: burst=16 cycles=722.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=17 cycles=770.000000
test_for_last_enqueue_issue_doorbell: burst=17 cycles=767.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=18 cycles=815.000000
test_for_last_enqueue_issue_doorbell: burst=18 cycles=812.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=19 cycles=857.000000
test_for_last_enqueue_issue_doorbell: burst=19 cycles=854.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=20 cycles=902.000000
test_for_last_enqueue_issue_doorbell: burst=20 cycles=899.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=21 cycles=945.000000
test_for_last_enqueue_issue_doorbell: burst=21 cycles=943.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=22 cycles=990.000000
test_for_last_enqueue_issue_doorbell: burst=22 cycles=988.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=23 cycles=1033.000000
test_for_last_enqueue_issue_doorbell: burst=23 cycles=1031.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=24 cycles=1077.000000
test_for_last_enqueue_issue_doorbell: burst=24 cycles=1075.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=25 cycles=1121.000000
test_for_last_enqueue_issue_doorbell: burst=25 cycles=1119.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=26 cycles=1166.000000
test_for_last_enqueue_issue_doorbell: burst=26 cycles=1163.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=27 cycles=1208.000000
test_for_last_enqueue_issue_doorbell: burst=27 cycles=1208.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=28 cycles=1252.000000
test_for_last_enqueue_issue_doorbell: burst=28 cycles=1252.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=29 cycles=1295.000000
test_for_last_enqueue_issue_doorbell: burst=29 cycles=1295.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=30 cycles=1342.000000
test_for_last_enqueue_issue_doorbell: burst=30 cycles=1340.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=31 cycles=1386.000000
test_for_last_enqueue_issue_doorbell: burst=31 cycles=1384.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=32 cycles=1429.000000
test_for_last_enqueue_issue_doorbell: burst=32 cycles=1428.000000-------------------------------------------------------------------------------
octeontx2:
See https://doc.dpdk.org/guides/prog_guide/profile_app.html section 62.2.3. High-resolution cycle counter
meson --cross config/arm/arm64_octeontx2_linux_gcc -Dc_args='-DRTE_ARM_EAL_RDTSC_USE_PMU' build
echo "dma_perf_autotest" | ./build/app/test/dpdk-test --no-huge -c 0xff0000
RTE>>dma_perf_autotest^M
lcore=16 Timer running at 2400.00MHz
test_for_perform_after_multiple_enqueue: burst=1 cycles=105.000000
test_for_last_enqueue_issue_doorbell: burst=1 cycles=105.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=2 cycles=207.000000
test_for_last_enqueue_issue_doorbell: burst=2 cycles=207.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=3 cycles=309.000000
test_for_last_enqueue_issue_doorbell: burst=3 cycles=310.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=4 cycles=411.000000
test_for_last_enqueue_issue_doorbell: burst=4 cycles=410.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=5 cycles=513.000000
test_for_last_enqueue_issue_doorbell: burst=5 cycles=512.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=6 cycles=615.000000
test_for_last_enqueue_issue_doorbell: burst=6 cycles=615.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=7 cycles=717.000000
test_for_last_enqueue_issue_doorbell: burst=7 cycles=716.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=8 cycles=819.000000
test_for_last_enqueue_issue_doorbell: burst=8 cycles=818.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=9 cycles=921.000000
test_for_last_enqueue_issue_doorbell: burst=9 cycles=922.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=10 cycles=1023.000000
test_for_last_enqueue_issue_doorbell: burst=10 cycles=1022.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=11 cycles=1126.000000
test_for_last_enqueue_issue_doorbell: burst=11 cycles=1124.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=12 cycles=1227.000000
test_for_last_enqueue_issue_doorbell: burst=12 cycles=1227.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=13 cycles=1329.000000
test_for_last_enqueue_issue_doorbell: burst=13 cycles=1328.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=14 cycles=1431.000000
test_for_last_enqueue_issue_doorbell: burst=14 cycles=1430.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=15 cycles=1534.000000
test_for_last_enqueue_issue_doorbell: burst=15 cycles=1534.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=16 cycles=1638.000000
test_for_last_enqueue_issue_doorbell: burst=16 cycles=1640.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=17 cycles=1746.000000
test_for_last_enqueue_issue_doorbell: burst=17 cycles=1739.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=18 cycles=1847.000000
test_for_last_enqueue_issue_doorbell: burst=18 cycles=1841.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=19 cycles=1950.000000
test_for_last_enqueue_issue_doorbell: burst=19 cycles=1944.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=20 cycles=2051.000000
test_for_last_enqueue_issue_doorbell: burst=20 cycles=2045.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=21 cycles=2154.000000
test_for_last_enqueue_issue_doorbell: burst=21 cycles=2148.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=22 cycles=2257.000000
test_for_last_enqueue_issue_doorbell: burst=22 cycles=2249.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=23 cycles=2358.000000
test_for_last_enqueue_issue_doorbell: burst=23 cycles=2352.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=24 cycles=2459.000000
test_for_last_enqueue_issue_doorbell: burst=24 cycles=2454.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=25 cycles=2562.000000
test_for_last_enqueue_issue_doorbell: burst=25 cycles=2555.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=26 cycles=2665.000000
test_for_last_enqueue_issue_doorbell: burst=26 cycles=2657.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=27 cycles=2766.000000
test_for_last_enqueue_issue_doorbell: burst=27 cycles=2760.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=28 cycles=2867.000000
test_for_last_enqueue_issue_doorbell: burst=28 cycles=2861.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=29 cycles=2970.000000
test_for_last_enqueue_issue_doorbell: burst=29 cycles=2964.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=30 cycles=3073.000000
test_for_last_enqueue_issue_doorbell: burst=30 cycles=3065.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=31 cycles=3174.000000
test_for_last_enqueue_issue_doorbell: burst=31 cycles=3168.000000
-------------------------------------------------------------------------------
test_for_perform_after_multiple_enqueue: burst=32 cycles=3275.000000
test_for_last_enqueue_issue_doorbell: burst=32 cycles=3269.000000-------------------------------------------------------------------------------
Test OK
RTE>
Quoted 305 lines
And also user may confuse about the doorbell operations.
Kunpeng platform test result:
[root@SZ tmp]# ./a1 1 burst = 1 perform_after_multiple_enqueue: burst:1 cost:0s.554422us doorbell_for_every_enqueue: burst:1 cost:0s.450927us last_enqueue_issue_doorbell: burst:1 cost:0s.450479us [root@SZ tmp]# [root@SZ tmp]# ./a1 2 burst = 2 perform_after_multiple_enqueue: burst:2 cost:0s.900884us doorbell_for_every_enqueue: burst:2 cost:0s.866732us last_enqueue_issue_doorbell: burst:2 cost:0s.732469us [root@SZ tmp]# ./a1 5 burst = 5 perform_after_multiple_enqueue: burst:5 cost:1s.732410us doorbell_for_every_enqueue: burst:5 cost:2s.115479us last_enqueue_issue_doorbell: burst:5 cost:1s.759349us [root@SZ tmp]# ./a1 10 burst = 10 perform_after_multiple_enqueue: burst:10 cost:3s.490716us doorbell_for_every_enqueue: burst:10 cost:4s.194691us last_enqueue_issue_doorbell: burst:10 cost:3s.331825us [root@SZ tmp]# ./a1 30 burst = 30 perform_after_multiple_enqueue: burst:30 cost:9s.61761us doorbell_for_every_enqueue: burst:30 cost:12s.517082us last_enqueue_issue_doorbell: burst:30 cost:9s.614802usX86 platform test result:
fengchengwen@SZ:~/tmp$ ./a1 1 burst = 1 perform_after_multiple_enqueue: burst:1 cost:0s.406331us doorbell_for_every_enqueue: burst:1 cost:0s.331109us last_enqueue_issue_doorbell: burst:1 cost:0s.381782us fengchengwen@SZ:~/tmp$ ./a1 2 burst = 2 perform_after_multiple_enqueue: burst:2 cost:0s.569024us doorbell_for_every_enqueue: burst:2 cost:0s.643449us last_enqueue_issue_doorbell: burst:2 cost:0s.486639us fengchengwen@SZ:~/tmp$ ./a1 5 burst = 5 perform_after_multiple_enqueue: burst:5 cost:1s.166384us doorbell_for_every_enqueue: burst:5 cost:1s.602369us last_enqueue_issue_doorbell: burst:5 cost:1s.209392us fengchengwen@SZ:~/tmp$ ./a1 10 burst = 10 perform_after_multiple_enqueue: burst:10 cost:2s.229901us doorbell_for_every_enqueue: burst:10 cost:3s.754802us last_enqueue_issue_doorbell: burst:10 cost:2s.328705us fengchengwen@SZ:~/tmp$ fengchengwen@SZ:~/tmp$ ./a1 30 burst = 30 perform_after_multiple_enqueue: burst:30 cost:6s.132817us doorbell_for_every_enqueue: burst:30 cost:9s.944619us last_enqueue_issue_doorbell: burst:30 cost:7s.73551ustest-code:
#include <
stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>struct dmadev;
unsigned int dev_reg[10240];
volatile unsigned int *ring;
volatile unsigned int *doorbell;void
init_global(void){ ring = &dev_reg[100]; doorbell = &dev_reg[10000]; }#define
rte_wmb()asmvolatile("dmb oshst" : : : "memory")//#definerte_wmb()asm volatile ("" : : : "memory")typedef int (*enqueue_t)(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags); typedef void (*perform_t)(struct dmadev *dev, int vchan);
struct dmadev { enqueue_t enqueue; perform_t perform; char rsv[512]; };int
hisi_dma_enqueue(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags){ *ring = 1; }int
hisi_dma_enqueue_doorbell(struct dmadev *dev, int vchan, void *src, void *dst, int len, int flags){ *ring = 1; if (flags == 1) { rte_wmb(); *doorbell = 1; } }void
hisi_dma_perform(struct dmadev *dev, int vchan){ rte_wmb(); *doorbell = 1; }struct dmadev devlist[64];
void
init_devlist(bool enq_doorbell){ int i; for (i = 0; i < 64; i++) { devlist[i].enqueue = enq_doorbell ? hisi_dma_enqueue_doorbell : hisi_dma_enqueue; devlist[i].perform = hisi_dma_perform; } }static inline int
dma_enqueue(int dev_id, int vchan, void *src, void *dst, int len, int flags){ struct dmadev *dev = &devlist[dev_id]; return dev->enqueue(dev, vchan, src, dst, len, flags); }static inline void
dma_perform(int dev_id, int vchan){ struct dmadev *dev = &devlist[dev_id]; return dev->perform(dev, vchan); }#define
MAX_LOOPS90000000void
test_for_perform_after_multiple_enqueue(int burst){ struct timeval start, end, delta; unsigned int i, j; init_devlist(false); gettimeofday(&start, NULL); for (i = 0; i < MAX_LOOPS; i++) { for (j = 0; j < burst; j++) (void)dma_enqueue(10, 0, NULL, NULL, 0, 0); dma_perform(10, 0); } gettimeofday(&end, NULL); timersub(&end, &start, &delta); printf("perform_after_multiple_enqueue: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec); }void
test_for_doorbell_for_every_enqueue(int burst){ struct timeval start, end, delta; unsigned int i, j; init_devlist(true); gettimeofday(&start, NULL); for (i = 0; i < MAX_LOOPS; i++) { for (j = 0; j < burst; j++) (void)dma_enqueue(10, 0, NULL, NULL, 0, 1); } gettimeofday(&end, NULL); timersub(&end, &start, &delta); printf("doorbell_for_every_enqueue: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec); }void
test_for_last_enqueue_issue_doorbell(int burst){ struct timeval start, end, delta; unsigned int i, j; init_devlist(true); gettimeofday(&start, NULL); for (i = 0; i < MAX_LOOPS; i++) { for (j = 0; j < burst - 1; j++) (void)dma_enqueue(10, 0, NULL, NULL, 0, 0); dma_enqueue(10, 0, NULL, NULL, 0, 1); } gettimeofday(&end, NULL); timersub(&end, &start, &delta); printf("last_enqueue_issue_doorbell: burst:%d cost:%us.%uus \n", burst, delta.tv_sec, delta.tv_usec); }void
main(int argc, char *argv[]){ if (argc < 2) { printf("please input burst parameter!\n"); return; } init_global(); int burst = atol(argv[1]); printf("burst = %d \n", burst); test_for_perform_after_multiple_enqueue(burst); test_for_doorbell_for_every_enqueue(burst); test_for_last_enqueue_issue_doorbell(burst); }Quoted 108 lines
Quoted 102 lines
Quoted 93 lines
Quoted 84 lines
Quoted 84 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
<snip>
Quoted 55 lines
Quoted 47 lines
Quoted 26 lines
Quoted 6 lines
+ +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Returns the number of operations that failed to complete. + * NOTE: This API was used when
rte_dmadev_completedhas_errorwas set. + * + * @paramdev_id
+ * The identifier of the device. + * @paramvq_id+ * The
identifier of virt queue.(> + * @param
nb_statusQuoted 11 lines
+ * Indicates the size of status array. + * @param[out]
status + * The error code of operations that failed to
complete. + * @param[out] cookie + * The last failed
completed operation's cookie. + * + * @return + * The number
of operations that failed to complete. + * + * NOTE: The caller must ensure that the input parameter is valid and the +
* corresponding device supports the operation. + */(quoted diff) +2
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, +const
uint16_tnb_status,uint32_t*status, +dma_cookie_t*cookie)IMO, it is better to move cookie/rind_idx at 3. Why it would return any array of errors? since it called after
rte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)Quoted 9 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes of all the driver and return string from driver existing
rte_flow_errorSee struct
rte_flow_error{ enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */ };I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
Quoted 7 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 3 lines
OK. What is the purpose of errors status? Is it for application printing it or Does the application need to take any action based on specific error requests?
It's largely for information purposes, but in the case of SVA/SVM errors could occur due to the memory not being pinned, i.e. a page fault, in some cases. If that happens, then it's up the app to either touch the memory and retry the copy, or to do a SW memcpy as a fallback.
In other error cases, I think it's good to tell the application if it's passing around bad data, or data that is beyond the scope of hardware, e.g. a copy that is beyond what can be done in a single transaction for a HW instance. Given that there are always things that can go wrong, I think we need some error reporting mechanism.
Quoted 4 lines
If the former is scope, then we need to define the standard enum value for the error right? ie.
uint32_t*status needs to change to enumrte_dma_erroror so.Quoted 9 lines
Quoted 2 lines
Sure. Perhaps an error/status structure either is an option, where we explicitly call out error info from status info.
Agree. Better to have a structure with filed like,
1) enum
rte_dma_error_type2) memory to store, informative message on fine aspects of error. LIke address caused issue etc.(Which will be driver-specific information).Quoted 8 lines
The only issue I have with that is that once we have driver specific information it is of little use to the application, since it can't know anything about it excepy maybe log it. I'd much rather have a set of error codes telling user that "source address is wrong", "dest address is wrong", and a generic "an address is wrong" in case driver/HW cannot distinguish source of error. Can we see how far we get with just error codes before we start into passing string messages around and all the memory management headaches that implies.
Quoted 3 lines
Works for me. It should be "enum
rte_dma_error_type" then, which has a standard error type. Which is missing in the spec now.+1
.
Quoted 50 lines · Jerin Jacob
Quoted 33 lines · fengchengwen
Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has
data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy()andrte_dma_perform()b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
thatrte_dma_copy()flag can be updated to fire the doorbell.IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.IMO, a single branch is most optimal from performance PoV.
Quoted 8 lines
Quoted 1 line
Ok, let's try it and see how it goes.
Test result show:
1) For Kunpeng platform (ARMv8) could benefit very little with doorbell in flags
2) For Xeon E5-2690 v2 (X86) could benefit with separate function
3) Both platform could benefit with doorbell in flags if burst < 5There is a performance gain in small bursts (<5). Given the extensive use of bursts
in DPDK applications and users are accustomed to the concept, I do
not recommendQuoted 1 line
using the 'doorbell' in flags.
There is NO concept change between one option vs other option. Just argument differnet.
Also,_perform()scheme not used anywhere in DPDK. I
Quoted 7 lines
Regarding performance, I have added dummy instructions to simulate the real work load[1], now burst also has some gain in both x86 and arm64[3]
I have modified your application[2] to dpdk test application to use cpu isolation etc.
So this is gain in flag scheme ad code is checked in to Github[2[
<snip>
The benchmark numbers all seem very close between the two schemes. On my team we pretty much have test ioat & idxd drivers ported internally to the last dmadev draft library, and have sample apps handling traffic using those. I'll therefore attempt to get these numbers with real traffic on real drivers to just double check that it's the same as these microbenchmarks.
Assuming that perf is the same, how to resolve this? Some thoughts:
* As I understand it, the main objection to the separate doorbell function is the use of 8-bytes in fastpath slot. Therefore I will also attempt to benchmark having the doorbell function not on the same cacheline and check perf impact, if any.
* If we don't have a impact to perf by having the doorbell function inside the regular "ops" rather than on fastpath cacheline, there is no reason we can't implement both schemes. The user can then choose themselves whether to doorbell using a flag on last item, or to doorbell explicitly using function call.
Of the two schemes, and assuming they are equal, I do have a preference for the separate function one, primarily from a code readability point of view. Other than that, I have no strong opinions.
/Bruce
Quoted 59 lines · Bruce Richardson
Quoted 50 lines · Jerin Jacob
Quoted 33 lines · fengchengwen
Quoted 33 lines
Quoted 33 lines
Quoted 9 lines
It's just more conditionals and branches all through the code. Inside the user application, the user has to check whether to set the flag or not (or special-case the last transaction outside the loop), and within the driver, there has to be a branch whether or not to call the doorbell function. The code on both sides is far simpler and more readable if the doorbell function is exactly that - a separate function.
I disagree. The reason is:
We will have two classes of applications
a) do dma copy request as and when it has
data(I think, this is the prime use case), for those,
I think, it is considerable overhead to have two function invocation per transfer i.erte_dma_copy()andrte_dma_perform()b) do dma copy when the data is reached to a logical state, like copy IP frame from Ethernet packets or so,
In that case, the application will have a LOGIC to detect when to perform it so on the end of
thatrte_dma_copy()flag can be updated to fire the doorbell.IMO, We are comparing against a branch(flag is already in register) vs a set of instructions for
1) function pointer overhead
2) Need to use the channel context again back in another function.IMO, a single branch is most optimal from performance PoV.
Quoted 8 lines
Quoted 1 line
Ok, let's try it and see how it goes.
Test result show:
1) For Kunpeng platform (ARMv8) could benefit very little with doorbell in flags
2) For Xeon E5-2690 v2 (X86) could benefit with separate function
3) Both platform could benefit with doorbell in flags if burst < 5There is a performance gain in small bursts (<5). Given the extensive use of bursts
in DPDK applications and users are accustomed to the concept, I do
not recommendQuoted 1 line
using the 'doorbell' in flags.
There is NO concept change between one option vs other option. Just argument differnet.
Also,_perform()scheme not used anywhere in DPDK. IQuoted 7 lines
Regarding performance, I have added dummy instructions to simulate the real work load[1], now burst also has some gain in both x86 and arm64[3]
I have modified your application[2] to dpdk test application to use cpu isolation etc.
So this is gain in flag scheme ad code is checked in to Github[2[
Quoted 8 lines
<snip>
The benchmark numbers all seem very close between the two schemes. On my team we pretty much have test ioat & idxd drivers ported internally to the last dmadev draft library, and have sample apps handling traffic using those. I'll therefore attempt to get these numbers with real traffic on real drivers to just double check that it's the same as these microbenchmarks.
Thanks.
Quoted 6 lines
Assuming that perf is the same, how to resolve this? Some thoughts:
* As I understand it, the main objection to the separate doorbell function is the use of 8-bytes in fastpath slot. Therefore I will also attempt to benchmark having the doorbell function not on the same cacheline and check perf impact, if any.
Probably we can remove rte_dmadev_fill_sg() variant and keep sg only for copy to save 8B.
Quoted 5 lines
* If we don't have a impact to perf by having the doorbell function inside the regular "ops" rather than on fastpath cacheline, there is no reason we can't implement both schemes. The user can then choose themselves whether to doorbell using a flag on last item, or to doorbell explicitly using function call.
Yes. I think, we can keep both.
Quoted 6 lines
Of the two schemes, and assuming they are equal, I do have a preference for the separate function one, primarily from a code readability point of view. Other than that, I have no strong opinions.
/Bruce
Quoted 4 lines
From: dev [mailto:[email protected]] On Behalf Of Jerin Jacob
Probably we can remove
rte_dmadev_fill_sg()variant and keep sg only for copy to save 8B.
Perhaps the scatter/gather functions can be on a separate cache line, following the cache line with the simple functions? Of course, this is only beneficial if the SG functions are not used with simple functions.
This means that we reserve space for 8 simple functions and 8 SG functions.
And if one or two functions are used with both simple and SG functions, it/they can be present in both cache lines. (This is somewhat dirty, but would be a typical implementation for a DPDK flow data structure.)
-Morten
Quoted 9 lines · Morten Brørup
Quoted 5 lines
From: dev [mailto:[email protected]] On Behalf Of Jerin Jacob
Probably we can remove
rte_dmadev_fill_sg()variant and keep sg only for copy to save 8B.Perhaps the scatter/gather functions can be on a separate cache line, following the cache line with the simple functions? Of course, this is only beneficial if the SG functions are not used with simple functions.
This means that we reserve space for 8 simple functions and 8 SG functions.
Currently, there are only two SG and normal ops functions. IMO, should be to keep all fastpath functions in the same CL irrespective of it is simple or not.
My suggestion was more like, if there is no HW support for rte_dmadev_fill_sg() we can remove it from spec.
Quoted 4 lines
And if one or two functions are used with both simple and SG functions, it/they can be present in both cache lines. (This is somewhat dirty, but would be a typical implementation for a DPDK flow data structure.)
-Morten
Quoted 2 lines · Bruce Richardson
Quoted 1 line · Jerin Jacob
On Fri, Jul 2, 2021 at 6:51 PM Chengwen Feng <[email protected]> wrote:
[snip]
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.
Quoted 7 lines
I disagree with the
INT_MAX(orINT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for theINT_MAXvalue. Better to:
1. Specify that it wraps atUINT16_MAXwhich allows us to just use auint16_tinternally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >=UINT16_MAX, giving drivers the flexibility at what value to wrap around.
+1 for option 1
BTW: option 2 seem a little complicated for driver and application.
Quoted 22 lines
Quoted 6 lines
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.Quoted 8 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.I don't think we need this level of detail for addressing capabilities. Unless I'm missing something, the hardware should behave exactly as other hardware does taking in iova's. If the user wants to check whether virtual addresses to pinned memory can be used directly, the user can call "
rte_eal_iova_mode". We can't have a situation where some hardware uses one type of addresses and another hardware the other.
Quoted 4 lines
Therefore, the only additional addressing capability we should need to report is that the hardware can use SVM/SVA and use virtual addresses not in hugepage memory.
I discuss the addressing capability in previous thread. Indeed, we can reduce it to just one capability.
Quoted 28 lines
Quoted 21 lines
Quoted 12 lines
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the DMA virt queue
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.Quoted 8 lines
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dst
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An opaque flags for this operation.Quoted 6 lines
PLEASE REMOVE opaque stuff from fastpath it will be a pain for application writers as
they need to write multiple combinations of fastpath. flags are OK, if we have a valid
generic flag now to control the transfer behavior.
Quoted 4 lines
+1. Flags need to be explicitly listed. If we don't have any flags for now, we can specify that the value must be given as zero and it's for future use.
+1, I will delete the flags parameters.
Currently we have fence which was implemented by ops, if later need more flags, maybe we need create one new ops, this is not the way to expand.
So I think we need change fence ops to extra_flags ops:
rte_dmadev_fence(uint16_t dev_id, uint16_t vq_id) to rte_dmadev_extra_flags(uint16_t dev_id, uint16_t vq_id, uint64_t flags);
So we could add fence by: rte_dmadev_extra_flags(dev_id, vq_id, RTE_DMA_FLAG_FENCE);
Quoted 50 lines
Quoted 42 lines
Quoted 11 lines
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Returns the number of operations that failed to complete.
+ * NOTE: This API was used whenrte_dmadev_completedhas_errorwas set.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.(> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_errorQuoted 7 lines
See
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};
Quoted 3 lines
I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful
Just curious, what the 'compare' operations's application scenario ?
Quoted 6 lines
compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
In the current design, rte_dmadev_completed_fails applies only to failure scenarios. Do you mean in 'compare' operations, the status always non-zero whether or not the two are consistent ?
Quoted 29 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 10 lines
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
Quoted 6 lines
I also would remove the enqueue fail counts, since they are better counted by the app. If a driver reports 20,000 failures we have no way of knowing if that is 20,000 unique operations which failed to enqueue or a single operation which failed to enqueue 20,000 times but succeeded on attempt 20,001.
This does exist, The application may just show a DEBUG trace other than recording. So I would recommend keeping at least know if it happens after a long run.
Quoted 1 line
Quoted 22 lines · fengchengwen
Quoted 2 lines · Bruce Richardson
Quoted 1 line · Jerin Jacob
On Fri, Jul 2, 2021 at 6:51 PM Chengwen Feng <[email protected]> wrote:
[snip]
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
+ *
+ * Ifdma_cookie_tis >=0 it's a DMA operation request cookie, <0 it's a error
+ * code.
+ * When using cookies, comply with the following rules:
+ * a) Cookies for each virtual queue are independent.
+ * b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.Quoted 7 lines
I disagree with the
INT_MAX(orINT32_MAX) value here. If we use that value, it means that we cannot use implicit wrap-around inside the CPU and have to check for theINT_MAXvalue. Better to:
1. Specify that it wraps atUINT16_MAXwhich allows us to just use auint16_tinternally and wrap-around automatically, or:
2. Specify that it wraps at a power-of-2 value >=UINT16_MAX, giving drivers the flexibility at what value to wrap around.
Quoted 3 lines
+1 for option 1
BTW: option 2 seem a little complicated for driver and application.
I would tend to agree. I just included it in case there was a case where you explicitly wanted more than UINT16_MAX values in your driver.
Quoted 68 lines
Quoted 22 lines
Quoted 6 lines
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.Quoted 8 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.I don't think we need this level of detail for addressing capabilities. Unless I'm missing something, the hardware should behave exactly as other hardware does taking in iova's. If the user wants to check whether virtual addresses to pinned memory can be used directly, the user can call "
rte_eal_iova_mode". We can't have a situation where some hardware uses one type of addresses and another hardware the other.Quoted 4 lines
Therefore, the only additional addressing capability we should need to report is that the hardware can use SVM/SVA and use virtual addresses not in hugepage memory.
I discuss the addressing capability in previous thread. Indeed, we can reduce it to just one capability.
Quoted 28 lines
Quoted 21 lines
Quoted 12 lines
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the DMA virt queue
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.Quoted 8 lines
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dst
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An opaque flags for this operation.Quoted 6 lines
PLEASE REMOVE opaque stuff from fastpath it will be a pain for application writers as
they need to write multiple combinations of fastpath. flags are OK, if we have a valid
generic flag now to control the transfer behavior.Quoted 4 lines
+1. Flags need to be explicitly listed. If we don't have any flags for now, we can specify that the value must be given as zero and it's for future use.
+1, I will delete the flags parameters.
Currently we have fence which was implemented by ops, if later need more flags, maybe we need create one new ops, this is not the way to expand.
Quoted 7 lines
So I think we need change fence ops to
extra_flagsops:rte_dmadev_fence(uint16_t dev_id, uint16_t vq_id) to rte_dmadev_extra_flags(uint16_t dev_id, uint16_t vq_id, uint64_t flags);So we could add fence by:
rte_dmadev_extra_flags(dev_id, vq_id, RTE_DMA_FLAG_FENCE);
I don't think this is the way to go. I think we will need the flags parameter per op in the future, so we should keep it, even if it is always zero for now. It gives us future expandability options.
Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
Quoted 11 lines
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Returns the number of operations that failed to complete.
+ * NOTE: This API was used whenrte_dmadev_completedhas_errorwas set.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.(> + * @param
nb_statusQuoted 12 lines
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to changerte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_errorSee
structrte_flow_error{
enumrte_flow_error_typetype; /**< Cause field and error types. */ const void *cause; /**< Object responsible for the error. */ const char *message; /**< Human-readable error message. */
};
Quoted 6 lines
Quoted 3 lines
I think we need a multi-return value API here, as we may add operations in future which have non-error status values to return. The obvious case is DMA engines which support "compare" operations. In that case a successful
Just curious, what the 'compare' operations's application scenario ?
We are not looking to use this capability just now - but it's a capability in our hardware that offers some interest possibilities so I'd like to ensure it's possible to integrate in future. To do so, we just need to ensure that the function which returns the "error" status - or status generally, can be used to returns bursts of statuses, even if it's slower compared to the regular completion return which just assumes all succeed.
Quoted 11 lines
Quoted 6 lines
compare (as in there were no DMA or HW errors) can return "equal" or "not-equal" as statuses. For general "copy" operations, the faster completion op can be used to just return successful values (and only call this status version on error), while apps using those compare ops or a mixture of copy and compare ops, would always use the slower one that returns status values for each and every op..
In the current design,
rte_dmadev_completed_failsapplies only to failure scenarios. Do you mean in 'compare' operations, the status always non-zero whether or not the two are consistent ?
Yes and no. There are two separate "status" values to be returned for such operations - the actual HW status i.e. all parameters valid, and the actual memcmp result of equal/non-equal. In our completion records these are called "status" and "result" respectively. "Result" is only valid if "status" is successful, and is not relevant for copy or fill or similar ops. Therefore, to support this, we just need some bits in "status" reserved for that result case, and the completed_status op to return an array of status values, not just a single one.
Quoted 36 lines
Quoted 29 lines
The ioat APIs used 32-bit integer values for this status array so as to allow e.g. 16-bits for error code and 16-bits for future status values. For most operations there should be a fairly small set of things that can go wrong, i.e. bad source address, bad destination address or invalid length. Within that we may have a couple of specifics for why an address is bad, but even so I don't think we need to start having multiple bit combinations.
Quoted 10 lines
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
Quoted 6 lines
I also would remove the enqueue fail counts, since they are better counted by the app. If a driver reports 20,000 failures we have no way of knowing if that is 20,000 unique operations which failed to enqueue or a single operation which failed to enqueue 20,000 times but succeeded on attempt 20,001.
Quoted 3 lines
This does exist, The application may just show a DEBUG trace other than recording. So I would recommend keeping at least know if it happens after a long run.
I disagree here - the enqueue failure should only be tracked by the app, because:
1. only app knows whether a particular enqueue failure is retry or not and how it should be counted
2. these failures cannot be counted by hardware and must be counted by software, so adding additional operations to our enqueue path. In the retry case, that could be a lot of load-update-stores that will have to be done in the driver, while if tracked in the app, the count would just be a register increment.
Operation failures can be tracked in driver stats, though, as that is related to hardware operation.
/Bruce
Many thanks, mostly OK, and a few comment inline
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
...
Quoted 11 lines
Quoted 1 line
+#include <
rte_compat.h>Sort in alphabetical order.
lib/dmadev/rte_dmadev.h line 110
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+ +/** +* dma_cookie_t - an opaque DMA cookie Since we are defining the behaviour is not opaque any more. I think, it is better to call
ring_idxor so.
This type is designed to have two meanings, return <0 on failure and return >=0 on success.
How about follwing definition:
typedef int dma_ring_index_t;
if >= 0, it's value range is [0, 65535] = uint16_t, so driver implementation will simply. if <0, then men enqueue failure
For driver, it could hold uint16_t ring_index, if enquer fail just return fail, else return the current ring_index, and update it by: ring_index++;
Quoted 28 lines
lib/dmadev/rte_dmadev.h line 212
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+ +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok typo.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** lib/dmadev/rte_dmadev.h line 228
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */
Quoted 1 line
Please add
max_nb_segs. i.e maximum number of segments supported.
Do you means something like "burst_size" ?
Quoted 32 lines
Quoted 13 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + i + +/** +* dma_address_type +*/ lib/dmadev/rte_dmadev.h line 270
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ I think, there are 3 kinds of limitations/capabilities.
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.
Quoted 7 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.
OK, Let's put together our ideas on address type:
There are three mode, we may define as:
IOVA_as_VA-ALL ---for device which may need support SVA feature
---may also be a CPU memcpy 'device'
IOVA_as_VA ---for device which need support IOMMU
IOVA_as_PA
There are many combination of the modes which device supports: eg. some device may only support IOVA_as_PA, some may only support IOVA_as_VA, and some support IOVA_as_PA and IOVA_as_VA. The specific runtime type is determined by the vfio and drive capability(e.g RTE_PCI_DRV_NEED_IOVA_AS_VA).
So we already define two capabilities for this:
#define RTE_DMA_DEV_CAPA_IOVA (1ull << 8) /**< Support IOVA as DMA address */ ---this cover IOVA_as_VA and IOVA_as_PA #define RTE_DMA_DEV_CAPA_VA (1ull << 9) /**< Support VA as DMA address */ ---this cover IOVA_as_VA-ALL
for a device which don't support SVA:
only declare RTE_DMA_DEV_CAPA_IOVA
for a device which support SVA:
delcare RTE_DAMA_DEV_CAPA_IOVA
delcare RTE_DMA_DEV_CAPA_VA (only when IOMMU enabled and 'SVA flag' was set)
for a CPU memcpy device:
only declare RTE_DMA_DEV_CAPA_VA
As application:
- if RTE_DMA_DEV_CAPA_VA support, then it could pass any va address to the DMA,
- else if RTE_DMA_DEV_CAPA_IOVA support, then it should pass iova address to the DMA
- else the DMA device should not exist.
Quoted 13 lines
lib/dmadev/rte_dmadev.h line 545
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags)I would like to change this as:
rte_dmadev_copy_sg(uint16_tdev_id,uint16_tvq_id, const structrte_dma_sg*src,uint32_tnb_src,
const structrte_dma_sg*dst,uint32_tnb_dst) or so allow the use case like src 30 MB copy can be splitted as written as 1 MB x 30 dst.
There are already too many arguments, and the above use case could split 30 sg-item.
Quoted 4 lines
Quoted 4 lines
lib/dmadev/rte_dmadev.h new file +4
-0+__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 657
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +}Since HW submission is in a queue(FIFO) the ordering is always maintained. Right?
Could you share more details and use case offence()from driver/application PoV?
For Kunpeng DMA, hardware supports parallel execution of requests in the same queue,
It applies to the following scenarios: communication with the remote end is involved. driver should ensure issure 'doorbell' after data was full written.
Quoted 27 lines
Quoted 27 lines
lib/dmadev/rte_dmadev.h new file +26
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 686
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +}Since we have additional function call overhead in all the applications for this scheme, I would like to understand the use of doing this way vs enq does the doorbell implicitly from driver/application PoV?
Because we split the burst operation into multiple substeps: for each enq we don't issue 'doorbell', and at last call perform() to issue 'doorbell'.
For ARM platform, should call mb ops when issue 'doorbell', if call mb ops every enq, it may lead significant performance degradation.
Quoted 11 lines
lib/dmadev/rte_dmadev.h line 749
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie)IMO, it is better to move cookie/rind_idx at 3.
Why it would return any array of errors? since it called afterrte_dmadev_completed()hashas_error. Is it better to change
Quoted 7 lines
rte_dmadev_error_status((uint16_t
dev_id,uint16_tvq_id,dma_cookie_t*cookie,uint32_t*status)I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_error
bitmask has limit for most 32 (or we can extend 64), and also the rte_flow_error is heavy.
Considering that errors are a small number of scenarios, so it's OK to pass status array, and status have 32bit it could denotes a very large number of errcode.
Quoted 6 lines
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */
Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
There are fewer fields, and I don't think it's necessary to add capability API, for those who don't support, it could don't implement the callback. For those support, these fields are minimum et.
Quoted 23 lines
Quoted 23 lines
lib/dmadev/rte_dmadev_core.h new file +16
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* +* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ +
Quoted 8 lines
lib/dmadev/rte_dmadev_core.h line 22
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */ To avoid namespace conflict(as it is public API) use
rte_
These are internal function used by driver, not application. and the eth/regexdev_core also defined without rte_
So I think it should remain as it is.
Quoted 17 lines
Quoted 17 lines
lib/dmadev/rte_dmadev_core.h new file +15
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence;
Quoted 8 lines
lib/dmadev/rte_dmadev_core.h line 78
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails;We need to limit fastpath items in 1 CL
yes, currently there are 8 callback, which just fill one cache line.
Quoted 23 lines · fengchengwen
Many thanks, mostly OK, and a few comment inline
Quoted 4 lines · Jerin Jacob
Quoted 3 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
...
Quoted 11 lines
Quoted 1 line
+#include <
rte_compat.h>Sort in alphabetical order.
lib/dmadev/rte_dmadev.h line 110
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+ +/** +* dma_cookie_t - an opaque DMA cookie Since we are defining the behaviour is not opaque any more. I think, it is better to call
ring_idxor so.This type is designed to have two meanings, return <0 on failure and return >=0 on success.
Quoted 9 lines
How about follwing definition:
typedef int dma_ring_index_t;if >= 0, it's value range is [0, 65535] =
uint16_t, so driver implementation will simply. if <0, then men enqueue failureFor driver, it could hold
uint16_tring_index, if enquer fail just return fail, else return the currentring_index, and update it by: ring_index++;
Well, yes and no on the "two meanings". For the enqueue function, yes the return value can have two meanings, but I don't consider them one type. On the completion call, however, this can only be positive values < UINT16_MAX, so having two meanings is actually confusing. Better to have
* enqueue return regular int, with doxygen comment
"@return
Negative on error, otherwise job index between 0 and UINT16_MAX"
* for completions, take a uint16_t* parameter for the last completed index since no negative values are needed.
Beyond this, we generally don't use typedefs in DPDK for basic types (with a few exceptions e.g. rte_iova_t), and save their use only for function pointers.
Quoted 98 lines
Quoted 28 lines
lib/dmadev/rte_dmadev.h line 212
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+ +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok typo.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** lib/dmadev/rte_dmadev.h line 228
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */ Quoted 1 line
Please add
max_nb_segs. i.e maximum number of segments supported.Do you means something like "
burst_size" ?Quoted 32 lines
Quoted 13 lines
lib/dmadev/rte_dmadev.h new file +12
-0+ +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + i + +/** +* dma_address_type +*/ lib/dmadev/rte_dmadev.h line 270
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ I think, there are 3 kinds of limitations/capabilities.
When the system is configured as IOVA as VA
1) Device supports any VA address like memory fromrte_malloc(),rte_memzone(), malloc, stack memory
2) Device support only VA address fromrte_malloc(),rte_memzone()i.e memory backed by hugepage and added to DMA map.Quoted 7 lines
When the system is configured as IOVA as PA
1) Devices support only PA addresses .IMO, Above needs to be advertised as capability and application needs to align with that
and I dont think application requests the driver to work in any of the modes.OK, Let's put together our ideas on address type:
There are three mode, we may define as:
IOVA_as_VA-ALL ---for device which may need support SVA feature
---may also be a CPU memcpy 'device'
IOVA_as_VA---for device which need support IOMMU
IOVA_as_PAThere are many combination of the modes which device supports: eg. some device may only support
IOVA_as_PA, some may only supportIOVA_as_VA, and some supportIOVA_as_PAandIOVA_as_VA. The specific runtime type is determined by the vfio and drivecapability(e.g RTE_PCI_DRV_NEED_IOVA_AS_VA).So we already define two capabilities for this:
#define RTE_DMA_DEV_CAPA_IOVA (1ull << 8) /**< Support IOVA as DMA address */ ---this cover IOVA_as_VA and IOVA_as_PA #define RTE_DMA_DEV_CAPA_VA (1ull << 9) /**< Support VA as DMA address */ ---this cover IOVA_as_VA-ALLfor a device which don't support SVA:
only declareRTE_DMA_DEV_CAPA_IOVA
for a device which support SVA:
delcareRTE_DAMA_DEV_CAPA_IOVA
delcareRTE_DMA_DEV_CAPA_VA(only when IOMMU enabled and 'SVA flag' was set)
for a CPU memcpy device:
only declareRTE_DMA_DEV_CAPA_VA
Quoted 5 lines
As application:
- ifRTE_DMA_DEV_CAPA_VAsupport, then it could pass any va address to the DMA,
- else ifRTE_DMA_DEV_CAPA_IOVAsupport, then it should pass iova address to the DMA
- else the DMA device should not exist.
I still don't think we need all of this. DPDK already has support through the existing bus infrastructure for determining if DPDK needs to use physical or virtual addresses, so we should not be duplicating that as devices *cannot* use a different addressing mode to DPDK itself. Given that, the only flag we need is one to indicate SVA support.
Quoted 1 line
Quoted 1 line
<snip>
Quoted 6 lines
Quoted 5 lines
I also think, we may need to set status as bitmask and enumerate all the combination of error codes
of all the driver and return string from driver existingrte_flow_error
Quoted 7 lines
bitmask has limit for most 32 (or we can extend 64), and also the
rte_flow_erroris heavy.Considering that errors are a small number of scenarios, so it's OK to pass status array, and status have 32bit it could denotes a very large number of errcode.
+1 to this.
Quoted 52 lines
Quoted 6 lines
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ Quoted 9 lines
lib/dmadev/rte_dmadev.h line 764
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +};We need to have capability API to tell which items are updated/supported by the driver.
There are fewer fields, and I don't think it's necessary to add capability API, for those who don't support, it could don't implement the callback. For those support, these fields are minimum et.
Quoted 23 lines
Quoted 23 lines
lib/dmadev/rte_dmadev_core.h new file +16
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* +* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ +Quoted 8 lines
lib/dmadev/rte_dmadev_core.h line 22
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */ To avoid namespace conflict(as it is public API) use
rte_
Quoted 5 lines
These are internal function used by driver, not application. and the eth/regexdev_core also defined without
rte_So I think it should remain as it is.
Even if only used by a driver, APIs are exported from the .so built for the library, which means that they become public for apps using the lib. Even for header-only symbols for drivers, it's good practice to put the prefix since they are for use outside the compilation unit.
Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
lib/dmadev/rte_dmadev_core.h new file +15
-0+ +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence;Quoted 8 lines
lib/dmadev/rte_dmadev_core.h line 78
Quoted 6 lines
lib/dmadev/rte_dmadev_core.h new file +6
-0+/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails;We need to limit fastpath items in 1 CL
Quoted 2 lines
yes, currently there are 8 callback, which just fill one cache line.
Before we get overly concerned about this, I think we should benchmark it to see how much our "one cacheline" is giving us compared to having them in ops. For example, the "perform" doorbell function, or the completed function is only called once every burst, so it would be interesting to see how much difference it really makes for that.
/Bruce
Quoted 2 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
"This patch introduces ... " -> "Introduce ..."
Quoted 5 lines
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>
[snip]
MAINTAINERS F: drivers/raw/skeleton/ · line 499
Quoted 9 lines
MAINTAINERS +1
-0@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst +Dma device API
Dma -> DMA
Quoted 6 lines
MAINTAINERS +3
-0+M: Chengwen Feng <[email protected]> +F: lib/dmadev/ + Memory Pool Drivers -------------------
[snip]
Quoted 473 lines
lib/dmadev/rte_dmadev.c new file +438
-0@@ -0,0 +1,438 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> + +#include <rte_log.h> +#include <rte_debug.h> +#include <rte_dev.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_malloc.h> +#include <rte_errno.h> +#include <rte_string_fns.h> + +#include "rte_dmadev.h" +#include "rte_dmadev_pmd.h" + +struct rte_dmadev rte_dmadevices[RTE_DMADEV_MAX_DEVS ]; + +uint16_t +rte_dmadev_count (void ) +{ +uint16_t count =0 ; +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (rte_dmadevices[i].attached) + count++; + } + +return count; +} + +int +rte_dmadev_get_dev_id (const char *name) +{ +uint16_t i; + +if (name ==NULL ) +return -EINVAL ; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) +if ((strcmp (rte_dmadevices[i].name, name) ==0 ) && + (rte_dmadevices[i].attached ==RTE_DMADEV_ATTACHED )) +return i; + +return -ENODEV ; +} + +int +rte_dmadev_socket_id (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +return dev->socket_id; +} + +int +rte_dmadev_info_get (uint16_t dev_id,struct rte_dmadev_info *dev_info) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_info, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_info_get, -ENOTSUP ); + +memset (dev_info,0 ,sizeof (struct rte_dmadev_info )); + diag = (*dev->dev_ops->dev_info_get)(dev, dev_info); +if (diag !=0 ) +return diag; + + dev_info->device = dev->device; + dev_info->driver_name = dev->driver_name; + dev_info->socket_id = dev->socket_id; + +return 0 ; +} + +int +rte_dmadev_configure (uint16_t dev_id,const struct rte_dmadev_conf *dev_conf) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_conf, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_configure, -ENOTSUP ); + +if (dev->started) { +RTE_DMADEV_LOG (ERR , +"device %u must be stopped to allow configuration" , dev_id); +return -EBUSY ; + } + + diag = (*dev->dev_ops->dev_configure)(dev, dev_conf); +if (diag !=0 ) +RTE_DMADEV_LOG (ERR ,"device %u dev_configure failed, ret = %d" , + dev_id, diag); +else + dev->attached =1 ; + +return diag; +} + +int +rte_dmadev_start (uint16_t dev_id) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; +if (dev->started !=0 ) { +RTE_DMADEV_LOG (ERR ,"device %u already started" , dev_id); +return 0 ; + } + +if (dev->dev_ops->dev_start ==NULL ) + goto mark_started; + + diag = (*dev->dev_ops->dev_start)(dev); +if (diag !=0 ) +return diag; + +mark_started: + dev->started =1 ; +return 0 ; +} + +int +rte_dmadev_stop (uint16_t dev_id) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +if (dev->started ==0 ) { +RTE_DMADEV_LOG (ERR ,"device %u already stopped" , dev_id); +return 0 ; + } + +if (dev->dev_ops->dev_stop ==NULL ) + goto mark_stopped; + + diag = (*dev->dev_ops->dev_stop)(dev); +if (diag !=0 ) +return diag; + +mark_stopped: + dev->started =0 ; +return 0 ; +} + +int +rte_dmadev_close (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_close, -ENOTSUP ); + +/* Device must be stopped before it can be closed */ +if (dev->started ==1 ) { +RTE_DMADEV_LOG (ERR ,"device %u must be stopped before closing" , + dev_id); +return -EBUSY ; + } + +return (*dev->dev_ops->dev_close)(dev); +} + +int +rte_dmadev_reset (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_reset, -ENOTSUP ); + +/* Reset is not dependent on state of the device */ +return (*dev->dev_ops->dev_reset)(dev); +} + +int +rte_dmadev_queue_setup (uint16_t dev_id, +const struct rte_dmadev_queue_conf *conf) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (conf, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->queue_setup, -ENOTSUP ); + +return (*dev->dev_ops->queue_setup)(dev, conf); +} + +int +rte_dmadev_queue_release (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->queue_release, -ENOTSUP ); + +return (*dev->dev_ops->queue_release)(dev, vq_id); +} + +int +rte_dmadev_queue_info_get (uint16_t dev_id,uint16_t vq_id, +struct rte_dmadev_queue_info *info) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (info, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->queue_info_get, -ENOTSUP ); + +memset (info,0 ,sizeof (struct rte_dmadev_queue_info )); +return (*dev->dev_ops->queue_info_get)(dev, vq_id, info); +} + +int +rte_dmadev_stats_get (uint16_t dev_id,int vq_id, +struct rte_dmadev_stats *stats) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (stats, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->stats_get, -ENOTSUP ); + +return (*dev->dev_ops->stats_get)(dev, vq_id, stats); +} + +int +rte_dmadev_stats_reset (uint16_t dev_id,int vq_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->stats_reset, -ENOTSUP ); + +return (*dev->dev_ops->stats_reset)(dev, vq_id); +} + +static int +xstats_get_count (uint16_t dev_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get_names, -ENOTSUP ); + +return (*dev->dev_ops->xstats_get_names)(dev,NULL ,0 ); +} + +int +rte_dmadev_xstats_names_get (uint16_t dev_id, +struct rte_dmadev_xstats_name *xstats_names, +uint32_t size) +{ +struct rte_dmadev *dev; +int cnt_expected_entries; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + cnt_expected_entries =xstats_get_count (dev_id); + +if (xstats_names ==NULL || cnt_expected_entries <0 || + (int )size < cnt_expected_entries || size ==0 ) +return cnt_expected_entries; + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get_names, -ENOTSUP ); +return (*dev->dev_ops->xstats_get_names)(dev, xstats_names, size); +} + +int +rte_dmadev_xstats_get (uint16_t dev_id,const uint32_t ids[], +uint64_t values[],uint32_t n) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (ids, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (values, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get, -ENOTSUP ); + +return (*dev->dev_ops->xstats_get)(dev, ids, values, n); +} + +int +rte_dmadev_xstats_reset (uint16_t dev_id,const uint32_t ids[],uint32_t nb_ids) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_reset, -ENOTSUP ); + +return (*dev->dev_ops->xstats_reset)(dev, ids, nb_ids); +} + +int +rte_dmadev_selftest (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_selftest, -ENOTSUP ); + +return (*dev->dev_ops->dev_selftest)(dev_id); +} + +static inline uint16_t +rte_dmadev_find_free_device_index (void ) +{ +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (rte_dmadevices[i].attached ==RTE_DMADEV_DETACHED ) +return i; + } + +return RTE_DMADEV_MAX_DEVS ; +} + +struct rte_dmadev * +rte_dmadev_pmd_allocate (const char *name,size_t dev_priv_size,int socket_id) +{ +struct rte_dmadev *dev; +uint16_t dev_id; + +if (rte_dmadev_get_dev_id (name) >=0 ) { +RTE_DMADEV_LOG (ERR , +"device with name %s already allocated!" , name); +return NULL ; + } + + dev_id =rte_dmadev_find_free_device_index (); +if (dev_id ==RTE_DMADEV_MAX_DEVS ) { +RTE_DMADEV_LOG (ERR ,"reached maximum number of DMA devices" ); +return NULL ; + } + + dev = &rte_dmadevices[dev_id]; + +if (dev_priv_size >0 ) { + dev->dev_private =rte_zmalloc_socket ("dmadev private" , + dev_priv_size, +RTE_CACHE_LINE_SIZE , + socket_id); +if (dev->dev_private ==NULL ) { +RTE_DMADEV_LOG (ERR , +"unable to allocate memory for dmadev" ); +return NULL ; + } + } + + dev->dev_id = dev_id; + dev->socket_id = socket_id; + dev->started =0 ; +strlcpy (dev->name, name,RTE_DMADEV_NAME_MAX_LEN ); + + dev->attached =RTE_DMADEV_ATTACHED ; + +return dev; +} + +int +rte_dmadev_pmd_release (struct rte_dmadev *dev) +{ +int ret; + +if (dev ==NULL ) +return -EINVAL ; + + ret =rte_dmadev_close (dev->dev_id); +if (ret !=0 ) +return ret; + +if (dev->dev_private !=NULL ) +rte_free (dev->dev_private); + +memset (dev,0 ,sizeof (struct rte_dmadev )); + dev->attached =RTE_DMADEV_DETACHED ; + +return 0 ; +} + +RTE_LOG_REGISTER (libdmadev_logtype, lib.dmadev,INFO );lib/dmadev/rte_dmadev.h new file +23
-0@@ -0,0 +1,919 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_H_ +#define _RTE_DMADEV_H_ + +/** +* @file rte_dmadev.h +* +* RTE DMA (Direct Memory Access) device APIs. +* +* The generic DMA device diagram: +* +* ------------ ------------ +* | HW-queue | | HW-queue | +* ------------ ------------ +* \ / +* \ / +* \ / +* ---------------- +* |dma-controller| +* ----------------
lib/dmadev/rte_dmadev.h line 33
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* +* The DMA could have multiple HW-queues, each HW-queue could have multiple +* capabilities, e.g. whether to support fill operation, supported DMA +* transfter direction and etc. +* +* The DMA framework is built on the following abstraction model: +* +* ------------ ------------ +* |virt-queue| |virt-queue| +* ------------ ------------
Do we really need "virt" here? "virt queue" could be incorrectly associated with virtio spec. IMHO it would be better w/o virt or full "virtual" everywhere in the documentation.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+* \ / +* \ / +* \ / +* ------------ ------------ +* | HW-queue | | HW-queue | +* ------------ ------------
lib/dmadev/rte_dmadev.h line 49
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* \ / +* \ / +* \ / +* ---------- +* | dmadev | +* ---------- +* +* a) The DMA operation request must be submitted to the virt queue, virt +* queues must be created based on HW queues, the DMA device could have +* multiple HW queues.
What does define mapping of virtual queues to HW queues? Does API user sees HW queues? If no, it should be kept transparent and HW queues should be simply removed from the picture.
Quoted 58 lines
lib/dmadev/rte_dmadev.h new file +58
-0+* b) The virt queues on the same HW-queue could represent different contexts, +* e.g. user could create virt-queue-0 on HW-queue-0 for mem-to-mem +* transfer scenario, and create virt-queue-1 on the same HW-queue for +* mem-to-dev transfer scenario. +* NOTE: user could also create multiple virt queues for mem-to-mem transfer +* scenario as long as the corresponding driver supports. +* +* The control plane APIs include configure/queue_setup/queue_release/start/ +* stop/reset/close, in order to start device work, the call sequence must be +* as follows: +* - rte_dmadev_configure() +* - rte_dmadev_queue_setup() +* - rte_dmadev_start() +* +* The dataplane APIs include two parts: +* a) The first part is the submission of operation requests: +* - rte_dmadev_copy() +* - rte_dmadev_copy_sg() - scatter-gather form of copy +* - rte_dmadev_fill() +* - rte_dmadev_fill_sg() - scatter-gather form of fill +* - rte_dmadev_fence() - add a fence force ordering between operations +* - rte_dmadev_perform() - issue doorbell to hardware +* These APIs could work with different virt queues which have different +* contexts. +* The first four APIs are used to submit the operation request to the virt +* queue, if the submission is successful, a cookie (as type +* 'dma_cookie_t') is returned, otherwise a negative number is returned. +* b) The second part is to obtain the result of requests: +* - rte_dmadev_completed() +* - return the number of operation requests completed successfully. +* - rte_dmadev_completed_fails() +* - return the number of operation requests failed to complete. +* +* The misc APIs include info_get/queue_info_get/stats/xstats/selftest, provide +* information query and self-test capabilities. +* +* About the dataplane APIs MT-safe, there are two dimensions: +* a) For one virt queue, the submit/completion API could be MT-safe, +* e.g. one thread do submit operation, another thread do completion +* operation. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VQ. +* If driver don't support it, it's up to the application to guarantee +* MT-safe. +* b) For multiple virt queues on the same HW queue, e.g. one thread do +* operation on virt-queue-0, another thread do operation on virt-queue-1. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MVQ. +* If driver don't support it, it's up to the application to guarantee +* MT-safe. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rte_common.h> +#include <rte_memory.h> +#include <rte_errno.h> +#include <rte_compat.h>
lib/dmadev/rte_dmadev.h line 117
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ +/** +* dma_cookie_t - an opaque DMA cookie +* +* If dma_cookie_t is >=0 it's a DMA operation request cookie, <0 it's a error +* code. +* When using cookies, comply with the following rules: +* a) Cookies for each virtual queue are independent. +* b) For a virt queue, the cookie are monotonically incremented, when it reach +* the INT_MAX, it wraps back to zero.
INT32_MAX
Quoted 61 lines
lib/dmadev/rte_dmadev.h new file +61
-0+* c) The initial cookie of a virt queue is zero, after the device is stopped or +* reset, the virt queue's cookie needs to be reset to zero. +* Example: +* step-1: start one dmadev +* step-2: enqueue a copy operation, the cookie return is 0 +* step-3: enqueue a copy operation again, the cookie return is 1 +* ... +* step-101: stop the dmadev +* step-102: start the dmadev +* step-103: enqueue a copy operation, the cookie return is 0 +* ... +*/ +typedef int32_t dma_cookie_t ; + +/** +* dma_scatterlist - can hold scatter DMA operation request +*/ +struct dma_scatterlist { +void *src; +void *dst; +uint32_t length; +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Get the total number of DMA devices that have been successfully +* initialised. +* +* @return +* The total number of usable DMA devices. +*/ +__rte_experimental +uint16_t +rte_dmadev_count (void ); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Get the device identifier for the named DMA device. +* +* @param name +* DMA device name to select the DMA device identifier. +* +* @return +* Returns DMA device identifier on success. +* - <0: Failure to find named DMA device. +*/ +__rte_experimental +int +rte_dmadev_get_dev_id (const char *name); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Return the NUMA socket to which a device is connected. +* +* @param dev_id
lib/dmadev/rte_dmadev.h line 188
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* The identifier of the device. +* +* @return +* The NUMA socket id to which the device is connected or +* a default of zero if the socket could not be determined. +* - -EINVAL: dev_id value is out of range. +*/ +__rte_experimental +int +rte_dmadev_socket_id (uint16_t dev_id);
It should be rte_dmadev_numa_node(), I guess.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+ +/** +* The capabilities of a DMA device +*/ +#define RTE_DMA_DEV_CAPA_M2M (1ull << 0)/**< Support mem-to-mem transfer */ +#define RTE_DMA_DEV_CAPA_M2D (1ull << 1)/**< Support mem-to-dev transfer */
lib/dmadev/rte_dmadev.h line 204
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+#define RTE_DMA_DEV_CAPA_D2M (1ull << 2)/**< Support dev-to-mem transfer */ +#define RTE_DMA_DEV_CAPA_D2D (1ull << 3)/**< Support dev-to-dev transfer */ +#define RTE_DMA_DEV_CAPA_COPY (1ull << 4)/**< Support copy ops */ +#define RTE_DMA_DEV_CAPA_FILL (1ull << 5)/**< Support fill ops */ +#define RTE_DMA_DEV_CAPA_SG (1ull << 6)/**< Support scatter-gather ops */ +#define RTE_DMA_DEV_CAPA_FENCE (1ull << 7)/**< Support fence ops */ +#define RTE_DMA_DEV_CAPA_IOVA (1ull << 8)/**< Support IOVA as DMA address */ +#define RTE_DMA_DEV_CAPA_VA (1ull << 9)/**< Support VA as DMA address */ +#define RTE_DMA_DEV_CAPA_MT_VQ (1ull << 10)/**< Support MT-safe of one virt queue */ +#define RTE_DMA_DEV_CAPA_MT_MVQ (1ull << 11)/**< Support MT-safe of multiple virt queues */
Above is very hard to read. Values should be aligned at the same column.
lib/dmadev/rte_dmadev.h line 213
Quoted 9 lines
lib/dmadev/rte_dmadev.h new file +9
-0+ +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok +*/
Doxygen has a way to document groups. Please, use it.
Quoted 49 lines
lib/dmadev/rte_dmadev.h new file +49
-0+struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** +* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */ + +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve the contextual information of a DMA device. +* +* @param dev_id +* The identifier of the device. +* +* @param[out] dev_info +* A pointer to a structure of type *rte_dmadev_info* to be filled with the +* contextual information of the device. +* @return +* - =0: Success, driver updates the contextual information of the DMA device +* - <0: Error code returned by the driver info get function. +* +*/ +__rte_experimental +int +rte_dmadev_info_get (uint16_t dev_id,struct rte_dmadev_info *dev_info); + +/** +* dma_address_type +*/ +enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */
lib/dmadev/rte_dmadev.h line 272
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ DMA_ADDRESS_TYPE_VA, /**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ +uint16_t nb_hw_queues;/**< Number of HW-queues enable to use */ +uint16_t max_vqs;/**< Maximum number of virt queues to use */
Is it total or per HW queue? Please, clarify in the documetnation.
Quoted 100 lines
lib/dmadev/rte_dmadev.h new file +100
-0+}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Configure a DMA device. +* +* This function must be invoked first before any other function in the +* API. This function can also be re-invoked when a device is in the +* stopped state. +* +* The caller may use rte_dmadev_info_get() to get the capability of each +* resources available for this DMA device. +* +* @param dev_id +* The identifier of the device to configure. +* @param dev_conf +* The DMA device configuration structure encapsulated into rte_dmadev_conf +* object. +* +* @return +* - =0: Success, device configured. +* - <0: Error code returned by the driver configuration function. +*/ +__rte_experimental +int +rte_dmadev_configure (uint16_t dev_id,const struct rte_dmadev_conf *dev_conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Start a DMA device. +* +* The device start step is the last one and consists of setting the DMA +* to start accepting jobs. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device started. +* - <0: Error code returned by the driver start function. +*/ +__rte_experimental +int +rte_dmadev_start (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Stop a DMA device. +* +* The device can be restarted with a call to rte_dmadev_start() +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device stopped. +* - <0: Error code returned by the driver stop function. +*/ +__rte_experimental +int +rte_dmadev_stop (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Close a DMA device. +* +* The device cannot be restarted after this call. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Successfully closing device +* - <0: Failure to close device +*/ +__rte_experimental +int +rte_dmadev_close (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset a DMA device. +* +* This is different from cycle of rte_dmadev_start->rte_dmadev_stop in the +* sense similar to hard or soft reset. +* +* @param dev_id +* The identifier of the device. +* +* @return
lib/dmadev/rte_dmadev.h line 382
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* - =0: Successful reset device. +* - <0: Failure to reset device. +* - (-ENOTSUP): If the device doesn't support this function. +*/ +__rte_experimental +int +rte_dmadev_reset (uint16_t dev_id); + +/** +* dma_transfer_direction
Such comments must be avoided.
Quoted 4 lines
lib/dmadev/rte_dmadev.h new file +4
-0+*/ +enum dma_transfer_direction { +DMA_MEM_TO_MEM , +DMA_MEM_TO_DEV ,
lib/dmadev/rte_dmadev.h line 396
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ DMA_DEV_TO_MEM, + DMA_DEV_TO_DEV, +}; + +/** +* A structure used to configure a DMA virt queue. +*/ +struct rte_dmadev_queue_conf { +enum dma_transfer_direction direction; +/**< Associated transfer direction */
Please, put comments before the code if comment is in a separate line.
lib/dmadev/rte_dmadev.h line 397
Quoted 1 line
lib/dmadev/rte_dmadev.h new file +1
-0+uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */
How does caller understand which HW queue ID to use? Which one should be chosen? May PMD should device which HW queue to use? Queue configuration can provide hints to make the right choice: required capabilties, relation to another virtual queue etc.
lib/dmadev/rte_dmadev.h line 400
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +void *dev_ctx;/**< Device specific context */
Device specific flags and context sounds bad and adds vendors specifics in API. If so, it could be very hard to switch from vendor to vendor. Do I misunderstand?
Quoted 38 lines
lib/dmadev/rte_dmadev.h new file +38
-0+}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Allocate and set up a virt queue. +* +* @param dev_id +* The identifier of the device. +* @param conf +* The queue configuration structure encapsulated into rte_dmadev_queue_conf +* object. +* +* @return +* - >=0: Allocate virt queue success, it is virt queue id. +* - <0: Error code returned by the driver queue setup function. +*/ +__rte_experimental +int +rte_dmadev_queue_setup (uint16_t dev_id, +const struct rte_dmadev_queue_conf *conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Release a virt queue. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue which return by queue setup. +* +* @return +* - =0: Successful release the virt queue. +* - <0: Error code returned by the driver queue release function. +*/
lib/dmadev/rte_dmadev.h line 448
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+__rte_experimental +int +rte_dmadev_queue_release (uint16_t dev_id,uint16_t vq_id); + +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction; +/**< Associated transfer direction */
Please, put comments before the code if comment is in a separate line.
Quoted 299 lines
lib/dmadev/rte_dmadev.h new file +299
-0+uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */ +uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve information of a DMA virt queue. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue which return by queue setup. +* @param[out] info +* The queue info structure encapsulated into rte_dmadev_queue_info object. +* +* @return +* - =0: Successful retrieve information. +* - <0: Error code returned by the driver queue release function. +*/ +__rte_experimental +int +rte_dmadev_queue_info_get (uint16_t dev_id,uint16_t vq_id, +struct rte_dmadev_queue_info *info); + +#include "rte_dmadev_core.h" + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a copy operation onto the DMA virt queue. +* +* This queues up a copy operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param src +* The address of the source buffer. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the data to be copied. +* @param flags +* An opaque flags for this operation. +* +* @return +* dma_cookie_t: please refer to the corresponding definition. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy (uint16_t dev_id,uint16_t vq_id,void *src,void *dst, +uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy)(dev, vq_id, src, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list copy operation onto the DMA virt queue. +* +* This queues up a scatter list copy operation to be performed by hardware, +* but does not trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param sg +* The pointer of scatterlist. +* @param sg_len +* The number of scatterlist elements. +* @param flags +* An opaque flags for this operation. +* +* @return +* dma_cookie_t: please refer to the corresponding definition. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy_sg)(dev, vq_id, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the DMA virt queue +* +* This queues up a fill operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the destination buffer. +* @param flags +* An opaque flags for this operation. +* +* @return +* dma_cookie_t: please refer to the corresponding definition. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline dma_cookie_t +rte_dmadev_fill (uint16_t dev_id,uint16_t vq_id,uint64_t pattern, +void *dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fill)(dev, vq_id, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list fill operation onto the DMA virt queue +* +* This queues up a scatter list fill operation to be performed by hardware, +* but does not trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param sg +* The pointer of scatterlist. +* @param sg_len +* The number of scatterlist elements. +* @param flags +* An opaque flags for this operation. +* +* @return +* dma_cookie_t: please refer to the corresponding definition. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline dma_cookie_t +rte_dmadev_fill_sg (uint16_t dev_id,uint16_t vq_id,uint64_t pattern, +const struct dma_scatterlist *sg,uint32_t sg_len, +uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fill_sg)(dev, vq_id, pattern, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add a fence to force ordering between operations +* +* This adds a fence to a sequence of operations to enforce ordering, such that +* all operations enqueued before the fence must be completed before operations +* after the fence. +* NOTE: Since this fence may be added as a flag to the last operation enqueued, +* this API may not function correctly when called immediately after an +* "rte_dmadev_perform" call i.e. before any new operations are enqueued. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful add fence. +* - <0: Failure to add fence. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successful completed. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] cookie +* The last completed operation's cookie. +* @param[out] has_error +* Indicates if there are transfer error. +* +* @return +* The number of operations that successful completed. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_cpls, +dma_cookie_t *cookie,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + has_error = false; +return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param nb_status +* Indicates the size of status array. +* @param[out] status +* The error code of operations that failed to complete. +* @param[out] cookie +* The last failed completed operation's cookie. +* +* @return +* The number of operations that failed to complete. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id,
lib/dmadev/rte_dmadev.h line 757
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ const uint16_t nb_status, uint32_t *status, + dma_cookie_t *cookie) +{ + struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */
Please, put comments before the code.
Quoted 172 lines
lib/dmadev/rte_dmadev.h new file +162
-0+uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ +uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve basic statistics of a or all DMA virt queue(s). +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue, -1 means all virt queues. +* @param[out] stats +* The basic statistics structure encapsulated into rte_dmadev_stats +* object. +* +* @return +* - =0: Successful retrieve stats. +* - <0: Failure to retrieve stats. +*/ +__rte_experimental +int +rte_dmadev_stats_get (uint16_t dev_id,int vq_id, +struct rte_dmadev_stats *stats); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset basic statistics of a or all DMA virt queue(s). +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue, -1 means all virt queues. +* +* @return +* - =0: Successful retrieve stats. +* - <0: Failure to retrieve stats. +*/ +__rte_experimental +int +rte_dmadev_stats_reset (uint16_t dev_id,int vq_id); + +/** Maximum name length for extended statistics counters */ +#define RTE_DMA_DEV_XSTATS_NAME_SIZE 64 + +/** +* A name-key lookup element for extended statistics. +* +* This structure is used to map between names and ID numbers +* for extended ethdev statistics. +*/ +struct rte_dmadev_xstats_name { +char name[RTE_DMA_DEV_XSTATS_NAME_SIZE ]; +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve names of extended statistics of a DMA device. +* +* @param dev_id +* The identifier of the device. +* @param[out] xstats_names +* Block of memory to insert names into. Must be at least size in capacity. +* If set to NULL, function returns required capacity. +* @param size +* Capacity of xstats_names (number of names). +* @return +* - positive value lower or equal to size: success. The return value +* is the number of entries filled in the stats table. +* - positive value higher than size: error, the given statistics table +* is too small. The return value corresponds to the size that should +* be given to succeed. The entries in the table are not valid and +* shall not be used by the caller. +* - negative value on error. +*/ +__rte_experimental +int +rte_dmadev_xstats_names_get (uint16_t dev_id, +struct rte_dmadev_xstats_name *xstats_names, +uint32_t size); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve extended statistics of a DMA device. +* +* @param dev_id +* The identifier of the device. +* @param ids +* The id numbers of the stats to get. The ids can be got from the stat +* position in the stat list from rte_dmadev_get_xstats_names(). +* @param[out] values +* The values for each stats request by ID. +* @param n +* The number of stats requested. +* +* @return +* - positive value: number of stat entries filled into the values array. +* - negative value on error. +*/ +__rte_experimental +int +rte_dmadev_xstats_get (uint16_t dev_id,const uint32_t ids[], +uint64_t values[],uint32_t n); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset the values of the xstats of the selected component in the device. +* +* @param dev_id +* The identifier of the device. +* @param ids +* Selects specific statistics to be reset. When NULL, all statistics +* will be reset. If non-NULL, must point to array of at least +* *nb_ids* size. +* @param nb_ids +* The number of ids available from the *ids* array. Ignored when ids is NULL. +* +* @return +* - zero: successfully reset the statistics to zero. +* - negative value on error. +*/ +__rte_experimental +int +rte_dmadev_xstats_reset (uint16_t dev_id,const uint32_t ids[],uint32_t nb_ids); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger the dmadev self test. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - 0: Selftest successful. +* - -ENOTSUP if the device doesn't support selftest +* - other values < 0 on failure. +*/ +__rte_experimental +int +rte_dmadev_selftest (uint16_t dev_id); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_H_ */ lib/dmadev/rte_dmadev_core.h new file +4
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ +
lib/dmadev/rte_dmadev_core.h line 14
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* +* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions.
Do we really want it? Anyway rte_dmadev must not be here. Some sub-structure could be, but not entire rte_dmadev.
lib/dmadev/rte_dmadev_core.h line 22
Quoted 8 lines
lib/dmadev/rte_dmadev_core.h new file +8
-0+*/ + +struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +void *src,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */
Avoid comments after the code in a seprate line. Move it to be before the code.
Quoted 31 lines
lib/dmadev/rte_dmadev_core.h new file +31
-0+ +typedef dma_cookie_t (*dmadev_copy_sg_t )(struct rte_dmadev *dev,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags); +/**< @internal Function used to enqueue a scatter list copy operation. */ + +typedef dma_cookie_t (*dmadev_fill_t )(struct rte_dmadev *dev,uint16_t vq_id, +uint64_t pattern,void *dst, +uint32_t length,uint64_t flags); +/**< @internal Function used to enqueue a fill operation. */ + +typedef dma_cookie_t (*dmadev_fill_sg_t )(struct rte_dmadev *dev,uint16_t vq_id, +uint64_t pattern,const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags); +/**< @internal Function used to enqueue a scatter list fill operation. */ + +typedef int (*dmadev_fence_t )(struct rte_dmadev *dev,uint16_t vq_id); +/**< @internal Function used to add a fence ordering between operations. */ + +typedef int (*dmadev_perform_t )(struct rte_dmadev *dev,uint16_t vq_id); +/**< @internal Function used to trigger hardware to begin performing. */ + +typedef uint16_t (*dmadev_completed_t )(struct rte_dmadev *dev,uint16_t vq_id, +const uint16_t nb_cpls, +dma_cookie_t *cookie,bool *has_error); +/**< @internal Function used to return number of successful completed operations */ + +typedef uint16_t (*dmadev_completed_fails_t )(struct rte_dmadev *dev, +uint16_t vq_id,const uint16_t nb_status, +uint32_t *status,dma_cookie_t *cookie); +/**< @internal Function used to return number of failed completed operations */
lib/dmadev/rte_dmadev_core.h line 63
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+ +#define RTE_DMADEV_NAME_MAX_LEN 64/**< Max length of name of DMA PMD */ + +struct rte_dmadev_ops ; + +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */
Comment before code should start from /** (not /**< ).
Quoted 13 lines
lib/dmadev/rte_dmadev_core.h new file +13
-0+dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence; +/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed;
lib/dmadev/rte_dmadev_core.h line 86
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails; + +void *dev_private;/**< PMD-specific private data */ +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD */ + +uint16_t dev_id;/**< Device ID for this instance */ +int socket_id;/**< Socket ID where memory is allocated */ +struct rte_device *device; +/**< Device info. supplied during device initialization */
Please, put comments before the code if comment is in a separate line.
lib/dmadev/rte_dmadev_pmd.h
Quoted 13 lines
lib/dmadev/rte_dmadev_core.h new file +12
-0+const char *driver_name;/**< Driver info. supplied by probing */ +char name[RTE_DMADEV_NAME_MAX_LEN ];/**< Device name */ + +RTE_STD_C11 + uint8_t attached : 1; /**< Flag indicating the device is attached */ + uint8_t started : 1; /**< Device state: STARTED(1)/STOPPED(0) */ + +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; + +#endif /* _RTE_DMADEV_CORE_H_ */ lib/dmadev/rte_dmadev_pmd.h +0
-0
Let's remove rte_ prefix from DPDK internal headers.
Quoted 25 lines
new file mode 100644
index 0000000..ef03cf7lib/dmadev/rte_dmadev_pmd.h new file +20
-0@@ -0,0 +1,210 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_PMD_H_ +#define _RTE_DMADEV_PMD_H_ + +/** @file + * RTE DMA PMD APIs + * + * @note + * Driver facing APIs for a DMA device. These are not to be called directly by + * any application. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <string.h>
lib/dmadev/rte_dmadev_pmd.h line 30
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+ +#include <rte_dev.h> +#include <rte_log.h> +#include <rte_common.h> + +#include "rte_dmadev.h" + +extern int libdmadev_logtype; + +#define RTE_DMADEV_LOG(level, fmt, args...) \
Do we need RTE_ prefix for internal API?
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+ rte_log(RTE_LOG_ ## level, libdmadev_logtype, "%s(): " fmt "\n", \ + __func__, ##args) + +/* Macros to check for valid device */ +#define RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, retval) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \ + return retval; \ + } \ +} while (0)
lib/dmadev/rte_dmadev_pmd.h line 50
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+ +#define RTE_DMADEV_VALID_DEVID_OR_RET (dev_id) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \ + return; \ + } \ +} while (0) + +#define RTE_DMADEV_DETACHED 0 +#define RTE_DMADEV_ATTACHED 1
Do we really need RTE_ prefix for interlal defines?
lib/dmadev/rte_dmadev_pmd.h line 61
Quoted 11 lines
lib/dmadev/rte_dmadev_pmd.h new file +11
-0+ +/** +* Validate if the DMA device index is a valid attached DMA device. +* +* @param dev_id +* DMA device index. +* +* @return +* - If the device index is valid (1) or not (0). +*/ +static inline unsigned
'unsigned int', but it sounds like the function should return 'bool'.
lib/dmadev/rte_dmadev_pmd.h line 62
Quoted 1 line
lib/dmadev/rte_dmadev_pmd.h new file +1
-0+rte_dmadev_pmd_is_valid_dev(uint16_t dev_id)
Again, do we really need rte_ prefix for internal functions?
Quoted 12 lines
lib/dmadev/rte_dmadev_pmd.h new file +12
-0+{ +struct rte_dmadev *dev; + +if (dev_id >=RTE_DMADEV_MAX_DEVS ) +return 0 ; + + dev = &rte_dmadevices[dev_id]; +if (dev->attached !=RTE_DMADEV_ATTACHED ) +return 0 ; +else +return 1 ; +}
lib/dmadev/rte_dmadev_pmd.h line 84
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+ +/** +* Definitions of control-plane functions exported by a driver through the +* generic structure of type *rte_dmadev_ops* supplied in the *rte_dmadev* +* structure associated with a device. +*/ + +typedef int (*dmadev_info_get_t )(struct rte_dmadev *dev, +struct rte_dmadev_info *dev_info); +/**< @internal Function used to get device information of a device. */
Let's don't use documentation after code in a separate line in a new code.
Quoted 37 lines
lib/dmadev/rte_dmadev_pmd.h new file +37
-0+ +typedef int (*dmadev_configure_t )(struct rte_dmadev *dev, +const struct rte_dmadev_conf *dev_conf); +/**< @internal Function used to configure a device. */ + +typedef int (*dmadev_start_t )(struct rte_dmadev *dev); +/**< @internal Function used to start a configured device. */ + +typedef int (*dmadev_stop_t )(struct rte_dmadev *dev); +/**< @internal Function used to stop a configured device. */ + +typedef int (*dmadev_close_t )(struct rte_dmadev *dev); +/**< @internal Function used to close a configured device. */ + +typedef int (*dmadev_reset_t )(struct rte_dmadev *dev); +/**< @internal Function used to reset a configured device. */ + +typedef int (*dmadev_queue_setup_t )(struct rte_dmadev *dev, +const struct rte_dmadev_queue_conf *conf); +/**< @internal Function used to allocate and set up a virt queue. */ + +typedef int (*dmadev_queue_release_t )(struct rte_dmadev *dev,uint16_t vq_id); +/**< @internal Function used to release a virt queue. */ + +typedef int (*dmadev_queue_info_t )(struct rte_dmadev *dev,uint16_t vq_id, +struct rte_dmadev_queue_info *info); +/**< @internal Function used to retrieve information of a virt queue. */ + +typedef int (*dmadev_stats_get_t )(struct rte_dmadev *dev,int vq_id, +struct rte_dmadev_stats *stats); +/**< @internal Function used to retrieve basic statistics. */ + +typedef int (*dmadev_stats_reset_t )(struct rte_dmadev *dev,int vq_id); +/**< @internal Function used to reset basic statistics. */ + +typedef int (*dmadev_xstats_get_names_t)(const struct rte_dmadev *dev, + struct rte_dmadev_xstats_name *xstats_names,
lib/dmadev/rte_dmadev_pmd.h line 131
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+ uint32_t size); +/**< @internal Function used to get names of extended stats. */ + +typedef int (*dmadev_xstats_get_t )(const struct rte_dmadev *dev, +const uint32_t ids[],uint64_t values[],uint32_t n); +/**< @internal Function used to retrieve extended stats. */ + +typedef int (*dmadev_xstats_reset_t )(struct rte_dmadev *dev, +const uint32_t ids[],uint32_t nb_ids); +/**< @internal Function used to reset extended stats. */
Do we really need both stats and xstats from the very beginning? I think it is better to start from just generic stats and add xstats when it is really required.
lib/dmadev/rte_dmadev_pmd.h line 137
Quoted 6 lines
lib/dmadev/rte_dmadev_pmd.h new file +6
-0+ +typedef int (*dmadev_selftest_t )(uint16_t dev_id); +/**< @internal Function used to start dmadev selftest. */ + +/** DMA device operations function pointer table */ +struct rte_dmadev_ops {
Do we need rte_ prefiix for internal data types?
Quoted 37 lines
lib/dmadev/rte_dmadev_pmd.h new file +37
-0+/**< Get device info. */ +dmadev_info_get_t dev_info_get; +/**< Configure device. */ +dmadev_configure_t dev_configure; +/**< Start device. */ +dmadev_start_t dev_start; +/**< Stop device. */ +dmadev_stop_t dev_stop; +/**< Close device. */ +dmadev_close_t dev_close; +/**< Reset device. */ +dmadev_reset_t dev_reset; + +/**< Allocate and set up a virt queue. */ +dmadev_queue_setup_t queue_setup; +/**< Release a virt queue. */ +dmadev_queue_release_t queue_release; +/**< Retrieve information of a virt queue */ +dmadev_queue_info_t queue_info_get; + +/**< Get basic statistics. */ +dmadev_stats_get_t stats_get; +/**< Reset basic statistics. */ +dmadev_stats_reset_t stats_reset; +/**< Get names of extended stats. */ +dmadev_xstats_get_names_t xstats_get_names; +/**< Get extended statistics. */ +dmadev_xstats_get_t xstats_get; +/**< Reset extended statistics values. */ +dmadev_xstats_reset_t xstats_reset; + +/**< Device selftest function */ +dmadev_selftest_t dev_selftest; +}; + +/** +* Allocates a new dmadev slot for an DMA device and returns the pointer
lib/dmadev/rte_dmadev_pmd.h line 184
Quoted 10 lines
lib/dmadev/rte_dmadev_pmd.h new file +10
-0+* to that slot for the driver to use. +* +* @param name +* Unique identifier name for each device +* @param dev_private_size +* Size of private data memory allocated within rte_dmadev object. +* Set to 0 to disable internal memory allocation and allow for +* self-allocation. +* @param socket_id +* Socket to allocate resources on.
It should be numa_node. See recent mails from Thomas M.
lib/dmadev/rte_dmadev_pmd.h line 195
Quoted 11 lines
lib/dmadev/rte_dmadev_pmd.h new file +11
-0+* +* @return +* - NULL: Failure to allocate +* - Other: The rte_dmadev structure pointer for the new device +*/ +struct rte_dmadev * +rte_dmadev_pmd_allocate (const char *name,size_t dev_private_size, +int socket_id); + +/** +* Release the specified dmadev device.
"dmadev device" sounds strange. May be "DMA device"?
Quoted 15 lines
lib/dmadev/rte_dmadev_pmd.h new file +15
-0+* +* @param dev +* The *dmadev* pointer is the address of the *rte_dmadev* structure. +* +* @return +* - 0 on success, negative on error +*/ +int +rte_dmadev_pmd_release (struct rte_dmadev *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_PMD_H_ */
[snip]
Many thanks, mostly OK, a few comment inline
Quoted 3 lines · Andrew Rybchenko
Quoted 2 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
[snip]
Quoted 5 lines
Quoted 5 lines
lib/dmadev/rte_dmadev_core.h new file +5
-0+#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file
Quoted 9 lines
Quoted 5 lines
+ *
+ * RTE DMA Device internal header.
+ *
+ * This header contains internal data types. But they are still part of the
+ * public API because they are used by inline public functions.Do we really want it? Anyway
rte_dmadevmust not be here. Some sub-structure could be, but not entirerte_dmadev.
struct rte_dmadev should expose to public for device probe and etc. and because the public dataplane function use static inline to embellish, should put the rte_dmadevices to public file too.
PS: it widely used in eth/regexdev...
Quoted 7 lines
lib/dmadev/rte_dmadev_pmd.h
Quoted 5 lines
lib/dmadev/rte_dmadev_core.h new file +4
-0+ +extern struct rte_dmadev rte_dmadevices[]; + +#endif /* _RTE_DMADEV_CORE_H_ */ lib/dmadev/rte_dmadev_pmd.h +0
-0Let's remove
rte_prefix from DPDK internal headers.
as above explained, it's public header file.
Quoted 19 lines
lib/dmadev/rte_dmadev_pmd.h line 30
Quoted 2 lines
lib/dmadev/rte_dmadev_pmd.h +2
-0+ +#define RTE_DMADEV_LOG(level, fmt, args...) \Do we need
RTE_prefix for internal API?Quoted 14 lines
lib/dmadev/rte_dmadev_pmd.h +14
-0+ rte_log(RTE_LOG_ ## level, libdmadev_logtype, "%s(): " fmt "\n", \ + __func__, ##args) + +/* Macros to check for valid device */ +#define RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, retval) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \ + return retval; \ + } \ +} while (0) + +#define RTE_DMADEV_VALID_DEVID_OR_RET (dev_id) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \
Quoted 8 lines
lib/dmadev/rte_dmadev_pmd.h line 50
Quoted 6 lines
lib/dmadev/rte_dmadev_pmd.h +6
-0+return ; \ + } \ +} while (0) + +#define RTE_DMADEV_DETACHED 0 +#define RTE_DMADEV_ATTACHED 1Do we really need
RTE_prefix for interlal defines?
with RTE_ prefix will reduce namespace conflicts.
it's same as it lib/eth or regexdev...
Quoted 7 lines
lib/dmadev/rte_dmadev_pmd.h line 131
Quoted 3 lines
lib/dmadev/rte_dmadev_pmd.h +3
-0+typedef int (*dmadev_xstats_reset_t )(struct rte_dmadev *dev, +const uint32_t ids[],uint32_t nb_ids); +/**< @internal Function used to reset extended stats. */ Do we really need both stats and xstats from the very beginning? I think it is better to start from just generic stats and add xstats when it is really required.
OK, but I think we should add one dump ops, which could be useful to find the problem.
Quoted 2 lines
.
Quoted 6 lines · fengchengwen
Many thanks, mostly OK, a few comment inline
Quoted 3 lines · Andrew Rybchenko
Quoted 2 lines · Chengwen Feng
This patch introduces 'dmadevice' which is a generic type of DMA device.
<snip>
Quoted 7 lines
Quoted 3 lines
Do we really need both stats and xstats from the very beginning? I think it is better to start from just generic stats and add xstats when it is really required.
OK, but I think we should add one dump ops, which could be useful to find the problem.
+1 to both suggestions - dropping xstats (for now) and adding dump fn.
From: Chengwen Feng
Quoted 6 lines
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Did you consider RTE_COMP_ALGO_NULL xform in compressdev library?
Quoted 1,061 lines
Signed-off-by Chengwen Feng <[email protected]>--- MAINTAINERS | 4 + config/rte_config.h | 3 + lib/dmadev/meson.build | 6 + lib/dmadev/rte_dmadev.c | 438 +++++++++++++++++++++ lib/dmadev/rte_dmadev.h | 919 +++++++++++++++++++++++++++++++++++++++++++ lib/dmadev/rte_dmadev_core.h | 98 +++++ lib/dmadev/rte_dmadev_pmd.h | 210 ++++++++++ lib/dmadev/version.map | 32 ++ lib/meson.build | 1 + 9 files changed, 1711 insertions(+) create mode 100644 lib/dmadev/meson.build create mode 100644 lib/dmadev/rte_dmadev.c create mode 100644 lib/dmadev/rte_dmadev.h create mode 100644 lib/dmadev/rte_dmadev_core.h create mode 100644 lib/dmadev/rte_dmadev_pmd.h create mode 100644 lib/dmadev/version.mapMAINTAINERS +4
-0@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst +Dma device API +M: Chengwen Feng <[email protected]> +F: lib/dmadev/ + Memory Pool Drivers -------------------config/rte_config.h +3
-0@@ -81,6 +81,9 @@/* rawdev defines */ #define RTE_RAWDEV_MAX_DEVS 64 +/* dmadev defines */ +#define RTE_DMADEV_MAX_DEVS 64 +/* ip_fragmentation defines */ #define RTE_LIBRTE_IP_FRAG_MAX_FRAG 4#undef RTE_LIBRTE_IP_FRAG_TBL_STATlib/dmadev/meson.build new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2021 HiSilicon Limited. + +sources = files('rte_dmadev.c') +headers = files('rte_dmadev.h', 'rte_dmadev_pmd.h') +indirect_headers += files('rte_dmadev_core.h')lib/dmadev/rte_dmadev.c new file +76
-0@@ -0,0 +1,438 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> + +#include <rte_log.h> +#include <rte_debug.h> +#include <rte_dev.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_malloc.h> +#include <rte_errno.h> +#include <rte_string_fns.h> + +#include "rte_dmadev.h" +#include "rte_dmadev_pmd.h" + +struct rte_dmadev rte_dmadevices[RTE_DMADEV_MAX_DEVS ]; + +uint16_t +rte_dmadev_count (void ) +{ +uint16_t count =0 ; +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (rte_dmadevices[i].attached) + count++; + } + +return count; +} + +int +rte_dmadev_get_dev_id (const char *name) +{ +uint16_t i; + +if (name ==NULL ) +return -EINVAL ; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) +if ((strcmp (rte_dmadevices[i].name, name) ==0 ) && + (rte_dmadevices[i].attached ==RTE_DMADEV_ATTACHED )) +return i; + +return -ENODEV ; +} + +int +rte_dmadev_socket_id (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +return dev->socket_id; +} + +int +rte_dmadev_info_get (uint16_t dev_id,struct rte_dmadev_info *dev_info) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_info, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_info_get, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +15
-0+ +memset (dev_info,0 ,sizeof (struct rte_dmadev_info )); + diag = (*dev->dev_ops->dev_info_get)(dev, dev_info); +if (diag !=0 ) +return diag; + + dev_info->device = dev->device; + dev_info->driver_name = dev->driver_name; + dev_info->socket_id = dev->socket_id; + +return 0 ; +} + +int +rte_dmadev_configure(uint16_t dev_id, const struct rte_dmadev_conf
*dev_conf)lib/dmadev/rte_dmadev.c new file +10
-0+{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_conf, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +10
-0+ +if (dev->started) { +RTE_DMADEV_LOG (ERR , +"device %u must be stopped to allow configuration" , dev_id); +return -EBUSY ; + } + + diag = (*dev->dev_ops->dev_configure)(dev, dev_conf); +if (diag !=0 ) + RTE_DMADEV_LOG(ERR, "device %u dev_configure failed, ret =%d",
lib/dmadev/rte_dmadev.c new file +74
-0+ dev_id, diag); + else + dev->attached = 1; + +return diag; +} + +int +rte_dmadev_start (uint16_t dev_id) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; +if (dev->started !=0 ) { +RTE_DMADEV_LOG (ERR ,"device %u already started" , dev_id); +return 0 ; + } + +if (dev->dev_ops->dev_start ==NULL ) + goto mark_started; + + diag = (*dev->dev_ops->dev_start)(dev); +if (diag !=0 ) +return diag; + +mark_started: + dev->started =1 ; +return 0 ; +} + +int +rte_dmadev_stop (uint16_t dev_id) +{ +struct rte_dmadev *dev; +int diag; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +if (dev->started ==0 ) { +RTE_DMADEV_LOG (ERR ,"device %u already stopped" , dev_id); +return 0 ; + } + +if (dev->dev_ops->dev_stop ==NULL ) + goto mark_stopped; + + diag = (*dev->dev_ops->dev_stop)(dev); +if (diag !=0 ) +return diag; + +mark_stopped: + dev->started =0 ; +return 0 ; +} + +int +rte_dmadev_close (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_close, -ENOTSUP ); + +/* Device must be stopped before it can be closed */ +if (dev->started ==1 ) { + RTE_DMADEV_LOG(ERR, "device %u must be stopped beforeclosing",
lib/dmadev/rte_dmadev.c new file +34
-0+ dev_id); +return -EBUSY ; + } + +return (*dev->dev_ops->dev_close)(dev); +} + +int +rte_dmadev_reset (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_reset, -ENOTSUP ); + +/* Reset is not dependent on state of the device */ +return (*dev->dev_ops->dev_reset)(dev); +} + +int +rte_dmadev_queue_setup (uint16_t dev_id, +const struct rte_dmadev_queue_conf *conf) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (conf, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +14
-0+ +return (*dev->dev_ops->queue_setup)(dev, conf); +} + +int +rte_dmadev_queue_release (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +16
-0+ +return (*dev->dev_ops->queue_release)(dev, vq_id); +} + +int +rte_dmadev_queue_info_get (uint16_t dev_id,uint16_t vq_id, +struct rte_dmadev_queue_info *info) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (info, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_info_get, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +31
-0+ +memset (info,0 ,sizeof (struct rte_dmadev_queue_info )); +return (*dev->dev_ops->queue_info_get)(dev, vq_id, info); +} + +int +rte_dmadev_stats_get (uint16_t dev_id,int vq_id, +struct rte_dmadev_stats *stats) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (stats, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->stats_get, -ENOTSUP ); + +return (*dev->dev_ops->stats_get)(dev, vq_id, stats); +} + +int +rte_dmadev_stats_reset (uint16_t dev_id,int vq_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +10
-0+ +return (*dev->dev_ops->stats_reset)(dev, vq_id); +} + +static int +xstats_get_count (uint16_t dev_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->xstats_get_names, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +23
-0+ +return (*dev->dev_ops->xstats_get_names)(dev,NULL ,0 ); +} + +int +rte_dmadev_xstats_names_get (uint16_t dev_id, +struct rte_dmadev_xstats_name *xstats_names, +uint32_t size) +{ +struct rte_dmadev *dev; +int cnt_expected_entries; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + cnt_expected_entries =xstats_get_count (dev_id); + +if (xstats_names ==NULL || cnt_expected_entries <0 || + (int )size < cnt_expected_entries || size ==0 ) +return cnt_expected_entries; + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->xstats_get_names, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +16
-0+return (*dev->dev_ops->xstats_get_names)(dev, xstats_names, size); +} + +int +rte_dmadev_xstats_get (uint16_t dev_id,const uint32_t ids[], +uint64_t values[],uint32_t n) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (ids, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (values, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->xstats_get, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +6
-0+ +return (*dev->dev_ops->xstats_get)(dev, ids, values, n); +} + +int +rte_dmadev_xstats_reset(uint16_t dev_id, const uint32_t ids[], uint32_t
nb_ids)lib/dmadev/rte_dmadev.c new file +8
-0+{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->xstats_reset, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +14
-0+ +return (*dev->dev_ops->xstats_reset)(dev, ids, nb_ids); +} + +int +rte_dmadev_selftest (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_selftest, -ENOTSUP);
lib/dmadev/rte_dmadev.c new file +19
-0+ +return (*dev->dev_ops->dev_selftest)(dev_id); +} + +static inline uint16_t +rte_dmadev_find_free_device_index (void ) +{ +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (rte_dmadevices[i].attached ==RTE_DMADEV_DETACHED ) +return i; + } + +return RTE_DMADEV_MAX_DEVS ; +} + +struct rte_dmadev * +rte_dmadev_pmd_allocate(const char *name, size_t dev_priv_size, int
socket_id)lib/dmadev/rte_dmadev.c new file +13
-0+{ +struct rte_dmadev *dev; +uint16_t dev_id; + +if (rte_dmadev_get_dev_id (name) >=0 ) { +RTE_DMADEV_LOG (ERR , +"device with name %s already allocated!" , name); +return NULL ; + } + + dev_id =rte_dmadev_find_free_device_index (); +if (dev_id ==RTE_DMADEV_MAX_DEVS ) { + RTE_DMADEV_LOG(ERR, "reached maximum number of DMAdevices");
lib/dmadev/rte_dmadev.c new file +49
-0+return NULL ; + } + + dev = &rte_dmadevices[dev_id]; + +if (dev_priv_size >0 ) { + dev->dev_private =rte_zmalloc_socket ("dmadev private" , + dev_priv_size, +RTE_CACHE_LINE_SIZE , + socket_id); +if (dev->dev_private ==NULL ) { +RTE_DMADEV_LOG (ERR , +"unable to allocate memory for dmadev" ); +return NULL ; + } + } + + dev->dev_id = dev_id; + dev->socket_id = socket_id; + dev->started =0 ; +strlcpy (dev->name, name,RTE_DMADEV_NAME_MAX_LEN ); + + dev->attached =RTE_DMADEV_ATTACHED ; + +return dev; +} + +int +rte_dmadev_pmd_release (struct rte_dmadev *dev) +{ +int ret; + +if (dev ==NULL ) +return -EINVAL ; + + ret =rte_dmadev_close (dev->dev_id); +if (ret !=0 ) +return ret; + +if (dev->dev_private !=NULL ) +rte_free (dev->dev_private); + +memset (dev,0 ,sizeof (struct rte_dmadev )); + dev->attached =RTE_DMADEV_DETACHED ; + +return 0 ; +} + +RTE_LOG_REGISTER (libdmadev_logtype, lib.dmadev,INFO );lib/dmadev/rte_dmadev.h new file +25
-0@@ -0,0 +1,919 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_H_ +#define _RTE_DMADEV_H_ + +/** +* @file rte_dmadev.h +* +* RTE DMA (Direct Memory Access) device APIs. +* +* The generic DMA device diagram: +* +* ------------ ------------ +* | HW-queue | | HW-queue | +* ------------ ------------ +* \ / +* \ / +* \ / +* ---------------- +* |dma-controller| +* ---------------- +* +* The DMA could have multiple HW-queues, each HW-queue could have multiple
+ * capabilities, e.g. whether to support fill operation, supported DMA
+ * transfter direction and etc.
+ *
+ * The DMA framework is built on the following abstraction model:
+ *+ * ------------ ------------ + * |virt-queue| |virt-queue| + * ------------ ------------ + * \ / + * \ / + * \ / + * ------------ ------------ + * | HW-queue | | HW-queue | + * ------------ ------------ + * \ / + * \ / + * \ / + * ---------- + * | dmadev | + * ----------+ *
+ * a) The DMA operation request must be submitted to the virt queue, virt
+ * queues must be created based on HW queues, the DMA device could
have
+ * multiple HW queues.
+ * b) The virt queues on the same HW-queue could represent different
contexts,+ * e.g. user could create virt-queue-0 on HW-queue-0 for mem-to-mem + * transfer scenario, and create virt-queue-1 on the same HW-queue for + * mem-to-dev transfer scenario.+ * NOTE: user could also create multiple virt queues for mem-to-mem
transfer
+ * scenario as long as the corresponding driver supports.
+ *
+ * The control plane APIs include configure/queue_setup/queue_release/start/
+ * stop/reset/close, in order to start device work, the call sequence must be
+ * as follows:+ * - rte_dmadev_configure() + * - rte_dmadev_queue_setup() + * - rte_dmadev_start() + * + * The dataplane APIs include two parts: + * a) The first part is the submission of operation requests: + * - rte_dmadev_copy() + * - rte_dmadev_copy_sg() - scatter-gather form of copy + * - rte_dmadev_fill() + * - rte_dmadev_fill_sg() - scatter-gather form of fill + * - rte_dmadev_fence() - add a fence force ordering between operations + * - rte_dmadev_perform() - issue doorbell to hardware + * These APIs could work with different virt queues which have different + * contexts. + * The first four APIs are used to submit the operation request to the virt + * queue, if the submission is successful, a cookie (as type + * 'dma_cookie_t') is returned, otherwise a negative number is returned.+ * b) The second part is to obtain the result of requests:
+ * -rte_dmadev_completed()
+ * - return the number of operation requests completed successfully.
+ * -rte_dmadev_completed_fails()
+ * - return the number of operation requests failed to complete.
+ *
+ * The misc APIs include info_get/queue_info_get/stats/xstats/selftest, provide
+ * information query and self-test capabilities.
+ *
+ * About the dataplane APIs MT-safe, there are two dimensions:
+ * a) For one virt queue, the submit/completion API could be MT-safe,+ * e.g. one thread do submit operation, another thread do completion + * operation. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe. + * b) For multiple virt queues on the same HW queue, e.g. one thread do + * operation on virt-queue-0, another thread do operation on virt-queue- 1. + * If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MVQ. + * If driver don't support it, it's up to the application to guarantee + * MT-safe.+ */
lib/dmadev/rte_dmadev.h new file +18
-0+ +#ifdef __cplusplus +extern "C" { +#endif + +#include <rte_common.h> +#include <rte_memory.h> +#include <rte_errno.h> +#include <rte_compat.h> + +/** +* dma_cookie_t - an opaque DMA cookie +* +* If dma_cookie_t is >=0 it's a DMA operation request cookie, <0 it's a error +* code. +* When using cookies, comply with the following rules: +* a) Cookies for each virtual queue are independent. +* b) For a virt queue, the cookie are monotonically incremented, when it reach
+ * theINT_MAX, it wraps back to zero.
+ * c) The initial cookie of a virt queue is zero, after the device is stopped or
+ * reset, the virt queue's cookie needs to be reset to zero.
+ * Example:+ * step-1: start one dmadev + * step-2: enqueue a copy operation, the cookie return is 0 + * step-3: enqueue a copy operation again, the cookie return is 1 + * ... + * step-101: stop the dmadev + * step-102: start the dmadev + * step-103: enqueue a copy operation, the cookie return is 0 + * ...+ */
lib/dmadev/rte_dmadev.h new file +64
-0+typedef int32_t dma_cookie_t ; + +/** +* dma_scatterlist - can hold scatter DMA operation request +*/ +struct dma_scatterlist { +void *src; +void *dst; +uint32_t length; +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Get the total number of DMA devices that have been successfully +* initialised. +* +* @return +* The total number of usable DMA devices. +*/ +__rte_experimental +uint16_t +rte_dmadev_count (void ); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Get the device identifier for the named DMA device. +* +* @param name +* DMA device name to select the DMA device identifier. +* +* @return +* Returns DMA device identifier on success. +* - <0: Failure to find named DMA device. +*/ +__rte_experimental +int +rte_dmadev_get_dev_id (const char *name); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Return the NUMA socket to which a device is connected. +* +* @param dev_id +* The identifier of the device. +* +* @return +* The NUMA socket id to which the device is connected or +* a default of zero if the socket could not be determined. +* - -EINVAL: dev_id value is out of range. +*/ +__rte_experimental +int +rte_dmadev_socket_id (uint16_t dev_id); + +/** +* The capabilities of a DMA device +*/ +#define RTE_DMA_DEV_CAPA_M2M (1ull << 0)/**< Support mem-to- mem transfer */
+#defineRTE_DMA_DEV_CAPA_M2D(1ull << 1) /**< Support mem-to-dev
transfer */
+#defineRTE_DMA_DEV_CAPA_D2M(1ull << 2) /**< Support dev-to-mem
transfer */
+#defineRTE_DMA_DEV_CAPA_D2D(1ull << 3) /**< Support dev-to-dev
transfer */lib/dmadev/rte_dmadev.h new file +3
-0+#define RTE_DMA_DEV_CAPA_COPY (1ull << 4)/**< Support copy ops */ +#define RTE_DMA_DEV_CAPA_FILL (1ull << 5)/**< Support fill ops */ +#define RTE_DMA_DEV_CAPA_SG (1ull << 6)/**< Support scatter-gather ops */
lib/dmadev/rte_dmadev.h new file +2
-0+#define RTE_DMA_DEV_CAPA_FENCE (1ull << 7)/**< Support fence ops */ +#define RTE_DMA_DEV_CAPA_IOVA (1ull << 8)/**< Support IOVA as DMA address */
+#defineRTE_DMA_DEV_CAPA_VA(1ull << 9) /**< Support VA as DMA
address */
+#defineRTE_DMA_DEV_CAPA_MT_VQ(1ull << 10) /**< Support MT-safe of one virt queue */
+#defineRTE_DMA_DEV_CAPA_MT_MVQ(1ull << 11) /**< Support MT-
safe of multiple virt queues */lib/dmadev/rte_dmadev.h new file +46
-0+ +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +/** +* Fields filled by framewok +*/ +struct rte_device *device;/**< Generic Device information */ +const char *driver_name;/**< Device driver name */ +int socket_id;/**< Socket ID where memory is allocated */ + +/** +* Specification fields filled by driver +*/ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +uint16_t max_hw_queues;/**< Maximum number of HW queues. */ +uint16_t max_vqs_per_hw_queue; +/**< Maximum number of virt queues to allocate per HW queue */ +uint16_t max_desc; +/**< Maximum allowed number of virt queue descriptors */ +uint16_t min_desc; +/**< Minimum allowed number of virt queue descriptors */ + +/** +* Status fields filled by driver +*/ +uint16_t nb_hw_queues;/**< Number of HW queues configured */ +uint16_t nb_vqs;/**< Number of virt queues configured */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve the contextual information of a DMA device. +* +* @param dev_id +* The identifier of the device. +* +* @param[out] dev_info +* A pointer to a structure of type *rte_dmadev_info* to be filled with the +* contextual information of the device. +* @return +* - =0: Success, driver updates the contextual information of the DMA device
+ * - <0: Error code returned by the driver info get function.
+ *
+ */lib/dmadev/rte_dmadev.h new file +3
-0+__rte_experimental +int +rte_dmadev_info_get(uint16_t dev_id, struct rte_dmadev_info
*dev_info);lib/dmadev/rte_dmadev.h new file +35
-0+ +/** +* dma_address_type +*/ +enum dma_address_type { +DMA_ADDRESS_TYPE_IOVA ,/**< Use IOVA as dma address */ +DMA_ADDRESS_TYPE_VA ,/**< Use VA as dma address */ +}; + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +enum dma_address_type addr_type;/**< Address type to used */ +uint16_t nb_hw_queues;/**< Number of HW-queues enable to use */ +uint16_t max_vqs;/**< Maximum number of virt queues to use */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Configure a DMA device. +* +* This function must be invoked first before any other function in the +* API. This function can also be re-invoked when a device is in the +* stopped state. +* +* The caller may use rte_dmadev_info_get() to get the capability of each +* resources available for this DMA device. +* +* @param dev_id +* The identifier of the device to configure. +* @param dev_conf +* The DMA device configuration structure encapsulated into
rte_dmadev_conf
+ * object.
+ *
+ * @return
+ * - =0: Success, device configured.
+ * - <0: Error code returned by the driver configuration function.
+ */lib/dmadev/rte_dmadev.h new file +3
-0+__rte_experimental +int +rte_dmadev_configure(uint16_t dev_id, const struct rte_dmadev_conf
*dev_conf);lib/dmadev/rte_dmadev.h new file +66
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Start a DMA device. +* +* The device start step is the last one and consists of setting the DMA +* to start accepting jobs. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device started. +* - <0: Error code returned by the driver start function. +*/ +__rte_experimental +int +rte_dmadev_start (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Stop a DMA device. +* +* The device can be restarted with a call to rte_dmadev_start() +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device stopped. +* - <0: Error code returned by the driver stop function. +*/ +__rte_experimental +int +rte_dmadev_stop (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Close a DMA device. +* +* The device cannot be restarted after this call. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Successfully closing device +* - <0: Failure to close device +*/ +__rte_experimental +int +rte_dmadev_close (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset a DMA device. +* +* This is different from cycle of rte_dmadev_start->rte_dmadev_stop in the
+ * sense similar to hard or soft reset.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ *
+ * @return+ * - =0: Successful reset device. + * - <0: Failure to reset device. + * - (-ENOTSUP): If the device doesn't support this function.+ */
lib/dmadev/rte_dmadev.h new file +21
-0+__rte_experimental +int +rte_dmadev_reset (uint16_t dev_id); + +/** +* dma_transfer_direction +*/ +enum dma_transfer_direction { +DMA_MEM_TO_MEM , +DMA_MEM_TO_DEV , +DMA_DEV_TO_MEM , +DMA_DEV_TO_DEV , +}; + +/** +* A structure used to configure a DMA virt queue. +*/ +struct rte_dmadev_queue_conf { +enum dma_transfer_direction direction; +/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */
lib/dmadev/rte_dmadev.h new file +15
-0+uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +void *dev_ctx;/**< Device specific context */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Allocate and set up a virt queue. +* +* @param dev_id +* The identifier of the device. +* @param conf +* The queue configuration structure encapsulated into
rte_dmadev_queue_conf
+ * object.
+ *
+ * @return
+ * - >=0: Allocate virt queue success, it is virt queue id.
+ * - <0: Error code returned by the driver queue setup function.
+ */lib/dmadev/rte_dmadev.h new file +31
-0+__rte_experimental +int +rte_dmadev_queue_setup (uint16_t dev_id, +const struct rte_dmadev_queue_conf *conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Release a virt queue. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue which return by queue setup. +* +* @return +* - =0: Successful release the virt queue. +* - <0: Error code returned by the driver queue release function. +*/ +__rte_experimental +int +rte_dmadev_queue_release (uint16_t dev_id,uint16_t vq_id); + +/** +* A structure used to retrieve information of a DMA virt queue. +*/ +struct rte_dmadev_queue_info { +enum dma_transfer_direction direction; +/**< Associated transfer direction */ +uint16_t hw_queue_id;/**< The HW queue on which to create virt queue */
lib/dmadev/rte_dmadev.h new file +16
-0+uint16_t nb_desc;/**< Number of descriptor for this virt queue */ +uint64_t dev_flags;/**< Device specific flags */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve information of a DMA virt queue. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue which return by queue setup. +* @param[out] info +* The queue info structure encapsulated into rte_dmadev_queue_info object.
+ *
+ * @return
+ * - =0: Successful retrieve information.
+ * - <0: Error code returned by the driver queue release function.
+ */lib/dmadev/rte_dmadev.h new file +14
-0+__rte_experimental +int +rte_dmadev_queue_info_get (uint16_t dev_id,uint16_t vq_id, +struct rte_dmadev_queue_info *info); + +#include "rte_dmadev_core.h" + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a copy operation onto the DMA virt queue. +* +* This queues up a copy operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.
+ * @param src
+ * The address of the source buffer.
+ * @param dst
+ * The address of the destination buffer.
+ * @param length
+ * The length of the data to be copied.
+ * @param flags
+ * An opaque flags for this operation.
+ *
+ * @return
+ *dma_cookie_t: please refer to the corresponding definition.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */
lib/dmadev/rte_dmadev.h line 508
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy(uint16_t dev_id, uint16_t vq_id, void *src, void *dst,
Did you consider also mbuf API usage for memory descriptor?
Quoted 810 lines
lib/dmadev/rte_dmadev.h new file +13
-0+ uint32_t length, uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy)(dev, vq_id, src, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list copy operation onto the DMA virt queue. +* +* This queues up a scatter list copy operation to be performed by hardware,
+ * but does not trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.
+ * @param sg
+ * The pointer of scatterlist.
+ * @paramsg_len
+ * The number of scatterlist elements.
+ * @param flags
+ * An opaque flags for this operation.
+ *
+ * @return
+ *dma_cookie_t: please refer to the corresponding definition.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +17
-0+__rte_experimental +static inline dma_cookie_t +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id, +const struct dma_scatterlist *sg, +uint32_t sg_len,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->copy_sg)(dev, vq_id, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the DMA virt queue +* +* This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dst
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An opaque flags for this operation.
+ *
+ * @return
+ *dma_cookie_t: please refer to the corresponding definition.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +54
-0+__rte_experimental +static inline dma_cookie_t +rte_dmadev_fill (uint16_t dev_id,uint16_t vq_id,uint64_t pattern, +void *dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fill)(dev, vq_id, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list fill operation onto the DMA virt queue +* +* This queues up a scatter list fill operation to be performed by hardware, +* but does not trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param pattern +* The pattern to populate the destination buffer with. +* @param sg +* The pointer of scatterlist. +* @param sg_len +* The number of scatterlist elements. +* @param flags +* An opaque flags for this operation. +* +* @return +* dma_cookie_t: please refer to the corresponding definition. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline dma_cookie_t +rte_dmadev_fill_sg (uint16_t dev_id,uint16_t vq_id,uint64_t pattern, +const struct dma_scatterlist *sg,uint32_t sg_len, +uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fill_sg)(dev, vq_id, pattern, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Add a fence to force ordering between operations +* +* This adds a fence to a sequence of operations to enforce ordering, such that
+ * all operations enqueued before the fence must be completed before operations
+ * after the fence.
+ * NOTE: Since this fence may be added as a flag to the last operation enqueued,
+ * this API may not function correctly when called immediately after an
+ * "rte_dmadev_perform" call i.e. before any new operations are enqueued.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.
+ *
+ * @return
+ * - =0: Successful add fence.
+ * - <0: Failure to add fence.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +63
-0+__rte_experimental +static inline int +rte_dmadev_fence (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->fence)(dev, vq_id); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* +* @return +* - =0: Successful trigger hardware. +* - <0: Failure to trigger hardware. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline int +rte_dmadev_perform (uint16_t dev_id,uint16_t vq_id) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->perform)(dev, vq_id); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successful completed. +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] cookie +* The last completed operation's cookie. +* @param[out] has_error +* Indicates if there are transfer error. +* +* @return +* The number of operations that successful completed. +* +* NOTE: The caller must ensure that the input parameter is valid and the +* corresponding device supports the operation. +*/ +__rte_experimental +static inline uint16_t +rte_dmadev_completed(uint16_t dev_id, uint16_t vq_id, const uint16_t
nb_cpls,lib/dmadev/rte_dmadev.h new file +13
-0+ dma_cookie_t *cookie, bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + has_error = false; +return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @paramvq_id
+ * The identifier of virt queue.
+ * @paramnb_status
+ * Indicates the size of status array.
+ * @param[out] status
+ * The error code of operations that failed to complete.
+ * @param[out] cookie
+ * The last failed completed operation's cookie.
+ *
+ * @return
+ * The number of operations that failed to complete.
+ *
+ * NOTE: The caller must ensure that the input parameter is valid and the
+ * corresponding device supports the operation.
+ */lib/dmadev/rte_dmadev.h new file +143
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id, +const uint16_t nb_status,uint32_t *status, +dma_cookie_t *cookie) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +} + +struct rte_dmadev_stats { +uint64_t enqueue_fail_count; +/**< Conut of all operations which failed enqueued */ +uint64_t enqueued_count; +/**< Count of all operations which successful enqueued */ +uint64_t completed_fail_count; +/**< Count of all operations which failed to complete */ +uint64_t completed_count; +/**< Count of all operations which successful complete */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve basic statistics of a or all DMA virt queue(s). +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue, -1 means all virt queues. +* @param[out] stats +* The basic statistics structure encapsulated into rte_dmadev_stats +* object. +* +* @return +* - =0: Successful retrieve stats. +* - <0: Failure to retrieve stats. +*/ +__rte_experimental +int +rte_dmadev_stats_get (uint16_t dev_id,int vq_id, +struct rte_dmadev_stats *stats); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset basic statistics of a or all DMA virt queue(s). +* +* @param dev_id +* The identifier of the device. +* @param vq_id +* The identifier of virt queue, -1 means all virt queues. +* +* @return +* - =0: Successful retrieve stats. +* - <0: Failure to retrieve stats. +*/ +__rte_experimental +int +rte_dmadev_stats_reset (uint16_t dev_id,int vq_id); + +/** Maximum name length for extended statistics counters */ +#define RTE_DMA_DEV_XSTATS_NAME_SIZE 64 + +/** +* A name-key lookup element for extended statistics. +* +* This structure is used to map between names and ID numbers +* for extended ethdev statistics. +*/ +struct rte_dmadev_xstats_name { +char name[RTE_DMA_DEV_XSTATS_NAME_SIZE ]; +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve names of extended statistics of a DMA device. +* +* @param dev_id +* The identifier of the device. +* @param[out] xstats_names +* Block of memory to insert names into. Must be at least size in capacity. +* If set to NULL, function returns required capacity. +* @param size +* Capacity of xstats_names (number of names). +* @return +* - positive value lower or equal to size: success. The return value +* is the number of entries filled in the stats table. +* - positive value higher than size: error, the given statistics table +* is too small. The return value corresponds to the size that should +* be given to succeed. The entries in the table are not valid and +* shall not be used by the caller. +* - negative value on error. +*/ +__rte_experimental +int +rte_dmadev_xstats_names_get (uint16_t dev_id, +struct rte_dmadev_xstats_name *xstats_names, +uint32_t size); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve extended statistics of a DMA device. +* +* @param dev_id +* The identifier of the device. +* @param ids +* The id numbers of the stats to get. The ids can be got from the stat +* position in the stat list from rte_dmadev_get_xstats_names(). +* @param[out] values +* The values for each stats request by ID. +* @param n +* The number of stats requested. +* +* @return +* - positive value: number of stat entries filled into the values array. +* - negative value on error. +*/ +__rte_experimental +int +rte_dmadev_xstats_get (uint16_t dev_id,const uint32_t ids[], +uint64_t values[],uint32_t n); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset the values of the xstats of the selected component in the device. +* +* @param dev_id +* The identifier of the device. +* @param ids +* Selects specific statistics to be reset. When NULL, all statistics +* will be reset. If non-NULL, must point to array of at least +* *nb_ids* size. +* @param nb_ids +* The number of ids available from the *ids* array. Ignored when ids is NULL.
+ *
+ * @return
+ * - zero: successfully reset the statistics to zero.
+ * - negative value on error.
+ */lib/dmadev/rte_dmadev.h new file +3
-0+__rte_experimental +int +rte_dmadev_xstats_reset(uint16_t dev_id, const uint32_t ids[], uint32_t
nb_ids);lib/dmadev/rte_dmadev.h new file +24
-0+ +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger the dmadev self test. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - 0: Selftest successful. +* - -ENOTSUP if the device doesn't support selftest +* - other values < 0 on failure. +*/ +__rte_experimental +int +rte_dmadev_selftest (uint16_t dev_id); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_H_ */ lib/dmadev/rte_dmadev_core.h new file +19
-0@@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* +* This header contains internal data types. But they are still part of the +* public API because they are used by inline public functions. +*/ + +struct rte_dmadev ; + +typedef dma_cookie_t (*dmadev_copy_t)(struct rte_dmadev *dev,
uint16_tvq_id,lib/dmadev/rte_dmadev_core.h new file +5
-0+ void *src, void *dst, + uint32_t length, uint64_t flags); +/**< @internal Function used to enqueue a copy operation. */ + +typedef dma_cookie_t (*dmadev_copy_sg_t)(struct rte_dmadev *dev,
uint16_tvq_id,lib/dmadev/rte_dmadev_core.h new file +5
-0+const struct dma_scatterlist *sg, + uint32_t sg_len, uint64_t flags); +/**< @internal Function used to enqueue a scatter list copy operation. */ + +typedef dma_cookie_t (*dmadev_fill_t)(struct rte_dmadev *dev, uint16_t
vq_id,lib/dmadev/rte_dmadev_core.h new file +5
-0+ uint64_t pattern, void *dst, + uint32_t length, uint64_t flags); +/**< @internal Function used to enqueue a fill operation. */ + +typedef dma_cookie_t (*dmadev_fill_sg_t)(struct rte_dmadev *dev,
uint16_tvq_id,lib/dmadev/rte_dmadev_core.h new file +6
-0+ uint64_t pattern, const struct dma_scatterlist *sg, + uint32_t sg_len, uint64_t flags); +/**< @internal Function used to enqueue a scatter list fill operation. */ + +typedef int (*dmadev_fence_t )(struct rte_dmadev *dev,uint16_t vq_id); +/**< @internal Function used to add a fence ordering between operations. */
lib/dmadev/rte_dmadev_core.h new file +2
-0+ +typedef int (*dmadev_perform_t)(struct rte_dmadev *dev, uint16_t
vq_id);lib/dmadev/rte_dmadev_core.h new file +3
-0+/**< @internal Function used to trigger hardware to begin performing. */ + +typedef uint16_t (*dmadev_completed_t)(struct rte_dmadev *dev,
uint16_tvq_id,lib/dmadev/rte_dmadev_core.h new file +3
-0+const uint16_t nb_cpls, + dma_cookie_t *cookie, bool *has_error); +/**< @internal Function used to return number of successful completed operations */
lib/dmadev/rte_dmadev_core.h new file +5
-0+ +typedef uint16_t (*dmadev_completed_fails_t )(struct rte_dmadev *dev, +uint16_t vq_id,const uint16_t nb_status, +uint32_t *status,dma_cookie_t *cookie); +/**< @internal Function used to return number of failed completed operations */
lib/dmadev/rte_dmadev_core.h new file +2
-0+ +#define RTE_DMADEV_NAME_MAX_LEN 64/**< Max length of name of DMA PMD */
lib/dmadev/rte_dmadev_core.h new file +26
-0+ +struct rte_dmadev_ops ; + +/** +* The data structure associated with each DMA device. +*/ +struct rte_dmadev { +/**< Enqueue a copy operation onto the DMA device. */ +dmadev_copy_t copy; +/**< Enqueue a scatter list copy operation onto the DMA device. */ +dmadev_copy_sg_t copy_sg; +/**< Enqueue a fill operation onto the DMA device. */ +dmadev_fill_t fill; +/**< Enqueue a scatter list fill operation onto the DMA device. */ +dmadev_fill_sg_t fill_sg; +/**< Add a fence to force ordering between operations. */ +dmadev_fence_t fence; +/**< Trigger hardware to begin performing enqueued operations. */ +dmadev_perform_t perform; +/**< Returns the number of operations that successful completed. */ +dmadev_completed_t completed; +/**< Returns the number of operations that failed to complete. */ +dmadev_completed_fails_t completed_fails; + +void *dev_private;/**< PMD-specific private data */ +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD */
lib/dmadev/rte_dmadev_core.h new file +17
-0+ +uint16_t dev_id;/**< Device ID for this instance */ +int socket_id;/**< Socket ID where memory is allocated */ +struct rte_device *device; +/**< Device info. supplied during device initialization */ +const char *driver_name;/**< Driver info. supplied by probing */ +char name[RTE_DMADEV_NAME_MAX_LEN ];/**< Device name */ + +RTE_STD_C11 + uint8_t attached : 1; /**< Flag indicating the device is attached */ + uint8_t started : 1; /**< Device state: STARTED(1)/STOPPED(0) */ + +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; + +#endif /* _RTE_DMADEV_CORE_H_ */ lib/dmadev/rte_dmadev_pmd.h new file +78
-0@@ -0,0 +1,210 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_PMD_H_ +#define _RTE_DMADEV_PMD_H_ + +/** @file + * RTE DMA PMD APIs + * + * @note + * Driver facing APIs for a DMA device. These are not to be called directly by + * any application. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <string.h> + +#include <rte_dev.h> +#include <rte_log.h> +#include <rte_common.h> + +#include "rte_dmadev.h" + +extern int libdmadev_logtype; + +#define RTE_DMADEV_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, libdmadev_logtype, "%s(): " fmt "\n", \ + __func__, ##args) + +/* Macros to check for valid device */ +#define RTE_DMADEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \ + return retval; \ + } \ +} while (0) + +#define RTE_DMADEV_VALID_DEVID_OR_RET(dev_id) do { \ + if (!rte_dmadev_pmd_is_valid_dev((dev_id))) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%d", dev_id); \ + return; \ + } \ +} while (0) + +#define RTE_DMADEV_DETACHED 0 +#define RTE_DMADEV_ATTACHED 1 + +/** + * Validate if the DMA device index is a valid attached DMA device. + * + * @param dev_id + * DMA device index. + * + * @return + * - If the device index is valid (1) or not (0). + */ +static inline unsigned +rte_dmadev_pmd_is_valid_dev(uint16_t dev_id) +{ + struct rte_dmadev *dev; + + if (dev_id >= RTE_DMADEV_MAX_DEVS) + return 0; + + dev = &rte_dmadevices[dev_id]; + if (dev->attached != RTE_DMADEV_ATTACHED) + return 0; + else + return 1; +} + +/** + * Definitions of control-plane functions exported by a driver through the + * generic structure of type *rte_dmadev_ops* supplied in the*rte_dmadev*
+ * structure associated with a device.
+ */lib/dmadev/rte_dmadev_pmd.h new file +26
-0+ +typedef int (*dmadev_info_get_t )(struct rte_dmadev *dev, +struct rte_dmadev_info *dev_info); +/**< @internal Function used to get device information of a device. */ + +typedef int (*dmadev_configure_t )(struct rte_dmadev *dev, +const struct rte_dmadev_conf *dev_conf); +/**< @internal Function used to configure a device. */ + +typedef int (*dmadev_start_t )(struct rte_dmadev *dev); +/**< @internal Function used to start a configured device. */ + +typedef int (*dmadev_stop_t )(struct rte_dmadev *dev); +/**< @internal Function used to stop a configured device. */ + +typedef int (*dmadev_close_t )(struct rte_dmadev *dev); +/**< @internal Function used to close a configured device. */ + +typedef int (*dmadev_reset_t )(struct rte_dmadev *dev); +/**< @internal Function used to reset a configured device. */ + +typedef int (*dmadev_queue_setup_t )(struct rte_dmadev *dev, +const struct rte_dmadev_queue_conf *conf); +/**< @internal Function used to allocate and set up a virt queue. */ + +typedef int (*dmadev_queue_release_t)(struct rte_dmadev *dev,
uint16_tvq_id);lib/dmadev/rte_dmadev_pmd.h new file +3
-0+/**< @internal Function used to release a virt queue. */ + +typedef int (*dmadev_queue_info_t)(struct rte_dmadev *dev, uint16_t
vq_id,lib/dmadev/rte_dmadev_pmd.h new file +11
-0+ struct rte_dmadev_queue_info *info); +/**< @internal Function used to retrieve information of a virt queue. */ + +typedef int (*dmadev_stats_get_t )(struct rte_dmadev *dev,int vq_id, +struct rte_dmadev_stats *stats); +/**< @internal Function used to retrieve basic statistics. */ + +typedef int (*dmadev_stats_reset_t )(struct rte_dmadev *dev,int vq_id); +/**< @internal Function used to reset basic statistics. */ + +typedef int (*dmadev_xstats_get_names_t)(const struct rte_dmadev*dev,
lib/dmadev/rte_dmadev_pmd.h new file +90
-0+struct rte_dmadev_xstats_name *xstats_names, + uint32_t size); +/**< @internal Function used to get names of extended stats. */ + +typedef int (*dmadev_xstats_get_t )(const struct rte_dmadev *dev, +const uint32_t ids[],uint64_t values[],uint32_t n); +/**< @internal Function used to retrieve extended stats. */ + +typedef int (*dmadev_xstats_reset_t )(struct rte_dmadev *dev, +const uint32_t ids[],uint32_t nb_ids); +/**< @internal Function used to reset extended stats. */ + +typedef int (*dmadev_selftest_t )(uint16_t dev_id); +/**< @internal Function used to start dmadev selftest. */ + +/** DMA device operations function pointer table */ +struct rte_dmadev_ops { +/**< Get device info. */ +dmadev_info_get_t dev_info_get; +/**< Configure device. */ +dmadev_configure_t dev_configure; +/**< Start device. */ +dmadev_start_t dev_start; +/**< Stop device. */ +dmadev_stop_t dev_stop; +/**< Close device. */ +dmadev_close_t dev_close; +/**< Reset device. */ +dmadev_reset_t dev_reset; + +/**< Allocate and set up a virt queue. */ +dmadev_queue_setup_t queue_setup; +/**< Release a virt queue. */ +dmadev_queue_release_t queue_release; +/**< Retrieve information of a virt queue */ +dmadev_queue_info_t queue_info_get; + +/**< Get basic statistics. */ +dmadev_stats_get_t stats_get; +/**< Reset basic statistics. */ +dmadev_stats_reset_t stats_reset; +/**< Get names of extended stats. */ +dmadev_xstats_get_names_t xstats_get_names; +/**< Get extended statistics. */ +dmadev_xstats_get_t xstats_get; +/**< Reset extended statistics values. */ +dmadev_xstats_reset_t xstats_reset; + +/**< Device selftest function */ +dmadev_selftest_t dev_selftest; +}; + +/** +* Allocates a new dmadev slot for an DMA device and returns the pointer +* to that slot for the driver to use. +* +* @param name +* Unique identifier name for each device +* @param dev_private_size +* Size of private data memory allocated within rte_dmadev object. +* Set to 0 to disable internal memory allocation and allow for +* self-allocation. +* @param socket_id +* Socket to allocate resources on. +* +* @return +* - NULL: Failure to allocate +* - Other: The rte_dmadev structure pointer for the new device +*/ +struct rte_dmadev * +rte_dmadev_pmd_allocate (const char *name,size_t dev_private_size, +int socket_id); + +/** +* Release the specified dmadev device. +* +* @param dev +* The *dmadev* pointer is the address of the *rte_dmadev* structure. +* +* @return +* - 0 on success, negative on error +*/ +int +rte_dmadev_pmd_release (struct rte_dmadev *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_PMD_H_ */ lib/dmadev/version.map new file +32
-0@@ -0,0 +1,32 @@ +EXPERIMENTAL { + global: + + rte_dmadev_count; + rte_dmadev_get_dev_id; + rte_dmadev_socket_id; + rte_dmadev_info_get; + rte_dmadev_configure; + rte_dmadev_start; + rte_dmadev_stop; + rte_dmadev_close; + rte_dmadev_reset; + rte_dmadev_queue_setup; + rte_dmadev_queue_release; + rte_dmadev_queue_info_get; + rte_dmadev_copy; + rte_dmadev_copy_sg; + rte_dmadev_fill; + rte_dmadev_fill_sg; + rte_dmadev_fence; + rte_dmadev_perform; + rte_dmadev_completed; + rte_dmadev_completed_fails; + rte_dmadev_stats_get; + rte_dmadev_stats_reset; + rte_dmadev_xstats_names_get; + rte_dmadev_xstats_get; + rte_dmadev_xstats_reset; + rte_dmadev_selftest; + + local: *; +};lib/meson.build +1
-1@@ -60,6 +60,7 @@ libraries = [ 'bpf', 'graph', 'node', + 'dmadev', ] if is_windows --2.8.1
Quoted 11 lines · Matan Azrad
From: Chengwen Feng
Quoted 6 lines
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Did you consider
RTE_COMP_ALGO_NULLxform in compressdev library?
em, I just looked at the code.
The RTE_COMP_ALGO_NULL is a small feature of the compression device. and currently only mlx5 and isal support it.
Also the compressdev dataplane API relatively complicated to do just DMA copy.
So I think we need a separate driver framework for the DMA device.
thanks
[snip]
Quoted 4 lines
.
Hi
From: fengchengwen
Quoted 10 lines · Matan Azrad
Quoted 9 lines
From: Chengwen Feng
Quoted 6 lines
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Quoted 7 lines
Quoted 2 lines
Did you consider
RTE_COMP_ALGO_NULLxform in compressdev library?em, I just looked at the code.
The
RTE_COMP_ALGO_NULLis a small feature of the compression device. and currently only mlx5 and isal support it.
Yes, but what that is mean?
If more drivers support DMA operations they can add the support there, no?
Quoted 2 lines
Also the compressdev dataplane API relatively complicated to do just DMA copy.
You snipped more comments I wrote below 😊
Maybe it is related....
Quoted 1 line
So I think we need a separate driver framework for the DMA device.
Need to consider deprecation in compressdev if so....
Quoted 8 lines
thanks
[snip]
Quoted 4 lines
.
Quoted 16 lines · Matan Azrad
Hi
From: fengchengwen
Quoted 13 lines · Matan Azrad
Quoted 11 lines
From: Chengwen Feng
Quoted 6 lines
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Did you consider
RTE_COMP_ALGO_NULLxform in compressdev library?
Quoted 8 lines
Quoted 4 lines
em, I just looked at the code.
The
RTE_COMP_ALGO_NULLis a small feature of the compression device. and currently only mlx5 and isal support it.Yes, but what that is mean?
If more drivers support DMA operations they can add the support there, no?
You mean to expand directly on compressdev ?
I think it hard to expand, and may break the compressdev concept.
Quoted 6 lines
Quoted 3 lines
Also the compressdev dataplane API relatively complicated to do just DMA copy.
You snipped more comments I wrote below 😊
Maybe it is related....
Sorry, I just skipped.
'Did you consider also mbuf API usage for memory descriptor?' ---One scenario of the DMA is vhost-net, which src or dst could be mbuf, but the peer were not mbuf. so here we use raw fields.
Quoted 14 lines
Quoted 2 lines
So I think we need a separate driver framework for the DMA device.
Need to consider deprecation in compressdev if so....
Quoted 8 lines
thanks
[snip]
Quoted 4 lines
.
From: fengchengwen
Quoted 22 lines · Matan Azrad
Quoted 21 lines
Hi
From: fengchengwen
Quoted 17 lines · Matan Azrad
Quoted 11 lines
From: Chengwen Feng
Quoted 6 lines
This patch introduces 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Did you consider
RTE_COMP_ALGO_NULLxform in compressdev library?em, I just looked at the code.
The
RTE_COMP_ALGO_NULLis a small feature of the compression device. and currently only mlx5 and isal support it.
Quoted 7 lines
Quoted 2 lines
Yes, but what that is mean?
If more drivers support DMA operations they can add the support there,no?
Quoted 1 line
You mean to expand directly on compressdev ?
I think it hard to expand, and may break the compressdev concept.
Maybe, what do you need to expand?
Also maybe your expansion is related also to compress, finally both are mem-to-mem offload.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Also the compressdev dataplane API relatively complicated to do just DMA copy.
Quoted 8 lines
Quoted 2 lines
You snipped more comments I wrote below 😊
Maybe it is related....Sorry, I just skipped.
'Did you consider also mbuf API usage for memory descriptor?' ---One scenario of the DMA is vhost-net, which src or dst could be mbuf, but the peer were not mbuf. so here we use raw fields.
Did you consider using external\attached mbuf for this case?
Did you also consider raw API in cryptodev library?
Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
So I think we need a separate driver framework for the DMA device.
Need to consider deprecation in compressdev if so....
Quoted 8 lines
thanks
[snip]
Quoted 4 lines
.
cover dmadev rfc suggested updates
In reply to Chengwen FengThis patchset contains a series of changes to dmadev based on work being done to port over our drivers to test this new infrastructure. Some of these are bug fixes to enable compilation e.g. missing exports or meson.build files, while others are suggested changes to enhance the API. All these patches are to be applied on top of [1] as they are mostly suggested changes to that RFC i.e. patches to the patch!
The final patch includes some basic sanity tests for copy operations that we have ported over from the ioat self-tests to use the dmadev APIs. The basic dataplane part of those tests is probably ok for now, but the initialization of queues in that test code may need some enhancement. Feedback welcome.
A tree with all these patches applied can be got at [2] if anyone wants to use that as a basis for working on drivers, or for other discussion.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
[2] https://github.com/bruce-richardson/dpdk/tree/dmadev-rfcs
Bruce Richardson (9):
dmadev: add missing exports
dmadev: change virtual addresses to IOVA
dmadev: add dump function
dmadev: remove xstats functions
dmadev: drop cookie typedef
dmadev: allow NULL parameters to completed ops call
dmadev: stats structure updates
drivers: add dma driver category
app/test: add basic dmadev unit test
app/test/meson.build | 2 + app/test/test_dmadev.c | 320 +++++++++++++++++++++++++++++++++++ drivers/dma/meson.build | 11 ++ drivers/meson.build | 1 + lib/dmadev/rte_dmadev.c | 66 ++------ lib/dmadev/rte_dmadev.h | 204 +++++++--------------- lib/dmadev/rte_dmadev_core.h | 16 +- lib/dmadev/rte_dmadev_pmd.h | 24 +-- lib/dmadev/version.map | 7 +- 9 files changed, 425 insertions(+), 226 deletions(-) create mode 100644 app/test/test_dmadev.c create mode 100644 drivers/dma/meson.build
--
2.30.2
RFC PATCH 1/9 dmadev: add missing exports
Export the rte_dmadevices array and the allocate and release functions which are needed by PMDs.
--- drivers/meson.build | 1 + lib/dmadev/rte_dmadev.c | 2 ++ lib/dmadev/version.map | 3 +++ 3 files changed, 6 insertions(+)
drivers/meson.build +1 -0
@@ -9,6 +9,7 @@ subdirs = [ 'common/mlx5', # depends on bus. 'common/qat', # depends on bus. 'common/sfc_efx', # depends on bus. + 'dma', # depends on bus. 'mempool', # depends on common and bus. 'net', # depends on common, bus, mempool 'raw', # depends on common, bus and net.
lib/dmadev/rte_dmadev.c +2 -0
@@ -372,6 +372,7 @@ rte_dmadev_find_free_device_index(void)return RTE_DMADEV_MAX_DEVS ; } +__rte_experimental struct rte_dmadev *rte_dmadev_pmd_allocate (const char *name,size_t dev_priv_size,int socket_id) {
@@ -414,6 +415,7 @@ rte_dmadev_pmd_allocate(const char *name, size_t dev_priv_size, int socket_id)return dev; } +__rte_experimental intrte_dmadev_pmd_release (struct rte_dmadev *dev) {
lib/dmadev/version.map +3 -0
@@ -1,6 +1,8 @@ EXPERIMENTAL { global: + rte_dmadevices; + rte_dmadev_pmd_allocate; rte_dmadev_count; rte_dmadev_get_dev_id; rte_dmadev_socket_id;
@@ -19,6 +21,7 @@ EXPERIMENTAL { rte_dmadev_fill_sg; rte_dmadev_fence; rte_dmadev_perform; + rte_dmadev_pmd_release; rte_dmadev_completed; rte_dmadev_completed_fails; rte_dmadev_stats_get;
Signature · 1 line
2.30.2
Re: [dpdk-dev] [RFC UPDATE PATCH 1/9] dmadev: add missing exports
Quoted 3 lines · Bruce Richardson
Export the
rte_dmadevicesarray and the allocate and release functions which are needed by PMDs.
rte_dmadevices[] might be an issue for inline accesses, but pmd allocate/release should be internal (driver only).
Signature · 1 line
David Marchand
Re: [dpdk-dev] [RFC UPDATE PATCH 1/9] dmadev: add missing exports
Quoted 9 lines · David Marchand
Quoted 3 lines · Bruce Richardson
Export the
rte_dmadevicesarray and the allocate and release functions which are needed by PMDs.rte_dmadevices[] might be an issue for inline accesses, but pmd allocate/release should be internal (driver only).
So if I understand correctly, they still need to be in the version.map file, but with "interal" versioning rather than "experimental", right?
Re: [dpdk-dev] [RFC UPDATE PATCH 1/9] dmadev: add missing exports
Quoted 5 lines · Bruce Richardson
Quoted 3 lines · David Marchand
Quoted 1 line · Bruce Richardson
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Export the
rte_dmadevicesarray and the allocate and release functions which are needed by PMDs.rte_dmadevices[] might be an issue for inline accesses, but pmd allocate/release should be internal (driver only).
So if I understand correctly, they still need to be in the version.map
drivers still need them exported, so yes they must be in version.map with INTERNAL version.
Quoted 1 line
file, but with "interal" versioning rather than "experimental", right?
But I would move them too in a separate header, for drivers, like ethdev_driver.h.
And the __rte_internal tag will be needed at their declarations.
https://git.dpdk.org/dpdk/tree/lib/ethdev/ethdev_driver.h#n1005
https://git.dpdk.org/dpdk/tree/lib/ethdev/version.map#n257
Signature · 1 line
David Marchand
RFC PATCH 2/9 dmadev: change virtual addresses to IOVA
In reply to Bruce RichardsonFor 32-bit builds, iova's are 64-bit still, so to ensure we can still use PA mode on 32-bit we need to convert all enqueue "void *" parameters to rte_iova_t
--- lib/dmadev/rte_dmadev.h | 8 ++++---- lib/dmadev/rte_dmadev_core.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
lib/dmadev/rte_dmadev.h +4 -4
@@ -133,8 +133,8 @@ typedef int32_t dma_cookie_t;* dma_scatterlist - can hold scatter DMA operation request */ struct dma_scatterlist { -void *src; -void *dst; +rte_iova_t src; +rte_iova_t dst;uint32_t length; };
@@ -505,7 +505,7 @@ rte_dmadev_queue_info_get(uint16_t dev_id, uint16_t vq_id,*/ __rte_experimental static inline dma_cookie_t -rte_dmadev_copy (uint16_t dev_id,uint16_t vq_id,void *src,void *dst, +rte_dmadev_copy (uint16_t dev_id,uint16_t vq_id,rte_iova_t src,rte_iova_t dst,uint32_t length,uint64_t flags) {struct rte_dmadev *dev = &rte_dmadevices[dev_id];
@@ -579,7 +579,7 @@ rte_dmadev_copy_sg(uint16_t dev_id, uint16_t vq_id,__rte_experimental static inline dma_cookie_trte_dmadev_fill (uint16_t dev_id,uint16_t vq_id,uint64_t pattern, -void *dst,uint32_t length,uint64_t flags) +rte_iova_t dst,uint32_t length,uint64_t flags) {struct rte_dmadev *dev = &rte_dmadevices[dev_id];return (*dev->fill)(dev, vq_id, pattern, dst, length, flags);
lib/dmadev/rte_dmadev_core.h +2 -2
@@ -17,7 +17,7 @@struct rte_dmadev ;typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, -void *src,void *dst, +rte_iova_t src,rte_iova_t dst,uint32_t length,uint64_t flags);/**< @internal Function used to enqueue a copy operation. */
@@ -27,7 +27,7 @@ typedef dma_cookie_t (*dmadev_copy_sg_t)(struct rte_dmadev *dev, uint16_t vq_id,/**< @internal Function used to enqueue a scatter list copy operation. */ typedef dma_cookie_t (*dmadev_fill_t )(struct rte_dmadev *dev,uint16_t vq_id, -uint64_t pattern,void *dst, +uint64_t pattern,rte_iova_t dst,uint32_t length,uint64_t flags);/**< @internal Function used to enqueue a fill operation. */
Signature · 1 line
2.30.2
RFC PATCH 3/9 dmadev: add dump function
In reply to Bruce Richardsona dump() function to print the state of a device to a file (e.g. sterr or stdout) is very useful for debugging drivers.
--- lib/dmadev/rte_dmadev.c | 17 +++++++++++++++++ lib/dmadev/rte_dmadev.h | 19 +++++++++++++++++++ lib/dmadev/rte_dmadev_pmd.h | 5 +++++ lib/dmadev/version.map | 1 + 4 files changed, 42 insertions(+)
lib/dmadev/rte_dmadev.c +17 -0
@@ -345,6 +345,23 @@ rte_dmadev_xstats_reset(uint16_t dev_id, const uint32_t ids[], uint32_t nb_ids)return (*dev->dev_ops->xstats_reset)(dev, ids, nb_ids); } +int +rte_dmadev_dump (uint16_t dev_id,FILE *f) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; + +RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); + +fprintf (f,"DMA Dev %u, '%s' [%s]\n" , dev->dev_id, dev->name, + dev->started ?"started" :"stopped" ); +fprintf (f," Driver: %s\n" , dev->driver_name); +fprintf (f," Socket Id: %d\n" , dev->socket_id); + +if (dev->dev_ops->dump !=NULL ) +return (*dev->dev_ops->dump)(dev, f); +return 0 ; +} +int rte_dmadev_selftest (uint16_t dev_id) {
lib/dmadev/rte_dmadev.h +19 -0
@@ -357,6 +357,25 @@ __rte_experimentalint rte_dmadev_close (uint16_t dev_id); +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Dump DMA device info. +* +* @param dev_id +* The identifier of the device. +* +* @param f +* The file to write the output to. +* +* @return +* 0 on success. Non-zero otherwise. +*/ +__rte_experimental +int +rte_dmadev_dump (uint16_t dev_id,FILE *f); +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice.
lib/dmadev/rte_dmadev_pmd.h +5 -0
@@ -99,6 +99,9 @@ typedef int (*dmadev_close_t)(struct rte_dmadev *dev);typedef int (*dmadev_reset_t )(struct rte_dmadev *dev);/**< @internal Function used to reset a configured device. */ +typedef int (*dmadev_dump_t )(struct rte_dmadev *dev,FILE *f); +/**< @internal Function used to dump out the state of a device for debugging. */ +typedef int (*dmadev_queue_setup_t )(struct rte_dmadev *dev,const struct rte_dmadev_queue_conf *conf);/**< @internal Function used to allocate and set up a virt queue. */
@@ -147,6 +150,8 @@ struct rte_dmadev_ops {dmadev_close_t dev_close;/**< Reset device. */ dmadev_reset_t dev_reset; +/**< Dump device info for debugging */ +dmadev_dump_t dump;/**< Allocate and set up a virt queue. */ dmadev_queue_setup_t queue_setup;
lib/dmadev/version.map +1 -0
@@ -4,6 +4,7 @@ EXPERIMENTAL { rte_dmadevices; rte_dmadev_pmd_allocate; rte_dmadev_count; + rte_dmadev_dump; rte_dmadev_get_dev_id; rte_dmadev_socket_id; rte_dmadev_info_get;
Signature · 1 line
2.30.2
RFC PATCH 4/9 dmadev: remove xstats functions
In reply to Bruce Richardsonremove the xstats function calls, as they are not needed for this class as-yet.
--- lib/dmadev/rte_dmadev.c | 63 -------------------------- lib/dmadev/rte_dmadev.h | 89 ------------------------------------- lib/dmadev/rte_dmadev_pmd.h | 19 -------- lib/dmadev/version.map | 3 -- 4 files changed, 174 deletions(-)
lib/dmadev/rte_dmadev.c +0 -63
@@ -282,69 +282,6 @@ rte_dmadev_stats_reset(uint16_t dev_id, int vq_id)return (*dev->dev_ops->stats_reset)(dev, vq_id); } -static int -xstats_get_count (uint16_t dev_id) -{ -struct rte_dmadev *dev = &rte_dmadevices[dev_id]; - -RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get_names, -ENOTSUP ); - -return (*dev->dev_ops->xstats_get_names)(dev,NULL ,0 ); -} - -int -rte_dmadev_xstats_names_get (uint16_t dev_id, -struct rte_dmadev_xstats_name *xstats_names, -uint32_t size) -{ -struct rte_dmadev *dev; -int cnt_expected_entries; - -RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); - - cnt_expected_entries =xstats_get_count (dev_id); - -if (xstats_names ==NULL || cnt_expected_entries <0 || - (int )size < cnt_expected_entries || size ==0 ) -return cnt_expected_entries; - - dev = &rte_dmadevices[dev_id]; - -RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get_names, -ENOTSUP ); -return (*dev->dev_ops->xstats_get_names)(dev, xstats_names, size); -} - -int -rte_dmadev_xstats_get (uint16_t dev_id,const uint32_t ids[], -uint64_t values[],uint32_t n) -{ -struct rte_dmadev *dev; - -RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); -RTE_FUNC_PTR_OR_ERR_RET (ids, -EINVAL ); -RTE_FUNC_PTR_OR_ERR_RET (values, -EINVAL ); - - dev = &rte_dmadevices[dev_id]; - -RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_get, -ENOTSUP ); - -return (*dev->dev_ops->xstats_get)(dev, ids, values, n); -} - -int -rte_dmadev_xstats_reset (uint16_t dev_id,const uint32_t ids[],uint32_t nb_ids) -{ -struct rte_dmadev *dev; - -RTE_DMADEV_VALID_DEVID_OR_ERR_RET (dev_id, -EINVAL ); - - dev = &rte_dmadevices[dev_id]; - -RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->xstats_reset, -ENOTSUP ); - -return (*dev->dev_ops->xstats_reset)(dev, ids, nb_ids); -} -int rte_dmadev_dump (uint16_t dev_id,FILE *f) {
lib/dmadev/rte_dmadev.h +0 -89
95 lines not on this page · raw message
lib/dmadev/rte_dmadev_pmd.h +0 -19
@@ -120,19 +120,6 @@ typedef int (*dmadev_stats_get_t)(struct rte_dmadev *dev, int vq_id,typedef int (*dmadev_stats_reset_t )(struct rte_dmadev *dev,int vq_id);/**< @internal Function used to reset basic statistics. */ -typedef int (*dmadev_xstats_get_names_t )(const struct rte_dmadev *dev, -struct rte_dmadev_xstats_name *xstats_names, -uint32_t size); -/**< @internal Function used to get names of extended stats. */ - -typedef int (*dmadev_xstats_get_t )(const struct rte_dmadev *dev, -const uint32_t ids[],uint64_t values[],uint32_t n); -/**< @internal Function used to retrieve extended stats. */ - -typedef int (*dmadev_xstats_reset_t )(struct rte_dmadev *dev, -const uint32_t ids[],uint32_t nb_ids); -/**< @internal Function used to reset extended stats. */ -typedef int (*dmadev_selftest_t )(uint16_t dev_id);/**< @internal Function used to start dmadev selftest. */
@@ -164,12 +151,6 @@ struct rte_dmadev_ops {dmadev_stats_get_t stats_get;/**< Reset basic statistics. */ dmadev_stats_reset_t stats_reset; -/**< Get names of extended stats. */ -dmadev_xstats_get_names_t xstats_get_names; -/**< Get extended statistics. */ -dmadev_xstats_get_t xstats_get; -/**< Reset extended statistics values. */ -dmadev_xstats_reset_t xstats_reset;/**< Device selftest function */ dmadev_selftest_t dev_selftest;
lib/dmadev/version.map +0 -3
@@ -27,9 +27,6 @@ EXPERIMENTAL { rte_dmadev_completed_fails; rte_dmadev_stats_get; rte_dmadev_stats_reset; - rte_dmadev_xstats_names_get; - rte_dmadev_xstats_get; - rte_dmadev_xstats_reset; rte_dmadev_selftest; local: *;
Signature · 1 line
2.30.2
RFC PATCH 5/9 dmadev: drop cookie typedef
In reply to Bruce RichardsonRather than having a special type for the index values used in dmadev, just use regular int types, with appropriate return value notifications.
--- lib/dmadev/rte_dmadev.h | 59 ++++++++++++------------------------ lib/dmadev/rte_dmadev_core.h | 12 ++++---- 2 files changed, 26 insertions(+), 45 deletions(-)
lib/dmadev/rte_dmadev.h +20 -39
@@ -106,29 +106,6 @@ extern "C" {#include <rte_errno.h> #include <rte_compat.h> -/** -* dma_cookie_t - an opaque DMA cookie -* -* If dma_cookie_t is >=0 it's a DMA operation request cookie, <0 it's a error -* code. -* When using cookies, comply with the following rules: -* a) Cookies for each virtual queue are independent. -* b) For a virt queue, the cookie are monotonically incremented, when it reach -* the INT_MAX, it wraps back to zero. -* c) The initial cookie of a virt queue is zero, after the device is stopped or -* reset, the virt queue's cookie needs to be reset to zero. -* Example: -* step-1: start one dmadev -* step-2: enqueue a copy operation, the cookie return is 0 -* step-3: enqueue a copy operation again, the cookie return is 1 -* ... -* step-101: stop the dmadev -* step-102: start the dmadev -* step-103: enqueue a copy operation, the cookie return is 0 -* ... -*/ -typedef int32_t dma_cookie_t ; -/** * dma_scatterlist - can hold scatter DMA operation request */
@@ -517,13 +494,14 @@ rte_dmadev_queue_info_get(uint16_t dev_id, uint16_t vq_id,* An opaque flags for this operation. * * @return -* dma_cookie_t: please refer to the corresponding definition. +* <0 on error, +* on success, index of enqueued copy job, monotonically increasing between 0..UINT16_MAX * * NOTE: The caller must ensure that the input parameter is valid and the * corresponding device supports the operation. */ __rte_experimental -static inline dma_cookie_t +static inline intrte_dmadev_copy (uint16_t dev_id,uint16_t vq_id,rte_iova_t src,rte_iova_t dst,uint32_t length,uint64_t flags) {
@@ -552,13 +530,14 @@ rte_dmadev_copy(uint16_t dev_id, uint16_t vq_id, rte_iova_t src, rte_iova_t dst,* An opaque flags for this operation. * * @return -* dma_cookie_t: please refer to the corresponding definition. +* <0 on error, +* on success, index of enqueued copy job, monotonically increasing between 0..UINT16_MAX * * NOTE: The caller must ensure that the input parameter is valid and the * corresponding device supports the operation. */ __rte_experimental -static inline dma_cookie_t +static inline intrte_dmadev_copy_sg (uint16_t dev_id,uint16_t vq_id,const struct dma_scatterlist *sg,uint32_t sg_len,uint64_t flags)
@@ -590,13 +569,14 @@ rte_dmadev_copy_sg(uint16_t dev_id, uint16_t vq_id,* An opaque flags for this operation. * * @return -* dma_cookie_t: please refer to the corresponding definition. +* <0 on error, +* on success, index of enqueued copy job, monotonically increasing between 0..UINT16_MAX * * NOTE: The caller must ensure that the input parameter is valid and the * corresponding device supports the operation. */ __rte_experimental -static inline dma_cookie_t +static inline intrte_dmadev_fill (uint16_t dev_id,uint16_t vq_id,uint64_t pattern,rte_iova_t dst,uint32_t length,uint64_t flags) {
@@ -627,13 +607,14 @@ rte_dmadev_fill(uint16_t dev_id, uint16_t vq_id, uint64_t pattern,* An opaque flags for this operation. * * @return -* dma_cookie_t: please refer to the corresponding definition. +* <0 on error, +* on success, index of enqueued copy job, monotonically increasing between 0..UINT16_MAX * * NOTE: The caller must ensure that the input parameter is valid and the * corresponding device supports the operation. */ __rte_experimental -static inline dma_cookie_t +static inline intrte_dmadev_fill_sg (uint16_t dev_id,uint16_t vq_id,uint64_t pattern,const struct dma_scatterlist *sg,uint32_t sg_len,uint64_t flags)
@@ -716,8 +697,8 @@ rte_dmadev_perform(uint16_t dev_id, uint16_t vq_id)* The identifier of virt queue. * @param nb_cpls * The maximum number of completed operations that can be processed. -* @param[out] cookie -* The last completed operation's cookie. +* @param[out] last_idx +* The last completed operation's index, as returned when entry was enqueued * @param[out] has_error * Indicates if there are transfer error. *
@@ -730,11 +711,11 @@ rte_dmadev_perform(uint16_t dev_id, uint16_t vq_id)__rte_experimental static inline uint16_trte_dmadev_completed (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_cpls, -dma_cookie_t *cookie,bool *has_error) +uint16_t *last_idx,bool *has_error) {struct rte_dmadev *dev = &rte_dmadevices[dev_id]; has_error = false; -return (*dev->completed)(dev, vq_id, nb_cpls, cookie, has_error); +return (*dev->completed)(dev, vq_id, nb_cpls, last_idx, has_error); }/**
@@ -752,8 +733,8 @@ rte_dmadev_completed(uint16_t dev_id, uint16_t vq_id, const uint16_t nb_cpls,* Indicates the size of status array. * @param[out] status * The error code of operations that failed to complete. -* @param[out] cookie -* The last failed completed operation's cookie. +* @param[out] last_idx +* The last failed completed operation's index. * * @return * The number of operations that failed to complete.
@@ -765,10 +746,10 @@ __rte_experimentalstatic inline uint16_t rte_dmadev_completed_fails (uint16_t dev_id,uint16_t vq_id,const uint16_t nb_status,uint32_t *status, -dma_cookie_t *cookie) +uint16_t *last_idx) {struct rte_dmadev *dev = &rte_dmadevices[dev_id]; -return (*dev->completed_fails)(dev, vq_id, nb_status, status, cookie); +return (*dev->completed_fails)(dev, vq_id, nb_status, status, last_idx); }struct rte_dmadev_stats {
lib/dmadev/rte_dmadev_core.h +6 -6
@@ -16,22 +16,22 @@struct rte_dmadev ; -typedef dma_cookie_t (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id, +typedef int (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vq_id,rte_iova_t src,rte_iova_t dst,uint32_t length,uint64_t flags);/**< @internal Function used to enqueue a copy operation. */ -typedef dma_cookie_t (*dmadev_copy_sg_t )(struct rte_dmadev *dev,uint16_t vq_id, +typedef int (*dmadev_copy_sg_t )(struct rte_dmadev *dev,uint16_t vq_id,const struct dma_scatterlist *sg,uint32_t sg_len,uint64_t flags);/**< @internal Function used to enqueue a scatter list copy operation. */ -typedef dma_cookie_t (*dmadev_fill_t )(struct rte_dmadev *dev,uint16_t vq_id, +typedef int (*dmadev_fill_t )(struct rte_dmadev *dev,uint16_t vq_id,uint64_t pattern,rte_iova_t dst,uint32_t length,uint64_t flags);/**< @internal Function used to enqueue a fill operation. */ -typedef dma_cookie_t (*dmadev_fill_sg_t )(struct rte_dmadev *dev,uint16_t vq_id, +typedef int (*dmadev_fill_sg_t )(struct rte_dmadev *dev,uint16_t vq_id,uint64_t pattern,const struct dma_scatterlist *sg,uint32_t sg_len,uint64_t flags);/**< @internal Function used to enqueue a scatter list fill operation. */
@@ -44,12 +44,12 @@ typedef int (*dmadev_perform_t)(struct rte_dmadev *dev, uint16_t vq_id);typedef uint16_t (*dmadev_completed_t )(struct rte_dmadev *dev,uint16_t vq_id,const uint16_t nb_cpls, -dma_cookie_t *cookie,bool *has_error); +uint16_t *last_idx,bool *has_error);/**< @internal Function used to return number of successful completed operations */ typedef uint16_t (*dmadev_completed_fails_t )(struct rte_dmadev *dev,uint16_t vq_id,const uint16_t nb_status, -uint32_t *status,dma_cookie_t *cookie); +uint32_t *status,uint16_t *last_idx);/**< @internal Function used to return number of failed completed operations */ #define RTE_DMADEV_NAME_MAX_LEN 64/**< Max length of name of DMA PMD */
Signature · 1 line
2.30.2
RFC PATCH 6/9 dmadev: allow NULL parameters to completed ops call
In reply to Bruce RichardsonAllow the user to skip passing the "out" parameters to the rte_dmadev_completed() API call, by using local replacements in the inline function. This simplifies drivers, and compilers should be able to remove the branches at compile time in many cases.
--- lib/dmadev/rte_dmadev.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
lib/dmadev/rte_dmadev.h +17 -2
@@ -698,9 +698,11 @@ rte_dmadev_perform(uint16_t dev_id, uint16_t vq_id)* @param nb_cpls * The maximum number of completed operations that can be processed. * @param[out] last_idx -* The last completed operation's index, as returned when entry was enqueued +* The last completed operation's index, as returned when entry was enqueued. +* If not required, NULL can be passed in. * @param[out] has_error * Indicates if there are transfer error. +* If not required, may be passed as NULL. * * @return * The number of operations that successful completed.
@@ -714,7 +716,20 @@ rte_dmadev_completed(uint16_t dev_id, uint16_t vq_id, const uint16_t nb_cpls, uint16_t *last_idx, bool *has_error) { struct rte_dmadev *dev = &rte_dmadevices[dev_id]; - has_error = false; +bool err = false; +uint16_t idx; + +/* ensure the pointer values are non-null to simplify drivers. +* In most cases these should be compile time evaluated, since this is an inline function. +* - If NULL is explicitly passed as parameter, then compiler knows the value is NULL +* - If address of local variable is passed as parameter, then compiler can +* know it's non-NULL. +*/ +if (has_error ==NULL ) + has_error = &err; +if (last_idx ==NULL ) + last_idx = &idx; +return (*dev->completed)(dev, vq_id, nb_cpls, last_idx, has_error); }
Signature · 1 line
2.30.2
RFC PATCH 7/9 dmadev: stats structure updates
In reply to Bruce RichardsonDrop the failed enqueue count since that is best tracked by the application so that retries of the same job can be counted as desired by the app developer. Since the "doorbell" function is separate from the actual functions to enqueue descriptors, track a separate stat for jobs which were submitted to hardware, in case the "enqueued" count includes jobs which were not yet "doorbelled".
--- lib/dmadev/rte_dmadev.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
lib/dmadev/rte_dmadev.h +4 -8
@@ -768,14 +768,10 @@ rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vq_id, }struct rte_dmadev_stats { -uint64_t enqueue_fail_count; -/**< Conut of all operations which failed enqueued */ -uint64_t enqueued_count; -/**< Count of all operations which successful enqueued */ -uint64_t completed_fail_count; -/**< Count of all operations which failed to complete */ -uint64_t completed_count; -/**< Count of all operations which successful complete */ +uint64_t enqueued_count;/**< Count of operations which were successful enqueued */ +uint64_t submitted_count;/**< Count of operations which were submitted to hardware */ +uint64_t completed_fail_count;/**< Count of operations which failed to complete */ +uint64_t completed_count;/**< Count of operations which successful complete */ };/**
Signature · 1 line
2.30.2
RFC PATCH 8/9 drivers: add dma driver category
In reply to Bruce Richardson--- drivers/dma/meson.build | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 drivers/dma/meson.build
drivers/dma/meson.build new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2021 Intel Corporation + +if is_windows + subdir_done() +endif + +drivers = [ +] + +std_deps = ['dmadev']
Signature · 1 line
2.30.2
RFC PATCH 9/9 app/test: add basic dmadev unit test
In reply to Bruce RichardsonAdd in some basic dmadev unit tests for testing drivers and the library itself.
--- app/test/meson.build | 2 + app/test/test_dmadev.c | 320 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 322 insertions(+) create mode 100644 app/test/test_dmadev.c
app/test/meson.build +2 -0
@@ -36,6 +36,7 @@ test_sources = files( 'test_debug.c', 'test_distributor.c', 'test_distributor_perf.c', + 'test_dmadev.c', 'test_eal_flags.c', 'test_eal_fs.c', 'test_efd.c',
@@ -155,6 +156,7 @@ test_deps = [ 'cmdline', 'cryptodev', 'distributor', + 'dmadev', 'efd', 'ethdev', 'eventdev',
app/test/test_dmadev.c new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [dpdk-dev] [RFC UPDATE PATCH 0/9] dmadev rfc suggested updates
In reply to Bruce RichardsonLGTM, thanks
And I'am prepare dmadev V2, include:
a) Fix code review comments (e.g. multiple-process support, doxygen, comments, typo)
b) Flatten device abstraction to two layer: dmadev <> vchan
c) Public API use dev_id and vchan_id to locate one vchan
d) Using the flags parameter instead of the fence API
e) Rename rte_dmadev_perform to rte_dmadev_submit so it corresponds to the stats variable.
PS: Some code (lib/dmadev) will rebase this patchset
Quoted 48 lines · Bruce Richardson
This patchset contains a series of changes to dmadev based on work being done to port over our drivers to test this new infrastructure. Some of these are bug fixes to enable compilation e.g. missing exports or meson.build files, while others are suggested changes to enhance the API. All these patches are to be applied on top of [1] as they are mostly suggested changes to that RFC i.e. patches to the patch!
The final patch includes some basic sanity tests for copy operations that we have ported over from the ioat self-tests to use the dmadev APIs. The basic dataplane part of those tests is probably ok for now, but the initialization of queues in that test code may need some enhancement. Feedback welcome.
A tree with all these patches applied can be got at [2] if anyone wants to use that as a basis for working on drivers, or for other discussion.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
[2] https://github.com/bruce-richardson/dpdk/tree/dmadev-rfcsBruce Richardson (9):
dmadev: add missing exports
dmadev: change virtual addresses to IOVA
dmadev: add dump function
dmadev: remove xstats functions
dmadev: drop cookie typedef
dmadev: allow NULL parameters to completed ops call
dmadev: stats structure updates
drivers: add dma driver category
app/test: add basic dmadev unit testapp/test/meson.build | 2 + app/test/test_dmadev.c | 320 +++++++++++++++++++++++++++++++++++ drivers/dma/meson.build | 11 ++ drivers/meson.build | 1 + lib/dmadev/rte_dmadev.c | 66 ++------ lib/dmadev/rte_dmadev.h | 204 +++++++--------------- lib/dmadev/rte_dmadev_core.h | 16 +- lib/dmadev/rte_dmadev_pmd.h | 24 +-- lib/dmadev/version.map | 7 +- 9 files changed, 425 insertions(+), 226 deletions(-) create mode 100644 app/test/test_dmadev.c create mode 100644 drivers/dma/meson.build--
2.30.2.
Re: [dpdk-dev] [RFC UPDATE PATCH 0/9] dmadev rfc suggested updates
Quoted 7 lines · fengchengwen
LGTM, thanks
And I'am prepare dmadev V2, include:
a) Fix code review comments (e.g. multiple-process support, doxygen, comments, typo)
b) Flatten device abstraction to two layer: dmadev <> vchan
c) Public API usedev_idandvchan_idto locate one vchan
d) Using the flags parameter instead of the fence API
Bit uncertain about this one still
Quoted 4 lines
e) Rename
rte_dmadev_performtorte_dmadev_submitso it corresponds to the stats variable.PS: Some code (lib/dmadev) will rebase this patchset
This was not meant to be a separate patchset, but rather to try and keep us all in sync on what was being looked at and tested. Please just pull in the changes from this set (as many as you are happy with) into your V2 RFC to simplify things. It's better to just have the one master RFC into which changes are pulled.
Thanks,
/Bruce
Re: [dpdk-dev] [RFC UPDATE PATCH 0/9] dmadev rfc suggested updates
In reply to fengchengwenQuoted 12 lines · fengchengwen
LGTM, thanks
And I'am prepare dmadev V2, include: a) Fix code review comments (e.g. multiple-process support, doxygen, comments, typo) b) Flatten device abstraction to two layer: dmadev <> vchan c) Public API use
dev_idandvchan_idto locate one vchan d) Using the flags parameter instead of the fence API e) Renamerte_dmadev_performtorte_dmadev_submitso it corresponds to the stats variable.PS: Some code (lib/dmadev) will rebase this patchset
As well as posting the RFC v2 here, could you also perhaps post it to a github repo, so that Jerin, myself and others can send pull-requests with suggested changes? For key areas of discussion, working through github with patches sent via pull request you can take in directly will probably be faster for getting us to a v3. The mail threads on list are already getting very long and hard to follow.
Regards,
/Bruce
Re: [dpdk-dev] [RFC UPDATE PATCH 0/9] dmadev rfc suggested updates
In reply to fengchengwenQuoted 6 lines · fengchengwen
LGTM, thanks
And I'am prepare dmadev V2, include:
a) Fix code review comments (e.g. multiple-process support, doxygen, comments, typo)
b) Flatten device abstraction to two layer: dmadev <> vchan
I think we should not have "virtual" in API specification. it can be virtual or real based on real HW/SW/Driver implementation. I think, just chan enough.
Quoted 57 lines
c) Public API use
dev_idandvchan_idto locate one vchan
d) Using the flags parameter instead of the fence API
e) Renamerte_dmadev_performtorte_dmadev_submitso it corresponds to the stats variable.PS: Some code (lib/dmadev) will rebase this patchset
Quoted 48 lines · Bruce Richardson
This patchset contains a series of changes to dmadev based on work being done to port over our drivers to test this new infrastructure. Some of these are bug fixes to enable compilation e.g. missing exports or meson.build files, while others are suggested changes to enhance the API. All these patches are to be applied on top of [1] as they are mostly suggested changes to that RFC i.e. patches to the patch!
The final patch includes some basic sanity tests for copy operations that we have ported over from the ioat self-tests to use the dmadev APIs. The basic dataplane part of those tests is probably ok for now, but the initialization of queues in that test code may need some enhancement. Feedback welcome.
A tree with all these patches applied can be got at [2] if anyone wants to use that as a basis for working on drivers, or for other discussion.
[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/
[2] https://github.com/bruce-richardson/dpdk/tree/dmadev-rfcsBruce Richardson (9):
dmadev: add missing exports
dmadev: change virtual addresses to IOVA
dmadev: add dump function
dmadev: remove xstats functions
dmadev: drop cookie typedef
dmadev: allow NULL parameters to completed ops call
dmadev: stats structure updates
drivers: add dma driver category
app/test: add basic dmadev unit testapp/test/meson.build | 2 + app/test/test_dmadev.c | 320 +++++++++++++++++++++++++++++++++++ drivers/dma/meson.build | 11 ++ drivers/meson.build | 1 + lib/dmadev/rte_dmadev.c | 66 ++------ lib/dmadev/rte_dmadev.h | 204 +++++++--------------- lib/dmadev/rte_dmadev_core.h | 16 +- lib/dmadev/rte_dmadev_pmd.h | 24 +-- lib/dmadev/version.map | 7 +- 9 files changed, 425 insertions(+), 226 deletions(-) create mode 100644 app/test/test_dmadev.c create mode 100644 drivers/dma/meson.build--
2.30.2.
PATCH v2 1/1 dmadev: introduce DMA device library
In reply to Chengwen FengThis patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
--- MAINTAINERS | 4 + config/rte_config.h | 3 + lib/dmadev/meson.build | 6 + lib/dmadev/rte_dmadev.c | 560 +++++++++++++++++++++++ lib/dmadev/rte_dmadev.h | 1030 ++++++++++++++++++++++++++++++++++++++++++ lib/dmadev/rte_dmadev_core.h | 159 +++++++ lib/dmadev/rte_dmadev_pmd.h | 72 +++ lib/dmadev/version.map | 40 ++ lib/meson.build | 1 + 9 files changed, 1875 insertions(+) create mode 100644 lib/dmadev/meson.build create mode 100644 lib/dmadev/rte_dmadev.c create mode 100644 lib/dmadev/rte_dmadev.h create mode 100644 lib/dmadev/rte_dmadev_core.h create mode 100644 lib/dmadev/rte_dmadev_pmd.h create mode 100644 lib/dmadev/version.map
MAINTAINERS +4 -0
@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst +DMA device API - EXPERIMENTAL +M: Chengwen Feng <[email protected]> +F: lib/dmadev/ + Memory Pool Drivers -------------------
config/rte_config.h +3 -0
@@ -81,6 +81,9 @@/* rawdev defines */ #define RTE_RAWDEV_MAX_DEVS 64 +/* dmadev defines */ +#define RTE_DMADEV_MAX_DEVS 64 +/* ip_fragmentation defines */ #define RTE_LIBRTE_IP_FRAG_MAX_FRAG 4#undef RTE_LIBRTE_IP_FRAG_TBL_STAT
lib/dmadev/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2021 HiSilicon Limited. + +sources = files('rte_dmadev.c') +headers = files('rte_dmadev.h', 'rte_dmadev_pmd.h') +indirect_headers += files('rte_dmadev_core.h')
lib/dmadev/rte_dmadev.c new file +560 -0
560 lines not on this page · raw message
lib/dmadev/rte_dmadev.h new file +1030 -0
1,030 lines not on this page · raw message
lib/dmadev/rte_dmadev_core.h new file +159 -0
159 lines not on this page · raw message
lib/dmadev/rte_dmadev_pmd.h new file +72 -0
72 lines not on this page · raw message
lib/dmadev/version.map new file +40 -0
@@ -0,0 +1,40 @@ +EXPERIMENTAL { + global: + + rte_dmadev_count; + rte_dmadev_info_get; + rte_dmadev_configure; + rte_dmadev_start; + rte_dmadev_stop; + rte_dmadev_close; + rte_dmadev_reset; + rte_dmadev_vchan_setup; + rte_dmadev_vchan_release; + rte_dmadev_stats_get; + rte_dmadev_stats_reset; + rte_dmadev_dump; + rte_dmadev_selftest; + rte_dmadev_copy; + rte_dmadev_copy_sg; + rte_dmadev_fill; + rte_dmadev_fill_sg; + rte_dmadev_submit; + rte_dmadev_completed; + rte_dmadev_completed_fails; + + local: *; +}; + +INTERNAL { + global: + + rte_dmadevices; + rte_dmadev_pmd_allocate; + rte_dmadev_pmd_release; + rte_dmadev_get_device_by_name; + + local: + + rte_dmadev_is_valid_dev; +}; +
lib/meson.build +1 -0
@@ -60,6 +60,7 @@ libraries = [ 'bpf', 'graph', 'node', + 'dmadev', ] if is_windows
Signature · 1 line
2.8.1
Note:
1) This patch hold dmadev <> vchan layer, I think vchan can be very conceptually separated from hw-channel.
2) I could not under struct dpi_dma_queue_ctx_s, so this patch I define the rte_dma_slave_port_parameters refer to Kunpeng DMA implemention.
3) This patch hasn't include doxy related file because failed to generate a doc in my environment, could this upstream as a new patch or must solved ?
Feedback welcome, thanks
Quoted 8 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
Quoted 4 lines · fengchengwen
Note:
1) This patch hold dmadev <> vchan layer, I think vchan can be very conceptually separated from hw-channel.
I would like to keep it as channel instead of virtual channel as it is implementation-specific.
No strong opinion on this? @Richardson, Bruce @Morten Brørup thoughts
Quoted 5 lines
2) I could not under struct
dpi_dma_queue_ctx_s, so this patch I define therte_dma_slave_port_parametersrefer to Kunpeng DMA implemention.
3) This patch hasn't include doxy related file because failed to generate a doc in my environment, could this upstream as a new patch or must solved ?
No IMO. The final version needs to be merged to should have split patch-like,
1) Header file with doxygen comments
2) Multiple patches for implementation as needed
3) Programmer guide doc
Other items, Typically we will have per new device class.
1) Skelton driver(can use memcpy in this case)
2) app/test-dmadev kind of application.(Can be used to measure performance and functionality)
Quoted 13 lines
Feedback welcome, thanks
Quoted 8 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
Quoted 5 lines
From: dev [mailto:[email protected]] On Behalf Of Jerin Jacob
Quoted 1 line · fengchengwen
Quoted 7 lines
Quoted 3 lines
Note:
1) This patch hold dmadev <> vchan layer, I think vchan can be very conceptually separated from hw-channel.I would like to keep it as channel instead of virtual channel as it is implementation-specific.
No strong opinion on this? @Richardson, Bruce @Morten Brørup thoughts
Consider using "context" or "ctx" instead. I might help avoid being mistaken as a DMA hardware feature.
No strong opinion, though. Whatever fits nicely in the documentation is a good choice.
A small anecdote: We once had to name an important parameter in our product, and it came down to the choice of two perfectly good names. We chose the shortest name, only because it fit better into the GUI.
Quoted 5 lines
Quoted 2 lines
2) I could not under struct
dpi_dma_queue_ctx_s, so this patch Idefine
Quoted 1 line
the
rte_dma_slave_port_parametersrefer to Kunpeng DMAimplemention.
One more thing:
The DPDK project is aiming to use inclusive code language. (Ref: https://www.dpdk.org/blog/2020/07/22/dpdk-governing-board-update-july-2020/)
Please replace the word "slave" with something politically correct.
-Morten
Quoted 42 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>lib/dmadev/rte_dmadev.h new file +28
-0@@ -0,0 +1,1030 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2021 HiSilicon Limited. +* Copyright(c) 2021 Intel Corporation. +* Copyright(c) 2021 Marvell International Ltd. +*/ + +#ifndef _RTE_DMADEV_H_ +#define _RTE_DMADEV_H_ + +/** +* @file rte_dmadev.h +* +* RTE DMA (Direct Memory Access) device APIs. +* +* The DMA framework is built on the following model: +* +* --------------- --------------- --------------- +* | virtual DMA | | virtual DMA | | virtual DMA | +* | channel | | channel | | channel | +* --------------- --------------- --------------- +* | | | +* ------------------ | +* | | +* ------------ ------------ +* | dmadev | | dmadev | +* ------------ ------------ +* | | +* ------------------ ------------------
lib/dmadev/rte_dmadev.h line 38
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* | HW-DMA-channel | | HW-DMA-channel | +* ------------------ ------------------ +* | | +* -------------------------------- +* | +* --------------------- +* | HW-DMA-Controller | +* --------------------- +* +* The DMA controller could have multilpe HW-DMA-channels (aka. HW-DMA-queues),
Typo - multiple
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+* each HW-DMA-channel should be represented by a dmadev. +* +* The dmadev could create multiple virtual DMA channel, each virtual DMA +* channel represents a different transfer context. The DMA operation request +* must be submitted to the virtual DMA channel.
lib/dmadev/rte_dmadev.h line 53
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* E.G. Application could create virtual DMA channel 0 for mem-to-mem transfer +* scenario, and create virtual DMA channel 1 for mem-to-dev transfer +* scenario. +* +* The dmadev are dynamically allocated by rte_dmadev_pmd_allocate() during the +* PCI/SoC device probing phase performed at EAL initialization time. And could +* be released by rte_dmadev_pmd_release() during the PCI/SoC device removing +* phase. +* +* We use 'uint16_t dev_id' as the device identifier of a dmadev, and
Please remove "We use" and reword accordingly.
Quoted 66 lines
lib/dmadev/rte_dmadev.h new file +66
-0+* 'uint16_t vchan' as the virtual DMA channel identifier in one dmadev. +* +* The functions exported by the dmadev API to setup a device designated by its +* device identifier must be invoked in the following order: +* - rte_dmadev_configure() +* - rte_dmadev_vchan_setup() +* - rte_dmadev_start() +* +* Then, the application can invoke dataplane APIs to process jobs. +* +* If the application wants to change the configuration (i.e. call +* rte_dmadev_configure()), it must call rte_dmadev_stop() first to stop the +* device and then do the reconfiguration before calling rte_dmadev_start() +* again. The dataplane APIs should not be invoked when the device is stopped. +* +* Finally, an application can close a dmadev by invoking the +* rte_dmadev_close() function. +* +* The dataplane APIs include two parts: +* a) The first part is the submission of operation requests: +* - rte_dmadev_copy() +* - rte_dmadev_copy_sg() - scatter-gather form of copy +* - rte_dmadev_fill() +* - rte_dmadev_fill_sg() - scatter-gather form of fill +* - rte_dmadev_perform() - issue doorbell to hardware +* These APIs could work with different virtual DMA channels which have +* different contexts. +* The first four APIs are used to submit the operation request to the +* virtual DMA channel, if the submission is successful, a uint16_t +* ring_idx is returned, otherwise a negative number is returned. +* b) The second part is to obtain the result of requests: +* - rte_dmadev_completed() +* - return the number of operation requests completed successfully. +* - rte_dmadev_completed_fails() +* - return the number of operation requests failed to complete. +* +* About the ring_idx which rte_dmadev_copy/copy_sg/fill/fill_sg() returned, +* the rules are as follows: +* a) ring_idx for each virtual DMA channel are independent. +* b) For a virtual DMA channel, the ring_idx is monotonically incremented, +* when it reach UINT16_MAX, it wraps back to zero. +* c) The initial ring_idx of a virtual DMA channel is zero, after the device +* is stopped or reset, the ring_idx needs to be reset to zero. +* Example: +* step-1: start one dmadev +* step-2: enqueue a copy operation, the ring_idx return is 0 +* step-3: enqueue a copy operation again, the ring_idx return is 1 +* ... +* step-101: stop the dmadev +* step-102: start the dmadev +* step-103: enqueue a copy operation, the cookie return is 0 +* ... +* step-x+0: enqueue a fill operation, the ring_idx return is 65535 +* step-x+1: enqueue a copy operation, the ring_idx return is 0 +* ... +* +* By default, all the non-dataplane functions of the dmadev API exported by a +* PMD are lock-free functions which assume to not be invoked in parallel on +* different logical cores to work on the same target object. +* +* The dataplane functions of the dmadev API exported by a PMD can be MT-safe +* only when supported by the driver, generally, the driver will reports two +* capabilities: +* a) Whether to support MT-safe for the submit/completion API of the same +* virtual DMA channel. +* E.G. one thread do submit operation, another thread do completion
lib/dmadev/rte_dmadev.h line 129
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* operation. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_VCHAN. +* If driver don't support it, it's up to the application to guarantee +* MT-safe. +* b) Whether to support MT-safe for different virtual DMA channels. +* E.G. one thread do operation on virtual DMA channel 0, another thread +* do operation on virtual DMA channel 1. +* If driver support it, then declare RTE_DMA_DEV_CAPA_MT_MULTI_VCHAN. +* If driver don't support it, it's up to the application to guarantee +* MT-safe.
The above cases make it difficult to write applications . Also, application locking using spinlock
etc may not better optimization.(If an driver can do it better way). IMO, As discussed with @Morten Brørup ,
I think, it is better while configuring the channel application can specify, do they "need" MT safe to
have a portable application.Unlike network or crypto device, Since we are creating the virtual channel
such scheme is useful.
Quoted 6 lines
lib/dmadev/rte_dmadev.h new file +6
-0+* +*/ + +#include <rte_common.h> +#include <rte_compat.h> +#include <rte_errno.h>
lib/dmadev/rte_dmadev.h line 145
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+#include <rte_memory.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define RTE_DMADEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN + +extern int rte_dmadev_logtype; +
Missing Doxygen comment
lib/dmadev/rte_dmadev.h line 148
Quoted 3 lines
lib/dmadev/rte_dmadev.h new file +3
-0+#define RTE_DMADEV_LOG (level, ...) \ + rte_log(RTE_LOG_ ## level, rte_dmadev_logtype, "" __VA_ARGS__) +
Make it as internal.
lib/dmadev/rte_dmadev.h line 156
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+/* Macros to check for valid port */ +#define RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, retval) do { \ + if (!rte_dmadev_is_valid_dev(dev_id)) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \ + return retval; \ + } \ +} while (0) +
Make it as internal.
lib/dmadev/rte_dmadev.h line 165
Quoted 9 lines
lib/dmadev/rte_dmadev.h new file +9
-0+#define RTE_DMADEV_VALID_DEV_ID_OR_RET (dev_id) do { \ + if (!rte_dmadev_is_valid_dev(dev_id)) { \ + RTE_DMADEV_LOG(ERR, "Invalid dev_id=%u\n", dev_id); \ + return; \ + } \ +} while (0) + +/** +* @internal
We can make it as a public API.
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+* Validate if the DMA device index is a valid attached DMA device. +* +* @param dev_id +* DMA device index. +* +* @return +* - If the device index is valid (true) or not (false). +*/
lib/dmadev/rte_dmadev.h line 183
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+__rte_internal +bool +rte_dmadev_is_valid_dev (uint16_t dev_id); + +/** +* rte_dma_sg - can hold scatter DMA operation request +*/ +struct rte_dma_sg { +rte_iova_t src; +rte_iova_t dst;
IMO, it should be only rte_iova_t addr. See comment at _sg API
Quoted 17 lines
lib/dmadev/rte_dmadev.h new file +17
-0+uint32_t length; +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Get the total number of DMA devices that have been successfully +* initialised. +* +* @return +* The total number of usable DMA devices. +*/ +__rte_experimental +uint16_t +rte_dmadev_count (void ); +
lib/dmadev/rte_dmadev.h line 210
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+/** +* The capabilities of a DMA device +*/ +#define RTE_DMA_DEV_CAPA_MEM_TO_MEM (1ull << 0) +/**< DMA device support mem-to-mem transfer. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_MEM_TO_DEV (1ull << 1) +/**< DMA device support slave mode & mem-to-dev transfer.
Do we need to say slave mode? Just mem to dev is fine. Right?
lib/dmadev/rte_dmadev.h line 215
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_DEV_TO_MEM (1ull << 2) +/**< DMA device support slave mode & dev-to-mem transfer.
See above.
lib/dmadev/rte_dmadev.h line 220
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_DEV_TO_DEV (1ull << 3) +/**< DMA device support slave mode & dev-to-dev transfer.
See above.
Quoted 48 lines
lib/dmadev/rte_dmadev.h new file +48
-0+* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_OPS_COPY (1ull << 4) +/**< DMA device support copy ops. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_OPS_FILL (1ull << 5) +/**< DMA device support fill ops. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_OPS_SG (1ull << 6) +/**< DMA device support scatter-list ops. +* If device support ops_copy and ops_sg, it means supporting copy_sg ops. +* If device support ops_fill and ops_sg, it means supporting fill_sg ops. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_FENCE (1ull << 7) +/**< DMA device support fence. +* If device support fence, then application could set a fence flags when +* enqueue operation by rte_dma_copy/copy_sg/fill/fill_sg. +* If a operation has a fence flags, it means the operation must be processed +* only after all previous operations are completed. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_SVA (1ull << 8) +/**< DMA device support SVA which could use VA as DMA address. +* If device support SVA then application could pass any VA address like memory +* from rte_malloc(), rte_memzone(), malloc, stack memory. +* If device don't support SVA, then application should pass IOVA address which +* from rte_malloc(), rte_memzone(). +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_MT_VCHAN (1ull << 9) +/**< DMA device support MT-safe of a virtual DMA channel. +* +* @see struct rte_dmadev_info::dev_capa +*/ +#define RTE_DMA_DEV_CAPA_MT_MULTI_VCHAN (1ull << 10) +/**< DMA device support MT-safe of different virtual DMA channels. +* +* @see struct rte_dmadev_info::dev_capa +*/
lib/dmadev/rte_dmadev.h line 278
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ +/** +* A structure used to retrieve the contextual information of +* an DMA device +*/ +struct rte_dmadev_info { +struct rte_device *device;/**< Generic Device information */ +uint64_t dev_capa;/**< Device capabilities (RTE_DMA_DEV_CAPA_) */ +/** Maximum number of virtual DMA channels supported */ +uint16_t max_vchans;
Doxygen comment should come after the symbol. Not above.
Quoted 37 lines
lib/dmadev/rte_dmadev.h new file +37
-0+/** Maximum allowed number of virtual DMA channel descriptors */ +uint16_t max_desc; +/** Minimum allowed number of virtual DMA channel descriptors */ +uint16_t min_desc; +uint16_t nb_vchans;/**< Number of virtual DMA channel configured */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve the contextual information of a DMA device. +* +* @param dev_id +* The identifier of the device. +* @param[out] dev_info +* A pointer to a structure of type *rte_dmadev_info* to be filled with the +* contextual information of the device. +* +* @return +* - =0: Success, driver updates the contextual information of the DMA device +* - <0: Error code returned by the driver info get function. +* +*/ +__rte_experimental +int +rte_dmadev_info_get (uint16_t dev_id,struct rte_dmadev_info *dev_info); + +/** +* A structure used to configure a DMA device. +*/ +struct rte_dmadev_conf { +/** Maximum number of virtual DMA channel to use. +* This value cannot be greater than the field 'max_vchans' of struct +* rte_dmadev_info which get from rte_dmadev_info_get(). +*/ +uint16_t max_vchans;
lib/dmadev/rte_dmadev.h line 325
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+/** Enable bit for MT-safe of a virtual DMA channel. +* This bit can be enabled only when the device supports +* RTE_DMA_DEV_CAPA_MT_VCHAN. +* @see RTE_DMA_DEV_CAPA_MT_VCHAN +*/ + uint8_t enable_mt_vchan : 1; +/** Enable bit for MT-safe of different virtual DMA channels. +* This bit can be enabled only when the device supports +* RTE_DMA_DEV_CAPA_MT_MULTI_VCHAN. +* @see RTE_DMA_DEV_CAPA_MT_MULTI_VCHAN
I think, we can support this even if the flag is not supported to limit the application fastpath options.
Quoted 97 lines
lib/dmadev/rte_dmadev.h new file +97
-0+*/ + uint8_t enable_mt_multi_vchan : 1; +uint64_t reserved[2 ];/**< Reserved for future fields */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Configure a DMA device. +* +* This function must be invoked first before any other function in the +* API. This function can also be re-invoked when a device is in the +* stopped state. +* +* @param dev_id +* The identifier of the device to configure. +* @param dev_conf +* The DMA device configuration structure encapsulated into rte_dmadev_conf +* object. +* +* @return +* - =0: Success, device configured. +* - <0: Error code returned by the driver configuration function. +*/ +__rte_experimental +int +rte_dmadev_configure (uint16_t dev_id,const struct rte_dmadev_conf *dev_conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Start a DMA device. +* +* The device start step is the last one and consists of setting the DMA +* to start accepting jobs. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device started. +* - <0: Error code returned by the driver start function. +*/ +__rte_experimental +int +rte_dmadev_start (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Stop a DMA device. +* +* The device can be restarted with a call to rte_dmadev_start() +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Success, device stopped. +* - <0: Error code returned by the driver stop function. +*/ +__rte_experimental +int +rte_dmadev_stop (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Close a DMA device. +* +* The device cannot be restarted after this call. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - =0: Successfully close device +* - <0: Failure to close device +*/ +__rte_experimental +int +rte_dmadev_close (uint16_t dev_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset a DMA device. +* +* This is different from cycle of rte_dmadev_start->rte_dmadev_stop in the +* sense similar to hard or soft reset. +* +* @param dev_id
lib/dmadev/rte_dmadev.h line 432
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* The identifier of the device. +* +* @return +* - =0: Successfully reset device. +* - <0: Failure to reset device. +* - (-ENOTSUP): If the device doesn't support this function. +*/ +__rte_experimental +int +rte_dmadev_reset (uint16_t dev_id);
Is this required now?
lib/dmadev/rte_dmadev.h line 437
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* DMA transfer direction defines. +*/ +#define RTE_DMA_MEM_TO_MEM (1ull << 0)
RTE_DMA_DIRECTION_...
Quoted 26 lines
lib/dmadev/rte_dmadev.h new file +26
-0+/**< DMA transfer direction - from memory to memory. +* +* @see struct rte_dmadev_vchan_conf::direction +*/ +#define RTE_DMA_MEM_TO_DEV (1ull << 1) +/**< DMA transfer direction - slave mode & from memory to device. +* In a typical scenario, ARM SoCs are installed on x86 servers as iNICs. In +* this case, the ARM SoCs works in slave mode, it could initiate a DMA move +* request from ARM memory to x86 host memory. +* +* @see struct rte_dmadev_vchan_conf::direction +*/ +#define RTE_DMA_DEV_TO_MEM (1ull << 2) +/**< DMA transfer direction - slave mode & from device to memory. +* In a typical scenario, ARM SoCs are installed on x86 servers as iNICs. In +* this case, the ARM SoCs works in slave mode, it could initiate a DMA move +* request from x86 host memory to ARM memory. +* +* @see struct rte_dmadev_vchan_conf::direction +*/ +#define RTE_DMA_DEV_TO_DEV (1ull << 3) +/**< DMA transfer direction - slave mode & from device to device. +* In a typical scenario, ARM SoCs are installed on x86 servers as iNICs. In +* this case, the ARM SoCs works in slave mode, it could initiate a DMA m> + * request from x86 host memory to another x86 host memory. +* +* @see struct rte_dmadev_vchan_conf::direction
lib/dmadev/rte_dmadev.h line 474
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+*/ +#define RTE_DMA_TRANSFER_DIR_ALL (RTE_DMA_MEM_TO_MEM | \ + RTE_DMA_MEM_TO_DEV | \ + RTE_DMA_DEV_TO_MEM | \ + RTE_DMA_DEV_TO_DEV) + +/** +* enum rte_dma_slave_port_type - slave mode type defines +*/ +enum rte_dma_slave_port_type {
I think, rte_dmadev_dev_type
lib/dmadev/rte_dmadev.h line 482
Quoted 8 lines
lib/dmadev/rte_dmadev.h new file +8
-0+/** The slave port is PCIE. */ + RTE_DMA_SLAVE_PORT_PCIE = 1, +}; + +/** +* A structure used to descript slave port parameters.* +*/ +struct rte_dma_slave_port_parameters {
May be rte_dmadev_dev_conf?
Quoted 12 lines
lib/dmadev/rte_dmadev.h new file +12
-0+enum rte_dma_slave_port_type port_type; +union { +/** For PCIE port */ +struct { +/** The physical function number which to use */ +uint64_t pf_number :6 ; +/** Virtual function enable bit */ +uint64_t vf_enable :1 ; +/** The virtual function number which to use */ +uint64_t vf_number :8 ; +uint64_t pasid :20 ; +/** The attributes filed in TLP packet */
lib/dmadev/rte_dmadev.h line 504
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+ uint64_t tlp_attr : 3; + }; + }; +}; + +/** +* A structure used to configure a virtual DMA channel. +*/ +struct rte_dmadev_vchan_conf { +uint8_t direction;/**< Set of supported transfer directions */
We could add @see RTE_DMA_DIRECTION_*.
Also, say, how the application can know the valid flags.aka point to info.
Quoted 46 lines
lib/dmadev/rte_dmadev.h new file +46
-0+/** Number of descriptor for the virtual DMA channel */ +uint16_t nb_desc; +/** 1) Used to describes the dev parameter in the mem-to-dev/dev-to-mem +* transfer scenario. +* 2) Used to describes the src dev parameter in the dev-to-dev +* transfer scenario. +*/ +struct rte_dma_slave_port_parameters port; +/** Used to describes the dst dev parameters in the dev-to-dev +* transfer scenario. +*/ +struct rte_dma_slave_port_parameters peer_port; +uint64_t reserved[2 ];/**< Reserved for future fields */ +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Allocate and set up a virtual DMA channel. +* +* @param dev_id +* The identifier of the device. +* @param conf +* The virtual DMA channel configuration structure encapsulated into +* rte_dmadev_vchan_conf object. +* +* @return +* - >=0: Allocate success, it is the virtual DMA channel id. This value must +* be less than the field 'max_vchans' of struct rte_dmadev_conf +which configured by rte_dmadev_configure(). +* - <0: Error code returned by the driver virtual channel setup function. +*/ +__rte_experimental +int +rte_dmadev_vchan_setup (uint16_t dev_id, +const struct rte_dmadev_vchan_conf *conf); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Release a virtual DMA channel. +* +* @param dev_id +* The identifier of the device.
lib/dmadev/rte_dmadev.h line 560
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* @param vchan +* The identifier of virtual DMA channel which return by vchan setup. +* +* @return +* - =0: Successfully release the virtual DMA channel. +* - <0: Error code returned by the driver virtual channel release function. +*/ +__rte_experimental +int +rte_dmadev_vchan_release (uint16_t dev_id,uint16_t vchan);
We are not making release as pubic API in other device class. See ethdev spec.
Quoted 5 lines
lib/dmadev/rte_dmadev.h new file +5
-0+ +/** +* rte_dmadev_stats - running statistics. +*/ +struct rte_dmadev_stats {
lib/dmadev/rte_dmadev.h line 575
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+/** Count of operations which were successfully enqueued */ +uint64_t enqueued_count; +/** Count of operations which were submitted to hardware */ +uint64_t submitted_count; +/** Count of operations which failed to complete */ +uint64_t completed_fail_count; +/** Count of operations which successfully complete */ +uint64_t completed_count; +uint64_t reserved[4 ];/**< Reserved for future fields */ +};
Please add the capability for each counter in info structure as one device may support all
the counters.
Quoted 75 lines
lib/dmadev/rte_dmadev.h new file +75
-0+/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Retrieve basic statistics of a or all virtual DMA channel(s). +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel, -1 means all channels. +* @param[out] stats +* The basic statistics structure encapsulated into rte_dmadev_stats +* object. +* +* @return +* - =0: Successfully retrieve stats. +* - <0: Failure to retrieve stats. +*/ +__rte_experimental +int +rte_dmadev_stats_get (uint16_t dev_id,int vchan, +struct rte_dmadev_stats *stats); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Reset basic statistics of a or all virtual DMA channel(s). +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel, -1 means all channels. +* +* @return +* - =0: Successfully reset stats. +* - <0: Failure to reset stats. +*/ +__rte_experimental +int +rte_dmadev_stats_reset (uint16_t dev_id,int vchan); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Dump DMA device info. +* +* @param dev_id +* The identifier of the device. +* @param f +* The file to write the output to. +* +* @return +* 0 on success. Non-zero otherwise. +*/ +__rte_experimental +int +rte_dmadev_dump (uint16_t dev_id,FILE *f); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger the dmadev self test. +* +* @param dev_id +* The identifier of the device. +* +* @return +* - 0: Selftest successful. +* - -ENOTSUP if the device doesn't support selftest +* - other values < 0 on failure. +*/ +__rte_experimental
lib/dmadev/rte_dmadev.h line 661
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+int +rte_dmadev_selftest (uint16_t dev_id); + +#include "rte_dmadev_core.h" + +/** +* DMA flags to augment operation preparation. +* Used as the 'flags' parameter of rte_dmadev_copy/copy_sg/fill/fill_sg. +*/ +#define RTE_DMA_FLAG_FENCE (1ull << 0)
RTE_DMA_OP_FLAG_FENCE
Please add also add RTE_DMA_OP_FLAG_SUMBIT as we discussed in another thread. We can support submit based on the flag and _submit() version based on application preference.
Quoted 21 lines
lib/dmadev/rte_dmadev.h new file +21
-0+/**< DMA fence flag +* It means the operation with this flag must be processed only after all +* previous operations are completed. +* +* @see rte_dmadev_copy() +* @see rte_dmadev_copy_sg() +* @see rte_dmadev_fill() +* @see rte_dmadev_fill_sg() +*/ + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a copy operation onto the virtual DMA channel. +* +* This queues up a copy operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device.
lib/dmadev/rte_dmadev.h line 692
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* @param vchan +* The identifier of virtual DMA channel. +* @param src +* The address of the source buffer. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the data to be copied. +* @param flags +* An flags for this operation.
See RTE_DMA_OP_FLAG_*
Quoted 39 lines
lib/dmadev/rte_dmadev.h new file +38
-0+* +* @return +* - 0..UINT16_MAX: index of enqueued copy job. +* - <0: Error code returned by the driver copy function. +*/ +__rte_experimental +static inline int +rte_dmadev_copy (uint16_t dev_id,uint16_t vchan,rte_iova_t src,rte_iova_t dst, +uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->copy, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->copy)(dev, vchan, src, dst, length, flags)> + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list copy operation onto the virtual DMA channel. +* +* This queues up a scatter list copy operation to be performed by hardware, +* but does not trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param sg +* The pointer of scatterlist. +* @param sg_len +* The number of scatterlist elements. +* @param flags
lib/dmadev/rte_dmadev.h line 742
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* An flags for this operation. +* +* @return +* - 0..UINT16_MAX: index of enqueued copy job. +* - <0: Error code returned by the driver copy function. +*/ +__rte_experimental +static inline int +rte_dmadev_copy_sg (uint16_t dev_id,uint16_t vchan,const struct rte_dma_sg *sg, +uint32_t sg_len,uint64_t flags)
As requested earlier, I prefer to have
rte_dmadev_copy_sg(uint16_t dev_id, uint16_t vchan, const struct rte_dma_sg *src, uint32_t nb_src, const struct rte_dma_sg *dst, uint32_t nb_dst, uint64_t flags)
Quoted 45 lines
lib/dmadev/rte_dmadev.h new file +45
-0+{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (sg, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->copy_sg, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->copy_sg)(dev, vchan, sg, sg_len, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a fill operation onto the virtual DMA channel. +* +* This queues up a fill operation to be performed by hardware, but does not +* trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param pattern +* The pattern to populate the destination buffer with. +* @param dst +* The address of the destination buffer. +* @param length +* The length of the destination buffer. +* @param flags +* An flags for this operation. +* +* @return +* - 0..UINT16_MAX: index of enqueued copy job. +* - <0: Error code returned by the driver copy function. +*/ +__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{
lib/dmadev/rte_dmadev.h line 797
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags);
Instead of every driver set the NOP function, In the common code, If the CAPA is not set,
common code can set NOP function for this with <0 return value.
Quoted 35 lines
lib/dmadev/rte_dmadev.h new file +35
-0+} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Enqueue a scatter list fill operation onto the virtual DMA channel. +* +* This queues up a scatter list fill operation to be performed by hardware, +* but does not trigger hardware to begin that operation. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param pattern +* The pattern to populate the destination buffer with. +* @param sg +* The pointer of scatterlist. +* @param sg_len +* The number of scatterlist elements. +* @param flags +* An flags for this operation. +* +* @return +* - 0..UINT16_MAX: index of enqueued copy job. +* - <0: Error code returned by the driver copy function. +*/ +__rte_experimental +static inline int +rte_dmadev_fill_sg (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +const struct rte_dma_sg *sg,uint32_t sg_len, +uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id];
lib/dmadev/rte_dmadev.h line 842
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (sg, -ENOTSUP ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill_sg)(dev, vchan, pattern, sg, sg_len, flags);
In order to save 8B in rte_dmadev this API can be removed as looks like none of the drivers supports fill in sg mode.
Quoted 122 lines
lib/dmadev/rte_dmadev.h new file +122
-0+} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Trigger hardware to begin performing enqueued operations. +* +* This API is used to write the "doorbell" to the hardware to trigger it +* to begin the operations previously enqueued by rte_dmadev_copy/fill() +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* +* @return +* - =0: Successfully trigger hardware. +* - <0: Failure to trigger hardware. +*/ +__rte_experimental +static inline int +rte_dmadev_submit (uint16_t dev_id,uint16_t vchan) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->submit, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->submit)(dev, vchan); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in. +* @param[out] has_error +* Indicates if there are transfer error. +* If not required, NULL can be passed in. +* +* @return +* The number of operations that successfully completed. +*/ +__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vchan,const uint16_t nb_cpls, +uint16_t *last_idx,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +uint16_t idx; +bool err; + +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->completed, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +if (nb_cpls ==0 ) { +RTE_DMADEV_LOG (ERR ,"Invalid nb_cpls\n" ); +return -EINVAL ; + } +#endif + +/* Ensure the pointer values are non-null to simplify drivers. +* In most cases these should be compile time evaluated, since this is +* an inline function. +* - If NULL is explicitly passed as parameter, then compiler knows the +* value is NULL +* - If address of local variable is passed as parameter, then compiler +* can know it's non-NULL. +*/ +if (last_idx ==NULL ) + last_idx = &idx; +if (has_error ==NULL ) + has_error = &err; + + *has_error = false; +return (*dev->completed)(dev, vchan, nb_cpls, last_idx, has_error); +} + +/** +* DMA transfer status code defines +*/ +enum rte_dma_status_code { +/** The operation completed successfully */ +RTE_DMA_STATUS_SUCCESSFUL =0 , +/** The operation failed to complete due active drop +* This is mainly used when processing dev_stop, allow outstanding +* requests to be completed as much as possible. +*/ +RTE_DMA_STATUS_ACTIVE_DROP , +/** The operation failed to complete due invalid source address */ +RTE_DMA_STATUS_INVALID_SRC_ADDR , +/** The operation failed to complete due invalid destination address */ +RTE_DMA_STATUS_INVALID_DST_ADDR , +/** The operation failed to complete due invalid length */ +RTE_DMA_STATUS_INVALID_LENGTH , +/** The operation failed to complete due invalid opcode +* The DMA descriptor could have multiple format, which are +* distinguished by the opcode field. +*/ +RTE_DMA_STATUS_INVALID_OPCODE , +/** The operation failed to complete due bus err */ +RTE_DMA_STATUS_BUS_ERROR , +/** The operation failed to complete due data poison */
lib/dmadev/rte_dmadev.h line 974
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+RTE_DMA_STATUS_DATA_POISION , +/** The operation failed to complete due descriptor read error */ +RTE_DMA_STATUS_DESCRIPTOR_READ_ERROR , +/** The operation failed to complete due device link error +* Used to indicates that the link error in the mem-to-dev/dev-to-mem/ +* dev-to-dev transfer scenario. +*/ + RTE_DMA_STATUS_DEV_LINK_ERROR, +/** Driver specific status code offset +* Start status code for the driver to define its own error code.
RTE_DMA_STATUS_UNKNOWN for the ones which are not added in public API spec.
Quoted 21 lines
lib/dmadev/rte_dmadev.h new file +21
-0+*/ + RTE_DMA_STATUS_DRV_SPECIFIC_OFFSET = 0x10000, +}; + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that failed to complete. +* NOTE: This API was used when rte_dmadev_completed has_error was set. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_status +* Indicates the size of status array. +* @param[out] status +* The error code of operations that failed to complete. +* Some standard error code are described in 'enum rte_dma_status_code' +* @see rte_dma_status_code
lib/dmadev/rte_dmadev.h line 1005
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* @param[out] last_idx +* The last failed completed operation's index. +* +* @return +* The number of operations that failed to complete. +*/ +__rte_experimental +static inline uint16_t +rte_dmadev_completed_fails(uint16_t dev_id, uint16_t vchan, + const uint16_t nb_status, uint32_t *status,
uint32_t -> enum rte_dma_status_code
Quoted 46 lines
lib/dmadev/rte_dmadev.h new file +25
-0+ uint16_t *last_idx) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (status, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (last_idx, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->completed_fails, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +if (nb_status ==0 ) { +RTE_DMADEV_LOG (ERR ,"Invalid nb_status\n" ); +return -EINVAL ; + } +#endif +return (*dev->completed_fails)(dev, vchan, nb_status, status, last_idx); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_H_ */ lib/dmadev/rte_dmadev_core.h new file +15
-0@@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2021 HiSilicon Limited. +* Copyright(c) 2021 Intel Corporation. +*/ + +#ifndef _RTE_DMADEV_CORE_H_ +#define _RTE_DMADEV_CORE_H_ + +/** +* @file +* +* RTE DMA Device internal header. +* +* This header contains internal data types, that are used by the DMA devices +* in order to expose their ops to the class.
lib/dmadev/rte_dmadev_core.h line 25
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+* +* Applications should not use these API directly. +* +*/ + +struct rte_dmadev ; + +/** @internal Used to get device information of a device. */ +typedef int (*dmadev_info_get_t )(struct rte_dmadev *dev, +struct rte_dmadev_info *dev_info);
Please change to rte_dmadev_info_get_t to avoid conflict due to namespace issue as this header is exported.
Quoted 111 lines
lib/dmadev/rte_dmadev_core.h new file +111
-0+ +/** @internal Used to configure a device. */ +typedef int (*dmadev_configure_t )(struct rte_dmadev *dev, +const struct rte_dmadev_conf *dev_conf); + +/** @internal Used to start a configured device. */ +typedef int (*dmadev_start_t )(struct rte_dmadev *dev); + +/** @internal Used to stop a configured device. */ +typedef int (*dmadev_stop_t )(struct rte_dmadev *dev); + +/** @internal Used to close a configured device. */ +typedef int (*dmadev_close_t )(struct rte_dmadev *dev); + +/** @internal Used to reset a configured device. */ +typedef int (*dmadev_reset_t )(struct rte_dmadev *dev); + +/** @internal Used to allocate and set up a virtual DMA channel. */ +typedef int (*dmadev_vchan_setup_t )(struct rte_dmadev *dev, +const struct rte_dmadev_vchan_conf *conf); + +/** @internal Used to release a virtual DMA channel. */ +typedef int (*dmadev_vchan_release_t )(struct rte_dmadev *dev,uint16_t vchan); + +/** @internal Used to retrieve basic statistics. */ +typedef int (*dmadev_stats_get_t )(struct rte_dmadev *dev,int vchan, +struct rte_dmadev_stats *stats); + +/** @internal Used to reset basic statistics. */ +typedef int (*dmadev_stats_reset_t )(struct rte_dmadev *dev,int vchan); + +/** @internal Used to dump internal information. */ +typedef int (*dmadev_dump_t )(struct rte_dmadev *dev,FILE *f); + +/** @internal Used to start dmadev selftest. */ +typedef int (*dmadev_selftest_t )(uint16_t dev_id); + +/** @internal Used to enqueue a copy operation. */ +typedef int (*dmadev_copy_t )(struct rte_dmadev *dev,uint16_t vchan, +rte_iova_t src,rte_iova_t dst, +uint32_t length,uint64_t flags); + +/** @internal Used to enqueue a scatter list copy operation. */ +typedef int (*dmadev_copy_sg_t )(struct rte_dmadev *dev,uint16_t vchan, +const struct rte_dma_sg *sg, +uint32_t sg_len,uint64_t flags); + +/** @internal Used to enqueue a fill operation. */ +typedef int (*dmadev_fill_t )(struct rte_dmadev *dev,uint16_t vchan, +uint64_t pattern,rte_iova_t dst, +uint32_t length,uint64_t flags); + +/** @internal Used to enqueue a scatter list fill operation. */ +typedef int (*dmadev_fill_sg_t )(struct rte_dmadev *dev,uint16_t vchan, +uint64_t pattern,const struct rte_dma_sg *sg, +uint32_t sg_len,uint64_t flags); + +/** @internal Used to trigger hardware to begin working. */ +typedef int (*dmadev_submit_t )(struct rte_dmadev *dev,uint16_t vchan); + +/** @internal Used to return number of successful completed operations. */ +typedef uint16_t (*dmadev_completed_t )(struct rte_dmadev *dev,uint16_t vchan, +const uint16_t nb_cpls, +uint16_t *last_idx,bool *has_error); + +/** @internal Used to return number of failed completed operations. */ +typedef uint16_t (*dmadev_completed_fails_t )(struct rte_dmadev *dev, +uint16_t vchan,const uint16_t nb_status, +uint32_t *status,uint16_t *last_idx); + +/** +* DMA device operations function pointer table +*/ +struct rte_dmadev_ops { +dmadev_info_get_t dev_info_get; +dmadev_configure_t dev_configure; +dmadev_start_t dev_start; +dmadev_stop_t dev_stop; +dmadev_close_t dev_close; +dmadev_reset_t dev_reset; +dmadev_vchan_setup_t vchan_setup; +dmadev_vchan_release_t vchan_release; +dmadev_stats_get_t stats_get; +dmadev_stats_reset_t stats_reset; +dmadev_dump_t dev_dump; +dmadev_selftest_t dev_selftest; +}; + +/** +* @internal +* The data part, with no function pointers, associated with each DMA device. +* +* This structure is safe to place in shared memory to be common among different +* processes in a multi-process configuration. +*/ +struct rte_dmadev_data { +uint16_t dev_id;/**< Device [external] identifier. */ +char dev_name[RTE_DMADEV_NAME_MAX_LEN ];/**< Unique identifier name */ +void *dev_private;/**< PMD-specific private data. */ +struct rte_dmadev_conf dev_conf;/**< DMA device configuration. */ +uint8_t dev_started :1 ;/**< Device state: STARTED(1)/STOPPED(0). */ +uint64_t reserved[4 ];/**< Reserved for future fields */ +} __rte_cache_aligned; + +/** +* @internal +* The generic data structure associated with each DMA device. +* +* The dataplane APIs are located at the beginning of the structure, along +* with the pointer to where all the data elements for the particular device +* are stored in shared memory. This split scheme allows the function pointer
lib/dmadev/rte_dmadev_core.h line 146
Quoted 10 lines
lib/dmadev/rte_dmadev_core.h new file +10
-0+* and driver data to be per-process, while the actual configuration data for +* the device is shared. +*/ +struct rte_dmadev { +dmadev_copy_t copy; +dmadev_copy_sg_t copy_sg; +dmadev_fill_t fill; +dmadev_fill_sg_t fill_sg; +dmadev_submit_t submit; +dmadev_completed_t completed;
We could add reserved here for any fastpath future additions.
Quoted 154 lines
lib/dmadev/rte_dmadev_core.h new file +13
-0+dmadev_completed_fails_t completed_fails; +const struct rte_dmadev_ops *dev_ops;/**< Functions exported by PMD. */ +/** Flag indicating the device is attached: ATTACHED(1)/DETACHED(0). */ + uint8_t attached : 1; +/** Device info which supplied during device initialization. */ +struct rte_device *device; +struct rte_dmadev_data *data;/**< Pointer to device data. */ + uint64_t reserved[4]; /**< Reserved for future fields */ +} __rte_cache_aligned; + +extern struct rte_dmadev rte_dmadevices[]; + +#endif /* _RTE_DMADEV_CORE_H_ */ lib/dmadev/rte_dmadev_pmd.h new file +72
-0@@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2021 HiSilicon Limited. +*/ + +#ifndef _RTE_DMADEV_PMD_H_ +#define _RTE_DMADEV_PMD_H_ + +/** +* @file +* +* RTE DMA Device PMD APIs +* +* Driver facing APIs for a DMA device. These are not to be called directly by +* any application. +*/ + +#include "rte_dmadev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @internal +* Allocates a new dmadev slot for an DMA device and returns the pointer +* to that slot for the driver to use. +* +* @param name +* DMA device name. +* +* @return +* A pointer to the DMA device slot case of success, +* NULL otherwise. +*/ +__rte_internal +struct rte_dmadev * +rte_dmadev_pmd_allocate (const char *name); + +/** +* @internal +* Release the specified dmadev. +* +* @param dev +* Device to be released. +* +* @return +* - 0 on success, negative on error +*/ +__rte_internal +int +rte_dmadev_pmd_release (struct rte_dmadev *dev); + +/** +* @internal +* Return the DMA device based on the device name. +* +* @param name +* DMA device name. +* +* @return +* A pointer to the DMA device slot case of success, +* NULL otherwise. +*/ +__rte_internal +struct rte_dmadev * +rte_dmadev_get_device_by_name (const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_DMADEV_PMD_H_ */ lib/dmadev/version.map new file +40
-0@@ -0,0 +1,40 @@ +EXPERIMENTAL { + global: + + rte_dmadev_count; + rte_dmadev_info_get; + rte_dmadev_configure; + rte_dmadev_start; + rte_dmadev_stop; + rte_dmadev_close; + rte_dmadev_reset; + rte_dmadev_vchan_setup; + rte_dmadev_vchan_release; + rte_dmadev_stats_get; + rte_dmadev_stats_reset; + rte_dmadev_dump; + rte_dmadev_selftest; + rte_dmadev_copy; + rte_dmadev_copy_sg; + rte_dmadev_fill; + rte_dmadev_fill_sg; + rte_dmadev_submit; + rte_dmadev_completed; + rte_dmadev_completed_fails; + + local: *; +}; + +INTERNAL { + global: + + rte_dmadevices; + rte_dmadev_pmd_allocate; + rte_dmadev_pmd_release; + rte_dmadev_get_device_by_name; + + local: + + rte_dmadev_is_valid_dev; +}; +lib/meson.build +1
-1@@ -60,6 +60,7 @@ libraries = [ 'bpf', 'graph', 'node', + 'dmadev', ] if is_windows --2.8.1
Quoted 9 lines
From: dev [mailto:[email protected]] On Behalf Of Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>
[snip]
lib/dmadev/rte_dmadev.h line 4
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +4
-0@@ -0,0 +1,1030 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2021 HiSilicon Limited. +* Copyright(c) 2021 Intel Corporation. +* Copyright(c) 2021 Marvell International Ltd.
If the group of DMA device hardware vendors don't oppose, I would appreciate it if my contribution to the definition of the DMA device API is recognized in this file:
+ * Copyright(c) 2021 SmartShare Systems.
lib/dmadev/rte_dmadev.h line 6
Quoted 2 lines
lib/dmadev/rte_dmadev.h new file +2
-0+*/ +
Also remember the other contributors in the other files, where appropriate.
-Morten
Quoted 25 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the virtual DMA channel.
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @param vchan
+ * The identifier of virtual DMA channel.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dst
Quoted 8 lines
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An flags for this operation.
+ *
+ * @return
+ * - 0..UINT16_MAX: index of enqueued copy job.
fill job
Quoted 25 lines
+ * - <0: Error code returned by the driver copy function.
+ */lib/dmadev/rte_dmadev.h new file +22
-0+__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed.
lib/dmadev/rte_dmadev.h line 893
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in.
This means the driver will be tracking the last index.
Is that mean, the application needs to call this API periodically to consume the completion slot.
I.e up to 64K (UINT16_MAX) outstanding jobs are possible. If the application fails to call this
Quoted 1 line
64K outstand job then the subsequence enqueue will fail.
If so, we need to document this.
One of the concerns of keeping UINT16_MAX as the limit is the completion memory will always not in cache.
On the other hand, if we make this size programmable. it may introduce complexity in the application.
Thoughts?
Quoted 45 lines
+ * @param[out]
has_error
+ * Indicates if there are transfer error.
+ * If not required, NULL can be passed in.
+ *
+ * @return
+ * The number of operations that successfully completed.
+ */lib/dmadev/rte_dmadev.h new file +38
-0+__rte_experimental +static inline uint16_t +rte_dmadev_completed (uint16_t dev_id,uint16_t vchan,const uint16_t nb_cpls, +uint16_t *last_idx,bool *has_error) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +uint16_t idx; +bool err; + +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->completed, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +if (nb_cpls ==0 ) { +RTE_DMADEV_LOG (ERR ,"Invalid nb_cpls\n" ); +return -EINVAL ; + } +#endif + +/* Ensure the pointer values are non-null to simplify drivers. +* In most cases these should be compile time evaluated, since this is +* an inline function. +* - If NULL is explicitly passed as parameter, then compiler knows the +* value is NULL +* - If address of local variable is passed as parameter, then compiler +* can know it's non-NULL. +*/ +if (last_idx ==NULL ) + last_idx = &idx; +if (has_error ==NULL ) + has_error = &err; + + *has_error = false; +return (*dev->completed)(dev, vchan, nb_cpls, last_idx, has_error); +}
Quoted 73 lines · Jerin Jacob
Quoted 25 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the virtual DMA channel.
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @param vchan
+ * The identifier of virtual DMA channel.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dstQuoted 8 lines
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An flags for this operation.
+ *
+ * @return
+ * - 0..UINT16_MAX: index of enqueued copy job.fill job
Quoted 25 lines
+ * - <0: Error code returned by the driver copy function.
+ */lib/dmadev/rte_dmadev.h new file +22
-0+__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed. lib/dmadev/rte_dmadev.h line 893
Quoted 10 lines
lib/dmadev/rte_dmadev.h new file +10
-0+* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in.
Quoted 2 lines
This means the driver will be tracking the last index.
Driver will be doing this anyway, no, since it needs to ensure we don't wrap around?
Quoted 5 lines
Is that mean, the application needs to call this API periodically to consume the completion slot.
I.e up to 64K (UINT16_MAX) outstanding jobs are possible. If the application fails to call thisQuoted 1 line
64K outstand job then the subsequence enqueue will fail.
Well, given that there will be a regular enqueue ring which will probably be <= 64k in size, the completion call will need to be called frequently anyway. I don't think we need to document this restriction as it's fairly understood that you can't go beyond the size of the ring without cleanup.
Quoted 9 lines
If so, we need to document this.
One of the concerns of keeping
UINT16_MAXas the limit is the completion memory will always not in cache.
On the other hand, if we make this size programmable. it may introduce complexity in the application.Thoughts?
The reason for using powers-of-2 sizes, e.g. 0 .. UINT16_MAX, is that the ring can be any other power-of-2 size and we can index it just by masking. In the sample app for dmadev, I expect the ring size used to be set the same as the dmadev enqueue ring size, for simplicity.
In fact, I was thinking that in later versions we may be able to include some macros to help make this whole process easier, of converting indexes to arbitrary data structures. [The reason for using macros is so that the actual rings we are indexing can be of user-defined type, rather than just a ring of pointers].
/Bruce
Quoted 75 lines · Bruce Richardson
Quoted 73 lines · Jerin Jacob
Quoted 25 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the virtual DMA channel.
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @param vchan
+ * The identifier of virtual DMA channel.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dstQuoted 8 lines
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An flags for this operation.
+ *
+ * @return
+ * - 0..UINT16_MAX: index of enqueued copy job.fill job
Quoted 35 lines
+ * - <0: Error code returned by the driver copy function.
+ */lib/dmadev/rte_dmadev.h new file +32
-0+__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in.
Quoted 4 lines
Quoted 2 lines
This means the driver will be tracking the last index.
Driver will be doing this anyway, no, since it needs to ensure we don't
Yes.
Quoted 8 lines
wrap around?
Quoted 4 lines
Is that mean, the application needs to call this API periodically to consume the completion slot.
I.e up to 64K (UINT16_MAX) outstanding jobs are possible. If the application fails to call this
Quoted 6 lines
Quoted 1 line
Quoted 1 line
64K outstand job then the subsequence enqueue will fail.
Well, given that there will be a regular enqueue ring which will probably be <= 64k in size, the completion call will need to be called frequently anyway. I don't think we need to document this restriction as it's fairly understood that you can't go beyond the size of the ring without cleanup.
See below.
Quoted 9 lines
Quoted 9 lines
If so, we need to document this.
One of the concerns of keeping
UINT16_MAXas the limit is the completion memory will always not in cache.
On the other hand, if we make this size programmable. it may introduce complexity in the application.
Quoted 6 lines
Quoted 1 line
Thoughts?
The reason for using powers-of-2 sizes, e.g. 0 ..
UINT16_MAX, is that the ring can be any other power-of-2 size and we can index it just by masking. In the sample app for dmadev, I expect the ring size used to be set the same as the dmadev enqueue ring size, for simplicity.
No question on not using power of 2. Aligned on that.
At least in our HW, the size of the ring is rte_dmadev_vchan_conf::nb_desc. But completion happens in _different_ memory space. Currently, we are allocating UINT16_MAX entries to hold that. That's where cache miss aspects of completion aspects
came.
In your case, Is completion happens in the same ring memory(looks like one bit in job desc represents the job completed or not) ? And when application calls rte_dmadev_completed(), You are converting UINT16_MAX based index torte_dmadev_vchan_conf::nb_desc. Right?
Quoted 8 lines
In fact, I was thinking that in later versions we may be able to include some macros to help make this whole process easier, of converting indexes to arbitrary data structures. [The reason for using macros is so that the actual rings we are indexing can be of user-defined type, rather than just a ring of pointers].
/Bruce
Quoted 118 lines · Jerin Jacob
Quoted 75 lines · Bruce Richardson
Quoted 73 lines · Jerin Jacob
Quoted 25 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the virtual DMA channel.
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @param vchan
+ * The identifier of virtual DMA channel.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dstQuoted 8 lines
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An flags for this operation.
+ *
+ * @return
+ * - 0..UINT16_MAX: index of enqueued copy job.fill job
Quoted 35 lines
+ * - <0: Error code returned by the driver copy function.
+ */lib/dmadev/rte_dmadev.h new file +32
-0+__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in. Quoted 4 lines
Quoted 2 lines
This means the driver will be tracking the last index.
Driver will be doing this anyway, no, since it needs to ensure we don't
Yes.
Quoted 8 lines
wrap around?
Quoted 4 lines
Is that mean, the application needs to call this API periodically to consume the completion slot.
I.e up to 64K (UINT16_MAX) outstanding jobs are possible. If the application fails to call thisQuoted 6 lines
Quoted 1 line
Quoted 1 line
64K outstand job then the subsequence enqueue will fail.
Well, given that there will be a regular enqueue ring which will probably be <= 64k in size, the completion call will need to be called frequently anyway. I don't think we need to document this restriction as it's fairly understood that you can't go beyond the size of the ring without cleanup.
See below.
Quoted 9 lines
Quoted 9 lines
If so, we need to document this.
One of the concerns of keeping
UINT16_MAXas the limit is the completion memory will always not in cache.
On the other hand, if we make this size programmable. it may introduce complexity in the application.Quoted 6 lines
Quoted 1 line
Thoughts?
The reason for using powers-of-2 sizes, e.g. 0 ..
UINT16_MAX, is that the ring can be any other power-of-2 size and we can index it just by masking. In the sample app for dmadev, I expect the ring size used to be set the same as the dmadev enqueue ring size, for simplicity.
Quoted 7 lines
No question on not using power of 2. Aligned on that.
At least in our HW, the size of the ring is
rte_dmadev_vchan_conf::nb_desc. But completion happens in _different_ memory space. Currently, we are allocatingUINT16_MAXentries to hold that. That's where cache miss aspects of completion aspects
came.
Depending on HW, our completions can be written back to a separate memory area - a completion ring, if you will - but I've generally found it works as well to reuse the enqueue ring for that purpose. However, with a separate memory area for completions, why do you need to allocate 64K entries for the completions? Would nb_desc entries not be enough? Is that to allow the user to have more than nb_desc jobs outstanding before calling "get_completions" API?
Quoted 6 lines
In your case, Is completion happens in the same ring memory(looks like one bit in job desc represents the job completed or not) ? And when application calls
rte_dmadev_completed(), You are convertingUINT16_MAXbased index torte_dmadev_vchan_conf::nb_desc. Right?
Yes, we are masking to do that. Actually, for simplicity and perf we should only allow power-of-2 ring sizes. Having to use modulus instead of masking could be a problem. [Alternatively, I suppose we can allow drivers to round up the ring sizes to the next power of 2, but I prefer just documenting it as a limitation].
/Bruce
Quoted 128 lines · Bruce Richardson
Quoted 118 lines · Jerin Jacob
Quoted 75 lines · Bruce Richardson
Quoted 73 lines · Jerin Jacob
Quoted 25 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>---
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Enqueue a fill operation onto the virtual DMA channel.
+ *
+ * This queues up a fill operation to be performed by hardware, but does not
+ * trigger hardware to begin that operation.
+ *
+ * @paramdev_id
+ * The identifier of the device.
+ * @param vchan
+ * The identifier of virtual DMA channel.
+ * @param pattern
+ * The pattern to populate the destination buffer with.
+ * @param dstQuoted 8 lines
+ * The address of the destination buffer.
+ * @param length
+ * The length of the destination buffer.
+ * @param flags
+ * An flags for this operation.
+ *
+ * @return
+ * - 0..UINT16_MAX: index of enqueued copy job.fill job
Quoted 35 lines
+ * - <0: Error code returned by the driver copy function.
+ */lib/dmadev/rte_dmadev.h new file +32
-0+__rte_experimental +static inline int +rte_dmadev_fill (uint16_t dev_id,uint16_t vchan,uint64_t pattern, +rte_iova_t dst,uint32_t length,uint64_t flags) +{ +struct rte_dmadev *dev = &rte_dmadevices[dev_id]; +#ifdef RTE_DMADEV_DEBUG +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (*dev->fill, -ENOTSUP ); +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR ,"Invalid vchan %d\n" , vchan); +return -EINVAL ; + } +#endif +return (*dev->fill)(dev, vchan, pattern, dst, length, flags); +} + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice. +* +* Returns the number of operations that have been successfully completed. +* +* @param dev_id +* The identifier of the device. +* @param vchan +* The identifier of virtual DMA channel. +* @param nb_cpls +* The maximum number of completed operations that can be processed. +* @param[out] last_idx +* The last completed operation's index. +* If not required, NULL can be passed in. Quoted 4 lines
Quoted 2 lines
This means the driver will be tracking the last index.
Driver will be doing this anyway, no, since it needs to ensure we don't
Yes.
Quoted 8 lines
wrap around?
Quoted 4 lines
Is that mean, the application needs to call this API periodically to consume the completion slot.
I.e up to 64K (UINT16_MAX) outstanding jobs are possible. If the application fails to call thisQuoted 6 lines
Quoted 1 line
Quoted 1 line
64K outstand job then the subsequence enqueue will fail.
Well, given that there will be a regular enqueue ring which will probably be <= 64k in size, the completion call will need to be called frequently anyway. I don't think we need to document this restriction as it's fairly understood that you can't go beyond the size of the ring without cleanup.
See below.
Quoted 9 lines
Quoted 9 lines
If so, we need to document this.
One of the concerns of keeping
UINT16_MAXas the limit is the completion memory will always not in cache.
On the other hand, if we make this size programmable. it may introduce complexity in the application.Quoted 6 lines
Quoted 1 line
Thoughts?
The reason for using powers-of-2 sizes, e.g. 0 ..
UINT16_MAX, is that the ring can be any other power-of-2 size and we can index it just by masking. In the sample app for dmadev, I expect the ring size used to be set the same as the dmadev enqueue ring size, for simplicity.Quoted 7 lines
No question on not using power of 2. Aligned on that.
At least in our HW, the size of the ring is
rte_dmadev_vchan_conf::nb_desc. But completion happens in _different_ memory space. Currently, we are allocatingUINT16_MAXentries to hold that. That's where cache miss aspects of completion aspects
came.
Quoted 7 lines
Depending on HW, our completions can be written back to a separate memory area - a completion ring, if you will - but I've generally found it works as well to reuse the enqueue ring for that purpose. However, with a separate memory area for completions, why do you need to allocate 64K entries for the completions? Would
nb_descentries not be enough? Is that to allow the user to have more thannb_descjobs outstanding before calling "get_completions" API?
Yes. That's what I thought. Thats where my question on what is the max number of outstanding completions. I thought it can be up to 64K. Agree to keep it implementation-specific and not need to highlight this in the documentation.
Quoted 8 lines
Quoted 7 lines
In your case, Is completion happens in the same ring memory(looks like one bit in job desc represents the job completed or not) ? And when application calls
rte_dmadev_completed(), You are convertingUINT16_MAXbased index torte_dmadev_vchan_conf::nb_desc. Right?
Quoted 5 lines
Yes, we are masking to do that. Actually, for simplicity and perf we should only allow power-of-2 ring sizes. Having to use modulus instead of masking could be a problem. [Alternatively, I suppose we can allow drivers to round up the ring sizes to the next power of 2, but I prefer just documenting it as a limitation].
OK.
Quoted 2 lines
/Bruce
Quoted 7 lines · Chengwen Feng
This patch introduce 'dmadevice' which is a generic type of DMA device.
The APIs of dmadev library exposes some generic operations which can enable configuration and I/O with the DMA devices.
Signed-off-by Chengwen Feng <[email protected]>
Thanks for this V2.
Some initial (mostly minor) comments on the meson.build and dmadev .c file below. I'll review the headers in a separate email.
/Bruce
Quoted 53 lines
--- MAINTAINERS | 4 + config/rte_config.h | 3 + lib/dmadev/meson.build | 6 + lib/dmadev/rte_dmadev.c | 560 +++++++++++++++++++++++ lib/dmadev/rte_dmadev.h | 1030 ++++++++++++++++++++++++++++++++++++++++++ lib/dmadev/rte_dmadev_core.h | 159 +++++++ lib/dmadev/rte_dmadev_pmd.h | 72 +++ lib/dmadev/version.map | 40 ++ lib/meson.build | 1 + 9 files changed, 1875 insertions(+) create mode 100644 lib/dmadev/meson.build create mode 100644 lib/dmadev/rte_dmadev.c create mode 100644 lib/dmadev/rte_dmadev.h create mode 100644 lib/dmadev/rte_dmadev_core.h create mode 100644 lib/dmadev/rte_dmadev_pmd.h create mode 100644 lib/dmadev/version.mapMAINTAINERS +4
-0@@ -496,6 +496,10 @@ F: drivers/raw/skeleton/ F: app/test/test_rawdev.c F: doc/guides/prog_guide/rawdev.rst +DMA device API - EXPERIMENTAL +M: Chengwen Feng <[email protected]> +F: lib/dmadev/ + Memory Pool Drivers -------------------config/rte_config.h +3
-0@@ -81,6 +81,9 @@/* rawdev defines */ #define RTE_RAWDEV_MAX_DEVS 64 +/* dmadev defines */ +#define RTE_DMADEV_MAX_DEVS 64 +/* ip_fragmentation defines */ #define RTE_LIBRTE_IP_FRAG_MAX_FRAG 4#undef RTE_LIBRTE_IP_FRAG_TBL_STATlib/dmadev/meson.build new file +0
-0
lib/dmadev/meson.build line 5
Quoted 5 lines
lib/dmadev/meson.build new file +5
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2021 HiSilicon Limited. + +sources = files('rte_dmadev.c') +headers = files('rte_dmadev.h', 'rte_dmadev_pmd.h')
If rte_dmadev_pmd.h is only for PMD use, then it should be in "driver_sdk_headers".
Quoted 73 lines
lib/dmadev/meson.build new file +1
-0+indirect_headers += files('rte_dmadev_core.h')lib/dmadev/rte_dmadev.c new file +66
-0@@ -0,0 +1,560 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2021 HiSilicon Limited. +* Copyright(c) 2021 Intel Corporation. +*/ + +#include <ctype.h> +#include <inttypes.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <rte_debug.h> +#include <rte_dev.h> +#include <rte_eal.h> +#include <rte_errno.h> +#include <rte_lcore.h> +#include <rte_log.h> +#include <rte_memory.h> +#include <rte_memzone.h> +#include <rte_malloc.h> +#include <rte_string_fns.h> + +#include "rte_dmadev.h" +#include "rte_dmadev_pmd.h" + +RTE_LOG_REGISTER (rte_dmadev_logtype, lib.dmadev,INFO ); + +struct rte_dmadev rte_dmadevices[RTE_DMADEV_MAX_DEVS ]; + +static const char *MZ_RTE_DMADEV_DATA ="rte_dmadev_data" ; +/* Shared memory between primary and secondary processes. */ +static struct { +struct rte_dmadev_data data[RTE_DMADEV_MAX_DEVS ]; +} *dmadev_shared_data; + +static int +dmadev_check_name (const char *name) +{ +size_t name_len; + +if (name ==NULL ) { +RTE_DMADEV_LOG (ERR ,"Name can't be NULL\n" ); +return -EINVAL ; + } + + name_len =strnlen (name,RTE_DMADEV_NAME_MAX_LEN ); +if (name_len ==0 ) { +RTE_DMADEV_LOG (ERR ,"Zero length DMA device name\n" ); +return -EINVAL ; + } +if (name_len >=RTE_DMADEV_NAME_MAX_LEN ) { +RTE_DMADEV_LOG (ERR ,"DMA device name is too long\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static uint16_t +dmadev_find_free_dev (void ) +{ +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (dmadev_shared_data->data[i].dev_name[0 ] =='\0' ) {
lib/dmadev/rte_dmadev.c line 76
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+RTE_ASSERT (rte_dmadevices[i].attached ==0 ); +return i; + } + } + +return RTE_DMADEV_MAX_DEVS ; +} + +static struct rte_dmadev * +dmadev_allocated (const char *name)
The name implies a boolean lookup for whether a particular dmadev has been allocated or not. Since this returns a pointer, I think a name like "dmadev_find" or "dmadev_get" would be more appropriate.
Quoted 180 lines
lib/dmadev/rte_dmadev.c new file +180
-0+{ +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if ((rte_dmadevices[i].attached ==1 ) && + (!strcmp (name, rte_dmadevices[i].data->dev_name))) +return &rte_dmadevices[i]; + } + +return NULL ; +} + +static int +dmadev_shared_data_prepare (void ) +{ +const struct rte_memzone *mz; + +if (dmadev_shared_data ==NULL ) { +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +/* Allocate port data and ownership shared memory. */ + mz =rte_memzone_reserve (MZ_RTE_DMADEV_DATA , +sizeof (*dmadev_shared_data), +rte_socket_id (),0 ); + }else { + mz =rte_memzone_lookup (MZ_RTE_DMADEV_DATA ); + } +if (mz ==NULL ) +return -ENOMEM ; + + dmadev_shared_data = mz->addr; +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) +memset (dmadev_shared_data->data,0 , +sizeof (dmadev_shared_data->data)); + } + +return 0 ; +} + +static struct rte_dmadev * +dmadev_allocate (const char *name) +{ +struct rte_dmadev *dev; +uint16_t dev_id; + + dev =dmadev_allocated (name); +if (dev !=NULL ) { +RTE_DMADEV_LOG (ERR ,"DMA device already allocated\n" ); +return NULL ; + } + + dev_id =dmadev_find_free_dev (); +if (dev_id ==RTE_DMADEV_MAX_DEVS ) { +RTE_DMADEV_LOG (ERR ,"Reached maximum number of DMA devices\n" ); +return NULL ; + } + +if (dmadev_shared_data_prepare () !=0 ) { +RTE_DMADEV_LOG (ERR ,"Cannot allocate DMA shared data\n" ); +return NULL ; + } + + dev = &rte_dmadevices[dev_id]; + dev->data = &dmadev_shared_data->data[dev_id]; + dev->data->dev_id = dev_id; +strlcpy (dev->data->dev_name, name,sizeof (dev->data->dev_name)); + +return dev; +} + +static struct rte_dmadev * +dmadev_attach_secondary (const char *name) +{ +struct rte_dmadev *dev; +uint16_t i; + +if (dmadev_shared_data_prepare () !=0 ) { +RTE_DMADEV_LOG (ERR ,"Cannot allocate DMA shared data\n" ); +return NULL ; + } + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (!strcmp (dmadev_shared_data->data[i].dev_name, name)) +break ; + } +if (i ==RTE_DMADEV_MAX_DEVS ) { +RTE_DMADEV_LOG (ERR , +"Device %s is not driven by the primary process\n" , + name); +return NULL ; + } + + dev = &rte_dmadevices[i]; + dev->data = &dmadev_shared_data->data[i]; +RTE_ASSERT (dev->data->dev_id == i); + +return dev; +} + +struct rte_dmadev * +rte_dmadev_pmd_allocate (const char *name) +{ +struct rte_dmadev *dev; + +if (dmadev_check_name (name) !=0 ) +return NULL ; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) + dev =dmadev_allocate (name); +else + dev =dmadev_attach_secondary (name); + +if (dev ==NULL ) +return NULL ; + dev->attached =1 ; + +return dev; +} + +int +rte_dmadev_pmd_release (struct rte_dmadev *dev) +{ +if (dev ==NULL ) +return -EINVAL ; + +if (dev->attached ==0 ) +return 0 ; + +if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) { +rte_free (dev->data->dev_private); +memset (dev->data,0 ,sizeof (struct rte_dmadev_data )); + } + +memset (dev,0 ,sizeof (struct rte_dmadev )); + dev->attached =0 ; + +return 0 ; +} + +struct rte_dmadev * +rte_dmadev_get_device_by_name (const char *name) +{ +if (dmadev_check_name (name) !=0 ) +return NULL ; +return dmadev_allocated (name); +} + +bool +rte_dmadev_is_valid_dev (uint16_t dev_id) +{ +if (dev_id >=RTE_DMADEV_MAX_DEVS || + rte_dmadevices[dev_id].attached ==0 ) +return false; +return true; +} + +uint16_t +rte_dmadev_count (void ) +{ +uint16_t count =0 ; +uint16_t i; + +for (i =0 ; i <RTE_DMADEV_MAX_DEVS ; i++) { +if (rte_dmadevices[i].attached ==1 ) + count++; + } + +return count; +} + +int +rte_dmadev_info_get (uint16_t dev_id,struct rte_dmadev_info *dev_info) +{ +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_info, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; +
lib/dmadev/rte_dmadev.c line 266
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_info_get, -ENOTSUP ); +memset (dev_info,0 ,sizeof (struct rte_dmadev_info )); + ret = (*dev->dev_ops->dev_info_get)(dev, dev_info); +if (ret !=0 ) +return ret; + + dev_info->device = dev->device; + +return 0 ; +}
Should the info_get function (and the related info structure), not include in it the parameters passed into the configure function. That way, the user can query a previously set up configuration. This should be done at the dmadev level, rather than driver level, since I see the parameters are already being saved in configure below.
Also, for ABI purposes, I would strongly suggest passing "sizeof(dev_info)" to the driver in the "dev_info_get" call. When dev_info changes, we can version rte_dmadev_info_get, but can't version the functions that it calls in turn. When we add a new field to the struct, the driver functions that choose to use that new field can check the size of the struct passed to determine if it's safe to write that new field or not. [So long as field is added at the end, driver functions not updated for the new field, need no changes]
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+ +int +rte_dmadev_configure (uint16_t dev_id,const struct rte_dmadev_conf *dev_conf) +{ +struct rte_dmadev_info info; +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (dev_conf, -EINVAL );
lib/dmadev/rte_dmadev.c line 286
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+ dev = &rte_dmadevices[dev_id]; + + ret =rte_dmadev_info_get (dev_id, &info); +if (ret !=0 ) { +RTE_DMADEV_LOG (ERR ,"Device %u get device info fail\n" , dev_id); +return -EINVAL ; + } +if (dev_conf->max_vchans > info.max_vchans) { +RTE_DMADEV_LOG (ERR , +"Device %u configure too many vchans\n" , dev_id);
We allow up to 100 characters per line for DPDK code, so these don't need to be wrapped so aggressively.
Quoted 32 lines
lib/dmadev/rte_dmadev.c new file +32
-0+return -EINVAL ; + } +if (dev_conf->enable_mt_vchan && + !(info.dev_capa &RTE_DMA_DEV_CAPA_MT_VCHAN )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support MT-safe vchan\n" , dev_id); +return -EINVAL ; + } +if (dev_conf->enable_mt_multi_vchan && + !(info.dev_capa &RTE_DMA_DEV_CAPA_MT_MULTI_VCHAN )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support MT-safe multiple vchan\n" , + dev_id); +return -EINVAL ; + } + +if (dev->data->dev_started !=0 ) { +RTE_DMADEV_LOG (ERR , +"Device %u must be stopped to allow configuration\n" , + dev_id); +return -EBUSY ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_configure, -ENOTSUP ); + ret = (*dev->dev_ops->dev_configure)(dev, dev_conf); +if (ret ==0 ) +memcpy (&dev->data->dev_conf, dev_conf,sizeof (*dev_conf)); + +return ret; +} + +int
lib/dmadev/rte_dmadev.c line 328
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+rte_dmadev_start(uint16_t dev_id) +{ +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +if (dev->data->dev_started !=0 ) { +RTE_DMADEV_LOG (ERR ,"Device %u already started\n" , dev_id);
Maybe make this a warning rather than error.
Quoted 16 lines
lib/dmadev/rte_dmadev.c new file +16
-0+return 0 ; + } + +if (dev->dev_ops->dev_start ==NULL ) + goto mark_started; + + ret = (*dev->dev_ops->dev_start)(dev); +if (ret !=0 ) +return ret; + +mark_started: + dev->data->dev_started =1 ; +return 0 ; +} + +int
lib/dmadev/rte_dmadev.c line 354
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+rte_dmadev_stop(uint16_t dev_id) +{ +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +if (dev->data->dev_started ==0 ) { +RTE_DMADEV_LOG (ERR ,"Device %u already stopped\n" , dev_id);
As above, suggest just warning rather than error.
Quoted 36 lines
lib/dmadev/rte_dmadev.c new file +36
-0+return 0 ; + } + +if (dev->dev_ops->dev_stop ==NULL ) + goto mark_stopped; + + ret = (*dev->dev_ops->dev_stop)(dev); +if (ret !=0 ) +return ret; + +mark_stopped: + dev->data->dev_started =0 ; +return 0 ; +} + +int +rte_dmadev_close (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +/* Device must be stopped before it can be closed */ +if (dev->data->dev_started ==1 ) { +RTE_DMADEV_LOG (ERR , +"Device %u must be stopped before closing\n" , dev_id); +return -EBUSY ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_close, -ENOTSUP ); +return (*dev->dev_ops->dev_close)(dev); +} + +int +rte_dmadev_reset (uint16_t dev_id)
lib/dmadev/rte_dmadev.c line 400
Quoted 10 lines
lib/dmadev/rte_dmadev.c new file +10
-0+{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_reset, -ENOTSUP ); +/* Reset is not dependent on state of the device */ +return (*dev->dev_ops->dev_reset)(dev); +}
I would tend to agree with the query as to whether this is needed or not. Can we perhaps remove for now, and add it back later if it does prove to be needed. The less code to review and work with for the first version, the better IMHO. :-)
lib/dmadev/rte_dmadev.c line 411
Quoted 11 lines
lib/dmadev/rte_dmadev.c new file +11
-0+ +int +rte_dmadev_vchan_setup (uint16_t dev_id, +const struct rte_dmadev_vchan_conf *conf) +{ +struct rte_dmadev_info info; +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (conf, -EINVAL );
This is confusing, because you are actually doing a parameter check using a macro named for checking a function. Better to explicitly just check conf for null.
lib/dmadev/rte_dmadev.c line 424
Quoted 13 lines
lib/dmadev/rte_dmadev.c new file +13
-0+ + dev = &rte_dmadevices[dev_id]; + + ret =rte_dmadev_info_get (dev_id, &info); +if (ret !=0 ) { +RTE_DMADEV_LOG (ERR ,"Device %u get device info fail\n" , dev_id); +return -EINVAL ; + } +if (conf->direction ==0 || + conf->direction & ~RTE_DMA_TRANSFER_DIR_ALL ) { +RTE_DMADEV_LOG (ERR ,"Device %u direction invalid!\n" , dev_id); +return -EINVAL ; + }
I wonder should we allow direction == 0, to be the same as all bits set, or to be all supported bits set?
Quoted 136 lines
lib/dmadev/rte_dmadev.c new file +136
-0+if (conf->direction &RTE_DMA_MEM_TO_MEM && + !(info.dev_capa &RTE_DMA_DEV_CAPA_MEM_TO_MEM )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support mem2mem transfer\n" , dev_id); +return -EINVAL ; + } +if (conf->direction &RTE_DMA_MEM_TO_DEV && + !(info.dev_capa &RTE_DMA_DEV_CAPA_MEM_TO_DEV )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support mem2dev transfer\n" , dev_id); +return -EINVAL ; + } +if (conf->direction &RTE_DMA_DEV_TO_MEM && + !(info.dev_capa &RTE_DMA_DEV_CAPA_DEV_TO_MEM )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support dev2mem transfer\n" , dev_id); +return -EINVAL ; + } +if (conf->direction &RTE_DMA_DEV_TO_DEV && + !(info.dev_capa &RTE_DMA_DEV_CAPA_DEV_TO_DEV )) { +RTE_DMADEV_LOG (ERR , +"Device %u don't support dev2dev transfer\n" , dev_id); +return -EINVAL ; + } +if (conf->nb_desc < info.min_desc || conf->nb_desc > info.max_desc) { +RTE_DMADEV_LOG (ERR , +"Device %u number of descriptors invalid\n" , dev_id); +return -EINVAL ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->vchan_setup, -ENOTSUP ); +return (*dev->dev_ops->vchan_setup)(dev, conf); +} + +int +rte_dmadev_vchan_release (uint16_t dev_id,uint16_t vchan) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +if (vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR , +"Device %u vchan %u out of range\n" , dev_id, vchan); +return -EINVAL ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->vchan_release, -ENOTSUP ); +return (*dev->dev_ops->vchan_release)(dev, vchan); +} + +int +rte_dmadev_stats_get (uint16_t dev_id,int vchan,struct rte_dmadev_stats *stats) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (stats, -EINVAL ); + + dev = &rte_dmadevices[dev_id]; + +if (vchan <-1 || vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR , +"Device %u vchan %u out of range\n" , dev_id, vchan); +return -EINVAL ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->stats_get, -ENOTSUP ); +return (*dev->dev_ops->stats_get)(dev, vchan, stats); +} + +int +rte_dmadev_stats_reset (uint16_t dev_id,int vchan) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +if (vchan <-1 || vchan >= dev->data->dev_conf.max_vchans) { +RTE_DMADEV_LOG (ERR , +"Device %u vchan %u out of range\n" , dev_id, vchan); +return -EINVAL ; + } + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->stats_reset, -ENOTSUP ); +return (*dev->dev_ops->stats_reset)(dev, vchan); +} + +int +rte_dmadev_dump (uint16_t dev_id,FILE *f) +{ +struct rte_dmadev_info info; +struct rte_dmadev *dev; +int ret; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); +RTE_FUNC_PTR_OR_ERR_RET (f, -EINVAL ); + + ret =rte_dmadev_info_get (dev_id, &info); +if (ret !=0 ) { +RTE_DMADEV_LOG (ERR ,"Device %u get device info fail\n" , dev_id); +return -EINVAL ; + } + + dev = &rte_dmadevices[dev_id]; + +fprintf (f,"DMA Dev %u, '%s' [%s]\n" , + dev->data->dev_id, + dev->data->dev_name, + dev->data->dev_started ?"started" :"stopped" ); +fprintf (f," dev_capa: 0x%" PRIx64"\n" , info.dev_capa); +fprintf (f," max_vchans_supported: %u\n" , info.max_vchans); +fprintf (f," max_vchans_configured: %u\n" , info.nb_vchans); +fprintf (f," MT-safe-configured: vchans: %u multi-vchans: %u\n" , + dev->data->dev_conf.enable_mt_vchan, + dev->data->dev_conf.enable_mt_multi_vchan); + +if (dev->dev_ops->dev_dump !=NULL ) +return (*dev->dev_ops->dev_dump)(dev, f); + +return 0 ; +} + +int +rte_dmadev_selftest (uint16_t dev_id) +{ +struct rte_dmadev *dev; + +RTE_DMADEV_VALID_DEV_ID_OR_ERR_RET (dev_id, -EINVAL ); + dev = &rte_dmadevices[dev_id]; + +RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->dev_selftest, -ENOTSUP ); +return (*dev->dev_ops->dev_selftest)(dev_id); +}