DPDK  22.11.0-rc0
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  if (*obj->copy == NULL)
864  return -ENOTSUP;
865 #endif
866 
867  return (*obj->copy)(obj->dev_private, vchan, src, dst, length, flags);
868 }
869 
903 __rte_experimental
904 static inline int
905 rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src,
906  struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst,
907  uint64_t flags)
908 {
909  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
910 
911 #ifdef RTE_DMADEV_DEBUG
912  if (!rte_dma_is_valid(dev_id) || src == NULL || dst == NULL ||
913  nb_src == 0 || nb_dst == 0)
914  return -EINVAL;
915  if (*obj->copy_sg == NULL)
916  return -ENOTSUP;
917 #endif
918 
919  return (*obj->copy_sg)(obj->dev_private, vchan, src, dst, nb_src,
920  nb_dst, flags);
921 }
922 
952 __rte_experimental
953 static inline int
954 rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern,
955  rte_iova_t dst, uint32_t length, uint64_t flags)
956 {
957  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
958 
959 #ifdef RTE_DMADEV_DEBUG
960  if (!rte_dma_is_valid(dev_id) || length == 0)
961  return -EINVAL;
962  if (*obj->fill == NULL)
963  return -ENOTSUP;
964 #endif
965 
966  return (*obj->fill)(obj->dev_private, vchan, pattern, dst, length,
967  flags);
968 }
969 
987 __rte_experimental
988 static inline int
989 rte_dma_submit(int16_t dev_id, uint16_t vchan)
990 {
991  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
992 
993 #ifdef RTE_DMADEV_DEBUG
994  if (!rte_dma_is_valid(dev_id))
995  return -EINVAL;
996  if (*obj->submit == NULL)
997  return -ENOTSUP;
998 #endif
999 
1000  return (*obj->submit)(obj->dev_private, vchan);
1001 }
1002 
1028 __rte_experimental
1029 static inline uint16_t
1030 rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls,
1031  uint16_t *last_idx, bool *has_error)
1032 {
1033  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1034  uint16_t idx;
1035  bool err;
1036 
1037 #ifdef RTE_DMADEV_DEBUG
1038  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0)
1039  return 0;
1040  if (*obj->completed == NULL)
1041  return 0;
1042 #endif
1043 
1044  /* Ensure the pointer values are non-null to simplify drivers.
1045  * In most cases these should be compile time evaluated, since this is
1046  * an inline function.
1047  * - If NULL is explicitly passed as parameter, then compiler knows the
1048  * value is NULL
1049  * - If address of local variable is passed as parameter, then compiler
1050  * can know it's non-NULL.
1051  */
1052  if (last_idx == NULL)
1053  last_idx = &idx;
1054  if (has_error == NULL)
1055  has_error = &err;
1056 
1057  *has_error = false;
1058  return (*obj->completed)(obj->dev_private, vchan, nb_cpls, last_idx,
1059  has_error);
1060 }
1061 
1091 __rte_experimental
1092 static inline uint16_t
1093 rte_dma_completed_status(int16_t dev_id, uint16_t vchan,
1094  const uint16_t nb_cpls, uint16_t *last_idx,
1095  enum rte_dma_status_code *status)
1096 {
1097  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1098  uint16_t idx;
1099 
1100 #ifdef RTE_DMADEV_DEBUG
1101  if (!rte_dma_is_valid(dev_id) || nb_cpls == 0 || status == NULL)
1102  return 0;
1103  if (*obj->completed_status == NULL)
1104  return 0;
1105 #endif
1106 
1107  if (last_idx == NULL)
1108  last_idx = &idx;
1109 
1110  return (*obj->completed_status)(obj->dev_private, vchan, nb_cpls,
1111  last_idx, status);
1112 }
1113 
1129 __rte_experimental
1130 static inline uint16_t
1131 rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
1132 {
1133  struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
1134 
1135 #ifdef RTE_DMADEV_DEBUG
1136  if (!rte_dma_is_valid(dev_id))
1137  return 0;
1138  if (*obj->burst_capacity == NULL)
1139  return 0;
1140 #endif
1141  return (*obj->burst_capacity)(obj->dev_private, vchan);
1142 }
1143 
1144 #ifdef __cplusplus
1145 }
1146 #endif
1147 
1148 #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:458
__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:905
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:1093
__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:1030
__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:39
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:1131
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:954
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:989