1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2018 Mellanox Technologies, Ltd 3 */ 4 5 #ifndef RTE_PMD_MLX5_FLOW_H_ 6 #define RTE_PMD_MLX5_FLOW_H_ 7 8 #include <stdalign.h> 9 #include <stdint.h> 10 #include <string.h> 11 #include <sys/queue.h> 12 13 #include <rte_alarm.h> 14 #include <rte_mtr.h> 15 16 #include <mlx5_glue.h> 17 #include <mlx5_prm.h> 18 19 #include "mlx5.h" 20 #include "hws/mlx5dr.h" 21 22 /* E-Switch Manager port, used for rte_flow_item_port_id. */ 23 #define MLX5_PORT_ESW_MGR UINT32_MAX 24 25 /* E-Switch Manager port, used for rte_flow_item_ethdev. */ 26 #define MLX5_REPRESENTED_PORT_ESW_MGR UINT16_MAX 27 28 /* Private rte flow items. */ 29 enum mlx5_rte_flow_item_type { 30 MLX5_RTE_FLOW_ITEM_TYPE_END = INT_MIN, 31 MLX5_RTE_FLOW_ITEM_TYPE_TAG, 32 MLX5_RTE_FLOW_ITEM_TYPE_SQ, 33 MLX5_RTE_FLOW_ITEM_TYPE_VLAN, 34 MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL, 35 }; 36 37 /* Private (internal) rte flow actions. */ 38 enum mlx5_rte_flow_action_type { 39 MLX5_RTE_FLOW_ACTION_TYPE_END = INT_MIN, 40 MLX5_RTE_FLOW_ACTION_TYPE_TAG, 41 MLX5_RTE_FLOW_ACTION_TYPE_MARK, 42 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG, 43 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS, 44 MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET, 45 MLX5_RTE_FLOW_ACTION_TYPE_AGE, 46 MLX5_RTE_FLOW_ACTION_TYPE_COUNT, 47 MLX5_RTE_FLOW_ACTION_TYPE_JUMP, 48 MLX5_RTE_FLOW_ACTION_TYPE_RSS, 49 MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK, 50 }; 51 52 /* Private (internal) Field IDs for MODIFY_FIELD action. */ 53 enum mlx5_rte_flow_field_id { 54 MLX5_RTE_FLOW_FIELD_END = INT_MIN, 55 MLX5_RTE_FLOW_FIELD_META_REG, 56 }; 57 58 #define MLX5_INDIRECT_ACTION_TYPE_OFFSET 29 59 60 #define MLX5_INDIRECT_ACTION_TYPE_GET(handle) \ 61 (((uint32_t)(uintptr_t)(handle)) >> MLX5_INDIRECT_ACTION_TYPE_OFFSET) 62 63 #define MLX5_INDIRECT_ACTION_IDX_GET(handle) \ 64 (((uint32_t)(uintptr_t)(handle)) & \ 65 ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1)) 66 67 enum { 68 MLX5_INDIRECT_ACTION_TYPE_RSS, 69 MLX5_INDIRECT_ACTION_TYPE_AGE, 70 MLX5_INDIRECT_ACTION_TYPE_COUNT, 71 MLX5_INDIRECT_ACTION_TYPE_CT, 72 MLX5_INDIRECT_ACTION_TYPE_METER_MARK, 73 }; 74 75 /* Now, the maximal ports will be supported is 16, action number is 32M. */ 76 #define MLX5_INDIRECT_ACT_CT_MAX_PORT 0x10 77 78 #define MLX5_INDIRECT_ACT_CT_OWNER_SHIFT 22 79 #define MLX5_INDIRECT_ACT_CT_OWNER_MASK (MLX5_INDIRECT_ACT_CT_MAX_PORT - 1) 80 81 /* 29-31: type, 25-28: owner port, 0-24: index */ 82 #define MLX5_INDIRECT_ACT_CT_GEN_IDX(owner, index) \ 83 ((MLX5_INDIRECT_ACTION_TYPE_CT << MLX5_INDIRECT_ACTION_TYPE_OFFSET) | \ 84 (((owner) & MLX5_INDIRECT_ACT_CT_OWNER_MASK) << \ 85 MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) | (index)) 86 87 #define MLX5_INDIRECT_ACT_CT_GET_OWNER(index) \ 88 (((index) >> MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) & \ 89 MLX5_INDIRECT_ACT_CT_OWNER_MASK) 90 91 #define MLX5_INDIRECT_ACT_CT_GET_IDX(index) \ 92 ((index) & ((1 << MLX5_INDIRECT_ACT_CT_OWNER_SHIFT) - 1)) 93 94 #define MLX5_ACTION_CTX_CT_GET_IDX MLX5_INDIRECT_ACT_CT_GET_IDX 95 #define MLX5_ACTION_CTX_CT_GET_OWNER MLX5_INDIRECT_ACT_CT_GET_OWNER 96 #define MLX5_ACTION_CTX_CT_GEN_IDX MLX5_INDIRECT_ACT_CT_GEN_IDX 97 98 /* Matches on selected register. */ 99 struct mlx5_rte_flow_item_tag { 100 enum modify_reg id; 101 uint32_t data; 102 }; 103 104 /* Modify selected register. */ 105 struct mlx5_rte_flow_action_set_tag { 106 enum modify_reg id; 107 uint8_t offset; 108 uint8_t length; 109 uint32_t data; 110 }; 111 112 struct mlx5_flow_action_copy_mreg { 113 enum modify_reg dst; 114 enum modify_reg src; 115 }; 116 117 /* Matches on source queue. */ 118 struct mlx5_rte_flow_item_sq { 119 uint32_t queue; /* DevX SQ number */ 120 }; 121 122 /* Feature name to allocate metadata register. */ 123 enum mlx5_feature_name { 124 MLX5_HAIRPIN_RX, 125 MLX5_HAIRPIN_TX, 126 MLX5_METADATA_RX, 127 MLX5_METADATA_TX, 128 MLX5_METADATA_FDB, 129 MLX5_FLOW_MARK, 130 MLX5_APP_TAG, 131 MLX5_COPY_MARK, 132 MLX5_MTR_COLOR, 133 MLX5_MTR_ID, 134 MLX5_ASO_FLOW_HIT, 135 MLX5_ASO_CONNTRACK, 136 MLX5_SAMPLE_ID, 137 }; 138 139 /* Default queue number. */ 140 #define MLX5_RSSQ_DEFAULT_NUM 16 141 142 #define MLX5_FLOW_LAYER_OUTER_L2 (1u << 0) 143 #define MLX5_FLOW_LAYER_OUTER_L3_IPV4 (1u << 1) 144 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6 (1u << 2) 145 #define MLX5_FLOW_LAYER_OUTER_L4_UDP (1u << 3) 146 #define MLX5_FLOW_LAYER_OUTER_L4_TCP (1u << 4) 147 #define MLX5_FLOW_LAYER_OUTER_VLAN (1u << 5) 148 149 /* Pattern inner Layer bits. */ 150 #define MLX5_FLOW_LAYER_INNER_L2 (1u << 6) 151 #define MLX5_FLOW_LAYER_INNER_L3_IPV4 (1u << 7) 152 #define MLX5_FLOW_LAYER_INNER_L3_IPV6 (1u << 8) 153 #define MLX5_FLOW_LAYER_INNER_L4_UDP (1u << 9) 154 #define MLX5_FLOW_LAYER_INNER_L4_TCP (1u << 10) 155 #define MLX5_FLOW_LAYER_INNER_VLAN (1u << 11) 156 157 /* Pattern tunnel Layer bits. */ 158 #define MLX5_FLOW_LAYER_VXLAN (1u << 12) 159 #define MLX5_FLOW_LAYER_VXLAN_GPE (1u << 13) 160 #define MLX5_FLOW_LAYER_GRE (1u << 14) 161 #define MLX5_FLOW_LAYER_MPLS (1u << 15) 162 /* List of tunnel Layer bits continued below. */ 163 164 /* General pattern items bits. */ 165 #define MLX5_FLOW_ITEM_METADATA (1u << 16) 166 #define MLX5_FLOW_ITEM_PORT_ID (1u << 17) 167 #define MLX5_FLOW_ITEM_TAG (1u << 18) 168 #define MLX5_FLOW_ITEM_MARK (1u << 19) 169 170 /* Pattern MISC bits. */ 171 #define MLX5_FLOW_LAYER_ICMP (1u << 20) 172 #define MLX5_FLOW_LAYER_ICMP6 (1u << 21) 173 #define MLX5_FLOW_LAYER_GRE_KEY (1u << 22) 174 175 /* Pattern tunnel Layer bits (continued). */ 176 #define MLX5_FLOW_LAYER_IPIP (1u << 23) 177 #define MLX5_FLOW_LAYER_IPV6_ENCAP (1u << 24) 178 #define MLX5_FLOW_LAYER_NVGRE (1u << 25) 179 #define MLX5_FLOW_LAYER_GENEVE (1u << 26) 180 181 /* Queue items. */ 182 #define MLX5_FLOW_ITEM_SQ (1u << 27) 183 184 /* Pattern tunnel Layer bits (continued). */ 185 #define MLX5_FLOW_LAYER_GTP (1u << 28) 186 187 /* Pattern eCPRI Layer bit. */ 188 #define MLX5_FLOW_LAYER_ECPRI (UINT64_C(1) << 29) 189 190 /* IPv6 Fragment Extension Header bit. */ 191 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT (1u << 30) 192 #define MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT (1u << 31) 193 194 /* Pattern tunnel Layer bits (continued). */ 195 #define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32) 196 #define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33) 197 198 /* INTEGRITY item bits */ 199 #define MLX5_FLOW_ITEM_OUTER_INTEGRITY (UINT64_C(1) << 34) 200 #define MLX5_FLOW_ITEM_INNER_INTEGRITY (UINT64_C(1) << 35) 201 #define MLX5_FLOW_ITEM_INTEGRITY \ 202 (MLX5_FLOW_ITEM_OUTER_INTEGRITY | MLX5_FLOW_ITEM_INNER_INTEGRITY) 203 204 /* Conntrack item. */ 205 #define MLX5_FLOW_LAYER_ASO_CT (UINT64_C(1) << 36) 206 207 /* Flex item */ 208 #define MLX5_FLOW_ITEM_OUTER_FLEX (UINT64_C(1) << 37) 209 #define MLX5_FLOW_ITEM_INNER_FLEX (UINT64_C(1) << 38) 210 #define MLX5_FLOW_ITEM_FLEX_TUNNEL (UINT64_C(1) << 39) 211 212 /* ESP item */ 213 #define MLX5_FLOW_ITEM_ESP (UINT64_C(1) << 40) 214 215 /* Port Representor/Represented Port item */ 216 #define MLX5_FLOW_ITEM_PORT_REPRESENTOR (UINT64_C(1) << 41) 217 #define MLX5_FLOW_ITEM_REPRESENTED_PORT (UINT64_C(1) << 42) 218 219 /* Meter color item */ 220 #define MLX5_FLOW_ITEM_METER_COLOR (UINT64_C(1) << 44) 221 222 /* Outer Masks. */ 223 #define MLX5_FLOW_LAYER_OUTER_L3 \ 224 (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6) 225 #define MLX5_FLOW_LAYER_OUTER_L4 \ 226 (MLX5_FLOW_LAYER_OUTER_L4_UDP | MLX5_FLOW_LAYER_OUTER_L4_TCP) 227 #define MLX5_FLOW_LAYER_OUTER \ 228 (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_OUTER_L3 | \ 229 MLX5_FLOW_LAYER_OUTER_L4) 230 231 /* Tunnel Masks. */ 232 #define MLX5_FLOW_LAYER_TUNNEL \ 233 (MLX5_FLOW_LAYER_VXLAN | MLX5_FLOW_LAYER_VXLAN_GPE | \ 234 MLX5_FLOW_LAYER_GRE | MLX5_FLOW_LAYER_NVGRE | MLX5_FLOW_LAYER_MPLS | \ 235 MLX5_FLOW_LAYER_IPIP | MLX5_FLOW_LAYER_IPV6_ENCAP | \ 236 MLX5_FLOW_LAYER_GENEVE | MLX5_FLOW_LAYER_GTP | \ 237 MLX5_FLOW_ITEM_FLEX_TUNNEL) 238 239 /* Inner Masks. */ 240 #define MLX5_FLOW_LAYER_INNER_L3 \ 241 (MLX5_FLOW_LAYER_INNER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV6) 242 #define MLX5_FLOW_LAYER_INNER_L4 \ 243 (MLX5_FLOW_LAYER_INNER_L4_UDP | MLX5_FLOW_LAYER_INNER_L4_TCP) 244 #define MLX5_FLOW_LAYER_INNER \ 245 (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3 | \ 246 MLX5_FLOW_LAYER_INNER_L4) 247 248 /* Layer Masks. */ 249 #define MLX5_FLOW_LAYER_L2 \ 250 (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_INNER_L2) 251 #define MLX5_FLOW_LAYER_L3_IPV4 \ 252 (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV4) 253 #define MLX5_FLOW_LAYER_L3_IPV6 \ 254 (MLX5_FLOW_LAYER_OUTER_L3_IPV6 | MLX5_FLOW_LAYER_INNER_L3_IPV6) 255 #define MLX5_FLOW_LAYER_L3 \ 256 (MLX5_FLOW_LAYER_L3_IPV4 | MLX5_FLOW_LAYER_L3_IPV6) 257 #define MLX5_FLOW_LAYER_L4 \ 258 (MLX5_FLOW_LAYER_OUTER_L4 | MLX5_FLOW_LAYER_INNER_L4) 259 260 /* Actions */ 261 #define MLX5_FLOW_ACTION_DROP (1ull << 0) 262 #define MLX5_FLOW_ACTION_QUEUE (1ull << 1) 263 #define MLX5_FLOW_ACTION_RSS (1ull << 2) 264 #define MLX5_FLOW_ACTION_FLAG (1ull << 3) 265 #define MLX5_FLOW_ACTION_MARK (1ull << 4) 266 #define MLX5_FLOW_ACTION_COUNT (1ull << 5) 267 #define MLX5_FLOW_ACTION_PORT_ID (1ull << 6) 268 #define MLX5_FLOW_ACTION_OF_POP_VLAN (1ull << 7) 269 #define MLX5_FLOW_ACTION_OF_PUSH_VLAN (1ull << 8) 270 #define MLX5_FLOW_ACTION_OF_SET_VLAN_VID (1ull << 9) 271 #define MLX5_FLOW_ACTION_OF_SET_VLAN_PCP (1ull << 10) 272 #define MLX5_FLOW_ACTION_SET_IPV4_SRC (1ull << 11) 273 #define MLX5_FLOW_ACTION_SET_IPV4_DST (1ull << 12) 274 #define MLX5_FLOW_ACTION_SET_IPV6_SRC (1ull << 13) 275 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1ull << 14) 276 #define MLX5_FLOW_ACTION_SET_TP_SRC (1ull << 15) 277 #define MLX5_FLOW_ACTION_SET_TP_DST (1ull << 16) 278 #define MLX5_FLOW_ACTION_JUMP (1ull << 17) 279 #define MLX5_FLOW_ACTION_SET_TTL (1ull << 18) 280 #define MLX5_FLOW_ACTION_DEC_TTL (1ull << 19) 281 #define MLX5_FLOW_ACTION_SET_MAC_SRC (1ull << 20) 282 #define MLX5_FLOW_ACTION_SET_MAC_DST (1ull << 21) 283 #define MLX5_FLOW_ACTION_ENCAP (1ull << 22) 284 #define MLX5_FLOW_ACTION_DECAP (1ull << 23) 285 #define MLX5_FLOW_ACTION_INC_TCP_SEQ (1ull << 24) 286 #define MLX5_FLOW_ACTION_DEC_TCP_SEQ (1ull << 25) 287 #define MLX5_FLOW_ACTION_INC_TCP_ACK (1ull << 26) 288 #define MLX5_FLOW_ACTION_DEC_TCP_ACK (1ull << 27) 289 #define MLX5_FLOW_ACTION_SET_TAG (1ull << 28) 290 #define MLX5_FLOW_ACTION_MARK_EXT (1ull << 29) 291 #define MLX5_FLOW_ACTION_SET_META (1ull << 30) 292 #define MLX5_FLOW_ACTION_METER (1ull << 31) 293 #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32) 294 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33) 295 #define MLX5_FLOW_ACTION_AGE (1ull << 34) 296 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) 297 #define MLX5_FLOW_ACTION_SAMPLE (1ull << 36) 298 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37) 299 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38) 300 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39) 301 #define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40) 302 #define MLX5_FLOW_ACTION_CT (1ull << 41) 303 #define MLX5_FLOW_ACTION_SEND_TO_KERNEL (1ull << 42) 304 #define MLX5_FLOW_ACTION_INDIRECT_COUNT (1ull << 43) 305 #define MLX5_FLOW_ACTION_INDIRECT_AGE (1ull << 44) 306 307 #define MLX5_FLOW_DROP_INCLUSIVE_ACTIONS \ 308 (MLX5_FLOW_ACTION_COUNT | MLX5_FLOW_ACTION_SAMPLE | MLX5_FLOW_ACTION_AGE) 309 310 #define MLX5_FLOW_FATE_ACTIONS \ 311 (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \ 312 MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \ 313 MLX5_FLOW_ACTION_DEFAULT_MISS | \ 314 MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY | \ 315 MLX5_FLOW_ACTION_SEND_TO_KERNEL) 316 317 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \ 318 (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \ 319 MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY) 320 321 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \ 322 MLX5_FLOW_ACTION_SET_IPV4_DST | \ 323 MLX5_FLOW_ACTION_SET_IPV6_SRC | \ 324 MLX5_FLOW_ACTION_SET_IPV6_DST | \ 325 MLX5_FLOW_ACTION_SET_TP_SRC | \ 326 MLX5_FLOW_ACTION_SET_TP_DST | \ 327 MLX5_FLOW_ACTION_SET_TTL | \ 328 MLX5_FLOW_ACTION_DEC_TTL | \ 329 MLX5_FLOW_ACTION_SET_MAC_SRC | \ 330 MLX5_FLOW_ACTION_SET_MAC_DST | \ 331 MLX5_FLOW_ACTION_INC_TCP_SEQ | \ 332 MLX5_FLOW_ACTION_DEC_TCP_SEQ | \ 333 MLX5_FLOW_ACTION_INC_TCP_ACK | \ 334 MLX5_FLOW_ACTION_DEC_TCP_ACK | \ 335 MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \ 336 MLX5_FLOW_ACTION_SET_TAG | \ 337 MLX5_FLOW_ACTION_MARK_EXT | \ 338 MLX5_FLOW_ACTION_SET_META | \ 339 MLX5_FLOW_ACTION_SET_IPV4_DSCP | \ 340 MLX5_FLOW_ACTION_SET_IPV6_DSCP | \ 341 MLX5_FLOW_ACTION_MODIFY_FIELD) 342 343 #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \ 344 MLX5_FLOW_ACTION_OF_PUSH_VLAN) 345 346 #define MLX5_FLOW_XCAP_ACTIONS (MLX5_FLOW_ACTION_ENCAP | MLX5_FLOW_ACTION_DECAP) 347 348 #ifndef IPPROTO_MPLS 349 #define IPPROTO_MPLS 137 350 #endif 351 352 /* UDP port number for MPLS */ 353 #define MLX5_UDP_PORT_MPLS 6635 354 355 /* UDP port numbers for VxLAN. */ 356 #define MLX5_UDP_PORT_VXLAN 4789 357 #define MLX5_UDP_PORT_VXLAN_GPE 4790 358 359 /* UDP port numbers for GENEVE. */ 360 #define MLX5_UDP_PORT_GENEVE 6081 361 362 /* Lowest priority indicator. */ 363 #define MLX5_FLOW_LOWEST_PRIO_INDICATOR ((uint32_t)-1) 364 365 /* 366 * Max priority for ingress\egress flow groups 367 * greater than 0 and for any transfer flow group. 368 * From user configation: 0 - 21843. 369 */ 370 #define MLX5_NON_ROOT_FLOW_MAX_PRIO (21843 + 1) 371 372 /* 373 * Number of sub priorities. 374 * For each kind of pattern matching i.e. L2, L3, L4 to have a correct 375 * matching on the NIC (firmware dependent) L4 most have the higher priority 376 * followed by L3 and ending with L2. 377 */ 378 #define MLX5_PRIORITY_MAP_L2 2 379 #define MLX5_PRIORITY_MAP_L3 1 380 #define MLX5_PRIORITY_MAP_L4 0 381 #define MLX5_PRIORITY_MAP_MAX 3 382 383 /* Valid layer type for IPV4 RSS. */ 384 #define MLX5_IPV4_LAYER_TYPES \ 385 (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 | \ 386 RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 387 RTE_ETH_RSS_NONFRAG_IPV4_OTHER) 388 389 /* IBV hash source bits for IPV4. */ 390 #define MLX5_IPV4_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4) 391 392 /* Valid layer type for IPV6 RSS. */ 393 #define MLX5_IPV6_LAYER_TYPES \ 394 (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 395 RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_IPV6_EX | RTE_ETH_RSS_IPV6_TCP_EX | \ 396 RTE_ETH_RSS_IPV6_UDP_EX | RTE_ETH_RSS_NONFRAG_IPV6_OTHER) 397 398 /* IBV hash source bits for IPV6. */ 399 #define MLX5_IPV6_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6) 400 401 /* IBV hash bits for L3 SRC. */ 402 #define MLX5_L3_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_SRC_IPV6) 403 404 /* IBV hash bits for L3 DST. */ 405 #define MLX5_L3_DST_IBV_RX_HASH (IBV_RX_HASH_DST_IPV4 | IBV_RX_HASH_DST_IPV6) 406 407 /* IBV hash bits for TCP. */ 408 #define MLX5_TCP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \ 409 IBV_RX_HASH_DST_PORT_TCP) 410 411 /* IBV hash bits for UDP. */ 412 #define MLX5_UDP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_UDP | \ 413 IBV_RX_HASH_DST_PORT_UDP) 414 415 /* IBV hash bits for L4 SRC. */ 416 #define MLX5_L4_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \ 417 IBV_RX_HASH_SRC_PORT_UDP) 418 419 /* IBV hash bits for L4 DST. */ 420 #define MLX5_L4_DST_IBV_RX_HASH (IBV_RX_HASH_DST_PORT_TCP | \ 421 IBV_RX_HASH_DST_PORT_UDP) 422 423 /* Geneve header first 16Bit */ 424 #define MLX5_GENEVE_VER_MASK 0x3 425 #define MLX5_GENEVE_VER_SHIFT 14 426 #define MLX5_GENEVE_VER_VAL(a) \ 427 (((a) >> (MLX5_GENEVE_VER_SHIFT)) & (MLX5_GENEVE_VER_MASK)) 428 #define MLX5_GENEVE_OPTLEN_MASK 0x3F 429 #define MLX5_GENEVE_OPTLEN_SHIFT 8 430 #define MLX5_GENEVE_OPTLEN_VAL(a) \ 431 (((a) >> (MLX5_GENEVE_OPTLEN_SHIFT)) & (MLX5_GENEVE_OPTLEN_MASK)) 432 #define MLX5_GENEVE_OAMF_MASK 0x1 433 #define MLX5_GENEVE_OAMF_SHIFT 7 434 #define MLX5_GENEVE_OAMF_VAL(a) \ 435 (((a) >> (MLX5_GENEVE_OAMF_SHIFT)) & (MLX5_GENEVE_OAMF_MASK)) 436 #define MLX5_GENEVE_CRITO_MASK 0x1 437 #define MLX5_GENEVE_CRITO_SHIFT 6 438 #define MLX5_GENEVE_CRITO_VAL(a) \ 439 (((a) >> (MLX5_GENEVE_CRITO_SHIFT)) & (MLX5_GENEVE_CRITO_MASK)) 440 #define MLX5_GENEVE_RSVD_MASK 0x3F 441 #define MLX5_GENEVE_RSVD_VAL(a) ((a) & (MLX5_GENEVE_RSVD_MASK)) 442 /* 443 * The length of the Geneve options fields, expressed in four byte multiples, 444 * not including the eight byte fixed tunnel. 445 */ 446 #define MLX5_GENEVE_OPT_LEN_0 14 447 #define MLX5_GENEVE_OPT_LEN_1 63 448 449 #define MLX5_ENCAPSULATION_DECISION_SIZE (sizeof(struct rte_ether_hdr) + \ 450 sizeof(struct rte_ipv4_hdr)) 451 /* GTP extension header flag. */ 452 #define MLX5_GTP_EXT_HEADER_FLAG 4 453 454 /* GTP extension header PDU type shift. */ 455 #define MLX5_GTP_PDU_TYPE_SHIFT(a) ((a) << 4) 456 457 /* IPv4 fragment_offset field contains relevant data in bits 2 to 15. */ 458 #define MLX5_IPV4_FRAG_OFFSET_MASK \ 459 (RTE_IPV4_HDR_OFFSET_MASK | RTE_IPV4_HDR_MF_FLAG) 460 461 /* Specific item's fields can accept a range of values (using spec and last). */ 462 #define MLX5_ITEM_RANGE_NOT_ACCEPTED false 463 #define MLX5_ITEM_RANGE_ACCEPTED true 464 465 /* Software header modify action numbers of a flow. */ 466 #define MLX5_ACT_NUM_MDF_IPV4 1 467 #define MLX5_ACT_NUM_MDF_IPV6 4 468 #define MLX5_ACT_NUM_MDF_MAC 2 469 #define MLX5_ACT_NUM_MDF_VID 1 470 #define MLX5_ACT_NUM_MDF_PORT 1 471 #define MLX5_ACT_NUM_MDF_TTL 1 472 #define MLX5_ACT_NUM_DEC_TTL MLX5_ACT_NUM_MDF_TTL 473 #define MLX5_ACT_NUM_MDF_TCPSEQ 1 474 #define MLX5_ACT_NUM_MDF_TCPACK 1 475 #define MLX5_ACT_NUM_SET_REG 1 476 #define MLX5_ACT_NUM_SET_TAG 1 477 #define MLX5_ACT_NUM_CPY_MREG MLX5_ACT_NUM_SET_TAG 478 #define MLX5_ACT_NUM_SET_MARK MLX5_ACT_NUM_SET_TAG 479 #define MLX5_ACT_NUM_SET_META MLX5_ACT_NUM_SET_TAG 480 #define MLX5_ACT_NUM_SET_DSCP 1 481 482 /* Maximum number of fields to modify in MODIFY_FIELD */ 483 #define MLX5_ACT_MAX_MOD_FIELDS 5 484 485 /* Syndrome bits definition for connection tracking. */ 486 #define MLX5_CT_SYNDROME_VALID (0x0 << 6) 487 #define MLX5_CT_SYNDROME_INVALID (0x1 << 6) 488 #define MLX5_CT_SYNDROME_TRAP (0x2 << 6) 489 #define MLX5_CT_SYNDROME_STATE_CHANGE (0x1 << 1) 490 #define MLX5_CT_SYNDROME_BAD_PACKET (0x1 << 0) 491 492 enum mlx5_flow_drv_type { 493 MLX5_FLOW_TYPE_MIN, 494 MLX5_FLOW_TYPE_DV, 495 MLX5_FLOW_TYPE_VERBS, 496 MLX5_FLOW_TYPE_HW, 497 MLX5_FLOW_TYPE_MAX, 498 }; 499 500 /* Fate action type. */ 501 enum mlx5_flow_fate_type { 502 MLX5_FLOW_FATE_NONE, /* Egress flow. */ 503 MLX5_FLOW_FATE_QUEUE, 504 MLX5_FLOW_FATE_JUMP, 505 MLX5_FLOW_FATE_PORT_ID, 506 MLX5_FLOW_FATE_DROP, 507 MLX5_FLOW_FATE_DEFAULT_MISS, 508 MLX5_FLOW_FATE_SHARED_RSS, 509 MLX5_FLOW_FATE_MTR, 510 MLX5_FLOW_FATE_SEND_TO_KERNEL, 511 MLX5_FLOW_FATE_MAX, 512 }; 513 514 /* Matcher PRM representation */ 515 struct mlx5_flow_dv_match_params { 516 size_t size; 517 /**< Size of match value. Do NOT split size and key! */ 518 uint32_t buf[MLX5_ST_SZ_DW(fte_match_param)]; 519 /**< Matcher value. This value is used as the mask or as a key. */ 520 }; 521 522 /* Matcher structure. */ 523 struct mlx5_flow_dv_matcher { 524 struct mlx5_list_entry entry; /**< Pointer to the next element. */ 525 struct mlx5_flow_tbl_resource *tbl; 526 /**< Pointer to the table(group) the matcher associated with. */ 527 void *matcher_object; /**< Pointer to DV matcher */ 528 uint16_t crc; /**< CRC of key. */ 529 uint16_t priority; /**< Priority of matcher. */ 530 struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */ 531 }; 532 533 #define MLX5_ENCAP_MAX_LEN 132 534 535 /* Encap/decap resource structure. */ 536 struct mlx5_flow_dv_encap_decap_resource { 537 struct mlx5_list_entry entry; 538 /* Pointer to next element. */ 539 uint32_t refcnt; /**< Reference counter. */ 540 void *action; 541 /**< Encap/decap action object. */ 542 uint8_t buf[MLX5_ENCAP_MAX_LEN]; 543 size_t size; 544 uint8_t reformat_type; 545 uint8_t ft_type; 546 uint64_t flags; /**< Flags for RDMA API. */ 547 uint32_t idx; /**< Index for the index memory pool. */ 548 }; 549 550 /* Tag resource structure. */ 551 struct mlx5_flow_dv_tag_resource { 552 struct mlx5_list_entry entry; 553 /**< hash list entry for tag resource, tag value as the key. */ 554 void *action; 555 /**< Tag action object. */ 556 uint32_t refcnt; /**< Reference counter. */ 557 uint32_t idx; /**< Index for the index memory pool. */ 558 uint32_t tag_id; /**< Tag ID. */ 559 }; 560 561 /* Modify resource structure */ 562 struct mlx5_flow_dv_modify_hdr_resource { 563 struct mlx5_list_entry entry; 564 void *action; /**< Modify header action object. */ 565 uint32_t idx; 566 /* Key area for hash list matching: */ 567 uint8_t ft_type; /**< Flow table type, Rx or Tx. */ 568 uint8_t actions_num; /**< Number of modification actions. */ 569 bool root; /**< Whether action is in root table. */ 570 struct mlx5_modification_cmd actions[]; 571 /**< Modification actions. */ 572 } __rte_packed; 573 574 /* Modify resource key of the hash organization. */ 575 union mlx5_flow_modify_hdr_key { 576 struct { 577 uint32_t ft_type:8; /**< Flow table type, Rx or Tx. */ 578 uint32_t actions_num:5; /**< Number of modification actions. */ 579 uint32_t group:19; /**< Flow group id. */ 580 uint32_t cksum; /**< Actions check sum. */ 581 }; 582 uint64_t v64; /**< full 64bits value of key */ 583 }; 584 585 /* Jump action resource structure. */ 586 struct mlx5_flow_dv_jump_tbl_resource { 587 void *action; /**< Pointer to the rdma core action. */ 588 }; 589 590 /* Port ID resource structure. */ 591 struct mlx5_flow_dv_port_id_action_resource { 592 struct mlx5_list_entry entry; 593 void *action; /**< Action object. */ 594 uint32_t port_id; /**< Port ID value. */ 595 uint32_t idx; /**< Indexed pool memory index. */ 596 }; 597 598 /* Push VLAN action resource structure */ 599 struct mlx5_flow_dv_push_vlan_action_resource { 600 struct mlx5_list_entry entry; /* Cache entry. */ 601 void *action; /**< Action object. */ 602 uint8_t ft_type; /**< Flow table type, Rx, Tx or FDB. */ 603 rte_be32_t vlan_tag; /**< VLAN tag value. */ 604 uint32_t idx; /**< Indexed pool memory index. */ 605 }; 606 607 /* Metadata register copy table entry. */ 608 struct mlx5_flow_mreg_copy_resource { 609 /* 610 * Hash list entry for copy table. 611 * - Key is 32/64-bit MARK action ID. 612 * - MUST be the first entry. 613 */ 614 struct mlx5_list_entry hlist_ent; 615 LIST_ENTRY(mlx5_flow_mreg_copy_resource) next; 616 /* List entry for device flows. */ 617 uint32_t idx; 618 uint32_t rix_flow; /* Built flow for copy. */ 619 uint32_t mark_id; 620 }; 621 622 /* Table tunnel parameter. */ 623 struct mlx5_flow_tbl_tunnel_prm { 624 const struct mlx5_flow_tunnel *tunnel; 625 uint32_t group_id; 626 bool external; 627 }; 628 629 /* Table data structure of the hash organization. */ 630 struct mlx5_flow_tbl_data_entry { 631 struct mlx5_list_entry entry; 632 /**< hash list entry, 64-bits key inside. */ 633 struct mlx5_flow_tbl_resource tbl; 634 /**< flow table resource. */ 635 struct mlx5_list *matchers; 636 /**< matchers' header associated with the flow table. */ 637 struct mlx5_flow_dv_jump_tbl_resource jump; 638 /**< jump resource, at most one for each table created. */ 639 uint32_t idx; /**< index for the indexed mempool. */ 640 /**< tunnel offload */ 641 const struct mlx5_flow_tunnel *tunnel; 642 uint32_t group_id; 643 uint32_t external:1; 644 uint32_t tunnel_offload:1; /* Tunnel offload table or not. */ 645 uint32_t is_egress:1; /**< Egress table. */ 646 uint32_t is_transfer:1; /**< Transfer table. */ 647 uint32_t dummy:1; /**< DR table. */ 648 uint32_t id:22; /**< Table ID. */ 649 uint32_t reserve:5; /**< Reserved to future using. */ 650 uint32_t level; /**< Table level. */ 651 }; 652 653 /* Sub rdma-core actions list. */ 654 struct mlx5_flow_sub_actions_list { 655 uint32_t actions_num; /**< Number of sample actions. */ 656 uint64_t action_flags; 657 void *dr_queue_action; 658 void *dr_tag_action; 659 void *dr_cnt_action; 660 void *dr_port_id_action; 661 void *dr_encap_action; 662 void *dr_jump_action; 663 }; 664 665 /* Sample sub-actions resource list. */ 666 struct mlx5_flow_sub_actions_idx { 667 uint32_t rix_hrxq; /**< Hash Rx queue object index. */ 668 uint32_t rix_tag; /**< Index to the tag action. */ 669 uint32_t rix_port_id_action; /**< Index to port ID action resource. */ 670 uint32_t rix_encap_decap; /**< Index to encap/decap resource. */ 671 uint32_t rix_jump; /**< Index to the jump action resource. */ 672 }; 673 674 /* Sample action resource structure. */ 675 struct mlx5_flow_dv_sample_resource { 676 struct mlx5_list_entry entry; /**< Cache entry. */ 677 union { 678 void *verbs_action; /**< Verbs sample action object. */ 679 void **sub_actions; /**< Sample sub-action array. */ 680 }; 681 struct rte_eth_dev *dev; /**< Device registers the action. */ 682 uint32_t idx; /** Sample object index. */ 683 uint8_t ft_type; /** Flow Table Type */ 684 uint32_t ft_id; /** Flow Table Level */ 685 uint32_t ratio; /** Sample Ratio */ 686 uint64_t set_action; /** Restore reg_c0 value */ 687 void *normal_path_tbl; /** Flow Table pointer */ 688 struct mlx5_flow_sub_actions_idx sample_idx; 689 /**< Action index resources. */ 690 struct mlx5_flow_sub_actions_list sample_act; 691 /**< Action resources. */ 692 }; 693 694 #define MLX5_MAX_DEST_NUM 2 695 696 /* Destination array action resource structure. */ 697 struct mlx5_flow_dv_dest_array_resource { 698 struct mlx5_list_entry entry; /**< Cache entry. */ 699 uint32_t idx; /** Destination array action object index. */ 700 uint8_t ft_type; /** Flow Table Type */ 701 uint8_t num_of_dest; /**< Number of destination actions. */ 702 struct rte_eth_dev *dev; /**< Device registers the action. */ 703 void *action; /**< Pointer to the rdma core action. */ 704 struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM]; 705 /**< Action index resources. */ 706 struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM]; 707 /**< Action resources. */ 708 }; 709 710 /* PMD flow priority for tunnel */ 711 #define MLX5_TUNNEL_PRIO_GET(rss_desc) \ 712 ((rss_desc)->level >= 2 ? MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4) 713 714 715 /** Device flow handle structure for DV mode only. */ 716 struct mlx5_flow_handle_dv { 717 /* Flow DV api: */ 718 struct mlx5_flow_dv_matcher *matcher; /**< Cache to matcher. */ 719 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr; 720 /**< Pointer to modify header resource in cache. */ 721 uint32_t rix_encap_decap; 722 /**< Index to encap/decap resource in cache. */ 723 uint32_t rix_push_vlan; 724 /**< Index to push VLAN action resource in cache. */ 725 uint32_t rix_tag; 726 /**< Index to the tag action. */ 727 uint32_t rix_sample; 728 /**< Index to sample action resource in cache. */ 729 uint32_t rix_dest_array; 730 /**< Index to destination array resource in cache. */ 731 } __rte_packed; 732 733 /** Device flow handle structure: used both for creating & destroying. */ 734 struct mlx5_flow_handle { 735 SILIST_ENTRY(uint32_t)next; 736 struct mlx5_vf_vlan vf_vlan; /**< Structure for VF VLAN workaround. */ 737 /**< Index to next device flow handle. */ 738 uint64_t layers; 739 /**< Bit-fields of present layers, see MLX5_FLOW_LAYER_*. */ 740 void *drv_flow; /**< pointer to driver flow object. */ 741 uint32_t split_flow_id:27; /**< Sub flow unique match flow id. */ 742 uint32_t is_meter_flow_id:1; /**< Indicate if flow_id is for meter. */ 743 uint32_t fate_action:4; /**< Fate action type. */ 744 union { 745 uint32_t rix_hrxq; /**< Hash Rx queue object index. */ 746 uint32_t rix_jump; /**< Index to the jump action resource. */ 747 uint32_t rix_port_id_action; 748 /**< Index to port ID action resource. */ 749 uint32_t rix_fate; 750 /**< Generic value indicates the fate action. */ 751 uint32_t rix_default_fate; 752 /**< Indicates default miss fate action. */ 753 uint32_t rix_srss; 754 /**< Indicates shared RSS fate action. */ 755 }; 756 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 757 struct mlx5_flow_handle_dv dvh; 758 #endif 759 uint8_t flex_item; /**< referenced Flex Item bitmask. */ 760 } __rte_packed; 761 762 /* 763 * Size for Verbs device flow handle structure only. Do not use the DV only 764 * structure in Verbs. No DV flows attributes will be accessed. 765 * Macro offsetof() could also be used here. 766 */ 767 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 768 #define MLX5_FLOW_HANDLE_VERBS_SIZE \ 769 (sizeof(struct mlx5_flow_handle) - sizeof(struct mlx5_flow_handle_dv)) 770 #else 771 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle)) 772 #endif 773 774 /** Device flow structure only for DV flow creation. */ 775 struct mlx5_flow_dv_workspace { 776 uint32_t group; /**< The group index. */ 777 uint32_t table_id; /**< Flow table identifier. */ 778 uint8_t transfer; /**< 1 if the flow is E-Switch flow. */ 779 int actions_n; /**< number of actions. */ 780 void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; /**< Action list. */ 781 struct mlx5_flow_dv_encap_decap_resource *encap_decap; 782 /**< Pointer to encap/decap resource in cache. */ 783 struct mlx5_flow_dv_push_vlan_action_resource *push_vlan_res; 784 /**< Pointer to push VLAN action resource in cache. */ 785 struct mlx5_flow_dv_tag_resource *tag_resource; 786 /**< pointer to the tag action. */ 787 struct mlx5_flow_dv_port_id_action_resource *port_id_action; 788 /**< Pointer to port ID action resource. */ 789 struct mlx5_flow_dv_jump_tbl_resource *jump; 790 /**< Pointer to the jump action resource. */ 791 struct mlx5_flow_dv_match_params value; 792 /**< Holds the value that the packet is compared to. */ 793 struct mlx5_flow_dv_sample_resource *sample_res; 794 /**< Pointer to the sample action resource. */ 795 struct mlx5_flow_dv_dest_array_resource *dest_array_res; 796 /**< Pointer to the destination array resource. */ 797 }; 798 799 #ifdef HAVE_INFINIBAND_VERBS_H 800 /* 801 * Maximal Verbs flow specifications & actions size. 802 * Some elements are mutually exclusive, but enough space should be allocated. 803 * Tunnel cases: 1. Max 2 Ethernet + IP(v6 len > v4 len) + TCP/UDP headers. 804 * 2. One tunnel header (exception: GRE + MPLS), 805 * SPEC length: GRE == tunnel. 806 * Actions: 1. 1 Mark OR Flag. 807 * 2. 1 Drop (if any). 808 * 3. No limitation for counters, but it makes no sense to support too 809 * many counters in a single device flow. 810 */ 811 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT 812 #define MLX5_VERBS_MAX_SPEC_SIZE \ 813 ( \ 814 (2 * (sizeof(struct ibv_flow_spec_eth) + \ 815 sizeof(struct ibv_flow_spec_ipv6) + \ 816 sizeof(struct ibv_flow_spec_tcp_udp)) + \ 817 sizeof(struct ibv_flow_spec_gre) + \ 818 sizeof(struct ibv_flow_spec_mpls)) \ 819 ) 820 #else 821 #define MLX5_VERBS_MAX_SPEC_SIZE \ 822 ( \ 823 (2 * (sizeof(struct ibv_flow_spec_eth) + \ 824 sizeof(struct ibv_flow_spec_ipv6) + \ 825 sizeof(struct ibv_flow_spec_tcp_udp)) + \ 826 sizeof(struct ibv_flow_spec_tunnel)) \ 827 ) 828 #endif 829 830 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ 831 defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) 832 #define MLX5_VERBS_MAX_ACT_SIZE \ 833 ( \ 834 sizeof(struct ibv_flow_spec_action_tag) + \ 835 sizeof(struct ibv_flow_spec_action_drop) + \ 836 sizeof(struct ibv_flow_spec_counter_action) * 4 \ 837 ) 838 #else 839 #define MLX5_VERBS_MAX_ACT_SIZE \ 840 ( \ 841 sizeof(struct ibv_flow_spec_action_tag) + \ 842 sizeof(struct ibv_flow_spec_action_drop) \ 843 ) 844 #endif 845 846 #define MLX5_VERBS_MAX_SPEC_ACT_SIZE \ 847 (MLX5_VERBS_MAX_SPEC_SIZE + MLX5_VERBS_MAX_ACT_SIZE) 848 849 /** Device flow structure only for Verbs flow creation. */ 850 struct mlx5_flow_verbs_workspace { 851 unsigned int size; /**< Size of the attribute. */ 852 struct ibv_flow_attr attr; /**< Verbs flow attribute buffer. */ 853 uint8_t specs[MLX5_VERBS_MAX_SPEC_ACT_SIZE]; 854 /**< Specifications & actions buffer of verbs flow. */ 855 }; 856 #endif /* HAVE_INFINIBAND_VERBS_H */ 857 858 #define MLX5_SCALE_FLOW_GROUP_BIT 0 859 #define MLX5_SCALE_JUMP_FLOW_GROUP_BIT 1 860 861 /** Maximal number of device sub-flows supported. */ 862 #define MLX5_NUM_MAX_DEV_FLOWS 32 863 864 /** 865 * tunnel offload rules type 866 */ 867 enum mlx5_tof_rule_type { 868 MLX5_TUNNEL_OFFLOAD_NONE = 0, 869 MLX5_TUNNEL_OFFLOAD_SET_RULE, 870 MLX5_TUNNEL_OFFLOAD_MATCH_RULE, 871 MLX5_TUNNEL_OFFLOAD_MISS_RULE, 872 }; 873 874 /** Device flow structure. */ 875 __extension__ 876 struct mlx5_flow { 877 struct rte_flow *flow; /**< Pointer to the main flow. */ 878 uint32_t flow_idx; /**< The memory pool index to the main flow. */ 879 uint64_t hash_fields; /**< Hash Rx queue hash fields. */ 880 uint64_t act_flags; 881 /**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */ 882 bool external; /**< true if the flow is created external to PMD. */ 883 uint8_t ingress:1; /**< 1 if the flow is ingress. */ 884 uint8_t skip_scale:2; 885 /** 886 * Each Bit be set to 1 if Skip the scale the flow group with factor. 887 * If bit0 be set to 1, then skip the scale the original flow group; 888 * If bit1 be set to 1, then skip the scale the jump flow group if 889 * having jump action. 890 * 00: Enable scale in a flow, default value. 891 * 01: Skip scale the flow group with factor, enable scale the group 892 * of jump action. 893 * 10: Enable scale the group with factor, skip scale the group of 894 * jump action. 895 * 11: Skip scale the table with factor both for flow group and jump 896 * group. 897 */ 898 union { 899 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 900 struct mlx5_flow_dv_workspace dv; 901 #endif 902 #ifdef HAVE_INFINIBAND_VERBS_H 903 struct mlx5_flow_verbs_workspace verbs; 904 #endif 905 }; 906 struct mlx5_flow_handle *handle; 907 uint32_t handle_idx; /* Index of the mlx5 flow handle memory. */ 908 const struct mlx5_flow_tunnel *tunnel; 909 enum mlx5_tof_rule_type tof_type; 910 }; 911 912 /* Flow meter state. */ 913 #define MLX5_FLOW_METER_DISABLE 0 914 #define MLX5_FLOW_METER_ENABLE 1 915 916 #define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u 917 #define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u 918 919 #define MLX5_CT_POLL_WQE_CQE_TIMES MLX5_MTR_POLL_WQE_CQE_TIMES 920 921 #define MLX5_MAN_WIDTH 8 922 /* Legacy Meter parameter structure. */ 923 struct mlx5_legacy_flow_meter { 924 struct mlx5_flow_meter_info fm; 925 /* Must be the first in struct. */ 926 TAILQ_ENTRY(mlx5_legacy_flow_meter) next; 927 /**< Pointer to the next flow meter structure. */ 928 uint32_t idx; 929 /* Index to meter object. */ 930 }; 931 932 #define MLX5_MAX_TUNNELS 256 933 #define MLX5_TNL_MISS_RULE_PRIORITY 3 934 #define MLX5_TNL_MISS_FDB_JUMP_GRP 0x1234faac 935 936 /* 937 * When tunnel offload is active, all JUMP group ids are converted 938 * using the same method. That conversion is applied both to tunnel and 939 * regular rule types. 940 * Group ids used in tunnel rules are relative to it's tunnel (!). 941 * Application can create number of steer rules, using the same 942 * tunnel, with different group id in each rule. 943 * Each tunnel stores its groups internally in PMD tunnel object. 944 * Groups used in regular rules do not belong to any tunnel and are stored 945 * in tunnel hub. 946 */ 947 948 struct mlx5_flow_tunnel { 949 LIST_ENTRY(mlx5_flow_tunnel) chain; 950 struct rte_flow_tunnel app_tunnel; /** app tunnel copy */ 951 uint32_t tunnel_id; /** unique tunnel ID */ 952 uint32_t refctn; 953 struct rte_flow_action action; 954 struct rte_flow_item item; 955 struct mlx5_hlist *groups; /** tunnel groups */ 956 }; 957 958 /** PMD tunnel related context */ 959 struct mlx5_flow_tunnel_hub { 960 /* Tunnels list 961 * Access to the list MUST be MT protected 962 */ 963 LIST_HEAD(, mlx5_flow_tunnel) tunnels; 964 /* protect access to the tunnels list */ 965 rte_spinlock_t sl; 966 struct mlx5_hlist *groups; /** non tunnel groups */ 967 }; 968 969 /* convert jump group to flow table ID in tunnel rules */ 970 struct tunnel_tbl_entry { 971 struct mlx5_list_entry hash; 972 uint32_t flow_table; 973 uint32_t tunnel_id; 974 uint32_t group; 975 }; 976 977 static inline uint32_t 978 tunnel_id_to_flow_tbl(uint32_t id) 979 { 980 return id | (1u << 16); 981 } 982 983 static inline uint32_t 984 tunnel_flow_tbl_to_id(uint32_t flow_tbl) 985 { 986 return flow_tbl & ~(1u << 16); 987 } 988 989 union tunnel_tbl_key { 990 uint64_t val; 991 struct { 992 uint32_t tunnel_id; 993 uint32_t group; 994 }; 995 }; 996 997 static inline struct mlx5_flow_tunnel_hub * 998 mlx5_tunnel_hub(struct rte_eth_dev *dev) 999 { 1000 struct mlx5_priv *priv = dev->data->dev_private; 1001 return priv->sh->tunnel_hub; 1002 } 1003 1004 static inline bool 1005 is_tunnel_offload_active(const struct rte_eth_dev *dev) 1006 { 1007 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 1008 const struct mlx5_priv *priv = dev->data->dev_private; 1009 return !!priv->sh->config.dv_miss_info; 1010 #else 1011 RTE_SET_USED(dev); 1012 return false; 1013 #endif 1014 } 1015 1016 static inline bool 1017 is_flow_tunnel_match_rule(enum mlx5_tof_rule_type tof_rule_type) 1018 { 1019 return tof_rule_type == MLX5_TUNNEL_OFFLOAD_MATCH_RULE; 1020 } 1021 1022 static inline bool 1023 is_flow_tunnel_steer_rule(enum mlx5_tof_rule_type tof_rule_type) 1024 { 1025 return tof_rule_type == MLX5_TUNNEL_OFFLOAD_SET_RULE; 1026 } 1027 1028 static inline const struct mlx5_flow_tunnel * 1029 flow_actions_to_tunnel(const struct rte_flow_action actions[]) 1030 { 1031 return actions[0].conf; 1032 } 1033 1034 static inline const struct mlx5_flow_tunnel * 1035 flow_items_to_tunnel(const struct rte_flow_item items[]) 1036 { 1037 return items[0].spec; 1038 } 1039 1040 /** 1041 * Fetch 1, 2, 3 or 4 byte field from the byte array 1042 * and return as unsigned integer in host-endian format. 1043 * 1044 * @param[in] data 1045 * Pointer to data array. 1046 * @param[in] size 1047 * Size of field to extract. 1048 * 1049 * @return 1050 * converted field in host endian format. 1051 */ 1052 static inline uint32_t 1053 flow_dv_fetch_field(const uint8_t *data, uint32_t size) 1054 { 1055 uint32_t ret; 1056 1057 switch (size) { 1058 case 1: 1059 ret = *data; 1060 break; 1061 case 2: 1062 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data); 1063 break; 1064 case 3: 1065 ret = rte_be_to_cpu_16(*(const unaligned_uint16_t *)data); 1066 ret = (ret << 8) | *(data + sizeof(uint16_t)); 1067 break; 1068 case 4: 1069 ret = rte_be_to_cpu_32(*(const unaligned_uint32_t *)data); 1070 break; 1071 default: 1072 MLX5_ASSERT(false); 1073 ret = 0; 1074 break; 1075 } 1076 return ret; 1077 } 1078 1079 struct field_modify_info { 1080 uint32_t size; /* Size of field in protocol header, in bytes. */ 1081 uint32_t offset; /* Offset of field in protocol header, in bytes. */ 1082 enum mlx5_modification_field id; 1083 }; 1084 1085 /* HW steering flow attributes. */ 1086 struct mlx5_flow_attr { 1087 uint32_t port_id; /* Port index. */ 1088 uint32_t group; /* Flow group. */ 1089 uint32_t priority; /* Original Priority. */ 1090 /* rss level, used by priority adjustment. */ 1091 uint32_t rss_level; 1092 /* Action flags, used by priority adjustment. */ 1093 uint32_t act_flags; 1094 uint32_t tbl_type; /* Flow table type. */ 1095 }; 1096 1097 /* Flow structure. */ 1098 struct rte_flow { 1099 uint32_t dev_handles; 1100 /**< Device flow handles that are part of the flow. */ 1101 uint32_t type:2; 1102 uint32_t drv_type:2; /**< Driver type. */ 1103 uint32_t tunnel:1; 1104 uint32_t meter:24; /**< Holds flow meter id. */ 1105 uint32_t indirect_type:2; /**< Indirect action type. */ 1106 uint32_t rix_mreg_copy; 1107 /**< Index to metadata register copy table resource. */ 1108 uint32_t counter; /**< Holds flow counter. */ 1109 uint32_t tunnel_id; /**< Tunnel id */ 1110 union { 1111 uint32_t age; /**< Holds ASO age bit index. */ 1112 uint32_t ct; /**< Holds ASO CT index. */ 1113 }; 1114 uint32_t geneve_tlv_option; /**< Holds Geneve TLV option id. > */ 1115 } __rte_packed; 1116 1117 /* 1118 * HWS COUNTER ID's layout 1119 * 3 2 1 0 1120 * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1121 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1122 * | T | | D | | 1123 * ~ Y | | C | IDX ~ 1124 * | P | | S | | 1125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1126 * 1127 * Bit 31:29 = TYPE = MLX5_INDIRECT_ACTION_TYPE_COUNT = b'10 1128 * Bit 25:24 = DCS index 1129 * Bit 23:00 = IDX in this counter belonged DCS bulk. 1130 */ 1131 typedef uint32_t cnt_id_t; 1132 1133 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 1134 1135 #ifdef PEDANTIC 1136 #pragma GCC diagnostic ignored "-Wpedantic" 1137 #endif 1138 1139 /* HWS flow struct. */ 1140 struct rte_flow_hw { 1141 uint32_t idx; /* Flow index from indexed pool. */ 1142 uint32_t fate_type; /* Fate action type. */ 1143 union { 1144 /* Jump action. */ 1145 struct mlx5_hw_jump_action *jump; 1146 struct mlx5_hrxq *hrxq; /* TIR action. */ 1147 }; 1148 struct rte_flow_template_table *table; /* The table flow allcated from. */ 1149 uint32_t age_idx; 1150 cnt_id_t cnt_id; 1151 uint32_t mtr_id; 1152 uint8_t rule[0]; /* HWS layer data struct. */ 1153 } __rte_packed; 1154 1155 #ifdef PEDANTIC 1156 #pragma GCC diagnostic error "-Wpedantic" 1157 #endif 1158 1159 /* rte flow action translate to DR action struct. */ 1160 struct mlx5_action_construct_data { 1161 LIST_ENTRY(mlx5_action_construct_data) next; 1162 /* Ensure the action types are matched. */ 1163 int type; 1164 uint32_t idx; /* Data index. */ 1165 uint16_t action_src; /* rte_flow_action src offset. */ 1166 uint16_t action_dst; /* mlx5dr_rule_action dst offset. */ 1167 union { 1168 struct { 1169 /* encap data len. */ 1170 uint16_t len; 1171 } encap; 1172 struct { 1173 /* Modify header action offset in pattern. */ 1174 uint16_t mhdr_cmds_off; 1175 /* Offset in pattern after modify header actions. */ 1176 uint16_t mhdr_cmds_end; 1177 /* 1178 * True if this action is masked and does not need to 1179 * be generated. 1180 */ 1181 bool shared; 1182 /* 1183 * Modified field definitions in dst field (SET, ADD) 1184 * or src field (COPY). 1185 */ 1186 struct field_modify_info field[MLX5_ACT_MAX_MOD_FIELDS]; 1187 /* Modified field definitions in dst field (COPY). */ 1188 struct field_modify_info dcopy[MLX5_ACT_MAX_MOD_FIELDS]; 1189 /* 1190 * Masks applied to field values to generate 1191 * PRM actions. 1192 */ 1193 uint32_t mask[MLX5_ACT_MAX_MOD_FIELDS]; 1194 } modify_header; 1195 struct { 1196 uint64_t types; /* RSS hash types. */ 1197 uint32_t level; /* RSS level. */ 1198 uint32_t idx; /* Shared action index. */ 1199 } shared_rss; 1200 struct { 1201 cnt_id_t id; 1202 } shared_counter; 1203 struct { 1204 uint32_t id; 1205 } shared_meter; 1206 }; 1207 }; 1208 1209 /* Flow item template struct. */ 1210 struct rte_flow_pattern_template { 1211 LIST_ENTRY(rte_flow_pattern_template) next; 1212 /* Template attributes. */ 1213 struct rte_flow_pattern_template_attr attr; 1214 struct mlx5dr_match_template *mt; /* mlx5 match template. */ 1215 uint64_t item_flags; /* Item layer flags. */ 1216 uint64_t orig_item_nb; /* Number of pattern items provided by the user (with END item). */ 1217 uint32_t refcnt; /* Reference counter. */ 1218 /* 1219 * If true, then rule pattern should be prepended with 1220 * represented_port pattern item. 1221 */ 1222 bool implicit_port; 1223 /* 1224 * If true, then rule pattern should be prepended with 1225 * tag pattern item for representor matching. 1226 */ 1227 bool implicit_tag; 1228 }; 1229 1230 /* Flow action template struct. */ 1231 struct rte_flow_actions_template { 1232 LIST_ENTRY(rte_flow_actions_template) next; 1233 /* Template attributes. */ 1234 struct rte_flow_actions_template_attr attr; 1235 struct rte_flow_action *actions; /* Cached flow actions. */ 1236 struct rte_flow_action *masks; /* Cached action masks.*/ 1237 struct mlx5dr_action_template *tmpl; /* mlx5dr action template. */ 1238 uint64_t action_flags; /* Bit-map of all valid action in template. */ 1239 uint16_t dr_actions_num; /* Amount of DR rules actions. */ 1240 uint16_t actions_num; /* Amount of flow actions */ 1241 uint16_t *actions_off; /* DR action offset for given rte action offset. */ 1242 uint16_t reformat_off; /* Offset of DR reformat action. */ 1243 uint16_t mhdr_off; /* Offset of DR modify header action. */ 1244 uint32_t refcnt; /* Reference counter. */ 1245 uint16_t rx_cpy_pos; /* Action position of Rx metadata to be copied. */ 1246 }; 1247 1248 /* Jump action struct. */ 1249 struct mlx5_hw_jump_action { 1250 /* Action jump from root. */ 1251 struct mlx5dr_action *root_action; 1252 /* HW steering jump action. */ 1253 struct mlx5dr_action *hws_action; 1254 }; 1255 1256 /* Encap decap action struct. */ 1257 struct mlx5_hw_encap_decap_action { 1258 struct mlx5dr_action *action; /* Action object. */ 1259 /* Is header_reformat action shared across flows in table. */ 1260 bool shared; 1261 size_t data_size; /* Action metadata size. */ 1262 uint8_t data[]; /* Action data. */ 1263 }; 1264 1265 #define MLX5_MHDR_MAX_CMD ((MLX5_MAX_MODIFY_NUM) * 2 + 1) 1266 1267 /* Modify field action struct. */ 1268 struct mlx5_hw_modify_header_action { 1269 /* Reference to DR action */ 1270 struct mlx5dr_action *action; 1271 /* Modify header action position in action rule table. */ 1272 uint16_t pos; 1273 /* Is MODIFY_HEADER action shared across flows in table. */ 1274 bool shared; 1275 /* Amount of modification commands stored in the precompiled buffer. */ 1276 uint32_t mhdr_cmds_num; 1277 /* Precompiled modification commands. */ 1278 struct mlx5_modification_cmd mhdr_cmds[MLX5_MHDR_MAX_CMD]; 1279 }; 1280 1281 /* The maximum actions support in the flow. */ 1282 #define MLX5_HW_MAX_ACTS 16 1283 1284 /* DR action set struct. */ 1285 struct mlx5_hw_actions { 1286 /* Dynamic action list. */ 1287 LIST_HEAD(act_list, mlx5_action_construct_data) act_list; 1288 struct mlx5_hw_jump_action *jump; /* Jump action. */ 1289 struct mlx5_hrxq *tir; /* TIR action. */ 1290 struct mlx5_hw_modify_header_action *mhdr; /* Modify header action. */ 1291 /* Encap/Decap action. */ 1292 struct mlx5_hw_encap_decap_action *encap_decap; 1293 uint16_t encap_decap_pos; /* Encap/Decap action position. */ 1294 uint32_t mark:1; /* Indicate the mark action. */ 1295 cnt_id_t cnt_id; /* Counter id. */ 1296 uint32_t mtr_id; /* Meter id. */ 1297 /* Translated DR action array from action template. */ 1298 struct mlx5dr_rule_action rule_acts[MLX5_HW_MAX_ACTS]; 1299 }; 1300 1301 /* mlx5 action template struct. */ 1302 struct mlx5_hw_action_template { 1303 /* Action template pointer. */ 1304 struct rte_flow_actions_template *action_template; 1305 struct mlx5_hw_actions acts; /* Template actions. */ 1306 }; 1307 1308 /* mlx5 flow group struct. */ 1309 struct mlx5_flow_group { 1310 struct mlx5_list_entry entry; 1311 struct rte_eth_dev *dev; /* Reference to corresponding device. */ 1312 struct mlx5dr_table *tbl; /* HWS table object. */ 1313 struct mlx5_hw_jump_action jump; /* Jump action. */ 1314 enum mlx5dr_table_type type; /* Table type. */ 1315 uint32_t group_id; /* Group id. */ 1316 uint32_t idx; /* Group memory index. */ 1317 }; 1318 1319 1320 #define MLX5_HW_TBL_MAX_ITEM_TEMPLATE 2 1321 #define MLX5_HW_TBL_MAX_ACTION_TEMPLATE 32 1322 1323 struct mlx5_flow_template_table_cfg { 1324 struct rte_flow_template_table_attr attr; /* Table attributes passed through flow API. */ 1325 bool external; /* True if created by flow API, false if table is internal to PMD. */ 1326 }; 1327 1328 struct rte_flow_template_table { 1329 LIST_ENTRY(rte_flow_template_table) next; 1330 struct mlx5_flow_group *grp; /* The group rte_flow_template_table uses. */ 1331 struct mlx5dr_matcher *matcher; /* Template matcher. */ 1332 /* Item templates bind to the table. */ 1333 struct rte_flow_pattern_template *its[MLX5_HW_TBL_MAX_ITEM_TEMPLATE]; 1334 /* Action templates bind to the table. */ 1335 struct mlx5_hw_action_template ats[MLX5_HW_TBL_MAX_ACTION_TEMPLATE]; 1336 struct mlx5_indexed_pool *flow; /* The table's flow ipool. */ 1337 struct mlx5_flow_template_table_cfg cfg; 1338 uint32_t type; /* Flow table type RX/TX/FDB. */ 1339 uint8_t nb_item_templates; /* Item template number. */ 1340 uint8_t nb_action_templates; /* Action template number. */ 1341 uint32_t refcnt; /* Table reference counter. */ 1342 }; 1343 1344 #endif 1345 1346 /* 1347 * Define list of valid combinations of RX Hash fields 1348 * (see enum ibv_rx_hash_fields). 1349 */ 1350 #define MLX5_RSS_HASH_IPV4 (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4) 1351 #define MLX5_RSS_HASH_IPV4_TCP \ 1352 (MLX5_RSS_HASH_IPV4 | \ 1353 IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP) 1354 #define MLX5_RSS_HASH_IPV4_UDP \ 1355 (MLX5_RSS_HASH_IPV4 | \ 1356 IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP) 1357 #define MLX5_RSS_HASH_IPV6 (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6) 1358 #define MLX5_RSS_HASH_IPV6_TCP \ 1359 (MLX5_RSS_HASH_IPV6 | \ 1360 IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP) 1361 #define MLX5_RSS_HASH_IPV6_UDP \ 1362 (MLX5_RSS_HASH_IPV6 | \ 1363 IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP) 1364 #define MLX5_RSS_HASH_IPV4_SRC_ONLY IBV_RX_HASH_SRC_IPV4 1365 #define MLX5_RSS_HASH_IPV4_DST_ONLY IBV_RX_HASH_DST_IPV4 1366 #define MLX5_RSS_HASH_IPV6_SRC_ONLY IBV_RX_HASH_SRC_IPV6 1367 #define MLX5_RSS_HASH_IPV6_DST_ONLY IBV_RX_HASH_DST_IPV6 1368 #define MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY \ 1369 (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_SRC_PORT_UDP) 1370 #define MLX5_RSS_HASH_IPV4_UDP_DST_ONLY \ 1371 (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_DST_PORT_UDP) 1372 #define MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY \ 1373 (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_SRC_PORT_UDP) 1374 #define MLX5_RSS_HASH_IPV6_UDP_DST_ONLY \ 1375 (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_DST_PORT_UDP) 1376 #define MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY \ 1377 (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_SRC_PORT_TCP) 1378 #define MLX5_RSS_HASH_IPV4_TCP_DST_ONLY \ 1379 (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_DST_PORT_TCP) 1380 #define MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY \ 1381 (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_SRC_PORT_TCP) 1382 #define MLX5_RSS_HASH_IPV6_TCP_DST_ONLY \ 1383 (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_DST_PORT_TCP) 1384 1385 #ifndef HAVE_IBV_RX_HASH_IPSEC_SPI 1386 #define IBV_RX_HASH_IPSEC_SPI (1U << 8) 1387 #endif 1388 1389 #define MLX5_RSS_HASH_ESP_SPI IBV_RX_HASH_IPSEC_SPI 1390 #define MLX5_RSS_HASH_IPV4_ESP (MLX5_RSS_HASH_IPV4 | \ 1391 MLX5_RSS_HASH_ESP_SPI) 1392 #define MLX5_RSS_HASH_IPV6_ESP (MLX5_RSS_HASH_IPV6 | \ 1393 MLX5_RSS_HASH_ESP_SPI) 1394 #define MLX5_RSS_HASH_NONE 0ULL 1395 1396 1397 /* extract next protocol type from Ethernet & VLAN headers */ 1398 #define MLX5_ETHER_TYPE_FROM_HEADER(_s, _m, _itm, _prt) do { \ 1399 (_prt) = ((const struct _s *)(_itm)->mask)->_m; \ 1400 (_prt) &= ((const struct _s *)(_itm)->spec)->_m; \ 1401 (_prt) = rte_be_to_cpu_16((_prt)); \ 1402 } while (0) 1403 1404 /* array of valid combinations of RX Hash fields for RSS */ 1405 static const uint64_t mlx5_rss_hash_fields[] = { 1406 MLX5_RSS_HASH_IPV4, 1407 MLX5_RSS_HASH_IPV4_TCP, 1408 MLX5_RSS_HASH_IPV4_UDP, 1409 MLX5_RSS_HASH_IPV4_ESP, 1410 MLX5_RSS_HASH_IPV6, 1411 MLX5_RSS_HASH_IPV6_TCP, 1412 MLX5_RSS_HASH_IPV6_UDP, 1413 MLX5_RSS_HASH_IPV6_ESP, 1414 MLX5_RSS_HASH_ESP_SPI, 1415 MLX5_RSS_HASH_NONE, 1416 }; 1417 1418 /* Shared RSS action structure */ 1419 struct mlx5_shared_action_rss { 1420 ILIST_ENTRY(uint32_t)next; /**< Index to the next RSS structure. */ 1421 uint32_t refcnt; /**< Atomically accessed refcnt. */ 1422 struct rte_flow_action_rss origin; /**< Original rte RSS action. */ 1423 uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */ 1424 struct mlx5_ind_table_obj *ind_tbl; 1425 /**< Hash RX queues (hrxq, hrxq_tunnel fields) indirection table. */ 1426 uint32_t hrxq[MLX5_RSS_HASH_FIELDS_LEN]; 1427 /**< Hash RX queue indexes mapped to mlx5_rss_hash_fields */ 1428 rte_spinlock_t action_rss_sl; /**< Shared RSS action spinlock. */ 1429 }; 1430 1431 struct rte_flow_action_handle { 1432 uint32_t id; 1433 }; 1434 1435 /* Thread specific flow workspace intermediate data. */ 1436 struct mlx5_flow_workspace { 1437 /* If creating another flow in same thread, push new as stack. */ 1438 struct mlx5_flow_workspace *prev; 1439 struct mlx5_flow_workspace *next; 1440 uint32_t inuse; /* can't create new flow with current. */ 1441 struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS]; 1442 struct mlx5_flow_rss_desc rss_desc; 1443 uint32_t rssq_num; /* Allocated queue num in rss_desc. */ 1444 uint32_t flow_idx; /* Intermediate device flow index. */ 1445 struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */ 1446 struct mlx5_flow_meter_policy *policy; 1447 /* The meter policy used by meter in flow. */ 1448 struct mlx5_flow_meter_policy *final_policy; 1449 /* The final policy when meter policy is hierarchy. */ 1450 uint32_t skip_matcher_reg:1; 1451 /* Indicates if need to skip matcher register in translate. */ 1452 uint32_t mark:1; /* Indicates if flow contains mark action. */ 1453 uint32_t vport_meta_tag; /* Used for vport index match. */ 1454 }; 1455 1456 /* Matcher translate type. */ 1457 enum MLX5_SET_MATCHER { 1458 MLX5_SET_MATCHER_SW_V = 1 << 0, 1459 MLX5_SET_MATCHER_SW_M = 1 << 1, 1460 MLX5_SET_MATCHER_HS_V = 1 << 2, 1461 MLX5_SET_MATCHER_HS_M = 1 << 3, 1462 }; 1463 1464 #define MLX5_SET_MATCHER_SW (MLX5_SET_MATCHER_SW_V | MLX5_SET_MATCHER_SW_M) 1465 #define MLX5_SET_MATCHER_HS (MLX5_SET_MATCHER_HS_V | MLX5_SET_MATCHER_HS_M) 1466 #define MLX5_SET_MATCHER_V (MLX5_SET_MATCHER_SW_V | MLX5_SET_MATCHER_HS_V) 1467 #define MLX5_SET_MATCHER_M (MLX5_SET_MATCHER_SW_M | MLX5_SET_MATCHER_HS_M) 1468 1469 /* Flow matcher workspace intermediate data. */ 1470 struct mlx5_dv_matcher_workspace { 1471 uint8_t priority; /* Flow priority. */ 1472 uint64_t last_item; /* Last item in pattern. */ 1473 uint64_t item_flags; /* Flow item pattern flags. */ 1474 uint64_t action_flags; /* Flow action flags. */ 1475 bool external; /* External flow or not. */ 1476 uint32_t vlan_tag:12; /* Flow item VLAN tag. */ 1477 uint8_t next_protocol; /* Tunnel next protocol */ 1478 uint32_t geneve_tlv_option; /* Flow item Geneve TLV option. */ 1479 uint32_t group; /* Flow group. */ 1480 uint16_t udp_dport; /* Flow item UDP port. */ 1481 const struct rte_flow_attr *attr; /* Flow attribute. */ 1482 struct mlx5_flow_rss_desc *rss_desc; /* RSS descriptor. */ 1483 const struct rte_flow_item *tunnel_item; /* Flow tunnel item. */ 1484 const struct rte_flow_item *gre_item; /* Flow GRE item. */ 1485 const struct rte_flow_item *integrity_items[2]; 1486 }; 1487 1488 struct mlx5_flow_split_info { 1489 uint32_t external:1; 1490 /**< True if flow is created by request external to PMD. */ 1491 uint32_t prefix_mark:1; /**< Prefix subflow mark flag. */ 1492 uint32_t skip_scale:8; /**< Skip the scale the table with factor. */ 1493 uint32_t flow_idx; /**< This memory pool index to the flow. */ 1494 uint32_t table_id; /**< Flow table identifier. */ 1495 uint64_t prefix_layers; /**< Prefix subflow layers. */ 1496 }; 1497 1498 struct flow_hw_port_info { 1499 uint32_t regc_mask; 1500 uint32_t regc_value; 1501 uint32_t is_wire:1; 1502 }; 1503 1504 extern struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS]; 1505 1506 #define MLX5_FLOW_HW_TAGS_MAX 8 1507 extern uint32_t mlx5_flow_hw_avl_tags_init_cnt; 1508 extern enum modify_reg mlx5_flow_hw_avl_tags[]; 1509 extern enum modify_reg mlx5_flow_hw_aso_tag; 1510 1511 /* 1512 * Get metadata match tag and mask for given rte_eth_dev port. 1513 * Used in HWS rule creation. 1514 */ 1515 static __rte_always_inline const struct flow_hw_port_info * 1516 flow_hw_conv_port_id(const uint16_t port_id) 1517 { 1518 struct flow_hw_port_info *port_info; 1519 1520 if (port_id >= RTE_MAX_ETHPORTS) 1521 return NULL; 1522 port_info = &mlx5_flow_hw_port_infos[port_id]; 1523 return !!port_info->regc_mask ? port_info : NULL; 1524 } 1525 1526 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 1527 /* 1528 * Get metadata match tag and mask for the uplink port represented 1529 * by given IB context. Used in HWS context creation. 1530 */ 1531 static __rte_always_inline const struct flow_hw_port_info * 1532 flow_hw_get_wire_port(struct ibv_context *ibctx) 1533 { 1534 struct ibv_device *ibdev = ibctx->device; 1535 uint16_t port_id; 1536 1537 MLX5_ETH_FOREACH_DEV(port_id, NULL) { 1538 const struct mlx5_priv *priv = 1539 rte_eth_devices[port_id].data->dev_private; 1540 1541 if (priv && priv->master) { 1542 struct ibv_context *port_ibctx = priv->sh->cdev->ctx; 1543 1544 if (port_ibctx->device == ibdev) 1545 return flow_hw_conv_port_id(port_id); 1546 } 1547 } 1548 return NULL; 1549 } 1550 #endif 1551 1552 extern uint32_t mlx5_flow_hw_flow_metadata_config_refcnt; 1553 extern uint8_t mlx5_flow_hw_flow_metadata_esw_en; 1554 extern uint8_t mlx5_flow_hw_flow_metadata_xmeta_en; 1555 1556 void flow_hw_init_flow_metadata_config(struct rte_eth_dev *dev); 1557 void flow_hw_clear_flow_metadata_config(void); 1558 1559 /* 1560 * Convert metadata or tag to the actual register. 1561 * META: Can only be used to match in the FDB in this stage, fixed C_1. 1562 * TAG: C_x expect meter color reg and the reserved ones. 1563 * TODO: Per port / device, FDB or NIC for Meta matching. 1564 */ 1565 static __rte_always_inline int 1566 flow_hw_get_reg_id(enum rte_flow_item_type type, uint32_t id) 1567 { 1568 switch (type) { 1569 case RTE_FLOW_ITEM_TYPE_META: 1570 #ifdef HAVE_MLX5_HWS_SUPPORT 1571 if (mlx5_flow_hw_flow_metadata_esw_en && 1572 mlx5_flow_hw_flow_metadata_xmeta_en == MLX5_XMETA_MODE_META32_HWS) { 1573 return REG_C_1; 1574 } 1575 #endif 1576 /* 1577 * On root table - PMD allows only egress META matching, thus 1578 * REG_A matching is sufficient. 1579 * 1580 * On non-root tables - REG_A corresponds to general_purpose_lookup_field, 1581 * which translates to REG_A in NIC TX and to REG_B in NIC RX. 1582 * However, current FW does not implement REG_B case right now, so 1583 * REG_B case should be rejected on pattern template validation. 1584 */ 1585 return REG_A; 1586 case RTE_FLOW_ITEM_TYPE_CONNTRACK: 1587 case RTE_FLOW_ITEM_TYPE_METER_COLOR: 1588 return mlx5_flow_hw_aso_tag; 1589 case RTE_FLOW_ITEM_TYPE_TAG: 1590 MLX5_ASSERT(id < MLX5_FLOW_HW_TAGS_MAX); 1591 return mlx5_flow_hw_avl_tags[id]; 1592 default: 1593 return REG_NON; 1594 } 1595 } 1596 1597 void flow_hw_set_port_info(struct rte_eth_dev *dev); 1598 void flow_hw_clear_port_info(struct rte_eth_dev *dev); 1599 1600 void flow_hw_init_tags_set(struct rte_eth_dev *dev); 1601 void flow_hw_clear_tags_set(struct rte_eth_dev *dev); 1602 1603 int flow_hw_create_vport_action(struct rte_eth_dev *dev); 1604 void flow_hw_destroy_vport_action(struct rte_eth_dev *dev); 1605 1606 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev, 1607 const struct rte_flow_attr *attr, 1608 const struct rte_flow_item items[], 1609 const struct rte_flow_action actions[], 1610 bool external, 1611 int hairpin, 1612 struct rte_flow_error *error); 1613 typedef struct mlx5_flow *(*mlx5_flow_prepare_t) 1614 (struct rte_eth_dev *dev, const struct rte_flow_attr *attr, 1615 const struct rte_flow_item items[], 1616 const struct rte_flow_action actions[], struct rte_flow_error *error); 1617 typedef int (*mlx5_flow_translate_t)(struct rte_eth_dev *dev, 1618 struct mlx5_flow *dev_flow, 1619 const struct rte_flow_attr *attr, 1620 const struct rte_flow_item items[], 1621 const struct rte_flow_action actions[], 1622 struct rte_flow_error *error); 1623 typedef int (*mlx5_flow_apply_t)(struct rte_eth_dev *dev, struct rte_flow *flow, 1624 struct rte_flow_error *error); 1625 typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev, 1626 struct rte_flow *flow); 1627 typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev, 1628 struct rte_flow *flow); 1629 typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev, 1630 struct rte_flow *flow, 1631 const struct rte_flow_action *actions, 1632 void *data, 1633 struct rte_flow_error *error); 1634 typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev, 1635 struct mlx5_flow_meter_info *fm, 1636 uint32_t mtr_idx, 1637 uint8_t domain_bitmap); 1638 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev, 1639 struct mlx5_flow_meter_info *fm); 1640 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev); 1641 typedef struct mlx5_flow_meter_sub_policy * 1642 (*mlx5_flow_meter_sub_policy_rss_prepare_t) 1643 (struct rte_eth_dev *dev, 1644 struct mlx5_flow_meter_policy *mtr_policy, 1645 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]); 1646 typedef int (*mlx5_flow_meter_hierarchy_rule_create_t) 1647 (struct rte_eth_dev *dev, 1648 struct mlx5_flow_meter_info *fm, 1649 int32_t src_port, 1650 const struct rte_flow_item *item, 1651 struct rte_flow_error *error); 1652 typedef void (*mlx5_flow_destroy_sub_policy_with_rxq_t) 1653 (struct rte_eth_dev *dev, 1654 struct mlx5_flow_meter_policy *mtr_policy); 1655 typedef uint32_t (*mlx5_flow_mtr_alloc_t) 1656 (struct rte_eth_dev *dev); 1657 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev, 1658 uint32_t mtr_idx); 1659 typedef uint32_t (*mlx5_flow_counter_alloc_t) 1660 (struct rte_eth_dev *dev); 1661 typedef void (*mlx5_flow_counter_free_t)(struct rte_eth_dev *dev, 1662 uint32_t cnt); 1663 typedef int (*mlx5_flow_counter_query_t)(struct rte_eth_dev *dev, 1664 uint32_t cnt, 1665 bool clear, uint64_t *pkts, 1666 uint64_t *bytes, void **action); 1667 typedef int (*mlx5_flow_get_aged_flows_t) 1668 (struct rte_eth_dev *dev, 1669 void **context, 1670 uint32_t nb_contexts, 1671 struct rte_flow_error *error); 1672 typedef int (*mlx5_flow_get_q_aged_flows_t) 1673 (struct rte_eth_dev *dev, 1674 uint32_t queue_id, 1675 void **context, 1676 uint32_t nb_contexts, 1677 struct rte_flow_error *error); 1678 typedef int (*mlx5_flow_action_validate_t) 1679 (struct rte_eth_dev *dev, 1680 const struct rte_flow_indir_action_conf *conf, 1681 const struct rte_flow_action *action, 1682 struct rte_flow_error *error); 1683 typedef struct rte_flow_action_handle *(*mlx5_flow_action_create_t) 1684 (struct rte_eth_dev *dev, 1685 const struct rte_flow_indir_action_conf *conf, 1686 const struct rte_flow_action *action, 1687 struct rte_flow_error *error); 1688 typedef int (*mlx5_flow_action_destroy_t) 1689 (struct rte_eth_dev *dev, 1690 struct rte_flow_action_handle *action, 1691 struct rte_flow_error *error); 1692 typedef int (*mlx5_flow_action_update_t) 1693 (struct rte_eth_dev *dev, 1694 struct rte_flow_action_handle *action, 1695 const void *update, 1696 struct rte_flow_error *error); 1697 typedef int (*mlx5_flow_action_query_t) 1698 (struct rte_eth_dev *dev, 1699 const struct rte_flow_action_handle *action, 1700 void *data, 1701 struct rte_flow_error *error); 1702 typedef int (*mlx5_flow_sync_domain_t) 1703 (struct rte_eth_dev *dev, 1704 uint32_t domains, 1705 uint32_t flags); 1706 typedef int (*mlx5_flow_validate_mtr_acts_t) 1707 (struct rte_eth_dev *dev, 1708 const struct rte_flow_action *actions[RTE_COLORS], 1709 struct rte_flow_attr *attr, 1710 bool *is_rss, 1711 uint8_t *domain_bitmap, 1712 uint8_t *policy_mode, 1713 struct rte_mtr_error *error); 1714 typedef int (*mlx5_flow_create_mtr_acts_t) 1715 (struct rte_eth_dev *dev, 1716 struct mlx5_flow_meter_policy *mtr_policy, 1717 const struct rte_flow_action *actions[RTE_COLORS], 1718 struct rte_flow_attr *attr, 1719 struct rte_mtr_error *error); 1720 typedef void (*mlx5_flow_destroy_mtr_acts_t) 1721 (struct rte_eth_dev *dev, 1722 struct mlx5_flow_meter_policy *mtr_policy); 1723 typedef int (*mlx5_flow_create_policy_rules_t) 1724 (struct rte_eth_dev *dev, 1725 struct mlx5_flow_meter_policy *mtr_policy); 1726 typedef void (*mlx5_flow_destroy_policy_rules_t) 1727 (struct rte_eth_dev *dev, 1728 struct mlx5_flow_meter_policy *mtr_policy); 1729 typedef int (*mlx5_flow_create_def_policy_t) 1730 (struct rte_eth_dev *dev); 1731 typedef void (*mlx5_flow_destroy_def_policy_t) 1732 (struct rte_eth_dev *dev); 1733 typedef int (*mlx5_flow_discover_priorities_t) 1734 (struct rte_eth_dev *dev, 1735 const uint16_t *vprio, int vprio_n); 1736 typedef struct rte_flow_item_flex_handle *(*mlx5_flow_item_create_t) 1737 (struct rte_eth_dev *dev, 1738 const struct rte_flow_item_flex_conf *conf, 1739 struct rte_flow_error *error); 1740 typedef int (*mlx5_flow_item_release_t) 1741 (struct rte_eth_dev *dev, 1742 const struct rte_flow_item_flex_handle *handle, 1743 struct rte_flow_error *error); 1744 typedef int (*mlx5_flow_item_update_t) 1745 (struct rte_eth_dev *dev, 1746 const struct rte_flow_item_flex_handle *handle, 1747 const struct rte_flow_item_flex_conf *conf, 1748 struct rte_flow_error *error); 1749 typedef int (*mlx5_flow_info_get_t) 1750 (struct rte_eth_dev *dev, 1751 struct rte_flow_port_info *port_info, 1752 struct rte_flow_queue_info *queue_info, 1753 struct rte_flow_error *error); 1754 typedef int (*mlx5_flow_port_configure_t) 1755 (struct rte_eth_dev *dev, 1756 const struct rte_flow_port_attr *port_attr, 1757 uint16_t nb_queue, 1758 const struct rte_flow_queue_attr *queue_attr[], 1759 struct rte_flow_error *err); 1760 typedef int (*mlx5_flow_pattern_validate_t) 1761 (struct rte_eth_dev *dev, 1762 const struct rte_flow_pattern_template_attr *attr, 1763 const struct rte_flow_item items[], 1764 struct rte_flow_error *error); 1765 typedef struct rte_flow_pattern_template *(*mlx5_flow_pattern_template_create_t) 1766 (struct rte_eth_dev *dev, 1767 const struct rte_flow_pattern_template_attr *attr, 1768 const struct rte_flow_item items[], 1769 struct rte_flow_error *error); 1770 typedef int (*mlx5_flow_pattern_template_destroy_t) 1771 (struct rte_eth_dev *dev, 1772 struct rte_flow_pattern_template *template, 1773 struct rte_flow_error *error); 1774 typedef int (*mlx5_flow_actions_validate_t) 1775 (struct rte_eth_dev *dev, 1776 const struct rte_flow_actions_template_attr *attr, 1777 const struct rte_flow_action actions[], 1778 const struct rte_flow_action masks[], 1779 struct rte_flow_error *error); 1780 typedef struct rte_flow_actions_template *(*mlx5_flow_actions_template_create_t) 1781 (struct rte_eth_dev *dev, 1782 const struct rte_flow_actions_template_attr *attr, 1783 const struct rte_flow_action actions[], 1784 const struct rte_flow_action masks[], 1785 struct rte_flow_error *error); 1786 typedef int (*mlx5_flow_actions_template_destroy_t) 1787 (struct rte_eth_dev *dev, 1788 struct rte_flow_actions_template *template, 1789 struct rte_flow_error *error); 1790 typedef struct rte_flow_template_table *(*mlx5_flow_table_create_t) 1791 (struct rte_eth_dev *dev, 1792 const struct rte_flow_template_table_attr *attr, 1793 struct rte_flow_pattern_template *item_templates[], 1794 uint8_t nb_item_templates, 1795 struct rte_flow_actions_template *action_templates[], 1796 uint8_t nb_action_templates, 1797 struct rte_flow_error *error); 1798 typedef int (*mlx5_flow_table_destroy_t) 1799 (struct rte_eth_dev *dev, 1800 struct rte_flow_template_table *table, 1801 struct rte_flow_error *error); 1802 typedef struct rte_flow *(*mlx5_flow_async_flow_create_t) 1803 (struct rte_eth_dev *dev, 1804 uint32_t queue, 1805 const struct rte_flow_op_attr *attr, 1806 struct rte_flow_template_table *table, 1807 const struct rte_flow_item items[], 1808 uint8_t pattern_template_index, 1809 const struct rte_flow_action actions[], 1810 uint8_t action_template_index, 1811 void *user_data, 1812 struct rte_flow_error *error); 1813 typedef int (*mlx5_flow_async_flow_destroy_t) 1814 (struct rte_eth_dev *dev, 1815 uint32_t queue, 1816 const struct rte_flow_op_attr *attr, 1817 struct rte_flow *flow, 1818 void *user_data, 1819 struct rte_flow_error *error); 1820 typedef int (*mlx5_flow_pull_t) 1821 (struct rte_eth_dev *dev, 1822 uint32_t queue, 1823 struct rte_flow_op_result res[], 1824 uint16_t n_res, 1825 struct rte_flow_error *error); 1826 typedef int (*mlx5_flow_push_t) 1827 (struct rte_eth_dev *dev, 1828 uint32_t queue, 1829 struct rte_flow_error *error); 1830 1831 typedef struct rte_flow_action_handle *(*mlx5_flow_async_action_handle_create_t) 1832 (struct rte_eth_dev *dev, 1833 uint32_t queue, 1834 const struct rte_flow_op_attr *attr, 1835 const struct rte_flow_indir_action_conf *conf, 1836 const struct rte_flow_action *action, 1837 void *user_data, 1838 struct rte_flow_error *error); 1839 1840 typedef int (*mlx5_flow_async_action_handle_update_t) 1841 (struct rte_eth_dev *dev, 1842 uint32_t queue, 1843 const struct rte_flow_op_attr *attr, 1844 struct rte_flow_action_handle *handle, 1845 const void *update, 1846 void *user_data, 1847 struct rte_flow_error *error); 1848 1849 typedef int (*mlx5_flow_async_action_handle_query_t) 1850 (struct rte_eth_dev *dev, 1851 uint32_t queue, 1852 const struct rte_flow_op_attr *attr, 1853 const struct rte_flow_action_handle *handle, 1854 void *data, 1855 void *user_data, 1856 struct rte_flow_error *error); 1857 1858 typedef int (*mlx5_flow_async_action_handle_destroy_t) 1859 (struct rte_eth_dev *dev, 1860 uint32_t queue, 1861 const struct rte_flow_op_attr *attr, 1862 struct rte_flow_action_handle *handle, 1863 void *user_data, 1864 struct rte_flow_error *error); 1865 1866 struct mlx5_flow_driver_ops { 1867 mlx5_flow_validate_t validate; 1868 mlx5_flow_prepare_t prepare; 1869 mlx5_flow_translate_t translate; 1870 mlx5_flow_apply_t apply; 1871 mlx5_flow_remove_t remove; 1872 mlx5_flow_destroy_t destroy; 1873 mlx5_flow_query_t query; 1874 mlx5_flow_create_mtr_tbls_t create_mtr_tbls; 1875 mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls; 1876 mlx5_flow_destroy_mtr_drop_tbls_t destroy_mtr_drop_tbls; 1877 mlx5_flow_mtr_alloc_t create_meter; 1878 mlx5_flow_mtr_free_t free_meter; 1879 mlx5_flow_validate_mtr_acts_t validate_mtr_acts; 1880 mlx5_flow_create_mtr_acts_t create_mtr_acts; 1881 mlx5_flow_destroy_mtr_acts_t destroy_mtr_acts; 1882 mlx5_flow_create_policy_rules_t create_policy_rules; 1883 mlx5_flow_destroy_policy_rules_t destroy_policy_rules; 1884 mlx5_flow_create_def_policy_t create_def_policy; 1885 mlx5_flow_destroy_def_policy_t destroy_def_policy; 1886 mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare; 1887 mlx5_flow_meter_hierarchy_rule_create_t meter_hierarchy_rule_create; 1888 mlx5_flow_destroy_sub_policy_with_rxq_t destroy_sub_policy_with_rxq; 1889 mlx5_flow_counter_alloc_t counter_alloc; 1890 mlx5_flow_counter_free_t counter_free; 1891 mlx5_flow_counter_query_t counter_query; 1892 mlx5_flow_get_aged_flows_t get_aged_flows; 1893 mlx5_flow_get_q_aged_flows_t get_q_aged_flows; 1894 mlx5_flow_action_validate_t action_validate; 1895 mlx5_flow_action_create_t action_create; 1896 mlx5_flow_action_destroy_t action_destroy; 1897 mlx5_flow_action_update_t action_update; 1898 mlx5_flow_action_query_t action_query; 1899 mlx5_flow_sync_domain_t sync_domain; 1900 mlx5_flow_discover_priorities_t discover_priorities; 1901 mlx5_flow_item_create_t item_create; 1902 mlx5_flow_item_release_t item_release; 1903 mlx5_flow_item_update_t item_update; 1904 mlx5_flow_info_get_t info_get; 1905 mlx5_flow_port_configure_t configure; 1906 mlx5_flow_pattern_validate_t pattern_validate; 1907 mlx5_flow_pattern_template_create_t pattern_template_create; 1908 mlx5_flow_pattern_template_destroy_t pattern_template_destroy; 1909 mlx5_flow_actions_validate_t actions_validate; 1910 mlx5_flow_actions_template_create_t actions_template_create; 1911 mlx5_flow_actions_template_destroy_t actions_template_destroy; 1912 mlx5_flow_table_create_t template_table_create; 1913 mlx5_flow_table_destroy_t template_table_destroy; 1914 mlx5_flow_async_flow_create_t async_flow_create; 1915 mlx5_flow_async_flow_destroy_t async_flow_destroy; 1916 mlx5_flow_pull_t pull; 1917 mlx5_flow_push_t push; 1918 mlx5_flow_async_action_handle_create_t async_action_create; 1919 mlx5_flow_async_action_handle_update_t async_action_update; 1920 mlx5_flow_async_action_handle_query_t async_action_query; 1921 mlx5_flow_async_action_handle_destroy_t async_action_destroy; 1922 }; 1923 1924 /* mlx5_flow.c */ 1925 1926 struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void); 1927 void mlx5_flow_pop_thread_workspace(void); 1928 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void); 1929 __extension__ 1930 struct flow_grp_info { 1931 uint64_t external:1; 1932 uint64_t transfer:1; 1933 uint64_t fdb_def_rule:1; 1934 /* force standard group translation */ 1935 uint64_t std_tbl_fix:1; 1936 uint64_t skip_scale:2; 1937 }; 1938 1939 static inline bool 1940 tunnel_use_standard_attr_group_translate 1941 (const struct rte_eth_dev *dev, 1942 const struct rte_flow_attr *attr, 1943 const struct mlx5_flow_tunnel *tunnel, 1944 enum mlx5_tof_rule_type tof_rule_type) 1945 { 1946 bool verdict; 1947 1948 if (!is_tunnel_offload_active(dev)) 1949 /* no tunnel offload API */ 1950 verdict = true; 1951 else if (tunnel) { 1952 /* 1953 * OvS will use jump to group 0 in tunnel steer rule. 1954 * If tunnel steer rule starts from group 0 (attr.group == 0) 1955 * that 0 group must be translated with standard method. 1956 * attr.group == 0 in tunnel match rule translated with tunnel 1957 * method 1958 */ 1959 verdict = !attr->group && 1960 is_flow_tunnel_steer_rule(tof_rule_type); 1961 } else { 1962 /* 1963 * non-tunnel group translation uses standard method for 1964 * root group only: attr.group == 0 1965 */ 1966 verdict = !attr->group; 1967 } 1968 1969 return verdict; 1970 } 1971 1972 /** 1973 * Get DV flow aso meter by index. 1974 * 1975 * @param[in] dev 1976 * Pointer to the Ethernet device structure. 1977 * @param[in] idx 1978 * mlx5 flow aso meter index in the container. 1979 * @param[out] ppool 1980 * mlx5 flow aso meter pool in the container, 1981 * 1982 * @return 1983 * Pointer to the aso meter, NULL otherwise. 1984 */ 1985 static inline struct mlx5_aso_mtr * 1986 mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) 1987 { 1988 struct mlx5_aso_mtr_pool *pool; 1989 struct mlx5_aso_mtr_pools_mng *pools_mng = 1990 &priv->sh->mtrmng->pools_mng; 1991 1992 if (priv->mtr_bulk.aso) 1993 return priv->mtr_bulk.aso + idx; 1994 /* Decrease to original index. */ 1995 idx--; 1996 MLX5_ASSERT(idx / MLX5_ASO_MTRS_PER_POOL < pools_mng->n); 1997 rte_rwlock_read_lock(&pools_mng->resize_mtrwl); 1998 pool = pools_mng->pools[idx / MLX5_ASO_MTRS_PER_POOL]; 1999 rte_rwlock_read_unlock(&pools_mng->resize_mtrwl); 2000 return &pool->mtrs[idx % MLX5_ASO_MTRS_PER_POOL]; 2001 } 2002 2003 static __rte_always_inline const struct rte_flow_item * 2004 mlx5_find_end_item(const struct rte_flow_item *item) 2005 { 2006 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++); 2007 return item; 2008 } 2009 2010 static __rte_always_inline bool 2011 mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item) 2012 { 2013 struct rte_flow_item_integrity test = *item; 2014 test.l3_ok = 0; 2015 test.l4_ok = 0; 2016 test.ipv4_csum_ok = 0; 2017 test.l4_csum_ok = 0; 2018 return (test.value == 0); 2019 } 2020 2021 /* 2022 * Get ASO CT action by device and index. 2023 * 2024 * @param[in] dev 2025 * Pointer to the Ethernet device structure. 2026 * @param[in] idx 2027 * Index to the ASO CT action. 2028 * 2029 * @return 2030 * The specified ASO CT action pointer. 2031 */ 2032 static inline struct mlx5_aso_ct_action * 2033 flow_aso_ct_get_by_dev_idx(struct rte_eth_dev *dev, uint32_t idx) 2034 { 2035 struct mlx5_priv *priv = dev->data->dev_private; 2036 struct mlx5_aso_ct_pools_mng *mng = priv->sh->ct_mng; 2037 struct mlx5_aso_ct_pool *pool; 2038 2039 idx--; 2040 MLX5_ASSERT((idx / MLX5_ASO_CT_ACTIONS_PER_POOL) < mng->n); 2041 /* Bit operation AND could be used. */ 2042 rte_rwlock_read_lock(&mng->resize_rwl); 2043 pool = mng->pools[idx / MLX5_ASO_CT_ACTIONS_PER_POOL]; 2044 rte_rwlock_read_unlock(&mng->resize_rwl); 2045 return &pool->actions[idx % MLX5_ASO_CT_ACTIONS_PER_POOL]; 2046 } 2047 2048 /* 2049 * Get ASO CT action by owner & index. 2050 * 2051 * @param[in] dev 2052 * Pointer to the Ethernet device structure. 2053 * @param[in] idx 2054 * Index to the ASO CT action and owner port combination. 2055 * 2056 * @return 2057 * The specified ASO CT action pointer. 2058 */ 2059 static inline struct mlx5_aso_ct_action * 2060 flow_aso_ct_get_by_idx(struct rte_eth_dev *dev, uint32_t own_idx) 2061 { 2062 struct mlx5_priv *priv = dev->data->dev_private; 2063 struct mlx5_aso_ct_action *ct; 2064 uint16_t owner = (uint16_t)MLX5_INDIRECT_ACT_CT_GET_OWNER(own_idx); 2065 uint32_t idx = MLX5_INDIRECT_ACT_CT_GET_IDX(own_idx); 2066 2067 if (owner == PORT_ID(priv)) { 2068 ct = flow_aso_ct_get_by_dev_idx(dev, idx); 2069 } else { 2070 struct rte_eth_dev *owndev = &rte_eth_devices[owner]; 2071 2072 MLX5_ASSERT(owner < RTE_MAX_ETHPORTS); 2073 if (dev->data->dev_started != 1) 2074 return NULL; 2075 ct = flow_aso_ct_get_by_dev_idx(owndev, idx); 2076 if (ct->peer != PORT_ID(priv)) 2077 return NULL; 2078 } 2079 return ct; 2080 } 2081 2082 static inline uint16_t 2083 mlx5_translate_tunnel_etypes(uint64_t pattern_flags) 2084 { 2085 if (pattern_flags & MLX5_FLOW_LAYER_INNER_L2) 2086 return RTE_ETHER_TYPE_TEB; 2087 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV4) 2088 return RTE_ETHER_TYPE_IPV4; 2089 else if (pattern_flags & MLX5_FLOW_LAYER_INNER_L3_IPV6) 2090 return RTE_ETHER_TYPE_IPV6; 2091 else if (pattern_flags & MLX5_FLOW_LAYER_MPLS) 2092 return RTE_ETHER_TYPE_MPLS; 2093 return 0; 2094 } 2095 2096 int flow_hw_q_flow_flush(struct rte_eth_dev *dev, 2097 struct rte_flow_error *error); 2098 2099 /* 2100 * Convert rte_mtr_color to mlx5 color. 2101 * 2102 * @param[in] rcol 2103 * rte_mtr_color. 2104 * 2105 * @return 2106 * mlx5 color. 2107 */ 2108 static inline int 2109 rte_col_2_mlx5_col(enum rte_color rcol) 2110 { 2111 switch (rcol) { 2112 case RTE_COLOR_GREEN: 2113 return MLX5_FLOW_COLOR_GREEN; 2114 case RTE_COLOR_YELLOW: 2115 return MLX5_FLOW_COLOR_YELLOW; 2116 case RTE_COLOR_RED: 2117 return MLX5_FLOW_COLOR_RED; 2118 default: 2119 break; 2120 } 2121 return MLX5_FLOW_COLOR_UNDEFINED; 2122 } 2123 2124 /** 2125 * Indicates whether flow source vport is representor port. 2126 * 2127 * @param[in] priv 2128 * Pointer to device private context structure. 2129 * @param[in] act_priv 2130 * Pointer to actual device private context structure if have. 2131 * 2132 * @return 2133 * True when the flow source vport is representor port, false otherwise. 2134 */ 2135 static inline bool 2136 flow_source_vport_representor(struct mlx5_priv *priv, struct mlx5_priv *act_priv) 2137 { 2138 MLX5_ASSERT(priv); 2139 return (!act_priv ? (priv->representor_id != UINT16_MAX) : 2140 (act_priv->representor_id != UINT16_MAX)); 2141 } 2142 2143 /* All types of Ethernet patterns used in control flow rules. */ 2144 enum mlx5_flow_ctrl_rx_eth_pattern_type { 2145 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL = 0, 2146 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_ALL_MCAST, 2147 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST, 2148 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_BCAST_VLAN, 2149 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST, 2150 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV4_MCAST_VLAN, 2151 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST, 2152 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_IPV6_MCAST_VLAN, 2153 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC, 2154 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_DMAC_VLAN, 2155 MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX, 2156 }; 2157 2158 /* All types of RSS actions used in control flow rules. */ 2159 enum mlx5_flow_ctrl_rx_expanded_rss_type { 2160 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_NON_IP = 0, 2161 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4, 2162 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_UDP, 2163 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV4_TCP, 2164 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6, 2165 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_UDP, 2166 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_IPV6_TCP, 2167 MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX, 2168 }; 2169 2170 /** 2171 * Contains pattern template, template table and its attributes for a single 2172 * combination of Ethernet pattern and RSS action. Used to create control flow rules 2173 * with HWS. 2174 */ 2175 struct mlx5_flow_hw_ctrl_rx_table { 2176 struct rte_flow_template_table_attr attr; 2177 struct rte_flow_pattern_template *pt; 2178 struct rte_flow_template_table *tbl; 2179 }; 2180 2181 /* Contains all templates required to create control flow rules with HWS. */ 2182 struct mlx5_flow_hw_ctrl_rx { 2183 struct rte_flow_actions_template *rss[MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX]; 2184 struct mlx5_flow_hw_ctrl_rx_table tables[MLX5_FLOW_HW_CTRL_RX_ETH_PATTERN_MAX] 2185 [MLX5_FLOW_HW_CTRL_RX_EXPANDED_RSS_MAX]; 2186 }; 2187 2188 #define MLX5_CTRL_PROMISCUOUS (RTE_BIT32(0)) 2189 #define MLX5_CTRL_ALL_MULTICAST (RTE_BIT32(1)) 2190 #define MLX5_CTRL_BROADCAST (RTE_BIT32(2)) 2191 #define MLX5_CTRL_IPV4_MULTICAST (RTE_BIT32(3)) 2192 #define MLX5_CTRL_IPV6_MULTICAST (RTE_BIT32(4)) 2193 #define MLX5_CTRL_DMAC (RTE_BIT32(5)) 2194 #define MLX5_CTRL_VLAN_FILTER (RTE_BIT32(6)) 2195 2196 int mlx5_flow_hw_ctrl_flows(struct rte_eth_dev *dev, uint32_t flags); 2197 void mlx5_flow_hw_cleanup_ctrl_rx_templates(struct rte_eth_dev *dev); 2198 2199 int mlx5_flow_group_to_table(struct rte_eth_dev *dev, 2200 const struct mlx5_flow_tunnel *tunnel, 2201 uint32_t group, uint32_t *table, 2202 const struct flow_grp_info *flags, 2203 struct rte_flow_error *error); 2204 uint64_t mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc, 2205 int tunnel, uint64_t layer_types, 2206 uint64_t hash_fields); 2207 int mlx5_flow_discover_priorities(struct rte_eth_dev *dev); 2208 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority, 2209 uint32_t subpriority); 2210 uint32_t mlx5_get_lowest_priority(struct rte_eth_dev *dev, 2211 const struct rte_flow_attr *attr); 2212 uint16_t mlx5_get_matcher_priority(struct rte_eth_dev *dev, 2213 const struct rte_flow_attr *attr, 2214 uint32_t subpriority, bool external); 2215 uint32_t mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev); 2216 int mlx5_flow_get_reg_id(struct rte_eth_dev *dev, 2217 enum mlx5_feature_name feature, 2218 uint32_t id, 2219 struct rte_flow_error *error); 2220 const struct rte_flow_action *mlx5_flow_find_action 2221 (const struct rte_flow_action *actions, 2222 enum rte_flow_action_type action); 2223 int mlx5_validate_action_rss(struct rte_eth_dev *dev, 2224 const struct rte_flow_action *action, 2225 struct rte_flow_error *error); 2226 int mlx5_flow_validate_action_count(struct rte_eth_dev *dev, 2227 const struct rte_flow_attr *attr, 2228 struct rte_flow_error *error); 2229 int mlx5_flow_validate_action_drop(uint64_t action_flags, 2230 const struct rte_flow_attr *attr, 2231 struct rte_flow_error *error); 2232 int mlx5_flow_validate_action_flag(uint64_t action_flags, 2233 const struct rte_flow_attr *attr, 2234 struct rte_flow_error *error); 2235 int mlx5_flow_validate_action_mark(const struct rte_flow_action *action, 2236 uint64_t action_flags, 2237 const struct rte_flow_attr *attr, 2238 struct rte_flow_error *error); 2239 int mlx5_flow_validate_action_queue(const struct rte_flow_action *action, 2240 uint64_t action_flags, 2241 struct rte_eth_dev *dev, 2242 const struct rte_flow_attr *attr, 2243 struct rte_flow_error *error); 2244 int mlx5_flow_validate_action_rss(const struct rte_flow_action *action, 2245 uint64_t action_flags, 2246 struct rte_eth_dev *dev, 2247 const struct rte_flow_attr *attr, 2248 uint64_t item_flags, 2249 struct rte_flow_error *error); 2250 int mlx5_flow_validate_action_default_miss(uint64_t action_flags, 2251 const struct rte_flow_attr *attr, 2252 struct rte_flow_error *error); 2253 int mlx5_flow_item_acceptable(const struct rte_flow_item *item, 2254 const uint8_t *mask, 2255 const uint8_t *nic_mask, 2256 unsigned int size, 2257 bool range_accepted, 2258 struct rte_flow_error *error); 2259 int mlx5_flow_validate_item_eth(const struct rte_flow_item *item, 2260 uint64_t item_flags, bool ext_vlan_sup, 2261 struct rte_flow_error *error); 2262 int mlx5_flow_validate_item_gre(const struct rte_flow_item *item, 2263 uint64_t item_flags, 2264 uint8_t target_protocol, 2265 struct rte_flow_error *error); 2266 int mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item, 2267 uint64_t item_flags, 2268 const struct rte_flow_item *gre_item, 2269 struct rte_flow_error *error); 2270 int mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev, 2271 const struct rte_flow_item *item, 2272 uint64_t item_flags, 2273 const struct rte_flow_attr *attr, 2274 const struct rte_flow_item *gre_item, 2275 struct rte_flow_error *error); 2276 int mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item, 2277 uint64_t item_flags, 2278 uint64_t last_item, 2279 uint16_t ether_type, 2280 const struct rte_flow_item_ipv4 *acc_mask, 2281 bool range_accepted, 2282 struct rte_flow_error *error); 2283 int mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item, 2284 uint64_t item_flags, 2285 uint64_t last_item, 2286 uint16_t ether_type, 2287 const struct rte_flow_item_ipv6 *acc_mask, 2288 struct rte_flow_error *error); 2289 int mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev, 2290 const struct rte_flow_item *item, 2291 uint64_t item_flags, 2292 uint64_t prev_layer, 2293 struct rte_flow_error *error); 2294 int mlx5_flow_validate_item_tcp(const struct rte_flow_item *item, 2295 uint64_t item_flags, 2296 uint8_t target_protocol, 2297 const struct rte_flow_item_tcp *flow_mask, 2298 struct rte_flow_error *error); 2299 int mlx5_flow_validate_item_udp(const struct rte_flow_item *item, 2300 uint64_t item_flags, 2301 uint8_t target_protocol, 2302 struct rte_flow_error *error); 2303 int mlx5_flow_validate_item_vlan(const struct rte_flow_item *item, 2304 uint64_t item_flags, 2305 struct rte_eth_dev *dev, 2306 struct rte_flow_error *error); 2307 int mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev, 2308 uint16_t udp_dport, 2309 const struct rte_flow_item *item, 2310 uint64_t item_flags, 2311 bool root, 2312 struct rte_flow_error *error); 2313 int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item, 2314 uint64_t item_flags, 2315 struct rte_eth_dev *dev, 2316 struct rte_flow_error *error); 2317 int mlx5_flow_validate_item_icmp(const struct rte_flow_item *item, 2318 uint64_t item_flags, 2319 uint8_t target_protocol, 2320 struct rte_flow_error *error); 2321 int mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item, 2322 uint64_t item_flags, 2323 uint8_t target_protocol, 2324 struct rte_flow_error *error); 2325 int mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item, 2326 uint64_t item_flags, 2327 uint8_t target_protocol, 2328 struct rte_flow_error *error); 2329 int mlx5_flow_validate_item_geneve(const struct rte_flow_item *item, 2330 uint64_t item_flags, 2331 struct rte_eth_dev *dev, 2332 struct rte_flow_error *error); 2333 int mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item, 2334 uint64_t last_item, 2335 const struct rte_flow_item *geneve_item, 2336 struct rte_eth_dev *dev, 2337 struct rte_flow_error *error); 2338 int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item, 2339 uint64_t item_flags, 2340 uint64_t last_item, 2341 uint16_t ether_type, 2342 const struct rte_flow_item_ecpri *acc_mask, 2343 struct rte_flow_error *error); 2344 int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev, 2345 struct mlx5_flow_meter_info *fm, 2346 uint32_t mtr_idx, 2347 uint8_t domain_bitmap); 2348 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev, 2349 struct mlx5_flow_meter_info *fm); 2350 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev); 2351 struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare 2352 (struct rte_eth_dev *dev, 2353 struct mlx5_flow_meter_policy *mtr_policy, 2354 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]); 2355 void mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev, 2356 struct mlx5_flow_meter_policy *mtr_policy); 2357 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev); 2358 int mlx5_flow_discover_dr_action_support(struct rte_eth_dev *dev); 2359 int mlx5_action_handle_attach(struct rte_eth_dev *dev); 2360 int mlx5_action_handle_detach(struct rte_eth_dev *dev); 2361 int mlx5_action_handle_flush(struct rte_eth_dev *dev); 2362 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id); 2363 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh); 2364 2365 struct mlx5_list_entry *flow_dv_tbl_create_cb(void *tool_ctx, void *entry_ctx); 2366 int flow_dv_tbl_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2367 void *cb_ctx); 2368 void flow_dv_tbl_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2369 struct mlx5_list_entry *flow_dv_tbl_clone_cb(void *tool_ctx, 2370 struct mlx5_list_entry *oentry, 2371 void *entry_ctx); 2372 void flow_dv_tbl_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2373 struct mlx5_flow_tbl_resource *flow_dv_tbl_resource_get(struct rte_eth_dev *dev, 2374 uint32_t table_level, uint8_t egress, uint8_t transfer, 2375 bool external, const struct mlx5_flow_tunnel *tunnel, 2376 uint32_t group_id, uint8_t dummy, 2377 uint32_t table_id, struct rte_flow_error *error); 2378 int flow_dv_tbl_resource_release(struct mlx5_dev_ctx_shared *sh, 2379 struct mlx5_flow_tbl_resource *tbl); 2380 2381 struct mlx5_list_entry *flow_dv_tag_create_cb(void *tool_ctx, void *cb_ctx); 2382 int flow_dv_tag_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2383 void *cb_ctx); 2384 void flow_dv_tag_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2385 struct mlx5_list_entry *flow_dv_tag_clone_cb(void *tool_ctx, 2386 struct mlx5_list_entry *oentry, 2387 void *cb_ctx); 2388 void flow_dv_tag_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2389 2390 int flow_dv_modify_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2391 void *cb_ctx); 2392 struct mlx5_list_entry *flow_dv_modify_create_cb(void *tool_ctx, void *ctx); 2393 void flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2394 struct mlx5_list_entry *flow_dv_modify_clone_cb(void *tool_ctx, 2395 struct mlx5_list_entry *oentry, 2396 void *ctx); 2397 void flow_dv_modify_clone_free_cb(void *tool_ctx, 2398 struct mlx5_list_entry *entry); 2399 2400 struct mlx5_list_entry *flow_dv_mreg_create_cb(void *tool_ctx, void *ctx); 2401 int flow_dv_mreg_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2402 void *cb_ctx); 2403 void flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2404 struct mlx5_list_entry *flow_dv_mreg_clone_cb(void *tool_ctx, 2405 struct mlx5_list_entry *entry, 2406 void *ctx); 2407 void flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2408 2409 int flow_dv_encap_decap_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2410 void *cb_ctx); 2411 struct mlx5_list_entry *flow_dv_encap_decap_create_cb(void *tool_ctx, 2412 void *cb_ctx); 2413 void flow_dv_encap_decap_remove_cb(void *tool_ctx, 2414 struct mlx5_list_entry *entry); 2415 struct mlx5_list_entry *flow_dv_encap_decap_clone_cb(void *tool_ctx, 2416 struct mlx5_list_entry *entry, 2417 void *cb_ctx); 2418 void flow_dv_encap_decap_clone_free_cb(void *tool_ctx, 2419 struct mlx5_list_entry *entry); 2420 2421 int flow_dv_matcher_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2422 void *ctx); 2423 struct mlx5_list_entry *flow_dv_matcher_create_cb(void *tool_ctx, void *ctx); 2424 void flow_dv_matcher_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2425 2426 int flow_dv_port_id_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2427 void *cb_ctx); 2428 struct mlx5_list_entry *flow_dv_port_id_create_cb(void *tool_ctx, void *cb_ctx); 2429 void flow_dv_port_id_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2430 struct mlx5_list_entry *flow_dv_port_id_clone_cb(void *tool_ctx, 2431 struct mlx5_list_entry *entry, void *cb_ctx); 2432 void flow_dv_port_id_clone_free_cb(void *tool_ctx, 2433 struct mlx5_list_entry *entry); 2434 2435 int flow_dv_push_vlan_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2436 void *cb_ctx); 2437 struct mlx5_list_entry *flow_dv_push_vlan_create_cb(void *tool_ctx, 2438 void *cb_ctx); 2439 void flow_dv_push_vlan_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2440 struct mlx5_list_entry *flow_dv_push_vlan_clone_cb(void *tool_ctx, 2441 struct mlx5_list_entry *entry, void *cb_ctx); 2442 void flow_dv_push_vlan_clone_free_cb(void *tool_ctx, 2443 struct mlx5_list_entry *entry); 2444 2445 int flow_dv_sample_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2446 void *cb_ctx); 2447 struct mlx5_list_entry *flow_dv_sample_create_cb(void *tool_ctx, void *cb_ctx); 2448 void flow_dv_sample_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2449 struct mlx5_list_entry *flow_dv_sample_clone_cb(void *tool_ctx, 2450 struct mlx5_list_entry *entry, void *cb_ctx); 2451 void flow_dv_sample_clone_free_cb(void *tool_ctx, 2452 struct mlx5_list_entry *entry); 2453 2454 int flow_dv_dest_array_match_cb(void *tool_ctx, struct mlx5_list_entry *entry, 2455 void *cb_ctx); 2456 struct mlx5_list_entry *flow_dv_dest_array_create_cb(void *tool_ctx, 2457 void *cb_ctx); 2458 void flow_dv_dest_array_remove_cb(void *tool_ctx, 2459 struct mlx5_list_entry *entry); 2460 struct mlx5_list_entry *flow_dv_dest_array_clone_cb(void *tool_ctx, 2461 struct mlx5_list_entry *entry, void *cb_ctx); 2462 void flow_dv_dest_array_clone_free_cb(void *tool_ctx, 2463 struct mlx5_list_entry *entry); 2464 void flow_dv_hashfields_set(uint64_t item_flags, 2465 struct mlx5_flow_rss_desc *rss_desc, 2466 uint64_t *hash_fields); 2467 void flow_dv_action_rss_l34_hash_adjust(uint64_t rss_types, 2468 uint64_t *hash_field); 2469 uint32_t flow_dv_action_rss_hrxq_lookup(struct rte_eth_dev *dev, uint32_t idx, 2470 const uint64_t hash_fields); 2471 2472 struct mlx5_list_entry *flow_hw_grp_create_cb(void *tool_ctx, void *cb_ctx); 2473 void flow_hw_grp_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2474 int flow_hw_grp_match_cb(void *tool_ctx, 2475 struct mlx5_list_entry *entry, 2476 void *cb_ctx); 2477 struct mlx5_list_entry *flow_hw_grp_clone_cb(void *tool_ctx, 2478 struct mlx5_list_entry *oentry, 2479 void *cb_ctx); 2480 void flow_hw_grp_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry); 2481 2482 struct mlx5_aso_age_action *flow_aso_age_get_by_idx(struct rte_eth_dev *dev, 2483 uint32_t age_idx); 2484 int flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev, 2485 const struct rte_flow_item *item, 2486 struct rte_flow_error *error); 2487 void flow_dev_geneve_tlv_option_resource_release(struct mlx5_dev_ctx_shared *sh); 2488 2489 void flow_release_workspace(void *data); 2490 int mlx5_flow_os_init_workspace_once(void); 2491 void *mlx5_flow_os_get_specific_workspace(void); 2492 int mlx5_flow_os_set_specific_workspace(struct mlx5_flow_workspace *data); 2493 void mlx5_flow_os_release_workspace(void); 2494 uint32_t mlx5_flow_mtr_alloc(struct rte_eth_dev *dev); 2495 void mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx); 2496 int mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev, 2497 const struct rte_flow_action *actions[RTE_COLORS], 2498 struct rte_flow_attr *attr, 2499 bool *is_rss, 2500 uint8_t *domain_bitmap, 2501 uint8_t *policy_mode, 2502 struct rte_mtr_error *error); 2503 void mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev, 2504 struct mlx5_flow_meter_policy *mtr_policy); 2505 int mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev, 2506 struct mlx5_flow_meter_policy *mtr_policy, 2507 const struct rte_flow_action *actions[RTE_COLORS], 2508 struct rte_flow_attr *attr, 2509 struct rte_mtr_error *error); 2510 int mlx5_flow_create_policy_rules(struct rte_eth_dev *dev, 2511 struct mlx5_flow_meter_policy *mtr_policy); 2512 void mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev, 2513 struct mlx5_flow_meter_policy *mtr_policy); 2514 int mlx5_flow_create_def_policy(struct rte_eth_dev *dev); 2515 void mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev); 2516 void flow_drv_rxq_flags_set(struct rte_eth_dev *dev, 2517 struct mlx5_flow_handle *dev_handle); 2518 const struct mlx5_flow_tunnel * 2519 mlx5_get_tof(const struct rte_flow_item *items, 2520 const struct rte_flow_action *actions, 2521 enum mlx5_tof_rule_type *rule_type); 2522 void 2523 flow_hw_resource_release(struct rte_eth_dev *dev); 2524 void 2525 flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable); 2526 int flow_dv_action_validate(struct rte_eth_dev *dev, 2527 const struct rte_flow_indir_action_conf *conf, 2528 const struct rte_flow_action *action, 2529 struct rte_flow_error *err); 2530 struct rte_flow_action_handle *flow_dv_action_create(struct rte_eth_dev *dev, 2531 const struct rte_flow_indir_action_conf *conf, 2532 const struct rte_flow_action *action, 2533 struct rte_flow_error *err); 2534 int flow_dv_action_destroy(struct rte_eth_dev *dev, 2535 struct rte_flow_action_handle *handle, 2536 struct rte_flow_error *error); 2537 int flow_dv_action_update(struct rte_eth_dev *dev, 2538 struct rte_flow_action_handle *handle, 2539 const void *update, 2540 struct rte_flow_error *err); 2541 int flow_dv_action_query(struct rte_eth_dev *dev, 2542 const struct rte_flow_action_handle *handle, 2543 void *data, 2544 struct rte_flow_error *error); 2545 size_t flow_dv_get_item_hdr_len(const enum rte_flow_item_type item_type); 2546 int flow_dv_convert_encap_data(const struct rte_flow_item *items, uint8_t *buf, 2547 size_t *size, struct rte_flow_error *error); 2548 void mlx5_flow_field_id_to_modify_info 2549 (const struct rte_flow_action_modify_data *data, 2550 struct field_modify_info *info, uint32_t *mask, 2551 uint32_t width, struct rte_eth_dev *dev, 2552 const struct rte_flow_attr *attr, struct rte_flow_error *error); 2553 int flow_dv_convert_modify_action(struct rte_flow_item *item, 2554 struct field_modify_info *field, 2555 struct field_modify_info *dcopy, 2556 struct mlx5_flow_dv_modify_hdr_resource *resource, 2557 uint32_t type, struct rte_flow_error *error); 2558 2559 #define MLX5_PF_VPORT_ID 0 2560 #define MLX5_ECPF_VPORT_ID 0xFFFE 2561 2562 int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev); 2563 int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev, 2564 const struct rte_flow_item *item, 2565 uint16_t *vport_id, 2566 bool *all_ports, 2567 struct rte_flow_error *error); 2568 2569 int flow_dv_translate_items_hws(const struct rte_flow_item *items, 2570 struct mlx5_flow_attr *attr, void *key, 2571 uint32_t key_type, uint64_t *item_flags, 2572 uint8_t *match_criteria, 2573 struct rte_flow_error *error); 2574 2575 int mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev, 2576 uint16_t *proxy_port_id, 2577 struct rte_flow_error *error); 2578 2579 int mlx5_flow_hw_flush_ctrl_flows(struct rte_eth_dev *dev); 2580 2581 int mlx5_flow_hw_esw_create_sq_miss_flow(struct rte_eth_dev *dev, 2582 uint32_t sqn); 2583 int mlx5_flow_hw_esw_create_default_jump_flow(struct rte_eth_dev *dev); 2584 int mlx5_flow_hw_create_tx_default_mreg_copy_flow(struct rte_eth_dev *dev); 2585 int mlx5_flow_hw_tx_repr_matching_flow(struct rte_eth_dev *dev, uint32_t sqn); 2586 int mlx5_flow_actions_validate(struct rte_eth_dev *dev, 2587 const struct rte_flow_actions_template_attr *attr, 2588 const struct rte_flow_action actions[], 2589 const struct rte_flow_action masks[], 2590 struct rte_flow_error *error); 2591 int mlx5_flow_pattern_validate(struct rte_eth_dev *dev, 2592 const struct rte_flow_pattern_template_attr *attr, 2593 const struct rte_flow_item items[], 2594 struct rte_flow_error *error); 2595 int flow_hw_table_update(struct rte_eth_dev *dev, 2596 struct rte_flow_error *error); 2597 int mlx5_flow_item_field_width(struct rte_eth_dev *dev, 2598 enum rte_flow_field_id field, int inherit, 2599 const struct rte_flow_attr *attr, 2600 struct rte_flow_error *error); 2601 #endif /* RTE_PMD_MLX5_FLOW_H_ */ 2602