1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
4 #ifndef __INCLUDE_RTE_SWX_PIPELINE_H__
5 #define __INCLUDE_RTE_SWX_PIPELINE_H__
19 #include <rte_compat.h>
21 #include "rte_swx_port.h"
22 #include "rte_swx_extern.h"
25 #ifndef RTE_SWX_NAME_SIZE
26 #define RTE_SWX_NAME_SIZE 64
29 * Pipeline setup and operation
32 /** Pipeline opaque data structure. */
33 struct rte_swx_pipeline;
39 * Pipeline handle. Must point to valid memory. Contains valid pipeline handle
40 * when the function returns successfully.
41 * @param[in] numa_node
42 * Non-Uniform Memory Access (NUMA) node.
44 * 0 on success or the following error codes otherwise:
45 * -EINVAL: Invalid argument;
46 * -ENOMEM: Not enough space/cannot allocate memory.
50 rte_swx_pipeline_config(struct rte_swx_pipeline **p,
54 * Pipeline input ports
58 * Pipeline input port type register
63 * Input port type name.
65 * Input port type operations.
67 * 0 on success or the following error codes otherwise:
68 * -EINVAL: Invalid argument;
69 * -ENOMEM: Not enough space/cannot allocate memory;
70 * -EEXIST: Input port type with this name already exists.
74 rte_swx_pipeline_port_in_type_register(struct rte_swx_pipeline *p,
76 struct rte_swx_port_in_ops *ops);
79 * Pipeline input port configure
85 * @param[in] port_type_name
86 * Existing input port type name.
88 * Input port creation arguments.
90 * 0 on success or the following error codes otherwise:
91 * -EINVAL: Invalid argument;
92 * -ENOMEM: Not enough space/cannot allocate memory;
93 * -ENODEV: Input port object creation error.
97 rte_swx_pipeline_port_in_config(struct rte_swx_pipeline *p,
99 const char *port_type_name,
103 * Pipeline output ports
107 * Pipeline output port type register
112 * Output port type name.
114 * Output port type operations.
116 * 0 on success or the following error codes otherwise:
117 * -EINVAL: Invalid argument;
118 * -ENOMEM: Not enough space/cannot allocate memory;
119 * -EEXIST: Output port type with this name already exists.
123 rte_swx_pipeline_port_out_type_register(struct rte_swx_pipeline *p,
125 struct rte_swx_port_out_ops *ops);
128 * Pipeline output port configure
134 * @param[in] port_type_name
135 * Existing output port type name.
137 * Output port creation arguments.
139 * 0 on success or the following error codes otherwise:
140 * -EINVAL: Invalid argument;
141 * -ENOMEM: Not enough space/cannot allocate memory;
142 * -ENODEV: Output port object creation error.
146 rte_swx_pipeline_port_out_config(struct rte_swx_pipeline *p,
148 const char *port_type_name,
152 * Extern objects and functions
156 * Pipeline extern type register
162 * @param[in] mailbox_struct_type_name
163 * Name of existing struct type used to define the mailbox size and layout for
164 * the extern objects that are instances of this type. Each extern object gets
165 * its own mailbox, which is used to pass the input arguments to the member
166 * functions and retrieve the output results.
167 * @param[in] constructor
168 * Function used to create the extern objects that are instances of this type.
169 * @param[in] destructor
170 * Function used to free the extern objects that are instances of this type.
172 * 0 on success or the following error codes otherwise:
173 * -EINVAL: Invalid argument;
174 * -ENOMEM: Not enough space/cannot allocate memory;
175 * -EEXIST: Extern type with this name already exists.
179 rte_swx_pipeline_extern_type_register(struct rte_swx_pipeline *p,
181 const char *mailbox_struct_type_name,
182 rte_swx_extern_type_constructor_t constructor,
183 rte_swx_extern_type_destructor_t destructor);
186 * Pipeline extern type member function register
190 * @param[in] extern_type_name
191 * Existing extern type name.
193 * Name for the new member function to be added to the extern type.
194 * @param[in] member_func
195 * The new member function.
197 * 0 on success or the following error codes otherwise:
198 * -EINVAL: Invalid argument;
199 * -ENOMEM: Not enough space/cannot allocate memory;
200 * -EEXIST: Member function with this name already exists for this type;
201 * -ENOSPC: Maximum number of member functions reached for this type.
205 rte_swx_pipeline_extern_type_member_func_register(struct rte_swx_pipeline *p,
206 const char *extern_type_name,
208 rte_swx_extern_type_member_func_t member_func);
211 * Pipeline extern object configure
213 * Instantiate a given extern type to create new extern object.
217 * @param[in] extern_type_name
218 * Existing extern type name.
220 * Name for the new object instantiating the extern type.
222 * Extern object constructor arguments.
224 * 0 on success or the following error codes otherwise:
225 * -EINVAL: Invalid argument;
226 * -ENOMEM: Not enough space/cannot allocate memory;
227 * -EEXIST: Extern object with this name already exists;
228 * -ENODEV: Extern object constructor error.
232 rte_swx_pipeline_extern_object_config(struct rte_swx_pipeline *p,
233 const char *extern_type_name,
238 * Pipeline extern function register
243 * Extern function name.
244 * @param[in] mailbox_struct_type_name
245 * Name of existing struct type used to define the mailbox size and layout for
246 * this extern function. The mailbox is used to pass the input arguments to
247 * the extern function and retrieve the output results.
249 * The extern function.
251 * 0 on success or the following error codes otherwise:
252 * -EINVAL: Invalid argument;
253 * -ENOMEM: Not enough space/cannot allocate memory;
254 * -EEXIST: Extern function with this name already exists.
258 rte_swx_pipeline_extern_func_register(struct rte_swx_pipeline *p,
260 const char *mailbox_struct_type_name,
261 rte_swx_extern_func_t func);
264 * Packet headers and meta-data
267 /** Structure (struct) field. */
268 struct rte_swx_field_params {
269 /** Struct field name. */
272 /** Struct field size (in bits).
273 * Restriction: All struct fields must be a multiple of 8 bits.
274 * Restriction: All struct fields must be no greater than 64 bits.
280 * Pipeline struct type register
282 * Structs are used extensively in many part of the pipeline to define the size
283 * and layout of a specific memory piece such as: headers, meta-data, action
284 * data stored in a table entry, mailboxes for extern objects and functions.
285 * Similar to C language structs, they are a well defined sequence of fields,
286 * with each field having a unique name and a constant size.
293 * The sequence of struct fields.
294 * @param[in] n_fields
295 * The number of struct fields.
297 * 0 on success or the following error codes otherwise:
298 * -EINVAL: Invalid argument;
299 * -ENOMEM: Not enough space/cannot allocate memory;
300 * -EEXIST: Struct type with this name already exists.
304 rte_swx_pipeline_struct_type_register(struct rte_swx_pipeline *p,
306 struct rte_swx_field_params *fields,
310 * Pipeline packet header register
316 * @param[in] struct_type_name
317 * The struct type instantiated by this packet header.
319 * 0 on success or the following error codes otherwise:
320 * -EINVAL: Invalid argument;
321 * -ENOMEM: Not enough space/cannot allocate memory;
322 * -EEXIST: Header with this name already exists;
323 * -ENOSPC: Maximum number of headers reached for the pipeline.
327 rte_swx_pipeline_packet_header_register(struct rte_swx_pipeline *p,
329 const char *struct_type_name);
332 * Pipeline packet meta-data register
336 * @param[in] struct_type_name
337 * The struct type instantiated by the packet meta-data.
339 * 0 on success or the following error codes otherwise:
340 * -EINVAL: Invalid argument.
344 rte_swx_pipeline_packet_metadata_register(struct rte_swx_pipeline *p,
345 const char *struct_type_name);
352 * Pipeline action configure
358 * @param[in] args_struct_type_name
359 * The struct type instantiated by the action data. The action data represent
360 * the action arguments that are stored in the table entry together with the
361 * action ID. Set to NULL when the action does not have any arguments.
362 * @param[in] instructions
363 * Action instructions.
364 * @param[in] n_instructions
365 * Number of action instructions.
367 * 0 on success or the following error codes otherwise:
368 * -EINVAL: Invalid argument;
369 * -ENOMEM: Not enough space/cannot allocate memory;
370 * -EEXIST: Action with this name already exists.
374 rte_swx_pipeline_action_config(struct rte_swx_pipeline *p,
376 const char *args_struct_type_name,
377 const char **instructions,
378 uint32_t n_instructions);
383 * Once called, the pipeline build operation marks the end of pipeline
384 * configuration. At this point, all the internal data structures needed to run
385 * the pipeline are built.
390 * 0 on success or the following error codes otherwise:
391 * -EINVAL: Invalid argument;
392 * -ENOMEM: Not enough space/cannot allocate memory;
393 * -EEXIST: Pipeline was already built successfully.
397 rte_swx_pipeline_build(struct rte_swx_pipeline *p);
407 rte_swx_pipeline_free(struct rte_swx_pipeline *p);