Imported Upstream version 16.07-rc1
[deb_dpdk.git] / 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_source_sink.h>
43 #ifdef RTE_LIBRTE_KNI
44 #include <rte_port_kni.h>
45 #endif
46 #include <rte_pipeline.h>
47
48 enum pipeline_port_in_type {
49         PIPELINE_PORT_IN_ETHDEV_READER,
50         PIPELINE_PORT_IN_RING_READER,
51         PIPELINE_PORT_IN_RING_MULTI_READER,
52         PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
53         PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
54         PIPELINE_PORT_IN_SCHED_READER,
55         PIPELINE_PORT_IN_KNI_READER,
56         PIPELINE_PORT_IN_SOURCE,
57 };
58
59 struct pipeline_port_in_params {
60         enum pipeline_port_in_type type;
61         union {
62                 struct rte_port_ethdev_reader_params ethdev;
63                 struct rte_port_ring_reader_params ring;
64                 struct rte_port_ring_multi_reader_params ring_multi;
65                 struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
66                 struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
67                 struct rte_port_sched_reader_params sched;
68 #ifdef RTE_LIBRTE_KNI
69                 struct rte_port_kni_reader_params kni;
70 #endif
71                 struct rte_port_source_params source;
72         } params;
73         uint32_t burst_size;
74 };
75
76 static inline void *
77 pipeline_port_in_params_convert(struct pipeline_port_in_params  *p)
78 {
79         switch (p->type) {
80         case PIPELINE_PORT_IN_ETHDEV_READER:
81                 return (void *) &p->params.ethdev;
82         case PIPELINE_PORT_IN_RING_READER:
83                 return (void *) &p->params.ring;
84         case PIPELINE_PORT_IN_RING_MULTI_READER:
85                 return (void *) &p->params.ring_multi;
86         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
87                 return (void *) &p->params.ring_ipv4_frag;
88         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
89                 return (void *) &p->params.ring_ipv6_frag;
90         case PIPELINE_PORT_IN_SCHED_READER:
91                 return (void *) &p->params.sched;
92 #ifdef RTE_LIBRTE_KNI
93         case PIPELINE_PORT_IN_KNI_READER:
94                 return (void *) &p->params.kni;
95 #endif
96         case PIPELINE_PORT_IN_SOURCE:
97                 return (void *) &p->params.source;
98         default:
99                 return NULL;
100         }
101 }
102
103 static inline struct rte_port_in_ops *
104 pipeline_port_in_params_get_ops(struct pipeline_port_in_params  *p)
105 {
106         switch (p->type) {
107         case PIPELINE_PORT_IN_ETHDEV_READER:
108                 return &rte_port_ethdev_reader_ops;
109         case PIPELINE_PORT_IN_RING_READER:
110                 return &rte_port_ring_reader_ops;
111         case PIPELINE_PORT_IN_RING_MULTI_READER:
112                 return &rte_port_ring_multi_reader_ops;
113         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
114                 return &rte_port_ring_reader_ipv4_frag_ops;
115         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
116                 return &rte_port_ring_reader_ipv6_frag_ops;
117         case PIPELINE_PORT_IN_SCHED_READER:
118                 return &rte_port_sched_reader_ops;
119 #ifdef RTE_LIBRTE_KNI
120         case PIPELINE_PORT_IN_KNI_READER:
121                 return &rte_port_kni_reader_ops;
122 #endif
123         case PIPELINE_PORT_IN_SOURCE:
124                 return &rte_port_source_ops;
125         default:
126                 return NULL;
127         }
128 }
129
130 enum pipeline_port_out_type {
131         PIPELINE_PORT_OUT_ETHDEV_WRITER,
132         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP,
133         PIPELINE_PORT_OUT_RING_WRITER,
134         PIPELINE_PORT_OUT_RING_MULTI_WRITER,
135         PIPELINE_PORT_OUT_RING_WRITER_NODROP,
136         PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP,
137         PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
138         PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
139         PIPELINE_PORT_OUT_SCHED_WRITER,
140         PIPELINE_PORT_OUT_KNI_WRITER,
141         PIPELINE_PORT_OUT_KNI_WRITER_NODROP,
142         PIPELINE_PORT_OUT_SINK,
143 };
144
145 struct pipeline_port_out_params {
146         enum pipeline_port_out_type type;
147         union {
148                 struct rte_port_ethdev_writer_params ethdev;
149                 struct rte_port_ethdev_writer_nodrop_params ethdev_nodrop;
150                 struct rte_port_ring_writer_params ring;
151                 struct rte_port_ring_multi_writer_params ring_multi;
152                 struct rte_port_ring_writer_nodrop_params ring_nodrop;
153                 struct rte_port_ring_multi_writer_nodrop_params ring_multi_nodrop;
154                 struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
155                 struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
156                 struct rte_port_sched_writer_params sched;
157 #ifdef RTE_LIBRTE_KNI
158                 struct rte_port_kni_writer_params kni;
159                 struct rte_port_kni_writer_nodrop_params kni_nodrop;
160 #endif
161                 struct rte_port_sink_params sink;
162         } params;
163 };
164
165 static inline void *
166 pipeline_port_out_params_convert(struct pipeline_port_out_params  *p)
167 {
168         switch (p->type) {
169         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
170                 return (void *) &p->params.ethdev;
171         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
172                 return (void *) &p->params.ethdev_nodrop;
173         case PIPELINE_PORT_OUT_RING_WRITER:
174                 return (void *) &p->params.ring;
175         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
176                 return (void *) &p->params.ring_multi;
177         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
178                 return (void *) &p->params.ring_nodrop;
179         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
180                 return (void *) &p->params.ring_multi_nodrop;
181         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
182                 return (void *) &p->params.ring_ipv4_ras;
183         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
184                 return (void *) &p->params.ring_ipv6_ras;
185         case PIPELINE_PORT_OUT_SCHED_WRITER:
186                 return (void *) &p->params.sched;
187 #ifdef RTE_LIBRTE_KNI
188         case PIPELINE_PORT_OUT_KNI_WRITER:
189                 return (void *) &p->params.kni;
190         case PIPELINE_PORT_OUT_KNI_WRITER_NODROP:
191                 return (void *) &p->params.kni_nodrop;
192 #endif
193         case PIPELINE_PORT_OUT_SINK:
194                 return (void *) &p->params.sink;
195         default:
196                 return NULL;
197         }
198 }
199
200 static inline void *
201 pipeline_port_out_params_get_ops(struct pipeline_port_out_params  *p)
202 {
203         switch (p->type) {
204         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
205                 return &rte_port_ethdev_writer_ops;
206         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
207                 return &rte_port_ethdev_writer_nodrop_ops;
208         case PIPELINE_PORT_OUT_RING_WRITER:
209                 return &rte_port_ring_writer_ops;
210         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
211                 return &rte_port_ring_multi_writer_ops;
212         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
213                 return &rte_port_ring_writer_nodrop_ops;
214         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
215                 return &rte_port_ring_multi_writer_nodrop_ops;
216         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
217                 return &rte_port_ring_writer_ipv4_ras_ops;
218         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
219                 return &rte_port_ring_writer_ipv6_ras_ops;
220         case PIPELINE_PORT_OUT_SCHED_WRITER:
221                 return &rte_port_sched_writer_ops;
222 #ifdef RTE_LIBRTE_KNI
223         case PIPELINE_PORT_OUT_KNI_WRITER:
224                 return &rte_port_kni_writer_ops;
225         case PIPELINE_PORT_OUT_KNI_WRITER_NODROP:
226                 return &rte_port_kni_writer_nodrop_ops;
227 #endif
228         case PIPELINE_PORT_OUT_SINK:
229                 return &rte_port_sink_ops;
230         default:
231                 return NULL;
232         }
233 }
234
235 #ifndef PIPELINE_NAME_SIZE
236 #define PIPELINE_NAME_SIZE                       64
237 #endif
238
239 #ifndef PIPELINE_TYPE_SIZE
240 #define PIPELINE_TYPE_SIZE                       64
241 #endif
242
243 #ifndef PIPELINE_MAX_PORT_IN
244 #define PIPELINE_MAX_PORT_IN                     64
245 #endif
246
247 #ifndef PIPELINE_MAX_PORT_OUT
248 #define PIPELINE_MAX_PORT_OUT                    64
249 #endif
250
251 #ifndef PIPELINE_MAX_TABLES
252 #define PIPELINE_MAX_TABLES                      16
253 #endif
254
255 #ifndef PIPELINE_MAX_MSGQ_IN
256 #define PIPELINE_MAX_MSGQ_IN                     16
257 #endif
258
259 #ifndef PIPELINE_MAX_MSGQ_OUT
260 #define PIPELINE_MAX_MSGQ_OUT                    16
261 #endif
262
263 #ifndef PIPELINE_MAX_ARGS
264 #define PIPELINE_MAX_ARGS                        64
265 #endif
266
267 struct pipeline_params {
268         char name[PIPELINE_NAME_SIZE];
269         char type[PIPELINE_TYPE_SIZE];
270
271         struct pipeline_port_in_params port_in[PIPELINE_MAX_PORT_IN];
272         struct pipeline_port_out_params port_out[PIPELINE_MAX_PORT_OUT];
273         struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
274         struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
275
276         uint32_t n_ports_in;
277         uint32_t n_ports_out;
278         uint32_t n_msgq;
279
280         int socket_id;
281
282         char *args_name[PIPELINE_MAX_ARGS];
283         char *args_value[PIPELINE_MAX_ARGS];
284         uint32_t n_args;
285
286         uint32_t log_level;
287 };
288
289 /*
290  * Pipeline type back-end operations
291  */
292
293 typedef void* (*pipeline_be_op_init)(struct pipeline_params *params,
294         void *arg);
295
296 typedef int (*pipeline_be_op_free)(void *pipeline);
297
298 typedef int (*pipeline_be_op_run)(void *pipeline);
299
300 typedef int (*pipeline_be_op_timer)(void *pipeline);
301
302 struct pipeline_be_ops {
303         pipeline_be_op_init f_init;
304         pipeline_be_op_free f_free;
305         pipeline_be_op_run f_run;
306         pipeline_be_op_timer f_timer;
307 };
308
309 /* Pipeline specific config parse error messages */
310 #define PIPELINE_ARG_CHECK(exp, fmt, ...)                               \
311 do {                                                                    \
312         if (!(exp)) {                                                   \
313                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
314                 return -1;                                              \
315         }                                                               \
316 } while (0)
317
318 #define PIPELINE_PARSE_ERR_INV_VAL(exp, section, entry, val)            \
319 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" "  \
320         "has invalid value (\"%s\")", section, entry, val)
321
322 #define PIPELINE_PARSE_ERR_OUT_RNG(exp, section, entry, val)            \
323 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" "  \
324         "value is out of range (\"%s\")", section, entry, val)
325
326 #define PIPELINE_PARSE_ERR_DUPLICATE(exp, section, entry)               \
327 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": duplicated "    \
328         "entry \"%s\"", section, entry)
329
330 #define PIPELINE_PARSE_ERR_INV_ENT(exp, section, entry)                 \
331 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": invalid entry " \
332         "\"%s\"", section, entry)
333
334 #define PIPELINE_PARSE_ERR_MANDATORY(exp, section, entry)               \
335 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": mandatory "     \
336         "entry \"%s\" is missing", section, entry)
337
338 #endif