1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2018-2019 Cisco Systems, Inc. All rights reserved. 3 */ 4 #ifndef _VNIC_FLOWMAN_H_ 5 #define _VNIC_FLOWMAN_H_ 6 7 /* This file contains Flow Manager (FM) API of the firmware */ 8 9 /* Flow manager sub-ops */ 10 enum { 11 FM_EXACT_TABLE_ALLOC, 12 FM_TCAM_TABLE_ALLOC, 13 FM_MATCH_TABLE_FREE, 14 FM_COUNTER_BRK, 15 FM_COUNTER_QUERY, 16 FM_COUNTER_CLEAR_ALL, 17 FM_COUNTER_DMA, 18 FM_ACTION_ALLOC, 19 FM_ACTION_FREE, 20 FM_EXACT_ENTRY_INSTALL, 21 FM_TCAM_ENTRY_INSTALL, 22 FM_MATCH_ENTRY_REMOVE, 23 FM_VNIC_FIND, 24 FM_API_VERSION_QUERY, 25 FM_API_VERSION_SELECT, 26 FM_INFO_QUERY 27 }; 28 29 /* 30 * FKM (flow key metadata) flags used to match packet metadata 31 * (e.g. packet is tcp) 32 */ 33 #define FKM_BITS \ 34 FBIT(FKM_QTAG) \ 35 FBIT(FKM_CMD) \ 36 FBIT(FKM_IPV4) \ 37 FBIT(FKM_IPV6) \ 38 FBIT(FKM_ROCE) \ 39 FBIT(FKM_UDP) \ 40 FBIT(FKM_TCP) \ 41 FBIT(FKM_TCPORUDP) \ 42 FBIT(FKM_IPFRAG) \ 43 FBIT(FKM_NVGRE) \ 44 FBIT(FKM_VXLAN) \ 45 FBIT(FKM_GENEVE) \ 46 FBIT(FKM_NSH) \ 47 FBIT(FKM_ROCEV2) \ 48 FBIT(FKM_VLAN_PRES) \ 49 FBIT(FKM_IPOK) \ 50 FBIT(FKM_L4OK) \ 51 FBIT(FKM_ROCEOK) \ 52 FBIT(FKM_FCSOK) \ 53 FBIT(FKM_EG_SPAN) \ 54 FBIT(FKM_IG_SPAN) \ 55 FBIT(FKM_EG_HAIRPINNED) 56 57 /* 58 * FKH (flow key header) flags. 59 * This selects which headers are valid in the struct. 60 * This is distinct from metadata in that metadata is requesting actual 61 * selection criteria. If, for example, a TCAM match with metadata "FKM_UDP" 62 * is feeding into an exact match table, there may be no need for the 63 * exact match table to also specify FKM_UDP, so FKH_UDP is used to 64 * specify that the UDP header fields should be used in the match. 65 */ 66 #define FKH_BITS \ 67 FBIT(FKH_ETHER) \ 68 FBIT(FKH_QTAG) \ 69 FBIT(FKH_L2RAW) \ 70 FBIT(FKH_IPV4) \ 71 FBIT(FKH_IPV6) \ 72 FBIT(FKH_L3RAW) \ 73 FBIT(FKH_UDP) \ 74 FBIT(FKH_TCP) \ 75 FBIT(FKH_ICMP) \ 76 FBIT(FKH_VXLAN) \ 77 FBIT(FKH_L4RAW) 78 79 #define FBIT(X) X##_BIT, 80 enum { 81 FKM_BITS 82 FKM_BIT_COUNT 83 }; 84 85 enum { 86 FKH_BITS 87 FKH_BIT_COUNT 88 }; 89 #undef FBIT 90 #define FBIT(X) X = (1 << X##_BIT), 91 enum { 92 FKM_BITS 93 }; 94 enum { 95 FKH_BITS 96 }; 97 #undef FBIT 98 99 #define FM_ETH_ALEN 6 100 #define FM_LAYER_SIZE 64 101 102 /* Header match pattern */ 103 struct __rte_packed_begin fm_header_set { 104 uint32_t fk_metadata; /* FKM flags */ 105 uint32_t fk_header_select; /* FKH flags */ 106 uint16_t fk_vlan; 107 /* L2: Ethernet Header (valid if FKH_ETHER) */ 108 union __rte_packed_begin { 109 struct __rte_packed_begin { 110 uint8_t fk_dstmac[FM_ETH_ALEN]; 111 uint8_t fk_srcmac[FM_ETH_ALEN]; 112 uint16_t fk_ethtype; 113 } __rte_packed_end eth; 114 uint8_t rawdata[FM_LAYER_SIZE]; 115 } __rte_packed_end l2; 116 /* L3: IPv4 or IPv6 (valid if FKH_IPV4,6) */ 117 union __rte_packed_begin { 118 /* Valid if FKH_IPV4 */ 119 struct __rte_packed_begin { 120 uint8_t fk_ihl_vers; 121 uint8_t fk_tos; 122 uint16_t fk_tot_len; 123 uint16_t fk_id; 124 uint16_t fk_frag_off; 125 uint8_t fk_ttl; 126 uint8_t fk_proto; 127 uint16_t fk_check; 128 uint32_t fk_saddr; 129 uint32_t fk_daddr; 130 } __rte_packed_end ip4; 131 /* Valid if FKH_IPV6 */ 132 struct __rte_packed_begin { 133 union { 134 struct { 135 uint32_t fk_un1_flow; 136 uint16_t fk_un1_plen; 137 uint8_t fk_un1_nxt; 138 uint8_t fk_un1_hlim; 139 } unl; 140 uint8_t fk_un2_vfc; 141 } ctl; 142 uint8_t fk_srcip[16]; 143 uint8_t fk_dstip[16]; 144 } __rte_packed_end ip6; 145 uint8_t rawdata[FM_LAYER_SIZE]; 146 } __rte_packed_end l3; 147 /* L4: UDP, TCP, or ICMP (valid if FKH_UDP,TCP,ICMP) */ 148 union __rte_packed_begin { 149 struct __rte_packed_begin { 150 uint16_t fk_source; 151 uint16_t fk_dest; 152 uint16_t fk_len; 153 uint16_t fk_check; 154 } __rte_packed_end udp; 155 struct __rte_packed_begin { 156 uint16_t fk_source; 157 uint16_t fk_dest; 158 uint32_t fk_seq; 159 uint32_t fk_ack_seq; 160 uint16_t fk_flags; 161 uint16_t fk_window; 162 uint16_t fk_check; 163 uint16_t fk_urg_ptr; 164 } __rte_packed_end tcp; 165 struct __rte_packed_begin { 166 uint8_t fk_code; 167 uint8_t fk_type; 168 } __rte_packed_end icmp; 169 uint8_t rawdata[FM_LAYER_SIZE]; 170 } __rte_packed_end l4; 171 /* VXLAN (valid if FKH_VXLAN) */ 172 struct __rte_packed_begin { 173 uint8_t fkvx_flags; 174 uint8_t fkvx_res0[3]; 175 uint8_t fkvx_vni[3]; 176 uint8_t fkvx_res1; 177 } __rte_packed_end vxlan; 178 /* Payload or unknown inner-most protocol */ 179 uint8_t fk_l5_data[64]; 180 } __rte_packed_end; 181 182 /* 183 * FK (flow key) template. 184 * fk_hdrset specifies a set of headers per layer of encapsulation. 185 * Currently FM supports two header sets: outer (0) and inner(1) 186 */ 187 #define FM_HDRSET_MAX 2 188 189 struct __rte_packed_begin fm_key_template { 190 struct fm_header_set fk_hdrset[FM_HDRSET_MAX]; 191 uint32_t fk_flags; 192 uint16_t fk_packet_tag; 193 uint16_t fk_packet_size; 194 uint16_t fk_port_id; 195 uint32_t fk_wq_id; /* WQ index */ 196 uint64_t fk_wq_vnic; /* VNIC handle for WQ index */ 197 } __rte_packed_end; 198 199 /* Action operation types */ 200 enum { 201 FMOP_NOP = 0, 202 /* End the action chain. */ 203 FMOP_END, 204 /* Drop packet and end the action chain. */ 205 FMOP_DROP, 206 /* Steer packet to an RQ. */ 207 FMOP_RQ_STEER, 208 /* 209 * Jump to an exact match table. 210 * arg1: exact match table handle 211 */ 212 FMOP_EXACT_MATCH, 213 /* Apply CQ-visible mark on packet. Mark is written to RSS HASH. */ 214 FMOP_MARK, 215 /* 216 * Apply CQ-visible mark on packet. Mark is written to a field in 217 * extended CQ. RSS HASH is preserved. 218 */ 219 FMOP_EXT_MARK, 220 /* 221 * Apply internal tag which can be matched in subsequent 222 * stages or hairpin. 223 */ 224 FMOP_TAG, 225 /* Hairpin packet from EG -> IG */ 226 FMOP_EG_HAIRPIN, 227 /* Hairpin packet from IG -> EG */ 228 FMOP_IG_HAIRPIN, 229 /* Encap with VXLAN and inner VLAN from metadata. */ 230 FMOP_ENCAP_IVLAN, 231 /* Encap, no inner VLAN. */ 232 FMOP_ENCAP_NOIVLAN, 233 /* Encap, add inner VLAN if present. */ 234 FMOP_ENCAP, 235 /* Set outer VLAN. */ 236 FMOP_SET_OVLAN, 237 /* Decap when vlan_strip is off */ 238 FMOP_DECAP_NOSTRIP, 239 /* Decap and strip VLAN */ 240 FMOP_DECAP_STRIP, 241 /* Remove outer VLAN */ 242 FMOP_POP_VLAN, 243 /* Set Egress port */ 244 FMOP_SET_EGPORT, 245 /* Steer to an RQ without entering EMIT state */ 246 FMOP_RQ_STEER_ONLY, 247 /* Set VLAN when replicating encapped packets */ 248 FMOP_SET_ENCAP_VLAN, 249 /* Enter EMIT state */ 250 FMOP_EMIT, 251 /* Enter MODIFY state */ 252 FMOP_MODIFY, 253 FMOP_OP_MAX, 254 }; 255 256 /* 257 * Action operation. 258 * Complex actions are achieved by a series of "transform operations" 259 * We can have complex transform operations like "decap" or "vxlan 260 * encap" and also simple ops like insert this data, add PACKET_LEN to 261 * this address, etc. 262 */ 263 struct __rte_packed_begin fm_action_op { 264 uint32_t fa_op; /* FMOP flags */ 265 266 union __rte_packed_begin { 267 struct __rte_packed_begin { 268 uint8_t len1_offset; 269 uint8_t len1_delta; 270 uint8_t len2_offset; 271 uint8_t len2_delta; 272 uint16_t outer_vlan; 273 uint8_t template_offset; 274 uint8_t template_len; 275 } __rte_packed_end encap; 276 struct __rte_packed_begin { 277 uint16_t rq_index; 278 uint16_t rq_count; 279 uint64_t vnic_handle; 280 } __rte_packed_end rq_steer; 281 struct __rte_packed_begin { 282 uint16_t vlan; 283 } __rte_packed_end ovlan; 284 struct __rte_packed_begin { 285 uint16_t vlan; 286 } __rte_packed_end set_encap_vlan; 287 struct __rte_packed_begin { 288 uint16_t mark; 289 } __rte_packed_end mark; 290 struct __rte_packed_begin { 291 uint32_t ext_mark; 292 } __rte_packed_end ext_mark; 293 struct __rte_packed_begin { 294 uint8_t tag; 295 } __rte_packed_end tag; 296 struct __rte_packed_begin { 297 uint64_t handle; 298 } __rte_packed_end exact; 299 struct __rte_packed_begin { 300 uint32_t egport; 301 } __rte_packed_end set_egport; 302 } __rte_packed_end; 303 } __rte_packed_end; 304 305 #define FM_ACTION_OP_MAX 64 306 #define FM_ACTION_DATA_MAX 96 307 308 /* 309 * Action is a series of action operations applied to matched 310 * packet. FMA (flowman action). 311 */ 312 struct __rte_packed_begin fm_action { 313 struct fm_action_op fma_action_ops[FM_ACTION_OP_MAX]; 314 uint8_t fma_data[FM_ACTION_DATA_MAX]; 315 } __rte_packed_end; 316 317 /* Match entry flags. FMEF (flow match entry flag) */ 318 #define FMEF_COUNTER 0x0001 /* counter index is valid */ 319 320 /* FEM (flow exact match) entry */ 321 struct __rte_packed_begin fm_exact_match_entry { 322 struct fm_key_template fem_data; /* Match data. Mask is per table */ 323 uint32_t fem_flags; /* FMEF_xxx */ 324 uint64_t fem_action; /* Action handle */ 325 uint32_t fem_counter; /* Counter index */ 326 } __rte_packed_end; 327 328 /* FTM (flow TCAM match) entry */ 329 struct __rte_packed_begin fm_tcam_match_entry { 330 struct fm_key_template ftm_mask; /* Key mask */ 331 struct fm_key_template ftm_data; /* Match data */ 332 uint32_t ftm_flags; /* FMEF_xxx */ 333 uint32_t ftm_position; /* Entry position */ 334 uint64_t ftm_action; /* Action handle */ 335 uint32_t ftm_counter; /* Counter index */ 336 } __rte_packed_end; 337 338 /* Match directions */ 339 enum { 340 FM_INGRESS, 341 FM_EGRESS, 342 FM_DIR_CNT 343 }; 344 345 /* Last stage ID, independent of the number of stages in hardware */ 346 #define FM_STAGE_LAST 0xff 347 348 /* Hash based exact match table. FET (flow exact match table) */ 349 struct __rte_packed_begin fm_exact_match_table { 350 uint8_t fet_direction; /* FM_INGRESS or EGRESS*/ 351 uint8_t fet_stage; 352 uint8_t pad[2]; 353 uint32_t fet_max_entries; 354 uint64_t fet_dflt_action; 355 struct fm_key_template fet_key; 356 } __rte_packed_end; 357 358 /* TCAM based match table. FTT (flow TCAM match table) */ 359 struct __rte_packed_begin fm_tcam_match_table { 360 uint8_t ftt_direction; 361 uint8_t ftt_stage; 362 uint8_t pad[2]; 363 uint32_t ftt_max_entries; 364 } __rte_packed_end; 365 366 struct __rte_packed_begin fm_counter_counts { 367 uint64_t fcc_packets; 368 uint64_t fcc_bytes; 369 } __rte_packed_end; 370 371 /* 372 * Return structure for FM_INFO_QUERY devcmd 373 */ 374 #define FM_VERSION 1 /* This header file is for version 1 */ 375 376 struct __rte_packed_begin fm_info { 377 uint64_t fm_op_mask; /* Bitmask of action supported ops */ 378 uint64_t fm_current_ts; /* Current VIC timestamp */ 379 uint64_t fm_clock_freq; /* Timestamp clock frequency */ 380 uint16_t fm_max_ops; /* Max ops in an action */ 381 uint8_t fm_stages; /* Number of match-action stages */ 382 uint8_t pad[5]; 383 uint32_t fm_counter_count; /* Number of allocated counters */ 384 } __rte_packed_end; 385 386 #endif /* _VNIC_FLOWMAN_H_ */ 387