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