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 int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler happy */
13 static struct rte_mempool *pool;
14 static unsigned short expected_ring_size;
17 test_enqueue_copies(int dev_id)
19 const unsigned int length = 1024;
23 struct rte_mbuf *src, *dst;
24 char *src_data, *dst_data;
25 struct rte_mbuf *completed[2] = {0};
27 /* test doing a single copy */
28 src = rte_pktmbuf_alloc(pool);
29 dst = rte_pktmbuf_alloc(pool);
30 src->data_len = src->pkt_len = length;
31 dst->data_len = dst->pkt_len = length;
32 src_data = rte_pktmbuf_mtod(src, char *);
33 dst_data = rte_pktmbuf_mtod(dst, char *);
35 for (i = 0; i < length; i++)
36 src_data[i] = rand() & 0xFF;
38 if (rte_ioat_enqueue_copy(dev_id,
39 src->buf_iova + src->data_off,
40 dst->buf_iova + dst->data_off,
44 0 /* no fence */) != 1) {
45 printf("Error with rte_ioat_enqueue_copy\n");
48 rte_ioat_do_copies(dev_id);
51 if (rte_ioat_completed_copies(dev_id, 1, (void *)&completed[0],
52 (void *)&completed[1]) != 1) {
53 printf("Error with rte_ioat_completed_copies\n");
56 if (completed[0] != src || completed[1] != dst) {
57 printf("Error with completions: got (%p, %p), not (%p,%p)\n",
58 completed[0], completed[1], src, dst);
62 for (i = 0; i < length; i++)
63 if (dst_data[i] != src_data[i]) {
64 printf("Data mismatch at char %u\n", i);
67 rte_pktmbuf_free(src);
68 rte_pktmbuf_free(dst);
71 /* test doing multiple copies */
73 struct rte_mbuf *srcs[32], *dsts[32];
74 struct rte_mbuf *completed_src[64];
75 struct rte_mbuf *completed_dst[64];
78 for (i = 0; i < RTE_DIM(srcs); i++) {
81 srcs[i] = rte_pktmbuf_alloc(pool);
82 dsts[i] = rte_pktmbuf_alloc(pool);
83 srcs[i]->data_len = srcs[i]->pkt_len = length;
84 dsts[i]->data_len = dsts[i]->pkt_len = length;
85 src_data = rte_pktmbuf_mtod(srcs[i], char *);
87 for (j = 0; j < length; j++)
88 src_data[j] = rand() & 0xFF;
90 if (rte_ioat_enqueue_copy(dev_id,
91 srcs[i]->buf_iova + srcs[i]->data_off,
92 dsts[i]->buf_iova + dsts[i]->data_off,
96 0 /* nofence */) != 1) {
97 printf("Error with rte_ioat_enqueue_copy for buffer %u\n",
102 rte_ioat_do_copies(dev_id);
105 if (rte_ioat_completed_copies(dev_id, 64, (void *)completed_src,
106 (void *)completed_dst) != RTE_DIM(srcs)) {
107 printf("Error with rte_ioat_completed_copies\n");
110 for (i = 0; i < RTE_DIM(srcs); i++) {
111 char *src_data, *dst_data;
113 if (completed_src[i] != srcs[i]) {
114 printf("Error with source pointer %u\n", i);
117 if (completed_dst[i] != dsts[i]) {
118 printf("Error with dest pointer %u\n", i);
122 src_data = rte_pktmbuf_mtod(srcs[i], char *);
123 dst_data = rte_pktmbuf_mtod(dsts[i], char *);
124 for (j = 0; j < length; j++)
125 if (src_data[j] != dst_data[j]) {
126 printf("Error with copy of packet %u, byte %u\n",
130 rte_pktmbuf_free(srcs[i]);
131 rte_pktmbuf_free(dsts[i]);
140 ioat_rawdev_test(uint16_t dev_id)
142 #define IOAT_TEST_RINGSIZE 512
143 struct rte_ioat_rawdev_config p = { .ring_size = -1 };
144 struct rte_rawdev_info info = { .dev_private = &p };
145 struct rte_rawdev_xstats_name *snames = NULL;
146 uint64_t *stats = NULL;
147 unsigned int *ids = NULL;
148 unsigned int nb_xstats;
151 rte_rawdev_info_get(dev_id, &info);
152 if (p.ring_size != expected_ring_size) {
153 printf("Error, initial ring size is not as expected (Actual: %d, Expected: %d)\n",
154 (int)p.ring_size, expected_ring_size);
158 p.ring_size = IOAT_TEST_RINGSIZE;
159 if (rte_rawdev_configure(dev_id, &info) != 0) {
160 printf("Error with rte_rawdev_configure()\n");
163 rte_rawdev_info_get(dev_id, &info);
164 if (p.ring_size != IOAT_TEST_RINGSIZE) {
165 printf("Error, ring size is not %d (%d)\n",
166 IOAT_TEST_RINGSIZE, (int)p.ring_size);
169 expected_ring_size = p.ring_size;
171 if (rte_rawdev_start(dev_id) != 0) {
172 printf("Error with rte_rawdev_start()\n");
176 pool = rte_pktmbuf_pool_create("TEST_IOAT_POOL",
177 256, /* n == num elements */
180 2048, /* data room size */
183 printf("Error with mempool creation\n");
187 /* allocate memory for xstats names and values */
188 nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
190 snames = malloc(sizeof(*snames) * nb_xstats);
191 if (snames == NULL) {
192 printf("Error allocating xstat names memory\n");
195 rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
197 ids = malloc(sizeof(*ids) * nb_xstats);
199 printf("Error allocating xstat ids memory\n");
202 for (i = 0; i < nb_xstats; i++)
205 stats = malloc(sizeof(*stats) * nb_xstats);
207 printf("Error allocating xstat memory\n");
211 /* run the test cases */
212 for (i = 0; i < 100; i++) {
215 if (test_enqueue_copies(dev_id) != 0)
218 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
219 for (j = 0; j < nb_xstats; j++)
220 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
225 rte_rawdev_stop(dev_id);
226 rte_mempool_free(pool);
233 rte_rawdev_stop(dev_id);
234 rte_mempool_free(pool);