xref: /dpdk/lib/pipeline/rte_swx_pipeline.h (revision 8f1d23ece06adff5eae9f1b4365bdbbd3abee2b2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4 #ifndef __INCLUDE_RTE_SWX_PIPELINE_H__
5 #define __INCLUDE_RTE_SWX_PIPELINE_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 /**
12  * @file
13  * RTE SWX Pipeline
14  */
15 
16 #include <stdint.h>
17 #include <stdio.h>
18 
19 #include <rte_compat.h>
20 
21 #include "rte_swx_port.h"
22 #include "rte_swx_table.h"
23 #include "rte_swx_extern.h"
24 
25 /** Name size. */
26 #ifndef RTE_SWX_NAME_SIZE
27 #define RTE_SWX_NAME_SIZE 64
28 #endif
29 
30 /** Instruction size. */
31 #ifndef RTE_SWX_INSTRUCTION_SIZE
32 #define RTE_SWX_INSTRUCTION_SIZE 256
33 #endif
34 
35 /** Instruction tokens. */
36 #ifndef RTE_SWX_INSTRUCTION_TOKENS_MAX
37 #define RTE_SWX_INSTRUCTION_TOKENS_MAX 16
38 #endif
39 
40 /*
41  * Pipeline setup and operation
42  */
43 
44 /** Pipeline opaque data structure. */
45 struct rte_swx_pipeline;
46 
47 /**
48  * Pipeline find
49  *
50  * @param[in] name
51  *   Pipeline name.
52  * @return
53  *   Valid pipeline handle if found or NULL otherwise.
54  */
55 __rte_experimental
56 struct rte_swx_pipeline *
57 rte_swx_pipeline_find(const char *name);
58 
59 /**
60  * Pipeline configure
61  *
62  * @param[out] p
63  *   Pipeline handle. Must point to valid memory. Contains valid pipeline handle
64  *   when the function returns successfully.
65  * @param[in] name
66  *   Pipeline unique name.
67  * @param[in] numa_node
68  *   Non-Uniform Memory Access (NUMA) node.
69  * @return
70  *   0 on success or the following error codes otherwise:
71  *   -EINVAL: Invalid argument;
72  *   -ENOMEM: Not enough space/cannot allocate memory;
73  *   -EEXIST: Pipeline with this name already exists.
74  */
75 __rte_experimental
76 int
77 rte_swx_pipeline_config(struct rte_swx_pipeline **p,
78 			const char *name,
79 			int numa_node);
80 
81 /*
82  * Pipeline input ports
83  */
84 
85 /**
86  * Pipeline input port type register
87  *
88  * @param[in] p
89  *   Pipeline handle.
90  * @param[in] name
91  *   Input port type name.
92  * @param[in] ops
93  *   Input port type operations.
94  * @return
95  *   0 on success or the following error codes otherwise:
96  *   -EINVAL: Invalid argument;
97  *   -ENOMEM: Not enough space/cannot allocate memory;
98  *   -EEXIST: Input port type with this name already exists.
99  */
100 __rte_experimental
101 int
102 rte_swx_pipeline_port_in_type_register(struct rte_swx_pipeline *p,
103 				       const char *name,
104 				       struct rte_swx_port_in_ops *ops);
105 
106 /**
107  * Pipeline input port configure
108  *
109  * @param[in] p
110  *   Pipeline handle.
111  * @param[in] port_id
112  *   Input port ID.
113  * @param[in] port_type_name
114  *   Existing input port type name.
115  * @param[in] args
116  *   Input port creation arguments.
117  * @return
118  *   0 on success or the following error codes otherwise:
119  *   -EINVAL: Invalid argument;
120  *   -ENOMEM: Not enough space/cannot allocate memory;
121  *   -ENODEV: Input port object creation error.
122  */
123 __rte_experimental
124 int
125 rte_swx_pipeline_port_in_config(struct rte_swx_pipeline *p,
126 				uint32_t port_id,
127 				const char *port_type_name,
128 				void *args);
129 
130 /*
131  * Pipeline output ports
132  */
133 
134 /**
135  * Pipeline output port type register
136  *
137  * @param[in] p
138  *   Pipeline handle.
139  * @param[in] name
140  *   Output port type name.
141  * @param[in] ops
142  *   Output port type operations.
143  * @return
144  *   0 on success or the following error codes otherwise:
145  *   -EINVAL: Invalid argument;
146  *   -ENOMEM: Not enough space/cannot allocate memory;
147  *   -EEXIST: Output port type with this name already exists.
148  */
149 __rte_experimental
150 int
151 rte_swx_pipeline_port_out_type_register(struct rte_swx_pipeline *p,
152 					const char *name,
153 					struct rte_swx_port_out_ops *ops);
154 
155 /**
156  * Pipeline output port configure
157  *
158  * @param[in] p
159  *   Pipeline handle.
160  * @param[in] port_id
161  *   Output port ID.
162  * @param[in] port_type_name
163  *   Existing output port type name.
164  * @param[in] args
165  *   Output port creation arguments.
166  * @return
167  *   0 on success or the following error codes otherwise:
168  *   -EINVAL: Invalid argument;
169  *   -ENOMEM: Not enough space/cannot allocate memory;
170  *   -ENODEV: Output port object creation error.
171  */
172 __rte_experimental
173 int
174 rte_swx_pipeline_port_out_config(struct rte_swx_pipeline *p,
175 				 uint32_t port_id,
176 				 const char *port_type_name,
177 				 void *args);
178 /*
179  * Packet mirroring
180  */
181 
182 /** Default number of packet mirroring slots. */
183 #ifndef RTE_SWX_PACKET_MIRRORING_SLOTS_DEFAULT
184 #define RTE_SWX_PACKET_MIRRORING_SLOTS_DEFAULT 4
185 #endif
186 
187 /** Default maximum number of packet mirroring sessions. */
188 #ifndef RTE_SWX_PACKET_MIRRORING_SESSIONS_DEFAULT
189 #define RTE_SWX_PACKET_MIRRORING_SESSIONS_DEFAULT 64
190 #endif
191 
192 /** Packet mirroring parameters. */
193 struct rte_swx_pipeline_mirroring_params {
194 	/** Number of packet mirroring slots. */
195 	uint32_t n_slots;
196 
197 	/** Maximum number of packet mirroring sessions. */
198 	uint32_t n_sessions;
199 };
200 
201 /**
202  * Packet mirroring configure
203  *
204  * @param[in] p
205  *   Pipeline handle.
206  * @param[in] params
207  *   Packet mirroring parameters.
208  * @return
209  *   0 on success or the following error codes otherwise:
210  *   -EINVAL: Invalid argument;
211  *   -ENOMEM: Not enough memory;
212  *   -EEXIST: Pipeline was already built successfully.
213  */
214 __rte_experimental
215 int
216 rte_swx_pipeline_mirroring_config(struct rte_swx_pipeline *p,
217 				  struct rte_swx_pipeline_mirroring_params *params);
218 
219 /*
220  * Extern objects and functions
221  */
222 
223 /**
224  * Pipeline extern type register
225  *
226  * @param[in] p
227  *   Pipeline handle.
228  * @param[in] name
229  *   Extern type name.
230  * @param[in] mailbox_struct_type_name
231  *   Name of existing struct type used to define the mailbox size and layout for
232  *   the extern objects that are instances of this type. Each extern object gets
233  *   its own mailbox, which is used to pass the input arguments to the member
234  *   functions and retrieve the output results.
235  * @param[in] constructor
236  *   Function used to create the extern objects that are instances of this type.
237  * @param[in] destructor
238  *   Function used to free the extern objects that are instances of  this type.
239  * @return
240  *   0 on success or the following error codes otherwise:
241  *   -EINVAL: Invalid argument;
242  *   -ENOMEM: Not enough space/cannot allocate memory;
243  *   -EEXIST: Extern type with this name already exists.
244  */
245 __rte_experimental
246 int
247 rte_swx_pipeline_extern_type_register(struct rte_swx_pipeline *p,
248 	const char *name,
249 	const char *mailbox_struct_type_name,
250 	rte_swx_extern_type_constructor_t constructor,
251 	rte_swx_extern_type_destructor_t destructor);
252 
253 /**
254  * Pipeline extern type member function register
255  *
256  * @param[in] p
257  *   Pipeline handle.
258  * @param[in] extern_type_name
259  *   Existing extern type name.
260  * @param[in] name
261  *   Name for the new member function to be added to the extern type.
262  * @param[in] member_func
263  *   The new member function.
264  * @return
265  *   0 on success or the following error codes otherwise:
266  *   -EINVAL: Invalid argument;
267  *   -ENOMEM: Not enough space/cannot allocate memory;
268  *   -EEXIST: Member function with this name already exists for this type;
269  *   -ENOSPC: Maximum number of member functions reached for this type.
270  */
271 __rte_experimental
272 int
273 rte_swx_pipeline_extern_type_member_func_register(struct rte_swx_pipeline *p,
274 	const char *extern_type_name,
275 	const char *name,
276 	rte_swx_extern_type_member_func_t member_func);
277 
278 /**
279  * Pipeline extern object configure
280  *
281  * Instantiate a given extern type to create new extern object.
282  *
283  * @param[in] p
284  *   Pipeline handle.
285  * @param[in] extern_type_name
286  *   Existing extern type name.
287  * @param[in] name
288  *   Name for the new object instantiating the extern type.
289  * @param[in] args
290  *   Extern object constructor arguments.
291  * @return
292  *   0 on success or the following error codes otherwise:
293  *   -EINVAL: Invalid argument;
294  *   -ENOMEM: Not enough space/cannot allocate memory;
295  *   -EEXIST: Extern object with this name already exists;
296  *   -ENODEV: Extern object constructor error.
297  */
298 __rte_experimental
299 int
300 rte_swx_pipeline_extern_object_config(struct rte_swx_pipeline *p,
301 				      const char *extern_type_name,
302 				      const char *name,
303 				      const char *args);
304 
305 /**
306  * Pipeline extern function register
307  *
308  * @param[in] p
309  *   Pipeline handle.
310  * @param[in] name
311  *   Extern function name.
312  * @param[in] mailbox_struct_type_name
313  *   Name of existing struct type used to define the mailbox size and layout for
314  *   this extern function. The mailbox is used to pass the input arguments to
315  *   the extern function and retrieve the output results.
316  * @param[in] func
317  *   The extern function.
318  * @return
319  *   0 on success or the following error codes otherwise:
320  *   -EINVAL: Invalid argument;
321  *   -ENOMEM: Not enough space/cannot allocate memory;
322  *   -EEXIST: Extern function with this name already exists.
323  */
324 __rte_experimental
325 int
326 rte_swx_pipeline_extern_func_register(struct rte_swx_pipeline *p,
327 				      const char *name,
328 				      const char *mailbox_struct_type_name,
329 				      rte_swx_extern_func_t func);
330 /*
331  * Hash function.
332  */
333 
334 /**
335  * Hash function prototype
336  *
337  * @param[in] key
338  *   Key to hash. Must be non-NULL.
339  * @param[in] length
340  *   Key length in bytes.
341  * @param[in] seed
342  *   Hash seed.
343  * @return
344  *   Hash value.
345  */
346 typedef uint32_t
347 (*rte_swx_hash_func_t)(const void *key,
348 		       uint32_t length,
349 		       uint32_t seed);
350 
351 /**
352  * Pipeline hash function register
353  *
354  * @param[in] p
355  *   Pipeline handle.
356  * @param[in] name
357  *   Hash function name.
358  * @param[in] func
359  *   Hash function.
360  * @return
361  *   0 on success or the following error codes otherwise:
362  *   -EINVAL: Invalid argument;
363  *   -ENOMEM: Not enough space/cannot allocate memory;
364  *   -EEXIST: Hash function with this name already exists.
365  */
366 __rte_experimental
367 int
368 rte_swx_pipeline_hash_func_register(struct rte_swx_pipeline *p,
369 				    const char *name,
370 				    rte_swx_hash_func_t func);
371 
372 /*
373  * Packet headers and meta-data
374  */
375 
376 /** Structure (struct) field. */
377 struct rte_swx_field_params {
378 	/** Struct field name. */
379 	const char *name;
380 
381 	/** Struct field size (in bits).
382 	 * Restriction: All struct fields must be a multiple of 8 bits.
383 	 * Restriction: All struct fields must be no greater than 64 bits.
384 	 */
385 	uint32_t n_bits;
386 };
387 
388 /**
389  * Pipeline struct type register
390  *
391  * Structs are used extensively in many part of the pipeline to define the size
392  * and layout of a specific memory piece such as: headers, meta-data, action
393  * data stored in a table entry, mailboxes for extern objects and functions.
394  * Similar to C language structs, they are a well defined sequence of fields,
395  * with each field having a unique name and a constant size.
396  *
397  * In order to use structs to express variable size packet headers such as IPv4
398  * with options, it is allowed for the last field of the struct type to have a
399  * variable size between 0 and *n_bits* bits, with the actual size of this field
400  * determined at run-time for each packet. This struct feature is restricted to
401  * just a few selected instructions that deal with packet headers, so a typical
402  * struct generally has a constant size that is fully known when its struct type
403  * is registered.
404  *
405  * @param[in] p
406  *   Pipeline handle.
407  * @param[in] name
408  *   Struct type name.
409  * @param[in] fields
410  *   The sequence of struct fields.
411  * @param[in] n_fields
412  *   The number of struct fields.
413  * @param[in] last_field_has_variable_size
414  *   If non-zero (true), then the last field has a variable size between 0 and
415  *   *n_bits* bits, with its actual size determined at run-time for each packet.
416  *   If zero (false), then the last field has a constant size of *n_bits* bits.
417  * @return
418  *   0 on success or the following error codes otherwise:
419  *   -EINVAL: Invalid argument;
420  *   -ENOMEM: Not enough space/cannot allocate memory;
421  *   -EEXIST: Struct type with this name already exists.
422  */
423 __rte_experimental
424 int
425 rte_swx_pipeline_struct_type_register(struct rte_swx_pipeline *p,
426 				      const char *name,
427 				      struct rte_swx_field_params *fields,
428 				      uint32_t n_fields,
429 				      int last_field_has_variable_size);
430 
431 /**
432  * Pipeline packet header register
433  *
434  * @param[in] p
435  *   Pipeline handle.
436  * @param[in] name
437  *   Header name.
438  * @param[in] struct_type_name
439  *   The struct type instantiated by this packet header.
440  * @return
441  *   0 on success or the following error codes otherwise:
442  *   -EINVAL: Invalid argument;
443  *   -ENOMEM: Not enough space/cannot allocate memory;
444  *   -EEXIST: Header with this name already exists;
445  *   -ENOSPC: Maximum number of headers reached for the pipeline.
446  */
447 __rte_experimental
448 int
449 rte_swx_pipeline_packet_header_register(struct rte_swx_pipeline *p,
450 					const char *name,
451 					const char *struct_type_name);
452 
453 /**
454  * Pipeline packet meta-data register
455  *
456  * @param[in] p
457  *   Pipeline handle.
458  * @param[in] struct_type_name
459  *   The struct type instantiated by the packet meta-data.
460  * @return
461  *   0 on success or the following error codes otherwise:
462  *   -EINVAL: Invalid argument.
463  */
464 __rte_experimental
465 int
466 rte_swx_pipeline_packet_metadata_register(struct rte_swx_pipeline *p,
467 					  const char *struct_type_name);
468 
469 /*
470  * Instructions
471  */
472 
473 /**
474  * Instruction operands:
475  *
476  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
477  *<pre>|     | Description               | Format           | DST | SRC |</pre>
478  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
479  *<pre>| hdr | Header                    | h.header         |     |     |</pre>
480  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
481  *<pre>| act | Action                    | ACTION           |     |     |</pre>
482  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
483  *<pre>| tbl | Table                     | TABLE            |     |     |</pre>
484  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
485  *<pre>| H   | Header field              | h.header.field   | YES | YES |</pre>
486  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
487  *<pre>| M   | Meta-data field           | m.field          | YES | YES |</pre>
488  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
489  *<pre>| E   | Extern obj mailbox field  | e.ext_obj.field  | YES | YES |</pre>
490  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
491  *<pre>| F   | Extern func mailbox field | f.ext_func.field | YES | YES |</pre>
492  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
493  *<pre>| T   | Table action data field   | t.header.field   | NO  | YES |</pre>
494  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
495  *<pre>| I   | Immediate value (64-bit)  | h.header.field   | NO  | YES |</pre>
496  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
497  *
498  * Instruction set:
499  *
500  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
501  *<pre>| Instr.     | Instruction          | Instruction       | 1st  | 2nd    |</pre>
502  *<pre>| Name       | Description          | Format            | opnd.| opnd.  |</pre>
503  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
504  *<pre>| rx         | Receive one pkt      | rx m.port_in      | M    |        |</pre>
505  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
506  *<pre>| tx         | Transmit one pkt     | tx m.port_out     | M    |        |</pre>
507  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
508  *<pre>| extract    | Extract one hdr      | extract h.hdr     | hdr  |        |</pre>
509  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
510  *<pre>| emit       | Emit one hdr         | emit h.hdr        | hdr  |        |</pre>
511  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
512  *<pre>| validate   | Validate one hdr     | validate h.hdr    | hdr  |        |</pre>
513  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
514  *<pre>| invalidate | Invalidate one hdr   | invalidate h.hdr  | hdr  |        |</pre>
515  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
516  *<pre>| mov        | dst = src            | mov dst src       | HMEF | HMEFTI |</pre>
517  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
518  *<pre>| add        | dst += src           | add dst src       | HMEF | HMEFTI |</pre>
519  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
520  *<pre>| sub        | dst -= src           | add dst src       | HMEF | HMEFTI |</pre>
521  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
522  *<pre>| ckadd      | Checksum add: dst =  | add dst src       | HMEF | HMEFTI |</pre>
523  *<pre>|            | dst '+ src[0:1] '+   |                   |      | or hdr |</pre>
524  *<pre>|            | src[2:3] '+ ...      |                   |      |        |</pre>
525  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
526  *<pre>| cksub      | Checksum subtract:   | add dst src       | HMEF | HMEFTI |</pre>
527  *<pre>|            | dst = dst '- src     |                   |      |        |</pre>
528  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
529  *<pre>| and        | dst &= src           | and dst src       | HMEF | HMEFTI |</pre>
530  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
531  *<pre>| or         | dst |= src           | or  dst src       | HMEF | HMEFTI |</pre>
532  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
533  *<pre>| xor        | dst ^= src           | xor dst src       | HMEF | HMEFTI |</pre>
534  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
535  *<pre>| shl        | dst <<= src          | shl dst src       | HMEF | HMEFTI |</pre>
536  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
537  *<pre>| shr        | dst >>= src          | shr dst src       | HMEF | HMEFTI |</pre>
538  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
539  *<pre>| table      | Table lookup         | table TABLE       | tbl  |        |</pre>
540  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
541  *<pre>| extern     | Ext obj member func  | extern e.obj.mfunc| ext  |        |</pre>
542  *<pre>|            | call or ext func call| extern f.func     |      |        |</pre>
543  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
544  *<pre>| jmp        | Unconditional jump   | jmp LABEL         |      |        |</pre>
545  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
546  *<pre>| jmpv       | Jump if hdr is valid | jmpv LABEL h.hdr  | hdr  |        |</pre>
547  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
548  *<pre>| jmpnv      | Jump if hdr is inval | jmpnv LABEL h.hdr | hdr  |        |</pre>
549  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
550  *<pre>| jmph       | Jump if tbl lkp hit  | jmph LABEL        |      |        |</pre>
551  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
552  *<pre>| jmpnh      | Jump if tbl lkp miss | jmpnh LABEL       |      |        |</pre>
553  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
554  *<pre>| jmpa       | Jump if action run   | jmpa LABEL ACTION | act  |        |</pre>
555  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
556  *<pre>| jmpna      | Jump if act not run  | jmpna LABEL ACTION| act  |        |</pre>
557  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
558  *<pre>| jmpeq      | Jump if (a == b)     | jmpeq LABEL a b   | HMEFT| HMEFTI |</pre>
559  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
560  *<pre>| jmpneq     | Jump if (a != b)     | jmpneq LABEL a b  | HMEFT| HMEFTI |</pre>
561  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
562  *<pre>| jmplt      | Jump if (a < b)      | jmplt LABEL a b   | HMEFT| HMEFTI |</pre>
563  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
564  *<pre>| jmpgt      | Jump if (a > b)      | jmpgt LABEL a b   | HMEFT| HMEFTI |</pre>
565  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
566  *<pre>| return     | Return from action   | return            |      |        |</pre>
567  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
568  *
569  * At initialization time, the pipeline and action instructions (including the
570  * symbolic name operands) are translated to internal data structures that are
571  * used at run-time.
572  */
573 
574 /*
575  * Pipeline action
576  */
577 
578 /**
579  * Pipeline action configure
580  *
581  * @param[in] p
582  *   Pipeline handle.
583  * @param[in] name
584  *   Action name.
585  * @param[in] args_struct_type_name
586  *   The struct type instantiated by the action data. The action data represent
587  *   the action arguments that are stored in the table entry together with the
588  *   action ID. Set to NULL when the action does not have any arguments.
589  * @param[in] instructions
590  *   Action instructions.
591  * @param[in] n_instructions
592  *   Number of action instructions.
593  * @return
594  *   0 on success or the following error codes otherwise:
595  *   -EINVAL: Invalid argument;
596  *   -ENOMEM: Not enough space/cannot allocate memory;
597  *   -EEXIST: Action with this name already exists.
598  */
599 __rte_experimental
600 int
601 rte_swx_pipeline_action_config(struct rte_swx_pipeline *p,
602 			       const char *name,
603 			       const char *args_struct_type_name,
604 			       const char **instructions,
605 			       uint32_t n_instructions);
606 
607 /*
608  * Pipeline table
609  */
610 
611 /**
612  * Pipeline table type register
613  *
614  * @param[in] p
615  *   Pipeline handle.
616  * @param[in] name
617  *   Table type name.
618  * @param[in] match_type
619  *   Match type implemented by the new table type.
620  * @param[in] ops
621  *   Table type operations.
622  * @return
623  *   0 on success or the following error codes otherwise:
624  *   -EINVAL: Invalid argument;
625  *   -ENOMEM: Not enough space/cannot allocate memory;
626  *   -EEXIST: Table type with this name already exists.
627  */
628 __rte_experimental
629 int
630 rte_swx_pipeline_table_type_register(struct rte_swx_pipeline *p,
631 				     const char *name,
632 				     enum rte_swx_table_match_type match_type,
633 				     struct rte_swx_table_ops *ops);
634 
635 /** Match field parameters. */
636 struct rte_swx_match_field_params {
637 	/** Match field name. Must be either a field of one of the registered
638 	 * packet headers ("h.header.field") or a field of the registered
639 	 * meta-data ("m.field").
640 	 */
641 	const char *name;
642 
643 	/** Match type of the field. */
644 	enum rte_swx_table_match_type match_type;
645 };
646 
647 /** Pipeline table parameters. */
648 struct rte_swx_pipeline_table_params {
649 	/** The set of match fields for the current table.
650 	 * Restriction: All the match fields of the current table need to be
651 	 * part of the same struct, i.e. either all the match fields are part of
652 	 * the same header or all the match fields are part of the meta-data.
653 	 */
654 	struct rte_swx_match_field_params *fields;
655 
656 	/** The number of match fields for the current table. If set to zero, no
657 	 * "regular" entries (i.e. entries other than the default entry) can be
658 	 * added to the current table and the match process always results in
659 	 * lookup miss.
660 	 */
661 	uint32_t n_fields;
662 
663 	/** The set of actions for the current table. */
664 	const char **action_names;
665 
666 	/**  Array of *n_actions* flags. For each action, the associated flag
667 	 * indicates whether the action can be assigned to regular table entries
668 	 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set
669 	 * to NULL, it defaults to true for all actions.
670 	 */
671 	int *action_is_for_table_entries;
672 
673 	/**  Array of *n_actions* flags. For each action, the associated flag
674 	 * indicates whether the action can be assigned to the default table
675 	 * entry (when non-zero, i.e. true) or not (when zero, i.e. false).
676 	 * When set to NULL, it defaults to true for all actions.
677 	 */
678 	int *action_is_for_default_entry;
679 
680 	/** The number of actions for the current table. Must be at least one.
681 	 */
682 	uint32_t n_actions;
683 
684 	/** The default table action that gets executed on lookup miss. Must be
685 	 * one of the table actions included in the *action_names*.
686 	 */
687 	const char *default_action_name;
688 
689 	/** Default action arguments. Specified as a string with the format
690 	 * "ARG0_NAME ARG0_VALUE ...". The number of arguments in this string
691 	 * must match exactly the number of arguments of the default action.
692 	 * Must be NULL if the default action does not have any arguments.
693 	 */
694 	const char *default_action_args;
695 
696 	/** If non-zero (true), then the default action of the current table
697 	 * cannot be changed. If zero (false), then the default action can be
698 	 * changed in the future with another action from the *action_names*
699 	 * list.
700 	 */
701 	int default_action_is_const;
702 };
703 
704 /**
705  * Pipeline table configure
706  *
707  * @param[out] p
708  *   Pipeline handle.
709  * @param[in] name
710  *   Table name.
711  * @param[in] params
712  *   Table parameters.
713  * @param[in] recommended_table_type_name
714  *   Recommended table type. Typically set to NULL. Useful as guidance when
715  *   there are multiple table types registered for the match type of the table,
716  *   as determined from the table match fields specification. Silently ignored
717  *   if the recommended table type does not exist or it serves a different match
718  *   type.
719  * @param[in] args
720  *   Table creation arguments.
721  * @param[in] size
722  *   Guideline on maximum number of table entries.
723  * @return
724  *   0 on success or the following error codes otherwise:
725  *   -EINVAL: Invalid argument;
726  *   -ENOMEM: Not enough space/cannot allocate memory;
727  *   -EEXIST: Table with this name already exists;
728  *   -ENODEV: Table creation error.
729  */
730 __rte_experimental
731 int
732 rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
733 			      const char *name,
734 			      struct rte_swx_pipeline_table_params *params,
735 			      const char *recommended_table_type_name,
736 			      const char *args,
737 			      uint32_t size);
738 
739 /** Pipeline selector table parameters. */
740 struct rte_swx_pipeline_selector_params {
741 	/** The group ID field. Input into the selection operation.
742 	 * Restriction: This field must be a meta-data field.
743 	 */
744 	const char *group_id_field_name;
745 
746 	/** The set of fields used to select (through a hashing scheme) the
747 	 * member within the current group. Inputs into the selection operation.
748 	 * Restriction: All the selector fields must be part of the same struct,
749 	 * i.e. part of the same header or part of the meta-data structure.
750 	 */
751 	const char **selector_field_names;
752 
753 	/** The number of selector fields. Must be non-zero. */
754 	uint32_t n_selector_fields;
755 
756 	/** The member ID field. Output from the selection operation.
757 	 * Restriction: This field must be a meta-data field.
758 	 */
759 	const char *member_id_field_name;
760 
761 	/** Maximum number of groups. Must be non-zero. */
762 	uint32_t n_groups_max;
763 
764 	/** Maximum number of members per group. Must be non-zero. */
765 	uint32_t n_members_per_group_max;
766 };
767 
768 /**
769  * Pipeline selector table configure
770  *
771  * @param[out] p
772  *   Pipeline handle.
773  * @param[in] name
774  *   Selector table name.
775  * @param[in] params
776  *   Selector table parameters.
777  * @return
778  *   0 on success or the following error codes otherwise:
779  *   -EINVAL: Invalid argument;
780  *   -ENOMEM: Not enough space/cannot allocate memory;
781  *   -EEXIST: Selector table with this name already exists;
782  *   -ENODEV: Selector table creation error.
783  */
784 __rte_experimental
785 int
786 rte_swx_pipeline_selector_config(struct rte_swx_pipeline *p,
787 				 const char *name,
788 				 struct rte_swx_pipeline_selector_params *params);
789 
790 /** Pipeline learner table parameters. */
791 struct rte_swx_pipeline_learner_params {
792 	/** The set of match fields for the current table.
793 	 * Restriction: All the match fields of the current table need to be
794 	 * part of the same struct, i.e. either all the match fields are part of
795 	 * the same header or all the match fields are part of the meta-data.
796 	 */
797 	const char **field_names;
798 
799 	/** The number of match fields for the current table. Must be non-zero.
800 	 */
801 	uint32_t n_fields;
802 
803 	/** The set of actions for the current table. */
804 	const char **action_names;
805 
806 	/**  Array of *n_actions* flags. For each action, the associated flag
807 	 * indicates whether the action can be assigned to regular table entries
808 	 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set
809 	 * to NULL, it defaults to true for all actions.
810 	 */
811 	int *action_is_for_table_entries;
812 
813 	/**  Array of *n_actions* flags. For each action, the associated flag
814 	 * indicates whether the action can be assigned to the default table
815 	 * entry (when non-zero, i.e. true) or not (when zero, i.e. false).
816 	 * When set to NULL, it defaults to true for all actions.
817 	 */
818 	int *action_is_for_default_entry;
819 
820 	/** The number of actions for the current table. Must be at least one.
821 	 */
822 	uint32_t n_actions;
823 
824 	/** The default table action that gets executed on lookup miss. Must be
825 	 * one of the table actions included in the *action_names*.
826 	 */
827 	const char *default_action_name;
828 
829 	/** Default action arguments. Specified as a string with the format
830 	 * "ARG0_NAME ARG0_VALUE ...". The number of arguments in this string
831 	 * must match exactly the number of arguments of the default action.
832 	 * Must be NULL if the default action does not have any arguments.
833 	 */
834 	const char *default_action_args;
835 
836 	/** If non-zero (true), then the default action of the current table
837 	 * cannot be changed. If zero (false), then the default action can be
838 	 * changed in the future with another action from the *action_names*
839 	 * list.
840 	 */
841 	int default_action_is_const;
842 };
843 
844 /**
845  * Pipeline learner table configure
846  *
847  * @param[out] p
848  *   Pipeline handle.
849  * @param[in] name
850  *   Learner table name.
851  * @param[in] params
852  *   Learner table parameters.
853  * @param[in] size
854  *   The maximum number of table entries. Must be non-zero.
855  * @param[in] timeout
856  *   Array of possible table entry timeouts in seconds. Must be non-NULL.
857  * @param[in] n_timeouts
858  *   Number of elements in the *timeout* array.
859  * @return
860  *   0 on success or the following error codes otherwise:
861  *   -EINVAL: Invalid argument;
862  *   -ENOMEM: Not enough space/cannot allocate memory;
863  *   -EEXIST: Learner table with this name already exists;
864  *   -ENODEV: Learner table creation error.
865  */
866 __rte_experimental
867 int
868 rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p,
869 				const char *name,
870 				struct rte_swx_pipeline_learner_params *params,
871 				uint32_t size,
872 				uint32_t *timeout,
873 				uint32_t n_timeouts);
874 
875 /**
876  * Pipeline register array configure
877  *
878  * @param[in] p
879  *   Pipeline handle.
880  * @param[in] name
881  *   Register array name.
882  * @param[in] size
883  *   Number of registers in the array. Each register is 64-bit in size.
884  * @param[in] init_val
885  *   Initial value for every register in the array. The recommended value is 0.
886  * @return
887  *   0 on success or the following error codes otherwise:
888  *   -EINVAL: Invalid argument;
889  *   -ENOMEM: Not enough space/cannot allocate memory;
890  *   -EEXIST: Register array with this name already exists.
891  */
892 __rte_experimental
893 int
894 rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
895 				 const char *name,
896 				 uint32_t size,
897 				 uint64_t init_val);
898 
899 /**
900  * Pipeline meter array configure
901  *
902  * @param[in] p
903  *   Pipeline handle.
904  * @param[in] name
905  *   Meter array name.
906  * @param[in] size
907  *   Number of meters in the array. Each meter in the array implements the Two
908  *   Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698.
909  * @return
910  *   0 on success or the following error codes otherwise:
911  *   -EINVAL: Invalid argument;
912  *   -ENOMEM: Not enough space/cannot allocate memory;
913  *   -EEXIST: Meter array with this name already exists.
914  */
915 __rte_experimental
916 int
917 rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
918 				 const char *name,
919 				 uint32_t size);
920 
921 /**
922  * Pipeline instructions configure
923  *
924  * @param[in] p
925  *   Pipeline handle.
926  * @param[in] instructions
927  *   Pipeline instructions.
928  * @param[in] n_instructions
929  *   Number of pipeline instructions.
930  * @return
931  *   0 on success or the following error codes otherwise:
932  *   -EINVAL: Invalid argument;
933  *   -ENOMEM: Not enough space/cannot allocate memory.
934  */
935 __rte_experimental
936 int
937 rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
938 				     const char **instructions,
939 				     uint32_t n_instructions);
940 
941 /**
942  * Pipeline build
943  *
944  * Once called, the pipeline build operation marks the end of pipeline
945  * configuration. At this point, all the internal data structures needed to run
946  * the pipeline are built.
947  *
948  * @param[in] p
949  *   Pipeline handle.
950  * @return
951  *   0 on success or the following error codes otherwise:
952  *   -EINVAL: Invalid argument;
953  *   -ENOMEM: Not enough space/cannot allocate memory;
954  *   -EEXIST: Pipeline was already built successfully.
955  */
956 __rte_experimental
957 int
958 rte_swx_pipeline_build(struct rte_swx_pipeline *p);
959 
960 /**
961  * Pipeline C code generate based on input specification file
962  *
963  * @param[in] spec_file
964  *   Pipeline specification file (.spec) provided as input.
965  * @param[in] code_file
966  *   Pipeline C language file (.c) to be generated.
967  * @param[out] err_line
968  *   In case of error and non-NULL, the line number within the *spec* file where
969  *   the error occurred. The first line number in the file is 1.
970  * @param[out] err_msg
971  *   In case of error and non-NULL, the error message.
972  * @return
973  *   0 on success or the following error codes otherwise:
974  *   -EINVAL: Invalid argument;
975  *   -ENOMEM: Not enough space/cannot allocate memory;
976  *   -EEXIST: Resource with the same name already exists.
977  */
978 __rte_experimental
979 int
980 rte_swx_pipeline_codegen(FILE *spec_file,
981 			 FILE *code_file,
982 			 uint32_t *err_line,
983 			 const char **err_msg);
984 
985 /**
986  * Pipeline build from shared object library
987  *
988  * The shared object library must be built from the C language source code file
989  * previously generated by the rte_swx_pipeline_codegen() API function.
990  *
991  * The pipeline I/O specification file defines the I/O ports of the pipeline.
992  *
993  * @param[out] p
994  *   Pipeline handle. Must point to valid memory. Contains valid pipeline handle
995  *   when the function returns successfully.
996  * @param[in] name
997  *   Pipeline unique name.
998  * @param[in] lib_file_name
999  *   Shared object library file name.
1000  * @param[in] iospec_file
1001  *   Pipeline I/O specification file.
1002  * @param[in] numa_node
1003  *   Non-Uniform Memory Access (NUMA) node.
1004  * @return
1005  *   0 on success or the following error codes otherwise:
1006  *   -EINVAL: Invalid argument;
1007  *   -ENOMEM: Not enough space/cannot allocate memory;
1008  *   -EEXIST: Pipeline with this name already exists;
1009  *   -ENODEV: Extern object or table creation error.
1010  */
1011 __rte_experimental
1012 int
1013 rte_swx_pipeline_build_from_lib(struct rte_swx_pipeline **p,
1014 				const char *name,
1015 				const char *lib_file_name,
1016 				FILE *iospec_file,
1017 				int numa_node);
1018 
1019 /**
1020  * Pipeline run
1021  *
1022  * @param[in] p
1023  *   Pipeline handle.
1024  * @param[in] n_instructions
1025  *   Number of instructions to execute.
1026  */
1027 __rte_experimental
1028 void
1029 rte_swx_pipeline_run(struct rte_swx_pipeline *p,
1030 		     uint32_t n_instructions);
1031 
1032 /**
1033  * Pipeline flush
1034  *
1035  * Flush all output ports of the pipeline.
1036  *
1037  * @param[in] p
1038  *   Pipeline handle.
1039  *   If p is NULL, no operation is performed.
1040  */
1041 __rte_experimental
1042 void
1043 rte_swx_pipeline_flush(struct rte_swx_pipeline *p);
1044 
1045 /**
1046  * Pipeline free
1047  *
1048  * @param[in] p
1049  *   Pipeline handle.
1050  */
1051 __rte_experimental
1052 void
1053 rte_swx_pipeline_free(struct rte_swx_pipeline *p);
1054 
1055 #ifdef __cplusplus
1056 }
1057 #endif
1058 
1059 #endif
1060