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. */
50 /** Number of register arrays. */
59 * @param[out] pipeline
62 * 0 on success or the following error codes otherwise:
63 * -EINVAL: Invalid argument.
67 rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
68 struct rte_swx_ctl_pipeline_info *pipeline);
71 * Pipeline NUMA node get
75 * @param[out] numa_node
78 * 0 on success or the following error codes otherwise:
79 * -EINVAL: Invalid argument.
83 rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p,
91 * Input port statistics counters read
96 * Port ID (0 .. *n_ports_in* - 1).
100 * 0 on success or the following error codes otherwise:
101 * -EINVAL: Invalid argument.
105 rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
107 struct rte_swx_port_in_stats *stats);
110 * Output port statistics counters read
115 * Port ID (0 .. *n_ports_out* - 1).
119 * 0 on success or the following error codes otherwise:
120 * -EINVAL: Invalid argument.
124 rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
126 struct rte_swx_port_out_stats *stats);
133 struct rte_swx_ctl_action_info {
135 char name[RTE_SWX_CTL_NAME_SIZE];
137 /** Number of action arguments. */
146 * @param[in] action_id
147 * Action ID (0 .. *n_actions* - 1).
151 * 0 on success or the following error codes otherwise:
152 * -EINVAL: Invalid argument.
156 rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
158 struct rte_swx_ctl_action_info *action);
160 /** Action argument info. */
161 struct rte_swx_ctl_action_arg_info {
162 /** Action argument name. */
163 char name[RTE_SWX_CTL_NAME_SIZE];
165 /** Action argument size (in bits). */
170 * Action argument info get
174 * @param[in] action_id
175 * Action ID (0 .. *n_actions* - 1).
176 * @param[in] action_arg_id
177 * Action ID (0 .. *n_args* - 1).
178 * @param[out] action_arg
179 * Action argument info.
181 * 0 on success or the following error codes otherwise:
182 * -EINVAL: Invalid argument.
186 rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
188 uint32_t action_arg_id,
189 struct rte_swx_ctl_action_arg_info *action_arg);
196 struct rte_swx_ctl_table_info {
198 char name[RTE_SWX_CTL_NAME_SIZE];
200 /** Table creation arguments. */
201 char args[RTE_SWX_CTL_NAME_SIZE];
203 /** Number of match fields. */
204 uint32_t n_match_fields;
206 /** Number of actions. */
209 /** Non-zero (true) when the default action is constant, therefore it
210 * cannot be changed; zero (false) when the default action not constant,
211 * therefore it can be changed.
213 int default_action_is_const;
215 /** Table size parameter. */
224 * @param[in] table_id
225 * Table ID (0 .. *n_tables* - 1).
229 * 0 on success or the following error codes otherwise:
230 * -EINVAL: Invalid argument.
234 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
236 struct rte_swx_ctl_table_info *table);
238 /** Table match field info.
240 * If (n_bits, offset) are known for all the match fields of the table, then the
241 * table (key_offset, key_size, key_mask0) can be computed.
243 struct rte_swx_ctl_table_match_field_info {
244 /** Match type of the current match field. */
245 enum rte_swx_table_match_type match_type;
247 /** Non-zero (true) when the current match field is part of a registered
248 * header, zero (false) when it is part of the registered meta-data.
252 /** Match field size (in bits). */
255 /** Match field offset within its parent struct (one of the headers or
262 * Table match field info get
266 * @param[in] table_id
267 * Table ID (0 .. *n_tables*).
268 * @param[in] match_field_id
269 * Match field ID (0 .. *n_match_fields* - 1).
270 * @param[out] match_field
271 * Table match field info.
273 * 0 on success or the following error codes otherwise:
274 * -EINVAL: Invalid argument.
278 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
280 uint32_t match_field_id,
281 struct rte_swx_ctl_table_match_field_info *match_field);
283 /** Table action info. */
284 struct rte_swx_ctl_table_action_info {
290 * Table action info get
294 * @param[in] table_id
295 * Table ID (0 .. *n_tables*).
296 * @param[in] table_action_id
297 * Action index within the set of table actions (0 .. table n_actions - 1).
298 * Not to be confused with the action ID, which works at the pipeline level
299 * (0 .. pipeline n_actions - 1), which is precisely what this function
300 * returns as part of *table_action*.
301 * @param[out] table_action
304 * 0 on success or the following error codes otherwise:
305 * -EINVAL: Invalid argument.
309 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
311 uint32_t table_action_id,
312 struct rte_swx_ctl_table_action_info *table_action);
315 * Table operations get
319 * @param[in] table_id
320 * Table ID (0 .. *n_tables*).
321 * @param[out] table_ops
322 * Table operations. Only valid when function returns success and *is_stub* is
324 * @param[out] is_stub
325 * A stub table is a table with no match fields. No "regular" table entries
326 * (i.e. entries other than the default entry) can be added to such a table,
327 * therefore the lookup operation always results in lookup miss. Non-zero
328 * (true) when the current table is a stub table, zero (false) otherwise.
330 * 0 on success or the following error codes otherwise:
331 * -EINVAL: Invalid argument.
335 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
337 struct rte_swx_table_ops *table_ops,
345 struct rte_swx_table_state {
349 /** Action ID of the table default action. */
350 uint64_t default_action_id;
352 /** Action data of the table default action. Ignored when the action
353 * data size is zero; otherwise, action data size bytes are meaningful.
355 uint8_t *default_action_data;
359 * Pipeline table state get
363 * @param[out] table_state
364 * After successful execution, the *table_state* contains the pointer to the
365 * current pipeline table state, which is an array of *n_tables* elements,
366 * with array element i containing the state of the i-th pipeline table. The
367 * pipeline continues to own all the data structures directly or indirectly
368 * referenced by the *table_state* until the subsequent successful invocation
369 * of function *rte_swx_pipeline_table_state_set*.
371 * 0 on success or the following error codes otherwise:
372 * -EINVAL: Invalid argument.
376 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
377 struct rte_swx_table_state **table_state);
380 * Pipeline table state set
384 * @param[out] table_state
385 * After successful execution, the pipeline table state is updated to this
386 * *table_state*. The ownership of all the data structures directly or
387 * indirectly referenced by this *table_state* is passed from the caller to
390 * 0 on success or the following error codes otherwise:
391 * -EINVAL: Invalid argument.
395 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
396 struct rte_swx_table_state *table_state);
399 * High Level Reference Table Update API.
402 /** Pipeline control opaque data structure. */
403 struct rte_swx_ctl_pipeline;
406 * Pipeline control create
411 * Pipeline control handle, on success, or NULL, on error.
414 struct rte_swx_ctl_pipeline *
415 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p);
418 * Pipeline table entry add
420 * Schedule entry for addition to table or update as part of the next commit
424 * Pipeline control handle.
425 * @param[in] table_name
428 * Entry to be added to the table.
430 * 0 on success or the following error codes otherwise:
431 * -EINVAL: Invalid argument.
435 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl,
436 const char *table_name,
437 struct rte_swx_table_entry *entry);
440 * Pipeline table default entry add
442 * Schedule table default entry update as part of the next commit operation.
445 * Pipeline control handle.
446 * @param[in] table_name
449 * The new table default entry. The *key* and *key_mask* entry fields are
452 * 0 on success or the following error codes otherwise:
453 * -EINVAL: Invalid argument.
457 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
458 const char *table_name,
459 struct rte_swx_table_entry *entry);
462 * Pipeline table entry delete
464 * Schedule entry for deletion from table as part of the next commit operation.
465 * Request is silently discarded if no such entry exists.
468 * Pipeline control handle.
469 * @param[in] table_name
472 * Entry to be deleted from the table. The *action_id* and *action_data* entry
473 * fields are ignored.
475 * 0 on success or the following error codes otherwise:
476 * -EINVAL: Invalid argument.
480 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl,
481 const char *table_name,
482 struct rte_swx_table_entry *entry);
487 * Perform all the scheduled table work.
490 * Pipeline control handle.
491 * @param[in] abort_on_fail
492 * When non-zero (false), all the scheduled work is discarded after a failed
493 * commit. Otherwise, the scheduled work is still kept pending for the next
496 * 0 on success or the following error codes otherwise:
497 * -EINVAL: Invalid argument.
501 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl,
507 * Discard all the scheduled table work.
510 * Pipeline control handle.
514 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl);
517 * Pipeline table entry read
519 * Read table entry from string.
522 * Pipeline control handle.
523 * @param[in] table_name
526 * String containing the table entry.
527 * @param[out] is_blank_or_comment
528 * On error, this argument provides an indication of whether *string* contains
529 * an invalid table entry (set to zero) or a blank or comment line that should
530 * typically be ignored (set to a non-zero value).
532 * 0 on success or the following error codes otherwise:
533 * -EINVAL: Invalid argument.
536 struct rte_swx_table_entry *
537 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl,
538 const char *table_name,
540 int *is_blank_or_comment);
543 * Pipeline table print to file
545 * Print all the table entries to file.
550 * Pipeline control handle.
551 * @param[in] table_name
554 * 0 on success or the following error codes otherwise:
555 * -EINVAL: Invalid argument.
559 rte_swx_ctl_pipeline_table_fprintf(FILE *f,
560 struct rte_swx_ctl_pipeline *ctl,
561 const char *table_name);
564 * Register Array Query API.
567 /** Register array info. */
568 struct rte_swx_ctl_regarray_info {
569 /** Register array name. */
570 char name[RTE_SWX_CTL_NAME_SIZE];
572 /** Register array size. */
577 * Register array info get
581 * @param[in] regarray_id
582 * Register array ID (0 .. *n_regarrays* - 1).
583 * @param[out] regarray
584 * Register array info.
586 * 0 on success or the following error codes otherwise:
587 * -EINVAL: Invalid argument.
591 rte_swx_ctl_regarray_info_get(struct rte_swx_pipeline *p,
592 uint32_t regarray_id,
593 struct rte_swx_ctl_regarray_info *regarray);
600 * @param[in] regarray_name
601 * Register array name.
602 * @param[in] regarray_index
603 * Register index within the array (0 .. *size* - 1).
605 * Current register value.
607 * 0 on success or the following error codes otherwise:
608 * -EINVAL: Invalid argument.
612 rte_swx_ctl_pipeline_regarray_read(struct rte_swx_pipeline *p,
613 const char *regarray_name,
614 uint32_t regarray_index,
622 * @param[in] regarray_name
623 * Register array name.
624 * @param[in] regarray_index
625 * Register index within the array (0 .. *size* - 1).
627 * Value to be written to the register.
629 * 0 on success or the following error codes otherwise:
630 * -EINVAL: Invalid argument.
634 rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
635 const char *regarray_name,
636 uint32_t regarray_index,
640 * Pipeline control free
643 * Pipeline control handle.
647 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl);