Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017 Cavium, Inc
3 : : */
4 : :
5 : : #ifndef _EVT_COMMON_
6 : : #define _EVT_COMMON_
7 : :
8 : : #include <rte_common.h>
9 : : #include <rte_crypto.h>
10 : : #include <rte_debug.h>
11 : : #include <rte_event_crypto_adapter.h>
12 : : #include <rte_eventdev.h>
13 : : #include <rte_service.h>
14 : :
15 : : #define CLNRM "\x1b[0m"
16 : : #define CLRED "\x1b[31m"
17 : : #define CLGRN "\x1b[32m"
18 : : #define CLYEL "\x1b[33m"
19 : :
20 : : #define evt_err(fmt, args...) \
21 : : fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args)
22 : :
23 : : #define evt_info(fmt, args...) \
24 : : fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args)
25 : :
26 : : #define EVT_STR_FMT 20
27 : :
28 : : #define evt_dump(str, fmt, val...) \
29 : : printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val)
30 : :
31 : : #define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)
32 : :
33 : : #define evt_dump_end printf("\b}\n")
34 : :
35 : : #define EVT_MAX_STAGES 64
36 : : #define EVT_MAX_PORTS 256
37 : : #define EVT_MAX_QUEUES 256
38 : :
39 : : enum evt_prod_type {
40 : : EVT_PROD_TYPE_NONE,
41 : : EVT_PROD_TYPE_SYNT, /* Producer type Synthetic i.e. CPU. */
42 : : EVT_PROD_TYPE_ETH_RX_ADPTR, /* Producer type Eth Rx Adapter. */
43 : : EVT_PROD_TYPE_EVENT_TIMER_ADPTR, /* Producer type Timer Adapter. */
44 : : EVT_PROD_TYPE_EVENT_CRYPTO_ADPTR, /* Producer type Crypto Adapter. */
45 : : EVT_PROD_TYPE_MAX,
46 : : };
47 : :
48 : : struct evt_options {
49 : : #define EVT_TEST_NAME_MAX_LEN 32
50 : : #define EVT_CRYPTO_MAX_KEY_SIZE 256
51 : : #define EVT_CRYPTO_MAX_IV_SIZE 16
52 : : char test_name[EVT_TEST_NAME_MAX_LEN];
53 : : bool plcores[RTE_MAX_LCORE];
54 : : bool wlcores[RTE_MAX_LCORE];
55 : : bool crypto_cipher_bit_mode;
56 : : int pool_sz;
57 : : int socket_id;
58 : : int nb_stages;
59 : : int verbose_level;
60 : : uint8_t dev_id;
61 : : uint8_t timdev_cnt;
62 : : uint8_t nb_timer_adptrs;
63 : : uint8_t timdev_use_burst;
64 : : uint8_t per_port_pool;
65 : : uint8_t sched_type_list[EVT_MAX_STAGES];
66 : : uint16_t mbuf_sz;
67 : : uint16_t wkr_deq_dep;
68 : : uint16_t vector_size;
69 : : uint16_t eth_queues;
70 : : uint16_t crypto_cipher_iv_sz;
71 : : uint32_t nb_flows;
72 : : uint32_t tx_first;
73 : : uint16_t tx_pkt_sz;
74 : : uint32_t max_pkt_sz;
75 : : uint32_t prod_enq_burst_sz;
76 : : uint32_t deq_tmo_nsec;
77 : : uint32_t crypto_cipher_key_sz;
78 : : uint32_t q_priority:1;
79 : : uint32_t fwd_latency:1;
80 : : uint32_t ena_vector : 1;
81 : : uint64_t nb_pkts;
82 : : uint64_t nb_timers;
83 : : uint64_t expiry_nsec;
84 : : uint64_t max_tmo_nsec;
85 : : uint64_t vector_tmo_nsec;
86 : : uint64_t timer_tick_nsec;
87 : : uint64_t optm_timer_tick_nsec;
88 : : enum evt_prod_type prod_type;
89 : : enum rte_event_crypto_adapter_mode crypto_adptr_mode;
90 : : enum rte_crypto_op_type crypto_op_type;
91 : : enum rte_crypto_cipher_algorithm crypto_cipher_alg;
92 : : uint8_t crypto_cipher_key[EVT_CRYPTO_MAX_KEY_SIZE];
93 : : };
94 : :
95 : : static inline bool
96 : : evt_has_distributed_sched(uint8_t dev_id)
97 : : {
98 : : struct rte_event_dev_info dev_info;
99 : :
100 : 0 : rte_event_dev_info_get(dev_id, &dev_info);
101 : 0 : return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) ?
102 : 0 : true : false;
103 : : }
104 : :
105 : : static inline bool
106 : : evt_has_burst_mode(uint8_t dev_id)
107 : : {
108 : : struct rte_event_dev_info dev_info;
109 : :
110 : 0 : rte_event_dev_info_get(dev_id, &dev_info);
111 : 0 : return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
112 : 0 : true : false;
113 : : }
114 : :
115 : :
116 : : static inline bool
117 : : evt_has_all_types_queue(uint8_t dev_id)
118 : : {
119 : : struct rte_event_dev_info dev_info;
120 : :
121 : 0 : rte_event_dev_info_get(dev_id, &dev_info);
122 : 0 : return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES) ?
123 : 0 : true : false;
124 : : }
125 : :
126 : : static inline bool
127 : : evt_has_flow_id(uint8_t dev_id)
128 : : {
129 : : struct rte_event_dev_info dev_info;
130 : :
131 : 0 : rte_event_dev_info_get(dev_id, &dev_info);
132 : 0 : return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_CARRY_FLOW_ID) ?
133 : 0 : true : false;
134 : : }
135 : :
136 : : static inline int
137 : 0 : evt_service_setup(uint32_t service_id)
138 : : {
139 : : int32_t core_cnt;
140 : : unsigned int lcore = 0;
141 : : uint32_t core_array[RTE_MAX_LCORE];
142 : : uint8_t cnt;
143 : : uint8_t min_cnt = UINT8_MAX;
144 : :
145 : 0 : if (!rte_service_lcore_count())
146 : : return -ENOENT;
147 : :
148 : 0 : core_cnt = rte_service_lcore_list(core_array,
149 : : RTE_MAX_LCORE);
150 : 0 : if (core_cnt < 0)
151 : : return -ENOENT;
152 : : /* Get the core which has least number of services running. */
153 : 0 : while (core_cnt--) {
154 : : /* Reset default mapping */
155 : 0 : rte_service_map_lcore_set(service_id,
156 : : core_array[core_cnt], 0);
157 : 0 : cnt = rte_service_lcore_count_services(
158 : : core_array[core_cnt]);
159 : 0 : if (cnt < min_cnt) {
160 : 0 : lcore = core_array[core_cnt];
161 : : min_cnt = cnt;
162 : : }
163 : : }
164 : 0 : if (rte_service_map_lcore_set(service_id, lcore, 1))
165 : 0 : return -ENOENT;
166 : :
167 : : return 0;
168 : : }
169 : :
170 : : static inline int
171 : 0 : evt_configure_eventdev(struct evt_options *opt, uint8_t nb_queues,
172 : : uint8_t nb_ports)
173 : : {
174 : : struct rte_event_dev_info info;
175 : : int ret;
176 : :
177 : : memset(&info, 0, sizeof(struct rte_event_dev_info));
178 : 0 : ret = rte_event_dev_info_get(opt->dev_id, &info);
179 : 0 : if (ret) {
180 : 0 : evt_err("failed to get eventdev info %d", opt->dev_id);
181 : 0 : return ret;
182 : : }
183 : :
184 : 0 : if (opt->deq_tmo_nsec) {
185 : 0 : if (opt->deq_tmo_nsec < info.min_dequeue_timeout_ns) {
186 : 0 : opt->deq_tmo_nsec = info.min_dequeue_timeout_ns;
187 : 0 : evt_info("dequeue_timeout_ns too low, using %d",
188 : : opt->deq_tmo_nsec);
189 : : }
190 : 0 : if (opt->deq_tmo_nsec > info.max_dequeue_timeout_ns) {
191 : 0 : opt->deq_tmo_nsec = info.max_dequeue_timeout_ns;
192 : 0 : evt_info("dequeue_timeout_ns too high, using %d",
193 : : opt->deq_tmo_nsec);
194 : : }
195 : : }
196 : :
197 : 0 : const struct rte_event_dev_config config = {
198 : 0 : .dequeue_timeout_ns = opt->deq_tmo_nsec,
199 : : .nb_event_queues = nb_queues,
200 : : .nb_event_ports = nb_ports,
201 : : .nb_single_link_event_port_queues = 0,
202 : 0 : .nb_events_limit = info.max_num_events,
203 : 0 : .nb_event_queue_flows = opt->nb_flows,
204 : : .nb_event_port_dequeue_depth =
205 : 0 : info.max_event_port_dequeue_depth,
206 : : .nb_event_port_enqueue_depth =
207 : 0 : info.max_event_port_enqueue_depth,
208 : : };
209 : :
210 : 0 : return rte_event_dev_configure(opt->dev_id, &config);
211 : : }
212 : :
213 : : #endif /* _EVT_COMMON_*/
|