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 : 0 : rule->mask.dst_port_mask = 0;
1648 : 0 : rule->mask.src_port_mask = 0;
1649 : :
1650 : : /**
1651 : : * The first not void item should be
1652 : : * MAC or IPv4 or TCP or UDP or SCTP.
1653 : : */
1654 : : item = next_no_fuzzy_pattern(pattern, NULL);
1655 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
1656 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1657 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
1658 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1659 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1660 : : item->type != RTE_FLOW_ITEM_TYPE_SCTP) {
1661 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1662 : 0 : rte_flow_error_set(error, EINVAL,
1663 : : RTE_FLOW_ERROR_TYPE_ITEM,
1664 : : item, "Not supported by fdir filter");
1665 : 0 : return -rte_errno;
1666 : : }
1667 : :
1668 [ # # ]: 0 : if (signature_match(pattern))
1669 : 0 : rule->mode = RTE_FDIR_MODE_SIGNATURE;
1670 : : else
1671 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT;
1672 : :
1673 : : /*Not supported last point for range*/
1674 [ # # ]: 0 : if (item->last) {
1675 : 0 : rte_flow_error_set(error, EINVAL,
1676 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1677 : : item, "Not supported last point for range");
1678 : 0 : return -rte_errno;
1679 : : }
1680 : :
1681 : : /* Get the MAC info. */
1682 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
1683 : : /**
1684 : : * Only support vlan and dst MAC address,
1685 : : * others should be masked.
1686 : : */
1687 [ # # # # ]: 0 : if (item->spec && !item->mask) {
1688 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1689 : 0 : rte_flow_error_set(error, EINVAL,
1690 : : RTE_FLOW_ERROR_TYPE_ITEM,
1691 : : item, "Not supported by fdir filter");
1692 : 0 : return -rte_errno;
1693 : : }
1694 : :
1695 [ # # ]: 0 : if (item->spec) {
1696 : 0 : rule->b_spec = TRUE;
1697 : : eth_spec = item->spec;
1698 : :
1699 : : /* Get the dst MAC. */
1700 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
1701 : 0 : rule->ixgbe_fdir.formatted.inner_mac[j] =
1702 : 0 : eth_spec->hdr.dst_addr.addr_bytes[j];
1703 : : }
1704 : : }
1705 : :
1706 : :
1707 [ # # ]: 0 : if (item->mask) {
1708 : :
1709 : 0 : rule->b_mask = TRUE;
1710 : : eth_mask = item->mask;
1711 : :
1712 : : /* Ether type should be masked. */
1713 [ # # ]: 0 : if (eth_mask->hdr.ether_type ||
1714 [ # # ]: 0 : rule->mode == RTE_FDIR_MODE_SIGNATURE) {
1715 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1716 : 0 : rte_flow_error_set(error, EINVAL,
1717 : : RTE_FLOW_ERROR_TYPE_ITEM,
1718 : : item, "Not supported by fdir filter");
1719 : 0 : return -rte_errno;
1720 : : }
1721 : :
1722 : : /* If ethernet has meaning, it means MAC VLAN mode. */
1723 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
1724 : :
1725 : : /**
1726 : : * src MAC address must be masked,
1727 : : * and don't support dst MAC address mask.
1728 : : */
1729 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
1730 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j] ||
1731 [ # # ]: 0 : eth_mask->hdr.dst_addr.addr_bytes[j] != 0xFF) {
1732 : : memset(rule, 0,
1733 : : sizeof(struct ixgbe_fdir_rule));
1734 : 0 : rte_flow_error_set(error, EINVAL,
1735 : : RTE_FLOW_ERROR_TYPE_ITEM,
1736 : : item, "Not supported by fdir filter");
1737 : 0 : return -rte_errno;
1738 : : }
1739 : : }
1740 : :
1741 : : /* When no VLAN, considered as full mask. */
1742 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
1743 : : }
1744 : : /*** If both spec and mask are item,
1745 : : * it means don't care about ETH.
1746 : : * Do nothing.
1747 : : */
1748 : :
1749 : : /**
1750 : : * Check if the next not void item is vlan or ipv4.
1751 : : * IPv6 is not supported.
1752 : : */
1753 : : item = next_no_fuzzy_pattern(pattern, item);
1754 [ # # ]: 0 : if (rule->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
1755 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
1756 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1757 : 0 : rte_flow_error_set(error, EINVAL,
1758 : : RTE_FLOW_ERROR_TYPE_ITEM,
1759 : : item, "Not supported by fdir filter");
1760 : 0 : return -rte_errno;
1761 : : }
1762 : : } else {
1763 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1764 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
1765 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1766 : 0 : rte_flow_error_set(error, EINVAL,
1767 : : RTE_FLOW_ERROR_TYPE_ITEM,
1768 : : item, "Not supported by fdir filter");
1769 : 0 : return -rte_errno;
1770 : : }
1771 : : }
1772 : : }
1773 : :
1774 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1775 [ # # # # ]: 0 : if (!(item->spec && item->mask)) {
1776 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1777 : 0 : rte_flow_error_set(error, EINVAL,
1778 : : RTE_FLOW_ERROR_TYPE_ITEM,
1779 : : item, "Not supported by fdir filter");
1780 : 0 : return -rte_errno;
1781 : : }
1782 : :
1783 : : /*Not supported last point for range*/
1784 [ # # ]: 0 : if (item->last) {
1785 : 0 : rte_flow_error_set(error, EINVAL,
1786 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1787 : : item, "Not supported last point for range");
1788 : 0 : return -rte_errno;
1789 : : }
1790 : :
1791 : : vlan_spec = item->spec;
1792 : : vlan_mask = item->mask;
1793 : :
1794 : 0 : rule->ixgbe_fdir.formatted.vlan_id = vlan_spec->hdr.vlan_tci;
1795 : :
1796 : 0 : rule->mask.vlan_tci_mask = vlan_mask->hdr.vlan_tci;
1797 : 0 : rule->mask.vlan_tci_mask &= rte_cpu_to_be_16(0xEFFF);
1798 : : /* More than one tags are not supported. */
1799 : :
1800 : : /* Next not void item must be END */
1801 : : item = next_no_fuzzy_pattern(pattern, item);
1802 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1803 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1804 : 0 : rte_flow_error_set(error, EINVAL,
1805 : : RTE_FLOW_ERROR_TYPE_ITEM,
1806 : : item, "Not supported by fdir filter");
1807 : 0 : return -rte_errno;
1808 : : }
1809 : : }
1810 : :
1811 : : /* Get the IPV4 info. */
1812 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
1813 : : /**
1814 : : * Set the flow type even if there's no content
1815 : : * as we must have a flow type.
1816 : : */
1817 : : rule->ixgbe_fdir.formatted.flow_type =
1818 : : IXGBE_ATR_FLOW_TYPE_IPV4;
1819 : : /*Not supported last point for range*/
1820 [ # # ]: 0 : if (item->last) {
1821 : 0 : rte_flow_error_set(error, EINVAL,
1822 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1823 : : item, "Not supported last point for range");
1824 : 0 : return -rte_errno;
1825 : : }
1826 : : /**
1827 : : * Only care about src & dst addresses,
1828 : : * others should be masked.
1829 : : */
1830 [ # # ]: 0 : if (!item->mask) {
1831 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1832 : 0 : rte_flow_error_set(error, EINVAL,
1833 : : RTE_FLOW_ERROR_TYPE_ITEM,
1834 : : item, "Not supported by fdir filter");
1835 : 0 : return -rte_errno;
1836 : : }
1837 : 0 : rule->b_mask = TRUE;
1838 : : ipv4_mask = item->mask;
1839 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
1840 : 0 : ipv4_mask->hdr.type_of_service ||
1841 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
1842 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
1843 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
1844 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
1845 : 0 : ipv4_mask->hdr.next_proto_id ||
1846 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
1847 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1848 : 0 : rte_flow_error_set(error, EINVAL,
1849 : : RTE_FLOW_ERROR_TYPE_ITEM,
1850 : : item, "Not supported by fdir filter");
1851 : 0 : return -rte_errno;
1852 : : }
1853 : 0 : rule->mask.dst_ipv4_mask = ipv4_mask->hdr.dst_addr;
1854 : 0 : rule->mask.src_ipv4_mask = ipv4_mask->hdr.src_addr;
1855 : :
1856 [ # # ]: 0 : if (item->spec) {
1857 : 0 : rule->b_spec = TRUE;
1858 : : ipv4_spec = item->spec;
1859 : 0 : rule->ixgbe_fdir.formatted.dst_ip[0] =
1860 : 0 : ipv4_spec->hdr.dst_addr;
1861 : 0 : rule->ixgbe_fdir.formatted.src_ip[0] =
1862 : 0 : ipv4_spec->hdr.src_addr;
1863 : : }
1864 : :
1865 : : /**
1866 : : * Check if the next not void item is
1867 : : * TCP or UDP or SCTP or END.
1868 : : */
1869 : : item = next_no_fuzzy_pattern(pattern, item);
1870 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1871 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1872 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1873 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1874 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1875 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1876 : 0 : rte_flow_error_set(error, EINVAL,
1877 : : RTE_FLOW_ERROR_TYPE_ITEM,
1878 : : item, "Not supported by fdir filter");
1879 : 0 : return -rte_errno;
1880 : : }
1881 : : }
1882 : :
1883 : : /* Get the IPV6 info. */
1884 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
1885 : : /**
1886 : : * Set the flow type even if there's no content
1887 : : * as we must have a flow type.
1888 : : */
1889 : 0 : rule->ixgbe_fdir.formatted.flow_type =
1890 : : IXGBE_ATR_FLOW_TYPE_IPV6;
1891 : :
1892 : : /**
1893 : : * 1. must signature match
1894 : : * 2. not support last
1895 : : * 3. mask must not null
1896 : : */
1897 [ # # ]: 0 : if (rule->mode != RTE_FDIR_MODE_SIGNATURE ||
1898 [ # # ]: 0 : item->last ||
1899 [ # # ]: 0 : !item->mask) {
1900 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1901 : 0 : rte_flow_error_set(error, EINVAL,
1902 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1903 : : item, "Not supported last point for range");
1904 : 0 : return -rte_errno;
1905 : : }
1906 : :
1907 : 0 : rule->b_mask = TRUE;
1908 : : ipv6_mask = item->mask;
1909 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow ||
1910 : : ipv6_mask->hdr.payload_len ||
1911 [ # # ]: 0 : ipv6_mask->hdr.proto ||
1912 : : ipv6_mask->hdr.hop_limits) {
1913 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1914 : 0 : rte_flow_error_set(error, EINVAL,
1915 : : RTE_FLOW_ERROR_TYPE_ITEM,
1916 : : item, "Not supported by fdir filter");
1917 : 0 : return -rte_errno;
1918 : : }
1919 : :
1920 : : /* check src addr mask */
1921 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1922 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j] == 0) {
1923 : 0 : rule->mask.src_ipv6_mask &= ~(1 << j);
1924 [ # # ]: 0 : } else if (ipv6_mask->hdr.src_addr.a[j] != UINT8_MAX) {
1925 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1926 : 0 : rte_flow_error_set(error, EINVAL,
1927 : : RTE_FLOW_ERROR_TYPE_ITEM,
1928 : : item, "Not supported by fdir filter");
1929 : 0 : return -rte_errno;
1930 : : }
1931 : : }
1932 : :
1933 : : /* check dst addr mask */
1934 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1935 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j] == 0) {
1936 : 0 : rule->mask.dst_ipv6_mask &= ~(1 << j);
1937 [ # # ]: 0 : } else if (ipv6_mask->hdr.dst_addr.a[j] != UINT8_MAX) {
1938 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1939 : 0 : rte_flow_error_set(error, EINVAL,
1940 : : RTE_FLOW_ERROR_TYPE_ITEM,
1941 : : item, "Not supported by fdir filter");
1942 : 0 : return -rte_errno;
1943 : : }
1944 : : }
1945 : :
1946 [ # # ]: 0 : if (item->spec) {
1947 : 0 : rule->b_spec = TRUE;
1948 : : ipv6_spec = item->spec;
1949 : 0 : rte_memcpy(rule->ixgbe_fdir.formatted.src_ip,
1950 [ # # ]: 0 : &ipv6_spec->hdr.src_addr, 16);
1951 : 0 : rte_memcpy(rule->ixgbe_fdir.formatted.dst_ip,
1952 [ # # ]: 0 : &ipv6_spec->hdr.dst_addr, 16);
1953 : : }
1954 : :
1955 : : /**
1956 : : * Check if the next not void item is
1957 : : * TCP or UDP or SCTP or END.
1958 : : */
1959 : : item = next_no_fuzzy_pattern(pattern, item);
1960 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1961 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1962 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1963 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1964 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1965 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1966 : 0 : rte_flow_error_set(error, EINVAL,
1967 : : RTE_FLOW_ERROR_TYPE_ITEM,
1968 : : item, "Not supported by fdir filter");
1969 : 0 : return -rte_errno;
1970 : : }
1971 : : }
1972 : :
1973 : : /* Get the TCP info. */
1974 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
1975 : : /**
1976 : : * Set the flow type even if there's no content
1977 : : * as we must have a flow type.
1978 : : */
1979 : 0 : rule->ixgbe_fdir.formatted.flow_type |=
1980 : : IXGBE_ATR_L4TYPE_TCP;
1981 : : /*Not supported last point for range*/
1982 [ # # ]: 0 : if (item->last) {
1983 : 0 : rte_flow_error_set(error, EINVAL,
1984 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1985 : : item, "Not supported last point for range");
1986 : 0 : return -rte_errno;
1987 : : }
1988 : : /**
1989 : : * Only care about src & dst ports,
1990 : : * others should be masked.
1991 : : */
1992 [ # # ]: 0 : if (!item->mask) {
1993 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
1994 : 0 : rte_flow_error_set(error, EINVAL,
1995 : : RTE_FLOW_ERROR_TYPE_ITEM,
1996 : : item, "Not supported by fdir filter");
1997 : 0 : return -rte_errno;
1998 : : }
1999 : 0 : rule->b_mask = TRUE;
2000 : : tcp_mask = item->mask;
2001 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
2002 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
2003 [ # # ]: 0 : tcp_mask->hdr.data_off ||
2004 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
2005 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
2006 [ # # ]: 0 : tcp_mask->hdr.cksum ||
2007 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
2008 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2009 : 0 : rte_flow_error_set(error, EINVAL,
2010 : : RTE_FLOW_ERROR_TYPE_ITEM,
2011 : : item, "Not supported by fdir filter");
2012 : 0 : return -rte_errno;
2013 : : }
2014 : 0 : rule->mask.src_port_mask = tcp_mask->hdr.src_port;
2015 : 0 : rule->mask.dst_port_mask = tcp_mask->hdr.dst_port;
2016 : :
2017 [ # # ]: 0 : if (item->spec) {
2018 : 0 : rule->b_spec = TRUE;
2019 : : tcp_spec = item->spec;
2020 : 0 : rule->ixgbe_fdir.formatted.src_port =
2021 : 0 : tcp_spec->hdr.src_port;
2022 : 0 : rule->ixgbe_fdir.formatted.dst_port =
2023 : 0 : tcp_spec->hdr.dst_port;
2024 : : }
2025 : :
2026 : : item = next_no_fuzzy_pattern(pattern, item);
2027 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2028 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2029 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2030 : 0 : rte_flow_error_set(error, EINVAL,
2031 : : RTE_FLOW_ERROR_TYPE_ITEM,
2032 : : item, "Not supported by fdir filter");
2033 : 0 : return -rte_errno;
2034 : : }
2035 : :
2036 : : }
2037 : :
2038 : : /* Get the UDP info */
2039 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2040 : : /**
2041 : : * Set the flow type even if there's no content
2042 : : * as we must have a flow type.
2043 : : */
2044 : 0 : rule->ixgbe_fdir.formatted.flow_type |=
2045 : : IXGBE_ATR_L4TYPE_UDP;
2046 : : /*Not supported last point for range*/
2047 [ # # ]: 0 : if (item->last) {
2048 : 0 : rte_flow_error_set(error, EINVAL,
2049 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2050 : : item, "Not supported last point for range");
2051 : 0 : return -rte_errno;
2052 : : }
2053 : : /**
2054 : : * Only care about src & dst ports,
2055 : : * others should be masked.
2056 : : */
2057 [ # # ]: 0 : if (!item->mask) {
2058 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2059 : 0 : rte_flow_error_set(error, EINVAL,
2060 : : RTE_FLOW_ERROR_TYPE_ITEM,
2061 : : item, "Not supported by fdir filter");
2062 : 0 : return -rte_errno;
2063 : : }
2064 : 0 : rule->b_mask = TRUE;
2065 : : udp_mask = item->mask;
2066 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
2067 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
2068 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2069 : 0 : rte_flow_error_set(error, EINVAL,
2070 : : RTE_FLOW_ERROR_TYPE_ITEM,
2071 : : item, "Not supported by fdir filter");
2072 : 0 : return -rte_errno;
2073 : : }
2074 : 0 : rule->mask.src_port_mask = udp_mask->hdr.src_port;
2075 : 0 : rule->mask.dst_port_mask = udp_mask->hdr.dst_port;
2076 : :
2077 [ # # ]: 0 : if (item->spec) {
2078 : 0 : rule->b_spec = TRUE;
2079 : : udp_spec = item->spec;
2080 : 0 : rule->ixgbe_fdir.formatted.src_port =
2081 : 0 : udp_spec->hdr.src_port;
2082 : 0 : rule->ixgbe_fdir.formatted.dst_port =
2083 : 0 : udp_spec->hdr.dst_port;
2084 : : }
2085 : :
2086 : : item = next_no_fuzzy_pattern(pattern, item);
2087 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2088 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2089 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2090 : 0 : rte_flow_error_set(error, EINVAL,
2091 : : RTE_FLOW_ERROR_TYPE_ITEM,
2092 : : item, "Not supported by fdir filter");
2093 : 0 : return -rte_errno;
2094 : : }
2095 : :
2096 : : }
2097 : :
2098 : : /* Get the SCTP info */
2099 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
2100 : : /**
2101 : : * Set the flow type even if there's no content
2102 : : * as we must have a flow type.
2103 : : */
2104 : 0 : rule->ixgbe_fdir.formatted.flow_type |=
2105 : : IXGBE_ATR_L4TYPE_SCTP;
2106 : : /*Not supported last point for range*/
2107 [ # # ]: 0 : if (item->last) {
2108 : 0 : rte_flow_error_set(error, EINVAL,
2109 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2110 : : item, "Not supported last point for range");
2111 : 0 : return -rte_errno;
2112 : : }
2113 : :
2114 : : /* only x550 family only support sctp port */
2115 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
2116 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
2117 : : hw->mac.type == ixgbe_mac_X550EM_a) {
2118 : : /**
2119 : : * Only care about src & dst ports,
2120 : : * others should be masked.
2121 : : */
2122 [ # # ]: 0 : if (!item->mask) {
2123 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2124 : 0 : rte_flow_error_set(error, EINVAL,
2125 : : RTE_FLOW_ERROR_TYPE_ITEM,
2126 : : item, "Not supported by fdir filter");
2127 : 0 : return -rte_errno;
2128 : : }
2129 : 0 : rule->b_mask = TRUE;
2130 : : sctp_mask = item->mask;
2131 [ # # ]: 0 : if (sctp_mask->hdr.tag ||
2132 [ # # ]: 0 : sctp_mask->hdr.cksum) {
2133 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2134 : 0 : rte_flow_error_set(error, EINVAL,
2135 : : RTE_FLOW_ERROR_TYPE_ITEM,
2136 : : item, "Not supported by fdir filter");
2137 : 0 : return -rte_errno;
2138 : : }
2139 : 0 : rule->mask.src_port_mask = sctp_mask->hdr.src_port;
2140 : 0 : rule->mask.dst_port_mask = sctp_mask->hdr.dst_port;
2141 : :
2142 [ # # ]: 0 : if (item->spec) {
2143 : 0 : rule->b_spec = TRUE;
2144 : : sctp_spec = item->spec;
2145 : 0 : rule->ixgbe_fdir.formatted.src_port =
2146 : 0 : sctp_spec->hdr.src_port;
2147 : 0 : rule->ixgbe_fdir.formatted.dst_port =
2148 : 0 : sctp_spec->hdr.dst_port;
2149 : : }
2150 : : /* others even sctp port is not supported */
2151 : : } else {
2152 : 0 : sctp_mask = item->mask;
2153 [ # # ]: 0 : if (sctp_mask &&
2154 [ # # ]: 0 : (sctp_mask->hdr.src_port ||
2155 [ # # ]: 0 : sctp_mask->hdr.dst_port ||
2156 [ # # ]: 0 : sctp_mask->hdr.tag ||
2157 [ # # ]: 0 : sctp_mask->hdr.cksum)) {
2158 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2159 : 0 : rte_flow_error_set(error, EINVAL,
2160 : : RTE_FLOW_ERROR_TYPE_ITEM,
2161 : : item, "Not supported by fdir filter");
2162 : 0 : return -rte_errno;
2163 : : }
2164 : : }
2165 : :
2166 : : item = next_no_fuzzy_pattern(pattern, item);
2167 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2168 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2169 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2170 : 0 : rte_flow_error_set(error, EINVAL,
2171 : : RTE_FLOW_ERROR_TYPE_ITEM,
2172 : : item, "Not supported by fdir filter");
2173 : 0 : return -rte_errno;
2174 : : }
2175 : : }
2176 : :
2177 : : /* Get the flex byte info */
2178 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_RAW) {
2179 : : /* Not supported last point for range*/
2180 [ # # ]: 0 : if (item->last) {
2181 : 0 : rte_flow_error_set(error, EINVAL,
2182 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2183 : : item, "Not supported last point for range");
2184 : 0 : return -rte_errno;
2185 : : }
2186 : : /* mask should not be null */
2187 [ # # # # ]: 0 : if (!item->mask || !item->spec) {
2188 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2189 : 0 : rte_flow_error_set(error, EINVAL,
2190 : : RTE_FLOW_ERROR_TYPE_ITEM,
2191 : : item, "Not supported by fdir filter");
2192 : 0 : return -rte_errno;
2193 : : }
2194 : :
2195 : : raw_mask = item->mask;
2196 : :
2197 : : /* check mask */
2198 : 0 : if (raw_mask->relative != 0x1 ||
2199 : : raw_mask->search != 0x1 ||
2200 [ # # ]: 0 : raw_mask->reserved != 0x0 ||
2201 : : (uint32_t)raw_mask->offset != 0xffffffff ||
2202 [ # # ]: 0 : raw_mask->limit != 0xffff ||
2203 : : raw_mask->length != 0xffff) {
2204 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2205 : 0 : rte_flow_error_set(error, EINVAL,
2206 : : RTE_FLOW_ERROR_TYPE_ITEM,
2207 : : item, "Not supported by fdir filter");
2208 : 0 : return -rte_errno;
2209 : : }
2210 : :
2211 : : raw_spec = item->spec;
2212 : :
2213 : : /* check spec */
2214 : 0 : if (raw_spec->relative != 0 ||
2215 [ # # ]: 0 : raw_spec->search != 0 ||
2216 : 0 : raw_spec->reserved != 0 ||
2217 [ # # # # ]: 0 : raw_spec->offset > IXGBE_MAX_FLX_SOURCE_OFF ||
2218 : : raw_spec->offset % 2 ||
2219 [ # # ]: 0 : raw_spec->limit != 0 ||
2220 : 0 : raw_spec->length != 2 ||
2221 : : /* pattern can't be 0xffff */
2222 [ # # ]: 0 : (raw_spec->pattern[0] == 0xff &&
2223 [ # # ]: 0 : raw_spec->pattern[1] == 0xff)) {
2224 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2225 : 0 : rte_flow_error_set(error, EINVAL,
2226 : : RTE_FLOW_ERROR_TYPE_ITEM,
2227 : : item, "Not supported by fdir filter");
2228 : 0 : return -rte_errno;
2229 : : }
2230 : :
2231 : : /* check pattern mask */
2232 [ # # ]: 0 : if (raw_mask->pattern[0] != 0xff ||
2233 [ # # ]: 0 : raw_mask->pattern[1] != 0xff) {
2234 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2235 : 0 : rte_flow_error_set(error, EINVAL,
2236 : : RTE_FLOW_ERROR_TYPE_ITEM,
2237 : : item, "Not supported by fdir filter");
2238 : 0 : return -rte_errno;
2239 : : }
2240 : :
2241 : 0 : rule->mask.flex_bytes_mask = 0xffff;
2242 : 0 : rule->ixgbe_fdir.formatted.flex_bytes =
2243 : 0 : (((uint16_t)raw_spec->pattern[1]) << 8) |
2244 : 0 : raw_spec->pattern[0];
2245 : 0 : rule->flex_bytes_offset = raw_spec->offset;
2246 : : }
2247 : :
2248 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2249 : : /* check if the next not void item is END */
2250 : : item = next_no_fuzzy_pattern(pattern, item);
2251 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2252 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2253 : 0 : rte_flow_error_set(error, EINVAL,
2254 : : RTE_FLOW_ERROR_TYPE_ITEM,
2255 : : item, "Not supported by fdir filter");
2256 : 0 : return -rte_errno;
2257 : : }
2258 : : }
2259 : :
2260 : 0 : return ixgbe_parse_fdir_act_attr(attr, actions, rule, error);
2261 : : }
2262 : :
2263 : : #define NVGRE_PROTOCOL 0x6558
2264 : :
2265 : : /**
2266 : : * Parse the rule to see if it is a VxLAN or NVGRE flow director rule.
2267 : : * And get the flow director filter info BTW.
2268 : : * VxLAN PATTERN:
2269 : : * The first not void item must be ETH.
2270 : : * The second not void item must be IPV4/ IPV6.
2271 : : * The third not void item must be NVGRE.
2272 : : * The next not void item must be END.
2273 : : * NVGRE PATTERN:
2274 : : * The first not void item must be ETH.
2275 : : * The second not void item must be IPV4/ IPV6.
2276 : : * The third not void item must be NVGRE.
2277 : : * The next not void item must be END.
2278 : : * ACTION:
2279 : : * The first not void action should be QUEUE or DROP.
2280 : : * The second not void optional action should be MARK,
2281 : : * mark_id is a uint32_t number.
2282 : : * The next not void action should be END.
2283 : : * VxLAN pattern example:
2284 : : * ITEM Spec Mask
2285 : : * ETH NULL NULL
2286 : : * IPV4/IPV6 NULL NULL
2287 : : * UDP NULL NULL
2288 : : * VxLAN vni{0x00, 0x32, 0x54} {0xFF, 0xFF, 0xFF}
2289 : : * MAC VLAN tci 0x2016 0xEFFF
2290 : : * END
2291 : : * NEGRV pattern example:
2292 : : * ITEM Spec Mask
2293 : : * ETH NULL NULL
2294 : : * IPV4/IPV6 NULL NULL
2295 : : * NVGRE protocol 0x6558 0xFFFF
2296 : : * tni{0x00, 0x32, 0x54} {0xFF, 0xFF, 0xFF}
2297 : : * MAC VLAN tci 0x2016 0xEFFF
2298 : : * END
2299 : : * other members in mask and spec should set to 0x00.
2300 : : * item->last should be NULL.
2301 : : */
2302 : : static int
2303 : 0 : ixgbe_parse_fdir_filter_tunnel(const struct rte_flow_attr *attr,
2304 : : const struct rte_flow_item pattern[],
2305 : : const struct rte_flow_action actions[],
2306 : : struct ixgbe_fdir_rule *rule,
2307 : : struct rte_flow_error *error)
2308 : : {
2309 : : const struct rte_flow_item *item;
2310 : : const struct rte_flow_item_vxlan *vxlan_spec;
2311 : : const struct rte_flow_item_vxlan *vxlan_mask;
2312 : : const struct rte_flow_item_nvgre *nvgre_spec;
2313 : : const struct rte_flow_item_nvgre *nvgre_mask;
2314 : : const struct rte_flow_item_eth *eth_spec;
2315 : : const struct rte_flow_item_eth *eth_mask;
2316 : : const struct rte_flow_item_vlan *vlan_spec;
2317 : : const struct rte_flow_item_vlan *vlan_mask;
2318 : : uint32_t j;
2319 : :
2320 [ # # ]: 0 : if (!pattern) {
2321 : 0 : rte_flow_error_set(error, EINVAL,
2322 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
2323 : : NULL, "NULL pattern.");
2324 : 0 : return -rte_errno;
2325 : : }
2326 : :
2327 [ # # ]: 0 : if (!actions) {
2328 : 0 : rte_flow_error_set(error, EINVAL,
2329 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
2330 : : NULL, "NULL action.");
2331 : 0 : return -rte_errno;
2332 : : }
2333 : :
2334 [ # # ]: 0 : if (!attr) {
2335 : 0 : rte_flow_error_set(error, EINVAL,
2336 : : RTE_FLOW_ERROR_TYPE_ATTR,
2337 : : NULL, "NULL attribute.");
2338 : 0 : return -rte_errno;
2339 : : }
2340 : :
2341 : : /**
2342 : : * Some fields may not be provided. Set spec to 0 and mask to default
2343 : : * value. So, we need not do anything for the not provided fields later.
2344 : : */
2345 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2346 : 0 : memset(&rule->mask, 0xFF, sizeof(struct ixgbe_hw_fdir_mask));
2347 : 0 : rule->mask.vlan_tci_mask = 0;
2348 : :
2349 : : /**
2350 : : * The first not void item should be
2351 : : * MAC or IPv4 or IPv6 or UDP or VxLAN.
2352 : : */
2353 : : item = next_no_void_pattern(pattern, NULL);
2354 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
2355 : : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2356 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2357 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2358 : : item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2359 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE) {
2360 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2361 : 0 : rte_flow_error_set(error, EINVAL,
2362 : : RTE_FLOW_ERROR_TYPE_ITEM,
2363 : : item, "Not supported by fdir filter");
2364 : 0 : return -rte_errno;
2365 : : }
2366 : :
2367 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT_TUNNEL;
2368 : :
2369 : : /* Skip MAC. */
2370 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
2371 : : /* Only used to describe the protocol stack. */
2372 [ # # # # ]: 0 : if (item->spec || item->mask) {
2373 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2374 : 0 : rte_flow_error_set(error, EINVAL,
2375 : : RTE_FLOW_ERROR_TYPE_ITEM,
2376 : : item, "Not supported by fdir filter");
2377 : 0 : return -rte_errno;
2378 : : }
2379 : : /* Not supported last point for range*/
2380 [ # # ]: 0 : if (item->last) {
2381 : 0 : rte_flow_error_set(error, EINVAL,
2382 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2383 : : item, "Not supported last point for range");
2384 : 0 : return -rte_errno;
2385 : : }
2386 : :
2387 : : /* Check if the next not void item is IPv4 or IPv6. */
2388 : : item = next_no_void_pattern(pattern, item);
2389 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2390 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
2391 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2392 : 0 : rte_flow_error_set(error, EINVAL,
2393 : : RTE_FLOW_ERROR_TYPE_ITEM,
2394 : : item, "Not supported by fdir filter");
2395 : 0 : return -rte_errno;
2396 : : }
2397 : : }
2398 : :
2399 : : /* Skip IP. */
2400 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
2401 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
2402 : : /* Only used to describe the protocol stack. */
2403 [ # # # # ]: 0 : if (item->spec || item->mask) {
2404 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2405 : 0 : rte_flow_error_set(error, EINVAL,
2406 : : RTE_FLOW_ERROR_TYPE_ITEM,
2407 : : item, "Not supported by fdir filter");
2408 : 0 : return -rte_errno;
2409 : : }
2410 : : /*Not supported last point for range*/
2411 [ # # ]: 0 : if (item->last) {
2412 : 0 : rte_flow_error_set(error, EINVAL,
2413 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2414 : : item, "Not supported last point for range");
2415 : 0 : return -rte_errno;
2416 : : }
2417 : :
2418 : : /* Check if the next not void item is UDP or NVGRE. */
2419 : : item = next_no_void_pattern(pattern, item);
2420 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2421 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE) {
2422 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2423 : 0 : rte_flow_error_set(error, EINVAL,
2424 : : RTE_FLOW_ERROR_TYPE_ITEM,
2425 : : item, "Not supported by fdir filter");
2426 : 0 : return -rte_errno;
2427 : : }
2428 : : }
2429 : :
2430 : : /* Skip UDP. */
2431 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2432 : : /* Only used to describe the protocol stack. */
2433 [ # # # # ]: 0 : if (item->spec || item->mask) {
2434 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2435 : 0 : rte_flow_error_set(error, EINVAL,
2436 : : RTE_FLOW_ERROR_TYPE_ITEM,
2437 : : item, "Not supported by fdir filter");
2438 : 0 : return -rte_errno;
2439 : : }
2440 : : /*Not supported last point for range*/
2441 [ # # ]: 0 : if (item->last) {
2442 : 0 : rte_flow_error_set(error, EINVAL,
2443 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2444 : : item, "Not supported last point for range");
2445 : 0 : return -rte_errno;
2446 : : }
2447 : :
2448 : : /* Check if the next not void item is VxLAN. */
2449 : : item = next_no_void_pattern(pattern, item);
2450 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN) {
2451 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2452 : 0 : rte_flow_error_set(error, EINVAL,
2453 : : RTE_FLOW_ERROR_TYPE_ITEM,
2454 : : item, "Not supported by fdir filter");
2455 : 0 : return -rte_errno;
2456 : : }
2457 : : }
2458 : :
2459 : : /* Get the VxLAN info */
2460 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
2461 : 0 : rule->ixgbe_fdir.formatted.tunnel_type =
2462 : : IXGBE_FDIR_VXLAN_TUNNEL_TYPE;
2463 : :
2464 : : /* Only care about VNI, others should be masked. */
2465 [ # # ]: 0 : if (!item->mask) {
2466 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2467 : 0 : rte_flow_error_set(error, EINVAL,
2468 : : RTE_FLOW_ERROR_TYPE_ITEM,
2469 : : item, "Not supported by fdir filter");
2470 : 0 : return -rte_errno;
2471 : : }
2472 : : /*Not supported last point for range*/
2473 [ # # ]: 0 : if (item->last) {
2474 : 0 : rte_flow_error_set(error, EINVAL,
2475 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2476 : : item, "Not supported last point for range");
2477 : 0 : return -rte_errno;
2478 : : }
2479 : 0 : rule->b_mask = TRUE;
2480 : :
2481 : : /* Tunnel type is always meaningful. */
2482 : 0 : rule->mask.tunnel_type_mask = 1;
2483 : :
2484 : : vxlan_mask = item->mask;
2485 [ # # ]: 0 : if (vxlan_mask->hdr.flags) {
2486 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2487 : 0 : rte_flow_error_set(error, EINVAL,
2488 : : RTE_FLOW_ERROR_TYPE_ITEM,
2489 : : item, "Not supported by fdir filter");
2490 : 0 : return -rte_errno;
2491 : : }
2492 : : /* VNI must be totally masked or not. */
2493 [ # # # # ]: 0 : if ((vxlan_mask->hdr.vni[0] || vxlan_mask->hdr.vni[1] ||
2494 [ # # # # ]: 0 : vxlan_mask->hdr.vni[2]) &&
2495 : 0 : ((vxlan_mask->hdr.vni[0] != 0xFF) ||
2496 [ # # ]: 0 : (vxlan_mask->hdr.vni[1] != 0xFF) ||
2497 [ # # ]: 0 : (vxlan_mask->hdr.vni[2] != 0xFF))) {
2498 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2499 : 0 : rte_flow_error_set(error, EINVAL,
2500 : : RTE_FLOW_ERROR_TYPE_ITEM,
2501 : : item, "Not supported by fdir filter");
2502 : 0 : return -rte_errno;
2503 : : }
2504 : :
2505 [ # # ]: 0 : rte_memcpy(&rule->mask.tunnel_id_mask, vxlan_mask->hdr.vni,
2506 : : RTE_DIM(vxlan_mask->hdr.vni));
2507 : :
2508 [ # # ]: 0 : if (item->spec) {
2509 : 0 : rule->b_spec = TRUE;
2510 : : vxlan_spec = item->spec;
2511 : : rte_memcpy(((uint8_t *)
2512 : 0 : &rule->ixgbe_fdir.formatted.tni_vni),
2513 [ # # ]: 0 : vxlan_spec->hdr.vni, RTE_DIM(vxlan_spec->hdr.vni));
2514 : : }
2515 : : }
2516 : :
2517 : : /* Get the NVGRE info */
2518 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_NVGRE) {
2519 : 0 : rule->ixgbe_fdir.formatted.tunnel_type =
2520 : : IXGBE_FDIR_NVGRE_TUNNEL_TYPE;
2521 : :
2522 : : /**
2523 : : * Only care about flags0, flags1, protocol and TNI,
2524 : : * others should be masked.
2525 : : */
2526 [ # # ]: 0 : if (!item->mask) {
2527 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2528 : 0 : rte_flow_error_set(error, EINVAL,
2529 : : RTE_FLOW_ERROR_TYPE_ITEM,
2530 : : item, "Not supported by fdir filter");
2531 : 0 : return -rte_errno;
2532 : : }
2533 : : /*Not supported last point for range*/
2534 [ # # ]: 0 : if (item->last) {
2535 : 0 : rte_flow_error_set(error, EINVAL,
2536 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2537 : : item, "Not supported last point for range");
2538 : 0 : return -rte_errno;
2539 : : }
2540 : 0 : rule->b_mask = TRUE;
2541 : :
2542 : : /* Tunnel type is always meaningful. */
2543 : 0 : rule->mask.tunnel_type_mask = 1;
2544 : :
2545 : : nvgre_mask = item->mask;
2546 [ # # ]: 0 : if (nvgre_mask->flow_id) {
2547 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2548 : 0 : rte_flow_error_set(error, EINVAL,
2549 : : RTE_FLOW_ERROR_TYPE_ITEM,
2550 : : item, "Not supported by fdir filter");
2551 : 0 : return -rte_errno;
2552 : : }
2553 [ # # ]: 0 : if (nvgre_mask->protocol &&
2554 : : nvgre_mask->protocol != 0xFFFF) {
2555 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2556 : 0 : rte_flow_error_set(error, EINVAL,
2557 : : RTE_FLOW_ERROR_TYPE_ITEM,
2558 : : item, "Not supported by fdir filter");
2559 : 0 : return -rte_errno;
2560 : : }
2561 [ # # # # ]: 0 : if (nvgre_mask->c_k_s_rsvd0_ver &&
2562 : : nvgre_mask->c_k_s_rsvd0_ver !=
2563 : : rte_cpu_to_be_16(0xFFFF)) {
2564 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2565 : 0 : rte_flow_error_set(error, EINVAL,
2566 : : RTE_FLOW_ERROR_TYPE_ITEM,
2567 : : item, "Not supported by fdir filter");
2568 : 0 : return -rte_errno;
2569 : : }
2570 : : /* TNI must be totally masked or not. */
2571 [ # # ]: 0 : if (nvgre_mask->tni[0] &&
2572 [ # # ]: 0 : ((nvgre_mask->tni[0] != 0xFF) ||
2573 : 0 : (nvgre_mask->tni[1] != 0xFF) ||
2574 [ # # ]: 0 : (nvgre_mask->tni[2] != 0xFF))) {
2575 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2576 : 0 : rte_flow_error_set(error, EINVAL,
2577 : : RTE_FLOW_ERROR_TYPE_ITEM,
2578 : : item, "Not supported by fdir filter");
2579 : 0 : return -rte_errno;
2580 : : }
2581 : : /* tni is a 24-bits bit field */
2582 [ # # ]: 0 : rte_memcpy(&rule->mask.tunnel_id_mask, nvgre_mask->tni,
2583 : : RTE_DIM(nvgre_mask->tni));
2584 : 0 : rule->mask.tunnel_id_mask <<= 8;
2585 : :
2586 [ # # ]: 0 : if (item->spec) {
2587 : 0 : rule->b_spec = TRUE;
2588 : : nvgre_spec = item->spec;
2589 [ # # ]: 0 : if (nvgre_spec->c_k_s_rsvd0_ver !=
2590 : 0 : rte_cpu_to_be_16(0x2000) &&
2591 [ # # ]: 0 : nvgre_mask->c_k_s_rsvd0_ver) {
2592 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2593 : 0 : rte_flow_error_set(error, EINVAL,
2594 : : RTE_FLOW_ERROR_TYPE_ITEM,
2595 : : item, "Not supported by fdir filter");
2596 : 0 : return -rte_errno;
2597 : : }
2598 [ # # ]: 0 : if (nvgre_mask->protocol &&
2599 [ # # ]: 0 : nvgre_spec->protocol !=
2600 : : rte_cpu_to_be_16(NVGRE_PROTOCOL)) {
2601 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2602 : 0 : rte_flow_error_set(error, EINVAL,
2603 : : RTE_FLOW_ERROR_TYPE_ITEM,
2604 : : item, "Not supported by fdir filter");
2605 : 0 : return -rte_errno;
2606 : : }
2607 : : /* tni is a 24-bits bit field */
2608 : 0 : rte_memcpy(&rule->ixgbe_fdir.formatted.tni_vni,
2609 [ # # ]: 0 : nvgre_spec->tni, RTE_DIM(nvgre_spec->tni));
2610 : : }
2611 : : }
2612 : :
2613 : : /* check if the next not void item is MAC */
2614 : : item = next_no_void_pattern(pattern, item);
2615 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
2616 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2617 : 0 : rte_flow_error_set(error, EINVAL,
2618 : : RTE_FLOW_ERROR_TYPE_ITEM,
2619 : : item, "Not supported by fdir filter");
2620 : 0 : return -rte_errno;
2621 : : }
2622 : :
2623 : : /**
2624 : : * Only support vlan and dst MAC address,
2625 : : * others should be masked.
2626 : : */
2627 : :
2628 [ # # ]: 0 : if (!item->mask) {
2629 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2630 : 0 : rte_flow_error_set(error, EINVAL,
2631 : : RTE_FLOW_ERROR_TYPE_ITEM,
2632 : : item, "Not supported by fdir filter");
2633 : 0 : return -rte_errno;
2634 : : }
2635 : : /*Not supported last point for range*/
2636 [ # # ]: 0 : if (item->last) {
2637 : 0 : rte_flow_error_set(error, EINVAL,
2638 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2639 : : item, "Not supported last point for range");
2640 : 0 : return -rte_errno;
2641 : : }
2642 : 0 : rule->b_mask = TRUE;
2643 : : eth_mask = item->mask;
2644 : :
2645 : : /* Ether type should be masked. */
2646 [ # # ]: 0 : if (eth_mask->hdr.ether_type) {
2647 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2648 : 0 : rte_flow_error_set(error, EINVAL,
2649 : : RTE_FLOW_ERROR_TYPE_ITEM,
2650 : : item, "Not supported by fdir filter");
2651 : 0 : return -rte_errno;
2652 : : }
2653 : :
2654 : : /* src MAC address should be masked. */
2655 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
2656 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j]) {
2657 : : memset(rule, 0,
2658 : : sizeof(struct ixgbe_fdir_rule));
2659 : 0 : rte_flow_error_set(error, EINVAL,
2660 : : RTE_FLOW_ERROR_TYPE_ITEM,
2661 : : item, "Not supported by fdir filter");
2662 : 0 : return -rte_errno;
2663 : : }
2664 : : }
2665 : 0 : rule->mask.mac_addr_byte_mask = 0;
2666 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
2667 : : /* It's a per byte mask. */
2668 [ # # ]: 0 : if (eth_mask->hdr.dst_addr.addr_bytes[j] == 0xFF) {
2669 : 0 : rule->mask.mac_addr_byte_mask |= 0x1 << j;
2670 [ # # ]: 0 : } else if (eth_mask->hdr.dst_addr.addr_bytes[j]) {
2671 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2672 : 0 : rte_flow_error_set(error, EINVAL,
2673 : : RTE_FLOW_ERROR_TYPE_ITEM,
2674 : : item, "Not supported by fdir filter");
2675 : 0 : return -rte_errno;
2676 : : }
2677 : : }
2678 : :
2679 : : /* When no vlan, considered as full mask. */
2680 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
2681 : :
2682 [ # # ]: 0 : if (item->spec) {
2683 : 0 : rule->b_spec = TRUE;
2684 : : eth_spec = item->spec;
2685 : :
2686 : : /* Get the dst MAC. */
2687 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
2688 : 0 : rule->ixgbe_fdir.formatted.inner_mac[j] =
2689 : 0 : eth_spec->hdr.dst_addr.addr_bytes[j];
2690 : : }
2691 : : }
2692 : :
2693 : : /**
2694 : : * Check if the next not void item is vlan or ipv4.
2695 : : * IPv6 is not supported.
2696 : : */
2697 : : item = next_no_void_pattern(pattern, item);
2698 [ # # ]: 0 : if ((item->type != RTE_FLOW_ITEM_TYPE_VLAN) &&
2699 : : (item->type != RTE_FLOW_ITEM_TYPE_IPV4)) {
2700 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2701 : 0 : rte_flow_error_set(error, EINVAL,
2702 : : RTE_FLOW_ERROR_TYPE_ITEM,
2703 : : item, "Not supported by fdir filter");
2704 : 0 : return -rte_errno;
2705 : : }
2706 : : /*Not supported last point for range*/
2707 [ # # ]: 0 : if (item->last) {
2708 : 0 : rte_flow_error_set(error, EINVAL,
2709 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2710 : : item, "Not supported last point for range");
2711 : 0 : return -rte_errno;
2712 : : }
2713 : :
2714 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2715 [ # # # # ]: 0 : if (!(item->spec && item->mask)) {
2716 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2717 : 0 : rte_flow_error_set(error, EINVAL,
2718 : : RTE_FLOW_ERROR_TYPE_ITEM,
2719 : : item, "Not supported by fdir filter");
2720 : 0 : return -rte_errno;
2721 : : }
2722 : :
2723 : : vlan_spec = item->spec;
2724 : : vlan_mask = item->mask;
2725 : :
2726 : 0 : rule->ixgbe_fdir.formatted.vlan_id = vlan_spec->hdr.vlan_tci;
2727 : :
2728 : 0 : rule->mask.vlan_tci_mask = vlan_mask->hdr.vlan_tci;
2729 : 0 : rule->mask.vlan_tci_mask &= rte_cpu_to_be_16(0xEFFF);
2730 : : /* More than one tags are not supported. */
2731 : :
2732 : : /* check if the next not void item is END */
2733 : : item = next_no_void_pattern(pattern, item);
2734 : :
2735 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2736 : : memset(rule, 0, sizeof(struct ixgbe_fdir_rule));
2737 : 0 : rte_flow_error_set(error, EINVAL,
2738 : : RTE_FLOW_ERROR_TYPE_ITEM,
2739 : : item, "Not supported by fdir filter");
2740 : 0 : return -rte_errno;
2741 : : }
2742 : : }
2743 : :
2744 : : /**
2745 : : * If the tags is 0, it means don't care about the VLAN.
2746 : : * Do nothing.
2747 : : */
2748 : :
2749 : 0 : return ixgbe_parse_fdir_act_attr(attr, actions, rule, error);
2750 : : }
2751 : :
2752 : : static int
2753 : 0 : ixgbe_parse_fdir_filter(struct rte_eth_dev *dev,
2754 : : const struct rte_flow_attr *attr,
2755 : : const struct rte_flow_item pattern[],
2756 : : const struct rte_flow_action actions[],
2757 : : struct ixgbe_fdir_rule *rule,
2758 : : struct rte_flow_error *error)
2759 : : {
2760 : : int ret;
2761 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2762 : : struct rte_eth_fdir_conf *fdir_conf = IXGBE_DEV_FDIR_CONF(dev);
2763 : 0 : fdir_conf->drop_queue = IXGBE_FDIR_DROP_QUEUE;
2764 : :
2765 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82599EB &&
2766 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X540 &&
2767 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550 &&
2768 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
2769 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
2770 : : hw->mac.type != ixgbe_mac_E610)
2771 : : return -ENOTSUP;
2772 : :
2773 : 0 : ret = ixgbe_parse_fdir_filter_normal(dev, attr, pattern,
2774 : : actions, rule, error);
2775 : :
2776 [ # # ]: 0 : if (!ret)
2777 : 0 : goto step_next;
2778 : :
2779 : 0 : ret = ixgbe_parse_fdir_filter_tunnel(attr, pattern,
2780 : : actions, rule, error);
2781 : :
2782 [ # # ]: 0 : if (ret)
2783 : : return ret;
2784 : :
2785 : 0 : step_next:
2786 : :
2787 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB &&
2788 [ # # ]: 0 : rule->fdirflags == IXGBE_FDIRCMD_DROP &&
2789 [ # # ]: 0 : (rule->ixgbe_fdir.formatted.src_port != 0 ||
2790 : : rule->ixgbe_fdir.formatted.dst_port != 0))
2791 : : return -ENOTSUP;
2792 : :
2793 [ # # ]: 0 : if (fdir_conf->mode == RTE_FDIR_MODE_NONE) {
2794 : 0 : fdir_conf->mode = rule->mode;
2795 : 0 : ret = ixgbe_fdir_configure(dev);
2796 [ # # ]: 0 : if (ret) {
2797 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
2798 : 0 : return ret;
2799 : : }
2800 [ # # ]: 0 : } else if (fdir_conf->mode != rule->mode) {
2801 : : return -ENOTSUP;
2802 : : }
2803 : :
2804 [ # # ]: 0 : if (rule->queue >= dev->data->nb_rx_queues)
2805 : 0 : return -ENOTSUP;
2806 : :
2807 : : return ret;
2808 : : }
2809 : :
2810 : : static int
2811 : 0 : ixgbe_parse_rss_filter(struct rte_eth_dev *dev,
2812 : : const struct rte_flow_attr *attr,
2813 : : const struct rte_flow_action actions[],
2814 : : struct ixgbe_rte_flow_rss_conf *rss_conf,
2815 : : struct rte_flow_error *error)
2816 : : {
2817 : : const struct rte_flow_action *act;
2818 : : const struct rte_flow_action_rss *rss;
2819 : : uint16_t n;
2820 : :
2821 : : /**
2822 : : * rss only supports forwarding,
2823 : : * check if the first not void action is RSS.
2824 : : */
2825 : : act = next_no_void_action(actions, NULL);
2826 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
2827 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2828 : 0 : rte_flow_error_set(error, EINVAL,
2829 : : RTE_FLOW_ERROR_TYPE_ACTION,
2830 : : act, "Not supported action.");
2831 : 0 : return -rte_errno;
2832 : : }
2833 : :
2834 : 0 : rss = (const struct rte_flow_action_rss *)act->conf;
2835 : :
2836 [ # # # # ]: 0 : if (!rss || !rss->queue_num) {
2837 : 0 : rte_flow_error_set(error, EINVAL,
2838 : : RTE_FLOW_ERROR_TYPE_ACTION,
2839 : : act,
2840 : : "no valid queues");
2841 : 0 : return -rte_errno;
2842 : : }
2843 : :
2844 [ # # ]: 0 : for (n = 0; n < rss->queue_num; n++) {
2845 [ # # ]: 0 : if (rss->queue[n] >= dev->data->nb_rx_queues) {
2846 : 0 : rte_flow_error_set(error, EINVAL,
2847 : : RTE_FLOW_ERROR_TYPE_ACTION,
2848 : : act,
2849 : : "queue id > max number of queues");
2850 : 0 : return -rte_errno;
2851 : : }
2852 : : }
2853 : :
2854 [ # # ]: 0 : if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
2855 : 0 : return rte_flow_error_set
2856 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2857 : : "non-default RSS hash functions are not supported");
2858 [ # # ]: 0 : if (rss->level)
2859 : 0 : return rte_flow_error_set
2860 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2861 : : "a nonzero RSS encapsulation level is not supported");
2862 [ # # ]: 0 : if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
2863 : 0 : return rte_flow_error_set
2864 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2865 : : "RSS hash key must be exactly 40 bytes");
2866 [ # # ]: 0 : if (rss->queue_num > RTE_DIM(rss_conf->queue))
2867 : 0 : return rte_flow_error_set
2868 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2869 : : "too many queues for RSS context");
2870 [ # # ]: 0 : if (ixgbe_rss_conf_init(rss_conf, rss))
2871 : 0 : return rte_flow_error_set
2872 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, act,
2873 : : "RSS context initialization failure");
2874 : :
2875 : : /* check if the next not void item is END */
2876 : : act = next_no_void_action(actions, act);
2877 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
2878 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2879 : 0 : rte_flow_error_set(error, EINVAL,
2880 : : RTE_FLOW_ERROR_TYPE_ACTION,
2881 : : act, "Not supported action.");
2882 : 0 : return -rte_errno;
2883 : : }
2884 : :
2885 : : /* parse attr */
2886 : : /* must be input direction */
2887 [ # # ]: 0 : if (!attr->ingress) {
2888 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2889 : 0 : rte_flow_error_set(error, EINVAL,
2890 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2891 : : attr, "Only support ingress.");
2892 : 0 : return -rte_errno;
2893 : : }
2894 : :
2895 : : /* not supported */
2896 [ # # ]: 0 : if (attr->egress) {
2897 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2898 : 0 : rte_flow_error_set(error, EINVAL,
2899 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2900 : : attr, "Not support egress.");
2901 : 0 : return -rte_errno;
2902 : : }
2903 : :
2904 : : /* not supported */
2905 [ # # ]: 0 : if (attr->transfer) {
2906 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2907 : 0 : rte_flow_error_set(error, EINVAL,
2908 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2909 : : attr, "No support for transfer.");
2910 : 0 : return -rte_errno;
2911 : : }
2912 : :
2913 [ # # ]: 0 : if (attr->priority > 0xFFFF) {
2914 : : memset(rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
2915 : 0 : rte_flow_error_set(error, EINVAL,
2916 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2917 : : attr, "Error priority.");
2918 : 0 : return -rte_errno;
2919 : : }
2920 : :
2921 : : return 0;
2922 : : }
2923 : :
2924 : : /* remove the rss filter */
2925 : : static void
2926 : : ixgbe_clear_rss_filter(struct rte_eth_dev *dev)
2927 : : {
2928 : : struct ixgbe_filter_info *filter_info =
2929 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2930 : :
2931 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
2932 : 0 : ixgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
2933 : : }
2934 : :
2935 : : void
2936 : 0 : ixgbe_filterlist_init(void)
2937 : : {
2938 : 0 : TAILQ_INIT(&filter_ntuple_list);
2939 : 0 : TAILQ_INIT(&filter_ethertype_list);
2940 : 0 : TAILQ_INIT(&filter_syn_list);
2941 : 0 : TAILQ_INIT(&filter_fdir_list);
2942 : 0 : TAILQ_INIT(&filter_l2_tunnel_list);
2943 : 0 : TAILQ_INIT(&filter_rss_list);
2944 : 0 : TAILQ_INIT(&ixgbe_flow_list);
2945 : 0 : }
2946 : :
2947 : : void
2948 : 0 : ixgbe_filterlist_flush(void)
2949 : : {
2950 : : struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
2951 : : struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
2952 : : struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
2953 : : struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
2954 : : struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
2955 : : struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
2956 : : struct ixgbe_rss_conf_ele *rss_filter_ptr;
2957 : :
2958 [ # # ]: 0 : while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
2959 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
2960 : : ntuple_filter_ptr,
2961 : : entries);
2962 : 0 : rte_free(ntuple_filter_ptr);
2963 : : }
2964 : :
2965 [ # # ]: 0 : while ((ethertype_filter_ptr = TAILQ_FIRST(&filter_ethertype_list))) {
2966 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
2967 : : ethertype_filter_ptr,
2968 : : entries);
2969 : 0 : rte_free(ethertype_filter_ptr);
2970 : : }
2971 : :
2972 [ # # ]: 0 : while ((syn_filter_ptr = TAILQ_FIRST(&filter_syn_list))) {
2973 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
2974 : : syn_filter_ptr,
2975 : : entries);
2976 : 0 : rte_free(syn_filter_ptr);
2977 : : }
2978 : :
2979 [ # # ]: 0 : while ((l2_tn_filter_ptr = TAILQ_FIRST(&filter_l2_tunnel_list))) {
2980 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
2981 : : l2_tn_filter_ptr,
2982 : : entries);
2983 : 0 : rte_free(l2_tn_filter_ptr);
2984 : : }
2985 : :
2986 [ # # ]: 0 : while ((fdir_rule_ptr = TAILQ_FIRST(&filter_fdir_list))) {
2987 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
2988 : : fdir_rule_ptr,
2989 : : entries);
2990 : 0 : rte_free(fdir_rule_ptr);
2991 : : }
2992 : :
2993 [ # # ]: 0 : while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
2994 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
2995 : : rss_filter_ptr,
2996 : : entries);
2997 : 0 : rte_free(rss_filter_ptr);
2998 : : }
2999 : :
3000 [ # # ]: 0 : while ((ixgbe_flow_mem_ptr = TAILQ_FIRST(&ixgbe_flow_list))) {
3001 [ # # ]: 0 : TAILQ_REMOVE(&ixgbe_flow_list,
3002 : : ixgbe_flow_mem_ptr,
3003 : : entries);
3004 : 0 : rte_free(ixgbe_flow_mem_ptr->flow);
3005 : 0 : rte_free(ixgbe_flow_mem_ptr);
3006 : : }
3007 : 0 : }
3008 : :
3009 : : /**
3010 : : * Create or destroy a flow rule.
3011 : : * Theorically one rule can match more than one filters.
3012 : : * We will let it use the filter which it hitt first.
3013 : : * So, the sequence matters.
3014 : : */
3015 : : static struct rte_flow *
3016 : 0 : ixgbe_flow_create(struct rte_eth_dev *dev,
3017 : : const struct rte_flow_attr *attr,
3018 : : const struct rte_flow_item pattern[],
3019 : : const struct rte_flow_action actions[],
3020 : : struct rte_flow_error *error)
3021 : : {
3022 : : int ret;
3023 : : struct rte_eth_ntuple_filter ntuple_filter;
3024 : : struct rte_eth_ethertype_filter ethertype_filter;
3025 : : struct rte_eth_syn_filter syn_filter;
3026 : : struct ixgbe_fdir_rule fdir_rule;
3027 : : struct ixgbe_l2_tunnel_conf l2_tn_filter;
3028 : : struct ixgbe_hw_fdir_info *fdir_info =
3029 : 0 : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
3030 : : struct ixgbe_rte_flow_rss_conf rss_conf;
3031 : : struct rte_flow *flow = NULL;
3032 : : struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
3033 : : struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
3034 : : struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
3035 : : struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3036 : : struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
3037 : : struct ixgbe_rss_conf_ele *rss_filter_ptr;
3038 : : struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
3039 : : uint8_t first_mask = FALSE;
3040 : :
3041 : 0 : flow = rte_zmalloc("ixgbe_rte_flow", sizeof(struct rte_flow), 0);
3042 [ # # ]: 0 : if (!flow) {
3043 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3044 : 0 : return (struct rte_flow *)flow;
3045 : : }
3046 : 0 : ixgbe_flow_mem_ptr = rte_zmalloc("ixgbe_flow_mem",
3047 : : sizeof(struct ixgbe_flow_mem), 0);
3048 [ # # ]: 0 : if (!ixgbe_flow_mem_ptr) {
3049 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3050 : 0 : rte_free(flow);
3051 : 0 : return NULL;
3052 : : }
3053 : 0 : ixgbe_flow_mem_ptr->flow = flow;
3054 : 0 : TAILQ_INSERT_TAIL(&ixgbe_flow_list,
3055 : : ixgbe_flow_mem_ptr, entries);
3056 : :
3057 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3058 : 0 : ret = ixgbe_parse_ntuple_filter(dev, attr, pattern,
3059 : : actions, &ntuple_filter, error);
3060 : :
3061 : : #ifdef RTE_LIB_SECURITY
3062 : : /* ESP flow not really a flow*/
3063 [ # # ]: 0 : if (ntuple_filter.proto == IPPROTO_ESP)
3064 : : return flow;
3065 : : #endif
3066 : :
3067 [ # # ]: 0 : if (!ret) {
3068 : 0 : ret = ixgbe_add_del_ntuple_filter(dev, &ntuple_filter, TRUE);
3069 [ # # ]: 0 : if (!ret) {
3070 : 0 : ntuple_filter_ptr = rte_zmalloc("ixgbe_ntuple_filter",
3071 : : sizeof(struct ixgbe_ntuple_filter_ele), 0);
3072 [ # # ]: 0 : if (!ntuple_filter_ptr) {
3073 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3074 : 0 : goto out;
3075 : : }
3076 [ # # ]: 0 : rte_memcpy(&ntuple_filter_ptr->filter_info,
3077 : : &ntuple_filter,
3078 : : sizeof(struct rte_eth_ntuple_filter));
3079 : 0 : TAILQ_INSERT_TAIL(&filter_ntuple_list,
3080 : : ntuple_filter_ptr, entries);
3081 : 0 : flow->rule = ntuple_filter_ptr;
3082 : 0 : flow->filter_type = RTE_ETH_FILTER_NTUPLE;
3083 : 0 : return flow;
3084 : : }
3085 : 0 : goto out;
3086 : : }
3087 : :
3088 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3089 : 0 : ret = ixgbe_parse_ethertype_filter(dev, attr, pattern,
3090 : : actions, ðertype_filter, error);
3091 [ # # ]: 0 : if (!ret) {
3092 : 0 : ret = ixgbe_add_del_ethertype_filter(dev,
3093 : : ðertype_filter, TRUE);
3094 [ # # ]: 0 : if (!ret) {
3095 : 0 : ethertype_filter_ptr = rte_zmalloc(
3096 : : "ixgbe_ethertype_filter",
3097 : : sizeof(struct ixgbe_ethertype_filter_ele), 0);
3098 [ # # ]: 0 : if (!ethertype_filter_ptr) {
3099 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3100 : 0 : goto out;
3101 : : }
3102 [ # # ]: 0 : rte_memcpy(ðertype_filter_ptr->filter_info,
3103 : : ðertype_filter,
3104 : : sizeof(struct rte_eth_ethertype_filter));
3105 : 0 : TAILQ_INSERT_TAIL(&filter_ethertype_list,
3106 : : ethertype_filter_ptr, entries);
3107 : 0 : flow->rule = ethertype_filter_ptr;
3108 : 0 : flow->filter_type = RTE_ETH_FILTER_ETHERTYPE;
3109 : 0 : return flow;
3110 : : }
3111 : 0 : goto out;
3112 : : }
3113 : :
3114 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3115 : 0 : ret = ixgbe_parse_syn_filter(dev, attr, pattern,
3116 : : actions, &syn_filter, error);
3117 [ # # ]: 0 : if (!ret) {
3118 : 0 : ret = ixgbe_syn_filter_set(dev, &syn_filter, TRUE);
3119 [ # # ]: 0 : if (!ret) {
3120 : 0 : syn_filter_ptr = rte_zmalloc("ixgbe_syn_filter",
3121 : : sizeof(struct ixgbe_eth_syn_filter_ele), 0);
3122 [ # # ]: 0 : if (!syn_filter_ptr) {
3123 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3124 : 0 : goto out;
3125 : : }
3126 [ # # ]: 0 : rte_memcpy(&syn_filter_ptr->filter_info,
3127 : : &syn_filter,
3128 : : sizeof(struct rte_eth_syn_filter));
3129 : 0 : TAILQ_INSERT_TAIL(&filter_syn_list,
3130 : : syn_filter_ptr,
3131 : : entries);
3132 : 0 : flow->rule = syn_filter_ptr;
3133 : 0 : flow->filter_type = RTE_ETH_FILTER_SYN;
3134 : 0 : return flow;
3135 : : }
3136 : 0 : goto out;
3137 : : }
3138 : :
3139 : : memset(&fdir_rule, 0, sizeof(struct ixgbe_fdir_rule));
3140 : 0 : ret = ixgbe_parse_fdir_filter(dev, attr, pattern,
3141 : : actions, &fdir_rule, error);
3142 [ # # ]: 0 : if (!ret) {
3143 : : /* A mask cannot be deleted. */
3144 [ # # ]: 0 : if (fdir_rule.b_mask) {
3145 [ # # ]: 0 : if (!fdir_info->mask_added) {
3146 : : /* It's the first time the mask is set. */
3147 [ # # ]: 0 : rte_memcpy(&fdir_info->mask,
3148 : : &fdir_rule.mask,
3149 : : sizeof(struct ixgbe_hw_fdir_mask));
3150 : :
3151 [ # # ]: 0 : if (fdir_rule.mask.flex_bytes_mask) {
3152 : 0 : ret = ixgbe_fdir_set_flexbytes_offset(dev,
3153 : 0 : fdir_rule.flex_bytes_offset);
3154 [ # # ]: 0 : if (ret)
3155 : 0 : goto out;
3156 : : }
3157 : 0 : ret = ixgbe_fdir_set_input_mask(dev);
3158 [ # # ]: 0 : if (ret)
3159 : 0 : goto out;
3160 : :
3161 : 0 : fdir_info->mask_added = TRUE;
3162 : : first_mask = TRUE;
3163 : : } else {
3164 : : /**
3165 : : * Only support one global mask,
3166 : : * all the masks should be the same.
3167 : : */
3168 : 0 : ret = memcmp(&fdir_info->mask,
3169 : : &fdir_rule.mask,
3170 : : sizeof(struct ixgbe_hw_fdir_mask));
3171 [ # # ]: 0 : if (ret)
3172 : 0 : goto out;
3173 : :
3174 [ # # ]: 0 : if (fdir_rule.mask.flex_bytes_mask &&
3175 : 0 : fdir_info->flex_bytes_offset !=
3176 [ # # ]: 0 : fdir_rule.flex_bytes_offset)
3177 : 0 : goto out;
3178 : : }
3179 : : }
3180 : :
3181 [ # # ]: 0 : if (fdir_rule.b_spec) {
3182 : 0 : ret = ixgbe_fdir_filter_program(dev, &fdir_rule,
3183 : : FALSE, FALSE);
3184 [ # # ]: 0 : if (!ret) {
3185 : 0 : fdir_rule_ptr = rte_zmalloc("ixgbe_fdir_filter",
3186 : : sizeof(struct ixgbe_fdir_rule_ele), 0);
3187 [ # # ]: 0 : if (!fdir_rule_ptr) {
3188 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3189 : 0 : goto out;
3190 : : }
3191 [ # # ]: 0 : rte_memcpy(&fdir_rule_ptr->filter_info,
3192 : : &fdir_rule,
3193 : : sizeof(struct ixgbe_fdir_rule));
3194 : 0 : TAILQ_INSERT_TAIL(&filter_fdir_list,
3195 : : fdir_rule_ptr, entries);
3196 : 0 : flow->rule = fdir_rule_ptr;
3197 : 0 : flow->filter_type = RTE_ETH_FILTER_FDIR;
3198 : :
3199 : 0 : return flow;
3200 : : }
3201 : :
3202 : : if (ret) {
3203 : : /**
3204 : : * clean the mask_added flag if fail to
3205 : : * program
3206 : : **/
3207 [ # # ]: 0 : if (first_mask)
3208 : 0 : fdir_info->mask_added = FALSE;
3209 : 0 : goto out;
3210 : : }
3211 : : }
3212 : :
3213 : 0 : goto out;
3214 : : }
3215 : :
3216 : : memset(&l2_tn_filter, 0, sizeof(struct ixgbe_l2_tunnel_conf));
3217 : 0 : ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
3218 : : actions, &l2_tn_filter, error);
3219 [ # # ]: 0 : if (!ret) {
3220 : 0 : ret = ixgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_filter, FALSE);
3221 [ # # ]: 0 : if (!ret) {
3222 : 0 : l2_tn_filter_ptr = rte_zmalloc("ixgbe_l2_tn_filter",
3223 : : sizeof(struct ixgbe_eth_l2_tunnel_conf_ele), 0);
3224 [ # # ]: 0 : if (!l2_tn_filter_ptr) {
3225 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3226 : 0 : goto out;
3227 : : }
3228 [ # # ]: 0 : rte_memcpy(&l2_tn_filter_ptr->filter_info,
3229 : : &l2_tn_filter,
3230 : : sizeof(struct ixgbe_l2_tunnel_conf));
3231 : 0 : TAILQ_INSERT_TAIL(&filter_l2_tunnel_list,
3232 : : l2_tn_filter_ptr, entries);
3233 : 0 : flow->rule = l2_tn_filter_ptr;
3234 : 0 : flow->filter_type = RTE_ETH_FILTER_L2_TUNNEL;
3235 : 0 : return flow;
3236 : : }
3237 : : }
3238 : :
3239 : : memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
3240 : 0 : ret = ixgbe_parse_rss_filter(dev, attr,
3241 : : actions, &rss_conf, error);
3242 [ # # ]: 0 : if (!ret) {
3243 : 0 : ret = ixgbe_config_rss_filter(dev, &rss_conf, TRUE);
3244 [ # # ]: 0 : if (!ret) {
3245 : 0 : rss_filter_ptr = rte_zmalloc("ixgbe_rss_filter",
3246 : : sizeof(struct ixgbe_rss_conf_ele), 0);
3247 [ # # ]: 0 : if (!rss_filter_ptr) {
3248 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3249 : 0 : goto out;
3250 : : }
3251 : 0 : ixgbe_rss_conf_init(&rss_filter_ptr->filter_info,
3252 : : &rss_conf.conf);
3253 : 0 : TAILQ_INSERT_TAIL(&filter_rss_list,
3254 : : rss_filter_ptr, entries);
3255 : 0 : flow->rule = rss_filter_ptr;
3256 : 0 : flow->filter_type = RTE_ETH_FILTER_HASH;
3257 : 0 : return flow;
3258 : : }
3259 : : }
3260 : :
3261 : 0 : out:
3262 [ # # ]: 0 : TAILQ_REMOVE(&ixgbe_flow_list,
3263 : : ixgbe_flow_mem_ptr, entries);
3264 : 0 : rte_flow_error_set(error, -ret,
3265 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
3266 : : "Failed to create flow.");
3267 : 0 : rte_free(ixgbe_flow_mem_ptr);
3268 : 0 : rte_free(flow);
3269 : 0 : return NULL;
3270 : : }
3271 : :
3272 : : /**
3273 : : * Check if the flow rule is supported by ixgbe.
3274 : : * It only checks the format. Don't guarantee the rule can be programmed into
3275 : : * the HW. Because there can be no enough room for the rule.
3276 : : */
3277 : : static int
3278 : 0 : ixgbe_flow_validate(struct rte_eth_dev *dev,
3279 : : const struct rte_flow_attr *attr,
3280 : : const struct rte_flow_item pattern[],
3281 : : const struct rte_flow_action actions[],
3282 : : struct rte_flow_error *error)
3283 : : {
3284 : : struct rte_eth_ntuple_filter ntuple_filter;
3285 : : struct rte_eth_ethertype_filter ethertype_filter;
3286 : : struct rte_eth_syn_filter syn_filter;
3287 : : struct ixgbe_l2_tunnel_conf l2_tn_filter;
3288 : : struct ixgbe_fdir_rule fdir_rule;
3289 : : struct ixgbe_rte_flow_rss_conf rss_conf;
3290 : : int ret;
3291 : :
3292 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3293 : 0 : ret = ixgbe_parse_ntuple_filter(dev, attr, pattern,
3294 : : actions, &ntuple_filter, error);
3295 [ # # ]: 0 : if (!ret)
3296 : : return 0;
3297 : :
3298 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3299 : 0 : ret = ixgbe_parse_ethertype_filter(dev, attr, pattern,
3300 : : actions, ðertype_filter, error);
3301 [ # # ]: 0 : if (!ret)
3302 : : return 0;
3303 : :
3304 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3305 : 0 : ret = ixgbe_parse_syn_filter(dev, attr, pattern,
3306 : : actions, &syn_filter, error);
3307 [ # # ]: 0 : if (!ret)
3308 : : return 0;
3309 : :
3310 : : memset(&fdir_rule, 0, sizeof(struct ixgbe_fdir_rule));
3311 : 0 : ret = ixgbe_parse_fdir_filter(dev, attr, pattern,
3312 : : actions, &fdir_rule, error);
3313 [ # # ]: 0 : if (!ret)
3314 : : return 0;
3315 : :
3316 : : memset(&l2_tn_filter, 0, sizeof(struct ixgbe_l2_tunnel_conf));
3317 : 0 : ret = ixgbe_parse_l2_tn_filter(dev, attr, pattern,
3318 : : actions, &l2_tn_filter, error);
3319 [ # # ]: 0 : if (!ret)
3320 : : return 0;
3321 : :
3322 : : memset(&rss_conf, 0, sizeof(struct ixgbe_rte_flow_rss_conf));
3323 : 0 : ret = ixgbe_parse_rss_filter(dev, attr,
3324 : : actions, &rss_conf, error);
3325 : :
3326 : 0 : return ret;
3327 : : }
3328 : :
3329 : : /* Destroy a flow rule on ixgbe. */
3330 : : static int
3331 : 0 : ixgbe_flow_destroy(struct rte_eth_dev *dev,
3332 : : struct rte_flow *flow,
3333 : : struct rte_flow_error *error)
3334 : : {
3335 : : int ret;
3336 : : struct rte_flow *pmd_flow = flow;
3337 : 0 : enum rte_filter_type filter_type = pmd_flow->filter_type;
3338 : : struct rte_eth_ntuple_filter ntuple_filter;
3339 : : struct rte_eth_ethertype_filter ethertype_filter;
3340 : : struct rte_eth_syn_filter syn_filter;
3341 : : struct ixgbe_fdir_rule fdir_rule;
3342 : : struct ixgbe_l2_tunnel_conf l2_tn_filter;
3343 : : struct ixgbe_ntuple_filter_ele *ntuple_filter_ptr;
3344 : : struct ixgbe_ethertype_filter_ele *ethertype_filter_ptr;
3345 : : struct ixgbe_eth_syn_filter_ele *syn_filter_ptr;
3346 : : struct ixgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3347 : : struct ixgbe_fdir_rule_ele *fdir_rule_ptr;
3348 : : struct ixgbe_flow_mem *ixgbe_flow_mem_ptr;
3349 : : struct ixgbe_hw_fdir_info *fdir_info =
3350 : 0 : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(dev->data->dev_private);
3351 : : struct ixgbe_rss_conf_ele *rss_filter_ptr;
3352 : :
3353 [ # # # # : 0 : switch (filter_type) {
# # # ]
3354 : 0 : case RTE_ETH_FILTER_NTUPLE:
3355 : 0 : ntuple_filter_ptr = (struct ixgbe_ntuple_filter_ele *)
3356 : : pmd_flow->rule;
3357 : : rte_memcpy(&ntuple_filter,
3358 [ # # ]: 0 : &ntuple_filter_ptr->filter_info,
3359 : : sizeof(struct rte_eth_ntuple_filter));
3360 : 0 : ret = ixgbe_add_del_ntuple_filter(dev, &ntuple_filter, FALSE);
3361 [ # # ]: 0 : if (!ret) {
3362 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
3363 : : ntuple_filter_ptr, entries);
3364 : 0 : rte_free(ntuple_filter_ptr);
3365 : : }
3366 : : break;
3367 : 0 : case RTE_ETH_FILTER_ETHERTYPE:
3368 : 0 : ethertype_filter_ptr = (struct ixgbe_ethertype_filter_ele *)
3369 : : pmd_flow->rule;
3370 : : rte_memcpy(ðertype_filter,
3371 [ # # ]: 0 : ðertype_filter_ptr->filter_info,
3372 : : sizeof(struct rte_eth_ethertype_filter));
3373 : 0 : ret = ixgbe_add_del_ethertype_filter(dev,
3374 : : ðertype_filter, FALSE);
3375 [ # # ]: 0 : if (!ret) {
3376 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
3377 : : ethertype_filter_ptr, entries);
3378 : 0 : rte_free(ethertype_filter_ptr);
3379 : : }
3380 : : break;
3381 : 0 : case RTE_ETH_FILTER_SYN:
3382 : 0 : syn_filter_ptr = (struct ixgbe_eth_syn_filter_ele *)
3383 : : pmd_flow->rule;
3384 : : rte_memcpy(&syn_filter,
3385 [ # # ]: 0 : &syn_filter_ptr->filter_info,
3386 : : sizeof(struct rte_eth_syn_filter));
3387 : 0 : ret = ixgbe_syn_filter_set(dev, &syn_filter, FALSE);
3388 [ # # ]: 0 : if (!ret) {
3389 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
3390 : : syn_filter_ptr, entries);
3391 : 0 : rte_free(syn_filter_ptr);
3392 : : }
3393 : : break;
3394 : 0 : case RTE_ETH_FILTER_FDIR:
3395 : 0 : fdir_rule_ptr = (struct ixgbe_fdir_rule_ele *)pmd_flow->rule;
3396 : : rte_memcpy(&fdir_rule,
3397 [ # # ]: 0 : &fdir_rule_ptr->filter_info,
3398 : : sizeof(struct ixgbe_fdir_rule));
3399 : 0 : ret = ixgbe_fdir_filter_program(dev, &fdir_rule, TRUE, FALSE);
3400 [ # # ]: 0 : if (!ret) {
3401 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
3402 : : fdir_rule_ptr, entries);
3403 : 0 : rte_free(fdir_rule_ptr);
3404 [ # # ]: 0 : if (TAILQ_EMPTY(&filter_fdir_list))
3405 : 0 : fdir_info->mask_added = false;
3406 : : }
3407 : : break;
3408 : 0 : case RTE_ETH_FILTER_L2_TUNNEL:
3409 : 0 : l2_tn_filter_ptr = (struct ixgbe_eth_l2_tunnel_conf_ele *)
3410 : : pmd_flow->rule;
3411 [ # # ]: 0 : rte_memcpy(&l2_tn_filter, &l2_tn_filter_ptr->filter_info,
3412 : : sizeof(struct ixgbe_l2_tunnel_conf));
3413 : 0 : ret = ixgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_filter);
3414 [ # # ]: 0 : if (!ret) {
3415 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
3416 : : l2_tn_filter_ptr, entries);
3417 : 0 : rte_free(l2_tn_filter_ptr);
3418 : : }
3419 : : break;
3420 : 0 : case RTE_ETH_FILTER_HASH:
3421 : 0 : rss_filter_ptr = (struct ixgbe_rss_conf_ele *)
3422 : : pmd_flow->rule;
3423 : 0 : ret = ixgbe_config_rss_filter(dev,
3424 : : &rss_filter_ptr->filter_info, FALSE);
3425 [ # # ]: 0 : if (!ret) {
3426 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
3427 : : rss_filter_ptr, entries);
3428 : 0 : rte_free(rss_filter_ptr);
3429 : : }
3430 : : break;
3431 : 0 : default:
3432 : 0 : PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3433 : : filter_type);
3434 : : ret = -EINVAL;
3435 : : break;
3436 : : }
3437 : :
3438 [ # # ]: 0 : if (ret) {
3439 : 0 : rte_flow_error_set(error, EINVAL,
3440 : : RTE_FLOW_ERROR_TYPE_HANDLE,
3441 : : NULL, "Failed to destroy flow");
3442 : 0 : return ret;
3443 : : }
3444 : :
3445 [ # # ]: 0 : TAILQ_FOREACH(ixgbe_flow_mem_ptr, &ixgbe_flow_list, entries) {
3446 [ # # ]: 0 : if (ixgbe_flow_mem_ptr->flow == pmd_flow) {
3447 [ # # ]: 0 : TAILQ_REMOVE(&ixgbe_flow_list,
3448 : : ixgbe_flow_mem_ptr, entries);
3449 : 0 : rte_free(ixgbe_flow_mem_ptr);
3450 : 0 : break;
3451 : : }
3452 : : }
3453 : 0 : rte_free(flow);
3454 : :
3455 : 0 : return ret;
3456 : : }
3457 : :
3458 : : /* Destroy all flow rules associated with a port on ixgbe. */
3459 : : static int
3460 : 0 : ixgbe_flow_flush(struct rte_eth_dev *dev,
3461 : : struct rte_flow_error *error)
3462 : : {
3463 : : int ret = 0;
3464 : :
3465 : 0 : ixgbe_clear_all_ntuple_filter(dev);
3466 : 0 : ixgbe_clear_all_ethertype_filter(dev);
3467 : 0 : ixgbe_clear_syn_filter(dev);
3468 : :
3469 : 0 : ret = ixgbe_clear_all_fdir_filter(dev);
3470 [ # # ]: 0 : if (ret < 0) {
3471 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3472 : : NULL, "Failed to flush rule");
3473 : 0 : return ret;
3474 : : }
3475 : :
3476 : 0 : ret = ixgbe_clear_all_l2_tn_filter(dev);
3477 [ # # ]: 0 : if (ret < 0) {
3478 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3479 : : NULL, "Failed to flush rule");
3480 : 0 : return ret;
3481 : : }
3482 : :
3483 : : ixgbe_clear_rss_filter(dev);
3484 : :
3485 : 0 : ixgbe_filterlist_flush();
3486 : :
3487 : 0 : return 0;
3488 : : }
3489 : :
3490 : : const struct rte_flow_ops ixgbe_flow_ops = {
3491 : : .validate = ixgbe_flow_validate,
3492 : : .create = ixgbe_flow_create,
3493 : : .destroy = ixgbe_flow_destroy,
3494 : : .flush = ixgbe_flow_flush,
3495 : : };
|