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, 30d75c371eSJasvinder Singh }; 31d75c371eSJasvinder Singh 32d75c371eSJasvinder Singh struct port_in_params { 33d75c371eSJasvinder Singh /* Read */ 34d75c371eSJasvinder Singh enum port_in_type type; 35d75c371eSJasvinder Singh const char *dev_name; 36d75c371eSJasvinder Singh union { 37d75c371eSJasvinder Singh struct { 38d75c371eSJasvinder Singh uint16_t queue_id; 39d75c371eSJasvinder Singh } rxq; 40d75c371eSJasvinder Singh 41d75c371eSJasvinder Singh struct { 42d75c371eSJasvinder Singh const char *mempool_name; 43d75c371eSJasvinder Singh uint32_t mtu; 44d75c371eSJasvinder Singh } tap; 45d75c371eSJasvinder Singh 46d75c371eSJasvinder Singh struct { 47d75c371eSJasvinder Singh const char *mempool_name; 48d75c371eSJasvinder Singh const char *file_name; 49d75c371eSJasvinder Singh uint32_t n_bytes_per_pkt; 50d75c371eSJasvinder Singh } source; 51d75c371eSJasvinder Singh }; 52d75c371eSJasvinder Singh uint32_t burst_size; 53d75c371eSJasvinder Singh 54d75c371eSJasvinder Singh /* Action */ 55d75c371eSJasvinder Singh const char *action_profile_name; 56d75c371eSJasvinder Singh }; 57d75c371eSJasvinder Singh 58d75c371eSJasvinder Singh enum port_out_type { 59d75c371eSJasvinder Singh PORT_OUT_TXQ, 60d75c371eSJasvinder Singh PORT_OUT_SWQ, 61d75c371eSJasvinder Singh PORT_OUT_TMGR, 62d75c371eSJasvinder Singh PORT_OUT_TAP, 63d75c371eSJasvinder Singh PORT_OUT_KNI, 64d75c371eSJasvinder Singh PORT_OUT_SINK, 65d75c371eSJasvinder Singh }; 66d75c371eSJasvinder Singh 67d75c371eSJasvinder Singh struct port_out_params { 68d75c371eSJasvinder Singh enum port_out_type type; 69d75c371eSJasvinder Singh const char *dev_name; 70d75c371eSJasvinder Singh union { 71d75c371eSJasvinder Singh struct { 72d75c371eSJasvinder Singh uint16_t queue_id; 73d75c371eSJasvinder Singh } txq; 74d75c371eSJasvinder Singh 75d75c371eSJasvinder Singh struct { 76d75c371eSJasvinder Singh const char *file_name; 77d75c371eSJasvinder Singh uint32_t max_n_pkts; 78d75c371eSJasvinder Singh } sink; 79d75c371eSJasvinder Singh }; 80d75c371eSJasvinder Singh uint32_t burst_size; 81d75c371eSJasvinder Singh int retry; 82d75c371eSJasvinder Singh uint32_t n_retries; 83d75c371eSJasvinder Singh }; 84d75c371eSJasvinder Singh 85d75c371eSJasvinder Singh enum table_type { 86d75c371eSJasvinder Singh TABLE_ACL, 87d75c371eSJasvinder Singh TABLE_ARRAY, 88d75c371eSJasvinder Singh TABLE_HASH, 89d75c371eSJasvinder Singh TABLE_LPM, 90d75c371eSJasvinder Singh TABLE_STUB, 91d75c371eSJasvinder Singh }; 92d75c371eSJasvinder Singh 93d75c371eSJasvinder Singh struct table_acl_params { 94d75c371eSJasvinder Singh uint32_t n_rules; 95d75c371eSJasvinder Singh uint32_t ip_header_offset; 96d75c371eSJasvinder Singh int ip_version; 97d75c371eSJasvinder Singh }; 98d75c371eSJasvinder Singh 99d75c371eSJasvinder Singh struct table_array_params { 100d75c371eSJasvinder Singh uint32_t n_keys; 101d75c371eSJasvinder Singh uint32_t key_offset; 102d75c371eSJasvinder Singh }; 103d75c371eSJasvinder Singh 104d75c371eSJasvinder Singh struct table_hash_params { 105d75c371eSJasvinder Singh uint32_t n_keys; 106d75c371eSJasvinder Singh uint32_t key_offset; 107d75c371eSJasvinder Singh uint32_t key_size; 108d75c371eSJasvinder Singh uint8_t *key_mask; 109d75c371eSJasvinder Singh uint32_t n_buckets; 110d75c371eSJasvinder Singh int extendable_bucket; 111d75c371eSJasvinder Singh }; 112d75c371eSJasvinder Singh 113d75c371eSJasvinder Singh struct table_lpm_params { 114d75c371eSJasvinder Singh uint32_t n_rules; 115d75c371eSJasvinder Singh uint32_t key_offset; 116d75c371eSJasvinder Singh uint32_t key_size; 117d75c371eSJasvinder Singh }; 118d75c371eSJasvinder Singh 119d75c371eSJasvinder Singh struct table_params { 120d75c371eSJasvinder Singh /* Match */ 121d75c371eSJasvinder Singh enum table_type match_type; 122d75c371eSJasvinder Singh union { 123d75c371eSJasvinder Singh struct table_acl_params acl; 124d75c371eSJasvinder Singh struct table_array_params array; 125d75c371eSJasvinder Singh struct table_hash_params hash; 126d75c371eSJasvinder Singh struct table_lpm_params lpm; 127d75c371eSJasvinder Singh } match; 128d75c371eSJasvinder Singh 129d75c371eSJasvinder Singh /* Action */ 130d75c371eSJasvinder Singh const char *action_profile_name; 131d75c371eSJasvinder Singh }; 132d75c371eSJasvinder Singh 133d75c371eSJasvinder Singh struct port_in { 134d75c371eSJasvinder Singh struct port_in_params params; 135d75c371eSJasvinder Singh struct port_in_action_profile *ap; 136d75c371eSJasvinder Singh struct rte_port_in_action *a; 137d75c371eSJasvinder Singh }; 138d75c371eSJasvinder Singh 139d75c371eSJasvinder Singh struct table { 140d75c371eSJasvinder Singh struct table_params params; 141d75c371eSJasvinder Singh struct table_action_profile *ap; 142d75c371eSJasvinder Singh struct rte_table_action *a; 143d75c371eSJasvinder Singh }; 144d75c371eSJasvinder Singh 145d75c371eSJasvinder Singh struct pipeline { 146d75c371eSJasvinder Singh TAILQ_ENTRY(pipeline) node; 147d75c371eSJasvinder Singh char name[NAME_SIZE]; 148d75c371eSJasvinder Singh 149d75c371eSJasvinder Singh struct rte_pipeline *p; 150d75c371eSJasvinder Singh struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX]; 151d75c371eSJasvinder Singh struct table table[RTE_PIPELINE_TABLE_MAX]; 152d75c371eSJasvinder Singh uint32_t n_ports_in; 153d75c371eSJasvinder Singh uint32_t n_ports_out; 154d75c371eSJasvinder Singh uint32_t n_tables; 155d75c371eSJasvinder Singh 156d75c371eSJasvinder Singh struct rte_ring *msgq_req; 157d75c371eSJasvinder Singh struct rte_ring *msgq_rsp; 158d75c371eSJasvinder Singh uint32_t timer_period_ms; 159d75c371eSJasvinder Singh 160d75c371eSJasvinder Singh int enabled; 161d75c371eSJasvinder Singh uint32_t thread_id; 162d75c371eSJasvinder Singh uint32_t cpu_id; 163d75c371eSJasvinder Singh }; 164d75c371eSJasvinder Singh 165d75c371eSJasvinder Singh TAILQ_HEAD(pipeline_list, pipeline); 166d75c371eSJasvinder Singh 167d75c371eSJasvinder Singh int 168d75c371eSJasvinder Singh pipeline_init(void); 169d75c371eSJasvinder Singh 170d75c371eSJasvinder Singh struct pipeline * 171d75c371eSJasvinder Singh pipeline_find(const char *name); 172d75c371eSJasvinder Singh 173d75c371eSJasvinder Singh struct pipeline * 174d75c371eSJasvinder Singh pipeline_create(const char *name, struct pipeline_params *params); 175d75c371eSJasvinder Singh 176d75c371eSJasvinder Singh int 177d75c371eSJasvinder Singh pipeline_port_in_create(const char *pipeline_name, 178d75c371eSJasvinder Singh struct port_in_params *params, 179d75c371eSJasvinder Singh int enabled); 180d75c371eSJasvinder Singh 181d75c371eSJasvinder Singh int 182d75c371eSJasvinder Singh pipeline_port_in_connect_to_table(const char *pipeline_name, 183d75c371eSJasvinder Singh uint32_t port_id, 184d75c371eSJasvinder Singh uint32_t table_id); 185d75c371eSJasvinder Singh 186d75c371eSJasvinder Singh int 187d75c371eSJasvinder Singh pipeline_port_out_create(const char *pipeline_name, 188d75c371eSJasvinder Singh struct port_out_params *params); 189d75c371eSJasvinder Singh 190d75c371eSJasvinder Singh int 191d75c371eSJasvinder Singh pipeline_table_create(const char *pipeline_name, 192d75c371eSJasvinder Singh struct table_params *params); 193d75c371eSJasvinder Singh 194d75c371eSJasvinder Singh struct table_rule_match_acl { 195d75c371eSJasvinder Singh int ip_version; 196d75c371eSJasvinder Singh 197d75c371eSJasvinder Singh RTE_STD_C11 198d75c371eSJasvinder Singh union { 199d75c371eSJasvinder Singh struct { 200d75c371eSJasvinder Singh uint32_t sa; 201d75c371eSJasvinder Singh uint32_t da; 202d75c371eSJasvinder Singh } ipv4; 203d75c371eSJasvinder Singh 204d75c371eSJasvinder Singh struct { 205d75c371eSJasvinder Singh uint8_t sa[16]; 206d75c371eSJasvinder Singh uint8_t da[16]; 207d75c371eSJasvinder Singh } ipv6; 208d75c371eSJasvinder Singh }; 209d75c371eSJasvinder Singh 210d75c371eSJasvinder Singh uint32_t sa_depth; 211d75c371eSJasvinder Singh uint32_t da_depth; 212d75c371eSJasvinder Singh uint16_t sp0; 213d75c371eSJasvinder Singh uint16_t sp1; 214d75c371eSJasvinder Singh uint16_t dp0; 215d75c371eSJasvinder Singh uint16_t dp1; 216d75c371eSJasvinder Singh uint8_t proto; 217d75c371eSJasvinder Singh uint8_t proto_mask; 218d75c371eSJasvinder Singh uint32_t priority; 219d75c371eSJasvinder Singh }; 220d75c371eSJasvinder Singh 221d75c371eSJasvinder Singh struct table_rule_match_array { 222d75c371eSJasvinder Singh uint32_t pos; 223d75c371eSJasvinder Singh }; 224d75c371eSJasvinder Singh 225d75c371eSJasvinder Singh #ifndef TABLE_RULE_MATCH_SIZE_MAX 226d75c371eSJasvinder Singh #define TABLE_RULE_MATCH_SIZE_MAX 256 227d75c371eSJasvinder Singh #endif 228d75c371eSJasvinder Singh 229d75c371eSJasvinder Singh #ifndef TABLE_RULE_ACTION_SIZE_MAX 230d75c371eSJasvinder Singh #define TABLE_RULE_ACTION_SIZE_MAX 2048 231d75c371eSJasvinder Singh #endif 232d75c371eSJasvinder Singh 233d75c371eSJasvinder Singh struct table_rule_match_hash { 234d75c371eSJasvinder Singh uint8_t key[TABLE_RULE_MATCH_SIZE_MAX]; 235d75c371eSJasvinder Singh }; 236d75c371eSJasvinder Singh 237d75c371eSJasvinder Singh struct table_rule_match_lpm { 238d75c371eSJasvinder Singh int ip_version; 239d75c371eSJasvinder Singh 240d75c371eSJasvinder Singh RTE_STD_C11 241d75c371eSJasvinder Singh union { 242d75c371eSJasvinder Singh uint32_t ipv4; 243d75c371eSJasvinder Singh uint8_t ipv6[16]; 244d75c371eSJasvinder Singh }; 245d75c371eSJasvinder Singh 246d75c371eSJasvinder Singh uint8_t depth; 247d75c371eSJasvinder Singh }; 248d75c371eSJasvinder Singh 249d75c371eSJasvinder Singh struct table_rule_match { 250d75c371eSJasvinder Singh enum table_type match_type; 251d75c371eSJasvinder Singh 252d75c371eSJasvinder Singh union { 253d75c371eSJasvinder Singh struct table_rule_match_acl acl; 254d75c371eSJasvinder Singh struct table_rule_match_array array; 255d75c371eSJasvinder Singh struct table_rule_match_hash hash; 256d75c371eSJasvinder Singh struct table_rule_match_lpm lpm; 257d75c371eSJasvinder Singh } match; 258d75c371eSJasvinder Singh }; 259d75c371eSJasvinder Singh 260d75c371eSJasvinder Singh struct table_rule_action { 261d75c371eSJasvinder Singh uint64_t action_mask; 262d75c371eSJasvinder Singh struct rte_table_action_fwd_params fwd; 263d75c371eSJasvinder Singh struct rte_table_action_mtr_params mtr; 264d75c371eSJasvinder Singh struct rte_table_action_tm_params tm; 265d75c371eSJasvinder Singh struct rte_table_action_encap_params encap; 266d75c371eSJasvinder Singh struct rte_table_action_nat_params nat; 267d75c371eSJasvinder Singh struct rte_table_action_ttl_params ttl; 268d75c371eSJasvinder Singh struct rte_table_action_stats_params stats; 269d75c371eSJasvinder Singh struct rte_table_action_time_params time; 270d75c371eSJasvinder Singh }; 271d75c371eSJasvinder Singh 2726b1b3c3cSJasvinder Singh int 27350e73d05SJasvinder Singh pipeline_port_in_stats_read(const char *pipeline_name, 27450e73d05SJasvinder Singh uint32_t port_id, 27550e73d05SJasvinder Singh struct rte_pipeline_port_in_stats *stats, 27650e73d05SJasvinder Singh int clear); 27750e73d05SJasvinder Singh 27850e73d05SJasvinder Singh int 2796b1b3c3cSJasvinder Singh pipeline_port_in_enable(const char *pipeline_name, 2806b1b3c3cSJasvinder Singh uint32_t port_id); 2816b1b3c3cSJasvinder Singh 2826b1b3c3cSJasvinder Singh int 2836b1b3c3cSJasvinder Singh pipeline_port_in_disable(const char *pipeline_name, 2846b1b3c3cSJasvinder Singh uint32_t port_id); 2856b1b3c3cSJasvinder Singh 28650e73d05SJasvinder Singh int 28750e73d05SJasvinder Singh pipeline_port_out_stats_read(const char *pipeline_name, 28850e73d05SJasvinder Singh uint32_t port_id, 28950e73d05SJasvinder Singh struct rte_pipeline_port_out_stats *stats, 29050e73d05SJasvinder Singh int clear); 29150e73d05SJasvinder Singh 29250e73d05SJasvinder Singh int 29350e73d05SJasvinder Singh pipeline_table_stats_read(const char *pipeline_name, 29450e73d05SJasvinder Singh uint32_t table_id, 29550e73d05SJasvinder Singh struct rte_pipeline_table_stats *stats, 29650e73d05SJasvinder Singh int clear); 29750e73d05SJasvinder Singh 298a3a95b7dSJasvinder Singh int 299a3a95b7dSJasvinder Singh pipeline_table_rule_add(const char *pipeline_name, 300a3a95b7dSJasvinder Singh uint32_t table_id, 301a3a95b7dSJasvinder Singh struct table_rule_match *match, 302a3a95b7dSJasvinder Singh struct table_rule_action *action, 303a3a95b7dSJasvinder Singh void **data); 304a3a95b7dSJasvinder Singh 305a3a95b7dSJasvinder Singh int 306a3a95b7dSJasvinder Singh pipeline_table_rule_add_default(const char *pipeline_name, 307a3a95b7dSJasvinder Singh uint32_t table_id, 308a3a95b7dSJasvinder Singh struct table_rule_action *action, 309a3a95b7dSJasvinder Singh void **data); 310a3a95b7dSJasvinder Singh 311*f634e4c5SJasvinder Singh int 312*f634e4c5SJasvinder Singh pipeline_table_rule_delete(const char *pipeline_name, 313*f634e4c5SJasvinder Singh uint32_t table_id, 314*f634e4c5SJasvinder Singh struct table_rule_match *match); 315*f634e4c5SJasvinder Singh 316*f634e4c5SJasvinder Singh int 317*f634e4c5SJasvinder Singh pipeline_table_rule_delete_default(const char *pipeline_name, 318*f634e4c5SJasvinder Singh uint32_t table_id); 319*f634e4c5SJasvinder Singh 320d75c371eSJasvinder Singh #endif /* _INCLUDE_PIPELINE_H_ */ 321