1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 HiSilicon Limited
3 * Copyright(c) 2021 Intel Corporation
11 #include <rte_malloc.h>
12 #include <rte_memzone.h>
13 #include <rte_string_fns.h>
14 #include <rte_telemetry.h>
16 #include "rte_dmadev.h"
17 #include "rte_dmadev_pmd.h"
19 static int16_t dma_devices_max;
21 struct rte_dma_fp_object *rte_dma_fp_objs;
22 static struct rte_dma_dev *rte_dma_devices;
24 /* Hold the dev_max information of the primary process. This field is
25 * set by the primary process and is read by the secondary process.
28 struct rte_dma_dev_data data[0];
29 } *dma_devices_shared_data;
31 RTE_LOG_REGISTER_DEFAULT(rte_dma_logtype, INFO);
32 #define RTE_DMA_LOG(level, ...) \
33 rte_log(RTE_LOG_ ## level, rte_dma_logtype, RTE_FMT("dma: " \
34 RTE_FMT_HEAD(__VA_ARGS__,) "\n", RTE_FMT_TAIL(__VA_ARGS__,)))
37 rte_dma_dev_max(size_t dev_max)
39 /* This function may be called before rte_eal_init(), so no rte library
40 * function can be called in this function.
42 if (dev_max == 0 || dev_max > INT16_MAX)
45 if (dma_devices_max > 0)
48 dma_devices_max = dev_max;
54 rte_dma_next_dev(int16_t start_dev_id)
56 int16_t dev_id = start_dev_id;
57 while (dev_id < dma_devices_max && rte_dma_devices[dev_id].state == RTE_DMA_DEV_UNUSED)
60 if (dev_id < dma_devices_max)
67 dma_check_name(const char *name)
72 RTE_DMA_LOG(ERR, "Name can't be NULL");
76 name_len = strnlen(name, RTE_DEV_NAME_MAX_LEN);
78 RTE_DMA_LOG(ERR, "Zero length DMA device name");
81 if (name_len >= RTE_DEV_NAME_MAX_LEN) {
82 RTE_DMA_LOG(ERR, "DMA device name is too long");
90 dma_find_free_id(void)
94 if (rte_dma_devices == NULL || dma_devices_shared_data == NULL)
97 for (i = 0; i < dma_devices_max; i++) {
98 if (dma_devices_shared_data->data[i].dev_name[0] == '\0')
105 static struct rte_dma_dev*
106 dma_find_by_name(const char *name)
110 if (rte_dma_devices == NULL)
113 for (i = 0; i < dma_devices_max; i++) {
114 if ((rte_dma_devices[i].state != RTE_DMA_DEV_UNUSED) &&
115 (!strcmp(name, rte_dma_devices[i].data->dev_name)))
116 return &rte_dma_devices[i];
122 static void dma_fp_object_dummy(struct rte_dma_fp_object *obj);
125 dma_fp_data_prepare(void)
131 if (rte_dma_fp_objs != NULL)
134 /* Fast-path object must align cacheline, but the return value of malloc
135 * may not be aligned to the cache line. Therefore, extra memory is
136 * applied for realignment.
137 * note: We do not call posix_memalign/aligned_alloc because it is
138 * version dependent on libc.
140 size = dma_devices_max * sizeof(struct rte_dma_fp_object) +
145 memset(ptr, 0, size);
147 rte_dma_fp_objs = RTE_PTR_ALIGN(ptr, RTE_CACHE_LINE_SIZE);
148 for (i = 0; i < dma_devices_max; i++)
149 dma_fp_object_dummy(&rte_dma_fp_objs[i]);
155 dma_dev_data_prepare(void)
159 if (rte_dma_devices != NULL)
162 size = dma_devices_max * sizeof(struct rte_dma_dev);
163 rte_dma_devices = malloc(size);
164 if (rte_dma_devices == NULL)
166 memset(rte_dma_devices, 0, size);
172 dma_shared_data_prepare(void)
174 const char *mz_name = "rte_dma_dev_data";
175 const struct rte_memzone *mz;
178 if (dma_devices_shared_data != NULL)
181 size = sizeof(*dma_devices_shared_data) +
182 sizeof(struct rte_dma_dev_data) * dma_devices_max;
184 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
185 mz = rte_memzone_reserve(mz_name, size, rte_socket_id(), 0);
187 mz = rte_memzone_lookup(mz_name);
191 dma_devices_shared_data = mz->addr;
192 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
193 memset(dma_devices_shared_data, 0, size);
194 dma_devices_shared_data->dev_max = dma_devices_max;
196 dma_devices_max = dma_devices_shared_data->dev_max;
203 dma_data_prepare(void)
207 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
208 if (dma_devices_max == 0)
209 dma_devices_max = RTE_DMADEV_DEFAULT_MAX;
210 ret = dma_fp_data_prepare();
213 ret = dma_dev_data_prepare();
216 ret = dma_shared_data_prepare();
220 ret = dma_shared_data_prepare();
223 ret = dma_fp_data_prepare();
226 ret = dma_dev_data_prepare();
234 static struct rte_dma_dev *
235 dma_allocate_primary(const char *name, int numa_node, size_t private_data_size)
237 struct rte_dma_dev *dev;
242 ret = dma_data_prepare();
244 RTE_DMA_LOG(ERR, "Cannot initialize dmadevs data");
248 dev = dma_find_by_name(name);
250 RTE_DMA_LOG(ERR, "DMA device already allocated");
254 dev_private = rte_zmalloc_socket(name, private_data_size,
255 RTE_CACHE_LINE_SIZE, numa_node);
256 if (dev_private == NULL) {
257 RTE_DMA_LOG(ERR, "Cannot allocate private data");
261 dev_id = dma_find_free_id();
263 RTE_DMA_LOG(ERR, "Reached maximum number of DMA devices");
264 rte_free(dev_private);
268 dev = &rte_dma_devices[dev_id];
269 dev->data = &dma_devices_shared_data->data[dev_id];
270 rte_strscpy(dev->data->dev_name, name, sizeof(dev->data->dev_name));
271 dev->data->dev_id = dev_id;
272 dev->data->numa_node = numa_node;
273 dev->data->dev_private = dev_private;
278 static struct rte_dma_dev *
279 dma_attach_secondary(const char *name)
281 struct rte_dma_dev *dev;
285 ret = dma_data_prepare();
287 RTE_DMA_LOG(ERR, "Cannot initialize dmadevs data");
291 for (i = 0; i < dma_devices_max; i++) {
292 if (!strcmp(dma_devices_shared_data->data[i].dev_name, name))
295 if (i == dma_devices_max) {
297 "Device %s is not driven by the primary process",
302 dev = &rte_dma_devices[i];
303 dev->data = &dma_devices_shared_data->data[i];
308 static struct rte_dma_dev *
309 dma_allocate(const char *name, int numa_node, size_t private_data_size)
311 struct rte_dma_dev *dev;
313 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
314 dev = dma_allocate_primary(name, numa_node, private_data_size);
316 dev = dma_attach_secondary(name);
319 dev->fp_obj = &rte_dma_fp_objs[dev->data->dev_id];
320 dma_fp_object_dummy(dev->fp_obj);
327 dma_release(struct rte_dma_dev *dev)
329 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
330 rte_free(dev->data->dev_private);
331 memset(dev->data, 0, sizeof(struct rte_dma_dev_data));
334 dma_fp_object_dummy(dev->fp_obj);
335 memset(dev, 0, sizeof(struct rte_dma_dev));
339 rte_dma_pmd_allocate(const char *name, int numa_node, size_t private_data_size)
341 struct rte_dma_dev *dev;
343 if (dma_check_name(name) != 0 || private_data_size == 0)
346 dev = dma_allocate(name, numa_node, private_data_size);
350 dev->state = RTE_DMA_DEV_REGISTERED;
356 rte_dma_pmd_release(const char *name)
358 struct rte_dma_dev *dev;
360 if (dma_check_name(name) != 0)
363 dev = dma_find_by_name(name);
367 if (dev->state == RTE_DMA_DEV_READY)
368 return rte_dma_close(dev->data->dev_id);
375 rte_dma_get_dev_id_by_name(const char *name)
377 struct rte_dma_dev *dev;
379 if (dma_check_name(name) != 0)
382 dev = dma_find_by_name(name);
386 return dev->data->dev_id;
390 rte_dma_is_valid(int16_t dev_id)
392 return (dev_id >= 0) && (dev_id < dma_devices_max) &&
393 rte_dma_devices != NULL &&
394 rte_dma_devices[dev_id].state != RTE_DMA_DEV_UNUSED;
398 rte_dma_count_avail(void)
403 if (rte_dma_devices == NULL)
406 for (i = 0; i < dma_devices_max; i++) {
407 if (rte_dma_devices[i].state != RTE_DMA_DEV_UNUSED)
415 rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
417 const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
420 if (!rte_dma_is_valid(dev_id) || dev_info == NULL)
423 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_info_get, -ENOTSUP);
424 memset(dev_info, 0, sizeof(struct rte_dma_info));
425 ret = (*dev->dev_ops->dev_info_get)(dev, dev_info,
426 sizeof(struct rte_dma_info));
430 dev_info->dev_name = dev->data->dev_name;
431 dev_info->numa_node = dev->device->numa_node;
432 dev_info->nb_vchans = dev->data->dev_conf.nb_vchans;
438 rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
440 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
441 struct rte_dma_info dev_info;
444 if (!rte_dma_is_valid(dev_id) || dev_conf == NULL)
447 if (dev->data->dev_started != 0) {
449 "Device %d must be stopped to allow configuration",
454 ret = rte_dma_info_get(dev_id, &dev_info);
456 RTE_DMA_LOG(ERR, "Device %d get device info fail", dev_id);
459 if (dev_conf->nb_vchans == 0) {
461 "Device %d configure zero vchans", dev_id);
464 if (dev_conf->nb_vchans > dev_info.max_vchans) {
466 "Device %d configure too many vchans", dev_id);
469 if (dev_conf->enable_silent &&
470 !(dev_info.dev_capa & RTE_DMA_CAPA_SILENT)) {
471 RTE_DMA_LOG(ERR, "Device %d don't support silent", dev_id);
475 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
476 ret = (*dev->dev_ops->dev_configure)(dev, dev_conf,
477 sizeof(struct rte_dma_conf));
479 memcpy(&dev->data->dev_conf, dev_conf,
480 sizeof(struct rte_dma_conf));
486 rte_dma_start(int16_t dev_id)
488 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
491 if (!rte_dma_is_valid(dev_id))
494 if (dev->data->dev_conf.nb_vchans == 0) {
495 RTE_DMA_LOG(ERR, "Device %d must be configured first", dev_id);
499 if (dev->data->dev_started != 0) {
500 RTE_DMA_LOG(WARNING, "Device %d already started", dev_id);
504 if (dev->dev_ops->dev_start == NULL)
507 ret = (*dev->dev_ops->dev_start)(dev);
512 dev->data->dev_started = 1;
517 rte_dma_stop(int16_t dev_id)
519 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
522 if (!rte_dma_is_valid(dev_id))
525 if (dev->data->dev_started == 0) {
526 RTE_DMA_LOG(WARNING, "Device %d already stopped", dev_id);
530 if (dev->dev_ops->dev_stop == NULL)
533 ret = (*dev->dev_ops->dev_stop)(dev);
538 dev->data->dev_started = 0;
543 rte_dma_close(int16_t dev_id)
545 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
548 if (!rte_dma_is_valid(dev_id))
551 /* Device must be stopped before it can be closed */
552 if (dev->data->dev_started == 1) {
554 "Device %d must be stopped before closing", dev_id);
558 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
559 ret = (*dev->dev_ops->dev_close)(dev);
567 rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
568 const struct rte_dma_vchan_conf *conf)
570 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
571 struct rte_dma_info dev_info;
572 bool src_is_dev, dst_is_dev;
575 if (!rte_dma_is_valid(dev_id) || conf == NULL)
578 if (dev->data->dev_started != 0) {
580 "Device %d must be stopped to allow configuration",
585 ret = rte_dma_info_get(dev_id, &dev_info);
587 RTE_DMA_LOG(ERR, "Device %d get device info fail", dev_id);
590 if (dev->data->dev_conf.nb_vchans == 0) {
591 RTE_DMA_LOG(ERR, "Device %d must be configured first", dev_id);
594 if (vchan >= dev_info.nb_vchans) {
595 RTE_DMA_LOG(ERR, "Device %d vchan out range!", dev_id);
598 if (conf->direction != RTE_DMA_DIR_MEM_TO_MEM &&
599 conf->direction != RTE_DMA_DIR_MEM_TO_DEV &&
600 conf->direction != RTE_DMA_DIR_DEV_TO_MEM &&
601 conf->direction != RTE_DMA_DIR_DEV_TO_DEV) {
602 RTE_DMA_LOG(ERR, "Device %d direction invalid!", dev_id);
605 if (conf->direction == RTE_DMA_DIR_MEM_TO_MEM &&
606 !(dev_info.dev_capa & RTE_DMA_CAPA_MEM_TO_MEM)) {
608 "Device %d don't support mem2mem transfer", dev_id);
611 if (conf->direction == RTE_DMA_DIR_MEM_TO_DEV &&
612 !(dev_info.dev_capa & RTE_DMA_CAPA_MEM_TO_DEV)) {
614 "Device %d don't support mem2dev transfer", dev_id);
617 if (conf->direction == RTE_DMA_DIR_DEV_TO_MEM &&
618 !(dev_info.dev_capa & RTE_DMA_CAPA_DEV_TO_MEM)) {
620 "Device %d don't support dev2mem transfer", dev_id);
623 if (conf->direction == RTE_DMA_DIR_DEV_TO_DEV &&
624 !(dev_info.dev_capa & RTE_DMA_CAPA_DEV_TO_DEV)) {
626 "Device %d don't support dev2dev transfer", dev_id);
629 if (conf->nb_desc < dev_info.min_desc ||
630 conf->nb_desc > dev_info.max_desc) {
632 "Device %d number of descriptors invalid", dev_id);
635 src_is_dev = conf->direction == RTE_DMA_DIR_DEV_TO_MEM ||
636 conf->direction == RTE_DMA_DIR_DEV_TO_DEV;
637 if ((conf->src_port.port_type == RTE_DMA_PORT_NONE && src_is_dev) ||
638 (conf->src_port.port_type != RTE_DMA_PORT_NONE && !src_is_dev)) {
639 RTE_DMA_LOG(ERR, "Device %d source port type invalid", dev_id);
642 dst_is_dev = conf->direction == RTE_DMA_DIR_MEM_TO_DEV ||
643 conf->direction == RTE_DMA_DIR_DEV_TO_DEV;
644 if ((conf->dst_port.port_type == RTE_DMA_PORT_NONE && dst_is_dev) ||
645 (conf->dst_port.port_type != RTE_DMA_PORT_NONE && !dst_is_dev)) {
647 "Device %d destination port type invalid", dev_id);
651 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vchan_setup, -ENOTSUP);
652 return (*dev->dev_ops->vchan_setup)(dev, vchan, conf,
653 sizeof(struct rte_dma_vchan_conf));
657 rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
659 const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
661 if (!rte_dma_is_valid(dev_id) || stats == NULL)
664 if (vchan >= dev->data->dev_conf.nb_vchans &&
665 vchan != RTE_DMA_ALL_VCHAN) {
667 "Device %d vchan %u out of range", dev_id, vchan);
671 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
672 memset(stats, 0, sizeof(struct rte_dma_stats));
673 return (*dev->dev_ops->stats_get)(dev, vchan, stats,
674 sizeof(struct rte_dma_stats));
678 rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
680 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
682 if (!rte_dma_is_valid(dev_id))
685 if (vchan >= dev->data->dev_conf.nb_vchans &&
686 vchan != RTE_DMA_ALL_VCHAN) {
688 "Device %d vchan %u out of range", dev_id, vchan);
692 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP);
693 return (*dev->dev_ops->stats_reset)(dev, vchan);
697 rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status)
699 struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
701 if (!rte_dma_is_valid(dev_id))
704 if (vchan >= dev->data->dev_conf.nb_vchans) {
705 RTE_DMA_LOG(ERR, "Device %u vchan %u out of range\n", dev_id, vchan);
709 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vchan_status, -ENOTSUP);
710 return (*dev->dev_ops->vchan_status)(dev, vchan, status);
714 dma_capability_name(uint64_t capability)
716 static const struct {
720 { RTE_DMA_CAPA_MEM_TO_MEM, "mem2mem" },
721 { RTE_DMA_CAPA_MEM_TO_DEV, "mem2dev" },
722 { RTE_DMA_CAPA_DEV_TO_MEM, "dev2mem" },
723 { RTE_DMA_CAPA_DEV_TO_DEV, "dev2dev" },
724 { RTE_DMA_CAPA_SVA, "sva" },
725 { RTE_DMA_CAPA_SILENT, "silent" },
726 { RTE_DMA_CAPA_HANDLES_ERRORS, "handles_errors" },
727 { RTE_DMA_CAPA_OPS_COPY, "copy" },
728 { RTE_DMA_CAPA_OPS_COPY_SG, "copy_sg" },
729 { RTE_DMA_CAPA_OPS_FILL, "fill" },
732 const char *name = "unknown";
735 for (i = 0; i < RTE_DIM(capa_names); i++) {
736 if (capability == capa_names[i].capability) {
737 name = capa_names[i].name;
746 dma_dump_capability(FILE *f, uint64_t dev_capa)
750 (void)fprintf(f, " dev_capa: 0x%" PRIx64 " -", dev_capa);
751 while (dev_capa > 0) {
752 capa = 1ull << __builtin_ctzll(dev_capa);
753 (void)fprintf(f, " %s", dma_capability_name(capa));
756 (void)fprintf(f, "\n");
760 rte_dma_dump(int16_t dev_id, FILE *f)
762 const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
763 struct rte_dma_info dev_info;
766 if (!rte_dma_is_valid(dev_id) || f == NULL)
769 ret = rte_dma_info_get(dev_id, &dev_info);
771 RTE_DMA_LOG(ERR, "Device %d get device info fail", dev_id);
775 (void)fprintf(f, "DMA Dev %d, '%s' [%s]\n",
778 dev->data->dev_started ? "started" : "stopped");
779 dma_dump_capability(f, dev_info.dev_capa);
780 (void)fprintf(f, " max_vchans_supported: %u\n", dev_info.max_vchans);
781 (void)fprintf(f, " nb_vchans_configured: %u\n", dev_info.nb_vchans);
782 (void)fprintf(f, " silent_mode: %s\n",
783 dev->data->dev_conf.enable_silent ? "on" : "off");
785 if (dev->dev_ops->dev_dump != NULL)
786 return (*dev->dev_ops->dev_dump)(dev, f);
792 dummy_copy(__rte_unused void *dev_private, __rte_unused uint16_t vchan,
793 __rte_unused rte_iova_t src, __rte_unused rte_iova_t dst,
794 __rte_unused uint32_t length, __rte_unused uint64_t flags)
796 RTE_DMA_LOG(ERR, "copy is not configured or not supported.");
801 dummy_copy_sg(__rte_unused void *dev_private, __rte_unused uint16_t vchan,
802 __rte_unused const struct rte_dma_sge *src,
803 __rte_unused const struct rte_dma_sge *dst,
804 __rte_unused uint16_t nb_src, __rte_unused uint16_t nb_dst,
805 __rte_unused uint64_t flags)
807 RTE_DMA_LOG(ERR, "copy_sg is not configured or not supported.");
812 dummy_fill(__rte_unused void *dev_private, __rte_unused uint16_t vchan,
813 __rte_unused uint64_t pattern, __rte_unused rte_iova_t dst,
814 __rte_unused uint32_t length, __rte_unused uint64_t flags)
816 RTE_DMA_LOG(ERR, "fill is not configured or not supported.");
821 dummy_submit(__rte_unused void *dev_private, __rte_unused uint16_t vchan)
823 RTE_DMA_LOG(ERR, "submit is not configured or not supported.");
828 dummy_completed(__rte_unused void *dev_private, __rte_unused uint16_t vchan,
829 __rte_unused const uint16_t nb_cpls,
830 __rte_unused uint16_t *last_idx, __rte_unused bool *has_error)
832 RTE_DMA_LOG(ERR, "completed is not configured or not supported.");
837 dummy_completed_status(__rte_unused void *dev_private,
838 __rte_unused uint16_t vchan,
839 __rte_unused const uint16_t nb_cpls,
840 __rte_unused uint16_t *last_idx,
841 __rte_unused enum rte_dma_status_code *status)
844 "completed_status is not configured or not supported.");
849 dummy_burst_capacity(__rte_unused const void *dev_private,
850 __rte_unused uint16_t vchan)
852 RTE_DMA_LOG(ERR, "burst_capacity is not configured or not supported.");
857 dma_fp_object_dummy(struct rte_dma_fp_object *obj)
859 obj->dev_private = NULL;
860 obj->copy = dummy_copy;
861 obj->copy_sg = dummy_copy_sg;
862 obj->fill = dummy_fill;
863 obj->submit = dummy_submit;
864 obj->completed = dummy_completed;
865 obj->completed_status = dummy_completed_status;
866 obj->burst_capacity = dummy_burst_capacity;
870 dmadev_handle_dev_list(const char *cmd __rte_unused,
871 const char *params __rte_unused,
872 struct rte_tel_data *d)
876 rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
877 for (dev_id = 0; dev_id < dma_devices_max; dev_id++)
878 if (rte_dma_is_valid(dev_id))
879 rte_tel_data_add_array_int(d, dev_id);
884 #define ADD_CAPA(td, dc, c) rte_tel_data_add_dict_int(td, dma_capability_name(c), !!(dc & c))
887 dmadev_handle_dev_info(const char *cmd __rte_unused,
888 const char *params, struct rte_tel_data *d)
890 struct rte_dma_info dma_info;
891 struct rte_tel_data *dma_caps;
896 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
899 dev_id = strtoul(params, &end_param, 0);
900 if (*end_param != '\0')
901 RTE_DMA_LOG(WARNING, "Extra parameters passed to dmadev telemetry command, ignoring");
903 /* Function info_get validates dev_id so we don't need to. */
904 ret = rte_dma_info_get(dev_id, &dma_info);
907 dev_capa = dma_info.dev_capa;
909 rte_tel_data_start_dict(d);
910 rte_tel_data_add_dict_string(d, "name", dma_info.dev_name);
911 rte_tel_data_add_dict_int(d, "nb_vchans", dma_info.nb_vchans);
912 rte_tel_data_add_dict_int(d, "numa_node", dma_info.numa_node);
913 rte_tel_data_add_dict_int(d, "max_vchans", dma_info.max_vchans);
914 rte_tel_data_add_dict_int(d, "max_desc", dma_info.max_desc);
915 rte_tel_data_add_dict_int(d, "min_desc", dma_info.min_desc);
916 rte_tel_data_add_dict_int(d, "max_sges", dma_info.max_sges);
918 dma_caps = rte_tel_data_alloc();
922 rte_tel_data_start_dict(dma_caps);
923 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_MEM_TO_MEM);
924 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_MEM_TO_DEV);
925 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_DEV_TO_MEM);
926 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_DEV_TO_DEV);
927 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_SVA);
928 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_SILENT);
929 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_HANDLES_ERRORS);
930 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_OPS_COPY);
931 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_OPS_COPY_SG);
932 ADD_CAPA(dma_caps, dev_capa, RTE_DMA_CAPA_OPS_FILL);
933 rte_tel_data_add_dict_container(d, "capabilities", dma_caps, 0);
938 #define ADD_DICT_STAT(s) rte_tel_data_add_dict_u64(d, #s, dma_stats.s)
941 dmadev_handle_dev_stats(const char *cmd __rte_unused,
943 struct rte_tel_data *d)
945 struct rte_dma_info dma_info;
946 struct rte_dma_stats dma_stats;
947 int dev_id, ret, vchan_id;
949 const char *vchan_param;
951 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
954 dev_id = strtoul(params, &end_param, 0);
956 /* Function info_get validates dev_id so we don't need to. */
957 ret = rte_dma_info_get(dev_id, &dma_info);
961 /* If the device has one vchan the user does not need to supply the
962 * vchan id and only the device id is needed, no extra parameters.
964 if (dma_info.nb_vchans == 1 && *end_param == '\0')
967 vchan_param = strtok(end_param, ",");
968 if (!vchan_param || strlen(vchan_param) == 0 || !isdigit(*vchan_param))
971 vchan_id = strtoul(vchan_param, &end_param, 0);
973 if (*end_param != '\0')
974 RTE_DMA_LOG(WARNING, "Extra parameters passed to dmadev telemetry command, ignoring");
976 ret = rte_dma_stats_get(dev_id, vchan_id, &dma_stats);
980 rte_tel_data_start_dict(d);
981 ADD_DICT_STAT(submitted);
982 ADD_DICT_STAT(completed);
983 ADD_DICT_STAT(errors);
988 RTE_INIT(dmadev_init_telemetry)
990 rte_telemetry_register_cmd("/dmadev/list", dmadev_handle_dev_list,
991 "Returns list of available dmadev devices by IDs. No parameters.");
992 rte_telemetry_register_cmd("/dmadev/info", dmadev_handle_dev_info,
993 "Returns information for a dmadev. Parameters: int dev_id");
994 rte_telemetry_register_cmd("/dmadev/stats", dmadev_handle_dev_stats,
995 "Returns the stats for a dmadev vchannel. Parameters: int dev_id, vchan_id (Optional if only one vchannel)");