LCOV - code coverage report
Current view: top level - drivers/net/ixgbe - ixgbe_flow.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1204 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1071 0.0 %

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

Generated by: LCOV version 1.14