DPDK  22.07.0
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 
149 #include <rte_bitops.h>
150 #include <rte_common.h>
151 #include <rte_compat.h>
152 
153 #ifdef __cplusplus
154 extern "C" {
155 #endif
156 
158 #define RTE_DMADEV_DEFAULT_MAX 64
159 
175 __rte_experimental
176 int rte_dma_dev_max(size_t dev_max);
177 
191 __rte_experimental
192 int rte_dma_get_dev_id_by_name(const char *name);
193 
206 __rte_experimental
207 bool rte_dma_is_valid(int16_t dev_id);
208 
219 __rte_experimental
220 uint16_t rte_dma_count_avail(void);
221 
230 __rte_experimental
231 int16_t rte_dma_next_dev(int16_t start_dev_id);
232 
234 #define RTE_DMA_FOREACH_DEV(p) \
235  for (p = rte_dma_next_dev(0); \
236  p != -1; \
237  p = rte_dma_next_dev(p + 1))
238 
239 
244 #define RTE_DMA_CAPA_MEM_TO_MEM RTE_BIT64(0)
245 
246 #define RTE_DMA_CAPA_MEM_TO_DEV RTE_BIT64(1)
247 
248 #define RTE_DMA_CAPA_DEV_TO_MEM RTE_BIT64(2)
249 
250 #define RTE_DMA_CAPA_DEV_TO_DEV RTE_BIT64(3)
251 
257 #define RTE_DMA_CAPA_SVA RTE_BIT64(4)
258 
263 #define RTE_DMA_CAPA_SILENT RTE_BIT64(5)
264 
271 #define RTE_DMA_CAPA_HANDLES_ERRORS RTE_BIT64(6)
272 
276 #define RTE_DMA_CAPA_OPS_COPY RTE_BIT64(32)
277 
278 #define RTE_DMA_CAPA_OPS_COPY_SG RTE_BIT64(33)
279 
280 #define RTE_DMA_CAPA_OPS_FILL RTE_BIT64(34)
281 
288 struct rte_dma_info {
289  const char *dev_name;
291  uint64_t dev_capa;
293  uint16_t max_vchans;
295  uint16_t max_desc;
297  uint16_t min_desc;
305  uint16_t max_sges;
307  int16_t numa_node;
309  uint16_t nb_vchans;
310 };
311 
327 __rte_experimental
328 int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info);
329 
335 struct rte_dma_conf {
340  uint16_t nb_vchans;
349 };
350 
370 __rte_experimental
371 int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf);
372 
388 __rte_experimental
389 int rte_dma_start(int16_t dev_id);
390 
405 __rte_experimental
406 int rte_dma_stop(int16_t dev_id);
407 
422 __rte_experimental
423 int rte_dma_close(int16_t dev_id);
424 
463 };
464 
471  RTE_DMA_PORT_NONE,
473 };
474 
486  enum rte_dma_port_type port_type;
488  union {
537  __extension__
538  struct {
539  uint64_t coreid : 4;
540  uint64_t pfid : 8;
541  uint64_t vfen : 1;
542  uint64_t vfid : 16;
544  uint64_t pasid : 20;
546  uint64_t attr : 3;
548  uint64_t ph : 2;
550  uint64_t st : 16;
551  } pcie;
552  };
553  uint64_t reserved[2];
554 };
555 
566  enum rte_dma_direction direction;
568  uint16_t nb_desc;
576  struct rte_dma_port_param src_port;
584  struct rte_dma_port_param dst_port;
585 };
586 
605 __rte_experimental
606 int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
607  const struct rte_dma_vchan_conf *conf);
608 
616  uint64_t submitted;
620  uint64_t completed;
622  uint64_t errors;
623 };
624 
631 #define RTE_DMA_ALL_VCHAN 0xFFFFu
632 
651 __rte_experimental
652 int rte_dma_stats_get(int16_t dev_id, uint16_t vchan,
653  struct rte_dma_stats *stats);
654 
670 __rte_experimental
671 int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan);
672 
683 };
684 
703 __rte_experimental
704 int
705 rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status);
706 
721 __rte_experimental
722 int rte_dma_dump(int16_t dev_id, FILE *f);
723 
786 };
787 
793 struct rte_dma_sge {
795  uint32_t length;
796 };
797 
798 #include "rte_dmadev_core.h"
799 
811 #define RTE_DMA_OP_FLAG_FENCE RTE_BIT64(0)
812 
816 #define RTE_DMA_OP_FLAG_SUBMIT RTE_BIT64(1)
817 
821 #define RTE_DMA_OP_FLAG_LLC RTE_BIT64(2)
822 
853 __rte_experimental
854 static inline int
855 rte_dma_copy(int16_t dev_id, uint16_t vchan, rte_iova_t src, rte_iova_t dst,
856  uint32_t length, uint64_t flags)
857 {
858  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
859 
860 #ifdef RTE_DMADEV_DEBUG
861  if (!rte_dma_is_valid(dev_id) || length == 0)
862  return -EINVAL;
863  RTE_FUNC_PTR_OR_ERR_RET(*obj->copy, -ENOTSUP);
864 #endif
865 
866  return (*obj->copy)(obj->dev_private, vchan, src, dst, length, flags);
867 }
868 
902 __rte_experimental
903 static inline int
904 rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src,
905  struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst,
906  uint64_t flags)
907 {
908  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
909 
910 #ifdef RTE_DMADEV_DEBUG
911  if (!rte_dma_is_valid(dev_id) || src == NULL || dst == NULL ||
912  nb_src == 0 || nb_dst == 0)
913  return -EINVAL;
914  RTE_FUNC_PTR_OR_ERR_RET(*obj->copy_sg, -ENOTSUP);
915 #endif
916 
917  return (*obj->copy_sg)(obj->dev_private, vchan, src, dst, nb_src,
918  nb_dst, flags);
919 }
920 
950 __rte_experimental
951 static inline int
952 rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern,
953  rte_iova_t dst, uint32_t length, uint64_t flags)
954 {
955  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
956 
957 #ifdef RTE_DMADEV_DEBUG
958  if (!rte_dma_is_valid(dev_id) || length == 0)
959  return -EINVAL;
960  RTE_FUNC_PTR_OR_ERR_RET(*obj->fill, -ENOTSUP);
961 #endif
962 
963  return (*obj->fill)(obj->dev_private, vchan, pattern, dst, length,
964  flags);
965 }
966 
984 __rte_experimental
985 static inline int
986 rte_dma_submit(int16_t dev_id, uint16_t vchan)
987 {
988  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
989 
990 #ifdef RTE_DMADEV_DEBUG
991  if (!rte_dma_is_valid(dev_id))
992  return -EINVAL;
993  RTE_FUNC_PTR_OR_ERR_RET(*obj->submit, -ENOTSUP);
994 #endif
995 
996  return (*obj->submit)(obj->dev_private, vchan);
997 }
998 
1024 __rte_experimental
1025 static inline uint16_t
1026 rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls,
1027  uint16_t *last_idx, bool *has_error)
1028 {
1029  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1030  uint16_t idx;
1031  bool err;
1032 
1033 #ifdef RTE_DMADEV_DEBUG
1034  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0)
1035  return 0;
1036  RTE_FUNC_PTR_OR_ERR_RET(*obj->completed, 0);
1037 #endif
1038 
1039  /* Ensure the pointer values are non-null to simplify drivers.
1040  * In most cases these should be compile time evaluated, since this is
1041  * an inline function.
1042  * - If NULL is explicitly passed as parameter, then compiler knows the
1043  * value is NULL
1044  * - If address of local variable is passed as parameter, then compiler
1045  * can know it's non-NULL.
1046  */
1047  if (last_idx == NULL)
1048  last_idx = &idx;
1049  if (has_error == NULL)
1050  has_error = &err;
1051 
1052  *has_error = false;
1053  return (*obj->completed)(obj->dev_private, vchan, nb_cpls, last_idx,
1054  has_error);
1055 }
1056 
1086 __rte_experimental
1087 static inline uint16_t
1088 rte_dma_completed_status(int16_t dev_id, uint16_t vchan,
1089  const uint16_t nb_cpls, uint16_t *last_idx,
1090  enum rte_dma_status_code *status)
1091 {
1092  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1093  uint16_t idx;
1094 
1095 #ifdef RTE_DMADEV_DEBUG
1096  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0 || status == NULL)
1097  return 0;
1098  RTE_FUNC_PTR_OR_ERR_RET(*obj->completed_status, 0);
1099 #endif
1100 
1101  if (last_idx == NULL)
1102  last_idx = &idx;
1103 
1104  return (*obj->completed_status)(obj->dev_private, vchan, nb_cpls,
1105  last_idx, status);
1106 }
1107 
1123 __rte_experimental
1124 static inline uint16_t
1125 rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
1126 {
1127  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1128 
1129 #ifdef RTE_DMADEV_DEBUG
1130  if (!rte_dma_is_valid(dev_id))
1131  return 0;
1132  RTE_FUNC_PTR_OR_ERR_RET(*obj->burst_capacity, 0);
1133 #endif
1134  return (*obj->burst_capacity)(obj->dev_private, vchan);
1135 }
1136 
1137 #ifdef __cplusplus
1138 }
1139 #endif
1140 
1141 #endif /* RTE_DMADEV_H */
__rte_experimental uint16_t rte_dma_count_avail(void)
uint16_t max_desc
Definition: rte_dmadev.h:295
uint16_t nb_vchans
Definition: rte_dmadev.h:340
uint64_t rte_iova_t
Definition: rte_common.h:463
__rte_experimental int rte_dma_dump(int16_t dev_id, FILE *f)
rte_iova_t addr
Definition: rte_dmadev.h:794
__rte_experimental bool rte_dma_is_valid(int16_t dev_id)
uint64_t dev_capa
Definition: rte_dmadev.h:291
__rte_experimental int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
static __rte_experimental 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:904
rte_dma_direction
Definition: rte_dmadev.h:430
__rte_experimental int rte_dma_get_dev_id_by_name(const char *name)
bool enable_silent
Definition: rte_dmadev.h:348
rte_dma_port_type
Definition: rte_dmadev.h:470
__rte_experimental int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan, const struct rte_dma_vchan_conf *conf)
static __rte_experimental 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:1088
__rte_experimental int rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
__rte_experimental int rte_dma_stop(int16_t dev_id)
uint16_t max_sges
Definition: rte_dmadev.h:305
__rte_experimental int16_t rte_dma_next_dev(int16_t start_dev_id)
static __rte_experimental 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:1026
__rte_experimental int rte_dma_close(int16_t dev_id)
const char * dev_name
Definition: rte_dmadev.h:289
uint64_t errors
Definition: rte_dmadev.h:622
static __rte_experimental 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:855
__rte_experimental int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
int16_t numa_node
Definition: rte_dmadev.h:307
__rte_experimental int rte_dma_start(int16_t dev_id)
rte_dma_status_code
Definition: rte_dmadev.h:729
#define RTE_STD_C11
Definition: rte_common.h:42
uint16_t min_desc
Definition: rte_dmadev.h:297
static __rte_experimental uint16_t rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
Definition: rte_dmadev.h:1125
uint16_t max_vchans
Definition: rte_dmadev.h:293
rte_dma_vchan_status
Definition: rte_dmadev.h:679
uint64_t completed
Definition: rte_dmadev.h:620
uint64_t submitted
Definition: rte_dmadev.h:616
__rte_experimental int rte_dma_dev_max(size_t dev_max)
static __rte_experimental 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:952
uint16_t nb_vchans
Definition: rte_dmadev.h:309
uint32_t length
Definition: rte_dmadev.h:795
__rte_experimental int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
static __rte_experimental int rte_dma_submit(int16_t dev_id, uint16_t vchan)
Definition: rte_dmadev.h:986