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