net/mlx5: support match on IPv4 fragment packets
[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_atomic.h>
15 #include <rte_alarm.h>
16 #include <rte_mtr.h>
17
18 #include <mlx5_glue.h>
19 #include <mlx5_prm.h>
20
21 #include "mlx5.h"
22
23 /* Private rte flow items. */
24 enum mlx5_rte_flow_item_type {
25         MLX5_RTE_FLOW_ITEM_TYPE_END = INT_MIN,
26         MLX5_RTE_FLOW_ITEM_TYPE_TAG,
27         MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
28         MLX5_RTE_FLOW_ITEM_TYPE_VLAN,
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 };
39
40 /* Matches on selected register. */
41 struct mlx5_rte_flow_item_tag {
42         enum modify_reg id;
43         uint32_t data;
44 };
45
46 /* Modify selected register. */
47 struct mlx5_rte_flow_action_set_tag {
48         enum modify_reg id;
49         uint32_t data;
50 };
51
52 struct mlx5_flow_action_copy_mreg {
53         enum modify_reg dst;
54         enum modify_reg src;
55 };
56
57 /* Matches on source queue. */
58 struct mlx5_rte_flow_item_tx_queue {
59         uint32_t queue;
60 };
61
62 /* Feature name to allocate metadata register. */
63 enum mlx5_feature_name {
64         MLX5_HAIRPIN_RX,
65         MLX5_HAIRPIN_TX,
66         MLX5_METADATA_RX,
67         MLX5_METADATA_TX,
68         MLX5_METADATA_FDB,
69         MLX5_FLOW_MARK,
70         MLX5_APP_TAG,
71         MLX5_COPY_MARK,
72         MLX5_MTR_COLOR,
73         MLX5_MTR_SFX,
74 };
75
76 /* Pattern outer Layer bits. */
77 #define MLX5_FLOW_LAYER_OUTER_L2 (1u << 0)
78 #define MLX5_FLOW_LAYER_OUTER_L3_IPV4 (1u << 1)
79 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6 (1u << 2)
80 #define MLX5_FLOW_LAYER_OUTER_L4_UDP (1u << 3)
81 #define MLX5_FLOW_LAYER_OUTER_L4_TCP (1u << 4)
82 #define MLX5_FLOW_LAYER_OUTER_VLAN (1u << 5)
83
84 /* Pattern inner Layer bits. */
85 #define MLX5_FLOW_LAYER_INNER_L2 (1u << 6)
86 #define MLX5_FLOW_LAYER_INNER_L3_IPV4 (1u << 7)
87 #define MLX5_FLOW_LAYER_INNER_L3_IPV6 (1u << 8)
88 #define MLX5_FLOW_LAYER_INNER_L4_UDP (1u << 9)
89 #define MLX5_FLOW_LAYER_INNER_L4_TCP (1u << 10)
90 #define MLX5_FLOW_LAYER_INNER_VLAN (1u << 11)
91
92 /* Pattern tunnel Layer bits. */
93 #define MLX5_FLOW_LAYER_VXLAN (1u << 12)
94 #define MLX5_FLOW_LAYER_VXLAN_GPE (1u << 13)
95 #define MLX5_FLOW_LAYER_GRE (1u << 14)
96 #define MLX5_FLOW_LAYER_MPLS (1u << 15)
97 /* List of tunnel Layer bits continued below. */
98
99 /* General pattern items bits. */
100 #define MLX5_FLOW_ITEM_METADATA (1u << 16)
101 #define MLX5_FLOW_ITEM_PORT_ID (1u << 17)
102 #define MLX5_FLOW_ITEM_TAG (1u << 18)
103 #define MLX5_FLOW_ITEM_MARK (1u << 19)
104
105 /* Pattern MISC bits. */
106 #define MLX5_FLOW_LAYER_ICMP (1u << 20)
107 #define MLX5_FLOW_LAYER_ICMP6 (1u << 21)
108 #define MLX5_FLOW_LAYER_GRE_KEY (1u << 22)
109
110 /* Pattern tunnel Layer bits (continued). */
111 #define MLX5_FLOW_LAYER_IPIP (1u << 23)
112 #define MLX5_FLOW_LAYER_IPV6_ENCAP (1u << 24)
113 #define MLX5_FLOW_LAYER_NVGRE (1u << 25)
114 #define MLX5_FLOW_LAYER_GENEVE (1u << 26)
115
116 /* Queue items. */
117 #define MLX5_FLOW_ITEM_TX_QUEUE (1u << 27)
118
119 /* Pattern tunnel Layer bits (continued). */
120 #define MLX5_FLOW_LAYER_GTP (1u << 28)
121
122 /* Pattern eCPRI Layer bit. */
123 #define MLX5_FLOW_LAYER_ECPRI (UINT64_C(1) << 29)
124
125 /* Outer Masks. */
126 #define MLX5_FLOW_LAYER_OUTER_L3 \
127         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
128 #define MLX5_FLOW_LAYER_OUTER_L4 \
129         (MLX5_FLOW_LAYER_OUTER_L4_UDP | MLX5_FLOW_LAYER_OUTER_L4_TCP)
130 #define MLX5_FLOW_LAYER_OUTER \
131         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_OUTER_L3 | \
132          MLX5_FLOW_LAYER_OUTER_L4)
133
134 /* Tunnel Masks. */
135 #define MLX5_FLOW_LAYER_TUNNEL \
136         (MLX5_FLOW_LAYER_VXLAN | MLX5_FLOW_LAYER_VXLAN_GPE | \
137          MLX5_FLOW_LAYER_GRE | MLX5_FLOW_LAYER_NVGRE | MLX5_FLOW_LAYER_MPLS | \
138          MLX5_FLOW_LAYER_IPIP | MLX5_FLOW_LAYER_IPV6_ENCAP | \
139          MLX5_FLOW_LAYER_GENEVE | MLX5_FLOW_LAYER_GTP)
140
141 /* Inner Masks. */
142 #define MLX5_FLOW_LAYER_INNER_L3 \
143         (MLX5_FLOW_LAYER_INNER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
144 #define MLX5_FLOW_LAYER_INNER_L4 \
145         (MLX5_FLOW_LAYER_INNER_L4_UDP | MLX5_FLOW_LAYER_INNER_L4_TCP)
146 #define MLX5_FLOW_LAYER_INNER \
147         (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3 | \
148          MLX5_FLOW_LAYER_INNER_L4)
149
150 /* Layer Masks. */
151 #define MLX5_FLOW_LAYER_L2 \
152         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_INNER_L2)
153 #define MLX5_FLOW_LAYER_L3_IPV4 \
154         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV4)
155 #define MLX5_FLOW_LAYER_L3_IPV6 \
156         (MLX5_FLOW_LAYER_OUTER_L3_IPV6 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
157 #define MLX5_FLOW_LAYER_L3 \
158         (MLX5_FLOW_LAYER_L3_IPV4 | MLX5_FLOW_LAYER_L3_IPV6)
159 #define MLX5_FLOW_LAYER_L4 \
160         (MLX5_FLOW_LAYER_OUTER_L4 | MLX5_FLOW_LAYER_INNER_L4)
161
162 /* Actions */
163 #define MLX5_FLOW_ACTION_DROP (1u << 0)
164 #define MLX5_FLOW_ACTION_QUEUE (1u << 1)
165 #define MLX5_FLOW_ACTION_RSS (1u << 2)
166 #define MLX5_FLOW_ACTION_FLAG (1u << 3)
167 #define MLX5_FLOW_ACTION_MARK (1u << 4)
168 #define MLX5_FLOW_ACTION_COUNT (1u << 5)
169 #define MLX5_FLOW_ACTION_PORT_ID (1u << 6)
170 #define MLX5_FLOW_ACTION_OF_POP_VLAN (1u << 7)
171 #define MLX5_FLOW_ACTION_OF_PUSH_VLAN (1u << 8)
172 #define MLX5_FLOW_ACTION_OF_SET_VLAN_VID (1u << 9)
173 #define MLX5_FLOW_ACTION_OF_SET_VLAN_PCP (1u << 10)
174 #define MLX5_FLOW_ACTION_SET_IPV4_SRC (1u << 11)
175 #define MLX5_FLOW_ACTION_SET_IPV4_DST (1u << 12)
176 #define MLX5_FLOW_ACTION_SET_IPV6_SRC (1u << 13)
177 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
178 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
179 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
180 #define MLX5_FLOW_ACTION_JUMP (1u << 17)
181 #define MLX5_FLOW_ACTION_SET_TTL (1u << 18)
182 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 19)
183 #define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 20)
184 #define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 21)
185 #define MLX5_FLOW_ACTION_ENCAP (1u << 22)
186 #define MLX5_FLOW_ACTION_DECAP (1u << 23)
187 #define MLX5_FLOW_ACTION_INC_TCP_SEQ (1u << 24)
188 #define MLX5_FLOW_ACTION_DEC_TCP_SEQ (1u << 25)
189 #define MLX5_FLOW_ACTION_INC_TCP_ACK (1u << 26)
190 #define MLX5_FLOW_ACTION_DEC_TCP_ACK (1u << 27)
191 #define MLX5_FLOW_ACTION_SET_TAG (1ull << 28)
192 #define MLX5_FLOW_ACTION_MARK_EXT (1ull << 29)
193 #define MLX5_FLOW_ACTION_SET_META (1ull << 30)
194 #define MLX5_FLOW_ACTION_METER (1ull << 31)
195 #define MLX5_FLOW_ACTION_SET_IPV4_DSCP (1ull << 32)
196 #define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)
197 #define MLX5_FLOW_ACTION_AGE (1ull << 34)
198 #define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35)
199 #define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)
200
201 #define MLX5_FLOW_FATE_ACTIONS \
202         (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
203          MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP | \
204          MLX5_FLOW_ACTION_DEFAULT_MISS)
205
206 #define MLX5_FLOW_FATE_ESWITCH_ACTIONS \
207         (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_PORT_ID | \
208          MLX5_FLOW_ACTION_JUMP)
209
210
211 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
212                                       MLX5_FLOW_ACTION_SET_IPV4_DST | \
213                                       MLX5_FLOW_ACTION_SET_IPV6_SRC | \
214                                       MLX5_FLOW_ACTION_SET_IPV6_DST | \
215                                       MLX5_FLOW_ACTION_SET_TP_SRC | \
216                                       MLX5_FLOW_ACTION_SET_TP_DST | \
217                                       MLX5_FLOW_ACTION_SET_TTL | \
218                                       MLX5_FLOW_ACTION_DEC_TTL | \
219                                       MLX5_FLOW_ACTION_SET_MAC_SRC | \
220                                       MLX5_FLOW_ACTION_SET_MAC_DST | \
221                                       MLX5_FLOW_ACTION_INC_TCP_SEQ | \
222                                       MLX5_FLOW_ACTION_DEC_TCP_SEQ | \
223                                       MLX5_FLOW_ACTION_INC_TCP_ACK | \
224                                       MLX5_FLOW_ACTION_DEC_TCP_ACK | \
225                                       MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
226                                       MLX5_FLOW_ACTION_SET_TAG | \
227                                       MLX5_FLOW_ACTION_MARK_EXT | \
228                                       MLX5_FLOW_ACTION_SET_META | \
229                                       MLX5_FLOW_ACTION_SET_IPV4_DSCP | \
230                                       MLX5_FLOW_ACTION_SET_IPV6_DSCP)
231
232 #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \
233                                 MLX5_FLOW_ACTION_OF_PUSH_VLAN)
234
235 #define MLX5_FLOW_XCAP_ACTIONS (MLX5_FLOW_ACTION_ENCAP | MLX5_FLOW_ACTION_DECAP)
236
237 #ifndef IPPROTO_MPLS
238 #define IPPROTO_MPLS 137
239 #endif
240
241 /* UDP port number for MPLS */
242 #define MLX5_UDP_PORT_MPLS 6635
243
244 /* UDP port numbers for VxLAN. */
245 #define MLX5_UDP_PORT_VXLAN 4789
246 #define MLX5_UDP_PORT_VXLAN_GPE 4790
247
248 /* UDP port numbers for GENEVE. */
249 #define MLX5_UDP_PORT_GENEVE 6081
250
251 /* Priority reserved for default flows. */
252 #define MLX5_FLOW_PRIO_RSVD ((uint32_t)-1)
253
254 /*
255  * Number of sub priorities.
256  * For each kind of pattern matching i.e. L2, L3, L4 to have a correct
257  * matching on the NIC (firmware dependent) L4 most have the higher priority
258  * followed by L3 and ending with L2.
259  */
260 #define MLX5_PRIORITY_MAP_L2 2
261 #define MLX5_PRIORITY_MAP_L3 1
262 #define MLX5_PRIORITY_MAP_L4 0
263 #define MLX5_PRIORITY_MAP_MAX 3
264
265 /* Valid layer type for IPV4 RSS. */
266 #define MLX5_IPV4_LAYER_TYPES \
267         (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | \
268          ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP | \
269          ETH_RSS_NONFRAG_IPV4_OTHER)
270
271 /* IBV hash source bits  for IPV4. */
272 #define MLX5_IPV4_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4)
273
274 /* Valid layer type for IPV6 RSS. */
275 #define MLX5_IPV6_LAYER_TYPES \
276         (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 | ETH_RSS_NONFRAG_IPV6_TCP | \
277          ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_IPV6_EX  | ETH_RSS_IPV6_TCP_EX | \
278          ETH_RSS_IPV6_UDP_EX | ETH_RSS_NONFRAG_IPV6_OTHER)
279
280 /* IBV hash source bits  for IPV6. */
281 #define MLX5_IPV6_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6)
282
283 /* IBV hash bits for L3 SRC. */
284 #define MLX5_L3_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_SRC_IPV6)
285
286 /* IBV hash bits for L3 DST. */
287 #define MLX5_L3_DST_IBV_RX_HASH (IBV_RX_HASH_DST_IPV4 | IBV_RX_HASH_DST_IPV6)
288
289 /* IBV hash bits for TCP. */
290 #define MLX5_TCP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \
291                               IBV_RX_HASH_DST_PORT_TCP)
292
293 /* IBV hash bits for UDP. */
294 #define MLX5_UDP_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_UDP | \
295                               IBV_RX_HASH_DST_PORT_UDP)
296
297 /* IBV hash bits for L4 SRC. */
298 #define MLX5_L4_SRC_IBV_RX_HASH (IBV_RX_HASH_SRC_PORT_TCP | \
299                                  IBV_RX_HASH_SRC_PORT_UDP)
300
301 /* IBV hash bits for L4 DST. */
302 #define MLX5_L4_DST_IBV_RX_HASH (IBV_RX_HASH_DST_PORT_TCP | \
303                                  IBV_RX_HASH_DST_PORT_UDP)
304
305 /* Geneve header first 16Bit */
306 #define MLX5_GENEVE_VER_MASK 0x3
307 #define MLX5_GENEVE_VER_SHIFT 14
308 #define MLX5_GENEVE_VER_VAL(a) \
309                 (((a) >> (MLX5_GENEVE_VER_SHIFT)) & (MLX5_GENEVE_VER_MASK))
310 #define MLX5_GENEVE_OPTLEN_MASK 0x3F
311 #define MLX5_GENEVE_OPTLEN_SHIFT 7
312 #define MLX5_GENEVE_OPTLEN_VAL(a) \
313             (((a) >> (MLX5_GENEVE_OPTLEN_SHIFT)) & (MLX5_GENEVE_OPTLEN_MASK))
314 #define MLX5_GENEVE_OAMF_MASK 0x1
315 #define MLX5_GENEVE_OAMF_SHIFT 7
316 #define MLX5_GENEVE_OAMF_VAL(a) \
317                 (((a) >> (MLX5_GENEVE_OAMF_SHIFT)) & (MLX5_GENEVE_OAMF_MASK))
318 #define MLX5_GENEVE_CRITO_MASK 0x1
319 #define MLX5_GENEVE_CRITO_SHIFT 6
320 #define MLX5_GENEVE_CRITO_VAL(a) \
321                 (((a) >> (MLX5_GENEVE_CRITO_SHIFT)) & (MLX5_GENEVE_CRITO_MASK))
322 #define MLX5_GENEVE_RSVD_MASK 0x3F
323 #define MLX5_GENEVE_RSVD_VAL(a) ((a) & (MLX5_GENEVE_RSVD_MASK))
324 /*
325  * The length of the Geneve options fields, expressed in four byte multiples,
326  * not including the eight byte fixed tunnel.
327  */
328 #define MLX5_GENEVE_OPT_LEN_0 14
329 #define MLX5_GENEVE_OPT_LEN_1 63
330
331 #define MLX5_ENCAPSULATION_DECISION_SIZE (sizeof(struct rte_flow_item_eth) + \
332                                           sizeof(struct rte_flow_item_ipv4))
333
334 /* IPv4 fragment_offset field contains relevant data in bits 2 to 15. */
335 #define MLX5_IPV4_FRAG_OFFSET_MASK \
336                 (RTE_IPV4_HDR_OFFSET_MASK | RTE_IPV4_HDR_MF_FLAG)
337
338 /* Specific item's fields can accept a range of values (using spec and last). */
339 #define MLX5_ITEM_RANGE_NOT_ACCEPTED    false
340 #define MLX5_ITEM_RANGE_ACCEPTED        true
341
342 /* Software header modify action numbers of a flow. */
343 #define MLX5_ACT_NUM_MDF_IPV4           1
344 #define MLX5_ACT_NUM_MDF_IPV6           4
345 #define MLX5_ACT_NUM_MDF_MAC            2
346 #define MLX5_ACT_NUM_MDF_VID            1
347 #define MLX5_ACT_NUM_MDF_PORT           2
348 #define MLX5_ACT_NUM_MDF_TTL            1
349 #define MLX5_ACT_NUM_DEC_TTL            MLX5_ACT_NUM_MDF_TTL
350 #define MLX5_ACT_NUM_MDF_TCPSEQ         1
351 #define MLX5_ACT_NUM_MDF_TCPACK         1
352 #define MLX5_ACT_NUM_SET_REG            1
353 #define MLX5_ACT_NUM_SET_TAG            1
354 #define MLX5_ACT_NUM_CPY_MREG           MLX5_ACT_NUM_SET_TAG
355 #define MLX5_ACT_NUM_SET_MARK           MLX5_ACT_NUM_SET_TAG
356 #define MLX5_ACT_NUM_SET_META           MLX5_ACT_NUM_SET_TAG
357 #define MLX5_ACT_NUM_SET_DSCP           1
358
359 enum mlx5_flow_drv_type {
360         MLX5_FLOW_TYPE_MIN,
361         MLX5_FLOW_TYPE_DV,
362         MLX5_FLOW_TYPE_VERBS,
363         MLX5_FLOW_TYPE_MAX,
364 };
365
366 /* Fate action type. */
367 enum mlx5_flow_fate_type {
368         MLX5_FLOW_FATE_NONE, /* Egress flow. */
369         MLX5_FLOW_FATE_QUEUE,
370         MLX5_FLOW_FATE_JUMP,
371         MLX5_FLOW_FATE_PORT_ID,
372         MLX5_FLOW_FATE_DROP,
373         MLX5_FLOW_FATE_DEFAULT_MISS,
374         MLX5_FLOW_FATE_MAX,
375 };
376
377 /* Matcher PRM representation */
378 struct mlx5_flow_dv_match_params {
379         size_t size;
380         /**< Size of match value. Do NOT split size and key! */
381         uint32_t buf[MLX5_ST_SZ_DW(fte_match_param)];
382         /**< Matcher value. This value is used as the mask or as a key. */
383 };
384
385 /* Matcher structure. */
386 struct mlx5_flow_dv_matcher {
387         LIST_ENTRY(mlx5_flow_dv_matcher) next;
388         /**< Pointer to the next element. */
389         struct mlx5_flow_tbl_resource *tbl;
390         /**< Pointer to the table(group) the matcher associated with. */
391         rte_atomic32_t refcnt; /**< Reference counter. */
392         void *matcher_object; /**< Pointer to DV matcher */
393         uint16_t crc; /**< CRC of key. */
394         uint16_t priority; /**< Priority of matcher. */
395         struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */
396 };
397
398 #define MLX5_ENCAP_MAX_LEN 132
399
400 /* Encap/decap resource key of the hash organization. */
401 union mlx5_flow_encap_decap_key {
402         struct {
403                 uint32_t ft_type:8;     /**< Flow table type, Rx or Tx. */
404                 uint32_t refmt_type:8;  /**< Header reformat type. */
405                 uint32_t buf_size:8;    /**< Encap buf size. */
406                 uint32_t table_level:8; /**< Root table or not. */
407                 uint32_t cksum;         /**< Encap buf check sum. */
408         };
409         uint64_t v64;                   /**< full 64bits value of key */
410 };
411
412 /* Encap/decap resource structure. */
413 struct mlx5_flow_dv_encap_decap_resource {
414         struct mlx5_hlist_entry entry;
415         /* Pointer to next element. */
416         rte_atomic32_t refcnt; /**< Reference counter. */
417         void *action;
418         /**< Encap/decap action object. */
419         uint8_t buf[MLX5_ENCAP_MAX_LEN];
420         size_t size;
421         uint8_t reformat_type;
422         uint8_t ft_type;
423         uint64_t flags; /**< Flags for RDMA API. */
424         uint32_t idx; /**< Index for the index memory pool. */
425 };
426
427 /* Tag resource structure. */
428 struct mlx5_flow_dv_tag_resource {
429         struct mlx5_hlist_entry entry;
430         /**< hash list entry for tag resource, tag value as the key. */
431         void *action;
432         /**< Tag action object. */
433         rte_atomic32_t refcnt; /**< Reference counter. */
434         uint32_t idx; /**< Index for the index memory pool. */
435 };
436
437 /*
438  * Number of modification commands.
439  * The maximal actions amount in FW is some constant, and it is 16 in the
440  * latest releases. In some old releases, it will be limited to 8.
441  * Since there is no interface to query the capacity, the maximal value should
442  * be used to allow PMD to create the flow. The validation will be done in the
443  * lower driver layer or FW. A failure will be returned if exceeds the maximal
444  * supported actions number on the root table.
445  * On non-root tables, there is no limitation, but 32 is enough right now.
446  */
447 #define MLX5_MAX_MODIFY_NUM                     32
448 #define MLX5_ROOT_TBL_MODIFY_NUM                16
449
450 /* Modify resource structure */
451 struct mlx5_flow_dv_modify_hdr_resource {
452         struct mlx5_hlist_entry entry;
453         /* Pointer to next element. */
454         rte_atomic32_t refcnt; /**< Reference counter. */
455         void *action;
456         /**< Modify header action object. */
457         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
458         uint32_t actions_num; /**< Number of modification actions. */
459         uint64_t flags; /**< Flags for RDMA API. */
460         struct mlx5_modification_cmd actions[];
461         /**< Modification actions. */
462 };
463
464 /* Modify resource key of the hash organization. */
465 union mlx5_flow_modify_hdr_key {
466         struct {
467                 uint32_t ft_type:8;     /**< Flow table type, Rx or Tx. */
468                 uint32_t actions_num:5; /**< Number of modification actions. */
469                 uint32_t group:19;      /**< Flow group id. */
470                 uint32_t cksum;         /**< Actions check sum. */
471         };
472         uint64_t v64;                   /**< full 64bits value of key */
473 };
474
475 /* Jump action resource structure. */
476 struct mlx5_flow_dv_jump_tbl_resource {
477         rte_atomic32_t refcnt; /**< Reference counter. */
478         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
479         void *action; /**< Pointer to the rdma core action. */
480 };
481
482 /* Port ID resource structure. */
483 struct mlx5_flow_dv_port_id_action_resource {
484         ILIST_ENTRY(uint32_t)next;
485         /* Pointer to next element. */
486         rte_atomic32_t refcnt; /**< Reference counter. */
487         void *action;
488         /**< Action object. */
489         uint32_t port_id; /**< Port ID value. */
490 };
491
492 /* Push VLAN action resource structure */
493 struct mlx5_flow_dv_push_vlan_action_resource {
494         ILIST_ENTRY(uint32_t)next;
495         /* Pointer to next element. */
496         rte_atomic32_t refcnt; /**< Reference counter. */
497         void *action; /**< Action object. */
498         uint8_t ft_type; /**< Flow table type, Rx, Tx or FDB. */
499         rte_be32_t vlan_tag; /**< VLAN tag value. */
500 };
501
502 /* Metadata register copy table entry. */
503 struct mlx5_flow_mreg_copy_resource {
504         /*
505          * Hash list entry for copy table.
506          *  - Key is 32/64-bit MARK action ID.
507          *  - MUST be the first entry.
508          */
509         struct mlx5_hlist_entry hlist_ent;
510         LIST_ENTRY(mlx5_flow_mreg_copy_resource) next;
511         /* List entry for device flows. */
512         uint32_t refcnt; /* Reference counter. */
513         uint32_t appcnt; /* Apply/Remove counter. */
514         uint32_t idx;
515         uint32_t rix_flow; /* Built flow for copy. */
516 };
517
518 /* Table data structure of the hash organization. */
519 struct mlx5_flow_tbl_data_entry {
520         struct mlx5_hlist_entry entry;
521         /**< hash list entry, 64-bits key inside. */
522         struct mlx5_flow_tbl_resource tbl;
523         /**< flow table resource. */
524         LIST_HEAD(matchers, mlx5_flow_dv_matcher) matchers;
525         /**< matchers' header associated with the flow table. */
526         struct mlx5_flow_dv_jump_tbl_resource jump;
527         /**< jump resource, at most one for each table created. */
528         uint32_t idx; /**< index for the indexed mempool. */
529 };
530
531 /* Sub rdma-core actions list. */
532 struct mlx5_flow_sub_actions_list {
533         uint32_t actions_num; /**< Number of sample actions. */
534         uint64_t action_flags;
535         void *dr_queue_action;
536         void *dr_tag_action;
537         void *dr_cnt_action;
538         void *dr_port_id_action;
539         void *dr_encap_action;
540 };
541
542 /* Sample sub-actions resource list. */
543 struct mlx5_flow_sub_actions_idx {
544         uint32_t rix_hrxq; /**< Hash Rx queue object index. */
545         uint32_t rix_tag; /**< Index to the tag action. */
546         uint32_t cnt;
547         uint32_t rix_port_id_action; /**< Index to port ID action resource. */
548         uint32_t rix_encap_decap; /**< Index to encap/decap resource. */
549 };
550
551 /* Sample action resource structure. */
552 struct mlx5_flow_dv_sample_resource {
553         ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
554         uint32_t refcnt; /**< Reference counter. */
555         void *verbs_action; /**< Verbs sample action object. */
556         uint8_t ft_type; /** Flow Table Type */
557         uint32_t ft_id; /** Flow Table Level */
558         uint32_t ratio;   /** Sample Ratio */
559         uint64_t set_action; /** Restore reg_c0 value */
560         void *normal_path_tbl; /** Flow Table pointer */
561         void *default_miss; /** default_miss dr_action. */
562         struct mlx5_flow_sub_actions_idx sample_idx;
563         /**< Action index resources. */
564         struct mlx5_flow_sub_actions_list sample_act;
565         /**< Action resources. */
566 };
567
568 #define MLX5_MAX_DEST_NUM       2
569
570 /* Destination array action resource structure. */
571 struct mlx5_flow_dv_dest_array_resource {
572         ILIST_ENTRY(uint32_t)next; /**< Pointer to next element. */
573         uint32_t refcnt; /**< Reference counter. */
574         uint8_t ft_type; /** Flow Table Type */
575         uint8_t num_of_dest; /**< Number of destination actions. */
576         void *action; /**< Pointer to the rdma core action. */
577         struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM];
578         /**< Action index resources. */
579         struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM];
580         /**< Action resources. */
581 };
582
583 /* Verbs specification header. */
584 struct ibv_spec_header {
585         enum ibv_flow_spec_type type;
586         uint16_t size;
587 };
588
589 /* RSS description. */
590 struct mlx5_flow_rss_desc {
591         uint32_t level;
592         uint32_t queue_num; /**< Number of entries in @p queue. */
593         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
594         uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */
595         uint16_t queue[]; /**< Destination queues to redirect traffic to. */
596 };
597
598 /* PMD flow priority for tunnel */
599 #define MLX5_TUNNEL_PRIO_GET(rss_desc) \
600         ((rss_desc)->level >= 2 ? MLX5_PRIORITY_MAP_L2 : MLX5_PRIORITY_MAP_L4)
601
602
603 /** Device flow handle structure for DV mode only. */
604 struct mlx5_flow_handle_dv {
605         /* Flow DV api: */
606         struct mlx5_flow_dv_matcher *matcher; /**< Cache to matcher. */
607         struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
608         /**< Pointer to modify header resource in cache. */
609         uint32_t rix_encap_decap;
610         /**< Index to encap/decap resource in cache. */
611         uint32_t rix_push_vlan;
612         /**< Index to push VLAN action resource in cache. */
613         uint32_t rix_tag;
614         /**< Index to the tag action. */
615         uint32_t rix_sample;
616         /**< Index to sample action resource in cache. */
617         uint32_t rix_dest_array;
618         /**< Index to destination array resource in cache. */
619 } __rte_packed;
620
621 /** Device flow handle structure: used both for creating & destroying. */
622 struct mlx5_flow_handle {
623         SILIST_ENTRY(uint32_t)next;
624         struct mlx5_vf_vlan vf_vlan; /**< Structure for VF VLAN workaround. */
625         /**< Index to next device flow handle. */
626         uint64_t layers;
627         /**< Bit-fields of present layers, see MLX5_FLOW_LAYER_*. */
628         void *drv_flow; /**< pointer to driver flow object. */
629         uint32_t split_flow_id:28; /**< Sub flow unique match flow id. */
630         uint32_t mark:1; /**< Metadate rxq mark flag. */
631         uint32_t fate_action:3; /**< Fate action type. */
632         union {
633                 uint32_t rix_hrxq; /**< Hash Rx queue object index. */
634                 uint32_t rix_jump; /**< Index to the jump action resource. */
635                 uint32_t rix_port_id_action;
636                 /**< Index to port ID action resource. */
637                 uint32_t rix_fate;
638                 /**< Generic value indicates the fate action. */
639                 uint32_t rix_default_fate;
640                 /**< Indicates default miss fate action. */
641         };
642 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
643         struct mlx5_flow_handle_dv dvh;
644 #endif
645 } __rte_packed;
646
647 /*
648  * Size for Verbs device flow handle structure only. Do not use the DV only
649  * structure in Verbs. No DV flows attributes will be accessed.
650  * Macro offsetof() could also be used here.
651  */
652 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
653 #define MLX5_FLOW_HANDLE_VERBS_SIZE \
654         (sizeof(struct mlx5_flow_handle) - sizeof(struct mlx5_flow_handle_dv))
655 #else
656 #define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))
657 #endif
658
659 /*
660  * Max number of actions per DV flow.
661  * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
662  * in rdma-core file providers/mlx5/verbs.c.
663  */
664 #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
665
666 /** Device flow structure only for DV flow creation. */
667 struct mlx5_flow_dv_workspace {
668         uint32_t group; /**< The group index. */
669         uint8_t transfer; /**< 1 if the flow is E-Switch flow. */
670         int actions_n; /**< number of actions. */
671         void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; /**< Action list. */
672         struct mlx5_flow_dv_encap_decap_resource *encap_decap;
673         /**< Pointer to encap/decap resource in cache. */
674         struct mlx5_flow_dv_push_vlan_action_resource *push_vlan_res;
675         /**< Pointer to push VLAN action resource in cache. */
676         struct mlx5_flow_dv_tag_resource *tag_resource;
677         /**< pointer to the tag action. */
678         struct mlx5_flow_dv_port_id_action_resource *port_id_action;
679         /**< Pointer to port ID action resource. */
680         struct mlx5_flow_dv_jump_tbl_resource *jump;
681         /**< Pointer to the jump action resource. */
682         struct mlx5_flow_dv_match_params value;
683         /**< Holds the value that the packet is compared to. */
684         struct mlx5_flow_dv_sample_resource *sample_res;
685         /**< Pointer to the sample action resource. */
686         struct mlx5_flow_dv_dest_array_resource *dest_array_res;
687         /**< Pointer to the destination array resource. */
688 };
689
690 /*
691  * Maximal Verbs flow specifications & actions size.
692  * Some elements are mutually exclusive, but enough space should be allocated.
693  * Tunnel cases: 1. Max 2 Ethernet + IP(v6 len > v4 len) + TCP/UDP headers.
694  *               2. One tunnel header (exception: GRE + MPLS),
695  *                  SPEC length: GRE == tunnel.
696  * Actions: 1. 1 Mark OR Flag.
697  *          2. 1 Drop (if any).
698  *          3. No limitation for counters, but it makes no sense to support too
699  *             many counters in a single device flow.
700  */
701 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
702 #define MLX5_VERBS_MAX_SPEC_SIZE \
703                 ( \
704                         (2 * (sizeof(struct ibv_flow_spec_eth) + \
705                               sizeof(struct ibv_flow_spec_ipv6) + \
706                               sizeof(struct ibv_flow_spec_tcp_udp)) + \
707                         sizeof(struct ibv_flow_spec_gre) + \
708                         sizeof(struct ibv_flow_spec_mpls)) \
709                 )
710 #else
711 #define MLX5_VERBS_MAX_SPEC_SIZE \
712                 ( \
713                         (2 * (sizeof(struct ibv_flow_spec_eth) + \
714                               sizeof(struct ibv_flow_spec_ipv6) + \
715                               sizeof(struct ibv_flow_spec_tcp_udp)) + \
716                         sizeof(struct ibv_flow_spec_tunnel)) \
717                 )
718 #endif
719
720 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \
721         defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
722 #define MLX5_VERBS_MAX_ACT_SIZE \
723                 ( \
724                         sizeof(struct ibv_flow_spec_action_tag) + \
725                         sizeof(struct ibv_flow_spec_action_drop) + \
726                         sizeof(struct ibv_flow_spec_counter_action) * 4 \
727                 )
728 #else
729 #define MLX5_VERBS_MAX_ACT_SIZE \
730                 ( \
731                         sizeof(struct ibv_flow_spec_action_tag) + \
732                         sizeof(struct ibv_flow_spec_action_drop) \
733                 )
734 #endif
735
736 #define MLX5_VERBS_MAX_SPEC_ACT_SIZE \
737                 (MLX5_VERBS_MAX_SPEC_SIZE + MLX5_VERBS_MAX_ACT_SIZE)
738
739 /** Device flow structure only for Verbs flow creation. */
740 struct mlx5_flow_verbs_workspace {
741         unsigned int size; /**< Size of the attribute. */
742         struct ibv_flow_attr attr; /**< Verbs flow attribute buffer. */
743         uint8_t specs[MLX5_VERBS_MAX_SPEC_ACT_SIZE];
744         /**< Specifications & actions buffer of verbs flow. */
745 };
746
747 /** Maximal number of device sub-flows supported. */
748 #define MLX5_NUM_MAX_DEV_FLOWS 32
749
750 /** Device flow structure. */
751 struct mlx5_flow {
752         struct rte_flow *flow; /**< Pointer to the main flow. */
753         uint32_t flow_idx; /**< The memory pool index to the main flow. */
754         uint64_t hash_fields; /**< Hash Rx queue hash fields. */
755         uint64_t act_flags;
756         /**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */
757         bool external; /**< true if the flow is created external to PMD. */
758         uint8_t ingress; /**< 1 if the flow is ingress. */
759         union {
760 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
761                 struct mlx5_flow_dv_workspace dv;
762 #endif
763                 struct mlx5_flow_verbs_workspace verbs;
764         };
765         struct mlx5_flow_handle *handle;
766         uint32_t handle_idx; /* Index of the mlx5 flow handle memory. */
767 };
768
769 /* Flow meter state. */
770 #define MLX5_FLOW_METER_DISABLE 0
771 #define MLX5_FLOW_METER_ENABLE 1
772
773 #define MLX5_MAN_WIDTH 8
774 /* Modify this value if enum rte_mtr_color changes. */
775 #define RTE_MTR_DROPPED RTE_COLORS
776
777 /* Meter policer statistics */
778 struct mlx5_flow_policer_stats {
779         uint32_t cnt[RTE_COLORS + 1];
780         /**< Color counter, extra for drop. */
781         uint64_t stats_mask;
782         /**< Statistics mask for the colors. */
783 };
784
785 /* Meter table structure. */
786 struct mlx5_meter_domain_info {
787         struct mlx5_flow_tbl_resource *tbl;
788         /**< Meter table. */
789         struct mlx5_flow_tbl_resource *sfx_tbl;
790         /**< Meter suffix table. */
791         void *any_matcher;
792         /**< Meter color not match default criteria. */
793         void *color_matcher;
794         /**< Meter color match criteria. */
795         void *jump_actn;
796         /**< Meter match action. */
797         void *policer_rules[RTE_MTR_DROPPED + 1];
798         /**< Meter policer for the match. */
799 };
800
801 /* Meter table set for TX RX FDB. */
802 struct mlx5_meter_domains_infos {
803         uint32_t ref_cnt;
804         /**< Table user count. */
805         struct mlx5_meter_domain_info egress;
806         /**< TX meter table. */
807         struct mlx5_meter_domain_info ingress;
808         /**< RX meter table. */
809         struct mlx5_meter_domain_info transfer;
810         /**< FDB meter table. */
811         void *drop_actn;
812         /**< Drop action as not matched. */
813         void *count_actns[RTE_MTR_DROPPED + 1];
814         /**< Counters for match and unmatched statistics. */
815         uint32_t fmp[MLX5_ST_SZ_DW(flow_meter_parameters)];
816         /**< Flow meter parameter. */
817         size_t fmp_size;
818         /**< Flow meter parameter size. */
819         void *meter_action;
820         /**< Flow meter action. */
821 };
822
823 /* Meter parameter structure. */
824 struct mlx5_flow_meter {
825         TAILQ_ENTRY(mlx5_flow_meter) next;
826         /**< Pointer to the next flow meter structure. */
827         uint32_t idx; /* Index to meter object. */
828         uint32_t meter_id;
829         /**< Meter id. */
830         struct mlx5_flow_meter_profile *profile;
831         /**< Meter profile parameters. */
832
833         /** Policer actions (per meter output color). */
834         enum rte_mtr_policer_action action[RTE_COLORS];
835
836         /** Set of stats counters to be enabled.
837          * @see enum rte_mtr_stats_type
838          */
839         uint64_t stats_mask;
840
841         /**< Rule applies to ingress traffic. */
842         uint32_t ingress:1;
843
844         /**< Rule applies to egress traffic. */
845         uint32_t egress:1;
846         /**
847          * Instead of simply matching the properties of traffic as it would
848          * appear on a given DPDK port ID, enabling this attribute transfers
849          * a flow rule to the lowest possible level of any device endpoints
850          * found in the pattern.
851          *
852          * When supported, this effectively enables an application to
853          * re-route traffic not necessarily intended for it (e.g. coming
854          * from or addressed to different physical ports, VFs or
855          * applications) at the device level.
856          *
857          * It complements the behavior of some pattern items such as
858          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
859          *
860          * When transferring flow rules, ingress and egress attributes keep
861          * their original meaning, as if processing traffic emitted or
862          * received by the application.
863          */
864         uint32_t transfer:1;
865         struct mlx5_meter_domains_infos *mfts;
866         /**< Flow table created for this meter. */
867         struct mlx5_flow_policer_stats policer_stats;
868         /**< Meter policer statistics. */
869         uint32_t ref_cnt;
870         /**< Use count. */
871         uint32_t active_state:1;
872         /**< Meter state. */
873         uint32_t shared:1;
874         /**< Meter shared or not. */
875 };
876
877 /* RFC2697 parameter structure. */
878 struct mlx5_flow_meter_srtcm_rfc2697_prm {
879         /* green_saturation_value = cbs_mantissa * 2^cbs_exponent */
880         uint32_t cbs_exponent:5;
881         uint32_t cbs_mantissa:8;
882         /* cir = 8G * cir_mantissa * 1/(2^cir_exponent) Bytes/Sec */
883         uint32_t cir_exponent:5;
884         uint32_t cir_mantissa:8;
885         /* yellow _saturation_value = ebs_mantissa * 2^ebs_exponent */
886         uint32_t ebs_exponent:5;
887         uint32_t ebs_mantissa:8;
888 };
889
890 /* Flow meter profile structure. */
891 struct mlx5_flow_meter_profile {
892         TAILQ_ENTRY(mlx5_flow_meter_profile) next;
893         /**< Pointer to the next flow meter structure. */
894         uint32_t meter_profile_id; /**< Profile id. */
895         struct rte_mtr_meter_profile profile; /**< Profile detail. */
896         union {
897                 struct mlx5_flow_meter_srtcm_rfc2697_prm srtcm_prm;
898                 /**< srtcm_rfc2697 struct. */
899         };
900         uint32_t ref_cnt; /**< Use count. */
901 };
902
903 /* Fdir flow structure */
904 struct mlx5_fdir_flow {
905         LIST_ENTRY(mlx5_fdir_flow) next; /* Pointer to the next element. */
906         struct mlx5_fdir *fdir; /* Pointer to fdir. */
907         uint32_t rix_flow; /* Index to flow. */
908 };
909
910 #define HAIRPIN_FLOW_ID_BITS 28
911
912 /* Flow structure. */
913 struct rte_flow {
914         ILIST_ENTRY(uint32_t)next; /**< Index to the next flow structure. */
915         uint32_t dev_handles;
916         /**< Device flow handles that are part of the flow. */
917         uint32_t drv_type:2; /**< Driver type. */
918         uint32_t fdir:1; /**< Identifier of associated FDIR if any. */
919         uint32_t hairpin_flow_id:HAIRPIN_FLOW_ID_BITS;
920         /**< The flow id used for hairpin. */
921         uint32_t copy_applied:1; /**< The MARK copy Flow os applied. */
922         uint32_t rix_mreg_copy;
923         /**< Index to metadata register copy table resource. */
924         uint32_t counter; /**< Holds flow counter. */
925         uint16_t meter; /**< Holds flow meter id. */
926 } __rte_packed;
927
928 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev,
929                                     const struct rte_flow_attr *attr,
930                                     const struct rte_flow_item items[],
931                                     const struct rte_flow_action actions[],
932                                     bool external,
933                                     int hairpin,
934                                     struct rte_flow_error *error);
935 typedef struct mlx5_flow *(*mlx5_flow_prepare_t)
936         (struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
937          const struct rte_flow_item items[],
938          const struct rte_flow_action actions[], struct rte_flow_error *error);
939 typedef int (*mlx5_flow_translate_t)(struct rte_eth_dev *dev,
940                                      struct mlx5_flow *dev_flow,
941                                      const struct rte_flow_attr *attr,
942                                      const struct rte_flow_item items[],
943                                      const struct rte_flow_action actions[],
944                                      struct rte_flow_error *error);
945 typedef int (*mlx5_flow_apply_t)(struct rte_eth_dev *dev, struct rte_flow *flow,
946                                  struct rte_flow_error *error);
947 typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev,
948                                    struct rte_flow *flow);
949 typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev,
950                                     struct rte_flow *flow);
951 typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
952                                  struct rte_flow *flow,
953                                  const struct rte_flow_action *actions,
954                                  void *data,
955                                  struct rte_flow_error *error);
956 typedef struct mlx5_meter_domains_infos *(*mlx5_flow_create_mtr_tbls_t)
957                                             (struct rte_eth_dev *dev,
958                                              const struct mlx5_flow_meter *fm);
959 typedef int (*mlx5_flow_destroy_mtr_tbls_t)(struct rte_eth_dev *dev,
960                                         struct mlx5_meter_domains_infos *tbls);
961 typedef int (*mlx5_flow_create_policer_rules_t)
962                                         (struct rte_eth_dev *dev,
963                                          struct mlx5_flow_meter *fm,
964                                          const struct rte_flow_attr *attr);
965 typedef int (*mlx5_flow_destroy_policer_rules_t)
966                                         (struct rte_eth_dev *dev,
967                                          const struct mlx5_flow_meter *fm,
968                                          const struct rte_flow_attr *attr);
969 typedef uint32_t (*mlx5_flow_counter_alloc_t)
970                                    (struct rte_eth_dev *dev);
971 typedef void (*mlx5_flow_counter_free_t)(struct rte_eth_dev *dev,
972                                          uint32_t cnt);
973 typedef int (*mlx5_flow_counter_query_t)(struct rte_eth_dev *dev,
974                                          uint32_t cnt,
975                                          bool clear, uint64_t *pkts,
976                                          uint64_t *bytes);
977 typedef int (*mlx5_flow_get_aged_flows_t)
978                                         (struct rte_eth_dev *dev,
979                                          void **context,
980                                          uint32_t nb_contexts,
981                                          struct rte_flow_error *error);
982 struct mlx5_flow_driver_ops {
983         mlx5_flow_validate_t validate;
984         mlx5_flow_prepare_t prepare;
985         mlx5_flow_translate_t translate;
986         mlx5_flow_apply_t apply;
987         mlx5_flow_remove_t remove;
988         mlx5_flow_destroy_t destroy;
989         mlx5_flow_query_t query;
990         mlx5_flow_create_mtr_tbls_t create_mtr_tbls;
991         mlx5_flow_destroy_mtr_tbls_t destroy_mtr_tbls;
992         mlx5_flow_create_policer_rules_t create_policer_rules;
993         mlx5_flow_destroy_policer_rules_t destroy_policer_rules;
994         mlx5_flow_counter_alloc_t counter_alloc;
995         mlx5_flow_counter_free_t counter_free;
996         mlx5_flow_counter_query_t counter_query;
997         mlx5_flow_get_aged_flows_t get_aged_flows;
998 };
999
1000 /* mlx5_flow.c */
1001
1002 struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(uint32_t max_id);
1003 void mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool);
1004 uint32_t mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id);
1005 uint32_t mlx5_flow_id_release(struct mlx5_flow_id_pool *pool,
1006                               uint32_t id);
1007 int mlx5_flow_group_to_table(const struct rte_flow_attr *attributes,
1008                              bool external, uint32_t group, bool fdb_def_rule,
1009                              uint32_t *table, struct rte_flow_error *error);
1010 uint64_t mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
1011                                      int tunnel, uint64_t layer_types,
1012                                      uint64_t hash_fields);
1013 int mlx5_flow_discover_priorities(struct rte_eth_dev *dev);
1014 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
1015                                    uint32_t subpriority);
1016 int mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
1017                                      enum mlx5_feature_name feature,
1018                                      uint32_t id,
1019                                      struct rte_flow_error *error);
1020 const struct rte_flow_action *mlx5_flow_find_action
1021                                         (const struct rte_flow_action *actions,
1022                                          enum rte_flow_action_type action);
1023 int mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
1024                                     const struct rte_flow_attr *attr,
1025                                     struct rte_flow_error *error);
1026 int mlx5_flow_validate_action_drop(uint64_t action_flags,
1027                                    const struct rte_flow_attr *attr,
1028                                    struct rte_flow_error *error);
1029 int mlx5_flow_validate_action_flag(uint64_t action_flags,
1030                                    const struct rte_flow_attr *attr,
1031                                    struct rte_flow_error *error);
1032 int mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
1033                                    uint64_t action_flags,
1034                                    const struct rte_flow_attr *attr,
1035                                    struct rte_flow_error *error);
1036 int mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
1037                                     uint64_t action_flags,
1038                                     struct rte_eth_dev *dev,
1039                                     const struct rte_flow_attr *attr,
1040                                     struct rte_flow_error *error);
1041 int mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
1042                                   uint64_t action_flags,
1043                                   struct rte_eth_dev *dev,
1044                                   const struct rte_flow_attr *attr,
1045                                   uint64_t item_flags,
1046                                   struct rte_flow_error *error);
1047 int mlx5_flow_validate_action_default_miss(uint64_t action_flags,
1048                                 const struct rte_flow_attr *attr,
1049                                 struct rte_flow_error *error);
1050 int mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
1051                                   const struct rte_flow_attr *attributes,
1052                                   struct rte_flow_error *error);
1053 int mlx5_flow_item_acceptable(const struct rte_flow_item *item,
1054                               const uint8_t *mask,
1055                               const uint8_t *nic_mask,
1056                               unsigned int size,
1057                               bool range_accepted,
1058                               struct rte_flow_error *error);
1059 int mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
1060                                 uint64_t item_flags,
1061                                 struct rte_flow_error *error);
1062 int mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
1063                                 uint64_t item_flags,
1064                                 uint8_t target_protocol,
1065                                 struct rte_flow_error *error);
1066 int mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
1067                                     uint64_t item_flags,
1068                                     const struct rte_flow_item *gre_item,
1069                                     struct rte_flow_error *error);
1070 int mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
1071                                  uint64_t item_flags,
1072                                  uint64_t last_item,
1073                                  uint16_t ether_type,
1074                                  const struct rte_flow_item_ipv4 *acc_mask,
1075                                  bool range_accepted,
1076                                  struct rte_flow_error *error);
1077 int mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
1078                                  uint64_t item_flags,
1079                                  uint64_t last_item,
1080                                  uint16_t ether_type,
1081                                  const struct rte_flow_item_ipv6 *acc_mask,
1082                                  struct rte_flow_error *error);
1083 int mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev,
1084                                  const struct rte_flow_item *item,
1085                                  uint64_t item_flags,
1086                                  uint64_t prev_layer,
1087                                  struct rte_flow_error *error);
1088 int mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
1089                                 uint64_t item_flags,
1090                                 uint8_t target_protocol,
1091                                 const struct rte_flow_item_tcp *flow_mask,
1092                                 struct rte_flow_error *error);
1093 int mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
1094                                 uint64_t item_flags,
1095                                 uint8_t target_protocol,
1096                                 struct rte_flow_error *error);
1097 int mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
1098                                  uint64_t item_flags,
1099                                  struct rte_eth_dev *dev,
1100                                  struct rte_flow_error *error);
1101 int mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
1102                                   uint64_t item_flags,
1103                                   struct rte_flow_error *error);
1104 int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
1105                                       uint64_t item_flags,
1106                                       struct rte_eth_dev *dev,
1107                                       struct rte_flow_error *error);
1108 int mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
1109                                  uint64_t item_flags,
1110                                  uint8_t target_protocol,
1111                                  struct rte_flow_error *error);
1112 int mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
1113                                    uint64_t item_flags,
1114                                    uint8_t target_protocol,
1115                                    struct rte_flow_error *error);
1116 int mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
1117                                   uint64_t item_flags,
1118                                   uint8_t target_protocol,
1119                                   struct rte_flow_error *error);
1120 int mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
1121                                    uint64_t item_flags,
1122                                    struct rte_eth_dev *dev,
1123                                    struct rte_flow_error *error);
1124 int mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
1125                                   uint64_t item_flags,
1126                                   uint64_t last_item,
1127                                   uint16_t ether_type,
1128                                   const struct rte_flow_item_ecpri *acc_mask,
1129                                   struct rte_flow_error *error);
1130 struct mlx5_meter_domains_infos *mlx5_flow_create_mtr_tbls
1131                                         (struct rte_eth_dev *dev,
1132                                          const struct mlx5_flow_meter *fm);
1133 int mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
1134                                struct mlx5_meter_domains_infos *tbl);
1135 int mlx5_flow_create_policer_rules(struct rte_eth_dev *dev,
1136                                    struct mlx5_flow_meter *fm,
1137                                    const struct rte_flow_attr *attr);
1138 int mlx5_flow_destroy_policer_rules(struct rte_eth_dev *dev,
1139                                     struct mlx5_flow_meter *fm,
1140                                     const struct rte_flow_attr *attr);
1141 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
1142                           struct rte_mtr_error *error);
1143 #endif /* RTE_PMD_MLX5_FLOW_H_ */