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