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;
16 test_enqueue_copies(int dev_id)
18 const unsigned int length = 1024;
22 struct rte_mbuf *src, *dst;
23 char *src_data, *dst_data;
24 struct rte_mbuf *completed[2] = {0};
26 /* test doing a single copy */
27 src = rte_pktmbuf_alloc(pool);
28 dst = rte_pktmbuf_alloc(pool);
29 src->data_len = src->pkt_len = length;
30 dst->data_len = dst->pkt_len = length;
31 src_data = rte_pktmbuf_mtod(src, char *);
32 dst_data = rte_pktmbuf_mtod(dst, char *);
34 for (i = 0; i < length; i++)
35 src_data[i] = rand() & 0xFF;
37 if (rte_ioat_enqueue_copy(dev_id,
38 src->buf_iova + src->data_off,
39 dst->buf_iova + dst->data_off,
43 0 /* no fence */) != 1) {
44 printf("Error with rte_ioat_enqueue_copy\n");
47 rte_ioat_do_copies(dev_id);
50 if (rte_ioat_completed_copies(dev_id, 1, (void *)&completed[0],
51 (void *)&completed[1]) != 1) {
52 printf("Error with rte_ioat_completed_copies\n");
55 if (completed[0] != src || completed[1] != dst) {
56 printf("Error with completions: got (%p, %p), not (%p,%p)\n",
57 completed[0], completed[1], src, dst);
61 for (i = 0; i < length; i++)
62 if (dst_data[i] != src_data[i]) {
63 printf("Data mismatch at char %u\n", i);
66 rte_pktmbuf_free(src);
67 rte_pktmbuf_free(dst);
70 /* test doing multiple copies */
72 struct rte_mbuf *srcs[32], *dsts[32];
73 struct rte_mbuf *completed_src[64];
74 struct rte_mbuf *completed_dst[64];
77 for (i = 0; i < RTE_DIM(srcs); i++) {
80 srcs[i] = rte_pktmbuf_alloc(pool);
81 dsts[i] = rte_pktmbuf_alloc(pool);
82 srcs[i]->data_len = srcs[i]->pkt_len = length;
83 dsts[i]->data_len = dsts[i]->pkt_len = length;
84 src_data = rte_pktmbuf_mtod(srcs[i], char *);
86 for (j = 0; j < length; j++)
87 src_data[j] = rand() & 0xFF;
89 if (rte_ioat_enqueue_copy(dev_id,
90 srcs[i]->buf_iova + srcs[i]->data_off,
91 dsts[i]->buf_iova + dsts[i]->data_off,
95 0 /* nofence */) != 1) {
96 printf("Error with rte_ioat_enqueue_copy for buffer %u\n",
101 rte_ioat_do_copies(dev_id);
104 if (rte_ioat_completed_copies(dev_id, 64, (void *)completed_src,
105 (void *)completed_dst) != RTE_DIM(srcs)) {
106 printf("Error with rte_ioat_completed_copies\n");
109 for (i = 0; i < RTE_DIM(srcs); i++) {
110 char *src_data, *dst_data;
112 if (completed_src[i] != srcs[i]) {
113 printf("Error with source pointer %u\n", i);
116 if (completed_dst[i] != dsts[i]) {
117 printf("Error with dest pointer %u\n", i);
121 src_data = rte_pktmbuf_mtod(srcs[i], char *);
122 dst_data = rte_pktmbuf_mtod(dsts[i], char *);
123 for (j = 0; j < length; j++)
124 if (src_data[j] != dst_data[j]) {
125 printf("Error with copy of packet %u, byte %u\n",
129 rte_pktmbuf_free(srcs[i]);
130 rte_pktmbuf_free(dsts[i]);
139 ioat_rawdev_test(uint16_t dev_id)
141 #define IOAT_TEST_RINGSIZE 512
142 struct rte_ioat_rawdev_config p = { .ring_size = -1 };
143 struct rte_rawdev_info info = { .dev_private = &p };
144 struct rte_rawdev_xstats_name *snames = NULL;
145 uint64_t *stats = NULL;
146 unsigned int *ids = NULL;
147 unsigned int nb_xstats;
150 rte_rawdev_info_get(dev_id, &info);
151 if (p.ring_size != 0) {
152 printf("Error, initial ring size is non-zero (%d)\n",
157 p.ring_size = IOAT_TEST_RINGSIZE;
158 if (rte_rawdev_configure(dev_id, &info) != 0) {
159 printf("Error with rte_rawdev_configure()\n");
162 rte_rawdev_info_get(dev_id, &info);
163 if (p.ring_size != IOAT_TEST_RINGSIZE) {
164 printf("Error, ring size is not %d (%d)\n",
165 IOAT_TEST_RINGSIZE, (int)p.ring_size);
169 if (rte_rawdev_start(dev_id) != 0) {
170 printf("Error with rte_rawdev_start()\n");
174 pool = rte_pktmbuf_pool_create("TEST_IOAT_POOL",
175 256, /* n == num elements */
178 2048, /* data room size */
181 printf("Error with mempool creation\n");
185 /* allocate memory for xstats names and values */
186 nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
188 snames = malloc(sizeof(*snames) * nb_xstats);
189 if (snames == NULL) {
190 printf("Error allocating xstat names memory\n");
193 rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
195 ids = malloc(sizeof(*ids) * nb_xstats);
197 printf("Error allocating xstat ids memory\n");
200 for (i = 0; i < nb_xstats; i++)
203 stats = malloc(sizeof(*stats) * nb_xstats);
205 printf("Error allocating xstat memory\n");
209 /* run the test cases */
210 for (i = 0; i < 100; i++) {
213 if (test_enqueue_copies(dev_id) != 0)
216 rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
217 for (j = 0; j < nb_xstats; j++)
218 printf("%s: %"PRIu64" ", snames[j].name, stats[j]);
223 rte_rawdev_stop(dev_id);
224 rte_mempool_free(pool);
231 rte_rawdev_stop(dev_id);
232 rte_mempool_free(pool);