6bb9b6085d84d084cd43ceadc85e0f68591efb80
[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 /* Private rte flow items. */
22 enum mlx5_rte_flow_item_type {
23         MLX5_RTE_FLOW_ITEM_TYPE_END = INT_MIN,
24         MLX5_RTE_FLOW_ITEM_TYPE_TAG,
25         MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
26         MLX5_RTE_FLOW_ITEM_TYPE_VLAN,
27         MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL,
28 };
29
30 /* Private (internal) rte flow actions. */
31 enum mlx5_rte_flow_action_type {
32         MLX5_RTE_FLOW_ACTION_TYPE_END = INT_MIN,
33         MLX5_RTE_FLOW_ACTION_TYPE_TAG,
34         MLX5_RTE_FLOW_ACTION_TYPE_MARK,
35         MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
36         MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
37         MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET,
38         MLX5_RTE_FLOW_ACTION_TYPE_AGE,
39         MLX5_RTE_FLOW_ACTION_TYPE_COUNT,
40         MLX5_RTE_FLOW_ACTION_TYPE_JUMP,
41 };
42
43 #define MLX5_INDIRECT_ACTION_TYPE_OFFSET 30
44
45 enum {
46         MLX5_INDIRECT_ACTION_TYPE_RSS,
47         MLX5_INDIRECT_ACTION_TYPE_AGE,
48         MLX5_INDIRECT_ACTION_TYPE_COUNT,
49 };
50
51 /* Matches on selected register. */
52 struct mlx5_rte_flow_item_tag {
53         enum modify_reg id;
54         uint32_t data;
55 };
56
57 /* Modify selected register. */
58 struct mlx5_rte_flow_action_set_tag {
59         enum modify_reg id;
60         uint8_t offset;
61         uint8_t length;
62         uint32_t data;
63 };
64
65 struct mlx5_flow_action_copy_mreg {
66         enum modify_reg dst;
67         enum modify_reg src;
68 };
69
70 /* Matches on source queue. */
71 struct mlx5_rte_flow_item_tx_queue {
72         uint32_t queue;
73 };
74
75 /* Feature name to allocate metadata register. */
76 enum mlx5_feature_name {
77         MLX5_HAIRPIN_RX,
78         MLX5_HAIRPIN_TX,
79         MLX5_METADATA_RX,
80         MLX5_METADATA_TX,
81         MLX5_METADATA_FDB,
82         MLX5_FLOW_MARK,
83         MLX5_APP_TAG,
84         MLX5_COPY_MARK,
85         MLX5_MTR_COLOR,
86         MLX5_MTR_ID,
87         MLX5_ASO_FLOW_HIT,
88         MLX5_ASO_CONNTRACK,
89 };
90
91 /* Default queue number. */
92 #define MLX5_RSSQ_DEFAULT_NUM 16
93
94 #define MLX5_FLOW_LAYER_OUTER_L2 (1u << 0)
95 #define MLX5_FLOW_LAYER_OUTER_L3_IPV4 (1u << 1)
96 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6 (1u << 2)
97 #define MLX5_FLOW_LAYER_OUTER_L4_UDP (1u << 3)
98 #define MLX5_FLOW_LAYER_OUTER_L4_TCP (1u << 4)
99 #define MLX5_FLOW_LAYER_OUTER_VLAN (1u << 5)
100
101 /* Pattern inner Layer bits. */
102 #define MLX5_FLOW_LAYER_INNER_L2 (1u << 6)
103 #define MLX5_FLOW_LAYER_INNER_L3_IPV4 (1u << 7)
104 #define MLX5_FLOW_LAYER_INNER_L3_IPV6 (1u << 8)
105 #define MLX5_FLOW_LAYER_INNER_L4_UDP (1u << 9)
106 #define MLX5_FLOW_LAYER_INNER_L4_TCP (1u << 10)
107 #define MLX5_FLOW_LAYER_INNER_VLAN (1u << 11)
108
109 /* Pattern tunnel Layer bits. */
110 #define MLX5_FLOW_LAYER_VXLAN (1u << 12)
111 #define MLX5_FLOW_LAYER_VXLAN_GPE (1u << 13)
112 #define MLX5_FLOW_LAYER_GRE (1u << 14)
113 #define MLX5_FLOW_LAYER_MPLS (1u << 15)
114 /* List of tunnel Layer bits continued below. */
115
116 /* General pattern items bits. */
117 #define MLX5_FLOW_ITEM_METADATA (1u << 16)
118 #define MLX5_FLOW_ITEM_PORT_ID (1u << 17)
119 #define MLX5_FLOW_ITEM_TAG (1u << 18)
120 #define MLX5_FLOW_ITEM_MARK (1u << 19)
121
122 /* Pattern MISC bits. */
123 #define MLX5_FLOW_LAYER_ICMP (1u << 20)
124 #define MLX5_FLOW_LAYER_ICMP6 (1u << 21)
125 #define MLX5_FLOW_LAYER_GRE_KEY (1u << 22)
126
127 /* Pattern tunnel Layer bits (continued). */
128 #define MLX5_FLOW_LAYER_IPIP (1u << 23)
129 #define MLX5_FLOW_LAYER_IPV6_ENCAP (1u << 24)
130 #define MLX5_FLOW_LAYER_NVGRE (1u << 25)
131 #define MLX5_FLOW_LAYER_GENEVE (1u << 26)
132
133 /* Queue items. */
134 #define MLX5_FLOW_ITEM_TX_QUEUE (1u << 27)
135
136 /* Pattern tunnel Layer bits (continued). */
137 #define MLX5_FLOW_LAYER_GTP (1u << 28)
138
139 /* Pattern eCPRI Layer bit. */
140 #define MLX5_FLOW_LAYER_ECPRI (UINT64_C(1) << 29)
141
142 /* IPv6 Fragment Extension Header bit. */
143 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6_FRAG_EXT (1u << 30)
144 #define MLX5_FLOW_LAYER_INNER_L3_IPV6_FRAG_EXT (1u << 31)
145
146 /* Pattern tunnel Layer bits (continued). */
147 #define MLX5_FLOW_LAYER_GENEVE_OPT (UINT64_C(1) << 32)
148 #define MLX5_FLOW_LAYER_GTP_PSC (UINT64_C(1) << 33)
149
150 /* INTEGRITY item bit */
151 #define MLX5_FLOW_ITEM_INTEGRITY (UINT64_C(1) << 34)
152
153 /* Outer Masks. */
154 #define MLX5_FLOW_LAYER_OUTER_L3 \
155         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
156 #define MLX5_FLOW_LAYER_OUTER_L4 \
157         (MLX5_FLOW_LAYER_OUTER_L4_UDP | MLX5_FLOW_LAYER_OUTER_L4_TCP)
158 #define MLX5_FLOW_LAYER_OUTER \
159         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_OUTER_L3 | \
160          MLX5_FLOW_LAYER_OUTER_L4)
161
162 /* Tunnel Masks. */
163 #define MLX5_FLOW_LAYER_TUNNEL \
164         (MLX5_FLOW_LAYER_VXLAN | MLX5_FLOW_LAYER_VXLAN_GPE | \
165          MLX5_FLOW_LAYER_GRE | MLX5_FLOW_LAYER_NVGRE | MLX5_FLOW_LAYER_MPLS | \
166          MLX5_FLOW_LAYER_IPIP | MLX5_FLOW_LAYER_IPV6_ENCAP | \
167          MLX5_FLOW_LAYER_GENEVE | MLX5_FLOW_LAYER_GTP)
168
169 /* Inner Masks. */
170 #define MLX5_FLOW_LAYER_INNER_L3 \
171         (MLX5_FLOW_LAYER_INNER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
172 #define MLX5_FLOW_LAYER_INNER_L4 \
173         (MLX5_FLOW_LAYER_INNER_L4_UDP | MLX5_FLOW_LAYER_INNER_L4_TCP)
174 #define MLX5_FLOW_LAYER_INNER \
175         (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3 | \
176          MLX5_FLOW_LAYER_INNER_L4)
177
178 /* Layer Masks. */
179 #define MLX5_FLOW_LAYER_L2 \
180         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_INNER_L2)
181 #define MLX5_FLOW_LAYER_L3_IPV4 \
182         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV4)
183 #define MLX5_FLOW_LAYER_L3_IPV6 \
184         (MLX5_FLOW_LAYER_OUTER_L3_IPV6 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
185 #define MLX5_FLOW_LAYER_L3 \
186         (MLX5_FLOW_LAYER_L3_IPV4 | MLX5_FLOW_LAYER_L3_IPV6)
187 #define MLX5_FLOW_LAYER_L4 \
188         (MLX5_FLOW_LAYER_OUTER_L4 | MLX5_FLOW_LAYER_INNER_L4)
189
190 /* Actions */
191 #define MLX5_FLOW_ACTION_DROP (1u << 0)
192 #define MLX5_FLOW_ACTION_QUEUE (1u << 1)
193 #define MLX5_FLOW_ACTION_RSS (1u << 2)
194 #define MLX5_FLOW_ACTION_FLAG (1u << 3)
195 #define MLX5_FLOW_ACTION_MARK (1u << 4)
196 #define MLX5_FLOW_ACTION_COUNT (1u << 5)
197 #define MLX5_FLOW_ACTION_PORT_ID (1u << 6)
198 #define MLX5_FLOW_ACTION_OF_POP_VLAN (1u << 7)
199 #define MLX5_FLOW_ACTION_OF_PUSH_VLAN (1u << 8)
200 #define MLX5_FLOW_ACTION_OF_SET_VLAN_VID (1u << 9)
201 #define MLX5_FLOW_ACTION_OF_SET_VLAN_PCP (1u << 10)
202 #define MLX5_FLOW_ACTION_SET_IPV4_SRC (1u << 11)
203 #define MLX5_FLOW_ACTION_SET_IPV4_DST (1u << 12)
204 #define MLX5_FLOW_ACTION_SET_IPV6_SRC (1u << 13)
205 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
206 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
207 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
208 #define MLX5_FLOW_ACTION_JUMP (1u << 17)
209 #define MLX5_FLOW_ACTION_SET_TTL (1u << 18)
210 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 19)
211 #define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 20)
212 #define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 21)
213 #define MLX5_FLOW_ACTION_ENCAP (1u << 22)
214 #define MLX5_FLOW_ACTION_DECAP (1u << 23)
215 #define MLX5_FLOW_ACTION_INC_TCP_SEQ (1u << 24)
216 #define MLX5_FLOW_ACTION_DEC_TCP_SEQ (1u << 25)
217 #define MLX5_FLOW_ACTION_INC_TCP_ACK (1u << 26)
218 #define MLX5_FLOW_ACTION_DEC_TCP_ACK (1u << 27)
219 #define MLX5_FLOW_ACTION_SET_TAG (1ull << 28)
220 #define MLX5_FLOW_ACTION_MARK_EXT (1ull << 29)
221 #define MLX5_FLOW_ACTION_SET_META (1ull << 30)
222 #define MLX5_FLOW_ACTION_METER (1ull << 31)
223 #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32)
224 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
225 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
226 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
227 #define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
228 #define MLX5_FLOW_ACTION_TUNNEL_SET (1ull << 37)
229 #define MLX5_FLOW_ACTION_TUNNEL_MATCH (1ull << 38)
230 #define MLX5_FLOW_ACTION_MODIFY_FIELD (1ull << 39)
231 #define MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY (1ull << 40)
232
233 #define MLX5_FLOW_FATE_ACTIONS \
234         (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
235          MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
236          MLX5_FLOW_ACTION_DEFAULT_MISS | \
237          MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
238
239 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
240         (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
241          MLX5_FLOW_ACTION_JUMP | MLX5_FLOW_ACTION_METER_WITH_TERMINATED_POLICY)
242
243 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
244                                       MLX5_FLOW_ACTION_SET_IPV4_DST | \
245                                       MLX5_FLOW_ACTION_SET_IPV6_SRC | \
246                                       MLX5_FLOW_ACTION_SET_IPV6_DST | \
247                                       MLX5_FLOW_ACTION_SET_TP_SRC | \
248                                       MLX5_FLOW_ACTION_SET_TP_DST | \
249                                       MLX5_FLOW_ACTION_SET_TTL | \
250                                       MLX5_FLOW_ACTION_DEC_TTL | \
251                                       MLX5_FLOW_ACTION_SET_MAC_SRC | \
252                                       MLX5_FLOW_ACTION_SET_MAC_DST | \
253                                       MLX5_FLOW_ACTION_INC_TCP_SEQ | \
254                                       MLX5_FLOW_ACTION_DEC_TCP_SEQ | \
255                                       MLX5_FLOW_ACTION_INC_TCP_ACK | \
256                                       MLX5_FLOW_ACTION_DEC_TCP_ACK | \
257                                       MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
258                                       MLX5_FLOW_ACTION_SET_TAG | \
259                                       MLX5_FLOW_ACTION_MARK_EXT | \
260                                       MLX5_FLOW_ACTION_SET_META | \
261                                       MLX5_FLOW_ACTION_SET_IPV4_DSCP | \
262                                       MLX5_FLOW_ACTION_SET_IPV6_DSCP | \
263                                       MLX5_FLOW_ACTION_MODIFY_FIELD)
264
265 #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \
266                                 MLX5_FLOW_ACTION_OF_PUSH_VLAN)
267
268 #define MLX5_FLOW_XCAP_ACTIONS (MLX5_FLOW_ACTION_ENCAP | MLX5_FLOW_ACTION_DECAP)
269
270 #ifndef IPPROTO_MPLS
271 #define IPPROTO_MPLS 137
272 #endif
273
274 /* UDP port number for MPLS */
275 #define MLX5_UDP_PORT_MPLS 6635
276
277 /* UDP port numbers for VxLAN. */
278 #define MLX5_UDP_PORT_VXLAN 4789
279 #define MLX5_UDP_PORT_VXLAN_GPE 4790
280
281 /* UDP port numbers for GENEVE. */
282 #define MLX5_UDP_PORT_GENEVE 6081
283
284 /* Lowest priority indicator. */
285 #define MLX5_FLOW_LOWEST_PRIO_INDICATOR ((uint32_t)-1)
286
287 /*
288  * Max priority for ingress\egress flow groups
289  * greater than 0 and for any transfer flow group.
290  * From user configation: 0 - 21843.
291  */
292 #define MLX5_NON_ROOT_FLOW_MAX_PRIO     (21843 + 1)
293
294 /*
295  * Number of sub priorities.
296  * For each kind of pattern matching i.e. L2, L3, L4 to have a correct
297  * matching on the NIC (firmware dependent) L4 most have the higher priority
298  * followed by L3 and ending with L2.
299  */
300 #define MLX5_PRIORITY_MAP_L2 2
301 #define MLX5_PRIORITY_MAP_L3 1
302 #define MLX5_PRIORITY_MAP_L4 0
303 #define MLX5_PRIORITY_MAP_MAX 3
304
305 /* Valid layer type for IPV4 RSS. */
306 #define MLX5_IPV4_LAYER_TYPES \
307         (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | \
308          ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP | \
309          ETH_RSS_NONFRAG_IPV4_OTHER)
310
311 /* IBV hash source bits  for IPV4. */
312 #define MLX5_IPV4_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4)
313
314 /* Valid layer type for IPV6 RSS. */
315 #define MLX5_IPV6_LAYER_TYPES \
316         (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 | ETH_RSS_NONFRAG_IPV6_TCP | \
317          ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_IPV6_EX  | ETH_RSS_IPV6_TCP_EX | \
318          ETH_RSS_IPV6_UDP_EX | ETH_RSS_NONFRAG_IPV6_OTHER)
319
320 /* IBV hash source bits  for IPV6. */
321 #define MLX5_IPV6_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6)
322
323 /* IBV hash bits for L3 SRC. */
324 #define MLX5_L3_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_SRC_IPV6)
325
326 /* IBV hash bits for L3 DST. */
327 #define MLX5_L3_DST_IBV_RX_HASH (IBV_RX_HASH_DST_IPV4 | IBV_RX_HASH_DST_IPV6)
328
329 /* IBV hash bits for TCP. */
330 #define MLX5_TCP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \
331                               IBV_RX_HASH_DST_PORT_TCP)
332
333 /* IBV hash bits for UDP. */
334 #define MLX5_UDP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_UDP | \
335                               IBV_RX_HASH_DST_PORT_UDP)
336
337 /* IBV hash bits for L4 SRC. */
338 #define MLX5_L4_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \
339                                  IBV_RX_HASH_SRC_PORT_UDP)
340
341 /* IBV hash bits for L4 DST. */
342 #define MLX5_L4_DST_IBV_RX_HASH (IBV_RX_HASH_DST_PORT_TCP | \
343                                  IBV_RX_HASH_DST_PORT_UDP)
344
345 /* Geneve header first 16Bit */
346 #define MLX5_GENEVE_VER_MASK 0x3
347 #define MLX5_GENEVE_VER_SHIFT 14
348 #define MLX5_GENEVE_VER_VAL(a) \
349                 (((a) >> (MLX5_GENEVE_VER_SHIFT)) & (MLX5_GENEVE_VER_MASK))
350 #define MLX5_GENEVE_OPTLEN_MASK 0x3F
351 #define MLX5_GENEVE_OPTLEN_SHIFT 8
352 #define MLX5_GENEVE_OPTLEN_VAL(a) \
353             (((a) >> (MLX5_GENEVE_OPTLEN_SHIFT)) & (MLX5_GENEVE_OPTLEN_MASK))
354 #define MLX5_GENEVE_OAMF_MASK 0x1
355 #define MLX5_GENEVE_OAMF_SHIFT 7
356 #define MLX5_GENEVE_OAMF_VAL(a) \
357                 (((a) >> (MLX5_GENEVE_OAMF_SHIFT)) & (MLX5_GENEVE_OAMF_MASK))
358 #define MLX5_GENEVE_CRITO_MASK 0x1
359 #define MLX5_GENEVE_CRITO_SHIFT 6
360 #define MLX5_GENEVE_CRITO_VAL(a) \
361                 (((a) >> (MLX5_GENEVE_CRITO_SHIFT)) & (MLX5_GENEVE_CRITO_MASK))
362 #define MLX5_GENEVE_RSVD_MASK 0x3F
363 #define MLX5_GENEVE_RSVD_VAL(a) ((a) & (MLX5_GENEVE_RSVD_MASK))
364 /*
365  * The length of the Geneve options fields, expressed in four byte multiples,
366  * not including the eight byte fixed tunnel.
367  */
368 #define MLX5_GENEVE_OPT_LEN_0 14
369 #define MLX5_GENEVE_OPT_LEN_1 63
370
371 #define MLX5_ENCAPSULATION_DECISION_SIZE (sizeof(struct rte_ether_hdr) + \
372                                           sizeof(struct rte_ipv4_hdr))
373 /* GTP extension header flag. */
374 #define MLX5_GTP_EXT_HEADER_FLAG 4
375
376 /* GTP extension header max PDU type value. */
377 #define MLX5_GTP_EXT_MAX_PDU_TYPE 15
378
379 /* GTP extension header PDU type shift. */
380 #define MLX5_GTP_PDU_TYPE_SHIFT(a) ((a) << 4)
381
382 /* IPv4 fragment_offset field contains relevant data in bits 2 to 15. */
383 #define MLX5_IPV4_FRAG_OFFSET_MASK \
384                 (RTE_IPV4_HDR_OFFSET_MASK | RTE_IPV4_HDR_MF_FLAG)
385
386 /* Specific item's fields can accept a range of values (using spec and last). */
387 #define MLX5_ITEM_RANGE_NOT_ACCEPTED    false
388 #define MLX5_ITEM_RANGE_ACCEPTED        true
389
390 /* Software header modify action numbers of a flow. */
391 #define MLX5_ACT_NUM_MDF_IPV4           1
392 #define MLX5_ACT_NUM_MDF_IPV6           4
393 #define MLX5_ACT_NUM_MDF_MAC            2
394 #define MLX5_ACT_NUM_MDF_VID            1
395 #define MLX5_ACT_NUM_MDF_PORT           2
396 #define MLX5_ACT_NUM_MDF_TTL            1
397 #define MLX5_ACT_NUM_DEC_TTL            MLX5_ACT_NUM_MDF_TTL
398 #define MLX5_ACT_NUM_MDF_TCPSEQ         1
399 #define MLX5_ACT_NUM_MDF_TCPACK         1
400 #define MLX5_ACT_NUM_SET_REG            1
401 #define MLX5_ACT_NUM_SET_TAG            1
402 #define MLX5_ACT_NUM_CPY_MREG           MLX5_ACT_NUM_SET_TAG
403 #define MLX5_ACT_NUM_SET_MARK           MLX5_ACT_NUM_SET_TAG
404 #define MLX5_ACT_NUM_SET_META           MLX5_ACT_NUM_SET_TAG
405 #define MLX5_ACT_NUM_SET_DSCP           1
406
407 /* Maximum number of fields to modify in MODIFY_FIELD */
408 #define MLX5_ACT_MAX_MOD_FIELDS 5
409
410 enum mlx5_flow_drv_type {
411         MLX5_FLOW_TYPE_MIN,
412         MLX5_FLOW_TYPE_DV,
413         MLX5_FLOW_TYPE_VERBS,
414         MLX5_FLOW_TYPE_MAX,
415 };
416
417 /* Fate action type. */
418 enum mlx5_flow_fate_type {
419         MLX5_FLOW_FATE_NONE, /* Egress flow. */
420         MLX5_FLOW_FATE_QUEUE,
421         MLX5_FLOW_FATE_JUMP,
422         MLX5_FLOW_FATE_PORT_ID,
423         MLX5_FLOW_FATE_DROP,
424         MLX5_FLOW_FATE_DEFAULT_MISS,
425         MLX5_FLOW_FATE_SHARED_RSS,
426         MLX5_FLOW_FATE_MAX,
427 };
428
429 /* Matcher PRM representation */
430 struct mlx5_flow_dv_match_params {
431         size_t size;
432         /**< Size of match value. Do NOT split size and key! */
433         uint32_t buf[MLX5_ST_SZ_DW(fte_match_param)];
434         /**< Matcher value. This value is used as the mask or as a key. */
435 };
436
437 /* Matcher structure. */
438 struct mlx5_flow_dv_matcher {
439         struct mlx5_cache_entry entry; /**< Pointer to the next element. */
440         struct mlx5_flow_tbl_resource *tbl;
441         /**< Pointer to the table(group) the matcher associated with. */
442         void *matcher_object; /**< Pointer to DV matcher */
443         uint16_t crc; /**< CRC of key. */
444         uint16_t priority; /**< Priority of matcher. */
445         struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */
446 };
447
448 #define MLX5_ENCAP_MAX_LEN 132
449
450 /* Encap/decap resource structure. */
451 struct mlx5_flow_dv_encap_decap_resource {
452         struct mlx5_hlist_entry entry;
453         /* Pointer to next element. */
454         uint32_t refcnt; /**< Reference counter. */
455         void *action;
456         /**< Encap/decap action object. */
457         uint8_t buf[MLX5_ENCAP_MAX_LEN];
458         size_t size;
459         uint8_t reformat_type;
460         uint8_t ft_type;
461         uint64_t flags; /**< Flags for RDMA API. */
462         uint32_t idx; /**< Index for the index memory pool. */
463 };
464
465 /* Tag resource structure. */
466 struct mlx5_flow_dv_tag_resource {
467         struct mlx5_hlist_entry entry;
468         /**< hash list entry for tag resource, tag value as the key. */
469         void *action;
470         /**< Tag action object. */
471         uint32_t refcnt; /**< Reference counter. */
472         uint32_t idx; /**< Index for the index memory pool. */
473         uint32_t tag_id; /**< Tag ID. */
474 };
475
476 /*
477  * Number of modification commands.
478  * The maximal actions amount in FW is some constant, and it is 16 in the
479  * latest releases. In some old releases, it will be limited to 8.
480  * Since there is no interface to query the capacity, the maximal value should
481  * be used to allow PMD to create the flow. The validation will be done in the
482  * lower driver layer or FW. A failure will be returned if exceeds the maximal
483  * supported actions number on the root table.
484  * On non-root tables, there is no limitation, but 32 is enough right now.
485  */
486 #define MLX5_MAX_MODIFY_NUM                     32
487 #define MLX5_ROOT_TBL_MODIFY_NUM                16
488
489 /* Modify resource structure */
490 struct mlx5_flow_dv_modify_hdr_resource {
491         struct mlx5_hlist_entry entry;
492         void *action; /**< Modify header action object. */
493         /* Key area for hash list matching: */
494         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
495         uint32_t actions_num; /**< Number of modification actions. */
496         uint64_t flags; /**< Flags for RDMA API. */
497         struct mlx5_modification_cmd actions[];
498         /**< Modification actions. */
499 };
500
501 /* Modify resource key of the hash organization. */
502 union mlx5_flow_modify_hdr_key {
503         struct {
504                 uint32_t ft_type:8;     /**< Flow table type, Rx or Tx. */
505                 uint32_t actions_num:5; /**< Number of modification actions. */
506                 uint32_t group:19;      /**< Flow group id. */
507                 uint32_t cksum;         /**< Actions check sum. */
508         };
509         uint64_t v64;                   /**< full 64bits value of key */
510 };
511
512 /* Jump action resource structure. */
513 struct mlx5_flow_dv_jump_tbl_resource {
514         void *action; /**< Pointer to the rdma core action. */
515 };
516
517 /* Port ID resource structure. */
518 struct mlx5_flow_dv_port_id_action_resource {
519         struct mlx5_cache_entry entry;
520         void *action; /**< Action object. */
521         uint32_t port_id; /**< Port ID value. */
522         uint32_t idx; /**< Indexed pool memory index. */
523 };
524
525 /* Push VLAN action resource structure */
526 struct mlx5_flow_dv_push_vlan_action_resource {
527         struct mlx5_cache_entry entry; /* Cache entry. */
528         void *action; /**< Action object. */
529         uint8_t ft_type; /**< Flow table type, Rx, Tx or FDB. */
530         rte_be32_t vlan_tag; /**< VLAN tag value. */
531         uint32_t idx; /**< Indexed pool memory index. */
532 };
533
534 /* Metadata register copy table entry. */
535 struct mlx5_flow_mreg_copy_resource {
536         /*
537          * Hash list entry for copy table.
538          *  - Key is 32/64-bit MARK action ID.
539          *  - MUST be the first entry.
540          */
541         struct mlx5_hlist_entry hlist_ent;
542         LIST_ENTRY(mlx5_flow_mreg_copy_resource) next;
543         /* List entry for device flows. */
544         uint32_t idx;
545         uint32_t rix_flow; /* Built flow for copy. */
546         uint32_t mark_id;
547 };
548
549 /* Table tunnel parameter. */
550 struct mlx5_flow_tbl_tunnel_prm {
551         const struct mlx5_flow_tunnel *tunnel;
552         uint32_t group_id;
553         bool external;
554 };
555
556 /* Table data structure of the hash organization. */
557 struct mlx5_flow_tbl_data_entry {
558         struct mlx5_hlist_entry entry;
559         /**< hash list entry, 64-bits key inside. */
560         struct mlx5_flow_tbl_resource tbl;
561         /**< flow table resource. */
562         struct mlx5_cache_list matchers;
563         /**< matchers' header associated with the flow table. */
564         struct mlx5_flow_dv_jump_tbl_resource jump;
565         /**< jump resource, at most one for each table created. */
566         uint32_t idx; /**< index for the indexed mempool. */
567         /**< tunnel offload */
568         const struct mlx5_flow_tunnel *tunnel;
569         uint32_t group_id;
570         uint32_t external:1;
571         uint32_t tunnel_offload:1; /* Tunnel offlod table or not. */
572         uint32_t is_egress:1; /**< Egress table. */
573         uint32_t is_transfer:1; /**< Transfer table. */
574         uint32_t dummy:1; /**<  DR table. */
575         uint32_t id:22; /**< Table ID. */
576         uint32_t reserve:5; /**< Reserved to future using. */
577         uint32_t level; /**< Table level. */
578 };
579
580 /* Sub rdma-core actions list. */
581 struct mlx5_flow_sub_actions_list {
582         uint32_t actions_num; /**< Number of sample actions. */
583         uint64_t action_flags;
584         void *dr_queue_action;
585         void *dr_tag_action;
586         void *dr_cnt_action;
587         void *dr_port_id_action;
588         void *dr_encap_action;
589         void *dr_jump_action;
590 };
591
592 /* Sample sub-actions resource list. */
593 struct mlx5_flow_sub_actions_idx {
594         uint32_t rix_hrxq; /**< Hash Rx queue object index. */
595         uint32_t rix_tag; /**< Index to the tag action. */
596         uint32_t rix_port_id_action; /**< Index to port ID action resource. */
597         uint32_t rix_encap_decap; /**< Index to encap/decap resource. */
598         uint32_t rix_jump; /**< Index to the jump action resource. */
599 };
600
601 /* Sample action resource structure. */
602 struct mlx5_flow_dv_sample_resource {
603         struct mlx5_cache_entry entry; /**< Cache entry. */
604         union {
605                 void *verbs_action; /**< Verbs sample action object. */
606                 void **sub_actions; /**< Sample sub-action array. */
607         };
608         struct rte_eth_dev *dev; /**< Device registers the action. */
609         uint32_t idx; /** Sample object index. */
610         uint8_t ft_type; /** Flow Table Type */
611         uint32_t ft_id; /** Flow Table Level */
612         uint32_t ratio;   /** Sample Ratio */
613         uint64_t set_action; /** Restore reg_c0 value */
614         void *normal_path_tbl; /** Flow Table pointer */
615         struct mlx5_flow_sub_actions_idx sample_idx;
616         /**< Action index resources. */
617         struct mlx5_flow_sub_actions_list sample_act;
618         /**< Action resources. */
619 };
620
621 #define MLX5_MAX_DEST_NUM       2
622
623 /* Destination array action resource structure. */
624 struct mlx5_flow_dv_dest_array_resource {
625         struct mlx5_cache_entry entry; /**< Cache entry. */
626         uint32_t idx; /** Destination array action object index. */
627         uint8_t ft_type; /** Flow Table Type */
628         uint8_t num_of_dest; /**< Number of destination actions. */
629         struct rte_eth_dev *dev; /**< Device registers the action. */
630         void *action; /**< Pointer to the rdma core action. */
631         struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM];
632         /**< Action index resources. */
633         struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM];
634         /**< Action resources. */
635 };
636
637 /* PMD flow priority for tunnel */
638 #define MLX5_TUNNEL_PRIO_GET(rss_desc) \
639         ((rss_desc)->level >= 2 ? MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4)
640
641
642 /** Device flow handle structure for DV mode only. */
643 struct mlx5_flow_handle_dv {
644         /* Flow DV api: */
645         struct mlx5_flow_dv_matcher *matcher; /**< Cache to matcher. */
646         struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
647         /**< Pointer to modify header resource in cache. */
648         uint32_t rix_encap_decap;
649         /**< Index to encap/decap resource in cache. */
650         uint32_t rix_push_vlan;
651         /**< Index to push VLAN action resource in cache. */
652         uint32_t rix_tag;
653         /**< Index to the tag action. */
654         uint32_t rix_sample;
655         /**< Index to sample action resource in cache. */
656         uint32_t rix_dest_array;
657         /**< Index to destination array resource in cache. */
658 } __rte_packed;
659
660 /** Device flow handle structure: used both for creating & destroying. */
661 struct mlx5_flow_handle {
662         SILIST_ENTRY(uint32_t)next;
663         struct mlx5_vf_vlan vf_vlan; /**< Structure for VF VLAN workaround. */
664         /**< Index to next device flow handle. */
665         uint64_t layers;
666         /**< Bit-fields of present layers, see MLX5_FLOW_LAYER_*. */
667         void *drv_flow; /**< pointer to driver flow object. */
668         uint32_t split_flow_id:27; /**< Sub flow unique match flow id. */
669         uint32_t is_meter_flow_id:1; /**< Indate if flow_id is for meter. */
670         uint32_t mark:1; /**< Metadate rxq mark flag. */
671         uint32_t fate_action:3; /**< Fate action type. */
672         union {
673                 uint32_t rix_hrxq; /**< Hash Rx queue object index. */
674                 uint32_t rix_jump; /**< Index to the jump action resource. */
675                 uint32_t rix_port_id_action;
676                 /**< Index to port ID action resource. */
677                 uint32_t rix_fate;
678                 /**< Generic value indicates the fate action. */
679                 uint32_t rix_default_fate;
680                 /**< Indicates default miss fate action. */
681                 uint32_t rix_srss;
682                 /**< Indicates shared RSS fate action. */
683         };
684 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
685         struct mlx5_flow_handle_dv dvh;
686 #endif
687 } __rte_packed;
688
689 /*
690  * Size for Verbs device flow handle structure only. Do not use the DV only
691  * structure in Verbs. No DV flows attributes will be accessed.
692  * Macro offsetof() could also be used here.
693  */
694 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
695 #define MLX5_FLOW_HANDLE_VERBS_SIZE \
696         (sizeof(struct mlx5_flow_handle) - sizeof(struct mlx5_flow_handle_dv))
697 #else
698 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
699 #endif
700
701 /** Device flow structure only for DV flow creation. */
702 struct mlx5_flow_dv_workspace {
703         uint32_t group; /**< The group index. */
704         uint32_t table_id; /**< Flow table identifier. */
705         uint8_t transfer; /**< 1 if the flow is E-Switch flow. */
706         int actions_n; /**< number of actions. */
707         void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; /**< Action list. */
708         struct mlx5_flow_dv_encap_decap_resource *encap_decap;
709         /**< Pointer to encap/decap resource in cache. */
710         struct mlx5_flow_dv_push_vlan_action_resource *push_vlan_res;
711         /**< Pointer to push VLAN action resource in cache. */
712         struct mlx5_flow_dv_tag_resource *tag_resource;
713         /**< pointer to the tag action. */
714         struct mlx5_flow_dv_port_id_action_resource *port_id_action;
715         /**< Pointer to port ID action resource. */
716         struct mlx5_flow_dv_jump_tbl_resource *jump;
717         /**< Pointer to the jump action resource. */
718         struct mlx5_flow_dv_match_params value;
719         /**< Holds the value that the packet is compared to. */
720         struct mlx5_flow_dv_sample_resource *sample_res;
721         /**< Pointer to the sample action resource. */
722         struct mlx5_flow_dv_dest_array_resource *dest_array_res;
723         /**< Pointer to the destination array resource. */
724 };
725
726 #ifdef HAVE_INFINIBAND_VERBS_H
727 /*
728  * Maximal Verbs flow specifications & actions size.
729  * Some elements are mutually exclusive, but enough space should be allocated.
730  * Tunnel cases: 1. Max 2 Ethernet + IP(v6 len > v4 len) + TCP/UDP headers.
731  *               2. One tunnel header (exception: GRE + MPLS),
732  *                  SPEC length: GRE == tunnel.
733  * Actions: 1. 1 Mark OR Flag.
734  *          2. 1 Drop (if any).
735  *          3. No limitation for counters, but it makes no sense to support too
736  *             many counters in a single device flow.
737  */
738 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
739 #define MLX5_VERBS_MAX_SPEC_SIZE \
740                 ( \
741                         (2 * (sizeof(struct ibv_flow_spec_eth) + \
742                               sizeof(struct ibv_flow_spec_ipv6) + \
743                               sizeof(struct ibv_flow_spec_tcp_udp)) + \
744                         sizeof(struct ibv_flow_spec_gre) + \
745                         sizeof(struct ibv_flow_spec_mpls)) \
746                 )
747 #else
748 #define MLX5_VERBS_MAX_SPEC_SIZE \
749                 ( \
750                         (2 * (sizeof(struct ibv_flow_spec_eth) + \
751                               sizeof(struct ibv_flow_spec_ipv6) + \
752                               sizeof(struct ibv_flow_spec_tcp_udp)) + \
753                         sizeof(struct ibv_flow_spec_tunnel)) \
754                 )
755 #endif
756
757 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
758         defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
759 #define MLX5_VERBS_MAX_ACT_SIZE \
760                 ( \
761                         sizeof(struct ibv_flow_spec_action_tag) + \
762                         sizeof(struct ibv_flow_spec_action_drop) + \
763                         sizeof(struct ibv_flow_spec_counter_action) * 4 \
764                 )
765 #else
766 #define MLX5_VERBS_MAX_ACT_SIZE \
767                 ( \
768                         sizeof(struct ibv_flow_spec_action_tag) + \
769                         sizeof(struct ibv_flow_spec_action_drop) \
770                 )
771 #endif
772
773 #define MLX5_VERBS_MAX_SPEC_ACT_SIZE \
774                 (MLX5_VERBS_MAX_SPEC_SIZE + MLX5_VERBS_MAX_ACT_SIZE)
775
776 /** Device flow structure only for Verbs flow creation. */
777 struct mlx5_flow_verbs_workspace {
778         unsigned int size; /**< Size of the attribute. */
779         struct ibv_flow_attr attr; /**< Verbs flow attribute buffer. */
780         uint8_t specs[MLX5_VERBS_MAX_SPEC_ACT_SIZE];
781         /**< Specifications & actions buffer of verbs flow. */
782 };
783 #endif /* HAVE_INFINIBAND_VERBS_H */
784
785 #define MLX5_SCALE_FLOW_GROUP_BIT 0
786 #define MLX5_SCALE_JUMP_FLOW_GROUP_BIT 1
787
788 /** Maximal number of device sub-flows supported. */
789 #define MLX5_NUM_MAX_DEV_FLOWS 32
790
791 /** Device flow structure. */
792 __extension__
793 struct mlx5_flow {
794         struct rte_flow *flow; /**< Pointer to the main flow. */
795         uint32_t flow_idx; /**< The memory pool index to the main flow. */
796         uint64_t hash_fields; /**< Hash Rx queue hash fields. */
797         uint64_t act_flags;
798         /**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */
799         bool external; /**< true if the flow is created external to PMD. */
800         uint8_t ingress:1; /**< 1 if the flow is ingress. */
801         uint8_t skip_scale:2;
802         /**
803          * Each Bit be set to 1 if Skip the scale the flow group with factor.
804          * If bit0 be set to 1, then skip the scale the original flow group;
805          * If bit1 be set to 1, then skip the scale the jump flow group if
806          * having jump action.
807          * 00: Enable scale in a flow, default value.
808          * 01: Skip scale the flow group with factor, enable scale the group
809          * of jump action.
810          * 10: Enable scale the group with factor, skip scale the group of
811          * jump action.
812          * 11: Skip scale the table with factor both for flow group and jump
813          * group.
814          */
815         union {
816 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
817                 struct mlx5_flow_dv_workspace dv;
818 #endif
819 #ifdef HAVE_INFINIBAND_VERBS_H
820                 struct mlx5_flow_verbs_workspace verbs;
821 #endif
822         };
823         struct mlx5_flow_handle *handle;
824         uint32_t handle_idx; /* Index of the mlx5 flow handle memory. */
825         const struct mlx5_flow_tunnel *tunnel;
826 };
827
828 /* Flow meter state. */
829 #define MLX5_FLOW_METER_DISABLE 0
830 #define MLX5_FLOW_METER_ENABLE 1
831
832 #define MLX5_ASO_WQE_CQE_RESPONSE_DELAY 10u
833 #define MLX5_MTR_POLL_WQE_CQE_TIMES 100000u
834
835 #define MLX5_MAN_WIDTH 8
836 /* Legacy Meter parameter structure. */
837 struct mlx5_legacy_flow_meter {
838         struct mlx5_flow_meter_info fm;
839         /* Must be the first in struct. */
840         TAILQ_ENTRY(mlx5_legacy_flow_meter) next;
841         /**< Pointer to the next flow meter structure. */
842         uint32_t idx;
843         /* Index to meter object. */
844 };
845
846 #define MLX5_MAX_TUNNELS 256
847 #define MLX5_TNL_MISS_RULE_PRIORITY 3
848 #define MLX5_TNL_MISS_FDB_JUMP_GRP  0x1234faac
849
850 /*
851  * When tunnel offload is active, all JUMP group ids are converted
852  * using the same method. That conversion is applied both to tunnel and
853  * regular rule types.
854  * Group ids used in tunnel rules are relative to it's tunnel (!).
855  * Application can create number of steer rules, using the same
856  * tunnel, with different group id in each rule.
857  * Each tunnel stores its groups internally in PMD tunnel object.
858  * Groups used in regular rules do not belong to any tunnel and are stored
859  * in tunnel hub.
860  */
861
862 struct mlx5_flow_tunnel {
863         LIST_ENTRY(mlx5_flow_tunnel) chain;
864         struct rte_flow_tunnel app_tunnel;      /** app tunnel copy */
865         uint32_t tunnel_id;                     /** unique tunnel ID */
866         uint32_t refctn;
867         struct rte_flow_action action;
868         struct rte_flow_item item;
869         struct mlx5_hlist *groups;              /** tunnel groups */
870 };
871
872 /** PMD tunnel related context */
873 struct mlx5_flow_tunnel_hub {
874         /* Tunnels list
875          * Access to the list MUST be MT protected
876          */
877         LIST_HEAD(, mlx5_flow_tunnel) tunnels;
878          /* protect access to the tunnels list */
879         rte_spinlock_t sl;
880         struct mlx5_hlist *groups;              /** non tunnel groups */
881 };
882
883 /* convert jump group to flow table ID in tunnel rules */
884 struct tunnel_tbl_entry {
885         struct mlx5_hlist_entry hash;
886         uint32_t flow_table;
887         uint32_t tunnel_id;
888         uint32_t group;
889 };
890
891 static inline uint32_t
892 tunnel_id_to_flow_tbl(uint32_t id)
893 {
894         return id | (1u << 16);
895 }
896
897 static inline uint32_t
898 tunnel_flow_tbl_to_id(uint32_t flow_tbl)
899 {
900         return flow_tbl & ~(1u << 16);
901 }
902
903 union tunnel_tbl_key {
904         uint64_t val;
905         struct {
906                 uint32_t tunnel_id;
907                 uint32_t group;
908         };
909 };
910
911 static inline struct mlx5_flow_tunnel_hub *
912 mlx5_tunnel_hub(struct rte_eth_dev *dev)
913 {
914         struct mlx5_priv *priv = dev->data->dev_private;
915         return priv->sh->tunnel_hub;
916 }
917
918 static inline bool
919 is_tunnel_offload_active(struct rte_eth_dev *dev)
920 {
921 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
922         struct mlx5_priv *priv = dev->data->dev_private;
923         return !!priv->config.dv_miss_info;
924 #else
925         RTE_SET_USED(dev);
926         return false;
927 #endif
928 }
929
930 static inline bool
931 is_flow_tunnel_match_rule(__rte_unused struct rte_eth_dev *dev,
932                           __rte_unused const struct rte_flow_attr *attr,
933                           __rte_unused const struct rte_flow_item items[],
934                           __rte_unused const struct rte_flow_action actions[])
935 {
936         return (items[0].type == (typeof(items[0].type))
937                                  MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL);
938 }
939
940 static inline bool
941 is_flow_tunnel_steer_rule(__rte_unused struct rte_eth_dev *dev,
942                           __rte_unused const struct rte_flow_attr *attr,
943                           __rte_unused const struct rte_flow_item items[],
944                           __rte_unused const struct rte_flow_action actions[])
945 {
946         return (actions[0].type == (typeof(actions[0].type))
947                                    MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET);
948 }
949
950 static inline const struct mlx5_flow_tunnel *
951 flow_actions_to_tunnel(const struct rte_flow_action actions[])
952 {
953         return actions[0].conf;
954 }
955
956 static inline const struct mlx5_flow_tunnel *
957 flow_items_to_tunnel(const struct rte_flow_item items[])
958 {
959         return items[0].spec;
960 }
961
962 /* Flow structure. */
963 struct rte_flow {
964         ILIST_ENTRY(uint32_t)next; /**< Index to the next flow structure. */
965         uint32_t dev_handles;
966         /**< Device flow handles that are part of the flow. */
967         uint32_t drv_type:2; /**< Driver type. */
968         uint32_t tunnel:1;
969         uint32_t meter:24; /**< Holds flow meter id. */
970         uint32_t rix_mreg_copy;
971         /**< Index to metadata register copy table resource. */
972         uint32_t counter; /**< Holds flow counter. */
973         uint32_t tunnel_id;  /**< Tunnel id */
974         uint32_t age; /**< Holds ASO age bit index. */
975         uint32_t geneve_tlv_option; /**< Holds Geneve TLV option id. > */
976 } __rte_packed;
977
978 /*
979  * Define list of valid combinations of RX Hash fields
980  * (see enum ibv_rx_hash_fields).
981  */
982 #define MLX5_RSS_HASH_IPV4 (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4)
983 #define MLX5_RSS_HASH_IPV4_TCP \
984         (MLX5_RSS_HASH_IPV4 | \
985          IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP)
986 #define MLX5_RSS_HASH_IPV4_UDP \
987         (MLX5_RSS_HASH_IPV4 | \
988          IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP)
989 #define MLX5_RSS_HASH_IPV6 (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6)
990 #define MLX5_RSS_HASH_IPV6_TCP \
991         (MLX5_RSS_HASH_IPV6 | \
992          IBV_RX_HASH_SRC_PORT_TCP | IBV_RX_HASH_DST_PORT_TCP)
993 #define MLX5_RSS_HASH_IPV6_UDP \
994         (MLX5_RSS_HASH_IPV6 | \
995          IBV_RX_HASH_SRC_PORT_UDP | IBV_RX_HASH_DST_PORT_UDP)
996 #define MLX5_RSS_HASH_IPV4_SRC_ONLY IBV_RX_HASH_SRC_IPV4
997 #define MLX5_RSS_HASH_IPV4_DST_ONLY IBV_RX_HASH_DST_IPV4
998 #define MLX5_RSS_HASH_IPV6_SRC_ONLY IBV_RX_HASH_SRC_IPV6
999 #define MLX5_RSS_HASH_IPV6_DST_ONLY IBV_RX_HASH_DST_IPV6
1000 #define MLX5_RSS_HASH_IPV4_UDP_SRC_ONLY \
1001         (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_SRC_PORT_UDP)
1002 #define MLX5_RSS_HASH_IPV4_UDP_DST_ONLY \
1003         (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_DST_PORT_UDP)
1004 #define MLX5_RSS_HASH_IPV6_UDP_SRC_ONLY \
1005         (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_SRC_PORT_UDP)
1006 #define MLX5_RSS_HASH_IPV6_UDP_DST_ONLY \
1007         (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_DST_PORT_UDP)
1008 #define MLX5_RSS_HASH_IPV4_TCP_SRC_ONLY \
1009         (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_SRC_PORT_TCP)
1010 #define MLX5_RSS_HASH_IPV4_TCP_DST_ONLY \
1011         (MLX5_RSS_HASH_IPV4 | IBV_RX_HASH_DST_PORT_TCP)
1012 #define MLX5_RSS_HASH_IPV6_TCP_SRC_ONLY \
1013         (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_SRC_PORT_TCP)
1014 #define MLX5_RSS_HASH_IPV6_TCP_DST_ONLY \
1015         (MLX5_RSS_HASH_IPV6 | IBV_RX_HASH_DST_PORT_TCP)
1016 #define MLX5_RSS_HASH_NONE 0ULL
1017
1018
1019 /* extract next protocol type from Ethernet & VLAN headers */
1020 #define MLX5_ETHER_TYPE_FROM_HEADER(_s, _m, _itm, _prt) do { \
1021         (_prt) = ((const struct _s *)(_itm)->mask)->_m;       \
1022         (_prt) &= ((const struct _s *)(_itm)->spec)->_m;      \
1023         (_prt) = rte_be_to_cpu_16((_prt));                    \
1024 } while (0)
1025
1026 /* array of valid combinations of RX Hash fields for RSS */
1027 static const uint64_t mlx5_rss_hash_fields[] = {
1028         MLX5_RSS_HASH_IPV4,
1029         MLX5_RSS_HASH_IPV4_TCP,
1030         MLX5_RSS_HASH_IPV4_UDP,
1031         MLX5_RSS_HASH_IPV6,
1032         MLX5_RSS_HASH_IPV6_TCP,
1033         MLX5_RSS_HASH_IPV6_UDP,
1034         MLX5_RSS_HASH_NONE,
1035 };
1036
1037 /* Shared RSS action structure */
1038 struct mlx5_shared_action_rss {
1039         ILIST_ENTRY(uint32_t)next; /**< Index to the next RSS structure. */
1040         uint32_t refcnt; /**< Atomically accessed refcnt. */
1041         struct rte_flow_action_rss origin; /**< Original rte RSS action. */
1042         uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */
1043         struct mlx5_ind_table_obj *ind_tbl;
1044         /**< Hash RX queues (hrxq, hrxq_tunnel fields) indirection table. */
1045         uint32_t hrxq[MLX5_RSS_HASH_FIELDS_LEN];
1046         /**< Hash RX queue indexes mapped to mlx5_rss_hash_fields */
1047         rte_spinlock_t action_rss_sl; /**< Shared RSS action spinlock. */
1048 };
1049
1050 struct rte_flow_action_handle {
1051         uint32_t id;
1052 };
1053
1054 /* Thread specific flow workspace intermediate data. */
1055 struct mlx5_flow_workspace {
1056         /* If creating another flow in same thread, push new as stack. */
1057         struct mlx5_flow_workspace *prev;
1058         struct mlx5_flow_workspace *next;
1059         uint32_t inuse; /* can't create new flow with current. */
1060         struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS];
1061         struct mlx5_flow_rss_desc rss_desc;
1062         uint32_t rssq_num; /* Allocated queue num in rss_desc. */
1063         uint32_t flow_idx; /* Intermediate device flow index. */
1064         struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */
1065         uint32_t skip_matcher_reg:1;
1066         /* Indicates if need to skip matcher register in translate. */
1067 };
1068
1069 struct mlx5_flow_split_info {
1070         bool external;
1071         /**< True if flow is created by request external to PMD. */
1072         uint8_t skip_scale; /**< Skip the scale the table with factor. */
1073         uint32_t flow_idx; /**< This memory pool index to the flow. */
1074         uint32_t prefix_mark; /**< Prefix subflow mark flag. */
1075         uint64_t prefix_layers; /**< Prefix subflow layers. */
1076         uint32_t table_id; /**< Flow table identifier. */
1077 };
1078
1079 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev,
1080                                     const struct rte_flow_attr *attr,
1081                                     const struct rte_flow_item items[],
1082                                     const struct rte_flow_action actions[],
1083                                     bool external,
1084                                     int hairpin,
1085                                     struct rte_flow_error *error);
1086 typedef struct mlx5_flow *(*mlx5_flow_prepare_t)
1087         (struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1088          const struct rte_flow_item items[],
1089          const struct rte_flow_action actions[], struct rte_flow_error *error);
1090 typedef int (*mlx5_flow_translate_t)(struct rte_eth_dev *dev,
1091                                      struct mlx5_flow *dev_flow,
1092                                      const struct rte_flow_attr *attr,
1093                                      const struct rte_flow_item items[],
1094                                      const struct rte_flow_action actions[],
1095                                      struct rte_flow_error *error);
1096 typedef int (*mlx5_flow_apply_t)(struct rte_eth_dev *dev, struct rte_flow *flow,
1097                                  struct rte_flow_error *error);
1098 typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev,
1099                                    struct rte_flow *flow);
1100 typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev,
1101                                     struct rte_flow *flow);
1102 typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
1103                                  struct rte_flow *flow,
1104                                  const struct rte_flow_action *actions,
1105                                  void *data,
1106                                  struct rte_flow_error *error);
1107 typedef int (*mlx5_flow_create_mtr_tbls_t)(struct rte_eth_dev *dev,
1108                                         struct mlx5_flow_meter_info *fm,
1109                                         uint32_t mtr_idx,
1110                                         uint8_t domain_bitmap);
1111 typedef void (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
1112                                 struct mlx5_flow_meter_info *fm);
1113 typedef void (*mlx5_flow_destroy_mtr_drop_tbls_t)(struct rte_eth_dev *dev);
1114 typedef struct mlx5_flow_meter_sub_policy *
1115         (*mlx5_flow_meter_sub_policy_rss_prepare_t)
1116                 (struct rte_eth_dev *dev,
1117                 struct mlx5_flow_meter_policy *mtr_policy,
1118                 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
1119 typedef uint32_t (*mlx5_flow_mtr_alloc_t)
1120                                             (struct rte_eth_dev *dev);
1121 typedef void (*mlx5_flow_mtr_free_t)(struct rte_eth_dev *dev,
1122                                                 uint32_t mtr_idx);
1123 typedef uint32_t (*mlx5_flow_counter_alloc_t)
1124                                    (struct rte_eth_dev *dev);
1125 typedef void (*mlx5_flow_counter_free_t)(struct rte_eth_dev *dev,
1126                                          uint32_t cnt);
1127 typedef int (*mlx5_flow_counter_query_t)(struct rte_eth_dev *dev,
1128                                          uint32_t cnt,
1129                                          bool clear, uint64_t *pkts,
1130                                          uint64_t *bytes);
1131 typedef int (*mlx5_flow_get_aged_flows_t)
1132                                         (struct rte_eth_dev *dev,
1133                                          void **context,
1134                                          uint32_t nb_contexts,
1135                                          struct rte_flow_error *error);
1136 typedef int (*mlx5_flow_action_validate_t)
1137                                 (struct rte_eth_dev *dev,
1138                                  const struct rte_flow_indir_action_conf *conf,
1139                                  const struct rte_flow_action *action,
1140                                  struct rte_flow_error *error);
1141 typedef struct rte_flow_action_handle *(*mlx5_flow_action_create_t)
1142                                 (struct rte_eth_dev *dev,
1143                                  const struct rte_flow_indir_action_conf *conf,
1144                                  const struct rte_flow_action *action,
1145                                  struct rte_flow_error *error);
1146 typedef int (*mlx5_flow_action_destroy_t)
1147                                 (struct rte_eth_dev *dev,
1148                                  struct rte_flow_action_handle *action,
1149                                  struct rte_flow_error *error);
1150 typedef int (*mlx5_flow_action_update_t)
1151                         (struct rte_eth_dev *dev,
1152                          struct rte_flow_action_handle *action,
1153                          const void *update,
1154                          struct rte_flow_error *error);
1155 typedef int (*mlx5_flow_action_query_t)
1156                         (struct rte_eth_dev *dev,
1157                          const struct rte_flow_action_handle *action,
1158                          void *data,
1159                          struct rte_flow_error *error);
1160 typedef int (*mlx5_flow_sync_domain_t)
1161                         (struct rte_eth_dev *dev,
1162                          uint32_t domains,
1163                          uint32_t flags);
1164 typedef int (*mlx5_flow_validate_mtr_acts_t)
1165                         (struct rte_eth_dev *dev,
1166                          const struct rte_flow_action *actions[RTE_COLORS],
1167                          struct rte_flow_attr *attr,
1168                          bool *is_rss,
1169                          uint8_t *domain_bitmap,
1170                          bool *is_def_policy,
1171                          struct rte_mtr_error *error);
1172 typedef int (*mlx5_flow_create_mtr_acts_t)
1173                         (struct rte_eth_dev *dev,
1174                       struct mlx5_flow_meter_policy *mtr_policy,
1175                       const struct rte_flow_action *actions[RTE_COLORS],
1176                       struct rte_mtr_error *error);
1177 typedef void (*mlx5_flow_destroy_mtr_acts_t)
1178                         (struct rte_eth_dev *dev,
1179                       struct mlx5_flow_meter_policy *mtr_policy);
1180 typedef int (*mlx5_flow_create_policy_rules_t)
1181                         (struct rte_eth_dev *dev,
1182                           struct mlx5_flow_meter_policy *mtr_policy);
1183 typedef void (*mlx5_flow_destroy_policy_rules_t)
1184                         (struct rte_eth_dev *dev,
1185                           struct mlx5_flow_meter_policy *mtr_policy);
1186 typedef int (*mlx5_flow_create_def_policy_t)
1187                         (struct rte_eth_dev *dev);
1188 typedef void (*mlx5_flow_destroy_def_policy_t)
1189                         (struct rte_eth_dev *dev);
1190
1191 struct mlx5_flow_driver_ops {
1192         mlx5_flow_validate_t validate;
1193         mlx5_flow_prepare_t prepare;
1194         mlx5_flow_translate_t translate;
1195         mlx5_flow_apply_t apply;
1196         mlx5_flow_remove_t remove;
1197         mlx5_flow_destroy_t destroy;
1198         mlx5_flow_query_t query;
1199         mlx5_flow_create_mtr_tbls_t create_mtr_tbls;
1200         mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls;
1201         mlx5_flow_destroy_mtr_drop_tbls_t destroy_mtr_drop_tbls;
1202         mlx5_flow_mtr_alloc_t create_meter;
1203         mlx5_flow_mtr_free_t free_meter;
1204         mlx5_flow_validate_mtr_acts_t validate_mtr_acts;
1205         mlx5_flow_create_mtr_acts_t create_mtr_acts;
1206         mlx5_flow_destroy_mtr_acts_t destroy_mtr_acts;
1207         mlx5_flow_create_policy_rules_t create_policy_rules;
1208         mlx5_flow_destroy_policy_rules_t destroy_policy_rules;
1209         mlx5_flow_create_def_policy_t create_def_policy;
1210         mlx5_flow_destroy_def_policy_t destroy_def_policy;
1211         mlx5_flow_meter_sub_policy_rss_prepare_t meter_sub_policy_rss_prepare;
1212         mlx5_flow_counter_alloc_t counter_alloc;
1213         mlx5_flow_counter_free_t counter_free;
1214         mlx5_flow_counter_query_t counter_query;
1215         mlx5_flow_get_aged_flows_t get_aged_flows;
1216         mlx5_flow_action_validate_t action_validate;
1217         mlx5_flow_action_create_t action_create;
1218         mlx5_flow_action_destroy_t action_destroy;
1219         mlx5_flow_action_update_t action_update;
1220         mlx5_flow_action_query_t action_query;
1221         mlx5_flow_sync_domain_t sync_domain;
1222 };
1223
1224 /* mlx5_flow.c */
1225
1226 struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void);
1227 __extension__
1228 struct flow_grp_info {
1229         uint64_t external:1;
1230         uint64_t transfer:1;
1231         uint64_t fdb_def_rule:1;
1232         /* force standard group translation */
1233         uint64_t std_tbl_fix:1;
1234         uint64_t skip_scale:2;
1235 };
1236
1237 static inline bool
1238 tunnel_use_standard_attr_group_translate
1239                     (struct rte_eth_dev *dev,
1240                      const struct mlx5_flow_tunnel *tunnel,
1241                      const struct rte_flow_attr *attr,
1242                      const struct rte_flow_item items[],
1243                      const struct rte_flow_action actions[])
1244 {
1245         bool verdict;
1246
1247         if (!is_tunnel_offload_active(dev))
1248                 /* no tunnel offload API */
1249                 verdict = true;
1250         else if (tunnel) {
1251                 /*
1252                  * OvS will use jump to group 0 in tunnel steer rule.
1253                  * If tunnel steer rule starts from group 0 (attr.group == 0)
1254                  * that 0 group must be translated with standard method.
1255                  * attr.group == 0 in tunnel match rule translated with tunnel
1256                  * method
1257                  */
1258                 verdict = !attr->group &&
1259                           is_flow_tunnel_steer_rule(dev, attr, items, actions);
1260         } else {
1261                 /*
1262                  * non-tunnel group translation uses standard method for
1263                  * root group only: attr.group == 0
1264                  */
1265                 verdict = !attr->group;
1266         }
1267
1268         return verdict;
1269 }
1270
1271 /**
1272  * Get DV flow aso meter by index.
1273  *
1274  * @param[in] dev
1275  *   Pointer to the Ethernet device structure.
1276  * @param[in] idx
1277  *   mlx5 flow aso meter index in the container.
1278  * @param[out] ppool
1279  *   mlx5 flow aso meter pool in the container,
1280  *
1281  * @return
1282  *   Pointer to the aso meter, NULL otherwise.
1283  */
1284 static inline struct mlx5_aso_mtr *
1285 mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx)
1286 {
1287         struct mlx5_aso_mtr_pool *pool;
1288         struct mlx5_aso_mtr_pools_mng *pools_mng =
1289                                 &priv->sh->mtrmng->pools_mng;
1290
1291         /* Decrease to original index. */
1292         idx--;
1293         MLX5_ASSERT(idx / MLX5_ASO_MTRS_PER_POOL < pools_mng->n);
1294         pool = pools_mng->pools[idx / MLX5_ASO_MTRS_PER_POOL];
1295         return &pool->mtrs[idx % MLX5_ASO_MTRS_PER_POOL];
1296 }
1297
1298 static __rte_always_inline const struct rte_flow_item *
1299 mlx5_find_end_item(const struct rte_flow_item *item)
1300 {
1301         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++);
1302         return item;
1303 }
1304
1305 static __rte_always_inline bool
1306 mlx5_validate_integrity_item(const struct rte_flow_item_integrity *item)
1307 {
1308         struct rte_flow_item_integrity test = *item;
1309         test.l3_ok = 0;
1310         test.l4_ok = 0;
1311         test.ipv4_csum_ok = 0;
1312         test.l4_csum_ok = 0;
1313         return (test.value == 0);
1314 }
1315
1316 int mlx5_flow_group_to_table(struct rte_eth_dev *dev,
1317                              const struct mlx5_flow_tunnel *tunnel,
1318                              uint32_t group, uint32_t *table,
1319                              const struct flow_grp_info *flags,
1320                              struct rte_flow_error *error);
1321 uint64_t mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1322                                      int tunnel, uint64_t layer_types,
1323                                      uint64_t hash_fields);
1324 int mlx5_flow_discover_priorities(struct rte_eth_dev *dev);
1325 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
1326                                    uint32_t subpriority);
1327 uint32_t mlx5_get_lowest_priority(struct rte_eth_dev *dev,
1328                                         const struct rte_flow_attr *attr);
1329 uint16_t mlx5_get_matcher_priority(struct rte_eth_dev *dev,
1330                                      const struct rte_flow_attr *attr,
1331                                      uint32_t subpriority);
1332 int mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1333                                      enum mlx5_feature_name feature,
1334                                      uint32_t id,
1335                                      struct rte_flow_error *error);
1336 const struct rte_flow_action *mlx5_flow_find_action
1337                                         (const struct rte_flow_action *actions,
1338                                          enum rte_flow_action_type action);
1339 int mlx5_validate_action_rss(struct rte_eth_dev *dev,
1340                              const struct rte_flow_action *action,
1341                              struct rte_flow_error *error);
1342 int mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
1343                                     const struct rte_flow_attr *attr,
1344                                     struct rte_flow_error *error);
1345 int mlx5_flow_validate_action_drop(uint64_t action_flags,
1346                                    const struct rte_flow_attr *attr,
1347                                    struct rte_flow_error *error);
1348 int mlx5_flow_validate_action_flag(uint64_t action_flags,
1349                                    const struct rte_flow_attr *attr,
1350                                    struct rte_flow_error *error);
1351 int mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1352                                    uint64_t action_flags,
1353                                    const struct rte_flow_attr *attr,
1354                                    struct rte_flow_error *error);
1355 int mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1356                                     uint64_t action_flags,
1357                                     struct rte_eth_dev *dev,
1358                                     const struct rte_flow_attr *attr,
1359                                     struct rte_flow_error *error);
1360 int mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1361                                   uint64_t action_flags,
1362                                   struct rte_eth_dev *dev,
1363                                   const struct rte_flow_attr *attr,
1364                                   uint64_t item_flags,
1365                                   struct rte_flow_error *error);
1366 int mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1367                                 const struct rte_flow_attr *attr,
1368                                 struct rte_flow_error *error);
1369 int mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1370                                   const struct rte_flow_attr *attributes,
1371                                   struct rte_flow_error *error);
1372 int mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1373                               const uint8_t *mask,
1374                               const uint8_t *nic_mask,
1375                               unsigned int size,
1376                               bool range_accepted,
1377                               struct rte_flow_error *error);
1378 int mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1379                                 uint64_t item_flags, bool ext_vlan_sup,
1380                                 struct rte_flow_error *error);
1381 int mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1382                                 uint64_t item_flags,
1383                                 uint8_t target_protocol,
1384                                 struct rte_flow_error *error);
1385 int mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1386                                     uint64_t item_flags,
1387                                     const struct rte_flow_item *gre_item,
1388                                     struct rte_flow_error *error);
1389 int mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1390                                  uint64_t item_flags,
1391                                  uint64_t last_item,
1392                                  uint16_t ether_type,
1393                                  const struct rte_flow_item_ipv4 *acc_mask,
1394                                  bool range_accepted,
1395                                  struct rte_flow_error *error);
1396 int mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1397                                  uint64_t item_flags,
1398                                  uint64_t last_item,
1399                                  uint16_t ether_type,
1400                                  const struct rte_flow_item_ipv6 *acc_mask,
1401                                  struct rte_flow_error *error);
1402 int mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev,
1403                                  const struct rte_flow_item *item,
1404                                  uint64_t item_flags,
1405                                  uint64_t prev_layer,
1406                                  struct rte_flow_error *error);
1407 int mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1408                                 uint64_t item_flags,
1409                                 uint8_t target_protocol,
1410                                 const struct rte_flow_item_tcp *flow_mask,
1411                                 struct rte_flow_error *error);
1412 int mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1413                                 uint64_t item_flags,
1414                                 uint8_t target_protocol,
1415                                 struct rte_flow_error *error);
1416 int mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1417                                  uint64_t item_flags,
1418                                  struct rte_eth_dev *dev,
1419                                  struct rte_flow_error *error);
1420 int mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1421                                   uint64_t item_flags,
1422                                   struct rte_flow_error *error);
1423 int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1424                                       uint64_t item_flags,
1425                                       struct rte_eth_dev *dev,
1426                                       struct rte_flow_error *error);
1427 int mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1428                                  uint64_t item_flags,
1429                                  uint8_t target_protocol,
1430                                  struct rte_flow_error *error);
1431 int mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1432                                    uint64_t item_flags,
1433                                    uint8_t target_protocol,
1434                                    struct rte_flow_error *error);
1435 int mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
1436                                   uint64_t item_flags,
1437                                   uint8_t target_protocol,
1438                                   struct rte_flow_error *error);
1439 int mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
1440                                    uint64_t item_flags,
1441                                    struct rte_eth_dev *dev,
1442                                    struct rte_flow_error *error);
1443 int mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
1444                                    uint64_t last_item,
1445                                    const struct rte_flow_item *geneve_item,
1446                                    struct rte_eth_dev *dev,
1447                                    struct rte_flow_error *error);
1448 int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
1449                                   uint64_t item_flags,
1450                                   uint64_t last_item,
1451                                   uint16_t ether_type,
1452                                   const struct rte_flow_item_ecpri *acc_mask,
1453                                   struct rte_flow_error *error);
1454 int mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
1455                               struct mlx5_flow_meter_info *fm,
1456                               uint32_t mtr_idx,
1457                               uint8_t domain_bitmap);
1458 void mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
1459                                struct mlx5_flow_meter_info *fm);
1460 void mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev);
1461 struct mlx5_flow_meter_sub_policy *mlx5_flow_meter_sub_policy_rss_prepare
1462                 (struct rte_eth_dev *dev,
1463                 struct mlx5_flow_meter_policy *mtr_policy,
1464                 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS]);
1465 int mlx5_flow_dv_discover_counter_offset_support(struct rte_eth_dev *dev);
1466 int mlx5_action_handle_flush(struct rte_eth_dev *dev);
1467 void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id);
1468 int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh);
1469
1470 /* Hash list callbacks for flow tables: */
1471 struct mlx5_hlist_entry *flow_dv_tbl_create_cb(struct mlx5_hlist *list,
1472                                                uint64_t key, void *entry_ctx);
1473 int flow_dv_tbl_match_cb(struct mlx5_hlist *list,
1474                          struct mlx5_hlist_entry *entry, uint64_t key,
1475                          void *cb_ctx);
1476 void flow_dv_tbl_remove_cb(struct mlx5_hlist *list,
1477                            struct mlx5_hlist_entry *entry);
1478 struct mlx5_flow_tbl_resource *flow_dv_tbl_resource_get(struct rte_eth_dev *dev,
1479                 uint32_t table_level, uint8_t egress, uint8_t transfer,
1480                 bool external, const struct mlx5_flow_tunnel *tunnel,
1481                 uint32_t group_id, uint8_t dummy,
1482                 uint32_t table_id, struct rte_flow_error *error);
1483
1484 struct mlx5_hlist_entry *flow_dv_tag_create_cb(struct mlx5_hlist *list,
1485                                                uint64_t key, void *cb_ctx);
1486 int flow_dv_tag_match_cb(struct mlx5_hlist *list,
1487                          struct mlx5_hlist_entry *entry, uint64_t key,
1488                          void *cb_ctx);
1489 void flow_dv_tag_remove_cb(struct mlx5_hlist *list,
1490                            struct mlx5_hlist_entry *entry);
1491
1492 int flow_dv_modify_match_cb(struct mlx5_hlist *list,
1493                             struct mlx5_hlist_entry *entry,
1494                             uint64_t key, void *cb_ctx);
1495 struct mlx5_hlist_entry *flow_dv_modify_create_cb(struct mlx5_hlist *list,
1496                                                   uint64_t key, void *ctx);
1497 void flow_dv_modify_remove_cb(struct mlx5_hlist *list,
1498                               struct mlx5_hlist_entry *entry);
1499
1500 struct mlx5_hlist_entry *flow_dv_mreg_create_cb(struct mlx5_hlist *list,
1501                                                 uint64_t key, void *ctx);
1502 int flow_dv_mreg_match_cb(struct mlx5_hlist *list,
1503                           struct mlx5_hlist_entry *entry, uint64_t key,
1504                           void *cb_ctx);
1505 void flow_dv_mreg_remove_cb(struct mlx5_hlist *list,
1506                             struct mlx5_hlist_entry *entry);
1507
1508 int flow_dv_encap_decap_match_cb(struct mlx5_hlist *list,
1509                                  struct mlx5_hlist_entry *entry,
1510                                  uint64_t key, void *cb_ctx);
1511 struct mlx5_hlist_entry *flow_dv_encap_decap_create_cb(struct mlx5_hlist *list,
1512                                 uint64_t key, void *cb_ctx);
1513 void flow_dv_encap_decap_remove_cb(struct mlx5_hlist *list,
1514                                    struct mlx5_hlist_entry *entry);
1515
1516 int flow_dv_matcher_match_cb(struct mlx5_cache_list *list,
1517                              struct mlx5_cache_entry *entry, void *ctx);
1518 struct mlx5_cache_entry *flow_dv_matcher_create_cb(struct mlx5_cache_list *list,
1519                 struct mlx5_cache_entry *entry, void *ctx);
1520 void flow_dv_matcher_remove_cb(struct mlx5_cache_list *list,
1521                                struct mlx5_cache_entry *entry);
1522
1523 int flow_dv_port_id_match_cb(struct mlx5_cache_list *list,
1524                              struct mlx5_cache_entry *entry, void *cb_ctx);
1525 struct mlx5_cache_entry *flow_dv_port_id_create_cb(struct mlx5_cache_list *list,
1526                 struct mlx5_cache_entry *entry, void *cb_ctx);
1527 void flow_dv_port_id_remove_cb(struct mlx5_cache_list *list,
1528                                struct mlx5_cache_entry *entry);
1529
1530 int flow_dv_push_vlan_match_cb(struct mlx5_cache_list *list,
1531                                struct mlx5_cache_entry *entry, void *cb_ctx);
1532 struct mlx5_cache_entry *flow_dv_push_vlan_create_cb
1533                                 (struct mlx5_cache_list *list,
1534                                  struct mlx5_cache_entry *entry, void *cb_ctx);
1535 void flow_dv_push_vlan_remove_cb(struct mlx5_cache_list *list,
1536                                  struct mlx5_cache_entry *entry);
1537
1538 int flow_dv_sample_match_cb(struct mlx5_cache_list *list,
1539                             struct mlx5_cache_entry *entry, void *cb_ctx);
1540 struct mlx5_cache_entry *flow_dv_sample_create_cb
1541                                 (struct mlx5_cache_list *list,
1542                                  struct mlx5_cache_entry *entry, void *cb_ctx);
1543 void flow_dv_sample_remove_cb(struct mlx5_cache_list *list,
1544                               struct mlx5_cache_entry *entry);
1545
1546 int flow_dv_dest_array_match_cb(struct mlx5_cache_list *list,
1547                                 struct mlx5_cache_entry *entry, void *cb_ctx);
1548 struct mlx5_cache_entry *flow_dv_dest_array_create_cb
1549                                 (struct mlx5_cache_list *list,
1550                                  struct mlx5_cache_entry *entry, void *cb_ctx);
1551 void flow_dv_dest_array_remove_cb(struct mlx5_cache_list *list,
1552                                   struct mlx5_cache_entry *entry);
1553 struct mlx5_aso_age_action *flow_aso_age_get_by_idx(struct rte_eth_dev *dev,
1554                                                     uint32_t age_idx);
1555 int flow_dev_geneve_tlv_option_resource_register(struct rte_eth_dev *dev,
1556                                              const struct rte_flow_item *item,
1557                                              struct rte_flow_error *error);
1558 void flow_release_workspace(void *data);
1559 int mlx5_flow_os_init_workspace_once(void);
1560 void *mlx5_flow_os_get_specific_workspace(void);
1561 int mlx5_flow_os_set_specific_workspace(struct mlx5_flow_workspace *data);
1562 void mlx5_flow_os_release_workspace(void);
1563 uint32_t mlx5_flow_mtr_alloc(struct rte_eth_dev *dev);
1564 void mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx);
1565 int mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
1566                         const struct rte_flow_action *actions[RTE_COLORS],
1567                         struct rte_flow_attr *attr,
1568                         bool *is_rss,
1569                         uint8_t *domain_bitmap,
1570                         bool *is_def_policy,
1571                         struct rte_mtr_error *error);
1572 void mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
1573                       struct mlx5_flow_meter_policy *mtr_policy);
1574 int mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
1575                       struct mlx5_flow_meter_policy *mtr_policy,
1576                       const struct rte_flow_action *actions[RTE_COLORS],
1577                       struct rte_mtr_error *error);
1578 int mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
1579                              struct mlx5_flow_meter_policy *mtr_policy);
1580 void mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
1581                              struct mlx5_flow_meter_policy *mtr_policy);
1582 int mlx5_flow_create_def_policy(struct rte_eth_dev *dev);
1583 void mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev);
1584 void flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
1585                        struct mlx5_flow_handle *dev_handle);
1586 #endif /* RTE_PMD_MLX5_FLOW_H_ */