13421eb42SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause 23421eb42SCristian Dumitrescu * Copyright(c) 2022 Intel Corporation 33421eb42SCristian Dumitrescu */ 454cae37eSCristian Dumitrescu #ifndef __INCLUDE_RTE_SWX_PIPELINE_SPEC_H__ 554cae37eSCristian Dumitrescu #define __INCLUDE_RTE_SWX_PIPELINE_SPEC_H__ 654cae37eSCristian Dumitrescu 73421eb42SCristian Dumitrescu #include <stdint.h> 83421eb42SCristian Dumitrescu #include <stdio.h> 93421eb42SCristian Dumitrescu 103421eb42SCristian Dumitrescu #include <rte_common.h> 113421eb42SCristian Dumitrescu 123421eb42SCristian Dumitrescu #include <rte_swx_pipeline.h> 133421eb42SCristian Dumitrescu 14*719834a6SMattias Rönnblom #ifdef __cplusplus 15*719834a6SMattias Rönnblom extern "C" { 16*719834a6SMattias Rönnblom #endif 17*719834a6SMattias Rönnblom 183421eb42SCristian Dumitrescu /* 193421eb42SCristian Dumitrescu * extobj. 203421eb42SCristian Dumitrescu * 213421eb42SCristian Dumitrescu * extobj OBJ_NAME instanceof OBJ_TYPE [ pragma OBJ_CREATE_ARGS ] 223421eb42SCristian Dumitrescu */ 233421eb42SCristian Dumitrescu struct extobj_spec { 243421eb42SCristian Dumitrescu char *name; 253421eb42SCristian Dumitrescu char *extern_type_name; 263421eb42SCristian Dumitrescu char *pragma; 273421eb42SCristian Dumitrescu }; 283421eb42SCristian Dumitrescu 293421eb42SCristian Dumitrescu /* 303421eb42SCristian Dumitrescu * struct. 313421eb42SCristian Dumitrescu * 323421eb42SCristian Dumitrescu * struct STRUCT_TYPE_NAME { 333421eb42SCristian Dumitrescu * bit<SIZE> | varbit<SIZE> FIELD_NAME 343421eb42SCristian Dumitrescu * ... 353421eb42SCristian Dumitrescu * } 363421eb42SCristian Dumitrescu */ 373421eb42SCristian Dumitrescu struct struct_spec { 383421eb42SCristian Dumitrescu char *name; 393421eb42SCristian Dumitrescu struct rte_swx_field_params *fields; 403421eb42SCristian Dumitrescu uint32_t n_fields; 413421eb42SCristian Dumitrescu int varbit; 423421eb42SCristian Dumitrescu }; 433421eb42SCristian Dumitrescu 443421eb42SCristian Dumitrescu /* 453421eb42SCristian Dumitrescu * header. 463421eb42SCristian Dumitrescu * 473421eb42SCristian Dumitrescu * header HEADER_NAME instanceof STRUCT_TYPE_NAME 483421eb42SCristian Dumitrescu */ 493421eb42SCristian Dumitrescu struct header_spec { 503421eb42SCristian Dumitrescu char *name; 513421eb42SCristian Dumitrescu char *struct_type_name; 523421eb42SCristian Dumitrescu }; 533421eb42SCristian Dumitrescu 543421eb42SCristian Dumitrescu /* 553421eb42SCristian Dumitrescu * metadata. 563421eb42SCristian Dumitrescu * 573421eb42SCristian Dumitrescu * metadata instanceof STRUCT_TYPE_NAME 583421eb42SCristian Dumitrescu */ 593421eb42SCristian Dumitrescu struct metadata_spec { 603421eb42SCristian Dumitrescu char *struct_type_name; 613421eb42SCristian Dumitrescu }; 623421eb42SCristian Dumitrescu 633421eb42SCristian Dumitrescu /* 643421eb42SCristian Dumitrescu * action. 653421eb42SCristian Dumitrescu * 663421eb42SCristian Dumitrescu * action ACTION_NAME args none | instanceof STRUCT_TYPE_NAME { 673421eb42SCristian Dumitrescu * INSTRUCTION 683421eb42SCristian Dumitrescu * ... 693421eb42SCristian Dumitrescu * } 703421eb42SCristian Dumitrescu */ 713421eb42SCristian Dumitrescu struct action_spec { 723421eb42SCristian Dumitrescu char *name; 733421eb42SCristian Dumitrescu char *args_struct_type_name; 743421eb42SCristian Dumitrescu const char **instructions; 753421eb42SCristian Dumitrescu uint32_t n_instructions; 763421eb42SCristian Dumitrescu }; 773421eb42SCristian Dumitrescu 783421eb42SCristian Dumitrescu /* 793421eb42SCristian Dumitrescu * table. 803421eb42SCristian Dumitrescu * 813421eb42SCristian Dumitrescu * table TABLE_NAME { 823421eb42SCristian Dumitrescu * key { 833421eb42SCristian Dumitrescu * MATCH_FIELD_NAME exact | wildcard | lpm 843421eb42SCristian Dumitrescu * ... 853421eb42SCristian Dumitrescu * } 863421eb42SCristian Dumitrescu * actions { 873421eb42SCristian Dumitrescu * ACTION_NAME [ @tableonly | @defaultonly ] 883421eb42SCristian Dumitrescu * ... 893421eb42SCristian Dumitrescu * } 903421eb42SCristian Dumitrescu * default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ] 919560a329SCristian Dumitrescu * hash HASH_FUNCTION_NAME 923421eb42SCristian Dumitrescu * instanceof TABLE_TYPE_NAME 933421eb42SCristian Dumitrescu * pragma ARGS 943421eb42SCristian Dumitrescu * size SIZE 953421eb42SCristian Dumitrescu * } 963421eb42SCristian Dumitrescu */ 973421eb42SCristian Dumitrescu struct table_spec { 983421eb42SCristian Dumitrescu char *name; 993421eb42SCristian Dumitrescu struct rte_swx_pipeline_table_params params; 1003421eb42SCristian Dumitrescu char *recommended_table_type_name; 1013421eb42SCristian Dumitrescu char *args; 1023421eb42SCristian Dumitrescu uint32_t size; 1033421eb42SCristian Dumitrescu }; 1043421eb42SCristian Dumitrescu 1053421eb42SCristian Dumitrescu /* 1063421eb42SCristian Dumitrescu * selector. 1073421eb42SCristian Dumitrescu * 1083421eb42SCristian Dumitrescu * selector SELECTOR_NAME { 1093421eb42SCristian Dumitrescu * group_id FIELD_NAME 1103421eb42SCristian Dumitrescu * selector { 1113421eb42SCristian Dumitrescu * FIELD_NAME 1123421eb42SCristian Dumitrescu * ... 1133421eb42SCristian Dumitrescu * } 1143421eb42SCristian Dumitrescu * member_id FIELD_NAME 1153421eb42SCristian Dumitrescu * n_groups N_GROUPS 1163421eb42SCristian Dumitrescu * n_members_per_group N_MEMBERS_PER_GROUP 1173421eb42SCristian Dumitrescu * } 1183421eb42SCristian Dumitrescu */ 1193421eb42SCristian Dumitrescu struct selector_spec { 1203421eb42SCristian Dumitrescu char *name; 1213421eb42SCristian Dumitrescu struct rte_swx_pipeline_selector_params params; 1223421eb42SCristian Dumitrescu }; 1233421eb42SCristian Dumitrescu 1243421eb42SCristian Dumitrescu /* 1253421eb42SCristian Dumitrescu * learner. 1263421eb42SCristian Dumitrescu * 1273421eb42SCristian Dumitrescu * learner LEARNER_NAME { 1283421eb42SCristian Dumitrescu * key { 1293421eb42SCristian Dumitrescu * MATCH_FIELD_NAME 1303421eb42SCristian Dumitrescu * ... 1313421eb42SCristian Dumitrescu * } 1323421eb42SCristian Dumitrescu * actions { 1333421eb42SCristian Dumitrescu * ACTION_NAME [ @tableonly | @defaultonly] 1343421eb42SCristian Dumitrescu * ... 1353421eb42SCristian Dumitrescu * } 1363421eb42SCristian Dumitrescu * default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ] 137fa7723b5SCristian Dumitrescu * hash HASH_FUNCTION_NAME 1383421eb42SCristian Dumitrescu * size SIZE 1393421eb42SCristian Dumitrescu * timeout { 1403421eb42SCristian Dumitrescu * TIMEOUT_IN_SECONDS 1413421eb42SCristian Dumitrescu * ... 1423421eb42SCristian Dumitrescu * } 1433421eb42SCristian Dumitrescu * } 1443421eb42SCristian Dumitrescu */ 1453421eb42SCristian Dumitrescu struct learner_spec { 1463421eb42SCristian Dumitrescu char *name; 1473421eb42SCristian Dumitrescu struct rte_swx_pipeline_learner_params params; 1483421eb42SCristian Dumitrescu uint32_t size; 1493421eb42SCristian Dumitrescu uint32_t *timeout; 1503421eb42SCristian Dumitrescu uint32_t n_timeouts; 1513421eb42SCristian Dumitrescu }; 1523421eb42SCristian Dumitrescu 1533421eb42SCristian Dumitrescu /* 1543421eb42SCristian Dumitrescu * regarray. 1553421eb42SCristian Dumitrescu * 1563421eb42SCristian Dumitrescu * regarray NAME size SIZE initval INITVAL 1573421eb42SCristian Dumitrescu */ 1583421eb42SCristian Dumitrescu struct regarray_spec { 1593421eb42SCristian Dumitrescu char *name; 1603421eb42SCristian Dumitrescu uint64_t init_val; 1613421eb42SCristian Dumitrescu uint32_t size; 1623421eb42SCristian Dumitrescu }; 1633421eb42SCristian Dumitrescu 1643421eb42SCristian Dumitrescu /* 1653421eb42SCristian Dumitrescu * metarray. 1663421eb42SCristian Dumitrescu * 1673421eb42SCristian Dumitrescu * metarray NAME size SIZE 1683421eb42SCristian Dumitrescu */ 1693421eb42SCristian Dumitrescu struct metarray_spec { 1703421eb42SCristian Dumitrescu char *name; 1713421eb42SCristian Dumitrescu uint32_t size; 1723421eb42SCristian Dumitrescu }; 1733421eb42SCristian Dumitrescu 1743421eb42SCristian Dumitrescu /* 1758ba342ceSCristian Dumitrescu * rss. 1768ba342ceSCristian Dumitrescu * 1778ba342ceSCristian Dumitrescu * rss NAME 1788ba342ceSCristian Dumitrescu */ 1798ba342ceSCristian Dumitrescu struct rss_spec { 1808ba342ceSCristian Dumitrescu char *name; 1818ba342ceSCristian Dumitrescu }; 1828ba342ceSCristian Dumitrescu 1838ba342ceSCristian Dumitrescu /* 1843421eb42SCristian Dumitrescu * apply. 1853421eb42SCristian Dumitrescu * 1863421eb42SCristian Dumitrescu * apply { 1873421eb42SCristian Dumitrescu * INSTRUCTION 1883421eb42SCristian Dumitrescu * ... 1893421eb42SCristian Dumitrescu * } 1903421eb42SCristian Dumitrescu */ 1913421eb42SCristian Dumitrescu struct apply_spec { 1923421eb42SCristian Dumitrescu const char **instructions; 1933421eb42SCristian Dumitrescu uint32_t n_instructions; 1943421eb42SCristian Dumitrescu }; 1954684aa75SCristian Dumitrescu 1964684aa75SCristian Dumitrescu /* 1974684aa75SCristian Dumitrescu * Pipeline. 1984684aa75SCristian Dumitrescu */ 1994684aa75SCristian Dumitrescu struct pipeline_spec { 2004684aa75SCristian Dumitrescu struct extobj_spec *extobjs; 2014684aa75SCristian Dumitrescu struct struct_spec *structs; 2024684aa75SCristian Dumitrescu struct header_spec *headers; 2034684aa75SCristian Dumitrescu struct metadata_spec *metadata; 2044684aa75SCristian Dumitrescu struct action_spec *actions; 2054684aa75SCristian Dumitrescu struct table_spec *tables; 2064684aa75SCristian Dumitrescu struct selector_spec *selectors; 2074684aa75SCristian Dumitrescu struct learner_spec *learners; 2084684aa75SCristian Dumitrescu struct regarray_spec *regarrays; 2094684aa75SCristian Dumitrescu struct metarray_spec *metarrays; 2108ba342ceSCristian Dumitrescu struct rss_spec *rss; 2114684aa75SCristian Dumitrescu struct apply_spec *apply; 2124684aa75SCristian Dumitrescu 2134684aa75SCristian Dumitrescu uint32_t n_extobjs; 2144684aa75SCristian Dumitrescu uint32_t n_structs; 2154684aa75SCristian Dumitrescu uint32_t n_headers; 2164684aa75SCristian Dumitrescu uint32_t n_metadata; 2174684aa75SCristian Dumitrescu uint32_t n_actions; 2184684aa75SCristian Dumitrescu uint32_t n_tables; 2194684aa75SCristian Dumitrescu uint32_t n_selectors; 2204684aa75SCristian Dumitrescu uint32_t n_learners; 2214684aa75SCristian Dumitrescu uint32_t n_regarrays; 2224684aa75SCristian Dumitrescu uint32_t n_metarrays; 2238ba342ceSCristian Dumitrescu uint32_t n_rss; 2244684aa75SCristian Dumitrescu uint32_t n_apply; 2254684aa75SCristian Dumitrescu }; 2264684aa75SCristian Dumitrescu 22754cae37eSCristian Dumitrescu /* 22854cae37eSCristian Dumitrescu * Mirroring: 22954cae37eSCristian Dumitrescu * mirroring slots <n_slots> sessions <n_sessions> 23054cae37eSCristian Dumitrescu * 23154cae37eSCristian Dumitrescu * Input ports: 23254cae37eSCristian Dumitrescu * port in <port_id> ethdev <ethdev_name> rxq <queue_id> bsz <burst_size> 23354cae37eSCristian Dumitrescu * port in <port_id> ring <ring_name> bsz <burst_size> 23454cae37eSCristian Dumitrescu * port in <port_id> source mempool <mempool_name> file <file_name> loop <n_loops> 23554cae37eSCristian Dumitrescu * packets <n_pkts_max> 23654cae37eSCristian Dumitrescu * port in <port_id> fd <file_descriptor> mtu <mtu> mempool <mempool_name> bsz <burst_size> 23754cae37eSCristian Dumitrescu * 23854cae37eSCristian Dumitrescu * Output ports: 23954cae37eSCristian Dumitrescu * port out <port_id> ethdev <ethdev_name> txq <queue_id> bsz <burst_size> 24054cae37eSCristian Dumitrescu * port out <port_id> ring <ring_name> bsz <burst_size> 24154cae37eSCristian Dumitrescu * port out <port_id> sink file <file_name> | none 24254cae37eSCristian Dumitrescu * port out <port_id> fd <file_descriptor> bsz <burst_size> 24354cae37eSCristian Dumitrescu */ 24454cae37eSCristian Dumitrescu struct pipeline_iospec { 24554cae37eSCristian Dumitrescu struct rte_swx_pipeline_mirroring_params mirroring_params; 24654cae37eSCristian Dumitrescu 24754cae37eSCristian Dumitrescu uint32_t *port_in_id; 24854cae37eSCristian Dumitrescu const char **port_in_type; 24954cae37eSCristian Dumitrescu void **port_in_params; 25054cae37eSCristian Dumitrescu 25154cae37eSCristian Dumitrescu uint32_t *port_out_id; 25254cae37eSCristian Dumitrescu const char **port_out_type; 25354cae37eSCristian Dumitrescu void **port_out_params; 25454cae37eSCristian Dumitrescu 25554cae37eSCristian Dumitrescu uint32_t n_ports_in; 25654cae37eSCristian Dumitrescu uint32_t n_ports_out; 25754cae37eSCristian Dumitrescu }; 25854cae37eSCristian Dumitrescu 2594684aa75SCristian Dumitrescu void 2604684aa75SCristian Dumitrescu pipeline_spec_free(struct pipeline_spec *s); 261894c93e1SCristian Dumitrescu 262894c93e1SCristian Dumitrescu void 263894c93e1SCristian Dumitrescu pipeline_spec_codegen(FILE *f, 264894c93e1SCristian Dumitrescu struct pipeline_spec *s); 265894c93e1SCristian Dumitrescu 26630c4abb9SCristian Dumitrescu struct pipeline_spec * 26730c4abb9SCristian Dumitrescu pipeline_spec_parse(FILE *spec, 26830c4abb9SCristian Dumitrescu uint32_t *err_line, 26930c4abb9SCristian Dumitrescu const char **err_msg); 27030c4abb9SCristian Dumitrescu 27130c4abb9SCristian Dumitrescu int 27230c4abb9SCristian Dumitrescu pipeline_spec_configure(struct rte_swx_pipeline *p, 27330c4abb9SCristian Dumitrescu struct pipeline_spec *s, 27430c4abb9SCristian Dumitrescu const char **err_msg); 27554cae37eSCristian Dumitrescu 27654cae37eSCristian Dumitrescu void 27754cae37eSCristian Dumitrescu pipeline_iospec_free(struct pipeline_iospec *s); 27854cae37eSCristian Dumitrescu 27954cae37eSCristian Dumitrescu struct pipeline_iospec * 28054cae37eSCristian Dumitrescu pipeline_iospec_parse(FILE *spec, 28154cae37eSCristian Dumitrescu uint32_t *err_line, 28254cae37eSCristian Dumitrescu const char **err_msg); 28354cae37eSCristian Dumitrescu 28454cae37eSCristian Dumitrescu int 28554cae37eSCristian Dumitrescu pipeline_iospec_configure(struct rte_swx_pipeline *p, 28654cae37eSCristian Dumitrescu struct pipeline_iospec *s, 28754cae37eSCristian Dumitrescu const char **err_msg); 28854cae37eSCristian Dumitrescu 28954cae37eSCristian Dumitrescu #ifdef __cplusplus 29054cae37eSCristian Dumitrescu } 29154cae37eSCristian Dumitrescu #endif 29254cae37eSCristian Dumitrescu 29354cae37eSCristian Dumitrescu #endif 294