4 * Copyright (c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/queue.h>
41 #include <rte_ether.h>
42 #include <rte_ethdev.h>
44 #include <rte_memzone.h>
45 #include <rte_malloc.h>
46 #include <rte_eth_ctrl.h>
47 #include <rte_tailq.h>
48 #include <rte_flow_driver.h>
50 #include "i40e_logs.h"
51 #include "base/i40e_type.h"
52 #include "base/i40e_prototype.h"
53 #include "i40e_ethdev.h"
55 #define I40E_IPV4_TC_SHIFT 4
56 #define I40E_IPV6_TC_MASK (0x00FF << I40E_IPV4_TC_SHIFT)
57 #define I40E_IPV6_FRAG_HEADER 44
58 #define I40E_TENANT_ARRAY_NUM 3
59 #define I40E_TCI_MASK 0xFFFF
61 static int i40e_flow_validate(struct rte_eth_dev *dev,
62 const struct rte_flow_attr *attr,
63 const struct rte_flow_item pattern[],
64 const struct rte_flow_action actions[],
65 struct rte_flow_error *error);
66 static struct rte_flow *i40e_flow_create(struct rte_eth_dev *dev,
67 const struct rte_flow_attr *attr,
68 const struct rte_flow_item pattern[],
69 const struct rte_flow_action actions[],
70 struct rte_flow_error *error);
71 static int i40e_flow_destroy(struct rte_eth_dev *dev,
72 struct rte_flow *flow,
73 struct rte_flow_error *error);
74 static int i40e_flow_flush(struct rte_eth_dev *dev,
75 struct rte_flow_error *error);
77 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
78 const struct rte_flow_item *pattern,
79 struct rte_flow_error *error,
80 struct rte_eth_ethertype_filter *filter);
81 static int i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
82 const struct rte_flow_action *actions,
83 struct rte_flow_error *error,
84 struct rte_eth_ethertype_filter *filter);
85 static int i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
86 const struct rte_flow_item *pattern,
87 struct rte_flow_error *error,
88 struct rte_eth_fdir_filter *filter);
89 static int i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
90 const struct rte_flow_action *actions,
91 struct rte_flow_error *error,
92 struct rte_eth_fdir_filter *filter);
93 static int i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
94 const struct rte_flow_action *actions,
95 struct rte_flow_error *error,
96 struct i40e_tunnel_filter_conf *filter);
97 static int i40e_flow_parse_attr(const struct rte_flow_attr *attr,
98 struct rte_flow_error *error);
99 static int i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
100 const struct rte_flow_attr *attr,
101 const struct rte_flow_item pattern[],
102 const struct rte_flow_action actions[],
103 struct rte_flow_error *error,
104 union i40e_filter_t *filter);
105 static int i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
106 const struct rte_flow_attr *attr,
107 const struct rte_flow_item pattern[],
108 const struct rte_flow_action actions[],
109 struct rte_flow_error *error,
110 union i40e_filter_t *filter);
111 static int i40e_flow_parse_vxlan_filter(struct rte_eth_dev *dev,
112 const struct rte_flow_attr *attr,
113 const struct rte_flow_item pattern[],
114 const struct rte_flow_action actions[],
115 struct rte_flow_error *error,
116 union i40e_filter_t *filter);
117 static int i40e_flow_parse_mpls_filter(struct rte_eth_dev *dev,
118 const struct rte_flow_attr *attr,
119 const struct rte_flow_item pattern[],
120 const struct rte_flow_action actions[],
121 struct rte_flow_error *error,
122 union i40e_filter_t *filter);
123 static int i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
124 struct i40e_ethertype_filter *filter);
125 static int i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
126 struct i40e_tunnel_filter *filter);
127 static int i40e_flow_flush_fdir_filter(struct i40e_pf *pf);
128 static int i40e_flow_flush_ethertype_filter(struct i40e_pf *pf);
129 static int i40e_flow_flush_tunnel_filter(struct i40e_pf *pf);
131 i40e_flow_parse_qinq_filter(struct rte_eth_dev *dev,
132 const struct rte_flow_attr *attr,
133 const struct rte_flow_item pattern[],
134 const struct rte_flow_action actions[],
135 struct rte_flow_error *error,
136 union i40e_filter_t *filter);
138 i40e_flow_parse_qinq_pattern(__rte_unused struct rte_eth_dev *dev,
139 const struct rte_flow_item *pattern,
140 struct rte_flow_error *error,
141 struct i40e_tunnel_filter_conf *filter);
143 const struct rte_flow_ops i40e_flow_ops = {
144 .validate = i40e_flow_validate,
145 .create = i40e_flow_create,
146 .destroy = i40e_flow_destroy,
147 .flush = i40e_flow_flush,
150 union i40e_filter_t cons_filter;
151 enum rte_filter_type cons_filter_type = RTE_ETH_FILTER_NONE;
153 /* Pattern matched ethertype filter */
154 static enum rte_flow_item_type pattern_ethertype[] = {
155 RTE_FLOW_ITEM_TYPE_ETH,
156 RTE_FLOW_ITEM_TYPE_END,
159 /* Pattern matched flow director filter */
160 static enum rte_flow_item_type pattern_fdir_ipv4[] = {
161 RTE_FLOW_ITEM_TYPE_IPV4,
162 RTE_FLOW_ITEM_TYPE_END,
165 static enum rte_flow_item_type pattern_fdir_ipv4_ext[] = {
166 RTE_FLOW_ITEM_TYPE_ETH,
167 RTE_FLOW_ITEM_TYPE_IPV4,
168 RTE_FLOW_ITEM_TYPE_END,
171 static enum rte_flow_item_type pattern_fdir_ipv4_udp[] = {
172 RTE_FLOW_ITEM_TYPE_IPV4,
173 RTE_FLOW_ITEM_TYPE_UDP,
174 RTE_FLOW_ITEM_TYPE_END,
177 static enum rte_flow_item_type pattern_fdir_ipv4_udp_ext[] = {
178 RTE_FLOW_ITEM_TYPE_ETH,
179 RTE_FLOW_ITEM_TYPE_IPV4,
180 RTE_FLOW_ITEM_TYPE_UDP,
181 RTE_FLOW_ITEM_TYPE_END,
184 static enum rte_flow_item_type pattern_fdir_ipv4_tcp[] = {
185 RTE_FLOW_ITEM_TYPE_IPV4,
186 RTE_FLOW_ITEM_TYPE_TCP,
187 RTE_FLOW_ITEM_TYPE_END,
190 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_ext[] = {
191 RTE_FLOW_ITEM_TYPE_ETH,
192 RTE_FLOW_ITEM_TYPE_IPV4,
193 RTE_FLOW_ITEM_TYPE_TCP,
194 RTE_FLOW_ITEM_TYPE_END,
197 static enum rte_flow_item_type pattern_fdir_ipv4_sctp[] = {
198 RTE_FLOW_ITEM_TYPE_IPV4,
199 RTE_FLOW_ITEM_TYPE_SCTP,
200 RTE_FLOW_ITEM_TYPE_END,
203 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_ext[] = {
204 RTE_FLOW_ITEM_TYPE_ETH,
205 RTE_FLOW_ITEM_TYPE_IPV4,
206 RTE_FLOW_ITEM_TYPE_SCTP,
207 RTE_FLOW_ITEM_TYPE_END,
210 static enum rte_flow_item_type pattern_fdir_ipv6[] = {
211 RTE_FLOW_ITEM_TYPE_IPV6,
212 RTE_FLOW_ITEM_TYPE_END,
215 static enum rte_flow_item_type pattern_fdir_ipv6_ext[] = {
216 RTE_FLOW_ITEM_TYPE_ETH,
217 RTE_FLOW_ITEM_TYPE_IPV6,
218 RTE_FLOW_ITEM_TYPE_END,
221 static enum rte_flow_item_type pattern_fdir_ipv6_udp[] = {
222 RTE_FLOW_ITEM_TYPE_IPV6,
223 RTE_FLOW_ITEM_TYPE_UDP,
224 RTE_FLOW_ITEM_TYPE_END,
227 static enum rte_flow_item_type pattern_fdir_ipv6_udp_ext[] = {
228 RTE_FLOW_ITEM_TYPE_ETH,
229 RTE_FLOW_ITEM_TYPE_IPV6,
230 RTE_FLOW_ITEM_TYPE_UDP,
231 RTE_FLOW_ITEM_TYPE_END,
234 static enum rte_flow_item_type pattern_fdir_ipv6_tcp[] = {
235 RTE_FLOW_ITEM_TYPE_IPV6,
236 RTE_FLOW_ITEM_TYPE_TCP,
237 RTE_FLOW_ITEM_TYPE_END,
240 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_ext[] = {
241 RTE_FLOW_ITEM_TYPE_ETH,
242 RTE_FLOW_ITEM_TYPE_IPV6,
243 RTE_FLOW_ITEM_TYPE_TCP,
244 RTE_FLOW_ITEM_TYPE_END,
247 static enum rte_flow_item_type pattern_fdir_ipv6_sctp[] = {
248 RTE_FLOW_ITEM_TYPE_IPV6,
249 RTE_FLOW_ITEM_TYPE_SCTP,
250 RTE_FLOW_ITEM_TYPE_END,
253 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_ext[] = {
254 RTE_FLOW_ITEM_TYPE_ETH,
255 RTE_FLOW_ITEM_TYPE_IPV6,
256 RTE_FLOW_ITEM_TYPE_SCTP,
257 RTE_FLOW_ITEM_TYPE_END,
260 /* Pattern matched tunnel filter */
261 static enum rte_flow_item_type pattern_vxlan_1[] = {
262 RTE_FLOW_ITEM_TYPE_ETH,
263 RTE_FLOW_ITEM_TYPE_IPV4,
264 RTE_FLOW_ITEM_TYPE_UDP,
265 RTE_FLOW_ITEM_TYPE_VXLAN,
266 RTE_FLOW_ITEM_TYPE_ETH,
267 RTE_FLOW_ITEM_TYPE_END,
270 static enum rte_flow_item_type pattern_vxlan_2[] = {
271 RTE_FLOW_ITEM_TYPE_ETH,
272 RTE_FLOW_ITEM_TYPE_IPV6,
273 RTE_FLOW_ITEM_TYPE_UDP,
274 RTE_FLOW_ITEM_TYPE_VXLAN,
275 RTE_FLOW_ITEM_TYPE_ETH,
276 RTE_FLOW_ITEM_TYPE_END,
279 static enum rte_flow_item_type pattern_vxlan_3[] = {
280 RTE_FLOW_ITEM_TYPE_ETH,
281 RTE_FLOW_ITEM_TYPE_IPV4,
282 RTE_FLOW_ITEM_TYPE_UDP,
283 RTE_FLOW_ITEM_TYPE_VXLAN,
284 RTE_FLOW_ITEM_TYPE_ETH,
285 RTE_FLOW_ITEM_TYPE_VLAN,
286 RTE_FLOW_ITEM_TYPE_END,
289 static enum rte_flow_item_type pattern_vxlan_4[] = {
290 RTE_FLOW_ITEM_TYPE_ETH,
291 RTE_FLOW_ITEM_TYPE_IPV6,
292 RTE_FLOW_ITEM_TYPE_UDP,
293 RTE_FLOW_ITEM_TYPE_VXLAN,
294 RTE_FLOW_ITEM_TYPE_ETH,
295 RTE_FLOW_ITEM_TYPE_VLAN,
296 RTE_FLOW_ITEM_TYPE_END,
299 /* Pattern matched MPLS */
300 static enum rte_flow_item_type pattern_mpls_1[] = {
301 RTE_FLOW_ITEM_TYPE_ETH,
302 RTE_FLOW_ITEM_TYPE_IPV4,
303 RTE_FLOW_ITEM_TYPE_UDP,
304 RTE_FLOW_ITEM_TYPE_MPLS,
305 RTE_FLOW_ITEM_TYPE_END,
308 static enum rte_flow_item_type pattern_mpls_2[] = {
309 RTE_FLOW_ITEM_TYPE_ETH,
310 RTE_FLOW_ITEM_TYPE_IPV6,
311 RTE_FLOW_ITEM_TYPE_UDP,
312 RTE_FLOW_ITEM_TYPE_MPLS,
313 RTE_FLOW_ITEM_TYPE_END,
316 static enum rte_flow_item_type pattern_mpls_3[] = {
317 RTE_FLOW_ITEM_TYPE_ETH,
318 RTE_FLOW_ITEM_TYPE_IPV4,
319 RTE_FLOW_ITEM_TYPE_GRE,
320 RTE_FLOW_ITEM_TYPE_MPLS,
321 RTE_FLOW_ITEM_TYPE_END,
324 static enum rte_flow_item_type pattern_mpls_4[] = {
325 RTE_FLOW_ITEM_TYPE_ETH,
326 RTE_FLOW_ITEM_TYPE_IPV6,
327 RTE_FLOW_ITEM_TYPE_GRE,
328 RTE_FLOW_ITEM_TYPE_MPLS,
329 RTE_FLOW_ITEM_TYPE_END,
332 /* Pattern matched QINQ */
333 static enum rte_flow_item_type pattern_qinq_1[] = {
334 RTE_FLOW_ITEM_TYPE_ETH,
335 RTE_FLOW_ITEM_TYPE_VLAN,
336 RTE_FLOW_ITEM_TYPE_VLAN,
337 RTE_FLOW_ITEM_TYPE_END,
340 static struct i40e_valid_pattern i40e_supported_patterns[] = {
342 { pattern_ethertype, i40e_flow_parse_ethertype_filter },
344 { pattern_fdir_ipv4, i40e_flow_parse_fdir_filter },
345 { pattern_fdir_ipv4_ext, i40e_flow_parse_fdir_filter },
346 { pattern_fdir_ipv4_udp, i40e_flow_parse_fdir_filter },
347 { pattern_fdir_ipv4_udp_ext, i40e_flow_parse_fdir_filter },
348 { pattern_fdir_ipv4_tcp, i40e_flow_parse_fdir_filter },
349 { pattern_fdir_ipv4_tcp_ext, i40e_flow_parse_fdir_filter },
350 { pattern_fdir_ipv4_sctp, i40e_flow_parse_fdir_filter },
351 { pattern_fdir_ipv4_sctp_ext, i40e_flow_parse_fdir_filter },
352 { pattern_fdir_ipv6, i40e_flow_parse_fdir_filter },
353 { pattern_fdir_ipv6_ext, i40e_flow_parse_fdir_filter },
354 { pattern_fdir_ipv6_udp, i40e_flow_parse_fdir_filter },
355 { pattern_fdir_ipv6_udp_ext, i40e_flow_parse_fdir_filter },
356 { pattern_fdir_ipv6_tcp, i40e_flow_parse_fdir_filter },
357 { pattern_fdir_ipv6_tcp_ext, i40e_flow_parse_fdir_filter },
358 { pattern_fdir_ipv6_sctp, i40e_flow_parse_fdir_filter },
359 { pattern_fdir_ipv6_sctp_ext, i40e_flow_parse_fdir_filter },
361 { pattern_vxlan_1, i40e_flow_parse_vxlan_filter },
362 { pattern_vxlan_2, i40e_flow_parse_vxlan_filter },
363 { pattern_vxlan_3, i40e_flow_parse_vxlan_filter },
364 { pattern_vxlan_4, i40e_flow_parse_vxlan_filter },
365 /* MPLSoUDP & MPLSoGRE */
366 { pattern_mpls_1, i40e_flow_parse_mpls_filter },
367 { pattern_mpls_2, i40e_flow_parse_mpls_filter },
368 { pattern_mpls_3, i40e_flow_parse_mpls_filter },
369 { pattern_mpls_4, i40e_flow_parse_mpls_filter },
371 { pattern_qinq_1, i40e_flow_parse_qinq_filter },
374 #define NEXT_ITEM_OF_ACTION(act, actions, index) \
376 act = actions + index; \
377 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) { \
379 act = actions + index; \
383 /* Find the first VOID or non-VOID item pointer */
384 static const struct rte_flow_item *
385 i40e_find_first_item(const struct rte_flow_item *item, bool is_void)
389 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
391 is_find = item->type == RTE_FLOW_ITEM_TYPE_VOID;
393 is_find = item->type != RTE_FLOW_ITEM_TYPE_VOID;
401 /* Skip all VOID items of the pattern */
403 i40e_pattern_skip_void_item(struct rte_flow_item *items,
404 const struct rte_flow_item *pattern)
406 uint32_t cpy_count = 0;
407 const struct rte_flow_item *pb = pattern, *pe = pattern;
410 /* Find a non-void item first */
411 pb = i40e_find_first_item(pb, false);
412 if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
417 /* Find a void item */
418 pe = i40e_find_first_item(pb + 1, true);
421 rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
425 if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
432 /* Copy the END item. */
433 rte_memcpy(items, pe, sizeof(struct rte_flow_item));
436 /* Check if the pattern matches a supported item type array */
438 i40e_match_pattern(enum rte_flow_item_type *item_array,
439 struct rte_flow_item *pattern)
441 struct rte_flow_item *item = pattern;
443 while ((*item_array == item->type) &&
444 (*item_array != RTE_FLOW_ITEM_TYPE_END)) {
449 return (*item_array == RTE_FLOW_ITEM_TYPE_END &&
450 item->type == RTE_FLOW_ITEM_TYPE_END);
453 /* Find if there's parse filter function matched */
454 static parse_filter_t
455 i40e_find_parse_filter_func(struct rte_flow_item *pattern)
457 parse_filter_t parse_filter = NULL;
460 for (; i < RTE_DIM(i40e_supported_patterns); i++) {
461 if (i40e_match_pattern(i40e_supported_patterns[i].items,
463 parse_filter = i40e_supported_patterns[i].parse_filter;
471 /* Parse attributes */
473 i40e_flow_parse_attr(const struct rte_flow_attr *attr,
474 struct rte_flow_error *error)
476 /* Must be input direction */
477 if (!attr->ingress) {
478 rte_flow_error_set(error, EINVAL,
479 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
480 attr, "Only support ingress.");
486 rte_flow_error_set(error, EINVAL,
487 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
488 attr, "Not support egress.");
493 if (attr->priority) {
494 rte_flow_error_set(error, EINVAL,
495 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
496 attr, "Not support priority.");
502 rte_flow_error_set(error, EINVAL,
503 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
504 attr, "Not support group.");
512 i40e_get_outer_vlan(struct rte_eth_dev *dev)
514 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
515 int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
525 i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
528 tpid = (reg_r >> I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT) & 0xFFFF;
533 /* 1. Last in item should be NULL as range is not supported.
534 * 2. Supported filter types: MAC_ETHTYPE and ETHTYPE.
535 * 3. SRC mac_addr mask should be 00:00:00:00:00:00.
536 * 4. DST mac_addr mask should be 00:00:00:00:00:00 or
538 * 5. Ether_type mask should be 0xFFFF.
541 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
542 const struct rte_flow_item *pattern,
543 struct rte_flow_error *error,
544 struct rte_eth_ethertype_filter *filter)
546 const struct rte_flow_item *item = pattern;
547 const struct rte_flow_item_eth *eth_spec;
548 const struct rte_flow_item_eth *eth_mask;
549 enum rte_flow_item_type item_type;
552 outer_tpid = i40e_get_outer_vlan(dev);
554 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
556 rte_flow_error_set(error, EINVAL,
557 RTE_FLOW_ERROR_TYPE_ITEM,
559 "Not support range");
562 item_type = item->type;
564 case RTE_FLOW_ITEM_TYPE_ETH:
565 eth_spec = (const struct rte_flow_item_eth *)item->spec;
566 eth_mask = (const struct rte_flow_item_eth *)item->mask;
567 /* Get the MAC info. */
568 if (!eth_spec || !eth_mask) {
569 rte_flow_error_set(error, EINVAL,
570 RTE_FLOW_ERROR_TYPE_ITEM,
572 "NULL ETH spec/mask");
576 /* Mask bits of source MAC address must be full of 0.
577 * Mask bits of destination MAC address must be full
580 if (!is_zero_ether_addr(ð_mask->src) ||
581 (!is_zero_ether_addr(ð_mask->dst) &&
582 !is_broadcast_ether_addr(ð_mask->dst))) {
583 rte_flow_error_set(error, EINVAL,
584 RTE_FLOW_ERROR_TYPE_ITEM,
586 "Invalid MAC_addr mask");
590 if ((eth_mask->type & UINT16_MAX) != UINT16_MAX) {
591 rte_flow_error_set(error, EINVAL,
592 RTE_FLOW_ERROR_TYPE_ITEM,
594 "Invalid ethertype mask");
598 /* If mask bits of destination MAC address
599 * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
601 if (is_broadcast_ether_addr(ð_mask->dst)) {
602 filter->mac_addr = eth_spec->dst;
603 filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
605 filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
607 filter->ether_type = rte_be_to_cpu_16(eth_spec->type);
609 if (filter->ether_type == ETHER_TYPE_IPv4 ||
610 filter->ether_type == ETHER_TYPE_IPv6 ||
611 filter->ether_type == ETHER_TYPE_LLDP ||
612 filter->ether_type == outer_tpid) {
613 rte_flow_error_set(error, EINVAL,
614 RTE_FLOW_ERROR_TYPE_ITEM,
616 "Unsupported ether_type in"
617 " control packet filter.");
629 /* Ethertype action only supports QUEUE or DROP. */
631 i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
632 const struct rte_flow_action *actions,
633 struct rte_flow_error *error,
634 struct rte_eth_ethertype_filter *filter)
636 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
637 const struct rte_flow_action *act;
638 const struct rte_flow_action_queue *act_q;
641 /* Check if the first non-void action is QUEUE or DROP. */
642 NEXT_ITEM_OF_ACTION(act, actions, index);
643 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
644 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
645 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
646 act, "Not supported action.");
650 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
651 act_q = (const struct rte_flow_action_queue *)act->conf;
652 filter->queue = act_q->index;
653 if (filter->queue >= pf->dev_data->nb_rx_queues) {
654 rte_flow_error_set(error, EINVAL,
655 RTE_FLOW_ERROR_TYPE_ACTION,
656 act, "Invalid queue ID for"
657 " ethertype_filter.");
661 filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
664 /* Check if the next non-void item is END */
666 NEXT_ITEM_OF_ACTION(act, actions, index);
667 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
668 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
669 act, "Not supported action.");
677 i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
678 const struct rte_flow_attr *attr,
679 const struct rte_flow_item pattern[],
680 const struct rte_flow_action actions[],
681 struct rte_flow_error *error,
682 union i40e_filter_t *filter)
684 struct rte_eth_ethertype_filter *ethertype_filter =
685 &filter->ethertype_filter;
688 ret = i40e_flow_parse_ethertype_pattern(dev, pattern, error,
693 ret = i40e_flow_parse_ethertype_action(dev, actions, error,
698 ret = i40e_flow_parse_attr(attr, error);
702 cons_filter_type = RTE_ETH_FILTER_ETHERTYPE;
707 /* 1. Last in item should be NULL as range is not supported.
708 * 2. Supported flow type and input set: refer to array
709 * default_inset_table in i40e_ethdev.c.
710 * 3. Mask of fields which need to be matched should be
712 * 4. Mask of fields which needn't to be matched should be
716 i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
717 const struct rte_flow_item *pattern,
718 struct rte_flow_error *error,
719 struct rte_eth_fdir_filter *filter)
721 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
722 const struct rte_flow_item *item = pattern;
723 const struct rte_flow_item_eth *eth_spec, *eth_mask;
724 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
725 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
726 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
727 const struct rte_flow_item_udp *udp_spec, *udp_mask;
728 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
729 const struct rte_flow_item_vf *vf_spec;
730 uint32_t flow_type = RTE_ETH_FLOW_UNKNOWN;
731 enum i40e_filter_pctype pctype;
732 uint64_t input_set = I40E_INSET_NONE;
733 uint16_t flag_offset;
734 enum rte_flow_item_type item_type;
735 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
738 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
740 rte_flow_error_set(error, EINVAL,
741 RTE_FLOW_ERROR_TYPE_ITEM,
743 "Not support range");
746 item_type = item->type;
748 case RTE_FLOW_ITEM_TYPE_ETH:
749 eth_spec = (const struct rte_flow_item_eth *)item->spec;
750 eth_mask = (const struct rte_flow_item_eth *)item->mask;
751 if (eth_spec || eth_mask) {
752 rte_flow_error_set(error, EINVAL,
753 RTE_FLOW_ERROR_TYPE_ITEM,
755 "Invalid ETH spec/mask");
759 case RTE_FLOW_ITEM_TYPE_IPV4:
760 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
762 (const struct rte_flow_item_ipv4 *)item->spec;
764 (const struct rte_flow_item_ipv4 *)item->mask;
765 if (!ipv4_spec || !ipv4_mask) {
766 rte_flow_error_set(error, EINVAL,
767 RTE_FLOW_ERROR_TYPE_ITEM,
769 "NULL IPv4 spec/mask");
773 /* Check IPv4 mask and update input set */
774 if (ipv4_mask->hdr.version_ihl ||
775 ipv4_mask->hdr.total_length ||
776 ipv4_mask->hdr.packet_id ||
777 ipv4_mask->hdr.fragment_offset ||
778 ipv4_mask->hdr.hdr_checksum) {
779 rte_flow_error_set(error, EINVAL,
780 RTE_FLOW_ERROR_TYPE_ITEM,
782 "Invalid IPv4 mask.");
786 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
787 input_set |= I40E_INSET_IPV4_SRC;
788 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
789 input_set |= I40E_INSET_IPV4_DST;
790 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
791 input_set |= I40E_INSET_IPV4_TOS;
792 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
793 input_set |= I40E_INSET_IPV4_TTL;
794 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
795 input_set |= I40E_INSET_IPV4_PROTO;
797 /* Get filter info */
798 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_OTHER;
799 /* Check if it is fragment. */
801 rte_be_to_cpu_16(ipv4_spec->hdr.fragment_offset);
802 if (flag_offset & IPV4_HDR_OFFSET_MASK ||
803 flag_offset & IPV4_HDR_MF_FLAG)
804 flow_type = RTE_ETH_FLOW_FRAG_IPV4;
806 /* Get the filter info */
807 filter->input.flow.ip4_flow.proto =
808 ipv4_spec->hdr.next_proto_id;
809 filter->input.flow.ip4_flow.tos =
810 ipv4_spec->hdr.type_of_service;
811 filter->input.flow.ip4_flow.ttl =
812 ipv4_spec->hdr.time_to_live;
813 filter->input.flow.ip4_flow.src_ip =
814 ipv4_spec->hdr.src_addr;
815 filter->input.flow.ip4_flow.dst_ip =
816 ipv4_spec->hdr.dst_addr;
819 case RTE_FLOW_ITEM_TYPE_IPV6:
820 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
822 (const struct rte_flow_item_ipv6 *)item->spec;
824 (const struct rte_flow_item_ipv6 *)item->mask;
825 if (!ipv6_spec || !ipv6_mask) {
826 rte_flow_error_set(error, EINVAL,
827 RTE_FLOW_ERROR_TYPE_ITEM,
829 "NULL IPv6 spec/mask");
833 /* Check IPv6 mask and update input set */
834 if (ipv6_mask->hdr.payload_len) {
835 rte_flow_error_set(error, EINVAL,
836 RTE_FLOW_ERROR_TYPE_ITEM,
838 "Invalid IPv6 mask");
842 /* SCR and DST address of IPv6 shouldn't be masked */
843 for (j = 0; j < RTE_DIM(ipv6_mask->hdr.src_addr); j++) {
844 if (ipv6_mask->hdr.src_addr[j] != UINT8_MAX ||
845 ipv6_mask->hdr.dst_addr[j] != UINT8_MAX) {
846 rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM,
849 "Invalid IPv6 mask");
854 input_set |= I40E_INSET_IPV6_SRC;
855 input_set |= I40E_INSET_IPV6_DST;
857 if ((ipv6_mask->hdr.vtc_flow &
858 rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
859 == rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
860 input_set |= I40E_INSET_IPV6_TC;
861 if (ipv6_mask->hdr.proto == UINT8_MAX)
862 input_set |= I40E_INSET_IPV6_NEXT_HDR;
863 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
864 input_set |= I40E_INSET_IPV6_HOP_LIMIT;
866 /* Get filter info */
867 filter->input.flow.ipv6_flow.tc =
868 (uint8_t)(ipv6_spec->hdr.vtc_flow <<
870 filter->input.flow.ipv6_flow.proto =
871 ipv6_spec->hdr.proto;
872 filter->input.flow.ipv6_flow.hop_limits =
873 ipv6_spec->hdr.hop_limits;
875 rte_memcpy(filter->input.flow.ipv6_flow.src_ip,
876 ipv6_spec->hdr.src_addr, 16);
877 rte_memcpy(filter->input.flow.ipv6_flow.dst_ip,
878 ipv6_spec->hdr.dst_addr, 16);
880 /* Check if it is fragment. */
881 if (ipv6_spec->hdr.proto == I40E_IPV6_FRAG_HEADER)
882 flow_type = RTE_ETH_FLOW_FRAG_IPV6;
884 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_OTHER;
886 case RTE_FLOW_ITEM_TYPE_TCP:
887 tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
888 tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
889 if (!tcp_spec || !tcp_mask) {
890 rte_flow_error_set(error, EINVAL,
891 RTE_FLOW_ERROR_TYPE_ITEM,
893 "NULL TCP spec/mask");
897 /* Check TCP mask and update input set */
898 if (tcp_mask->hdr.sent_seq ||
899 tcp_mask->hdr.recv_ack ||
900 tcp_mask->hdr.data_off ||
901 tcp_mask->hdr.tcp_flags ||
902 tcp_mask->hdr.rx_win ||
903 tcp_mask->hdr.cksum ||
904 tcp_mask->hdr.tcp_urp) {
905 rte_flow_error_set(error, EINVAL,
906 RTE_FLOW_ERROR_TYPE_ITEM,
912 if (tcp_mask->hdr.src_port != UINT16_MAX ||
913 tcp_mask->hdr.dst_port != UINT16_MAX) {
914 rte_flow_error_set(error, EINVAL,
915 RTE_FLOW_ERROR_TYPE_ITEM,
921 input_set |= I40E_INSET_SRC_PORT;
922 input_set |= I40E_INSET_DST_PORT;
924 /* Get filter info */
925 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
926 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_TCP;
927 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
928 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_TCP;
930 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
931 filter->input.flow.tcp4_flow.src_port =
932 tcp_spec->hdr.src_port;
933 filter->input.flow.tcp4_flow.dst_port =
934 tcp_spec->hdr.dst_port;
935 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
936 filter->input.flow.tcp6_flow.src_port =
937 tcp_spec->hdr.src_port;
938 filter->input.flow.tcp6_flow.dst_port =
939 tcp_spec->hdr.dst_port;
942 case RTE_FLOW_ITEM_TYPE_UDP:
943 udp_spec = (const struct rte_flow_item_udp *)item->spec;
944 udp_mask = (const struct rte_flow_item_udp *)item->mask;
945 if (!udp_spec || !udp_mask) {
946 rte_flow_error_set(error, EINVAL,
947 RTE_FLOW_ERROR_TYPE_ITEM,
949 "NULL UDP spec/mask");
953 /* Check UDP mask and update input set*/
954 if (udp_mask->hdr.dgram_len ||
955 udp_mask->hdr.dgram_cksum) {
956 rte_flow_error_set(error, EINVAL,
957 RTE_FLOW_ERROR_TYPE_ITEM,
963 if (udp_mask->hdr.src_port != UINT16_MAX ||
964 udp_mask->hdr.dst_port != UINT16_MAX) {
965 rte_flow_error_set(error, EINVAL,
966 RTE_FLOW_ERROR_TYPE_ITEM,
972 input_set |= I40E_INSET_SRC_PORT;
973 input_set |= I40E_INSET_DST_PORT;
975 /* Get filter info */
976 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
978 RTE_ETH_FLOW_NONFRAG_IPV4_UDP;
979 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
981 RTE_ETH_FLOW_NONFRAG_IPV6_UDP;
983 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
984 filter->input.flow.udp4_flow.src_port =
985 udp_spec->hdr.src_port;
986 filter->input.flow.udp4_flow.dst_port =
987 udp_spec->hdr.dst_port;
988 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
989 filter->input.flow.udp6_flow.src_port =
990 udp_spec->hdr.src_port;
991 filter->input.flow.udp6_flow.dst_port =
992 udp_spec->hdr.dst_port;
995 case RTE_FLOW_ITEM_TYPE_SCTP:
997 (const struct rte_flow_item_sctp *)item->spec;
999 (const struct rte_flow_item_sctp *)item->mask;
1000 if (!sctp_spec || !sctp_mask) {
1001 rte_flow_error_set(error, EINVAL,
1002 RTE_FLOW_ERROR_TYPE_ITEM,
1004 "NULL SCTP spec/mask");
1008 /* Check SCTP mask and update input set */
1009 if (sctp_mask->hdr.cksum) {
1010 rte_flow_error_set(error, EINVAL,
1011 RTE_FLOW_ERROR_TYPE_ITEM,
1013 "Invalid UDP mask");
1017 if (sctp_mask->hdr.src_port != UINT16_MAX ||
1018 sctp_mask->hdr.dst_port != UINT16_MAX ||
1019 sctp_mask->hdr.tag != UINT32_MAX) {
1020 rte_flow_error_set(error, EINVAL,
1021 RTE_FLOW_ERROR_TYPE_ITEM,
1023 "Invalid UDP mask");
1026 input_set |= I40E_INSET_SRC_PORT;
1027 input_set |= I40E_INSET_DST_PORT;
1028 input_set |= I40E_INSET_SCTP_VT;
1030 /* Get filter info */
1031 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
1032 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_SCTP;
1033 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
1034 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_SCTP;
1036 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1037 filter->input.flow.sctp4_flow.src_port =
1038 sctp_spec->hdr.src_port;
1039 filter->input.flow.sctp4_flow.dst_port =
1040 sctp_spec->hdr.dst_port;
1041 filter->input.flow.sctp4_flow.verify_tag =
1043 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1044 filter->input.flow.sctp6_flow.src_port =
1045 sctp_spec->hdr.src_port;
1046 filter->input.flow.sctp6_flow.dst_port =
1047 sctp_spec->hdr.dst_port;
1048 filter->input.flow.sctp6_flow.verify_tag =
1052 case RTE_FLOW_ITEM_TYPE_VF:
1053 vf_spec = (const struct rte_flow_item_vf *)item->spec;
1054 filter->input.flow_ext.is_vf = 1;
1055 filter->input.flow_ext.dst_id = vf_spec->id;
1056 if (filter->input.flow_ext.is_vf &&
1057 filter->input.flow_ext.dst_id >= pf->vf_num) {
1058 rte_flow_error_set(error, EINVAL,
1059 RTE_FLOW_ERROR_TYPE_ITEM,
1061 "Invalid VF ID for FDIR.");
1070 pctype = i40e_flowtype_to_pctype(flow_type);
1071 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
1072 rte_flow_error_set(error, EINVAL,
1073 RTE_FLOW_ERROR_TYPE_ITEM, item,
1074 "Unsupported flow type");
1078 if (input_set != i40e_get_default_input_set(pctype)) {
1079 rte_flow_error_set(error, EINVAL,
1080 RTE_FLOW_ERROR_TYPE_ITEM, item,
1081 "Invalid input set.");
1084 filter->input.flow_type = flow_type;
1089 /* Parse to get the action info of a FDIR filter.
1090 * FDIR action supports QUEUE or (QUEUE + MARK).
1093 i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
1094 const struct rte_flow_action *actions,
1095 struct rte_flow_error *error,
1096 struct rte_eth_fdir_filter *filter)
1098 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1099 const struct rte_flow_action *act;
1100 const struct rte_flow_action_queue *act_q;
1101 const struct rte_flow_action_mark *mark_spec;
1104 /* Check if the first non-void action is QUEUE or DROP. */
1105 NEXT_ITEM_OF_ACTION(act, actions, index);
1106 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
1107 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
1108 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1109 act, "Invalid action.");
1113 act_q = (const struct rte_flow_action_queue *)act->conf;
1114 filter->action.flex_off = 0;
1115 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE)
1116 filter->action.behavior = RTE_ETH_FDIR_ACCEPT;
1118 filter->action.behavior = RTE_ETH_FDIR_REJECT;
1120 filter->action.report_status = RTE_ETH_FDIR_REPORT_ID;
1121 filter->action.rx_queue = act_q->index;
1123 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1124 rte_flow_error_set(error, EINVAL,
1125 RTE_FLOW_ERROR_TYPE_ACTION, act,
1126 "Invalid queue ID for FDIR.");
1130 /* Check if the next non-void item is MARK or END. */
1132 NEXT_ITEM_OF_ACTION(act, actions, index);
1133 if (act->type != RTE_FLOW_ACTION_TYPE_MARK &&
1134 act->type != RTE_FLOW_ACTION_TYPE_END) {
1135 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1136 act, "Invalid action.");
1140 if (act->type == RTE_FLOW_ACTION_TYPE_MARK) {
1141 mark_spec = (const struct rte_flow_action_mark *)act->conf;
1142 filter->soft_id = mark_spec->id;
1144 /* Check if the next non-void item is END */
1146 NEXT_ITEM_OF_ACTION(act, actions, index);
1147 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1148 rte_flow_error_set(error, EINVAL,
1149 RTE_FLOW_ERROR_TYPE_ACTION,
1150 act, "Invalid action.");
1159 i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
1160 const struct rte_flow_attr *attr,
1161 const struct rte_flow_item pattern[],
1162 const struct rte_flow_action actions[],
1163 struct rte_flow_error *error,
1164 union i40e_filter_t *filter)
1166 struct rte_eth_fdir_filter *fdir_filter =
1167 &filter->fdir_filter;
1170 ret = i40e_flow_parse_fdir_pattern(dev, pattern, error, fdir_filter);
1174 ret = i40e_flow_parse_fdir_action(dev, actions, error, fdir_filter);
1178 ret = i40e_flow_parse_attr(attr, error);
1182 cons_filter_type = RTE_ETH_FILTER_FDIR;
1184 if (dev->data->dev_conf.fdir_conf.mode !=
1185 RTE_FDIR_MODE_PERFECT) {
1186 rte_flow_error_set(error, ENOTSUP,
1187 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1189 "Check the mode in fdir_conf.");
1196 /* Parse to get the action info of a tunnel filter
1197 * Tunnel action only supports PF, VF and QUEUE.
1200 i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
1201 const struct rte_flow_action *actions,
1202 struct rte_flow_error *error,
1203 struct i40e_tunnel_filter_conf *filter)
1205 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1206 const struct rte_flow_action *act;
1207 const struct rte_flow_action_queue *act_q;
1208 const struct rte_flow_action_vf *act_vf;
1211 /* Check if the first non-void action is PF or VF. */
1212 NEXT_ITEM_OF_ACTION(act, actions, index);
1213 if (act->type != RTE_FLOW_ACTION_TYPE_PF &&
1214 act->type != RTE_FLOW_ACTION_TYPE_VF) {
1215 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1216 act, "Not supported action.");
1220 if (act->type == RTE_FLOW_ACTION_TYPE_VF) {
1221 act_vf = (const struct rte_flow_action_vf *)act->conf;
1222 filter->vf_id = act_vf->id;
1223 filter->is_to_vf = 1;
1224 if (filter->vf_id >= pf->vf_num) {
1225 rte_flow_error_set(error, EINVAL,
1226 RTE_FLOW_ERROR_TYPE_ACTION,
1227 act, "Invalid VF ID for tunnel filter");
1232 /* Check if the next non-void item is QUEUE */
1234 NEXT_ITEM_OF_ACTION(act, actions, index);
1235 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
1236 act_q = (const struct rte_flow_action_queue *)act->conf;
1237 filter->queue_id = act_q->index;
1238 if ((!filter->is_to_vf) &&
1239 (filter->queue_id >= pf->dev_data->nb_rx_queues)) {
1240 rte_flow_error_set(error, EINVAL,
1241 RTE_FLOW_ERROR_TYPE_ACTION,
1242 act, "Invalid queue ID for tunnel filter");
1244 } else if (filter->is_to_vf &&
1245 (filter->queue_id >= pf->vf_nb_qps)) {
1246 rte_flow_error_set(error, EINVAL,
1247 RTE_FLOW_ERROR_TYPE_ACTION,
1248 act, "Invalid queue ID for tunnel filter");
1253 /* Check if the next non-void item is END */
1255 NEXT_ITEM_OF_ACTION(act, actions, index);
1256 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1257 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1258 act, "Not supported action.");
1266 i40e_check_tenant_id_mask(const uint8_t *mask)
1271 for (j = 0; j < I40E_TENANT_ARRAY_NUM; j++) {
1272 if (*(mask + j) == UINT8_MAX) {
1273 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1276 } else if (*(mask + j) == 0) {
1277 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1288 /* 1. Last in item should be NULL as range is not supported.
1289 * 2. Supported filter types: IMAC_IVLAN_TENID, IMAC_IVLAN,
1290 * IMAC_TENID, OMAC_TENID_IMAC and IMAC.
1291 * 3. Mask of fields which need to be matched should be
1293 * 4. Mask of fields which needn't to be matched should be
1297 i40e_flow_parse_vxlan_pattern(__rte_unused struct rte_eth_dev *dev,
1298 const struct rte_flow_item *pattern,
1299 struct rte_flow_error *error,
1300 struct i40e_tunnel_filter_conf *filter)
1302 const struct rte_flow_item *item = pattern;
1303 const struct rte_flow_item_eth *eth_spec;
1304 const struct rte_flow_item_eth *eth_mask;
1305 const struct rte_flow_item_eth *o_eth_spec = NULL;
1306 const struct rte_flow_item_eth *o_eth_mask = NULL;
1307 const struct rte_flow_item_vxlan *vxlan_spec = NULL;
1308 const struct rte_flow_item_vxlan *vxlan_mask = NULL;
1309 const struct rte_flow_item_eth *i_eth_spec = NULL;
1310 const struct rte_flow_item_eth *i_eth_mask = NULL;
1311 const struct rte_flow_item_vlan *vlan_spec = NULL;
1312 const struct rte_flow_item_vlan *vlan_mask = NULL;
1313 bool is_vni_masked = 0;
1314 enum rte_flow_item_type item_type;
1315 bool vxlan_flag = 0;
1316 uint32_t tenant_id_be = 0;
1318 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1320 rte_flow_error_set(error, EINVAL,
1321 RTE_FLOW_ERROR_TYPE_ITEM,
1323 "Not support range");
1326 item_type = item->type;
1327 switch (item_type) {
1328 case RTE_FLOW_ITEM_TYPE_ETH:
1329 eth_spec = (const struct rte_flow_item_eth *)item->spec;
1330 eth_mask = (const struct rte_flow_item_eth *)item->mask;
1331 if ((!eth_spec && eth_mask) ||
1332 (eth_spec && !eth_mask)) {
1333 rte_flow_error_set(error, EINVAL,
1334 RTE_FLOW_ERROR_TYPE_ITEM,
1336 "Invalid ether spec/mask");
1340 if (eth_spec && eth_mask) {
1341 /* DST address of inner MAC shouldn't be masked.
1342 * SRC address of Inner MAC should be masked.
1344 if (!is_broadcast_ether_addr(ð_mask->dst) ||
1345 !is_zero_ether_addr(ð_mask->src) ||
1347 rte_flow_error_set(error, EINVAL,
1348 RTE_FLOW_ERROR_TYPE_ITEM,
1350 "Invalid ether spec/mask");
1355 rte_memcpy(&filter->outer_mac,
1359 rte_memcpy(&filter->inner_mac,
1365 o_eth_spec = eth_spec;
1366 o_eth_mask = eth_mask;
1368 i_eth_spec = eth_spec;
1369 i_eth_mask = eth_mask;
1373 case RTE_FLOW_ITEM_TYPE_VLAN:
1375 (const struct rte_flow_item_vlan *)item->spec;
1377 (const struct rte_flow_item_vlan *)item->mask;
1380 (const struct rte_flow_item_vlan *)item->spec;
1382 (const struct rte_flow_item_vlan *)item->mask;
1383 if (!(vlan_spec && vlan_mask)) {
1384 rte_flow_error_set(error, EINVAL,
1385 RTE_FLOW_ERROR_TYPE_ITEM,
1387 "Invalid vlan item");
1391 if (vlan_spec || vlan_mask)
1392 rte_flow_error_set(error, EINVAL,
1393 RTE_FLOW_ERROR_TYPE_ITEM,
1395 "Invalid vlan item");
1399 case RTE_FLOW_ITEM_TYPE_IPV4:
1400 filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
1401 /* IPv4 is used to describe protocol,
1402 * spec and mask should be NULL.
1404 if (item->spec || item->mask) {
1405 rte_flow_error_set(error, EINVAL,
1406 RTE_FLOW_ERROR_TYPE_ITEM,
1408 "Invalid IPv4 item");
1412 case RTE_FLOW_ITEM_TYPE_IPV6:
1413 filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
1414 /* IPv6 is used to describe protocol,
1415 * spec and mask should be NULL.
1417 if (item->spec || item->mask) {
1418 rte_flow_error_set(error, EINVAL,
1419 RTE_FLOW_ERROR_TYPE_ITEM,
1421 "Invalid IPv6 item");
1425 case RTE_FLOW_ITEM_TYPE_UDP:
1426 /* UDP is used to describe protocol,
1427 * spec and mask should be NULL.
1429 if (item->spec || item->mask) {
1430 rte_flow_error_set(error, EINVAL,
1431 RTE_FLOW_ERROR_TYPE_ITEM,
1433 "Invalid UDP item");
1437 case RTE_FLOW_ITEM_TYPE_VXLAN:
1439 (const struct rte_flow_item_vxlan *)item->spec;
1441 (const struct rte_flow_item_vxlan *)item->mask;
1442 /* Check if VXLAN item is used to describe protocol.
1443 * If yes, both spec and mask should be NULL.
1444 * If no, either spec or mask shouldn't be NULL.
1446 if ((!vxlan_spec && vxlan_mask) ||
1447 (vxlan_spec && !vxlan_mask)) {
1448 rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ITEM,
1451 "Invalid VXLAN item");
1455 /* Check if VNI is masked. */
1458 i40e_check_tenant_id_mask(vxlan_mask->vni);
1459 if (is_vni_masked < 0) {
1460 rte_flow_error_set(error, EINVAL,
1461 RTE_FLOW_ERROR_TYPE_ITEM,
1463 "Invalid VNI mask");
1474 /* Check specification and mask to get the filter type */
1475 if (vlan_spec && vlan_mask &&
1476 (vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK))) {
1477 /* If there's inner vlan */
1478 filter->inner_vlan = rte_be_to_cpu_16(vlan_spec->tci)
1480 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1481 /* If there's vxlan */
1482 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
1483 vxlan_spec->vni, 3);
1484 filter->tenant_id = rte_be_to_cpu_32(tenant_id_be);
1485 if (!o_eth_spec && !o_eth_mask &&
1486 i_eth_spec && i_eth_mask)
1487 filter->filter_type =
1488 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
1490 rte_flow_error_set(error, EINVAL,
1491 RTE_FLOW_ERROR_TYPE_ITEM,
1493 "Invalid filter type");
1496 } else if (!vxlan_spec && !vxlan_mask) {
1497 /* If there's no vxlan */
1498 if (!o_eth_spec && !o_eth_mask &&
1499 i_eth_spec && i_eth_mask)
1500 filter->filter_type =
1501 RTE_TUNNEL_FILTER_IMAC_IVLAN;
1503 rte_flow_error_set(error, EINVAL,
1504 RTE_FLOW_ERROR_TYPE_ITEM,
1506 "Invalid filter type");
1510 rte_flow_error_set(error, EINVAL,
1511 RTE_FLOW_ERROR_TYPE_ITEM,
1513 "Invalid filter type");
1516 } else if ((!vlan_spec && !vlan_mask) ||
1517 (vlan_spec && vlan_mask && vlan_mask->tci == 0x0)) {
1518 /* If there's no inner vlan */
1519 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1520 /* If there's vxlan */
1521 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
1522 vxlan_spec->vni, 3);
1523 filter->tenant_id = rte_be_to_cpu_32(tenant_id_be);
1524 if (!o_eth_spec && !o_eth_mask &&
1525 i_eth_spec && i_eth_mask)
1526 filter->filter_type =
1527 RTE_TUNNEL_FILTER_IMAC_TENID;
1528 else if (o_eth_spec && o_eth_mask &&
1529 i_eth_spec && i_eth_mask)
1530 filter->filter_type =
1531 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
1532 } else if (!vxlan_spec && !vxlan_mask) {
1533 /* If there's no vxlan */
1534 if (!o_eth_spec && !o_eth_mask &&
1535 i_eth_spec && i_eth_mask) {
1536 filter->filter_type = ETH_TUNNEL_FILTER_IMAC;
1538 rte_flow_error_set(error, EINVAL,
1539 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1540 "Invalid filter type");
1544 rte_flow_error_set(error, EINVAL,
1545 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1546 "Invalid filter type");
1550 rte_flow_error_set(error, EINVAL,
1551 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1552 "Not supported by tunnel filter.");
1556 filter->tunnel_type = I40E_TUNNEL_TYPE_VXLAN;
1562 i40e_flow_parse_vxlan_filter(struct rte_eth_dev *dev,
1563 const struct rte_flow_attr *attr,
1564 const struct rte_flow_item pattern[],
1565 const struct rte_flow_action actions[],
1566 struct rte_flow_error *error,
1567 union i40e_filter_t *filter)
1569 struct i40e_tunnel_filter_conf *tunnel_filter =
1570 &filter->consistent_tunnel_filter;
1573 ret = i40e_flow_parse_vxlan_pattern(dev, pattern,
1574 error, tunnel_filter);
1578 ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
1582 ret = i40e_flow_parse_attr(attr, error);
1586 cons_filter_type = RTE_ETH_FILTER_TUNNEL;
1591 /* 1. Last in item should be NULL as range is not supported.
1592 * 2. Supported filter types: MPLS label.
1593 * 3. Mask of fields which need to be matched should be
1595 * 4. Mask of fields which needn't to be matched should be
1599 i40e_flow_parse_mpls_pattern(__rte_unused struct rte_eth_dev *dev,
1600 const struct rte_flow_item *pattern,
1601 struct rte_flow_error *error,
1602 struct i40e_tunnel_filter_conf *filter)
1604 const struct rte_flow_item *item = pattern;
1605 const struct rte_flow_item_mpls *mpls_spec;
1606 const struct rte_flow_item_mpls *mpls_mask;
1607 enum rte_flow_item_type item_type;
1608 bool is_mplsoudp = 0; /* 1 - MPLSoUDP, 0 - MPLSoGRE */
1609 const uint8_t label_mask[3] = {0xFF, 0xFF, 0xF0};
1610 uint32_t label_be = 0;
1612 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1614 rte_flow_error_set(error, EINVAL,
1615 RTE_FLOW_ERROR_TYPE_ITEM,
1617 "Not support range");
1620 item_type = item->type;
1621 switch (item_type) {
1622 case RTE_FLOW_ITEM_TYPE_ETH:
1623 if (item->spec || item->mask) {
1624 rte_flow_error_set(error, EINVAL,
1625 RTE_FLOW_ERROR_TYPE_ITEM,
1627 "Invalid ETH item");
1631 case RTE_FLOW_ITEM_TYPE_IPV4:
1632 filter->ip_type = I40E_TUNNEL_IPTYPE_IPV4;
1633 /* IPv4 is used to describe protocol,
1634 * spec and mask should be NULL.
1636 if (item->spec || item->mask) {
1637 rte_flow_error_set(error, EINVAL,
1638 RTE_FLOW_ERROR_TYPE_ITEM,
1640 "Invalid IPv4 item");
1644 case RTE_FLOW_ITEM_TYPE_IPV6:
1645 filter->ip_type = I40E_TUNNEL_IPTYPE_IPV6;
1646 /* IPv6 is used to describe protocol,
1647 * spec and mask should be NULL.
1649 if (item->spec || item->mask) {
1650 rte_flow_error_set(error, EINVAL,
1651 RTE_FLOW_ERROR_TYPE_ITEM,
1653 "Invalid IPv6 item");
1657 case RTE_FLOW_ITEM_TYPE_UDP:
1658 /* UDP is used to describe protocol,
1659 * spec and mask should be NULL.
1661 if (item->spec || item->mask) {
1662 rte_flow_error_set(error, EINVAL,
1663 RTE_FLOW_ERROR_TYPE_ITEM,
1665 "Invalid UDP item");
1670 case RTE_FLOW_ITEM_TYPE_GRE:
1671 /* GRE is used to describe protocol,
1672 * spec and mask should be NULL.
1674 if (item->spec || item->mask) {
1675 rte_flow_error_set(error, EINVAL,
1676 RTE_FLOW_ERROR_TYPE_ITEM,
1678 "Invalid GRE item");
1682 case RTE_FLOW_ITEM_TYPE_MPLS:
1684 (const struct rte_flow_item_mpls *)item->spec;
1686 (const struct rte_flow_item_mpls *)item->mask;
1688 if (!mpls_spec || !mpls_mask) {
1689 rte_flow_error_set(error, EINVAL,
1690 RTE_FLOW_ERROR_TYPE_ITEM,
1692 "Invalid MPLS item");
1696 if (memcmp(mpls_mask->label_tc_s, label_mask, 3)) {
1697 rte_flow_error_set(error, EINVAL,
1698 RTE_FLOW_ERROR_TYPE_ITEM,
1700 "Invalid MPLS label mask");
1703 rte_memcpy(((uint8_t *)&label_be + 1),
1704 mpls_spec->label_tc_s, 3);
1705 filter->tenant_id = rte_be_to_cpu_32(label_be) >> 4;
1713 filter->tunnel_type = I40E_TUNNEL_TYPE_MPLSoUDP;
1715 filter->tunnel_type = I40E_TUNNEL_TYPE_MPLSoGRE;
1721 i40e_flow_parse_mpls_filter(struct rte_eth_dev *dev,
1722 const struct rte_flow_attr *attr,
1723 const struct rte_flow_item pattern[],
1724 const struct rte_flow_action actions[],
1725 struct rte_flow_error *error,
1726 union i40e_filter_t *filter)
1728 struct i40e_tunnel_filter_conf *tunnel_filter =
1729 &filter->consistent_tunnel_filter;
1732 ret = i40e_flow_parse_mpls_pattern(dev, pattern,
1733 error, tunnel_filter);
1737 ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
1741 ret = i40e_flow_parse_attr(attr, error);
1745 cons_filter_type = RTE_ETH_FILTER_TUNNEL;
1750 /* 1. Last in item should be NULL as range is not supported.
1751 * 2. Supported filter types: QINQ.
1752 * 3. Mask of fields which need to be matched should be
1754 * 4. Mask of fields which needn't to be matched should be
1758 i40e_flow_parse_qinq_pattern(__rte_unused struct rte_eth_dev *dev,
1759 const struct rte_flow_item *pattern,
1760 struct rte_flow_error *error,
1761 struct i40e_tunnel_filter_conf *filter)
1763 const struct rte_flow_item *item = pattern;
1764 const struct rte_flow_item_vlan *vlan_spec = NULL;
1765 const struct rte_flow_item_vlan *vlan_mask = NULL;
1766 const struct rte_flow_item_vlan *i_vlan_spec = NULL;
1767 const struct rte_flow_item_vlan *i_vlan_mask = NULL;
1768 const struct rte_flow_item_vlan *o_vlan_spec = NULL;
1769 const struct rte_flow_item_vlan *o_vlan_mask = NULL;
1771 enum rte_flow_item_type item_type;
1774 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1776 rte_flow_error_set(error, EINVAL,
1777 RTE_FLOW_ERROR_TYPE_ITEM,
1779 "Not support range");
1782 item_type = item->type;
1783 switch (item_type) {
1784 case RTE_FLOW_ITEM_TYPE_ETH:
1785 if (item->spec || item->mask) {
1786 rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_ITEM,
1789 "Invalid ETH item");
1793 case RTE_FLOW_ITEM_TYPE_VLAN:
1795 (const struct rte_flow_item_vlan *)item->spec;
1797 (const struct rte_flow_item_vlan *)item->mask;
1799 if (!(vlan_spec && vlan_mask)) {
1800 rte_flow_error_set(error, EINVAL,
1801 RTE_FLOW_ERROR_TYPE_ITEM,
1803 "Invalid vlan item");
1808 o_vlan_spec = vlan_spec;
1809 o_vlan_mask = vlan_mask;
1812 i_vlan_spec = vlan_spec;
1813 i_vlan_mask = vlan_mask;
1823 /* Get filter specification */
1824 if ((o_vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK)) &&
1825 (i_vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK))) {
1826 filter->outer_vlan = rte_be_to_cpu_16(o_vlan_spec->tci)
1828 filter->inner_vlan = rte_be_to_cpu_16(i_vlan_spec->tci)
1831 rte_flow_error_set(error, EINVAL,
1832 RTE_FLOW_ERROR_TYPE_ITEM,
1834 "Invalid filter type");
1838 filter->tunnel_type = I40E_TUNNEL_TYPE_QINQ;
1843 i40e_flow_parse_qinq_filter(struct rte_eth_dev *dev,
1844 const struct rte_flow_attr *attr,
1845 const struct rte_flow_item pattern[],
1846 const struct rte_flow_action actions[],
1847 struct rte_flow_error *error,
1848 union i40e_filter_t *filter)
1850 struct i40e_tunnel_filter_conf *tunnel_filter =
1851 &filter->consistent_tunnel_filter;
1854 ret = i40e_flow_parse_qinq_pattern(dev, pattern,
1855 error, tunnel_filter);
1859 ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
1863 ret = i40e_flow_parse_attr(attr, error);
1867 cons_filter_type = RTE_ETH_FILTER_TUNNEL;
1873 i40e_flow_validate(struct rte_eth_dev *dev,
1874 const struct rte_flow_attr *attr,
1875 const struct rte_flow_item pattern[],
1876 const struct rte_flow_action actions[],
1877 struct rte_flow_error *error)
1879 struct rte_flow_item *items; /* internal pattern w/o VOID items */
1880 parse_filter_t parse_filter;
1881 uint32_t item_num = 0; /* non-void item number of pattern*/
1886 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1887 NULL, "NULL pattern.");
1892 rte_flow_error_set(error, EINVAL,
1893 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1894 NULL, "NULL action.");
1899 rte_flow_error_set(error, EINVAL,
1900 RTE_FLOW_ERROR_TYPE_ATTR,
1901 NULL, "NULL attribute.");
1905 memset(&cons_filter, 0, sizeof(cons_filter));
1907 /* Get the non-void item number of pattern */
1908 while ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_END) {
1909 if ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_VOID)
1915 items = rte_zmalloc("i40e_pattern",
1916 item_num * sizeof(struct rte_flow_item), 0);
1918 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1919 NULL, "No memory for PMD internal items.");
1923 i40e_pattern_skip_void_item(items, pattern);
1925 /* Find if there's matched parse filter function */
1926 parse_filter = i40e_find_parse_filter_func(items);
1927 if (!parse_filter) {
1928 rte_flow_error_set(error, EINVAL,
1929 RTE_FLOW_ERROR_TYPE_ITEM,
1930 pattern, "Unsupported pattern");
1934 ret = parse_filter(dev, attr, items, actions, error, &cons_filter);
1941 static struct rte_flow *
1942 i40e_flow_create(struct rte_eth_dev *dev,
1943 const struct rte_flow_attr *attr,
1944 const struct rte_flow_item pattern[],
1945 const struct rte_flow_action actions[],
1946 struct rte_flow_error *error)
1948 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1949 struct rte_flow *flow;
1952 flow = rte_zmalloc("i40e_flow", sizeof(struct rte_flow), 0);
1954 rte_flow_error_set(error, ENOMEM,
1955 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1956 "Failed to allocate memory");
1960 ret = i40e_flow_validate(dev, attr, pattern, actions, error);
1964 switch (cons_filter_type) {
1965 case RTE_ETH_FILTER_ETHERTYPE:
1966 ret = i40e_ethertype_filter_set(pf,
1967 &cons_filter.ethertype_filter, 1);
1970 flow->rule = TAILQ_LAST(&pf->ethertype.ethertype_list,
1971 i40e_ethertype_filter_list);
1973 case RTE_ETH_FILTER_FDIR:
1974 ret = i40e_add_del_fdir_filter(dev,
1975 &cons_filter.fdir_filter, 1);
1978 flow->rule = TAILQ_LAST(&pf->fdir.fdir_list,
1979 i40e_fdir_filter_list);
1981 case RTE_ETH_FILTER_TUNNEL:
1982 ret = i40e_dev_consistent_tunnel_filter_set(pf,
1983 &cons_filter.consistent_tunnel_filter, 1);
1986 flow->rule = TAILQ_LAST(&pf->tunnel.tunnel_list,
1987 i40e_tunnel_filter_list);
1993 flow->filter_type = cons_filter_type;
1994 TAILQ_INSERT_TAIL(&pf->flow_list, flow, node);
1998 rte_flow_error_set(error, -ret,
1999 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2000 "Failed to create flow.");
2006 i40e_flow_destroy(struct rte_eth_dev *dev,
2007 struct rte_flow *flow,
2008 struct rte_flow_error *error)
2010 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2011 enum rte_filter_type filter_type = flow->filter_type;
2014 switch (filter_type) {
2015 case RTE_ETH_FILTER_ETHERTYPE:
2016 ret = i40e_flow_destroy_ethertype_filter(pf,
2017 (struct i40e_ethertype_filter *)flow->rule);
2019 case RTE_ETH_FILTER_TUNNEL:
2020 ret = i40e_flow_destroy_tunnel_filter(pf,
2021 (struct i40e_tunnel_filter *)flow->rule);
2023 case RTE_ETH_FILTER_FDIR:
2024 ret = i40e_add_del_fdir_filter(dev,
2025 &((struct i40e_fdir_filter *)flow->rule)->fdir, 0);
2028 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
2035 TAILQ_REMOVE(&pf->flow_list, flow, node);
2038 rte_flow_error_set(error, -ret,
2039 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2040 "Failed to destroy flow.");
2046 i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
2047 struct i40e_ethertype_filter *filter)
2049 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2050 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
2051 struct i40e_ethertype_filter *node;
2052 struct i40e_control_filter_stats stats;
2056 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
2057 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
2058 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
2059 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
2060 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
2062 memset(&stats, 0, sizeof(stats));
2063 ret = i40e_aq_add_rem_control_packet_filter(hw,
2064 filter->input.mac_addr.addr_bytes,
2065 filter->input.ether_type,
2066 flags, pf->main_vsi->seid,
2067 filter->queue, 0, &stats, NULL);
2071 node = i40e_sw_ethertype_filter_lookup(ethertype_rule, &filter->input);
2075 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
2081 i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
2082 struct i40e_tunnel_filter *filter)
2084 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2085 struct i40e_vsi *vsi;
2086 struct i40e_pf_vf *vf;
2087 struct i40e_aqc_add_rm_cloud_filt_elem_ext cld_filter;
2088 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
2089 struct i40e_tunnel_filter *node;
2090 bool big_buffer = 0;
2093 memset(&cld_filter, 0, sizeof(cld_filter));
2094 ether_addr_copy((struct ether_addr *)&filter->input.outer_mac,
2095 (struct ether_addr *)&cld_filter.element.outer_mac);
2096 ether_addr_copy((struct ether_addr *)&filter->input.inner_mac,
2097 (struct ether_addr *)&cld_filter.element.inner_mac);
2098 cld_filter.element.inner_vlan = filter->input.inner_vlan;
2099 cld_filter.element.flags = filter->input.flags;
2100 cld_filter.element.tenant_id = filter->input.tenant_id;
2101 cld_filter.element.queue_number = filter->queue;
2102 rte_memcpy(cld_filter.general_fields,
2103 filter->input.general_fields,
2104 sizeof(cld_filter.general_fields));
2106 if (!filter->is_to_vf)
2109 vf = &pf->vfs[filter->vf_id];
2113 if (((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoUDP) ==
2114 I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoUDP) ||
2115 ((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ==
2116 I40E_AQC_ADD_CLOUD_FILTER_TEID_MPLSoGRE) ||
2117 ((filter->input.flags & I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ) ==
2118 I40E_AQC_ADD_CLOUD_FILTER_CUSTOM_QINQ))
2122 ret = i40e_aq_remove_cloud_filters_big_buffer(hw, vsi->seid,
2125 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
2126 &cld_filter.element, 1);
2130 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &filter->input);
2134 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
2140 i40e_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
2142 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2145 ret = i40e_flow_flush_fdir_filter(pf);
2147 rte_flow_error_set(error, -ret,
2148 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2149 "Failed to flush FDIR flows.");
2153 ret = i40e_flow_flush_ethertype_filter(pf);
2155 rte_flow_error_set(error, -ret,
2156 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2157 "Failed to ethertype flush flows.");
2161 ret = i40e_flow_flush_tunnel_filter(pf);
2163 rte_flow_error_set(error, -ret,
2164 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2165 "Failed to flush tunnel flows.");
2173 i40e_flow_flush_fdir_filter(struct i40e_pf *pf)
2175 struct rte_eth_dev *dev = pf->adapter->eth_dev;
2176 struct i40e_fdir_info *fdir_info = &pf->fdir;
2177 struct i40e_fdir_filter *fdir_filter;
2178 struct rte_flow *flow;
2182 ret = i40e_fdir_flush(dev);
2184 /* Delete FDIR filters in FDIR list. */
2185 while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
2186 ret = i40e_sw_fdir_filter_del(pf,
2187 &fdir_filter->fdir.input);
2192 /* Delete FDIR flows in flow list. */
2193 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
2194 if (flow->filter_type == RTE_ETH_FILTER_FDIR) {
2195 TAILQ_REMOVE(&pf->flow_list, flow, node);
2204 /* Flush all ethertype filters */
2206 i40e_flow_flush_ethertype_filter(struct i40e_pf *pf)
2208 struct i40e_ethertype_filter_list
2209 *ethertype_list = &pf->ethertype.ethertype_list;
2210 struct i40e_ethertype_filter *filter;
2211 struct rte_flow *flow;
2215 while ((filter = TAILQ_FIRST(ethertype_list))) {
2216 ret = i40e_flow_destroy_ethertype_filter(pf, filter);
2221 /* Delete ethertype flows in flow list. */
2222 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
2223 if (flow->filter_type == RTE_ETH_FILTER_ETHERTYPE) {
2224 TAILQ_REMOVE(&pf->flow_list, flow, node);
2232 /* Flush all tunnel filters */
2234 i40e_flow_flush_tunnel_filter(struct i40e_pf *pf)
2236 struct i40e_tunnel_filter_list
2237 *tunnel_list = &pf->tunnel.tunnel_list;
2238 struct i40e_tunnel_filter *filter;
2239 struct rte_flow *flow;
2243 while ((filter = TAILQ_FIRST(tunnel_list))) {
2244 ret = i40e_flow_destroy_tunnel_filter(pf, filter);
2249 /* Delete tunnel flows in flow list. */
2250 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
2251 if (flow->filter_type == RTE_ETH_FILTER_TUNNEL) {
2252 TAILQ_REMOVE(&pf->flow_list, flow, node);