net/bnxt: fix using RSS config struct
[dpdk.git] / drivers / net / ice / ice_generic_flow.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <sys/queue.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12
13 #include <rte_ether.h>
14 #include <rte_ethdev_driver.h>
15 #include <rte_malloc.h>
16 #include <rte_tailq.h>
17
18 #include "ice_ethdev.h"
19 #include "ice_generic_flow.h"
20
21 /**
22  * Non-pipeline mode, fdir and switch both used as distributor,
23  * fdir used first, switch used as fdir's backup.
24  */
25 #define ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR_ONLY 0
26 /*Pipeline mode, switch used at permission stage*/
27 #define ICE_FLOW_CLASSIFY_STAGE_PERMISSION 1
28 /*Pipeline mode, fdir used at distributor stage*/
29 #define ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR 2
30
31 static struct ice_engine_list engine_list =
32                 TAILQ_HEAD_INITIALIZER(engine_list);
33
34 static int ice_flow_validate(struct rte_eth_dev *dev,
35                 const struct rte_flow_attr *attr,
36                 const struct rte_flow_item pattern[],
37                 const struct rte_flow_action actions[],
38                 struct rte_flow_error *error);
39 static struct rte_flow *ice_flow_create(struct rte_eth_dev *dev,
40                 const struct rte_flow_attr *attr,
41                 const struct rte_flow_item pattern[],
42                 const struct rte_flow_action actions[],
43                 struct rte_flow_error *error);
44 static int ice_flow_destroy(struct rte_eth_dev *dev,
45                 struct rte_flow *flow,
46                 struct rte_flow_error *error);
47 static int ice_flow_flush(struct rte_eth_dev *dev,
48                 struct rte_flow_error *error);
49 static int ice_flow_query(struct rte_eth_dev *dev,
50                 struct rte_flow *flow,
51                 const struct rte_flow_action *actions,
52                 void *data,
53                 struct rte_flow_error *error);
54
55 const struct rte_flow_ops ice_flow_ops = {
56         .validate = ice_flow_validate,
57         .create = ice_flow_create,
58         .destroy = ice_flow_destroy,
59         .flush = ice_flow_flush,
60         .query = ice_flow_query,
61 };
62
63 /* empty */
64 enum rte_flow_item_type pattern_empty[] = {
65         RTE_FLOW_ITEM_TYPE_END,
66 };
67
68 /* L2 */
69 enum rte_flow_item_type pattern_ethertype[] = {
70         RTE_FLOW_ITEM_TYPE_ETH,
71         RTE_FLOW_ITEM_TYPE_END,
72 };
73 enum rte_flow_item_type pattern_ethertype_vlan[] = {
74         RTE_FLOW_ITEM_TYPE_ETH,
75         RTE_FLOW_ITEM_TYPE_VLAN,
76         RTE_FLOW_ITEM_TYPE_END,
77 };
78 enum rte_flow_item_type pattern_ethertype_qinq[] = {
79         RTE_FLOW_ITEM_TYPE_ETH,
80         RTE_FLOW_ITEM_TYPE_VLAN,
81         RTE_FLOW_ITEM_TYPE_VLAN,
82         RTE_FLOW_ITEM_TYPE_END,
83 };
84
85 /* ARP */
86 enum rte_flow_item_type pattern_eth_arp[] = {
87         RTE_FLOW_ITEM_TYPE_ETH,
88         RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
89         RTE_FLOW_ITEM_TYPE_END,
90 };
91
92 /* non-tunnel IPv4 */
93 enum rte_flow_item_type pattern_eth_ipv4[] = {
94         RTE_FLOW_ITEM_TYPE_ETH,
95         RTE_FLOW_ITEM_TYPE_IPV4,
96         RTE_FLOW_ITEM_TYPE_END,
97 };
98 enum rte_flow_item_type pattern_eth_vlan_ipv4[] = {
99         RTE_FLOW_ITEM_TYPE_ETH,
100         RTE_FLOW_ITEM_TYPE_VLAN,
101         RTE_FLOW_ITEM_TYPE_IPV4,
102         RTE_FLOW_ITEM_TYPE_END,
103 };
104 enum rte_flow_item_type pattern_eth_qinq_ipv4[] = {
105         RTE_FLOW_ITEM_TYPE_ETH,
106         RTE_FLOW_ITEM_TYPE_VLAN,
107         RTE_FLOW_ITEM_TYPE_VLAN,
108         RTE_FLOW_ITEM_TYPE_IPV4,
109         RTE_FLOW_ITEM_TYPE_END,
110 };
111 enum rte_flow_item_type pattern_eth_ipv4_udp[] = {
112         RTE_FLOW_ITEM_TYPE_ETH,
113         RTE_FLOW_ITEM_TYPE_IPV4,
114         RTE_FLOW_ITEM_TYPE_UDP,
115         RTE_FLOW_ITEM_TYPE_END,
116 };
117 enum rte_flow_item_type pattern_eth_vlan_ipv4_udp[] = {
118         RTE_FLOW_ITEM_TYPE_ETH,
119         RTE_FLOW_ITEM_TYPE_VLAN,
120         RTE_FLOW_ITEM_TYPE_IPV4,
121         RTE_FLOW_ITEM_TYPE_UDP,
122         RTE_FLOW_ITEM_TYPE_END,
123 };
124 enum rte_flow_item_type pattern_eth_qinq_ipv4_udp[] = {
125         RTE_FLOW_ITEM_TYPE_ETH,
126         RTE_FLOW_ITEM_TYPE_VLAN,
127         RTE_FLOW_ITEM_TYPE_VLAN,
128         RTE_FLOW_ITEM_TYPE_IPV4,
129         RTE_FLOW_ITEM_TYPE_UDP,
130         RTE_FLOW_ITEM_TYPE_END,
131 };
132 enum rte_flow_item_type pattern_eth_ipv4_tcp[] = {
133         RTE_FLOW_ITEM_TYPE_ETH,
134         RTE_FLOW_ITEM_TYPE_IPV4,
135         RTE_FLOW_ITEM_TYPE_TCP,
136         RTE_FLOW_ITEM_TYPE_END,
137 };
138 enum rte_flow_item_type pattern_eth_vlan_ipv4_tcp[] = {
139         RTE_FLOW_ITEM_TYPE_ETH,
140         RTE_FLOW_ITEM_TYPE_VLAN,
141         RTE_FLOW_ITEM_TYPE_IPV4,
142         RTE_FLOW_ITEM_TYPE_TCP,
143         RTE_FLOW_ITEM_TYPE_END,
144 };
145 enum rte_flow_item_type pattern_eth_qinq_ipv4_tcp[] = {
146         RTE_FLOW_ITEM_TYPE_ETH,
147         RTE_FLOW_ITEM_TYPE_VLAN,
148         RTE_FLOW_ITEM_TYPE_VLAN,
149         RTE_FLOW_ITEM_TYPE_IPV4,
150         RTE_FLOW_ITEM_TYPE_TCP,
151         RTE_FLOW_ITEM_TYPE_END,
152 };
153 enum rte_flow_item_type pattern_eth_ipv4_sctp[] = {
154         RTE_FLOW_ITEM_TYPE_ETH,
155         RTE_FLOW_ITEM_TYPE_IPV4,
156         RTE_FLOW_ITEM_TYPE_SCTP,
157         RTE_FLOW_ITEM_TYPE_END,
158 };
159 enum rte_flow_item_type pattern_eth_vlan_ipv4_sctp[] = {
160         RTE_FLOW_ITEM_TYPE_ETH,
161         RTE_FLOW_ITEM_TYPE_VLAN,
162         RTE_FLOW_ITEM_TYPE_IPV4,
163         RTE_FLOW_ITEM_TYPE_SCTP,
164         RTE_FLOW_ITEM_TYPE_END,
165 };
166 enum rte_flow_item_type pattern_eth_qinq_ipv4_sctp[] = {
167         RTE_FLOW_ITEM_TYPE_ETH,
168         RTE_FLOW_ITEM_TYPE_VLAN,
169         RTE_FLOW_ITEM_TYPE_VLAN,
170         RTE_FLOW_ITEM_TYPE_IPV4,
171         RTE_FLOW_ITEM_TYPE_SCTP,
172         RTE_FLOW_ITEM_TYPE_END,
173 };
174 enum rte_flow_item_type pattern_eth_ipv4_icmp[] = {
175         RTE_FLOW_ITEM_TYPE_ETH,
176         RTE_FLOW_ITEM_TYPE_IPV4,
177         RTE_FLOW_ITEM_TYPE_ICMP,
178         RTE_FLOW_ITEM_TYPE_END,
179 };
180 enum rte_flow_item_type pattern_eth_vlan_ipv4_icmp[] = {
181         RTE_FLOW_ITEM_TYPE_ETH,
182         RTE_FLOW_ITEM_TYPE_VLAN,
183         RTE_FLOW_ITEM_TYPE_IPV4,
184         RTE_FLOW_ITEM_TYPE_ICMP,
185         RTE_FLOW_ITEM_TYPE_END,
186 };
187 enum rte_flow_item_type pattern_eth_qinq_ipv4_icmp[] = {
188         RTE_FLOW_ITEM_TYPE_ETH,
189         RTE_FLOW_ITEM_TYPE_VLAN,
190         RTE_FLOW_ITEM_TYPE_VLAN,
191         RTE_FLOW_ITEM_TYPE_IPV4,
192         RTE_FLOW_ITEM_TYPE_ICMP,
193         RTE_FLOW_ITEM_TYPE_END,
194 };
195
196 /* non-tunnel IPv6 */
197 enum rte_flow_item_type pattern_eth_ipv6[] = {
198         RTE_FLOW_ITEM_TYPE_ETH,
199         RTE_FLOW_ITEM_TYPE_IPV6,
200         RTE_FLOW_ITEM_TYPE_END,
201 };
202 enum rte_flow_item_type pattern_eth_vlan_ipv6[] = {
203         RTE_FLOW_ITEM_TYPE_ETH,
204         RTE_FLOW_ITEM_TYPE_VLAN,
205         RTE_FLOW_ITEM_TYPE_IPV6,
206         RTE_FLOW_ITEM_TYPE_END,
207 };
208 enum rte_flow_item_type pattern_eth_qinq_ipv6[] = {
209         RTE_FLOW_ITEM_TYPE_ETH,
210         RTE_FLOW_ITEM_TYPE_VLAN,
211         RTE_FLOW_ITEM_TYPE_VLAN,
212         RTE_FLOW_ITEM_TYPE_IPV6,
213         RTE_FLOW_ITEM_TYPE_END,
214 };
215 enum rte_flow_item_type pattern_eth_ipv6_udp[] = {
216         RTE_FLOW_ITEM_TYPE_ETH,
217         RTE_FLOW_ITEM_TYPE_IPV6,
218         RTE_FLOW_ITEM_TYPE_UDP,
219         RTE_FLOW_ITEM_TYPE_END,
220 };
221 enum rte_flow_item_type pattern_eth_vlan_ipv6_udp[] = {
222         RTE_FLOW_ITEM_TYPE_ETH,
223         RTE_FLOW_ITEM_TYPE_VLAN,
224         RTE_FLOW_ITEM_TYPE_IPV6,
225         RTE_FLOW_ITEM_TYPE_UDP,
226         RTE_FLOW_ITEM_TYPE_END,
227 };
228 enum rte_flow_item_type pattern_eth_qinq_ipv6_udp[] = {
229         RTE_FLOW_ITEM_TYPE_ETH,
230         RTE_FLOW_ITEM_TYPE_VLAN,
231         RTE_FLOW_ITEM_TYPE_VLAN,
232         RTE_FLOW_ITEM_TYPE_IPV6,
233         RTE_FLOW_ITEM_TYPE_UDP,
234         RTE_FLOW_ITEM_TYPE_END,
235 };
236 enum rte_flow_item_type pattern_eth_ipv6_tcp[] = {
237         RTE_FLOW_ITEM_TYPE_ETH,
238         RTE_FLOW_ITEM_TYPE_IPV6,
239         RTE_FLOW_ITEM_TYPE_TCP,
240         RTE_FLOW_ITEM_TYPE_END,
241 };
242 enum rte_flow_item_type pattern_eth_vlan_ipv6_tcp[] = {
243         RTE_FLOW_ITEM_TYPE_ETH,
244         RTE_FLOW_ITEM_TYPE_VLAN,
245         RTE_FLOW_ITEM_TYPE_IPV6,
246         RTE_FLOW_ITEM_TYPE_TCP,
247         RTE_FLOW_ITEM_TYPE_END,
248 };
249 enum rte_flow_item_type pattern_eth_qinq_ipv6_tcp[] = {
250         RTE_FLOW_ITEM_TYPE_ETH,
251         RTE_FLOW_ITEM_TYPE_VLAN,
252         RTE_FLOW_ITEM_TYPE_VLAN,
253         RTE_FLOW_ITEM_TYPE_IPV6,
254         RTE_FLOW_ITEM_TYPE_TCP,
255         RTE_FLOW_ITEM_TYPE_END,
256 };
257 enum rte_flow_item_type pattern_eth_ipv6_sctp[] = {
258         RTE_FLOW_ITEM_TYPE_ETH,
259         RTE_FLOW_ITEM_TYPE_IPV6,
260         RTE_FLOW_ITEM_TYPE_SCTP,
261         RTE_FLOW_ITEM_TYPE_END,
262 };
263 enum rte_flow_item_type pattern_eth_vlan_ipv6_sctp[] = {
264         RTE_FLOW_ITEM_TYPE_ETH,
265         RTE_FLOW_ITEM_TYPE_VLAN,
266         RTE_FLOW_ITEM_TYPE_IPV6,
267         RTE_FLOW_ITEM_TYPE_SCTP,
268         RTE_FLOW_ITEM_TYPE_END,
269 };
270 enum rte_flow_item_type pattern_eth_qinq_ipv6_sctp[] = {
271         RTE_FLOW_ITEM_TYPE_ETH,
272         RTE_FLOW_ITEM_TYPE_VLAN,
273         RTE_FLOW_ITEM_TYPE_VLAN,
274         RTE_FLOW_ITEM_TYPE_IPV6,
275         RTE_FLOW_ITEM_TYPE_SCTP,
276         RTE_FLOW_ITEM_TYPE_END,
277 };
278 enum rte_flow_item_type pattern_eth_ipv6_icmp6[] = {
279         RTE_FLOW_ITEM_TYPE_ETH,
280         RTE_FLOW_ITEM_TYPE_IPV6,
281         RTE_FLOW_ITEM_TYPE_ICMP6,
282         RTE_FLOW_ITEM_TYPE_END,
283 };
284 enum rte_flow_item_type pattern_eth_vlan_ipv6_icmp6[] = {
285         RTE_FLOW_ITEM_TYPE_ETH,
286         RTE_FLOW_ITEM_TYPE_VLAN,
287         RTE_FLOW_ITEM_TYPE_IPV6,
288         RTE_FLOW_ITEM_TYPE_ICMP6,
289         RTE_FLOW_ITEM_TYPE_END,
290 };
291 enum rte_flow_item_type pattern_eth_qinq_ipv6_icmp6[] = {
292         RTE_FLOW_ITEM_TYPE_ETH,
293         RTE_FLOW_ITEM_TYPE_VLAN,
294         RTE_FLOW_ITEM_TYPE_VLAN,
295         RTE_FLOW_ITEM_TYPE_IPV6,
296         RTE_FLOW_ITEM_TYPE_ICMP6,
297         RTE_FLOW_ITEM_TYPE_END,
298 };
299
300 /* IPv4 VXLAN IPv4 */
301 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv4[] = {
302         RTE_FLOW_ITEM_TYPE_ETH,
303         RTE_FLOW_ITEM_TYPE_IPV4,
304         RTE_FLOW_ITEM_TYPE_UDP,
305         RTE_FLOW_ITEM_TYPE_VXLAN,
306         RTE_FLOW_ITEM_TYPE_IPV4,
307         RTE_FLOW_ITEM_TYPE_END,
308 };
309 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv4_udp[] = {
310         RTE_FLOW_ITEM_TYPE_ETH,
311         RTE_FLOW_ITEM_TYPE_IPV4,
312         RTE_FLOW_ITEM_TYPE_UDP,
313         RTE_FLOW_ITEM_TYPE_VXLAN,
314         RTE_FLOW_ITEM_TYPE_IPV4,
315         RTE_FLOW_ITEM_TYPE_UDP,
316         RTE_FLOW_ITEM_TYPE_END,
317 };
318 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv4_tcp[] = {
319         RTE_FLOW_ITEM_TYPE_ETH,
320         RTE_FLOW_ITEM_TYPE_IPV4,
321         RTE_FLOW_ITEM_TYPE_UDP,
322         RTE_FLOW_ITEM_TYPE_VXLAN,
323         RTE_FLOW_ITEM_TYPE_IPV4,
324         RTE_FLOW_ITEM_TYPE_TCP,
325         RTE_FLOW_ITEM_TYPE_END,
326 };
327 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv4_sctp[] = {
328         RTE_FLOW_ITEM_TYPE_ETH,
329         RTE_FLOW_ITEM_TYPE_IPV4,
330         RTE_FLOW_ITEM_TYPE_UDP,
331         RTE_FLOW_ITEM_TYPE_VXLAN,
332         RTE_FLOW_ITEM_TYPE_IPV4,
333         RTE_FLOW_ITEM_TYPE_SCTP,
334         RTE_FLOW_ITEM_TYPE_END,
335 };
336 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv4_icmp[] = {
337         RTE_FLOW_ITEM_TYPE_ETH,
338         RTE_FLOW_ITEM_TYPE_IPV4,
339         RTE_FLOW_ITEM_TYPE_UDP,
340         RTE_FLOW_ITEM_TYPE_VXLAN,
341         RTE_FLOW_ITEM_TYPE_IPV4,
342         RTE_FLOW_ITEM_TYPE_ICMP,
343         RTE_FLOW_ITEM_TYPE_END,
344 };
345
346 /* IPv4 VXLAN MAC IPv4 */
347 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv4[] = {
348         RTE_FLOW_ITEM_TYPE_ETH,
349         RTE_FLOW_ITEM_TYPE_IPV4,
350         RTE_FLOW_ITEM_TYPE_UDP,
351         RTE_FLOW_ITEM_TYPE_VXLAN,
352         RTE_FLOW_ITEM_TYPE_ETH,
353         RTE_FLOW_ITEM_TYPE_IPV4,
354         RTE_FLOW_ITEM_TYPE_END,
355 };
356 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv4_udp[] = {
357         RTE_FLOW_ITEM_TYPE_ETH,
358         RTE_FLOW_ITEM_TYPE_IPV4,
359         RTE_FLOW_ITEM_TYPE_UDP,
360         RTE_FLOW_ITEM_TYPE_VXLAN,
361         RTE_FLOW_ITEM_TYPE_ETH,
362         RTE_FLOW_ITEM_TYPE_IPV4,
363         RTE_FLOW_ITEM_TYPE_UDP,
364         RTE_FLOW_ITEM_TYPE_END,
365 };
366 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv4_tcp[] = {
367         RTE_FLOW_ITEM_TYPE_ETH,
368         RTE_FLOW_ITEM_TYPE_IPV4,
369         RTE_FLOW_ITEM_TYPE_UDP,
370         RTE_FLOW_ITEM_TYPE_VXLAN,
371         RTE_FLOW_ITEM_TYPE_ETH,
372         RTE_FLOW_ITEM_TYPE_IPV4,
373         RTE_FLOW_ITEM_TYPE_TCP,
374         RTE_FLOW_ITEM_TYPE_END,
375 };
376 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv4_sctp[] = {
377         RTE_FLOW_ITEM_TYPE_ETH,
378         RTE_FLOW_ITEM_TYPE_IPV4,
379         RTE_FLOW_ITEM_TYPE_UDP,
380         RTE_FLOW_ITEM_TYPE_VXLAN,
381         RTE_FLOW_ITEM_TYPE_ETH,
382         RTE_FLOW_ITEM_TYPE_IPV4,
383         RTE_FLOW_ITEM_TYPE_SCTP,
384         RTE_FLOW_ITEM_TYPE_END,
385 };
386 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv4_icmp[] = {
387         RTE_FLOW_ITEM_TYPE_ETH,
388         RTE_FLOW_ITEM_TYPE_IPV4,
389         RTE_FLOW_ITEM_TYPE_UDP,
390         RTE_FLOW_ITEM_TYPE_VXLAN,
391         RTE_FLOW_ITEM_TYPE_ETH,
392         RTE_FLOW_ITEM_TYPE_IPV4,
393         RTE_FLOW_ITEM_TYPE_ICMP,
394         RTE_FLOW_ITEM_TYPE_END,
395 };
396
397 /* IPv6 VXLAN IPv4 */
398 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv4[] = {
399         RTE_FLOW_ITEM_TYPE_ETH,
400         RTE_FLOW_ITEM_TYPE_IPV6,
401         RTE_FLOW_ITEM_TYPE_UDP,
402         RTE_FLOW_ITEM_TYPE_VXLAN,
403         RTE_FLOW_ITEM_TYPE_IPV4,
404         RTE_FLOW_ITEM_TYPE_END,
405 };
406 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv4_tcp[] = {
407         RTE_FLOW_ITEM_TYPE_ETH,
408         RTE_FLOW_ITEM_TYPE_IPV6,
409         RTE_FLOW_ITEM_TYPE_UDP,
410         RTE_FLOW_ITEM_TYPE_VXLAN,
411         RTE_FLOW_ITEM_TYPE_IPV4,
412         RTE_FLOW_ITEM_TYPE_TCP,
413         RTE_FLOW_ITEM_TYPE_END,
414 };
415 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv4_udp[] = {
416         RTE_FLOW_ITEM_TYPE_ETH,
417         RTE_FLOW_ITEM_TYPE_IPV6,
418         RTE_FLOW_ITEM_TYPE_UDP,
419         RTE_FLOW_ITEM_TYPE_VXLAN,
420         RTE_FLOW_ITEM_TYPE_IPV4,
421         RTE_FLOW_ITEM_TYPE_UDP,
422         RTE_FLOW_ITEM_TYPE_END,
423 };
424 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv4_sctp[] = {
425         RTE_FLOW_ITEM_TYPE_ETH,
426         RTE_FLOW_ITEM_TYPE_IPV6,
427         RTE_FLOW_ITEM_TYPE_UDP,
428         RTE_FLOW_ITEM_TYPE_VXLAN,
429         RTE_FLOW_ITEM_TYPE_IPV4,
430         RTE_FLOW_ITEM_TYPE_SCTP,
431         RTE_FLOW_ITEM_TYPE_END,
432 };
433 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv4_icmp[] = {
434         RTE_FLOW_ITEM_TYPE_ETH,
435         RTE_FLOW_ITEM_TYPE_IPV6,
436         RTE_FLOW_ITEM_TYPE_UDP,
437         RTE_FLOW_ITEM_TYPE_VXLAN,
438         RTE_FLOW_ITEM_TYPE_IPV4,
439         RTE_FLOW_ITEM_TYPE_ICMP,
440         RTE_FLOW_ITEM_TYPE_END,
441 };
442
443 /* IPv6 VXLAN MAC IPv4 */
444 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv4[] = {
445         RTE_FLOW_ITEM_TYPE_ETH,
446         RTE_FLOW_ITEM_TYPE_IPV6,
447         RTE_FLOW_ITEM_TYPE_UDP,
448         RTE_FLOW_ITEM_TYPE_VXLAN,
449         RTE_FLOW_ITEM_TYPE_ETH,
450         RTE_FLOW_ITEM_TYPE_IPV4,
451         RTE_FLOW_ITEM_TYPE_END,
452 };
453 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv4_tcp[] = {
454         RTE_FLOW_ITEM_TYPE_ETH,
455         RTE_FLOW_ITEM_TYPE_IPV6,
456         RTE_FLOW_ITEM_TYPE_UDP,
457         RTE_FLOW_ITEM_TYPE_VXLAN,
458         RTE_FLOW_ITEM_TYPE_ETH,
459         RTE_FLOW_ITEM_TYPE_IPV4,
460         RTE_FLOW_ITEM_TYPE_TCP,
461         RTE_FLOW_ITEM_TYPE_END,
462 };
463 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv4_udp[] = {
464         RTE_FLOW_ITEM_TYPE_ETH,
465         RTE_FLOW_ITEM_TYPE_IPV6,
466         RTE_FLOW_ITEM_TYPE_UDP,
467         RTE_FLOW_ITEM_TYPE_VXLAN,
468         RTE_FLOW_ITEM_TYPE_ETH,
469         RTE_FLOW_ITEM_TYPE_IPV4,
470         RTE_FLOW_ITEM_TYPE_UDP,
471         RTE_FLOW_ITEM_TYPE_END,
472 };
473 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv4_sctp[] = {
474         RTE_FLOW_ITEM_TYPE_ETH,
475         RTE_FLOW_ITEM_TYPE_IPV6,
476         RTE_FLOW_ITEM_TYPE_UDP,
477         RTE_FLOW_ITEM_TYPE_VXLAN,
478         RTE_FLOW_ITEM_TYPE_ETH,
479         RTE_FLOW_ITEM_TYPE_IPV4,
480         RTE_FLOW_ITEM_TYPE_SCTP,
481         RTE_FLOW_ITEM_TYPE_END,
482 };
483 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv4_icmp[] = {
484         RTE_FLOW_ITEM_TYPE_ETH,
485         RTE_FLOW_ITEM_TYPE_IPV6,
486         RTE_FLOW_ITEM_TYPE_UDP,
487         RTE_FLOW_ITEM_TYPE_VXLAN,
488         RTE_FLOW_ITEM_TYPE_ETH,
489         RTE_FLOW_ITEM_TYPE_IPV4,
490         RTE_FLOW_ITEM_TYPE_ICMP,
491         RTE_FLOW_ITEM_TYPE_END,
492 };
493
494 /* IPv4 VXLAN IPv6 */
495 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv6[] = {
496         RTE_FLOW_ITEM_TYPE_ETH,
497         RTE_FLOW_ITEM_TYPE_IPV4,
498         RTE_FLOW_ITEM_TYPE_UDP,
499         RTE_FLOW_ITEM_TYPE_VXLAN,
500         RTE_FLOW_ITEM_TYPE_IPV6,
501         RTE_FLOW_ITEM_TYPE_END,
502 };
503 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv6_udp[] = {
504         RTE_FLOW_ITEM_TYPE_ETH,
505         RTE_FLOW_ITEM_TYPE_IPV4,
506         RTE_FLOW_ITEM_TYPE_UDP,
507         RTE_FLOW_ITEM_TYPE_VXLAN,
508         RTE_FLOW_ITEM_TYPE_IPV6,
509         RTE_FLOW_ITEM_TYPE_UDP,
510         RTE_FLOW_ITEM_TYPE_END,
511 };
512 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv6_tcp[] = {
513         RTE_FLOW_ITEM_TYPE_ETH,
514         RTE_FLOW_ITEM_TYPE_IPV4,
515         RTE_FLOW_ITEM_TYPE_UDP,
516         RTE_FLOW_ITEM_TYPE_VXLAN,
517         RTE_FLOW_ITEM_TYPE_IPV6,
518         RTE_FLOW_ITEM_TYPE_TCP,
519         RTE_FLOW_ITEM_TYPE_END,
520 };
521 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv6_sctp[] = {
522         RTE_FLOW_ITEM_TYPE_ETH,
523         RTE_FLOW_ITEM_TYPE_IPV4,
524         RTE_FLOW_ITEM_TYPE_UDP,
525         RTE_FLOW_ITEM_TYPE_VXLAN,
526         RTE_FLOW_ITEM_TYPE_IPV6,
527         RTE_FLOW_ITEM_TYPE_SCTP,
528         RTE_FLOW_ITEM_TYPE_END,
529 };
530 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_ipv6_icmp6[] = {
531         RTE_FLOW_ITEM_TYPE_ETH,
532         RTE_FLOW_ITEM_TYPE_IPV4,
533         RTE_FLOW_ITEM_TYPE_UDP,
534         RTE_FLOW_ITEM_TYPE_VXLAN,
535         RTE_FLOW_ITEM_TYPE_IPV6,
536         RTE_FLOW_ITEM_TYPE_ICMP6,
537         RTE_FLOW_ITEM_TYPE_END,
538 };
539
540 /* IPv4 VXLAN MAC IPv6 */
541 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv6[] = {
542         RTE_FLOW_ITEM_TYPE_ETH,
543         RTE_FLOW_ITEM_TYPE_IPV4,
544         RTE_FLOW_ITEM_TYPE_UDP,
545         RTE_FLOW_ITEM_TYPE_VXLAN,
546         RTE_FLOW_ITEM_TYPE_ETH,
547         RTE_FLOW_ITEM_TYPE_IPV6,
548         RTE_FLOW_ITEM_TYPE_END,
549 };
550 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv6_udp[] = {
551         RTE_FLOW_ITEM_TYPE_ETH,
552         RTE_FLOW_ITEM_TYPE_IPV4,
553         RTE_FLOW_ITEM_TYPE_UDP,
554         RTE_FLOW_ITEM_TYPE_VXLAN,
555         RTE_FLOW_ITEM_TYPE_ETH,
556         RTE_FLOW_ITEM_TYPE_IPV6,
557         RTE_FLOW_ITEM_TYPE_UDP,
558         RTE_FLOW_ITEM_TYPE_END,
559 };
560 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv6_tcp[] = {
561         RTE_FLOW_ITEM_TYPE_ETH,
562         RTE_FLOW_ITEM_TYPE_IPV4,
563         RTE_FLOW_ITEM_TYPE_UDP,
564         RTE_FLOW_ITEM_TYPE_VXLAN,
565         RTE_FLOW_ITEM_TYPE_ETH,
566         RTE_FLOW_ITEM_TYPE_IPV6,
567         RTE_FLOW_ITEM_TYPE_TCP,
568         RTE_FLOW_ITEM_TYPE_END,
569 };
570 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv6_sctp[] = {
571         RTE_FLOW_ITEM_TYPE_ETH,
572         RTE_FLOW_ITEM_TYPE_IPV4,
573         RTE_FLOW_ITEM_TYPE_UDP,
574         RTE_FLOW_ITEM_TYPE_VXLAN,
575         RTE_FLOW_ITEM_TYPE_ETH,
576         RTE_FLOW_ITEM_TYPE_IPV6,
577         RTE_FLOW_ITEM_TYPE_SCTP,
578         RTE_FLOW_ITEM_TYPE_END,
579 };
580 enum rte_flow_item_type pattern_eth_ipv4_udp_vxlan_eth_ipv6_icmp6[] = {
581         RTE_FLOW_ITEM_TYPE_ETH,
582         RTE_FLOW_ITEM_TYPE_IPV4,
583         RTE_FLOW_ITEM_TYPE_UDP,
584         RTE_FLOW_ITEM_TYPE_VXLAN,
585         RTE_FLOW_ITEM_TYPE_ETH,
586         RTE_FLOW_ITEM_TYPE_IPV6,
587         RTE_FLOW_ITEM_TYPE_ICMP6,
588         RTE_FLOW_ITEM_TYPE_END,
589 };
590
591 /* IPv6 VXLAN IPv6 */
592 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv6[] = {
593         RTE_FLOW_ITEM_TYPE_ETH,
594         RTE_FLOW_ITEM_TYPE_IPV6,
595         RTE_FLOW_ITEM_TYPE_UDP,
596         RTE_FLOW_ITEM_TYPE_VXLAN,
597         RTE_FLOW_ITEM_TYPE_IPV6,
598         RTE_FLOW_ITEM_TYPE_END,
599 };
600 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv6_tcp[] = {
601         RTE_FLOW_ITEM_TYPE_ETH,
602         RTE_FLOW_ITEM_TYPE_IPV6,
603         RTE_FLOW_ITEM_TYPE_UDP,
604         RTE_FLOW_ITEM_TYPE_VXLAN,
605         RTE_FLOW_ITEM_TYPE_IPV6,
606         RTE_FLOW_ITEM_TYPE_TCP,
607         RTE_FLOW_ITEM_TYPE_END,
608 };
609 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv6_udp[] = {
610         RTE_FLOW_ITEM_TYPE_ETH,
611         RTE_FLOW_ITEM_TYPE_IPV6,
612         RTE_FLOW_ITEM_TYPE_UDP,
613         RTE_FLOW_ITEM_TYPE_VXLAN,
614         RTE_FLOW_ITEM_TYPE_IPV6,
615         RTE_FLOW_ITEM_TYPE_UDP,
616         RTE_FLOW_ITEM_TYPE_END,
617 };
618 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv6_sctp[] = {
619         RTE_FLOW_ITEM_TYPE_ETH,
620         RTE_FLOW_ITEM_TYPE_IPV6,
621         RTE_FLOW_ITEM_TYPE_UDP,
622         RTE_FLOW_ITEM_TYPE_VXLAN,
623         RTE_FLOW_ITEM_TYPE_IPV6,
624         RTE_FLOW_ITEM_TYPE_SCTP,
625         RTE_FLOW_ITEM_TYPE_END,
626 };
627 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_ipv6_icmp6[] = {
628         RTE_FLOW_ITEM_TYPE_ETH,
629         RTE_FLOW_ITEM_TYPE_IPV6,
630         RTE_FLOW_ITEM_TYPE_UDP,
631         RTE_FLOW_ITEM_TYPE_VXLAN,
632         RTE_FLOW_ITEM_TYPE_IPV6,
633         RTE_FLOW_ITEM_TYPE_ICMP6,
634         RTE_FLOW_ITEM_TYPE_END,
635 };
636
637 /* IPv6 VXLAN MAC IPv6 */
638 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv6[] = {
639         RTE_FLOW_ITEM_TYPE_ETH,
640         RTE_FLOW_ITEM_TYPE_IPV6,
641         RTE_FLOW_ITEM_TYPE_UDP,
642         RTE_FLOW_ITEM_TYPE_VXLAN,
643         RTE_FLOW_ITEM_TYPE_ETH,
644         RTE_FLOW_ITEM_TYPE_IPV6,
645         RTE_FLOW_ITEM_TYPE_END,
646 };
647 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv6_tcp[] = {
648         RTE_FLOW_ITEM_TYPE_ETH,
649         RTE_FLOW_ITEM_TYPE_IPV6,
650         RTE_FLOW_ITEM_TYPE_UDP,
651         RTE_FLOW_ITEM_TYPE_VXLAN,
652         RTE_FLOW_ITEM_TYPE_ETH,
653         RTE_FLOW_ITEM_TYPE_IPV6,
654         RTE_FLOW_ITEM_TYPE_TCP,
655         RTE_FLOW_ITEM_TYPE_END,
656 };
657 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv6_udp[] = {
658         RTE_FLOW_ITEM_TYPE_ETH,
659         RTE_FLOW_ITEM_TYPE_IPV6,
660         RTE_FLOW_ITEM_TYPE_UDP,
661         RTE_FLOW_ITEM_TYPE_VXLAN,
662         RTE_FLOW_ITEM_TYPE_ETH,
663         RTE_FLOW_ITEM_TYPE_IPV6,
664         RTE_FLOW_ITEM_TYPE_UDP,
665         RTE_FLOW_ITEM_TYPE_END,
666 };
667 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv6_sctp[] = {
668         RTE_FLOW_ITEM_TYPE_ETH,
669         RTE_FLOW_ITEM_TYPE_IPV6,
670         RTE_FLOW_ITEM_TYPE_UDP,
671         RTE_FLOW_ITEM_TYPE_VXLAN,
672         RTE_FLOW_ITEM_TYPE_ETH,
673         RTE_FLOW_ITEM_TYPE_IPV6,
674         RTE_FLOW_ITEM_TYPE_SCTP,
675         RTE_FLOW_ITEM_TYPE_END,
676 };
677 enum rte_flow_item_type pattern_eth_ipv6_udp_vxlan_eth_ipv6_icmp6[] = {
678         RTE_FLOW_ITEM_TYPE_ETH,
679         RTE_FLOW_ITEM_TYPE_IPV6,
680         RTE_FLOW_ITEM_TYPE_UDP,
681         RTE_FLOW_ITEM_TYPE_VXLAN,
682         RTE_FLOW_ITEM_TYPE_ETH,
683         RTE_FLOW_ITEM_TYPE_IPV6,
684         RTE_FLOW_ITEM_TYPE_ICMP6,
685         RTE_FLOW_ITEM_TYPE_END,
686 };
687
688 /* IPv4 NVGRE IPv4 */
689 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv4[] = {
690         RTE_FLOW_ITEM_TYPE_ETH,
691         RTE_FLOW_ITEM_TYPE_IPV4,
692         RTE_FLOW_ITEM_TYPE_NVGRE,
693         RTE_FLOW_ITEM_TYPE_IPV4,
694         RTE_FLOW_ITEM_TYPE_END,
695 };
696 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv4_udp[] = {
697         RTE_FLOW_ITEM_TYPE_ETH,
698         RTE_FLOW_ITEM_TYPE_IPV4,
699         RTE_FLOW_ITEM_TYPE_NVGRE,
700         RTE_FLOW_ITEM_TYPE_IPV4,
701         RTE_FLOW_ITEM_TYPE_UDP,
702         RTE_FLOW_ITEM_TYPE_END,
703 };
704 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv4_tcp[] = {
705         RTE_FLOW_ITEM_TYPE_ETH,
706         RTE_FLOW_ITEM_TYPE_IPV4,
707         RTE_FLOW_ITEM_TYPE_NVGRE,
708         RTE_FLOW_ITEM_TYPE_IPV4,
709         RTE_FLOW_ITEM_TYPE_TCP,
710         RTE_FLOW_ITEM_TYPE_END,
711 };
712 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv4_sctp[] = {
713         RTE_FLOW_ITEM_TYPE_ETH,
714         RTE_FLOW_ITEM_TYPE_IPV4,
715         RTE_FLOW_ITEM_TYPE_NVGRE,
716         RTE_FLOW_ITEM_TYPE_IPV4,
717         RTE_FLOW_ITEM_TYPE_SCTP,
718         RTE_FLOW_ITEM_TYPE_END,
719 };
720 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv4_icmp[] = {
721         RTE_FLOW_ITEM_TYPE_ETH,
722         RTE_FLOW_ITEM_TYPE_IPV4,
723         RTE_FLOW_ITEM_TYPE_NVGRE,
724         RTE_FLOW_ITEM_TYPE_IPV4,
725         RTE_FLOW_ITEM_TYPE_ICMP,
726         RTE_FLOW_ITEM_TYPE_END,
727 };
728
729 /* IPv4 NVGRE MAC IPv4 */
730 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv4[] = {
731         RTE_FLOW_ITEM_TYPE_ETH,
732         RTE_FLOW_ITEM_TYPE_IPV4,
733         RTE_FLOW_ITEM_TYPE_NVGRE,
734         RTE_FLOW_ITEM_TYPE_ETH,
735         RTE_FLOW_ITEM_TYPE_IPV4,
736         RTE_FLOW_ITEM_TYPE_END,
737 };
738 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv4_udp[] = {
739         RTE_FLOW_ITEM_TYPE_ETH,
740         RTE_FLOW_ITEM_TYPE_IPV4,
741         RTE_FLOW_ITEM_TYPE_NVGRE,
742         RTE_FLOW_ITEM_TYPE_ETH,
743         RTE_FLOW_ITEM_TYPE_IPV4,
744         RTE_FLOW_ITEM_TYPE_UDP,
745         RTE_FLOW_ITEM_TYPE_END,
746 };
747 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv4_tcp[] = {
748         RTE_FLOW_ITEM_TYPE_ETH,
749         RTE_FLOW_ITEM_TYPE_IPV4,
750         RTE_FLOW_ITEM_TYPE_NVGRE,
751         RTE_FLOW_ITEM_TYPE_ETH,
752         RTE_FLOW_ITEM_TYPE_IPV4,
753         RTE_FLOW_ITEM_TYPE_TCP,
754         RTE_FLOW_ITEM_TYPE_END,
755 };
756 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv4_sctp[] = {
757         RTE_FLOW_ITEM_TYPE_ETH,
758         RTE_FLOW_ITEM_TYPE_IPV4,
759         RTE_FLOW_ITEM_TYPE_NVGRE,
760         RTE_FLOW_ITEM_TYPE_ETH,
761         RTE_FLOW_ITEM_TYPE_IPV4,
762         RTE_FLOW_ITEM_TYPE_SCTP,
763         RTE_FLOW_ITEM_TYPE_END,
764 };
765 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv4_icmp[] = {
766         RTE_FLOW_ITEM_TYPE_ETH,
767         RTE_FLOW_ITEM_TYPE_IPV4,
768         RTE_FLOW_ITEM_TYPE_NVGRE,
769         RTE_FLOW_ITEM_TYPE_ETH,
770         RTE_FLOW_ITEM_TYPE_IPV4,
771         RTE_FLOW_ITEM_TYPE_ICMP,
772         RTE_FLOW_ITEM_TYPE_END,
773 };
774
775 /* IPv6 NVGRE IPv4 */
776 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv4[] = {
777         RTE_FLOW_ITEM_TYPE_ETH,
778         RTE_FLOW_ITEM_TYPE_IPV6,
779         RTE_FLOW_ITEM_TYPE_NVGRE,
780         RTE_FLOW_ITEM_TYPE_IPV4,
781         RTE_FLOW_ITEM_TYPE_END,
782 };
783 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv4_tcp[] = {
784         RTE_FLOW_ITEM_TYPE_ETH,
785         RTE_FLOW_ITEM_TYPE_IPV6,
786         RTE_FLOW_ITEM_TYPE_NVGRE,
787         RTE_FLOW_ITEM_TYPE_IPV4,
788         RTE_FLOW_ITEM_TYPE_TCP,
789         RTE_FLOW_ITEM_TYPE_END,
790 };
791 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv4_udp[] = {
792         RTE_FLOW_ITEM_TYPE_ETH,
793         RTE_FLOW_ITEM_TYPE_IPV6,
794         RTE_FLOW_ITEM_TYPE_NVGRE,
795         RTE_FLOW_ITEM_TYPE_IPV4,
796         RTE_FLOW_ITEM_TYPE_UDP,
797         RTE_FLOW_ITEM_TYPE_END,
798 };
799 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv4_sctp[] = {
800         RTE_FLOW_ITEM_TYPE_ETH,
801         RTE_FLOW_ITEM_TYPE_IPV6,
802         RTE_FLOW_ITEM_TYPE_NVGRE,
803         RTE_FLOW_ITEM_TYPE_IPV4,
804         RTE_FLOW_ITEM_TYPE_SCTP,
805         RTE_FLOW_ITEM_TYPE_END,
806 };
807 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv4_icmp[] = {
808         RTE_FLOW_ITEM_TYPE_ETH,
809         RTE_FLOW_ITEM_TYPE_IPV6,
810         RTE_FLOW_ITEM_TYPE_NVGRE,
811         RTE_FLOW_ITEM_TYPE_IPV4,
812         RTE_FLOW_ITEM_TYPE_ICMP,
813         RTE_FLOW_ITEM_TYPE_END,
814 };
815
816 /* IPv6 NVGRE MAC IPv4 */
817 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv4[] = {
818         RTE_FLOW_ITEM_TYPE_ETH,
819         RTE_FLOW_ITEM_TYPE_IPV6,
820         RTE_FLOW_ITEM_TYPE_NVGRE,
821         RTE_FLOW_ITEM_TYPE_ETH,
822         RTE_FLOW_ITEM_TYPE_IPV4,
823         RTE_FLOW_ITEM_TYPE_END,
824 };
825 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv4_tcp[] = {
826         RTE_FLOW_ITEM_TYPE_ETH,
827         RTE_FLOW_ITEM_TYPE_IPV6,
828         RTE_FLOW_ITEM_TYPE_NVGRE,
829         RTE_FLOW_ITEM_TYPE_ETH,
830         RTE_FLOW_ITEM_TYPE_IPV4,
831         RTE_FLOW_ITEM_TYPE_TCP,
832         RTE_FLOW_ITEM_TYPE_END,
833 };
834 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv4_udp[] = {
835         RTE_FLOW_ITEM_TYPE_ETH,
836         RTE_FLOW_ITEM_TYPE_IPV6,
837         RTE_FLOW_ITEM_TYPE_NVGRE,
838         RTE_FLOW_ITEM_TYPE_ETH,
839         RTE_FLOW_ITEM_TYPE_IPV4,
840         RTE_FLOW_ITEM_TYPE_UDP,
841         RTE_FLOW_ITEM_TYPE_END,
842 };
843 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv4_sctp[] = {
844         RTE_FLOW_ITEM_TYPE_ETH,
845         RTE_FLOW_ITEM_TYPE_IPV6,
846         RTE_FLOW_ITEM_TYPE_NVGRE,
847         RTE_FLOW_ITEM_TYPE_ETH,
848         RTE_FLOW_ITEM_TYPE_IPV4,
849         RTE_FLOW_ITEM_TYPE_SCTP,
850         RTE_FLOW_ITEM_TYPE_END,
851 };
852 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv4_icmp[] = {
853         RTE_FLOW_ITEM_TYPE_ETH,
854         RTE_FLOW_ITEM_TYPE_IPV6,
855         RTE_FLOW_ITEM_TYPE_NVGRE,
856         RTE_FLOW_ITEM_TYPE_ETH,
857         RTE_FLOW_ITEM_TYPE_IPV4,
858         RTE_FLOW_ITEM_TYPE_ICMP,
859         RTE_FLOW_ITEM_TYPE_END,
860 };
861
862 /* IPv4 NVGRE IPv6 */
863 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv6[] = {
864         RTE_FLOW_ITEM_TYPE_ETH,
865         RTE_FLOW_ITEM_TYPE_IPV4,
866         RTE_FLOW_ITEM_TYPE_NVGRE,
867         RTE_FLOW_ITEM_TYPE_IPV6,
868         RTE_FLOW_ITEM_TYPE_END,
869 };
870 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv6_udp[] = {
871         RTE_FLOW_ITEM_TYPE_ETH,
872         RTE_FLOW_ITEM_TYPE_IPV4,
873         RTE_FLOW_ITEM_TYPE_NVGRE,
874         RTE_FLOW_ITEM_TYPE_IPV6,
875         RTE_FLOW_ITEM_TYPE_UDP,
876         RTE_FLOW_ITEM_TYPE_END,
877 };
878 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv6_tcp[] = {
879         RTE_FLOW_ITEM_TYPE_ETH,
880         RTE_FLOW_ITEM_TYPE_IPV4,
881         RTE_FLOW_ITEM_TYPE_NVGRE,
882         RTE_FLOW_ITEM_TYPE_IPV6,
883         RTE_FLOW_ITEM_TYPE_TCP,
884         RTE_FLOW_ITEM_TYPE_END,
885 };
886 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv6_sctp[] = {
887         RTE_FLOW_ITEM_TYPE_ETH,
888         RTE_FLOW_ITEM_TYPE_IPV4,
889         RTE_FLOW_ITEM_TYPE_NVGRE,
890         RTE_FLOW_ITEM_TYPE_IPV6,
891         RTE_FLOW_ITEM_TYPE_SCTP,
892         RTE_FLOW_ITEM_TYPE_END,
893 };
894 enum rte_flow_item_type pattern_eth_ipv4_nvgre_ipv6_icmp6[] = {
895         RTE_FLOW_ITEM_TYPE_ETH,
896         RTE_FLOW_ITEM_TYPE_IPV4,
897         RTE_FLOW_ITEM_TYPE_NVGRE,
898         RTE_FLOW_ITEM_TYPE_IPV6,
899         RTE_FLOW_ITEM_TYPE_ICMP6,
900         RTE_FLOW_ITEM_TYPE_END,
901 };
902
903 /* IPv4 NVGRE MAC IPv6 */
904 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv6[] = {
905         RTE_FLOW_ITEM_TYPE_ETH,
906         RTE_FLOW_ITEM_TYPE_IPV4,
907         RTE_FLOW_ITEM_TYPE_NVGRE,
908         RTE_FLOW_ITEM_TYPE_ETH,
909         RTE_FLOW_ITEM_TYPE_IPV6,
910         RTE_FLOW_ITEM_TYPE_END,
911 };
912 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv6_udp[] = {
913         RTE_FLOW_ITEM_TYPE_ETH,
914         RTE_FLOW_ITEM_TYPE_IPV4,
915         RTE_FLOW_ITEM_TYPE_NVGRE,
916         RTE_FLOW_ITEM_TYPE_ETH,
917         RTE_FLOW_ITEM_TYPE_IPV6,
918         RTE_FLOW_ITEM_TYPE_UDP,
919         RTE_FLOW_ITEM_TYPE_END,
920 };
921 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv6_tcp[] = {
922         RTE_FLOW_ITEM_TYPE_ETH,
923         RTE_FLOW_ITEM_TYPE_IPV4,
924         RTE_FLOW_ITEM_TYPE_NVGRE,
925         RTE_FLOW_ITEM_TYPE_ETH,
926         RTE_FLOW_ITEM_TYPE_IPV6,
927         RTE_FLOW_ITEM_TYPE_TCP,
928         RTE_FLOW_ITEM_TYPE_END,
929 };
930 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv6_sctp[] = {
931         RTE_FLOW_ITEM_TYPE_ETH,
932         RTE_FLOW_ITEM_TYPE_IPV4,
933         RTE_FLOW_ITEM_TYPE_NVGRE,
934         RTE_FLOW_ITEM_TYPE_ETH,
935         RTE_FLOW_ITEM_TYPE_IPV6,
936         RTE_FLOW_ITEM_TYPE_SCTP,
937         RTE_FLOW_ITEM_TYPE_END,
938 };
939 enum rte_flow_item_type pattern_eth_ipv4_nvgre_eth_ipv6_icmp6[] = {
940         RTE_FLOW_ITEM_TYPE_ETH,
941         RTE_FLOW_ITEM_TYPE_IPV4,
942         RTE_FLOW_ITEM_TYPE_NVGRE,
943         RTE_FLOW_ITEM_TYPE_ETH,
944         RTE_FLOW_ITEM_TYPE_IPV6,
945         RTE_FLOW_ITEM_TYPE_ICMP6,
946         RTE_FLOW_ITEM_TYPE_END,
947 };
948
949 /* IPv6 NVGRE IPv6 */
950 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv6[] = {
951         RTE_FLOW_ITEM_TYPE_ETH,
952         RTE_FLOW_ITEM_TYPE_IPV6,
953         RTE_FLOW_ITEM_TYPE_NVGRE,
954         RTE_FLOW_ITEM_TYPE_IPV6,
955         RTE_FLOW_ITEM_TYPE_END,
956 };
957 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv6_tcp[] = {
958         RTE_FLOW_ITEM_TYPE_ETH,
959         RTE_FLOW_ITEM_TYPE_IPV6,
960         RTE_FLOW_ITEM_TYPE_NVGRE,
961         RTE_FLOW_ITEM_TYPE_IPV6,
962         RTE_FLOW_ITEM_TYPE_TCP,
963         RTE_FLOW_ITEM_TYPE_END,
964 };
965 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv6_udp[] = {
966         RTE_FLOW_ITEM_TYPE_ETH,
967         RTE_FLOW_ITEM_TYPE_IPV6,
968         RTE_FLOW_ITEM_TYPE_NVGRE,
969         RTE_FLOW_ITEM_TYPE_IPV6,
970         RTE_FLOW_ITEM_TYPE_UDP,
971         RTE_FLOW_ITEM_TYPE_END,
972 };
973 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv6_sctp[] = {
974         RTE_FLOW_ITEM_TYPE_ETH,
975         RTE_FLOW_ITEM_TYPE_IPV6,
976         RTE_FLOW_ITEM_TYPE_NVGRE,
977         RTE_FLOW_ITEM_TYPE_IPV6,
978         RTE_FLOW_ITEM_TYPE_SCTP,
979         RTE_FLOW_ITEM_TYPE_END,
980 };
981 enum rte_flow_item_type pattern_eth_ipv6_nvgre_ipv6_icmp6[] = {
982         RTE_FLOW_ITEM_TYPE_ETH,
983         RTE_FLOW_ITEM_TYPE_IPV6,
984         RTE_FLOW_ITEM_TYPE_NVGRE,
985         RTE_FLOW_ITEM_TYPE_IPV6,
986         RTE_FLOW_ITEM_TYPE_ICMP6,
987         RTE_FLOW_ITEM_TYPE_END,
988 };
989
990 /* IPv6 NVGRE MAC IPv6 */
991 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv6[] = {
992         RTE_FLOW_ITEM_TYPE_ETH,
993         RTE_FLOW_ITEM_TYPE_IPV6,
994         RTE_FLOW_ITEM_TYPE_NVGRE,
995         RTE_FLOW_ITEM_TYPE_ETH,
996         RTE_FLOW_ITEM_TYPE_IPV6,
997         RTE_FLOW_ITEM_TYPE_END,
998 };
999 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv6_tcp[] = {
1000         RTE_FLOW_ITEM_TYPE_ETH,
1001         RTE_FLOW_ITEM_TYPE_IPV6,
1002         RTE_FLOW_ITEM_TYPE_NVGRE,
1003         RTE_FLOW_ITEM_TYPE_ETH,
1004         RTE_FLOW_ITEM_TYPE_IPV6,
1005         RTE_FLOW_ITEM_TYPE_TCP,
1006         RTE_FLOW_ITEM_TYPE_END,
1007 };
1008 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv6_udp[] = {
1009         RTE_FLOW_ITEM_TYPE_ETH,
1010         RTE_FLOW_ITEM_TYPE_IPV6,
1011         RTE_FLOW_ITEM_TYPE_NVGRE,
1012         RTE_FLOW_ITEM_TYPE_ETH,
1013         RTE_FLOW_ITEM_TYPE_IPV6,
1014         RTE_FLOW_ITEM_TYPE_UDP,
1015         RTE_FLOW_ITEM_TYPE_END,
1016 };
1017 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv6_sctp[] = {
1018         RTE_FLOW_ITEM_TYPE_ETH,
1019         RTE_FLOW_ITEM_TYPE_IPV6,
1020         RTE_FLOW_ITEM_TYPE_NVGRE,
1021         RTE_FLOW_ITEM_TYPE_ETH,
1022         RTE_FLOW_ITEM_TYPE_IPV6,
1023         RTE_FLOW_ITEM_TYPE_SCTP,
1024         RTE_FLOW_ITEM_TYPE_END,
1025 };
1026 enum rte_flow_item_type pattern_eth_ipv6_nvgre_eth_ipv6_icmp6[] = {
1027         RTE_FLOW_ITEM_TYPE_ETH,
1028         RTE_FLOW_ITEM_TYPE_IPV6,
1029         RTE_FLOW_ITEM_TYPE_NVGRE,
1030         RTE_FLOW_ITEM_TYPE_ETH,
1031         RTE_FLOW_ITEM_TYPE_IPV6,
1032         RTE_FLOW_ITEM_TYPE_ICMP6,
1033         RTE_FLOW_ITEM_TYPE_END,
1034 };
1035
1036 /* GTPU */
1037 enum rte_flow_item_type pattern_eth_ipv4_gtpu[] = {
1038         RTE_FLOW_ITEM_TYPE_ETH,
1039         RTE_FLOW_ITEM_TYPE_IPV4,
1040         RTE_FLOW_ITEM_TYPE_UDP,
1041         RTE_FLOW_ITEM_TYPE_GTPU,
1042         RTE_FLOW_ITEM_TYPE_END,
1043 };
1044 enum rte_flow_item_type pattern_eth_ipv4_gtpu_ipv4[] = {
1045         RTE_FLOW_ITEM_TYPE_ETH,
1046         RTE_FLOW_ITEM_TYPE_IPV4,
1047         RTE_FLOW_ITEM_TYPE_UDP,
1048         RTE_FLOW_ITEM_TYPE_GTPU,
1049         RTE_FLOW_ITEM_TYPE_IPV4,
1050         RTE_FLOW_ITEM_TYPE_END,
1051 };
1052 enum rte_flow_item_type pattern_eth_ipv4_gtpu_eh[] = {
1053         RTE_FLOW_ITEM_TYPE_ETH,
1054         RTE_FLOW_ITEM_TYPE_IPV4,
1055         RTE_FLOW_ITEM_TYPE_UDP,
1056         RTE_FLOW_ITEM_TYPE_GTPU,
1057         RTE_FLOW_ITEM_TYPE_GTP_PSC,
1058         RTE_FLOW_ITEM_TYPE_END,
1059 };
1060 enum rte_flow_item_type pattern_eth_ipv4_gtpu_eh_ipv4[] = {
1061         RTE_FLOW_ITEM_TYPE_ETH,
1062         RTE_FLOW_ITEM_TYPE_IPV4,
1063         RTE_FLOW_ITEM_TYPE_UDP,
1064         RTE_FLOW_ITEM_TYPE_GTPU,
1065         RTE_FLOW_ITEM_TYPE_GTP_PSC,
1066         RTE_FLOW_ITEM_TYPE_IPV4,
1067         RTE_FLOW_ITEM_TYPE_END,
1068 };
1069 enum rte_flow_item_type pattern_eth_ipv4_gtpu_eh_ipv4_udp[] = {
1070         RTE_FLOW_ITEM_TYPE_ETH,
1071         RTE_FLOW_ITEM_TYPE_IPV4,
1072         RTE_FLOW_ITEM_TYPE_UDP,
1073         RTE_FLOW_ITEM_TYPE_GTPU,
1074         RTE_FLOW_ITEM_TYPE_GTP_PSC,
1075         RTE_FLOW_ITEM_TYPE_IPV4,
1076         RTE_FLOW_ITEM_TYPE_UDP,
1077         RTE_FLOW_ITEM_TYPE_END,
1078 };
1079 enum rte_flow_item_type pattern_eth_ipv4_gtpu_eh_ipv4_tcp[] = {
1080         RTE_FLOW_ITEM_TYPE_ETH,
1081         RTE_FLOW_ITEM_TYPE_IPV4,
1082         RTE_FLOW_ITEM_TYPE_UDP,
1083         RTE_FLOW_ITEM_TYPE_GTPU,
1084         RTE_FLOW_ITEM_TYPE_GTP_PSC,
1085         RTE_FLOW_ITEM_TYPE_IPV4,
1086         RTE_FLOW_ITEM_TYPE_TCP,
1087         RTE_FLOW_ITEM_TYPE_END,
1088
1089 };
1090 enum rte_flow_item_type pattern_eth_ipv4_gtpu_eh_ipv4_icmp[] = {
1091         RTE_FLOW_ITEM_TYPE_ETH,
1092         RTE_FLOW_ITEM_TYPE_IPV4,
1093         RTE_FLOW_ITEM_TYPE_UDP,
1094         RTE_FLOW_ITEM_TYPE_GTPU,
1095         RTE_FLOW_ITEM_TYPE_GTP_PSC,
1096         RTE_FLOW_ITEM_TYPE_IPV4,
1097         RTE_FLOW_ITEM_TYPE_ICMP,
1098         RTE_FLOW_ITEM_TYPE_END,
1099 };
1100
1101 /* PPPoE */
1102 enum rte_flow_item_type pattern_eth_pppoed[] = {
1103         RTE_FLOW_ITEM_TYPE_ETH,
1104         RTE_FLOW_ITEM_TYPE_PPPOED,
1105         RTE_FLOW_ITEM_TYPE_END,
1106 };
1107 enum rte_flow_item_type pattern_eth_vlan_pppoed[] = {
1108         RTE_FLOW_ITEM_TYPE_ETH,
1109         RTE_FLOW_ITEM_TYPE_VLAN,
1110         RTE_FLOW_ITEM_TYPE_PPPOED,
1111         RTE_FLOW_ITEM_TYPE_END,
1112 };
1113 enum rte_flow_item_type pattern_eth_qinq_pppoed[] = {
1114         RTE_FLOW_ITEM_TYPE_ETH,
1115         RTE_FLOW_ITEM_TYPE_VLAN,
1116         RTE_FLOW_ITEM_TYPE_VLAN,
1117         RTE_FLOW_ITEM_TYPE_PPPOED,
1118         RTE_FLOW_ITEM_TYPE_END,
1119 };
1120 enum rte_flow_item_type pattern_eth_pppoes[] = {
1121         RTE_FLOW_ITEM_TYPE_ETH,
1122         RTE_FLOW_ITEM_TYPE_PPPOES,
1123         RTE_FLOW_ITEM_TYPE_END,
1124 };
1125 enum rte_flow_item_type pattern_eth_pppoes_proto[] = {
1126         RTE_FLOW_ITEM_TYPE_ETH,
1127         RTE_FLOW_ITEM_TYPE_PPPOES,
1128         RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID,
1129         RTE_FLOW_ITEM_TYPE_END,
1130 };
1131 enum rte_flow_item_type pattern_eth_vlan_pppoes[] = {
1132         RTE_FLOW_ITEM_TYPE_ETH,
1133         RTE_FLOW_ITEM_TYPE_VLAN,
1134         RTE_FLOW_ITEM_TYPE_PPPOES,
1135         RTE_FLOW_ITEM_TYPE_END,
1136 };
1137 enum rte_flow_item_type pattern_eth_vlan_pppoes_proto[] = {
1138         RTE_FLOW_ITEM_TYPE_ETH,
1139         RTE_FLOW_ITEM_TYPE_VLAN,
1140         RTE_FLOW_ITEM_TYPE_PPPOES,
1141         RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID,
1142         RTE_FLOW_ITEM_TYPE_END,
1143 };
1144 enum rte_flow_item_type pattern_eth_qinq_pppoes[] = {
1145         RTE_FLOW_ITEM_TYPE_ETH,
1146         RTE_FLOW_ITEM_TYPE_VLAN,
1147         RTE_FLOW_ITEM_TYPE_VLAN,
1148         RTE_FLOW_ITEM_TYPE_PPPOES,
1149         RTE_FLOW_ITEM_TYPE_END,
1150 };
1151 enum rte_flow_item_type pattern_eth_pppoes_ipv4[] = {
1152         RTE_FLOW_ITEM_TYPE_ETH,
1153         RTE_FLOW_ITEM_TYPE_PPPOES,
1154         RTE_FLOW_ITEM_TYPE_IPV4,
1155         RTE_FLOW_ITEM_TYPE_END,
1156 };
1157 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv4[] = {
1158         RTE_FLOW_ITEM_TYPE_ETH,
1159         RTE_FLOW_ITEM_TYPE_VLAN,
1160         RTE_FLOW_ITEM_TYPE_PPPOES,
1161         RTE_FLOW_ITEM_TYPE_IPV4,
1162         RTE_FLOW_ITEM_TYPE_END,
1163 };
1164 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv4[] = {
1165         RTE_FLOW_ITEM_TYPE_ETH,
1166         RTE_FLOW_ITEM_TYPE_VLAN,
1167         RTE_FLOW_ITEM_TYPE_VLAN,
1168         RTE_FLOW_ITEM_TYPE_PPPOES,
1169         RTE_FLOW_ITEM_TYPE_IPV4,
1170         RTE_FLOW_ITEM_TYPE_END,
1171 };
1172 enum rte_flow_item_type pattern_eth_pppoes_ipv4_udp[] = {
1173         RTE_FLOW_ITEM_TYPE_ETH,
1174         RTE_FLOW_ITEM_TYPE_PPPOES,
1175         RTE_FLOW_ITEM_TYPE_IPV4,
1176         RTE_FLOW_ITEM_TYPE_UDP,
1177         RTE_FLOW_ITEM_TYPE_END,
1178 };
1179 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv4_udp[] = {
1180         RTE_FLOW_ITEM_TYPE_ETH,
1181         RTE_FLOW_ITEM_TYPE_VLAN,
1182         RTE_FLOW_ITEM_TYPE_PPPOES,
1183         RTE_FLOW_ITEM_TYPE_IPV4,
1184         RTE_FLOW_ITEM_TYPE_UDP,
1185         RTE_FLOW_ITEM_TYPE_END,
1186 };
1187 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv4_udp[] = {
1188         RTE_FLOW_ITEM_TYPE_ETH,
1189         RTE_FLOW_ITEM_TYPE_VLAN,
1190         RTE_FLOW_ITEM_TYPE_VLAN,
1191         RTE_FLOW_ITEM_TYPE_PPPOES,
1192         RTE_FLOW_ITEM_TYPE_IPV4,
1193         RTE_FLOW_ITEM_TYPE_UDP,
1194         RTE_FLOW_ITEM_TYPE_END,
1195 };
1196 enum rte_flow_item_type pattern_eth_pppoes_ipv4_tcp[] = {
1197         RTE_FLOW_ITEM_TYPE_ETH,
1198         RTE_FLOW_ITEM_TYPE_PPPOES,
1199         RTE_FLOW_ITEM_TYPE_IPV4,
1200         RTE_FLOW_ITEM_TYPE_TCP,
1201         RTE_FLOW_ITEM_TYPE_END,
1202 };
1203 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv4_tcp[] = {
1204         RTE_FLOW_ITEM_TYPE_ETH,
1205         RTE_FLOW_ITEM_TYPE_VLAN,
1206         RTE_FLOW_ITEM_TYPE_PPPOES,
1207         RTE_FLOW_ITEM_TYPE_IPV4,
1208         RTE_FLOW_ITEM_TYPE_TCP,
1209         RTE_FLOW_ITEM_TYPE_END,
1210 };
1211 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv4_tcp[] = {
1212         RTE_FLOW_ITEM_TYPE_ETH,
1213         RTE_FLOW_ITEM_TYPE_VLAN,
1214         RTE_FLOW_ITEM_TYPE_VLAN,
1215         RTE_FLOW_ITEM_TYPE_PPPOES,
1216         RTE_FLOW_ITEM_TYPE_IPV4,
1217         RTE_FLOW_ITEM_TYPE_TCP,
1218         RTE_FLOW_ITEM_TYPE_END,
1219 };
1220 enum rte_flow_item_type pattern_eth_pppoes_ipv4_sctp[] = {
1221         RTE_FLOW_ITEM_TYPE_ETH,
1222         RTE_FLOW_ITEM_TYPE_PPPOES,
1223         RTE_FLOW_ITEM_TYPE_IPV4,
1224         RTE_FLOW_ITEM_TYPE_SCTP,
1225         RTE_FLOW_ITEM_TYPE_END,
1226 };
1227 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv4_sctp[] = {
1228         RTE_FLOW_ITEM_TYPE_ETH,
1229         RTE_FLOW_ITEM_TYPE_VLAN,
1230         RTE_FLOW_ITEM_TYPE_PPPOES,
1231         RTE_FLOW_ITEM_TYPE_IPV4,
1232         RTE_FLOW_ITEM_TYPE_SCTP,
1233         RTE_FLOW_ITEM_TYPE_END,
1234 };
1235 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv4_sctp[] = {
1236         RTE_FLOW_ITEM_TYPE_ETH,
1237         RTE_FLOW_ITEM_TYPE_VLAN,
1238         RTE_FLOW_ITEM_TYPE_VLAN,
1239         RTE_FLOW_ITEM_TYPE_PPPOES,
1240         RTE_FLOW_ITEM_TYPE_IPV4,
1241         RTE_FLOW_ITEM_TYPE_SCTP,
1242         RTE_FLOW_ITEM_TYPE_END,
1243 };
1244 enum rte_flow_item_type pattern_eth_pppoes_ipv4_icmp[] = {
1245         RTE_FLOW_ITEM_TYPE_ETH,
1246         RTE_FLOW_ITEM_TYPE_PPPOES,
1247         RTE_FLOW_ITEM_TYPE_IPV4,
1248         RTE_FLOW_ITEM_TYPE_ICMP,
1249         RTE_FLOW_ITEM_TYPE_END,
1250 };
1251 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv4_icmp[] = {
1252         RTE_FLOW_ITEM_TYPE_ETH,
1253         RTE_FLOW_ITEM_TYPE_VLAN,
1254         RTE_FLOW_ITEM_TYPE_PPPOES,
1255         RTE_FLOW_ITEM_TYPE_IPV4,
1256         RTE_FLOW_ITEM_TYPE_ICMP,
1257         RTE_FLOW_ITEM_TYPE_END,
1258 };
1259 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv4_icmp[] = {
1260         RTE_FLOW_ITEM_TYPE_ETH,
1261         RTE_FLOW_ITEM_TYPE_VLAN,
1262         RTE_FLOW_ITEM_TYPE_VLAN,
1263         RTE_FLOW_ITEM_TYPE_PPPOES,
1264         RTE_FLOW_ITEM_TYPE_IPV4,
1265         RTE_FLOW_ITEM_TYPE_ICMP,
1266         RTE_FLOW_ITEM_TYPE_END,
1267 };
1268 enum rte_flow_item_type pattern_eth_pppoes_ipv6[] = {
1269         RTE_FLOW_ITEM_TYPE_ETH,
1270         RTE_FLOW_ITEM_TYPE_PPPOES,
1271         RTE_FLOW_ITEM_TYPE_IPV6,
1272         RTE_FLOW_ITEM_TYPE_END,
1273 };
1274 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv6[] = {
1275         RTE_FLOW_ITEM_TYPE_ETH,
1276         RTE_FLOW_ITEM_TYPE_VLAN,
1277         RTE_FLOW_ITEM_TYPE_PPPOES,
1278         RTE_FLOW_ITEM_TYPE_IPV6,
1279         RTE_FLOW_ITEM_TYPE_END,
1280 };
1281 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv6[] = {
1282         RTE_FLOW_ITEM_TYPE_ETH,
1283         RTE_FLOW_ITEM_TYPE_VLAN,
1284         RTE_FLOW_ITEM_TYPE_VLAN,
1285         RTE_FLOW_ITEM_TYPE_PPPOES,
1286         RTE_FLOW_ITEM_TYPE_IPV6,
1287         RTE_FLOW_ITEM_TYPE_END,
1288 };
1289 enum rte_flow_item_type pattern_eth_pppoes_ipv6_udp[] = {
1290         RTE_FLOW_ITEM_TYPE_ETH,
1291         RTE_FLOW_ITEM_TYPE_PPPOES,
1292         RTE_FLOW_ITEM_TYPE_IPV6,
1293         RTE_FLOW_ITEM_TYPE_UDP,
1294         RTE_FLOW_ITEM_TYPE_END,
1295 };
1296 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv6_udp[] = {
1297         RTE_FLOW_ITEM_TYPE_ETH,
1298         RTE_FLOW_ITEM_TYPE_VLAN,
1299         RTE_FLOW_ITEM_TYPE_PPPOES,
1300         RTE_FLOW_ITEM_TYPE_IPV6,
1301         RTE_FLOW_ITEM_TYPE_UDP,
1302         RTE_FLOW_ITEM_TYPE_END,
1303 };
1304 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv6_udp[] = {
1305         RTE_FLOW_ITEM_TYPE_ETH,
1306         RTE_FLOW_ITEM_TYPE_VLAN,
1307         RTE_FLOW_ITEM_TYPE_VLAN,
1308         RTE_FLOW_ITEM_TYPE_PPPOES,
1309         RTE_FLOW_ITEM_TYPE_IPV6,
1310         RTE_FLOW_ITEM_TYPE_UDP,
1311         RTE_FLOW_ITEM_TYPE_END,
1312 };
1313 enum rte_flow_item_type pattern_eth_pppoes_ipv6_tcp[] = {
1314         RTE_FLOW_ITEM_TYPE_ETH,
1315         RTE_FLOW_ITEM_TYPE_PPPOES,
1316         RTE_FLOW_ITEM_TYPE_IPV6,
1317         RTE_FLOW_ITEM_TYPE_TCP,
1318         RTE_FLOW_ITEM_TYPE_END,
1319 };
1320 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv6_tcp[] = {
1321         RTE_FLOW_ITEM_TYPE_ETH,
1322         RTE_FLOW_ITEM_TYPE_VLAN,
1323         RTE_FLOW_ITEM_TYPE_PPPOES,
1324         RTE_FLOW_ITEM_TYPE_IPV6,
1325         RTE_FLOW_ITEM_TYPE_TCP,
1326         RTE_FLOW_ITEM_TYPE_END,
1327 };
1328 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv6_tcp[] = {
1329         RTE_FLOW_ITEM_TYPE_ETH,
1330         RTE_FLOW_ITEM_TYPE_VLAN,
1331         RTE_FLOW_ITEM_TYPE_VLAN,
1332         RTE_FLOW_ITEM_TYPE_PPPOES,
1333         RTE_FLOW_ITEM_TYPE_IPV6,
1334         RTE_FLOW_ITEM_TYPE_TCP,
1335         RTE_FLOW_ITEM_TYPE_END,
1336 };
1337 enum rte_flow_item_type pattern_eth_pppoes_ipv6_sctp[] = {
1338         RTE_FLOW_ITEM_TYPE_ETH,
1339         RTE_FLOW_ITEM_TYPE_PPPOES,
1340         RTE_FLOW_ITEM_TYPE_IPV6,
1341         RTE_FLOW_ITEM_TYPE_SCTP,
1342         RTE_FLOW_ITEM_TYPE_END,
1343 };
1344 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv6_sctp[] = {
1345         RTE_FLOW_ITEM_TYPE_ETH,
1346         RTE_FLOW_ITEM_TYPE_VLAN,
1347         RTE_FLOW_ITEM_TYPE_PPPOES,
1348         RTE_FLOW_ITEM_TYPE_IPV6,
1349         RTE_FLOW_ITEM_TYPE_SCTP,
1350         RTE_FLOW_ITEM_TYPE_END,
1351 };
1352 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv6_sctp[] = {
1353         RTE_FLOW_ITEM_TYPE_ETH,
1354         RTE_FLOW_ITEM_TYPE_VLAN,
1355         RTE_FLOW_ITEM_TYPE_VLAN,
1356         RTE_FLOW_ITEM_TYPE_PPPOES,
1357         RTE_FLOW_ITEM_TYPE_IPV6,
1358         RTE_FLOW_ITEM_TYPE_SCTP,
1359         RTE_FLOW_ITEM_TYPE_END,
1360 };
1361 enum rte_flow_item_type pattern_eth_pppoes_ipv6_icmp6[] = {
1362         RTE_FLOW_ITEM_TYPE_ETH,
1363         RTE_FLOW_ITEM_TYPE_PPPOES,
1364         RTE_FLOW_ITEM_TYPE_IPV6,
1365         RTE_FLOW_ITEM_TYPE_ICMP6,
1366         RTE_FLOW_ITEM_TYPE_END,
1367 };
1368 enum rte_flow_item_type pattern_eth_vlan_pppoes_ipv6_icmp6[] = {
1369         RTE_FLOW_ITEM_TYPE_ETH,
1370         RTE_FLOW_ITEM_TYPE_VLAN,
1371         RTE_FLOW_ITEM_TYPE_PPPOES,
1372         RTE_FLOW_ITEM_TYPE_IPV6,
1373         RTE_FLOW_ITEM_TYPE_ICMP6,
1374         RTE_FLOW_ITEM_TYPE_END,
1375 };
1376 enum rte_flow_item_type pattern_eth_qinq_pppoes_ipv6_icmp6[] = {
1377         RTE_FLOW_ITEM_TYPE_ETH,
1378         RTE_FLOW_ITEM_TYPE_VLAN,
1379         RTE_FLOW_ITEM_TYPE_VLAN,
1380         RTE_FLOW_ITEM_TYPE_PPPOES,
1381         RTE_FLOW_ITEM_TYPE_IPV6,
1382         RTE_FLOW_ITEM_TYPE_ICMP6,
1383         RTE_FLOW_ITEM_TYPE_END,
1384 };
1385 enum rte_flow_item_type pattern_eth_ipv4_esp[] = {
1386         RTE_FLOW_ITEM_TYPE_ETH,
1387         RTE_FLOW_ITEM_TYPE_IPV4,
1388         RTE_FLOW_ITEM_TYPE_ESP,
1389         RTE_FLOW_ITEM_TYPE_END,
1390 };
1391 enum rte_flow_item_type pattern_eth_ipv6_esp[] = {
1392         RTE_FLOW_ITEM_TYPE_ETH,
1393         RTE_FLOW_ITEM_TYPE_IPV6,
1394         RTE_FLOW_ITEM_TYPE_ESP,
1395         RTE_FLOW_ITEM_TYPE_END,
1396 };
1397 enum rte_flow_item_type pattern_eth_ipv4_ah[] = {
1398         RTE_FLOW_ITEM_TYPE_ETH,
1399         RTE_FLOW_ITEM_TYPE_IPV4,
1400         RTE_FLOW_ITEM_TYPE_AH,
1401         RTE_FLOW_ITEM_TYPE_END,
1402 };
1403 enum rte_flow_item_type pattern_eth_ipv6_ah[] = {
1404         RTE_FLOW_ITEM_TYPE_ETH,
1405         RTE_FLOW_ITEM_TYPE_IPV6,
1406         RTE_FLOW_ITEM_TYPE_AH,
1407         RTE_FLOW_ITEM_TYPE_END,
1408 };
1409 enum rte_flow_item_type pattern_eth_ipv4_udp_esp[] = {
1410         RTE_FLOW_ITEM_TYPE_ETH,
1411         RTE_FLOW_ITEM_TYPE_IPV4,
1412         RTE_FLOW_ITEM_TYPE_UDP,
1413         RTE_FLOW_ITEM_TYPE_ESP,
1414         RTE_FLOW_ITEM_TYPE_END,
1415 };
1416 enum rte_flow_item_type pattern_eth_ipv6_udp_esp[] = {
1417         RTE_FLOW_ITEM_TYPE_ETH,
1418         RTE_FLOW_ITEM_TYPE_IPV6,
1419         RTE_FLOW_ITEM_TYPE_UDP,
1420         RTE_FLOW_ITEM_TYPE_ESP,
1421         RTE_FLOW_ITEM_TYPE_END,
1422 };
1423 enum rte_flow_item_type pattern_eth_ipv6_udp_ah[] = {
1424         RTE_FLOW_ITEM_TYPE_ETH,
1425         RTE_FLOW_ITEM_TYPE_IPV6,
1426         RTE_FLOW_ITEM_TYPE_UDP,
1427         RTE_FLOW_ITEM_TYPE_AH,
1428         RTE_FLOW_ITEM_TYPE_END,
1429 };
1430 enum rte_flow_item_type pattern_eth_ipv4_l2tp[] = {
1431         RTE_FLOW_ITEM_TYPE_ETH,
1432         RTE_FLOW_ITEM_TYPE_IPV4,
1433         RTE_FLOW_ITEM_TYPE_L2TPV3OIP,
1434         RTE_FLOW_ITEM_TYPE_END,
1435 };
1436 enum rte_flow_item_type pattern_eth_ipv6_l2tp[] = {
1437         RTE_FLOW_ITEM_TYPE_ETH,
1438         RTE_FLOW_ITEM_TYPE_IPV6,
1439         RTE_FLOW_ITEM_TYPE_L2TPV3OIP,
1440         RTE_FLOW_ITEM_TYPE_END,
1441 };
1442 enum rte_flow_item_type pattern_eth_ipv4_pfcp[] = {
1443         RTE_FLOW_ITEM_TYPE_ETH,
1444         RTE_FLOW_ITEM_TYPE_IPV4,
1445         RTE_FLOW_ITEM_TYPE_UDP,
1446         RTE_FLOW_ITEM_TYPE_PFCP,
1447         RTE_FLOW_ITEM_TYPE_END,
1448 };
1449 enum rte_flow_item_type pattern_eth_ipv6_pfcp[] = {
1450         RTE_FLOW_ITEM_TYPE_ETH,
1451         RTE_FLOW_ITEM_TYPE_IPV6,
1452         RTE_FLOW_ITEM_TYPE_UDP,
1453         RTE_FLOW_ITEM_TYPE_PFCP,
1454         RTE_FLOW_ITEM_TYPE_END,
1455 };
1456
1457
1458
1459 typedef struct ice_flow_engine * (*parse_engine_t)(struct ice_adapter *ad,
1460                 struct rte_flow *flow,
1461                 struct ice_parser_list *parser_list,
1462                 const struct rte_flow_item pattern[],
1463                 const struct rte_flow_action actions[],
1464                 struct rte_flow_error *error);
1465
1466 void
1467 ice_register_flow_engine(struct ice_flow_engine *engine)
1468 {
1469         TAILQ_INSERT_TAIL(&engine_list, engine, node);
1470 }
1471
1472 int
1473 ice_flow_init(struct ice_adapter *ad)
1474 {
1475         int ret;
1476         struct ice_pf *pf = &ad->pf;
1477         void *temp;
1478         struct ice_flow_engine *engine;
1479
1480         TAILQ_INIT(&pf->flow_list);
1481         TAILQ_INIT(&pf->rss_parser_list);
1482         TAILQ_INIT(&pf->perm_parser_list);
1483         TAILQ_INIT(&pf->dist_parser_list);
1484         rte_spinlock_init(&pf->flow_ops_lock);
1485
1486         TAILQ_FOREACH_SAFE(engine, &engine_list, node, temp) {
1487                 if (engine->init == NULL) {
1488                         PMD_INIT_LOG(ERR, "Invalid engine type (%d)",
1489                                         engine->type);
1490                         return -ENOTSUP;
1491                 }
1492
1493                 ret = engine->init(ad);
1494                 if (ret) {
1495                         PMD_INIT_LOG(ERR, "Failed to initialize engine %d",
1496                                         engine->type);
1497                         return ret;
1498                 }
1499         }
1500         return 0;
1501 }
1502
1503 void
1504 ice_flow_uninit(struct ice_adapter *ad)
1505 {
1506         struct ice_pf *pf = &ad->pf;
1507         struct ice_flow_engine *engine;
1508         struct rte_flow *p_flow;
1509         struct ice_flow_parser_node *p_parser;
1510         void *temp;
1511
1512         TAILQ_FOREACH_SAFE(engine, &engine_list, node, temp) {
1513                 if (engine->uninit)
1514                         engine->uninit(ad);
1515         }
1516
1517         /* Remove all flows */
1518         while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
1519                 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
1520                 if (p_flow->engine->free)
1521                         p_flow->engine->free(p_flow);
1522                 rte_free(p_flow);
1523         }
1524
1525         /* Cleanup parser list */
1526         while ((p_parser = TAILQ_FIRST(&pf->rss_parser_list))) {
1527                 TAILQ_REMOVE(&pf->rss_parser_list, p_parser, node);
1528                 rte_free(p_parser);
1529         }
1530
1531         while ((p_parser = TAILQ_FIRST(&pf->perm_parser_list))) {
1532                 TAILQ_REMOVE(&pf->perm_parser_list, p_parser, node);
1533                 rte_free(p_parser);
1534         }
1535
1536         while ((p_parser = TAILQ_FIRST(&pf->dist_parser_list))) {
1537                 TAILQ_REMOVE(&pf->dist_parser_list, p_parser, node);
1538                 rte_free(p_parser);
1539         }
1540 }
1541
1542 static struct ice_parser_list *
1543 ice_get_parser_list(struct ice_flow_parser *parser,
1544                 struct ice_adapter *ad)
1545 {
1546         struct ice_parser_list *list;
1547         struct ice_pf *pf = &ad->pf;
1548
1549         switch (parser->stage) {
1550         case ICE_FLOW_STAGE_RSS:
1551                 list = &pf->rss_parser_list;
1552                 break;
1553         case ICE_FLOW_STAGE_PERMISSION:
1554                 list = &pf->perm_parser_list;
1555                 break;
1556         case ICE_FLOW_STAGE_DISTRIBUTOR:
1557                 list = &pf->dist_parser_list;
1558                 break;
1559         default:
1560                 return NULL;
1561         }
1562
1563         return list;
1564 }
1565
1566 int
1567 ice_register_parser(struct ice_flow_parser *parser,
1568                 struct ice_adapter *ad)
1569 {
1570         struct ice_parser_list *list;
1571         struct ice_flow_parser_node *parser_node;
1572
1573         parser_node = rte_zmalloc("ice_parser", sizeof(*parser_node), 0);
1574         if (parser_node == NULL) {
1575                 PMD_DRV_LOG(ERR, "Failed to allocate memory.");
1576                 return -ENOMEM;
1577         }
1578         parser_node->parser = parser;
1579
1580         list = ice_get_parser_list(parser, ad);
1581         if (list == NULL)
1582                 return -EINVAL;
1583
1584         if (ad->devargs.pipe_mode_support) {
1585                 TAILQ_INSERT_TAIL(list, parser_node, node);
1586         } else {
1587                 if (parser->engine->type == ICE_FLOW_ENGINE_SWITCH ||
1588                                 parser->engine->type == ICE_FLOW_ENGINE_HASH)
1589                         TAILQ_INSERT_TAIL(list, parser_node, node);
1590                 else if (parser->engine->type == ICE_FLOW_ENGINE_FDIR)
1591                         TAILQ_INSERT_HEAD(list, parser_node, node);
1592                 else
1593                         return -EINVAL;
1594         }
1595         return 0;
1596 }
1597
1598 void
1599 ice_unregister_parser(struct ice_flow_parser *parser,
1600                 struct ice_adapter *ad)
1601 {
1602         struct ice_parser_list *list;
1603         struct ice_flow_parser_node *p_parser;
1604         void *temp;
1605
1606         list = ice_get_parser_list(parser, ad);
1607         if (list == NULL)
1608                 return;
1609
1610         TAILQ_FOREACH_SAFE(p_parser, list, node, temp) {
1611                 if (p_parser->parser->engine->type == parser->engine->type) {
1612                         TAILQ_REMOVE(list, p_parser, node);
1613                         rte_free(p_parser);
1614                 }
1615         }
1616 }
1617
1618 static int
1619 ice_flow_valid_attr(struct ice_adapter *ad,
1620                 const struct rte_flow_attr *attr,
1621                 int *ice_pipeline_stage,
1622                 struct rte_flow_error *error)
1623 {
1624         /* Must be input direction */
1625         if (!attr->ingress) {
1626                 rte_flow_error_set(error, EINVAL,
1627                                 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1628                                 attr, "Only support ingress.");
1629                 return -rte_errno;
1630         }
1631
1632         /* Not supported */
1633         if (attr->egress) {
1634                 rte_flow_error_set(error, EINVAL,
1635                                 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1636                                 attr, "Not support egress.");
1637                 return -rte_errno;
1638         }
1639
1640         /* Check pipeline mode support to set classification stage */
1641         if (ad->devargs.pipe_mode_support) {
1642                 if (attr->priority == 0)
1643                         *ice_pipeline_stage =
1644                                 ICE_FLOW_CLASSIFY_STAGE_PERMISSION;
1645                 else
1646                         *ice_pipeline_stage =
1647                                 ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR;
1648         } else {
1649                 *ice_pipeline_stage =
1650                         ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR_ONLY;
1651                 /* Not supported */
1652                 if (attr->priority) {
1653                         rte_flow_error_set(error, EINVAL,
1654                                         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1655                                         attr, "Not support priority.");
1656                         return -rte_errno;
1657                 }
1658         }
1659
1660         /* Not supported */
1661         if (attr->group) {
1662                 rte_flow_error_set(error, EINVAL,
1663                                 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
1664                                 attr, "Not support group.");
1665                 return -rte_errno;
1666         }
1667
1668         return 0;
1669 }
1670
1671 /* Find the first VOID or non-VOID item pointer */
1672 static const struct rte_flow_item *
1673 ice_find_first_item(const struct rte_flow_item *item, bool is_void)
1674 {
1675         bool is_find;
1676
1677         while (item->type != RTE_FLOW_ITEM_TYPE_END) {
1678                 if (is_void)
1679                         is_find = item->type == RTE_FLOW_ITEM_TYPE_VOID;
1680                 else
1681                         is_find = item->type != RTE_FLOW_ITEM_TYPE_VOID;
1682                 if (is_find)
1683                         break;
1684                 item++;
1685         }
1686         return item;
1687 }
1688
1689 /* Skip all VOID items of the pattern */
1690 static void
1691 ice_pattern_skip_void_item(struct rte_flow_item *items,
1692                         const struct rte_flow_item *pattern)
1693 {
1694         uint32_t cpy_count = 0;
1695         const struct rte_flow_item *pb = pattern, *pe = pattern;
1696
1697         for (;;) {
1698                 /* Find a non-void item first */
1699                 pb = ice_find_first_item(pb, false);
1700                 if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
1701                         pe = pb;
1702                         break;
1703                 }
1704
1705                 /* Find a void item */
1706                 pe = ice_find_first_item(pb + 1, true);
1707
1708                 cpy_count = pe - pb;
1709                 rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
1710
1711                 items += cpy_count;
1712
1713                 if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
1714                         break;
1715                 }
1716
1717                 pb = pe + 1;
1718         }
1719         /* Copy the END item. */
1720         rte_memcpy(items, pe, sizeof(struct rte_flow_item));
1721 }
1722
1723 /* Check if the pattern matches a supported item type array */
1724 static bool
1725 ice_match_pattern(enum rte_flow_item_type *item_array,
1726                 const struct rte_flow_item *pattern)
1727 {
1728         const struct rte_flow_item *item = pattern;
1729
1730         while ((*item_array == item->type) &&
1731                (*item_array != RTE_FLOW_ITEM_TYPE_END)) {
1732                 item_array++;
1733                 item++;
1734         }
1735
1736         return (*item_array == RTE_FLOW_ITEM_TYPE_END &&
1737                 item->type == RTE_FLOW_ITEM_TYPE_END);
1738 }
1739
1740 struct ice_pattern_match_item *
1741 ice_search_pattern_match_item(const struct rte_flow_item pattern[],
1742                 struct ice_pattern_match_item *array,
1743                 uint32_t array_len,
1744                 struct rte_flow_error *error)
1745 {
1746         uint16_t i = 0;
1747         struct ice_pattern_match_item *pattern_match_item;
1748         /* need free by each filter */
1749         struct rte_flow_item *items; /* used for pattern without VOID items */
1750         uint32_t item_num = 0; /* non-void item number */
1751
1752         /* Get the non-void item number of pattern */
1753         while ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_END) {
1754                 if ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_VOID)
1755                         item_num++;
1756                 i++;
1757         }
1758         item_num++;
1759
1760         items = rte_zmalloc("ice_pattern",
1761                             item_num * sizeof(struct rte_flow_item), 0);
1762         if (!items) {
1763                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1764                                    NULL, "No memory for PMD internal items.");
1765                 return NULL;
1766         }
1767         pattern_match_item = rte_zmalloc("ice_pattern_match_item",
1768                         sizeof(struct ice_pattern_match_item), 0);
1769         if (!pattern_match_item) {
1770                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1771                                 NULL, "Failed to allocate memory.");
1772                 return NULL;
1773         }
1774
1775         ice_pattern_skip_void_item(items, pattern);
1776
1777         for (i = 0; i < array_len; i++)
1778                 if (ice_match_pattern(array[i].pattern_list,
1779                                         items)) {
1780                         pattern_match_item->input_set_mask =
1781                                 array[i].input_set_mask;
1782                         pattern_match_item->pattern_list =
1783                                 array[i].pattern_list;
1784                         pattern_match_item->meta = array[i].meta;
1785                         rte_free(items);
1786                         return pattern_match_item;
1787                 }
1788         rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
1789                            pattern, "Unsupported pattern");
1790
1791         rte_free(items);
1792         rte_free(pattern_match_item);
1793         return NULL;
1794 }
1795
1796 static struct ice_flow_engine *
1797 ice_parse_engine_create(struct ice_adapter *ad,
1798                 struct rte_flow *flow,
1799                 struct ice_parser_list *parser_list,
1800                 const struct rte_flow_item pattern[],
1801                 const struct rte_flow_action actions[],
1802                 struct rte_flow_error *error)
1803 {
1804         struct ice_flow_engine *engine = NULL;
1805         struct ice_flow_parser_node *parser_node;
1806         void *meta = NULL;
1807         void *temp;
1808
1809         TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
1810                 int ret;
1811
1812                 if (parser_node->parser->parse_pattern_action(ad,
1813                                 parser_node->parser->array,
1814                                 parser_node->parser->array_len,
1815                                 pattern, actions, &meta, error) < 0)
1816                         continue;
1817
1818                 engine = parser_node->parser->engine;
1819                 RTE_ASSERT(engine->create != NULL);
1820                 ret = engine->create(ad, flow, meta, error);
1821                 if (ret == 0)
1822                         return engine;
1823                 else if (ret == -EEXIST)
1824                         return NULL;
1825         }
1826         return NULL;
1827 }
1828
1829 static struct ice_flow_engine *
1830 ice_parse_engine_validate(struct ice_adapter *ad,
1831                 struct rte_flow *flow __rte_unused,
1832                 struct ice_parser_list *parser_list,
1833                 const struct rte_flow_item pattern[],
1834                 const struct rte_flow_action actions[],
1835                 struct rte_flow_error *error)
1836 {
1837         struct ice_flow_engine *engine = NULL;
1838         struct ice_flow_parser_node *parser_node;
1839         void *temp;
1840
1841         TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
1842                 if (parser_node->parser->parse_pattern_action(ad,
1843                                 parser_node->parser->array,
1844                                 parser_node->parser->array_len,
1845                                 pattern, actions, NULL, error) < 0)
1846                         continue;
1847
1848                 engine = parser_node->parser->engine;
1849                 break;
1850         }
1851         return engine;
1852 }
1853
1854 static int
1855 ice_flow_process_filter(struct rte_eth_dev *dev,
1856                 struct rte_flow *flow,
1857                 const struct rte_flow_attr *attr,
1858                 const struct rte_flow_item pattern[],
1859                 const struct rte_flow_action actions[],
1860                 struct ice_flow_engine **engine,
1861                 parse_engine_t ice_parse_engine,
1862                 struct rte_flow_error *error)
1863 {
1864         int ret = ICE_ERR_NOT_SUPPORTED;
1865         struct ice_adapter *ad =
1866                 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1867         struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1868         int ice_pipeline_stage = 0;
1869
1870         if (!pattern) {
1871                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1872                                    NULL, "NULL pattern.");
1873                 return -rte_errno;
1874         }
1875
1876         if (!actions) {
1877                 rte_flow_error_set(error, EINVAL,
1878                                    RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1879                                    NULL, "NULL action.");
1880                 return -rte_errno;
1881         }
1882
1883         if (!attr) {
1884                 rte_flow_error_set(error, EINVAL,
1885                                    RTE_FLOW_ERROR_TYPE_ATTR,
1886                                    NULL, "NULL attribute.");
1887                 return -rte_errno;
1888         }
1889
1890         ret = ice_flow_valid_attr(ad, attr, &ice_pipeline_stage, error);
1891         if (ret)
1892                 return ret;
1893
1894         *engine = ice_parse_engine(ad, flow, &pf->rss_parser_list,
1895                         pattern, actions, error);
1896         if (*engine != NULL)
1897                 return 0;
1898
1899         switch (ice_pipeline_stage) {
1900         case ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR_ONLY:
1901         case ICE_FLOW_CLASSIFY_STAGE_DISTRIBUTOR:
1902                 *engine = ice_parse_engine(ad, flow, &pf->dist_parser_list,
1903                                 pattern, actions, error);
1904                 break;
1905         case ICE_FLOW_CLASSIFY_STAGE_PERMISSION:
1906                 *engine = ice_parse_engine(ad, flow, &pf->perm_parser_list,
1907                                 pattern, actions, error);
1908                 break;
1909         default:
1910                 return -EINVAL;
1911         }
1912
1913         if (*engine == NULL)
1914                 return -EINVAL;
1915
1916         return 0;
1917 }
1918
1919 static int
1920 ice_flow_validate(struct rte_eth_dev *dev,
1921                 const struct rte_flow_attr *attr,
1922                 const struct rte_flow_item pattern[],
1923                 const struct rte_flow_action actions[],
1924                 struct rte_flow_error *error)
1925 {
1926         struct ice_flow_engine *engine;
1927
1928         return ice_flow_process_filter(dev, NULL, attr, pattern, actions,
1929                         &engine, ice_parse_engine_validate, error);
1930 }
1931
1932 static struct rte_flow *
1933 ice_flow_create(struct rte_eth_dev *dev,
1934                 const struct rte_flow_attr *attr,
1935                 const struct rte_flow_item pattern[],
1936                 const struct rte_flow_action actions[],
1937                 struct rte_flow_error *error)
1938 {
1939         struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1940         struct rte_flow *flow = NULL;
1941         int ret;
1942         struct ice_flow_engine *engine = NULL;
1943
1944         flow = rte_zmalloc("ice_flow", sizeof(struct rte_flow), 0);
1945         if (!flow) {
1946                 rte_flow_error_set(error, ENOMEM,
1947                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1948                                    "Failed to allocate memory");
1949                 return flow;
1950         }
1951
1952         rte_spinlock_lock(&pf->flow_ops_lock);
1953
1954         ret = ice_flow_process_filter(dev, flow, attr, pattern, actions,
1955                         &engine, ice_parse_engine_create, error);
1956         if (ret < 0) {
1957                 PMD_DRV_LOG(ERR, "Failed to create flow");
1958                 rte_free(flow);
1959                 flow = NULL;
1960                 goto out;
1961         }
1962
1963         flow->engine = engine;
1964         TAILQ_INSERT_TAIL(&pf->flow_list, flow, node);
1965         PMD_DRV_LOG(INFO, "Succeeded to create (%d) flow", engine->type);
1966
1967 out:
1968         rte_spinlock_unlock(&pf->flow_ops_lock);
1969         return flow;
1970 }
1971
1972 static int
1973 ice_flow_destroy(struct rte_eth_dev *dev,
1974                 struct rte_flow *flow,
1975                 struct rte_flow_error *error)
1976 {
1977         struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1978         struct ice_adapter *ad =
1979                 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1980         int ret = 0;
1981
1982         if (!flow || !flow->engine || !flow->engine->destroy) {
1983                 rte_flow_error_set(error, EINVAL,
1984                                 RTE_FLOW_ERROR_TYPE_HANDLE,
1985                                 NULL, "Invalid flow");
1986                 return -rte_errno;
1987         }
1988
1989         rte_spinlock_lock(&pf->flow_ops_lock);
1990
1991         ret = flow->engine->destroy(ad, flow, error);
1992         if (!ret) {
1993                 TAILQ_REMOVE(&pf->flow_list, flow, node);
1994                 rte_free(flow);
1995         } else {
1996                 PMD_DRV_LOG(ERR, "Failed to destroy flow");
1997         }
1998
1999         rte_spinlock_unlock(&pf->flow_ops_lock);
2000
2001         return ret;
2002 }
2003
2004 static int
2005 ice_flow_flush(struct rte_eth_dev *dev,
2006                 struct rte_flow_error *error)
2007 {
2008         struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2009         struct rte_flow *p_flow;
2010         void *temp;
2011         int ret = 0;
2012
2013         TAILQ_FOREACH_SAFE(p_flow, &pf->flow_list, node, temp) {
2014                 ret = ice_flow_destroy(dev, p_flow, error);
2015                 if (ret) {
2016                         PMD_DRV_LOG(ERR, "Failed to flush flows");
2017                         return -EINVAL;
2018                 }
2019         }
2020
2021         return ret;
2022 }
2023
2024 static int
2025 ice_flow_query(struct rte_eth_dev *dev,
2026                 struct rte_flow *flow,
2027                 const struct rte_flow_action *actions,
2028                 void *data,
2029                 struct rte_flow_error *error)
2030 {
2031         int ret = -EINVAL;
2032         struct ice_adapter *ad =
2033                 ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2034         struct rte_flow_query_count *count = data;
2035         struct ice_pf *pf = &ad->pf;
2036
2037         if (!flow || !flow->engine || !flow->engine->query_count) {
2038                 rte_flow_error_set(error, EINVAL,
2039                                 RTE_FLOW_ERROR_TYPE_HANDLE,
2040                                 NULL, "Invalid flow");
2041                 return -rte_errno;
2042         }
2043
2044         rte_spinlock_lock(&pf->flow_ops_lock);
2045
2046         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2047                 switch (actions->type) {
2048                 case RTE_FLOW_ACTION_TYPE_VOID:
2049                         break;
2050                 case RTE_FLOW_ACTION_TYPE_COUNT:
2051                         ret = flow->engine->query_count(ad, flow, count, error);
2052                         break;
2053                 default:
2054                         return rte_flow_error_set(error, ENOTSUP,
2055                                         RTE_FLOW_ERROR_TYPE_ACTION,
2056                                         actions,
2057                                         "action not supported");
2058                 }
2059         }
2060
2061         rte_spinlock_unlock(&pf->flow_ops_lock);
2062
2063         return ret;
2064 }
2065
2066 int
2067 ice_flow_redirect(struct ice_adapter *ad,
2068                   struct ice_flow_redirect *rd)
2069 {
2070         struct ice_pf *pf = &ad->pf;
2071         struct rte_flow *p_flow;
2072         void *temp;
2073         int ret;
2074
2075         rte_spinlock_lock(&pf->flow_ops_lock);
2076
2077         TAILQ_FOREACH_SAFE(p_flow, &pf->flow_list, node, temp) {
2078                 if (!p_flow->engine->redirect)
2079                         continue;
2080                 ret = p_flow->engine->redirect(ad, p_flow, rd);
2081                 if (ret) {
2082                         PMD_DRV_LOG(ERR, "Failed to redirect flows");
2083                         return ret;
2084                 }
2085         }
2086
2087         rte_spinlock_unlock(&pf->flow_ops_lock);
2088
2089         return 0;
2090 }