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>
22 #include "rte_swx_port.h"
23 #include "rte_swx_table.h"
25 struct rte_swx_pipeline;
28 #ifndef RTE_SWX_CTL_NAME_SIZE
29 #define RTE_SWX_CTL_NAME_SIZE 64
37 struct rte_swx_ctl_pipeline_info {
38 /** Number of input ports. */
41 /** Number of input ports. */
44 /** Number of actions. */
47 /** Number of tables. */
56 * @param[out] pipeline
59 * 0 on success or the following error codes otherwise:
60 * -EINVAL: Invalid argument.
64 rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
65 struct rte_swx_ctl_pipeline_info *pipeline);
68 * Pipeline NUMA node get
72 * @param[out] numa_node
75 * 0 on success or the following error codes otherwise:
76 * -EINVAL: Invalid argument.
80 rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p,
88 * Input port statistics counters read
93 * Port ID (0 .. *n_ports_in* - 1).
97 * 0 on success or the following error codes otherwise:
98 * -EINVAL: Invalid argument.
102 rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
104 struct rte_swx_port_in_stats *stats);
107 * Output port statistics counters read
112 * Port ID (0 .. *n_ports_out* - 1).
116 * 0 on success or the following error codes otherwise:
117 * -EINVAL: Invalid argument.
121 rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
123 struct rte_swx_port_out_stats *stats);
130 struct rte_swx_ctl_action_info {
132 char name[RTE_SWX_CTL_NAME_SIZE];
134 /** Number of action arguments. */
143 * @param[in] action_id
144 * Action ID (0 .. *n_actions* - 1).
148 * 0 on success or the following error codes otherwise:
149 * -EINVAL: Invalid argument.
153 rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
155 struct rte_swx_ctl_action_info *action);
157 /** Action argument info. */
158 struct rte_swx_ctl_action_arg_info {
159 /** Action argument name. */
160 char name[RTE_SWX_CTL_NAME_SIZE];
162 /** Action argument size (in bits). */
167 * Action argument info get
171 * @param[in] action_id
172 * Action ID (0 .. *n_actions* - 1).
173 * @param[in] action_arg_id
174 * Action ID (0 .. *n_args* - 1).
175 * @param[out] action_arg
176 * Action argument info.
178 * 0 on success or the following error codes otherwise:
179 * -EINVAL: Invalid argument.
183 rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
185 uint32_t action_arg_id,
186 struct rte_swx_ctl_action_arg_info *action_arg);
193 struct rte_swx_ctl_table_info {
195 char name[RTE_SWX_CTL_NAME_SIZE];
197 /** Table creation arguments. */
198 char args[RTE_SWX_CTL_NAME_SIZE];
200 /** Number of match fields. */
201 uint32_t n_match_fields;
203 /** Number of actions. */
206 /** Non-zero (true) when the default action is constant, therefore it
207 * cannot be changed; zero (false) when the default action not constant,
208 * therefore it can be changed.
210 int default_action_is_const;
212 /** Table size parameter. */
221 * @param[in] table_id
222 * Table ID (0 .. *n_tables* - 1).
226 * 0 on success or the following error codes otherwise:
227 * -EINVAL: Invalid argument.
231 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
233 struct rte_swx_ctl_table_info *table);
235 /** Table match field info.
237 * If (n_bits, offset) are known for all the match fields of the table, then the
238 * table (key_offset, key_size, key_mask0) can be computed.
240 struct rte_swx_ctl_table_match_field_info {
241 /** Match type of the current match field. */
242 enum rte_swx_table_match_type match_type;
244 /** Non-zero (true) when the current match field is part of a registered
245 * header, zero (false) when it is part of the registered meta-data.
249 /** Match field size (in bits). */
252 /** Match field offset within its parent struct (one of the headers or
259 * Table match field info get
263 * @param[in] table_id
264 * Table ID (0 .. *n_tables*).
265 * @param[in] match_field_id
266 * Match field ID (0 .. *n_match_fields* - 1).
267 * @param[out] match_field
268 * Table match field info.
270 * 0 on success or the following error codes otherwise:
271 * -EINVAL: Invalid argument.
275 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
277 uint32_t match_field_id,
278 struct rte_swx_ctl_table_match_field_info *match_field);
280 /** Table action info. */
281 struct rte_swx_ctl_table_action_info {
287 * Table action info get
291 * @param[in] table_id
292 * Table ID (0 .. *n_tables*).
293 * @param[in] table_action_id
294 * Action index within the set of table actions (0 .. table n_actions - 1).
295 * Not to be confused with the action ID, which works at the pipeline level
296 * (0 .. pipeline n_actions - 1), which is precisely what this function
297 * returns as part of *table_action*.
298 * @param[out] table_action
301 * 0 on success or the following error codes otherwise:
302 * -EINVAL: Invalid argument.
306 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
308 uint32_t table_action_id,
309 struct rte_swx_ctl_table_action_info *table_action);
312 * Table operations get
316 * @param[in] table_id
317 * Table ID (0 .. *n_tables*).
318 * @param[out] table_ops
319 * Table operations. Only valid when function returns success and *is_stub* is
321 * @param[out] is_stub
322 * A stub table is a table with no match fields. No "regular" table entries
323 * (i.e. entries other than the default entry) can be added to such a table,
324 * therefore the lookup operation always results in lookup miss. Non-zero
325 * (true) when the current table is a stub table, zero (false) otherwise.
327 * 0 on success or the following error codes otherwise:
328 * -EINVAL: Invalid argument.
332 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
334 struct rte_swx_table_ops *table_ops,
342 struct rte_swx_table_state {
346 /** Action ID of the table default action. */
347 uint64_t default_action_id;
349 /** Action data of the table default action. Ignored when the action
350 * data size is zero; otherwise, action data size bytes are meaningful.
352 uint8_t *default_action_data;
356 * Pipeline table state get
360 * @param[out] table_state
361 * After successful execution, the *table_state* contains the pointer to the
362 * current pipeline table state, which is an array of *n_tables* elements,
363 * with array element i containing the state of the i-th pipeline table. The
364 * pipeline continues to own all the data structures directly or indirectly
365 * referenced by the *table_state* until the subsequent successful invocation
366 * of function *rte_swx_pipeline_table_state_set*.
368 * 0 on success or the following error codes otherwise:
369 * -EINVAL: Invalid argument.
373 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
374 struct rte_swx_table_state **table_state);
377 * Pipeline table state set
381 * @param[out] table_state
382 * After successful execution, the pipeline table state is updated to this
383 * *table_state*. The ownership of all the data structures directly or
384 * indirectly referenced by this *table_state* is passed from the caller to
387 * 0 on success or the following error codes otherwise:
388 * -EINVAL: Invalid argument.
392 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
393 struct rte_swx_table_state *table_state);
396 * High Level Reference Table Update API.
399 /** Pipeline control opaque data structure. */
400 struct rte_swx_ctl_pipeline;
403 * Pipeline control create
408 * Pipeline control handle, on success, or NULL, on error.
411 struct rte_swx_ctl_pipeline *
412 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p);
415 * Pipeline table entry add
417 * Schedule entry for addition to table or update as part of the next commit
421 * Pipeline control handle.
422 * @param[in] table_name
425 * Entry to be added to the table.
427 * 0 on success or the following error codes otherwise:
428 * -EINVAL: Invalid argument.
432 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl,
433 const char *table_name,
434 struct rte_swx_table_entry *entry);
437 * Pipeline table default entry add
439 * Schedule table default entry update as part of the next commit operation.
442 * Pipeline control handle.
443 * @param[in] table_name
446 * The new table default entry. The *key* and *key_mask* entry fields are
449 * 0 on success or the following error codes otherwise:
450 * -EINVAL: Invalid argument.
454 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
455 const char *table_name,
456 struct rte_swx_table_entry *entry);
459 * Pipeline table entry delete
461 * Schedule entry for deletion from table as part of the next commit operation.
462 * Request is silently discarded if no such entry exists.
465 * Pipeline control handle.
466 * @param[in] table_name
469 * Entry to be deleted from the table. The *action_id* and *action_data* entry
470 * fields are ignored.
472 * 0 on success or the following error codes otherwise:
473 * -EINVAL: Invalid argument.
477 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl,
478 const char *table_name,
479 struct rte_swx_table_entry *entry);
484 * Perform all the scheduled table work.
487 * Pipeline control handle.
488 * @param[in] abort_on_fail
489 * When non-zero (false), all the scheduled work is discarded after a failed
490 * commit. Otherwise, the scheduled work is still kept pending for the next
493 * 0 on success or the following error codes otherwise:
494 * -EINVAL: Invalid argument.
498 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl,
504 * Discard all the scheduled table work.
507 * Pipeline control handle.
511 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl);
514 * Pipeline table entry read
516 * Read table entry from string.
519 * Pipeline control handle.
520 * @param[in] table_name
523 * String containing the table entry.
525 * 0 on success or the following error codes otherwise:
526 * -EINVAL: Invalid argument.
529 struct rte_swx_table_entry *
530 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl,
531 const char *table_name,
535 * Pipeline table print to file
537 * Print all the table entries to file.
542 * Pipeline control handle.
543 * @param[in] table_name
546 * 0 on success or the following error codes otherwise:
547 * -EINVAL: Invalid argument.
551 rte_swx_ctl_pipeline_table_fprintf(FILE *f,
552 struct rte_swx_ctl_pipeline *ctl,
553 const char *table_name);
556 * Pipeline control free
559 * Pipeline control handle.
563 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl);