Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <errno.h>
7 : : #include <sys/queue.h>
8 : : #include <bus_pci_driver.h>
9 : : #include <rte_malloc.h>
10 : : #include <rte_flow.h>
11 : : #include <rte_flow_driver.h>
12 : :
13 : : #include "txgbe_ethdev.h"
14 : :
15 : : #define TXGBE_MIN_N_TUPLE_PRIO 1
16 : : #define TXGBE_MAX_N_TUPLE_PRIO 7
17 : : #define TXGBE_MAX_FLX_SOURCE_OFF 62
18 : :
19 : : /* ntuple filter list structure */
20 : : struct txgbe_ntuple_filter_ele {
21 : : TAILQ_ENTRY(txgbe_ntuple_filter_ele) entries;
22 : : struct rte_eth_ntuple_filter filter_info;
23 : : };
24 : : /* ethertype filter list structure */
25 : : struct txgbe_ethertype_filter_ele {
26 : : TAILQ_ENTRY(txgbe_ethertype_filter_ele) entries;
27 : : struct rte_eth_ethertype_filter filter_info;
28 : : };
29 : : /* syn filter list structure */
30 : : struct txgbe_eth_syn_filter_ele {
31 : : TAILQ_ENTRY(txgbe_eth_syn_filter_ele) entries;
32 : : struct rte_eth_syn_filter filter_info;
33 : : };
34 : : /* fdir filter list structure */
35 : : struct txgbe_fdir_rule_ele {
36 : : TAILQ_ENTRY(txgbe_fdir_rule_ele) entries;
37 : : struct txgbe_fdir_rule filter_info;
38 : : };
39 : : /* l2_tunnel filter list structure */
40 : : struct txgbe_eth_l2_tunnel_conf_ele {
41 : : TAILQ_ENTRY(txgbe_eth_l2_tunnel_conf_ele) entries;
42 : : struct txgbe_l2_tunnel_conf filter_info;
43 : : };
44 : : /* rss filter list structure */
45 : : struct txgbe_rss_conf_ele {
46 : : TAILQ_ENTRY(txgbe_rss_conf_ele) entries;
47 : : struct txgbe_rte_flow_rss_conf filter_info;
48 : : };
49 : : /* txgbe_flow memory list structure */
50 : : struct txgbe_flow_mem {
51 : : TAILQ_ENTRY(txgbe_flow_mem) entries;
52 : : struct rte_flow *flow;
53 : : };
54 : :
55 : : TAILQ_HEAD(txgbe_ntuple_filter_list, txgbe_ntuple_filter_ele);
56 : : TAILQ_HEAD(txgbe_ethertype_filter_list, txgbe_ethertype_filter_ele);
57 : : TAILQ_HEAD(txgbe_syn_filter_list, txgbe_eth_syn_filter_ele);
58 : : TAILQ_HEAD(txgbe_fdir_rule_filter_list, txgbe_fdir_rule_ele);
59 : : TAILQ_HEAD(txgbe_l2_tunnel_filter_list, txgbe_eth_l2_tunnel_conf_ele);
60 : : TAILQ_HEAD(txgbe_rss_filter_list, txgbe_rss_conf_ele);
61 : : TAILQ_HEAD(txgbe_flow_mem_list, txgbe_flow_mem);
62 : :
63 : : static struct txgbe_ntuple_filter_list filter_ntuple_list;
64 : : static struct txgbe_ethertype_filter_list filter_ethertype_list;
65 : : static struct txgbe_syn_filter_list filter_syn_list;
66 : : static struct txgbe_fdir_rule_filter_list filter_fdir_list;
67 : : static struct txgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
68 : : static struct txgbe_rss_filter_list filter_rss_list;
69 : : static struct txgbe_flow_mem_list txgbe_flow_list;
70 : :
71 : : /**
72 : : * Endless loop will never happen with below assumption
73 : : * 1. there is at least one no-void item(END)
74 : : * 2. cur is before END.
75 : : */
76 : : static inline
77 : : const struct rte_flow_item *next_no_void_pattern(
78 : : const struct rte_flow_item pattern[],
79 : : const struct rte_flow_item *cur)
80 : : {
81 : : const struct rte_flow_item *next =
82 : 0 : cur ? cur + 1 : &pattern[0];
83 : : while (1) {
84 [ # # # # : 0 : if (next->type != RTE_FLOW_ITEM_TYPE_VOID)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
85 : : return next;
86 : 0 : next++;
87 : : }
88 : : }
89 : :
90 : : static inline
91 : : const struct rte_flow_action *next_no_void_action(
92 : : const struct rte_flow_action actions[],
93 : : const struct rte_flow_action *cur)
94 : : {
95 : : const struct rte_flow_action *next =
96 : 0 : cur ? cur + 1 : &actions[0];
97 : : while (1) {
98 [ # # # # : 0 : if (next->type != RTE_FLOW_ACTION_TYPE_VOID)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
99 : : return next;
100 : 0 : next++;
101 : : }
102 : : }
103 : :
104 : : /**
105 : : * Please aware there's an assumption for all the parsers.
106 : : * rte_flow_item is using big endian, rte_flow_attr and
107 : : * rte_flow_action are using CPU order.
108 : : * Because the pattern is used to describe the packets,
109 : : * normally the packets should use network order.
110 : : */
111 : :
112 : : /**
113 : : * Parse the rule to see if it is a n-tuple rule.
114 : : * And get the n-tuple filter info BTW.
115 : : * pattern:
116 : : * The first not void item can be ETH or IPV4.
117 : : * The second not void item must be IPV4 if the first one is ETH.
118 : : * The third not void item must be UDP or TCP.
119 : : * The next not void item must be END.
120 : : * action:
121 : : * The first not void action should be QUEUE.
122 : : * The next not void action should be END.
123 : : * pattern example:
124 : : * ITEM Spec Mask
125 : : * ETH NULL NULL
126 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
127 : : * dst_addr 192.167.3.50 0xFFFFFFFF
128 : : * next_proto_id 17 0xFF
129 : : * UDP/TCP/ src_port 80 0xFFFF
130 : : * SCTP dst_port 80 0xFFFF
131 : : * END
132 : : * other members in mask and spec should set to 0x00.
133 : : * item->last should be NULL.
134 : : *
135 : : * Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY.
136 : : *
137 : : */
138 : : static int
139 : 0 : cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
140 : : const struct rte_flow_item pattern[],
141 : : const struct rte_flow_action actions[],
142 : : struct rte_eth_ntuple_filter *filter,
143 : : struct rte_flow_error *error)
144 : : {
145 : : const struct rte_flow_item *item;
146 : : const struct rte_flow_action *act;
147 : : const struct rte_flow_item_ipv4 *ipv4_spec;
148 : : const struct rte_flow_item_ipv4 *ipv4_mask;
149 : : const struct rte_flow_item_tcp *tcp_spec;
150 : : const struct rte_flow_item_tcp *tcp_mask;
151 : : const struct rte_flow_item_udp *udp_spec;
152 : : const struct rte_flow_item_udp *udp_mask;
153 : : const struct rte_flow_item_sctp *sctp_spec;
154 : : const struct rte_flow_item_sctp *sctp_mask;
155 : : const struct rte_flow_item_eth *eth_spec;
156 : : const struct rte_flow_item_eth *eth_mask;
157 : : const struct rte_flow_item_vlan *vlan_spec;
158 : : const struct rte_flow_item_vlan *vlan_mask;
159 : : struct rte_flow_item_eth eth_null;
160 : : struct rte_flow_item_vlan vlan_null;
161 : :
162 [ # # ]: 0 : if (!pattern) {
163 : 0 : rte_flow_error_set(error,
164 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
165 : : NULL, "NULL pattern.");
166 : 0 : return -rte_errno;
167 : : }
168 : :
169 [ # # ]: 0 : if (!actions) {
170 : 0 : rte_flow_error_set(error, EINVAL,
171 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
172 : : NULL, "NULL action.");
173 : 0 : return -rte_errno;
174 : : }
175 [ # # ]: 0 : if (!attr) {
176 : 0 : rte_flow_error_set(error, EINVAL,
177 : : RTE_FLOW_ERROR_TYPE_ATTR,
178 : : NULL, "NULL attribute.");
179 : 0 : return -rte_errno;
180 : : }
181 : :
182 : : memset(ð_null, 0, sizeof(struct rte_flow_item_eth));
183 : : memset(&vlan_null, 0, sizeof(struct rte_flow_item_vlan));
184 : :
185 : : #ifdef RTE_LIB_SECURITY
186 : : /**
187 : : * Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY
188 : : */
189 : : act = next_no_void_action(actions, NULL);
190 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_SECURITY) {
191 : 0 : const void *conf = act->conf;
192 : : /* check if the next not void item is END */
193 : : act = next_no_void_action(actions, act);
194 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
195 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
196 : 0 : rte_flow_error_set(error, EINVAL,
197 : : RTE_FLOW_ERROR_TYPE_ACTION,
198 : : act, "Not supported action.");
199 : 0 : return -rte_errno;
200 : : }
201 : :
202 : : /* get the IP pattern*/
203 : : item = next_no_void_pattern(pattern, NULL);
204 [ # # ]: 0 : while (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
205 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
206 [ # # # # ]: 0 : if (item->last ||
207 : : item->type == RTE_FLOW_ITEM_TYPE_END) {
208 : 0 : rte_flow_error_set(error, EINVAL,
209 : : RTE_FLOW_ERROR_TYPE_ITEM,
210 : : item, "IP pattern missing.");
211 : 0 : return -rte_errno;
212 : : }
213 : : item = next_no_void_pattern(pattern, item);
214 : : }
215 : :
216 : 0 : filter->proto = IPPROTO_ESP;
217 : 0 : return txgbe_crypto_add_ingress_sa_from_flow(conf, item->spec,
218 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
219 : : }
220 : : #endif
221 : :
222 : : /* the first not void item can be MAC or IPv4 */
223 : : item = next_no_void_pattern(pattern, NULL);
224 : :
225 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
226 : : item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
227 : 0 : rte_flow_error_set(error, EINVAL,
228 : : RTE_FLOW_ERROR_TYPE_ITEM,
229 : : item, "Not supported by ntuple filter");
230 : 0 : return -rte_errno;
231 : : }
232 : : /* Skip Ethernet */
233 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
234 : 0 : eth_spec = item->spec;
235 : 0 : eth_mask = item->mask;
236 : : /*Not supported last point for range*/
237 [ # # ]: 0 : if (item->last) {
238 : 0 : rte_flow_error_set(error,
239 : : EINVAL,
240 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
241 : : item, "Not supported last point for range");
242 : 0 : return -rte_errno;
243 : : }
244 : : /* if the first item is MAC, the content should be NULL */
245 [ # # # # ]: 0 : if ((item->spec && memcmp(eth_spec, ð_null,
246 [ # # ]: 0 : sizeof(struct rte_flow_item_eth))) ||
247 [ # # ]: 0 : (item->mask && memcmp(eth_mask, ð_null,
248 : : sizeof(struct rte_flow_item_eth)))) {
249 : 0 : rte_flow_error_set(error, EINVAL,
250 : : RTE_FLOW_ERROR_TYPE_ITEM,
251 : : item, "Not supported by ntuple filter");
252 : 0 : return -rte_errno;
253 : : }
254 : : /* check if the next not void item is IPv4 or Vlan */
255 : : item = next_no_void_pattern(pattern, item);
256 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
257 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
258 : 0 : rte_flow_error_set(error,
259 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
260 : : item, "Not supported by ntuple filter");
261 : 0 : return -rte_errno;
262 : : }
263 : : }
264 : :
265 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
266 : 0 : vlan_spec = item->spec;
267 : 0 : vlan_mask = item->mask;
268 : : /*Not supported last point for range*/
269 [ # # ]: 0 : if (item->last) {
270 : 0 : rte_flow_error_set(error,
271 : : EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
272 : : item, "Not supported last point for range");
273 : 0 : return -rte_errno;
274 : : }
275 : : /* the content should be NULL */
276 [ # # # # ]: 0 : if ((item->spec && memcmp(vlan_spec, &vlan_null,
277 [ # # ]: 0 : sizeof(struct rte_flow_item_vlan))) ||
278 [ # # ]: 0 : (item->mask && memcmp(vlan_mask, &vlan_null,
279 : : sizeof(struct rte_flow_item_vlan)))) {
280 : 0 : rte_flow_error_set(error, EINVAL,
281 : : RTE_FLOW_ERROR_TYPE_ITEM,
282 : : item, "Not supported by ntuple filter");
283 : 0 : return -rte_errno;
284 : : }
285 : : /* check if the next not void item is IPv4 */
286 : : item = next_no_void_pattern(pattern, item);
287 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
288 : 0 : rte_flow_error_set(error,
289 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
290 : : item, "Not supported by ntuple filter");
291 : 0 : return -rte_errno;
292 : : }
293 : : }
294 : :
295 [ # # ]: 0 : if (item->mask) {
296 : : /* get the IPv4 info */
297 [ # # ]: 0 : if (!item->spec || !item->mask) {
298 : 0 : rte_flow_error_set(error, EINVAL,
299 : : RTE_FLOW_ERROR_TYPE_ITEM,
300 : : item, "Invalid ntuple mask");
301 : 0 : return -rte_errno;
302 : : }
303 : : /*Not supported last point for range*/
304 [ # # ]: 0 : if (item->last) {
305 : 0 : rte_flow_error_set(error, EINVAL,
306 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
307 : : item, "Not supported last point for range");
308 : 0 : return -rte_errno;
309 : : }
310 : :
311 : : ipv4_mask = item->mask;
312 : : /**
313 : : * Only support src & dst addresses, protocol,
314 : : * others should be masked.
315 : : */
316 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
317 : 0 : ipv4_mask->hdr.type_of_service ||
318 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
319 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
320 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
321 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
322 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
323 : 0 : rte_flow_error_set(error,
324 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
325 : : item, "Not supported by ntuple filter");
326 : 0 : return -rte_errno;
327 : : }
328 [ # # ]: 0 : if ((ipv4_mask->hdr.src_addr != 0 &&
329 : 0 : ipv4_mask->hdr.src_addr != UINT32_MAX) ||
330 [ # # ]: 0 : (ipv4_mask->hdr.dst_addr != 0 &&
331 : 0 : ipv4_mask->hdr.dst_addr != UINT32_MAX) ||
332 [ # # ]: 0 : (ipv4_mask->hdr.next_proto_id != UINT8_MAX &&
333 : : ipv4_mask->hdr.next_proto_id != 0)) {
334 : 0 : rte_flow_error_set(error,
335 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
336 : : item, "Not supported by ntuple filter");
337 : 0 : return -rte_errno;
338 : : }
339 : :
340 : 0 : filter->dst_ip_mask = ipv4_mask->hdr.dst_addr;
341 : 0 : filter->src_ip_mask = ipv4_mask->hdr.src_addr;
342 : 0 : filter->proto_mask = ipv4_mask->hdr.next_proto_id;
343 : :
344 : : ipv4_spec = item->spec;
345 : 0 : filter->dst_ip = ipv4_spec->hdr.dst_addr;
346 : 0 : filter->src_ip = ipv4_spec->hdr.src_addr;
347 : 0 : filter->proto = ipv4_spec->hdr.next_proto_id;
348 : : }
349 : :
350 : : /* check if the next not void item is TCP or UDP */
351 : : item = next_no_void_pattern(pattern, item);
352 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
353 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
354 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
355 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
356 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
357 : 0 : rte_flow_error_set(error, EINVAL,
358 : : RTE_FLOW_ERROR_TYPE_ITEM,
359 : : item, "Not supported by ntuple filter");
360 : 0 : return -rte_errno;
361 : : }
362 : :
363 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END &&
364 [ # # # # ]: 0 : (!item->spec && !item->mask)) {
365 : 0 : goto item_end;
366 : : }
367 : :
368 : : /* get the TCP/UDP/SCTP info */
369 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END &&
370 [ # # # # ]: 0 : (!item->spec || !item->mask)) {
371 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
372 : 0 : rte_flow_error_set(error, EINVAL,
373 : : RTE_FLOW_ERROR_TYPE_ITEM,
374 : : item, "Invalid ntuple mask");
375 : 0 : return -rte_errno;
376 : : }
377 : :
378 : : /*Not supported last point for range*/
379 [ # # ]: 0 : if (item->last) {
380 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
381 : 0 : rte_flow_error_set(error, EINVAL,
382 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
383 : : item, "Not supported last point for range");
384 : 0 : return -rte_errno;
385 : : }
386 : :
387 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
388 : 0 : tcp_mask = item->mask;
389 : :
390 : : /**
391 : : * Only support src & dst ports, tcp flags,
392 : : * others should be masked.
393 : : */
394 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
395 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
396 [ # # ]: 0 : tcp_mask->hdr.data_off ||
397 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
398 [ # # ]: 0 : tcp_mask->hdr.cksum ||
399 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
400 : : memset(filter, 0,
401 : : sizeof(struct rte_eth_ntuple_filter));
402 : 0 : rte_flow_error_set(error, EINVAL,
403 : : RTE_FLOW_ERROR_TYPE_ITEM,
404 : : item, "Not supported by ntuple filter");
405 : 0 : return -rte_errno;
406 : : }
407 [ # # ]: 0 : if ((tcp_mask->hdr.src_port != 0 &&
408 : 0 : tcp_mask->hdr.src_port != UINT16_MAX) ||
409 [ # # ]: 0 : (tcp_mask->hdr.dst_port != 0 &&
410 : : tcp_mask->hdr.dst_port != UINT16_MAX)) {
411 : 0 : rte_flow_error_set(error,
412 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
413 : : item, "Not supported by ntuple filter");
414 : 0 : return -rte_errno;
415 : : }
416 : :
417 : 0 : filter->dst_port_mask = tcp_mask->hdr.dst_port;
418 : 0 : filter->src_port_mask = tcp_mask->hdr.src_port;
419 [ # # ]: 0 : if (tcp_mask->hdr.tcp_flags == 0xFF) {
420 : 0 : filter->flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
421 [ # # ]: 0 : } else if (!tcp_mask->hdr.tcp_flags) {
422 : 0 : filter->flags &= ~RTE_NTUPLE_FLAGS_TCP_FLAG;
423 : : } else {
424 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
425 : 0 : rte_flow_error_set(error, EINVAL,
426 : : RTE_FLOW_ERROR_TYPE_ITEM,
427 : : item, "Not supported by ntuple filter");
428 : 0 : return -rte_errno;
429 : : }
430 : :
431 : 0 : tcp_spec = item->spec;
432 : 0 : filter->dst_port = tcp_spec->hdr.dst_port;
433 : 0 : filter->src_port = tcp_spec->hdr.src_port;
434 : 0 : filter->tcp_flags = tcp_spec->hdr.tcp_flags;
435 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
436 : 0 : udp_mask = item->mask;
437 : :
438 : : /**
439 : : * Only support src & dst ports,
440 : : * others should be masked.
441 : : */
442 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
443 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
444 : : memset(filter, 0,
445 : : sizeof(struct rte_eth_ntuple_filter));
446 : 0 : rte_flow_error_set(error, EINVAL,
447 : : RTE_FLOW_ERROR_TYPE_ITEM,
448 : : item, "Not supported by ntuple filter");
449 : 0 : return -rte_errno;
450 : : }
451 [ # # ]: 0 : if ((udp_mask->hdr.src_port != 0 &&
452 : 0 : udp_mask->hdr.src_port != UINT16_MAX) ||
453 [ # # ]: 0 : (udp_mask->hdr.dst_port != 0 &&
454 : : udp_mask->hdr.dst_port != UINT16_MAX)) {
455 : 0 : rte_flow_error_set(error,
456 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
457 : : item, "Not supported by ntuple filter");
458 : 0 : return -rte_errno;
459 : : }
460 : :
461 : 0 : filter->dst_port_mask = udp_mask->hdr.dst_port;
462 : 0 : filter->src_port_mask = udp_mask->hdr.src_port;
463 : :
464 : 0 : udp_spec = item->spec;
465 : 0 : filter->dst_port = udp_spec->hdr.dst_port;
466 : 0 : filter->src_port = udp_spec->hdr.src_port;
467 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
468 : 0 : sctp_mask = item->mask;
469 : :
470 : : /**
471 : : * Only support src & dst ports,
472 : : * others should be masked.
473 : : */
474 [ # # ]: 0 : if (sctp_mask->hdr.tag ||
475 [ # # ]: 0 : sctp_mask->hdr.cksum) {
476 : : memset(filter, 0,
477 : : sizeof(struct rte_eth_ntuple_filter));
478 : 0 : rte_flow_error_set(error, EINVAL,
479 : : RTE_FLOW_ERROR_TYPE_ITEM,
480 : : item, "Not supported by ntuple filter");
481 : 0 : return -rte_errno;
482 : : }
483 : :
484 : 0 : filter->dst_port_mask = sctp_mask->hdr.dst_port;
485 : 0 : filter->src_port_mask = sctp_mask->hdr.src_port;
486 : :
487 : 0 : sctp_spec = item->spec;
488 : 0 : filter->dst_port = sctp_spec->hdr.dst_port;
489 : 0 : filter->src_port = sctp_spec->hdr.src_port;
490 : : } else {
491 : 0 : goto action;
492 : : }
493 : :
494 : 0 : item_end:
495 : : /* check if the next not void item is END */
496 : : item = next_no_void_pattern(pattern, item);
497 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
498 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
499 : 0 : rte_flow_error_set(error, EINVAL,
500 : : RTE_FLOW_ERROR_TYPE_ITEM,
501 : : item, "Not supported by ntuple filter");
502 : 0 : return -rte_errno;
503 : : }
504 : :
505 : 0 : action:
506 : :
507 : : /**
508 : : * n-tuple only supports forwarding,
509 : : * check if the first not void action is QUEUE.
510 : : */
511 : : act = next_no_void_action(actions, NULL);
512 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
513 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
514 : 0 : rte_flow_error_set(error, EINVAL,
515 : : RTE_FLOW_ERROR_TYPE_ACTION,
516 : : act, "Not supported action.");
517 : 0 : return -rte_errno;
518 : : }
519 : 0 : filter->queue =
520 : 0 : ((const struct rte_flow_action_queue *)act->conf)->index;
521 : :
522 : : /* check if the next not void item is END */
523 : : act = next_no_void_action(actions, act);
524 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
525 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
526 : 0 : rte_flow_error_set(error, EINVAL,
527 : : RTE_FLOW_ERROR_TYPE_ACTION,
528 : : act, "Not supported action.");
529 : 0 : return -rte_errno;
530 : : }
531 : :
532 : : /* parse attr */
533 : : /* must be input direction */
534 [ # # ]: 0 : if (!attr->ingress) {
535 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
536 : 0 : rte_flow_error_set(error, EINVAL,
537 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
538 : : attr, "Only support ingress.");
539 : 0 : return -rte_errno;
540 : : }
541 : :
542 : : /* not supported */
543 [ # # ]: 0 : if (attr->egress) {
544 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
545 : 0 : rte_flow_error_set(error, EINVAL,
546 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
547 : : attr, "Not support egress.");
548 : 0 : return -rte_errno;
549 : : }
550 : :
551 : : /* not supported */
552 [ # # ]: 0 : if (attr->transfer) {
553 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
554 : 0 : rte_flow_error_set(error, EINVAL,
555 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
556 : : attr, "No support for transfer.");
557 : 0 : return -rte_errno;
558 : : }
559 : :
560 [ # # ]: 0 : if (attr->priority > 0xFFFF) {
561 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
562 : 0 : rte_flow_error_set(error, EINVAL,
563 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
564 : : attr, "Error priority.");
565 : 0 : return -rte_errno;
566 : : }
567 : 0 : filter->priority = (uint16_t)attr->priority;
568 [ # # ]: 0 : if (attr->priority < TXGBE_MIN_N_TUPLE_PRIO ||
569 : : attr->priority > TXGBE_MAX_N_TUPLE_PRIO)
570 : 0 : filter->priority = 1;
571 : :
572 : : return 0;
573 : : }
574 : :
575 : : /* a specific function for txgbe because the flags is specific */
576 : : static int
577 : 0 : txgbe_parse_ntuple_filter(struct rte_eth_dev *dev,
578 : : const struct rte_flow_attr *attr,
579 : : const struct rte_flow_item pattern[],
580 : : const struct rte_flow_action actions[],
581 : : struct rte_eth_ntuple_filter *filter,
582 : : struct rte_flow_error *error)
583 : : {
584 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
585 : : int ret;
586 : :
587 [ # # ]: 0 : if (filter_info->ntuple_is_full)
588 : : return -ENOSYS;
589 : :
590 : 0 : ret = cons_parse_ntuple_filter(attr, pattern, actions, filter, error);
591 : :
592 [ # # ]: 0 : if (ret)
593 : : return ret;
594 : :
595 : : #ifdef RTE_LIB_SECURITY
596 : : /* ESP flow not really a flow */
597 [ # # ]: 0 : if (filter->proto == IPPROTO_ESP)
598 : : return 0;
599 : : #endif
600 : :
601 : : /* txgbe doesn't support tcp flags */
602 [ # # ]: 0 : if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
603 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
604 : 0 : rte_flow_error_set(error, EINVAL,
605 : : RTE_FLOW_ERROR_TYPE_ITEM,
606 : : NULL, "Not supported by ntuple filter");
607 : 0 : return -rte_errno;
608 : : }
609 : :
610 : : /* txgbe doesn't support many priorities */
611 [ # # ]: 0 : if (filter->priority < TXGBE_MIN_N_TUPLE_PRIO ||
612 : : filter->priority > TXGBE_MAX_N_TUPLE_PRIO) {
613 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
614 : 0 : rte_flow_error_set(error, EINVAL,
615 : : RTE_FLOW_ERROR_TYPE_ITEM,
616 : : NULL, "Priority not supported by ntuple filter");
617 : 0 : return -rte_errno;
618 : : }
619 : :
620 [ # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues) {
621 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
622 : 0 : rte_flow_error_set(error, EINVAL,
623 : : RTE_FLOW_ERROR_TYPE_ITEM,
624 : : NULL, "Not supported by ntuple filter");
625 : 0 : return -rte_errno;
626 : : }
627 : :
628 : : /* fixed value for txgbe */
629 : 0 : filter->flags = RTE_5TUPLE_FLAGS;
630 : 0 : return 0;
631 : : }
632 : :
633 : : /**
634 : : * Parse the rule to see if it is a ethertype rule.
635 : : * And get the ethertype filter info BTW.
636 : : * pattern:
637 : : * The first not void item can be ETH.
638 : : * The next not void item must be END.
639 : : * action:
640 : : * The first not void action should be QUEUE.
641 : : * The next not void action should be END.
642 : : * pattern example:
643 : : * ITEM Spec Mask
644 : : * ETH type 0x0807 0xFFFF
645 : : * END
646 : : * other members in mask and spec should set to 0x00.
647 : : * item->last should be NULL.
648 : : */
649 : : static int
650 : 0 : cons_parse_ethertype_filter(const struct rte_flow_attr *attr,
651 : : const struct rte_flow_item *pattern,
652 : : const struct rte_flow_action *actions,
653 : : struct rte_eth_ethertype_filter *filter,
654 : : struct rte_flow_error *error)
655 : : {
656 : : const struct rte_flow_item *item;
657 : : const struct rte_flow_action *act;
658 : : const struct rte_flow_item_eth *eth_spec;
659 : : const struct rte_flow_item_eth *eth_mask;
660 : : const struct rte_flow_action_queue *act_q;
661 : :
662 [ # # ]: 0 : if (!pattern) {
663 : 0 : rte_flow_error_set(error, EINVAL,
664 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
665 : : NULL, "NULL pattern.");
666 : 0 : return -rte_errno;
667 : : }
668 : :
669 [ # # ]: 0 : if (!actions) {
670 : 0 : rte_flow_error_set(error, EINVAL,
671 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
672 : : NULL, "NULL action.");
673 : 0 : return -rte_errno;
674 : : }
675 : :
676 [ # # ]: 0 : if (!attr) {
677 : 0 : rte_flow_error_set(error, EINVAL,
678 : : RTE_FLOW_ERROR_TYPE_ATTR,
679 : : NULL, "NULL attribute.");
680 : 0 : return -rte_errno;
681 : : }
682 : :
683 : : item = next_no_void_pattern(pattern, NULL);
684 : : /* The first non-void item should be MAC. */
685 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
686 : 0 : rte_flow_error_set(error, EINVAL,
687 : : RTE_FLOW_ERROR_TYPE_ITEM,
688 : : item, "Not supported by ethertype filter");
689 : 0 : return -rte_errno;
690 : : }
691 : :
692 : : /*Not supported last point for range*/
693 [ # # ]: 0 : if (item->last) {
694 : 0 : rte_flow_error_set(error, EINVAL,
695 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
696 : : item, "Not supported last point for range");
697 : 0 : return -rte_errno;
698 : : }
699 : :
700 : : /* Get the MAC info. */
701 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
702 : 0 : rte_flow_error_set(error, EINVAL,
703 : : RTE_FLOW_ERROR_TYPE_ITEM,
704 : : item, "Not supported by ethertype filter");
705 : 0 : return -rte_errno;
706 : : }
707 : :
708 : : eth_spec = item->spec;
709 : : eth_mask = item->mask;
710 : :
711 : : /* Mask bits of source MAC address must be full of 0.
712 : : * Mask bits of destination MAC address must be full
713 : : * of 1 or full of 0.
714 : : */
715 [ # # # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.src_addr) ||
716 [ # # ]: 0 : (!rte_is_zero_ether_addr(ð_mask->hdr.dst_addr) &&
717 : : !rte_is_broadcast_ether_addr(ð_mask->hdr.dst_addr))) {
718 : 0 : rte_flow_error_set(error, EINVAL,
719 : : RTE_FLOW_ERROR_TYPE_ITEM,
720 : : item, "Invalid ether address mask");
721 : 0 : return -rte_errno;
722 : : }
723 : :
724 [ # # ]: 0 : if ((eth_mask->hdr.ether_type & UINT16_MAX) != UINT16_MAX) {
725 : 0 : rte_flow_error_set(error, EINVAL,
726 : : RTE_FLOW_ERROR_TYPE_ITEM,
727 : : item, "Invalid ethertype mask");
728 : 0 : return -rte_errno;
729 : : }
730 : :
731 : : /* If mask bits of destination MAC address
732 : : * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
733 : : */
734 [ # # ]: 0 : if (rte_is_broadcast_ether_addr(ð_mask->hdr.dst_addr)) {
735 : 0 : filter->mac_addr = eth_spec->hdr.dst_addr;
736 : 0 : filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
737 : : } else {
738 : 0 : filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
739 : : }
740 [ # # ]: 0 : filter->ether_type = rte_be_to_cpu_16(eth_spec->hdr.ether_type);
741 : :
742 : : /* Check if the next non-void item is END. */
743 : : item = next_no_void_pattern(pattern, item);
744 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
745 : 0 : rte_flow_error_set(error, EINVAL,
746 : : RTE_FLOW_ERROR_TYPE_ITEM,
747 : : item, "Not supported by ethertype filter.");
748 : 0 : return -rte_errno;
749 : : }
750 : :
751 : : /* Parse action */
752 : :
753 : : act = next_no_void_action(actions, NULL);
754 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
755 : : act->type != RTE_FLOW_ACTION_TYPE_DROP) {
756 : 0 : rte_flow_error_set(error, EINVAL,
757 : : RTE_FLOW_ERROR_TYPE_ACTION,
758 : : act, "Not supported action.");
759 : 0 : return -rte_errno;
760 : : }
761 : :
762 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
763 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
764 : 0 : filter->queue = act_q->index;
765 : : } else {
766 : 0 : filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
767 : : }
768 : :
769 : : /* Check if the next non-void item is END */
770 : : act = next_no_void_action(actions, act);
771 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
772 : 0 : rte_flow_error_set(error, EINVAL,
773 : : RTE_FLOW_ERROR_TYPE_ACTION,
774 : : act, "Not supported action.");
775 : 0 : return -rte_errno;
776 : : }
777 : :
778 : : /* Parse attr */
779 : : /* Must be input direction */
780 [ # # ]: 0 : if (!attr->ingress) {
781 : 0 : rte_flow_error_set(error, EINVAL,
782 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
783 : : attr, "Only support ingress.");
784 : 0 : return -rte_errno;
785 : : }
786 : :
787 : : /* Not supported */
788 [ # # ]: 0 : if (attr->egress) {
789 : 0 : rte_flow_error_set(error, EINVAL,
790 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
791 : : attr, "Not support egress.");
792 : 0 : return -rte_errno;
793 : : }
794 : :
795 : : /* Not supported */
796 [ # # ]: 0 : if (attr->transfer) {
797 : 0 : rte_flow_error_set(error, EINVAL,
798 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
799 : : attr, "No support for transfer.");
800 : 0 : return -rte_errno;
801 : : }
802 : :
803 : : /* Not supported */
804 [ # # ]: 0 : if (attr->priority) {
805 : 0 : rte_flow_error_set(error, EINVAL,
806 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
807 : : attr, "Not support priority.");
808 : 0 : return -rte_errno;
809 : : }
810 : :
811 : : /* Not supported */
812 [ # # ]: 0 : if (attr->group) {
813 : 0 : rte_flow_error_set(error, EINVAL,
814 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
815 : : attr, "Not support group.");
816 : 0 : return -rte_errno;
817 : : }
818 : :
819 : : return 0;
820 : : }
821 : :
822 : : static int
823 : 0 : txgbe_parse_ethertype_filter(struct rte_eth_dev *dev,
824 : : const struct rte_flow_attr *attr,
825 : : const struct rte_flow_item pattern[],
826 : : const struct rte_flow_action actions[],
827 : : struct rte_eth_ethertype_filter *filter,
828 : : struct rte_flow_error *error)
829 : : {
830 : : int ret;
831 : :
832 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
833 : 0 : rte_flow_error_set(error, EINVAL,
834 : : RTE_FLOW_ERROR_TYPE_ITEM,
835 : : NULL, "Flow type not suppotted yet on VF");
836 : 0 : return -rte_errno;
837 : : }
838 : :
839 : 0 : ret = cons_parse_ethertype_filter(attr, pattern,
840 : : actions, filter, error);
841 : :
842 [ # # ]: 0 : if (ret)
843 : : return ret;
844 : :
845 [ # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues) {
846 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
847 : 0 : rte_flow_error_set(error, EINVAL,
848 : : RTE_FLOW_ERROR_TYPE_ITEM,
849 : : NULL, "queue index much too big");
850 : 0 : return -rte_errno;
851 : : }
852 : :
853 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
854 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
855 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
856 : 0 : rte_flow_error_set(error, EINVAL,
857 : : RTE_FLOW_ERROR_TYPE_ITEM,
858 : : NULL, "IPv4/IPv6 not supported by ethertype filter");
859 : 0 : return -rte_errno;
860 : : }
861 : :
862 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
863 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
864 : 0 : rte_flow_error_set(error, EINVAL,
865 : : RTE_FLOW_ERROR_TYPE_ITEM,
866 : : NULL, "mac compare is unsupported");
867 : 0 : return -rte_errno;
868 : : }
869 : :
870 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
871 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
872 : 0 : rte_flow_error_set(error, EINVAL,
873 : : RTE_FLOW_ERROR_TYPE_ITEM,
874 : : NULL, "drop option is unsupported");
875 : 0 : return -rte_errno;
876 : : }
877 : :
878 : : return 0;
879 : : }
880 : :
881 : : /**
882 : : * Parse the rule to see if it is a TCP SYN rule.
883 : : * And get the TCP SYN filter info BTW.
884 : : * pattern:
885 : : * The first not void item must be ETH.
886 : : * The second not void item must be IPV4 or IPV6.
887 : : * The third not void item must be TCP.
888 : : * The next not void item must be END.
889 : : * action:
890 : : * The first not void action should be QUEUE.
891 : : * The next not void action should be END.
892 : : * pattern example:
893 : : * ITEM Spec Mask
894 : : * ETH NULL NULL
895 : : * IPV4/IPV6 NULL NULL
896 : : * TCP tcp_flags 0x02 0xFF
897 : : * END
898 : : * other members in mask and spec should set to 0x00.
899 : : * item->last should be NULL.
900 : : */
901 : : static int
902 : 0 : cons_parse_syn_filter(const struct rte_flow_attr *attr,
903 : : const struct rte_flow_item pattern[],
904 : : const struct rte_flow_action actions[],
905 : : struct rte_eth_syn_filter *filter,
906 : : struct rte_flow_error *error)
907 : : {
908 : : const struct rte_flow_item *item;
909 : : const struct rte_flow_action *act;
910 : : const struct rte_flow_item_tcp *tcp_spec;
911 : : const struct rte_flow_item_tcp *tcp_mask;
912 : : const struct rte_flow_action_queue *act_q;
913 : :
914 [ # # ]: 0 : if (!pattern) {
915 : 0 : rte_flow_error_set(error, EINVAL,
916 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
917 : : NULL, "NULL pattern.");
918 : 0 : return -rte_errno;
919 : : }
920 : :
921 [ # # ]: 0 : if (!actions) {
922 : 0 : rte_flow_error_set(error, EINVAL,
923 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
924 : : NULL, "NULL action.");
925 : 0 : return -rte_errno;
926 : : }
927 : :
928 [ # # ]: 0 : if (!attr) {
929 : 0 : rte_flow_error_set(error, EINVAL,
930 : : RTE_FLOW_ERROR_TYPE_ATTR,
931 : : NULL, "NULL attribute.");
932 : 0 : return -rte_errno;
933 : : }
934 : :
935 : :
936 : : /* the first not void item should be MAC or IPv4 or IPv6 or TCP */
937 : : item = next_no_void_pattern(pattern, NULL);
938 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
939 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
940 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
941 : : item->type != RTE_FLOW_ITEM_TYPE_TCP) {
942 : 0 : rte_flow_error_set(error, EINVAL,
943 : : RTE_FLOW_ERROR_TYPE_ITEM,
944 : : item, "Not supported by syn filter");
945 : 0 : return -rte_errno;
946 : : }
947 : : /*Not supported last point for range*/
948 [ # # ]: 0 : if (item->last) {
949 : 0 : rte_flow_error_set(error, EINVAL,
950 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
951 : : item, "Not supported last point for range");
952 : 0 : return -rte_errno;
953 : : }
954 : :
955 : : /* Skip Ethernet */
956 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
957 : : /* if the item is MAC, the content should be NULL */
958 [ # # # # ]: 0 : if (item->spec || item->mask) {
959 : 0 : rte_flow_error_set(error, EINVAL,
960 : : RTE_FLOW_ERROR_TYPE_ITEM,
961 : : item, "Invalid SYN address mask");
962 : 0 : return -rte_errno;
963 : : }
964 : :
965 : : /* check if the next not void item is IPv4 or IPv6 */
966 : : item = next_no_void_pattern(pattern, item);
967 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
968 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
969 : 0 : rte_flow_error_set(error, EINVAL,
970 : : RTE_FLOW_ERROR_TYPE_ITEM,
971 : : item, "Not supported by syn filter");
972 : 0 : return -rte_errno;
973 : : }
974 : : }
975 : :
976 : : /* Skip IP */
977 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
978 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
979 : : /* if the item is IP, the content should be NULL */
980 [ # # # # ]: 0 : if (item->spec || item->mask) {
981 : 0 : rte_flow_error_set(error, EINVAL,
982 : : RTE_FLOW_ERROR_TYPE_ITEM,
983 : : item, "Invalid SYN mask");
984 : 0 : return -rte_errno;
985 : : }
986 : :
987 : : /* check if the next not void item is TCP */
988 : : item = next_no_void_pattern(pattern, item);
989 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP) {
990 : 0 : rte_flow_error_set(error, EINVAL,
991 : : RTE_FLOW_ERROR_TYPE_ITEM,
992 : : item, "Not supported by syn filter");
993 : 0 : return -rte_errno;
994 : : }
995 : : }
996 : :
997 : : /* Get the TCP info. Only support SYN. */
998 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
999 : 0 : rte_flow_error_set(error, EINVAL,
1000 : : RTE_FLOW_ERROR_TYPE_ITEM,
1001 : : item, "Invalid SYN mask");
1002 : 0 : return -rte_errno;
1003 : : }
1004 : : /*Not supported last point for range*/
1005 [ # # ]: 0 : if (item->last) {
1006 : 0 : rte_flow_error_set(error, EINVAL,
1007 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1008 : : item, "Not supported last point for range");
1009 : 0 : return -rte_errno;
1010 : : }
1011 : :
1012 : : tcp_spec = item->spec;
1013 : : tcp_mask = item->mask;
1014 [ # # ]: 0 : if (!(tcp_spec->hdr.tcp_flags & RTE_TCP_SYN_FLAG) ||
1015 [ # # ]: 0 : tcp_mask->hdr.src_port ||
1016 [ # # ]: 0 : tcp_mask->hdr.dst_port ||
1017 [ # # ]: 0 : tcp_mask->hdr.sent_seq ||
1018 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
1019 [ # # ]: 0 : tcp_mask->hdr.data_off ||
1020 [ # # ]: 0 : tcp_mask->hdr.tcp_flags != RTE_TCP_SYN_FLAG ||
1021 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
1022 [ # # ]: 0 : tcp_mask->hdr.cksum ||
1023 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
1024 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1025 : 0 : rte_flow_error_set(error, EINVAL,
1026 : : RTE_FLOW_ERROR_TYPE_ITEM,
1027 : : item, "Not supported by syn filter");
1028 : 0 : return -rte_errno;
1029 : : }
1030 : :
1031 : : /* check if the next not void item is END */
1032 : : item = next_no_void_pattern(pattern, item);
1033 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1034 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1035 : 0 : rte_flow_error_set(error, EINVAL,
1036 : : RTE_FLOW_ERROR_TYPE_ITEM,
1037 : : item, "Not supported by syn filter");
1038 : 0 : return -rte_errno;
1039 : : }
1040 : :
1041 : : /* check if the first not void action is QUEUE. */
1042 : : act = next_no_void_action(actions, NULL);
1043 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
1044 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1045 : 0 : rte_flow_error_set(error, EINVAL,
1046 : : RTE_FLOW_ERROR_TYPE_ACTION,
1047 : : act, "Not supported action.");
1048 : 0 : return -rte_errno;
1049 : : }
1050 : :
1051 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
1052 : 0 : filter->queue = act_q->index;
1053 [ # # ]: 0 : if (filter->queue >= TXGBE_MAX_RX_QUEUE_NUM) {
1054 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1055 : 0 : rte_flow_error_set(error, EINVAL,
1056 : : RTE_FLOW_ERROR_TYPE_ACTION,
1057 : : act, "Not supported action.");
1058 : 0 : return -rte_errno;
1059 : : }
1060 : :
1061 : : /* check if the next not void item is END */
1062 : : act = next_no_void_action(actions, act);
1063 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1064 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1065 : 0 : rte_flow_error_set(error, EINVAL,
1066 : : RTE_FLOW_ERROR_TYPE_ACTION,
1067 : : act, "Not supported action.");
1068 : 0 : return -rte_errno;
1069 : : }
1070 : :
1071 : : /* parse attr */
1072 : : /* must be input direction */
1073 [ # # ]: 0 : if (!attr->ingress) {
1074 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1075 : 0 : rte_flow_error_set(error, EINVAL,
1076 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1077 : : attr, "Only support ingress.");
1078 : 0 : return -rte_errno;
1079 : : }
1080 : :
1081 : : /* not supported */
1082 [ # # ]: 0 : if (attr->egress) {
1083 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1084 : 0 : rte_flow_error_set(error, EINVAL,
1085 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1086 : : attr, "Not support egress.");
1087 : 0 : return -rte_errno;
1088 : : }
1089 : :
1090 : : /* not supported */
1091 [ # # ]: 0 : if (attr->transfer) {
1092 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1093 : 0 : rte_flow_error_set(error, EINVAL,
1094 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1095 : : attr, "No support for transfer.");
1096 : 0 : return -rte_errno;
1097 : : }
1098 : :
1099 : : /* Support 2 priorities, the lowest or highest. */
1100 [ # # ]: 0 : if (!attr->priority) {
1101 : 0 : filter->hig_pri = 0;
1102 [ # # ]: 0 : } else if (attr->priority == (uint32_t)~0U) {
1103 : 0 : filter->hig_pri = 1;
1104 : : } else {
1105 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1106 : 0 : rte_flow_error_set(error, EINVAL,
1107 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1108 : : attr, "Not support priority.");
1109 : 0 : return -rte_errno;
1110 : : }
1111 : :
1112 : : return 0;
1113 : : }
1114 : :
1115 : : static int
1116 : 0 : txgbe_parse_syn_filter(struct rte_eth_dev *dev,
1117 : : const struct rte_flow_attr *attr,
1118 : : const struct rte_flow_item pattern[],
1119 : : const struct rte_flow_action actions[],
1120 : : struct rte_eth_syn_filter *filter,
1121 : : struct rte_flow_error *error)
1122 : : {
1123 : : int ret;
1124 : :
1125 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
1126 : 0 : rte_flow_error_set(error, EINVAL,
1127 : : RTE_FLOW_ERROR_TYPE_ITEM,
1128 : : NULL, "Flow type not suppotted yet on VF");
1129 : 0 : return -rte_errno;
1130 : : }
1131 : :
1132 : 0 : ret = cons_parse_syn_filter(attr, pattern,
1133 : : actions, filter, error);
1134 : :
1135 [ # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues)
1136 : 0 : return -rte_errno;
1137 : :
1138 [ # # ]: 0 : if (ret)
1139 : 0 : return ret;
1140 : :
1141 : : return 0;
1142 : : }
1143 : :
1144 : : /**
1145 : : * Parse the rule to see if it is a L2 tunnel rule.
1146 : : * And get the L2 tunnel filter info BTW.
1147 : : * Only support E-tag now.
1148 : : * pattern:
1149 : : * The first not void item can be E_TAG.
1150 : : * The next not void item must be END.
1151 : : * action:
1152 : : * The first not void action should be VF or PF.
1153 : : * The next not void action should be END.
1154 : : * pattern example:
1155 : : * ITEM Spec Mask
1156 : : * E_TAG grp 0x1 0x3
1157 : : e_cid_base 0x309 0xFFF
1158 : : * END
1159 : : * other members in mask and spec should set to 0x00.
1160 : : * item->last should be NULL.
1161 : : */
1162 : : static int
1163 : 0 : cons_parse_l2_tn_filter(struct rte_eth_dev *dev,
1164 : : const struct rte_flow_attr *attr,
1165 : : const struct rte_flow_item pattern[],
1166 : : const struct rte_flow_action actions[],
1167 : : struct txgbe_l2_tunnel_conf *filter,
1168 : : struct rte_flow_error *error)
1169 : : {
1170 : : const struct rte_flow_item *item;
1171 : : const struct rte_flow_item_e_tag *e_tag_spec;
1172 : : const struct rte_flow_item_e_tag *e_tag_mask;
1173 : : const struct rte_flow_action *act;
1174 : : const struct rte_flow_action_vf *act_vf;
1175 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1176 : :
1177 [ # # ]: 0 : if (!pattern) {
1178 : 0 : rte_flow_error_set(error, EINVAL,
1179 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1180 : : NULL, "NULL pattern.");
1181 : 0 : return -rte_errno;
1182 : : }
1183 : :
1184 [ # # ]: 0 : if (!actions) {
1185 : 0 : rte_flow_error_set(error, EINVAL,
1186 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1187 : : NULL, "NULL action.");
1188 : 0 : return -rte_errno;
1189 : : }
1190 : :
1191 [ # # ]: 0 : if (!attr) {
1192 : 0 : rte_flow_error_set(error, EINVAL,
1193 : : RTE_FLOW_ERROR_TYPE_ATTR,
1194 : : NULL, "NULL attribute.");
1195 : 0 : return -rte_errno;
1196 : : }
1197 : :
1198 : : /* The first not void item should be e-tag. */
1199 : : item = next_no_void_pattern(pattern, NULL);
1200 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_E_TAG) {
1201 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1202 : 0 : rte_flow_error_set(error, EINVAL,
1203 : : RTE_FLOW_ERROR_TYPE_ITEM,
1204 : : item, "Not supported by L2 tunnel filter");
1205 : 0 : return -rte_errno;
1206 : : }
1207 : :
1208 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
1209 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1210 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
1211 : : item, "Not supported by L2 tunnel filter");
1212 : 0 : return -rte_errno;
1213 : : }
1214 : :
1215 : : /*Not supported last point for range*/
1216 [ # # ]: 0 : if (item->last) {
1217 : 0 : rte_flow_error_set(error, EINVAL,
1218 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1219 : : item, "Not supported last point for range");
1220 : 0 : return -rte_errno;
1221 : : }
1222 : :
1223 : : e_tag_spec = item->spec;
1224 : : e_tag_mask = item->mask;
1225 : :
1226 : : /* Only care about GRP and E cid base. */
1227 [ # # ]: 0 : if (e_tag_mask->epcp_edei_in_ecid_b ||
1228 [ # # ]: 0 : e_tag_mask->in_ecid_e ||
1229 : 0 : e_tag_mask->ecid_e ||
1230 [ # # ]: 0 : e_tag_mask->rsvd_grp_ecid_b != rte_cpu_to_be_16(0x3FFF)) {
1231 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1232 : 0 : rte_flow_error_set(error, EINVAL,
1233 : : RTE_FLOW_ERROR_TYPE_ITEM,
1234 : : item, "Not supported by L2 tunnel filter");
1235 : 0 : return -rte_errno;
1236 : : }
1237 : :
1238 : 0 : filter->l2_tunnel_type = RTE_ETH_L2_TUNNEL_TYPE_E_TAG;
1239 : : /**
1240 : : * grp and e_cid_base are bit fields and only use 14 bits.
1241 : : * e-tag id is taken as little endian by HW.
1242 : : */
1243 [ # # ]: 0 : filter->tunnel_id = rte_be_to_cpu_16(e_tag_spec->rsvd_grp_ecid_b);
1244 : :
1245 : : /* check if the next not void item is END */
1246 : : item = next_no_void_pattern(pattern, item);
1247 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1248 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1249 : 0 : rte_flow_error_set(error, EINVAL,
1250 : : RTE_FLOW_ERROR_TYPE_ITEM,
1251 : : item, "Not supported by L2 tunnel filter");
1252 : 0 : return -rte_errno;
1253 : : }
1254 : :
1255 : : /* parse attr */
1256 : : /* must be input direction */
1257 [ # # ]: 0 : if (!attr->ingress) {
1258 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1259 : 0 : rte_flow_error_set(error, EINVAL,
1260 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1261 : : attr, "Only support ingress.");
1262 : 0 : return -rte_errno;
1263 : : }
1264 : :
1265 : : /* not supported */
1266 [ # # ]: 0 : if (attr->egress) {
1267 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1268 : 0 : rte_flow_error_set(error, EINVAL,
1269 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1270 : : attr, "Not support egress.");
1271 : 0 : return -rte_errno;
1272 : : }
1273 : :
1274 : : /* not supported */
1275 [ # # ]: 0 : if (attr->transfer) {
1276 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1277 : 0 : rte_flow_error_set(error, EINVAL,
1278 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1279 : : attr, "No support for transfer.");
1280 : 0 : return -rte_errno;
1281 : : }
1282 : :
1283 : : /* not supported */
1284 [ # # ]: 0 : if (attr->priority) {
1285 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1286 : 0 : rte_flow_error_set(error, EINVAL,
1287 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1288 : : attr, "Not support priority.");
1289 : 0 : return -rte_errno;
1290 : : }
1291 : :
1292 : : /* check if the first not void action is VF or PF. */
1293 : : act = next_no_void_action(actions, NULL);
1294 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_VF &&
1295 : : act->type != RTE_FLOW_ACTION_TYPE_PF) {
1296 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1297 : 0 : rte_flow_error_set(error, EINVAL,
1298 : : RTE_FLOW_ERROR_TYPE_ACTION,
1299 : : act, "Not supported action.");
1300 : 0 : return -rte_errno;
1301 : : }
1302 : :
1303 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_VF) {
1304 : 0 : act_vf = (const struct rte_flow_action_vf *)act->conf;
1305 : 0 : filter->pool = act_vf->id;
1306 : : } else {
1307 : 0 : filter->pool = pci_dev->max_vfs;
1308 : : }
1309 : :
1310 : : /* check if the next not void item is END */
1311 : : act = next_no_void_action(actions, act);
1312 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1313 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1314 : 0 : rte_flow_error_set(error, EINVAL,
1315 : : RTE_FLOW_ERROR_TYPE_ACTION,
1316 : : act, "Not supported action.");
1317 : 0 : return -rte_errno;
1318 : : }
1319 : :
1320 : : return 0;
1321 : : }
1322 : :
1323 : : static int
1324 : 0 : txgbe_parse_l2_tn_filter(struct rte_eth_dev *dev,
1325 : : const struct rte_flow_attr *attr,
1326 : : const struct rte_flow_item pattern[],
1327 : : const struct rte_flow_action actions[],
1328 : : struct txgbe_l2_tunnel_conf *l2_tn_filter,
1329 : : struct rte_flow_error *error)
1330 : : {
1331 : : int ret = 0;
1332 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1333 : : uint16_t vf_num;
1334 : :
1335 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
1336 : 0 : rte_flow_error_set(error, EINVAL,
1337 : : RTE_FLOW_ERROR_TYPE_ITEM,
1338 : : NULL, "Flow type not suppotted yet on VF");
1339 : 0 : return -rte_errno;
1340 : : }
1341 : :
1342 : 0 : ret = cons_parse_l2_tn_filter(dev, attr, pattern,
1343 : : actions, l2_tn_filter, error);
1344 : :
1345 : 0 : vf_num = pci_dev->max_vfs;
1346 : :
1347 [ # # ]: 0 : if (l2_tn_filter->pool > vf_num)
1348 : 0 : return -rte_errno;
1349 : :
1350 : : return ret;
1351 : : }
1352 : :
1353 : : /* Parse to get the attr and action info of flow director rule. */
1354 : : static int
1355 : 0 : txgbe_parse_fdir_act_attr(const struct rte_flow_attr *attr,
1356 : : const struct rte_flow_action actions[],
1357 : : struct txgbe_fdir_rule *rule,
1358 : : struct rte_flow_error *error)
1359 : : {
1360 : : const struct rte_flow_action *act;
1361 : : const struct rte_flow_action_queue *act_q;
1362 : :
1363 : : /* parse attr */
1364 : : /* must be input direction */
1365 [ # # ]: 0 : if (!attr->ingress) {
1366 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1367 : 0 : rte_flow_error_set(error, EINVAL,
1368 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1369 : : attr, "Only support ingress.");
1370 : 0 : return -rte_errno;
1371 : : }
1372 : :
1373 : : /* not supported */
1374 [ # # ]: 0 : if (attr->egress) {
1375 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1376 : 0 : rte_flow_error_set(error, EINVAL,
1377 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1378 : : attr, "Not support egress.");
1379 : 0 : return -rte_errno;
1380 : : }
1381 : :
1382 : : /* not supported */
1383 [ # # ]: 0 : if (attr->transfer) {
1384 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1385 : 0 : rte_flow_error_set(error, EINVAL,
1386 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1387 : : attr, "No support for transfer.");
1388 : 0 : return -rte_errno;
1389 : : }
1390 : :
1391 : : /* not supported */
1392 [ # # ]: 0 : if (attr->priority) {
1393 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1394 : 0 : rte_flow_error_set(error, EINVAL,
1395 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1396 : : attr, "Not support priority.");
1397 : 0 : return -rte_errno;
1398 : : }
1399 : :
1400 : : /* check if the first not void action is QUEUE or DROP. */
1401 : : act = next_no_void_action(actions, NULL);
1402 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
1403 : : act->type != RTE_FLOW_ACTION_TYPE_DROP) {
1404 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1405 : 0 : rte_flow_error_set(error, EINVAL,
1406 : : RTE_FLOW_ERROR_TYPE_ACTION,
1407 : : act, "Not supported action.");
1408 : 0 : return -rte_errno;
1409 : : }
1410 : :
1411 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
1412 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
1413 : 0 : rule->queue = act_q->index;
1414 : : } else { /* drop */
1415 : : /* signature mode does not support drop action. */
1416 [ # # ]: 0 : if (rule->mode == RTE_FDIR_MODE_SIGNATURE) {
1417 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1418 : 0 : rte_flow_error_set(error, EINVAL,
1419 : : RTE_FLOW_ERROR_TYPE_ACTION,
1420 : : act, "Not supported action.");
1421 : 0 : return -rte_errno;
1422 : : }
1423 : 0 : rule->fdirflags = TXGBE_FDIRPICMD_DROP;
1424 : : }
1425 : :
1426 : : /* nothing else supported */
1427 : : act = next_no_void_action(actions, act);
1428 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1429 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1430 : 0 : rte_flow_error_set(error, EINVAL,
1431 : : RTE_FLOW_ERROR_TYPE_ACTION,
1432 : : act, "Not supported action.");
1433 : 0 : return -rte_errno;
1434 : : }
1435 : :
1436 : 0 : rule->soft_id = 0;
1437 : :
1438 : 0 : return 0;
1439 : : }
1440 : :
1441 : : /* search next no void pattern and skip fuzzy */
1442 : : static inline
1443 : : const struct rte_flow_item *next_no_fuzzy_pattern(
1444 : : const struct rte_flow_item pattern[],
1445 : : const struct rte_flow_item *cur)
1446 : : {
1447 : : const struct rte_flow_item *next =
1448 : : next_no_void_pattern(pattern, cur);
1449 : : while (1) {
1450 [ # # # # : 0 : if (next->type != RTE_FLOW_ITEM_TYPE_FUZZY)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1451 : : return next;
1452 : : next = next_no_void_pattern(pattern, next);
1453 : : }
1454 : : }
1455 : :
1456 : 0 : static inline uint8_t signature_match(const struct rte_flow_item pattern[])
1457 : : {
1458 : : const struct rte_flow_item_fuzzy *spec, *last, *mask;
1459 : : const struct rte_flow_item *item;
1460 : : uint32_t sh, lh, mh;
1461 : : int i = 0;
1462 : :
1463 : : while (1) {
1464 : 0 : item = pattern + i;
1465 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_END)
1466 : : break;
1467 : :
1468 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_FUZZY) {
1469 : 0 : spec = item->spec;
1470 : 0 : last = item->last;
1471 : 0 : mask = item->mask;
1472 : :
1473 [ # # ]: 0 : if (!spec || !mask)
1474 : : return 0;
1475 : :
1476 : 0 : sh = spec->thresh;
1477 : :
1478 [ # # ]: 0 : if (!last)
1479 : : lh = sh;
1480 : : else
1481 : 0 : lh = last->thresh;
1482 : :
1483 : 0 : mh = mask->thresh;
1484 : 0 : sh = sh & mh;
1485 : 0 : lh = lh & mh;
1486 : :
1487 [ # # ]: 0 : if (!sh || sh > lh)
1488 : : return 0;
1489 : :
1490 : 0 : return 1;
1491 : : }
1492 : :
1493 : 0 : i++;
1494 : : }
1495 : :
1496 : : return 0;
1497 : : }
1498 : :
1499 : : static void
1500 : 0 : txgbe_fdir_parse_flow_type(struct txgbe_atr_input *input, u8 ptid, bool tun)
1501 : : {
1502 [ # # ]: 0 : if (!tun)
1503 : : ptid = TXGBE_PTID_PKT_IP;
1504 : :
1505 [ # # # # ]: 0 : switch (input->flow_type & TXGBE_ATR_L4TYPE_MASK) {
1506 : 0 : case TXGBE_ATR_L4TYPE_UDP:
1507 : 0 : ptid |= TXGBE_PTID_TYP_UDP;
1508 : 0 : break;
1509 : 0 : case TXGBE_ATR_L4TYPE_TCP:
1510 : 0 : ptid |= TXGBE_PTID_TYP_TCP;
1511 : 0 : break;
1512 : 0 : case TXGBE_ATR_L4TYPE_SCTP:
1513 : 0 : ptid |= TXGBE_PTID_TYP_SCTP;
1514 : 0 : break;
1515 : : default:
1516 : : break;
1517 : : }
1518 : :
1519 [ # # ]: 0 : switch (input->flow_type & TXGBE_ATR_L3TYPE_MASK) {
1520 : : case TXGBE_ATR_L3TYPE_IPV4:
1521 : : break;
1522 : 0 : case TXGBE_ATR_L3TYPE_IPV6:
1523 : 0 : ptid |= TXGBE_PTID_PKT_IPV6;
1524 : 0 : break;
1525 : : default:
1526 : : break;
1527 : : }
1528 : :
1529 [ # # ]: 0 : input->pkt_type = cpu_to_be16(ptid);
1530 : 0 : }
1531 : :
1532 : : /**
1533 : : * Parse the rule to see if it is a IP flow director rule.
1534 : : * And get the flow director filter info BTW.
1535 : : * UDP/TCP/SCTP PATTERN:
1536 : : * The first not void item can be ETH or IPV4 or IPV6
1537 : : * The second not void item must be IPV4 or IPV6 if the first one is ETH.
1538 : : * The next not void item could be UDP or TCP or SCTP (optional)
1539 : : * The next not void item could be RAW (for flexbyte, optional)
1540 : : * The next not void item must be END.
1541 : : * A Fuzzy Match pattern can appear at any place before END.
1542 : : * Fuzzy Match is optional for IPV4 but is required for IPV6
1543 : : * MAC VLAN PATTERN:
1544 : : * The first not void item must be ETH.
1545 : : * The second not void item must be MAC VLAN.
1546 : : * The next not void item must be END.
1547 : : * ACTION:
1548 : : * The first not void action should be QUEUE or DROP.
1549 : : * The next not void action should be END.
1550 : : * UDP/TCP/SCTP pattern example:
1551 : : * ITEM Spec Mask
1552 : : * ETH NULL NULL
1553 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
1554 : : * dst_addr 192.167.3.50 0xFFFFFFFF
1555 : : * UDP/TCP/SCTP src_port 80 0xFFFF
1556 : : * dst_port 80 0xFFFF
1557 : : * FLEX relative 0 0x1
1558 : : * search 0 0x1
1559 : : * reserved 0 0
1560 : : * offset 12 0xFFFFFFFF
1561 : : * limit 0 0xFFFF
1562 : : * length 2 0xFFFF
1563 : : * pattern[0] 0x86 0xFF
1564 : : * pattern[1] 0xDD 0xFF
1565 : : * END
1566 : : * MAC VLAN pattern example:
1567 : : * ITEM Spec Mask
1568 : : * ETH dst_addr
1569 : : {0xAC, 0x7B, 0xA1, {0xFF, 0xFF, 0xFF,
1570 : : 0x2C, 0x6D, 0x36} 0xFF, 0xFF, 0xFF}
1571 : : * MAC VLAN tci 0x2016 0xEFFF
1572 : : * END
1573 : : * Other members in mask and spec should set to 0x00.
1574 : : * Item->last should be NULL.
1575 : : */
1576 : : static int
1577 : 0 : txgbe_parse_fdir_filter_normal(struct rte_eth_dev *dev __rte_unused,
1578 : : const struct rte_flow_attr *attr,
1579 : : const struct rte_flow_item pattern[],
1580 : : const struct rte_flow_action actions[],
1581 : : struct txgbe_fdir_rule *rule,
1582 : : struct rte_flow_error *error)
1583 : : {
1584 : : const struct rte_flow_item *item;
1585 : : const struct rte_flow_item_eth *eth_mask;
1586 : : const struct rte_flow_item_ipv4 *ipv4_spec;
1587 : : const struct rte_flow_item_ipv4 *ipv4_mask;
1588 : : const struct rte_flow_item_ipv6 *ipv6_spec;
1589 : : const struct rte_flow_item_ipv6 *ipv6_mask;
1590 : : const struct rte_flow_item_tcp *tcp_spec;
1591 : : const struct rte_flow_item_tcp *tcp_mask;
1592 : : const struct rte_flow_item_udp *udp_spec;
1593 : : const struct rte_flow_item_udp *udp_mask;
1594 : : const struct rte_flow_item_sctp *sctp_spec;
1595 : : const struct rte_flow_item_sctp *sctp_mask;
1596 : : const struct rte_flow_item_raw *raw_mask;
1597 : : const struct rte_flow_item_raw *raw_spec;
1598 : : uint8_t j;
1599 : :
1600 [ # # ]: 0 : if (!pattern) {
1601 : 0 : rte_flow_error_set(error, EINVAL,
1602 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1603 : : NULL, "NULL pattern.");
1604 : 0 : return -rte_errno;
1605 : : }
1606 : :
1607 [ # # ]: 0 : if (!actions) {
1608 : 0 : rte_flow_error_set(error, EINVAL,
1609 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1610 : : NULL, "NULL action.");
1611 : 0 : return -rte_errno;
1612 : : }
1613 : :
1614 [ # # ]: 0 : if (!attr) {
1615 : 0 : rte_flow_error_set(error, EINVAL,
1616 : : RTE_FLOW_ERROR_TYPE_ATTR,
1617 : : NULL, "NULL attribute.");
1618 : 0 : return -rte_errno;
1619 : : }
1620 : :
1621 : : /**
1622 : : * Some fields may not be provided. Set spec to 0 and mask to default
1623 : : * value. So, we need not do anything for the not provided fields later.
1624 : : */
1625 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1626 : : memset(&rule->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
1627 : 0 : rule->mask.pkt_type_mask = TXGBE_ATR_TYPE_MASK_L3P |
1628 : : TXGBE_ATR_TYPE_MASK_L4P;
1629 : 0 : memset(&rule->input, 0, sizeof(struct txgbe_atr_input));
1630 : :
1631 : : /**
1632 : : * The first not void item should be
1633 : : * MAC or IPv4 or TCP or UDP or SCTP.
1634 : : */
1635 : : item = next_no_fuzzy_pattern(pattern, NULL);
1636 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
1637 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1638 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
1639 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1640 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1641 : : item->type != RTE_FLOW_ITEM_TYPE_SCTP) {
1642 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1643 : 0 : rte_flow_error_set(error, EINVAL,
1644 : : RTE_FLOW_ERROR_TYPE_ITEM,
1645 : : item, "Not supported by fdir filter");
1646 : 0 : return -rte_errno;
1647 : : }
1648 : :
1649 [ # # ]: 0 : if (signature_match(pattern))
1650 : 0 : rule->mode = RTE_FDIR_MODE_SIGNATURE;
1651 : : else
1652 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT;
1653 : :
1654 : : /*Not supported last point for range*/
1655 [ # # ]: 0 : if (item->last) {
1656 : 0 : rte_flow_error_set(error, EINVAL,
1657 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1658 : : item, "Not supported last point for range");
1659 : 0 : return -rte_errno;
1660 : : }
1661 : :
1662 : : /* Get the MAC info. */
1663 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
1664 : : /**
1665 : : * Only support vlan and dst MAC address,
1666 : : * others should be masked.
1667 : : */
1668 [ # # # # ]: 0 : if (item->spec && !item->mask) {
1669 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1670 : 0 : rte_flow_error_set(error, EINVAL,
1671 : : RTE_FLOW_ERROR_TYPE_ITEM,
1672 : : item, "Not supported by fdir filter");
1673 : 0 : return -rte_errno;
1674 : : }
1675 : :
1676 [ # # ]: 0 : if (item->mask) {
1677 : 0 : rule->b_mask = TRUE;
1678 : : eth_mask = item->mask;
1679 : :
1680 : : /* Ether type should be masked. */
1681 [ # # ]: 0 : if (eth_mask->hdr.ether_type ||
1682 [ # # ]: 0 : rule->mode == RTE_FDIR_MODE_SIGNATURE) {
1683 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1684 : 0 : rte_flow_error_set(error, EINVAL,
1685 : : RTE_FLOW_ERROR_TYPE_ITEM,
1686 : : item, "Not supported by fdir filter");
1687 : 0 : return -rte_errno;
1688 : : }
1689 : :
1690 : : /* If ethernet has meaning, it means MAC VLAN mode. */
1691 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
1692 : :
1693 : : /**
1694 : : * src MAC address must be masked,
1695 : : * and don't support dst MAC address mask.
1696 : : */
1697 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
1698 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j] ||
1699 [ # # ]: 0 : eth_mask->hdr.dst_addr.addr_bytes[j] != 0xFF) {
1700 : : memset(rule, 0,
1701 : : sizeof(struct txgbe_fdir_rule));
1702 : 0 : rte_flow_error_set(error, EINVAL,
1703 : : RTE_FLOW_ERROR_TYPE_ITEM,
1704 : : item, "Not supported by fdir filter");
1705 : 0 : return -rte_errno;
1706 : : }
1707 : : }
1708 : :
1709 : : /* When no VLAN, considered as full mask. */
1710 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
1711 : : }
1712 : : /*** If both spec and mask are item,
1713 : : * it means don't care about ETH.
1714 : : * Do nothing.
1715 : : */
1716 : :
1717 : : /**
1718 : : * Check if the next not void item is vlan or ipv4.
1719 : : * IPv6 is not supported.
1720 : : */
1721 : : item = next_no_fuzzy_pattern(pattern, item);
1722 [ # # ]: 0 : if (rule->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
1723 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
1724 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1725 : 0 : rte_flow_error_set(error, EINVAL,
1726 : : RTE_FLOW_ERROR_TYPE_ITEM,
1727 : : item, "Not supported by fdir filter");
1728 : 0 : return -rte_errno;
1729 : : }
1730 : : } else {
1731 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1732 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN &&
1733 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
1734 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1735 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1736 : 0 : rte_flow_error_set(error, EINVAL,
1737 : : RTE_FLOW_ERROR_TYPE_ITEM,
1738 : : item, "Not supported by fdir filter");
1739 : 0 : return -rte_errno;
1740 : : }
1741 : : }
1742 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN)
1743 : : item = next_no_fuzzy_pattern(pattern, item);
1744 : : }
1745 : :
1746 : : /* Get the IPV4 info. */
1747 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
1748 : : /**
1749 : : * Set the flow type even if there's no content
1750 : : * as we must have a flow type.
1751 : : */
1752 : : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV4;
1753 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
1754 : : /*Not supported last point for range*/
1755 [ # # ]: 0 : if (item->last) {
1756 : 0 : rte_flow_error_set(error, EINVAL,
1757 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1758 : : item, "Not supported last point for range");
1759 : 0 : return -rte_errno;
1760 : : }
1761 : : /**
1762 : : * Only care about src & dst addresses,
1763 : : * others should be masked.
1764 : : */
1765 [ # # ]: 0 : if (item->mask) {
1766 : 0 : rule->b_mask = TRUE;
1767 : : ipv4_mask = item->mask;
1768 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
1769 : 0 : ipv4_mask->hdr.type_of_service ||
1770 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
1771 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
1772 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
1773 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
1774 : 0 : ipv4_mask->hdr.next_proto_id ||
1775 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
1776 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1777 : 0 : rte_flow_error_set(error, EINVAL,
1778 : : RTE_FLOW_ERROR_TYPE_ITEM,
1779 : : item, "Not supported by fdir filter");
1780 : 0 : return -rte_errno;
1781 : : }
1782 : 0 : rule->mask.dst_ipv4_mask = ipv4_mask->hdr.dst_addr;
1783 : 0 : rule->mask.src_ipv4_mask = ipv4_mask->hdr.src_addr;
1784 : : }
1785 : :
1786 [ # # ]: 0 : if (item->spec) {
1787 : 0 : rule->b_spec = TRUE;
1788 : : ipv4_spec = item->spec;
1789 : 0 : rule->input.dst_ip[0] =
1790 : 0 : ipv4_spec->hdr.dst_addr;
1791 : 0 : rule->input.src_ip[0] =
1792 : 0 : ipv4_spec->hdr.src_addr;
1793 : : }
1794 : :
1795 : : /**
1796 : : * Check if the next not void item is
1797 : : * TCP or UDP or SCTP or END.
1798 : : */
1799 : : item = next_no_fuzzy_pattern(pattern, item);
1800 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1801 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1802 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1803 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1804 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1805 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1806 : 0 : rte_flow_error_set(error, EINVAL,
1807 : : RTE_FLOW_ERROR_TYPE_ITEM,
1808 : : item, "Not supported by fdir filter");
1809 : 0 : return -rte_errno;
1810 : : }
1811 : : }
1812 : :
1813 : : /* Get the IPV6 info. */
1814 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
1815 : : /**
1816 : : * Set the flow type even if there's no content
1817 : : * as we must have a flow type.
1818 : : */
1819 : 0 : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV6;
1820 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
1821 : :
1822 [ # # ]: 0 : if (item->last) {
1823 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1824 : 0 : rte_flow_error_set(error, EINVAL,
1825 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1826 : : item, "Not supported last point for range");
1827 : 0 : return -rte_errno;
1828 : : }
1829 : :
1830 [ # # ]: 0 : if (item->mask) {
1831 : 0 : rule->b_mask = TRUE;
1832 : : ipv6_mask = item->mask;
1833 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow ||
1834 : : ipv6_mask->hdr.payload_len ||
1835 [ # # ]: 0 : ipv6_mask->hdr.proto ||
1836 : : ipv6_mask->hdr.hop_limits) {
1837 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1838 : 0 : rte_flow_error_set(error, EINVAL,
1839 : : RTE_FLOW_ERROR_TYPE_ITEM,
1840 : : item, "Not supported by fdir filter");
1841 : 0 : return -rte_errno;
1842 : : }
1843 : :
1844 : : /* check src addr mask */
1845 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1846 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j] == UINT8_MAX) {
1847 : 0 : rule->mask.src_ipv6_mask |= 1 << j;
1848 [ # # ]: 0 : } else if (ipv6_mask->hdr.src_addr.a[j] != 0) {
1849 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1850 : 0 : rte_flow_error_set(error, EINVAL,
1851 : : RTE_FLOW_ERROR_TYPE_ITEM,
1852 : : item, "Not supported by fdir filter");
1853 : 0 : return -rte_errno;
1854 : : }
1855 : : }
1856 : :
1857 : : /* check dst addr mask */
1858 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1859 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j] != 0) {
1860 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1861 : 0 : rte_flow_error_set(error, EINVAL,
1862 : : RTE_FLOW_ERROR_TYPE_ITEM,
1863 : : item, "Not supported by fdir filter");
1864 : 0 : return -rte_errno;
1865 : : }
1866 : : }
1867 : : }
1868 : :
1869 [ # # ]: 0 : if (item->spec) {
1870 : 0 : rule->b_spec = TRUE;
1871 : : ipv6_spec = item->spec;
1872 : : rte_memcpy(rule->input.src_ip,
1873 : : &ipv6_spec->hdr.src_addr, 16);
1874 : : rte_memcpy(rule->input.dst_ip,
1875 : : &ipv6_spec->hdr.dst_addr, 16);
1876 : : }
1877 : :
1878 : : /**
1879 : : * Check if the next not void item is
1880 : : * TCP or UDP or SCTP or END.
1881 : : */
1882 : : item = next_no_fuzzy_pattern(pattern, item);
1883 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1884 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1885 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1886 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1887 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1888 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1889 : 0 : rte_flow_error_set(error, EINVAL,
1890 : : RTE_FLOW_ERROR_TYPE_ITEM,
1891 : : item, "Not supported by fdir filter");
1892 : 0 : return -rte_errno;
1893 : : }
1894 : : }
1895 : :
1896 : : /* Get the TCP info. */
1897 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
1898 : : /**
1899 : : * Set the flow type even if there's no content
1900 : : * as we must have a flow type.
1901 : : */
1902 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_TCP;
1903 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
1904 : :
1905 : : /*Not supported last point for range*/
1906 [ # # ]: 0 : if (item->last) {
1907 : 0 : rte_flow_error_set(error, EINVAL,
1908 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1909 : : item, "Not supported last point for range");
1910 : 0 : return -rte_errno;
1911 : : }
1912 : : /**
1913 : : * Only care about src & dst ports,
1914 : : * others should be masked.
1915 : : */
1916 [ # # ]: 0 : if (!item->mask) {
1917 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1918 : 0 : rte_flow_error_set(error, EINVAL,
1919 : : RTE_FLOW_ERROR_TYPE_ITEM,
1920 : : item, "Not supported by fdir filter");
1921 : 0 : return -rte_errno;
1922 : : }
1923 : 0 : rule->b_mask = TRUE;
1924 : : tcp_mask = item->mask;
1925 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
1926 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
1927 [ # # ]: 0 : tcp_mask->hdr.data_off ||
1928 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
1929 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
1930 [ # # ]: 0 : tcp_mask->hdr.cksum ||
1931 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
1932 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1933 : 0 : rte_flow_error_set(error, EINVAL,
1934 : : RTE_FLOW_ERROR_TYPE_ITEM,
1935 : : item, "Not supported by fdir filter");
1936 : 0 : return -rte_errno;
1937 : : }
1938 : 0 : rule->mask.src_port_mask = tcp_mask->hdr.src_port;
1939 : 0 : rule->mask.dst_port_mask = tcp_mask->hdr.dst_port;
1940 : :
1941 [ # # ]: 0 : if (item->spec) {
1942 : 0 : rule->b_spec = TRUE;
1943 : : tcp_spec = item->spec;
1944 : 0 : rule->input.src_port =
1945 : 0 : tcp_spec->hdr.src_port;
1946 : 0 : rule->input.dst_port =
1947 : 0 : tcp_spec->hdr.dst_port;
1948 : : }
1949 : :
1950 : : item = next_no_fuzzy_pattern(pattern, item);
1951 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
1952 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
1953 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1954 : 0 : rte_flow_error_set(error, EINVAL,
1955 : : RTE_FLOW_ERROR_TYPE_ITEM,
1956 : : item, "Not supported by fdir filter");
1957 : 0 : return -rte_errno;
1958 : : }
1959 : : }
1960 : :
1961 : : /* Get the UDP info */
1962 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
1963 : : /**
1964 : : * Set the flow type even if there's no content
1965 : : * as we must have a flow type.
1966 : : */
1967 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_UDP;
1968 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
1969 : :
1970 : : /*Not supported last point for range*/
1971 [ # # ]: 0 : if (item->last) {
1972 : 0 : rte_flow_error_set(error, EINVAL,
1973 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1974 : : item, "Not supported last point for range");
1975 : 0 : return -rte_errno;
1976 : : }
1977 : : /**
1978 : : * Only care about src & dst ports,
1979 : : * others should be masked.
1980 : : */
1981 [ # # ]: 0 : if (!item->mask) {
1982 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1983 : 0 : rte_flow_error_set(error, EINVAL,
1984 : : RTE_FLOW_ERROR_TYPE_ITEM,
1985 : : item, "Not supported by fdir filter");
1986 : 0 : return -rte_errno;
1987 : : }
1988 : 0 : rule->b_mask = TRUE;
1989 : : udp_mask = item->mask;
1990 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
1991 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
1992 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1993 : 0 : rte_flow_error_set(error, EINVAL,
1994 : : RTE_FLOW_ERROR_TYPE_ITEM,
1995 : : item, "Not supported by fdir filter");
1996 : 0 : return -rte_errno;
1997 : : }
1998 : 0 : rule->mask.src_port_mask = udp_mask->hdr.src_port;
1999 : 0 : rule->mask.dst_port_mask = udp_mask->hdr.dst_port;
2000 : :
2001 [ # # ]: 0 : if (item->spec) {
2002 : 0 : rule->b_spec = TRUE;
2003 : : udp_spec = item->spec;
2004 : 0 : rule->input.src_port =
2005 : 0 : udp_spec->hdr.src_port;
2006 : 0 : rule->input.dst_port =
2007 : 0 : udp_spec->hdr.dst_port;
2008 : : }
2009 : :
2010 : : item = next_no_fuzzy_pattern(pattern, item);
2011 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2012 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2013 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2014 : 0 : rte_flow_error_set(error, EINVAL,
2015 : : RTE_FLOW_ERROR_TYPE_ITEM,
2016 : : item, "Not supported by fdir filter");
2017 : 0 : return -rte_errno;
2018 : : }
2019 : : }
2020 : :
2021 : : /* Get the SCTP info */
2022 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
2023 : : /**
2024 : : * Set the flow type even if there's no content
2025 : : * as we must have a flow type.
2026 : : */
2027 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_SCTP;
2028 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2029 : :
2030 : : /*Not supported last point for range*/
2031 [ # # ]: 0 : if (item->last) {
2032 : 0 : rte_flow_error_set(error, EINVAL,
2033 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2034 : : item, "Not supported last point for range");
2035 : 0 : return -rte_errno;
2036 : : }
2037 : :
2038 : : /**
2039 : : * Only care about src & dst ports,
2040 : : * others should be masked.
2041 : : */
2042 [ # # ]: 0 : if (!item->mask) {
2043 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2044 : 0 : rte_flow_error_set(error, EINVAL,
2045 : : RTE_FLOW_ERROR_TYPE_ITEM,
2046 : : item, "Not supported by fdir filter");
2047 : 0 : return -rte_errno;
2048 : : }
2049 : 0 : rule->b_mask = TRUE;
2050 : : sctp_mask = item->mask;
2051 [ # # ]: 0 : if (sctp_mask->hdr.tag ||
2052 [ # # ]: 0 : sctp_mask->hdr.cksum) {
2053 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2054 : 0 : rte_flow_error_set(error, EINVAL,
2055 : : RTE_FLOW_ERROR_TYPE_ITEM,
2056 : : item, "Not supported by fdir filter");
2057 : 0 : return -rte_errno;
2058 : : }
2059 : 0 : rule->mask.src_port_mask = sctp_mask->hdr.src_port;
2060 : 0 : rule->mask.dst_port_mask = sctp_mask->hdr.dst_port;
2061 : :
2062 [ # # ]: 0 : if (item->spec) {
2063 : 0 : rule->b_spec = TRUE;
2064 : : sctp_spec = item->spec;
2065 : 0 : rule->input.src_port =
2066 : 0 : sctp_spec->hdr.src_port;
2067 : 0 : rule->input.dst_port =
2068 : 0 : sctp_spec->hdr.dst_port;
2069 : : }
2070 : :
2071 : : item = next_no_fuzzy_pattern(pattern, item);
2072 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2073 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2074 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2075 : 0 : rte_flow_error_set(error, EINVAL,
2076 : : RTE_FLOW_ERROR_TYPE_ITEM,
2077 : : item, "Not supported by fdir filter");
2078 : 0 : return -rte_errno;
2079 : : }
2080 : : }
2081 : :
2082 : : /* Get the flex byte info */
2083 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_RAW) {
2084 : 0 : uint16_t pattern = 0;
2085 : :
2086 : : /* Not supported last point for range*/
2087 [ # # ]: 0 : if (item->last) {
2088 : 0 : rte_flow_error_set(error, EINVAL,
2089 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2090 : : item, "Not supported last point for range");
2091 : 0 : return -rte_errno;
2092 : : }
2093 : : /* mask should not be null */
2094 [ # # # # ]: 0 : if (!item->mask || !item->spec) {
2095 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2096 : 0 : rte_flow_error_set(error, EINVAL,
2097 : : RTE_FLOW_ERROR_TYPE_ITEM,
2098 : : item, "Not supported by fdir filter");
2099 : 0 : return -rte_errno;
2100 : : }
2101 : :
2102 : 0 : rule->b_mask = TRUE;
2103 : : raw_mask = item->mask;
2104 : :
2105 : : /* check mask */
2106 : 0 : if (raw_mask->relative != 0x1 ||
2107 : : raw_mask->search != 0x1 ||
2108 [ # # ]: 0 : raw_mask->reserved != 0x0 ||
2109 : : (uint32_t)raw_mask->offset != 0xffffffff ||
2110 [ # # ]: 0 : raw_mask->limit != 0xffff ||
2111 : : raw_mask->length != 0xffff) {
2112 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2113 : 0 : rte_flow_error_set(error, EINVAL,
2114 : : RTE_FLOW_ERROR_TYPE_ITEM,
2115 : : item, "Not supported by fdir filter");
2116 : 0 : return -rte_errno;
2117 : : }
2118 : :
2119 : 0 : rule->b_spec = TRUE;
2120 : : raw_spec = item->spec;
2121 : :
2122 : : /* check spec */
2123 [ # # ]: 0 : if (raw_spec->search != 0 ||
2124 : 0 : raw_spec->reserved != 0 ||
2125 [ # # # # ]: 0 : raw_spec->offset > TXGBE_MAX_FLX_SOURCE_OFF ||
2126 : : raw_spec->offset % 2 ||
2127 [ # # ]: 0 : raw_spec->limit != 0 ||
2128 : 0 : raw_spec->length != 4 ||
2129 : : /* pattern can't be 0xffff */
2130 [ # # ]: 0 : (raw_spec->pattern[0] == 0xff &&
2131 [ # # ]: 0 : raw_spec->pattern[1] == 0xff &&
2132 [ # # ]: 0 : raw_spec->pattern[2] == 0xff &&
2133 [ # # ]: 0 : raw_spec->pattern[3] == 0xff)) {
2134 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2135 : 0 : rte_flow_error_set(error, EINVAL,
2136 : : RTE_FLOW_ERROR_TYPE_ITEM,
2137 : : item, "Not supported by fdir filter");
2138 : 0 : return -rte_errno;
2139 : : }
2140 : :
2141 : : /* check pattern mask */
2142 [ # # ]: 0 : if (raw_mask->pattern[0] != 0xff ||
2143 [ # # ]: 0 : raw_mask->pattern[1] != 0xff ||
2144 [ # # ]: 0 : raw_mask->pattern[2] != 0xff ||
2145 [ # # ]: 0 : raw_mask->pattern[3] != 0xff) {
2146 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2147 : 0 : rte_flow_error_set(error, EINVAL,
2148 : : RTE_FLOW_ERROR_TYPE_ITEM,
2149 : : item, "Not supported by fdir filter");
2150 : 0 : return -rte_errno;
2151 : : }
2152 : :
2153 : 0 : rule->mask.flex_bytes_mask = 0xffff;
2154 : : /* Convert pattern string to hex bytes */
2155 [ # # ]: 0 : if (sscanf((const char *)raw_spec->pattern, "%hx", &pattern) != 1) {
2156 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2157 : 0 : rte_flow_error_set(error, EINVAL,
2158 : : RTE_FLOW_ERROR_TYPE_ITEM,
2159 : : item, "Failed to parse raw pattern");
2160 : 0 : return -rte_errno;
2161 : : }
2162 : 0 : rule->input.flex_bytes = (pattern & 0x00FF) << 8;
2163 : 0 : rule->input.flex_bytes |= (pattern & 0xFF00) >> 8;
2164 : :
2165 : 0 : rule->flex_bytes_offset = raw_spec->offset;
2166 : 0 : rule->flex_relative = raw_spec->relative;
2167 : : }
2168 : :
2169 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2170 : : /* check if the next not void item is END */
2171 : : item = next_no_fuzzy_pattern(pattern, item);
2172 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2173 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2174 : 0 : rte_flow_error_set(error, EINVAL,
2175 : : RTE_FLOW_ERROR_TYPE_ITEM,
2176 : : item, "Not supported by fdir filter");
2177 : 0 : return -rte_errno;
2178 : : }
2179 : : }
2180 : :
2181 : 0 : txgbe_fdir_parse_flow_type(&rule->input, 0, false);
2182 : :
2183 : 0 : return txgbe_parse_fdir_act_attr(attr, actions, rule, error);
2184 : : }
2185 : :
2186 : : /**
2187 : : * Parse the rule to see if it is a IP tunnel flow director rule.
2188 : : * And get the flow director filter info BTW.
2189 : : * PATTERN:
2190 : : * The first not void item can be ETH or IPV4 or IPV6 or UDP or tunnel type.
2191 : : * The second not void item must be IPV4 or IPV6 if the first one is ETH.
2192 : : * The next not void item could be UDP or tunnel type.
2193 : : * The next not void item could be a certain inner layer.
2194 : : * The next not void item must be END.
2195 : : * ACTION:
2196 : : * The first not void action should be QUEUE.
2197 : : * The next not void action should be END.
2198 : : * pattern example:
2199 : : * ITEM Spec Mask
2200 : : * ETH NULL NULL
2201 : : * IPV4 NULL NULL
2202 : : * UDP NULL NULL
2203 : : * VXLAN NULL NULL
2204 : : * ETH NULL NULL
2205 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
2206 : : * dst_addr 192.167.3.50 0xFFFFFFFF
2207 : : * UDP/TCP/SCTP src_port 80 0xFFFF
2208 : : * dst_port 80 0xFFFF
2209 : : * END
2210 : : */
2211 : : static int
2212 : 0 : txgbe_parse_fdir_filter_tunnel(const struct rte_flow_attr *attr,
2213 : : const struct rte_flow_item pattern[],
2214 : : const struct rte_flow_action actions[],
2215 : : struct txgbe_fdir_rule *rule,
2216 : : struct rte_flow_error *error)
2217 : : {
2218 : : const struct rte_flow_item *item;
2219 : : const struct rte_flow_item_eth *eth_mask;
2220 : : const struct rte_flow_item_ipv4 *ipv4_spec;
2221 : : const struct rte_flow_item_ipv4 *ipv4_mask;
2222 : : const struct rte_flow_item_ipv6 *ipv6_spec;
2223 : : const struct rte_flow_item_ipv6 *ipv6_mask;
2224 : : const struct rte_flow_item_tcp *tcp_spec;
2225 : : const struct rte_flow_item_tcp *tcp_mask;
2226 : : const struct rte_flow_item_udp *udp_spec;
2227 : : const struct rte_flow_item_udp *udp_mask;
2228 : : const struct rte_flow_item_sctp *sctp_spec;
2229 : : const struct rte_flow_item_sctp *sctp_mask;
2230 : : const struct rte_flow_item_raw *raw_mask;
2231 : : const struct rte_flow_item_raw *raw_spec;
2232 : : u8 ptid = 0;
2233 : : uint32_t j;
2234 : :
2235 [ # # ]: 0 : if (!pattern) {
2236 : 0 : rte_flow_error_set(error, EINVAL,
2237 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
2238 : : NULL, "NULL pattern.");
2239 : 0 : return -rte_errno;
2240 : : }
2241 : :
2242 [ # # ]: 0 : if (!actions) {
2243 : 0 : rte_flow_error_set(error, EINVAL,
2244 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
2245 : : NULL, "NULL action.");
2246 : 0 : return -rte_errno;
2247 : : }
2248 : :
2249 [ # # ]: 0 : if (!attr) {
2250 : 0 : rte_flow_error_set(error, EINVAL,
2251 : : RTE_FLOW_ERROR_TYPE_ATTR,
2252 : : NULL, "NULL attribute.");
2253 : 0 : return -rte_errno;
2254 : : }
2255 : :
2256 : : /**
2257 : : * Some fields may not be provided. Set spec to 0 and mask to default
2258 : : * value. So, we need not do anything for the not provided fields later.
2259 : : */
2260 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2261 : : memset(&rule->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
2262 : 0 : rule->mask.pkt_type_mask = TXGBE_ATR_TYPE_MASK_TUN_OUTIP |
2263 : : TXGBE_ATR_TYPE_MASK_L3P |
2264 : : TXGBE_ATR_TYPE_MASK_L4P;
2265 : :
2266 : : /**
2267 : : * The first not void item should be
2268 : : * MAC or IPv4 or IPv6 or UDP or tunnel.
2269 : : */
2270 : : item = next_no_void_pattern(pattern, NULL);
2271 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
2272 : : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2273 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2274 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2275 : : item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2276 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE &&
2277 : : item->type != RTE_FLOW_ITEM_TYPE_GRE &&
2278 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2279 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2280 : 0 : rte_flow_error_set(error, EINVAL,
2281 : : RTE_FLOW_ERROR_TYPE_ITEM,
2282 : : item, "Not supported by fdir filter");
2283 : 0 : return -rte_errno;
2284 : : }
2285 : :
2286 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT;
2287 : : ptid = TXGBE_PTID_PKT_TUN;
2288 : :
2289 : : /* Skip MAC. */
2290 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
2291 : : /* Only used to describe the protocol stack. */
2292 [ # # # # ]: 0 : if (item->spec || item->mask) {
2293 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2294 : 0 : rte_flow_error_set(error, EINVAL,
2295 : : RTE_FLOW_ERROR_TYPE_ITEM,
2296 : : item, "Not supported by fdir filter");
2297 : 0 : return -rte_errno;
2298 : : }
2299 : : /* Not supported last point for range*/
2300 [ # # ]: 0 : if (item->last) {
2301 : 0 : rte_flow_error_set(error, EINVAL,
2302 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2303 : : item, "Not supported last point for range");
2304 : 0 : return -rte_errno;
2305 : : }
2306 : :
2307 : : /* Check if the next not void item is IPv4 or IPv6. */
2308 : : item = next_no_void_pattern(pattern, item);
2309 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN)
2310 : : item = next_no_fuzzy_pattern(pattern, item);
2311 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2312 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
2313 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2314 : 0 : rte_flow_error_set(error, EINVAL,
2315 : : RTE_FLOW_ERROR_TYPE_ITEM,
2316 : : item, "Not supported by fdir filter");
2317 : 0 : return -rte_errno;
2318 : : }
2319 : : }
2320 : :
2321 : : /* Skip IP. */
2322 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
2323 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
2324 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_TUN_OUTIP;
2325 : :
2326 : : /* Only used to describe the protocol stack. */
2327 [ # # # # ]: 0 : if (item->spec || item->mask) {
2328 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2329 : 0 : rte_flow_error_set(error, EINVAL,
2330 : : RTE_FLOW_ERROR_TYPE_ITEM,
2331 : : item, "Not supported by fdir filter");
2332 : 0 : return -rte_errno;
2333 : : }
2334 : : /*Not supported last point for range*/
2335 [ # # ]: 0 : if (item->last) {
2336 : 0 : rte_flow_error_set(error, EINVAL,
2337 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2338 : : item, "Not supported last point for range");
2339 : 0 : return -rte_errno;
2340 : : }
2341 : :
2342 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6)
2343 : : ptid |= TXGBE_PTID_TUN_IPV6;
2344 : :
2345 : : item = next_no_void_pattern(pattern, item);
2346 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2347 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2348 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2349 : : item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2350 : : item->type != RTE_FLOW_ITEM_TYPE_GRE &&
2351 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE &&
2352 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2353 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2354 : 0 : rte_flow_error_set(error, EINVAL,
2355 : : RTE_FLOW_ERROR_TYPE_ITEM,
2356 : : item, "Not supported by fdir filter");
2357 : 0 : return -rte_errno;
2358 : : }
2359 : : }
2360 : :
2361 : : /* Skip UDP. */
2362 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2363 : : /*Not supported last point for range*/
2364 [ # # ]: 0 : if (item->last) {
2365 : 0 : rte_flow_error_set(error, EINVAL,
2366 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2367 : : item, "Not supported last point for range");
2368 : 0 : return -rte_errno;
2369 : : }
2370 : :
2371 : : /* Check if the next not void item is VxLAN or GENEVE. */
2372 : : item = next_no_void_pattern(pattern, item);
2373 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2374 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2375 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2376 : 0 : rte_flow_error_set(error, EINVAL,
2377 : : RTE_FLOW_ERROR_TYPE_ITEM,
2378 : : item, "Not supported by fdir filter");
2379 : 0 : return -rte_errno;
2380 : : }
2381 : : }
2382 : :
2383 : : /* Skip tunnel. */
2384 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN ||
2385 [ # # ]: 0 : item->type == RTE_FLOW_ITEM_TYPE_GRE ||
2386 [ # # ]: 0 : item->type == RTE_FLOW_ITEM_TYPE_NVGRE ||
2387 : : item->type == RTE_FLOW_ITEM_TYPE_GENEVE) {
2388 : : /* Only used to describe the protocol stack. */
2389 [ # # # # ]: 0 : if (item->spec || item->mask) {
2390 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2391 : 0 : rte_flow_error_set(error, EINVAL,
2392 : : RTE_FLOW_ERROR_TYPE_ITEM,
2393 : : item, "Not supported by fdir filter");
2394 : 0 : return -rte_errno;
2395 : : }
2396 : : /*Not supported last point for range*/
2397 [ # # ]: 0 : if (item->last) {
2398 : 0 : rte_flow_error_set(error, EINVAL,
2399 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2400 : : item, "Not supported last point for range");
2401 : 0 : return -rte_errno;
2402 : : }
2403 : :
2404 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_GRE)
2405 : 0 : ptid |= TXGBE_PTID_TUN_EIG;
2406 : : else
2407 : 0 : ptid |= TXGBE_PTID_TUN_EIGM;
2408 : :
2409 : : item = next_no_void_pattern(pattern, item);
2410 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
2411 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2412 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
2413 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2414 : 0 : rte_flow_error_set(error, EINVAL,
2415 : : RTE_FLOW_ERROR_TYPE_ITEM,
2416 : : item, "Not supported by fdir filter");
2417 : 0 : return -rte_errno;
2418 : : }
2419 : : }
2420 : :
2421 : : /* Get the MAC info. */
2422 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
2423 : : /**
2424 : : * Only support vlan and dst MAC address,
2425 : : * others should be masked.
2426 : : */
2427 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2428 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2429 : 0 : rte_flow_error_set(error, EINVAL,
2430 : : RTE_FLOW_ERROR_TYPE_ITEM,
2431 : : item, "Not supported by fdir filter");
2432 : 0 : return -rte_errno;
2433 : : }
2434 : :
2435 [ # # ]: 0 : if (item->mask) {
2436 : 0 : rule->b_mask = TRUE;
2437 : : eth_mask = item->mask;
2438 : :
2439 : : /* Ether type should be masked. */
2440 [ # # ]: 0 : if (eth_mask->hdr.ether_type) {
2441 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2442 : 0 : rte_flow_error_set(error, EINVAL,
2443 : : RTE_FLOW_ERROR_TYPE_ITEM,
2444 : : item, "Not supported by fdir filter");
2445 : 0 : return -rte_errno;
2446 : : }
2447 : :
2448 : : /**
2449 : : * src MAC address must be masked,
2450 : : * and don't support dst MAC address mask.
2451 : : */
2452 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
2453 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j] ||
2454 [ # # ]: 0 : eth_mask->hdr.dst_addr.addr_bytes[j] != 0xFF) {
2455 : : memset(rule, 0,
2456 : : sizeof(struct txgbe_fdir_rule));
2457 : 0 : rte_flow_error_set(error, EINVAL,
2458 : : RTE_FLOW_ERROR_TYPE_ITEM,
2459 : : item, "Not supported by fdir filter");
2460 : 0 : return -rte_errno;
2461 : : }
2462 : : }
2463 : :
2464 : : /* When no VLAN, considered as full mask. */
2465 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
2466 : : }
2467 : :
2468 : : item = next_no_fuzzy_pattern(pattern, item);
2469 [ # # ]: 0 : if (rule->mask.vlan_tci_mask) {
2470 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
2471 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2472 : 0 : rte_flow_error_set(error, EINVAL,
2473 : : RTE_FLOW_ERROR_TYPE_ITEM,
2474 : : item, "Not supported by fdir filter");
2475 : 0 : return -rte_errno;
2476 : : }
2477 : : } else {
2478 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2479 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2480 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
2481 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2482 : 0 : rte_flow_error_set(error, EINVAL,
2483 : : RTE_FLOW_ERROR_TYPE_ITEM,
2484 : : item, "Not supported by fdir filter");
2485 : 0 : return -rte_errno;
2486 : : }
2487 : : }
2488 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2489 : 0 : ptid |= TXGBE_PTID_TUN_EIGMV;
2490 : : item = next_no_fuzzy_pattern(pattern, item);
2491 : : }
2492 : : }
2493 : :
2494 : : /* Get the IPV4 info. */
2495 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
2496 : : /**
2497 : : * Set the flow type even if there's no content
2498 : : * as we must have a flow type.
2499 : : */
2500 : : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV4;
2501 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
2502 : :
2503 : : /*Not supported last point for range*/
2504 [ # # ]: 0 : if (item->last) {
2505 : 0 : rte_flow_error_set(error, EINVAL,
2506 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2507 : : item, "Not supported last point for range");
2508 : 0 : return -rte_errno;
2509 : : }
2510 : : /**
2511 : : * Only care about src & dst addresses,
2512 : : * others should be masked.
2513 : : */
2514 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2515 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2516 : 0 : rte_flow_error_set(error, EINVAL,
2517 : : RTE_FLOW_ERROR_TYPE_ITEM,
2518 : : item, "Not supported by fdir filter");
2519 : 0 : return -rte_errno;
2520 : : }
2521 [ # # ]: 0 : if (item->mask) {
2522 : 0 : rule->b_mask = TRUE;
2523 : : ipv4_mask = item->mask;
2524 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
2525 : 0 : ipv4_mask->hdr.type_of_service ||
2526 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
2527 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
2528 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
2529 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
2530 : 0 : ipv4_mask->hdr.next_proto_id ||
2531 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
2532 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2533 : 0 : rte_flow_error_set(error, EINVAL,
2534 : : RTE_FLOW_ERROR_TYPE_ITEM,
2535 : : item, "Not supported by fdir filter");
2536 : 0 : return -rte_errno;
2537 : : }
2538 : 0 : rule->mask.dst_ipv4_mask = ipv4_mask->hdr.dst_addr;
2539 : 0 : rule->mask.src_ipv4_mask = ipv4_mask->hdr.src_addr;
2540 : : }
2541 [ # # ]: 0 : if (item->spec) {
2542 : 0 : rule->b_spec = TRUE;
2543 : : ipv4_spec = item->spec;
2544 : 0 : rule->input.dst_ip[0] =
2545 : 0 : ipv4_spec->hdr.dst_addr;
2546 : 0 : rule->input.src_ip[0] =
2547 : 0 : ipv4_spec->hdr.src_addr;
2548 : : }
2549 : :
2550 : : /**
2551 : : * Check if the next not void item is
2552 : : * TCP or UDP or SCTP or END.
2553 : : */
2554 : : item = next_no_fuzzy_pattern(pattern, item);
2555 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
2556 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2557 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
2558 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
2559 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
2560 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2561 : 0 : rte_flow_error_set(error, EINVAL,
2562 : : RTE_FLOW_ERROR_TYPE_ITEM,
2563 : : item, "Not supported by fdir filter");
2564 : 0 : return -rte_errno;
2565 : : }
2566 : : }
2567 : :
2568 : : /* Get the IPV6 info. */
2569 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
2570 : : /**
2571 : : * Set the flow type even if there's no content
2572 : : * as we must have a flow type.
2573 : : */
2574 : 0 : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV6;
2575 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
2576 : :
2577 [ # # ]: 0 : if (item->last) {
2578 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2579 : 0 : rte_flow_error_set(error, EINVAL,
2580 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2581 : : item, "Not supported last point for range");
2582 : 0 : return -rte_errno;
2583 : : }
2584 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2585 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2586 : 0 : rte_flow_error_set(error, EINVAL,
2587 : : RTE_FLOW_ERROR_TYPE_ITEM,
2588 : : item, "Not supported by fdir filter");
2589 : 0 : return -rte_errno;
2590 : : }
2591 [ # # ]: 0 : if (item->mask) {
2592 : 0 : rule->b_mask = TRUE;
2593 : : ipv6_mask = item->mask;
2594 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow ||
2595 : : ipv6_mask->hdr.payload_len ||
2596 [ # # ]: 0 : ipv6_mask->hdr.proto ||
2597 : : ipv6_mask->hdr.hop_limits) {
2598 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2599 : 0 : rte_flow_error_set(error, EINVAL,
2600 : : RTE_FLOW_ERROR_TYPE_ITEM,
2601 : : item, "Not supported by fdir filter");
2602 : 0 : return -rte_errno;
2603 : : }
2604 : :
2605 : : /* check src addr mask */
2606 [ # # ]: 0 : for (j = 0; j < 16; j++) {
2607 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j] == UINT8_MAX) {
2608 : 0 : rule->mask.src_ipv6_mask |= 1 << j;
2609 [ # # ]: 0 : } else if (ipv6_mask->hdr.src_addr.a[j] != 0) {
2610 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2611 : 0 : rte_flow_error_set(error, EINVAL,
2612 : : RTE_FLOW_ERROR_TYPE_ITEM,
2613 : : item, "Not supported by fdir filter");
2614 : 0 : return -rte_errno;
2615 : : }
2616 : : }
2617 : :
2618 : : /* check dst addr mask */
2619 [ # # ]: 0 : for (j = 0; j < 16; j++) {
2620 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j] != 0) {
2621 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2622 : 0 : rte_flow_error_set(error, EINVAL,
2623 : : RTE_FLOW_ERROR_TYPE_ITEM,
2624 : : item, "Not supported by fdir filter");
2625 : 0 : return -rte_errno;
2626 : : }
2627 : : }
2628 : : }
2629 [ # # ]: 0 : if (item->spec) {
2630 : 0 : rule->b_spec = TRUE;
2631 : : ipv6_spec = item->spec;
2632 : : rte_memcpy(rule->input.src_ip,
2633 : : &ipv6_spec->hdr.src_addr, 16);
2634 : : rte_memcpy(rule->input.dst_ip,
2635 : : &ipv6_spec->hdr.dst_addr, 16);
2636 : : }
2637 : :
2638 : : /**
2639 : : * Check if the next not void item is
2640 : : * TCP or UDP or SCTP or END.
2641 : : */
2642 : : item = next_no_fuzzy_pattern(pattern, item);
2643 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
2644 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2645 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
2646 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
2647 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
2648 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2649 : 0 : rte_flow_error_set(error, EINVAL,
2650 : : RTE_FLOW_ERROR_TYPE_ITEM,
2651 : : item, "Not supported by fdir filter");
2652 : 0 : return -rte_errno;
2653 : : }
2654 : : }
2655 : :
2656 : : /* Get the TCP info. */
2657 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
2658 : : /**
2659 : : * Set the flow type even if there's no content
2660 : : * as we must have a flow type.
2661 : : */
2662 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_TCP;
2663 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2664 : :
2665 : : /*Not supported last point for range*/
2666 [ # # ]: 0 : if (item->last) {
2667 : 0 : rte_flow_error_set(error, EINVAL,
2668 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2669 : : item, "Not supported last point for range");
2670 : 0 : return -rte_errno;
2671 : : }
2672 : : /**
2673 : : * Only care about src & dst ports,
2674 : : * others should be masked.
2675 : : */
2676 [ # # ]: 0 : if (!item->mask) {
2677 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2678 : 0 : rte_flow_error_set(error, EINVAL,
2679 : : RTE_FLOW_ERROR_TYPE_ITEM,
2680 : : item, "Not supported by fdir filter");
2681 : 0 : return -rte_errno;
2682 : : }
2683 : 0 : rule->b_mask = TRUE;
2684 : : tcp_mask = item->mask;
2685 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
2686 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
2687 [ # # ]: 0 : tcp_mask->hdr.data_off ||
2688 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
2689 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
2690 [ # # ]: 0 : tcp_mask->hdr.cksum ||
2691 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
2692 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2693 : 0 : rte_flow_error_set(error, EINVAL,
2694 : : RTE_FLOW_ERROR_TYPE_ITEM,
2695 : : item, "Not supported by fdir filter");
2696 : 0 : return -rte_errno;
2697 : : }
2698 : 0 : rule->mask.src_port_mask = tcp_mask->hdr.src_port;
2699 : 0 : rule->mask.dst_port_mask = tcp_mask->hdr.dst_port;
2700 : :
2701 [ # # ]: 0 : if (item->spec) {
2702 : 0 : rule->b_spec = TRUE;
2703 : : tcp_spec = item->spec;
2704 : 0 : rule->input.src_port =
2705 : 0 : tcp_spec->hdr.src_port;
2706 : 0 : rule->input.dst_port =
2707 : 0 : tcp_spec->hdr.dst_port;
2708 : : }
2709 : :
2710 : : item = next_no_fuzzy_pattern(pattern, item);
2711 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2712 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2713 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2714 : 0 : rte_flow_error_set(error, EINVAL,
2715 : : RTE_FLOW_ERROR_TYPE_ITEM,
2716 : : item, "Not supported by fdir filter");
2717 : 0 : return -rte_errno;
2718 : : }
2719 : : }
2720 : :
2721 : : /* Get the UDP info */
2722 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2723 : : /**
2724 : : * Set the flow type even if there's no content
2725 : : * as we must have a flow type.
2726 : : */
2727 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_UDP;
2728 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2729 : : /*Not supported last point for range*/
2730 [ # # ]: 0 : if (item->last) {
2731 : 0 : rte_flow_error_set(error, EINVAL,
2732 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2733 : : item, "Not supported last point for range");
2734 : 0 : return -rte_errno;
2735 : : }
2736 : : /**
2737 : : * Only care about src & dst ports,
2738 : : * others should be masked.
2739 : : */
2740 [ # # ]: 0 : if (!item->mask) {
2741 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2742 : 0 : rte_flow_error_set(error, EINVAL,
2743 : : RTE_FLOW_ERROR_TYPE_ITEM,
2744 : : item, "Not supported by fdir filter");
2745 : 0 : return -rte_errno;
2746 : : }
2747 : 0 : rule->b_mask = TRUE;
2748 : : udp_mask = item->mask;
2749 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
2750 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
2751 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2752 : 0 : rte_flow_error_set(error, EINVAL,
2753 : : RTE_FLOW_ERROR_TYPE_ITEM,
2754 : : item, "Not supported by fdir filter");
2755 : 0 : return -rte_errno;
2756 : : }
2757 : 0 : rule->mask.src_port_mask = udp_mask->hdr.src_port;
2758 : 0 : rule->mask.dst_port_mask = udp_mask->hdr.dst_port;
2759 : :
2760 [ # # ]: 0 : if (item->spec) {
2761 : 0 : rule->b_spec = TRUE;
2762 : : udp_spec = item->spec;
2763 : 0 : rule->input.src_port =
2764 : 0 : udp_spec->hdr.src_port;
2765 : 0 : rule->input.dst_port =
2766 : 0 : udp_spec->hdr.dst_port;
2767 : : }
2768 : :
2769 : : item = next_no_fuzzy_pattern(pattern, item);
2770 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2771 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2772 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2773 : 0 : rte_flow_error_set(error, EINVAL,
2774 : : RTE_FLOW_ERROR_TYPE_ITEM,
2775 : : item, "Not supported by fdir filter");
2776 : 0 : return -rte_errno;
2777 : : }
2778 : : }
2779 : :
2780 : : /* Get the SCTP info */
2781 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
2782 : : /**
2783 : : * Set the flow type even if there's no content
2784 : : * as we must have a flow type.
2785 : : */
2786 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_SCTP;
2787 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2788 : :
2789 : : /*Not supported last point for range*/
2790 [ # # ]: 0 : if (item->last) {
2791 : 0 : rte_flow_error_set(error, EINVAL,
2792 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2793 : : item, "Not supported last point for range");
2794 : 0 : return -rte_errno;
2795 : : }
2796 : :
2797 : : /**
2798 : : * Only care about src & dst ports,
2799 : : * others should be masked.
2800 : : */
2801 [ # # ]: 0 : if (!item->mask) {
2802 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2803 : 0 : rte_flow_error_set(error, EINVAL,
2804 : : RTE_FLOW_ERROR_TYPE_ITEM,
2805 : : item, "Not supported by fdir filter");
2806 : 0 : return -rte_errno;
2807 : : }
2808 : 0 : rule->b_mask = TRUE;
2809 : : sctp_mask = item->mask;
2810 [ # # # # ]: 0 : if (sctp_mask->hdr.tag || sctp_mask->hdr.cksum) {
2811 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2812 : 0 : rte_flow_error_set(error, EINVAL,
2813 : : RTE_FLOW_ERROR_TYPE_ITEM,
2814 : : item, "Not supported by fdir filter");
2815 : 0 : return -rte_errno;
2816 : : }
2817 : 0 : rule->mask.src_port_mask = sctp_mask->hdr.src_port;
2818 : 0 : rule->mask.dst_port_mask = sctp_mask->hdr.dst_port;
2819 : :
2820 [ # # ]: 0 : if (item->spec) {
2821 : 0 : rule->b_spec = TRUE;
2822 : : sctp_spec = item->spec;
2823 : 0 : rule->input.src_port =
2824 : 0 : sctp_spec->hdr.src_port;
2825 : 0 : rule->input.dst_port =
2826 : 0 : sctp_spec->hdr.dst_port;
2827 : : }
2828 : :
2829 : : item = next_no_fuzzy_pattern(pattern, item);
2830 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2831 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2832 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2833 : 0 : rte_flow_error_set(error, EINVAL,
2834 : : RTE_FLOW_ERROR_TYPE_ITEM,
2835 : : item, "Not supported by fdir filter");
2836 : 0 : return -rte_errno;
2837 : : }
2838 : : }
2839 : :
2840 : : /* Get the flex byte info */
2841 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_RAW) {
2842 : 0 : uint16_t pattern = 0;
2843 : :
2844 : : /* Not supported last point for range*/
2845 [ # # ]: 0 : if (item->last) {
2846 : 0 : rte_flow_error_set(error, EINVAL,
2847 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2848 : : item, "Not supported last point for range");
2849 : 0 : return -rte_errno;
2850 : : }
2851 : : /* mask should not be null */
2852 [ # # # # ]: 0 : if (!item->mask || !item->spec) {
2853 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2854 : 0 : rte_flow_error_set(error, EINVAL,
2855 : : RTE_FLOW_ERROR_TYPE_ITEM,
2856 : : item, "Not supported by fdir filter");
2857 : 0 : return -rte_errno;
2858 : : }
2859 : :
2860 : 0 : rule->b_mask = TRUE;
2861 : : raw_mask = item->mask;
2862 : :
2863 : : /* check mask */
2864 : 0 : if (raw_mask->relative != 0x1 ||
2865 : : raw_mask->search != 0x1 ||
2866 [ # # ]: 0 : raw_mask->reserved != 0x0 ||
2867 : : (uint32_t)raw_mask->offset != 0xffffffff ||
2868 [ # # ]: 0 : raw_mask->limit != 0xffff ||
2869 : : raw_mask->length != 0xffff) {
2870 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2871 : 0 : rte_flow_error_set(error, EINVAL,
2872 : : RTE_FLOW_ERROR_TYPE_ITEM,
2873 : : item, "Not supported by fdir filter");
2874 : 0 : return -rte_errno;
2875 : : }
2876 : :
2877 : 0 : rule->b_spec = TRUE;
2878 : : raw_spec = item->spec;
2879 : :
2880 : : /* check spec */
2881 [ # # ]: 0 : if (raw_spec->search != 0 ||
2882 : 0 : raw_spec->reserved != 0 ||
2883 [ # # # # ]: 0 : raw_spec->offset > TXGBE_MAX_FLX_SOURCE_OFF ||
2884 : : raw_spec->offset % 2 ||
2885 [ # # ]: 0 : raw_spec->limit != 0 ||
2886 : 0 : raw_spec->length != 4 ||
2887 : : /* pattern can't be 0xffff */
2888 [ # # ]: 0 : (raw_spec->pattern[0] == 0xff &&
2889 [ # # ]: 0 : raw_spec->pattern[1] == 0xff &&
2890 [ # # ]: 0 : raw_spec->pattern[2] == 0xff &&
2891 [ # # ]: 0 : raw_spec->pattern[3] == 0xff)) {
2892 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2893 : 0 : rte_flow_error_set(error, EINVAL,
2894 : : RTE_FLOW_ERROR_TYPE_ITEM,
2895 : : item, "Not supported by fdir filter");
2896 : 0 : return -rte_errno;
2897 : : }
2898 : :
2899 : : /* check pattern mask */
2900 [ # # ]: 0 : if (raw_mask->pattern[0] != 0xff ||
2901 [ # # ]: 0 : raw_mask->pattern[1] != 0xff ||
2902 [ # # ]: 0 : raw_mask->pattern[2] != 0xff ||
2903 [ # # ]: 0 : raw_mask->pattern[3] != 0xff) {
2904 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2905 : 0 : rte_flow_error_set(error, EINVAL,
2906 : : RTE_FLOW_ERROR_TYPE_ITEM,
2907 : : item, "Not supported by fdir filter");
2908 : 0 : return -rte_errno;
2909 : : }
2910 : :
2911 : 0 : rule->mask.flex_bytes_mask = 0xffff;
2912 : : /* Convert pattern string to hex bytes */
2913 [ # # ]: 0 : if (sscanf((const char *)raw_spec->pattern, "%hx", &pattern) != 1) {
2914 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2915 : 0 : rte_flow_error_set(error, EINVAL,
2916 : : RTE_FLOW_ERROR_TYPE_ITEM,
2917 : : item, "Failed to parse raw pattern");
2918 : 0 : return -rte_errno;
2919 : : }
2920 : 0 : rule->input.flex_bytes = (pattern & 0x00FF) << 8;
2921 : 0 : rule->input.flex_bytes |= (pattern & 0xFF00) >> 8;
2922 : :
2923 : 0 : rule->flex_bytes_offset = raw_spec->offset;
2924 : 0 : rule->flex_relative = raw_spec->relative;
2925 : : }
2926 : :
2927 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2928 : : /* check if the next not void item is END */
2929 : : item = next_no_fuzzy_pattern(pattern, item);
2930 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2931 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2932 : 0 : rte_flow_error_set(error, EINVAL,
2933 : : RTE_FLOW_ERROR_TYPE_ITEM,
2934 : : item, "Not supported by fdir filter");
2935 : 0 : return -rte_errno;
2936 : : }
2937 : : }
2938 : :
2939 : 0 : txgbe_fdir_parse_flow_type(&rule->input, ptid, true);
2940 : :
2941 : 0 : return txgbe_parse_fdir_act_attr(attr, actions, rule, error);
2942 : : }
2943 : :
2944 : : static int
2945 : 0 : txgbe_parse_fdir_filter(struct rte_eth_dev *dev,
2946 : : const struct rte_flow_attr *attr,
2947 : : const struct rte_flow_item pattern[],
2948 : : const struct rte_flow_action actions[],
2949 : : struct txgbe_fdir_rule *rule,
2950 : : struct rte_flow_error *error)
2951 : : {
2952 : : int ret;
2953 : 0 : struct rte_eth_fdir_conf *fdir_conf = TXGBE_DEV_FDIR_CONF(dev);
2954 : :
2955 : 0 : ret = txgbe_parse_fdir_filter_normal(dev, attr, pattern,
2956 : : actions, rule, error);
2957 [ # # ]: 0 : if (!ret)
2958 : 0 : goto step_next;
2959 : :
2960 : 0 : ret = txgbe_parse_fdir_filter_tunnel(attr, pattern,
2961 : : actions, rule, error);
2962 [ # # ]: 0 : if (ret)
2963 : : return ret;
2964 : :
2965 : 0 : step_next:
2966 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev)))
2967 : : return ret;
2968 : :
2969 [ # # ]: 0 : if (fdir_conf->mode == RTE_FDIR_MODE_NONE) {
2970 : 0 : fdir_conf->mode = rule->mode;
2971 : 0 : ret = txgbe_fdir_configure(dev);
2972 [ # # ]: 0 : if (ret) {
2973 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
2974 : 0 : return ret;
2975 : : }
2976 [ # # ]: 0 : } else if (fdir_conf->mode != rule->mode) {
2977 : : return -ENOTSUP;
2978 : : }
2979 : :
2980 [ # # ]: 0 : if (rule->queue >= dev->data->nb_rx_queues)
2981 : 0 : return -ENOTSUP;
2982 : :
2983 : : return ret;
2984 : : }
2985 : :
2986 : : static int
2987 : 0 : txgbe_parse_rss_filter(struct rte_eth_dev *dev,
2988 : : const struct rte_flow_attr *attr,
2989 : : const struct rte_flow_action actions[],
2990 : : struct txgbe_rte_flow_rss_conf *rss_conf,
2991 : : struct rte_flow_error *error)
2992 : : {
2993 : : const struct rte_flow_action *act;
2994 : : const struct rte_flow_action_rss *rss;
2995 : : uint16_t n;
2996 : :
2997 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
2998 : 0 : rte_flow_error_set(error, EINVAL,
2999 : : RTE_FLOW_ERROR_TYPE_ITEM,
3000 : : NULL, "Flow type not suppotted yet on VF");
3001 : 0 : return -rte_errno;
3002 : : }
3003 : :
3004 : : /**
3005 : : * rss only supports forwarding,
3006 : : * check if the first not void action is RSS.
3007 : : */
3008 : : act = next_no_void_action(actions, NULL);
3009 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
3010 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3011 : 0 : rte_flow_error_set(error, EINVAL,
3012 : : RTE_FLOW_ERROR_TYPE_ACTION,
3013 : : act, "Not supported action.");
3014 : 0 : return -rte_errno;
3015 : : }
3016 : :
3017 : 0 : rss = (const struct rte_flow_action_rss *)act->conf;
3018 : :
3019 [ # # # # ]: 0 : if (!rss || !rss->queue_num) {
3020 : 0 : rte_flow_error_set(error, EINVAL,
3021 : : RTE_FLOW_ERROR_TYPE_ACTION,
3022 : : act,
3023 : : "no valid queues");
3024 : 0 : return -rte_errno;
3025 : : }
3026 : :
3027 [ # # ]: 0 : for (n = 0; n < rss->queue_num; n++) {
3028 [ # # ]: 0 : if (rss->queue[n] >= dev->data->nb_rx_queues) {
3029 : 0 : rte_flow_error_set(error, EINVAL,
3030 : : RTE_FLOW_ERROR_TYPE_ACTION,
3031 : : act,
3032 : : "queue id > max number of queues");
3033 : 0 : return -rte_errno;
3034 : : }
3035 : : }
3036 : :
3037 [ # # ]: 0 : if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
3038 : 0 : return rte_flow_error_set
3039 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
3040 : : "non-default RSS hash functions are not supported");
3041 [ # # ]: 0 : if (rss->level)
3042 : 0 : return rte_flow_error_set
3043 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
3044 : : "a nonzero RSS encapsulation level is not supported");
3045 [ # # ]: 0 : if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
3046 : 0 : return rte_flow_error_set
3047 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
3048 : : "RSS hash key must be exactly 40 bytes");
3049 [ # # ]: 0 : if (rss->queue_num > RTE_DIM(rss_conf->queue))
3050 : 0 : return rte_flow_error_set
3051 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
3052 : : "too many queues for RSS context");
3053 [ # # ]: 0 : if (txgbe_rss_conf_init(rss_conf, rss))
3054 : 0 : return rte_flow_error_set
3055 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, act,
3056 : : "RSS context initialization failure");
3057 : :
3058 : : /* check if the next not void item is END */
3059 : : act = next_no_void_action(actions, act);
3060 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
3061 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3062 : 0 : rte_flow_error_set(error, EINVAL,
3063 : : RTE_FLOW_ERROR_TYPE_ACTION,
3064 : : act, "Not supported action.");
3065 : 0 : return -rte_errno;
3066 : : }
3067 : :
3068 : : /* parse attr */
3069 : : /* must be input direction */
3070 [ # # ]: 0 : if (!attr->ingress) {
3071 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3072 : 0 : rte_flow_error_set(error, EINVAL,
3073 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
3074 : : attr, "Only support ingress.");
3075 : 0 : return -rte_errno;
3076 : : }
3077 : :
3078 : : /* not supported */
3079 [ # # ]: 0 : if (attr->egress) {
3080 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3081 : 0 : rte_flow_error_set(error, EINVAL,
3082 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
3083 : : attr, "Not support egress.");
3084 : 0 : return -rte_errno;
3085 : : }
3086 : :
3087 : : /* not supported */
3088 [ # # ]: 0 : if (attr->transfer) {
3089 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3090 : 0 : rte_flow_error_set(error, EINVAL,
3091 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
3092 : : attr, "No support for transfer.");
3093 : 0 : return -rte_errno;
3094 : : }
3095 : :
3096 [ # # ]: 0 : if (attr->priority > 0xFFFF) {
3097 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3098 : 0 : rte_flow_error_set(error, EINVAL,
3099 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
3100 : : attr, "Error priority.");
3101 : 0 : return -rte_errno;
3102 : : }
3103 : :
3104 : : return 0;
3105 : : }
3106 : :
3107 : : /* remove the rss filter */
3108 : : static void
3109 : : txgbe_clear_rss_filter(struct rte_eth_dev *dev)
3110 : : {
3111 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
3112 : :
3113 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
3114 : 0 : txgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
3115 : : }
3116 : :
3117 : : void
3118 : 0 : txgbe_filterlist_init(void)
3119 : : {
3120 : 0 : TAILQ_INIT(&filter_ntuple_list);
3121 : 0 : TAILQ_INIT(&filter_ethertype_list);
3122 : 0 : TAILQ_INIT(&filter_syn_list);
3123 : 0 : TAILQ_INIT(&filter_fdir_list);
3124 : 0 : TAILQ_INIT(&filter_l2_tunnel_list);
3125 : 0 : TAILQ_INIT(&filter_rss_list);
3126 : 0 : TAILQ_INIT(&txgbe_flow_list);
3127 : 0 : }
3128 : :
3129 : : void
3130 : 0 : txgbe_filterlist_flush(void)
3131 : : {
3132 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3133 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3134 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3135 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3136 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3137 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3138 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3139 : :
3140 [ # # ]: 0 : while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
3141 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
3142 : : ntuple_filter_ptr,
3143 : : entries);
3144 : 0 : rte_free(ntuple_filter_ptr);
3145 : : }
3146 : :
3147 [ # # ]: 0 : while ((ethertype_filter_ptr = TAILQ_FIRST(&filter_ethertype_list))) {
3148 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
3149 : : ethertype_filter_ptr,
3150 : : entries);
3151 : 0 : rte_free(ethertype_filter_ptr);
3152 : : }
3153 : :
3154 [ # # ]: 0 : while ((syn_filter_ptr = TAILQ_FIRST(&filter_syn_list))) {
3155 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
3156 : : syn_filter_ptr,
3157 : : entries);
3158 : 0 : rte_free(syn_filter_ptr);
3159 : : }
3160 : :
3161 [ # # ]: 0 : while ((l2_tn_filter_ptr = TAILQ_FIRST(&filter_l2_tunnel_list))) {
3162 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
3163 : : l2_tn_filter_ptr,
3164 : : entries);
3165 : 0 : rte_free(l2_tn_filter_ptr);
3166 : : }
3167 : :
3168 [ # # ]: 0 : while ((fdir_rule_ptr = TAILQ_FIRST(&filter_fdir_list))) {
3169 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
3170 : : fdir_rule_ptr,
3171 : : entries);
3172 : 0 : rte_free(fdir_rule_ptr);
3173 : : }
3174 : :
3175 [ # # ]: 0 : while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
3176 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
3177 : : rss_filter_ptr,
3178 : : entries);
3179 : 0 : rte_free(rss_filter_ptr);
3180 : : }
3181 : :
3182 [ # # ]: 0 : while ((txgbe_flow_mem_ptr = TAILQ_FIRST(&txgbe_flow_list))) {
3183 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3184 : : txgbe_flow_mem_ptr,
3185 : : entries);
3186 : 0 : rte_free(txgbe_flow_mem_ptr->flow);
3187 : 0 : rte_free(txgbe_flow_mem_ptr);
3188 : : }
3189 : 0 : }
3190 : :
3191 : : /**
3192 : : * Create or destroy a flow rule.
3193 : : * Theorically one rule can match more than one filters.
3194 : : * We will let it use the filter which it hit first.
3195 : : * So, the sequence matters.
3196 : : */
3197 : : static struct rte_flow *
3198 : 0 : txgbe_flow_create(struct rte_eth_dev *dev,
3199 : : const struct rte_flow_attr *attr,
3200 : : const struct rte_flow_item pattern[],
3201 : : const struct rte_flow_action actions[],
3202 : : struct rte_flow_error *error)
3203 : : {
3204 : : int ret;
3205 : : struct rte_eth_ntuple_filter ntuple_filter;
3206 : : struct rte_eth_ethertype_filter ethertype_filter;
3207 : : struct rte_eth_syn_filter syn_filter;
3208 : : struct txgbe_fdir_rule fdir_rule;
3209 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3210 : 0 : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
3211 : : struct txgbe_rte_flow_rss_conf rss_conf;
3212 : : struct rte_flow *flow = NULL;
3213 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3214 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3215 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3216 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3217 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3218 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3219 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3220 : : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
3221 : : uint8_t first_mask = FALSE;
3222 : :
3223 : 0 : flow = rte_zmalloc("txgbe_rte_flow", sizeof(struct rte_flow), 0);
3224 [ # # ]: 0 : if (!flow) {
3225 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3226 : 0 : return (struct rte_flow *)flow;
3227 : : }
3228 : 0 : txgbe_flow_mem_ptr = rte_zmalloc("txgbe_flow_mem",
3229 : : sizeof(struct txgbe_flow_mem), 0);
3230 [ # # ]: 0 : if (!txgbe_flow_mem_ptr) {
3231 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3232 : 0 : rte_free(flow);
3233 : 0 : return NULL;
3234 : : }
3235 : 0 : txgbe_flow_mem_ptr->flow = flow;
3236 : 0 : TAILQ_INSERT_TAIL(&txgbe_flow_list,
3237 : : txgbe_flow_mem_ptr, entries);
3238 : :
3239 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3240 : 0 : ret = txgbe_parse_ntuple_filter(dev, attr, pattern,
3241 : : actions, &ntuple_filter, error);
3242 : :
3243 : : #ifdef RTE_LIB_SECURITY
3244 : : /* ESP flow not really a flow*/
3245 [ # # ]: 0 : if (ntuple_filter.proto == IPPROTO_ESP)
3246 : : return flow;
3247 : : #endif
3248 : :
3249 [ # # ]: 0 : if (!ret) {
3250 : 0 : ntuple_filter_ptr = rte_zmalloc("txgbe_ntuple_filter",
3251 : : sizeof(struct txgbe_ntuple_filter_ele), 0);
3252 [ # # ]: 0 : if (!ntuple_filter_ptr) {
3253 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3254 : : ret = -ENOMEM;
3255 : 0 : goto out;
3256 : : }
3257 : 0 : ntuple_filter_ptr->filter_info = ntuple_filter;
3258 : 0 : ret = txgbe_add_del_ntuple_filter(dev, &ntuple_filter, TRUE);
3259 [ # # ]: 0 : if (ret) {
3260 : 0 : rte_free(ntuple_filter_ptr);
3261 [ # # ]: 0 : if (filter_info->ntuple_is_full)
3262 : 0 : goto next;
3263 : 0 : goto out;
3264 : : }
3265 : 0 : TAILQ_INSERT_TAIL(&filter_ntuple_list,
3266 : : ntuple_filter_ptr, entries);
3267 : 0 : flow->rule = ntuple_filter_ptr;
3268 : 0 : flow->filter_type = RTE_ETH_FILTER_NTUPLE;
3269 : 0 : return flow;
3270 : : }
3271 : :
3272 : 0 : next:
3273 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3274 : 0 : ret = txgbe_parse_ethertype_filter(dev, attr, pattern,
3275 : : actions, ðertype_filter, error);
3276 [ # # ]: 0 : if (!ret) {
3277 : 0 : ethertype_filter_ptr = rte_zmalloc("txgbe_ethertype_filter",
3278 : : sizeof(struct txgbe_ethertype_filter_ele), 0);
3279 [ # # ]: 0 : if (!ethertype_filter_ptr) {
3280 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3281 : : ret = -ENOMEM;
3282 : 0 : goto out;
3283 : : }
3284 : 0 : ethertype_filter_ptr->filter_info = ethertype_filter;
3285 : 0 : ret = txgbe_add_del_ethertype_filter(dev,
3286 : : ðertype_filter, TRUE);
3287 [ # # ]: 0 : if (ret) {
3288 : 0 : rte_free(ethertype_filter_ptr);
3289 : 0 : goto out;
3290 : : }
3291 : 0 : TAILQ_INSERT_TAIL(&filter_ethertype_list,
3292 : : ethertype_filter_ptr, entries);
3293 : 0 : flow->rule = ethertype_filter_ptr;
3294 : 0 : flow->filter_type = RTE_ETH_FILTER_ETHERTYPE;
3295 : 0 : return flow;
3296 : : }
3297 : :
3298 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3299 : 0 : ret = txgbe_parse_syn_filter(dev, attr, pattern,
3300 : : actions, &syn_filter, error);
3301 [ # # ]: 0 : if (!ret) {
3302 : 0 : syn_filter_ptr = rte_zmalloc("txgbe_syn_filter",
3303 : : sizeof(struct txgbe_eth_syn_filter_ele), 0);
3304 [ # # ]: 0 : if (!syn_filter_ptr) {
3305 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3306 : : ret = -ENOMEM;
3307 : 0 : goto out;
3308 : : }
3309 : 0 : syn_filter_ptr->filter_info = syn_filter;
3310 : 0 : ret = txgbe_syn_filter_set(dev, &syn_filter, TRUE);
3311 [ # # ]: 0 : if (ret) {
3312 : 0 : rte_free(syn_filter_ptr);
3313 : 0 : goto out;
3314 : : }
3315 : 0 : TAILQ_INSERT_TAIL(&filter_syn_list,
3316 : : syn_filter_ptr, entries);
3317 : 0 : flow->rule = syn_filter_ptr;
3318 : 0 : flow->filter_type = RTE_ETH_FILTER_SYN;
3319 : 0 : return flow;
3320 : : }
3321 : :
3322 : : memset(&fdir_rule, 0, sizeof(struct txgbe_fdir_rule));
3323 : 0 : ret = txgbe_parse_fdir_filter(dev, attr, pattern,
3324 : : actions, &fdir_rule, error);
3325 [ # # ]: 0 : if (!ret) {
3326 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
3327 : 0 : fdir_rule_ptr = rte_zmalloc("txgbe_fdir_filter",
3328 : : sizeof(struct txgbe_fdir_rule_ele), 0);
3329 [ # # ]: 0 : if (!fdir_rule_ptr) {
3330 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3331 : : ret = -ENOMEM;
3332 : 0 : goto out;
3333 : : }
3334 : :
3335 : 0 : ret = txgbevf_fdir_filter_program(dev, &fdir_rule,
3336 : : FALSE);
3337 [ # # ]: 0 : if (ret < 0) {
3338 : 0 : rte_free(fdir_rule_ptr);
3339 : 0 : goto out;
3340 : : }
3341 : :
3342 : 0 : fdir_rule_ptr->filter_info = fdir_rule;
3343 : 0 : TAILQ_INSERT_TAIL(&filter_fdir_list,
3344 : : fdir_rule_ptr, entries);
3345 : 0 : flow->rule = fdir_rule_ptr;
3346 : 0 : flow->filter_type = RTE_ETH_FILTER_FDIR;
3347 : 0 : return flow;
3348 : : }
3349 : :
3350 [ # # ]: 0 : if (!fdir_rule.b_spec) {
3351 : : ret = -EINVAL;
3352 : 0 : goto out;
3353 : : }
3354 : :
3355 : 0 : fdir_rule_ptr = rte_zmalloc("txgbe_fdir_filter",
3356 : : sizeof(struct txgbe_fdir_rule_ele), 0);
3357 [ # # ]: 0 : if (!fdir_rule_ptr) {
3358 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3359 : : ret = -ENOMEM;
3360 : 0 : goto out;
3361 : : }
3362 : :
3363 : : /* A mask cannot be deleted. */
3364 [ # # ]: 0 : if (fdir_rule.b_mask) {
3365 [ # # ]: 0 : if (!fdir_info->mask_added) {
3366 : : /* It's the first time the mask is set. */
3367 : 0 : fdir_info->mask = fdir_rule.mask;
3368 : 0 : fdir_info->flex_bytes_offset =
3369 : 0 : fdir_rule.flex_bytes_offset;
3370 : 0 : fdir_info->flex_relative = fdir_rule.flex_relative;
3371 : :
3372 [ # # ]: 0 : if (fdir_rule.mask.flex_bytes_mask) {
3373 : : uint16_t flex_base;
3374 : :
3375 : 0 : flex_base = txgbe_fdir_get_flex_base(&fdir_rule);
3376 : 0 : txgbe_fdir_set_flexbytes_offset(dev,
3377 : 0 : fdir_rule.flex_bytes_offset,
3378 : : flex_base);
3379 : : }
3380 : :
3381 : 0 : fdir_info->mask.pkt_type_mask =
3382 : 0 : fdir_rule.mask.pkt_type_mask;
3383 : 0 : ret = txgbe_fdir_set_input_mask(dev);
3384 [ # # ]: 0 : if (ret) {
3385 : 0 : rte_free(fdir_rule_ptr);
3386 : 0 : goto out;
3387 : : }
3388 : :
3389 : 0 : fdir_info->mask_added = TRUE;
3390 : : first_mask = TRUE;
3391 : : } else {
3392 : : /**
3393 : : * Only support one global mask,
3394 : : * all the masks should be the same.
3395 : : */
3396 [ # # ]: 0 : if (memcmp(&fdir_info->mask,
3397 : : &fdir_rule.mask,
3398 : : sizeof(struct txgbe_hw_fdir_mask)) != 0) {
3399 : 0 : PMD_DRV_LOG(ERR, "only support one global mask");
3400 : 0 : rte_free(fdir_rule_ptr);
3401 : : ret = -EINVAL;
3402 : 0 : goto out;
3403 : : }
3404 : :
3405 : 0 : if (fdir_info->flex_bytes_offset !=
3406 [ # # ]: 0 : fdir_rule.flex_bytes_offset ||
3407 : : fdir_info->flex_relative !=
3408 : : fdir_rule.flex_relative) {
3409 : 0 : PMD_DRV_LOG(ERR,
3410 : : "flex bytes offset mismatch");
3411 : 0 : rte_free(fdir_rule_ptr);
3412 : : ret = -EINVAL;
3413 : 0 : goto out;
3414 : : }
3415 : : }
3416 : : }
3417 : :
3418 : 0 : ret = txgbe_fdir_filter_program(dev, &fdir_rule,
3419 : : FALSE, FALSE);
3420 [ # # ]: 0 : if (ret) {
3421 : 0 : rte_free(fdir_rule_ptr);
3422 : : /**
3423 : : * clean the mask_added flag if fail to
3424 : : * program
3425 : : **/
3426 [ # # ]: 0 : if (first_mask)
3427 : 0 : fdir_info->mask_added = FALSE;
3428 : 0 : goto out;
3429 : : }
3430 : :
3431 : 0 : fdir_rule_ptr->filter_info = fdir_rule;
3432 : 0 : TAILQ_INSERT_TAIL(&filter_fdir_list,
3433 : : fdir_rule_ptr, entries);
3434 : 0 : flow->rule = fdir_rule_ptr;
3435 : 0 : flow->filter_type = RTE_ETH_FILTER_FDIR;
3436 : :
3437 : 0 : return flow;
3438 : : }
3439 : :
3440 : : memset(&l2_tn_filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
3441 : 0 : ret = txgbe_parse_l2_tn_filter(dev, attr, pattern,
3442 : : actions, &l2_tn_filter, error);
3443 [ # # ]: 0 : if (!ret) {
3444 : 0 : l2_tn_filter_ptr = rte_zmalloc("txgbe_l2_tn_filter",
3445 : : sizeof(struct txgbe_eth_l2_tunnel_conf_ele), 0);
3446 [ # # ]: 0 : if (!l2_tn_filter_ptr) {
3447 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3448 : : ret = -ENOMEM;
3449 : 0 : goto out;
3450 : : }
3451 : 0 : l2_tn_filter_ptr->filter_info = l2_tn_filter;
3452 : 0 : ret = txgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_filter, FALSE);
3453 [ # # ]: 0 : if (ret) {
3454 : 0 : rte_free(l2_tn_filter_ptr);
3455 : 0 : goto out;
3456 : : }
3457 : 0 : TAILQ_INSERT_TAIL(&filter_l2_tunnel_list,
3458 : : l2_tn_filter_ptr, entries);
3459 : 0 : flow->rule = l2_tn_filter_ptr;
3460 : 0 : flow->filter_type = RTE_ETH_FILTER_L2_TUNNEL;
3461 : 0 : return flow;
3462 : : }
3463 : :
3464 : : memset(&rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3465 : 0 : ret = txgbe_parse_rss_filter(dev, attr,
3466 : : actions, &rss_conf, error);
3467 [ # # ]: 0 : if (!ret) {
3468 : 0 : rss_filter_ptr = rte_zmalloc("txgbe_rss_filter",
3469 : : sizeof(struct txgbe_rss_conf_ele), 0);
3470 [ # # ]: 0 : if (!rss_filter_ptr) {
3471 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3472 : : ret = -ENOMEM;
3473 : 0 : goto out;
3474 : : }
3475 : 0 : ret = txgbe_config_rss_filter(dev, &rss_conf, TRUE);
3476 [ # # ]: 0 : if (ret) {
3477 : 0 : rte_free(rss_filter_ptr);
3478 : 0 : goto out;
3479 : : }
3480 : 0 : txgbe_rss_conf_init(&rss_filter_ptr->filter_info,
3481 : : &rss_conf.conf);
3482 : 0 : TAILQ_INSERT_TAIL(&filter_rss_list,
3483 : : rss_filter_ptr, entries);
3484 : 0 : flow->rule = rss_filter_ptr;
3485 : 0 : flow->filter_type = RTE_ETH_FILTER_HASH;
3486 : 0 : return flow;
3487 : : }
3488 : :
3489 : 0 : out:
3490 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3491 : : txgbe_flow_mem_ptr, entries);
3492 : 0 : rte_flow_error_set(error, -ret,
3493 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
3494 : : "Failed to create flow.");
3495 : 0 : rte_free(txgbe_flow_mem_ptr);
3496 : 0 : rte_free(flow);
3497 : 0 : return NULL;
3498 : : }
3499 : :
3500 : : /**
3501 : : * Check if the flow rule is supported by txgbe.
3502 : : * It only checks the format. Don't guarantee the rule can be programmed into
3503 : : * the HW. Because there can be no enough room for the rule.
3504 : : */
3505 : : static int
3506 : 0 : txgbe_flow_validate(struct rte_eth_dev *dev,
3507 : : const struct rte_flow_attr *attr,
3508 : : const struct rte_flow_item pattern[],
3509 : : const struct rte_flow_action actions[],
3510 : : struct rte_flow_error *error)
3511 : : {
3512 : : struct rte_eth_ntuple_filter ntuple_filter;
3513 : : struct rte_eth_ethertype_filter ethertype_filter;
3514 : : struct rte_eth_syn_filter syn_filter;
3515 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3516 : : struct txgbe_fdir_rule fdir_rule;
3517 : : struct txgbe_rte_flow_rss_conf rss_conf;
3518 : : int ret = 0;
3519 : :
3520 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3521 : 0 : ret = txgbe_parse_ntuple_filter(dev, attr, pattern,
3522 : : actions, &ntuple_filter, error);
3523 [ # # ]: 0 : if (!ret)
3524 : : return 0;
3525 : :
3526 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3527 : 0 : ret = txgbe_parse_ethertype_filter(dev, attr, pattern,
3528 : : actions, ðertype_filter, error);
3529 [ # # ]: 0 : if (!ret)
3530 : : return 0;
3531 : :
3532 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3533 : 0 : ret = txgbe_parse_syn_filter(dev, attr, pattern,
3534 : : actions, &syn_filter, error);
3535 [ # # ]: 0 : if (!ret)
3536 : : return 0;
3537 : :
3538 : : memset(&fdir_rule, 0, sizeof(struct txgbe_fdir_rule));
3539 : 0 : ret = txgbe_parse_fdir_filter(dev, attr, pattern,
3540 : : actions, &fdir_rule, error);
3541 [ # # ]: 0 : if (!ret)
3542 : : return 0;
3543 : :
3544 : : memset(&l2_tn_filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
3545 : 0 : ret = txgbe_parse_l2_tn_filter(dev, attr, pattern,
3546 : : actions, &l2_tn_filter, error);
3547 [ # # ]: 0 : if (!ret)
3548 : : return 0;
3549 : :
3550 : : memset(&rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3551 : 0 : ret = txgbe_parse_rss_filter(dev, attr,
3552 : : actions, &rss_conf, error);
3553 : :
3554 : 0 : return ret;
3555 : : }
3556 : :
3557 : : /* Destroy a flow rule on txgbe. */
3558 : : static int
3559 : 0 : txgbe_flow_destroy(struct rte_eth_dev *dev,
3560 : : struct rte_flow *flow,
3561 : : struct rte_flow_error *error)
3562 : : {
3563 : : int ret = 0;
3564 : : struct rte_flow *pmd_flow = flow;
3565 : 0 : enum rte_filter_type filter_type = pmd_flow->filter_type;
3566 : : struct rte_eth_ntuple_filter ntuple_filter;
3567 : : struct rte_eth_ethertype_filter ethertype_filter;
3568 : : struct rte_eth_syn_filter syn_filter;
3569 : : struct txgbe_fdir_rule fdir_rule;
3570 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3571 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3572 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3573 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3574 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3575 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3576 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3577 : 0 : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
3578 : : struct rte_eth_fdir_conf *fdir_conf = TXGBE_DEV_FDIR_CONF(dev);
3579 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3580 : :
3581 [ # # # # : 0 : switch (filter_type) {
# # # ]
3582 : 0 : case RTE_ETH_FILTER_NTUPLE:
3583 : 0 : ntuple_filter_ptr = (struct txgbe_ntuple_filter_ele *)
3584 : : pmd_flow->rule;
3585 : : rte_memcpy(&ntuple_filter,
3586 : : &ntuple_filter_ptr->filter_info,
3587 : : sizeof(struct rte_eth_ntuple_filter));
3588 : 0 : ret = txgbe_add_del_ntuple_filter(dev, &ntuple_filter, FALSE);
3589 [ # # ]: 0 : if (!ret) {
3590 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
3591 : : ntuple_filter_ptr, entries);
3592 : 0 : rte_free(ntuple_filter_ptr);
3593 : : }
3594 : : break;
3595 : 0 : case RTE_ETH_FILTER_ETHERTYPE:
3596 : 0 : ethertype_filter_ptr = (struct txgbe_ethertype_filter_ele *)
3597 : : pmd_flow->rule;
3598 : : rte_memcpy(ðertype_filter,
3599 : : ðertype_filter_ptr->filter_info,
3600 : : sizeof(struct rte_eth_ethertype_filter));
3601 : 0 : ret = txgbe_add_del_ethertype_filter(dev,
3602 : : ðertype_filter, FALSE);
3603 [ # # ]: 0 : if (!ret) {
3604 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
3605 : : ethertype_filter_ptr, entries);
3606 : 0 : rte_free(ethertype_filter_ptr);
3607 : : }
3608 : : break;
3609 : 0 : case RTE_ETH_FILTER_SYN:
3610 : 0 : syn_filter_ptr = (struct txgbe_eth_syn_filter_ele *)
3611 : : pmd_flow->rule;
3612 : : rte_memcpy(&syn_filter,
3613 : : &syn_filter_ptr->filter_info,
3614 : : sizeof(struct rte_eth_syn_filter));
3615 : 0 : ret = txgbe_syn_filter_set(dev, &syn_filter, FALSE);
3616 [ # # ]: 0 : if (!ret) {
3617 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
3618 : : syn_filter_ptr, entries);
3619 : 0 : rte_free(syn_filter_ptr);
3620 : : }
3621 : : break;
3622 : 0 : case RTE_ETH_FILTER_FDIR:
3623 : 0 : fdir_rule_ptr = (struct txgbe_fdir_rule_ele *)pmd_flow->rule;
3624 : : rte_memcpy(&fdir_rule,
3625 [ # # ]: 0 : &fdir_rule_ptr->filter_info,
3626 : : sizeof(struct txgbe_fdir_rule));
3627 [ # # ]: 0 : if (txgbe_is_pf(TXGBE_DEV_HW(dev)))
3628 : 0 : ret = txgbe_fdir_filter_program(dev, &fdir_rule, TRUE, FALSE);
3629 : : else
3630 : 0 : ret = txgbevf_fdir_filter_program(dev, &fdir_rule, TRUE);
3631 [ # # ]: 0 : if (!ret) {
3632 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
3633 : : fdir_rule_ptr, entries);
3634 : 0 : rte_free(fdir_rule_ptr);
3635 [ # # ]: 0 : if (TAILQ_EMPTY(&filter_fdir_list)) {
3636 : 0 : memset(&fdir_info->mask, 0,
3637 : : sizeof(struct txgbe_hw_fdir_mask));
3638 : 0 : fdir_info->mask_added = false;
3639 : 0 : fdir_info->flex_relative = false;
3640 : 0 : fdir_info->flex_bytes_offset = 0;
3641 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
3642 : : }
3643 : : }
3644 : : break;
3645 : 0 : case RTE_ETH_FILTER_L2_TUNNEL:
3646 : 0 : l2_tn_filter_ptr = (struct txgbe_eth_l2_tunnel_conf_ele *)
3647 : : pmd_flow->rule;
3648 : : rte_memcpy(&l2_tn_filter, &l2_tn_filter_ptr->filter_info,
3649 : : sizeof(struct txgbe_l2_tunnel_conf));
3650 : 0 : ret = txgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_filter);
3651 [ # # ]: 0 : if (!ret) {
3652 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
3653 : : l2_tn_filter_ptr, entries);
3654 : 0 : rte_free(l2_tn_filter_ptr);
3655 : : }
3656 : : break;
3657 : 0 : case RTE_ETH_FILTER_HASH:
3658 : 0 : rss_filter_ptr = (struct txgbe_rss_conf_ele *)
3659 : : pmd_flow->rule;
3660 : 0 : ret = txgbe_config_rss_filter(dev,
3661 : : &rss_filter_ptr->filter_info, FALSE);
3662 [ # # ]: 0 : if (!ret) {
3663 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
3664 : : rss_filter_ptr, entries);
3665 : 0 : rte_free(rss_filter_ptr);
3666 : : }
3667 : : break;
3668 : 0 : default:
3669 : 0 : PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3670 : : filter_type);
3671 : : ret = -EINVAL;
3672 : : break;
3673 : : }
3674 : :
3675 [ # # ]: 0 : if (ret) {
3676 : 0 : rte_flow_error_set(error, EINVAL,
3677 : : RTE_FLOW_ERROR_TYPE_HANDLE,
3678 : : NULL, "Failed to destroy flow");
3679 : 0 : return ret;
3680 : : }
3681 : :
3682 [ # # ]: 0 : TAILQ_FOREACH(txgbe_flow_mem_ptr, &txgbe_flow_list, entries) {
3683 [ # # ]: 0 : if (txgbe_flow_mem_ptr->flow == pmd_flow)
3684 : : break;
3685 : : }
3686 [ # # ]: 0 : if (txgbe_flow_mem_ptr != NULL) {
3687 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3688 : : txgbe_flow_mem_ptr, entries);
3689 : 0 : rte_free(txgbe_flow_mem_ptr);
3690 : : }
3691 : 0 : rte_free(flow);
3692 : :
3693 : 0 : return ret;
3694 : : }
3695 : :
3696 : : /* Destroy all flow rules associated with a port on txgbe. */
3697 : : static int
3698 : 0 : txgbe_flow_flush(struct rte_eth_dev *dev,
3699 : : struct rte_flow_error *error)
3700 : : {
3701 : : int ret = 0;
3702 : :
3703 : 0 : txgbe_clear_all_ntuple_filter(dev);
3704 : :
3705 : 0 : ret = txgbe_clear_all_fdir_filter(dev);
3706 [ # # ]: 0 : if (ret < 0) {
3707 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3708 : : NULL, "Failed to flush rule");
3709 : 0 : return ret;
3710 : : }
3711 : :
3712 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev)))
3713 : 0 : goto out;
3714 : :
3715 : 0 : txgbe_clear_all_ethertype_filter(dev);
3716 : 0 : txgbe_clear_syn_filter(dev);
3717 : :
3718 : 0 : ret = txgbe_clear_all_l2_tn_filter(dev);
3719 [ # # ]: 0 : if (ret < 0) {
3720 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3721 : : NULL, "Failed to flush rule");
3722 : 0 : return ret;
3723 : : }
3724 : :
3725 : : txgbe_clear_rss_filter(dev);
3726 : :
3727 : 0 : out:
3728 : 0 : txgbe_filterlist_flush();
3729 : :
3730 : 0 : return 0;
3731 : : }
3732 : :
3733 : : const struct rte_flow_ops txgbe_flow_ops = {
3734 : : .validate = txgbe_flow_validate,
3735 : : .create = txgbe_flow_create,
3736 : : .destroy = txgbe_flow_destroy,
3737 : : .flush = txgbe_flow_flush,
3738 : : };
|