2c479dfbd450b0f48942d8d4b53fc387f8ff12d6
[dpdk.git] / drivers / net / ice / base / ice_fdir.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #include "ice_common.h"
6 #include "ice_fdir.h"
7
8 /* These are training packet headers used to program flow director filters. */
9 static const u8 ice_fdir_tcpv4_pkt[] = {
10         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
11         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
12         0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
13         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00,
16         0x20, 0x00, 0x00, 0x00, 0x00, 0x00
17 };
18
19 static const u8 ice_fdir_udpv4_pkt[] = {
20         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
22         0x00, 0x1C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
23         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25         0x00, 0x00,
26 };
27
28 static const u8 ice_fdir_sctpv4_pkt[] = {
29         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
31         0x00, 0x20, 0x00, 0x00, 0x40, 0x00, 0x40, 0x84,
32         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 };
36
37 static const u8 ice_fdir_ipv4_pkt[] = {
38         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
40         0x00, 0x14, 0x00, 0x00, 0x40, 0x00, 0x40, 0x10,
41         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42         0x00, 0x00
43 };
44
45 static const u8 ice_fdir_udp4_vxlan_pkt[] = {
46         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
48         0x00, 0x4e, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
49         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
52         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
54         0x45, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x40, 0x00,
55         0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57         0x00, 0x00, 0x00, 0x00,
58 };
59
60 static const u8 ice_fdir_ipv4_gtpu4_pkt[] = {
61         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
63         0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
64         0x7c, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x24,
66         0xbf, 0xc0, 0x30, 0xff, 0x00, 0x14, 0x00, 0x00,
67         0x00, 0x00, 0x45, 0x00, 0x00, 0x14, 0x00, 0x01,
68         0x00, 0x00, 0x40, 0x00, 0x3a, 0x3d, 0x00, 0x00,
69         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 };
71
72 static const u8 ice_fdir_udp4_gtpu4_pkt[] = {
73         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
75         0x00, 0x40, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
76         0x7c, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x2c,
78         0x00, 0x6f, 0x30, 0xff, 0x00, 0x1c, 0x00, 0x00,
79         0x00, 0x00, 0x45, 0x00, 0x00, 0x1c, 0x00, 0x01,
80         0x00, 0x00, 0x40, 0x11, 0x3a, 0x24, 0x00, 0x00,
81         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82         0x00, 0x00, 0x00, 0x08, 0xbe, 0xc7, 0x00, 0x00,
83 };
84
85 static const u8 ice_fdir_tcp4_gtpu4_pkt[] = {
86         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
88         0x00, 0x4c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
89         0x7c, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x38,
91         0x00, 0x4c, 0x30, 0xff, 0x00, 0x28, 0x00, 0x00,
92         0x00, 0x00, 0x45, 0x00, 0x00, 0x28, 0x00, 0x01,
93         0x00, 0x00, 0x40, 0x06, 0x3a, 0x23, 0x00, 0x00,
94         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96         0x00, 0x00, 0x50, 0x02, 0x20, 0x00, 0x4e, 0xd2,
97         0x00, 0x00, 0x00, 0x00,
98 };
99
100 static const u8 ice_fdir_ipv4_gtpu4_eh_pkt[] = {
101         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
103         0x00, 0x44, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
104         0x39, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x30,
106         0x76, 0x6c, 0x34, 0xff, 0x00, 0x20, 0x00, 0x00,
107         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
108         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
109         0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00,
110         0x3a, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111         0x00, 0x00, 0x00, 0x00,
112 };
113
114 static const u8 ice_fdir_udp4_gtpu4_eh_pkt[] = {
115         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
117         0x00, 0x4c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
118         0x39, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x38,
120         0xb7, 0x1a, 0x34, 0xff, 0x00, 0x28, 0x00, 0x00,
121         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
122         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
123         0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
124         0x3a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
126         0xbe, 0xc7, 0x00, 0x00,
127 };
128
129 static const u8 ice_fdir_tcp4_gtpu4_eh_pkt[] = {
130         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
132         0x00, 0x58, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
133         0x39, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x44,
135         0xb6, 0xf7, 0x34, 0xff, 0x00, 0x34, 0x00, 0x00,
136         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
137         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
138         0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
139         0x3a, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
142         0x20, 0x00, 0x4e, 0xd2, 0x00, 0x00, 0x00, 0x00,
143 };
144
145 static const u8 ice_fdir_ipv4_gtpu4_eh_dw_pkt[] = {
146         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
148         0x00, 0x58, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
149         0x39, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x44,
151         0xb6, 0xf7, 0x34, 0xff, 0x00, 0x34, 0x00, 0x00,
152         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
153         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
154         0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
155         0x3a, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
156         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
157         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
158         0x20, 0x00, 0x4e, 0xd2, 0x00, 0x00, 0x00, 0x00,
159 };
160
161 static const u8 ice_fdir_udp4_gtpu4_eh_dw_pkt[] = {
162         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
164         0x00, 0x4c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
165         0x39, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x38,
167         0xb7, 0x1a, 0x34, 0xff, 0x00, 0x28, 0x00, 0x00,
168         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
169         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
170         0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
171         0x3a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
173         0xbe, 0xc7, 0x00, 0x00,
174 };
175
176 static const u8 ice_fdir_tcp4_gtpu4_eh_dw_pkt[] = {
177         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
179         0x00, 0x58, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
180         0x39, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x44,
182         0xb6, 0xf7, 0x34, 0xff, 0x00, 0x34, 0x00, 0x00,
183         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
184         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
185         0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
186         0x3a, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
189         0x20, 0x00, 0x4e, 0xd2, 0x00, 0x00, 0x00, 0x00,
190 };
191
192 static const u8 ice_fdir_ipv4_gtpu4_eh_up_pkt[] = {
193         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
195         0x00, 0x44, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
196         0x39, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x30,
198         0x76, 0x5c, 0x34, 0xff, 0x00, 0x20, 0x00, 0x00,
199         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x10,
200         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
201         0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00,
202         0x3a, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203         0x00, 0x00, 0x00, 0x00,
204 };
205
206 static const u8 ice_fdir_udp4_gtpu4_eh_up_pkt[] = {
207         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
209         0x00, 0x4c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
210         0x39, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
211         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x38,
212         0xb7, 0x0a, 0x34, 0xff, 0x00, 0x28, 0x00, 0x00,
213         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x10,
214         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
215         0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
216         0x3a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
217         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
218         0xbe, 0xc7, 0x00, 0x00,
219 };
220
221 static const u8 ice_fdir_tcp4_gtpu4_eh_up_pkt[] = {
222         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
224         0x00, 0x58, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11,
225         0x39, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x44,
227         0xb6, 0xe7, 0x34, 0xff, 0x00, 0x34, 0x00, 0x00,
228         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x10,
229         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
230         0x00, 0x28, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06,
231         0x3a, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02,
234         0x20, 0x00, 0x4e, 0xd2, 0x00, 0x00, 0x00, 0x00,
235 };
236
237 static const u8 ice_fdir_icmp4_gtpu4_pkt[] = {
238         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
240         0x00, 0x4c, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
241         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242         0x00, 0x00, 0x08, 0x68, 0x08, 0x68, 0x00, 0x00,
243         0x00, 0x00, 0x34, 0xff, 0x00, 0x28, 0x00, 0x00,
244         0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x02, 0x00,
245         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00,
246         0x00, 0x1c, 0x00, 0x00, 0x40, 0x00, 0x40, 0x01,
247         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
249         0x00, 0x00,
250 };
251
252 static const u8 ice_fdir_ipv6_gtpu6_pkt[] = {
253         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254         0x00, 0x00, 0x00, 0x00, 0x86, 0xdd, 0x60, 0x00,
255         0x00, 0x00, 0x00, 0x38, 0x11, 0x40, 0x00, 0x00,
256         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x68,
260         0x08, 0x68, 0x00, 0x38, 0x22, 0x43, 0x30, 0xff,
261         0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
262         0x00, 0x00, 0x00, 0x00, 0x3b, 0x40, 0x00, 0x00,
263         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 };
268
269 static const u8 ice_fdir_ipv6_gtpu6_eh_pkt[] = {
270         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271         0x00, 0x00, 0x00, 0x00, 0x86, 0xdd, 0x60, 0x00,
272         0x00, 0x00, 0x00, 0x44, 0x11, 0x40, 0x00, 0x00,
273         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x68,
277         0x08, 0x68, 0x00, 0x44, 0x1b, 0x9a, 0x34, 0xff,
278         0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279         0x00, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
280         0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
281         0x3b, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285         0x00, 0x00, 0x00, 0x00,
286 };
287
288 static const u8 ice_fdir_ipv6_gtpu6_eh_dw_pkt[] = {
289         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290         0x00, 0x00, 0x00, 0x00, 0x86, 0xdd, 0x60, 0x00,
291         0x00, 0x00, 0x00, 0x44, 0x11, 0x40, 0x00, 0x00,
292         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x68,
296         0x08, 0x68, 0x00, 0x44, 0x1b, 0x9a, 0x34, 0xff,
297         0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298         0x00, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
299         0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
300         0x3b, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304         0x00, 0x00, 0x00, 0x00,
305 };
306
307 static const u8 ice_fdir_ipv6_gtpu6_eh_up_pkt[] = {
308         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309         0x00, 0x00, 0x00, 0x00, 0x86, 0xdd, 0x60, 0x00,
310         0x00, 0x00, 0x00, 0x44, 0x11, 0x40, 0x00, 0x00,
311         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
313         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x68,
315         0x08, 0x68, 0x00, 0x44, 0x1b, 0x8a, 0x34, 0xff,
316         0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317         0x00, 0x85, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,
318         0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,
319         0x3b, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323         0x00, 0x00, 0x00, 0x00,
324 };
325
326 static const u8 ice_fdir_ipv4_l2tpv3_pkt[] = {
327         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
329         0x00, 0x14, 0x00, 0x00, 0x40, 0x00, 0x40, 0x73,
330         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333 };
334
335 static const u8 ice_fdir_ipv6_l2tpv3_pkt[] = {
336         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
337         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
338         0x00, 0x00, 0x00, 0x00, 0x73, 0x40, 0x00, 0x00,
339         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344         0x00, 0x00,
345 };
346
347 static const u8 ice_fdir_ipv4_esp_pkt[] = {
348         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
350         0x00, 0x14, 0x00, 0x00, 0x40, 0x00, 0x40, 0x32,
351         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353         0x00, 0x00
354 };
355
356 static const u8 ice_fdir_ipv6_esp_pkt[] = {
357         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
358         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
359         0x00, 0x00, 0x00, 0x00, 0x32, 0x40, 0x00, 0x00,
360         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
361         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
363         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
364         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
365 };
366
367 static const u8 ice_fdir_ipv4_ah_pkt[] = {
368         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
369         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
370         0x00, 0x14, 0x00, 0x00, 0x40, 0x00, 0x40, 0x33,
371         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374         0x00, 0x00
375 };
376
377 static const u8 ice_fdir_ipv6_ah_pkt[] = {
378         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
380         0x00, 0x00, 0x00, 0x00, 0x33, 0x40, 0x00, 0x00,
381         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
383         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
384         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
386         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
387 };
388
389 static const u8 ice_fdir_ipv4_nat_t_esp_pkt[] = {
390         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
392         0x00, 0x1C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
393         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
394         0x00, 0x00, 0x00, 0x00, 0x11, 0x94, 0x00, 0x00,
395         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
396         0x00, 0x00,
397 };
398
399 static const u8 ice_fdir_ipv6_nat_t_esp_pkt[] = {
400         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
401         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
402         0x00, 0x00, 0x00, 0x08, 0x11, 0x40, 0x00, 0x00,
403         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
405         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
406         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
407         0x11, 0x94, 0x00, 0x00, 0x00, 0x08,
408 };
409
410 static const u8 ice_fdir_ipv4_pfcp_node_pkt[] = {
411         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
412         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
413         0x00, 0x2C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
414         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415         0x00, 0x00, 0x22, 0x65, 0x22, 0x65, 0x00, 0x00,
416         0x00, 0x00, 0x20, 0x00, 0x00, 0x10, 0x00, 0x00,
417         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
418         0x00, 0x00,
419 };
420
421 static const u8 ice_fdir_ipv4_pfcp_session_pkt[] = {
422         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
423         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
424         0x00, 0x2C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
425         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426         0x00, 0x00, 0x22, 0x65, 0x22, 0x65, 0x00, 0x00,
427         0x00, 0x00, 0x21, 0x00, 0x00, 0x10, 0x00, 0x00,
428         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
429         0x00, 0x00,
430 };
431
432 static const u8 ice_fdir_ipv6_pfcp_node_pkt[] = {
433         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
434         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
435         0x00, 0x00, 0x00, 0x18, 0x11, 0x40, 0x00, 0x00,
436         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
438         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
439         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x65,
440         0x22, 0x65, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
441         0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
442         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
443 };
444
445 static const u8 ice_fdir_ipv6_pfcp_session_pkt[] = {
446         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
447         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
448         0x00, 0x00, 0x00, 0x18, 0x11, 0x40, 0x00, 0x00,
449         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
450         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
451         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
452         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x65,
453         0x22, 0x65, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00,
454         0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
455         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
456 };
457
458 static const u8 ice_fdir_non_ip_l2_pkt[] = {
459         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
460         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
461         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
462 };
463
464 static const u8 ice_fdir_ecpri_tp0_pkt[] = {
465         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
466         0x00, 0x00, 0x00, 0x00, 0xAE, 0xFE, 0x10, 0x00,
467         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
468         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
469 };
470
471 static const u8 ice_fdir_ipv4_udp_ecpri_tp0_pkt[] = {
472         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
473         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
474         0x00, 0x1C, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
475         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
476         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
477         0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
478         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
479 };
480
481 static const u8 ice_fdir_tcpv6_pkt[] = {
482         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
483         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
484         0x00, 0x00, 0x00, 0x14, 0x06, 0x40, 0x00, 0x00,
485         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
486         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
487         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
489         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
490         0x00, 0x00, 0x50, 0x00, 0x20, 0x00, 0x00, 0x00,
491         0x00, 0x00,
492 };
493
494 static const u8 ice_fdir_udpv6_pkt[] = {
495         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
496         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
497         0x00, 0x00, 0x00, 0x08, 0x11, 0x40, 0x00, 0x00,
498         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
499         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
500         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
501         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
502         0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
503 };
504
505 static const u8 ice_fdir_sctpv6_pkt[] = {
506         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
507         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
508         0x00, 0x00, 0x00, 0x0C, 0x84, 0x40, 0x00, 0x00,
509         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
510         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
511         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
512         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
513         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
514         0x00, 0x00,
515 };
516
517 static const u8 ice_fdir_ipv6_pkt[] = {
518         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
519         0x00, 0x00, 0x00, 0x00, 0x86, 0xDD, 0x60, 0x00,
520         0x00, 0x00, 0x00, 0x00, 0x3B, 0x40, 0x00, 0x00,
521         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
522         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
523         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
524         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
525 };
526
527 static const u8 ice_fdir_tcp4_tun_pkt[] = {
528         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
529         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
530         0x00, 0x5a, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
531         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
532         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
533         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
534         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
535         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
536         0x45, 0x00, 0x00, 0x28, 0x00, 0x00, 0x40, 0x00,
537         0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
538         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
539         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
540         0x50, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
541 };
542
543 static const u8 ice_fdir_udp4_tun_pkt[] = {
544         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
545         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
546         0x00, 0x4e, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
547         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
548         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
549         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
550         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
551         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
552         0x45, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x40, 0x00,
553         0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
554         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
555         0x00, 0x00, 0x00, 0x00,
556 };
557
558 static const u8 ice_fdir_sctp4_tun_pkt[] = {
559         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
560         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
561         0x00, 0x52, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
562         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
563         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
564         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
565         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
566         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
567         0x45, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00,
568         0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
569         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
570         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
571 };
572
573 static const u8 ice_fdir_ip4_tun_pkt[] = {
574         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
575         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
576         0x00, 0x46, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
577         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
579         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
580         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
581         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
582         0x45, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
583         0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
584         0x00, 0x00, 0x00, 0x00,
585 };
586
587 static const u8 ice_fdir_tcp6_tun_pkt[] = {
588         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
589         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
590         0x00, 0x6e, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
591         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
592         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
593         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
594         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
595         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
596         0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x06, 0x40,
597         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
598         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
599         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
600         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
601         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
602         0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x20, 0x00,
603         0x00, 0x00, 0x00, 0x00,
604 };
605
606 static const u8 ice_fdir_udp6_tun_pkt[] = {
607         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
608         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
609         0x00, 0x62, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
610         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
611         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
612         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
613         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
614         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
615         0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x40,
616         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
617         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
619         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
621 };
622
623 static const u8 ice_fdir_sctp6_tun_pkt[] = {
624         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
625         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
626         0x00, 0x66, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
627         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
628         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
630         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
631         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
632         0x60, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x84, 0x40,
633         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
634         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
635         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
636         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
637         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
638         0x00, 0x00, 0x00, 0x00,
639 };
640
641 static const u8 ice_fdir_ip6_tun_pkt[] = {
642         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
643         0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
644         0x00, 0x5a, 0x00, 0x00, 0x40, 0x00, 0x40, 0x11,
645         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
647         0x00, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x00,
648         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
649         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xdd,
650         0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x40,
651         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
655 };
656
657 /* Flow Director no-op training packet table */
658 static const struct ice_fdir_base_pkt ice_fdir_pkt[] = {
659         {
660                 ICE_FLTR_PTYPE_NONF_IPV4_TCP,
661                 sizeof(ice_fdir_tcpv4_pkt), ice_fdir_tcpv4_pkt,
662                 sizeof(ice_fdir_tcp4_tun_pkt), ice_fdir_tcp4_tun_pkt,
663         },
664         {
665                 ICE_FLTR_PTYPE_NONF_IPV4_UDP,
666                 sizeof(ice_fdir_udpv4_pkt), ice_fdir_udpv4_pkt,
667                 sizeof(ice_fdir_udp4_tun_pkt), ice_fdir_udp4_tun_pkt,
668         },
669         {
670                 ICE_FLTR_PTYPE_NONF_IPV4_SCTP,
671                 sizeof(ice_fdir_sctpv4_pkt), ice_fdir_sctpv4_pkt,
672                 sizeof(ice_fdir_sctp4_tun_pkt), ice_fdir_sctp4_tun_pkt,
673         },
674         {
675                 ICE_FLTR_PTYPE_NONF_IPV4_OTHER,
676                 sizeof(ice_fdir_ipv4_pkt), ice_fdir_ipv4_pkt,
677                 sizeof(ice_fdir_ip4_tun_pkt), ice_fdir_ip4_tun_pkt,
678         },
679         {
680                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU,
681                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
682                 ice_fdir_ipv4_gtpu4_pkt,
683                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
684                 ice_fdir_ipv4_gtpu4_pkt,
685         },
686         {
687                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH,
688                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
689                 ice_fdir_ipv4_gtpu4_eh_pkt,
690                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
691                 ice_fdir_ipv4_gtpu4_eh_pkt,
692         },
693         {
694                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW,
695                 sizeof(ice_fdir_ipv4_gtpu4_eh_dw_pkt),
696                 ice_fdir_ipv4_gtpu4_eh_dw_pkt,
697                 sizeof(ice_fdir_ipv4_gtpu4_eh_dw_pkt),
698                 ice_fdir_ipv4_gtpu4_eh_dw_pkt,
699         },
700         {
701                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP,
702                 sizeof(ice_fdir_ipv4_gtpu4_eh_up_pkt),
703                 ice_fdir_ipv4_gtpu4_eh_up_pkt,
704                 sizeof(ice_fdir_ipv4_gtpu4_eh_up_pkt),
705                 ice_fdir_ipv4_gtpu4_eh_up_pkt,
706         },
707         {
708                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4,
709                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
710                 ice_fdir_ipv4_gtpu4_pkt,
711                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
712                 ice_fdir_ipv4_gtpu4_pkt,
713         },
714         {
715                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP,
716                 sizeof(ice_fdir_udp4_gtpu4_pkt),
717                 ice_fdir_udp4_gtpu4_pkt,
718                 sizeof(ice_fdir_udp4_gtpu4_pkt),
719                 ice_fdir_udp4_gtpu4_pkt,
720         },
721         {
722                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP,
723                 sizeof(ice_fdir_tcp4_gtpu4_pkt),
724                 ice_fdir_tcp4_gtpu4_pkt,
725                 sizeof(ice_fdir_tcp4_gtpu4_pkt),
726                 ice_fdir_tcp4_gtpu4_pkt,
727         },
728         {
729                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4,
730                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
731                 ice_fdir_ipv4_gtpu4_eh_pkt,
732                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
733                 ice_fdir_ipv4_gtpu4_eh_pkt,
734         },
735         {
736                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_UDP,
737                 sizeof(ice_fdir_udp4_gtpu4_eh_pkt),
738                 ice_fdir_udp4_gtpu4_eh_pkt,
739                 sizeof(ice_fdir_udp4_gtpu4_eh_pkt),
740                 ice_fdir_udp4_gtpu4_eh_pkt,
741         },
742         {
743                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_TCP,
744                 sizeof(ice_fdir_tcp4_gtpu4_eh_pkt),
745                 ice_fdir_tcp4_gtpu4_eh_pkt,
746                 sizeof(ice_fdir_tcp4_gtpu4_eh_pkt),
747                 ice_fdir_tcp4_gtpu4_eh_pkt,
748         },
749         {
750                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4,
751                 sizeof(ice_fdir_ipv4_gtpu4_eh_dw_pkt),
752                 ice_fdir_ipv4_gtpu4_eh_dw_pkt,
753                 sizeof(ice_fdir_ipv4_gtpu4_eh_dw_pkt),
754                 ice_fdir_ipv4_gtpu4_eh_dw_pkt,
755         },
756         {
757                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_UDP,
758                 sizeof(ice_fdir_udp4_gtpu4_eh_dw_pkt),
759                 ice_fdir_udp4_gtpu4_eh_dw_pkt,
760                 sizeof(ice_fdir_udp4_gtpu4_eh_dw_pkt),
761                 ice_fdir_udp4_gtpu4_eh_dw_pkt,
762         },
763         {
764                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_TCP,
765                 sizeof(ice_fdir_tcp4_gtpu4_eh_dw_pkt),
766                 ice_fdir_tcp4_gtpu4_eh_dw_pkt,
767                 sizeof(ice_fdir_tcp4_gtpu4_eh_dw_pkt),
768                 ice_fdir_tcp4_gtpu4_eh_dw_pkt,
769         },
770         {
771                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4,
772                 sizeof(ice_fdir_ipv4_gtpu4_eh_up_pkt),
773                 ice_fdir_ipv4_gtpu4_eh_up_pkt,
774                 sizeof(ice_fdir_ipv4_gtpu4_eh_up_pkt),
775                 ice_fdir_ipv4_gtpu4_eh_up_pkt,
776         },
777         {
778                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_UDP,
779                 sizeof(ice_fdir_udp4_gtpu4_eh_up_pkt),
780                 ice_fdir_udp4_gtpu4_eh_up_pkt,
781                 sizeof(ice_fdir_udp4_gtpu4_eh_up_pkt),
782                 ice_fdir_udp4_gtpu4_eh_up_pkt,
783         },
784         {
785                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_TCP,
786                 sizeof(ice_fdir_tcp4_gtpu4_eh_up_pkt),
787                 ice_fdir_tcp4_gtpu4_eh_up_pkt,
788                 sizeof(ice_fdir_tcp4_gtpu4_eh_up_pkt),
789                 ice_fdir_tcp4_gtpu4_eh_up_pkt,
790         },
791         {
792                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP,
793                 sizeof(ice_fdir_icmp4_gtpu4_pkt),
794                 ice_fdir_icmp4_gtpu4_pkt,
795                 sizeof(ice_fdir_icmp4_gtpu4_pkt),
796                 ice_fdir_icmp4_gtpu4_pkt,
797         },
798         {
799                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER,
800                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
801                 ice_fdir_ipv4_gtpu4_pkt,
802                 sizeof(ice_fdir_ipv4_gtpu4_pkt),
803                 ice_fdir_ipv4_gtpu4_pkt,
804         },
805         {
806                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU,
807                 sizeof(ice_fdir_ipv6_gtpu6_pkt),
808                 ice_fdir_ipv6_gtpu6_pkt,
809                 sizeof(ice_fdir_ipv6_gtpu6_pkt),
810                 ice_fdir_ipv6_gtpu6_pkt,
811         },
812         {
813                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH,
814                 sizeof(ice_fdir_ipv6_gtpu6_eh_pkt),
815                 ice_fdir_ipv6_gtpu6_eh_pkt,
816                 sizeof(ice_fdir_ipv6_gtpu6_eh_pkt),
817                 ice_fdir_ipv6_gtpu6_eh_pkt,
818         },
819         {
820                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_DW,
821                 sizeof(ice_fdir_ipv6_gtpu6_eh_dw_pkt),
822                 ice_fdir_ipv6_gtpu6_eh_dw_pkt,
823                 sizeof(ice_fdir_ipv6_gtpu6_eh_dw_pkt),
824                 ice_fdir_ipv6_gtpu6_eh_dw_pkt,
825         },
826         {
827                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_UP,
828                 sizeof(ice_fdir_ipv6_gtpu6_eh_up_pkt),
829                 ice_fdir_ipv6_gtpu6_eh_up_pkt,
830                 sizeof(ice_fdir_ipv6_gtpu6_eh_up_pkt),
831                 ice_fdir_ipv6_gtpu6_eh_up_pkt,
832         },
833         {
834                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU_IPV6_OTHER,
835                 sizeof(ice_fdir_ipv6_gtpu6_pkt),
836                 ice_fdir_ipv6_gtpu6_pkt,
837                 sizeof(ice_fdir_ipv6_gtpu6_pkt),
838                 ice_fdir_ipv6_gtpu6_pkt,
839         },
840         {
841                 ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_OTHER,
842                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
843                 ice_fdir_ipv4_gtpu4_eh_pkt,
844                 sizeof(ice_fdir_ipv4_gtpu4_eh_pkt),
845                 ice_fdir_ipv4_gtpu4_eh_pkt,
846         },
847         {
848                 ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_IPV6_OTHER,
849                 sizeof(ice_fdir_ipv6_gtpu6_eh_pkt),
850                 ice_fdir_ipv6_gtpu6_eh_pkt,
851                 sizeof(ice_fdir_ipv6_gtpu6_eh_pkt),
852                 ice_fdir_ipv6_gtpu6_eh_pkt,
853         },
854         {
855                 ICE_FLTR_PTYPE_NONF_IPV4_L2TPV3,
856                 sizeof(ice_fdir_ipv4_l2tpv3_pkt), ice_fdir_ipv4_l2tpv3_pkt,
857                 sizeof(ice_fdir_ipv4_l2tpv3_pkt), ice_fdir_ipv4_l2tpv3_pkt,
858         },
859         {
860                 ICE_FLTR_PTYPE_NONF_IPV6_L2TPV3,
861                 sizeof(ice_fdir_ipv6_l2tpv3_pkt), ice_fdir_ipv6_l2tpv3_pkt,
862                 sizeof(ice_fdir_ipv6_l2tpv3_pkt), ice_fdir_ipv6_l2tpv3_pkt,
863         },
864         {
865                 ICE_FLTR_PTYPE_NONF_IPV4_ESP,
866                 sizeof(ice_fdir_ipv4_esp_pkt), ice_fdir_ipv4_esp_pkt,
867                 sizeof(ice_fdir_ipv4_esp_pkt), ice_fdir_ipv4_esp_pkt,
868         },
869         {
870                 ICE_FLTR_PTYPE_NONF_IPV6_ESP,
871                 sizeof(ice_fdir_ipv6_esp_pkt), ice_fdir_ipv6_esp_pkt,
872                 sizeof(ice_fdir_ipv6_esp_pkt), ice_fdir_ipv6_esp_pkt,
873         },
874         {
875                 ICE_FLTR_PTYPE_NONF_IPV4_AH,
876                 sizeof(ice_fdir_ipv4_ah_pkt), ice_fdir_ipv4_ah_pkt,
877                 sizeof(ice_fdir_ipv4_ah_pkt), ice_fdir_ipv4_ah_pkt,
878         },
879         {
880                 ICE_FLTR_PTYPE_NONF_IPV6_AH,
881                 sizeof(ice_fdir_ipv6_ah_pkt), ice_fdir_ipv6_ah_pkt,
882                 sizeof(ice_fdir_ipv6_ah_pkt), ice_fdir_ipv6_ah_pkt,
883         },
884         {
885                 ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP,
886                 sizeof(ice_fdir_ipv4_nat_t_esp_pkt),
887                 ice_fdir_ipv4_nat_t_esp_pkt,
888                 sizeof(ice_fdir_ipv4_nat_t_esp_pkt),
889                 ice_fdir_ipv4_nat_t_esp_pkt,
890         },
891         {
892                 ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP,
893                 sizeof(ice_fdir_ipv6_nat_t_esp_pkt),
894                 ice_fdir_ipv6_nat_t_esp_pkt,
895                 sizeof(ice_fdir_ipv6_nat_t_esp_pkt),
896                 ice_fdir_ipv6_nat_t_esp_pkt,
897         },
898         {
899                 ICE_FLTR_PTYPE_NONF_IPV4_PFCP_NODE,
900                 sizeof(ice_fdir_ipv4_pfcp_node_pkt),
901                 ice_fdir_ipv4_pfcp_node_pkt,
902                 sizeof(ice_fdir_ipv4_pfcp_node_pkt),
903                 ice_fdir_ipv4_pfcp_node_pkt,
904         },
905         {
906                 ICE_FLTR_PTYPE_NONF_IPV4_PFCP_SESSION,
907                 sizeof(ice_fdir_ipv4_pfcp_session_pkt),
908                 ice_fdir_ipv4_pfcp_session_pkt,
909                 sizeof(ice_fdir_ipv4_pfcp_session_pkt),
910                 ice_fdir_ipv4_pfcp_session_pkt,
911         },
912         {
913                 ICE_FLTR_PTYPE_NONF_IPV6_PFCP_NODE,
914                 sizeof(ice_fdir_ipv6_pfcp_node_pkt),
915                 ice_fdir_ipv6_pfcp_node_pkt,
916                 sizeof(ice_fdir_ipv6_pfcp_node_pkt),
917                 ice_fdir_ipv6_pfcp_node_pkt,
918         },
919         {
920                 ICE_FLTR_PTYPE_NONF_IPV6_PFCP_SESSION,
921                 sizeof(ice_fdir_ipv6_pfcp_session_pkt),
922                 ice_fdir_ipv6_pfcp_session_pkt,
923                 sizeof(ice_fdir_ipv6_pfcp_session_pkt),
924                 ice_fdir_ipv6_pfcp_session_pkt,
925         },
926         {
927                 ICE_FLTR_PTYPE_NON_IP_L2,
928                 sizeof(ice_fdir_non_ip_l2_pkt), ice_fdir_non_ip_l2_pkt,
929                 sizeof(ice_fdir_non_ip_l2_pkt), ice_fdir_non_ip_l2_pkt,
930         },
931         {
932                 ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN,
933                 sizeof(ice_fdir_udp4_vxlan_pkt), ice_fdir_udp4_vxlan_pkt,
934                 sizeof(ice_fdir_udp4_vxlan_pkt), ice_fdir_udp4_vxlan_pkt,
935         },
936         {
937                 ICE_FLTR_PTYPE_NONF_ECPRI_TP0,
938                 sizeof(ice_fdir_ecpri_tp0_pkt), ice_fdir_ecpri_tp0_pkt,
939                 sizeof(ice_fdir_ecpri_tp0_pkt), ice_fdir_ecpri_tp0_pkt,
940         },
941         {
942                 ICE_FLTR_PTYPE_NONF_IPV4_UDP_ECPRI_TP0,
943                 sizeof(ice_fdir_ipv4_udp_ecpri_tp0_pkt),
944                 ice_fdir_ipv4_udp_ecpri_tp0_pkt,
945                 sizeof(ice_fdir_ipv4_udp_ecpri_tp0_pkt),
946                 ice_fdir_ipv4_udp_ecpri_tp0_pkt,
947         },
948         {
949                 ICE_FLTR_PTYPE_NONF_IPV6_TCP,
950                 sizeof(ice_fdir_tcpv6_pkt), ice_fdir_tcpv6_pkt,
951                 sizeof(ice_fdir_tcp6_tun_pkt), ice_fdir_tcp6_tun_pkt,
952         },
953         {
954                 ICE_FLTR_PTYPE_NONF_IPV6_UDP,
955                 sizeof(ice_fdir_udpv6_pkt), ice_fdir_udpv6_pkt,
956                 sizeof(ice_fdir_udp6_tun_pkt), ice_fdir_udp6_tun_pkt,
957         },
958         {
959                 ICE_FLTR_PTYPE_NONF_IPV6_SCTP,
960                 sizeof(ice_fdir_sctpv6_pkt), ice_fdir_sctpv6_pkt,
961                 sizeof(ice_fdir_sctp6_tun_pkt), ice_fdir_sctp6_tun_pkt,
962         },
963         {
964                 ICE_FLTR_PTYPE_NONF_IPV6_OTHER,
965                 sizeof(ice_fdir_ipv6_pkt), ice_fdir_ipv6_pkt,
966                 sizeof(ice_fdir_ip6_tun_pkt), ice_fdir_ip6_tun_pkt,
967         },
968 };
969
970 #define ICE_FDIR_NUM_PKT ARRAY_SIZE(ice_fdir_pkt)
971
972 /**
973  * ice_set_dflt_val_fd_desc
974  * @fd_fltr_ctx: pointer to fd filter descriptor
975  */
976 static void ice_set_dflt_val_fd_desc(struct ice_fd_fltr_desc_ctx *fd_fltr_ctx)
977 {
978         fd_fltr_ctx->comp_q = ICE_FXD_FLTR_QW0_COMP_Q_ZERO;
979         fd_fltr_ctx->comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW_FAIL;
980         fd_fltr_ctx->fd_space = ICE_FXD_FLTR_QW0_FD_SPACE_GUAR_BEST;
981         fd_fltr_ctx->cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
982         fd_fltr_ctx->evict_ena = ICE_FXD_FLTR_QW0_EVICT_ENA_TRUE;
983         fd_fltr_ctx->toq = ICE_FXD_FLTR_QW0_TO_Q_EQUALS_QINDEX;
984         fd_fltr_ctx->toq_prio = ICE_FXD_FLTR_QW0_TO_Q_PRIO1;
985         fd_fltr_ctx->dpu_recipe = ICE_FXD_FLTR_QW0_DPU_RECIPE_DFLT;
986         fd_fltr_ctx->drop = ICE_FXD_FLTR_QW0_DROP_NO;
987         fd_fltr_ctx->flex_prio = ICE_FXD_FLTR_QW0_FLEX_PRI_NONE;
988         fd_fltr_ctx->flex_mdid = ICE_FXD_FLTR_QW0_FLEX_MDID0;
989         fd_fltr_ctx->flex_val = ICE_FXD_FLTR_QW0_FLEX_VAL0;
990         fd_fltr_ctx->dtype = ICE_TX_DESC_DTYPE_FLTR_PROG;
991         fd_fltr_ctx->desc_prof_prio = ICE_FXD_FLTR_QW1_PROF_PRIO_ZERO;
992         fd_fltr_ctx->desc_prof = ICE_FXD_FLTR_QW1_PROF_ZERO;
993         fd_fltr_ctx->swap = ICE_FXD_FLTR_QW1_SWAP_SET;
994         fd_fltr_ctx->fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_ONE;
995         fd_fltr_ctx->fdid_mdid = ICE_FXD_FLTR_QW1_FDID_MDID_FD;
996         fd_fltr_ctx->fdid = ICE_FXD_FLTR_QW1_FDID_ZERO;
997 }
998
999 /**
1000  * ice_set_fd_desc_val
1001  * @ctx: pointer to fd filter descriptor context
1002  * @fdir_desc: populated with fd filter descriptor values
1003  */
1004 static void
1005 ice_set_fd_desc_val(struct ice_fd_fltr_desc_ctx *ctx,
1006                     struct ice_fltr_desc *fdir_desc)
1007 {
1008         u64 qword;
1009
1010         /* prep QW0 of FD filter programming desc */
1011         qword = ((u64)ctx->qindex << ICE_FXD_FLTR_QW0_QINDEX_S) &
1012                 ICE_FXD_FLTR_QW0_QINDEX_M;
1013         qword |= ((u64)ctx->comp_q << ICE_FXD_FLTR_QW0_COMP_Q_S) &
1014                  ICE_FXD_FLTR_QW0_COMP_Q_M;
1015         qword |= ((u64)ctx->comp_report << ICE_FXD_FLTR_QW0_COMP_REPORT_S) &
1016                  ICE_FXD_FLTR_QW0_COMP_REPORT_M;
1017         qword |= ((u64)ctx->fd_space << ICE_FXD_FLTR_QW0_FD_SPACE_S) &
1018                  ICE_FXD_FLTR_QW0_FD_SPACE_M;
1019         qword |= ((u64)ctx->cnt_index << ICE_FXD_FLTR_QW0_STAT_CNT_S) &
1020                  ICE_FXD_FLTR_QW0_STAT_CNT_M;
1021         qword |= ((u64)ctx->cnt_ena << ICE_FXD_FLTR_QW0_STAT_ENA_S) &
1022                  ICE_FXD_FLTR_QW0_STAT_ENA_M;
1023         qword |= ((u64)ctx->evict_ena << ICE_FXD_FLTR_QW0_EVICT_ENA_S) &
1024                  ICE_FXD_FLTR_QW0_EVICT_ENA_M;
1025         qword |= ((u64)ctx->toq << ICE_FXD_FLTR_QW0_TO_Q_S) &
1026                  ICE_FXD_FLTR_QW0_TO_Q_M;
1027         qword |= ((u64)ctx->toq_prio << ICE_FXD_FLTR_QW0_TO_Q_PRI_S) &
1028                  ICE_FXD_FLTR_QW0_TO_Q_PRI_M;
1029         qword |= ((u64)ctx->dpu_recipe << ICE_FXD_FLTR_QW0_DPU_RECIPE_S) &
1030                  ICE_FXD_FLTR_QW0_DPU_RECIPE_M;
1031         qword |= ((u64)ctx->drop << ICE_FXD_FLTR_QW0_DROP_S) &
1032                  ICE_FXD_FLTR_QW0_DROP_M;
1033         qword |= ((u64)ctx->flex_prio << ICE_FXD_FLTR_QW0_FLEX_PRI_S) &
1034                  ICE_FXD_FLTR_QW0_FLEX_PRI_M;
1035         qword |= ((u64)ctx->flex_mdid << ICE_FXD_FLTR_QW0_FLEX_MDID_S) &
1036                  ICE_FXD_FLTR_QW0_FLEX_MDID_M;
1037         qword |= ((u64)ctx->flex_val << ICE_FXD_FLTR_QW0_FLEX_VAL_S) &
1038                  ICE_FXD_FLTR_QW0_FLEX_VAL_M;
1039         fdir_desc->qidx_compq_space_stat = CPU_TO_LE64(qword);
1040
1041         /* prep QW1 of FD filter programming desc */
1042         qword = ((u64)ctx->dtype << ICE_FXD_FLTR_QW1_DTYPE_S) &
1043                 ICE_FXD_FLTR_QW1_DTYPE_M;
1044         qword |= ((u64)ctx->pcmd << ICE_FXD_FLTR_QW1_PCMD_S) &
1045                  ICE_FXD_FLTR_QW1_PCMD_M;
1046         qword |= ((u64)ctx->desc_prof_prio << ICE_FXD_FLTR_QW1_PROF_PRI_S) &
1047                  ICE_FXD_FLTR_QW1_PROF_PRI_M;
1048         qword |= ((u64)ctx->desc_prof << ICE_FXD_FLTR_QW1_PROF_S) &
1049                  ICE_FXD_FLTR_QW1_PROF_M;
1050         qword |= ((u64)ctx->fd_vsi << ICE_FXD_FLTR_QW1_FD_VSI_S) &
1051                  ICE_FXD_FLTR_QW1_FD_VSI_M;
1052         qword |= ((u64)ctx->swap << ICE_FXD_FLTR_QW1_SWAP_S) &
1053                  ICE_FXD_FLTR_QW1_SWAP_M;
1054         qword |= ((u64)ctx->fdid_prio << ICE_FXD_FLTR_QW1_FDID_PRI_S) &
1055                  ICE_FXD_FLTR_QW1_FDID_PRI_M;
1056         qword |= ((u64)ctx->fdid_mdid << ICE_FXD_FLTR_QW1_FDID_MDID_S) &
1057                  ICE_FXD_FLTR_QW1_FDID_MDID_M;
1058         qword |= ((u64)ctx->fdid << ICE_FXD_FLTR_QW1_FDID_S) &
1059                  ICE_FXD_FLTR_QW1_FDID_M;
1060         fdir_desc->dtype_cmd_vsi_fdid = CPU_TO_LE64(qword);
1061 }
1062
1063 /**
1064  * ice_fdir_get_prgm_desc - set a fdir descriptor from a fdir filter struct
1065  * @hw: pointer to the hardware structure
1066  * @input: filter
1067  * @fdesc: filter descriptor
1068  * @add: if add is true, this is an add operation, false implies delete
1069  */
1070 void
1071 ice_fdir_get_prgm_desc(struct ice_hw *hw, struct ice_fdir_fltr *input,
1072                        struct ice_fltr_desc *fdesc, bool add)
1073 {
1074         struct ice_fd_fltr_desc_ctx fdir_fltr_ctx = { 0 };
1075
1076         /* set default context info */
1077         ice_set_dflt_val_fd_desc(&fdir_fltr_ctx);
1078
1079         /* change sideband filtering values */
1080         fdir_fltr_ctx.fdid = input->fltr_id;
1081         if (input->dest_ctl == ICE_FLTR_PRGM_DESC_DEST_DROP_PKT) {
1082                 fdir_fltr_ctx.drop = ICE_FXD_FLTR_QW0_DROP_YES;
1083                 fdir_fltr_ctx.qindex = 0;
1084         } else if (input->dest_ctl ==
1085                    ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER) {
1086                 fdir_fltr_ctx.drop = ICE_FXD_FLTR_QW0_DROP_NO;
1087                 fdir_fltr_ctx.qindex = 0;
1088         } else {
1089                 if (input->dest_ctl ==
1090                     ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP)
1091                         fdir_fltr_ctx.toq = input->q_region;
1092                 fdir_fltr_ctx.drop = ICE_FXD_FLTR_QW0_DROP_NO;
1093                 fdir_fltr_ctx.qindex = input->q_index;
1094         }
1095         fdir_fltr_ctx.cnt_ena = input->cnt_ena;
1096         fdir_fltr_ctx.cnt_index = input->cnt_index;
1097         fdir_fltr_ctx.fd_vsi = ice_get_hw_vsi_num(hw, input->dest_vsi);
1098         fdir_fltr_ctx.evict_ena = ICE_FXD_FLTR_QW0_EVICT_ENA_FALSE;
1099         if (input->dest_ctl == ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER)
1100                 fdir_fltr_ctx.toq_prio = 0;
1101         else
1102                 fdir_fltr_ctx.toq_prio = 3;
1103         fdir_fltr_ctx.pcmd = add ? ICE_FXD_FLTR_QW1_PCMD_ADD :
1104                 ICE_FXD_FLTR_QW1_PCMD_REMOVE;
1105         fdir_fltr_ctx.swap = ICE_FXD_FLTR_QW1_SWAP_NOT_SET;
1106         fdir_fltr_ctx.comp_q = ICE_FXD_FLTR_QW0_COMP_Q_ZERO;
1107         fdir_fltr_ctx.comp_report = input->comp_report;
1108         fdir_fltr_ctx.fdid_prio = input->fdid_prio;
1109         fdir_fltr_ctx.desc_prof = 1;
1110         fdir_fltr_ctx.desc_prof_prio = 3;
1111         ice_set_fd_desc_val(&fdir_fltr_ctx, fdesc);
1112 }
1113
1114 /**
1115  * ice_alloc_fd_res_cntr - obtain counter resource for FD type
1116  * @hw: pointer to the hardware structure
1117  * @cntr_id: returns counter index
1118  */
1119 enum ice_status ice_alloc_fd_res_cntr(struct ice_hw *hw, u16 *cntr_id)
1120 {
1121         return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_COUNTER_BLOCK,
1122                                   ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1, cntr_id);
1123 }
1124
1125 /**
1126  * ice_free_fd_res_cntr - Free counter resource for FD type
1127  * @hw: pointer to the hardware structure
1128  * @cntr_id: counter index to be freed
1129  */
1130 enum ice_status ice_free_fd_res_cntr(struct ice_hw *hw, u16 cntr_id)
1131 {
1132         return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_COUNTER_BLOCK,
1133                                  ICE_AQC_RES_TYPE_FLAG_DEDICATED, 1, cntr_id);
1134 }
1135
1136 /**
1137  * ice_alloc_fd_guar_item - allocate resource for FD guaranteed entries
1138  * @hw: pointer to the hardware structure
1139  * @cntr_id: returns counter index
1140  * @num_fltr: number of filter entries to be allocated
1141  */
1142 enum ice_status
1143 ice_alloc_fd_guar_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr)
1144 {
1145         return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_GUARANTEED_ENTRIES,
1146                                   ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
1147                                   cntr_id);
1148 }
1149
1150 /**
1151  * ice_free_fd_guar_item - Free flow director guaranteed entries
1152  * @hw: pointer to the hardware structure
1153  * @cntr_id: counter index that needs to be freed
1154  * @num_fltr: number of filters to be freed
1155  */
1156 enum ice_status
1157 ice_free_fd_guar_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr)
1158 {
1159         return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_GUARANTEED_ENTRIES,
1160                                  ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
1161                                  cntr_id);
1162 }
1163
1164 /**
1165  * ice_alloc_fd_shrd_item - allocate resource for flow director shared entries
1166  * @hw: pointer to the hardware structure
1167  * @cntr_id: returns counter index
1168  * @num_fltr: number of filter entries to be allocated
1169  */
1170 enum ice_status
1171 ice_alloc_fd_shrd_item(struct ice_hw *hw, u16 *cntr_id, u16 num_fltr)
1172 {
1173         return ice_alloc_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_SHARED_ENTRIES,
1174                                   ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
1175                                   cntr_id);
1176 }
1177
1178 /**
1179  * ice_free_fd_shrd_item - Free flow director shared entries
1180  * @hw: pointer to the hardware structure
1181  * @cntr_id: counter index that needs to be freed
1182  * @num_fltr: number of filters to be freed
1183  */
1184 enum ice_status
1185 ice_free_fd_shrd_item(struct ice_hw *hw, u16 cntr_id, u16 num_fltr)
1186 {
1187         return ice_free_res_cntr(hw, ICE_AQC_RES_TYPE_FDIR_SHARED_ENTRIES,
1188                                  ICE_AQC_RES_TYPE_FLAG_DEDICATED, num_fltr,
1189                                  cntr_id);
1190 }
1191
1192 /**
1193  * ice_get_fdir_cnt_all - get the number of Flow Director filters
1194  * @hw: hardware data structure
1195  *
1196  * Returns the number of filters available on device
1197  */
1198 int ice_get_fdir_cnt_all(struct ice_hw *hw)
1199 {
1200         return hw->func_caps.fd_fltr_guar + hw->func_caps.fd_fltr_best_effort;
1201 }
1202
1203 /**
1204  * ice_pkt_insert_ipv6_addr - insert a be32 IPv6 address into a memory buffer.
1205  * @pkt: packet buffer
1206  * @offset: offset into buffer
1207  * @addr: IPv6 address to convert and insert into pkt at offset
1208  */
1209 static void ice_pkt_insert_ipv6_addr(u8 *pkt, int offset, __be32 *addr)
1210 {
1211         int idx;
1212
1213         for (idx = 0; idx < ICE_IPV6_ADDR_LEN_AS_U32; idx++)
1214                 ice_memcpy(pkt + offset + idx * sizeof(*addr), &addr[idx],
1215                            sizeof(*addr), ICE_NONDMA_TO_NONDMA);
1216 }
1217
1218 /**
1219  * ice_pkt_insert_u6_qfi - insert a u6 value qfi into a memory buffer for gtpu
1220  * @pkt: packet buffer
1221  * @offset: offset into buffer
1222  * @data: 8 bit value to convert and insert into pkt at offset
1223  *
1224  * This function is designed for inserting qfi (6 bits) for gtpu.
1225  */
1226 static void ice_pkt_insert_u6_qfi(u8 *pkt, int offset, u8 data)
1227 {
1228         u8 ret;
1229
1230         ret = (data & 0x3F) + (*(pkt + offset) & 0xC0);
1231         ice_memcpy(pkt + offset, &ret, sizeof(ret), ICE_NONDMA_TO_NONDMA);
1232 }
1233
1234 /**
1235  * ice_pkt_insert_u8 - insert a u8 value into a memory buffer.
1236  * @pkt: packet buffer
1237  * @offset: offset into buffer
1238  * @data: 8 bit value to convert and insert into pkt at offset
1239  */
1240 static void ice_pkt_insert_u8(u8 *pkt, int offset, u8 data)
1241 {
1242         ice_memcpy(pkt + offset, &data, sizeof(data), ICE_NONDMA_TO_NONDMA);
1243 }
1244
1245 /**
1246  * ice_pkt_insert_u8_tc - insert a u8 value into a memory buffer for TC ipv6.
1247  * @pkt: packet buffer
1248  * @offset: offset into buffer
1249  * @data: 8 bit value to convert and insert into pkt at offset
1250  *
1251  * This function is designed for inserting Traffic Class (TC) for IPv6,
1252  * since that TC is not aligned in number of bytes. Here we split it out
1253  * into two part and fill each byte with data copy from pkt, then insert
1254  * the two bytes data one by one.
1255  */
1256 static void ice_pkt_insert_u8_tc(u8 *pkt, int offset, u8 data)
1257 {
1258         u8 high, low;
1259
1260         high = (data >> 4) + (*(pkt + offset) & 0xF0);
1261         ice_memcpy(pkt + offset, &high, sizeof(high), ICE_NONDMA_TO_NONDMA);
1262
1263         low = (*(pkt + offset + 1) & 0x0F) + ((data & 0x0F) << 4);
1264         ice_memcpy(pkt + offset + 1, &low, sizeof(low), ICE_NONDMA_TO_NONDMA);
1265 }
1266
1267 /**
1268  * ice_pkt_insert_u16 - insert a be16 value into a memory buffer.
1269  * @pkt: packet buffer
1270  * @offset: offset into buffer
1271  * @data: 16 bit value to convert and insert into pkt at offset
1272  */
1273 static void ice_pkt_insert_u16(u8 *pkt, int offset, __be16 data)
1274 {
1275         ice_memcpy(pkt + offset, &data, sizeof(data), ICE_NONDMA_TO_NONDMA);
1276 }
1277
1278 /**
1279  * ice_pkt_insert_u32 - insert a be32 value into a memory buffer.
1280  * @pkt: packet buffer
1281  * @offset: offset into buffer
1282  * @data: 32 bit value to convert and insert into pkt at offset
1283  */
1284 static void ice_pkt_insert_u32(u8 *pkt, int offset, __be32 data)
1285 {
1286         ice_memcpy(pkt + offset, &data, sizeof(data), ICE_NONDMA_TO_NONDMA);
1287 }
1288
1289 /**
1290  * ice_pkt_insert_mac_addr - insert a MAC addr into a memory buffer.
1291  * @pkt: packet buffer
1292  * @addr: MAC address to convert and insert into pkt at offset
1293  */
1294 static void ice_pkt_insert_mac_addr(u8 *pkt, u8 *addr)
1295 {
1296         ice_memcpy(pkt, addr, ETH_ALEN, ICE_NONDMA_TO_NONDMA);
1297 }
1298
1299 /**
1300  * ice_fdir_get_open_tunnel_port
1301  * @hw: pointer to the hardware structure
1302  * @flow: flow ptype
1303  * @port: returns open port
1304  *
1305  * returns an open tunnel port specified for this flow type
1306  */
1307 static enum ice_status
1308 ice_fdir_get_open_tunnel_port(struct ice_hw *hw, enum ice_fltr_ptype flow,
1309                               u16 *port)
1310 {
1311         switch (flow) {
1312         case ICE_FLTR_PTYPE_NONF_IPV4_UDP_ECPRI_TP0:
1313                 /* eCPRI tunnel */
1314                 if (!ice_get_open_tunnel_port(hw, TNL_ECPRI, port))
1315                         return ICE_ERR_DOES_NOT_EXIST;
1316                 break;
1317         default:
1318                 if (!ice_get_open_tunnel_port(hw, TNL_VXLAN, port) &&
1319                     !ice_get_open_tunnel_port(hw, TNL_GENEVE, port))
1320                         return ICE_ERR_DOES_NOT_EXIST;
1321         }
1322
1323         return ICE_SUCCESS;
1324 }
1325
1326 /**
1327  * ice_fdir_get_gen_prgm_pkt - generate a training packet
1328  * @hw: pointer to the hardware structure
1329  * @input: flow director filter data structure
1330  * @pkt: pointer to return filter packet
1331  * @frag: generate a fragment packet
1332  * @tun: true implies generate a tunnel packet
1333  */
1334 enum ice_status
1335 ice_fdir_get_gen_prgm_pkt(struct ice_hw *hw, struct ice_fdir_fltr *input,
1336                           u8 *pkt, bool frag, bool tun)
1337 {
1338         enum ice_fltr_ptype flow;
1339         u16 tnl_port;
1340         u8 *loc;
1341         u16 idx;
1342
1343         if (input->flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER) {
1344                 switch (input->ip.v4.proto) {
1345                 case ICE_IP_PROTO_TCP:
1346                         flow = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
1347                         break;
1348                 case ICE_IP_PROTO_UDP:
1349                         flow = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
1350                         break;
1351                 case ICE_IP_PROTO_SCTP:
1352                         flow = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
1353                         break;
1354                 default:
1355                         flow = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
1356                         break;
1357                 }
1358         } else if (input->flow_type == ICE_FLTR_PTYPE_NONF_IPV6_OTHER) {
1359                 switch (input->ip.v6.proto) {
1360                 case ICE_IP_PROTO_TCP:
1361                         flow = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
1362                         break;
1363                 case ICE_IP_PROTO_UDP:
1364                         flow = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
1365                         break;
1366                 case ICE_IP_PROTO_SCTP:
1367                         flow = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
1368                         break;
1369                 default:
1370                         flow = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
1371                         break;
1372                 }
1373         } else {
1374                 flow = input->flow_type;
1375         }
1376
1377         for (idx = 0; idx < ICE_FDIR_NUM_PKT; idx++)
1378                 if (ice_fdir_pkt[idx].flow == flow)
1379                         break;
1380         if (idx == ICE_FDIR_NUM_PKT)
1381                 return ICE_ERR_PARAM;
1382         if (!tun) {
1383                 ice_memcpy(pkt, ice_fdir_pkt[idx].pkt,
1384                            ice_fdir_pkt[idx].pkt_len, ICE_NONDMA_TO_NONDMA);
1385                 loc = pkt;
1386         } else {
1387                 if (!ice_fdir_pkt[idx].tun_pkt)
1388                         return ICE_ERR_PARAM;
1389
1390                 switch (flow) {
1391                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4:
1392                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
1393                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
1394                         ice_memcpy(pkt, ice_fdir_pkt[idx].tun_pkt,
1395                                    ice_fdir_pkt[idx].tun_pkt_len,
1396                                    ICE_NONDMA_TO_NONDMA);
1397                         loc = &pkt[ICE_FDIR_GTPU_IP_INNER_PKT_OFF];
1398                         break;
1399                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4:
1400                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_UDP:
1401                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_TCP:
1402                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4:
1403                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_UDP:
1404                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_TCP:
1405                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4:
1406                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_UDP:
1407                 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_TCP:
1408                         ice_memcpy(pkt, ice_fdir_pkt[idx].tun_pkt,
1409                                    ice_fdir_pkt[idx].tun_pkt_len,
1410                                    ICE_NONDMA_TO_NONDMA);
1411                         loc = &pkt[ICE_FDIR_GTPU_EH_INNER_PKT_OFF];
1412                         break;
1413                 default:
1414                         if (ice_fdir_get_open_tunnel_port(hw, flow, &tnl_port))
1415                                 return ICE_ERR_DOES_NOT_EXIST;
1416
1417                         ice_memcpy(pkt, ice_fdir_pkt[idx].tun_pkt,
1418                                    ice_fdir_pkt[idx].tun_pkt_len,
1419                                    ICE_NONDMA_TO_NONDMA);
1420                         ice_pkt_insert_u16(pkt, ICE_IPV4_UDP_DST_PORT_OFFSET,
1421                                            HTONS(tnl_port));
1422                         loc = &pkt[ICE_FDIR_TUN_PKT_OFF];
1423                         break;
1424                 }
1425         }
1426
1427         /* Reverse the src and dst, since the HW expects them to be from Tx
1428          * perspective. The input from user is from Rx filter perspective.
1429          */
1430         switch (flow) {
1431         case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
1432                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1433                                    input->ip.v4.src_ip);
1434                 ice_pkt_insert_u16(loc, ICE_IPV4_TCP_DST_PORT_OFFSET,
1435                                    input->ip.v4.src_port);
1436                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1437                                    input->ip.v4.dst_ip);
1438                 ice_pkt_insert_u16(loc, ICE_IPV4_TCP_SRC_PORT_OFFSET,
1439                                    input->ip.v4.dst_port);
1440                 ice_pkt_insert_u8(loc, ICE_IPV4_TOS_OFFSET, input->ip.v4.tos);
1441                 ice_pkt_insert_u8(loc, ICE_IPV4_TTL_OFFSET, input->ip.v4.ttl);
1442                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1443                 if (frag)
1444                         loc[20] = ICE_FDIR_IPV4_PKT_FLAG_DF;
1445                 break;
1446         case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
1447                 ice_pkt_insert_mac_addr(pkt, input->ext_data_outer.dst_mac);
1448                 ice_pkt_insert_mac_addr(pkt + ETH_ALEN,
1449                                         input->ext_data_outer.src_mac);
1450                 ice_pkt_insert_u32(pkt, ICE_IPV4_SRC_ADDR_OFFSET,
1451                                    input->ip_outer.v4.dst_ip);
1452                 ice_pkt_insert_u32(pkt, ICE_IPV4_DST_ADDR_OFFSET,
1453                                    input->ip_outer.v4.src_ip);
1454                 ice_pkt_insert_u8(pkt, ICE_IPV4_TOS_OFFSET, input->ip_outer.v4.tos);
1455                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1456                                    input->ip.v4.src_ip);
1457                 ice_pkt_insert_u16(loc, ICE_IPV4_UDP_DST_PORT_OFFSET,
1458                                    input->ip.v4.src_port);
1459                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1460                                    input->ip.v4.dst_ip);
1461                 ice_pkt_insert_u16(loc, ICE_IPV4_UDP_SRC_PORT_OFFSET,
1462                                    input->ip.v4.dst_port);
1463                 ice_pkt_insert_u8(loc, ICE_IPV4_TOS_OFFSET, input->ip.v4.tos);
1464                 ice_pkt_insert_u8(loc, ICE_IPV4_TTL_OFFSET, input->ip.v4.ttl);
1465                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1466                 ice_pkt_insert_mac_addr(loc + ETH_ALEN, input->ext_data.src_mac);
1467                 break;
1468         case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
1469                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1470                                    input->ip.v4.src_ip);
1471                 ice_pkt_insert_u16(loc, ICE_IPV4_SCTP_DST_PORT_OFFSET,
1472                                    input->ip.v4.src_port);
1473                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1474                                    input->ip.v4.dst_ip);
1475                 ice_pkt_insert_u16(loc, ICE_IPV4_SCTP_SRC_PORT_OFFSET,
1476                                    input->ip.v4.dst_port);
1477                 ice_pkt_insert_u8(loc, ICE_IPV4_TOS_OFFSET, input->ip.v4.tos);
1478                 ice_pkt_insert_u8(loc, ICE_IPV4_TTL_OFFSET, input->ip.v4.ttl);
1479                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1480                 break;
1481         case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
1482                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1483                                    input->ip.v4.src_ip);
1484                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1485                                    input->ip.v4.dst_ip);
1486                 ice_pkt_insert_u8(loc, ICE_IPV4_TOS_OFFSET, input->ip.v4.tos);
1487                 ice_pkt_insert_u8(loc, ICE_IPV4_TTL_OFFSET, input->ip.v4.ttl);
1488                 ice_pkt_insert_u8(loc, ICE_IPV4_PROTO_OFFSET,
1489                                   input->ip.v4.proto);
1490                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1491                 break;
1492         case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN:
1493                 ice_pkt_insert_mac_addr(pkt, input->ext_data_outer.dst_mac);
1494                 ice_pkt_insert_mac_addr(pkt + ETH_ALEN, input->ext_data_outer.src_mac);
1495                 ice_pkt_insert_u32(pkt, ICE_IPV4_SRC_ADDR_OFFSET,
1496                                    input->ip_outer.v4.dst_ip);
1497                 ice_pkt_insert_u32(pkt, ICE_IPV4_DST_ADDR_OFFSET,
1498                                    input->ip_outer.v4.src_ip);
1499                 ice_pkt_insert_u8(pkt, ICE_IPV4_TOS_OFFSET, input->ip_outer.v4.tos);
1500                 ice_pkt_insert_u32(pkt, ICE_IPV4_VXLAN_VNI_OFFSET,
1501                                    input->vxlan_data.vni);
1502                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1503                                    input->ip.v4.src_ip);
1504                 ice_pkt_insert_u16(loc, ICE_IPV4_UDP_DST_PORT_OFFSET,
1505                                    input->ip.v4.src_port);
1506                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1507                                    input->ip.v4.dst_ip);
1508                 ice_pkt_insert_u16(loc, ICE_IPV4_UDP_SRC_PORT_OFFSET,
1509                                    input->ip.v4.dst_port);
1510                 ice_pkt_insert_u8(loc, ICE_IPV4_TOS_OFFSET, input->ip.v4.tos);
1511                 ice_pkt_insert_u8(loc, ICE_IPV4_TTL_OFFSET, input->ip.v4.ttl);
1512                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1513                 ice_pkt_insert_mac_addr(loc + ETH_ALEN, input->ext_data.src_mac);
1514                 break;
1515         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU:
1516                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1517                                    input->ip.v4.src_ip);
1518                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1519                                    input->ip.v4.dst_ip);
1520                 ice_pkt_insert_u32(loc, ICE_IPV4_GTPU_TEID_OFFSET,
1521                                    input->gtpu_data.teid);
1522                 break;
1523         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4:
1524         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4:
1525         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4:
1526         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4:
1527                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_DST_ADDR_OFFSET,
1528                                    input->ip.v4.src_ip);
1529                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_SRC_ADDR_OFFSET,
1530                                    input->ip.v4.dst_ip);
1531                 break;
1532         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH:
1533         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW:
1534         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP:
1535                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1536                                    input->ip.v4.src_ip);
1537                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1538                                    input->ip.v4.dst_ip);
1539                 ice_pkt_insert_u32(loc, ICE_IPV4_GTPU_TEID_OFFSET,
1540                                    input->gtpu_data.teid);
1541                 ice_pkt_insert_u6_qfi(loc, ICE_IPV4_GTPU_QFI_OFFSET,
1542                                       input->gtpu_data.qfi);
1543                 break;
1544         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
1545         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_UDP:
1546         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_UDP:
1547         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_UDP:
1548                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_DST_ADDR_OFFSET,
1549                                    input->ip.v4.src_ip);
1550                 ice_pkt_insert_u16(loc, ICE_UDP4_NO_MAC_DST_PORT_OFFSET,
1551                                    input->ip.v4.src_port);
1552                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_SRC_ADDR_OFFSET,
1553                                    input->ip.v4.dst_ip);
1554                 ice_pkt_insert_u16(loc, ICE_UDP4_NO_MAC_SRC_PORT_OFFSET,
1555                                    input->ip.v4.dst_port);
1556                 break;
1557         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
1558         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_TCP:
1559         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_DW_IPV4_TCP:
1560         case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_UP_IPV4_TCP:
1561                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_DST_ADDR_OFFSET,
1562                                    input->ip.v4.src_ip);
1563                 ice_pkt_insert_u16(loc, ICE_TCP4_NO_MAC_DST_PORT_OFFSET,
1564                                    input->ip.v4.src_port);
1565                 ice_pkt_insert_u32(loc, ICE_IPV4_NO_MAC_SRC_ADDR_OFFSET,
1566                                    input->ip.v4.dst_ip);
1567                 ice_pkt_insert_u16(loc, ICE_TCP4_NO_MAC_SRC_PORT_OFFSET,
1568                                    input->ip.v4.dst_port);
1569                 break;
1570         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU:
1571         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_IPV6_OTHER:
1572                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1573                                          input->ip.v6.src_ip);
1574                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1575                                          input->ip.v6.dst_ip);
1576                 ice_pkt_insert_u32(loc, ICE_IPV6_GTPU_TEID_OFFSET,
1577                                    input->gtpu_data.teid);
1578                 break;
1579         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH:
1580         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_DW:
1581         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_UP:
1582         case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_IPV6_OTHER:
1583                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1584                                          input->ip.v6.src_ip);
1585                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1586                                          input->ip.v6.dst_ip);
1587                 ice_pkt_insert_u32(loc, ICE_IPV6_GTPU_TEID_OFFSET,
1588                                    input->gtpu_data.teid);
1589                 ice_pkt_insert_u6_qfi(loc, ICE_IPV6_GTPU_QFI_OFFSET,
1590                                       input->gtpu_data.qfi);
1591                 break;
1592         case ICE_FLTR_PTYPE_NONF_IPV4_L2TPV3:
1593                 ice_pkt_insert_u32(loc, ICE_IPV4_L2TPV3_SESS_ID_OFFSET,
1594                                    input->l2tpv3_data.session_id);
1595                 break;
1596         case ICE_FLTR_PTYPE_NONF_IPV6_L2TPV3:
1597                 ice_pkt_insert_u32(loc, ICE_IPV6_L2TPV3_SESS_ID_OFFSET,
1598                                    input->l2tpv3_data.session_id);
1599                 break;
1600         case ICE_FLTR_PTYPE_NONF_IPV4_ESP:
1601                 ice_pkt_insert_u32(loc, ICE_IPV4_ESP_SPI_OFFSET,
1602                                    input->ip.v4.sec_parm_idx);
1603                 break;
1604         case ICE_FLTR_PTYPE_NONF_IPV6_ESP:
1605                 ice_pkt_insert_u32(loc, ICE_IPV6_ESP_SPI_OFFSET,
1606                                    input->ip.v6.sec_parm_idx);
1607                 break;
1608         case ICE_FLTR_PTYPE_NONF_IPV4_AH:
1609                 ice_pkt_insert_u32(loc, ICE_IPV4_AH_SPI_OFFSET,
1610                                    input->ip.v4.sec_parm_idx);
1611                 break;
1612         case ICE_FLTR_PTYPE_NONF_IPV6_AH:
1613                 ice_pkt_insert_u32(loc, ICE_IPV6_AH_SPI_OFFSET,
1614                                    input->ip.v6.sec_parm_idx);
1615                 break;
1616         case ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP:
1617                 ice_pkt_insert_u32(loc, ICE_IPV4_DST_ADDR_OFFSET,
1618                                    input->ip.v4.src_ip);
1619                 ice_pkt_insert_u32(loc, ICE_IPV4_SRC_ADDR_OFFSET,
1620                                    input->ip.v4.dst_ip);
1621                 ice_pkt_insert_u32(loc, ICE_IPV4_NAT_T_ESP_SPI_OFFSET,
1622                                    input->ip.v4.sec_parm_idx);
1623                 break;
1624         case ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP:
1625                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1626                                          input->ip.v6.src_ip);
1627                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1628                                          input->ip.v6.dst_ip);
1629                 ice_pkt_insert_u32(loc, ICE_IPV6_NAT_T_ESP_SPI_OFFSET,
1630                                    input->ip.v6.sec_parm_idx);
1631                 break;
1632         case ICE_FLTR_PTYPE_NONF_IPV4_PFCP_NODE:
1633         case ICE_FLTR_PTYPE_NONF_IPV4_PFCP_SESSION:
1634                 ice_pkt_insert_u16(loc, ICE_IPV4_UDP_SRC_PORT_OFFSET,
1635                                    input->ip.v4.dst_port);
1636                 break;
1637         case ICE_FLTR_PTYPE_NONF_IPV6_PFCP_NODE:
1638         case ICE_FLTR_PTYPE_NONF_IPV6_PFCP_SESSION:
1639                 ice_pkt_insert_u16(loc, ICE_IPV6_UDP_SRC_PORT_OFFSET,
1640                                    input->ip.v6.dst_port);
1641                 break;
1642         case ICE_FLTR_PTYPE_NON_IP_L2:
1643                 ice_pkt_insert_u16(loc, ICE_MAC_ETHTYPE_OFFSET,
1644                                    input->ext_data.ether_type);
1645                 break;
1646         case ICE_FLTR_PTYPE_NONF_ECPRI_TP0:
1647                 ice_pkt_insert_u16(loc, ICE_ECPRI_TP0_PC_ID_OFFSET,
1648                                    input->ecpri_data.pc_id);
1649                 break;
1650         case ICE_FLTR_PTYPE_NONF_IPV4_UDP_ECPRI_TP0:
1651                 /* Use pkt instead of loc, since PC_ID is in outer part */
1652                 ice_pkt_insert_u16(pkt, ICE_IPV4_UDP_ECPRI_TP0_PC_ID_OFFSET,
1653                                    input->ecpri_data.pc_id);
1654                 break;
1655         case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
1656                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1657                                          input->ip.v6.src_ip);
1658                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1659                                          input->ip.v6.dst_ip);
1660                 ice_pkt_insert_u16(loc, ICE_IPV6_TCP_DST_PORT_OFFSET,
1661                                    input->ip.v6.src_port);
1662                 ice_pkt_insert_u16(loc, ICE_IPV6_TCP_SRC_PORT_OFFSET,
1663                                    input->ip.v6.dst_port);
1664                 ice_pkt_insert_u8_tc(loc, ICE_IPV6_TC_OFFSET, input->ip.v6.tc);
1665                 ice_pkt_insert_u8(loc, ICE_IPV6_HLIM_OFFSET, input->ip.v6.hlim);
1666                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1667                 break;
1668         case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
1669                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1670                                          input->ip.v6.src_ip);
1671                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1672                                          input->ip.v6.dst_ip);
1673                 ice_pkt_insert_u16(loc, ICE_IPV6_UDP_DST_PORT_OFFSET,
1674                                    input->ip.v6.src_port);
1675                 ice_pkt_insert_u16(loc, ICE_IPV6_UDP_SRC_PORT_OFFSET,
1676                                    input->ip.v6.dst_port);
1677                 ice_pkt_insert_u8_tc(loc, ICE_IPV6_TC_OFFSET, input->ip.v6.tc);
1678                 ice_pkt_insert_u8(loc, ICE_IPV6_HLIM_OFFSET, input->ip.v6.hlim);
1679                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1680                 break;
1681         case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
1682                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1683                                          input->ip.v6.src_ip);
1684                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1685                                          input->ip.v6.dst_ip);
1686                 ice_pkt_insert_u16(loc, ICE_IPV6_SCTP_DST_PORT_OFFSET,
1687                                    input->ip.v6.src_port);
1688                 ice_pkt_insert_u16(loc, ICE_IPV6_SCTP_SRC_PORT_OFFSET,
1689                                    input->ip.v6.dst_port);
1690                 ice_pkt_insert_u8_tc(loc, ICE_IPV6_TC_OFFSET, input->ip.v6.tc);
1691                 ice_pkt_insert_u8(loc, ICE_IPV6_HLIM_OFFSET, input->ip.v6.hlim);
1692                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1693                 break;
1694         case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
1695                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_DST_ADDR_OFFSET,
1696                                          input->ip.v6.src_ip);
1697                 ice_pkt_insert_ipv6_addr(loc, ICE_IPV6_SRC_ADDR_OFFSET,
1698                                          input->ip.v6.dst_ip);
1699                 ice_pkt_insert_u8_tc(loc, ICE_IPV6_TC_OFFSET, input->ip.v6.tc);
1700                 ice_pkt_insert_u8(loc, ICE_IPV6_HLIM_OFFSET, input->ip.v6.hlim);
1701                 ice_pkt_insert_u8(loc, ICE_IPV6_PROTO_OFFSET,
1702                                   input->ip.v6.proto);
1703                 ice_pkt_insert_mac_addr(loc, input->ext_data.dst_mac);
1704                 break;
1705         default:
1706                 return ICE_ERR_PARAM;
1707         }
1708
1709         if (input->flex_fltr)
1710                 ice_pkt_insert_u16(loc, input->flex_offset, input->flex_word);
1711
1712         return ICE_SUCCESS;
1713 }
1714
1715 /**
1716  * ice_fdir_get_prgm_pkt - generate a training packet
1717  * @input: flow director filter data structure
1718  * @pkt: pointer to return filter packet
1719  * @frag: generate a fragment packet
1720  */
1721 enum ice_status
1722 ice_fdir_get_prgm_pkt(struct ice_fdir_fltr *input, u8 *pkt, bool frag)
1723 {
1724         return ice_fdir_get_gen_prgm_pkt(NULL, input, pkt, frag, false);
1725 }
1726
1727 /**
1728  * ice_fdir_has_frag - does flow type have 2 ptypes
1729  * @flow: flow ptype
1730  *
1731  * returns true is there is a fragment packet for this ptype
1732  */
1733 bool ice_fdir_has_frag(enum ice_fltr_ptype flow)
1734 {
1735         if (flow == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
1736                 return true;
1737         else
1738                 return false;
1739 }
1740
1741 /**
1742  * ice_fdir_find_by_idx - find filter with idx
1743  * @hw: pointer to hardware structure
1744  * @fltr_idx: index to find.
1745  *
1746  * Returns pointer to filter if found or null
1747  */
1748 struct ice_fdir_fltr *
1749 ice_fdir_find_fltr_by_idx(struct ice_hw *hw, u32 fltr_idx)
1750 {
1751         struct ice_fdir_fltr *rule;
1752
1753         LIST_FOR_EACH_ENTRY(rule, &hw->fdir_list_head, ice_fdir_fltr,
1754                             fltr_node) {
1755                 /* rule ID found in the list */
1756                 if (fltr_idx == rule->fltr_id)
1757                         return rule;
1758                 if (fltr_idx < rule->fltr_id)
1759                         break;
1760         }
1761         return NULL;
1762 }
1763
1764 /**
1765  * ice_fdir_list_add_fltr - add a new node to the flow director filter list
1766  * @hw: hardware structure
1767  * @fltr: filter node to add to structure
1768  */
1769 void ice_fdir_list_add_fltr(struct ice_hw *hw, struct ice_fdir_fltr *fltr)
1770 {
1771         struct ice_fdir_fltr *rule, *parent = NULL;
1772
1773         LIST_FOR_EACH_ENTRY(rule, &hw->fdir_list_head, ice_fdir_fltr,
1774                             fltr_node) {
1775                 /* rule ID found or pass its spot in the list */
1776                 if (rule->fltr_id >= fltr->fltr_id)
1777                         break;
1778                 parent = rule;
1779         }
1780
1781         if (parent)
1782                 LIST_ADD_AFTER(&fltr->fltr_node, &parent->fltr_node);
1783         else
1784                 LIST_ADD(&fltr->fltr_node, &hw->fdir_list_head);
1785 }
1786
1787 /**
1788  * ice_fdir_update_cntrs - increment / decrement filter counter
1789  * @hw: pointer to hardware structure
1790  * @flow: filter flow type
1791  * @acl_fltr: true indicates an ACL filter
1792  * @add: true implies filters added
1793  */
1794 void
1795 ice_fdir_update_cntrs(struct ice_hw *hw, enum ice_fltr_ptype flow,
1796                       bool acl_fltr, bool add)
1797 {
1798         int incr;
1799
1800         incr = add ? 1 : -1;
1801         hw->fdir_active_fltr += incr;
1802         if (flow == ICE_FLTR_PTYPE_NONF_NONE || flow >= ICE_FLTR_PTYPE_MAX) {
1803                 ice_debug(hw, ICE_DBG_SW, "Unknown filter type %d\n", flow);
1804         } else {
1805                 if (acl_fltr)
1806                         hw->acl_fltr_cnt[flow] += incr;
1807                 else
1808                         hw->fdir_fltr_cnt[flow] += incr;
1809         }
1810 }
1811
1812 /**
1813  * ice_cmp_ipv6_addr - compare 2 IP v6 addresses
1814  * @a: IP v6 address
1815  * @b: IP v6 address
1816  *
1817  * Returns 0 on equal, returns non-0 if different
1818  */
1819 static int ice_cmp_ipv6_addr(__be32 *a, __be32 *b)
1820 {
1821         return memcmp(a, b, 4 * sizeof(__be32));
1822 }
1823
1824 /**
1825  * ice_fdir_comp_rules - compare 2 filters
1826  * @a: a Flow Director filter data structure
1827  * @b: a Flow Director filter data structure
1828  * @v6: bool true if v6 filter
1829  *
1830  * Returns true if the filters match
1831  */
1832 static bool
1833 ice_fdir_comp_rules(struct ice_fdir_fltr *a,  struct ice_fdir_fltr *b, bool v6)
1834 {
1835         enum ice_fltr_ptype flow_type = a->flow_type;
1836
1837         /* The calling function already checks that the two filters have the
1838          * same flow_type.
1839          */
1840         if (!v6) {
1841                 if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
1842                     flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
1843                     flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP) {
1844                         if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
1845                             a->ip.v4.src_ip == b->ip.v4.src_ip &&
1846                             a->ip.v4.dst_port == b->ip.v4.dst_port &&
1847                             a->ip.v4.src_port == b->ip.v4.src_port)
1848                                 return true;
1849                 } else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER) {
1850                         if (a->ip.v4.dst_ip == b->ip.v4.dst_ip &&
1851                             a->ip.v4.src_ip == b->ip.v4.src_ip &&
1852                             a->ip.v4.l4_header == b->ip.v4.l4_header &&
1853                             a->ip.v4.proto == b->ip.v4.proto &&
1854                             a->ip.v4.ip_ver == b->ip.v4.ip_ver &&
1855                             a->ip.v4.tos == b->ip.v4.tos)
1856                                 return true;
1857                 }
1858         } else {
1859                 if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP ||
1860                     flow_type == ICE_FLTR_PTYPE_NONF_IPV6_TCP ||
1861                     flow_type == ICE_FLTR_PTYPE_NONF_IPV6_SCTP) {
1862                         if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
1863                             a->ip.v6.src_port == b->ip.v6.src_port &&
1864                             !ice_cmp_ipv6_addr(a->ip.v6.dst_ip,
1865                                                b->ip.v6.dst_ip) &&
1866                             !ice_cmp_ipv6_addr(a->ip.v6.src_ip,
1867                                                b->ip.v6.src_ip))
1868                                 return true;
1869                 } else if (flow_type == ICE_FLTR_PTYPE_NONF_IPV6_OTHER) {
1870                         if (a->ip.v6.dst_port == b->ip.v6.dst_port &&
1871                             a->ip.v6.src_port == b->ip.v6.src_port)
1872                                 return true;
1873                 }
1874         }
1875
1876         return false;
1877 }
1878
1879 /**
1880  * ice_fdir_is_dup_fltr - test if filter is already in list for PF
1881  * @hw: hardware data structure
1882  * @input: Flow Director filter data structure
1883  *
1884  * Returns true if the filter is found in the list
1885  */
1886 bool ice_fdir_is_dup_fltr(struct ice_hw *hw, struct ice_fdir_fltr *input)
1887 {
1888         struct ice_fdir_fltr *rule;
1889         bool ret = false;
1890
1891         LIST_FOR_EACH_ENTRY(rule, &hw->fdir_list_head, ice_fdir_fltr,
1892                             fltr_node) {
1893                 enum ice_fltr_ptype flow_type;
1894
1895                 if (rule->flow_type != input->flow_type)
1896                         continue;
1897
1898                 flow_type = input->flow_type;
1899                 if (flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP ||
1900                     flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP ||
1901                     flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP ||
1902                     flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
1903                         ret = ice_fdir_comp_rules(rule, input, false);
1904                 else
1905                         ret = ice_fdir_comp_rules(rule, input, true);
1906                 if (ret) {
1907                         if (rule->fltr_id == input->fltr_id &&
1908                             rule->q_index != input->q_index)
1909                                 ret = false;
1910                         else
1911                                 break;
1912                 }
1913         }
1914
1915         return ret;
1916 }
1917
1918 /**
1919  * ice_clear_pf_fd_table - admin command to clear FD table for PF
1920  * @hw: hardware data structure
1921  *
1922  * Clears FD table entries for a PF by issuing admin command (direct, 0x0B06)
1923  */
1924 enum ice_status ice_clear_pf_fd_table(struct ice_hw *hw)
1925 {
1926         struct ice_aqc_clear_fd_table *cmd;
1927         struct ice_aq_desc desc;
1928
1929         cmd = &desc.params.clear_fd_table;
1930         ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_clear_fd_table);
1931         cmd->clear_type = CL_FD_VM_VF_TYPE_PF_IDX;
1932         /* vsi_index must be 0 to clear FD table for a PF */
1933         cmd->vsi_index = CPU_TO_LE16(0);
1934
1935         return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
1936 }