19942ebb9SChengwen Feng /* SPDX-License-Identifier: BSD-3-Clause 29942ebb9SChengwen Feng * Copyright(c) 2021 HiSilicon Limited 39942ebb9SChengwen Feng * Copyright(c) 2021 Intel Corporation 49942ebb9SChengwen Feng */ 59942ebb9SChengwen Feng 6718f7804SBruce Richardson #include <inttypes.h> 7718f7804SBruce Richardson 89942ebb9SChengwen Feng #include <rte_dmadev.h> 98febcbe1SBruce Richardson #include <rte_mbuf.h> 108febcbe1SBruce Richardson #include <rte_pause.h> 118febcbe1SBruce Richardson #include <rte_cycles.h> 128febcbe1SBruce Richardson #include <rte_random.h> 139942ebb9SChengwen Feng #include <rte_bus_vdev.h> 14718f7804SBruce Richardson #include <rte_dmadev_pmd.h> 159942ebb9SChengwen Feng 169942ebb9SChengwen Feng #include "test.h" 179942ebb9SChengwen Feng #include "test_dmadev_api.h" 189942ebb9SChengwen Feng 19718f7804SBruce Richardson #define ERR_RETURN(...) do { print_err(__func__, __LINE__, __VA_ARGS__); return -1; } while (0) 20718f7804SBruce Richardson 218febcbe1SBruce Richardson #define COPY_LEN 1024 228febcbe1SBruce Richardson 238febcbe1SBruce Richardson static struct rte_mempool *pool; 248febcbe1SBruce Richardson static uint16_t id_count; 258febcbe1SBruce Richardson 26718f7804SBruce Richardson static void 27718f7804SBruce Richardson __rte_format_printf(3, 4) 28718f7804SBruce Richardson print_err(const char *func, int lineno, const char *format, ...) 29718f7804SBruce Richardson { 30718f7804SBruce Richardson va_list ap; 31718f7804SBruce Richardson 32718f7804SBruce Richardson fprintf(stderr, "In %s:%d - ", func, lineno); 33718f7804SBruce Richardson va_start(ap, format); 34718f7804SBruce Richardson vfprintf(stderr, format, ap); 35718f7804SBruce Richardson va_end(ap); 36718f7804SBruce Richardson } 37718f7804SBruce Richardson 38718f7804SBruce Richardson static int 398febcbe1SBruce Richardson runtest(const char *printable, int (*test_fn)(int16_t dev_id, uint16_t vchan), int iterations, 408febcbe1SBruce Richardson int16_t dev_id, uint16_t vchan, bool check_err_stats) 418febcbe1SBruce Richardson { 428febcbe1SBruce Richardson struct rte_dma_stats stats; 438febcbe1SBruce Richardson int i; 448febcbe1SBruce Richardson 458febcbe1SBruce Richardson rte_dma_stats_reset(dev_id, vchan); 468febcbe1SBruce Richardson printf("DMA Dev %d: Running %s Tests %s\n", dev_id, printable, 478febcbe1SBruce Richardson check_err_stats ? " " : "(errors expected)"); 488febcbe1SBruce Richardson for (i = 0; i < iterations; i++) { 498febcbe1SBruce Richardson if (test_fn(dev_id, vchan) < 0) 508febcbe1SBruce Richardson return -1; 518febcbe1SBruce Richardson 528febcbe1SBruce Richardson rte_dma_stats_get(dev_id, 0, &stats); 538febcbe1SBruce Richardson printf("Ops submitted: %"PRIu64"\t", stats.submitted); 548febcbe1SBruce Richardson printf("Ops completed: %"PRIu64"\t", stats.completed); 558febcbe1SBruce Richardson printf("Errors: %"PRIu64"\r", stats.errors); 568febcbe1SBruce Richardson 578febcbe1SBruce Richardson if (stats.completed != stats.submitted) 588febcbe1SBruce Richardson ERR_RETURN("\nError, not all submitted jobs are reported as completed\n"); 598febcbe1SBruce Richardson if (check_err_stats && stats.errors != 0) 608febcbe1SBruce Richardson ERR_RETURN("\nErrors reported during op processing, aborting tests\n"); 618febcbe1SBruce Richardson } 628febcbe1SBruce Richardson printf("\n"); 638febcbe1SBruce Richardson return 0; 648febcbe1SBruce Richardson } 658febcbe1SBruce Richardson 668febcbe1SBruce Richardson static void 678febcbe1SBruce Richardson await_hw(int16_t dev_id, uint16_t vchan) 688febcbe1SBruce Richardson { 698febcbe1SBruce Richardson enum rte_dma_vchan_status st; 708febcbe1SBruce Richardson 718febcbe1SBruce Richardson if (rte_dma_vchan_status(dev_id, vchan, &st) < 0) { 728febcbe1SBruce Richardson /* for drivers that don't support this op, just sleep for 1 millisecond */ 738febcbe1SBruce Richardson rte_delay_us_sleep(1000); 748febcbe1SBruce Richardson return; 758febcbe1SBruce Richardson } 768febcbe1SBruce Richardson 778febcbe1SBruce Richardson /* for those that do, *max* end time is one second from now, but all should be faster */ 788febcbe1SBruce Richardson const uint64_t end_cycles = rte_get_timer_cycles() + rte_get_timer_hz(); 798febcbe1SBruce Richardson while (st == RTE_DMA_VCHAN_ACTIVE && rte_get_timer_cycles() < end_cycles) { 808febcbe1SBruce Richardson rte_pause(); 818febcbe1SBruce Richardson rte_dma_vchan_status(dev_id, vchan, &st); 828febcbe1SBruce Richardson } 838febcbe1SBruce Richardson } 848febcbe1SBruce Richardson 85*1b86a66aSBruce Richardson /* run a series of copy tests just using some different options for enqueues and completions */ 86*1b86a66aSBruce Richardson static int 87*1b86a66aSBruce Richardson do_multi_copies(int16_t dev_id, uint16_t vchan, 88*1b86a66aSBruce Richardson int split_batches, /* submit 2 x 16 or 1 x 32 burst */ 89*1b86a66aSBruce Richardson int split_completions, /* gather 2 x 16 or 1 x 32 completions */ 90*1b86a66aSBruce Richardson int use_completed_status) /* use completed or completed_status function */ 91*1b86a66aSBruce Richardson { 92*1b86a66aSBruce Richardson struct rte_mbuf *srcs[32], *dsts[32]; 93*1b86a66aSBruce Richardson enum rte_dma_status_code sc[32]; 94*1b86a66aSBruce Richardson unsigned int i, j; 95*1b86a66aSBruce Richardson bool dma_err = false; 96*1b86a66aSBruce Richardson 97*1b86a66aSBruce Richardson /* Enqueue burst of copies and hit doorbell */ 98*1b86a66aSBruce Richardson for (i = 0; i < RTE_DIM(srcs); i++) { 99*1b86a66aSBruce Richardson uint64_t *src_data; 100*1b86a66aSBruce Richardson 101*1b86a66aSBruce Richardson if (split_batches && i == RTE_DIM(srcs) / 2) 102*1b86a66aSBruce Richardson rte_dma_submit(dev_id, vchan); 103*1b86a66aSBruce Richardson 104*1b86a66aSBruce Richardson srcs[i] = rte_pktmbuf_alloc(pool); 105*1b86a66aSBruce Richardson dsts[i] = rte_pktmbuf_alloc(pool); 106*1b86a66aSBruce Richardson if (srcs[i] == NULL || dsts[i] == NULL) 107*1b86a66aSBruce Richardson ERR_RETURN("Error allocating buffers\n"); 108*1b86a66aSBruce Richardson 109*1b86a66aSBruce Richardson src_data = rte_pktmbuf_mtod(srcs[i], uint64_t *); 110*1b86a66aSBruce Richardson for (j = 0; j < COPY_LEN/sizeof(uint64_t); j++) 111*1b86a66aSBruce Richardson src_data[j] = rte_rand(); 112*1b86a66aSBruce Richardson 113*1b86a66aSBruce Richardson if (rte_dma_copy(dev_id, vchan, srcs[i]->buf_iova + srcs[i]->data_off, 114*1b86a66aSBruce Richardson dsts[i]->buf_iova + dsts[i]->data_off, COPY_LEN, 0) != id_count++) 115*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_copy for buffer %u\n", i); 116*1b86a66aSBruce Richardson } 117*1b86a66aSBruce Richardson rte_dma_submit(dev_id, vchan); 118*1b86a66aSBruce Richardson 119*1b86a66aSBruce Richardson await_hw(dev_id, vchan); 120*1b86a66aSBruce Richardson 121*1b86a66aSBruce Richardson if (split_completions) { 122*1b86a66aSBruce Richardson /* gather completions in two halves */ 123*1b86a66aSBruce Richardson uint16_t half_len = RTE_DIM(srcs) / 2; 124*1b86a66aSBruce Richardson int ret = rte_dma_completed(dev_id, vchan, half_len, NULL, &dma_err); 125*1b86a66aSBruce Richardson if (ret != half_len || dma_err) 126*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_completed - first half. ret = %d, expected ret = %u, dma_err = %d\n", 127*1b86a66aSBruce Richardson ret, half_len, dma_err); 128*1b86a66aSBruce Richardson 129*1b86a66aSBruce Richardson ret = rte_dma_completed(dev_id, vchan, half_len, NULL, &dma_err); 130*1b86a66aSBruce Richardson if (ret != half_len || dma_err) 131*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_completed - second half. ret = %d, expected ret = %u, dma_err = %d\n", 132*1b86a66aSBruce Richardson ret, half_len, dma_err); 133*1b86a66aSBruce Richardson } else { 134*1b86a66aSBruce Richardson /* gather all completions in one go, using either 135*1b86a66aSBruce Richardson * completed or completed_status fns 136*1b86a66aSBruce Richardson */ 137*1b86a66aSBruce Richardson if (!use_completed_status) { 138*1b86a66aSBruce Richardson int n = rte_dma_completed(dev_id, vchan, RTE_DIM(srcs), NULL, &dma_err); 139*1b86a66aSBruce Richardson if (n != RTE_DIM(srcs) || dma_err) 140*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_completed, %u [expected: %zu], dma_err = %d\n", 141*1b86a66aSBruce Richardson n, RTE_DIM(srcs), dma_err); 142*1b86a66aSBruce Richardson } else { 143*1b86a66aSBruce Richardson int n = rte_dma_completed_status(dev_id, vchan, RTE_DIM(srcs), NULL, sc); 144*1b86a66aSBruce Richardson if (n != RTE_DIM(srcs)) 145*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_completed_status, %u [expected: %zu]\n", 146*1b86a66aSBruce Richardson n, RTE_DIM(srcs)); 147*1b86a66aSBruce Richardson 148*1b86a66aSBruce Richardson for (j = 0; j < (uint16_t)n; j++) 149*1b86a66aSBruce Richardson if (sc[j] != RTE_DMA_STATUS_SUCCESSFUL) 150*1b86a66aSBruce Richardson ERR_RETURN("Error with rte_dma_completed_status, job %u reports failure [code %u]\n", 151*1b86a66aSBruce Richardson j, sc[j]); 152*1b86a66aSBruce Richardson } 153*1b86a66aSBruce Richardson } 154*1b86a66aSBruce Richardson 155*1b86a66aSBruce Richardson /* check for empty */ 156*1b86a66aSBruce Richardson int ret = use_completed_status ? 157*1b86a66aSBruce Richardson rte_dma_completed_status(dev_id, vchan, RTE_DIM(srcs), NULL, sc) : 158*1b86a66aSBruce Richardson rte_dma_completed(dev_id, vchan, RTE_DIM(srcs), NULL, &dma_err); 159*1b86a66aSBruce Richardson if (ret != 0) 160*1b86a66aSBruce Richardson ERR_RETURN("Error with completion check - ops unexpectedly returned\n"); 161*1b86a66aSBruce Richardson 162*1b86a66aSBruce Richardson for (i = 0; i < RTE_DIM(srcs); i++) { 163*1b86a66aSBruce Richardson char *src_data, *dst_data; 164*1b86a66aSBruce Richardson 165*1b86a66aSBruce Richardson src_data = rte_pktmbuf_mtod(srcs[i], char *); 166*1b86a66aSBruce Richardson dst_data = rte_pktmbuf_mtod(dsts[i], char *); 167*1b86a66aSBruce Richardson for (j = 0; j < COPY_LEN; j++) 168*1b86a66aSBruce Richardson if (src_data[j] != dst_data[j]) 169*1b86a66aSBruce Richardson ERR_RETURN("Error with copy of packet %u, byte %u\n", i, j); 170*1b86a66aSBruce Richardson 171*1b86a66aSBruce Richardson rte_pktmbuf_free(srcs[i]); 172*1b86a66aSBruce Richardson rte_pktmbuf_free(dsts[i]); 173*1b86a66aSBruce Richardson } 174*1b86a66aSBruce Richardson return 0; 175*1b86a66aSBruce Richardson } 176*1b86a66aSBruce Richardson 1778febcbe1SBruce Richardson static int 1788febcbe1SBruce Richardson test_enqueue_copies(int16_t dev_id, uint16_t vchan) 1798febcbe1SBruce Richardson { 1808febcbe1SBruce Richardson unsigned int i; 1818febcbe1SBruce Richardson uint16_t id; 1828febcbe1SBruce Richardson 1838febcbe1SBruce Richardson /* test doing a single copy */ 1848febcbe1SBruce Richardson do { 1858febcbe1SBruce Richardson struct rte_mbuf *src, *dst; 1868febcbe1SBruce Richardson char *src_data, *dst_data; 1878febcbe1SBruce Richardson 1888febcbe1SBruce Richardson src = rte_pktmbuf_alloc(pool); 1898febcbe1SBruce Richardson dst = rte_pktmbuf_alloc(pool); 1908febcbe1SBruce Richardson src_data = rte_pktmbuf_mtod(src, char *); 1918febcbe1SBruce Richardson dst_data = rte_pktmbuf_mtod(dst, char *); 1928febcbe1SBruce Richardson 1938febcbe1SBruce Richardson for (i = 0; i < COPY_LEN; i++) 1948febcbe1SBruce Richardson src_data[i] = rte_rand() & 0xFF; 1958febcbe1SBruce Richardson 1968febcbe1SBruce Richardson id = rte_dma_copy(dev_id, vchan, rte_pktmbuf_iova(src), rte_pktmbuf_iova(dst), 1978febcbe1SBruce Richardson COPY_LEN, RTE_DMA_OP_FLAG_SUBMIT); 1988febcbe1SBruce Richardson if (id != id_count) 1998febcbe1SBruce Richardson ERR_RETURN("Error with rte_dma_copy, got %u, expected %u\n", 2008febcbe1SBruce Richardson id, id_count); 2018febcbe1SBruce Richardson 2028febcbe1SBruce Richardson /* give time for copy to finish, then check it was done */ 2038febcbe1SBruce Richardson await_hw(dev_id, vchan); 2048febcbe1SBruce Richardson 2058febcbe1SBruce Richardson for (i = 0; i < COPY_LEN; i++) 2068febcbe1SBruce Richardson if (dst_data[i] != src_data[i]) 2078febcbe1SBruce Richardson ERR_RETURN("Data mismatch at char %u [Got %02x not %02x]\n", i, 2088febcbe1SBruce Richardson dst_data[i], src_data[i]); 2098febcbe1SBruce Richardson 2108febcbe1SBruce Richardson /* now check completion works */ 2118febcbe1SBruce Richardson if (rte_dma_completed(dev_id, vchan, 1, &id, NULL) != 1) 2128febcbe1SBruce Richardson ERR_RETURN("Error with rte_dma_completed\n"); 2138febcbe1SBruce Richardson 2148febcbe1SBruce Richardson if (id != id_count) 2158febcbe1SBruce Richardson ERR_RETURN("Error:incorrect job id received, %u [expected %u]\n", 2168febcbe1SBruce Richardson id, id_count); 2178febcbe1SBruce Richardson 2188febcbe1SBruce Richardson rte_pktmbuf_free(src); 2198febcbe1SBruce Richardson rte_pktmbuf_free(dst); 2208febcbe1SBruce Richardson 2218febcbe1SBruce Richardson /* now check completion returns nothing more */ 2228febcbe1SBruce Richardson if (rte_dma_completed(dev_id, 0, 1, NULL, NULL) != 0) 2238febcbe1SBruce Richardson ERR_RETURN("Error with rte_dma_completed in empty check\n"); 2248febcbe1SBruce Richardson 2258febcbe1SBruce Richardson id_count++; 2268febcbe1SBruce Richardson 2278febcbe1SBruce Richardson } while (0); 2288febcbe1SBruce Richardson 2298febcbe1SBruce Richardson /* test doing a multiple single copies */ 2308febcbe1SBruce Richardson do { 2318febcbe1SBruce Richardson const uint16_t max_ops = 4; 2328febcbe1SBruce Richardson struct rte_mbuf *src, *dst; 2338febcbe1SBruce Richardson char *src_data, *dst_data; 2348febcbe1SBruce Richardson uint16_t count; 2358febcbe1SBruce Richardson 2368febcbe1SBruce Richardson src = rte_pktmbuf_alloc(pool); 2378febcbe1SBruce Richardson dst = rte_pktmbuf_alloc(pool); 2388febcbe1SBruce Richardson src_data = rte_pktmbuf_mtod(src, char *); 2398febcbe1SBruce Richardson dst_data = rte_pktmbuf_mtod(dst, char *); 2408febcbe1SBruce Richardson 2418febcbe1SBruce Richardson for (i = 0; i < COPY_LEN; i++) 2428febcbe1SBruce Richardson src_data[i] = rte_rand() & 0xFF; 2438febcbe1SBruce Richardson 2448febcbe1SBruce Richardson /* perform the same copy <max_ops> times */ 2458febcbe1SBruce Richardson for (i = 0; i < max_ops; i++) 2468febcbe1SBruce Richardson if (rte_dma_copy(dev_id, vchan, 2478febcbe1SBruce Richardson rte_pktmbuf_iova(src), 2488febcbe1SBruce Richardson rte_pktmbuf_iova(dst), 2498febcbe1SBruce Richardson COPY_LEN, RTE_DMA_OP_FLAG_SUBMIT) != id_count++) 2508febcbe1SBruce Richardson ERR_RETURN("Error with rte_dma_copy\n"); 2518febcbe1SBruce Richardson 2528febcbe1SBruce Richardson await_hw(dev_id, vchan); 2538febcbe1SBruce Richardson 2548febcbe1SBruce Richardson count = rte_dma_completed(dev_id, vchan, max_ops * 2, &id, NULL); 2558febcbe1SBruce Richardson if (count != max_ops) 2568febcbe1SBruce Richardson ERR_RETURN("Error with rte_dma_completed, got %u not %u\n", 2578febcbe1SBruce Richardson count, max_ops); 2588febcbe1SBruce Richardson 2598febcbe1SBruce Richardson if (id != id_count - 1) 2608febcbe1SBruce Richardson ERR_RETURN("Error, incorrect job id returned: got %u not %u\n", 2618febcbe1SBruce Richardson id, id_count - 1); 2628febcbe1SBruce Richardson 2638febcbe1SBruce Richardson for (i = 0; i < COPY_LEN; i++) 2648febcbe1SBruce Richardson if (dst_data[i] != src_data[i]) 2658febcbe1SBruce Richardson ERR_RETURN("Data mismatch at char %u\n", i); 2668febcbe1SBruce Richardson 2678febcbe1SBruce Richardson rte_pktmbuf_free(src); 2688febcbe1SBruce Richardson rte_pktmbuf_free(dst); 2698febcbe1SBruce Richardson } while (0); 2708febcbe1SBruce Richardson 271*1b86a66aSBruce Richardson /* test doing multiple copies */ 272*1b86a66aSBruce Richardson return do_multi_copies(dev_id, vchan, 0, 0, 0) /* enqueue and complete 1 batch at a time */ 273*1b86a66aSBruce Richardson /* enqueue 2 batches and then complete both */ 274*1b86a66aSBruce Richardson || do_multi_copies(dev_id, vchan, 1, 0, 0) 275*1b86a66aSBruce Richardson /* enqueue 1 batch, then complete in two halves */ 276*1b86a66aSBruce Richardson || do_multi_copies(dev_id, vchan, 0, 1, 0) 277*1b86a66aSBruce Richardson /* test using completed_status in place of regular completed API */ 278*1b86a66aSBruce Richardson || do_multi_copies(dev_id, vchan, 0, 0, 1); 2798febcbe1SBruce Richardson } 2808febcbe1SBruce Richardson 2818febcbe1SBruce Richardson static int 282718f7804SBruce Richardson test_dmadev_instance(int16_t dev_id) 283718f7804SBruce Richardson { 284718f7804SBruce Richardson #define TEST_RINGSIZE 512 2858febcbe1SBruce Richardson #define CHECK_ERRS true 286718f7804SBruce Richardson struct rte_dma_stats stats; 287718f7804SBruce Richardson struct rte_dma_info info; 288718f7804SBruce Richardson const struct rte_dma_conf conf = { .nb_vchans = 1}; 289718f7804SBruce Richardson const struct rte_dma_vchan_conf qconf = { 290718f7804SBruce Richardson .direction = RTE_DMA_DIR_MEM_TO_MEM, 291718f7804SBruce Richardson .nb_desc = TEST_RINGSIZE, 292718f7804SBruce Richardson }; 293718f7804SBruce Richardson const int vchan = 0; 294718f7804SBruce Richardson 295718f7804SBruce Richardson printf("\n### Test dmadev instance %u [%s]\n", 296718f7804SBruce Richardson dev_id, rte_dma_devices[dev_id].data->dev_name); 297718f7804SBruce Richardson 298718f7804SBruce Richardson rte_dma_info_get(dev_id, &info); 299718f7804SBruce Richardson if (info.max_vchans < 1) 300718f7804SBruce Richardson ERR_RETURN("Error, no channels available on device id %u\n", dev_id); 301718f7804SBruce Richardson 302718f7804SBruce Richardson if (rte_dma_configure(dev_id, &conf) != 0) 303718f7804SBruce Richardson ERR_RETURN("Error with rte_dma_configure()\n"); 304718f7804SBruce Richardson 305718f7804SBruce Richardson if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0) 306718f7804SBruce Richardson ERR_RETURN("Error with queue configuration\n"); 307718f7804SBruce Richardson 308718f7804SBruce Richardson rte_dma_info_get(dev_id, &info); 309718f7804SBruce Richardson if (info.nb_vchans != 1) 310718f7804SBruce Richardson ERR_RETURN("Error, no configured queues reported on device id %u\n", dev_id); 311718f7804SBruce Richardson 312718f7804SBruce Richardson if (rte_dma_start(dev_id) != 0) 313718f7804SBruce Richardson ERR_RETURN("Error with rte_dma_start()\n"); 314718f7804SBruce Richardson 315718f7804SBruce Richardson if (rte_dma_stats_get(dev_id, vchan, &stats) != 0) 316718f7804SBruce Richardson ERR_RETURN("Error with rte_dma_stats_get()\n"); 317718f7804SBruce Richardson 318718f7804SBruce Richardson if (stats.completed != 0 || stats.submitted != 0 || stats.errors != 0) 319718f7804SBruce Richardson ERR_RETURN("Error device stats are not all zero: completed = %"PRIu64", " 320718f7804SBruce Richardson "submitted = %"PRIu64", errors = %"PRIu64"\n", 321718f7804SBruce Richardson stats.completed, stats.submitted, stats.errors); 3228febcbe1SBruce Richardson id_count = 0; 323718f7804SBruce Richardson 3248febcbe1SBruce Richardson /* create a mempool for running tests */ 3258febcbe1SBruce Richardson pool = rte_pktmbuf_pool_create("TEST_DMADEV_POOL", 3268febcbe1SBruce Richardson TEST_RINGSIZE * 2, /* n == num elements */ 3278febcbe1SBruce Richardson 32, /* cache size */ 3288febcbe1SBruce Richardson 0, /* priv size */ 3298febcbe1SBruce Richardson 2048, /* data room size */ 3308febcbe1SBruce Richardson info.numa_node); 3318febcbe1SBruce Richardson if (pool == NULL) 3328febcbe1SBruce Richardson ERR_RETURN("Error with mempool creation\n"); 3338febcbe1SBruce Richardson 3348febcbe1SBruce Richardson /* run the test cases, use many iterations to ensure UINT16_MAX id wraparound */ 3358febcbe1SBruce Richardson if (runtest("copy", test_enqueue_copies, 640, dev_id, vchan, CHECK_ERRS) < 0) 3368febcbe1SBruce Richardson goto err; 3378febcbe1SBruce Richardson 3388febcbe1SBruce Richardson rte_mempool_free(pool); 339718f7804SBruce Richardson rte_dma_stop(dev_id); 340718f7804SBruce Richardson rte_dma_stats_reset(dev_id, vchan); 341718f7804SBruce Richardson return 0; 3428febcbe1SBruce Richardson 3438febcbe1SBruce Richardson err: 3448febcbe1SBruce Richardson rte_mempool_free(pool); 3458febcbe1SBruce Richardson rte_dma_stop(dev_id); 3468febcbe1SBruce Richardson return -1; 347718f7804SBruce Richardson } 348718f7804SBruce Richardson 3499942ebb9SChengwen Feng static int 3509942ebb9SChengwen Feng test_apis(void) 3519942ebb9SChengwen Feng { 3529942ebb9SChengwen Feng const char *pmd = "dma_skeleton"; 3539942ebb9SChengwen Feng int id; 3549942ebb9SChengwen Feng int ret; 3559942ebb9SChengwen Feng 3567f699229SBruce Richardson /* attempt to create skeleton instance - ignore errors due to one being already present */ 3577f699229SBruce Richardson rte_vdev_init(pmd, NULL); 3589942ebb9SChengwen Feng id = rte_dma_get_dev_id_by_name(pmd); 3599942ebb9SChengwen Feng if (id < 0) 3609942ebb9SChengwen Feng return TEST_SKIPPED; 3619942ebb9SChengwen Feng printf("\n### Test dmadev infrastructure using skeleton driver\n"); 3629942ebb9SChengwen Feng ret = test_dma_api(id); 3639942ebb9SChengwen Feng 3649942ebb9SChengwen Feng return ret; 3659942ebb9SChengwen Feng } 3669942ebb9SChengwen Feng 3679942ebb9SChengwen Feng static int 3689942ebb9SChengwen Feng test_dma(void) 3699942ebb9SChengwen Feng { 370718f7804SBruce Richardson int i; 371718f7804SBruce Richardson 3729942ebb9SChengwen Feng /* basic sanity on dmadev infrastructure */ 3739942ebb9SChengwen Feng if (test_apis() < 0) 374718f7804SBruce Richardson ERR_RETURN("Error performing API tests\n"); 375718f7804SBruce Richardson 376718f7804SBruce Richardson if (rte_dma_count_avail() == 0) 377718f7804SBruce Richardson return TEST_SKIPPED; 378718f7804SBruce Richardson 379718f7804SBruce Richardson RTE_DMA_FOREACH_DEV(i) 380718f7804SBruce Richardson if (test_dmadev_instance(i) < 0) 381718f7804SBruce Richardson ERR_RETURN("Error, test failure for device %d\n", i); 3829942ebb9SChengwen Feng 3839942ebb9SChengwen Feng return 0; 3849942ebb9SChengwen Feng } 3859942ebb9SChengwen Feng 3869942ebb9SChengwen Feng REGISTER_TEST_COMMAND(dmadev_autotest, test_dma); 387