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