LCOV - code coverage report
Current view: top level - drivers/net/mlx5 - mlx5_flow.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 3357 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 230 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 2449 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2016 6WIND S.A.
       3                 :            :  * Copyright 2016 Mellanox Technologies, Ltd
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stdalign.h>
       7                 :            : #include <stdint.h>
       8                 :            : #include <string.h>
       9                 :            : #include <stdbool.h>
      10                 :            : #include <sys/queue.h>
      11                 :            : 
      12                 :            : #include <rte_common.h>
      13                 :            : #include <rte_ether.h>
      14                 :            : #include <ethdev_driver.h>
      15                 :            : #include <rte_eal_paging.h>
      16                 :            : #include <rte_flow.h>
      17                 :            : #include <rte_cycles.h>
      18                 :            : #include <rte_flow_driver.h>
      19                 :            : #include <rte_malloc.h>
      20                 :            : #include <rte_ip.h>
      21                 :            : 
      22                 :            : #include <mlx5_glue.h>
      23                 :            : #include <mlx5_devx_cmds.h>
      24                 :            : #include <mlx5_prm.h>
      25                 :            : #include <mlx5_malloc.h>
      26                 :            : 
      27                 :            : #include "mlx5_defs.h"
      28                 :            : #include "mlx5.h"
      29                 :            : #include "mlx5_flow.h"
      30                 :            : #include "mlx5_flow_os.h"
      31                 :            : #include "mlx5_rx.h"
      32                 :            : #include "mlx5_tx.h"
      33                 :            : #include "mlx5_common_os.h"
      34                 :            : #include "rte_pmd_mlx5.h"
      35                 :            : 
      36                 :            : /*
      37                 :            :  * Shared array for quick translation between port_id and vport mask/values
      38                 :            :  * used for HWS rules.
      39                 :            :  */
      40                 :            : struct flow_hw_port_info mlx5_flow_hw_port_infos[RTE_MAX_ETHPORTS];
      41                 :            : 
      42                 :            : struct tunnel_default_miss_ctx {
      43                 :            :         uint16_t *queue;
      44                 :            :         __extension__
      45                 :            :         union {
      46                 :            :                 struct rte_flow_action_rss action_rss;
      47                 :            :                 struct rte_flow_action_queue miss_queue;
      48                 :            :                 struct rte_flow_action_jump miss_jump;
      49                 :            :                 uint8_t raw[0];
      50                 :            :         };
      51                 :            : };
      52                 :            : 
      53                 :            : void
      54                 :          0 : mlx5_indirect_list_handles_release(struct rte_eth_dev *dev)
      55                 :            : {
      56                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      57                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
      58                 :            :         struct rte_flow_error error;
      59                 :            : #endif
      60                 :            : 
      61         [ #  # ]:          0 :         while (!LIST_EMPTY(&priv->indirect_list_head)) {
      62                 :            :                 struct mlx5_indirect_list *e =
      63                 :            :                         LIST_FIRST(&priv->indirect_list_head);
      64                 :            : 
      65         [ #  # ]:          0 :                 LIST_REMOVE(e, entry);
      66   [ #  #  #  # ]:          0 :                 switch (e->type) {
      67                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
      68                 :          0 :                 case MLX5_INDIRECT_ACTION_LIST_TYPE_MIRROR:
      69                 :          0 :                         mlx5_hw_mirror_destroy(dev, (struct mlx5_mirror *)e);
      70                 :          0 :                 break;
      71                 :          0 :                 case MLX5_INDIRECT_ACTION_LIST_TYPE_LEGACY:
      72                 :          0 :                         mlx5_destroy_legacy_indirect(dev, e);
      73                 :          0 :                         break;
      74                 :          0 :                 case MLX5_INDIRECT_ACTION_LIST_TYPE_REFORMAT:
      75                 :          0 :                         mlx5_reformat_action_destroy(dev,
      76                 :            :                                 (struct rte_flow_action_list_handle *)e, &error);
      77                 :          0 :                         break;
      78                 :            : #endif
      79                 :          0 :                 default:
      80                 :          0 :                         DRV_LOG(ERR, "invalid indirect list type");
      81                 :            :                         MLX5_ASSERT(false);
      82                 :          0 :                         break;
      83                 :            :                 }
      84                 :            :         }
      85                 :          0 : }
      86                 :            : 
      87                 :            : static int
      88                 :            : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
      89                 :            :                              struct rte_flow *flow,
      90                 :            :                              const struct rte_flow_attr *attr,
      91                 :            :                              const struct rte_flow_action *app_actions,
      92                 :            :                              uint32_t flow_idx,
      93                 :            :                              const struct mlx5_flow_tunnel *tunnel,
      94                 :            :                              struct tunnel_default_miss_ctx *ctx,
      95                 :            :                              struct rte_flow_error *error);
      96                 :            : static struct mlx5_flow_tunnel *
      97                 :            : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
      98                 :            : static void
      99                 :            : mlx5_flow_tunnel_free(struct rte_eth_dev *dev, struct mlx5_flow_tunnel *tunnel);
     100                 :            : static uint32_t
     101                 :            : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
     102                 :            :                                 const struct mlx5_flow_tunnel *tunnel,
     103                 :            :                                 uint32_t group, uint32_t *table,
     104                 :            :                                 struct rte_flow_error *error);
     105                 :            : 
     106                 :            : /** Device flow drivers. */
     107                 :            : extern const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops;
     108                 :            : 
     109                 :            : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops;
     110                 :            : 
     111                 :            : const struct mlx5_flow_driver_ops *flow_drv_ops[] = {
     112                 :            :         [MLX5_FLOW_TYPE_MIN] = &mlx5_flow_null_drv_ops,
     113                 :            : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
     114                 :            :         [MLX5_FLOW_TYPE_DV] = &mlx5_flow_dv_drv_ops,
     115                 :            : #endif
     116                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
     117                 :            :         [MLX5_FLOW_TYPE_HW] = &mlx5_flow_hw_drv_ops,
     118                 :            : #endif
     119                 :            :         [MLX5_FLOW_TYPE_VERBS] = &mlx5_flow_verbs_drv_ops,
     120                 :            :         [MLX5_FLOW_TYPE_MAX] = &mlx5_flow_null_drv_ops
     121                 :            : };
     122                 :            : 
     123                 :            : /** Helper macro to build input graph for mlx5_flow_expand_rss(). */
     124                 :            : #define MLX5_FLOW_EXPAND_RSS_NEXT(...) \
     125                 :            :         (const int []){ \
     126                 :            :                 __VA_ARGS__, 0, \
     127                 :            :         }
     128                 :            : 
     129                 :            : /** Node object of input graph for mlx5_flow_expand_rss(). */
     130                 :            : struct mlx5_flow_expand_node {
     131                 :            :         const int *const next;
     132                 :            :         /**<
     133                 :            :          * List of next node indexes. Index 0 is interpreted as a terminator.
     134                 :            :          */
     135                 :            :         const enum rte_flow_item_type type;
     136                 :            :         /**< Pattern item type of current node. */
     137                 :            :         uint64_t rss_types;
     138                 :            :         /**<
     139                 :            :          * RSS types bit-field associated with this node
     140                 :            :          * (see RTE_ETH_RSS_* definitions).
     141                 :            :          */
     142                 :            :         uint64_t node_flags;
     143                 :            :         /**<
     144                 :            :          *  Bit-fields that define how the node is used in the expansion.
     145                 :            :          * (see MLX5_EXPANSION_NODE_* definitions).
     146                 :            :          */
     147                 :            : };
     148                 :            : 
     149                 :            : /** Keep same format with mlx5_flow_expand_rss to share the buffer for expansion. */
     150                 :            : struct mlx5_flow_expand_sqn {
     151                 :            :         uint32_t entries; /** Number of entries */
     152                 :            :         struct {
     153                 :            :                 struct rte_flow_item *pattern; /**< Expanded pattern array. */
     154                 :            :                 uint32_t priority; /**< Priority offset for each expansion. */
     155                 :            :         } entry[];
     156                 :            : };
     157                 :            : 
     158                 :            : /* Optional expand field. The expansion alg will not go deeper. */
     159                 :            : #define MLX5_EXPANSION_NODE_OPTIONAL (UINT64_C(1) << 0)
     160                 :            : 
     161                 :            : /* The node is not added implicitly as expansion to the flow pattern.
     162                 :            :  * If the node type does not match the flow pattern item type, the
     163                 :            :  * expansion alg will go deeper to its next items.
     164                 :            :  * In the current implementation, the list of next nodes indexes can
     165                 :            :  * have up to one node with this flag set and it has to be the last
     166                 :            :  * node index (before the list terminator).
     167                 :            :  */
     168                 :            : #define MLX5_EXPANSION_NODE_EXPLICIT (UINT64_C(1) << 1)
     169                 :            : 
     170                 :            : /** Object returned by mlx5_flow_expand_rss(). */
     171                 :            : struct mlx5_flow_expand_rss {
     172                 :            :         uint32_t entries;
     173                 :            :         /**< Number of entries @p patterns and @p priorities. */
     174                 :            :         struct {
     175                 :            :                 struct rte_flow_item *pattern; /**< Expanded pattern array. */
     176                 :            :                 uint32_t priority; /**< Priority offset for each expansion. */
     177                 :            :         } entry[];
     178                 :            : };
     179                 :            : 
     180                 :            : static void
     181                 :            : mlx5_dbg__print_pattern(const struct rte_flow_item *item);
     182                 :            : 
     183                 :            : static const struct mlx5_flow_expand_node *
     184                 :            : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
     185                 :            :                 unsigned int item_idx,
     186                 :            :                 const struct mlx5_flow_expand_node graph[],
     187                 :            :                 const struct mlx5_flow_expand_node *node);
     188                 :            : 
     189                 :            : static __rte_always_inline int
     190                 :            : mlx5_need_cache_flow(const struct mlx5_priv *priv,
     191                 :            :                      const struct rte_flow_attr *attr)
     192                 :            : {
     193   [ #  #  #  #  :          0 :         return priv->isolated && priv->sh->config.dv_flow_en == 1 &&
             #  #  #  # ]
     194   [ #  #  #  # ]:          0 :                 (attr ? !attr->group : true) &&
     195   [ #  #  #  #  :          0 :                 priv->mode_info.mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY &&
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     196   [ #  #  #  #  :          0 :                 (!priv->sh->config.dv_esw_en || !priv->sh->config.fdb_def_rule);
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     197                 :            : }
     198                 :            : 
     199                 :            : static bool
     200                 :          0 : mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
     201                 :            : {
     202         [ #  # ]:          0 :         switch (item->type) {
     203                 :            :         case RTE_FLOW_ITEM_TYPE_ETH:
     204                 :            :         case RTE_FLOW_ITEM_TYPE_VLAN:
     205                 :            :         case RTE_FLOW_ITEM_TYPE_IPV4:
     206                 :            :         case RTE_FLOW_ITEM_TYPE_IPV6:
     207                 :            :         case RTE_FLOW_ITEM_TYPE_UDP:
     208                 :            :         case RTE_FLOW_ITEM_TYPE_TCP:
     209                 :            :         case RTE_FLOW_ITEM_TYPE_ESP:
     210                 :            :         case RTE_FLOW_ITEM_TYPE_ICMP:
     211                 :            :         case RTE_FLOW_ITEM_TYPE_ICMP6:
     212                 :            :         case RTE_FLOW_ITEM_TYPE_VXLAN:
     213                 :            :         case RTE_FLOW_ITEM_TYPE_NVGRE:
     214                 :            :         case RTE_FLOW_ITEM_TYPE_GRE:
     215                 :            :         case RTE_FLOW_ITEM_TYPE_GENEVE:
     216                 :            :         case RTE_FLOW_ITEM_TYPE_MPLS:
     217                 :            :         case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
     218                 :            :         case RTE_FLOW_ITEM_TYPE_GRE_KEY:
     219                 :            :         case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
     220                 :            :         case RTE_FLOW_ITEM_TYPE_GTP:
     221                 :            :                 return true;
     222                 :            :         default:
     223                 :            :                 break;
     224                 :            :         }
     225                 :          0 :         return false;
     226                 :            : }
     227                 :            : 
     228                 :            : /**
     229                 :            :  * Network Service Header (NSH) and its next protocol values
     230                 :            :  * are described in RFC-8393.
     231                 :            :  */
     232                 :            : static enum rte_flow_item_type
     233                 :            : mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
     234                 :            : {
     235                 :            :         enum rte_flow_item_type type;
     236                 :            : 
     237                 :          0 :         switch (proto_mask & proto_spec) {
     238                 :            :         case 0:
     239                 :            :                 type = RTE_FLOW_ITEM_TYPE_VOID;
     240                 :            :                 break;
     241                 :            :         case RTE_VXLAN_GPE_TYPE_IPV4:
     242                 :            :                 type = RTE_FLOW_ITEM_TYPE_IPV4;
     243                 :            :                 break;
     244                 :            :         case RTE_VXLAN_GPE_TYPE_IPV6:
     245                 :            :                 type = RTE_VXLAN_GPE_TYPE_IPV6;
     246                 :            :                 break;
     247                 :            :         case RTE_VXLAN_GPE_TYPE_ETH:
     248                 :            :                 type = RTE_FLOW_ITEM_TYPE_ETH;
     249                 :            :                 break;
     250                 :            :         default:
     251                 :            :                 type = RTE_FLOW_ITEM_TYPE_END;
     252                 :            :         }
     253                 :            :         return type;
     254                 :            : }
     255                 :            : 
     256                 :            : static enum rte_flow_item_type
     257                 :            : mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
     258                 :            : {
     259                 :            :         enum rte_flow_item_type type;
     260                 :            : 
     261   [ #  #  #  #  :          0 :         switch (proto_mask & proto_spec) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     262                 :            :         case 0:
     263                 :            :                 type = RTE_FLOW_ITEM_TYPE_VOID;
     264                 :            :                 break;
     265                 :          0 :         case IPPROTO_UDP:
     266                 :            :                 type = RTE_FLOW_ITEM_TYPE_UDP;
     267                 :          0 :                 break;
     268                 :          0 :         case IPPROTO_TCP:
     269                 :            :                 type = RTE_FLOW_ITEM_TYPE_TCP;
     270                 :          0 :                 break;
     271                 :          0 :         case IPPROTO_IPIP:
     272                 :            :                 type = RTE_FLOW_ITEM_TYPE_IPV4;
     273                 :          0 :                 break;
     274                 :          0 :         case IPPROTO_IPV6:
     275                 :            :                 type = RTE_FLOW_ITEM_TYPE_IPV6;
     276                 :          0 :                 break;
     277                 :          0 :         case IPPROTO_ESP:
     278                 :            :                 type = RTE_FLOW_ITEM_TYPE_ESP;
     279                 :          0 :                 break;
     280                 :          0 :         default:
     281                 :            :                 type = RTE_FLOW_ITEM_TYPE_END;
     282                 :            :         }
     283                 :            :         return type;
     284                 :            : }
     285                 :            : 
     286                 :            : static enum rte_flow_item_type
     287                 :            : mlx5_ethertype_to_item_type(rte_be16_t type_spec,
     288                 :            :                             rte_be16_t type_mask, bool is_tunnel)
     289                 :            : {
     290                 :            :         enum rte_flow_item_type type;
     291                 :            : 
     292   [ #  #  #  #  :          0 :         switch (rte_be_to_cpu_16(type_spec & type_mask)) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     293                 :            :         case 0:
     294                 :            :                 type = RTE_FLOW_ITEM_TYPE_VOID;
     295                 :            :                 break;
     296                 :          0 :         case RTE_ETHER_TYPE_TEB:
     297                 :            :                 type = is_tunnel ?
     298                 :            :                        RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
     299                 :            :                 break;
     300                 :          0 :         case RTE_ETHER_TYPE_VLAN:
     301                 :            :                 type = !is_tunnel ?
     302                 :            :                        RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
     303                 :            :                 break;
     304                 :          0 :         case RTE_ETHER_TYPE_IPV4:
     305                 :            :                 type = RTE_FLOW_ITEM_TYPE_IPV4;
     306                 :          0 :                 break;
     307                 :          0 :         case RTE_ETHER_TYPE_IPV6:
     308                 :            :                 type = RTE_FLOW_ITEM_TYPE_IPV6;
     309                 :          0 :                 break;
     310                 :          0 :         default:
     311                 :            :                 type = RTE_FLOW_ITEM_TYPE_END;
     312                 :            :         }
     313                 :            :         return type;
     314                 :            : }
     315                 :            : 
     316                 :            : static enum rte_flow_item_type
     317                 :          0 : mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
     318                 :            : {
     319                 :            : #define MLX5_XSET_ITEM_MASK_SPEC(type, fld)                              \
     320                 :            :         do {                                                             \
     321                 :            :                 const void *m = item->mask;                              \
     322                 :            :                 const void *s = item->spec;                              \
     323                 :            :                 mask = m ?                                               \
     324                 :            :                         ((const struct rte_flow_item_##type *)m)->fld :  \
     325                 :            :                         rte_flow_item_##type##_mask.fld;                 \
     326                 :            :                 spec = ((const struct rte_flow_item_##type *)s)->fld;    \
     327                 :            :         } while (0)
     328                 :            : 
     329                 :            :         enum rte_flow_item_type ret;
     330                 :            :         uint16_t spec, mask;
     331                 :            : 
     332   [ #  #  #  # ]:          0 :         if (item == NULL || item->spec == NULL)
     333                 :            :                 return RTE_FLOW_ITEM_TYPE_VOID;
     334   [ #  #  #  #  :          0 :         switch (item->type) {
             #  #  #  # ]
     335                 :          0 :         case RTE_FLOW_ITEM_TYPE_ETH:
     336         [ #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(eth, hdr.ether_type);
     337         [ #  # ]:          0 :                 if (!mask)
     338                 :            :                         return RTE_FLOW_ITEM_TYPE_VOID;
     339                 :            :                 ret = mlx5_ethertype_to_item_type(spec, mask, false);
     340                 :            :                 break;
     341                 :          0 :         case RTE_FLOW_ITEM_TYPE_VLAN:
     342         [ #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(vlan, hdr.eth_proto);
     343         [ #  # ]:          0 :                 if (!mask)
     344                 :            :                         return RTE_FLOW_ITEM_TYPE_VOID;
     345                 :            :                 ret = mlx5_ethertype_to_item_type(spec, mask, false);
     346                 :            :                 break;
     347                 :          0 :         case RTE_FLOW_ITEM_TYPE_IPV4:
     348         [ #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
     349         [ #  # ]:          0 :                 if (!mask)
     350                 :            :                         return RTE_FLOW_ITEM_TYPE_VOID;
     351                 :            :                 ret = mlx5_inet_proto_to_item_type(spec, mask);
     352                 :            :                 break;
     353                 :          0 :         case RTE_FLOW_ITEM_TYPE_IPV6:
     354         [ #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
     355         [ #  # ]:          0 :                 if (!mask)
     356                 :            :                         return RTE_FLOW_ITEM_TYPE_VOID;
     357                 :            :                 ret = mlx5_inet_proto_to_item_type(spec, mask);
     358                 :            :                 break;
     359                 :          0 :         case RTE_FLOW_ITEM_TYPE_GENEVE:
     360   [ #  #  #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
     361                 :            :                 ret = mlx5_ethertype_to_item_type(spec, mask, true);
     362                 :            :                 break;
     363                 :          0 :         case RTE_FLOW_ITEM_TYPE_GRE:
     364   [ #  #  #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
     365                 :            :                 ret = mlx5_ethertype_to_item_type(spec, mask, true);
     366                 :            :                 break;
     367                 :          0 :         case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
     368         [ #  # ]:          0 :                 MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, hdr.proto);
     369         [ #  # ]:          0 :                 ret = mlx5_nsh_proto_to_item_type(spec, mask);
     370                 :            :                 break;
     371                 :            :         default:
     372                 :            :                 ret = RTE_FLOW_ITEM_TYPE_VOID;
     373                 :            :                 break;
     374                 :            :         }
     375                 :            :         return ret;
     376                 :            : #undef MLX5_XSET_ITEM_MASK_SPEC
     377                 :            : }
     378                 :            : 
     379                 :            : static const int *
     380                 :            : mlx5_flow_expand_rss_skip_explicit(const struct mlx5_flow_expand_node graph[],
     381                 :            :                 const int *next_node)
     382                 :            : {
     383                 :            :         const struct mlx5_flow_expand_node *node = NULL;
     384                 :            :         const int *next = next_node;
     385                 :            : 
     386   [ #  #  #  #  :          0 :         while (next && *next) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     387                 :            :                 /*
     388                 :            :                  * Skip the nodes with the MLX5_EXPANSION_NODE_EXPLICIT
     389                 :            :                  * flag set, because they were not found in the flow pattern.
     390                 :            :                  */
     391                 :          0 :                 node = &graph[*next];
     392   [ #  #  #  #  :          0 :                 if (!(node->node_flags & MLX5_EXPANSION_NODE_EXPLICIT))
             #  #  #  # ]
     393                 :            :                         break;
     394                 :          0 :                 next = node->next;
     395                 :            :         }
     396                 :            :         return next;
     397                 :            : }
     398                 :            : 
     399                 :            : #define MLX5_RSS_EXP_ELT_N 32
     400                 :            : 
     401                 :            : /**
     402                 :            :  * Expand RSS flows into several possible flows according to the RSS hash
     403                 :            :  * fields requested and the driver capabilities.
     404                 :            :  *
     405                 :            :  * @param[out] buf
     406                 :            :  *   Buffer to store the result expansion.
     407                 :            :  * @param[in] size
     408                 :            :  *   Buffer size in bytes. If 0, @p buf can be NULL.
     409                 :            :  * @param[in] pattern
     410                 :            :  *   User flow pattern.
     411                 :            :  * @param[in] types
     412                 :            :  *   RSS types to expand (see RTE_ETH_RSS_* definitions).
     413                 :            :  * @param[in] graph
     414                 :            :  *   Input graph to expand @p pattern according to @p types.
     415                 :            :  * @param[in] graph_root_index
     416                 :            :  *   Index of root node in @p graph, typically 0.
     417                 :            :  *
     418                 :            :  * @return
     419                 :            :  *   A positive value representing the size of @p buf in bytes regardless of
     420                 :            :  *   @p size on success, a negative errno value otherwise and rte_errno is
     421                 :            :  *   set, the following errors are defined:
     422                 :            :  *
     423                 :            :  *   -E2BIG: graph-depth @p graph is too deep.
     424                 :            :  *   -EINVAL: @p size has not enough space for expanded pattern.
     425                 :            :  */
     426                 :            : static int
     427                 :          0 : mlx5_flow_expand_rss(struct mlx5_flow_expand_rss *buf, size_t size,
     428                 :            :                      const struct rte_flow_item *pattern, uint64_t types,
     429                 :            :                      const struct mlx5_flow_expand_node graph[],
     430                 :            :                      int graph_root_index)
     431                 :            : {
     432                 :            :         const struct rte_flow_item *item;
     433         [ #  # ]:          0 :         const struct mlx5_flow_expand_node *node = &graph[graph_root_index];
     434                 :            :         const int *next_node;
     435                 :            :         const int *stack[MLX5_RSS_EXP_ELT_N];
     436                 :            :         int stack_pos = 0;
     437                 :            :         struct rte_flow_item flow_items[MLX5_RSS_EXP_ELT_N];
     438                 :            :         unsigned int i, item_idx, last_expand_item_idx = 0;
     439                 :            :         size_t lsize;
     440                 :            :         size_t user_pattern_size = 0;
     441                 :            :         void *addr = NULL;
     442                 :            :         const struct mlx5_flow_expand_node *next = NULL;
     443                 :            :         struct rte_flow_item missed_item;
     444                 :            :         int missed = 0;
     445                 :            :         int elt = 0;
     446                 :            :         const struct rte_flow_item *last_expand_item = NULL;
     447                 :            : 
     448                 :            :         memset(&missed_item, 0, sizeof(missed_item));
     449                 :            :         lsize = offsetof(struct mlx5_flow_expand_rss, entry) +
     450                 :            :                 MLX5_RSS_EXP_ELT_N * sizeof(buf->entry[0]);
     451         [ #  # ]:          0 :         if (lsize > size)
     452                 :            :                 return -EINVAL;
     453                 :          0 :         buf->entry[0].priority = 0;
     454                 :          0 :         buf->entry[0].pattern = (void *)&buf->entry[MLX5_RSS_EXP_ELT_N];
     455                 :          0 :         buf->entries = 0;
     456                 :            :         addr = buf->entry[0].pattern;
     457                 :          0 :         for (item = pattern, item_idx = 0;
     458         [ #  # ]:          0 :                         item->type != RTE_FLOW_ITEM_TYPE_END;
     459                 :          0 :                         item++, item_idx++) {
     460         [ #  # ]:          0 :                 if (!mlx5_flow_is_rss_expandable_item(item)) {
     461                 :          0 :                         user_pattern_size += sizeof(*item);
     462                 :          0 :                         continue;
     463                 :            :                 }
     464                 :            :                 last_expand_item = item;
     465                 :            :                 last_expand_item_idx = item_idx;
     466                 :            :                 i = 0;
     467   [ #  #  #  # ]:          0 :                 while (node->next && node->next[i]) {
     468                 :          0 :                         next = &graph[node->next[i]];
     469         [ #  # ]:          0 :                         if (next->type == item->type)
     470                 :            :                                 break;
     471         [ #  # ]:          0 :                         if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
     472                 :            :                                 node = next;
     473                 :            :                                 i = 0;
     474                 :            :                         } else {
     475                 :          0 :                                 ++i;
     476                 :            :                         }
     477                 :            :                 }
     478         [ #  # ]:          0 :                 if (next)
     479                 :            :                         node = next;
     480                 :          0 :                 user_pattern_size += sizeof(*item);
     481                 :            :         }
     482                 :          0 :         user_pattern_size += sizeof(*item); /* Handle END item. */
     483                 :          0 :         lsize += user_pattern_size;
     484         [ #  # ]:          0 :         if (lsize > size)
     485                 :            :                 return -EINVAL;
     486                 :            :         /* Copy the user pattern in the first entry of the buffer. */
     487                 :            :         rte_memcpy(addr, pattern, user_pattern_size);
     488                 :          0 :         addr = (void *)(((uintptr_t)addr) + user_pattern_size);
     489                 :          0 :         buf->entries = 1;
     490                 :            :         /* Start expanding. */
     491                 :            :         memset(flow_items, 0, sizeof(flow_items));
     492                 :            :         user_pattern_size -= sizeof(*item);
     493                 :            :         /*
     494                 :            :          * Check if the last valid item has spec set, need complete pattern,
     495                 :            :          * and the pattern can be used for expansion.
     496                 :            :          */
     497                 :          0 :         missed_item.type = mlx5_flow_expand_rss_item_complete(last_expand_item);
     498         [ #  # ]:          0 :         if (missed_item.type == RTE_FLOW_ITEM_TYPE_END) {
     499                 :            :                 /* Item type END indicates expansion is not required. */
     500                 :          0 :                 return lsize;
     501                 :            :         }
     502         [ #  # ]:          0 :         if (missed_item.type != RTE_FLOW_ITEM_TYPE_VOID) {
     503                 :            :                 next = NULL;
     504                 :            :                 missed = 1;
     505                 :            :                 i = 0;
     506   [ #  #  #  # ]:          0 :                 while (node->next && node->next[i]) {
     507                 :          0 :                         next = &graph[node->next[i]];
     508         [ #  # ]:          0 :                         if (next->type == missed_item.type) {
     509                 :          0 :                                 flow_items[0].type = missed_item.type;
     510                 :            :                                 flow_items[1].type = RTE_FLOW_ITEM_TYPE_END;
     511                 :          0 :                                 break;
     512                 :            :                         }
     513         [ #  # ]:          0 :                         if (next->node_flags & MLX5_EXPANSION_NODE_EXPLICIT) {
     514                 :            :                                 node = next;
     515                 :            :                                 i = 0;
     516                 :            :                         } else {
     517                 :          0 :                                 ++i;
     518                 :            :                         }
     519                 :            :                         next = NULL;
     520                 :            :                 }
     521                 :            :         }
     522         [ #  # ]:          0 :         if (next && missed) {
     523                 :            :                 elt = 2; /* missed item + item end. */
     524                 :            :                 node = next;
     525                 :          0 :                 lsize += elt * sizeof(*item) + user_pattern_size;
     526         [ #  # ]:          0 :                 if (lsize > size)
     527                 :            :                         return -EINVAL;
     528         [ #  # ]:          0 :                 if (node->rss_types & types) {
     529                 :          0 :                         buf->entry[buf->entries].priority = 1;
     530                 :          0 :                         buf->entry[buf->entries].pattern = addr;
     531                 :          0 :                         buf->entries++;
     532         [ #  # ]:          0 :                         rte_memcpy(addr, buf->entry[0].pattern,
     533                 :            :                                    user_pattern_size);
     534         [ #  # ]:          0 :                         addr = (void *)(((uintptr_t)addr) + user_pattern_size);
     535                 :            :                         rte_memcpy(addr, flow_items, elt * sizeof(*item));
     536                 :          0 :                         addr = (void *)(((uintptr_t)addr) +
     537                 :            :                                         elt * sizeof(*item));
     538                 :            :                 }
     539         [ #  # ]:          0 :         } else if (last_expand_item != NULL) {
     540                 :          0 :                 node = mlx5_flow_expand_rss_adjust_node(pattern,
     541                 :            :                                 last_expand_item_idx, graph, node);
     542                 :            :         }
     543                 :            :         memset(flow_items, 0, sizeof(flow_items));
     544                 :            :         next_node = mlx5_flow_expand_rss_skip_explicit(graph,
     545                 :          0 :                         node->next);
     546                 :          0 :         stack[stack_pos] = next_node;
     547         [ #  # ]:          0 :         node = next_node ? &graph[*next_node] : NULL;
     548         [ #  # ]:          0 :         while (node) {
     549                 :          0 :                 flow_items[stack_pos].type = node->type;
     550         [ #  # ]:          0 :                 if (node->rss_types & types) {
     551                 :            :                         size_t n;
     552                 :            :                         /*
     553                 :            :                          * compute the number of items to copy from the
     554                 :            :                          * expansion and copy it.
     555                 :            :                          * When the stack_pos is 0, there are 1 element in it,
     556                 :            :                          * plus the addition END item.
     557                 :            :                          */
     558                 :          0 :                         elt = stack_pos + 2;
     559                 :          0 :                         flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END;
     560                 :          0 :                         lsize += elt * sizeof(*item) + user_pattern_size;
     561         [ #  # ]:          0 :                         if (lsize > size)
     562                 :            :                                 return -EINVAL;
     563                 :            :                         n = elt * sizeof(*item);
     564                 :            :                         MLX5_ASSERT((buf->entries) < MLX5_RSS_EXP_ELT_N);
     565                 :          0 :                         buf->entry[buf->entries].priority =
     566                 :          0 :                                 stack_pos + 1 + missed;
     567                 :          0 :                         buf->entry[buf->entries].pattern = addr;
     568                 :          0 :                         buf->entries++;
     569         [ #  # ]:          0 :                         rte_memcpy(addr, buf->entry[0].pattern,
     570                 :            :                                    user_pattern_size);
     571                 :          0 :                         addr = (void *)(((uintptr_t)addr) +
     572                 :            :                                         user_pattern_size);
     573         [ #  # ]:          0 :                         rte_memcpy(addr, &missed_item,
     574                 :            :                                    missed * sizeof(*item));
     575         [ #  # ]:          0 :                         addr = (void *)(((uintptr_t)addr) +
     576                 :            :                                 missed * sizeof(*item));
     577                 :            :                         rte_memcpy(addr, flow_items, n);
     578                 :          0 :                         addr = (void *)(((uintptr_t)addr) + n);
     579                 :            :                 }
     580                 :            :                 /* Go deeper. */
     581         [ #  # ]:          0 :                 if (!(node->node_flags & MLX5_EXPANSION_NODE_OPTIONAL) &&
     582         [ #  # ]:          0 :                                 node->next) {
     583                 :            :                         next_node = mlx5_flow_expand_rss_skip_explicit(graph,
     584                 :            :                                         node->next);
     585         [ #  # ]:          0 :                         if (stack_pos++ == MLX5_RSS_EXP_ELT_N) {
     586                 :          0 :                                 rte_errno = E2BIG;
     587                 :          0 :                                 return -rte_errno;
     588                 :            :                         }
     589                 :          0 :                         stack[stack_pos] = next_node;
     590         [ #  # ]:          0 :                 } else if (*(next_node + 1)) {
     591                 :            :                         /* Follow up with the next possibility. */
     592                 :          0 :                         next_node = mlx5_flow_expand_rss_skip_explicit(graph,
     593                 :            :                                         ++next_node);
     594         [ #  # ]:          0 :                 } else if (!stack_pos) {
     595                 :            :                         /*
     596                 :            :                          * Completing the traverse over the different paths.
     597                 :            :                          * The next_node is advanced to the terminator.
     598                 :            :                          */
     599                 :          0 :                         ++next_node;
     600                 :            :                 } else {
     601                 :            :                         /* Move to the next path. */
     602         [ #  # ]:          0 :                         while (stack_pos) {
     603                 :          0 :                                 next_node = stack[--stack_pos];
     604                 :          0 :                                 next_node++;
     605         [ #  # ]:          0 :                                 if (*next_node)
     606                 :            :                                         break;
     607                 :            :                         }
     608                 :            :                         next_node = mlx5_flow_expand_rss_skip_explicit(graph,
     609                 :            :                                         next_node);
     610                 :          0 :                         stack[stack_pos] = next_node;
     611                 :            :                 }
     612   [ #  #  #  # ]:          0 :                 node = next_node && *next_node ? &graph[*next_node] : NULL;
     613                 :            :         };
     614                 :          0 :         return lsize;
     615                 :            : }
     616                 :            : 
     617                 :            : /**
     618                 :            :  * Expand SQN flows into several possible flows according to the Tx queue
     619                 :            :  * number
     620                 :            :  *
     621                 :            :  * @param[in] buf
     622                 :            :  *   Buffer to store the result expansion.
     623                 :            :  * @param[in] size
     624                 :            :  *   Buffer size in bytes. If 0, @p buf can be NULL.
     625                 :            :  * @param[in] pattern
     626                 :            :  *   User flow pattern.
     627                 :            :  * @param[in] sq_specs
     628                 :            :  *   Buffer to store sq spec.
     629                 :            :  *
     630                 :            :  * @return
     631                 :            :  *   0 for success and negative value for failure
     632                 :            :  *
     633                 :            :  */
     634                 :            : static int
     635                 :          0 : mlx5_flow_expand_sqn(struct mlx5_flow_expand_sqn *buf, size_t size,
     636                 :            :                      const struct rte_flow_item *pattern,
     637                 :            :                      struct mlx5_rte_flow_item_sq *sq_specs)
     638                 :            : {
     639                 :            :         const struct rte_flow_item *item;
     640                 :            :         bool port_representor = false;
     641                 :            :         size_t user_pattern_size = 0;
     642                 :            :         struct rte_eth_dev *dev;
     643                 :            :         struct mlx5_priv *priv;
     644                 :            :         void *addr = NULL;
     645                 :            :         uint16_t port_id;
     646                 :            :         size_t lsize;
     647                 :            :         int elt = 2;
     648                 :            :         uint16_t i;
     649                 :            : 
     650                 :          0 :         buf->entries = 0;
     651         [ #  # ]:          0 :         for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
     652         [ #  # ]:          0 :                 if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
     653                 :          0 :                         const struct rte_flow_item_ethdev *pid_v = item->spec;
     654                 :            : 
     655         [ #  # ]:          0 :                         if (!pid_v)
     656                 :            :                                 return 0;
     657                 :          0 :                         port_id = pid_v->port_id;
     658                 :            :                         port_representor = true;
     659                 :            :                 }
     660                 :          0 :                 user_pattern_size += sizeof(*item);
     661                 :            :         }
     662         [ #  # ]:          0 :         if (!port_representor)
     663                 :            :                 return 0;
     664                 :          0 :         dev = &rte_eth_devices[port_id];
     665                 :          0 :         priv = dev->data->dev_private;
     666                 :          0 :         buf->entry[0].pattern = (void *)&buf->entry[priv->txqs_n];
     667                 :          0 :         lsize = offsetof(struct mlx5_flow_expand_sqn, entry) +
     668                 :          0 :                 sizeof(buf->entry[0]) * priv->txqs_n;
     669         [ #  # ]:          0 :         if (lsize + (user_pattern_size + sizeof(struct rte_flow_item) * elt) * priv->txqs_n > size)
     670                 :            :                 return -EINVAL;
     671                 :            :         addr = buf->entry[0].pattern;
     672         [ #  # ]:          0 :         for (i = 0; i != priv->txqs_n; ++i) {
     673                 :          0 :                 struct rte_flow_item pattern_add[] = {
     674                 :            :                         {
     675                 :            :                                 .type = (enum rte_flow_item_type)
     676                 :            :                                         MLX5_RTE_FLOW_ITEM_TYPE_SQ,
     677                 :          0 :                                 .spec = &sq_specs[i],
     678                 :            :                         },
     679                 :            :                         {
     680                 :            :                                 .type = RTE_FLOW_ITEM_TYPE_END,
     681                 :            :                         },
     682                 :            :                 };
     683                 :          0 :                 struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
     684                 :            : 
     685         [ #  # ]:          0 :                 if (txq == NULL)
     686                 :          0 :                         return -EINVAL;
     687                 :          0 :                 buf->entry[i].pattern = addr;
     688                 :          0 :                 sq_specs[i].queue = mlx5_txq_get_sqn(txq);
     689                 :          0 :                 mlx5_txq_release(dev, i);
     690                 :            :                 rte_memcpy(addr, pattern, user_pattern_size);
     691         [ #  # ]:          0 :                 addr = (void *)(((uintptr_t)addr) + user_pattern_size);
     692                 :            :                 rte_memcpy(addr, pattern_add, sizeof(struct rte_flow_item) * elt);
     693                 :          0 :                 addr = (void *)(((uintptr_t)addr) + sizeof(struct rte_flow_item) * elt);
     694                 :          0 :                 buf->entries++;
     695                 :            :         }
     696                 :            :         return 0;
     697                 :            : }
     698                 :            : 
     699                 :            : enum mlx5_expansion {
     700                 :            :         MLX5_EXPANSION_ROOT,
     701                 :            :         MLX5_EXPANSION_ROOT_OUTER,
     702                 :            :         MLX5_EXPANSION_OUTER_ETH,
     703                 :            :         MLX5_EXPANSION_OUTER_VLAN,
     704                 :            :         MLX5_EXPANSION_OUTER_IPV4,
     705                 :            :         MLX5_EXPANSION_OUTER_IPV4_UDP,
     706                 :            :         MLX5_EXPANSION_OUTER_IPV4_TCP,
     707                 :            :         MLX5_EXPANSION_OUTER_IPV4_ESP,
     708                 :            :         MLX5_EXPANSION_OUTER_IPV4_ICMP,
     709                 :            :         MLX5_EXPANSION_OUTER_IPV6,
     710                 :            :         MLX5_EXPANSION_OUTER_IPV6_UDP,
     711                 :            :         MLX5_EXPANSION_OUTER_IPV6_TCP,
     712                 :            :         MLX5_EXPANSION_OUTER_IPV6_ESP,
     713                 :            :         MLX5_EXPANSION_OUTER_IPV6_ICMP6,
     714                 :            :         MLX5_EXPANSION_VXLAN,
     715                 :            :         MLX5_EXPANSION_STD_VXLAN,
     716                 :            :         MLX5_EXPANSION_L3_VXLAN,
     717                 :            :         MLX5_EXPANSION_VXLAN_GPE,
     718                 :            :         MLX5_EXPANSION_GRE,
     719                 :            :         MLX5_EXPANSION_NVGRE,
     720                 :            :         MLX5_EXPANSION_GRE_KEY,
     721                 :            :         MLX5_EXPANSION_MPLS,
     722                 :            :         MLX5_EXPANSION_ETH,
     723                 :            :         MLX5_EXPANSION_VLAN,
     724                 :            :         MLX5_EXPANSION_IPV4,
     725                 :            :         MLX5_EXPANSION_IPV4_UDP,
     726                 :            :         MLX5_EXPANSION_IPV4_TCP,
     727                 :            :         MLX5_EXPANSION_IPV4_ESP,
     728                 :            :         MLX5_EXPANSION_IPV4_ICMP,
     729                 :            :         MLX5_EXPANSION_IPV6,
     730                 :            :         MLX5_EXPANSION_IPV6_UDP,
     731                 :            :         MLX5_EXPANSION_IPV6_TCP,
     732                 :            :         MLX5_EXPANSION_IPV6_ESP,
     733                 :            :         MLX5_EXPANSION_IPV6_ICMP6,
     734                 :            :         MLX5_EXPANSION_IPV6_FRAG_EXT,
     735                 :            :         MLX5_EXPANSION_GTP,
     736                 :            :         MLX5_EXPANSION_GENEVE,
     737                 :            : };
     738                 :            : 
     739                 :            : /** Supported expansion of items. */
     740                 :            : static const struct mlx5_flow_expand_node mlx5_support_expansion[] = {
     741                 :            :         [MLX5_EXPANSION_ROOT] = {
     742                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
     743                 :            :                                                   MLX5_EXPANSION_IPV4,
     744                 :            :                                                   MLX5_EXPANSION_IPV6),
     745                 :            :                 .type = RTE_FLOW_ITEM_TYPE_END,
     746                 :            :         },
     747                 :            :         [MLX5_EXPANSION_ROOT_OUTER] = {
     748                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_ETH,
     749                 :            :                                                   MLX5_EXPANSION_OUTER_IPV4,
     750                 :            :                                                   MLX5_EXPANSION_OUTER_IPV6),
     751                 :            :                 .type = RTE_FLOW_ITEM_TYPE_END,
     752                 :            :         },
     753                 :            :         [MLX5_EXPANSION_OUTER_ETH] = {
     754                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_VLAN),
     755                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ETH,
     756                 :            :                 .rss_types = 0,
     757                 :            :         },
     758                 :            :         [MLX5_EXPANSION_OUTER_VLAN] = {
     759                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_OUTER_IPV4,
     760                 :            :                                                   MLX5_EXPANSION_OUTER_IPV6),
     761                 :            :                 .type = RTE_FLOW_ITEM_TYPE_VLAN,
     762                 :            :                 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
     763                 :            :         },
     764                 :            :         [MLX5_EXPANSION_OUTER_IPV4] = {
     765                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT
     766                 :            :                         (MLX5_EXPANSION_OUTER_IPV4_UDP,
     767                 :            :                          MLX5_EXPANSION_OUTER_IPV4_TCP,
     768                 :            :                          MLX5_EXPANSION_OUTER_IPV4_ESP,
     769                 :            :                          MLX5_EXPANSION_OUTER_IPV4_ICMP,
     770                 :            :                          MLX5_EXPANSION_GRE,
     771                 :            :                          MLX5_EXPANSION_NVGRE,
     772                 :            :                          MLX5_EXPANSION_IPV4,
     773                 :            :                          MLX5_EXPANSION_IPV6),
     774                 :            :                 .type = RTE_FLOW_ITEM_TYPE_IPV4,
     775                 :            :                 .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
     776                 :            :                         RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
     777                 :            :         },
     778                 :            :         [MLX5_EXPANSION_OUTER_IPV4_UDP] = {
     779                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
     780                 :            :                                                   MLX5_EXPANSION_VXLAN_GPE,
     781                 :            :                                                   MLX5_EXPANSION_MPLS,
     782                 :            :                                                   MLX5_EXPANSION_GENEVE,
     783                 :            :                                                   MLX5_EXPANSION_GTP),
     784                 :            :                 .type = RTE_FLOW_ITEM_TYPE_UDP,
     785                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
     786                 :            :         },
     787                 :            :         [MLX5_EXPANSION_OUTER_IPV4_TCP] = {
     788                 :            :                 .type = RTE_FLOW_ITEM_TYPE_TCP,
     789                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
     790                 :            :         },
     791                 :            :         [MLX5_EXPANSION_OUTER_IPV4_ESP] = {
     792                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ESP,
     793                 :            :                 .rss_types = RTE_ETH_RSS_ESP,
     794                 :            :         },
     795                 :            :         [MLX5_EXPANSION_OUTER_IPV4_ICMP] = {
     796                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ICMP,
     797                 :            :         },
     798                 :            :         [MLX5_EXPANSION_OUTER_IPV6] = {
     799                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT
     800                 :            :                         (MLX5_EXPANSION_OUTER_IPV6_UDP,
     801                 :            :                          MLX5_EXPANSION_OUTER_IPV6_TCP,
     802                 :            :                          MLX5_EXPANSION_OUTER_IPV6_ESP,
     803                 :            :                          MLX5_EXPANSION_OUTER_IPV6_ICMP6,
     804                 :            :                          MLX5_EXPANSION_IPV4,
     805                 :            :                          MLX5_EXPANSION_IPV6,
     806                 :            :                          MLX5_EXPANSION_GRE,
     807                 :            :                          MLX5_EXPANSION_NVGRE),
     808                 :            :                 .type = RTE_FLOW_ITEM_TYPE_IPV6,
     809                 :            :                 .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
     810                 :            :                         RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
     811                 :            :         },
     812                 :            :         [MLX5_EXPANSION_OUTER_IPV6_UDP] = {
     813                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VXLAN,
     814                 :            :                                                   MLX5_EXPANSION_VXLAN_GPE,
     815                 :            :                                                   MLX5_EXPANSION_MPLS,
     816                 :            :                                                   MLX5_EXPANSION_GENEVE,
     817                 :            :                                                   MLX5_EXPANSION_GTP),
     818                 :            :                 .type = RTE_FLOW_ITEM_TYPE_UDP,
     819                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
     820                 :            :         },
     821                 :            :         [MLX5_EXPANSION_OUTER_IPV6_TCP] = {
     822                 :            :                 .type = RTE_FLOW_ITEM_TYPE_TCP,
     823                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
     824                 :            :         },
     825                 :            :         [MLX5_EXPANSION_OUTER_IPV6_ESP] = {
     826                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ESP,
     827                 :            :                 .rss_types = RTE_ETH_RSS_ESP,
     828                 :            :         },
     829                 :            :         [MLX5_EXPANSION_OUTER_IPV6_ICMP6] = {
     830                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ICMP6,
     831                 :            :         },
     832                 :            :         [MLX5_EXPANSION_VXLAN] = {
     833                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
     834                 :            :                                                   MLX5_EXPANSION_IPV4,
     835                 :            :                                                   MLX5_EXPANSION_IPV6),
     836                 :            :                 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
     837                 :            :         },
     838                 :            :         [MLX5_EXPANSION_STD_VXLAN] = {
     839                 :            :                         .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
     840                 :            :                                         .type = RTE_FLOW_ITEM_TYPE_VXLAN,
     841                 :            :         },
     842                 :            :         [MLX5_EXPANSION_L3_VXLAN] = {
     843                 :            :                         .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
     844                 :            :                                         MLX5_EXPANSION_IPV6),
     845                 :            :                                         .type = RTE_FLOW_ITEM_TYPE_VXLAN,
     846                 :            :         },
     847                 :            :         [MLX5_EXPANSION_VXLAN_GPE] = {
     848                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
     849                 :            :                                                   MLX5_EXPANSION_IPV4,
     850                 :            :                                                   MLX5_EXPANSION_IPV6),
     851                 :            :                 .type = RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
     852                 :            :         },
     853                 :            :         [MLX5_EXPANSION_GRE] = {
     854                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
     855                 :            :                                                   MLX5_EXPANSION_IPV4,
     856                 :            :                                                   MLX5_EXPANSION_IPV6,
     857                 :            :                                                   MLX5_EXPANSION_GRE_KEY,
     858                 :            :                                                   MLX5_EXPANSION_MPLS),
     859                 :            :                 .type = RTE_FLOW_ITEM_TYPE_GRE,
     860                 :            :         },
     861                 :            :         [MLX5_EXPANSION_GRE_KEY] = {
     862                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
     863                 :            :                                                   MLX5_EXPANSION_IPV6,
     864                 :            :                                                   MLX5_EXPANSION_MPLS),
     865                 :            :                 .type = RTE_FLOW_ITEM_TYPE_GRE_KEY,
     866                 :            :                 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
     867                 :            :         },
     868                 :            :         [MLX5_EXPANSION_NVGRE] = {
     869                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH),
     870                 :            :                 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
     871                 :            :         },
     872                 :            :         [MLX5_EXPANSION_MPLS] = {
     873                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
     874                 :            :                                                   MLX5_EXPANSION_IPV6,
     875                 :            :                                                   MLX5_EXPANSION_ETH),
     876                 :            :                 .type = RTE_FLOW_ITEM_TYPE_MPLS,
     877                 :            :                 .node_flags = MLX5_EXPANSION_NODE_OPTIONAL,
     878                 :            :         },
     879                 :            :         [MLX5_EXPANSION_ETH] = {
     880                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_VLAN),
     881                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ETH,
     882                 :            :         },
     883                 :            :         [MLX5_EXPANSION_VLAN] = {
     884                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
     885                 :            :                                                   MLX5_EXPANSION_IPV6),
     886                 :            :                 .type = RTE_FLOW_ITEM_TYPE_VLAN,
     887                 :            :                 .node_flags = MLX5_EXPANSION_NODE_EXPLICIT,
     888                 :            :         },
     889                 :            :         [MLX5_EXPANSION_IPV4] = {
     890                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4_UDP,
     891                 :            :                                                   MLX5_EXPANSION_IPV4_TCP,
     892                 :            :                                                   MLX5_EXPANSION_IPV4_ESP,
     893                 :            :                                                   MLX5_EXPANSION_IPV4_ICMP),
     894                 :            :                 .type = RTE_FLOW_ITEM_TYPE_IPV4,
     895                 :            :                 .rss_types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
     896                 :            :                         RTE_ETH_RSS_NONFRAG_IPV4_OTHER,
     897                 :            :         },
     898                 :            :         [MLX5_EXPANSION_IPV4_UDP] = {
     899                 :            :                 .type = RTE_FLOW_ITEM_TYPE_UDP,
     900                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_UDP,
     901                 :            :         },
     902                 :            :         [MLX5_EXPANSION_IPV4_TCP] = {
     903                 :            :                 .type = RTE_FLOW_ITEM_TYPE_TCP,
     904                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV4_TCP,
     905                 :            :         },
     906                 :            :         [MLX5_EXPANSION_IPV4_ESP] = {
     907                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ESP,
     908                 :            :                 .rss_types = RTE_ETH_RSS_ESP,
     909                 :            :         },
     910                 :            :         [MLX5_EXPANSION_IPV4_ICMP] = {
     911                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ICMP,
     912                 :            :         },
     913                 :            :         [MLX5_EXPANSION_IPV6] = {
     914                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV6_UDP,
     915                 :            :                                                   MLX5_EXPANSION_IPV6_TCP,
     916                 :            :                                                   MLX5_EXPANSION_IPV6_ESP,
     917                 :            :                                                   MLX5_EXPANSION_IPV6_ICMP6,
     918                 :            :                                                   MLX5_EXPANSION_IPV6_FRAG_EXT),
     919                 :            :                 .type = RTE_FLOW_ITEM_TYPE_IPV6,
     920                 :            :                 .rss_types = RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
     921                 :            :                         RTE_ETH_RSS_NONFRAG_IPV6_OTHER,
     922                 :            :         },
     923                 :            :         [MLX5_EXPANSION_IPV6_UDP] = {
     924                 :            :                 .type = RTE_FLOW_ITEM_TYPE_UDP,
     925                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_UDP,
     926                 :            :         },
     927                 :            :         [MLX5_EXPANSION_IPV6_TCP] = {
     928                 :            :                 .type = RTE_FLOW_ITEM_TYPE_TCP,
     929                 :            :                 .rss_types = RTE_ETH_RSS_NONFRAG_IPV6_TCP,
     930                 :            :         },
     931                 :            :         [MLX5_EXPANSION_IPV6_ESP] = {
     932                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ESP,
     933                 :            :                 .rss_types = RTE_ETH_RSS_ESP,
     934                 :            :         },
     935                 :            :         [MLX5_EXPANSION_IPV6_FRAG_EXT] = {
     936                 :            :                 .type = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT,
     937                 :            :         },
     938                 :            :         [MLX5_EXPANSION_IPV6_ICMP6] = {
     939                 :            :                 .type = RTE_FLOW_ITEM_TYPE_ICMP6,
     940                 :            :         },
     941                 :            :         [MLX5_EXPANSION_GTP] = {
     942                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_IPV4,
     943                 :            :                                                   MLX5_EXPANSION_IPV6),
     944                 :            :                 .type = RTE_FLOW_ITEM_TYPE_GTP,
     945                 :            :         },
     946                 :            :         [MLX5_EXPANSION_GENEVE] = {
     947                 :            :                 .next = MLX5_FLOW_EXPAND_RSS_NEXT(MLX5_EXPANSION_ETH,
     948                 :            :                                                   MLX5_EXPANSION_IPV4,
     949                 :            :                                                   MLX5_EXPANSION_IPV6),
     950                 :            :                 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
     951                 :            :         },
     952                 :            : };
     953                 :            : 
     954                 :            : static struct rte_flow_action_handle *
     955                 :            : mlx5_action_handle_create(struct rte_eth_dev *dev,
     956                 :            :                           const struct rte_flow_indir_action_conf *conf,
     957                 :            :                           const struct rte_flow_action *action,
     958                 :            :                           struct rte_flow_error *error);
     959                 :            : static int mlx5_action_handle_destroy
     960                 :            :                                 (struct rte_eth_dev *dev,
     961                 :            :                                  struct rte_flow_action_handle *handle,
     962                 :            :                                  struct rte_flow_error *error);
     963                 :            : static int mlx5_action_handle_update
     964                 :            :                                 (struct rte_eth_dev *dev,
     965                 :            :                                  struct rte_flow_action_handle *handle,
     966                 :            :                                  const void *update,
     967                 :            :                                  struct rte_flow_error *error);
     968                 :            : static int mlx5_action_handle_query
     969                 :            :                                 (struct rte_eth_dev *dev,
     970                 :            :                                  const struct rte_flow_action_handle *handle,
     971                 :            :                                  void *data,
     972                 :            :                                  struct rte_flow_error *error);
     973                 :            : static int
     974                 :            : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
     975                 :            :                     struct rte_flow_tunnel *app_tunnel,
     976                 :            :                     struct rte_flow_action **actions,
     977                 :            :                     uint32_t *num_of_actions,
     978                 :            :                     struct rte_flow_error *error);
     979                 :            : static int
     980                 :            : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
     981                 :            :                        struct rte_flow_tunnel *app_tunnel,
     982                 :            :                        struct rte_flow_item **items,
     983                 :            :                        uint32_t *num_of_items,
     984                 :            :                        struct rte_flow_error *error);
     985                 :            : static int
     986                 :            : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
     987                 :            :                               struct rte_flow_item *pmd_items,
     988                 :            :                               uint32_t num_items, struct rte_flow_error *err);
     989                 :            : static int
     990                 :            : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
     991                 :            :                                 struct rte_flow_action *pmd_actions,
     992                 :            :                                 uint32_t num_actions,
     993                 :            :                                 struct rte_flow_error *err);
     994                 :            : static int
     995                 :            : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
     996                 :            :                                   struct rte_mbuf *m,
     997                 :            :                                   struct rte_flow_restore_info *info,
     998                 :            :                                   struct rte_flow_error *err);
     999                 :            : static struct rte_flow_item_flex_handle *
    1000                 :            : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
    1001                 :            :                            const struct rte_flow_item_flex_conf *conf,
    1002                 :            :                            struct rte_flow_error *error);
    1003                 :            : static int
    1004                 :            : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
    1005                 :            :                             const struct rte_flow_item_flex_handle *handle,
    1006                 :            :                             struct rte_flow_error *error);
    1007                 :            : static int
    1008                 :            : mlx5_flow_info_get(struct rte_eth_dev *dev,
    1009                 :            :                    struct rte_flow_port_info *port_info,
    1010                 :            :                    struct rte_flow_queue_info *queue_info,
    1011                 :            :                    struct rte_flow_error *error);
    1012                 :            : static int
    1013                 :            : mlx5_flow_port_configure(struct rte_eth_dev *dev,
    1014                 :            :                          const struct rte_flow_port_attr *port_attr,
    1015                 :            :                          uint16_t nb_queue,
    1016                 :            :                          const struct rte_flow_queue_attr *queue_attr[],
    1017                 :            :                          struct rte_flow_error *err);
    1018                 :            : 
    1019                 :            : static struct rte_flow_pattern_template *
    1020                 :            : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
    1021                 :            :                 const struct rte_flow_pattern_template_attr *attr,
    1022                 :            :                 const struct rte_flow_item items[],
    1023                 :            :                 struct rte_flow_error *error);
    1024                 :            : 
    1025                 :            : static int
    1026                 :            : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
    1027                 :            :                                    struct rte_flow_pattern_template *template,
    1028                 :            :                                    struct rte_flow_error *error);
    1029                 :            : static struct rte_flow_actions_template *
    1030                 :            : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
    1031                 :            :                         const struct rte_flow_actions_template_attr *attr,
    1032                 :            :                         const struct rte_flow_action actions[],
    1033                 :            :                         const struct rte_flow_action masks[],
    1034                 :            :                         struct rte_flow_error *error);
    1035                 :            : static int
    1036                 :            : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
    1037                 :            :                                    struct rte_flow_actions_template *template,
    1038                 :            :                                    struct rte_flow_error *error);
    1039                 :            : 
    1040                 :            : static struct rte_flow_template_table *
    1041                 :            : mlx5_flow_table_create(struct rte_eth_dev *dev,
    1042                 :            :                        const struct rte_flow_template_table_attr *attr,
    1043                 :            :                        struct rte_flow_pattern_template *item_templates[],
    1044                 :            :                        uint8_t nb_item_templates,
    1045                 :            :                        struct rte_flow_actions_template *action_templates[],
    1046                 :            :                        uint8_t nb_action_templates,
    1047                 :            :                        struct rte_flow_error *error);
    1048                 :            : static int
    1049                 :            : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
    1050                 :            :                         struct rte_flow_template_table *table,
    1051                 :            :                         struct rte_flow_error *error);
    1052                 :            : static int
    1053                 :            : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
    1054                 :            :                                  uint32_t group_id,
    1055                 :            :                                  const struct rte_flow_group_attr *attr,
    1056                 :            :                                  const struct rte_flow_action actions[],
    1057                 :            :                                  struct rte_flow_error *error);
    1058                 :            : 
    1059                 :            : static int
    1060                 :            : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
    1061                 :            :                                 struct rte_flow_action_handle *handle,
    1062                 :            :                                 const void *update, void *query,
    1063                 :            :                                 enum rte_flow_query_update_mode qu_mode,
    1064                 :            :                                 struct rte_flow_error *error);
    1065                 :            : 
    1066                 :            : static struct rte_flow_action_list_handle *
    1067                 :            : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
    1068                 :            :                                const struct rte_flow_indir_action_conf *conf,
    1069                 :            :                                const struct rte_flow_action *actions,
    1070                 :            :                                struct rte_flow_error *error);
    1071                 :            : 
    1072                 :            : static int
    1073                 :            : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
    1074                 :            :                                 struct rte_flow_action_list_handle *handle,
    1075                 :            :                                 struct rte_flow_error *error);
    1076                 :            : 
    1077                 :            : static int
    1078                 :            : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
    1079                 :            :                                           const
    1080                 :            :                                           struct rte_flow_action_list_handle *handle,
    1081                 :            :                                           const void **update, void **query,
    1082                 :            :                                           enum rte_flow_query_update_mode mode,
    1083                 :            :                                           struct rte_flow_error *error);
    1084                 :            : 
    1085                 :            : static int
    1086                 :            : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
    1087                 :            :                           const struct rte_flow_template_table *table,
    1088                 :            :                           const struct rte_flow_item pattern[],
    1089                 :            :                           uint8_t pattern_template_index,
    1090                 :            :                           uint32_t *hash, struct rte_flow_error *error);
    1091                 :            : static int
    1092                 :            : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
    1093                 :            :                           const struct rte_flow_item pattern[],
    1094                 :            :                           enum rte_flow_encap_hash_field dest_field,
    1095                 :            :                           uint8_t *hash,
    1096                 :            :                           struct rte_flow_error *error);
    1097                 :            : 
    1098                 :            : static int
    1099                 :            : mlx5_template_table_resize(struct rte_eth_dev *dev,
    1100                 :            :                            struct rte_flow_template_table *table,
    1101                 :            :                            uint32_t nb_rules, struct rte_flow_error *error);
    1102                 :            : static int
    1103                 :            : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
    1104                 :            :                                const struct rte_flow_op_attr *attr,
    1105                 :            :                                struct rte_flow *rule, void *user_data,
    1106                 :            :                                struct rte_flow_error *error);
    1107                 :            : static int
    1108                 :            : mlx5_table_resize_complete(struct rte_eth_dev *dev,
    1109                 :            :                            struct rte_flow_template_table *table,
    1110                 :            :                            struct rte_flow_error *error);
    1111                 :            : 
    1112                 :            : static const struct rte_flow_ops mlx5_flow_ops = {
    1113                 :            :         .validate = mlx5_flow_validate,
    1114                 :            :         .create = mlx5_flow_create,
    1115                 :            :         .destroy = mlx5_flow_destroy,
    1116                 :            :         .flush = mlx5_flow_flush,
    1117                 :            :         .isolate = mlx5_flow_isolate,
    1118                 :            :         .query = mlx5_flow_query,
    1119                 :            :         .dev_dump = mlx5_flow_dev_dump,
    1120                 :            :         .get_q_aged_flows = mlx5_flow_get_q_aged_flows,
    1121                 :            :         .get_aged_flows = mlx5_flow_get_aged_flows,
    1122                 :            :         .action_handle_create = mlx5_action_handle_create,
    1123                 :            :         .action_handle_destroy = mlx5_action_handle_destroy,
    1124                 :            :         .action_handle_update = mlx5_action_handle_update,
    1125                 :            :         .action_handle_query = mlx5_action_handle_query,
    1126                 :            :         .action_handle_query_update = mlx5_action_handle_query_update,
    1127                 :            :         .action_list_handle_create = mlx5_action_list_handle_create,
    1128                 :            :         .action_list_handle_destroy = mlx5_action_list_handle_destroy,
    1129                 :            :         .tunnel_decap_set = mlx5_flow_tunnel_decap_set,
    1130                 :            :         .tunnel_match = mlx5_flow_tunnel_match,
    1131                 :            :         .tunnel_action_decap_release = mlx5_flow_tunnel_action_release,
    1132                 :            :         .tunnel_item_release = mlx5_flow_tunnel_item_release,
    1133                 :            :         .get_restore_info = mlx5_flow_tunnel_get_restore_info,
    1134                 :            :         .flex_item_create = mlx5_flow_flex_item_create,
    1135                 :            :         .flex_item_release = mlx5_flow_flex_item_release,
    1136                 :            :         .info_get = mlx5_flow_info_get,
    1137                 :            :         .pick_transfer_proxy = mlx5_flow_pick_transfer_proxy,
    1138                 :            :         .configure = mlx5_flow_port_configure,
    1139                 :            :         .pattern_template_create = mlx5_flow_pattern_template_create,
    1140                 :            :         .pattern_template_destroy = mlx5_flow_pattern_template_destroy,
    1141                 :            :         .actions_template_create = mlx5_flow_actions_template_create,
    1142                 :            :         .actions_template_destroy = mlx5_flow_actions_template_destroy,
    1143                 :            :         .template_table_create = mlx5_flow_table_create,
    1144                 :            :         .template_table_destroy = mlx5_flow_table_destroy,
    1145                 :            :         .group_set_miss_actions = mlx5_flow_group_set_miss_actions,
    1146                 :            :         .action_list_handle_query_update =
    1147                 :            :                 mlx5_flow_action_list_handle_query_update,
    1148                 :            :         .flow_calc_table_hash = mlx5_flow_calc_table_hash,
    1149                 :            :         .flow_calc_encap_hash = mlx5_flow_calc_encap_hash,
    1150                 :            :         .flow_template_table_resize = mlx5_template_table_resize,
    1151                 :            :         .flow_update_resized = mlx5_flow_async_update_resized,
    1152                 :            :         .flow_template_table_resize_complete = mlx5_table_resize_complete,
    1153                 :            : };
    1154                 :            : 
    1155                 :            : /* Tunnel information. */
    1156                 :            : struct mlx5_flow_tunnel_info {
    1157                 :            :         uint64_t tunnel; /**< Tunnel bit (see MLX5_FLOW_*). */
    1158                 :            :         uint32_t ptype; /**< Tunnel Ptype (see RTE_PTYPE_*). */
    1159                 :            : };
    1160                 :            : 
    1161                 :            : static struct mlx5_flow_tunnel_info tunnels_info[] = {
    1162                 :            :         {
    1163                 :            :                 .tunnel = MLX5_FLOW_LAYER_VXLAN,
    1164                 :            :                 .ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP,
    1165                 :            :         },
    1166                 :            :         {
    1167                 :            :                 .tunnel = MLX5_FLOW_LAYER_GENEVE,
    1168                 :            :                 .ptype = RTE_PTYPE_TUNNEL_GENEVE | RTE_PTYPE_L4_UDP,
    1169                 :            :         },
    1170                 :            :         {
    1171                 :            :                 .tunnel = MLX5_FLOW_LAYER_VXLAN_GPE,
    1172                 :            :                 .ptype = RTE_PTYPE_TUNNEL_VXLAN_GPE | RTE_PTYPE_L4_UDP,
    1173                 :            :         },
    1174                 :            :         {
    1175                 :            :                 .tunnel = MLX5_FLOW_LAYER_GRE,
    1176                 :            :                 .ptype = RTE_PTYPE_TUNNEL_GRE,
    1177                 :            :         },
    1178                 :            :         {
    1179                 :            :                 .tunnel = MLX5_FLOW_LAYER_MPLS | MLX5_FLOW_LAYER_OUTER_L4_UDP,
    1180                 :            :                 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_UDP | RTE_PTYPE_L4_UDP,
    1181                 :            :         },
    1182                 :            :         {
    1183                 :            :                 .tunnel = MLX5_FLOW_LAYER_MPLS,
    1184                 :            :                 .ptype = RTE_PTYPE_TUNNEL_MPLS_IN_GRE,
    1185                 :            :         },
    1186                 :            :         {
    1187                 :            :                 .tunnel = MLX5_FLOW_LAYER_NVGRE,
    1188                 :            :                 .ptype = RTE_PTYPE_TUNNEL_NVGRE,
    1189                 :            :         },
    1190                 :            :         {
    1191                 :            :                 .tunnel = MLX5_FLOW_LAYER_IPIP,
    1192                 :            :                 .ptype = RTE_PTYPE_TUNNEL_IP,
    1193                 :            :         },
    1194                 :            :         {
    1195                 :            :                 .tunnel = MLX5_FLOW_LAYER_IPV6_ENCAP,
    1196                 :            :                 .ptype = RTE_PTYPE_TUNNEL_IP,
    1197                 :            :         },
    1198                 :            :         {
    1199                 :            :                 .tunnel = MLX5_FLOW_LAYER_GTP,
    1200                 :            :                 .ptype = RTE_PTYPE_TUNNEL_GTPU,
    1201                 :            :         },
    1202                 :            : };
    1203                 :            : 
    1204                 :            : 
    1205                 :            : 
    1206                 :            : /**
    1207                 :            :  * Translate tag ID to register.
    1208                 :            :  *
    1209                 :            :  * @param[in] dev
    1210                 :            :  *   Pointer to the Ethernet device structure.
    1211                 :            :  * @param[in] feature
    1212                 :            :  *   The feature that request the register.
    1213                 :            :  * @param[in] id
    1214                 :            :  *   The request register ID.
    1215                 :            :  * @param[out] error
    1216                 :            :  *   Error description in case of any.
    1217                 :            :  *
    1218                 :            :  * @return
    1219                 :            :  *   The request register on success, a negative errno
    1220                 :            :  *   value otherwise and rte_errno is set.
    1221                 :            :  */
    1222                 :            : int
    1223                 :          0 : mlx5_flow_get_reg_id(struct rte_eth_dev *dev,
    1224                 :            :                      enum mlx5_feature_name feature,
    1225                 :            :                      uint32_t id,
    1226                 :            :                      struct rte_flow_error *error)
    1227                 :            : {
    1228                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1229                 :          0 :         struct mlx5_sh_config *config = &priv->sh->config;
    1230                 :            :         struct mlx5_dev_registers *reg = &priv->sh->registers;
    1231                 :            :         enum modify_reg start_reg;
    1232                 :            :         bool skip_mtr_reg = false;
    1233                 :            : 
    1234   [ #  #  #  #  :          0 :         switch (feature) {
          #  #  #  #  #  
                   #  # ]
    1235                 :            :         case MLX5_HAIRPIN_RX:
    1236                 :            :                 return REG_B;
    1237                 :          0 :         case MLX5_HAIRPIN_TX:
    1238                 :          0 :                 return REG_A;
    1239                 :          0 :         case MLX5_METADATA_RX:
    1240   [ #  #  #  #  :          0 :                 switch (config->dv_xmeta_en) {
                      # ]
    1241                 :            :                 case MLX5_XMETA_MODE_LEGACY:
    1242                 :            :                         return REG_B;
    1243                 :          0 :                 case MLX5_XMETA_MODE_META16:
    1244                 :          0 :                         return REG_C_0;
    1245                 :          0 :                 case MLX5_XMETA_MODE_META32:
    1246                 :          0 :                         return REG_C_1;
    1247                 :          0 :                 case MLX5_XMETA_MODE_META32_HWS:
    1248                 :          0 :                         return REG_C_1;
    1249                 :            :                 }
    1250                 :            :                 break;
    1251                 :          0 :         case MLX5_METADATA_TX:
    1252         [ #  # ]:          0 :                 if (config->dv_flow_en == 2 && config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS) {
    1253                 :            :                         return REG_C_1;
    1254                 :            :                 } else {
    1255                 :          0 :                         return REG_A;
    1256                 :            :                 }
    1257                 :          0 :         case MLX5_METADATA_FDB:
    1258   [ #  #  #  #  :          0 :                 switch (config->dv_xmeta_en) {
                      # ]
    1259                 :            :                 case MLX5_XMETA_MODE_LEGACY:
    1260                 :            :                         return REG_NON;
    1261                 :          0 :                 case MLX5_XMETA_MODE_META16:
    1262                 :          0 :                         return REG_C_0;
    1263                 :          0 :                 case MLX5_XMETA_MODE_META32:
    1264                 :          0 :                         return REG_C_1;
    1265                 :          0 :                 case MLX5_XMETA_MODE_META32_HWS:
    1266                 :          0 :                         return REG_C_1;
    1267                 :            :                 }
    1268                 :            :                 break;
    1269                 :          0 :         case MLX5_FLOW_MARK:
    1270   [ #  #  #  # ]:          0 :                 switch (config->dv_xmeta_en) {
    1271                 :            :                 case MLX5_XMETA_MODE_LEGACY:
    1272                 :            :                 case MLX5_XMETA_MODE_META32_HWS:
    1273                 :            :                         return REG_NON;
    1274                 :          0 :                 case MLX5_XMETA_MODE_META16:
    1275                 :          0 :                         return REG_C_1;
    1276                 :          0 :                 case MLX5_XMETA_MODE_META32:
    1277                 :          0 :                         return REG_C_0;
    1278                 :            :                 }
    1279                 :            :                 break;
    1280                 :          0 :         case MLX5_MTR_ID:
    1281                 :            :                 /*
    1282                 :            :                  * If meter color and meter id share one register, flow match
    1283                 :            :                  * should use the meter color register for match.
    1284                 :            :                  */
    1285         [ #  # ]:          0 :                 if (priv->mtr_reg_share)
    1286                 :          0 :                         return reg->aso_reg;
    1287                 :            :                 else
    1288         [ #  # ]:          0 :                         return reg->aso_reg != REG_C_2 ? REG_C_2 :
    1289                 :            :                                REG_C_3;
    1290                 :          0 :         case MLX5_MTR_COLOR:
    1291                 :            :         case MLX5_ASO_FLOW_HIT:
    1292                 :            :         case MLX5_ASO_CONNTRACK:
    1293                 :            :         case MLX5_SAMPLE_ID:
    1294                 :            :                 /* All features use the same REG_C. */
    1295                 :            :                 MLX5_ASSERT(reg->aso_reg != REG_NON);
    1296                 :          0 :                 return reg->aso_reg;
    1297                 :          0 :         case MLX5_COPY_MARK:
    1298                 :            :                 /*
    1299                 :            :                  * Metadata COPY_MARK register using is in meter suffix sub
    1300                 :            :                  * flow while with meter. It's safe to share the same register.
    1301                 :            :                  */
    1302         [ #  # ]:          0 :                 return reg->aso_reg != REG_C_2 ? REG_C_2 : REG_C_3;
    1303                 :          0 :         case MLX5_APP_TAG:
    1304                 :            :                 /*
    1305                 :            :                  * If meter is enable, it will engage the register for color
    1306                 :            :                  * match and flow match. If meter color match is not using the
    1307                 :            :                  * REG_C_2, need to skip the REG_C_x be used by meter color
    1308                 :            :                  * match.
    1309                 :            :                  * If meter is disable, free to use all available registers.
    1310                 :            :                  */
    1311         [ #  # ]:          0 :                 start_reg = reg->aso_reg != REG_C_2 ? REG_C_2 :
    1312         [ #  # ]:          0 :                             (priv->mtr_reg_share ? REG_C_3 : REG_C_4);
    1313   [ #  #  #  # ]:          0 :                 skip_mtr_reg = !!(priv->mtr_en && start_reg == REG_C_2);
    1314         [ #  # ]:          0 :                 if (id > (uint32_t)(REG_C_7 - start_reg))
    1315                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    1316                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    1317                 :            :                                                   NULL, "invalid tag id");
    1318         [ #  # ]:          0 :                 if (priv->sh->flow_mreg_c[id + start_reg - REG_C_0] == REG_NON)
    1319                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    1320                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    1321                 :            :                                                   NULL, "unsupported tag id");
    1322                 :            :                 /*
    1323                 :            :                  * This case means meter is using the REG_C_x great than 2.
    1324                 :            :                  * Take care not to conflict with meter color REG_C_x.
    1325                 :            :                  * If the available index REG_C_y >= REG_C_x, skip the
    1326                 :            :                  * color register.
    1327                 :            :                  */
    1328   [ #  #  #  # ]:          0 :                 if (skip_mtr_reg && priv->sh->flow_mreg_c
    1329                 :            :                     [id + start_reg - REG_C_0] >= reg->aso_reg) {
    1330         [ #  # ]:          0 :                         if (id >= (uint32_t)(REG_C_7 - start_reg))
    1331                 :          0 :                                 return rte_flow_error_set(error, EINVAL,
    1332                 :            :                                                        RTE_FLOW_ERROR_TYPE_ITEM,
    1333                 :            :                                                         NULL, "invalid tag id");
    1334                 :          0 :                         if (priv->sh->flow_mreg_c
    1335         [ #  # ]:          0 :                             [id + 1 + start_reg - REG_C_0] != REG_NON)
    1336                 :            :                                 return priv->sh->flow_mreg_c
    1337                 :          0 :                                                [id + 1 + start_reg - REG_C_0];
    1338                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    1339                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    1340                 :            :                                                   NULL, "unsupported tag id");
    1341                 :            :                 }
    1342                 :          0 :                 return priv->sh->flow_mreg_c[id + start_reg - REG_C_0];
    1343                 :            :         }
    1344                 :            :         MLX5_ASSERT(false);
    1345                 :          0 :         return rte_flow_error_set(error, EINVAL,
    1346                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    1347                 :            :                                   NULL, "invalid feature name");
    1348                 :            : }
    1349                 :            : 
    1350                 :            : /**
    1351                 :            :  * Check extensive flow metadata register support.
    1352                 :            :  *
    1353                 :            :  * @param dev
    1354                 :            :  *   Pointer to rte_eth_dev structure.
    1355                 :            :  *
    1356                 :            :  * @return
    1357                 :            :  *   True if device supports extensive flow metadata register, otherwise false.
    1358                 :            :  */
    1359                 :            : bool
    1360                 :          0 : mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev)
    1361                 :            : {
    1362                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1363                 :            : 
    1364                 :            :         /*
    1365                 :            :          * Having available reg_c can be regarded inclusively as supporting
    1366                 :            :          * extensive flow metadata register, which could mean,
    1367                 :            :          * - metadata register copy action by modify header.
    1368                 :            :          * - 16 modify header actions is supported.
    1369                 :            :          * - reg_c's are preserved across different domain (FDB and NIC) on
    1370                 :            :          *   packet loopback by flow lookup miss.
    1371                 :            :          */
    1372                 :          0 :         return priv->sh->flow_mreg_c[2] != REG_NON;
    1373                 :            : }
    1374                 :            : 
    1375                 :            : /**
    1376                 :            :  * Get the lowest priority.
    1377                 :            :  *
    1378                 :            :  * @param[in] dev
    1379                 :            :  *   Pointer to the Ethernet device structure.
    1380                 :            :  * @param[in] attributes
    1381                 :            :  *   Pointer to device flow rule attributes.
    1382                 :            :  *
    1383                 :            :  * @return
    1384                 :            :  *   The value of lowest priority of flow.
    1385                 :            :  */
    1386                 :            : uint32_t
    1387                 :          0 : mlx5_get_lowest_priority(struct rte_eth_dev *dev,
    1388                 :            :                           const struct rte_flow_attr *attr)
    1389                 :            : {
    1390                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1391                 :            : 
    1392   [ #  #  #  #  :          0 :         if (!attr->group && !(attr->transfer && priv->fdb_def_rule))
                   #  # ]
    1393                 :          0 :                 return priv->sh->flow_max_priority - 2;
    1394                 :            :         return MLX5_NON_ROOT_FLOW_MAX_PRIO - 1;
    1395                 :            : }
    1396                 :            : 
    1397                 :            : /**
    1398                 :            :  * Calculate matcher priority of the flow.
    1399                 :            :  *
    1400                 :            :  * @param[in] dev
    1401                 :            :  *   Pointer to the Ethernet device structure.
    1402                 :            :  * @param[in] attr
    1403                 :            :  *   Pointer to device flow rule attributes.
    1404                 :            :  * @param[in] subpriority
    1405                 :            :  *   The priority based on the items.
    1406                 :            :  * @param[in] external
    1407                 :            :  *   Flow is user flow.
    1408                 :            :  * @return
    1409                 :            :  *   The matcher priority of the flow.
    1410                 :            :  */
    1411                 :            : uint16_t
    1412                 :          0 : mlx5_get_matcher_priority(struct rte_eth_dev *dev,
    1413                 :            :                           const struct rte_flow_attr *attr,
    1414                 :            :                           uint32_t subpriority, bool external)
    1415                 :            : {
    1416                 :          0 :         uint16_t priority = (uint16_t)attr->priority;
    1417                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1418                 :            : 
    1419                 :            :         /* NIC root rules */
    1420   [ #  #  #  # ]:          0 :         if (!attr->group && !attr->transfer) {
    1421         [ #  # ]:          0 :                 if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
    1422                 :          0 :                         priority = priv->sh->flow_max_priority - 1;
    1423                 :          0 :                 return mlx5_os_flow_adjust_priority(dev, priority, subpriority);
    1424                 :            :         /* FDB root rules */
    1425   [ #  #  #  #  :          0 :         } else if (attr->transfer && (!external || !priv->fdb_def_rule) &&
             #  #  #  # ]
    1426         [ #  # ]:          0 :                    attr->group == 0 &&
    1427                 :            :                    attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR) {
    1428                 :          0 :                 return (priv->sh->flow_max_priority - 1) * 3;
    1429                 :            :         }
    1430         [ #  # ]:          0 :         if (attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)
    1431                 :            :                 priority = MLX5_NON_ROOT_FLOW_MAX_PRIO;
    1432                 :          0 :         return priority * 3 + subpriority;
    1433                 :            : }
    1434                 :            : 
    1435                 :            : /**
    1436                 :            :  * Verify the @p item specifications (spec, last, mask) are compatible with the
    1437                 :            :  * NIC capabilities.
    1438                 :            :  *
    1439                 :            :  * @param[in] item
    1440                 :            :  *   Item specification.
    1441                 :            :  * @param[in] mask
    1442                 :            :  *   @p item->mask or flow default bit-masks.
    1443                 :            :  * @param[in] nic_mask
    1444                 :            :  *   Bit-masks covering supported fields by the NIC to compare with user mask.
    1445                 :            :  * @param[in] size
    1446                 :            :  *   Bit-masks size in bytes.
    1447                 :            :  * @param[in] range_accepted
    1448                 :            :  *   True if range of values is accepted for specific fields, false otherwise.
    1449                 :            :  * @param[out] error
    1450                 :            :  *   Pointer to error structure.
    1451                 :            :  *
    1452                 :            :  * @return
    1453                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1454                 :            :  */
    1455                 :            : int
    1456                 :          0 : mlx5_flow_item_acceptable(const struct rte_flow_item *item,
    1457                 :            :                           const uint8_t *mask,
    1458                 :            :                           const uint8_t *nic_mask,
    1459                 :            :                           unsigned int size,
    1460                 :            :                           bool range_accepted,
    1461                 :            :                           struct rte_flow_error *error)
    1462                 :            : {
    1463                 :            :         unsigned int i;
    1464                 :            : 
    1465                 :            :         MLX5_ASSERT(nic_mask);
    1466         [ #  # ]:          0 :         for (i = 0; i < size; ++i)
    1467         [ #  # ]:          0 :                 if ((nic_mask[i] | mask[i]) != nic_mask[i])
    1468                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    1469                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    1470                 :            :                                                   item,
    1471                 :            :                                                   "mask enables non supported"
    1472                 :            :                                                   " bits");
    1473   [ #  #  #  #  :          0 :         if (!item->spec && (item->mask || item->last))
                   #  # ]
    1474                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1475                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    1476                 :            :                                           "mask/last without a spec is not"
    1477                 :            :                                           " supported");
    1478   [ #  #  #  #  :          0 :         if (item->spec && item->last && !range_accepted) {
                   #  # ]
    1479                 :          0 :                 uint8_t spec[size];
    1480                 :          0 :                 uint8_t last[size];
    1481                 :            :                 unsigned int i;
    1482                 :            :                 int ret;
    1483                 :            : 
    1484         [ #  # ]:          0 :                 for (i = 0; i < size; ++i) {
    1485                 :          0 :                         spec[i] = ((const uint8_t *)item->spec)[i] & mask[i];
    1486                 :          0 :                         last[i] = ((const uint8_t *)item->last)[i] & mask[i];
    1487                 :            :                 }
    1488                 :          0 :                 ret = memcmp(spec, last, size);
    1489         [ #  # ]:          0 :                 if (ret != 0)
    1490                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    1491                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    1492                 :            :                                                   item,
    1493                 :            :                                                   "range is not valid");
    1494                 :            :         }
    1495                 :            :         return 0;
    1496                 :            : }
    1497                 :            : 
    1498                 :            : /**
    1499                 :            :  * Adjust the hash fields according to the @p flow information.
    1500                 :            :  *
    1501                 :            :  * @param[in] dev_flow.
    1502                 :            :  *   Pointer to the mlx5_flow.
    1503                 :            :  * @param[in] tunnel
    1504                 :            :  *   1 when the hash field is for a tunnel item.
    1505                 :            :  * @param[in] layer_types
    1506                 :            :  *   RTE_ETH_RSS_* types.
    1507                 :            :  * @param[in] hash_fields
    1508                 :            :  *   Item hash fields.
    1509                 :            :  *
    1510                 :            :  * @return
    1511                 :            :  *   The hash fields that should be used.
    1512                 :            :  */
    1513                 :            : uint64_t
    1514                 :          0 : mlx5_flow_hashfields_adjust(struct mlx5_flow_rss_desc *rss_desc,
    1515                 :            :                             int tunnel __rte_unused, uint64_t layer_types,
    1516                 :            :                             uint64_t hash_fields)
    1517                 :            : {
    1518                 :            : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
    1519                 :          0 :         int rss_request_inner = rss_desc->level >= 2;
    1520                 :            : 
    1521                 :            :         /* Check RSS hash level for tunnel. */
    1522         [ #  # ]:          0 :         if (tunnel && rss_request_inner)
    1523                 :          0 :                 hash_fields |= IBV_RX_HASH_INNER;
    1524         [ #  # ]:          0 :         else if (tunnel || rss_request_inner)
    1525                 :            :                 return 0;
    1526                 :            : #endif
    1527                 :            :         /* Check if requested layer matches RSS hash fields. */
    1528         [ #  # ]:          0 :         if (!(rss_desc->types & layer_types))
    1529                 :          0 :                 return 0;
    1530                 :            :         return hash_fields;
    1531                 :            : }
    1532                 :            : 
    1533                 :            : /**
    1534                 :            :  * Lookup and set the ptype in the data Rx part.  A single Ptype can be used,
    1535                 :            :  * if several tunnel rules are used on this queue, the tunnel ptype will be
    1536                 :            :  * cleared.
    1537                 :            :  *
    1538                 :            :  * @param rxq_ctrl
    1539                 :            :  *   Rx queue to update.
    1540                 :            :  */
    1541                 :            : static void
    1542                 :            : flow_rxq_tunnel_ptype_update(struct mlx5_rxq_ctrl *rxq_ctrl)
    1543                 :            : {
    1544                 :            :         unsigned int i;
    1545                 :            :         uint32_t tunnel_ptype = 0;
    1546                 :            : 
    1547                 :            :         /* Look up for the ptype to use. */
    1548   [ #  #  #  # ]:          0 :         for (i = 0; i != MLX5_FLOW_TUNNEL; ++i) {
    1549   [ #  #  #  # ]:          0 :                 if (!rxq_ctrl->flow_tunnels_n[i])
    1550                 :          0 :                         continue;
    1551   [ #  #  #  # ]:          0 :                 if (!tunnel_ptype) {
    1552                 :          0 :                         tunnel_ptype = tunnels_info[i].ptype;
    1553                 :            :                 } else {
    1554                 :            :                         tunnel_ptype = 0;
    1555                 :            :                         break;
    1556                 :            :                 }
    1557                 :            :         }
    1558                 :          0 :         rxq_ctrl->rxq.tunnel = tunnel_ptype;
    1559                 :          0 : }
    1560                 :            : 
    1561                 :            : /**
    1562                 :            :  * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) according to the device
    1563                 :            :  * flow.
    1564                 :            :  *
    1565                 :            :  * @param[in] dev
    1566                 :            :  *   Pointer to the Ethernet device structure.
    1567                 :            :  * @param[in] dev_handle
    1568                 :            :  *   Pointer to device flow handle structure.
    1569                 :            :  */
    1570                 :            : void
    1571                 :          0 : flow_drv_rxq_flags_set(struct rte_eth_dev *dev,
    1572                 :            :                        struct mlx5_flow_handle *dev_handle)
    1573                 :            : {
    1574                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1575                 :          0 :         const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
    1576                 :            :         struct mlx5_ind_table_obj *ind_tbl = NULL;
    1577                 :            :         unsigned int i;
    1578                 :            : 
    1579         [ #  # ]:          0 :         if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
    1580                 :            :                 struct mlx5_hrxq *hrxq;
    1581                 :            : 
    1582                 :          0 :                 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
    1583                 :            :                               dev_handle->rix_hrxq);
    1584         [ #  # ]:          0 :                 if (hrxq)
    1585                 :          0 :                         ind_tbl = hrxq->ind_table;
    1586         [ #  # ]:          0 :         } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
    1587                 :            :                 struct mlx5_shared_action_rss *shared_rss;
    1588                 :            : 
    1589                 :          0 :                 shared_rss = mlx5_ipool_get
    1590                 :          0 :                         (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
    1591                 :            :                          dev_handle->rix_srss);
    1592         [ #  # ]:          0 :                 if (shared_rss)
    1593                 :          0 :                         ind_tbl = shared_rss->ind_tbl;
    1594                 :            :         }
    1595         [ #  # ]:          0 :         if (!ind_tbl)
    1596                 :          0 :                 return;
    1597         [ #  # ]:          0 :         for (i = 0; i != ind_tbl->queues_n; ++i) {
    1598         [ #  # ]:          0 :                 int idx = ind_tbl->queues[i];
    1599                 :            :                 struct mlx5_rxq_ctrl *rxq_ctrl;
    1600                 :            : 
    1601         [ #  # ]:          0 :                 if (mlx5_is_external_rxq(dev, idx))
    1602                 :          0 :                         continue;
    1603                 :          0 :                 rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
    1604                 :            :                 MLX5_ASSERT(rxq_ctrl != NULL);
    1605         [ #  # ]:          0 :                 if (rxq_ctrl == NULL)
    1606                 :          0 :                         continue;
    1607                 :            :                 /*
    1608                 :            :                  * To support metadata register copy on Tx loopback,
    1609                 :            :                  * this must be always enabled (metadata may arive
    1610                 :            :                  * from other port - not from local flows only.
    1611                 :            :                  */
    1612         [ #  # ]:          0 :                 if (tunnel) {
    1613                 :            :                         unsigned int j;
    1614                 :            : 
    1615                 :            :                         /* Increase the counter matching the flow. */
    1616         [ #  # ]:          0 :                         for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
    1617                 :          0 :                                 if ((tunnels_info[j].tunnel &
    1618         [ #  # ]:          0 :                                      dev_handle->layers) ==
    1619                 :            :                                     tunnels_info[j].tunnel) {
    1620                 :          0 :                                         rxq_ctrl->flow_tunnels_n[j]++;
    1621                 :          0 :                                         break;
    1622                 :            :                                 }
    1623                 :            :                         }
    1624                 :            :                         flow_rxq_tunnel_ptype_update(rxq_ctrl);
    1625                 :            :                 }
    1626                 :            :         }
    1627                 :            : }
    1628                 :            : 
    1629                 :            : static void
    1630                 :          0 : flow_rxq_mark_flag_set(struct rte_eth_dev *dev)
    1631                 :            : {
    1632                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1633                 :            :         struct mlx5_rxq_ctrl *rxq_ctrl;
    1634                 :            :         uint16_t port_id;
    1635                 :            : 
    1636         [ #  # ]:          0 :         if (priv->sh->shared_mark_enabled)
    1637                 :            :                 return;
    1638         [ #  # ]:          0 :         if (priv->master || priv->representor) {
    1639         [ #  # ]:          0 :                 MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
    1640                 :          0 :                         struct mlx5_priv *opriv =
    1641                 :          0 :                                 rte_eth_devices[port_id].data->dev_private;
    1642                 :            : 
    1643         [ #  # ]:          0 :                         if (!opriv ||
    1644         [ #  # ]:          0 :                             opriv->sh != priv->sh ||
    1645   [ #  #  #  # ]:          0 :                             opriv->domain_id != priv->domain_id ||
    1646                 :            :                             opriv->mark_enabled)
    1647                 :          0 :                                 continue;
    1648         [ #  # ]:          0 :                         LIST_FOREACH(rxq_ctrl, &opriv->rxqsctrl, next) {
    1649                 :          0 :                                 rxq_ctrl->rxq.mark = 1;
    1650                 :            :                         }
    1651                 :          0 :                         opriv->mark_enabled = 1;
    1652                 :            :                 }
    1653                 :            :         } else {
    1654         [ #  # ]:          0 :                 LIST_FOREACH(rxq_ctrl, &priv->rxqsctrl, next) {
    1655                 :          0 :                         rxq_ctrl->rxq.mark = 1;
    1656                 :            :                 }
    1657                 :          0 :                 priv->mark_enabled = 1;
    1658                 :            :         }
    1659                 :          0 :         priv->sh->shared_mark_enabled = 1;
    1660                 :            : }
    1661                 :            : 
    1662                 :            : /**
    1663                 :            :  * Set the Rx queue flags (Mark/Flag and Tunnel Ptypes) for a flow
    1664                 :            :  *
    1665                 :            :  * @param[in] dev
    1666                 :            :  *   Pointer to the Ethernet device structure.
    1667                 :            :  * @param[in] flow
    1668                 :            :  *   Pointer to flow structure.
    1669                 :            :  */
    1670                 :            : static void
    1671                 :          0 : flow_rxq_flags_set(struct rte_eth_dev *dev, struct rte_flow *flow)
    1672                 :            : {
    1673                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1674                 :            :         uint32_t handle_idx;
    1675                 :            :         struct mlx5_flow_handle *dev_handle;
    1676                 :          0 :         struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
    1677                 :            : 
    1678                 :            :         MLX5_ASSERT(wks);
    1679         [ #  # ]:          0 :         if (wks->mark)
    1680                 :          0 :                 flow_rxq_mark_flag_set(dev);
    1681   [ #  #  #  #  :          0 :         SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
                   #  # ]
    1682                 :            :                        handle_idx, dev_handle, next)
    1683                 :          0 :                 flow_drv_rxq_flags_set(dev, dev_handle);
    1684                 :          0 : }
    1685                 :            : 
    1686                 :            : /**
    1687                 :            :  * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
    1688                 :            :  * device flow if no other flow uses it with the same kind of request.
    1689                 :            :  *
    1690                 :            :  * @param dev
    1691                 :            :  *   Pointer to Ethernet device.
    1692                 :            :  * @param[in] dev_handle
    1693                 :            :  *   Pointer to the device flow handle structure.
    1694                 :            :  */
    1695                 :            : static void
    1696                 :          0 : flow_drv_rxq_flags_trim(struct rte_eth_dev *dev,
    1697                 :            :                         struct mlx5_flow_handle *dev_handle)
    1698                 :            : {
    1699                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1700                 :          0 :         const int tunnel = !!(dev_handle->layers & MLX5_FLOW_LAYER_TUNNEL);
    1701                 :            :         struct mlx5_ind_table_obj *ind_tbl = NULL;
    1702                 :            :         unsigned int i;
    1703                 :            : 
    1704         [ #  # ]:          0 :         if (dev_handle->fate_action == MLX5_FLOW_FATE_QUEUE) {
    1705                 :            :                 struct mlx5_hrxq *hrxq;
    1706                 :            : 
    1707                 :          0 :                 hrxq = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_HRXQ],
    1708                 :            :                               dev_handle->rix_hrxq);
    1709         [ #  # ]:          0 :                 if (hrxq)
    1710                 :          0 :                         ind_tbl = hrxq->ind_table;
    1711         [ #  # ]:          0 :         } else if (dev_handle->fate_action == MLX5_FLOW_FATE_SHARED_RSS) {
    1712                 :            :                 struct mlx5_shared_action_rss *shared_rss;
    1713                 :            : 
    1714                 :          0 :                 shared_rss = mlx5_ipool_get
    1715                 :          0 :                         (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
    1716                 :            :                          dev_handle->rix_srss);
    1717         [ #  # ]:          0 :                 if (shared_rss)
    1718                 :          0 :                         ind_tbl = shared_rss->ind_tbl;
    1719                 :            :         }
    1720         [ #  # ]:          0 :         if (!ind_tbl)
    1721                 :          0 :                 return;
    1722                 :            :         MLX5_ASSERT(dev->data->dev_started);
    1723         [ #  # ]:          0 :         for (i = 0; i != ind_tbl->queues_n; ++i) {
    1724         [ #  # ]:          0 :                 int idx = ind_tbl->queues[i];
    1725                 :            :                 struct mlx5_rxq_ctrl *rxq_ctrl;
    1726                 :            : 
    1727         [ #  # ]:          0 :                 if (mlx5_is_external_rxq(dev, idx))
    1728                 :          0 :                         continue;
    1729                 :          0 :                 rxq_ctrl = mlx5_rxq_ctrl_get(dev, idx);
    1730                 :            :                 MLX5_ASSERT(rxq_ctrl != NULL);
    1731         [ #  # ]:          0 :                 if (rxq_ctrl == NULL)
    1732                 :          0 :                         continue;
    1733         [ #  # ]:          0 :                 if (tunnel) {
    1734                 :            :                         unsigned int j;
    1735                 :            : 
    1736                 :            :                         /* Decrease the counter matching the flow. */
    1737         [ #  # ]:          0 :                         for (j = 0; j != MLX5_FLOW_TUNNEL; ++j) {
    1738                 :          0 :                                 if ((tunnels_info[j].tunnel &
    1739         [ #  # ]:          0 :                                      dev_handle->layers) ==
    1740                 :            :                                     tunnels_info[j].tunnel) {
    1741                 :          0 :                                         rxq_ctrl->flow_tunnels_n[j]--;
    1742                 :          0 :                                         break;
    1743                 :            :                                 }
    1744                 :            :                         }
    1745                 :            :                         flow_rxq_tunnel_ptype_update(rxq_ctrl);
    1746                 :            :                 }
    1747                 :            :         }
    1748                 :            : }
    1749                 :            : 
    1750                 :            : /**
    1751                 :            :  * Clear the Rx queue flags (Mark/Flag and Tunnel Ptype) associated with the
    1752                 :            :  * @p flow if no other flow uses it with the same kind of request.
    1753                 :            :  *
    1754                 :            :  * @param dev
    1755                 :            :  *   Pointer to Ethernet device.
    1756                 :            :  * @param[in] flow
    1757                 :            :  *   Pointer to the flow.
    1758                 :            :  */
    1759                 :            : static void
    1760                 :          0 : flow_rxq_flags_trim(struct rte_eth_dev *dev, struct rte_flow *flow)
    1761                 :            : {
    1762                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1763                 :            :         uint32_t handle_idx;
    1764                 :            :         struct mlx5_flow_handle *dev_handle;
    1765                 :            : 
    1766   [ #  #  #  #  :          0 :         SILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW], flow->dev_handles,
                   #  # ]
    1767                 :            :                        handle_idx, dev_handle, next)
    1768                 :          0 :                 flow_drv_rxq_flags_trim(dev, dev_handle);
    1769                 :          0 : }
    1770                 :            : 
    1771                 :            : /**
    1772                 :            :  * Clear the Mark/Flag and Tunnel ptype information in all Rx queues.
    1773                 :            :  *
    1774                 :            :  * @param dev
    1775                 :            :  *   Pointer to Ethernet device.
    1776                 :            :  */
    1777                 :            : static void
    1778                 :          0 : flow_rxq_flags_clear(struct rte_eth_dev *dev)
    1779                 :            : {
    1780                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1781                 :            :         unsigned int i;
    1782                 :            : 
    1783         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1784                 :          0 :                 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
    1785                 :            :                 unsigned int j;
    1786                 :            : 
    1787   [ #  #  #  # ]:          0 :                 if (rxq == NULL || rxq->ctrl == NULL)
    1788                 :          0 :                         continue;
    1789                 :          0 :                 rxq->ctrl->rxq.mark = 0;
    1790         [ #  # ]:          0 :                 for (j = 0; j != MLX5_FLOW_TUNNEL; ++j)
    1791                 :          0 :                         rxq->ctrl->flow_tunnels_n[j] = 0;
    1792                 :          0 :                 rxq->ctrl->rxq.tunnel = 0;
    1793                 :            :         }
    1794                 :          0 :         priv->mark_enabled = 0;
    1795                 :          0 :         priv->sh->shared_mark_enabled = 0;
    1796                 :          0 : }
    1797                 :            : 
    1798                 :            : static uint64_t mlx5_restore_info_dynflag;
    1799                 :            : 
    1800                 :            : int
    1801                 :          0 : mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
    1802                 :            : {
    1803         [ #  # ]:          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1804                 :            :         uint64_t supported = 0;
    1805                 :            : 
    1806         [ #  # ]:          0 :         if (!is_tunnel_offload_active(dev)) {
    1807                 :            :                 supported |= RTE_ETH_RX_METADATA_USER_FLAG;
    1808                 :            :                 supported |= RTE_ETH_RX_METADATA_USER_MARK;
    1809         [ #  # ]:          0 :                 if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0) {
    1810                 :          0 :                         DRV_LOG(DEBUG,
    1811                 :            :                                 "tunnel offload was not activated, consider setting dv_xmeta_en=%d",
    1812                 :            :                                 MLX5_XMETA_MODE_MISS_INFO);
    1813                 :            :                 }
    1814                 :            :         } else {
    1815                 :            :                 supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
    1816         [ #  # ]:          0 :                 if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
    1817         [ #  # ]:          0 :                                 mlx5_restore_info_dynflag == 0)
    1818                 :          0 :                         mlx5_restore_info_dynflag = rte_flow_restore_info_dynflag();
    1819                 :            :         }
    1820                 :            : 
    1821         [ #  # ]:          0 :         if (((*features & supported) & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0)
    1822                 :          0 :                 priv->tunnel_enabled = 1;
    1823                 :            :         else
    1824                 :          0 :                 priv->tunnel_enabled = 0;
    1825                 :            : 
    1826                 :          0 :         *features &= supported;
    1827                 :          0 :         return 0;
    1828                 :            : }
    1829                 :            : 
    1830                 :            : /**
    1831                 :            :  * Set the Rx queue dynamic metadata (mask and offset) for a flow
    1832                 :            :  *
    1833                 :            :  * @param[in] dev
    1834                 :            :  *   Pointer to the Ethernet device structure.
    1835                 :            :  */
    1836                 :            : void
    1837                 :          0 : mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev)
    1838                 :            : {
    1839                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1840                 :            :         uint64_t mark_flag = RTE_MBUF_F_RX_FDIR_ID;
    1841                 :            :         unsigned int i;
    1842                 :            : 
    1843         [ #  # ]:          0 :         if (priv->tunnel_enabled)
    1844                 :          0 :                 mark_flag |= mlx5_restore_info_dynflag;
    1845                 :            : 
    1846         [ #  # ]:          0 :         for (i = 0; i != priv->rxqs_n; ++i) {
    1847                 :          0 :                 struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
    1848                 :            :                 struct mlx5_rxq_data *data;
    1849                 :            : 
    1850   [ #  #  #  # ]:          0 :                 if (rxq == NULL || rxq->ctrl == NULL)
    1851                 :          0 :                         continue;
    1852                 :            :                 data = &rxq->ctrl->rxq;
    1853         [ #  # ]:          0 :                 if (!rte_flow_dynf_metadata_avail()) {
    1854                 :          0 :                         data->dynf_meta = 0;
    1855                 :          0 :                         data->flow_meta_mask = 0;
    1856                 :          0 :                         data->flow_meta_offset = -1;
    1857                 :          0 :                         data->flow_meta_port_mask = 0;
    1858                 :            :                 } else {
    1859                 :          0 :                         data->dynf_meta = 1;
    1860                 :          0 :                         data->flow_meta_mask = rte_flow_dynf_metadata_mask;
    1861                 :          0 :                         data->flow_meta_offset = rte_flow_dynf_metadata_offs;
    1862                 :          0 :                         data->flow_meta_port_mask = priv->sh->dv_meta_mask;
    1863                 :            :                 }
    1864                 :          0 :                 data->mark_flag = mark_flag;
    1865                 :            :         }
    1866                 :          0 : }
    1867                 :            : 
    1868                 :            : /*
    1869                 :            :  * return a pointer to the desired action in the list of actions.
    1870                 :            :  *
    1871                 :            :  * @param[in] actions
    1872                 :            :  *   The list of actions to search the action in.
    1873                 :            :  * @param[in] action
    1874                 :            :  *   The action to find.
    1875                 :            :  *
    1876                 :            :  * @return
    1877                 :            :  *   Pointer to the action in the list, if found. NULL otherwise.
    1878                 :            :  */
    1879                 :            : const struct rte_flow_action *
    1880                 :          0 : mlx5_flow_find_action(const struct rte_flow_action *actions,
    1881                 :            :                       enum rte_flow_action_type action)
    1882                 :            : {
    1883         [ #  # ]:          0 :         if (actions == NULL)
    1884                 :            :                 return NULL;
    1885         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++)
    1886         [ #  # ]:          0 :                 if (actions->type == action)
    1887                 :          0 :                         return actions;
    1888                 :            :         return NULL;
    1889                 :            : }
    1890                 :            : 
    1891                 :            : /*
    1892                 :            :  * Validate the flag action.
    1893                 :            :  *
    1894                 :            :  * @param[in] action_flags
    1895                 :            :  *   Bit-fields that holds the actions detected until now.
    1896                 :            :  * @param[in] attr
    1897                 :            :  *   Attributes of flow that includes this action.
    1898                 :            :  * @param[out] error
    1899                 :            :  *   Pointer to error structure.
    1900                 :            :  *
    1901                 :            :  * @return
    1902                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1903                 :            :  */
    1904                 :            : int
    1905                 :          0 : mlx5_flow_validate_action_flag(uint64_t action_flags,
    1906                 :            :                                const struct rte_flow_attr *attr,
    1907                 :            :                                struct rte_flow_error *error)
    1908                 :            : {
    1909         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_ACTION_MARK)
    1910                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1911                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    1912                 :            :                                           "can't mark and flag in same flow");
    1913         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_ACTION_FLAG)
    1914                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1915                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    1916                 :            :                                           "can't have 2 flag"
    1917                 :            :                                           " actions in same flow");
    1918         [ #  # ]:          0 :         if (attr->egress)
    1919                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    1920                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    1921                 :            :                                           "flag action not supported for "
    1922                 :            :                                           "egress");
    1923                 :            :         return 0;
    1924                 :            : }
    1925                 :            : 
    1926                 :            : /*
    1927                 :            :  * Validate the mark action.
    1928                 :            :  *
    1929                 :            :  * @param[in] action
    1930                 :            :  *   Pointer to the queue action.
    1931                 :            :  * @param[in] action_flags
    1932                 :            :  *   Bit-fields that holds the actions detected until now.
    1933                 :            :  * @param[in] attr
    1934                 :            :  *   Attributes of flow that includes this action.
    1935                 :            :  * @param[out] error
    1936                 :            :  *   Pointer to error structure.
    1937                 :            :  *
    1938                 :            :  * @return
    1939                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1940                 :            :  */
    1941                 :            : int
    1942                 :          0 : mlx5_flow_validate_action_mark(const struct rte_flow_action *action,
    1943                 :            :                                uint64_t action_flags,
    1944                 :            :                                const struct rte_flow_attr *attr,
    1945                 :            :                                struct rte_flow_error *error)
    1946                 :            : {
    1947                 :          0 :         const struct rte_flow_action_mark *mark = action->conf;
    1948                 :            : 
    1949         [ #  # ]:          0 :         if (!mark)
    1950                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1951                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
    1952                 :            :                                           action,
    1953                 :            :                                           "configuration cannot be null");
    1954         [ #  # ]:          0 :         if (mark->id >= MLX5_FLOW_MARK_MAX)
    1955                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1956                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    1957                 :          0 :                                           &mark->id,
    1958                 :            :                                           "mark id must in 0 <= id < "
    1959                 :            :                                           RTE_STR(MLX5_FLOW_MARK_MAX));
    1960         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_ACTION_FLAG)
    1961                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1962                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    1963                 :            :                                           "can't flag and mark in same flow");
    1964         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_ACTION_MARK)
    1965                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    1966                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    1967                 :            :                                           "can't have 2 mark actions in same"
    1968                 :            :                                           " flow");
    1969         [ #  # ]:          0 :         if (attr->egress)
    1970                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    1971                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    1972                 :            :                                           "mark action not supported for "
    1973                 :            :                                           "egress");
    1974                 :            :         return 0;
    1975                 :            : }
    1976                 :            : 
    1977                 :            : /*
    1978                 :            :  * Validate the drop action.
    1979                 :            :  *
    1980                 :            :  * @param[in] dev
    1981                 :            :  *   Pointer to the Ethernet device structure.
    1982                 :            :  * @param[in] is_root
    1983                 :            :  *   True if flow is validated for root table. False otherwise.
    1984                 :            :  * @param[in] attr
    1985                 :            :  *   Attributes of flow that includes this action.
    1986                 :            :  * @param[out] error
    1987                 :            :  *   Pointer to error structure.
    1988                 :            :  *
    1989                 :            :  * @return
    1990                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    1991                 :            :  */
    1992                 :            : int
    1993                 :          0 : mlx5_flow_validate_action_drop(struct rte_eth_dev *dev,
    1994                 :            :                                bool is_root,
    1995                 :            :                                const struct rte_flow_attr *attr,
    1996                 :            :                                struct rte_flow_error *error)
    1997                 :            : {
    1998                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    1999                 :            : 
    2000   [ #  #  #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 0 && attr->egress)
    2001                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2002                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    2003                 :            :                                           "drop action not supported for "
    2004                 :            :                                           "egress");
    2005   [ #  #  #  #  :          0 :         if (priv->sh->config.dv_flow_en == 1 && is_root && (attr->egress || attr->transfer) &&
                   #  # ]
    2006         [ #  # ]:          0 :             !priv->sh->dr_root_drop_action_en) {
    2007                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2008                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR, NULL,
    2009                 :            :                                           "drop action not supported for "
    2010                 :            :                                           "egress and transfer on group 0");
    2011                 :            :         }
    2012                 :            :         return 0;
    2013                 :            : }
    2014                 :            : 
    2015                 :            : /*
    2016                 :            :  * Validate the queue action.
    2017                 :            :  *
    2018                 :            :  * @param[in] action
    2019                 :            :  *   Pointer to the queue action.
    2020                 :            :  * @param[in] action_flags
    2021                 :            :  *   Bit-fields that holds the actions detected until now.
    2022                 :            :  * @param[in] dev
    2023                 :            :  *   Pointer to the Ethernet device structure.
    2024                 :            :  * @param[in] attr
    2025                 :            :  *   Attributes of flow that includes this action.
    2026                 :            :  * @param[out] error
    2027                 :            :  *   Pointer to error structure.
    2028                 :            :  *
    2029                 :            :  * @return
    2030                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2031                 :            :  */
    2032                 :            : int
    2033                 :          0 : mlx5_flow_validate_action_queue(const struct rte_flow_action *action,
    2034                 :            :                                 uint64_t action_flags,
    2035                 :            :                                 struct rte_eth_dev *dev,
    2036                 :            :                                 const struct rte_flow_attr *attr,
    2037                 :            :                                 struct rte_flow_error *error)
    2038                 :            : {
    2039                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2040                 :          0 :         const struct rte_flow_action_queue *queue = action->conf;
    2041                 :            : 
    2042         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_FATE_ACTIONS)
    2043                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2044                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2045                 :            :                                           "can't have 2 fate actions in"
    2046                 :            :                                           " same flow");
    2047         [ #  # ]:          0 :         if (attr->egress)
    2048                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2049                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    2050                 :            :                                           "queue action not supported for egress.");
    2051   [ #  #  #  # ]:          0 :         if (mlx5_is_external_rxq(dev, queue->index))
    2052                 :            :                 return 0;
    2053         [ #  # ]:          0 :         if (!priv->rxqs_n)
    2054                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2055                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2056                 :            :                                           NULL, "No Rx queues configured");
    2057         [ #  # ]:          0 :         if (queue->index >= priv->rxqs_n)
    2058                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2059                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2060                 :          0 :                                           &queue->index,
    2061                 :            :                                           "queue index out of range");
    2062         [ #  # ]:          0 :         if (mlx5_rxq_get(dev, queue->index) == NULL)
    2063                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2064                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2065                 :          0 :                                           &queue->index,
    2066                 :            :                                           "queue is not configured");
    2067                 :            :         return 0;
    2068                 :            : }
    2069                 :            : 
    2070                 :            : /**
    2071                 :            :  * Validate queue numbers for device RSS.
    2072                 :            :  *
    2073                 :            :  * @param[in] dev
    2074                 :            :  *   Configured device.
    2075                 :            :  * @param[in] queues
    2076                 :            :  *   Array of queue numbers.
    2077                 :            :  * @param[in] queues_n
    2078                 :            :  *   Size of the @p queues array.
    2079                 :            :  * @param[out] error
    2080                 :            :  *   On error, filled with a textual error description.
    2081                 :            :  * @param[out] queue_idx
    2082                 :            :  *   On error, filled with an offending queue index in @p queues array.
    2083                 :            :  *
    2084                 :            :  * @return
    2085                 :            :  *   0 on success, a negative errno code on error.
    2086                 :            :  */
    2087                 :            : static int
    2088                 :          0 : mlx5_validate_rss_queues(struct rte_eth_dev *dev,
    2089                 :            :                          const uint16_t *queues, uint32_t queues_n,
    2090                 :            :                          const char **error, uint32_t *queue_idx)
    2091                 :            : {
    2092                 :          0 :         const struct mlx5_priv *priv = dev->data->dev_private;
    2093                 :            :         bool is_hairpin = false;
    2094                 :            :         bool is_ext_rss = false;
    2095                 :            :         uint32_t i;
    2096                 :            : 
    2097         [ #  # ]:          0 :         for (i = 0; i != queues_n; ++i) {
    2098                 :            :                 struct mlx5_rxq_ctrl *rxq_ctrl;
    2099                 :            : 
    2100   [ #  #  #  # ]:          0 :                 if (mlx5_is_external_rxq(dev, queues[0])) {
    2101                 :            :                         is_ext_rss = true;
    2102                 :          0 :                         continue;
    2103                 :            :                 }
    2104         [ #  # ]:          0 :                 if (is_ext_rss) {
    2105                 :          0 :                         *error = "Combining external and regular RSS queues is not supported";
    2106                 :          0 :                         *queue_idx = i;
    2107                 :          0 :                         return -ENOTSUP;
    2108                 :            :                 }
    2109         [ #  # ]:          0 :                 if (queues[i] >= priv->rxqs_n) {
    2110                 :          0 :                         *error = "queue index out of range";
    2111                 :          0 :                         *queue_idx = i;
    2112                 :          0 :                         return -EINVAL;
    2113                 :            :                 }
    2114                 :          0 :                 rxq_ctrl = mlx5_rxq_ctrl_get(dev, queues[i]);
    2115         [ #  # ]:          0 :                 if (rxq_ctrl == NULL) {
    2116                 :          0 :                         *error =  "queue is not configured";
    2117                 :          0 :                         *queue_idx = i;
    2118                 :          0 :                         return -EINVAL;
    2119                 :            :                 }
    2120   [ #  #  #  # ]:          0 :                 if (i == 0 && rxq_ctrl->is_hairpin)
    2121                 :            :                         is_hairpin = true;
    2122         [ #  # ]:          0 :                 if (is_hairpin != rxq_ctrl->is_hairpin) {
    2123                 :          0 :                         *error = "combining hairpin and regular RSS queues is not supported";
    2124                 :          0 :                         *queue_idx = i;
    2125                 :          0 :                         return -ENOTSUP;
    2126                 :            :                 }
    2127                 :            :         }
    2128                 :            :         return 0;
    2129                 :            : }
    2130                 :            : 
    2131                 :            : /*
    2132                 :            :  * Validate the rss action.
    2133                 :            :  *
    2134                 :            :  * @param[in] dev
    2135                 :            :  *   Pointer to the Ethernet device structure.
    2136                 :            :  * @param[in] action
    2137                 :            :  *   Pointer to the queue action.
    2138                 :            :  * @param[out] error
    2139                 :            :  *   Pointer to error structure.
    2140                 :            :  *
    2141                 :            :  * @return
    2142                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2143                 :            :  */
    2144                 :            : int
    2145                 :          0 : mlx5_validate_action_rss(struct rte_eth_dev *dev,
    2146                 :            :                          const struct rte_flow_action *action,
    2147                 :            :                          struct rte_flow_error *error)
    2148                 :            : {
    2149                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    2150                 :          0 :         const struct rte_flow_action_rss *rss = action->conf;
    2151                 :            :         int ret;
    2152                 :            :         const char *message;
    2153                 :            :         uint32_t queue_idx;
    2154                 :            : 
    2155         [ #  # ]:          0 :         if (rss->func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
    2156                 :          0 :                 DRV_LOG(WARNING, "port %u symmetric RSS supported with SORT",
    2157                 :            :                         dev->data->port_id);
    2158         [ #  # ]:          0 :         } else if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT &&
    2159                 :            :                    rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ)
    2160                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2161                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2162                 :          0 :                                           &rss->func,
    2163                 :            :                                           "RSS hash function not supported");
    2164                 :            : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
    2165         [ #  # ]:          0 :         if (rss->level > 2)
    2166                 :            : #else
    2167                 :            :         if (rss->level > 1)
    2168                 :            : #endif
    2169                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2170                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2171                 :          0 :                                           &rss->level,
    2172                 :            :                                           "tunnel RSS is not supported");
    2173                 :            :         /* allow RSS key_len 0 in case of NULL (default) RSS key. */
    2174   [ #  #  #  # ]:          0 :         if (rss->key_len == 0 && rss->key != NULL)
    2175                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2176                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2177                 :          0 :                                           &rss->key_len,
    2178                 :            :                                           "RSS hash key length 0");
    2179         [ #  # ]:          0 :         if (rss->key_len > 0 && rss->key_len < MLX5_RSS_HASH_KEY_LEN)
    2180                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2181                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2182                 :          0 :                                           &rss->key_len,
    2183                 :            :                                           "RSS hash key too small");
    2184         [ #  # ]:          0 :         if (rss->key_len > MLX5_RSS_HASH_KEY_LEN)
    2185                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2186                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2187                 :          0 :                                           &rss->key_len,
    2188                 :            :                                           "RSS hash key too large");
    2189         [ #  # ]:          0 :         if (rss->queue_num > priv->sh->dev_cap.ind_table_max_size)
    2190                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2191                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2192                 :          0 :                                           &rss->queue_num,
    2193                 :            :                                           "number of queues too large");
    2194         [ #  # ]:          0 :         if (rss->types & MLX5_RSS_HF_MASK)
    2195                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2196                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2197                 :          0 :                                           &rss->types,
    2198                 :            :                                           "some RSS protocols are not"
    2199                 :            :                                           " supported");
    2200         [ #  # ]:          0 :         if ((rss->types & (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY)) &&
    2201         [ #  # ]:          0 :             !(rss->types & RTE_ETH_RSS_IP))
    2202                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2203                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
    2204                 :            :                                           "L3 partial RSS requested but L3 RSS"
    2205                 :            :                                           " type not specified");
    2206         [ #  # ]:          0 :         if ((rss->types & (RTE_ETH_RSS_L4_SRC_ONLY | RTE_ETH_RSS_L4_DST_ONLY)) &&
    2207         [ #  # ]:          0 :             !(rss->types & (RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP)))
    2208                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2209                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
    2210                 :            :                                           "L4 partial RSS requested but L4 RSS"
    2211                 :            :                                           " type not specified");
    2212   [ #  #  #  # ]:          0 :         if (!priv->rxqs_n && priv->ext_rxqs == NULL)
    2213                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2214                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2215                 :            :                                           NULL, "No Rx queues configured");
    2216         [ #  # ]:          0 :         if (!rss->queue_num)
    2217                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2218                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2219                 :            :                                           NULL, "No queues configured");
    2220                 :          0 :         ret = mlx5_validate_rss_queues(dev, rss->queue, rss->queue_num,
    2221                 :            :                                        &message, &queue_idx);
    2222         [ #  # ]:          0 :         if (ret != 0) {
    2223                 :          0 :                 return rte_flow_error_set(error, -ret,
    2224                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
    2225                 :          0 :                                           &rss->queue[queue_idx], message);
    2226                 :            :         }
    2227                 :            :         return 0;
    2228                 :            : }
    2229                 :            : 
    2230                 :            : /*
    2231                 :            :  * Validate the rss action.
    2232                 :            :  *
    2233                 :            :  * @param[in] action
    2234                 :            :  *   Pointer to the queue action.
    2235                 :            :  * @param[in] action_flags
    2236                 :            :  *   Bit-fields that holds the actions detected until now.
    2237                 :            :  * @param[in] dev
    2238                 :            :  *   Pointer to the Ethernet device structure.
    2239                 :            :  * @param[in] attr
    2240                 :            :  *   Attributes of flow that includes this action.
    2241                 :            :  * @param[in] item_flags
    2242                 :            :  *   Items that were detected.
    2243                 :            :  * @param[out] error
    2244                 :            :  *   Pointer to error structure.
    2245                 :            :  *
    2246                 :            :  * @return
    2247                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2248                 :            :  */
    2249                 :            : int
    2250                 :          0 : mlx5_flow_validate_action_rss(const struct rte_flow_action *action,
    2251                 :            :                               uint64_t action_flags,
    2252                 :            :                               struct rte_eth_dev *dev,
    2253                 :            :                               const struct rte_flow_attr *attr,
    2254                 :            :                               uint64_t item_flags,
    2255                 :            :                               struct rte_flow_error *error)
    2256                 :            : {
    2257                 :          0 :         const struct rte_flow_action_rss *rss = action->conf;
    2258                 :          0 :         int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2259                 :            :         int ret;
    2260                 :            : 
    2261         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_FATE_ACTIONS)
    2262                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2263                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2264                 :            :                                           "can't have 2 fate actions"
    2265                 :            :                                           " in same flow");
    2266                 :          0 :         ret = mlx5_validate_action_rss(dev, action, error);
    2267         [ #  # ]:          0 :         if (ret)
    2268                 :            :                 return ret;
    2269         [ #  # ]:          0 :         if (attr->egress)
    2270                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2271                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    2272                 :            :                                           "rss action not supported for "
    2273                 :            :                                           "egress");
    2274   [ #  #  #  # ]:          0 :         if (rss->level > 1 && !tunnel)
    2275                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2276                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
    2277                 :            :                                           "inner RSS is not supported for "
    2278                 :            :                                           "non-tunnel flows");
    2279         [ #  # ]:          0 :         if ((item_flags & MLX5_FLOW_LAYER_ECPRI) &&
    2280                 :            :             !(item_flags & MLX5_FLOW_LAYER_INNER_L4_UDP)) {
    2281                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2282                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
    2283                 :            :                                           "RSS on eCPRI is not supported now");
    2284                 :            :         }
    2285         [ #  # ]:          0 :         if ((item_flags & MLX5_FLOW_LAYER_MPLS) &&
    2286                 :            :             !(item_flags &
    2287         [ #  # ]:          0 :               (MLX5_FLOW_LAYER_INNER_L2 | MLX5_FLOW_LAYER_INNER_L3)) &&
    2288                 :            :             rss->level > 1)
    2289                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2290                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, NULL,
    2291                 :            :                                           "MPLS inner RSS needs to specify inner L2/L3 items after MPLS in pattern");
    2292                 :            :         return 0;
    2293                 :            : }
    2294                 :            : 
    2295                 :            : /*
    2296                 :            :  * Validate the default miss action.
    2297                 :            :  *
    2298                 :            :  * @param[in] action_flags
    2299                 :            :  *   Bit-fields that holds the actions detected until now.
    2300                 :            :  * @param[out] error
    2301                 :            :  *   Pointer to error structure.
    2302                 :            :  *
    2303                 :            :  * @return
    2304                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2305                 :            :  */
    2306                 :            : int
    2307                 :          0 : mlx5_flow_validate_action_default_miss(uint64_t action_flags,
    2308                 :            :                                 const struct rte_flow_attr *attr,
    2309                 :            :                                 struct rte_flow_error *error)
    2310                 :            : {
    2311         [ #  # ]:          0 :         if (action_flags & MLX5_FLOW_FATE_ACTIONS)
    2312                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2313                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2314                 :            :                                           "can't have 2 fate actions in"
    2315                 :            :                                           " same flow");
    2316         [ #  # ]:          0 :         if (attr->egress)
    2317                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2318                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    2319                 :            :                                           "default miss action not supported "
    2320                 :            :                                           "for egress");
    2321         [ #  # ]:          0 :         if (attr->group)
    2322                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2323                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_GROUP, NULL,
    2324                 :            :                                           "only group 0 is supported");
    2325         [ #  # ]:          0 :         if (attr->transfer)
    2326                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2327                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
    2328                 :            :                                           NULL, "transfer is not supported");
    2329                 :            :         return 0;
    2330                 :            : }
    2331                 :            : 
    2332                 :            : /*
    2333                 :            :  * Validate the count action.
    2334                 :            :  *
    2335                 :            :  * @param[in] dev
    2336                 :            :  *   Pointer to the Ethernet device structure.
    2337                 :            :  * @param[in] attr
    2338                 :            :  *   Attributes of flow that includes this action.
    2339                 :            :  * @param[out] error
    2340                 :            :  *   Pointer to error structure.
    2341                 :            :  *
    2342                 :            :  * @return
    2343                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2344                 :            :  */
    2345                 :            : int
    2346                 :          0 : mlx5_flow_validate_action_count(struct rte_eth_dev *dev __rte_unused,
    2347                 :            :                                 const struct rte_flow_attr *attr,
    2348                 :            :                                 struct rte_flow_error *error)
    2349                 :            : {
    2350         [ #  # ]:          0 :         if (attr->egress)
    2351                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2352                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, NULL,
    2353                 :            :                                           "count action not supported for "
    2354                 :            :                                           "egress");
    2355                 :            :         return 0;
    2356                 :            : }
    2357                 :            : 
    2358                 :            : /*
    2359                 :            :  * Validate the ASO CT action.
    2360                 :            :  *
    2361                 :            :  * @param[in] dev
    2362                 :            :  *   Pointer to the Ethernet device structure.
    2363                 :            :  * @param[in] conntrack
    2364                 :            :  *   Pointer to the CT action profile.
    2365                 :            :  * @param[out] error
    2366                 :            :  *   Pointer to error structure.
    2367                 :            :  *
    2368                 :            :  * @return
    2369                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2370                 :            :  */
    2371                 :            : int
    2372                 :          0 : mlx5_validate_action_ct(struct rte_eth_dev *dev,
    2373                 :            :                         const struct rte_flow_action_conntrack *conntrack,
    2374                 :            :                         struct rte_flow_error *error)
    2375                 :            : {
    2376                 :            :         RTE_SET_USED(dev);
    2377                 :            : 
    2378         [ #  # ]:          0 :         if (conntrack->state > RTE_FLOW_CONNTRACK_STATE_TIME_WAIT)
    2379                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2380                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2381                 :            :                                           "Invalid CT state");
    2382         [ #  # ]:          0 :         if (conntrack->last_index > RTE_FLOW_CONNTRACK_FLAG_RST)
    2383                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2384                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2385                 :            :                                           "Invalid last TCP packet flag");
    2386                 :            :         return 0;
    2387                 :            : }
    2388                 :            : 
    2389                 :            : /**
    2390                 :            :  * Validate the level value for modify field action.
    2391                 :            :  *
    2392                 :            :  * @param[in] data
    2393                 :            :  *   Pointer to the rte_flow_field_data structure either src or dst.
    2394                 :            :  * @param[out] error
    2395                 :            :  *   Pointer to error structure.
    2396                 :            :  *
    2397                 :            :  * @return
    2398                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2399                 :            :  */
    2400                 :            : int
    2401                 :          0 : flow_validate_modify_field_level(const struct rte_flow_field_data *data,
    2402                 :            :                                  struct rte_flow_error *error)
    2403                 :            : {
    2404   [ #  #  #  # ]:          0 :         if (data->level == 0 || data->field == RTE_FLOW_FIELD_FLEX_ITEM)
    2405                 :            :                 return 0;
    2406         [ #  # ]:          0 :         if (data->field != RTE_FLOW_FIELD_TAG &&
    2407                 :            :             data->field != (enum rte_flow_field_id)MLX5_RTE_FLOW_FIELD_META_REG) {
    2408         [ #  # ]:          0 :                 if (data->level > 1)
    2409                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    2410                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    2411                 :            :                                                   NULL,
    2412                 :            :                                                   "inner header fields modification is not supported");
    2413                 :            :                 return 0;
    2414                 :            :         }
    2415         [ #  # ]:          0 :         if (data->tag_index != 0)
    2416                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2417                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    2418                 :            :                                           "tag array can be provided using 'level' or 'tag_index' fields, not both");
    2419                 :            :         /*
    2420                 :            :          * The tag array for RTE_FLOW_FIELD_TAG type is provided using
    2421                 :            :          * 'tag_index' field. In old API, it was provided using 'level' field
    2422                 :            :          * and it is still supported for backwards compatibility.
    2423                 :            :          */
    2424                 :          0 :         DRV_LOG(DEBUG, "tag array provided in 'level' field instead of 'tag_index' field.");
    2425                 :          0 :         return 0;
    2426                 :            : }
    2427                 :            : 
    2428                 :            : /**
    2429                 :            :  * Validate ICMP6 item.
    2430                 :            :  *
    2431                 :            :  * @param[in] item
    2432                 :            :  *   Item specification.
    2433                 :            :  * @param[in] item_flags
    2434                 :            :  *   Bit-fields that holds the items detected until now.
    2435                 :            :  * @param[in] ext_vlan_sup
    2436                 :            :  *   Whether extended VLAN features are supported or not.
    2437                 :            :  * @param[out] error
    2438                 :            :  *   Pointer to error structure.
    2439                 :            :  *
    2440                 :            :  * @return
    2441                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2442                 :            :  */
    2443                 :            : int
    2444                 :          0 : mlx5_flow_validate_item_icmp6(const struct rte_flow_item *item,
    2445                 :            :                                uint64_t item_flags,
    2446                 :            :                                uint8_t target_protocol,
    2447                 :            :                                struct rte_flow_error *error)
    2448                 :            : {
    2449                 :          0 :         const struct rte_flow_item_icmp6 *mask = item->mask;
    2450                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2451         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
    2452                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3_IPV6;
    2453         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2454                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2455                 :            :         int ret;
    2456                 :            : 
    2457         [ #  # ]:          0 :         if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
    2458                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2459                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2460                 :            :                                           "protocol filtering not compatible"
    2461                 :            :                                           " with ICMP6 layer");
    2462         [ #  # ]:          0 :         if (!(item_flags & l3m))
    2463                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2464                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2465                 :            :                                           "IPv6 is mandatory to filter on"
    2466                 :            :                                           " ICMP6");
    2467         [ #  # ]:          0 :         if (item_flags & l4m)
    2468                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2469                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2470                 :            :                                           "multiple L4 layers not supported");
    2471         [ #  # ]:          0 :         if (!mask)
    2472                 :            :                 mask = &rte_flow_item_icmp6_mask;
    2473                 :          0 :         ret = mlx5_flow_item_acceptable
    2474                 :            :                 (item, (const uint8_t *)mask,
    2475                 :            :                  (const uint8_t *)&rte_flow_item_icmp6_mask,
    2476                 :            :                  sizeof(struct rte_flow_item_icmp6),
    2477                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2478                 :            :         if (ret < 0)
    2479                 :            :                 return ret;
    2480                 :            :         return 0;
    2481                 :            : }
    2482                 :            : 
    2483                 :            : /**
    2484                 :            :  * Validate ICMP6 echo request/reply item.
    2485                 :            :  *
    2486                 :            :  * @param[in] item
    2487                 :            :  *   Item specification.
    2488                 :            :  * @param[in] item_flags
    2489                 :            :  *   Bit-fields that holds the items detected until now.
    2490                 :            :  * @param[in] ext_vlan_sup
    2491                 :            :  *   Whether extended VLAN features are supported or not.
    2492                 :            :  * @param[out] error
    2493                 :            :  *   Pointer to error structure.
    2494                 :            :  *
    2495                 :            :  * @return
    2496                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2497                 :            :  */
    2498                 :            : int
    2499                 :          0 : mlx5_flow_validate_item_icmp6_echo(const struct rte_flow_item *item,
    2500                 :            :                                    uint64_t item_flags,
    2501                 :            :                                    uint8_t target_protocol,
    2502                 :            :                                    struct rte_flow_error *error)
    2503                 :            : {
    2504                 :          0 :         const struct rte_flow_item_icmp6_echo *mask = item->mask;
    2505                 :          0 :         const struct rte_flow_item_icmp6_echo nic_mask = {
    2506                 :            :                 .hdr.base.type = 0xff,
    2507                 :            :                 .hdr.base.code = 0xff,
    2508                 :            :                 .hdr.identifier = RTE_BE16(0xffff),
    2509                 :            :                 .hdr.sequence = RTE_BE16(0xffff),
    2510                 :            :         };
    2511                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2512         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV6 :
    2513                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3_IPV6;
    2514         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2515                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2516                 :            :         int ret;
    2517                 :            : 
    2518         [ #  # ]:          0 :         if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMPV6)
    2519                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2520                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2521                 :            :                                           "protocol filtering not compatible"
    2522                 :            :                                           " with ICMP6 layer");
    2523         [ #  # ]:          0 :         if (!(item_flags & l3m))
    2524                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2525                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2526                 :            :                                           "IPv6 is mandatory to filter on"
    2527                 :            :                                           " ICMP6");
    2528         [ #  # ]:          0 :         if (item_flags & l4m)
    2529                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2530                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2531                 :            :                                           "multiple L4 layers not supported");
    2532         [ #  # ]:          0 :         if (!mask)
    2533                 :            :                 mask = &nic_mask;
    2534                 :          0 :         ret = mlx5_flow_item_acceptable
    2535                 :            :                 (item, (const uint8_t *)mask,
    2536                 :            :                  (const uint8_t *)&nic_mask,
    2537                 :            :                  sizeof(struct rte_flow_item_icmp6_echo),
    2538                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2539                 :            :         if (ret < 0)
    2540                 :            :                 return ret;
    2541                 :            :         return 0;
    2542                 :            : }
    2543                 :            : 
    2544                 :            : /**
    2545                 :            :  * Validate ICMP item.
    2546                 :            :  *
    2547                 :            :  * @param[in] item
    2548                 :            :  *   Item specification.
    2549                 :            :  * @param[in] item_flags
    2550                 :            :  *   Bit-fields that holds the items detected until now.
    2551                 :            :  * @param[out] error
    2552                 :            :  *   Pointer to error structure.
    2553                 :            :  *
    2554                 :            :  * @return
    2555                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2556                 :            :  */
    2557                 :            : int
    2558                 :          0 : mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
    2559                 :            :                              uint64_t item_flags,
    2560                 :            :                              uint8_t target_protocol,
    2561                 :            :                              struct rte_flow_error *error)
    2562                 :            : {
    2563                 :          0 :         const struct rte_flow_item_icmp *mask = item->mask;
    2564                 :          0 :         const struct rte_flow_item_icmp nic_mask = {
    2565                 :            :                 .hdr.icmp_type = 0xff,
    2566                 :            :                 .hdr.icmp_code = 0xff,
    2567                 :            :                 .hdr.icmp_ident = RTE_BE16(0xffff),
    2568                 :            :                 .hdr.icmp_seq_nb = RTE_BE16(0xffff),
    2569                 :            :         };
    2570                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2571         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3_IPV4 :
    2572                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3_IPV4;
    2573         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2574                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2575                 :            :         int ret;
    2576                 :            : 
    2577         [ #  # ]:          0 :         if (target_protocol != 0xFF && target_protocol != IPPROTO_ICMP)
    2578                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2579                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2580                 :            :                                           "protocol filtering not compatible"
    2581                 :            :                                           " with ICMP layer");
    2582         [ #  # ]:          0 :         if (!(item_flags & l3m))
    2583                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2584                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2585                 :            :                                           "IPv4 is mandatory to filter"
    2586                 :            :                                           " on ICMP");
    2587         [ #  # ]:          0 :         if (item_flags & l4m)
    2588                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2589                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2590                 :            :                                           "multiple L4 layers not supported");
    2591         [ #  # ]:          0 :         if (!mask)
    2592                 :            :                 mask = &nic_mask;
    2593                 :          0 :         ret = mlx5_flow_item_acceptable
    2594                 :            :                 (item, (const uint8_t *)mask,
    2595                 :            :                  (const uint8_t *)&nic_mask,
    2596                 :            :                  sizeof(struct rte_flow_item_icmp),
    2597                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2598                 :            :         if (ret < 0)
    2599                 :            :                 return ret;
    2600                 :            :         return 0;
    2601                 :            : }
    2602                 :            : 
    2603                 :            : /**
    2604                 :            :  * Validate Ethernet item.
    2605                 :            :  *
    2606                 :            :  * @param[in] item
    2607                 :            :  *   Item specification.
    2608                 :            :  * @param[in] item_flags
    2609                 :            :  *   Bit-fields that holds the items detected until now.
    2610                 :            :  * @param[out] error
    2611                 :            :  *   Pointer to error structure.
    2612                 :            :  *
    2613                 :            :  * @return
    2614                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2615                 :            :  */
    2616                 :            : int
    2617                 :          0 : mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
    2618                 :            :                             uint64_t item_flags, bool ext_vlan_sup,
    2619                 :            :                             struct rte_flow_error *error)
    2620                 :            : {
    2621                 :          0 :         const struct rte_flow_item_eth *mask = item->mask;
    2622                 :          0 :         const struct rte_flow_item_eth nic_mask = {
    2623                 :            :                 .hdr.dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
    2624                 :            :                 .hdr.src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff",
    2625                 :            :                 .hdr.ether_type = RTE_BE16(0xffff),
    2626                 :            :                 .has_vlan = ext_vlan_sup ? 1 : 0,
    2627                 :            :         };
    2628                 :            :         int ret;
    2629                 :          0 :         int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2630         [ #  # ]:          0 :         const uint64_t ethm = tunnel ? MLX5_FLOW_LAYER_INNER_L2 :
    2631                 :            :                                        MLX5_FLOW_LAYER_OUTER_L2;
    2632                 :            : 
    2633         [ #  # ]:          0 :         if (item_flags & ethm)
    2634                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2635                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2636                 :            :                                           "multiple L2 layers not supported");
    2637   [ #  #  #  #  :          0 :         if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_L3)) ||
                   #  # ]
    2638         [ #  # ]:          0 :             (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_L3)))
    2639                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2640                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2641                 :            :                                           "L2 layer should not follow "
    2642                 :            :                                           "L3 layers");
    2643   [ #  #  #  #  :          0 :         if ((!tunnel && (item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) ||
                   #  # ]
    2644         [ #  # ]:          0 :             (tunnel && (item_flags & MLX5_FLOW_LAYER_INNER_VLAN)))
    2645                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2646                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2647                 :            :                                           "L2 layer should not follow VLAN");
    2648         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_GTP)
    2649                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2650                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2651                 :            :                                           "L2 layer should not follow GTP");
    2652         [ #  # ]:          0 :         if (!mask)
    2653                 :            :                 mask = &rte_flow_item_eth_mask;
    2654                 :          0 :         ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
    2655                 :            :                                         (const uint8_t *)&nic_mask,
    2656                 :            :                                         sizeof(struct rte_flow_item_eth),
    2657                 :            :                                         MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2658                 :          0 :         return ret;
    2659                 :            : }
    2660                 :            : 
    2661                 :            : /**
    2662                 :            :  * Validate VLAN item.
    2663                 :            :  *
    2664                 :            :  * @param[in] item
    2665                 :            :  *   Item specification.
    2666                 :            :  * @param[in] item_flags
    2667                 :            :  *   Bit-fields that holds the items detected until now.
    2668                 :            :  * @param[in] dev
    2669                 :            :  *   Ethernet device flow is being created on.
    2670                 :            :  * @param[out] error
    2671                 :            :  *   Pointer to error structure.
    2672                 :            :  *
    2673                 :            :  * @return
    2674                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2675                 :            :  */
    2676                 :            : int
    2677                 :          0 : mlx5_flow_validate_item_vlan(const struct rte_flow_item *item,
    2678                 :            :                              uint64_t item_flags,
    2679                 :            :                              struct rte_eth_dev *dev,
    2680                 :            :                              struct rte_flow_error *error)
    2681                 :            : {
    2682                 :          0 :         const struct rte_flow_item_vlan *spec = item->spec;
    2683                 :          0 :         const struct rte_flow_item_vlan *mask = item->mask;
    2684                 :          0 :         const struct rte_flow_item_vlan nic_mask = {
    2685                 :            :                 .hdr.vlan_tci = RTE_BE16(UINT16_MAX),
    2686                 :            :                 .hdr.eth_proto = RTE_BE16(UINT16_MAX),
    2687                 :            :         };
    2688                 :            :         uint16_t vlan_tag = 0;
    2689                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2690                 :            :         int ret;
    2691                 :            :         const uint64_t l34m = tunnel ? (MLX5_FLOW_LAYER_INNER_L3 |
    2692         [ #  # ]:          0 :                                         MLX5_FLOW_LAYER_INNER_L4) :
    2693                 :            :                                        (MLX5_FLOW_LAYER_OUTER_L3 |
    2694                 :            :                                         MLX5_FLOW_LAYER_OUTER_L4);
    2695         [ #  # ]:          0 :         const uint64_t vlanm = tunnel ? MLX5_FLOW_LAYER_INNER_VLAN :
    2696                 :            :                                         MLX5_FLOW_LAYER_OUTER_VLAN;
    2697                 :            : 
    2698         [ #  # ]:          0 :         if (item_flags & vlanm)
    2699                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2700                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2701                 :            :                                           "multiple VLAN layers not supported");
    2702         [ #  # ]:          0 :         else if ((item_flags & l34m) != 0)
    2703                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2704                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2705                 :            :                                           "VLAN cannot follow L3/L4 layer");
    2706         [ #  # ]:          0 :         if (!mask)
    2707                 :            :                 mask = &rte_flow_item_vlan_mask;
    2708                 :          0 :         ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
    2709                 :            :                                         (const uint8_t *)&nic_mask,
    2710                 :            :                                         sizeof(struct rte_flow_item_vlan),
    2711                 :            :                                         MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2712         [ #  # ]:          0 :         if (ret)
    2713                 :            :                 return ret;
    2714   [ #  #  #  # ]:          0 :         if (!tunnel && mask->hdr.vlan_tci != RTE_BE16(0x0fff)) {
    2715                 :          0 :                 struct mlx5_priv *priv = dev->data->dev_private;
    2716                 :            : 
    2717         [ #  # ]:          0 :                 if (priv->vmwa_context) {
    2718                 :            :                         /*
    2719                 :            :                          * Non-NULL context means we have a virtual machine
    2720                 :            :                          * and SR-IOV enabled, we have to create VLAN interface
    2721                 :            :                          * to make hypervisor to setup E-Switch vport
    2722                 :            :                          * context correctly. We avoid creating the multiple
    2723                 :            :                          * VLAN interfaces, so we cannot support VLAN tag mask.
    2724                 :            :                          */
    2725                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    2726                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    2727                 :            :                                                   item,
    2728                 :            :                                                   "VLAN tag mask is not"
    2729                 :            :                                                   " supported in virtual"
    2730                 :            :                                                   " environment");
    2731                 :            :                 }
    2732                 :            :         }
    2733         [ #  # ]:          0 :         if (spec) {
    2734                 :          0 :                 vlan_tag = spec->hdr.vlan_tci;
    2735                 :          0 :                 vlan_tag &= mask->hdr.vlan_tci;
    2736                 :            :         }
    2737                 :            :         /*
    2738                 :            :          * From verbs perspective an empty VLAN is equivalent
    2739                 :            :          * to a packet without VLAN layer.
    2740                 :            :          */
    2741         [ #  # ]:          0 :         if (!vlan_tag)
    2742                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2743                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
    2744                 :          0 :                                           item->spec,
    2745                 :            :                                           "VLAN cannot be empty");
    2746                 :            :         return 0;
    2747                 :            : }
    2748                 :            : 
    2749                 :            : /**
    2750                 :            :  * Validate IPV4 item.
    2751                 :            :  *
    2752                 :            :  * @param[in] item
    2753                 :            :  *   Item specification.
    2754                 :            :  * @param[in] item_flags
    2755                 :            :  *   Bit-fields that holds the items detected until now.
    2756                 :            :  * @param[in] last_item
    2757                 :            :  *   Previous validated item in the pattern items.
    2758                 :            :  * @param[in] ether_type
    2759                 :            :  *   Type in the ethernet layer header (including dot1q).
    2760                 :            :  * @param[in] acc_mask
    2761                 :            :  *   Acceptable mask, if NULL default internal default mask
    2762                 :            :  *   will be used to check whether item fields are supported.
    2763                 :            :  * @param[in] range_accepted
    2764                 :            :  *   True if range of values is accepted for specific fields, false otherwise.
    2765                 :            :  * @param[out] error
    2766                 :            :  *   Pointer to error structure.
    2767                 :            :  *
    2768                 :            :  * @return
    2769                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2770                 :            :  */
    2771                 :            : int
    2772                 :          0 : mlx5_flow_validate_item_ipv4(const struct rte_flow_item *item,
    2773                 :            :                              uint64_t item_flags,
    2774                 :            :                              uint64_t last_item,
    2775                 :            :                              uint16_t ether_type,
    2776                 :            :                              const struct rte_flow_item_ipv4 *acc_mask,
    2777                 :            :                              bool range_accepted,
    2778                 :            :                              struct rte_flow_error *error)
    2779                 :            : {
    2780                 :          0 :         const struct rte_flow_item_ipv4 *mask = item->mask;
    2781                 :          0 :         const struct rte_flow_item_ipv4 *spec = item->spec;
    2782                 :          0 :         const struct rte_flow_item_ipv4 nic_mask = {
    2783                 :            :                 .hdr = {
    2784                 :            :                         .src_addr = RTE_BE32(0xffffffff),
    2785                 :            :                         .dst_addr = RTE_BE32(0xffffffff),
    2786                 :            :                         .type_of_service = 0xff,
    2787                 :            :                         .next_proto_id = 0xff,
    2788                 :            :                 },
    2789                 :            :         };
    2790                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2791         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
    2792                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3;
    2793         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2794                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2795                 :            :         int ret;
    2796                 :            :         uint8_t next_proto = 0xFF;
    2797                 :            :         const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
    2798                 :            :                                   MLX5_FLOW_LAYER_OUTER_VLAN |
    2799                 :            :                                   MLX5_FLOW_LAYER_INNER_VLAN);
    2800                 :            : 
    2801         [ #  # ]:          0 :         if ((last_item & l2_vlan) && ether_type &&
    2802         [ #  # ]:          0 :             ether_type != RTE_ETHER_TYPE_IPV4)
    2803                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2804                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2805                 :            :                                           "IPv4 cannot follow L2/VLAN layer "
    2806                 :            :                                           "which ether type is not IPv4");
    2807         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_IPIP) {
    2808         [ #  # ]:          0 :                 if (mask && spec)
    2809                 :          0 :                         next_proto = mask->hdr.next_proto_id &
    2810                 :          0 :                                      spec->hdr.next_proto_id;
    2811         [ #  # ]:          0 :                 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
    2812                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    2813                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    2814                 :            :                                                   item,
    2815                 :            :                                                   "multiple tunnel "
    2816                 :            :                                                   "not supported");
    2817                 :            :         }
    2818         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_IPV6_ENCAP)
    2819                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2820                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2821                 :            :                                           "wrong tunnel type - IPv6 specified "
    2822                 :            :                                           "but IPv4 item provided");
    2823         [ #  # ]:          0 :         if (item_flags & l3m)
    2824                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2825                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2826                 :            :                                           "multiple L3 layers not supported");
    2827         [ #  # ]:          0 :         else if (item_flags & l4m)
    2828                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2829                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2830                 :            :                                           "L3 cannot follow an L4 layer.");
    2831         [ #  # ]:          0 :         else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
    2832                 :            :                   !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
    2833                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2834                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2835                 :            :                                           "L3 cannot follow an NVGRE layer.");
    2836         [ #  # ]:          0 :         if (!mask)
    2837                 :            :                 mask = &rte_flow_item_ipv4_mask;
    2838         [ #  # ]:          0 :         else if (mask->hdr.next_proto_id != 0 &&
    2839                 :            :                  mask->hdr.next_proto_id != 0xff)
    2840                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2841                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
    2842                 :            :                                           "partial mask is not supported"
    2843                 :            :                                           " for protocol");
    2844         [ #  # ]:          0 :         ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
    2845                 :            :                                         acc_mask ? (const uint8_t *)acc_mask
    2846                 :            :                                                  : (const uint8_t *)&nic_mask,
    2847                 :            :                                         sizeof(struct rte_flow_item_ipv4),
    2848                 :            :                                         range_accepted, error);
    2849                 :            :         if (ret < 0)
    2850                 :            :                 return ret;
    2851                 :            :         return 0;
    2852                 :            : }
    2853                 :            : 
    2854                 :            : /**
    2855                 :            :  * Validate IPV6 item.
    2856                 :            :  *
    2857                 :            :  * @param[in] item
    2858                 :            :  *   Item specification.
    2859                 :            :  * @param[in] item_flags
    2860                 :            :  *   Bit-fields that holds the items detected until now.
    2861                 :            :  * @param[in] last_item
    2862                 :            :  *   Previous validated item in the pattern items.
    2863                 :            :  * @param[in] ether_type
    2864                 :            :  *   Type in the ethernet layer header (including dot1q).
    2865                 :            :  * @param[in] acc_mask
    2866                 :            :  *   Acceptable mask, if NULL default internal default mask
    2867                 :            :  *   will be used to check whether item fields are supported.
    2868                 :            :  * @param[out] error
    2869                 :            :  *   Pointer to error structure.
    2870                 :            :  *
    2871                 :            :  * @return
    2872                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2873                 :            :  */
    2874                 :            : int
    2875                 :          0 : mlx5_flow_validate_item_ipv6(const struct rte_flow_item *item,
    2876                 :            :                              uint64_t item_flags,
    2877                 :            :                              uint64_t last_item,
    2878                 :            :                              uint16_t ether_type,
    2879                 :            :                              const struct rte_flow_item_ipv6 *acc_mask,
    2880                 :            :                              struct rte_flow_error *error)
    2881                 :            : {
    2882                 :          0 :         const struct rte_flow_item_ipv6 *mask = item->mask;
    2883                 :          0 :         const struct rte_flow_item_ipv6 *spec = item->spec;
    2884                 :          0 :         const struct rte_flow_item_ipv6 nic_mask = {
    2885                 :            :                 .hdr = {
    2886                 :            :                         .src_addr =
    2887                 :            :                                 "\xff\xff\xff\xff\xff\xff\xff\xff"
    2888                 :            :                                 "\xff\xff\xff\xff\xff\xff\xff\xff",
    2889                 :            :                         .dst_addr =
    2890                 :            :                                 "\xff\xff\xff\xff\xff\xff\xff\xff"
    2891                 :            :                                 "\xff\xff\xff\xff\xff\xff\xff\xff",
    2892                 :            :                         .vtc_flow = RTE_BE32(0xffffffff),
    2893                 :            :                         .proto = 0xff,
    2894                 :            :                 },
    2895                 :            :         };
    2896                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2897         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
    2898                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3;
    2899         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2900                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2901                 :            :         int ret;
    2902                 :            :         uint8_t next_proto = 0xFF;
    2903                 :            :         const uint64_t l2_vlan = (MLX5_FLOW_LAYER_L2 |
    2904                 :            :                                   MLX5_FLOW_LAYER_OUTER_VLAN |
    2905                 :            :                                   MLX5_FLOW_LAYER_INNER_VLAN);
    2906                 :            : 
    2907         [ #  # ]:          0 :         if ((last_item & l2_vlan) && ether_type &&
    2908         [ #  # ]:          0 :             ether_type != RTE_ETHER_TYPE_IPV6)
    2909                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2910                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2911                 :            :                                           "IPv6 cannot follow L2/VLAN layer "
    2912                 :            :                                           "which ether type is not IPv6");
    2913   [ #  #  #  #  :          0 :         if (mask && mask->hdr.proto == UINT8_MAX && spec)
                   #  # ]
    2914                 :          0 :                 next_proto = spec->hdr.proto;
    2915         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_IPIP) {
    2916         [ #  # ]:          0 :                 if (next_proto == IPPROTO_IPIP || next_proto == IPPROTO_IPV6)
    2917                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    2918                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    2919                 :            :                                                   item,
    2920                 :            :                                                   "multiple tunnel "
    2921                 :            :                                                   "not supported");
    2922                 :            :         }
    2923                 :          0 :         if (next_proto == IPPROTO_HOPOPTS  ||
    2924         [ #  # ]:          0 :             next_proto == IPPROTO_ROUTING  ||
    2925                 :            :             next_proto == IPPROTO_FRAGMENT ||
    2926                 :            :             next_proto == IPPROTO_ESP      ||
    2927                 :            :             next_proto == IPPROTO_AH       ||
    2928                 :            :             next_proto == IPPROTO_DSTOPTS)
    2929                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2930                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2931                 :            :                                           "IPv6 proto (next header) should "
    2932                 :            :                                           "not be set as extension header");
    2933         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_IPIP)
    2934                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2935                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2936                 :            :                                           "wrong tunnel type - IPv4 specified "
    2937                 :            :                                           "but IPv6 item provided");
    2938         [ #  # ]:          0 :         if (item_flags & l3m)
    2939                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    2940                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2941                 :            :                                           "multiple L3 layers not supported");
    2942         [ #  # ]:          0 :         else if (item_flags & l4m)
    2943                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2944                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2945                 :            :                                           "L3 cannot follow an L4 layer.");
    2946         [ #  # ]:          0 :         else if ((item_flags & MLX5_FLOW_LAYER_NVGRE) &&
    2947                 :            :                   !(item_flags & MLX5_FLOW_LAYER_INNER_L2))
    2948                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2949                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2950                 :            :                                           "L3 cannot follow an NVGRE layer.");
    2951         [ #  # ]:          0 :         if (!mask)
    2952                 :            :                 mask = &rte_flow_item_ipv6_mask;
    2953         [ #  # ]:          0 :         ret = mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
    2954                 :            :                                         acc_mask ? (const uint8_t *)acc_mask
    2955                 :            :                                                  : (const uint8_t *)&nic_mask,
    2956                 :            :                                         sizeof(struct rte_flow_item_ipv6),
    2957                 :            :                                         MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    2958                 :            :         if (ret < 0)
    2959                 :            :                 return ret;
    2960                 :            :         return 0;
    2961                 :            : }
    2962                 :            : 
    2963                 :            : /**
    2964                 :            :  * Validate UDP item.
    2965                 :            :  *
    2966                 :            :  * @param[in] item
    2967                 :            :  *   Item specification.
    2968                 :            :  * @param[in] item_flags
    2969                 :            :  *   Bit-fields that holds the items detected until now.
    2970                 :            :  * @param[in] target_protocol
    2971                 :            :  *   The next protocol in the previous item.
    2972                 :            :  * @param[in] flow_mask
    2973                 :            :  *   mlx5 flow-specific (DV, verbs, etc.) supported header fields mask.
    2974                 :            :  * @param[out] error
    2975                 :            :  *   Pointer to error structure.
    2976                 :            :  *
    2977                 :            :  * @return
    2978                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    2979                 :            :  */
    2980                 :            : int
    2981                 :          0 : mlx5_flow_validate_item_udp(const struct rte_flow_item *item,
    2982                 :            :                             uint64_t item_flags,
    2983                 :            :                             uint8_t target_protocol,
    2984                 :            :                             struct rte_flow_error *error)
    2985                 :            : {
    2986                 :          0 :         const struct rte_flow_item_udp *mask = item->mask;
    2987                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    2988         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
    2989                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3;
    2990         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    2991                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    2992                 :            :         int ret;
    2993                 :            : 
    2994         [ #  # ]:          0 :         if (target_protocol != 0xff && target_protocol != IPPROTO_UDP)
    2995                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    2996                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    2997                 :            :                                           "protocol filtering not compatible"
    2998                 :            :                                           " with UDP layer");
    2999         [ #  # ]:          0 :         if (!(item_flags & l3m))
    3000                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3001                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3002                 :            :                                           "L3 is mandatory to filter on L4");
    3003         [ #  # ]:          0 :         if (item_flags & l4m)
    3004                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3005                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3006                 :            :                                           "multiple L4 layers not supported");
    3007         [ #  # ]:          0 :         if (!mask)
    3008                 :            :                 mask = &rte_flow_item_udp_mask;
    3009                 :          0 :         ret = mlx5_flow_item_acceptable
    3010                 :            :                 (item, (const uint8_t *)mask,
    3011                 :            :                  (const uint8_t *)&rte_flow_item_udp_mask,
    3012                 :            :                  sizeof(struct rte_flow_item_udp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
    3013                 :            :                  error);
    3014                 :            :         if (ret < 0)
    3015                 :            :                 return ret;
    3016                 :            :         return 0;
    3017                 :            : }
    3018                 :            : 
    3019                 :            : /**
    3020                 :            :  * Validate TCP item.
    3021                 :            :  *
    3022                 :            :  * @param[in] item
    3023                 :            :  *   Item specification.
    3024                 :            :  * @param[in] item_flags
    3025                 :            :  *   Bit-fields that holds the items detected until now.
    3026                 :            :  * @param[in] target_protocol
    3027                 :            :  *   The next protocol in the previous item.
    3028                 :            :  * @param[out] error
    3029                 :            :  *   Pointer to error structure.
    3030                 :            :  *
    3031                 :            :  * @return
    3032                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3033                 :            :  */
    3034                 :            : int
    3035                 :          0 : mlx5_flow_validate_item_tcp(const struct rte_flow_item *item,
    3036                 :            :                             uint64_t item_flags,
    3037                 :            :                             uint8_t target_protocol,
    3038                 :            :                             const struct rte_flow_item_tcp *flow_mask,
    3039                 :            :                             struct rte_flow_error *error)
    3040                 :            : {
    3041                 :          0 :         const struct rte_flow_item_tcp *mask = item->mask;
    3042                 :          0 :         const int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
    3043         [ #  # ]:          0 :         const uint64_t l3m = tunnel ? MLX5_FLOW_LAYER_INNER_L3 :
    3044                 :            :                                       MLX5_FLOW_LAYER_OUTER_L3;
    3045         [ #  # ]:          0 :         const uint64_t l4m = tunnel ? MLX5_FLOW_LAYER_INNER_L4 :
    3046                 :            :                                       MLX5_FLOW_LAYER_OUTER_L4;
    3047                 :            :         int ret;
    3048                 :            : 
    3049                 :            :         MLX5_ASSERT(flow_mask);
    3050         [ #  # ]:          0 :         if (target_protocol != 0xff && target_protocol != IPPROTO_TCP)
    3051                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3052                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3053                 :            :                                           "protocol filtering not compatible"
    3054                 :            :                                           " with TCP layer");
    3055         [ #  # ]:          0 :         if (!(item_flags & l3m))
    3056                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3057                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3058                 :            :                                           "L3 is mandatory to filter on L4");
    3059         [ #  # ]:          0 :         if (item_flags & l4m)
    3060                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3061                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3062                 :            :                                           "multiple L4 layers not supported");
    3063         [ #  # ]:          0 :         if (!mask)
    3064                 :            :                 mask = &rte_flow_item_tcp_mask;
    3065                 :          0 :         ret = mlx5_flow_item_acceptable
    3066                 :            :                 (item, (const uint8_t *)mask,
    3067                 :            :                  (const uint8_t *)flow_mask,
    3068                 :            :                  sizeof(struct rte_flow_item_tcp), MLX5_ITEM_RANGE_NOT_ACCEPTED,
    3069                 :            :                  error);
    3070                 :            :         if (ret < 0)
    3071                 :            :                 return ret;
    3072                 :            :         return 0;
    3073                 :            : }
    3074                 :            : 
    3075                 :            : /**
    3076                 :            :  * Validate VXLAN item.
    3077                 :            :  *
    3078                 :            :  * @param[in] dev
    3079                 :            :  *   Pointer to the Ethernet device structure.
    3080                 :            :  * @param[in] udp_dport
    3081                 :            :  *   UDP destination port
    3082                 :            :  * @param[in] item
    3083                 :            :  *   Item specification.
    3084                 :            :  * @param[in] item_flags
    3085                 :            :  *   Bit-fields that holds the items detected until now.
    3086                 :            :  * @param root
    3087                 :            :  *   Whether action is on root table.
    3088                 :            :  * @param[out] error
    3089                 :            :  *   Pointer to error structure.
    3090                 :            :  *
    3091                 :            :  * @return
    3092                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3093                 :            :  */
    3094                 :            : int
    3095                 :          0 : mlx5_flow_validate_item_vxlan(struct rte_eth_dev *dev,
    3096                 :            :                               uint16_t udp_dport,
    3097                 :            :                               const struct rte_flow_item *item,
    3098                 :            :                               uint64_t item_flags,
    3099                 :            :                               bool root,
    3100                 :            :                               struct rte_flow_error *error)
    3101                 :            : {
    3102                 :            :         const struct rte_flow_item_vxlan *spec = item->spec;
    3103                 :          0 :         const struct rte_flow_item_vxlan *mask = item->mask;
    3104                 :            :         int ret;
    3105                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3106                 :            :         union vni {
    3107                 :            :                 uint32_t vlan_id;
    3108                 :            :                 uint8_t vni[4];
    3109                 :          0 :         } id = { .vlan_id = 0, };
    3110                 :          0 :         const struct rte_flow_item_vxlan nic_mask = {
    3111                 :            :                 .hdr.vni = "\xff\xff\xff",
    3112                 :            :                 .hdr.rsvd1 = 0xff,
    3113                 :            :         };
    3114                 :            :         const struct rte_flow_item_vxlan *valid_mask;
    3115                 :            : 
    3116         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3117                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3118                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3119                 :            :                                           "multiple tunnel layers not"
    3120                 :            :                                           " supported");
    3121                 :            :         valid_mask = &rte_flow_item_vxlan_mask;
    3122                 :            :         /*
    3123                 :            :          * Verify only UDPv4 is present as defined in
    3124                 :            :          * https://tools.ietf.org/html/rfc7348
    3125                 :            :          */
    3126         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
    3127                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3128                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3129                 :            :                                           "no outer UDP layer found");
    3130         [ #  # ]:          0 :         if (!mask)
    3131                 :            :                 mask = &rte_flow_item_vxlan_mask;
    3132                 :            : 
    3133         [ #  # ]:          0 :         if (priv->sh->steering_format_version !=
    3134                 :            :             MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
    3135         [ #  # ]:          0 :             !udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN) {
    3136                 :            :                 /* non-root table */
    3137   [ #  #  #  # ]:          0 :                 if (!root && priv->sh->misc5_cap)
    3138                 :            :                         valid_mask = &nic_mask;
    3139                 :            :                 /* Group zero in NIC domain */
    3140   [ #  #  #  # ]:          0 :                 if (!root && priv->sh->tunnel_header_0_1)
    3141                 :            :                         valid_mask = &nic_mask;
    3142                 :            :         }
    3143                 :          0 :         ret = mlx5_flow_item_acceptable
    3144                 :            :                 (item, (const uint8_t *)mask,
    3145                 :            :                  (const uint8_t *)valid_mask,
    3146                 :            :                  sizeof(struct rte_flow_item_vxlan),
    3147                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3148         [ #  # ]:          0 :         if (ret < 0)
    3149                 :            :                 return ret;
    3150                 :            :         if (spec) {
    3151                 :            :                 memcpy(&id.vni[1], spec->hdr.vni, 3);
    3152                 :            :                 memcpy(&id.vni[1], mask->hdr.vni, 3);
    3153                 :            :         }
    3154         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
    3155                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3156                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3157                 :            :                                           "VXLAN tunnel must be fully defined");
    3158                 :            :         return 0;
    3159                 :            : }
    3160                 :            : 
    3161                 :            : /**
    3162                 :            :  * Validate VXLAN_GPE item.
    3163                 :            :  *
    3164                 :            :  * @param[in] item
    3165                 :            :  *   Item specification.
    3166                 :            :  * @param[in] item_flags
    3167                 :            :  *   Bit-fields that holds the items detected until now.
    3168                 :            :  * @param[in] priv
    3169                 :            :  *   Pointer to the private data structure.
    3170                 :            :  * @param[in] target_protocol
    3171                 :            :  *   The next protocol in the previous item.
    3172                 :            :  * @param[out] error
    3173                 :            :  *   Pointer to error structure.
    3174                 :            :  *
    3175                 :            :  * @return
    3176                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3177                 :            :  */
    3178                 :            : int
    3179                 :          0 : mlx5_flow_validate_item_vxlan_gpe(const struct rte_flow_item *item,
    3180                 :            :                                   uint64_t item_flags,
    3181                 :            :                                   struct rte_eth_dev *dev,
    3182                 :            :                                   struct rte_flow_error *error)
    3183                 :            : {
    3184                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3185                 :            :         const struct rte_flow_item_vxlan_gpe *spec = item->spec;
    3186                 :          0 :         const struct rte_flow_item_vxlan_gpe *mask = item->mask;
    3187                 :            :         int ret;
    3188                 :            :         union vni {
    3189                 :            :                 uint32_t vlan_id;
    3190                 :            :                 uint8_t vni[4];
    3191                 :          0 :         } id = { .vlan_id = 0, };
    3192                 :            : 
    3193                 :          0 :         struct rte_flow_item_vxlan_gpe nic_mask = {
    3194                 :            :                 .vni = "\xff\xff\xff",
    3195                 :            :                 .protocol = 0xff,
    3196                 :            :                 .flags = 0xff,
    3197                 :            :         };
    3198                 :            : 
    3199         [ #  # ]:          0 :         if (!priv->sh->config.l3_vxlan_en)
    3200                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3201                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3202                 :            :                                           "L3 VXLAN is not enabled by device"
    3203                 :            :                                           " parameter and/or not configured in"
    3204                 :            :                                           " firmware");
    3205         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3206                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3207                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3208                 :            :                                           "multiple tunnel layers not"
    3209                 :            :                                           " supported");
    3210                 :            :         /*
    3211                 :            :          * Verify only UDPv4 is present as defined in
    3212                 :            :          * https://tools.ietf.org/html/rfc7348
    3213                 :            :          */
    3214         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
    3215                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3216                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3217                 :            :                                           "no outer UDP layer found");
    3218         [ #  # ]:          0 :         if (!mask)
    3219                 :            :                 mask = &rte_flow_item_vxlan_gpe_mask;
    3220         [ #  # ]:          0 :         if (priv->sh->misc5_cap && priv->sh->tunnel_header_0_1) {
    3221                 :          0 :                 nic_mask.rsvd0[0] = 0xff;
    3222                 :          0 :                 nic_mask.rsvd0[1] = 0xff;
    3223                 :          0 :                 nic_mask.rsvd1 = 0xff;
    3224                 :            :         }
    3225                 :          0 :         ret = mlx5_flow_item_acceptable
    3226                 :            :                 (item, (const uint8_t *)mask,
    3227                 :            :                  (const uint8_t *)&nic_mask,
    3228                 :            :                  sizeof(struct rte_flow_item_vxlan_gpe),
    3229                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3230         [ #  # ]:          0 :         if (ret < 0)
    3231                 :            :                 return ret;
    3232                 :            :         if (spec) {
    3233                 :            :                 memcpy(&id.vni[1], spec->hdr.vni, 3);
    3234                 :            :                 memcpy(&id.vni[1], mask->hdr.vni, 3);
    3235                 :            :         }
    3236         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
    3237                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3238                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3239                 :            :                                           "VXLAN-GPE tunnel must be fully"
    3240                 :            :                                           " defined");
    3241                 :            :         return 0;
    3242                 :            : }
    3243                 :            : /**
    3244                 :            :  * Validate GRE Key item.
    3245                 :            :  *
    3246                 :            :  * @param[in] item
    3247                 :            :  *   Item specification.
    3248                 :            :  * @param[in] item_flags
    3249                 :            :  *   Bit flags to mark detected items.
    3250                 :            :  * @param[in] gre_item
    3251                 :            :  *   Pointer to gre_item
    3252                 :            :  * @param[out] error
    3253                 :            :  *   Pointer to error structure.
    3254                 :            :  *
    3255                 :            :  * @return
    3256                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3257                 :            :  */
    3258                 :            : int
    3259                 :          0 : mlx5_flow_validate_item_gre_key(const struct rte_flow_item *item,
    3260                 :            :                                 uint64_t item_flags,
    3261                 :            :                                 const struct rte_flow_item *gre_item,
    3262                 :            :                                 struct rte_flow_error *error)
    3263                 :            : {
    3264                 :          0 :         const rte_be32_t *mask = item->mask;
    3265                 :            :         int ret = 0;
    3266                 :          0 :         rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
    3267                 :            :         const struct rte_flow_item_gre *gre_spec;
    3268                 :            :         const struct rte_flow_item_gre *gre_mask;
    3269                 :            : 
    3270         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_GRE_KEY)
    3271                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3272                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3273                 :            :                                           "Multiple GRE key not support");
    3274         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_GRE))
    3275                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3276                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3277                 :            :                                           "No preceding GRE header");
    3278         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_INNER)
    3279                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3280                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3281                 :            :                                           "GRE key following a wrong item");
    3282                 :          0 :         gre_mask = gre_item->mask;
    3283         [ #  # ]:          0 :         if (!gre_mask)
    3284                 :            :                 gre_mask = &rte_flow_item_gre_mask;
    3285                 :          0 :         gre_spec = gre_item->spec;
    3286   [ #  #  #  # ]:          0 :         if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
    3287         [ #  # ]:          0 :                          !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
    3288                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3289                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3290                 :            :                                           "Key bit must be on");
    3291                 :            : 
    3292         [ #  # ]:          0 :         if (!mask)
    3293                 :            :                 mask = &gre_key_default_mask;
    3294                 :          0 :         ret = mlx5_flow_item_acceptable
    3295                 :            :                 (item, (const uint8_t *)mask,
    3296                 :            :                  (const uint8_t *)&gre_key_default_mask,
    3297                 :            :                  sizeof(rte_be32_t), MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3298                 :          0 :         return ret;
    3299                 :            : }
    3300                 :            : 
    3301                 :            : /**
    3302                 :            :  * Validate GRE optional item.
    3303                 :            :  *
    3304                 :            :  * @param[in] dev
    3305                 :            :  *   Pointer to the Ethernet device structure.
    3306                 :            :  * @param[in] item
    3307                 :            :  *   Item specification.
    3308                 :            :  * @param[in] item_flags
    3309                 :            :  *   Bit flags to mark detected items.
    3310                 :            :  * @param[in] attr
    3311                 :            :  *   Flow rule attributes.
    3312                 :            :  * @param[in] gre_item
    3313                 :            :  *   Pointer to gre_item
    3314                 :            :  * @param[out] error
    3315                 :            :  *   Pointer to error structure.
    3316                 :            :  *
    3317                 :            :  * @return
    3318                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3319                 :            :  */
    3320                 :            : int
    3321                 :          0 : mlx5_flow_validate_item_gre_option(struct rte_eth_dev *dev,
    3322                 :            :                                    const struct rte_flow_item *item,
    3323                 :            :                                    uint64_t item_flags,
    3324                 :            :                                    const struct rte_flow_attr *attr,
    3325                 :            :                                    const struct rte_flow_item *gre_item,
    3326                 :            :                                    struct rte_flow_error *error)
    3327                 :            : {
    3328                 :          0 :         const struct rte_flow_item_gre *gre_spec = gre_item->spec;
    3329                 :          0 :         const struct rte_flow_item_gre *gre_mask = gre_item->mask;
    3330                 :          0 :         const struct rte_flow_item_gre_opt *spec = item->spec;
    3331                 :          0 :         const struct rte_flow_item_gre_opt *mask = item->mask;
    3332                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3333                 :            :         int ret = 0;
    3334                 :          0 :         struct rte_flow_item_gre_opt nic_mask = {
    3335                 :            :                 .checksum_rsvd = {
    3336                 :            :                         .checksum = RTE_BE16(UINT16_MAX),
    3337                 :            :                         .reserved1 = 0x0,
    3338                 :            :                 },
    3339                 :            :                 .key = {
    3340                 :            :                         .key = RTE_BE32(UINT32_MAX),
    3341                 :            :                 },
    3342                 :            :                 .sequence = {
    3343                 :            :                         .sequence = RTE_BE32(UINT32_MAX),
    3344                 :            :                 },
    3345                 :            :         };
    3346                 :            : 
    3347         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_GRE))
    3348                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3349                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3350                 :            :                                           "No preceding GRE header");
    3351         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_INNER)
    3352                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3353                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3354                 :            :                                           "GRE option following a wrong item");
    3355         [ #  # ]:          0 :         if (!spec || !mask)
    3356                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3357                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3358                 :            :                                           "At least one field gre_option(checksum/key/sequence) must be specified");
    3359         [ #  # ]:          0 :         if (!gre_mask)
    3360                 :            :                 gre_mask = &rte_flow_item_gre_mask;
    3361         [ #  # ]:          0 :         if (mask->checksum_rsvd.checksum)
    3362   [ #  #  #  # ]:          0 :                 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x8000)) &&
    3363         [ #  # ]:          0 :                                  !(gre_spec->c_rsvd0_ver & RTE_BE16(0x8000)))
    3364                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    3365                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    3366                 :            :                                                   item,
    3367                 :            :                                                   "Checksum bit must be on");
    3368         [ #  # ]:          0 :         if (mask->key.key)
    3369   [ #  #  #  # ]:          0 :                 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x2000)) &&
    3370         [ #  # ]:          0 :                                  !(gre_spec->c_rsvd0_ver & RTE_BE16(0x2000)))
    3371                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    3372                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    3373                 :            :                                                   item, "Key bit must be on");
    3374         [ #  # ]:          0 :         if (mask->sequence.sequence)
    3375   [ #  #  #  # ]:          0 :                 if (gre_spec && (gre_mask->c_rsvd0_ver & RTE_BE16(0x1000)) &&
    3376         [ #  # ]:          0 :                                  !(gre_spec->c_rsvd0_ver & RTE_BE16(0x1000)))
    3377                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    3378                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    3379                 :            :                                                   item,
    3380                 :            :                                                   "Sequence bit must be on");
    3381   [ #  #  #  # ]:          0 :         if (mask->checksum_rsvd.checksum || mask->sequence.sequence) {
    3382         [ #  # ]:          0 :                 if (priv->sh->steering_format_version ==
    3383                 :          0 :                     MLX5_STEERING_LOGIC_FORMAT_CONNECTX_5 ||
    3384   [ #  #  #  #  :          0 :                     ((attr->group || (attr->transfer && priv->fdb_def_rule)) &&
                   #  # ]
    3385         [ #  # ]:          0 :                      !priv->sh->misc5_cap) ||
    3386         [ #  # ]:          0 :                     (!(priv->sh->tunnel_header_0_1 &&
    3387         [ #  # ]:          0 :                        priv->sh->tunnel_header_2_3) &&
    3388   [ #  #  #  # ]:          0 :                     !attr->group && (!attr->transfer || !priv->fdb_def_rule)))
    3389                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    3390                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    3391                 :            :                                                   item,
    3392                 :            :                                                   "Checksum/Sequence not supported");
    3393                 :            :         }
    3394                 :          0 :         ret = mlx5_flow_item_acceptable
    3395                 :            :                 (item, (const uint8_t *)mask,
    3396                 :            :                  (const uint8_t *)&nic_mask,
    3397                 :            :                  sizeof(struct rte_flow_item_gre_opt),
    3398                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3399                 :          0 :         return ret;
    3400                 :            : }
    3401                 :            : 
    3402                 :            : /**
    3403                 :            :  * Validate GRE item.
    3404                 :            :  *
    3405                 :            :  * @param[in] item
    3406                 :            :  *   Item specification.
    3407                 :            :  * @param[in] item_flags
    3408                 :            :  *   Bit flags to mark detected items.
    3409                 :            :  * @param[in] target_protocol
    3410                 :            :  *   The next protocol in the previous item.
    3411                 :            :  * @param[out] error
    3412                 :            :  *   Pointer to error structure.
    3413                 :            :  *
    3414                 :            :  * @return
    3415                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3416                 :            :  */
    3417                 :            : int
    3418                 :          0 : mlx5_flow_validate_item_gre(const struct rte_flow_item *item,
    3419                 :            :                             uint64_t item_flags,
    3420                 :            :                             uint8_t target_protocol,
    3421                 :            :                             struct rte_flow_error *error)
    3422                 :            : {
    3423                 :            :         const struct rte_flow_item_gre *spec __rte_unused = item->spec;
    3424                 :          0 :         const struct rte_flow_item_gre *mask = item->mask;
    3425                 :            :         int ret;
    3426                 :          0 :         const struct rte_flow_item_gre nic_mask = {
    3427                 :            :                 .c_rsvd0_ver = RTE_BE16(0xB000),
    3428                 :            :                 .protocol = RTE_BE16(UINT16_MAX),
    3429                 :            :         };
    3430                 :            : 
    3431         [ #  # ]:          0 :         if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
    3432                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3433                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3434                 :            :                                           "protocol filtering not compatible"
    3435                 :            :                                           " with this GRE layer");
    3436         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3437                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3438                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3439                 :            :                                           "multiple tunnel layers not"
    3440                 :            :                                           " supported");
    3441         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
    3442                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3443                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3444                 :            :                                           "L3 Layer is missing");
    3445         [ #  # ]:          0 :         if (!mask)
    3446                 :            :                 mask = &rte_flow_item_gre_mask;
    3447                 :          0 :         ret = mlx5_flow_item_acceptable
    3448                 :            :                 (item, (const uint8_t *)mask,
    3449                 :            :                  (const uint8_t *)&nic_mask,
    3450                 :            :                  sizeof(struct rte_flow_item_gre), MLX5_ITEM_RANGE_NOT_ACCEPTED,
    3451                 :            :                  error);
    3452                 :            :         if (ret < 0)
    3453                 :            :                 return ret;
    3454                 :            : #ifndef HAVE_MLX5DV_DR
    3455                 :            : #ifndef HAVE_IBV_DEVICE_MPLS_SUPPORT
    3456                 :            :         if (spec && (spec->protocol & mask->protocol))
    3457                 :            :                 return rte_flow_error_set(error, ENOTSUP,
    3458                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3459                 :            :                                           "without MPLS support the"
    3460                 :            :                                           " specification cannot be used for"
    3461                 :            :                                           " filtering");
    3462                 :            : #endif
    3463                 :            : #endif
    3464                 :            :         return 0;
    3465                 :            : }
    3466                 :            : 
    3467                 :            : /**
    3468                 :            :  * Validate Geneve item.
    3469                 :            :  *
    3470                 :            :  * @param[in] item
    3471                 :            :  *   Item specification.
    3472                 :            :  * @param[in] itemFlags
    3473                 :            :  *   Bit-fields that holds the items detected until now.
    3474                 :            :  * @param[in] enPriv
    3475                 :            :  *   Pointer to the private data structure.
    3476                 :            :  * @param[out] error
    3477                 :            :  *   Pointer to error structure.
    3478                 :            :  *
    3479                 :            :  * @return
    3480                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3481                 :            :  */
    3482                 :            : 
    3483                 :            : int
    3484                 :          0 : mlx5_flow_validate_item_geneve(const struct rte_flow_item *item,
    3485                 :            :                                uint64_t item_flags,
    3486                 :            :                                struct rte_eth_dev *dev,
    3487                 :            :                                struct rte_flow_error *error)
    3488                 :            : {
    3489                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3490                 :          0 :         const struct rte_flow_item_geneve *spec = item->spec;
    3491                 :          0 :         const struct rte_flow_item_geneve *mask = item->mask;
    3492                 :            :         int ret;
    3493                 :            :         uint16_t gbhdr;
    3494         [ #  # ]:          0 :         uint8_t opt_len = priv->sh->cdev->config.hca_attr.geneve_max_opt_len ?
    3495                 :            :                           MLX5_GENEVE_OPT_LEN_1 : MLX5_GENEVE_OPT_LEN_0;
    3496                 :          0 :         const struct rte_flow_item_geneve nic_mask = {
    3497                 :            :                 .ver_opt_len_o_c_rsvd0 = RTE_BE16(0x3f80),
    3498                 :            :                 .vni = "\xff\xff\xff",
    3499                 :            :                 .protocol = RTE_BE16(UINT16_MAX),
    3500                 :            :         };
    3501                 :            : 
    3502         [ #  # ]:          0 :         if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_geneve_rx)
    3503                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3504                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3505                 :            :                                           "L3 Geneve is not enabled by device"
    3506                 :            :                                           " parameter and/or not configured in"
    3507                 :            :                                           " firmware");
    3508         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3509                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3510                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3511                 :            :                                           "multiple tunnel layers not"
    3512                 :            :                                           " supported");
    3513                 :            :         /*
    3514                 :            :          * Verify only UDPv4 is present as defined in
    3515                 :            :          * https://tools.ietf.org/html/rfc7348
    3516                 :            :          */
    3517         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP))
    3518                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3519                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3520                 :            :                                           "no outer UDP layer found");
    3521         [ #  # ]:          0 :         if (!mask)
    3522                 :            :                 mask = &rte_flow_item_geneve_mask;
    3523                 :          0 :         ret = mlx5_flow_item_acceptable
    3524                 :            :                                   (item, (const uint8_t *)mask,
    3525                 :            :                                    (const uint8_t *)&nic_mask,
    3526                 :            :                                    sizeof(struct rte_flow_item_geneve),
    3527                 :            :                                    MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3528         [ #  # ]:          0 :         if (ret)
    3529                 :            :                 return ret;
    3530         [ #  # ]:          0 :         if (spec) {
    3531         [ #  # ]:          0 :                 gbhdr = rte_be_to_cpu_16(spec->ver_opt_len_o_c_rsvd0);
    3532         [ #  # ]:          0 :                 if (MLX5_GENEVE_VER_VAL(gbhdr) ||
    3533   [ #  #  #  # ]:          0 :                      MLX5_GENEVE_CRITO_VAL(gbhdr) ||
    3534         [ #  # ]:          0 :                      MLX5_GENEVE_RSVD_VAL(gbhdr) || spec->rsvd1)
    3535                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    3536                 :            :                                                   RTE_FLOW_ERROR_TYPE_ITEM,
    3537                 :            :                                                   item,
    3538                 :            :                                                   "Geneve protocol unsupported"
    3539                 :            :                                                   " fields are being used");
    3540         [ #  # ]:          0 :                 if (MLX5_GENEVE_OPTLEN_VAL(gbhdr) > opt_len)
    3541                 :          0 :                         return rte_flow_error_set
    3542                 :            :                                         (error, ENOTSUP,
    3543                 :            :                                          RTE_FLOW_ERROR_TYPE_ITEM,
    3544                 :            :                                          item,
    3545                 :            :                                          "Unsupported Geneve options length");
    3546                 :            :         }
    3547         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER))
    3548                 :          0 :                 return rte_flow_error_set
    3549                 :            :                                     (error, ENOTSUP,
    3550                 :            :                                      RTE_FLOW_ERROR_TYPE_ITEM, item,
    3551                 :            :                                      "Geneve tunnel must be fully defined");
    3552                 :            :         return 0;
    3553                 :            : }
    3554                 :            : 
    3555                 :            : /**
    3556                 :            :  * Validate Geneve TLV option item.
    3557                 :            :  *
    3558                 :            :  * @param[in] item
    3559                 :            :  *   Item specification.
    3560                 :            :  * @param[in] last_item
    3561                 :            :  *   Previous validated item in the pattern items.
    3562                 :            :  * @param[in] geneve_item
    3563                 :            :  *   Previous GENEVE item specification.
    3564                 :            :  * @param[in] dev
    3565                 :            :  *   Pointer to the rte_eth_dev structure.
    3566                 :            :  * @param[out] error
    3567                 :            :  *   Pointer to error structure.
    3568                 :            :  *
    3569                 :            :  * @return
    3570                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3571                 :            :  */
    3572                 :            : int
    3573                 :          0 : mlx5_flow_validate_item_geneve_opt(const struct rte_flow_item *item,
    3574                 :            :                                    uint64_t last_item,
    3575                 :            :                                    const struct rte_flow_item *geneve_item,
    3576                 :            :                                    struct rte_eth_dev *dev,
    3577                 :            :                                    struct rte_flow_error *error)
    3578                 :            : {
    3579                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3580                 :          0 :         struct mlx5_dev_ctx_shared *sh = priv->sh;
    3581                 :            :         struct mlx5_geneve_tlv_option_resource *geneve_opt_resource;
    3582                 :          0 :         struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
    3583                 :          0 :         uint8_t data_max_supported =
    3584                 :          0 :                         hca_attr->max_geneve_tlv_option_data_len * 4;
    3585                 :            :         const struct rte_flow_item_geneve *geneve_spec;
    3586                 :            :         const struct rte_flow_item_geneve *geneve_mask;
    3587                 :          0 :         const struct rte_flow_item_geneve_opt *spec = item->spec;
    3588                 :          0 :         const struct rte_flow_item_geneve_opt *mask = item->mask;
    3589                 :            :         unsigned int i;
    3590                 :            :         unsigned int data_len;
    3591                 :            :         uint8_t tlv_option_len;
    3592                 :            :         uint16_t optlen_m, optlen_v;
    3593                 :            :         const struct rte_flow_item_geneve_opt full_mask = {
    3594                 :            :                 .option_class = RTE_BE16(0xffff),
    3595                 :            :                 .option_type = 0xff,
    3596                 :            :                 .option_len = 0x1f,
    3597                 :            :         };
    3598                 :            : 
    3599         [ #  # ]:          0 :         if (!mask)
    3600                 :            :                 mask = &rte_flow_item_geneve_opt_mask;
    3601         [ #  # ]:          0 :         if (!spec)
    3602                 :          0 :                 return rte_flow_error_set
    3603                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3604                 :            :                         "Geneve TLV opt class/type/length must be specified");
    3605         [ #  # ]:          0 :         if ((uint32_t)spec->option_len > MLX5_GENEVE_OPTLEN_MASK)
    3606                 :          0 :                 return rte_flow_error_set
    3607                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3608                 :            :                         "Geneve TLV opt length exceeds the limit (31)");
    3609                 :            :         /* Check if class type and length masks are full. */
    3610         [ #  # ]:          0 :         if (full_mask.option_class != mask->option_class ||
    3611                 :          0 :             full_mask.option_type != mask->option_type ||
    3612         [ #  # ]:          0 :             full_mask.option_len != (mask->option_len & full_mask.option_len))
    3613                 :          0 :                 return rte_flow_error_set
    3614                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3615                 :            :                         "Geneve TLV opt class/type/length masks must be full");
    3616                 :            :         /* Check if length is supported */
    3617         [ #  # ]:          0 :         if ((uint32_t)spec->option_len >
    3618                 :            :                         hca_attr->max_geneve_tlv_option_data_len)
    3619                 :          0 :                 return rte_flow_error_set
    3620                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3621                 :            :                         "Geneve TLV opt length not supported");
    3622         [ #  # ]:          0 :         if (hca_attr->max_geneve_tlv_options > 1)
    3623                 :          0 :                 DRV_LOG(DEBUG,
    3624                 :            :                         "max_geneve_tlv_options supports more than 1 option");
    3625                 :            :         /* Check GENEVE item preceding. */
    3626   [ #  #  #  # ]:          0 :         if (!geneve_item || !(last_item & MLX5_FLOW_LAYER_GENEVE))
    3627                 :          0 :                 return rte_flow_error_set
    3628                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3629                 :            :                         "Geneve opt item must be preceded with Geneve item");
    3630                 :          0 :         geneve_spec = geneve_item->spec;
    3631         [ #  # ]:          0 :         geneve_mask = geneve_item->mask ? geneve_item->mask :
    3632                 :            :                                           &rte_flow_item_geneve_mask;
    3633                 :            :         /* Check if GENEVE TLV option size doesn't exceed option length */
    3634   [ #  #  #  # ]:          0 :         if (geneve_spec && (geneve_mask->ver_opt_len_o_c_rsvd0 ||
    3635         [ #  # ]:          0 :                             geneve_spec->ver_opt_len_o_c_rsvd0)) {
    3636                 :          0 :                 tlv_option_len = spec->option_len & mask->option_len;
    3637         [ #  # ]:          0 :                 optlen_v = rte_be_to_cpu_16(geneve_spec->ver_opt_len_o_c_rsvd0);
    3638                 :          0 :                 optlen_v = MLX5_GENEVE_OPTLEN_VAL(optlen_v);
    3639         [ #  # ]:          0 :                 optlen_m = rte_be_to_cpu_16(geneve_mask->ver_opt_len_o_c_rsvd0);
    3640                 :          0 :                 optlen_m = MLX5_GENEVE_OPTLEN_VAL(optlen_m);
    3641         [ #  # ]:          0 :                 if ((optlen_v & optlen_m) <= tlv_option_len)
    3642                 :          0 :                         return rte_flow_error_set
    3643                 :            :                                 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3644                 :            :                                  "GENEVE TLV option length exceeds optlen");
    3645                 :            :         }
    3646                 :            :         /* Check if length is 0 or data is 0. */
    3647   [ #  #  #  # ]:          0 :         if (spec->data == NULL || spec->option_len == 0)
    3648                 :          0 :                 return rte_flow_error_set
    3649                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3650                 :            :                         "Geneve TLV opt with zero data/length not supported");
    3651                 :            :         /* Check not all data & mask are 0. */
    3652                 :          0 :         data_len = spec->option_len * 4;
    3653         [ #  # ]:          0 :         if (mask->data == NULL) {
    3654         [ #  # ]:          0 :                 for (i = 0; i < data_len; i++)
    3655         [ #  # ]:          0 :                         if (spec->data[i])
    3656                 :            :                                 break;
    3657         [ #  # ]:          0 :                 if (i == data_len)
    3658                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    3659                 :            :                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
    3660                 :            :                                 "Can't match on Geneve option data 0");
    3661                 :            :         } else {
    3662         [ #  # ]:          0 :                 for (i = 0; i < data_len; i++)
    3663         [ #  # ]:          0 :                         if (spec->data[i] & mask->data[i])
    3664                 :            :                                 break;
    3665         [ #  # ]:          0 :                 if (i == data_len)
    3666                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    3667                 :            :                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
    3668                 :            :                                 "Can't match on Geneve option data and mask 0");
    3669                 :            :                 /* Check data mask supported. */
    3670         [ #  # ]:          0 :                 for (i = data_max_supported; i < data_len ; i++)
    3671         [ #  # ]:          0 :                         if (mask->data[i])
    3672                 :          0 :                                 return rte_flow_error_set(error, ENOTSUP,
    3673                 :            :                                         RTE_FLOW_ERROR_TYPE_ITEM, item,
    3674                 :            :                                         "Data mask is of unsupported size");
    3675                 :            :         }
    3676                 :            :         /* Check GENEVE option is supported in NIC. */
    3677         [ #  # ]:          0 :         if (!hca_attr->geneve_tlv_opt)
    3678                 :          0 :                 return rte_flow_error_set
    3679                 :            :                         (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, item,
    3680                 :            :                         "Geneve TLV opt not supported");
    3681                 :            :         /* Check if we already have geneve option with different type/class. */
    3682                 :          0 :         rte_spinlock_lock(&sh->geneve_tlv_opt_sl);
    3683                 :          0 :         geneve_opt_resource = sh->geneve_tlv_option_resource;
    3684         [ #  # ]:          0 :         if (geneve_opt_resource != NULL)
    3685                 :          0 :                 if (geneve_opt_resource->option_class != spec->option_class ||
    3686         [ #  # ]:          0 :                     geneve_opt_resource->option_type != spec->option_type ||
    3687                 :            :                     geneve_opt_resource->length != spec->option_len) {
    3688                 :            :                         rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
    3689                 :          0 :                         return rte_flow_error_set(error, ENOTSUP,
    3690                 :            :                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
    3691                 :            :                                 "Only one Geneve TLV option supported");
    3692                 :            :                 }
    3693                 :            :         rte_spinlock_unlock(&sh->geneve_tlv_opt_sl);
    3694                 :          0 :         return 0;
    3695                 :            : }
    3696                 :            : 
    3697                 :            : /**
    3698                 :            :  * Validate MPLS item.
    3699                 :            :  *
    3700                 :            :  * @param[in] dev
    3701                 :            :  *   Pointer to the rte_eth_dev structure.
    3702                 :            :  * @param[in] item
    3703                 :            :  *   Item specification.
    3704                 :            :  * @param[in] item_flags
    3705                 :            :  *   Bit-fields that holds the items detected until now.
    3706                 :            :  * @param[in] prev_layer
    3707                 :            :  *   The protocol layer indicated in previous item.
    3708                 :            :  * @param[out] error
    3709                 :            :  *   Pointer to error structure.
    3710                 :            :  *
    3711                 :            :  * @return
    3712                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3713                 :            :  */
    3714                 :            : int
    3715                 :          0 : mlx5_flow_validate_item_mpls(struct rte_eth_dev *dev __rte_unused,
    3716                 :            :                              const struct rte_flow_item *item __rte_unused,
    3717                 :            :                              uint64_t item_flags __rte_unused,
    3718                 :            :                              uint64_t prev_layer __rte_unused,
    3719                 :            :                              struct rte_flow_error *error)
    3720                 :            : {
    3721                 :            : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
    3722                 :          0 :         const struct rte_flow_item_mpls *mask = item->mask;
    3723                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3724                 :            :         int ret;
    3725                 :            : 
    3726         [ #  # ]:          0 :         if (!priv->sh->dev_cap.mpls_en)
    3727                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3728                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3729                 :            :                                           "MPLS not supported or"
    3730                 :            :                                           " disabled in firmware"
    3731                 :            :                                           " configuration.");
    3732                 :            :         /* MPLS over UDP, GRE is allowed */
    3733         [ #  # ]:          0 :         if (!(prev_layer & (MLX5_FLOW_LAYER_OUTER_L4_UDP |
    3734                 :            :                             MLX5_FLOW_LAYER_GRE |
    3735                 :            :                             MLX5_FLOW_LAYER_GRE_KEY)))
    3736                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3737                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3738                 :            :                                           "protocol filtering not compatible"
    3739                 :            :                                           " with MPLS layer");
    3740                 :            :         /* Multi-tunnel isn't allowed but MPLS over GRE is an exception. */
    3741         [ #  # ]:          0 :         if ((item_flags & MLX5_FLOW_LAYER_TUNNEL) &&
    3742         [ #  # ]:          0 :             !(item_flags & MLX5_FLOW_LAYER_GRE))
    3743                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3744                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3745                 :            :                                           "multiple tunnel layers not"
    3746                 :            :                                           " supported");
    3747         [ #  # ]:          0 :         if (!mask)
    3748                 :            :                 mask = &rte_flow_item_mpls_mask;
    3749                 :          0 :         ret = mlx5_flow_item_acceptable
    3750                 :            :                 (item, (const uint8_t *)mask,
    3751                 :            :                  (const uint8_t *)&rte_flow_item_mpls_mask,
    3752                 :            :                  sizeof(struct rte_flow_item_mpls),
    3753                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3754                 :            :         if (ret < 0)
    3755                 :            :                 return ret;
    3756                 :            :         return 0;
    3757                 :            : #else
    3758                 :            :         return rte_flow_error_set(error, ENOTSUP,
    3759                 :            :                                   RTE_FLOW_ERROR_TYPE_ITEM, item,
    3760                 :            :                                   "MPLS is not supported by Verbs, please"
    3761                 :            :                                   " update.");
    3762                 :            : #endif
    3763                 :            : }
    3764                 :            : 
    3765                 :            : /**
    3766                 :            :  * Validate NVGRE item.
    3767                 :            :  *
    3768                 :            :  * @param[in] item
    3769                 :            :  *   Item specification.
    3770                 :            :  * @param[in] item_flags
    3771                 :            :  *   Bit flags to mark detected items.
    3772                 :            :  * @param[in] target_protocol
    3773                 :            :  *   The next protocol in the previous item.
    3774                 :            :  * @param[out] error
    3775                 :            :  *   Pointer to error structure.
    3776                 :            :  *
    3777                 :            :  * @return
    3778                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3779                 :            :  */
    3780                 :            : int
    3781                 :          0 : mlx5_flow_validate_item_nvgre(const struct rte_flow_item *item,
    3782                 :            :                               uint64_t item_flags,
    3783                 :            :                               uint8_t target_protocol,
    3784                 :            :                               struct rte_flow_error *error)
    3785                 :            : {
    3786                 :          0 :         const struct rte_flow_item_nvgre *mask = item->mask;
    3787                 :            :         int ret;
    3788                 :            : 
    3789         [ #  # ]:          0 :         if (target_protocol != 0xff && target_protocol != IPPROTO_GRE)
    3790                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3791                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3792                 :            :                                           "protocol filtering not compatible"
    3793                 :            :                                           " with this GRE layer");
    3794         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3795                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3796                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3797                 :            :                                           "multiple tunnel layers not"
    3798                 :            :                                           " supported");
    3799         [ #  # ]:          0 :         if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3))
    3800                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3801                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3802                 :            :                                           "L3 Layer is missing");
    3803         [ #  # ]:          0 :         if (!mask)
    3804                 :            :                 mask = &rte_flow_item_nvgre_mask;
    3805                 :          0 :         ret = mlx5_flow_item_acceptable
    3806                 :            :                 (item, (const uint8_t *)mask,
    3807                 :            :                  (const uint8_t *)&rte_flow_item_nvgre_mask,
    3808                 :            :                  sizeof(struct rte_flow_item_nvgre),
    3809                 :            :                  MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3810                 :            :         if (ret < 0)
    3811                 :            :                 return ret;
    3812                 :            :         return 0;
    3813                 :            : }
    3814                 :            : 
    3815                 :            : /**
    3816                 :            :  * Validate eCPRI item.
    3817                 :            :  *
    3818                 :            :  * @param[in] item
    3819                 :            :  *   Item specification.
    3820                 :            :  * @param[in] item_flags
    3821                 :            :  *   Bit-fields that holds the items detected until now.
    3822                 :            :  * @param[in] last_item
    3823                 :            :  *   Previous validated item in the pattern items.
    3824                 :            :  * @param[in] ether_type
    3825                 :            :  *   Type in the ethernet layer header (including dot1q).
    3826                 :            :  * @param[in] acc_mask
    3827                 :            :  *   Acceptable mask, if NULL default internal default mask
    3828                 :            :  *   will be used to check whether item fields are supported.
    3829                 :            :  * @param[out] error
    3830                 :            :  *   Pointer to error structure.
    3831                 :            :  *
    3832                 :            :  * @return
    3833                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3834                 :            :  */
    3835                 :            : int
    3836                 :          0 : mlx5_flow_validate_item_ecpri(const struct rte_flow_item *item,
    3837                 :            :                               uint64_t item_flags,
    3838                 :            :                               uint64_t last_item,
    3839                 :            :                               uint16_t ether_type,
    3840                 :            :                               const struct rte_flow_item_ecpri *acc_mask,
    3841                 :            :                               struct rte_flow_error *error)
    3842                 :            : {
    3843                 :          0 :         const struct rte_flow_item_ecpri *mask = item->mask;
    3844                 :          0 :         const struct rte_flow_item_ecpri nic_mask = {
    3845                 :            :                 .hdr = {
    3846                 :            :                         .common = {
    3847                 :            :                                 .u32 =
    3848                 :            :                                 RTE_BE32(((const struct rte_ecpri_common_hdr) {
    3849                 :            :                                         .type = 0xFF,
    3850                 :            :                                         }).u32),
    3851                 :            :                         },
    3852                 :            :                         .dummy[0] = 0xFFFFFFFF,
    3853                 :            :                 },
    3854                 :            :         };
    3855                 :            :         const uint64_t outer_l2_vlan = (MLX5_FLOW_LAYER_OUTER_L2 |
    3856                 :            :                                         MLX5_FLOW_LAYER_OUTER_VLAN);
    3857                 :            :         struct rte_flow_item_ecpri mask_lo;
    3858                 :            : 
    3859   [ #  #  #  # ]:          0 :         if (!(last_item & outer_l2_vlan) &&
    3860                 :            :             last_item != MLX5_FLOW_LAYER_OUTER_L4_UDP)
    3861                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3862                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3863                 :            :                                           "eCPRI can only follow L2/VLAN layer or UDP layer");
    3864         [ #  # ]:          0 :         if ((last_item & outer_l2_vlan) && ether_type &&
    3865         [ #  # ]:          0 :             ether_type != RTE_ETHER_TYPE_ECPRI)
    3866                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3867                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3868                 :            :                                           "eCPRI cannot follow L2/VLAN layer which ether type is not 0xAEFE");
    3869         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_TUNNEL)
    3870                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3871                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3872                 :            :                                           "eCPRI with tunnel is not supported right now");
    3873         [ #  # ]:          0 :         if (item_flags & MLX5_FLOW_LAYER_OUTER_L3)
    3874                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3875                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3876                 :            :                                           "multiple L3 layers not supported");
    3877         [ #  # ]:          0 :         else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP)
    3878                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3879                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3880                 :            :                                           "eCPRI cannot coexist with a TCP layer");
    3881                 :            :         /* In specification, eCPRI could be over UDP layer. */
    3882         [ #  # ]:          0 :         else if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP)
    3883                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3884                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3885                 :            :                                           "eCPRI over UDP layer is not yet supported right now");
    3886                 :            :         /* Mask for type field in common header could be zero. */
    3887         [ #  # ]:          0 :         if (!mask)
    3888                 :            :                 mask = &rte_flow_item_ecpri_mask;
    3889         [ #  # ]:          0 :         mask_lo.hdr.common.u32 = rte_be_to_cpu_32(mask->hdr.common.u32);
    3890                 :            :         /* Input mask is in big-endian format. */
    3891         [ #  # ]:          0 :         if (mask_lo.hdr.common.type != 0 && mask_lo.hdr.common.type != 0xff)
    3892                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3893                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
    3894                 :            :                                           "partial mask is not supported for protocol");
    3895   [ #  #  #  # ]:          0 :         else if (mask_lo.hdr.common.type == 0 && mask->hdr.dummy[0] != 0)
    3896                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    3897                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM_MASK, mask,
    3898                 :            :                                           "message header mask must be after a type mask");
    3899         [ #  # ]:          0 :         return mlx5_flow_item_acceptable(item, (const uint8_t *)mask,
    3900                 :            :                                          acc_mask ? (const uint8_t *)acc_mask
    3901                 :            :                                                   : (const uint8_t *)&nic_mask,
    3902                 :            :                                          sizeof(struct rte_flow_item_ecpri),
    3903                 :            :                                          MLX5_ITEM_RANGE_NOT_ACCEPTED, error);
    3904                 :            : }
    3905                 :            : 
    3906                 :            : /**
    3907                 :            :  * Validate the NSH item.
    3908                 :            :  *
    3909                 :            :  * @param[in] dev
    3910                 :            :  *   Pointer to Ethernet device on which flow rule is being created on.
    3911                 :            :  * @param[out] error
    3912                 :            :  *   Pointer to error structure.
    3913                 :            :  *
    3914                 :            :  * @return
    3915                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    3916                 :            :  */
    3917                 :            : int
    3918                 :          0 : mlx5_flow_validate_item_nsh(struct rte_eth_dev *dev,
    3919                 :            :                             const struct rte_flow_item *item,
    3920                 :            :                             struct rte_flow_error *error)
    3921                 :            : {
    3922                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    3923                 :            : 
    3924         [ #  # ]:          0 :         if (item->mask) {
    3925                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3926                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3927                 :            :                                           "NSH fields matching is not supported");
    3928                 :            :         }
    3929                 :            : 
    3930         [ #  # ]:          0 :         if (!priv->sh->config.dv_flow_en) {
    3931                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3932                 :            :                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    3933                 :            :                                           NULL, "NSH support requires DV flow interface");
    3934                 :            :         }
    3935                 :            : 
    3936         [ #  # ]:          0 :         if (!priv->sh->cdev->config.hca_attr.tunnel_stateless_vxlan_gpe_nsh) {
    3937                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    3938                 :            :                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
    3939                 :            :                                           "Current FW does not support matching on NSH");
    3940                 :            :         }
    3941                 :            : 
    3942                 :            :         return 0;
    3943                 :            : }
    3944                 :            : 
    3945                 :            : static int
    3946                 :          0 : flow_null_validate(struct rte_eth_dev *dev __rte_unused,
    3947                 :            :                    const struct rte_flow_attr *attr __rte_unused,
    3948                 :            :                    const struct rte_flow_item items[] __rte_unused,
    3949                 :            :                    const struct rte_flow_action actions[] __rte_unused,
    3950                 :            :                    bool external __rte_unused,
    3951                 :            :                    int hairpin __rte_unused,
    3952                 :            :                    struct rte_flow_error *error)
    3953                 :            : {
    3954                 :          0 :         return rte_flow_error_set(error, ENOTSUP,
    3955                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
    3956                 :            : }
    3957                 :            : 
    3958                 :            : static struct mlx5_flow *
    3959                 :          0 : flow_null_prepare(struct rte_eth_dev *dev __rte_unused,
    3960                 :            :                   const struct rte_flow_attr *attr __rte_unused,
    3961                 :            :                   const struct rte_flow_item items[] __rte_unused,
    3962                 :            :                   const struct rte_flow_action actions[] __rte_unused,
    3963                 :            :                   struct rte_flow_error *error)
    3964                 :            : {
    3965                 :          0 :         rte_flow_error_set(error, ENOTSUP,
    3966                 :            :                            RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
    3967                 :          0 :         return NULL;
    3968                 :            : }
    3969                 :            : 
    3970                 :            : static int
    3971                 :          0 : flow_null_translate(struct rte_eth_dev *dev __rte_unused,
    3972                 :            :                     struct mlx5_flow *dev_flow __rte_unused,
    3973                 :            :                     const struct rte_flow_attr *attr __rte_unused,
    3974                 :            :                     const struct rte_flow_item items[] __rte_unused,
    3975                 :            :                     const struct rte_flow_action actions[] __rte_unused,
    3976                 :            :                     struct rte_flow_error *error)
    3977                 :            : {
    3978                 :          0 :         return rte_flow_error_set(error, ENOTSUP,
    3979                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
    3980                 :            : }
    3981                 :            : 
    3982                 :            : static int
    3983                 :          0 : flow_null_apply(struct rte_eth_dev *dev __rte_unused,
    3984                 :            :                 struct rte_flow *flow __rte_unused,
    3985                 :            :                 struct rte_flow_error *error)
    3986                 :            : {
    3987                 :          0 :         return rte_flow_error_set(error, ENOTSUP,
    3988                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
    3989                 :            : }
    3990                 :            : 
    3991                 :            : static void
    3992                 :          0 : flow_null_remove(struct rte_eth_dev *dev __rte_unused,
    3993                 :            :                  struct rte_flow *flow __rte_unused)
    3994                 :            : {
    3995                 :          0 : }
    3996                 :            : 
    3997                 :            : static void
    3998                 :          0 : flow_null_destroy(struct rte_eth_dev *dev __rte_unused,
    3999                 :            :                   struct rte_flow *flow __rte_unused)
    4000                 :            : {
    4001                 :          0 : }
    4002                 :            : 
    4003                 :            : static int
    4004                 :          0 : flow_null_query(struct rte_eth_dev *dev __rte_unused,
    4005                 :            :                 struct rte_flow *flow __rte_unused,
    4006                 :            :                 const struct rte_flow_action *actions __rte_unused,
    4007                 :            :                 void *data __rte_unused,
    4008                 :            :                 struct rte_flow_error *error)
    4009                 :            : {
    4010                 :          0 :         return rte_flow_error_set(error, ENOTSUP,
    4011                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
    4012                 :            : }
    4013                 :            : 
    4014                 :            : static int
    4015                 :          0 : flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
    4016                 :            :                       uint32_t domains __rte_unused,
    4017                 :            :                       uint32_t flags __rte_unused)
    4018                 :            : {
    4019                 :          0 :         return 0;
    4020                 :            : }
    4021                 :            : 
    4022                 :            : int
    4023                 :          0 : flow_null_get_aged_flows(struct rte_eth_dev *dev,
    4024                 :            :                     void **context __rte_unused,
    4025                 :            :                     uint32_t nb_contexts __rte_unused,
    4026                 :            :                     struct rte_flow_error *error __rte_unused)
    4027                 :            : {
    4028                 :          0 :         DRV_LOG(ERR, "port %u get aged flows is not supported.",
    4029                 :            :                 dev->data->port_id);
    4030                 :          0 :         return -ENOTSUP;
    4031                 :            : }
    4032                 :            : 
    4033                 :            : uint32_t
    4034                 :          0 : flow_null_counter_allocate(struct rte_eth_dev *dev)
    4035                 :            : {
    4036                 :          0 :         DRV_LOG(ERR, "port %u counter allocate is not supported.",
    4037                 :            :                 dev->data->port_id);
    4038                 :          0 :         return 0;
    4039                 :            : }
    4040                 :            : 
    4041                 :            : void
    4042                 :          0 : flow_null_counter_free(struct rte_eth_dev *dev,
    4043                 :            :                         uint32_t counter __rte_unused)
    4044                 :            : {
    4045                 :          0 :         DRV_LOG(ERR, "port %u counter free is not supported.",
    4046                 :            :                  dev->data->port_id);
    4047                 :          0 : }
    4048                 :            : 
    4049                 :            : int
    4050                 :          0 : flow_null_counter_query(struct rte_eth_dev *dev,
    4051                 :            :                         uint32_t counter __rte_unused,
    4052                 :            :                         bool clear __rte_unused,
    4053                 :            :                         uint64_t *pkts __rte_unused,
    4054                 :            :                         uint64_t *bytes __rte_unused,
    4055                 :            :                         void **action __rte_unused)
    4056                 :            : {
    4057                 :          0 :         DRV_LOG(ERR, "port %u counter query is not supported.",
    4058                 :            :                  dev->data->port_id);
    4059                 :          0 :         return -ENOTSUP;
    4060                 :            : }
    4061                 :            : 
    4062                 :            : /* Void driver to protect from null pointer reference. */
    4063                 :            : const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
    4064                 :            :         .validate = flow_null_validate,
    4065                 :            :         .prepare = flow_null_prepare,
    4066                 :            :         .translate = flow_null_translate,
    4067                 :            :         .apply = flow_null_apply,
    4068                 :            :         .remove = flow_null_remove,
    4069                 :            :         .destroy = flow_null_destroy,
    4070                 :            :         .query = flow_null_query,
    4071                 :            :         .sync_domain = flow_null_sync_domain,
    4072                 :            :         .get_aged_flows = flow_null_get_aged_flows,
    4073                 :            :         .counter_alloc = flow_null_counter_allocate,
    4074                 :            :         .counter_free = flow_null_counter_free,
    4075                 :            :         .counter_query = flow_null_counter_query
    4076                 :            : };
    4077                 :            : 
    4078                 :            : /**
    4079                 :            :  * Select flow driver type according to flow attributes and device
    4080                 :            :  * configuration.
    4081                 :            :  *
    4082                 :            :  * @param[in] dev
    4083                 :            :  *   Pointer to the dev structure.
    4084                 :            :  * @param[in] attr
    4085                 :            :  *   Pointer to the flow attributes.
    4086                 :            :  *
    4087                 :            :  * @return
    4088                 :            :  *   flow driver type, MLX5_FLOW_TYPE_MAX otherwise.
    4089                 :            :  */
    4090                 :            : static enum mlx5_flow_drv_type
    4091                 :          0 : flow_get_drv_type(struct rte_eth_dev *dev, const struct rte_flow_attr *attr)
    4092                 :            : {
    4093                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4094                 :            :         /* The OS can determine first a specific flow type (DV, VERBS) */
    4095                 :            :         enum mlx5_flow_drv_type type = mlx5_flow_os_get_type();
    4096                 :            : 
    4097                 :            :         if (type != MLX5_FLOW_TYPE_MAX)
    4098                 :            :                 return type;
    4099                 :            :         /*
    4100                 :            :          * Currently when dv_flow_en == 2, only HW steering engine is
    4101                 :            :          * supported. New engines can also be chosen here if ready.
    4102                 :            :          */
    4103         [ #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 2)
    4104                 :            :                 return MLX5_FLOW_TYPE_HW;
    4105         [ #  # ]:          0 :         if (!attr)
    4106                 :            :                 return MLX5_FLOW_TYPE_MIN;
    4107                 :            :         /* If no OS specific type - continue with DV/VERBS selection */
    4108   [ #  #  #  # ]:          0 :         if (attr->transfer && priv->sh->config.dv_esw_en)
    4109                 :            :                 type = MLX5_FLOW_TYPE_DV;
    4110         [ #  # ]:          0 :         if (!attr->transfer)
    4111   [ #  #  #  #  :          0 :                 type = priv->sh->config.dv_flow_en ? MLX5_FLOW_TYPE_DV :
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
    4112                 :            :                                                      MLX5_FLOW_TYPE_VERBS;
    4113                 :            :         return type;
    4114                 :            : }
    4115                 :            : 
    4116                 :            : #define flow_get_drv_ops(type) flow_drv_ops[type]
    4117                 :            : 
    4118                 :            : /**
    4119                 :            :  * Flow driver validation API. This abstracts calling driver specific functions.
    4120                 :            :  * The type of flow driver is determined according to flow attributes.
    4121                 :            :  *
    4122                 :            :  * @param[in] dev
    4123                 :            :  *   Pointer to the dev structure.
    4124                 :            :  * @param[in] attr
    4125                 :            :  *   Pointer to the flow attributes.
    4126                 :            :  * @param[in] items
    4127                 :            :  *   Pointer to the list of items.
    4128                 :            :  * @param[in] actions
    4129                 :            :  *   Pointer to the list of actions.
    4130                 :            :  * @param[in] external
    4131                 :            :  *   This flow rule is created by request external to PMD.
    4132                 :            :  * @param[in] hairpin
    4133                 :            :  *   Number of hairpin TX actions, 0 means classic flow.
    4134                 :            :  * @param[out] error
    4135                 :            :  *   Pointer to the error structure.
    4136                 :            :  *
    4137                 :            :  * @return
    4138                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    4139                 :            :  */
    4140                 :            : static inline int
    4141                 :          0 : flow_drv_validate(struct rte_eth_dev *dev,
    4142                 :            :                   const struct rte_flow_attr *attr,
    4143                 :            :                   const struct rte_flow_item items[],
    4144                 :            :                   const struct rte_flow_action actions[],
    4145                 :            :                   bool external, int hairpin, struct rte_flow_error *error)
    4146                 :            : {
    4147                 :            :         const struct mlx5_flow_driver_ops *fops;
    4148                 :          0 :         enum mlx5_flow_drv_type type = flow_get_drv_type(dev, attr);
    4149                 :            : 
    4150                 :          0 :         fops = flow_get_drv_ops(type);
    4151                 :          0 :         return fops->validate(dev, attr, items, actions, external,
    4152                 :            :                               hairpin, error);
    4153                 :            : }
    4154                 :            : 
    4155                 :            : /**
    4156                 :            :  * Flow driver preparation API. This abstracts calling driver specific
    4157                 :            :  * functions. Parent flow (rte_flow) should have driver type (drv_type). It
    4158                 :            :  * calculates the size of memory required for device flow, allocates the memory,
    4159                 :            :  * initializes the device flow and returns the pointer.
    4160                 :            :  *
    4161                 :            :  * @note
    4162                 :            :  *   This function initializes device flow structure such as dv or verbs in
    4163                 :            :  *   struct mlx5_flow. However, it is caller's responsibility to initialize the
    4164                 :            :  *   rest. For example, adding returning device flow to flow->dev_flow list and
    4165                 :            :  *   setting backward reference to the flow should be done out of this function.
    4166                 :            :  *   layers field is not filled either.
    4167                 :            :  *
    4168                 :            :  * @param[in] dev
    4169                 :            :  *   Pointer to the dev structure.
    4170                 :            :  * @param[in] attr
    4171                 :            :  *   Pointer to the flow attributes.
    4172                 :            :  * @param[in] items
    4173                 :            :  *   Pointer to the list of items.
    4174                 :            :  * @param[in] actions
    4175                 :            :  *   Pointer to the list of actions.
    4176                 :            :  * @param[in] flow_idx
    4177                 :            :  *   This memory pool index to the flow.
    4178                 :            :  * @param[out] error
    4179                 :            :  *   Pointer to the error structure.
    4180                 :            :  *
    4181                 :            :  * @return
    4182                 :            :  *   Pointer to device flow on success, otherwise NULL and rte_errno is set.
    4183                 :            :  */
    4184                 :            : static inline struct mlx5_flow *
    4185                 :            : flow_drv_prepare(struct rte_eth_dev *dev,
    4186                 :            :                  const struct rte_flow *flow,
    4187                 :            :                  const struct rte_flow_attr *attr,
    4188                 :            :                  const struct rte_flow_item items[],
    4189                 :            :                  const struct rte_flow_action actions[],
    4190                 :            :                  uint32_t flow_idx,
    4191                 :            :                  struct rte_flow_error *error)
    4192                 :            : {
    4193                 :            :         const struct mlx5_flow_driver_ops *fops;
    4194                 :          0 :         enum mlx5_flow_drv_type type = flow->drv_type;
    4195                 :            :         struct mlx5_flow *mlx5_flow = NULL;
    4196                 :            : 
    4197                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4198                 :          0 :         fops = flow_get_drv_ops(type);
    4199                 :          0 :         mlx5_flow = fops->prepare(dev, attr, items, actions, error);
    4200   [ #  #  #  #  :          0 :         if (mlx5_flow)
                   #  # ]
    4201                 :          0 :                 mlx5_flow->flow_idx = flow_idx;
    4202                 :            :         return mlx5_flow;
    4203                 :            : }
    4204                 :            : 
    4205                 :            : /**
    4206                 :            :  * Flow driver translation API. This abstracts calling driver specific
    4207                 :            :  * functions. Parent flow (rte_flow) should have driver type (drv_type). It
    4208                 :            :  * translates a generic flow into a driver flow. flow_drv_prepare() must
    4209                 :            :  * precede.
    4210                 :            :  *
    4211                 :            :  * @note
    4212                 :            :  *   dev_flow->layers could be filled as a result of parsing during translation
    4213                 :            :  *   if needed by flow_drv_apply(). dev_flow->flow->actions can also be filled
    4214                 :            :  *   if necessary. As a flow can have multiple dev_flows by RSS flow expansion,
    4215                 :            :  *   flow->actions could be overwritten even though all the expanded dev_flows
    4216                 :            :  *   have the same actions.
    4217                 :            :  *
    4218                 :            :  * @param[in] dev
    4219                 :            :  *   Pointer to the rte dev structure.
    4220                 :            :  * @param[in, out] dev_flow
    4221                 :            :  *   Pointer to the mlx5 flow.
    4222                 :            :  * @param[in] attr
    4223                 :            :  *   Pointer to the flow attributes.
    4224                 :            :  * @param[in] items
    4225                 :            :  *   Pointer to the list of items.
    4226                 :            :  * @param[in] actions
    4227                 :            :  *   Pointer to the list of actions.
    4228                 :            :  * @param[out] error
    4229                 :            :  *   Pointer to the error structure.
    4230                 :            :  *
    4231                 :            :  * @return
    4232                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    4233                 :            :  */
    4234                 :            : static inline int
    4235                 :            : flow_drv_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
    4236                 :            :                    const struct rte_flow_attr *attr,
    4237                 :            :                    const struct rte_flow_item items[],
    4238                 :            :                    const struct rte_flow_action actions[],
    4239                 :            :                    struct rte_flow_error *error)
    4240                 :            : {
    4241                 :            :         const struct mlx5_flow_driver_ops *fops;
    4242                 :          0 :         enum mlx5_flow_drv_type type = dev_flow->flow->drv_type;
    4243                 :            : 
    4244                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4245                 :          0 :         fops = flow_get_drv_ops(type);
    4246                 :          0 :         return fops->translate(dev, dev_flow, attr, items, actions, error);
    4247                 :            : }
    4248                 :            : 
    4249                 :            : /**
    4250                 :            :  * Flow driver apply API. This abstracts calling driver specific functions.
    4251                 :            :  * Parent flow (rte_flow) should have driver type (drv_type). It applies
    4252                 :            :  * translated driver flows on to device. flow_drv_translate() must precede.
    4253                 :            :  *
    4254                 :            :  * @param[in] dev
    4255                 :            :  *   Pointer to Ethernet device structure.
    4256                 :            :  * @param[in, out] flow
    4257                 :            :  *   Pointer to flow structure.
    4258                 :            :  * @param[out] error
    4259                 :            :  *   Pointer to error structure.
    4260                 :            :  *
    4261                 :            :  * @return
    4262                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    4263                 :            :  */
    4264                 :            : static inline int
    4265                 :            : flow_drv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
    4266                 :            :                struct rte_flow_error *error)
    4267                 :            : {
    4268                 :            :         const struct mlx5_flow_driver_ops *fops;
    4269                 :          0 :         enum mlx5_flow_drv_type type = flow->drv_type;
    4270                 :            : 
    4271                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4272                 :          0 :         fops = flow_get_drv_ops(type);
    4273                 :          0 :         return fops->apply(dev, flow, error);
    4274                 :            : }
    4275                 :            : 
    4276                 :            : /**
    4277                 :            :  * Flow driver destroy API. This abstracts calling driver specific functions.
    4278                 :            :  * Parent flow (rte_flow) should have driver type (drv_type). It removes a flow
    4279                 :            :  * on device and releases resources of the flow.
    4280                 :            :  *
    4281                 :            :  * @param[in] dev
    4282                 :            :  *   Pointer to Ethernet device.
    4283                 :            :  * @param[in, out] flow
    4284                 :            :  *   Pointer to flow structure.
    4285                 :            :  */
    4286                 :            : static inline void
    4287                 :            : flow_drv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
    4288                 :            : {
    4289                 :            :         const struct mlx5_flow_driver_ops *fops;
    4290                 :          0 :         enum mlx5_flow_drv_type type = flow->drv_type;
    4291                 :            : 
    4292                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4293                 :          0 :         fops = flow_get_drv_ops(type);
    4294                 :          0 :         fops->destroy(dev, flow);
    4295                 :            : }
    4296                 :            : 
    4297                 :            : /**
    4298                 :            :  * Flow driver find RSS policy tbl API. This abstracts calling driver
    4299                 :            :  * specific functions. Parent flow (rte_flow) should have driver
    4300                 :            :  * type (drv_type). It will find the RSS policy table that has the rss_desc.
    4301                 :            :  *
    4302                 :            :  * @param[in] dev
    4303                 :            :  *   Pointer to Ethernet device.
    4304                 :            :  * @param[in, out] flow
    4305                 :            :  *   Pointer to flow structure.
    4306                 :            :  * @param[in] policy
    4307                 :            :  *   Pointer to meter policy table.
    4308                 :            :  * @param[in] rss_desc
    4309                 :            :  *   Pointer to rss_desc
    4310                 :            :  */
    4311                 :            : static struct mlx5_flow_meter_sub_policy *
    4312                 :            : flow_drv_meter_sub_policy_rss_prepare(struct rte_eth_dev *dev,
    4313                 :            :                 struct rte_flow *flow,
    4314                 :            :                 struct mlx5_flow_meter_policy *policy,
    4315                 :            :                 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS])
    4316                 :            : {
    4317                 :            :         const struct mlx5_flow_driver_ops *fops;
    4318                 :          0 :         enum mlx5_flow_drv_type type = flow->drv_type;
    4319                 :            : 
    4320                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4321                 :          0 :         fops = flow_get_drv_ops(type);
    4322                 :          0 :         return fops->meter_sub_policy_rss_prepare(dev, policy, rss_desc);
    4323                 :            : }
    4324                 :            : 
    4325                 :            : /**
    4326                 :            :  * Flow driver color tag rule API. This abstracts calling driver
    4327                 :            :  * specific functions. Parent flow (rte_flow) should have driver
    4328                 :            :  * type (drv_type). It will create the color tag rules in hierarchy meter.
    4329                 :            :  *
    4330                 :            :  * @param[in] dev
    4331                 :            :  *   Pointer to Ethernet device.
    4332                 :            :  * @param[in, out] flow
    4333                 :            :  *   Pointer to flow structure.
    4334                 :            :  * @param[in] fm
    4335                 :            :  *   Pointer to flow meter structure.
    4336                 :            :  * @param[in] src_port
    4337                 :            :  *   The src port this extra rule should use.
    4338                 :            :  * @param[in] item
    4339                 :            :  *   The src port id match item.
    4340                 :            :  * @param[out] error
    4341                 :            :  *   Pointer to error structure.
    4342                 :            :  */
    4343                 :            : static int
    4344                 :            : flow_drv_mtr_hierarchy_rule_create(struct rte_eth_dev *dev,
    4345                 :            :                 struct rte_flow *flow,
    4346                 :            :                 struct mlx5_flow_meter_info *fm,
    4347                 :            :                 int32_t src_port,
    4348                 :            :                 const struct rte_flow_item *item,
    4349                 :            :                 struct rte_flow_error *error)
    4350                 :            : {
    4351                 :            :         const struct mlx5_flow_driver_ops *fops;
    4352                 :          0 :         enum mlx5_flow_drv_type type = flow->drv_type;
    4353                 :            : 
    4354                 :            :         MLX5_ASSERT(type > MLX5_FLOW_TYPE_MIN && type < MLX5_FLOW_TYPE_MAX);
    4355                 :          0 :         fops = flow_get_drv_ops(type);
    4356                 :          0 :         return fops->meter_hierarchy_rule_create(dev, fm,
    4357                 :            :                                                 src_port, item, error);
    4358                 :            : }
    4359                 :            : 
    4360                 :            : /**
    4361                 :            :  * Get RSS action from the action list.
    4362                 :            :  *
    4363                 :            :  * @param[in] dev
    4364                 :            :  *   Pointer to Ethernet device.
    4365                 :            :  * @param[in] actions
    4366                 :            :  *   Pointer to the list of actions.
    4367                 :            :  * @param[in] flow
    4368                 :            :  *   Parent flow structure pointer.
    4369                 :            :  *
    4370                 :            :  * @return
    4371                 :            :  *   Pointer to the RSS action if exist, else return NULL.
    4372                 :            :  */
    4373                 :            : static const struct rte_flow_action_rss*
    4374                 :          0 : flow_get_rss_action(struct rte_eth_dev *dev,
    4375                 :            :                     const struct rte_flow_action actions[])
    4376                 :            : {
    4377                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4378                 :            :         const struct rte_flow_action_rss *rss = NULL;
    4379                 :            :         struct mlx5_meter_policy_action_container *acg;
    4380                 :            :         struct mlx5_meter_policy_action_container *acy;
    4381                 :            : 
    4382         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    4383   [ #  #  #  # ]:          0 :                 switch (actions->type) {
    4384                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RSS:
    4385                 :          0 :                         rss = actions->conf;
    4386                 :          0 :                         break;
    4387                 :          0 :                 case RTE_FLOW_ACTION_TYPE_SAMPLE:
    4388                 :            :                 {
    4389                 :          0 :                         const struct rte_flow_action_sample *sample =
    4390                 :            :                                                                 actions->conf;
    4391                 :          0 :                         const struct rte_flow_action *act = sample->actions;
    4392         [ #  # ]:          0 :                         for (; act->type != RTE_FLOW_ACTION_TYPE_END; act++)
    4393         [ #  # ]:          0 :                                 if (act->type == RTE_FLOW_ACTION_TYPE_RSS)
    4394                 :          0 :                                         rss = act->conf;
    4395                 :            :                         break;
    4396                 :            :                 }
    4397                 :          0 :                 case RTE_FLOW_ACTION_TYPE_METER:
    4398                 :            :                 {
    4399                 :            :                         uint32_t mtr_idx;
    4400                 :            :                         struct mlx5_flow_meter_info *fm;
    4401                 :            :                         struct mlx5_flow_meter_policy *policy;
    4402                 :          0 :                         const struct rte_flow_action_meter *mtr = actions->conf;
    4403                 :            : 
    4404                 :          0 :                         fm = mlx5_flow_meter_find(priv, mtr->mtr_id, &mtr_idx);
    4405   [ #  #  #  # ]:          0 :                         if (fm && !fm->def_policy) {
    4406                 :          0 :                                 policy = mlx5_flow_meter_policy_find(dev,
    4407                 :            :                                                 fm->policy_id, NULL);
    4408                 :            :                                 MLX5_ASSERT(policy);
    4409         [ #  # ]:          0 :                                 if (policy->is_hierarchy) {
    4410                 :            :                                         policy =
    4411                 :          0 :                                 mlx5_flow_meter_hierarchy_get_final_policy(dev,
    4412                 :            :                                                                         policy);
    4413         [ #  # ]:          0 :                                         if (!policy)
    4414                 :          0 :                                                 return NULL;
    4415                 :            :                                 }
    4416         [ #  # ]:          0 :                                 if (policy->is_rss) {
    4417                 :            :                                         acg =
    4418                 :            :                                         &policy->act_cnt[RTE_COLOR_GREEN];
    4419                 :            :                                         acy =
    4420                 :            :                                         &policy->act_cnt[RTE_COLOR_YELLOW];
    4421         [ #  # ]:          0 :                                         if (acg->fate_action ==
    4422                 :            :                                             MLX5_FLOW_FATE_SHARED_RSS)
    4423                 :          0 :                                                 rss = acg->rss->conf;
    4424         [ #  # ]:          0 :                                         else if (acy->fate_action ==
    4425                 :            :                                                  MLX5_FLOW_FATE_SHARED_RSS)
    4426                 :          0 :                                                 rss = acy->rss->conf;
    4427                 :            :                                 }
    4428                 :            :                         }
    4429                 :          0 :                         break;
    4430                 :            :                 }
    4431                 :            :                 default:
    4432                 :            :                         break;
    4433                 :            :                 }
    4434                 :            :         }
    4435                 :            :         return rss;
    4436                 :            : }
    4437                 :            : 
    4438                 :            : /**
    4439                 :            :  * Get ASO age action by index.
    4440                 :            :  *
    4441                 :            :  * @param[in] dev
    4442                 :            :  *   Pointer to the Ethernet device structure.
    4443                 :            :  * @param[in] age_idx
    4444                 :            :  *   Index to the ASO age action.
    4445                 :            :  *
    4446                 :            :  * @return
    4447                 :            :  *   The specified ASO age action.
    4448                 :            :  */
    4449                 :            : struct mlx5_aso_age_action*
    4450                 :          0 : flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx)
    4451                 :            : {
    4452                 :          0 :         uint16_t pool_idx = age_idx & UINT16_MAX;
    4453                 :          0 :         uint16_t offset = (age_idx >> 16) & UINT16_MAX;
    4454                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4455                 :          0 :         struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng;
    4456                 :            :         struct mlx5_aso_age_pool *pool;
    4457                 :            : 
    4458                 :          0 :         rte_rwlock_read_lock(&mng->resize_rwl);
    4459                 :          0 :         pool = mng->pools[pool_idx];
    4460                 :            :         rte_rwlock_read_unlock(&mng->resize_rwl);
    4461                 :          0 :         return &pool->actions[offset - 1];
    4462                 :            : }
    4463                 :            : 
    4464                 :            : /* maps indirect action to translated direct in some actions array */
    4465                 :            : struct mlx5_translated_action_handle {
    4466                 :            :         struct rte_flow_action_handle *action; /**< Indirect action handle. */
    4467                 :            :         int index; /**< Index in related array of rte_flow_action. */
    4468                 :            : };
    4469                 :            : 
    4470                 :            : /**
    4471                 :            :  * Translates actions of type RTE_FLOW_ACTION_TYPE_INDIRECT to related
    4472                 :            :  * direct action if translation possible.
    4473                 :            :  * This functionality used to run same execution path for both direct and
    4474                 :            :  * indirect actions on flow create. All necessary preparations for indirect
    4475                 :            :  * action handling should be performed on *handle* actions list returned
    4476                 :            :  * from this call.
    4477                 :            :  *
    4478                 :            :  * @param[in] dev
    4479                 :            :  *   Pointer to Ethernet device.
    4480                 :            :  * @param[in] actions
    4481                 :            :  *   List of actions to translate.
    4482                 :            :  * @param[out] handle
    4483                 :            :  *   List to store translated indirect action object handles.
    4484                 :            :  * @param[in, out] indir_n
    4485                 :            :  *   Size of *handle* array. On return should be updated with number of
    4486                 :            :  *   indirect actions retrieved from the *actions* list.
    4487                 :            :  * @param[out] translated_actions
    4488                 :            :  *   List of actions where all indirect actions were translated to direct
    4489                 :            :  *   if possible. NULL if no translation took place.
    4490                 :            :  * @param[out] error
    4491                 :            :  *   Pointer to the error structure.
    4492                 :            :  *
    4493                 :            :  * @return
    4494                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    4495                 :            :  */
    4496                 :            : static int
    4497                 :          0 : flow_action_handles_translate(struct rte_eth_dev *dev,
    4498                 :            :                               const struct rte_flow_action actions[],
    4499                 :            :                               struct mlx5_translated_action_handle *handle,
    4500                 :            :                               int *indir_n,
    4501                 :            :                               struct rte_flow_action **translated_actions,
    4502                 :            :                               struct rte_flow_error *error)
    4503                 :            : {
    4504                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4505                 :            :         struct rte_flow_action *translated = NULL;
    4506                 :            :         size_t actions_size;
    4507                 :            :         int n;
    4508                 :            :         int copied_n = 0;
    4509                 :            :         struct mlx5_translated_action_handle *handle_end = NULL;
    4510                 :            : 
    4511         [ #  # ]:          0 :         for (n = 0; actions[n].type != RTE_FLOW_ACTION_TYPE_END; n++) {
    4512         [ #  # ]:          0 :                 if (actions[n].type != RTE_FLOW_ACTION_TYPE_INDIRECT)
    4513                 :          0 :                         continue;
    4514         [ #  # ]:          0 :                 if (copied_n == *indir_n) {
    4515                 :          0 :                         return rte_flow_error_set
    4516                 :            :                                 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
    4517                 :            :                                  NULL, "too many shared actions");
    4518                 :            :                 }
    4519         [ #  # ]:          0 :                 rte_memcpy(&handle[copied_n].action, &actions[n].conf,
    4520                 :            :                            sizeof(actions[n].conf));
    4521                 :          0 :                 handle[copied_n].index = n;
    4522                 :          0 :                 copied_n++;
    4523                 :            :         }
    4524                 :          0 :         n++;
    4525                 :          0 :         *indir_n = copied_n;
    4526         [ #  # ]:          0 :         if (!copied_n)
    4527                 :            :                 return 0;
    4528                 :          0 :         actions_size = sizeof(struct rte_flow_action) * n;
    4529                 :          0 :         translated = mlx5_malloc(MLX5_MEM_ZERO, actions_size, 0, SOCKET_ID_ANY);
    4530         [ #  # ]:          0 :         if (!translated) {
    4531                 :          0 :                 rte_errno = ENOMEM;
    4532                 :          0 :                 return -ENOMEM;
    4533                 :            :         }
    4534                 :            :         memcpy(translated, actions, actions_size);
    4535         [ #  # ]:          0 :         for (handle_end = handle + copied_n; handle < handle_end; handle++) {
    4536                 :            :                 struct mlx5_shared_action_rss *shared_rss;
    4537                 :          0 :                 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
    4538                 :          0 :                 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
    4539                 :          0 :                 uint32_t idx = act_idx &
    4540                 :            :                                ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
    4541                 :            : 
    4542   [ #  #  #  #  :          0 :                 switch (type) {
                   #  # ]
    4543                 :          0 :                 case MLX5_INDIRECT_ACTION_TYPE_RSS:
    4544                 :          0 :                         shared_rss = mlx5_ipool_get
    4545                 :          0 :                           (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS], idx);
    4546                 :          0 :                         translated[handle->index].type =
    4547                 :            :                                 RTE_FLOW_ACTION_TYPE_RSS;
    4548                 :          0 :                         translated[handle->index].conf =
    4549                 :          0 :                                 &shared_rss->origin;
    4550                 :          0 :                         break;
    4551                 :          0 :                 case MLX5_INDIRECT_ACTION_TYPE_COUNT:
    4552                 :          0 :                         translated[handle->index].type =
    4553                 :            :                                                 (enum rte_flow_action_type)
    4554                 :            :                                                 MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
    4555                 :          0 :                         translated[handle->index].conf = (void *)(uintptr_t)idx;
    4556                 :          0 :                         break;
    4557                 :          0 :                 case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
    4558                 :          0 :                         translated[handle->index].type =
    4559                 :            :                                                 (enum rte_flow_action_type)
    4560                 :            :                                                 MLX5_RTE_FLOW_ACTION_TYPE_METER_MARK;
    4561                 :          0 :                         translated[handle->index].conf = (void *)(uintptr_t)idx;
    4562                 :          0 :                         break;
    4563                 :          0 :                 case MLX5_INDIRECT_ACTION_TYPE_AGE:
    4564         [ #  # ]:          0 :                         if (priv->sh->flow_hit_aso_en) {
    4565                 :          0 :                                 translated[handle->index].type =
    4566                 :            :                                         (enum rte_flow_action_type)
    4567                 :            :                                         MLX5_RTE_FLOW_ACTION_TYPE_AGE;
    4568                 :          0 :                                 translated[handle->index].conf =
    4569                 :          0 :                                                          (void *)(uintptr_t)idx;
    4570                 :          0 :                                 break;
    4571                 :            :                         }
    4572                 :            :                         /* Fall-through */
    4573                 :            :                 case MLX5_INDIRECT_ACTION_TYPE_CT:
    4574         [ #  # ]:          0 :                         if (priv->sh->ct_aso_en) {
    4575                 :          0 :                                 translated[handle->index].type =
    4576                 :            :                                         RTE_FLOW_ACTION_TYPE_CONNTRACK;
    4577                 :          0 :                                 translated[handle->index].conf =
    4578                 :          0 :                                                          (void *)(uintptr_t)idx;
    4579                 :          0 :                                 break;
    4580                 :            :                         }
    4581                 :            :                         /* Fall-through */
    4582                 :            :                 default:
    4583                 :          0 :                         mlx5_free(translated);
    4584                 :          0 :                         return rte_flow_error_set
    4585                 :            :                                 (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
    4586                 :            :                                  NULL, "invalid indirect action type");
    4587                 :            :                 }
    4588                 :            :         }
    4589                 :          0 :         *translated_actions = translated;
    4590                 :          0 :         return 0;
    4591                 :            : }
    4592                 :            : 
    4593                 :            : /**
    4594                 :            :  * Get Shared RSS action from the action list.
    4595                 :            :  *
    4596                 :            :  * @param[in] dev
    4597                 :            :  *   Pointer to Ethernet device.
    4598                 :            :  * @param[in] shared
    4599                 :            :  *   Pointer to the list of actions.
    4600                 :            :  * @param[in] shared_n
    4601                 :            :  *   Actions list length.
    4602                 :            :  *
    4603                 :            :  * @return
    4604                 :            :  *   The MLX5 RSS action ID if exists, otherwise return 0.
    4605                 :            :  */
    4606                 :            : static uint32_t
    4607                 :          0 : flow_get_shared_rss_action(struct rte_eth_dev *dev,
    4608                 :            :                            struct mlx5_translated_action_handle *handle,
    4609                 :            :                            int shared_n)
    4610                 :            : {
    4611                 :            :         struct mlx5_translated_action_handle *handle_end;
    4612                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4613                 :            :         struct mlx5_shared_action_rss *shared_rss;
    4614                 :            : 
    4615                 :            : 
    4616         [ #  # ]:          0 :         for (handle_end = handle + shared_n; handle < handle_end; handle++) {
    4617                 :          0 :                 uint32_t act_idx = (uint32_t)(uintptr_t)handle->action;
    4618                 :          0 :                 uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
    4619                 :          0 :                 uint32_t idx = act_idx &
    4620                 :            :                                ((1u << MLX5_INDIRECT_ACTION_TYPE_OFFSET) - 1);
    4621         [ #  # ]:          0 :                 switch (type) {
    4622                 :          0 :                 case MLX5_INDIRECT_ACTION_TYPE_RSS:
    4623                 :          0 :                         shared_rss = mlx5_ipool_get
    4624                 :          0 :                                 (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
    4625                 :            :                                                                            idx);
    4626                 :          0 :                         __atomic_fetch_add(&shared_rss->refcnt, 1,
    4627                 :            :                                            __ATOMIC_RELAXED);
    4628                 :          0 :                         return idx;
    4629                 :            :                 default:
    4630                 :            :                         break;
    4631                 :            :                 }
    4632                 :            :         }
    4633                 :            :         return 0;
    4634                 :            : }
    4635                 :            : 
    4636                 :            : static unsigned int
    4637                 :            : find_graph_root(uint32_t rss_level)
    4638                 :            : {
    4639                 :          0 :         return rss_level < 2 ? MLX5_EXPANSION_ROOT :
    4640                 :            :                                MLX5_EXPANSION_ROOT_OUTER;
    4641                 :            : }
    4642                 :            : 
    4643                 :            : /**
    4644                 :            :  *  Get layer flags from the prefix flow.
    4645                 :            :  *
    4646                 :            :  *  Some flows may be split to several subflows, the prefix subflow gets the
    4647                 :            :  *  match items and the suffix sub flow gets the actions.
    4648                 :            :  *  Some actions need the user defined match item flags to get the detail for
    4649                 :            :  *  the action.
    4650                 :            :  *  This function helps the suffix flow to get the item layer flags from prefix
    4651                 :            :  *  subflow.
    4652                 :            :  *
    4653                 :            :  * @param[in] dev_flow
    4654                 :            :  *   Pointer the created prefix subflow.
    4655                 :            :  *
    4656                 :            :  * @return
    4657                 :            :  *   The layers get from prefix subflow.
    4658                 :            :  */
    4659                 :            : static inline uint64_t
    4660                 :          0 : flow_get_prefix_layer_flags(struct mlx5_flow *dev_flow)
    4661                 :            : {
    4662                 :            :         uint64_t layers = 0;
    4663                 :            : 
    4664                 :            :         /*
    4665                 :            :          * Layers bits could be localization, but usually the compiler will
    4666                 :            :          * help to do the optimization work for source code.
    4667                 :            :          * If no decap actions, use the layers directly.
    4668                 :            :          */
    4669         [ #  # ]:          0 :         if (!(dev_flow->act_flags & MLX5_FLOW_ACTION_DECAP))
    4670                 :          0 :                 return dev_flow->handle->layers;
    4671                 :            :         /* Convert L3 layers with decap action. */
    4672         [ #  # ]:          0 :         if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV4)
    4673                 :            :                 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
    4674         [ #  # ]:          0 :         else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L3_IPV6)
    4675                 :            :                 layers |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
    4676                 :            :         /* Convert L4 layers with decap action.  */
    4677         [ #  # ]:          0 :         if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_TCP)
    4678                 :          0 :                 layers |= MLX5_FLOW_LAYER_OUTER_L4_TCP;
    4679         [ #  # ]:          0 :         else if (dev_flow->handle->layers & MLX5_FLOW_LAYER_INNER_L4_UDP)
    4680                 :          0 :                 layers |= MLX5_FLOW_LAYER_OUTER_L4_UDP;
    4681                 :            :         return layers;
    4682                 :            : }
    4683                 :            : 
    4684                 :            : /**
    4685                 :            :  * Get metadata split action information.
    4686                 :            :  *
    4687                 :            :  * @param[in] actions
    4688                 :            :  *   Pointer to the list of actions.
    4689                 :            :  * @param[out] qrss
    4690                 :            :  *   Pointer to the return pointer.
    4691                 :            :  * @param[out] qrss_type
    4692                 :            :  *   Pointer to the action type to return. RTE_FLOW_ACTION_TYPE_END is returned
    4693                 :            :  *   if no QUEUE/RSS is found.
    4694                 :            :  * @param[out] encap_idx
    4695                 :            :  *   Pointer to the index of the encap action if exists, otherwise the last
    4696                 :            :  *   action index.
    4697                 :            :  *
    4698                 :            :  * @return
    4699                 :            :  *   Total number of actions.
    4700                 :            :  */
    4701                 :            : static int
    4702                 :          0 : flow_parse_metadata_split_actions_info(const struct rte_flow_action actions[],
    4703                 :            :                                        const struct rte_flow_action **qrss,
    4704                 :            :                                        int *encap_idx)
    4705                 :            : {
    4706                 :            :         const struct rte_flow_action_raw_encap *raw_encap;
    4707                 :            :         int actions_n = 0;
    4708                 :            :         int raw_decap_idx = -1;
    4709                 :            : 
    4710                 :          0 :         *encap_idx = -1;
    4711         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    4712   [ #  #  #  #  :          0 :                 switch (actions->type) {
                      # ]
    4713                 :          0 :                 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
    4714                 :            :                 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
    4715                 :          0 :                         *encap_idx = actions_n;
    4716                 :          0 :                         break;
    4717                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    4718                 :            :                         raw_decap_idx = actions_n;
    4719                 :          0 :                         break;
    4720                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    4721                 :          0 :                         raw_encap = actions->conf;
    4722         [ #  # ]:          0 :                         if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
    4723                 :          0 :                                 *encap_idx = raw_decap_idx != -1 ?
    4724         [ #  # ]:          0 :                                                       raw_decap_idx : actions_n;
    4725                 :            :                         break;
    4726                 :          0 :                 case RTE_FLOW_ACTION_TYPE_QUEUE:
    4727                 :            :                 case RTE_FLOW_ACTION_TYPE_RSS:
    4728                 :          0 :                         *qrss = actions;
    4729                 :          0 :                         break;
    4730                 :            :                 default:
    4731                 :            :                         break;
    4732                 :            :                 }
    4733                 :          0 :                 actions_n++;
    4734                 :            :         }
    4735         [ #  # ]:          0 :         if (*encap_idx == -1)
    4736                 :          0 :                 *encap_idx = actions_n;
    4737                 :            :         /* Count RTE_FLOW_ACTION_TYPE_END. */
    4738                 :          0 :         return actions_n + 1;
    4739                 :            : }
    4740                 :            : 
    4741                 :            : /**
    4742                 :            :  * Check if the action will change packet.
    4743                 :            :  *
    4744                 :            :  * @param dev
    4745                 :            :  *   Pointer to Ethernet device.
    4746                 :            :  * @param[in] type
    4747                 :            :  *   action type.
    4748                 :            :  *
    4749                 :            :  * @return
    4750                 :            :  *   true if action will change packet, false otherwise.
    4751                 :            :  */
    4752                 :          0 : static bool flow_check_modify_action_type(struct rte_eth_dev *dev,
    4753                 :            :                                           enum rte_flow_action_type type)
    4754                 :            : {
    4755                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4756                 :            : 
    4757      [ #  #  # ]:          0 :         switch (type) {
    4758                 :            :         case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
    4759                 :            :         case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
    4760                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
    4761                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
    4762                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
    4763                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
    4764                 :            :         case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
    4765                 :            :         case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
    4766                 :            :         case RTE_FLOW_ACTION_TYPE_DEC_TTL:
    4767                 :            :         case RTE_FLOW_ACTION_TYPE_SET_TTL:
    4768                 :            :         case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
    4769                 :            :         case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
    4770                 :            :         case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
    4771                 :            :         case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
    4772                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
    4773                 :            :         case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
    4774                 :            :         case RTE_FLOW_ACTION_TYPE_SET_META:
    4775                 :            :         case RTE_FLOW_ACTION_TYPE_SET_TAG:
    4776                 :            :         case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
    4777                 :            :         case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    4778                 :            :         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    4779                 :            :         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
    4780                 :            :         case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
    4781                 :            :         case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
    4782                 :            :         case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
    4783                 :            :         case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
    4784                 :            :         case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    4785                 :            :         case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    4786                 :            :         case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
    4787                 :            :                 return true;
    4788                 :          0 :         case RTE_FLOW_ACTION_TYPE_FLAG:
    4789                 :            :         case RTE_FLOW_ACTION_TYPE_MARK:
    4790         [ #  # ]:          0 :                 if (priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
    4791                 :            :                     priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS)
    4792                 :            :                         return true;
    4793                 :            :                 else
    4794                 :          0 :                         return false;
    4795                 :          0 :         default:
    4796                 :          0 :                 return false;
    4797                 :            :         }
    4798                 :            : }
    4799                 :            : 
    4800                 :            : /**
    4801                 :            :  * Check meter action from the action list.
    4802                 :            :  *
    4803                 :            :  * @param dev
    4804                 :            :  *   Pointer to Ethernet device.
    4805                 :            :  * @param[in] actions
    4806                 :            :  *   Pointer to the list of actions.
    4807                 :            :  * @param[out] has_mtr
    4808                 :            :  *   Pointer to the meter exist flag.
    4809                 :            :  * @param[out] has_modify
    4810                 :            :  *   Pointer to the flag showing there's packet change action.
    4811                 :            :  * @param[out] meter_id
    4812                 :            :  *   Pointer to the meter id.
    4813                 :            :  *
    4814                 :            :  * @return
    4815                 :            :  *   Total number of actions.
    4816                 :            :  */
    4817                 :            : static int
    4818                 :          0 : flow_check_meter_action(struct rte_eth_dev *dev,
    4819                 :            :                         const struct rte_flow_action actions[],
    4820                 :            :                         bool *has_mtr, bool *has_modify, uint32_t *meter_id)
    4821                 :            : {
    4822                 :            :         const struct rte_flow_action_meter *mtr = NULL;
    4823                 :            :         int actions_n = 0;
    4824                 :            : 
    4825                 :            :         MLX5_ASSERT(has_mtr);
    4826                 :          0 :         *has_mtr = false;
    4827         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    4828         [ #  # ]:          0 :                 switch (actions->type) {
    4829                 :          0 :                 case RTE_FLOW_ACTION_TYPE_METER:
    4830                 :          0 :                         mtr = actions->conf;
    4831                 :          0 :                         *meter_id = mtr->mtr_id;
    4832                 :          0 :                         *has_mtr = true;
    4833                 :          0 :                         break;
    4834                 :            :                 default:
    4835                 :            :                         break;
    4836                 :            :                 }
    4837         [ #  # ]:          0 :                 if (!*has_mtr)
    4838                 :          0 :                         *has_modify |= flow_check_modify_action_type(dev,
    4839                 :          0 :                                                                 actions->type);
    4840                 :          0 :                 actions_n++;
    4841                 :            :         }
    4842                 :            :         /* Count RTE_FLOW_ACTION_TYPE_END. */
    4843                 :          0 :         return actions_n + 1;
    4844                 :            : }
    4845                 :            : 
    4846                 :            : /**
    4847                 :            :  * Check if the flow should be split due to hairpin.
    4848                 :            :  * The reason for the split is that in current HW we can't
    4849                 :            :  * support encap and push-vlan on Rx, so if a flow contains
    4850                 :            :  * these actions we move it to Tx.
    4851                 :            :  *
    4852                 :            :  * @param dev
    4853                 :            :  *   Pointer to Ethernet device.
    4854                 :            :  * @param[in] attr
    4855                 :            :  *   Flow rule attributes.
    4856                 :            :  * @param[in] actions
    4857                 :            :  *   Associated actions (list terminated by the END action).
    4858                 :            :  *
    4859                 :            :  * @return
    4860                 :            :  *   > 0 the number of actions and the flow should be split,
    4861                 :            :  *   0 when no split required.
    4862                 :            :  */
    4863                 :            : static int
    4864                 :          0 : flow_check_hairpin_split(struct rte_eth_dev *dev,
    4865                 :            :                          const struct rte_flow_attr *attr,
    4866                 :            :                          const struct rte_flow_action actions[])
    4867                 :            : {
    4868                 :            :         int queue_action = 0;
    4869                 :            :         int action_n = 0;
    4870                 :            :         int split = 0;
    4871                 :            :         int push_vlan = 0;
    4872                 :            :         const struct rte_flow_action_queue *queue;
    4873                 :            :         const struct rte_flow_action_rss *rss;
    4874                 :            :         const struct rte_flow_action_raw_encap *raw_encap;
    4875                 :            :         const struct rte_eth_hairpin_conf *conf;
    4876                 :            : 
    4877         [ #  # ]:          0 :         if (!attr->ingress)
    4878                 :            :                 return 0;
    4879         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    4880         [ #  # ]:          0 :                 if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
    4881                 :            :                         push_vlan = 1;
    4882   [ #  #  #  #  :          0 :                 switch (actions->type) {
                   #  # ]
    4883                 :          0 :                 case RTE_FLOW_ACTION_TYPE_QUEUE:
    4884                 :          0 :                         queue = actions->conf;
    4885         [ #  # ]:          0 :                         if (queue == NULL)
    4886                 :            :                                 return 0;
    4887                 :          0 :                         conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
    4888   [ #  #  #  # ]:          0 :                         if (conf == NULL || conf->tx_explicit != 0)
    4889                 :            :                                 return 0;
    4890                 :            :                         queue_action = 1;
    4891                 :          0 :                         action_n++;
    4892                 :          0 :                         break;
    4893                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RSS:
    4894                 :          0 :                         rss = actions->conf;
    4895   [ #  #  #  # ]:          0 :                         if (rss == NULL || rss->queue_num == 0)
    4896                 :            :                                 return 0;
    4897                 :          0 :                         conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
    4898   [ #  #  #  # ]:          0 :                         if (conf == NULL || conf->tx_explicit != 0)
    4899                 :            :                                 return 0;
    4900                 :            :                         queue_action = 1;
    4901                 :          0 :                         action_n++;
    4902                 :          0 :                         break;
    4903                 :          0 :                 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
    4904                 :            :                 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
    4905                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    4906                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
    4907                 :          0 :                         split++;
    4908                 :          0 :                         action_n++;
    4909                 :          0 :                         break;
    4910                 :          0 :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    4911         [ #  # ]:          0 :                         if (push_vlan)
    4912                 :          0 :                                 split++;
    4913                 :          0 :                         action_n++;
    4914                 :          0 :                         break;
    4915                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    4916                 :          0 :                         raw_encap = actions->conf;
    4917         [ #  # ]:          0 :                         if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
    4918                 :          0 :                                 split++;
    4919                 :          0 :                         action_n++;
    4920                 :          0 :                         break;
    4921                 :          0 :                 default:
    4922                 :          0 :                         action_n++;
    4923                 :          0 :                         break;
    4924                 :            :                 }
    4925                 :            :         }
    4926         [ #  # ]:          0 :         if (split && queue_action)
    4927                 :          0 :                 return action_n;
    4928                 :            :         return 0;
    4929                 :            : }
    4930                 :            : 
    4931                 :            : /* Declare flow create/destroy prototype in advance. */
    4932                 :            : static uint32_t
    4933                 :            : flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
    4934                 :            :                  const struct rte_flow_attr *attr,
    4935                 :            :                  const struct rte_flow_item items[],
    4936                 :            :                  const struct rte_flow_action actions[],
    4937                 :            :                  bool external, struct rte_flow_error *error);
    4938                 :            : 
    4939                 :            : static void
    4940                 :            : flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
    4941                 :            :                   uint32_t flow_idx);
    4942                 :            : 
    4943                 :            : int
    4944                 :          0 : flow_dv_mreg_match_cb(void *tool_ctx __rte_unused,
    4945                 :            :                       struct mlx5_list_entry *entry, void *cb_ctx)
    4946                 :            : {
    4947                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
    4948                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res =
    4949                 :            :                                container_of(entry, typeof(*mcp_res), hlist_ent);
    4950                 :            : 
    4951                 :          0 :         return mcp_res->mark_id != *(uint32_t *)(ctx->data);
    4952                 :            : }
    4953                 :            : 
    4954                 :            : struct mlx5_list_entry *
    4955                 :          0 : flow_dv_mreg_create_cb(void *tool_ctx, void *cb_ctx)
    4956                 :            : {
    4957                 :            :         struct rte_eth_dev *dev = tool_ctx;
    4958                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    4959                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
    4960                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res;
    4961                 :          0 :         struct rte_flow_error *error = ctx->error;
    4962                 :          0 :         uint32_t idx = 0;
    4963                 :            :         int ret;
    4964                 :          0 :         uint32_t mark_id = *(uint32_t *)(ctx->data);
    4965                 :          0 :         struct rte_flow_attr attr = {
    4966                 :            :                 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
    4967                 :            :                 .ingress = 1,
    4968                 :            :         };
    4969                 :          0 :         struct mlx5_rte_flow_item_tag tag_spec = {
    4970                 :            :                 .data = mark_id,
    4971                 :            :         };
    4972                 :          0 :         struct rte_flow_item items[] = {
    4973                 :            :                 [1] = { .type = RTE_FLOW_ITEM_TYPE_END, },
    4974                 :            :         };
    4975                 :          0 :         struct rte_flow_action_mark ftag = {
    4976                 :            :                 .id = mark_id,
    4977                 :            :         };
    4978                 :          0 :         struct mlx5_flow_action_copy_mreg cp_mreg = {
    4979                 :            :                 .dst = REG_B,
    4980                 :            :                 .src = REG_NON,
    4981                 :            :         };
    4982                 :          0 :         struct rte_flow_action_jump jump = {
    4983                 :            :                 .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
    4984                 :            :         };
    4985                 :          0 :         struct rte_flow_action actions[] = {
    4986                 :            :                 [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
    4987                 :            :         };
    4988                 :            : 
    4989                 :            :         /* Fill the register fields in the flow. */
    4990                 :          0 :         ret = mlx5_flow_get_reg_id(dev, MLX5_FLOW_MARK, 0, error);
    4991         [ #  # ]:          0 :         if (ret < 0)
    4992                 :            :                 return NULL;
    4993                 :          0 :         tag_spec.id = ret;
    4994                 :          0 :         ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
    4995         [ #  # ]:          0 :         if (ret < 0)
    4996                 :            :                 return NULL;
    4997                 :          0 :         cp_mreg.src = ret;
    4998                 :            :         /* Provide the full width of FLAG specific value. */
    4999         [ #  # ]:          0 :         if (mark_id == (priv->sh->dv_regc0_mask & MLX5_FLOW_MARK_DEFAULT))
    5000                 :          0 :                 tag_spec.data = MLX5_FLOW_MARK_DEFAULT;
    5001                 :            :         /* Build a new flow. */
    5002         [ #  # ]:          0 :         if (mark_id != MLX5_DEFAULT_COPY_ID) {
    5003                 :          0 :                 items[0] = (struct rte_flow_item){
    5004                 :            :                         .type = (enum rte_flow_item_type)
    5005                 :            :                                 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
    5006                 :            :                         .spec = &tag_spec,
    5007                 :            :                 };
    5008                 :          0 :                 items[1] = (struct rte_flow_item){
    5009                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    5010                 :            :                 };
    5011                 :          0 :                 actions[0] = (struct rte_flow_action){
    5012                 :            :                         .type = (enum rte_flow_action_type)
    5013                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_MARK,
    5014                 :            :                         .conf = &ftag,
    5015                 :            :                 };
    5016                 :          0 :                 actions[1] = (struct rte_flow_action){
    5017                 :            :                         .type = (enum rte_flow_action_type)
    5018                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
    5019                 :            :                         .conf = &cp_mreg,
    5020                 :            :                 };
    5021                 :          0 :                 actions[2] = (struct rte_flow_action){
    5022                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
    5023                 :            :                         .conf = &jump,
    5024                 :            :                 };
    5025                 :          0 :                 actions[3] = (struct rte_flow_action){
    5026                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    5027                 :            :                 };
    5028                 :            :         } else {
    5029                 :            :                 /* Default rule, wildcard match. */
    5030                 :          0 :                 attr.priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR;
    5031                 :          0 :                 items[0] = (struct rte_flow_item){
    5032                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    5033                 :            :                 };
    5034                 :          0 :                 actions[0] = (struct rte_flow_action){
    5035                 :            :                         .type = (enum rte_flow_action_type)
    5036                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
    5037                 :            :                         .conf = &cp_mreg,
    5038                 :            :                 };
    5039                 :          0 :                 actions[1] = (struct rte_flow_action){
    5040                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
    5041                 :            :                         .conf = &jump,
    5042                 :            :                 };
    5043                 :          0 :                 actions[2] = (struct rte_flow_action){
    5044                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    5045                 :            :                 };
    5046                 :            :         }
    5047                 :            :         /* Build a new entry. */
    5048                 :          0 :         mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
    5049         [ #  # ]:          0 :         if (!mcp_res) {
    5050                 :          0 :                 rte_errno = ENOMEM;
    5051                 :          0 :                 return NULL;
    5052                 :            :         }
    5053                 :          0 :         mcp_res->idx = idx;
    5054                 :          0 :         mcp_res->mark_id = mark_id;
    5055                 :            :         /*
    5056                 :            :          * The copy Flows are not included in any list. There
    5057                 :            :          * ones are referenced from other Flows and can not
    5058                 :            :          * be applied, removed, deleted in arbitrary order
    5059                 :            :          * by list traversing.
    5060                 :            :          */
    5061                 :          0 :         mcp_res->rix_flow = flow_list_create(dev, MLX5_FLOW_TYPE_MCP,
    5062                 :            :                                         &attr, items, actions, false, error);
    5063         [ #  # ]:          0 :         if (!mcp_res->rix_flow) {
    5064                 :          0 :                 mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], idx);
    5065                 :          0 :                 return NULL;
    5066                 :            :         }
    5067                 :          0 :         return &mcp_res->hlist_ent;
    5068                 :            : }
    5069                 :            : 
    5070                 :            : struct mlx5_list_entry *
    5071                 :          0 : flow_dv_mreg_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry,
    5072                 :            :                       void *cb_ctx __rte_unused)
    5073                 :            : {
    5074                 :            :         struct rte_eth_dev *dev = tool_ctx;
    5075                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5076                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res;
    5077                 :          0 :         uint32_t idx = 0;
    5078                 :            : 
    5079                 :          0 :         mcp_res = mlx5_ipool_malloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
    5080         [ #  # ]:          0 :         if (!mcp_res) {
    5081                 :          0 :                 rte_errno = ENOMEM;
    5082                 :          0 :                 return NULL;
    5083                 :            :         }
    5084                 :            :         memcpy(mcp_res, oentry, sizeof(*mcp_res));
    5085                 :          0 :         mcp_res->idx = idx;
    5086                 :          0 :         return &mcp_res->hlist_ent;
    5087                 :            : }
    5088                 :            : 
    5089                 :            : void
    5090                 :          0 : flow_dv_mreg_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry)
    5091                 :            : {
    5092                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res =
    5093                 :            :                                container_of(entry, typeof(*mcp_res), hlist_ent);
    5094                 :            :         struct rte_eth_dev *dev = tool_ctx;
    5095                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5096                 :            : 
    5097                 :          0 :         mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
    5098                 :          0 : }
    5099                 :            : 
    5100                 :            : /**
    5101                 :            :  * Add a flow of copying flow metadata registers in RX_CP_TBL.
    5102                 :            :  *
    5103                 :            :  * As mark_id is unique, if there's already a registered flow for the mark_id,
    5104                 :            :  * return by increasing the reference counter of the resource. Otherwise, create
    5105                 :            :  * the resource (mcp_res) and flow.
    5106                 :            :  *
    5107                 :            :  * Flow looks like,
    5108                 :            :  *   - If ingress port is ANY and reg_c[1] is mark_id,
    5109                 :            :  *     flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
    5110                 :            :  *
    5111                 :            :  * For default flow (zero mark_id), flow is like,
    5112                 :            :  *   - If ingress port is ANY,
    5113                 :            :  *     reg_b := reg_c[0] and jump to RX_ACT_TBL.
    5114                 :            :  *
    5115                 :            :  * @param dev
    5116                 :            :  *   Pointer to Ethernet device.
    5117                 :            :  * @param mark_id
    5118                 :            :  *   ID of MARK action, zero means default flow for META.
    5119                 :            :  * @param[out] error
    5120                 :            :  *   Perform verbose error reporting if not NULL.
    5121                 :            :  *
    5122                 :            :  * @return
    5123                 :            :  *   Associated resource on success, NULL otherwise and rte_errno is set.
    5124                 :            :  */
    5125                 :            : static struct mlx5_flow_mreg_copy_resource *
    5126                 :          0 : flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
    5127                 :            :                           struct rte_flow_error *error)
    5128                 :            : {
    5129                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5130                 :            :         struct mlx5_list_entry *entry;
    5131                 :          0 :         struct mlx5_flow_cb_ctx ctx = {
    5132                 :            :                 .dev = dev,
    5133                 :            :                 .error = error,
    5134                 :            :                 .data = &mark_id,
    5135                 :            :         };
    5136                 :            : 
    5137                 :            :         /* Check if already registered. */
    5138                 :            :         MLX5_ASSERT(priv->mreg_cp_tbl);
    5139                 :          0 :         entry = mlx5_hlist_register(priv->mreg_cp_tbl, mark_id, &ctx);
    5140         [ #  # ]:          0 :         if (!entry)
    5141                 :          0 :                 return NULL;
    5142                 :            :         return container_of(entry, struct mlx5_flow_mreg_copy_resource,
    5143                 :            :                             hlist_ent);
    5144                 :            : }
    5145                 :            : 
    5146                 :            : void
    5147                 :          0 : flow_dv_mreg_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry)
    5148                 :            : {
    5149                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res =
    5150                 :            :                                container_of(entry, typeof(*mcp_res), hlist_ent);
    5151                 :            :         struct rte_eth_dev *dev = tool_ctx;
    5152                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5153                 :            : 
    5154                 :            :         MLX5_ASSERT(mcp_res->rix_flow);
    5155                 :          0 :         flow_list_destroy(dev, MLX5_FLOW_TYPE_MCP, mcp_res->rix_flow);
    5156                 :          0 :         mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
    5157                 :          0 : }
    5158                 :            : 
    5159                 :            : /**
    5160                 :            :  * Release flow in RX_CP_TBL.
    5161                 :            :  *
    5162                 :            :  * @param dev
    5163                 :            :  *   Pointer to Ethernet device.
    5164                 :            :  * @flow
    5165                 :            :  *   Parent flow for wich copying is provided.
    5166                 :            :  */
    5167                 :            : static void
    5168                 :          0 : flow_mreg_del_copy_action(struct rte_eth_dev *dev,
    5169                 :            :                           struct rte_flow *flow)
    5170                 :            : {
    5171                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res;
    5172                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5173                 :            : 
    5174         [ #  # ]:          0 :         if (!flow->rix_mreg_copy)
    5175                 :            :                 return;
    5176                 :          0 :         mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
    5177                 :            :                                  flow->rix_mreg_copy);
    5178   [ #  #  #  # ]:          0 :         if (!mcp_res || !priv->mreg_cp_tbl)
    5179                 :            :                 return;
    5180                 :            :         MLX5_ASSERT(mcp_res->rix_flow);
    5181                 :          0 :         mlx5_hlist_unregister(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
    5182                 :          0 :         flow->rix_mreg_copy = 0;
    5183                 :            : }
    5184                 :            : 
    5185                 :            : /**
    5186                 :            :  * Remove the default copy action from RX_CP_TBL.
    5187                 :            :  *
    5188                 :            :  * This functions is called in the mlx5_dev_start(). No thread safe
    5189                 :            :  * is guaranteed.
    5190                 :            :  *
    5191                 :            :  * @param dev
    5192                 :            :  *   Pointer to Ethernet device.
    5193                 :            :  */
    5194                 :            : static void
    5195                 :          0 : flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
    5196                 :            : {
    5197                 :            :         struct mlx5_list_entry *entry;
    5198                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5199                 :            :         struct mlx5_flow_cb_ctx ctx;
    5200                 :            :         uint32_t mark_id;
    5201                 :            : 
    5202                 :            :         /* Check if default flow is registered. */
    5203         [ #  # ]:          0 :         if (!priv->mreg_cp_tbl)
    5204                 :          0 :                 return;
    5205                 :          0 :         mark_id = MLX5_DEFAULT_COPY_ID;
    5206                 :          0 :         ctx.data = &mark_id;
    5207                 :          0 :         entry = mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx);
    5208         [ #  # ]:          0 :         if (!entry)
    5209                 :            :                 return;
    5210                 :          0 :         mlx5_hlist_unregister(priv->mreg_cp_tbl, entry);
    5211                 :            : }
    5212                 :            : 
    5213                 :            : /**
    5214                 :            :  * Add the default copy action in RX_CP_TBL.
    5215                 :            :  *
    5216                 :            :  * This functions is called in the mlx5_dev_start(). No thread safe
    5217                 :            :  * is guaranteed.
    5218                 :            :  *
    5219                 :            :  * @param dev
    5220                 :            :  *   Pointer to Ethernet device.
    5221                 :            :  * @param[out] error
    5222                 :            :  *   Perform verbose error reporting if not NULL.
    5223                 :            :  *
    5224                 :            :  * @return
    5225                 :            :  *   0 for success, negative value otherwise and rte_errno is set.
    5226                 :            :  */
    5227                 :            : static int
    5228                 :          0 : flow_mreg_add_default_copy_action(struct rte_eth_dev *dev,
    5229                 :            :                                   struct rte_flow_error *error)
    5230                 :            : {
    5231                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5232                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res;
    5233                 :            :         struct mlx5_flow_cb_ctx ctx;
    5234                 :            :         uint32_t mark_id;
    5235                 :            : 
    5236                 :            :         /* Check whether extensive metadata feature is engaged. */
    5237         [ #  # ]:          0 :         if (!priv->sh->config.dv_flow_en ||
    5238   [ #  #  #  # ]:          0 :             priv->sh->config.dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
    5239                 :          0 :             !mlx5_flow_ext_mreg_supported(dev) ||
    5240         [ #  # ]:          0 :             !priv->sh->dv_regc0_mask)
    5241                 :          0 :                 return 0;
    5242                 :            :         /*
    5243                 :            :          * Add default mreg copy flow may be called multiple time, but
    5244                 :            :          * only be called once in stop. Avoid register it twice.
    5245                 :            :          */
    5246                 :          0 :         mark_id = MLX5_DEFAULT_COPY_ID;
    5247                 :          0 :         ctx.data = &mark_id;
    5248         [ #  # ]:          0 :         if (mlx5_hlist_lookup(priv->mreg_cp_tbl, mark_id, &ctx))
    5249                 :            :                 return 0;
    5250                 :          0 :         mcp_res = flow_mreg_add_copy_action(dev, mark_id, error);
    5251         [ #  # ]:          0 :         if (!mcp_res)
    5252                 :          0 :                 return -rte_errno;
    5253                 :            :         return 0;
    5254                 :            : }
    5255                 :            : 
    5256                 :            : /**
    5257                 :            :  * Add a flow of copying flow metadata registers in RX_CP_TBL.
    5258                 :            :  *
    5259                 :            :  * All the flow having Q/RSS action should be split by
    5260                 :            :  * flow_mreg_split_qrss_prep() to pass by RX_CP_TBL. A flow in the RX_CP_TBL
    5261                 :            :  * performs the following,
    5262                 :            :  *   - CQE->flow_tag := reg_c[1] (MARK)
    5263                 :            :  *   - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
    5264                 :            :  * As CQE's flow_tag is not a register, it can't be simply copied from reg_c[1]
    5265                 :            :  * but there should be a flow per each MARK ID set by MARK action.
    5266                 :            :  *
    5267                 :            :  * For the aforementioned reason, if there's a MARK action in flow's action
    5268                 :            :  * list, a corresponding flow should be added to the RX_CP_TBL in order to copy
    5269                 :            :  * the MARK ID to CQE's flow_tag like,
    5270                 :            :  *   - If reg_c[1] is mark_id,
    5271                 :            :  *     flow_tag := mark_id, reg_b := reg_c[0] and jump to RX_ACT_TBL.
    5272                 :            :  *
    5273                 :            :  * For SET_META action which stores value in reg_c[0], as the destination is
    5274                 :            :  * also a flow metadata register (reg_b), adding a default flow is enough. Zero
    5275                 :            :  * MARK ID means the default flow. The default flow looks like,
    5276                 :            :  *   - For all flow, reg_b := reg_c[0] and jump to RX_ACT_TBL.
    5277                 :            :  *
    5278                 :            :  * @param dev
    5279                 :            :  *   Pointer to Ethernet device.
    5280                 :            :  * @param flow
    5281                 :            :  *   Pointer to flow structure.
    5282                 :            :  * @param[in] actions
    5283                 :            :  *   Pointer to the list of actions.
    5284                 :            :  * @param[out] error
    5285                 :            :  *   Perform verbose error reporting if not NULL.
    5286                 :            :  *
    5287                 :            :  * @return
    5288                 :            :  *   0 on success, negative value otherwise and rte_errno is set.
    5289                 :            :  */
    5290                 :            : static int
    5291                 :          0 : flow_mreg_update_copy_table(struct rte_eth_dev *dev,
    5292                 :            :                             struct rte_flow *flow,
    5293                 :            :                             const struct rte_flow_action *actions,
    5294                 :            :                             struct rte_flow_error *error)
    5295                 :            : {
    5296                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5297                 :          0 :         struct mlx5_sh_config *config = &priv->sh->config;
    5298                 :            :         struct mlx5_flow_mreg_copy_resource *mcp_res;
    5299                 :            :         const struct rte_flow_action_mark *mark;
    5300                 :            : 
    5301                 :            :         /* Check whether extensive metadata feature is engaged. */
    5302         [ #  # ]:          0 :         if (!config->dv_flow_en ||
    5303   [ #  #  #  # ]:          0 :             config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
    5304                 :          0 :             !mlx5_flow_ext_mreg_supported(dev) ||
    5305         [ #  # ]:          0 :             !priv->sh->dv_regc0_mask)
    5306                 :          0 :                 return 0;
    5307                 :            :         /* Find MARK action. */
    5308         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    5309      [ #  #  # ]:          0 :                 switch (actions->type) {
    5310                 :          0 :                 case RTE_FLOW_ACTION_TYPE_FLAG:
    5311                 :          0 :                         mcp_res = flow_mreg_add_copy_action
    5312                 :            :                                 (dev, MLX5_FLOW_MARK_DEFAULT, error);
    5313         [ #  # ]:          0 :                         if (!mcp_res)
    5314                 :          0 :                                 return -rte_errno;
    5315                 :          0 :                         flow->rix_mreg_copy = mcp_res->idx;
    5316                 :          0 :                         return 0;
    5317                 :          0 :                 case RTE_FLOW_ACTION_TYPE_MARK:
    5318                 :          0 :                         mark = (const struct rte_flow_action_mark *)
    5319                 :            :                                 actions->conf;
    5320                 :            :                         mcp_res =
    5321                 :          0 :                                 flow_mreg_add_copy_action(dev, mark->id, error);
    5322         [ #  # ]:          0 :                         if (!mcp_res)
    5323                 :          0 :                                 return -rte_errno;
    5324                 :          0 :                         flow->rix_mreg_copy = mcp_res->idx;
    5325                 :          0 :                         return 0;
    5326                 :            :                 default:
    5327                 :            :                         break;
    5328                 :            :                 }
    5329                 :            :         }
    5330                 :            :         return 0;
    5331                 :            : }
    5332                 :            : 
    5333                 :            : #define MLX5_MAX_SPLIT_ACTIONS 24
    5334                 :            : #define MLX5_MAX_SPLIT_ITEMS 24
    5335                 :            : 
    5336                 :            : /**
    5337                 :            :  * Split the hairpin flow.
    5338                 :            :  * Since HW can't support encap and push-vlan on Rx, we move these
    5339                 :            :  * actions to Tx.
    5340                 :            :  * If the count action is after the encap then we also
    5341                 :            :  * move the count action. in this case the count will also measure
    5342                 :            :  * the outer bytes.
    5343                 :            :  *
    5344                 :            :  * @param dev
    5345                 :            :  *   Pointer to Ethernet device.
    5346                 :            :  * @param[in] actions
    5347                 :            :  *   Associated actions (list terminated by the END action).
    5348                 :            :  * @param[out] actions_rx
    5349                 :            :  *   Rx flow actions.
    5350                 :            :  * @param[out] actions_tx
    5351                 :            :  *   Tx flow actions..
    5352                 :            :  * @param[out] pattern_tx
    5353                 :            :  *   The pattern items for the Tx flow.
    5354                 :            :  * @param[out] flow_id
    5355                 :            :  *   The flow ID connected to this flow.
    5356                 :            :  *
    5357                 :            :  * @return
    5358                 :            :  *   0 on success.
    5359                 :            :  */
    5360                 :            : static int
    5361                 :          0 : flow_hairpin_split(struct rte_eth_dev *dev,
    5362                 :            :                    const struct rte_flow_action actions[],
    5363                 :            :                    struct rte_flow_action actions_rx[],
    5364                 :            :                    struct rte_flow_action actions_tx[],
    5365                 :            :                    struct rte_flow_item pattern_tx[],
    5366                 :            :                    uint32_t flow_id)
    5367                 :            : {
    5368                 :            :         const struct rte_flow_action_raw_encap *raw_encap;
    5369                 :            :         const struct rte_flow_action_raw_decap *raw_decap;
    5370                 :            :         struct mlx5_rte_flow_action_set_tag *set_tag;
    5371                 :            :         struct rte_flow_action *tag_action;
    5372                 :            :         struct mlx5_rte_flow_item_tag *tag_item;
    5373                 :            :         struct rte_flow_item *item;
    5374                 :            :         char *addr;
    5375                 :            :         int push_vlan = 0;
    5376                 :            :         int encap = 0;
    5377                 :            : 
    5378         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    5379         [ #  # ]:          0 :                 if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)
    5380                 :            :                         push_vlan = 1;
    5381   [ #  #  #  #  :          0 :                 switch (actions->type) {
                   #  # ]
    5382                 :            :                 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
    5383                 :            :                 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
    5384                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    5385                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
    5386                 :            :                         rte_memcpy(actions_tx, actions,
    5387                 :            :                                sizeof(struct rte_flow_action));
    5388                 :          0 :                         actions_tx++;
    5389                 :          0 :                         break;
    5390                 :          0 :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    5391         [ #  # ]:          0 :                         if (push_vlan) {
    5392                 :            :                                 rte_memcpy(actions_tx, actions,
    5393                 :            :                                            sizeof(struct rte_flow_action));
    5394                 :          0 :                                 actions_tx++;
    5395                 :            :                         } else {
    5396                 :            :                                 rte_memcpy(actions_rx, actions,
    5397                 :            :                                            sizeof(struct rte_flow_action));
    5398                 :          0 :                                 actions_rx++;
    5399                 :            :                         }
    5400                 :            :                         break;
    5401                 :          0 :                 case RTE_FLOW_ACTION_TYPE_COUNT:
    5402                 :            :                 case RTE_FLOW_ACTION_TYPE_AGE:
    5403         [ #  # ]:          0 :                         if (encap) {
    5404                 :            :                                 rte_memcpy(actions_tx, actions,
    5405                 :            :                                            sizeof(struct rte_flow_action));
    5406                 :          0 :                                 actions_tx++;
    5407                 :            :                         } else {
    5408                 :            :                                 rte_memcpy(actions_rx, actions,
    5409                 :            :                                            sizeof(struct rte_flow_action));
    5410                 :          0 :                                 actions_rx++;
    5411                 :            :                         }
    5412                 :            :                         break;
    5413                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    5414                 :          0 :                         raw_encap = actions->conf;
    5415         [ #  # ]:          0 :                         if (raw_encap->size > MLX5_ENCAPSULATION_DECISION_SIZE) {
    5416                 :            :                                 memcpy(actions_tx, actions,
    5417                 :            :                                        sizeof(struct rte_flow_action));
    5418                 :          0 :                                 actions_tx++;
    5419                 :            :                                 encap = 1;
    5420                 :            :                         } else {
    5421                 :            :                                 rte_memcpy(actions_rx, actions,
    5422                 :            :                                            sizeof(struct rte_flow_action));
    5423                 :          0 :                                 actions_rx++;
    5424                 :            :                         }
    5425                 :            :                         break;
    5426                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    5427                 :          0 :                         raw_decap = actions->conf;
    5428         [ #  # ]:          0 :                         if (raw_decap->size < MLX5_ENCAPSULATION_DECISION_SIZE) {
    5429                 :            :                                 memcpy(actions_tx, actions,
    5430                 :            :                                        sizeof(struct rte_flow_action));
    5431                 :          0 :                                 actions_tx++;
    5432                 :            :                         } else {
    5433                 :            :                                 rte_memcpy(actions_rx, actions,
    5434                 :            :                                            sizeof(struct rte_flow_action));
    5435                 :          0 :                                 actions_rx++;
    5436                 :            :                         }
    5437                 :            :                         break;
    5438                 :            :                 default:
    5439                 :            :                         rte_memcpy(actions_rx, actions,
    5440                 :            :                                    sizeof(struct rte_flow_action));
    5441                 :          0 :                         actions_rx++;
    5442                 :          0 :                         break;
    5443                 :            :                 }
    5444                 :            :         }
    5445                 :            :         /* Add set meta action and end action for the Rx flow. */
    5446                 :            :         tag_action = actions_rx;
    5447                 :          0 :         tag_action->type = (enum rte_flow_action_type)
    5448                 :            :                            MLX5_RTE_FLOW_ACTION_TYPE_TAG;
    5449         [ #  # ]:          0 :         actions_rx++;
    5450                 :            :         rte_memcpy(actions_rx, actions, sizeof(struct rte_flow_action));
    5451                 :          0 :         actions_rx++;
    5452                 :            :         set_tag = (void *)actions_rx;
    5453                 :          0 :         *set_tag = (struct mlx5_rte_flow_action_set_tag) {
    5454                 :          0 :                 .id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_RX, 0, NULL),
    5455                 :            :                 .data = flow_id,
    5456                 :            :         };
    5457                 :            :         MLX5_ASSERT(set_tag->id > REG_NON);
    5458         [ #  # ]:          0 :         tag_action->conf = set_tag;
    5459                 :            :         /* Create Tx item list. */
    5460                 :            :         rte_memcpy(actions_tx, actions, sizeof(struct rte_flow_action));
    5461                 :          0 :         addr = (void *)&pattern_tx[2];
    5462                 :            :         item = pattern_tx;
    5463                 :          0 :         item->type = (enum rte_flow_item_type)
    5464                 :            :                      MLX5_RTE_FLOW_ITEM_TYPE_TAG;
    5465                 :            :         tag_item = (void *)addr;
    5466                 :          0 :         tag_item->data = flow_id;
    5467                 :          0 :         tag_item->id = mlx5_flow_get_reg_id(dev, MLX5_HAIRPIN_TX, 0, NULL);
    5468                 :            :         MLX5_ASSERT(set_tag->id > REG_NON);
    5469                 :          0 :         item->spec = tag_item;
    5470                 :          0 :         addr += sizeof(struct mlx5_rte_flow_item_tag);
    5471                 :            :         tag_item = (void *)addr;
    5472                 :          0 :         tag_item->data = UINT32_MAX;
    5473                 :          0 :         tag_item->id = UINT16_MAX;
    5474                 :          0 :         item->mask = tag_item;
    5475                 :          0 :         item->last = NULL;
    5476                 :            :         item++;
    5477                 :          0 :         item->type = RTE_FLOW_ITEM_TYPE_END;
    5478                 :          0 :         return 0;
    5479                 :            : }
    5480                 :            : 
    5481                 :            : /**
    5482                 :            :  * The last stage of splitting chain, just creates the subflow
    5483                 :            :  * without any modification.
    5484                 :            :  *
    5485                 :            :  * @param[in] dev
    5486                 :            :  *   Pointer to Ethernet device.
    5487                 :            :  * @param[in] flow
    5488                 :            :  *   Parent flow structure pointer.
    5489                 :            :  * @param[in, out] sub_flow
    5490                 :            :  *   Pointer to return the created subflow, may be NULL.
    5491                 :            :  * @param[in] attr
    5492                 :            :  *   Flow rule attributes.
    5493                 :            :  * @param[in] items
    5494                 :            :  *   Pattern specification (list terminated by the END pattern item).
    5495                 :            :  * @param[in] actions
    5496                 :            :  *   Associated actions (list terminated by the END action).
    5497                 :            :  * @param[in] flow_split_info
    5498                 :            :  *   Pointer to flow split info structure.
    5499                 :            :  * @param[out] error
    5500                 :            :  *   Perform verbose error reporting if not NULL.
    5501                 :            :  * @return
    5502                 :            :  *   0 on success, negative value otherwise
    5503                 :            :  */
    5504                 :            : static int
    5505                 :          0 : flow_create_split_inner(struct rte_eth_dev *dev,
    5506                 :            :                         struct rte_flow *flow,
    5507                 :            :                         struct mlx5_flow **sub_flow,
    5508                 :            :                         const struct rte_flow_attr *attr,
    5509                 :            :                         const struct rte_flow_item items[],
    5510                 :            :                         const struct rte_flow_action actions[],
    5511                 :            :                         struct mlx5_flow_split_info *flow_split_info,
    5512                 :            :                         struct rte_flow_error *error)
    5513                 :            : {
    5514                 :            :         struct mlx5_flow *dev_flow;
    5515                 :          0 :         struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
    5516                 :            : 
    5517                 :          0 :         dev_flow = flow_drv_prepare(dev, flow, attr, items, actions,
    5518                 :            :                                     flow_split_info->flow_idx, error);
    5519         [ #  # ]:          0 :         if (!dev_flow)
    5520                 :          0 :                 return -rte_errno;
    5521                 :          0 :         dev_flow->flow = flow;
    5522                 :          0 :         dev_flow->external = flow_split_info->external;
    5523                 :          0 :         dev_flow->skip_scale = flow_split_info->skip_scale;
    5524                 :            :         /* Subflow object was created, we must include one in the list. */
    5525                 :          0 :         SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
    5526                 :            :                       dev_flow->handle, next);
    5527                 :            :         /*
    5528                 :            :          * If dev_flow is as one of the suffix flow, some actions in suffix
    5529                 :            :          * flow may need some user defined item layer flags, and pass the
    5530                 :            :          * Metadata rxq mark flag to suffix flow as well.
    5531                 :            :          */
    5532         [ #  # ]:          0 :         if (flow_split_info->prefix_layers)
    5533                 :          0 :                 dev_flow->handle->layers = flow_split_info->prefix_layers;
    5534         [ #  # ]:          0 :         if (flow_split_info->prefix_mark) {
    5535                 :            :                 MLX5_ASSERT(wks);
    5536                 :          0 :                 wks->mark = 1;
    5537                 :            :         }
    5538         [ #  # ]:          0 :         if (sub_flow)
    5539                 :          0 :                 *sub_flow = dev_flow;
    5540                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    5541                 :          0 :         dev_flow->dv.table_id = flow_split_info->table_id;
    5542                 :            : #endif
    5543                 :          0 :         return flow_drv_translate(dev, dev_flow, attr, items, actions, error);
    5544                 :            : }
    5545                 :            : 
    5546                 :            : /**
    5547                 :            :  * Get the sub policy of a meter.
    5548                 :            :  *
    5549                 :            :  * @param[in] dev
    5550                 :            :  *   Pointer to Ethernet device.
    5551                 :            :  * @param[in] flow
    5552                 :            :  *   Parent flow structure pointer.
    5553                 :            :  * @param wks
    5554                 :            :  *   Pointer to thread flow work space.
    5555                 :            :  * @param[in] attr
    5556                 :            :  *   Flow rule attributes.
    5557                 :            :  * @param[in] items
    5558                 :            :  *   Pattern specification (list terminated by the END pattern item).
    5559                 :            :  * @param[out] error
    5560                 :            :  *   Perform verbose error reporting if not NULL.
    5561                 :            :  *
    5562                 :            :  * @return
    5563                 :            :  *   Pointer to the meter sub policy, NULL otherwise and rte_errno is set.
    5564                 :            :  */
    5565                 :            : static struct mlx5_flow_meter_sub_policy *
    5566                 :          0 : get_meter_sub_policy(struct rte_eth_dev *dev,
    5567                 :            :                      struct rte_flow *flow,
    5568                 :            :                      struct mlx5_flow_workspace *wks,
    5569                 :            :                      const struct rte_flow_attr *attr,
    5570                 :            :                      const struct rte_flow_item items[],
    5571                 :            :                      struct rte_flow_error *error)
    5572                 :            : {
    5573                 :            :         struct mlx5_flow_meter_policy *policy;
    5574                 :            :         struct mlx5_flow_meter_policy *final_policy;
    5575                 :            :         struct mlx5_flow_meter_sub_policy *sub_policy = NULL;
    5576                 :            : 
    5577                 :          0 :         policy = wks->policy;
    5578         [ #  # ]:          0 :         final_policy = policy->is_hierarchy ? wks->final_policy : policy;
    5579         [ #  # ]:          0 :         if (final_policy->is_rss || final_policy->is_queue) {
    5580                 :            :                 struct mlx5_flow_rss_desc rss_desc_v[MLX5_MTR_RTE_COLORS];
    5581                 :          0 :                 struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS] = {0};
    5582                 :            :                 uint32_t i;
    5583                 :            : 
    5584                 :            :                 /*
    5585                 :            :                  * This is a tmp dev_flow,
    5586                 :            :                  * no need to register any matcher for it in translate.
    5587                 :            :                  */
    5588                 :          0 :                 wks->skip_matcher_reg = 1;
    5589         [ #  # ]:          0 :                 for (i = 0; i < MLX5_MTR_RTE_COLORS; i++) {
    5590                 :          0 :                         struct mlx5_flow dev_flow = {0};
    5591                 :          0 :                         struct mlx5_flow_handle dev_handle = { {0} };
    5592                 :          0 :                         uint8_t fate = final_policy->act_cnt[i].fate_action;
    5593                 :            : 
    5594         [ #  # ]:          0 :                         if (fate == MLX5_FLOW_FATE_SHARED_RSS) {
    5595                 :          0 :                                 const struct rte_flow_action_rss *rss_act =
    5596                 :          0 :                                         final_policy->act_cnt[i].rss->conf;
    5597                 :          0 :                                 struct rte_flow_action rss_actions[2] = {
    5598                 :            :                                         [0] = {
    5599                 :            :                                         .type = RTE_FLOW_ACTION_TYPE_RSS,
    5600                 :            :                                         .conf = rss_act,
    5601                 :            :                                         },
    5602                 :            :                                         [1] = {
    5603                 :            :                                         .type = RTE_FLOW_ACTION_TYPE_END,
    5604                 :            :                                         .conf = NULL,
    5605                 :            :                                         }
    5606                 :            :                                 };
    5607                 :            : 
    5608                 :          0 :                                 dev_flow.handle = &dev_handle;
    5609                 :          0 :                                 dev_flow.ingress = attr->ingress;
    5610                 :          0 :                                 dev_flow.flow = flow;
    5611                 :            :                                 dev_flow.external = 0;
    5612                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    5613                 :          0 :                                 dev_flow.dv.transfer = attr->transfer;
    5614                 :            : #endif
    5615                 :            :                                 /**
    5616                 :            :                                  * Translate RSS action to get rss hash fields.
    5617                 :            :                                  */
    5618         [ #  # ]:          0 :                                 if (flow_drv_translate(dev, &dev_flow, attr,
    5619                 :            :                                                 items, rss_actions, error))
    5620                 :          0 :                                         goto exit;
    5621                 :          0 :                                 rss_desc_v[i] = wks->rss_desc;
    5622                 :          0 :                                 rss_desc_v[i].symmetric_hash_function =
    5623                 :          0 :                                                 dev_flow.symmetric_hash_function;
    5624                 :          0 :                                 rss_desc_v[i].key_len = MLX5_RSS_HASH_KEY_LEN;
    5625                 :          0 :                                 rss_desc_v[i].hash_fields =
    5626                 :          0 :                                                 dev_flow.hash_fields;
    5627                 :          0 :                                 rss_desc_v[i].queue_num =
    5628                 :            :                                                 rss_desc_v[i].hash_fields ?
    5629         [ #  # ]:          0 :                                                 rss_desc_v[i].queue_num : 1;
    5630                 :          0 :                                 rss_desc_v[i].tunnel =
    5631                 :          0 :                                                 !!(dev_flow.handle->layers &
    5632                 :            :                                                    MLX5_FLOW_LAYER_TUNNEL);
    5633                 :            :                                 /* Use the RSS queues in the containers. */
    5634                 :          0 :                                 rss_desc_v[i].queue =
    5635                 :          0 :                                         (uint16_t *)(uintptr_t)rss_act->queue;
    5636                 :          0 :                                 rss_desc[i] = &rss_desc_v[i];
    5637         [ #  # ]:          0 :                         } else if (fate == MLX5_FLOW_FATE_QUEUE) {
    5638                 :            :                                 /* This is queue action. */
    5639                 :          0 :                                 rss_desc_v[i] = wks->rss_desc;
    5640                 :          0 :                                 rss_desc_v[i].key_len = 0;
    5641                 :          0 :                                 rss_desc_v[i].hash_fields = 0;
    5642                 :          0 :                                 rss_desc_v[i].queue =
    5643                 :          0 :                                         &final_policy->act_cnt[i].queue;
    5644                 :          0 :                                 rss_desc_v[i].queue_num = 1;
    5645                 :          0 :                                 rss_desc[i] = &rss_desc_v[i];
    5646                 :            :                         } else {
    5647                 :          0 :                                 rss_desc[i] = NULL;
    5648                 :            :                         }
    5649                 :            :                 }
    5650                 :            :                 sub_policy = flow_drv_meter_sub_policy_rss_prepare(dev,
    5651                 :            :                                                 flow, policy, rss_desc);
    5652                 :            :         } else {
    5653                 :            :                 enum mlx5_meter_domain mtr_domain =
    5654         [ #  # ]:          0 :                         attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
    5655                 :          0 :                                 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
    5656                 :            :                                                 MLX5_MTR_DOMAIN_INGRESS);
    5657                 :          0 :                 sub_policy = policy->sub_policys[mtr_domain][0];
    5658                 :            :         }
    5659         [ #  # ]:          0 :         if (!sub_policy)
    5660                 :          0 :                 rte_flow_error_set(error, EINVAL,
    5661                 :            :                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    5662                 :            :                                    "Failed to get meter sub-policy.");
    5663                 :          0 : exit:
    5664                 :          0 :         return sub_policy;
    5665                 :            : }
    5666                 :            : 
    5667                 :            : /**
    5668                 :            :  * Split the meter flow.
    5669                 :            :  *
    5670                 :            :  * As meter flow will split to three sub flow, other than meter
    5671                 :            :  * action, the other actions make sense to only meter accepts
    5672                 :            :  * the packet. If it need to be dropped, no other additional
    5673                 :            :  * actions should be take.
    5674                 :            :  *
    5675                 :            :  * One kind of special action which decapsulates the L3 tunnel
    5676                 :            :  * header will be in the prefix sub flow, as not to take the
    5677                 :            :  * L3 tunnel header into account.
    5678                 :            :  *
    5679                 :            :  * @param[in] dev
    5680                 :            :  *   Pointer to Ethernet device.
    5681                 :            :  * @param[in] flow
    5682                 :            :  *   Parent flow structure pointer.
    5683                 :            :  * @param wks
    5684                 :            :  *   Pointer to thread flow work space.
    5685                 :            :  * @param[in] attr
    5686                 :            :  *   Flow rule attributes.
    5687                 :            :  * @param[in] items
    5688                 :            :  *   Pattern specification (list terminated by the END pattern item).
    5689                 :            :  * @param[out] sfx_items
    5690                 :            :  *   Suffix flow match items (list terminated by the END pattern item).
    5691                 :            :  * @param[in] actions
    5692                 :            :  *   Associated actions (list terminated by the END action).
    5693                 :            :  * @param[out] actions_sfx
    5694                 :            :  *   Suffix flow actions.
    5695                 :            :  * @param[out] actions_pre
    5696                 :            :  *   Prefix flow actions.
    5697                 :            :  * @param[out] mtr_flow_id
    5698                 :            :  *   Pointer to meter flow id.
    5699                 :            :  * @param[out] error
    5700                 :            :  *   Perform verbose error reporting if not NULL.
    5701                 :            :  *
    5702                 :            :  * @return
    5703                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    5704                 :            :  */
    5705                 :            : static int
    5706                 :          0 : flow_meter_split_prep(struct rte_eth_dev *dev,
    5707                 :            :                       struct rte_flow *flow,
    5708                 :            :                       struct mlx5_flow_workspace *wks,
    5709                 :            :                       const struct rte_flow_attr *attr,
    5710                 :            :                       const struct rte_flow_item items[],
    5711                 :            :                       struct rte_flow_item sfx_items[],
    5712                 :            :                       const struct rte_flow_action actions[],
    5713                 :            :                       struct rte_flow_action actions_sfx[],
    5714                 :            :                       struct rte_flow_action actions_pre[],
    5715                 :            :                       uint32_t *mtr_flow_id,
    5716                 :            :                       struct rte_flow_error *error)
    5717                 :            : {
    5718                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5719                 :          0 :         struct mlx5_flow_meter_info *fm = wks->fm;
    5720                 :            :         struct rte_flow_action *tag_action = NULL;
    5721                 :            :         struct rte_flow_item *tag_item;
    5722                 :            :         struct mlx5_rte_flow_action_set_tag *set_tag;
    5723                 :            :         const struct rte_flow_action_raw_encap *raw_encap;
    5724                 :            :         const struct rte_flow_action_raw_decap *raw_decap;
    5725                 :            :         struct mlx5_rte_flow_item_tag *tag_item_spec;
    5726                 :            :         struct mlx5_rte_flow_item_tag *tag_item_mask;
    5727                 :          0 :         uint32_t tag_id = 0;
    5728                 :            :         bool vlan_actions;
    5729                 :            :         struct rte_flow_item *orig_sfx_items = sfx_items;
    5730                 :            :         const struct rte_flow_item *orig_items = items;
    5731                 :            :         struct rte_flow_action *hw_mtr_action;
    5732                 :            :         struct rte_flow_action *action_pre_head = NULL;
    5733                 :          0 :         uint16_t flow_src_port = priv->representor_id;
    5734                 :            :         bool mtr_first;
    5735                 :          0 :         uint8_t mtr_id_offset = priv->mtr_reg_share ? MLX5_MTR_COLOR_BITS : 0;
    5736         [ #  # ]:          0 :         uint8_t mtr_reg_bits = priv->mtr_reg_share ?
    5737                 :            :                                 MLX5_MTR_IDLE_BITS_IN_COLOR_REG : MLX5_REG_BITS;
    5738                 :            :         uint32_t flow_id = 0;
    5739                 :            :         uint32_t flow_id_reversed = 0;
    5740                 :            :         uint8_t flow_id_bits = 0;
    5741                 :            :         bool after_meter = false;
    5742                 :            :         int shift;
    5743                 :            : 
    5744                 :            :         /* Prepare the suffix subflow items. */
    5745                 :          0 :         tag_item = sfx_items++;
    5746                 :          0 :         tag_item->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_TAG;
    5747         [ #  # ]:          0 :         for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
    5748                 :            :                 int item_type = items->type;
    5749                 :            : 
    5750      [ #  #  # ]:          0 :                 switch (item_type) {
    5751                 :          0 :                 case RTE_FLOW_ITEM_TYPE_PORT_ID:
    5752                 :            :                 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
    5753                 :            :                 case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
    5754         [ #  # ]:          0 :                         if (mlx5_flow_get_item_vport_id(dev, items, &flow_src_port, NULL, error))
    5755                 :          0 :                                 return -rte_errno;
    5756   [ #  #  #  # ]:          0 :                         if (!fm->def_policy && wks->policy->hierarchy_match_port &&
    5757         [ #  # ]:          0 :                             flow_src_port != priv->representor_id) {
    5758         [ #  # ]:          0 :                                 if (flow_drv_mtr_hierarchy_rule_create(dev,
    5759                 :            :                                                                 flow, fm,
    5760                 :            :                                                                 flow_src_port,
    5761                 :            :                                                                 items,
    5762                 :            :                                                                 error))
    5763                 :          0 :                                         return -rte_errno;
    5764                 :            :                         }
    5765                 :            :                         memcpy(sfx_items, items, sizeof(*sfx_items));
    5766                 :          0 :                         sfx_items++;
    5767                 :          0 :                         break;
    5768                 :            :                 case RTE_FLOW_ITEM_TYPE_VLAN:
    5769                 :            :                         /*
    5770                 :            :                          * Copy VLAN items in case VLAN actions are performed.
    5771                 :            :                          * If there are no VLAN actions, these items will be VOID.
    5772                 :            :                          */
    5773                 :            :                         memcpy(sfx_items, items, sizeof(*sfx_items));
    5774                 :          0 :                         sfx_items->type = (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN;
    5775                 :          0 :                         sfx_items++;
    5776                 :          0 :                         break;
    5777                 :            :                 default:
    5778                 :            :                         break;
    5779                 :            :                 }
    5780                 :            :         }
    5781                 :          0 :         sfx_items->type = RTE_FLOW_ITEM_TYPE_END;
    5782                 :          0 :         sfx_items++;
    5783         [ #  # ]:          0 :         mtr_first = priv->sh->meter_aso_en &&
    5784   [ #  #  #  #  :          0 :                 (attr->egress || (attr->transfer && flow_src_port != UINT16_MAX));
                   #  # ]
    5785                 :            :         /* For ASO meter, meter must be before tag in TX direction. */
    5786         [ #  # ]:          0 :         if (mtr_first) {
    5787                 :          0 :                 action_pre_head = actions_pre++;
    5788                 :            :                 /* Leave space for tag action. */
    5789                 :          0 :                 tag_action = actions_pre++;
    5790                 :            :         }
    5791                 :            :         /* Prepare the actions for prefix and suffix flow. */
    5792                 :            :         vlan_actions = false;
    5793         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    5794                 :            :                 struct rte_flow_action *action_cur = NULL;
    5795                 :            : 
    5796   [ #  #  #  #  :          0 :                 switch (actions->type) {
                #  #  # ]
    5797                 :          0 :                 case RTE_FLOW_ACTION_TYPE_METER:
    5798         [ #  # ]:          0 :                         if (mtr_first) {
    5799                 :            :                                 action_cur = action_pre_head;
    5800                 :            :                         } else {
    5801                 :            :                                 /* Leave space for tag action. */
    5802                 :          0 :                                 tag_action = actions_pre++;
    5803                 :          0 :                                 action_cur = actions_pre++;
    5804                 :            :                         }
    5805                 :            :                         after_meter = true;
    5806                 :            :                         break;
    5807                 :          0 :                 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
    5808                 :            :                 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
    5809                 :          0 :                         action_cur = actions_pre++;
    5810                 :          0 :                         break;
    5811                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    5812                 :          0 :                         raw_encap = actions->conf;
    5813         [ #  # ]:          0 :                         if (raw_encap->size < MLX5_ENCAPSULATION_DECISION_SIZE)
    5814                 :          0 :                                 action_cur = actions_pre++;
    5815                 :            :                         break;
    5816                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    5817                 :          0 :                         raw_decap = actions->conf;
    5818         [ #  # ]:          0 :                         if (raw_decap->size > MLX5_ENCAPSULATION_DECISION_SIZE)
    5819                 :          0 :                                 action_cur = actions_pre++;
    5820                 :            :                         break;
    5821                 :          0 :                 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    5822                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    5823                 :            :                         vlan_actions = true;
    5824                 :          0 :                         break;
    5825                 :          0 :                 case RTE_FLOW_ACTION_TYPE_COUNT:
    5826         [ #  # ]:          0 :                         if (fm->def_policy)
    5827                 :            :                                 action_cur = after_meter ?
    5828         [ #  # ]:          0 :                                                 actions_sfx++ : actions_pre++;
    5829                 :            :                         break;
    5830                 :            :                 default:
    5831                 :            :                         break;
    5832                 :            :                 }
    5833         [ #  # ]:          0 :                 if (!action_cur)
    5834                 :          0 :                         action_cur = (fm->def_policy) ?
    5835         [ #  # ]:          0 :                                         actions_sfx++ : actions_pre++;
    5836                 :            :                 memcpy(action_cur, actions, sizeof(struct rte_flow_action));
    5837                 :            :         }
    5838                 :            :         /* If there are no VLAN actions, convert VLAN items to VOID in suffix flow items. */
    5839         [ #  # ]:          0 :         if (!vlan_actions) {
    5840                 :            :                 struct rte_flow_item *it = orig_sfx_items;
    5841                 :            : 
    5842         [ #  # ]:          0 :                 for (; it->type != RTE_FLOW_ITEM_TYPE_END; it++)
    5843         [ #  # ]:          0 :                         if (it->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
    5844                 :          0 :                                 it->type = RTE_FLOW_ITEM_TYPE_VOID;
    5845                 :            :         }
    5846                 :            :         /* Add end action to the actions. */
    5847                 :          0 :         actions_sfx->type = RTE_FLOW_ACTION_TYPE_END;
    5848         [ #  # ]:          0 :         if (priv->sh->meter_aso_en) {
    5849                 :            :                 /**
    5850                 :            :                  * For ASO meter, need to add an extra jump action explicitly,
    5851                 :            :                  * to jump from meter to policer table.
    5852                 :            :                  */
    5853                 :            :                 struct mlx5_flow_meter_sub_policy *sub_policy;
    5854                 :            :                 struct mlx5_flow_tbl_data_entry *tbl_data;
    5855                 :            : 
    5856         [ #  # ]:          0 :                 if (!fm->def_policy) {
    5857                 :          0 :                         sub_policy = get_meter_sub_policy(dev, flow, wks,
    5858                 :            :                                                           attr, orig_items,
    5859                 :            :                                                           error);
    5860         [ #  # ]:          0 :                         if (!sub_policy)
    5861                 :          0 :                                 return -rte_errno;
    5862                 :            :                 } else {
    5863                 :            :                         enum mlx5_meter_domain mtr_domain =
    5864         [ #  # ]:          0 :                         attr->transfer ? MLX5_MTR_DOMAIN_TRANSFER :
    5865                 :          0 :                                 (attr->egress ? MLX5_MTR_DOMAIN_EGRESS :
    5866                 :            :                                                 MLX5_MTR_DOMAIN_INGRESS);
    5867                 :            : 
    5868                 :          0 :                         sub_policy =
    5869                 :          0 :                         &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
    5870                 :            :                 }
    5871                 :          0 :                 tbl_data = container_of(sub_policy->tbl_rsc,
    5872                 :            :                                         struct mlx5_flow_tbl_data_entry, tbl);
    5873                 :          0 :                 hw_mtr_action = actions_pre++;
    5874                 :          0 :                 hw_mtr_action->type = (enum rte_flow_action_type)
    5875                 :            :                                       MLX5_RTE_FLOW_ACTION_TYPE_JUMP;
    5876                 :          0 :                 hw_mtr_action->conf = tbl_data->jump.action;
    5877                 :            :         }
    5878                 :          0 :         actions_pre->type = RTE_FLOW_ACTION_TYPE_END;
    5879                 :          0 :         actions_pre++;
    5880         [ #  # ]:          0 :         if (!tag_action)
    5881                 :          0 :                 return rte_flow_error_set(error, ENOMEM,
    5882                 :            :                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    5883                 :            :                                           NULL, "No tag action space.");
    5884         [ #  # ]:          0 :         if (!mtr_flow_id) {
    5885                 :          0 :                 tag_action->type = RTE_FLOW_ACTION_TYPE_VOID;
    5886                 :          0 :                 goto exit;
    5887                 :            :         }
    5888                 :            :         /* Only default-policy Meter creates mtr flow id. */
    5889         [ #  # ]:          0 :         if (fm->def_policy) {
    5890                 :          0 :                 mlx5_ipool_malloc(fm->flow_ipool, &tag_id);
    5891         [ #  # ]:          0 :                 if (!tag_id)
    5892                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    5893                 :            :                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    5894                 :            :                                         "Failed to allocate meter flow id.");
    5895                 :          0 :                 flow_id = tag_id - 1;
    5896         [ #  # ]:          0 :                 flow_id_bits = (!flow_id) ? 1 :
    5897                 :          0 :                                 (MLX5_REG_BITS - rte_clz32(flow_id));
    5898         [ #  # ]:          0 :                 if ((flow_id_bits + priv->sh->mtrmng->max_mtr_bits) >
    5899                 :            :                     mtr_reg_bits) {
    5900                 :          0 :                         mlx5_ipool_free(fm->flow_ipool, tag_id);
    5901                 :          0 :                         return rte_flow_error_set(error, EINVAL,
    5902                 :            :                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    5903                 :            :                                         "Meter flow id exceeds max limit.");
    5904                 :            :                 }
    5905         [ #  # ]:          0 :                 if (flow_id_bits > priv->sh->mtrmng->max_mtr_flow_bits)
    5906                 :          0 :                         priv->sh->mtrmng->max_mtr_flow_bits = flow_id_bits;
    5907                 :            :         }
    5908                 :            :         /* Build tag actions and items for meter_id/meter flow_id. */
    5909                 :            :         set_tag = (struct mlx5_rte_flow_action_set_tag *)actions_pre;
    5910                 :            :         tag_item_spec = (struct mlx5_rte_flow_item_tag *)sfx_items;
    5911                 :          0 :         tag_item_mask = tag_item_spec + 1;
    5912                 :            :         /* Both flow_id and meter_id share the same register. */
    5913                 :          0 :         *set_tag = (struct mlx5_rte_flow_action_set_tag) {
    5914                 :          0 :                 .id = (enum modify_reg)mlx5_flow_get_reg_id(dev, MLX5_MTR_ID,
    5915                 :            :                                                             0, error),
    5916                 :            :                 .offset = mtr_id_offset,
    5917                 :            :                 .length = mtr_reg_bits,
    5918                 :          0 :                 .data = flow->meter,
    5919                 :            :         };
    5920                 :            :         /*
    5921                 :            :          * The color Reg bits used by flow_id are growing from
    5922                 :            :          * msb to lsb, so must do bit reverse for flow_id val in RegC.
    5923                 :            :          */
    5924         [ #  # ]:          0 :         for (shift = 0; shift < flow_id_bits; shift++)
    5925                 :          0 :                 flow_id_reversed = (flow_id_reversed << 1) |
    5926                 :          0 :                                 ((flow_id >> shift) & 0x1);
    5927                 :          0 :         set_tag->data |=
    5928                 :          0 :                 flow_id_reversed << (mtr_reg_bits - flow_id_bits);
    5929                 :          0 :         tag_item_spec->id = set_tag->id;
    5930                 :          0 :         tag_item_spec->data = set_tag->data << mtr_id_offset;
    5931                 :          0 :         tag_item_mask->data = UINT32_MAX << mtr_id_offset;
    5932                 :          0 :         tag_action->type = (enum rte_flow_action_type)
    5933                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_TAG;
    5934                 :          0 :         tag_action->conf = set_tag;
    5935                 :          0 :         tag_item->spec = tag_item_spec;
    5936                 :          0 :         tag_item->last = NULL;
    5937                 :          0 :         tag_item->mask = tag_item_mask;
    5938                 :          0 : exit:
    5939         [ #  # ]:          0 :         if (mtr_flow_id)
    5940                 :          0 :                 *mtr_flow_id = tag_id;
    5941                 :            :         return 0;
    5942                 :            : }
    5943                 :            : 
    5944                 :            : /**
    5945                 :            :  * Split action list having QUEUE/RSS for metadata register copy.
    5946                 :            :  *
    5947                 :            :  * Once Q/RSS action is detected in user's action list, the flow action
    5948                 :            :  * should be split in order to copy metadata registers, which will happen in
    5949                 :            :  * RX_CP_TBL like,
    5950                 :            :  *   - CQE->flow_tag := reg_c[1] (MARK)
    5951                 :            :  *   - CQE->flow_table_metadata (reg_b) := reg_c[0] (META)
    5952                 :            :  * The Q/RSS action will be performed on RX_ACT_TBL after passing by RX_CP_TBL.
    5953                 :            :  * This is because the last action of each flow must be a terminal action
    5954                 :            :  * (QUEUE, RSS or DROP).
    5955                 :            :  *
    5956                 :            :  * Flow ID must be allocated to identify actions in the RX_ACT_TBL and it is
    5957                 :            :  * stored and kept in the mlx5_flow structure per each sub_flow.
    5958                 :            :  *
    5959                 :            :  * The Q/RSS action is replaced with,
    5960                 :            :  *   - SET_TAG, setting the allocated flow ID to reg_c[2].
    5961                 :            :  * And the following JUMP action is added at the end,
    5962                 :            :  *   - JUMP, to RX_CP_TBL.
    5963                 :            :  *
    5964                 :            :  * A flow to perform remained Q/RSS action will be created in RX_ACT_TBL by
    5965                 :            :  * flow_create_split_metadata() routine. The flow will look like,
    5966                 :            :  *   - If flow ID matches (reg_c[2]), perform Q/RSS.
    5967                 :            :  *
    5968                 :            :  * @param dev
    5969                 :            :  *   Pointer to Ethernet device.
    5970                 :            :  * @param[out] split_actions
    5971                 :            :  *   Pointer to store split actions to jump to CP_TBL.
    5972                 :            :  * @param[in] actions
    5973                 :            :  *   Pointer to the list of original flow actions.
    5974                 :            :  * @param[in] qrss
    5975                 :            :  *   Pointer to the Q/RSS action.
    5976                 :            :  * @param[in] actions_n
    5977                 :            :  *   Number of original actions.
    5978                 :            :  * @param[in] mtr_sfx
    5979                 :            :  *   Check if it is in meter suffix table.
    5980                 :            :  * @param[out] error
    5981                 :            :  *   Perform verbose error reporting if not NULL.
    5982                 :            :  *
    5983                 :            :  * @return
    5984                 :            :  *   non-zero unique flow_id on success, otherwise 0 and
    5985                 :            :  *   error/rte_error are set.
    5986                 :            :  */
    5987                 :            : static uint32_t
    5988                 :          0 : flow_mreg_split_qrss_prep(struct rte_eth_dev *dev,
    5989                 :            :                           struct rte_flow_action *split_actions,
    5990                 :            :                           const struct rte_flow_action *actions,
    5991                 :            :                           const struct rte_flow_action *qrss,
    5992                 :            :                           int actions_n, int mtr_sfx,
    5993                 :            :                           struct rte_flow_error *error)
    5994                 :            : {
    5995                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    5996                 :            :         struct mlx5_rte_flow_action_set_tag *set_tag;
    5997                 :            :         struct rte_flow_action_jump *jump;
    5998                 :          0 :         const int qrss_idx = qrss - actions;
    5999                 :          0 :         uint32_t flow_id = 0;
    6000                 :            :         int ret = 0;
    6001                 :            : 
    6002                 :            :         /*
    6003                 :            :          * Given actions will be split
    6004                 :            :          * - Replace QUEUE/RSS action with SET_TAG to set flow ID.
    6005                 :            :          * - Add jump to mreg CP_TBL.
    6006                 :            :          * As a result, there will be one more action.
    6007                 :            :          */
    6008         [ #  # ]:          0 :         memcpy(split_actions, actions, sizeof(*split_actions) * actions_n);
    6009                 :            :         /* Count MLX5_RTE_FLOW_ACTION_TYPE_TAG. */
    6010                 :          0 :         ++actions_n;
    6011                 :          0 :         set_tag = (void *)(split_actions + actions_n);
    6012                 :            :         /*
    6013                 :            :          * If we are not the meter suffix flow, add the tag action.
    6014                 :            :          * Since meter suffix flow already has the tag added.
    6015                 :            :          */
    6016         [ #  # ]:          0 :         if (!mtr_sfx) {
    6017                 :            :                 /*
    6018                 :            :                  * Allocate the new subflow ID. This one is unique within
    6019                 :            :                  * device and not shared with representors. Otherwise,
    6020                 :            :                  * we would have to resolve multi-thread access synch
    6021                 :            :                  * issue. Each flow on the shared device is appended
    6022                 :            :                  * with source vport identifier, so the resulting
    6023                 :            :                  * flows will be unique in the shared (by master and
    6024                 :            :                  * representors) domain even if they have coinciding
    6025                 :            :                  * IDs.
    6026                 :            :                  */
    6027                 :          0 :                 mlx5_ipool_malloc(priv->sh->ipool
    6028                 :            :                                   [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &flow_id);
    6029         [ #  # ]:          0 :                 if (!flow_id)
    6030                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    6031                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    6032                 :            :                                                   NULL, "can't allocate id "
    6033                 :            :                                                   "for split Q/RSS subflow");
    6034                 :            :                 /* Internal SET_TAG action to set flow ID. */
    6035                 :          0 :                 *set_tag = (struct mlx5_rte_flow_action_set_tag){
    6036                 :            :                         .data = flow_id,
    6037                 :            :                 };
    6038                 :          0 :                 ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0, error);
    6039         [ #  # ]:          0 :                 if (ret < 0)
    6040                 :          0 :                         return ret;
    6041                 :          0 :                 set_tag->id = ret;
    6042                 :            :                 /* Construct new actions array. */
    6043                 :            :                 /* Replace QUEUE/RSS action. */
    6044                 :          0 :                 split_actions[qrss_idx] = (struct rte_flow_action){
    6045                 :            :                         .type = (enum rte_flow_action_type)
    6046                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
    6047                 :            :                         .conf = set_tag,
    6048                 :            :                 };
    6049                 :            :         } else {
    6050                 :            :                 /*
    6051                 :            :                  * If we are the suffix flow of meter, tag already exist.
    6052                 :            :                  * Set the QUEUE/RSS action to void.
    6053                 :            :                  */
    6054                 :          0 :                 split_actions[qrss_idx].type = RTE_FLOW_ACTION_TYPE_VOID;
    6055                 :            :         }
    6056                 :            :         /* JUMP action to jump to mreg copy table (CP_TBL). */
    6057                 :          0 :         jump = (void *)(set_tag + 1);
    6058                 :          0 :         *jump = (struct rte_flow_action_jump){
    6059                 :            :                 .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
    6060                 :            :         };
    6061                 :          0 :         split_actions[actions_n - 2] = (struct rte_flow_action){
    6062                 :            :                 .type = RTE_FLOW_ACTION_TYPE_JUMP,
    6063                 :            :                 .conf = jump,
    6064                 :            :         };
    6065                 :          0 :         split_actions[actions_n - 1] = (struct rte_flow_action){
    6066                 :            :                 .type = RTE_FLOW_ACTION_TYPE_END,
    6067                 :            :         };
    6068                 :          0 :         return flow_id;
    6069                 :            : }
    6070                 :            : 
    6071                 :            : /**
    6072                 :            :  * Extend the given action list for Tx metadata copy.
    6073                 :            :  *
    6074                 :            :  * Copy the given action list to the ext_actions and add flow metadata register
    6075                 :            :  * copy action in order to copy reg_a set by WQE to reg_c[0].
    6076                 :            :  *
    6077                 :            :  * @param[out] ext_actions
    6078                 :            :  *   Pointer to the extended action list.
    6079                 :            :  * @param[in] actions
    6080                 :            :  *   Pointer to the list of actions.
    6081                 :            :  * @param[in] actions_n
    6082                 :            :  *   Number of actions in the list.
    6083                 :            :  * @param[out] error
    6084                 :            :  *   Perform verbose error reporting if not NULL.
    6085                 :            :  * @param[in] encap_idx
    6086                 :            :  *   The encap action index.
    6087                 :            :  *
    6088                 :            :  * @return
    6089                 :            :  *   0 on success, negative value otherwise
    6090                 :            :  */
    6091                 :            : static int
    6092                 :          0 : flow_mreg_tx_copy_prep(struct rte_eth_dev *dev,
    6093                 :            :                        struct rte_flow_action *ext_actions,
    6094                 :            :                        const struct rte_flow_action *actions,
    6095                 :            :                        int actions_n, struct rte_flow_error *error,
    6096                 :            :                        int encap_idx)
    6097                 :            : {
    6098                 :          0 :         struct mlx5_flow_action_copy_mreg *cp_mreg =
    6099                 :            :                 (struct mlx5_flow_action_copy_mreg *)
    6100                 :          0 :                         (ext_actions + actions_n + 1);
    6101                 :            :         int ret;
    6102                 :            : 
    6103                 :          0 :         ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_RX, 0, error);
    6104         [ #  # ]:          0 :         if (ret < 0)
    6105                 :            :                 return ret;
    6106                 :          0 :         cp_mreg->dst = ret;
    6107                 :          0 :         ret = mlx5_flow_get_reg_id(dev, MLX5_METADATA_TX, 0, error);
    6108         [ #  # ]:          0 :         if (ret < 0)
    6109                 :            :                 return ret;
    6110                 :          0 :         cp_mreg->src = ret;
    6111         [ #  # ]:          0 :         if (encap_idx != 0)
    6112                 :          0 :                 memcpy(ext_actions, actions, sizeof(*ext_actions) * encap_idx);
    6113         [ #  # ]:          0 :         if (encap_idx == actions_n - 1) {
    6114                 :          0 :                 ext_actions[actions_n - 1] = (struct rte_flow_action){
    6115                 :            :                         .type = (enum rte_flow_action_type)
    6116                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
    6117                 :            :                         .conf = cp_mreg,
    6118                 :            :                 };
    6119                 :          0 :                 ext_actions[actions_n] = (struct rte_flow_action){
    6120                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    6121                 :            :                 };
    6122                 :            :         } else {
    6123                 :          0 :                 ext_actions[encap_idx] = (struct rte_flow_action){
    6124                 :            :                         .type = (enum rte_flow_action_type)
    6125                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
    6126                 :            :                         .conf = cp_mreg,
    6127                 :            :                 };
    6128                 :          0 :                 memcpy(ext_actions + encap_idx + 1, actions + encap_idx,
    6129                 :          0 :                                 sizeof(*ext_actions) * (actions_n - encap_idx));
    6130                 :            :         }
    6131                 :            :         return 0;
    6132                 :            : }
    6133                 :            : 
    6134                 :            : /**
    6135                 :            :  * Check the match action from the action list.
    6136                 :            :  *
    6137                 :            :  * @param[in] actions
    6138                 :            :  *   Pointer to the list of actions.
    6139                 :            :  * @param[in] attr
    6140                 :            :  *   Flow rule attributes.
    6141                 :            :  * @param[in] action
    6142                 :            :  *   The action to be check if exist.
    6143                 :            :  * @param[out] match_action_pos
    6144                 :            :  *   Pointer to the position of the matched action if exists, otherwise is -1.
    6145                 :            :  * @param[out] qrss_action_pos
    6146                 :            :  *   Pointer to the position of the Queue/RSS action if exists, otherwise is -1.
    6147                 :            :  * @param[out] modify_after_mirror
    6148                 :            :  *   Pointer to the flag of modify action after FDB mirroring.
    6149                 :            :  *
    6150                 :            :  * @return
    6151                 :            :  *   > 0 the total number of actions.
    6152                 :            :  *   0 if not found match action in action list.
    6153                 :            :  */
    6154                 :            : static int
    6155                 :          0 : flow_check_match_action(const struct rte_flow_action actions[],
    6156                 :            :                         const struct rte_flow_attr *attr,
    6157                 :            :                         enum rte_flow_action_type action,
    6158                 :            :                         int *match_action_pos, int *qrss_action_pos,
    6159                 :            :                         int *modify_after_mirror)
    6160                 :            : {
    6161                 :            :         const struct rte_flow_action_sample *sample;
    6162                 :            :         const struct rte_flow_action_raw_decap *decap;
    6163                 :            :         const struct rte_flow_action *action_cur = NULL;
    6164                 :            :         int actions_n = 0;
    6165                 :            :         uint32_t ratio = 0;
    6166                 :            :         int sub_type = 0;
    6167                 :            :         int flag = 0;
    6168                 :            :         int fdb_mirror = 0;
    6169                 :            : 
    6170                 :          0 :         *match_action_pos = -1;
    6171                 :          0 :         *qrss_action_pos = -1;
    6172         [ #  # ]:          0 :         for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
    6173         [ #  # ]:          0 :                 if (actions->type == action) {
    6174                 :            :                         flag = 1;
    6175                 :          0 :                         *match_action_pos = actions_n;
    6176                 :            :                 }
    6177   [ #  #  #  #  :          0 :                 switch (actions->type) {
                      # ]
    6178                 :          0 :                 case RTE_FLOW_ACTION_TYPE_QUEUE:
    6179                 :            :                 case RTE_FLOW_ACTION_TYPE_RSS:
    6180                 :          0 :                         *qrss_action_pos = actions_n;
    6181                 :          0 :                         break;
    6182                 :          0 :                 case RTE_FLOW_ACTION_TYPE_SAMPLE:
    6183                 :          0 :                         sample = actions->conf;
    6184                 :          0 :                         ratio = sample->ratio;
    6185                 :          0 :                         sub_type = ((const struct rte_flow_action *)
    6186                 :          0 :                                         (sample->actions))->type;
    6187   [ #  #  #  #  :          0 :                         if (ratio == 1 && attr->transfer &&
                   #  # ]
    6188                 :            :                             sub_type != RTE_FLOW_ACTION_TYPE_END)
    6189                 :            :                                 fdb_mirror = 1;
    6190                 :            :                         break;
    6191                 :          0 :                 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
    6192                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
    6193                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC:
    6194                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST:
    6195                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC:
    6196                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
    6197                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
    6198                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
    6199                 :            :                 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
    6200                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_TTL:
    6201                 :            :                 case RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ:
    6202                 :            :                 case RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ:
    6203                 :            :                 case RTE_FLOW_ACTION_TYPE_INC_TCP_ACK:
    6204                 :            :                 case RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK:
    6205                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP:
    6206                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP:
    6207                 :            :                 case RTE_FLOW_ACTION_TYPE_FLAG:
    6208                 :            :                 case RTE_FLOW_ACTION_TYPE_MARK:
    6209                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_META:
    6210                 :            :                 case RTE_FLOW_ACTION_TYPE_SET_TAG:
    6211                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
    6212                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    6213                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    6214                 :            :                 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
    6215                 :            :                 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
    6216                 :            :                 case RTE_FLOW_ACTION_TYPE_NVGRE_DECAP:
    6217                 :            :                 case RTE_FLOW_ACTION_TYPE_MODIFY_FIELD:
    6218                 :            :                 case RTE_FLOW_ACTION_TYPE_METER:
    6219         [ #  # ]:          0 :                         if (fdb_mirror)
    6220                 :          0 :                                 *modify_after_mirror = 1;
    6221                 :            :                         break;
    6222                 :          0 :                 case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    6223                 :          0 :                         decap = actions->conf;
    6224                 :            :                         action_cur = actions;
    6225         [ #  # ]:          0 :                         while ((++action_cur)->type == RTE_FLOW_ACTION_TYPE_VOID)
    6226                 :            :                                 ;
    6227         [ #  # ]:          0 :                         if (action_cur->type == RTE_FLOW_ACTION_TYPE_RAW_ENCAP) {
    6228                 :          0 :                                 const struct rte_flow_action_raw_encap *encap =
    6229                 :            :                                                                 action_cur->conf;
    6230         [ #  # ]:          0 :                                 if (decap->size <=
    6231                 :          0 :                                         MLX5_ENCAPSULATION_DECISION_SIZE &&
    6232         [ #  # ]:          0 :                                     encap->size >
    6233                 :            :                                         MLX5_ENCAPSULATION_DECISION_SIZE)
    6234                 :            :                                         /* L3 encap. */
    6235                 :            :                                         break;
    6236                 :            :                         }
    6237         [ #  # ]:          0 :                         if (fdb_mirror)
    6238                 :          0 :                                 *modify_after_mirror = 1;
    6239                 :            :                         break;
    6240                 :            :                 default:
    6241                 :            :                         break;
    6242                 :            :                 }
    6243                 :          0 :                 actions_n++;
    6244                 :            :         }
    6245   [ #  #  #  # ]:          0 :         if (flag && fdb_mirror && !*modify_after_mirror) {
    6246                 :            :                 /* FDB mirroring uses the destination array to implement
    6247                 :            :                  * instead of FLOW_SAMPLER object.
    6248                 :            :                  */
    6249         [ #  # ]:          0 :                 if (sub_type != RTE_FLOW_ACTION_TYPE_END)
    6250                 :            :                         flag = 0;
    6251                 :            :         }
    6252                 :            :         /* Count RTE_FLOW_ACTION_TYPE_END. */
    6253         [ #  # ]:          0 :         return flag ? actions_n + 1 : 0;
    6254                 :            : }
    6255                 :            : 
    6256                 :            : #define SAMPLE_SUFFIX_ITEM 3
    6257                 :            : 
    6258                 :            : /**
    6259                 :            :  * Split the sample flow.
    6260                 :            :  *
    6261                 :            :  * As sample flow will split to two sub flow, sample flow with
    6262                 :            :  * sample action, the other actions will move to new suffix flow.
    6263                 :            :  *
    6264                 :            :  * Also add unique tag id with tag action in the sample flow,
    6265                 :            :  * the same tag id will be as match in the suffix flow.
    6266                 :            :  *
    6267                 :            :  * @param dev
    6268                 :            :  *   Pointer to Ethernet device.
    6269                 :            :  * @param[in] add_tag
    6270                 :            :  *   Add extra tag action flag.
    6271                 :            :  * @param[out] sfx_items
    6272                 :            :  *   Suffix flow match items (list terminated by the END pattern item).
    6273                 :            :  * @param[in] actions
    6274                 :            :  *   Associated actions (list terminated by the END action).
    6275                 :            :  * @param[out] actions_sfx
    6276                 :            :  *   Suffix flow actions.
    6277                 :            :  * @param[out] actions_pre
    6278                 :            :  *   Prefix flow actions.
    6279                 :            :  * @param[in] actions_n
    6280                 :            :  *  The total number of actions.
    6281                 :            :  * @param[in] sample_action_pos
    6282                 :            :  *   The sample action position.
    6283                 :            :  * @param[in] qrss_action_pos
    6284                 :            :  *   The Queue/RSS action position.
    6285                 :            :  * @param[in] jump_table
    6286                 :            :  *   Add extra jump action flag.
    6287                 :            :  * @param[out] error
    6288                 :            :  *   Perform verbose error reporting if not NULL.
    6289                 :            :  *
    6290                 :            :  * @return
    6291                 :            :  *   0 on success, or unique flow_id, a negative errno value
    6292                 :            :  *   otherwise and rte_errno is set.
    6293                 :            :  */
    6294                 :            : static int
    6295                 :          0 : flow_sample_split_prep(struct rte_eth_dev *dev,
    6296                 :            :                        int add_tag,
    6297                 :            :                        const struct rte_flow_item items[],
    6298                 :            :                        struct rte_flow_item sfx_items[],
    6299                 :            :                        const struct rte_flow_action actions[],
    6300                 :            :                        struct rte_flow_action actions_sfx[],
    6301                 :            :                        struct rte_flow_action actions_pre[],
    6302                 :            :                        int actions_n,
    6303                 :            :                        int sample_action_pos,
    6304                 :            :                        int qrss_action_pos,
    6305                 :            :                        int jump_table,
    6306                 :            :                        struct rte_flow_error *error)
    6307                 :            : {
    6308                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    6309                 :            :         struct mlx5_rte_flow_action_set_tag *set_tag;
    6310                 :            :         struct mlx5_rte_flow_item_tag *tag_spec;
    6311                 :            :         struct mlx5_rte_flow_item_tag *tag_mask;
    6312                 :            :         struct rte_flow_action_jump *jump_action;
    6313                 :          0 :         uint32_t tag_id = 0;
    6314                 :            :         int append_index = 0;
    6315                 :            :         int set_tag_idx = -1;
    6316                 :            :         int index;
    6317                 :            :         int ret;
    6318                 :            : 
    6319         [ #  # ]:          0 :         if (sample_action_pos < 0)
    6320                 :          0 :                 return rte_flow_error_set(error, EINVAL,
    6321                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
    6322                 :            :                                           NULL, "invalid position of sample "
    6323                 :            :                                           "action in list");
    6324                 :            :         /* Prepare the actions for prefix and suffix flow. */
    6325         [ #  # ]:          0 :         if (add_tag) {
    6326                 :            :                 /* Update the new added tag action index preceding
    6327                 :            :                  * the PUSH_VLAN or ENCAP action.
    6328                 :            :                  */
    6329                 :            :                 const struct rte_flow_action_raw_encap *raw_encap;
    6330                 :            :                 const struct rte_flow_action *action = actions;
    6331                 :            :                 int encap_idx;
    6332                 :            :                 int action_idx = 0;
    6333                 :            :                 int raw_decap_idx = -1;
    6334                 :            :                 int push_vlan_idx = -1;
    6335         [ #  # ]:          0 :                 for (; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
    6336   [ #  #  #  #  :          0 :                         switch (action->type) {
                      # ]
    6337                 :          0 :                         case RTE_FLOW_ACTION_TYPE_RAW_DECAP:
    6338                 :            :                                 raw_decap_idx = action_idx;
    6339                 :          0 :                                 break;
    6340                 :          0 :                         case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
    6341                 :          0 :                                 raw_encap = action->conf;
    6342         [ #  # ]:          0 :                                 if (raw_encap->size >
    6343                 :            :                                         MLX5_ENCAPSULATION_DECISION_SIZE) {
    6344                 :            :                                         encap_idx = raw_decap_idx != -1 ?
    6345         [ #  # ]:          0 :                                                     raw_decap_idx : action_idx;
    6346                 :          0 :                                         if (encap_idx < sample_action_pos &&
    6347         [ #  # ]:          0 :                                             push_vlan_idx == -1)
    6348                 :            :                                                 set_tag_idx = encap_idx;
    6349                 :            :                                 }
    6350                 :            :                                 break;
    6351                 :          0 :                         case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
    6352                 :            :                         case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
    6353                 :            :                                 encap_idx = action_idx;
    6354                 :          0 :                                 if (encap_idx < sample_action_pos &&
    6355         [ #  # ]:          0 :                                     push_vlan_idx == -1)
    6356                 :            :                                         set_tag_idx = encap_idx;
    6357                 :            :                                 break;
    6358                 :          0 :                         case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
    6359                 :            :                         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
    6360                 :          0 :                                 if (action_idx < sample_action_pos &&
    6361         [ #  # ]:          0 :                                     push_vlan_idx == -1) {
    6362                 :            :                                         set_tag_idx = action_idx;
    6363                 :            :                                         push_vlan_idx = action_idx;
    6364                 :            :                                 }
    6365                 :            :                                 break;
    6366                 :            :                         default:
    6367                 :            :                                 break;
    6368                 :            :                         }
    6369                 :          0 :                         action_idx++;
    6370                 :            :                 }
    6371                 :            :         }
    6372                 :            :         /* Prepare the actions for prefix and suffix flow. */
    6373         [ #  # ]:          0 :         if (qrss_action_pos >= 0 && qrss_action_pos < sample_action_pos) {
    6374                 :            :                 index = qrss_action_pos;
    6375                 :            :                 /* Put the preceding the Queue/RSS action into prefix flow. */
    6376         [ #  # ]:          0 :                 if (index != 0)
    6377                 :          0 :                         memcpy(actions_pre, actions,
    6378                 :            :                                sizeof(struct rte_flow_action) * index);
    6379                 :            :                 /* Put others preceding the sample action into prefix flow. */
    6380         [ #  # ]:          0 :                 if (sample_action_pos > index + 1)
    6381                 :          0 :                         memcpy(actions_pre + index, actions + index + 1,
    6382                 :            :                                sizeof(struct rte_flow_action) *
    6383                 :          0 :                                (sample_action_pos - index - 1));
    6384                 :          0 :                 index = sample_action_pos - 1;
    6385                 :            :                 /* Put Queue/RSS action into Suffix flow. */
    6386                 :          0 :                 memcpy(actions_sfx, actions + qrss_action_pos,
    6387                 :            :                        sizeof(struct rte_flow_action));
    6388                 :          0 :                 actions_sfx++;
    6389         [ #  # ]:          0 :         } else if (add_tag && set_tag_idx >= 0) {
    6390         [ #  # ]:          0 :                 if (set_tag_idx > 0)
    6391                 :          0 :                         memcpy(actions_pre, actions,
    6392                 :            :                                sizeof(struct rte_flow_action) * set_tag_idx);
    6393                 :          0 :                 memcpy(actions_pre + set_tag_idx + 1, actions + set_tag_idx,
    6394                 :            :                        sizeof(struct rte_flow_action) *
    6395                 :          0 :                        (sample_action_pos - set_tag_idx));
    6396                 :            :                 index = sample_action_pos;
    6397                 :            :         } else {
    6398                 :            :                 index = sample_action_pos;
    6399         [ #  # ]:          0 :                 if (index != 0)
    6400                 :          0 :                         memcpy(actions_pre, actions,
    6401                 :            :                                sizeof(struct rte_flow_action) * index);
    6402                 :            :         }
    6403                 :            :         /* For CX5, add an extra tag action for NIC-RX and E-Switch ingress.
    6404                 :            :          * For CX6DX and above, metadata registers Cx preserve their value,
    6405                 :            :          * add an extra tag action for NIC-RX and E-Switch Domain.
    6406                 :            :          */
    6407         [ #  # ]:          0 :         if (add_tag) {
    6408                 :            :                 /* Prepare the prefix tag action. */
    6409                 :            :                 append_index++;
    6410                 :          0 :                 set_tag = (void *)(actions_pre + actions_n + append_index);
    6411                 :            :                 /* Trust VF/SF on CX5 not supported meter so that the reserved
    6412                 :            :                  * metadata regC is REG_NON, back to use application tag
    6413                 :            :                  * index 0.
    6414                 :            :                  */
    6415         [ #  # ]:          0 :                 if (unlikely(priv->sh->registers.aso_reg == REG_NON))
    6416                 :          0 :                         ret = mlx5_flow_get_reg_id(dev, MLX5_APP_TAG, 0, error);
    6417                 :            :                 else
    6418                 :          0 :                         ret = mlx5_flow_get_reg_id(dev, MLX5_SAMPLE_ID, 0, error);
    6419         [ #  # ]:          0 :                 if (ret < 0)
    6420                 :            :                         return ret;
    6421                 :          0 :                 mlx5_ipool_malloc(priv->sh->ipool
    6422                 :            :                                   [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID], &tag_id);
    6423                 :          0 :                 *set_tag = (struct mlx5_rte_flow_action_set_tag) {
    6424                 :            :                         .id = ret,
    6425                 :            :                         .data = tag_id,
    6426                 :            :                 };
    6427                 :            :                 /* Prepare the suffix subflow items. */
    6428                 :          0 :                 tag_spec = (void *)(sfx_items + SAMPLE_SUFFIX_ITEM);
    6429                 :          0 :                 tag_spec->data = tag_id;
    6430                 :          0 :                 tag_spec->id = set_tag->id;
    6431                 :          0 :                 tag_mask = tag_spec + 1;
    6432                 :          0 :                 tag_mask->data = UINT32_MAX;
    6433         [ #  # ]:          0 :                 for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
    6434         [ #  # ]:          0 :                         if (items->type == RTE_FLOW_ITEM_TYPE_PORT_ID ||
    6435                 :            :                             items->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR ||
    6436                 :            :                             items->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
    6437                 :            :                                 memcpy(sfx_items, items, sizeof(*sfx_items));
    6438                 :          0 :                                 sfx_items++;
    6439                 :          0 :                                 break;
    6440                 :            :                         }
    6441                 :            :                 }
    6442                 :          0 :                 sfx_items[0] = (struct rte_flow_item){
    6443                 :            :                         .type = (enum rte_flow_item_type)
    6444                 :            :                                 MLX5_RTE_FLOW_ITEM_TYPE_TAG,
    6445                 :            :                         .spec = tag_spec,
    6446                 :            :                         .last = NULL,
    6447                 :            :                         .mask = tag_mask,
    6448                 :            :                 };
    6449                 :          0 :                 sfx_items[1] = (struct rte_flow_item){
    6450                 :            :                         .type = (enum rte_flow_item_type)
    6451                 :            :                                 RTE_FLOW_ITEM_TYPE_END,
    6452                 :            :                 };
    6453                 :            :                 /* Prepare the tag action in prefix subflow. */
    6454         [ #  # ]:          0 :                 set_tag_idx = (set_tag_idx == -1) ? index : set_tag_idx;
    6455                 :          0 :                 actions_pre[set_tag_idx] =
    6456                 :            :                         (struct rte_flow_action){
    6457                 :            :                         .type = (enum rte_flow_action_type)
    6458                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_TAG,
    6459                 :            :                         .conf = set_tag,
    6460                 :            :                 };
    6461                 :            :                 /* Update next sample position due to add one tag action */
    6462                 :          0 :                 index += 1;
    6463                 :            :         }
    6464                 :            :         /* Copy the sample action into prefix flow. */
    6465         [ #  # ]:          0 :         memcpy(actions_pre + index, actions + sample_action_pos,
    6466                 :            :                sizeof(struct rte_flow_action));
    6467                 :          0 :         index += 1;
    6468                 :            :         /* For the modify action after the sample action in E-Switch mirroring,
    6469                 :            :          * Add the extra jump action in prefix subflow and jump into the next
    6470                 :            :          * table, then do the modify action in the new table.
    6471                 :            :          */
    6472         [ #  # ]:          0 :         if (jump_table) {
    6473                 :            :                 /* Prepare the prefix jump action. */
    6474                 :          0 :                 append_index++;
    6475                 :          0 :                 jump_action = (void *)(actions_pre + actions_n + append_index);
    6476                 :          0 :                 jump_action->group = jump_table;
    6477                 :          0 :                 actions_pre[index++] =
    6478                 :            :                         (struct rte_flow_action){
    6479                 :            :                         .type = (enum rte_flow_action_type)
    6480                 :            :                                 RTE_FLOW_ACTION_TYPE_JUMP,
    6481                 :            :                         .conf = jump_action,
    6482                 :            :                 };
    6483                 :            :         }
    6484                 :          0 :         actions_pre[index] = (struct rte_flow_action){
    6485                 :            :                 .type = (enum rte_flow_action_type)
    6486                 :            :                         RTE_FLOW_ACTION_TYPE_END,
    6487                 :            :         };
    6488                 :            :         /* Put the actions after sample into Suffix flow. */
    6489                 :          0 :         memcpy(actions_sfx, actions + sample_action_pos + 1,
    6490                 :            :                sizeof(struct rte_flow_action) *
    6491                 :          0 :                (actions_n - sample_action_pos - 1));
    6492                 :          0 :         return tag_id;
    6493                 :            : }
    6494                 :            : 
    6495                 :            : /**
    6496                 :            :  * The splitting for metadata feature.
    6497                 :            :  *
    6498                 :            :  * - Q/RSS action on NIC Rx should be split in order to pass by
    6499                 :            :  *   the mreg copy table (RX_CP_TBL) and then it jumps to the
    6500                 :            :  *   action table (RX_ACT_TBL) which has the split Q/RSS action.
    6501                 :            :  *
    6502                 :            :  * - All the actions on NIC Tx should have a mreg copy action to
    6503                 :            :  *   copy reg_a from WQE to reg_c[0].
    6504                 :            :  *
    6505                 :            :  * @param dev
    6506                 :            :  *   Pointer to Ethernet device.
    6507                 :            :  * @param[in] flow
    6508                 :            :  *   Parent flow structure pointer.
    6509                 :            :  * @param[in] attr
    6510                 :            :  *   Flow rule attributes.
    6511                 :            :  * @param[in] items
    6512                 :            :  *   Pattern specification (list terminated by the END pattern item).
    6513                 :            :  * @param[in] actions
    6514                 :            :  *   Associated actions (list terminated by the END action).
    6515                 :            :  * @param[in] flow_split_info
    6516                 :            :  *   Pointer to flow split info structure.
    6517                 :            :  * @param[out] error
    6518                 :            :  *   Perform verbose error reporting if not NULL.
    6519                 :            :  * @return
    6520                 :            :  *   0 on success, negative value otherwise
    6521                 :            :  */
    6522                 :            : static int
    6523                 :          0 : flow_create_split_metadata(struct rte_eth_dev *dev,
    6524                 :            :                            struct rte_flow *flow,
    6525                 :            :                            const struct rte_flow_attr *attr,
    6526                 :            :                            const struct rte_flow_item items[],
    6527                 :            :                            const struct rte_flow_action actions[],
    6528                 :            :                            struct mlx5_flow_split_info *flow_split_info,
    6529                 :            :                            struct rte_flow_error *error)
    6530                 :            : {
    6531                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    6532                 :          0 :         struct mlx5_sh_config *config = &priv->sh->config;
    6533                 :          0 :         const struct rte_flow_action *qrss = NULL;
    6534                 :            :         struct rte_flow_action *ext_actions = NULL;
    6535                 :          0 :         struct mlx5_flow *dev_flow = NULL;
    6536                 :            :         uint32_t qrss_id = 0;
    6537                 :            :         int mtr_sfx = 0;
    6538                 :            :         size_t act_size;
    6539                 :            :         int actions_n;
    6540                 :            :         int encap_idx;
    6541                 :            :         int ret;
    6542                 :            : 
    6543                 :            :         /* Check whether extensive metadata feature is engaged. */
    6544         [ #  # ]:          0 :         if (!config->dv_flow_en ||
    6545   [ #  #  #  # ]:          0 :             config->dv_xmeta_en == MLX5_XMETA_MODE_LEGACY ||
    6546                 :          0 :             !mlx5_flow_ext_mreg_supported(dev))
    6547                 :          0 :                 return flow_create_split_inner(dev, flow, NULL, attr, items,
    6548                 :            :                                                actions, flow_split_info, error);
    6549                 :          0 :         actions_n = flow_parse_metadata_split_actions_info(actions, &qrss,
    6550                 :            :                                                            &encap_idx);
    6551         [ #  # ]:          0 :         if (qrss) {
    6552                 :            :                 /* Exclude hairpin flows from splitting. */
    6553         [ #  # ]:          0 :                 if (qrss->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
    6554                 :            :                         const struct rte_flow_action_queue *queue;
    6555                 :            : 
    6556                 :          0 :                         queue = qrss->conf;
    6557         [ #  # ]:          0 :                         if (mlx5_rxq_is_hairpin(dev, queue->index))
    6558                 :          0 :                                 qrss = NULL;
    6559         [ #  # ]:          0 :                 } else if (qrss->type == RTE_FLOW_ACTION_TYPE_RSS) {
    6560                 :            :                         const struct rte_flow_action_rss *rss;
    6561                 :            : 
    6562                 :          0 :                         rss = qrss->conf;
    6563         [ #  # ]:          0 :                         if (mlx5_rxq_is_hairpin(dev, rss->queue[0]))
    6564                 :          0 :                                 qrss = NULL;
    6565                 :            :                 }
    6566                 :            :         }
    6567         [ #  # ]:          0 :         if (qrss) {
    6568                 :            :                 /* Check if it is in meter suffix table. */
    6569                 :          0 :                 mtr_sfx = attr->group ==
    6570         [ #  # ]:          0 :                           ((attr->transfer && priv->fdb_def_rule) ?
    6571         [ #  # ]:          0 :                           (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
    6572                 :            :                           MLX5_FLOW_TABLE_LEVEL_METER);
    6573                 :            :                 /*
    6574                 :            :                  * Q/RSS action on NIC Rx should be split in order to pass by
    6575                 :            :                  * the mreg copy table (RX_CP_TBL) and then it jumps to the
    6576                 :            :                  * action table (RX_ACT_TBL) which has the split Q/RSS action.
    6577                 :            :                  */
    6578                 :          0 :                 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
    6579                 :          0 :                            sizeof(struct rte_flow_action_set_tag) +
    6580                 :            :                            sizeof(struct rte_flow_action_jump);
    6581                 :          0 :                 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
    6582                 :            :                                           SOCKET_ID_ANY);
    6583         [ #  # ]:          0 :                 if (!ext_actions)
    6584                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    6585                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    6586                 :            :                                                   NULL, "no memory to split "
    6587                 :            :                                                   "metadata flow");
    6588                 :            :                 /*
    6589                 :            :                  * Create the new actions list with removed Q/RSS action
    6590                 :            :                  * and appended set tag and jump to register copy table
    6591                 :            :                  * (RX_CP_TBL). We should preallocate unique tag ID here
    6592                 :            :                  * in advance, because it is needed for set tag action.
    6593                 :            :                  */
    6594                 :          0 :                 qrss_id = flow_mreg_split_qrss_prep(dev, ext_actions, actions,
    6595                 :            :                                                     qrss, actions_n,
    6596                 :            :                                                     mtr_sfx, error);
    6597         [ #  # ]:          0 :                 if (!mtr_sfx && !qrss_id) {
    6598                 :          0 :                         ret = -rte_errno;
    6599                 :          0 :                         goto exit;
    6600                 :            :                 }
    6601         [ #  # ]:          0 :         } else if (attr->egress) {
    6602                 :            :                 /*
    6603                 :            :                  * All the actions on NIC Tx should have a metadata register
    6604                 :            :                  * copy action to copy reg_a from WQE to reg_c[meta]
    6605                 :            :                  */
    6606                 :          0 :                 act_size = sizeof(struct rte_flow_action) * (actions_n + 1) +
    6607                 :            :                            sizeof(struct mlx5_flow_action_copy_mreg);
    6608                 :          0 :                 ext_actions = mlx5_malloc(MLX5_MEM_ZERO, act_size, 0,
    6609                 :            :                                           SOCKET_ID_ANY);
    6610         [ #  # ]:          0 :                 if (!ext_actions)
    6611                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    6612                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    6613                 :            :                                                   NULL, "no memory to split "
    6614                 :            :                                                   "metadata flow");
    6615                 :            :                 /* Create the action list appended with copy register. */
    6616                 :          0 :                 ret = flow_mreg_tx_copy_prep(dev, ext_actions, actions,
    6617                 :            :                                              actions_n, error, encap_idx);
    6618         [ #  # ]:          0 :                 if (ret < 0)
    6619                 :          0 :                         goto exit;
    6620                 :            :         }
    6621                 :            :         /* Add the unmodified original or prefix subflow. */
    6622         [ #  # ]:          0 :         ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
    6623                 :            :                                       items, ext_actions ? ext_actions :
    6624                 :            :                                       actions, flow_split_info, error);
    6625         [ #  # ]:          0 :         if (ret < 0)
    6626                 :          0 :                 goto exit;
    6627                 :            :         MLX5_ASSERT(dev_flow);
    6628         [ #  # ]:          0 :         if (qrss) {
    6629                 :          0 :                 const struct rte_flow_attr q_attr = {
    6630                 :            :                         .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
    6631                 :            :                         .ingress = 1,
    6632                 :            :                 };
    6633                 :            :                 /* Internal PMD action to set register. */
    6634                 :          0 :                 struct mlx5_rte_flow_item_tag q_tag_spec = {
    6635                 :            :                         .data = qrss_id,
    6636                 :            :                         .id = REG_NON,
    6637                 :            :                 };
    6638                 :          0 :                 struct rte_flow_item q_items[] = {
    6639                 :            :                         {
    6640                 :            :                                 .type = (enum rte_flow_item_type)
    6641                 :            :                                         MLX5_RTE_FLOW_ITEM_TYPE_TAG,
    6642                 :            :                                 .spec = &q_tag_spec,
    6643                 :            :                                 .last = NULL,
    6644                 :            :                                 .mask = NULL,
    6645                 :            :                         },
    6646                 :            :                         {
    6647                 :            :                                 .type = RTE_FLOW_ITEM_TYPE_END,
    6648                 :            :                         },
    6649                 :            :                 };
    6650                 :          0 :                 struct rte_flow_action q_actions[] = {
    6651                 :            :                         {
    6652                 :          0 :                                 .type = qrss->type,
    6653                 :          0 :                                 .conf = qrss->conf,
    6654                 :            :                         },
    6655                 :            :                         {
    6656                 :            :                                 .type = RTE_FLOW_ACTION_TYPE_END,
    6657                 :            :                         },
    6658                 :            :                 };
    6659                 :          0 :                 uint64_t layers = flow_get_prefix_layer_flags(dev_flow);
    6660                 :            : 
    6661                 :            :                 /*
    6662                 :            :                  * Configure the tag item only if there is no meter subflow.
    6663                 :            :                  * Since tag is already marked in the meter suffix subflow
    6664                 :            :                  * we can just use the meter suffix items as is.
    6665                 :            :                  */
    6666         [ #  # ]:          0 :                 if (qrss_id) {
    6667                 :            :                         /* Not meter subflow. */
    6668                 :            :                         MLX5_ASSERT(!mtr_sfx);
    6669                 :            :                         /*
    6670                 :            :                          * Put unique id in prefix flow due to it is destroyed
    6671                 :            :                          * after suffix flow and id will be freed after there
    6672                 :            :                          * is no actual flows with this id and identifier
    6673                 :            :                          * reallocation becomes possible (for example, for
    6674                 :            :                          * other flows in other threads).
    6675                 :            :                          */
    6676                 :          0 :                         dev_flow->handle->split_flow_id = qrss_id;
    6677                 :          0 :                         ret = mlx5_flow_get_reg_id(dev, MLX5_COPY_MARK, 0,
    6678                 :            :                                                    error);
    6679         [ #  # ]:          0 :                         if (ret < 0)
    6680                 :          0 :                                 goto exit;
    6681                 :          0 :                         q_tag_spec.id = ret;
    6682                 :            :                 }
    6683                 :          0 :                 dev_flow = NULL;
    6684                 :            :                 /* Add suffix subflow to execute Q/RSS. */
    6685                 :          0 :                 flow_split_info->prefix_layers = layers;
    6686                 :          0 :                 flow_split_info->prefix_mark = 0;
    6687                 :          0 :                 flow_split_info->table_id = 0;
    6688         [ #  # ]:          0 :                 ret = flow_create_split_inner(dev, flow, &dev_flow,
    6689                 :            :                                               &q_attr, mtr_sfx ? items :
    6690                 :            :                                               q_items, q_actions,
    6691                 :            :                                               flow_split_info, error);
    6692         [ #  # ]:          0 :                 if (ret < 0)
    6693                 :          0 :                         goto exit;
    6694                 :            :                 /* qrss ID should be freed if failed. */
    6695                 :            :                 qrss_id = 0;
    6696                 :            :                 MLX5_ASSERT(dev_flow);
    6697                 :            :         }
    6698                 :            : 
    6699                 :          0 : exit:
    6700                 :            :         /*
    6701                 :            :          * We do not destroy the partially created sub_flows in case of error.
    6702                 :            :          * These ones are included into parent flow list and will be destroyed
    6703                 :            :          * by flow_drv_destroy.
    6704                 :            :          */
    6705                 :          0 :         mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_RSS_EXPANTION_FLOW_ID],
    6706                 :            :                         qrss_id);
    6707                 :          0 :         mlx5_free(ext_actions);
    6708                 :          0 :         return ret;
    6709                 :            : }
    6710                 :            : 
    6711                 :            : /**
    6712                 :            :  * Create meter internal drop flow with the original pattern.
    6713                 :            :  *
    6714                 :            :  * @param dev
    6715                 :            :  *   Pointer to Ethernet device.
    6716                 :            :  * @param[in] flow
    6717                 :            :  *   Parent flow structure pointer.
    6718                 :            :  * @param[in] attr
    6719                 :            :  *   Flow rule attributes.
    6720                 :            :  * @param[in] items
    6721                 :            :  *   Pattern specification (list terminated by the END pattern item).
    6722                 :            :  * @param[in] flow_split_info
    6723                 :            :  *   Pointer to flow split info structure.
    6724                 :            :  * @param[in] fm
    6725                 :            :  *   Pointer to flow meter structure.
    6726                 :            :  * @param[out] error
    6727                 :            :  *   Perform verbose error reporting if not NULL.
    6728                 :            :  * @return
    6729                 :            :  *   0 on success, negative value otherwise
    6730                 :            :  */
    6731                 :            : static uint32_t
    6732                 :          0 : flow_meter_create_drop_flow_with_org_pattern(struct rte_eth_dev *dev,
    6733                 :            :                         struct rte_flow *flow,
    6734                 :            :                         const struct rte_flow_attr *attr,
    6735                 :            :                         const struct rte_flow_item items[],
    6736                 :            :                         struct mlx5_flow_split_info *flow_split_info,
    6737                 :            :                         struct mlx5_flow_meter_info *fm,
    6738                 :            :                         struct rte_flow_error *error)
    6739                 :            : {
    6740                 :          0 :         struct mlx5_flow *dev_flow = NULL;
    6741                 :          0 :         struct rte_flow_attr drop_attr = *attr;
    6742                 :            :         struct rte_flow_action drop_actions[3];
    6743                 :          0 :         struct mlx5_flow_split_info drop_split_info = *flow_split_info;
    6744                 :            : 
    6745                 :            :         MLX5_ASSERT(fm->drop_cnt);
    6746                 :          0 :         drop_actions[0].type =
    6747                 :            :                 (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_COUNT;
    6748                 :          0 :         drop_actions[0].conf = (void *)(uintptr_t)fm->drop_cnt;
    6749                 :          0 :         drop_actions[1].type = RTE_FLOW_ACTION_TYPE_DROP;
    6750                 :          0 :         drop_actions[1].conf = NULL;
    6751                 :          0 :         drop_actions[2].type = RTE_FLOW_ACTION_TYPE_END;
    6752                 :          0 :         drop_actions[2].conf = NULL;
    6753                 :          0 :         drop_split_info.external = false;
    6754                 :          0 :         drop_split_info.skip_scale |= 1 << MLX5_SCALE_FLOW_GROUP_BIT;
    6755                 :          0 :         drop_split_info.table_id = MLX5_MTR_TABLE_ID_DROP;
    6756                 :          0 :         drop_attr.group = MLX5_FLOW_TABLE_LEVEL_METER;
    6757                 :          0 :         return flow_create_split_inner(dev, flow, &dev_flow,
    6758                 :            :                                 &drop_attr, items, drop_actions,
    6759                 :            :                                 &drop_split_info, error);
    6760                 :            : }
    6761                 :            : 
    6762                 :            : static int
    6763                 :            : flow_count_vlan_items(const struct rte_flow_item items[])
    6764                 :            : {
    6765                 :            :         int items_n = 0;
    6766                 :            : 
    6767         [ #  # ]:          0 :         for (; items->type != RTE_FLOW_ITEM_TYPE_END; items++) {
    6768         [ #  # ]:          0 :                 if (items->type == RTE_FLOW_ITEM_TYPE_VLAN ||
    6769                 :            :                     items->type == (enum rte_flow_item_type)MLX5_RTE_FLOW_ITEM_TYPE_VLAN)
    6770                 :          0 :                         items_n++;
    6771                 :            :         }
    6772                 :            :         return items_n;
    6773                 :            : }
    6774                 :            : 
    6775                 :            : /**
    6776                 :            :  * The splitting for meter feature.
    6777                 :            :  *
    6778                 :            :  * - The meter flow will be split to two flows as prefix and
    6779                 :            :  *   suffix flow. The packets make sense only it pass the prefix
    6780                 :            :  *   meter action.
    6781                 :            :  *
    6782                 :            :  * - Reg_C_5 is used for the packet to match betweend prefix and
    6783                 :            :  *   suffix flow.
    6784                 :            :  *
    6785                 :            :  * @param dev
    6786                 :            :  *   Pointer to Ethernet device.
    6787                 :            :  * @param[in] flow
    6788                 :            :  *   Parent flow structure pointer.
    6789                 :            :  * @param[in] attr
    6790                 :            :  *   Flow rule attributes.
    6791                 :            :  * @param[in] items
    6792                 :            :  *   Pattern specification (list terminated by the END pattern item).
    6793                 :            :  * @param[in] actions
    6794                 :            :  *   Associated actions (list terminated by the END action).
    6795                 :            :  * @param[in] flow_split_info
    6796                 :            :  *   Pointer to flow split info structure.
    6797                 :            :  * @param[out] error
    6798                 :            :  *   Perform verbose error reporting if not NULL.
    6799                 :            :  * @return
    6800                 :            :  *   0 on success, negative value otherwise
    6801                 :            :  */
    6802                 :            : static int
    6803                 :          0 : flow_create_split_meter(struct rte_eth_dev *dev,
    6804                 :            :                         struct rte_flow *flow,
    6805                 :            :                         const struct rte_flow_attr *attr,
    6806                 :            :                         const struct rte_flow_item items[],
    6807                 :            :                         const struct rte_flow_action actions[],
    6808                 :            :                         struct mlx5_flow_split_info *flow_split_info,
    6809                 :            :                         struct rte_flow_error *error)
    6810                 :            : {
    6811                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    6812                 :          0 :         struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
    6813                 :            :         struct rte_flow_action *sfx_actions = NULL;
    6814                 :            :         struct rte_flow_action *pre_actions = NULL;
    6815                 :            :         struct rte_flow_item *sfx_items = NULL;
    6816                 :          0 :         struct mlx5_flow *dev_flow = NULL;
    6817                 :          0 :         struct rte_flow_attr sfx_attr = *attr;
    6818                 :            :         struct mlx5_flow_meter_info *fm = NULL;
    6819                 :            :         uint8_t skip_scale_restore;
    6820                 :          0 :         bool has_mtr = false;
    6821                 :          0 :         bool has_modify = false;
    6822                 :            :         bool set_mtr_reg = true;
    6823                 :            :         bool is_mtr_hierarchy = false;
    6824                 :          0 :         uint32_t meter_id = 0;
    6825                 :          0 :         uint32_t mtr_idx = 0;
    6826                 :          0 :         uint32_t mtr_flow_id = 0;
    6827                 :            :         size_t act_size;
    6828                 :            :         size_t item_size;
    6829                 :            :         int actions_n = 0;
    6830                 :            :         int vlan_items_n = 0;
    6831                 :            :         int ret = 0;
    6832                 :            : 
    6833         [ #  # ]:          0 :         if (priv->mtr_en)
    6834                 :          0 :                 actions_n = flow_check_meter_action(dev, actions, &has_mtr,
    6835                 :            :                                                     &has_modify, &meter_id);
    6836         [ #  # ]:          0 :         if (has_mtr) {
    6837         [ #  # ]:          0 :                 if (flow->meter) {
    6838                 :          0 :                         fm = flow_dv_meter_find_by_idx(priv, flow->meter);
    6839         [ #  # ]:          0 :                         if (!fm)
    6840                 :          0 :                                 return rte_flow_error_set(error, EINVAL,
    6841                 :            :                                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    6842                 :            :                                                 NULL, "Meter not found.");
    6843                 :            :                 } else {
    6844                 :          0 :                         fm = mlx5_flow_meter_find(priv, meter_id, &mtr_idx);
    6845         [ #  # ]:          0 :                         if (!fm)
    6846                 :          0 :                                 return rte_flow_error_set(error, EINVAL,
    6847                 :            :                                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    6848                 :            :                                                 NULL, "Meter not found.");
    6849                 :          0 :                         ret = mlx5_flow_meter_attach(priv, fm,
    6850                 :            :                                                      &sfx_attr, error);
    6851         [ #  # ]:          0 :                         if (ret)
    6852                 :          0 :                                 return -rte_errno;
    6853                 :          0 :                         flow->meter = mtr_idx;
    6854                 :            :                 }
    6855                 :            :                 MLX5_ASSERT(wks);
    6856                 :          0 :                 wks->fm = fm;
    6857         [ #  # ]:          0 :                 if (!fm->def_policy) {
    6858                 :          0 :                         wks->policy = mlx5_flow_meter_policy_find(dev,
    6859                 :            :                                                                   fm->policy_id,
    6860                 :            :                                                                   NULL);
    6861                 :            :                         MLX5_ASSERT(wks->policy);
    6862         [ #  # ]:          0 :                         if (wks->policy->mark)
    6863                 :          0 :                                 wks->mark = 1;
    6864         [ #  # ]:          0 :                         if (wks->policy->is_hierarchy) {
    6865                 :          0 :                                 wks->final_policy =
    6866                 :          0 :                                 mlx5_flow_meter_hierarchy_get_final_policy(dev,
    6867                 :            :                                                                 wks->policy);
    6868         [ #  # ]:          0 :                                 if (!wks->final_policy)
    6869                 :          0 :                                         return rte_flow_error_set(error,
    6870                 :            :                                         EINVAL,
    6871                 :            :                                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
    6872                 :            :                                 "Failed to find terminal policy of hierarchy.");
    6873                 :            :                                 is_mtr_hierarchy = true;
    6874                 :            :                         }
    6875                 :            :                 }
    6876                 :            :                 /*
    6877                 :            :                  * If it isn't default-policy Meter, and
    6878                 :            :                  * 1. Not meter hierarchy and there's no action in flow to change
    6879                 :            :                  *    packet (modify/encap/decap etc.), OR
    6880                 :            :                  * 2. No drop count needed for this meter.
    6881                 :            :                  * Then no need to use regC to save meter id anymore.
    6882                 :            :                  */
    6883   [ #  #  #  #  :          0 :                 if (!fm->def_policy && ((!has_modify && !is_mtr_hierarchy) || !fm->drop_cnt))
             #  #  #  # ]
    6884                 :            :                         set_mtr_reg = false;
    6885                 :            :                 /* Prefix actions: meter, decap, encap, tag, jump, end, cnt. */
    6886                 :            : #define METER_PREFIX_ACTION 7
    6887                 :          0 :                 act_size = (sizeof(struct rte_flow_action) *
    6888                 :          0 :                             (actions_n + METER_PREFIX_ACTION)) +
    6889                 :            :                            sizeof(struct mlx5_rte_flow_action_set_tag);
    6890                 :            :                 /* Flow can have multiple VLAN items. Account for them in suffix items. */
    6891                 :            :                 vlan_items_n = flow_count_vlan_items(items);
    6892                 :            :                 /* Suffix items: tag, [vlans], port id, end. */
    6893                 :            : #define METER_SUFFIX_ITEM 3
    6894                 :          0 :                 item_size = sizeof(struct rte_flow_item) * (METER_SUFFIX_ITEM + vlan_items_n) +
    6895                 :            :                             sizeof(struct mlx5_rte_flow_item_tag) * 2;
    6896                 :          0 :                 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size + item_size),
    6897                 :            :                                           0, SOCKET_ID_ANY);
    6898         [ #  # ]:          0 :                 if (!sfx_actions)
    6899                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    6900                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    6901                 :            :                                                   NULL, "no memory to split "
    6902                 :            :                                                   "meter flow");
    6903                 :          0 :                 sfx_items = (struct rte_flow_item *)((char *)sfx_actions +
    6904                 :            :                              act_size);
    6905                 :            :                 /* There's no suffix flow for meter of non-default policy. */
    6906         [ #  # ]:          0 :                 if (!fm->def_policy)
    6907                 :          0 :                         pre_actions = sfx_actions + 1;
    6908                 :            :                 else
    6909                 :          0 :                         pre_actions = sfx_actions + actions_n;
    6910         [ #  # ]:          0 :                 ret = flow_meter_split_prep(dev, flow, wks, &sfx_attr,
    6911                 :            :                                             items, sfx_items, actions,
    6912                 :            :                                             sfx_actions, pre_actions,
    6913                 :            :                                             (set_mtr_reg ? &mtr_flow_id : NULL),
    6914                 :            :                                             error);
    6915         [ #  # ]:          0 :                 if (ret) {
    6916                 :          0 :                         ret = -rte_errno;
    6917                 :          0 :                         goto exit;
    6918                 :            :                 }
    6919                 :            :                 /* Add the prefix subflow. */
    6920                 :          0 :                 skip_scale_restore = flow_split_info->skip_scale;
    6921                 :          0 :                 flow_split_info->skip_scale |=
    6922                 :            :                         1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
    6923                 :          0 :                 ret = flow_create_split_inner(dev, flow, &dev_flow,
    6924                 :            :                                               attr, items, pre_actions,
    6925                 :            :                                               flow_split_info, error);
    6926                 :          0 :                 flow_split_info->skip_scale = skip_scale_restore;
    6927         [ #  # ]:          0 :                 if (ret) {
    6928         [ #  # ]:          0 :                         if (mtr_flow_id)
    6929                 :          0 :                                 mlx5_ipool_free(fm->flow_ipool, mtr_flow_id);
    6930                 :          0 :                         ret = -rte_errno;
    6931                 :          0 :                         goto exit;
    6932                 :            :                 }
    6933         [ #  # ]:          0 :                 if (mtr_flow_id) {
    6934                 :          0 :                         dev_flow->handle->split_flow_id = mtr_flow_id;
    6935                 :          0 :                         dev_flow->handle->is_meter_flow_id = 1;
    6936                 :            :                 }
    6937         [ #  # ]:          0 :                 if (!fm->def_policy) {
    6938   [ #  #  #  # ]:          0 :                         if (!set_mtr_reg && fm->drop_cnt)
    6939                 :          0 :                                 ret =
    6940                 :          0 :                         flow_meter_create_drop_flow_with_org_pattern(dev, flow,
    6941                 :            :                                                         &sfx_attr, items,
    6942                 :            :                                                         flow_split_info,
    6943                 :            :                                                         fm, error);
    6944                 :          0 :                         goto exit;
    6945                 :            :                 }
    6946                 :            :                 /* Setting the sfx group atrr. */
    6947                 :          0 :                 sfx_attr.group = sfx_attr.transfer ?
    6948         [ #  # ]:          0 :                                 (MLX5_FLOW_TABLE_LEVEL_METER - 1) :
    6949                 :            :                                  MLX5_FLOW_TABLE_LEVEL_METER;
    6950                 :          0 :                 flow_split_info->prefix_layers =
    6951                 :          0 :                                 flow_get_prefix_layer_flags(dev_flow);
    6952                 :          0 :                 flow_split_info->prefix_mark |= wks->mark;
    6953                 :          0 :                 flow_split_info->table_id = MLX5_MTR_TABLE_ID_SUFFIX;
    6954                 :            :         }
    6955                 :            :         /* Add the prefix subflow. */
    6956         [ #  # ]:          0 :         ret = flow_create_split_metadata(dev, flow,
    6957                 :            :                                          &sfx_attr, sfx_items ?
    6958                 :            :                                          sfx_items : items,
    6959                 :            :                                          sfx_actions ? sfx_actions : actions,
    6960                 :            :                                          flow_split_info, error);
    6961                 :          0 : exit:
    6962         [ #  # ]:          0 :         if (sfx_actions)
    6963                 :          0 :                 mlx5_free(sfx_actions);
    6964                 :            :         return ret;
    6965                 :            : }
    6966                 :            : 
    6967                 :            : /**
    6968                 :            :  * The splitting for sample feature.
    6969                 :            :  *
    6970                 :            :  * Once Sample action is detected in the action list, the flow actions should
    6971                 :            :  * be split into prefix sub flow and suffix sub flow.
    6972                 :            :  *
    6973                 :            :  * The original items remain in the prefix sub flow, all actions preceding the
    6974                 :            :  * sample action and the sample action itself will be copied to the prefix
    6975                 :            :  * sub flow, the actions following the sample action will be copied to the
    6976                 :            :  * suffix sub flow, Queue action always be located in the suffix sub flow.
    6977                 :            :  *
    6978                 :            :  * In order to make the packet from prefix sub flow matches with suffix sub
    6979                 :            :  * flow, an extra tag action be added into prefix sub flow, and the suffix sub
    6980                 :            :  * flow uses tag item with the unique flow id.
    6981                 :            :  *
    6982                 :            :  * @param dev
    6983                 :            :  *   Pointer to Ethernet device.
    6984                 :            :  * @param[in] flow
    6985                 :            :  *   Parent flow structure pointer.
    6986                 :            :  * @param[in] attr
    6987                 :            :  *   Flow rule attributes.
    6988                 :            :  * @param[in] items
    6989                 :            :  *   Pattern specification (list terminated by the END pattern item).
    6990                 :            :  * @param[in] actions
    6991                 :            :  *   Associated actions (list terminated by the END action).
    6992                 :            :  * @param[in] flow_split_info
    6993                 :            :  *   Pointer to flow split info structure.
    6994                 :            :  * @param[out] error
    6995                 :            :  *   Perform verbose error reporting if not NULL.
    6996                 :            :  * @return
    6997                 :            :  *   0 on success, negative value otherwise
    6998                 :            :  */
    6999                 :            : static int
    7000                 :          0 : flow_create_split_sample(struct rte_eth_dev *dev,
    7001                 :            :                          struct rte_flow *flow,
    7002                 :            :                          const struct rte_flow_attr *attr,
    7003                 :            :                          const struct rte_flow_item items[],
    7004                 :            :                          const struct rte_flow_action actions[],
    7005                 :            :                          struct mlx5_flow_split_info *flow_split_info,
    7006                 :            :                          struct rte_flow_error *error)
    7007                 :            : {
    7008                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7009                 :            :         struct rte_flow_action *sfx_actions = NULL;
    7010                 :            :         struct rte_flow_action *pre_actions = NULL;
    7011                 :            :         struct rte_flow_item *sfx_items = NULL;
    7012                 :          0 :         struct mlx5_flow *dev_flow = NULL;
    7013                 :          0 :         struct rte_flow_attr sfx_attr = *attr;
    7014                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    7015                 :            :         struct mlx5_flow_dv_sample_resource *sample_res;
    7016                 :            :         struct mlx5_flow_tbl_data_entry *sfx_tbl_data;
    7017                 :            :         struct mlx5_flow_tbl_resource *sfx_tbl;
    7018                 :          0 :         struct mlx5_flow_workspace *wks = mlx5_flow_get_thread_workspace();
    7019                 :            : #endif
    7020                 :            :         size_t act_size;
    7021                 :            :         size_t item_size;
    7022                 :            :         uint32_t fdb_tx = 0;
    7023                 :            :         int32_t tag_id = 0;
    7024                 :            :         int actions_n = 0;
    7025                 :            :         int sample_action_pos;
    7026                 :            :         int qrss_action_pos;
    7027                 :            :         int add_tag = 0;
    7028                 :          0 :         int modify_after_mirror = 0;
    7029                 :            :         uint16_t jump_table = 0;
    7030                 :            :         const uint32_t next_ft_step = 1;
    7031                 :            :         int ret = 0;
    7032                 :            :         struct mlx5_priv *item_port_priv = NULL;
    7033                 :            :         const struct rte_flow_item *item;
    7034                 :            : 
    7035         [ #  # ]:          0 :         if (priv->sampler_en)
    7036                 :          0 :                 actions_n = flow_check_match_action(actions, attr,
    7037                 :            :                                         RTE_FLOW_ACTION_TYPE_SAMPLE,
    7038                 :            :                                         &sample_action_pos, &qrss_action_pos,
    7039                 :            :                                         &modify_after_mirror);
    7040         [ #  # ]:          0 :         if (actions_n) {
    7041                 :            :                 /* The prefix actions must includes sample, tag, end. */
    7042                 :          0 :                 act_size = sizeof(struct rte_flow_action) * (actions_n * 2 + 1)
    7043                 :            :                            + sizeof(struct mlx5_rte_flow_action_set_tag);
    7044                 :            :                 item_size = sizeof(struct rte_flow_item) * SAMPLE_SUFFIX_ITEM +
    7045                 :            :                             sizeof(struct mlx5_rte_flow_item_tag) * 2;
    7046                 :          0 :                 sfx_actions = mlx5_malloc(MLX5_MEM_ZERO, (act_size +
    7047                 :            :                                           item_size), 0, SOCKET_ID_ANY);
    7048         [ #  # ]:          0 :                 if (!sfx_actions)
    7049                 :          0 :                         return rte_flow_error_set(error, ENOMEM,
    7050                 :            :                                                   RTE_FLOW_ERROR_TYPE_ACTION,
    7051                 :            :                                                   NULL, "no memory to split "
    7052                 :            :                                                   "sample flow");
    7053         [ #  # ]:          0 :                 for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
    7054         [ #  # ]:          0 :                         if (item->type == RTE_FLOW_ITEM_TYPE_PORT_ID) {
    7055                 :            :                                 const struct rte_flow_item_port_id *spec;
    7056                 :            : 
    7057                 :          0 :                                 spec = (const struct rte_flow_item_port_id *)item->spec;
    7058         [ #  # ]:          0 :                                 if (spec)
    7059                 :            :                                         item_port_priv =
    7060                 :          0 :                                                 mlx5_port_to_eswitch_info(spec->id, true);
    7061                 :            :                                 break;
    7062         [ #  # ]:          0 :                         } else if (item->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT) {
    7063                 :            :                                 const struct rte_flow_item_ethdev *spec;
    7064                 :            : 
    7065                 :          0 :                                 spec = (const struct rte_flow_item_ethdev *)item->spec;
    7066         [ #  # ]:          0 :                                 if (spec)
    7067                 :            :                                         item_port_priv =
    7068                 :          0 :                                                 mlx5_port_to_eswitch_info(spec->port_id, true);
    7069                 :            :                                 break;
    7070         [ #  # ]:          0 :                         } else if (item->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
    7071                 :            :                                 const struct rte_flow_item_ethdev *spec;
    7072                 :            : 
    7073                 :          0 :                                 spec = (const struct rte_flow_item_ethdev *)item->spec;
    7074         [ #  # ]:          0 :                                 if (spec)
    7075                 :            :                                         item_port_priv =
    7076                 :          0 :                                                 mlx5_port_to_eswitch_info(spec->port_id, true);
    7077                 :            :                                 break;
    7078                 :            :                         }
    7079                 :            :                 }
    7080                 :            :                 /* The representor_id is UINT16_MAX for uplink. */
    7081   [ #  #  #  # ]:          0 :                 fdb_tx = (attr->transfer &&
    7082                 :            :                           flow_source_vport_representor(priv, item_port_priv));
    7083                 :            :                 /*
    7084                 :            :                  * When reg_c_preserve is set, metadata registers Cx preserve
    7085                 :            :                  * their value even through packet duplication.
    7086                 :            :                  */
    7087                 :          0 :                 add_tag = (!fdb_tx ||
    7088         [ #  # ]:          0 :                            priv->sh->cdev->config.hca_attr.reg_c_preserve);
    7089                 :            :                 if (add_tag)
    7090                 :          0 :                         sfx_items = (struct rte_flow_item *)((char *)sfx_actions
    7091                 :            :                                         + act_size);
    7092         [ #  # ]:          0 :                 if (modify_after_mirror)
    7093                 :          0 :                         jump_table = attr->group * MLX5_FLOW_TABLE_FACTOR +
    7094                 :            :                                      next_ft_step;
    7095                 :          0 :                 pre_actions = sfx_actions + actions_n;
    7096                 :          0 :                 tag_id = flow_sample_split_prep(dev, add_tag, items, sfx_items,
    7097                 :            :                                                 actions, sfx_actions,
    7098                 :            :                                                 pre_actions, actions_n,
    7099                 :            :                                                 sample_action_pos,
    7100                 :            :                                                 qrss_action_pos, jump_table,
    7101                 :            :                                                 error);
    7102   [ #  #  #  # ]:          0 :                 if (tag_id < 0 || (add_tag && !tag_id)) {
    7103                 :          0 :                         ret = -rte_errno;
    7104                 :          0 :                         goto exit;
    7105                 :            :                 }
    7106         [ #  # ]:          0 :                 if (modify_after_mirror)
    7107                 :          0 :                         flow_split_info->skip_scale =
    7108                 :            :                                         1 << MLX5_SCALE_JUMP_FLOW_GROUP_BIT;
    7109                 :            :                 /* Add the prefix subflow. */
    7110                 :          0 :                 ret = flow_create_split_inner(dev, flow, &dev_flow, attr,
    7111                 :            :                                               items, pre_actions,
    7112                 :            :                                               flow_split_info, error);
    7113         [ #  # ]:          0 :                 if (ret) {
    7114                 :          0 :                         ret = -rte_errno;
    7115                 :          0 :                         goto exit;
    7116                 :            :                 }
    7117                 :          0 :                 dev_flow->handle->split_flow_id = tag_id;
    7118                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    7119         [ #  # ]:          0 :                 if (!modify_after_mirror) {
    7120                 :            :                         /* Set the sfx group attr. */
    7121                 :          0 :                         sample_res = (struct mlx5_flow_dv_sample_resource *)
    7122                 :            :                                                 dev_flow->dv.sample_res;
    7123                 :          0 :                         sfx_tbl = (struct mlx5_flow_tbl_resource *)
    7124                 :            :                                                 sample_res->normal_path_tbl;
    7125                 :          0 :                         sfx_tbl_data = container_of(sfx_tbl,
    7126                 :            :                                                 struct mlx5_flow_tbl_data_entry,
    7127                 :            :                                                 tbl);
    7128                 :          0 :                         sfx_attr.group = sfx_attr.transfer ?
    7129         [ #  # ]:          0 :                         (sfx_tbl_data->level - 1) : sfx_tbl_data->level;
    7130                 :            :                 } else {
    7131                 :            :                         MLX5_ASSERT(attr->transfer);
    7132                 :          0 :                         sfx_attr.group = jump_table;
    7133                 :            :                 }
    7134                 :          0 :                 flow_split_info->prefix_layers =
    7135                 :          0 :                                 flow_get_prefix_layer_flags(dev_flow);
    7136                 :            :                 MLX5_ASSERT(wks);
    7137                 :          0 :                 flow_split_info->prefix_mark |= wks->mark;
    7138                 :            :                 /* Suffix group level already be scaled with factor, set
    7139                 :            :                  * MLX5_SCALE_FLOW_GROUP_BIT of skip_scale to 1 to avoid scale
    7140                 :            :                  * again in translation.
    7141                 :            :                  */
    7142                 :          0 :                 flow_split_info->skip_scale = 1 << MLX5_SCALE_FLOW_GROUP_BIT;
    7143                 :            : #endif
    7144                 :            :         }
    7145                 :            :         /* Add the suffix subflow. */
    7146   [ #  #  #  # ]:          0 :         ret = flow_create_split_meter(dev, flow, &sfx_attr,
    7147                 :            :                                       sfx_items ? sfx_items : items,
    7148                 :            :                                       sfx_actions ? sfx_actions : actions,
    7149                 :            :                                       flow_split_info, error);
    7150                 :          0 : exit:
    7151         [ #  # ]:          0 :         if (sfx_actions)
    7152                 :          0 :                 mlx5_free(sfx_actions);
    7153                 :            :         return ret;
    7154                 :            : }
    7155                 :            : 
    7156                 :            : /**
    7157                 :            :  * Split the flow to subflow set. The splitters might be linked
    7158                 :            :  * in the chain, like this:
    7159                 :            :  * flow_create_split_outer() calls:
    7160                 :            :  *   flow_create_split_meter() calls:
    7161                 :            :  *     flow_create_split_metadata(meter_subflow_0) calls:
    7162                 :            :  *       flow_create_split_inner(metadata_subflow_0)
    7163                 :            :  *       flow_create_split_inner(metadata_subflow_1)
    7164                 :            :  *       flow_create_split_inner(metadata_subflow_2)
    7165                 :            :  *     flow_create_split_metadata(meter_subflow_1) calls:
    7166                 :            :  *       flow_create_split_inner(metadata_subflow_0)
    7167                 :            :  *       flow_create_split_inner(metadata_subflow_1)
    7168                 :            :  *       flow_create_split_inner(metadata_subflow_2)
    7169                 :            :  *
    7170                 :            :  * This provide flexible way to add new levels of flow splitting.
    7171                 :            :  * The all of successfully created subflows are included to the
    7172                 :            :  * parent flow dev_flow list.
    7173                 :            :  *
    7174                 :            :  * @param dev
    7175                 :            :  *   Pointer to Ethernet device.
    7176                 :            :  * @param[in] flow
    7177                 :            :  *   Parent flow structure pointer.
    7178                 :            :  * @param[in] attr
    7179                 :            :  *   Flow rule attributes.
    7180                 :            :  * @param[in] items
    7181                 :            :  *   Pattern specification (list terminated by the END pattern item).
    7182                 :            :  * @param[in] actions
    7183                 :            :  *   Associated actions (list terminated by the END action).
    7184                 :            :  * @param[in] flow_split_info
    7185                 :            :  *   Pointer to flow split info structure.
    7186                 :            :  * @param[out] error
    7187                 :            :  *   Perform verbose error reporting if not NULL.
    7188                 :            :  * @return
    7189                 :            :  *   0 on success, negative value otherwise
    7190                 :            :  */
    7191                 :            : static int
    7192                 :            : flow_create_split_outer(struct rte_eth_dev *dev,
    7193                 :            :                         struct rte_flow *flow,
    7194                 :            :                         const struct rte_flow_attr *attr,
    7195                 :            :                         const struct rte_flow_item items[],
    7196                 :            :                         const struct rte_flow_action actions[],
    7197                 :            :                         struct mlx5_flow_split_info *flow_split_info,
    7198                 :            :                         struct rte_flow_error *error)
    7199                 :            : {
    7200                 :            :         int ret;
    7201                 :            : 
    7202                 :          0 :         ret = flow_create_split_sample(dev, flow, attr, items,
    7203                 :            :                                        actions, flow_split_info, error);
    7204                 :            :         MLX5_ASSERT(ret <= 0);
    7205                 :            :         return ret;
    7206                 :            : }
    7207                 :            : 
    7208                 :            : static inline struct mlx5_flow_tunnel *
    7209                 :            : flow_tunnel_from_rule(const struct mlx5_flow *flow)
    7210                 :            : {
    7211                 :            :         struct mlx5_flow_tunnel *tunnel;
    7212                 :            : 
    7213                 :            : #pragma GCC diagnostic push
    7214                 :            : #pragma GCC diagnostic ignored "-Wcast-qual"
    7215                 :          0 :         tunnel = (typeof(tunnel))flow->tunnel;
    7216                 :            : #pragma GCC diagnostic pop
    7217                 :            : 
    7218                 :            :         return tunnel;
    7219                 :            : }
    7220                 :            : 
    7221                 :            : /**
    7222                 :            :  * Create a flow and add it to @p list.
    7223                 :            :  *
    7224                 :            :  * @param dev
    7225                 :            :  *   Pointer to Ethernet device.
    7226                 :            :  * @param list
    7227                 :            :  *   Pointer to a TAILQ flow list. If this parameter NULL,
    7228                 :            :  *   no list insertion occurred, flow is just created,
    7229                 :            :  *   this is caller's responsibility to track the
    7230                 :            :  *   created flow.
    7231                 :            :  * @param[in] attr
    7232                 :            :  *   Flow rule attributes.
    7233                 :            :  * @param[in] items
    7234                 :            :  *   Pattern specification (list terminated by the END pattern item).
    7235                 :            :  * @param[in] actions
    7236                 :            :  *   Associated actions (list terminated by the END action).
    7237                 :            :  * @param[in] external
    7238                 :            :  *   This flow rule is created by request external to PMD.
    7239                 :            :  * @param[out] error
    7240                 :            :  *   Perform verbose error reporting if not NULL.
    7241                 :            :  *
    7242                 :            :  * @return
    7243                 :            :  *   A flow index on success, 0 otherwise and rte_errno is set.
    7244                 :            :  */
    7245                 :            : static uint32_t
    7246                 :          0 : flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type,
    7247                 :            :                  const struct rte_flow_attr *attr,
    7248                 :            :                  const struct rte_flow_item items[],
    7249                 :            :                  const struct rte_flow_action original_actions[],
    7250                 :            :                  bool external, struct rte_flow_error *error)
    7251                 :            : {
    7252                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7253                 :            :         struct rte_flow *flow = NULL;
    7254                 :            :         struct mlx5_flow *dev_flow;
    7255                 :            :         const struct rte_flow_action_rss *rss = NULL;
    7256                 :            :         struct mlx5_translated_action_handle
    7257                 :            :                 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
    7258                 :          0 :         int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
    7259                 :            :         union {
    7260                 :            :                 struct mlx5_flow_expand_rss buf;
    7261                 :            :                 uint8_t buffer[8192];
    7262                 :            :         } expand_buffer;
    7263                 :            :         union {
    7264                 :            :                 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
    7265                 :            :                 uint8_t buffer[2048];
    7266                 :            :         } actions_rx;
    7267                 :            :         union {
    7268                 :            :                 struct rte_flow_action actions[MLX5_MAX_SPLIT_ACTIONS];
    7269                 :            :                 uint8_t buffer[2048];
    7270                 :            :         } actions_hairpin_tx;
    7271                 :            :         union {
    7272                 :            :                 struct rte_flow_item items[MLX5_MAX_SPLIT_ITEMS];
    7273                 :            :                 uint8_t buffer[2048];
    7274                 :            :         } items_tx;
    7275                 :            :         struct mlx5_rte_flow_item_sq sq_specs[RTE_MAX_QUEUES_PER_PORT];
    7276                 :            :         struct mlx5_flow_expand_rss *buf = &expand_buffer.buf;
    7277                 :            :         struct mlx5_flow_rss_desc *rss_desc;
    7278                 :            :         const struct rte_flow_action *p_actions_rx;
    7279                 :            :         uint32_t i;
    7280                 :          0 :         uint32_t idx = 0;
    7281                 :            :         int hairpin_flow;
    7282                 :          0 :         struct rte_flow_attr attr_tx = { .priority = 0 };
    7283                 :            :         const struct rte_flow_action *actions;
    7284                 :          0 :         struct rte_flow_action *translated_actions = NULL;
    7285                 :            :         struct mlx5_flow_tunnel *tunnel;
    7286                 :          0 :         struct tunnel_default_miss_ctx default_miss_ctx = { 0, };
    7287                 :          0 :         struct mlx5_flow_workspace *wks = mlx5_flow_push_thread_workspace();
    7288                 :          0 :         struct mlx5_flow_split_info flow_split_info = {
    7289                 :            :                 .external = !!external,
    7290                 :            :                 .skip_scale = 0,
    7291                 :            :                 .flow_idx = 0,
    7292                 :            :                 .prefix_mark = 0,
    7293                 :            :                 .prefix_layers = 0,
    7294                 :            :                 .table_id = 0
    7295                 :            :         };
    7296                 :            :         int ret;
    7297                 :            : 
    7298                 :            :         MLX5_ASSERT(wks);
    7299                 :          0 :         rss_desc = &wks->rss_desc;
    7300                 :          0 :         ret = flow_action_handles_translate(dev, original_actions,
    7301                 :            :                                             indir_actions,
    7302                 :            :                                             &indir_actions_n,
    7303                 :            :                                             &translated_actions, error);
    7304         [ #  # ]:          0 :         if (ret < 0) {
    7305                 :            :                 MLX5_ASSERT(translated_actions == NULL);
    7306                 :            :                 return 0;
    7307                 :            :         }
    7308         [ #  # ]:          0 :         actions = translated_actions ? translated_actions : original_actions;
    7309                 :            :         p_actions_rx = actions;
    7310                 :          0 :         hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
    7311                 :          0 :         ret = flow_drv_validate(dev, attr, items, p_actions_rx,
    7312                 :            :                                 external, hairpin_flow, error);
    7313         [ #  # ]:          0 :         if (ret < 0)
    7314                 :          0 :                 goto error_before_hairpin_split;
    7315                 :          0 :         flow = mlx5_ipool_zmalloc(priv->flows[type], &idx);
    7316         [ #  # ]:          0 :         if (!flow) {
    7317                 :          0 :                 rte_errno = ENOMEM;
    7318                 :          0 :                 goto error_before_hairpin_split;
    7319                 :            :         }
    7320         [ #  # ]:          0 :         if (hairpin_flow > 0) {
    7321         [ #  # ]:          0 :                 if (hairpin_flow > MLX5_MAX_SPLIT_ACTIONS) {
    7322                 :          0 :                         rte_errno = EINVAL;
    7323                 :          0 :                         goto error_before_hairpin_split;
    7324                 :            :                 }
    7325                 :          0 :                 flow_hairpin_split(dev, actions, actions_rx.actions,
    7326                 :            :                                    actions_hairpin_tx.actions, items_tx.items,
    7327                 :            :                                    idx);
    7328                 :            :                 p_actions_rx = actions_rx.actions;
    7329                 :            :         }
    7330                 :          0 :         flow_split_info.flow_idx = idx;
    7331         [ #  # ]:          0 :         flow->drv_type = flow_get_drv_type(dev, attr);
    7332                 :            :         MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
    7333                 :            :                     flow->drv_type < MLX5_FLOW_TYPE_MAX);
    7334                 :            :         memset(rss_desc, 0, offsetof(struct mlx5_flow_rss_desc, queue));
    7335                 :            :         /* RSS Action only works on NIC RX domain */
    7336         [ #  # ]:          0 :         if (attr->ingress)
    7337                 :          0 :                 rss = flow_get_rss_action(dev, p_actions_rx);
    7338         [ #  # ]:          0 :         if (rss) {
    7339                 :            :                 MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512);
    7340                 :          0 :                 rss_desc->symmetric_hash_function = MLX5_RSS_IS_SYMM(rss->func);
    7341                 :            :                 /*
    7342                 :            :                  * The following information is required by
    7343                 :            :                  * mlx5_flow_hashfields_adjust() in advance.
    7344                 :            :                  */
    7345                 :          0 :                 rss_desc->level = rss->level;
    7346                 :            :                 /* RSS type 0 indicates default RSS type (RTE_ETH_RSS_IP). */
    7347         [ #  # ]:          0 :                 rss_desc->types = !rss->types ? RTE_ETH_RSS_IP : rss->types;
    7348                 :            :         }
    7349                 :          0 :         flow->dev_handles = 0;
    7350   [ #  #  #  # ]:          0 :         if (rss && rss->types) {
    7351                 :            :                 unsigned int graph_root;
    7352                 :            : 
    7353                 :          0 :                 graph_root = find_graph_root(rss->level);
    7354                 :          0 :                 ret = mlx5_flow_expand_rss(buf, sizeof(expand_buffer.buffer),
    7355                 :            :                                            items, rss->types,
    7356                 :            :                                            mlx5_support_expansion, graph_root);
    7357                 :            :                 MLX5_ASSERT(ret > 0 &&
    7358                 :            :                        (unsigned int)ret < sizeof(expand_buffer.buffer));
    7359         [ #  # ]:          0 :                 if (rte_log_can_log(mlx5_logtype, RTE_LOG_DEBUG)) {
    7360         [ #  # ]:          0 :                         for (i = 0; i < buf->entries; ++i)
    7361                 :          0 :                                 mlx5_dbg__print_pattern(buf->entry[i].pattern);
    7362                 :            :                 }
    7363                 :            :         } else {
    7364                 :          0 :                 ret = mlx5_flow_expand_sqn((struct mlx5_flow_expand_sqn *)buf,
    7365                 :            :                                            sizeof(expand_buffer.buffer),
    7366                 :            :                                            items, sq_specs);
    7367         [ #  # ]:          0 :                 if (ret) {
    7368                 :          0 :                         rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
    7369                 :            :                                            NULL, "not enough memory for rte_flow");
    7370                 :          0 :                         goto error;
    7371                 :            :                 }
    7372         [ #  # ]:          0 :                 if (buf->entries == 0) {
    7373                 :          0 :                         buf->entries = 1;
    7374                 :          0 :                         buf->entry[0].pattern = (void *)(uintptr_t)items;
    7375                 :            :                 }
    7376                 :            :         }
    7377                 :          0 :         rss_desc->shared_rss = flow_get_shared_rss_action(dev, indir_actions,
    7378                 :            :                                                       indir_actions_n);
    7379         [ #  # ]:          0 :         for (i = 0; i < buf->entries; ++i) {
    7380                 :            :                 /* Initialize flow split data. */
    7381                 :          0 :                 flow_split_info.prefix_layers = 0;
    7382                 :          0 :                 flow_split_info.prefix_mark = 0;
    7383                 :          0 :                 flow_split_info.skip_scale = 0;
    7384                 :            :                 /*
    7385                 :            :                  * The splitter may create multiple dev_flows,
    7386                 :            :                  * depending on configuration. In the simplest
    7387                 :            :                  * case it just creates unmodified original flow.
    7388                 :            :                  */
    7389                 :            :                 ret = flow_create_split_outer(dev, flow, attr,
    7390                 :          0 :                                               buf->entry[i].pattern,
    7391                 :            :                                               p_actions_rx, &flow_split_info,
    7392                 :            :                                               error);
    7393         [ #  # ]:          0 :                 if (ret < 0)
    7394                 :          0 :                         goto error;
    7395         [ #  # ]:          0 :                 if (is_flow_tunnel_steer_rule(wks->flows[0].tof_type)) {
    7396                 :          0 :                         ret = flow_tunnel_add_default_miss(dev, flow, attr,
    7397                 :            :                                                            p_actions_rx,
    7398                 :            :                                                            idx,
    7399                 :            :                                                            wks->flows[0].tunnel,
    7400                 :            :                                                            &default_miss_ctx,
    7401                 :            :                                                            error);
    7402         [ #  # ]:          0 :                         if (ret < 0) {
    7403                 :          0 :                                 mlx5_free(default_miss_ctx.queue);
    7404                 :          0 :                                 goto error;
    7405                 :            :                         }
    7406                 :            :                 }
    7407                 :            :         }
    7408                 :            :         /* Create the tx flow. */
    7409         [ #  # ]:          0 :         if (hairpin_flow) {
    7410                 :          0 :                 attr_tx.group = MLX5_HAIRPIN_TX_TABLE;
    7411                 :          0 :                 attr_tx.ingress = 0;
    7412                 :          0 :                 attr_tx.egress = 1;
    7413                 :          0 :                 dev_flow = flow_drv_prepare(dev, flow, &attr_tx, items_tx.items,
    7414                 :            :                                          actions_hairpin_tx.actions,
    7415                 :            :                                          idx, error);
    7416         [ #  # ]:          0 :                 if (!dev_flow)
    7417                 :          0 :                         goto error;
    7418                 :          0 :                 dev_flow->flow = flow;
    7419                 :          0 :                 dev_flow->external = 0;
    7420                 :          0 :                 SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
    7421                 :            :                               dev_flow->handle, next);
    7422                 :            :                 ret = flow_drv_translate(dev, dev_flow, &attr_tx,
    7423                 :            :                                          items_tx.items,
    7424                 :            :                                          actions_hairpin_tx.actions, error);
    7425         [ #  # ]:          0 :                 if (ret < 0)
    7426                 :          0 :                         goto error;
    7427                 :            :         }
    7428                 :            :         /*
    7429                 :            :          * Update the metadata register copy table. If extensive
    7430                 :            :          * metadata feature is enabled and registers are supported
    7431                 :            :          * we might create the extra rte_flow for each unique
    7432                 :            :          * MARK/FLAG action ID.
    7433                 :            :          *
    7434                 :            :          * The table is updated for ingress and transfer flows only, because
    7435                 :            :          * the egress Flows belong to the different device and
    7436                 :            :          * copy table should be updated in peer NIC Rx domain.
    7437                 :            :          */
    7438   [ #  #  #  # ]:          0 :         if ((attr->ingress || attr->transfer) &&
    7439         [ #  # ]:          0 :             (external || attr->group != MLX5_FLOW_MREG_CP_TABLE_GROUP)) {
    7440                 :          0 :                 ret = flow_mreg_update_copy_table(dev, flow, actions, error);
    7441         [ #  # ]:          0 :                 if (ret)
    7442                 :          0 :                         goto error;
    7443                 :            :         }
    7444                 :            :         /*
    7445                 :            :          * If the flow is external (from application) OR device is started,
    7446                 :            :          * OR mreg discover, then apply immediately.
    7447                 :            :          */
    7448   [ #  #  #  # ]:          0 :         if (external || dev->data->dev_started ||
    7449         [ #  # ]:          0 :             (attr->group == MLX5_FLOW_MREG_CP_TABLE_GROUP &&
    7450         [ #  # ]:          0 :              attr->priority == MLX5_FLOW_LOWEST_PRIO_INDICATOR)) {
    7451                 :            :                 ret = flow_drv_apply(dev, flow, error);
    7452         [ #  # ]:          0 :                 if (ret < 0)
    7453                 :          0 :                         goto error;
    7454                 :            :         }
    7455                 :          0 :         flow->type = type;
    7456                 :          0 :         flow_rxq_flags_set(dev, flow);
    7457                 :          0 :         rte_free(translated_actions);
    7458                 :            :         tunnel = flow_tunnel_from_rule(wks->flows);
    7459         [ #  # ]:          0 :         if (tunnel) {
    7460                 :          0 :                 flow->tunnel = 1;
    7461                 :          0 :                 flow->tunnel_id = tunnel->tunnel_id;
    7462                 :          0 :                 __atomic_fetch_add(&tunnel->refctn, 1, __ATOMIC_RELAXED);
    7463                 :          0 :                 mlx5_free(default_miss_ctx.queue);
    7464                 :            :         }
    7465                 :          0 :         mlx5_flow_pop_thread_workspace();
    7466                 :          0 :         return idx;
    7467                 :          0 : error:
    7468                 :            :         MLX5_ASSERT(flow);
    7469                 :          0 :         ret = rte_errno; /* Save rte_errno before cleanup. */
    7470                 :          0 :         flow_mreg_del_copy_action(dev, flow);
    7471                 :            :         flow_drv_destroy(dev, flow);
    7472         [ #  # ]:          0 :         if (rss_desc->shared_rss)
    7473                 :          0 :                 __atomic_fetch_sub(&((struct mlx5_shared_action_rss *)
    7474                 :          0 :                         mlx5_ipool_get
    7475                 :          0 :                         (priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
    7476                 :            :                         rss_desc->shared_rss))->refcnt, 1, __ATOMIC_RELAXED);
    7477                 :          0 :         mlx5_ipool_free(priv->flows[type], idx);
    7478                 :          0 :         rte_errno = ret; /* Restore rte_errno. */
    7479                 :            :         ret = rte_errno;
    7480                 :            :         rte_errno = ret;
    7481                 :          0 : error_before_hairpin_split:
    7482                 :          0 :         mlx5_flow_pop_thread_workspace();
    7483                 :          0 :         rte_free(translated_actions);
    7484                 :          0 :         return 0;
    7485                 :            : }
    7486                 :            : 
    7487                 :            : /**
    7488                 :            :  * Create a dedicated flow rule on e-switch table 0 (root table), to direct all
    7489                 :            :  * incoming packets to table 1.
    7490                 :            :  *
    7491                 :            :  * Other flow rules, requested for group n, will be created in
    7492                 :            :  * e-switch table n+1.
    7493                 :            :  * Jump action to e-switch group n will be created to group n+1.
    7494                 :            :  *
    7495                 :            :  * Used when working in switchdev mode, to utilise advantages of table 1
    7496                 :            :  * and above.
    7497                 :            :  *
    7498                 :            :  * @param dev
    7499                 :            :  *   Pointer to Ethernet device.
    7500                 :            :  *
    7501                 :            :  * @return
    7502                 :            :  *   Pointer to flow on success, NULL otherwise and rte_errno is set.
    7503                 :            :  */
    7504                 :            : struct rte_flow *
    7505                 :          0 : mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev)
    7506                 :            : {
    7507                 :          0 :         const struct rte_flow_attr attr = {
    7508                 :            :                 .group = 0,
    7509                 :            :                 .priority = 0,
    7510                 :            :                 .ingress = 0,
    7511                 :            :                 .egress = 0,
    7512                 :            :                 .transfer = 1,
    7513                 :            :         };
    7514                 :          0 :         const struct rte_flow_item pattern = {
    7515                 :            :                 .type = RTE_FLOW_ITEM_TYPE_END,
    7516                 :            :         };
    7517                 :          0 :         struct rte_flow_action_jump jump = {
    7518                 :            :                 .group = 1,
    7519                 :            :         };
    7520                 :          0 :         const struct rte_flow_action actions[] = {
    7521                 :            :                 {
    7522                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
    7523                 :            :                         .conf = &jump,
    7524                 :            :                 },
    7525                 :            :                 {
    7526                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    7527                 :            :                 },
    7528                 :            :         };
    7529                 :            :         struct rte_flow_error error;
    7530                 :            : 
    7531                 :          0 :         return (void *)(uintptr_t)flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
    7532                 :            :                                                    &attr, &pattern,
    7533                 :            :                                                    actions, false, &error);
    7534                 :            : }
    7535                 :            : 
    7536                 :            : /**
    7537                 :            :  * Create a dedicated flow rule on e-switch table 1, matches ESW manager
    7538                 :            :  * and sq number, directs all packets to peer vport.
    7539                 :            :  *
    7540                 :            :  * @param dev
    7541                 :            :  *   Pointer to Ethernet device.
    7542                 :            :  * @param sq_num
    7543                 :            :  *   SQ number.
    7544                 :            :  *
    7545                 :            :  * @return
    7546                 :            :  *   Flow ID on success, 0 otherwise and rte_errno is set.
    7547                 :            :  */
    7548                 :            : uint32_t
    7549                 :          0 : mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, uint32_t sq_num)
    7550                 :            : {
    7551                 :          0 :         struct rte_flow_attr attr = {
    7552                 :            :                 .group = 0,
    7553                 :            :                 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
    7554                 :            :                 .ingress = 0,
    7555                 :            :                 .egress = 0,
    7556                 :            :                 .transfer = 1,
    7557                 :            :         };
    7558                 :          0 :         struct rte_flow_item_port_id port_spec = {
    7559                 :            :                 .id = MLX5_PORT_ESW_MGR,
    7560                 :            :         };
    7561                 :          0 :         struct mlx5_rte_flow_item_sq sq_spec = {
    7562                 :            :                 .queue = sq_num,
    7563                 :            :         };
    7564                 :          0 :         struct rte_flow_item pattern[] = {
    7565                 :            :                 {
    7566                 :            :                         .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
    7567                 :            :                         .spec = &port_spec,
    7568                 :            :                 },
    7569                 :            :                 {
    7570                 :            :                         .type = (enum rte_flow_item_type)
    7571                 :            :                                 MLX5_RTE_FLOW_ITEM_TYPE_SQ,
    7572                 :            :                         .spec = &sq_spec,
    7573                 :            :                 },
    7574                 :            :                 {
    7575                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    7576                 :            :                 },
    7577                 :            :         };
    7578                 :          0 :         struct rte_flow_action_jump jump = {
    7579                 :            :                 .group = 1,
    7580                 :            :         };
    7581                 :          0 :         struct rte_flow_action_port_id port = {
    7582                 :          0 :                 .id = dev->data->port_id,
    7583                 :            :         };
    7584                 :          0 :         struct rte_flow_action actions[] = {
    7585                 :            :                 {
    7586                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
    7587                 :            :                         .conf = &jump,
    7588                 :            :                 },
    7589                 :            :                 {
    7590                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    7591                 :            :                 },
    7592                 :            :         };
    7593                 :            :         struct rte_flow_error error;
    7594                 :            : 
    7595                 :            :         /*
    7596                 :            :          * Creates group 0, highest priority jump flow.
    7597                 :            :          * Matches txq to bypass kernel packets.
    7598                 :            :          */
    7599         [ #  # ]:          0 :         if (flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern, actions,
    7600                 :            :                              false, &error) == 0)
    7601                 :            :                 return 0;
    7602                 :            :         /* Create group 1, lowest priority redirect flow for txq. */
    7603                 :          0 :         attr.group = 1;
    7604                 :          0 :         actions[0].conf = &port;
    7605                 :          0 :         actions[0].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
    7606                 :          0 :         return flow_list_create(dev, MLX5_FLOW_TYPE_CTL, &attr, pattern,
    7607                 :            :                                 actions, false, &error);
    7608                 :            : }
    7609                 :            : 
    7610                 :            : /**
    7611                 :            :  * Validate a flow supported by the NIC.
    7612                 :            :  *
    7613                 :            :  * @see rte_flow_validate()
    7614                 :            :  * @see rte_flow_ops
    7615                 :            :  */
    7616                 :            : int
    7617                 :          0 : mlx5_flow_validate(struct rte_eth_dev *dev,
    7618                 :            :                    const struct rte_flow_attr *attr,
    7619                 :            :                    const struct rte_flow_item items[],
    7620                 :            :                    const struct rte_flow_action original_actions[],
    7621                 :            :                    struct rte_flow_error *error)
    7622                 :            : {
    7623                 :            :         int hairpin_flow;
    7624                 :            :         struct mlx5_translated_action_handle
    7625                 :            :                 indir_actions[MLX5_MAX_INDIRECT_ACTIONS];
    7626                 :          0 :         int indir_actions_n = MLX5_MAX_INDIRECT_ACTIONS;
    7627                 :            :         const struct rte_flow_action *actions;
    7628                 :          0 :         struct rte_flow_action *translated_actions = NULL;
    7629                 :          0 :         int ret = flow_action_handles_translate(dev, original_actions,
    7630                 :            :                                                 indir_actions,
    7631                 :            :                                                 &indir_actions_n,
    7632                 :            :                                                 &translated_actions, error);
    7633                 :            : 
    7634         [ #  # ]:          0 :         if (ret)
    7635                 :            :                 return ret;
    7636         [ #  # ]:          0 :         actions = translated_actions ? translated_actions : original_actions;
    7637                 :          0 :         hairpin_flow = flow_check_hairpin_split(dev, attr, actions);
    7638                 :          0 :         ret = flow_drv_validate(dev, attr, items, actions,
    7639                 :            :                                 true, hairpin_flow, error);
    7640                 :          0 :         rte_free(translated_actions);
    7641                 :          0 :         return ret;
    7642                 :            : }
    7643                 :            : 
    7644                 :            : static int
    7645                 :          0 : mlx5_flow_cache_flow_info(struct rte_eth_dev *dev,
    7646                 :            :                           const struct rte_flow_attr *attr,
    7647                 :            :                           const uint32_t orig_prio,
    7648                 :            :                           const struct rte_flow_item *items,
    7649                 :            :                           const struct rte_flow_action *actions,
    7650                 :            :                           uint32_t flow_idx)
    7651                 :            : {
    7652                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7653                 :            :         struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
    7654                 :            :         struct mlx5_dv_flow_info *flow_info, *tmp_info;
    7655                 :            :         struct rte_flow_error error;
    7656                 :            :         int len, ret;
    7657                 :            : 
    7658                 :          0 :         flow_info = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_info), 0, SOCKET_ID_ANY);
    7659         [ #  # ]:          0 :         if (!flow_info) {
    7660                 :          0 :                 DRV_LOG(ERR, "No enough memory for flow_info caching.");
    7661                 :          0 :                 return -1;
    7662                 :            :         }
    7663                 :          0 :         flow_info->orig_prio = orig_prio;
    7664                 :          0 :         flow_info->attr = *attr;
    7665                 :            :         /* Standby mode rule awlays saves it in low priority entry. */
    7666                 :          0 :         flow_info->flow_idx_low_prio = flow_idx;
    7667                 :            : 
    7668                 :            :         /* Store matching items. */
    7669                 :          0 :         ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, NULL, 0, items, &error);
    7670         [ #  # ]:          0 :         if (ret <= 0) {
    7671                 :          0 :                 DRV_LOG(ERR, "Can't get items length.");
    7672                 :          0 :                 goto end;
    7673                 :            :         }
    7674                 :          0 :         len = RTE_ALIGN(ret, 16);
    7675                 :          0 :         flow_info->items = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
    7676         [ #  # ]:          0 :         if (!flow_info->items) {
    7677                 :          0 :                 DRV_LOG(ERR, "No enough memory for items caching.");
    7678                 :          0 :                 goto end;
    7679                 :            :         }
    7680                 :          0 :         ret = rte_flow_conv(RTE_FLOW_CONV_OP_PATTERN, flow_info->items, ret, items, &error);
    7681         [ #  # ]:          0 :         if (ret <= 0) {
    7682                 :          0 :                 DRV_LOG(ERR, "Can't duplicate items.");
    7683                 :          0 :                 goto end;
    7684                 :            :         }
    7685                 :            : 
    7686                 :            :         /* Store flow actions. */
    7687                 :          0 :         ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, actions, &error);
    7688         [ #  # ]:          0 :         if (ret <= 0) {
    7689                 :          0 :                 DRV_LOG(ERR, "Can't get actions length.");
    7690                 :          0 :                 goto end;
    7691                 :            :         }
    7692                 :          0 :         len = RTE_ALIGN(ret, 16);
    7693                 :          0 :         flow_info->actions = mlx5_malloc(MLX5_MEM_ZERO, len, 0, SOCKET_ID_ANY);
    7694         [ #  # ]:          0 :         if (!flow_info->actions) {
    7695                 :          0 :                 DRV_LOG(ERR, "No enough memory for actions caching.");
    7696                 :          0 :                 goto end;
    7697                 :            :         }
    7698                 :          0 :         ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, flow_info->actions, ret, actions, &error);
    7699         [ #  # ]:          0 :         if (ret <= 0) {
    7700                 :          0 :                 DRV_LOG(ERR, "Can't duplicate actions.");
    7701                 :          0 :                 goto end;
    7702                 :            :         }
    7703                 :            : 
    7704                 :            :         /* Insert to the list end. */
    7705         [ #  # ]:          0 :         if (LIST_EMPTY(&mode_info->hot_upgrade)) {
    7706                 :          0 :                 LIST_INSERT_HEAD(&mode_info->hot_upgrade, flow_info,  next);
    7707                 :            :         } else {
    7708                 :            :                 tmp_info = LIST_FIRST(&mode_info->hot_upgrade);
    7709         [ #  # ]:          0 :                 while (LIST_NEXT(tmp_info, next))
    7710                 :            :                         tmp_info = LIST_NEXT(tmp_info, next);
    7711                 :          0 :                 LIST_INSERT_AFTER(tmp_info, flow_info, next);
    7712                 :            :         }
    7713                 :            :         return 0;
    7714                 :          0 : end:
    7715         [ #  # ]:          0 :         if (flow_info->items)
    7716                 :          0 :                 mlx5_free(flow_info->items);
    7717         [ #  # ]:          0 :         if (flow_info->actions)
    7718                 :          0 :                 mlx5_free(flow_info->actions);
    7719                 :          0 :         mlx5_free(flow_info);
    7720                 :          0 :         return -1;
    7721                 :            : }
    7722                 :            : 
    7723                 :            : static int
    7724                 :          0 : mlx5_flow_cache_flow_toggle(struct rte_eth_dev *dev, bool orig_prio)
    7725                 :            : {
    7726                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7727                 :            :         struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
    7728                 :            :         struct mlx5_dv_flow_info *flow_info;
    7729                 :            :         struct rte_flow_attr attr;
    7730                 :            :         struct rte_flow_error error;
    7731                 :            :         struct rte_flow *high, *low;
    7732                 :            : 
    7733                 :          0 :         flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    7734         [ #  # ]:          0 :         while (flow_info) {
    7735                 :            :                 /* DUP flow may have the same priority. */
    7736         [ #  # ]:          0 :                 if (flow_info->orig_prio != flow_info->attr.priority) {
    7737                 :          0 :                         attr = flow_info->attr;
    7738         [ #  # ]:          0 :                         if (orig_prio)
    7739                 :          0 :                                 attr.priority = flow_info->orig_prio;
    7740                 :          0 :                         flow_info->flow_idx_high_prio = flow_list_create(dev, MLX5_FLOW_TYPE_GEN,
    7741                 :          0 :                                         &attr, flow_info->items, flow_info->actions,
    7742                 :            :                                         true, &error);
    7743         [ #  # ]:          0 :                         if (!flow_info->flow_idx_high_prio) {
    7744                 :          0 :                                 DRV_LOG(ERR, "Priority toggle failed internally.");
    7745                 :          0 :                                 goto err;
    7746                 :            :                         }
    7747                 :            :                 }
    7748                 :          0 :                 flow_info = LIST_NEXT(flow_info, next);
    7749                 :            :         }
    7750                 :            :         /* Delete the low priority rules and swap the flow handle. */
    7751                 :          0 :         flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    7752         [ #  # ]:          0 :         while (flow_info) {
    7753                 :            :                 MLX5_ASSERT(flow_info->flow_idx_low_prio);
    7754         [ #  # ]:          0 :                 if (flow_info->orig_prio != flow_info->attr.priority) {
    7755                 :          0 :                         high = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
    7756                 :            :                                         flow_info->flow_idx_high_prio);
    7757                 :          0 :                         low = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
    7758                 :            :                                         flow_info->flow_idx_low_prio);
    7759         [ #  # ]:          0 :                         if (high && low) {
    7760                 :          0 :                                 RTE_SWAP(*low, *high);
    7761                 :          0 :                                 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
    7762                 :            :                                                   flow_info->flow_idx_low_prio);
    7763                 :          0 :                                 flow_info->flow_idx_high_prio = 0;
    7764                 :            :                         }
    7765                 :            :                 }
    7766                 :          0 :                 flow_info = LIST_NEXT(flow_info, next);
    7767                 :            :         }
    7768                 :            :         return 0;
    7769                 :            : err:
    7770                 :            :         /* Destroy preceding successful high priority rules. */
    7771                 :          0 :         flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    7772         [ #  # ]:          0 :         while (flow_info) {
    7773         [ #  # ]:          0 :                 if (flow_info->orig_prio != flow_info->attr.priority) {
    7774         [ #  # ]:          0 :                         if (flow_info->flow_idx_high_prio)
    7775                 :          0 :                                 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
    7776                 :            :                                                   flow_info->flow_idx_high_prio);
    7777                 :            :                         else
    7778                 :            :                                 break;
    7779                 :          0 :                         flow_info->flow_idx_high_prio = 0;
    7780                 :            :                 }
    7781                 :          0 :                 flow_info = LIST_NEXT(flow_info, next);
    7782                 :            :         }
    7783                 :            :         return -1;
    7784                 :            : }
    7785                 :            : 
    7786                 :            : /**
    7787                 :            :  * Set the mode of the flow engine of a process to active or standby during live migration.
    7788                 :            :  *
    7789                 :            :  * @param[in] mode
    7790                 :            :  *   MLX5 flow engine mode, @see `enum rte_pmd_mlx5_flow_engine_mode`.
    7791                 :            :  * @param[in] flags
    7792                 :            :  *   Flow engine mode specific flags.
    7793                 :            :  *
    7794                 :            :  * @return
    7795                 :            :  *   Negative value on error, positive on success.
    7796                 :            :  */
    7797                 :            : int
    7798                 :          0 : rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags)
    7799                 :            : {
    7800                 :            :         struct mlx5_priv *priv;
    7801                 :            :         struct rte_pmd_mlx5_flow_engine_mode_info *mode_info;
    7802                 :            :         struct mlx5_dv_flow_info *flow_info, *tmp_info;
    7803                 :            :         uint16_t port, port_id;
    7804                 :            :         uint16_t toggle_num = 0;
    7805                 :            :         struct rte_eth_dev *dev;
    7806                 :            :         enum rte_pmd_mlx5_flow_engine_mode orig_mode;
    7807                 :            :         uint32_t orig_flags;
    7808                 :            :         bool need_toggle = false;
    7809                 :            : 
    7810                 :            :         /* Check if flags combinations are supported. */
    7811         [ #  # ]:          0 :         if (flags && flags != RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS) {
    7812                 :          0 :                 DRV_LOG(ERR, "Doesn't support such flags %u", flags);
    7813                 :          0 :                 return -1;
    7814                 :            :         }
    7815         [ #  # ]:          0 :         MLX5_ETH_FOREACH_DEV(port, NULL) {
    7816                 :          0 :                 dev = &rte_eth_devices[port];
    7817                 :          0 :                 priv = dev->data->dev_private;
    7818                 :            :                 mode_info = &priv->mode_info;
    7819                 :            :                 /* No mode change. Assume all devices hold the same mode. */
    7820         [ #  # ]:          0 :                 if (mode_info->mode == mode) {
    7821                 :          0 :                         DRV_LOG(INFO, "Process flow engine has been in mode %u", mode);
    7822   [ #  #  #  # ]:          0 :                         if (mode_info->mode_flag != flags && !LIST_EMPTY(&mode_info->hot_upgrade)) {
    7823                 :          0 :                                 DRV_LOG(ERR, "Port %u has rule cache with different flag %u\n",
    7824                 :            :                                                 port, mode_info->mode_flag);
    7825                 :          0 :                                 orig_mode = mode_info->mode;
    7826                 :          0 :                                 orig_flags = mode_info->mode_flag;
    7827                 :          0 :                                 goto err;
    7828                 :            :                         }
    7829                 :          0 :                         mode_info->mode_flag = flags;
    7830                 :          0 :                         toggle_num++;
    7831                 :          0 :                         continue;
    7832                 :            :                 }
    7833                 :            :                 /* Active -> standby. */
    7834         [ #  # ]:          0 :                 if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY) {
    7835         [ #  # ]:          0 :                         if (!LIST_EMPTY(&mode_info->hot_upgrade)) {
    7836                 :          0 :                                 DRV_LOG(ERR, "Cached rule existed");
    7837                 :          0 :                                 orig_mode = mode_info->mode;
    7838                 :          0 :                                 orig_flags = mode_info->mode_flag;
    7839                 :          0 :                                 goto err;
    7840                 :            :                         }
    7841                 :          0 :                         mode_info->mode_flag = flags;
    7842                 :          0 :                         mode_info->mode = mode;
    7843                 :          0 :                         toggle_num++;
    7844                 :            :                 /* Standby -> active. */
    7845         [ #  # ]:          0 :                 } else if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
    7846         [ #  # ]:          0 :                         if (LIST_EMPTY(&mode_info->hot_upgrade)) {
    7847                 :          0 :                                 DRV_LOG(INFO, "No cached rule existed");
    7848                 :            :                         } else {
    7849         [ #  # ]:          0 :                                 if (mlx5_flow_cache_flow_toggle(dev, true)) {
    7850                 :          0 :                                         orig_mode = mode_info->mode;
    7851                 :          0 :                                         orig_flags = mode_info->mode_flag;
    7852                 :            :                                         need_toggle = true;
    7853                 :          0 :                                         goto err;
    7854                 :            :                                 }
    7855                 :            :                         }
    7856                 :          0 :                         toggle_num++;
    7857                 :            :                 }
    7858                 :            :         }
    7859         [ #  # ]:          0 :         if (mode == RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE) {
    7860                 :            :                 /* Clear cache flow rules. */
    7861         [ #  # ]:          0 :                 MLX5_ETH_FOREACH_DEV(port, NULL) {
    7862                 :          0 :                         priv = rte_eth_devices[port].data->dev_private;
    7863                 :            :                         mode_info = &priv->mode_info;
    7864                 :          0 :                         flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    7865         [ #  # ]:          0 :                         while (flow_info) {
    7866                 :          0 :                                 tmp_info = LIST_NEXT(flow_info, next);
    7867         [ #  # ]:          0 :                                 LIST_REMOVE(flow_info, next);
    7868                 :          0 :                                 mlx5_free(flow_info->actions);
    7869                 :          0 :                                 mlx5_free(flow_info->items);
    7870                 :          0 :                                 mlx5_free(flow_info);
    7871                 :            :                                 flow_info = tmp_info;
    7872                 :            :                         }
    7873                 :            :                         MLX5_ASSERT(LIST_EMPTY(&mode_info->hot_upgrade));
    7874                 :            :                 }
    7875                 :            :         }
    7876                 :          0 :         return toggle_num;
    7877                 :          0 : err:
    7878                 :            :         /* Rollback all preceding successful ports. */
    7879         [ #  # ]:          0 :         MLX5_ETH_FOREACH_DEV(port_id, NULL) {
    7880         [ #  # ]:          0 :                 if (port_id == port)
    7881                 :            :                         break;
    7882                 :          0 :                 priv = rte_eth_devices[port_id].data->dev_private;
    7883                 :            :                 mode_info = &priv->mode_info;
    7884   [ #  #  #  #  :          0 :                 if (need_toggle && !LIST_EMPTY(&mode_info->hot_upgrade) &&
                   #  # ]
    7885                 :          0 :                     mlx5_flow_cache_flow_toggle(dev, false))
    7886                 :            :                         return -EPERM;
    7887                 :          0 :                 mode_info->mode = orig_mode;
    7888                 :          0 :                 mode_info->mode_flag = orig_flags;
    7889                 :            :         }
    7890                 :            :         return -EINVAL;
    7891                 :            : }
    7892                 :            : /**
    7893                 :            :  * Create a flow.
    7894                 :            :  *
    7895                 :            :  * @see rte_flow_create()
    7896                 :            :  * @see rte_flow_ops
    7897                 :            :  */
    7898                 :            : struct rte_flow *
    7899                 :          0 : mlx5_flow_create(struct rte_eth_dev *dev,
    7900                 :            :                  const struct rte_flow_attr *attr,
    7901                 :            :                  const struct rte_flow_item items[],
    7902                 :            :                  const struct rte_flow_action actions[],
    7903                 :            :                  struct rte_flow_error *error)
    7904                 :            : {
    7905                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7906                 :            :         struct rte_flow_attr *new_attr = (void *)(uintptr_t)attr;
    7907                 :          0 :         uint32_t prio = attr->priority;
    7908                 :            :         uint32_t flow_idx;
    7909                 :            : 
    7910         [ #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 2) {
    7911                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    7912                 :            :                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    7913                 :            :                           NULL,
    7914                 :            :                           "Flow non-Q creation not supported");
    7915                 :          0 :                 return NULL;
    7916                 :            :         }
    7917                 :            :         /*
    7918                 :            :          * If the device is not started yet, it is not allowed to created a
    7919                 :            :          * flow from application. PMD default flows and traffic control flows
    7920                 :            :          * are not affected.
    7921                 :            :          */
    7922         [ #  # ]:          0 :         if (unlikely(!dev->data->dev_started)) {
    7923                 :          0 :                 DRV_LOG(DEBUG, "port %u is not started when "
    7924                 :            :                         "inserting a flow", dev->data->port_id);
    7925                 :          0 :                 rte_flow_error_set(error, ENODEV,
    7926                 :            :                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    7927                 :            :                                    NULL,
    7928                 :            :                                    "port not started");
    7929                 :          0 :                 return NULL;
    7930                 :            :         }
    7931         [ #  # ]:          0 :         if (unlikely(mlx5_need_cache_flow(priv, attr))) {
    7932         [ #  # ]:          0 :                 if (attr->transfer ||
    7933   [ #  #  #  # ]:          0 :                                 (attr->ingress && !(priv->mode_info.mode_flag &
    7934                 :            :                                 RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS)))
    7935                 :          0 :                         new_attr->priority += 1;
    7936                 :            :         }
    7937                 :          0 :         flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, attr, items, actions, true, error);
    7938         [ #  # ]:          0 :         if (!flow_idx)
    7939                 :            :                 return NULL;
    7940         [ #  # ]:          0 :         if (unlikely(mlx5_need_cache_flow(priv, attr))) {
    7941         [ #  # ]:          0 :                 if (mlx5_flow_cache_flow_info(dev, attr, prio, items, actions, flow_idx)) {
    7942                 :          0 :                         flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
    7943                 :            :                         flow_idx = 0;
    7944                 :            :                 }
    7945                 :            :         }
    7946                 :          0 :         return (void *)(uintptr_t)flow_idx;
    7947                 :            : }
    7948                 :            : 
    7949                 :            : /**
    7950                 :            :  * Destroy a flow in a list.
    7951                 :            :  *
    7952                 :            :  * @param dev
    7953                 :            :  *   Pointer to Ethernet device.
    7954                 :            :  * @param[in] flow_idx
    7955                 :            :  *   Index of flow to destroy.
    7956                 :            :  */
    7957                 :            : static void
    7958                 :          0 : flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type,
    7959                 :            :                   uint32_t flow_idx)
    7960                 :            : {
    7961                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    7962                 :          0 :         struct rte_flow *flow = mlx5_ipool_get(priv->flows[type], flow_idx);
    7963                 :            : 
    7964         [ #  # ]:          0 :         if (!flow)
    7965                 :            :                 return;
    7966                 :            :         MLX5_ASSERT(flow->type == type);
    7967                 :            :         /*
    7968                 :            :          * Update RX queue flags only if port is started, otherwise it is
    7969                 :            :          * already clean.
    7970                 :            :          */
    7971         [ #  # ]:          0 :         if (dev->data->dev_started)
    7972                 :          0 :                 flow_rxq_flags_trim(dev, flow);
    7973                 :            :         flow_drv_destroy(dev, flow);
    7974         [ #  # ]:          0 :         if (flow->tunnel) {
    7975                 :            :                 struct mlx5_flow_tunnel *tunnel;
    7976                 :            : 
    7977                 :          0 :                 tunnel = mlx5_find_tunnel_id(dev, flow->tunnel_id);
    7978                 :          0 :                 RTE_VERIFY(tunnel);
    7979         [ #  # ]:          0 :                 if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
    7980                 :          0 :                         mlx5_flow_tunnel_free(dev, tunnel);
    7981                 :            :         }
    7982                 :          0 :         flow_mreg_del_copy_action(dev, flow);
    7983                 :          0 :         mlx5_ipool_free(priv->flows[type], flow_idx);
    7984                 :            : }
    7985                 :            : 
    7986                 :            : /**
    7987                 :            :  * Destroy all flows.
    7988                 :            :  *
    7989                 :            :  * @param dev
    7990                 :            :  *   Pointer to Ethernet device.
    7991                 :            :  * @param type
    7992                 :            :  *   Flow type to be flushed.
    7993                 :            :  * @param active
    7994                 :            :  *   If flushing is called actively.
    7995                 :            :  */
    7996                 :            : void
    7997                 :          0 : mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
    7998                 :            :                      bool active)
    7999                 :            : {
    8000                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8001                 :          0 :         uint32_t num_flushed = 0, fidx = 1;
    8002                 :            :         struct rte_flow *flow;
    8003                 :            :         struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
    8004                 :            :         struct mlx5_dv_flow_info *flow_info;
    8005                 :            : 
    8006                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    8007   [ #  #  #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 2 &&
    8008                 :            :             type == MLX5_FLOW_TYPE_GEN) {
    8009                 :          0 :                 flow_hw_q_flow_flush(dev, NULL);
    8010                 :          0 :                 return;
    8011                 :            :         }
    8012                 :            : #endif
    8013                 :            : 
    8014         [ #  # ]:          0 :         MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) {
    8015                 :          0 :                 flow_list_destroy(dev, type, fidx);
    8016   [ #  #  #  # ]:          0 :                 if (unlikely(mlx5_need_cache_flow(priv, NULL) && type == MLX5_FLOW_TYPE_GEN)) {
    8017                 :          0 :                         flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    8018         [ #  # ]:          0 :                         while (flow_info) {
    8019                 :            :                                 /* Romove the cache flow info. */
    8020         [ #  # ]:          0 :                                 if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)fidx) {
    8021                 :            :                                         MLX5_ASSERT(!flow_info->flow_idx_high_prio);
    8022         [ #  # ]:          0 :                                         LIST_REMOVE(flow_info, next);
    8023                 :          0 :                                         mlx5_free(flow_info->items);
    8024                 :          0 :                                         mlx5_free(flow_info->actions);
    8025                 :          0 :                                         mlx5_free(flow_info);
    8026                 :          0 :                                         break;
    8027                 :            :                                 }
    8028                 :          0 :                                 flow_info = LIST_NEXT(flow_info, next);
    8029                 :            :                         }
    8030                 :            :                 }
    8031                 :          0 :                 num_flushed++;
    8032                 :            :         }
    8033         [ #  # ]:          0 :         if (active) {
    8034                 :          0 :                 DRV_LOG(INFO, "port %u: %u flows flushed before stopping",
    8035                 :            :                         dev->data->port_id, num_flushed);
    8036                 :            :         }
    8037                 :            : }
    8038                 :            : 
    8039                 :            : /**
    8040                 :            :  * Stop all default actions for flows.
    8041                 :            :  *
    8042                 :            :  * @param dev
    8043                 :            :  *   Pointer to Ethernet device.
    8044                 :            :  */
    8045                 :            : void
    8046                 :          0 : mlx5_flow_stop_default(struct rte_eth_dev *dev)
    8047                 :            : {
    8048                 :          0 :         flow_mreg_del_default_copy_action(dev);
    8049                 :          0 :         flow_rxq_flags_clear(dev);
    8050                 :          0 : }
    8051                 :            : 
    8052                 :            : /**
    8053                 :            :  * Set rxq flag.
    8054                 :            :  *
    8055                 :            :  * @param[in] dev
    8056                 :            :  *   Pointer to the rte_eth_dev structure.
    8057                 :            :  * @param[in] enable
    8058                 :            :  *   Flag to enable or not.
    8059                 :            :  */
    8060                 :            : void
    8061                 :          0 : flow_hw_rxq_flag_set(struct rte_eth_dev *dev, bool enable)
    8062                 :            : {
    8063                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8064                 :            :         unsigned int i;
    8065                 :            : 
    8066   [ #  #  #  #  :          0 :         if ((!priv->mark_enabled && !enable) ||
                   #  # ]
    8067         [ #  # ]:          0 :             (priv->mark_enabled && enable))
    8068                 :            :                 return;
    8069         [ #  # ]:          0 :         for (i = 0; i < priv->rxqs_n; ++i) {
    8070                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
    8071                 :            : 
    8072                 :            :                 /* With RXQ start/stop feature, RXQ might be stopped. */
    8073         [ #  # ]:          0 :                 if (!rxq_ctrl)
    8074                 :          0 :                         continue;
    8075                 :          0 :                 rxq_ctrl->rxq.mark = enable;
    8076                 :            :         }
    8077                 :          0 :         priv->mark_enabled = enable;
    8078                 :            : }
    8079                 :            : 
    8080                 :            : /**
    8081                 :            :  * Start all default actions for flows.
    8082                 :            :  *
    8083                 :            :  * @param dev
    8084                 :            :  *   Pointer to Ethernet device.
    8085                 :            :  * @return
    8086                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8087                 :            :  */
    8088                 :            : int
    8089                 :          0 : mlx5_flow_start_default(struct rte_eth_dev *dev)
    8090                 :            : {
    8091                 :            :         struct rte_flow_error error;
    8092                 :            : 
    8093                 :            :         /* Make sure default copy action (reg_c[0] -> reg_b) is created. */
    8094                 :          0 :         return flow_mreg_add_default_copy_action(dev, &error);
    8095                 :            : }
    8096                 :            : 
    8097                 :            : /**
    8098                 :            :  * Release key of thread specific flow workspace data.
    8099                 :            :  */
    8100                 :            : void
    8101                 :          0 : flow_release_workspace(void *data)
    8102                 :            : {
    8103                 :            :         struct mlx5_flow_workspace *wks = data;
    8104                 :            :         struct mlx5_flow_workspace *next;
    8105                 :            : 
    8106         [ #  # ]:          0 :         while (wks) {
    8107                 :          0 :                 next = wks->next;
    8108                 :          0 :                 free(wks);
    8109                 :            :                 wks = next;
    8110                 :            :         }
    8111                 :          0 : }
    8112                 :            : 
    8113                 :            : /**
    8114                 :            :  * Get thread specific current flow workspace.
    8115                 :            :  *
    8116                 :            :  * @return pointer to thread specific flow workspace data, NULL on error.
    8117                 :            :  */
    8118                 :            : struct mlx5_flow_workspace*
    8119                 :          0 : mlx5_flow_get_thread_workspace(void)
    8120                 :            : {
    8121                 :            :         struct mlx5_flow_workspace *data;
    8122                 :            : 
    8123                 :          0 :         data = mlx5_flow_os_get_specific_workspace();
    8124                 :            :         MLX5_ASSERT(data && data->inuse);
    8125   [ #  #  #  # ]:          0 :         if (!data || !data->inuse)
    8126                 :          0 :                 DRV_LOG(ERR, "flow workspace not initialized.");
    8127                 :          0 :         return data;
    8128                 :            : }
    8129                 :            : 
    8130                 :            : /**
    8131                 :            :  * Allocate and init new flow workspace.
    8132                 :            :  *
    8133                 :            :  * @return pointer to flow workspace data, NULL on error.
    8134                 :            :  */
    8135                 :            : static struct mlx5_flow_workspace*
    8136                 :          0 : flow_alloc_thread_workspace(void)
    8137                 :            : {
    8138                 :            :         size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long));
    8139                 :            :         size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512;
    8140                 :          0 :         struct mlx5_flow_workspace *data = calloc(1, data_size +
    8141                 :            :                                                      rss_queue_array_size);
    8142                 :            : 
    8143         [ #  # ]:          0 :         if (!data) {
    8144                 :          0 :                 DRV_LOG(ERR, "Failed to allocate flow workspace memory.");
    8145                 :          0 :                 return NULL;
    8146                 :            :         }
    8147                 :          0 :         data->rss_desc.queue = RTE_PTR_ADD(data, data_size);
    8148                 :          0 :         return data;
    8149                 :            : }
    8150                 :            : 
    8151                 :            : /**
    8152                 :            :  * Get new thread specific flow workspace.
    8153                 :            :  *
    8154                 :            :  * If current workspace inuse, create new one and set as current.
    8155                 :            :  *
    8156                 :            :  * @return pointer to thread specific flow workspace data, NULL on error.
    8157                 :            :  */
    8158                 :            : struct mlx5_flow_workspace*
    8159                 :          0 : mlx5_flow_push_thread_workspace(void)
    8160                 :            : {
    8161                 :            :         struct mlx5_flow_workspace *curr;
    8162                 :            :         struct mlx5_flow_workspace *data;
    8163                 :            : 
    8164                 :          0 :         curr = mlx5_flow_os_get_specific_workspace();
    8165         [ #  # ]:          0 :         if (!curr) {
    8166                 :          0 :                 data = flow_alloc_thread_workspace();
    8167         [ #  # ]:          0 :                 if (!data)
    8168                 :            :                         return NULL;
    8169                 :          0 :                 mlx5_flow_os_workspace_gc_add(data);
    8170         [ #  # ]:          0 :         } else if (!curr->inuse) {
    8171                 :            :                 data = curr;
    8172         [ #  # ]:          0 :         } else if (curr->next) {
    8173                 :            :                 data = curr->next;
    8174                 :            :         } else {
    8175                 :          0 :                 data = flow_alloc_thread_workspace();
    8176         [ #  # ]:          0 :                 if (!data)
    8177                 :            :                         return NULL;
    8178                 :          0 :                 curr->next = data;
    8179                 :          0 :                 data->prev = curr;
    8180                 :            :         }
    8181                 :          0 :         data->inuse = 1;
    8182                 :          0 :         data->flow_idx = 0;
    8183                 :            :         /* Set as current workspace */
    8184         [ #  # ]:          0 :         if (mlx5_flow_os_set_specific_workspace(data))
    8185                 :          0 :                 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
    8186                 :            :         return data;
    8187                 :            : }
    8188                 :            : 
    8189                 :            : /**
    8190                 :            :  * Close current thread specific flow workspace.
    8191                 :            :  *
    8192                 :            :  * If previous workspace available, set it as current.
    8193                 :            :  *
    8194                 :            :  * @return pointer to thread specific flow workspace data, NULL on error.
    8195                 :            :  */
    8196                 :            : void
    8197                 :          0 : mlx5_flow_pop_thread_workspace(void)
    8198                 :            : {
    8199                 :          0 :         struct mlx5_flow_workspace *data = mlx5_flow_get_thread_workspace();
    8200                 :            : 
    8201         [ #  # ]:          0 :         if (!data)
    8202                 :            :                 return;
    8203         [ #  # ]:          0 :         if (!data->inuse) {
    8204                 :          0 :                 DRV_LOG(ERR, "Failed to close unused flow workspace.");
    8205                 :          0 :                 return;
    8206                 :            :         }
    8207                 :          0 :         data->inuse = 0;
    8208         [ #  # ]:          0 :         if (!data->prev)
    8209                 :            :                 return;
    8210         [ #  # ]:          0 :         if (mlx5_flow_os_set_specific_workspace(data->prev))
    8211                 :          0 :                 DRV_LOG(ERR, "Failed to set flow workspace to thread.");
    8212                 :            : }
    8213                 :            : 
    8214                 :            : /**
    8215                 :            :  * Verify the flow list is empty
    8216                 :            :  *
    8217                 :            :  * @param dev
    8218                 :            :  *  Pointer to Ethernet device.
    8219                 :            :  *
    8220                 :            :  * @return the number of flows not released.
    8221                 :            :  */
    8222                 :            : int
    8223                 :          0 : mlx5_flow_verify(struct rte_eth_dev *dev __rte_unused)
    8224                 :            : {
    8225                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8226                 :            :         struct rte_flow *flow;
    8227                 :            :         uint32_t idx = 0;
    8228                 :            :         int ret = 0, i;
    8229                 :            : 
    8230         [ #  # ]:          0 :         for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
    8231         [ #  # ]:          0 :                 MLX5_IPOOL_FOREACH(priv->flows[i], idx, flow) {
    8232                 :          0 :                         DRV_LOG(DEBUG, "port %u flow %p still referenced",
    8233                 :            :                                 dev->data->port_id, (void *)flow);
    8234                 :          0 :                         ret++;
    8235                 :            :                 }
    8236                 :            :         }
    8237                 :          0 :         return ret;
    8238                 :            : }
    8239                 :            : 
    8240                 :            : /**
    8241                 :            :  * Enable default hairpin egress flow.
    8242                 :            :  *
    8243                 :            :  * @param dev
    8244                 :            :  *   Pointer to Ethernet device.
    8245                 :            :  * @param sq_num
    8246                 :            :  *   The SQ hw number.
    8247                 :            :  *
    8248                 :            :  * @return
    8249                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8250                 :            :  */
    8251                 :            : int
    8252                 :          0 : mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev,
    8253                 :            :                             uint32_t sq_num)
    8254                 :            : {
    8255                 :          0 :         const struct rte_flow_attr attr = {
    8256                 :            :                 .egress = 1,
    8257                 :            :                 .priority = 0,
    8258                 :            :         };
    8259                 :          0 :         struct mlx5_rte_flow_item_sq queue_spec = {
    8260                 :            :                 .queue = sq_num,
    8261                 :            :         };
    8262                 :          0 :         struct mlx5_rte_flow_item_sq queue_mask = {
    8263                 :            :                 .queue = UINT32_MAX,
    8264                 :            :         };
    8265                 :          0 :         struct rte_flow_item items[] = {
    8266                 :            :                 {
    8267                 :            :                         .type = (enum rte_flow_item_type)
    8268                 :            :                                 MLX5_RTE_FLOW_ITEM_TYPE_SQ,
    8269                 :            :                         .spec = &queue_spec,
    8270                 :            :                         .last = NULL,
    8271                 :            :                         .mask = &queue_mask,
    8272                 :            :                 },
    8273                 :            :                 {
    8274                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    8275                 :            :                 },
    8276                 :            :         };
    8277                 :          0 :         struct rte_flow_action_jump jump = {
    8278                 :            :                 .group = MLX5_HAIRPIN_TX_TABLE,
    8279                 :            :         };
    8280                 :            :         struct rte_flow_action actions[2];
    8281                 :            :         uint32_t flow_idx;
    8282                 :            :         struct rte_flow_error error;
    8283                 :            : 
    8284                 :          0 :         actions[0].type = RTE_FLOW_ACTION_TYPE_JUMP;
    8285                 :          0 :         actions[0].conf = &jump;
    8286                 :          0 :         actions[1].type = RTE_FLOW_ACTION_TYPE_END;
    8287                 :          0 :         flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
    8288                 :            :                                     &attr, items, actions, false, &error);
    8289         [ #  # ]:          0 :         if (!flow_idx) {
    8290         [ #  # ]:          0 :                 DRV_LOG(DEBUG,
    8291                 :            :                         "Failed to create ctrl flow: rte_errno(%d),"
    8292                 :            :                         " type(%d), message(%s)",
    8293                 :            :                         rte_errno, error.type,
    8294                 :            :                         error.message ? error.message : " (no stated reason)");
    8295                 :          0 :                 return -rte_errno;
    8296                 :            :         }
    8297                 :            :         return 0;
    8298                 :            : }
    8299                 :            : 
    8300                 :            : /**
    8301                 :            :  * Enable a control flow configured from the control plane.
    8302                 :            :  *
    8303                 :            :  * @param dev
    8304                 :            :  *   Pointer to Ethernet device.
    8305                 :            :  * @param eth_spec
    8306                 :            :  *   An Ethernet flow spec to apply.
    8307                 :            :  * @param eth_mask
    8308                 :            :  *   An Ethernet flow mask to apply.
    8309                 :            :  * @param vlan_spec
    8310                 :            :  *   A VLAN flow spec to apply.
    8311                 :            :  * @param vlan_mask
    8312                 :            :  *   A VLAN flow mask to apply.
    8313                 :            :  *
    8314                 :            :  * @return
    8315                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8316                 :            :  */
    8317                 :            : int
    8318                 :          0 : mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
    8319                 :            :                     struct rte_flow_item_eth *eth_spec,
    8320                 :            :                     struct rte_flow_item_eth *eth_mask,
    8321                 :            :                     struct rte_flow_item_vlan *vlan_spec,
    8322                 :            :                     struct rte_flow_item_vlan *vlan_mask)
    8323                 :          0 : {
    8324                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8325                 :          0 :         const struct rte_flow_attr attr = {
    8326                 :            :                 .ingress = 1,
    8327                 :            :                 .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
    8328                 :            :         };
    8329                 :          0 :         struct rte_flow_item items[] = {
    8330                 :            :                 {
    8331                 :            :                         .type = RTE_FLOW_ITEM_TYPE_ETH,
    8332                 :            :                         .spec = eth_spec,
    8333                 :            :                         .last = NULL,
    8334                 :            :                         .mask = eth_mask,
    8335                 :            :                 },
    8336                 :            :                 {
    8337         [ #  # ]:          0 :                         .type = (vlan_spec) ? RTE_FLOW_ITEM_TYPE_VLAN :
    8338                 :            :                                               RTE_FLOW_ITEM_TYPE_END,
    8339                 :            :                         .spec = vlan_spec,
    8340                 :            :                         .last = NULL,
    8341                 :            :                         .mask = vlan_mask,
    8342                 :            :                 },
    8343                 :            :                 {
    8344                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    8345                 :            :                 },
    8346                 :            :         };
    8347                 :          0 :         uint16_t queue[priv->reta_idx_n];
    8348                 :          0 :         struct rte_flow_action_rss action_rss = {
    8349                 :            :                 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
    8350                 :            :                 .level = 0,
    8351                 :          0 :                 .types = priv->rss_conf.rss_hf,
    8352                 :          0 :                 .key_len = priv->rss_conf.rss_key_len,
    8353                 :            :                 .queue_num = priv->reta_idx_n,
    8354                 :          0 :                 .key = priv->rss_conf.rss_key,
    8355                 :            :                 .queue = queue,
    8356                 :            :         };
    8357                 :          0 :         struct rte_flow_action actions[] = {
    8358                 :            :                 {
    8359                 :            :                         .type = RTE_FLOW_ACTION_TYPE_RSS,
    8360                 :            :                         .conf = &action_rss,
    8361                 :            :                 },
    8362                 :            :                 {
    8363                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    8364                 :            :                 },
    8365                 :            :         };
    8366                 :            :         uint32_t flow_idx;
    8367                 :            :         struct rte_flow_error error;
    8368                 :            :         unsigned int i;
    8369                 :            : 
    8370   [ #  #  #  # ]:          0 :         if (!priv->reta_idx_n || !priv->rxqs_n) {
    8371                 :            :                 return 0;
    8372                 :            :         }
    8373         [ #  # ]:          0 :         if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
    8374                 :          0 :                 action_rss.types = 0;
    8375         [ #  # ]:          0 :         for (i = 0; i != priv->reta_idx_n; ++i)
    8376                 :          0 :                 queue[i] = (*priv->reta_idx)[i];
    8377                 :          0 :         flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
    8378                 :            :                                     &attr, items, actions, false, &error);
    8379         [ #  # ]:          0 :         if (!flow_idx)
    8380                 :          0 :                 return -rte_errno;
    8381                 :            :         return 0;
    8382                 :            : }
    8383                 :            : 
    8384                 :            : /**
    8385                 :            :  * Enable a flow control configured from the control plane.
    8386                 :            :  *
    8387                 :            :  * @param dev
    8388                 :            :  *   Pointer to Ethernet device.
    8389                 :            :  * @param eth_spec
    8390                 :            :  *   An Ethernet flow spec to apply.
    8391                 :            :  * @param eth_mask
    8392                 :            :  *   An Ethernet flow mask to apply.
    8393                 :            :  *
    8394                 :            :  * @return
    8395                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8396                 :            :  */
    8397                 :            : int
    8398                 :          0 : mlx5_ctrl_flow(struct rte_eth_dev *dev,
    8399                 :            :                struct rte_flow_item_eth *eth_spec,
    8400                 :            :                struct rte_flow_item_eth *eth_mask)
    8401                 :            : {
    8402                 :          0 :         return mlx5_ctrl_flow_vlan(dev, eth_spec, eth_mask, NULL, NULL);
    8403                 :            : }
    8404                 :            : 
    8405                 :            : /**
    8406                 :            :  * Create default miss flow rule matching lacp traffic
    8407                 :            :  *
    8408                 :            :  * @param dev
    8409                 :            :  *   Pointer to Ethernet device.
    8410                 :            :  * @param eth_spec
    8411                 :            :  *   An Ethernet flow spec to apply.
    8412                 :            :  *
    8413                 :            :  * @return
    8414                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8415                 :            :  */
    8416                 :            : int
    8417                 :          0 : mlx5_flow_lacp_miss(struct rte_eth_dev *dev)
    8418                 :            : {
    8419                 :            :         /*
    8420                 :            :          * The LACP matching is done by only using ether type since using
    8421                 :            :          * a multicast dst mac causes kernel to give low priority to this flow.
    8422                 :            :          */
    8423                 :            :         static const struct rte_flow_item_eth lacp_spec = {
    8424                 :            :                 .hdr.ether_type = RTE_BE16(0x8809),
    8425                 :            :         };
    8426                 :            :         static const struct rte_flow_item_eth lacp_mask = {
    8427                 :            :                 .hdr.ether_type = 0xffff,
    8428                 :            :         };
    8429                 :          0 :         const struct rte_flow_attr attr = {
    8430                 :            :                 .ingress = 1,
    8431                 :            :         };
    8432                 :          0 :         struct rte_flow_item items[] = {
    8433                 :            :                 {
    8434                 :            :                         .type = RTE_FLOW_ITEM_TYPE_ETH,
    8435                 :            :                         .spec = &lacp_spec,
    8436                 :            :                         .mask = &lacp_mask,
    8437                 :            :                 },
    8438                 :            :                 {
    8439                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
    8440                 :            :                 },
    8441                 :            :         };
    8442                 :          0 :         struct rte_flow_action actions[] = {
    8443                 :            :                 {
    8444                 :            :                         .type = (enum rte_flow_action_type)
    8445                 :            :                                 MLX5_RTE_FLOW_ACTION_TYPE_DEFAULT_MISS,
    8446                 :            :                 },
    8447                 :            :                 {
    8448                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END,
    8449                 :            :                 },
    8450                 :            :         };
    8451                 :            :         struct rte_flow_error error;
    8452                 :          0 :         uint32_t flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_CTL,
    8453                 :            :                                         &attr, items, actions,
    8454                 :            :                                         false, &error);
    8455                 :            : 
    8456         [ #  # ]:          0 :         if (!flow_idx)
    8457                 :          0 :                 return -rte_errno;
    8458                 :            :         return 0;
    8459                 :            : }
    8460                 :            : 
    8461                 :            : /**
    8462                 :            :  * Destroy a flow.
    8463                 :            :  *
    8464                 :            :  * @see rte_flow_destroy()
    8465                 :            :  * @see rte_flow_ops
    8466                 :            :  */
    8467                 :            : int
    8468                 :          0 : mlx5_flow_destroy(struct rte_eth_dev *dev,
    8469                 :            :                   struct rte_flow *flow,
    8470                 :            :                   struct rte_flow_error *error __rte_unused)
    8471                 :            : {
    8472                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8473                 :            :         struct rte_pmd_mlx5_flow_engine_mode_info *mode_info = &priv->mode_info;
    8474                 :            :         struct mlx5_dv_flow_info *flow_info;
    8475                 :            : 
    8476         [ #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 2)
    8477                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    8478                 :            :                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    8479                 :            :                           NULL,
    8480                 :            :                           "Flow non-Q destruction not supported");
    8481                 :          0 :         flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN,
    8482                 :            :                                 (uintptr_t)(void *)flow);
    8483         [ #  # ]:          0 :         if (unlikely(mlx5_need_cache_flow(priv, NULL))) {
    8484                 :          0 :                 flow_info = LIST_FIRST(&mode_info->hot_upgrade);
    8485         [ #  # ]:          0 :                 while (flow_info) {
    8486                 :            :                         /* Romove the cache flow info. */
    8487         [ #  # ]:          0 :                         if (flow_info->flow_idx_low_prio == (uint32_t)(uintptr_t)flow) {
    8488                 :            :                                 MLX5_ASSERT(!flow_info->flow_idx_high_prio);
    8489         [ #  # ]:          0 :                                 LIST_REMOVE(flow_info, next);
    8490                 :          0 :                                 mlx5_free(flow_info->items);
    8491                 :          0 :                                 mlx5_free(flow_info->actions);
    8492                 :          0 :                                 mlx5_free(flow_info);
    8493                 :          0 :                                 break;
    8494                 :            :                         }
    8495                 :          0 :                         flow_info = LIST_NEXT(flow_info, next);
    8496                 :            :                 }
    8497                 :            :         }
    8498                 :            :         return 0;
    8499                 :            : }
    8500                 :            : 
    8501                 :            : /**
    8502                 :            :  * Destroy all flows.
    8503                 :            :  *
    8504                 :            :  * @see rte_flow_flush()
    8505                 :            :  * @see rte_flow_ops
    8506                 :            :  */
    8507                 :            : int
    8508                 :          0 : mlx5_flow_flush(struct rte_eth_dev *dev,
    8509                 :            :                 struct rte_flow_error *error __rte_unused)
    8510                 :            : {
    8511                 :          0 :         mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, false);
    8512                 :          0 :         return 0;
    8513                 :            : }
    8514                 :            : 
    8515                 :            : /**
    8516                 :            :  * Isolated mode.
    8517                 :            :  *
    8518                 :            :  * @see rte_flow_isolate()
    8519                 :            :  * @see rte_flow_ops
    8520                 :            :  */
    8521                 :            : int
    8522                 :          0 : mlx5_flow_isolate(struct rte_eth_dev *dev,
    8523                 :            :                   int enable,
    8524                 :            :                   struct rte_flow_error *error)
    8525                 :            : {
    8526                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8527                 :            : 
    8528         [ #  # ]:          0 :         if (dev->data->dev_started) {
    8529                 :          0 :                 rte_flow_error_set(error, EBUSY,
    8530                 :            :                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    8531                 :            :                                    NULL,
    8532                 :            :                                    "port must be stopped first");
    8533                 :          0 :                 return -rte_errno;
    8534                 :            :         }
    8535   [ #  #  #  # ]:          0 :         if (!enable && !priv->sh->config.repr_matching)
    8536                 :          0 :                 return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    8537                 :            :                                           "isolated mode cannot be disabled when "
    8538                 :            :                                           "representor matching is disabled");
    8539                 :          0 :         priv->isolated = !!enable;
    8540         [ #  # ]:          0 :         if (enable)
    8541                 :          0 :                 dev->dev_ops = &mlx5_dev_ops_isolate;
    8542                 :            :         else
    8543                 :          0 :                 dev->dev_ops = &mlx5_dev_ops;
    8544                 :            : 
    8545                 :          0 :         dev->rx_descriptor_status = mlx5_rx_descriptor_status;
    8546                 :          0 :         dev->tx_descriptor_status = mlx5_tx_descriptor_status;
    8547                 :            : 
    8548                 :          0 :         return 0;
    8549                 :            : }
    8550                 :            : 
    8551                 :            : /**
    8552                 :            :  * Query a flow.
    8553                 :            :  *
    8554                 :            :  * @see rte_flow_query()
    8555                 :            :  * @see rte_flow_ops
    8556                 :            :  */
    8557                 :            : static int
    8558                 :          0 : flow_drv_query(struct rte_eth_dev *dev,
    8559                 :            :                struct rte_flow *eflow,
    8560                 :            :                const struct rte_flow_action *actions,
    8561                 :            :                void *data,
    8562                 :            :                struct rte_flow_error *error)
    8563                 :            : {
    8564                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    8565                 :            :         const struct mlx5_flow_driver_ops *fops;
    8566                 :            :         struct rte_flow *flow = NULL;
    8567                 :            :         enum mlx5_flow_drv_type ftype = MLX5_FLOW_TYPE_MIN;
    8568                 :            : 
    8569         [ #  # ]:          0 :         if (priv->sh->config.dv_flow_en == 2) {
    8570                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
    8571                 :            :                 flow = eflow;
    8572                 :            :                 ftype = MLX5_FLOW_TYPE_HW;
    8573                 :            : #endif
    8574                 :            :         } else {
    8575                 :          0 :                 flow = (struct rte_flow *)mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
    8576                 :            :                                 (uintptr_t)(void *)eflow);
    8577                 :            :         }
    8578         [ #  # ]:          0 :         if (!flow) {
    8579                 :          0 :                 return rte_flow_error_set(error, ENOENT,
    8580                 :            :                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    8581                 :            :                           NULL,
    8582                 :            :                           "invalid flow handle");
    8583                 :            :         }
    8584         [ #  # ]:          0 :         if (ftype == MLX5_FLOW_TYPE_MIN)
    8585                 :          0 :                 ftype = flow->drv_type;
    8586                 :            :         MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN && ftype < MLX5_FLOW_TYPE_MAX);
    8587                 :          0 :         fops = flow_get_drv_ops(ftype);
    8588                 :            : 
    8589                 :          0 :         return fops->query(dev, flow, actions, data, error);
    8590                 :            : }
    8591                 :            : 
    8592                 :            : /**
    8593                 :            :  * Query a flow.
    8594                 :            :  *
    8595                 :            :  * @see rte_flow_query()
    8596                 :            :  * @see rte_flow_ops
    8597                 :            :  */
    8598                 :            : int
    8599                 :          0 : mlx5_flow_query(struct rte_eth_dev *dev,
    8600                 :            :                 struct rte_flow *flow,
    8601                 :            :                 const struct rte_flow_action *actions,
    8602                 :            :                 void *data,
    8603                 :            :                 struct rte_flow_error *error)
    8604                 :            : {
    8605                 :            :         int ret;
    8606                 :            : 
    8607                 :          0 :         ret = flow_drv_query(dev, flow, actions, data,
    8608                 :            :                              error);
    8609                 :            :         if (ret < 0)
    8610                 :            :                 return ret;
    8611                 :            :         return 0;
    8612                 :            : }
    8613                 :            : 
    8614                 :            : /**
    8615                 :            :  * Get rte_flow callbacks.
    8616                 :            :  *
    8617                 :            :  * @param dev
    8618                 :            :  *   Pointer to Ethernet device structure.
    8619                 :            :  * @param ops
    8620                 :            :  *   Pointer to operation-specific structure.
    8621                 :            :  *
    8622                 :            :  * @return 0
    8623                 :            :  */
    8624                 :            : int
    8625                 :          0 : mlx5_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
    8626                 :            :                   const struct rte_flow_ops **ops)
    8627                 :            : {
    8628                 :          0 :         *ops = &mlx5_flow_ops;
    8629                 :          0 :         return 0;
    8630                 :            : }
    8631                 :            : 
    8632                 :            : /**
    8633                 :            :  * Validate meter policy actions.
    8634                 :            :  * Dispatcher for action type specific validation.
    8635                 :            :  *
    8636                 :            :  * @param[in] dev
    8637                 :            :  *   Pointer to the Ethernet device structure.
    8638                 :            :  * @param[in] action
    8639                 :            :  *   The meter policy action object to validate.
    8640                 :            :  * @param[in] attr
    8641                 :            :  *   Attributes of flow to determine steering domain.
    8642                 :            :  * @param[out] is_rss
    8643                 :            :  *   Is RSS or not.
    8644                 :            :  * @param[out] domain_bitmap
    8645                 :            :  *   Domain bitmap.
    8646                 :            :  * @param[out] is_def_policy
    8647                 :            :  *   Is default policy or not.
    8648                 :            :  * @param[out] error
    8649                 :            :  *   Perform verbose error reporting if not NULL. Initialized in case of
    8650                 :            :  *   error only.
    8651                 :            :  *
    8652                 :            :  * @return
    8653                 :            :  *   0 on success, otherwise negative errno value.
    8654                 :            :  */
    8655                 :            : int
    8656                 :          0 : mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,
    8657                 :            :                         const struct rte_flow_action *actions[RTE_COLORS],
    8658                 :            :                         struct rte_flow_attr *attr,
    8659                 :            :                         bool *is_rss,
    8660                 :            :                         uint8_t *domain_bitmap,
    8661                 :            :                         uint8_t *policy_mode,
    8662                 :            :                         struct rte_mtr_error *error)
    8663                 :            : {
    8664                 :            :         const struct mlx5_flow_driver_ops *fops;
    8665                 :            : 
    8666                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8667                 :          0 :         return fops->validate_mtr_acts(dev, actions, attr, is_rss,
    8668                 :            :                                        domain_bitmap, policy_mode, error);
    8669                 :            : }
    8670                 :            : 
    8671                 :            : /**
    8672                 :            :  * Destroy the meter table set.
    8673                 :            :  *
    8674                 :            :  * @param[in] dev
    8675                 :            :  *   Pointer to Ethernet device.
    8676                 :            :  * @param[in] mtr_policy
    8677                 :            :  *   Meter policy struct.
    8678                 :            :  */
    8679                 :            : void
    8680                 :          0 : mlx5_flow_destroy_mtr_acts(struct rte_eth_dev *dev,
    8681                 :            :                       struct mlx5_flow_meter_policy *mtr_policy)
    8682                 :            : {
    8683                 :            :         const struct mlx5_flow_driver_ops *fops;
    8684                 :            : 
    8685                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8686                 :          0 :         fops->destroy_mtr_acts(dev, mtr_policy);
    8687                 :          0 : }
    8688                 :            : 
    8689                 :            : /**
    8690                 :            :  * Create policy action, lock free,
    8691                 :            :  * (mutex should be acquired by caller).
    8692                 :            :  * Dispatcher for action type specific call.
    8693                 :            :  *
    8694                 :            :  * @param[in] dev
    8695                 :            :  *   Pointer to the Ethernet device structure.
    8696                 :            :  * @param[in] mtr_policy
    8697                 :            :  *   Meter policy struct.
    8698                 :            :  * @param[in] action
    8699                 :            :  *   Action specification used to create meter actions.
    8700                 :            :  * @param[in] attr
    8701                 :            :  *   Flow rule attributes.
    8702                 :            :  * @param[out] error
    8703                 :            :  *   Perform verbose error reporting if not NULL. Initialized in case of
    8704                 :            :  *   error only.
    8705                 :            :  *
    8706                 :            :  * @return
    8707                 :            :  *   0 on success, otherwise negative errno value.
    8708                 :            :  */
    8709                 :            : int
    8710                 :          0 : mlx5_flow_create_mtr_acts(struct rte_eth_dev *dev,
    8711                 :            :                       struct mlx5_flow_meter_policy *mtr_policy,
    8712                 :            :                       const struct rte_flow_action *actions[RTE_COLORS],
    8713                 :            :                       struct rte_flow_attr *attr,
    8714                 :            :                       struct rte_mtr_error *error)
    8715                 :            : {
    8716                 :            :         const struct mlx5_flow_driver_ops *fops;
    8717                 :            : 
    8718                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8719                 :          0 :         return fops->create_mtr_acts(dev, mtr_policy, actions, attr, error);
    8720                 :            : }
    8721                 :            : 
    8722                 :            : /**
    8723                 :            :  * Create policy rules, lock free,
    8724                 :            :  * (mutex should be acquired by caller).
    8725                 :            :  * Dispatcher for action type specific call.
    8726                 :            :  *
    8727                 :            :  * @param[in] dev
    8728                 :            :  *   Pointer to the Ethernet device structure.
    8729                 :            :  * @param[in] mtr_policy
    8730                 :            :  *   Meter policy struct.
    8731                 :            :  *
    8732                 :            :  * @return
    8733                 :            :  *   0 on success, -1 otherwise.
    8734                 :            :  */
    8735                 :            : int
    8736                 :          0 : mlx5_flow_create_policy_rules(struct rte_eth_dev *dev,
    8737                 :            :                              struct mlx5_flow_meter_policy *mtr_policy)
    8738                 :            : {
    8739                 :            :         const struct mlx5_flow_driver_ops *fops;
    8740                 :            : 
    8741                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8742                 :          0 :         return fops->create_policy_rules(dev, mtr_policy);
    8743                 :            : }
    8744                 :            : 
    8745                 :            : /**
    8746                 :            :  * Destroy policy rules, lock free,
    8747                 :            :  * (mutex should be acquired by caller).
    8748                 :            :  * Dispatcher for action type specific call.
    8749                 :            :  *
    8750                 :            :  * @param[in] dev
    8751                 :            :  *   Pointer to the Ethernet device structure.
    8752                 :            :  * @param[in] mtr_policy
    8753                 :            :  *   Meter policy struct.
    8754                 :            :  */
    8755                 :            : void
    8756                 :          0 : mlx5_flow_destroy_policy_rules(struct rte_eth_dev *dev,
    8757                 :            :                              struct mlx5_flow_meter_policy *mtr_policy)
    8758                 :            : {
    8759                 :            :         const struct mlx5_flow_driver_ops *fops;
    8760                 :            : 
    8761                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8762                 :          0 :         fops->destroy_policy_rules(dev, mtr_policy);
    8763                 :          0 : }
    8764                 :            : 
    8765                 :            : /**
    8766                 :            :  * Destroy the default policy table set.
    8767                 :            :  *
    8768                 :            :  * @param[in] dev
    8769                 :            :  *   Pointer to Ethernet device.
    8770                 :            :  */
    8771                 :            : void
    8772                 :          0 : mlx5_flow_destroy_def_policy(struct rte_eth_dev *dev)
    8773                 :            : {
    8774                 :            :         const struct mlx5_flow_driver_ops *fops;
    8775                 :            : 
    8776                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8777                 :          0 :         fops->destroy_def_policy(dev);
    8778                 :          0 : }
    8779                 :            : 
    8780                 :            : /**
    8781                 :            :  * Destroy the default policy table set.
    8782                 :            :  *
    8783                 :            :  * @param[in] dev
    8784                 :            :  *   Pointer to Ethernet device.
    8785                 :            :  *
    8786                 :            :  * @return
    8787                 :            :  *   0 on success, -1 otherwise.
    8788                 :            :  */
    8789                 :            : int
    8790                 :          0 : mlx5_flow_create_def_policy(struct rte_eth_dev *dev)
    8791                 :            : {
    8792                 :            :         const struct mlx5_flow_driver_ops *fops;
    8793                 :            : 
    8794                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8795                 :          0 :         return fops->create_def_policy(dev);
    8796                 :            : }
    8797                 :            : 
    8798                 :            : /**
    8799                 :            :  * Create the needed meter and suffix tables.
    8800                 :            :  *
    8801                 :            :  * @param[in] dev
    8802                 :            :  *   Pointer to Ethernet device.
    8803                 :            :  *
    8804                 :            :  * @return
    8805                 :            :  *   0 on success, -1 otherwise.
    8806                 :            :  */
    8807                 :            : int
    8808                 :          0 : mlx5_flow_create_mtr_tbls(struct rte_eth_dev *dev,
    8809                 :            :                         struct mlx5_flow_meter_info *fm,
    8810                 :            :                         uint32_t mtr_idx,
    8811                 :            :                         uint8_t domain_bitmap)
    8812                 :            : {
    8813                 :            :         const struct mlx5_flow_driver_ops *fops;
    8814                 :            : 
    8815                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8816                 :          0 :         return fops->create_mtr_tbls(dev, fm, mtr_idx, domain_bitmap);
    8817                 :            : }
    8818                 :            : 
    8819                 :            : /**
    8820                 :            :  * Destroy the meter table set.
    8821                 :            :  *
    8822                 :            :  * @param[in] dev
    8823                 :            :  *   Pointer to Ethernet device.
    8824                 :            :  * @param[in] tbl
    8825                 :            :  *   Pointer to the meter table set.
    8826                 :            :  */
    8827                 :            : void
    8828                 :          0 : mlx5_flow_destroy_mtr_tbls(struct rte_eth_dev *dev,
    8829                 :            :                            struct mlx5_flow_meter_info *fm)
    8830                 :            : {
    8831                 :            :         const struct mlx5_flow_driver_ops *fops;
    8832                 :            : 
    8833                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8834                 :          0 :         fops->destroy_mtr_tbls(dev, fm);
    8835                 :          0 : }
    8836                 :            : 
    8837                 :            : /**
    8838                 :            :  * Destroy the global meter drop table.
    8839                 :            :  *
    8840                 :            :  * @param[in] dev
    8841                 :            :  *   Pointer to Ethernet device.
    8842                 :            :  */
    8843                 :            : void
    8844                 :          0 : mlx5_flow_destroy_mtr_drop_tbls(struct rte_eth_dev *dev)
    8845                 :            : {
    8846                 :            :         const struct mlx5_flow_driver_ops *fops;
    8847                 :            : 
    8848                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8849                 :          0 :         fops->destroy_mtr_drop_tbls(dev);
    8850                 :          0 : }
    8851                 :            : 
    8852                 :            : /**
    8853                 :            :  * Destroy the sub policy table with RX queue.
    8854                 :            :  *
    8855                 :            :  * @param[in] dev
    8856                 :            :  *   Pointer to Ethernet device.
    8857                 :            :  * @param[in] mtr_policy
    8858                 :            :  *   Pointer to meter policy table.
    8859                 :            :  */
    8860                 :            : void
    8861                 :          0 : mlx5_flow_destroy_sub_policy_with_rxq(struct rte_eth_dev *dev,
    8862                 :            :                 struct mlx5_flow_meter_policy *mtr_policy)
    8863                 :            : {
    8864                 :            :         const struct mlx5_flow_driver_ops *fops;
    8865                 :            : 
    8866                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8867                 :          0 :         fops->destroy_sub_policy_with_rxq(dev, mtr_policy);
    8868                 :          0 : }
    8869                 :            : 
    8870                 :            : /**
    8871                 :            :  * Allocate the needed aso flow meter id.
    8872                 :            :  *
    8873                 :            :  * @param[in] dev
    8874                 :            :  *   Pointer to Ethernet device.
    8875                 :            :  *
    8876                 :            :  * @return
    8877                 :            :  *   Index to aso flow meter on success, NULL otherwise.
    8878                 :            :  */
    8879                 :            : uint32_t
    8880                 :          0 : mlx5_flow_mtr_alloc(struct rte_eth_dev *dev)
    8881                 :            : {
    8882                 :            :         const struct mlx5_flow_driver_ops *fops;
    8883                 :            : 
    8884                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8885                 :          0 :         return fops->create_meter(dev);
    8886                 :            : }
    8887                 :            : 
    8888                 :            : /**
    8889                 :            :  * Free the aso flow meter id.
    8890                 :            :  *
    8891                 :            :  * @param[in] dev
    8892                 :            :  *   Pointer to Ethernet device.
    8893                 :            :  * @param[in] mtr_idx
    8894                 :            :  *  Index to aso flow meter to be free.
    8895                 :            :  *
    8896                 :            :  * @return
    8897                 :            :  *   0 on success.
    8898                 :            :  */
    8899                 :            : void
    8900                 :          0 : mlx5_flow_mtr_free(struct rte_eth_dev *dev, uint32_t mtr_idx)
    8901                 :            : {
    8902                 :            :         const struct mlx5_flow_driver_ops *fops;
    8903                 :            : 
    8904                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
    8905                 :          0 :         fops->free_meter(dev, mtr_idx);
    8906                 :          0 : }
    8907                 :            : 
    8908                 :            : /**
    8909                 :            :  * Allocate a counter.
    8910                 :            :  *
    8911                 :            :  * @param[in] dev
    8912                 :            :  *   Pointer to Ethernet device structure.
    8913                 :            :  *
    8914                 :            :  * @return
    8915                 :            :  *   Index to allocated counter  on success, 0 otherwise.
    8916                 :            :  */
    8917                 :            : uint32_t
    8918         [ #  # ]:          0 : mlx5_counter_alloc(struct rte_eth_dev *dev)
    8919                 :            : {
    8920                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
    8921                 :            : 
    8922                 :          0 :         return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_alloc
    8923                 :            :                 (dev);
    8924                 :            : }
    8925                 :            : 
    8926                 :            : /**
    8927                 :            :  * Free a counter.
    8928                 :            :  *
    8929                 :            :  * @param[in] dev
    8930                 :            :  *   Pointer to Ethernet device structure.
    8931                 :            :  * @param[in] cnt
    8932                 :            :  *   Index to counter to be free.
    8933                 :            :  */
    8934                 :            : void
    8935         [ #  # ]:          0 : mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
    8936                 :            : {
    8937                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
    8938                 :            : 
    8939                 :          0 :         flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_free(dev, cnt);
    8940                 :          0 : }
    8941                 :            : 
    8942                 :            : /**
    8943                 :            :  * Query counter statistics.
    8944                 :            :  *
    8945                 :            :  * @param[in] dev
    8946                 :            :  *   Pointer to Ethernet device structure.
    8947                 :            :  * @param[in] cnt
    8948                 :            :  *   Index to counter to query.
    8949                 :            :  * @param[in] clear
    8950                 :            :  *   Set to clear counter statistics.
    8951                 :            :  * @param[out] pkts
    8952                 :            :  *   The counter hits packets number to save.
    8953                 :            :  * @param[out] bytes
    8954                 :            :  *   The counter hits bytes number to save.
    8955                 :            :  *
    8956                 :            :  * @return
    8957                 :            :  *   0 on success, a negative errno value otherwise.
    8958                 :            :  */
    8959                 :            : int
    8960         [ #  # ]:          0 : mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
    8961                 :            :                    bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
    8962                 :            : {
    8963                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
    8964                 :            : 
    8965                 :          0 :         return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->counter_query
    8966                 :            :                 (dev, cnt, clear, pkts, bytes, action);
    8967                 :            : }
    8968                 :            : 
    8969                 :            : /**
    8970                 :            :  * Get information about HWS pre-configurable resources.
    8971                 :            :  *
    8972                 :            :  * @param[in] dev
    8973                 :            :  *   Pointer to the rte_eth_dev structure.
    8974                 :            :  * @param[out] port_info
    8975                 :            :  *   Pointer to port information.
    8976                 :            :  * @param[out] queue_info
    8977                 :            :  *   Pointer to queue information.
    8978                 :            :  * @param[out] error
    8979                 :            :  *   Pointer to error structure.
    8980                 :            :  *
    8981                 :            :  * @return
    8982                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    8983                 :            :  */
    8984                 :            : static int
    8985         [ #  # ]:          0 : mlx5_flow_info_get(struct rte_eth_dev *dev,
    8986                 :            :                    struct rte_flow_port_info *port_info,
    8987                 :            :                    struct rte_flow_queue_info *queue_info,
    8988                 :            :                    struct rte_flow_error *error)
    8989                 :            : {
    8990                 :            :         const struct mlx5_flow_driver_ops *fops;
    8991                 :            :         struct rte_flow_attr attr = {0};
    8992                 :            : 
    8993                 :            :         if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
    8994                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    8995                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    8996                 :            :                                 NULL,
    8997                 :            :                                 "info get with incorrect steering mode");
    8998                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    8999                 :          0 :         return fops->info_get(dev, port_info, queue_info, error);
    9000                 :            : }
    9001                 :            : 
    9002                 :            : /**
    9003                 :            :  * Configure port HWS resources.
    9004                 :            :  *
    9005                 :            :  * @param[in] dev
    9006                 :            :  *   Pointer to the rte_eth_dev structure.
    9007                 :            :  * @param[in] port_attr
    9008                 :            :  *   Port configuration attributes.
    9009                 :            :  * @param[in] nb_queue
    9010                 :            :  *   Number of queue.
    9011                 :            :  * @param[in] queue_attr
    9012                 :            :  *   Array that holds attributes for each flow queue.
    9013                 :            :  * @param[out] error
    9014                 :            :  *   Pointer to error structure.
    9015                 :            :  *
    9016                 :            :  * @return
    9017                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9018                 :            :  */
    9019                 :            : static int
    9020         [ #  # ]:          0 : mlx5_flow_port_configure(struct rte_eth_dev *dev,
    9021                 :            :                          const struct rte_flow_port_attr *port_attr,
    9022                 :            :                          uint16_t nb_queue,
    9023                 :            :                          const struct rte_flow_queue_attr *queue_attr[],
    9024                 :            :                          struct rte_flow_error *error)
    9025                 :            : {
    9026                 :            :         const struct mlx5_flow_driver_ops *fops;
    9027                 :            :         struct rte_flow_attr attr = {0};
    9028                 :            : 
    9029                 :            :         if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
    9030                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    9031                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9032                 :            :                                 NULL,
    9033                 :            :                                 "port configure with incorrect steering mode");
    9034                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9035                 :          0 :         return fops->configure(dev, port_attr, nb_queue, queue_attr, error);
    9036                 :            : }
    9037                 :            : 
    9038                 :            : /**
    9039                 :            :  * Validate item template.
    9040                 :            :  *
    9041                 :            :  * @param[in] dev
    9042                 :            :  *   Pointer to the rte_eth_dev structure.
    9043                 :            :  * @param[in] attr
    9044                 :            :  *   Pointer to the item template attributes.
    9045                 :            :  * @param[in] items
    9046                 :            :  *   The template item pattern.
    9047                 :            :  * @param[out] error
    9048                 :            :  *   Pointer to error structure.
    9049                 :            :  *
    9050                 :            :  * @return
    9051                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9052                 :            :  */
    9053                 :            : int
    9054         [ #  # ]:          0 : mlx5_flow_pattern_validate(struct rte_eth_dev *dev,
    9055                 :            :                 const struct rte_flow_pattern_template_attr *attr,
    9056                 :            :                 const struct rte_flow_item items[],
    9057                 :            :                 struct rte_flow_error *error)
    9058                 :            : {
    9059                 :            :         const struct mlx5_flow_driver_ops *fops;
    9060                 :            :         struct rte_flow_attr fattr = {0};
    9061                 :            : 
    9062                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
    9063                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    9064                 :            :                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    9065                 :            :                         "pattern validate with incorrect steering mode");
    9066                 :          0 :                 return -ENOTSUP;
    9067                 :            :         }
    9068                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9069                 :          0 :         return fops->pattern_validate(dev, attr, items, error);
    9070                 :            : }
    9071                 :            : 
    9072                 :            : /**
    9073                 :            :  * Create flow item template.
    9074                 :            :  *
    9075                 :            :  * @param[in] dev
    9076                 :            :  *   Pointer to the rte_eth_dev structure.
    9077                 :            :  * @param[in] attr
    9078                 :            :  *   Pointer to the item template attributes.
    9079                 :            :  * @param[in] items
    9080                 :            :  *   The template item pattern.
    9081                 :            :  * @param[out] error
    9082                 :            :  *   Pointer to error structure.
    9083                 :            :  *
    9084                 :            :  * @return
    9085                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9086                 :            :  */
    9087                 :            : static struct rte_flow_pattern_template *
    9088         [ #  # ]:          0 : mlx5_flow_pattern_template_create(struct rte_eth_dev *dev,
    9089                 :            :                 const struct rte_flow_pattern_template_attr *attr,
    9090                 :            :                 const struct rte_flow_item items[],
    9091                 :            :                 struct rte_flow_error *error)
    9092                 :            : {
    9093                 :            :         const struct mlx5_flow_driver_ops *fops;
    9094                 :            :         struct rte_flow_attr fattr = {0};
    9095                 :            : 
    9096                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
    9097                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    9098                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9099                 :            :                                 NULL,
    9100                 :            :                                 "pattern create with incorrect steering mode");
    9101                 :          0 :                 return NULL;
    9102                 :            :         }
    9103                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9104                 :          0 :         return fops->pattern_template_create(dev, attr, items, error);
    9105                 :            : }
    9106                 :            : 
    9107                 :            : /**
    9108                 :            :  * Destroy flow item template.
    9109                 :            :  *
    9110                 :            :  * @param[in] dev
    9111                 :            :  *   Pointer to the rte_eth_dev structure.
    9112                 :            :  * @param[in] template
    9113                 :            :  *   Pointer to the item template to be destroyed.
    9114                 :            :  * @param[out] error
    9115                 :            :  *   Pointer to error structure.
    9116                 :            :  *
    9117                 :            :  * @return
    9118                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9119                 :            :  */
    9120                 :            : static int
    9121         [ #  # ]:          0 : mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev,
    9122                 :            :                                    struct rte_flow_pattern_template *template,
    9123                 :            :                                    struct rte_flow_error *error)
    9124                 :            : {
    9125                 :            :         const struct mlx5_flow_driver_ops *fops;
    9126                 :            :         struct rte_flow_attr attr = {0};
    9127                 :            : 
    9128                 :            :         if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
    9129                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    9130                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9131                 :            :                                 NULL,
    9132                 :            :                                 "pattern destroy with incorrect steering mode");
    9133                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9134                 :          0 :         return fops->pattern_template_destroy(dev, template, error);
    9135                 :            : }
    9136                 :            : 
    9137                 :            : /**
    9138                 :            :  * Validate flow actions template.
    9139                 :            :  *
    9140                 :            :  * @param[in] dev
    9141                 :            :  *   Pointer to the rte_eth_dev structure.
    9142                 :            :  * @param[in] attr
    9143                 :            :  *   Pointer to the action template attributes.
    9144                 :            :  * @param[in] actions
    9145                 :            :  *   Associated actions (list terminated by the END action).
    9146                 :            :  * @param[in] masks
    9147                 :            :  *   List of actions that marks which of the action's member is constant.
    9148                 :            :  * @param[out] error
    9149                 :            :  *   Pointer to error structure.
    9150                 :            :  *
    9151                 :            :  * @return
    9152                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9153                 :            :  */
    9154                 :            : int
    9155         [ #  # ]:          0 : mlx5_flow_actions_validate(struct rte_eth_dev *dev,
    9156                 :            :                         const struct rte_flow_actions_template_attr *attr,
    9157                 :            :                         const struct rte_flow_action actions[],
    9158                 :            :                         const struct rte_flow_action masks[],
    9159                 :            :                         struct rte_flow_error *error)
    9160                 :            : {
    9161                 :            :         const struct mlx5_flow_driver_ops *fops;
    9162                 :            :         struct rte_flow_attr fattr = {0};
    9163                 :            : 
    9164                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
    9165                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    9166                 :            :                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
    9167                 :            :                         "actions validate with incorrect steering mode");
    9168                 :          0 :                 return -ENOTSUP;
    9169                 :            :         }
    9170                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9171                 :          0 :         return fops->actions_validate(dev, attr, actions, masks, error);
    9172                 :            : }
    9173                 :            : 
    9174                 :            : /**
    9175                 :            :  * Create flow item template.
    9176                 :            :  *
    9177                 :            :  * @param[in] dev
    9178                 :            :  *   Pointer to the rte_eth_dev structure.
    9179                 :            :  * @param[in] attr
    9180                 :            :  *   Pointer to the action template attributes.
    9181                 :            :  * @param[in] actions
    9182                 :            :  *   Associated actions (list terminated by the END action).
    9183                 :            :  * @param[in] masks
    9184                 :            :  *   List of actions that marks which of the action's member is constant.
    9185                 :            :  * @param[out] error
    9186                 :            :  *   Pointer to error structure.
    9187                 :            :  *
    9188                 :            :  * @return
    9189                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9190                 :            :  */
    9191                 :            : static struct rte_flow_actions_template *
    9192         [ #  # ]:          0 : mlx5_flow_actions_template_create(struct rte_eth_dev *dev,
    9193                 :            :                         const struct rte_flow_actions_template_attr *attr,
    9194                 :            :                         const struct rte_flow_action actions[],
    9195                 :            :                         const struct rte_flow_action masks[],
    9196                 :            :                         struct rte_flow_error *error)
    9197                 :            : {
    9198                 :            :         const struct mlx5_flow_driver_ops *fops;
    9199                 :            :         struct rte_flow_attr fattr = {0};
    9200                 :            : 
    9201                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
    9202                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    9203                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9204                 :            :                                 NULL,
    9205                 :            :                                 "action create with incorrect steering mode");
    9206                 :          0 :                 return NULL;
    9207                 :            :         }
    9208                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9209                 :          0 :         return fops->actions_template_create(dev, attr, actions, masks, error);
    9210                 :            : }
    9211                 :            : 
    9212                 :            : /**
    9213                 :            :  * Destroy flow action template.
    9214                 :            :  *
    9215                 :            :  * @param[in] dev
    9216                 :            :  *   Pointer to the rte_eth_dev structure.
    9217                 :            :  * @param[in] template
    9218                 :            :  *   Pointer to the action template to be destroyed.
    9219                 :            :  * @param[out] error
    9220                 :            :  *   Pointer to error structure.
    9221                 :            :  *
    9222                 :            :  * @return
    9223                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9224                 :            :  */
    9225                 :            : static int
    9226         [ #  # ]:          0 : mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev,
    9227                 :            :                                    struct rte_flow_actions_template *template,
    9228                 :            :                                    struct rte_flow_error *error)
    9229                 :            : {
    9230                 :            :         const struct mlx5_flow_driver_ops *fops;
    9231                 :            :         struct rte_flow_attr attr = {0};
    9232                 :            : 
    9233                 :            :         if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
    9234                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    9235                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9236                 :            :                                 NULL,
    9237                 :            :                                 "action destroy with incorrect steering mode");
    9238                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9239                 :          0 :         return fops->actions_template_destroy(dev, template, error);
    9240                 :            : }
    9241                 :            : 
    9242                 :            : /**
    9243                 :            :  * Create flow table.
    9244                 :            :  *
    9245                 :            :  * @param[in] dev
    9246                 :            :  *   Pointer to the rte_eth_dev structure.
    9247                 :            :  * @param[in] attr
    9248                 :            :  *   Pointer to the table attributes.
    9249                 :            :  * @param[in] item_templates
    9250                 :            :  *   Item template array to be binded to the table.
    9251                 :            :  * @param[in] nb_item_templates
    9252                 :            :  *   Number of item template.
    9253                 :            :  * @param[in] action_templates
    9254                 :            :  *   Action template array to be binded to the table.
    9255                 :            :  * @param[in] nb_action_templates
    9256                 :            :  *   Number of action template.
    9257                 :            :  * @param[out] error
    9258                 :            :  *   Pointer to error structure.
    9259                 :            :  *
    9260                 :            :  * @return
    9261                 :            :  *    Table on success, NULL otherwise and rte_errno is set.
    9262                 :            :  */
    9263                 :            : static struct rte_flow_template_table *
    9264         [ #  # ]:          0 : mlx5_flow_table_create(struct rte_eth_dev *dev,
    9265                 :            :                        const struct rte_flow_template_table_attr *attr,
    9266                 :            :                        struct rte_flow_pattern_template *item_templates[],
    9267                 :            :                        uint8_t nb_item_templates,
    9268                 :            :                        struct rte_flow_actions_template *action_templates[],
    9269                 :            :                        uint8_t nb_action_templates,
    9270                 :            :                        struct rte_flow_error *error)
    9271                 :            : {
    9272                 :            :         const struct mlx5_flow_driver_ops *fops;
    9273                 :            :         struct rte_flow_attr fattr = {0};
    9274                 :            : 
    9275                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW) {
    9276                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
    9277                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9278                 :            :                                 NULL,
    9279                 :            :                                 "table create with incorrect steering mode");
    9280                 :          0 :                 return NULL;
    9281                 :            :         }
    9282                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9283                 :          0 :         return fops->template_table_create(dev,
    9284                 :            :                                            attr,
    9285                 :            :                                            item_templates,
    9286                 :            :                                            nb_item_templates,
    9287                 :            :                                            action_templates,
    9288                 :            :                                            nb_action_templates,
    9289                 :            :                                            error);
    9290                 :            : }
    9291                 :            : 
    9292                 :            : /**
    9293                 :            :  * PMD destroy flow table.
    9294                 :            :  *
    9295                 :            :  * @param[in] dev
    9296                 :            :  *   Pointer to the rte_eth_dev structure.
    9297                 :            :  * @param[in] table
    9298                 :            :  *   Pointer to the table to be destroyed.
    9299                 :            :  * @param[out] error
    9300                 :            :  *   Pointer to error structure.
    9301                 :            :  *
    9302                 :            :  * @return
    9303                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9304                 :            :  */
    9305                 :            : static int
    9306         [ #  # ]:          0 : mlx5_flow_table_destroy(struct rte_eth_dev *dev,
    9307                 :            :                         struct rte_flow_template_table *table,
    9308                 :            :                         struct rte_flow_error *error)
    9309                 :            : {
    9310                 :            :         const struct mlx5_flow_driver_ops *fops;
    9311                 :            :         struct rte_flow_attr attr = {0};
    9312                 :            : 
    9313                 :            :         if (flow_get_drv_type(dev, &attr) != MLX5_FLOW_TYPE_HW)
    9314                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    9315                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9316                 :            :                                 NULL,
    9317                 :            :                                 "table destroy with incorrect steering mode");
    9318                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9319                 :          0 :         return fops->template_table_destroy(dev, table, error);
    9320                 :            : }
    9321                 :            : 
    9322                 :            : /**
    9323                 :            :  * PMD group set miss actions.
    9324                 :            :  *
    9325                 :            :  * @param[in] dev
    9326                 :            :  *   Pointer to the rte_eth_dev structure.
    9327                 :            :  * @param[in] attr
    9328                 :            :  *   Pointer to group attributes
    9329                 :            :  * @param[in] actions
    9330                 :            :  *   Array of actions
    9331                 :            :  * @param[out] error
    9332                 :            :  *   Pointer to error structure.
    9333                 :            :  *
    9334                 :            :  * @return
    9335                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9336                 :            :  */
    9337                 :            : static int
    9338         [ #  # ]:          0 : mlx5_flow_group_set_miss_actions(struct rte_eth_dev *dev,
    9339                 :            :                                  uint32_t group_id,
    9340                 :            :                                  const struct rte_flow_group_attr *attr,
    9341                 :            :                                  const struct rte_flow_action actions[],
    9342                 :            :                                  struct rte_flow_error *error)
    9343                 :            : {
    9344                 :            :         const struct mlx5_flow_driver_ops *fops;
    9345                 :            :         struct rte_flow_attr fattr = {0};
    9346                 :            : 
    9347                 :            :         if (flow_get_drv_type(dev, &fattr) != MLX5_FLOW_TYPE_HW)
    9348                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
    9349                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9350                 :            :                                 NULL,
    9351                 :            :                                 "group set miss actions with incorrect steering mode");
    9352                 :          0 :         fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
    9353                 :          0 :         return fops->group_set_miss_actions(dev, group_id, attr, actions, error);
    9354                 :            : }
    9355                 :            : 
    9356                 :            : /**
    9357                 :            :  * Allocate a new memory for the counter values wrapped by all the needed
    9358                 :            :  * management.
    9359                 :            :  *
    9360                 :            :  * @param[in] sh
    9361                 :            :  *   Pointer to mlx5_dev_ctx_shared object.
    9362                 :            :  *
    9363                 :            :  * @return
    9364                 :            :  *   0 on success, a negative errno value otherwise.
    9365                 :            :  */
    9366                 :            : static int
    9367                 :          0 : mlx5_flow_create_counter_stat_mem_mng(struct mlx5_dev_ctx_shared *sh)
    9368                 :            : {
    9369                 :            :         struct mlx5_counter_stats_mem_mng *mem_mng;
    9370                 :            :         volatile struct flow_counter_stats *raw_data;
    9371                 :            :         int raws_n = MLX5_CNT_MR_ALLOC_BULK + MLX5_MAX_PENDING_QUERIES;
    9372                 :            :         int size = (sizeof(struct flow_counter_stats) *
    9373                 :            :                         MLX5_COUNTERS_PER_POOL +
    9374                 :            :                         sizeof(struct mlx5_counter_stats_raw)) * raws_n +
    9375                 :            :                         sizeof(struct mlx5_counter_stats_mem_mng);
    9376                 :          0 :         size_t pgsize = rte_mem_page_size();
    9377                 :            :         uint8_t *mem;
    9378                 :            :         int ret;
    9379                 :            :         int i;
    9380                 :            : 
    9381         [ #  # ]:          0 :         if (pgsize == (size_t)-1) {
    9382                 :          0 :                 DRV_LOG(ERR, "Failed to get mem page size");
    9383                 :          0 :                 rte_errno = ENOMEM;
    9384                 :          0 :                 return -ENOMEM;
    9385                 :            :         }
    9386                 :          0 :         mem = mlx5_malloc(MLX5_MEM_ZERO, size, pgsize, SOCKET_ID_ANY);
    9387         [ #  # ]:          0 :         if (!mem) {
    9388                 :          0 :                 rte_errno = ENOMEM;
    9389                 :          0 :                 return -ENOMEM;
    9390                 :            :         }
    9391                 :          0 :         mem_mng = (struct mlx5_counter_stats_mem_mng *)(mem + size) - 1;
    9392                 :            :         size = sizeof(*raw_data) * MLX5_COUNTERS_PER_POOL * raws_n;
    9393                 :          0 :         ret = mlx5_os_wrapped_mkey_create(sh->cdev->ctx, sh->cdev->pd,
    9394                 :          0 :                                           sh->cdev->pdn, mem, size,
    9395                 :            :                                           &mem_mng->wm);
    9396         [ #  # ]:          0 :         if (ret) {
    9397                 :          0 :                 rte_errno = errno;
    9398                 :          0 :                 mlx5_free(mem);
    9399                 :          0 :                 return -rte_errno;
    9400                 :            :         }
    9401                 :          0 :         mem_mng->raws = (struct mlx5_counter_stats_raw *)(mem + size);
    9402                 :            :         raw_data = (volatile struct flow_counter_stats *)mem;
    9403         [ #  # ]:          0 :         for (i = 0; i < raws_n; ++i) {
    9404                 :          0 :                 mem_mng->raws[i].mem_mng = mem_mng;
    9405                 :          0 :                 mem_mng->raws[i].data = raw_data + i * MLX5_COUNTERS_PER_POOL;
    9406                 :            :         }
    9407         [ #  # ]:          0 :         for (i = 0; i < MLX5_MAX_PENDING_QUERIES; ++i)
    9408         [ #  # ]:          0 :                 LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws,
    9409                 :            :                                  mem_mng->raws + MLX5_CNT_MR_ALLOC_BULK + i,
    9410                 :            :                                  next);
    9411         [ #  # ]:          0 :         LIST_INSERT_HEAD(&sh->sws_cmng.mem_mngs, mem_mng, next);
    9412                 :          0 :         sh->sws_cmng.mem_mng = mem_mng;
    9413                 :          0 :         return 0;
    9414                 :            : }
    9415                 :            : 
    9416                 :            : /**
    9417                 :            :  * Set the statistic memory to the new counter pool.
    9418                 :            :  *
    9419                 :            :  * @param[in] sh
    9420                 :            :  *   Pointer to mlx5_dev_ctx_shared object.
    9421                 :            :  * @param[in] pool
    9422                 :            :  *   Pointer to the pool to set the statistic memory.
    9423                 :            :  *
    9424                 :            :  * @return
    9425                 :            :  *   0 on success, a negative errno value otherwise.
    9426                 :            :  */
    9427                 :            : static int
    9428                 :          0 : mlx5_flow_set_counter_stat_mem(struct mlx5_dev_ctx_shared *sh,
    9429                 :            :                                struct mlx5_flow_counter_pool *pool)
    9430                 :            : {
    9431                 :            :         struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
    9432                 :            :         /* Resize statistic memory once used out. */
    9433   [ #  #  #  # ]:          0 :         if (!(pool->index % MLX5_CNT_MR_ALLOC_BULK) &&
    9434                 :          0 :             mlx5_flow_create_counter_stat_mem_mng(sh)) {
    9435                 :          0 :                 DRV_LOG(ERR, "Cannot resize counter stat mem.");
    9436                 :          0 :                 return -1;
    9437                 :            :         }
    9438                 :          0 :         rte_spinlock_lock(&pool->sl);
    9439                 :          0 :         pool->raw = cmng->mem_mng->raws + pool->index % MLX5_CNT_MR_ALLOC_BULK;
    9440                 :            :         rte_spinlock_unlock(&pool->sl);
    9441                 :          0 :         pool->raw_hw = NULL;
    9442                 :          0 :         return 0;
    9443                 :            : }
    9444                 :            : 
    9445                 :            : #define MLX5_POOL_QUERY_FREQ_US 1000000
    9446                 :            : 
    9447                 :            : /**
    9448                 :            :  * Set the periodic procedure for triggering asynchronous batch queries for all
    9449                 :            :  * the counter pools.
    9450                 :            :  *
    9451                 :            :  * @param[in] sh
    9452                 :            :  *   Pointer to mlx5_dev_ctx_shared object.
    9453                 :            :  */
    9454                 :            : void
    9455                 :          0 : mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh)
    9456                 :            : {
    9457                 :            :         uint32_t pools_n, us;
    9458                 :            : 
    9459                 :          0 :         pools_n = __atomic_load_n(&sh->sws_cmng.n_valid, __ATOMIC_RELAXED);
    9460                 :          0 :         us = MLX5_POOL_QUERY_FREQ_US / pools_n;
    9461                 :          0 :         DRV_LOG(DEBUG, "Set alarm for %u pools each %u us", pools_n, us);
    9462         [ #  # ]:          0 :         if (rte_eal_alarm_set(us, mlx5_flow_query_alarm, sh)) {
    9463                 :          0 :                 sh->sws_cmng.query_thread_on = 0;
    9464                 :          0 :                 DRV_LOG(ERR, "Cannot reinitialize query alarm");
    9465                 :            :         } else {
    9466                 :          0 :                 sh->sws_cmng.query_thread_on = 1;
    9467                 :            :         }
    9468                 :          0 : }
    9469                 :            : 
    9470                 :            : /**
    9471                 :            :  * The periodic procedure for triggering asynchronous batch queries for all the
    9472                 :            :  * counter pools. This function is probably called by the host thread.
    9473                 :            :  *
    9474                 :            :  * @param[in] arg
    9475                 :            :  *   The parameter for the alarm process.
    9476                 :            :  */
    9477                 :            : void
    9478                 :          0 : mlx5_flow_query_alarm(void *arg)
    9479                 :            : {
    9480                 :            :         struct mlx5_dev_ctx_shared *sh = arg;
    9481                 :            :         struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
    9482                 :          0 :         uint16_t pool_index = cmng->pool_index;
    9483                 :            :         struct mlx5_flow_counter_pool *pool;
    9484                 :            :         uint16_t n_valid;
    9485                 :            :         int ret;
    9486                 :            : 
    9487         [ #  # ]:          0 :         if (cmng->pending_queries >= MLX5_MAX_PENDING_QUERIES)
    9488                 :          0 :                 goto set_alarm;
    9489                 :          0 :         rte_spinlock_lock(&cmng->pool_update_sl);
    9490                 :          0 :         pool = cmng->pools[pool_index];
    9491                 :          0 :         n_valid = cmng->n_valid;
    9492                 :            :         rte_spinlock_unlock(&cmng->pool_update_sl);
    9493                 :            :         /* Set the statistic memory to the new created pool. */
    9494   [ #  #  #  # ]:          0 :         if ((!pool->raw && mlx5_flow_set_counter_stat_mem(sh, pool)))
    9495                 :          0 :                 goto set_alarm;
    9496         [ #  # ]:          0 :         if (pool->raw_hw)
    9497                 :            :                 /* There is a pool query in progress. */
    9498                 :          0 :                 goto set_alarm;
    9499                 :          0 :         pool->raw_hw = LIST_FIRST(&cmng->free_stat_raws);
    9500         [ #  # ]:          0 :         if (!pool->raw_hw)
    9501                 :            :                 /* No free counter statistics raw memory. */
    9502                 :          0 :                 goto set_alarm;
    9503                 :            :         /*
    9504                 :            :          * Identify the counters released between query trigger and query
    9505                 :            :          * handle more efficiently. The counter released in this gap period
    9506                 :            :          * should wait for a new round of query as the new arrived packets
    9507                 :            :          * will not be taken into account.
    9508                 :            :          */
    9509                 :          0 :         pool->query_gen++;
    9510                 :          0 :         ret = mlx5_devx_cmd_flow_counter_query(pool->min_dcs, 0,
    9511                 :            :                                                MLX5_COUNTERS_PER_POOL,
    9512                 :            :                                                NULL, NULL,
    9513                 :          0 :                                                pool->raw_hw->mem_mng->wm.lkey,
    9514                 :            :                                                (void *)(uintptr_t)
    9515                 :          0 :                                                pool->raw_hw->data,
    9516                 :            :                                                sh->devx_comp,
    9517                 :            :                                                (uint64_t)(uintptr_t)pool);
    9518         [ #  # ]:          0 :         if (ret) {
    9519                 :          0 :                 DRV_LOG(ERR, "Failed to trigger asynchronous query for dcs ID"
    9520                 :            :                         " %d", pool->min_dcs->id);
    9521                 :          0 :                 pool->raw_hw = NULL;
    9522                 :          0 :                 goto set_alarm;
    9523                 :            :         }
    9524         [ #  # ]:          0 :         LIST_REMOVE(pool->raw_hw, next);
    9525                 :          0 :         cmng->pending_queries++;
    9526                 :          0 :         pool_index++;
    9527         [ #  # ]:          0 :         if (pool_index >= n_valid)
    9528                 :            :                 pool_index = 0;
    9529                 :          0 : set_alarm:
    9530                 :          0 :         cmng->pool_index = pool_index;
    9531                 :          0 :         mlx5_set_query_alarm(sh);
    9532                 :          0 : }
    9533                 :            : 
    9534                 :            : /**
    9535                 :            :  * Check and callback event for new aged flow in the counter pool
    9536                 :            :  *
    9537                 :            :  * @param[in] sh
    9538                 :            :  *   Pointer to mlx5_dev_ctx_shared object.
    9539                 :            :  * @param[in] pool
    9540                 :            :  *   Pointer to Current counter pool.
    9541                 :            :  */
    9542                 :            : static void
    9543                 :          0 : mlx5_flow_aging_check(struct mlx5_dev_ctx_shared *sh,
    9544                 :            :                    struct mlx5_flow_counter_pool *pool)
    9545                 :            : {
    9546                 :            :         struct mlx5_priv *priv;
    9547                 :            :         struct mlx5_flow_counter *cnt;
    9548                 :            :         struct mlx5_age_info *age_info;
    9549                 :            :         struct mlx5_age_param *age_param;
    9550                 :          0 :         struct mlx5_counter_stats_raw *cur = pool->raw_hw;
    9551                 :          0 :         struct mlx5_counter_stats_raw *prev = pool->raw;
    9552                 :          0 :         const uint64_t curr_time = MLX5_CURR_TIME_SEC;
    9553                 :          0 :         const uint32_t time_delta = curr_time - pool->time_of_last_age_check;
    9554                 :            :         uint16_t expected = AGE_CANDIDATE;
    9555                 :            :         uint32_t i;
    9556                 :            : 
    9557                 :          0 :         pool->time_of_last_age_check = curr_time;
    9558         [ #  # ]:          0 :         for (i = 0; i < MLX5_COUNTERS_PER_POOL; ++i) {
    9559         [ #  # ]:          0 :                 cnt = MLX5_POOL_GET_CNT(pool, i);
    9560                 :            :                 age_param = MLX5_CNT_TO_AGE(cnt);
    9561         [ #  # ]:          0 :                 if (__atomic_load_n(&age_param->state,
    9562                 :            :                                     __ATOMIC_RELAXED) != AGE_CANDIDATE)
    9563                 :          0 :                         continue;
    9564         [ #  # ]:          0 :                 if (cur->data[i].hits != prev->data[i].hits) {
    9565                 :          0 :                         __atomic_store_n(&age_param->sec_since_last_hit, 0,
    9566                 :            :                                          __ATOMIC_RELAXED);
    9567                 :          0 :                         continue;
    9568                 :            :                 }
    9569                 :          0 :                 if (__atomic_fetch_add(&age_param->sec_since_last_hit,
    9570                 :            :                                        time_delta,
    9571         [ #  # ]:          0 :                                        __ATOMIC_RELAXED) + time_delta <= age_param->timeout)
    9572                 :          0 :                         continue;
    9573                 :            :                 /**
    9574                 :            :                  * Hold the lock first, or if between the
    9575                 :            :                  * state AGE_TMOUT and tailq operation the
    9576                 :            :                  * release happened, the release procedure
    9577                 :            :                  * may delete a non-existent tailq node.
    9578                 :            :                  */
    9579                 :          0 :                 priv = rte_eth_devices[age_param->port_id].data->dev_private;
    9580                 :          0 :                 age_info = GET_PORT_AGE_INFO(priv);
    9581                 :          0 :                 rte_spinlock_lock(&age_info->aged_sl);
    9582         [ #  # ]:          0 :                 if (__atomic_compare_exchange_n(&age_param->state, &expected,
    9583                 :            :                                                 AGE_TMOUT, false,
    9584                 :            :                                                 __ATOMIC_RELAXED,
    9585                 :            :                                                 __ATOMIC_RELAXED)) {
    9586                 :          0 :                         TAILQ_INSERT_TAIL(&age_info->aged_counters, cnt, next);
    9587                 :          0 :                         MLX5_AGE_SET(age_info, MLX5_AGE_EVENT_NEW);
    9588                 :            :                 }
    9589                 :            :                 rte_spinlock_unlock(&age_info->aged_sl);
    9590                 :            :         }
    9591                 :          0 :         mlx5_age_event_prepare(sh);
    9592                 :          0 : }
    9593                 :            : 
    9594                 :            : /**
    9595                 :            :  * Handler for the HW respond about ready values from an asynchronous batch
    9596                 :            :  * query. This function is probably called by the host thread.
    9597                 :            :  *
    9598                 :            :  * @param[in] sh
    9599                 :            :  *   The pointer to the shared device context.
    9600                 :            :  * @param[in] async_id
    9601                 :            :  *   The Devx async ID.
    9602                 :            :  * @param[in] status
    9603                 :            :  *   The status of the completion.
    9604                 :            :  */
    9605                 :            : void
    9606                 :          0 : mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
    9607                 :            :                                   uint64_t async_id, int status)
    9608                 :            : {
    9609                 :          0 :         struct mlx5_flow_counter_pool *pool =
    9610                 :            :                 (struct mlx5_flow_counter_pool *)(uintptr_t)async_id;
    9611                 :            :         struct mlx5_counter_stats_raw *raw_to_free;
    9612                 :          0 :         uint8_t query_gen = pool->query_gen ^ 1;
    9613                 :            :         struct mlx5_flow_counter_mng *cmng = &sh->sws_cmng;
    9614                 :          0 :         enum mlx5_counter_type cnt_type =
    9615                 :          0 :                 pool->is_aged ? MLX5_COUNTER_TYPE_AGE :
    9616                 :            :                                 MLX5_COUNTER_TYPE_ORIGIN;
    9617                 :            : 
    9618         [ #  # ]:          0 :         if (unlikely(status)) {
    9619                 :          0 :                 raw_to_free = pool->raw_hw;
    9620                 :            :         } else {
    9621                 :          0 :                 raw_to_free = pool->raw;
    9622         [ #  # ]:          0 :                 if (pool->is_aged)
    9623                 :          0 :                         mlx5_flow_aging_check(sh, pool);
    9624                 :          0 :                 rte_spinlock_lock(&pool->sl);
    9625                 :          0 :                 pool->raw = pool->raw_hw;
    9626                 :            :                 rte_spinlock_unlock(&pool->sl);
    9627                 :            :                 /* Be sure the new raw counters data is updated in memory. */
    9628                 :          0 :                 rte_io_wmb();
    9629         [ #  # ]:          0 :                 if (!TAILQ_EMPTY(&pool->counters[query_gen])) {
    9630                 :          0 :                         rte_spinlock_lock(&cmng->csl[cnt_type]);
    9631         [ #  # ]:          0 :                         TAILQ_CONCAT(&cmng->counters[cnt_type],
    9632                 :            :                                      &pool->counters[query_gen], next);
    9633                 :            :                         rte_spinlock_unlock(&cmng->csl[cnt_type]);
    9634                 :            :                 }
    9635                 :            :         }
    9636         [ #  # ]:          0 :         LIST_INSERT_HEAD(&sh->sws_cmng.free_stat_raws, raw_to_free, next);
    9637                 :          0 :         pool->raw_hw = NULL;
    9638                 :          0 :         sh->sws_cmng.pending_queries--;
    9639                 :          0 : }
    9640                 :            : 
    9641                 :            : static int
    9642                 :          0 : flow_group_to_table(uint32_t port_id, uint32_t group, uint32_t *table,
    9643                 :            :                     const struct flow_grp_info *grp_info,
    9644                 :            :                     struct rte_flow_error *error)
    9645                 :            : {
    9646         [ #  # ]:          0 :         if (grp_info->transfer && grp_info->external &&
    9647                 :            :             grp_info->fdb_def_rule) {
    9648         [ #  # ]:          0 :                 if (group == UINT32_MAX)
    9649                 :          0 :                         return rte_flow_error_set
    9650                 :            :                                                 (error, EINVAL,
    9651                 :            :                                                  RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
    9652                 :            :                                                  NULL,
    9653                 :            :                                                  "group index not supported");
    9654                 :          0 :                 *table = group + 1;
    9655                 :            :         } else {
    9656                 :          0 :                 *table = group;
    9657                 :            :         }
    9658                 :          0 :         DRV_LOG(DEBUG, "port %u group=%#x table=%#x", port_id, group, *table);
    9659                 :          0 :         return 0;
    9660                 :            : }
    9661                 :            : 
    9662                 :            : /**
    9663                 :            :  * Translate the rte_flow group index to HW table value.
    9664                 :            :  *
    9665                 :            :  * If tunnel offload is disabled, all group ids converted to flow table
    9666                 :            :  * id using the standard method.
    9667                 :            :  * If tunnel offload is enabled, group id can be converted using the
    9668                 :            :  * standard or tunnel conversion method. Group conversion method
    9669                 :            :  * selection depends on flags in `grp_info` parameter:
    9670                 :            :  * - Internal (grp_info.external == 0) groups conversion uses the
    9671                 :            :  *   standard method.
    9672                 :            :  * - Group ids in JUMP action converted with the tunnel conversion.
    9673                 :            :  * - Group id in rule attribute conversion depends on a rule type and
    9674                 :            :  *   group id value:
    9675                 :            :  *   ** non zero group attributes converted with the tunnel method
    9676                 :            :  *   ** zero group attribute in non-tunnel rule is converted using the
    9677                 :            :  *      standard method - there's only one root table
    9678                 :            :  *   ** zero group attribute in steer tunnel rule is converted with the
    9679                 :            :  *      standard method - single root table
    9680                 :            :  *   ** zero group attribute in match tunnel rule is a special OvS
    9681                 :            :  *      case: that value is used for portability reasons. That group
    9682                 :            :  *      id is converted with the tunnel conversion method.
    9683                 :            :  *
    9684                 :            :  * @param[in] dev
    9685                 :            :  *   Port device
    9686                 :            :  * @param[in] tunnel
    9687                 :            :  *   PMD tunnel offload object
    9688                 :            :  * @param[in] group
    9689                 :            :  *   rte_flow group index value.
    9690                 :            :  * @param[out] table
    9691                 :            :  *   HW table value.
    9692                 :            :  * @param[in] grp_info
    9693                 :            :  *   flags used for conversion
    9694                 :            :  * @param[out] error
    9695                 :            :  *   Pointer to error structure.
    9696                 :            :  *
    9697                 :            :  * @return
    9698                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9699                 :            :  */
    9700                 :            : int
    9701                 :          0 : mlx5_flow_group_to_table(struct rte_eth_dev *dev,
    9702                 :            :                          const struct mlx5_flow_tunnel *tunnel,
    9703                 :            :                          uint32_t group, uint32_t *table,
    9704                 :            :                          const struct flow_grp_info *grp_info,
    9705                 :            :                          struct rte_flow_error *error)
    9706                 :            : {
    9707                 :            :         int ret;
    9708                 :            :         bool standard_translation;
    9709                 :            : 
    9710   [ #  #  #  # ]:          0 :         if (!grp_info->skip_scale && grp_info->external &&
    9711                 :            :             group < MLX5_MAX_TABLES_EXTERNAL)
    9712                 :          0 :                 group *= MLX5_FLOW_TABLE_FACTOR;
    9713         [ #  # ]:          0 :         if (is_tunnel_offload_active(dev)) {
    9714                 :          0 :                 standard_translation = !grp_info->external ||
    9715                 :            :                                         grp_info->std_tbl_fix;
    9716                 :            :         } else {
    9717                 :            :                 standard_translation = true;
    9718                 :            :         }
    9719         [ #  # ]:          0 :         DRV_LOG(DEBUG,
    9720                 :            :                 "port %u group=%u transfer=%d external=%d fdb_def_rule=%d translate=%s",
    9721                 :            :                 dev->data->port_id, group, grp_info->transfer,
    9722                 :            :                 grp_info->external, grp_info->fdb_def_rule,
    9723                 :            :                 standard_translation ? "STANDARD" : "TUNNEL");
    9724         [ #  # ]:          0 :         if (standard_translation)
    9725                 :          0 :                 ret = flow_group_to_table(dev->data->port_id, group, table,
    9726                 :            :                                           grp_info, error);
    9727                 :            :         else
    9728                 :          0 :                 ret = tunnel_flow_group_to_flow_table(dev, tunnel, group,
    9729                 :            :                                                       table, error);
    9730                 :            : 
    9731                 :          0 :         return ret;
    9732                 :            : }
    9733                 :            : 
    9734                 :            : /**
    9735                 :            :  * Discover availability of metadata reg_c's.
    9736                 :            :  *
    9737                 :            :  * Iteratively use test flows to check availability.
    9738                 :            :  *
    9739                 :            :  * @param[in] dev
    9740                 :            :  *   Pointer to the Ethernet device structure.
    9741                 :            :  *
    9742                 :            :  * @return
    9743                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
    9744                 :            :  */
    9745                 :            : int
    9746                 :          0 : mlx5_flow_discover_mreg_c(struct rte_eth_dev *dev)
    9747                 :            : {
    9748                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    9749                 :            :         enum modify_reg idx;
    9750                 :            :         int n = 0;
    9751                 :            : 
    9752                 :            :         /* reg_c[0] and reg_c[1] are reserved. */
    9753                 :          0 :         priv->sh->flow_mreg_c[n++] = REG_C_0;
    9754                 :          0 :         priv->sh->flow_mreg_c[n++] = REG_C_1;
    9755                 :            :         /* Discover availability of other reg_c's. */
    9756         [ #  # ]:          0 :         for (idx = REG_C_2; idx <= REG_C_7; ++idx) {
    9757                 :          0 :                 struct rte_flow_attr attr = {
    9758                 :            :                         .group = MLX5_FLOW_MREG_CP_TABLE_GROUP,
    9759                 :            :                         .priority = MLX5_FLOW_LOWEST_PRIO_INDICATOR,
    9760                 :            :                         .ingress = 1,
    9761                 :            :                 };
    9762                 :          0 :                 struct rte_flow_item items[] = {
    9763                 :            :                         [0] = {
    9764                 :            :                                 .type = RTE_FLOW_ITEM_TYPE_END,
    9765                 :            :                         },
    9766                 :            :                 };
    9767                 :          0 :                 struct rte_flow_action actions[] = {
    9768                 :            :                         [0] = {
    9769                 :            :                                 .type = (enum rte_flow_action_type)
    9770                 :            :                                         MLX5_RTE_FLOW_ACTION_TYPE_COPY_MREG,
    9771                 :          0 :                                 .conf = &(struct mlx5_flow_action_copy_mreg){
    9772                 :            :                                         .src = REG_C_1,
    9773                 :            :                                         .dst = idx,
    9774                 :            :                                 },
    9775                 :            :                         },
    9776                 :            :                         [1] = {
    9777                 :            :                                 .type = RTE_FLOW_ACTION_TYPE_JUMP,
    9778                 :          0 :                                 .conf = &(struct rte_flow_action_jump){
    9779                 :            :                                         .group = MLX5_FLOW_MREG_ACT_TABLE_GROUP,
    9780                 :            :                                 },
    9781                 :            :                         },
    9782                 :            :                         [2] = {
    9783                 :            :                                 .type = RTE_FLOW_ACTION_TYPE_END,
    9784                 :            :                         },
    9785                 :            :                 };
    9786                 :            :                 uint32_t flow_idx;
    9787                 :            :                 struct rte_flow *flow;
    9788                 :            :                 struct rte_flow_error error;
    9789                 :            : 
    9790         [ #  # ]:          0 :                 if (!priv->sh->config.dv_flow_en)
    9791                 :            :                         break;
    9792                 :            :                 /* Create internal flow, validation skips copy action. */
    9793                 :          0 :                 flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr,
    9794                 :            :                                         items, actions, false, &error);
    9795                 :          0 :                 flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
    9796                 :            :                                       flow_idx);
    9797         [ #  # ]:          0 :                 if (!flow)
    9798                 :          0 :                         continue;
    9799                 :          0 :                 priv->sh->flow_mreg_c[n++] = idx;
    9800                 :          0 :                 flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
    9801                 :            :         }
    9802         [ #  # ]:          0 :         for (; n < MLX5_MREG_C_NUM; ++n)
    9803                 :          0 :                 priv->sh->flow_mreg_c[n] = REG_NON;
    9804                 :          0 :         priv->sh->metadata_regc_check_flag = 1;
    9805                 :          0 :         return 0;
    9806                 :            : }
    9807                 :            : 
    9808                 :            : int
    9809   [ #  #  #  # ]:          0 : save_dump_file(const uint8_t *data, uint32_t size,
    9810                 :            :         uint32_t type, uint64_t id, void *arg, FILE *file)
    9811                 :            : {
    9812                 :            :         char line[BUF_SIZE];
    9813                 :            :         uint32_t out = 0;
    9814                 :            :         uint32_t k;
    9815                 :            :         uint32_t actions_num;
    9816                 :            :         struct rte_flow_query_count *count;
    9817                 :            : 
    9818                 :            :         memset(line, 0, BUF_SIZE);
    9819   [ #  #  #  # ]:          0 :         switch (type) {
    9820                 :          0 :         case DR_DUMP_REC_TYPE_PMD_MODIFY_HDR:
    9821                 :          0 :                 actions_num = *(uint32_t *)(arg);
    9822                 :          0 :                 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",%d,",
    9823                 :            :                                 type, id, actions_num);
    9824                 :          0 :                 break;
    9825                 :          0 :         case DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT:
    9826                 :          0 :                 out += snprintf(line + out, BUF_SIZE - out, "%d,0x%" PRIx64 ",",
    9827                 :            :                                 type, id);
    9828                 :          0 :                 break;
    9829                 :          0 :         case DR_DUMP_REC_TYPE_PMD_COUNTER:
    9830                 :            :                 count = (struct rte_flow_query_count *)arg;
    9831                 :          0 :                 fprintf(file,
    9832                 :            :                         "%d,0x%" PRIx64 ",%" PRIu64 ",%" PRIu64 "\n",
    9833                 :            :                         type, id, count->hits, count->bytes);
    9834                 :          0 :                 return 0;
    9835                 :            :         default:
    9836                 :            :                 return -1;
    9837                 :            :         }
    9838                 :            : 
    9839         [ #  # ]:          0 :         for (k = 0; k < size; k++) {
    9840                 :            :                 /* Make sure we do not overrun the line buffer length. */
    9841         [ #  # ]:          0 :                 if (out >= BUF_SIZE - 4) {
    9842                 :          0 :                         line[out] = '\0';
    9843                 :          0 :                         break;
    9844                 :            :                 }
    9845                 :          0 :                 out += snprintf(line + out, BUF_SIZE - out, "%02x",
    9846                 :          0 :                                 (data[k]) & 0xff);
    9847                 :            :         }
    9848                 :            :         fprintf(file, "%s\n", line);
    9849                 :          0 :         return 0;
    9850                 :            : }
    9851                 :            : 
    9852                 :            : int
    9853                 :          0 : mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
    9854                 :            :         struct rte_flow_query_count *count, struct rte_flow_error *error)
    9855                 :            : {
    9856                 :            :         struct rte_flow_action action[2];
    9857                 :            :         enum mlx5_flow_drv_type ftype;
    9858                 :            :         const struct mlx5_flow_driver_ops *fops;
    9859                 :            : 
    9860         [ #  # ]:          0 :         if (!flow) {
    9861                 :          0 :                 return rte_flow_error_set(error, ENOENT,
    9862                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9863                 :            :                                 NULL,
    9864                 :            :                                 "invalid flow handle");
    9865                 :            :         }
    9866                 :          0 :         action[0].type = RTE_FLOW_ACTION_TYPE_COUNT;
    9867                 :          0 :         action[1].type = RTE_FLOW_ACTION_TYPE_END;
    9868         [ #  # ]:          0 :         if (flow->counter) {
    9869                 :            :                 memset(count, 0, sizeof(struct rte_flow_query_count));
    9870                 :          0 :                 ftype = (enum mlx5_flow_drv_type)(flow->drv_type);
    9871                 :            :                 MLX5_ASSERT(ftype > MLX5_FLOW_TYPE_MIN &&
    9872                 :            :                                                 ftype < MLX5_FLOW_TYPE_MAX);
    9873                 :          0 :                 fops = flow_get_drv_ops(ftype);
    9874                 :          0 :                 return fops->query(dev, flow, action, count, error);
    9875                 :            :         }
    9876                 :            :         return -1;
    9877                 :            : }
    9878                 :            : 
    9879                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
    9880                 :            : /**
    9881                 :            :  * Dump flow ipool data to file
    9882                 :            :  *
    9883                 :            :  * @param[in] dev
    9884                 :            :  *   The pointer to Ethernet device.
    9885                 :            :  * @param[in] file
    9886                 :            :  *   A pointer to a file for output.
    9887                 :            :  * @param[out] error
    9888                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
    9889                 :            :  *   structure in case of error only.
    9890                 :            :  * @return
    9891                 :            :  *   0 on success, a negative value otherwise.
    9892                 :            :  */
    9893                 :            : int
    9894                 :          0 : mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev,
    9895                 :            :         struct rte_flow *flow, FILE *file,
    9896                 :            :         struct rte_flow_error *error)
    9897                 :            : {
    9898                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    9899                 :            :         struct mlx5_flow_dv_modify_hdr_resource  *modify_hdr;
    9900                 :            :         struct mlx5_flow_dv_encap_decap_resource *encap_decap;
    9901                 :            :         uint32_t handle_idx;
    9902                 :            :         struct mlx5_flow_handle *dh;
    9903                 :            :         struct rte_flow_query_count count;
    9904                 :            :         uint32_t actions_num;
    9905                 :            :         const uint8_t *data;
    9906                 :            :         size_t size;
    9907                 :            :         uint64_t id;
    9908                 :            :         uint32_t type;
    9909                 :          0 :         void *action = NULL;
    9910                 :            : 
    9911         [ #  # ]:          0 :         if (!flow) {
    9912                 :          0 :                 return rte_flow_error_set(error, ENOENT,
    9913                 :            :                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
    9914                 :            :                                 NULL,
    9915                 :            :                                 "invalid flow handle");
    9916                 :            :         }
    9917                 :          0 :         handle_idx = flow->dev_handles;
    9918                 :            :         /* query counter */
    9919   [ #  #  #  # ]:          0 :         if (flow->counter &&
    9920                 :          0 :         (!mlx5_counter_query(dev, flow->counter, false,
    9921         [ #  # ]:          0 :         &count.hits, &count.bytes, &action)) && action) {
    9922                 :          0 :                 id = (uint64_t)(uintptr_t)action;
    9923                 :            :                 type = DR_DUMP_REC_TYPE_PMD_COUNTER;
    9924                 :          0 :                 save_dump_file(NULL, 0, type,
    9925                 :            :                         id, (void *)&count, file);
    9926                 :            :         }
    9927                 :            : 
    9928         [ #  # ]:          0 :         while (handle_idx) {
    9929                 :          0 :                 dh = mlx5_ipool_get(priv->sh->ipool
    9930                 :            :                                 [MLX5_IPOOL_MLX5_FLOW], handle_idx);
    9931         [ #  # ]:          0 :                 if (!dh)
    9932                 :          0 :                         continue;
    9933                 :          0 :                 handle_idx = dh->next.next;
    9934                 :            : 
    9935                 :            :                 /* Get modify_hdr and encap_decap buf from ipools. */
    9936                 :            :                 encap_decap = NULL;
    9937                 :          0 :                 modify_hdr = dh->dvh.modify_hdr;
    9938                 :            : 
    9939         [ #  # ]:          0 :                 if (dh->dvh.rix_encap_decap) {
    9940                 :          0 :                         encap_decap = mlx5_ipool_get(priv->sh->ipool
    9941                 :            :                                                 [MLX5_IPOOL_DECAP_ENCAP],
    9942                 :            :                                                 dh->dvh.rix_encap_decap);
    9943                 :            :                 }
    9944         [ #  # ]:          0 :                 if (modify_hdr) {
    9945                 :          0 :                         data = (const uint8_t *)modify_hdr->actions;
    9946                 :          0 :                         size = (size_t)(modify_hdr->actions_num) * 8;
    9947                 :          0 :                         id = (uint64_t)(uintptr_t)modify_hdr->action;
    9948                 :          0 :                         actions_num = modify_hdr->actions_num;
    9949                 :            :                         type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
    9950                 :          0 :                         save_dump_file(data, size, type, id,
    9951                 :            :                                                 (void *)(&actions_num), file);
    9952                 :            :                 }
    9953         [ #  # ]:          0 :                 if (encap_decap) {
    9954                 :          0 :                         data = encap_decap->buf;
    9955                 :          0 :                         size = encap_decap->size;
    9956                 :          0 :                         id = (uint64_t)(uintptr_t)encap_decap->action;
    9957                 :            :                         type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
    9958                 :          0 :                         save_dump_file(data, size, type,
    9959                 :            :                                                 id, NULL, file);
    9960                 :            :                 }
    9961                 :            :         }
    9962                 :            :         return 0;
    9963                 :            : }
    9964                 :            : 
    9965                 :            : /**
    9966                 :            :  * Dump all flow's encap_decap/modify_hdr/counter data to file
    9967                 :            :  *
    9968                 :            :  * @param[in] dev
    9969                 :            :  *   The pointer to Ethernet device.
    9970                 :            :  * @param[in] file
    9971                 :            :  *   A pointer to a file for output.
    9972                 :            :  * @param[out] error
    9973                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
    9974                 :            :  *   structure in case of error only.
    9975                 :            :  * @return
    9976                 :            :  *   0 on success, a negative value otherwise.
    9977                 :            :  */
    9978                 :            : static int
    9979                 :          0 : mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
    9980                 :            :         FILE *file, struct rte_flow_error *error __rte_unused)
    9981                 :            : {
    9982                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
    9983                 :          0 :         struct mlx5_dev_ctx_shared *sh = priv->sh;
    9984                 :            :         struct mlx5_hlist *h;
    9985                 :            :         struct mlx5_flow_dv_modify_hdr_resource  *modify_hdr;
    9986                 :            :         struct mlx5_flow_dv_encap_decap_resource *encap_decap;
    9987                 :            :         struct rte_flow_query_count count;
    9988                 :            :         uint32_t actions_num;
    9989                 :            :         const uint8_t *data;
    9990                 :            :         size_t size;
    9991                 :            :         uint64_t id;
    9992                 :            :         uint32_t type;
    9993                 :            :         uint32_t i;
    9994                 :            :         uint32_t j;
    9995                 :            :         struct mlx5_list_inconst *l_inconst;
    9996                 :            :         struct mlx5_list_entry *e;
    9997                 :            :         int lcore_index;
    9998                 :            :         struct mlx5_flow_counter_mng *cmng = &priv->sh->sws_cmng;
    9999                 :            :         uint32_t max;
   10000                 :            :         void *action;
   10001                 :            : 
   10002                 :            :         /* encap_decap hlist is lcore_share, get global core cache. */
   10003                 :            :         i = MLX5_LIST_GLOBAL;
   10004                 :          0 :         h = sh->encaps_decaps;
   10005         [ #  # ]:          0 :         if (h) {
   10006         [ #  # ]:          0 :                 for (j = 0; j <= h->mask; j++) {
   10007                 :            :                         l_inconst = &h->buckets[j].l;
   10008         [ #  # ]:          0 :                         if (!l_inconst || !l_inconst->cache[i])
   10009                 :          0 :                                 continue;
   10010                 :            : 
   10011                 :          0 :                         e = LIST_FIRST(&l_inconst->cache[i]->h);
   10012         [ #  # ]:          0 :                         while (e) {
   10013                 :            :                                 encap_decap =
   10014                 :            :                                 (struct mlx5_flow_dv_encap_decap_resource *)e;
   10015                 :          0 :                                 data = encap_decap->buf;
   10016                 :          0 :                                 size = encap_decap->size;
   10017                 :          0 :                                 id = (uint64_t)(uintptr_t)encap_decap->action;
   10018                 :            :                                 type = DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT;
   10019                 :          0 :                                 save_dump_file(data, size, type,
   10020                 :            :                                         id, NULL, file);
   10021                 :          0 :                                 e = LIST_NEXT(e, next);
   10022                 :            :                         }
   10023                 :            :                 }
   10024                 :            :         }
   10025                 :            : 
   10026                 :            :         /* get modify_hdr */
   10027                 :          0 :         h = sh->modify_cmds;
   10028         [ #  # ]:          0 :         if (h) {
   10029                 :          0 :                 lcore_index = rte_lcore_index(rte_lcore_id());
   10030         [ #  # ]:          0 :                 if (unlikely(lcore_index == -1)) {
   10031                 :            :                         lcore_index = MLX5_LIST_NLCORE;
   10032                 :          0 :                         rte_spinlock_lock(&h->l_const.lcore_lock);
   10033                 :            :                 }
   10034                 :          0 :                 i = lcore_index;
   10035                 :            : 
   10036         [ #  # ]:          0 :                 if (lcore_index == MLX5_LIST_NLCORE) {
   10037         [ #  # ]:          0 :                         for (i = 0; i <= (uint32_t)lcore_index; i++) {
   10038         [ #  # ]:          0 :                                 for (j = 0; j <= h->mask; j++) {
   10039                 :            :                                         l_inconst = &h->buckets[j].l;
   10040         [ #  # ]:          0 :                                         if (!l_inconst || !l_inconst->cache[i])
   10041                 :          0 :                                                 continue;
   10042                 :            : 
   10043                 :          0 :                                         e = LIST_FIRST(&l_inconst->cache[i]->h);
   10044         [ #  # ]:          0 :                                         while (e) {
   10045                 :            :                                                 modify_hdr =
   10046                 :            :                                                 (struct mlx5_flow_dv_modify_hdr_resource *)e;
   10047                 :          0 :                                                 data = (const uint8_t *)modify_hdr->actions;
   10048                 :          0 :                                                 size = (size_t)(modify_hdr->actions_num) * 8;
   10049                 :          0 :                                                 actions_num = modify_hdr->actions_num;
   10050                 :          0 :                                                 id = (uint64_t)(uintptr_t)modify_hdr->action;
   10051                 :            :                                                 type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
   10052                 :          0 :                                                 save_dump_file(data, size, type, id,
   10053                 :            :                                                                 (void *)(&actions_num), file);
   10054                 :          0 :                                                 e = LIST_NEXT(e, next);
   10055                 :            :                                         }
   10056                 :            :                                 }
   10057                 :            :                         }
   10058                 :            :                 } else {
   10059         [ #  # ]:          0 :                         for (j = 0; j <= h->mask; j++) {
   10060                 :            :                                 l_inconst = &h->buckets[j].l;
   10061         [ #  # ]:          0 :                                 if (!l_inconst || !l_inconst->cache[i])
   10062                 :          0 :                                         continue;
   10063                 :            : 
   10064                 :          0 :                                 e = LIST_FIRST(&l_inconst->cache[i]->h);
   10065         [ #  # ]:          0 :                                 while (e) {
   10066                 :            :                                         modify_hdr =
   10067                 :            :                                         (struct mlx5_flow_dv_modify_hdr_resource *)e;
   10068                 :          0 :                                         data = (const uint8_t *)modify_hdr->actions;
   10069                 :          0 :                                         size = (size_t)(modify_hdr->actions_num) * 8;
   10070                 :          0 :                                         actions_num = modify_hdr->actions_num;
   10071                 :          0 :                                         id = (uint64_t)(uintptr_t)modify_hdr->action;
   10072                 :            :                                         type = DR_DUMP_REC_TYPE_PMD_MODIFY_HDR;
   10073                 :          0 :                                         save_dump_file(data, size, type, id,
   10074                 :            :                                                         (void *)(&actions_num), file);
   10075                 :          0 :                                         e = LIST_NEXT(e, next);
   10076                 :            :                                 }
   10077                 :            :                         }
   10078                 :            :                 }
   10079                 :            : 
   10080         [ #  # ]:          0 :                 if (unlikely(lcore_index == MLX5_LIST_NLCORE))
   10081                 :          0 :                         rte_spinlock_unlock(&h->l_const.lcore_lock);
   10082                 :            :         }
   10083                 :            : 
   10084                 :            :         /* get counter */
   10085                 :            :         MLX5_ASSERT(cmng->n_valid <= MLX5_COUNTER_POOLS_MAX_NUM);
   10086                 :          0 :         max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
   10087         [ #  # ]:          0 :         for (j = 1; j <= max; j++) {
   10088                 :          0 :                 action = NULL;
   10089         [ #  # ]:          0 :                 if ((!mlx5_counter_query(dev, j, false, &count.hits,
   10090         [ #  # ]:          0 :                 &count.bytes, &action)) && action) {
   10091                 :          0 :                         id = (uint64_t)(uintptr_t)action;
   10092                 :            :                         type = DR_DUMP_REC_TYPE_PMD_COUNTER;
   10093                 :          0 :                         save_dump_file(NULL, 0, type,
   10094                 :            :                                         id, (void *)&count, file);
   10095                 :            :                 }
   10096                 :            :         }
   10097                 :          0 :         return 0;
   10098                 :            : }
   10099                 :            : #endif
   10100                 :            : 
   10101                 :            : /**
   10102                 :            :  * Dump flow raw hw data to file
   10103                 :            :  *
   10104                 :            :  * @param[in] dev
   10105                 :            :  *    The pointer to Ethernet device.
   10106                 :            :  * @param[in] file
   10107                 :            :  *   A pointer to a file for output.
   10108                 :            :  * @param[out] error
   10109                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
   10110                 :            :  *   structure in case of error only.
   10111                 :            :  * @return
   10112                 :            :  *   0 on success, a negative value otherwise.
   10113                 :            :  */
   10114                 :            : int
   10115                 :          0 : mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow_idx,
   10116                 :            :                    FILE *file,
   10117                 :            :                    struct rte_flow_error *error __rte_unused)
   10118                 :            : {
   10119                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10120                 :          0 :         struct mlx5_dev_ctx_shared *sh = priv->sh;
   10121                 :            :         uint32_t handle_idx;
   10122                 :            :         int ret;
   10123                 :            :         struct mlx5_flow_handle *dh;
   10124                 :            :         struct rte_flow *flow;
   10125                 :            : 
   10126         [ #  # ]:          0 :         if (!sh->config.dv_flow_en) {
   10127         [ #  # ]:          0 :                 if (fputs("device dv flow disabled\n", file) <= 0)
   10128                 :          0 :                         return -errno;
   10129                 :            :                 return -ENOTSUP;
   10130                 :            :         }
   10131                 :            : 
   10132                 :            :         /* dump all */
   10133         [ #  # ]:          0 :         if (!flow_idx) {
   10134                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
   10135         [ #  # ]:          0 :                 if (mlx5_flow_dev_dump_sh_all(dev, file, error))
   10136                 :            :                         return -EINVAL;
   10137                 :            : 
   10138         [ #  # ]:          0 :                 if (sh->config.dv_flow_en == 2)
   10139                 :          0 :                         return mlx5dr_debug_dump(priv->dr_ctx, file);
   10140                 :            : #endif
   10141                 :          0 :                 return mlx5_devx_cmd_flow_dump(sh->fdb_domain,
   10142                 :            :                                                sh->rx_domain,
   10143                 :            :                                                sh->tx_domain, file);
   10144                 :            :         }
   10145                 :            :         /* dump one */
   10146                 :          0 :         flow = mlx5_ipool_get(priv->flows[MLX5_FLOW_TYPE_GEN],
   10147                 :            :                         (uintptr_t)(void *)flow_idx);
   10148         [ #  # ]:          0 :         if (!flow)
   10149                 :            :                 return -EINVAL;
   10150                 :            : 
   10151                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
   10152                 :          0 :         mlx5_flow_dev_dump_ipool(dev, flow, file, error);
   10153                 :            : #endif
   10154                 :          0 :         handle_idx = flow->dev_handles;
   10155         [ #  # ]:          0 :         while (handle_idx) {
   10156                 :          0 :                 dh = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MLX5_FLOW],
   10157                 :            :                                 handle_idx);
   10158         [ #  # ]:          0 :                 if (!dh)
   10159                 :            :                         return -ENOENT;
   10160         [ #  # ]:          0 :                 if (dh->drv_flow) {
   10161         [ #  # ]:          0 :                         if (sh->config.dv_flow_en == 2)
   10162                 :            :                                 return -ENOTSUP;
   10163                 :            : 
   10164                 :          0 :                         ret = mlx5_devx_cmd_flow_single_dump(dh->drv_flow,
   10165                 :            :                                                              file);
   10166         [ #  # ]:          0 :                         if (ret)
   10167                 :            :                                 return -ENOENT;
   10168                 :            :                 }
   10169                 :          0 :                 handle_idx = dh->next.next;
   10170                 :            :         }
   10171                 :            :         return 0;
   10172                 :            : }
   10173                 :            : 
   10174                 :            : /**
   10175                 :            :  * Get aged-out flows.
   10176                 :            :  *
   10177                 :            :  * @param[in] dev
   10178                 :            :  *   Pointer to the Ethernet device structure.
   10179                 :            :  * @param[in] context
   10180                 :            :  *   The address of an array of pointers to the aged-out flows contexts.
   10181                 :            :  * @param[in] nb_countexts
   10182                 :            :  *   The length of context array pointers.
   10183                 :            :  * @param[out] error
   10184                 :            :  *   Perform verbose error reporting if not NULL. Initialized in case of
   10185                 :            :  *   error only.
   10186                 :            :  *
   10187                 :            :  * @return
   10188                 :            :  *   how many contexts get in success, otherwise negative errno value.
   10189                 :            :  *   if nb_contexts is 0, return the amount of all aged contexts.
   10190                 :            :  *   if nb_contexts is not 0 , return the amount of aged flows reported
   10191                 :            :  *   in the context array.
   10192                 :            :  */
   10193                 :            : int
   10194         [ #  # ]:          0 : mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
   10195                 :            :                         uint32_t nb_contexts, struct rte_flow_error *error)
   10196                 :            : {
   10197                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10198                 :            : 
   10199                 :          0 :         return flow_get_drv_ops(flow_get_drv_type(dev, &attr))->get_aged_flows
   10200                 :            :                 (dev, contexts, nb_contexts, error);
   10201                 :            : }
   10202                 :            : 
   10203                 :            : /**
   10204                 :            :  * Get aged-out flows per HWS queue.
   10205                 :            :  *
   10206                 :            :  * @param[in] dev
   10207                 :            :  *   Pointer to the Ethernet device structure.
   10208                 :            :  * @param[in] queue_id
   10209                 :            :  *   Flow queue to query.
   10210                 :            :  * @param[in] context
   10211                 :            :  *   The address of an array of pointers to the aged-out flows contexts.
   10212                 :            :  * @param[in] nb_countexts
   10213                 :            :  *   The length of context array pointers.
   10214                 :            :  * @param[out] error
   10215                 :            :  *   Perform verbose error reporting if not NULL. Initialized in case of
   10216                 :            :  *   error only.
   10217                 :            :  *
   10218                 :            :  * @return
   10219                 :            :  *   how many contexts get in success, otherwise negative errno value.
   10220                 :            :  *   if nb_contexts is 0, return the amount of all aged contexts.
   10221                 :            :  *   if nb_contexts is not 0 , return the amount of aged flows reported
   10222                 :            :  *   in the context array.
   10223                 :            :  */
   10224                 :            : int
   10225         [ #  # ]:          0 : mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id,
   10226                 :            :                            void **contexts, uint32_t nb_contexts,
   10227                 :            :                            struct rte_flow_error *error)
   10228                 :            : {
   10229                 :            :         const struct mlx5_flow_driver_ops *fops;
   10230                 :            :         struct rte_flow_attr attr = { 0 };
   10231                 :            : 
   10232                 :            :         if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_HW) {
   10233                 :          0 :                 fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW);
   10234                 :          0 :                 return fops->get_q_aged_flows(dev, queue_id, contexts,
   10235                 :            :                                               nb_contexts, error);
   10236                 :            :         }
   10237                 :          0 :         DRV_LOG(ERR, "port %u queue %u get aged flows is not supported.",
   10238                 :            :                 dev->data->port_id, queue_id);
   10239                 :          0 :         return rte_flow_error_set(error, ENOTSUP,
   10240                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
   10241                 :            :                                   "get Q aged flows with incorrect steering mode");
   10242                 :            : }
   10243                 :            : 
   10244                 :            : /* Wrapper for driver action_validate op callback */
   10245                 :            : static int
   10246                 :          0 : flow_drv_action_validate(struct rte_eth_dev *dev,
   10247                 :            :                          const struct rte_flow_indir_action_conf *conf,
   10248                 :            :                          const struct rte_flow_action *action,
   10249                 :            :                          const struct mlx5_flow_driver_ops *fops,
   10250                 :            :                          struct rte_flow_error *error)
   10251                 :            : {
   10252                 :            :         static const char err_msg[] = "indirect action validation unsupported";
   10253                 :            : 
   10254         [ #  # ]:          0 :         if (!fops->action_validate) {
   10255                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   10256                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   10257                 :            :                                    NULL, err_msg);
   10258                 :          0 :                 return -rte_errno;
   10259                 :            :         }
   10260                 :          0 :         return fops->action_validate(dev, conf, action, error);
   10261                 :            : }
   10262                 :            : 
   10263                 :            : /**
   10264                 :            :  * Destroys the shared action by handle.
   10265                 :            :  *
   10266                 :            :  * @param dev
   10267                 :            :  *   Pointer to Ethernet device structure.
   10268                 :            :  * @param[in] handle
   10269                 :            :  *   Handle for the indirect action object to be destroyed.
   10270                 :            :  * @param[out] error
   10271                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
   10272                 :            :  *   structure in case of error only.
   10273                 :            :  *
   10274                 :            :  * @return
   10275                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10276                 :            :  *
   10277                 :            :  * @note: wrapper for driver action_create op callback.
   10278                 :            :  */
   10279                 :            : static int
   10280         [ #  # ]:          0 : mlx5_action_handle_destroy(struct rte_eth_dev *dev,
   10281                 :            :                            struct rte_flow_action_handle *handle,
   10282                 :            :                            struct rte_flow_error *error)
   10283                 :            : {
   10284                 :            :         static const char err_msg[] = "indirect action destruction unsupported";
   10285                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10286                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   10287                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   10288                 :            : 
   10289         [ #  # ]:          0 :         if (!fops->action_destroy) {
   10290                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   10291                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   10292                 :            :                                    NULL, err_msg);
   10293                 :          0 :                 return -rte_errno;
   10294                 :            :         }
   10295                 :          0 :         return fops->action_destroy(dev, handle, error);
   10296                 :            : }
   10297                 :            : 
   10298                 :            : /* Wrapper for driver action_destroy op callback */
   10299                 :            : static int
   10300                 :          0 : flow_drv_action_update(struct rte_eth_dev *dev,
   10301                 :            :                        struct rte_flow_action_handle *handle,
   10302                 :            :                        const void *update,
   10303                 :            :                        const struct mlx5_flow_driver_ops *fops,
   10304                 :            :                        struct rte_flow_error *error)
   10305                 :            : {
   10306                 :            :         static const char err_msg[] = "indirect action update unsupported";
   10307                 :            : 
   10308         [ #  # ]:          0 :         if (!fops->action_update) {
   10309                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   10310                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   10311                 :            :                                    NULL, err_msg);
   10312                 :          0 :                 return -rte_errno;
   10313                 :            :         }
   10314                 :          0 :         return fops->action_update(dev, handle, update, error);
   10315                 :            : }
   10316                 :            : 
   10317                 :            : /* Wrapper for driver action_destroy op callback */
   10318                 :            : static int
   10319                 :          0 : flow_drv_action_query(struct rte_eth_dev *dev,
   10320                 :            :                       const struct rte_flow_action_handle *handle,
   10321                 :            :                       void *data,
   10322                 :            :                       const struct mlx5_flow_driver_ops *fops,
   10323                 :            :                       struct rte_flow_error *error)
   10324                 :            : {
   10325                 :            :         static const char err_msg[] = "indirect action query unsupported";
   10326                 :            : 
   10327         [ #  # ]:          0 :         if (!fops->action_query) {
   10328                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   10329                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   10330                 :            :                                    NULL, err_msg);
   10331                 :          0 :                 return -rte_errno;
   10332                 :            :         }
   10333                 :          0 :         return fops->action_query(dev, handle, data, error);
   10334                 :            : }
   10335                 :            : 
   10336                 :            : /**
   10337                 :            :  * Create indirect action for reuse in multiple flow rules.
   10338                 :            :  *
   10339                 :            :  * @param dev
   10340                 :            :  *   Pointer to Ethernet device structure.
   10341                 :            :  * @param conf
   10342                 :            :  *   Pointer to indirect action object configuration.
   10343                 :            :  * @param[in] action
   10344                 :            :  *   Action configuration for indirect action object creation.
   10345                 :            :  * @param[out] error
   10346                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
   10347                 :            :  *   structure in case of error only.
   10348                 :            :  * @return
   10349                 :            :  *   A valid handle in case of success, NULL otherwise and rte_errno is set.
   10350                 :            :  */
   10351                 :            : static struct rte_flow_action_handle *
   10352         [ #  # ]:          0 : mlx5_action_handle_create(struct rte_eth_dev *dev,
   10353                 :            :                           const struct rte_flow_indir_action_conf *conf,
   10354                 :            :                           const struct rte_flow_action *action,
   10355                 :            :                           struct rte_flow_error *error)
   10356                 :            : {
   10357                 :            :         static const char err_msg[] = "indirect action creation unsupported";
   10358                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10359                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   10360                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   10361                 :            : 
   10362         [ #  # ]:          0 :         if (flow_drv_action_validate(dev, conf, action, fops, error))
   10363                 :            :                 return NULL;
   10364         [ #  # ]:          0 :         if (!fops->action_create) {
   10365                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   10366                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   10367                 :            :                                    NULL, err_msg);
   10368                 :          0 :                 return NULL;
   10369                 :            :         }
   10370                 :          0 :         return fops->action_create(dev, conf, action, error);
   10371                 :            : }
   10372                 :            : 
   10373                 :            : /**
   10374                 :            :  * Updates inplace the indirect action configuration pointed by *handle*
   10375                 :            :  * with the configuration provided as *update* argument.
   10376                 :            :  * The update of the indirect action configuration effects all flow rules
   10377                 :            :  * reusing the action via handle.
   10378                 :            :  *
   10379                 :            :  * @param dev
   10380                 :            :  *   Pointer to Ethernet device structure.
   10381                 :            :  * @param[in] handle
   10382                 :            :  *   Handle for the indirect action to be updated.
   10383                 :            :  * @param[in] update
   10384                 :            :  *   Action specification used to modify the action pointed by handle.
   10385                 :            :  *   *update* could be of same type with the action pointed by the *handle*
   10386                 :            :  *   handle argument, or some other structures like a wrapper, depending on
   10387                 :            :  *   the indirect action type.
   10388                 :            :  * @param[out] error
   10389                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
   10390                 :            :  *   structure in case of error only.
   10391                 :            :  *
   10392                 :            :  * @return
   10393                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10394                 :            :  */
   10395                 :            : static int
   10396         [ #  # ]:          0 : mlx5_action_handle_update(struct rte_eth_dev *dev,
   10397                 :            :                 struct rte_flow_action_handle *handle,
   10398                 :            :                 const void *update,
   10399                 :            :                 struct rte_flow_error *error)
   10400                 :            : {
   10401                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10402                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   10403                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   10404                 :            :         int ret;
   10405                 :          0 :         uint32_t act_idx = (uint32_t)(uintptr_t)handle;
   10406                 :          0 :         uint32_t type = act_idx >> MLX5_INDIRECT_ACTION_TYPE_OFFSET;
   10407                 :            : 
   10408         [ #  # ]:          0 :         switch (type) {
   10409                 :            :         case MLX5_INDIRECT_ACTION_TYPE_CT:
   10410                 :            :         case MLX5_INDIRECT_ACTION_TYPE_METER_MARK:
   10411                 :            :                 ret = 0;
   10412                 :            :                 break;
   10413                 :          0 :         default:
   10414                 :          0 :                 ret = flow_drv_action_validate(dev, NULL,
   10415                 :            :                                 (const struct rte_flow_action *)update,
   10416                 :            :                                 fops, error);
   10417                 :            :         }
   10418         [ #  # ]:          0 :         if (ret)
   10419                 :            :                 return ret;
   10420                 :          0 :         return flow_drv_action_update(dev, handle, update, fops,
   10421                 :            :                                       error);
   10422                 :            : }
   10423                 :            : 
   10424                 :            : /**
   10425                 :            :  * Query the indirect action by handle.
   10426                 :            :  *
   10427                 :            :  * This function allows retrieving action-specific data such as counters.
   10428                 :            :  * Data is gathered by special action which may be present/referenced in
   10429                 :            :  * more than one flow rule definition.
   10430                 :            :  *
   10431                 :            :  * see @RTE_FLOW_ACTION_TYPE_COUNT
   10432                 :            :  *
   10433                 :            :  * @param dev
   10434                 :            :  *   Pointer to Ethernet device structure.
   10435                 :            :  * @param[in] handle
   10436                 :            :  *   Handle for the indirect action to query.
   10437                 :            :  * @param[in, out] data
   10438                 :            :  *   Pointer to storage for the associated query data type.
   10439                 :            :  * @param[out] error
   10440                 :            :  *   Perform verbose error reporting if not NULL. PMDs initialize this
   10441                 :            :  *   structure in case of error only.
   10442                 :            :  *
   10443                 :            :  * @return
   10444                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10445                 :            :  */
   10446                 :            : static int
   10447         [ #  # ]:          0 : mlx5_action_handle_query(struct rte_eth_dev *dev,
   10448                 :            :                          const struct rte_flow_action_handle *handle,
   10449                 :            :                          void *data,
   10450                 :            :                          struct rte_flow_error *error)
   10451                 :            : {
   10452                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10453                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   10454                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   10455                 :            : 
   10456                 :          0 :         return flow_drv_action_query(dev, handle, data, fops, error);
   10457                 :            : }
   10458                 :            : 
   10459                 :            : static int
   10460         [ #  # ]:          0 : mlx5_action_handle_query_update(struct rte_eth_dev *dev,
   10461                 :            :                                 struct rte_flow_action_handle *handle,
   10462                 :            :                                 const void *update, void *query,
   10463                 :            :                                 enum rte_flow_query_update_mode qu_mode,
   10464                 :            :                                 struct rte_flow_error *error)
   10465                 :            : {
   10466                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10467                 :            :         enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
   10468                 :            :         const struct mlx5_flow_driver_ops *fops;
   10469                 :            : 
   10470                 :            :         if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
   10471                 :            :                 return rte_flow_error_set(error, ENOTSUP,
   10472                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10473                 :            :                                           NULL, "invalid driver type");
   10474                 :          0 :         fops = flow_get_drv_ops(drv_type);
   10475   [ #  #  #  # ]:          0 :         if (!fops || !fops->action_query_update)
   10476                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   10477                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10478                 :            :                                           NULL, "no query_update handler");
   10479                 :          0 :         return fops->action_query_update(dev, handle, update,
   10480                 :            :                                          query, qu_mode, error);
   10481                 :            : }
   10482                 :            : 
   10483                 :            : 
   10484                 :            : #define MLX5_DRV_FOPS_OR_ERR(dev, fops, drv_cb, ret)                           \
   10485                 :            : {                                                                              \
   10486                 :            :         struct rte_flow_attr attr = { .transfer = 0 };                         \
   10487                 :            :         enum mlx5_flow_drv_type drv_type = flow_get_drv_type((dev), &attr);    \
   10488                 :            :         if (drv_type == MLX5_FLOW_TYPE_MIN ||                                  \
   10489                 :            :             drv_type == MLX5_FLOW_TYPE_MAX) {                                  \
   10490                 :            :                 rte_flow_error_set(error, ENOTSUP,                             \
   10491                 :            :                                    RTE_FLOW_ERROR_TYPE_ACTION,                 \
   10492                 :            :                                    NULL, "invalid driver type");               \
   10493                 :            :                 return ret;                                                    \
   10494                 :            :         }                                                                      \
   10495                 :            :         (fops) = flow_get_drv_ops(drv_type);                                   \
   10496                 :            :         if (!(fops) || !(fops)->drv_cb) {                                      \
   10497                 :            :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, \
   10498                 :            :                                    NULL, "no action_list handler");            \
   10499                 :            :                 return ret;                                                    \
   10500                 :            :         }                                                                      \
   10501                 :            : }
   10502                 :            : 
   10503                 :            : static struct rte_flow_action_list_handle *
   10504         [ #  # ]:          0 : mlx5_action_list_handle_create(struct rte_eth_dev *dev,
   10505                 :            :                                const struct rte_flow_indir_action_conf *conf,
   10506                 :            :                                const struct rte_flow_action *actions,
   10507                 :            :                                struct rte_flow_error *error)
   10508                 :            : {
   10509                 :            :         const struct mlx5_flow_driver_ops *fops;
   10510                 :            : 
   10511   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_create, NULL);
   10512                 :          0 :         return fops->action_list_handle_create(dev, conf, actions, error);
   10513                 :            : }
   10514                 :            : 
   10515                 :            : static int
   10516         [ #  # ]:          0 : mlx5_action_list_handle_destroy(struct rte_eth_dev *dev,
   10517                 :            :                                 struct rte_flow_action_list_handle *handle,
   10518                 :            :                                 struct rte_flow_error *error)
   10519                 :            : {
   10520                 :            :         const struct mlx5_flow_driver_ops *fops;
   10521                 :            : 
   10522   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops, action_list_handle_destroy, ENOTSUP);
   10523                 :          0 :         return fops->action_list_handle_destroy(dev, handle, error);
   10524                 :            : }
   10525                 :            : 
   10526                 :            : static int
   10527         [ #  # ]:          0 : mlx5_flow_action_list_handle_query_update(struct rte_eth_dev *dev,
   10528                 :            :                                           const
   10529                 :            :                                           struct rte_flow_action_list_handle *handle,
   10530                 :            :                                           const void **update, void **query,
   10531                 :            :                                           enum rte_flow_query_update_mode mode,
   10532                 :            :                                           struct rte_flow_error *error)
   10533                 :            : {
   10534                 :            :         const struct mlx5_flow_driver_ops *fops;
   10535                 :            : 
   10536   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops,
   10537                 :            :                              action_list_handle_query_update, ENOTSUP);
   10538                 :          0 :         return fops->action_list_handle_query_update(dev, handle, update, query,
   10539                 :            :                                                      mode, error);
   10540                 :            : }
   10541                 :            : static int
   10542         [ #  # ]:          0 : mlx5_flow_calc_table_hash(struct rte_eth_dev *dev,
   10543                 :            :                           const struct rte_flow_template_table *table,
   10544                 :            :                           const struct rte_flow_item pattern[],
   10545                 :            :                           uint8_t pattern_template_index,
   10546                 :            :                           uint32_t *hash, struct rte_flow_error *error)
   10547                 :            : {
   10548                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10549                 :            :         enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, &attr);
   10550                 :            :         const struct mlx5_flow_driver_ops *fops;
   10551                 :            : 
   10552                 :            :         if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
   10553                 :            :                 return rte_flow_error_set(error, ENOTSUP,
   10554                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10555                 :            :                                           NULL, "invalid driver type");
   10556                 :          0 :         fops = flow_get_drv_ops(drv_type);
   10557   [ #  #  #  # ]:          0 :         if (!fops || !fops->action_query_update)
   10558                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   10559                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10560                 :            :                                           NULL, "no query_update handler");
   10561                 :          0 :         return fops->flow_calc_table_hash(dev, table, pattern, pattern_template_index,
   10562                 :            :                                           hash, error);
   10563                 :            : }
   10564                 :            : 
   10565                 :            : static int
   10566         [ #  # ]:          0 : mlx5_flow_calc_encap_hash(struct rte_eth_dev *dev,
   10567                 :            :                           const struct rte_flow_item pattern[],
   10568                 :            :                           enum rte_flow_encap_hash_field dest_field,
   10569                 :            :                           uint8_t *hash,
   10570                 :            :                           struct rte_flow_error *error)
   10571                 :            : {
   10572                 :            :         enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL);
   10573                 :            :         const struct mlx5_flow_driver_ops *fops;
   10574                 :            : 
   10575                 :            :         if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX)
   10576                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   10577                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10578                 :            :                                           NULL, "invalid driver type");
   10579                 :          0 :         fops = flow_get_drv_ops(drv_type);
   10580   [ #  #  #  # ]:          0 :         if (!fops || !fops->flow_calc_encap_hash)
   10581                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   10582                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION,
   10583                 :            :                                           NULL, "no calc encap hash handler");
   10584                 :          0 :         return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error);
   10585                 :            : }
   10586                 :            : 
   10587                 :            : static int
   10588         [ #  # ]:          0 : mlx5_template_table_resize(struct rte_eth_dev *dev,
   10589                 :            :                            struct rte_flow_template_table *table,
   10590                 :            :                            uint32_t nb_rules, struct rte_flow_error *error)
   10591                 :            : {
   10592                 :            :         const struct mlx5_flow_driver_ops *fops;
   10593                 :            : 
   10594   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize, ENOTSUP);
   10595                 :          0 :         return fops->table_resize(dev, table, nb_rules, error);
   10596                 :            : }
   10597                 :            : 
   10598                 :            : static int
   10599         [ #  # ]:          0 : mlx5_table_resize_complete(struct rte_eth_dev *dev,
   10600                 :            :                            struct rte_flow_template_table *table,
   10601                 :            :                            struct rte_flow_error *error)
   10602                 :            : {
   10603                 :            :         const struct mlx5_flow_driver_ops *fops;
   10604                 :            : 
   10605   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops, table_resize_complete, ENOTSUP);
   10606                 :          0 :         return fops->table_resize_complete(dev, table, error);
   10607                 :            : }
   10608                 :            : 
   10609                 :            : static int
   10610         [ #  # ]:          0 : mlx5_flow_async_update_resized(struct rte_eth_dev *dev, uint32_t queue,
   10611                 :            :                                const struct rte_flow_op_attr *op_attr,
   10612                 :            :                                struct rte_flow *rule, void *user_data,
   10613                 :            :                                struct rte_flow_error *error)
   10614                 :            : {
   10615                 :            :         const struct mlx5_flow_driver_ops *fops;
   10616                 :            : 
   10617   [ #  #  #  # ]:          0 :         MLX5_DRV_FOPS_OR_ERR(dev, fops, flow_update_resized, ENOTSUP);
   10618                 :          0 :         return fops->flow_update_resized(dev, queue, op_attr, rule, user_data, error);
   10619                 :            : }
   10620                 :            : 
   10621                 :            : /**
   10622                 :            :  * Destroy all indirect actions (shared RSS).
   10623                 :            :  *
   10624                 :            :  * @param dev
   10625                 :            :  *   Pointer to Ethernet device.
   10626                 :            :  *
   10627                 :            :  * @return
   10628                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10629                 :            :  */
   10630                 :            : int
   10631                 :          0 : mlx5_action_handle_flush(struct rte_eth_dev *dev)
   10632                 :            : {
   10633                 :            :         struct rte_flow_error error;
   10634                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10635                 :            :         struct mlx5_shared_action_rss *shared_rss;
   10636                 :            :         int ret = 0;
   10637                 :            :         uint32_t idx;
   10638                 :            : 
   10639   [ #  #  #  # ]:          0 :         ILIST_FOREACH(priv->sh->ipool[MLX5_IPOOL_RSS_SHARED_ACTIONS],
   10640                 :            :                       priv->rss_shared_actions, idx, shared_rss, next) {
   10641         [ #  # ]:          0 :                 ret |= mlx5_action_handle_destroy(dev,
   10642                 :          0 :                        (struct rte_flow_action_handle *)(uintptr_t)idx, &error);
   10643                 :            :         }
   10644                 :          0 :         return ret;
   10645                 :            : }
   10646                 :            : 
   10647                 :            : /**
   10648                 :            :  * Validate existing indirect actions against current device configuration
   10649                 :            :  * and attach them to device resources.
   10650                 :            :  *
   10651                 :            :  * @param dev
   10652                 :            :  *   Pointer to Ethernet device.
   10653                 :            :  *
   10654                 :            :  * @return
   10655                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10656                 :            :  */
   10657                 :            : int
   10658                 :          0 : mlx5_action_handle_attach(struct rte_eth_dev *dev)
   10659                 :            : {
   10660                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10661                 :            :         int ret = 0;
   10662                 :            :         struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
   10663                 :            : 
   10664         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
   10665                 :            :                 const char *message;
   10666                 :            :                 uint32_t queue_idx;
   10667                 :            : 
   10668                 :          0 :                 ret = mlx5_validate_rss_queues(dev, ind_tbl->queues,
   10669                 :            :                                                ind_tbl->queues_n,
   10670                 :            :                                                &message, &queue_idx);
   10671         [ #  # ]:          0 :                 if (ret != 0) {
   10672                 :          0 :                         DRV_LOG(ERR, "Port %u cannot use queue %u in RSS: %s",
   10673                 :            :                                 dev->data->port_id, ind_tbl->queues[queue_idx],
   10674                 :            :                                 message);
   10675                 :          0 :                         break;
   10676                 :            :                 }
   10677                 :            :         }
   10678         [ #  # ]:          0 :         if (ret != 0)
   10679                 :            :                 return ret;
   10680         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
   10681                 :          0 :                 ret = mlx5_ind_table_obj_attach(dev, ind_tbl);
   10682         [ #  # ]:          0 :                 if (ret != 0) {
   10683                 :          0 :                         DRV_LOG(ERR, "Port %u could not attach "
   10684                 :            :                                 "indirection table obj %p",
   10685                 :            :                                 dev->data->port_id, (void *)ind_tbl);
   10686                 :          0 :                         goto error;
   10687                 :            :                 }
   10688                 :            :         }
   10689                 :            : 
   10690                 :            :         return 0;
   10691                 :            : error:
   10692                 :            :         ind_tbl_last = ind_tbl;
   10693         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
   10694         [ #  # ]:          0 :                 if (ind_tbl == ind_tbl_last)
   10695                 :            :                         break;
   10696         [ #  # ]:          0 :                 if (mlx5_ind_table_obj_detach(dev, ind_tbl) != 0)
   10697                 :          0 :                         DRV_LOG(CRIT, "Port %u could not detach "
   10698                 :            :                                 "indirection table obj %p on rollback",
   10699                 :            :                                 dev->data->port_id, (void *)ind_tbl);
   10700                 :            :         }
   10701                 :            :         return ret;
   10702                 :            : }
   10703                 :            : 
   10704                 :            : /**
   10705                 :            :  * Detach indirect actions of the device from its resources.
   10706                 :            :  *
   10707                 :            :  * @param dev
   10708                 :            :  *   Pointer to Ethernet device.
   10709                 :            :  *
   10710                 :            :  * @return
   10711                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   10712                 :            :  */
   10713                 :            : int
   10714                 :          0 : mlx5_action_handle_detach(struct rte_eth_dev *dev)
   10715                 :            : {
   10716                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10717                 :            :         int ret = 0;
   10718                 :            :         struct mlx5_ind_table_obj *ind_tbl, *ind_tbl_last;
   10719                 :            : 
   10720         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
   10721                 :          0 :                 ret = mlx5_ind_table_obj_detach(dev, ind_tbl);
   10722         [ #  # ]:          0 :                 if (ret != 0) {
   10723                 :          0 :                         DRV_LOG(ERR, "Port %u could not detach "
   10724                 :            :                                 "indirection table obj %p",
   10725                 :            :                                 dev->data->port_id, (void *)ind_tbl);
   10726                 :          0 :                         goto error;
   10727                 :            :                 }
   10728                 :            :         }
   10729                 :            :         return 0;
   10730                 :            : error:
   10731                 :            :         ind_tbl_last = ind_tbl;
   10732         [ #  # ]:          0 :         LIST_FOREACH(ind_tbl, &priv->standalone_ind_tbls, next) {
   10733         [ #  # ]:          0 :                 if (ind_tbl == ind_tbl_last)
   10734                 :            :                         break;
   10735         [ #  # ]:          0 :                 if (mlx5_ind_table_obj_attach(dev, ind_tbl) != 0)
   10736                 :          0 :                         DRV_LOG(CRIT, "Port %u could not attach "
   10737                 :            :                                 "indirection table obj %p on rollback",
   10738                 :            :                                 dev->data->port_id, (void *)ind_tbl);
   10739                 :            :         }
   10740                 :            :         return ret;
   10741                 :            : }
   10742                 :            : 
   10743                 :            : #ifndef HAVE_MLX5DV_DR
   10744                 :            : #define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
   10745                 :            : #else
   10746                 :            : #define MLX5_DOMAIN_SYNC_FLOW \
   10747                 :            :         (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
   10748                 :            : #endif
   10749                 :            : 
   10750                 :          0 : int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
   10751                 :            : {
   10752         [ #  # ]:          0 :         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
   10753                 :            :         const struct mlx5_flow_driver_ops *fops;
   10754                 :            :         int ret;
   10755                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   10756                 :            : 
   10757                 :          0 :         fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   10758                 :          0 :         ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
   10759         [ #  # ]:          0 :         if (ret > 0)
   10760                 :          0 :                 ret = -ret;
   10761                 :          0 :         return ret;
   10762                 :            : }
   10763                 :            : 
   10764                 :            : const struct mlx5_flow_tunnel *
   10765                 :          0 : mlx5_get_tof(const struct rte_flow_item *item,
   10766                 :            :              const struct rte_flow_action *action,
   10767                 :            :              enum mlx5_tof_rule_type *rule_type)
   10768                 :            : {
   10769         [ #  # ]:          0 :         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
   10770         [ #  # ]:          0 :                 if (item->type == (typeof(item->type))
   10771                 :            :                                   MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL) {
   10772                 :          0 :                         *rule_type = MLX5_TUNNEL_OFFLOAD_MATCH_RULE;
   10773                 :          0 :                         return flow_items_to_tunnel(item);
   10774                 :            :                 }
   10775                 :            :         }
   10776         [ #  # ]:          0 :         for (; action->conf != RTE_FLOW_ACTION_TYPE_END; action++) {
   10777         [ #  # ]:          0 :                 if (action->type == (typeof(action->type))
   10778                 :            :                                     MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET) {
   10779                 :          0 :                         *rule_type = MLX5_TUNNEL_OFFLOAD_SET_RULE;
   10780                 :          0 :                         return flow_actions_to_tunnel(action);
   10781                 :            :                 }
   10782                 :            :         }
   10783                 :            :         return NULL;
   10784                 :            : }
   10785                 :            : 
   10786                 :            : /**
   10787                 :            :  * tunnel offload functionality is defined for DV environment only
   10788                 :            :  */
   10789                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
   10790                 :            : __extension__
   10791                 :            : union tunnel_offload_mark {
   10792                 :            :         uint32_t val;
   10793                 :            :         struct {
   10794                 :            :                 uint32_t app_reserve:8;
   10795                 :            :                 uint32_t table_id:15;
   10796                 :            :                 uint32_t transfer:1;
   10797                 :            :                 uint32_t _unused_:8;
   10798                 :            :         };
   10799                 :            : };
   10800                 :            : 
   10801                 :            : static bool
   10802                 :            : mlx5_access_tunnel_offload_db
   10803                 :            :         (struct rte_eth_dev *dev,
   10804                 :            :          bool (*match)(struct rte_eth_dev *,
   10805                 :            :                        struct mlx5_flow_tunnel *, const void *),
   10806                 :            :          void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
   10807                 :            :          void (*miss)(struct rte_eth_dev *, void *),
   10808                 :            :          void *ctx, bool lock_op);
   10809                 :            : 
   10810                 :            : static int
   10811                 :          0 : flow_tunnel_add_default_miss(struct rte_eth_dev *dev,
   10812                 :            :                              struct rte_flow *flow,
   10813                 :            :                              const struct rte_flow_attr *attr,
   10814                 :            :                              const struct rte_flow_action *app_actions,
   10815                 :            :                              uint32_t flow_idx,
   10816                 :            :                              const struct mlx5_flow_tunnel *tunnel,
   10817                 :            :                              struct tunnel_default_miss_ctx *ctx,
   10818                 :            :                              struct rte_flow_error *error)
   10819                 :            : {
   10820                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10821                 :            :         struct mlx5_flow *dev_flow;
   10822                 :          0 :         struct rte_flow_attr miss_attr = *attr;
   10823                 :          0 :         const struct rte_flow_item miss_items[2] = {
   10824                 :            :                 {
   10825                 :            :                         .type = RTE_FLOW_ITEM_TYPE_ETH,
   10826                 :            :                         .spec = NULL,
   10827                 :            :                         .last = NULL,
   10828                 :            :                         .mask = NULL
   10829                 :            :                 },
   10830                 :            :                 {
   10831                 :            :                         .type = RTE_FLOW_ITEM_TYPE_END,
   10832                 :            :                         .spec = NULL,
   10833                 :            :                         .last = NULL,
   10834                 :            :                         .mask = NULL
   10835                 :            :                 }
   10836                 :            :         };
   10837                 :            :         union tunnel_offload_mark mark_id;
   10838                 :            :         struct rte_flow_action_mark miss_mark;
   10839                 :          0 :         struct rte_flow_action miss_actions[3] = {
   10840                 :            :                 [0] = { .type = RTE_FLOW_ACTION_TYPE_MARK, .conf = &miss_mark },
   10841                 :            :                 [2] = { .type = RTE_FLOW_ACTION_TYPE_END,  .conf = NULL }
   10842                 :            :         };
   10843                 :            :         const struct rte_flow_action_jump *jump_data;
   10844                 :          0 :         uint32_t i, flow_table = 0; /* prevent compilation warning */
   10845                 :          0 :         struct flow_grp_info grp_info = {
   10846                 :            :                 .external = 1,
   10847                 :          0 :                 .transfer = attr->transfer,
   10848                 :          0 :                 .fdb_def_rule = !!priv->fdb_def_rule,
   10849                 :            :                 .std_tbl_fix = 0,
   10850                 :            :         };
   10851                 :            :         int ret;
   10852                 :            : 
   10853         [ #  # ]:          0 :         if (!attr->transfer) {
   10854                 :            :                 uint32_t q_size;
   10855                 :            : 
   10856                 :          0 :                 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_RSS;
   10857                 :          0 :                 q_size = priv->reta_idx_n * sizeof(ctx->queue[0]);
   10858                 :          0 :                 ctx->queue = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, q_size,
   10859                 :            :                                          0, SOCKET_ID_ANY);
   10860         [ #  # ]:          0 :                 if (!ctx->queue)
   10861                 :          0 :                         return rte_flow_error_set
   10862                 :            :                                 (error, ENOMEM,
   10863                 :            :                                 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
   10864                 :            :                                 NULL, "invalid default miss RSS");
   10865                 :          0 :                 ctx->action_rss.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
   10866                 :          0 :                 ctx->action_rss.level = 0,
   10867                 :          0 :                 ctx->action_rss.types = priv->rss_conf.rss_hf,
   10868                 :          0 :                 ctx->action_rss.key_len = priv->rss_conf.rss_key_len,
   10869                 :          0 :                 ctx->action_rss.queue_num = priv->reta_idx_n,
   10870                 :          0 :                 ctx->action_rss.key = priv->rss_conf.rss_key,
   10871                 :          0 :                 ctx->action_rss.queue = ctx->queue;
   10872   [ #  #  #  # ]:          0 :                 if (!priv->reta_idx_n || !priv->rxqs_n)
   10873                 :          0 :                         return rte_flow_error_set
   10874                 :            :                                 (error, EINVAL,
   10875                 :            :                                 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
   10876                 :            :                                 NULL, "invalid port configuration");
   10877         [ #  # ]:          0 :                 if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
   10878                 :          0 :                         ctx->action_rss.types = 0;
   10879         [ #  # ]:          0 :                 for (i = 0; i != priv->reta_idx_n; ++i)
   10880                 :          0 :                         ctx->queue[i] = (*priv->reta_idx)[i];
   10881                 :            :         } else {
   10882                 :          0 :                 miss_actions[1].type = RTE_FLOW_ACTION_TYPE_JUMP;
   10883                 :          0 :                 ctx->miss_jump.group = MLX5_TNL_MISS_FDB_JUMP_GRP;
   10884                 :            :         }
   10885                 :          0 :         miss_actions[1].conf = (typeof(miss_actions[1].conf))ctx->raw;
   10886         [ #  # ]:          0 :         for (; app_actions->type != RTE_FLOW_ACTION_TYPE_JUMP; app_actions++);
   10887                 :          0 :         jump_data = app_actions->conf;
   10888                 :          0 :         miss_attr.priority = MLX5_TNL_MISS_RULE_PRIORITY;
   10889                 :          0 :         miss_attr.group = jump_data->group;
   10890                 :          0 :         ret = mlx5_flow_group_to_table(dev, tunnel, jump_data->group,
   10891                 :            :                                        &flow_table, &grp_info, error);
   10892         [ #  # ]:          0 :         if (ret)
   10893                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   10894                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF,
   10895                 :            :                                           NULL, "invalid tunnel id");
   10896                 :          0 :         mark_id.app_reserve = 0;
   10897                 :          0 :         mark_id.table_id = tunnel_flow_tbl_to_id(flow_table);
   10898                 :          0 :         mark_id.transfer = !!attr->transfer;
   10899                 :          0 :         mark_id._unused_ = 0;
   10900                 :          0 :         miss_mark.id = mark_id.val;
   10901                 :            :         dev_flow = flow_drv_prepare(dev, flow, &miss_attr,
   10902                 :            :                                     miss_items, miss_actions, flow_idx, error);
   10903         [ #  # ]:          0 :         if (!dev_flow)
   10904                 :          0 :                 return -rte_errno;
   10905                 :          0 :         dev_flow->flow = flow;
   10906                 :          0 :         dev_flow->external = true;
   10907                 :          0 :         dev_flow->tunnel = tunnel;
   10908                 :          0 :         dev_flow->tof_type = MLX5_TUNNEL_OFFLOAD_MISS_RULE;
   10909                 :            :         /* Subflow object was created, we must include one in the list. */
   10910                 :          0 :         SILIST_INSERT(&flow->dev_handles, dev_flow->handle_idx,
   10911                 :            :                       dev_flow->handle, next);
   10912                 :          0 :         DRV_LOG(DEBUG,
   10913                 :            :                 "port %u tunnel type=%d id=%u miss rule priority=%u group=%u",
   10914                 :            :                 dev->data->port_id, tunnel->app_tunnel.type,
   10915                 :            :                 tunnel->tunnel_id, miss_attr.priority, miss_attr.group);
   10916                 :            :         ret = flow_drv_translate(dev, dev_flow, &miss_attr, miss_items,
   10917                 :            :                                   miss_actions, error);
   10918         [ #  # ]:          0 :         if (!ret)
   10919                 :          0 :                 ret = flow_mreg_update_copy_table(dev, flow, miss_actions,
   10920                 :            :                                                   error);
   10921                 :            : 
   10922                 :            :         return ret;
   10923                 :            : }
   10924                 :            : 
   10925                 :            : static const struct mlx5_flow_tbl_data_entry  *
   10926                 :          0 : tunnel_mark_decode(struct rte_eth_dev *dev, uint32_t mark)
   10927                 :            : {
   10928                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   10929                 :          0 :         struct mlx5_dev_ctx_shared *sh = priv->sh;
   10930                 :            :         struct mlx5_list_entry *he;
   10931                 :          0 :         union tunnel_offload_mark mbits = { .val = mark };
   10932                 :          0 :         union mlx5_flow_tbl_key table_key = {
   10933                 :            :                 {
   10934                 :          0 :                         .level = tunnel_id_to_flow_tbl(mbits.table_id),
   10935                 :            :                         .id = 0,
   10936                 :            :                         .reserved = 0,
   10937                 :            :                         .dummy = 0,
   10938                 :          0 :                         .is_fdb = !!mbits.transfer,
   10939                 :            :                         .is_egress = 0,
   10940                 :            :                 }
   10941                 :            :         };
   10942                 :          0 :         struct mlx5_flow_cb_ctx ctx = {
   10943                 :            :                 .data = &table_key.v64,
   10944                 :            :         };
   10945                 :            : 
   10946                 :          0 :         he = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64, &ctx);
   10947                 :            :         return he ?
   10948         [ #  # ]:          0 :                container_of(he, struct mlx5_flow_tbl_data_entry, entry) : NULL;
   10949                 :            : }
   10950                 :            : 
   10951                 :            : static void
   10952                 :          0 : mlx5_flow_tunnel_grp2tbl_remove_cb(void *tool_ctx,
   10953                 :            :                                    struct mlx5_list_entry *entry)
   10954                 :            : {
   10955                 :            :         struct mlx5_dev_ctx_shared *sh = tool_ctx;
   10956                 :            :         struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
   10957                 :            : 
   10958                 :          0 :         mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
   10959                 :            :                         tunnel_flow_tbl_to_id(tte->flow_table));
   10960                 :          0 :         mlx5_free(tte);
   10961                 :          0 : }
   10962                 :            : 
   10963                 :            : static int
   10964                 :          0 : mlx5_flow_tunnel_grp2tbl_match_cb(void *tool_ctx __rte_unused,
   10965                 :            :                                   struct mlx5_list_entry *entry, void *cb_ctx)
   10966                 :            : {
   10967                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
   10968                 :            :         union tunnel_tbl_key tbl = {
   10969                 :          0 :                 .val = *(uint64_t *)(ctx->data),
   10970                 :            :         };
   10971                 :            :         struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
   10972                 :            : 
   10973   [ #  #  #  # ]:          0 :         return tbl.tunnel_id != tte->tunnel_id || tbl.group != tte->group;
   10974                 :            : }
   10975                 :            : 
   10976                 :            : static struct mlx5_list_entry *
   10977                 :          0 : mlx5_flow_tunnel_grp2tbl_create_cb(void *tool_ctx, void *cb_ctx)
   10978                 :            : {
   10979                 :            :         struct mlx5_dev_ctx_shared *sh = tool_ctx;
   10980                 :            :         struct mlx5_flow_cb_ctx *ctx = cb_ctx;
   10981                 :            :         struct tunnel_tbl_entry *tte;
   10982                 :            :         union tunnel_tbl_key tbl = {
   10983                 :          0 :                 .val = *(uint64_t *)(ctx->data),
   10984                 :            :         };
   10985                 :            : 
   10986                 :          0 :         tte = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO,
   10987                 :            :                           sizeof(*tte), 0,
   10988                 :            :                           SOCKET_ID_ANY);
   10989         [ #  # ]:          0 :         if (!tte)
   10990                 :          0 :                 goto err;
   10991                 :          0 :         mlx5_ipool_malloc(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
   10992                 :            :                           &tte->flow_table);
   10993         [ #  # ]:          0 :         if (tte->flow_table >= MLX5_MAX_TABLES) {
   10994                 :          0 :                 DRV_LOG(ERR, "Tunnel TBL ID %d exceed max limit.",
   10995                 :            :                         tte->flow_table);
   10996                 :          0 :                 mlx5_ipool_free(sh->ipool[MLX5_IPOOL_TNL_TBL_ID],
   10997                 :            :                                 tte->flow_table);
   10998                 :          0 :                 goto err;
   10999         [ #  # ]:          0 :         } else if (!tte->flow_table) {
   11000                 :          0 :                 goto err;
   11001                 :            :         }
   11002                 :          0 :         tte->flow_table = tunnel_id_to_flow_tbl(tte->flow_table);
   11003                 :          0 :         tte->tunnel_id = tbl.tunnel_id;
   11004                 :          0 :         tte->group = tbl.group;
   11005                 :          0 :         return &tte->hash;
   11006                 :          0 : err:
   11007         [ #  # ]:          0 :         if (tte)
   11008                 :          0 :                 mlx5_free(tte);
   11009                 :            :         return NULL;
   11010                 :            : }
   11011                 :            : 
   11012                 :            : static struct mlx5_list_entry *
   11013                 :          0 : mlx5_flow_tunnel_grp2tbl_clone_cb(void *tool_ctx __rte_unused,
   11014                 :            :                                   struct mlx5_list_entry *oentry,
   11015                 :            :                                   void *cb_ctx __rte_unused)
   11016                 :            : {
   11017                 :          0 :         struct tunnel_tbl_entry *tte = mlx5_malloc(MLX5_MEM_SYS, sizeof(*tte),
   11018                 :            :                                                    0, SOCKET_ID_ANY);
   11019                 :            : 
   11020         [ #  # ]:          0 :         if (!tte)
   11021                 :            :                 return NULL;
   11022                 :            :         memcpy(tte, oentry, sizeof(*tte));
   11023                 :          0 :         return &tte->hash;
   11024                 :            : }
   11025                 :            : 
   11026                 :            : static void
   11027                 :          0 : mlx5_flow_tunnel_grp2tbl_clone_free_cb(void *tool_ctx __rte_unused,
   11028                 :            :                                        struct mlx5_list_entry *entry)
   11029                 :            : {
   11030                 :            :         struct tunnel_tbl_entry *tte = container_of(entry, typeof(*tte), hash);
   11031                 :            : 
   11032                 :          0 :         mlx5_free(tte);
   11033                 :          0 : }
   11034                 :            : 
   11035                 :            : static uint32_t
   11036                 :          0 : tunnel_flow_group_to_flow_table(struct rte_eth_dev *dev,
   11037                 :            :                                 const struct mlx5_flow_tunnel *tunnel,
   11038                 :            :                                 uint32_t group, uint32_t *table,
   11039                 :            :                                 struct rte_flow_error *error)
   11040                 :            : {
   11041                 :            :         struct mlx5_list_entry *he;
   11042                 :            :         struct tunnel_tbl_entry *tte;
   11043         [ #  # ]:          0 :         union tunnel_tbl_key key = {
   11044         [ #  # ]:          0 :                 .tunnel_id = tunnel ? tunnel->tunnel_id : 0,
   11045                 :            :                 .group = group
   11046                 :            :         };
   11047                 :            :         struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
   11048                 :            :         struct mlx5_hlist *group_hash;
   11049                 :          0 :         struct mlx5_flow_cb_ctx ctx = {
   11050                 :            :                 .data = &key.val,
   11051                 :            :         };
   11052                 :            : 
   11053         [ #  # ]:          0 :         group_hash = tunnel ? tunnel->groups : thub->groups;
   11054                 :          0 :         he = mlx5_hlist_register(group_hash, key.val, &ctx);
   11055         [ #  # ]:          0 :         if (!he)
   11056                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   11057                 :            :                                           RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
   11058                 :            :                                           NULL,
   11059                 :            :                                           "tunnel group index not supported");
   11060                 :            :         tte = container_of(he, typeof(*tte), hash);
   11061                 :          0 :         *table = tte->flow_table;
   11062                 :          0 :         DRV_LOG(DEBUG, "port %u tunnel %u group=%#x table=%#x",
   11063                 :            :                 dev->data->port_id, key.tunnel_id, group, *table);
   11064                 :          0 :         return 0;
   11065                 :            : }
   11066                 :            : 
   11067                 :            : static void
   11068                 :          0 : mlx5_flow_tunnel_free(struct rte_eth_dev *dev,
   11069                 :            :                       struct mlx5_flow_tunnel *tunnel)
   11070                 :            : {
   11071                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11072                 :            :         struct mlx5_indexed_pool *ipool;
   11073                 :            : 
   11074                 :          0 :         DRV_LOG(DEBUG, "port %u release pmd tunnel id=0x%x",
   11075                 :            :                 dev->data->port_id, tunnel->tunnel_id);
   11076         [ #  # ]:          0 :         LIST_REMOVE(tunnel, chain);
   11077                 :          0 :         mlx5_hlist_destroy(tunnel->groups);
   11078                 :          0 :         ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
   11079                 :          0 :         mlx5_ipool_free(ipool, tunnel->tunnel_id);
   11080                 :          0 : }
   11081                 :            : 
   11082                 :            : static bool
   11083                 :          0 : mlx5_access_tunnel_offload_db
   11084                 :            :         (struct rte_eth_dev *dev,
   11085                 :            :          bool (*match)(struct rte_eth_dev *,
   11086                 :            :                        struct mlx5_flow_tunnel *, const void *),
   11087                 :            :          void (*hit)(struct rte_eth_dev *, struct mlx5_flow_tunnel *, void *),
   11088                 :            :          void (*miss)(struct rte_eth_dev *, void *),
   11089                 :            :          void *ctx, bool lock_op)
   11090                 :            : {
   11091                 :            :         bool verdict = false;
   11092                 :            :         struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
   11093                 :            :         struct mlx5_flow_tunnel *tunnel;
   11094                 :            : 
   11095                 :          0 :         rte_spinlock_lock(&thub->sl);
   11096         [ #  # ]:          0 :         LIST_FOREACH(tunnel, &thub->tunnels, chain) {
   11097                 :          0 :                 verdict = match(dev, tunnel, (const void *)ctx);
   11098         [ #  # ]:          0 :                 if (verdict)
   11099                 :            :                         break;
   11100                 :            :         }
   11101         [ #  # ]:          0 :         if (!lock_op)
   11102                 :            :                 rte_spinlock_unlock(&thub->sl);
   11103         [ #  # ]:          0 :         if (verdict && hit)
   11104                 :          0 :                 hit(dev, tunnel, ctx);
   11105         [ #  # ]:          0 :         if (!verdict && miss)
   11106                 :          0 :                 miss(dev, ctx);
   11107         [ #  # ]:          0 :         if (lock_op)
   11108                 :            :                 rte_spinlock_unlock(&thub->sl);
   11109                 :            : 
   11110                 :          0 :         return verdict;
   11111                 :            : }
   11112                 :            : 
   11113                 :            : struct tunnel_db_find_tunnel_id_ctx {
   11114                 :            :         uint32_t tunnel_id;
   11115                 :            :         struct mlx5_flow_tunnel *tunnel;
   11116                 :            : };
   11117                 :            : 
   11118                 :            : static bool
   11119                 :          0 : find_tunnel_id_match(struct rte_eth_dev *dev,
   11120                 :            :                      struct mlx5_flow_tunnel *tunnel, const void *x)
   11121                 :            : {
   11122                 :            :         const struct tunnel_db_find_tunnel_id_ctx *ctx = x;
   11123                 :            : 
   11124                 :            :         RTE_SET_USED(dev);
   11125                 :          0 :         return tunnel->tunnel_id == ctx->tunnel_id;
   11126                 :            : }
   11127                 :            : 
   11128                 :            : static void
   11129                 :          0 : find_tunnel_id_hit(struct rte_eth_dev *dev,
   11130                 :            :                    struct mlx5_flow_tunnel *tunnel, void *x)
   11131                 :            : {
   11132                 :            :         struct tunnel_db_find_tunnel_id_ctx *ctx = x;
   11133                 :            :         RTE_SET_USED(dev);
   11134                 :          0 :         ctx->tunnel = tunnel;
   11135                 :          0 : }
   11136                 :            : 
   11137                 :            : static struct mlx5_flow_tunnel *
   11138                 :            : mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id)
   11139                 :            : {
   11140                 :          0 :         struct tunnel_db_find_tunnel_id_ctx ctx = {
   11141                 :            :                 .tunnel_id = id,
   11142                 :            :         };
   11143                 :            : 
   11144                 :          0 :         mlx5_access_tunnel_offload_db(dev, find_tunnel_id_match,
   11145                 :            :                                       find_tunnel_id_hit, NULL, &ctx, true);
   11146                 :            : 
   11147         [ #  # ]:          0 :         return ctx.tunnel;
   11148                 :            : }
   11149                 :            : 
   11150                 :            : static struct mlx5_flow_tunnel *
   11151                 :          0 : mlx5_flow_tunnel_allocate(struct rte_eth_dev *dev,
   11152                 :            :                           const struct rte_flow_tunnel *app_tunnel)
   11153                 :            : {
   11154                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11155                 :            :         struct mlx5_indexed_pool *ipool;
   11156                 :            :         struct mlx5_flow_tunnel *tunnel;
   11157                 :            :         uint32_t id;
   11158                 :            : 
   11159                 :          0 :         ipool = priv->sh->ipool[MLX5_IPOOL_TUNNEL_ID];
   11160                 :          0 :         tunnel = mlx5_ipool_zmalloc(ipool, &id);
   11161         [ #  # ]:          0 :         if (!tunnel)
   11162                 :            :                 return NULL;
   11163         [ #  # ]:          0 :         if (id >= MLX5_MAX_TUNNELS) {
   11164                 :          0 :                 mlx5_ipool_free(ipool, id);
   11165                 :          0 :                 DRV_LOG(ERR, "Tunnel ID %d exceed max limit.", id);
   11166                 :          0 :                 return NULL;
   11167                 :            :         }
   11168                 :          0 :         tunnel->groups = mlx5_hlist_create("tunnel groups", 64, false, true,
   11169                 :          0 :                                            priv->sh,
   11170                 :            :                                            mlx5_flow_tunnel_grp2tbl_create_cb,
   11171                 :            :                                            mlx5_flow_tunnel_grp2tbl_match_cb,
   11172                 :            :                                            mlx5_flow_tunnel_grp2tbl_remove_cb,
   11173                 :            :                                            mlx5_flow_tunnel_grp2tbl_clone_cb,
   11174                 :            :                                         mlx5_flow_tunnel_grp2tbl_clone_free_cb);
   11175         [ #  # ]:          0 :         if (!tunnel->groups) {
   11176                 :          0 :                 mlx5_ipool_free(ipool, id);
   11177                 :          0 :                 return NULL;
   11178                 :            :         }
   11179                 :            :         /* initiate new PMD tunnel */
   11180                 :          0 :         memcpy(&tunnel->app_tunnel, app_tunnel, sizeof(*app_tunnel));
   11181                 :          0 :         tunnel->tunnel_id = id;
   11182                 :          0 :         tunnel->action.type = (typeof(tunnel->action.type))
   11183                 :            :                               MLX5_RTE_FLOW_ACTION_TYPE_TUNNEL_SET;
   11184                 :          0 :         tunnel->action.conf = tunnel;
   11185                 :          0 :         tunnel->item.type = (typeof(tunnel->item.type))
   11186                 :            :                             MLX5_RTE_FLOW_ITEM_TYPE_TUNNEL;
   11187                 :          0 :         tunnel->item.spec = tunnel;
   11188                 :          0 :         tunnel->item.last = NULL;
   11189                 :          0 :         tunnel->item.mask = NULL;
   11190                 :            : 
   11191                 :          0 :         DRV_LOG(DEBUG, "port %u new pmd tunnel id=0x%x",
   11192                 :            :                 dev->data->port_id, tunnel->tunnel_id);
   11193                 :            : 
   11194                 :          0 :         return tunnel;
   11195                 :            : }
   11196                 :            : 
   11197                 :            : struct tunnel_db_get_tunnel_ctx {
   11198                 :            :         const struct rte_flow_tunnel *app_tunnel;
   11199                 :            :         struct mlx5_flow_tunnel *tunnel;
   11200                 :            : };
   11201                 :            : 
   11202                 :          0 : static bool get_tunnel_match(struct rte_eth_dev *dev,
   11203                 :            :                              struct mlx5_flow_tunnel *tunnel, const void *x)
   11204                 :            : {
   11205                 :            :         const struct tunnel_db_get_tunnel_ctx *ctx = x;
   11206                 :            : 
   11207                 :            :         RTE_SET_USED(dev);
   11208                 :          0 :         return !memcmp(ctx->app_tunnel, &tunnel->app_tunnel,
   11209                 :            :                        sizeof(*ctx->app_tunnel));
   11210                 :            : }
   11211                 :            : 
   11212                 :          0 : static void get_tunnel_hit(struct rte_eth_dev *dev,
   11213                 :            :                            struct mlx5_flow_tunnel *tunnel, void *x)
   11214                 :            : {
   11215                 :            :         /* called under tunnel spinlock protection */
   11216                 :            :         struct tunnel_db_get_tunnel_ctx *ctx = x;
   11217                 :            : 
   11218                 :            :         RTE_SET_USED(dev);
   11219                 :          0 :         tunnel->refctn++;
   11220                 :          0 :         ctx->tunnel = tunnel;
   11221                 :          0 : }
   11222                 :            : 
   11223                 :          0 : static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
   11224                 :            : {
   11225                 :            :         /* called under tunnel spinlock protection */
   11226                 :            :         struct mlx5_flow_tunnel_hub *thub = mlx5_tunnel_hub(dev);
   11227                 :            :         struct tunnel_db_get_tunnel_ctx *ctx = x;
   11228                 :            : 
   11229                 :          0 :         rte_spinlock_unlock(&thub->sl);
   11230                 :          0 :         ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
   11231                 :            :         rte_spinlock_lock(&thub->sl);
   11232         [ #  # ]:          0 :         if (ctx->tunnel) {
   11233                 :          0 :                 ctx->tunnel->refctn = 1;
   11234         [ #  # ]:          0 :                 LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
   11235                 :            :         }
   11236                 :          0 : }
   11237                 :            : 
   11238                 :            : 
   11239                 :            : static int
   11240                 :          0 : mlx5_get_flow_tunnel(struct rte_eth_dev *dev,
   11241                 :            :                      const struct rte_flow_tunnel *app_tunnel,
   11242                 :            :                      struct mlx5_flow_tunnel **tunnel)
   11243                 :            : {
   11244                 :          0 :         struct tunnel_db_get_tunnel_ctx ctx = {
   11245                 :            :                 .app_tunnel = app_tunnel,
   11246                 :            :         };
   11247                 :            : 
   11248                 :          0 :         mlx5_access_tunnel_offload_db(dev, get_tunnel_match, get_tunnel_hit,
   11249                 :            :                                       get_tunnel_miss, &ctx, true);
   11250                 :          0 :         *tunnel = ctx.tunnel;
   11251         [ #  # ]:          0 :         return ctx.tunnel ? 0 : -ENOMEM;
   11252                 :            : }
   11253                 :            : 
   11254                 :          0 : void mlx5_release_tunnel_hub(struct mlx5_dev_ctx_shared *sh, uint16_t port_id)
   11255                 :            : {
   11256                 :          0 :         struct mlx5_flow_tunnel_hub *thub = sh->tunnel_hub;
   11257                 :            : 
   11258         [ #  # ]:          0 :         if (!thub)
   11259                 :            :                 return;
   11260         [ #  # ]:          0 :         if (!LIST_EMPTY(&thub->tunnels))
   11261                 :          0 :                 DRV_LOG(WARNING, "port %u tunnels present", port_id);
   11262                 :          0 :         mlx5_hlist_destroy(thub->groups);
   11263                 :          0 :         mlx5_free(thub);
   11264                 :            : }
   11265                 :            : 
   11266                 :          0 : int mlx5_alloc_tunnel_hub(struct mlx5_dev_ctx_shared *sh)
   11267                 :            : {
   11268                 :            :         int err;
   11269                 :            :         struct mlx5_flow_tunnel_hub *thub;
   11270                 :            : 
   11271                 :          0 :         thub = mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, sizeof(*thub),
   11272                 :            :                            0, SOCKET_ID_ANY);
   11273         [ #  # ]:          0 :         if (!thub)
   11274                 :            :                 return -ENOMEM;
   11275                 :          0 :         LIST_INIT(&thub->tunnels);
   11276                 :            :         rte_spinlock_init(&thub->sl);
   11277                 :          0 :         thub->groups = mlx5_hlist_create("flow groups", 64,
   11278                 :            :                                          false, true, sh,
   11279                 :            :                                          mlx5_flow_tunnel_grp2tbl_create_cb,
   11280                 :            :                                          mlx5_flow_tunnel_grp2tbl_match_cb,
   11281                 :            :                                          mlx5_flow_tunnel_grp2tbl_remove_cb,
   11282                 :            :                                          mlx5_flow_tunnel_grp2tbl_clone_cb,
   11283                 :            :                                         mlx5_flow_tunnel_grp2tbl_clone_free_cb);
   11284         [ #  # ]:          0 :         if (!thub->groups) {
   11285                 :          0 :                 err = -rte_errno;
   11286                 :          0 :                 goto err;
   11287                 :            :         }
   11288                 :          0 :         sh->tunnel_hub = thub;
   11289                 :            : 
   11290                 :          0 :         return 0;
   11291                 :            : 
   11292                 :            : err:
   11293                 :            :         if (thub->groups)
   11294                 :            :                 mlx5_hlist_destroy(thub->groups);
   11295                 :            :         if (thub)
   11296                 :          0 :                 mlx5_free(thub);
   11297                 :          0 :         return err;
   11298                 :            : }
   11299                 :            : 
   11300                 :            : static inline int
   11301                 :          0 : mlx5_flow_tunnel_validate(struct rte_eth_dev *dev,
   11302                 :            :                           struct rte_flow_tunnel *tunnel,
   11303                 :            :                           struct rte_flow_error *error)
   11304                 :            : {
   11305                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11306                 :            : 
   11307         [ #  # ]:          0 :         if (!priv->sh->config.dv_flow_en)
   11308                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   11309                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
   11310                 :            :                                           "flow DV interface is off");
   11311         [ #  # ]:          0 :         if (!is_tunnel_offload_active(dev))
   11312                 :          0 :                 return rte_flow_error_set(error, ENOTSUP,
   11313                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
   11314                 :            :                                           "tunnel offload was not activated, consider setting dv_xmeta_en=3");
   11315         [ #  # ]:          0 :         if (!tunnel)
   11316                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   11317                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
   11318                 :            :                                           "no application tunnel");
   11319         [ #  # ]:          0 :         switch (tunnel->type) {
   11320                 :          0 :         default:
   11321                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   11322                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
   11323                 :            :                                           "unsupported tunnel type");
   11324                 :            :         case RTE_FLOW_ITEM_TYPE_VXLAN:
   11325                 :            :         case RTE_FLOW_ITEM_TYPE_GRE:
   11326                 :            :         case RTE_FLOW_ITEM_TYPE_NVGRE:
   11327                 :            :         case RTE_FLOW_ITEM_TYPE_GENEVE:
   11328                 :            :                 break;
   11329                 :            :         }
   11330                 :            :         return 0;
   11331                 :            : }
   11332                 :            : 
   11333                 :            : static int
   11334                 :          0 : mlx5_flow_tunnel_decap_set(struct rte_eth_dev *dev,
   11335                 :            :                     struct rte_flow_tunnel *app_tunnel,
   11336                 :            :                     struct rte_flow_action **actions,
   11337                 :            :                     uint32_t *num_of_actions,
   11338                 :            :                     struct rte_flow_error *error)
   11339                 :            : {
   11340                 :            :         struct mlx5_flow_tunnel *tunnel;
   11341                 :          0 :         int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
   11342                 :            : 
   11343         [ #  # ]:          0 :         if (ret)
   11344                 :            :                 return ret;
   11345                 :          0 :         ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
   11346         [ #  # ]:          0 :         if (ret < 0) {
   11347                 :          0 :                 return rte_flow_error_set(error, ret,
   11348                 :            :                                           RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
   11349                 :            :                                           "failed to initialize pmd tunnel");
   11350                 :            :         }
   11351                 :          0 :         *actions = &tunnel->action;
   11352                 :          0 :         *num_of_actions = 1;
   11353                 :          0 :         return 0;
   11354                 :            : }
   11355                 :            : 
   11356                 :            : static int
   11357                 :          0 : mlx5_flow_tunnel_match(struct rte_eth_dev *dev,
   11358                 :            :                        struct rte_flow_tunnel *app_tunnel,
   11359                 :            :                        struct rte_flow_item **items,
   11360                 :            :                        uint32_t *num_of_items,
   11361                 :            :                        struct rte_flow_error *error)
   11362                 :            : {
   11363                 :            :         struct mlx5_flow_tunnel *tunnel;
   11364                 :          0 :         int ret = mlx5_flow_tunnel_validate(dev, app_tunnel, error);
   11365                 :            : 
   11366         [ #  # ]:          0 :         if (ret)
   11367                 :            :                 return ret;
   11368                 :          0 :         ret = mlx5_get_flow_tunnel(dev, app_tunnel, &tunnel);
   11369         [ #  # ]:          0 :         if (ret < 0) {
   11370                 :          0 :                 return rte_flow_error_set(error, ret,
   11371                 :            :                                           RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
   11372                 :            :                                           "failed to initialize pmd tunnel");
   11373                 :            :         }
   11374                 :          0 :         *items = &tunnel->item;
   11375                 :          0 :         *num_of_items = 1;
   11376                 :          0 :         return 0;
   11377                 :            : }
   11378                 :            : 
   11379                 :            : struct tunnel_db_element_release_ctx {
   11380                 :            :         struct rte_flow_item *items;
   11381                 :            :         struct rte_flow_action *actions;
   11382                 :            :         uint32_t num_elements;
   11383                 :            :         struct rte_flow_error *error;
   11384                 :            :         int ret;
   11385                 :            : };
   11386                 :            : 
   11387                 :            : static bool
   11388                 :          0 : tunnel_element_release_match(struct rte_eth_dev *dev,
   11389                 :            :                              struct mlx5_flow_tunnel *tunnel, const void *x)
   11390                 :            : {
   11391                 :            :         const struct tunnel_db_element_release_ctx *ctx = x;
   11392                 :            : 
   11393                 :            :         RTE_SET_USED(dev);
   11394         [ #  # ]:          0 :         if (ctx->num_elements != 1)
   11395                 :            :                 return false;
   11396         [ #  # ]:          0 :         else if (ctx->items)
   11397                 :          0 :                 return ctx->items == &tunnel->item;
   11398         [ #  # ]:          0 :         else if (ctx->actions)
   11399                 :          0 :                 return ctx->actions == &tunnel->action;
   11400                 :            : 
   11401                 :            :         return false;
   11402                 :            : }
   11403                 :            : 
   11404                 :            : static void
   11405                 :          0 : tunnel_element_release_hit(struct rte_eth_dev *dev,
   11406                 :            :                            struct mlx5_flow_tunnel *tunnel, void *x)
   11407                 :            : {
   11408                 :            :         struct tunnel_db_element_release_ctx *ctx = x;
   11409                 :          0 :         ctx->ret = 0;
   11410         [ #  # ]:          0 :         if (!(__atomic_fetch_sub(&tunnel->refctn, 1, __ATOMIC_RELAXED) - 1))
   11411                 :          0 :                 mlx5_flow_tunnel_free(dev, tunnel);
   11412                 :          0 : }
   11413                 :            : 
   11414                 :            : static void
   11415                 :          0 : tunnel_element_release_miss(struct rte_eth_dev *dev, void *x)
   11416                 :            : {
   11417                 :            :         struct tunnel_db_element_release_ctx *ctx = x;
   11418                 :            :         RTE_SET_USED(dev);
   11419                 :          0 :         ctx->ret = rte_flow_error_set(ctx->error, EINVAL,
   11420                 :            :                                       RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
   11421                 :            :                                       "invalid argument");
   11422                 :          0 : }
   11423                 :            : 
   11424                 :            : static int
   11425                 :          0 : mlx5_flow_tunnel_item_release(struct rte_eth_dev *dev,
   11426                 :            :                        struct rte_flow_item *pmd_items,
   11427                 :            :                        uint32_t num_items, struct rte_flow_error *err)
   11428                 :            : {
   11429                 :          0 :         struct tunnel_db_element_release_ctx ctx = {
   11430                 :            :                 .items = pmd_items,
   11431                 :            :                 .actions = NULL,
   11432                 :            :                 .num_elements = num_items,
   11433                 :            :                 .error = err,
   11434                 :            :         };
   11435                 :            : 
   11436                 :          0 :         mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
   11437                 :            :                                       tunnel_element_release_hit,
   11438                 :            :                                       tunnel_element_release_miss, &ctx, false);
   11439                 :            : 
   11440                 :          0 :         return ctx.ret;
   11441                 :            : }
   11442                 :            : 
   11443                 :            : static int
   11444                 :          0 : mlx5_flow_tunnel_action_release(struct rte_eth_dev *dev,
   11445                 :            :                          struct rte_flow_action *pmd_actions,
   11446                 :            :                          uint32_t num_actions, struct rte_flow_error *err)
   11447                 :            : {
   11448                 :          0 :         struct tunnel_db_element_release_ctx ctx = {
   11449                 :            :                 .items = NULL,
   11450                 :            :                 .actions = pmd_actions,
   11451                 :            :                 .num_elements = num_actions,
   11452                 :            :                 .error = err,
   11453                 :            :         };
   11454                 :            : 
   11455                 :          0 :         mlx5_access_tunnel_offload_db(dev, tunnel_element_release_match,
   11456                 :            :                                       tunnel_element_release_hit,
   11457                 :            :                                       tunnel_element_release_miss, &ctx, false);
   11458                 :            : 
   11459                 :          0 :         return ctx.ret;
   11460                 :            : }
   11461                 :            : 
   11462                 :            : static int
   11463                 :          0 : mlx5_flow_tunnel_get_restore_info(struct rte_eth_dev *dev,
   11464                 :            :                                   struct rte_mbuf *m,
   11465                 :            :                                   struct rte_flow_restore_info *info,
   11466                 :            :                                   struct rte_flow_error *err)
   11467                 :            : {
   11468                 :          0 :         uint64_t ol_flags = m->ol_flags;
   11469                 :            :         const struct mlx5_flow_tbl_data_entry *tble;
   11470                 :            :         const uint64_t mask = RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
   11471                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11472                 :            : 
   11473         [ #  # ]:          0 :         if (priv->tunnel_enabled == 0)
   11474                 :          0 :                 goto err;
   11475         [ #  # ]:          0 :         if ((ol_flags & mask) != mask)
   11476                 :          0 :                 goto err;
   11477                 :          0 :         tble = tunnel_mark_decode(dev, m->hash.fdir.hi);
   11478         [ #  # ]:          0 :         if (!tble) {
   11479                 :          0 :                 DRV_LOG(DEBUG, "port %u invalid miss tunnel mark %#x",
   11480                 :            :                         dev->data->port_id, m->hash.fdir.hi);
   11481                 :          0 :                 goto err;
   11482                 :            :         }
   11483                 :            :         MLX5_ASSERT(tble->tunnel);
   11484                 :          0 :         memcpy(&info->tunnel, &tble->tunnel->app_tunnel, sizeof(info->tunnel));
   11485                 :          0 :         info->group_id = tble->group_id;
   11486                 :          0 :         info->flags = RTE_FLOW_RESTORE_INFO_TUNNEL |
   11487                 :            :                       RTE_FLOW_RESTORE_INFO_GROUP_ID |
   11488                 :            :                       RTE_FLOW_RESTORE_INFO_ENCAPSULATED;
   11489                 :            : 
   11490                 :          0 :         return 0;
   11491                 :            : 
   11492                 :          0 : err:
   11493                 :          0 :         return rte_flow_error_set(err, EINVAL,
   11494                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
   11495                 :            :                                   "failed to get restore info");
   11496                 :            : }
   11497                 :            : 
   11498                 :            : #else /* HAVE_IBV_FLOW_DV_SUPPORT */
   11499                 :            : static int
   11500                 :            : mlx5_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev,
   11501                 :            :                            __rte_unused struct rte_flow_tunnel *app_tunnel,
   11502                 :            :                            __rte_unused struct rte_flow_action **actions,
   11503                 :            :                            __rte_unused uint32_t *num_of_actions,
   11504                 :            :                            __rte_unused struct rte_flow_error *error)
   11505                 :            : {
   11506                 :            :         return -ENOTSUP;
   11507                 :            : }
   11508                 :            : 
   11509                 :            : static int
   11510                 :            : mlx5_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
   11511                 :            :                        __rte_unused struct rte_flow_tunnel *app_tunnel,
   11512                 :            :                        __rte_unused struct rte_flow_item **items,
   11513                 :            :                        __rte_unused uint32_t *num_of_items,
   11514                 :            :                        __rte_unused struct rte_flow_error *error)
   11515                 :            : {
   11516                 :            :         return -ENOTSUP;
   11517                 :            : }
   11518                 :            : 
   11519                 :            : static int
   11520                 :            : mlx5_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
   11521                 :            :                               __rte_unused struct rte_flow_item *pmd_items,
   11522                 :            :                               __rte_unused uint32_t num_items,
   11523                 :            :                               __rte_unused struct rte_flow_error *err)
   11524                 :            : {
   11525                 :            :         return -ENOTSUP;
   11526                 :            : }
   11527                 :            : 
   11528                 :            : static int
   11529                 :            : mlx5_flow_tunnel_action_release(__rte_unused struct rte_eth_dev *dev,
   11530                 :            :                                 __rte_unused struct rte_flow_action *pmd_action,
   11531                 :            :                                 __rte_unused uint32_t num_actions,
   11532                 :            :                                 __rte_unused struct rte_flow_error *err)
   11533                 :            : {
   11534                 :            :         return -ENOTSUP;
   11535                 :            : }
   11536                 :            : 
   11537                 :            : static int
   11538                 :            : mlx5_flow_tunnel_get_restore_info(__rte_unused struct rte_eth_dev *dev,
   11539                 :            :                                   __rte_unused struct rte_mbuf *m,
   11540                 :            :                                   __rte_unused struct rte_flow_restore_info *i,
   11541                 :            :                                   __rte_unused struct rte_flow_error *err)
   11542                 :            : {
   11543                 :            :         return -ENOTSUP;
   11544                 :            : }
   11545                 :            : 
   11546                 :            : static int
   11547                 :            : flow_tunnel_add_default_miss(__rte_unused struct rte_eth_dev *dev,
   11548                 :            :                              __rte_unused struct rte_flow *flow,
   11549                 :            :                              __rte_unused const struct rte_flow_attr *attr,
   11550                 :            :                              __rte_unused const struct rte_flow_action *actions,
   11551                 :            :                              __rte_unused uint32_t flow_idx,
   11552                 :            :                              __rte_unused const struct mlx5_flow_tunnel *tunnel,
   11553                 :            :                              __rte_unused struct tunnel_default_miss_ctx *ctx,
   11554                 :            :                              __rte_unused struct rte_flow_error *error)
   11555                 :            : {
   11556                 :            :         return -ENOTSUP;
   11557                 :            : }
   11558                 :            : 
   11559                 :            : static struct mlx5_flow_tunnel *
   11560                 :            : mlx5_find_tunnel_id(__rte_unused struct rte_eth_dev *dev,
   11561                 :            :                     __rte_unused uint32_t id)
   11562                 :            : {
   11563                 :            :         return NULL;
   11564                 :            : }
   11565                 :            : 
   11566                 :            : static void
   11567                 :            : mlx5_flow_tunnel_free(__rte_unused struct rte_eth_dev *dev,
   11568                 :            :                       __rte_unused struct mlx5_flow_tunnel *tunnel)
   11569                 :            : {
   11570                 :            : }
   11571                 :            : 
   11572                 :            : static uint32_t
   11573                 :            : tunnel_flow_group_to_flow_table(__rte_unused struct rte_eth_dev *dev,
   11574                 :            :                                 __rte_unused const struct mlx5_flow_tunnel *t,
   11575                 :            :                                 __rte_unused uint32_t group,
   11576                 :            :                                 __rte_unused uint32_t *table,
   11577                 :            :                                 struct rte_flow_error *error)
   11578                 :            : {
   11579                 :            :         return rte_flow_error_set(error, ENOTSUP,
   11580                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
   11581                 :            :                                   "tunnel offload requires DV support");
   11582                 :            : }
   11583                 :            : 
   11584                 :            : void
   11585                 :            : mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
   11586                 :            :                         __rte_unused  uint16_t port_id)
   11587                 :            : {
   11588                 :            : }
   11589                 :            : #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
   11590                 :            : 
   11591                 :            : /* Flex flow item API */
   11592                 :            : static struct rte_flow_item_flex_handle *
   11593                 :          0 : mlx5_flow_flex_item_create(struct rte_eth_dev *dev,
   11594                 :            :                            const struct rte_flow_item_flex_conf *conf,
   11595                 :            :                            struct rte_flow_error *error)
   11596                 :            : {
   11597                 :            :         static const char err_msg[] = "flex item creation unsupported";
   11598         [ #  # ]:          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11599                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   11600                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   11601                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   11602                 :            : 
   11603         [ #  # ]:          0 :         if (!priv->pci_dev) {
   11604                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
   11605                 :            :                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
   11606                 :            :                                    "create flex item on PF only");
   11607                 :          0 :                 return NULL;
   11608                 :            :         }
   11609         [ #  # ]:          0 :         switch (priv->pci_dev->id.device_id) {
   11610                 :            :         case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
   11611                 :            :         case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
   11612                 :            :                 break;
   11613                 :          0 :         default:
   11614                 :          0 :                 rte_flow_error_set(error, ENOTSUP,
   11615                 :            :                                    RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
   11616                 :            :                                    "flex item available on BlueField ports only");
   11617                 :          0 :                 return NULL;
   11618                 :            :         }
   11619         [ #  # ]:          0 :         if (!fops->item_create) {
   11620                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   11621                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   11622                 :            :                                    NULL, err_msg);
   11623                 :          0 :                 return NULL;
   11624                 :            :         }
   11625                 :          0 :         return fops->item_create(dev, conf, error);
   11626                 :            : }
   11627                 :            : 
   11628                 :            : static int
   11629         [ #  # ]:          0 : mlx5_flow_flex_item_release(struct rte_eth_dev *dev,
   11630                 :            :                             const struct rte_flow_item_flex_handle *handle,
   11631                 :            :                             struct rte_flow_error *error)
   11632                 :            : {
   11633                 :            :         static const char err_msg[] = "flex item release unsupported";
   11634                 :            :         struct rte_flow_attr attr = { .transfer = 0 };
   11635                 :          0 :         const struct mlx5_flow_driver_ops *fops =
   11636                 :            :                         flow_get_drv_ops(flow_get_drv_type(dev, &attr));
   11637                 :            : 
   11638         [ #  # ]:          0 :         if (!fops->item_release) {
   11639                 :          0 :                 DRV_LOG(ERR, "port %u %s.", dev->data->port_id, err_msg);
   11640                 :          0 :                 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
   11641                 :            :                                    NULL, err_msg);
   11642                 :          0 :                 return -rte_errno;
   11643                 :            :         }
   11644                 :          0 :         return fops->item_release(dev, handle, error);
   11645                 :            : }
   11646                 :            : 
   11647                 :            : static void
   11648                 :          0 : mlx5_dbg__print_pattern(const struct rte_flow_item *item)
   11649                 :            : {
   11650                 :            :         int ret;
   11651                 :            :         struct rte_flow_error error;
   11652                 :            : 
   11653         [ #  # ]:          0 :         for (; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
   11654                 :            :                 char *item_name;
   11655                 :          0 :                 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, &item_name,
   11656                 :            :                                     sizeof(item_name),
   11657                 :          0 :                                     (void *)(uintptr_t)item->type, &error);
   11658         [ #  # ]:          0 :                 if (ret > 0)
   11659                 :          0 :                         printf("%s ", item_name);
   11660                 :            :                 else
   11661                 :          0 :                         printf("%d\n", (int)item->type);
   11662                 :            :         }
   11663                 :            :         printf("END\n");
   11664                 :          0 : }
   11665                 :            : 
   11666                 :            : static int
   11667                 :            : mlx5_flow_is_std_vxlan_port(const struct rte_flow_item *udp_item)
   11668                 :            : {
   11669                 :          0 :         const struct rte_flow_item_udp *spec = udp_item->spec;
   11670                 :          0 :         const struct rte_flow_item_udp *mask = udp_item->mask;
   11671                 :            :         uint16_t udp_dport = 0;
   11672                 :            : 
   11673                 :          0 :         if (spec != NULL) {
   11674         [ #  # ]:          0 :                 if (!mask)
   11675                 :            :                         mask = &rte_flow_item_udp_mask;
   11676         [ #  # ]:          0 :                 udp_dport = rte_be_to_cpu_16(spec->hdr.dst_port &
   11677                 :            :                                 mask->hdr.dst_port);
   11678                 :            :         }
   11679                 :          0 :         return (!udp_dport || udp_dport == MLX5_UDP_PORT_VXLAN);
   11680                 :            : }
   11681                 :            : 
   11682                 :            : static const struct mlx5_flow_expand_node *
   11683                 :          0 : mlx5_flow_expand_rss_adjust_node(const struct rte_flow_item *pattern,
   11684                 :            :                 unsigned int item_idx,
   11685                 :            :                 const struct mlx5_flow_expand_node graph[],
   11686                 :            :                 const struct mlx5_flow_expand_node *node)
   11687                 :            : {
   11688                 :          0 :         const struct rte_flow_item *item = pattern + item_idx, *prev_item;
   11689                 :            : 
   11690   [ #  #  #  # ]:          0 :         if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN &&
   11691                 :          0 :                         node != NULL &&
   11692         [ #  # ]:          0 :                         node->type == RTE_FLOW_ITEM_TYPE_VXLAN) {
   11693                 :            :                 /*
   11694                 :            :                  * The expansion node is VXLAN and it is also the last
   11695                 :            :                  * expandable item in the pattern, so need to continue
   11696                 :            :                  * expansion of the inner tunnel.
   11697                 :            :                  */
   11698                 :            :                 MLX5_ASSERT(item_idx > 0);
   11699         [ #  # ]:          0 :                 prev_item = pattern + item_idx - 1;
   11700                 :            :                 MLX5_ASSERT(prev_item->type == RTE_FLOW_ITEM_TYPE_UDP);
   11701         [ #  # ]:          0 :                 if (mlx5_flow_is_std_vxlan_port(prev_item))
   11702                 :          0 :                         return &graph[MLX5_EXPANSION_STD_VXLAN];
   11703                 :          0 :                 return &graph[MLX5_EXPANSION_L3_VXLAN];
   11704                 :            :         }
   11705                 :            :         return node;
   11706                 :            : }
   11707                 :            : 
   11708                 :            : /* Map of Verbs to Flow priority with 8 Verbs priorities. */
   11709                 :            : static const uint32_t priority_map_3[][MLX5_PRIORITY_MAP_MAX] = {
   11710                 :            :         { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 },
   11711                 :            : };
   11712                 :            : 
   11713                 :            : /* Map of Verbs to Flow priority with 16 Verbs priorities. */
   11714                 :            : static const uint32_t priority_map_5[][MLX5_PRIORITY_MAP_MAX] = {
   11715                 :            :         { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 },
   11716                 :            :         { 9, 10, 11 }, { 12, 13, 14 },
   11717                 :            : };
   11718                 :            : 
   11719                 :            : /**
   11720                 :            :  * Discover the number of available flow priorities.
   11721                 :            :  *
   11722                 :            :  * @param dev
   11723                 :            :  *   Ethernet device.
   11724                 :            :  *
   11725                 :            :  * @return
   11726                 :            :  *   On success, number of available flow priorities.
   11727                 :            :  *   On failure, a negative errno-style code and rte_errno is set.
   11728                 :            :  */
   11729                 :            : int
   11730                 :          0 : mlx5_flow_discover_priorities(struct rte_eth_dev *dev)
   11731                 :            : {
   11732                 :            :         static const uint16_t vprio[] = {8, 16};
   11733                 :          0 :         const struct mlx5_priv *priv = dev->data->dev_private;
   11734                 :            :         const struct mlx5_flow_driver_ops *fops;
   11735                 :            :         enum mlx5_flow_drv_type type;
   11736                 :            :         int ret;
   11737                 :            : 
   11738                 :            :         type = mlx5_flow_os_get_type();
   11739                 :            :         if (type == MLX5_FLOW_TYPE_MAX) {
   11740                 :            :                 type = MLX5_FLOW_TYPE_VERBS;
   11741   [ #  #  #  # ]:          0 :                 if (priv->sh->cdev->config.devx && priv->sh->config.dv_flow_en)
   11742                 :            :                         type = MLX5_FLOW_TYPE_DV;
   11743                 :            :         }
   11744                 :          0 :         fops = flow_get_drv_ops(type);
   11745         [ #  # ]:          0 :         if (fops->discover_priorities == NULL) {
   11746                 :          0 :                 DRV_LOG(ERR, "Priority discovery not supported");
   11747                 :          0 :                 rte_errno = ENOTSUP;
   11748                 :          0 :                 return -rte_errno;
   11749                 :            :         }
   11750                 :          0 :         ret = fops->discover_priorities(dev, vprio, RTE_DIM(vprio));
   11751         [ #  # ]:          0 :         if (ret < 0)
   11752                 :            :                 return ret;
   11753      [ #  #  # ]:          0 :         switch (ret) {
   11754                 :            :         case 8:
   11755                 :            :                 ret = RTE_DIM(priority_map_3);
   11756                 :            :                 break;
   11757                 :          0 :         case 16:
   11758                 :            :                 ret = RTE_DIM(priority_map_5);
   11759                 :          0 :                 break;
   11760                 :          0 :         default:
   11761                 :          0 :                 rte_errno = ENOTSUP;
   11762                 :          0 :                 DRV_LOG(ERR,
   11763                 :            :                         "port %u maximum priority: %d expected 8/16",
   11764                 :            :                         dev->data->port_id, ret);
   11765                 :          0 :                 return -rte_errno;
   11766                 :            :         }
   11767                 :          0 :         DRV_LOG(INFO, "port %u supported flow priorities:"
   11768                 :            :                 " 0-%d for ingress or egress root table,"
   11769                 :            :                 " 0-%d for non-root table or transfer root table.",
   11770                 :            :                 dev->data->port_id, ret - 2,
   11771                 :            :                 MLX5_NON_ROOT_FLOW_MAX_PRIO - 1);
   11772                 :          0 :         return ret;
   11773                 :            : }
   11774                 :            : 
   11775                 :            : /**
   11776                 :            :  * Adjust flow priority based on the highest layer and the request priority.
   11777                 :            :  *
   11778                 :            :  * @param[in] dev
   11779                 :            :  *   Pointer to the Ethernet device structure.
   11780                 :            :  * @param[in] priority
   11781                 :            :  *   The rule base priority.
   11782                 :            :  * @param[in] subpriority
   11783                 :            :  *   The priority based on the items.
   11784                 :            :  *
   11785                 :            :  * @return
   11786                 :            :  *   The new priority.
   11787                 :            :  */
   11788                 :            : uint32_t
   11789                 :          0 : mlx5_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
   11790                 :            :                           uint32_t subpriority)
   11791                 :            : {
   11792                 :            :         uint32_t res = 0;
   11793                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11794                 :            : 
   11795      [ #  #  # ]:          0 :         switch (priv->sh->flow_max_priority) {
   11796                 :          0 :         case RTE_DIM(priority_map_3):
   11797                 :          0 :                 res = priority_map_3[priority][subpriority];
   11798                 :          0 :                 break;
   11799                 :          0 :         case RTE_DIM(priority_map_5):
   11800                 :          0 :                 res = priority_map_5[priority][subpriority];
   11801                 :          0 :                 break;
   11802                 :            :         }
   11803                 :          0 :         return  res;
   11804                 :            : }
   11805                 :            : 
   11806                 :            : /**
   11807                 :            :  * Get the priority for sending traffic to kernel table.
   11808                 :            :  *
   11809                 :            :  * @param[in] dev
   11810                 :            :  *   Pointer to the Ethernet device structure.
   11811                 :            :  *
   11812                 :            :  * @return
   11813                 :            :  *   On success: the value of priority for sending traffic to kernel table
   11814                 :            :  *   On failure: -1
   11815                 :            :  */
   11816                 :            : uint32_t
   11817                 :          0 : mlx5_get_send_to_kernel_priority(struct rte_eth_dev *dev)
   11818                 :            : {
   11819                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11820                 :            :         uint32_t res;
   11821                 :            : 
   11822      [ #  #  # ]:          0 :         switch (priv->sh->flow_max_priority) {
   11823                 :            :         case RTE_DIM(priority_map_5):
   11824                 :            :                 res = 15;
   11825                 :            :                 break;
   11826                 :          0 :         case RTE_DIM(priority_map_3):
   11827                 :            :                 res = 7;
   11828                 :          0 :                 break;
   11829                 :          0 :         default:
   11830                 :          0 :                 DRV_LOG(ERR,
   11831                 :            :                         "port %u maximum priority: %d expected 8/16",
   11832                 :            :                         dev->data->port_id, priv->sh->flow_max_priority);
   11833                 :            :                 res = (uint32_t)-1;
   11834                 :            :         }
   11835                 :          0 :         return res;
   11836                 :            : }
   11837                 :            : 
   11838                 :            : /**
   11839                 :            :  * Get the E-Switch Manager vport id.
   11840                 :            :  *
   11841                 :            :  * @param[in] dev
   11842                 :            :  *   Pointer to the Ethernet device structure.
   11843                 :            :  *
   11844                 :            :  * @return
   11845                 :            :  *   The vport id.
   11846                 :            :  */
   11847                 :          0 : int16_t mlx5_flow_get_esw_manager_vport_id(struct rte_eth_dev *dev)
   11848                 :            : {
   11849                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
   11850                 :          0 :         struct mlx5_common_device *cdev = priv->sh->cdev;
   11851                 :            : 
   11852                 :            :         /* New FW exposes E-Switch Manager vport ID, can use it directly. */
   11853         [ #  # ]:          0 :         if (cdev->config.hca_attr.esw_mgr_vport_id_valid)
   11854                 :          0 :                 return (int16_t)cdev->config.hca_attr.esw_mgr_vport_id;
   11855                 :            : 
   11856         [ #  # ]:          0 :         if (priv->pci_dev == NULL)
   11857                 :            :                 return 0;
   11858         [ #  # ]:          0 :         switch (priv->pci_dev->id.device_id) {
   11859                 :            :         case PCI_DEVICE_ID_MELLANOX_BLUEFIELD:
   11860                 :            :         case PCI_DEVICE_ID_MELLANOX_BLUEFIELD2:
   11861                 :            :         case PCI_DEVICE_ID_MELLANOX_BLUEFIELD3:
   11862                 :            :         /*
   11863                 :            :          * In old FW which doesn't expose the E-Switch Manager vport ID in the capability,
   11864                 :            :          * only the BF embedded CPUs control the E-Switch Manager port. Hence,
   11865                 :            :          * ECPF vport ID is selected and not the host port (0) in any BF case.
   11866                 :            :          */
   11867                 :            :                 return (int16_t)MLX5_ECPF_VPORT_ID;
   11868                 :          0 :         default:
   11869                 :          0 :                 return MLX5_PF_VPORT_ID;
   11870                 :            :         }
   11871                 :            : }
   11872                 :            : 
   11873                 :            : /**
   11874                 :            :  * Parse item to get the vport id.
   11875                 :            :  *
   11876                 :            :  * @param[in] dev
   11877                 :            :  *   Pointer to the Ethernet device structure.
   11878                 :            :  * @param[in] item
   11879                 :            :  *   The src port id match item.
   11880                 :            :  * @param[out] vport_id
   11881                 :            :  *   Pointer to put the vport id.
   11882                 :            :  * @param[out] all_ports
   11883                 :            :  *   Indicate if the item matches all ports.
   11884                 :            :  * @param[out] error
   11885                 :            :  *   Pointer to error structure.
   11886                 :            :  *
   11887                 :            :  * @return
   11888                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
   11889                 :            :  */
   11890                 :          0 : int mlx5_flow_get_item_vport_id(struct rte_eth_dev *dev,
   11891                 :            :                                 const struct rte_flow_item *item,
   11892                 :            :                                 uint16_t *vport_id,
   11893                 :            :                                 bool *all_ports,
   11894                 :            :                                 struct rte_flow_error *error)
   11895                 :            : {
   11896                 :            :         struct mlx5_priv *port_priv;
   11897                 :            :         const struct rte_flow_item_port_id *pid_v = NULL;
   11898                 :            :         const struct rte_flow_item_ethdev *dev_v = NULL;
   11899                 :            :         uint32_t esw_mgr_port;
   11900                 :            :         uint32_t src_port;
   11901                 :            : 
   11902         [ #  # ]:          0 :         if (all_ports)
   11903                 :          0 :                 *all_ports = false;
   11904   [ #  #  #  # ]:          0 :         switch (item->type) {
   11905                 :          0 :         case RTE_FLOW_ITEM_TYPE_PORT_ID:
   11906                 :          0 :                 pid_v = item->spec;
   11907         [ #  # ]:          0 :                 if (!pid_v)
   11908                 :            :                         return 0;
   11909                 :          0 :                 src_port = pid_v->id;
   11910                 :            :                 esw_mgr_port = MLX5_PORT_ESW_MGR;
   11911                 :          0 :                 break;
   11912                 :          0 :         case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
   11913                 :          0 :                 dev_v = item->spec;
   11914         [ #  # ]:          0 :                 if (!dev_v) {
   11915         [ #  # ]:          0 :                         if (all_ports)
   11916                 :          0 :                                 *all_ports = true;
   11917                 :          0 :                         return 0;
   11918                 :            :                 }
   11919                 :          0 :                 src_port = dev_v->port_id;
   11920                 :            :                 esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
   11921                 :          0 :                 break;
   11922                 :            :         case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
   11923                 :            :                 src_port = MLX5_REPRESENTED_PORT_ESW_MGR;
   11924                 :            :                 esw_mgr_port = MLX5_REPRESENTED_PORT_ESW_MGR;
   11925                 :            :                 break;
   11926                 :          0 :         default:
   11927                 :          0 :                 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
   11928                 :            :                                           NULL, "Incorrect item type.");
   11929                 :            :         }
   11930         [ #  # ]:          0 :         if (src_port == esw_mgr_port) {
   11931                 :          0 :                 *vport_id = mlx5_flow_get_esw_manager_vport_id(dev);
   11932                 :            :         } else {
   11933                 :          0 :                 port_priv = mlx5_port_to_eswitch_info(src_port, false);
   11934         [ #  # ]:          0 :                 if (!port_priv)
   11935                 :          0 :                         return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
   11936                 :            :                                                   NULL, "Failed to get port info.");
   11937                 :          0 :                 *vport_id = port_priv->representor_id;
   11938                 :            :         }
   11939                 :            : 
   11940                 :            :         return 0;
   11941                 :            : }
   11942                 :            : 
   11943                 :            : int
   11944                 :          0 : mlx5_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
   11945                 :            :                               uint16_t *proxy_port_id,
   11946                 :            :                               struct rte_flow_error *error)
   11947                 :            : {
   11948                 :          0 :         const struct mlx5_priv *priv = dev->data->dev_private;
   11949                 :            :         uint16_t port_id;
   11950                 :            : 
   11951         [ #  # ]:          0 :         if (!priv->sh->config.dv_esw_en)
   11952                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   11953                 :            :                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
   11954                 :            :                                           NULL,
   11955                 :            :                                           "unable to provide a proxy port"
   11956                 :            :                                           " without E-Switch configured");
   11957         [ #  # ]:          0 :         if (!priv->master && !priv->representor)
   11958                 :          0 :                 return rte_flow_error_set(error, EINVAL,
   11959                 :            :                                           RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
   11960                 :            :                                           NULL,
   11961                 :            :                                           "unable to provide a proxy port"
   11962                 :            :                                           " for port which is not a master"
   11963                 :            :                                           " or a representor port");
   11964         [ #  # ]:          0 :         if (priv->master) {
   11965                 :          0 :                 *proxy_port_id = dev->data->port_id;
   11966                 :          0 :                 return 0;
   11967                 :            :         }
   11968         [ #  # ]:          0 :         MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
   11969                 :          0 :                 const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
   11970                 :          0 :                 const struct mlx5_priv *port_priv = port_dev->data->dev_private;
   11971                 :            : 
   11972         [ #  # ]:          0 :                 if (port_priv->master &&
   11973         [ #  # ]:          0 :                     port_priv->domain_id == priv->domain_id) {
   11974                 :          0 :                         *proxy_port_id = port_id;
   11975                 :          0 :                         return 0;
   11976                 :            :                 }
   11977                 :            :         }
   11978                 :          0 :         return rte_flow_error_set(error, ENODEV,
   11979                 :            :                                   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
   11980                 :            :                                   NULL, "unable to find a proxy port");
   11981                 :            : }
   11982                 :            : 
   11983                 :            : /**
   11984                 :            :  * Discover IPv6 traffic class ID support in rdma-core and firmware.
   11985                 :            :  *
   11986                 :            :  * @param dev
   11987                 :            :  *   Ethernet device.
   11988                 :            :  *
   11989                 :            :  * @return
   11990                 :            :  *   0, rdma-core is good to work with firmware.
   11991                 :            :  *   -EOPNOTSUPP, rdma-core could not work with new IPv6 TC ID.
   11992                 :            :  */
   11993                 :            : int
   11994                 :          0 : mlx5_flow_discover_ipv6_tc_support(struct rte_eth_dev *dev)
   11995                 :            : {
   11996                 :            :         struct rte_flow_action_set_dscp set_dscp;
   11997                 :            :         struct rte_flow_attr attr;
   11998                 :            :         struct rte_flow_action actions[2];
   11999                 :            :         struct rte_flow_item items[3];
   12000                 :            :         struct rte_flow_error error;
   12001                 :            :         uint32_t flow_idx;
   12002                 :            : 
   12003                 :            :         memset(&attr, 0, sizeof(attr));
   12004                 :            :         memset(actions, 0, sizeof(actions));
   12005                 :            :         memset(items, 0, sizeof(items));
   12006                 :          0 :         attr.group = 1;
   12007                 :          0 :         attr.egress = 1;
   12008                 :          0 :         items[0].type = RTE_FLOW_ITEM_TYPE_ETH;
   12009                 :          0 :         items[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
   12010                 :            :         items[2].type = RTE_FLOW_ITEM_TYPE_END;
   12011                 :            :         /* Random value */
   12012                 :          0 :         set_dscp.dscp = 9;
   12013                 :          0 :         actions[0].type = RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP;
   12014                 :          0 :         actions[0].conf = &set_dscp;
   12015                 :            :         actions[1].type = RTE_FLOW_ACTION_TYPE_END;
   12016                 :            : 
   12017                 :          0 :         flow_idx = flow_list_create(dev, MLX5_FLOW_TYPE_GEN, &attr, items, actions, true, &error);
   12018         [ #  # ]:          0 :         if (!flow_idx)
   12019                 :            :                 return -EOPNOTSUPP;
   12020                 :            : 
   12021                 :          0 :         flow_list_destroy(dev, MLX5_FLOW_TYPE_GEN, flow_idx);
   12022                 :          0 :         return 0;
   12023                 :            : }
   12024                 :            : 
   12025                 :            : void *
   12026                 :          0 : rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
   12027                 :            :                                       const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
   12028                 :            :                                       uint8_t nb_options)
   12029                 :            : {
   12030                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
   12031                 :          0 :         return mlx5_geneve_tlv_parser_create(port_id, tlv_list, nb_options);
   12032                 :            : #else
   12033                 :            :         (void)port_id;
   12034                 :            :         (void)tlv_list;
   12035                 :            :         (void)nb_options;
   12036                 :            :         DRV_LOG(ERR, "%s is not supported.", __func__);
   12037                 :            :         rte_errno = ENOTSUP;
   12038                 :            :         return NULL;
   12039                 :            : #endif
   12040                 :            : }
   12041                 :            : 
   12042                 :            : int
   12043                 :          0 : rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle)
   12044                 :            : {
   12045                 :            : #ifdef HAVE_MLX5_HWS_SUPPORT
   12046                 :          0 :         return mlx5_geneve_tlv_parser_destroy(handle);
   12047                 :            : #else
   12048                 :            :         (void)handle;
   12049                 :            :         DRV_LOG(ERR, "%s is not supported.", __func__);
   12050                 :            :         rte_errno = ENOTSUP;
   12051                 :            :         return -rte_errno;
   12052                 :            : #endif
   12053                 :            : }

Generated by: LCOV version 1.14