DPDK  24.11.6
rte_dmadev.h
Go to the documentation of this file.
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
6  */
7 
8 #ifndef RTE_DMADEV_H
9 #define RTE_DMADEV_H
10 
147 #include <stdint.h>
148 #include <errno.h>
149 
150 #include <rte_bitops.h>
151 #include <rte_common.h>
152 
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 
158 #define RTE_DMADEV_DEFAULT_MAX 64
159 
172 int rte_dma_dev_max(size_t dev_max);
173 
184 int rte_dma_get_dev_id_by_name(const char *name);
185 
195 bool rte_dma_is_valid(int16_t dev_id);
196 
204 uint16_t rte_dma_count_avail(void);
205 
214 int16_t rte_dma_next_dev(int16_t start_dev_id);
215 
217 #define RTE_DMA_FOREACH_DEV(p) \
218  for (p = rte_dma_next_dev(0); \
219  p != -1; \
220  p = rte_dma_next_dev(p + 1))
221 
222 
227 #define RTE_DMA_CAPA_MEM_TO_MEM RTE_BIT64(0)
228 
229 #define RTE_DMA_CAPA_MEM_TO_DEV RTE_BIT64(1)
230 
231 #define RTE_DMA_CAPA_DEV_TO_MEM RTE_BIT64(2)
232 
233 #define RTE_DMA_CAPA_DEV_TO_DEV RTE_BIT64(3)
234 
240 #define RTE_DMA_CAPA_SVA RTE_BIT64(4)
241 
246 #define RTE_DMA_CAPA_SILENT RTE_BIT64(5)
247 
254 #define RTE_DMA_CAPA_HANDLES_ERRORS RTE_BIT64(6)
255 
261 #define RTE_DMA_CAPA_M2D_AUTO_FREE RTE_BIT64(7)
262 
268 #define RTE_DMA_CAPA_PRI_POLICY_SP RTE_BIT64(8)
269 
274 #define RTE_DMA_CAPA_OPS_COPY RTE_BIT64(32)
275 
276 #define RTE_DMA_CAPA_OPS_COPY_SG RTE_BIT64(33)
277 
278 #define RTE_DMA_CAPA_OPS_FILL RTE_BIT64(34)
279 
286 struct rte_dma_info {
287  const char *dev_name;
289  uint64_t dev_capa;
291  uint16_t max_vchans;
293  uint16_t max_desc;
295  uint16_t min_desc;
303  uint16_t max_sges;
305  int16_t numa_node;
307  uint16_t nb_vchans;
311  uint16_t nb_priorities;
312 };
313 
326 int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info);
327 
333 struct rte_dma_conf {
338  uint16_t nb_vchans;
347  /* The priority of the DMA device.
348  * This value should be lower than the field 'nb_priorities' of struct
349  * rte_dma_info which get from rte_dma_info_get(). If the DMA device
350  * does not support priority scheduling, this value should be zero.
351  *
352  * Lowest value indicates higher priority and vice-versa.
353  */
354  uint16_t priority;
355 };
356 
373 int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf);
374 
387 int rte_dma_start(int16_t dev_id);
388 
400 int rte_dma_stop(int16_t dev_id);
401 
413 int rte_dma_close(int16_t dev_id);
414 
453 };
454 
461  RTE_DMA_PORT_NONE,
463 };
464 
477  union {
526  __extension__
527  struct {
528  uint64_t coreid : 4;
529  uint64_t pfid : 8;
530  uint64_t vfen : 1;
531  uint64_t vfid : 16;
533  uint64_t pasid : 20;
535  uint64_t attr : 3;
537  uint64_t ph : 2;
539  uint64_t st : 16;
540  } pcie;
541  };
542  uint64_t reserved[2];
543 };
544 
549  union {
550  struct {
558  struct rte_mempool *pool;
559  } m2d;
560  };
562  uint64_t reserved[2];
563 };
564 
577  uint16_t nb_desc;
602 };
603 
619 int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
620  const struct rte_dma_vchan_conf *conf);
621 
629  uint64_t submitted;
633  uint64_t completed;
635  uint64_t errors;
636 };
637 
644 #define RTE_DMA_ALL_VCHAN 0xFFFFu
645 
661 int rte_dma_stats_get(int16_t dev_id, uint16_t vchan,
662  struct rte_dma_stats *stats);
663 
676 int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan);
677 
688 };
689 
705 int
706 rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status);
707 
719 int rte_dma_dump(int16_t dev_id, FILE *f);
720 
783 };
784 
790 struct rte_dma_sge {
792  uint32_t length;
793 };
794 
795 #ifdef __cplusplus
796 }
797 #endif
798 
799 #include "rte_dmadev_core.h"
800 #include "rte_dmadev_trace_fp.h"
801 
802 #ifdef __cplusplus
803 extern "C" {
804 #endif
805 
817 #define RTE_DMA_OP_FLAG_FENCE RTE_BIT64(0)
818 
822 #define RTE_DMA_OP_FLAG_SUBMIT RTE_BIT64(1)
823 
827 #define RTE_DMA_OP_FLAG_LLC RTE_BIT64(2)
828 
834 #define RTE_DMA_OP_FLAG_AUTO_FREE RTE_BIT64(3)
835 
863 static inline int
864 rte_dma_copy(int16_t dev_id, uint16_t vchan, rte_iova_t src, rte_iova_t dst,
865  uint32_t length, uint64_t flags)
866 {
867  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
868  int ret;
869 
870 #ifdef RTE_DMADEV_DEBUG
871  if (!rte_dma_is_valid(dev_id) || length == 0)
872  return -EINVAL;
873  if (*obj->copy == NULL)
874  return -ENOTSUP;
875 #endif
876 
877  ret = (*obj->copy)(obj->dev_private, vchan, src, dst, length, flags);
878  rte_dma_trace_copy(dev_id, vchan, src, dst, length, flags, ret);
879 
880  return ret;
881 }
882 
913 static inline int
914 rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src,
915  struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst,
916  uint64_t flags)
917 {
918  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
919  int ret;
920 
921 #ifdef RTE_DMADEV_DEBUG
922  if (!rte_dma_is_valid(dev_id) || src == NULL || dst == NULL ||
923  nb_src == 0 || nb_dst == 0)
924  return -EINVAL;
925  if (*obj->copy_sg == NULL)
926  return -ENOTSUP;
927 #endif
928 
929  ret = (*obj->copy_sg)(obj->dev_private, vchan, src, dst, nb_src,
930  nb_dst, flags);
931  rte_dma_trace_copy_sg(dev_id, vchan, src, dst, nb_src, nb_dst, flags,
932  ret);
933 
934  return ret;
935 }
936 
963 static inline int
964 rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern,
965  rte_iova_t dst, uint32_t length, uint64_t flags)
966 {
967  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
968  int ret;
969 
970 #ifdef RTE_DMADEV_DEBUG
971  if (!rte_dma_is_valid(dev_id) || length == 0)
972  return -EINVAL;
973  if (*obj->fill == NULL)
974  return -ENOTSUP;
975 #endif
976 
977  ret = (*obj->fill)(obj->dev_private, vchan, pattern, dst, length,
978  flags);
979  rte_dma_trace_fill(dev_id, vchan, pattern, dst, length, flags, ret);
980 
981  return ret;
982 }
983 
998 static inline int
999 rte_dma_submit(int16_t dev_id, uint16_t vchan)
1000 {
1001  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1002  int ret;
1003 
1004 #ifdef RTE_DMADEV_DEBUG
1005  if (!rte_dma_is_valid(dev_id))
1006  return -EINVAL;
1007  if (*obj->submit == NULL)
1008  return -ENOTSUP;
1009 #endif
1010 
1011  ret = (*obj->submit)(obj->dev_private, vchan);
1012  rte_dma_trace_submit(dev_id, vchan, ret);
1013 
1014  return ret;
1015 }
1016 
1039 static inline uint16_t
1040 rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls,
1041  uint16_t *last_idx, bool *has_error)
1042 {
1043  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1044  uint16_t idx, ret;
1045  bool err;
1046 
1047 #ifdef RTE_DMADEV_DEBUG
1048  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0)
1049  return 0;
1050  if (*obj->completed == NULL)
1051  return 0;
1052 #endif
1053 
1054  /* Ensure the pointer values are non-null to simplify drivers.
1055  * In most cases these should be compile time evaluated, since this is
1056  * an inline function.
1057  * - If NULL is explicitly passed as parameter, then compiler knows the
1058  * value is NULL
1059  * - If address of local variable is passed as parameter, then compiler
1060  * can know it's non-NULL.
1061  */
1062  if (last_idx == NULL)
1063  last_idx = &idx;
1064  if (has_error == NULL)
1065  has_error = &err;
1066 
1067  *has_error = false;
1068  ret = (*obj->completed)(obj->dev_private, vchan, nb_cpls, last_idx,
1069  has_error);
1070  rte_dma_trace_completed(dev_id, vchan, nb_cpls, last_idx, has_error,
1071  ret);
1072 
1073  return ret;
1074 }
1075 
1102 static inline uint16_t
1103 rte_dma_completed_status(int16_t dev_id, uint16_t vchan,
1104  const uint16_t nb_cpls, uint16_t *last_idx,
1105  enum rte_dma_status_code *status)
1106 {
1107  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1108  uint16_t idx, ret;
1109 
1110 #ifdef RTE_DMADEV_DEBUG
1111  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0 || status == NULL)
1112  return 0;
1113  if (*obj->completed_status == NULL)
1114  return 0;
1115 #endif
1116 
1117  if (last_idx == NULL)
1118  last_idx = &idx;
1119 
1120  ret = (*obj->completed_status)(obj->dev_private, vchan, nb_cpls,
1121  last_idx, status);
1122  rte_dma_trace_completed_status(dev_id, vchan, nb_cpls, last_idx, status,
1123  ret);
1124 
1125  return ret;
1126 }
1127 
1140 static inline uint16_t
1141 rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
1142 {
1143  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1144  uint16_t ret;
1145 
1146 #ifdef RTE_DMADEV_DEBUG
1147  if (!rte_dma_is_valid(dev_id))
1148  return 0;
1149  if (*obj->burst_capacity == NULL)
1150  return 0;
1151 #endif
1152  ret = (*obj->burst_capacity)(obj->dev_private, vchan);
1153  rte_dma_trace_burst_capacity(dev_id, vchan, ret);
1154 
1155  return ret;
1156 }
1157 
1158 #ifdef __cplusplus
1159 }
1160 #endif
1161 
1162 #endif /* RTE_DMADEV_H */
uint16_t max_desc
Definition: rte_dmadev.h:293
int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
uint16_t nb_vchans
Definition: rte_dmadev.h:338
uint16_t rte_dma_count_avail(void)
int rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
int rte_dma_start(int16_t dev_id)
int rte_dma_stop(int16_t dev_id)
static int rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src, struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst, uint64_t flags)
Definition: rte_dmadev.h:914
uint64_t rte_iova_t
Definition: rte_common.h:662
struct rte_dma_auto_free_param auto_free
Definition: rte_dmadev.h:601
rte_iova_t addr
Definition: rte_dmadev.h:791
struct rte_dma_port_param dst_port
Definition: rte_dmadev.h:593
int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
uint64_t dev_capa
Definition: rte_dmadev.h:289
__extension__ struct rte_dma_port_param::@135::@137 pcie
static int rte_dma_copy(int16_t dev_id, uint16_t vchan, rte_iova_t src, rte_iova_t dst, uint32_t length, uint64_t flags)
Definition: rte_dmadev.h:864
bool rte_dma_is_valid(int16_t dev_id)
int rte_dma_get_dev_id_by_name(const char *name)
int rte_dma_close(int16_t dev_id)
int rte_dma_dev_max(size_t dev_max)
int16_t rte_dma_next_dev(int16_t start_dev_id)
rte_dma_direction
Definition: rte_dmadev.h:420
int rte_dma_dump(int16_t dev_id, FILE *f)
bool enable_silent
Definition: rte_dmadev.h:346
rte_dma_port_type
Definition: rte_dmadev.h:460
struct rte_dma_port_param src_port
Definition: rte_dmadev.h:585
uint16_t max_sges
Definition: rte_dmadev.h:303
const char * dev_name
Definition: rte_dmadev.h:287
uint64_t reserved[2]
Definition: rte_dmadev.h:542
static int rte_dma_submit(int16_t dev_id, uint16_t vchan)
Definition: rte_dmadev.h:999
uint64_t errors
Definition: rte_dmadev.h:635
int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
int16_t numa_node
Definition: rte_dmadev.h:305
enum rte_dma_port_type port_type
Definition: rte_dmadev.h:476
rte_dma_status_code
Definition: rte_dmadev.h:726
int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan, const struct rte_dma_vchan_conf *conf)
uint16_t min_desc
Definition: rte_dmadev.h:295
static uint16_t rte_dma_completed_status(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls, uint16_t *last_idx, enum rte_dma_status_code *status)
Definition: rte_dmadev.h:1103
uint16_t max_vchans
Definition: rte_dmadev.h:291
enum rte_dma_direction direction
Definition: rte_dmadev.h:575
static uint16_t rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
Definition: rte_dmadev.h:1141
rte_dma_vchan_status
Definition: rte_dmadev.h:684
uint64_t completed
Definition: rte_dmadev.h:633
uint64_t submitted
Definition: rte_dmadev.h:629
static int rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern, rte_iova_t dst, uint32_t length, uint64_t flags)
Definition: rte_dmadev.h:964
static uint16_t rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls, uint16_t *last_idx, bool *has_error)
Definition: rte_dmadev.h:1040
uint16_t nb_vchans
Definition: rte_dmadev.h:307
uint32_t length
Definition: rte_dmadev.h:792
struct rte_mempool * pool
Definition: rte_dmadev.h:558
uint16_t nb_priorities
Definition: rte_dmadev.h:311