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