xref: /dpdk/lib/pipeline/rte_swx_ctl.h (revision 8f1d23ece06adff5eae9f1b4365bdbbd3abee2b2)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4 #ifndef __INCLUDE_RTE_SWX_CTL_H__
5 #define __INCLUDE_RTE_SWX_CTL_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 /**
12  * @file
13  * RTE SWX Pipeline Control
14  */
15 
16 #include <stdint.h>
17 #include <stdio.h>
18 
19 #include <rte_compat.h>
20 #include <rte_meter.h>
21 
22 #include "rte_swx_port.h"
23 #include "rte_swx_table.h"
24 
25 struct rte_swx_pipeline;
26 
27 /** Name size. */
28 #ifndef RTE_SWX_CTL_NAME_SIZE
29 #define RTE_SWX_CTL_NAME_SIZE 64
30 #endif
31 
32 /*
33  * Pipeline Query API.
34  */
35 
36 /** Pipeline info. */
37 struct rte_swx_ctl_pipeline_info {
38 	/** Pipeline name. */
39 	char name[RTE_SWX_CTL_NAME_SIZE];
40 
41 	/** Number of input ports. */
42 	uint32_t n_ports_in;
43 
44 	/** Number of input ports. */
45 	uint32_t n_ports_out;
46 
47 	/** Number of packet mirroring slots. */
48 	uint32_t n_mirroring_slots;
49 
50 	/** Number of packet mirroring sessions. */
51 	uint32_t n_mirroring_sessions;
52 
53 	/** Number of actions. */
54 	uint32_t n_actions;
55 
56 	/** Number of tables. */
57 	uint32_t n_tables;
58 
59 	/** Number of selector tables. */
60 	uint32_t n_selectors;
61 
62 	/** Number of learner tables. */
63 	uint32_t n_learners;
64 
65 	/** Number of register arrays. */
66 	uint32_t n_regarrays;
67 
68 	/** Number of meter arrays. */
69 	uint32_t n_metarrays;
70 };
71 
72 /**
73  * Pipeline info get
74  *
75  * @param[in] p
76  *   Pipeline handle.
77  * @param[out] pipeline
78  *   Pipeline info.
79  * @return
80  *   0 on success or the following error codes otherwise:
81  *   -EINVAL: Invalid argument.
82  */
83 __rte_experimental
84 int
85 rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
86 			      struct rte_swx_ctl_pipeline_info *pipeline);
87 
88 /**
89  * Pipeline NUMA node get
90  *
91  * @param[in] p
92  *   Pipeline handle.
93  * @param[out] numa_node
94  *   Pipeline NUMA node.
95  * @return
96  *   0 on success or the following error codes otherwise:
97  *   -EINVAL: Invalid argument.
98  */
99 __rte_experimental
100 int
101 rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p,
102 				   int *numa_node);
103 
104 /*
105  * Ports Query API.
106  */
107 
108 /**
109  * Input port statistics counters read
110  *
111  * @param[in] p
112  *   Pipeline handle.
113  * @param[in] port_id
114  *   Port ID (0 .. *n_ports_in* - 1).
115  * @param[out] stats
116  *   Input port stats.
117  * @return
118  *   0 on success or the following error codes otherwise:
119  *   -EINVAL: Invalid argument.
120  */
121 __rte_experimental
122 int
123 rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
124 					uint32_t port_id,
125 					struct rte_swx_port_in_stats *stats);
126 
127 /**
128  * Output port statistics counters read
129  *
130  * @param[in] p
131  *   Pipeline handle.
132  * @param[in] port_id
133  *   Port ID (0 .. *n_ports_out* - 1).
134  * @param[out] stats
135  *   Output port stats.
136  * @return
137  *   0 on success or the following error codes otherwise:
138  *   -EINVAL: Invalid argument.
139  */
140 __rte_experimental
141 int
142 rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
143 					 uint32_t port_id,
144 					 struct rte_swx_port_out_stats *stats);
145 
146 /*
147  * Action Query API.
148  */
149 
150 /** Action info. */
151 struct rte_swx_ctl_action_info {
152 	/** Action name. */
153 	char name[RTE_SWX_CTL_NAME_SIZE];
154 
155 	/** Number of action arguments. */
156 	uint32_t n_args;
157 };
158 
159 /**
160  * Action info get
161  *
162  * @param[in] p
163  *   Pipeline handle.
164  * @param[in] action_id
165  *   Action ID (0 .. *n_actions* - 1).
166  * @param[out] action
167  *   Action info.
168  * @return
169  *   0 on success or the following error codes otherwise:
170  *   -EINVAL: Invalid argument.
171  */
172 __rte_experimental
173 int
174 rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
175 			    uint32_t action_id,
176 			    struct rte_swx_ctl_action_info *action);
177 
178 /** Action argument info. */
179 struct rte_swx_ctl_action_arg_info {
180 	/** Action argument name. */
181 	char name[RTE_SWX_CTL_NAME_SIZE];
182 
183 	/** Action argument size (in bits). */
184 	uint32_t n_bits;
185 
186 	/** Non-zero (true) when this action argument must be stored in the
187 	 * table in network byte order (NBO), zero when it must be stored in
188 	 * host byte order (HBO).
189 	 */
190 	int is_network_byte_order;
191 };
192 
193 /**
194  * Action argument info get
195  *
196  * @param[in] p
197  *   Pipeline handle.
198  * @param[in] action_id
199  *   Action ID (0 .. *n_actions* - 1).
200  * @param[in] action_arg_id
201  *   Action ID (0 .. *n_args* - 1).
202  * @param[out] action_arg
203  *   Action argument info.
204  * @return
205  *   0 on success or the following error codes otherwise:
206  *   -EINVAL: Invalid argument.
207  */
208 __rte_experimental
209 int
210 rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
211 				uint32_t action_id,
212 				uint32_t action_arg_id,
213 				struct rte_swx_ctl_action_arg_info *action_arg);
214 
215 /*
216  * Table Query API.
217  */
218 
219 /** Table info. */
220 struct rte_swx_ctl_table_info {
221 	/** Table name. */
222 	char name[RTE_SWX_CTL_NAME_SIZE];
223 
224 	/** Table creation arguments. */
225 	char args[RTE_SWX_CTL_NAME_SIZE];
226 
227 	/** Number of match fields. */
228 	uint32_t n_match_fields;
229 
230 	/** Number of actions. */
231 	uint32_t n_actions;
232 
233 	/** Non-zero (true) when the default action is constant, therefore it
234 	 * cannot be changed; zero (false) when the default action not constant,
235 	 * therefore it can be changed.
236 	 */
237 	int default_action_is_const;
238 
239 	/** Table size parameter. */
240 	uint32_t size;
241 };
242 
243 /**
244  * Table info get
245  *
246  * @param[in] p
247  *   Pipeline handle.
248  * @param[in] table_id
249  *   Table ID (0 .. *n_tables* - 1).
250  * @param[out] table
251  *   Table info.
252  * @return
253  *   0 on success or the following error codes otherwise:
254  *   -EINVAL: Invalid argument.
255  */
256 __rte_experimental
257 int
258 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
259 			   uint32_t table_id,
260 			   struct rte_swx_ctl_table_info *table);
261 
262 /** Table match field info.
263  *
264  * If (n_bits, offset) are known for all the match fields of the table, then the
265  * table (key_offset, key_size, key_mask0) can be computed.
266  */
267 struct rte_swx_ctl_table_match_field_info {
268 	/** Match type of the current match field. */
269 	enum rte_swx_table_match_type match_type;
270 
271 	/** Non-zero (true) when the current match field is part of a registered
272 	 * header, zero (false) when it is part of the registered meta-data.
273 	 */
274 	int is_header;
275 
276 	/** Match field size (in bits). */
277 	uint32_t n_bits;
278 
279 	/** Match field offset within its parent struct (one of the headers or
280 	 * the meta-data).
281 	 */
282 	uint32_t offset;
283 };
284 
285 /**
286  * Table match field info get
287  *
288  * @param[in] p
289  *   Pipeline handle.
290  * @param[in] table_id
291  *   Table ID (0 .. *n_tables*).
292  * @param[in] match_field_id
293  *   Match field ID (0 .. *n_match_fields* - 1).
294  * @param[out] match_field
295  *   Table match field info.
296  * @return
297  *   0 on success or the following error codes otherwise:
298  *   -EINVAL: Invalid argument.
299  */
300 __rte_experimental
301 int
302 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
303 	uint32_t table_id,
304 	uint32_t match_field_id,
305 	struct rte_swx_ctl_table_match_field_info *match_field);
306 
307 /** Table action info. */
308 struct rte_swx_ctl_table_action_info {
309 	/** Action ID. */
310 	uint32_t action_id;
311 
312 	/**  When non-zero (true), the action can be assigned to regular table entries. */
313 	int action_is_for_table_entries;
314 
315 	/**  When non-zero (true), the action can be assigned to the table default entry. */
316 	int action_is_for_default_entry;
317 };
318 
319 /**
320  * Table action info get
321  *
322  * @param[in] p
323  *   Pipeline handle.
324  * @param[in] table_id
325  *   Table ID (0 .. *n_tables*).
326  * @param[in] table_action_id
327  *   Action index within the set of table actions (0 .. table n_actions - 1).
328  *   Not to be confused with the action ID, which works at the pipeline level
329  *   (0 .. pipeline n_actions - 1), which is precisely what this function
330  *   returns as part of *table_action*.
331  * @param[out] table_action
332  *   Table action info.
333  * @return
334  *   0 on success or the following error codes otherwise:
335  *   -EINVAL: Invalid argument.
336  */
337 __rte_experimental
338 int
339 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
340 	uint32_t table_id,
341 	uint32_t table_action_id,
342 	struct rte_swx_ctl_table_action_info *table_action);
343 
344 /**
345  * Table operations get
346  *
347  * @param[in] p
348  *   Pipeline handle.
349  * @param[in] table_id
350  *   Table ID (0 .. *n_tables*).
351  * @param[out] table_ops
352  *   Table operations. Only valid when function returns success and *is_stub* is
353  *   zero (false).
354  * @param[out] is_stub
355  *   A stub table is a table with no match fields. No "regular" table entries
356  *   (i.e. entries other than the default entry) can be added to such a table,
357  *   therefore the lookup operation always results in lookup miss. Non-zero
358  *   (true) when the current table is a stub table, zero (false) otherwise.
359  * @return
360  *   0 on success or the following error codes otherwise:
361  *   -EINVAL: Invalid argument.
362  */
363 __rte_experimental
364 int
365 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
366 			  uint32_t table_id,
367 			  struct rte_swx_table_ops *table_ops,
368 			  int *is_stub);
369 
370 /** Table statistics. */
371 struct rte_swx_table_stats {
372 	/** Number of packets with lookup hit. */
373 	uint64_t n_pkts_hit;
374 
375 	/** Number of packets with lookup miss. */
376 	uint64_t n_pkts_miss;
377 
378 	/** Number of packets (with either lookup hit or miss) per pipeline
379 	 * action. Array of pipeline *n_actions* elements indexed by the
380 	 * pipeline-level *action_id*, therefore this array has the same size
381 	 * for all the tables within the same pipeline.
382 	 */
383 	uint64_t *n_pkts_action;
384 };
385 
386 /**
387  * Table statistics counters read
388  *
389  * @param[in] p
390  *   Pipeline handle.
391  * @param[in] table_name
392  *   Table name.
393  * @param[out] stats
394  *   Table stats. Must point to a pre-allocated structure. The *n_pkts_action*
395  *   field also needs to be pre-allocated as array of pipeline *n_actions*
396  *   elements. The pipeline actions that are not valid for the current table
397  *   have their associated *n_pkts_action* element always set to zero.
398  * @return
399  *   0 on success or the following error codes otherwise:
400  *   -EINVAL: Invalid argument.
401  */
402 __rte_experimental
403 int
404 rte_swx_ctl_pipeline_table_stats_read(struct rte_swx_pipeline *p,
405 				      const char *table_name,
406 				      struct rte_swx_table_stats *stats);
407 
408 /*
409  * Selector Table Query API.
410  */
411 
412 /** Selector info. */
413 struct rte_swx_ctl_selector_info {
414 	/** Selector table name. */
415 	char name[RTE_SWX_CTL_NAME_SIZE];
416 
417 	/** Number of selector fields. */
418 	uint32_t n_selector_fields;
419 
420 	/** Maximum number of groups. */
421 	uint32_t n_groups_max;
422 
423 	/** Maximum number of members per group. */
424 	uint32_t n_members_per_group_max;
425 };
426 
427 /**
428  * Selector table info get
429  *
430  * @param[in] p
431  *   Pipeline handle.
432  * @param[in] selector_id
433  *   Selector table ID (0 .. *n_selectors* - 1).
434  * @param[out] selector
435  *   Selector table info.
436  * @return
437  *   0 on success or the following error codes otherwise:
438  *   -EINVAL: Invalid argument.
439  */
440 __rte_experimental
441 int
442 rte_swx_ctl_selector_info_get(struct rte_swx_pipeline *p,
443 			      uint32_t selector_id,
444 			      struct rte_swx_ctl_selector_info *selector);
445 
446 /**
447  * Selector table "group ID" field info get
448  *
449  * @param[in] p
450  *   Pipeline handle.
451  * @param[in] selector_id
452  *   Selector table ID (0 .. *n_selectors*).
453  * @param[out] field
454  *   Selector table "group ID" field info.
455  * @return
456  *   0 on success or the following error codes otherwise:
457  *   -EINVAL: Invalid argument.
458  */
459 __rte_experimental
460 int
461 rte_swx_ctl_selector_group_id_field_info_get(struct rte_swx_pipeline *p,
462 					     uint32_t selector_id,
463 					     struct rte_swx_ctl_table_match_field_info *field);
464 
465 /**
466  * Sselector table selector field info get
467  *
468  * @param[in] p
469  *   Pipeline handle.
470  * @param[in] selector_id
471  *   Selector table ID (0 .. *n_selectors*).
472  * @param[in] selector_field_id
473  *   Selector table selector field ID (0 .. *n_selector_fields* - 1).
474  * @param[out] field
475  *   Selector table selector field info.
476  * @return
477  *   0 on success or the following error codes otherwise:
478  *   -EINVAL: Invalid argument.
479  */
480 __rte_experimental
481 int
482 rte_swx_ctl_selector_field_info_get(struct rte_swx_pipeline *p,
483 				    uint32_t selector_id,
484 				    uint32_t selector_field_id,
485 				    struct rte_swx_ctl_table_match_field_info *field);
486 
487 /**
488  * Selector table "member ID" field info get
489  *
490  * @param[in] p
491  *   Pipeline handle.
492  * @param[in] selector_id
493  *   Selector table ID (0 .. *n_selectors*).
494  * @param[out] field
495  *   Selector table "member ID" field info.
496  * @return
497  *   0 on success or the following error codes otherwise:
498  *   -EINVAL: Invalid argument.
499  */
500 __rte_experimental
501 int
502 rte_swx_ctl_selector_member_id_field_info_get(struct rte_swx_pipeline *p,
503 					      uint32_t selector_id,
504 					      struct rte_swx_ctl_table_match_field_info *field);
505 
506 /** Selector table statistics. */
507 struct rte_swx_pipeline_selector_stats {
508 	/** Number of packets. */
509 	uint64_t n_pkts;
510 };
511 
512 /**
513  * Selector table statistics counters read
514  *
515  * @param[in] p
516  *   Pipeline handle.
517  * @param[in] selector_name
518  *   Selector table name.
519  * @param[out] stats
520  *   Selector table stats. Must point to a pre-allocated structure.
521  * @return
522  *   0 on success or the following error codes otherwise:
523  *   -EINVAL: Invalid argument.
524  */
525 __rte_experimental
526 int
527 rte_swx_ctl_pipeline_selector_stats_read(struct rte_swx_pipeline *p,
528 					 const char *selector_name,
529 					 struct rte_swx_pipeline_selector_stats *stats);
530 
531 /*
532  * Learner Table Query API.
533  */
534 
535 /** Learner table info. */
536 struct rte_swx_ctl_learner_info {
537 	/** Learner table name. */
538 	char name[RTE_SWX_CTL_NAME_SIZE];
539 
540 	/** Number of match fields. */
541 	uint32_t n_match_fields;
542 
543 	/** Number of actions. */
544 	uint32_t n_actions;
545 
546 	/** Non-zero (true) when the default action is constant, therefore it
547 	 * cannot be changed; zero (false) when the default action not constant,
548 	 * therefore it can be changed.
549 	 */
550 	int default_action_is_const;
551 
552 	/** Learner table size parameter. */
553 	uint32_t size;
554 
555 	/** Number of possible key timeout values. */
556 	uint32_t n_key_timeouts;
557 };
558 
559 /**
560  * Learner table info get
561  *
562  * @param[in] p
563  *   Pipeline handle.
564  * @param[in] learner_id
565  *   Learner table ID (0 .. *n_learners* - 1).
566  * @param[out] learner
567  *   Learner table info.
568  * @return
569  *   0 on success or the following error codes otherwise:
570  *   -EINVAL: Invalid argument.
571  */
572 __rte_experimental
573 int
574 rte_swx_ctl_learner_info_get(struct rte_swx_pipeline *p,
575 			     uint32_t learner_id,
576 			     struct rte_swx_ctl_learner_info *learner);
577 
578 /**
579  * Learner table match field info get
580  *
581  * @param[in] p
582  *   Pipeline handle.
583  * @param[in] learner_id
584  *   Learner table ID (0 .. *n_learners* - 1).
585  * @param[in] match_field_id
586  *   Match field ID (0 .. *n_match_fields* - 1).
587  * @param[out] match_field
588  *   Learner table match field info.
589  * @return
590  *   0 on success or the following error codes otherwise:
591  *   -EINVAL: Invalid argument.
592  */
593 __rte_experimental
594 int
595 rte_swx_ctl_learner_match_field_info_get(struct rte_swx_pipeline *p,
596 					 uint32_t learner_id,
597 					 uint32_t match_field_id,
598 					 struct rte_swx_ctl_table_match_field_info *match_field);
599 
600 /**
601  * Learner table action info get
602  *
603  * @param[in] p
604  *   Pipeline handle.
605  * @param[in] learner_id
606  *   Learner table ID (0 .. *n_learners* - 1).
607  * @param[in] learner_action_id
608  *   Action index within the set of learner table actions (0 .. learner table n_actions - 1). Not
609  *   to be confused with the pipeline-leve action ID (0 .. pipeline n_actions - 1), which is
610  *   precisely what this function returns as part of the *learner_action*.
611  * @param[out] learner_action
612  *   Learner action info.
613  * @return
614  *   0 on success or the following error codes otherwise:
615  *   -EINVAL: Invalid argument.
616  */
617 __rte_experimental
618 int
619 rte_swx_ctl_learner_action_info_get(struct rte_swx_pipeline *p,
620 				    uint32_t learner_id,
621 				    uint32_t learner_action_id,
622 				    struct rte_swx_ctl_table_action_info *learner_action);
623 
624 /**
625  * Learner table timeout get
626  *
627  * @param[in] p
628  *   Pipeline handle.
629  * @param[in] learner_id
630  *   Learner table ID (0 .. *n_learners* - 1).
631  * @param[in] timeout_id
632  *   Timeout ID.
633  * @param[out] timeout
634  *   Timeout value measured in seconds. Must be non-NULL.
635  * @return
636  *   0 on success or the following error codes otherwise:
637  *   -EINVAL: Invalid argument.
638  */
639 __rte_experimental
640 int
641 rte_swx_ctl_pipeline_learner_timeout_get(struct rte_swx_pipeline *p,
642 					 uint32_t learner_id,
643 					 uint32_t timeout_id,
644 					 uint32_t *timeout);
645 
646 /**
647  * Learner table timeout set
648  *
649  * @param[in] p
650  *   Pipeline handle.
651  * @param[in] learner_id
652  *   Learner table ID (0 .. *n_learners* - 1).
653  * @param[in] timeout_id
654  *   Timeout ID.
655  * @param[in] timeout
656  *   Timeout value measured in seconds.
657  * @return
658  *   0 on success or the following error codes otherwise:
659  *   -EINVAL: Invalid argument.
660  */
661 __rte_experimental
662 int
663 rte_swx_ctl_pipeline_learner_timeout_set(struct rte_swx_pipeline *p,
664 					 uint32_t learner_id,
665 					 uint32_t timeout_id,
666 					 uint32_t timeout);
667 
668 /** Learner table statistics. */
669 struct rte_swx_learner_stats {
670 	/** Number of packets with lookup hit. */
671 	uint64_t n_pkts_hit;
672 
673 	/** Number of packets with lookup miss. */
674 	uint64_t n_pkts_miss;
675 
676 	/** Number of packets with successful learning. */
677 	uint64_t n_pkts_learn_ok;
678 
679 	/** Number of packets with learning error. */
680 	uint64_t n_pkts_learn_err;
681 
682 	/** Number of packets with rearm event. */
683 	uint64_t n_pkts_rearm;
684 
685 	/** Number of packets with forget event. */
686 	uint64_t n_pkts_forget;
687 
688 	/** Number of packets (with either lookup hit or miss) per pipeline action. Array of
689 	 * pipeline *n_actions* elements indexed by the pipeline-level *action_id*, therefore this
690 	 * array has the same size for all the tables within the same pipeline.
691 	 */
692 	uint64_t *n_pkts_action;
693 };
694 
695 /**
696  * Learner table statistics counters read
697  *
698  * @param[in] p
699  *   Pipeline handle.
700  * @param[in] learner_name
701  *   Learner table name.
702  * @param[out] stats
703  *   Learner table stats. Must point to a pre-allocated structure. The *n_pkts_action* field also
704  *   needs to be pre-allocated as array of pipeline *n_actions* elements. The pipeline actions that
705  *   are not valid for the current learner table have their associated *n_pkts_action* element
706  *   always set to zero.
707  * @return
708  *   0 on success or the following error codes otherwise:
709  *   -EINVAL: Invalid argument.
710  */
711 __rte_experimental
712 int
713 rte_swx_ctl_pipeline_learner_stats_read(struct rte_swx_pipeline *p,
714 				      const char *learner_name,
715 				      struct rte_swx_learner_stats *stats);
716 
717 /*
718  * Packet mirroring API.
719  */
720 
721 /** Packet mirroring session parameters. */
722 struct rte_swx_pipeline_mirroring_session_params {
723 	/** Output port ID. */
724 	uint32_t port_id;
725 
726 	/** Fast clone flag. */
727 	int fast_clone;
728 
729 	/** Truncation packet length (in bytes). Zero means no truncation. */
730 	uint32_t truncation_length;
731 };
732 
733 /**
734  * Packet mirroring session set
735  *
736  * @param[in] p
737  *   Pipeline handle.
738  * @param[in] session_id
739  *   Packet mirroring session ID.
740  * @param[in] params
741  *   Packet mirroring session parameters.
742  * @return
743  *   0 on success or the following error codes otherwise:
744  *   -EINVAL: Invalid argument;
745  *   -EEXIST: Pipeline was already built successfully.
746  */
747 __rte_experimental
748 int
749 rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p,
750 	uint32_t session_id,
751 	struct rte_swx_pipeline_mirroring_session_params *params);
752 
753 /*
754  * Table Update API.
755  */
756 
757 /** Table state. */
758 struct rte_swx_table_state {
759 	/** Table object. */
760 	void *obj;
761 
762 	/** Action ID of the table default action. */
763 	uint64_t default_action_id;
764 
765 	/** Action data of the table default action. Ignored when the action
766 	 * data size is zero; otherwise, action data size bytes are meaningful.
767 	 */
768 	uint8_t *default_action_data;
769 };
770 
771 /**
772  * Pipeline table state get
773  *
774  * @param[in] p
775  *   Pipeline handle.
776  * @param[out] table_state
777  *   After successful execution, the *table_state* contains the pointer to the
778  *   current pipeline table state, which is an array of *n_tables* elements,
779  *   with array element i containing the state of the i-th pipeline table. The
780  *   pipeline continues to own all the data structures directly or indirectly
781  *   referenced by the *table_state* until the subsequent successful invocation
782  *   of function *rte_swx_pipeline_table_state_set*.
783  * @return
784  *   0 on success or the following error codes otherwise:
785  *   -EINVAL: Invalid argument.
786  */
787 __rte_experimental
788 int
789 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
790 				 struct rte_swx_table_state **table_state);
791 
792 /**
793  * Pipeline table state set
794  *
795  * @param[in] p
796  *   Pipeline handle.
797  * @param[out] table_state
798  *   After successful execution, the pipeline table state is updated to this
799  *   *table_state*. The ownership of all the data structures directly or
800  *   indirectly referenced by this *table_state* is passed from the caller to
801  *   the pipeline.
802  * @return
803  *   0 on success or the following error codes otherwise:
804  *   -EINVAL: Invalid argument.
805  */
806 __rte_experimental
807 int
808 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
809 				 struct rte_swx_table_state *table_state);
810 
811 /*
812  * High Level Reference Table Update API.
813  */
814 
815 /** Pipeline control opaque data structure. */
816 struct rte_swx_ctl_pipeline;
817 
818 /**
819  * Pipeline control find
820  *
821  * @param[in] name
822  *   Pipeline name.
823  * @return
824  *   Valid pipeline control handle if found or NULL otherwise.
825  */
826 __rte_experimental
827 struct rte_swx_ctl_pipeline *
828 rte_swx_ctl_pipeline_find(const char *name);
829 
830 /**
831  * Pipeline control create
832  *
833  * @param[in] p
834  *   Pipeline handle.
835  * @return
836  *   Pipeline control handle, on success, or NULL, on error.
837  */
838 __rte_experimental
839 struct rte_swx_ctl_pipeline *
840 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p);
841 
842 /**
843  * Pipeline table entry add
844  *
845  * Schedule entry for addition to table or update as part of the next commit
846  * operation.
847  *
848  * @param[in] ctl
849  *   Pipeline control handle.
850  * @param[in] table_name
851  *   Table name.
852  * @param[in] entry
853  *   Entry to be added to the table.
854  * @return
855  *   0 on success or the following error codes otherwise:
856  *   -EINVAL: Invalid argument.
857  */
858 __rte_experimental
859 int
860 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl,
861 				     const char *table_name,
862 				     struct rte_swx_table_entry *entry);
863 
864 /**
865  * Pipeline table default entry add
866  *
867  * Schedule table default entry update as part of the next commit operation.
868  *
869  * @param[in] ctl
870  *   Pipeline control handle.
871  * @param[in] table_name
872  *   Table name.
873  * @param[in] entry
874  *   The new table default entry. The *key* and *key_mask* entry fields are
875  *   ignored.
876  * @return
877  *   0 on success or the following error codes otherwise:
878  *   -EINVAL: Invalid argument.
879  */
880 __rte_experimental
881 int
882 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
883 					     const char *table_name,
884 					     struct rte_swx_table_entry *entry);
885 
886 /**
887  * Pipeline table entry delete
888  *
889  * Schedule entry for deletion from table as part of the next commit operation.
890  * Request is silently discarded if no such entry exists.
891  *
892  * @param[in] ctl
893  *   Pipeline control handle.
894  * @param[in] table_name
895  *   Table name.
896  * @param[in] entry
897  *   Entry to be deleted from the table. The *action_id* and *action_data* entry
898  *   fields are ignored.
899  * @return
900  *   0 on success or the following error codes otherwise:
901  *   -EINVAL: Invalid argument.
902  */
903 __rte_experimental
904 int
905 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl,
906 					const char *table_name,
907 					struct rte_swx_table_entry *entry);
908 
909 /**
910  * Pipeline selector table group add
911  *
912  * Add a new group to a selector table. This operation is executed before this
913  * function returns and its result is independent of the result of the next
914  * commit operation.
915  *
916  * @param[in] ctl
917  *   Pipeline control handle.
918  * @param[in] selector_name
919  *   Selector table name.
920  * @param[out] group_id
921  *   The ID of the new group. Only valid when the function call is successful.
922  *   This group is initially empty, i.e. it does not contain any members.
923  * @return
924  *   0 on success or the following error codes otherwise:
925  *   -EINVAL: Invalid argument;
926  *   -ENOSPC: All groups are currently in use, no group available.
927  */
928 __rte_experimental
929 int
930 rte_swx_ctl_pipeline_selector_group_add(struct rte_swx_ctl_pipeline *ctl,
931 					const char *selector_name,
932 					uint32_t *group_id);
933 
934 /**
935  * Pipeline selector table group delete
936  *
937  * Schedule a group for deletion as part of the next commit operation. The group
938  * to be deleted can be empty or non-empty.
939  *
940  * @param[in] ctl
941  *   Pipeline control handle.
942  * @param[in] selector_name
943  *   Selector table name.
944  * @param[in] group_id
945  *   Group to be deleted from the selector table.
946  * @return
947  *   0 on success or the following error codes otherwise:
948  *   -EINVAL: Invalid argument;
949  *   -ENOMEM: Not enough memory.
950  */
951 __rte_experimental
952 int
953 rte_swx_ctl_pipeline_selector_group_delete(struct rte_swx_ctl_pipeline *ctl,
954 					   const char *selector_name,
955 					   uint32_t group_id);
956 
957 /**
958  * Pipeline selector table member add to group
959  *
960  * Schedule the operation to add a new member to an existing group as part of
961  * the next commit operation. If this member is already in this group, the
962  * member weight is updated to the new value. A weight of zero means this member
963  * is to be deleted from the group.
964  *
965  * @param[in] ctl
966  *   Pipeline control handle.
967  * @param[in] selector_name
968  *   Selector table name.
969  * @param[in] group_id
970  *   The group ID.
971  * @param[in] member_id
972  *   The member to be added to the group.
973  * @param[in] member_weight
974  *   Member weight.
975  * @return
976  *   0 on success or the following error codes otherwise:
977  *   -EINVAL: Invalid argument;
978  *   -ENOMEM: Not enough memory;
979  *   -ENOSPC: The group is full.
980  */
981 __rte_experimental
982 int
983 rte_swx_ctl_pipeline_selector_group_member_add(struct rte_swx_ctl_pipeline *ctl,
984 					       const char *selector_name,
985 					       uint32_t group_id,
986 					       uint32_t member_id,
987 					       uint32_t member_weight);
988 
989 /**
990  * Pipeline selector table member delete from group
991  *
992  * Schedule the operation to delete a member from an existing group as part of
993  * the next commit operation.
994  *
995  * @param[in] ctl
996  *   Pipeline control handle.
997  * @param[in] selector_name
998  *   Selector table name.
999  * @param[in] group_id
1000  *   The group ID. Must be valid.
1001  * @param[in] member_id
1002  *   The member to be added to the group. Must be valid.
1003  * @return
1004  *   0 on success or the following error codes otherwise:
1005  *   -EINVAL: Invalid argument.
1006  */
1007 __rte_experimental
1008 int
1009 rte_swx_ctl_pipeline_selector_group_member_delete(struct rte_swx_ctl_pipeline *ctl,
1010 						  const char *selector_name,
1011 						  uint32_t group_id,
1012 						  uint32_t member_id);
1013 
1014 /**
1015  * Pipeline learner table default entry add
1016  *
1017  * Schedule learner table default entry update as part of the next commit operation.
1018  *
1019  * @param[in] ctl
1020  *   Pipeline control handle.
1021  * @param[in] learner_name
1022  *   Learner table name.
1023  * @param[in] entry
1024  *   The new table default entry. The *key* and *key_mask* entry fields are ignored.
1025  * @return
1026  *   0 on success or the following error codes otherwise:
1027  *   -EINVAL: Invalid argument.
1028  */
1029 __rte_experimental
1030 int
1031 rte_swx_ctl_pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
1032 					       const char *learner_name,
1033 					       struct rte_swx_table_entry *entry);
1034 
1035 /**
1036  * Pipeline commit
1037  *
1038  * Perform all the scheduled table work.
1039  *
1040  * @param[in] ctl
1041  *   Pipeline control handle.
1042  * @param[in] abort_on_fail
1043  *   When non-zero (false), all the scheduled work is discarded after a failed
1044  *   commit. Otherwise, the scheduled work is still kept pending for the next
1045  *   commit.
1046  * @return
1047  *   0 on success or the following error codes otherwise:
1048  *   -EINVAL: Invalid argument.
1049  */
1050 __rte_experimental
1051 int
1052 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl,
1053 			    int abort_on_fail);
1054 
1055 /**
1056  * Pipeline abort
1057  *
1058  * Discard all the scheduled table work.
1059  *
1060  * @param[in] ctl
1061  *   Pipeline control handle.
1062  */
1063 __rte_experimental
1064 void
1065 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl);
1066 
1067 /**
1068  * Pipeline table entry read
1069  *
1070  * Read table entry from string.
1071  *
1072  * @param[in] ctl
1073  *   Pipeline control handle.
1074  * @param[in] table_name
1075  *   Table name.
1076  * @param[in] string
1077  *   String containing the table entry.
1078  * @param[out] is_blank_or_comment
1079  *   On error, this argument provides an indication of whether *string* contains
1080  *   an invalid table entry (set to zero) or a blank or comment line that should
1081  *   typically be ignored (set to a non-zero value).
1082  * @return
1083  *   0 on success or the following error codes otherwise:
1084  *   -EINVAL: Invalid argument.
1085  */
1086 __rte_experimental
1087 struct rte_swx_table_entry *
1088 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl,
1089 				      const char *table_name,
1090 				      const char *string,
1091 				      int *is_blank_or_comment);
1092 
1093 /**
1094  * Pipeline learner table default entry read
1095  *
1096  * Read learner table default entry from string.
1097  *
1098  * @param[in] ctl
1099  *   Pipeline control handle.
1100  * @param[in] learner_name
1101  *   Learner table name.
1102  * @param[in] string
1103  *   String containing the learner table default entry.
1104  * @param[out] is_blank_or_comment
1105  *   On error, this argument provides an indication of whether *string* contains
1106  *   an invalid table entry (set to zero) or a blank or comment line that should
1107  *   typically be ignored (set to a non-zero value).
1108  * @return
1109  *   0 on success or the following error codes otherwise:
1110  *   -EINVAL: Invalid argument.
1111  */
1112 __rte_experimental
1113 struct rte_swx_table_entry *
1114 rte_swx_ctl_pipeline_learner_default_entry_read(struct rte_swx_ctl_pipeline *ctl,
1115 						const char *learner_name,
1116 						const char *string,
1117 						int *is_blank_or_comment);
1118 
1119 /**
1120  * Pipeline table print to file
1121  *
1122  * Print all the table entries to file.
1123  *
1124  * @param[in] f
1125  *   Output file.
1126  * @param[in] ctl
1127  *   Pipeline control handle.
1128  * @param[in] table_name
1129  *   Table name.
1130  * @return
1131  *   0 on success or the following error codes otherwise:
1132  *   -EINVAL: Invalid argument.
1133  */
1134 __rte_experimental
1135 int
1136 rte_swx_ctl_pipeline_table_fprintf(FILE *f,
1137 				   struct rte_swx_ctl_pipeline *ctl,
1138 				   const char *table_name);
1139 
1140 /**
1141  * Pipeline selector print to file
1142  *
1143  * Print all the selector entries to file.
1144  *
1145  * @param[in] f
1146  *   Output file.
1147  * @param[in] ctl
1148  *   Pipeline control handle.
1149  * @param[in] selector_name
1150  *   Selector table name.
1151  * @return
1152  *   0 on success or the following error codes otherwise:
1153  *   -EINVAL: Invalid argument.
1154  */
1155 __rte_experimental
1156 int
1157 rte_swx_ctl_pipeline_selector_fprintf(FILE *f,
1158 				      struct rte_swx_ctl_pipeline *ctl,
1159 				      const char *selector_name);
1160 
1161 /*
1162  * Register Array Query API.
1163  */
1164 
1165 /** Register array info. */
1166 struct rte_swx_ctl_regarray_info {
1167 	/** Register array name. */
1168 	char name[RTE_SWX_CTL_NAME_SIZE];
1169 
1170 	/** Register array size. */
1171 	uint32_t size;
1172 };
1173 
1174 /**
1175  * Register array info get
1176  *
1177  * @param[in] p
1178  *   Pipeline handle.
1179  * @param[in] regarray_id
1180  *   Register array ID (0 .. *n_regarrays* - 1).
1181  * @param[out] regarray
1182  *   Register array info.
1183  * @return
1184  *   0 on success or the following error codes otherwise:
1185  *   -EINVAL: Invalid argument.
1186  */
1187 __rte_experimental
1188 int
1189 rte_swx_ctl_regarray_info_get(struct rte_swx_pipeline *p,
1190 			      uint32_t regarray_id,
1191 			      struct rte_swx_ctl_regarray_info *regarray);
1192 
1193 /**
1194  * Register read
1195  *
1196  * @param[in] p
1197  *   Pipeline handle.
1198  * @param[in] regarray_name
1199  *   Register array name.
1200  * @param[in] regarray_index
1201  *   Register index within the array (0 .. *size* - 1).
1202  * @param[out] value
1203  *   Current register value.
1204  * @return
1205  *   0 on success or the following error codes otherwise:
1206  *   -EINVAL: Invalid argument.
1207  */
1208 __rte_experimental
1209 int
1210 rte_swx_ctl_pipeline_regarray_read(struct rte_swx_pipeline *p,
1211 				   const char *regarray_name,
1212 				   uint32_t regarray_index,
1213 				   uint64_t *value);
1214 
1215 /**
1216  * Register write
1217  *
1218  * @param[in] p
1219  *   Pipeline handle.
1220  * @param[in] regarray_name
1221  *   Register array name.
1222  * @param[in] regarray_index
1223  *   Register index within the array (0 .. *size* - 1).
1224  * @param[in] value
1225  *   Value to be written to the register.
1226  * @return
1227  *   0 on success or the following error codes otherwise:
1228  *   -EINVAL: Invalid argument.
1229  */
1230 __rte_experimental
1231 int
1232 rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
1233 				   const char *regarray_name,
1234 				   uint32_t regarray_index,
1235 				   uint64_t value);
1236 
1237 /*
1238  * Meter Array Query and Configuration API.
1239  */
1240 
1241 /** Meter array info. */
1242 struct rte_swx_ctl_metarray_info {
1243 	/** Meter array name. */
1244 	char name[RTE_SWX_CTL_NAME_SIZE];
1245 
1246 	/** Meter array size. */
1247 	uint32_t size;
1248 };
1249 
1250 /**
1251  * Meter array info get
1252  *
1253  * @param[in] p
1254  *   Pipeline handle.
1255  * @param[in] metarray_id
1256  *   Meter array ID (0 .. *n_metarrays* - 1).
1257  * @param[out] metarray
1258  *   Meter array info.
1259  * @return
1260  *   0 on success or the following error codes otherwise:
1261  *   -EINVAL: Invalid argument.
1262  */
1263 __rte_experimental
1264 int
1265 rte_swx_ctl_metarray_info_get(struct rte_swx_pipeline *p,
1266 			      uint32_t metarray_id,
1267 			      struct rte_swx_ctl_metarray_info *metarray);
1268 
1269 /**
1270  * Meter profile add
1271  *
1272  * @param[in] p
1273  *   Pipeline handle.
1274  * @param[in] name
1275  *   Meter profile name.
1276  * @param[in] params
1277  *   Meter profile parameters.
1278  * @return
1279  *   0 on success or the following error codes otherwise:
1280  *   -EINVAL: Invalid argument;
1281  *   -ENOMEM: Not enough space/cannot allocate memory;
1282  *   -EEXIST: Meter profile with this name already exists.
1283  */
1284 __rte_experimental
1285 int
1286 rte_swx_ctl_meter_profile_add(struct rte_swx_pipeline *p,
1287 			      const char *name,
1288 			      struct rte_meter_trtcm_params *params);
1289 
1290 /**
1291  * Meter profile delete
1292  *
1293  * @param[in] p
1294  *   Pipeline handle.
1295  * @param[in] name
1296  *   Meter profile name.
1297  * @return
1298  *   0 on success or the following error codes otherwise:
1299  *   -EINVAL: Invalid argument;
1300  *   -EBUSY: Meter profile is currently in use.
1301  */
1302 __rte_experimental
1303 int
1304 rte_swx_ctl_meter_profile_delete(struct rte_swx_pipeline *p,
1305 				 const char *name);
1306 
1307 /**
1308  * Meter reset
1309  *
1310  * Reset a meter within a given meter array to use the default profile that
1311  * causes all the input packets to be colored as green. It is the responsibility
1312  * of the control plane to make sure this meter is not used by the data plane
1313  * pipeline before calling this function.
1314  *
1315  * @param[in] p
1316  *   Pipeline handle.
1317  * @param[in] metarray_name
1318  *   Meter array name.
1319  * @param[in] metarray_index
1320  *   Meter index within the meter array.
1321  * @return
1322  *   0 on success or the following error codes otherwise:
1323  *   -EINVAL: Invalid argument.
1324  */
1325 __rte_experimental
1326 int
1327 rte_swx_ctl_meter_reset(struct rte_swx_pipeline *p,
1328 			const char *metarray_name,
1329 			uint32_t metarray_index);
1330 
1331 /**
1332  * Meter set
1333  *
1334  * Set a meter within a given meter array to use a specific profile. It is the
1335  * responsibility of the control plane to make sure this meter is not used by
1336  * the data plane pipeline before calling this function.
1337  *
1338  * @param[in] p
1339  *   Pipeline handle.
1340  * @param[in] metarray_name
1341  *   Meter array name.
1342  * @param[in] metarray_index
1343  *   Meter index within the meter array.
1344  * @param[in] profile_name
1345  *   Existing meter profile name.
1346  * @return
1347  *   0 on success or the following error codes otherwise:
1348  *   -EINVAL: Invalid argument.
1349  */
1350 __rte_experimental
1351 int
1352 rte_swx_ctl_meter_set(struct rte_swx_pipeline *p,
1353 		      const char *metarray_name,
1354 		      uint32_t metarray_index,
1355 		      const char *profile_name);
1356 
1357 /** Meter statistics counters. */
1358 struct rte_swx_ctl_meter_stats {
1359 	/** Number of packets tagged by the meter for each color. */
1360 	uint64_t n_pkts[RTE_COLORS];
1361 
1362 	/** Number of bytes tagged by the meter for each color. */
1363 	uint64_t n_bytes[RTE_COLORS];
1364 };
1365 
1366 /**
1367  * Meter statistics counters read
1368  *
1369  * @param[in] p
1370  *   Pipeline handle.
1371  * @param[in] metarray_name
1372  *   Meter array name.
1373  * @param[in] metarray_index
1374  *   Meter index within the meter array.
1375  * @param[out] stats
1376  *   Meter statistics counters.
1377  * @return
1378  *   0 on success or the following error codes otherwise:
1379  *   -EINVAL: Invalid argument.
1380  */
1381 __rte_experimental
1382 int
1383 rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
1384 			     const char *metarray_name,
1385 			     uint32_t metarray_index,
1386 			     struct rte_swx_ctl_meter_stats *stats);
1387 
1388 /**
1389  * Pipeline control free
1390  *
1391  * @param[in] ctl
1392  *   Pipeline control handle.
1393  *   If ctl is NULL, no operation is performed.
1394  */
1395 __rte_experimental
1396 void
1397 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl);
1398 
1399 #ifdef __cplusplus
1400 }
1401 #endif
1402 
1403 #endif
1404