1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 HiSilicon Limited
3 * Copyright(c) 2021 Intel Corporation
4 * Copyright(c) 2021 Marvell International Ltd
5 * Copyright(c) 2021 SmartShare Systems
14 * DMA (Direct Memory Access) device API.
16 * The DMA framework is built on the following model:
18 * --------------- --------------- ---------------
19 * | virtual DMA | | virtual DMA | | virtual DMA |
20 * | channel | | channel | | channel |
21 * --------------- --------------- ---------------
23 * ------------------ |
25 * ------------ ------------
26 * | dmadev | | dmadev |
27 * ------------ ------------
29 * ------------------ ------------------
30 * | HW DMA channel | | HW DMA channel |
31 * ------------------ ------------------
33 * --------------------------------
35 * ---------------------
36 * | HW DMA Controller |
37 * ---------------------
39 * The DMA controller could have multiple HW-DMA-channels (aka. HW-DMA-queues),
40 * each HW-DMA-channel should be represented by a dmadev.
42 * The dmadev could create multiple virtual DMA channels, each virtual DMA
43 * channel represents a different transfer context. The DMA operation request
44 * must be submitted to the virtual DMA channel. e.g. Application could create
45 * virtual DMA channel 0 for memory-to-memory transfer scenario, and create
46 * virtual DMA channel 1 for memory-to-device transfer scenario.
48 * This framework uses 'int16_t dev_id' as the device identifier of a dmadev,
49 * and 'uint16_t vchan' as the virtual DMA channel identifier in one dmadev.
51 * The functions exported by the dmadev API to setup a device designated by its
52 * device identifier must be invoked in the following order:
53 * - rte_dma_configure()
54 * - rte_dma_vchan_setup()
57 * Then, the application can invoke dataplane functions to process jobs.
59 * If the application wants to change the configuration (i.e. invoke
60 * rte_dma_configure() or rte_dma_vchan_setup()), it must invoke
61 * rte_dma_stop() first to stop the device and then do the reconfiguration
62 * before invoking rte_dma_start() again. The dataplane functions should not
63 * be invoked when the device is stopped.
65 * Finally, an application can close a dmadev by invoking the rte_dma_close()
68 * The dataplane APIs include two parts:
69 * The first part is the submission of operation requests:
75 * These APIs could work with different virtual DMA channels which have
78 * The first three APIs are used to submit the operation request to the virtual
79 * DMA channel, if the submission is successful, a positive
80 * ring_idx <= UINT16_MAX is returned, otherwise a negative number is returned.
82 * The last API is used to issue doorbell to hardware, and also there are flags
83 * (@see RTE_DMA_OP_FLAG_SUBMIT) parameter of the first three APIs could do the
85 * @note When enqueuing a set of jobs to the device, having a separate submit
86 * outside a loop makes for clearer code than having a check for the last
87 * iteration inside the loop to set a special submit flag. However, for cases
88 * where one item alone is to be submitted or there is a small set of jobs to
89 * be submitted sequentially, having a submit flag provides a lower-overhead
90 * way of doing the submission while still keeping the code clean.
92 * The second part is to obtain the result of requests:
93 * - rte_dma_completed()
94 * - return the number of operation requests completed successfully.
95 * - rte_dma_completed_status()
96 * - return the number of operation requests completed.
98 * @note If the dmadev works in silent mode (@see RTE_DMA_CAPA_SILENT),
99 * application does not invoke the above two completed APIs.
101 * About the ring_idx which enqueue APIs (e.g. rte_dma_copy(), rte_dma_fill())
102 * return, the rules are as follows:
103 * - ring_idx for each virtual DMA channel are independent.
104 * - For a virtual DMA channel, the ring_idx is monotonically incremented,
105 * when it reach UINT16_MAX, it wraps back to zero.
106 * - This ring_idx can be used by applications to track per-operation
107 * metadata in an application-defined circular ring.
108 * - The initial ring_idx of a virtual DMA channel is zero, after the
109 * device is stopped, the ring_idx needs to be reset to zero.
112 * - step-1: start one dmadev
113 * - step-2: enqueue a copy operation, the ring_idx return is 0
114 * - step-3: enqueue a copy operation again, the ring_idx return is 1
116 * - step-101: stop the dmadev
117 * - step-102: start the dmadev
118 * - step-103: enqueue a copy operation, the ring_idx return is 0
120 * - step-x+0: enqueue a fill operation, the ring_idx return is 65535
121 * - step-x+1: enqueue a copy operation, the ring_idx return is 0
124 * The DMA operation address used in enqueue APIs (i.e. rte_dma_copy(),
125 * rte_dma_copy_sg(), rte_dma_fill()) is defined as rte_iova_t type.
127 * The dmadev supports two types of address: memory address and device address.
129 * - memory address: the source and destination address of the memory-to-memory
130 * transfer type, or the source address of the memory-to-device transfer type,
131 * or the destination address of the device-to-memory transfer type.
132 * @note If the device support SVA (@see RTE_DMA_CAPA_SVA), the memory address
133 * can be any VA address, otherwise it must be an IOVA address.
135 * - device address: the source and destination address of the device-to-device
136 * transfer type, or the source address of the device-to-memory transfer type,
137 * or the destination address of the memory-to-device transfer type.
139 * About MT-safe, all the functions of the dmadev API implemented by a PMD are
140 * lock-free functions which assume to not be invoked in parallel on different
141 * logical cores to work on the same target dmadev object.
142 * @note Different virtual DMA channels on the same dmadev *DO NOT* support
143 * parallel invocation because these virtual DMA channels share the same
149 #include <rte_bitops.h>
150 #include <rte_common.h>
151 #include <rte_compat.h>
158 /** Maximum number of devices if rte_dma_dev_max() is not called. */
159 #define RTE_DMADEV_DEFAULT_MAX 64
163 * @b EXPERIMENTAL: this API may change without prior notice.
165 * Configure the maximum number of dmadevs.
166 * @note This function can be invoked before the primary process rte_eal_init()
167 * to change the maximum number of dmadevs. If not invoked, the maximum number
168 * of dmadevs is @see RTE_DMADEV_DEFAULT_MAX
171 * maximum number of dmadevs.
174 * 0 on success. Otherwise negative value is returned.
177 int rte_dma_dev_max(size_t dev_max);
181 * @b EXPERIMENTAL: this API may change without prior notice.
183 * Get the device identifier for the named DMA device.
189 * Returns DMA device identifier on success.
190 * - <0: Failure to find named DMA device.
193 int rte_dma_get_dev_id_by_name(const char *name);
197 * @b EXPERIMENTAL: this API may change without prior notice.
199 * Check whether the dev_id is valid.
205 * - If the device index is valid (true) or not (false).
208 bool rte_dma_is_valid(int16_t dev_id);
212 * @b EXPERIMENTAL: this API may change without prior notice.
214 * Get the total number of DMA devices that have been successfully
218 * The total number of usable DMA devices.
221 uint16_t rte_dma_count_avail(void);
224 * Iterates over valid dmadev instances.
226 * @param start_dev_id
227 * The id of the next possible dmadev.
229 * Next valid dmadev, UINT16_MAX if there is none.
232 int16_t rte_dma_next_dev(int16_t start_dev_id);
234 /** Utility macro to iterate over all available dmadevs */
235 #define RTE_DMA_FOREACH_DEV(p) \
236 for (p = rte_dma_next_dev(0); \
238 p = rte_dma_next_dev(p + 1))
241 /**@{@name DMA capability
242 * @see struct rte_dma_info::dev_capa
244 /** Support memory-to-memory transfer */
245 #define RTE_DMA_CAPA_MEM_TO_MEM RTE_BIT64(0)
246 /** Support memory-to-device transfer. */
247 #define RTE_DMA_CAPA_MEM_TO_DEV RTE_BIT64(1)
248 /** Support device-to-memory transfer. */
249 #define RTE_DMA_CAPA_DEV_TO_MEM RTE_BIT64(2)
250 /** Support device-to-device transfer. */
251 #define RTE_DMA_CAPA_DEV_TO_DEV RTE_BIT64(3)
252 /** Support SVA which could use VA as DMA address.
253 * If device support SVA then application could pass any VA address like memory
254 * from rte_malloc(), rte_memzone(), malloc, stack memory.
255 * If device don't support SVA, then application should pass IOVA address which
256 * from rte_malloc(), rte_memzone().
258 #define RTE_DMA_CAPA_SVA RTE_BIT64(4)
259 /** Support work in silent mode.
260 * In this mode, application don't required to invoke rte_dma_completed*()
262 * @see struct rte_dma_conf::silent_mode
264 #define RTE_DMA_CAPA_SILENT RTE_BIT64(5)
265 /** Support copy operation.
266 * This capability start with index of 32, so that it could leave gap between
267 * normal capability and ops capability.
269 #define RTE_DMA_CAPA_OPS_COPY RTE_BIT64(32)
270 /** Support scatter-gather list copy operation. */
271 #define RTE_DMA_CAPA_OPS_COPY_SG RTE_BIT64(33)
272 /** Support fill operation. */
273 #define RTE_DMA_CAPA_OPS_FILL RTE_BIT64(34)
277 * A structure used to retrieve the information of a DMA device.
279 * @see rte_dma_info_get
281 struct rte_dma_info {
282 const char *dev_name; /**< Unique device name. */
283 /** Device capabilities (RTE_DMA_CAPA_*). */
285 /** Maximum number of virtual DMA channels supported. */
287 /** Maximum allowed number of virtual DMA channel descriptors. */
289 /** Minimum allowed number of virtual DMA channel descriptors. */
291 /** Maximum number of source or destination scatter-gather entry
293 * If the device does not support COPY_SG capability, this value can be
295 * If the device supports COPY_SG capability, then rte_dma_copy_sg()
296 * parameter nb_src/nb_dst should not exceed this value.
299 /** NUMA node connection, -1 if unknown. */
301 /** Number of virtual DMA channel configured. */
307 * @b EXPERIMENTAL: this API may change without prior notice.
309 * Retrieve information of a DMA device.
312 * The identifier of the device.
313 * @param[out] dev_info
314 * A pointer to a structure of type *rte_dma_info* to be filled with the
315 * information of the device.
318 * 0 on success. Otherwise negative value is returned.
321 int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info);
324 * A structure used to configure a DMA device.
326 * @see rte_dma_configure
328 struct rte_dma_conf {
329 /** The number of virtual DMA channels to set up for the DMA device.
330 * This value cannot be greater than the field 'max_vchans' of struct
331 * rte_dma_info which get from rte_dma_info_get().
334 /** Indicates whether to enable silent mode.
335 * false-default mode, true-silent mode.
336 * This value can be set to true only when the SILENT capability is
339 * @see RTE_DMA_CAPA_SILENT
346 * @b EXPERIMENTAL: this API may change without prior notice.
348 * Configure a DMA device.
350 * This function must be invoked first before any other function in the
351 * API. This function can also be re-invoked when a device is in the
355 * The identifier of the device to configure.
357 * The DMA device configuration structure encapsulated into rte_dma_conf
361 * 0 on success. Otherwise negative value is returned.
364 int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf);
368 * @b EXPERIMENTAL: this API may change without prior notice.
370 * Start a DMA device.
372 * The device start step is the last one and consists of setting the DMA
373 * to start accepting jobs.
376 * The identifier of the device.
379 * 0 on success. Otherwise negative value is returned.
382 int rte_dma_start(int16_t dev_id);
386 * @b EXPERIMENTAL: this API may change without prior notice.
390 * The device can be restarted with a call to rte_dma_start().
393 * The identifier of the device.
396 * 0 on success. Otherwise negative value is returned.
399 int rte_dma_stop(int16_t dev_id);
403 * @b EXPERIMENTAL: this API may change without prior notice.
405 * Close a DMA device.
407 * The device cannot be restarted after this call.
410 * The identifier of the device.
413 * 0 on success. Otherwise negative value is returned.
416 int rte_dma_close(int16_t dev_id);
419 * DMA transfer direction defines.
421 * @see struct rte_dma_vchan_conf::direction
423 enum rte_dma_direction {
424 /** DMA transfer direction - from memory to memory.
426 * @see struct rte_dma_vchan_conf::direction
428 RTE_DMA_DIR_MEM_TO_MEM,
429 /** DMA transfer direction - from memory to device.
430 * In a typical scenario, the SoCs are installed on host servers as
431 * iNICs through the PCIe interface. In this case, the SoCs works in
432 * EP(endpoint) mode, it could initiate a DMA move request from memory
433 * (which is SoCs memory) to device (which is host memory).
435 * @see struct rte_dma_vchan_conf::direction
437 RTE_DMA_DIR_MEM_TO_DEV,
438 /** DMA transfer direction - from device to memory.
439 * In a typical scenario, the SoCs are installed on host servers as
440 * iNICs through the PCIe interface. In this case, the SoCs works in
441 * EP(endpoint) mode, it could initiate a DMA move request from device
442 * (which is host memory) to memory (which is SoCs memory).
444 * @see struct rte_dma_vchan_conf::direction
446 RTE_DMA_DIR_DEV_TO_MEM,
447 /** DMA transfer direction - from device to device.
448 * In a typical scenario, the SoCs are installed on host servers as
449 * iNICs through the PCIe interface. In this case, the SoCs works in
450 * EP(endpoint) mode, it could initiate a DMA move request from device
451 * (which is host memory) to the device (which is another host memory).
453 * @see struct rte_dma_vchan_conf::direction
455 RTE_DMA_DIR_DEV_TO_DEV,
459 * DMA access port type defines.
461 * @see struct rte_dma_port_param::port_type
463 enum rte_dma_port_type {
465 RTE_DMA_PORT_PCIE, /**< The DMA access port is PCIe. */
469 * A structure used to descript DMA access port parameters.
471 * @see struct rte_dma_vchan_conf::src_port
472 * @see struct rte_dma_vchan_conf::dst_port
474 struct rte_dma_port_param {
475 /** The device access port type.
477 * @see enum rte_dma_port_type
479 enum rte_dma_port_type port_type;
482 /** PCIe access port parameters.
484 * The following model shows SoC's PCIe module connects to
485 * multiple PCIe hosts and multiple endpoints. The PCIe module
486 * has an integrated DMA controller.
488 * If the DMA wants to access the memory of host A, it can be
489 * initiated by PF1 in core0, or by VF0 of PF0 in core0.
493 * | ----------PCIe module----------
496 * | ----- ------------------
497 * | | | | PCIe Core0 |
498 * | | | | | -----------
499 * | | | | PF-0 -- VF-0 | | Host A |
500 * | | |--------| |- VF-1 |--------| Root |
501 * | | | | PF-1 | | Complex |
502 * | | | | PF-2 | -----------
503 * | | | ------------------
505 * | | | ------------------
506 * | | | | PCIe Core1 |
507 * | | | | | -----------
508 * | | | | PF-0 -- VF-0 | | Host B |
509 * |-----| |--------| PF-1 -- VF-0 |--------| Root |
510 * | | | | |- VF-1 | | Complex |
511 * | | | | PF-2 | -----------
512 * | | | ------------------
514 * | | | ------------------
516 * | | | | |--------| EP |
517 * | | |--------| PCIe Core2 | ------
519 * | | | | |--------| EP |
521 * | ----- ------------------
525 * @note If some fields can not be supported by the
526 * hardware/driver, then the driver ignores those fields.
527 * Please check driver-specific documentation for limitations
532 uint64_t coreid : 4; /**< PCIe core id used. */
533 uint64_t pfid : 8; /**< PF id used. */
534 uint64_t vfen : 1; /**< VF enable bit. */
535 uint64_t vfid : 16; /**< VF id used. */
536 /** The pasid filed in TLP packet. */
538 /** The attributes filed in TLP packet. */
540 /** The processing hint filed in TLP packet. */
542 /** The steering tag filed in TLP packet. */
546 uint64_t reserved[2]; /**< Reserved for future fields. */
550 * A structure used to configure a virtual DMA channel.
552 * @see rte_dma_vchan_setup
554 struct rte_dma_vchan_conf {
555 /** Transfer direction
557 * @see enum rte_dma_direction
559 enum rte_dma_direction direction;
560 /** Number of descriptor for the virtual DMA channel */
562 /** 1) Used to describes the device access port parameter in the
563 * device-to-memory transfer scenario.
564 * 2) Used to describes the source device access port parameter in the
565 * device-to-device transfer scenario.
567 * @see struct rte_dma_port_param
569 struct rte_dma_port_param src_port;
570 /** 1) Used to describes the device access port parameter in the
571 * memory-to-device transfer scenario.
572 * 2) Used to describes the destination device access port parameter in
573 * the device-to-device transfer scenario.
575 * @see struct rte_dma_port_param
577 struct rte_dma_port_param dst_port;
582 * @b EXPERIMENTAL: this API may change without prior notice.
584 * Allocate and set up a virtual DMA channel.
587 * The identifier of the device.
589 * The identifier of virtual DMA channel. The value must be in the range
590 * [0, nb_vchans - 1] previously supplied to rte_dma_configure().
592 * The virtual DMA channel configuration structure encapsulated into
593 * rte_dma_vchan_conf object.
596 * 0 on success. Otherwise negative value is returned.
599 int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
600 const struct rte_dma_vchan_conf *conf);
603 * A structure used to retrieve statistics.
605 * @see rte_dma_stats_get
607 struct rte_dma_stats {
608 /** Count of operations which were submitted to hardware. */
610 /** Count of operations which were completed, including successful and
611 * failed completions.
614 /** Count of operations which failed to complete. */
619 * Special ID, which is used to represent all virtual DMA channels.
621 * @see rte_dma_stats_get
622 * @see rte_dma_stats_reset
624 #define RTE_DMA_ALL_VCHAN 0xFFFFu
628 * @b EXPERIMENTAL: this API may change without prior notice.
630 * Retrieve basic statistics of a or all virtual DMA channel(s).
633 * The identifier of the device.
635 * The identifier of virtual DMA channel.
636 * If equal RTE_DMA_ALL_VCHAN means all channels.
638 * The basic statistics structure encapsulated into rte_dma_stats
642 * 0 on success. Otherwise negative value is returned.
645 int rte_dma_stats_get(int16_t dev_id, uint16_t vchan,
646 struct rte_dma_stats *stats);
650 * @b EXPERIMENTAL: this API may change without prior notice.
652 * Reset basic statistics of a or all virtual DMA channel(s).
655 * The identifier of the device.
657 * The identifier of virtual DMA channel.
658 * If equal RTE_DMA_ALL_VCHAN means all channels.
661 * 0 on success. Otherwise negative value is returned.
664 int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan);
667 * device vchannel status
669 * Enum with the options for the channel status, either idle, active or halted due to error
670 * @see rte_dma_vchan_status
672 enum rte_dma_vchan_status {
673 RTE_DMA_VCHAN_IDLE, /**< not processing, awaiting ops */
674 RTE_DMA_VCHAN_ACTIVE, /**< currently processing jobs */
675 RTE_DMA_VCHAN_HALTED_ERROR, /**< not processing due to error, cannot accept new ops */
680 * @b EXPERIMENTAL: this API may change without prior notice.
682 * Determine if all jobs have completed on a device channel.
683 * This function is primarily designed for testing use, as it allows a process to check if
684 * all jobs are completed, without actually gathering completions from those jobs.
687 * The identifier of the device.
689 * The identifier of virtual DMA channel.
693 * 0 - call completed successfully
694 * < 0 - error code indicating there was a problem calling the API
698 rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status);
702 * @b EXPERIMENTAL: this API may change without prior notice.
704 * Dump DMA device info.
707 * The identifier of the device.
709 * The file to write the output to.
712 * 0 on success. Otherwise negative value is returned.
715 int rte_dma_dump(int16_t dev_id, FILE *f);
718 * DMA transfer result status code defines.
720 * @see rte_dma_completed_status
722 enum rte_dma_status_code {
723 /** The operation completed successfully. */
724 RTE_DMA_STATUS_SUCCESSFUL,
725 /** The operation failed to complete due abort by user.
726 * This is mainly used when processing dev_stop, user could modidy the
727 * descriptors (e.g. change one bit to tell hardware abort this job),
728 * it allows outstanding requests to be complete as much as possible,
729 * so reduce the time to stop the device.
731 RTE_DMA_STATUS_USER_ABORT,
732 /** The operation failed to complete due to following scenarios:
733 * The jobs in a particular batch are not attempted because they
734 * appeared after a fence where a previous job failed. In some HW
735 * implementation it's possible for jobs from later batches would be
736 * completed, though, so report the status from the not attempted jobs
737 * before reporting those newer completed jobs.
739 RTE_DMA_STATUS_NOT_ATTEMPTED,
740 /** The operation failed to complete due invalid source address. */
741 RTE_DMA_STATUS_INVALID_SRC_ADDR,
742 /** The operation failed to complete due invalid destination address. */
743 RTE_DMA_STATUS_INVALID_DST_ADDR,
744 /** The operation failed to complete due invalid source or destination
745 * address, cover the case that only knows the address error, but not
746 * sure which address error.
748 RTE_DMA_STATUS_INVALID_ADDR,
749 /** The operation failed to complete due invalid length. */
750 RTE_DMA_STATUS_INVALID_LENGTH,
751 /** The operation failed to complete due invalid opcode.
752 * The DMA descriptor could have multiple format, which are
753 * distinguished by the opcode field.
755 RTE_DMA_STATUS_INVALID_OPCODE,
756 /** The operation failed to complete due bus read error. */
757 RTE_DMA_STATUS_BUS_READ_ERROR,
758 /** The operation failed to complete due bus write error. */
759 RTE_DMA_STATUS_BUS_WRITE_ERROR,
760 /** The operation failed to complete due bus error, cover the case that
761 * only knows the bus error, but not sure which direction error.
763 RTE_DMA_STATUS_BUS_ERROR,
764 /** The operation failed to complete due data poison. */
765 RTE_DMA_STATUS_DATA_POISION,
766 /** The operation failed to complete due descriptor read error. */
767 RTE_DMA_STATUS_DESCRIPTOR_READ_ERROR,
768 /** The operation failed to complete due device link error.
769 * Used to indicates that the link error in the memory-to-device/
770 * device-to-memory/device-to-device transfer scenario.
772 RTE_DMA_STATUS_DEV_LINK_ERROR,
773 /** The operation failed to complete due lookup page fault. */
774 RTE_DMA_STATUS_PAGE_FAULT,
775 /** The operation failed to complete due unknown reason.
776 * The initial value is 256, which reserves space for future errors.
778 RTE_DMA_STATUS_ERROR_UNKNOWN = 0x100,
782 * A structure used to hold scatter-gather DMA operation request entry.
784 * @see rte_dma_copy_sg
787 rte_iova_t addr; /**< The DMA operation address. */
788 uint32_t length; /**< The DMA operation length. */
791 #include "rte_dmadev_core.h"
793 /**@{@name DMA operation flag
794 * @see rte_dma_copy()
795 * @see rte_dma_copy_sg()
796 * @see rte_dma_fill()
799 * It means the operation with this flag must be processed only after all
800 * previous operations are completed.
801 * If the specify DMA HW works in-order (it means it has default fence between
802 * operations), this flag could be NOP.
804 #define RTE_DMA_OP_FLAG_FENCE RTE_BIT64(0)
806 * It means the operation with this flag must issue doorbell to hardware after
809 #define RTE_DMA_OP_FLAG_SUBMIT RTE_BIT64(1)
810 /** Write data to low level cache hint.
811 * Used for performance optimization, this is just a hint, and there is no
812 * capability bit for this, driver should not return error if this flag was set.
814 #define RTE_DMA_OP_FLAG_LLC RTE_BIT64(2)
819 * @b EXPERIMENTAL: this API may change without prior notice.
821 * Enqueue a copy operation onto the virtual DMA channel.
823 * This queues up a copy operation to be performed by hardware, if the 'flags'
824 * parameter contains RTE_DMA_OP_FLAG_SUBMIT then trigger doorbell to begin
825 * this operation, otherwise do not trigger doorbell.
828 * The identifier of the device.
830 * The identifier of virtual DMA channel.
832 * The address of the source buffer.
834 * The address of the destination buffer.
836 * The length of the data to be copied.
838 * An flags for this operation.
839 * @see RTE_DMA_OP_FLAG_*
842 * - 0..UINT16_MAX: index of enqueued job.
843 * - -ENOSPC: if no space left to enqueue.
844 * - other values < 0 on failure.
848 rte_dma_copy(int16_t dev_id, uint16_t vchan, rte_iova_t src, rte_iova_t dst,
849 uint32_t length, uint64_t flags)
851 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
853 #ifdef RTE_DMADEV_DEBUG
854 if (!rte_dma_is_valid(dev_id) || length == 0)
856 RTE_FUNC_PTR_OR_ERR_RET(*obj->copy, -ENOTSUP);
859 return (*obj->copy)(obj->dev_private, vchan, src, dst, length, flags);
864 * @b EXPERIMENTAL: this API may change without prior notice.
866 * Enqueue a scatter-gather list copy operation onto the virtual DMA channel.
868 * This queues up a scatter-gather list copy operation to be performed by
869 * hardware, if the 'flags' parameter contains RTE_DMA_OP_FLAG_SUBMIT then
870 * trigger doorbell to begin this operation, otherwise do not trigger doorbell.
873 * The identifier of the device.
875 * The identifier of virtual DMA channel.
877 * The pointer of source scatter-gather entry array.
879 * The pointer of destination scatter-gather entry array.
881 * The number of source scatter-gather entry.
882 * @see struct rte_dma_info::max_sges
884 * The number of destination scatter-gather entry.
885 * @see struct rte_dma_info::max_sges
887 * An flags for this operation.
888 * @see RTE_DMA_OP_FLAG_*
891 * - 0..UINT16_MAX: index of enqueued job.
892 * - -ENOSPC: if no space left to enqueue.
893 * - other values < 0 on failure.
897 rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src,
898 struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst,
901 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
903 #ifdef RTE_DMADEV_DEBUG
904 if (!rte_dma_is_valid(dev_id) || src == NULL || dst == NULL ||
905 nb_src == 0 || nb_dst == 0)
907 RTE_FUNC_PTR_OR_ERR_RET(*obj->copy_sg, -ENOTSUP);
910 return (*obj->copy_sg)(obj->dev_private, vchan, src, dst, nb_src,
916 * @b EXPERIMENTAL: this API may change without prior notice.
918 * Enqueue a fill operation onto the virtual DMA channel.
920 * This queues up a fill operation to be performed by hardware, if the 'flags'
921 * parameter contains RTE_DMA_OP_FLAG_SUBMIT then trigger doorbell to begin
922 * this operation, otherwise do not trigger doorbell.
925 * The identifier of the device.
927 * The identifier of virtual DMA channel.
929 * The pattern to populate the destination buffer with.
931 * The address of the destination buffer.
933 * The length of the destination buffer.
935 * An flags for this operation.
936 * @see RTE_DMA_OP_FLAG_*
939 * - 0..UINT16_MAX: index of enqueued job.
940 * - -ENOSPC: if no space left to enqueue.
941 * - other values < 0 on failure.
945 rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern,
946 rte_iova_t dst, uint32_t length, uint64_t flags)
948 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
950 #ifdef RTE_DMADEV_DEBUG
951 if (!rte_dma_is_valid(dev_id) || length == 0)
953 RTE_FUNC_PTR_OR_ERR_RET(*obj->fill, -ENOTSUP);
956 return (*obj->fill)(obj->dev_private, vchan, pattern, dst, length,
962 * @b EXPERIMENTAL: this API may change without prior notice.
964 * Trigger hardware to begin performing enqueued operations.
966 * This API is used to write the "doorbell" to the hardware to trigger it
967 * to begin the operations previously enqueued by rte_dma_copy/fill().
970 * The identifier of the device.
972 * The identifier of virtual DMA channel.
975 * 0 on success. Otherwise negative value is returned.
979 rte_dma_submit(int16_t dev_id, uint16_t vchan)
981 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
983 #ifdef RTE_DMADEV_DEBUG
984 if (!rte_dma_is_valid(dev_id))
986 RTE_FUNC_PTR_OR_ERR_RET(*obj->submit, -ENOTSUP);
989 return (*obj->submit)(obj->dev_private, vchan);
994 * @b EXPERIMENTAL: this API may change without prior notice.
996 * Return the number of operations that have been successfully completed.
999 * The identifier of the device.
1001 * The identifier of virtual DMA channel.
1003 * The maximum number of completed operations that can be processed.
1004 * @param[out] last_idx
1005 * The last completed operation's ring_idx.
1006 * If not required, NULL can be passed in.
1007 * @param[out] has_error
1008 * Indicates if there are transfer error.
1009 * If not required, NULL can be passed in.
1012 * The number of operations that successfully completed. This return value
1013 * must be less than or equal to the value of nb_cpls.
1016 static inline uint16_t
1017 rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls,
1018 uint16_t *last_idx, bool *has_error)
1020 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1024 #ifdef RTE_DMADEV_DEBUG
1025 if (!rte_dma_is_valid(dev_id) || nb_cpls == 0)
1027 RTE_FUNC_PTR_OR_ERR_RET(*obj->completed, 0);
1030 /* Ensure the pointer values are non-null to simplify drivers.
1031 * In most cases these should be compile time evaluated, since this is
1032 * an inline function.
1033 * - If NULL is explicitly passed as parameter, then compiler knows the
1035 * - If address of local variable is passed as parameter, then compiler
1036 * can know it's non-NULL.
1038 if (last_idx == NULL)
1040 if (has_error == NULL)
1044 return (*obj->completed)(obj->dev_private, vchan, nb_cpls, last_idx,
1050 * @b EXPERIMENTAL: this API may change without prior notice.
1052 * Return the number of operations that have been completed, and the operations
1053 * result may succeed or fail.
1056 * The identifier of the device.
1058 * The identifier of virtual DMA channel.
1060 * Indicates the size of status array.
1061 * @param[out] last_idx
1062 * The last completed operation's ring_idx.
1063 * If not required, NULL can be passed in.
1064 * @param[out] status
1065 * This is a pointer to an array of length 'nb_cpls' that holds the completion
1066 * status code of each operation.
1067 * @see enum rte_dma_status_code
1070 * The number of operations that completed. This return value must be less
1071 * than or equal to the value of nb_cpls.
1072 * If this number is greater than zero (assuming n), then n values in the
1073 * status array are also set.
1076 static inline uint16_t
1077 rte_dma_completed_status(int16_t dev_id, uint16_t vchan,
1078 const uint16_t nb_cpls, uint16_t *last_idx,
1079 enum rte_dma_status_code *status)
1081 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1084 #ifdef RTE_DMADEV_DEBUG
1085 if (!rte_dma_is_valid(dev_id) || nb_cpls == 0 || status == NULL)
1087 RTE_FUNC_PTR_OR_ERR_RET(*obj->completed_status, 0);
1090 if (last_idx == NULL)
1093 return (*obj->completed_status)(obj->dev_private, vchan, nb_cpls,
1099 * @b EXPERIMENTAL: this API may change without prior notice.
1101 * Check remaining capacity in descriptor ring for the current burst.
1104 * The identifier of the device.
1106 * The identifier of virtual DMA channel.
1109 * - Remaining space in the descriptor ring for the current burst.
1113 static inline uint16_t
1114 rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
1116 struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1118 #ifdef RTE_DMADEV_DEBUG
1119 if (!rte_dma_is_valid(dev_id))
1121 RTE_FUNC_PTR_OR_ERR_RET(*obbj->burst_capacity, 0);
1123 return (*obj->burst_capacity)(obj->dev_private, vchan);
1130 #endif /* RTE_DMADEV_H */