]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/examples/ip_pipeline/pipeline_be.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / examples / ip_pipeline / pipeline_be.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef __INCLUDE_PIPELINE_BE_H__
35 #define __INCLUDE_PIPELINE_BE_H__
36
37 #include <rte_port_ethdev.h>
38 #include <rte_port_ring.h>
39 #include <rte_port_frag.h>
40 #include <rte_port_ras.h>
41 #include <rte_port_sched.h>
42 #include <rte_port_fd.h>
43 #include <rte_port_source_sink.h>
44 #ifdef RTE_LIBRTE_KNI
45 #include <rte_port_kni.h>
46 #endif
47 #include <rte_pipeline.h>
48
49 enum pipeline_port_in_type {
50 PIPELINE_PORT_IN_ETHDEV_READER,
51 PIPELINE_PORT_IN_RING_READER,
52 PIPELINE_PORT_IN_RING_MULTI_READER,
53 PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
54 PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
55 PIPELINE_PORT_IN_SCHED_READER,
56 PIPELINE_PORT_IN_FD_READER,
57 PIPELINE_PORT_IN_KNI_READER,
58 PIPELINE_PORT_IN_SOURCE,
59 };
60
61 struct pipeline_port_in_params {
62 enum pipeline_port_in_type type;
63 union {
64 struct rte_port_ethdev_reader_params ethdev;
65 struct rte_port_ring_reader_params ring;
66 struct rte_port_ring_multi_reader_params ring_multi;
67 struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
68 struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
69 struct rte_port_sched_reader_params sched;
70 struct rte_port_fd_reader_params fd;
71 #ifdef RTE_LIBRTE_KNI
72 struct rte_port_kni_reader_params kni;
73 #endif
74 struct rte_port_source_params source;
75 } params;
76 uint32_t burst_size;
77 };
78
79 static inline void *
80 pipeline_port_in_params_convert(struct pipeline_port_in_params *p)
81 {
82 switch (p->type) {
83 case PIPELINE_PORT_IN_ETHDEV_READER:
84 return (void *) &p->params.ethdev;
85 case PIPELINE_PORT_IN_RING_READER:
86 return (void *) &p->params.ring;
87 case PIPELINE_PORT_IN_RING_MULTI_READER:
88 return (void *) &p->params.ring_multi;
89 case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
90 return (void *) &p->params.ring_ipv4_frag;
91 case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
92 return (void *) &p->params.ring_ipv6_frag;
93 case PIPELINE_PORT_IN_SCHED_READER:
94 return (void *) &p->params.sched;
95 case PIPELINE_PORT_IN_FD_READER:
96 return (void *) &p->params.fd;
97 #ifdef RTE_LIBRTE_KNI
98 case PIPELINE_PORT_IN_KNI_READER:
99 return (void *) &p->params.kni;
100 #endif
101 case PIPELINE_PORT_IN_SOURCE:
102 return (void *) &p->params.source;
103 default:
104 return NULL;
105 }
106 }
107
108 static inline struct rte_port_in_ops *
109 pipeline_port_in_params_get_ops(struct pipeline_port_in_params *p)
110 {
111 switch (p->type) {
112 case PIPELINE_PORT_IN_ETHDEV_READER:
113 return &rte_port_ethdev_reader_ops;
114 case PIPELINE_PORT_IN_RING_READER:
115 return &rte_port_ring_reader_ops;
116 case PIPELINE_PORT_IN_RING_MULTI_READER:
117 return &rte_port_ring_multi_reader_ops;
118 case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
119 return &rte_port_ring_reader_ipv4_frag_ops;
120 case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
121 return &rte_port_ring_reader_ipv6_frag_ops;
122 case PIPELINE_PORT_IN_SCHED_READER:
123 return &rte_port_sched_reader_ops;
124 case PIPELINE_PORT_IN_FD_READER:
125 return &rte_port_fd_reader_ops;
126 #ifdef RTE_LIBRTE_KNI
127 case PIPELINE_PORT_IN_KNI_READER:
128 return &rte_port_kni_reader_ops;
129 #endif
130 case PIPELINE_PORT_IN_SOURCE:
131 return &rte_port_source_ops;
132 default:
133 return NULL;
134 }
135 }
136
137 enum pipeline_port_out_type {
138 PIPELINE_PORT_OUT_ETHDEV_WRITER,
139 PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP,
140 PIPELINE_PORT_OUT_RING_WRITER,
141 PIPELINE_PORT_OUT_RING_MULTI_WRITER,
142 PIPELINE_PORT_OUT_RING_WRITER_NODROP,
143 PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP,
144 PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
145 PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
146 PIPELINE_PORT_OUT_SCHED_WRITER,
147 PIPELINE_PORT_OUT_FD_WRITER,
148 PIPELINE_PORT_OUT_KNI_WRITER,
149 PIPELINE_PORT_OUT_KNI_WRITER_NODROP,
150 PIPELINE_PORT_OUT_SINK,
151 };
152
153 struct pipeline_port_out_params {
154 enum pipeline_port_out_type type;
155 union {
156 struct rte_port_ethdev_writer_params ethdev;
157 struct rte_port_ethdev_writer_nodrop_params ethdev_nodrop;
158 struct rte_port_ring_writer_params ring;
159 struct rte_port_ring_multi_writer_params ring_multi;
160 struct rte_port_ring_writer_nodrop_params ring_nodrop;
161 struct rte_port_ring_multi_writer_nodrop_params ring_multi_nodrop;
162 struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
163 struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
164 struct rte_port_sched_writer_params sched;
165 struct rte_port_fd_writer_params fd;
166 #ifdef RTE_LIBRTE_KNI
167 struct rte_port_kni_writer_params kni;
168 struct rte_port_kni_writer_nodrop_params kni_nodrop;
169 #endif
170 struct rte_port_sink_params sink;
171 } params;
172 };
173
174 static inline void *
175 pipeline_port_out_params_convert(struct pipeline_port_out_params *p)
176 {
177 switch (p->type) {
178 case PIPELINE_PORT_OUT_ETHDEV_WRITER:
179 return (void *) &p->params.ethdev;
180 case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
181 return (void *) &p->params.ethdev_nodrop;
182 case PIPELINE_PORT_OUT_RING_WRITER:
183 return (void *) &p->params.ring;
184 case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
185 return (void *) &p->params.ring_multi;
186 case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
187 return (void *) &p->params.ring_nodrop;
188 case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
189 return (void *) &p->params.ring_multi_nodrop;
190 case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
191 return (void *) &p->params.ring_ipv4_ras;
192 case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
193 return (void *) &p->params.ring_ipv6_ras;
194 case PIPELINE_PORT_OUT_SCHED_WRITER:
195 return (void *) &p->params.sched;
196 case PIPELINE_PORT_OUT_FD_WRITER:
197 return (void *) &p->params.fd;
198 #ifdef RTE_LIBRTE_KNI
199 case PIPELINE_PORT_OUT_KNI_WRITER:
200 return (void *) &p->params.kni;
201 case PIPELINE_PORT_OUT_KNI_WRITER_NODROP:
202 return (void *) &p->params.kni_nodrop;
203 #endif
204 case PIPELINE_PORT_OUT_SINK:
205 return (void *) &p->params.sink;
206 default:
207 return NULL;
208 }
209 }
210
211 static inline void *
212 pipeline_port_out_params_get_ops(struct pipeline_port_out_params *p)
213 {
214 switch (p->type) {
215 case PIPELINE_PORT_OUT_ETHDEV_WRITER:
216 return &rte_port_ethdev_writer_ops;
217 case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
218 return &rte_port_ethdev_writer_nodrop_ops;
219 case PIPELINE_PORT_OUT_RING_WRITER:
220 return &rte_port_ring_writer_ops;
221 case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
222 return &rte_port_ring_multi_writer_ops;
223 case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
224 return &rte_port_ring_writer_nodrop_ops;
225 case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
226 return &rte_port_ring_multi_writer_nodrop_ops;
227 case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
228 return &rte_port_ring_writer_ipv4_ras_ops;
229 case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
230 return &rte_port_ring_writer_ipv6_ras_ops;
231 case PIPELINE_PORT_OUT_SCHED_WRITER:
232 return &rte_port_sched_writer_ops;
233 case PIPELINE_PORT_OUT_FD_WRITER:
234 return &rte_port_fd_writer_ops;
235 #ifdef RTE_LIBRTE_KNI
236 case PIPELINE_PORT_OUT_KNI_WRITER:
237 return &rte_port_kni_writer_ops;
238 case PIPELINE_PORT_OUT_KNI_WRITER_NODROP:
239 return &rte_port_kni_writer_nodrop_ops;
240 #endif
241 case PIPELINE_PORT_OUT_SINK:
242 return &rte_port_sink_ops;
243 default:
244 return NULL;
245 }
246 }
247
248 #ifndef PIPELINE_NAME_SIZE
249 #define PIPELINE_NAME_SIZE 64
250 #endif
251
252 #ifndef PIPELINE_TYPE_SIZE
253 #define PIPELINE_TYPE_SIZE 64
254 #endif
255
256 #ifndef PIPELINE_MAX_PORT_IN
257 #define PIPELINE_MAX_PORT_IN 64
258 #endif
259
260 #ifndef PIPELINE_MAX_PORT_OUT
261 #define PIPELINE_MAX_PORT_OUT 64
262 #endif
263
264 #ifndef PIPELINE_MAX_TABLES
265 #define PIPELINE_MAX_TABLES 16
266 #endif
267
268 #ifndef PIPELINE_MAX_MSGQ_IN
269 #define PIPELINE_MAX_MSGQ_IN 16
270 #endif
271
272 #ifndef PIPELINE_MAX_MSGQ_OUT
273 #define PIPELINE_MAX_MSGQ_OUT 16
274 #endif
275
276 #ifndef PIPELINE_MAX_ARGS
277 #define PIPELINE_MAX_ARGS 64
278 #endif
279
280 struct pipeline_params {
281 char name[PIPELINE_NAME_SIZE];
282 char type[PIPELINE_TYPE_SIZE];
283
284 struct pipeline_port_in_params port_in[PIPELINE_MAX_PORT_IN];
285 struct pipeline_port_out_params port_out[PIPELINE_MAX_PORT_OUT];
286 struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
287 struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
288
289 uint32_t n_ports_in;
290 uint32_t n_ports_out;
291 uint32_t n_msgq;
292
293 int socket_id;
294
295 char *args_name[PIPELINE_MAX_ARGS];
296 char *args_value[PIPELINE_MAX_ARGS];
297 uint32_t n_args;
298
299 uint32_t log_level;
300 };
301
302 /*
303 * Pipeline type back-end operations
304 */
305
306 typedef void* (*pipeline_be_op_init)(struct pipeline_params *params,
307 void *arg);
308
309 typedef int (*pipeline_be_op_free)(void *pipeline);
310
311 typedef int (*pipeline_be_op_run)(void *pipeline);
312
313 typedef int (*pipeline_be_op_timer)(void *pipeline);
314
315 struct pipeline_be_ops {
316 pipeline_be_op_init f_init;
317 pipeline_be_op_free f_free;
318 pipeline_be_op_run f_run;
319 pipeline_be_op_timer f_timer;
320 };
321
322 /* Pipeline specific config parse error messages */
323 #define PIPELINE_ARG_CHECK(exp, fmt, ...) \
324 do { \
325 if (!(exp)) { \
326 fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
327 return -1; \
328 } \
329 } while (0)
330
331 #define PIPELINE_PARSE_ERR_INV_VAL(exp, section, entry, val) \
332 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" " \
333 "has invalid value (\"%s\")", section, entry, val)
334
335 #define PIPELINE_PARSE_ERR_OUT_RNG(exp, section, entry, val) \
336 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" " \
337 "value is out of range (\"%s\")", section, entry, val)
338
339 #define PIPELINE_PARSE_ERR_DUPLICATE(exp, section, entry) \
340 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": duplicated " \
341 "entry \"%s\"", section, entry)
342
343 #define PIPELINE_PARSE_ERR_INV_ENT(exp, section, entry) \
344 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": invalid entry " \
345 "\"%s\"", section, entry)
346
347 #define PIPELINE_PARSE_ERR_MANDATORY(exp, section, entry) \
348 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": mandatory " \
349 "entry \"%s\" is missing", section, entry)
350
351 #endif