1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * Copyright(c) 2023 Napatech A/S 4 */ 5 6 #ifndef _FLOW_API_ENGINE_H_ 7 #define _FLOW_API_ENGINE_H_ 8 9 #include <stdint.h> 10 #include <stdatomic.h> 11 12 #include "hw_mod_backend.h" 13 #include "stream_binary_flow_api.h" 14 15 /* 16 * Resource management 17 */ 18 #define BIT_CONTAINER_8_ALIGN(x) (((x) + 7) / 8) 19 20 /* 21 * Resource management 22 * These are free resources in FPGA 23 * Other FPGA memory lists are linked to one of these 24 * and will implicitly follow them 25 */ 26 enum res_type_e { 27 RES_QUEUE, 28 RES_CAT_CFN, 29 RES_CAT_COT, 30 RES_CAT_EXO, 31 RES_CAT_LEN, 32 RES_KM_FLOW_TYPE, 33 RES_KM_CATEGORY, 34 RES_HSH_RCP, 35 RES_PDB_RCP, 36 RES_QSL_RCP, 37 RES_QSL_QST, 38 RES_SLC_LR_RCP, 39 40 RES_FLM_FLOW_TYPE, 41 RES_FLM_RCP, 42 RES_TPE_RCP, 43 RES_TPE_EXT, 44 RES_TPE_RPL, 45 RES_SCRUB_RCP, 46 RES_COUNT, 47 RES_INVALID, 48 RES_END 49 }; 50 51 /* 52 * Flow NIC offload management 53 */ 54 #define MAX_OUTPUT_DEST (128) 55 56 #define MAX_WORD_NUM 24 57 #define MAX_BANKS 6 58 59 #define MAX_TCAM_START_OFFSETS 4 60 61 #define MAX_FLM_MTRS_SUPPORTED 4 62 #define MAX_CPY_WRITERS_SUPPORTED 8 63 64 #define MAX_MATCH_FIELDS 16 65 66 /* 67 * 128 128 32 32 32 68 * Have | QW0 || QW4 || SW8 || SW9 | SWX in FPGA 69 * 70 * Each word may start at any offset, though 71 * they are combined in chronological order, with all enabled to 72 * build the extracted match data, thus that is how the match key 73 * must be build 74 */ 75 enum extractor_e { 76 KM_USE_EXTRACTOR_UNDEF, 77 KM_USE_EXTRACTOR_QWORD, 78 KM_USE_EXTRACTOR_SWORD, 79 }; 80 81 struct match_elem_s { 82 enum extractor_e extr; 83 int masked_for_tcam; /* if potentially selected for TCAM */ 84 uint32_t e_word[4]; 85 uint32_t e_mask[4]; 86 87 int extr_start_offs_id; 88 int8_t rel_offs; 89 uint32_t word_len; 90 }; 91 92 enum cam_tech_use_e { 93 KM_CAM, 94 KM_TCAM, 95 KM_SYNERGY 96 }; 97 98 struct km_flow_def_s { 99 struct flow_api_backend_s *be; 100 101 /* For keeping track of identical entries */ 102 struct km_flow_def_s *reference; 103 struct km_flow_def_s *root; 104 105 /* For collect flow elements and sorting */ 106 struct match_elem_s match[MAX_MATCH_FIELDS]; 107 struct match_elem_s *match_map[MAX_MATCH_FIELDS]; 108 int num_ftype_elem; 109 110 /* Finally formatted CAM/TCAM entry */ 111 enum cam_tech_use_e target; 112 uint32_t entry_word[MAX_WORD_NUM]; 113 uint32_t entry_mask[MAX_WORD_NUM]; 114 int key_word_size; 115 116 /* TCAM calculated possible bank start offsets */ 117 int start_offsets[MAX_TCAM_START_OFFSETS]; 118 int num_start_offsets; 119 120 /* Flow information */ 121 /* HW input port ID needed for compare. In port must be identical on flow types */ 122 uint32_t port_id; 123 uint32_t info; /* used for color (actions) */ 124 int info_set; 125 int flow_type; /* 0 is illegal and used as unset */ 126 int flushed_to_target; /* if this km entry has been finally programmed into NIC hw */ 127 128 /* CAM specific bank management */ 129 int cam_paired; 130 int record_indexes[MAX_BANKS]; 131 int bank_used; 132 uint32_t *cuckoo_moves; /* for CAM statistics only */ 133 struct cam_distrib_s *cam_dist; 134 struct hasher_s *hsh; 135 136 /* TCAM specific bank management */ 137 struct tcam_distrib_s *tcam_dist; 138 int tcam_start_bank; 139 int tcam_record; 140 }; 141 142 /* 143 * RSS configuration, see struct rte_flow_action_rss 144 */ 145 struct hsh_def_s { 146 enum rte_eth_hash_function func; /* RSS hash function to apply */ 147 /* RSS hash types, see definition of RTE_ETH_RSS_* for hash calculation options */ 148 uint64_t types; 149 uint32_t key_len; /* Hash key length in bytes. */ 150 const uint8_t *key; /* Hash key. */ 151 }; 152 153 /* 154 * AGE configuration, see struct rte_flow_action_age 155 */ 156 struct age_def_s { 157 uint32_t timeout; 158 void *context; 159 }; 160 161 /* 162 * Tunnel encapsulation header definition 163 */ 164 #define MAX_TUN_HDR_SIZE 128 165 166 struct tunnel_header_s { 167 union { 168 uint8_t hdr8[MAX_TUN_HDR_SIZE]; 169 uint32_t hdr32[(MAX_TUN_HDR_SIZE + 3) / 4]; 170 } d; 171 172 uint8_t len; 173 174 uint8_t nb_vlans; 175 176 uint8_t ip_version; /* 4: v4, 6: v6 */ 177 178 uint8_t new_outer; 179 uint8_t l2_len; 180 uint8_t l3_len; 181 uint8_t l4_len; 182 }; 183 184 enum flow_port_type_e { 185 PORT_NONE, /* not defined or drop */ 186 PORT_INTERNAL, /* no queues attached */ 187 PORT_PHY, /* MAC phy output queue */ 188 PORT_VIRT, /* Memory queues to Host */ 189 }; 190 191 struct output_s { 192 uint32_t owning_port_id;/* the port who owns this output destination */ 193 enum flow_port_type_e type; 194 int id; /* depending on port type: queue ID or physical port id or not used */ 195 int active; /* activated */ 196 }; 197 198 struct nic_flow_def { 199 /* 200 * Frame Decoder match info collected 201 */ 202 int l2_prot; 203 int l3_prot; 204 int l4_prot; 205 int tunnel_prot; 206 int tunnel_l3_prot; 207 int tunnel_l4_prot; 208 int vlans; 209 int fragmentation; 210 int ip_prot; 211 int tunnel_ip_prot; 212 /* 213 * Additional meta data for various functions 214 */ 215 int in_port_override; 216 int non_empty; /* default value is -1; value 1 means flow actions update */ 217 struct output_s dst_id[MAX_OUTPUT_DEST];/* define the output to use */ 218 /* total number of available queues defined for all outputs - i.e. number of dst_id's */ 219 int dst_num_avail; 220 221 /* 222 * Mark or Action info collection 223 */ 224 uint32_t mark; 225 226 uint32_t jump_to_group; 227 228 uint32_t mtr_ids[MAX_FLM_MTRS_SUPPORTED]; 229 230 int full_offload; 231 232 /* 233 * Action push tunnel 234 */ 235 struct tunnel_header_s tun_hdr; 236 237 /* 238 * If DPDK RTE tunnel helper API used 239 * this holds the tunnel if used in flow 240 */ 241 struct tunnel_s *tnl; 242 243 /* 244 * Header Stripper 245 */ 246 int header_strip_end_dyn; 247 int header_strip_end_ofs; 248 249 /* 250 * Modify field 251 */ 252 struct { 253 uint32_t select; 254 uint32_t dyn; 255 uint32_t ofs; 256 uint32_t len; 257 uint32_t level; 258 union { 259 uint8_t value8[16]; 260 uint16_t value16[8]; 261 uint32_t value32[4]; 262 }; 263 } modify_field[MAX_CPY_WRITERS_SUPPORTED]; 264 265 uint32_t modify_field_count; 266 uint8_t ttl_sub_enable; 267 uint8_t ttl_sub_ipv4; 268 uint8_t ttl_sub_outer; 269 270 /* 271 * Key Matcher flow definitions 272 */ 273 struct km_flow_def_s km; 274 275 /* 276 * Hash module RSS definitions 277 */ 278 struct hsh_def_s hsh; 279 280 /* 281 * AGE action timeout 282 */ 283 struct age_def_s age; 284 285 /* 286 * TX fragmentation IFR/RPP_LR MTU recipe 287 */ 288 uint8_t flm_mtu_fragmentation_recipe; 289 }; 290 291 enum flow_handle_type { 292 FLOW_HANDLE_TYPE_FLOW, 293 FLOW_HANDLE_TYPE_FLM, 294 }; 295 296 struct flow_handle { 297 enum flow_handle_type type; 298 uint32_t flm_id; 299 uint16_t caller_id; 300 uint16_t learn_ignored; 301 302 struct flow_eth_dev *dev; 303 struct flow_handle *next; 304 struct flow_handle *prev; 305 306 /* Flow specific pointer to application data stored during action creation. */ 307 void *context; 308 void *user_data; 309 310 union { 311 struct { 312 /* 313 * 1st step conversion and validation of flow 314 * verified and converted flow match + actions structure 315 */ 316 struct nic_flow_def *fd; 317 /* 318 * 2nd step NIC HW resource allocation and configuration 319 * NIC resource management structures 320 */ 321 struct { 322 uint32_t db_idx_counter; 323 uint32_t db_idxs[RES_COUNT]; 324 }; 325 uint32_t port_id; /* MAC port ID or override of virtual in_port */ 326 }; 327 328 struct { 329 uint32_t flm_db_idx_counter; 330 uint32_t flm_db_idxs[RES_COUNT]; 331 332 uint32_t flm_mtr_ids[MAX_FLM_MTRS_SUPPORTED]; 333 334 uint32_t flm_data[10]; 335 uint8_t flm_prot; 336 uint8_t flm_kid; 337 uint8_t flm_prio; 338 uint8_t flm_ft; 339 340 uint16_t flm_rpl_ext_ptr; 341 uint32_t flm_nat_ipv4; 342 uint16_t flm_nat_port; 343 uint8_t flm_dscp; 344 uint32_t flm_teid; 345 uint8_t flm_rqi; 346 uint8_t flm_qfi; 347 uint8_t flm_scrub_prof; 348 349 uint8_t flm_mtu_fragmentation_recipe; 350 351 /* Flow specific pointer to application template table cell stored during 352 * flow create. 353 */ 354 struct flow_template_table_cell *template_table_cell; 355 bool flm_async; 356 }; 357 }; 358 }; 359 360 struct flow_pattern_template { 361 struct nic_flow_def *fd; 362 }; 363 364 struct flow_actions_template { 365 struct nic_flow_def *fd; 366 367 uint32_t num_dest_port; 368 uint32_t num_queues; 369 }; 370 371 struct flow_template_table_cell { 372 atomic_int status; 373 atomic_int counter; 374 375 uint32_t flm_db_idx_counter; 376 uint32_t flm_db_idxs[RES_COUNT]; 377 378 uint32_t flm_key_id; 379 uint32_t flm_ft; 380 381 uint16_t flm_rpl_ext_ptr; 382 uint8_t flm_scrub_prof; 383 }; 384 385 struct flow_template_table { 386 struct flow_pattern_template **pattern_templates; 387 uint8_t nb_pattern_templates; 388 389 struct flow_actions_template **actions_templates; 390 uint8_t nb_actions_templates; 391 392 struct flow_template_table_cell *pattern_action_pairs; 393 394 struct rte_flow_attr attr; 395 uint16_t forced_vlan_vid; 396 uint16_t caller_id; 397 }; 398 399 void km_attach_ndev_resource_management(struct km_flow_def_s *km, void **handle); 400 void km_free_ndev_resource_management(void **handle); 401 402 int km_add_match_elem(struct km_flow_def_s *km, uint32_t e_word[4], uint32_t e_mask[4], 403 uint32_t word_len, enum frame_offs_e start, int8_t offset); 404 405 int km_key_create(struct km_flow_def_s *km, uint32_t port_id); 406 /* 407 * Compares 2 KM key definitions after first collect validate and optimization. 408 * km is compared against an existing km1. 409 * if identical, km1 flow_type is returned 410 */ 411 int km_key_compare(struct km_flow_def_s *km, struct km_flow_def_s *km1); 412 413 int km_rcp_set(struct km_flow_def_s *km, int index); 414 415 int km_write_data_match_entry(struct km_flow_def_s *km, uint32_t color); 416 int km_clear_data_match_entry(struct km_flow_def_s *km); 417 418 void kcc_free_ndev_resource_management(void **handle); 419 420 /* 421 * Group management 422 */ 423 int flow_group_handle_create(void **handle, uint32_t group_count); 424 int flow_group_handle_destroy(void **handle); 425 426 int flow_group_translate_get(void *handle, uint8_t owner_id, uint8_t port_id, uint32_t group_in, 427 uint32_t *group_out); 428 429 #endif /* _FLOW_API_ENGINE_H_ */ 430