1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 HiSilicon Limited
3 * Copyright(c) 2021 Intel Corporation
8 #include <rte_dmadev.h>
9 #include <rte_bus_vdev.h>
10 #include <rte_dmadev_pmd.h>
13 #include "test_dmadev_api.h"
15 #define ERR_RETURN(...) do { print_err(__func__, __LINE__, __VA_ARGS__); return -1; } while (0)
18 __rte_format_printf(3, 4)
19 print_err(const char *func, int lineno, const char *format, ...)
23 fprintf(stderr, "In %s:%d - ", func, lineno);
25 vfprintf(stderr, format, ap);
30 test_dmadev_instance(int16_t dev_id)
32 #define TEST_RINGSIZE 512
33 struct rte_dma_stats stats;
34 struct rte_dma_info info;
35 const struct rte_dma_conf conf = { .nb_vchans = 1};
36 const struct rte_dma_vchan_conf qconf = {
37 .direction = RTE_DMA_DIR_MEM_TO_MEM,
38 .nb_desc = TEST_RINGSIZE,
42 printf("\n### Test dmadev instance %u [%s]\n",
43 dev_id, rte_dma_devices[dev_id].data->dev_name);
45 rte_dma_info_get(dev_id, &info);
46 if (info.max_vchans < 1)
47 ERR_RETURN("Error, no channels available on device id %u\n", dev_id);
49 if (rte_dma_configure(dev_id, &conf) != 0)
50 ERR_RETURN("Error with rte_dma_configure()\n");
52 if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0)
53 ERR_RETURN("Error with queue configuration\n");
55 rte_dma_info_get(dev_id, &info);
56 if (info.nb_vchans != 1)
57 ERR_RETURN("Error, no configured queues reported on device id %u\n", dev_id);
59 if (rte_dma_start(dev_id) != 0)
60 ERR_RETURN("Error with rte_dma_start()\n");
62 if (rte_dma_stats_get(dev_id, vchan, &stats) != 0)
63 ERR_RETURN("Error with rte_dma_stats_get()\n");
65 if (stats.completed != 0 || stats.submitted != 0 || stats.errors != 0)
66 ERR_RETURN("Error device stats are not all zero: completed = %"PRIu64", "
67 "submitted = %"PRIu64", errors = %"PRIu64"\n",
68 stats.completed, stats.submitted, stats.errors);
71 rte_dma_stats_reset(dev_id, vchan);
78 const char *pmd = "dma_skeleton";
82 if (rte_vdev_init(pmd, NULL) < 0)
84 id = rte_dma_get_dev_id_by_name(pmd);
87 printf("\n### Test dmadev infrastructure using skeleton driver\n");
88 ret = test_dma_api(id);
99 /* basic sanity on dmadev infrastructure */
101 ERR_RETURN("Error performing API tests\n");
103 if (rte_dma_count_avail() == 0)
106 RTE_DMA_FOREACH_DEV(i)
107 if (test_dmadev_instance(i) < 0)
108 ERR_RETURN("Error, test failure for device %d\n", i);
113 REGISTER_TEST_COMMAND(dmadev_autotest, test_dma);