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