1d1f59fb7SJerin Jacob /*
2d1f59fb7SJerin Jacob  *   BSD LICENSE
3d1f59fb7SJerin Jacob  *
4d1f59fb7SJerin Jacob  *   Copyright (C) Cavium 2017.
5d1f59fb7SJerin Jacob  *
6d1f59fb7SJerin Jacob  *   Redistribution and use in source and binary forms, with or without
7d1f59fb7SJerin Jacob  *   modification, are permitted provided that the following conditions
8d1f59fb7SJerin Jacob  *   are met:
9d1f59fb7SJerin Jacob  *
10d1f59fb7SJerin Jacob  *     * Redistributions of source code must retain the above copyright
11d1f59fb7SJerin Jacob  *       notice, this list of conditions and the following disclaimer.
12d1f59fb7SJerin Jacob  *     * Redistributions in binary form must reproduce the above copyright
13d1f59fb7SJerin Jacob  *       notice, this list of conditions and the following disclaimer in
14d1f59fb7SJerin Jacob  *       the documentation and/or other materials provided with the
15d1f59fb7SJerin Jacob  *       distribution.
16d1f59fb7SJerin Jacob  *     * Neither the name of Cavium networks nor the names of its
17d1f59fb7SJerin Jacob  *       contributors may be used to endorse or promote products derived
18d1f59fb7SJerin Jacob  *       from this software without specific prior written permission.
19d1f59fb7SJerin Jacob  *
20d1f59fb7SJerin Jacob  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21d1f59fb7SJerin Jacob  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22d1f59fb7SJerin Jacob  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23d1f59fb7SJerin Jacob  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24d1f59fb7SJerin Jacob  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25d1f59fb7SJerin Jacob  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26d1f59fb7SJerin Jacob  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27d1f59fb7SJerin Jacob  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28d1f59fb7SJerin Jacob  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29d1f59fb7SJerin Jacob  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30d1f59fb7SJerin Jacob  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31d1f59fb7SJerin Jacob  */
32d1f59fb7SJerin Jacob 
33d1f59fb7SJerin Jacob #ifndef _TEST_ORDER_COMMON_
34d1f59fb7SJerin Jacob #define _TEST_ORDER_COMMON_
35d1f59fb7SJerin Jacob 
36d1f59fb7SJerin Jacob #include <stdio.h>
37d1f59fb7SJerin Jacob #include <stdbool.h>
38d1f59fb7SJerin Jacob 
39d1f59fb7SJerin Jacob #include <rte_cycles.h>
40d1f59fb7SJerin Jacob #include <rte_eventdev.h>
41d1f59fb7SJerin Jacob #include <rte_lcore.h>
42d1f59fb7SJerin Jacob #include <rte_malloc.h>
43d1f59fb7SJerin Jacob #include <rte_mbuf.h>
44d1f59fb7SJerin Jacob 
45d1f59fb7SJerin Jacob #include "evt_common.h"
46d1f59fb7SJerin Jacob #include "evt_options.h"
47d1f59fb7SJerin Jacob #include "evt_test.h"
48d1f59fb7SJerin Jacob 
49d1f59fb7SJerin Jacob #define BURST_SIZE 16
50d1f59fb7SJerin Jacob 
51d1f59fb7SJerin Jacob struct test_order;
52d1f59fb7SJerin Jacob 
53d1f59fb7SJerin Jacob struct worker_data {
54d1f59fb7SJerin Jacob 	uint8_t dev_id;
55d1f59fb7SJerin Jacob 	uint8_t port_id;
56d1f59fb7SJerin Jacob 	struct test_order *t;
57d1f59fb7SJerin Jacob };
58d1f59fb7SJerin Jacob 
59d1f59fb7SJerin Jacob struct prod_data {
60d1f59fb7SJerin Jacob 	uint8_t dev_id;
61d1f59fb7SJerin Jacob 	uint8_t port_id;
62d1f59fb7SJerin Jacob 	uint8_t queue_id;
63d1f59fb7SJerin Jacob 	struct test_order *t;
64d1f59fb7SJerin Jacob };
65d1f59fb7SJerin Jacob 
66d1f59fb7SJerin Jacob struct test_order {
67d1f59fb7SJerin Jacob 	/* Don't change the offset of "err". Signal handler use this memory
68d1f59fb7SJerin Jacob 	 * to terminate all lcores work.
69d1f59fb7SJerin Jacob 	 */
70d1f59fb7SJerin Jacob 	int err;
71d1f59fb7SJerin Jacob 	/*
72d1f59fb7SJerin Jacob 	 * The atomic_* is an expensive operation,Since it is a functional test,
73d1f59fb7SJerin Jacob 	 * We are using the atomic_ operation to reduce the code complexity.
74d1f59fb7SJerin Jacob 	 */
75d1f59fb7SJerin Jacob 	rte_atomic64_t outstand_pkts;
76d1f59fb7SJerin Jacob 	enum evt_test_result result;
77d1f59fb7SJerin Jacob 	uint32_t nb_flows;
78d1f59fb7SJerin Jacob 	uint64_t nb_pkts;
79d1f59fb7SJerin Jacob 	struct rte_mempool *pool;
80d1f59fb7SJerin Jacob 	struct prod_data prod;
81d1f59fb7SJerin Jacob 	struct worker_data worker[EVT_MAX_PORTS];
82d1f59fb7SJerin Jacob 	uint32_t *producer_flow_seq;
83d1f59fb7SJerin Jacob 	uint32_t *expected_flow_seq;
84d1f59fb7SJerin Jacob 	struct evt_options *opt;
85d1f59fb7SJerin Jacob } __rte_cache_aligned;
86d1f59fb7SJerin Jacob 
87ba11ebf1SJerin Jacob static inline int
88ba11ebf1SJerin Jacob order_nb_event_ports(struct evt_options *opt)
89ba11ebf1SJerin Jacob {
90ba11ebf1SJerin Jacob 	return evt_nr_active_lcores(opt->wlcores) + 1 /* producer */;
91ba11ebf1SJerin Jacob }
92ba11ebf1SJerin Jacob 
93ba11ebf1SJerin Jacob int order_test_result(struct evt_test *test, struct evt_options *opt);
94ba11ebf1SJerin Jacob int order_opt_check(struct evt_options *opt);
95d1f59fb7SJerin Jacob int order_test_setup(struct evt_test *test, struct evt_options *opt);
96ba11ebf1SJerin Jacob int order_mempool_setup(struct evt_test *test, struct evt_options *opt);
97*33b7483dSJerin Jacob int order_launch_lcores(struct evt_test *test, struct evt_options *opt,
98*33b7483dSJerin Jacob 			int (*worker)(void *));
995710e751SJerin Jacob int order_event_dev_port_setup(struct evt_test *test, struct evt_options *opt,
1005710e751SJerin Jacob 				uint8_t nb_workers, uint8_t nb_queues);
101d1f59fb7SJerin Jacob void order_test_destroy(struct evt_test *test, struct evt_options *opt);
102ba11ebf1SJerin Jacob void order_opt_dump(struct evt_options *opt);
103ba11ebf1SJerin Jacob void order_mempool_destroy(struct evt_test *test, struct evt_options *opt);
104ba11ebf1SJerin Jacob void order_eventdev_destroy(struct evt_test *test, struct evt_options *opt);
105d1f59fb7SJerin Jacob 
106d1f59fb7SJerin Jacob #endif /* _TEST_ORDER_COMMON_ */
107