b9ef778c1a8b462c3e6dcae9a411002e80c1252a
[dpdk.git] / drivers / event / dlb / dlb_selftest.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdint.h>
8 #include <errno.h>
9 #include <unistd.h>
10 #include <sys/queue.h>
11
12 #include <rte_memory.h>
13 #include <rte_memzone.h>
14 #include <rte_launch.h>
15 #include <rte_eal.h>
16 #include <rte_lcore.h>
17 #include <rte_debug.h>
18 #include <rte_cycles.h>
19 #include <rte_eventdev.h>
20 #include <rte_mempool.h>
21 #include <rte_mbuf.h>
22
23 #include "dlb_priv.h"
24 #include "rte_pmd_dlb.h"
25
26 #define MAX_PORTS 32
27 #define MAX_QIDS 32
28 #define DEFAULT_NUM_SEQ_NUMS 32
29
30 static struct rte_mempool *eventdev_func_mempool;
31 static int evdev;
32
33 struct test {
34         struct rte_mempool *mbuf_pool;
35         int nb_qids;
36 };
37
38 /* initialization and config */
39 static inline int
40 init(struct test *t, int nb_queues, int nb_ports)
41 {
42         struct rte_event_dev_config config = {0};
43         struct rte_event_dev_info info;
44         int ret;
45
46         memset(t, 0, sizeof(*t));
47
48         t->mbuf_pool = eventdev_func_mempool;
49
50         if (rte_event_dev_info_get(evdev, &info)) {
51                 printf("%d: Error querying device info\n", __LINE__);
52                 return -1;
53         }
54
55         config.nb_event_queues = nb_queues;
56         config.nb_event_ports = nb_ports;
57         config.nb_event_queue_flows = info.max_event_queue_flows;
58         config.nb_events_limit = info.max_num_events;
59         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
60         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
61         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
62         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
63
64         ret = rte_event_dev_configure(evdev, &config);
65         if (ret < 0)
66                 printf("%d: Error configuring device\n", __LINE__);
67
68         return ret;
69 }
70
71 static inline int
72 create_ports(int num_ports)
73 {
74         int i;
75
76         if (num_ports > MAX_PORTS)
77                 return -1;
78
79         for (i = 0; i < num_ports; i++) {
80                 struct rte_event_port_conf conf;
81
82                 if (rte_event_port_default_conf_get(evdev, i, &conf)) {
83                         printf("%d: Error querying default port conf\n",
84                                __LINE__);
85                         return -1;
86                 }
87
88                 if (rte_event_port_setup(evdev, i, &conf) < 0) {
89                         printf("%d: Error setting up port %d\n", __LINE__, i);
90                         return -1;
91                 }
92         }
93
94         return 0;
95 }
96
97 static inline int
98 create_lb_qids(struct test *t, int num_qids, uint32_t flags)
99 {
100         int i;
101
102         for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
103                 struct rte_event_queue_conf conf;
104
105                 if (rte_event_queue_default_conf_get(evdev, i, &conf)) {
106                         printf("%d: Error querying default queue conf\n",
107                                __LINE__);
108                         return -1;
109                 }
110
111                 conf.schedule_type = flags;
112
113                 if (conf.schedule_type == RTE_SCHED_TYPE_PARALLEL)
114                         conf.nb_atomic_order_sequences = 0;
115                 else
116                         conf.nb_atomic_order_sequences = DEFAULT_NUM_SEQ_NUMS;
117
118                 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
119                         printf("%d: error creating qid %d\n", __LINE__, i);
120                         return -1;
121                 }
122         }
123
124         t->nb_qids += num_qids;
125         if (t->nb_qids > MAX_QIDS)
126                 return -1;
127
128         return 0;
129 }
130
131 static inline int
132 create_atomic_qids(struct test *t, int num_qids)
133 {
134         return create_lb_qids(t, num_qids, RTE_SCHED_TYPE_ATOMIC);
135 }
136
137 /* destruction */
138 static inline int
139 cleanup(void)
140 {
141         rte_event_dev_stop(evdev);
142         return rte_event_dev_close(evdev);
143 };
144
145 static inline int
146 enqueue_timeout(uint8_t port_id, struct rte_event *ev, uint64_t tmo_us)
147 {
148         const uint64_t start = rte_get_timer_cycles();
149         const uint64_t ticks = (tmo_us * rte_get_timer_hz()) / 1E6;
150
151         while ((rte_get_timer_cycles() - start) < ticks) {
152                 if (rte_event_enqueue_burst(evdev, port_id, ev, 1) == 1)
153                         return 0;
154
155                 if (rte_errno != -ENOSPC)
156                         return -1;
157         }
158
159         return -1;
160 }
161
162 static void
163 flush(uint8_t id __rte_unused, struct rte_event event, void *arg __rte_unused)
164 {
165         rte_pktmbuf_free(event.mbuf);
166 }
167
168 static int
169 test_stop_flush(struct test *t) /* test to check we can properly flush events */
170 {
171         struct rte_event ev;
172         uint32_t dequeue_depth;
173         unsigned int i, count;
174         uint8_t queue_id;
175
176         ev.op = RTE_EVENT_OP_NEW;
177
178         if (init(t, 2, 1) < 0 ||
179             create_ports(1) < 0 ||
180             create_atomic_qids(t, 2) < 0) {
181                 printf("%d: Error initializing device\n", __LINE__);
182                 return -1;
183         }
184
185         if (rte_event_port_link(evdev, 0, NULL, NULL, 0) != 2) {
186                 printf("%d: Error linking queues to the port\n", __LINE__);
187                 goto err;
188         }
189
190         if (rte_event_dev_start(evdev) < 0) {
191                 printf("%d: Error with start call\n", __LINE__);
192                 goto err;
193         }
194
195         /* Unlink queue 1 so the PMD's stop callback has to cleanup an unlinked
196          * queue.
197          */
198         queue_id = 1;
199
200         if (rte_event_port_unlink(evdev, 0, &queue_id, 1) != 1) {
201                 printf("%d: Error unlinking queue 1 from port\n", __LINE__);
202                 goto err;
203         }
204
205         count = rte_mempool_avail_count(t->mbuf_pool);
206
207         if (rte_event_port_attr_get(evdev,
208                                     0,
209                                     RTE_EVENT_PORT_ATTR_DEQ_DEPTH,
210                                     &dequeue_depth)) {
211                 printf("%d: Error retrieveing dequeue depth\n", __LINE__);
212                 goto err;
213         }
214
215         /* Send QEs to queue 0 */
216         for (i = 0; i < dequeue_depth + 1; i++) {
217                 ev.mbuf = rte_pktmbuf_alloc(t->mbuf_pool);
218                 ev.queue_id = 0;
219                 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
220
221                 if (enqueue_timeout(0, &ev, 1000)) {
222                         printf("%d: Error enqueuing events\n", __LINE__);
223                         goto err;
224                 }
225         }
226
227         /* Send QEs to queue 1 */
228         for (i = 0; i < dequeue_depth + 1; i++) {
229                 ev.mbuf = rte_pktmbuf_alloc(t->mbuf_pool);
230                 ev.queue_id = 1;
231                 ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
232
233                 if (enqueue_timeout(0, &ev, 1000)) {
234                         printf("%d: Error enqueuing events\n", __LINE__);
235                         goto err;
236                 }
237         }
238
239         /* Now the DLB is scheduling events from the port to the IQ, and at
240          * least one event should be remaining in each queue.
241          */
242
243         if (rte_event_dev_stop_flush_callback_register(evdev, flush, NULL)) {
244                 printf("%d: Error installing the flush callback\n", __LINE__);
245                 goto err;
246         }
247
248         cleanup();
249
250         if (count != rte_mempool_avail_count(t->mbuf_pool)) {
251                 printf("%d: Error executing the flush callback\n", __LINE__);
252                 goto err;
253         }
254
255         if (rte_event_dev_stop_flush_callback_register(evdev, NULL, NULL)) {
256                 printf("%d: Error uninstalling the flush callback\n", __LINE__);
257                 goto err;
258         }
259
260         return 0;
261 err:
262         cleanup();
263         return -1;
264 }
265
266 static int
267 test_single_link(void)
268 {
269         struct rte_event_dev_config config = {0};
270         struct rte_event_queue_conf queue_conf;
271         struct rte_event_port_conf port_conf;
272         struct rte_event_dev_info info;
273         uint8_t queue_id;
274         int ret;
275
276         if (rte_event_dev_info_get(evdev, &info)) {
277                 printf("%d: Error querying device info\n", __LINE__);
278                 return -1;
279         }
280
281         config.nb_event_queues = 2;
282         config.nb_event_ports = 2;
283         config.nb_single_link_event_port_queues = 1;
284         config.nb_event_queue_flows = info.max_event_queue_flows;
285         config.nb_events_limit = info.max_num_events;
286         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
287         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
288         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
289         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
290
291         ret = rte_event_dev_configure(evdev, &config);
292         if (ret < 0) {
293                 printf("%d: Error configuring device\n", __LINE__);
294                 return -1;
295         }
296
297         /* Create a directed port */
298         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
299                 printf("%d: Error querying default port conf\n", __LINE__);
300                 goto err;
301         }
302
303         port_conf.event_port_cfg = RTE_EVENT_PORT_CFG_SINGLE_LINK;
304
305         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
306                 printf("%d: port 0 setup expected to succeed\n", __LINE__);
307                 goto err;
308         }
309
310         /* Attempt to create another directed port */
311         if (rte_event_port_setup(evdev, 1, &port_conf) == 0) {
312                 printf("%d: port 1 setup expected to fail\n", __LINE__);
313                 goto err;
314         }
315
316         port_conf.event_port_cfg = 0;
317
318         /* Create a load-balanced port */
319         if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
320                 printf("%d: port 1 setup expected to succeed\n", __LINE__);
321                 goto err;
322         }
323
324         /* Create a directed queue */
325         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
326                 printf("%d: Error querying default queue conf\n", __LINE__);
327                 goto err;
328         }
329
330         queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
331
332         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
333                 printf("%d: queue 0 setup expected to succeed\n", __LINE__);
334                 goto err;
335         }
336
337         /* Attempt to create another directed queue */
338         if (rte_event_queue_setup(evdev, 1, &queue_conf) == 0) {
339                 printf("%d: queue 1 setup expected to fail\n", __LINE__);
340                 goto err;
341         }
342
343         /* Create a load-balanced queue */
344         queue_conf.event_queue_cfg = 0;
345
346         if (rte_event_queue_setup(evdev, 1, &queue_conf) < 0) {
347                 printf("%d: queue 1 setup expected to succeed\n", __LINE__);
348                 goto err;
349         }
350
351         /* Attempt to link directed and load-balanced resources */
352         queue_id = 1;
353         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) == 1) {
354                 printf("%d: port 0 link expected to fail\n", __LINE__);
355                 goto err;
356         }
357
358         queue_id = 0;
359         if (rte_event_port_link(evdev, 1, &queue_id, NULL, 1) == 1) {
360                 printf("%d: port 1 link expected to fail\n", __LINE__);
361                 goto err;
362         }
363
364         /* Link ports to queues */
365         queue_id = 0;
366         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
367                 printf("%d: port 0 link expected to succeed\n", __LINE__);
368                 goto err;
369         }
370
371         queue_id = 1;
372         if (rte_event_port_link(evdev, 1, &queue_id, NULL, 1) != 1) {
373                 printf("%d: port 1 link expected to succeed\n", __LINE__);
374                 goto err;
375         }
376
377         return rte_event_dev_close(evdev);
378
379 err:
380         rte_event_dev_close(evdev);
381         return -1;
382 }
383
384 #define NUM_LDB_PORTS 64
385 #define NUM_LDB_QUEUES 128
386
387 static int
388 test_info_get(void)
389 {
390         struct rte_event_dev_config config = {0};
391         struct rte_event_dev_info info;
392         int ret;
393
394         if (rte_event_dev_info_get(evdev, &info)) {
395                 printf("%d: Error querying device info\n", __LINE__);
396                 return -1;
397         }
398
399         if (info.max_event_ports != NUM_LDB_PORTS) {
400                 printf("%d: Got %u ports, expected %u\n",
401                        __LINE__, info.max_event_ports, NUM_LDB_PORTS);
402                 goto err;
403         }
404
405         if (info.max_event_queues != NUM_LDB_QUEUES) {
406                 printf("%d: Got %u queues, expected %u\n",
407                        __LINE__, info.max_event_queues, NUM_LDB_QUEUES);
408                 goto err;
409         }
410
411         config.nb_event_ports = info.max_event_ports;
412         config.nb_event_queues = NUM_LDB_QUEUES + info.max_event_ports / 2;
413         config.nb_single_link_event_port_queues = info.max_event_ports / 2;
414         config.nb_event_queue_flows = info.max_event_queue_flows;
415         config.nb_events_limit = info.max_num_events;
416         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
417         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
418         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
419         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
420
421         ret = rte_event_dev_configure(evdev, &config);
422         if (ret < 0) {
423                 printf("%d: Error configuring device\n", __LINE__);
424                 return -1;
425         }
426
427         if (rte_event_dev_info_get(evdev, &info)) {
428                 printf("%d: Error querying device info\n", __LINE__);
429                 goto err;
430         }
431
432         /* The DLB PMD only reports load-balanced ports and queues in its
433          * info_get function. Confirm that these values don't include the
434          * directed port or queue counts.
435          */
436
437         if (info.max_event_ports != NUM_LDB_PORTS) {
438                 printf("%d: Got %u ports, expected %u\n",
439                        __LINE__, info.max_event_ports, NUM_LDB_PORTS);
440                 goto err;
441         }
442
443         if (info.max_event_queues != NUM_LDB_QUEUES) {
444                 printf("%d: Got %u queues, expected %u\n",
445                        __LINE__, info.max_event_queues, NUM_LDB_QUEUES);
446                 goto err;
447         }
448
449         ret = rte_event_dev_close(evdev);
450         if (ret) {
451                 printf("rte_event_dev_close err %d\n", ret);
452                 goto err;
453         }
454
455         return 0;
456
457 err:
458         rte_event_dev_close(evdev);
459         return -1;
460 }
461
462 static int
463 test_reconfiguration_link(void)
464 {
465         struct rte_event_dev_config config = {0};
466         struct rte_event_queue_conf queue_conf;
467         struct rte_event_port_conf port_conf;
468         struct rte_event_dev_info info;
469         uint8_t queue_id;
470         int ret, i;
471
472         if (rte_event_dev_info_get(evdev, &info)) {
473                 printf("%d: Error querying device info\n", __LINE__);
474                 return -1;
475         }
476
477         config.nb_event_queues = 2;
478         config.nb_event_ports = 2;
479         config.nb_single_link_event_port_queues = 0;
480         config.nb_event_queue_flows = info.max_event_queue_flows;
481         config.nb_events_limit = info.max_num_events;
482         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
483         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
484         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
485         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
486
487         /* Configure the device with 2 LDB ports and 2 LDB queues */
488         ret = rte_event_dev_configure(evdev, &config);
489         if (ret < 0) {
490                 printf("%d: Error configuring device\n", __LINE__);
491                 return -1;
492         }
493
494         /* Configure the ports and queues */
495         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
496                 printf("%d: Error querying default port conf\n", __LINE__);
497                 goto err;
498         }
499
500         for (i = 0; i < 2; i++) {
501                 if (rte_event_port_setup(evdev, i, &port_conf) < 0) {
502                         printf("%d: port %d setup expected to succeed\n",
503                                __LINE__, i);
504                         goto err;
505                 }
506         }
507
508         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
509                 printf("%d: Error querying default queue conf\n", __LINE__);
510                 goto err;
511         }
512
513         for (i = 0; i < 2; i++) {
514                 if (rte_event_queue_setup(evdev, i, &queue_conf) < 0) {
515                         printf("%d: queue %d setup expected to succeed\n",
516                                __LINE__, i);
517                         goto err;
518                 }
519         }
520
521         /* Link P0->Q0 and P1->Q1 */
522         for (i = 0; i < 2; i++) {
523                 queue_id = i;
524
525                 if (rte_event_port_link(evdev, i, &queue_id, NULL, 1) != 1) {
526                         printf("%d: port %d link expected to succeed\n",
527                                __LINE__, i);
528                         goto err;
529                 }
530         }
531
532         /* Start the device */
533         if (rte_event_dev_start(evdev) < 0) {
534                 printf("%d: device start failed\n", __LINE__);
535                 goto err;
536         }
537
538         /* Stop the device */
539         rte_event_dev_stop(evdev);
540
541         /* Reconfigure device */
542         ret = rte_event_dev_configure(evdev, &config);
543         if (ret < 0) {
544                 printf("%d: Error re-configuring device\n", __LINE__);
545                 return -1;
546         }
547
548         /* Configure P1 and Q1, leave P0 and Q0 to be configured by the PMD. */
549         if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
550                 printf("%d: port 1 setup expected to succeed\n",
551                        __LINE__);
552                 goto err;
553         }
554
555         if (rte_event_queue_setup(evdev, 1, &queue_conf) < 0) {
556                 printf("%d: queue 1 setup expected to succeed\n",
557                        __LINE__);
558                 goto err;
559         }
560
561         /* Link P0->Q0 and Q1 */
562         for (i = 0; i < 2; i++) {
563                 queue_id = i;
564
565                 if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
566                         printf("%d: P0->Q%d link expected to succeed\n",
567                                __LINE__, i);
568                         goto err;
569                 }
570         }
571
572         /* Link P1->Q0 and Q1 */
573         for (i = 0; i < 2; i++) {
574                 queue_id = i;
575
576                 if (rte_event_port_link(evdev, 1, &queue_id, NULL, 1) != 1) {
577                         printf("%d: P1->Q%d link expected to succeed\n",
578                                __LINE__, i);
579                         goto err;
580                 }
581         }
582
583         /* Start the device */
584         if (rte_event_dev_start(evdev) < 0) {
585                 printf("%d: device start failed\n", __LINE__);
586                 goto err;
587         }
588
589         /* Stop the device */
590         rte_event_dev_stop(evdev);
591
592         /* Configure device with 2 DIR ports and 2 DIR queues */
593         config.nb_single_link_event_port_queues = 2;
594
595         ret = rte_event_dev_configure(evdev, &config);
596         if (ret < 0) {
597                 printf("%d: Error configuring device\n", __LINE__);
598                 return -1;
599         }
600
601         /* Configure the ports and queues */
602         port_conf.event_port_cfg = RTE_EVENT_PORT_CFG_SINGLE_LINK;
603
604         for (i = 0; i < 2; i++) {
605                 if (rte_event_port_setup(evdev, i, &port_conf) < 0) {
606                         printf("%d: port %d setup expected to succeed\n",
607                                __LINE__, i);
608                         goto err;
609                 }
610         }
611
612         queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
613
614         for (i = 0; i < 2; i++) {
615                 if (rte_event_queue_setup(evdev, i, &queue_conf) < 0) {
616                         printf("%d: queue %d setup expected to succeed\n",
617                                __LINE__, i);
618                         goto err;
619                 }
620         }
621
622         /* Link P0->Q0 and P1->Q1 */
623         for (i = 0; i < 2; i++) {
624                 queue_id = i;
625
626                 if (rte_event_port_link(evdev, i, &queue_id, NULL, 1) != 1) {
627                         printf("%d: port %d link expected to succeed\n",
628                                __LINE__, i);
629                         goto err;
630                 }
631         }
632
633         /* Start the device */
634         if (rte_event_dev_start(evdev) < 0) {
635                 printf("%d: device start failed\n", __LINE__);
636                 goto err;
637         }
638
639         /* Stop the device */
640         rte_event_dev_stop(evdev);
641
642         /* Reconfigure device */
643         ret = rte_event_dev_configure(evdev, &config);
644         if (ret < 0) {
645                 printf("%d: Error re-configuring device\n", __LINE__);
646                 return -1;
647         }
648
649         /* Configure P1 and Q0, leave P0 and Q1 to be configured by the PMD. */
650         if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
651                 printf("%d: port 1 setup expected to succeed\n",
652                        __LINE__);
653                 goto err;
654         }
655
656         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
657                 printf("%d: queue 1 setup expected to succeed\n",
658                        __LINE__);
659                 goto err;
660         }
661
662         /* Link P0->Q1 */
663         queue_id = 1;
664
665         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
666                 printf("%d: P0->Q%d link expected to succeed\n",
667                        __LINE__, i);
668                 goto err;
669         }
670
671         /* Link P1->Q0 */
672         queue_id = 0;
673
674         if (rte_event_port_link(evdev, 1, &queue_id, NULL, 1) != 1) {
675                 printf("%d: P1->Q%d link expected to succeed\n",
676                        __LINE__, i);
677                 goto err;
678         }
679
680         /* Start the device */
681         if (rte_event_dev_start(evdev) < 0) {
682                 printf("%d: device start failed\n", __LINE__);
683                 goto err;
684         }
685
686         rte_event_dev_stop(evdev);
687
688         config.nb_event_queues = 5;
689         config.nb_event_ports = 5;
690         config.nb_single_link_event_port_queues = 1;
691
692         ret = rte_event_dev_configure(evdev, &config);
693         if (ret < 0) {
694                 printf("%d: Error re-configuring device\n", __LINE__);
695                 return -1;
696         }
697
698         for (i = 0; i < config.nb_event_queues - 1; i++) {
699                 port_conf.event_port_cfg = 0;
700                 queue_conf.event_queue_cfg = 0;
701
702                 if (rte_event_port_setup(evdev, i, &port_conf) < 0) {
703                         printf("%d: port %d setup expected to succeed\n",
704                                __LINE__, i);
705                         goto err;
706                 }
707
708                 if (rte_event_queue_setup(evdev, i, &queue_conf) < 0) {
709                         printf("%d: queue %d setup expected to succeed\n",
710                                __LINE__, i);
711                         goto err;
712                 }
713
714                 queue_id = i;
715
716                 if (rte_event_port_link(evdev, i, &queue_id, NULL, 1) != 1) {
717                         printf("%d: P%d->Q%d link expected to succeed\n",
718                                __LINE__, i, i);
719                         goto err;
720                 }
721         }
722
723         port_conf.event_port_cfg = RTE_EVENT_PORT_CFG_SINGLE_LINK;
724         queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
725
726         if (rte_event_port_setup(evdev, i, &port_conf) < 0) {
727                 printf("%d: port %d setup expected to succeed\n",
728                        __LINE__, i);
729                 goto err;
730         }
731
732         if (rte_event_queue_setup(evdev, i, &queue_conf) < 0) {
733                 printf("%d: queue %d setup expected to succeed\n",
734                        __LINE__, i);
735                 goto err;
736         }
737
738         queue_id = i;
739
740         if (rte_event_port_link(evdev, i, &queue_id, NULL, 1) != 1) {
741                 printf("%d: P%d->Q%d link expected to succeed\n",
742                        __LINE__, i, i);
743                 goto err;
744         }
745
746         /* Start the device */
747         if (rte_event_dev_start(evdev) < 0) {
748                 printf("%d: device start failed\n", __LINE__);
749                 goto err;
750         }
751
752         /* Stop the device */
753         rte_event_dev_stop(evdev);
754
755         config.nb_event_ports += 1;
756
757         /* Reconfigure device with 1 more load-balanced port */
758         ret = rte_event_dev_configure(evdev, &config);
759         if (ret < 0) {
760                 printf("%d: Error re-configuring device\n", __LINE__);
761                 return -1;
762         }
763
764         port_conf.event_port_cfg = 0;
765
766         /* Configure the new port */
767         if (rte_event_port_setup(evdev, config.nb_event_ports - 1,
768                                  &port_conf) < 0) {
769                 printf("%d: port 1 setup expected to succeed\n",
770                        __LINE__);
771                 goto err;
772         }
773
774         /* Start the device */
775         if (rte_event_dev_start(evdev) < 0) {
776                 printf("%d: device start failed\n", __LINE__);
777                 goto err;
778         }
779
780         cleanup();
781         return 0;
782
783 err:
784         cleanup();
785         return -1;
786 }
787
788 static int
789 test_load_balanced_traffic(void)
790 {
791         uint64_t timeout;
792         struct rte_event_dev_config config = {0};
793         struct rte_event_queue_conf queue_conf;
794         struct rte_event_port_conf port_conf;
795         struct rte_event_dev_info info;
796         struct rte_event ev;
797         uint8_t queue_id;
798         int ret;
799
800         if (rte_event_dev_info_get(evdev, &info)) {
801                 printf("%d: Error querying device info\n", __LINE__);
802                 return -1;
803         }
804
805         config.nb_event_queues = 1;
806         config.nb_event_ports = 1;
807         config.nb_single_link_event_port_queues = 0;
808         config.nb_event_queue_flows = info.max_event_queue_flows;
809         config.nb_events_limit = info.max_num_events;
810         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
811         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
812         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
813         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
814
815         /* Configure the device with 1 LDB port and queue */
816         ret = rte_event_dev_configure(evdev, &config);
817         if (ret < 0) {
818                 printf("%d: Error configuring device\n", __LINE__);
819                 return -1;
820         }
821
822         /* Configure the ports and queues */
823         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
824                 printf("%d: Error querying default port conf\n", __LINE__);
825                 goto err;
826         }
827
828         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
829                 printf("%d: port 0 setup expected to succeed\n",
830                        __LINE__);
831                 goto err;
832         }
833
834         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
835                 printf("%d: Error querying default queue conf\n", __LINE__);
836                 goto err;
837         }
838
839         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
840                 printf("%d: queue 0 setup expected to succeed\n",
841                        __LINE__);
842                 goto err;
843         }
844
845         /* Link P0->Q0 */
846         queue_id = 0;
847
848         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
849                 printf("%d: port 0 link expected to succeed\n",
850                        __LINE__);
851                 goto err;
852         }
853
854         /* Start the device */
855         if (rte_event_dev_start(evdev) < 0) {
856                 printf("%d: device start failed\n", __LINE__);
857                 goto err;
858         }
859
860         /* Enqueue 1 NEW event */
861         ev.op = RTE_EVENT_OP_NEW;
862         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
863         ev.queue_id = 0;
864         ev.priority = 0;
865         ev.u64 = 0;
866
867         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
868                 printf("%d: NEW enqueue expected to succeed\n",
869                        __LINE__);
870                 goto err;
871         }
872
873         /* Dequeue and enqueue 1 FORWARD event */
874         timeout = 0xFFFFFFFFF;
875         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
876                 printf("%d: event dequeue expected to succeed\n",
877                        __LINE__);
878                 goto err;
879         }
880
881         ev.op = RTE_EVENT_OP_FORWARD;
882
883         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
884                 printf("%d: NEW enqueue expected to succeed\n",
885                        __LINE__);
886                 goto err;
887         }
888
889         /* Dequeue and enqueue 1 RELEASE operation */
890         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
891                 printf("%d: event dequeue expected to succeed\n",
892                        __LINE__);
893                 goto err;
894         }
895
896         ev.op = RTE_EVENT_OP_RELEASE;
897
898         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
899                 printf("%d: NEW enqueue expected to succeed\n",
900                        __LINE__);
901                 goto err;
902         }
903
904         cleanup();
905         return 0;
906
907 err:
908         cleanup();
909         return -1;
910 }
911
912 static int
913 test_directed_traffic(void)
914 {
915         uint64_t timeout;
916         struct rte_event_dev_config config = {0};
917         struct rte_event_queue_conf queue_conf;
918         struct rte_event_port_conf port_conf;
919         struct rte_event_dev_info info;
920         struct rte_event ev;
921         uint8_t queue_id;
922         int ret;
923
924         if (rte_event_dev_info_get(evdev, &info)) {
925                 printf("%d: Error querying device info\n", __LINE__);
926                 return -1;
927         }
928
929         config.nb_event_queues = 1;
930         config.nb_event_ports = 1;
931         config.nb_single_link_event_port_queues = 1;
932         config.nb_event_queue_flows = info.max_event_queue_flows;
933         config.nb_events_limit = info.max_num_events;
934         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
935         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
936         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
937         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
938
939         /* Configure the device with 1 DIR port and queue */
940         ret = rte_event_dev_configure(evdev, &config);
941         if (ret < 0) {
942                 printf("%d: Error configuring device\n", __LINE__);
943                 return -1;
944         }
945
946         /* Configure the ports and queues */
947         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
948                 printf("%d: Error querying default port conf\n", __LINE__);
949                 goto err;
950         }
951
952         port_conf.event_port_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
953
954         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
955                 printf("%d: port 0 setup expected to succeed\n",
956                        __LINE__);
957                 goto err;
958         }
959
960         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
961                 printf("%d: Error querying default queue conf\n", __LINE__);
962                 goto err;
963         }
964
965         queue_conf.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
966
967         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
968                 printf("%d: queue 0 setup expected to succeed\n",
969                        __LINE__);
970                 goto err;
971         }
972
973         /* Link P0->Q0 */
974         queue_id = 0;
975
976         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
977                 printf("%d: port 0 link expected to succeed\n",
978                        __LINE__);
979                 goto err;
980         }
981
982         /* Start the device */
983         if (rte_event_dev_start(evdev) < 0) {
984                 printf("%d: device start failed\n", __LINE__);
985                 goto err;
986         }
987
988         /* Enqueue 1 NEW event */
989         ev.op = RTE_EVENT_OP_NEW;
990         ev.queue_id = 0;
991         ev.priority = 0;
992         ev.u64 = 0;
993
994         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
995                 printf("%d: NEW enqueue expected to succeed\n",
996                        __LINE__);
997                 goto err;
998         }
999
1000         /* Dequeue and enqueue 1 FORWARD event */
1001         timeout = 0xFFFFFFFFF;
1002         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1003                 printf("%d: event dequeue expected to succeed\n",
1004                        __LINE__);
1005                 goto err;
1006         }
1007
1008         if (ev.queue_id != 0) {
1009                 printf("%d: invalid dequeued event queue ID (%d)\n",
1010                        __LINE__, ev.queue_id);
1011                 goto err;
1012         }
1013
1014         ev.op = RTE_EVENT_OP_FORWARD;
1015
1016         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1017                 printf("%d: NEW enqueue expected to succeed\n",
1018                        __LINE__);
1019                 goto err;
1020         }
1021
1022         /* Dequeue and enqueue 1 RELEASE operation */
1023         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1024                 printf("%d: event dequeue expected to succeed\n",
1025                        __LINE__);
1026                 goto err;
1027         }
1028
1029         ev.op = RTE_EVENT_OP_RELEASE;
1030
1031         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1032                 printf("%d: NEW enqueue expected to succeed\n",
1033                        __LINE__);
1034                 goto err;
1035         }
1036
1037         cleanup();
1038         return 0;
1039
1040 err:
1041         cleanup();
1042         return -1;
1043 }
1044
1045 static int
1046 test_deferred_sched(void)
1047 {
1048         uint64_t timeout;
1049         struct rte_event_dev_config config = {0};
1050         struct rte_event_queue_conf queue_conf;
1051         struct rte_event_port_conf port_conf;
1052         struct rte_event_dev_info info;
1053         const int num_events = 128;
1054         struct rte_event ev;
1055         uint8_t queue_id;
1056         int ret, i;
1057
1058         if (rte_event_dev_info_get(evdev, &info)) {
1059                 printf("%d: Error querying device info\n", __LINE__);
1060                 return -1;
1061         }
1062
1063         config.nb_event_queues = 1;
1064         config.nb_event_ports = 2;
1065         config.nb_single_link_event_port_queues = 0;
1066         config.nb_event_queue_flows = info.max_event_queue_flows;
1067         config.nb_events_limit = info.max_num_events;
1068         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
1069         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
1070         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
1071         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
1072
1073         /* Configure the device with 2 LDB ports and 1 queue */
1074         ret = rte_event_dev_configure(evdev, &config);
1075         if (ret < 0) {
1076                 printf("%d: Error configuring device\n", __LINE__);
1077                 return -1;
1078         }
1079
1080         ret = rte_pmd_dlb_set_token_pop_mode(evdev, 0, DEFERRED_POP);
1081         if (ret < 0) {
1082                 printf("%d: Error setting deferred scheduling\n", __LINE__);
1083                 goto err;
1084         }
1085
1086         ret = rte_pmd_dlb_set_token_pop_mode(evdev, 1, DEFERRED_POP);
1087         if (ret < 0) {
1088                 printf("%d: Error setting deferred scheduling\n", __LINE__);
1089                 goto err;
1090         }
1091
1092         /* Configure the ports and queues */
1093         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
1094                 printf("%d: Error querying default port conf\n", __LINE__);
1095                 goto err;
1096         }
1097
1098         port_conf.dequeue_depth = 1;
1099
1100         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1101                 printf("%d: port 0 setup expected to succeed\n",
1102                        __LINE__);
1103                 goto err;
1104         }
1105
1106         if (rte_event_port_setup(evdev, 1, &port_conf) < 0) {
1107                 printf("%d: port 1 setup expected to succeed\n",
1108                        __LINE__);
1109                 goto err;
1110         }
1111
1112         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
1113                 printf("%d: Error querying default queue conf\n", __LINE__);
1114                 goto err;
1115         }
1116
1117         queue_conf.schedule_type = RTE_SCHED_TYPE_PARALLEL;
1118         queue_conf.nb_atomic_order_sequences = 0;
1119
1120         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
1121                 printf("%d: queue 0 setup expected to succeed\n",
1122                        __LINE__);
1123                 goto err;
1124         }
1125
1126         /* Link P0->Q0 and P1->Q0 */
1127         queue_id = 0;
1128
1129         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1130                 printf("%d: port 0 link expected to succeed\n",
1131                        __LINE__);
1132                 goto err;
1133         }
1134
1135         if (rte_event_port_link(evdev, 1, &queue_id, NULL, 1) != 1) {
1136                 printf("%d: port 1 link expected to succeed\n",
1137                        __LINE__);
1138                 goto err;
1139         }
1140
1141         /* Start the device */
1142         if (rte_event_dev_start(evdev) < 0) {
1143                 printf("%d: device start failed\n", __LINE__);
1144                 goto err;
1145         }
1146
1147         /* Enqueue 128 NEW events */
1148         ev.op = RTE_EVENT_OP_NEW;
1149         ev.sched_type = RTE_SCHED_TYPE_PARALLEL;
1150         ev.queue_id = 0;
1151         ev.priority = 0;
1152         ev.u64 = 0;
1153
1154         for (i = 0; i < num_events; i++) {
1155                 if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1156                         printf("%d: NEW enqueue expected to succeed\n",
1157                                __LINE__);
1158                         goto err;
1159                 }
1160         }
1161
1162         /* Dequeue two events from port 0 (dequeue_depth * 2 due to the
1163          * reserved token scheme)
1164          */
1165         timeout = 0xFFFFFFFFF;
1166         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1167                 printf("%d: event dequeue expected to succeed\n",
1168                        __LINE__);
1169                 goto err;
1170         }
1171
1172         if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1173                 printf("%d: event dequeue expected to succeed\n",
1174                        __LINE__);
1175                 goto err;
1176         }
1177
1178         /* Dequeue (and release) all other events from port 1. Deferred
1179          * scheduling ensures no other events are scheduled to port 0 without a
1180          * subsequent rte_event_dequeue_burst() call.
1181          */
1182         for (i = 0; i < num_events - 2; i++) {
1183                 if (rte_event_dequeue_burst(evdev, 1, &ev, 1, timeout) != 1) {
1184                         printf("%d: event dequeue expected to succeed\n",
1185                                __LINE__);
1186                         goto err;
1187                 }
1188
1189                 ev.op = RTE_EVENT_OP_RELEASE;
1190
1191                 if (rte_event_enqueue_burst(evdev, 1, &ev, 1) != 1) {
1192                         printf("%d: RELEASE enqueue expected to succeed\n",
1193                                __LINE__);
1194                         goto err;
1195                 }
1196         }
1197
1198         cleanup();
1199         return 0;
1200
1201 err:
1202         cleanup();
1203         return -1;
1204 }
1205
1206 static int
1207 test_delayed_pop(void)
1208 {
1209         uint64_t timeout;
1210         struct rte_event_dev_config config = {0};
1211         struct rte_event_queue_conf queue_conf;
1212         struct rte_event_port_conf port_conf;
1213         struct rte_event_dev_info info;
1214         int ret, i, num_events;
1215         struct rte_event ev;
1216         uint8_t queue_id;
1217
1218         if (rte_event_dev_info_get(evdev, &info)) {
1219                 printf("%d: Error querying device info\n", __LINE__);
1220                 return -1;
1221         }
1222
1223         config.nb_event_queues = 1;
1224         config.nb_event_ports = 1;
1225         config.nb_single_link_event_port_queues = 0;
1226         config.nb_event_queue_flows = info.max_event_queue_flows;
1227         config.nb_events_limit = info.max_num_events;
1228         config.nb_event_port_dequeue_depth = info.max_event_port_dequeue_depth;
1229         config.nb_event_port_enqueue_depth = info.max_event_port_enqueue_depth;
1230         config.dequeue_timeout_ns = info.max_dequeue_timeout_ns;
1231         config.event_dev_cfg = RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT;
1232
1233         /* Configure the device with 1 LDB port and queue */
1234         ret = rte_event_dev_configure(evdev, &config);
1235         if (ret < 0) {
1236                 printf("%d: Error configuring device\n", __LINE__);
1237                 return -1;
1238         }
1239
1240         ret = rte_pmd_dlb_set_token_pop_mode(evdev, 0, DELAYED_POP);
1241         if (ret < 0) {
1242                 printf("%d: Error setting deferred scheduling\n", __LINE__);
1243                 goto err;
1244         }
1245
1246         /* Configure the ports and queues */
1247         if (rte_event_port_default_conf_get(evdev, 0, &port_conf)) {
1248                 printf("%d: Error querying default port conf\n", __LINE__);
1249                 goto err;
1250         }
1251
1252         port_conf.dequeue_depth = 16;
1253         port_conf.event_port_cfg = RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL;
1254
1255         if (rte_event_port_setup(evdev, 0, &port_conf) < 0) {
1256                 printf("%d: port 0 setup expected to succeed\n",
1257                        __LINE__);
1258                 goto err;
1259         }
1260
1261         if (rte_event_queue_default_conf_get(evdev, 0, &queue_conf)) {
1262                 printf("%d: Error querying default queue conf\n", __LINE__);
1263                 goto err;
1264         }
1265
1266         if (rte_event_queue_setup(evdev, 0, &queue_conf) < 0) {
1267                 printf("%d: queue 0 setup expected to succeed\n",
1268                        __LINE__);
1269                 goto err;
1270         }
1271
1272         /* Link P0->Q0 */
1273         queue_id = 0;
1274
1275         if (rte_event_port_link(evdev, 0, &queue_id, NULL, 1) != 1) {
1276                 printf("%d: port 0 link expected to succeed\n",
1277                        __LINE__);
1278                 goto err;
1279         }
1280
1281         /* Start the device */
1282         if (rte_event_dev_start(evdev) < 0) {
1283                 printf("%d: device start failed\n", __LINE__);
1284                 goto err;
1285         }
1286
1287         num_events = 2 * port_conf.dequeue_depth;
1288
1289         /* Enqueue 2 * dequeue_depth NEW events. Due to the PMD's reserved
1290          * token scheme, the port will initially behave as though its
1291          * dequeue_depth is twice the requested size.
1292          */
1293         ev.op = RTE_EVENT_OP_NEW;
1294         ev.sched_type = RTE_SCHED_TYPE_PARALLEL;
1295         ev.queue_id = 0;
1296         ev.priority = 0;
1297         ev.u64 = 0;
1298
1299         for (i = 0; i < num_events; i++) {
1300                 if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1301                         printf("%d: NEW enqueue expected to succeed\n",
1302                                __LINE__);
1303                         goto err;
1304                 }
1305         }
1306
1307         /* Flush these events out of the CQ */
1308         timeout = 0xFFFFFFFFF;
1309
1310         for (i = 0; i < num_events; i++) {
1311                 if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1312                         printf("%d: event dequeue expected to succeed\n",
1313                                __LINE__);
1314                         goto err;
1315                 }
1316         }
1317
1318         ev.op = RTE_EVENT_OP_RELEASE;
1319
1320         for (i = 0; i < num_events; i++) {
1321                 if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1322                         printf("%d: RELEASE enqueue expected to succeed\n",
1323                                __LINE__);
1324                         goto err;
1325                 }
1326         }
1327
1328         /* Enqueue 2 * dequeue_depth NEW events again */
1329         ev.op = RTE_EVENT_OP_NEW;
1330         ev.sched_type = RTE_SCHED_TYPE_ATOMIC;
1331         ev.queue_id = 0;
1332         ev.priority = 0;
1333         ev.u64 = 0;
1334
1335         for (i = 0; i < num_events; i++) {
1336                 if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1337                         printf("%d: NEW enqueue expected to succeed\n",
1338                                __LINE__);
1339                         goto err;
1340                 }
1341         }
1342
1343         /* Dequeue dequeue_depth events but only release dequeue_depth - 1.
1344          * Delayed pop won't perform the pop and no more events will be
1345          * scheduled.
1346          */
1347         for (i = 0; i < port_conf.dequeue_depth; i++) {
1348                 if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1349                         printf("%d: event dequeue expected to succeed\n",
1350                                __LINE__);
1351                         goto err;
1352                 }
1353         }
1354
1355         ev.op = RTE_EVENT_OP_RELEASE;
1356
1357         for (i = 0; i < port_conf.dequeue_depth - 1; i++) {
1358                 if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1359                         printf("%d: RELEASE enqueue expected to succeed\n",
1360                                __LINE__);
1361                         goto err;
1362                 }
1363         }
1364
1365         timeout = 0x10000;
1366
1367         ret = rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout);
1368         if (ret != 0) {
1369                 printf("%d: event dequeue expected to fail (ret = %d)\n",
1370                        __LINE__, ret);
1371                 goto err;
1372         }
1373
1374         /* Release one more event. This will trigger the token pop, and
1375          * another batch of events will be scheduled to the device.
1376          */
1377         ev.op = RTE_EVENT_OP_RELEASE;
1378
1379         if (rte_event_enqueue_burst(evdev, 0, &ev, 1) != 1) {
1380                 printf("%d: RELEASE enqueue expected to succeed\n",
1381                        __LINE__);
1382                 goto err;
1383         }
1384
1385         timeout = 0xFFFFFFFFF;
1386
1387         for (i = 0; i < port_conf.dequeue_depth; i++) {
1388                 if (rte_event_dequeue_burst(evdev, 0, &ev, 1, timeout) != 1) {
1389                         printf("%d: event dequeue expected to succeed\n",
1390                                __LINE__);
1391                         goto err;
1392                 }
1393         }
1394
1395         cleanup();
1396         return 0;
1397
1398 err:
1399         cleanup();
1400         return -1;
1401 }
1402
1403 static int
1404 do_selftest(void)
1405 {
1406         struct test t;
1407         int ret;
1408
1409         /* Only create mbuf pool once, reuse for each test run */
1410         if (!eventdev_func_mempool) {
1411                 eventdev_func_mempool =
1412                         rte_pktmbuf_pool_create("EVENTDEV_DLB_SA_MBUF_POOL",
1413                                                 (1 << 12), /* 4k buffers */
1414                                                 32 /*MBUF_CACHE_SIZE*/,
1415                                                 0,
1416                                                 512, /* use very small mbufs */
1417                                                 rte_socket_id());
1418                 if (!eventdev_func_mempool) {
1419                         printf("ERROR creating mempool\n");
1420                         goto test_fail;
1421                 }
1422         }
1423         t.mbuf_pool = eventdev_func_mempool;
1424
1425         printf("*** Running Stop Flush test...\n");
1426         ret = test_stop_flush(&t);
1427         if (ret != 0) {
1428                 printf("ERROR - Stop Flush test FAILED.\n");
1429                 return ret;
1430         }
1431
1432         printf("*** Running Single Link test...\n");
1433         ret = test_single_link();
1434         if (ret != 0) {
1435                 printf("ERROR - Single Link test FAILED.\n");
1436
1437                 goto test_fail;
1438         }
1439
1440         printf("*** Running Info Get test...\n");
1441         ret = test_info_get();
1442         if (ret != 0) {
1443                 printf("ERROR - Stop Flush test FAILED.\n");
1444                 return ret;
1445         }
1446
1447         printf("*** Running Reconfiguration Link test...\n");
1448         ret = test_reconfiguration_link();
1449         if (ret != 0) {
1450                 printf("ERROR - Reconfiguration Link test FAILED.\n");
1451
1452                 goto test_fail;
1453         }
1454
1455         printf("*** Running Load-Balanced Traffic test...\n");
1456         ret = test_load_balanced_traffic();
1457         if (ret != 0) {
1458                 printf("ERROR - Load-Balanced Traffic test FAILED.\n");
1459
1460                 goto test_fail;
1461         }
1462
1463         printf("*** Running Directed Traffic test...\n");
1464         ret = test_directed_traffic();
1465         if (ret != 0) {
1466                 printf("ERROR - Directed Traffic test FAILED.\n");
1467
1468                 goto test_fail;
1469         }
1470
1471         printf("*** Running Deferred Scheduling test...\n");
1472         ret = test_deferred_sched();
1473         if (ret != 0) {
1474                 printf("ERROR - Deferred Scheduling test FAILED.\n");
1475
1476                 goto test_fail;
1477         }
1478
1479         printf("*** Running Delayed Pop test...\n");
1480         ret = test_delayed_pop();
1481         if (ret != 0) {
1482                 printf("ERROR - Delayed Pop test FAILED.\n");
1483
1484                 goto test_fail;
1485         }
1486
1487         return 0;
1488
1489 test_fail:
1490         return -1;
1491 }
1492
1493 int
1494 test_dlb_eventdev(void)
1495 {
1496         const char *dlb_eventdev_name = "dlb_event";
1497         uint8_t num_evdevs = rte_event_dev_count();
1498         int i, ret = 0;
1499         int found = 0, skipped = 0, passed = 0, failed = 0;
1500         struct rte_event_dev_info info;
1501
1502         for (i = 0; found + skipped < num_evdevs && i < RTE_EVENT_MAX_DEVS;
1503              i++) {
1504                 ret = rte_event_dev_info_get(i, &info);
1505                 if (ret < 0)
1506                         continue;
1507
1508                 /* skip non-dlb event devices */
1509                 if (strncmp(info.driver_name, dlb_eventdev_name,
1510                             sizeof(*info.driver_name)) != 0) {
1511                         skipped++;
1512                         continue;
1513                 }
1514
1515                 evdev = rte_event_dev_get_dev_id(info.driver_name);
1516                 if (evdev < 0) {
1517                         printf("Could not get dev_id for eventdev with name %s, i=%d\n",
1518                                info.driver_name, i);
1519                         skipped++;
1520                         continue;
1521                 }
1522                 found++;
1523                 printf("Running selftest on eventdev %s\n", info.driver_name);
1524                 ret = do_selftest();
1525                 if (ret == 0) {
1526                         passed++;
1527                         printf("Selftest passed for eventdev %s\n",
1528                                info.driver_name);
1529                 } else {
1530                         failed++;
1531                         printf("Selftest failed for eventdev %s, err=%d\n",
1532                                info.driver_name, ret);
1533                 }
1534         }
1535
1536         printf("Ran selftest on %d eventdevs, %d skipped, %d passed, %d failed\n",
1537                found, skipped, passed, failed);
1538         return ret;
1539 }