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