1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
4 #ifndef __INCLUDE_RTE_SWX_CTL_H__
5 #define __INCLUDE_RTE_SWX_CTL_H__
13 * RTE SWX Pipeline Control
20 #include <rte_compat.h>
21 #include <rte_meter.h>
23 #include "rte_swx_port.h"
24 #include "rte_swx_table.h"
25 #include "rte_swx_table_selector.h"
27 struct rte_swx_pipeline;
30 #ifndef RTE_SWX_CTL_NAME_SIZE
31 #define RTE_SWX_CTL_NAME_SIZE 64
39 struct rte_swx_ctl_pipeline_info {
40 /** Number of input ports. */
43 /** Number of input ports. */
46 /** Number of actions. */
49 /** Number of tables. */
52 /** Number of selector tables. */
55 /** Number of register arrays. */
58 /** Number of meter arrays. */
67 * @param[out] pipeline
70 * 0 on success or the following error codes otherwise:
71 * -EINVAL: Invalid argument.
75 rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
76 struct rte_swx_ctl_pipeline_info *pipeline);
79 * Pipeline NUMA node get
83 * @param[out] numa_node
86 * 0 on success or the following error codes otherwise:
87 * -EINVAL: Invalid argument.
91 rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p,
99 * Input port statistics counters read
104 * Port ID (0 .. *n_ports_in* - 1).
108 * 0 on success or the following error codes otherwise:
109 * -EINVAL: Invalid argument.
113 rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
115 struct rte_swx_port_in_stats *stats);
118 * Output port statistics counters read
123 * Port ID (0 .. *n_ports_out* - 1).
127 * 0 on success or the following error codes otherwise:
128 * -EINVAL: Invalid argument.
132 rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
134 struct rte_swx_port_out_stats *stats);
141 struct rte_swx_ctl_action_info {
143 char name[RTE_SWX_CTL_NAME_SIZE];
145 /** Number of action arguments. */
154 * @param[in] action_id
155 * Action ID (0 .. *n_actions* - 1).
159 * 0 on success or the following error codes otherwise:
160 * -EINVAL: Invalid argument.
164 rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
166 struct rte_swx_ctl_action_info *action);
168 /** Action argument info. */
169 struct rte_swx_ctl_action_arg_info {
170 /** Action argument name. */
171 char name[RTE_SWX_CTL_NAME_SIZE];
173 /** Action argument size (in bits). */
176 /** Non-zero (true) when this action argument must be stored in the
177 * table in network byte order (NBO), zero when it must be stored in
178 * host byte order (HBO).
180 int is_network_byte_order;
184 * Action argument info get
188 * @param[in] action_id
189 * Action ID (0 .. *n_actions* - 1).
190 * @param[in] action_arg_id
191 * Action ID (0 .. *n_args* - 1).
192 * @param[out] action_arg
193 * Action argument info.
195 * 0 on success or the following error codes otherwise:
196 * -EINVAL: Invalid argument.
200 rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
202 uint32_t action_arg_id,
203 struct rte_swx_ctl_action_arg_info *action_arg);
210 struct rte_swx_ctl_table_info {
212 char name[RTE_SWX_CTL_NAME_SIZE];
214 /** Table creation arguments. */
215 char args[RTE_SWX_CTL_NAME_SIZE];
217 /** Number of match fields. */
218 uint32_t n_match_fields;
220 /** Number of actions. */
223 /** Non-zero (true) when the default action is constant, therefore it
224 * cannot be changed; zero (false) when the default action not constant,
225 * therefore it can be changed.
227 int default_action_is_const;
229 /** Table size parameter. */
238 * @param[in] table_id
239 * Table ID (0 .. *n_tables* - 1).
243 * 0 on success or the following error codes otherwise:
244 * -EINVAL: Invalid argument.
248 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
250 struct rte_swx_ctl_table_info *table);
252 /** Table match field info.
254 * If (n_bits, offset) are known for all the match fields of the table, then the
255 * table (key_offset, key_size, key_mask0) can be computed.
257 struct rte_swx_ctl_table_match_field_info {
258 /** Match type of the current match field. */
259 enum rte_swx_table_match_type match_type;
261 /** Non-zero (true) when the current match field is part of a registered
262 * header, zero (false) when it is part of the registered meta-data.
266 /** Match field size (in bits). */
269 /** Match field offset within its parent struct (one of the headers or
276 * Table match field info get
280 * @param[in] table_id
281 * Table ID (0 .. *n_tables*).
282 * @param[in] match_field_id
283 * Match field ID (0 .. *n_match_fields* - 1).
284 * @param[out] match_field
285 * Table match field info.
287 * 0 on success or the following error codes otherwise:
288 * -EINVAL: Invalid argument.
292 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
294 uint32_t match_field_id,
295 struct rte_swx_ctl_table_match_field_info *match_field);
297 /** Table action info. */
298 struct rte_swx_ctl_table_action_info {
304 * Table action info get
308 * @param[in] table_id
309 * Table ID (0 .. *n_tables*).
310 * @param[in] table_action_id
311 * Action index within the set of table actions (0 .. table n_actions - 1).
312 * Not to be confused with the action ID, which works at the pipeline level
313 * (0 .. pipeline n_actions - 1), which is precisely what this function
314 * returns as part of *table_action*.
315 * @param[out] table_action
318 * 0 on success or the following error codes otherwise:
319 * -EINVAL: Invalid argument.
323 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
325 uint32_t table_action_id,
326 struct rte_swx_ctl_table_action_info *table_action);
329 * Table operations get
333 * @param[in] table_id
334 * Table ID (0 .. *n_tables*).
335 * @param[out] table_ops
336 * Table operations. Only valid when function returns success and *is_stub* is
338 * @param[out] is_stub
339 * A stub table is a table with no match fields. No "regular" table entries
340 * (i.e. entries other than the default entry) can be added to such a table,
341 * therefore the lookup operation always results in lookup miss. Non-zero
342 * (true) when the current table is a stub table, zero (false) otherwise.
344 * 0 on success or the following error codes otherwise:
345 * -EINVAL: Invalid argument.
349 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
351 struct rte_swx_table_ops *table_ops,
354 /** Table statistics. */
355 struct rte_swx_table_stats {
356 /** Number of packets with lookup hit. */
359 /** Number of packets with lookup miss. */
360 uint64_t n_pkts_miss;
362 /** Number of packets (with either lookup hit or miss) per pipeline
363 * action. Array of pipeline *n_actions* elements indedex by the
364 * pipeline-level *action_id*, therefore this array has the same size
365 * for all the tables within the same pipeline.
367 uint64_t *n_pkts_action;
371 * Table statistics counters read
375 * @param[in] table_name
378 * Table stats. Must point to a pre-allocated structure. The *n_pkts_action*
379 * field also needs to be pre-allocated as array of pipeline *n_actions*
380 * elements. The pipeline actions that are not valid for the current table
381 * have their associated *n_pkts_action* element always set to zero.
383 * 0 on success or the following error codes otherwise:
384 * -EINVAL: Invalid argument.
388 rte_swx_ctl_pipeline_table_stats_read(struct rte_swx_pipeline *p,
389 const char *table_name,
390 struct rte_swx_table_stats *stats);
393 * Selector Table Query API.
396 /** Selector info. */
397 struct rte_swx_ctl_selector_info {
398 /** Selector table name. */
399 char name[RTE_SWX_CTL_NAME_SIZE];
401 /** Number of selector fields. */
402 uint32_t n_selector_fields;
404 /** Maximum number of groups. */
405 uint32_t n_groups_max;
407 /** Maximum number of members per group. */
408 uint32_t n_members_per_group_max;
412 * Selector table info get
416 * @param[in] selector_id
417 * Selector table ID (0 .. *n_selectors* - 1).
418 * @param[out] selector
419 * Selector table info.
421 * 0 on success or the following error codes otherwise:
422 * -EINVAL: Invalid argument.
426 rte_swx_ctl_selector_info_get(struct rte_swx_pipeline *p,
427 uint32_t selector_id,
428 struct rte_swx_ctl_selector_info *selector);
431 * Selector table "group ID" field info get
435 * @param[in] selector_id
436 * Selector table ID (0 .. *n_selectors*).
438 * Selector table "group ID" field info.
440 * 0 on success or the following error codes otherwise:
441 * -EINVAL: Invalid argument.
445 rte_swx_ctl_selector_group_id_field_info_get(struct rte_swx_pipeline *p,
446 uint32_t selector_id,
447 struct rte_swx_ctl_table_match_field_info *field);
450 * Sselector table selector field info get
454 * @param[in] selector_id
455 * Selector table ID (0 .. *n_selectors*).
456 * @param[in] selector_field_id
457 * Selector table selector field ID (0 .. *n_selector_fields* - 1).
459 * Selector table selector field info.
461 * 0 on success or the following error codes otherwise:
462 * -EINVAL: Invalid argument.
466 rte_swx_ctl_selector_field_info_get(struct rte_swx_pipeline *p,
467 uint32_t selector_id,
468 uint32_t selector_field_id,
469 struct rte_swx_ctl_table_match_field_info *field);
472 * Selector table "member ID" field info get
476 * @param[in] selector_id
477 * Selector table ID (0 .. *n_selectors*).
479 * Selector table "member ID" field info.
481 * 0 on success or the following error codes otherwise:
482 * -EINVAL: Invalid argument.
486 rte_swx_ctl_selector_member_id_field_info_get(struct rte_swx_pipeline *p,
487 uint32_t selector_id,
488 struct rte_swx_ctl_table_match_field_info *field);
490 /** Selector table statistics. */
491 struct rte_swx_pipeline_selector_stats {
492 /** Number of packets. */
497 * Selector table statistics counters read
501 * @param[in] selector_name
502 * Selector table name.
504 * Selector table stats. Must point to a pre-allocated structure.
506 * 0 on success or the following error codes otherwise:
507 * -EINVAL: Invalid argument.
511 rte_swx_ctl_pipeline_selector_stats_read(struct rte_swx_pipeline *p,
512 const char *selector_name,
513 struct rte_swx_pipeline_selector_stats *stats);
520 struct rte_swx_table_state {
524 /** Action ID of the table default action. */
525 uint64_t default_action_id;
527 /** Action data of the table default action. Ignored when the action
528 * data size is zero; otherwise, action data size bytes are meaningful.
530 uint8_t *default_action_data;
534 * Pipeline table state get
538 * @param[out] table_state
539 * After successful execution, the *table_state* contains the pointer to the
540 * current pipeline table state, which is an array of *n_tables* elements,
541 * with array element i containing the state of the i-th pipeline table. The
542 * pipeline continues to own all the data structures directly or indirectly
543 * referenced by the *table_state* until the subsequent successful invocation
544 * of function *rte_swx_pipeline_table_state_set*.
546 * 0 on success or the following error codes otherwise:
547 * -EINVAL: Invalid argument.
551 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
552 struct rte_swx_table_state **table_state);
555 * Pipeline table state set
559 * @param[out] table_state
560 * After successful execution, the pipeline table state is updated to this
561 * *table_state*. The ownership of all the data structures directly or
562 * indirectly referenced by this *table_state* is passed from the caller to
565 * 0 on success or the following error codes otherwise:
566 * -EINVAL: Invalid argument.
570 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
571 struct rte_swx_table_state *table_state);
574 * High Level Reference Table Update API.
577 /** Pipeline control opaque data structure. */
578 struct rte_swx_ctl_pipeline;
581 * Pipeline control create
586 * Pipeline control handle, on success, or NULL, on error.
589 struct rte_swx_ctl_pipeline *
590 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p);
593 * Pipeline table entry add
595 * Schedule entry for addition to table or update as part of the next commit
599 * Pipeline control handle.
600 * @param[in] table_name
603 * Entry to be added to the table.
605 * 0 on success or the following error codes otherwise:
606 * -EINVAL: Invalid argument.
610 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl,
611 const char *table_name,
612 struct rte_swx_table_entry *entry);
615 * Pipeline table default entry add
617 * Schedule table default entry update as part of the next commit operation.
620 * Pipeline control handle.
621 * @param[in] table_name
624 * The new table default entry. The *key* and *key_mask* entry fields are
627 * 0 on success or the following error codes otherwise:
628 * -EINVAL: Invalid argument.
632 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
633 const char *table_name,
634 struct rte_swx_table_entry *entry);
637 * Pipeline table entry delete
639 * Schedule entry for deletion from table as part of the next commit operation.
640 * Request is silently discarded if no such entry exists.
643 * Pipeline control handle.
644 * @param[in] table_name
647 * Entry to be deleted from the table. The *action_id* and *action_data* entry
648 * fields are ignored.
650 * 0 on success or the following error codes otherwise:
651 * -EINVAL: Invalid argument.
655 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl,
656 const char *table_name,
657 struct rte_swx_table_entry *entry);
660 * Pipeline selector table group add
662 * Add a new group to a selector table. This operation is executed before this
663 * function returns and its result is independent of the result of the next
667 * Pipeline control handle.
668 * @param[in] selector_name
669 * Selector table name.
670 * @param[out] group_id
671 * The ID of the new group. Only valid when the function call is successful.
672 * This group is initially empty, i.e. it does not contain any members.
674 * 0 on success or the following error codes otherwise:
675 * -EINVAL: Invalid argument;
676 * -ENOSPC: All groups are currently in use, no group available.
680 rte_swx_ctl_pipeline_selector_group_add(struct rte_swx_ctl_pipeline *ctl,
681 const char *selector_name,
685 * Pipeline selector table group delete
687 * Schedule a group for deletion as part of the next commit operation. The group
688 * to be deleted can be empty or non-empty.
691 * Pipeline control handle.
692 * @param[in] selector_name
693 * Selector table name.
694 * @param[in] group_id
695 * Group to be deleted from the selector table.
697 * 0 on success or the following error codes otherwise:
698 * -EINVAL: Invalid argument;
699 * -ENOMEM: Not enough memory.
703 rte_swx_ctl_pipeline_selector_group_delete(struct rte_swx_ctl_pipeline *ctl,
704 const char *selector_name,
708 * Pipeline selector table member add to group
710 * Schedule the operation to add a new member to an existing group as part of
711 * the next commit operation. If this member is already in this group, the
712 * member weight is updated to the new value. A weight of zero means this member
713 * is to be deleted from the group.
716 * Pipeline control handle.
717 * @param[in] selector_name
718 * Selector table name.
719 * @param[in] group_id
721 * @param[in] member_id
722 * The member to be added to the group.
723 * @param[in] member_weight
726 * 0 on success or the following error codes otherwise:
727 * -EINVAL: Invalid argument;
728 * -ENOMEM: Not enough memory;
729 * -ENOSPC: The group is full.
733 rte_swx_ctl_pipeline_selector_group_member_add(struct rte_swx_ctl_pipeline *ctl,
734 const char *selector_name,
737 uint32_t member_weight);
740 * Pipeline selector table member delete from group
742 * Schedule the operation to delete a member from an existing group as part of
743 * the next commit operation.
746 * Pipeline control handle.
747 * @param[in] selector_name
748 * Selector table name.
749 * @param[in] group_id
750 * The group ID. Must be valid.
751 * @param[in] member_id
752 * The member to be added to the group. Must be valid.
754 * 0 on success or the following error codes otherwise:
755 * -EINVAL: Invalid argument.
759 rte_swx_ctl_pipeline_selector_group_member_delete(struct rte_swx_ctl_pipeline *ctl,
760 const char *selector_name,
767 * Perform all the scheduled table work.
770 * Pipeline control handle.
771 * @param[in] abort_on_fail
772 * When non-zero (false), all the scheduled work is discarded after a failed
773 * commit. Otherwise, the scheduled work is still kept pending for the next
776 * 0 on success or the following error codes otherwise:
777 * -EINVAL: Invalid argument.
781 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl,
787 * Discard all the scheduled table work.
790 * Pipeline control handle.
794 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl);
797 * Pipeline table entry read
799 * Read table entry from string.
802 * Pipeline control handle.
803 * @param[in] table_name
806 * String containing the table entry.
807 * @param[out] is_blank_or_comment
808 * On error, this argument provides an indication of whether *string* contains
809 * an invalid table entry (set to zero) or a blank or comment line that should
810 * typically be ignored (set to a non-zero value).
812 * 0 on success or the following error codes otherwise:
813 * -EINVAL: Invalid argument.
816 struct rte_swx_table_entry *
817 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl,
818 const char *table_name,
820 int *is_blank_or_comment);
823 * Pipeline table print to file
825 * Print all the table entries to file.
830 * Pipeline control handle.
831 * @param[in] table_name
834 * 0 on success or the following error codes otherwise:
835 * -EINVAL: Invalid argument.
839 rte_swx_ctl_pipeline_table_fprintf(FILE *f,
840 struct rte_swx_ctl_pipeline *ctl,
841 const char *table_name);
844 * Pipeline selector print to file
846 * Print all the selector entries to file.
851 * Pipeline control handle.
852 * @param[in] selector_name
853 * Selector table name.
855 * 0 on success or the following error codes otherwise:
856 * -EINVAL: Invalid argument.
860 rte_swx_ctl_pipeline_selector_fprintf(FILE *f,
861 struct rte_swx_ctl_pipeline *ctl,
862 const char *selector_name);
865 * Register Array Query API.
868 /** Register array info. */
869 struct rte_swx_ctl_regarray_info {
870 /** Register array name. */
871 char name[RTE_SWX_CTL_NAME_SIZE];
873 /** Register array size. */
878 * Register array info get
882 * @param[in] regarray_id
883 * Register array ID (0 .. *n_regarrays* - 1).
884 * @param[out] regarray
885 * Register array info.
887 * 0 on success or the following error codes otherwise:
888 * -EINVAL: Invalid argument.
892 rte_swx_ctl_regarray_info_get(struct rte_swx_pipeline *p,
893 uint32_t regarray_id,
894 struct rte_swx_ctl_regarray_info *regarray);
901 * @param[in] regarray_name
902 * Register array name.
903 * @param[in] regarray_index
904 * Register index within the array (0 .. *size* - 1).
906 * Current register value.
908 * 0 on success or the following error codes otherwise:
909 * -EINVAL: Invalid argument.
913 rte_swx_ctl_pipeline_regarray_read(struct rte_swx_pipeline *p,
914 const char *regarray_name,
915 uint32_t regarray_index,
923 * @param[in] regarray_name
924 * Register array name.
925 * @param[in] regarray_index
926 * Register index within the array (0 .. *size* - 1).
928 * Value to be written to the register.
930 * 0 on success or the following error codes otherwise:
931 * -EINVAL: Invalid argument.
935 rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
936 const char *regarray_name,
937 uint32_t regarray_index,
941 * Meter Array Query and Configuration API.
944 /** Meter array info. */
945 struct rte_swx_ctl_metarray_info {
946 /** Meter array name. */
947 char name[RTE_SWX_CTL_NAME_SIZE];
949 /** Meter array size. */
954 * Meter array info get
958 * @param[in] metarray_id
959 * Meter array ID (0 .. *n_metarrays* - 1).
960 * @param[out] metarray
963 * 0 on success or the following error codes otherwise:
964 * -EINVAL: Invalid argument.
968 rte_swx_ctl_metarray_info_get(struct rte_swx_pipeline *p,
969 uint32_t metarray_id,
970 struct rte_swx_ctl_metarray_info *metarray);
978 * Meter profile name.
980 * Meter profile parameters.
982 * 0 on success or the following error codes otherwise:
983 * -EINVAL: Invalid argument;
984 * -ENOMEM: Not enough space/cannot allocate memory;
985 * -EEXIST: Meter profile with this name already exists.
989 rte_swx_ctl_meter_profile_add(struct rte_swx_pipeline *p,
991 struct rte_meter_trtcm_params *params);
994 * Meter profile delete
999 * Meter profile name.
1001 * 0 on success or the following error codes otherwise:
1002 * -EINVAL: Invalid argument;
1003 * -EBUSY: Meter profile is currently in use.
1007 rte_swx_ctl_meter_profile_delete(struct rte_swx_pipeline *p,
1013 * Reset a meter within a given meter array to use the default profile that
1014 * causes all the input packets to be colored as green. It is the responsibility
1015 * of the control plane to make sure this meter is not used by the data plane
1016 * pipeline before calling this function.
1020 * @param[in] metarray_name
1022 * @param[in] metarray_index
1023 * Meter index within the meter array.
1025 * 0 on success or the following error codes otherwise:
1026 * -EINVAL: Invalid argument.
1030 rte_swx_ctl_meter_reset(struct rte_swx_pipeline *p,
1031 const char *metarray_name,
1032 uint32_t metarray_index);
1037 * Set a meter within a given meter array to use a specific profile. It is the
1038 * responsibility of the control plane to make sure this meter is not used by
1039 * the data plane pipeline before calling this function.
1043 * @param[in] metarray_name
1045 * @param[in] metarray_index
1046 * Meter index within the meter array.
1047 * @param[in] profile_name
1048 * Existing meter profile name.
1050 * 0 on success or the following error codes otherwise:
1051 * -EINVAL: Invalid argument.
1055 rte_swx_ctl_meter_set(struct rte_swx_pipeline *p,
1056 const char *metarray_name,
1057 uint32_t metarray_index,
1058 const char *profile_name);
1060 /** Meter statistics counters. */
1061 struct rte_swx_ctl_meter_stats {
1062 /** Number of packets tagged by the meter for each color. */
1063 uint64_t n_pkts[RTE_COLORS];
1065 /** Number of bytes tagged by the meter for each color. */
1066 uint64_t n_bytes[RTE_COLORS];
1070 * Meter statistics counters read
1074 * @param[in] metarray_name
1076 * @param[in] metarray_index
1077 * Meter index within the meter array.
1079 * Meter statistics counters.
1081 * 0 on success or the following error codes otherwise:
1082 * -EINVAL: Invalid argument.
1086 rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,
1087 const char *metarray_name,
1088 uint32_t metarray_index,
1089 struct rte_swx_ctl_meter_stats *stats);
1092 * Pipeline control free
1095 * Pipeline control handle.
1099 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl);