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