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

Generated by: LCOV version 1.14