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