1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
8 #include "rte_rawdev.h"
9 #include "rte_ioat_rawdev.h"
10 #include "ioat_private.h"
12 #define MAX_SUPPORTED_RAWDEVS 64
13 #define TEST_SKIPPED 77
15 int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler happy */
17 static struct rte_mempool *pool;
18 static unsigned short expected_ring_size[MAX_SUPPORTED_RAWDEVS];
20 #define PRINT_ERR(...) print_err(__func__, __LINE__, __VA_ARGS__)
23 __rte_format_printf(3, 4)
24 print_err(const char *func, int lineno, const char *format, ...)
29 ret = fprintf(stderr, "In %s:%d - ", func, lineno);
31 ret += vfprintf(stderr, format, ap);
38 test_enqueue_copies(int dev_id)
40 const unsigned int length = 1024;
44 struct rte_mbuf *src, *dst;
45 char *src_data, *dst_data;
46 struct rte_mbuf *completed[2] = {0};
48 /* test doing a single copy */
49 src = rte_pktmbuf_alloc(pool);
50 dst = rte_pktmbuf_alloc(pool);
51 src->data_len = src->pkt_len = length;
52 dst->data_len = dst->pkt_len = length;
53 src_data = rte_pktmbuf_mtod(src, char *);
54 dst_data = rte_pktmbuf_mtod(dst, char *);
56 for (i = 0; i < length; i++)
57 src_data[i] = rand() & 0xFF;
59 if (rte_ioat_enqueue_copy(dev_id,
60 src->buf_iova + src->data_off,
61 dst->buf_iova + dst->data_off,
64 (uintptr_t)dst) != 1) {
65 PRINT_ERR("Error with rte_ioat_enqueue_copy\n");
68 rte_ioat_perform_ops(dev_id);
71 if (rte_ioat_completed_ops(dev_id, 1, (void *)&completed[0],
72 (void *)&completed[1]) != 1) {
73 PRINT_ERR("Error with rte_ioat_completed_ops\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,
115 (uintptr_t)dsts[i]) != 1) {
116 PRINT_ERR("Error with rte_ioat_enqueue_copy for buffer %u\n",
121 rte_ioat_perform_ops(dev_id);
124 if (rte_ioat_completed_ops(dev_id, 64, (void *)completed_src,
125 (void *)completed_dst) != RTE_DIM(srcs)) {
126 PRINT_ERR("Error with rte_ioat_completed_ops\n");
129 for (i = 0; i < RTE_DIM(srcs); i++) {
130 char *src_data, *dst_data;
132 if (completed_src[i] != srcs[i]) {
133 PRINT_ERR("Error with source pointer %u\n", i);
136 if (completed_dst[i] != dsts[i]) {
137 PRINT_ERR("Error with dest pointer %u\n", i);
141 src_data = rte_pktmbuf_mtod(srcs[i], char *);
142 dst_data = rte_pktmbuf_mtod(dsts[i], char *);
143 for (j = 0; j < length; j++)
144 if (src_data[j] != dst_data[j]) {
145 PRINT_ERR("Error with copy of packet %u, byte %u\n",
149 rte_pktmbuf_free(srcs[i]);
150 rte_pktmbuf_free(dsts[i]);
159 ioat_rawdev_test(uint16_t dev_id)
161 #define IOAT_TEST_RINGSIZE 512
162 struct rte_ioat_rawdev_config p = { .ring_size = -1 };
163 struct rte_rawdev_info info = { .dev_private = &p };
164 struct rte_rawdev_xstats_name *snames = NULL;
165 uint64_t *stats = NULL;
166 unsigned int *ids = NULL;
167 unsigned int nb_xstats;
170 if (dev_id >= MAX_SUPPORTED_RAWDEVS) {
171 printf("Skipping test. Cannot test rawdevs with id's greater than %d\n",
172 MAX_SUPPORTED_RAWDEVS);
176 rte_rawdev_info_get(dev_id, &info, sizeof(p));
177 if (p.ring_size != expected_ring_size[dev_id]) {
178 PRINT_ERR("Error, initial ring size is not as expected (Actual: %d, Expected: %d)\n",
179 (int)p.ring_size, expected_ring_size[dev_id]);
183 p.ring_size = IOAT_TEST_RINGSIZE;
184 if (rte_rawdev_configure(dev_id, &info, sizeof(p)) != 0) {
185 PRINT_ERR("Error with rte_rawdev_configure()\n");
188 rte_rawdev_info_get(dev_id, &info, sizeof(p));
189 if (p.ring_size != IOAT_TEST_RINGSIZE) {
190 PRINT_ERR("Error, ring size is not %d (%d)\n",
191 IOAT_TEST_RINGSIZE, (int)p.ring_size);
194 expected_ring_size[dev_id] = p.ring_size;
196 if (rte_rawdev_start(dev_id) != 0) {
197 PRINT_ERR("Error with rte_rawdev_start()\n");
201 pool = rte_pktmbuf_pool_create("TEST_IOAT_POOL",
202 256, /* n == num elements */
205 2048, /* data room size */
208 PRINT_ERR("Error with mempool creation\n");
212 /* allocate memory for xstats names and values */
213 nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
215 snames = malloc(sizeof(*snames) * nb_xstats);
216 if (snames == NULL) {
217 PRINT_ERR("Error allocating xstat names memory\n");
220 rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
222 ids = malloc(sizeof(*ids) * nb_xstats);
224 PRINT_ERR("Error allocating xstat ids memory\n");
227 for (i = 0; i < nb_xstats; i++)
230 stats = malloc(sizeof(*stats) * nb_xstats);
232 PRINT_ERR("Error allocating xstat memory\n");
236 /* run the test cases */
237 for (i = 0; i < 100; i++) {
240 if (test_enqueue_copies(dev_id) != 0)
243 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
244 for (j = 0; j < nb_xstats; j++)
245 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
250 rte_rawdev_stop(dev_id);
251 if (rte_rawdev_xstats_reset(dev_id, NULL, 0) != 0) {
252 PRINT_ERR("Error resetting xstat values\n");
256 rte_mempool_free(pool);
263 rte_rawdev_stop(dev_id);
264 rte_rawdev_xstats_reset(dev_id, NULL, 0);
265 rte_mempool_free(pool);