LCOV - code coverage report
Current view: top level - drivers/net/txgbe - txgbe_flow.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1346 0.0 %
Date: 2025-12-01 19:08:10 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1197 0.0 %

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

Generated by: LCOV version 1.14