1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2020 Intel Corporation 3 */ 4 #ifndef __INCLUDE_RTE_SWX_PIPELINE_H__ 5 #define __INCLUDE_RTE_SWX_PIPELINE_H__ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 /** 12 * @file 13 * RTE SWX Pipeline 14 */ 15 16 #include <stddef.h> 17 #include <stdint.h> 18 #include <stdio.h> 19 20 #include <rte_compat.h> 21 22 #include "rte_swx_port.h" 23 #include "rte_swx_table.h" 24 #include "rte_swx_extern.h" 25 26 /** Name size. */ 27 #ifndef RTE_SWX_NAME_SIZE 28 #define RTE_SWX_NAME_SIZE 64 29 #endif 30 31 /** Instruction size. */ 32 #ifndef RTE_SWX_INSTRUCTION_SIZE 33 #define RTE_SWX_INSTRUCTION_SIZE 256 34 #endif 35 36 /** Instruction tokens. */ 37 #ifndef RTE_SWX_INSTRUCTION_TOKENS_MAX 38 #define RTE_SWX_INSTRUCTION_TOKENS_MAX 16 39 #endif 40 41 /* 42 * Pipeline setup and operation 43 */ 44 45 /** Pipeline opaque data structure. */ 46 struct rte_swx_pipeline; 47 48 /** 49 * Pipeline configure 50 * 51 * @param[out] p 52 * Pipeline handle. Must point to valid memory. Contains valid pipeline handle 53 * when the function returns successfully. 54 * @param[in] numa_node 55 * Non-Uniform Memory Access (NUMA) node. 56 * @return 57 * 0 on success or the following error codes otherwise: 58 * -EINVAL: Invalid argument; 59 * -ENOMEM: Not enough space/cannot allocate memory. 60 */ 61 __rte_experimental 62 int 63 rte_swx_pipeline_config(struct rte_swx_pipeline **p, 64 int numa_node); 65 66 /* 67 * Pipeline input ports 68 */ 69 70 /** 71 * Pipeline input port type register 72 * 73 * @param[in] p 74 * Pipeline handle. 75 * @param[in] name 76 * Input port type name. 77 * @param[in] ops 78 * Input port type operations. 79 * @return 80 * 0 on success or the following error codes otherwise: 81 * -EINVAL: Invalid argument; 82 * -ENOMEM: Not enough space/cannot allocate memory; 83 * -EEXIST: Input port type with this name already exists. 84 */ 85 __rte_experimental 86 int 87 rte_swx_pipeline_port_in_type_register(struct rte_swx_pipeline *p, 88 const char *name, 89 struct rte_swx_port_in_ops *ops); 90 91 /** 92 * Pipeline input port configure 93 * 94 * @param[in] p 95 * Pipeline handle. 96 * @param[in] port_id 97 * Input port ID. 98 * @param[in] port_type_name 99 * Existing input port type name. 100 * @param[in] args 101 * Input port creation arguments. 102 * @return 103 * 0 on success or the following error codes otherwise: 104 * -EINVAL: Invalid argument; 105 * -ENOMEM: Not enough space/cannot allocate memory; 106 * -ENODEV: Input port object creation error. 107 */ 108 __rte_experimental 109 int 110 rte_swx_pipeline_port_in_config(struct rte_swx_pipeline *p, 111 uint32_t port_id, 112 const char *port_type_name, 113 void *args); 114 115 /* 116 * Pipeline output ports 117 */ 118 119 /** 120 * Pipeline output port type register 121 * 122 * @param[in] p 123 * Pipeline handle. 124 * @param[in] name 125 * Output port type name. 126 * @param[in] ops 127 * Output port type operations. 128 * @return 129 * 0 on success or the following error codes otherwise: 130 * -EINVAL: Invalid argument; 131 * -ENOMEM: Not enough space/cannot allocate memory; 132 * -EEXIST: Output port type with this name already exists. 133 */ 134 __rte_experimental 135 int 136 rte_swx_pipeline_port_out_type_register(struct rte_swx_pipeline *p, 137 const char *name, 138 struct rte_swx_port_out_ops *ops); 139 140 /** 141 * Pipeline output port configure 142 * 143 * @param[in] p 144 * Pipeline handle. 145 * @param[in] port_id 146 * Output port ID. 147 * @param[in] port_type_name 148 * Existing output port type name. 149 * @param[in] args 150 * Output port creation arguments. 151 * @return 152 * 0 on success or the following error codes otherwise: 153 * -EINVAL: Invalid argument; 154 * -ENOMEM: Not enough space/cannot allocate memory; 155 * -ENODEV: Output port object creation error. 156 */ 157 __rte_experimental 158 int 159 rte_swx_pipeline_port_out_config(struct rte_swx_pipeline *p, 160 uint32_t port_id, 161 const char *port_type_name, 162 void *args); 163 164 /* 165 * Extern objects and functions 166 */ 167 168 /** 169 * Pipeline extern type register 170 * 171 * @param[in] p 172 * Pipeline handle. 173 * @param[in] name 174 * Extern type name. 175 * @param[in] mailbox_struct_type_name 176 * Name of existing struct type used to define the mailbox size and layout for 177 * the extern objects that are instances of this type. Each extern object gets 178 * its own mailbox, which is used to pass the input arguments to the member 179 * functions and retrieve the output results. 180 * @param[in] constructor 181 * Function used to create the extern objects that are instances of this type. 182 * @param[in] destructor 183 * Function used to free the extern objects that are instances of this type. 184 * @return 185 * 0 on success or the following error codes otherwise: 186 * -EINVAL: Invalid argument; 187 * -ENOMEM: Not enough space/cannot allocate memory; 188 * -EEXIST: Extern type with this name already exists. 189 */ 190 __rte_experimental 191 int 192 rte_swx_pipeline_extern_type_register(struct rte_swx_pipeline *p, 193 const char *name, 194 const char *mailbox_struct_type_name, 195 rte_swx_extern_type_constructor_t constructor, 196 rte_swx_extern_type_destructor_t destructor); 197 198 /** 199 * Pipeline extern type member function register 200 * 201 * @param[in] p 202 * Pipeline handle. 203 * @param[in] extern_type_name 204 * Existing extern type name. 205 * @param[in] name 206 * Name for the new member function to be added to the extern type. 207 * @param[in] member_func 208 * The new member function. 209 * @return 210 * 0 on success or the following error codes otherwise: 211 * -EINVAL: Invalid argument; 212 * -ENOMEM: Not enough space/cannot allocate memory; 213 * -EEXIST: Member function with this name already exists for this type; 214 * -ENOSPC: Maximum number of member functions reached for this type. 215 */ 216 __rte_experimental 217 int 218 rte_swx_pipeline_extern_type_member_func_register(struct rte_swx_pipeline *p, 219 const char *extern_type_name, 220 const char *name, 221 rte_swx_extern_type_member_func_t member_func); 222 223 /** 224 * Pipeline extern object configure 225 * 226 * Instantiate a given extern type to create new extern object. 227 * 228 * @param[in] p 229 * Pipeline handle. 230 * @param[in] extern_type_name 231 * Existing extern type name. 232 * @param[in] name 233 * Name for the new object instantiating the extern type. 234 * @param[in] args 235 * Extern object constructor arguments. 236 * @return 237 * 0 on success or the following error codes otherwise: 238 * -EINVAL: Invalid argument; 239 * -ENOMEM: Not enough space/cannot allocate memory; 240 * -EEXIST: Extern object with this name already exists; 241 * -ENODEV: Extern object constructor error. 242 */ 243 __rte_experimental 244 int 245 rte_swx_pipeline_extern_object_config(struct rte_swx_pipeline *p, 246 const char *extern_type_name, 247 const char *name, 248 const char *args); 249 250 /** 251 * Pipeline extern function register 252 * 253 * @param[in] p 254 * Pipeline handle. 255 * @param[in] name 256 * Extern function name. 257 * @param[in] mailbox_struct_type_name 258 * Name of existing struct type used to define the mailbox size and layout for 259 * this extern function. The mailbox is used to pass the input arguments to 260 * the extern function and retrieve the output results. 261 * @param[in] func 262 * The extern function. 263 * @return 264 * 0 on success or the following error codes otherwise: 265 * -EINVAL: Invalid argument; 266 * -ENOMEM: Not enough space/cannot allocate memory; 267 * -EEXIST: Extern function with this name already exists. 268 */ 269 __rte_experimental 270 int 271 rte_swx_pipeline_extern_func_register(struct rte_swx_pipeline *p, 272 const char *name, 273 const char *mailbox_struct_type_name, 274 rte_swx_extern_func_t func); 275 276 /* 277 * Packet headers and meta-data 278 */ 279 280 /** Structure (struct) field. */ 281 struct rte_swx_field_params { 282 /** Struct field name. */ 283 const char *name; 284 285 /** Struct field size (in bits). 286 * Restriction: All struct fields must be a multiple of 8 bits. 287 * Restriction: All struct fields must be no greater than 64 bits. 288 */ 289 uint32_t n_bits; 290 }; 291 292 /** 293 * Pipeline struct type register 294 * 295 * Structs are used extensively in many part of the pipeline to define the size 296 * and layout of a specific memory piece such as: headers, meta-data, action 297 * data stored in a table entry, mailboxes for extern objects and functions. 298 * Similar to C language structs, they are a well defined sequence of fields, 299 * with each field having a unique name and a constant size. 300 * 301 * In order to use structs to express variable size packet headers such as IPv4 302 * with options, it is allowed for the last field of the struct type to have a 303 * variable size between 0 and *n_bits* bits, with the actual size of this field 304 * determined at run-time for each packet. This struct feature is restricted to 305 * just a few selected instructions that deal with packet headers, so a typical 306 * struct generally has a constant size that is fully known when its struct type 307 * is registered. 308 * 309 * @param[in] p 310 * Pipeline handle. 311 * @param[in] name 312 * Struct type name. 313 * @param[in] fields 314 * The sequence of struct fields. 315 * @param[in] n_fields 316 * The number of struct fields. 317 * @param[in] last_field_has_variable_size 318 * If non-zero (true), then the last field has a variable size between 0 and 319 * *n_bits* bits, with its actual size determined at run-time for each packet. 320 * If zero (false), then the last field has a constant size of *n_bits* bits. 321 * @return 322 * 0 on success or the following error codes otherwise: 323 * -EINVAL: Invalid argument; 324 * -ENOMEM: Not enough space/cannot allocate memory; 325 * -EEXIST: Struct type with this name already exists. 326 */ 327 __rte_experimental 328 int 329 rte_swx_pipeline_struct_type_register(struct rte_swx_pipeline *p, 330 const char *name, 331 struct rte_swx_field_params *fields, 332 uint32_t n_fields, 333 int last_field_has_variable_size); 334 335 /** 336 * Pipeline packet header register 337 * 338 * @param[in] p 339 * Pipeline handle. 340 * @param[in] name 341 * Header name. 342 * @param[in] struct_type_name 343 * The struct type instantiated by this packet header. 344 * @return 345 * 0 on success or the following error codes otherwise: 346 * -EINVAL: Invalid argument; 347 * -ENOMEM: Not enough space/cannot allocate memory; 348 * -EEXIST: Header with this name already exists; 349 * -ENOSPC: Maximum number of headers reached for the pipeline. 350 */ 351 __rte_experimental 352 int 353 rte_swx_pipeline_packet_header_register(struct rte_swx_pipeline *p, 354 const char *name, 355 const char *struct_type_name); 356 357 /** 358 * Pipeline packet meta-data register 359 * 360 * @param[in] p 361 * Pipeline handle. 362 * @param[in] struct_type_name 363 * The struct type instantiated by the packet meta-data. 364 * @return 365 * 0 on success or the following error codes otherwise: 366 * -EINVAL: Invalid argument. 367 */ 368 __rte_experimental 369 int 370 rte_swx_pipeline_packet_metadata_register(struct rte_swx_pipeline *p, 371 const char *struct_type_name); 372 373 /* 374 * Instructions 375 */ 376 377 /** 378 * Instruction operands: 379 * 380 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 381 *<pre>| | Description | Format | DST | SRC |</pre> 382 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 383 *<pre>| hdr | Header | h.header | | |</pre> 384 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 385 *<pre>| act | Action | ACTION | | |</pre> 386 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 387 *<pre>| tbl | Table | TABLE | | |</pre> 388 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 389 *<pre>| H | Header field | h.header.field | YES | YES |</pre> 390 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 391 *<pre>| M | Meta-data field | m.field | YES | YES |</pre> 392 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 393 *<pre>| E | Extern obj mailbox field | e.ext_obj.field | YES | YES |</pre> 394 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 395 *<pre>| F | Extern func mailbox field | f.ext_func.field | YES | YES |</pre> 396 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 397 *<pre>| T | Table action data field | t.header.field | NO | YES |</pre> 398 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 399 *<pre>| I | Immediate value (64-bit) | h.header.field | NO | YES |</pre> 400 *<pre>+-----+---------------------------+------------------+-----+-----+</pre> 401 * 402 * Instruction set: 403 * 404 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 405 *<pre>| Instr. | Instruction | Instruction | 1st | 2nd |</pre> 406 *<pre>| Name | Description | Format | opnd.| opnd. |</pre> 407 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 408 *<pre>| rx | Receive one pkt | rx m.port_in | M | |</pre> 409 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 410 *<pre>| tx | Transmit one pkt | tx m.port_out | M | |</pre> 411 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 412 *<pre>| extract | Extract one hdr | extract h.hdr | hdr | |</pre> 413 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 414 *<pre>| emit | Emit one hdr | emit h.hdr | hdr | |</pre> 415 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 416 *<pre>| validate | Validate one hdr | validate h.hdr | hdr | |</pre> 417 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 418 *<pre>| invalidate | Invalidate one hdr | invalidate h.hdr | hdr | |</pre> 419 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 420 *<pre>| mov | dst = src | mov dst src | HMEF | HMEFTI |</pre> 421 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 422 *<pre>| add | dst += src | add dst src | HMEF | HMEFTI |</pre> 423 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 424 *<pre>| sub | dst -= src | add dst src | HMEF | HMEFTI |</pre> 425 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 426 *<pre>| ckadd | Checksum add: dst = | add dst src | HMEF | HMEFTI |</pre> 427 *<pre>| | dst '+ src[0:1] '+ | | | or hdr |</pre> 428 *<pre>| | src[2:3] '+ ... | | | |</pre> 429 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 430 *<pre>| cksub | Checksum subtract: | add dst src | HMEF | HMEFTI |</pre> 431 *<pre>| | dst = dst '- src | | | |</pre> 432 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 433 *<pre>| and | dst &= src | and dst src | HMEF | HMEFTI |</pre> 434 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 435 *<pre>| or | dst |= src | or dst src | HMEF | HMEFTI |</pre> 436 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 437 *<pre>| xor | dst ^= src | xor dst src | HMEF | HMEFTI |</pre> 438 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 439 *<pre>| shl | dst <<= src | shl dst src | HMEF | HMEFTI |</pre> 440 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 441 *<pre>| shr | dst >>= src | shr dst src | HMEF | HMEFTI |</pre> 442 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 443 *<pre>| table | Table lookup | table TABLE | tbl | |</pre> 444 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 445 *<pre>| extern | Ext obj member func | extern e.obj.mfunc| ext | |</pre> 446 *<pre>| | call or ext func call| extern f.func | | |</pre> 447 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 448 *<pre>| jmp | Unconditional jump | jmp LABEL | | |</pre> 449 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 450 *<pre>| jmpv | Jump if hdr is valid | jmpv LABEL h.hdr | hdr | |</pre> 451 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 452 *<pre>| jmpnv | Jump if hdr is inval | jmpnv LABEL h.hdr | hdr | |</pre> 453 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 454 *<pre>| jmph | Jump if tbl lkp hit | jmph LABEL | | |</pre> 455 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 456 *<pre>| jmpnh | Jump if tbl lkp miss | jmpnh LABEL | | |</pre> 457 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 458 *<pre>| jmpa | Jump if action run | jmpa LABEL ACTION | act | |</pre> 459 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 460 *<pre>| jmpna | Jump if act not run | jmpna LABEL ACTION| act | |</pre> 461 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 462 *<pre>| jmpeq | Jump if (a == b) | jmpeq LABEL a b | HMEFT| HMEFTI |</pre> 463 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 464 *<pre>| jmpneq | Jump if (a != b) | jmpneq LABEL a b | HMEFT| HMEFTI |</pre> 465 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 466 *<pre>| jmplt | Jump if (a < b) | jmplt LABEL a b | HMEFT| HMEFTI |</pre> 467 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 468 *<pre>| jmpgt | Jump if (a > b) | jmpgt LABEL a b | HMEFT| HMEFTI |</pre> 469 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 470 *<pre>| return | Return from action | return | | |</pre> 471 *<pre>+------------+----------------------+-------------------+------+--------+</pre> 472 * 473 * At initialization time, the pipeline and action instructions (including the 474 * symbolic name operands) are translated to internal data structures that are 475 * used at run-time. 476 */ 477 478 /* 479 * Pipeline action 480 */ 481 482 /** 483 * Pipeline action configure 484 * 485 * @param[in] p 486 * Pipeline handle. 487 * @param[in] name 488 * Action name. 489 * @param[in] args_struct_type_name 490 * The struct type instantiated by the action data. The action data represent 491 * the action arguments that are stored in the table entry together with the 492 * action ID. Set to NULL when the action does not have any arguments. 493 * @param[in] instructions 494 * Action instructions. 495 * @param[in] n_instructions 496 * Number of action instructions. 497 * @return 498 * 0 on success or the following error codes otherwise: 499 * -EINVAL: Invalid argument; 500 * -ENOMEM: Not enough space/cannot allocate memory; 501 * -EEXIST: Action with this name already exists. 502 */ 503 __rte_experimental 504 int 505 rte_swx_pipeline_action_config(struct rte_swx_pipeline *p, 506 const char *name, 507 const char *args_struct_type_name, 508 const char **instructions, 509 uint32_t n_instructions); 510 511 /* 512 * Pipeline table 513 */ 514 515 /** 516 * Pipeline table type register 517 * 518 * @param[in] p 519 * Pipeline handle. 520 * @param[in] name 521 * Table type name. 522 * @param[in] match_type 523 * Match type implemented by the new table type. 524 * @param[in] ops 525 * Table type operations. 526 * @return 527 * 0 on success or the following error codes otherwise: 528 * -EINVAL: Invalid argument; 529 * -ENOMEM: Not enough space/cannot allocate memory; 530 * -EEXIST: Table type with this name already exists. 531 */ 532 __rte_experimental 533 int 534 rte_swx_pipeline_table_type_register(struct rte_swx_pipeline *p, 535 const char *name, 536 enum rte_swx_table_match_type match_type, 537 struct rte_swx_table_ops *ops); 538 539 /** Match field parameters. */ 540 struct rte_swx_match_field_params { 541 /** Match field name. Must be either a field of one of the registered 542 * packet headers ("h.header.field") or a field of the registered 543 * meta-data ("m.field"). 544 */ 545 const char *name; 546 547 /** Match type of the field. */ 548 enum rte_swx_table_match_type match_type; 549 }; 550 551 /** Pipeline table parameters. */ 552 struct rte_swx_pipeline_table_params { 553 /** The set of match fields for the current table. 554 * Restriction: All the match fields of the current table need to be 555 * part of the same struct, i.e. either all the match fields are part of 556 * the same header or all the match fields are part of the meta-data. 557 */ 558 struct rte_swx_match_field_params *fields; 559 560 /** The number of match fields for the current table. If set to zero, no 561 * "regular" entries (i.e. entries other than the default entry) can be 562 * added to the current table and the match process always results in 563 * lookup miss. 564 */ 565 uint32_t n_fields; 566 567 /** The set of actions for the current table. */ 568 const char **action_names; 569 570 /** Array of *n_actions* flags. For each action, the associated flag 571 * indicates whether the action can be assigned to regular table entries 572 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set 573 * to NULL, it defaults to true for all actions. 574 */ 575 int *action_is_for_table_entries; 576 577 /** Array of *n_actions* flags. For each action, the associated flag 578 * indicates whether the action can be assigned to the default table 579 * entry (when non-zero, i.e. true) or not (when zero, i.e. false). 580 * When set to NULL, it defaults to true for all actions. 581 */ 582 int *action_is_for_default_entry; 583 584 /** The number of actions for the current table. Must be at least one. 585 */ 586 uint32_t n_actions; 587 588 /** The default table action that gets executed on lookup miss. Must be 589 * one of the table actions included in the *action_names*. 590 */ 591 const char *default_action_name; 592 593 /** Default action data. The size of this array is the action data size 594 * of the default action. Must be NULL if the default action data size 595 * is zero. 596 */ 597 uint8_t *default_action_data; 598 599 /** If non-zero (true), then the default action of the current table 600 * cannot be changed. If zero (false), then the default action can be 601 * changed in the future with another action from the *action_names* 602 * list. 603 */ 604 int default_action_is_const; 605 }; 606 607 /** 608 * Pipeline table configure 609 * 610 * @param[out] p 611 * Pipeline handle. 612 * @param[in] name 613 * Table name. 614 * @param[in] params 615 * Table parameters. 616 * @param[in] recommended_table_type_name 617 * Recommended table type. Typically set to NULL. Useful as guidance when 618 * there are multiple table types registered for the match type of the table, 619 * as determined from the table match fields specification. Silently ignored 620 * if the recommended table type does not exist or it serves a different match 621 * type. 622 * @param[in] args 623 * Table creation arguments. 624 * @param[in] size 625 * Guideline on maximum number of table entries. 626 * @return 627 * 0 on success or the following error codes otherwise: 628 * -EINVAL: Invalid argument; 629 * -ENOMEM: Not enough space/cannot allocate memory; 630 * -EEXIST: Table with this name already exists; 631 * -ENODEV: Table creation error. 632 */ 633 __rte_experimental 634 int 635 rte_swx_pipeline_table_config(struct rte_swx_pipeline *p, 636 const char *name, 637 struct rte_swx_pipeline_table_params *params, 638 const char *recommended_table_type_name, 639 const char *args, 640 uint32_t size); 641 642 /** Pipeline selector table parameters. */ 643 struct rte_swx_pipeline_selector_params { 644 /** The group ID field. Input into the selection operation. 645 * Restriction: This field must be a meta-data field. 646 */ 647 const char *group_id_field_name; 648 649 /** The set of fields used to select (through a hashing scheme) the 650 * member within the current group. Inputs into the seletion operation. 651 * Restriction: All the selector fields must be part of the same struct, 652 * i.e. part of the same header or part of the meta-data structure. 653 */ 654 const char **selector_field_names; 655 656 /** The number of selector fields. Must be non-zero. */ 657 uint32_t n_selector_fields; 658 659 /** The member ID field. Output from the selection operation. 660 * Restriction: This field must be a meta-data field. 661 */ 662 const char *member_id_field_name; 663 664 /** Maximum number of groups. Must be non-zero. */ 665 uint32_t n_groups_max; 666 667 /** Maximum number of members per group. Must be non-zero. */ 668 uint32_t n_members_per_group_max; 669 }; 670 671 /** 672 * Pipeline selector table configure 673 * 674 * @param[out] p 675 * Pipeline handle. 676 * @param[in] name 677 * Selector table name. 678 * @param[in] params 679 * Selector table parameters. 680 * @return 681 * 0 on success or the following error codes otherwise: 682 * -EINVAL: Invalid argument; 683 * -ENOMEM: Not enough space/cannot allocate memory; 684 * -EEXIST: Selector table with this name already exists; 685 * -ENODEV: Selector table creation error. 686 */ 687 __rte_experimental 688 int 689 rte_swx_pipeline_selector_config(struct rte_swx_pipeline *p, 690 const char *name, 691 struct rte_swx_pipeline_selector_params *params); 692 693 /** Pipeline learner table parameters. */ 694 struct rte_swx_pipeline_learner_params { 695 /** The set of match fields for the current table. 696 * Restriction: All the match fields of the current table need to be 697 * part of the same struct, i.e. either all the match fields are part of 698 * the same header or all the match fields are part of the meta-data. 699 */ 700 const char **field_names; 701 702 /** The number of match fields for the current table. Must be non-zero. 703 */ 704 uint32_t n_fields; 705 706 /** The set of actions for the current table. */ 707 const char **action_names; 708 709 /** Array of *n_actions* flags. For each action, the associated flag 710 * indicates whether the action can be assigned to regular table entries 711 * (when non-zero, i.e. true) or not (when zero, i.e. false). When set 712 * to NULL, it defaults to true for all actions. 713 */ 714 int *action_is_for_table_entries; 715 716 /** Array of *n_actions* flags. For each action, the associated flag 717 * indicates whether the action can be assigned to the default table 718 * entry (when non-zero, i.e. true) or not (when zero, i.e. false). 719 * When set to NULL, it defaults to true for all actions. 720 */ 721 int *action_is_for_default_entry; 722 723 /** The number of actions for the current table. Must be at least one. 724 */ 725 uint32_t n_actions; 726 727 /** The default table action that gets executed on lookup miss. Must be 728 * one of the table actions included in the *action_names*. 729 */ 730 const char *default_action_name; 731 732 /** Default action data. The size of this array is the action data size 733 * of the default action. Must be NULL if the default action data size 734 * is zero. 735 */ 736 uint8_t *default_action_data; 737 738 /** If non-zero (true), then the default action of the current table 739 * cannot be changed. If zero (false), then the default action can be 740 * changed in the future with another action from the *action_names* 741 * list. 742 */ 743 int default_action_is_const; 744 }; 745 746 /** 747 * Pipeline learner table configure 748 * 749 * @param[out] p 750 * Pipeline handle. 751 * @param[in] name 752 * Learner table name. 753 * @param[in] params 754 * Learner table parameters. 755 * @param[in] size 756 * The maximum number of table entries. Must be non-zero. 757 * @param[in] timeout 758 * Table entry timeout in seconds. Must be non-zero. 759 * @return 760 * 0 on success or the following error codes otherwise: 761 * -EINVAL: Invalid argument; 762 * -ENOMEM: Not enough space/cannot allocate memory; 763 * -EEXIST: Learner table with this name already exists; 764 * -ENODEV: Learner table creation error. 765 */ 766 __rte_experimental 767 int 768 rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p, 769 const char *name, 770 struct rte_swx_pipeline_learner_params *params, 771 uint32_t size, 772 uint32_t timeout); 773 774 /** 775 * Pipeline register array configure 776 * 777 * @param[in] p 778 * Pipeline handle. 779 * @param[in] name 780 * Register array name. 781 * @param[in] size 782 * Number of registers in the array. Each register is 64-bit in size. 783 * @param[in] init_val 784 * Initial value for every register in the array. The recommended value is 0. 785 * @return 786 * 0 on success or the following error codes otherwise: 787 * -EINVAL: Invalid argument; 788 * -ENOMEM: Not enough space/cannot allocate memory; 789 * -EEXIST: Register array with this name already exists. 790 */ 791 __rte_experimental 792 int 793 rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p, 794 const char *name, 795 uint32_t size, 796 uint64_t init_val); 797 798 /** 799 * Pipeline meter array configure 800 * 801 * @param[in] p 802 * Pipeline handle. 803 * @param[in] name 804 * Meter array name. 805 * @param[in] size 806 * Number of meters in the array. Each meter in the array implements the Two 807 * Rate Three Color Marker (trTCM) algorithm, as specified by RFC 2698. 808 * @return 809 * 0 on success or the following error codes otherwise: 810 * -EINVAL: Invalid argument; 811 * -ENOMEM: Not enough space/cannot allocate memory; 812 * -EEXIST: Meter array with this name already exists. 813 */ 814 __rte_experimental 815 int 816 rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p, 817 const char *name, 818 uint32_t size); 819 820 /** 821 * Pipeline instructions configure 822 * 823 * @param[in] p 824 * Pipeline handle. 825 * @param[in] instructions 826 * Pipeline instructions. 827 * @param[in] n_instructions 828 * Number of pipeline instructions. 829 * @return 830 * 0 on success or the following error codes otherwise: 831 * -EINVAL: Invalid argument; 832 * -ENOMEM: Not enough space/cannot allocate memory. 833 */ 834 __rte_experimental 835 int 836 rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p, 837 const char **instructions, 838 uint32_t n_instructions); 839 840 /** 841 * Pipeline build 842 * 843 * Once called, the pipeline build operation marks the end of pipeline 844 * configuration. At this point, all the internal data structures needed to run 845 * the pipeline are built. 846 * 847 * @param[in] p 848 * Pipeline handle. 849 * @return 850 * 0 on success or the following error codes otherwise: 851 * -EINVAL: Invalid argument; 852 * -ENOMEM: Not enough space/cannot allocate memory; 853 * -EEXIST: Pipeline was already built successfully. 854 */ 855 __rte_experimental 856 int 857 rte_swx_pipeline_build(struct rte_swx_pipeline *p); 858 859 /** 860 * Pipeline build from specification file 861 * 862 * @param[in] p 863 * Pipeline handle. 864 * @param[in] spec 865 * Pipeline specification file. 866 * @param[out] err_line 867 * In case of error and non-NULL, the line number within the *spec* file where 868 * the error occurred. The first line number in the file is 1. 869 * @param[out] err_msg 870 * In case of error and non-NULL, the error message. 871 * @return 872 * 0 on success or the following error codes otherwise: 873 * -EINVAL: Invalid argument; 874 * -ENOMEM: Not enough space/cannot allocate memory; 875 * -EEXIST: Resource with the same name already exists; 876 * -ENODEV: Extern object or table creation error. 877 */ 878 __rte_experimental 879 int 880 rte_swx_pipeline_build_from_spec(struct rte_swx_pipeline *p, 881 FILE *spec, 882 uint32_t *err_line, 883 const char **err_msg); 884 885 /** 886 * Pipeline run 887 * 888 * @param[in] p 889 * Pipeline handle. 890 * @param[in] n_instructions 891 * Number of instructions to execute. 892 */ 893 __rte_experimental 894 void 895 rte_swx_pipeline_run(struct rte_swx_pipeline *p, 896 uint32_t n_instructions); 897 898 /** 899 * Pipeline flush 900 * 901 * Flush all output ports of the pipeline. 902 * 903 * @param[in] p 904 * Pipeline handle. 905 */ 906 __rte_experimental 907 void 908 rte_swx_pipeline_flush(struct rte_swx_pipeline *p); 909 910 /** 911 * Pipeline free 912 * 913 * @param[in] p 914 * Pipeline handle. 915 */ 916 __rte_experimental 917 void 918 rte_swx_pipeline_free(struct rte_swx_pipeline *p); 919 920 #ifdef __cplusplus 921 } 922 #endif 923 924 #endif 925