net/i40e: add cloud filter parsing function for GTP
[dpdk.git] / drivers / net / i40e / i40e_flow.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <sys/queue.h>
34 #include <stdio.h>
35 #include <errno.h>
36 #include <stdint.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include <stdarg.h>
40
41 #include <rte_ether.h>
42 #include <rte_ethdev.h>
43 #include <rte_log.h>
44 #include <rte_memzone.h>
45 #include <rte_malloc.h>
46 #include <rte_eth_ctrl.h>
47 #include <rte_tailq.h>
48 #include <rte_flow_driver.h>
49
50 #include "i40e_logs.h"
51 #include "base/i40e_type.h"
52 #include "base/i40e_prototype.h"
53 #include "i40e_ethdev.h"
54
55 #define I40E_IPV6_TC_MASK       (0xFF << I40E_FDIR_IPv6_TC_OFFSET)
56 #define I40E_IPV6_FRAG_HEADER   44
57 #define I40E_TENANT_ARRAY_NUM   3
58 #define I40E_TCI_MASK           0xFFFF
59
60 static int i40e_flow_validate(struct rte_eth_dev *dev,
61                               const struct rte_flow_attr *attr,
62                               const struct rte_flow_item pattern[],
63                               const struct rte_flow_action actions[],
64                               struct rte_flow_error *error);
65 static struct rte_flow *i40e_flow_create(struct rte_eth_dev *dev,
66                                          const struct rte_flow_attr *attr,
67                                          const struct rte_flow_item pattern[],
68                                          const struct rte_flow_action actions[],
69                                          struct rte_flow_error *error);
70 static int i40e_flow_destroy(struct rte_eth_dev *dev,
71                              struct rte_flow *flow,
72                              struct rte_flow_error *error);
73 static int i40e_flow_flush(struct rte_eth_dev *dev,
74                            struct rte_flow_error *error);
75 static int
76 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
77                                   const struct rte_flow_item *pattern,
78                                   struct rte_flow_error *error,
79                                   struct rte_eth_ethertype_filter *filter);
80 static int i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
81                                     const struct rte_flow_action *actions,
82                                     struct rte_flow_error *error,
83                                     struct rte_eth_ethertype_filter *filter);
84 static int i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
85                                         const struct rte_flow_item *pattern,
86                                         struct rte_flow_error *error,
87                                         struct i40e_fdir_filter_conf *filter);
88 static int i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
89                                        const struct rte_flow_action *actions,
90                                        struct rte_flow_error *error,
91                                        struct i40e_fdir_filter_conf *filter);
92 static int i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
93                                  const struct rte_flow_action *actions,
94                                  struct rte_flow_error *error,
95                                  struct i40e_tunnel_filter_conf *filter);
96 static int i40e_flow_parse_attr(const struct rte_flow_attr *attr,
97                                 struct rte_flow_error *error);
98 static int i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
99                                     const struct rte_flow_attr *attr,
100                                     const struct rte_flow_item pattern[],
101                                     const struct rte_flow_action actions[],
102                                     struct rte_flow_error *error,
103                                     union i40e_filter_t *filter);
104 static int i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
105                                        const struct rte_flow_attr *attr,
106                                        const struct rte_flow_item pattern[],
107                                        const struct rte_flow_action actions[],
108                                        struct rte_flow_error *error,
109                                        union i40e_filter_t *filter);
110 static int i40e_flow_parse_vxlan_filter(struct rte_eth_dev *dev,
111                                         const struct rte_flow_attr *attr,
112                                         const struct rte_flow_item pattern[],
113                                         const struct rte_flow_action actions[],
114                                         struct rte_flow_error *error,
115                                         union i40e_filter_t *filter);
116 static int i40e_flow_parse_nvgre_filter(struct rte_eth_dev *dev,
117                                         const struct rte_flow_attr *attr,
118                                         const struct rte_flow_item pattern[],
119                                         const struct rte_flow_action actions[],
120                                         struct rte_flow_error *error,
121                                         union i40e_filter_t *filter);
122 static int i40e_flow_parse_mpls_filter(struct rte_eth_dev *dev,
123                                        const struct rte_flow_attr *attr,
124                                        const struct rte_flow_item pattern[],
125                                        const struct rte_flow_action actions[],
126                                        struct rte_flow_error *error,
127                                        union i40e_filter_t *filter);
128 static int i40e_flow_parse_gtp_filter(struct rte_eth_dev *dev,
129                                       const struct rte_flow_attr *attr,
130                                       const struct rte_flow_item pattern[],
131                                       const struct rte_flow_action actions[],
132                                       struct rte_flow_error *error,
133                                       union i40e_filter_t *filter);
134 static int i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
135                                       struct i40e_ethertype_filter *filter);
136 static int i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
137                                            struct i40e_tunnel_filter *filter);
138 static int i40e_flow_flush_fdir_filter(struct i40e_pf *pf);
139 static int i40e_flow_flush_ethertype_filter(struct i40e_pf *pf);
140 static int i40e_flow_flush_tunnel_filter(struct i40e_pf *pf);
141 static int
142 i40e_flow_parse_qinq_filter(struct rte_eth_dev *dev,
143                               const struct rte_flow_attr *attr,
144                               const struct rte_flow_item pattern[],
145                               const struct rte_flow_action actions[],
146                               struct rte_flow_error *error,
147                               union i40e_filter_t *filter);
148 static int
149 i40e_flow_parse_qinq_pattern(struct rte_eth_dev *dev,
150                               const struct rte_flow_item *pattern,
151                               struct rte_flow_error *error,
152                               struct i40e_tunnel_filter_conf *filter);
153
154 const struct rte_flow_ops i40e_flow_ops = {
155         .validate = i40e_flow_validate,
156         .create = i40e_flow_create,
157         .destroy = i40e_flow_destroy,
158         .flush = i40e_flow_flush,
159 };
160
161 union i40e_filter_t cons_filter;
162 enum rte_filter_type cons_filter_type = RTE_ETH_FILTER_NONE;
163
164 /* Pattern matched ethertype filter */
165 static enum rte_flow_item_type pattern_ethertype[] = {
166         RTE_FLOW_ITEM_TYPE_ETH,
167         RTE_FLOW_ITEM_TYPE_END,
168 };
169
170 /* Pattern matched flow director filter */
171 static enum rte_flow_item_type pattern_fdir_ipv4[] = {
172         RTE_FLOW_ITEM_TYPE_ETH,
173         RTE_FLOW_ITEM_TYPE_IPV4,
174         RTE_FLOW_ITEM_TYPE_END,
175 };
176
177 static enum rte_flow_item_type pattern_fdir_ipv4_udp[] = {
178         RTE_FLOW_ITEM_TYPE_ETH,
179         RTE_FLOW_ITEM_TYPE_IPV4,
180         RTE_FLOW_ITEM_TYPE_UDP,
181         RTE_FLOW_ITEM_TYPE_END,
182 };
183
184 static enum rte_flow_item_type pattern_fdir_ipv4_tcp[] = {
185         RTE_FLOW_ITEM_TYPE_ETH,
186         RTE_FLOW_ITEM_TYPE_IPV4,
187         RTE_FLOW_ITEM_TYPE_TCP,
188         RTE_FLOW_ITEM_TYPE_END,
189 };
190
191 static enum rte_flow_item_type pattern_fdir_ipv4_sctp[] = {
192         RTE_FLOW_ITEM_TYPE_ETH,
193         RTE_FLOW_ITEM_TYPE_IPV4,
194         RTE_FLOW_ITEM_TYPE_SCTP,
195         RTE_FLOW_ITEM_TYPE_END,
196 };
197
198 static enum rte_flow_item_type pattern_fdir_ipv4_gtpc[] = {
199         RTE_FLOW_ITEM_TYPE_ETH,
200         RTE_FLOW_ITEM_TYPE_IPV4,
201         RTE_FLOW_ITEM_TYPE_UDP,
202         RTE_FLOW_ITEM_TYPE_GTPC,
203         RTE_FLOW_ITEM_TYPE_END,
204 };
205
206 static enum rte_flow_item_type pattern_fdir_ipv4_gtpu[] = {
207         RTE_FLOW_ITEM_TYPE_ETH,
208         RTE_FLOW_ITEM_TYPE_IPV4,
209         RTE_FLOW_ITEM_TYPE_UDP,
210         RTE_FLOW_ITEM_TYPE_GTPU,
211         RTE_FLOW_ITEM_TYPE_END,
212 };
213
214 static enum rte_flow_item_type pattern_fdir_ipv4_gtpu_ipv4[] = {
215         RTE_FLOW_ITEM_TYPE_ETH,
216         RTE_FLOW_ITEM_TYPE_IPV4,
217         RTE_FLOW_ITEM_TYPE_UDP,
218         RTE_FLOW_ITEM_TYPE_GTPU,
219         RTE_FLOW_ITEM_TYPE_IPV4,
220         RTE_FLOW_ITEM_TYPE_END,
221 };
222
223 static enum rte_flow_item_type pattern_fdir_ipv4_gtpu_ipv6[] = {
224         RTE_FLOW_ITEM_TYPE_ETH,
225         RTE_FLOW_ITEM_TYPE_IPV4,
226         RTE_FLOW_ITEM_TYPE_UDP,
227         RTE_FLOW_ITEM_TYPE_GTPU,
228         RTE_FLOW_ITEM_TYPE_IPV6,
229         RTE_FLOW_ITEM_TYPE_END,
230 };
231
232 static enum rte_flow_item_type pattern_fdir_ipv6[] = {
233         RTE_FLOW_ITEM_TYPE_ETH,
234         RTE_FLOW_ITEM_TYPE_IPV6,
235         RTE_FLOW_ITEM_TYPE_END,
236 };
237
238 static enum rte_flow_item_type pattern_fdir_ipv6_udp[] = {
239         RTE_FLOW_ITEM_TYPE_ETH,
240         RTE_FLOW_ITEM_TYPE_IPV6,
241         RTE_FLOW_ITEM_TYPE_UDP,
242         RTE_FLOW_ITEM_TYPE_END,
243 };
244
245 static enum rte_flow_item_type pattern_fdir_ipv6_tcp[] = {
246         RTE_FLOW_ITEM_TYPE_ETH,
247         RTE_FLOW_ITEM_TYPE_IPV6,
248         RTE_FLOW_ITEM_TYPE_TCP,
249         RTE_FLOW_ITEM_TYPE_END,
250 };
251
252 static enum rte_flow_item_type pattern_fdir_ipv6_sctp[] = {
253         RTE_FLOW_ITEM_TYPE_ETH,
254         RTE_FLOW_ITEM_TYPE_IPV6,
255         RTE_FLOW_ITEM_TYPE_SCTP,
256         RTE_FLOW_ITEM_TYPE_END,
257 };
258
259 static enum rte_flow_item_type pattern_fdir_ipv6_gtpc[] = {
260         RTE_FLOW_ITEM_TYPE_ETH,
261         RTE_FLOW_ITEM_TYPE_IPV6,
262         RTE_FLOW_ITEM_TYPE_UDP,
263         RTE_FLOW_ITEM_TYPE_GTPC,
264         RTE_FLOW_ITEM_TYPE_END,
265 };
266
267 static enum rte_flow_item_type pattern_fdir_ipv6_gtpu[] = {
268         RTE_FLOW_ITEM_TYPE_ETH,
269         RTE_FLOW_ITEM_TYPE_IPV6,
270         RTE_FLOW_ITEM_TYPE_UDP,
271         RTE_FLOW_ITEM_TYPE_GTPU,
272         RTE_FLOW_ITEM_TYPE_END,
273 };
274
275 static enum rte_flow_item_type pattern_fdir_ipv6_gtpu_ipv4[] = {
276         RTE_FLOW_ITEM_TYPE_ETH,
277         RTE_FLOW_ITEM_TYPE_IPV6,
278         RTE_FLOW_ITEM_TYPE_UDP,
279         RTE_FLOW_ITEM_TYPE_GTPU,
280         RTE_FLOW_ITEM_TYPE_IPV4,
281         RTE_FLOW_ITEM_TYPE_END,
282 };
283
284 static enum rte_flow_item_type pattern_fdir_ipv6_gtpu_ipv6[] = {
285         RTE_FLOW_ITEM_TYPE_ETH,
286         RTE_FLOW_ITEM_TYPE_IPV6,
287         RTE_FLOW_ITEM_TYPE_UDP,
288         RTE_FLOW_ITEM_TYPE_GTPU,
289         RTE_FLOW_ITEM_TYPE_IPV6,
290         RTE_FLOW_ITEM_TYPE_END,
291 };
292
293 static enum rte_flow_item_type pattern_fdir_ethertype_raw_1[] = {
294         RTE_FLOW_ITEM_TYPE_ETH,
295         RTE_FLOW_ITEM_TYPE_RAW,
296         RTE_FLOW_ITEM_TYPE_END,
297 };
298
299 static enum rte_flow_item_type pattern_fdir_ethertype_raw_2[] = {
300         RTE_FLOW_ITEM_TYPE_ETH,
301         RTE_FLOW_ITEM_TYPE_RAW,
302         RTE_FLOW_ITEM_TYPE_RAW,
303         RTE_FLOW_ITEM_TYPE_END,
304 };
305
306 static enum rte_flow_item_type pattern_fdir_ethertype_raw_3[] = {
307         RTE_FLOW_ITEM_TYPE_ETH,
308         RTE_FLOW_ITEM_TYPE_RAW,
309         RTE_FLOW_ITEM_TYPE_RAW,
310         RTE_FLOW_ITEM_TYPE_RAW,
311         RTE_FLOW_ITEM_TYPE_END,
312 };
313
314 static enum rte_flow_item_type pattern_fdir_ipv4_raw_1[] = {
315         RTE_FLOW_ITEM_TYPE_ETH,
316         RTE_FLOW_ITEM_TYPE_IPV4,
317         RTE_FLOW_ITEM_TYPE_RAW,
318         RTE_FLOW_ITEM_TYPE_END,
319 };
320
321 static enum rte_flow_item_type pattern_fdir_ipv4_raw_2[] = {
322         RTE_FLOW_ITEM_TYPE_ETH,
323         RTE_FLOW_ITEM_TYPE_IPV4,
324         RTE_FLOW_ITEM_TYPE_RAW,
325         RTE_FLOW_ITEM_TYPE_RAW,
326         RTE_FLOW_ITEM_TYPE_END,
327 };
328
329 static enum rte_flow_item_type pattern_fdir_ipv4_raw_3[] = {
330         RTE_FLOW_ITEM_TYPE_ETH,
331         RTE_FLOW_ITEM_TYPE_IPV4,
332         RTE_FLOW_ITEM_TYPE_RAW,
333         RTE_FLOW_ITEM_TYPE_RAW,
334         RTE_FLOW_ITEM_TYPE_RAW,
335         RTE_FLOW_ITEM_TYPE_END,
336 };
337
338 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_1[] = {
339         RTE_FLOW_ITEM_TYPE_ETH,
340         RTE_FLOW_ITEM_TYPE_IPV4,
341         RTE_FLOW_ITEM_TYPE_UDP,
342         RTE_FLOW_ITEM_TYPE_RAW,
343         RTE_FLOW_ITEM_TYPE_END,
344 };
345
346 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_2[] = {
347         RTE_FLOW_ITEM_TYPE_ETH,
348         RTE_FLOW_ITEM_TYPE_IPV4,
349         RTE_FLOW_ITEM_TYPE_UDP,
350         RTE_FLOW_ITEM_TYPE_RAW,
351         RTE_FLOW_ITEM_TYPE_RAW,
352         RTE_FLOW_ITEM_TYPE_END,
353 };
354
355 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_3[] = {
356         RTE_FLOW_ITEM_TYPE_ETH,
357         RTE_FLOW_ITEM_TYPE_IPV4,
358         RTE_FLOW_ITEM_TYPE_UDP,
359         RTE_FLOW_ITEM_TYPE_RAW,
360         RTE_FLOW_ITEM_TYPE_RAW,
361         RTE_FLOW_ITEM_TYPE_RAW,
362         RTE_FLOW_ITEM_TYPE_END,
363 };
364
365 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_1[] = {
366         RTE_FLOW_ITEM_TYPE_ETH,
367         RTE_FLOW_ITEM_TYPE_IPV4,
368         RTE_FLOW_ITEM_TYPE_TCP,
369         RTE_FLOW_ITEM_TYPE_RAW,
370         RTE_FLOW_ITEM_TYPE_END,
371 };
372
373 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_2[] = {
374         RTE_FLOW_ITEM_TYPE_ETH,
375         RTE_FLOW_ITEM_TYPE_IPV4,
376         RTE_FLOW_ITEM_TYPE_TCP,
377         RTE_FLOW_ITEM_TYPE_RAW,
378         RTE_FLOW_ITEM_TYPE_RAW,
379         RTE_FLOW_ITEM_TYPE_END,
380 };
381
382 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_3[] = {
383         RTE_FLOW_ITEM_TYPE_ETH,
384         RTE_FLOW_ITEM_TYPE_IPV4,
385         RTE_FLOW_ITEM_TYPE_TCP,
386         RTE_FLOW_ITEM_TYPE_RAW,
387         RTE_FLOW_ITEM_TYPE_RAW,
388         RTE_FLOW_ITEM_TYPE_RAW,
389         RTE_FLOW_ITEM_TYPE_END,
390 };
391
392 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_1[] = {
393         RTE_FLOW_ITEM_TYPE_ETH,
394         RTE_FLOW_ITEM_TYPE_IPV4,
395         RTE_FLOW_ITEM_TYPE_SCTP,
396         RTE_FLOW_ITEM_TYPE_RAW,
397         RTE_FLOW_ITEM_TYPE_END,
398 };
399
400 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_2[] = {
401         RTE_FLOW_ITEM_TYPE_ETH,
402         RTE_FLOW_ITEM_TYPE_IPV4,
403         RTE_FLOW_ITEM_TYPE_SCTP,
404         RTE_FLOW_ITEM_TYPE_RAW,
405         RTE_FLOW_ITEM_TYPE_RAW,
406         RTE_FLOW_ITEM_TYPE_END,
407 };
408
409 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_3[] = {
410         RTE_FLOW_ITEM_TYPE_ETH,
411         RTE_FLOW_ITEM_TYPE_IPV4,
412         RTE_FLOW_ITEM_TYPE_SCTP,
413         RTE_FLOW_ITEM_TYPE_RAW,
414         RTE_FLOW_ITEM_TYPE_RAW,
415         RTE_FLOW_ITEM_TYPE_RAW,
416         RTE_FLOW_ITEM_TYPE_END,
417 };
418
419 static enum rte_flow_item_type pattern_fdir_ipv6_raw_1[] = {
420         RTE_FLOW_ITEM_TYPE_ETH,
421         RTE_FLOW_ITEM_TYPE_IPV6,
422         RTE_FLOW_ITEM_TYPE_RAW,
423         RTE_FLOW_ITEM_TYPE_END,
424 };
425
426 static enum rte_flow_item_type pattern_fdir_ipv6_raw_2[] = {
427         RTE_FLOW_ITEM_TYPE_ETH,
428         RTE_FLOW_ITEM_TYPE_IPV6,
429         RTE_FLOW_ITEM_TYPE_RAW,
430         RTE_FLOW_ITEM_TYPE_RAW,
431         RTE_FLOW_ITEM_TYPE_END,
432 };
433
434 static enum rte_flow_item_type pattern_fdir_ipv6_raw_3[] = {
435         RTE_FLOW_ITEM_TYPE_ETH,
436         RTE_FLOW_ITEM_TYPE_IPV6,
437         RTE_FLOW_ITEM_TYPE_RAW,
438         RTE_FLOW_ITEM_TYPE_RAW,
439         RTE_FLOW_ITEM_TYPE_RAW,
440         RTE_FLOW_ITEM_TYPE_END,
441 };
442
443 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_1[] = {
444         RTE_FLOW_ITEM_TYPE_ETH,
445         RTE_FLOW_ITEM_TYPE_IPV6,
446         RTE_FLOW_ITEM_TYPE_UDP,
447         RTE_FLOW_ITEM_TYPE_RAW,
448         RTE_FLOW_ITEM_TYPE_END,
449 };
450
451 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_2[] = {
452         RTE_FLOW_ITEM_TYPE_ETH,
453         RTE_FLOW_ITEM_TYPE_IPV6,
454         RTE_FLOW_ITEM_TYPE_UDP,
455         RTE_FLOW_ITEM_TYPE_RAW,
456         RTE_FLOW_ITEM_TYPE_RAW,
457         RTE_FLOW_ITEM_TYPE_END,
458 };
459
460 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_3[] = {
461         RTE_FLOW_ITEM_TYPE_ETH,
462         RTE_FLOW_ITEM_TYPE_IPV6,
463         RTE_FLOW_ITEM_TYPE_UDP,
464         RTE_FLOW_ITEM_TYPE_RAW,
465         RTE_FLOW_ITEM_TYPE_RAW,
466         RTE_FLOW_ITEM_TYPE_RAW,
467         RTE_FLOW_ITEM_TYPE_END,
468 };
469
470 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_1[] = {
471         RTE_FLOW_ITEM_TYPE_ETH,
472         RTE_FLOW_ITEM_TYPE_IPV6,
473         RTE_FLOW_ITEM_TYPE_TCP,
474         RTE_FLOW_ITEM_TYPE_RAW,
475         RTE_FLOW_ITEM_TYPE_END,
476 };
477
478 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_2[] = {
479         RTE_FLOW_ITEM_TYPE_ETH,
480         RTE_FLOW_ITEM_TYPE_IPV6,
481         RTE_FLOW_ITEM_TYPE_TCP,
482         RTE_FLOW_ITEM_TYPE_RAW,
483         RTE_FLOW_ITEM_TYPE_RAW,
484         RTE_FLOW_ITEM_TYPE_END,
485 };
486
487 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_3[] = {
488         RTE_FLOW_ITEM_TYPE_ETH,
489         RTE_FLOW_ITEM_TYPE_IPV6,
490         RTE_FLOW_ITEM_TYPE_TCP,
491         RTE_FLOW_ITEM_TYPE_RAW,
492         RTE_FLOW_ITEM_TYPE_RAW,
493         RTE_FLOW_ITEM_TYPE_RAW,
494         RTE_FLOW_ITEM_TYPE_END,
495 };
496
497 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_1[] = {
498         RTE_FLOW_ITEM_TYPE_ETH,
499         RTE_FLOW_ITEM_TYPE_IPV6,
500         RTE_FLOW_ITEM_TYPE_SCTP,
501         RTE_FLOW_ITEM_TYPE_RAW,
502         RTE_FLOW_ITEM_TYPE_END,
503 };
504
505 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_2[] = {
506         RTE_FLOW_ITEM_TYPE_ETH,
507         RTE_FLOW_ITEM_TYPE_IPV6,
508         RTE_FLOW_ITEM_TYPE_SCTP,
509         RTE_FLOW_ITEM_TYPE_RAW,
510         RTE_FLOW_ITEM_TYPE_RAW,
511         RTE_FLOW_ITEM_TYPE_END,
512 };
513
514 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_3[] = {
515         RTE_FLOW_ITEM_TYPE_ETH,
516         RTE_FLOW_ITEM_TYPE_IPV6,
517         RTE_FLOW_ITEM_TYPE_SCTP,
518         RTE_FLOW_ITEM_TYPE_RAW,
519         RTE_FLOW_ITEM_TYPE_RAW,
520         RTE_FLOW_ITEM_TYPE_RAW,
521         RTE_FLOW_ITEM_TYPE_END,
522 };
523
524 static enum rte_flow_item_type pattern_fdir_ethertype_vlan[] = {
525         RTE_FLOW_ITEM_TYPE_ETH,
526         RTE_FLOW_ITEM_TYPE_VLAN,
527         RTE_FLOW_ITEM_TYPE_END,
528 };
529
530 static enum rte_flow_item_type pattern_fdir_vlan_ipv4[] = {
531         RTE_FLOW_ITEM_TYPE_ETH,
532         RTE_FLOW_ITEM_TYPE_VLAN,
533         RTE_FLOW_ITEM_TYPE_IPV4,
534         RTE_FLOW_ITEM_TYPE_END,
535 };
536
537 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp[] = {
538         RTE_FLOW_ITEM_TYPE_ETH,
539         RTE_FLOW_ITEM_TYPE_VLAN,
540         RTE_FLOW_ITEM_TYPE_IPV4,
541         RTE_FLOW_ITEM_TYPE_UDP,
542         RTE_FLOW_ITEM_TYPE_END,
543 };
544
545 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp[] = {
546         RTE_FLOW_ITEM_TYPE_ETH,
547         RTE_FLOW_ITEM_TYPE_VLAN,
548         RTE_FLOW_ITEM_TYPE_IPV4,
549         RTE_FLOW_ITEM_TYPE_TCP,
550         RTE_FLOW_ITEM_TYPE_END,
551 };
552
553 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp[] = {
554         RTE_FLOW_ITEM_TYPE_ETH,
555         RTE_FLOW_ITEM_TYPE_VLAN,
556         RTE_FLOW_ITEM_TYPE_IPV4,
557         RTE_FLOW_ITEM_TYPE_SCTP,
558         RTE_FLOW_ITEM_TYPE_END,
559 };
560
561 static enum rte_flow_item_type pattern_fdir_vlan_ipv6[] = {
562         RTE_FLOW_ITEM_TYPE_ETH,
563         RTE_FLOW_ITEM_TYPE_VLAN,
564         RTE_FLOW_ITEM_TYPE_IPV6,
565         RTE_FLOW_ITEM_TYPE_END,
566 };
567
568 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp[] = {
569         RTE_FLOW_ITEM_TYPE_ETH,
570         RTE_FLOW_ITEM_TYPE_VLAN,
571         RTE_FLOW_ITEM_TYPE_IPV6,
572         RTE_FLOW_ITEM_TYPE_UDP,
573         RTE_FLOW_ITEM_TYPE_END,
574 };
575
576 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp[] = {
577         RTE_FLOW_ITEM_TYPE_ETH,
578         RTE_FLOW_ITEM_TYPE_VLAN,
579         RTE_FLOW_ITEM_TYPE_IPV6,
580         RTE_FLOW_ITEM_TYPE_TCP,
581         RTE_FLOW_ITEM_TYPE_END,
582 };
583
584 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp[] = {
585         RTE_FLOW_ITEM_TYPE_ETH,
586         RTE_FLOW_ITEM_TYPE_VLAN,
587         RTE_FLOW_ITEM_TYPE_IPV6,
588         RTE_FLOW_ITEM_TYPE_SCTP,
589         RTE_FLOW_ITEM_TYPE_END,
590 };
591
592 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_1[] = {
593         RTE_FLOW_ITEM_TYPE_ETH,
594         RTE_FLOW_ITEM_TYPE_VLAN,
595         RTE_FLOW_ITEM_TYPE_RAW,
596         RTE_FLOW_ITEM_TYPE_END,
597 };
598
599 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_2[] = {
600         RTE_FLOW_ITEM_TYPE_ETH,
601         RTE_FLOW_ITEM_TYPE_VLAN,
602         RTE_FLOW_ITEM_TYPE_RAW,
603         RTE_FLOW_ITEM_TYPE_RAW,
604         RTE_FLOW_ITEM_TYPE_END,
605 };
606
607 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_3[] = {
608         RTE_FLOW_ITEM_TYPE_ETH,
609         RTE_FLOW_ITEM_TYPE_VLAN,
610         RTE_FLOW_ITEM_TYPE_RAW,
611         RTE_FLOW_ITEM_TYPE_RAW,
612         RTE_FLOW_ITEM_TYPE_RAW,
613         RTE_FLOW_ITEM_TYPE_END,
614 };
615
616 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_1[] = {
617         RTE_FLOW_ITEM_TYPE_ETH,
618         RTE_FLOW_ITEM_TYPE_VLAN,
619         RTE_FLOW_ITEM_TYPE_IPV4,
620         RTE_FLOW_ITEM_TYPE_RAW,
621         RTE_FLOW_ITEM_TYPE_END,
622 };
623
624 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_2[] = {
625         RTE_FLOW_ITEM_TYPE_ETH,
626         RTE_FLOW_ITEM_TYPE_VLAN,
627         RTE_FLOW_ITEM_TYPE_IPV4,
628         RTE_FLOW_ITEM_TYPE_RAW,
629         RTE_FLOW_ITEM_TYPE_RAW,
630         RTE_FLOW_ITEM_TYPE_END,
631 };
632
633 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_3[] = {
634         RTE_FLOW_ITEM_TYPE_ETH,
635         RTE_FLOW_ITEM_TYPE_VLAN,
636         RTE_FLOW_ITEM_TYPE_IPV4,
637         RTE_FLOW_ITEM_TYPE_RAW,
638         RTE_FLOW_ITEM_TYPE_RAW,
639         RTE_FLOW_ITEM_TYPE_RAW,
640         RTE_FLOW_ITEM_TYPE_END,
641 };
642
643 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_1[] = {
644         RTE_FLOW_ITEM_TYPE_ETH,
645         RTE_FLOW_ITEM_TYPE_VLAN,
646         RTE_FLOW_ITEM_TYPE_IPV4,
647         RTE_FLOW_ITEM_TYPE_UDP,
648         RTE_FLOW_ITEM_TYPE_RAW,
649         RTE_FLOW_ITEM_TYPE_END,
650 };
651
652 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_2[] = {
653         RTE_FLOW_ITEM_TYPE_ETH,
654         RTE_FLOW_ITEM_TYPE_VLAN,
655         RTE_FLOW_ITEM_TYPE_IPV4,
656         RTE_FLOW_ITEM_TYPE_UDP,
657         RTE_FLOW_ITEM_TYPE_RAW,
658         RTE_FLOW_ITEM_TYPE_RAW,
659         RTE_FLOW_ITEM_TYPE_END,
660 };
661
662 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_3[] = {
663         RTE_FLOW_ITEM_TYPE_ETH,
664         RTE_FLOW_ITEM_TYPE_VLAN,
665         RTE_FLOW_ITEM_TYPE_IPV4,
666         RTE_FLOW_ITEM_TYPE_UDP,
667         RTE_FLOW_ITEM_TYPE_RAW,
668         RTE_FLOW_ITEM_TYPE_RAW,
669         RTE_FLOW_ITEM_TYPE_RAW,
670         RTE_FLOW_ITEM_TYPE_END,
671 };
672
673 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_1[] = {
674         RTE_FLOW_ITEM_TYPE_ETH,
675         RTE_FLOW_ITEM_TYPE_VLAN,
676         RTE_FLOW_ITEM_TYPE_IPV4,
677         RTE_FLOW_ITEM_TYPE_TCP,
678         RTE_FLOW_ITEM_TYPE_RAW,
679         RTE_FLOW_ITEM_TYPE_END,
680 };
681
682 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_2[] = {
683         RTE_FLOW_ITEM_TYPE_ETH,
684         RTE_FLOW_ITEM_TYPE_VLAN,
685         RTE_FLOW_ITEM_TYPE_IPV4,
686         RTE_FLOW_ITEM_TYPE_TCP,
687         RTE_FLOW_ITEM_TYPE_RAW,
688         RTE_FLOW_ITEM_TYPE_RAW,
689         RTE_FLOW_ITEM_TYPE_END,
690 };
691
692 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_3[] = {
693         RTE_FLOW_ITEM_TYPE_ETH,
694         RTE_FLOW_ITEM_TYPE_VLAN,
695         RTE_FLOW_ITEM_TYPE_IPV4,
696         RTE_FLOW_ITEM_TYPE_TCP,
697         RTE_FLOW_ITEM_TYPE_RAW,
698         RTE_FLOW_ITEM_TYPE_RAW,
699         RTE_FLOW_ITEM_TYPE_RAW,
700         RTE_FLOW_ITEM_TYPE_END,
701 };
702
703 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_1[] = {
704         RTE_FLOW_ITEM_TYPE_ETH,
705         RTE_FLOW_ITEM_TYPE_VLAN,
706         RTE_FLOW_ITEM_TYPE_IPV4,
707         RTE_FLOW_ITEM_TYPE_SCTP,
708         RTE_FLOW_ITEM_TYPE_RAW,
709         RTE_FLOW_ITEM_TYPE_END,
710 };
711
712 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_2[] = {
713         RTE_FLOW_ITEM_TYPE_ETH,
714         RTE_FLOW_ITEM_TYPE_VLAN,
715         RTE_FLOW_ITEM_TYPE_IPV4,
716         RTE_FLOW_ITEM_TYPE_SCTP,
717         RTE_FLOW_ITEM_TYPE_RAW,
718         RTE_FLOW_ITEM_TYPE_RAW,
719         RTE_FLOW_ITEM_TYPE_END,
720 };
721
722 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_3[] = {
723         RTE_FLOW_ITEM_TYPE_ETH,
724         RTE_FLOW_ITEM_TYPE_VLAN,
725         RTE_FLOW_ITEM_TYPE_IPV4,
726         RTE_FLOW_ITEM_TYPE_SCTP,
727         RTE_FLOW_ITEM_TYPE_RAW,
728         RTE_FLOW_ITEM_TYPE_RAW,
729         RTE_FLOW_ITEM_TYPE_RAW,
730         RTE_FLOW_ITEM_TYPE_END,
731 };
732
733 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_1[] = {
734         RTE_FLOW_ITEM_TYPE_ETH,
735         RTE_FLOW_ITEM_TYPE_VLAN,
736         RTE_FLOW_ITEM_TYPE_IPV6,
737         RTE_FLOW_ITEM_TYPE_RAW,
738         RTE_FLOW_ITEM_TYPE_END,
739 };
740
741 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_2[] = {
742         RTE_FLOW_ITEM_TYPE_ETH,
743         RTE_FLOW_ITEM_TYPE_VLAN,
744         RTE_FLOW_ITEM_TYPE_IPV6,
745         RTE_FLOW_ITEM_TYPE_RAW,
746         RTE_FLOW_ITEM_TYPE_RAW,
747         RTE_FLOW_ITEM_TYPE_END,
748 };
749
750 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_3[] = {
751         RTE_FLOW_ITEM_TYPE_ETH,
752         RTE_FLOW_ITEM_TYPE_VLAN,
753         RTE_FLOW_ITEM_TYPE_IPV6,
754         RTE_FLOW_ITEM_TYPE_RAW,
755         RTE_FLOW_ITEM_TYPE_RAW,
756         RTE_FLOW_ITEM_TYPE_RAW,
757         RTE_FLOW_ITEM_TYPE_END,
758 };
759
760 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_1[] = {
761         RTE_FLOW_ITEM_TYPE_ETH,
762         RTE_FLOW_ITEM_TYPE_VLAN,
763         RTE_FLOW_ITEM_TYPE_IPV6,
764         RTE_FLOW_ITEM_TYPE_UDP,
765         RTE_FLOW_ITEM_TYPE_RAW,
766         RTE_FLOW_ITEM_TYPE_END,
767 };
768
769 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_2[] = {
770         RTE_FLOW_ITEM_TYPE_ETH,
771         RTE_FLOW_ITEM_TYPE_VLAN,
772         RTE_FLOW_ITEM_TYPE_IPV6,
773         RTE_FLOW_ITEM_TYPE_UDP,
774         RTE_FLOW_ITEM_TYPE_RAW,
775         RTE_FLOW_ITEM_TYPE_RAW,
776         RTE_FLOW_ITEM_TYPE_END,
777 };
778
779 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_3[] = {
780         RTE_FLOW_ITEM_TYPE_ETH,
781         RTE_FLOW_ITEM_TYPE_VLAN,
782         RTE_FLOW_ITEM_TYPE_IPV6,
783         RTE_FLOW_ITEM_TYPE_UDP,
784         RTE_FLOW_ITEM_TYPE_RAW,
785         RTE_FLOW_ITEM_TYPE_RAW,
786         RTE_FLOW_ITEM_TYPE_RAW,
787         RTE_FLOW_ITEM_TYPE_END,
788 };
789
790 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_1[] = {
791         RTE_FLOW_ITEM_TYPE_ETH,
792         RTE_FLOW_ITEM_TYPE_VLAN,
793         RTE_FLOW_ITEM_TYPE_IPV6,
794         RTE_FLOW_ITEM_TYPE_TCP,
795         RTE_FLOW_ITEM_TYPE_RAW,
796         RTE_FLOW_ITEM_TYPE_END,
797 };
798
799 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_2[] = {
800         RTE_FLOW_ITEM_TYPE_ETH,
801         RTE_FLOW_ITEM_TYPE_VLAN,
802         RTE_FLOW_ITEM_TYPE_IPV6,
803         RTE_FLOW_ITEM_TYPE_TCP,
804         RTE_FLOW_ITEM_TYPE_RAW,
805         RTE_FLOW_ITEM_TYPE_RAW,
806         RTE_FLOW_ITEM_TYPE_END,
807 };
808
809 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_3[] = {
810         RTE_FLOW_ITEM_TYPE_ETH,
811         RTE_FLOW_ITEM_TYPE_VLAN,
812         RTE_FLOW_ITEM_TYPE_IPV6,
813         RTE_FLOW_ITEM_TYPE_TCP,
814         RTE_FLOW_ITEM_TYPE_RAW,
815         RTE_FLOW_ITEM_TYPE_RAW,
816         RTE_FLOW_ITEM_TYPE_RAW,
817         RTE_FLOW_ITEM_TYPE_END,
818 };
819
820 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_1[] = {
821         RTE_FLOW_ITEM_TYPE_ETH,
822         RTE_FLOW_ITEM_TYPE_VLAN,
823         RTE_FLOW_ITEM_TYPE_IPV6,
824         RTE_FLOW_ITEM_TYPE_SCTP,
825         RTE_FLOW_ITEM_TYPE_RAW,
826         RTE_FLOW_ITEM_TYPE_END,
827 };
828
829 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_2[] = {
830         RTE_FLOW_ITEM_TYPE_ETH,
831         RTE_FLOW_ITEM_TYPE_VLAN,
832         RTE_FLOW_ITEM_TYPE_IPV6,
833         RTE_FLOW_ITEM_TYPE_SCTP,
834         RTE_FLOW_ITEM_TYPE_RAW,
835         RTE_FLOW_ITEM_TYPE_RAW,
836         RTE_FLOW_ITEM_TYPE_END,
837 };
838
839 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_3[] = {
840         RTE_FLOW_ITEM_TYPE_ETH,
841         RTE_FLOW_ITEM_TYPE_VLAN,
842         RTE_FLOW_ITEM_TYPE_IPV6,
843         RTE_FLOW_ITEM_TYPE_SCTP,
844         RTE_FLOW_ITEM_TYPE_RAW,
845         RTE_FLOW_ITEM_TYPE_RAW,
846         RTE_FLOW_ITEM_TYPE_RAW,
847         RTE_FLOW_ITEM_TYPE_END,
848 };
849
850 static enum rte_flow_item_type pattern_fdir_ipv4_vf[] = {
851         RTE_FLOW_ITEM_TYPE_ETH,
852         RTE_FLOW_ITEM_TYPE_IPV4,
853         RTE_FLOW_ITEM_TYPE_VF,
854         RTE_FLOW_ITEM_TYPE_END,
855 };
856
857 static enum rte_flow_item_type pattern_fdir_ipv4_udp_vf[] = {
858         RTE_FLOW_ITEM_TYPE_ETH,
859         RTE_FLOW_ITEM_TYPE_IPV4,
860         RTE_FLOW_ITEM_TYPE_UDP,
861         RTE_FLOW_ITEM_TYPE_VF,
862         RTE_FLOW_ITEM_TYPE_END,
863 };
864
865 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_vf[] = {
866         RTE_FLOW_ITEM_TYPE_ETH,
867         RTE_FLOW_ITEM_TYPE_IPV4,
868         RTE_FLOW_ITEM_TYPE_TCP,
869         RTE_FLOW_ITEM_TYPE_VF,
870         RTE_FLOW_ITEM_TYPE_END,
871 };
872
873 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_vf[] = {
874         RTE_FLOW_ITEM_TYPE_ETH,
875         RTE_FLOW_ITEM_TYPE_IPV4,
876         RTE_FLOW_ITEM_TYPE_SCTP,
877         RTE_FLOW_ITEM_TYPE_VF,
878         RTE_FLOW_ITEM_TYPE_END,
879 };
880
881 static enum rte_flow_item_type pattern_fdir_ipv6_vf[] = {
882         RTE_FLOW_ITEM_TYPE_ETH,
883         RTE_FLOW_ITEM_TYPE_IPV6,
884         RTE_FLOW_ITEM_TYPE_VF,
885         RTE_FLOW_ITEM_TYPE_END,
886 };
887
888 static enum rte_flow_item_type pattern_fdir_ipv6_udp_vf[] = {
889         RTE_FLOW_ITEM_TYPE_ETH,
890         RTE_FLOW_ITEM_TYPE_IPV6,
891         RTE_FLOW_ITEM_TYPE_UDP,
892         RTE_FLOW_ITEM_TYPE_VF,
893         RTE_FLOW_ITEM_TYPE_END,
894 };
895
896 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_vf[] = {
897         RTE_FLOW_ITEM_TYPE_ETH,
898         RTE_FLOW_ITEM_TYPE_IPV6,
899         RTE_FLOW_ITEM_TYPE_TCP,
900         RTE_FLOW_ITEM_TYPE_VF,
901         RTE_FLOW_ITEM_TYPE_END,
902 };
903
904 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_vf[] = {
905         RTE_FLOW_ITEM_TYPE_ETH,
906         RTE_FLOW_ITEM_TYPE_IPV6,
907         RTE_FLOW_ITEM_TYPE_SCTP,
908         RTE_FLOW_ITEM_TYPE_VF,
909         RTE_FLOW_ITEM_TYPE_END,
910 };
911
912 static enum rte_flow_item_type pattern_fdir_ethertype_raw_1_vf[] = {
913         RTE_FLOW_ITEM_TYPE_ETH,
914         RTE_FLOW_ITEM_TYPE_RAW,
915         RTE_FLOW_ITEM_TYPE_VF,
916         RTE_FLOW_ITEM_TYPE_END,
917 };
918
919 static enum rte_flow_item_type pattern_fdir_ethertype_raw_2_vf[] = {
920         RTE_FLOW_ITEM_TYPE_ETH,
921         RTE_FLOW_ITEM_TYPE_RAW,
922         RTE_FLOW_ITEM_TYPE_RAW,
923         RTE_FLOW_ITEM_TYPE_VF,
924         RTE_FLOW_ITEM_TYPE_END,
925 };
926
927 static enum rte_flow_item_type pattern_fdir_ethertype_raw_3_vf[] = {
928         RTE_FLOW_ITEM_TYPE_ETH,
929         RTE_FLOW_ITEM_TYPE_RAW,
930         RTE_FLOW_ITEM_TYPE_RAW,
931         RTE_FLOW_ITEM_TYPE_RAW,
932         RTE_FLOW_ITEM_TYPE_VF,
933         RTE_FLOW_ITEM_TYPE_END,
934 };
935
936 static enum rte_flow_item_type pattern_fdir_ipv4_raw_1_vf[] = {
937         RTE_FLOW_ITEM_TYPE_ETH,
938         RTE_FLOW_ITEM_TYPE_IPV4,
939         RTE_FLOW_ITEM_TYPE_RAW,
940         RTE_FLOW_ITEM_TYPE_VF,
941         RTE_FLOW_ITEM_TYPE_END,
942 };
943
944 static enum rte_flow_item_type pattern_fdir_ipv4_raw_2_vf[] = {
945         RTE_FLOW_ITEM_TYPE_ETH,
946         RTE_FLOW_ITEM_TYPE_IPV4,
947         RTE_FLOW_ITEM_TYPE_RAW,
948         RTE_FLOW_ITEM_TYPE_RAW,
949         RTE_FLOW_ITEM_TYPE_VF,
950         RTE_FLOW_ITEM_TYPE_END,
951 };
952
953 static enum rte_flow_item_type pattern_fdir_ipv4_raw_3_vf[] = {
954         RTE_FLOW_ITEM_TYPE_ETH,
955         RTE_FLOW_ITEM_TYPE_IPV4,
956         RTE_FLOW_ITEM_TYPE_RAW,
957         RTE_FLOW_ITEM_TYPE_RAW,
958         RTE_FLOW_ITEM_TYPE_RAW,
959         RTE_FLOW_ITEM_TYPE_VF,
960         RTE_FLOW_ITEM_TYPE_END,
961 };
962
963 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_1_vf[] = {
964         RTE_FLOW_ITEM_TYPE_ETH,
965         RTE_FLOW_ITEM_TYPE_IPV4,
966         RTE_FLOW_ITEM_TYPE_UDP,
967         RTE_FLOW_ITEM_TYPE_RAW,
968         RTE_FLOW_ITEM_TYPE_VF,
969         RTE_FLOW_ITEM_TYPE_END,
970 };
971
972 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_2_vf[] = {
973         RTE_FLOW_ITEM_TYPE_ETH,
974         RTE_FLOW_ITEM_TYPE_IPV4,
975         RTE_FLOW_ITEM_TYPE_UDP,
976         RTE_FLOW_ITEM_TYPE_RAW,
977         RTE_FLOW_ITEM_TYPE_RAW,
978         RTE_FLOW_ITEM_TYPE_VF,
979         RTE_FLOW_ITEM_TYPE_END,
980 };
981
982 static enum rte_flow_item_type pattern_fdir_ipv4_udp_raw_3_vf[] = {
983         RTE_FLOW_ITEM_TYPE_ETH,
984         RTE_FLOW_ITEM_TYPE_IPV4,
985         RTE_FLOW_ITEM_TYPE_UDP,
986         RTE_FLOW_ITEM_TYPE_RAW,
987         RTE_FLOW_ITEM_TYPE_RAW,
988         RTE_FLOW_ITEM_TYPE_RAW,
989         RTE_FLOW_ITEM_TYPE_VF,
990         RTE_FLOW_ITEM_TYPE_END,
991 };
992
993 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_1_vf[] = {
994         RTE_FLOW_ITEM_TYPE_ETH,
995         RTE_FLOW_ITEM_TYPE_IPV4,
996         RTE_FLOW_ITEM_TYPE_TCP,
997         RTE_FLOW_ITEM_TYPE_RAW,
998         RTE_FLOW_ITEM_TYPE_VF,
999         RTE_FLOW_ITEM_TYPE_END,
1000 };
1001
1002 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_2_vf[] = {
1003         RTE_FLOW_ITEM_TYPE_ETH,
1004         RTE_FLOW_ITEM_TYPE_IPV4,
1005         RTE_FLOW_ITEM_TYPE_TCP,
1006         RTE_FLOW_ITEM_TYPE_RAW,
1007         RTE_FLOW_ITEM_TYPE_RAW,
1008         RTE_FLOW_ITEM_TYPE_VF,
1009         RTE_FLOW_ITEM_TYPE_END,
1010 };
1011
1012 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_raw_3_vf[] = {
1013         RTE_FLOW_ITEM_TYPE_ETH,
1014         RTE_FLOW_ITEM_TYPE_IPV4,
1015         RTE_FLOW_ITEM_TYPE_TCP,
1016         RTE_FLOW_ITEM_TYPE_RAW,
1017         RTE_FLOW_ITEM_TYPE_RAW,
1018         RTE_FLOW_ITEM_TYPE_RAW,
1019         RTE_FLOW_ITEM_TYPE_VF,
1020         RTE_FLOW_ITEM_TYPE_END,
1021 };
1022
1023 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_1_vf[] = {
1024         RTE_FLOW_ITEM_TYPE_ETH,
1025         RTE_FLOW_ITEM_TYPE_IPV4,
1026         RTE_FLOW_ITEM_TYPE_SCTP,
1027         RTE_FLOW_ITEM_TYPE_RAW,
1028         RTE_FLOW_ITEM_TYPE_VF,
1029         RTE_FLOW_ITEM_TYPE_END,
1030 };
1031
1032 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_2_vf[] = {
1033         RTE_FLOW_ITEM_TYPE_ETH,
1034         RTE_FLOW_ITEM_TYPE_IPV4,
1035         RTE_FLOW_ITEM_TYPE_SCTP,
1036         RTE_FLOW_ITEM_TYPE_RAW,
1037         RTE_FLOW_ITEM_TYPE_RAW,
1038         RTE_FLOW_ITEM_TYPE_VF,
1039         RTE_FLOW_ITEM_TYPE_END,
1040 };
1041
1042 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_raw_3_vf[] = {
1043         RTE_FLOW_ITEM_TYPE_ETH,
1044         RTE_FLOW_ITEM_TYPE_IPV4,
1045         RTE_FLOW_ITEM_TYPE_SCTP,
1046         RTE_FLOW_ITEM_TYPE_RAW,
1047         RTE_FLOW_ITEM_TYPE_RAW,
1048         RTE_FLOW_ITEM_TYPE_RAW,
1049         RTE_FLOW_ITEM_TYPE_VF,
1050         RTE_FLOW_ITEM_TYPE_END,
1051 };
1052
1053 static enum rte_flow_item_type pattern_fdir_ipv6_raw_1_vf[] = {
1054         RTE_FLOW_ITEM_TYPE_ETH,
1055         RTE_FLOW_ITEM_TYPE_IPV6,
1056         RTE_FLOW_ITEM_TYPE_RAW,
1057         RTE_FLOW_ITEM_TYPE_VF,
1058         RTE_FLOW_ITEM_TYPE_END,
1059 };
1060
1061 static enum rte_flow_item_type pattern_fdir_ipv6_raw_2_vf[] = {
1062         RTE_FLOW_ITEM_TYPE_ETH,
1063         RTE_FLOW_ITEM_TYPE_IPV6,
1064         RTE_FLOW_ITEM_TYPE_RAW,
1065         RTE_FLOW_ITEM_TYPE_RAW,
1066         RTE_FLOW_ITEM_TYPE_VF,
1067         RTE_FLOW_ITEM_TYPE_END,
1068 };
1069
1070 static enum rte_flow_item_type pattern_fdir_ipv6_raw_3_vf[] = {
1071         RTE_FLOW_ITEM_TYPE_ETH,
1072         RTE_FLOW_ITEM_TYPE_IPV6,
1073         RTE_FLOW_ITEM_TYPE_RAW,
1074         RTE_FLOW_ITEM_TYPE_RAW,
1075         RTE_FLOW_ITEM_TYPE_RAW,
1076         RTE_FLOW_ITEM_TYPE_VF,
1077         RTE_FLOW_ITEM_TYPE_END,
1078 };
1079
1080 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_1_vf[] = {
1081         RTE_FLOW_ITEM_TYPE_ETH,
1082         RTE_FLOW_ITEM_TYPE_IPV6,
1083         RTE_FLOW_ITEM_TYPE_UDP,
1084         RTE_FLOW_ITEM_TYPE_RAW,
1085         RTE_FLOW_ITEM_TYPE_VF,
1086         RTE_FLOW_ITEM_TYPE_END,
1087 };
1088
1089 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_2_vf[] = {
1090         RTE_FLOW_ITEM_TYPE_ETH,
1091         RTE_FLOW_ITEM_TYPE_IPV6,
1092         RTE_FLOW_ITEM_TYPE_UDP,
1093         RTE_FLOW_ITEM_TYPE_RAW,
1094         RTE_FLOW_ITEM_TYPE_RAW,
1095         RTE_FLOW_ITEM_TYPE_VF,
1096         RTE_FLOW_ITEM_TYPE_END,
1097 };
1098
1099 static enum rte_flow_item_type pattern_fdir_ipv6_udp_raw_3_vf[] = {
1100         RTE_FLOW_ITEM_TYPE_ETH,
1101         RTE_FLOW_ITEM_TYPE_IPV6,
1102         RTE_FLOW_ITEM_TYPE_UDP,
1103         RTE_FLOW_ITEM_TYPE_RAW,
1104         RTE_FLOW_ITEM_TYPE_RAW,
1105         RTE_FLOW_ITEM_TYPE_RAW,
1106         RTE_FLOW_ITEM_TYPE_VF,
1107         RTE_FLOW_ITEM_TYPE_END,
1108 };
1109
1110 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_1_vf[] = {
1111         RTE_FLOW_ITEM_TYPE_ETH,
1112         RTE_FLOW_ITEM_TYPE_IPV6,
1113         RTE_FLOW_ITEM_TYPE_TCP,
1114         RTE_FLOW_ITEM_TYPE_RAW,
1115         RTE_FLOW_ITEM_TYPE_VF,
1116         RTE_FLOW_ITEM_TYPE_END,
1117 };
1118
1119 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_2_vf[] = {
1120         RTE_FLOW_ITEM_TYPE_ETH,
1121         RTE_FLOW_ITEM_TYPE_IPV6,
1122         RTE_FLOW_ITEM_TYPE_TCP,
1123         RTE_FLOW_ITEM_TYPE_RAW,
1124         RTE_FLOW_ITEM_TYPE_RAW,
1125         RTE_FLOW_ITEM_TYPE_VF,
1126         RTE_FLOW_ITEM_TYPE_END,
1127 };
1128
1129 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_raw_3_vf[] = {
1130         RTE_FLOW_ITEM_TYPE_ETH,
1131         RTE_FLOW_ITEM_TYPE_IPV6,
1132         RTE_FLOW_ITEM_TYPE_TCP,
1133         RTE_FLOW_ITEM_TYPE_RAW,
1134         RTE_FLOW_ITEM_TYPE_RAW,
1135         RTE_FLOW_ITEM_TYPE_RAW,
1136         RTE_FLOW_ITEM_TYPE_VF,
1137         RTE_FLOW_ITEM_TYPE_END,
1138 };
1139
1140 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_1_vf[] = {
1141         RTE_FLOW_ITEM_TYPE_ETH,
1142         RTE_FLOW_ITEM_TYPE_IPV6,
1143         RTE_FLOW_ITEM_TYPE_SCTP,
1144         RTE_FLOW_ITEM_TYPE_RAW,
1145         RTE_FLOW_ITEM_TYPE_VF,
1146         RTE_FLOW_ITEM_TYPE_END,
1147 };
1148
1149 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_2_vf[] = {
1150         RTE_FLOW_ITEM_TYPE_ETH,
1151         RTE_FLOW_ITEM_TYPE_IPV6,
1152         RTE_FLOW_ITEM_TYPE_SCTP,
1153         RTE_FLOW_ITEM_TYPE_RAW,
1154         RTE_FLOW_ITEM_TYPE_RAW,
1155         RTE_FLOW_ITEM_TYPE_VF,
1156         RTE_FLOW_ITEM_TYPE_END,
1157 };
1158
1159 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_raw_3_vf[] = {
1160         RTE_FLOW_ITEM_TYPE_ETH,
1161         RTE_FLOW_ITEM_TYPE_IPV6,
1162         RTE_FLOW_ITEM_TYPE_SCTP,
1163         RTE_FLOW_ITEM_TYPE_RAW,
1164         RTE_FLOW_ITEM_TYPE_RAW,
1165         RTE_FLOW_ITEM_TYPE_RAW,
1166         RTE_FLOW_ITEM_TYPE_VF,
1167         RTE_FLOW_ITEM_TYPE_END,
1168 };
1169
1170 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_vf[] = {
1171         RTE_FLOW_ITEM_TYPE_ETH,
1172         RTE_FLOW_ITEM_TYPE_VLAN,
1173         RTE_FLOW_ITEM_TYPE_VF,
1174         RTE_FLOW_ITEM_TYPE_END,
1175 };
1176
1177 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_vf[] = {
1178         RTE_FLOW_ITEM_TYPE_ETH,
1179         RTE_FLOW_ITEM_TYPE_VLAN,
1180         RTE_FLOW_ITEM_TYPE_IPV4,
1181         RTE_FLOW_ITEM_TYPE_VF,
1182         RTE_FLOW_ITEM_TYPE_END,
1183 };
1184
1185 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_vf[] = {
1186         RTE_FLOW_ITEM_TYPE_ETH,
1187         RTE_FLOW_ITEM_TYPE_VLAN,
1188         RTE_FLOW_ITEM_TYPE_IPV4,
1189         RTE_FLOW_ITEM_TYPE_UDP,
1190         RTE_FLOW_ITEM_TYPE_VF,
1191         RTE_FLOW_ITEM_TYPE_END,
1192 };
1193
1194 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_vf[] = {
1195         RTE_FLOW_ITEM_TYPE_ETH,
1196         RTE_FLOW_ITEM_TYPE_VLAN,
1197         RTE_FLOW_ITEM_TYPE_IPV4,
1198         RTE_FLOW_ITEM_TYPE_TCP,
1199         RTE_FLOW_ITEM_TYPE_VF,
1200         RTE_FLOW_ITEM_TYPE_END,
1201 };
1202
1203 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_vf[] = {
1204         RTE_FLOW_ITEM_TYPE_ETH,
1205         RTE_FLOW_ITEM_TYPE_VLAN,
1206         RTE_FLOW_ITEM_TYPE_IPV4,
1207         RTE_FLOW_ITEM_TYPE_SCTP,
1208         RTE_FLOW_ITEM_TYPE_VF,
1209         RTE_FLOW_ITEM_TYPE_END,
1210 };
1211
1212 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_vf[] = {
1213         RTE_FLOW_ITEM_TYPE_ETH,
1214         RTE_FLOW_ITEM_TYPE_VLAN,
1215         RTE_FLOW_ITEM_TYPE_IPV6,
1216         RTE_FLOW_ITEM_TYPE_VF,
1217         RTE_FLOW_ITEM_TYPE_END,
1218 };
1219
1220 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_vf[] = {
1221         RTE_FLOW_ITEM_TYPE_ETH,
1222         RTE_FLOW_ITEM_TYPE_VLAN,
1223         RTE_FLOW_ITEM_TYPE_IPV6,
1224         RTE_FLOW_ITEM_TYPE_UDP,
1225         RTE_FLOW_ITEM_TYPE_VF,
1226         RTE_FLOW_ITEM_TYPE_END,
1227 };
1228
1229 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_vf[] = {
1230         RTE_FLOW_ITEM_TYPE_ETH,
1231         RTE_FLOW_ITEM_TYPE_VLAN,
1232         RTE_FLOW_ITEM_TYPE_IPV6,
1233         RTE_FLOW_ITEM_TYPE_TCP,
1234         RTE_FLOW_ITEM_TYPE_VF,
1235         RTE_FLOW_ITEM_TYPE_END,
1236 };
1237
1238 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_vf[] = {
1239         RTE_FLOW_ITEM_TYPE_ETH,
1240         RTE_FLOW_ITEM_TYPE_VLAN,
1241         RTE_FLOW_ITEM_TYPE_IPV6,
1242         RTE_FLOW_ITEM_TYPE_SCTP,
1243         RTE_FLOW_ITEM_TYPE_VF,
1244         RTE_FLOW_ITEM_TYPE_END,
1245 };
1246
1247 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_1_vf[] = {
1248         RTE_FLOW_ITEM_TYPE_ETH,
1249         RTE_FLOW_ITEM_TYPE_VLAN,
1250         RTE_FLOW_ITEM_TYPE_RAW,
1251         RTE_FLOW_ITEM_TYPE_VF,
1252         RTE_FLOW_ITEM_TYPE_END,
1253 };
1254
1255 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_2_vf[] = {
1256         RTE_FLOW_ITEM_TYPE_ETH,
1257         RTE_FLOW_ITEM_TYPE_VLAN,
1258         RTE_FLOW_ITEM_TYPE_RAW,
1259         RTE_FLOW_ITEM_TYPE_RAW,
1260         RTE_FLOW_ITEM_TYPE_VF,
1261         RTE_FLOW_ITEM_TYPE_END,
1262 };
1263
1264 static enum rte_flow_item_type pattern_fdir_ethertype_vlan_raw_3_vf[] = {
1265         RTE_FLOW_ITEM_TYPE_ETH,
1266         RTE_FLOW_ITEM_TYPE_VLAN,
1267         RTE_FLOW_ITEM_TYPE_RAW,
1268         RTE_FLOW_ITEM_TYPE_RAW,
1269         RTE_FLOW_ITEM_TYPE_RAW,
1270         RTE_FLOW_ITEM_TYPE_VF,
1271         RTE_FLOW_ITEM_TYPE_END,
1272 };
1273
1274 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_1_vf[] = {
1275         RTE_FLOW_ITEM_TYPE_ETH,
1276         RTE_FLOW_ITEM_TYPE_VLAN,
1277         RTE_FLOW_ITEM_TYPE_IPV4,
1278         RTE_FLOW_ITEM_TYPE_RAW,
1279         RTE_FLOW_ITEM_TYPE_VF,
1280         RTE_FLOW_ITEM_TYPE_END,
1281 };
1282
1283 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_2_vf[] = {
1284         RTE_FLOW_ITEM_TYPE_ETH,
1285         RTE_FLOW_ITEM_TYPE_VLAN,
1286         RTE_FLOW_ITEM_TYPE_IPV4,
1287         RTE_FLOW_ITEM_TYPE_RAW,
1288         RTE_FLOW_ITEM_TYPE_RAW,
1289         RTE_FLOW_ITEM_TYPE_VF,
1290         RTE_FLOW_ITEM_TYPE_END,
1291 };
1292
1293 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_raw_3_vf[] = {
1294         RTE_FLOW_ITEM_TYPE_ETH,
1295         RTE_FLOW_ITEM_TYPE_VLAN,
1296         RTE_FLOW_ITEM_TYPE_IPV4,
1297         RTE_FLOW_ITEM_TYPE_RAW,
1298         RTE_FLOW_ITEM_TYPE_RAW,
1299         RTE_FLOW_ITEM_TYPE_RAW,
1300         RTE_FLOW_ITEM_TYPE_VF,
1301         RTE_FLOW_ITEM_TYPE_END,
1302 };
1303
1304 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_1_vf[] = {
1305         RTE_FLOW_ITEM_TYPE_ETH,
1306         RTE_FLOW_ITEM_TYPE_VLAN,
1307         RTE_FLOW_ITEM_TYPE_IPV4,
1308         RTE_FLOW_ITEM_TYPE_UDP,
1309         RTE_FLOW_ITEM_TYPE_RAW,
1310         RTE_FLOW_ITEM_TYPE_VF,
1311         RTE_FLOW_ITEM_TYPE_END,
1312 };
1313
1314 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_2_vf[] = {
1315         RTE_FLOW_ITEM_TYPE_ETH,
1316         RTE_FLOW_ITEM_TYPE_VLAN,
1317         RTE_FLOW_ITEM_TYPE_IPV4,
1318         RTE_FLOW_ITEM_TYPE_UDP,
1319         RTE_FLOW_ITEM_TYPE_RAW,
1320         RTE_FLOW_ITEM_TYPE_RAW,
1321         RTE_FLOW_ITEM_TYPE_VF,
1322         RTE_FLOW_ITEM_TYPE_END,
1323 };
1324
1325 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_udp_raw_3_vf[] = {
1326         RTE_FLOW_ITEM_TYPE_ETH,
1327         RTE_FLOW_ITEM_TYPE_VLAN,
1328         RTE_FLOW_ITEM_TYPE_IPV4,
1329         RTE_FLOW_ITEM_TYPE_UDP,
1330         RTE_FLOW_ITEM_TYPE_RAW,
1331         RTE_FLOW_ITEM_TYPE_RAW,
1332         RTE_FLOW_ITEM_TYPE_RAW,
1333         RTE_FLOW_ITEM_TYPE_VF,
1334         RTE_FLOW_ITEM_TYPE_END,
1335 };
1336
1337 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_1_vf[] = {
1338         RTE_FLOW_ITEM_TYPE_ETH,
1339         RTE_FLOW_ITEM_TYPE_VLAN,
1340         RTE_FLOW_ITEM_TYPE_IPV4,
1341         RTE_FLOW_ITEM_TYPE_TCP,
1342         RTE_FLOW_ITEM_TYPE_RAW,
1343         RTE_FLOW_ITEM_TYPE_VF,
1344         RTE_FLOW_ITEM_TYPE_END,
1345 };
1346
1347 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_2_vf[] = {
1348         RTE_FLOW_ITEM_TYPE_ETH,
1349         RTE_FLOW_ITEM_TYPE_VLAN,
1350         RTE_FLOW_ITEM_TYPE_IPV4,
1351         RTE_FLOW_ITEM_TYPE_TCP,
1352         RTE_FLOW_ITEM_TYPE_RAW,
1353         RTE_FLOW_ITEM_TYPE_RAW,
1354         RTE_FLOW_ITEM_TYPE_VF,
1355         RTE_FLOW_ITEM_TYPE_END,
1356 };
1357
1358 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_tcp_raw_3_vf[] = {
1359         RTE_FLOW_ITEM_TYPE_ETH,
1360         RTE_FLOW_ITEM_TYPE_VLAN,
1361         RTE_FLOW_ITEM_TYPE_IPV4,
1362         RTE_FLOW_ITEM_TYPE_TCP,
1363         RTE_FLOW_ITEM_TYPE_RAW,
1364         RTE_FLOW_ITEM_TYPE_RAW,
1365         RTE_FLOW_ITEM_TYPE_RAW,
1366         RTE_FLOW_ITEM_TYPE_VF,
1367         RTE_FLOW_ITEM_TYPE_END,
1368 };
1369
1370 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_1_vf[] = {
1371         RTE_FLOW_ITEM_TYPE_ETH,
1372         RTE_FLOW_ITEM_TYPE_VLAN,
1373         RTE_FLOW_ITEM_TYPE_IPV4,
1374         RTE_FLOW_ITEM_TYPE_SCTP,
1375         RTE_FLOW_ITEM_TYPE_RAW,
1376         RTE_FLOW_ITEM_TYPE_VF,
1377         RTE_FLOW_ITEM_TYPE_END,
1378 };
1379
1380 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_2_vf[] = {
1381         RTE_FLOW_ITEM_TYPE_ETH,
1382         RTE_FLOW_ITEM_TYPE_VLAN,
1383         RTE_FLOW_ITEM_TYPE_IPV4,
1384         RTE_FLOW_ITEM_TYPE_SCTP,
1385         RTE_FLOW_ITEM_TYPE_RAW,
1386         RTE_FLOW_ITEM_TYPE_RAW,
1387         RTE_FLOW_ITEM_TYPE_VF,
1388         RTE_FLOW_ITEM_TYPE_END,
1389 };
1390
1391 static enum rte_flow_item_type pattern_fdir_vlan_ipv4_sctp_raw_3_vf[] = {
1392         RTE_FLOW_ITEM_TYPE_ETH,
1393         RTE_FLOW_ITEM_TYPE_VLAN,
1394         RTE_FLOW_ITEM_TYPE_IPV4,
1395         RTE_FLOW_ITEM_TYPE_SCTP,
1396         RTE_FLOW_ITEM_TYPE_RAW,
1397         RTE_FLOW_ITEM_TYPE_RAW,
1398         RTE_FLOW_ITEM_TYPE_RAW,
1399         RTE_FLOW_ITEM_TYPE_VF,
1400         RTE_FLOW_ITEM_TYPE_END,
1401 };
1402
1403 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_1_vf[] = {
1404         RTE_FLOW_ITEM_TYPE_ETH,
1405         RTE_FLOW_ITEM_TYPE_VLAN,
1406         RTE_FLOW_ITEM_TYPE_IPV6,
1407         RTE_FLOW_ITEM_TYPE_RAW,
1408         RTE_FLOW_ITEM_TYPE_VF,
1409         RTE_FLOW_ITEM_TYPE_END,
1410 };
1411
1412 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_2_vf[] = {
1413         RTE_FLOW_ITEM_TYPE_ETH,
1414         RTE_FLOW_ITEM_TYPE_VLAN,
1415         RTE_FLOW_ITEM_TYPE_IPV6,
1416         RTE_FLOW_ITEM_TYPE_RAW,
1417         RTE_FLOW_ITEM_TYPE_RAW,
1418         RTE_FLOW_ITEM_TYPE_VF,
1419         RTE_FLOW_ITEM_TYPE_END,
1420 };
1421
1422 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_raw_3_vf[] = {
1423         RTE_FLOW_ITEM_TYPE_ETH,
1424         RTE_FLOW_ITEM_TYPE_VLAN,
1425         RTE_FLOW_ITEM_TYPE_IPV6,
1426         RTE_FLOW_ITEM_TYPE_RAW,
1427         RTE_FLOW_ITEM_TYPE_RAW,
1428         RTE_FLOW_ITEM_TYPE_RAW,
1429         RTE_FLOW_ITEM_TYPE_VF,
1430         RTE_FLOW_ITEM_TYPE_END,
1431 };
1432
1433 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_1_vf[] = {
1434         RTE_FLOW_ITEM_TYPE_ETH,
1435         RTE_FLOW_ITEM_TYPE_VLAN,
1436         RTE_FLOW_ITEM_TYPE_IPV6,
1437         RTE_FLOW_ITEM_TYPE_UDP,
1438         RTE_FLOW_ITEM_TYPE_RAW,
1439         RTE_FLOW_ITEM_TYPE_VF,
1440         RTE_FLOW_ITEM_TYPE_END,
1441 };
1442
1443 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_2_vf[] = {
1444         RTE_FLOW_ITEM_TYPE_ETH,
1445         RTE_FLOW_ITEM_TYPE_VLAN,
1446         RTE_FLOW_ITEM_TYPE_IPV6,
1447         RTE_FLOW_ITEM_TYPE_UDP,
1448         RTE_FLOW_ITEM_TYPE_RAW,
1449         RTE_FLOW_ITEM_TYPE_RAW,
1450         RTE_FLOW_ITEM_TYPE_VF,
1451         RTE_FLOW_ITEM_TYPE_END,
1452 };
1453
1454 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_udp_raw_3_vf[] = {
1455         RTE_FLOW_ITEM_TYPE_ETH,
1456         RTE_FLOW_ITEM_TYPE_VLAN,
1457         RTE_FLOW_ITEM_TYPE_IPV6,
1458         RTE_FLOW_ITEM_TYPE_UDP,
1459         RTE_FLOW_ITEM_TYPE_RAW,
1460         RTE_FLOW_ITEM_TYPE_RAW,
1461         RTE_FLOW_ITEM_TYPE_RAW,
1462         RTE_FLOW_ITEM_TYPE_VF,
1463         RTE_FLOW_ITEM_TYPE_END,
1464 };
1465
1466 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_1_vf[] = {
1467         RTE_FLOW_ITEM_TYPE_ETH,
1468         RTE_FLOW_ITEM_TYPE_VLAN,
1469         RTE_FLOW_ITEM_TYPE_IPV6,
1470         RTE_FLOW_ITEM_TYPE_TCP,
1471         RTE_FLOW_ITEM_TYPE_RAW,
1472         RTE_FLOW_ITEM_TYPE_VF,
1473         RTE_FLOW_ITEM_TYPE_END,
1474 };
1475
1476 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_2_vf[] = {
1477         RTE_FLOW_ITEM_TYPE_ETH,
1478         RTE_FLOW_ITEM_TYPE_VLAN,
1479         RTE_FLOW_ITEM_TYPE_IPV6,
1480         RTE_FLOW_ITEM_TYPE_TCP,
1481         RTE_FLOW_ITEM_TYPE_RAW,
1482         RTE_FLOW_ITEM_TYPE_RAW,
1483         RTE_FLOW_ITEM_TYPE_VF,
1484         RTE_FLOW_ITEM_TYPE_END,
1485 };
1486
1487 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_tcp_raw_3_vf[] = {
1488         RTE_FLOW_ITEM_TYPE_ETH,
1489         RTE_FLOW_ITEM_TYPE_VLAN,
1490         RTE_FLOW_ITEM_TYPE_IPV6,
1491         RTE_FLOW_ITEM_TYPE_TCP,
1492         RTE_FLOW_ITEM_TYPE_RAW,
1493         RTE_FLOW_ITEM_TYPE_RAW,
1494         RTE_FLOW_ITEM_TYPE_RAW,
1495         RTE_FLOW_ITEM_TYPE_VF,
1496         RTE_FLOW_ITEM_TYPE_END,
1497 };
1498
1499 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_1_vf[] = {
1500         RTE_FLOW_ITEM_TYPE_ETH,
1501         RTE_FLOW_ITEM_TYPE_VLAN,
1502         RTE_FLOW_ITEM_TYPE_IPV6,
1503         RTE_FLOW_ITEM_TYPE_SCTP,
1504         RTE_FLOW_ITEM_TYPE_RAW,
1505         RTE_FLOW_ITEM_TYPE_VF,
1506         RTE_FLOW_ITEM_TYPE_END,
1507 };
1508
1509 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_2_vf[] = {
1510         RTE_FLOW_ITEM_TYPE_ETH,
1511         RTE_FLOW_ITEM_TYPE_VLAN,
1512         RTE_FLOW_ITEM_TYPE_IPV6,
1513         RTE_FLOW_ITEM_TYPE_SCTP,
1514         RTE_FLOW_ITEM_TYPE_RAW,
1515         RTE_FLOW_ITEM_TYPE_RAW,
1516         RTE_FLOW_ITEM_TYPE_VF,
1517         RTE_FLOW_ITEM_TYPE_END,
1518 };
1519
1520 static enum rte_flow_item_type pattern_fdir_vlan_ipv6_sctp_raw_3_vf[] = {
1521         RTE_FLOW_ITEM_TYPE_ETH,
1522         RTE_FLOW_ITEM_TYPE_VLAN,
1523         RTE_FLOW_ITEM_TYPE_IPV6,
1524         RTE_FLOW_ITEM_TYPE_SCTP,
1525         RTE_FLOW_ITEM_TYPE_RAW,
1526         RTE_FLOW_ITEM_TYPE_RAW,
1527         RTE_FLOW_ITEM_TYPE_RAW,
1528         RTE_FLOW_ITEM_TYPE_VF,
1529         RTE_FLOW_ITEM_TYPE_END,
1530 };
1531
1532 /* Pattern matched tunnel filter */
1533 static enum rte_flow_item_type pattern_vxlan_1[] = {
1534         RTE_FLOW_ITEM_TYPE_ETH,
1535         RTE_FLOW_ITEM_TYPE_IPV4,
1536         RTE_FLOW_ITEM_TYPE_UDP,
1537         RTE_FLOW_ITEM_TYPE_VXLAN,
1538         RTE_FLOW_ITEM_TYPE_ETH,
1539         RTE_FLOW_ITEM_TYPE_END,
1540 };
1541
1542 static enum rte_flow_item_type pattern_vxlan_2[] = {
1543         RTE_FLOW_ITEM_TYPE_ETH,
1544         RTE_FLOW_ITEM_TYPE_IPV6,
1545         RTE_FLOW_ITEM_TYPE_UDP,
1546         RTE_FLOW_ITEM_TYPE_VXLAN,
1547         RTE_FLOW_ITEM_TYPE_ETH,
1548         RTE_FLOW_ITEM_TYPE_END,
1549 };
1550
1551 static enum rte_flow_item_type pattern_vxlan_3[] = {
1552         RTE_FLOW_ITEM_TYPE_ETH,
1553         RTE_FLOW_ITEM_TYPE_IPV4,
1554         RTE_FLOW_ITEM_TYPE_UDP,
1555         RTE_FLOW_ITEM_TYPE_VXLAN,
1556         RTE_FLOW_ITEM_TYPE_ETH,
1557         RTE_FLOW_ITEM_TYPE_VLAN,
1558         RTE_FLOW_ITEM_TYPE_END,
1559 };
1560
1561 static enum rte_flow_item_type pattern_vxlan_4[] = {
1562         RTE_FLOW_ITEM_TYPE_ETH,
1563         RTE_FLOW_ITEM_TYPE_IPV6,
1564         RTE_FLOW_ITEM_TYPE_UDP,
1565         RTE_FLOW_ITEM_TYPE_VXLAN,
1566         RTE_FLOW_ITEM_TYPE_ETH,
1567         RTE_FLOW_ITEM_TYPE_VLAN,
1568         RTE_FLOW_ITEM_TYPE_END,
1569 };
1570
1571 static enum rte_flow_item_type pattern_nvgre_1[] = {
1572         RTE_FLOW_ITEM_TYPE_ETH,
1573         RTE_FLOW_ITEM_TYPE_IPV4,
1574         RTE_FLOW_ITEM_TYPE_NVGRE,
1575         RTE_FLOW_ITEM_TYPE_ETH,
1576         RTE_FLOW_ITEM_TYPE_END,
1577 };
1578
1579 static enum rte_flow_item_type pattern_nvgre_2[] = {
1580         RTE_FLOW_ITEM_TYPE_ETH,
1581         RTE_FLOW_ITEM_TYPE_IPV6,
1582         RTE_FLOW_ITEM_TYPE_NVGRE,
1583         RTE_FLOW_ITEM_TYPE_ETH,
1584         RTE_FLOW_ITEM_TYPE_END,
1585 };
1586
1587 static enum rte_flow_item_type pattern_nvgre_3[] = {
1588         RTE_FLOW_ITEM_TYPE_ETH,
1589         RTE_FLOW_ITEM_TYPE_IPV4,
1590         RTE_FLOW_ITEM_TYPE_NVGRE,
1591         RTE_FLOW_ITEM_TYPE_ETH,
1592         RTE_FLOW_ITEM_TYPE_VLAN,
1593         RTE_FLOW_ITEM_TYPE_END,
1594 };
1595
1596 static enum rte_flow_item_type pattern_nvgre_4[] = {
1597         RTE_FLOW_ITEM_TYPE_ETH,
1598         RTE_FLOW_ITEM_TYPE_IPV6,
1599         RTE_FLOW_ITEM_TYPE_NVGRE,
1600         RTE_FLOW_ITEM_TYPE_ETH,
1601         RTE_FLOW_ITEM_TYPE_VLAN,
1602         RTE_FLOW_ITEM_TYPE_END,
1603 };
1604
1605 static enum rte_flow_item_type pattern_mpls_1[] = {
1606         RTE_FLOW_ITEM_TYPE_ETH,
1607         RTE_FLOW_ITEM_TYPE_IPV4,
1608         RTE_FLOW_ITEM_TYPE_UDP,
1609         RTE_FLOW_ITEM_TYPE_MPLS,
1610         RTE_FLOW_ITEM_TYPE_END,
1611 };
1612
1613 static enum rte_flow_item_type pattern_mpls_2[] = {
1614         RTE_FLOW_ITEM_TYPE_ETH,
1615         RTE_FLOW_ITEM_TYPE_IPV6,
1616         RTE_FLOW_ITEM_TYPE_UDP,
1617         RTE_FLOW_ITEM_TYPE_MPLS,
1618         RTE_FLOW_ITEM_TYPE_END,
1619 };
1620
1621 static enum rte_flow_item_type pattern_mpls_3[] = {
1622         RTE_FLOW_ITEM_TYPE_ETH,
1623         RTE_FLOW_ITEM_TYPE_IPV4,
1624         RTE_FLOW_ITEM_TYPE_GRE,
1625         RTE_FLOW_ITEM_TYPE_MPLS,
1626         RTE_FLOW_ITEM_TYPE_END,
1627 };
1628
1629 static enum rte_flow_item_type pattern_mpls_4[] = {
1630         RTE_FLOW_ITEM_TYPE_ETH,
1631         RTE_FLOW_ITEM_TYPE_IPV6,
1632         RTE_FLOW_ITEM_TYPE_GRE,
1633         RTE_FLOW_ITEM_TYPE_MPLS,
1634         RTE_FLOW_ITEM_TYPE_END,
1635 };
1636
1637 static enum rte_flow_item_type pattern_qinq_1[] = {
1638         RTE_FLOW_ITEM_TYPE_ETH,
1639         RTE_FLOW_ITEM_TYPE_VLAN,
1640         RTE_FLOW_ITEM_TYPE_VLAN,
1641         RTE_FLOW_ITEM_TYPE_END,
1642 };
1643
1644 static struct i40e_valid_pattern i40e_supported_patterns[] = {
1645         /* Ethertype */
1646         { pattern_ethertype, i40e_flow_parse_ethertype_filter },
1647         /* FDIR - support default flow type without flexible payload*/
1648         { pattern_ethertype, i40e_flow_parse_fdir_filter },
1649         { pattern_fdir_ipv4, i40e_flow_parse_fdir_filter },
1650         { pattern_fdir_ipv4_udp, i40e_flow_parse_fdir_filter },
1651         { pattern_fdir_ipv4_tcp, i40e_flow_parse_fdir_filter },
1652         { pattern_fdir_ipv4_sctp, i40e_flow_parse_fdir_filter },
1653         { pattern_fdir_ipv4_gtpc, i40e_flow_parse_fdir_filter },
1654         { pattern_fdir_ipv4_gtpu, i40e_flow_parse_fdir_filter },
1655         { pattern_fdir_ipv4_gtpu_ipv4, i40e_flow_parse_fdir_filter },
1656         { pattern_fdir_ipv4_gtpu_ipv6, i40e_flow_parse_fdir_filter },
1657         { pattern_fdir_ipv6, i40e_flow_parse_fdir_filter },
1658         { pattern_fdir_ipv6_udp, i40e_flow_parse_fdir_filter },
1659         { pattern_fdir_ipv6_tcp, i40e_flow_parse_fdir_filter },
1660         { pattern_fdir_ipv6_sctp, i40e_flow_parse_fdir_filter },
1661         { pattern_fdir_ipv6_gtpc, i40e_flow_parse_fdir_filter },
1662         { pattern_fdir_ipv6_gtpu, i40e_flow_parse_fdir_filter },
1663         { pattern_fdir_ipv6_gtpu_ipv4, i40e_flow_parse_fdir_filter },
1664         { pattern_fdir_ipv6_gtpu_ipv6, i40e_flow_parse_fdir_filter },
1665         /* FDIR - support default flow type with flexible payload */
1666         { pattern_fdir_ethertype_raw_1, i40e_flow_parse_fdir_filter },
1667         { pattern_fdir_ethertype_raw_2, i40e_flow_parse_fdir_filter },
1668         { pattern_fdir_ethertype_raw_3, i40e_flow_parse_fdir_filter },
1669         { pattern_fdir_ipv4_raw_1, i40e_flow_parse_fdir_filter },
1670         { pattern_fdir_ipv4_raw_2, i40e_flow_parse_fdir_filter },
1671         { pattern_fdir_ipv4_raw_3, i40e_flow_parse_fdir_filter },
1672         { pattern_fdir_ipv4_udp_raw_1, i40e_flow_parse_fdir_filter },
1673         { pattern_fdir_ipv4_udp_raw_2, i40e_flow_parse_fdir_filter },
1674         { pattern_fdir_ipv4_udp_raw_3, i40e_flow_parse_fdir_filter },
1675         { pattern_fdir_ipv4_tcp_raw_1, i40e_flow_parse_fdir_filter },
1676         { pattern_fdir_ipv4_tcp_raw_2, i40e_flow_parse_fdir_filter },
1677         { pattern_fdir_ipv4_tcp_raw_3, i40e_flow_parse_fdir_filter },
1678         { pattern_fdir_ipv4_sctp_raw_1, i40e_flow_parse_fdir_filter },
1679         { pattern_fdir_ipv4_sctp_raw_2, i40e_flow_parse_fdir_filter },
1680         { pattern_fdir_ipv4_sctp_raw_3, i40e_flow_parse_fdir_filter },
1681         { pattern_fdir_ipv6_raw_1, i40e_flow_parse_fdir_filter },
1682         { pattern_fdir_ipv6_raw_2, i40e_flow_parse_fdir_filter },
1683         { pattern_fdir_ipv6_raw_3, i40e_flow_parse_fdir_filter },
1684         { pattern_fdir_ipv6_udp_raw_1, i40e_flow_parse_fdir_filter },
1685         { pattern_fdir_ipv6_udp_raw_2, i40e_flow_parse_fdir_filter },
1686         { pattern_fdir_ipv6_udp_raw_3, i40e_flow_parse_fdir_filter },
1687         { pattern_fdir_ipv6_tcp_raw_1, i40e_flow_parse_fdir_filter },
1688         { pattern_fdir_ipv6_tcp_raw_2, i40e_flow_parse_fdir_filter },
1689         { pattern_fdir_ipv6_tcp_raw_3, i40e_flow_parse_fdir_filter },
1690         { pattern_fdir_ipv6_sctp_raw_1, i40e_flow_parse_fdir_filter },
1691         { pattern_fdir_ipv6_sctp_raw_2, i40e_flow_parse_fdir_filter },
1692         { pattern_fdir_ipv6_sctp_raw_3, i40e_flow_parse_fdir_filter },
1693         /* FDIR - support single vlan input set */
1694         { pattern_fdir_ethertype_vlan, i40e_flow_parse_fdir_filter },
1695         { pattern_fdir_vlan_ipv4, i40e_flow_parse_fdir_filter },
1696         { pattern_fdir_vlan_ipv4_udp, i40e_flow_parse_fdir_filter },
1697         { pattern_fdir_vlan_ipv4_tcp, i40e_flow_parse_fdir_filter },
1698         { pattern_fdir_vlan_ipv4_sctp, i40e_flow_parse_fdir_filter },
1699         { pattern_fdir_vlan_ipv6, i40e_flow_parse_fdir_filter },
1700         { pattern_fdir_vlan_ipv6_udp, i40e_flow_parse_fdir_filter },
1701         { pattern_fdir_vlan_ipv6_tcp, i40e_flow_parse_fdir_filter },
1702         { pattern_fdir_vlan_ipv6_sctp, i40e_flow_parse_fdir_filter },
1703         { pattern_fdir_ethertype_vlan_raw_1, i40e_flow_parse_fdir_filter },
1704         { pattern_fdir_ethertype_vlan_raw_2, i40e_flow_parse_fdir_filter },
1705         { pattern_fdir_ethertype_vlan_raw_3, i40e_flow_parse_fdir_filter },
1706         { pattern_fdir_vlan_ipv4_raw_1, i40e_flow_parse_fdir_filter },
1707         { pattern_fdir_vlan_ipv4_raw_2, i40e_flow_parse_fdir_filter },
1708         { pattern_fdir_vlan_ipv4_raw_3, i40e_flow_parse_fdir_filter },
1709         { pattern_fdir_vlan_ipv4_udp_raw_1, i40e_flow_parse_fdir_filter },
1710         { pattern_fdir_vlan_ipv4_udp_raw_2, i40e_flow_parse_fdir_filter },
1711         { pattern_fdir_vlan_ipv4_udp_raw_3, i40e_flow_parse_fdir_filter },
1712         { pattern_fdir_vlan_ipv4_tcp_raw_1, i40e_flow_parse_fdir_filter },
1713         { pattern_fdir_vlan_ipv4_tcp_raw_2, i40e_flow_parse_fdir_filter },
1714         { pattern_fdir_vlan_ipv4_tcp_raw_3, i40e_flow_parse_fdir_filter },
1715         { pattern_fdir_vlan_ipv4_sctp_raw_1, i40e_flow_parse_fdir_filter },
1716         { pattern_fdir_vlan_ipv4_sctp_raw_2, i40e_flow_parse_fdir_filter },
1717         { pattern_fdir_vlan_ipv4_sctp_raw_3, i40e_flow_parse_fdir_filter },
1718         { pattern_fdir_vlan_ipv6_raw_1, i40e_flow_parse_fdir_filter },
1719         { pattern_fdir_vlan_ipv6_raw_2, i40e_flow_parse_fdir_filter },
1720         { pattern_fdir_vlan_ipv6_raw_3, i40e_flow_parse_fdir_filter },
1721         { pattern_fdir_vlan_ipv6_udp_raw_1, i40e_flow_parse_fdir_filter },
1722         { pattern_fdir_vlan_ipv6_udp_raw_2, i40e_flow_parse_fdir_filter },
1723         { pattern_fdir_vlan_ipv6_udp_raw_3, i40e_flow_parse_fdir_filter },
1724         { pattern_fdir_vlan_ipv6_tcp_raw_1, i40e_flow_parse_fdir_filter },
1725         { pattern_fdir_vlan_ipv6_tcp_raw_2, i40e_flow_parse_fdir_filter },
1726         { pattern_fdir_vlan_ipv6_tcp_raw_3, i40e_flow_parse_fdir_filter },
1727         { pattern_fdir_vlan_ipv6_sctp_raw_1, i40e_flow_parse_fdir_filter },
1728         { pattern_fdir_vlan_ipv6_sctp_raw_2, i40e_flow_parse_fdir_filter },
1729         { pattern_fdir_vlan_ipv6_sctp_raw_3, i40e_flow_parse_fdir_filter },
1730         /* FDIR - support VF item */
1731         { pattern_fdir_ipv4_vf, i40e_flow_parse_fdir_filter },
1732         { pattern_fdir_ipv4_udp_vf, i40e_flow_parse_fdir_filter },
1733         { pattern_fdir_ipv4_tcp_vf, i40e_flow_parse_fdir_filter },
1734         { pattern_fdir_ipv4_sctp_vf, i40e_flow_parse_fdir_filter },
1735         { pattern_fdir_ipv6_vf, i40e_flow_parse_fdir_filter },
1736         { pattern_fdir_ipv6_udp_vf, i40e_flow_parse_fdir_filter },
1737         { pattern_fdir_ipv6_tcp_vf, i40e_flow_parse_fdir_filter },
1738         { pattern_fdir_ipv6_sctp_vf, i40e_flow_parse_fdir_filter },
1739         { pattern_fdir_ethertype_raw_1_vf, i40e_flow_parse_fdir_filter },
1740         { pattern_fdir_ethertype_raw_2_vf, i40e_flow_parse_fdir_filter },
1741         { pattern_fdir_ethertype_raw_3_vf, i40e_flow_parse_fdir_filter },
1742         { pattern_fdir_ipv4_raw_1_vf, i40e_flow_parse_fdir_filter },
1743         { pattern_fdir_ipv4_raw_2_vf, i40e_flow_parse_fdir_filter },
1744         { pattern_fdir_ipv4_raw_3_vf, i40e_flow_parse_fdir_filter },
1745         { pattern_fdir_ipv4_udp_raw_1_vf, i40e_flow_parse_fdir_filter },
1746         { pattern_fdir_ipv4_udp_raw_2_vf, i40e_flow_parse_fdir_filter },
1747         { pattern_fdir_ipv4_udp_raw_3_vf, i40e_flow_parse_fdir_filter },
1748         { pattern_fdir_ipv4_tcp_raw_1_vf, i40e_flow_parse_fdir_filter },
1749         { pattern_fdir_ipv4_tcp_raw_2_vf, i40e_flow_parse_fdir_filter },
1750         { pattern_fdir_ipv4_tcp_raw_3_vf, i40e_flow_parse_fdir_filter },
1751         { pattern_fdir_ipv4_sctp_raw_1_vf, i40e_flow_parse_fdir_filter },
1752         { pattern_fdir_ipv4_sctp_raw_2_vf, i40e_flow_parse_fdir_filter },
1753         { pattern_fdir_ipv4_sctp_raw_3_vf, i40e_flow_parse_fdir_filter },
1754         { pattern_fdir_ipv6_raw_1_vf, i40e_flow_parse_fdir_filter },
1755         { pattern_fdir_ipv6_raw_2_vf, i40e_flow_parse_fdir_filter },
1756         { pattern_fdir_ipv6_raw_3_vf, i40e_flow_parse_fdir_filter },
1757         { pattern_fdir_ipv6_udp_raw_1_vf, i40e_flow_parse_fdir_filter },
1758         { pattern_fdir_ipv6_udp_raw_2_vf, i40e_flow_parse_fdir_filter },
1759         { pattern_fdir_ipv6_udp_raw_3_vf, i40e_flow_parse_fdir_filter },
1760         { pattern_fdir_ipv6_tcp_raw_1_vf, i40e_flow_parse_fdir_filter },
1761         { pattern_fdir_ipv6_tcp_raw_2_vf, i40e_flow_parse_fdir_filter },
1762         { pattern_fdir_ipv6_tcp_raw_3_vf, i40e_flow_parse_fdir_filter },
1763         { pattern_fdir_ipv6_sctp_raw_1_vf, i40e_flow_parse_fdir_filter },
1764         { pattern_fdir_ipv6_sctp_raw_2_vf, i40e_flow_parse_fdir_filter },
1765         { pattern_fdir_ipv6_sctp_raw_3_vf, i40e_flow_parse_fdir_filter },
1766         { pattern_fdir_ethertype_vlan_vf, i40e_flow_parse_fdir_filter },
1767         { pattern_fdir_vlan_ipv4_vf, i40e_flow_parse_fdir_filter },
1768         { pattern_fdir_vlan_ipv4_udp_vf, i40e_flow_parse_fdir_filter },
1769         { pattern_fdir_vlan_ipv4_tcp_vf, i40e_flow_parse_fdir_filter },
1770         { pattern_fdir_vlan_ipv4_sctp_vf, i40e_flow_parse_fdir_filter },
1771         { pattern_fdir_vlan_ipv6_vf, i40e_flow_parse_fdir_filter },
1772         { pattern_fdir_vlan_ipv6_udp_vf, i40e_flow_parse_fdir_filter },
1773         { pattern_fdir_vlan_ipv6_tcp_vf, i40e_flow_parse_fdir_filter },
1774         { pattern_fdir_vlan_ipv6_sctp_vf, i40e_flow_parse_fdir_filter },
1775         { pattern_fdir_ethertype_vlan_raw_1_vf, i40e_flow_parse_fdir_filter },
1776         { pattern_fdir_ethertype_vlan_raw_2_vf, i40e_flow_parse_fdir_filter },
1777         { pattern_fdir_ethertype_vlan_raw_3_vf, i40e_flow_parse_fdir_filter },
1778         { pattern_fdir_vlan_ipv4_raw_1_vf, i40e_flow_parse_fdir_filter },
1779         { pattern_fdir_vlan_ipv4_raw_2_vf, i40e_flow_parse_fdir_filter },
1780         { pattern_fdir_vlan_ipv4_raw_3_vf, i40e_flow_parse_fdir_filter },
1781         { pattern_fdir_vlan_ipv4_udp_raw_1_vf, i40e_flow_parse_fdir_filter },
1782         { pattern_fdir_vlan_ipv4_udp_raw_2_vf, i40e_flow_parse_fdir_filter },
1783         { pattern_fdir_vlan_ipv4_udp_raw_3_vf, i40e_flow_parse_fdir_filter },
1784         { pattern_fdir_vlan_ipv4_tcp_raw_1_vf, i40e_flow_parse_fdir_filter },
1785         { pattern_fdir_vlan_ipv4_tcp_raw_2_vf, i40e_flow_parse_fdir_filter },
1786         { pattern_fdir_vlan_ipv4_tcp_raw_3_vf, i40e_flow_parse_fdir_filter },
1787         { pattern_fdir_vlan_ipv4_sctp_raw_1_vf, i40e_flow_parse_fdir_filter },
1788         { pattern_fdir_vlan_ipv4_sctp_raw_2_vf, i40e_flow_parse_fdir_filter },
1789         { pattern_fdir_vlan_ipv4_sctp_raw_3_vf, i40e_flow_parse_fdir_filter },
1790         { pattern_fdir_vlan_ipv6_raw_1_vf, i40e_flow_parse_fdir_filter },
1791         { pattern_fdir_vlan_ipv6_raw_2_vf, i40e_flow_parse_fdir_filter },
1792         { pattern_fdir_vlan_ipv6_raw_3_vf, i40e_flow_parse_fdir_filter },
1793         { pattern_fdir_vlan_ipv6_udp_raw_1_vf, i40e_flow_parse_fdir_filter },
1794         { pattern_fdir_vlan_ipv6_udp_raw_2_vf, i40e_flow_parse_fdir_filter },
1795         { pattern_fdir_vlan_ipv6_udp_raw_3_vf, i40e_flow_parse_fdir_filter },
1796         { pattern_fdir_vlan_ipv6_tcp_raw_1_vf, i40e_flow_parse_fdir_filter },
1797         { pattern_fdir_vlan_ipv6_tcp_raw_2_vf, i40e_flow_parse_fdir_filter },
1798         { pattern_fdir_vlan_ipv6_tcp_raw_3_vf, i40e_flow_parse_fdir_filter },
1799         { pattern_fdir_vlan_ipv6_sctp_raw_1_vf, i40e_flow_parse_fdir_filter },
1800         { pattern_fdir_vlan_ipv6_sctp_raw_2_vf, i40e_flow_parse_fdir_filter },
1801         { pattern_fdir_vlan_ipv6_sctp_raw_3_vf, i40e_flow_parse_fdir_filter },
1802         /* VXLAN */
1803         { pattern_vxlan_1, i40e_flow_parse_vxlan_filter },
1804         { pattern_vxlan_2, i40e_flow_parse_vxlan_filter },
1805         { pattern_vxlan_3, i40e_flow_parse_vxlan_filter },
1806         { pattern_vxlan_4, i40e_flow_parse_vxlan_filter },
1807         /* NVGRE */
1808         { pattern_nvgre_1, i40e_flow_parse_nvgre_filter },
1809         { pattern_nvgre_2, i40e_flow_parse_nvgre_filter },
1810         { pattern_nvgre_3, i40e_flow_parse_nvgre_filter },
1811         { pattern_nvgre_4, i40e_flow_parse_nvgre_filter },
1812         /* MPLSoUDP & MPLSoGRE */
1813         { pattern_mpls_1, i40e_flow_parse_mpls_filter },
1814         { pattern_mpls_2, i40e_flow_parse_mpls_filter },
1815         { pattern_mpls_3, i40e_flow_parse_mpls_filter },
1816         { pattern_mpls_4, i40e_flow_parse_mpls_filter },
1817         /* GTP-C & GTP-U */
1818         { pattern_fdir_ipv4_gtpc, i40e_flow_parse_gtp_filter },
1819         { pattern_fdir_ipv4_gtpu, i40e_flow_parse_gtp_filter },
1820         { pattern_fdir_ipv6_gtpc, i40e_flow_parse_gtp_filter },
1821         { pattern_fdir_ipv6_gtpu, i40e_flow_parse_gtp_filter },
1822         /* QINQ */
1823         { pattern_qinq_1, i40e_flow_parse_qinq_filter },
1824 };
1825
1826 #define NEXT_ITEM_OF_ACTION(act, actions, index)                        \
1827         do {                                                            \
1828                 act = actions + index;                                  \
1829                 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) {        \
1830                         index++;                                        \
1831                         act = actions + index;                          \
1832                 }                                                       \
1833         } while (0)
1834
1835 /* Find the first VOID or non-VOID item pointer */
1836 static const struct rte_flow_item *
1837 i40e_find_first_item(const struct rte_flow_item *item, bool is_void)
1838 {
1839         bool is_find;
1840
1841         while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1842                 if (is_void)
1843                         is_find = item->type == RTE_FLOW_ITEM_TYPE_VOID;
1844                 else
1845                         is_find = item->type != RTE_FLOW_ITEM_TYPE_VOID;
1846                 if (is_find)
1847                         break;
1848                 item++;
1849         }
1850         return item;
1851 }
1852
1853 /* Skip all VOID items of the pattern */
1854 static void
1855 i40e_pattern_skip_void_item(struct rte_flow_item *items,
1856                             const struct rte_flow_item *pattern)
1857 {
1858         uint32_t cpy_count = 0;
1859         const struct rte_flow_item *pb = pattern, *pe = pattern;
1860
1861         for (;;) {
1862                 /* Find a non-void item first */
1863                 pb = i40e_find_first_item(pb, false);
1864                 if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
1865                         pe = pb;
1866                         break;
1867                 }
1868
1869                 /* Find a void item */
1870                 pe = i40e_find_first_item(pb + 1, true);
1871
1872                 cpy_count = pe - pb;
1873                 rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
1874
1875                 items += cpy_count;
1876
1877                 if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
1878                         pb = pe;
1879                         break;
1880                 }
1881
1882                 pb = pe + 1;
1883         }
1884         /* Copy the END item. */
1885         rte_memcpy(items, pe, sizeof(struct rte_flow_item));
1886 }
1887
1888 /* Check if the pattern matches a supported item type array */
1889 static bool
1890 i40e_match_pattern(enum rte_flow_item_type *item_array,
1891                    struct rte_flow_item *pattern)
1892 {
1893         struct rte_flow_item *item = pattern;
1894
1895         while ((*item_array == item->type) &&
1896                (*item_array != RTE_FLOW_ITEM_TYPE_END)) {
1897                 item_array++;
1898                 item++;
1899         }
1900
1901         return (*item_array == RTE_FLOW_ITEM_TYPE_END &&
1902                 item->type == RTE_FLOW_ITEM_TYPE_END);
1903 }
1904
1905 /* Find if there's parse filter function matched */
1906 static parse_filter_t
1907 i40e_find_parse_filter_func(struct rte_flow_item *pattern, uint32_t *idx)
1908 {
1909         parse_filter_t parse_filter = NULL;
1910         uint8_t i = *idx;
1911
1912         for (; i < RTE_DIM(i40e_supported_patterns); i++) {
1913                 if (i40e_match_pattern(i40e_supported_patterns[i].items,
1914                                         pattern)) {
1915                         parse_filter = i40e_supported_patterns[i].parse_filter;
1916                         break;
1917                 }
1918         }
1919
1920         *idx = ++i;
1921
1922         return parse_filter;
1923 }
1924
1925 /* Parse attributes */
1926 static int
1927 i40e_flow_parse_attr(const struct rte_flow_attr *attr,
1928                      struct rte_flow_error *error)
1929 {
1930         /* Must be input direction */
1931         if (!attr->ingress) {
1932                 rte_flow_error_set(error, EINVAL,
1933                                    RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1934                                    attr, "Only support ingress.");
1935                 return -rte_errno;
1936         }
1937
1938         /* Not supported */
1939         if (attr->egress) {
1940                 rte_flow_error_set(error, EINVAL,
1941                                    RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1942                                    attr, "Not support egress.");
1943                 return -rte_errno;
1944         }
1945
1946         /* Not supported */
1947         if (attr->priority) {
1948                 rte_flow_error_set(error, EINVAL,
1949                                    RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1950                                    attr, "Not support priority.");
1951                 return -rte_errno;
1952         }
1953
1954         /* Not supported */
1955         if (attr->group) {
1956                 rte_flow_error_set(error, EINVAL,
1957                                    RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1958                                    attr, "Not support group.");
1959                 return -rte_errno;
1960         }
1961
1962         return 0;
1963 }
1964
1965 static uint16_t
1966 i40e_get_outer_vlan(struct rte_eth_dev *dev)
1967 {
1968         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1969         int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
1970         uint64_t reg_r = 0;
1971         uint16_t reg_id;
1972         uint16_t tpid;
1973
1974         if (qinq)
1975                 reg_id = 2;
1976         else
1977                 reg_id = 3;
1978
1979         i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
1980                                     &reg_r, NULL);
1981
1982         tpid = (reg_r >> I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT) & 0xFFFF;
1983
1984         return tpid;
1985 }
1986
1987 /* 1. Last in item should be NULL as range is not supported.
1988  * 2. Supported filter types: MAC_ETHTYPE and ETHTYPE.
1989  * 3. SRC mac_addr mask should be 00:00:00:00:00:00.
1990  * 4. DST mac_addr mask should be 00:00:00:00:00:00 or
1991  *    FF:FF:FF:FF:FF:FF
1992  * 5. Ether_type mask should be 0xFFFF.
1993  */
1994 static int
1995 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
1996                                   const struct rte_flow_item *pattern,
1997                                   struct rte_flow_error *error,
1998                                   struct rte_eth_ethertype_filter *filter)
1999 {
2000         const struct rte_flow_item *item = pattern;
2001         const struct rte_flow_item_eth *eth_spec;
2002         const struct rte_flow_item_eth *eth_mask;
2003         enum rte_flow_item_type item_type;
2004         uint16_t outer_tpid;
2005
2006         outer_tpid = i40e_get_outer_vlan(dev);
2007
2008         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2009                 if (item->last) {
2010                         rte_flow_error_set(error, EINVAL,
2011                                            RTE_FLOW_ERROR_TYPE_ITEM,
2012                                            item,
2013                                            "Not support range");
2014                         return -rte_errno;
2015                 }
2016                 item_type = item->type;
2017                 switch (item_type) {
2018                 case RTE_FLOW_ITEM_TYPE_ETH:
2019                         eth_spec = (const struct rte_flow_item_eth *)item->spec;
2020                         eth_mask = (const struct rte_flow_item_eth *)item->mask;
2021                         /* Get the MAC info. */
2022                         if (!eth_spec || !eth_mask) {
2023                                 rte_flow_error_set(error, EINVAL,
2024                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2025                                                    item,
2026                                                    "NULL ETH spec/mask");
2027                                 return -rte_errno;
2028                         }
2029
2030                         /* Mask bits of source MAC address must be full of 0.
2031                          * Mask bits of destination MAC address must be full
2032                          * of 1 or full of 0.
2033                          */
2034                         if (!is_zero_ether_addr(&eth_mask->src) ||
2035                             (!is_zero_ether_addr(&eth_mask->dst) &&
2036                              !is_broadcast_ether_addr(&eth_mask->dst))) {
2037                                 rte_flow_error_set(error, EINVAL,
2038                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2039                                                    item,
2040                                                    "Invalid MAC_addr mask");
2041                                 return -rte_errno;
2042                         }
2043
2044                         if ((eth_mask->type & UINT16_MAX) != UINT16_MAX) {
2045                                 rte_flow_error_set(error, EINVAL,
2046                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2047                                                    item,
2048                                                    "Invalid ethertype mask");
2049                                 return -rte_errno;
2050                         }
2051
2052                         /* If mask bits of destination MAC address
2053                          * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
2054                          */
2055                         if (is_broadcast_ether_addr(&eth_mask->dst)) {
2056                                 filter->mac_addr = eth_spec->dst;
2057                                 filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
2058                         } else {
2059                                 filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
2060                         }
2061                         filter->ether_type = rte_be_to_cpu_16(eth_spec->type);
2062
2063                         if (filter->ether_type == ETHER_TYPE_IPv4 ||
2064                             filter->ether_type == ETHER_TYPE_IPv6 ||
2065                             filter->ether_type == ETHER_TYPE_LLDP ||
2066                             filter->ether_type == outer_tpid) {
2067                                 rte_flow_error_set(error, EINVAL,
2068                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2069                                                    item,
2070                                                    "Unsupported ether_type in"
2071                                                    " control packet filter.");
2072                                 return -rte_errno;
2073                         }
2074                         break;
2075                 default:
2076                         break;
2077                 }
2078         }
2079
2080         return 0;
2081 }
2082
2083 /* Ethertype action only supports QUEUE or DROP. */
2084 static int
2085 i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
2086                                  const struct rte_flow_action *actions,
2087                                  struct rte_flow_error *error,
2088                                  struct rte_eth_ethertype_filter *filter)
2089 {
2090         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2091         const struct rte_flow_action *act;
2092         const struct rte_flow_action_queue *act_q;
2093         uint32_t index = 0;
2094
2095         /* Check if the first non-void action is QUEUE or DROP. */
2096         NEXT_ITEM_OF_ACTION(act, actions, index);
2097         if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
2098             act->type != RTE_FLOW_ACTION_TYPE_DROP) {
2099                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2100                                    act, "Not supported action.");
2101                 return -rte_errno;
2102         }
2103
2104         if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
2105                 act_q = (const struct rte_flow_action_queue *)act->conf;
2106                 filter->queue = act_q->index;
2107                 if (filter->queue >= pf->dev_data->nb_rx_queues) {
2108                         rte_flow_error_set(error, EINVAL,
2109                                            RTE_FLOW_ERROR_TYPE_ACTION,
2110                                            act, "Invalid queue ID for"
2111                                            " ethertype_filter.");
2112                         return -rte_errno;
2113                 }
2114         } else {
2115                 filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
2116         }
2117
2118         /* Check if the next non-void item is END */
2119         index++;
2120         NEXT_ITEM_OF_ACTION(act, actions, index);
2121         if (act->type != RTE_FLOW_ACTION_TYPE_END) {
2122                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2123                                    act, "Not supported action.");
2124                 return -rte_errno;
2125         }
2126
2127         return 0;
2128 }
2129
2130 static int
2131 i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
2132                                  const struct rte_flow_attr *attr,
2133                                  const struct rte_flow_item pattern[],
2134                                  const struct rte_flow_action actions[],
2135                                  struct rte_flow_error *error,
2136                                  union i40e_filter_t *filter)
2137 {
2138         struct rte_eth_ethertype_filter *ethertype_filter =
2139                 &filter->ethertype_filter;
2140         int ret;
2141
2142         ret = i40e_flow_parse_ethertype_pattern(dev, pattern, error,
2143                                                 ethertype_filter);
2144         if (ret)
2145                 return ret;
2146
2147         ret = i40e_flow_parse_ethertype_action(dev, actions, error,
2148                                                ethertype_filter);
2149         if (ret)
2150                 return ret;
2151
2152         ret = i40e_flow_parse_attr(attr, error);
2153         if (ret)
2154                 return ret;
2155
2156         cons_filter_type = RTE_ETH_FILTER_ETHERTYPE;
2157
2158         return ret;
2159 }
2160
2161 static int
2162 i40e_flow_check_raw_item(const struct rte_flow_item *item,
2163                          const struct rte_flow_item_raw *raw_spec,
2164                          struct rte_flow_error *error)
2165 {
2166         if (!raw_spec->relative) {
2167                 rte_flow_error_set(error, EINVAL,
2168                                    RTE_FLOW_ERROR_TYPE_ITEM,
2169                                    item,
2170                                    "Relative should be 1.");
2171                 return -rte_errno;
2172         }
2173
2174         if (raw_spec->offset % sizeof(uint16_t)) {
2175                 rte_flow_error_set(error, EINVAL,
2176                                    RTE_FLOW_ERROR_TYPE_ITEM,
2177                                    item,
2178                                    "Offset should be even.");
2179                 return -rte_errno;
2180         }
2181
2182         if (raw_spec->search || raw_spec->limit) {
2183                 rte_flow_error_set(error, EINVAL,
2184                                    RTE_FLOW_ERROR_TYPE_ITEM,
2185                                    item,
2186                                    "search or limit is not supported.");
2187                 return -rte_errno;
2188         }
2189
2190         if (raw_spec->offset < 0) {
2191                 rte_flow_error_set(error, EINVAL,
2192                                    RTE_FLOW_ERROR_TYPE_ITEM,
2193                                    item,
2194                                    "Offset should be non-negative.");
2195                 return -rte_errno;
2196         }
2197         return 0;
2198 }
2199
2200 static int
2201 i40e_flow_store_flex_pit(struct i40e_pf *pf,
2202                          struct i40e_fdir_flex_pit *flex_pit,
2203                          enum i40e_flxpld_layer_idx layer_idx,
2204                          uint8_t raw_id)
2205 {
2206         uint8_t field_idx;
2207
2208         field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + raw_id;
2209         /* Check if the configuration is conflicted */
2210         if (pf->fdir.flex_pit_flag[layer_idx] &&
2211             (pf->fdir.flex_set[field_idx].src_offset != flex_pit->src_offset ||
2212              pf->fdir.flex_set[field_idx].size != flex_pit->size ||
2213              pf->fdir.flex_set[field_idx].dst_offset != flex_pit->dst_offset))
2214                 return -1;
2215
2216         /* Check if the configuration exists. */
2217         if (pf->fdir.flex_pit_flag[layer_idx] &&
2218             (pf->fdir.flex_set[field_idx].src_offset == flex_pit->src_offset &&
2219              pf->fdir.flex_set[field_idx].size == flex_pit->size &&
2220              pf->fdir.flex_set[field_idx].dst_offset == flex_pit->dst_offset))
2221                 return 1;
2222
2223         pf->fdir.flex_set[field_idx].src_offset =
2224                 flex_pit->src_offset;
2225         pf->fdir.flex_set[field_idx].size =
2226                 flex_pit->size;
2227         pf->fdir.flex_set[field_idx].dst_offset =
2228                 flex_pit->dst_offset;
2229
2230         return 0;
2231 }
2232
2233 static int
2234 i40e_flow_store_flex_mask(struct i40e_pf *pf,
2235                           enum i40e_filter_pctype pctype,
2236                           uint8_t *mask)
2237 {
2238         struct i40e_fdir_flex_mask flex_mask;
2239         uint16_t mask_tmp;
2240         uint8_t i, nb_bitmask = 0;
2241
2242         memset(&flex_mask, 0, sizeof(struct i40e_fdir_flex_mask));
2243         for (i = 0; i < I40E_FDIR_MAX_FLEX_LEN; i += sizeof(uint16_t)) {
2244                 mask_tmp = I40E_WORD(mask[i], mask[i + 1]);
2245                 if (mask_tmp) {
2246                         flex_mask.word_mask |=
2247                                 I40E_FLEX_WORD_MASK(i / sizeof(uint16_t));
2248                         if (mask_tmp != UINT16_MAX) {
2249                                 flex_mask.bitmask[nb_bitmask].mask = ~mask_tmp;
2250                                 flex_mask.bitmask[nb_bitmask].offset =
2251                                         i / sizeof(uint16_t);
2252                                 nb_bitmask++;
2253                                 if (nb_bitmask > I40E_FDIR_BITMASK_NUM_WORD)
2254                                         return -1;
2255                         }
2256                 }
2257         }
2258         flex_mask.nb_bitmask = nb_bitmask;
2259
2260         if (pf->fdir.flex_mask_flag[pctype] &&
2261             (memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
2262                     sizeof(struct i40e_fdir_flex_mask))))
2263                 return -2;
2264         else if (pf->fdir.flex_mask_flag[pctype] &&
2265                  !(memcmp(&flex_mask, &pf->fdir.flex_mask[pctype],
2266                           sizeof(struct i40e_fdir_flex_mask))))
2267                 return 1;
2268
2269         memcpy(&pf->fdir.flex_mask[pctype], &flex_mask,
2270                sizeof(struct i40e_fdir_flex_mask));
2271         return 0;
2272 }
2273
2274 static void
2275 i40e_flow_set_fdir_flex_pit(struct i40e_pf *pf,
2276                             enum i40e_flxpld_layer_idx layer_idx,
2277                             uint8_t raw_id)
2278 {
2279         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2280         uint32_t flx_pit;
2281         uint8_t field_idx;
2282         uint16_t min_next_off = 0;  /* in words */
2283         uint8_t i;
2284
2285         /* Set flex pit */
2286         for (i = 0; i < raw_id; i++) {
2287                 field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
2288                 flx_pit = MK_FLX_PIT(pf->fdir.flex_set[field_idx].src_offset,
2289                                      pf->fdir.flex_set[field_idx].size,
2290                                      pf->fdir.flex_set[field_idx].dst_offset);
2291
2292                 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
2293                 min_next_off = pf->fdir.flex_set[field_idx].src_offset +
2294                         pf->fdir.flex_set[field_idx].size;
2295         }
2296
2297         for (; i < I40E_MAX_FLXPLD_FIED; i++) {
2298                 /* set the non-used register obeying register's constrain */
2299                 field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
2300                 flx_pit = MK_FLX_PIT(min_next_off, NONUSE_FLX_PIT_FSIZE,
2301                                      NONUSE_FLX_PIT_DEST_OFF);
2302                 I40E_WRITE_REG(hw, I40E_PRTQF_FLX_PIT(field_idx), flx_pit);
2303                 min_next_off++;
2304         }
2305
2306         pf->fdir.flex_pit_flag[layer_idx] = 1;
2307 }
2308
2309 static void
2310 i40e_flow_set_fdir_flex_msk(struct i40e_pf *pf,
2311                             enum i40e_filter_pctype pctype)
2312 {
2313         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2314         struct i40e_fdir_flex_mask *flex_mask;
2315         uint32_t flxinset, fd_mask;
2316         uint8_t i;
2317
2318         /* Set flex mask */
2319         flex_mask = &pf->fdir.flex_mask[pctype];
2320         flxinset = (flex_mask->word_mask <<
2321                     I40E_PRTQF_FD_FLXINSET_INSET_SHIFT) &
2322                 I40E_PRTQF_FD_FLXINSET_INSET_MASK;
2323         i40e_write_rx_ctl(hw, I40E_PRTQF_FD_FLXINSET(pctype), flxinset);
2324
2325         for (i = 0; i < flex_mask->nb_bitmask; i++) {
2326                 fd_mask = (flex_mask->bitmask[i].mask <<
2327                            I40E_PRTQF_FD_MSK_MASK_SHIFT) &
2328                         I40E_PRTQF_FD_MSK_MASK_MASK;
2329                 fd_mask |= ((flex_mask->bitmask[i].offset +
2330                              I40E_FLX_OFFSET_IN_FIELD_VECTOR) <<
2331                             I40E_PRTQF_FD_MSK_OFFSET_SHIFT) &
2332                         I40E_PRTQF_FD_MSK_OFFSET_MASK;
2333                 i40e_write_rx_ctl(hw, I40E_PRTQF_FD_MSK(pctype, i), fd_mask);
2334         }
2335
2336         pf->fdir.flex_mask_flag[pctype] = 1;
2337 }
2338
2339 static int
2340 i40e_flow_set_fdir_inset(struct i40e_pf *pf,
2341                          enum i40e_filter_pctype pctype,
2342                          uint64_t input_set)
2343 {
2344         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2345         uint64_t inset_reg = 0;
2346         uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
2347         int i, num;
2348
2349         /* Check if the input set is valid */
2350         if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
2351                                     input_set) != 0) {
2352                 PMD_DRV_LOG(ERR, "Invalid input set");
2353                 return -EINVAL;
2354         }
2355
2356         /* Check if the configuration is conflicted */
2357         if (pf->fdir.inset_flag[pctype] &&
2358             memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t)))
2359                 return -1;
2360
2361         if (pf->fdir.inset_flag[pctype] &&
2362             !memcmp(&pf->fdir.input_set[pctype], &input_set, sizeof(uint64_t)))
2363                 return 0;
2364
2365         num = i40e_generate_inset_mask_reg(input_set, mask_reg,
2366                                            I40E_INSET_MASK_NUM_REG);
2367         if (num < 0)
2368                 return -EINVAL;
2369
2370         inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
2371
2372         i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
2373                              (uint32_t)(inset_reg & UINT32_MAX));
2374         i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
2375                              (uint32_t)((inset_reg >>
2376                                          I40E_32_BIT_WIDTH) & UINT32_MAX));
2377
2378         for (i = 0; i < num; i++)
2379                 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
2380                                      mask_reg[i]);
2381
2382         /*clear unused mask registers of the pctype */
2383         for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
2384                 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype), 0);
2385         I40E_WRITE_FLUSH(hw);
2386
2387         pf->fdir.input_set[pctype] = input_set;
2388         pf->fdir.inset_flag[pctype] = 1;
2389         return 0;
2390 }
2391
2392 static uint8_t
2393 i40e_flow_fdir_get_pctype_value(struct i40e_pf *pf,
2394                                 enum rte_flow_item_type item_type,
2395                                 struct i40e_fdir_filter_conf *filter)
2396 {
2397         struct i40e_customized_pctype *cus_pctype = NULL;
2398
2399         switch (item_type) {
2400         case RTE_FLOW_ITEM_TYPE_GTPC:
2401                 cus_pctype = i40e_find_customized_pctype(pf,
2402                                                          I40E_CUSTOMIZED_GTPC);
2403                 break;
2404         case RTE_FLOW_ITEM_TYPE_GTPU:
2405                 if (!filter->input.flow_ext.inner_ip)
2406                         cus_pctype = i40e_find_customized_pctype(pf,
2407                                                          I40E_CUSTOMIZED_GTPU);
2408                 else if (filter->input.flow_ext.iip_type ==
2409                          I40E_FDIR_IPTYPE_IPV4)
2410                         cus_pctype = i40e_find_customized_pctype(pf,
2411                                                  I40E_CUSTOMIZED_GTPU_IPV4);
2412                 else if (filter->input.flow_ext.iip_type ==
2413                          I40E_FDIR_IPTYPE_IPV6)
2414                         cus_pctype = i40e_find_customized_pctype(pf,
2415                                                  I40E_CUSTOMIZED_GTPU_IPV6);
2416                 break;
2417         default:
2418                 PMD_DRV_LOG(ERR, "Unsupported item type");
2419                 break;
2420         }
2421
2422         if (cus_pctype)
2423                 return cus_pctype->pctype;
2424
2425         return I40E_FILTER_PCTYPE_INVALID;
2426 }
2427
2428 /* 1. Last in item should be NULL as range is not supported.
2429  * 2. Supported patterns: refer to array i40e_supported_patterns.
2430  * 3. Default supported flow type and input set: refer to array
2431  *    valid_fdir_inset_table in i40e_ethdev.c.
2432  * 4. Mask of fields which need to be matched should be
2433  *    filled with 1.
2434  * 5. Mask of fields which needn't to be matched should be
2435  *    filled with 0.
2436  * 6. GTP profile supports GTPv1 only.
2437  * 7. GTP-C response message ('source_port' = 2123) is not supported.
2438  */
2439 static int
2440 i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
2441                              const struct rte_flow_item *pattern,
2442                              struct rte_flow_error *error,
2443                              struct i40e_fdir_filter_conf *filter)
2444 {
2445         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2446         const struct rte_flow_item *item = pattern;
2447         const struct rte_flow_item_eth *eth_spec, *eth_mask;
2448         const struct rte_flow_item_vlan *vlan_spec, *vlan_mask;
2449         const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
2450         const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
2451         const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
2452         const struct rte_flow_item_udp *udp_spec, *udp_mask;
2453         const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
2454         const struct rte_flow_item_gtp *gtp_spec, *gtp_mask;
2455         const struct rte_flow_item_raw *raw_spec, *raw_mask;
2456         const struct rte_flow_item_vf *vf_spec;
2457
2458         uint8_t pctype = 0;
2459         uint64_t input_set = I40E_INSET_NONE;
2460         uint16_t frag_off;
2461         enum rte_flow_item_type item_type;
2462         enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
2463         enum rte_flow_item_type cus_proto = RTE_FLOW_ITEM_TYPE_END;
2464         uint32_t i, j;
2465         uint8_t  ipv6_addr_mask[16] = {
2466                 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
2467                 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
2468         enum i40e_flxpld_layer_idx layer_idx = I40E_FLXPLD_L2_IDX;
2469         uint8_t raw_id = 0;
2470         int32_t off_arr[I40E_MAX_FLXPLD_FIED];
2471         uint16_t len_arr[I40E_MAX_FLXPLD_FIED];
2472         struct i40e_fdir_flex_pit flex_pit;
2473         uint8_t next_dst_off = 0;
2474         uint8_t flex_mask[I40E_FDIR_MAX_FLEX_LEN];
2475         uint16_t flex_size;
2476         bool cfg_flex_pit = true;
2477         bool cfg_flex_msk = true;
2478         uint16_t outer_tpid;
2479         uint16_t ether_type;
2480         uint32_t vtc_flow_cpu;
2481         bool outer_ip = true;
2482         int ret;
2483
2484         memset(off_arr, 0, sizeof(off_arr));
2485         memset(len_arr, 0, sizeof(len_arr));
2486         memset(flex_mask, 0, I40E_FDIR_MAX_FLEX_LEN);
2487         outer_tpid = i40e_get_outer_vlan(dev);
2488         filter->input.flow_ext.customized_pctype = false;
2489         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
2490                 if (item->last) {
2491                         rte_flow_error_set(error, EINVAL,
2492                                            RTE_FLOW_ERROR_TYPE_ITEM,
2493                                            item,
2494                                            "Not support range");
2495                         return -rte_errno;
2496                 }
2497                 item_type = item->type;
2498                 switch (item_type) {
2499                 case RTE_FLOW_ITEM_TYPE_ETH:
2500                         eth_spec = (const struct rte_flow_item_eth *)item->spec;
2501                         eth_mask = (const struct rte_flow_item_eth *)item->mask;
2502
2503                         if (eth_spec && eth_mask) {
2504                                 if (!is_zero_ether_addr(&eth_mask->src) ||
2505                                     !is_zero_ether_addr(&eth_mask->dst)) {
2506                                         rte_flow_error_set(error, EINVAL,
2507                                                       RTE_FLOW_ERROR_TYPE_ITEM,
2508                                                       item,
2509                                                       "Invalid MAC_addr mask.");
2510                                         return -rte_errno;
2511                                 }
2512
2513                                 if ((eth_mask->type & UINT16_MAX) ==
2514                                     UINT16_MAX) {
2515                                         input_set |= I40E_INSET_LAST_ETHER_TYPE;
2516                                         filter->input.flow.l2_flow.ether_type =
2517                                                 eth_spec->type;
2518                                 }
2519
2520                                 ether_type = rte_be_to_cpu_16(eth_spec->type);
2521                                 if (ether_type == ETHER_TYPE_IPv4 ||
2522                                     ether_type == ETHER_TYPE_IPv6 ||
2523                                     ether_type == ETHER_TYPE_ARP ||
2524                                     ether_type == outer_tpid) {
2525                                         rte_flow_error_set(error, EINVAL,
2526                                                      RTE_FLOW_ERROR_TYPE_ITEM,
2527                                                      item,
2528                                                      "Unsupported ether_type.");
2529                                         return -rte_errno;
2530                                 }
2531                         }
2532
2533                         pctype = I40E_FILTER_PCTYPE_L2_PAYLOAD;
2534                         layer_idx = I40E_FLXPLD_L2_IDX;
2535
2536                         break;
2537                 case RTE_FLOW_ITEM_TYPE_VLAN:
2538                         vlan_spec =
2539                                 (const struct rte_flow_item_vlan *)item->spec;
2540                         vlan_mask =
2541                                 (const struct rte_flow_item_vlan *)item->mask;
2542                         if (vlan_spec && vlan_mask) {
2543                                 if (vlan_mask->tci ==
2544                                     rte_cpu_to_be_16(I40E_TCI_MASK)) {
2545                                         input_set |= I40E_INSET_VLAN_INNER;
2546                                         filter->input.flow_ext.vlan_tci =
2547                                                 vlan_spec->tci;
2548                                 }
2549                         }
2550
2551                         pctype = I40E_FILTER_PCTYPE_L2_PAYLOAD;
2552                         layer_idx = I40E_FLXPLD_L2_IDX;
2553
2554                         break;
2555                 case RTE_FLOW_ITEM_TYPE_IPV4:
2556                         l3 = RTE_FLOW_ITEM_TYPE_IPV4;
2557                         ipv4_spec =
2558                                 (const struct rte_flow_item_ipv4 *)item->spec;
2559                         ipv4_mask =
2560                                 (const struct rte_flow_item_ipv4 *)item->mask;
2561
2562                         if (ipv4_spec && ipv4_mask && outer_ip) {
2563                                 /* Check IPv4 mask and update input set */
2564                                 if (ipv4_mask->hdr.version_ihl ||
2565                                     ipv4_mask->hdr.total_length ||
2566                                     ipv4_mask->hdr.packet_id ||
2567                                     ipv4_mask->hdr.fragment_offset ||
2568                                     ipv4_mask->hdr.hdr_checksum) {
2569                                         rte_flow_error_set(error, EINVAL,
2570                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2571                                                    item,
2572                                                    "Invalid IPv4 mask.");
2573                                         return -rte_errno;
2574                                 }
2575
2576                                 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
2577                                         input_set |= I40E_INSET_IPV4_SRC;
2578                                 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
2579                                         input_set |= I40E_INSET_IPV4_DST;
2580                                 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
2581                                         input_set |= I40E_INSET_IPV4_TOS;
2582                                 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
2583                                         input_set |= I40E_INSET_IPV4_TTL;
2584                                 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
2585                                         input_set |= I40E_INSET_IPV4_PROTO;
2586
2587                                 /* Get filter info */
2588                                 pctype = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2589                                 /* Check if it is fragment. */
2590                                 frag_off = ipv4_spec->hdr.fragment_offset;
2591                                 frag_off = rte_be_to_cpu_16(frag_off);
2592                                 if (frag_off & IPV4_HDR_OFFSET_MASK ||
2593                                     frag_off & IPV4_HDR_MF_FLAG)
2594                                         pctype = I40E_FILTER_PCTYPE_FRAG_IPV4;
2595
2596                                 /* Get the filter info */
2597                                 filter->input.flow.ip4_flow.proto =
2598                                         ipv4_spec->hdr.next_proto_id;
2599                                 filter->input.flow.ip4_flow.tos =
2600                                         ipv4_spec->hdr.type_of_service;
2601                                 filter->input.flow.ip4_flow.ttl =
2602                                         ipv4_spec->hdr.time_to_live;
2603                                 filter->input.flow.ip4_flow.src_ip =
2604                                         ipv4_spec->hdr.src_addr;
2605                                 filter->input.flow.ip4_flow.dst_ip =
2606                                         ipv4_spec->hdr.dst_addr;
2607
2608                                 layer_idx = I40E_FLXPLD_L3_IDX;
2609                         } else if (!ipv4_spec && !ipv4_mask && !outer_ip) {
2610                                 filter->input.flow_ext.inner_ip = true;
2611                                 filter->input.flow_ext.iip_type =
2612                                         I40E_FDIR_IPTYPE_IPV4;
2613                         } else if ((ipv4_spec || ipv4_mask) && !outer_ip) {
2614                                 rte_flow_error_set(error, EINVAL,
2615                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2616                                                    item,
2617                                                    "Invalid inner IPv4 mask.");
2618                                 return -rte_errno;
2619                         }
2620
2621                         if (outer_ip)
2622                                 outer_ip = false;
2623
2624                         break;
2625                 case RTE_FLOW_ITEM_TYPE_IPV6:
2626                         l3 = RTE_FLOW_ITEM_TYPE_IPV6;
2627                         ipv6_spec =
2628                                 (const struct rte_flow_item_ipv6 *)item->spec;
2629                         ipv6_mask =
2630                                 (const struct rte_flow_item_ipv6 *)item->mask;
2631
2632                         if (ipv6_spec && ipv6_mask && outer_ip) {
2633                                 /* Check IPv6 mask and update input set */
2634                                 if (ipv6_mask->hdr.payload_len) {
2635                                         rte_flow_error_set(error, EINVAL,
2636                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2637                                                    item,
2638                                                    "Invalid IPv6 mask");
2639                                         return -rte_errno;
2640                                 }
2641
2642                                 if (!memcmp(ipv6_mask->hdr.src_addr,
2643                                             ipv6_addr_mask,
2644                                             RTE_DIM(ipv6_mask->hdr.src_addr)))
2645                                         input_set |= I40E_INSET_IPV6_SRC;
2646                                 if (!memcmp(ipv6_mask->hdr.dst_addr,
2647                                             ipv6_addr_mask,
2648                                             RTE_DIM(ipv6_mask->hdr.dst_addr)))
2649                                         input_set |= I40E_INSET_IPV6_DST;
2650
2651                                 if ((ipv6_mask->hdr.vtc_flow &
2652                                      rte_cpu_to_be_32(I40E_IPV6_TC_MASK))
2653                                     == rte_cpu_to_be_32(I40E_IPV6_TC_MASK))
2654                                         input_set |= I40E_INSET_IPV6_TC;
2655                                 if (ipv6_mask->hdr.proto == UINT8_MAX)
2656                                         input_set |= I40E_INSET_IPV6_NEXT_HDR;
2657                                 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
2658                                         input_set |= I40E_INSET_IPV6_HOP_LIMIT;
2659
2660                                 /* Get filter info */
2661                                 vtc_flow_cpu =
2662                                       rte_be_to_cpu_32(ipv6_spec->hdr.vtc_flow);
2663                                 filter->input.flow.ipv6_flow.tc =
2664                                         (uint8_t)(vtc_flow_cpu >>
2665                                                   I40E_FDIR_IPv6_TC_OFFSET);
2666                                 filter->input.flow.ipv6_flow.proto =
2667                                         ipv6_spec->hdr.proto;
2668                                 filter->input.flow.ipv6_flow.hop_limits =
2669                                         ipv6_spec->hdr.hop_limits;
2670
2671                                 rte_memcpy(filter->input.flow.ipv6_flow.src_ip,
2672                                            ipv6_spec->hdr.src_addr, 16);
2673                                 rte_memcpy(filter->input.flow.ipv6_flow.dst_ip,
2674                                            ipv6_spec->hdr.dst_addr, 16);
2675
2676                                 /* Check if it is fragment. */
2677                                 if (ipv6_spec->hdr.proto ==
2678                                     I40E_IPV6_FRAG_HEADER)
2679                                         pctype = I40E_FILTER_PCTYPE_FRAG_IPV6;
2680                                 else
2681                                         pctype =
2682                                              I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
2683
2684                                 layer_idx = I40E_FLXPLD_L3_IDX;
2685                         } else if (!ipv6_spec && !ipv6_mask && !outer_ip) {
2686                                 filter->input.flow_ext.inner_ip = true;
2687                                 filter->input.flow_ext.iip_type =
2688                                         I40E_FDIR_IPTYPE_IPV6;
2689                         } else if ((ipv6_spec || ipv6_mask) && !outer_ip) {
2690                                 rte_flow_error_set(error, EINVAL,
2691                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2692                                                    item,
2693                                                    "Invalid inner IPv6 mask");
2694                                 return -rte_errno;
2695                         }
2696
2697                         if (outer_ip)
2698                                 outer_ip = false;
2699                         break;
2700                 case RTE_FLOW_ITEM_TYPE_TCP:
2701                         tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
2702                         tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
2703
2704                         if (tcp_spec && tcp_mask) {
2705                                 /* Check TCP mask and update input set */
2706                                 if (tcp_mask->hdr.sent_seq ||
2707                                     tcp_mask->hdr.recv_ack ||
2708                                     tcp_mask->hdr.data_off ||
2709                                     tcp_mask->hdr.tcp_flags ||
2710                                     tcp_mask->hdr.rx_win ||
2711                                     tcp_mask->hdr.cksum ||
2712                                     tcp_mask->hdr.tcp_urp) {
2713                                         rte_flow_error_set(error, EINVAL,
2714                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2715                                                    item,
2716                                                    "Invalid TCP mask");
2717                                         return -rte_errno;
2718                                 }
2719
2720                                 if (tcp_mask->hdr.src_port == UINT16_MAX)
2721                                         input_set |= I40E_INSET_SRC_PORT;
2722                                 if (tcp_mask->hdr.dst_port == UINT16_MAX)
2723                                         input_set |= I40E_INSET_DST_PORT;
2724
2725                                 /* Get filter info */
2726                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2727                                         pctype =
2728                                                I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2729                                 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2730                                         pctype =
2731                                                I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2732
2733                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2734                                         filter->input.flow.tcp4_flow.src_port =
2735                                                 tcp_spec->hdr.src_port;
2736                                         filter->input.flow.tcp4_flow.dst_port =
2737                                                 tcp_spec->hdr.dst_port;
2738                                 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2739                                         filter->input.flow.tcp6_flow.src_port =
2740                                                 tcp_spec->hdr.src_port;
2741                                         filter->input.flow.tcp6_flow.dst_port =
2742                                                 tcp_spec->hdr.dst_port;
2743                                 }
2744                         }
2745
2746                         layer_idx = I40E_FLXPLD_L4_IDX;
2747
2748                         break;
2749                 case RTE_FLOW_ITEM_TYPE_UDP:
2750                         udp_spec = (const struct rte_flow_item_udp *)item->spec;
2751                         udp_mask = (const struct rte_flow_item_udp *)item->mask;
2752
2753                         if (udp_spec && udp_mask) {
2754                                 /* Check UDP mask and update input set*/
2755                                 if (udp_mask->hdr.dgram_len ||
2756                                     udp_mask->hdr.dgram_cksum) {
2757                                         rte_flow_error_set(error, EINVAL,
2758                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2759                                                    item,
2760                                                    "Invalid UDP mask");
2761                                         return -rte_errno;
2762                                 }
2763
2764                                 if (udp_mask->hdr.src_port == UINT16_MAX)
2765                                         input_set |= I40E_INSET_SRC_PORT;
2766                                 if (udp_mask->hdr.dst_port == UINT16_MAX)
2767                                         input_set |= I40E_INSET_DST_PORT;
2768
2769                                 /* Get filter info */
2770                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2771                                         pctype =
2772                                                I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2773                                 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2774                                         pctype =
2775                                                I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2776
2777                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2778                                         filter->input.flow.udp4_flow.src_port =
2779                                                 udp_spec->hdr.src_port;
2780                                         filter->input.flow.udp4_flow.dst_port =
2781                                                 udp_spec->hdr.dst_port;
2782                                 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2783                                         filter->input.flow.udp6_flow.src_port =
2784                                                 udp_spec->hdr.src_port;
2785                                         filter->input.flow.udp6_flow.dst_port =
2786                                                 udp_spec->hdr.dst_port;
2787                                 }
2788                         }
2789
2790                         layer_idx = I40E_FLXPLD_L4_IDX;
2791
2792                         break;
2793                 case RTE_FLOW_ITEM_TYPE_GTPC:
2794                 case RTE_FLOW_ITEM_TYPE_GTPU:
2795                         if (!pf->gtp_support) {
2796                                 rte_flow_error_set(error, EINVAL,
2797                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2798                                                    item,
2799                                                    "Unsupported protocol");
2800                                 return -rte_errno;
2801                         }
2802
2803                         gtp_spec = (const struct rte_flow_item_gtp *)item->spec;
2804                         gtp_mask = (const struct rte_flow_item_gtp *)item->mask;
2805
2806                         if (gtp_spec && gtp_mask) {
2807                                 if (gtp_mask->v_pt_rsv_flags ||
2808                                     gtp_mask->msg_type ||
2809                                     gtp_mask->msg_len ||
2810                                     gtp_mask->teid != UINT32_MAX) {
2811                                         rte_flow_error_set(error, EINVAL,
2812                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2813                                                    item,
2814                                                    "Invalid GTP mask");
2815                                         return -rte_errno;
2816                                 }
2817
2818                                 filter->input.flow.gtp_flow.teid =
2819                                         gtp_spec->teid;
2820                                 filter->input.flow_ext.customized_pctype = true;
2821                                 cus_proto = item_type;
2822                         }
2823                         break;
2824                 case RTE_FLOW_ITEM_TYPE_SCTP:
2825                         sctp_spec =
2826                                 (const struct rte_flow_item_sctp *)item->spec;
2827                         sctp_mask =
2828                                 (const struct rte_flow_item_sctp *)item->mask;
2829
2830                         if (sctp_spec && sctp_mask) {
2831                                 /* Check SCTP mask and update input set */
2832                                 if (sctp_mask->hdr.cksum) {
2833                                         rte_flow_error_set(error, EINVAL,
2834                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2835                                                    item,
2836                                                    "Invalid UDP mask");
2837                                         return -rte_errno;
2838                                 }
2839
2840                                 if (sctp_mask->hdr.src_port == UINT16_MAX)
2841                                         input_set |= I40E_INSET_SRC_PORT;
2842                                 if (sctp_mask->hdr.dst_port == UINT16_MAX)
2843                                         input_set |= I40E_INSET_DST_PORT;
2844                                 if (sctp_mask->hdr.tag == UINT32_MAX)
2845                                         input_set |= I40E_INSET_SCTP_VT;
2846
2847                                 /* Get filter info */
2848                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2849                                         pctype =
2850                                               I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2851                                 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2852                                         pctype =
2853                                               I40E_FILTER_PCTYPE_NONF_IPV6_SCTP;
2854
2855                                 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2856                                         filter->input.flow.sctp4_flow.src_port =
2857                                                 sctp_spec->hdr.src_port;
2858                                         filter->input.flow.sctp4_flow.dst_port =
2859                                                 sctp_spec->hdr.dst_port;
2860                                         filter->input.flow.sctp4_flow.verify_tag
2861                                                 = sctp_spec->hdr.tag;
2862                                 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2863                                         filter->input.flow.sctp6_flow.src_port =
2864                                                 sctp_spec->hdr.src_port;
2865                                         filter->input.flow.sctp6_flow.dst_port =
2866                                                 sctp_spec->hdr.dst_port;
2867                                         filter->input.flow.sctp6_flow.verify_tag
2868                                                 = sctp_spec->hdr.tag;
2869                                 }
2870                         }
2871
2872                         layer_idx = I40E_FLXPLD_L4_IDX;
2873
2874                         break;
2875                 case RTE_FLOW_ITEM_TYPE_RAW:
2876                         raw_spec = (const struct rte_flow_item_raw *)item->spec;
2877                         raw_mask = (const struct rte_flow_item_raw *)item->mask;
2878
2879                         if (!raw_spec || !raw_mask) {
2880                                 rte_flow_error_set(error, EINVAL,
2881                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2882                                                    item,
2883                                                    "NULL RAW spec/mask");
2884                                 return -rte_errno;
2885                         }
2886
2887                         ret = i40e_flow_check_raw_item(item, raw_spec, error);
2888                         if (ret < 0)
2889                                 return ret;
2890
2891                         off_arr[raw_id] = raw_spec->offset;
2892                         len_arr[raw_id] = raw_spec->length;
2893
2894                         flex_size = 0;
2895                         memset(&flex_pit, 0, sizeof(struct i40e_fdir_flex_pit));
2896                         flex_pit.size =
2897                                 raw_spec->length / sizeof(uint16_t);
2898                         flex_pit.dst_offset =
2899                                 next_dst_off / sizeof(uint16_t);
2900
2901                         for (i = 0; i <= raw_id; i++) {
2902                                 if (i == raw_id)
2903                                         flex_pit.src_offset +=
2904                                                 raw_spec->offset /
2905                                                 sizeof(uint16_t);
2906                                 else
2907                                         flex_pit.src_offset +=
2908                                                 (off_arr[i] + len_arr[i]) /
2909                                                 sizeof(uint16_t);
2910                                 flex_size += len_arr[i];
2911                         }
2912                         if (((flex_pit.src_offset + flex_pit.size) >=
2913                              I40E_MAX_FLX_SOURCE_OFF / sizeof(uint16_t)) ||
2914                                 flex_size > I40E_FDIR_MAX_FLEXLEN) {
2915                                 rte_flow_error_set(error, EINVAL,
2916                                            RTE_FLOW_ERROR_TYPE_ITEM,
2917                                            item,
2918                                            "Exceeds maxmial payload limit.");
2919                                 return -rte_errno;
2920                         }
2921
2922                         /* Store flex pit to SW */
2923                         ret = i40e_flow_store_flex_pit(pf, &flex_pit,
2924                                                        layer_idx, raw_id);
2925                         if (ret < 0) {
2926                                 rte_flow_error_set(error, EINVAL,
2927                                    RTE_FLOW_ERROR_TYPE_ITEM,
2928                                    item,
2929                                    "Conflict with the first flexible rule.");
2930                                 return -rte_errno;
2931                         } else if (ret > 0)
2932                                 cfg_flex_pit = false;
2933
2934                         for (i = 0; i < raw_spec->length; i++) {
2935                                 j = i + next_dst_off;
2936                                 filter->input.flow_ext.flexbytes[j] =
2937                                         raw_spec->pattern[i];
2938                                 flex_mask[j] = raw_mask->pattern[i];
2939                         }
2940
2941                         next_dst_off += raw_spec->length;
2942                         raw_id++;
2943                         break;
2944                 case RTE_FLOW_ITEM_TYPE_VF:
2945                         vf_spec = (const struct rte_flow_item_vf *)item->spec;
2946                         filter->input.flow_ext.is_vf = 1;
2947                         filter->input.flow_ext.dst_id = vf_spec->id;
2948                         if (filter->input.flow_ext.is_vf &&
2949                             filter->input.flow_ext.dst_id >= pf->vf_num) {
2950                                 rte_flow_error_set(error, EINVAL,
2951                                                    RTE_FLOW_ERROR_TYPE_ITEM,
2952                                                    item,
2953                                                    "Invalid VF ID for FDIR.");
2954                                 return -rte_errno;
2955                         }
2956                         break;
2957                 default:
2958                         break;
2959                 }
2960         }
2961
2962         /* Get customized pctype value */
2963         if (filter->input.flow_ext.customized_pctype) {
2964                 pctype = i40e_flow_fdir_get_pctype_value(pf, cus_proto, filter);
2965                 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
2966                         rte_flow_error_set(error, EINVAL,
2967                                            RTE_FLOW_ERROR_TYPE_ITEM,
2968                                            item,
2969                                            "Unsupported pctype");
2970                         return -rte_errno;
2971                 }
2972         }
2973
2974         /* If customized pctype is not used, set fdir configuration.*/
2975         if (!filter->input.flow_ext.customized_pctype) {
2976                 ret = i40e_flow_set_fdir_inset(pf, pctype, input_set);
2977                 if (ret == -1) {
2978                         rte_flow_error_set(error, EINVAL,
2979                                            RTE_FLOW_ERROR_TYPE_ITEM, item,
2980                                            "Conflict with the first rule's input set.");
2981                         return -rte_errno;
2982                 } else if (ret == -EINVAL) {
2983                         rte_flow_error_set(error, EINVAL,
2984                                            RTE_FLOW_ERROR_TYPE_ITEM, item,
2985                                            "Invalid pattern mask.");
2986                         return -rte_errno;
2987                 }
2988
2989                 /* Store flex mask to SW */
2990                 ret = i40e_flow_store_flex_mask(pf, pctype, flex_mask);
2991                 if (ret == -1) {
2992                         rte_flow_error_set(error, EINVAL,
2993                                            RTE_FLOW_ERROR_TYPE_ITEM,
2994                                            item,
2995                                            "Exceed maximal number of bitmasks");
2996                         return -rte_errno;
2997                 } else if (ret == -2) {
2998                         rte_flow_error_set(error, EINVAL,
2999                                            RTE_FLOW_ERROR_TYPE_ITEM,
3000                                            item,
3001                                            "Conflict with the first flexible rule");
3002                         return -rte_errno;
3003                 } else if (ret > 0)
3004                         cfg_flex_msk = false;
3005
3006                 if (cfg_flex_pit)
3007                         i40e_flow_set_fdir_flex_pit(pf, layer_idx, raw_id);
3008
3009                 if (cfg_flex_msk)
3010                         i40e_flow_set_fdir_flex_msk(pf, pctype);
3011         }
3012
3013         filter->input.pctype = pctype;
3014
3015         return 0;
3016 }
3017
3018 /* Parse to get the action info of a FDIR filter.
3019  * FDIR action supports QUEUE or (QUEUE + MARK).
3020  */
3021 static int
3022 i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
3023                             const struct rte_flow_action *actions,
3024                             struct rte_flow_error *error,
3025                             struct i40e_fdir_filter_conf *filter)
3026 {
3027         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3028         const struct rte_flow_action *act;
3029         const struct rte_flow_action_queue *act_q;
3030         const struct rte_flow_action_mark *mark_spec;
3031         uint32_t index = 0;
3032
3033         /* Check if the first non-void action is QUEUE or DROP or PASSTHRU. */
3034         NEXT_ITEM_OF_ACTION(act, actions, index);
3035         switch (act->type) {
3036         case RTE_FLOW_ACTION_TYPE_QUEUE:
3037                 act_q = (const struct rte_flow_action_queue *)act->conf;
3038                 filter->action.rx_queue = act_q->index;
3039                 if ((!filter->input.flow_ext.is_vf &&
3040                      filter->action.rx_queue >= pf->dev_data->nb_rx_queues) ||
3041                     (filter->input.flow_ext.is_vf &&
3042                      filter->action.rx_queue >= pf->vf_nb_qps)) {
3043                         rte_flow_error_set(error, EINVAL,
3044                                            RTE_FLOW_ERROR_TYPE_ACTION, act,
3045                                            "Invalid queue ID for FDIR.");
3046                         return -rte_errno;
3047                 }
3048                 filter->action.behavior = I40E_FDIR_ACCEPT;
3049                 break;
3050         case RTE_FLOW_ACTION_TYPE_DROP:
3051                 filter->action.behavior = I40E_FDIR_REJECT;
3052                 break;
3053         case RTE_FLOW_ACTION_TYPE_PASSTHRU:
3054                 filter->action.behavior = I40E_FDIR_PASSTHRU;
3055                 break;
3056         default:
3057                 rte_flow_error_set(error, EINVAL,
3058                                    RTE_FLOW_ERROR_TYPE_ACTION, act,
3059                                    "Invalid action.");
3060                 return -rte_errno;
3061         }
3062
3063         /* Check if the next non-void item is MARK or FLAG or END. */
3064         index++;
3065         NEXT_ITEM_OF_ACTION(act, actions, index);
3066         switch (act->type) {
3067         case RTE_FLOW_ACTION_TYPE_MARK:
3068                 mark_spec = (const struct rte_flow_action_mark *)act->conf;
3069                 filter->action.report_status = I40E_FDIR_REPORT_ID;
3070                 filter->soft_id = mark_spec->id;
3071                 break;
3072         case RTE_FLOW_ACTION_TYPE_FLAG:
3073                 filter->action.report_status = I40E_FDIR_NO_REPORT_STATUS;
3074                 break;
3075         case RTE_FLOW_ACTION_TYPE_END:
3076                 return 0;
3077         default:
3078                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3079                                    act, "Invalid action.");
3080                 return -rte_errno;
3081         }
3082
3083         /* Check if the next non-void item is END */
3084         index++;
3085         NEXT_ITEM_OF_ACTION(act, actions, index);
3086         if (act->type != RTE_FLOW_ACTION_TYPE_END) {
3087                 rte_flow_error_set(error, EINVAL,
3088                                    RTE_FLOW_ERROR_TYPE_ACTION,
3089                                    act, "Invalid action.");
3090                 return -rte_errno;
3091         }
3092
3093         return 0;
3094 }
3095
3096 static int
3097 i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
3098                             const struct rte_flow_attr *attr,
3099                             const struct rte_flow_item pattern[],
3100                             const struct rte_flow_action actions[],
3101                             struct rte_flow_error *error,
3102                             union i40e_filter_t *filter)
3103 {
3104         struct i40e_fdir_filter_conf *fdir_filter =
3105                 &filter->fdir_filter;
3106         int ret;
3107
3108         ret = i40e_flow_parse_fdir_pattern(dev, pattern, error, fdir_filter);
3109         if (ret)
3110                 return ret;
3111
3112         ret = i40e_flow_parse_fdir_action(dev, actions, error, fdir_filter);
3113         if (ret)
3114                 return ret;
3115
3116         ret = i40e_flow_parse_attr(attr, error);
3117         if (ret)
3118                 return ret;
3119
3120         cons_filter_type = RTE_ETH_FILTER_FDIR;
3121
3122         if (dev->data->dev_conf.fdir_conf.mode !=
3123             RTE_FDIR_MODE_PERFECT) {
3124                 rte_flow_error_set(error, ENOTSUP,
3125                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3126                                    NULL,
3127                                    "Check the mode in fdir_conf.");
3128                 return -rte_errno;
3129         }
3130
3131         return 0;
3132 }
3133
3134 /* Parse to get the action info of a tunnel filter
3135  * Tunnel action only supports PF, VF and QUEUE.
3136  */
3137 static int
3138 i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
3139                               const struct rte_flow_action *actions,
3140                               struct rte_flow_error *error,
3141                               struct i40e_tunnel_filter_conf *filter)
3142 {
3143         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3144         const struct rte_flow_action *act;
3145         const struct rte_flow_action_queue *act_q;
3146         const struct rte_flow_action_vf *act_vf;
3147         uint32_t index = 0;
3148
3149         /* Check if the first non-void action is PF or VF. */
3150         NEXT_ITEM_OF_ACTION(act, actions, index);
3151         if (act->type != RTE_FLOW_ACTION_TYPE_PF &&
3152             act->type != RTE_FLOW_ACTION_TYPE_VF) {
3153                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3154                                    act, "Not supported action.");
3155                 return -rte_errno;
3156         }
3157
3158         if (act->type == RTE_FLOW_ACTION_TYPE_VF) {
3159                 act_vf = (const struct rte_flow_action_vf *)act->conf;
3160                 filter->vf_id = act_vf->id;
3161                 filter->is_to_vf = 1;
3162                 if (filter->vf_id >= pf->vf_num) {
3163                         rte_flow_error_set(error, EINVAL,
3164                                    RTE_FLOW_ERROR_TYPE_ACTION,
3165                                    act, "Invalid VF ID for tunnel filter");
3166                         return -rte_errno;
3167                 }
3168         }
3169
3170         /* Check if the next non-void item is QUEUE */
3171         index++;
3172         NEXT_ITEM_OF_ACTION(act, actions, index);
3173         if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
3174                 act_q = (const struct rte_flow_action_queue *)act->conf;
3175                 filter->queue_id = act_q->index;
3176                 if ((!filter->is_to_vf) &&
3177                     (filter->queue_id >= pf->dev_data->nb_rx_queues)) {
3178                         rte_flow_error_set(error, EINVAL,
3179                                    RTE_FLOW_ERROR_TYPE_ACTION,
3180                                    act, "Invalid queue ID for tunnel filter");
3181                         return -rte_errno;
3182                 } else if (filter->is_to_vf &&
3183                            (filter->queue_id >= pf->vf_nb_qps)) {
3184                         rte_flow_error_set(error, EINVAL,
3185                                    RTE_FLOW_ERROR_TYPE_ACTION,
3186                                    act, "Invalid queue ID for tunnel filter");
3187                         return -rte_errno;
3188                 }
3189         }
3190
3191         /* Check if the next non-void item is END */
3192         index++;
3193         NEXT_ITEM_OF_ACTION(act, actions, index);
3194         if (act->type != RTE_FLOW_ACTION_TYPE_END) {
3195                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
3196                                    act, "Not supported action.");
3197                 return -rte_errno;
3198         }
3199
3200         return 0;
3201 }
3202
3203 static uint16_t i40e_supported_tunnel_filter_types[] = {
3204         ETH_TUNNEL_FILTER_IMAC | ETH_TUNNEL_FILTER_TENID |
3205         ETH_TUNNEL_FILTER_IVLAN,
3206         ETH_TUNNEL_FILTER_IMAC | ETH_TUNNEL_FILTER_IVLAN,
3207         ETH_TUNNEL_FILTER_IMAC | ETH_TUNNEL_FILTER_TENID,
3208         ETH_TUNNEL_FILTER_OMAC | ETH_TUNNEL_FILTER_TENID |
3209         ETH_TUNNEL_FILTER_IMAC,
3210         ETH_TUNNEL_FILTER_IMAC,
3211 };
3212
3213 static int
3214 i40e_check_tunnel_filter_type(uint8_t filter_type)
3215 {
3216         uint8_t i;
3217
3218         for (i = 0; i < RTE_DIM(i40e_supported_tunnel_filter_types); i++) {
3219                 if (filter_type == i40e_supported_tunnel_filter_types[i])
3220                         return 0;
3221         }
3222
3223         return -1;
3224 }
3225
3226 /* 1. Last in item should be NULL as range is not supported.
3227  * 2. Supported filter types: IMAC_IVLAN_TENID, IMAC_IVLAN,
3228  *    IMAC_TENID, OMAC_TENID_IMAC and IMAC.
3229  * 3. Mask of fields which need to be matched should be
3230  *    filled with 1.
3231  * 4. Mask of fields which needn't to be matched should be
3232  *    filled with 0.
3233  */
3234 static int
3235 i40e_flow_parse_vxlan_pattern(__rte_unused struct rte_eth_dev *dev,
3236                               const struct rte_flow_item *pattern,
3237                               struct rte_flow_error *error,
3238                               struct i40e_tunnel_filter_conf *filter)
3239 {
3240         const struct rte_flow_item *item = pattern;
3241         const struct rte_flow_item_eth *eth_spec;
3242         const struct rte_flow_item_eth *eth_mask;
3243         const struct rte_flow_item_vxlan *vxlan_spec;
3244         const struct rte_flow_item_vxlan *vxlan_mask;
3245         const struct rte_flow_item_vlan *vlan_spec;
3246         const struct rte_flow_item_vlan *vlan_mask;
3247         uint8_t filter_type = 0;
3248         bool is_vni_masked = 0;
3249         uint8_t vni_mask[] = {0xFF, 0xFF, 0xFF};
3250         enum rte_flow_item_type item_type;
3251         bool vxlan_flag = 0;
3252         uint32_t tenant_id_be = 0;
3253         int ret;
3254
3255         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3256                 if (item->last) {
3257                         rte_flow_error_set(error, EINVAL,
3258                                            RTE_FLOW_ERROR_TYPE_ITEM,
3259                                            item,
3260                                            "Not support range");
3261                         return -rte_errno;
3262                 }
3263                 item_type = item->type;
3264                 switch (item_type) {
3265                 case RTE_FLOW_ITEM_TYPE_ETH:
3266                         eth_spec = (const struct rte_flow_item_eth *)item->spec;
3267                         eth_mask = (const struct rte_flow_item_eth *)item->mask;
3268
3269                         /* Check if ETH item is used for place holder.
3270                          * If yes, both spec and mask should be NULL.
3271                          * If no, both spec and mask shouldn't be NULL.
3272                          */
3273                         if ((!eth_spec && eth_mask) ||
3274                             (eth_spec && !eth_mask)) {
3275                                 rte_flow_error_set(error, EINVAL,
3276                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3277                                                    item,
3278                                                    "Invalid ether spec/mask");
3279                                 return -rte_errno;
3280                         }
3281
3282                         if (eth_spec && eth_mask) {
3283                                 /* DST address of inner MAC shouldn't be masked.
3284                                  * SRC address of Inner MAC should be masked.
3285                                  */
3286                                 if (!is_broadcast_ether_addr(&eth_mask->dst) ||
3287                                     !is_zero_ether_addr(&eth_mask->src) ||
3288                                     eth_mask->type) {
3289                                         rte_flow_error_set(error, EINVAL,
3290                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3291                                                    item,
3292                                                    "Invalid ether spec/mask");
3293                                         return -rte_errno;
3294                                 }
3295
3296                                 if (!vxlan_flag) {
3297                                         rte_memcpy(&filter->outer_mac,
3298                                                    &eth_spec->dst,
3299                                                    ETHER_ADDR_LEN);
3300                                         filter_type |= ETH_TUNNEL_FILTER_OMAC;
3301                                 } else {
3302                                         rte_memcpy(&filter->inner_mac,
3303                                                    &eth_spec->dst,
3304                                                    ETHER_ADDR_LEN);
3305                                         filter_type |= ETH_TUNNEL_FILTER_IMAC;
3306                                 }
3307                         }
3308                         break;
3309                 case RTE_FLOW_ITEM_TYPE_VLAN:
3310                         vlan_spec =
3311                                 (const struct rte_flow_item_vlan *)item->spec;
3312                         vlan_mask =
3313                                 (const struct rte_flow_item_vlan *)item->mask;
3314                         if (!(vlan_spec && vlan_mask)) {
3315                                 rte_flow_error_set(error, EINVAL,
3316                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3317                                                    item,
3318                                                    "Invalid vlan item");
3319                                 return -rte_errno;
3320                         }
3321
3322                         if (vlan_spec && vlan_mask) {
3323                                 if (vlan_mask->tci ==
3324                                     rte_cpu_to_be_16(I40E_TCI_MASK))
3325                                         filter->inner_vlan =
3326                                               rte_be_to_cpu_16(vlan_spec->tci) &
3327                                               I40E_TCI_MASK;
3328                                 filter_type |= ETH_TUNNEL_FILTER_IVLAN;
3329                         }
3330                         break;
3331                 case RTE_FLOW_ITEM_TYPE_IPV4:
3332                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
3333                         /* IPv4 is used to describe protocol,
3334                          * spec and mask should be NULL.
3335                          */
3336                         if (item->spec || item->mask) {
3337                                 rte_flow_error_set(error, EINVAL,
3338                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3339                                                    item,
3340                                                    "Invalid IPv4 item");
3341                                 return -rte_errno;
3342                         }
3343                         break;
3344                 case RTE_FLOW_ITEM_TYPE_IPV6:
3345                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
3346                         /* IPv6 is used to describe protocol,
3347                          * spec and mask should be NULL.
3348                          */
3349                         if (item->spec || item->mask) {
3350                                 rte_flow_error_set(error, EINVAL,
3351                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3352                                                    item,
3353                                                    "Invalid IPv6 item");
3354                                 return -rte_errno;
3355                         }
3356                         break;
3357                 case RTE_FLOW_ITEM_TYPE_UDP:
3358                         /* UDP is used to describe protocol,
3359                          * spec and mask should be NULL.
3360                          */
3361                         if (item->spec || item->mask) {
3362                                 rte_flow_error_set(error, EINVAL,
3363                                            RTE_FLOW_ERROR_TYPE_ITEM,
3364                                            item,
3365                                            "Invalid UDP item");
3366                                 return -rte_errno;
3367                         }
3368                         break;
3369                 case RTE_FLOW_ITEM_TYPE_VXLAN:
3370                         vxlan_spec =
3371                                 (const struct rte_flow_item_vxlan *)item->spec;
3372                         vxlan_mask =
3373                                 (const struct rte_flow_item_vxlan *)item->mask;
3374                         /* Check if VXLAN item is used to describe protocol.
3375                          * If yes, both spec and mask should be NULL.
3376                          * If no, both spec and mask shouldn't be NULL.
3377                          */
3378                         if ((!vxlan_spec && vxlan_mask) ||
3379                             (vxlan_spec && !vxlan_mask)) {
3380                                 rte_flow_error_set(error, EINVAL,
3381                                            RTE_FLOW_ERROR_TYPE_ITEM,
3382                                            item,
3383                                            "Invalid VXLAN item");
3384                                 return -rte_errno;
3385                         }
3386
3387                         /* Check if VNI is masked. */
3388                         if (vxlan_spec && vxlan_mask) {
3389                                 is_vni_masked =
3390                                         !!memcmp(vxlan_mask->vni, vni_mask,
3391                                                  RTE_DIM(vni_mask));
3392                                 if (is_vni_masked) {
3393                                         rte_flow_error_set(error, EINVAL,
3394                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3395                                                    item,
3396                                                    "Invalid VNI mask");
3397                                         return -rte_errno;
3398                                 }
3399
3400                                 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
3401                                            vxlan_spec->vni, 3);
3402                                 filter->tenant_id =
3403                                         rte_be_to_cpu_32(tenant_id_be);
3404                                 filter_type |= ETH_TUNNEL_FILTER_TENID;
3405                         }
3406
3407                         vxlan_flag = 1;
3408                         break;
3409                 default:
3410                         break;
3411                 }
3412         }
3413
3414         ret = i40e_check_tunnel_filter_type(filter_type);
3415         if (ret < 0) {
3416                 rte_flow_error_set(error, EINVAL,
3417                                    RTE_FLOW_ERROR_TYPE_ITEM,
3418                                    NULL,
3419                                    "Invalid filter type");
3420                 return -rte_errno;
3421         }
3422         filter->filter_type = filter_type;
3423
3424         filter->tunnel_type = I40E_TUNNEL_TYPE_VXLAN;
3425
3426         return 0;
3427 }
3428
3429 static int
3430 i40e_flow_parse_vxlan_filter(struct rte_eth_dev *dev,
3431                              const struct rte_flow_attr *attr,
3432                              const struct rte_flow_item pattern[],
3433                              const struct rte_flow_action actions[],
3434                              struct rte_flow_error *error,
3435                              union i40e_filter_t *filter)
3436 {
3437         struct i40e_tunnel_filter_conf *tunnel_filter =
3438                 &filter->consistent_tunnel_filter;
3439         int ret;
3440
3441         ret = i40e_flow_parse_vxlan_pattern(dev, pattern,
3442                                             error, tunnel_filter);
3443         if (ret)
3444                 return ret;
3445
3446         ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
3447         if (ret)
3448                 return ret;
3449
3450         ret = i40e_flow_parse_attr(attr, error);
3451         if (ret)
3452                 return ret;
3453
3454         cons_filter_type = RTE_ETH_FILTER_TUNNEL;
3455
3456         return ret;
3457 }
3458
3459 /* 1. Last in item should be NULL as range is not supported.
3460  * 2. Supported filter types: IMAC_IVLAN_TENID, IMAC_IVLAN,
3461  *    IMAC_TENID, OMAC_TENID_IMAC and IMAC.
3462  * 3. Mask of fields which need to be matched should be
3463  *    filled with 1.
3464  * 4. Mask of fields which needn't to be matched should be
3465  *    filled with 0.
3466  */
3467 static int
3468 i40e_flow_parse_nvgre_pattern(__rte_unused struct rte_eth_dev *dev,
3469                               const struct rte_flow_item *pattern,
3470                               struct rte_flow_error *error,
3471                               struct i40e_tunnel_filter_conf *filter)
3472 {
3473         const struct rte_flow_item *item = pattern;
3474         const struct rte_flow_item_eth *eth_spec;
3475         const struct rte_flow_item_eth *eth_mask;
3476         const struct rte_flow_item_nvgre *nvgre_spec;
3477         const struct rte_flow_item_nvgre *nvgre_mask;
3478         const struct rte_flow_item_vlan *vlan_spec;
3479         const struct rte_flow_item_vlan *vlan_mask;
3480         enum rte_flow_item_type item_type;
3481         uint8_t filter_type = 0;
3482         bool is_tni_masked = 0;
3483         uint8_t tni_mask[] = {0xFF, 0xFF, 0xFF};
3484         bool nvgre_flag = 0;
3485         uint32_t tenant_id_be = 0;
3486         int ret;
3487
3488         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3489                 if (item->last) {
3490                         rte_flow_error_set(error, EINVAL,
3491                                            RTE_FLOW_ERROR_TYPE_ITEM,
3492                                            item,
3493                                            "Not support range");
3494                         return -rte_errno;
3495                 }
3496                 item_type = item->type;
3497                 switch (item_type) {
3498                 case RTE_FLOW_ITEM_TYPE_ETH:
3499                         eth_spec = (const struct rte_flow_item_eth *)item->spec;
3500                         eth_mask = (const struct rte_flow_item_eth *)item->mask;
3501
3502                         /* Check if ETH item is used for place holder.
3503                          * If yes, both spec and mask should be NULL.
3504                          * If no, both spec and mask shouldn't be NULL.
3505                          */
3506                         if ((!eth_spec && eth_mask) ||
3507                             (eth_spec && !eth_mask)) {
3508                                 rte_flow_error_set(error, EINVAL,
3509                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3510                                                    item,
3511                                                    "Invalid ether spec/mask");
3512                                 return -rte_errno;
3513                         }
3514
3515                         if (eth_spec && eth_mask) {
3516                                 /* DST address of inner MAC shouldn't be masked.
3517                                  * SRC address of Inner MAC should be masked.
3518                                  */
3519                                 if (!is_broadcast_ether_addr(&eth_mask->dst) ||
3520                                     !is_zero_ether_addr(&eth_mask->src) ||
3521                                     eth_mask->type) {
3522                                         rte_flow_error_set(error, EINVAL,
3523                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3524                                                    item,
3525                                                    "Invalid ether spec/mask");
3526                                         return -rte_errno;
3527                                 }
3528
3529                                 if (!nvgre_flag) {
3530                                         rte_memcpy(&filter->outer_mac,
3531                                                    &eth_spec->dst,
3532                                                    ETHER_ADDR_LEN);
3533                                         filter_type |= ETH_TUNNEL_FILTER_OMAC;
3534                                 } else {
3535                                         rte_memcpy(&filter->inner_mac,
3536                                                    &eth_spec->dst,
3537                                                    ETHER_ADDR_LEN);
3538                                         filter_type |= ETH_TUNNEL_FILTER_IMAC;
3539                                 }
3540                         }
3541
3542                         break;
3543                 case RTE_FLOW_ITEM_TYPE_VLAN:
3544                         vlan_spec =
3545                                 (const struct rte_flow_item_vlan *)item->spec;
3546                         vlan_mask =
3547                                 (const struct rte_flow_item_vlan *)item->mask;
3548                         if (!(vlan_spec && vlan_mask)) {
3549                                 rte_flow_error_set(error, EINVAL,
3550                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3551                                                    item,
3552                                                    "Invalid vlan item");
3553                                 return -rte_errno;
3554                         }
3555
3556                         if (vlan_spec && vlan_mask) {
3557                                 if (vlan_mask->tci ==
3558                                     rte_cpu_to_be_16(I40E_TCI_MASK))
3559                                         filter->inner_vlan =
3560                                               rte_be_to_cpu_16(vlan_spec->tci) &
3561                                               I40E_TCI_MASK;
3562                                 filter_type |= ETH_TUNNEL_FILTER_IVLAN;
3563                         }
3564                         break;
3565                 case RTE_FLOW_ITEM_TYPE_IPV4:
3566                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
3567                         /* IPv4 is used to describe protocol,
3568                          * spec and mask should be NULL.
3569                          */
3570                         if (item->spec || item->mask) {
3571                                 rte_flow_error_set(error, EINVAL,
3572                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3573                                                    item,
3574                                                    "Invalid IPv4 item");
3575                                 return -rte_errno;
3576                         }
3577                         break;
3578                 case RTE_FLOW_ITEM_TYPE_IPV6:
3579                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
3580                         /* IPv6 is used to describe protocol,
3581                          * spec and mask should be NULL.
3582                          */
3583                         if (item->spec || item->mask) {
3584                                 rte_flow_error_set(error, EINVAL,
3585                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3586                                                    item,
3587                                                    "Invalid IPv6 item");
3588                                 return -rte_errno;
3589                         }
3590                         break;
3591                 case RTE_FLOW_ITEM_TYPE_NVGRE:
3592                         nvgre_spec =
3593                                 (const struct rte_flow_item_nvgre *)item->spec;
3594                         nvgre_mask =
3595                                 (const struct rte_flow_item_nvgre *)item->mask;
3596                         /* Check if NVGRE item is used to describe protocol.
3597                          * If yes, both spec and mask should be NULL.
3598                          * If no, both spec and mask shouldn't be NULL.
3599                          */
3600                         if ((!nvgre_spec && nvgre_mask) ||
3601                             (nvgre_spec && !nvgre_mask)) {
3602                                 rte_flow_error_set(error, EINVAL,
3603                                            RTE_FLOW_ERROR_TYPE_ITEM,
3604                                            item,
3605                                            "Invalid NVGRE item");
3606                                 return -rte_errno;
3607                         }
3608
3609                         if (nvgre_spec && nvgre_mask) {
3610                                 is_tni_masked =
3611                                         !!memcmp(nvgre_mask->tni, tni_mask,
3612                                                  RTE_DIM(tni_mask));
3613                                 if (is_tni_masked) {
3614                                         rte_flow_error_set(error, EINVAL,
3615                                                        RTE_FLOW_ERROR_TYPE_ITEM,
3616                                                        item,
3617                                                        "Invalid TNI mask");
3618                                         return -rte_errno;
3619                                 }
3620                                 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
3621                                            nvgre_spec->tni, 3);
3622                                 filter->tenant_id =
3623                                         rte_be_to_cpu_32(tenant_id_be);
3624                                 filter_type |= ETH_TUNNEL_FILTER_TENID;
3625                         }
3626
3627                         nvgre_flag = 1;
3628                         break;
3629                 default:
3630                         break;
3631                 }
3632         }
3633
3634         ret = i40e_check_tunnel_filter_type(filter_type);
3635         if (ret < 0) {
3636                 rte_flow_error_set(error, EINVAL,
3637                                    RTE_FLOW_ERROR_TYPE_ITEM,
3638                                    NULL,
3639                                    "Invalid filter type");
3640                 return -rte_errno;
3641         }
3642         filter->filter_type = filter_type;
3643
3644         filter->tunnel_type = I40E_TUNNEL_TYPE_NVGRE;
3645
3646         return 0;
3647 }
3648
3649 static int
3650 i40e_flow_parse_nvgre_filter(struct rte_eth_dev *dev,
3651                              const struct rte_flow_attr *attr,
3652                              const struct rte_flow_item pattern[],
3653                              const struct rte_flow_action actions[],
3654                              struct rte_flow_error *error,
3655                              union i40e_filter_t *filter)
3656 {
3657         struct i40e_tunnel_filter_conf *tunnel_filter =
3658                 &filter->consistent_tunnel_filter;
3659         int ret;
3660
3661         ret = i40e_flow_parse_nvgre_pattern(dev, pattern,
3662                                             error, tunnel_filter);
3663         if (ret)
3664                 return ret;
3665
3666         ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
3667         if (ret)
3668                 return ret;
3669
3670         ret = i40e_flow_parse_attr(attr, error);
3671         if (ret)
3672                 return ret;
3673
3674         cons_filter_type = RTE_ETH_FILTER_TUNNEL;
3675
3676         return ret;
3677 }
3678
3679 /* 1. Last in item should be NULL as range is not supported.
3680  * 2. Supported filter types: MPLS label.
3681  * 3. Mask of fields which need to be matched should be
3682  *    filled with 1.
3683  * 4. Mask of fields which needn't to be matched should be
3684  *    filled with 0.
3685  */
3686 static int
3687 i40e_flow_parse_mpls_pattern(__rte_unused struct rte_eth_dev *dev,
3688                              const struct rte_flow_item *pattern,
3689                              struct rte_flow_error *error,
3690                              struct i40e_tunnel_filter_conf *filter)
3691 {
3692         const struct rte_flow_item *item = pattern;
3693         const struct rte_flow_item_mpls *mpls_spec;
3694         const struct rte_flow_item_mpls *mpls_mask;
3695         enum rte_flow_item_type item_type;
3696         bool is_mplsoudp = 0; /* 1 - MPLSoUDP, 0 - MPLSoGRE */
3697         const uint8_t label_mask[3] = {0xFF, 0xFF, 0xF0};
3698         uint32_t label_be = 0;
3699
3700         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3701                 if (item->last) {
3702                         rte_flow_error_set(error, EINVAL,
3703                                            RTE_FLOW_ERROR_TYPE_ITEM,
3704                                            item,
3705                                            "Not support range");
3706                         return -rte_errno;
3707                 }
3708                 item_type = item->type;
3709                 switch (item_type) {
3710                 case RTE_FLOW_ITEM_TYPE_ETH:
3711                         if (item->spec || item->mask) {
3712                                 rte_flow_error_set(error, EINVAL,
3713                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3714                                                    item,
3715                                                    "Invalid ETH item");
3716                                 return -rte_errno;
3717                         }
3718                         break;
3719                 case RTE_FLOW_ITEM_TYPE_IPV4:
3720                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
3721                         /* IPv4 is used to describe protocol,
3722                          * spec and mask should be NULL.
3723                          */
3724                         if (item->spec || item->mask) {
3725                                 rte_flow_error_set(error, EINVAL,
3726                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3727                                                    item,
3728                                                    "Invalid IPv4 item");
3729                                 return -rte_errno;
3730                         }
3731                         break;
3732                 case RTE_FLOW_ITEM_TYPE_IPV6:
3733                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
3734                         /* IPv6 is used to describe protocol,
3735                          * spec and mask should be NULL.
3736                          */
3737                         if (item->spec || item->mask) {
3738                                 rte_flow_error_set(error, EINVAL,
3739                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3740                                                    item,
3741                                                    "Invalid IPv6 item");
3742                                 return -rte_errno;
3743                         }
3744                         break;
3745                 case RTE_FLOW_ITEM_TYPE_UDP:
3746                         /* UDP is used to describe protocol,
3747                          * spec and mask should be NULL.
3748                          */
3749                         if (item->spec || item->mask) {
3750                                 rte_flow_error_set(error, EINVAL,
3751                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3752                                                    item,
3753                                                    "Invalid UDP item");
3754                                 return -rte_errno;
3755                         }
3756                         is_mplsoudp = 1;
3757                         break;
3758                 case RTE_FLOW_ITEM_TYPE_GRE:
3759                         /* GRE is used to describe protocol,
3760                          * spec and mask should be NULL.
3761                          */
3762                         if (item->spec || item->mask) {
3763                                 rte_flow_error_set(error, EINVAL,
3764                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3765                                                    item,
3766                                                    "Invalid GRE item");
3767                                 return -rte_errno;
3768                         }
3769                         break;
3770                 case RTE_FLOW_ITEM_TYPE_MPLS:
3771                         mpls_spec =
3772                                 (const struct rte_flow_item_mpls *)item->spec;
3773                         mpls_mask =
3774                                 (const struct rte_flow_item_mpls *)item->mask;
3775
3776                         if (!mpls_spec || !mpls_mask) {
3777                                 rte_flow_error_set(error, EINVAL,
3778                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3779                                                    item,
3780                                                    "Invalid MPLS item");
3781                                 return -rte_errno;
3782                         }
3783
3784                         if (memcmp(mpls_mask->label_tc_s, label_mask, 3)) {
3785                                 rte_flow_error_set(error, EINVAL,
3786                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3787                                                    item,
3788                                                    "Invalid MPLS label mask");
3789                                 return -rte_errno;
3790                         }
3791                         rte_memcpy(((uint8_t *)&label_be + 1),
3792                                    mpls_spec->label_tc_s, 3);
3793                         filter->tenant_id = rte_be_to_cpu_32(label_be) >> 4;
3794                         break;
3795                 default:
3796                         break;
3797                 }
3798         }
3799
3800         if (is_mplsoudp)
3801                 filter->tunnel_type = I40E_TUNNEL_TYPE_MPLSoUDP;
3802         else
3803                 filter->tunnel_type = I40E_TUNNEL_TYPE_MPLSoGRE;
3804
3805         return 0;
3806 }
3807
3808 static int
3809 i40e_flow_parse_mpls_filter(struct rte_eth_dev *dev,
3810                             const struct rte_flow_attr *attr,
3811                             const struct rte_flow_item pattern[],
3812                             const struct rte_flow_action actions[],
3813                             struct rte_flow_error *error,
3814                             union i40e_filter_t *filter)
3815 {
3816         struct i40e_tunnel_filter_conf *tunnel_filter =
3817                 &filter->consistent_tunnel_filter;
3818         int ret;
3819
3820         ret = i40e_flow_parse_mpls_pattern(dev, pattern,
3821                                            error, tunnel_filter);
3822         if (ret)
3823                 return ret;
3824
3825         ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
3826         if (ret)
3827                 return ret;
3828
3829         ret = i40e_flow_parse_attr(attr, error);
3830         if (ret)
3831                 return ret;
3832
3833         cons_filter_type = RTE_ETH_FILTER_TUNNEL;
3834
3835         return ret;
3836 }
3837
3838 /* 1. Last in item should be NULL as range is not supported.
3839  * 2. Supported filter types: GTP TEID.
3840  * 3. Mask of fields which need to be matched should be
3841  *    filled with 1.
3842  * 4. Mask of fields which needn't to be matched should be
3843  *    filled with 0.
3844  * 5. GTP profile supports GTPv1 only.
3845  * 6. GTP-C response message ('source_port' = 2123) is not supported.
3846  */
3847 static int
3848 i40e_flow_parse_gtp_pattern(struct rte_eth_dev *dev,
3849                             const struct rte_flow_item *pattern,
3850                             struct rte_flow_error *error,
3851                             struct i40e_tunnel_filter_conf *filter)
3852 {
3853         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3854         const struct rte_flow_item *item = pattern;
3855         const struct rte_flow_item_gtp *gtp_spec;
3856         const struct rte_flow_item_gtp *gtp_mask;
3857         enum rte_flow_item_type item_type;
3858
3859         if (!pf->gtp_support) {
3860                 rte_flow_error_set(error, EINVAL,
3861                                    RTE_FLOW_ERROR_TYPE_ITEM,
3862                                    item,
3863                                    "GTP is not supported by default.");
3864                 return -rte_errno;
3865         }
3866
3867         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
3868                 if (item->last) {
3869                         rte_flow_error_set(error, EINVAL,
3870                                            RTE_FLOW_ERROR_TYPE_ITEM,
3871                                            item,
3872                                            "Not support range");
3873                         return -rte_errno;
3874                 }
3875                 item_type = item->type;
3876                 switch (item_type) {
3877                 case RTE_FLOW_ITEM_TYPE_ETH:
3878                         if (item->spec || item->mask) {
3879                                 rte_flow_error_set(error, EINVAL,
3880                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3881                                                    item,
3882                                                    "Invalid ETH item");
3883                                 return -rte_errno;
3884                         }
3885                         break;
3886                 case RTE_FLOW_ITEM_TYPE_IPV4:
3887                         filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
3888                         /* IPv4 is used to describe protocol,
3889                          * spec and mask should be NULL.
3890                          */
3891                         if (item->spec || item->mask) {
3892                                 rte_flow_error_set(error, EINVAL,
3893                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3894                                                    item,
3895                                                    "Invalid IPv4 item");
3896                                 return -rte_errno;
3897                         }
3898                         break;
3899                 case RTE_FLOW_ITEM_TYPE_UDP:
3900                         if (item->spec || item->mask) {
3901                                 rte_flow_error_set(error, EINVAL,
3902                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3903                                                    item,
3904                                                    "Invalid UDP item");
3905                                 return -rte_errno;
3906                         }
3907                         break;
3908                 case RTE_FLOW_ITEM_TYPE_GTPC:
3909                 case RTE_FLOW_ITEM_TYPE_GTPU:
3910                         gtp_spec =
3911                                 (const struct rte_flow_item_gtp *)item->spec;
3912                         gtp_mask =
3913                                 (const struct rte_flow_item_gtp *)item->mask;
3914
3915                         if (!gtp_spec || !gtp_mask) {
3916                                 rte_flow_error_set(error, EINVAL,
3917                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3918                                                    item,
3919                                                    "Invalid GTP item");
3920                                 return -rte_errno;
3921                         }
3922
3923                         if (gtp_mask->v_pt_rsv_flags ||
3924                             gtp_mask->msg_type ||
3925                             gtp_mask->msg_len ||
3926                             gtp_mask->teid != UINT32_MAX) {
3927                                 rte_flow_error_set(error, EINVAL,
3928                                                    RTE_FLOW_ERROR_TYPE_ITEM,
3929                                                    item,
3930                                                    "Invalid GTP mask");
3931                                 return -rte_errno;
3932                         }
3933
3934                         if (item_type == RTE_FLOW_ITEM_TYPE_GTPC)
3935                                 filter->tunnel_type = I40E_TUNNEL_TYPE_GTPC;
3936                         else if (item_type == RTE_FLOW_ITEM_TYPE_GTPU)
3937                                 filter->tunnel_type = I40E_TUNNEL_TYPE_GTPU;
3938
3939                         filter->tenant_id = rte_be_to_cpu_32(gtp_spec->teid);
3940
3941                         break;
3942                 default:
3943                         break;
3944                 }
3945         }
3946
3947         return 0;
3948 }
3949
3950 static int
3951 i40e_flow_parse_gtp_filter(struct rte_eth_dev *dev,
3952                            const struct rte_flow_attr *attr,
3953                            const struct rte_flow_item pattern[],
3954                            const struct rte_flow_action actions[],
3955                            struct rte_flow_error *error,
3956                            union i40e_filter_t *filter)
3957 {
3958         struct i40e_tunnel_filter_conf *tunnel_filter =
3959                 &filter->consistent_tunnel_filter;
3960         int ret;
3961
3962         ret = i40e_flow_parse_gtp_pattern(dev, pattern,
3963                                           error, tunnel_filter);
3964         if (ret)
3965                 return ret;
3966
3967         ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
3968         if (ret)
3969                 return ret;
3970
3971         ret = i40e_flow_parse_attr(attr, error);
3972         if (ret)
3973                 return ret;
3974
3975         cons_filter_type = RTE_ETH_FILTER_TUNNEL;
3976
3977         return ret;
3978 }
3979
3980 /* 1. Last in item should be NULL as range is not supported.
3981  * 2. Supported filter types: QINQ.
3982  * 3. Mask of fields which need to be matched should be
3983  *    filled with 1.
3984  * 4. Mask of fields which needn't to be matched should be
3985  *    filled with 0.
3986  */
3987 static int
3988 i40e_flow_parse_qinq_pattern(__rte_unused struct rte_eth_dev *dev,
3989                               const struct rte_flow_item *pattern,
3990                               struct rte_flow_error *error,
3991                               struct i40e_tunnel_filter_conf *filter)
3992 {
3993         const struct rte_flow_item *item = pattern;
3994         const struct rte_flow_item_vlan *vlan_spec = NULL;
3995         const struct rte_flow_item_vlan *vlan_mask = NULL;
3996         const struct rte_flow_item_vlan *i_vlan_spec = NULL;
3997         const struct rte_flow_item_vlan *i_vlan_mask = NULL;
3998         const struct rte_flow_item_vlan *o_vlan_spec = NULL;
3999         const struct rte_flow_item_vlan *o_vlan_mask = NULL;
4000
4001         enum rte_flow_item_type item_type;
4002         bool vlan_flag = 0;
4003
4004         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
4005                 if (item->last) {
4006                         rte_flow_error_set(error, EINVAL,
4007                                            RTE_FLOW_ERROR_TYPE_ITEM,
4008                                            item,
4009                                            "Not support range");
4010                         return -rte_errno;
4011                 }
4012                 item_type = item->type;
4013                 switch (item_type) {
4014                 case RTE_FLOW_ITEM_TYPE_ETH:
4015                         if (item->spec || item->mask) {
4016                                 rte_flow_error_set(error, EINVAL,
4017                                                    RTE_FLOW_ERROR_TYPE_ITEM,
4018                                                    item,
4019                                                    "Invalid ETH item");
4020                                 return -rte_errno;
4021                         }
4022                         break;
4023                 case RTE_FLOW_ITEM_TYPE_VLAN:
4024                         vlan_spec =
4025                                 (const struct rte_flow_item_vlan *)item->spec;
4026                         vlan_mask =
4027                                 (const struct rte_flow_item_vlan *)item->mask;
4028
4029                         if (!(vlan_spec && vlan_mask)) {
4030                                 rte_flow_error_set(error, EINVAL,
4031                                            RTE_FLOW_ERROR_TYPE_ITEM,
4032                                            item,
4033                                            "Invalid vlan item");
4034                                 return -rte_errno;
4035                         }
4036
4037                         if (!vlan_flag) {
4038                                 o_vlan_spec = vlan_spec;
4039                                 o_vlan_mask = vlan_mask;
4040                                 vlan_flag = 1;
4041                         } else {
4042                                 i_vlan_spec = vlan_spec;
4043                                 i_vlan_mask = vlan_mask;
4044                                 vlan_flag = 0;
4045                         }
4046                         break;
4047
4048                 default:
4049                         break;
4050                 }
4051         }
4052
4053         /* Get filter specification */
4054         if ((o_vlan_mask != NULL) && (o_vlan_mask->tci ==
4055                         rte_cpu_to_be_16(I40E_TCI_MASK)) &&
4056                         (i_vlan_mask != NULL) &&
4057                         (i_vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK))) {
4058                 filter->outer_vlan = rte_be_to_cpu_16(o_vlan_spec->tci)
4059                         & I40E_TCI_MASK;
4060                 filter->inner_vlan = rte_be_to_cpu_16(i_vlan_spec->tci)
4061                         & I40E_TCI_MASK;
4062         } else {
4063                         rte_flow_error_set(error, EINVAL,
4064                                            RTE_FLOW_ERROR_TYPE_ITEM,
4065                                            NULL,
4066                                            "Invalid filter type");
4067                         return -rte_errno;
4068         }
4069
4070         filter->tunnel_type = I40E_TUNNEL_TYPE_QINQ;
4071         return 0;
4072 }
4073
4074 static int
4075 i40e_flow_parse_qinq_filter(struct rte_eth_dev *dev,
4076                               const struct rte_flow_attr *attr,
4077                               const struct rte_flow_item pattern[],
4078                               const struct rte_flow_action actions[],
4079                               struct rte_flow_error *error,
4080                               union i40e_filter_t *filter)
4081 {
4082         struct i40e_tunnel_filter_conf *tunnel_filter =
4083                 &filter->consistent_tunnel_filter;
4084         int ret;
4085
4086         ret = i40e_flow_parse_qinq_pattern(dev, pattern,
4087                                              error, tunnel_filter);
4088         if (ret)
4089                 return ret;
4090
4091         ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
4092         if (ret)
4093                 return ret;
4094
4095         ret = i40e_flow_parse_attr(attr, error);
4096         if (ret)
4097                 return ret;
4098
4099         cons_filter_type = RTE_ETH_FILTER_TUNNEL;
4100
4101         return ret;
4102 }
4103
4104 static int
4105 i40e_flow_validate(struct rte_eth_dev *dev,
4106                    const struct rte_flow_attr *attr,
4107                    const struct rte_flow_item pattern[],
4108                    const struct rte_flow_action actions[],
4109                    struct rte_flow_error *error)
4110 {
4111         struct rte_flow_item *items; /* internal pattern w/o VOID items */
4112         parse_filter_t parse_filter;
4113         uint32_t item_num = 0; /* non-void item number of pattern*/
4114         uint32_t i = 0;
4115         bool flag = false;
4116         int ret = I40E_NOT_SUPPORTED;
4117
4118         if (!pattern) {
4119                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
4120                                    NULL, "NULL pattern.");
4121                 return -rte_errno;
4122         }
4123
4124         if (!actions) {
4125                 rte_flow_error_set(error, EINVAL,
4126                                    RTE_FLOW_ERROR_TYPE_ACTION_NUM,
4127                                    NULL, "NULL action.");
4128                 return -rte_errno;
4129         }
4130
4131         if (!attr) {
4132                 rte_flow_error_set(error, EINVAL,
4133                                    RTE_FLOW_ERROR_TYPE_ATTR,
4134                                    NULL, "NULL attribute.");
4135                 return -rte_errno;
4136         }
4137
4138         memset(&cons_filter, 0, sizeof(cons_filter));
4139
4140         /* Get the non-void item number of pattern */
4141         while ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_END) {
4142                 if ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_VOID)
4143                         item_num++;
4144                 i++;
4145         }
4146         item_num++;
4147
4148         items = rte_zmalloc("i40e_pattern",
4149                             item_num * sizeof(struct rte_flow_item), 0);
4150         if (!items) {
4151                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
4152                                    NULL, "No memory for PMD internal items.");
4153                 return -ENOMEM;
4154         }
4155
4156         i40e_pattern_skip_void_item(items, pattern);
4157
4158         i = 0;
4159         do {
4160                 parse_filter = i40e_find_parse_filter_func(items, &i);
4161                 if (!parse_filter && !flag) {
4162                         rte_flow_error_set(error, EINVAL,
4163                                            RTE_FLOW_ERROR_TYPE_ITEM,
4164                                            pattern, "Unsupported pattern");
4165                         rte_free(items);
4166                         return -rte_errno;
4167                 }
4168                 if (parse_filter)
4169                         ret = parse_filter(dev, attr, items, actions,
4170                                            error, &cons_filter);
4171                 flag = true;
4172         } while ((ret < 0) && (i < RTE_DIM(i40e_supported_patterns)));
4173
4174         rte_free(items);
4175
4176         return ret;
4177 }
4178
4179 static struct rte_flow *
4180 i40e_flow_create(struct rte_eth_dev *dev,
4181                  const struct rte_flow_attr *attr,
4182                  const struct rte_flow_item pattern[],
4183                  const struct rte_flow_action actions[],
4184                  struct rte_flow_error *error)
4185 {
4186         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4187         struct rte_flow *flow;
4188         int ret;
4189
4190         flow = rte_zmalloc("i40e_flow", sizeof(struct rte_flow), 0);
4191         if (!flow) {
4192                 rte_flow_error_set(error, ENOMEM,
4193                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4194                                    "Failed to allocate memory");
4195                 return flow;
4196         }
4197
4198         ret = i40e_flow_validate(dev, attr, pattern, actions, error);
4199         if (ret < 0)
4200                 return NULL;
4201
4202         switch (cons_filter_type) {
4203         case RTE_ETH_FILTER_ETHERTYPE:
4204                 ret = i40e_ethertype_filter_set(pf,
4205                                         &cons_filter.ethertype_filter, 1);
4206                 if (ret)
4207                         goto free_flow;
4208                 flow->rule = TAILQ_LAST(&pf->ethertype.ethertype_list,
4209                                         i40e_ethertype_filter_list);
4210                 break;
4211         case RTE_ETH_FILTER_FDIR:
4212                 ret = i40e_flow_add_del_fdir_filter(dev,
4213                                        &cons_filter.fdir_filter, 1);
4214                 if (ret)
4215                         goto free_flow;
4216                 flow->rule = TAILQ_LAST(&pf->fdir.fdir_list,
4217                                         i40e_fdir_filter_list);
4218                 break;
4219         case RTE_ETH_FILTER_TUNNEL:
4220                 ret = i40e_dev_consistent_tunnel_filter_set(pf,
4221                             &cons_filter.consistent_tunnel_filter, 1);
4222                 if (ret)
4223                         goto free_flow;
4224                 flow->rule = TAILQ_LAST(&pf->tunnel.tunnel_list,
4225                                         i40e_tunnel_filter_list);
4226                 break;
4227         default:
4228                 goto free_flow;
4229         }
4230
4231         flow->filter_type = cons_filter_type;
4232         TAILQ_INSERT_TAIL(&pf->flow_list, flow, node);
4233         return flow;
4234
4235 free_flow:
4236         rte_flow_error_set(error, -ret,
4237                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4238                            "Failed to create flow.");
4239         rte_free(flow);
4240         return NULL;
4241 }
4242
4243 static int
4244 i40e_flow_destroy(struct rte_eth_dev *dev,
4245                   struct rte_flow *flow,
4246                   struct rte_flow_error *error)
4247 {
4248         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4249         enum rte_filter_type filter_type = flow->filter_type;
4250         int ret = 0;
4251
4252         switch (filter_type) {
4253         case RTE_ETH_FILTER_ETHERTYPE:
4254                 ret = i40e_flow_destroy_ethertype_filter(pf,
4255                          (struct i40e_ethertype_filter *)flow->rule);
4256                 break;
4257         case RTE_ETH_FILTER_TUNNEL:
4258                 ret = i40e_flow_destroy_tunnel_filter(pf,
4259                               (struct i40e_tunnel_filter *)flow->rule);
4260                 break;
4261         case RTE_ETH_FILTER_FDIR:
4262                 ret = i40e_flow_add_del_fdir_filter(dev,
4263                        &((struct i40e_fdir_filter *)flow->rule)->fdir, 0);
4264                 break;
4265         default:
4266                 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4267                             filter_type);
4268                 ret = -EINVAL;
4269                 break;
4270         }
4271
4272         if (!ret) {
4273                 TAILQ_REMOVE(&pf->flow_list, flow, node);
4274                 rte_free(flow);
4275         } else
4276                 rte_flow_error_set(error, -ret,
4277                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4278                                    "Failed to destroy flow.");
4279
4280         return ret;
4281 }
4282
4283 static int
4284 i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
4285                                    struct i40e_ethertype_filter *filter)
4286 {
4287         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4288         struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
4289         struct i40e_ethertype_filter *node;
4290         struct i40e_control_filter_stats stats;
4291         uint16_t flags = 0;
4292         int ret = 0;
4293
4294         if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
4295                 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
4296         if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
4297                 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
4298         flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
4299
4300         memset(&stats, 0, sizeof(stats));
4301         ret = i40e_aq_add_rem_control_packet_filter(hw,
4302                                     filter->input.mac_addr.addr_bytes,
4303                                     filter->input.ether_type,
4304                                     flags, pf->main_vsi->seid,
4305                                     filter->queue, 0, &stats, NULL);
4306         if (ret < 0)
4307                 return ret;
4308
4309         node = i40e_sw_ethertype_filter_lookup(ethertype_rule, &filter->input);
4310         if (!node)
4311                 return -EINVAL;
4312
4313         ret = i40e_sw_ethertype_filter_del(pf, &node->input);
4314
4315         return ret;
4316 }
4317
4318 static int
4319 i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
4320                                 struct i40e_tunnel_filter *filter)
4321 {
4322         struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4323         struct i40e_vsi *vsi;
4324         struct i40e_pf_vf *vf;
4325         struct i40e_aqc_add_rm_cloud_filt_elem_ext cld_filter;
4326         struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
4327         struct i40e_tunnel_filter *node;
4328         bool big_buffer = 0;
4329         int ret = 0;
4330
4331         memset(&cld_filter, 0, sizeof(cld_filter));
4332         ether_addr_copy((struct ether_addr *)&filter->input.outer_mac,
4333                         (struct ether_addr *)&cld_filter.element.outer_mac);
4334         ether_addr_copy((struct ether_addr *)&filter->input.inner_mac,
4335                         (struct ether_addr *)&cld_filter.element.inner_mac);
4336         cld_filter.element.inner_vlan = filter->input.inner_vlan;
4337         cld_filter.element.flags = filter->input.flags;
4338         cld_filter.element.tenant_id = filter->input.tenant_id;
4339         cld_filter.element.queue_number = filter->queue;
4340         rte_memcpy(cld_filter.general_fields,
4341                    filter->input.general_fields,
4342                    sizeof(cld_filter.general_fields));
4343
4344         if (!filter->is_to_vf)
4345                 vsi = pf->main_vsi;
4346         else {
4347                 vf = &pf->vfs[filter->vf_id];
4348                 vsi = vf->vsi;
4349         }
4350
4351         if (((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoUDP) ==
4352             I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoUDP) ||
4353             ((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ==
4354             I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ||
4355             ((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ) ==
4356             I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ))
4357                 big_buffer = 1;
4358
4359         if (big_buffer)
4360                 ret = i40e_aq_remove_cloud_filters_big_buffer(hw, vsi->seid,
4361                                                               &cld_filter, 1);
4362         else
4363                 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
4364                                                    &cld_filter.element, 1);
4365         if (ret < 0)
4366                 return -ENOTSUP;
4367
4368         node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &filter->input);
4369         if (!node)
4370                 return -EINVAL;
4371
4372         ret = i40e_sw_tunnel_filter_del(pf, &node->input);
4373
4374         return ret;
4375 }
4376
4377 static int
4378 i40e_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
4379 {
4380         struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4381         int ret;
4382
4383         ret = i40e_flow_flush_fdir_filter(pf);
4384         if (ret) {
4385                 rte_flow_error_set(error, -ret,
4386                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4387                                    "Failed to flush FDIR flows.");
4388                 return -rte_errno;
4389         }
4390
4391         ret = i40e_flow_flush_ethertype_filter(pf);
4392         if (ret) {
4393                 rte_flow_error_set(error, -ret,
4394                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4395                                    "Failed to ethertype flush flows.");
4396                 return -rte_errno;
4397         }
4398
4399         ret = i40e_flow_flush_tunnel_filter(pf);
4400         if (ret) {
4401                 rte_flow_error_set(error, -ret,
4402                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
4403                                    "Failed to flush tunnel flows.");
4404                 return -rte_errno;
4405         }
4406
4407         return ret;
4408 }
4409
4410 static int
4411 i40e_flow_flush_fdir_filter(struct i40e_pf *pf)
4412 {
4413         struct rte_eth_dev *dev = pf->adapter->eth_dev;
4414         struct i40e_fdir_info *fdir_info = &pf->fdir;
4415         struct i40e_fdir_filter *fdir_filter;
4416         struct rte_flow *flow;
4417         void *temp;
4418         int ret;
4419
4420         ret = i40e_fdir_flush(dev);
4421         if (!ret) {
4422                 /* Delete FDIR filters in FDIR list. */
4423                 while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
4424                         ret = i40e_sw_fdir_filter_del(pf,
4425                                                       &fdir_filter->fdir.input);
4426                         if (ret < 0)
4427                                 return ret;
4428                 }
4429
4430                 /* Delete FDIR flows in flow list. */
4431                 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
4432                         if (flow->filter_type == RTE_ETH_FILTER_FDIR) {
4433                                 TAILQ_REMOVE(&pf->flow_list, flow, node);
4434                                 rte_free(flow);
4435                         }
4436                 }
4437         }
4438
4439         return ret;
4440 }
4441
4442 /* Flush all ethertype filters */
4443 static int
4444 i40e_flow_flush_ethertype_filter(struct i40e_pf *pf)
4445 {
4446         struct i40e_ethertype_filter_list
4447                 *ethertype_list = &pf->ethertype.ethertype_list;
4448         struct i40e_ethertype_filter *filter;
4449         struct rte_flow *flow;
4450         void *temp;
4451         int ret = 0;
4452
4453         while ((filter = TAILQ_FIRST(ethertype_list))) {
4454                 ret = i40e_flow_destroy_ethertype_filter(pf, filter);
4455                 if (ret)
4456                         return ret;
4457         }
4458
4459         /* Delete ethertype flows in flow list. */
4460         TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
4461                 if (flow->filter_type == RTE_ETH_FILTER_ETHERTYPE) {
4462                         TAILQ_REMOVE(&pf->flow_list, flow, node);
4463                         rte_free(flow);
4464                 }
4465         }
4466
4467         return ret;
4468 }
4469
4470 /* Flush all tunnel filters */
4471 static int
4472 i40e_flow_flush_tunnel_filter(struct i40e_pf *pf)
4473 {
4474         struct i40e_tunnel_filter_list
4475                 *tunnel_list = &pf->tunnel.tunnel_list;
4476         struct i40e_tunnel_filter *filter;
4477         struct rte_flow *flow;
4478         void *temp;
4479         int ret = 0;
4480
4481         while ((filter = TAILQ_FIRST(tunnel_list))) {
4482                 ret = i40e_flow_destroy_tunnel_filter(pf, filter);
4483                 if (ret)
4484                         return ret;
4485         }
4486
4487         /* Delete tunnel flows in flow list. */
4488         TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
4489                 if (flow->filter_type == RTE_ETH_FILTER_TUNNEL) {
4490                         TAILQ_REMOVE(&pf->flow_list, flow, node);
4491                         rte_free(flow);
4492                 }
4493         }
4494
4495         return ret;
4496 }