1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2018 Intel Corporation 3 */ 4 5 #ifndef _INCLUDE_PIPELINE_H_ 6 #define _INCLUDE_PIPELINE_H_ 7 8 #include <stdint.h> 9 #include <sys/queue.h> 10 11 #include <rte_pipeline.h> 12 #include <rte_table_action.h> 13 14 #include "common.h" 15 #include "action.h" 16 17 struct pipeline_params { 18 uint32_t timer_period_ms; 19 uint32_t offset_port_id; 20 uint32_t cpu_id; 21 }; 22 23 enum port_in_type { 24 PORT_IN_RXQ, 25 PORT_IN_SWQ, 26 PORT_IN_TMGR, 27 PORT_IN_TAP, 28 PORT_IN_SOURCE, 29 PORT_IN_CRYPTODEV, 30 }; 31 32 struct port_in_params { 33 /* Read */ 34 enum port_in_type type; 35 const char *dev_name; 36 union { 37 struct { 38 uint16_t queue_id; 39 } rxq; 40 41 struct { 42 const char *mempool_name; 43 uint32_t mtu; 44 } tap; 45 46 struct { 47 const char *mempool_name; 48 const char *file_name; 49 uint32_t n_bytes_per_pkt; 50 } source; 51 52 struct { 53 uint16_t queue_id; 54 void *f_callback; 55 void *arg_callback; 56 } cryptodev; 57 }; 58 uint32_t burst_size; 59 60 /* Action */ 61 const char *action_profile_name; 62 }; 63 64 enum port_out_type { 65 PORT_OUT_TXQ, 66 PORT_OUT_SWQ, 67 PORT_OUT_TMGR, 68 PORT_OUT_TAP, 69 PORT_OUT_SINK, 70 PORT_OUT_CRYPTODEV, 71 }; 72 73 struct port_out_params { 74 enum port_out_type type; 75 const char *dev_name; 76 union { 77 struct { 78 uint16_t queue_id; 79 } txq; 80 81 struct { 82 const char *file_name; 83 uint32_t max_n_pkts; 84 } sink; 85 86 struct { 87 uint16_t queue_id; 88 uint32_t op_offset; 89 } cryptodev; 90 }; 91 uint32_t burst_size; 92 int retry; 93 uint32_t n_retries; 94 }; 95 96 enum table_type { 97 TABLE_ACL, 98 TABLE_ARRAY, 99 TABLE_HASH, 100 TABLE_LPM, 101 TABLE_STUB, 102 }; 103 104 struct table_acl_params { 105 uint32_t n_rules; 106 uint32_t ip_header_offset; 107 int ip_version; 108 }; 109 110 struct table_array_params { 111 uint32_t n_keys; 112 uint32_t key_offset; 113 }; 114 115 struct table_hash_params { 116 uint32_t n_keys; 117 uint32_t key_offset; 118 uint32_t key_size; 119 uint8_t *key_mask; 120 uint32_t n_buckets; 121 int extendable_bucket; 122 }; 123 124 struct table_lpm_params { 125 uint32_t n_rules; 126 uint32_t key_offset; 127 uint32_t key_size; 128 }; 129 130 struct table_params { 131 /* Match */ 132 enum table_type match_type; 133 union { 134 struct table_acl_params acl; 135 struct table_array_params array; 136 struct table_hash_params hash; 137 struct table_lpm_params lpm; 138 } match; 139 140 /* Action */ 141 const char *action_profile_name; 142 }; 143 144 struct table_rule; 145 146 TAILQ_HEAD(table_rule_list, table_rule); 147 148 struct port_in { 149 struct port_in_params params; 150 struct port_in_action_profile *ap; 151 struct rte_port_in_action *a; 152 }; 153 154 struct table { 155 struct table_params params; 156 struct table_action_profile *ap; 157 struct rte_table_action *a; 158 struct table_rule_list rules; 159 struct table_rule *rule_default; 160 }; 161 162 struct pipeline { 163 TAILQ_ENTRY(pipeline) node; 164 char name[NAME_SIZE]; 165 166 struct rte_pipeline *p; 167 struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX]; 168 struct table table[RTE_PIPELINE_TABLE_MAX]; 169 uint32_t n_ports_in; 170 uint32_t n_ports_out; 171 uint32_t n_tables; 172 173 struct rte_ring *msgq_req; 174 struct rte_ring *msgq_rsp; 175 uint32_t timer_period_ms; 176 177 int enabled; 178 uint32_t thread_id; 179 uint32_t cpu_id; 180 }; 181 182 TAILQ_HEAD(pipeline_list, pipeline); 183 184 int 185 pipeline_init(void); 186 187 struct pipeline * 188 pipeline_find(const char *name); 189 190 struct pipeline * 191 pipeline_create(const char *name, struct pipeline_params *params); 192 193 int 194 pipeline_port_in_create(const char *pipeline_name, 195 struct port_in_params *params, 196 int enabled); 197 198 int 199 pipeline_port_in_connect_to_table(const char *pipeline_name, 200 uint32_t port_id, 201 uint32_t table_id); 202 203 int 204 pipeline_port_out_create(const char *pipeline_name, 205 struct port_out_params *params); 206 207 int 208 pipeline_table_create(const char *pipeline_name, 209 struct table_params *params); 210 211 struct table_rule_match_acl { 212 int ip_version; 213 214 union { 215 struct { 216 uint32_t sa; 217 uint32_t da; 218 } ipv4; 219 220 struct { 221 struct rte_ipv6_addr sa; 222 struct rte_ipv6_addr da; 223 } ipv6; 224 }; 225 226 uint32_t sa_depth; 227 uint32_t da_depth; 228 uint16_t sp0; 229 uint16_t sp1; 230 uint16_t dp0; 231 uint16_t dp1; 232 uint8_t proto; 233 uint8_t proto_mask; 234 uint32_t priority; 235 }; 236 237 struct table_rule_match_array { 238 uint32_t pos; 239 }; 240 241 #ifndef TABLE_RULE_MATCH_SIZE_MAX 242 #define TABLE_RULE_MATCH_SIZE_MAX 256 243 #endif 244 245 #ifndef TABLE_RULE_ACTION_SIZE_MAX 246 #define TABLE_RULE_ACTION_SIZE_MAX 2048 247 #endif 248 249 struct table_rule_match_hash { 250 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX]; 251 }; 252 253 struct table_rule_match_lpm { 254 int ip_version; 255 256 union { 257 uint32_t ipv4; 258 struct rte_ipv6_addr ipv6; 259 }; 260 261 uint8_t depth; 262 }; 263 264 struct table_rule_match { 265 enum table_type match_type; 266 267 union { 268 struct table_rule_match_acl acl; 269 struct table_rule_match_array array; 270 struct table_rule_match_hash hash; 271 struct table_rule_match_lpm lpm; 272 } match; 273 }; 274 275 #ifndef SYM_CRYPTO_MAX_KEY_SIZE 276 #define SYM_CRYPTO_MAX_KEY_SIZE (256) 277 #endif 278 279 struct table_rule_action { 280 uint64_t action_mask; 281 struct rte_table_action_fwd_params fwd; 282 struct rte_table_action_lb_params lb; 283 struct rte_table_action_mtr_params mtr; 284 struct rte_table_action_tm_params tm; 285 struct rte_table_action_encap_params encap; 286 struct rte_table_action_nat_params nat; 287 struct rte_table_action_ttl_params ttl; 288 struct rte_table_action_stats_params stats; 289 struct rte_table_action_time_params time; 290 struct rte_table_action_sym_crypto_params sym_crypto; 291 uint8_t sym_crypto_key[SYM_CRYPTO_MAX_KEY_SIZE]; 292 struct rte_table_action_tag_params tag; 293 struct rte_table_action_decap_params decap; 294 295 }; 296 297 struct table_rule { 298 TAILQ_ENTRY(table_rule) node; 299 struct table_rule_match match; 300 struct table_rule_action action; 301 void *data; 302 }; 303 304 int 305 pipeline_port_in_stats_read(const char *pipeline_name, 306 uint32_t port_id, 307 struct rte_pipeline_port_in_stats *stats, 308 int clear); 309 310 int 311 pipeline_port_in_enable(const char *pipeline_name, 312 uint32_t port_id); 313 314 int 315 pipeline_port_in_disable(const char *pipeline_name, 316 uint32_t port_id); 317 318 int 319 pipeline_port_out_stats_read(const char *pipeline_name, 320 uint32_t port_id, 321 struct rte_pipeline_port_out_stats *stats, 322 int clear); 323 324 int 325 pipeline_table_stats_read(const char *pipeline_name, 326 uint32_t table_id, 327 struct rte_pipeline_table_stats *stats, 328 int clear); 329 330 int 331 pipeline_table_rule_add(const char *pipeline_name, 332 uint32_t table_id, 333 struct table_rule_match *match, 334 struct table_rule_action *action); 335 336 int 337 pipeline_table_rule_add_bulk(const char *pipeline_name, 338 uint32_t table_id, 339 struct table_rule_list *list, 340 uint32_t *n_rules_added, 341 uint32_t *n_rules_not_added); 342 343 int 344 pipeline_table_rule_add_default(const char *pipeline_name, 345 uint32_t table_id, 346 struct table_rule_action *action); 347 348 int 349 pipeline_table_rule_delete(const char *pipeline_name, 350 uint32_t table_id, 351 struct table_rule_match *match); 352 353 int 354 pipeline_table_rule_delete_default(const char *pipeline_name, 355 uint32_t table_id); 356 357 int 358 pipeline_table_rule_stats_read(const char *pipeline_name, 359 uint32_t table_id, 360 struct table_rule_match *match, 361 struct rte_table_action_stats_counters *stats, 362 int clear); 363 364 int 365 pipeline_table_mtr_profile_add(const char *pipeline_name, 366 uint32_t table_id, 367 uint32_t meter_profile_id, 368 struct rte_table_action_meter_profile *profile); 369 370 int 371 pipeline_table_mtr_profile_delete(const char *pipeline_name, 372 uint32_t table_id, 373 uint32_t meter_profile_id); 374 375 int 376 pipeline_table_rule_mtr_read(const char *pipeline_name, 377 uint32_t table_id, 378 struct table_rule_match *match, 379 struct rte_table_action_mtr_counters *stats, 380 int clear); 381 382 int 383 pipeline_table_dscp_table_update(const char *pipeline_name, 384 uint32_t table_id, 385 uint64_t dscp_mask, 386 struct rte_table_action_dscp_table *dscp_table); 387 388 int 389 pipeline_table_rule_ttl_read(const char *pipeline_name, 390 uint32_t table_id, 391 struct table_rule_match *match, 392 struct rte_table_action_ttl_counters *stats, 393 int clear); 394 395 int 396 pipeline_table_rule_time_read(const char *pipeline_name, 397 uint32_t table_id, 398 struct table_rule_match *match, 399 uint64_t *timestamp); 400 401 struct table_rule * 402 table_rule_find(struct table *table, 403 struct table_rule_match *match); 404 405 void 406 table_rule_add(struct table *table, 407 struct table_rule *rule); 408 409 void 410 table_rule_add_bulk(struct table *table, 411 struct table_rule_list *list, 412 uint32_t n_rules); 413 414 void 415 table_rule_delete(struct table *table, 416 struct table_rule_match *match); 417 418 void 419 table_rule_default_add(struct table *table, 420 struct table_rule *rule); 421 422 void 423 table_rule_default_delete(struct table *table); 424 425 #endif /* _INCLUDE_PIPELINE_H_ */ 426