4 * Copyright (c) 2016 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_pattern(__rte_unused struct rte_eth_dev *dev,
94 const struct rte_flow_item *pattern,
95 struct rte_flow_error *error,
96 struct rte_eth_tunnel_filter_conf *filter);
97 static int i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
98 const struct rte_flow_action *actions,
99 struct rte_flow_error *error,
100 struct rte_eth_tunnel_filter_conf *filter);
101 static int i40e_flow_parse_attr(const struct rte_flow_attr *attr,
102 struct rte_flow_error *error);
103 static int i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
104 const struct rte_flow_attr *attr,
105 const struct rte_flow_item pattern[],
106 const struct rte_flow_action actions[],
107 struct rte_flow_error *error,
108 union i40e_filter_t *filter);
109 static int i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
110 const struct rte_flow_attr *attr,
111 const struct rte_flow_item pattern[],
112 const struct rte_flow_action actions[],
113 struct rte_flow_error *error,
114 union i40e_filter_t *filter);
115 static int i40e_flow_parse_tunnel_filter(struct rte_eth_dev *dev,
116 const struct rte_flow_attr *attr,
117 const struct rte_flow_item pattern[],
118 const struct rte_flow_action actions[],
119 struct rte_flow_error *error,
120 union i40e_filter_t *filter);
121 static int i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
122 struct i40e_ethertype_filter *filter);
123 static int i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
124 struct i40e_tunnel_filter *filter);
125 static int i40e_flow_flush_fdir_filter(struct i40e_pf *pf);
126 static int i40e_flow_flush_ethertype_filter(struct i40e_pf *pf);
127 static int i40e_flow_flush_tunnel_filter(struct i40e_pf *pf);
129 const struct rte_flow_ops i40e_flow_ops = {
130 .validate = i40e_flow_validate,
131 .create = i40e_flow_create,
132 .destroy = i40e_flow_destroy,
133 .flush = i40e_flow_flush,
136 union i40e_filter_t cons_filter;
137 enum rte_filter_type cons_filter_type = RTE_ETH_FILTER_NONE;
139 /* Pattern matched ethertype filter */
140 static enum rte_flow_item_type pattern_ethertype[] = {
141 RTE_FLOW_ITEM_TYPE_ETH,
142 RTE_FLOW_ITEM_TYPE_END,
145 /* Pattern matched flow director filter */
146 static enum rte_flow_item_type pattern_fdir_ipv4[] = {
147 RTE_FLOW_ITEM_TYPE_IPV4,
148 RTE_FLOW_ITEM_TYPE_END,
151 static enum rte_flow_item_type pattern_fdir_ipv4_ext[] = {
152 RTE_FLOW_ITEM_TYPE_ETH,
153 RTE_FLOW_ITEM_TYPE_IPV4,
154 RTE_FLOW_ITEM_TYPE_END,
157 static enum rte_flow_item_type pattern_fdir_ipv4_udp[] = {
158 RTE_FLOW_ITEM_TYPE_IPV4,
159 RTE_FLOW_ITEM_TYPE_UDP,
160 RTE_FLOW_ITEM_TYPE_END,
163 static enum rte_flow_item_type pattern_fdir_ipv4_udp_ext[] = {
164 RTE_FLOW_ITEM_TYPE_ETH,
165 RTE_FLOW_ITEM_TYPE_IPV4,
166 RTE_FLOW_ITEM_TYPE_UDP,
167 RTE_FLOW_ITEM_TYPE_END,
170 static enum rte_flow_item_type pattern_fdir_ipv4_tcp[] = {
171 RTE_FLOW_ITEM_TYPE_IPV4,
172 RTE_FLOW_ITEM_TYPE_TCP,
173 RTE_FLOW_ITEM_TYPE_END,
176 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_ext[] = {
177 RTE_FLOW_ITEM_TYPE_ETH,
178 RTE_FLOW_ITEM_TYPE_IPV4,
179 RTE_FLOW_ITEM_TYPE_TCP,
180 RTE_FLOW_ITEM_TYPE_END,
183 static enum rte_flow_item_type pattern_fdir_ipv4_sctp[] = {
184 RTE_FLOW_ITEM_TYPE_IPV4,
185 RTE_FLOW_ITEM_TYPE_SCTP,
186 RTE_FLOW_ITEM_TYPE_END,
189 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_ext[] = {
190 RTE_FLOW_ITEM_TYPE_ETH,
191 RTE_FLOW_ITEM_TYPE_IPV4,
192 RTE_FLOW_ITEM_TYPE_SCTP,
193 RTE_FLOW_ITEM_TYPE_END,
196 static enum rte_flow_item_type pattern_fdir_ipv6[] = {
197 RTE_FLOW_ITEM_TYPE_IPV6,
198 RTE_FLOW_ITEM_TYPE_END,
201 static enum rte_flow_item_type pattern_fdir_ipv6_ext[] = {
202 RTE_FLOW_ITEM_TYPE_ETH,
203 RTE_FLOW_ITEM_TYPE_IPV6,
204 RTE_FLOW_ITEM_TYPE_END,
207 static enum rte_flow_item_type pattern_fdir_ipv6_udp[] = {
208 RTE_FLOW_ITEM_TYPE_IPV6,
209 RTE_FLOW_ITEM_TYPE_UDP,
210 RTE_FLOW_ITEM_TYPE_END,
213 static enum rte_flow_item_type pattern_fdir_ipv6_udp_ext[] = {
214 RTE_FLOW_ITEM_TYPE_ETH,
215 RTE_FLOW_ITEM_TYPE_IPV6,
216 RTE_FLOW_ITEM_TYPE_UDP,
217 RTE_FLOW_ITEM_TYPE_END,
220 static enum rte_flow_item_type pattern_fdir_ipv6_tcp[] = {
221 RTE_FLOW_ITEM_TYPE_IPV6,
222 RTE_FLOW_ITEM_TYPE_TCP,
223 RTE_FLOW_ITEM_TYPE_END,
226 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_ext[] = {
227 RTE_FLOW_ITEM_TYPE_ETH,
228 RTE_FLOW_ITEM_TYPE_IPV6,
229 RTE_FLOW_ITEM_TYPE_TCP,
230 RTE_FLOW_ITEM_TYPE_END,
233 static enum rte_flow_item_type pattern_fdir_ipv6_sctp[] = {
234 RTE_FLOW_ITEM_TYPE_IPV6,
235 RTE_FLOW_ITEM_TYPE_SCTP,
236 RTE_FLOW_ITEM_TYPE_END,
239 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_ext[] = {
240 RTE_FLOW_ITEM_TYPE_ETH,
241 RTE_FLOW_ITEM_TYPE_IPV6,
242 RTE_FLOW_ITEM_TYPE_SCTP,
243 RTE_FLOW_ITEM_TYPE_END,
246 /* Pattern matched tunnel filter */
247 static enum rte_flow_item_type pattern_vxlan_1[] = {
248 RTE_FLOW_ITEM_TYPE_ETH,
249 RTE_FLOW_ITEM_TYPE_IPV4,
250 RTE_FLOW_ITEM_TYPE_UDP,
251 RTE_FLOW_ITEM_TYPE_VXLAN,
252 RTE_FLOW_ITEM_TYPE_ETH,
253 RTE_FLOW_ITEM_TYPE_END,
256 static enum rte_flow_item_type pattern_vxlan_2[] = {
257 RTE_FLOW_ITEM_TYPE_ETH,
258 RTE_FLOW_ITEM_TYPE_IPV6,
259 RTE_FLOW_ITEM_TYPE_UDP,
260 RTE_FLOW_ITEM_TYPE_VXLAN,
261 RTE_FLOW_ITEM_TYPE_ETH,
262 RTE_FLOW_ITEM_TYPE_END,
265 static enum rte_flow_item_type pattern_vxlan_3[] = {
266 RTE_FLOW_ITEM_TYPE_ETH,
267 RTE_FLOW_ITEM_TYPE_IPV4,
268 RTE_FLOW_ITEM_TYPE_UDP,
269 RTE_FLOW_ITEM_TYPE_VXLAN,
270 RTE_FLOW_ITEM_TYPE_ETH,
271 RTE_FLOW_ITEM_TYPE_VLAN,
272 RTE_FLOW_ITEM_TYPE_END,
275 static enum rte_flow_item_type pattern_vxlan_4[] = {
276 RTE_FLOW_ITEM_TYPE_ETH,
277 RTE_FLOW_ITEM_TYPE_IPV6,
278 RTE_FLOW_ITEM_TYPE_UDP,
279 RTE_FLOW_ITEM_TYPE_VXLAN,
280 RTE_FLOW_ITEM_TYPE_ETH,
281 RTE_FLOW_ITEM_TYPE_VLAN,
282 RTE_FLOW_ITEM_TYPE_END,
285 static struct i40e_valid_pattern i40e_supported_patterns[] = {
287 { pattern_ethertype, i40e_flow_parse_ethertype_filter },
289 { pattern_fdir_ipv4, i40e_flow_parse_fdir_filter },
290 { pattern_fdir_ipv4_ext, i40e_flow_parse_fdir_filter },
291 { pattern_fdir_ipv4_udp, i40e_flow_parse_fdir_filter },
292 { pattern_fdir_ipv4_udp_ext, i40e_flow_parse_fdir_filter },
293 { pattern_fdir_ipv4_tcp, i40e_flow_parse_fdir_filter },
294 { pattern_fdir_ipv4_tcp_ext, i40e_flow_parse_fdir_filter },
295 { pattern_fdir_ipv4_sctp, i40e_flow_parse_fdir_filter },
296 { pattern_fdir_ipv4_sctp_ext, i40e_flow_parse_fdir_filter },
297 { pattern_fdir_ipv6, i40e_flow_parse_fdir_filter },
298 { pattern_fdir_ipv6_ext, i40e_flow_parse_fdir_filter },
299 { pattern_fdir_ipv6_udp, i40e_flow_parse_fdir_filter },
300 { pattern_fdir_ipv6_udp_ext, i40e_flow_parse_fdir_filter },
301 { pattern_fdir_ipv6_tcp, i40e_flow_parse_fdir_filter },
302 { pattern_fdir_ipv6_tcp_ext, i40e_flow_parse_fdir_filter },
303 { pattern_fdir_ipv6_sctp, i40e_flow_parse_fdir_filter },
304 { pattern_fdir_ipv6_sctp_ext, i40e_flow_parse_fdir_filter },
306 { pattern_vxlan_1, i40e_flow_parse_tunnel_filter },
307 { pattern_vxlan_2, i40e_flow_parse_tunnel_filter },
308 { pattern_vxlan_3, i40e_flow_parse_tunnel_filter },
309 { pattern_vxlan_4, i40e_flow_parse_tunnel_filter },
312 #define NEXT_ITEM_OF_ACTION(act, actions, index) \
314 act = actions + index; \
315 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) { \
317 act = actions + index; \
321 /* Find the first VOID or non-VOID item pointer */
322 static const struct rte_flow_item *
323 i40e_find_first_item(const struct rte_flow_item *item, bool is_void)
327 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
329 is_find = item->type == RTE_FLOW_ITEM_TYPE_VOID;
331 is_find = item->type != RTE_FLOW_ITEM_TYPE_VOID;
339 /* Skip all VOID items of the pattern */
341 i40e_pattern_skip_void_item(struct rte_flow_item *items,
342 const struct rte_flow_item *pattern)
344 uint32_t cpy_count = 0;
345 const struct rte_flow_item *pb = pattern, *pe = pattern;
348 /* Find a non-void item first */
349 pb = i40e_find_first_item(pb, false);
350 if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
355 /* Find a void item */
356 pe = i40e_find_first_item(pb + 1, true);
359 rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
363 if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
370 /* Copy the END item. */
371 rte_memcpy(items, pe, sizeof(struct rte_flow_item));
374 /* Check if the pattern matches a supported item type array */
376 i40e_match_pattern(enum rte_flow_item_type *item_array,
377 struct rte_flow_item *pattern)
379 struct rte_flow_item *item = pattern;
381 while ((*item_array == item->type) &&
382 (*item_array != RTE_FLOW_ITEM_TYPE_END)) {
387 return (*item_array == RTE_FLOW_ITEM_TYPE_END &&
388 item->type == RTE_FLOW_ITEM_TYPE_END);
391 /* Find if there's parse filter function matched */
392 static parse_filter_t
393 i40e_find_parse_filter_func(struct rte_flow_item *pattern)
395 parse_filter_t parse_filter = NULL;
398 for (; i < RTE_DIM(i40e_supported_patterns); i++) {
399 if (i40e_match_pattern(i40e_supported_patterns[i].items,
401 parse_filter = i40e_supported_patterns[i].parse_filter;
409 /* Parse attributes */
411 i40e_flow_parse_attr(const struct rte_flow_attr *attr,
412 struct rte_flow_error *error)
414 /* Must be input direction */
415 if (!attr->ingress) {
416 rte_flow_error_set(error, EINVAL,
417 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
418 attr, "Only support ingress.");
424 rte_flow_error_set(error, EINVAL,
425 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
426 attr, "Not support egress.");
431 if (attr->priority) {
432 rte_flow_error_set(error, EINVAL,
433 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
434 attr, "Not support priority.");
440 rte_flow_error_set(error, EINVAL,
441 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
442 attr, "Not support group.");
450 i40e_get_outer_vlan(struct rte_eth_dev *dev)
452 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
453 int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
463 i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
466 tpid = (reg_r >> I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT) & 0xFFFF;
471 /* 1. Last in item should be NULL as range is not supported.
472 * 2. Supported filter types: MAC_ETHTYPE and ETHTYPE.
473 * 3. SRC mac_addr mask should be 00:00:00:00:00:00.
474 * 4. DST mac_addr mask should be 00:00:00:00:00:00 or
476 * 5. Ether_type mask should be 0xFFFF.
479 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
480 const struct rte_flow_item *pattern,
481 struct rte_flow_error *error,
482 struct rte_eth_ethertype_filter *filter)
484 const struct rte_flow_item *item = pattern;
485 const struct rte_flow_item_eth *eth_spec;
486 const struct rte_flow_item_eth *eth_mask;
487 enum rte_flow_item_type item_type;
490 outer_tpid = i40e_get_outer_vlan(dev);
492 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
494 rte_flow_error_set(error, EINVAL,
495 RTE_FLOW_ERROR_TYPE_ITEM,
497 "Not support range");
500 item_type = item->type;
502 case RTE_FLOW_ITEM_TYPE_ETH:
503 eth_spec = (const struct rte_flow_item_eth *)item->spec;
504 eth_mask = (const struct rte_flow_item_eth *)item->mask;
505 /* Get the MAC info. */
506 if (!eth_spec || !eth_mask) {
507 rte_flow_error_set(error, EINVAL,
508 RTE_FLOW_ERROR_TYPE_ITEM,
510 "NULL ETH spec/mask");
514 /* Mask bits of source MAC address must be full of 0.
515 * Mask bits of destination MAC address must be full
518 if (!is_zero_ether_addr(ð_mask->src) ||
519 (!is_zero_ether_addr(ð_mask->dst) &&
520 !is_broadcast_ether_addr(ð_mask->dst))) {
521 rte_flow_error_set(error, EINVAL,
522 RTE_FLOW_ERROR_TYPE_ITEM,
524 "Invalid MAC_addr mask");
528 if ((eth_mask->type & UINT16_MAX) != UINT16_MAX) {
529 rte_flow_error_set(error, EINVAL,
530 RTE_FLOW_ERROR_TYPE_ITEM,
532 "Invalid ethertype mask");
536 /* If mask bits of destination MAC address
537 * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
539 if (is_broadcast_ether_addr(ð_mask->dst)) {
540 filter->mac_addr = eth_spec->dst;
541 filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
543 filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
545 filter->ether_type = rte_be_to_cpu_16(eth_spec->type);
547 if (filter->ether_type == ETHER_TYPE_IPv4 ||
548 filter->ether_type == ETHER_TYPE_IPv6 ||
549 filter->ether_type == outer_tpid) {
550 rte_flow_error_set(error, EINVAL,
551 RTE_FLOW_ERROR_TYPE_ITEM,
553 "Unsupported ether_type in"
554 " control packet filter.");
566 /* Ethertype action only supports QUEUE or DROP. */
568 i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
569 const struct rte_flow_action *actions,
570 struct rte_flow_error *error,
571 struct rte_eth_ethertype_filter *filter)
573 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
574 const struct rte_flow_action *act;
575 const struct rte_flow_action_queue *act_q;
578 /* Check if the first non-void action is QUEUE or DROP. */
579 NEXT_ITEM_OF_ACTION(act, actions, index);
580 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
581 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
582 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
583 act, "Not supported action.");
587 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
588 act_q = (const struct rte_flow_action_queue *)act->conf;
589 filter->queue = act_q->index;
590 if (filter->queue >= pf->dev_data->nb_rx_queues) {
591 rte_flow_error_set(error, EINVAL,
592 RTE_FLOW_ERROR_TYPE_ACTION,
593 act, "Invalid queue ID for"
594 " ethertype_filter.");
598 filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
601 /* Check if the next non-void item is END */
603 NEXT_ITEM_OF_ACTION(act, actions, index);
604 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
605 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
606 act, "Not supported action.");
614 i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
615 const struct rte_flow_attr *attr,
616 const struct rte_flow_item pattern[],
617 const struct rte_flow_action actions[],
618 struct rte_flow_error *error,
619 union i40e_filter_t *filter)
621 struct rte_eth_ethertype_filter *ethertype_filter =
622 &filter->ethertype_filter;
625 ret = i40e_flow_parse_ethertype_pattern(dev, pattern, error,
630 ret = i40e_flow_parse_ethertype_action(dev, actions, error,
635 ret = i40e_flow_parse_attr(attr, error);
639 cons_filter_type = RTE_ETH_FILTER_ETHERTYPE;
644 /* 1. Last in item should be NULL as range is not supported.
645 * 2. Supported flow type and input set: refer to array
646 * default_inset_table in i40e_ethdev.c.
647 * 3. Mask of fields which need to be matched should be
649 * 4. Mask of fields which needn't to be matched should be
653 i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
654 const struct rte_flow_item *pattern,
655 struct rte_flow_error *error,
656 struct rte_eth_fdir_filter *filter)
658 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
659 const struct rte_flow_item *item = pattern;
660 const struct rte_flow_item_eth *eth_spec, *eth_mask;
661 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
662 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
663 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
664 const struct rte_flow_item_udp *udp_spec, *udp_mask;
665 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
666 const struct rte_flow_item_vf *vf_spec;
667 uint32_t flow_type = RTE_ETH_FLOW_UNKNOWN;
668 enum i40e_filter_pctype pctype;
669 uint64_t input_set = I40E_INSET_NONE;
670 uint16_t flag_offset;
671 enum rte_flow_item_type item_type;
672 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
675 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
677 rte_flow_error_set(error, EINVAL,
678 RTE_FLOW_ERROR_TYPE_ITEM,
680 "Not support range");
683 item_type = item->type;
685 case RTE_FLOW_ITEM_TYPE_ETH:
686 eth_spec = (const struct rte_flow_item_eth *)item->spec;
687 eth_mask = (const struct rte_flow_item_eth *)item->mask;
688 if (eth_spec || eth_mask) {
689 rte_flow_error_set(error, EINVAL,
690 RTE_FLOW_ERROR_TYPE_ITEM,
692 "Invalid ETH spec/mask");
696 case RTE_FLOW_ITEM_TYPE_IPV4:
697 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
699 (const struct rte_flow_item_ipv4 *)item->spec;
701 (const struct rte_flow_item_ipv4 *)item->mask;
702 if (!ipv4_spec || !ipv4_mask) {
703 rte_flow_error_set(error, EINVAL,
704 RTE_FLOW_ERROR_TYPE_ITEM,
706 "NULL IPv4 spec/mask");
710 /* Check IPv4 mask and update input set */
711 if (ipv4_mask->hdr.version_ihl ||
712 ipv4_mask->hdr.total_length ||
713 ipv4_mask->hdr.packet_id ||
714 ipv4_mask->hdr.fragment_offset ||
715 ipv4_mask->hdr.hdr_checksum) {
716 rte_flow_error_set(error, EINVAL,
717 RTE_FLOW_ERROR_TYPE_ITEM,
719 "Invalid IPv4 mask.");
723 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
724 input_set |= I40E_INSET_IPV4_SRC;
725 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
726 input_set |= I40E_INSET_IPV4_DST;
727 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
728 input_set |= I40E_INSET_IPV4_TOS;
729 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
730 input_set |= I40E_INSET_IPV4_TTL;
731 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
732 input_set |= I40E_INSET_IPV4_PROTO;
734 /* Get filter info */
735 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_OTHER;
736 /* Check if it is fragment. */
738 rte_be_to_cpu_16(ipv4_spec->hdr.fragment_offset);
739 if (flag_offset & IPV4_HDR_OFFSET_MASK ||
740 flag_offset & IPV4_HDR_MF_FLAG)
741 flow_type = RTE_ETH_FLOW_FRAG_IPV4;
743 /* Get the filter info */
744 filter->input.flow.ip4_flow.proto =
745 ipv4_spec->hdr.next_proto_id;
746 filter->input.flow.ip4_flow.tos =
747 ipv4_spec->hdr.type_of_service;
748 filter->input.flow.ip4_flow.ttl =
749 ipv4_spec->hdr.time_to_live;
750 filter->input.flow.ip4_flow.src_ip =
751 ipv4_spec->hdr.src_addr;
752 filter->input.flow.ip4_flow.dst_ip =
753 ipv4_spec->hdr.dst_addr;
756 case RTE_FLOW_ITEM_TYPE_IPV6:
757 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
759 (const struct rte_flow_item_ipv6 *)item->spec;
761 (const struct rte_flow_item_ipv6 *)item->mask;
762 if (!ipv6_spec || !ipv6_mask) {
763 rte_flow_error_set(error, EINVAL,
764 RTE_FLOW_ERROR_TYPE_ITEM,
766 "NULL IPv6 spec/mask");
770 /* Check IPv6 mask and update input set */
771 if (ipv6_mask->hdr.payload_len) {
772 rte_flow_error_set(error, EINVAL,
773 RTE_FLOW_ERROR_TYPE_ITEM,
775 "Invalid IPv6 mask");
779 /* SCR and DST address of IPv6 shouldn't be masked */
780 for (j = 0; j < RTE_DIM(ipv6_mask->hdr.src_addr); j++) {
781 if (ipv6_mask->hdr.src_addr[j] != UINT8_MAX ||
782 ipv6_mask->hdr.dst_addr[j] != UINT8_MAX) {
783 rte_flow_error_set(error, EINVAL,
784 RTE_FLOW_ERROR_TYPE_ITEM,
786 "Invalid IPv6 mask");
791 input_set |= I40E_INSET_IPV6_SRC;
792 input_set |= I40E_INSET_IPV6_DST;
794 if ((ipv6_mask->hdr.vtc_flow &
795 rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
796 == rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
797 input_set |= I40E_INSET_IPV6_TC;
798 if (ipv6_mask->hdr.proto == UINT8_MAX)
799 input_set |= I40E_INSET_IPV6_NEXT_HDR;
800 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
801 input_set |= I40E_INSET_IPV6_HOP_LIMIT;
803 /* Get filter info */
804 filter->input.flow.ipv6_flow.tc =
805 (uint8_t)(ipv6_spec->hdr.vtc_flow <<
807 filter->input.flow.ipv6_flow.proto =
808 ipv6_spec->hdr.proto;
809 filter->input.flow.ipv6_flow.hop_limits =
810 ipv6_spec->hdr.hop_limits;
812 rte_memcpy(filter->input.flow.ipv6_flow.src_ip,
813 ipv6_spec->hdr.src_addr, 16);
814 rte_memcpy(filter->input.flow.ipv6_flow.dst_ip,
815 ipv6_spec->hdr.dst_addr, 16);
817 /* Check if it is fragment. */
818 if (ipv6_spec->hdr.proto == I40E_IPV6_FRAG_HEADER)
819 flow_type = RTE_ETH_FLOW_FRAG_IPV6;
821 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_OTHER;
823 case RTE_FLOW_ITEM_TYPE_TCP:
824 tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
825 tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
826 if (!tcp_spec || !tcp_mask) {
827 rte_flow_error_set(error, EINVAL,
828 RTE_FLOW_ERROR_TYPE_ITEM,
830 "NULL TCP spec/mask");
834 /* Check TCP mask and update input set */
835 if (tcp_mask->hdr.sent_seq ||
836 tcp_mask->hdr.recv_ack ||
837 tcp_mask->hdr.data_off ||
838 tcp_mask->hdr.tcp_flags ||
839 tcp_mask->hdr.rx_win ||
840 tcp_mask->hdr.cksum ||
841 tcp_mask->hdr.tcp_urp) {
842 rte_flow_error_set(error, EINVAL,
843 RTE_FLOW_ERROR_TYPE_ITEM,
849 if (tcp_mask->hdr.src_port != UINT16_MAX ||
850 tcp_mask->hdr.dst_port != UINT16_MAX) {
851 rte_flow_error_set(error, EINVAL,
852 RTE_FLOW_ERROR_TYPE_ITEM,
858 input_set |= I40E_INSET_SRC_PORT;
859 input_set |= I40E_INSET_DST_PORT;
861 /* Get filter info */
862 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
863 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_TCP;
864 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
865 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_TCP;
867 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
868 filter->input.flow.tcp4_flow.src_port =
869 tcp_spec->hdr.src_port;
870 filter->input.flow.tcp4_flow.dst_port =
871 tcp_spec->hdr.dst_port;
872 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
873 filter->input.flow.tcp6_flow.src_port =
874 tcp_spec->hdr.src_port;
875 filter->input.flow.tcp6_flow.dst_port =
876 tcp_spec->hdr.dst_port;
879 case RTE_FLOW_ITEM_TYPE_UDP:
880 udp_spec = (const struct rte_flow_item_udp *)item->spec;
881 udp_mask = (const struct rte_flow_item_udp *)item->mask;
882 if (!udp_spec || !udp_mask) {
883 rte_flow_error_set(error, EINVAL,
884 RTE_FLOW_ERROR_TYPE_ITEM,
886 "NULL UDP spec/mask");
890 /* Check UDP mask and update input set*/
891 if (udp_mask->hdr.dgram_len ||
892 udp_mask->hdr.dgram_cksum) {
893 rte_flow_error_set(error, EINVAL,
894 RTE_FLOW_ERROR_TYPE_ITEM,
900 if (udp_mask->hdr.src_port != UINT16_MAX ||
901 udp_mask->hdr.dst_port != UINT16_MAX) {
902 rte_flow_error_set(error, EINVAL,
903 RTE_FLOW_ERROR_TYPE_ITEM,
909 input_set |= I40E_INSET_SRC_PORT;
910 input_set |= I40E_INSET_DST_PORT;
912 /* Get filter info */
913 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
915 RTE_ETH_FLOW_NONFRAG_IPV4_UDP;
916 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
918 RTE_ETH_FLOW_NONFRAG_IPV6_UDP;
920 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
921 filter->input.flow.udp4_flow.src_port =
922 udp_spec->hdr.src_port;
923 filter->input.flow.udp4_flow.dst_port =
924 udp_spec->hdr.dst_port;
925 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
926 filter->input.flow.udp6_flow.src_port =
927 udp_spec->hdr.src_port;
928 filter->input.flow.udp6_flow.dst_port =
929 udp_spec->hdr.dst_port;
932 case RTE_FLOW_ITEM_TYPE_SCTP:
934 (const struct rte_flow_item_sctp *)item->spec;
936 (const struct rte_flow_item_sctp *)item->mask;
937 if (!sctp_spec || !sctp_mask) {
938 rte_flow_error_set(error, EINVAL,
939 RTE_FLOW_ERROR_TYPE_ITEM,
941 "NULL SCTP spec/mask");
945 /* Check SCTP mask and update input set */
946 if (sctp_mask->hdr.cksum) {
947 rte_flow_error_set(error, EINVAL,
948 RTE_FLOW_ERROR_TYPE_ITEM,
954 if (sctp_mask->hdr.src_port != UINT16_MAX ||
955 sctp_mask->hdr.dst_port != UINT16_MAX ||
956 sctp_mask->hdr.tag != UINT32_MAX) {
957 rte_flow_error_set(error, EINVAL,
958 RTE_FLOW_ERROR_TYPE_ITEM,
963 input_set |= I40E_INSET_SRC_PORT;
964 input_set |= I40E_INSET_DST_PORT;
965 input_set |= I40E_INSET_SCTP_VT;
967 /* Get filter info */
968 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
969 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_SCTP;
970 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
971 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_SCTP;
973 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
974 filter->input.flow.sctp4_flow.src_port =
975 sctp_spec->hdr.src_port;
976 filter->input.flow.sctp4_flow.dst_port =
977 sctp_spec->hdr.dst_port;
978 filter->input.flow.sctp4_flow.verify_tag =
980 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
981 filter->input.flow.sctp6_flow.src_port =
982 sctp_spec->hdr.src_port;
983 filter->input.flow.sctp6_flow.dst_port =
984 sctp_spec->hdr.dst_port;
985 filter->input.flow.sctp6_flow.verify_tag =
989 case RTE_FLOW_ITEM_TYPE_VF:
990 vf_spec = (const struct rte_flow_item_vf *)item->spec;
991 filter->input.flow_ext.is_vf = 1;
992 filter->input.flow_ext.dst_id = vf_spec->id;
993 if (filter->input.flow_ext.is_vf &&
994 filter->input.flow_ext.dst_id >= pf->vf_num) {
995 rte_flow_error_set(error, EINVAL,
996 RTE_FLOW_ERROR_TYPE_ITEM,
998 "Invalid VF ID for FDIR.");
1007 pctype = i40e_flowtype_to_pctype(flow_type);
1008 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
1009 rte_flow_error_set(error, EINVAL,
1010 RTE_FLOW_ERROR_TYPE_ITEM, item,
1011 "Unsupported flow type");
1015 if (input_set != i40e_get_default_input_set(pctype)) {
1016 rte_flow_error_set(error, EINVAL,
1017 RTE_FLOW_ERROR_TYPE_ITEM, item,
1018 "Invalid input set.");
1021 filter->input.flow_type = flow_type;
1026 /* Parse to get the action info of a FDIR filter.
1027 * FDIR action supports QUEUE or (QUEUE + MARK).
1030 i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
1031 const struct rte_flow_action *actions,
1032 struct rte_flow_error *error,
1033 struct rte_eth_fdir_filter *filter)
1035 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1036 const struct rte_flow_action *act;
1037 const struct rte_flow_action_queue *act_q;
1038 const struct rte_flow_action_mark *mark_spec;
1041 /* Check if the first non-void action is QUEUE or DROP. */
1042 NEXT_ITEM_OF_ACTION(act, actions, index);
1043 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
1044 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
1045 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1046 act, "Invalid action.");
1050 act_q = (const struct rte_flow_action_queue *)act->conf;
1051 filter->action.flex_off = 0;
1052 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE)
1053 filter->action.behavior = RTE_ETH_FDIR_ACCEPT;
1055 filter->action.behavior = RTE_ETH_FDIR_REJECT;
1057 filter->action.report_status = RTE_ETH_FDIR_REPORT_ID;
1058 filter->action.rx_queue = act_q->index;
1060 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1061 rte_flow_error_set(error, EINVAL,
1062 RTE_FLOW_ERROR_TYPE_ACTION, act,
1063 "Invalid queue ID for FDIR.");
1067 /* Check if the next non-void item is MARK or END. */
1069 NEXT_ITEM_OF_ACTION(act, actions, index);
1070 if (act->type != RTE_FLOW_ACTION_TYPE_MARK &&
1071 act->type != RTE_FLOW_ACTION_TYPE_END) {
1072 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1073 act, "Invalid action.");
1077 if (act->type == RTE_FLOW_ACTION_TYPE_MARK) {
1078 mark_spec = (const struct rte_flow_action_mark *)act->conf;
1079 filter->soft_id = mark_spec->id;
1081 /* Check if the next non-void item is END */
1083 NEXT_ITEM_OF_ACTION(act, actions, index);
1084 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1085 rte_flow_error_set(error, EINVAL,
1086 RTE_FLOW_ERROR_TYPE_ACTION,
1087 act, "Invalid action.");
1096 i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
1097 const struct rte_flow_attr *attr,
1098 const struct rte_flow_item pattern[],
1099 const struct rte_flow_action actions[],
1100 struct rte_flow_error *error,
1101 union i40e_filter_t *filter)
1103 struct rte_eth_fdir_filter *fdir_filter =
1104 &filter->fdir_filter;
1107 ret = i40e_flow_parse_fdir_pattern(dev, pattern, error, fdir_filter);
1111 ret = i40e_flow_parse_fdir_action(dev, actions, error, fdir_filter);
1115 ret = i40e_flow_parse_attr(attr, error);
1119 cons_filter_type = RTE_ETH_FILTER_FDIR;
1121 if (dev->data->dev_conf.fdir_conf.mode !=
1122 RTE_FDIR_MODE_PERFECT) {
1123 rte_flow_error_set(error, ENOTSUP,
1124 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1126 "Check the mode in fdir_conf.");
1133 /* Parse to get the action info of a tunnle filter
1134 * Tunnel action only supports QUEUE.
1137 i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
1138 const struct rte_flow_action *actions,
1139 struct rte_flow_error *error,
1140 struct rte_eth_tunnel_filter_conf *filter)
1142 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1143 const struct rte_flow_action *act;
1144 const struct rte_flow_action_queue *act_q;
1147 /* Check if the first non-void action is QUEUE. */
1148 NEXT_ITEM_OF_ACTION(act, actions, index);
1149 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
1150 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1151 act, "Not supported action.");
1155 act_q = (const struct rte_flow_action_queue *)act->conf;
1156 filter->queue_id = act_q->index;
1157 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
1158 rte_flow_error_set(error, EINVAL,
1159 RTE_FLOW_ERROR_TYPE_ACTION,
1160 act, "Invalid queue ID for tunnel filter");
1164 /* Check if the next non-void item is END */
1166 NEXT_ITEM_OF_ACTION(act, actions, index);
1167 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1168 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1169 act, "Not supported action.");
1177 i40e_check_tenant_id_mask(const uint8_t *mask)
1182 for (j = 0; j < I40E_TENANT_ARRAY_NUM; j++) {
1183 if (*(mask + j) == UINT8_MAX) {
1184 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1187 } else if (*(mask + j) == 0) {
1188 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1199 /* 1. Last in item should be NULL as range is not supported.
1200 * 2. Supported filter types: IMAC_IVLAN_TENID, IMAC_IVLAN,
1201 * IMAC_TENID, OMAC_TENID_IMAC and IMAC.
1202 * 3. Mask of fields which need to be matched should be
1204 * 4. Mask of fields which needn't to be matched should be
1208 i40e_flow_parse_vxlan_pattern(const struct rte_flow_item *pattern,
1209 struct rte_flow_error *error,
1210 struct rte_eth_tunnel_filter_conf *filter)
1212 const struct rte_flow_item *item = pattern;
1213 const struct rte_flow_item_eth *eth_spec;
1214 const struct rte_flow_item_eth *eth_mask;
1215 const struct rte_flow_item_eth *o_eth_spec = NULL;
1216 const struct rte_flow_item_eth *o_eth_mask = NULL;
1217 const struct rte_flow_item_vxlan *vxlan_spec = NULL;
1218 const struct rte_flow_item_vxlan *vxlan_mask = NULL;
1219 const struct rte_flow_item_eth *i_eth_spec = NULL;
1220 const struct rte_flow_item_eth *i_eth_mask = NULL;
1221 const struct rte_flow_item_vlan *vlan_spec = NULL;
1222 const struct rte_flow_item_vlan *vlan_mask = NULL;
1223 bool is_vni_masked = 0;
1224 enum rte_flow_item_type item_type;
1225 bool vxlan_flag = 0;
1226 uint32_t tenant_id_be = 0;
1228 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1230 rte_flow_error_set(error, EINVAL,
1231 RTE_FLOW_ERROR_TYPE_ITEM,
1233 "Not support range");
1236 item_type = item->type;
1237 switch (item_type) {
1238 case RTE_FLOW_ITEM_TYPE_ETH:
1239 eth_spec = (const struct rte_flow_item_eth *)item->spec;
1240 eth_mask = (const struct rte_flow_item_eth *)item->mask;
1241 if ((!eth_spec && eth_mask) ||
1242 (eth_spec && !eth_mask)) {
1243 rte_flow_error_set(error, EINVAL,
1244 RTE_FLOW_ERROR_TYPE_ITEM,
1246 "Invalid ether spec/mask");
1250 if (eth_spec && eth_mask) {
1251 /* DST address of inner MAC shouldn't be masked.
1252 * SRC address of Inner MAC should be masked.
1254 if (!is_broadcast_ether_addr(ð_mask->dst) ||
1255 !is_zero_ether_addr(ð_mask->src) ||
1257 rte_flow_error_set(error, EINVAL,
1258 RTE_FLOW_ERROR_TYPE_ITEM,
1260 "Invalid ether spec/mask");
1265 rte_memcpy(&filter->outer_mac,
1269 rte_memcpy(&filter->inner_mac,
1275 o_eth_spec = eth_spec;
1276 o_eth_mask = eth_mask;
1278 i_eth_spec = eth_spec;
1279 i_eth_mask = eth_mask;
1283 case RTE_FLOW_ITEM_TYPE_VLAN:
1285 (const struct rte_flow_item_vlan *)item->spec;
1287 (const struct rte_flow_item_vlan *)item->mask;
1290 (const struct rte_flow_item_vlan *)item->spec;
1292 (const struct rte_flow_item_vlan *)item->mask;
1293 if (!(vlan_spec && vlan_mask)) {
1294 rte_flow_error_set(error, EINVAL,
1295 RTE_FLOW_ERROR_TYPE_ITEM,
1297 "Invalid vlan item");
1301 if (vlan_spec || vlan_mask)
1302 rte_flow_error_set(error, EINVAL,
1303 RTE_FLOW_ERROR_TYPE_ITEM,
1305 "Invalid vlan item");
1309 case RTE_FLOW_ITEM_TYPE_IPV4:
1310 filter->ip_type = RTE_TUNNEL_IPTYPE_IPV4;
1311 /* IPv4 is used to describe protocol,
1312 * spec and mask should be NULL.
1314 if (item->spec || item->mask) {
1315 rte_flow_error_set(error, EINVAL,
1316 RTE_FLOW_ERROR_TYPE_ITEM,
1318 "Invalid IPv4 item");
1322 case RTE_FLOW_ITEM_TYPE_IPV6:
1323 filter->ip_type = RTE_TUNNEL_IPTYPE_IPV6;
1324 /* IPv6 is used to describe protocol,
1325 * spec and mask should be NULL.
1327 if (item->spec || item->mask) {
1328 rte_flow_error_set(error, EINVAL,
1329 RTE_FLOW_ERROR_TYPE_ITEM,
1331 "Invalid IPv6 item");
1335 case RTE_FLOW_ITEM_TYPE_UDP:
1336 /* UDP is used to describe protocol,
1337 * spec and mask should be NULL.
1339 if (item->spec || item->mask) {
1340 rte_flow_error_set(error, EINVAL,
1341 RTE_FLOW_ERROR_TYPE_ITEM,
1343 "Invalid UDP item");
1347 case RTE_FLOW_ITEM_TYPE_VXLAN:
1349 (const struct rte_flow_item_vxlan *)item->spec;
1351 (const struct rte_flow_item_vxlan *)item->mask;
1352 /* Check if VXLAN item is used to describe protocol.
1353 * If yes, both spec and mask should be NULL.
1354 * If no, either spec or mask shouldn't be NULL.
1356 if ((!vxlan_spec && vxlan_mask) ||
1357 (vxlan_spec && !vxlan_mask)) {
1358 rte_flow_error_set(error, EINVAL,
1359 RTE_FLOW_ERROR_TYPE_ITEM,
1361 "Invalid VXLAN item");
1365 /* Check if VNI is masked. */
1368 i40e_check_tenant_id_mask(vxlan_mask->vni);
1369 if (is_vni_masked < 0) {
1370 rte_flow_error_set(error, EINVAL,
1371 RTE_FLOW_ERROR_TYPE_ITEM,
1373 "Invalid VNI mask");
1384 /* Check specification and mask to get the filter type */
1385 if (vlan_spec && vlan_mask &&
1386 (vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK))) {
1387 /* If there's inner vlan */
1388 filter->inner_vlan = rte_be_to_cpu_16(vlan_spec->tci)
1390 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1391 /* If there's vxlan */
1392 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
1393 vxlan_spec->vni, 3);
1394 filter->tenant_id = rte_be_to_cpu_32(tenant_id_be);
1395 if (!o_eth_spec && !o_eth_mask &&
1396 i_eth_spec && i_eth_mask)
1397 filter->filter_type =
1398 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
1400 rte_flow_error_set(error, EINVAL,
1401 RTE_FLOW_ERROR_TYPE_ITEM,
1403 "Invalid filter type");
1406 } else if (!vxlan_spec && !vxlan_mask) {
1407 /* If there's no vxlan */
1408 if (!o_eth_spec && !o_eth_mask &&
1409 i_eth_spec && i_eth_mask)
1410 filter->filter_type =
1411 RTE_TUNNEL_FILTER_IMAC_IVLAN;
1413 rte_flow_error_set(error, EINVAL,
1414 RTE_FLOW_ERROR_TYPE_ITEM,
1416 "Invalid filter type");
1420 rte_flow_error_set(error, EINVAL,
1421 RTE_FLOW_ERROR_TYPE_ITEM,
1423 "Invalid filter type");
1426 } else if ((!vlan_spec && !vlan_mask) ||
1427 (vlan_spec && vlan_mask && vlan_mask->tci == 0x0)) {
1428 /* If there's no inner vlan */
1429 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1430 /* If there's vxlan */
1431 rte_memcpy(((uint8_t *)&tenant_id_be + 1),
1432 vxlan_spec->vni, 3);
1433 filter->tenant_id = rte_be_to_cpu_32(tenant_id_be);
1434 if (!o_eth_spec && !o_eth_mask &&
1435 i_eth_spec && i_eth_mask)
1436 filter->filter_type =
1437 RTE_TUNNEL_FILTER_IMAC_TENID;
1438 else if (o_eth_spec && o_eth_mask &&
1439 i_eth_spec && i_eth_mask)
1440 filter->filter_type =
1441 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
1442 } else if (!vxlan_spec && !vxlan_mask) {
1443 /* If there's no vxlan */
1444 if (!o_eth_spec && !o_eth_mask &&
1445 i_eth_spec && i_eth_mask) {
1446 filter->filter_type = ETH_TUNNEL_FILTER_IMAC;
1448 rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1450 "Invalid filter type");
1454 rte_flow_error_set(error, EINVAL,
1455 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1456 "Invalid filter type");
1460 rte_flow_error_set(error, EINVAL,
1461 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1462 "Not supported by tunnel filter.");
1466 filter->tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
1472 i40e_flow_parse_tunnel_pattern(__rte_unused struct rte_eth_dev *dev,
1473 const struct rte_flow_item *pattern,
1474 struct rte_flow_error *error,
1475 struct rte_eth_tunnel_filter_conf *filter)
1479 ret = i40e_flow_parse_vxlan_pattern(pattern, error, filter);
1485 i40e_flow_parse_tunnel_filter(struct rte_eth_dev *dev,
1486 const struct rte_flow_attr *attr,
1487 const struct rte_flow_item pattern[],
1488 const struct rte_flow_action actions[],
1489 struct rte_flow_error *error,
1490 union i40e_filter_t *filter)
1492 struct rte_eth_tunnel_filter_conf *tunnel_filter =
1493 &filter->tunnel_filter;
1496 ret = i40e_flow_parse_tunnel_pattern(dev, pattern,
1497 error, tunnel_filter);
1501 ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
1505 ret = i40e_flow_parse_attr(attr, error);
1509 cons_filter_type = RTE_ETH_FILTER_TUNNEL;
1515 i40e_flow_validate(struct rte_eth_dev *dev,
1516 const struct rte_flow_attr *attr,
1517 const struct rte_flow_item pattern[],
1518 const struct rte_flow_action actions[],
1519 struct rte_flow_error *error)
1521 struct rte_flow_item *items; /* internal pattern w/o VOID items */
1522 parse_filter_t parse_filter;
1523 uint32_t item_num = 0; /* non-void item number of pattern*/
1528 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1529 NULL, "NULL pattern.");
1534 rte_flow_error_set(error, EINVAL,
1535 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1536 NULL, "NULL action.");
1541 rte_flow_error_set(error, EINVAL,
1542 RTE_FLOW_ERROR_TYPE_ATTR,
1543 NULL, "NULL attribute.");
1547 memset(&cons_filter, 0, sizeof(cons_filter));
1549 /* Get the non-void item number of pattern */
1550 while ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_END) {
1551 if ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_VOID)
1557 items = rte_zmalloc("i40e_pattern",
1558 item_num * sizeof(struct rte_flow_item), 0);
1560 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1561 NULL, "No memory for PMD internal items.");
1565 i40e_pattern_skip_void_item(items, pattern);
1567 /* Find if there's matched parse filter function */
1568 parse_filter = i40e_find_parse_filter_func(items);
1569 if (!parse_filter) {
1570 rte_flow_error_set(error, EINVAL,
1571 RTE_FLOW_ERROR_TYPE_ITEM,
1572 pattern, "Unsupported pattern");
1576 ret = parse_filter(dev, attr, items, actions, error, &cons_filter);
1583 static struct rte_flow *
1584 i40e_flow_create(struct rte_eth_dev *dev,
1585 const struct rte_flow_attr *attr,
1586 const struct rte_flow_item pattern[],
1587 const struct rte_flow_action actions[],
1588 struct rte_flow_error *error)
1590 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1591 struct rte_flow *flow;
1594 flow = rte_zmalloc("i40e_flow", sizeof(struct rte_flow), 0);
1596 rte_flow_error_set(error, ENOMEM,
1597 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1598 "Failed to allocate memory");
1602 ret = i40e_flow_validate(dev, attr, pattern, actions, error);
1606 switch (cons_filter_type) {
1607 case RTE_ETH_FILTER_ETHERTYPE:
1608 ret = i40e_ethertype_filter_set(pf,
1609 &cons_filter.ethertype_filter, 1);
1612 flow->rule = TAILQ_LAST(&pf->ethertype.ethertype_list,
1613 i40e_ethertype_filter_list);
1615 case RTE_ETH_FILTER_FDIR:
1616 ret = i40e_add_del_fdir_filter(dev,
1617 &cons_filter.fdir_filter, 1);
1620 flow->rule = TAILQ_LAST(&pf->fdir.fdir_list,
1621 i40e_fdir_filter_list);
1623 case RTE_ETH_FILTER_TUNNEL:
1624 ret = i40e_dev_tunnel_filter_set(pf,
1625 &cons_filter.tunnel_filter, 1);
1628 flow->rule = TAILQ_LAST(&pf->tunnel.tunnel_list,
1629 i40e_tunnel_filter_list);
1635 flow->filter_type = cons_filter_type;
1636 TAILQ_INSERT_TAIL(&pf->flow_list, flow, node);
1640 rte_flow_error_set(error, -ret,
1641 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1642 "Failed to create flow.");
1648 i40e_flow_destroy(struct rte_eth_dev *dev,
1649 struct rte_flow *flow,
1650 struct rte_flow_error *error)
1652 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1653 enum rte_filter_type filter_type = flow->filter_type;
1656 switch (filter_type) {
1657 case RTE_ETH_FILTER_ETHERTYPE:
1658 ret = i40e_flow_destroy_ethertype_filter(pf,
1659 (struct i40e_ethertype_filter *)flow->rule);
1661 case RTE_ETH_FILTER_TUNNEL:
1662 ret = i40e_flow_destroy_tunnel_filter(pf,
1663 (struct i40e_tunnel_filter *)flow->rule);
1665 case RTE_ETH_FILTER_FDIR:
1666 ret = i40e_add_del_fdir_filter(dev,
1667 &((struct i40e_fdir_filter *)flow->rule)->fdir, 0);
1670 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1677 TAILQ_REMOVE(&pf->flow_list, flow, node);
1680 rte_flow_error_set(error, -ret,
1681 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1682 "Failed to destroy flow.");
1688 i40e_flow_destroy_ethertype_filter(struct i40e_pf *pf,
1689 struct i40e_ethertype_filter *filter)
1691 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1692 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
1693 struct i40e_ethertype_filter *node;
1694 struct i40e_control_filter_stats stats;
1698 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
1699 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
1700 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
1701 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
1702 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
1704 memset(&stats, 0, sizeof(stats));
1705 ret = i40e_aq_add_rem_control_packet_filter(hw,
1706 filter->input.mac_addr.addr_bytes,
1707 filter->input.ether_type,
1708 flags, pf->main_vsi->seid,
1709 filter->queue, 0, &stats, NULL);
1713 node = i40e_sw_ethertype_filter_lookup(ethertype_rule, &filter->input);
1717 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
1723 i40e_flow_destroy_tunnel_filter(struct i40e_pf *pf,
1724 struct i40e_tunnel_filter *filter)
1726 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1727 struct i40e_vsi *vsi = pf->main_vsi;
1728 struct i40e_aqc_add_remove_cloud_filters_element_data cld_filter;
1729 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1730 struct i40e_tunnel_filter *node;
1733 memset(&cld_filter, 0, sizeof(cld_filter));
1734 ether_addr_copy((struct ether_addr *)&filter->input.outer_mac,
1735 (struct ether_addr *)&cld_filter.outer_mac);
1736 ether_addr_copy((struct ether_addr *)&filter->input.inner_mac,
1737 (struct ether_addr *)&cld_filter.inner_mac);
1738 cld_filter.inner_vlan = filter->input.inner_vlan;
1739 cld_filter.flags = filter->input.flags;
1740 cld_filter.tenant_id = filter->input.tenant_id;
1741 cld_filter.queue_number = filter->queue;
1743 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
1748 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &filter->input);
1752 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
1758 i40e_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
1760 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1763 ret = i40e_flow_flush_fdir_filter(pf);
1765 rte_flow_error_set(error, -ret,
1766 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1767 "Failed to flush FDIR flows.");
1771 ret = i40e_flow_flush_ethertype_filter(pf);
1773 rte_flow_error_set(error, -ret,
1774 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1775 "Failed to ethertype flush flows.");
1779 ret = i40e_flow_flush_tunnel_filter(pf);
1781 rte_flow_error_set(error, -ret,
1782 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1783 "Failed to flush tunnel flows.");
1791 i40e_flow_flush_fdir_filter(struct i40e_pf *pf)
1793 struct rte_eth_dev *dev = pf->adapter->eth_dev;
1794 struct i40e_fdir_info *fdir_info = &pf->fdir;
1795 struct i40e_fdir_filter *fdir_filter;
1796 struct rte_flow *flow;
1800 ret = i40e_fdir_flush(dev);
1802 /* Delete FDIR filters in FDIR list. */
1803 while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1804 ret = i40e_sw_fdir_filter_del(pf,
1805 &fdir_filter->fdir.input);
1810 /* Delete FDIR flows in flow list. */
1811 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
1812 if (flow->filter_type == RTE_ETH_FILTER_FDIR) {
1813 TAILQ_REMOVE(&pf->flow_list, flow, node);
1822 /* Flush all ethertype filters */
1824 i40e_flow_flush_ethertype_filter(struct i40e_pf *pf)
1826 struct i40e_ethertype_filter_list
1827 *ethertype_list = &pf->ethertype.ethertype_list;
1828 struct i40e_ethertype_filter *filter;
1829 struct rte_flow *flow;
1833 while ((filter = TAILQ_FIRST(ethertype_list))) {
1834 ret = i40e_flow_destroy_ethertype_filter(pf, filter);
1839 /* Delete ethertype flows in flow list. */
1840 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
1841 if (flow->filter_type == RTE_ETH_FILTER_ETHERTYPE) {
1842 TAILQ_REMOVE(&pf->flow_list, flow, node);
1850 /* Flush all tunnel filters */
1852 i40e_flow_flush_tunnel_filter(struct i40e_pf *pf)
1854 struct i40e_tunnel_filter_list
1855 *tunnel_list = &pf->tunnel.tunnel_list;
1856 struct i40e_tunnel_filter *filter;
1857 struct rte_flow *flow;
1861 while ((filter = TAILQ_FIRST(tunnel_list))) {
1862 ret = i40e_flow_destroy_tunnel_filter(pf, filter);
1867 /* Delete tunnel flows in flow list. */
1868 TAILQ_FOREACH_SAFE(flow, &pf->flow_list, node, temp) {
1869 if (flow->filter_type == RTE_ETH_FILTER_TUNNEL) {
1870 TAILQ_REMOVE(&pf->flow_list, flow, node);