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