1d75c371eSJasvinder Singh /* SPDX-License-Identifier: BSD-3-Clause 2d75c371eSJasvinder Singh * Copyright(c) 2010-2018 Intel Corporation 3d75c371eSJasvinder Singh */ 4d75c371eSJasvinder Singh 5d75c371eSJasvinder Singh #ifndef _INCLUDE_PIPELINE_H_ 6d75c371eSJasvinder Singh #define _INCLUDE_PIPELINE_H_ 7d75c371eSJasvinder Singh 8d75c371eSJasvinder Singh #include <stdint.h> 9d75c371eSJasvinder Singh #include <sys/queue.h> 10d75c371eSJasvinder Singh 11d75c371eSJasvinder Singh #include <rte_pipeline.h> 12d75c371eSJasvinder Singh #include <rte_table_action.h> 13d75c371eSJasvinder Singh 14d75c371eSJasvinder Singh #include "common.h" 15d75c371eSJasvinder Singh #include "action.h" 16d75c371eSJasvinder Singh 17d75c371eSJasvinder Singh struct pipeline_params { 18d75c371eSJasvinder Singh uint32_t timer_period_ms; 19d75c371eSJasvinder Singh uint32_t offset_port_id; 20d75c371eSJasvinder Singh uint32_t cpu_id; 21d75c371eSJasvinder Singh }; 22d75c371eSJasvinder Singh 23d75c371eSJasvinder Singh enum port_in_type { 24d75c371eSJasvinder Singh PORT_IN_RXQ, 25d75c371eSJasvinder Singh PORT_IN_SWQ, 26d75c371eSJasvinder Singh PORT_IN_TMGR, 27d75c371eSJasvinder Singh PORT_IN_TAP, 28d75c371eSJasvinder Singh PORT_IN_KNI, 29d75c371eSJasvinder Singh PORT_IN_SOURCE, 30e1884698SFan Zhang PORT_IN_CRYPTODEV, 31d75c371eSJasvinder Singh }; 32d75c371eSJasvinder Singh 33d75c371eSJasvinder Singh struct port_in_params { 34d75c371eSJasvinder Singh /* Read */ 35d75c371eSJasvinder Singh enum port_in_type type; 36d75c371eSJasvinder Singh const char *dev_name; 37d75c371eSJasvinder Singh union { 38d75c371eSJasvinder Singh struct { 39d75c371eSJasvinder Singh uint16_t queue_id; 40d75c371eSJasvinder Singh } rxq; 41d75c371eSJasvinder Singh 42d75c371eSJasvinder Singh struct { 43d75c371eSJasvinder Singh const char *mempool_name; 44d75c371eSJasvinder Singh uint32_t mtu; 45d75c371eSJasvinder Singh } tap; 46d75c371eSJasvinder Singh 47d75c371eSJasvinder Singh struct { 48d75c371eSJasvinder Singh const char *mempool_name; 49d75c371eSJasvinder Singh const char *file_name; 50d75c371eSJasvinder Singh uint32_t n_bytes_per_pkt; 51d75c371eSJasvinder Singh } source; 52e1884698SFan Zhang 53e1884698SFan Zhang struct { 54e1884698SFan Zhang uint16_t queue_id; 55e1884698SFan Zhang void *f_callback; 56e1884698SFan Zhang void *arg_callback; 57e1884698SFan Zhang } cryptodev; 58d75c371eSJasvinder Singh }; 59d75c371eSJasvinder Singh uint32_t burst_size; 60d75c371eSJasvinder Singh 61d75c371eSJasvinder Singh /* Action */ 62d75c371eSJasvinder Singh const char *action_profile_name; 63d75c371eSJasvinder Singh }; 64d75c371eSJasvinder Singh 65d75c371eSJasvinder Singh enum port_out_type { 66d75c371eSJasvinder Singh PORT_OUT_TXQ, 67d75c371eSJasvinder Singh PORT_OUT_SWQ, 68d75c371eSJasvinder Singh PORT_OUT_TMGR, 69d75c371eSJasvinder Singh PORT_OUT_TAP, 70d75c371eSJasvinder Singh PORT_OUT_KNI, 71d75c371eSJasvinder Singh PORT_OUT_SINK, 72e1884698SFan Zhang PORT_OUT_CRYPTODEV, 73d75c371eSJasvinder Singh }; 74d75c371eSJasvinder Singh 75d75c371eSJasvinder Singh struct port_out_params { 76d75c371eSJasvinder Singh enum port_out_type type; 77d75c371eSJasvinder Singh const char *dev_name; 78d75c371eSJasvinder Singh union { 79d75c371eSJasvinder Singh struct { 80d75c371eSJasvinder Singh uint16_t queue_id; 81d75c371eSJasvinder Singh } txq; 82d75c371eSJasvinder Singh 83d75c371eSJasvinder Singh struct { 84d75c371eSJasvinder Singh const char *file_name; 85d75c371eSJasvinder Singh uint32_t max_n_pkts; 86d75c371eSJasvinder Singh } sink; 87e1884698SFan Zhang 88e1884698SFan Zhang struct { 89e1884698SFan Zhang uint16_t queue_id; 90e1884698SFan Zhang uint32_t op_offset; 91e1884698SFan Zhang } cryptodev; 92d75c371eSJasvinder Singh }; 93d75c371eSJasvinder Singh uint32_t burst_size; 94d75c371eSJasvinder Singh int retry; 95d75c371eSJasvinder Singh uint32_t n_retries; 96d75c371eSJasvinder Singh }; 97d75c371eSJasvinder Singh 98d75c371eSJasvinder Singh enum table_type { 99d75c371eSJasvinder Singh TABLE_ACL, 100d75c371eSJasvinder Singh TABLE_ARRAY, 101d75c371eSJasvinder Singh TABLE_HASH, 102d75c371eSJasvinder Singh TABLE_LPM, 103d75c371eSJasvinder Singh TABLE_STUB, 104d75c371eSJasvinder Singh }; 105d75c371eSJasvinder Singh 106d75c371eSJasvinder Singh struct table_acl_params { 107d75c371eSJasvinder Singh uint32_t n_rules; 108d75c371eSJasvinder Singh uint32_t ip_header_offset; 109d75c371eSJasvinder Singh int ip_version; 110d75c371eSJasvinder Singh }; 111d75c371eSJasvinder Singh 112d75c371eSJasvinder Singh struct table_array_params { 113d75c371eSJasvinder Singh uint32_t n_keys; 114d75c371eSJasvinder Singh uint32_t key_offset; 115d75c371eSJasvinder Singh }; 116d75c371eSJasvinder Singh 117d75c371eSJasvinder Singh struct table_hash_params { 118d75c371eSJasvinder Singh uint32_t n_keys; 119d75c371eSJasvinder Singh uint32_t key_offset; 120d75c371eSJasvinder Singh uint32_t key_size; 121d75c371eSJasvinder Singh uint8_t *key_mask; 122d75c371eSJasvinder Singh uint32_t n_buckets; 123d75c371eSJasvinder Singh int extendable_bucket; 124d75c371eSJasvinder Singh }; 125d75c371eSJasvinder Singh 126d75c371eSJasvinder Singh struct table_lpm_params { 127d75c371eSJasvinder Singh uint32_t n_rules; 128d75c371eSJasvinder Singh uint32_t key_offset; 129d75c371eSJasvinder Singh uint32_t key_size; 130d75c371eSJasvinder Singh }; 131d75c371eSJasvinder Singh 132d75c371eSJasvinder Singh struct table_params { 133d75c371eSJasvinder Singh /* Match */ 134d75c371eSJasvinder Singh enum table_type match_type; 135d75c371eSJasvinder Singh union { 136d75c371eSJasvinder Singh struct table_acl_params acl; 137d75c371eSJasvinder Singh struct table_array_params array; 138d75c371eSJasvinder Singh struct table_hash_params hash; 139d75c371eSJasvinder Singh struct table_lpm_params lpm; 140d75c371eSJasvinder Singh } match; 141d75c371eSJasvinder Singh 142d75c371eSJasvinder Singh /* Action */ 143d75c371eSJasvinder Singh const char *action_profile_name; 144d75c371eSJasvinder Singh }; 145d75c371eSJasvinder Singh 14635c10b58SCristian Dumitrescu struct table_rule; 14735c10b58SCristian Dumitrescu 14835c10b58SCristian Dumitrescu TAILQ_HEAD(table_rule_list, table_rule); 14935c10b58SCristian Dumitrescu 150d75c371eSJasvinder Singh struct port_in { 151d75c371eSJasvinder Singh struct port_in_params params; 152d75c371eSJasvinder Singh struct port_in_action_profile *ap; 153d75c371eSJasvinder Singh struct rte_port_in_action *a; 154d75c371eSJasvinder Singh }; 155d75c371eSJasvinder Singh 156d75c371eSJasvinder Singh struct table { 157d75c371eSJasvinder Singh struct table_params params; 158d75c371eSJasvinder Singh struct table_action_profile *ap; 159d75c371eSJasvinder Singh struct rte_table_action *a; 16035c10b58SCristian Dumitrescu struct table_rule_list rules; 16135c10b58SCristian Dumitrescu struct table_rule *rule_default; 162d75c371eSJasvinder Singh }; 163d75c371eSJasvinder Singh 164d75c371eSJasvinder Singh struct pipeline { 165d75c371eSJasvinder Singh TAILQ_ENTRY(pipeline) node; 166d75c371eSJasvinder Singh char name[NAME_SIZE]; 167d75c371eSJasvinder Singh 168d75c371eSJasvinder Singh struct rte_pipeline *p; 169d75c371eSJasvinder Singh struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX]; 170d75c371eSJasvinder Singh struct table table[RTE_PIPELINE_TABLE_MAX]; 171d75c371eSJasvinder Singh uint32_t n_ports_in; 172d75c371eSJasvinder Singh uint32_t n_ports_out; 173d75c371eSJasvinder Singh uint32_t n_tables; 174d75c371eSJasvinder Singh 175d75c371eSJasvinder Singh struct rte_ring *msgq_req; 176d75c371eSJasvinder Singh struct rte_ring *msgq_rsp; 177d75c371eSJasvinder Singh uint32_t timer_period_ms; 178d75c371eSJasvinder Singh 179d75c371eSJasvinder Singh int enabled; 180d75c371eSJasvinder Singh uint32_t thread_id; 181d75c371eSJasvinder Singh uint32_t cpu_id; 182d75c371eSJasvinder Singh }; 183d75c371eSJasvinder Singh 184d75c371eSJasvinder Singh TAILQ_HEAD(pipeline_list, pipeline); 185d75c371eSJasvinder Singh 186d75c371eSJasvinder Singh int 187d75c371eSJasvinder Singh pipeline_init(void); 188d75c371eSJasvinder Singh 189d75c371eSJasvinder Singh struct pipeline * 190d75c371eSJasvinder Singh pipeline_find(const char *name); 191d75c371eSJasvinder Singh 192d75c371eSJasvinder Singh struct pipeline * 193d75c371eSJasvinder Singh pipeline_create(const char *name, struct pipeline_params *params); 194d75c371eSJasvinder Singh 195d75c371eSJasvinder Singh int 196d75c371eSJasvinder Singh pipeline_port_in_create(const char *pipeline_name, 197d75c371eSJasvinder Singh struct port_in_params *params, 198d75c371eSJasvinder Singh int enabled); 199d75c371eSJasvinder Singh 200d75c371eSJasvinder Singh int 201d75c371eSJasvinder Singh pipeline_port_in_connect_to_table(const char *pipeline_name, 202d75c371eSJasvinder Singh uint32_t port_id, 203d75c371eSJasvinder Singh uint32_t table_id); 204d75c371eSJasvinder Singh 205d75c371eSJasvinder Singh int 206d75c371eSJasvinder Singh pipeline_port_out_create(const char *pipeline_name, 207d75c371eSJasvinder Singh struct port_out_params *params); 208d75c371eSJasvinder Singh 209d75c371eSJasvinder Singh int 210d75c371eSJasvinder Singh pipeline_table_create(const char *pipeline_name, 211d75c371eSJasvinder Singh struct table_params *params); 212d75c371eSJasvinder Singh 213d75c371eSJasvinder Singh struct table_rule_match_acl { 214d75c371eSJasvinder Singh int ip_version; 215d75c371eSJasvinder Singh 216d75c371eSJasvinder Singh RTE_STD_C11 217d75c371eSJasvinder Singh union { 218d75c371eSJasvinder Singh struct { 219d75c371eSJasvinder Singh uint32_t sa; 220d75c371eSJasvinder Singh uint32_t da; 221d75c371eSJasvinder Singh } ipv4; 222d75c371eSJasvinder Singh 223d75c371eSJasvinder Singh struct { 224d75c371eSJasvinder Singh uint8_t sa[16]; 225d75c371eSJasvinder Singh uint8_t da[16]; 226d75c371eSJasvinder Singh } ipv6; 227d75c371eSJasvinder Singh }; 228d75c371eSJasvinder Singh 229d75c371eSJasvinder Singh uint32_t sa_depth; 230d75c371eSJasvinder Singh uint32_t da_depth; 231d75c371eSJasvinder Singh uint16_t sp0; 232d75c371eSJasvinder Singh uint16_t sp1; 233d75c371eSJasvinder Singh uint16_t dp0; 234d75c371eSJasvinder Singh uint16_t dp1; 235d75c371eSJasvinder Singh uint8_t proto; 236d75c371eSJasvinder Singh uint8_t proto_mask; 237d75c371eSJasvinder Singh uint32_t priority; 238d75c371eSJasvinder Singh }; 239d75c371eSJasvinder Singh 240d75c371eSJasvinder Singh struct table_rule_match_array { 241d75c371eSJasvinder Singh uint32_t pos; 242d75c371eSJasvinder Singh }; 243d75c371eSJasvinder Singh 244d75c371eSJasvinder Singh #ifndef TABLE_RULE_MATCH_SIZE_MAX 245d75c371eSJasvinder Singh #define TABLE_RULE_MATCH_SIZE_MAX 256 246d75c371eSJasvinder Singh #endif 247d75c371eSJasvinder Singh 248d75c371eSJasvinder Singh #ifndef TABLE_RULE_ACTION_SIZE_MAX 249d75c371eSJasvinder Singh #define TABLE_RULE_ACTION_SIZE_MAX 2048 250d75c371eSJasvinder Singh #endif 251d75c371eSJasvinder Singh 252d75c371eSJasvinder Singh struct table_rule_match_hash { 253d75c371eSJasvinder Singh uint8_t key[TABLE_RULE_MATCH_SIZE_MAX]; 254d75c371eSJasvinder Singh }; 255d75c371eSJasvinder Singh 256d75c371eSJasvinder Singh struct table_rule_match_lpm { 257d75c371eSJasvinder Singh int ip_version; 258d75c371eSJasvinder Singh 259d75c371eSJasvinder Singh RTE_STD_C11 260d75c371eSJasvinder Singh union { 261d75c371eSJasvinder Singh uint32_t ipv4; 262d75c371eSJasvinder Singh uint8_t ipv6[16]; 263d75c371eSJasvinder Singh }; 264d75c371eSJasvinder Singh 265d75c371eSJasvinder Singh uint8_t depth; 266d75c371eSJasvinder Singh }; 267d75c371eSJasvinder Singh 268d75c371eSJasvinder Singh struct table_rule_match { 269d75c371eSJasvinder Singh enum table_type match_type; 270d75c371eSJasvinder Singh 271d75c371eSJasvinder Singh union { 272d75c371eSJasvinder Singh struct table_rule_match_acl acl; 273d75c371eSJasvinder Singh struct table_rule_match_array array; 274d75c371eSJasvinder Singh struct table_rule_match_hash hash; 275d75c371eSJasvinder Singh struct table_rule_match_lpm lpm; 276d75c371eSJasvinder Singh } match; 277d75c371eSJasvinder Singh }; 278d75c371eSJasvinder Singh 279d75c371eSJasvinder Singh struct table_rule_action { 280d75c371eSJasvinder Singh uint64_t action_mask; 281d75c371eSJasvinder Singh struct rte_table_action_fwd_params fwd; 282802755dcSJasvinder Singh struct rte_table_action_lb_params lb; 283d75c371eSJasvinder Singh struct rte_table_action_mtr_params mtr; 284d75c371eSJasvinder Singh struct rte_table_action_tm_params tm; 285d75c371eSJasvinder Singh struct rte_table_action_encap_params encap; 286d75c371eSJasvinder Singh struct rte_table_action_nat_params nat; 287d75c371eSJasvinder Singh struct rte_table_action_ttl_params ttl; 288d75c371eSJasvinder Singh struct rte_table_action_stats_params stats; 289d75c371eSJasvinder Singh struct rte_table_action_time_params time; 290d46fe944SFan Zhang struct rte_table_action_sym_crypto_params sym_crypto; 2911bdf2632SCristian Dumitrescu struct rte_table_action_tag_params tag; 292d5ed626fSCristian Dumitrescu struct rte_table_action_decap_params decap; 293d75c371eSJasvinder Singh }; 294d75c371eSJasvinder Singh 29535c10b58SCristian Dumitrescu struct table_rule { 29635c10b58SCristian Dumitrescu TAILQ_ENTRY(table_rule) node; 29735c10b58SCristian Dumitrescu struct table_rule_match match; 29835c10b58SCristian Dumitrescu struct table_rule_action action; 29935c10b58SCristian Dumitrescu void *data; 30035c10b58SCristian Dumitrescu }; 30135c10b58SCristian Dumitrescu 3026b1b3c3cSJasvinder Singh int 30350e73d05SJasvinder Singh pipeline_port_in_stats_read(const char *pipeline_name, 30450e73d05SJasvinder Singh uint32_t port_id, 30550e73d05SJasvinder Singh struct rte_pipeline_port_in_stats *stats, 30650e73d05SJasvinder Singh int clear); 30750e73d05SJasvinder Singh 30850e73d05SJasvinder Singh int 3096b1b3c3cSJasvinder Singh pipeline_port_in_enable(const char *pipeline_name, 3106b1b3c3cSJasvinder Singh uint32_t port_id); 3116b1b3c3cSJasvinder Singh 3126b1b3c3cSJasvinder Singh int 3136b1b3c3cSJasvinder Singh pipeline_port_in_disable(const char *pipeline_name, 3146b1b3c3cSJasvinder Singh uint32_t port_id); 3156b1b3c3cSJasvinder Singh 31650e73d05SJasvinder Singh int 31750e73d05SJasvinder Singh pipeline_port_out_stats_read(const char *pipeline_name, 31850e73d05SJasvinder Singh uint32_t port_id, 31950e73d05SJasvinder Singh struct rte_pipeline_port_out_stats *stats, 32050e73d05SJasvinder Singh int clear); 32150e73d05SJasvinder Singh 32250e73d05SJasvinder Singh int 32350e73d05SJasvinder Singh pipeline_table_stats_read(const char *pipeline_name, 32450e73d05SJasvinder Singh uint32_t table_id, 32550e73d05SJasvinder Singh struct rte_pipeline_table_stats *stats, 32650e73d05SJasvinder Singh int clear); 32750e73d05SJasvinder Singh 328a3a95b7dSJasvinder Singh int 329a3a95b7dSJasvinder Singh pipeline_table_rule_add(const char *pipeline_name, 330a3a95b7dSJasvinder Singh uint32_t table_id, 331a3a95b7dSJasvinder Singh struct table_rule_match *match, 3324c65163eSCristian Dumitrescu struct table_rule_action *action); 333a3a95b7dSJasvinder Singh 334a3a95b7dSJasvinder Singh int 3353186282fSJasvinder Singh pipeline_table_rule_add_bulk(const char *pipeline_name, 3363186282fSJasvinder Singh uint32_t table_id, 33727b333b2SCristian Dumitrescu struct table_rule_list *list, 33827b333b2SCristian Dumitrescu uint32_t *n_rules_added, 33927b333b2SCristian Dumitrescu uint32_t *n_rules_not_added); 3403186282fSJasvinder Singh 3413186282fSJasvinder Singh int 342a3a95b7dSJasvinder Singh pipeline_table_rule_add_default(const char *pipeline_name, 343a3a95b7dSJasvinder Singh uint32_t table_id, 344*c348ec05SCristian Dumitrescu struct table_rule_action *action); 345a3a95b7dSJasvinder Singh 346f634e4c5SJasvinder Singh int 347f634e4c5SJasvinder Singh pipeline_table_rule_delete(const char *pipeline_name, 348f634e4c5SJasvinder Singh uint32_t table_id, 349f634e4c5SJasvinder Singh struct table_rule_match *match); 350f634e4c5SJasvinder Singh 351f634e4c5SJasvinder Singh int 352f634e4c5SJasvinder Singh pipeline_table_rule_delete_default(const char *pipeline_name, 353f634e4c5SJasvinder Singh uint32_t table_id); 354f634e4c5SJasvinder Singh 355c64b9121SJasvinder Singh int 356c64b9121SJasvinder Singh pipeline_table_rule_stats_read(const char *pipeline_name, 357c64b9121SJasvinder Singh uint32_t table_id, 358c64b9121SJasvinder Singh void *data, 359c64b9121SJasvinder Singh struct rte_table_action_stats_counters *stats, 360c64b9121SJasvinder Singh int clear); 361c64b9121SJasvinder Singh 3627e11393eSJasvinder Singh int 3637e11393eSJasvinder Singh pipeline_table_mtr_profile_add(const char *pipeline_name, 3647e11393eSJasvinder Singh uint32_t table_id, 3657e11393eSJasvinder Singh uint32_t meter_profile_id, 3667e11393eSJasvinder Singh struct rte_table_action_meter_profile *profile); 3677e11393eSJasvinder Singh 3687e11393eSJasvinder Singh int 3697e11393eSJasvinder Singh pipeline_table_mtr_profile_delete(const char *pipeline_name, 3707e11393eSJasvinder Singh uint32_t table_id, 3717e11393eSJasvinder Singh uint32_t meter_profile_id); 3727e11393eSJasvinder Singh 373e92058d6SJasvinder Singh int 374e92058d6SJasvinder Singh pipeline_table_rule_mtr_read(const char *pipeline_name, 375e92058d6SJasvinder Singh uint32_t table_id, 376e92058d6SJasvinder Singh void *data, 377e92058d6SJasvinder Singh uint32_t tc_mask, 378e92058d6SJasvinder Singh struct rte_table_action_mtr_counters *stats, 379e92058d6SJasvinder Singh int clear); 380e92058d6SJasvinder Singh 3812b82ef48SJasvinder Singh int 3822b82ef48SJasvinder Singh pipeline_table_dscp_table_update(const char *pipeline_name, 3832b82ef48SJasvinder Singh uint32_t table_id, 3842b82ef48SJasvinder Singh uint64_t dscp_mask, 3852b82ef48SJasvinder Singh struct rte_table_action_dscp_table *dscp_table); 3862b82ef48SJasvinder Singh 387d0d306c7SJasvinder Singh int 388d0d306c7SJasvinder Singh pipeline_table_rule_ttl_read(const char *pipeline_name, 389d0d306c7SJasvinder Singh uint32_t table_id, 390d0d306c7SJasvinder Singh void *data, 391d0d306c7SJasvinder Singh struct rte_table_action_ttl_counters *stats, 392d0d306c7SJasvinder Singh int clear); 39335c10b58SCristian Dumitrescu struct table_rule * 39435c10b58SCristian Dumitrescu table_rule_find(struct table *table, 39535c10b58SCristian Dumitrescu struct table_rule_match *match); 39635c10b58SCristian Dumitrescu 39735c10b58SCristian Dumitrescu void 39835c10b58SCristian Dumitrescu table_rule_add(struct table *table, 39935c10b58SCristian Dumitrescu struct table_rule *rule); 40035c10b58SCristian Dumitrescu 40135c10b58SCristian Dumitrescu void 40235c10b58SCristian Dumitrescu table_rule_add_bulk(struct table *table, 40335c10b58SCristian Dumitrescu struct table_rule_list *list, 40435c10b58SCristian Dumitrescu uint32_t n_rules); 40535c10b58SCristian Dumitrescu 40635c10b58SCristian Dumitrescu void 40735c10b58SCristian Dumitrescu table_rule_delete(struct table *table, 40835c10b58SCristian Dumitrescu struct table_rule_match *match); 40935c10b58SCristian Dumitrescu 41035c10b58SCristian Dumitrescu void 41135c10b58SCristian Dumitrescu table_rule_default_add(struct table *table, 41235c10b58SCristian Dumitrescu struct table_rule *rule); 41335c10b58SCristian Dumitrescu 41435c10b58SCristian Dumitrescu void 41535c10b58SCristian Dumitrescu table_rule_default_delete(struct table *table); 416d0d306c7SJasvinder Singh 417d75c371eSJasvinder Singh #endif /* _INCLUDE_PIPELINE_H_ */ 418