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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2025 NVIDIA Corporation & Affiliates
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_flow.h>
       6                 :            : #include "mlx5_malloc.h"
       7                 :            : #include "mlx5.h"
       8                 :            : #include "mlx5_defs.h"
       9                 :            : #include "mlx5_flow.h"
      10                 :            : #include "mlx5_rx.h"
      11                 :            : 
      12                 :            : SLIST_HEAD(mlx5_flow_head, rte_flow_hw);
      13                 :            : 
      14                 :            : struct mlx5_nta_sample_ctx {
      15                 :            :         uint32_t groups_num;
      16                 :            :         struct mlx5_indexed_pool *group_ids;
      17                 :            :         struct mlx5_list *mirror_actions; /* cache FW mirror actions */
      18                 :            :         struct mlx5_list *mirror_groups; /* cache groups for sample and suffix actions */
      19                 :            : };
      20                 :            : 
      21                 :            : static void
      22                 :            : release_chained_flows(struct rte_eth_dev *dev, struct mlx5_flow_head *flow_head,
      23                 :            :                       enum mlx5_flow_type type)
      24                 :            : {
      25                 :            :         struct rte_flow_hw *flow = SLIST_FIRST(flow_head);
      26                 :            : 
      27                 :            :         if (flow) {
      28                 :          0 :                 flow->nt2hws->chaned_flow = 0;
      29                 :          0 :                 flow_hw_list_destroy(dev, type, (uintptr_t)flow);
      30                 :            :         }
      31                 :          0 : }
      32                 :            : 
      33                 :            : static void
      34                 :            : release_cached_group(struct rte_eth_dev *dev, uint32_t group)
      35                 :            : {
      36                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      37                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
      38                 :            : 
      39                 :          0 :         mlx5_ipool_free(ctx->group_ids, group - MLX5_FLOW_TABLE_SAMPLE_BASE);
      40                 :          0 : }
      41                 :            : 
      42                 :            : static uint32_t
      43                 :          0 : alloc_cached_group(struct rte_eth_dev *dev)
      44                 :            : {
      45                 :            :         void *obj;
      46                 :          0 :         uint32_t idx = 0;
      47                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      48                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
      49                 :            : 
      50                 :          0 :         obj = mlx5_ipool_malloc(ctx->group_ids, &idx);
      51         [ #  # ]:          0 :         if (obj == NULL)
      52                 :            :                 return 0;
      53                 :          0 :         return idx + MLX5_FLOW_TABLE_SAMPLE_BASE;
      54                 :            : }
      55                 :            : 
      56                 :            : void
      57                 :          0 : mlx5_nta_sample_context_free(struct rte_eth_dev *dev)
      58                 :            : {
      59                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
      60                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
      61                 :            : 
      62         [ #  # ]:          0 :         if (ctx == NULL)
      63                 :            :                 return;
      64         [ #  # ]:          0 :         if (ctx->mirror_groups != NULL)
      65                 :          0 :                 mlx5_list_destroy(ctx->mirror_groups);
      66         [ #  # ]:          0 :         if (ctx->group_ids != NULL)
      67                 :          0 :                 mlx5_ipool_destroy(ctx->group_ids);
      68         [ #  # ]:          0 :         if (ctx->mirror_actions != NULL)
      69                 :          0 :                 mlx5_list_destroy(ctx->mirror_actions);
      70                 :          0 :         mlx5_free(ctx);
      71                 :          0 :         priv->nta_sample_ctx = NULL;
      72                 :            : }
      73                 :            : 
      74                 :            : struct mlx5_nta_sample_cached_group {
      75                 :            :         const struct rte_flow_action *actions;
      76                 :            :         size_t actions_size;
      77                 :            :         uint32_t group;
      78                 :            :         struct mlx5_list_entry entry;
      79                 :            : };
      80                 :            : 
      81                 :            : struct mlx5_nta_sample_cached_group_ctx {
      82                 :            :         struct rte_flow_action *actions;
      83                 :            :         size_t actions_size;
      84                 :            : };
      85                 :            : 
      86                 :            : struct mlx5_nta_sample_cached_mirror {
      87                 :            :         struct mlx5_flow_template_table_cfg table_cfg;
      88                 :            :         struct mlx5_list_entry *sample;
      89                 :            :         struct mlx5_list_entry *suffix;
      90                 :            :         struct mlx5_mirror *mirror;
      91                 :            :         struct mlx5_list_entry entry;
      92                 :            : };
      93                 :            : 
      94                 :            : struct mlx5_nta_sample_cached_mirror_ctx {
      95                 :            :         struct mlx5_flow_template_table_cfg *table_cfg;
      96                 :            :         struct mlx5_list_entry *sample;
      97                 :            :         struct mlx5_list_entry *suffix;
      98                 :            : };
      99                 :            : 
     100                 :            : static struct mlx5_mirror *
     101                 :            : mirror_entry_to_mirror_action(struct mlx5_list_entry *entry)
     102                 :            : {
     103                 :          0 :         return container_of(entry, struct mlx5_nta_sample_cached_mirror, entry)->mirror;
     104                 :            : }
     105                 :            : 
     106                 :            : static uint32_t
     107                 :            : mirror_entry_to_mirror_sample_group(struct mlx5_list_entry *entry)
     108                 :            : {
     109                 :          0 :         struct mlx5_list_entry *sample = container_of(entry,
     110                 :            :                                                       struct mlx5_nta_sample_cached_mirror,
     111                 :            :                                                       entry)->sample;
     112                 :            : 
     113                 :          0 :         return container_of(sample, struct mlx5_nta_sample_cached_group, entry)->group;
     114                 :            : }
     115                 :            : 
     116                 :            : static uint32_t
     117                 :            : mirror_entry_to_mirror_suffix_group(struct mlx5_list_entry *entry)
     118                 :            : {
     119                 :          0 :         struct mlx5_list_entry *suffix = container_of(entry,
     120                 :            :                                                       struct mlx5_nta_sample_cached_mirror,
     121                 :            :                                                       entry)->suffix;
     122                 :            : 
     123                 :          0 :         return container_of(suffix, struct mlx5_nta_sample_cached_group, entry)->group;
     124                 :            : }
     125                 :            : 
     126                 :            : static struct mlx5_list_entry *
     127                 :          0 : mlx5_nta_sample_cached_mirror_create(void *cache_ctx, void *cb_ctx)
     128                 :            : {
     129                 :            :         struct rte_eth_dev *dev = cache_ctx;
     130                 :            :         struct mlx5_nta_sample_cached_mirror_ctx *ctx = cb_ctx;
     131                 :          0 :         struct rte_flow_action_jump sample_jump_conf = {
     132                 :          0 :                 .group = container_of(ctx->sample,
     133                 :          0 :                                       struct mlx5_nta_sample_cached_group, entry)->group
     134                 :            :         };
     135                 :          0 :         struct rte_flow_action_jump suffix_jump_conf = {
     136                 :          0 :                 .group = container_of(ctx->suffix,
     137                 :          0 :                                       struct mlx5_nta_sample_cached_group, entry)->group
     138                 :            :         };
     139                 :          0 :         struct rte_flow_action mirror_sample_actions[2] = {
     140                 :            :                 [0] = {
     141                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
     142                 :            :                         .conf = &sample_jump_conf,
     143                 :            :                 },
     144                 :            :                 [1] = {
     145                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END
     146                 :            :                 }
     147                 :            :         };
     148                 :          0 :         struct rte_flow_action_sample mirror_conf = {
     149                 :            :                 .ratio = 1,
     150                 :            :                 .actions = mirror_sample_actions,
     151                 :            :         };
     152                 :          0 :         struct rte_flow_action mirror_actions[3] = {
     153                 :            :                 [0] = {
     154                 :            :                         .type = RTE_FLOW_ACTION_TYPE_SAMPLE,
     155                 :            :                         .conf = &mirror_conf,
     156                 :            :                 },
     157                 :            :                 [1] = {
     158                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
     159                 :            :                         .conf = &suffix_jump_conf,
     160                 :            :                 },
     161                 :            :                 [2] = {
     162                 :            :                         .type = RTE_FLOW_ACTION_TYPE_END
     163                 :            :                 }
     164                 :            :         };
     165                 :          0 :         struct mlx5_nta_sample_cached_mirror *obj = mlx5_malloc(MLX5_MEM_ANY,
     166                 :            :                                                                 sizeof(*obj), 0,
     167                 :            :                                                                 SOCKET_ID_ANY);
     168         [ #  # ]:          0 :         if (obj == NULL)
     169                 :            :                 return NULL;
     170                 :          0 :         obj->mirror = mlx5_hw_create_mirror(dev, ctx->table_cfg, mirror_actions, NULL);
     171         [ #  # ]:          0 :         if (obj->mirror == NULL) {
     172                 :          0 :                 mlx5_free(obj);
     173                 :          0 :                 return NULL;
     174                 :            :         }
     175                 :          0 :         obj->sample = ctx->sample;
     176                 :          0 :         obj->suffix = ctx->suffix;
     177                 :          0 :         obj->table_cfg = *ctx->table_cfg;
     178                 :          0 :         return &obj->entry;
     179                 :            : }
     180                 :            : 
     181                 :            : static struct mlx5_list_entry *
     182                 :          0 : mlx5_nta_sample_cached_mirror_clone(void *tool_ctx __rte_unused,
     183                 :            :                                     struct mlx5_list_entry *entry,
     184                 :            :                                     void *cb_ctx __rte_unused)
     185                 :            : {
     186                 :            :         struct mlx5_nta_sample_cached_mirror *cached_obj =
     187                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_mirror, entry);
     188                 :          0 :         struct mlx5_nta_sample_cached_mirror *new_obj = mlx5_malloc(MLX5_MEM_ANY,
     189                 :            :                                                                     sizeof(*new_obj), 0,
     190                 :            :                                                                     SOCKET_ID_ANY);
     191                 :            : 
     192         [ #  # ]:          0 :         if (new_obj == NULL)
     193                 :            :                 return NULL;
     194                 :            :         memcpy(new_obj, cached_obj, sizeof(*new_obj));
     195                 :          0 :         return &new_obj->entry;
     196                 :            : }
     197                 :            : 
     198                 :            : static int
     199                 :          0 : mlx5_nta_sample_cached_mirror_match(void *cache_ctx __rte_unused,
     200                 :            :                                     struct mlx5_list_entry *entry, void *cb_ctx)
     201                 :            : {
     202                 :            :         bool match;
     203                 :            :         struct mlx5_nta_sample_cached_mirror_ctx *ctx = cb_ctx;
     204                 :            :         struct mlx5_nta_sample_cached_mirror *obj =
     205                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_mirror, entry);
     206                 :            : 
     207                 :          0 :         match = obj->sample == ctx->sample &&
     208   [ #  #  #  # ]:          0 :                 obj->suffix == ctx->suffix &&
     209         [ #  # ]:          0 :                 memcmp(&obj->table_cfg, ctx->table_cfg, sizeof(obj->table_cfg)) == 0;
     210                 :            : 
     211         [ #  # ]:          0 :         return match ? 0 : ~0;
     212                 :            : }
     213                 :            : 
     214                 :            : static void
     215                 :          0 : mlx5_nta_sample_cached_mirror_remove(void *cache_ctx, struct mlx5_list_entry *entry)
     216                 :            : {
     217                 :            :         struct rte_eth_dev *dev = cache_ctx;
     218                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     219                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
     220                 :            : 
     221                 :            :         struct mlx5_nta_sample_cached_mirror *obj =
     222                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_mirror, entry);
     223                 :          0 :         mlx5_hw_mirror_destroy(dev, obj->mirror);
     224                 :            : 
     225                 :          0 :         mlx5_list_unregister(ctx->mirror_groups, obj->sample);
     226                 :          0 :         mlx5_list_unregister(ctx->mirror_groups, obj->suffix);
     227                 :          0 :         mlx5_free(obj);
     228                 :          0 : }
     229                 :            : 
     230                 :            : static void
     231                 :          0 : mlx5_nta_sample_cached_mirror_free_cloned(void *cache_ctx __rte_unused,
     232                 :            :                                           struct mlx5_list_entry *entry)
     233                 :            : {
     234                 :            :         struct mlx5_nta_sample_cached_mirror *cloned_obj =
     235                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_mirror, entry);
     236                 :            : 
     237                 :          0 :         mlx5_free(cloned_obj);
     238                 :          0 : }
     239                 :            : 
     240                 :            : static int
     241                 :          0 : serialize_actions(struct mlx5_nta_sample_cached_group_ctx *obj_ctx)
     242                 :            : {
     243         [ #  # ]:          0 :         if (obj_ctx->actions_size == 0) {
     244                 :            :                 uint8_t *tgt_buffer;
     245                 :          0 :                 int size = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, NULL, 0, obj_ctx->actions, NULL);
     246         [ #  # ]:          0 :                 if (size < 0)
     247                 :            :                         return size;
     248                 :          0 :                 tgt_buffer = mlx5_malloc(MLX5_MEM_ANY, size, 0, SOCKET_ID_ANY);
     249         [ #  # ]:          0 :                 if (tgt_buffer == NULL)
     250                 :            :                         return -ENOMEM;
     251                 :          0 :                 obj_ctx->actions_size = size;
     252                 :          0 :                 size = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, tgt_buffer, size,
     253                 :          0 :                                      obj_ctx->actions, NULL);
     254         [ #  # ]:          0 :                 if (size < 0) {
     255                 :          0 :                         mlx5_free(tgt_buffer);
     256                 :          0 :                         return size;
     257                 :            :                 }
     258                 :          0 :                 obj_ctx->actions = (struct rte_flow_action *)tgt_buffer;
     259                 :            :         }
     260                 :          0 :         return obj_ctx->actions_size;
     261                 :            : }
     262                 :            : 
     263                 :            : static struct mlx5_list_entry *
     264                 :          0 : mlx5_nta_sample_cached_group_create(void *cache_ctx, void *cb_ctx)
     265                 :            : {
     266                 :            :         struct rte_eth_dev *dev = cache_ctx;
     267                 :            :         struct mlx5_nta_sample_cached_group_ctx *obj_ctx = cb_ctx;
     268                 :            :         struct mlx5_nta_sample_cached_group *obj;
     269                 :          0 :         int actions_size = serialize_actions(obj_ctx);
     270                 :            : 
     271         [ #  # ]:          0 :         if (actions_size < 0)
     272                 :            :                 return NULL;
     273                 :          0 :         obj = mlx5_malloc(MLX5_MEM_ANY, sizeof(*obj), 0, SOCKET_ID_ANY);
     274         [ #  # ]:          0 :         if (obj == NULL)
     275                 :            :                 return NULL;
     276                 :          0 :         obj->group = alloc_cached_group(dev);
     277         [ #  # ]:          0 :         if (obj->group == 0) {
     278                 :          0 :                 mlx5_free(obj);
     279                 :          0 :                 return NULL;
     280                 :            :         }
     281                 :          0 :         obj->actions = obj_ctx->actions;
     282                 :          0 :         obj->actions_size = obj_ctx->actions_size;
     283                 :          0 :         return &obj->entry;
     284                 :            : }
     285                 :            : 
     286                 :            : static int
     287                 :          0 : mlx5_nta_sample_cached_group_match(void *cache_ctx __rte_unused,
     288                 :            :                                    struct mlx5_list_entry *entry, void *cb_ctx)
     289                 :            : {
     290                 :            :         struct mlx5_nta_sample_cached_group_ctx *obj_ctx = cb_ctx;
     291                 :          0 :         int actions_size = serialize_actions(obj_ctx);
     292                 :            :         struct mlx5_nta_sample_cached_group *cached_obj =
     293                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_group, entry);
     294         [ #  # ]:          0 :         if (actions_size < 0)
     295                 :            :                 return ~0;
     296                 :          0 :         return memcmp(cached_obj->actions, obj_ctx->actions, actions_size);
     297                 :            : }
     298                 :            : 
     299                 :            : static void
     300                 :          0 : mlx5_nta_sample_cached_group_remove(void *cache_ctx, struct mlx5_list_entry *entry)
     301                 :            : {
     302                 :            :         struct rte_eth_dev *dev = cache_ctx;
     303                 :            :         struct mlx5_nta_sample_cached_group *cached_obj =
     304                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_group, entry);
     305                 :            : 
     306                 :          0 :         release_cached_group(dev, cached_obj->group);
     307                 :          0 :         mlx5_free((void *)(uintptr_t)cached_obj->actions);
     308                 :          0 :         mlx5_free(cached_obj);
     309                 :          0 : }
     310                 :            : 
     311                 :            : static struct mlx5_list_entry *
     312                 :          0 : mlx5_nta_sample_cached_group_clone(void *tool_ctx __rte_unused,
     313                 :            :                                    struct mlx5_list_entry *entry,
     314                 :            :                                    void *cb_ctx __rte_unused)
     315                 :            : {
     316                 :            :         struct mlx5_nta_sample_cached_group *cached_obj =
     317                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_group, entry);
     318                 :            :         struct mlx5_nta_sample_cached_group *new_obj;
     319                 :            : 
     320                 :          0 :         new_obj = mlx5_malloc(MLX5_MEM_ANY, sizeof(*new_obj), 0, SOCKET_ID_ANY);
     321         [ #  # ]:          0 :         if (new_obj == NULL)
     322                 :            :                 return NULL;
     323                 :            :         memcpy(new_obj, cached_obj, sizeof(*new_obj));
     324                 :          0 :         return &new_obj->entry;
     325                 :            : }
     326                 :            : 
     327                 :            : static void
     328                 :          0 : mlx5_nta_sample_cached_group_free_cloned(void *cache_ctx __rte_unused,
     329                 :            :                                          struct mlx5_list_entry *entry)
     330                 :            : {
     331                 :            :         struct mlx5_nta_sample_cached_group *cloned_obj =
     332                 :          0 :                 container_of(entry, struct mlx5_nta_sample_cached_group, entry);
     333                 :            : 
     334                 :          0 :         mlx5_free(cloned_obj);
     335                 :          0 : }
     336                 :            : 
     337                 :            : static int
     338                 :          0 : mlx5_init_nta_sample_context(struct rte_eth_dev *dev)
     339                 :            : {
     340                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     341                 :          0 :         struct mlx5_indexed_pool_config ipool_cfg = {
     342                 :            :                 .size = 0,
     343                 :            :                 .trunk_size = 32,
     344                 :            :                 .grow_trunk = 5,
     345                 :            :                 .grow_shift = 1,
     346                 :            :                 .need_lock = 1,
     347                 :          0 :                 .release_mem_en = !!priv->sh->config.reclaim_mode,
     348                 :            :                 .max_idx = MLX5_FLOW_TABLE_SAMPLE_NUM,
     349                 :            :                 .type = "mlx5_nta_sample"
     350                 :            :         };
     351                 :          0 :         struct mlx5_nta_sample_ctx *ctx = mlx5_malloc(MLX5_MEM_ZERO,
     352                 :            :                                                       sizeof(*ctx), 0, SOCKET_ID_ANY);
     353                 :            : 
     354         [ #  # ]:          0 :         if (ctx == NULL)
     355                 :            :                 return -ENOMEM;
     356                 :          0 :         priv->nta_sample_ctx = ctx;
     357                 :          0 :         ctx->group_ids = mlx5_ipool_create(&ipool_cfg);
     358         [ #  # ]:          0 :         if (ctx->group_ids == NULL)
     359                 :          0 :                 goto error;
     360                 :          0 :         ctx->mirror_groups = mlx5_list_create("nta sample groups", dev, true,
     361                 :            :                                               mlx5_nta_sample_cached_group_create,
     362                 :            :                                               mlx5_nta_sample_cached_group_match,
     363                 :            :                                               mlx5_nta_sample_cached_group_remove,
     364                 :            :                                               mlx5_nta_sample_cached_group_clone,
     365                 :            :                                               mlx5_nta_sample_cached_group_free_cloned);
     366         [ #  # ]:          0 :         if (ctx->mirror_groups == NULL)
     367                 :          0 :                 goto error;
     368                 :          0 :         ctx->mirror_actions = mlx5_list_create("nta sample mirror actions", dev, true,
     369                 :            :                                                mlx5_nta_sample_cached_mirror_create,
     370                 :            :                                                mlx5_nta_sample_cached_mirror_match,
     371                 :            :                                                mlx5_nta_sample_cached_mirror_remove,
     372                 :            :                                                mlx5_nta_sample_cached_mirror_clone,
     373                 :            :                                                mlx5_nta_sample_cached_mirror_free_cloned);
     374         [ #  # ]:          0 :         if (ctx->mirror_actions == NULL)
     375                 :          0 :                 goto error;
     376                 :            :         return 0;
     377                 :            : 
     378                 :          0 : error:
     379                 :          0 :         mlx5_nta_sample_context_free(dev);
     380                 :          0 :         return -ENOMEM;
     381                 :            : }
     382                 :            : 
     383                 :            : static struct mlx5_list_entry *
     384                 :            : register_mirror(struct mlx5_flow_template_table_cfg *table_cfg,
     385                 :            :                 struct mlx5_list *cache,
     386                 :            :                 struct mlx5_list_entry *sample,
     387                 :            :                 struct mlx5_list_entry *suffix)
     388                 :            : {
     389                 :          0 :         struct mlx5_nta_sample_cached_mirror_ctx ctx = {
     390                 :            :                 .table_cfg = table_cfg,
     391                 :            :                 .sample = sample,
     392                 :            :                 .suffix = suffix
     393                 :            :         };
     394                 :            : 
     395                 :          0 :         return mlx5_list_register(cache, &ctx);
     396                 :            : }
     397                 :            : 
     398                 :            : static struct mlx5_list_entry *
     399                 :            : register_mirror_actions(struct rte_flow_action *actions, struct mlx5_list *cache)
     400                 :            : {
     401                 :          0 :         struct mlx5_nta_sample_cached_group_ctx ctx = {
     402                 :            :                 .actions = actions
     403                 :            :         };
     404                 :          0 :         return mlx5_list_register(cache, &ctx);
     405                 :            : }
     406                 :            : 
     407                 :            : void
     408                 :          0 : mlx5_nta_sample_mirror_entry_release(struct rte_eth_dev *dev,
     409                 :            :                                      struct mlx5_sample_release_ctx *release)
     410                 :            : {
     411                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     412                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
     413                 :            : 
     414                 :          0 :         mlx5_list_unregister(ctx->mirror_actions, release->mirror_entry);
     415                 :          0 :         release_cached_group(dev, release->sample_group);
     416                 :          0 :         mlx5_free(release);
     417                 :          0 : }
     418                 :            : 
     419                 :            : static struct mlx5_list_entry *
     420                 :          0 : mlx5_create_nta_mirror(struct rte_eth_dev *dev,
     421                 :            :                        const struct rte_flow_attr *attr,
     422                 :            :                        struct rte_flow_action *sample_actions,
     423                 :            :                        struct rte_flow_action *suffix_actions,
     424                 :            :                        struct rte_flow_error *error)
     425                 :            : {
     426                 :            :         struct mlx5_list_entry *entry;
     427                 :            :         struct mlx5_list_entry *mirror_sample = NULL, *mirror_suffix = NULL;
     428                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     429                 :          0 :         struct mlx5_nta_sample_ctx *ctx = priv->nta_sample_ctx;
     430                 :          0 :         struct mlx5_flow_template_table_cfg table_cfg = {
     431                 :            :                 .external = true,
     432                 :            :                 .attr = {
     433                 :            :                         .flow_attr = *attr
     434                 :            :                 }
     435                 :            :         };
     436                 :            : 
     437                 :          0 :         mirror_sample = register_mirror_actions(sample_actions, ctx->mirror_groups);
     438         [ #  # ]:          0 :         if (mirror_sample == NULL) {
     439                 :          0 :                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
     440                 :            :                                            NULL, "Failed to register sample group");
     441                 :          0 :                 goto error;
     442                 :            :         }
     443                 :          0 :         mirror_suffix = register_mirror_actions(suffix_actions, ctx->mirror_groups);
     444         [ #  # ]:          0 :         if (mirror_suffix == NULL) {
     445                 :          0 :                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
     446                 :            :                                            NULL, "Failed to register suffix group");
     447                 :          0 :                 goto error;
     448                 :            :         }
     449                 :          0 :         entry = register_mirror(&table_cfg, ctx->mirror_actions, mirror_sample, mirror_suffix);
     450         [ #  # ]:          0 :         if (entry == NULL) {
     451                 :          0 :                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
     452                 :            :                         NULL, "Failed to register HWS mirror action");
     453                 :          0 :                 goto error;
     454                 :            :         }
     455                 :            : 
     456                 :            :         return entry;
     457                 :            : 
     458                 :          0 : error:
     459         [ #  # ]:          0 :         if (mirror_sample)
     460                 :          0 :                 mlx5_list_unregister(ctx->mirror_groups, mirror_sample);
     461         [ #  # ]:          0 :         if (mirror_suffix)
     462                 :          0 :                 mlx5_list_unregister(ctx->mirror_groups, mirror_suffix);
     463                 :            :         return NULL;
     464                 :            : }
     465                 :            : 
     466                 :            : static uint32_t
     467                 :          0 : generate_random_mask(uint32_t ratio)
     468                 :            : {
     469                 :            :         uint32_t i;
     470         [ #  # ]:          0 :         double goal = 1.0 / ratio;
     471                 :            : 
     472                 :            :         /* Check if the ratio value is power of 2 */
     473         [ #  # ]:          0 :         if (rte_popcount32(ratio) == 1) {
     474         [ #  # ]:          0 :                 for (i = 2; i < 32; i++) {
     475         [ #  # ]:          0 :                         if (RTE_BIT32(i) == ratio)
     476                 :          0 :                                 return RTE_BIT32(i) - 1;
     477                 :            :                 }
     478                 :            :         }
     479                 :            : 
     480                 :            :         /*
     481                 :            :          * Find the last power of 2 with ratio larger then the goal.
     482                 :            :          */
     483         [ #  # ]:          0 :         for (i = 2; i < 32; i++) {
     484                 :          0 :                 double res = 1.0 / RTE_BIT32(i);
     485                 :            : 
     486         [ #  # ]:          0 :                 if (res < goal)
     487                 :          0 :                         return RTE_BIT32(i - 1) - 1;
     488                 :            :         }
     489                 :            : 
     490                 :            :         return UINT32_MAX;
     491                 :            : }
     492                 :            : 
     493                 :            : static void
     494                 :          0 : mlx5_nta_parse_sample_actions(const struct rte_flow_action *action,
     495                 :            :                               const struct rte_flow_action **sample_action,
     496                 :            :                               struct rte_flow_action *prefix_actions,
     497                 :            :                               struct rte_flow_action *suffix_actions)
     498                 :            : {
     499                 :            :         struct rte_flow_action *pa = prefix_actions;
     500                 :            :         struct rte_flow_action *sa = suffix_actions;
     501                 :            : 
     502                 :          0 :         *sample_action = NULL;
     503                 :            :         do {
     504         [ #  # ]:          0 :                 if (action->type == RTE_FLOW_ACTION_TYPE_SAMPLE) {
     505                 :          0 :                         *sample_action = action;
     506         [ #  # ]:          0 :                 } else if (*sample_action == NULL) {
     507         [ #  # ]:          0 :                         if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
     508                 :          0 :                                 continue;
     509                 :          0 :                         *(pa++) = *action;
     510                 :            :                 } else {
     511         [ #  # ]:          0 :                         if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
     512                 :          0 :                                 continue;
     513                 :          0 :                         *(sa++) = *action;
     514                 :            :                 }
     515         [ #  # ]:          0 :         } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END);
     516                 :          0 : }
     517                 :            : 
     518                 :            : static bool
     519                 :            : validate_prefix_actions(const struct rte_flow_action *actions)
     520                 :            : {
     521                 :            :         uint32_t i = 0;
     522                 :            : 
     523         [ #  # ]:          0 :         while (actions[i].type != RTE_FLOW_ACTION_TYPE_END)
     524                 :          0 :                 i++;
     525                 :            :         return i < MLX5_HW_MAX_ACTS - 1;
     526                 :            : }
     527                 :            : 
     528                 :            : static bool
     529                 :          0 : validate_sample_terminal_actions(const struct rte_eth_dev *dev,
     530                 :            :                                  const struct rte_flow_attr *flow_attr,
     531                 :            :                                  const struct rte_flow_action *actions)
     532                 :            : {
     533                 :            :         uint32_t i;
     534                 :          0 :         const struct mlx5_priv *priv = dev->data->dev_private;
     535                 :            :         const struct rte_flow_action_ethdev *port = NULL;
     536   [ #  #  #  # ]:          0 :         bool is_proxy = MLX5_HW_PORT_IS_PROXY(priv);
     537                 :            :         const struct rte_flow_action *a = NULL;
     538                 :            : 
     539         [ #  # ]:          0 :         for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
     540         [ #  # ]:          0 :                 if (actions[i].type != RTE_FLOW_ACTION_TYPE_VOID)
     541                 :            :                         a = &actions[i];
     542                 :            :         }
     543         [ #  # ]:          0 :         if (a == NULL)
     544                 :            :                 return false;
     545      [ #  #  # ]:          0 :         switch (a->type) {
     546                 :            :         case RTE_FLOW_ACTION_TYPE_JUMP:
     547                 :            :         case RTE_FLOW_ACTION_TYPE_QUEUE:
     548                 :            :         case RTE_FLOW_ACTION_TYPE_DROP:
     549                 :            :         case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
     550                 :            :                 return true;
     551                 :          0 :         case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
     552   [ #  #  #  # ]:          0 :                 if (!is_proxy || !flow_attr->transfer)
     553                 :            :                         return false;
     554                 :          0 :                 port = a->conf;
     555   [ #  #  #  # ]:          0 :                 if (!port || port->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
     556                 :          0 :                         return false;
     557                 :            :                 return true;
     558                 :            :         default:
     559                 :            :                 break;
     560                 :            :         }
     561                 :          0 :         return false;
     562                 :            : }
     563                 :            : 
     564                 :            : static void
     565                 :            : action_append(struct rte_flow_action *actions, const struct rte_flow_action *last)
     566                 :            : {
     567                 :            :         uint32_t i = 0;
     568                 :            : 
     569   [ #  #  #  # ]:          0 :         while (actions[i].type != RTE_FLOW_ACTION_TYPE_END)
     570                 :          0 :                 i++;
     571                 :          0 :         actions[i] = *last;
     572                 :            : }
     573                 :            : 
     574                 :            : static int
     575                 :          0 : create_mirror_aux_flows(struct rte_eth_dev *dev,
     576                 :            :                         enum mlx5_flow_type type,
     577                 :            :                         const struct rte_flow_attr *attr,
     578                 :            :                         struct rte_flow_action *suffix_actions,
     579                 :            :                         struct rte_flow_action *sample_actions,
     580                 :            :                         struct mlx5_list_entry *mirror_entry,
     581                 :            :                         struct mlx5_flow_head *flow_head,
     582                 :            :                         struct rte_flow_error *error)
     583                 :            : {
     584                 :          0 :         const struct rte_flow_attr suffix_attr = {
     585                 :          0 :                 .ingress = attr->ingress,
     586                 :          0 :                 .egress = attr->egress,
     587                 :          0 :                 .transfer = attr->transfer,
     588                 :            :                 .group = mirror_entry_to_mirror_suffix_group(mirror_entry),
     589                 :            :         };
     590                 :          0 :         const struct rte_flow_attr sample_attr = {
     591                 :            :                 .ingress = attr->ingress,
     592                 :            :                 .egress = attr->egress,
     593                 :            :                 .transfer = attr->transfer,
     594                 :            :                 .group = mirror_entry_to_mirror_sample_group(mirror_entry),
     595                 :            :         };
     596                 :          0 :         const struct rte_flow_item secondary_pattern[1] = {
     597                 :            :                 [0] = { .type = RTE_FLOW_ITEM_TYPE_END }
     598                 :            :         };
     599                 :            :         int ret, encap_idx, actions_num;
     600                 :            :         uint64_t suffix_action_flags, sample_action_flags;
     601                 :          0 :         const struct rte_flow_action *qrss_action = NULL, *mark_action = NULL;
     602                 :          0 :         struct rte_flow_hw *suffix_flow = NULL, *sample_flow = NULL;
     603                 :            : 
     604                 :          0 :         suffix_action_flags = mlx5_flow_hw_action_flags_get(suffix_actions,
     605                 :            :                                                        &qrss_action, &mark_action,
     606                 :            :                                                        &encap_idx, &actions_num, error);
     607   [ #  #  #  # ]:          0 :         if (qrss_action != NULL && qrss_action->type == RTE_FLOW_ACTION_TYPE_RSS)
     608                 :          0 :                 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
     609                 :            :                         "RSS action is not supported in suffix sample action");
     610                 :          0 :         sample_action_flags = mlx5_flow_hw_action_flags_get(sample_actions,
     611                 :            :                                                        &qrss_action, &mark_action,
     612                 :            :                                                        &encap_idx, &actions_num, error);
     613   [ #  #  #  # ]:          0 :         if (qrss_action != NULL && qrss_action->type == RTE_FLOW_ACTION_TYPE_RSS)
     614                 :          0 :                 return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
     615                 :            :                         "RSS action is not supported in sample action");
     616                 :          0 :         ret = flow_hw_create_flow(dev, type, &suffix_attr,
     617                 :            :                                   secondary_pattern, suffix_actions,
     618                 :            :                                   MLX5_FLOW_LAYER_OUTER_L2, suffix_action_flags,
     619                 :            :                                   true, &suffix_flow, error);
     620         [ #  # ]:          0 :         if (ret != 0)
     621                 :            :                 return ret;
     622                 :          0 :         ret = flow_hw_create_flow(dev, type, &sample_attr,
     623                 :            :                                   secondary_pattern, sample_actions,
     624                 :            :                                   MLX5_FLOW_LAYER_OUTER_L2, sample_action_flags,
     625                 :            :                                   true, &sample_flow, error);
     626         [ #  # ]:          0 :         if (ret != 0) {
     627                 :          0 :                 flow_hw_destroy(dev, suffix_flow);
     628                 :          0 :                 return ret;
     629                 :            :         }
     630                 :          0 :         suffix_flow->nt2hws->chaned_flow = 1;
     631                 :          0 :         SLIST_INSERT_HEAD(flow_head, suffix_flow, nt2hws->next);
     632                 :          0 :         sample_flow->nt2hws->chaned_flow = 1;
     633                 :          0 :         SLIST_INSERT_HEAD(flow_head, sample_flow, nt2hws->next);
     634                 :          0 :         return 0;
     635                 :            : }
     636                 :            : 
     637                 :            : static struct rte_flow_hw *
     638                 :          0 : create_sample_flow(struct rte_eth_dev *dev,
     639                 :            :                    enum mlx5_flow_type type,
     640                 :            :                    const struct rte_flow_attr *attr,
     641                 :            :                    uint32_t ratio,
     642                 :            :                    uint32_t sample_group,
     643                 :            :                    struct mlx5_list_entry *mirror_entry,
     644                 :            :                    struct rte_flow_error *error)
     645                 :            : {
     646                 :          0 :         struct rte_flow_hw *sample_flow = NULL;
     647                 :          0 :         uint32_t random_mask = generate_random_mask(ratio);
     648                 :          0 :         const struct rte_flow_attr sample_attr = {
     649                 :          0 :                 .ingress = attr->ingress,
     650                 :          0 :                 .egress = attr->egress,
     651                 :          0 :                 .transfer = attr->transfer,
     652                 :            :                 .group = sample_group,
     653                 :            :         };
     654                 :          0 :         const struct rte_flow_item sample_pattern[2] = {
     655                 :            :                 [0] = {
     656                 :            :                         .type = RTE_FLOW_ITEM_TYPE_RANDOM,
     657                 :          0 :                         .mask = &(struct rte_flow_item_random) {
     658                 :            :                                 .value = random_mask
     659                 :            :                         },
     660                 :          0 :                         .spec = &(struct rte_flow_item_random) {
     661                 :            :                                 .value = 1
     662                 :            :                         },
     663                 :            :                 },
     664                 :            :                 [1] = { .type = RTE_FLOW_ITEM_TYPE_END }
     665                 :            :         };
     666                 :          0 :         const struct rte_flow_action sample_actions[2] = {
     667                 :            :                 [0] = {
     668                 :            :                         .type = (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_MIRROR,
     669                 :            :                         .conf = mirror_entry_to_mirror_action(mirror_entry)
     670                 :            :                 },
     671                 :            :                 [1] = { .type = RTE_FLOW_ACTION_TYPE_END }
     672                 :            :         };
     673                 :            : 
     674         [ #  # ]:          0 :         if (random_mask > UINT16_MAX)
     675                 :            :                 return NULL;
     676                 :          0 :         flow_hw_create_flow(dev, type, &sample_attr, sample_pattern, sample_actions,
     677                 :            :                             0, 0, true, &sample_flow, error);
     678                 :          0 :         return sample_flow;
     679                 :            : }
     680                 :            : 
     681                 :            : static int
     682                 :          0 : create_random_miss_actions(struct rte_eth_dev *dev,
     683                 :            :                            const struct rte_flow_attr *attr,
     684                 :            :                            uint32_t sample_group,
     685                 :            :                            struct mlx5_list_entry *mirror_entry,
     686                 :            :                            struct rte_flow_error *error)
     687                 :            : {
     688                 :          0 :         const struct rte_flow_group_attr sample_group_attr = {
     689                 :          0 :                 .ingress = attr->ingress,
     690                 :          0 :                 .egress = attr->egress,
     691                 :          0 :                 .transfer = attr->transfer,
     692                 :            :         };
     693                 :          0 :         const struct rte_flow_action sample_miss_actions[2] = {
     694                 :            :                 [0] = {
     695                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
     696                 :          0 :                         .conf = &(struct rte_flow_action_jump) {
     697                 :            :                                 .group = mirror_entry_to_mirror_suffix_group(mirror_entry)
     698                 :            :                         }
     699                 :            :                 },
     700                 :            :                 [1] = { .type = RTE_FLOW_ACTION_TYPE_END }
     701                 :            :         };
     702                 :            : 
     703                 :          0 :         return mlx5_flow_hw_group_set_miss_actions(dev, sample_group, &sample_group_attr,
     704                 :            :                                                    sample_miss_actions, error);
     705                 :            : }
     706                 :            : 
     707                 :            : static void
     708                 :            : save_sample_release_cxt(struct mlx5_sample_release_ctx *release,
     709                 :            :                         struct mlx5_flow_head *flow_head,
     710                 :            :                         struct mlx5_list_entry *mirror_entry,
     711                 :            :                         uint32_t sample_group)
     712                 :            : {
     713                 :            :         struct rte_flow_hw *var;
     714                 :            : 
     715                 :          0 :         release->mirror_entry = mirror_entry;
     716                 :          0 :         release->sample_group = sample_group;
     717                 :            : 
     718   [ #  #  #  # ]:          0 :         SLIST_FOREACH(var, flow_head, nt2hws->next) {
     719   [ #  #  #  # ]:          0 :                 if (SLIST_NEXT(var, nt2hws->next) == NULL)
     720                 :          0 :                         var->nt2hws->sample_release_ctx = release;
     721                 :            :         }
     722                 :            : }
     723                 :            : 
     724                 :            : static struct rte_flow_hw *
     725                 :          0 : mlx5_nta_create_sample_flow(struct rte_eth_dev *dev,
     726                 :            :                              enum mlx5_flow_type type,
     727                 :            :                              const struct rte_flow_attr *attr,
     728                 :            :                              uint32_t sample_ratio,
     729                 :            :                              uint64_t item_flags, uint64_t action_flags,
     730                 :            :                              const struct rte_flow_item *pattern,
     731                 :            :                              struct rte_flow_action *prefix_actions,
     732                 :            :                              struct rte_flow_action *suffix_actions,
     733                 :            :                              struct rte_flow_action *sample_actions,
     734                 :            :                              struct mlx5_list_entry *mirror_entry,
     735                 :            :                              struct mlx5_flow_head *flow_head,
     736                 :            :                              struct rte_flow_error *error)
     737                 :            : {
     738                 :            :         int ret;
     739                 :          0 :         uint32_t sample_group = alloc_cached_group(dev);
     740                 :          0 :         struct rte_flow_hw *base_flow = NULL, *sample_flow = NULL;
     741                 :            :         struct mlx5_sample_release_ctx *release = NULL;
     742                 :            : 
     743         [ #  # ]:          0 :         if (sample_group == 0)
     744                 :            :                 return NULL;
     745                 :          0 :         release = mlx5_malloc(MLX5_MEM_ANY, sizeof(*release), 0, SOCKET_ID_ANY);
     746         [ #  # ]:          0 :         if (release == NULL) {
     747                 :          0 :                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION,
     748                 :            :                                    NULL, "Failed to allocate release context");
     749                 :          0 :                 goto error;
     750                 :            :         }
     751                 :          0 :         ret = create_mirror_aux_flows(dev, type, attr,
     752                 :            :                                       suffix_actions, sample_actions,
     753                 :            :                                       mirror_entry, flow_head, error);
     754         [ #  # ]:          0 :         if (ret != 0)
     755                 :          0 :                 goto error;
     756                 :          0 :         ret = create_random_miss_actions(dev, attr, sample_group,
     757                 :            :                                                mirror_entry, error);
     758         [ #  # ]:          0 :         if (ret != 0)
     759                 :          0 :                 goto error;
     760                 :          0 :         sample_flow = create_sample_flow(dev, type, attr, sample_ratio, sample_group,
     761                 :            :                                          mirror_entry, error);
     762         [ #  # ]:          0 :         if (sample_flow == NULL)
     763                 :          0 :                 goto error;
     764                 :          0 :         sample_flow->nt2hws->chaned_flow = 1;
     765                 :          0 :         SLIST_INSERT_HEAD(flow_head, sample_flow, nt2hws->next);
     766                 :            :         action_append(prefix_actions,
     767                 :            :                 &(struct rte_flow_action) {
     768                 :            :                         .type = RTE_FLOW_ACTION_TYPE_JUMP,
     769                 :          0 :                         .conf = &(struct rte_flow_action_jump) { .group = sample_group }
     770                 :            :                 });
     771                 :          0 :         ret = flow_hw_create_flow(dev, type, attr, pattern, prefix_actions,
     772                 :            :                                   item_flags, action_flags, true, &base_flow, error);
     773         [ #  # ]:          0 :         if (ret != 0)
     774                 :          0 :                 goto error;
     775                 :          0 :         SLIST_INSERT_HEAD(flow_head, base_flow, nt2hws->next);
     776                 :            :         save_sample_release_cxt(release, flow_head, mirror_entry, sample_group);
     777                 :            :         return base_flow;
     778                 :            : 
     779                 :          0 : error:
     780         [ #  # ]:          0 :         if (!SLIST_EMPTY(flow_head))
     781                 :            :                 release_chained_flows(dev, flow_head, type);
     782         [ #  # ]:          0 :         if (release)
     783                 :          0 :                 mlx5_free(release);
     784         [ #  # ]:          0 :         if (sample_flow)
     785                 :            :                 release_cached_group(dev, sample_group);
     786                 :            :         return NULL;
     787                 :            : }
     788                 :            : 
     789                 :            : static struct rte_flow_hw *
     790                 :          0 : mlx5_nta_create_mirror_flow(struct rte_eth_dev *dev,
     791                 :            :                              enum mlx5_flow_type type,
     792                 :            :                              const struct rte_flow_attr *attr,
     793                 :            :                              uint64_t item_flags, uint64_t action_flags,
     794                 :            :                              const struct rte_flow_item *pattern,
     795                 :            :                              struct rte_flow_action *prefix_actions,
     796                 :            :                              struct rte_flow_action *suffix_actions,
     797                 :            :                              struct rte_flow_action *sample_actions,
     798                 :            :                              struct mlx5_list_entry *mirror_entry,
     799                 :            :                              struct mlx5_flow_head *flow_head,
     800                 :            :                              struct rte_flow_error *error)
     801                 :            : {
     802                 :            :         int ret;
     803                 :          0 :         struct rte_flow_hw *base_flow = NULL;
     804                 :          0 :         struct mlx5_sample_release_ctx *release = mlx5_malloc(MLX5_MEM_ANY, sizeof(*release),
     805                 :            :                                                               0, SOCKET_ID_ANY);
     806                 :            : 
     807         [ #  # ]:          0 :         if (release == NULL) {
     808                 :          0 :                 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION,
     809                 :            :                                    NULL, "Failed to allocate release context");
     810                 :          0 :                 return NULL;
     811                 :            :         }
     812                 :          0 :         ret = create_mirror_aux_flows(dev, type, attr,
     813                 :            :                                       suffix_actions, sample_actions,
     814                 :            :                                       mirror_entry, flow_head, error);
     815         [ #  # ]:          0 :         if (ret != 0)
     816                 :          0 :                 goto error;
     817                 :            :         action_append(prefix_actions,
     818                 :            :                 &(struct rte_flow_action) {
     819                 :            :                         .type = (enum rte_flow_action_type)MLX5_RTE_FLOW_ACTION_TYPE_MIRROR,
     820                 :            :                         .conf = mirror_entry_to_mirror_action(mirror_entry)
     821                 :            :                 });
     822                 :          0 :         ret = flow_hw_create_flow(dev, type, attr, pattern, prefix_actions,
     823                 :            :                                   item_flags, action_flags,
     824                 :            :                                   true, &base_flow, error);
     825         [ #  # ]:          0 :         if (ret != 0)
     826                 :          0 :                 goto error;
     827                 :          0 :         SLIST_INSERT_HEAD(flow_head, base_flow, nt2hws->next);
     828                 :            :         save_sample_release_cxt(release, flow_head, mirror_entry, 0);
     829                 :            :         return base_flow;
     830                 :            : 
     831                 :          0 : error:
     832         [ #  # ]:          0 :         if (!SLIST_EMPTY(flow_head))
     833                 :            :                 release_chained_flows(dev, flow_head, type);
     834                 :            :         if (release)
     835                 :          0 :                 mlx5_free(release);
     836                 :          0 :         return NULL;
     837                 :            : }
     838                 :            : 
     839                 :            : struct rte_flow_hw *
     840                 :          0 : mlx5_nta_sample_flow_list_create(struct rte_eth_dev *dev,
     841                 :            :                                  enum mlx5_flow_type type,
     842                 :            :                                  const struct rte_flow_attr *attr,
     843                 :            :                                  const struct rte_flow_item pattern[],
     844                 :            :                                  const struct rte_flow_action actions[],
     845                 :            :                                  uint64_t item_flags, uint64_t action_flags,
     846                 :            :                                  struct rte_flow_error *error)
     847                 :            : {
     848                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     849                 :            :         struct mlx5_list_entry *mirror_entry;
     850                 :            :         struct rte_flow_hw *flow = NULL;
     851                 :            :         const struct rte_flow_action *sample;
     852                 :            :         struct rte_flow_action *sample_actions;
     853                 :            :         const struct rte_flow_action_sample *sample_conf;
     854                 :          0 :         struct rte_flow_action prefix_actions[MLX5_HW_MAX_ACTS] = { 0 };
     855                 :          0 :         struct rte_flow_action suffix_actions[MLX5_HW_MAX_ACTS] = { 0 };
     856                 :          0 :         struct mlx5_flow_head flow_head = SLIST_HEAD_INITIALIZER(NULL);
     857                 :            : 
     858         [ #  # ]:          0 :         if (priv->nta_sample_ctx == NULL) {
     859                 :          0 :                 int rc = mlx5_init_nta_sample_context(dev);
     860         [ #  # ]:          0 :                 if (rc != 0) {
     861                 :          0 :                         rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_ACTION,
     862                 :            :                                            NULL, "Failed to allocate sample context");
     863                 :          0 :                         return NULL;
     864                 :            :                 }
     865                 :            :         }
     866                 :          0 :         mlx5_nta_parse_sample_actions(actions, &sample, prefix_actions, suffix_actions);
     867         [ #  # ]:          0 :         if (!validate_prefix_actions(prefix_actions)) {
     868                 :          0 :                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
     869                 :            :                                    NULL, "Too many actions");
     870                 :          0 :                 return NULL;
     871                 :            :         }
     872         [ #  # ]:          0 :         if (!validate_sample_terminal_actions(dev, attr, sample)) {
     873                 :          0 :                 rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
     874                 :            :                                    NULL, "Invalid sample actions");
     875                 :          0 :                 return NULL;
     876                 :            :         }
     877                 :          0 :         sample_conf = (const struct rte_flow_action_sample *)sample->conf;
     878                 :          0 :         sample_actions = (struct rte_flow_action *)(uintptr_t)sample_conf->actions;
     879                 :          0 :         mirror_entry = mlx5_create_nta_mirror(dev, attr, sample_actions,
     880                 :            :                                         suffix_actions, error);
     881         [ #  # ]:          0 :         if (mirror_entry == NULL)
     882                 :            :                 return NULL;
     883         [ #  # ]:          0 :         if (sample_conf->ratio == 1) {
     884                 :          0 :                 flow = mlx5_nta_create_mirror_flow(dev, type, attr, item_flags, action_flags,
     885                 :            :                                                    pattern, prefix_actions, suffix_actions,
     886                 :            :                                                    sample_actions, mirror_entry,
     887                 :            :                                                    &flow_head, error);
     888                 :            :         } else {
     889                 :          0 :                 flow = mlx5_nta_create_sample_flow(dev, type, attr, sample_conf->ratio,
     890                 :            :                                                    item_flags, action_flags, pattern,
     891                 :            :                                                    prefix_actions, suffix_actions,
     892                 :            :                                                    sample_actions, mirror_entry,
     893                 :            :                                                    &flow_head, error);
     894                 :            :         }
     895         [ #  # ]:          0 :         if (flow == NULL)
     896                 :          0 :                 mlx5_list_unregister(priv->nta_sample_ctx->mirror_actions, mirror_entry);
     897                 :            :         return flow;
     898                 :            : }

Generated by: LCOV version 1.14