xref: /dpdk/lib/pipeline/rte_swx_pipeline.h (revision 87d396163c005deb8d9f72ec0977f19e5edd8f47)
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  * Pipeline hash function register
336  *
337  * @param[in] p
338  *   Pipeline handle.
339  * @param[in] name
340  *   Hash function name.
341  * @param[in] func
342  *   Hash function.
343  * @return
344  *   0 on success or the following error codes otherwise:
345  *   -EINVAL: Invalid argument;
346  *   -ENOMEM: Not enough space/cannot allocate memory;
347  *   -EEXIST: Hash function with this name already exists.
348  */
349 __rte_experimental
350 int
351 rte_swx_pipeline_hash_func_register(struct rte_swx_pipeline *p,
352 				    const char *name,
353 				    rte_swx_hash_func_t func);
354 
355 /*
356  * Packet headers and meta-data
357  */
358 
359 /** Structure (struct) field. */
360 struct rte_swx_field_params {
361 	/** Struct field name. */
362 	const char *name;
363 
364 	/** Struct field size (in bits).
365 	 * Restriction: All struct fields must be a multiple of 8 bits.
366 	 * Restriction: All struct fields must be no greater than 64 bits.
367 	 */
368 	uint32_t n_bits;
369 };
370 
371 /**
372  * Pipeline struct type register
373  *
374  * Structs are used extensively in many part of the pipeline to define the size
375  * and layout of a specific memory piece such as: headers, meta-data, action
376  * data stored in a table entry, mailboxes for extern objects and functions.
377  * Similar to C language structs, they are a well defined sequence of fields,
378  * with each field having a unique name and a constant size.
379  *
380  * In order to use structs to express variable size packet headers such as IPv4
381  * with options, it is allowed for the last field of the struct type to have a
382  * variable size between 0 and *n_bits* bits, with the actual size of this field
383  * determined at run-time for each packet. This struct feature is restricted to
384  * just a few selected instructions that deal with packet headers, so a typical
385  * struct generally has a constant size that is fully known when its struct type
386  * is registered.
387  *
388  * @param[in] p
389  *   Pipeline handle.
390  * @param[in] name
391  *   Struct type name.
392  * @param[in] fields
393  *   The sequence of struct fields.
394  * @param[in] n_fields
395  *   The number of struct fields.
396  * @param[in] last_field_has_variable_size
397  *   If non-zero (true), then the last field has a variable size between 0 and
398  *   *n_bits* bits, with its actual size determined at run-time for each packet.
399  *   If zero (false), then the last field has a constant size of *n_bits* bits.
400  * @return
401  *   0 on success or the following error codes otherwise:
402  *   -EINVAL: Invalid argument;
403  *   -ENOMEM: Not enough space/cannot allocate memory;
404  *   -EEXIST: Struct type with this name already exists.
405  */
406 __rte_experimental
407 int
408 rte_swx_pipeline_struct_type_register(struct rte_swx_pipeline *p,
409 				      const char *name,
410 				      struct rte_swx_field_params *fields,
411 				      uint32_t n_fields,
412 				      int last_field_has_variable_size);
413 
414 /**
415  * Pipeline packet header register
416  *
417  * @param[in] p
418  *   Pipeline handle.
419  * @param[in] name
420  *   Header name.
421  * @param[in] struct_type_name
422  *   The struct type instantiated by this packet header.
423  * @return
424  *   0 on success or the following error codes otherwise:
425  *   -EINVAL: Invalid argument;
426  *   -ENOMEM: Not enough space/cannot allocate memory;
427  *   -EEXIST: Header with this name already exists;
428  *   -ENOSPC: Maximum number of headers reached for the pipeline.
429  */
430 __rte_experimental
431 int
432 rte_swx_pipeline_packet_header_register(struct rte_swx_pipeline *p,
433 					const char *name,
434 					const char *struct_type_name);
435 
436 /**
437  * Pipeline packet meta-data register
438  *
439  * @param[in] p
440  *   Pipeline handle.
441  * @param[in] struct_type_name
442  *   The struct type instantiated by the packet meta-data.
443  * @return
444  *   0 on success or the following error codes otherwise:
445  *   -EINVAL: Invalid argument.
446  */
447 __rte_experimental
448 int
449 rte_swx_pipeline_packet_metadata_register(struct rte_swx_pipeline *p,
450 					  const char *struct_type_name);
451 
452 /*
453  * Instructions
454  */
455 
456 /**
457  * Instruction operands:
458  *
459  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
460  *<pre>|     | Description               | Format           | DST | SRC |</pre>
461  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
462  *<pre>| hdr | Header                    | h.header         |     |     |</pre>
463  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
464  *<pre>| act | Action                    | ACTION           |     |     |</pre>
465  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
466  *<pre>| tbl | Table                     | TABLE            |     |     |</pre>
467  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
468  *<pre>| H   | Header field              | h.header.field   | YES | YES |</pre>
469  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
470  *<pre>| M   | Meta-data field           | m.field          | YES | YES |</pre>
471  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
472  *<pre>| E   | Extern obj mailbox field  | e.ext_obj.field  | YES | YES |</pre>
473  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
474  *<pre>| F   | Extern func mailbox field | f.ext_func.field | YES | YES |</pre>
475  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
476  *<pre>| T   | Table action data field   | t.header.field   | NO  | YES |</pre>
477  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
478  *<pre>| I   | Immediate value (64-bit)  | h.header.field   | NO  | YES |</pre>
479  *<pre>+-----+---------------------------+------------------+-----+-----+</pre>
480  *
481  * Instruction set:
482  *
483  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
484  *<pre>| Instr.     | Instruction          | Instruction       | 1st  | 2nd    |</pre>
485  *<pre>| Name       | Description          | Format            | opnd.| opnd.  |</pre>
486  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
487  *<pre>| rx         | Receive one pkt      | rx m.port_in      | M    |        |</pre>
488  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
489  *<pre>| tx         | Transmit one pkt     | tx m.port_out     | M    |        |</pre>
490  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
491  *<pre>| extract    | Extract one hdr      | extract h.hdr     | hdr  |        |</pre>
492  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
493  *<pre>| emit       | Emit one hdr         | emit h.hdr        | hdr  |        |</pre>
494  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
495  *<pre>| validate   | Validate one hdr     | validate h.hdr    | hdr  |        |</pre>
496  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
497  *<pre>| invalidate | Invalidate one hdr   | invalidate h.hdr  | hdr  |        |</pre>
498  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
499  *<pre>| mov        | dst = src            | mov dst src       | HMEF | HMEFTI |</pre>
500  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
501  *<pre>| add        | dst += src           | add dst src       | HMEF | HMEFTI |</pre>
502  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
503  *<pre>| sub        | dst -= src           | add dst src       | HMEF | HMEFTI |</pre>
504  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
505  *<pre>| ckadd      | Checksum add: dst =  | add dst src       | HMEF | HMEFTI |</pre>
506  *<pre>|            | dst '+ src[0:1] '+   |                   |      | or hdr |</pre>
507  *<pre>|            | src[2:3] '+ ...      |                   |      |        |</pre>
508  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
509  *<pre>| cksub      | Checksum subtract:   | add dst src       | HMEF | HMEFTI |</pre>
510  *<pre>|            | dst = dst '- src     |                   |      |        |</pre>
511  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
512  *<pre>| and        | dst &= src           | and dst src       | HMEF | HMEFTI |</pre>
513  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
514  *<pre>| or         | dst |= src           | or  dst src       | HMEF | HMEFTI |</pre>
515  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
516  *<pre>| xor        | dst ^= src           | xor dst src       | HMEF | HMEFTI |</pre>
517  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
518  *<pre>| shl        | dst <<= src          | shl dst src       | HMEF | HMEFTI |</pre>
519  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
520  *<pre>| shr        | dst >>= src          | shr dst src       | HMEF | HMEFTI |</pre>
521  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
522  *<pre>| table      | Table lookup         | table TABLE       | tbl  |        |</pre>
523  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
524  *<pre>| extern     | Ext obj member func  | extern e.obj.mfunc| ext  |        |</pre>
525  *<pre>|            | call or ext func call| extern f.func     |      |        |</pre>
526  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
527  *<pre>| jmp        | Unconditional jump   | jmp LABEL         |      |        |</pre>
528  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
529  *<pre>| jmpv       | Jump if hdr is valid | jmpv LABEL h.hdr  | hdr  |        |</pre>
530  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
531  *<pre>| jmpnv      | Jump if hdr is inval | jmpnv LABEL h.hdr | hdr  |        |</pre>
532  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
533  *<pre>| jmph       | Jump if tbl lkp hit  | jmph LABEL        |      |        |</pre>
534  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
535  *<pre>| jmpnh      | Jump if tbl lkp miss | jmpnh LABEL       |      |        |</pre>
536  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
537  *<pre>| jmpa       | Jump if action run   | jmpa LABEL ACTION | act  |        |</pre>
538  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
539  *<pre>| jmpna      | Jump if act not run  | jmpna LABEL ACTION| act  |        |</pre>
540  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
541  *<pre>| jmpeq      | Jump if (a == b)     | jmpeq LABEL a b   | HMEFT| HMEFTI |</pre>
542  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
543  *<pre>| jmpneq     | Jump if (a != b)     | jmpneq LABEL a b  | HMEFT| HMEFTI |</pre>
544  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
545  *<pre>| jmplt      | Jump if (a < b)      | jmplt LABEL a b   | HMEFT| HMEFTI |</pre>
546  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
547  *<pre>| jmpgt      | Jump if (a > b)      | jmpgt LABEL a b   | HMEFT| HMEFTI |</pre>
548  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
549  *<pre>| return     | Return from action   | return            |      |        |</pre>
550  *<pre>+------------+----------------------+-------------------+------+--------+</pre>
551  *
552  * At initialization time, the pipeline and action instructions (including the
553  * symbolic name operands) are translated to internal data structures that are
554  * used at run-time.
555  */
556 
557 /*
558  * Pipeline action
559  */
560 
561 /**
562  * Pipeline action configure
563  *
564  * @param[in] p
565  *   Pipeline handle.
566  * @param[in] name
567  *   Action name.
568  * @param[in] args_struct_type_name
569  *   The struct type instantiated by the action data. The action data represent
570  *   the action arguments that are stored in the table entry together with the
571  *   action ID. Set to NULL when the action does not have any arguments.
572  * @param[in] instructions
573  *   Action instructions.
574  * @param[in] n_instructions
575  *   Number of action instructions.
576  * @return
577  *   0 on success or the following error codes otherwise:
578  *   -EINVAL: Invalid argument;
579  *   -ENOMEM: Not enough space/cannot allocate memory;
580  *   -EEXIST: Action with this name already exists.
581  */
582 __rte_experimental
583 int
584 rte_swx_pipeline_action_config(struct rte_swx_pipeline *p,
585 			       const char *name,
586 			       const char *args_struct_type_name,
587 			       const char **instructions,
588 			       uint32_t n_instructions);
589 
590 /*
591  * Pipeline table
592  */
593 
594 /**
595  * Pipeline table type register
596  *
597  * @param[in] p
598  *   Pipeline handle.
599  * @param[in] name
600  *   Table type name.
601  * @param[in] match_type
602  *   Match type implemented by the new table type.
603  * @param[in] ops
604  *   Table type operations.
605  * @return
606  *   0 on success or the following error codes otherwise:
607  *   -EINVAL: Invalid argument;
608  *   -ENOMEM: Not enough space/cannot allocate memory;
609  *   -EEXIST: Table type with this name already exists.
610  */
611 __rte_experimental
612 int
613 rte_swx_pipeline_table_type_register(struct rte_swx_pipeline *p,
614 				     const char *name,
615 				     enum rte_swx_table_match_type match_type,
616 				     struct rte_swx_table_ops *ops);
617 
618 /** Match field parameters. */
619 struct rte_swx_match_field_params {
620 	/** Match field name. Must be either a field of one of the registered
621 	 * packet headers ("h.header.field") or a field of the registered
622 	 * meta-data ("m.field").
623 	 */
624 	const char *name;
625 
626 	/** Match type of the field. */
627 	enum rte_swx_table_match_type match_type;
628 };
629 
630 /** Pipeline table parameters. */
631 struct rte_swx_pipeline_table_params {
632 	/** The set of match fields for the current table.
633 	 * Restriction: All the match fields of the current table need to be
634 	 * part of the same struct, i.e. either all the match fields are part of
635 	 * the same header or all the match fields are part of the meta-data.
636 	 */
637 	struct rte_swx_match_field_params *fields;
638 
639 	/** The number of match fields for the current table. If set to zero, no
640 	 * "regular" entries (i.e. entries other than the default entry) can be
641 	 * added to the current table and the match process always results in
642 	 * lookup miss.
643 	 */
644 	uint32_t n_fields;
645 
646 	/** The set of actions for the current table. */
647 	const char **action_names;
648 
649 	/**  Array of *n_actions* flags. For each action, the associated flag
650 	 * indicates whether the action can be assigned to regular table entries
651 	 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set
652 	 * to NULL, it defaults to true for all actions.
653 	 */
654 	int *action_is_for_table_entries;
655 
656 	/**  Array of *n_actions* flags. For each action, the associated flag
657 	 * indicates whether the action can be assigned to the default table
658 	 * entry (when non-zero, i.e. true) or not (when zero, i.e. false).
659 	 * When set to NULL, it defaults to true for all actions.
660 	 */
661 	int *action_is_for_default_entry;
662 
663 	/** The number of actions for the current table. Must be at least one.
664 	 */
665 	uint32_t n_actions;
666 
667 	/** The default table action that gets executed on lookup miss. Must be
668 	 * one of the table actions included in the *action_names*.
669 	 */
670 	const char *default_action_name;
671 
672 	/** Default action arguments. Specified as a string with the format
673 	 * "ARG0_NAME ARG0_VALUE ...". The number of arguments in this string
674 	 * must match exactly the number of arguments of the default action.
675 	 * Must be NULL if the default action does not have any arguments.
676 	 */
677 	const char *default_action_args;
678 
679 	/** If non-zero (true), then the default action of the current table
680 	 * cannot be changed. If zero (false), then the default action can be
681 	 * changed in the future with another action from the *action_names*
682 	 * list.
683 	 */
684 	int default_action_is_const;
685 
686 	/** Hash function name. When not set to NULL, it must point to one of
687 	 * the hash functions that were registered for the current pipeline.
688 	 * Ignored by the table implementation when not needed. When needed but
689 	 * NULL, the table implementation will select the hash function to use.
690 	 */
691 	const char *hash_func_name;
692 };
693 
694 /**
695  * Pipeline table configure
696  *
697  * @param[out] p
698  *   Pipeline handle.
699  * @param[in] name
700  *   Table name.
701  * @param[in] params
702  *   Table parameters.
703  * @param[in] recommended_table_type_name
704  *   Recommended table type. Typically set to NULL. Useful as guidance when
705  *   there are multiple table types registered for the match type of the table,
706  *   as determined from the table match fields specification. Silently ignored
707  *   if the recommended table type does not exist or it serves a different match
708  *   type.
709  * @param[in] args
710  *   Table creation arguments.
711  * @param[in] size
712  *   Guideline on maximum number of table entries.
713  * @return
714  *   0 on success or the following error codes otherwise:
715  *   -EINVAL: Invalid argument;
716  *   -ENOMEM: Not enough space/cannot allocate memory;
717  *   -EEXIST: Table with this name already exists;
718  *   -ENODEV: Table creation error.
719  */
720 __rte_experimental
721 int
722 rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
723 			      const char *name,
724 			      struct rte_swx_pipeline_table_params *params,
725 			      const char *recommended_table_type_name,
726 			      const char *args,
727 			      uint32_t size);
728 
729 /** Pipeline selector table parameters. */
730 struct rte_swx_pipeline_selector_params {
731 	/** The group ID field. Input into the selection operation.
732 	 * Restriction: This field must be a meta-data field.
733 	 */
734 	const char *group_id_field_name;
735 
736 	/** The set of fields used to select (through a hashing scheme) the
737 	 * member within the current group. Inputs into the selection operation.
738 	 * Restriction: All the selector fields must be part of the same struct,
739 	 * i.e. part of the same header or part of the meta-data structure.
740 	 */
741 	const char **selector_field_names;
742 
743 	/** The number of selector fields. Must be non-zero. */
744 	uint32_t n_selector_fields;
745 
746 	/** The member ID field. Output from the selection operation.
747 	 * Restriction: This field must be a meta-data field.
748 	 */
749 	const char *member_id_field_name;
750 
751 	/** Maximum number of groups. Must be non-zero. */
752 	uint32_t n_groups_max;
753 
754 	/** Maximum number of members per group. Must be non-zero. */
755 	uint32_t n_members_per_group_max;
756 };
757 
758 /**
759  * Pipeline selector table configure
760  *
761  * @param[out] p
762  *   Pipeline handle.
763  * @param[in] name
764  *   Selector table name.
765  * @param[in] params
766  *   Selector table parameters.
767  * @return
768  *   0 on success or the following error codes otherwise:
769  *   -EINVAL: Invalid argument;
770  *   -ENOMEM: Not enough space/cannot allocate memory;
771  *   -EEXIST: Selector table with this name already exists;
772  *   -ENODEV: Selector table creation error.
773  */
774 __rte_experimental
775 int
776 rte_swx_pipeline_selector_config(struct rte_swx_pipeline *p,
777 				 const char *name,
778 				 struct rte_swx_pipeline_selector_params *params);
779 
780 /** Pipeline learner table parameters. */
781 struct rte_swx_pipeline_learner_params {
782 	/** The set of match fields for the current table.
783 	 * Restriction: All the match fields of the current table need to be
784 	 * part of the same struct, i.e. either all the match fields are part of
785 	 * the same header or all the match fields are part of the meta-data.
786 	 */
787 	const char **field_names;
788 
789 	/** The number of match fields for the current table. Must be non-zero.
790 	 */
791 	uint32_t n_fields;
792 
793 	/** The set of actions for the current table. */
794 	const char **action_names;
795 
796 	/**  Array of *n_actions* flags. For each action, the associated flag
797 	 * indicates whether the action can be assigned to regular table entries
798 	 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set
799 	 * to NULL, it defaults to true for all actions.
800 	 */
801 	int *action_is_for_table_entries;
802 
803 	/**  Array of *n_actions* flags. For each action, the associated flag
804 	 * indicates whether the action can be assigned to the default table
805 	 * entry (when non-zero, i.e. true) or not (when zero, i.e. false).
806 	 * When set to NULL, it defaults to true for all actions.
807 	 */
808 	int *action_is_for_default_entry;
809 
810 	/** The number of actions for the current table. Must be at least one.
811 	 */
812 	uint32_t n_actions;
813 
814 	/** The default table action that gets executed on lookup miss. Must be
815 	 * one of the table actions included in the *action_names*.
816 	 */
817 	const char *default_action_name;
818 
819 	/** Default action arguments. Specified as a string with the format
820 	 * "ARG0_NAME ARG0_VALUE ...". The number of arguments in this string
821 	 * must match exactly the number of arguments of the default action.
822 	 * Must be NULL if the default action does not have any arguments.
823 	 */
824 	const char *default_action_args;
825 
826 	/** If non-zero (true), then the default action of the current table
827 	 * cannot be changed. If zero (false), then the default action can be
828 	 * changed in the future with another action from the *action_names*
829 	 * list.
830 	 */
831 	int default_action_is_const;
832 
833 	/** Hash function name. When not set to NULL, it must point to one of
834 	 * the hash functions that were registered for the current pipeline.
835 	 * When NULL, the default hash function will be used.
836 	 */
837 	const char *hash_func_name;
838 };
839 
840 /**
841  * Pipeline learner table configure
842  *
843  * @param[out] p
844  *   Pipeline handle.
845  * @param[in] name
846  *   Learner table name.
847  * @param[in] params
848  *   Learner table parameters.
849  * @param[in] size
850  *   The maximum number of table entries. Must be non-zero.
851  * @param[in] timeout
852  *   Array of possible table entry timeouts in seconds. Must be non-NULL.
853  * @param[in] n_timeouts
854  *   Number of elements in the *timeout* array.
855  * @return
856  *   0 on success or the following error codes otherwise:
857  *   -EINVAL: Invalid argument;
858  *   -ENOMEM: Not enough space/cannot allocate memory;
859  *   -EEXIST: Learner table with this name already exists;
860  *   -ENODEV: Learner table creation error.
861  */
862 __rte_experimental
863 int
864 rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p,
865 				const char *name,
866 				struct rte_swx_pipeline_learner_params *params,
867 				uint32_t size,
868 				uint32_t *timeout,
869 				uint32_t n_timeouts);
870 
871 /**
872  * Pipeline register array configure
873  *
874  * @param[in] p
875  *   Pipeline handle.
876  * @param[in] name
877  *   Register array name.
878  * @param[in] size
879  *   Number of registers in the array. Each register is 64-bit in size.
880  * @param[in] init_val
881  *   Initial value for every register in the array. The recommended value is 0.
882  * @return
883  *   0 on success or the following error codes otherwise:
884  *   -EINVAL: Invalid argument;
885  *   -ENOMEM: Not enough space/cannot allocate memory;
886  *   -EEXIST: Register array with this name already exists.
887  */
888 __rte_experimental
889 int
890 rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
891 				 const char *name,
892 				 uint32_t size,
893 				 uint64_t init_val);
894 
895 /**
896  * Pipeline meter array configure
897  *
898  * @param[in] p
899  *   Pipeline handle.
900  * @param[in] name
901  *   Meter array name.
902  * @param[in] size
903  *   Number of meters in the array. Each meter in the array implements the Two
904  *   Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698.
905  * @return
906  *   0 on success or the following error codes otherwise:
907  *   -EINVAL: Invalid argument;
908  *   -ENOMEM: Not enough space/cannot allocate memory;
909  *   -EEXIST: Meter array with this name already exists.
910  */
911 __rte_experimental
912 int
913 rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
914 				 const char *name,
915 				 uint32_t size);
916 
917 /**
918  * Pipeline instructions configure
919  *
920  * @param[in] p
921  *   Pipeline handle.
922  * @param[in] instructions
923  *   Pipeline instructions.
924  * @param[in] n_instructions
925  *   Number of pipeline instructions.
926  * @return
927  *   0 on success or the following error codes otherwise:
928  *   -EINVAL: Invalid argument;
929  *   -ENOMEM: Not enough space/cannot allocate memory.
930  */
931 __rte_experimental
932 int
933 rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
934 				     const char **instructions,
935 				     uint32_t n_instructions);
936 
937 /**
938  * Pipeline build
939  *
940  * Once called, the pipeline build operation marks the end of pipeline
941  * configuration. At this point, all the internal data structures needed to run
942  * the pipeline are built.
943  *
944  * @param[in] p
945  *   Pipeline handle.
946  * @return
947  *   0 on success or the following error codes otherwise:
948  *   -EINVAL: Invalid argument;
949  *   -ENOMEM: Not enough space/cannot allocate memory;
950  *   -EEXIST: Pipeline was already built successfully.
951  */
952 __rte_experimental
953 int
954 rte_swx_pipeline_build(struct rte_swx_pipeline *p);
955 
956 /**
957  * Pipeline C code generate based on input specification file
958  *
959  * @param[in] spec_file
960  *   Pipeline specification file (.spec) provided as input.
961  * @param[in] code_file
962  *   Pipeline C language file (.c) to be generated.
963  * @param[out] err_line
964  *   In case of error and non-NULL, the line number within the *spec* file where
965  *   the error occurred. The first line number in the file is 1.
966  * @param[out] err_msg
967  *   In case of error and non-NULL, the error message.
968  * @return
969  *   0 on success or the following error codes otherwise:
970  *   -EINVAL: Invalid argument;
971  *   -ENOMEM: Not enough space/cannot allocate memory;
972  *   -EEXIST: Resource with the same name already exists.
973  */
974 __rte_experimental
975 int
976 rte_swx_pipeline_codegen(FILE *spec_file,
977 			 FILE *code_file,
978 			 uint32_t *err_line,
979 			 const char **err_msg);
980 
981 /**
982  * Pipeline build from shared object library
983  *
984  * The shared object library must be built from the C language source code file
985  * previously generated by the rte_swx_pipeline_codegen() API function.
986  *
987  * The pipeline I/O specification file defines the I/O ports of the pipeline.
988  *
989  * @param[out] p
990  *   Pipeline handle. Must point to valid memory. Contains valid pipeline handle
991  *   when the function returns successfully.
992  * @param[in] name
993  *   Pipeline unique name.
994  * @param[in] lib_file_name
995  *   Shared object library file name.
996  * @param[in] iospec_file
997  *   Pipeline I/O specification file.
998  * @param[in] numa_node
999  *   Non-Uniform Memory Access (NUMA) node.
1000  * @return
1001  *   0 on success or the following error codes otherwise:
1002  *   -EINVAL: Invalid argument;
1003  *   -ENOMEM: Not enough space/cannot allocate memory;
1004  *   -EEXIST: Pipeline with this name already exists;
1005  *   -ENODEV: Extern object or table creation error.
1006  */
1007 __rte_experimental
1008 int
1009 rte_swx_pipeline_build_from_lib(struct rte_swx_pipeline **p,
1010 				const char *name,
1011 				const char *lib_file_name,
1012 				FILE *iospec_file,
1013 				int numa_node);
1014 
1015 /**
1016  * Pipeline run
1017  *
1018  * @param[in] p
1019  *   Pipeline handle.
1020  * @param[in] n_instructions
1021  *   Number of instructions to execute.
1022  */
1023 __rte_experimental
1024 void
1025 rte_swx_pipeline_run(struct rte_swx_pipeline *p,
1026 		     uint32_t n_instructions);
1027 
1028 /**
1029  * Pipeline flush
1030  *
1031  * Flush all output ports of the pipeline.
1032  *
1033  * @param[in] p
1034  *   Pipeline handle.
1035  *   If p is NULL, no operation is performed.
1036  */
1037 __rte_experimental
1038 void
1039 rte_swx_pipeline_flush(struct rte_swx_pipeline *p);
1040 
1041 /**
1042  * Pipeline free
1043  *
1044  * @param[in] p
1045  *   Pipeline handle.
1046  */
1047 __rte_experimental
1048 void
1049 rte_swx_pipeline_free(struct rte_swx_pipeline *p);
1050 
1051 #ifdef __cplusplus
1052 }
1053 #endif
1054 
1055 #endif
1056