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 port_in { 147 struct port_in_params params; 148 struct port_in_action_profile *ap; 149 struct rte_port_in_action *a; 150 }; 151 152 struct table { 153 struct table_params params; 154 struct table_action_profile *ap; 155 struct rte_table_action *a; 156 }; 157 158 struct pipeline { 159 TAILQ_ENTRY(pipeline) node; 160 char name[NAME_SIZE]; 161 162 struct rte_pipeline *p; 163 struct port_in port_in[RTE_PIPELINE_PORT_IN_MAX]; 164 struct table table[RTE_PIPELINE_TABLE_MAX]; 165 uint32_t n_ports_in; 166 uint32_t n_ports_out; 167 uint32_t n_tables; 168 169 struct rte_ring *msgq_req; 170 struct rte_ring *msgq_rsp; 171 uint32_t timer_period_ms; 172 173 int enabled; 174 uint32_t thread_id; 175 uint32_t cpu_id; 176 }; 177 178 TAILQ_HEAD(pipeline_list, pipeline); 179 180 int 181 pipeline_init(void); 182 183 struct pipeline * 184 pipeline_find(const char *name); 185 186 struct pipeline * 187 pipeline_create(const char *name, struct pipeline_params *params); 188 189 int 190 pipeline_port_in_create(const char *pipeline_name, 191 struct port_in_params *params, 192 int enabled); 193 194 int 195 pipeline_port_in_connect_to_table(const char *pipeline_name, 196 uint32_t port_id, 197 uint32_t table_id); 198 199 int 200 pipeline_port_out_create(const char *pipeline_name, 201 struct port_out_params *params); 202 203 int 204 pipeline_table_create(const char *pipeline_name, 205 struct table_params *params); 206 207 struct table_rule_match_acl { 208 int ip_version; 209 210 RTE_STD_C11 211 union { 212 struct { 213 uint32_t sa; 214 uint32_t da; 215 } ipv4; 216 217 struct { 218 uint8_t sa[16]; 219 uint8_t da[16]; 220 } ipv6; 221 }; 222 223 uint32_t sa_depth; 224 uint32_t da_depth; 225 uint16_t sp0; 226 uint16_t sp1; 227 uint16_t dp0; 228 uint16_t dp1; 229 uint8_t proto; 230 uint8_t proto_mask; 231 uint32_t priority; 232 }; 233 234 struct table_rule_match_array { 235 uint32_t pos; 236 }; 237 238 #ifndef TABLE_RULE_MATCH_SIZE_MAX 239 #define TABLE_RULE_MATCH_SIZE_MAX 256 240 #endif 241 242 #ifndef TABLE_RULE_ACTION_SIZE_MAX 243 #define TABLE_RULE_ACTION_SIZE_MAX 2048 244 #endif 245 246 struct table_rule_match_hash { 247 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX]; 248 }; 249 250 struct table_rule_match_lpm { 251 int ip_version; 252 253 RTE_STD_C11 254 union { 255 uint32_t ipv4; 256 uint8_t ipv6[16]; 257 }; 258 259 uint8_t depth; 260 }; 261 262 struct table_rule_match { 263 enum table_type match_type; 264 265 union { 266 struct table_rule_match_acl acl; 267 struct table_rule_match_array array; 268 struct table_rule_match_hash hash; 269 struct table_rule_match_lpm lpm; 270 } match; 271 }; 272 273 struct table_rule_action { 274 uint64_t action_mask; 275 struct rte_table_action_fwd_params fwd; 276 struct rte_table_action_lb_params lb; 277 struct rte_table_action_mtr_params mtr; 278 struct rte_table_action_tm_params tm; 279 struct rte_table_action_encap_params encap; 280 struct rte_table_action_nat_params nat; 281 struct rte_table_action_ttl_params ttl; 282 struct rte_table_action_stats_params stats; 283 struct rte_table_action_time_params time; 284 struct rte_table_action_sym_crypto_params sym_crypto; 285 }; 286 287 int 288 pipeline_port_in_stats_read(const char *pipeline_name, 289 uint32_t port_id, 290 struct rte_pipeline_port_in_stats *stats, 291 int clear); 292 293 int 294 pipeline_port_in_enable(const char *pipeline_name, 295 uint32_t port_id); 296 297 int 298 pipeline_port_in_disable(const char *pipeline_name, 299 uint32_t port_id); 300 301 int 302 pipeline_port_out_stats_read(const char *pipeline_name, 303 uint32_t port_id, 304 struct rte_pipeline_port_out_stats *stats, 305 int clear); 306 307 int 308 pipeline_table_stats_read(const char *pipeline_name, 309 uint32_t table_id, 310 struct rte_pipeline_table_stats *stats, 311 int clear); 312 313 int 314 pipeline_table_rule_add(const char *pipeline_name, 315 uint32_t table_id, 316 struct table_rule_match *match, 317 struct table_rule_action *action, 318 void **data); 319 320 int 321 pipeline_table_rule_add_bulk(const char *pipeline_name, 322 uint32_t table_id, 323 struct table_rule_match *match, 324 struct table_rule_action *action, 325 void **data, 326 uint32_t *n_rules); 327 328 int 329 pipeline_table_rule_add_default(const char *pipeline_name, 330 uint32_t table_id, 331 struct table_rule_action *action, 332 void **data); 333 334 int 335 pipeline_table_rule_delete(const char *pipeline_name, 336 uint32_t table_id, 337 struct table_rule_match *match); 338 339 int 340 pipeline_table_rule_delete_default(const char *pipeline_name, 341 uint32_t table_id); 342 343 int 344 pipeline_table_rule_stats_read(const char *pipeline_name, 345 uint32_t table_id, 346 void *data, 347 struct rte_table_action_stats_counters *stats, 348 int clear); 349 350 int 351 pipeline_table_mtr_profile_add(const char *pipeline_name, 352 uint32_t table_id, 353 uint32_t meter_profile_id, 354 struct rte_table_action_meter_profile *profile); 355 356 int 357 pipeline_table_mtr_profile_delete(const char *pipeline_name, 358 uint32_t table_id, 359 uint32_t meter_profile_id); 360 361 int 362 pipeline_table_rule_mtr_read(const char *pipeline_name, 363 uint32_t table_id, 364 void *data, 365 uint32_t tc_mask, 366 struct rte_table_action_mtr_counters *stats, 367 int clear); 368 369 int 370 pipeline_table_dscp_table_update(const char *pipeline_name, 371 uint32_t table_id, 372 uint64_t dscp_mask, 373 struct rte_table_action_dscp_table *dscp_table); 374 375 int 376 pipeline_table_rule_ttl_read(const char *pipeline_name, 377 uint32_t table_id, 378 void *data, 379 struct rte_table_action_ttl_counters *stats, 380 int clear); 381 382 #endif /* _INCLUDE_PIPELINE_H_ */ 383