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 146d75c371eSJasvinder Singh struct port_in { 147d75c371eSJasvinder Singh struct port_in_params params; 148d75c371eSJasvinder Singh struct port_in_action_profile *ap; 149d75c371eSJasvinder Singh struct rte_port_in_action *a; 150d75c371eSJasvinder Singh }; 151d75c371eSJasvinder Singh 152d75c371eSJasvinder Singh struct table { 153d75c371eSJasvinder Singh struct table_params params; 154d75c371eSJasvinder Singh struct table_action_profile *ap; 155d75c371eSJasvinder Singh struct rte_table_action *a; 156d75c371eSJasvinder Singh }; 157d75c371eSJasvinder Singh 158d75c371eSJasvinder Singh struct pipeline { 159d75c371eSJasvinder Singh TAILQ_ENTRY(pipeline) node; 160d75c371eSJasvinder Singh char name[NAME_SIZE]; 161d75c371eSJasvinder Singh 162d75c371eSJasvinder Singh struct rte_pipeline *p; 163d75c371eSJasvinder Singh struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX]; 164d75c371eSJasvinder Singh struct table table[RTE_PIPELINE_TABLE_MAX]; 165d75c371eSJasvinder Singh uint32_t n_ports_in; 166d75c371eSJasvinder Singh uint32_t n_ports_out; 167d75c371eSJasvinder Singh uint32_t n_tables; 168d75c371eSJasvinder Singh 169d75c371eSJasvinder Singh struct rte_ring *msgq_req; 170d75c371eSJasvinder Singh struct rte_ring *msgq_rsp; 171d75c371eSJasvinder Singh uint32_t timer_period_ms; 172d75c371eSJasvinder Singh 173d75c371eSJasvinder Singh int enabled; 174d75c371eSJasvinder Singh uint32_t thread_id; 175d75c371eSJasvinder Singh uint32_t cpu_id; 176d75c371eSJasvinder Singh }; 177d75c371eSJasvinder Singh 178d75c371eSJasvinder Singh TAILQ_HEAD(pipeline_list, pipeline); 179d75c371eSJasvinder Singh 180d75c371eSJasvinder Singh int 181d75c371eSJasvinder Singh pipeline_init(void); 182d75c371eSJasvinder Singh 183d75c371eSJasvinder Singh struct pipeline * 184d75c371eSJasvinder Singh pipeline_find(const char *name); 185d75c371eSJasvinder Singh 186d75c371eSJasvinder Singh struct pipeline * 187d75c371eSJasvinder Singh pipeline_create(const char *name, struct pipeline_params *params); 188d75c371eSJasvinder Singh 189d75c371eSJasvinder Singh int 190d75c371eSJasvinder Singh pipeline_port_in_create(const char *pipeline_name, 191d75c371eSJasvinder Singh struct port_in_params *params, 192d75c371eSJasvinder Singh int enabled); 193d75c371eSJasvinder Singh 194d75c371eSJasvinder Singh int 195d75c371eSJasvinder Singh pipeline_port_in_connect_to_table(const char *pipeline_name, 196d75c371eSJasvinder Singh uint32_t port_id, 197d75c371eSJasvinder Singh uint32_t table_id); 198d75c371eSJasvinder Singh 199d75c371eSJasvinder Singh int 200d75c371eSJasvinder Singh pipeline_port_out_create(const char *pipeline_name, 201d75c371eSJasvinder Singh struct port_out_params *params); 202d75c371eSJasvinder Singh 203d75c371eSJasvinder Singh int 204d75c371eSJasvinder Singh pipeline_table_create(const char *pipeline_name, 205d75c371eSJasvinder Singh struct table_params *params); 206d75c371eSJasvinder Singh 207d75c371eSJasvinder Singh struct table_rule_match_acl { 208d75c371eSJasvinder Singh int ip_version; 209d75c371eSJasvinder Singh 210d75c371eSJasvinder Singh RTE_STD_C11 211d75c371eSJasvinder Singh union { 212d75c371eSJasvinder Singh struct { 213d75c371eSJasvinder Singh uint32_t sa; 214d75c371eSJasvinder Singh uint32_t da; 215d75c371eSJasvinder Singh } ipv4; 216d75c371eSJasvinder Singh 217d75c371eSJasvinder Singh struct { 218d75c371eSJasvinder Singh uint8_t sa[16]; 219d75c371eSJasvinder Singh uint8_t da[16]; 220d75c371eSJasvinder Singh } ipv6; 221d75c371eSJasvinder Singh }; 222d75c371eSJasvinder Singh 223d75c371eSJasvinder Singh uint32_t sa_depth; 224d75c371eSJasvinder Singh uint32_t da_depth; 225d75c371eSJasvinder Singh uint16_t sp0; 226d75c371eSJasvinder Singh uint16_t sp1; 227d75c371eSJasvinder Singh uint16_t dp0; 228d75c371eSJasvinder Singh uint16_t dp1; 229d75c371eSJasvinder Singh uint8_t proto; 230d75c371eSJasvinder Singh uint8_t proto_mask; 231d75c371eSJasvinder Singh uint32_t priority; 232d75c371eSJasvinder Singh }; 233d75c371eSJasvinder Singh 234d75c371eSJasvinder Singh struct table_rule_match_array { 235d75c371eSJasvinder Singh uint32_t pos; 236d75c371eSJasvinder Singh }; 237d75c371eSJasvinder Singh 238d75c371eSJasvinder Singh #ifndef TABLE_RULE_MATCH_SIZE_MAX 239d75c371eSJasvinder Singh #define TABLE_RULE_MATCH_SIZE_MAX 256 240d75c371eSJasvinder Singh #endif 241d75c371eSJasvinder Singh 242d75c371eSJasvinder Singh #ifndef TABLE_RULE_ACTION_SIZE_MAX 243d75c371eSJasvinder Singh #define TABLE_RULE_ACTION_SIZE_MAX 2048 244d75c371eSJasvinder Singh #endif 245d75c371eSJasvinder Singh 246d75c371eSJasvinder Singh struct table_rule_match_hash { 247d75c371eSJasvinder Singh uint8_t key[TABLE_RULE_MATCH_SIZE_MAX]; 248d75c371eSJasvinder Singh }; 249d75c371eSJasvinder Singh 250d75c371eSJasvinder Singh struct table_rule_match_lpm { 251d75c371eSJasvinder Singh int ip_version; 252d75c371eSJasvinder Singh 253d75c371eSJasvinder Singh RTE_STD_C11 254d75c371eSJasvinder Singh union { 255d75c371eSJasvinder Singh uint32_t ipv4; 256d75c371eSJasvinder Singh uint8_t ipv6[16]; 257d75c371eSJasvinder Singh }; 258d75c371eSJasvinder Singh 259d75c371eSJasvinder Singh uint8_t depth; 260d75c371eSJasvinder Singh }; 261d75c371eSJasvinder Singh 262d75c371eSJasvinder Singh struct table_rule_match { 263d75c371eSJasvinder Singh enum table_type match_type; 264d75c371eSJasvinder Singh 265d75c371eSJasvinder Singh union { 266d75c371eSJasvinder Singh struct table_rule_match_acl acl; 267d75c371eSJasvinder Singh struct table_rule_match_array array; 268d75c371eSJasvinder Singh struct table_rule_match_hash hash; 269d75c371eSJasvinder Singh struct table_rule_match_lpm lpm; 270d75c371eSJasvinder Singh } match; 271d75c371eSJasvinder Singh }; 272d75c371eSJasvinder Singh 273d75c371eSJasvinder Singh struct table_rule_action { 274d75c371eSJasvinder Singh uint64_t action_mask; 275d75c371eSJasvinder Singh struct rte_table_action_fwd_params fwd; 276802755dcSJasvinder Singh struct rte_table_action_lb_params lb; 277d75c371eSJasvinder Singh struct rte_table_action_mtr_params mtr; 278d75c371eSJasvinder Singh struct rte_table_action_tm_params tm; 279d75c371eSJasvinder Singh struct rte_table_action_encap_params encap; 280d75c371eSJasvinder Singh struct rte_table_action_nat_params nat; 281d75c371eSJasvinder Singh struct rte_table_action_ttl_params ttl; 282d75c371eSJasvinder Singh struct rte_table_action_stats_params stats; 283d75c371eSJasvinder Singh struct rte_table_action_time_params time; 284d46fe944SFan Zhang struct rte_table_action_sym_crypto_params sym_crypto; 2851bdf2632SCristian Dumitrescu struct rte_table_action_tag_params tag; 286*d5ed626fSCristian Dumitrescu struct rte_table_action_decap_params decap; 287d75c371eSJasvinder Singh }; 288d75c371eSJasvinder Singh 2896b1b3c3cSJasvinder Singh int 29050e73d05SJasvinder Singh pipeline_port_in_stats_read(const char *pipeline_name, 29150e73d05SJasvinder Singh uint32_t port_id, 29250e73d05SJasvinder Singh struct rte_pipeline_port_in_stats *stats, 29350e73d05SJasvinder Singh int clear); 29450e73d05SJasvinder Singh 29550e73d05SJasvinder Singh int 2966b1b3c3cSJasvinder Singh pipeline_port_in_enable(const char *pipeline_name, 2976b1b3c3cSJasvinder Singh uint32_t port_id); 2986b1b3c3cSJasvinder Singh 2996b1b3c3cSJasvinder Singh int 3006b1b3c3cSJasvinder Singh pipeline_port_in_disable(const char *pipeline_name, 3016b1b3c3cSJasvinder Singh uint32_t port_id); 3026b1b3c3cSJasvinder Singh 30350e73d05SJasvinder Singh int 30450e73d05SJasvinder Singh pipeline_port_out_stats_read(const char *pipeline_name, 30550e73d05SJasvinder Singh uint32_t port_id, 30650e73d05SJasvinder Singh struct rte_pipeline_port_out_stats *stats, 30750e73d05SJasvinder Singh int clear); 30850e73d05SJasvinder Singh 30950e73d05SJasvinder Singh int 31050e73d05SJasvinder Singh pipeline_table_stats_read(const char *pipeline_name, 31150e73d05SJasvinder Singh uint32_t table_id, 31250e73d05SJasvinder Singh struct rte_pipeline_table_stats *stats, 31350e73d05SJasvinder Singh int clear); 31450e73d05SJasvinder Singh 315a3a95b7dSJasvinder Singh int 316a3a95b7dSJasvinder Singh pipeline_table_rule_add(const char *pipeline_name, 317a3a95b7dSJasvinder Singh uint32_t table_id, 318a3a95b7dSJasvinder Singh struct table_rule_match *match, 319a3a95b7dSJasvinder Singh struct table_rule_action *action, 320a3a95b7dSJasvinder Singh void **data); 321a3a95b7dSJasvinder Singh 322a3a95b7dSJasvinder Singh int 3233186282fSJasvinder Singh pipeline_table_rule_add_bulk(const char *pipeline_name, 3243186282fSJasvinder Singh uint32_t table_id, 3253186282fSJasvinder Singh struct table_rule_match *match, 3263186282fSJasvinder Singh struct table_rule_action *action, 3273186282fSJasvinder Singh void **data, 3283186282fSJasvinder Singh uint32_t *n_rules); 3293186282fSJasvinder Singh 3303186282fSJasvinder Singh int 331a3a95b7dSJasvinder Singh pipeline_table_rule_add_default(const char *pipeline_name, 332a3a95b7dSJasvinder Singh uint32_t table_id, 333a3a95b7dSJasvinder Singh struct table_rule_action *action, 334a3a95b7dSJasvinder Singh void **data); 335a3a95b7dSJasvinder Singh 336f634e4c5SJasvinder Singh int 337f634e4c5SJasvinder Singh pipeline_table_rule_delete(const char *pipeline_name, 338f634e4c5SJasvinder Singh uint32_t table_id, 339f634e4c5SJasvinder Singh struct table_rule_match *match); 340f634e4c5SJasvinder Singh 341f634e4c5SJasvinder Singh int 342f634e4c5SJasvinder Singh pipeline_table_rule_delete_default(const char *pipeline_name, 343f634e4c5SJasvinder Singh uint32_t table_id); 344f634e4c5SJasvinder Singh 345c64b9121SJasvinder Singh int 346c64b9121SJasvinder Singh pipeline_table_rule_stats_read(const char *pipeline_name, 347c64b9121SJasvinder Singh uint32_t table_id, 348c64b9121SJasvinder Singh void *data, 349c64b9121SJasvinder Singh struct rte_table_action_stats_counters *stats, 350c64b9121SJasvinder Singh int clear); 351c64b9121SJasvinder Singh 3527e11393eSJasvinder Singh int 3537e11393eSJasvinder Singh pipeline_table_mtr_profile_add(const char *pipeline_name, 3547e11393eSJasvinder Singh uint32_t table_id, 3557e11393eSJasvinder Singh uint32_t meter_profile_id, 3567e11393eSJasvinder Singh struct rte_table_action_meter_profile *profile); 3577e11393eSJasvinder Singh 3587e11393eSJasvinder Singh int 3597e11393eSJasvinder Singh pipeline_table_mtr_profile_delete(const char *pipeline_name, 3607e11393eSJasvinder Singh uint32_t table_id, 3617e11393eSJasvinder Singh uint32_t meter_profile_id); 3627e11393eSJasvinder Singh 363e92058d6SJasvinder Singh int 364e92058d6SJasvinder Singh pipeline_table_rule_mtr_read(const char *pipeline_name, 365e92058d6SJasvinder Singh uint32_t table_id, 366e92058d6SJasvinder Singh void *data, 367e92058d6SJasvinder Singh uint32_t tc_mask, 368e92058d6SJasvinder Singh struct rte_table_action_mtr_counters *stats, 369e92058d6SJasvinder Singh int clear); 370e92058d6SJasvinder Singh 3712b82ef48SJasvinder Singh int 3722b82ef48SJasvinder Singh pipeline_table_dscp_table_update(const char *pipeline_name, 3732b82ef48SJasvinder Singh uint32_t table_id, 3742b82ef48SJasvinder Singh uint64_t dscp_mask, 3752b82ef48SJasvinder Singh struct rte_table_action_dscp_table *dscp_table); 3762b82ef48SJasvinder Singh 377d0d306c7SJasvinder Singh int 378d0d306c7SJasvinder Singh pipeline_table_rule_ttl_read(const char *pipeline_name, 379d0d306c7SJasvinder Singh uint32_t table_id, 380d0d306c7SJasvinder Singh void *data, 381d0d306c7SJasvinder Singh struct rte_table_action_ttl_counters *stats, 382d0d306c7SJasvinder Singh int clear); 383d0d306c7SJasvinder Singh 384d75c371eSJasvinder Singh #endif /* _INCLUDE_PIPELINE_H_ */ 385