1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
8 #include "rte_rawdev.h"
9 #include "rte_ioat_rawdev.h"
11 #define MAX_SUPPORTED_RAWDEVS 64
12 #define TEST_SKIPPED 77
14 int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler happy */
16 static struct rte_mempool *pool;
17 static unsigned short expected_ring_size[MAX_SUPPORTED_RAWDEVS];
19 #define PRINT_ERR(...) print_err(__func__, __LINE__, __VA_ARGS__)
22 __rte_format_printf(3, 4)
23 print_err(const char *func, int lineno, const char *format, ...)
28 ret = fprintf(stderr, "In %s:%d - ", func, lineno);
30 ret += vfprintf(stderr, format, ap);
37 test_enqueue_copies(int dev_id)
39 const unsigned int length = 1024;
43 struct rte_mbuf *src, *dst;
44 char *src_data, *dst_data;
45 struct rte_mbuf *completed[2] = {0};
47 /* test doing a single copy */
48 src = rte_pktmbuf_alloc(pool);
49 dst = rte_pktmbuf_alloc(pool);
50 src->data_len = src->pkt_len = length;
51 dst->data_len = dst->pkt_len = length;
52 src_data = rte_pktmbuf_mtod(src, char *);
53 dst_data = rte_pktmbuf_mtod(dst, char *);
55 for (i = 0; i < length; i++)
56 src_data[i] = rand() & 0xFF;
58 if (rte_ioat_enqueue_copy(dev_id,
59 src->buf_iova + src->data_off,
60 dst->buf_iova + dst->data_off,
64 0 /* no fence */) != 1) {
65 PRINT_ERR("Error with rte_ioat_enqueue_copy\n");
68 rte_ioat_do_copies(dev_id);
71 if (rte_ioat_completed_copies(dev_id, 1, (void *)&completed[0],
72 (void *)&completed[1]) != 1) {
73 PRINT_ERR("Error with rte_ioat_completed_copies\n");
76 if (completed[0] != src || completed[1] != dst) {
77 PRINT_ERR("Error with completions: got (%p, %p), not (%p,%p)\n",
78 completed[0], completed[1], src, dst);
82 for (i = 0; i < length; i++)
83 if (dst_data[i] != src_data[i]) {
84 PRINT_ERR("Data mismatch at char %u\n", i);
87 rte_pktmbuf_free(src);
88 rte_pktmbuf_free(dst);
91 /* test doing multiple copies */
93 struct rte_mbuf *srcs[32], *dsts[32];
94 struct rte_mbuf *completed_src[64];
95 struct rte_mbuf *completed_dst[64];
98 for (i = 0; i < RTE_DIM(srcs); i++) {
101 srcs[i] = rte_pktmbuf_alloc(pool);
102 dsts[i] = rte_pktmbuf_alloc(pool);
103 srcs[i]->data_len = srcs[i]->pkt_len = length;
104 dsts[i]->data_len = dsts[i]->pkt_len = length;
105 src_data = rte_pktmbuf_mtod(srcs[i], char *);
107 for (j = 0; j < length; j++)
108 src_data[j] = rand() & 0xFF;
110 if (rte_ioat_enqueue_copy(dev_id,
111 srcs[i]->buf_iova + srcs[i]->data_off,
112 dsts[i]->buf_iova + dsts[i]->data_off,
116 0 /* nofence */) != 1) {
117 PRINT_ERR("Error with rte_ioat_enqueue_copy for buffer %u\n",
122 rte_ioat_do_copies(dev_id);
125 if (rte_ioat_completed_copies(dev_id, 64, (void *)completed_src,
126 (void *)completed_dst) != RTE_DIM(srcs)) {
127 PRINT_ERR("Error with rte_ioat_completed_copies\n");
130 for (i = 0; i < RTE_DIM(srcs); i++) {
131 char *src_data, *dst_data;
133 if (completed_src[i] != srcs[i]) {
134 PRINT_ERR("Error with source pointer %u\n", i);
137 if (completed_dst[i] != dsts[i]) {
138 PRINT_ERR("Error with dest pointer %u\n", i);
142 src_data = rte_pktmbuf_mtod(srcs[i], char *);
143 dst_data = rte_pktmbuf_mtod(dsts[i], char *);
144 for (j = 0; j < length; j++)
145 if (src_data[j] != dst_data[j]) {
146 PRINT_ERR("Error with copy of packet %u, byte %u\n",
150 rte_pktmbuf_free(srcs[i]);
151 rte_pktmbuf_free(dsts[i]);
160 ioat_rawdev_test(uint16_t dev_id)
162 #define IOAT_TEST_RINGSIZE 512
163 struct rte_ioat_rawdev_config p = { .ring_size = -1 };
164 struct rte_rawdev_info info = { .dev_private = &p };
165 struct rte_rawdev_xstats_name *snames = NULL;
166 uint64_t *stats = NULL;
167 unsigned int *ids = NULL;
168 unsigned int nb_xstats;
171 if (dev_id >= MAX_SUPPORTED_RAWDEVS) {
172 printf("Skipping test. Cannot test rawdevs with id's greater than %d\n",
173 MAX_SUPPORTED_RAWDEVS);
177 rte_rawdev_info_get(dev_id, &info, sizeof(p));
178 if (p.ring_size != expected_ring_size[dev_id]) {
179 PRINT_ERR("Error, initial ring size is not as expected (Actual: %d, Expected: %d)\n",
180 (int)p.ring_size, expected_ring_size[dev_id]);
184 p.ring_size = IOAT_TEST_RINGSIZE;
185 if (rte_rawdev_configure(dev_id, &info, sizeof(p)) != 0) {
186 PRINT_ERR("Error with rte_rawdev_configure()\n");
189 rte_rawdev_info_get(dev_id, &info, sizeof(p));
190 if (p.ring_size != IOAT_TEST_RINGSIZE) {
191 PRINT_ERR("Error, ring size is not %d (%d)\n",
192 IOAT_TEST_RINGSIZE, (int)p.ring_size);
195 expected_ring_size[dev_id] = p.ring_size;
197 if (rte_rawdev_start(dev_id) != 0) {
198 PRINT_ERR("Error with rte_rawdev_start()\n");
202 pool = rte_pktmbuf_pool_create("TEST_IOAT_POOL",
203 256, /* n == num elements */
206 2048, /* data room size */
209 PRINT_ERR("Error with mempool creation\n");
213 /* allocate memory for xstats names and values */
214 nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
216 snames = malloc(sizeof(*snames) * nb_xstats);
217 if (snames == NULL) {
218 PRINT_ERR("Error allocating xstat names memory\n");
221 rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
223 ids = malloc(sizeof(*ids) * nb_xstats);
225 PRINT_ERR("Error allocating xstat ids memory\n");
228 for (i = 0; i < nb_xstats; i++)
231 stats = malloc(sizeof(*stats) * nb_xstats);
233 PRINT_ERR("Error allocating xstat memory\n");
237 /* run the test cases */
238 for (i = 0; i < 100; i++) {
241 if (test_enqueue_copies(dev_id) != 0)
244 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
245 for (j = 0; j < nb_xstats; j++)
246 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
251 rte_rawdev_stop(dev_id);
252 if (rte_rawdev_xstats_reset(dev_id, NULL, 0) != 0) {
253 PRINT_ERR("Error resetting xstat values\n");
257 rte_mempool_free(pool);
264 rte_rawdev_stop(dev_id);
265 rte_rawdev_xstats_reset(dev_id, NULL, 0);
266 rte_mempool_free(pool);