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