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
19 #include <rte_compat.h>
21 #include "rte_swx_port.h"
22 #include "rte_swx_table.h"
24 struct rte_swx_pipeline;
27 #ifndef RTE_SWX_CTL_NAME_SIZE
28 #define RTE_SWX_CTL_NAME_SIZE 64
36 struct rte_swx_ctl_pipeline_info {
37 /** Number of input ports. */
40 /** Number of input ports. */
43 /** Number of actions. */
46 /** Number of tables. */
55 * @param[out] pipeline
58 * 0 on success or the following error codes otherwise:
59 * -EINVAL: Invalid argument.
63 rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
64 struct rte_swx_ctl_pipeline_info *pipeline);
67 * Pipeline NUMA node get
71 * @param[out] numa_node
74 * 0 on success or the following error codes otherwise:
75 * -EINVAL: Invalid argument.
79 rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p,
87 * Input port statistics counters read
92 * Port ID (0 .. *n_ports_in* - 1).
96 * 0 on success or the following error codes otherwise:
97 * -EINVAL: Invalid argument.
101 rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
103 struct rte_swx_port_in_stats *stats);
106 * Output port statistics counters read
111 * Port ID (0 .. *n_ports_out* - 1).
115 * 0 on success or the following error codes otherwise:
116 * -EINVAL: Invalid argument.
120 rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
122 struct rte_swx_port_out_stats *stats);
129 struct rte_swx_ctl_action_info {
131 char name[RTE_SWX_CTL_NAME_SIZE];
133 /** Number of action arguments. */
142 * @param[in] action_id
143 * Action ID (0 .. *n_actions* - 1).
147 * 0 on success or the following error codes otherwise:
148 * -EINVAL: Invalid argument.
152 rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
154 struct rte_swx_ctl_action_info *action);
156 /** Action argument info. */
157 struct rte_swx_ctl_action_arg_info {
158 /** Action argument name. */
159 char name[RTE_SWX_CTL_NAME_SIZE];
161 /** Action argument size (in bits). */
166 * Action argument info get
170 * @param[in] action_id
171 * Action ID (0 .. *n_actions* - 1).
172 * @param[in] action_arg_id
173 * Action ID (0 .. *n_args* - 1).
174 * @param[out] action_arg
175 * Action argument info.
177 * 0 on success or the following error codes otherwise:
178 * -EINVAL: Invalid argument.
182 rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
184 uint32_t action_arg_id,
185 struct rte_swx_ctl_action_arg_info *action_arg);
192 struct rte_swx_ctl_table_info {
194 char name[RTE_SWX_CTL_NAME_SIZE];
196 /** Table creation arguments. */
197 char args[RTE_SWX_CTL_NAME_SIZE];
199 /** Number of match fields. */
200 uint32_t n_match_fields;
202 /** Number of actions. */
205 /** Non-zero (true) when the default action is constant, therefore it
206 * cannot be changed; zero (false) when the default action not constant,
207 * therefore it can be changed.
209 int default_action_is_const;
211 /** Table size parameter. */
220 * @param[in] table_id
221 * Table ID (0 .. *n_tables* - 1).
225 * 0 on success or the following error codes otherwise:
226 * -EINVAL: Invalid argument.
230 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
232 struct rte_swx_ctl_table_info *table);
234 /** Table match field info.
236 * If (n_bits, offset) are known for all the match fields of the table, then the
237 * table (key_offset, key_size, key_mask0) can be computed.
239 struct rte_swx_ctl_table_match_field_info {
240 /** Match type of the current match field. */
241 enum rte_swx_table_match_type match_type;
243 /** Non-zero (true) when the current match field is part of a registered
244 * header, zero (false) when it is part of the registered meta-data.
248 /** Match field size (in bits). */
251 /** Match field offset within its parent struct (one of the headers or
258 * Table match field info get
262 * @param[in] table_id
263 * Table ID (0 .. *n_tables*).
264 * @param[in] match_field_id
265 * Match field ID (0 .. *n_match_fields* - 1).
266 * @param[out] match_field
267 * Table match field info.
269 * 0 on success or the following error codes otherwise:
270 * -EINVAL: Invalid argument.
274 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
276 uint32_t match_field_id,
277 struct rte_swx_ctl_table_match_field_info *match_field);
279 /** Table action info. */
280 struct rte_swx_ctl_table_action_info {
286 * Table action info get
290 * @param[in] table_id
291 * Table ID (0 .. *n_tables*).
292 * @param[in] table_action_id
293 * Action index within the set of table actions (0 .. table n_actions - 1).
294 * Not to be confused with the action ID, which works at the pipeline level
295 * (0 .. pipeline n_actions - 1), which is precisely what this function
296 * returns as part of *table_action*.
297 * @param[out] table_action
300 * 0 on success or the following error codes otherwise:
301 * -EINVAL: Invalid argument.
305 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
307 uint32_t table_action_id,
308 struct rte_swx_ctl_table_action_info *table_action);
311 * Table operations get
315 * @param[in] table_id
316 * Table ID (0 .. *n_tables*).
317 * @param[out] table_ops
318 * Table operations. Only valid when function returns success and *is_stub* is
320 * @param[out] is_stub
321 * A stub table is a table with no match fields. No "regular" table entries
322 * (i.e. entries other than the default entry) can be added to such a table,
323 * therefore the lookup operation always results in lookup miss. Non-zero
324 * (true) when the current table is a stub table, zero (false) otherwise.
326 * 0 on success or the following error codes otherwise:
327 * -EINVAL: Invalid argument.
331 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
333 struct rte_swx_table_ops *table_ops,
341 struct rte_swx_table_state {
345 /** Action ID of the table default action. */
346 uint64_t default_action_id;
348 /** Action data of the table default action. Ignored when the action
349 * data size is zero; otherwise, action data size bytes are meaningful.
351 uint8_t *default_action_data;
355 * Pipeline table state get
359 * @param[out] table_state
360 * After successful execution, the *table_state* contains the pointer to the
361 * current pipeline table state, which is an array of *n_tables* elements,
362 * with array element i containing the state of the i-th pipeline table. The
363 * pipeline continues to own all the data structures directly or indirectly
364 * referenced by the *table_state* until the subsequent successful invocation
365 * of function *rte_swx_pipeline_table_state_set*.
367 * 0 on success or the following error codes otherwise:
368 * -EINVAL: Invalid argument.
372 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
373 struct rte_swx_table_state **table_state);
376 * Pipeline table state set
380 * @param[out] table_state
381 * After successful execution, the pipeline table state is updated to this
382 * *table_state*. The ownership of all the data structures directly or
383 * indirectly referenced by this *table_state* is passed from the caller to
386 * 0 on success or the following error codes otherwise:
387 * -EINVAL: Invalid argument.
391 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
392 struct rte_swx_table_state *table_state);
395 * High Level Reference Table Update API.
398 /** Pipeline control opaque data structure. */
399 struct rte_swx_ctl_pipeline;
402 * Pipeline control create
407 * Pipeline control handle, on success, or NULL, on error.
410 struct rte_swx_ctl_pipeline *
411 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p);
414 * Pipeline table entry add
416 * Schedule entry for addition to table or update as part of the next commit
420 * Pipeline control handle.
421 * @param[in] table_name
424 * Entry to be added to the table.
426 * 0 on success or the following error codes otherwise:
427 * -EINVAL: Invalid argument.
431 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl,
432 const char *table_name,
433 struct rte_swx_table_entry *entry);
436 * Pipeline table default entry add
438 * Schedule table default entry update as part of the next commit operation.
441 * Pipeline control handle.
442 * @param[in] table_name
445 * The new table default entry. The *key* and *key_mask* entry fields are
448 * 0 on success or the following error codes otherwise:
449 * -EINVAL: Invalid argument.
453 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl,
454 const char *table_name,
455 struct rte_swx_table_entry *entry);
458 * Pipeline table entry delete
460 * Schedule entry for deletion from table as part of the next commit operation.
461 * Request is silently discarded if no such entry exists.
464 * Pipeline control handle.
465 * @param[in] table_name
468 * Entry to be deleted from the table. The *action_id* and *action_data* entry
469 * fields are ignored.
471 * 0 on success or the following error codes otherwise:
472 * -EINVAL: Invalid argument.
476 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl,
477 const char *table_name,
478 struct rte_swx_table_entry *entry);
483 * Perform all the scheduled table work.
486 * Pipeline control handle.
487 * @param[in] abort_on_fail
488 * When non-zero (false), all the scheduled work is discarded after a failed
489 * commit. Otherwise, the scheduled work is still kept pending for the next
492 * 0 on success or the following error codes otherwise:
493 * -EINVAL: Invalid argument.
497 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl,
503 * Discard all the scheduled table work.
506 * Pipeline control handle.
510 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl);
513 * Pipeline table entry read
515 * Read table entry from string.
518 * Pipeline control handle.
519 * @param[in] table_name
522 * String containing the table entry.
524 * 0 on success or the following error codes otherwise:
525 * -EINVAL: Invalid argument.
528 struct rte_swx_table_entry *
529 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl,
530 const char *table_name,
534 * Pipeline table print to file
536 * Print all the table entries to file.
541 * Pipeline control handle.
542 * @param[in] table_name
545 * 0 on success or the following error codes otherwise:
546 * -EINVAL: Invalid argument.
550 rte_swx_ctl_pipeline_table_fprintf(FILE *f,
551 struct rte_swx_ctl_pipeline *ctl,
552 const char *table_name);
555 * Pipeline control free
558 * Pipeline control handle.
562 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl);