2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2010-2014 Intel Corporation
11 #include <sys/queue.h>
13 #include <rte_memory.h>
14 #include <rte_memzone.h>
15 #include <rte_launch.h>
17 #include <rte_per_lcore.h>
18 #include <rte_lcore.h>
19 #include <rte_debug.h>
20 #include <rte_ethdev.h>
21 #include <rte_cycles.h>
22 #include <rte_eventdev.h>
23 #include <rte_bus_vdev.h>
24 #include <rte_pause.h>
26 #include "opdl_evdev.h"
32 #define NUM_PACKETS (1<<18)
33 #define NUM_EVENTS 256
41 struct rte_mempool *mbuf_pool;
42 uint8_t port[MAX_PORTS];
43 uint8_t qid[MAX_QIDS];
47 static struct rte_mempool *eventdev_func_mempool;
49 static __rte_always_inline struct rte_mbuf *
50 rte_gen_arp(int portid, struct rte_mempool *mp)
54 * ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
56 static const uint8_t arp_request[] = {
57 /*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8,
58 0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
59 /*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8,
60 0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
61 /*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
62 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 /*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x00
67 int pkt_len = sizeof(arp_request) - 1;
69 m = rte_pktmbuf_alloc(mp);
73 memcpy((void *)((uintptr_t)m->buf_addr + m->data_off),
74 arp_request, pkt_len);
75 rte_pktmbuf_pkt_len(m) = pkt_len;
76 rte_pktmbuf_data_len(m) = pkt_len;
83 /* initialization and config */
84 static __rte_always_inline int
85 init(struct test *t, int nb_queues, int nb_ports)
87 struct rte_event_dev_config config = {
88 .nb_event_queues = nb_queues,
89 .nb_event_ports = nb_ports,
90 .nb_event_queue_flows = 1024,
91 .nb_events_limit = 4096,
92 .nb_event_port_dequeue_depth = 128,
93 .nb_event_port_enqueue_depth = 128,
97 void *temp = t->mbuf_pool; /* save and restore mbuf pool */
99 memset(t, 0, sizeof(*t));
102 ret = rte_event_dev_configure(evdev, &config);
104 PMD_DRV_LOG(ERR, "%d: Error configuring device\n", __LINE__);
108 static __rte_always_inline int
109 create_ports(struct test *t, int num_ports)
112 static const struct rte_event_port_conf conf = {
113 .new_event_threshold = 1024,
117 if (num_ports > MAX_PORTS)
120 for (i = 0; i < num_ports; i++) {
121 if (rte_event_port_setup(evdev, i, &conf) < 0) {
122 PMD_DRV_LOG(ERR, "Error setting up port %d\n", i);
131 static __rte_always_inline int
132 create_queues_type(struct test *t, int num_qids, enum queue_type flags)
138 case OPDL_Q_TYPE_ORDERED:
139 type = RTE_SCHED_TYPE_ORDERED;
141 case OPDL_Q_TYPE_ATOMIC:
142 type = RTE_SCHED_TYPE_ATOMIC;
149 const struct rte_event_queue_conf conf = {
151 (flags == OPDL_Q_TYPE_SINGLE_LINK ?
152 RTE_EVENT_QUEUE_CFG_SINGLE_LINK : 0),
153 .schedule_type = type,
154 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
155 .nb_atomic_flows = 1024,
156 .nb_atomic_order_sequences = 1024,
159 for (i = t->nb_qids ; i < t->nb_qids + num_qids; i++) {
160 if (rte_event_queue_setup(evdev, i, &conf) < 0) {
161 PMD_DRV_LOG(ERR, "%d: error creating qid %d\n ",
168 t->nb_qids += num_qids;
170 if (t->nb_qids > MAX_QIDS)
178 static __rte_always_inline int
179 cleanup(struct test *t __rte_unused)
181 rte_event_dev_stop(evdev);
182 rte_event_dev_close(evdev);
183 PMD_DRV_LOG(ERR, "clean up for test done\n");
188 ordered_basic(struct test *t)
190 const uint8_t rx_port = 0;
191 const uint8_t w1_port = 1;
192 const uint8_t w3_port = 3;
193 const uint8_t tx_port = 4;
197 struct rte_mbuf *mbufs[3];
199 const uint32_t MAGIC_SEQN = 1234;
201 /* Create instance with 5 ports */
202 if (init(t, 2, tx_port+1) < 0 ||
203 create_ports(t, tx_port+1) < 0 ||
204 create_queues_type(t, 2, OPDL_Q_TYPE_ORDERED)) {
205 PMD_DRV_LOG(ERR, "%d: Error initializing device\n", __LINE__);
211 * We need three ports, all mapped to the same ordered qid0. Then we'll
212 * take a packet out to each port, re-enqueue in reverse order,
213 * then make sure the reordering has taken place properly when we
214 * dequeue from the tx_port.
216 * Simplified test setup diagram:
220 * qid0 - w2_port - qid1
224 /* CQ mapping to QID for LB ports (directed mapped on create) */
225 for (i = w1_port; i <= w3_port; i++) {
226 err = rte_event_port_link(evdev, t->port[i], &t->qid[0], NULL,
229 PMD_DRV_LOG(ERR, "%d: error mapping lb qid\n",
236 err = rte_event_port_link(evdev, t->port[tx_port], &t->qid[1], NULL,
239 PMD_DRV_LOG(ERR, "%d: error mapping TX qid\n", __LINE__);
244 if (rte_event_dev_start(evdev) < 0) {
245 PMD_DRV_LOG(ERR, "%d: Error with start call\n", __LINE__);
248 /* Enqueue 3 packets to the rx port */
249 for (i = 0; i < 3; i++) {
251 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
253 PMD_DRV_LOG(ERR, "%d: gen of pkt failed\n", __LINE__);
257 ev.queue_id = t->qid[0];
258 ev.op = RTE_EVENT_OP_NEW;
260 mbufs[i]->seqn = MAGIC_SEQN + i;
262 /* generate pkt and enqueue */
263 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
265 PMD_DRV_LOG(ERR, "%d: Failed to enqueue pkt %u, retval = %u\n",
271 /* use extra slot to make logic in loops easier */
272 struct rte_event deq_ev[w3_port + 1];
276 /* Dequeue the 3 packets, one from each worker port */
277 for (i = w1_port; i <= w3_port; i++) {
278 deq_pkts = rte_event_dequeue_burst(evdev, t->port[i],
281 PMD_DRV_LOG(ERR, "%d: Failed to deq\n", __LINE__);
282 rte_event_dev_dump(evdev, stdout);
285 seq = deq_ev[i].mbuf->seqn - MAGIC_SEQN;
288 PMD_DRV_LOG(ERR, " seq test failed ! eq is %d , "
289 "port number is %u\n", seq, i);
294 /* Enqueue each packet in reverse order, flushing after each one */
295 for (i = w3_port; i >= w1_port; i--) {
297 deq_ev[i].op = RTE_EVENT_OP_FORWARD;
298 deq_ev[i].queue_id = t->qid[1];
299 err = rte_event_enqueue_burst(evdev, t->port[i], &deq_ev[i], 1);
301 PMD_DRV_LOG(ERR, "%d: Failed to enqueue\n", __LINE__);
306 /* dequeue from the tx ports, we should get 3 packets */
307 deq_pkts = rte_event_dequeue_burst(evdev, t->port[tx_port], deq_ev,
310 /* Check to see if we've got all 3 packets */
312 PMD_DRV_LOG(ERR, "%d: expected 3 pkts at tx port got %d from port %d\n",
313 __LINE__, deq_pkts, tx_port);
314 rte_event_dev_dump(evdev, stdout);
318 /* Destroy the instance */
326 atomic_basic(struct test *t)
328 const uint8_t rx_port = 0;
329 const uint8_t w1_port = 1;
330 const uint8_t w3_port = 3;
331 const uint8_t tx_port = 4;
335 struct rte_mbuf *mbufs[3];
336 const uint32_t MAGIC_SEQN = 1234;
338 /* Create instance with 5 ports */
339 if (init(t, 2, tx_port+1) < 0 ||
340 create_ports(t, tx_port+1) < 0 ||
341 create_queues_type(t, 2, OPDL_Q_TYPE_ATOMIC)) {
342 PMD_DRV_LOG(ERR, "%d: Error initializing device\n", __LINE__);
349 * We need three ports, all mapped to the same ordered qid0. Then we'll
350 * take a packet out to each port, re-enqueue in reverse order,
351 * then make sure the reordering has taken place properly when we
352 * dequeue from the tx_port.
354 * Simplified test setup diagram:
358 * qid0 - w2_port - qid1
362 /* CQ mapping to QID for Atomic ports (directed mapped on create) */
363 for (i = w1_port; i <= w3_port; i++) {
364 err = rte_event_port_link(evdev, t->port[i], &t->qid[0], NULL,
367 PMD_DRV_LOG(ERR, "%d: error mapping lb qid\n",
374 err = rte_event_port_link(evdev, t->port[tx_port], &t->qid[1], NULL,
377 PMD_DRV_LOG(ERR, "%d: error mapping TX qid\n", __LINE__);
382 if (rte_event_dev_start(evdev) < 0) {
383 PMD_DRV_LOG(ERR, "%d: Error with start call\n", __LINE__);
387 /* Enqueue 3 packets to the rx port */
388 for (i = 0; i < 3; i++) {
390 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
392 PMD_DRV_LOG(ERR, "%d: gen of pkt failed\n", __LINE__);
396 ev.queue_id = t->qid[0];
397 ev.op = RTE_EVENT_OP_NEW;
400 mbufs[i]->seqn = MAGIC_SEQN + i;
402 /* generate pkt and enqueue */
403 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
405 PMD_DRV_LOG(ERR, "%d: Failed to enqueue pkt %u, retval = %u\n",
411 /* use extra slot to make logic in loops easier */
412 struct rte_event deq_ev[w3_port + 1];
414 /* Dequeue the 3 packets, one from each worker port */
415 for (i = w1_port; i <= w3_port; i++) {
417 deq_pkts = rte_event_dequeue_burst(evdev, t->port[i],
420 if (t->port[i] != 2) {
422 PMD_DRV_LOG(ERR, "%d: deq none zero !\n",
424 rte_event_dev_dump(evdev, stdout);
430 PMD_DRV_LOG(ERR, "%d: deq not eqal to 3 %u !\n",
432 rte_event_dev_dump(evdev, stdout);
437 for (j = 0; j < 3; j++) {
438 deq_ev[j].op = RTE_EVENT_OP_FORWARD;
439 deq_ev[j].queue_id = t->qid[1];
442 err = rte_event_enqueue_burst(evdev, t->port[i],
446 PMD_DRV_LOG(ERR, "port %d: Failed to enqueue pkt %u, "
457 /* dequeue from the tx ports, we should get 3 packets */
458 deq_pkts = rte_event_dequeue_burst(evdev, t->port[tx_port], deq_ev,
461 /* Check to see if we've got all 3 packets */
463 PMD_DRV_LOG(ERR, "%d: expected 3 pkts at tx port got %d from port %d\n",
464 __LINE__, deq_pkts, tx_port);
465 rte_event_dev_dump(evdev, stdout);
473 static __rte_always_inline int
474 check_qid_stats(uint32_t id[], int index)
478 if (id[0] != 3 || id[1] != 3
481 } else if (index == 1) {
482 if (id[0] != 5 || id[1] != 5
485 } else if (index == 2) {
486 if (id[0] != 3 || id[1] != 1
496 check_statistics(void)
498 int num_ports = 3; /* Hard-coded for this app */
501 for (i = 0; i < num_ports; i++) {
502 int num_stats, num_stats_returned;
504 num_stats = rte_event_dev_xstats_names_get(0,
505 RTE_EVENT_DEV_XSTATS_PORT,
512 uint32_t id[num_stats];
513 struct rte_event_dev_xstats_name names[num_stats];
514 uint64_t values[num_stats];
516 num_stats_returned = rte_event_dev_xstats_names_get(0,
517 RTE_EVENT_DEV_XSTATS_PORT,
523 if (num_stats == num_stats_returned) {
524 num_stats_returned = rte_event_dev_xstats_get(0,
525 RTE_EVENT_DEV_XSTATS_PORT,
531 if (num_stats == num_stats_returned) {
534 err = check_qid_stats(id, i);
552 #define OLD_NUM_PACKETS 3
553 #define NEW_NUM_PACKETS 2
555 single_link_w_stats(struct test *t)
557 const uint8_t rx_port = 0;
558 const uint8_t w1_port = 1;
559 const uint8_t tx_port = 2;
563 struct rte_mbuf *mbufs[3];
567 /* Create instance with 3 ports */
568 if (init(t, 2, tx_port + 1) < 0 ||
569 create_ports(t, 3) < 0 || /* 0,1,2 */
570 create_queues_type(t, 1, OPDL_Q_TYPE_SINGLE_LINK) < 0 ||
571 create_queues_type(t, 1, OPDL_Q_TYPE_ORDERED) < 0) {
572 PMD_DRV_LOG(ERR, "%d: Error initializing device\n", __LINE__);
579 * Simplified test setup diagram:
583 * qid0 - w1_port(1) - qid1
588 err = rte_event_port_link(evdev, t->port[1], &t->qid[0], NULL,
591 PMD_DRV_LOG(ERR, "%d: error linking port:[%u] to queue:[%u]\n",
599 err = rte_event_port_link(evdev, t->port[2], &t->qid[1], NULL,
602 PMD_DRV_LOG(ERR, "%d: error linking port:[%u] to queue:[%u]\n",
610 if (rte_event_dev_start(evdev) != 0) {
611 PMD_DRV_LOG(ERR, "%d: failed to start device\n", __LINE__);
617 * Enqueue 3 packets to the rx port
619 for (i = 0; i < 3; i++) {
621 mbufs[i] = rte_gen_arp(0, t->mbuf_pool);
623 PMD_DRV_LOG(ERR, "%d: gen of pkt failed\n", __LINE__);
627 ev.queue_id = t->qid[0];
628 ev.op = RTE_EVENT_OP_NEW;
630 mbufs[i]->seqn = 1234 + i;
632 /* generate pkt and enqueue */
633 err = rte_event_enqueue_burst(evdev, t->port[rx_port], &ev, 1);
635 PMD_DRV_LOG(ERR, "%d: Failed to enqueue pkt %u, retval = %u\n",
643 /* Dequeue the 3 packets, from SINGLE_LINK worker port */
644 struct rte_event deq_ev[3];
646 deq_pkts = rte_event_dequeue_burst(evdev,
651 PMD_DRV_LOG(ERR, "%d: deq not 3 !\n", __LINE__);
656 /* Just enqueue 2 onto new ring */
657 for (i = 0; i < NEW_NUM_PACKETS; i++)
658 deq_ev[i].queue_id = t->qid[1];
660 deq_pkts = rte_event_enqueue_burst(evdev,
666 PMD_DRV_LOG(ERR, "%d: enq not 2 but %u!\n", __LINE__, deq_pkts);
671 /* dequeue from the tx ports, we should get 2 packets */
672 deq_pkts = rte_event_dequeue_burst(evdev,
678 /* Check to see if we've got all 2 packets */
680 PMD_DRV_LOG(ERR, "%d: expected 2 pkts at tx port got %d from port %d\n",
681 __LINE__, deq_pkts, tx_port);
686 if (!check_statistics()) {
687 PMD_DRV_LOG(ERR, "xstats check failed");
698 single_link(struct test *t)
700 /* const uint8_t rx_port = 0; */
701 /* const uint8_t w1_port = 1; */
702 /* const uint8_t w3_port = 3; */
703 const uint8_t tx_port = 2;
706 struct rte_mbuf *mbufs[3];
710 /* Create instance with 5 ports */
711 if (init(t, 2, tx_port+1) < 0 ||
712 create_ports(t, 3) < 0 || /* 0,1,2 */
713 create_queues_type(t, 1, OPDL_Q_TYPE_SINGLE_LINK) < 0 ||
714 create_queues_type(t, 1, OPDL_Q_TYPE_ORDERED) < 0) {
715 PMD_DRV_LOG(ERR, "%d: Error initializing device\n", __LINE__);
722 * Simplified test setup diagram:
726 * qid0 - w1_port(1) - qid1
731 err = rte_event_port_link(evdev, t->port[1], &t->qid[0], NULL,
734 PMD_DRV_LOG(ERR, "%d: error mapping lb qid\n", __LINE__);
739 err = rte_event_port_link(evdev, t->port[2], &t->qid[0], NULL,
742 PMD_DRV_LOG(ERR, "%d: error mapping lb qid\n", __LINE__);
747 if (rte_event_dev_start(evdev) == 0) {
748 PMD_DRV_LOG(ERR, "%d: start DIDN'T FAIL with more than 1 "
749 "SINGLE_LINK PORT\n", __LINE__);
760 static __rte_always_inline void
761 populate_event_burst(struct rte_event ev[],
766 for (i = 0; i < num_events; i++) {
768 ev[i].op = RTE_EVENT_OP_NEW;
769 ev[i].sched_type = RTE_SCHED_TYPE_ORDERED;
770 ev[i].queue_id = qid;
771 ev[i].event_type = RTE_EVENT_TYPE_ETHDEV;
772 ev[i].sub_event_type = 0;
773 ev[i].priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
774 ev[i].mbuf = (struct rte_mbuf *)0xdead0000;
779 #define BATCH_SIZE 32
782 qid_basic(struct test *t)
792 struct rte_event ev[BATCH_SIZE];
794 /* Create instance with 4 ports */
795 if (init(t, NUM_QUEUES, NUM_QUEUES+1) < 0 ||
796 create_ports(t, NUM_QUEUES+1) < 0 ||
797 create_queues_type(t, NUM_QUEUES, OPDL_Q_TYPE_ORDERED)) {
798 PMD_DRV_LOG(ERR, "%d: Error initializing device\n", __LINE__);
802 for (i = 0; i < NUM_QUEUES; i++) {
806 nb_linked = rte_event_port_link(evdev,
807 i+1, /* port = q_id + 1*/
812 if (nb_linked != 1) {
814 PMD_DRV_LOG(ERR, "%s:%d: error mapping port:%u to queue:%u\n",
827 /* Try and link to the same port again */
830 if (rte_event_port_link(evdev,
835 PMD_DRV_LOG(ERR, "%s:%d: Second call to port link on same port DID NOT fail\n",
841 uint32_t test_num_events;
844 test_num_events = rte_event_dequeue_burst(evdev,
849 if (test_num_events != 0) {
850 PMD_DRV_LOG(ERR, "%s:%d: Error dequeuing 0 packets from port %u on stopped device\n",
859 test_num_events = rte_event_enqueue_burst(evdev,
863 if (test_num_events != 0) {
864 PMD_DRV_LOG(ERR, "%s:%d: Error enqueuing 0 packets to port %u on stopped device\n",
874 /* Start the devicea */
876 if (rte_event_dev_start(evdev) < 0) {
877 PMD_DRV_LOG(ERR, "%s:%d: Error with start call\n",
885 /* Check we can't do any more links now that device is started.*/
888 if (rte_event_port_link(evdev,
893 PMD_DRV_LOG(ERR, "%s:%d: Call to port link on started device DID NOT fail\n",
904 populate_event_burst(ev,
908 num_events = rte_event_enqueue_burst(evdev,
912 if (num_events != BATCH_SIZE) {
913 PMD_DRV_LOG(ERR, "%s:%d: Error enqueuing rx packets\n",
921 while (++p_id < NUM_QUEUES) {
923 num_events = rte_event_dequeue_burst(evdev,
929 if (num_events != BATCH_SIZE) {
930 PMD_DRV_LOG(ERR, "%s:%d: Error dequeuing packets from port %u\n",
938 if (ev[0].queue_id != q_id) {
939 PMD_DRV_LOG(ERR, "%s:%d: Error event portid[%u] q_id:[%u] does not match expected:[%u]\n",
949 populate_event_burst(ev,
953 num_events = rte_event_enqueue_burst(evdev,
957 if (num_events != BATCH_SIZE) {
958 PMD_DRV_LOG(ERR, "%s:%d: Error enqueuing packets from port:%u to queue:%u\n",
970 num_events = rte_event_dequeue_burst(evdev,
975 if (num_events != BATCH_SIZE) {
976 PMD_DRV_LOG(ERR, "%s:%d: Error dequeuing packets from tx port %u\n",
994 struct test *t = malloc(sizeof(struct test));
997 const char *eventdev_name = "event_opdl0";
999 evdev = rte_event_dev_get_dev_id(eventdev_name);
1002 PMD_DRV_LOG(ERR, "%d: Eventdev %s not found - creating.\n",
1003 __LINE__, eventdev_name);
1004 /* turn on stats by default */
1005 if (rte_vdev_init(eventdev_name, "do_validation=1") < 0) {
1006 PMD_DRV_LOG(ERR, "Error creating eventdev\n");
1009 evdev = rte_event_dev_get_dev_id(eventdev_name);
1011 PMD_DRV_LOG(ERR, "Error finding newly created eventdev\n");
1016 /* Only create mbuf pool once, reuse for each test run */
1017 if (!eventdev_func_mempool) {
1018 eventdev_func_mempool = rte_pktmbuf_pool_create(
1019 "EVENTDEV_SW_SA_MBUF_POOL",
1020 (1<<12), /* 4k buffers */
1021 32 /*MBUF_CACHE_SIZE*/,
1023 512, /* use very small mbufs */
1025 if (!eventdev_func_mempool) {
1026 PMD_DRV_LOG(ERR, "ERROR creating mempool\n");
1030 t->mbuf_pool = eventdev_func_mempool;
1032 PMD_DRV_LOG(ERR, "*** Running Ordered Basic test...\n");
1033 ret = ordered_basic(t);
1035 PMD_DRV_LOG(ERR, "*** Running Atomic Basic test...\n");
1036 ret = atomic_basic(t);
1039 PMD_DRV_LOG(ERR, "*** Running QID Basic test...\n");
1042 PMD_DRV_LOG(ERR, "*** Running SINGLE LINK failure test...\n");
1043 ret = single_link(t);
1045 PMD_DRV_LOG(ERR, "*** Running SINGLE LINK w stats test...\n");
1046 ret = single_link_w_stats(t);
1049 * Free test instance, leaving mempool initialized, and a pointer to it
1050 * in static eventdev_func_mempool, as it is re-used on re-runs