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);
72 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
73 const struct rte_flow_item *pattern,
74 struct rte_flow_error *error,
75 struct rte_eth_ethertype_filter *filter);
76 static int i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
77 const struct rte_flow_action *actions,
78 struct rte_flow_error *error,
79 struct rte_eth_ethertype_filter *filter);
80 static int i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
81 const struct rte_flow_item *pattern,
82 struct rte_flow_error *error,
83 struct rte_eth_fdir_filter *filter);
84 static int i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
85 const struct rte_flow_action *actions,
86 struct rte_flow_error *error,
87 struct rte_eth_fdir_filter *filter);
88 static int i40e_flow_parse_tunnel_pattern(__rte_unused struct rte_eth_dev *dev,
89 const struct rte_flow_item *pattern,
90 struct rte_flow_error *error,
91 struct rte_eth_tunnel_filter_conf *filter);
92 static int i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
93 const struct rte_flow_action *actions,
94 struct rte_flow_error *error,
95 struct rte_eth_tunnel_filter_conf *filter);
96 static int i40e_flow_parse_attr(const struct rte_flow_attr *attr,
97 struct rte_flow_error *error);
98 static int i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
99 const struct rte_flow_attr *attr,
100 const struct rte_flow_item pattern[],
101 const struct rte_flow_action actions[],
102 struct rte_flow_error *error,
103 union i40e_filter_t *filter);
104 static int i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
105 const struct rte_flow_attr *attr,
106 const struct rte_flow_item pattern[],
107 const struct rte_flow_action actions[],
108 struct rte_flow_error *error,
109 union i40e_filter_t *filter);
110 static int i40e_flow_parse_tunnel_filter(struct rte_eth_dev *dev,
111 const struct rte_flow_attr *attr,
112 const struct rte_flow_item pattern[],
113 const struct rte_flow_action actions[],
114 struct rte_flow_error *error,
115 union i40e_filter_t *filter);
117 const struct rte_flow_ops i40e_flow_ops = {
118 .validate = i40e_flow_validate,
119 .create = i40e_flow_create,
122 union i40e_filter_t cons_filter;
123 enum rte_filter_type cons_filter_type = RTE_ETH_FILTER_NONE;
125 /* Pattern matched ethertype filter */
126 static enum rte_flow_item_type pattern_ethertype[] = {
127 RTE_FLOW_ITEM_TYPE_ETH,
128 RTE_FLOW_ITEM_TYPE_END,
131 /* Pattern matched flow director filter */
132 static enum rte_flow_item_type pattern_fdir_ipv4[] = {
133 RTE_FLOW_ITEM_TYPE_IPV4,
134 RTE_FLOW_ITEM_TYPE_END,
137 static enum rte_flow_item_type pattern_fdir_ipv4_ext[] = {
138 RTE_FLOW_ITEM_TYPE_ETH,
139 RTE_FLOW_ITEM_TYPE_IPV4,
140 RTE_FLOW_ITEM_TYPE_END,
143 static enum rte_flow_item_type pattern_fdir_ipv4_udp[] = {
144 RTE_FLOW_ITEM_TYPE_IPV4,
145 RTE_FLOW_ITEM_TYPE_UDP,
146 RTE_FLOW_ITEM_TYPE_END,
149 static enum rte_flow_item_type pattern_fdir_ipv4_udp_ext[] = {
150 RTE_FLOW_ITEM_TYPE_ETH,
151 RTE_FLOW_ITEM_TYPE_IPV4,
152 RTE_FLOW_ITEM_TYPE_UDP,
153 RTE_FLOW_ITEM_TYPE_END,
156 static enum rte_flow_item_type pattern_fdir_ipv4_tcp[] = {
157 RTE_FLOW_ITEM_TYPE_IPV4,
158 RTE_FLOW_ITEM_TYPE_TCP,
159 RTE_FLOW_ITEM_TYPE_END,
162 static enum rte_flow_item_type pattern_fdir_ipv4_tcp_ext[] = {
163 RTE_FLOW_ITEM_TYPE_ETH,
164 RTE_FLOW_ITEM_TYPE_IPV4,
165 RTE_FLOW_ITEM_TYPE_TCP,
166 RTE_FLOW_ITEM_TYPE_END,
169 static enum rte_flow_item_type pattern_fdir_ipv4_sctp[] = {
170 RTE_FLOW_ITEM_TYPE_IPV4,
171 RTE_FLOW_ITEM_TYPE_SCTP,
172 RTE_FLOW_ITEM_TYPE_END,
175 static enum rte_flow_item_type pattern_fdir_ipv4_sctp_ext[] = {
176 RTE_FLOW_ITEM_TYPE_ETH,
177 RTE_FLOW_ITEM_TYPE_IPV4,
178 RTE_FLOW_ITEM_TYPE_SCTP,
179 RTE_FLOW_ITEM_TYPE_END,
182 static enum rte_flow_item_type pattern_fdir_ipv6[] = {
183 RTE_FLOW_ITEM_TYPE_IPV6,
184 RTE_FLOW_ITEM_TYPE_END,
187 static enum rte_flow_item_type pattern_fdir_ipv6_ext[] = {
188 RTE_FLOW_ITEM_TYPE_ETH,
189 RTE_FLOW_ITEM_TYPE_IPV6,
190 RTE_FLOW_ITEM_TYPE_END,
193 static enum rte_flow_item_type pattern_fdir_ipv6_udp[] = {
194 RTE_FLOW_ITEM_TYPE_IPV6,
195 RTE_FLOW_ITEM_TYPE_UDP,
196 RTE_FLOW_ITEM_TYPE_END,
199 static enum rte_flow_item_type pattern_fdir_ipv6_udp_ext[] = {
200 RTE_FLOW_ITEM_TYPE_ETH,
201 RTE_FLOW_ITEM_TYPE_IPV6,
202 RTE_FLOW_ITEM_TYPE_UDP,
203 RTE_FLOW_ITEM_TYPE_END,
206 static enum rte_flow_item_type pattern_fdir_ipv6_tcp[] = {
207 RTE_FLOW_ITEM_TYPE_IPV6,
208 RTE_FLOW_ITEM_TYPE_TCP,
209 RTE_FLOW_ITEM_TYPE_END,
212 static enum rte_flow_item_type pattern_fdir_ipv6_tcp_ext[] = {
213 RTE_FLOW_ITEM_TYPE_ETH,
214 RTE_FLOW_ITEM_TYPE_IPV6,
215 RTE_FLOW_ITEM_TYPE_TCP,
216 RTE_FLOW_ITEM_TYPE_END,
219 static enum rte_flow_item_type pattern_fdir_ipv6_sctp[] = {
220 RTE_FLOW_ITEM_TYPE_IPV6,
221 RTE_FLOW_ITEM_TYPE_SCTP,
222 RTE_FLOW_ITEM_TYPE_END,
225 static enum rte_flow_item_type pattern_fdir_ipv6_sctp_ext[] = {
226 RTE_FLOW_ITEM_TYPE_ETH,
227 RTE_FLOW_ITEM_TYPE_IPV6,
228 RTE_FLOW_ITEM_TYPE_SCTP,
229 RTE_FLOW_ITEM_TYPE_END,
232 /* Pattern matched tunnel filter */
233 static enum rte_flow_item_type pattern_vxlan_1[] = {
234 RTE_FLOW_ITEM_TYPE_ETH,
235 RTE_FLOW_ITEM_TYPE_IPV4,
236 RTE_FLOW_ITEM_TYPE_UDP,
237 RTE_FLOW_ITEM_TYPE_VXLAN,
238 RTE_FLOW_ITEM_TYPE_ETH,
239 RTE_FLOW_ITEM_TYPE_END,
242 static enum rte_flow_item_type pattern_vxlan_2[] = {
243 RTE_FLOW_ITEM_TYPE_ETH,
244 RTE_FLOW_ITEM_TYPE_IPV6,
245 RTE_FLOW_ITEM_TYPE_UDP,
246 RTE_FLOW_ITEM_TYPE_VXLAN,
247 RTE_FLOW_ITEM_TYPE_ETH,
248 RTE_FLOW_ITEM_TYPE_END,
251 static enum rte_flow_item_type pattern_vxlan_3[] = {
252 RTE_FLOW_ITEM_TYPE_ETH,
253 RTE_FLOW_ITEM_TYPE_IPV4,
254 RTE_FLOW_ITEM_TYPE_UDP,
255 RTE_FLOW_ITEM_TYPE_VXLAN,
256 RTE_FLOW_ITEM_TYPE_ETH,
257 RTE_FLOW_ITEM_TYPE_VLAN,
258 RTE_FLOW_ITEM_TYPE_END,
261 static enum rte_flow_item_type pattern_vxlan_4[] = {
262 RTE_FLOW_ITEM_TYPE_ETH,
263 RTE_FLOW_ITEM_TYPE_IPV6,
264 RTE_FLOW_ITEM_TYPE_UDP,
265 RTE_FLOW_ITEM_TYPE_VXLAN,
266 RTE_FLOW_ITEM_TYPE_ETH,
267 RTE_FLOW_ITEM_TYPE_VLAN,
268 RTE_FLOW_ITEM_TYPE_END,
271 static struct i40e_valid_pattern i40e_supported_patterns[] = {
273 { pattern_ethertype, i40e_flow_parse_ethertype_filter },
275 { pattern_fdir_ipv4, i40e_flow_parse_fdir_filter },
276 { pattern_fdir_ipv4_ext, i40e_flow_parse_fdir_filter },
277 { pattern_fdir_ipv4_udp, i40e_flow_parse_fdir_filter },
278 { pattern_fdir_ipv4_udp_ext, i40e_flow_parse_fdir_filter },
279 { pattern_fdir_ipv4_tcp, i40e_flow_parse_fdir_filter },
280 { pattern_fdir_ipv4_tcp_ext, i40e_flow_parse_fdir_filter },
281 { pattern_fdir_ipv4_sctp, i40e_flow_parse_fdir_filter },
282 { pattern_fdir_ipv4_sctp_ext, i40e_flow_parse_fdir_filter },
283 { pattern_fdir_ipv6, i40e_flow_parse_fdir_filter },
284 { pattern_fdir_ipv6_ext, i40e_flow_parse_fdir_filter },
285 { pattern_fdir_ipv6_udp, i40e_flow_parse_fdir_filter },
286 { pattern_fdir_ipv6_udp_ext, i40e_flow_parse_fdir_filter },
287 { pattern_fdir_ipv6_tcp, i40e_flow_parse_fdir_filter },
288 { pattern_fdir_ipv6_tcp_ext, i40e_flow_parse_fdir_filter },
289 { pattern_fdir_ipv6_sctp, i40e_flow_parse_fdir_filter },
290 { pattern_fdir_ipv6_sctp_ext, i40e_flow_parse_fdir_filter },
292 { pattern_vxlan_1, i40e_flow_parse_tunnel_filter },
293 { pattern_vxlan_2, i40e_flow_parse_tunnel_filter },
294 { pattern_vxlan_3, i40e_flow_parse_tunnel_filter },
295 { pattern_vxlan_4, i40e_flow_parse_tunnel_filter },
298 #define NEXT_ITEM_OF_ACTION(act, actions, index) \
300 act = actions + index; \
301 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) { \
303 act = actions + index; \
307 /* Find the first VOID or non-VOID item pointer */
308 static const struct rte_flow_item *
309 i40e_find_first_item(const struct rte_flow_item *item, bool is_void)
313 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
315 is_find = item->type == RTE_FLOW_ITEM_TYPE_VOID;
317 is_find = item->type != RTE_FLOW_ITEM_TYPE_VOID;
325 /* Skip all VOID items of the pattern */
327 i40e_pattern_skip_void_item(struct rte_flow_item *items,
328 const struct rte_flow_item *pattern)
330 uint32_t cpy_count = 0;
331 const struct rte_flow_item *pb = pattern, *pe = pattern;
334 /* Find a non-void item first */
335 pb = i40e_find_first_item(pb, false);
336 if (pb->type == RTE_FLOW_ITEM_TYPE_END) {
341 /* Find a void item */
342 pe = i40e_find_first_item(pb + 1, true);
345 rte_memcpy(items, pb, sizeof(struct rte_flow_item) * cpy_count);
349 if (pe->type == RTE_FLOW_ITEM_TYPE_END) {
356 /* Copy the END item. */
357 rte_memcpy(items, pe, sizeof(struct rte_flow_item));
360 /* Check if the pattern matches a supported item type array */
362 i40e_match_pattern(enum rte_flow_item_type *item_array,
363 struct rte_flow_item *pattern)
365 struct rte_flow_item *item = pattern;
367 while ((*item_array == item->type) &&
368 (*item_array != RTE_FLOW_ITEM_TYPE_END)) {
373 return (*item_array == RTE_FLOW_ITEM_TYPE_END &&
374 item->type == RTE_FLOW_ITEM_TYPE_END);
377 /* Find if there's parse filter function matched */
378 static parse_filter_t
379 i40e_find_parse_filter_func(struct rte_flow_item *pattern)
381 parse_filter_t parse_filter = NULL;
384 for (; i < RTE_DIM(i40e_supported_patterns); i++) {
385 if (i40e_match_pattern(i40e_supported_patterns[i].items,
387 parse_filter = i40e_supported_patterns[i].parse_filter;
395 /* Parse attributes */
397 i40e_flow_parse_attr(const struct rte_flow_attr *attr,
398 struct rte_flow_error *error)
400 /* Must be input direction */
401 if (!attr->ingress) {
402 rte_flow_error_set(error, EINVAL,
403 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
404 attr, "Only support ingress.");
410 rte_flow_error_set(error, EINVAL,
411 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
412 attr, "Not support egress.");
417 if (attr->priority) {
418 rte_flow_error_set(error, EINVAL,
419 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
420 attr, "Not support priority.");
426 rte_flow_error_set(error, EINVAL,
427 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
428 attr, "Not support group.");
436 i40e_get_outer_vlan(struct rte_eth_dev *dev)
438 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
439 int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
449 i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
452 tpid = (reg_r >> I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT) & 0xFFFF;
457 /* 1. Last in item should be NULL as range is not supported.
458 * 2. Supported filter types: MAC_ETHTYPE and ETHTYPE.
459 * 3. SRC mac_addr mask should be 00:00:00:00:00:00.
460 * 4. DST mac_addr mask should be 00:00:00:00:00:00 or
462 * 5. Ether_type mask should be 0xFFFF.
465 i40e_flow_parse_ethertype_pattern(struct rte_eth_dev *dev,
466 const struct rte_flow_item *pattern,
467 struct rte_flow_error *error,
468 struct rte_eth_ethertype_filter *filter)
470 const struct rte_flow_item *item = pattern;
471 const struct rte_flow_item_eth *eth_spec;
472 const struct rte_flow_item_eth *eth_mask;
473 enum rte_flow_item_type item_type;
476 outer_tpid = i40e_get_outer_vlan(dev);
478 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
480 rte_flow_error_set(error, EINVAL,
481 RTE_FLOW_ERROR_TYPE_ITEM,
483 "Not support range");
486 item_type = item->type;
488 case RTE_FLOW_ITEM_TYPE_ETH:
489 eth_spec = (const struct rte_flow_item_eth *)item->spec;
490 eth_mask = (const struct rte_flow_item_eth *)item->mask;
491 /* Get the MAC info. */
492 if (!eth_spec || !eth_mask) {
493 rte_flow_error_set(error, EINVAL,
494 RTE_FLOW_ERROR_TYPE_ITEM,
496 "NULL ETH spec/mask");
500 /* Mask bits of source MAC address must be full of 0.
501 * Mask bits of destination MAC address must be full
504 if (!is_zero_ether_addr(ð_mask->src) ||
505 (!is_zero_ether_addr(ð_mask->dst) &&
506 !is_broadcast_ether_addr(ð_mask->dst))) {
507 rte_flow_error_set(error, EINVAL,
508 RTE_FLOW_ERROR_TYPE_ITEM,
510 "Invalid MAC_addr mask");
514 if ((eth_mask->type & UINT16_MAX) != UINT16_MAX) {
515 rte_flow_error_set(error, EINVAL,
516 RTE_FLOW_ERROR_TYPE_ITEM,
518 "Invalid ethertype mask");
522 /* If mask bits of destination MAC address
523 * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
525 if (is_broadcast_ether_addr(ð_mask->dst)) {
526 filter->mac_addr = eth_spec->dst;
527 filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
529 filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
531 filter->ether_type = rte_be_to_cpu_16(eth_spec->type);
533 if (filter->ether_type == ETHER_TYPE_IPv4 ||
534 filter->ether_type == ETHER_TYPE_IPv6 ||
535 filter->ether_type == outer_tpid) {
536 rte_flow_error_set(error, EINVAL,
537 RTE_FLOW_ERROR_TYPE_ITEM,
539 "Unsupported ether_type in"
540 " control packet filter.");
552 /* Ethertype action only supports QUEUE or DROP. */
554 i40e_flow_parse_ethertype_action(struct rte_eth_dev *dev,
555 const struct rte_flow_action *actions,
556 struct rte_flow_error *error,
557 struct rte_eth_ethertype_filter *filter)
559 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
560 const struct rte_flow_action *act;
561 const struct rte_flow_action_queue *act_q;
564 /* Check if the first non-void action is QUEUE or DROP. */
565 NEXT_ITEM_OF_ACTION(act, actions, index);
566 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
567 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
568 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
569 act, "Not supported action.");
573 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
574 act_q = (const struct rte_flow_action_queue *)act->conf;
575 filter->queue = act_q->index;
576 if (filter->queue >= pf->dev_data->nb_rx_queues) {
577 rte_flow_error_set(error, EINVAL,
578 RTE_FLOW_ERROR_TYPE_ACTION,
579 act, "Invalid queue ID for"
580 " ethertype_filter.");
584 filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
587 /* Check if the next non-void item is END */
589 NEXT_ITEM_OF_ACTION(act, actions, index);
590 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
591 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
592 act, "Not supported action.");
600 i40e_flow_parse_ethertype_filter(struct rte_eth_dev *dev,
601 const struct rte_flow_attr *attr,
602 const struct rte_flow_item pattern[],
603 const struct rte_flow_action actions[],
604 struct rte_flow_error *error,
605 union i40e_filter_t *filter)
607 struct rte_eth_ethertype_filter *ethertype_filter =
608 &filter->ethertype_filter;
611 ret = i40e_flow_parse_ethertype_pattern(dev, pattern, error,
616 ret = i40e_flow_parse_ethertype_action(dev, actions, error,
621 ret = i40e_flow_parse_attr(attr, error);
625 cons_filter_type = RTE_ETH_FILTER_ETHERTYPE;
630 /* 1. Last in item should be NULL as range is not supported.
631 * 2. Supported flow type and input set: refer to array
632 * default_inset_table in i40e_ethdev.c.
633 * 3. Mask of fields which need to be matched should be
635 * 4. Mask of fields which needn't to be matched should be
639 i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev,
640 const struct rte_flow_item *pattern,
641 struct rte_flow_error *error,
642 struct rte_eth_fdir_filter *filter)
644 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
645 const struct rte_flow_item *item = pattern;
646 const struct rte_flow_item_eth *eth_spec, *eth_mask;
647 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
648 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
649 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
650 const struct rte_flow_item_udp *udp_spec, *udp_mask;
651 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
652 const struct rte_flow_item_vf *vf_spec;
653 uint32_t flow_type = RTE_ETH_FLOW_UNKNOWN;
654 enum i40e_filter_pctype pctype;
655 uint64_t input_set = I40E_INSET_NONE;
656 uint16_t flag_offset;
657 enum rte_flow_item_type item_type;
658 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
661 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
663 rte_flow_error_set(error, EINVAL,
664 RTE_FLOW_ERROR_TYPE_ITEM,
666 "Not support range");
669 item_type = item->type;
671 case RTE_FLOW_ITEM_TYPE_ETH:
672 eth_spec = (const struct rte_flow_item_eth *)item->spec;
673 eth_mask = (const struct rte_flow_item_eth *)item->mask;
674 if (eth_spec || eth_mask) {
675 rte_flow_error_set(error, EINVAL,
676 RTE_FLOW_ERROR_TYPE_ITEM,
678 "Invalid ETH spec/mask");
682 case RTE_FLOW_ITEM_TYPE_IPV4:
683 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
685 (const struct rte_flow_item_ipv4 *)item->spec;
687 (const struct rte_flow_item_ipv4 *)item->mask;
688 if (!ipv4_spec || !ipv4_mask) {
689 rte_flow_error_set(error, EINVAL,
690 RTE_FLOW_ERROR_TYPE_ITEM,
692 "NULL IPv4 spec/mask");
696 /* Check IPv4 mask and update input set */
697 if (ipv4_mask->hdr.version_ihl ||
698 ipv4_mask->hdr.total_length ||
699 ipv4_mask->hdr.packet_id ||
700 ipv4_mask->hdr.fragment_offset ||
701 ipv4_mask->hdr.hdr_checksum) {
702 rte_flow_error_set(error, EINVAL,
703 RTE_FLOW_ERROR_TYPE_ITEM,
705 "Invalid IPv4 mask.");
709 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
710 input_set |= I40E_INSET_IPV4_SRC;
711 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
712 input_set |= I40E_INSET_IPV4_DST;
713 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
714 input_set |= I40E_INSET_IPV4_TOS;
715 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
716 input_set |= I40E_INSET_IPV4_TTL;
717 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
718 input_set |= I40E_INSET_IPV4_PROTO;
720 /* Get filter info */
721 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_OTHER;
722 /* Check if it is fragment. */
724 rte_be_to_cpu_16(ipv4_spec->hdr.fragment_offset);
725 if (flag_offset & IPV4_HDR_OFFSET_MASK ||
726 flag_offset & IPV4_HDR_MF_FLAG)
727 flow_type = RTE_ETH_FLOW_FRAG_IPV4;
729 /* Get the filter info */
730 filter->input.flow.ip4_flow.proto =
731 ipv4_spec->hdr.next_proto_id;
732 filter->input.flow.ip4_flow.tos =
733 ipv4_spec->hdr.type_of_service;
734 filter->input.flow.ip4_flow.ttl =
735 ipv4_spec->hdr.time_to_live;
736 filter->input.flow.ip4_flow.src_ip =
737 ipv4_spec->hdr.src_addr;
738 filter->input.flow.ip4_flow.dst_ip =
739 ipv4_spec->hdr.dst_addr;
742 case RTE_FLOW_ITEM_TYPE_IPV6:
743 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
745 (const struct rte_flow_item_ipv6 *)item->spec;
747 (const struct rte_flow_item_ipv6 *)item->mask;
748 if (!ipv6_spec || !ipv6_mask) {
749 rte_flow_error_set(error, EINVAL,
750 RTE_FLOW_ERROR_TYPE_ITEM,
752 "NULL IPv6 spec/mask");
756 /* Check IPv6 mask and update input set */
757 if (ipv6_mask->hdr.payload_len) {
758 rte_flow_error_set(error, EINVAL,
759 RTE_FLOW_ERROR_TYPE_ITEM,
761 "Invalid IPv6 mask");
765 /* SCR and DST address of IPv6 shouldn't be masked */
766 for (j = 0; j < RTE_DIM(ipv6_mask->hdr.src_addr); j++) {
767 if (ipv6_mask->hdr.src_addr[j] != UINT8_MAX ||
768 ipv6_mask->hdr.dst_addr[j] != UINT8_MAX) {
769 rte_flow_error_set(error, EINVAL,
770 RTE_FLOW_ERROR_TYPE_ITEM,
772 "Invalid IPv6 mask");
777 input_set |= I40E_INSET_IPV6_SRC;
778 input_set |= I40E_INSET_IPV6_DST;
780 if ((ipv6_mask->hdr.vtc_flow &
781 rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
782 == rte_cpu_to_be_16(I40E_IPV6_TC_MASK))
783 input_set |= I40E_INSET_IPV6_TC;
784 if (ipv6_mask->hdr.proto == UINT8_MAX)
785 input_set |= I40E_INSET_IPV6_NEXT_HDR;
786 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
787 input_set |= I40E_INSET_IPV6_HOP_LIMIT;
789 /* Get filter info */
790 filter->input.flow.ipv6_flow.tc =
791 (uint8_t)(ipv6_spec->hdr.vtc_flow <<
793 filter->input.flow.ipv6_flow.proto =
794 ipv6_spec->hdr.proto;
795 filter->input.flow.ipv6_flow.hop_limits =
796 ipv6_spec->hdr.hop_limits;
798 rte_memcpy(filter->input.flow.ipv6_flow.src_ip,
799 ipv6_spec->hdr.src_addr, 16);
800 rte_memcpy(filter->input.flow.ipv6_flow.dst_ip,
801 ipv6_spec->hdr.dst_addr, 16);
803 /* Check if it is fragment. */
804 if (ipv6_spec->hdr.proto == I40E_IPV6_FRAG_HEADER)
805 flow_type = RTE_ETH_FLOW_FRAG_IPV6;
807 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_OTHER;
809 case RTE_FLOW_ITEM_TYPE_TCP:
810 tcp_spec = (const struct rte_flow_item_tcp *)item->spec;
811 tcp_mask = (const struct rte_flow_item_tcp *)item->mask;
812 if (!tcp_spec || !tcp_mask) {
813 rte_flow_error_set(error, EINVAL,
814 RTE_FLOW_ERROR_TYPE_ITEM,
816 "NULL TCP spec/mask");
820 /* Check TCP mask and update input set */
821 if (tcp_mask->hdr.sent_seq ||
822 tcp_mask->hdr.recv_ack ||
823 tcp_mask->hdr.data_off ||
824 tcp_mask->hdr.tcp_flags ||
825 tcp_mask->hdr.rx_win ||
826 tcp_mask->hdr.cksum ||
827 tcp_mask->hdr.tcp_urp) {
828 rte_flow_error_set(error, EINVAL,
829 RTE_FLOW_ERROR_TYPE_ITEM,
835 if (tcp_mask->hdr.src_port != UINT16_MAX ||
836 tcp_mask->hdr.dst_port != UINT16_MAX) {
837 rte_flow_error_set(error, EINVAL,
838 RTE_FLOW_ERROR_TYPE_ITEM,
844 input_set |= I40E_INSET_SRC_PORT;
845 input_set |= I40E_INSET_DST_PORT;
847 /* Get filter info */
848 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
849 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_TCP;
850 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
851 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_TCP;
853 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
854 filter->input.flow.tcp4_flow.src_port =
855 tcp_spec->hdr.src_port;
856 filter->input.flow.tcp4_flow.dst_port =
857 tcp_spec->hdr.dst_port;
858 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
859 filter->input.flow.tcp6_flow.src_port =
860 tcp_spec->hdr.src_port;
861 filter->input.flow.tcp6_flow.dst_port =
862 tcp_spec->hdr.dst_port;
865 case RTE_FLOW_ITEM_TYPE_UDP:
866 udp_spec = (const struct rte_flow_item_udp *)item->spec;
867 udp_mask = (const struct rte_flow_item_udp *)item->mask;
868 if (!udp_spec || !udp_mask) {
869 rte_flow_error_set(error, EINVAL,
870 RTE_FLOW_ERROR_TYPE_ITEM,
872 "NULL UDP spec/mask");
876 /* Check UDP mask and update input set*/
877 if (udp_mask->hdr.dgram_len ||
878 udp_mask->hdr.dgram_cksum) {
879 rte_flow_error_set(error, EINVAL,
880 RTE_FLOW_ERROR_TYPE_ITEM,
886 if (udp_mask->hdr.src_port != UINT16_MAX ||
887 udp_mask->hdr.dst_port != UINT16_MAX) {
888 rte_flow_error_set(error, EINVAL,
889 RTE_FLOW_ERROR_TYPE_ITEM,
895 input_set |= I40E_INSET_SRC_PORT;
896 input_set |= I40E_INSET_DST_PORT;
898 /* Get filter info */
899 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
901 RTE_ETH_FLOW_NONFRAG_IPV4_UDP;
902 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
904 RTE_ETH_FLOW_NONFRAG_IPV6_UDP;
906 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
907 filter->input.flow.udp4_flow.src_port =
908 udp_spec->hdr.src_port;
909 filter->input.flow.udp4_flow.dst_port =
910 udp_spec->hdr.dst_port;
911 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
912 filter->input.flow.udp6_flow.src_port =
913 udp_spec->hdr.src_port;
914 filter->input.flow.udp6_flow.dst_port =
915 udp_spec->hdr.dst_port;
918 case RTE_FLOW_ITEM_TYPE_SCTP:
920 (const struct rte_flow_item_sctp *)item->spec;
922 (const struct rte_flow_item_sctp *)item->mask;
923 if (!sctp_spec || !sctp_mask) {
924 rte_flow_error_set(error, EINVAL,
925 RTE_FLOW_ERROR_TYPE_ITEM,
927 "NULL SCTP spec/mask");
931 /* Check SCTP mask and update input set */
932 if (sctp_mask->hdr.cksum) {
933 rte_flow_error_set(error, EINVAL,
934 RTE_FLOW_ERROR_TYPE_ITEM,
940 if (sctp_mask->hdr.src_port != UINT16_MAX ||
941 sctp_mask->hdr.dst_port != UINT16_MAX ||
942 sctp_mask->hdr.tag != UINT32_MAX) {
943 rte_flow_error_set(error, EINVAL,
944 RTE_FLOW_ERROR_TYPE_ITEM,
949 input_set |= I40E_INSET_SRC_PORT;
950 input_set |= I40E_INSET_DST_PORT;
951 input_set |= I40E_INSET_SCTP_VT;
953 /* Get filter info */
954 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
955 flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_SCTP;
956 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
957 flow_type = RTE_ETH_FLOW_NONFRAG_IPV6_SCTP;
959 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
960 filter->input.flow.sctp4_flow.src_port =
961 sctp_spec->hdr.src_port;
962 filter->input.flow.sctp4_flow.dst_port =
963 sctp_spec->hdr.dst_port;
964 filter->input.flow.sctp4_flow.verify_tag =
966 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
967 filter->input.flow.sctp6_flow.src_port =
968 sctp_spec->hdr.src_port;
969 filter->input.flow.sctp6_flow.dst_port =
970 sctp_spec->hdr.dst_port;
971 filter->input.flow.sctp6_flow.verify_tag =
975 case RTE_FLOW_ITEM_TYPE_VF:
976 vf_spec = (const struct rte_flow_item_vf *)item->spec;
977 filter->input.flow_ext.is_vf = 1;
978 filter->input.flow_ext.dst_id = vf_spec->id;
979 if (filter->input.flow_ext.is_vf &&
980 filter->input.flow_ext.dst_id >= pf->vf_num) {
981 rte_flow_error_set(error, EINVAL,
982 RTE_FLOW_ERROR_TYPE_ITEM,
984 "Invalid VF ID for FDIR.");
993 pctype = i40e_flowtype_to_pctype(flow_type);
994 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
995 rte_flow_error_set(error, EINVAL,
996 RTE_FLOW_ERROR_TYPE_ITEM, item,
997 "Unsupported flow type");
1001 if (input_set != i40e_get_default_input_set(pctype)) {
1002 rte_flow_error_set(error, EINVAL,
1003 RTE_FLOW_ERROR_TYPE_ITEM, item,
1004 "Invalid input set.");
1007 filter->input.flow_type = flow_type;
1012 /* Parse to get the action info of a FDIR filter.
1013 * FDIR action supports QUEUE or (QUEUE + MARK).
1016 i40e_flow_parse_fdir_action(struct rte_eth_dev *dev,
1017 const struct rte_flow_action *actions,
1018 struct rte_flow_error *error,
1019 struct rte_eth_fdir_filter *filter)
1021 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1022 const struct rte_flow_action *act;
1023 const struct rte_flow_action_queue *act_q;
1024 const struct rte_flow_action_mark *mark_spec;
1027 /* Check if the first non-void action is QUEUE or DROP. */
1028 NEXT_ITEM_OF_ACTION(act, actions, index);
1029 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
1030 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
1031 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1032 act, "Invalid action.");
1036 act_q = (const struct rte_flow_action_queue *)act->conf;
1037 filter->action.flex_off = 0;
1038 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE)
1039 filter->action.behavior = RTE_ETH_FDIR_ACCEPT;
1041 filter->action.behavior = RTE_ETH_FDIR_REJECT;
1043 filter->action.report_status = RTE_ETH_FDIR_REPORT_ID;
1044 filter->action.rx_queue = act_q->index;
1046 if (filter->action.rx_queue >= pf->dev_data->nb_rx_queues) {
1047 rte_flow_error_set(error, EINVAL,
1048 RTE_FLOW_ERROR_TYPE_ACTION, act,
1049 "Invalid queue ID for FDIR.");
1053 /* Check if the next non-void item is MARK or END. */
1055 NEXT_ITEM_OF_ACTION(act, actions, index);
1056 if (act->type != RTE_FLOW_ACTION_TYPE_MARK &&
1057 act->type != RTE_FLOW_ACTION_TYPE_END) {
1058 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1059 act, "Invalid action.");
1063 if (act->type == RTE_FLOW_ACTION_TYPE_MARK) {
1064 mark_spec = (const struct rte_flow_action_mark *)act->conf;
1065 filter->soft_id = mark_spec->id;
1067 /* Check if the next non-void item is END */
1069 NEXT_ITEM_OF_ACTION(act, actions, index);
1070 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1071 rte_flow_error_set(error, EINVAL,
1072 RTE_FLOW_ERROR_TYPE_ACTION,
1073 act, "Invalid action.");
1082 i40e_flow_parse_fdir_filter(struct rte_eth_dev *dev,
1083 const struct rte_flow_attr *attr,
1084 const struct rte_flow_item pattern[],
1085 const struct rte_flow_action actions[],
1086 struct rte_flow_error *error,
1087 union i40e_filter_t *filter)
1089 struct rte_eth_fdir_filter *fdir_filter =
1090 &filter->fdir_filter;
1093 ret = i40e_flow_parse_fdir_pattern(dev, pattern, error, fdir_filter);
1097 ret = i40e_flow_parse_fdir_action(dev, actions, error, fdir_filter);
1101 ret = i40e_flow_parse_attr(attr, error);
1105 cons_filter_type = RTE_ETH_FILTER_FDIR;
1107 if (dev->data->dev_conf.fdir_conf.mode !=
1108 RTE_FDIR_MODE_PERFECT) {
1109 rte_flow_error_set(error, ENOTSUP,
1110 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1112 "Check the mode in fdir_conf.");
1119 /* Parse to get the action info of a tunnle filter
1120 * Tunnel action only supports QUEUE.
1123 i40e_flow_parse_tunnel_action(struct rte_eth_dev *dev,
1124 const struct rte_flow_action *actions,
1125 struct rte_flow_error *error,
1126 struct rte_eth_tunnel_filter_conf *filter)
1128 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1129 const struct rte_flow_action *act;
1130 const struct rte_flow_action_queue *act_q;
1133 /* Check if the first non-void action is QUEUE. */
1134 NEXT_ITEM_OF_ACTION(act, actions, index);
1135 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
1136 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1137 act, "Not supported action.");
1141 act_q = (const struct rte_flow_action_queue *)act->conf;
1142 filter->queue_id = act_q->index;
1143 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
1144 rte_flow_error_set(error, EINVAL,
1145 RTE_FLOW_ERROR_TYPE_ACTION,
1146 act, "Invalid queue ID for tunnel filter");
1150 /* Check if the next non-void item is END */
1152 NEXT_ITEM_OF_ACTION(act, actions, index);
1153 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1154 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
1155 act, "Not supported action.");
1163 i40e_check_tenant_id_mask(const uint8_t *mask)
1168 for (j = 0; j < I40E_TENANT_ARRAY_NUM; j++) {
1169 if (*(mask + j) == UINT8_MAX) {
1170 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1173 } else if (*(mask + j) == 0) {
1174 if (j > 0 && (*(mask + j) != *(mask + j - 1)))
1185 /* 1. Last in item should be NULL as range is not supported.
1186 * 2. Supported filter types: IMAC_IVLAN_TENID, IMAC_IVLAN,
1187 * IMAC_TENID, OMAC_TENID_IMAC and IMAC.
1188 * 3. Mask of fields which need to be matched should be
1190 * 4. Mask of fields which needn't to be matched should be
1194 i40e_flow_parse_vxlan_pattern(const struct rte_flow_item *pattern,
1195 struct rte_flow_error *error,
1196 struct rte_eth_tunnel_filter_conf *filter)
1198 const struct rte_flow_item *item = pattern;
1199 const struct rte_flow_item_eth *eth_spec;
1200 const struct rte_flow_item_eth *eth_mask;
1201 const struct rte_flow_item_eth *o_eth_spec = NULL;
1202 const struct rte_flow_item_eth *o_eth_mask = NULL;
1203 const struct rte_flow_item_vxlan *vxlan_spec = NULL;
1204 const struct rte_flow_item_vxlan *vxlan_mask = NULL;
1205 const struct rte_flow_item_eth *i_eth_spec = NULL;
1206 const struct rte_flow_item_eth *i_eth_mask = NULL;
1207 const struct rte_flow_item_vlan *vlan_spec = NULL;
1208 const struct rte_flow_item_vlan *vlan_mask = NULL;
1209 bool is_vni_masked = 0;
1210 enum rte_flow_item_type item_type;
1211 bool vxlan_flag = 0;
1213 for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1215 rte_flow_error_set(error, EINVAL,
1216 RTE_FLOW_ERROR_TYPE_ITEM,
1218 "Not support range");
1221 item_type = item->type;
1222 switch (item_type) {
1223 case RTE_FLOW_ITEM_TYPE_ETH:
1224 eth_spec = (const struct rte_flow_item_eth *)item->spec;
1225 eth_mask = (const struct rte_flow_item_eth *)item->mask;
1226 if ((!eth_spec && eth_mask) ||
1227 (eth_spec && !eth_mask)) {
1228 rte_flow_error_set(error, EINVAL,
1229 RTE_FLOW_ERROR_TYPE_ITEM,
1231 "Invalid ether spec/mask");
1235 if (eth_spec && eth_mask) {
1236 /* DST address of inner MAC shouldn't be masked.
1237 * SRC address of Inner MAC should be masked.
1239 if (!is_broadcast_ether_addr(ð_mask->dst) ||
1240 !is_zero_ether_addr(ð_mask->src) ||
1242 rte_flow_error_set(error, EINVAL,
1243 RTE_FLOW_ERROR_TYPE_ITEM,
1245 "Invalid ether spec/mask");
1250 rte_memcpy(&filter->outer_mac,
1254 rte_memcpy(&filter->inner_mac,
1260 o_eth_spec = eth_spec;
1261 o_eth_mask = eth_mask;
1263 i_eth_spec = eth_spec;
1264 i_eth_mask = eth_mask;
1268 case RTE_FLOW_ITEM_TYPE_VLAN:
1270 (const struct rte_flow_item_vlan *)item->spec;
1272 (const struct rte_flow_item_vlan *)item->mask;
1275 (const struct rte_flow_item_vlan *)item->spec;
1277 (const struct rte_flow_item_vlan *)item->mask;
1278 if (!(vlan_spec && vlan_mask)) {
1279 rte_flow_error_set(error, EINVAL,
1280 RTE_FLOW_ERROR_TYPE_ITEM,
1282 "Invalid vlan item");
1286 if (vlan_spec || vlan_mask)
1287 rte_flow_error_set(error, EINVAL,
1288 RTE_FLOW_ERROR_TYPE_ITEM,
1290 "Invalid vlan item");
1294 case RTE_FLOW_ITEM_TYPE_IPV4:
1295 case RTE_FLOW_ITEM_TYPE_IPV6:
1296 case RTE_FLOW_ITEM_TYPE_UDP:
1297 /* IPv4/IPv6/UDP are used to describe protocol,
1298 * spec amd mask should be NULL.
1300 if (item->spec || item->mask) {
1301 rte_flow_error_set(error, EINVAL,
1302 RTE_FLOW_ERROR_TYPE_ITEM,
1304 "Invalid IPv4 item");
1308 case RTE_FLOW_ITEM_TYPE_VXLAN:
1310 (const struct rte_flow_item_vxlan *)item->spec;
1312 (const struct rte_flow_item_vxlan *)item->mask;
1313 /* Check if VXLAN item is used to describe protocol.
1314 * If yes, both spec and mask should be NULL.
1315 * If no, either spec or mask shouldn't be NULL.
1317 if ((!vxlan_spec && vxlan_mask) ||
1318 (vxlan_spec && !vxlan_mask)) {
1319 rte_flow_error_set(error, EINVAL,
1320 RTE_FLOW_ERROR_TYPE_ITEM,
1322 "Invalid VXLAN item");
1326 /* Check if VNI is masked. */
1329 i40e_check_tenant_id_mask(vxlan_mask->vni);
1330 if (is_vni_masked < 0) {
1331 rte_flow_error_set(error, EINVAL,
1332 RTE_FLOW_ERROR_TYPE_ITEM,
1334 "Invalid VNI mask");
1345 /* Check specification and mask to get the filter type */
1346 if (vlan_spec && vlan_mask &&
1347 (vlan_mask->tci == rte_cpu_to_be_16(I40E_TCI_MASK))) {
1348 /* If there's inner vlan */
1349 filter->inner_vlan = rte_be_to_cpu_16(vlan_spec->tci)
1351 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1352 /* If there's vxlan */
1353 rte_memcpy(&filter->tenant_id, vxlan_spec->vni,
1354 RTE_DIM(vxlan_spec->vni));
1355 if (!o_eth_spec && !o_eth_mask &&
1356 i_eth_spec && i_eth_mask)
1357 filter->filter_type =
1358 RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
1360 rte_flow_error_set(error, EINVAL,
1361 RTE_FLOW_ERROR_TYPE_ITEM,
1363 "Invalid filter type");
1366 } else if (!vxlan_spec && !vxlan_mask) {
1367 /* If there's no vxlan */
1368 if (!o_eth_spec && !o_eth_mask &&
1369 i_eth_spec && i_eth_mask)
1370 filter->filter_type =
1371 RTE_TUNNEL_FILTER_IMAC_IVLAN;
1373 rte_flow_error_set(error, EINVAL,
1374 RTE_FLOW_ERROR_TYPE_ITEM,
1376 "Invalid filter type");
1380 rte_flow_error_set(error, EINVAL,
1381 RTE_FLOW_ERROR_TYPE_ITEM,
1383 "Invalid filter type");
1386 } else if ((!vlan_spec && !vlan_mask) ||
1387 (vlan_spec && vlan_mask && vlan_mask->tci == 0x0)) {
1388 /* If there's no inner vlan */
1389 if (vxlan_spec && vxlan_mask && !is_vni_masked) {
1390 /* If there's vxlan */
1391 rte_memcpy(&filter->tenant_id, vxlan_spec->vni,
1392 RTE_DIM(vxlan_spec->vni));
1393 if (!o_eth_spec && !o_eth_mask &&
1394 i_eth_spec && i_eth_mask)
1395 filter->filter_type =
1396 RTE_TUNNEL_FILTER_IMAC_TENID;
1397 else if (o_eth_spec && o_eth_mask &&
1398 i_eth_spec && i_eth_mask)
1399 filter->filter_type =
1400 RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
1401 } else if (!vxlan_spec && !vxlan_mask) {
1402 /* If there's no vxlan */
1403 if (!o_eth_spec && !o_eth_mask &&
1404 i_eth_spec && i_eth_mask) {
1405 filter->filter_type = ETH_TUNNEL_FILTER_IMAC;
1407 rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1409 "Invalid filter type");
1413 rte_flow_error_set(error, EINVAL,
1414 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1415 "Invalid filter type");
1419 rte_flow_error_set(error, EINVAL,
1420 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1421 "Not supported by tunnel filter.");
1425 filter->tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
1431 i40e_flow_parse_tunnel_pattern(__rte_unused struct rte_eth_dev *dev,
1432 const struct rte_flow_item *pattern,
1433 struct rte_flow_error *error,
1434 struct rte_eth_tunnel_filter_conf *filter)
1438 ret = i40e_flow_parse_vxlan_pattern(pattern, error, filter);
1444 i40e_flow_parse_tunnel_filter(struct rte_eth_dev *dev,
1445 const struct rte_flow_attr *attr,
1446 const struct rte_flow_item pattern[],
1447 const struct rte_flow_action actions[],
1448 struct rte_flow_error *error,
1449 union i40e_filter_t *filter)
1451 struct rte_eth_tunnel_filter_conf *tunnel_filter =
1452 &filter->tunnel_filter;
1455 ret = i40e_flow_parse_tunnel_pattern(dev, pattern,
1456 error, tunnel_filter);
1460 ret = i40e_flow_parse_tunnel_action(dev, actions, error, tunnel_filter);
1464 ret = i40e_flow_parse_attr(attr, error);
1468 cons_filter_type = RTE_ETH_FILTER_TUNNEL;
1474 i40e_flow_validate(struct rte_eth_dev *dev,
1475 const struct rte_flow_attr *attr,
1476 const struct rte_flow_item pattern[],
1477 const struct rte_flow_action actions[],
1478 struct rte_flow_error *error)
1480 struct rte_flow_item *items; /* internal pattern w/o VOID items */
1481 parse_filter_t parse_filter;
1482 uint32_t item_num = 0; /* non-void item number of pattern*/
1487 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1488 NULL, "NULL pattern.");
1493 rte_flow_error_set(error, EINVAL,
1494 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1495 NULL, "NULL action.");
1500 rte_flow_error_set(error, EINVAL,
1501 RTE_FLOW_ERROR_TYPE_ATTR,
1502 NULL, "NULL attribute.");
1506 memset(&cons_filter, 0, sizeof(cons_filter));
1508 /* Get the non-void item number of pattern */
1509 while ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_END) {
1510 if ((pattern + i)->type != RTE_FLOW_ITEM_TYPE_VOID)
1516 items = rte_zmalloc("i40e_pattern",
1517 item_num * sizeof(struct rte_flow_item), 0);
1519 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1520 NULL, "No memory for PMD internal items.");
1524 i40e_pattern_skip_void_item(items, pattern);
1526 /* Find if there's matched parse filter function */
1527 parse_filter = i40e_find_parse_filter_func(items);
1528 if (!parse_filter) {
1529 rte_flow_error_set(error, EINVAL,
1530 RTE_FLOW_ERROR_TYPE_ITEM,
1531 pattern, "Unsupported pattern");
1535 ret = parse_filter(dev, attr, items, actions, error, &cons_filter);
1542 static struct rte_flow *
1543 i40e_flow_create(struct rte_eth_dev *dev,
1544 const struct rte_flow_attr *attr,
1545 const struct rte_flow_item pattern[],
1546 const struct rte_flow_action actions[],
1547 struct rte_flow_error *error)
1549 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1550 struct rte_flow *flow;
1553 flow = rte_zmalloc("i40e_flow", sizeof(struct rte_flow), 0);
1555 rte_flow_error_set(error, ENOMEM,
1556 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1557 "Failed to allocate memory");
1561 ret = i40e_flow_validate(dev, attr, pattern, actions, error);
1565 switch (cons_filter_type) {
1566 case RTE_ETH_FILTER_ETHERTYPE:
1567 ret = i40e_ethertype_filter_set(pf,
1568 &cons_filter.ethertype_filter, 1);
1571 flow->rule = TAILQ_LAST(&pf->ethertype.ethertype_list,
1572 i40e_ethertype_filter_list);
1574 case RTE_ETH_FILTER_FDIR:
1575 ret = i40e_add_del_fdir_filter(dev,
1576 &cons_filter.fdir_filter, 1);
1579 flow->rule = TAILQ_LAST(&pf->fdir.fdir_list,
1580 i40e_fdir_filter_list);
1582 case RTE_ETH_FILTER_TUNNEL:
1583 ret = i40e_dev_tunnel_filter_set(pf,
1584 &cons_filter.tunnel_filter, 1);
1587 flow->rule = TAILQ_LAST(&pf->tunnel.tunnel_list,
1588 i40e_tunnel_filter_list);
1594 flow->filter_type = cons_filter_type;
1595 TAILQ_INSERT_TAIL(&pf->flow_list, flow, node);
1599 rte_flow_error_set(error, -ret,
1600 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1601 "Failed to create flow.");