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 /** Hash function. */ 240 rte_swx_hash_func_t hash_func; 241 242 /** Table size parameter. */ 243 uint32_t size; 244 }; 245 246 /** 247 * Table info get 248 * 249 * @param[in] p 250 * Pipeline handle. 251 * @param[in] table_id 252 * Table ID (0 .. *n_tables* - 1). 253 * @param[out] table 254 * Table info. 255 * @return 256 * 0 on success or the following error codes otherwise: 257 * -EINVAL: Invalid argument. 258 */ 259 __rte_experimental 260 int 261 rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p, 262 uint32_t table_id, 263 struct rte_swx_ctl_table_info *table); 264 265 /** Table match field info. 266 * 267 * If (n_bits, offset) are known for all the match fields of the table, then the 268 * table (key_offset, key_size, key_mask0) can be computed. 269 */ 270 struct rte_swx_ctl_table_match_field_info { 271 /** Match type of the current match field. */ 272 enum rte_swx_table_match_type match_type; 273 274 /** Non-zero (true) when the current match field is part of a registered 275 * header, zero (false) when it is part of the registered meta-data. 276 */ 277 int is_header; 278 279 /** Match field size (in bits). */ 280 uint32_t n_bits; 281 282 /** Match field offset within its parent struct (one of the headers or 283 * the meta-data). 284 */ 285 uint32_t offset; 286 }; 287 288 /** 289 * Table match field info get 290 * 291 * @param[in] p 292 * Pipeline handle. 293 * @param[in] table_id 294 * Table ID (0 .. *n_tables*). 295 * @param[in] match_field_id 296 * Match field ID (0 .. *n_match_fields* - 1). 297 * @param[out] match_field 298 * Table match field info. 299 * @return 300 * 0 on success or the following error codes otherwise: 301 * -EINVAL: Invalid argument. 302 */ 303 __rte_experimental 304 int 305 rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p, 306 uint32_t table_id, 307 uint32_t match_field_id, 308 struct rte_swx_ctl_table_match_field_info *match_field); 309 310 /** Table action info. */ 311 struct rte_swx_ctl_table_action_info { 312 /** Action ID. */ 313 uint32_t action_id; 314 315 /** When non-zero (true), the action can be assigned to regular table entries. */ 316 int action_is_for_table_entries; 317 318 /** When non-zero (true), the action can be assigned to the table default entry. */ 319 int action_is_for_default_entry; 320 }; 321 322 /** 323 * Table action info get 324 * 325 * @param[in] p 326 * Pipeline handle. 327 * @param[in] table_id 328 * Table ID (0 .. *n_tables*). 329 * @param[in] table_action_id 330 * Action index within the set of table actions (0 .. table n_actions - 1). 331 * Not to be confused with the action ID, which works at the pipeline level 332 * (0 .. pipeline n_actions - 1), which is precisely what this function 333 * returns as part of *table_action*. 334 * @param[out] table_action 335 * Table action info. 336 * @return 337 * 0 on success or the following error codes otherwise: 338 * -EINVAL: Invalid argument. 339 */ 340 __rte_experimental 341 int 342 rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p, 343 uint32_t table_id, 344 uint32_t table_action_id, 345 struct rte_swx_ctl_table_action_info *table_action); 346 347 /** 348 * Table operations get 349 * 350 * @param[in] p 351 * Pipeline handle. 352 * @param[in] table_id 353 * Table ID (0 .. *n_tables*). 354 * @param[out] table_ops 355 * Table operations. Only valid when function returns success and *is_stub* is 356 * zero (false). 357 * @param[out] is_stub 358 * A stub table is a table with no match fields. No "regular" table entries 359 * (i.e. entries other than the default entry) can be added to such a table, 360 * therefore the lookup operation always results in lookup miss. Non-zero 361 * (true) when the current table is a stub table, zero (false) otherwise. 362 * @return 363 * 0 on success or the following error codes otherwise: 364 * -EINVAL: Invalid argument. 365 */ 366 __rte_experimental 367 int 368 rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p, 369 uint32_t table_id, 370 struct rte_swx_table_ops *table_ops, 371 int *is_stub); 372 373 /** Table statistics. */ 374 struct rte_swx_table_stats { 375 /** Number of packets with lookup hit. */ 376 uint64_t n_pkts_hit; 377 378 /** Number of packets with lookup miss. */ 379 uint64_t n_pkts_miss; 380 381 /** Number of packets (with either lookup hit or miss) per pipeline 382 * action. Array of pipeline *n_actions* elements indexed by the 383 * pipeline-level *action_id*, therefore this array has the same size 384 * for all the tables within the same pipeline. 385 */ 386 uint64_t *n_pkts_action; 387 }; 388 389 /** 390 * Table statistics counters read 391 * 392 * @param[in] p 393 * Pipeline handle. 394 * @param[in] table_name 395 * Table name. 396 * @param[out] stats 397 * Table stats. Must point to a pre-allocated structure. The *n_pkts_action* 398 * field also needs to be pre-allocated as array of pipeline *n_actions* 399 * elements. The pipeline actions that are not valid for the current table 400 * have their associated *n_pkts_action* element always set to zero. 401 * @return 402 * 0 on success or the following error codes otherwise: 403 * -EINVAL: Invalid argument. 404 */ 405 __rte_experimental 406 int 407 rte_swx_ctl_pipeline_table_stats_read(struct rte_swx_pipeline *p, 408 const char *table_name, 409 struct rte_swx_table_stats *stats); 410 411 /* 412 * Selector Table Query API. 413 */ 414 415 /** Selector info. */ 416 struct rte_swx_ctl_selector_info { 417 /** Selector table name. */ 418 char name[RTE_SWX_CTL_NAME_SIZE]; 419 420 /** Number of selector fields. */ 421 uint32_t n_selector_fields; 422 423 /** Maximum number of groups. */ 424 uint32_t n_groups_max; 425 426 /** Maximum number of members per group. */ 427 uint32_t n_members_per_group_max; 428 }; 429 430 /** 431 * Selector table info get 432 * 433 * @param[in] p 434 * Pipeline handle. 435 * @param[in] selector_id 436 * Selector table ID (0 .. *n_selectors* - 1). 437 * @param[out] selector 438 * Selector table info. 439 * @return 440 * 0 on success or the following error codes otherwise: 441 * -EINVAL: Invalid argument. 442 */ 443 __rte_experimental 444 int 445 rte_swx_ctl_selector_info_get(struct rte_swx_pipeline *p, 446 uint32_t selector_id, 447 struct rte_swx_ctl_selector_info *selector); 448 449 /** 450 * Selector table "group ID" field info get 451 * 452 * @param[in] p 453 * Pipeline handle. 454 * @param[in] selector_id 455 * Selector table ID (0 .. *n_selectors*). 456 * @param[out] field 457 * Selector table "group ID" field info. 458 * @return 459 * 0 on success or the following error codes otherwise: 460 * -EINVAL: Invalid argument. 461 */ 462 __rte_experimental 463 int 464 rte_swx_ctl_selector_group_id_field_info_get(struct rte_swx_pipeline *p, 465 uint32_t selector_id, 466 struct rte_swx_ctl_table_match_field_info *field); 467 468 /** 469 * Sselector table selector field info get 470 * 471 * @param[in] p 472 * Pipeline handle. 473 * @param[in] selector_id 474 * Selector table ID (0 .. *n_selectors*). 475 * @param[in] selector_field_id 476 * Selector table selector field ID (0 .. *n_selector_fields* - 1). 477 * @param[out] field 478 * Selector table selector field info. 479 * @return 480 * 0 on success or the following error codes otherwise: 481 * -EINVAL: Invalid argument. 482 */ 483 __rte_experimental 484 int 485 rte_swx_ctl_selector_field_info_get(struct rte_swx_pipeline *p, 486 uint32_t selector_id, 487 uint32_t selector_field_id, 488 struct rte_swx_ctl_table_match_field_info *field); 489 490 /** 491 * Selector table "member ID" field info get 492 * 493 * @param[in] p 494 * Pipeline handle. 495 * @param[in] selector_id 496 * Selector table ID (0 .. *n_selectors*). 497 * @param[out] field 498 * Selector table "member ID" field info. 499 * @return 500 * 0 on success or the following error codes otherwise: 501 * -EINVAL: Invalid argument. 502 */ 503 __rte_experimental 504 int 505 rte_swx_ctl_selector_member_id_field_info_get(struct rte_swx_pipeline *p, 506 uint32_t selector_id, 507 struct rte_swx_ctl_table_match_field_info *field); 508 509 /** Selector table statistics. */ 510 struct rte_swx_pipeline_selector_stats { 511 /** Number of packets. */ 512 uint64_t n_pkts; 513 }; 514 515 /** 516 * Selector table statistics counters read 517 * 518 * @param[in] p 519 * Pipeline handle. 520 * @param[in] selector_name 521 * Selector table name. 522 * @param[out] stats 523 * Selector table stats. Must point to a pre-allocated structure. 524 * @return 525 * 0 on success or the following error codes otherwise: 526 * -EINVAL: Invalid argument. 527 */ 528 __rte_experimental 529 int 530 rte_swx_ctl_pipeline_selector_stats_read(struct rte_swx_pipeline *p, 531 const char *selector_name, 532 struct rte_swx_pipeline_selector_stats *stats); 533 534 /* 535 * Learner Table Query API. 536 */ 537 538 /** Learner table info. */ 539 struct rte_swx_ctl_learner_info { 540 /** Learner table name. */ 541 char name[RTE_SWX_CTL_NAME_SIZE]; 542 543 /** Number of match fields. */ 544 uint32_t n_match_fields; 545 546 /** Number of actions. */ 547 uint32_t n_actions; 548 549 /** Non-zero (true) when the default action is constant, therefore it 550 * cannot be changed; zero (false) when the default action not constant, 551 * therefore it can be changed. 552 */ 553 int default_action_is_const; 554 555 /** Learner table size parameter. */ 556 uint32_t size; 557 558 /** Number of possible key timeout values. */ 559 uint32_t n_key_timeouts; 560 }; 561 562 /** 563 * Learner table info get 564 * 565 * @param[in] p 566 * Pipeline handle. 567 * @param[in] learner_id 568 * Learner table ID (0 .. *n_learners* - 1). 569 * @param[out] learner 570 * Learner table info. 571 * @return 572 * 0 on success or the following error codes otherwise: 573 * -EINVAL: Invalid argument. 574 */ 575 __rte_experimental 576 int 577 rte_swx_ctl_learner_info_get(struct rte_swx_pipeline *p, 578 uint32_t learner_id, 579 struct rte_swx_ctl_learner_info *learner); 580 581 /** 582 * Learner table match field info get 583 * 584 * @param[in] p 585 * Pipeline handle. 586 * @param[in] learner_id 587 * Learner table ID (0 .. *n_learners* - 1). 588 * @param[in] match_field_id 589 * Match field ID (0 .. *n_match_fields* - 1). 590 * @param[out] match_field 591 * Learner table match field info. 592 * @return 593 * 0 on success or the following error codes otherwise: 594 * -EINVAL: Invalid argument. 595 */ 596 __rte_experimental 597 int 598 rte_swx_ctl_learner_match_field_info_get(struct rte_swx_pipeline *p, 599 uint32_t learner_id, 600 uint32_t match_field_id, 601 struct rte_swx_ctl_table_match_field_info *match_field); 602 603 /** 604 * Learner table action info get 605 * 606 * @param[in] p 607 * Pipeline handle. 608 * @param[in] learner_id 609 * Learner table ID (0 .. *n_learners* - 1). 610 * @param[in] learner_action_id 611 * Action index within the set of learner table actions (0 .. learner table n_actions - 1). Not 612 * to be confused with the pipeline-leve action ID (0 .. pipeline n_actions - 1), which is 613 * precisely what this function returns as part of the *learner_action*. 614 * @param[out] learner_action 615 * Learner action info. 616 * @return 617 * 0 on success or the following error codes otherwise: 618 * -EINVAL: Invalid argument. 619 */ 620 __rte_experimental 621 int 622 rte_swx_ctl_learner_action_info_get(struct rte_swx_pipeline *p, 623 uint32_t learner_id, 624 uint32_t learner_action_id, 625 struct rte_swx_ctl_table_action_info *learner_action); 626 627 /** 628 * Learner table timeout get 629 * 630 * @param[in] p 631 * Pipeline handle. 632 * @param[in] learner_id 633 * Learner table ID (0 .. *n_learners* - 1). 634 * @param[in] timeout_id 635 * Timeout ID. 636 * @param[out] timeout 637 * Timeout value measured in seconds. Must be non-NULL. 638 * @return 639 * 0 on success or the following error codes otherwise: 640 * -EINVAL: Invalid argument. 641 */ 642 __rte_experimental 643 int 644 rte_swx_ctl_pipeline_learner_timeout_get(struct rte_swx_pipeline *p, 645 uint32_t learner_id, 646 uint32_t timeout_id, 647 uint32_t *timeout); 648 649 /** 650 * Learner table timeout set 651 * 652 * @param[in] p 653 * Pipeline handle. 654 * @param[in] learner_id 655 * Learner table ID (0 .. *n_learners* - 1). 656 * @param[in] timeout_id 657 * Timeout ID. 658 * @param[in] timeout 659 * Timeout value measured in seconds. 660 * @return 661 * 0 on success or the following error codes otherwise: 662 * -EINVAL: Invalid argument. 663 */ 664 __rte_experimental 665 int 666 rte_swx_ctl_pipeline_learner_timeout_set(struct rte_swx_pipeline *p, 667 uint32_t learner_id, 668 uint32_t timeout_id, 669 uint32_t timeout); 670 671 /** Learner table statistics. */ 672 struct rte_swx_learner_stats { 673 /** Number of packets with lookup hit. */ 674 uint64_t n_pkts_hit; 675 676 /** Number of packets with lookup miss. */ 677 uint64_t n_pkts_miss; 678 679 /** Number of packets with successful learning. */ 680 uint64_t n_pkts_learn_ok; 681 682 /** Number of packets with learning error. */ 683 uint64_t n_pkts_learn_err; 684 685 /** Number of packets with rearm event. */ 686 uint64_t n_pkts_rearm; 687 688 /** Number of packets with forget event. */ 689 uint64_t n_pkts_forget; 690 691 /** Number of packets (with either lookup hit or miss) per pipeline action. Array of 692 * pipeline *n_actions* elements indexed by the pipeline-level *action_id*, therefore this 693 * array has the same size for all the tables within the same pipeline. 694 */ 695 uint64_t *n_pkts_action; 696 }; 697 698 /** 699 * Learner table statistics counters read 700 * 701 * @param[in] p 702 * Pipeline handle. 703 * @param[in] learner_name 704 * Learner table name. 705 * @param[out] stats 706 * Learner table stats. Must point to a pre-allocated structure. The *n_pkts_action* field also 707 * needs to be pre-allocated as array of pipeline *n_actions* elements. The pipeline actions that 708 * are not valid for the current learner table have their associated *n_pkts_action* element 709 * always set to zero. 710 * @return 711 * 0 on success or the following error codes otherwise: 712 * -EINVAL: Invalid argument. 713 */ 714 __rte_experimental 715 int 716 rte_swx_ctl_pipeline_learner_stats_read(struct rte_swx_pipeline *p, 717 const char *learner_name, 718 struct rte_swx_learner_stats *stats); 719 720 /* 721 * Packet mirroring API. 722 */ 723 724 /** Packet mirroring session parameters. */ 725 struct rte_swx_pipeline_mirroring_session_params { 726 /** Output port ID. */ 727 uint32_t port_id; 728 729 /** Fast clone flag. */ 730 int fast_clone; 731 732 /** Truncation packet length (in bytes). Zero means no truncation. */ 733 uint32_t truncation_length; 734 }; 735 736 /** 737 * Packet mirroring session set 738 * 739 * @param[in] p 740 * Pipeline handle. 741 * @param[in] session_id 742 * Packet mirroring session ID. 743 * @param[in] params 744 * Packet mirroring session parameters. 745 * @return 746 * 0 on success or the following error codes otherwise: 747 * -EINVAL: Invalid argument; 748 * -EEXIST: Pipeline was already built successfully. 749 */ 750 __rte_experimental 751 int 752 rte_swx_ctl_pipeline_mirroring_session_set(struct rte_swx_pipeline *p, 753 uint32_t session_id, 754 struct rte_swx_pipeline_mirroring_session_params *params); 755 756 /* 757 * Table Update API. 758 */ 759 760 /** Table state. */ 761 struct rte_swx_table_state { 762 /** Table object. */ 763 void *obj; 764 765 /** Action ID of the table default action. */ 766 uint64_t default_action_id; 767 768 /** Action data of the table default action. Ignored when the action 769 * data size is zero; otherwise, action data size bytes are meaningful. 770 */ 771 uint8_t *default_action_data; 772 }; 773 774 /** 775 * Pipeline table state get 776 * 777 * @param[in] p 778 * Pipeline handle. 779 * @param[out] table_state 780 * After successful execution, the *table_state* contains the pointer to the 781 * current pipeline table state, which is an array of *n_tables* elements, 782 * with array element i containing the state of the i-th pipeline table. The 783 * pipeline continues to own all the data structures directly or indirectly 784 * referenced by the *table_state* until the subsequent successful invocation 785 * of function *rte_swx_pipeline_table_state_set*. 786 * @return 787 * 0 on success or the following error codes otherwise: 788 * -EINVAL: Invalid argument. 789 */ 790 __rte_experimental 791 int 792 rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p, 793 struct rte_swx_table_state **table_state); 794 795 /** 796 * Pipeline table state set 797 * 798 * @param[in] p 799 * Pipeline handle. 800 * @param[out] table_state 801 * After successful execution, the pipeline table state is updated to this 802 * *table_state*. The ownership of all the data structures directly or 803 * indirectly referenced by this *table_state* is passed from the caller to 804 * the pipeline. 805 * @return 806 * 0 on success or the following error codes otherwise: 807 * -EINVAL: Invalid argument. 808 */ 809 __rte_experimental 810 int 811 rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p, 812 struct rte_swx_table_state *table_state); 813 814 /* 815 * High Level Reference Table Update API. 816 */ 817 818 /** Pipeline control opaque data structure. */ 819 struct rte_swx_ctl_pipeline; 820 821 /** 822 * Pipeline control find 823 * 824 * @param[in] name 825 * Pipeline name. 826 * @return 827 * Valid pipeline control handle if found or NULL otherwise. 828 */ 829 __rte_experimental 830 struct rte_swx_ctl_pipeline * 831 rte_swx_ctl_pipeline_find(const char *name); 832 833 /** 834 * Pipeline control create 835 * 836 * @param[in] p 837 * Pipeline handle. 838 * @return 839 * Pipeline control handle, on success, or NULL, on error. 840 */ 841 __rte_experimental 842 struct rte_swx_ctl_pipeline * 843 rte_swx_ctl_pipeline_create(struct rte_swx_pipeline *p); 844 845 /** 846 * Pipeline table entry add 847 * 848 * Schedule entry for addition to table or update as part of the next commit 849 * operation. 850 * 851 * @param[in] ctl 852 * Pipeline control handle. 853 * @param[in] table_name 854 * Table name. 855 * @param[in] entry 856 * Entry to be added to the table. 857 * @return 858 * 0 on success or the following error codes otherwise: 859 * -EINVAL: Invalid argument. 860 */ 861 __rte_experimental 862 int 863 rte_swx_ctl_pipeline_table_entry_add(struct rte_swx_ctl_pipeline *ctl, 864 const char *table_name, 865 struct rte_swx_table_entry *entry); 866 867 /** 868 * Pipeline table default entry add 869 * 870 * Schedule table default entry update as part of the next commit operation. 871 * 872 * @param[in] ctl 873 * Pipeline control handle. 874 * @param[in] table_name 875 * Table name. 876 * @param[in] entry 877 * The new table default entry. The *key* and *key_mask* entry fields are 878 * ignored. 879 * @return 880 * 0 on success or the following error codes otherwise: 881 * -EINVAL: Invalid argument. 882 */ 883 __rte_experimental 884 int 885 rte_swx_ctl_pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *ctl, 886 const char *table_name, 887 struct rte_swx_table_entry *entry); 888 889 /** 890 * Pipeline table entry delete 891 * 892 * Schedule entry for deletion from table as part of the next commit operation. 893 * Request is silently discarded if no such entry exists. 894 * 895 * @param[in] ctl 896 * Pipeline control handle. 897 * @param[in] table_name 898 * Table name. 899 * @param[in] entry 900 * Entry to be deleted from the table. The *action_id* and *action_data* entry 901 * fields are ignored. 902 * @return 903 * 0 on success or the following error codes otherwise: 904 * -EINVAL: Invalid argument. 905 */ 906 __rte_experimental 907 int 908 rte_swx_ctl_pipeline_table_entry_delete(struct rte_swx_ctl_pipeline *ctl, 909 const char *table_name, 910 struct rte_swx_table_entry *entry); 911 912 /** 913 * Pipeline selector table group add 914 * 915 * Add a new group to a selector table. This operation is executed before this 916 * function returns and its result is independent of the result of the next 917 * commit operation. 918 * 919 * @param[in] ctl 920 * Pipeline control handle. 921 * @param[in] selector_name 922 * Selector table name. 923 * @param[out] group_id 924 * The ID of the new group. Only valid when the function call is successful. 925 * This group is initially empty, i.e. it does not contain any members. 926 * @return 927 * 0 on success or the following error codes otherwise: 928 * -EINVAL: Invalid argument; 929 * -ENOSPC: All groups are currently in use, no group available. 930 */ 931 __rte_experimental 932 int 933 rte_swx_ctl_pipeline_selector_group_add(struct rte_swx_ctl_pipeline *ctl, 934 const char *selector_name, 935 uint32_t *group_id); 936 937 /** 938 * Pipeline selector table group delete 939 * 940 * Schedule a group for deletion as part of the next commit operation. The group 941 * to be deleted can be empty or non-empty. 942 * 943 * @param[in] ctl 944 * Pipeline control handle. 945 * @param[in] selector_name 946 * Selector table name. 947 * @param[in] group_id 948 * Group to be deleted from the selector table. 949 * @return 950 * 0 on success or the following error codes otherwise: 951 * -EINVAL: Invalid argument; 952 * -ENOMEM: Not enough memory. 953 */ 954 __rte_experimental 955 int 956 rte_swx_ctl_pipeline_selector_group_delete(struct rte_swx_ctl_pipeline *ctl, 957 const char *selector_name, 958 uint32_t group_id); 959 960 /** 961 * Pipeline selector table member add to group 962 * 963 * Schedule the operation to add a new member to an existing group as part of 964 * the next commit operation. If this member is already in this group, the 965 * member weight is updated to the new value. A weight of zero means this member 966 * is to be deleted from the group. 967 * 968 * @param[in] ctl 969 * Pipeline control handle. 970 * @param[in] selector_name 971 * Selector table name. 972 * @param[in] group_id 973 * The group ID. 974 * @param[in] member_id 975 * The member to be added to the group. 976 * @param[in] member_weight 977 * Member weight. 978 * @return 979 * 0 on success or the following error codes otherwise: 980 * -EINVAL: Invalid argument; 981 * -ENOMEM: Not enough memory; 982 * -ENOSPC: The group is full. 983 */ 984 __rte_experimental 985 int 986 rte_swx_ctl_pipeline_selector_group_member_add(struct rte_swx_ctl_pipeline *ctl, 987 const char *selector_name, 988 uint32_t group_id, 989 uint32_t member_id, 990 uint32_t member_weight); 991 992 /** 993 * Pipeline selector table member delete from group 994 * 995 * Schedule the operation to delete a member from an existing group as part of 996 * the next commit operation. 997 * 998 * @param[in] ctl 999 * Pipeline control handle. 1000 * @param[in] selector_name 1001 * Selector table name. 1002 * @param[in] group_id 1003 * The group ID. Must be valid. 1004 * @param[in] member_id 1005 * The member to be added to the group. Must be valid. 1006 * @return 1007 * 0 on success or the following error codes otherwise: 1008 * -EINVAL: Invalid argument. 1009 */ 1010 __rte_experimental 1011 int 1012 rte_swx_ctl_pipeline_selector_group_member_delete(struct rte_swx_ctl_pipeline *ctl, 1013 const char *selector_name, 1014 uint32_t group_id, 1015 uint32_t member_id); 1016 1017 /** 1018 * Pipeline learner table default entry add 1019 * 1020 * Schedule learner table default entry update as part of the next commit operation. 1021 * 1022 * @param[in] ctl 1023 * Pipeline control handle. 1024 * @param[in] learner_name 1025 * Learner table name. 1026 * @param[in] entry 1027 * The new table default entry. The *key* and *key_mask* entry fields are ignored. 1028 * @return 1029 * 0 on success or the following error codes otherwise: 1030 * -EINVAL: Invalid argument. 1031 */ 1032 __rte_experimental 1033 int 1034 rte_swx_ctl_pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *ctl, 1035 const char *learner_name, 1036 struct rte_swx_table_entry *entry); 1037 1038 /** 1039 * Pipeline commit 1040 * 1041 * Perform all the scheduled table work. 1042 * 1043 * @param[in] ctl 1044 * Pipeline control handle. 1045 * @param[in] abort_on_fail 1046 * When non-zero (false), all the scheduled work is discarded after a failed 1047 * commit. Otherwise, the scheduled work is still kept pending for the next 1048 * commit. 1049 * @return 1050 * 0 on success or the following error codes otherwise: 1051 * -EINVAL: Invalid argument. 1052 */ 1053 __rte_experimental 1054 int 1055 rte_swx_ctl_pipeline_commit(struct rte_swx_ctl_pipeline *ctl, 1056 int abort_on_fail); 1057 1058 /** 1059 * Pipeline abort 1060 * 1061 * Discard all the scheduled table work. 1062 * 1063 * @param[in] ctl 1064 * Pipeline control handle. 1065 */ 1066 __rte_experimental 1067 void 1068 rte_swx_ctl_pipeline_abort(struct rte_swx_ctl_pipeline *ctl); 1069 1070 /** 1071 * Pipeline table entry read 1072 * 1073 * Read table entry from string. 1074 * 1075 * @param[in] ctl 1076 * Pipeline control handle. 1077 * @param[in] table_name 1078 * Table name. 1079 * @param[in] string 1080 * String containing the table entry. 1081 * @param[out] is_blank_or_comment 1082 * On error, this argument provides an indication of whether *string* contains 1083 * an invalid table entry (set to zero) or a blank or comment line that should 1084 * typically be ignored (set to a non-zero value). 1085 * @return 1086 * 0 on success or the following error codes otherwise: 1087 * -EINVAL: Invalid argument. 1088 */ 1089 __rte_experimental 1090 struct rte_swx_table_entry * 1091 rte_swx_ctl_pipeline_table_entry_read(struct rte_swx_ctl_pipeline *ctl, 1092 const char *table_name, 1093 const char *string, 1094 int *is_blank_or_comment); 1095 1096 /** 1097 * Pipeline learner table default entry read 1098 * 1099 * Read learner table default entry from string. 1100 * 1101 * @param[in] ctl 1102 * Pipeline control handle. 1103 * @param[in] learner_name 1104 * Learner table name. 1105 * @param[in] string 1106 * String containing the learner table default entry. 1107 * @param[out] is_blank_or_comment 1108 * On error, this argument provides an indication of whether *string* contains 1109 * an invalid table entry (set to zero) or a blank or comment line that should 1110 * typically be ignored (set to a non-zero value). 1111 * @return 1112 * 0 on success or the following error codes otherwise: 1113 * -EINVAL: Invalid argument. 1114 */ 1115 __rte_experimental 1116 struct rte_swx_table_entry * 1117 rte_swx_ctl_pipeline_learner_default_entry_read(struct rte_swx_ctl_pipeline *ctl, 1118 const char *learner_name, 1119 const char *string, 1120 int *is_blank_or_comment); 1121 1122 /** 1123 * Pipeline table print to file 1124 * 1125 * Print all the table entries to file. 1126 * 1127 * @param[in] f 1128 * Output file. 1129 * @param[in] ctl 1130 * Pipeline control handle. 1131 * @param[in] table_name 1132 * Table name. 1133 * @return 1134 * 0 on success or the following error codes otherwise: 1135 * -EINVAL: Invalid argument. 1136 */ 1137 __rte_experimental 1138 int 1139 rte_swx_ctl_pipeline_table_fprintf(FILE *f, 1140 struct rte_swx_ctl_pipeline *ctl, 1141 const char *table_name); 1142 1143 /** 1144 * Pipeline selector print to file 1145 * 1146 * Print all the selector entries to file. 1147 * 1148 * @param[in] f 1149 * Output file. 1150 * @param[in] ctl 1151 * Pipeline control handle. 1152 * @param[in] selector_name 1153 * Selector table name. 1154 * @return 1155 * 0 on success or the following error codes otherwise: 1156 * -EINVAL: Invalid argument. 1157 */ 1158 __rte_experimental 1159 int 1160 rte_swx_ctl_pipeline_selector_fprintf(FILE *f, 1161 struct rte_swx_ctl_pipeline *ctl, 1162 const char *selector_name); 1163 1164 /* 1165 * Register Array Query API. 1166 */ 1167 1168 /** Register array info. */ 1169 struct rte_swx_ctl_regarray_info { 1170 /** Register array name. */ 1171 char name[RTE_SWX_CTL_NAME_SIZE]; 1172 1173 /** Register array size. */ 1174 uint32_t size; 1175 }; 1176 1177 /** 1178 * Register array info get 1179 * 1180 * @param[in] p 1181 * Pipeline handle. 1182 * @param[in] regarray_id 1183 * Register array ID (0 .. *n_regarrays* - 1). 1184 * @param[out] regarray 1185 * Register array info. 1186 * @return 1187 * 0 on success or the following error codes otherwise: 1188 * -EINVAL: Invalid argument. 1189 */ 1190 __rte_experimental 1191 int 1192 rte_swx_ctl_regarray_info_get(struct rte_swx_pipeline *p, 1193 uint32_t regarray_id, 1194 struct rte_swx_ctl_regarray_info *regarray); 1195 1196 /** 1197 * Register read 1198 * 1199 * @param[in] p 1200 * Pipeline handle. 1201 * @param[in] regarray_name 1202 * Register array name. 1203 * @param[in] regarray_index 1204 * Register index within the array (0 .. *size* - 1). 1205 * @param[out] value 1206 * Current register value. 1207 * @return 1208 * 0 on success or the following error codes otherwise: 1209 * -EINVAL: Invalid argument. 1210 */ 1211 __rte_experimental 1212 int 1213 rte_swx_ctl_pipeline_regarray_read(struct rte_swx_pipeline *p, 1214 const char *regarray_name, 1215 uint32_t regarray_index, 1216 uint64_t *value); 1217 1218 /** 1219 * Register write 1220 * 1221 * @param[in] p 1222 * Pipeline handle. 1223 * @param[in] regarray_name 1224 * Register array name. 1225 * @param[in] regarray_index 1226 * Register index within the array (0 .. *size* - 1). 1227 * @param[in] value 1228 * Value to be written to the register. 1229 * @return 1230 * 0 on success or the following error codes otherwise: 1231 * -EINVAL: Invalid argument. 1232 */ 1233 __rte_experimental 1234 int 1235 rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p, 1236 const char *regarray_name, 1237 uint32_t regarray_index, 1238 uint64_t value); 1239 1240 /** 1241 * Register read with table key lookup 1242 * 1243 * @param[in] p 1244 * Pipeline handle. 1245 * @param[in] regarray_name 1246 * Register array name. 1247 * @param[in] table_name 1248 * Regular or learner table name. 1249 * @param[in] table_key 1250 * Table key. 1251 * @param[out] value 1252 * Current register value. 1253 * @return 1254 * 0 on success or the following error codes otherwise: 1255 * -EINVAL: Invalid argument; 1256 * -ENOMEM: Not enough memory. 1257 */ 1258 __rte_experimental 1259 int 1260 rte_swx_ctl_pipeline_regarray_read_with_key(struct rte_swx_pipeline *p, 1261 const char *regarray_name, 1262 const char *table_name, 1263 uint8_t *table_key, 1264 uint64_t *value); 1265 1266 /** 1267 * Register write with table key lookup 1268 * 1269 * @param[in] p 1270 * Pipeline handle. 1271 * @param[in] regarray_name 1272 * Register array name. 1273 * @param[in] table_name 1274 * Regular or learner table name. 1275 * @param[in] table_key 1276 * Table key. 1277 * @param[in] value 1278 * Value to be written to the register. 1279 * @return 1280 * 0 on success or the following error codes otherwise: 1281 * -EINVAL: Invalid argument; 1282 * -ENOMEM: Not enough memory. 1283 */ 1284 __rte_experimental 1285 int 1286 rte_swx_ctl_pipeline_regarray_write_with_key(struct rte_swx_pipeline *p, 1287 const char *regarray_name, 1288 const char *table_name, 1289 uint8_t *table_key, 1290 uint64_t value); 1291 1292 /* 1293 * Meter Array Query and Configuration API. 1294 */ 1295 1296 /** Meter array info. */ 1297 struct rte_swx_ctl_metarray_info { 1298 /** Meter array name. */ 1299 char name[RTE_SWX_CTL_NAME_SIZE]; 1300 1301 /** Meter array size. */ 1302 uint32_t size; 1303 }; 1304 1305 /** 1306 * Meter array info get 1307 * 1308 * @param[in] p 1309 * Pipeline handle. 1310 * @param[in] metarray_id 1311 * Meter array ID (0 .. *n_metarrays* - 1). 1312 * @param[out] metarray 1313 * Meter array info. 1314 * @return 1315 * 0 on success or the following error codes otherwise: 1316 * -EINVAL: Invalid argument. 1317 */ 1318 __rte_experimental 1319 int 1320 rte_swx_ctl_metarray_info_get(struct rte_swx_pipeline *p, 1321 uint32_t metarray_id, 1322 struct rte_swx_ctl_metarray_info *metarray); 1323 1324 /** 1325 * Meter profile add 1326 * 1327 * @param[in] p 1328 * Pipeline handle. 1329 * @param[in] name 1330 * Meter profile name. 1331 * @param[in] params 1332 * Meter profile parameters. 1333 * @return 1334 * 0 on success or the following error codes otherwise: 1335 * -EINVAL: Invalid argument; 1336 * -ENOMEM: Not enough space/cannot allocate memory; 1337 * -EEXIST: Meter profile with this name already exists. 1338 */ 1339 __rte_experimental 1340 int 1341 rte_swx_ctl_meter_profile_add(struct rte_swx_pipeline *p, 1342 const char *name, 1343 struct rte_meter_trtcm_params *params); 1344 1345 /** 1346 * Meter profile delete 1347 * 1348 * @param[in] p 1349 * Pipeline handle. 1350 * @param[in] name 1351 * Meter profile name. 1352 * @return 1353 * 0 on success or the following error codes otherwise: 1354 * -EINVAL: Invalid argument; 1355 * -EBUSY: Meter profile is currently in use. 1356 */ 1357 __rte_experimental 1358 int 1359 rte_swx_ctl_meter_profile_delete(struct rte_swx_pipeline *p, 1360 const char *name); 1361 1362 /** 1363 * Meter reset 1364 * 1365 * Reset a meter within a given meter array to use the default profile that 1366 * causes all the input packets to be colored as green. It is the responsibility 1367 * of the control plane to make sure this meter is not used by the data plane 1368 * pipeline before calling this function. 1369 * 1370 * @param[in] p 1371 * Pipeline handle. 1372 * @param[in] metarray_name 1373 * Meter array name. 1374 * @param[in] metarray_index 1375 * Meter index within the meter array. 1376 * @return 1377 * 0 on success or the following error codes otherwise: 1378 * -EINVAL: Invalid argument. 1379 */ 1380 __rte_experimental 1381 int 1382 rte_swx_ctl_meter_reset(struct rte_swx_pipeline *p, 1383 const char *metarray_name, 1384 uint32_t metarray_index); 1385 1386 /** 1387 * Meter set 1388 * 1389 * Set a meter within a given meter array to use a specific profile. It is the 1390 * responsibility of the control plane to make sure this meter is not used by 1391 * the data plane pipeline before calling this function. 1392 * 1393 * @param[in] p 1394 * Pipeline handle. 1395 * @param[in] metarray_name 1396 * Meter array name. 1397 * @param[in] metarray_index 1398 * Meter index within the meter array. 1399 * @param[in] profile_name 1400 * Existing meter profile name. 1401 * @return 1402 * 0 on success or the following error codes otherwise: 1403 * -EINVAL: Invalid argument. 1404 */ 1405 __rte_experimental 1406 int 1407 rte_swx_ctl_meter_set(struct rte_swx_pipeline *p, 1408 const char *metarray_name, 1409 uint32_t metarray_index, 1410 const char *profile_name); 1411 1412 /** Meter statistics counters. */ 1413 struct rte_swx_ctl_meter_stats { 1414 /** Number of packets tagged by the meter for each color. */ 1415 uint64_t n_pkts[RTE_COLORS]; 1416 1417 /** Number of bytes tagged by the meter for each color. */ 1418 uint64_t n_bytes[RTE_COLORS]; 1419 }; 1420 1421 /** 1422 * Meter statistics counters read 1423 * 1424 * @param[in] p 1425 * Pipeline handle. 1426 * @param[in] metarray_name 1427 * Meter array name. 1428 * @param[in] metarray_index 1429 * Meter index within the meter array. 1430 * @param[out] stats 1431 * Meter statistics counters. 1432 * @return 1433 * 0 on success or the following error codes otherwise: 1434 * -EINVAL: Invalid argument. 1435 */ 1436 __rte_experimental 1437 int 1438 rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p, 1439 const char *metarray_name, 1440 uint32_t metarray_index, 1441 struct rte_swx_ctl_meter_stats *stats); 1442 1443 /** 1444 * Meter reset with table key lookup 1445 * 1446 * Reset a meter within a given meter array to use the default profile that 1447 * causes all the input packets to be colored as green. It is the responsibility 1448 * of the control plane to make sure this meter is not used by the data plane 1449 * pipeline before calling this function. 1450 * 1451 * @param[in] p 1452 * Pipeline handle. 1453 * @param[in] metarray_name 1454 * Meter array name. 1455 * @param[in] table_name 1456 * Regular or learner table name. 1457 * @param[in] table_key 1458 * Table key. 1459 * @return 1460 * 0 on success or the following error codes otherwise: 1461 * -EINVAL: Invalid argument. 1462 */ 1463 __rte_experimental 1464 int 1465 rte_swx_ctl_meter_reset_with_key(struct rte_swx_pipeline *p, 1466 const char *metarray_name, 1467 const char *table_name, 1468 uint8_t *table_key); 1469 1470 /** 1471 * Meter set with table key lookup 1472 * 1473 * Set a meter within a given meter array to use a specific profile. It is the 1474 * responsibility of the control plane to make sure this meter is not used by 1475 * the data plane pipeline before calling this function. 1476 * 1477 * @param[in] p 1478 * Pipeline handle. 1479 * @param[in] metarray_name 1480 * Meter array name. 1481 * @param[in] table_name 1482 * Regular or learner table name. 1483 * @param[in] table_key 1484 * Table key. 1485 * @param[in] profile_name 1486 * Existing meter profile name. 1487 * @return 1488 * 0 on success or the following error codes otherwise: 1489 * -EINVAL: Invalid argument. 1490 */ 1491 __rte_experimental 1492 int 1493 rte_swx_ctl_meter_set_with_key(struct rte_swx_pipeline *p, 1494 const char *metarray_name, 1495 const char *table_name, 1496 uint8_t *table_key, 1497 const char *profile_name); 1498 1499 /** 1500 * Meter statistics counters read with table key lookup 1501 * 1502 * @param[in] p 1503 * Pipeline handle. 1504 * @param[in] metarray_name 1505 * Meter array name. 1506 * @param[in] table_name 1507 * Regular or learner table name. 1508 * @param[in] table_key 1509 * Table key. 1510 * @param[out] stats 1511 * Meter statistics counters. 1512 * @return 1513 * 0 on success or the following error codes otherwise: 1514 * -EINVAL: Invalid argument. 1515 */ 1516 __rte_experimental 1517 int 1518 rte_swx_ctl_meter_stats_read_with_key(struct rte_swx_pipeline *p, 1519 const char *metarray_name, 1520 const char *table_name, 1521 uint8_t *table_key, 1522 struct rte_swx_ctl_meter_stats *stats); 1523 1524 /** 1525 * Pipeline control free 1526 * 1527 * @param[in] ctl 1528 * Pipeline control handle. 1529 * If ctl is NULL, no operation is performed. 1530 */ 1531 __rte_experimental 1532 void 1533 rte_swx_ctl_pipeline_free(struct rte_swx_ctl_pipeline *ctl); 1534 1535 #ifdef __cplusplus 1536 } 1537 #endif 1538 1539 #endif 1540