i40evf: fix MAC deletion when stopping
[dpdk.git] / examples / ip_pipeline / pipeline_be.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 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 #include <rte_pipeline.h>
44
45 enum pipeline_port_in_type {
46         PIPELINE_PORT_IN_ETHDEV_READER,
47         PIPELINE_PORT_IN_RING_READER,
48         PIPELINE_PORT_IN_RING_MULTI_READER,
49         PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
50         PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
51         PIPELINE_PORT_IN_SCHED_READER,
52         PIPELINE_PORT_IN_SOURCE,
53 };
54
55 struct pipeline_port_in_params {
56         enum pipeline_port_in_type type;
57         union {
58                 struct rte_port_ethdev_reader_params ethdev;
59                 struct rte_port_ring_reader_params ring;
60                 struct rte_port_ring_multi_reader_params ring_multi;
61                 struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
62                 struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
63                 struct rte_port_sched_reader_params sched;
64                 struct rte_port_source_params source;
65         } params;
66         uint32_t burst_size;
67 };
68
69 static inline void *
70 pipeline_port_in_params_convert(struct pipeline_port_in_params  *p)
71 {
72         switch (p->type) {
73         case PIPELINE_PORT_IN_ETHDEV_READER:
74                 return (void *) &p->params.ethdev;
75         case PIPELINE_PORT_IN_RING_READER:
76                 return (void *) &p->params.ring;
77         case PIPELINE_PORT_IN_RING_MULTI_READER:
78                 return (void *) &p->params.ring_multi;
79         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
80                 return (void *) &p->params.ring_ipv4_frag;
81         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
82                 return (void *) &p->params.ring_ipv6_frag;
83         case PIPELINE_PORT_IN_SCHED_READER:
84                 return (void *) &p->params.sched;
85         case PIPELINE_PORT_IN_SOURCE:
86                 return (void *) &p->params.source;
87         default:
88                 return NULL;
89         }
90 }
91
92 static inline struct rte_port_in_ops *
93 pipeline_port_in_params_get_ops(struct pipeline_port_in_params  *p)
94 {
95         switch (p->type) {
96         case PIPELINE_PORT_IN_ETHDEV_READER:
97                 return &rte_port_ethdev_reader_ops;
98         case PIPELINE_PORT_IN_RING_READER:
99                 return &rte_port_ring_reader_ops;
100         case PIPELINE_PORT_IN_RING_MULTI_READER:
101                 return &rte_port_ring_multi_reader_ops;
102         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
103                 return &rte_port_ring_reader_ipv4_frag_ops;
104         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
105                 return &rte_port_ring_reader_ipv6_frag_ops;
106         case PIPELINE_PORT_IN_SCHED_READER:
107                 return &rte_port_sched_reader_ops;
108         case PIPELINE_PORT_IN_SOURCE:
109                 return &rte_port_source_ops;
110         default:
111                 return NULL;
112         }
113 }
114
115 enum pipeline_port_out_type {
116         PIPELINE_PORT_OUT_ETHDEV_WRITER,
117         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP,
118         PIPELINE_PORT_OUT_RING_WRITER,
119         PIPELINE_PORT_OUT_RING_MULTI_WRITER,
120         PIPELINE_PORT_OUT_RING_WRITER_NODROP,
121         PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP,
122         PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
123         PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
124         PIPELINE_PORT_OUT_SCHED_WRITER,
125         PIPELINE_PORT_OUT_SINK,
126 };
127
128 struct pipeline_port_out_params {
129         enum pipeline_port_out_type type;
130         union {
131                 struct rte_port_ethdev_writer_params ethdev;
132                 struct rte_port_ethdev_writer_nodrop_params ethdev_nodrop;
133                 struct rte_port_ring_writer_params ring;
134                 struct rte_port_ring_multi_writer_params ring_multi;
135                 struct rte_port_ring_writer_nodrop_params ring_nodrop;
136                 struct rte_port_ring_multi_writer_nodrop_params ring_multi_nodrop;
137                 struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
138                 struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
139                 struct rte_port_sched_writer_params sched;
140         } params;
141 };
142
143 static inline void *
144 pipeline_port_out_params_convert(struct pipeline_port_out_params  *p)
145 {
146         switch (p->type) {
147         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
148                 return (void *) &p->params.ethdev;
149         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
150                 return (void *) &p->params.ethdev_nodrop;
151         case PIPELINE_PORT_OUT_RING_WRITER:
152                 return (void *) &p->params.ring;
153         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
154                 return (void *) &p->params.ring_multi;
155         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
156                 return (void *) &p->params.ring_nodrop;
157         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
158                 return (void *) &p->params.ring_multi_nodrop;
159         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
160                 return (void *) &p->params.ring_ipv4_ras;
161         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
162                 return (void *) &p->params.ring_ipv6_ras;
163         case PIPELINE_PORT_OUT_SCHED_WRITER:
164                 return (void *) &p->params.sched;
165         case PIPELINE_PORT_OUT_SINK:
166         default:
167                 return NULL;
168         }
169 }
170
171 static inline void *
172 pipeline_port_out_params_get_ops(struct pipeline_port_out_params  *p)
173 {
174         switch (p->type) {
175         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
176                 return &rte_port_ethdev_writer_ops;
177         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
178                 return &rte_port_ethdev_writer_nodrop_ops;
179         case PIPELINE_PORT_OUT_RING_WRITER:
180                 return &rte_port_ring_writer_ops;
181         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
182                 return &rte_port_ring_multi_writer_ops;
183         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
184                 return &rte_port_ring_writer_nodrop_ops;
185         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
186                 return &rte_port_ring_multi_writer_nodrop_ops;
187         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
188                 return &rte_port_ring_writer_ipv4_ras_ops;
189         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
190                 return &rte_port_ring_writer_ipv6_ras_ops;
191         case PIPELINE_PORT_OUT_SCHED_WRITER:
192                 return &rte_port_sched_writer_ops;
193         case PIPELINE_PORT_OUT_SINK:
194                 return &rte_port_sink_ops;
195         default:
196                 return NULL;
197         }
198 }
199
200 #ifndef PIPELINE_NAME_SIZE
201 #define PIPELINE_NAME_SIZE                       32
202 #endif
203
204 #ifndef PIPELINE_MAX_PORT_IN
205 #define PIPELINE_MAX_PORT_IN                     16
206 #endif
207
208 #ifndef PIPELINE_MAX_PORT_OUT
209 #define PIPELINE_MAX_PORT_OUT                    16
210 #endif
211
212 #ifndef PIPELINE_MAX_TABLES
213 #define PIPELINE_MAX_TABLES                      16
214 #endif
215
216 #ifndef PIPELINE_MAX_MSGQ_IN
217 #define PIPELINE_MAX_MSGQ_IN                     16
218 #endif
219
220 #ifndef PIPELINE_MAX_MSGQ_OUT
221 #define PIPELINE_MAX_MSGQ_OUT                    16
222 #endif
223
224 #ifndef PIPELINE_MAX_ARGS
225 #define PIPELINE_MAX_ARGS                        32
226 #endif
227
228 struct pipeline_params {
229         char name[PIPELINE_NAME_SIZE];
230
231         struct pipeline_port_in_params port_in[PIPELINE_MAX_PORT_IN];
232         struct pipeline_port_out_params port_out[PIPELINE_MAX_PORT_OUT];
233         struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
234         struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
235
236         uint32_t n_ports_in;
237         uint32_t n_ports_out;
238         uint32_t n_msgq;
239
240         int socket_id;
241
242         char *args_name[PIPELINE_MAX_ARGS];
243         char *args_value[PIPELINE_MAX_ARGS];
244         uint32_t n_args;
245
246         uint32_t log_level;
247 };
248
249 /*
250  * Pipeline type back-end operations
251  */
252
253 typedef void* (*pipeline_be_op_init)(struct pipeline_params *params,
254         void *arg);
255
256 typedef int (*pipeline_be_op_free)(void *pipeline);
257
258 typedef int (*pipeline_be_op_run)(void *pipeline);
259
260 typedef int (*pipeline_be_op_timer)(void *pipeline);
261
262 typedef int (*pipeline_be_op_track)(void *pipeline,
263         uint32_t port_in,
264         uint32_t *port_out);
265
266 struct pipeline_be_ops {
267         pipeline_be_op_init f_init;
268         pipeline_be_op_free f_free;
269         pipeline_be_op_run f_run;
270         pipeline_be_op_timer f_timer;
271         pipeline_be_op_track f_track;
272 };
273
274 /* Parse hex string to uint8_t array */
275 int
276 parse_hex_string(char *src, uint8_t *dst, uint32_t *size);
277
278 #endif