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