1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <rte_common.h>
12 #include <rte_interrupts.h>
13 #include <rte_byteorder.h>
15 #include <rte_debug.h>
17 #include <rte_ether.h>
18 #include <rte_ethdev_driver.h>
19 #include <rte_ethdev_pci.h>
20 #include <rte_memory.h>
22 #include <rte_atomic.h>
23 #include <rte_malloc.h>
26 #include <rte_flow_driver.h>
28 #include "e1000_logs.h"
29 #include "base/e1000_api.h"
30 #include "e1000_ethdev.h"
32 #define NEXT_ITEM_OF_PATTERN(item, pattern, index) \
34 item = (pattern) + (index); \
35 while (item->type == RTE_FLOW_ITEM_TYPE_VOID) { \
37 item = (pattern) + (index); \
41 #define NEXT_ITEM_OF_ACTION(act, actions, index) \
43 act = (actions) + (index); \
44 while (act->type == RTE_FLOW_ACTION_TYPE_VOID) {\
46 act = (actions) + (index); \
50 #define IGB_FLEX_RAW_NUM 12
53 * Please aware there's an asumption for all the parsers.
54 * rte_flow_item is using big endian, rte_flow_attr and
55 * rte_flow_action are using CPU order.
56 * Because the pattern is used to describe the packets,
57 * normally the packets should use network order.
61 * Parse the rule to see if it is a n-tuple rule.
62 * And get the n-tuple filter info BTW.
64 * The first not void item can be ETH or IPV4.
65 * The second not void item must be IPV4 if the first one is ETH.
66 * The third not void item must be UDP or TCP or SCTP
67 * The next not void item must be END.
69 * The first not void action should be QUEUE.
70 * The next not void action should be END.
74 * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
75 * dst_addr 192.167.3.50 0xFFFFFFFF
76 * next_proto_id 17 0xFF
77 * UDP/TCP/ src_port 80 0xFFFF
78 * SCTP dst_port 80 0xFFFF
80 * other members in mask and spec should set to 0x00.
81 * item->last should be NULL.
84 cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
85 const struct rte_flow_item pattern[],
86 const struct rte_flow_action actions[],
87 struct rte_eth_ntuple_filter *filter,
88 struct rte_flow_error *error)
90 const struct rte_flow_item *item;
91 const struct rte_flow_action *act;
92 const struct rte_flow_item_ipv4 *ipv4_spec;
93 const struct rte_flow_item_ipv4 *ipv4_mask;
94 const struct rte_flow_item_tcp *tcp_spec;
95 const struct rte_flow_item_tcp *tcp_mask;
96 const struct rte_flow_item_udp *udp_spec;
97 const struct rte_flow_item_udp *udp_mask;
98 const struct rte_flow_item_sctp *sctp_spec;
99 const struct rte_flow_item_sctp *sctp_mask;
103 rte_flow_error_set(error,
104 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
105 NULL, "NULL pattern.");
110 rte_flow_error_set(error, EINVAL,
111 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
112 NULL, "NULL action.");
116 rte_flow_error_set(error, EINVAL,
117 RTE_FLOW_ERROR_TYPE_ATTR,
118 NULL, "NULL attribute.");
125 /* the first not void item can be MAC or IPv4 */
126 NEXT_ITEM_OF_PATTERN(item, pattern, index);
128 if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
129 item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
130 rte_flow_error_set(error, EINVAL,
131 RTE_FLOW_ERROR_TYPE_ITEM,
132 item, "Not supported by ntuple filter");
136 if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
137 /*Not supported last point for range*/
139 rte_flow_error_set(error,
141 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
142 item, "Not supported last point for range");
145 /* if the first item is MAC, the content should be NULL */
146 if (item->spec || item->mask) {
147 rte_flow_error_set(error, EINVAL,
148 RTE_FLOW_ERROR_TYPE_ITEM,
149 item, "Not supported by ntuple filter");
152 /* check if the next not void item is IPv4 */
154 NEXT_ITEM_OF_PATTERN(item, pattern, index);
155 if (item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
156 rte_flow_error_set(error,
157 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
158 item, "Not supported by ntuple filter");
163 /* get the IPv4 info */
164 if (!item->spec || !item->mask) {
165 rte_flow_error_set(error, EINVAL,
166 RTE_FLOW_ERROR_TYPE_ITEM,
167 item, "Invalid ntuple mask");
170 /* Not supported last point for range */
172 rte_flow_error_set(error, EINVAL,
173 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
174 item, "Not supported last point for range");
178 ipv4_mask = item->mask;
180 * Only support src & dst addresses, protocol,
181 * others should be masked.
184 if (ipv4_mask->hdr.version_ihl ||
185 ipv4_mask->hdr.type_of_service ||
186 ipv4_mask->hdr.total_length ||
187 ipv4_mask->hdr.packet_id ||
188 ipv4_mask->hdr.fragment_offset ||
189 ipv4_mask->hdr.time_to_live ||
190 ipv4_mask->hdr.hdr_checksum) {
191 rte_flow_error_set(error,
192 EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
193 item, "Not supported by ntuple filter");
197 filter->dst_ip_mask = ipv4_mask->hdr.dst_addr;
198 filter->src_ip_mask = ipv4_mask->hdr.src_addr;
199 filter->proto_mask = ipv4_mask->hdr.next_proto_id;
201 ipv4_spec = item->spec;
202 filter->dst_ip = ipv4_spec->hdr.dst_addr;
203 filter->src_ip = ipv4_spec->hdr.src_addr;
204 filter->proto = ipv4_spec->hdr.next_proto_id;
206 /* check if the next not void item is TCP or UDP or SCTP */
208 NEXT_ITEM_OF_PATTERN(item, pattern, index);
209 if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
210 item->type != RTE_FLOW_ITEM_TYPE_UDP &&
211 item->type != RTE_FLOW_ITEM_TYPE_SCTP) {
212 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
213 rte_flow_error_set(error, EINVAL,
214 RTE_FLOW_ERROR_TYPE_ITEM,
215 item, "Not supported by ntuple filter");
219 /* Not supported last point for range */
221 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
222 rte_flow_error_set(error, EINVAL,
223 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
224 item, "Not supported last point for range");
228 /* get the TCP/UDP/SCTP info */
229 if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
230 if (item->spec && item->mask) {
231 tcp_mask = item->mask;
234 * Only support src & dst ports, tcp flags,
235 * others should be masked.
237 if (tcp_mask->hdr.sent_seq ||
238 tcp_mask->hdr.recv_ack ||
239 tcp_mask->hdr.data_off ||
240 tcp_mask->hdr.rx_win ||
241 tcp_mask->hdr.cksum ||
242 tcp_mask->hdr.tcp_urp) {
244 sizeof(struct rte_eth_ntuple_filter));
245 rte_flow_error_set(error, EINVAL,
246 RTE_FLOW_ERROR_TYPE_ITEM,
247 item, "Not supported by ntuple filter");
251 filter->dst_port_mask = tcp_mask->hdr.dst_port;
252 filter->src_port_mask = tcp_mask->hdr.src_port;
253 if (tcp_mask->hdr.tcp_flags == 0xFF) {
254 filter->flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
255 } else if (!tcp_mask->hdr.tcp_flags) {
256 filter->flags &= ~RTE_NTUPLE_FLAGS_TCP_FLAG;
259 sizeof(struct rte_eth_ntuple_filter));
260 rte_flow_error_set(error, EINVAL,
261 RTE_FLOW_ERROR_TYPE_ITEM,
262 item, "Not supported by ntuple filter");
266 tcp_spec = item->spec;
267 filter->dst_port = tcp_spec->hdr.dst_port;
268 filter->src_port = tcp_spec->hdr.src_port;
269 filter->tcp_flags = tcp_spec->hdr.tcp_flags;
271 } else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
272 if (item->spec && item->mask) {
273 udp_mask = item->mask;
276 * Only support src & dst ports,
277 * others should be masked.
279 if (udp_mask->hdr.dgram_len ||
280 udp_mask->hdr.dgram_cksum) {
282 sizeof(struct rte_eth_ntuple_filter));
283 rte_flow_error_set(error, EINVAL,
284 RTE_FLOW_ERROR_TYPE_ITEM,
285 item, "Not supported by ntuple filter");
289 filter->dst_port_mask = udp_mask->hdr.dst_port;
290 filter->src_port_mask = udp_mask->hdr.src_port;
292 udp_spec = item->spec;
293 filter->dst_port = udp_spec->hdr.dst_port;
294 filter->src_port = udp_spec->hdr.src_port;
297 if (item->spec && item->mask) {
298 sctp_mask = item->mask;
301 * Only support src & dst ports,
302 * others should be masked.
304 if (sctp_mask->hdr.tag ||
305 sctp_mask->hdr.cksum) {
307 sizeof(struct rte_eth_ntuple_filter));
308 rte_flow_error_set(error, EINVAL,
309 RTE_FLOW_ERROR_TYPE_ITEM,
310 item, "Not supported by ntuple filter");
314 filter->dst_port_mask = sctp_mask->hdr.dst_port;
315 filter->src_port_mask = sctp_mask->hdr.src_port;
317 sctp_spec = (const struct rte_flow_item_sctp *)
319 filter->dst_port = sctp_spec->hdr.dst_port;
320 filter->src_port = sctp_spec->hdr.src_port;
323 /* check if the next not void item is END */
325 NEXT_ITEM_OF_PATTERN(item, pattern, index);
326 if (item->type != RTE_FLOW_ITEM_TYPE_END) {
327 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
328 rte_flow_error_set(error, EINVAL,
329 RTE_FLOW_ERROR_TYPE_ITEM,
330 item, "Not supported by ntuple filter");
338 * n-tuple only supports forwarding,
339 * check if the first not void action is QUEUE.
341 NEXT_ITEM_OF_ACTION(act, actions, index);
342 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
343 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
344 rte_flow_error_set(error, EINVAL,
345 RTE_FLOW_ERROR_TYPE_ACTION,
346 item, "Not supported action.");
350 ((const struct rte_flow_action_queue *)act->conf)->index;
352 /* check if the next not void item is END */
354 NEXT_ITEM_OF_ACTION(act, actions, index);
355 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
356 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
357 rte_flow_error_set(error, EINVAL,
358 RTE_FLOW_ERROR_TYPE_ACTION,
359 act, "Not supported action.");
364 /* must be input direction */
365 if (!attr->ingress) {
366 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
367 rte_flow_error_set(error, EINVAL,
368 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
369 attr, "Only support ingress.");
375 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
376 rte_flow_error_set(error, EINVAL,
377 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
378 attr, "Not support egress.");
383 if (attr->transfer) {
384 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
385 rte_flow_error_set(error, EINVAL,
386 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
387 attr, "No support for transfer.");
391 if (attr->priority > 0xFFFF) {
392 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
393 rte_flow_error_set(error, EINVAL,
394 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
395 attr, "Error priority.");
398 filter->priority = (uint16_t)attr->priority;
403 /* a specific function for igb because the flags is specific */
405 igb_parse_ntuple_filter(struct rte_eth_dev *dev,
406 const struct rte_flow_attr *attr,
407 const struct rte_flow_item pattern[],
408 const struct rte_flow_action actions[],
409 struct rte_eth_ntuple_filter *filter,
410 struct rte_flow_error *error)
412 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
415 MAC_TYPE_FILTER_SUP(hw->mac.type);
417 ret = cons_parse_ntuple_filter(attr, pattern, actions, filter, error);
422 /* Igb doesn't support many priorities. */
423 if (filter->priority > E1000_2TUPLE_MAX_PRI) {
424 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
425 rte_flow_error_set(error, EINVAL,
426 RTE_FLOW_ERROR_TYPE_ITEM,
427 NULL, "Priority not supported by ntuple filter");
431 if (hw->mac.type == e1000_82576) {
432 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576) {
433 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
434 rte_flow_error_set(error, EINVAL,
435 RTE_FLOW_ERROR_TYPE_ITEM,
436 NULL, "queue number not "
437 "supported by ntuple filter");
440 filter->flags |= RTE_5TUPLE_FLAGS;
442 if (filter->src_ip_mask || filter->dst_ip_mask ||
443 filter->src_port_mask) {
444 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
445 rte_flow_error_set(error, EINVAL,
446 RTE_FLOW_ERROR_TYPE_ITEM,
447 NULL, "only two tuple are "
448 "supported by this filter");
451 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM) {
452 memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
453 rte_flow_error_set(error, EINVAL,
454 RTE_FLOW_ERROR_TYPE_ITEM,
455 NULL, "queue number not "
456 "supported by ntuple filter");
459 filter->flags |= RTE_2TUPLE_FLAGS;
466 * Parse the rule to see if it is a ethertype rule.
467 * And get the ethertype filter info BTW.
469 * The first not void item can be ETH.
470 * The next not void item must be END.
472 * The first not void action should be QUEUE.
473 * The next not void action should be END.
476 * ETH type 0x0807 0xFFFF
478 * other members in mask and spec should set to 0x00.
479 * item->last should be NULL.
482 cons_parse_ethertype_filter(const struct rte_flow_attr *attr,
483 const struct rte_flow_item *pattern,
484 const struct rte_flow_action *actions,
485 struct rte_eth_ethertype_filter *filter,
486 struct rte_flow_error *error)
488 const struct rte_flow_item *item;
489 const struct rte_flow_action *act;
490 const struct rte_flow_item_eth *eth_spec;
491 const struct rte_flow_item_eth *eth_mask;
492 const struct rte_flow_action_queue *act_q;
496 rte_flow_error_set(error, EINVAL,
497 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
498 NULL, "NULL pattern.");
503 rte_flow_error_set(error, EINVAL,
504 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
505 NULL, "NULL action.");
510 rte_flow_error_set(error, EINVAL,
511 RTE_FLOW_ERROR_TYPE_ATTR,
512 NULL, "NULL attribute.");
519 /* The first non-void item should be MAC. */
520 NEXT_ITEM_OF_PATTERN(item, pattern, index);
521 if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
522 rte_flow_error_set(error, EINVAL,
523 RTE_FLOW_ERROR_TYPE_ITEM,
524 item, "Not supported by ethertype filter");
528 /*Not supported last point for range*/
530 rte_flow_error_set(error, EINVAL,
531 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
532 item, "Not supported last point for range");
536 /* Get the MAC info. */
537 if (!item->spec || !item->mask) {
538 rte_flow_error_set(error, EINVAL,
539 RTE_FLOW_ERROR_TYPE_ITEM,
540 item, "Not supported by ethertype filter");
544 eth_spec = item->spec;
545 eth_mask = item->mask;
547 /* Mask bits of source MAC address must be full of 0.
548 * Mask bits of destination MAC address must be full
551 if (!is_zero_ether_addr(ð_mask->src) ||
552 (!is_zero_ether_addr(ð_mask->dst) &&
553 !is_broadcast_ether_addr(ð_mask->dst))) {
554 rte_flow_error_set(error, EINVAL,
555 RTE_FLOW_ERROR_TYPE_ITEM,
556 item, "Invalid ether address mask");
560 if ((eth_mask->type & UINT16_MAX) != UINT16_MAX) {
561 rte_flow_error_set(error, EINVAL,
562 RTE_FLOW_ERROR_TYPE_ITEM,
563 item, "Invalid ethertype mask");
567 /* If mask bits of destination MAC address
568 * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
570 if (is_broadcast_ether_addr(ð_mask->dst)) {
571 filter->mac_addr = eth_spec->dst;
572 filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
574 filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
576 filter->ether_type = rte_be_to_cpu_16(eth_spec->type);
578 /* Check if the next non-void item is END. */
580 NEXT_ITEM_OF_PATTERN(item, pattern, index);
581 if (item->type != RTE_FLOW_ITEM_TYPE_END) {
582 rte_flow_error_set(error, EINVAL,
583 RTE_FLOW_ERROR_TYPE_ITEM,
584 item, "Not supported by ethertype filter.");
591 /* Check if the first non-void action is QUEUE or DROP. */
592 NEXT_ITEM_OF_ACTION(act, actions, index);
593 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
594 act->type != RTE_FLOW_ACTION_TYPE_DROP) {
595 rte_flow_error_set(error, EINVAL,
596 RTE_FLOW_ERROR_TYPE_ACTION,
597 act, "Not supported action.");
601 if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
602 act_q = (const struct rte_flow_action_queue *)act->conf;
603 filter->queue = act_q->index;
605 filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
608 /* Check if the next non-void item is END */
610 NEXT_ITEM_OF_ACTION(act, actions, index);
611 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
612 rte_flow_error_set(error, EINVAL,
613 RTE_FLOW_ERROR_TYPE_ACTION,
614 act, "Not supported action.");
619 /* Must be input direction */
620 if (!attr->ingress) {
621 rte_flow_error_set(error, EINVAL,
622 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
623 attr, "Only support ingress.");
629 rte_flow_error_set(error, EINVAL,
630 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
631 attr, "Not support egress.");
636 if (attr->transfer) {
637 rte_flow_error_set(error, EINVAL,
638 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
639 attr, "No support for transfer.");
644 if (attr->priority) {
645 rte_flow_error_set(error, EINVAL,
646 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
647 attr, "Not support priority.");
653 rte_flow_error_set(error, EINVAL,
654 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
655 attr, "Not support group.");
663 igb_parse_ethertype_filter(struct rte_eth_dev *dev,
664 const struct rte_flow_attr *attr,
665 const struct rte_flow_item pattern[],
666 const struct rte_flow_action actions[],
667 struct rte_eth_ethertype_filter *filter,
668 struct rte_flow_error *error)
670 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
673 MAC_TYPE_FILTER_SUP(hw->mac.type);
675 ret = cons_parse_ethertype_filter(attr, pattern,
676 actions, filter, error);
681 if (hw->mac.type == e1000_82576) {
682 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576) {
683 memset(filter, 0, sizeof(
684 struct rte_eth_ethertype_filter));
685 rte_flow_error_set(error, EINVAL,
686 RTE_FLOW_ERROR_TYPE_ITEM,
687 NULL, "queue number not supported "
688 "by ethertype filter");
692 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM) {
693 memset(filter, 0, sizeof(
694 struct rte_eth_ethertype_filter));
695 rte_flow_error_set(error, EINVAL,
696 RTE_FLOW_ERROR_TYPE_ITEM,
697 NULL, "queue number not supported "
698 "by ethertype filter");
703 if (filter->ether_type == ETHER_TYPE_IPv4 ||
704 filter->ether_type == ETHER_TYPE_IPv6) {
705 memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
706 rte_flow_error_set(error, EINVAL,
707 RTE_FLOW_ERROR_TYPE_ITEM,
708 NULL, "IPv4/IPv6 not supported by ethertype filter");
712 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
713 memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
714 rte_flow_error_set(error, EINVAL,
715 RTE_FLOW_ERROR_TYPE_ITEM,
716 NULL, "mac compare is unsupported");
720 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
721 memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
722 rte_flow_error_set(error, EINVAL,
723 RTE_FLOW_ERROR_TYPE_ITEM,
724 NULL, "drop option is unsupported");
732 * Parse the rule to see if it is a TCP SYN rule.
733 * And get the TCP SYN filter info BTW.
735 * The first not void item must be ETH.
736 * The second not void item must be IPV4 or IPV6.
737 * The third not void item must be TCP.
738 * The next not void item must be END.
740 * The first not void action should be QUEUE.
741 * The next not void action should be END.
745 * IPV4/IPV6 NULL NULL
746 * TCP tcp_flags 0x02 0xFF
748 * other members in mask and spec should set to 0x00.
749 * item->last should be NULL.
752 cons_parse_syn_filter(const struct rte_flow_attr *attr,
753 const struct rte_flow_item pattern[],
754 const struct rte_flow_action actions[],
755 struct rte_eth_syn_filter *filter,
756 struct rte_flow_error *error)
758 const struct rte_flow_item *item;
759 const struct rte_flow_action *act;
760 const struct rte_flow_item_tcp *tcp_spec;
761 const struct rte_flow_item_tcp *tcp_mask;
762 const struct rte_flow_action_queue *act_q;
766 rte_flow_error_set(error, EINVAL,
767 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
768 NULL, "NULL pattern.");
773 rte_flow_error_set(error, EINVAL,
774 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
775 NULL, "NULL action.");
780 rte_flow_error_set(error, EINVAL,
781 RTE_FLOW_ERROR_TYPE_ATTR,
782 NULL, "NULL attribute.");
789 /* the first not void item should be MAC or IPv4 or IPv6 or TCP */
790 NEXT_ITEM_OF_PATTERN(item, pattern, index);
791 if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
792 item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
793 item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
794 item->type != RTE_FLOW_ITEM_TYPE_TCP) {
795 rte_flow_error_set(error, EINVAL,
796 RTE_FLOW_ERROR_TYPE_ITEM,
797 item, "Not supported by syn filter");
800 /*Not supported last point for range*/
802 rte_flow_error_set(error, EINVAL,
803 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
804 item, "Not supported last point for range");
809 if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
810 /* if the item is MAC, the content should be NULL */
811 if (item->spec || item->mask) {
812 rte_flow_error_set(error, EINVAL,
813 RTE_FLOW_ERROR_TYPE_ITEM,
814 item, "Invalid SYN address mask");
818 /* check if the next not void item is IPv4 or IPv6 */
820 NEXT_ITEM_OF_PATTERN(item, pattern, index);
821 if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
822 item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
823 rte_flow_error_set(error, EINVAL,
824 RTE_FLOW_ERROR_TYPE_ITEM,
825 item, "Not supported by syn filter");
831 if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
832 item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
833 /* if the item is IP, the content should be NULL */
834 if (item->spec || item->mask) {
835 rte_flow_error_set(error, EINVAL,
836 RTE_FLOW_ERROR_TYPE_ITEM,
837 item, "Invalid SYN mask");
841 /* check if the next not void item is TCP */
843 NEXT_ITEM_OF_PATTERN(item, pattern, index);
844 if (item->type != RTE_FLOW_ITEM_TYPE_TCP) {
845 rte_flow_error_set(error, EINVAL,
846 RTE_FLOW_ERROR_TYPE_ITEM,
847 item, "Not supported by syn filter");
852 /* Get the TCP info. Only support SYN. */
853 if (!item->spec || !item->mask) {
854 rte_flow_error_set(error, EINVAL,
855 RTE_FLOW_ERROR_TYPE_ITEM,
856 item, "Invalid SYN mask");
859 /*Not supported last point for range*/
861 rte_flow_error_set(error, EINVAL,
862 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
863 item, "Not supported last point for range");
867 tcp_spec = item->spec;
868 tcp_mask = item->mask;
869 if (!(tcp_spec->hdr.tcp_flags & TCP_SYN_FLAG) ||
870 tcp_mask->hdr.src_port ||
871 tcp_mask->hdr.dst_port ||
872 tcp_mask->hdr.sent_seq ||
873 tcp_mask->hdr.recv_ack ||
874 tcp_mask->hdr.data_off ||
875 tcp_mask->hdr.tcp_flags != TCP_SYN_FLAG ||
876 tcp_mask->hdr.rx_win ||
877 tcp_mask->hdr.cksum ||
878 tcp_mask->hdr.tcp_urp) {
879 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
880 rte_flow_error_set(error, EINVAL,
881 RTE_FLOW_ERROR_TYPE_ITEM,
882 item, "Not supported by syn filter");
886 /* check if the next not void item is END */
888 NEXT_ITEM_OF_PATTERN(item, pattern, index);
889 if (item->type != RTE_FLOW_ITEM_TYPE_END) {
890 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
891 rte_flow_error_set(error, EINVAL,
892 RTE_FLOW_ERROR_TYPE_ITEM,
893 item, "Not supported by syn filter");
900 /* check if the first not void action is QUEUE. */
901 NEXT_ITEM_OF_ACTION(act, actions, index);
902 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
903 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
904 rte_flow_error_set(error, EINVAL,
905 RTE_FLOW_ERROR_TYPE_ACTION,
906 act, "Not supported action.");
910 act_q = (const struct rte_flow_action_queue *)act->conf;
911 filter->queue = act_q->index;
913 /* check if the next not void item is END */
915 NEXT_ITEM_OF_ACTION(act, actions, index);
916 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
917 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
918 rte_flow_error_set(error, EINVAL,
919 RTE_FLOW_ERROR_TYPE_ACTION,
920 act, "Not supported action.");
925 /* must be input direction */
926 if (!attr->ingress) {
927 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
928 rte_flow_error_set(error, EINVAL,
929 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
930 attr, "Only support ingress.");
936 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
937 rte_flow_error_set(error, EINVAL,
938 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
939 attr, "Not support egress.");
944 if (attr->transfer) {
945 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
946 rte_flow_error_set(error, EINVAL,
947 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
948 attr, "No support for transfer.");
952 /* Support 2 priorities, the lowest or highest. */
953 if (!attr->priority) {
955 } else if (attr->priority == (uint32_t)~0U) {
958 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
959 rte_flow_error_set(error, EINVAL,
960 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
961 attr, "Not support priority.");
969 igb_parse_syn_filter(struct rte_eth_dev *dev,
970 const struct rte_flow_attr *attr,
971 const struct rte_flow_item pattern[],
972 const struct rte_flow_action actions[],
973 struct rte_eth_syn_filter *filter,
974 struct rte_flow_error *error)
976 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
979 MAC_TYPE_FILTER_SUP(hw->mac.type);
981 ret = cons_parse_syn_filter(attr, pattern,
982 actions, filter, error);
984 if (hw->mac.type == e1000_82576) {
985 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576) {
986 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
987 rte_flow_error_set(error, EINVAL,
988 RTE_FLOW_ERROR_TYPE_ITEM,
989 NULL, "queue number not "
990 "supported by syn filter");
994 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM) {
995 memset(filter, 0, sizeof(struct rte_eth_syn_filter));
996 rte_flow_error_set(error, EINVAL,
997 RTE_FLOW_ERROR_TYPE_ITEM,
998 NULL, "queue number not "
999 "supported by syn filter");
1011 * Parse the rule to see if it is a flex byte rule.
1012 * And get the flex byte filter info BTW.
1014 * The first not void item must be RAW.
1015 * The second not void item can be RAW or END.
1016 * The third not void item can be RAW or END.
1017 * The last not void item must be END.
1019 * The first not void action should be QUEUE.
1020 * The next not void action should be END.
1023 * RAW relative 0 0x1
1024 * offset 0 0xFFFFFFFF
1025 * pattern {0x08, 0x06} {0xFF, 0xFF}
1026 * RAW relative 1 0x1
1027 * offset 100 0xFFFFFFFF
1028 * pattern {0x11, 0x22, 0x33} {0xFF, 0xFF, 0xFF}
1030 * other members in mask and spec should set to 0x00.
1031 * item->last should be NULL.
1034 cons_parse_flex_filter(const struct rte_flow_attr *attr,
1035 const struct rte_flow_item pattern[],
1036 const struct rte_flow_action actions[],
1037 struct rte_eth_flex_filter *filter,
1038 struct rte_flow_error *error)
1040 const struct rte_flow_item *item;
1041 const struct rte_flow_action *act;
1042 const struct rte_flow_item_raw *raw_spec;
1043 const struct rte_flow_item_raw *raw_mask;
1044 const struct rte_flow_action_queue *act_q;
1045 uint32_t index, i, offset, total_offset;
1046 uint32_t max_offset = 0;
1047 int32_t shift, j, raw_index = 0;
1048 int32_t relative[IGB_FLEX_RAW_NUM] = {0};
1049 int32_t raw_offset[IGB_FLEX_RAW_NUM] = {0};
1052 rte_flow_error_set(error, EINVAL,
1053 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1054 NULL, "NULL pattern.");
1059 rte_flow_error_set(error, EINVAL,
1060 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1061 NULL, "NULL action.");
1066 rte_flow_error_set(error, EINVAL,
1067 RTE_FLOW_ERROR_TYPE_ATTR,
1068 NULL, "NULL attribute.");
1077 /* the first not void item should be RAW */
1078 NEXT_ITEM_OF_PATTERN(item, pattern, index);
1079 if (item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1080 rte_flow_error_set(error, EINVAL,
1081 RTE_FLOW_ERROR_TYPE_ITEM,
1082 item, "Not supported by flex filter");
1085 /*Not supported last point for range*/
1087 rte_flow_error_set(error, EINVAL,
1088 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1089 item, "Not supported last point for range");
1093 raw_spec = item->spec;
1094 raw_mask = item->mask;
1096 if (!raw_mask->length ||
1097 !raw_mask->relative) {
1098 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1099 rte_flow_error_set(error, EINVAL,
1100 RTE_FLOW_ERROR_TYPE_ITEM,
1101 item, "Not supported by flex filter");
1105 if (raw_mask->offset)
1106 offset = raw_spec->offset;
1110 for (j = 0; j < raw_spec->length; j++) {
1111 if (raw_mask->pattern[j] != 0xFF) {
1112 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1113 rte_flow_error_set(error, EINVAL,
1114 RTE_FLOW_ERROR_TYPE_ITEM,
1115 item, "Not supported by flex filter");
1122 if (raw_spec->relative) {
1123 for (j = raw_index; j > 0; j--) {
1124 total_offset += raw_offset[j - 1];
1125 if (!relative[j - 1])
1128 if (total_offset + raw_spec->length + offset > max_offset)
1129 max_offset = total_offset + raw_spec->length + offset;
1131 if (raw_spec->length + offset > max_offset)
1132 max_offset = raw_spec->length + offset;
1135 if ((raw_spec->length + offset + total_offset) >
1136 RTE_FLEX_FILTER_MAXLEN) {
1137 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1138 rte_flow_error_set(error, EINVAL,
1139 RTE_FLOW_ERROR_TYPE_ITEM,
1140 item, "Not supported by flex filter");
1144 if (raw_spec->relative == 0) {
1145 for (j = 0; j < raw_spec->length; j++)
1146 filter->bytes[offset + j] =
1147 raw_spec->pattern[j];
1148 j = offset / CHAR_BIT;
1149 shift = offset % CHAR_BIT;
1151 for (j = 0; j < raw_spec->length; j++)
1152 filter->bytes[total_offset + offset + j] =
1153 raw_spec->pattern[j];
1154 j = (total_offset + offset) / CHAR_BIT;
1155 shift = (total_offset + offset) % CHAR_BIT;
1160 for ( ; shift < CHAR_BIT; shift++) {
1161 filter->mask[j] |= (0x80 >> shift);
1163 if (i == raw_spec->length)
1165 if (shift == (CHAR_BIT - 1)) {
1171 relative[raw_index] = raw_spec->relative;
1172 raw_offset[raw_index] = offset + raw_spec->length;
1175 /* check if the next not void item is RAW */
1177 NEXT_ITEM_OF_PATTERN(item, pattern, index);
1178 if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
1179 item->type != RTE_FLOW_ITEM_TYPE_END) {
1180 rte_flow_error_set(error, EINVAL,
1181 RTE_FLOW_ERROR_TYPE_ITEM,
1182 item, "Not supported by flex filter");
1186 /* go back to parser */
1187 if (item->type == RTE_FLOW_ITEM_TYPE_RAW) {
1188 /* if the item is RAW, the content should be parse */
1192 filter->len = RTE_ALIGN(max_offset, 8);
1197 /* check if the first not void action is QUEUE. */
1198 NEXT_ITEM_OF_ACTION(act, actions, index);
1199 if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
1200 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1201 rte_flow_error_set(error, EINVAL,
1202 RTE_FLOW_ERROR_TYPE_ACTION,
1203 act, "Not supported action.");
1207 act_q = (const struct rte_flow_action_queue *)act->conf;
1208 filter->queue = act_q->index;
1210 /* check if the next not void item is END */
1212 NEXT_ITEM_OF_ACTION(act, actions, index);
1213 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1214 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1215 rte_flow_error_set(error, EINVAL,
1216 RTE_FLOW_ERROR_TYPE_ACTION,
1217 act, "Not supported action.");
1222 /* must be input direction */
1223 if (!attr->ingress) {
1224 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1225 rte_flow_error_set(error, EINVAL,
1226 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1227 attr, "Only support ingress.");
1233 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1234 rte_flow_error_set(error, EINVAL,
1235 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1236 attr, "Not support egress.");
1241 if (attr->transfer) {
1242 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1243 rte_flow_error_set(error, EINVAL,
1244 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1245 attr, "No support for transfer.");
1249 if (attr->priority > 0xFFFF) {
1250 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1251 rte_flow_error_set(error, EINVAL,
1252 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1253 attr, "Error priority.");
1257 filter->priority = (uint16_t)attr->priority;
1263 igb_parse_flex_filter(struct rte_eth_dev *dev,
1264 const struct rte_flow_attr *attr,
1265 const struct rte_flow_item pattern[],
1266 const struct rte_flow_action actions[],
1267 struct rte_eth_flex_filter *filter,
1268 struct rte_flow_error *error)
1270 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1273 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
1275 ret = cons_parse_flex_filter(attr, pattern,
1276 actions, filter, error);
1278 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM) {
1279 memset(filter, 0, sizeof(struct rte_eth_flex_filter));
1280 rte_flow_error_set(error, EINVAL,
1281 RTE_FLOW_ERROR_TYPE_ITEM,
1282 NULL, "queue number not supported by flex filter");
1286 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN ||
1287 filter->len % sizeof(uint64_t) != 0) {
1288 PMD_DRV_LOG(ERR, "filter's length is out of range");
1292 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
1293 PMD_DRV_LOG(ERR, "filter's priority is out of range");
1304 igb_parse_rss_filter(struct rte_eth_dev *dev,
1305 const struct rte_flow_attr *attr,
1306 const struct rte_flow_action actions[],
1307 struct igb_rte_flow_rss_conf *rss_conf,
1308 struct rte_flow_error *error)
1310 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1311 const struct rte_flow_action *act;
1312 const struct rte_flow_action_rss *rss;
1316 * rss only supports forwarding,
1317 * check if the first not void action is RSS.
1320 NEXT_ITEM_OF_ACTION(act, actions, index);
1321 if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
1322 memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1323 rte_flow_error_set(error, EINVAL,
1324 RTE_FLOW_ERROR_TYPE_ACTION,
1325 act, "Not supported action.");
1329 rss = (const struct rte_flow_action_rss *)act->conf;
1331 if (!rss || !rss->queue_num) {
1332 rte_flow_error_set(error, EINVAL,
1333 RTE_FLOW_ERROR_TYPE_ACTION,
1339 for (n = 0; n < rss->queue_num; n++) {
1340 if (rss->queue[n] >= dev->data->nb_rx_queues) {
1341 rte_flow_error_set(error, EINVAL,
1342 RTE_FLOW_ERROR_TYPE_ACTION,
1344 "queue id > max number of queues");
1349 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
1350 return rte_flow_error_set
1351 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
1352 "non-default RSS hash functions are not supported");
1354 return rte_flow_error_set
1355 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
1356 "a nonzero RSS encapsulation level is not supported");
1357 if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
1358 return rte_flow_error_set
1359 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
1360 "RSS hash key must be exactly 40 bytes");
1361 if (((hw->mac.type == e1000_82576) &&
1362 (rss->queue_num > IGB_MAX_RX_QUEUE_NUM_82576)) ||
1363 ((hw->mac.type != e1000_82576) &&
1364 (rss->queue_num > IGB_MAX_RX_QUEUE_NUM)))
1365 return rte_flow_error_set
1366 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
1367 "too many queues for RSS context");
1368 if (igb_rss_conf_init(dev, rss_conf, rss))
1369 return rte_flow_error_set
1370 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, act,
1371 "RSS context initialization failure");
1373 /* check if the next not void item is END */
1375 NEXT_ITEM_OF_ACTION(act, actions, index);
1376 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1377 memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf));
1378 rte_flow_error_set(error, EINVAL,
1379 RTE_FLOW_ERROR_TYPE_ACTION,
1380 act, "Not supported action.");
1385 /* must be input direction */
1386 if (!attr->ingress) {
1387 memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1388 rte_flow_error_set(error, EINVAL,
1389 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1390 attr, "Only support ingress.");
1396 memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1397 rte_flow_error_set(error, EINVAL,
1398 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1399 attr, "Not support egress.");
1404 if (attr->transfer) {
1405 memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1406 rte_flow_error_set(error, EINVAL,
1407 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1408 attr, "No support for transfer.");
1412 if (attr->priority > 0xFFFF) {
1413 memset(rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1414 rte_flow_error_set(error, EINVAL,
1415 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1416 attr, "Error priority.");
1424 * Create a flow rule.
1425 * Theorically one rule can match more than one filters.
1426 * We will let it use the filter which it hitt first.
1427 * So, the sequence matters.
1429 static struct rte_flow *
1430 igb_flow_create(struct rte_eth_dev *dev,
1431 const struct rte_flow_attr *attr,
1432 const struct rte_flow_item pattern[],
1433 const struct rte_flow_action actions[],
1434 struct rte_flow_error *error)
1437 struct rte_eth_ntuple_filter ntuple_filter;
1438 struct rte_eth_ethertype_filter ethertype_filter;
1439 struct rte_eth_syn_filter syn_filter;
1440 struct rte_eth_flex_filter flex_filter;
1441 struct igb_rte_flow_rss_conf rss_conf;
1442 struct rte_flow *flow = NULL;
1443 struct igb_ntuple_filter_ele *ntuple_filter_ptr;
1444 struct igb_ethertype_filter_ele *ethertype_filter_ptr;
1445 struct igb_eth_syn_filter_ele *syn_filter_ptr;
1446 struct igb_flex_filter_ele *flex_filter_ptr;
1447 struct igb_rss_conf_ele *rss_filter_ptr;
1448 struct igb_flow_mem *igb_flow_mem_ptr;
1450 flow = rte_zmalloc("igb_rte_flow", sizeof(struct rte_flow), 0);
1452 PMD_DRV_LOG(ERR, "failed to allocate memory");
1453 return (struct rte_flow *)flow;
1455 igb_flow_mem_ptr = rte_zmalloc("igb_flow_mem",
1456 sizeof(struct igb_flow_mem), 0);
1457 if (!igb_flow_mem_ptr) {
1458 PMD_DRV_LOG(ERR, "failed to allocate memory");
1462 igb_flow_mem_ptr->flow = flow;
1463 igb_flow_mem_ptr->dev = dev;
1464 TAILQ_INSERT_TAIL(&igb_flow_list,
1465 igb_flow_mem_ptr, entries);
1467 memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
1468 ret = igb_parse_ntuple_filter(dev, attr, pattern,
1469 actions, &ntuple_filter, error);
1471 ret = igb_add_del_ntuple_filter(dev, &ntuple_filter, TRUE);
1473 ntuple_filter_ptr = rte_zmalloc("igb_ntuple_filter",
1474 sizeof(struct igb_ntuple_filter_ele), 0);
1475 if (!ntuple_filter_ptr) {
1476 PMD_DRV_LOG(ERR, "failed to allocate memory");
1480 rte_memcpy(&ntuple_filter_ptr->filter_info,
1482 sizeof(struct rte_eth_ntuple_filter));
1483 TAILQ_INSERT_TAIL(&igb_filter_ntuple_list,
1484 ntuple_filter_ptr, entries);
1485 flow->rule = ntuple_filter_ptr;
1486 flow->filter_type = RTE_ETH_FILTER_NTUPLE;
1492 memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
1493 ret = igb_parse_ethertype_filter(dev, attr, pattern,
1494 actions, ðertype_filter, error);
1496 ret = igb_add_del_ethertype_filter(dev,
1497 ðertype_filter, TRUE);
1499 ethertype_filter_ptr = rte_zmalloc(
1500 "igb_ethertype_filter",
1501 sizeof(struct igb_ethertype_filter_ele), 0);
1502 if (!ethertype_filter_ptr) {
1503 PMD_DRV_LOG(ERR, "failed to allocate memory");
1507 rte_memcpy(ðertype_filter_ptr->filter_info,
1509 sizeof(struct rte_eth_ethertype_filter));
1510 TAILQ_INSERT_TAIL(&igb_filter_ethertype_list,
1511 ethertype_filter_ptr, entries);
1512 flow->rule = ethertype_filter_ptr;
1513 flow->filter_type = RTE_ETH_FILTER_ETHERTYPE;
1519 memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
1520 ret = igb_parse_syn_filter(dev, attr, pattern,
1521 actions, &syn_filter, error);
1523 ret = eth_igb_syn_filter_set(dev, &syn_filter, TRUE);
1525 syn_filter_ptr = rte_zmalloc("igb_syn_filter",
1526 sizeof(struct igb_eth_syn_filter_ele), 0);
1527 if (!syn_filter_ptr) {
1528 PMD_DRV_LOG(ERR, "failed to allocate memory");
1532 rte_memcpy(&syn_filter_ptr->filter_info,
1534 sizeof(struct rte_eth_syn_filter));
1535 TAILQ_INSERT_TAIL(&igb_filter_syn_list,
1538 flow->rule = syn_filter_ptr;
1539 flow->filter_type = RTE_ETH_FILTER_SYN;
1545 memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
1546 ret = igb_parse_flex_filter(dev, attr, pattern,
1547 actions, &flex_filter, error);
1549 ret = eth_igb_add_del_flex_filter(dev, &flex_filter, TRUE);
1551 flex_filter_ptr = rte_zmalloc("igb_flex_filter",
1552 sizeof(struct igb_flex_filter_ele), 0);
1553 if (!flex_filter_ptr) {
1554 PMD_DRV_LOG(ERR, "failed to allocate memory");
1558 rte_memcpy(&flex_filter_ptr->filter_info,
1560 sizeof(struct rte_eth_flex_filter));
1561 TAILQ_INSERT_TAIL(&igb_filter_flex_list,
1562 flex_filter_ptr, entries);
1563 flow->rule = flex_filter_ptr;
1564 flow->filter_type = RTE_ETH_FILTER_FLEXIBLE;
1569 memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1570 ret = igb_parse_rss_filter(dev, attr,
1571 actions, &rss_conf, error);
1573 ret = igb_config_rss_filter(dev, &rss_conf, TRUE);
1575 rss_filter_ptr = rte_zmalloc("igb_rss_filter",
1576 sizeof(struct igb_rss_conf_ele), 0);
1577 if (!rss_filter_ptr) {
1578 PMD_DRV_LOG(ERR, "failed to allocate memory");
1581 igb_rss_conf_init(dev, &rss_filter_ptr->filter_info,
1583 TAILQ_INSERT_TAIL(&igb_filter_rss_list,
1584 rss_filter_ptr, entries);
1585 flow->rule = rss_filter_ptr;
1586 flow->filter_type = RTE_ETH_FILTER_HASH;
1592 TAILQ_REMOVE(&igb_flow_list,
1593 igb_flow_mem_ptr, entries);
1594 rte_flow_error_set(error, -ret,
1595 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1596 "Failed to create flow.");
1597 rte_free(igb_flow_mem_ptr);
1603 * Check if the flow rule is supported by igb.
1604 * It only checkes the format. Don't guarantee the rule can be programmed into
1605 * the HW. Because there can be no enough room for the rule.
1608 igb_flow_validate(__rte_unused struct rte_eth_dev *dev,
1609 const struct rte_flow_attr *attr,
1610 const struct rte_flow_item pattern[],
1611 const struct rte_flow_action actions[],
1612 struct rte_flow_error *error)
1614 struct rte_eth_ntuple_filter ntuple_filter;
1615 struct rte_eth_ethertype_filter ethertype_filter;
1616 struct rte_eth_syn_filter syn_filter;
1617 struct rte_eth_flex_filter flex_filter;
1618 struct igb_rte_flow_rss_conf rss_conf;
1621 memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
1622 ret = igb_parse_ntuple_filter(dev, attr, pattern,
1623 actions, &ntuple_filter, error);
1627 memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
1628 ret = igb_parse_ethertype_filter(dev, attr, pattern,
1629 actions, ðertype_filter, error);
1633 memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
1634 ret = igb_parse_syn_filter(dev, attr, pattern,
1635 actions, &syn_filter, error);
1639 memset(&flex_filter, 0, sizeof(struct rte_eth_flex_filter));
1640 ret = igb_parse_flex_filter(dev, attr, pattern,
1641 actions, &flex_filter, error);
1645 memset(&rss_conf, 0, sizeof(struct igb_rte_flow_rss_conf));
1646 ret = igb_parse_rss_filter(dev, attr,
1647 actions, &rss_conf, error);
1652 /* Destroy a flow rule on igb. */
1654 igb_flow_destroy(struct rte_eth_dev *dev,
1655 struct rte_flow *flow,
1656 struct rte_flow_error *error)
1659 struct rte_flow *pmd_flow = flow;
1660 enum rte_filter_type filter_type = pmd_flow->filter_type;
1661 struct igb_ntuple_filter_ele *ntuple_filter_ptr;
1662 struct igb_ethertype_filter_ele *ethertype_filter_ptr;
1663 struct igb_eth_syn_filter_ele *syn_filter_ptr;
1664 struct igb_flex_filter_ele *flex_filter_ptr;
1665 struct igb_flow_mem *igb_flow_mem_ptr;
1666 struct igb_rss_conf_ele *rss_filter_ptr;
1668 switch (filter_type) {
1669 case RTE_ETH_FILTER_NTUPLE:
1670 ntuple_filter_ptr = (struct igb_ntuple_filter_ele *)
1672 ret = igb_add_del_ntuple_filter(dev,
1673 &ntuple_filter_ptr->filter_info, FALSE);
1675 TAILQ_REMOVE(&igb_filter_ntuple_list,
1676 ntuple_filter_ptr, entries);
1677 rte_free(ntuple_filter_ptr);
1680 case RTE_ETH_FILTER_ETHERTYPE:
1681 ethertype_filter_ptr = (struct igb_ethertype_filter_ele *)
1683 ret = igb_add_del_ethertype_filter(dev,
1684 ðertype_filter_ptr->filter_info, FALSE);
1686 TAILQ_REMOVE(&igb_filter_ethertype_list,
1687 ethertype_filter_ptr, entries);
1688 rte_free(ethertype_filter_ptr);
1691 case RTE_ETH_FILTER_SYN:
1692 syn_filter_ptr = (struct igb_eth_syn_filter_ele *)
1694 ret = eth_igb_syn_filter_set(dev,
1695 &syn_filter_ptr->filter_info, FALSE);
1697 TAILQ_REMOVE(&igb_filter_syn_list,
1698 syn_filter_ptr, entries);
1699 rte_free(syn_filter_ptr);
1702 case RTE_ETH_FILTER_FLEXIBLE:
1703 flex_filter_ptr = (struct igb_flex_filter_ele *)
1705 ret = eth_igb_add_del_flex_filter(dev,
1706 &flex_filter_ptr->filter_info, FALSE);
1708 TAILQ_REMOVE(&igb_filter_flex_list,
1709 flex_filter_ptr, entries);
1710 rte_free(flex_filter_ptr);
1713 case RTE_ETH_FILTER_HASH:
1714 rss_filter_ptr = (struct igb_rss_conf_ele *)
1716 ret = igb_config_rss_filter(dev,
1717 &rss_filter_ptr->filter_info, FALSE);
1719 TAILQ_REMOVE(&igb_filter_rss_list,
1720 rss_filter_ptr, entries);
1721 rte_free(rss_filter_ptr);
1725 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
1732 rte_flow_error_set(error, EINVAL,
1733 RTE_FLOW_ERROR_TYPE_HANDLE,
1734 NULL, "Failed to destroy flow");
1738 TAILQ_FOREACH(igb_flow_mem_ptr, &igb_flow_list, entries) {
1739 if (igb_flow_mem_ptr->flow == pmd_flow) {
1740 TAILQ_REMOVE(&igb_flow_list,
1741 igb_flow_mem_ptr, entries);
1742 rte_free(igb_flow_mem_ptr);
1750 /* remove all the n-tuple filters */
1752 igb_clear_all_ntuple_filter(struct rte_eth_dev *dev)
1754 struct e1000_filter_info *filter_info =
1755 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1756 struct e1000_5tuple_filter *p_5tuple;
1757 struct e1000_2tuple_filter *p_2tuple;
1759 while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list)))
1760 igb_delete_5tuple_filter_82576(dev, p_5tuple);
1762 while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list)))
1763 igb_delete_2tuple_filter(dev, p_2tuple);
1766 /* remove all the ether type filters */
1768 igb_clear_all_ethertype_filter(struct rte_eth_dev *dev)
1770 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1771 struct e1000_filter_info *filter_info =
1772 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1775 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
1776 if (filter_info->ethertype_mask & (1 << i)) {
1777 (void)igb_ethertype_filter_remove(filter_info,
1779 E1000_WRITE_REG(hw, E1000_ETQF(i), 0);
1780 E1000_WRITE_FLUSH(hw);
1785 /* remove the SYN filter */
1787 igb_clear_syn_filter(struct rte_eth_dev *dev)
1789 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1790 struct e1000_filter_info *filter_info =
1791 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1793 if (filter_info->syn_info & E1000_SYN_FILTER_ENABLE) {
1794 filter_info->syn_info = 0;
1795 E1000_WRITE_REG(hw, E1000_SYNQF(0), 0);
1796 E1000_WRITE_FLUSH(hw);
1800 /* remove all the flex filters */
1802 igb_clear_all_flex_filter(struct rte_eth_dev *dev)
1804 struct e1000_filter_info *filter_info =
1805 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1806 struct e1000_flex_filter *flex_filter;
1808 while ((flex_filter = TAILQ_FIRST(&filter_info->flex_list)))
1809 igb_remove_flex_filter(dev, flex_filter);
1812 /* remove the rss filter */
1814 igb_clear_rss_filter(struct rte_eth_dev *dev)
1816 struct e1000_filter_info *filter =
1817 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1819 if (filter->rss_info.conf.queue_num)
1820 igb_config_rss_filter(dev, &filter->rss_info, FALSE);
1824 igb_filterlist_flush(struct rte_eth_dev *dev)
1826 struct igb_ntuple_filter_ele *ntuple_filter_ptr;
1827 struct igb_ethertype_filter_ele *ethertype_filter_ptr;
1828 struct igb_eth_syn_filter_ele *syn_filter_ptr;
1829 struct igb_flex_filter_ele *flex_filter_ptr;
1830 struct igb_rss_conf_ele *rss_filter_ptr;
1831 struct igb_flow_mem *igb_flow_mem_ptr;
1832 enum rte_filter_type filter_type;
1833 struct rte_flow *pmd_flow;
1835 TAILQ_FOREACH(igb_flow_mem_ptr, &igb_flow_list, entries) {
1836 if (igb_flow_mem_ptr->dev == dev) {
1837 pmd_flow = igb_flow_mem_ptr->flow;
1838 filter_type = pmd_flow->filter_type;
1840 switch (filter_type) {
1841 case RTE_ETH_FILTER_NTUPLE:
1843 (struct igb_ntuple_filter_ele *)
1845 TAILQ_REMOVE(&igb_filter_ntuple_list,
1846 ntuple_filter_ptr, entries);
1847 rte_free(ntuple_filter_ptr);
1849 case RTE_ETH_FILTER_ETHERTYPE:
1850 ethertype_filter_ptr =
1851 (struct igb_ethertype_filter_ele *)
1853 TAILQ_REMOVE(&igb_filter_ethertype_list,
1854 ethertype_filter_ptr, entries);
1855 rte_free(ethertype_filter_ptr);
1857 case RTE_ETH_FILTER_SYN:
1859 (struct igb_eth_syn_filter_ele *)
1861 TAILQ_REMOVE(&igb_filter_syn_list,
1862 syn_filter_ptr, entries);
1863 rte_free(syn_filter_ptr);
1865 case RTE_ETH_FILTER_FLEXIBLE:
1867 (struct igb_flex_filter_ele *)
1869 TAILQ_REMOVE(&igb_filter_flex_list,
1870 flex_filter_ptr, entries);
1871 rte_free(flex_filter_ptr);
1873 case RTE_ETH_FILTER_HASH:
1875 (struct igb_rss_conf_ele *)
1877 TAILQ_REMOVE(&igb_filter_rss_list,
1878 rss_filter_ptr, entries);
1879 rte_free(rss_filter_ptr);
1882 PMD_DRV_LOG(WARNING, "Filter type"
1883 "(%d) not supported", filter_type);
1886 TAILQ_REMOVE(&igb_flow_list,
1889 rte_free(igb_flow_mem_ptr->flow);
1890 rte_free(igb_flow_mem_ptr);
1895 /* Destroy all flow rules associated with a port on igb. */
1897 igb_flow_flush(struct rte_eth_dev *dev,
1898 __rte_unused struct rte_flow_error *error)
1900 igb_clear_all_ntuple_filter(dev);
1901 igb_clear_all_ethertype_filter(dev);
1902 igb_clear_syn_filter(dev);
1903 igb_clear_all_flex_filter(dev);
1904 igb_clear_rss_filter(dev);
1905 igb_filterlist_flush(dev);
1910 const struct rte_flow_ops igb_flow_ops = {
1911 .validate = igb_flow_validate,
1912 .create = igb_flow_create,
1913 .destroy = igb_flow_destroy,
1914 .flush = igb_flow_flush,