net: add rte prefix to ether structures
[dpdk.git] / app / test / test_event_eth_tx_adapter.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <string.h>
6
7 #include <rte_bus_vdev.h>
8 #include <rte_common.h>
9 #include <rte_ethdev.h>
10 #include <rte_eth_ring.h>
11 #include <rte_eventdev.h>
12 #include <rte_event_eth_tx_adapter.h>
13 #include <rte_mbuf.h>
14 #include <rte_mempool.h>
15 #include <rte_service.h>
16
17 #include "test.h"
18
19 #define MAX_NUM_QUEUE           RTE_PMD_RING_MAX_RX_RINGS
20 #define TEST_INST_ID            0
21 #define TEST_DEV_ID             0
22 #define SOCKET0                 0
23 #define RING_SIZE               256
24 #define ETH_NAME_LEN            32
25 #define NUM_ETH_PAIR            1
26 #define NUM_ETH_DEV             (2 * NUM_ETH_PAIR)
27 #define NB_MBUF                 512
28 #define PAIR_PORT_INDEX(p)      ((p) + NUM_ETH_PAIR)
29 #define PORT(p)                 default_params.port[(p)]
30 #define TEST_ETHDEV_ID          PORT(0)
31 #define TEST_ETHDEV_PAIR_ID     PORT(PAIR_PORT_INDEX(0))
32
33 #define EDEV_RETRY              0xffff
34
35 struct event_eth_tx_adapter_test_params {
36         struct rte_mempool *mp;
37         uint16_t rx_rings, tx_rings;
38         struct rte_ring *r[NUM_ETH_DEV][MAX_NUM_QUEUE];
39         int port[NUM_ETH_DEV];
40 };
41
42 static int event_dev_delete;
43 static struct event_eth_tx_adapter_test_params default_params;
44 static uint64_t eid = ~0ULL;
45 static uint32_t tid;
46
47 static inline int
48 port_init_common(uint8_t port, const struct rte_eth_conf *port_conf,
49                 struct rte_mempool *mp)
50 {
51         const uint16_t rx_ring_size = RING_SIZE, tx_ring_size = RING_SIZE;
52         int retval;
53         uint16_t q;
54
55         if (!rte_eth_dev_is_valid_port(port))
56                 return -1;
57
58         default_params.rx_rings = MAX_NUM_QUEUE;
59         default_params.tx_rings = MAX_NUM_QUEUE;
60
61         /* Configure the Ethernet device. */
62         retval = rte_eth_dev_configure(port, default_params.rx_rings,
63                                 default_params.tx_rings, port_conf);
64         if (retval != 0)
65                 return retval;
66
67         for (q = 0; q < default_params.rx_rings; q++) {
68                 retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
69                                 rte_eth_dev_socket_id(port), NULL, mp);
70                 if (retval < 0)
71                         return retval;
72         }
73
74         for (q = 0; q < default_params.tx_rings; q++) {
75                 retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
76                                 rte_eth_dev_socket_id(port), NULL);
77                 if (retval < 0)
78                         return retval;
79         }
80
81         /* Start the Ethernet port. */
82         retval = rte_eth_dev_start(port);
83         if (retval < 0)
84                 return retval;
85
86         /* Display the port MAC address. */
87         struct rte_ether_addr addr;
88         rte_eth_macaddr_get(port, &addr);
89         printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
90                            " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
91                         (unsigned int)port,
92                         addr.addr_bytes[0], addr.addr_bytes[1],
93                         addr.addr_bytes[2], addr.addr_bytes[3],
94                         addr.addr_bytes[4], addr.addr_bytes[5]);
95
96         /* Enable RX in promiscuous mode for the Ethernet device. */
97         rte_eth_promiscuous_enable(port);
98
99         return 0;
100 }
101
102 static inline int
103 port_init(uint8_t port, struct rte_mempool *mp)
104 {
105         struct rte_eth_conf conf = { 0 };
106         return port_init_common(port, &conf, mp);
107 }
108
109 #define RING_NAME_LEN   20
110 #define DEV_NAME_LEN    20
111
112 static int
113 init_ports(void)
114 {
115         char ring_name[ETH_NAME_LEN];
116         unsigned int i, j;
117         struct rte_ring * const *c1;
118         struct rte_ring * const *c2;
119         int err;
120
121         if (!default_params.mp)
122                 default_params.mp = rte_pktmbuf_pool_create("mbuf_pool",
123                         NB_MBUF, 32,
124                         0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
125
126         if (!default_params.mp)
127                 return -ENOMEM;
128
129         for (i = 0; i < NUM_ETH_DEV; i++) {
130                 for (j = 0; j < MAX_NUM_QUEUE; j++) {
131                         snprintf(ring_name, sizeof(ring_name), "R%u%u", i, j);
132                         default_params.r[i][j] = rte_ring_create(ring_name,
133                                                 RING_SIZE,
134                                                 SOCKET0,
135                                                 RING_F_SP_ENQ | RING_F_SC_DEQ);
136                         TEST_ASSERT((default_params.r[i][j] != NULL),
137                                 "Failed to allocate ring");
138                 }
139         }
140
141         /*
142          * To create two pseudo-Ethernet ports where the traffic is
143          * switched between them, that is, traffic sent to port 1 is
144          * read back from port 2 and vice-versa
145          */
146         for (i = 0; i < NUM_ETH_PAIR; i++) {
147                 char dev_name[DEV_NAME_LEN];
148                 int p;
149
150                 c1 = default_params.r[i];
151                 c2 = default_params.r[PAIR_PORT_INDEX(i)];
152
153                 snprintf(dev_name, DEV_NAME_LEN, "%u-%u", i, i + NUM_ETH_PAIR);
154                 p = rte_eth_from_rings(dev_name, c1, MAX_NUM_QUEUE,
155                                  c2, MAX_NUM_QUEUE, SOCKET0);
156                 TEST_ASSERT(p >= 0, "Port creation failed %s", dev_name);
157                 err = port_init(p, default_params.mp);
158                 TEST_ASSERT(err == 0, "Port init failed %s", dev_name);
159                 default_params.port[i] = p;
160
161                 snprintf(dev_name, DEV_NAME_LEN, "%u-%u",  i + NUM_ETH_PAIR, i);
162                 p = rte_eth_from_rings(dev_name, c2, MAX_NUM_QUEUE,
163                                 c1, MAX_NUM_QUEUE, SOCKET0);
164                 TEST_ASSERT(p > 0, "Port creation failed %s", dev_name);
165                 err = port_init(p, default_params.mp);
166                 TEST_ASSERT(err == 0, "Port init failed %s", dev_name);
167                 default_params.port[PAIR_PORT_INDEX(i)] = p;
168         }
169
170         return 0;
171 }
172
173 static void
174 deinit_ports(void)
175 {
176         uint16_t i, j;
177         char name[ETH_NAME_LEN];
178
179         for (i = 0; i < RTE_DIM(default_params.port); i++) {
180                 rte_eth_dev_stop(default_params.port[i]);
181                 rte_eth_dev_get_name_by_port(default_params.port[i], name);
182                 rte_vdev_uninit(name);
183                 for (j = 0; j < RTE_DIM(default_params.r[i]); j++)
184                         rte_ring_free(default_params.r[i][j]);
185         }
186 }
187
188 static int
189 testsuite_setup(void)
190 {
191         const char *vdev_name = "event_sw0";
192
193         int err = init_ports();
194         TEST_ASSERT(err == 0, "Port initialization failed err %d\n", err);
195
196         if (rte_event_dev_count() == 0) {
197                 printf("Failed to find a valid event device,"
198                         " testing with event_sw0 device\n");
199                 err = rte_vdev_init(vdev_name, NULL);
200                 TEST_ASSERT(err == 0, "vdev %s creation failed  %d\n",
201                         vdev_name, err);
202                 event_dev_delete = 1;
203         }
204         return err;
205 }
206
207 #define DEVICE_ID_SIZE 64
208
209 static void
210 testsuite_teardown(void)
211 {
212         deinit_ports();
213         rte_mempool_free(default_params.mp);
214         default_params.mp = NULL;
215         if (event_dev_delete)
216                 rte_vdev_uninit("event_sw0");
217 }
218
219 static int
220 tx_adapter_create(void)
221 {
222         int err;
223         struct rte_event_dev_info dev_info;
224         struct rte_event_port_conf tx_p_conf;
225         uint8_t priority;
226         uint8_t queue_id;
227
228         struct rte_event_dev_config config = {
229                         .nb_event_queues = 1,
230                         .nb_event_ports = 1,
231         };
232
233         struct rte_event_queue_conf wkr_q_conf = {
234                         .schedule_type = RTE_SCHED_TYPE_ORDERED,
235                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
236                         .nb_atomic_flows = 1024,
237                         .nb_atomic_order_sequences = 1024,
238         };
239
240         memset(&tx_p_conf, 0, sizeof(tx_p_conf));
241         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
242         config.nb_event_queue_flows = dev_info.max_event_queue_flows;
243         config.nb_event_port_dequeue_depth =
244                         dev_info.max_event_port_dequeue_depth;
245         config.nb_event_port_enqueue_depth =
246                         dev_info.max_event_port_enqueue_depth;
247         config.nb_events_limit =
248                         dev_info.max_num_events;
249
250         err = rte_event_dev_configure(TEST_DEV_ID, &config);
251         TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
252                         err);
253
254         queue_id = 0;
255         err = rte_event_queue_setup(TEST_DEV_ID, 0, &wkr_q_conf);
256         TEST_ASSERT(err == 0, "Event queue setup failed %d\n", err);
257
258         err = rte_event_port_setup(TEST_DEV_ID, 0, NULL);
259         TEST_ASSERT(err == 0, "Event port setup failed %d\n", err);
260
261         priority = RTE_EVENT_DEV_PRIORITY_LOWEST;
262         err = rte_event_port_link(TEST_DEV_ID, 0, &queue_id, &priority, 1);
263         TEST_ASSERT(err == 1, "Error linking port %s\n",
264                 rte_strerror(rte_errno));
265         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
266         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
267
268         tx_p_conf.new_event_threshold = dev_info.max_num_events;
269         tx_p_conf.dequeue_depth = dev_info.max_event_port_dequeue_depth;
270         tx_p_conf.enqueue_depth = dev_info.max_event_port_enqueue_depth;
271         err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
272                                         &tx_p_conf);
273         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
274
275         return err;
276 }
277
278 static void
279 tx_adapter_free(void)
280 {
281         rte_event_eth_tx_adapter_free(TEST_INST_ID);
282 }
283
284 static int
285 tx_adapter_create_free(void)
286 {
287         int err;
288         struct rte_event_dev_info dev_info;
289         struct rte_event_port_conf tx_p_conf;
290
291         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
292         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
293
294         tx_p_conf.new_event_threshold = dev_info.max_num_events;
295         tx_p_conf.dequeue_depth = dev_info.max_event_port_dequeue_depth;
296         tx_p_conf.enqueue_depth = dev_info.max_event_port_enqueue_depth;
297
298         err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
299                                         NULL);
300         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
301
302         err = rte_event_eth_tx_adapter_create(TEST_INST_ID, TEST_DEV_ID,
303                                         &tx_p_conf);
304         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
305
306         err = rte_event_eth_tx_adapter_create(TEST_INST_ID,
307                                         TEST_DEV_ID, &tx_p_conf);
308         TEST_ASSERT(err == -EEXIST, "Expected -EEXIST %d got %d", -EEXIST, err);
309
310         err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
311         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
312
313         err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
314         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);
315
316         err = rte_event_eth_tx_adapter_free(1);
317         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL %d got %d", -EINVAL, err);
318
319         return TEST_SUCCESS;
320 }
321
322 static int
323 tx_adapter_queue_add_del(void)
324 {
325         int err;
326         uint32_t cap;
327
328         err = rte_event_eth_tx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
329                                          &cap);
330         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
331
332
333         err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
334                                                 rte_eth_dev_count_total(),
335                                                 -1);
336         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
337
338         err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
339                                                 TEST_ETHDEV_ID,
340                                                 0);
341         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
342
343         err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
344                                                 TEST_ETHDEV_ID,
345                                                 -1);
346         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
347
348         err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
349                                                 TEST_ETHDEV_ID,
350                                                 0);
351         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
352
353         err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
354                                                 TEST_ETHDEV_ID,
355                                                 -1);
356         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
357
358         err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
359                                                 TEST_ETHDEV_ID,
360                                                 -1);
361         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
362
363         err = rte_event_eth_tx_adapter_queue_add(1, TEST_ETHDEV_ID, -1);
364         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
365
366         err = rte_event_eth_tx_adapter_queue_del(1, TEST_ETHDEV_ID, -1);
367         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
368
369         return TEST_SUCCESS;
370 }
371
372 static int
373 tx_adapter_start_stop(void)
374 {
375         int err;
376
377         err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, TEST_ETHDEV_ID,
378                                                 -1);
379         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
380
381         err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
382         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
383
384         err = rte_event_eth_tx_adapter_stop(TEST_INST_ID);
385         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
386
387         err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, TEST_ETHDEV_ID,
388                                                 -1);
389         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
390
391         err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
392         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
393
394         err = rte_event_eth_tx_adapter_stop(TEST_INST_ID);
395         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
396
397         err = rte_event_eth_tx_adapter_start(1);
398
399         err = rte_event_eth_tx_adapter_stop(1);
400         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
401
402         return TEST_SUCCESS;
403 }
404
405
406 static int
407 tx_adapter_single(uint16_t port, uint16_t tx_queue_id,
408                 struct rte_mbuf *m, uint8_t qid,
409                 uint8_t sched_type)
410 {
411         struct rte_event event;
412         struct rte_mbuf *r;
413         int ret;
414         unsigned int l;
415
416         event.queue_id = qid;
417         event.op = RTE_EVENT_OP_NEW;
418         event.event_type = RTE_EVENT_TYPE_CPU;
419         event.sched_type = sched_type;
420         event.mbuf = m;
421
422         m->port = port;
423         rte_event_eth_tx_adapter_txq_set(m, tx_queue_id);
424
425         l = 0;
426         while (rte_event_enqueue_burst(TEST_DEV_ID, 0, &event, 1) != 1) {
427                 l++;
428                 if (l > EDEV_RETRY)
429                         break;
430         }
431
432         TEST_ASSERT(l < EDEV_RETRY, "Unable to enqueue to eventdev");
433         l = 0;
434         while (l++ < EDEV_RETRY) {
435
436                 if (eid != ~0ULL) {
437                         ret = rte_service_run_iter_on_app_lcore(eid, 0);
438                         TEST_ASSERT(ret == 0, "failed to run service %d", ret);
439                 }
440
441                 ret = rte_service_run_iter_on_app_lcore(tid, 0);
442                 TEST_ASSERT(ret == 0, "failed to run service %d", ret);
443
444                 if (rte_eth_rx_burst(TEST_ETHDEV_PAIR_ID, tx_queue_id,
445                                 &r, 1)) {
446                         TEST_ASSERT_EQUAL(r, m, "mbuf comparison failed"
447                                         " expected %p received %p", m, r);
448                         return 0;
449                 }
450         }
451
452         TEST_ASSERT(0, "Failed to receive packet");
453         return -1;
454 }
455
456 static int
457 tx_adapter_service(void)
458 {
459         struct rte_event_eth_tx_adapter_stats stats;
460         uint32_t i;
461         int err;
462         uint8_t ev_port, ev_qid;
463         struct rte_mbuf  bufs[RING_SIZE];
464         struct rte_mbuf *pbufs[RING_SIZE];
465         struct rte_event_dev_info dev_info;
466         struct rte_event_dev_config dev_conf;
467         struct rte_event_queue_conf qconf;
468         uint32_t qcnt, pcnt;
469         uint16_t q;
470         int internal_port;
471         uint32_t cap;
472
473         memset(&dev_conf, 0, sizeof(dev_conf));
474         err = rte_event_eth_tx_adapter_caps_get(TEST_DEV_ID, TEST_ETHDEV_ID,
475                                                 &cap);
476         TEST_ASSERT(err == 0, "Failed to get adapter cap err %d\n", err);
477
478         internal_port = !!(cap & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT);
479         if (internal_port)
480                 return TEST_SUCCESS;
481
482         err = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID, TEST_ETHDEV_ID,
483                                                 -1);
484         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
485
486         err = rte_event_eth_tx_adapter_event_port_get(TEST_INST_ID,
487                                                 &ev_port);
488         TEST_ASSERT_SUCCESS(err, "Failed to get event port %d", err);
489
490         err = rte_event_dev_attr_get(TEST_DEV_ID, RTE_EVENT_DEV_ATTR_PORT_COUNT,
491                                         &pcnt);
492         TEST_ASSERT_SUCCESS(err, "Port count get failed");
493
494         err = rte_event_dev_attr_get(TEST_DEV_ID,
495                                 RTE_EVENT_DEV_ATTR_QUEUE_COUNT, &qcnt);
496         TEST_ASSERT_SUCCESS(err, "Queue count get failed");
497
498         err = rte_event_dev_info_get(TEST_DEV_ID, &dev_info);
499         TEST_ASSERT_SUCCESS(err, "Dev info failed");
500
501         dev_conf.nb_event_queue_flows = dev_info.max_event_queue_flows;
502         dev_conf.nb_event_port_dequeue_depth =
503                         dev_info.max_event_port_dequeue_depth;
504         dev_conf.nb_event_port_enqueue_depth =
505                         dev_info.max_event_port_enqueue_depth;
506         dev_conf.nb_events_limit =
507                         dev_info.max_num_events;
508         dev_conf.nb_event_queues = qcnt + 1;
509         dev_conf.nb_event_ports = pcnt;
510         err = rte_event_dev_configure(TEST_DEV_ID, &dev_conf);
511         TEST_ASSERT(err == 0, "Event device initialization failed err %d\n",
512                         err);
513
514         ev_qid = qcnt;
515         qconf.nb_atomic_flows = dev_info.max_event_queue_flows;
516         qconf.nb_atomic_order_sequences = 32;
517         qconf.schedule_type = RTE_SCHED_TYPE_ATOMIC;
518         qconf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST;
519         qconf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
520         err = rte_event_queue_setup(TEST_DEV_ID, ev_qid, &qconf);
521         TEST_ASSERT_SUCCESS(err, "Failed to setup queue %u", ev_qid);
522
523         /*
524          * Setup ports again so that the newly added queue is visible
525          * to them
526          */
527         for (i = 0; i < pcnt; i++) {
528
529                 int n_links;
530                 uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
531                 uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
532
533                 if (i == ev_port)
534                         continue;
535
536                 n_links = rte_event_port_links_get(TEST_DEV_ID, i, queues,
537                                                 priorities);
538                 TEST_ASSERT(n_links > 0, "Failed to get port links %d\n",
539                         n_links);
540                 err = rte_event_port_setup(TEST_DEV_ID, i, NULL);
541                 TEST_ASSERT(err == 0, "Failed to setup port err %d\n", err);
542                 err = rte_event_port_link(TEST_DEV_ID, i, queues, priorities,
543                                         n_links);
544                 TEST_ASSERT(n_links == err, "Failed to link all queues"
545                         " err %s\n", rte_strerror(rte_errno));
546         }
547
548         err = rte_event_port_link(TEST_DEV_ID, ev_port, &ev_qid, NULL, 1);
549         TEST_ASSERT(err == 1, "Failed to link queue port %u",
550                     ev_port);
551
552         err = rte_event_eth_tx_adapter_start(TEST_INST_ID);
553         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
554
555         if (!(dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED)) {
556                 err = rte_event_dev_service_id_get(0, (uint32_t *)&eid);
557                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
558
559                 err = rte_service_runstate_set(eid, 1);
560                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
561
562                 err = rte_service_set_runstate_mapped_check(eid, 0);
563                 TEST_ASSERT(err == 0, "Expected 0 got %d", err);
564         }
565
566         err = rte_event_eth_tx_adapter_service_id_get(TEST_INST_ID, &tid);
567         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
568
569         err = rte_service_runstate_set(tid, 1);
570         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
571
572         err = rte_service_set_runstate_mapped_check(tid, 0);
573         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
574
575         err = rte_event_dev_start(TEST_DEV_ID);
576         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
577
578         for (q = 0; q < MAX_NUM_QUEUE; q++) {
579                 for (i = 0; i < RING_SIZE; i++)
580                         pbufs[i] = &bufs[i];
581                 for (i = 0; i < RING_SIZE; i++) {
582                         pbufs[i] = &bufs[i];
583                         err = tx_adapter_single(TEST_ETHDEV_ID, q, pbufs[i],
584                                                 ev_qid,
585                                                 RTE_SCHED_TYPE_ORDERED);
586                         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
587                 }
588                 for (i = 0; i < RING_SIZE; i++) {
589                         TEST_ASSERT_EQUAL(pbufs[i], &bufs[i],
590                                 "Error: received data does not match"
591                                 " that transmitted");
592                 }
593         }
594
595         err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, NULL);
596         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
597
598         err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, &stats);
599         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
600         TEST_ASSERT_EQUAL(stats.tx_packets, MAX_NUM_QUEUE * RING_SIZE,
601                         "stats.tx_packets expected %u got %"PRIu64,
602                         MAX_NUM_QUEUE * RING_SIZE,
603                         stats.tx_packets);
604
605         err = rte_event_eth_tx_adapter_stats_reset(TEST_INST_ID);
606         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
607
608         err = rte_event_eth_tx_adapter_stats_get(TEST_INST_ID, &stats);
609         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
610         TEST_ASSERT_EQUAL(stats.tx_packets, 0,
611                         "stats.tx_packets expected %u got %"PRIu64,
612                         0,
613                         stats.tx_packets);
614
615         err = rte_event_eth_tx_adapter_stats_get(1, &stats);
616         TEST_ASSERT(err == -EINVAL, "Expected -EINVAL got %d", err);
617
618         err = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID, TEST_ETHDEV_ID,
619                                                 -1);
620         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
621
622         err = rte_event_eth_tx_adapter_free(TEST_INST_ID);
623         TEST_ASSERT(err == 0, "Expected 0 got %d", err);
624
625         rte_event_dev_stop(TEST_DEV_ID);
626
627         return TEST_SUCCESS;
628 }
629
630 static int
631 tx_adapter_dynamic_device(void)
632 {
633         uint16_t port_id = rte_eth_dev_count_avail();
634         const char *null_dev[2] = { "eth_null0", "eth_null1" };
635         struct rte_eth_conf dev_conf;
636         int ret;
637         size_t i;
638
639         memset(&dev_conf, 0, sizeof(dev_conf));
640         for (i = 0; i < RTE_DIM(null_dev); i++) {
641                 ret = rte_vdev_init(null_dev[i], NULL);
642                 TEST_ASSERT_SUCCESS(ret, "%s Port creation failed %d",
643                                 null_dev[i], ret);
644
645                 if (i == 0) {
646                         ret = tx_adapter_create();
647                         TEST_ASSERT_SUCCESS(ret, "Adapter create failed %d",
648                                         ret);
649                 }
650
651                 ret = rte_eth_dev_configure(port_id + i, MAX_NUM_QUEUE,
652                                         MAX_NUM_QUEUE, &dev_conf);
653                 TEST_ASSERT_SUCCESS(ret, "Failed to configure device %d", ret);
654
655                 ret = rte_event_eth_tx_adapter_queue_add(TEST_INST_ID,
656                                                         port_id + i, 0);
657                 TEST_ASSERT_SUCCESS(ret, "Failed to add queues %d", ret);
658
659         }
660
661         for (i = 0; i < RTE_DIM(null_dev); i++) {
662                 ret = rte_event_eth_tx_adapter_queue_del(TEST_INST_ID,
663                                                         port_id + i, -1);
664                 TEST_ASSERT_SUCCESS(ret, "Failed to delete queues %d", ret);
665         }
666
667         tx_adapter_free();
668
669         for (i = 0; i < RTE_DIM(null_dev); i++)
670                 rte_vdev_uninit(null_dev[i]);
671
672         return TEST_SUCCESS;
673 }
674
675 static struct unit_test_suite event_eth_tx_tests = {
676         .setup = testsuite_setup,
677         .teardown = testsuite_teardown,
678         .suite_name = "tx event eth adapter test suite",
679         .unit_test_cases = {
680                 TEST_CASE_ST(NULL, NULL, tx_adapter_create_free),
681                 TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
682                                         tx_adapter_queue_add_del),
683                 TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
684                                         tx_adapter_start_stop),
685                 TEST_CASE_ST(tx_adapter_create, tx_adapter_free,
686                                         tx_adapter_service),
687                 TEST_CASE_ST(NULL, NULL, tx_adapter_dynamic_device),
688                 TEST_CASES_END() /**< NULL terminate unit test array */
689         }
690 };
691
692 static int
693 test_event_eth_tx_adapter_common(void)
694 {
695         return unit_test_suite_runner(&event_eth_tx_tests);
696 }
697
698 REGISTER_TEST_COMMAND(event_eth_tx_adapter_autotest,
699                 test_event_eth_tx_adapter_common);