ba8c053e5a79ad3b94d0f42bd24c3da5bb686898
[deb_dpdk.git] / test / test / test_eventdev_sw.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdint.h>
37 #include <errno.h>
38 #include <unistd.h>
39 #include <sys/queue.h>
40
41 #include <rte_memory.h>
42 #include <rte_memzone.h>
43 #include <rte_launch.h>
44 #include <rte_eal.h>
45 #include <rte_per_lcore.h>
46 #include <rte_lcore.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
49 #include <rte_cycles.h>
50 #include <rte_eventdev.h>
51 #include <rte_pause.h>
52
53 #include "test.h"
54
55 #define MAX_PORTS 16
56 #define MAX_QIDS 16
57 #define NUM_PACKETS (1<<18)
58
59 static int evdev;
60
61 struct test {
62         struct rte_mempool *mbuf_pool;
63         uint8_t port[MAX_PORTS];
64         uint8_t qid[MAX_QIDS];
65         int nb_qids;
66 };
67
68 static struct rte_event release_ev;
69
70 static inline struct rte_mbuf *
71 rte_gen_arp(int portid, struct rte_mempool *mp)
72 {
73         /*
74          * len = 14 + 46
75          * ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
76          */
77         static const uint8_t arp_request[] = {
78                 /*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8,
79                 0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
80                 /*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8,
81                 0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
82                 /*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
83                 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84                 /*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85                 0x00, 0x00, 0x00, 0x00
86         };
87         struct rte_mbuf *m;
88         int pkt_len = sizeof(arp_request) - 1;
89
90         m = rte_pktmbuf_alloc(mp);
91         if (!m)
92                 return 0;
93
94         memcpy((void *)((uintptr_t)m->buf_addr + m->data_off),
95                 arp_request, pkt_len);
96         rte_pktmbuf_pkt_len(m) = pkt_len;
97         rte_pktmbuf_data_len(m) = pkt_len;
98
99         RTE_SET_USED(portid);
100
101         return m;
102 }
103
104 static void
105 xstats_print(void)
106 {
107         const uint32_t XSTATS_MAX = 1024;
108         uint32_t i;
109         uint32_t ids[XSTATS_MAX];
110         uint64_t values[XSTATS_MAX];
111         struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
112
113         for (i = 0; i < XSTATS_MAX; i++)
114                 ids[i] = i;
115
116         /* Device names / values */
117         int ret = rte_event_dev_xstats_names_get(evdev,
118                                         RTE_EVENT_DEV_XSTATS_DEVICE, 0,
119                                         xstats_names, ids, XSTATS_MAX);
120         if (ret < 0) {
121                 printf("%d: xstats names get() returned error\n",
122                         __LINE__);
123                 return;
124         }
125         ret = rte_event_dev_xstats_get(evdev,
126                                         RTE_EVENT_DEV_XSTATS_DEVICE,
127                                         0, ids, values, ret);
128         if (ret > (signed int)XSTATS_MAX)
129                 printf("%s %d: more xstats available than space\n",
130                                 __func__, __LINE__);
131         for (i = 0; (signed int)i < ret; i++) {
132                 printf("%d : %s : %"PRIu64"\n",
133                                 i, xstats_names[i].name, values[i]);
134         }
135
136         /* Port names / values */
137         ret = rte_event_dev_xstats_names_get(evdev,
138                                         RTE_EVENT_DEV_XSTATS_PORT, 0,
139                                         xstats_names, ids, XSTATS_MAX);
140         ret = rte_event_dev_xstats_get(evdev,
141                                         RTE_EVENT_DEV_XSTATS_PORT, 1,
142                                         ids, values, ret);
143         if (ret > (signed int)XSTATS_MAX)
144                 printf("%s %d: more xstats available than space\n",
145                                 __func__, __LINE__);
146         for (i = 0; (signed int)i < ret; i++) {
147                 printf("%d : %s : %"PRIu64"\n",
148                                 i, xstats_names[i].name, values[i]);
149         }
150
151         /* Queue names / values */
152         ret = rte_event_dev_xstats_names_get(evdev,
153                                         RTE_EVENT_DEV_XSTATS_QUEUE, 0,
154                                         xstats_names, ids, XSTATS_MAX);
155         ret = rte_event_dev_xstats_get(evdev,
156                                         RTE_EVENT_DEV_XSTATS_QUEUE,
157                                         1, ids, values, ret);
158         if (ret > (signed int)XSTATS_MAX)
159                 printf("%s %d: more xstats available than space\n",
160                                 __func__, __LINE__);
161         for (i = 0; (signed int)i < ret; i++) {
162                 printf("%d : %s : %"PRIu64"\n",
163                                 i, xstats_names[i].name, values[i]);
164         }
165 }
166
167 /* initialization and config */
168 static inline int
169 init(struct test *t, int nb_queues, int nb_ports)
170 {
171         struct rte_event_dev_config config = {
172                         .nb_event_queues = nb_queues,
173                         .nb_event_ports = nb_ports,
174                         .nb_event_queue_flows = 1024,
175                         .nb_events_limit = 4096,
176                         .nb_event_port_dequeue_depth = 128,
177                         .nb_event_port_enqueue_depth = 128,
178         };
179         int ret;
180
181         void *temp = t->mbuf_pool; /* save and restore mbuf pool */
182
183         memset(t, 0, sizeof(*t));
184         t->mbuf_pool = temp;
185
186         ret = rte_event_dev_configure(evdev, &config);
187         if (ret < 0)
188                 printf("%d: Error configuring device\n", __LINE__);
189         return ret;
190 };
191
192 static inline int
193 create_ports(struct test *t, int num_ports)
194 {
195         int i;
196         static const struct rte_event_port_conf conf = {
197                         .new_event_threshold = 1024,
198                         .dequeue_depth = 32,
199                         .enqueue_depth = 64,
200         };
201         if (num_ports > MAX_PORTS)
202                 return -1;
203
204         for (i = 0; i < num_ports; i++) {
205                 if (rte_event_port_setup(evdev, i, &conf) < 0) {
206                         printf("Error setting up port %d\n", i);
207                         return -1;
208                 }
209                 t->port[i] = i;
210         }
211
212         return 0;
213 }
214
215 static inline int
216 create_lb_qids(struct test *t, int num_qids, uint32_t flags)
217 {
218         int i;
219
220         /* Q creation */
221         const struct rte_event_queue_conf conf = {
222                         .event_queue_cfg = flags,
223                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
224                         .nb_atomic_flows = 1024,
225                         .nb_atomic_order_sequences = 1024,
226         };
227
228         for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
229                 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
230                         printf("%d: error creating qid %d\n", __LINE__, i);
231                         return -1;
232                 }
233                 t->qid[i] = i;
234         }
235         t->nb_qids += num_qids;
236         if (t->nb_qids > MAX_QIDS)
237                 return -1;
238
239         return 0;
240 }
241
242 static inline int
243 create_atomic_qids(struct test *t, int num_qids)
244 {
245         return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY);
246 }
247
248 static inline int
249 create_ordered_qids(struct test *t, int num_qids)
250 {
251         return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_ORDERED_ONLY);
252 }
253
254
255 static inline int
256 create_unordered_qids(struct test *t, int num_qids)
257 {
258         return create_lb_qids(t, num_qids, RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY);
259 }
260
261 static inline int
262 create_directed_qids(struct test *t, int num_qids, const uint8_t ports[])
263 {
264         int i;
265
266         /* Q creation */
267         static const struct rte_event_queue_conf conf = {
268                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
269                         .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
270                         .nb_atomic_flows = 1024,
271                         .nb_atomic_order_sequences = 1024,
272         };
273
274         for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
275                 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
276                         printf("%d: error creating qid %d\n", __LINE__, i);
277                         return -1;
278                 }
279                 t->qid[i] = i;
280
281                 if (rte_event_port_link(evdev, ports[i - t->nb_qids],
282                                 &t->qid[i], NULL, 1) != 1) {
283                         printf("%d: error creating link for qid %d\n",
284                                         __LINE__, i);
285                         return -1;
286                 }
287         }
288         t->nb_qids += num_qids;
289         if (t->nb_qids > MAX_QIDS)
290                 return -1;
291
292         return 0;
293 }
294
295 /* destruction */
296 static inline int
297 cleanup(struct test *t __rte_unused)
298 {
299         rte_event_dev_stop(evdev);
300         rte_event_dev_close(evdev);
301         return 0;
302 };
303
304 struct test_event_dev_stats {
305         uint64_t rx_pkts;       /**< Total packets received */
306         uint64_t rx_dropped;    /**< Total packets dropped (Eg Invalid QID) */
307         uint64_t tx_pkts;       /**< Total packets transmitted */
308
309         /** Packets received on this port */
310         uint64_t port_rx_pkts[MAX_PORTS];
311         /** Packets dropped on this port */
312         uint64_t port_rx_dropped[MAX_PORTS];
313         /** Packets inflight on this port */
314         uint64_t port_inflight[MAX_PORTS];
315         /** Packets transmitted on this port */
316         uint64_t port_tx_pkts[MAX_PORTS];
317         /** Packets received on this qid */
318         uint64_t qid_rx_pkts[MAX_QIDS];
319         /** Packets dropped on this qid */
320         uint64_t qid_rx_dropped[MAX_QIDS];
321         /** Packets transmitted on this qid */
322         uint64_t qid_tx_pkts[MAX_QIDS];
323 };
324
325 static inline int
326 test_event_dev_stats_get(int dev_id, struct test_event_dev_stats *stats)
327 {
328         static uint32_t i;
329         static uint32_t total_ids[3]; /* rx, tx and drop */
330         static uint32_t port_rx_pkts_ids[MAX_PORTS];
331         static uint32_t port_rx_dropped_ids[MAX_PORTS];
332         static uint32_t port_inflight_ids[MAX_PORTS];
333         static uint32_t port_tx_pkts_ids[MAX_PORTS];
334         static uint32_t qid_rx_pkts_ids[MAX_QIDS];
335         static uint32_t qid_rx_dropped_ids[MAX_QIDS];
336         static uint32_t qid_tx_pkts_ids[MAX_QIDS];
337
338
339         stats->rx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
340                         "dev_rx", &total_ids[0]);
341         stats->rx_dropped = rte_event_dev_xstats_by_name_get(dev_id,
342                         "dev_drop", &total_ids[1]);
343         stats->tx_pkts = rte_event_dev_xstats_by_name_get(dev_id,
344                         "dev_tx", &total_ids[2]);
345         for (i = 0; i < MAX_PORTS; i++) {
346                 char name[32];
347                 snprintf(name, sizeof(name), "port_%u_rx", i);
348                 stats->port_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
349                                 dev_id, name, &port_rx_pkts_ids[i]);
350                 snprintf(name, sizeof(name), "port_%u_drop", i);
351                 stats->port_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
352                                 dev_id, name, &port_rx_dropped_ids[i]);
353                 snprintf(name, sizeof(name), "port_%u_inflight", i);
354                 stats->port_inflight[i] = rte_event_dev_xstats_by_name_get(
355                                 dev_id, name, &port_inflight_ids[i]);
356                 snprintf(name, sizeof(name), "port_%u_tx", i);
357                 stats->port_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
358                                 dev_id, name, &port_tx_pkts_ids[i]);
359         }
360         for (i = 0; i < MAX_QIDS; i++) {
361                 char name[32];
362                 snprintf(name, sizeof(name), "qid_%u_rx", i);
363                 stats->qid_rx_pkts[i] = rte_event_dev_xstats_by_name_get(
364                                 dev_id, name, &qid_rx_pkts_ids[i]);
365                 snprintf(name, sizeof(name), "qid_%u_drop", i);
366                 stats->qid_rx_dropped[i] = rte_event_dev_xstats_by_name_get(
367                                 dev_id, name, &qid_rx_dropped_ids[i]);
368                 snprintf(name, sizeof(name), "qid_%u_tx", i);
369                 stats->qid_tx_pkts[i] = rte_event_dev_xstats_by_name_get(
370                                 dev_id, name, &qid_tx_pkts_ids[i]);
371         }
372
373         return 0;
374 }
375
376 /* run_prio_packet_test
377  * This performs a basic packet priority check on the test instance passed in.
378  * It is factored out of the main priority tests as the same tests must be
379  * performed to ensure prioritization of each type of QID.
380  *
381  * Requirements:
382  *  - An initialized test structure, including mempool
383  *  - t->port[0] is initialized for both Enq / Deq of packets to the QID
384  *  - t->qid[0] is the QID to be tested
385  *  - if LB QID, the CQ must be mapped to the QID.
386  */
387 static int
388 run_prio_packet_test(struct test *t)
389 {
390         int err;
391         const uint32_t MAGIC_SEQN[] = {4711, 1234};
392         const uint32_t PRIORITY[] = {
393                 RTE_EVENT_DEV_PRIORITY_NORMAL,
394                 RTE_EVENT_DEV_PRIORITY_HIGHEST
395         };
396         unsigned int i;
397         for (i = 0; i < RTE_DIM(MAGIC_SEQN); i++) {
398                 /* generate pkt and enqueue */
399                 struct rte_event ev;
400                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
401                 if (!arp) {
402                         printf("%d: gen of pkt failed\n", __LINE__);
403                         return -1;
404                 }
405                 arp->seqn = MAGIC_SEQN[i];
406
407                 ev = (struct rte_event){
408                         .priority = PRIORITY[i],
409                         .op = RTE_EVENT_OP_NEW,
410                         .queue_id = t->qid[0],
411                         .mbuf = arp
412                 };
413                 err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
414                 if (err < 0) {
415                         printf("%d: error failed to enqueue\n", __LINE__);
416                         return -1;
417                 }
418         }
419
420         rte_event_schedule(evdev);
421
422         struct test_event_dev_stats stats;
423         err = test_event_dev_stats_get(evdev, &stats);
424         if (err) {
425                 printf("%d: error failed to get stats\n", __LINE__);
426                 return -1;
427         }
428
429         if (stats.port_rx_pkts[t->port[0]] != 2) {
430                 printf("%d: error stats incorrect for directed port\n",
431                                 __LINE__);
432                 rte_event_dev_dump(evdev, stdout);
433                 return -1;
434         }
435
436         struct rte_event ev, ev2;
437         uint32_t deq_pkts;
438         deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
439         if (deq_pkts != 1) {
440                 printf("%d: error failed to deq\n", __LINE__);
441                 rte_event_dev_dump(evdev, stdout);
442                 return -1;
443         }
444         if (ev.mbuf->seqn != MAGIC_SEQN[1]) {
445                 printf("%d: first packet out not highest priority\n",
446                                 __LINE__);
447                 rte_event_dev_dump(evdev, stdout);
448                 return -1;
449         }
450         rte_pktmbuf_free(ev.mbuf);
451
452         deq_pkts = rte_event_dequeue_burst(evdev, t->port[0], &ev2, 1, 0);
453         if (deq_pkts != 1) {
454                 printf("%d: error failed to deq\n", __LINE__);
455                 rte_event_dev_dump(evdev, stdout);
456                 return -1;
457         }
458         if (ev2.mbuf->seqn != MAGIC_SEQN[0]) {
459                 printf("%d: second packet out not lower priority\n",
460                                 __LINE__);
461                 rte_event_dev_dump(evdev, stdout);
462                 return -1;
463         }
464         rte_pktmbuf_free(ev2.mbuf);
465
466         cleanup(t);
467         return 0;
468 }
469
470 static int
471 test_single_directed_packet(struct test *t)
472 {
473         const int rx_enq = 0;
474         const int wrk_enq = 2;
475         int err;
476
477         /* Create instance with 3 directed QIDs going to 3 ports */
478         if (init(t, 3, 3) < 0 ||
479                         create_ports(t, 3) < 0 ||
480                         create_directed_qids(t, 3, t->port) < 0)
481                 return -1;
482
483         if (rte_event_dev_start(evdev) < 0) {
484                 printf("%d: Error with start call\n", __LINE__);
485                 return -1;
486         }
487
488         /************** FORWARD ****************/
489         struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
490         struct rte_event ev = {
491                         .op = RTE_EVENT_OP_NEW,
492                         .queue_id = wrk_enq,
493                         .mbuf = arp,
494         };
495
496         if (!arp) {
497                 printf("%d: gen of pkt failed\n", __LINE__);
498                 return -1;
499         }
500
501         const uint32_t MAGIC_SEQN = 4711;
502         arp->seqn = MAGIC_SEQN;
503
504         /* generate pkt and enqueue */
505         err = rte_event_enqueue_burst(evdev, rx_enq, &ev, 1);
506         if (err < 0) {
507                 printf("%d: error failed to enqueue\n", __LINE__);
508                 return -1;
509         }
510
511         /* Run schedule() as dir packets may need to be re-ordered */
512         rte_event_schedule(evdev);
513
514         struct test_event_dev_stats stats;
515         err = test_event_dev_stats_get(evdev, &stats);
516         if (err) {
517                 printf("%d: error failed to get stats\n", __LINE__);
518                 return -1;
519         }
520
521         if (stats.port_rx_pkts[rx_enq] != 1) {
522                 printf("%d: error stats incorrect for directed port\n",
523                                 __LINE__);
524                 return -1;
525         }
526
527         uint32_t deq_pkts;
528         deq_pkts = rte_event_dequeue_burst(evdev, wrk_enq, &ev, 1, 0);
529         if (deq_pkts != 1) {
530                 printf("%d: error failed to deq\n", __LINE__);
531                 return -1;
532         }
533
534         err = test_event_dev_stats_get(evdev, &stats);
535         if (stats.port_rx_pkts[wrk_enq] != 0 &&
536                         stats.port_rx_pkts[wrk_enq] != 1) {
537                 printf("%d: error directed stats post-dequeue\n", __LINE__);
538                 return -1;
539         }
540
541         if (ev.mbuf->seqn != MAGIC_SEQN) {
542                 printf("%d: error magic sequence number not dequeued\n",
543                                 __LINE__);
544                 return -1;
545         }
546
547         rte_pktmbuf_free(ev.mbuf);
548         cleanup(t);
549         return 0;
550 }
551
552 static int
553 test_directed_forward_credits(struct test *t)
554 {
555         uint32_t i;
556         int32_t err;
557
558         if (init(t, 1, 1) < 0 ||
559                         create_ports(t, 1) < 0 ||
560                         create_directed_qids(t, 1, t->port) < 0)
561                 return -1;
562
563         if (rte_event_dev_start(evdev) < 0) {
564                 printf("%d: Error with start call\n", __LINE__);
565                 return -1;
566         }
567
568         struct rte_event ev = {
569                         .op = RTE_EVENT_OP_NEW,
570                         .queue_id = 0,
571         };
572
573         for (i = 0; i < 1000; i++) {
574                 err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
575                 if (err < 0) {
576                         printf("%d: error failed to enqueue\n", __LINE__);
577                         return -1;
578                 }
579                 rte_event_schedule(evdev);
580
581                 uint32_t deq_pkts;
582                 deq_pkts = rte_event_dequeue_burst(evdev, 0, &ev, 1, 0);
583                 if (deq_pkts != 1) {
584                         printf("%d: error failed to deq\n", __LINE__);
585                         return -1;
586                 }
587
588                 /* re-write event to be a forward, and continue looping it */
589                 ev.op = RTE_EVENT_OP_FORWARD;
590         }
591
592         cleanup(t);
593         return 0;
594 }
595
596
597 static int
598 test_priority_directed(struct test *t)
599 {
600         if (init(t, 1, 1) < 0 ||
601                         create_ports(t, 1) < 0 ||
602                         create_directed_qids(t, 1, t->port) < 0) {
603                 printf("%d: Error initializing device\n", __LINE__);
604                 return -1;
605         }
606
607         if (rte_event_dev_start(evdev) < 0) {
608                 printf("%d: Error with start call\n", __LINE__);
609                 return -1;
610         }
611
612         return run_prio_packet_test(t);
613 }
614
615 static int
616 test_priority_atomic(struct test *t)
617 {
618         if (init(t, 1, 1) < 0 ||
619                         create_ports(t, 1) < 0 ||
620                         create_atomic_qids(t, 1) < 0) {
621                 printf("%d: Error initializing device\n", __LINE__);
622                 return -1;
623         }
624
625         /* map the QID */
626         if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
627                 printf("%d: error mapping qid to port\n", __LINE__);
628                 return -1;
629         }
630         if (rte_event_dev_start(evdev) < 0) {
631                 printf("%d: Error with start call\n", __LINE__);
632                 return -1;
633         }
634
635         return run_prio_packet_test(t);
636 }
637
638 static int
639 test_priority_ordered(struct test *t)
640 {
641         if (init(t, 1, 1) < 0 ||
642                         create_ports(t, 1) < 0 ||
643                         create_ordered_qids(t, 1) < 0) {
644                 printf("%d: Error initializing device\n", __LINE__);
645                 return -1;
646         }
647
648         /* map the QID */
649         if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
650                 printf("%d: error mapping qid to port\n", __LINE__);
651                 return -1;
652         }
653         if (rte_event_dev_start(evdev) < 0) {
654                 printf("%d: Error with start call\n", __LINE__);
655                 return -1;
656         }
657
658         return run_prio_packet_test(t);
659 }
660
661 static int
662 test_priority_unordered(struct test *t)
663 {
664         if (init(t, 1, 1) < 0 ||
665                         create_ports(t, 1) < 0 ||
666                         create_unordered_qids(t, 1) < 0) {
667                 printf("%d: Error initializing device\n", __LINE__);
668                 return -1;
669         }
670
671         /* map the QID */
672         if (rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1) != 1) {
673                 printf("%d: error mapping qid to port\n", __LINE__);
674                 return -1;
675         }
676         if (rte_event_dev_start(evdev) < 0) {
677                 printf("%d: Error with start call\n", __LINE__);
678                 return -1;
679         }
680
681         return run_prio_packet_test(t);
682 }
683
684 static int
685 burst_packets(struct test *t)
686 {
687         /************** CONFIG ****************/
688         uint32_t i;
689         int err;
690         int ret;
691
692         /* Create instance with 2 ports and 2 queues */
693         if (init(t, 2, 2) < 0 ||
694                         create_ports(t, 2) < 0 ||
695                         create_atomic_qids(t, 2) < 0) {
696                 printf("%d: Error initializing device\n", __LINE__);
697                 return -1;
698         }
699
700         /* CQ mapping to QID */
701         ret = rte_event_port_link(evdev, t->port[0], &t->qid[0], NULL, 1);
702         if (ret != 1) {
703                 printf("%d: error mapping lb qid0\n", __LINE__);
704                 return -1;
705         }
706         ret = rte_event_port_link(evdev, t->port[1], &t->qid[1], NULL, 1);
707         if (ret != 1) {
708                 printf("%d: error mapping lb qid1\n", __LINE__);
709                 return -1;
710         }
711
712         if (rte_event_dev_start(evdev) < 0) {
713                 printf("%d: Error with start call\n", __LINE__);
714                 return -1;
715         }
716
717         /************** FORWARD ****************/
718         const uint32_t rx_port = 0;
719         const uint32_t NUM_PKTS = 2;
720
721         for (i = 0; i < NUM_PKTS; i++) {
722                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
723                 if (!arp) {
724                         printf("%d: error generating pkt\n", __LINE__);
725                         return -1;
726                 }
727
728                 struct rte_event ev = {
729                                 .op = RTE_EVENT_OP_NEW,
730                                 .queue_id = i % 2,
731                                 .flow_id = i % 3,
732                                 .mbuf = arp,
733                 };
734                 /* generate pkt and enqueue */
735                 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
736                 if (err < 0) {
737                         printf("%d: Failed to enqueue\n", __LINE__);
738                         return -1;
739                 }
740         }
741         rte_event_schedule(evdev);
742
743         /* Check stats for all NUM_PKTS arrived to sched core */
744         struct test_event_dev_stats stats;
745
746         err = test_event_dev_stats_get(evdev, &stats);
747         if (err) {
748                 printf("%d: failed to get stats\n", __LINE__);
749                 return -1;
750         }
751         if (stats.rx_pkts != NUM_PKTS || stats.tx_pkts != NUM_PKTS) {
752                 printf("%d: Sched core didn't receive all %d pkts\n",
753                                 __LINE__, NUM_PKTS);
754                 rte_event_dev_dump(evdev, stdout);
755                 return -1;
756         }
757
758         uint32_t deq_pkts;
759         int p;
760
761         deq_pkts = 0;
762         /******** DEQ QID 1 *******/
763         do {
764                 struct rte_event ev;
765                 p = rte_event_dequeue_burst(evdev, t->port[0], &ev, 1, 0);
766                 deq_pkts += p;
767                 rte_pktmbuf_free(ev.mbuf);
768         } while (p);
769
770         if (deq_pkts != NUM_PKTS/2) {
771                 printf("%d: Half of NUM_PKTS didn't arrive at port 1\n",
772                                 __LINE__);
773                 return -1;
774         }
775
776         /******** DEQ QID 2 *******/
777         deq_pkts = 0;
778         do {
779                 struct rte_event ev;
780                 p = rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0);
781                 deq_pkts += p;
782                 rte_pktmbuf_free(ev.mbuf);
783         } while (p);
784         if (deq_pkts != NUM_PKTS/2) {
785                 printf("%d: Half of NUM_PKTS didn't arrive at port 2\n",
786                                 __LINE__);
787                 return -1;
788         }
789
790         cleanup(t);
791         return 0;
792 }
793
794 static int
795 abuse_inflights(struct test *t)
796 {
797         const int rx_enq = 0;
798         const int wrk_enq = 2;
799         int err;
800
801         /* Create instance with 4 ports */
802         if (init(t, 1, 4) < 0 ||
803                         create_ports(t, 4) < 0 ||
804                         create_atomic_qids(t, 1) < 0) {
805                 printf("%d: Error initializing device\n", __LINE__);
806                 return -1;
807         }
808
809         /* CQ mapping to QID */
810         err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
811         if (err != 1) {
812                 printf("%d: error mapping lb qid\n", __LINE__);
813                 cleanup(t);
814                 return -1;
815         }
816
817         if (rte_event_dev_start(evdev) < 0) {
818                 printf("%d: Error with start call\n", __LINE__);
819                 return -1;
820         }
821
822         /* Enqueue op only */
823         err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &release_ev, 1);
824         if (err < 0) {
825                 printf("%d: Failed to enqueue\n", __LINE__);
826                 return -1;
827         }
828
829         /* schedule */
830         rte_event_schedule(evdev);
831
832         struct test_event_dev_stats stats;
833
834         err = test_event_dev_stats_get(evdev, &stats);
835         if (err) {
836                 printf("%d: failed to get stats\n", __LINE__);
837                 return -1;
838         }
839
840         if (stats.rx_pkts != 0 ||
841                         stats.tx_pkts != 0 ||
842                         stats.port_inflight[wrk_enq] != 0) {
843                 printf("%d: Sched core didn't handle pkt as expected\n",
844                                 __LINE__);
845                 return -1;
846         }
847
848         cleanup(t);
849         return 0;
850 }
851
852 static int
853 xstats_tests(struct test *t)
854 {
855         const int wrk_enq = 2;
856         int err;
857
858         /* Create instance with 4 ports */
859         if (init(t, 1, 4) < 0 ||
860                         create_ports(t, 4) < 0 ||
861                         create_atomic_qids(t, 1) < 0) {
862                 printf("%d: Error initializing device\n", __LINE__);
863                 return -1;
864         }
865
866         /* CQ mapping to QID */
867         err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
868         if (err != 1) {
869                 printf("%d: error mapping lb qid\n", __LINE__);
870                 cleanup(t);
871                 return -1;
872         }
873
874         if (rte_event_dev_start(evdev) < 0) {
875                 printf("%d: Error with start call\n", __LINE__);
876                 return -1;
877         }
878
879         const uint32_t XSTATS_MAX = 1024;
880
881         uint32_t i;
882         uint32_t ids[XSTATS_MAX];
883         uint64_t values[XSTATS_MAX];
884         struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
885
886         for (i = 0; i < XSTATS_MAX; i++)
887                 ids[i] = i;
888
889         /* Device names / values */
890         int ret = rte_event_dev_xstats_names_get(evdev,
891                                         RTE_EVENT_DEV_XSTATS_DEVICE,
892                                         0, xstats_names, ids, XSTATS_MAX);
893         if (ret != 6) {
894                 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
895                 return -1;
896         }
897         ret = rte_event_dev_xstats_get(evdev,
898                                         RTE_EVENT_DEV_XSTATS_DEVICE,
899                                         0, ids, values, ret);
900         if (ret != 6) {
901                 printf("%d: expected 6 stats, got return %d\n", __LINE__, ret);
902                 return -1;
903         }
904
905         /* Port names / values */
906         ret = rte_event_dev_xstats_names_get(evdev,
907                                         RTE_EVENT_DEV_XSTATS_PORT, 0,
908                                         xstats_names, ids, XSTATS_MAX);
909         if (ret != 21) {
910                 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
911                 return -1;
912         }
913         ret = rte_event_dev_xstats_get(evdev,
914                                         RTE_EVENT_DEV_XSTATS_PORT, 0,
915                                         ids, values, ret);
916         if (ret != 21) {
917                 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
918                 return -1;
919         }
920
921         /* Queue names / values */
922         ret = rte_event_dev_xstats_names_get(evdev,
923                                         RTE_EVENT_DEV_XSTATS_QUEUE,
924                                         0, xstats_names, ids, XSTATS_MAX);
925         if (ret != 17) {
926                 printf("%d: expected 17 stats, got return %d\n", __LINE__, ret);
927                 return -1;
928         }
929
930         /* NEGATIVE TEST: with wrong queue passed, 0 stats should be returned */
931         ret = rte_event_dev_xstats_get(evdev,
932                                         RTE_EVENT_DEV_XSTATS_QUEUE,
933                                         1, ids, values, ret);
934         if (ret != -EINVAL) {
935                 printf("%d: expected 0 stats, got return %d\n", __LINE__, ret);
936                 return -1;
937         }
938
939         ret = rte_event_dev_xstats_get(evdev,
940                                         RTE_EVENT_DEV_XSTATS_QUEUE,
941                                         0, ids, values, ret);
942         if (ret != 17) {
943                 printf("%d: expected 17 stats, got return %d\n", __LINE__, ret);
944                 return -1;
945         }
946
947         /* enqueue packets to check values */
948         for (i = 0; i < 3; i++) {
949                 struct rte_event ev;
950                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
951                 if (!arp) {
952                         printf("%d: gen of pkt failed\n", __LINE__);
953                         return -1;
954                 }
955                 ev.queue_id = t->qid[i];
956                 ev.op = RTE_EVENT_OP_NEW;
957                 ev.mbuf = arp;
958                 ev.flow_id = 7;
959                 arp->seqn = i;
960
961                 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
962                 if (err != 1) {
963                         printf("%d: Failed to enqueue\n", __LINE__);
964                         return -1;
965                 }
966         }
967
968         rte_event_schedule(evdev);
969
970         /* Device names / values */
971         int num_stats = rte_event_dev_xstats_names_get(evdev,
972                                         RTE_EVENT_DEV_XSTATS_DEVICE, 0,
973                                         xstats_names, ids, XSTATS_MAX);
974         if (num_stats < 0)
975                 goto fail;
976         ret = rte_event_dev_xstats_get(evdev,
977                                         RTE_EVENT_DEV_XSTATS_DEVICE,
978                                         0, ids, values, num_stats);
979         static const uint64_t expected[] = {3, 3, 0, 1, 0, 0};
980         for (i = 0; (signed int)i < ret; i++) {
981                 if (expected[i] != values[i]) {
982                         printf(
983                                 "%d Error xstat %d (id %d) %s : %"PRIu64
984                                 ", expect %"PRIu64"\n",
985                                 __LINE__, i, ids[i], xstats_names[i].name,
986                                 values[i], expected[i]);
987                         goto fail;
988                 }
989         }
990
991         ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_DEVICE,
992                                         0, NULL, 0);
993
994         /* ensure reset statistics are zero-ed */
995         static const uint64_t expected_zero[] = {0, 0, 0, 0, 0, 0};
996         ret = rte_event_dev_xstats_get(evdev,
997                                         RTE_EVENT_DEV_XSTATS_DEVICE,
998                                         0, ids, values, num_stats);
999         for (i = 0; (signed int)i < ret; i++) {
1000                 if (expected_zero[i] != values[i]) {
1001                         printf(
1002                                 "%d Error, xstat %d (id %d) %s : %"PRIu64
1003                                 ", expect %"PRIu64"\n",
1004                                 __LINE__, i, ids[i], xstats_names[i].name,
1005                                 values[i], expected_zero[i]);
1006                         goto fail;
1007                 }
1008         }
1009
1010         /* port reset checks */
1011         num_stats = rte_event_dev_xstats_names_get(evdev,
1012                                         RTE_EVENT_DEV_XSTATS_PORT, 0,
1013                                         xstats_names, ids, XSTATS_MAX);
1014         if (num_stats < 0)
1015                 goto fail;
1016         ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT,
1017                                         0, ids, values, num_stats);
1018
1019         static const uint64_t port_expected[] = {
1020                 3 /* rx */,
1021                 0 /* tx */,
1022                 0 /* drop */,
1023                 0 /* inflights */,
1024                 0 /* avg pkt cycles */,
1025                 29 /* credits */,
1026                 0 /* rx ring used */,
1027                 4096 /* rx ring free */,
1028                 0 /* cq ring used */,
1029                 32 /* cq ring free */,
1030                 0 /* dequeue calls */,
1031                 /* 10 dequeue burst buckets */
1032                 0, 0, 0, 0, 0,
1033                 0, 0, 0, 0, 0,
1034         };
1035         if (ret != RTE_DIM(port_expected)) {
1036                 printf(
1037                         "%s %d: wrong number of port stats (%d), expected %zu\n",
1038                         __func__, __LINE__, ret, RTE_DIM(port_expected));
1039         }
1040
1041         for (i = 0; (signed int)i < ret; i++) {
1042                 if (port_expected[i] != values[i]) {
1043                         printf(
1044                                 "%s : %d: Error stat %s is %"PRIu64
1045                                 ", expected %"PRIu64"\n",
1046                                 __func__, __LINE__, xstats_names[i].name,
1047                                 values[i], port_expected[i]);
1048                         goto fail;
1049                 }
1050         }
1051
1052         ret = rte_event_dev_xstats_reset(evdev, RTE_EVENT_DEV_XSTATS_PORT,
1053                                         0, NULL, 0);
1054
1055         /* ensure reset statistics are zero-ed */
1056         static const uint64_t port_expected_zero[] = {
1057                 0 /* rx */,
1058                 0 /* tx */,
1059                 0 /* drop */,
1060                 0 /* inflights */,
1061                 0 /* avg pkt cycles */,
1062                 29 /* credits */,
1063                 0 /* rx ring used */,
1064                 4096 /* rx ring free */,
1065                 0 /* cq ring used */,
1066                 32 /* cq ring free */,
1067                 0 /* dequeue calls */,
1068                 /* 10 dequeue burst buckets */
1069                 0, 0, 0, 0, 0,
1070                 0, 0, 0, 0, 0,
1071         };
1072         ret = rte_event_dev_xstats_get(evdev,
1073                                         RTE_EVENT_DEV_XSTATS_PORT,
1074                                         0, ids, values, num_stats);
1075         for (i = 0; (signed int)i < ret; i++) {
1076                 if (port_expected_zero[i] != values[i]) {
1077                         printf(
1078                                 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1079                                 ", expect %"PRIu64"\n",
1080                                 __LINE__, i, ids[i], xstats_names[i].name,
1081                                 values[i], port_expected_zero[i]);
1082                         goto fail;
1083                 }
1084         }
1085
1086         /* QUEUE STATS TESTS */
1087         num_stats = rte_event_dev_xstats_names_get(evdev,
1088                                                 RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1089                                                 xstats_names, ids, XSTATS_MAX);
1090         ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1091                                         0, ids, values, num_stats);
1092         if (ret < 0) {
1093                 printf("xstats get returned %d\n", ret);
1094                 goto fail;
1095         }
1096         if ((unsigned int)ret > XSTATS_MAX)
1097                 printf("%s %d: more xstats available than space\n",
1098                                 __func__, __LINE__);
1099
1100         static const uint64_t queue_expected[] = {
1101                 3 /* rx */,
1102                 3 /* tx */,
1103                 0 /* drop */,
1104                 3 /* inflights */,
1105                 512 /* iq size */,
1106                 0, 0, 0, 0, /* iq 0, 1, 2, 3 used */
1107                 /* QID-to-Port: pinned_flows, packets */
1108                 0, 0,
1109                 0, 0,
1110                 1, 3,
1111                 0, 0,
1112         };
1113         for (i = 0; (signed int)i < ret; i++) {
1114                 if (queue_expected[i] != values[i]) {
1115                         printf(
1116                                 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1117                                 ", expect %"PRIu64"\n",
1118                                 __LINE__, i, ids[i], xstats_names[i].name,
1119                                 values[i], queue_expected[i]);
1120                         goto fail;
1121                 }
1122         }
1123
1124         /* Reset the queue stats here */
1125         ret = rte_event_dev_xstats_reset(evdev,
1126                                         RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1127                                         NULL,
1128                                         0);
1129
1130         /* Verify that the resetable stats are reset, and others are not */
1131         static const uint64_t queue_expected_zero[] = {
1132                 0 /* rx */,
1133                 0 /* tx */,
1134                 0 /* drop */,
1135                 3 /* inflight */,
1136                 512 /* iq size */,
1137                 0, 0, 0, 0, /* 4 iq used */
1138                 /* QID-to-Port: pinned_flows, packets */
1139                 0, 0,
1140                 0, 0,
1141                 1, 0,
1142                 0, 0,
1143         };
1144
1145         ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE, 0,
1146                                         ids, values, num_stats);
1147         int fails = 0;
1148         for (i = 0; (signed int)i < ret; i++) {
1149                 if (queue_expected_zero[i] != values[i]) {
1150                         printf(
1151                                 "%d, Error, xstat %d (id %d) %s : %"PRIu64
1152                                 ", expect %"PRIu64"\n",
1153                                 __LINE__, i, ids[i], xstats_names[i].name,
1154                                 values[i], queue_expected_zero[i]);
1155                         fails++;
1156                 }
1157         }
1158         if (fails) {
1159                 printf("%d : %d of values were not as expected above\n",
1160                                 __LINE__, fails);
1161                 goto fail;
1162         }
1163
1164         cleanup(t);
1165         return 0;
1166
1167 fail:
1168         rte_event_dev_dump(0, stdout);
1169         cleanup(t);
1170         return -1;
1171 }
1172
1173
1174 static int
1175 xstats_id_abuse_tests(struct test *t)
1176 {
1177         int err;
1178         const uint32_t XSTATS_MAX = 1024;
1179         const uint32_t link_port = 2;
1180
1181         uint32_t ids[XSTATS_MAX];
1182         struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1183
1184         /* Create instance with 4 ports */
1185         if (init(t, 1, 4) < 0 ||
1186                         create_ports(t, 4) < 0 ||
1187                         create_atomic_qids(t, 1) < 0) {
1188                 printf("%d: Error initializing device\n", __LINE__);
1189                 goto fail;
1190         }
1191
1192         err = rte_event_port_link(evdev, t->port[link_port], NULL, NULL, 0);
1193         if (err != 1) {
1194                 printf("%d: error mapping lb qid\n", __LINE__);
1195                 goto fail;
1196         }
1197
1198         if (rte_event_dev_start(evdev) < 0) {
1199                 printf("%d: Error with start call\n", __LINE__);
1200                 goto fail;
1201         }
1202
1203         /* no test for device, as it ignores the port/q number */
1204         int num_stats = rte_event_dev_xstats_names_get(evdev,
1205                                         RTE_EVENT_DEV_XSTATS_PORT,
1206                                         UINT8_MAX-1, xstats_names, ids,
1207                                         XSTATS_MAX);
1208         if (num_stats != 0) {
1209                 printf("%d: expected %d stats, got return %d\n", __LINE__,
1210                                 0, num_stats);
1211                 goto fail;
1212         }
1213
1214         num_stats = rte_event_dev_xstats_names_get(evdev,
1215                                         RTE_EVENT_DEV_XSTATS_QUEUE,
1216                                         UINT8_MAX-1, xstats_names, ids,
1217                                         XSTATS_MAX);
1218         if (num_stats != 0) {
1219                 printf("%d: expected %d stats, got return %d\n", __LINE__,
1220                                 0, num_stats);
1221                 goto fail;
1222         }
1223
1224         cleanup(t);
1225         return 0;
1226 fail:
1227         cleanup(t);
1228         return -1;
1229 }
1230
1231 static int
1232 port_reconfig_credits(struct test *t)
1233 {
1234         if (init(t, 1, 1) < 0) {
1235                 printf("%d: Error initializing device\n", __LINE__);
1236                 return -1;
1237         }
1238
1239         uint32_t i;
1240         const uint32_t NUM_ITERS = 32;
1241         for (i = 0; i < NUM_ITERS; i++) {
1242                 const struct rte_event_queue_conf conf = {
1243                         .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1244                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1245                         .nb_atomic_flows = 1024,
1246                         .nb_atomic_order_sequences = 1024,
1247                 };
1248                 if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1249                         printf("%d: error creating qid\n", __LINE__);
1250                         return -1;
1251                 }
1252                 t->qid[0] = 0;
1253
1254                 static const struct rte_event_port_conf port_conf = {
1255                                 .new_event_threshold = 128,
1256                                 .dequeue_depth = 32,
1257                                 .enqueue_depth = 64,
1258                 };
1259                 if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1260                         printf("%d Error setting up port\n", __LINE__);
1261                         return -1;
1262                 }
1263
1264                 int links = rte_event_port_link(evdev, 0, NULL, NULL, 0);
1265                 if (links != 1) {
1266                         printf("%d: error mapping lb qid\n", __LINE__);
1267                         goto fail;
1268                 }
1269
1270                 if (rte_event_dev_start(evdev) < 0) {
1271                         printf("%d: Error with start call\n", __LINE__);
1272                         goto fail;
1273                 }
1274
1275                 const uint32_t NPKTS = 1;
1276                 uint32_t j;
1277                 for (j = 0; j < NPKTS; j++) {
1278                         struct rte_event ev;
1279                         struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1280                         if (!arp) {
1281                                 printf("%d: gen of pkt failed\n", __LINE__);
1282                                 goto fail;
1283                         }
1284                         ev.queue_id = t->qid[0];
1285                         ev.op = RTE_EVENT_OP_NEW;
1286                         ev.mbuf = arp;
1287                         int err = rte_event_enqueue_burst(evdev, 0, &ev, 1);
1288                         if (err != 1) {
1289                                 printf("%d: Failed to enqueue\n", __LINE__);
1290                                 rte_event_dev_dump(0, stdout);
1291                                 goto fail;
1292                         }
1293                 }
1294
1295                 rte_event_schedule(evdev);
1296
1297                 struct rte_event ev[NPKTS];
1298                 int deq = rte_event_dequeue_burst(evdev, t->port[0], ev,
1299                                                         NPKTS, 0);
1300                 if (deq != 1)
1301                         printf("%d error; no packet dequeued\n", __LINE__);
1302
1303                 /* let cleanup below stop the device on last iter */
1304                 if (i != NUM_ITERS-1)
1305                         rte_event_dev_stop(evdev);
1306         }
1307
1308         cleanup(t);
1309         return 0;
1310 fail:
1311         cleanup(t);
1312         return -1;
1313 }
1314
1315 static int
1316 port_single_lb_reconfig(struct test *t)
1317 {
1318         if (init(t, 2, 2) < 0) {
1319                 printf("%d: Error initializing device\n", __LINE__);
1320                 goto fail;
1321         }
1322
1323         static const struct rte_event_queue_conf conf_lb_atomic = {
1324                 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1325                 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1326                 .nb_atomic_flows = 1024,
1327                 .nb_atomic_order_sequences = 1024,
1328         };
1329         if (rte_event_queue_setup(evdev, 0, &conf_lb_atomic) < 0) {
1330                 printf("%d: error creating qid\n", __LINE__);
1331                 goto fail;
1332         }
1333
1334         static const struct rte_event_queue_conf conf_single_link = {
1335                 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1336                 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK,
1337                 .nb_atomic_flows = 1024,
1338                 .nb_atomic_order_sequences = 1024,
1339         };
1340         if (rte_event_queue_setup(evdev, 1, &conf_single_link) < 0) {
1341                 printf("%d: error creating qid\n", __LINE__);
1342                 goto fail;
1343         }
1344
1345         struct rte_event_port_conf port_conf = {
1346                 .new_event_threshold = 128,
1347                 .dequeue_depth = 32,
1348                 .enqueue_depth = 64,
1349         };
1350         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1351                 printf("%d Error setting up port\n", __LINE__);
1352                 goto fail;
1353         }
1354         if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
1355                 printf("%d Error setting up port\n", __LINE__);
1356                 goto fail;
1357         }
1358
1359         /* link port to lb queue */
1360         uint8_t queue_id = 0;
1361         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1362                 printf("%d: error creating link for qid\n", __LINE__);
1363                 goto fail;
1364         }
1365
1366         int ret = rte_event_port_unlink(evdev, 0, &queue_id, 1);
1367         if (ret != 1) {
1368                 printf("%d: Error unlinking lb port\n", __LINE__);
1369                 goto fail;
1370         }
1371
1372         queue_id = 1;
1373         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1374                 printf("%d: error creating link for qid\n", __LINE__);
1375                 goto fail;
1376         }
1377
1378         queue_id = 0;
1379         int err = rte_event_port_link(evdev, 1, &queue_id, NULL, 1);
1380         if (err != 1) {
1381                 printf("%d: error mapping lb qid\n", __LINE__);
1382                 goto fail;
1383         }
1384
1385         if (rte_event_dev_start(evdev) < 0) {
1386                 printf("%d: Error with start call\n", __LINE__);
1387                 goto fail;
1388         }
1389
1390         cleanup(t);
1391         return 0;
1392 fail:
1393         cleanup(t);
1394         return -1;
1395 }
1396
1397 static int
1398 xstats_brute_force(struct test *t)
1399 {
1400         uint32_t i;
1401         const uint32_t XSTATS_MAX = 1024;
1402         uint32_t ids[XSTATS_MAX];
1403         uint64_t values[XSTATS_MAX];
1404         struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1405
1406
1407         /* Create instance with 4 ports */
1408         if (init(t, 1, 4) < 0 ||
1409                         create_ports(t, 4) < 0 ||
1410                         create_atomic_qids(t, 1) < 0) {
1411                 printf("%d: Error initializing device\n", __LINE__);
1412                 return -1;
1413         }
1414
1415         int err = rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1416         if (err != 1) {
1417                 printf("%d: error mapping lb qid\n", __LINE__);
1418                 goto fail;
1419         }
1420
1421         if (rte_event_dev_start(evdev) < 0) {
1422                 printf("%d: Error with start call\n", __LINE__);
1423                 goto fail;
1424         }
1425
1426         for (i = 0; i < XSTATS_MAX; i++)
1427                 ids[i] = i;
1428
1429         for (i = 0; i < 3; i++) {
1430                 uint32_t mode = RTE_EVENT_DEV_XSTATS_DEVICE + i;
1431                 uint32_t j;
1432                 for (j = 0; j < UINT8_MAX; j++) {
1433                         rte_event_dev_xstats_names_get(evdev, mode,
1434                                 j, xstats_names, ids, XSTATS_MAX);
1435
1436                         rte_event_dev_xstats_get(evdev, mode, j, ids,
1437                                                  values, XSTATS_MAX);
1438                 }
1439         }
1440
1441         cleanup(t);
1442         return 0;
1443 fail:
1444         cleanup(t);
1445         return -1;
1446 }
1447
1448 static int
1449 xstats_id_reset_tests(struct test *t)
1450 {
1451         const int wrk_enq = 2;
1452         int err;
1453
1454         /* Create instance with 4 ports */
1455         if (init(t, 1, 4) < 0 ||
1456                         create_ports(t, 4) < 0 ||
1457                         create_atomic_qids(t, 1) < 0) {
1458                 printf("%d: Error initializing device\n", __LINE__);
1459                 return -1;
1460         }
1461
1462         /* CQ mapping to QID */
1463         err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
1464         if (err != 1) {
1465                 printf("%d: error mapping lb qid\n", __LINE__);
1466                 goto fail;
1467         }
1468
1469         if (rte_event_dev_start(evdev) < 0) {
1470                 printf("%d: Error with start call\n", __LINE__);
1471                 goto fail;
1472         }
1473
1474 #define XSTATS_MAX 1024
1475         int ret;
1476         uint32_t i;
1477         uint32_t ids[XSTATS_MAX];
1478         uint64_t values[XSTATS_MAX];
1479         struct rte_event_dev_xstats_name xstats_names[XSTATS_MAX];
1480
1481         for (i = 0; i < XSTATS_MAX; i++)
1482                 ids[i] = i;
1483
1484 #define NUM_DEV_STATS 6
1485         /* Device names / values */
1486         int num_stats = rte_event_dev_xstats_names_get(evdev,
1487                                         RTE_EVENT_DEV_XSTATS_DEVICE,
1488                                         0, xstats_names, ids, XSTATS_MAX);
1489         if (num_stats != NUM_DEV_STATS) {
1490                 printf("%d: expected %d stats, got return %d\n", __LINE__,
1491                                 NUM_DEV_STATS, num_stats);
1492                 goto fail;
1493         }
1494         ret = rte_event_dev_xstats_get(evdev,
1495                                         RTE_EVENT_DEV_XSTATS_DEVICE,
1496                                         0, ids, values, num_stats);
1497         if (ret != NUM_DEV_STATS) {
1498                 printf("%d: expected %d stats, got return %d\n", __LINE__,
1499                                 NUM_DEV_STATS, ret);
1500                 goto fail;
1501         }
1502
1503 #define NPKTS 7
1504         for (i = 0; i < NPKTS; i++) {
1505                 struct rte_event ev;
1506                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1507                 if (!arp) {
1508                         printf("%d: gen of pkt failed\n", __LINE__);
1509                         goto fail;
1510                 }
1511                 ev.queue_id = t->qid[i];
1512                 ev.op = RTE_EVENT_OP_NEW;
1513                 ev.mbuf = arp;
1514                 arp->seqn = i;
1515
1516                 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1517                 if (err != 1) {
1518                         printf("%d: Failed to enqueue\n", __LINE__);
1519                         goto fail;
1520                 }
1521         }
1522
1523         rte_event_schedule(evdev);
1524
1525         static const char * const dev_names[] = {
1526                 "dev_rx", "dev_tx", "dev_drop", "dev_sched_calls",
1527                 "dev_sched_no_iq_enq", "dev_sched_no_cq_enq",
1528         };
1529         uint64_t dev_expected[] = {NPKTS, NPKTS, 0, 1, 0, 0};
1530         for (i = 0; (int)i < ret; i++) {
1531                 unsigned int id;
1532                 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1533                                                                 dev_names[i],
1534                                                                 &id);
1535                 if (id != i) {
1536                         printf("%d: %s id incorrect, expected %d got %d\n",
1537                                         __LINE__, dev_names[i], i, id);
1538                         goto fail;
1539                 }
1540                 if (val != dev_expected[i]) {
1541                         printf("%d: %s value incorrect, expected %"
1542                                 PRIu64" got %d\n", __LINE__, dev_names[i],
1543                                 dev_expected[i], id);
1544                         goto fail;
1545                 }
1546                 /* reset to zero */
1547                 int reset_ret = rte_event_dev_xstats_reset(evdev,
1548                                                 RTE_EVENT_DEV_XSTATS_DEVICE, 0,
1549                                                 &id,
1550                                                 1);
1551                 if (reset_ret) {
1552                         printf("%d: failed to reset successfully\n", __LINE__);
1553                         goto fail;
1554                 }
1555                 dev_expected[i] = 0;
1556                 /* check value again */
1557                 val = rte_event_dev_xstats_by_name_get(evdev, dev_names[i], 0);
1558                 if (val != dev_expected[i]) {
1559                         printf("%d: %s value incorrect, expected %"PRIu64
1560                                 " got %"PRIu64"\n", __LINE__, dev_names[i],
1561                                 dev_expected[i], val);
1562                         goto fail;
1563                 }
1564         };
1565
1566 /* 48 is stat offset from start of the devices whole xstats.
1567  * This WILL break every time we add a statistic to a port
1568  * or the device, but there is no other way to test
1569  */
1570 #define PORT_OFF 48
1571 /* num stats for the tested port. CQ size adds more stats to a port */
1572 #define NUM_PORT_STATS 21
1573 /* the port to test. */
1574 #define PORT 2
1575         num_stats = rte_event_dev_xstats_names_get(evdev,
1576                                         RTE_EVENT_DEV_XSTATS_PORT, PORT,
1577                                         xstats_names, ids, XSTATS_MAX);
1578         if (num_stats != NUM_PORT_STATS) {
1579                 printf("%d: expected %d stats, got return %d\n",
1580                         __LINE__, NUM_PORT_STATS, num_stats);
1581                 goto fail;
1582         }
1583         ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_PORT, PORT,
1584                                         ids, values, num_stats);
1585
1586         if (ret != NUM_PORT_STATS) {
1587                 printf("%d: expected %d stats, got return %d\n",
1588                                 __LINE__, NUM_PORT_STATS, ret);
1589                 goto fail;
1590         }
1591         static const char * const port_names[] = {
1592                 "port_2_rx",
1593                 "port_2_tx",
1594                 "port_2_drop",
1595                 "port_2_inflight",
1596                 "port_2_avg_pkt_cycles",
1597                 "port_2_credits",
1598                 "port_2_rx_ring_used",
1599                 "port_2_rx_ring_free",
1600                 "port_2_cq_ring_used",
1601                 "port_2_cq_ring_free",
1602                 "port_2_dequeue_calls",
1603                 "port_2_dequeues_returning_0",
1604                 "port_2_dequeues_returning_1-4",
1605                 "port_2_dequeues_returning_5-8",
1606                 "port_2_dequeues_returning_9-12",
1607                 "port_2_dequeues_returning_13-16",
1608                 "port_2_dequeues_returning_17-20",
1609                 "port_2_dequeues_returning_21-24",
1610                 "port_2_dequeues_returning_25-28",
1611                 "port_2_dequeues_returning_29-32",
1612                 "port_2_dequeues_returning_33-36",
1613         };
1614         uint64_t port_expected[] = {
1615                 0, /* rx */
1616                 NPKTS, /* tx */
1617                 0, /* drop */
1618                 NPKTS, /* inflight */
1619                 0, /* avg pkt cycles */
1620                 0, /* credits */
1621                 0, /* rx ring used */
1622                 4096, /* rx ring free */
1623                 NPKTS,  /* cq ring used */
1624                 25, /* cq ring free */
1625                 0, /* dequeue zero calls */
1626                 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1627                 0, 0, 0, 0, 0,
1628         };
1629         uint64_t port_expected_zero[] = {
1630                 0, /* rx */
1631                 0, /* tx */
1632                 0, /* drop */
1633                 NPKTS, /* inflight */
1634                 0, /* avg pkt cycles */
1635                 0, /* credits */
1636                 0, /* rx ring used */
1637                 4096, /* rx ring free */
1638                 NPKTS,  /* cq ring used */
1639                 25, /* cq ring free */
1640                 0, /* dequeue zero calls */
1641                 0, 0, 0, 0, 0, /* 10 dequeue buckets */
1642                 0, 0, 0, 0, 0,
1643         };
1644         if (RTE_DIM(port_expected) != NUM_PORT_STATS ||
1645                         RTE_DIM(port_names) != NUM_PORT_STATS) {
1646                 printf("%d: port array of wrong size\n", __LINE__);
1647                 goto fail;
1648         }
1649
1650         int failed = 0;
1651         for (i = 0; (int)i < ret; i++) {
1652                 unsigned int id;
1653                 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1654                                                                 port_names[i],
1655                                                                 &id);
1656                 if (id != i + PORT_OFF) {
1657                         printf("%d: %s id incorrect, expected %d got %d\n",
1658                                         __LINE__, port_names[i], i+PORT_OFF,
1659                                         id);
1660                         failed = 1;
1661                 }
1662                 if (val != port_expected[i]) {
1663                         printf("%d: %s value incorrect, expected %"PRIu64
1664                                 " got %d\n", __LINE__, port_names[i],
1665                                 port_expected[i], id);
1666                         failed = 1;
1667                 }
1668                 /* reset to zero */
1669                 int reset_ret = rte_event_dev_xstats_reset(evdev,
1670                                                 RTE_EVENT_DEV_XSTATS_PORT, PORT,
1671                                                 &id,
1672                                                 1);
1673                 if (reset_ret) {
1674                         printf("%d: failed to reset successfully\n", __LINE__);
1675                         failed = 1;
1676                 }
1677                 /* check value again */
1678                 val = rte_event_dev_xstats_by_name_get(evdev, port_names[i], 0);
1679                 if (val != port_expected_zero[i]) {
1680                         printf("%d: %s value incorrect, expected %"PRIu64
1681                                 " got %"PRIu64"\n", __LINE__, port_names[i],
1682                                 port_expected_zero[i], val);
1683                         failed = 1;
1684                 }
1685         };
1686         if (failed)
1687                 goto fail;
1688
1689 /* num queue stats */
1690 #define NUM_Q_STATS 17
1691 /* queue offset from start of the devices whole xstats.
1692  * This will break every time we add a statistic to a device/port/queue
1693  */
1694 #define QUEUE_OFF 90
1695         const uint32_t queue = 0;
1696         num_stats = rte_event_dev_xstats_names_get(evdev,
1697                                         RTE_EVENT_DEV_XSTATS_QUEUE, queue,
1698                                         xstats_names, ids, XSTATS_MAX);
1699         if (num_stats != NUM_Q_STATS) {
1700                 printf("%d: expected %d stats, got return %d\n",
1701                         __LINE__, NUM_Q_STATS, num_stats);
1702                 goto fail;
1703         }
1704         ret = rte_event_dev_xstats_get(evdev, RTE_EVENT_DEV_XSTATS_QUEUE,
1705                                         queue, ids, values, num_stats);
1706         if (ret != NUM_Q_STATS) {
1707                 printf("%d: expected 21 stats, got return %d\n", __LINE__, ret);
1708                 goto fail;
1709         }
1710         static const char * const queue_names[] = {
1711                 "qid_0_rx",
1712                 "qid_0_tx",
1713                 "qid_0_drop",
1714                 "qid_0_inflight",
1715                 "qid_0_iq_size",
1716                 "qid_0_iq_0_used",
1717                 "qid_0_iq_1_used",
1718                 "qid_0_iq_2_used",
1719                 "qid_0_iq_3_used",
1720                 "qid_0_port_0_pinned_flows",
1721                 "qid_0_port_0_packets",
1722                 "qid_0_port_1_pinned_flows",
1723                 "qid_0_port_1_packets",
1724                 "qid_0_port_2_pinned_flows",
1725                 "qid_0_port_2_packets",
1726                 "qid_0_port_3_pinned_flows",
1727                 "qid_0_port_3_packets",
1728         };
1729         uint64_t queue_expected[] = {
1730                 7, /* rx */
1731                 7, /* tx */
1732                 0, /* drop */
1733                 7, /* inflight */
1734                 512, /* iq size */
1735                 0, /* iq 0 used */
1736                 0, /* iq 1 used */
1737                 0, /* iq 2 used */
1738                 0, /* iq 3 used */
1739                 /* QID-to-Port: pinned_flows, packets */
1740                 0, 0,
1741                 0, 0,
1742                 1, 7,
1743                 0, 0,
1744         };
1745         uint64_t queue_expected_zero[] = {
1746                 0, /* rx */
1747                 0, /* tx */
1748                 0, /* drop */
1749                 7, /* inflight */
1750                 512, /* iq size */
1751                 0, /* iq 0 used */
1752                 0, /* iq 1 used */
1753                 0, /* iq 2 used */
1754                 0, /* iq 3 used */
1755                 /* QID-to-Port: pinned_flows, packets */
1756                 0, 0,
1757                 0, 0,
1758                 1, 0,
1759                 0, 0,
1760         };
1761         if (RTE_DIM(queue_expected) != NUM_Q_STATS ||
1762                         RTE_DIM(queue_expected_zero) != NUM_Q_STATS ||
1763                         RTE_DIM(queue_names) != NUM_Q_STATS) {
1764                 printf("%d : queue array of wrong size\n", __LINE__);
1765                 goto fail;
1766         }
1767
1768         failed = 0;
1769         for (i = 0; (int)i < ret; i++) {
1770                 unsigned int id;
1771                 uint64_t val = rte_event_dev_xstats_by_name_get(evdev,
1772                                                                 queue_names[i],
1773                                                                 &id);
1774                 if (id != i + QUEUE_OFF) {
1775                         printf("%d: %s id incorrect, expected %d got %d\n",
1776                                         __LINE__, queue_names[i], i+QUEUE_OFF,
1777                                         id);
1778                         failed = 1;
1779                 }
1780                 if (val != queue_expected[i]) {
1781                         printf("%d: %d: %s value , expected %"PRIu64
1782                                 " got %"PRIu64"\n", i, __LINE__,
1783                                 queue_names[i], queue_expected[i], val);
1784                         failed = 1;
1785                 }
1786                 /* reset to zero */
1787                 int reset_ret = rte_event_dev_xstats_reset(evdev,
1788                                                 RTE_EVENT_DEV_XSTATS_QUEUE,
1789                                                 queue, &id, 1);
1790                 if (reset_ret) {
1791                         printf("%d: failed to reset successfully\n", __LINE__);
1792                         failed = 1;
1793                 }
1794                 /* check value again */
1795                 val = rte_event_dev_xstats_by_name_get(evdev, queue_names[i],
1796                                                         0);
1797                 if (val != queue_expected_zero[i]) {
1798                         printf("%d: %s value incorrect, expected %"PRIu64
1799                                 " got %"PRIu64"\n", __LINE__, queue_names[i],
1800                                 queue_expected_zero[i], val);
1801                         failed = 1;
1802                 }
1803         };
1804
1805         if (failed)
1806                 goto fail;
1807
1808         cleanup(t);
1809         return 0;
1810 fail:
1811         cleanup(t);
1812         return -1;
1813 }
1814
1815 static int
1816 ordered_reconfigure(struct test *t)
1817 {
1818         if (init(t, 1, 1) < 0 ||
1819                         create_ports(t, 1) < 0) {
1820                 printf("%d: Error initializing device\n", __LINE__);
1821                 return -1;
1822         }
1823
1824         const struct rte_event_queue_conf conf = {
1825                         .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY,
1826                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
1827                         .nb_atomic_flows = 1024,
1828                         .nb_atomic_order_sequences = 1024,
1829         };
1830
1831         if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1832                 printf("%d: error creating qid\n", __LINE__);
1833                 goto failed;
1834         }
1835
1836         if (rte_event_queue_setup(evdev, 0, &conf) < 0) {
1837                 printf("%d: error creating qid, for 2nd time\n", __LINE__);
1838                 goto failed;
1839         }
1840
1841         rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1842         if (rte_event_dev_start(evdev) < 0) {
1843                 printf("%d: Error with start call\n", __LINE__);
1844                 return -1;
1845         }
1846
1847         cleanup(t);
1848         return 0;
1849 failed:
1850         cleanup(t);
1851         return -1;
1852 }
1853
1854 static int
1855 qid_priorities(struct test *t)
1856 {
1857         /* Test works by having a CQ with enough empty space for all packets,
1858          * and enqueueing 3 packets to 3 QIDs. They must return based on the
1859          * priority of the QID, not the ingress order, to pass the test
1860          */
1861         unsigned int i;
1862         /* Create instance with 1 ports, and 3 qids */
1863         if (init(t, 3, 1) < 0 ||
1864                         create_ports(t, 1) < 0) {
1865                 printf("%d: Error initializing device\n", __LINE__);
1866                 return -1;
1867         }
1868
1869         for (i = 0; i < 3; i++) {
1870                 /* Create QID */
1871                 const struct rte_event_queue_conf conf = {
1872                         .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
1873                         /* increase priority (0 == highest), as we go */
1874                         .priority = RTE_EVENT_DEV_PRIORITY_NORMAL - i,
1875                         .nb_atomic_flows = 1024,
1876                         .nb_atomic_order_sequences = 1024,
1877                 };
1878
1879                 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
1880                         printf("%d: error creating qid %d\n", __LINE__, i);
1881                         return -1;
1882                 }
1883                 t->qid[i] = i;
1884         }
1885         t->nb_qids = i;
1886         /* map all QIDs to port */
1887         rte_event_port_link(evdev, t->port[0], NULL, NULL, 0);
1888
1889         if (rte_event_dev_start(evdev) < 0) {
1890                 printf("%d: Error with start call\n", __LINE__);
1891                 return -1;
1892         }
1893
1894         /* enqueue 3 packets, setting seqn and QID to check priority */
1895         for (i = 0; i < 3; i++) {
1896                 struct rte_event ev;
1897                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1898                 if (!arp) {
1899                         printf("%d: gen of pkt failed\n", __LINE__);
1900                         return -1;
1901                 }
1902                 ev.queue_id = t->qid[i];
1903                 ev.op = RTE_EVENT_OP_NEW;
1904                 ev.mbuf = arp;
1905                 arp->seqn = i;
1906
1907                 int err = rte_event_enqueue_burst(evdev, t->port[0], &ev, 1);
1908                 if (err != 1) {
1909                         printf("%d: Failed to enqueue\n", __LINE__);
1910                         return -1;
1911                 }
1912         }
1913
1914         rte_event_schedule(evdev);
1915
1916         /* dequeue packets, verify priority was upheld */
1917         struct rte_event ev[32];
1918         uint32_t deq_pkts =
1919                 rte_event_dequeue_burst(evdev, t->port[0], ev, 32, 0);
1920         if (deq_pkts != 3) {
1921                 printf("%d: failed to deq packets\n", __LINE__);
1922                 rte_event_dev_dump(evdev, stdout);
1923                 return -1;
1924         }
1925         for (i = 0; i < 3; i++) {
1926                 if (ev[i].mbuf->seqn != 2-i) {
1927                         printf(
1928                                 "%d: qid priority test: seqn %d incorrectly prioritized\n",
1929                                         __LINE__, i);
1930                 }
1931         }
1932
1933         cleanup(t);
1934         return 0;
1935 }
1936
1937 static int
1938 load_balancing(struct test *t)
1939 {
1940         const int rx_enq = 0;
1941         int err;
1942         uint32_t i;
1943
1944         if (init(t, 1, 4) < 0 ||
1945                         create_ports(t, 4) < 0 ||
1946                         create_atomic_qids(t, 1) < 0) {
1947                 printf("%d: Error initializing device\n", __LINE__);
1948                 return -1;
1949         }
1950
1951         for (i = 0; i < 3; i++) {
1952                 /* map port 1 - 3 inclusive */
1953                 if (rte_event_port_link(evdev, t->port[i+1], &t->qid[0],
1954                                 NULL, 1) != 1) {
1955                         printf("%d: error mapping qid to port %d\n",
1956                                         __LINE__, i);
1957                         return -1;
1958                 }
1959         }
1960
1961         if (rte_event_dev_start(evdev) < 0) {
1962                 printf("%d: Error with start call\n", __LINE__);
1963                 return -1;
1964         }
1965
1966         /************** FORWARD ****************/
1967         /*
1968          * Create a set of flows that test the load-balancing operation of the
1969          * implementation. Fill CQ 0 and 1 with flows 0 and 1, and test
1970          * with a new flow, which should be sent to the 3rd mapped CQ
1971          */
1972         static uint32_t flows[] = {0, 1, 1, 0, 0, 2, 2, 0, 2};
1973
1974         for (i = 0; i < RTE_DIM(flows); i++) {
1975                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
1976                 if (!arp) {
1977                         printf("%d: gen of pkt failed\n", __LINE__);
1978                         return -1;
1979                 }
1980
1981                 struct rte_event ev = {
1982                                 .op = RTE_EVENT_OP_NEW,
1983                                 .queue_id = t->qid[0],
1984                                 .flow_id = flows[i],
1985                                 .mbuf = arp,
1986                 };
1987                 /* generate pkt and enqueue */
1988                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
1989                 if (err < 0) {
1990                         printf("%d: Failed to enqueue\n", __LINE__);
1991                         return -1;
1992                 }
1993         }
1994
1995         rte_event_schedule(evdev);
1996
1997         struct test_event_dev_stats stats;
1998         err = test_event_dev_stats_get(evdev, &stats);
1999         if (err) {
2000                 printf("%d: failed to get stats\n", __LINE__);
2001                 return -1;
2002         }
2003
2004         if (stats.port_inflight[1] != 4) {
2005                 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
2006                                 __func__);
2007                 return -1;
2008         }
2009         if (stats.port_inflight[2] != 2) {
2010                 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
2011                                 __func__);
2012                 return -1;
2013         }
2014         if (stats.port_inflight[3] != 3) {
2015                 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
2016                                 __func__);
2017                 return -1;
2018         }
2019
2020         cleanup(t);
2021         return 0;
2022 }
2023
2024 static int
2025 load_balancing_history(struct test *t)
2026 {
2027         struct test_event_dev_stats stats = {0};
2028         const int rx_enq = 0;
2029         int err;
2030         uint32_t i;
2031
2032         /* Create instance with 1 atomic QID going to 3 ports + 1 prod port */
2033         if (init(t, 1, 4) < 0 ||
2034                         create_ports(t, 4) < 0 ||
2035                         create_atomic_qids(t, 1) < 0)
2036                 return -1;
2037
2038         /* CQ mapping to QID */
2039         if (rte_event_port_link(evdev, t->port[1], &t->qid[0], NULL, 1) != 1) {
2040                 printf("%d: error mapping port 1 qid\n", __LINE__);
2041                 return -1;
2042         }
2043         if (rte_event_port_link(evdev, t->port[2], &t->qid[0], NULL, 1) != 1) {
2044                 printf("%d: error mapping port 2 qid\n", __LINE__);
2045                 return -1;
2046         }
2047         if (rte_event_port_link(evdev, t->port[3], &t->qid[0], NULL, 1) != 1) {
2048                 printf("%d: error mapping port 3 qid\n", __LINE__);
2049                 return -1;
2050         }
2051         if (rte_event_dev_start(evdev) < 0) {
2052                 printf("%d: Error with start call\n", __LINE__);
2053                 return -1;
2054         }
2055
2056         /*
2057          * Create a set of flows that test the load-balancing operation of the
2058          * implementation. Fill CQ 0, 1 and 2 with flows 0, 1 and 2, drop
2059          * the packet from CQ 0, send in a new set of flows. Ensure that:
2060          *  1. The new flow 3 gets into the empty CQ0
2061          *  2. packets for existing flow gets added into CQ1
2062          *  3. Next flow 0 pkt is now onto CQ2, since CQ0 and CQ1 now contain
2063          *     more outstanding pkts
2064          *
2065          *  This test makes sure that when a flow ends (i.e. all packets
2066          *  have been completed for that flow), that the flow can be moved
2067          *  to a different CQ when new packets come in for that flow.
2068          */
2069         static uint32_t flows1[] = {0, 1, 1, 2};
2070
2071         for (i = 0; i < RTE_DIM(flows1); i++) {
2072                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2073                 struct rte_event ev = {
2074                                 .flow_id = flows1[i],
2075                                 .op = RTE_EVENT_OP_NEW,
2076                                 .queue_id = t->qid[0],
2077                                 .event_type = RTE_EVENT_TYPE_CPU,
2078                                 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2079                                 .mbuf = arp
2080                 };
2081
2082                 if (!arp) {
2083                         printf("%d: gen of pkt failed\n", __LINE__);
2084                         return -1;
2085                 }
2086                 arp->hash.rss = flows1[i];
2087                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2088                 if (err < 0) {
2089                         printf("%d: Failed to enqueue\n", __LINE__);
2090                         return -1;
2091                 }
2092         }
2093
2094         /* call the scheduler */
2095         rte_event_schedule(evdev);
2096
2097         /* Dequeue the flow 0 packet from port 1, so that we can then drop */
2098         struct rte_event ev;
2099         if (!rte_event_dequeue_burst(evdev, t->port[1], &ev, 1, 0)) {
2100                 printf("%d: failed to dequeue\n", __LINE__);
2101                 return -1;
2102         }
2103         if (ev.mbuf->hash.rss != flows1[0]) {
2104                 printf("%d: unexpected flow received\n", __LINE__);
2105                 return -1;
2106         }
2107
2108         /* drop the flow 0 packet from port 1 */
2109         rte_event_enqueue_burst(evdev, t->port[1], &release_ev, 1);
2110
2111         /* call the scheduler */
2112         rte_event_schedule(evdev);
2113
2114         /*
2115          * Set up the next set of flows, first a new flow to fill up
2116          * CQ 0, so that the next flow 0 packet should go to CQ2
2117          */
2118         static uint32_t flows2[] = { 3, 3, 3, 1, 1, 0 };
2119
2120         for (i = 0; i < RTE_DIM(flows2); i++) {
2121                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2122                 struct rte_event ev = {
2123                                 .flow_id = flows2[i],
2124                                 .op = RTE_EVENT_OP_NEW,
2125                                 .queue_id = t->qid[0],
2126                                 .event_type = RTE_EVENT_TYPE_CPU,
2127                                 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
2128                                 .mbuf = arp
2129                 };
2130
2131                 if (!arp) {
2132                         printf("%d: gen of pkt failed\n", __LINE__);
2133                         return -1;
2134                 }
2135                 arp->hash.rss = flows2[i];
2136
2137                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2138                 if (err < 0) {
2139                         printf("%d: Failed to enqueue\n", __LINE__);
2140                         return -1;
2141                 }
2142         }
2143
2144         /* schedule */
2145         rte_event_schedule(evdev);
2146
2147         err = test_event_dev_stats_get(evdev, &stats);
2148         if (err) {
2149                 printf("%d:failed to get stats\n", __LINE__);
2150                 return -1;
2151         }
2152
2153         /*
2154          * Now check the resulting inflights on each port.
2155          */
2156         if (stats.port_inflight[1] != 3) {
2157                 printf("%d:%s: port 1 inflight not correct\n", __LINE__,
2158                                 __func__);
2159                 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2160                                 (unsigned int)stats.port_inflight[1],
2161                                 (unsigned int)stats.port_inflight[2],
2162                                 (unsigned int)stats.port_inflight[3]);
2163                 return -1;
2164         }
2165         if (stats.port_inflight[2] != 4) {
2166                 printf("%d:%s: port 2 inflight not correct\n", __LINE__,
2167                                 __func__);
2168                 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2169                                 (unsigned int)stats.port_inflight[1],
2170                                 (unsigned int)stats.port_inflight[2],
2171                                 (unsigned int)stats.port_inflight[3]);
2172                 return -1;
2173         }
2174         if (stats.port_inflight[3] != 2) {
2175                 printf("%d:%s: port 3 inflight not correct\n", __LINE__,
2176                                 __func__);
2177                 printf("Inflights, ports 1, 2, 3: %u, %u, %u\n",
2178                                 (unsigned int)stats.port_inflight[1],
2179                                 (unsigned int)stats.port_inflight[2],
2180                                 (unsigned int)stats.port_inflight[3]);
2181                 return -1;
2182         }
2183
2184         for (i = 1; i <= 3; i++) {
2185                 struct rte_event ev;
2186                 while (rte_event_dequeue_burst(evdev, i, &ev, 1, 0))
2187                         rte_event_enqueue_burst(evdev, i, &release_ev, 1);
2188         }
2189         rte_event_schedule(evdev);
2190
2191         cleanup(t);
2192         return 0;
2193 }
2194
2195 static int
2196 invalid_qid(struct test *t)
2197 {
2198         struct test_event_dev_stats stats;
2199         const int rx_enq = 0;
2200         int err;
2201         uint32_t i;
2202
2203         if (init(t, 1, 4) < 0 ||
2204                         create_ports(t, 4) < 0 ||
2205                         create_atomic_qids(t, 1) < 0) {
2206                 printf("%d: Error initializing device\n", __LINE__);
2207                 return -1;
2208         }
2209
2210         /* CQ mapping to QID */
2211         for (i = 0; i < 4; i++) {
2212                 err = rte_event_port_link(evdev, t->port[i], &t->qid[0],
2213                                 NULL, 1);
2214                 if (err != 1) {
2215                         printf("%d: error mapping port 1 qid\n", __LINE__);
2216                         return -1;
2217                 }
2218         }
2219
2220         if (rte_event_dev_start(evdev) < 0) {
2221                 printf("%d: Error with start call\n", __LINE__);
2222                 return -1;
2223         }
2224
2225         /*
2226          * Send in a packet with an invalid qid to the scheduler.
2227          * We should see the packed enqueued OK, but the inflights for
2228          * that packet should not be incremented, and the rx_dropped
2229          * should be incremented.
2230          */
2231         static uint32_t flows1[] = {20};
2232
2233         for (i = 0; i < RTE_DIM(flows1); i++) {
2234                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2235                 if (!arp) {
2236                         printf("%d: gen of pkt failed\n", __LINE__);
2237                         return -1;
2238                 }
2239
2240                 struct rte_event ev = {
2241                                 .op = RTE_EVENT_OP_NEW,
2242                                 .queue_id = t->qid[0] + flows1[i],
2243                                 .flow_id = i,
2244                                 .mbuf = arp,
2245                 };
2246                 /* generate pkt and enqueue */
2247                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2248                 if (err < 0) {
2249                         printf("%d: Failed to enqueue\n", __LINE__);
2250                         return -1;
2251                 }
2252         }
2253
2254         /* call the scheduler */
2255         rte_event_schedule(evdev);
2256
2257         err = test_event_dev_stats_get(evdev, &stats);
2258         if (err) {
2259                 printf("%d: failed to get stats\n", __LINE__);
2260                 return -1;
2261         }
2262
2263         /*
2264          * Now check the resulting inflights on the port, and the rx_dropped.
2265          */
2266         if (stats.port_inflight[0] != 0) {
2267                 printf("%d:%s: port 1 inflight count not correct\n", __LINE__,
2268                                 __func__);
2269                 rte_event_dev_dump(evdev, stdout);
2270                 return -1;
2271         }
2272         if (stats.port_rx_dropped[0] != 1) {
2273                 printf("%d:%s: port 1 drops\n", __LINE__, __func__);
2274                 rte_event_dev_dump(evdev, stdout);
2275                 return -1;
2276         }
2277         /* each packet drop should only be counted in one place - port or dev */
2278         if (stats.rx_dropped != 0) {
2279                 printf("%d:%s: port 1 dropped count not correct\n", __LINE__,
2280                                 __func__);
2281                 rte_event_dev_dump(evdev, stdout);
2282                 return -1;
2283         }
2284
2285         cleanup(t);
2286         return 0;
2287 }
2288
2289 static int
2290 single_packet(struct test *t)
2291 {
2292         const uint32_t MAGIC_SEQN = 7321;
2293         struct rte_event ev;
2294         struct test_event_dev_stats stats;
2295         const int rx_enq = 0;
2296         const int wrk_enq = 2;
2297         int err;
2298
2299         /* Create instance with 4 ports */
2300         if (init(t, 1, 4) < 0 ||
2301                         create_ports(t, 4) < 0 ||
2302                         create_atomic_qids(t, 1) < 0) {
2303                 printf("%d: Error initializing device\n", __LINE__);
2304                 return -1;
2305         }
2306
2307         /* CQ mapping to QID */
2308         err = rte_event_port_link(evdev, t->port[wrk_enq], NULL, NULL, 0);
2309         if (err != 1) {
2310                 printf("%d: error mapping lb qid\n", __LINE__);
2311                 cleanup(t);
2312                 return -1;
2313         }
2314
2315         if (rte_event_dev_start(evdev) < 0) {
2316                 printf("%d: Error with start call\n", __LINE__);
2317                 return -1;
2318         }
2319
2320         /************** Gen pkt and enqueue ****************/
2321         struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2322         if (!arp) {
2323                 printf("%d: gen of pkt failed\n", __LINE__);
2324                 return -1;
2325         }
2326
2327         ev.op = RTE_EVENT_OP_NEW;
2328         ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
2329         ev.mbuf = arp;
2330         ev.queue_id = 0;
2331         ev.flow_id = 3;
2332         arp->seqn = MAGIC_SEQN;
2333
2334         err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2335         if (err < 0) {
2336                 printf("%d: Failed to enqueue\n", __LINE__);
2337                 return -1;
2338         }
2339
2340         rte_event_schedule(evdev);
2341
2342         err = test_event_dev_stats_get(evdev, &stats);
2343         if (err) {
2344                 printf("%d: failed to get stats\n", __LINE__);
2345                 return -1;
2346         }
2347
2348         if (stats.rx_pkts != 1 ||
2349                         stats.tx_pkts != 1 ||
2350                         stats.port_inflight[wrk_enq] != 1) {
2351                 printf("%d: Sched core didn't handle pkt as expected\n",
2352                                 __LINE__);
2353                 rte_event_dev_dump(evdev, stdout);
2354                 return -1;
2355         }
2356
2357         uint32_t deq_pkts;
2358
2359         deq_pkts = rte_event_dequeue_burst(evdev, t->port[wrk_enq], &ev, 1, 0);
2360         if (deq_pkts < 1) {
2361                 printf("%d: Failed to deq\n", __LINE__);
2362                 return -1;
2363         }
2364
2365         err = test_event_dev_stats_get(evdev, &stats);
2366         if (err) {
2367                 printf("%d: failed to get stats\n", __LINE__);
2368                 return -1;
2369         }
2370
2371         err = test_event_dev_stats_get(evdev, &stats);
2372         if (ev.mbuf->seqn != MAGIC_SEQN) {
2373                 printf("%d: magic sequence number not dequeued\n", __LINE__);
2374                 return -1;
2375         }
2376
2377         rte_pktmbuf_free(ev.mbuf);
2378         err = rte_event_enqueue_burst(evdev, t->port[wrk_enq], &release_ev, 1);
2379         if (err < 0) {
2380                 printf("%d: Failed to enqueue\n", __LINE__);
2381                 return -1;
2382         }
2383         rte_event_schedule(evdev);
2384
2385         err = test_event_dev_stats_get(evdev, &stats);
2386         if (stats.port_inflight[wrk_enq] != 0) {
2387                 printf("%d: port inflight not correct\n", __LINE__);
2388                 return -1;
2389         }
2390
2391         cleanup(t);
2392         return 0;
2393 }
2394
2395 static int
2396 inflight_counts(struct test *t)
2397 {
2398         struct rte_event ev;
2399         struct test_event_dev_stats stats;
2400         const int rx_enq = 0;
2401         const int p1 = 1;
2402         const int p2 = 2;
2403         int err;
2404         int i;
2405
2406         /* Create instance with 4 ports */
2407         if (init(t, 2, 3) < 0 ||
2408                         create_ports(t, 3) < 0 ||
2409                         create_atomic_qids(t, 2) < 0) {
2410                 printf("%d: Error initializing device\n", __LINE__);
2411                 return -1;
2412         }
2413
2414         /* CQ mapping to QID */
2415         err = rte_event_port_link(evdev, t->port[p1], &t->qid[0], NULL, 1);
2416         if (err != 1) {
2417                 printf("%d: error mapping lb qid\n", __LINE__);
2418                 cleanup(t);
2419                 return -1;
2420         }
2421         err = rte_event_port_link(evdev, t->port[p2], &t->qid[1], NULL, 1);
2422         if (err != 1) {
2423                 printf("%d: error mapping lb qid\n", __LINE__);
2424                 cleanup(t);
2425                 return -1;
2426         }
2427
2428         if (rte_event_dev_start(evdev) < 0) {
2429                 printf("%d: Error with start call\n", __LINE__);
2430                 return -1;
2431         }
2432
2433         /************** FORWARD ****************/
2434 #define QID1_NUM 5
2435         for (i = 0; i < QID1_NUM; i++) {
2436                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2437
2438                 if (!arp) {
2439                         printf("%d: gen of pkt failed\n", __LINE__);
2440                         goto err;
2441                 }
2442
2443                 ev.queue_id =  t->qid[0];
2444                 ev.op = RTE_EVENT_OP_NEW;
2445                 ev.mbuf = arp;
2446                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2447                 if (err != 1) {
2448                         printf("%d: Failed to enqueue\n", __LINE__);
2449                         goto err;
2450                 }
2451         }
2452 #define QID2_NUM 3
2453         for (i = 0; i < QID2_NUM; i++) {
2454                 struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
2455
2456                 if (!arp) {
2457                         printf("%d: gen of pkt failed\n", __LINE__);
2458                         goto err;
2459                 }
2460                 ev.queue_id =  t->qid[1];
2461                 ev.op = RTE_EVENT_OP_NEW;
2462                 ev.mbuf = arp;
2463                 err = rte_event_enqueue_burst(evdev, t->port[rx_enq], &ev, 1);
2464                 if (err != 1) {
2465                         printf("%d: Failed to enqueue\n", __LINE__);
2466                         goto err;
2467                 }
2468         }
2469
2470         /* schedule */
2471         rte_event_schedule(evdev);
2472
2473         err = test_event_dev_stats_get(evdev, &stats);
2474         if (err) {
2475                 printf("%d: failed to get stats\n", __LINE__);
2476                 goto err;
2477         }
2478
2479         if (stats.rx_pkts != QID1_NUM + QID2_NUM ||
2480                         stats.tx_pkts != QID1_NUM + QID2_NUM) {
2481                 printf("%d: Sched core didn't handle pkt as expected\n",
2482                                 __LINE__);
2483                 goto err;
2484         }
2485
2486         if (stats.port_inflight[p1] != QID1_NUM) {
2487                 printf("%d: %s port 1 inflight not correct\n", __LINE__,
2488                                 __func__);
2489                 goto err;
2490         }
2491         if (stats.port_inflight[p2] != QID2_NUM) {
2492                 printf("%d: %s port 2 inflight not correct\n", __LINE__,
2493                                 __func__);
2494                 goto err;
2495         }
2496
2497         /************** DEQUEUE INFLIGHT COUNT CHECKS  ****************/
2498         /* port 1 */
2499         struct rte_event events[QID1_NUM + QID2_NUM];
2500         uint32_t deq_pkts = rte_event_dequeue_burst(evdev, t->port[p1], events,
2501                         RTE_DIM(events), 0);
2502
2503         if (deq_pkts != QID1_NUM) {
2504                 printf("%d: Port 1: DEQUEUE inflight failed\n", __LINE__);
2505                 goto err;
2506         }
2507         err = test_event_dev_stats_get(evdev, &stats);
2508         if (stats.port_inflight[p1] != QID1_NUM) {
2509                 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2510                                 __LINE__);
2511                 goto err;
2512         }
2513         for (i = 0; i < QID1_NUM; i++) {
2514                 err = rte_event_enqueue_burst(evdev, t->port[p1], &release_ev,
2515                                 1);
2516                 if (err != 1) {
2517                         printf("%d: %s rte enqueue of inf release failed\n",
2518                                 __LINE__, __func__);
2519                         goto err;
2520                 }
2521         }
2522
2523         /*
2524          * As the scheduler core decrements inflights, it needs to run to
2525          * process packets to act on the drop messages
2526          */
2527         rte_event_schedule(evdev);
2528
2529         err = test_event_dev_stats_get(evdev, &stats);
2530         if (stats.port_inflight[p1] != 0) {
2531                 printf("%d: port 1 inflight NON NULL after DROP\n", __LINE__);
2532                 goto err;
2533         }
2534
2535         /* port2 */
2536         deq_pkts = rte_event_dequeue_burst(evdev, t->port[p2], events,
2537                         RTE_DIM(events), 0);
2538         if (deq_pkts != QID2_NUM) {
2539                 printf("%d: Port 2: DEQUEUE inflight failed\n", __LINE__);
2540                 goto err;
2541         }
2542         err = test_event_dev_stats_get(evdev, &stats);
2543         if (stats.port_inflight[p2] != QID2_NUM) {
2544                 printf("%d: port 1 inflight decrement after DEQ != 0\n",
2545                                 __LINE__);
2546                 goto err;
2547         }
2548         for (i = 0; i < QID2_NUM; i++) {
2549                 err = rte_event_enqueue_burst(evdev, t->port[p2], &release_ev,
2550                                 1);
2551                 if (err != 1) {
2552                         printf("%d: %s rte enqueue of inf release failed\n",
2553                                 __LINE__, __func__);
2554                         goto err;
2555                 }
2556         }
2557
2558         /*
2559          * As the scheduler core decrements inflights, it needs to run to
2560          * process packets to act on the drop messages
2561          */
2562         rte_event_schedule(evdev);
2563
2564         err = test_event_dev_stats_get(evdev, &stats);
2565         if (stats.port_inflight[p2] != 0) {
2566                 printf("%d: port 2 inflight NON NULL after DROP\n", __LINE__);
2567                 goto err;
2568         }
2569         cleanup(t);
2570         return 0;
2571
2572 err:
2573         rte_event_dev_dump(evdev, stdout);
2574         cleanup(t);
2575         return -1;
2576 }
2577
2578 static int
2579 parallel_basic(struct test *t, int check_order)
2580 {
2581         const uint8_t rx_port = 0;
2582         const uint8_t w1_port = 1;
2583         const uint8_t w3_port = 3;
2584         const uint8_t tx_port = 4;
2585         int err;
2586         int i;
2587         uint32_t deq_pkts, j;
2588         struct rte_mbuf *mbufs[3];
2589         struct rte_mbuf *mbufs_out[3] = { 0 };
2590         const uint32_t MAGIC_SEQN = 1234;
2591
2592         /* Create instance with 4 ports */
2593         if (init(t, 2, tx_port + 1) < 0 ||
2594                         create_ports(t, tx_port + 1) < 0 ||
2595                         (check_order ?  create_ordered_qids(t, 1) :
2596                                 create_unordered_qids(t, 1)) < 0 ||
2597                         create_directed_qids(t, 1, &tx_port)) {
2598                 printf("%d: Error initializing device\n", __LINE__);
2599                 return -1;
2600         }
2601
2602         /*
2603          * CQ mapping to QID
2604          * We need three ports, all mapped to the same ordered qid0. Then we'll
2605          * take a packet out to each port, re-enqueue in reverse order,
2606          * then make sure the reordering has taken place properly when we
2607          * dequeue from the tx_port.
2608          *
2609          * Simplified test setup diagram:
2610          *
2611          * rx_port        w1_port
2612          *        \     /         \
2613          *         qid0 - w2_port - qid1
2614          *              \         /     \
2615          *                w3_port        tx_port
2616          */
2617         /* CQ mapping to QID for LB ports (directed mapped on create) */
2618         for (i = w1_port; i <= w3_port; i++) {
2619                 err = rte_event_port_link(evdev, t->port[i], &t->qid[0], NULL,
2620                                 1);
2621                 if (err != 1) {
2622                         printf("%d: error mapping lb qid\n", __LINE__);
2623                         cleanup(t);
2624                         return -1;
2625                 }
2626         }
2627
2628         if (rte_event_dev_start(evdev) < 0) {
2629                 printf("%d: Error with start call\n", __LINE__);
2630                 return -1;
2631         }
2632
2633         /* Enqueue 3 packets to the rx port */
2634         for (i = 0; i < 3; i++) {
2635                 struct rte_event ev;
2636                 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
2637                 if (!mbufs[i]) {
2638                         printf("%d: gen of pkt failed\n", __LINE__);
2639                         return -1;
2640                 }
2641
2642                 ev.queue_id = t->qid[0];
2643                 ev.op = RTE_EVENT_OP_NEW;
2644                 ev.mbuf = mbufs[i];
2645                 mbufs[i]->seqn = MAGIC_SEQN + i;
2646
2647                 /* generate pkt and enqueue */
2648                 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
2649                 if (err != 1) {
2650                         printf("%d: Failed to enqueue pkt %u, retval = %u\n",
2651                                         __LINE__, i, err);
2652                         return -1;
2653                 }
2654         }
2655
2656         rte_event_schedule(evdev);
2657
2658         /* use extra slot to make logic in loops easier */
2659         struct rte_event deq_ev[w3_port + 1];
2660
2661         /* Dequeue the 3 packets, one from each worker port */
2662         for (i = w1_port; i <= w3_port; i++) {
2663                 deq_pkts = rte_event_dequeue_burst(evdev, t->port[i],
2664                                 &deq_ev[i], 1, 0);
2665                 if (deq_pkts != 1) {
2666                         printf("%d: Failed to deq\n", __LINE__);
2667                         rte_event_dev_dump(evdev, stdout);
2668                         return -1;
2669                 }
2670         }
2671
2672         /* Enqueue each packet in reverse order, flushing after each one */
2673         for (i = w3_port; i >= w1_port; i--) {
2674
2675                 deq_ev[i].op = RTE_EVENT_OP_FORWARD;
2676                 deq_ev[i].queue_id = t->qid[1];
2677                 err = rte_event_enqueue_burst(evdev, t->port[i], &deq_ev[i], 1);
2678                 if (err != 1) {
2679                         printf("%d: Failed to enqueue\n", __LINE__);
2680                         return -1;
2681                 }
2682         }
2683         rte_event_schedule(evdev);
2684
2685         /* dequeue from the tx ports, we should get 3 packets */
2686         deq_pkts = rte_event_dequeue_burst(evdev, t->port[tx_port], deq_ev,
2687                         3, 0);
2688
2689         /* Check to see if we've got all 3 packets */
2690         if (deq_pkts != 3) {
2691                 printf("%d: expected 3 pkts at tx port got %d from port %d\n",
2692                         __LINE__, deq_pkts, tx_port);
2693                 rte_event_dev_dump(evdev, stdout);
2694                 return 1;
2695         }
2696
2697         /* Check to see if the sequence numbers are in expected order */
2698         if (check_order) {
2699                 for (j = 0 ; j < deq_pkts ; j++) {
2700                         if (deq_ev[j].mbuf->seqn != MAGIC_SEQN + j) {
2701                                 printf(
2702                                         "%d: Incorrect sequence number(%d) from port %d\n",
2703                                         __LINE__, mbufs_out[j]->seqn, tx_port);
2704                                 return -1;
2705                         }
2706                 }
2707         }
2708
2709         /* Destroy the instance */
2710         cleanup(t);
2711         return 0;
2712 }
2713
2714 static int
2715 ordered_basic(struct test *t)
2716 {
2717         return parallel_basic(t, 1);
2718 }
2719
2720 static int
2721 unordered_basic(struct test *t)
2722 {
2723         return parallel_basic(t, 0);
2724 }
2725
2726 static int
2727 holb(struct test *t) /* test to check we avoid basic head-of-line blocking */
2728 {
2729         const struct rte_event new_ev = {
2730                         .op = RTE_EVENT_OP_NEW
2731                         /* all other fields zero */
2732         };
2733         struct rte_event ev = new_ev;
2734         unsigned int rx_port = 0; /* port we get the first flow on */
2735         char rx_port_used_stat[64];
2736         char rx_port_free_stat[64];
2737         char other_port_used_stat[64];
2738
2739         if (init(t, 1, 2) < 0 ||
2740                         create_ports(t, 2) < 0 ||
2741                         create_atomic_qids(t, 1) < 0) {
2742                 printf("%d: Error initializing device\n", __LINE__);
2743                 return -1;
2744         }
2745         int nb_links = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2746         if (rte_event_port_link(evdev, t->port[0], NULL, NULL, 0) != 1 ||
2747                         nb_links != 1) {
2748                 printf("%d: Error links queue to ports\n", __LINE__);
2749                 goto err;
2750         }
2751         if (rte_event_dev_start(evdev) < 0) {
2752                 printf("%d: Error with start call\n", __LINE__);
2753                 goto err;
2754         }
2755
2756         /* send one packet and see where it goes, port 0 or 1 */
2757         if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2758                 printf("%d: Error doing first enqueue\n", __LINE__);
2759                 goto err;
2760         }
2761         rte_event_schedule(evdev);
2762
2763         if (rte_event_dev_xstats_by_name_get(evdev, "port_0_cq_ring_used", NULL)
2764                         != 1)
2765                 rx_port = 1;
2766
2767         snprintf(rx_port_used_stat, sizeof(rx_port_used_stat),
2768                         "port_%u_cq_ring_used", rx_port);
2769         snprintf(rx_port_free_stat, sizeof(rx_port_free_stat),
2770                         "port_%u_cq_ring_free", rx_port);
2771         snprintf(other_port_used_stat, sizeof(other_port_used_stat),
2772                         "port_%u_cq_ring_used", rx_port ^ 1);
2773         if (rte_event_dev_xstats_by_name_get(evdev, rx_port_used_stat, NULL)
2774                         != 1) {
2775                 printf("%d: Error, first event not scheduled\n", __LINE__);
2776                 goto err;
2777         }
2778
2779         /* now fill up the rx port's queue with one flow to cause HOLB */
2780         do {
2781                 ev = new_ev;
2782                 if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2783                         printf("%d: Error with enqueue\n", __LINE__);
2784                         goto err;
2785                 }
2786                 rte_event_schedule(evdev);
2787         } while (rte_event_dev_xstats_by_name_get(evdev,
2788                                 rx_port_free_stat, NULL) != 0);
2789
2790         /* one more packet, which needs to stay in IQ - i.e. HOLB */
2791         ev = new_ev;
2792         if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2793                 printf("%d: Error with enqueue\n", __LINE__);
2794                 goto err;
2795         }
2796         rte_event_schedule(evdev);
2797
2798         /* check that the other port still has an empty CQ */
2799         if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2800                         != 0) {
2801                 printf("%d: Error, second port CQ is not empty\n", __LINE__);
2802                 goto err;
2803         }
2804         /* check IQ now has one packet */
2805         if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2806                         != 1) {
2807                 printf("%d: Error, QID does not have exactly 1 packet\n",
2808                         __LINE__);
2809                 goto err;
2810         }
2811
2812         /* send another flow, which should pass the other IQ entry */
2813         ev = new_ev;
2814         ev.flow_id = 1;
2815         if (rte_event_enqueue_burst(evdev, t->port[0], &ev, 1) != 1) {
2816                 printf("%d: Error with enqueue\n", __LINE__);
2817                 goto err;
2818         }
2819         rte_event_schedule(evdev);
2820
2821         if (rte_event_dev_xstats_by_name_get(evdev, other_port_used_stat, NULL)
2822                         != 1) {
2823                 printf("%d: Error, second flow did not pass out first\n",
2824                         __LINE__);
2825                 goto err;
2826         }
2827
2828         if (rte_event_dev_xstats_by_name_get(evdev, "qid_0_iq_0_used", NULL)
2829                         != 1) {
2830                 printf("%d: Error, QID does not have exactly 1 packet\n",
2831                         __LINE__);
2832                 goto err;
2833         }
2834         cleanup(t);
2835         return 0;
2836 err:
2837         rte_event_dev_dump(evdev, stdout);
2838         cleanup(t);
2839         return -1;
2840 }
2841
2842 static int
2843 worker_loopback_worker_fn(void *arg)
2844 {
2845         struct test *t = arg;
2846         uint8_t port = t->port[1];
2847         int count = 0;
2848         int enqd;
2849
2850         /*
2851          * Takes packets from the input port and then loops them back through
2852          * the Eventdev. Each packet gets looped through QIDs 0-8, 16 times
2853          * so each packet goes through 8*16 = 128 times.
2854          */
2855         printf("%d: \tWorker function started\n", __LINE__);
2856         while (count < NUM_PACKETS) {
2857 #define BURST_SIZE 32
2858                 struct rte_event ev[BURST_SIZE];
2859                 uint16_t i, nb_rx = rte_event_dequeue_burst(evdev, port, ev,
2860                                 BURST_SIZE, 0);
2861                 if (nb_rx == 0) {
2862                         rte_pause();
2863                         continue;
2864                 }
2865
2866                 for (i = 0; i < nb_rx; i++) {
2867                         ev[i].queue_id++;
2868                         if (ev[i].queue_id != 8) {
2869                                 ev[i].op = RTE_EVENT_OP_FORWARD;
2870                                 enqd = rte_event_enqueue_burst(evdev, port,
2871                                                 &ev[i], 1);
2872                                 if (enqd != 1) {
2873                                         printf("%d: Can't enqueue FWD!!\n",
2874                                                         __LINE__);
2875                                         return -1;
2876                                 }
2877                                 continue;
2878                         }
2879
2880                         ev[i].queue_id = 0;
2881                         ev[i].mbuf->udata64++;
2882                         if (ev[i].mbuf->udata64 != 16) {
2883                                 ev[i].op = RTE_EVENT_OP_FORWARD;
2884                                 enqd = rte_event_enqueue_burst(evdev, port,
2885                                                 &ev[i], 1);
2886                                 if (enqd != 1) {
2887                                         printf("%d: Can't enqueue FWD!!\n",
2888                                                         __LINE__);
2889                                         return -1;
2890                                 }
2891                                 continue;
2892                         }
2893                         /* we have hit 16 iterations through system - drop */
2894                         rte_pktmbuf_free(ev[i].mbuf);
2895                         count++;
2896                         ev[i].op = RTE_EVENT_OP_RELEASE;
2897                         enqd = rte_event_enqueue_burst(evdev, port, &ev[i], 1);
2898                         if (enqd != 1) {
2899                                 printf("%d drop enqueue failed\n", __LINE__);
2900                                 return -1;
2901                         }
2902                 }
2903         }
2904
2905         return 0;
2906 }
2907
2908 static int
2909 worker_loopback_producer_fn(void *arg)
2910 {
2911         struct test *t = arg;
2912         uint8_t port = t->port[0];
2913         uint64_t count = 0;
2914
2915         printf("%d: \tProducer function started\n", __LINE__);
2916         while (count < NUM_PACKETS) {
2917                 struct rte_mbuf *m = 0;
2918                 do {
2919                         m = rte_pktmbuf_alloc(t->mbuf_pool);
2920                 } while (m == NULL);
2921
2922                 m->udata64 = 0;
2923
2924                 struct rte_event ev = {
2925                                 .op = RTE_EVENT_OP_NEW,
2926                                 .queue_id = t->qid[0],
2927                                 .flow_id = (uintptr_t)m & 0xFFFF,
2928                                 .mbuf = m,
2929                 };
2930
2931                 if (rte_event_enqueue_burst(evdev, port, &ev, 1) != 1) {
2932                         while (rte_event_enqueue_burst(evdev, port, &ev, 1) !=
2933                                         1)
2934                                 rte_pause();
2935                 }
2936
2937                 count++;
2938         }
2939
2940         return 0;
2941 }
2942
2943 static int
2944 worker_loopback(struct test *t)
2945 {
2946         /* use a single producer core, and a worker core to see what happens
2947          * if the worker loops packets back multiple times
2948          */
2949         struct test_event_dev_stats stats;
2950         uint64_t print_cycles = 0, cycles = 0;
2951         uint64_t tx_pkts = 0;
2952         int err;
2953         int w_lcore, p_lcore;
2954
2955         if (init(t, 8, 2) < 0 ||
2956                         create_atomic_qids(t, 8) < 0) {
2957                 printf("%d: Error initializing device\n", __LINE__);
2958                 return -1;
2959         }
2960
2961         /* RX with low max events */
2962         static struct rte_event_port_conf conf = {
2963                         .dequeue_depth = 32,
2964                         .enqueue_depth = 64,
2965         };
2966         /* beware: this cannot be initialized in the static above as it would
2967          * only be initialized once - and this needs to be set for multiple runs
2968          */
2969         conf.new_event_threshold = 512;
2970
2971         if (rte_event_port_setup(evdev, 0, &conf) < 0) {
2972                 printf("Error setting up RX port\n");
2973                 return -1;
2974         }
2975         t->port[0] = 0;
2976         /* TX with higher max events */
2977         conf.new_event_threshold = 4096;
2978         if (rte_event_port_setup(evdev, 1, &conf) < 0) {
2979                 printf("Error setting up TX port\n");
2980                 return -1;
2981         }
2982         t->port[1] = 1;
2983
2984         /* CQ mapping to QID */
2985         err = rte_event_port_link(evdev, t->port[1], NULL, NULL, 0);
2986         if (err != 8) { /* should have mapped all queues*/
2987                 printf("%d: error mapping port 2 to all qids\n", __LINE__);
2988                 return -1;
2989         }
2990
2991         if (rte_event_dev_start(evdev) < 0) {
2992                 printf("%d: Error with start call\n", __LINE__);
2993                 return -1;
2994         }
2995
2996         p_lcore = rte_get_next_lcore(
2997                         /* start core */ -1,
2998                         /* skip master */ 1,
2999                         /* wrap */ 0);
3000         w_lcore = rte_get_next_lcore(p_lcore, 1, 0);
3001
3002         rte_eal_remote_launch(worker_loopback_producer_fn, t, p_lcore);
3003         rte_eal_remote_launch(worker_loopback_worker_fn, t, w_lcore);
3004
3005         print_cycles = cycles = rte_get_timer_cycles();
3006         while (rte_eal_get_lcore_state(p_lcore) != FINISHED ||
3007                         rte_eal_get_lcore_state(w_lcore) != FINISHED) {
3008
3009                 rte_event_schedule(evdev);
3010
3011                 uint64_t new_cycles = rte_get_timer_cycles();
3012
3013                 if (new_cycles - print_cycles > rte_get_timer_hz()) {
3014                         test_event_dev_stats_get(evdev, &stats);
3015                         printf(
3016                                 "%d: \tSched Rx = %"PRIu64", Tx = %"PRIu64"\n",
3017                                 __LINE__, stats.rx_pkts, stats.tx_pkts);
3018
3019                         print_cycles = new_cycles;
3020                 }
3021                 if (new_cycles - cycles > rte_get_timer_hz() * 3) {
3022                         test_event_dev_stats_get(evdev, &stats);
3023                         if (stats.tx_pkts == tx_pkts) {
3024                                 rte_event_dev_dump(evdev, stdout);
3025                                 printf("Dumping xstats:\n");
3026                                 xstats_print();
3027                                 printf(
3028                                         "%d: No schedules for seconds, deadlock\n",
3029                                         __LINE__);
3030                                 return -1;
3031                         }
3032                         tx_pkts = stats.tx_pkts;
3033                         cycles = new_cycles;
3034                 }
3035         }
3036         rte_event_schedule(evdev); /* ensure all completions are flushed */
3037
3038         rte_eal_mp_wait_lcore();
3039
3040         cleanup(t);
3041         return 0;
3042 }
3043
3044 static struct rte_mempool *eventdev_func_mempool;
3045
3046 static int
3047 test_sw_eventdev(void)
3048 {
3049         struct test *t = malloc(sizeof(struct test));
3050         int ret;
3051
3052         /* manually initialize the op, older gcc's complain on static
3053          * initialization of struct elements that are a bitfield.
3054          */
3055         release_ev.op = RTE_EVENT_OP_RELEASE;
3056
3057         const char *eventdev_name = "event_sw0";
3058         evdev = rte_event_dev_get_dev_id(eventdev_name);
3059         if (evdev < 0) {
3060                 printf("%d: Eventdev %s not found - creating.\n",
3061                                 __LINE__, eventdev_name);
3062                 if (rte_vdev_init(eventdev_name, NULL) < 0) {
3063                         printf("Error creating eventdev\n");
3064                         return -1;
3065                 }
3066                 evdev = rte_event_dev_get_dev_id(eventdev_name);
3067                 if (evdev < 0) {
3068                         printf("Error finding newly created eventdev\n");
3069                         return -1;
3070                 }
3071         }
3072
3073         /* Only create mbuf pool once, reuse for each test run */
3074         if (!eventdev_func_mempool) {
3075                 eventdev_func_mempool = rte_pktmbuf_pool_create(
3076                                 "EVENTDEV_SW_SA_MBUF_POOL",
3077                                 (1<<12), /* 4k buffers */
3078                                 32 /*MBUF_CACHE_SIZE*/,
3079                                 0,
3080                                 512, /* use very small mbufs */
3081                                 rte_socket_id());
3082                 if (!eventdev_func_mempool) {
3083                         printf("ERROR creating mempool\n");
3084                         return -1;
3085                 }
3086         }
3087         t->mbuf_pool = eventdev_func_mempool;
3088         printf("*** Running Single Directed Packet test...\n");
3089         ret = test_single_directed_packet(t);
3090         if (ret != 0) {
3091                 printf("ERROR - Single Directed Packet test FAILED.\n");
3092                 return ret;
3093         }
3094         printf("*** Running Directed Forward Credit test...\n");
3095         ret = test_directed_forward_credits(t);
3096         if (ret != 0) {
3097                 printf("ERROR - Directed Forward Credit test FAILED.\n");
3098                 return ret;
3099         }
3100         printf("*** Running Single Load Balanced Packet test...\n");
3101         ret = single_packet(t);
3102         if (ret != 0) {
3103                 printf("ERROR - Single Packet test FAILED.\n");
3104                 return ret;
3105         }
3106         printf("*** Running Unordered Basic test...\n");
3107         ret = unordered_basic(t);
3108         if (ret != 0) {
3109                 printf("ERROR -  Unordered Basic test FAILED.\n");
3110                 return ret;
3111         }
3112         printf("*** Running Ordered Basic test...\n");
3113         ret = ordered_basic(t);
3114         if (ret != 0) {
3115                 printf("ERROR -  Ordered Basic test FAILED.\n");
3116                 return ret;
3117         }
3118         printf("*** Running Burst Packets test...\n");
3119         ret = burst_packets(t);
3120         if (ret != 0) {
3121                 printf("ERROR - Burst Packets test FAILED.\n");
3122                 return ret;
3123         }
3124         printf("*** Running Load Balancing test...\n");
3125         ret = load_balancing(t);
3126         if (ret != 0) {
3127                 printf("ERROR - Load Balancing test FAILED.\n");
3128                 return ret;
3129         }
3130         printf("*** Running Prioritized Directed test...\n");
3131         ret = test_priority_directed(t);
3132         if (ret != 0) {
3133                 printf("ERROR - Prioritized Directed test FAILED.\n");
3134                 return ret;
3135         }
3136         printf("*** Running Prioritized Atomic test...\n");
3137         ret = test_priority_atomic(t);
3138         if (ret != 0) {
3139                 printf("ERROR - Prioritized Atomic test FAILED.\n");
3140                 return ret;
3141         }
3142
3143         printf("*** Running Prioritized Ordered test...\n");
3144         ret = test_priority_ordered(t);
3145         if (ret != 0) {
3146                 printf("ERROR - Prioritized Ordered test FAILED.\n");
3147                 return ret;
3148         }
3149         printf("*** Running Prioritized Unordered test...\n");
3150         ret = test_priority_unordered(t);
3151         if (ret != 0) {
3152                 printf("ERROR - Prioritized Unordered test FAILED.\n");
3153                 return ret;
3154         }
3155         printf("*** Running Invalid QID test...\n");
3156         ret = invalid_qid(t);
3157         if (ret != 0) {
3158                 printf("ERROR - Invalid QID test FAILED.\n");
3159                 return ret;
3160         }
3161         printf("*** Running Load Balancing History test...\n");
3162         ret = load_balancing_history(t);
3163         if (ret != 0) {
3164                 printf("ERROR - Load Balancing History test FAILED.\n");
3165                 return ret;
3166         }
3167         printf("*** Running Inflight Count test...\n");
3168         ret = inflight_counts(t);
3169         if (ret != 0) {
3170                 printf("ERROR - Inflight Count test FAILED.\n");
3171                 return ret;
3172         }
3173         printf("*** Running Abuse Inflights test...\n");
3174         ret = abuse_inflights(t);
3175         if (ret != 0) {
3176                 printf("ERROR - Abuse Inflights test FAILED.\n");
3177                 return ret;
3178         }
3179         printf("*** Running XStats test...\n");
3180         ret = xstats_tests(t);
3181         if (ret != 0) {
3182                 printf("ERROR - XStats test FAILED.\n");
3183                 return ret;
3184         }
3185         printf("*** Running XStats ID Reset test...\n");
3186         ret = xstats_id_reset_tests(t);
3187         if (ret != 0) {
3188                 printf("ERROR - XStats ID Reset test FAILED.\n");
3189                 return ret;
3190         }
3191         printf("*** Running XStats Brute Force test...\n");
3192         ret = xstats_brute_force(t);
3193         if (ret != 0) {
3194                 printf("ERROR - XStats Brute Force test FAILED.\n");
3195                 return ret;
3196         }
3197         printf("*** Running XStats ID Abuse test...\n");
3198         ret = xstats_id_abuse_tests(t);
3199         if (ret != 0) {
3200                 printf("ERROR - XStats ID Abuse test FAILED.\n");
3201                 return ret;
3202         }
3203         printf("*** Running QID Priority test...\n");
3204         ret = qid_priorities(t);
3205         if (ret != 0) {
3206                 printf("ERROR - QID Priority test FAILED.\n");
3207                 return ret;
3208         }
3209         printf("*** Running Ordered Reconfigure test...\n");
3210         ret = ordered_reconfigure(t);
3211         if (ret != 0) {
3212                 printf("ERROR - Ordered Reconfigure test FAILED.\n");
3213                 return ret;
3214         }
3215         printf("*** Running Port LB Single Reconfig test...\n");
3216         ret = port_single_lb_reconfig(t);
3217         if (ret != 0) {
3218                 printf("ERROR - Port LB Single Reconfig test FAILED.\n");
3219                 return ret;
3220         }
3221         printf("*** Running Port Reconfig Credits test...\n");
3222         ret = port_reconfig_credits(t);
3223         if (ret != 0) {
3224                 printf("ERROR - Port Reconfig Credits Reset test FAILED.\n");
3225                 return ret;
3226         }
3227         printf("*** Running Head-of-line-blocking test...\n");
3228         ret = holb(t);
3229         if (ret != 0) {
3230                 printf("ERROR - Head-of-line-blocking test FAILED.\n");
3231                 return ret;
3232         }
3233         if (rte_lcore_count() >= 3) {
3234                 printf("*** Running Worker loopback test...\n");
3235                 ret = worker_loopback(t);
3236                 if (ret != 0) {
3237                         printf("ERROR - Worker loopback test FAILED.\n");
3238                         return ret;
3239                 }
3240         } else {
3241                 printf("### Not enough cores for worker loopback test.\n");
3242                 printf("### Need at least 3 cores for test.\n");
3243         }
3244         /*
3245          * Free test instance, leaving mempool initialized, and a pointer to it
3246          * in static eventdev_func_mempool, as it is re-used on re-runs
3247          */
3248         free(t);
3249
3250         return 0;
3251 }
3252
3253 REGISTER_TEST_COMMAND(eventdev_sw_autotest, test_sw_eventdev);