net/mlx5: add metadata register copy table
[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 /* Verbs header. */
15 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
16 #ifdef PEDANTIC
17 #pragma GCC diagnostic ignored "-Wpedantic"
18 #endif
19 #include <infiniband/verbs.h>
20 #ifdef PEDANTIC
21 #pragma GCC diagnostic error "-Wpedantic"
22 #endif
23
24 #include <rte_atomic.h>
25 #include <rte_alarm.h>
26
27 #include "mlx5.h"
28 #include "mlx5_prm.h"
29
30 /* Private rte flow items. */
31 enum mlx5_rte_flow_item_type {
32         MLX5_RTE_FLOW_ITEM_TYPE_END = INT_MIN,
33         MLX5_RTE_FLOW_ITEM_TYPE_TAG,
34         MLX5_RTE_FLOW_ITEM_TYPE_TX_QUEUE,
35 };
36
37 /* Private (internal) rte flow actions. */
38 enum mlx5_rte_flow_action_type {
39         MLX5_RTE_FLOW_ACTION_TYPE_END = INT_MIN,
40         MLX5_RTE_FLOW_ACTION_TYPE_TAG,
41         MLX5_RTE_FLOW_ACTION_TYPE_MARK,
42         MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
43 };
44
45 /* Matches on selected register. */
46 struct mlx5_rte_flow_item_tag {
47         enum modify_reg id;
48         uint32_t data;
49 };
50
51 /* Modify selected register. */
52 struct mlx5_rte_flow_action_set_tag {
53         enum modify_reg id;
54         uint32_t data;
55 };
56
57 struct mlx5_flow_action_copy_mreg {
58         enum modify_reg dst;
59         enum modify_reg src;
60 };
61
62 /* Matches on source queue. */
63 struct mlx5_rte_flow_item_tx_queue {
64         uint32_t queue;
65 };
66
67 /* Feature name to allocate metadata register. */
68 enum mlx5_feature_name {
69         MLX5_HAIRPIN_RX,
70         MLX5_HAIRPIN_TX,
71         MLX5_METADATA_RX,
72         MLX5_METADATA_TX,
73         MLX5_METADATA_FDB,
74         MLX5_FLOW_MARK,
75         MLX5_APP_TAG,
76         MLX5_COPY_MARK,
77 };
78
79 /* Pattern outer Layer bits. */
80 #define MLX5_FLOW_LAYER_OUTER_L2 (1u << 0)
81 #define MLX5_FLOW_LAYER_OUTER_L3_IPV4 (1u << 1)
82 #define MLX5_FLOW_LAYER_OUTER_L3_IPV6 (1u << 2)
83 #define MLX5_FLOW_LAYER_OUTER_L4_UDP (1u << 3)
84 #define MLX5_FLOW_LAYER_OUTER_L4_TCP (1u << 4)
85 #define MLX5_FLOW_LAYER_OUTER_VLAN (1u << 5)
86
87 /* Pattern inner Layer bits. */
88 #define MLX5_FLOW_LAYER_INNER_L2 (1u << 6)
89 #define MLX5_FLOW_LAYER_INNER_L3_IPV4 (1u << 7)
90 #define MLX5_FLOW_LAYER_INNER_L3_IPV6 (1u << 8)
91 #define MLX5_FLOW_LAYER_INNER_L4_UDP (1u << 9)
92 #define MLX5_FLOW_LAYER_INNER_L4_TCP (1u << 10)
93 #define MLX5_FLOW_LAYER_INNER_VLAN (1u << 11)
94
95 /* Pattern tunnel Layer bits. */
96 #define MLX5_FLOW_LAYER_VXLAN (1u << 12)
97 #define MLX5_FLOW_LAYER_VXLAN_GPE (1u << 13)
98 #define MLX5_FLOW_LAYER_GRE (1u << 14)
99 #define MLX5_FLOW_LAYER_MPLS (1u << 15)
100 /* List of tunnel Layer bits continued below. */
101
102 /* General pattern items bits. */
103 #define MLX5_FLOW_ITEM_METADATA (1u << 16)
104 #define MLX5_FLOW_ITEM_PORT_ID (1u << 17)
105 #define MLX5_FLOW_ITEM_TAG (1u << 18)
106 #define MLX5_FLOW_ITEM_MARK (1u << 19)
107
108 /* Pattern MISC bits. */
109 #define MLX5_FLOW_LAYER_ICMP (1u << 19)
110 #define MLX5_FLOW_LAYER_ICMP6 (1u << 20)
111 #define MLX5_FLOW_LAYER_GRE_KEY (1u << 21)
112
113 /* Pattern tunnel Layer bits (continued). */
114 #define MLX5_FLOW_LAYER_IPIP (1u << 21)
115 #define MLX5_FLOW_LAYER_IPV6_ENCAP (1u << 22)
116 #define MLX5_FLOW_LAYER_NVGRE (1u << 23)
117 #define MLX5_FLOW_LAYER_GENEVE (1u << 24)
118
119 /* Queue items. */
120 #define MLX5_FLOW_ITEM_TX_QUEUE (1u << 25)
121
122 /* Outer Masks. */
123 #define MLX5_FLOW_LAYER_OUTER_L3 \
124         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
125 #define MLX5_FLOW_LAYER_OUTER_L4 \
126         (MLX5_FLOW_LAYER_OUTER_L4_UDP | MLX5_FLOW_LAYER_OUTER_L4_TCP)
127 #define MLX5_FLOW_LAYER_OUTER \
128         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_OUTER_L3 | \
129          MLX5_FLOW_LAYER_OUTER_L4)
130
131 /* LRO support mask, i.e. flow contains IPv4/IPv6 and TCP. */
132 #define MLX5_FLOW_LAYER_IPV4_LRO \
133         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L4_TCP)
134 #define MLX5_FLOW_LAYER_IPV6_LRO \
135         (MLX5_FLOW_LAYER_OUTER_L3_IPV6 | MLX5_FLOW_LAYER_OUTER_L4_TCP)
136
137 /* Tunnel Masks. */
138 #define MLX5_FLOW_LAYER_TUNNEL \
139         (MLX5_FLOW_LAYER_VXLAN | MLX5_FLOW_LAYER_VXLAN_GPE | \
140          MLX5_FLOW_LAYER_GRE | MLX5_FLOW_LAYER_NVGRE | MLX5_FLOW_LAYER_MPLS | \
141          MLX5_FLOW_LAYER_IPIP | MLX5_FLOW_LAYER_IPV6_ENCAP | \
142          MLX5_FLOW_LAYER_GENEVE)
143
144 /* Inner Masks. */
145 #define MLX5_FLOW_LAYER_INNER_L3 \
146         (MLX5_FLOW_LAYER_INNER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
147 #define MLX5_FLOW_LAYER_INNER_L4 \
148         (MLX5_FLOW_LAYER_INNER_L4_UDP | MLX5_FLOW_LAYER_INNER_L4_TCP)
149 #define MLX5_FLOW_LAYER_INNER \
150         (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3 | \
151          MLX5_FLOW_LAYER_INNER_L4)
152
153 /* Layer Masks. */
154 #define MLX5_FLOW_LAYER_L2 \
155         (MLX5_FLOW_LAYER_OUTER_L2 | MLX5_FLOW_LAYER_INNER_L2)
156 #define MLX5_FLOW_LAYER_L3_IPV4 \
157         (MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_INNER_L3_IPV4)
158 #define MLX5_FLOW_LAYER_L3_IPV6 \
159         (MLX5_FLOW_LAYER_OUTER_L3_IPV6 | MLX5_FLOW_LAYER_INNER_L3_IPV6)
160 #define MLX5_FLOW_LAYER_L3 \
161         (MLX5_FLOW_LAYER_L3_IPV4 | MLX5_FLOW_LAYER_L3_IPV6)
162 #define MLX5_FLOW_LAYER_L4 \
163         (MLX5_FLOW_LAYER_OUTER_L4 | MLX5_FLOW_LAYER_INNER_L4)
164
165 /* Actions */
166 #define MLX5_FLOW_ACTION_DROP (1u << 0)
167 #define MLX5_FLOW_ACTION_QUEUE (1u << 1)
168 #define MLX5_FLOW_ACTION_RSS (1u << 2)
169 #define MLX5_FLOW_ACTION_FLAG (1u << 3)
170 #define MLX5_FLOW_ACTION_MARK (1u << 4)
171 #define MLX5_FLOW_ACTION_COUNT (1u << 5)
172 #define MLX5_FLOW_ACTION_PORT_ID (1u << 6)
173 #define MLX5_FLOW_ACTION_OF_POP_VLAN (1u << 7)
174 #define MLX5_FLOW_ACTION_OF_PUSH_VLAN (1u << 8)
175 #define MLX5_FLOW_ACTION_OF_SET_VLAN_VID (1u << 9)
176 #define MLX5_FLOW_ACTION_OF_SET_VLAN_PCP (1u << 10)
177 #define MLX5_FLOW_ACTION_SET_IPV4_SRC (1u << 11)
178 #define MLX5_FLOW_ACTION_SET_IPV4_DST (1u << 12)
179 #define MLX5_FLOW_ACTION_SET_IPV6_SRC (1u << 13)
180 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
181 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
182 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
183 #define MLX5_FLOW_ACTION_JUMP (1u << 17)
184 #define MLX5_FLOW_ACTION_SET_TTL (1u << 18)
185 #define MLX5_FLOW_ACTION_DEC_TTL (1u << 19)
186 #define MLX5_FLOW_ACTION_SET_MAC_SRC (1u << 20)
187 #define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 21)
188 #define MLX5_FLOW_ACTION_VXLAN_ENCAP (1u << 22)
189 #define MLX5_FLOW_ACTION_VXLAN_DECAP (1u << 23)
190 #define MLX5_FLOW_ACTION_NVGRE_ENCAP (1u << 24)
191 #define MLX5_FLOW_ACTION_NVGRE_DECAP (1u << 25)
192 #define MLX5_FLOW_ACTION_RAW_ENCAP (1u << 26)
193 #define MLX5_FLOW_ACTION_RAW_DECAP (1u << 27)
194 #define MLX5_FLOW_ACTION_INC_TCP_SEQ (1u << 28)
195 #define MLX5_FLOW_ACTION_DEC_TCP_SEQ (1u << 29)
196 #define MLX5_FLOW_ACTION_INC_TCP_ACK (1u << 30)
197 #define MLX5_FLOW_ACTION_DEC_TCP_ACK (1u << 31)
198 #define MLX5_FLOW_ACTION_SET_TAG (1ull << 32)
199 #define MLX5_FLOW_ACTION_MARK_EXT (1ull << 33)
200 #define MLX5_FLOW_ACTION_SET_META (1ull << 34)
201
202 #define MLX5_FLOW_FATE_ACTIONS \
203         (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
204          MLX5_FLOW_ACTION_RSS | MLX5_FLOW_ACTION_JUMP)
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 #define MLX5_FLOW_ENCAP_ACTIONS (MLX5_FLOW_ACTION_VXLAN_ENCAP | \
211                                  MLX5_FLOW_ACTION_NVGRE_ENCAP | \
212                                  MLX5_FLOW_ACTION_RAW_ENCAP | \
213                                  MLX5_FLOW_ACTION_OF_PUSH_VLAN)
214
215 #define MLX5_FLOW_DECAP_ACTIONS (MLX5_FLOW_ACTION_VXLAN_DECAP | \
216                                  MLX5_FLOW_ACTION_NVGRE_DECAP | \
217                                  MLX5_FLOW_ACTION_RAW_DECAP | \
218                                  MLX5_FLOW_ACTION_OF_POP_VLAN)
219
220 #define MLX5_FLOW_MODIFY_HDR_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \
221                                       MLX5_FLOW_ACTION_SET_IPV4_DST | \
222                                       MLX5_FLOW_ACTION_SET_IPV6_SRC | \
223                                       MLX5_FLOW_ACTION_SET_IPV6_DST | \
224                                       MLX5_FLOW_ACTION_SET_TP_SRC | \
225                                       MLX5_FLOW_ACTION_SET_TP_DST | \
226                                       MLX5_FLOW_ACTION_SET_TTL | \
227                                       MLX5_FLOW_ACTION_DEC_TTL | \
228                                       MLX5_FLOW_ACTION_SET_MAC_SRC | \
229                                       MLX5_FLOW_ACTION_SET_MAC_DST | \
230                                       MLX5_FLOW_ACTION_INC_TCP_SEQ | \
231                                       MLX5_FLOW_ACTION_DEC_TCP_SEQ | \
232                                       MLX5_FLOW_ACTION_INC_TCP_ACK | \
233                                       MLX5_FLOW_ACTION_DEC_TCP_ACK | \
234                                       MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
235                                       MLX5_FLOW_ACTION_SET_TAG | \
236                                       MLX5_FLOW_ACTION_MARK_EXT | \
237                                       MLX5_FLOW_ACTION_SET_META)
238
239 #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \
240                                 MLX5_FLOW_ACTION_OF_PUSH_VLAN)
241 #ifndef IPPROTO_MPLS
242 #define IPPROTO_MPLS 137
243 #endif
244
245 /* UDP port number for MPLS */
246 #define MLX5_UDP_PORT_MPLS 6635
247
248 /* UDP port numbers for VxLAN. */
249 #define MLX5_UDP_PORT_VXLAN 4789
250 #define MLX5_UDP_PORT_VXLAN_GPE 4790
251
252 /* UDP port numbers for GENEVE. */
253 #define MLX5_UDP_PORT_GENEVE 6081
254
255 /* Priority reserved for default flows. */
256 #define MLX5_FLOW_PRIO_RSVD ((uint32_t)-1)
257
258 /*
259  * Number of sub priorities.
260  * For each kind of pattern matching i.e. L2, L3, L4 to have a correct
261  * matching on the NIC (firmware dependent) L4 most have the higher priority
262  * followed by L3 and ending with L2.
263  */
264 #define MLX5_PRIORITY_MAP_L2 2
265 #define MLX5_PRIORITY_MAP_L3 1
266 #define MLX5_PRIORITY_MAP_L4 0
267 #define MLX5_PRIORITY_MAP_MAX 3
268
269 /* Valid layer type for IPV4 RSS. */
270 #define MLX5_IPV4_LAYER_TYPES \
271         (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | \
272          ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP | \
273          ETH_RSS_NONFRAG_IPV4_OTHER)
274
275 /* IBV hash source bits  for IPV4. */
276 #define MLX5_IPV4_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV4 | IBV_RX_HASH_DST_IPV4)
277
278 /* Valid layer type for IPV6 RSS. */
279 #define MLX5_IPV6_LAYER_TYPES \
280         (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 | ETH_RSS_NONFRAG_IPV6_TCP | \
281          ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_IPV6_EX  | ETH_RSS_IPV6_TCP_EX | \
282          ETH_RSS_IPV6_UDP_EX | ETH_RSS_NONFRAG_IPV6_OTHER)
283
284 /* IBV hash source bits  for IPV6. */
285 #define MLX5_IPV6_IBV_RX_HASH (IBV_RX_HASH_SRC_IPV6 | IBV_RX_HASH_DST_IPV6)
286
287
288 /* Geneve header first 16Bit */
289 #define MLX5_GENEVE_VER_MASK 0x3
290 #define MLX5_GENEVE_VER_SHIFT 14
291 #define MLX5_GENEVE_VER_VAL(a) \
292                 (((a) >> (MLX5_GENEVE_VER_SHIFT)) & (MLX5_GENEVE_VER_MASK))
293 #define MLX5_GENEVE_OPTLEN_MASK 0x3F
294 #define MLX5_GENEVE_OPTLEN_SHIFT 7
295 #define MLX5_GENEVE_OPTLEN_VAL(a) \
296             (((a) >> (MLX5_GENEVE_OPTLEN_SHIFT)) & (MLX5_GENEVE_OPTLEN_MASK))
297 #define MLX5_GENEVE_OAMF_MASK 0x1
298 #define MLX5_GENEVE_OAMF_SHIFT 7
299 #define MLX5_GENEVE_OAMF_VAL(a) \
300                 (((a) >> (MLX5_GENEVE_OAMF_SHIFT)) & (MLX5_GENEVE_OAMF_MASK))
301 #define MLX5_GENEVE_CRITO_MASK 0x1
302 #define MLX5_GENEVE_CRITO_SHIFT 6
303 #define MLX5_GENEVE_CRITO_VAL(a) \
304                 (((a) >> (MLX5_GENEVE_CRITO_SHIFT)) & (MLX5_GENEVE_CRITO_MASK))
305 #define MLX5_GENEVE_RSVD_MASK 0x3F
306 #define MLX5_GENEVE_RSVD_VAL(a) ((a) & (MLX5_GENEVE_RSVD_MASK))
307 /*
308  * The length of the Geneve options fields, expressed in four byte multiples,
309  * not including the eight byte fixed tunnel.
310  */
311 #define MLX5_GENEVE_OPT_LEN_0 14
312 #define MLX5_GENEVE_OPT_LEN_1 63
313
314 enum mlx5_flow_drv_type {
315         MLX5_FLOW_TYPE_MIN,
316         MLX5_FLOW_TYPE_DV,
317         MLX5_FLOW_TYPE_VERBS,
318         MLX5_FLOW_TYPE_MAX,
319 };
320
321 /* Matcher PRM representation */
322 struct mlx5_flow_dv_match_params {
323         size_t size;
324         /**< Size of match value. Do NOT split size and key! */
325         uint32_t buf[MLX5_ST_SZ_DW(fte_match_param)];
326         /**< Matcher value. This value is used as the mask or as a key. */
327 };
328
329 /* Matcher structure. */
330 struct mlx5_flow_dv_matcher {
331         LIST_ENTRY(mlx5_flow_dv_matcher) next;
332         /* Pointer to the next element. */
333         rte_atomic32_t refcnt; /**< Reference counter. */
334         void *matcher_object; /**< Pointer to DV matcher */
335         uint16_t crc; /**< CRC of key. */
336         uint16_t priority; /**< Priority of matcher. */
337         uint8_t egress; /**< Egress matcher. */
338         uint8_t transfer; /**< 1 if the flow is E-Switch flow. */
339         uint32_t group; /**< The matcher group. */
340         struct mlx5_flow_dv_match_params mask; /**< Matcher mask. */
341 };
342
343 #define MLX5_ENCAP_MAX_LEN 132
344
345 /* Encap/decap resource structure. */
346 struct mlx5_flow_dv_encap_decap_resource {
347         LIST_ENTRY(mlx5_flow_dv_encap_decap_resource) next;
348         /* Pointer to next element. */
349         rte_atomic32_t refcnt; /**< Reference counter. */
350         void *verbs_action;
351         /**< Verbs encap/decap action object. */
352         uint8_t buf[MLX5_ENCAP_MAX_LEN];
353         size_t size;
354         uint8_t reformat_type;
355         uint8_t ft_type;
356         uint64_t flags; /**< Flags for RDMA API. */
357 };
358
359 /* Tag resource structure. */
360 struct mlx5_flow_dv_tag_resource {
361         LIST_ENTRY(mlx5_flow_dv_tag_resource) next;
362         /* Pointer to next element. */
363         rte_atomic32_t refcnt; /**< Reference counter. */
364         void *action;
365         /**< Verbs tag action object. */
366         uint32_t tag; /**< the tag value. */
367 };
368
369 /*
370  * Number of modification commands.
371  * If extensive metadata registers are supported
372  * the maximal actions amount is 16 and 8 otherwise.
373  */
374 #define MLX5_MODIFY_NUM 16
375 #define MLX5_MODIFY_NUM_NO_MREG 8
376
377 /* Modify resource structure */
378 struct mlx5_flow_dv_modify_hdr_resource {
379         LIST_ENTRY(mlx5_flow_dv_modify_hdr_resource) next;
380         /* Pointer to next element. */
381         rte_atomic32_t refcnt; /**< Reference counter. */
382         struct ibv_flow_action *verbs_action;
383         /**< Verbs modify header action object. */
384         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
385         uint32_t actions_num; /**< Number of modification actions. */
386         struct mlx5_modification_cmd actions[MLX5_MODIFY_NUM];
387         /**< Modification actions. */
388         uint64_t flags; /**< Flags for RDMA API. */
389 };
390
391 /* Jump action resource structure. */
392 struct mlx5_flow_dv_jump_tbl_resource {
393         LIST_ENTRY(mlx5_flow_dv_jump_tbl_resource) next;
394         /* Pointer to next element. */
395         rte_atomic32_t refcnt; /**< Reference counter. */
396         void *action; /**< Pointer to the rdma core action. */
397         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
398         struct mlx5_flow_tbl_resource *tbl; /**< The target table. */
399 };
400
401 /* Port ID resource structure. */
402 struct mlx5_flow_dv_port_id_action_resource {
403         LIST_ENTRY(mlx5_flow_dv_port_id_action_resource) next;
404         /* Pointer to next element. */
405         rte_atomic32_t refcnt; /**< Reference counter. */
406         void *action;
407         /**< Verbs tag action object. */
408         uint32_t port_id; /**< Port ID value. */
409 };
410
411 /* Push VLAN action resource structure */
412 struct mlx5_flow_dv_push_vlan_action_resource {
413         LIST_ENTRY(mlx5_flow_dv_push_vlan_action_resource) next;
414         /* Pointer to next element. */
415         rte_atomic32_t refcnt; /**< Reference counter. */
416         void *action; /**< Direct verbs action object. */
417         uint8_t ft_type; /**< Flow table type, Rx, Tx or FDB. */
418         rte_be32_t vlan_tag; /**< VLAN tag value. */
419 };
420
421 /* Metadata register copy table entry. */
422 struct mlx5_flow_mreg_copy_resource {
423         /*
424          * Hash list entry for copy table.
425          *  - Key is 32/64-bit MARK action ID.
426          *  - MUST be the first entry.
427          */
428         struct mlx5_hlist_entry hlist_ent;
429         LIST_ENTRY(mlx5_flow_mreg_copy_resource) next;
430         /* List entry for device flows. */
431         uint32_t refcnt; /* Reference counter. */
432         uint32_t appcnt; /* Apply/Remove counter. */
433         struct rte_flow *flow; /* Built flow for copy. */
434 };
435
436 /*
437  * Max number of actions per DV flow.
438  * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
439  * In rdma-core file providers/mlx5/verbs.c
440  */
441 #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
442
443 /* DV flows structure. */
444 struct mlx5_flow_dv {
445         struct mlx5_hrxq *hrxq; /**< Hash Rx queues. */
446         /* Flow DV api: */
447         struct mlx5_flow_dv_matcher *matcher; /**< Cache to matcher. */
448         struct mlx5_flow_dv_match_params value;
449         /**< Holds the value that the packet is compared to. */
450         struct mlx5_flow_dv_encap_decap_resource *encap_decap;
451         /**< Pointer to encap/decap resource in cache. */
452         struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
453         /**< Pointer to modify header resource in cache. */
454         struct ibv_flow *flow; /**< Installed flow. */
455         struct mlx5_flow_dv_jump_tbl_resource *jump;
456         /**< Pointer to the jump action resource. */
457         struct mlx5_flow_dv_port_id_action_resource *port_id_action;
458         /**< Pointer to port ID action resource. */
459         struct mlx5_vf_vlan vf_vlan;
460         /**< Structure for VF VLAN workaround. */
461         struct mlx5_flow_dv_push_vlan_action_resource *push_vlan_res;
462         /**< Pointer to push VLAN action resource in cache. */
463         struct mlx5_flow_dv_tag_resource *tag_resource;
464         /**< pointer to the tag action. */
465 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
466         void *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS];
467         /**< Action list. */
468 #endif
469         int actions_n; /**< number of actions. */
470 };
471
472 /* Verbs specification header. */
473 struct ibv_spec_header {
474         enum ibv_flow_spec_type type;
475         uint16_t size;
476 };
477
478 /** Handles information leading to a drop fate. */
479 struct mlx5_flow_verbs {
480         LIST_ENTRY(mlx5_flow_verbs) next;
481         unsigned int size; /**< Size of the attribute. */
482         struct {
483                 struct ibv_flow_attr *attr;
484                 /**< Pointer to the Specification buffer. */
485                 uint8_t *specs; /**< Pointer to the specifications. */
486         };
487         struct ibv_flow *flow; /**< Verbs flow pointer. */
488         struct mlx5_hrxq *hrxq; /**< Hash Rx queue object. */
489         struct mlx5_vf_vlan vf_vlan;
490         /**< Structure for VF VLAN workaround. */
491 };
492
493 struct mlx5_flow_rss {
494         uint32_t level;
495         uint32_t queue_num; /**< Number of entries in @p queue. */
496         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
497         uint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */
498         uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */
499 };
500
501 /** Device flow structure. */
502 struct mlx5_flow {
503         LIST_ENTRY(mlx5_flow) next;
504         struct rte_flow *flow; /**< Pointer to the main flow. */
505         uint64_t layers;
506         /**< Bit-fields of present layers, see MLX5_FLOW_LAYER_*. */
507         uint64_t actions;
508         /**< Bit-fields of detected actions, see MLX5_FLOW_ACTION_*. */
509         uint64_t hash_fields; /**< Verbs hash Rx queue hash fields. */
510         uint8_t ingress; /**< 1 if the flow is ingress. */
511         uint32_t group; /**< The group index. */
512         uint8_t transfer; /**< 1 if the flow is E-Switch flow. */
513         union {
514 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
515                 struct mlx5_flow_dv dv;
516 #endif
517                 struct mlx5_flow_verbs verbs;
518         };
519         uint32_t qrss_id; /**< Uniqie Q/RSS suffix subflow tag. */
520         bool external; /**< true if the flow is created external to PMD. */
521 };
522
523 /* Flow structure. */
524 struct rte_flow {
525         TAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */
526         enum mlx5_flow_drv_type drv_type; /**< Driver type. */
527         struct mlx5_flow_rss rss; /**< RSS context. */
528         struct mlx5_flow_counter *counter; /**< Holds flow counter. */
529         struct mlx5_flow_mreg_copy_resource *mreg_copy;
530         /**< pointer to metadata register copy table resource. */
531         LIST_HEAD(dev_flows, mlx5_flow) dev_flows;
532         /**< Device flows that are part of the flow. */
533         struct mlx5_fdir *fdir; /**< Pointer to associated FDIR if any. */
534         uint32_t hairpin_flow_id; /**< The flow id used for hairpin. */
535         uint32_t copy_applied:1; /**< The MARK copy Flow os applied. */
536 };
537
538 typedef int (*mlx5_flow_validate_t)(struct rte_eth_dev *dev,
539                                     const struct rte_flow_attr *attr,
540                                     const struct rte_flow_item items[],
541                                     const struct rte_flow_action actions[],
542                                     bool external,
543                                     struct rte_flow_error *error);
544 typedef struct mlx5_flow *(*mlx5_flow_prepare_t)
545         (const struct rte_flow_attr *attr, const struct rte_flow_item items[],
546          const struct rte_flow_action actions[], struct rte_flow_error *error);
547 typedef int (*mlx5_flow_translate_t)(struct rte_eth_dev *dev,
548                                      struct mlx5_flow *dev_flow,
549                                      const struct rte_flow_attr *attr,
550                                      const struct rte_flow_item items[],
551                                      const struct rte_flow_action actions[],
552                                      struct rte_flow_error *error);
553 typedef int (*mlx5_flow_apply_t)(struct rte_eth_dev *dev, struct rte_flow *flow,
554                                  struct rte_flow_error *error);
555 typedef void (*mlx5_flow_remove_t)(struct rte_eth_dev *dev,
556                                    struct rte_flow *flow);
557 typedef void (*mlx5_flow_destroy_t)(struct rte_eth_dev *dev,
558                                     struct rte_flow *flow);
559 typedef int (*mlx5_flow_query_t)(struct rte_eth_dev *dev,
560                                  struct rte_flow *flow,
561                                  const struct rte_flow_action *actions,
562                                  void *data,
563                                  struct rte_flow_error *error);
564 struct mlx5_flow_driver_ops {
565         mlx5_flow_validate_t validate;
566         mlx5_flow_prepare_t prepare;
567         mlx5_flow_translate_t translate;
568         mlx5_flow_apply_t apply;
569         mlx5_flow_remove_t remove;
570         mlx5_flow_destroy_t destroy;
571         mlx5_flow_query_t query;
572 };
573
574
575 #define MLX5_CNT_CONTAINER(sh, batch, thread) (&(sh)->cmng.ccont \
576         [(((sh)->cmng.mhi[batch] >> (thread)) & 0x1) * 2 + (batch)])
577 #define MLX5_CNT_CONTAINER_UNUSED(sh, batch, thread) (&(sh)->cmng.ccont \
578         [(~((sh)->cmng.mhi[batch] >> (thread)) & 0x1) * 2 + (batch)])
579
580 /* mlx5_flow.c */
581
582 struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(void);
583 void mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool);
584 uint32_t mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id);
585 uint32_t mlx5_flow_id_release(struct mlx5_flow_id_pool *pool,
586                               uint32_t id);
587 int mlx5_flow_group_to_table(const struct rte_flow_attr *attributes,
588                              bool external, uint32_t group, uint32_t *table,
589                              struct rte_flow_error *error);
590 uint64_t mlx5_flow_hashfields_adjust(struct mlx5_flow *dev_flow, int tunnel,
591                                      uint64_t layer_types,
592                                      uint64_t hash_fields);
593 uint32_t mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
594                                    uint32_t subpriority);
595 enum modify_reg mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
596                                      enum mlx5_feature_name feature,
597                                      uint32_t id,
598                                      struct rte_flow_error *error);
599 const struct rte_flow_action *mlx5_flow_find_action
600                                         (const struct rte_flow_action *actions,
601                                          enum rte_flow_action_type action);
602 int mlx5_flow_validate_action_count(struct rte_eth_dev *dev,
603                                     const struct rte_flow_attr *attr,
604                                     struct rte_flow_error *error);
605 int mlx5_flow_validate_action_drop(uint64_t action_flags,
606                                    const struct rte_flow_attr *attr,
607                                    struct rte_flow_error *error);
608 int mlx5_flow_validate_action_flag(uint64_t action_flags,
609                                    const struct rte_flow_attr *attr,
610                                    struct rte_flow_error *error);
611 int mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
612                                    uint64_t action_flags,
613                                    const struct rte_flow_attr *attr,
614                                    struct rte_flow_error *error);
615 int mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
616                                     uint64_t action_flags,
617                                     struct rte_eth_dev *dev,
618                                     const struct rte_flow_attr *attr,
619                                     struct rte_flow_error *error);
620 int mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
621                                   uint64_t action_flags,
622                                   struct rte_eth_dev *dev,
623                                   const struct rte_flow_attr *attr,
624                                   uint64_t item_flags,
625                                   struct rte_flow_error *error);
626 int mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
627                                   const struct rte_flow_attr *attributes,
628                                   struct rte_flow_error *error);
629 int mlx5_flow_item_acceptable(const struct rte_flow_item *item,
630                               const uint8_t *mask,
631                               const uint8_t *nic_mask,
632                               unsigned int size,
633                               struct rte_flow_error *error);
634 int mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
635                                 uint64_t item_flags,
636                                 struct rte_flow_error *error);
637 int mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
638                                 uint64_t item_flags,
639                                 uint8_t target_protocol,
640                                 struct rte_flow_error *error);
641 int mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
642                                     uint64_t item_flags,
643                                     const struct rte_flow_item *gre_item,
644                                     struct rte_flow_error *error);
645 int mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
646                                  uint64_t item_flags,
647                                  uint64_t last_item,
648                                  uint16_t ether_type,
649                                  const struct rte_flow_item_ipv4 *acc_mask,
650                                  struct rte_flow_error *error);
651 int mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
652                                  uint64_t item_flags,
653                                  uint64_t last_item,
654                                  uint16_t ether_type,
655                                  const struct rte_flow_item_ipv6 *acc_mask,
656                                  struct rte_flow_error *error);
657 int mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev,
658                                  const struct rte_flow_item *item,
659                                  uint64_t item_flags,
660                                  uint64_t prev_layer,
661                                  struct rte_flow_error *error);
662 int mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
663                                 uint64_t item_flags,
664                                 uint8_t target_protocol,
665                                 const struct rte_flow_item_tcp *flow_mask,
666                                 struct rte_flow_error *error);
667 int mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
668                                 uint64_t item_flags,
669                                 uint8_t target_protocol,
670                                 struct rte_flow_error *error);
671 int mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
672                                  uint64_t item_flags,
673                                  struct rte_eth_dev *dev,
674                                  struct rte_flow_error *error);
675 int mlx5_flow_validate_item_vxlan(const struct rte_flow_item *item,
676                                   uint64_t item_flags,
677                                   struct rte_flow_error *error);
678 int mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
679                                       uint64_t item_flags,
680                                       struct rte_eth_dev *dev,
681                                       struct rte_flow_error *error);
682 int mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
683                                  uint64_t item_flags,
684                                  uint8_t target_protocol,
685                                  struct rte_flow_error *error);
686 int mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
687                                    uint64_t item_flags,
688                                    uint8_t target_protocol,
689                                    struct rte_flow_error *error);
690 int mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
691                                   uint64_t item_flags,
692                                   uint8_t target_protocol,
693                                   struct rte_flow_error *error);
694 int mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
695                                    uint64_t item_flags,
696                                    struct rte_eth_dev *dev,
697                                    struct rte_flow_error *error);
698 #endif /* RTE_PMD_MLX5_FLOW_H_ */