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