LCOV - code coverage report
Current view: top level - drivers/net/mlx5/hws - mlx5dr_action.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 2077 0.0 %
Date: 2026-12-01 19:01:22 Functions: 0 95 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1173 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2022 NVIDIA Corporation & Affiliates
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "mlx5dr_internal.h"
       6                 :            : 
       7                 :            : #define WIRE_PORT 0xFFFF
       8                 :            : 
       9                 :            : #define MLX5DR_ACTION_METER_INIT_COLOR_OFFSET 1
      10                 :            : /* Header removal size limited to 128B (64 words) */
      11                 :            : #define MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE 128
      12                 :            : 
      13                 :            : static struct mlx5dr_devx_obj *
      14                 :            : mlx5dr_action_get_stc_obj_by_tbl_type(enum mlx5dr_table_type table_type,
      15                 :            :                                       struct mlx5dr_pool *stc_pool,
      16                 :            :                                       struct mlx5dr_pool_chunk *stc,
      17                 :            :                                       bool is_mirror);
      18                 :            : 
      19                 :            : /* This is the maximum allowed action order for each table type:
      20                 :            :  *       TX: POP_VLAN, CTR, ASO_METER, AS_CT, PUSH_VLAN, MODIFY, ENCAP, Term
      21                 :            :  *       RX: TAG, DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
      22                 :            :  *           ENCAP, Term
      23                 :            :  *      FDB: DECAP, POP_VLAN, CTR, ASO_METER, ASO_CT, PUSH_VLAN, MODIFY,
      24                 :            :  *           ENCAP, Term
      25                 :            :  */
      26                 :            : static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_MAX] = {
      27                 :            :         [MLX5DR_TABLE_TYPE_NIC_RX] = {
      28                 :            :                 BIT(MLX5DR_ACTION_TYP_TAG),
      29                 :            :                 BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
      30                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
      31                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
      32                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
      33                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      34                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      35                 :            :                 BIT(MLX5DR_ACTION_TYP_CTR),
      36                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_METER),
      37                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_CT),
      38                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      39                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      40                 :            :                 BIT(MLX5DR_ACTION_TYP_NAT64),
      41                 :            :                 BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
      42                 :            :                 BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
      43                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
      44                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
      45                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
      46                 :            :                 BIT(MLX5DR_ACTION_TYP_TBL) |
      47                 :            :                 BIT(MLX5DR_ACTION_TYP_MISS) |
      48                 :            :                 BIT(MLX5DR_ACTION_TYP_TIR) |
      49                 :            :                 BIT(MLX5DR_ACTION_TYP_DROP) |
      50                 :            :                 BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
      51                 :            :                 BIT(MLX5DR_ACTION_TYP_DEST_ARRAY) |
      52                 :            :                 BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
      53                 :            :                 BIT(MLX5DR_ACTION_TYP_LAST),
      54                 :            :         },
      55                 :            :         [MLX5DR_TABLE_TYPE_NIC_TX] = {
      56                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      57                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      58                 :            :                 BIT(MLX5DR_ACTION_TYP_CTR),
      59                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_METER),
      60                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_CT),
      61                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      62                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      63                 :            :                 BIT(MLX5DR_ACTION_TYP_NAT64),
      64                 :            :                 BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
      65                 :            :                 BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
      66                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
      67                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
      68                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
      69                 :            :                 BIT(MLX5DR_ACTION_TYP_TBL) |
      70                 :            :                 BIT(MLX5DR_ACTION_TYP_MISS) |
      71                 :            :                 BIT(MLX5DR_ACTION_TYP_DROP) |
      72                 :            :                 BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
      73                 :            :                 BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
      74                 :            :                 BIT(MLX5DR_ACTION_TYP_LAST),
      75                 :            :         },
      76                 :            :         [MLX5DR_TABLE_TYPE_FDB] = {
      77                 :            :                 BIT(MLX5DR_ACTION_TYP_REMOVE_HEADER) |
      78                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
      79                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2) |
      80                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT),
      81                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      82                 :            :                 BIT(MLX5DR_ACTION_TYP_POP_VLAN),
      83                 :            :                 BIT(MLX5DR_ACTION_TYP_CTR),
      84                 :            :                 BIT(MLX5DR_ACTION_TYP_TAG),
      85                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_METER),
      86                 :            :                 BIT(MLX5DR_ACTION_TYP_ASO_CT),
      87                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      88                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_VLAN),
      89                 :            :                 BIT(MLX5DR_ACTION_TYP_NAT64),
      90                 :            :                 BIT(MLX5DR_ACTION_TYP_MODIFY_HDR),
      91                 :            :                 BIT(MLX5DR_ACTION_TYP_INSERT_HEADER) |
      92                 :            :                 BIT(MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT) |
      93                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
      94                 :            :                 BIT(MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
      95                 :            :                 BIT(MLX5DR_ACTION_TYP_TBL) |
      96                 :            :                 BIT(MLX5DR_ACTION_TYP_MISS) |
      97                 :            :                 BIT(MLX5DR_ACTION_TYP_TIR) |
      98                 :            :                 BIT(MLX5DR_ACTION_TYP_VPORT) |
      99                 :            :                 BIT(MLX5DR_ACTION_TYP_DROP) |
     100                 :            :                 BIT(MLX5DR_ACTION_TYP_DEST_ROOT) |
     101                 :            :                 BIT(MLX5DR_ACTION_TYP_DEST_ARRAY) |
     102                 :            :                 BIT(MLX5DR_ACTION_TYP_JUMP_TO_MATCHER),
     103                 :            :                 BIT(MLX5DR_ACTION_TYP_LAST),
     104                 :            :         },
     105                 :            : };
     106                 :            : 
     107                 :          0 : static int mlx5dr_action_get_shared_stc_nic(struct mlx5dr_context *ctx,
     108                 :            :                                             enum mlx5dr_context_shared_stc_type stc_type,
     109                 :            :                                             uint8_t tbl_type)
     110                 :            : {
     111                 :          0 :         struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
     112                 :            :         struct mlx5dr_action_shared_stc *shared_stc;
     113                 :            :         int ret;
     114                 :            : 
     115                 :          0 :         pthread_spin_lock(&ctx->ctrl_lock);
     116         [ #  # ]:          0 :         if (ctx->common_res[tbl_type].shared_stc[stc_type]) {
     117                 :          0 :                 ctx->common_res[tbl_type].shared_stc[stc_type]->refcount++;
     118                 :          0 :                 pthread_spin_unlock(&ctx->ctrl_lock);
     119                 :          0 :                 return 0;
     120                 :            :         }
     121                 :            : 
     122                 :            :         shared_stc = simple_calloc(1, sizeof(*shared_stc));
     123         [ #  # ]:          0 :         if (!shared_stc) {
     124                 :          0 :                 DR_LOG(ERR, "Failed to allocate memory for shared STCs");
     125                 :          0 :                 rte_errno = ENOMEM;
     126                 :          0 :                 goto unlock_and_out;
     127                 :            :         }
     128      [ #  #  # ]:          0 :         switch (stc_type) {
     129                 :          0 :         case MLX5DR_CONTEXT_SHARED_STC_DECAP_L3:
     130                 :          0 :                 stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
     131                 :          0 :                 stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
     132                 :          0 :                 stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
     133                 :          0 :                 stc_attr.remove_header.decap = 0;
     134                 :          0 :                 stc_attr.remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
     135                 :          0 :                 stc_attr.remove_header.end_anchor = MLX5_HEADER_ANCHOR_IPV6_IPV4;
     136                 :          0 :                 break;
     137                 :          0 :         case MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP:
     138                 :          0 :                 stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
     139                 :          0 :                 stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
     140                 :          0 :                 stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
     141                 :          0 :                 stc_attr.remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
     142                 :          0 :                 stc_attr.remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
     143                 :          0 :                 break;
     144                 :          0 :         default:
     145                 :          0 :                 DR_LOG(ERR, "No such type : stc_type");
     146                 :          0 :                 assert(false);
     147                 :            :                 rte_errno = EINVAL;
     148                 :            :                 goto unlock_and_out;
     149                 :            :         }
     150                 :            : 
     151                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
     152                 :            :                                              &shared_stc->remove_header);
     153         [ #  # ]:          0 :         if (ret) {
     154                 :          0 :                 DR_LOG(ERR, "Failed to allocate shared decap l2 STC");
     155                 :          0 :                 goto free_shared_stc;
     156                 :            :         }
     157                 :            : 
     158                 :          0 :         ctx->common_res[tbl_type].shared_stc[stc_type] = shared_stc;
     159                 :          0 :         ctx->common_res[tbl_type].shared_stc[stc_type]->refcount = 1;
     160                 :            : 
     161                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
     162                 :            : 
     163                 :          0 :         return 0;
     164                 :            : 
     165                 :            : free_shared_stc:
     166                 :            :         simple_free(shared_stc);
     167                 :          0 : unlock_and_out:
     168                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
     169                 :          0 :         return rte_errno;
     170                 :            : }
     171                 :            : 
     172                 :          0 : static void mlx5dr_action_put_shared_stc_nic(struct mlx5dr_context *ctx,
     173                 :            :                                              enum mlx5dr_context_shared_stc_type stc_type,
     174                 :            :                                              uint8_t tbl_type)
     175                 :            : {
     176                 :            :         struct mlx5dr_action_shared_stc *shared_stc;
     177                 :            : 
     178                 :          0 :         pthread_spin_lock(&ctx->ctrl_lock);
     179         [ #  # ]:          0 :         if (--ctx->common_res[tbl_type].shared_stc[stc_type]->refcount) {
     180                 :          0 :                 pthread_spin_unlock(&ctx->ctrl_lock);
     181                 :          0 :                 return;
     182                 :            :         }
     183                 :            : 
     184                 :            :         shared_stc = ctx->common_res[tbl_type].shared_stc[stc_type];
     185                 :            : 
     186                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &shared_stc->remove_header);
     187                 :            :         simple_free(shared_stc);
     188                 :          0 :         ctx->common_res[tbl_type].shared_stc[stc_type] = NULL;
     189                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
     190                 :            : }
     191                 :            : 
     192                 :          0 : static int mlx5dr_action_get_shared_stc(struct mlx5dr_action *action,
     193                 :            :                                         enum mlx5dr_context_shared_stc_type stc_type)
     194                 :            : {
     195                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
     196                 :            :         int ret;
     197                 :            : 
     198         [ #  # ]:          0 :         if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
     199                 :          0 :                 assert(false);
     200                 :            :                 rte_errno = EINVAL;
     201                 :            :                 return rte_errno;
     202                 :            :         }
     203                 :            : 
     204         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
     205                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
     206         [ #  # ]:          0 :                 if (ret) {
     207                 :          0 :                         DR_LOG(ERR, "Failed to allocate memory for RX shared STCs (type: %d)",
     208                 :            :                                stc_type);
     209                 :          0 :                         return ret;
     210                 :            :                 }
     211                 :            :         }
     212                 :            : 
     213         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
     214                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
     215         [ #  # ]:          0 :                 if (ret) {
     216                 :          0 :                         DR_LOG(ERR, "Failed to allocate memory for TX shared STCs(type: %d)",
     217                 :            :                                stc_type);
     218                 :          0 :                         goto clean_nic_rx_stc;
     219                 :            :                 }
     220                 :            :         }
     221                 :            : 
     222         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
     223                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
     224         [ #  # ]:          0 :                 if (ret) {
     225                 :          0 :                         DR_LOG(ERR, "Failed to allocate memory for FDB shared STCs (type: %d)",
     226                 :            :                                stc_type);
     227                 :          0 :                         goto clean_nic_tx_stc;
     228                 :            :                 }
     229                 :            :         }
     230                 :            : 
     231         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX) {
     232                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
     233                 :            :                                                        MLX5DR_TABLE_TYPE_FDB_RX);
     234         [ #  # ]:          0 :                 if (ret) {
     235                 :          0 :                         DR_LOG(ERR, "Failed to allocate FDB_RX shared STCs (type: %d)",
     236                 :            :                                stc_type);
     237                 :          0 :                         goto clean_nic_fdb_stc;
     238                 :            :                 }
     239                 :            :         }
     240                 :            : 
     241         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX) {
     242                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
     243                 :            :                                                        MLX5DR_TABLE_TYPE_FDB_TX);
     244         [ #  # ]:          0 :                 if (ret) {
     245                 :          0 :                         DR_LOG(ERR, "Failed to allocate FDB_TX shared STCs (type: %d)",
     246                 :            :                                stc_type);
     247                 :          0 :                         goto clean_nic_fdb_rx_stc;
     248                 :            :                 }
     249                 :            :         }
     250                 :            : 
     251         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) {
     252                 :          0 :                 ret = mlx5dr_action_get_shared_stc_nic(ctx, stc_type,
     253                 :            :                                                        MLX5DR_TABLE_TYPE_FDB_UNIFIED);
     254         [ #  # ]:          0 :                 if (ret) {
     255                 :          0 :                         DR_LOG(ERR, "Failed to allocate FDB_UNIFIED shared STCs (type: %d)",
     256                 :            :                                stc_type);
     257                 :          0 :                         goto clean_nic_fdb_tx_stc;
     258                 :            :                 }
     259                 :            :         }
     260                 :            : 
     261                 :            :         return 0;
     262                 :            : 
     263                 :            : clean_nic_fdb_tx_stc:
     264         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
     265                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_TX);
     266                 :          0 : clean_nic_fdb_rx_stc:
     267         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
     268                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_RX);
     269                 :          0 : clean_nic_fdb_stc:
     270         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
     271                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
     272                 :          0 : clean_nic_tx_stc:
     273         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
     274                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
     275                 :          0 : clean_nic_rx_stc:
     276         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
     277                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
     278                 :            : 
     279                 :            :         return ret;
     280                 :            : }
     281                 :            : 
     282                 :          0 : static void mlx5dr_action_put_shared_stc(struct mlx5dr_action *action,
     283                 :            :                                          enum mlx5dr_context_shared_stc_type stc_type)
     284                 :            : {
     285                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
     286                 :            : 
     287         [ #  # ]:          0 :         if (stc_type >= MLX5DR_CONTEXT_SHARED_STC_MAX) {
     288                 :          0 :                 assert(false);
     289                 :            :                 return;
     290                 :            :         }
     291                 :            : 
     292         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
     293                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_RX);
     294                 :            : 
     295         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
     296                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_NIC_TX);
     297                 :            : 
     298         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
     299                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB);
     300                 :            : 
     301         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
     302                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_RX);
     303                 :            : 
     304         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
     305                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_TX);
     306                 :            : 
     307         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)
     308                 :          0 :                 mlx5dr_action_put_shared_stc_nic(ctx, stc_type, MLX5DR_TABLE_TYPE_FDB_UNIFIED);
     309                 :            : }
     310                 :            : 
     311                 :            : static void
     312                 :          0 : mlx5dr_action_create_nat64_zero_all_addr(uint8_t **action_ptr, bool is_v4_to_v6)
     313                 :            : {
     314         [ #  # ]:          0 :         if (is_v4_to_v6) {
     315         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     316         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV4);
     317         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     318                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     319                 :            : 
     320         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     321         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV4);
     322         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     323                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     324                 :            :         } else {
     325         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     326         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_127_96);
     327         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     328                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     329                 :            : 
     330         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     331         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_95_64);
     332         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     333                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     334                 :            : 
     335         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     336         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_63_32);
     337         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     338                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     339                 :            : 
     340         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     341         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_SIPV6_31_0);
     342         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     343                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     344                 :            : 
     345         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     346         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_127_96);
     347         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     348                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     349                 :            : 
     350         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     351         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_95_64);
     352         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     353                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     354                 :            : 
     355         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     356         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_63_32);
     357         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     358                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     359                 :            : 
     360         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     361         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, field, MLX5_MODI_OUT_DIPV6_31_0);
     362         [ #  # ]:          0 :                 MLX5_SET(set_action_in, *action_ptr, data, 0);
     363                 :          0 :                 *action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     364                 :            :         }
     365                 :          0 : }
     366                 :            : 
     367                 :            : static struct mlx5dr_action *
     368                 :          0 : mlx5dr_action_create_nat64_copy_state(struct mlx5dr_context *ctx,
     369                 :            :                                       struct mlx5dr_action_nat64_attr *attr,
     370                 :            :                                       uint32_t flags)
     371                 :            : {
     372                 :            :         rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
     373                 :            :         struct mlx5dr_action_mh_pattern pat[2];
     374                 :            :         struct mlx5dr_action *action;
     375                 :            :         uint32_t packet_len_field;
     376                 :            :         uint8_t *action_ptr;
     377                 :            :         uint32_t tos_field;
     378                 :            :         uint32_t tos_size;
     379                 :            :         uint32_t src_addr;
     380                 :            :         uint32_t dst_addr;
     381                 :            :         bool is_v4_to_v6;
     382                 :            :         uint32_t ecn;
     383                 :            : 
     384                 :          0 :         is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
     385                 :            : 
     386         [ #  # ]:          0 :         if (is_v4_to_v6) {
     387                 :            :                 packet_len_field = MLX5_MODI_OUT_IPV4_TOTAL_LEN;
     388                 :            :                 tos_field = MLX5_MODI_OUT_IP_DSCP;
     389                 :            :                 tos_size = 6;
     390                 :            :                 ecn = MLX5_MODI_OUT_IP_ECN;
     391                 :            :                 src_addr = MLX5_MODI_OUT_SIPV4;
     392                 :            :                 dst_addr = MLX5_MODI_OUT_DIPV4;
     393                 :            :         } else {
     394                 :            :                 packet_len_field = MLX5_MODI_OUT_IPV6_PAYLOAD_LEN;
     395                 :            :                 tos_field = MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS;
     396                 :            :                 tos_size = 8;
     397                 :            :                 ecn = 0;
     398                 :            :                 src_addr = MLX5_MODI_OUT_SIPV6_31_0;
     399                 :            :                 dst_addr = MLX5_MODI_OUT_DIPV6_31_0;
     400                 :            :         }
     401                 :            : 
     402                 :            :         memset(modify_action_data, 0, sizeof(modify_action_data));
     403                 :          0 :         action_ptr = (uint8_t *)modify_action_data;
     404                 :            : 
     405         [ #  # ]:          0 :         if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR) {
     406                 :            :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     407         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field, src_addr);
     408                 :          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field,
     409                 :            :                          attr->registers[MLX5DR_ACTION_NAT64_REG_SRC_IP]);
     410                 :            :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     411                 :            : 
     412                 :            :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     413         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field, dst_addr);
     414                 :          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field,
     415                 :            :                          attr->registers[MLX5DR_ACTION_NAT64_REG_DST_IP]);
     416                 :          0 :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     417                 :            :         }
     418                 :            : 
     419                 :            :         /* | 8 bit - 8 bit     - 16 bit     |
     420                 :            :          * | TOS   - protocol  - packet-len |
     421                 :            :          */
     422         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     423         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field, packet_len_field);
     424         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_field,
     425                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     426         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_offset, 0);/* 16 bits in the lsb */
     427         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, 16);
     428                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     429                 :            : 
     430         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     431                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     432                 :            : 
     433         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     434         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field, MLX5_MODI_OUT_IP_PROTOCOL);
     435         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_field,
     436                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     437         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_offset, 16);
     438         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, 8);
     439                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     440                 :            : 
     441         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     442                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     443                 :            : 
     444         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     445         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field, tos_field);
     446         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_field,
     447                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     448         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_offset, 24);
     449         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, tos_size);
     450                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     451                 :            :         /* in ipv4 TOS = {dscp (6bits) - ecn (2bits) }*/
     452         [ #  # ]:          0 :         if (ecn) {
     453         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     454                 :          0 :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     455                 :            : 
     456         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     457         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field, ecn);
     458         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field,
     459                 :            :                         attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     460         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_offset, 24 + tos_size);
     461         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, length, MLX5DR_ACTION_NAT64_ECN_SIZE);
     462                 :          0 :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     463                 :            :         }
     464                 :            : 
     465                 :            :         /* set sip and dip to 0, in order to have new csum */
     466                 :          0 :         mlx5dr_action_create_nat64_zero_all_addr(&action_ptr, is_v4_to_v6);
     467                 :            : 
     468                 :          0 :         pat[0].data = modify_action_data;
     469                 :          0 :         pat[0].sz = (action_ptr - (uint8_t *)modify_action_data);
     470                 :            : 
     471                 :          0 :         action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
     472         [ #  # ]:          0 :         if (!action) {
     473                 :          0 :                 DR_LOG(ERR, "Failed to create copy for NAT64: action_sz: %zu, flags: 0x%x\n",
     474                 :            :                        pat[0].sz, flags);
     475                 :          0 :                 return NULL;
     476                 :            :         }
     477                 :            : 
     478                 :            :         return action;
     479                 :            : }
     480                 :            : 
     481                 :            : static struct mlx5dr_action *
     482                 :          0 : mlx5dr_action_create_nat64_repalce_state(struct mlx5dr_context *ctx,
     483                 :            :                                          struct mlx5dr_action_nat64_attr *attr,
     484                 :            :                                          uint32_t flags)
     485                 :            : {
     486                 :          0 :         uint32_t address_prefix[MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE] = {0};
     487                 :            :         rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
     488                 :            :         struct mlx5dr_action_mh_pattern pat[2];
     489                 :            :         static struct mlx5dr_action *action;
     490                 :            :         uint8_t header_size_in_dw;
     491                 :            :         uint8_t *action_ptr;
     492                 :            :         uint32_t eth_type;
     493                 :            :         bool is_v4_to_v6;
     494                 :            :         uint32_t ip_ver;
     495                 :            :         int i;
     496                 :            : 
     497                 :          0 :         is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
     498                 :            : 
     499         [ #  # ]:          0 :         if (is_v4_to_v6) {
     500                 :            :                 uint32_t nat64_well_known_pref[] = {0x00010000,
     501                 :            :                                                     0x9bff6400, 0x0, 0x0, 0x0,
     502                 :            :                                                     0x9bff6400, 0x0, 0x0, 0x0};
     503                 :            : 
     504                 :            :                 header_size_in_dw = MLX5DR_ACTION_NAT64_IPV6_HEADER;
     505                 :            :                 ip_ver = MLX5DR_ACTION_NAT64_IPV6_VER;
     506                 :            :                 eth_type = RTE_ETHER_TYPE_IPV6;
     507                 :            :                 memcpy(address_prefix, nat64_well_known_pref,
     508                 :            :                        MLX5DR_ACTION_NAT64_HEADER_MINUS_ONE * sizeof(uint32_t));
     509                 :            :         } else {
     510                 :            :                 /* We make a buffer that contain the right HW csum and the DF bit set.
     511                 :            :                  * 0x00400000 - contain the DF bit in the right place.
     512                 :            :                  * 0xff7a0000 - is the csum for that buffer, calculated via external tool.
     513                 :            :                  */
     514                 :            :                 uint32_t ipv4_pref[] = {0x00400000, 0xff7a0000, 0x0, 0x0, 0x0};
     515                 :            : 
     516                 :            :                 header_size_in_dw = MLX5DR_ACTION_NAT64_IPV4_HEADER;
     517                 :            :                 ip_ver = MLX5DR_ACTION_NAT64_IPV4_VER;
     518                 :            :                 eth_type = RTE_ETHER_TYPE_IPV4;
     519                 :            :                 memcpy(address_prefix, ipv4_pref,
     520                 :            :                        MLX5DR_ACTION_NAT64_IPV4_HEADER * sizeof(uint32_t));
     521                 :            :         }
     522                 :            : 
     523                 :            :         memset(modify_action_data, 0, sizeof(modify_action_data));
     524                 :            :         action_ptr = (uint8_t *)modify_action_data;
     525                 :            : 
     526                 :            :         MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     527         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, field, MLX5_MODI_OUT_ETHERTYPE);
     528         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, length, 16);
     529                 :          0 :         MLX5_SET(set_action_in, action_ptr, data, eth_type);
     530                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     531                 :            : 
     532                 :            :         /* push empty header with ipv6 as version */
     533                 :            :         MLX5_SET(stc_ste_param_insert, action_ptr, action_type,
     534                 :            :                  MLX5_MODIFICATION_TYPE_INSERT);
     535         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_insert, action_ptr, inline_data, 0x1);
     536         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_insert, action_ptr, insert_anchor,
     537                 :            :                  MLX5_HEADER_ANCHOR_IPV6_IPV4);
     538         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_insert, action_ptr, insert_size, 2);
     539                 :          0 :         MLX5_SET(stc_ste_param_insert, action_ptr, insert_argument, ip_ver);
     540                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     541                 :            : 
     542         [ #  # ]:          0 :         for (i = 0; i < header_size_in_dw - 1; i++) {
     543         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, action_ptr, action_type,
     544                 :            :                                 MLX5_MODIFICATION_TYPE_INSERT);
     545         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, action_ptr, inline_data, 0x1);
     546         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, action_ptr, insert_anchor,
     547                 :            :                                 MLX5_HEADER_ANCHOR_IPV6_IPV4);
     548         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, action_ptr, insert_size, 2);
     549         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, action_ptr, insert_argument,
     550                 :            :                          htobe32(address_prefix[i]));
     551                 :          0 :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     552                 :            :         }
     553                 :            : 
     554                 :            :         /* Remove orig src/dst addr (8 bytes, 4 words) */
     555         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, action_ptr, action_type,
     556                 :            :                  MLX5_MODIFICATION_TYPE_REMOVE);
     557         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, action_ptr, remove_start_anchor,
     558                 :            :                  MLX5_HEADER_ANCHOR_IPV6_IPV4);
     559         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, action_ptr, remove_end_anchor,
     560                 :            :                  MLX5_HEADER_ANCHOR_TCP_UDP);
     561                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     562                 :            : 
     563                 :          0 :         pat[0].data = modify_action_data;
     564                 :          0 :         pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
     565                 :            : 
     566                 :          0 :         action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
     567         [ #  # ]:          0 :         if (!action) {
     568                 :          0 :                 DR_LOG(ERR, "Failed to create action: action_sz: %zu flags: 0x%x\n",
     569                 :            :                        pat[0].sz, flags);
     570                 :          0 :                 return NULL;
     571                 :            :         }
     572                 :            : 
     573                 :            :         return action;
     574                 :            : }
     575                 :            : 
     576                 :            : static struct mlx5dr_action *
     577                 :          0 : mlx5dr_action_create_nat64_copy_proto_state(struct mlx5dr_context *ctx,
     578                 :            :                                             struct mlx5dr_action_nat64_attr *attr,
     579                 :            :                                             uint32_t flags)
     580                 :            : {
     581                 :            :         rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
     582                 :            :         struct mlx5dr_action_mh_pattern pat[2];
     583                 :            :         struct mlx5dr_action *action;
     584                 :            :         uint8_t *action_ptr;
     585                 :            : 
     586                 :            :         memset(modify_action_data, 0, sizeof(modify_action_data));
     587                 :            :         action_ptr = (uint8_t *)modify_action_data;
     588                 :            : 
     589                 :          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     590         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field,
     591                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     592                 :            :         MLX5_SET(copy_action_in, action_ptr, dst_field,
     593                 :            :                  MLX5_MODI_OUT_IP_PROTOCOL);
     594         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_offset, 16);
     595         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, dst_offset, 0);
     596         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, 8);
     597                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     598                 :            : 
     599                 :          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     600                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     601                 :            : 
     602                 :          0 :         pat[0].data = modify_action_data;
     603                 :          0 :         pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
     604                 :            : 
     605                 :          0 :         action = mlx5dr_action_create_modify_header_reparse(ctx, 1, pat, 0, flags,
     606                 :            :                                                             MLX5DR_ACTION_STC_REPARSE_ON);
     607         [ #  # ]:          0 :         if (!action) {
     608                 :          0 :                 DR_LOG(ERR, "Failed to create action: action_sz: %zu, flags: 0x%x\n",
     609                 :            :                        pat[0].sz, flags);
     610                 :          0 :                 return NULL;
     611                 :            :         }
     612                 :            : 
     613                 :            :         return action;
     614                 :            : }
     615                 :            : 
     616                 :            : static struct mlx5dr_action *
     617                 :          0 : mlx5dr_action_create_nat64_copy_back_state(struct mlx5dr_context *ctx,
     618                 :            :                                            struct mlx5dr_action_nat64_attr *attr,
     619                 :            :                                            uint32_t flags)
     620                 :            : {
     621                 :            :         rte_be64_t modify_action_data[MLX5DR_ACTION_NAT64_MAX_MODIFY_ACTIONS];
     622                 :            :         struct mlx5dr_action_mh_pattern pat[2];
     623                 :            :         struct mlx5dr_action *action;
     624                 :            :         uint32_t packet_len_field;
     625                 :            :         uint32_t packet_len_add;
     626                 :            :         uint8_t *action_ptr;
     627                 :            :         uint32_t tos_field;
     628                 :            :         uint32_t ttl_field;
     629                 :            :         uint32_t tos_size;
     630                 :            :         uint32_t src_addr;
     631                 :            :         uint32_t dst_addr;
     632                 :            :         bool is_v4_to_v6;
     633                 :            :         uint32_t ecn;
     634                 :            : 
     635                 :          0 :         is_v4_to_v6 = attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6;
     636                 :            : 
     637         [ #  # ]:          0 :         if (is_v4_to_v6) {
     638                 :            :                 packet_len_field = MLX5_MODI_OUT_IPV6_PAYLOAD_LEN;
     639                 :            :                  /* 2' comp to 20, to get -20 in add operation */
     640                 :            :                 packet_len_add = MLX5DR_ACTION_NAT64_DEC_20;
     641                 :            :                 ttl_field = MLX5_MODI_OUT_IPV6_HOPLIMIT;
     642                 :            :                 src_addr = MLX5_MODI_OUT_SIPV6_31_0;
     643                 :            :                 dst_addr = MLX5_MODI_OUT_DIPV6_31_0;
     644                 :            :                 tos_field = MLX5_MODI_OUT_IPV6_TRAFFIC_CLASS;
     645                 :            :                 tos_size = 8;
     646                 :            :                 ecn = 0;
     647                 :            :         } else {
     648                 :            :                 packet_len_field = MLX5_MODI_OUT_IPV4_TOTAL_LEN;
     649                 :            :                 /* ipv4 len is including 20 bytes of the header, so add 20 over ipv6 len */
     650                 :            :                 packet_len_add = MLX5DR_ACTION_NAT64_ADD_20;
     651                 :            :                 ttl_field = MLX5_MODI_OUT_IPV4_TTL;
     652                 :            :                 src_addr = MLX5_MODI_OUT_SIPV4;
     653                 :            :                 dst_addr = MLX5_MODI_OUT_DIPV4;
     654                 :            :                 tos_field = MLX5_MODI_OUT_IP_DSCP;
     655                 :            :                 tos_size = 6;
     656                 :            :                 ecn = MLX5_MODI_OUT_IP_ECN;
     657                 :            :         }
     658                 :            : 
     659                 :            :         memset(modify_action_data, 0, sizeof(modify_action_data));
     660                 :            :         action_ptr = (uint8_t *)modify_action_data;
     661                 :            : 
     662                 :          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     663         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field,
     664                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     665                 :          0 :         MLX5_SET(copy_action_in, action_ptr, dst_field,
     666                 :            :                  packet_len_field);
     667         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_offset, 32);
     668         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, 16);
     669                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     670                 :            : 
     671                 :            :         MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_SET);
     672         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, field, ttl_field);
     673         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, length, 8);
     674                 :          0 :         MLX5_SET(set_action_in, action_ptr, data, MLX5DR_ACTION_NAT64_TTL_DEFAULT_VAL);
     675                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     676                 :            : 
     677                 :            :         /* copy TOS */
     678                 :          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     679         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_field,
     680                 :            :                  attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     681                 :          0 :         MLX5_SET(copy_action_in, action_ptr, dst_field, tos_field);
     682   [ #  #  #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, src_offset, 24 + (ecn ?
     683                 :            :                                                                MLX5DR_ACTION_NAT64_ECN_SIZE : 0));
     684         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, length, tos_size);
     685                 :            :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     686                 :            : 
     687         [ #  # ]:          0 :         if (ecn) {
     688                 :          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     689                 :            :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     690                 :            : 
     691                 :          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     692         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field,
     693                 :            :                         attr->registers[MLX5DR_ACTION_NAT64_REG_CONTROL]);
     694                 :          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field, ecn);
     695         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_offset, 24);
     696         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, length, MLX5DR_ACTION_NAT64_ECN_SIZE);
     697                 :            :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     698                 :            :         }
     699                 :            : 
     700         [ #  # ]:          0 :         MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_NOP);
     701                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     702                 :            : 
     703                 :            :         /* if required Copy original addresses */
     704         [ #  # ]:          0 :         if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR) {
     705         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     706         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field,
     707                 :            :                          attr->registers[MLX5DR_ACTION_NAT64_REG_SRC_IP]);
     708         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field, src_addr);
     709         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_offset, 0);
     710         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, length, 32);
     711                 :            :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     712                 :            : 
     713         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_COPY);
     714         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_field,
     715                 :            :                          attr->registers[MLX5DR_ACTION_NAT64_REG_DST_IP]);
     716         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, dst_field, dst_addr);
     717         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, src_offset, 0);
     718         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, action_ptr, length, 32);
     719                 :          0 :                 action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     720                 :            :         }
     721                 :            : 
     722                 :            :         /* take/add off 20 bytes ipv4/6 from/to the total size */
     723         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, action_type, MLX5_MODIFICATION_TYPE_ADD);
     724         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, field, packet_len_field);
     725         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, data, packet_len_add);
     726         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, length, 16);
     727                 :          0 :         action_ptr += MLX5DR_ACTION_DOUBLE_SIZE;
     728                 :            : 
     729                 :          0 :         pat[0].data = modify_action_data;
     730                 :          0 :         pat[0].sz = action_ptr - (uint8_t *)modify_action_data;
     731                 :            : 
     732                 :          0 :         action = mlx5dr_action_create_modify_header(ctx, 1, pat, 0, flags);
     733         [ #  # ]:          0 :         if (!action) {
     734                 :          0 :                 DR_LOG(ERR, "Failed to create action: action_sz: %zu, flags: 0x%x\n",
     735                 :            :                        pat[0].sz, flags);
     736                 :          0 :                 return NULL;
     737                 :            :         }
     738                 :            : 
     739                 :            :         return action;
     740                 :            : }
     741                 :            : 
     742                 :          0 : static void mlx5dr_action_print_combo(enum mlx5dr_action_type *user_actions)
     743                 :            : {
     744                 :          0 :         DR_LOG(ERR, "Invalid action_type sequence");
     745         [ #  # ]:          0 :         while (*user_actions != MLX5DR_ACTION_TYP_LAST) {
     746                 :          0 :                 DR_LOG(ERR, "%s", mlx5dr_debug_action_type_to_str(*user_actions));
     747                 :          0 :                 user_actions++;
     748                 :            :         }
     749                 :          0 : }
     750                 :            : 
     751                 :            : static const uint32_t *
     752                 :          0 : mlx5dr_action_get_order_entry(enum mlx5dr_table_type table_type)
     753                 :            : {
     754   [ #  #  #  # ]:          0 :         switch (table_type) {
     755                 :            :         case MLX5DR_TABLE_TYPE_NIC_RX:
     756                 :            :                 return action_order_arr[MLX5DR_TABLE_TYPE_NIC_RX];
     757                 :          0 :         case MLX5DR_TABLE_TYPE_NIC_TX:
     758                 :          0 :                 return action_order_arr[MLX5DR_TABLE_TYPE_NIC_TX];
     759                 :          0 :         case MLX5DR_TABLE_TYPE_FDB:
     760                 :            :         case MLX5DR_TABLE_TYPE_FDB_RX:
     761                 :            :         case MLX5DR_TABLE_TYPE_FDB_TX:
     762                 :            :         case MLX5DR_TABLE_TYPE_FDB_UNIFIED:
     763                 :          0 :                 return action_order_arr[MLX5DR_TABLE_TYPE_FDB];
     764                 :          0 :         default:
     765                 :          0 :                 assert(0);
     766                 :            :                 DR_LOG(ERR, "no such type: %d", table_type);
     767                 :            :                 return NULL;
     768                 :            :         }
     769                 :            : }
     770                 :            : 
     771                 :          0 : bool mlx5dr_action_check_combo(enum mlx5dr_action_type *user_actions,
     772                 :            :                                enum mlx5dr_table_type table_type)
     773                 :            : {
     774                 :          0 :         const uint32_t *order_arr = mlx5dr_action_get_order_entry(table_type);
     775                 :            :         uint8_t order_idx = 0;
     776                 :            :         uint8_t user_idx = 0;
     777                 :            :         bool valid_combo;
     778                 :            : 
     779         [ #  # ]:          0 :         if (!order_arr)
     780                 :            :                 return false;
     781                 :            : 
     782         [ #  # ]:          0 :         while (order_arr[order_idx] != BIT(MLX5DR_ACTION_TYP_LAST)) {
     783                 :            :                 /* User action order validated move to next user action */
     784         [ #  # ]:          0 :                 if (BIT(user_actions[user_idx]) & order_arr[order_idx])
     785                 :          0 :                         user_idx++;
     786                 :            : 
     787                 :            :                 /* Iterate to the next supported action in the order */
     788                 :          0 :                 order_idx++;
     789                 :            :         }
     790                 :            : 
     791                 :            :         /* Combination is valid if all user action were processed */
     792                 :          0 :         valid_combo = user_actions[user_idx] == MLX5DR_ACTION_TYP_LAST;
     793         [ #  # ]:          0 :         if (!valid_combo)
     794                 :          0 :                 mlx5dr_action_print_combo(user_actions);
     795                 :            : 
     796                 :            :         return valid_combo;
     797                 :            : }
     798                 :            : 
     799                 :          0 : int mlx5dr_action_root_build_attr(struct mlx5dr_rule_action rule_actions[],
     800                 :            :                                   uint32_t num_actions,
     801                 :            :                                   struct mlx5dv_flow_action_attr *attr)
     802                 :            : {
     803                 :            :         struct mlx5dr_action *action;
     804                 :            :         uint32_t i;
     805                 :            : 
     806         [ #  # ]:          0 :         for (i = 0; i < num_actions; i++) {
     807                 :          0 :                 action = rule_actions[i].action;
     808                 :            : 
     809   [ #  #  #  #  :          0 :                 switch (action->type) {
                #  #  # ]
     810                 :          0 :                 case MLX5DR_ACTION_TYP_TBL:
     811                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_DEST_DEVX;
     812                 :          0 :                         attr[i].obj = action->dest_tbl.devx_obj->obj;
     813                 :          0 :                         break;
     814                 :          0 :                 case MLX5DR_ACTION_TYP_TIR:
     815                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_DEST_DEVX;
     816                 :          0 :                         attr[i].obj = action->devx_obj;
     817                 :          0 :                         break;
     818                 :          0 :                 case MLX5DR_ACTION_TYP_TAG:
     819                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_TAG;
     820                 :          0 :                         attr[i].tag_value = rule_actions[i].tag.value;
     821                 :          0 :                         break;
     822                 :            : #ifdef HAVE_MLX5_DR_CREATE_ACTION_DEFAULT_MISS
     823                 :          0 :                 case MLX5DR_ACTION_TYP_MISS:
     824                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_DEFAULT_MISS;
     825                 :          0 :                         break;
     826                 :            : #endif
     827                 :          0 :                 case MLX5DR_ACTION_TYP_DROP:
     828                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_DROP;
     829                 :          0 :                         break;
     830                 :          0 :                 case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
     831                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
     832                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
     833                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
     834                 :            :                 case MLX5DR_ACTION_TYP_MODIFY_HDR:
     835                 :          0 :                         attr[i].type = MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION;
     836                 :          0 :                         attr[i].action = action->flow_action;
     837                 :          0 :                         break;
     838                 :            : #ifdef HAVE_MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET
     839                 :            :                 case MLX5DR_ACTION_TYP_CTR:
     840                 :            :                         attr[i].type = MLX5DV_FLOW_ACTION_COUNTERS_DEVX_WITH_OFFSET;
     841                 :            :                         attr[i].bulk_obj.obj = action->devx_obj;
     842                 :            :                         attr[i].bulk_obj.offset = rule_actions[i].counter.offset;
     843                 :            :                         break;
     844                 :            : #endif
     845                 :          0 :                 default:
     846                 :          0 :                         DR_LOG(ERR, "Found unsupported action type: %d", action->type);
     847                 :          0 :                         rte_errno = ENOTSUP;
     848                 :          0 :                         return rte_errno;
     849                 :            :                 }
     850                 :            :         }
     851                 :            : 
     852                 :            :         return 0;
     853                 :            : }
     854                 :            : 
     855                 :            : static bool
     856                 :          0 : mlx5dr_action_fixup_stc_attr(struct mlx5dr_context *ctx,
     857                 :            :                              struct mlx5dr_cmd_stc_modify_attr *stc_attr,
     858                 :            :                              struct mlx5dr_cmd_stc_modify_attr *fixup_stc_attr,
     859                 :            :                              enum mlx5dr_table_type table_type,
     860                 :            :                              bool is_mirror)
     861                 :            : {
     862                 :            :         struct mlx5dr_devx_obj *devx_obj;
     863                 :            :         bool use_fixup = false;
     864                 :            :         uint32_t fw_tbl_type;
     865                 :            : 
     866                 :          0 :         fw_tbl_type = mlx5dr_table_get_res_fw_ft_type(table_type, is_mirror);
     867                 :            : 
     868   [ #  #  #  #  :          0 :         switch (stc_attr->action_type) {
                   #  # ]
     869                 :          0 :         case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE:
     870                 :          0 :                 devx_obj = mlx5dr_action_get_stc_obj_by_tbl_type(table_type,
     871                 :            :                                                                  stc_attr->ste_table.ste_pool,
     872                 :            :                                                                  &stc_attr->ste_table.ste,
     873                 :            :                                                                  is_mirror);
     874                 :            : 
     875                 :          0 :                 *fixup_stc_attr = *stc_attr;
     876                 :          0 :                 fixup_stc_attr->ste_table.ste_obj_id = devx_obj->id;
     877                 :            :                 use_fixup = true;
     878                 :          0 :                 break;
     879                 :            : 
     880                 :          0 :         case MLX5_IFC_STC_ACTION_TYPE_TAG:
     881         [ #  # ]:          0 :                 if (fw_tbl_type == FS_FT_FDB_TX) {
     882                 :          0 :                         fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_NOP;
     883                 :          0 :                         fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
     884                 :          0 :                         fixup_stc_attr->stc_offset = stc_attr->stc_offset;
     885                 :            :                         use_fixup = true;
     886                 :            :                 }
     887                 :            :                 break;
     888                 :            : 
     889                 :            :         case MLX5_IFC_STC_ACTION_TYPE_ALLOW:
     890                 :            :                 if (mlx5dr_table_is_fw_fdb_any(fw_tbl_type)) {
     891                 :          0 :                         fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
     892                 :          0 :                         fixup_stc_attr->action_offset = stc_attr->action_offset;
     893                 :          0 :                         fixup_stc_attr->stc_offset = stc_attr->stc_offset;
     894                 :          0 :                         fixup_stc_attr->vport.esw_owner_vhca_id = ctx->caps->vhca_id;
     895                 :          0 :                         fixup_stc_attr->vport.vport_num = ctx->caps->eswitch_manager_vport_number;
     896                 :          0 :                         fixup_stc_attr->vport.eswitch_owner_vhca_id_valid =
     897                 :          0 :                                 ctx->caps->merged_eswitch;
     898                 :            :                         use_fixup = true;
     899                 :            :                 }
     900                 :            :                 break;
     901                 :            : 
     902                 :          0 :         case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT:
     903         [ #  # ]:          0 :                 if (stc_attr->vport.vport_num != WIRE_PORT)
     904                 :            :                         break;
     905                 :            : 
     906                 :            :                 if (mlx5dr_table_is_fw_fdb_any(fw_tbl_type)) {
     907                 :            :                         /* The FW doesn't allow to go to wire in the TX/RX by JUMP_TO_VPORT */
     908                 :          0 :                         fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_UPLINK;
     909                 :          0 :                         fixup_stc_attr->action_offset = stc_attr->action_offset;
     910                 :          0 :                         fixup_stc_attr->stc_offset = stc_attr->stc_offset;
     911                 :          0 :                         fixup_stc_attr->vport.vport_num = 0;
     912                 :          0 :                         fixup_stc_attr->vport.esw_owner_vhca_id = stc_attr->vport.esw_owner_vhca_id;
     913                 :          0 :                         fixup_stc_attr->vport.eswitch_owner_vhca_id_valid =
     914                 :          0 :                                 stc_attr->vport.eswitch_owner_vhca_id_valid;
     915                 :            :                 }
     916                 :            :                 use_fixup = true;
     917                 :            :                 break;
     918                 :          0 :         case MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR:
     919                 :            :                 /* TIR is allowed on RX side, requires mask in case of FDB */
     920         [ #  # ]:          0 :                 if (fw_tbl_type == FS_FT_FDB_TX) {
     921                 :          0 :                         fixup_stc_attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
     922                 :          0 :                         fixup_stc_attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
     923                 :          0 :                         fixup_stc_attr->stc_offset = stc_attr->stc_offset;
     924                 :            :                         use_fixup = true;
     925                 :            :                 }
     926                 :            :                 break;
     927                 :            :         default:
     928                 :            :                 break;
     929                 :            :         }
     930                 :            : 
     931                 :          0 :         return use_fixup;
     932                 :            : }
     933                 :            : 
     934                 :            : static struct mlx5dr_devx_obj *
     935                 :            : mlx5dr_action_get_stc_obj_by_tbl_type(enum mlx5dr_table_type table_type,
     936                 :            :                                       struct mlx5dr_pool *stc_pool,
     937                 :            :                                       struct mlx5dr_pool_chunk *stc,
     938                 :            :                                       bool is_mirror)
     939                 :            : {
     940   [ #  #  #  # ]:          0 :         if (table_type == MLX5DR_TABLE_TYPE_FDB_TX ||
     941         [ #  # ]:          0 :             (is_mirror && table_type == MLX5DR_TABLE_TYPE_FDB)) /* Optimized ORIG in FDB_TX */
     942                 :          0 :                 return mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
     943                 :            :         else
     944                 :          0 :                 return mlx5dr_pool_chunk_get_base_devx_obj(stc_pool, stc);
     945                 :            : }
     946                 :            : 
     947                 :          0 : int mlx5dr_action_alloc_single_stc(struct mlx5dr_context *ctx,
     948                 :            :                                    struct mlx5dr_cmd_stc_modify_attr *stc_attr,
     949                 :            :                                    uint32_t table_type,
     950                 :            :                                    struct mlx5dr_pool_chunk *stc)
     951                 :            : {
     952                 :          0 :         struct mlx5dr_cmd_stc_modify_attr cleanup_stc_attr = {0};
     953                 :          0 :         struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
     954                 :          0 :         struct mlx5dr_cmd_stc_modify_attr fixup_stc_attr = {0};
     955                 :            :         struct mlx5dr_devx_obj *devx_obj_0;
     956                 :            :         enum mlx5dr_table_type type;
     957                 :            :         bool use_fixup;
     958                 :            :         int ret;
     959                 :            : 
     960                 :          0 :         ret = mlx5dr_pool_chunk_alloc(stc_pool, stc);
     961         [ #  # ]:          0 :         if (ret) {
     962                 :          0 :                 DR_LOG(ERR, "Failed to allocate single action STC");
     963                 :          0 :                 return ret;
     964                 :            :         }
     965                 :            : 
     966                 :          0 :         stc_attr->stc_offset = stc->offset;
     967                 :            : 
     968                 :            :         /* Dynamic reparse not supported, overwrite and use default */
     969         [ #  # ]:          0 :         if (!mlx5dr_context_cap_dynamic_reparse(ctx))
     970                 :          0 :                 stc_attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
     971                 :            : 
     972                 :            :         type = (enum mlx5dr_table_type)table_type;
     973                 :            :         devx_obj_0 = mlx5dr_action_get_stc_obj_by_tbl_type(type, stc_pool, stc, false);
     974                 :            : 
     975                 :            :         /* According to table/action limitation change the stc_attr */
     976                 :          0 :         use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr, &fixup_stc_attr,
     977                 :            :                                                  (enum mlx5dr_table_type)table_type,
     978                 :            :                                                  (table_type == MLX5DR_TABLE_TYPE_FDB_TX));
     979         [ #  # ]:          0 :         ret = mlx5dr_cmd_stc_modify(devx_obj_0, use_fixup ? &fixup_stc_attr : stc_attr);
     980         [ #  # ]:          0 :         if (ret) {
     981                 :          0 :                 DR_LOG(ERR, "Failed to modify STC action_type %d tbl_type %d",
     982                 :            :                        stc_attr->action_type, table_type);
     983                 :          0 :                 goto free_chunk;
     984                 :            :         }
     985                 :            : 
     986                 :            :         /* Modify the FDB peer */
     987         [ #  # ]:          0 :         if (table_type == MLX5DR_TABLE_TYPE_FDB) {
     988                 :            :                 struct mlx5dr_devx_obj *devx_obj_1;
     989                 :            : 
     990                 :            :                 devx_obj_1 = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
     991                 :            : 
     992                 :          0 :                 use_fixup = mlx5dr_action_fixup_stc_attr(ctx, stc_attr,
     993                 :            :                                                          &fixup_stc_attr,
     994                 :            :                                                          table_type, true);
     995         [ #  # ]:          0 :                 ret = mlx5dr_cmd_stc_modify(devx_obj_1, use_fixup ? &fixup_stc_attr : stc_attr);
     996         [ #  # ]:          0 :                 if (ret) {
     997                 :          0 :                         DR_LOG(ERR, "Failed to modify peer STC action_type %d tbl_type %d",
     998                 :            :                                stc_attr->action_type, table_type);
     999                 :          0 :                         goto clean_devx_obj_0;
    1000                 :            :                 }
    1001                 :            :         }
    1002                 :            : 
    1003                 :            :         return 0;
    1004                 :            : 
    1005                 :            : clean_devx_obj_0:
    1006                 :          0 :         cleanup_stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
    1007                 :          0 :         cleanup_stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1008                 :          0 :         cleanup_stc_attr.stc_offset = stc->offset;
    1009                 :          0 :         mlx5dr_cmd_stc_modify(devx_obj_0, &cleanup_stc_attr);
    1010                 :          0 : free_chunk:
    1011                 :          0 :         mlx5dr_pool_chunk_free(stc_pool, stc);
    1012                 :          0 :         return rte_errno;
    1013                 :            : }
    1014                 :            : 
    1015                 :          0 : void mlx5dr_action_free_single_stc(struct mlx5dr_context *ctx,
    1016                 :            :                                    uint32_t table_type,
    1017                 :            :                                    struct mlx5dr_pool_chunk *stc)
    1018                 :            : {
    1019                 :          0 :         struct mlx5dr_pool *stc_pool = ctx->stc_pool[table_type];
    1020                 :          0 :         struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
    1021                 :            :         struct mlx5dr_devx_obj *devx_obj;
    1022                 :            :         enum mlx5dr_table_type type;
    1023                 :            : 
    1024                 :            :         /* Modify the STC not to point to an object */
    1025                 :          0 :         stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
    1026                 :          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1027         [ #  # ]:          0 :         stc_attr.stc_offset = stc->offset;
    1028                 :            :         type = (enum mlx5dr_table_type)table_type;
    1029                 :            :         devx_obj = mlx5dr_action_get_stc_obj_by_tbl_type(type, stc_pool, stc, false);
    1030                 :            : 
    1031                 :          0 :         mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
    1032                 :            : 
    1033         [ #  # ]:          0 :         if (table_type == MLX5DR_TABLE_TYPE_FDB) {
    1034                 :            :                 devx_obj = mlx5dr_pool_chunk_get_base_devx_obj_mirror(stc_pool, stc);
    1035                 :          0 :                 mlx5dr_cmd_stc_modify(devx_obj, &stc_attr);
    1036                 :            :         }
    1037                 :            : 
    1038                 :          0 :         mlx5dr_pool_chunk_free(stc_pool, stc);
    1039                 :          0 : }
    1040                 :            : 
    1041                 :          0 : static uint32_t mlx5dr_action_get_mh_stc_type(__be64 pattern)
    1042                 :            : {
    1043         [ #  # ]:          0 :         uint8_t action_type = MLX5_GET(set_action_in, &pattern, action_type);
    1044                 :            : 
    1045   [ #  #  #  #  :          0 :         switch (action_type) {
                      # ]
    1046                 :            :         case MLX5_MODIFICATION_TYPE_SET:
    1047                 :            :                 return MLX5_IFC_STC_ACTION_TYPE_SET;
    1048                 :          0 :         case MLX5_MODIFICATION_TYPE_ADD:
    1049                 :          0 :                 return MLX5_IFC_STC_ACTION_TYPE_ADD;
    1050                 :          0 :         case MLX5_MODIFICATION_TYPE_COPY:
    1051                 :          0 :                 return MLX5_IFC_STC_ACTION_TYPE_COPY;
    1052                 :          0 :         case MLX5_MODIFICATION_TYPE_ADD_FIELD:
    1053                 :          0 :                 return MLX5_IFC_STC_ACTION_TYPE_ADD_FIELD;
    1054                 :          0 :         default:
    1055                 :          0 :                 assert(false);
    1056                 :            :                 DR_LOG(ERR, "Unsupported action type: 0x%x", action_type);
    1057                 :            :                 rte_errno = ENOTSUP;
    1058                 :            :                 return MLX5_IFC_STC_ACTION_TYPE_NOP;
    1059                 :            :         }
    1060                 :            : }
    1061                 :            : 
    1062                 :          0 : static void mlx5dr_action_fill_stc_attr(struct mlx5dr_action *action,
    1063                 :            :                                         struct mlx5dr_devx_obj *obj,
    1064                 :            :                                         struct mlx5dr_cmd_stc_modify_attr *attr)
    1065                 :            : {
    1066                 :          0 :         attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
    1067                 :            : 
    1068   [ #  #  #  #  :          0 :         switch (action->type) {
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1069                 :          0 :         case MLX5DR_ACTION_TYP_TAG:
    1070                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_TAG;
    1071                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
    1072                 :          0 :                 break;
    1073                 :          0 :         case MLX5DR_ACTION_TYP_DROP:
    1074                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_DROP;
    1075                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1076                 :          0 :                 break;
    1077                 :          0 :         case MLX5DR_ACTION_TYP_MISS:
    1078                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
    1079                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1080                 :          0 :                 break;
    1081                 :          0 :         case MLX5DR_ACTION_TYP_CTR:
    1082                 :          0 :                 attr->id = obj->id;
    1083                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_COUNTER;
    1084                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW0;
    1085                 :          0 :                 break;
    1086                 :          0 :         case MLX5DR_ACTION_TYP_TIR:
    1087                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_TIR;
    1088                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1089                 :          0 :                 attr->dest_tir_num = obj->id;
    1090                 :          0 :                 break;
    1091                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    1092                 :            :         case MLX5DR_ACTION_TYP_MODIFY_HDR:
    1093                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
    1094                 :            :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
    1095         [ #  # ]:          0 :                 if (action->modify_header.require_reparse)
    1096                 :          0 :                         attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1097                 :            : 
    1098         [ #  # ]:          0 :                 if (action->modify_header.num_of_actions == 1) {
    1099                 :          0 :                         attr->modify_action.data = action->modify_header.single_action;
    1100                 :          0 :                         attr->action_type = mlx5dr_action_get_mh_stc_type(attr->modify_action.data);
    1101                 :            : 
    1102         [ #  # ]:          0 :                         if (attr->action_type == MLX5_IFC_STC_ACTION_TYPE_ADD ||
    1103                 :            :                             attr->action_type == MLX5_IFC_STC_ACTION_TYPE_SET)
    1104         [ #  # ]:          0 :                                 MLX5_SET(set_action_in, &attr->modify_action.data, data, 0);
    1105                 :            :                 } else {
    1106                 :          0 :                         attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ACC_MODIFY_LIST;
    1107                 :          0 :                         attr->modify_header.arg_id = action->modify_header.arg_obj->id;
    1108                 :          0 :                         attr->modify_header.pattern_id = action->modify_header.pat_obj->id;
    1109                 :            :                 }
    1110                 :            :                 break;
    1111                 :          0 :         case MLX5DR_ACTION_TYP_TBL:
    1112                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1113                 :          0 :                 attr->dest_table_id = obj->id;
    1114                 :            :                 /* Only for unified FDB Rx case */
    1115         [ #  # ]:          0 :                 if (mlx5dr_context_cap_stc(action->ctx,
    1116                 :          0 :                     MLX5_IFC_STC_ACTION_TYPE_JUMP_FLOW_TABLE_FDB_RX_BIT_INDEX) &&
    1117         [ #  # ]:          0 :                     action->dest_tbl.type == MLX5DR_TABLE_TYPE_FDB_RX)
    1118                 :          0 :                         attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FLOW_TABLE_FDB_RX;
    1119                 :            :                 else
    1120                 :          0 :                         attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
    1121                 :            : 
    1122                 :            :                 break;
    1123                 :          0 :         case MLX5DR_ACTION_TYP_DEST_ARRAY:
    1124                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
    1125                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1126                 :          0 :                 attr->dest_table_id = obj->id;
    1127                 :          0 :                 break;
    1128                 :          0 :         case MLX5DR_ACTION_TYP_DEST_ROOT:
    1129                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
    1130                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1131                 :          0 :                 attr->dest_table_id = action->root_tbl.sa->id;
    1132                 :          0 :                 break;
    1133                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    1134                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
    1135                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
    1136                 :          0 :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1137                 :          0 :                 attr->remove_header.decap = 1;
    1138                 :          0 :                 attr->remove_header.start_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
    1139                 :          0 :                 attr->remove_header.end_anchor = MLX5_HEADER_ANCHOR_INNER_MAC;
    1140                 :          0 :                 break;
    1141                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    1142                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    1143                 :            :         case MLX5DR_ACTION_TYP_INSERT_HEADER:
    1144                 :          0 :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1145         [ #  # ]:          0 :                 if (!action->reformat.require_reparse)
    1146                 :          0 :                         attr->reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
    1147                 :            : 
    1148                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
    1149                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
    1150                 :          0 :                 attr->insert_header.encap = action->reformat.encap;
    1151                 :          0 :                 attr->insert_header.push_esp = action->reformat.push_esp;
    1152                 :          0 :                 attr->insert_header.insert_anchor = action->reformat.anchor;
    1153                 :          0 :                 attr->insert_header.arg_id = action->reformat.arg_obj->id;
    1154                 :          0 :                 attr->insert_header.header_size = action->reformat.header_size;
    1155                 :          0 :                 attr->insert_header.insert_offset = action->reformat.offset;
    1156                 :          0 :                 break;
    1157                 :          0 :         case MLX5DR_ACTION_TYP_ASO_METER:
    1158                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
    1159                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
    1160                 :          0 :                 attr->aso.aso_type = ASO_OPC_MOD_POLICER;
    1161                 :          0 :                 attr->aso.devx_obj_id = obj->id;
    1162                 :          0 :                 attr->aso.return_reg_id = action->aso.return_reg_id;
    1163                 :          0 :                 break;
    1164                 :          0 :         case MLX5DR_ACTION_TYP_ASO_CT:
    1165                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
    1166                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_ASO;
    1167                 :          0 :                 attr->aso.aso_type = ASO_OPC_MOD_CONNECTION_TRACKING;
    1168                 :          0 :                 attr->aso.devx_obj_id = obj->id;
    1169                 :          0 :                 attr->aso.return_reg_id = action->aso.return_reg_id;
    1170                 :          0 :                 break;
    1171                 :          0 :         case MLX5DR_ACTION_TYP_VPORT:
    1172                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1173                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_VPORT;
    1174                 :          0 :                 attr->vport.vport_num = action->vport.vport_num;
    1175                 :          0 :                 attr->vport.esw_owner_vhca_id =      action->vport.esw_owner_vhca_id;
    1176                 :          0 :                 attr->vport.eswitch_owner_vhca_id_valid = action->ctx->caps->merged_eswitch;
    1177                 :          0 :                 break;
    1178                 :          0 :         case MLX5DR_ACTION_TYP_POP_VLAN:
    1179                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
    1180                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
    1181                 :          0 :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1182                 :          0 :                 attr->remove_words.start_anchor = MLX5_HEADER_ANCHOR_FIRST_VLAN_START;
    1183                 :          0 :                 attr->remove_words.num_of_words = MLX5DR_ACTION_HDR_LEN_L2_VLAN / 2;
    1184                 :          0 :                 break;
    1185                 :          0 :         case MLX5DR_ACTION_TYP_PUSH_VLAN:
    1186                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_INSERT;
    1187                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW6;
    1188                 :          0 :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1189                 :          0 :                 attr->insert_header.encap = 0;
    1190                 :          0 :                 attr->insert_header.push_esp = 0;
    1191                 :          0 :                 attr->insert_header.is_inline = 1;
    1192                 :          0 :                 attr->insert_header.insert_anchor = MLX5_HEADER_ANCHOR_PACKET_START;
    1193                 :          0 :                 attr->insert_header.insert_offset = MLX5DR_ACTION_HDR_LEN_L2_MACS;
    1194                 :          0 :                 attr->insert_header.header_size = MLX5DR_ACTION_HDR_LEN_L2_VLAN;
    1195                 :          0 :                 break;
    1196                 :          0 :         case MLX5DR_ACTION_TYP_REMOVE_HEADER:
    1197         [ #  # ]:          0 :                 if (action->remove_header.type == MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER) {
    1198                 :          0 :                         attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
    1199                 :          0 :                         attr->remove_header.decap = action->remove_header.decap;
    1200                 :          0 :                         attr->remove_header.start_anchor = action->remove_header.start_anchor;
    1201                 :          0 :                         attr->remove_header.end_anchor = action->remove_header.end_anchor;
    1202                 :            :                 } else {
    1203                 :          0 :                         attr->action_type = MLX5_IFC_STC_ACTION_TYPE_REMOVE_WORDS;
    1204                 :          0 :                         attr->remove_words.start_anchor = action->remove_header.start_anchor;
    1205                 :          0 :                         attr->remove_words.num_of_words = action->remove_header.num_of_words;
    1206                 :            :                 }
    1207                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
    1208                 :          0 :                 attr->reparse_mode = MLX5_IFC_STC_REPARSE_ALWAYS;
    1209                 :          0 :                 break;
    1210                 :          0 :         case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
    1211                 :          0 :                 attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_STE_TABLE;
    1212                 :          0 :                 attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
    1213                 :          0 :                 attr->ste_table.ste = action->jump_to_matcher.matcher->match_ste.ste;
    1214                 :          0 :                 attr->ste_table.ste_pool = action->jump_to_matcher.matcher->match_ste.pool;
    1215                 :          0 :                 attr->ste_table.match_definer_id = action->ctx->caps->trivial_match_definer;
    1216                 :          0 :                 break;
    1217                 :          0 :         default:
    1218                 :          0 :                 DR_LOG(ERR, "Invalid action type %d", action->type);
    1219                 :          0 :                 assert(false);
    1220                 :            :         }
    1221                 :          0 : }
    1222                 :            : 
    1223                 :            : static int
    1224                 :          0 : mlx5dr_action_create_stcs(struct mlx5dr_action *action,
    1225                 :            :                           struct mlx5dr_devx_obj *obj)
    1226                 :            : {
    1227                 :          0 :         struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
    1228                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
    1229                 :            :         int ret;
    1230                 :            : 
    1231                 :          0 :         mlx5dr_action_fill_stc_attr(action, obj, &stc_attr);
    1232                 :            : 
    1233                 :            :         /* Block unsupported parallel devx obj modify over the same base */
    1234                 :          0 :         pthread_spin_lock(&ctx->ctrl_lock);
    1235                 :            : 
    1236                 :            :         /* Allocate STC for RX */
    1237         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX) {
    1238                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1239                 :            :                                                      MLX5DR_TABLE_TYPE_NIC_RX,
    1240                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
    1241         [ #  # ]:          0 :                 if (ret)
    1242                 :          0 :                         goto out_err;
    1243                 :            :         }
    1244                 :            : 
    1245                 :            :         /* Allocate STC for TX */
    1246         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX) {
    1247                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1248                 :            :                                                      MLX5DR_TABLE_TYPE_NIC_TX,
    1249                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
    1250         [ #  # ]:          0 :                 if (ret)
    1251                 :          0 :                         goto free_stcs_rx;
    1252                 :            :         }
    1253                 :            : 
    1254                 :            :         /* Allocate STC for FDB */
    1255         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB) {
    1256                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1257                 :            :                                                      MLX5DR_TABLE_TYPE_FDB,
    1258                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_FDB]);
    1259         [ #  # ]:          0 :                 if (ret)
    1260                 :          0 :                         goto free_stcs_tx;
    1261                 :            :         }
    1262                 :            : 
    1263                 :            :         /* Allocate STC for FDB-RX */
    1264         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX) {
    1265                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1266                 :            :                                                      MLX5DR_TABLE_TYPE_FDB_RX,
    1267                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
    1268         [ #  # ]:          0 :                 if (ret)
    1269                 :          0 :                         goto free_stcs_fdb;
    1270                 :            :         }
    1271                 :            : 
    1272                 :            :         /* Allocate STC for FDB-TX */
    1273         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX) {
    1274                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1275                 :            :                                                      MLX5DR_TABLE_TYPE_FDB_TX,
    1276                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
    1277         [ #  # ]:          0 :                 if (ret)
    1278                 :          0 :                         goto free_stcs_fdb_rx;
    1279                 :            :         }
    1280                 :            : 
    1281                 :            :         /* Allocate STC for FDB Unified */
    1282         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED) {
    1283                 :          0 :                 ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr,
    1284                 :            :                                                      MLX5DR_TABLE_TYPE_FDB_UNIFIED,
    1285                 :            :                                                      &action->stc[MLX5DR_TABLE_TYPE_FDB_UNIFIED]);
    1286         [ #  # ]:          0 :                 if (ret)
    1287                 :          0 :                         goto free_stcs_fdb_tx;
    1288                 :            :         }
    1289                 :            : 
    1290                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
    1291                 :            : 
    1292                 :          0 :         return 0;
    1293                 :            : 
    1294                 :            : free_stcs_fdb_tx:
    1295         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
    1296                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_TX,
    1297                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
    1298                 :          0 : free_stcs_fdb_rx:
    1299         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
    1300                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_RX,
    1301                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
    1302                 :          0 : free_stcs_fdb:
    1303         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
    1304                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB,
    1305                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB]);
    1306                 :          0 : free_stcs_tx:
    1307         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
    1308                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_TX,
    1309                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
    1310                 :          0 : free_stcs_rx:
    1311         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
    1312                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_RX,
    1313                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
    1314                 :          0 : out_err:
    1315                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
    1316                 :          0 :         return rte_errno;
    1317                 :            : }
    1318                 :            : 
    1319                 :            : static void
    1320                 :          0 : mlx5dr_action_destroy_stcs(struct mlx5dr_action *action)
    1321                 :            : {
    1322                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
    1323                 :            : 
    1324                 :            :         /* Block unsupported parallel devx obj modify over the same base */
    1325                 :          0 :         pthread_spin_lock(&ctx->ctrl_lock);
    1326                 :            : 
    1327         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_RX)
    1328                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_RX,
    1329                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_NIC_RX]);
    1330                 :            : 
    1331         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_TX)
    1332                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_NIC_TX,
    1333                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_NIC_TX]);
    1334                 :            : 
    1335         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB)
    1336                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB,
    1337                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB]);
    1338                 :            : 
    1339         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_RX)
    1340                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_RX,
    1341                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB_RX]);
    1342                 :            : 
    1343         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_TX)
    1344                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_TX,
    1345                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB_TX]);
    1346                 :            : 
    1347         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)
    1348                 :          0 :                 mlx5dr_action_free_single_stc(ctx, MLX5DR_TABLE_TYPE_FDB_UNIFIED,
    1349                 :            :                                               &action->stc[MLX5DR_TABLE_TYPE_FDB_UNIFIED]);
    1350                 :            : 
    1351                 :          0 :         pthread_spin_unlock(&ctx->ctrl_lock);
    1352                 :          0 : }
    1353                 :            : 
    1354                 :            : static bool
    1355                 :            : mlx5dr_action_is_root_flags(uint32_t flags)
    1356                 :            : {
    1357                 :          0 :         return flags & (MLX5DR_ACTION_FLAG_ROOT_RX |
    1358                 :            :                         MLX5DR_ACTION_FLAG_ROOT_TX |
    1359                 :            :                         MLX5DR_ACTION_FLAG_ROOT_FDB);
    1360                 :            : }
    1361                 :            : 
    1362                 :            : static bool
    1363                 :            : mlx5dr_action_is_hws_flags(uint32_t flags)
    1364                 :            : {
    1365                 :          0 :         return flags & (MLX5DR_ACTION_FLAG_HWS_RX |
    1366                 :            :                         MLX5DR_ACTION_FLAG_HWS_TX |
    1367                 :            :                         MLX5DR_ACTION_FLAG_HWS_FDB |
    1368                 :            :                         MLX5DR_ACTION_FLAG_HWS_FDB_RX |
    1369                 :            :                         MLX5DR_ACTION_FLAG_HWS_FDB_TX |
    1370                 :            :                         MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED);
    1371                 :            : }
    1372                 :            : 
    1373                 :            : static struct mlx5dr_action *
    1374                 :          0 : mlx5dr_action_create_generic_bulk(struct mlx5dr_context *ctx,
    1375                 :            :                                   uint32_t flags,
    1376                 :            :                                   enum mlx5dr_action_type action_type,
    1377                 :            :                                   uint8_t bulk_sz)
    1378                 :            : {
    1379                 :            :         struct mlx5dr_action *action;
    1380                 :            :         int i;
    1381                 :            : 
    1382   [ #  #  #  # ]:          0 :         if (!mlx5dr_action_is_root_flags(flags) &&
    1383                 :            :             !mlx5dr_action_is_hws_flags(flags)) {
    1384                 :          0 :                 DR_LOG(ERR, "Action flags must specify root or non root (HWS)");
    1385                 :          0 :                 rte_errno = ENOTSUP;
    1386                 :          0 :                 return NULL;
    1387                 :            :         }
    1388                 :            : 
    1389         [ #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags) &&
    1390         [ #  # ]:          0 :             !(ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) {
    1391                 :          0 :                 DR_LOG(ERR, "Cannot create HWS action since HWS is not supported");
    1392                 :          0 :                 rte_errno = ENOTSUP;
    1393                 :          0 :                 return NULL;
    1394                 :            :         }
    1395                 :            : 
    1396                 :          0 :         action = simple_calloc(bulk_sz, sizeof(*action));
    1397         [ #  # ]:          0 :         if (!action) {
    1398                 :          0 :                 DR_LOG(ERR, "Failed to allocate memory for action [%d]", action_type);
    1399                 :          0 :                 rte_errno = ENOMEM;
    1400                 :          0 :                 return NULL;
    1401                 :            :         }
    1402                 :            : 
    1403         [ #  # ]:          0 :         for (i = 0; i < bulk_sz; i++) {
    1404                 :          0 :                 action[i].ctx = ctx;
    1405                 :          0 :                 action[i].flags = flags;
    1406                 :          0 :                 action[i].type = action_type;
    1407                 :            :         }
    1408                 :            : 
    1409                 :            :         return action;
    1410                 :            : }
    1411                 :            : 
    1412                 :            : static struct mlx5dr_action *
    1413                 :            : mlx5dr_action_create_generic(struct mlx5dr_context *ctx,
    1414                 :            :                              uint32_t flags,
    1415                 :            :                              enum mlx5dr_action_type action_type)
    1416                 :            : {
    1417                 :          0 :         return mlx5dr_action_create_generic_bulk(ctx, flags, action_type, 1);
    1418                 :            : }
    1419                 :            : 
    1420                 :            : struct mlx5dr_action *
    1421         [ #  # ]:          0 : mlx5dr_action_create_dest_table(struct mlx5dr_context *ctx,
    1422                 :            :                                 struct mlx5dr_table *tbl,
    1423                 :            :                                 uint32_t flags)
    1424                 :            : {
    1425                 :            :         struct mlx5dr_action *action;
    1426                 :            :         int ret;
    1427                 :            : 
    1428         [ #  # ]:          0 :         if (mlx5dr_table_is_root(tbl)) {
    1429                 :          0 :                 DR_LOG(ERR, "Root table cannot be set as destination");
    1430                 :          0 :                 rte_errno = ENOTSUP;
    1431                 :          0 :                 return NULL;
    1432                 :            :         }
    1433                 :            : 
    1434   [ #  #  #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags) &&
    1435                 :            :             mlx5dr_action_is_root_flags(flags)) {
    1436                 :          0 :                 DR_LOG(ERR, "Same action cannot be used for root and non root");
    1437                 :          0 :                 rte_errno = ENOTSUP;
    1438                 :          0 :                 return NULL;
    1439                 :            :         }
    1440                 :            : 
    1441                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TBL);
    1442         [ #  # ]:          0 :         if (!action)
    1443                 :            :                 return NULL;
    1444                 :            : 
    1445                 :          0 :         action->dest_tbl.type = tbl->type;
    1446                 :            : 
    1447         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    1448         [ #  # ]:          0 :                 if (mlx5dr_context_shared_gvmi_used(ctx))
    1449                 :          0 :                         action->dest_tbl.devx_obj = tbl->local_ft;
    1450                 :            :                 else
    1451                 :          0 :                         action->dest_tbl.devx_obj = tbl->ft;
    1452                 :            :         } else {
    1453                 :          0 :                 action->dest_tbl.devx_obj = tbl->ft;
    1454                 :            : 
    1455                 :          0 :                 ret = mlx5dr_action_create_stcs(action, tbl->ft);
    1456         [ #  # ]:          0 :                 if (ret)
    1457                 :          0 :                         goto free_action;
    1458                 :            :         }
    1459                 :            : 
    1460                 :            :         return action;
    1461                 :            : 
    1462                 :            : free_action:
    1463                 :            :         simple_free(action);
    1464                 :          0 :         return NULL;
    1465                 :            : }
    1466                 :            : 
    1467         [ #  # ]:          0 : static int mlx5dr_action_get_dest_tir_obj(struct mlx5dr_context *ctx,
    1468                 :            :                                           struct mlx5dr_action *action,
    1469                 :            :                                           struct mlx5dr_devx_obj *obj,
    1470                 :            :                                           struct mlx5dr_devx_obj **ret_obj)
    1471                 :            : {
    1472                 :            :         int ret;
    1473                 :            : 
    1474         [ #  # ]:          0 :         if (mlx5dr_context_shared_gvmi_used(ctx)) {
    1475                 :          0 :                 ret = mlx5dr_matcher_create_aliased_obj(ctx,
    1476                 :            :                                                         ctx->local_ibv_ctx,
    1477                 :            :                                                         ctx->ibv_ctx,
    1478                 :          0 :                                                         ctx->caps->vhca_id,
    1479                 :            :                                                         obj->id,
    1480                 :            :                                                         MLX5_GENERAL_OBJ_TYPE_TIR_ALIAS,
    1481                 :            :                                                         &action->alias.devx_obj);
    1482         [ #  # ]:          0 :                 if (ret) {
    1483                 :          0 :                         DR_LOG(ERR, "Failed to create tir alias");
    1484                 :          0 :                         return rte_errno;
    1485                 :            :                 }
    1486                 :          0 :                 *ret_obj = action->alias.devx_obj;
    1487                 :            :         } else {
    1488                 :          0 :                 *ret_obj = obj;
    1489                 :            :         }
    1490                 :            : 
    1491                 :            :         return 0;
    1492                 :            : }
    1493                 :            : 
    1494                 :            : struct mlx5dr_action *
    1495                 :          0 : mlx5dr_action_create_dest_tir(struct mlx5dr_context *ctx,
    1496                 :            :                               struct mlx5dr_devx_obj *obj,
    1497                 :            :                               uint32_t flags,
    1498                 :            :                               bool is_local)
    1499                 :            : {
    1500                 :            :         struct mlx5dr_action *action;
    1501                 :            :         int ret;
    1502                 :            : 
    1503   [ #  #  #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags) &&
    1504                 :            :             mlx5dr_action_is_root_flags(flags)) {
    1505                 :          0 :                 DR_LOG(ERR, "Same action cannot be used for root and non root");
    1506                 :          0 :                 rte_errno = ENOTSUP;
    1507                 :          0 :                 return NULL;
    1508                 :            :         }
    1509                 :            : 
    1510         [ #  # ]:          0 :         if ((flags & (MLX5DR_ACTION_FLAG_ROOT_FDB |
    1511                 :            :                       MLX5DR_ACTION_FLAG_HWS_FDB_TX |
    1512                 :          0 :                       MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) ||
    1513         [ #  # ]:          0 :             ((flags & (MLX5DR_ACTION_FLAG_HWS_FDB |
    1514                 :          0 :                        MLX5DR_ACTION_FLAG_HWS_FDB_RX)) &&
    1515         [ #  # ]:          0 :             !ctx->caps->fdb_tir_stc)) {
    1516                 :          0 :                 DR_LOG(ERR, "TIR action not support on FDB or FDB_TX or UNIFIED");
    1517                 :          0 :                 rte_errno = ENOTSUP;
    1518                 :          0 :                 return NULL;
    1519                 :            :         }
    1520                 :            : 
    1521         [ #  # ]:          0 :         if (!is_local) {
    1522                 :          0 :                 DR_LOG(ERR, "TIR should be created on local ibv_device, flags: 0x%x",
    1523                 :            :                        flags);
    1524                 :          0 :                 rte_errno = ENOTSUP;
    1525                 :          0 :                 return NULL;
    1526                 :            :         }
    1527                 :            : 
    1528                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TIR);
    1529         [ #  # ]:          0 :         if (!action)
    1530                 :            :                 return NULL;
    1531                 :            : 
    1532         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    1533                 :          0 :                 action->devx_obj = obj->obj;
    1534                 :            :         } else {
    1535                 :          0 :                 struct mlx5dr_devx_obj *cur_obj = NULL; /*compilation warn*/
    1536                 :            : 
    1537                 :          0 :                 ret = mlx5dr_action_get_dest_tir_obj(ctx, action, obj, &cur_obj);
    1538         [ #  # ]:          0 :                 if (ret) {
    1539                 :          0 :                         DR_LOG(ERR, "Failed to create tir alias (flags: %d)", flags);
    1540                 :          0 :                         goto free_action;
    1541                 :            :                 }
    1542                 :            : 
    1543                 :          0 :                 ret = mlx5dr_action_create_stcs(action, cur_obj);
    1544         [ #  # ]:          0 :                 if (ret)
    1545                 :          0 :                         goto clean_obj;
    1546                 :            : 
    1547                 :          0 :                 action->devx_dest.devx_obj = cur_obj;
    1548                 :            :         }
    1549                 :            : 
    1550                 :            :         return action;
    1551                 :            : 
    1552                 :            : clean_obj:
    1553                 :          0 :         mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
    1554                 :          0 : free_action:
    1555                 :            :         simple_free(action);
    1556                 :          0 :         return NULL;
    1557                 :            : }
    1558                 :            : 
    1559                 :            : struct mlx5dr_action *
    1560                 :          0 : mlx5dr_action_create_dest_drop(struct mlx5dr_context *ctx,
    1561                 :            :                                uint32_t flags)
    1562                 :            : {
    1563                 :            :         struct mlx5dr_action *action;
    1564                 :            :         int ret;
    1565                 :            : 
    1566                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DROP);
    1567         [ #  # ]:          0 :         if (!action)
    1568                 :            :                 return NULL;
    1569                 :            : 
    1570         [ #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags)) {
    1571                 :          0 :                 ret = mlx5dr_action_create_stcs(action, NULL);
    1572         [ #  # ]:          0 :                 if (ret)
    1573                 :          0 :                         goto free_action;
    1574                 :            :         }
    1575                 :            : 
    1576                 :            :         return action;
    1577                 :            : 
    1578                 :            : free_action:
    1579                 :            :         simple_free(action);
    1580                 :          0 :         return NULL;
    1581                 :            : }
    1582                 :            : 
    1583                 :            : struct mlx5dr_action *
    1584                 :          0 : mlx5dr_action_create_default_miss(struct mlx5dr_context *ctx,
    1585                 :            :                                   uint32_t flags)
    1586                 :            : {
    1587                 :            :         struct mlx5dr_action *action;
    1588                 :            :         int ret;
    1589                 :            : 
    1590                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_MISS);
    1591         [ #  # ]:          0 :         if (!action)
    1592                 :            :                 return NULL;
    1593                 :            : 
    1594         [ #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags)) {
    1595                 :          0 :                 ret = mlx5dr_action_create_stcs(action, NULL);
    1596         [ #  # ]:          0 :                 if (ret)
    1597                 :          0 :                         goto free_action;
    1598                 :            :         }
    1599                 :            : 
    1600                 :            :         return action;
    1601                 :            : 
    1602                 :            : free_action:
    1603                 :            :         simple_free(action);
    1604                 :          0 :         return NULL;
    1605                 :            : }
    1606                 :            : 
    1607                 :            : struct mlx5dr_action *
    1608                 :          0 : mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
    1609                 :            :                          uint32_t flags)
    1610                 :            : {
    1611                 :            :         struct mlx5dr_action *action;
    1612                 :            :         int ret;
    1613                 :            : 
    1614         [ #  # ]:          0 :         if (flags & (MLX5DR_ACTION_FLAG_HWS_FDB_TX | MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) {
    1615                 :          0 :                 DR_LOG(ERR, "TAG action not supported for UNIFIED or FDB_TX");
    1616                 :          0 :                 rte_errno = ENOTSUP;
    1617                 :          0 :                 return NULL;
    1618                 :            :         }
    1619                 :            : 
    1620                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_TAG);
    1621         [ #  # ]:          0 :         if (!action)
    1622                 :            :                 return NULL;
    1623                 :            : 
    1624         [ #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags)) {
    1625                 :          0 :                 ret = mlx5dr_action_create_stcs(action, NULL);
    1626         [ #  # ]:          0 :                 if (ret)
    1627                 :          0 :                         goto free_action;
    1628                 :            :         }
    1629                 :            : 
    1630                 :            :         return action;
    1631                 :            : 
    1632                 :            : free_action:
    1633                 :            :         simple_free(action);
    1634                 :          0 :         return NULL;
    1635                 :            : }
    1636                 :            : 
    1637                 :            : struct mlx5dr_action *
    1638                 :          0 : mlx5dr_action_create_last(struct mlx5dr_context *ctx,
    1639                 :            :                           uint32_t flags)
    1640                 :            : {
    1641                 :          0 :         return mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_LAST);
    1642                 :            : }
    1643                 :            : 
    1644                 :            : static struct mlx5dr_action *
    1645                 :          0 : mlx5dr_action_create_aso(struct mlx5dr_context *ctx,
    1646                 :            :                          enum mlx5dr_action_type action_type,
    1647                 :            :                          struct mlx5dr_devx_obj *devx_obj,
    1648                 :            :                          uint8_t return_reg_id,
    1649                 :            :                          uint32_t flags)
    1650                 :            : {
    1651                 :            :         struct mlx5dr_action *action;
    1652                 :            :         int ret;
    1653                 :            : 
    1654         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    1655                 :          0 :                 DR_LOG(ERR, "ASO action cannot be used over root table");
    1656                 :          0 :                 rte_errno = ENOTSUP;
    1657                 :          0 :                 return NULL;
    1658                 :            :         }
    1659                 :            : 
    1660                 :            :         action = mlx5dr_action_create_generic(ctx, flags, action_type);
    1661         [ #  # ]:          0 :         if (!action)
    1662                 :            :                 return NULL;
    1663                 :            : 
    1664                 :          0 :         action->aso.devx_obj = devx_obj;
    1665                 :          0 :         action->aso.return_reg_id = return_reg_id;
    1666                 :            : 
    1667                 :          0 :         ret = mlx5dr_action_create_stcs(action, devx_obj);
    1668         [ #  # ]:          0 :         if (ret)
    1669                 :          0 :                 goto free_action;
    1670                 :            : 
    1671                 :            :         return action;
    1672                 :            : 
    1673                 :            : free_action:
    1674                 :            :         simple_free(action);
    1675                 :          0 :         return NULL;
    1676                 :            : }
    1677                 :            : 
    1678                 :            : struct mlx5dr_action *
    1679                 :          0 : mlx5dr_action_create_aso_meter(struct mlx5dr_context *ctx,
    1680                 :            :                                struct mlx5dr_devx_obj *devx_obj,
    1681                 :            :                                uint8_t return_reg_id,
    1682                 :            :                                uint32_t flags)
    1683                 :            : {
    1684                 :          0 :         return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_METER,
    1685                 :            :                                         devx_obj, return_reg_id, flags);
    1686                 :            : }
    1687                 :            : 
    1688                 :            : struct mlx5dr_action *
    1689                 :          0 : mlx5dr_action_create_aso_ct(struct mlx5dr_context *ctx,
    1690                 :            :                             struct mlx5dr_devx_obj *devx_obj,
    1691                 :            :                             uint8_t return_reg_id,
    1692                 :            :                             uint32_t flags)
    1693                 :            : {
    1694                 :          0 :         return mlx5dr_action_create_aso(ctx, MLX5DR_ACTION_TYP_ASO_CT,
    1695                 :            :                                         devx_obj, return_reg_id, flags);
    1696                 :            : }
    1697                 :            : 
    1698                 :            : struct mlx5dr_action *
    1699                 :          0 : mlx5dr_action_create_counter(struct mlx5dr_context *ctx,
    1700                 :            :                              struct mlx5dr_devx_obj *obj,
    1701                 :            :                              uint32_t flags)
    1702                 :            : {
    1703                 :            :         struct mlx5dr_action *action;
    1704                 :            :         int ret;
    1705                 :            : 
    1706   [ #  #  #  # ]:          0 :         if (mlx5dr_action_is_hws_flags(flags) &&
    1707                 :            :             mlx5dr_action_is_root_flags(flags)) {
    1708                 :          0 :                 DR_LOG(ERR, "Same action cannot be used for root and non root");
    1709                 :          0 :                 rte_errno = ENOTSUP;
    1710                 :          0 :                 return NULL;
    1711                 :            :         }
    1712                 :            : 
    1713         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags) &&
    1714                 :            :             !mlx5dr_action_counter_root_is_supported()) {
    1715                 :          0 :                 DR_LOG(ERR, "Counter action is not supported on root");
    1716                 :          0 :                 rte_errno = ENOTSUP;
    1717                 :          0 :                 return NULL;
    1718                 :            :         }
    1719                 :            : 
    1720                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_CTR);
    1721         [ #  # ]:          0 :         if (!action)
    1722                 :            :                 return NULL;
    1723                 :            : 
    1724                 :            :         if (mlx5dr_action_is_root_flags(flags)) {
    1725                 :            :                 action->devx_obj = obj->obj;
    1726                 :            :         } else {
    1727                 :          0 :                 ret = mlx5dr_action_create_stcs(action, obj);
    1728         [ #  # ]:          0 :                 if (ret)
    1729                 :          0 :                         goto free_action;
    1730                 :            :         }
    1731                 :            : 
    1732                 :            :         return action;
    1733                 :            : 
    1734                 :            : free_action:
    1735                 :            :         simple_free(action);
    1736                 :          0 :         return NULL;
    1737                 :            : }
    1738                 :            : 
    1739                 :          0 : static int mlx5dr_action_create_dest_vport_hws(struct mlx5dr_context *ctx,
    1740                 :            :                                                struct mlx5dr_action *action,
    1741                 :            :                                                uint32_t ib_port_num)
    1742                 :            : {
    1743                 :          0 :         struct mlx5dr_cmd_query_vport_caps vport_caps = {0};
    1744                 :            :         int ret;
    1745                 :            : 
    1746                 :          0 :         ret = mlx5dr_cmd_query_ib_port(ctx->ibv_ctx, &vport_caps, ib_port_num);
    1747         [ #  # ]:          0 :         if (ret) {
    1748                 :          0 :                 DR_LOG(ERR, "Failed querying port %d", ib_port_num);
    1749                 :          0 :                 return ret;
    1750                 :            :         }
    1751                 :          0 :         action->vport.vport_num = vport_caps.vport_num;
    1752                 :          0 :         action->vport.esw_owner_vhca_id = vport_caps.esw_owner_vhca_id;
    1753                 :            : 
    1754         [ #  # ]:          0 :         if (!ctx->caps->merged_eswitch &&
    1755         [ #  # ]:          0 :             action->vport.esw_owner_vhca_id != ctx->caps->vhca_id) {
    1756                 :          0 :                 DR_LOG(ERR, "Not merged-eswitch (%d), not allowed to send to other vhca_id (%d)",
    1757                 :            :                        ctx->caps->vhca_id, action->vport.esw_owner_vhca_id);
    1758                 :          0 :                 rte_errno = ENOTSUP;
    1759                 :          0 :                 return rte_errno;
    1760                 :            :         }
    1761                 :            : 
    1762                 :          0 :         ret = mlx5dr_action_create_stcs(action, NULL);
    1763         [ #  # ]:          0 :         if (ret) {
    1764                 :          0 :                 DR_LOG(ERR, "Failed creating stc for port %d", ib_port_num);
    1765                 :          0 :                 return ret;
    1766                 :            :         }
    1767                 :            : 
    1768                 :            :         return 0;
    1769                 :            : }
    1770                 :            : 
    1771                 :            : struct mlx5dr_action *
    1772                 :          0 : mlx5dr_action_create_dest_vport(struct mlx5dr_context *ctx,
    1773                 :            :                                 uint32_t ib_port_num,
    1774                 :            :                                 uint32_t flags)
    1775                 :            : {
    1776                 :            :         struct mlx5dr_action *action;
    1777                 :            :         int ret;
    1778                 :            : 
    1779         [ #  # ]:          0 :         if (!(flags & (MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_HWS_FDB_RX |
    1780                 :            :                        MLX5DR_ACTION_FLAG_HWS_FDB_TX |
    1781                 :            :                        MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED))) {
    1782                 :          0 :                 DR_LOG(ERR, "Vport action is supported for FDB only");
    1783                 :          0 :                 rte_errno = EINVAL;
    1784                 :          0 :                 return NULL;
    1785                 :            :         }
    1786                 :            : 
    1787                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_VPORT);
    1788         [ #  # ]:          0 :         if (!action)
    1789                 :            :                 return NULL;
    1790                 :            : 
    1791                 :          0 :         ret = mlx5dr_action_create_dest_vport_hws(ctx, action, ib_port_num);
    1792         [ #  # ]:          0 :         if (ret) {
    1793                 :          0 :                 DR_LOG(ERR, "Failed to create vport action HWS");
    1794                 :          0 :                 goto free_action;
    1795                 :            :         }
    1796                 :            : 
    1797                 :            :         return action;
    1798                 :            : 
    1799                 :            : free_action:
    1800                 :            :         simple_free(action);
    1801                 :          0 :         return NULL;
    1802                 :            : }
    1803                 :            : 
    1804                 :            : struct mlx5dr_action *
    1805                 :          0 : mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags)
    1806                 :            : {
    1807                 :            :         struct mlx5dr_action *action;
    1808                 :            :         int ret;
    1809                 :            : 
    1810         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    1811                 :          0 :                 DR_LOG(ERR, "Push vlan action not supported for root");
    1812                 :          0 :                 rte_errno = ENOTSUP;
    1813                 :          0 :                 return NULL;
    1814                 :            :         }
    1815                 :            : 
    1816                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_PUSH_VLAN);
    1817         [ #  # ]:          0 :         if (!action)
    1818                 :            :                 return NULL;
    1819                 :            : 
    1820                 :          0 :         ret = mlx5dr_action_create_stcs(action, NULL);
    1821         [ #  # ]:          0 :         if (ret) {
    1822                 :          0 :                 DR_LOG(ERR, "Failed creating stc for push vlan");
    1823                 :          0 :                 goto free_action;
    1824                 :            :         }
    1825                 :            : 
    1826                 :            :         return action;
    1827                 :            : 
    1828                 :            : free_action:
    1829                 :            :         simple_free(action);
    1830                 :          0 :         return NULL;
    1831                 :            : }
    1832                 :            : 
    1833                 :            : struct mlx5dr_action *
    1834                 :          0 : mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags)
    1835                 :            : {
    1836                 :            :         struct mlx5dr_action *action;
    1837                 :            :         int ret;
    1838                 :            : 
    1839         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    1840                 :          0 :                 DR_LOG(ERR, "Pop vlan action not supported for root");
    1841                 :          0 :                 rte_errno = ENOTSUP;
    1842                 :          0 :                 return NULL;
    1843                 :            :         }
    1844                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_POP_VLAN);
    1845         [ #  # ]:          0 :         if (!action)
    1846                 :            :                 return NULL;
    1847                 :            : 
    1848                 :          0 :         ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
    1849         [ #  # ]:          0 :         if (ret) {
    1850                 :          0 :                 DR_LOG(ERR, "Failed to create remove stc for reformat");
    1851                 :          0 :                 goto free_action;
    1852                 :            :         }
    1853                 :            : 
    1854                 :          0 :         ret = mlx5dr_action_create_stcs(action, NULL);
    1855         [ #  # ]:          0 :         if (ret) {
    1856                 :          0 :                 DR_LOG(ERR, "Failed creating stc for pop vlan");
    1857                 :          0 :                 goto free_shared;
    1858                 :            :         }
    1859                 :            : 
    1860                 :            :         return action;
    1861                 :            : 
    1862                 :            : free_shared:
    1863                 :          0 :         mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
    1864                 :          0 : free_action:
    1865                 :            :         simple_free(action);
    1866                 :          0 :         return NULL;
    1867                 :            : }
    1868                 :            : 
    1869                 :            : static int
    1870                 :          0 : mlx5dr_action_conv_reformat_to_verbs(uint32_t action_type,
    1871                 :            :                                      uint32_t *verb_reformat_type)
    1872                 :            : {
    1873   [ #  #  #  #  :          0 :         switch (action_type) {
                      # ]
    1874                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    1875                 :          0 :                 *verb_reformat_type =
    1876                 :            :                         MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2;
    1877                 :          0 :                 return 0;
    1878                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    1879                 :          0 :                 *verb_reformat_type =
    1880                 :            :                         MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
    1881                 :          0 :                 return 0;
    1882                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    1883                 :          0 :                 *verb_reformat_type =
    1884                 :            :                         MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2;
    1885                 :          0 :                 return 0;
    1886                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    1887                 :          0 :                 *verb_reformat_type =
    1888                 :            :                         MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
    1889                 :          0 :                 return 0;
    1890                 :          0 :         default:
    1891                 :          0 :                 DR_LOG(ERR, "Invalid root reformat action type");
    1892                 :          0 :                 rte_errno = EINVAL;
    1893                 :          0 :                 return rte_errno;
    1894                 :            :         }
    1895                 :            : }
    1896                 :            : 
    1897                 :            : static int
    1898                 :          0 : mlx5dr_action_conv_root_flags_to_dv_ft(uint32_t flags,
    1899                 :            :                                        enum mlx5dv_flow_table_type *ft_type)
    1900                 :            : {
    1901                 :            :         uint8_t is_rx, is_tx, is_fdb;
    1902                 :            : 
    1903                 :          0 :         is_rx = !!(flags & MLX5DR_ACTION_FLAG_ROOT_RX);
    1904                 :          0 :         is_tx = !!(flags & MLX5DR_ACTION_FLAG_ROOT_TX);
    1905                 :          0 :         is_fdb = !!(flags & MLX5DR_ACTION_FLAG_ROOT_FDB);
    1906                 :            : 
    1907         [ #  # ]:          0 :         if (is_rx + is_tx + is_fdb != 1) {
    1908                 :          0 :                 DR_LOG(ERR, "Root action flags must be converted to a single ft type");
    1909                 :          0 :                 rte_errno = ENOTSUP;
    1910                 :          0 :                 return -rte_errno;
    1911                 :            :         }
    1912                 :            : 
    1913         [ #  # ]:          0 :         if (is_rx) {
    1914                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
    1915         [ #  # ]:          0 :         } else if (is_tx) {
    1916                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
    1917                 :            : #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
    1918         [ #  # ]:          0 :         } else if (is_fdb) {
    1919                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
    1920                 :            : #endif
    1921                 :            :         } else {
    1922                 :          0 :                 rte_errno = ENOTSUP;
    1923                 :          0 :                 return -rte_errno;
    1924                 :            :         }
    1925                 :            : 
    1926                 :            :         return 0;
    1927                 :            : }
    1928                 :            : 
    1929                 :            : static int
    1930                 :          0 : mlx5dr_action_conv_hws_flags_to_dv_ft(uint32_t flags,
    1931                 :            :                                      enum mlx5dv_flow_table_type *ft_type)
    1932                 :            : {
    1933                 :            :         uint8_t is_rx, is_tx, is_fdb;
    1934                 :            : 
    1935                 :          0 :         is_rx = !!(flags & MLX5DR_ACTION_FLAG_HWS_RX);
    1936                 :          0 :         is_tx = !!(flags & MLX5DR_ACTION_FLAG_HWS_TX);
    1937                 :          0 :         is_fdb = !!(flags & (MLX5DR_ACTION_FLAG_HWS_FDB |
    1938                 :            :                              MLX5DR_ACTION_FLAG_HWS_FDB_RX |
    1939                 :            :                              MLX5DR_ACTION_FLAG_HWS_FDB_TX |
    1940                 :            :                              MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED));
    1941                 :            : 
    1942         [ #  # ]:          0 :         if (is_rx + is_tx + is_fdb != 1) {
    1943                 :          0 :                 DR_LOG(ERR, "Action flags must be converted to a single ft type");
    1944                 :          0 :                 rte_errno = ENOTSUP;
    1945                 :          0 :                 return -rte_errno;
    1946                 :            :         }
    1947                 :            : 
    1948         [ #  # ]:          0 :         if (is_rx) {
    1949                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
    1950         [ #  # ]:          0 :         } else if (is_tx) {
    1951                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
    1952                 :            : #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
    1953         [ #  # ]:          0 :         } else if (is_fdb) {
    1954                 :          0 :                 *ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
    1955                 :            : #endif
    1956                 :            :         } else {
    1957                 :          0 :                 rte_errno = ENOTSUP;
    1958                 :          0 :                 return -rte_errno;
    1959                 :            :         }
    1960                 :            : 
    1961                 :            :         return 0;
    1962                 :            : }
    1963                 :            : 
    1964                 :            : static int
    1965                 :          0 : mlx5dr_action_create_reformat_root(struct mlx5dr_action *action,
    1966                 :            :                                    size_t data_sz,
    1967                 :            :                                    void *data)
    1968                 :            : {
    1969                 :          0 :         enum mlx5dv_flow_table_type ft_type = 0; /*fix compilation warn*/
    1970                 :          0 :         uint32_t verb_reformat_type = 0;
    1971                 :            :         struct ibv_context *ibv_ctx;
    1972                 :            :         int ret;
    1973                 :            : 
    1974                 :            :         /* Convert action to FT type and verbs reformat type */
    1975                 :          0 :         ret = mlx5dr_action_conv_root_flags_to_dv_ft(action->flags, &ft_type);
    1976         [ #  # ]:          0 :         if (ret)
    1977                 :            :                 return ret;
    1978                 :            : 
    1979                 :          0 :         ret = mlx5dr_action_conv_reformat_to_verbs(action->type, &verb_reformat_type);
    1980         [ #  # ]:          0 :         if (ret)
    1981                 :          0 :                 return rte_errno;
    1982                 :            : 
    1983                 :            :         /* Create the reformat type for root table */
    1984         [ #  # ]:          0 :         ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
    1985                 :          0 :         action->flow_action =
    1986                 :          0 :                 mlx5_glue->dv_create_flow_action_packet_reformat_root(ibv_ctx,
    1987                 :            :                                                                       data_sz,
    1988                 :            :                                                                       data,
    1989                 :            :                                                                       verb_reformat_type,
    1990                 :            :                                                                       ft_type);
    1991         [ #  # ]:          0 :         if (!action->flow_action) {
    1992                 :          0 :                 DR_LOG(ERR, "Failed to create dv_create_flow reformat");
    1993                 :          0 :                 rte_errno = errno;
    1994                 :          0 :                 return rte_errno;
    1995                 :            :         }
    1996                 :            : 
    1997                 :            :         return 0;
    1998                 :            : }
    1999                 :            : 
    2000                 :            : static int
    2001                 :          0 : mlx5dr_action_handle_insert_with_ptr(struct mlx5dr_action *action,
    2002                 :            :                                      uint8_t num_of_hdrs,
    2003                 :            :                                      struct mlx5dr_action_reformat_header *hdrs,
    2004                 :            :                                      uint32_t log_bulk_sz, uint32_t reparse)
    2005                 :            : {
    2006                 :            :         struct mlx5dr_devx_obj *arg_obj;
    2007                 :            :         size_t max_sz = 0;
    2008                 :            :         int ret, i;
    2009                 :            : 
    2010         [ #  # ]:          0 :         for (i = 0; i < num_of_hdrs; i++) {
    2011         [ #  # ]:          0 :                 if (hdrs[i].sz % W_SIZE != 0) {
    2012                 :          0 :                         DR_LOG(ERR, "Header data size should be in WORD granularity");
    2013                 :          0 :                         rte_errno = EINVAL;
    2014                 :          0 :                         return rte_errno;
    2015                 :            :                 }
    2016                 :          0 :                 max_sz = RTE_MAX(hdrs[i].sz, max_sz);
    2017                 :            :         }
    2018                 :            : 
    2019                 :            :         /* Allocate single shared arg object for all headers */
    2020                 :          0 :         arg_obj = mlx5dr_arg_create(action->ctx,
    2021                 :          0 :                                     hdrs->data,
    2022                 :            :                                     max_sz,
    2023                 :            :                                     log_bulk_sz,
    2024                 :          0 :                                     action->flags & MLX5DR_ACTION_FLAG_SHARED);
    2025         [ #  # ]:          0 :         if (!arg_obj)
    2026                 :          0 :                 return rte_errno;
    2027                 :            : 
    2028         [ #  # ]:          0 :         for (i = 0; i < num_of_hdrs; i++) {
    2029                 :          0 :                 action[i].reformat.arg_obj = arg_obj;
    2030                 :          0 :                 action[i].reformat.header_size = hdrs[i].sz;
    2031                 :          0 :                 action[i].reformat.num_of_hdrs = num_of_hdrs;
    2032                 :          0 :                 action[i].reformat.max_hdr_sz = max_sz;
    2033                 :            : 
    2034         [ #  # ]:          0 :                 if (action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2 ||
    2035                 :            :                     action[i].type == MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3) {
    2036                 :          0 :                         action[i].reformat.anchor = MLX5_HEADER_ANCHOR_PACKET_START;
    2037                 :          0 :                         action[i].reformat.offset = 0;
    2038                 :          0 :                         action[i].reformat.encap = 1;
    2039                 :          0 :                         action[i].reformat.push_esp = 0;
    2040                 :            :                 }
    2041                 :            : 
    2042         [ #  # ]:          0 :                 if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
    2043                 :          0 :                         action[i].reformat.require_reparse = true;
    2044         [ #  # ]:          0 :                 else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
    2045                 :          0 :                         action[i].reformat.require_reparse = true;
    2046                 :            : 
    2047                 :          0 :                 ret = mlx5dr_action_create_stcs(&action[i], NULL);
    2048         [ #  # ]:          0 :                 if (ret) {
    2049                 :          0 :                         DR_LOG(ERR, "Failed to create stc for reformat");
    2050                 :          0 :                         goto free_stc;
    2051                 :            :                 }
    2052                 :            :         }
    2053                 :            : 
    2054                 :            :         return 0;
    2055                 :            : 
    2056                 :            : free_stc:
    2057         [ #  # ]:          0 :         while (i--)
    2058                 :          0 :                 mlx5dr_action_destroy_stcs(&action[i]);
    2059                 :            : 
    2060                 :          0 :         mlx5dr_cmd_destroy_obj(arg_obj);
    2061                 :          0 :         return ret;
    2062                 :            : }
    2063                 :            : 
    2064                 :            : static int
    2065                 :          0 : mlx5dr_action_handle_l2_to_tunnel_l3(struct mlx5dr_action *action,
    2066                 :            :                                      uint8_t num_of_hdrs,
    2067                 :            :                                      struct mlx5dr_action_reformat_header *hdrs,
    2068                 :            :                                      uint32_t log_bulk_sz)
    2069                 :            : {
    2070                 :            :         int ret;
    2071                 :            : 
    2072                 :            :         /* The action is remove-l2-header + insert-l3-header */
    2073                 :          0 :         ret = mlx5dr_action_get_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
    2074         [ #  # ]:          0 :         if (ret) {
    2075                 :          0 :                 DR_LOG(ERR, "Failed to create remove stc for reformat");
    2076                 :          0 :                 return ret;
    2077                 :            :         }
    2078                 :            : 
    2079                 :            :         /* Reuse the insert with pointer for the L2L3 header */
    2080                 :          0 :         ret = mlx5dr_action_handle_insert_with_ptr(action,
    2081                 :            :                                                    num_of_hdrs,
    2082                 :            :                                                    hdrs,
    2083                 :            :                                                    log_bulk_sz,
    2084                 :            :                                                    MLX5DR_ACTION_STC_REPARSE_DEFAULT);
    2085         [ #  # ]:          0 :         if (ret)
    2086                 :          0 :                 goto put_shared_stc;
    2087                 :            : 
    2088                 :            :         return 0;
    2089                 :            : 
    2090                 :            : put_shared_stc:
    2091                 :          0 :         mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
    2092                 :          0 :         return ret;
    2093                 :            : }
    2094                 :            : 
    2095                 :          0 : static void mlx5dr_action_prepare_decap_l3_actions(size_t data_sz,
    2096                 :            :                                                    uint8_t *mh_data,
    2097                 :            :                                                    int *num_of_actions)
    2098                 :            : {
    2099                 :            :         int actions;
    2100                 :            :         uint32_t i;
    2101                 :            : 
    2102                 :            :         /* Remove L2L3 outer headers */
    2103         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, mh_data, action_type,
    2104                 :            :                  MLX5_MODIFICATION_TYPE_REMOVE);
    2105         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, mh_data, decap, 0x1);
    2106         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, mh_data, remove_start_anchor,
    2107                 :            :                  MLX5_HEADER_ANCHOR_PACKET_START);
    2108         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove, mh_data, remove_end_anchor,
    2109                 :            :                  MLX5_HEADER_ANCHOR_INNER_IPV6_IPV4);
    2110                 :          0 :         mh_data += MLX5DR_ACTION_DOUBLE_SIZE; /* Assume every action is 2 dw */
    2111                 :            :         actions = 1;
    2112                 :            : 
    2113                 :            :         /* Add the new header using inline action 4Byte at a time, the header
    2114                 :            :          * is added in reversed order to the beginning of the packet to avoid
    2115                 :            :          * incorrect parsing by the HW. Since header is 14B or 18B an extra
    2116                 :            :          * two bytes are padded and later removed.
    2117                 :            :          */
    2118         [ #  # ]:          0 :         for (i = 0; i < data_sz / MLX5DR_ACTION_INLINE_DATA_SIZE + 1; i++) {
    2119         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, mh_data, action_type,
    2120                 :            :                          MLX5_MODIFICATION_TYPE_INSERT);
    2121         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, mh_data, inline_data, 0x1);
    2122         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, mh_data, insert_anchor,
    2123                 :            :                          MLX5_HEADER_ANCHOR_PACKET_START);
    2124         [ #  # ]:          0 :                 MLX5_SET(stc_ste_param_insert, mh_data, insert_size, 2);
    2125                 :          0 :                 mh_data += MLX5DR_ACTION_DOUBLE_SIZE;
    2126                 :          0 :                 actions++;
    2127                 :            :         }
    2128                 :            : 
    2129                 :            :         /* Remove first 2 extra bytes */
    2130         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove_words, mh_data, action_type,
    2131                 :            :                  MLX5_MODIFICATION_TYPE_REMOVE_WORDS);
    2132         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove_words, mh_data, remove_start_anchor,
    2133                 :            :                  MLX5_HEADER_ANCHOR_PACKET_START);
    2134                 :            :         /* The hardware expects here size in words (2 bytes) */
    2135         [ #  # ]:          0 :         MLX5_SET(stc_ste_param_remove_words, mh_data, remove_size, 1);
    2136                 :          0 :         actions++;
    2137                 :            : 
    2138                 :          0 :         *num_of_actions = actions;
    2139                 :          0 : }
    2140                 :            : 
    2141                 :            : static int
    2142                 :          0 : mlx5dr_action_handle_tunnel_l3_to_l2(struct mlx5dr_action *action,
    2143                 :            :                                      uint8_t num_of_hdrs,
    2144                 :            :                                      struct mlx5dr_action_reformat_header *hdrs,
    2145                 :            :                                      uint32_t log_bulk_sz)
    2146                 :            : {
    2147                 :          0 :         uint8_t mh_data[MLX5DR_ACTION_REFORMAT_DATA_SIZE] = {0};
    2148                 :            :         struct mlx5dr_devx_obj *arg_obj, *pat_obj;
    2149                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
    2150                 :            :         int num_of_actions;
    2151                 :            :         int mh_data_size;
    2152                 :            :         int ret, i;
    2153                 :            : 
    2154         [ #  # ]:          0 :         for (i = 0; i < num_of_hdrs; i++) {
    2155         [ #  # ]:          0 :                 if (hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2 &&
    2156                 :            :                     hdrs[i].sz != MLX5DR_ACTION_HDR_LEN_L2_W_VLAN) {
    2157                 :          0 :                         DR_LOG(ERR, "Data size is not supported for decap-l3");
    2158                 :          0 :                         rte_errno = EINVAL;
    2159                 :          0 :                         return rte_errno;
    2160                 :            :                 }
    2161                 :            :         }
    2162                 :            : 
    2163                 :            :         /* Create a full modify header action list in case shared */
    2164                 :          0 :         mlx5dr_action_prepare_decap_l3_actions(hdrs->sz, mh_data, &num_of_actions);
    2165                 :            : 
    2166         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
    2167                 :          0 :                 mlx5dr_action_prepare_decap_l3_data(hdrs->data, mh_data, num_of_actions);
    2168                 :            : 
    2169                 :            :         /* All DecapL3 cases require the same max arg size */
    2170                 :          0 :         arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
    2171                 :            :                                                       (rte_be64_t *)mh_data,
    2172                 :            :                                                       num_of_actions,
    2173                 :            :                                                       log_bulk_sz,
    2174                 :          0 :                                                       action->flags & MLX5DR_ACTION_FLAG_SHARED);
    2175         [ #  # ]:          0 :         if (!arg_obj)
    2176                 :          0 :                 return rte_errno;
    2177                 :            : 
    2178         [ #  # ]:          0 :         for (i = 0; i < num_of_hdrs; i++) {
    2179                 :            :                 memset(mh_data, 0, MLX5DR_ACTION_REFORMAT_DATA_SIZE);
    2180                 :          0 :                 mlx5dr_action_prepare_decap_l3_actions(hdrs[i].sz, mh_data, &num_of_actions);
    2181                 :          0 :                 mh_data_size = num_of_actions * MLX5DR_MODIFY_ACTION_SIZE;
    2182                 :            : 
    2183                 :          0 :                 pat_obj = mlx5dr_pat_get_pattern(ctx, (rte_be64_t *)mh_data, mh_data_size);
    2184         [ #  # ]:          0 :                 if (!pat_obj) {
    2185                 :          0 :                         DR_LOG(ERR, "Failed to allocate pattern for DecapL3");
    2186                 :          0 :                         goto free_stc_and_pat;
    2187                 :            :                 }
    2188                 :            : 
    2189                 :          0 :                 action[i].modify_header.max_num_of_actions = num_of_actions;
    2190                 :          0 :                 action[i].modify_header.num_of_actions = num_of_actions;
    2191                 :          0 :                 action[i].modify_header.num_of_patterns = num_of_hdrs;
    2192                 :          0 :                 action[i].modify_header.arg_obj = arg_obj;
    2193                 :          0 :                 action[i].modify_header.pat_obj = pat_obj;
    2194                 :          0 :                 action[i].modify_header.require_reparse =
    2195                 :          0 :                         mlx5dr_pat_require_reparse((rte_be64_t *)mh_data, num_of_actions);
    2196                 :            : 
    2197                 :          0 :                 ret = mlx5dr_action_create_stcs(&action[i], NULL);
    2198         [ #  # ]:          0 :                 if (ret) {
    2199                 :          0 :                         mlx5dr_pat_put_pattern(ctx, pat_obj);
    2200                 :          0 :                         goto free_stc_and_pat;
    2201                 :            :                 }
    2202                 :            :         }
    2203                 :            : 
    2204                 :            :         return 0;
    2205                 :            : 
    2206                 :            : 
    2207                 :            : free_stc_and_pat:
    2208         [ #  # ]:          0 :         while (i--) {
    2209                 :          0 :                 mlx5dr_action_destroy_stcs(&action[i]);
    2210                 :          0 :                 mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
    2211                 :            :         }
    2212                 :            : 
    2213                 :          0 :         mlx5dr_cmd_destroy_obj(arg_obj);
    2214                 :          0 :         return 0;
    2215                 :            : }
    2216                 :            : 
    2217                 :            : static int
    2218                 :          0 : mlx5dr_action_create_reformat_hws(struct mlx5dr_action *action,
    2219                 :            :                                   uint8_t num_of_hdrs,
    2220                 :            :                                   struct mlx5dr_action_reformat_header *hdrs,
    2221                 :            :                                   uint32_t bulk_size)
    2222                 :            : {
    2223                 :            :         int ret;
    2224                 :            : 
    2225   [ #  #  #  #  :          0 :         switch (action->type) {
                      # ]
    2226                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    2227                 :          0 :                 ret = mlx5dr_action_create_stcs(action, NULL);
    2228                 :          0 :                 break;
    2229                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    2230                 :          0 :                 ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs, hdrs, bulk_size,
    2231                 :            :                                                            MLX5DR_ACTION_STC_REPARSE_DEFAULT);
    2232                 :          0 :                 break;
    2233                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    2234                 :          0 :                 ret = mlx5dr_action_handle_l2_to_tunnel_l3(action, num_of_hdrs, hdrs, bulk_size);
    2235                 :          0 :                 break;
    2236                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    2237                 :          0 :                 ret = mlx5dr_action_handle_tunnel_l3_to_l2(action, num_of_hdrs, hdrs, bulk_size);
    2238                 :          0 :                 break;
    2239                 :          0 :         default:
    2240                 :          0 :                 DR_LOG(ERR, "Invalid HWS reformat action type");
    2241                 :          0 :                 rte_errno = EINVAL;
    2242                 :          0 :                 return rte_errno;
    2243                 :            :         }
    2244                 :            : 
    2245                 :            :         return ret;
    2246                 :            : }
    2247                 :            : 
    2248                 :            : struct mlx5dr_action *
    2249                 :          0 : mlx5dr_action_create_reformat(struct mlx5dr_context *ctx,
    2250                 :            :                               enum mlx5dr_action_type reformat_type,
    2251                 :            :                               uint8_t num_of_hdrs,
    2252                 :            :                               struct mlx5dr_action_reformat_header *hdrs,
    2253                 :            :                               uint32_t log_bulk_size,
    2254                 :            :                               uint32_t flags)
    2255                 :            : {
    2256                 :            :         struct mlx5dr_action *action;
    2257                 :            :         int ret;
    2258                 :            : 
    2259         [ #  # ]:          0 :         if (!num_of_hdrs) {
    2260                 :          0 :                 DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
    2261                 :          0 :                 rte_errno = EINVAL;
    2262                 :          0 :                 return NULL;
    2263                 :            :         }
    2264                 :            : 
    2265                 :          0 :         action = mlx5dr_action_create_generic_bulk(ctx, flags, reformat_type, num_of_hdrs);
    2266         [ #  # ]:          0 :         if (!action)
    2267                 :            :                 return NULL;
    2268                 :            : 
    2269         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    2270         [ #  # ]:          0 :                 if (log_bulk_size) {
    2271                 :          0 :                         DR_LOG(ERR, "Bulk reformat not supported over root");
    2272                 :          0 :                         rte_errno = ENOTSUP;
    2273                 :          0 :                         goto free_action;
    2274                 :            :                 }
    2275                 :            : 
    2276   [ #  #  #  # ]:          0 :                 ret = mlx5dr_action_create_reformat_root(action,
    2277                 :            :                                                          hdrs ? hdrs->sz : 0,
    2278                 :            :                                                          hdrs ? hdrs->data : NULL);
    2279         [ #  # ]:          0 :                 if (ret) {
    2280                 :          0 :                         DR_LOG(ERR, "Failed to create root reformat action");
    2281                 :          0 :                         goto free_action;
    2282                 :            :                 }
    2283                 :            : 
    2284                 :            :                 return action;
    2285                 :            :         }
    2286                 :            : 
    2287         [ #  # ]:          0 :         if (!mlx5dr_action_is_hws_flags(flags) ||
    2288   [ #  #  #  # ]:          0 :             ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
    2289                 :          0 :                 DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
    2290                 :          0 :                 rte_errno = EINVAL;
    2291                 :          0 :                 goto free_action;
    2292                 :            :         }
    2293                 :            : 
    2294                 :          0 :         ret = mlx5dr_action_create_reformat_hws(action, num_of_hdrs, hdrs, log_bulk_size);
    2295         [ #  # ]:          0 :         if (ret) {
    2296                 :          0 :                 DR_LOG(ERR, "Failed to create HWS reformat action");
    2297                 :          0 :                 goto free_action;
    2298                 :            :         }
    2299                 :            : 
    2300                 :            :         return action;
    2301                 :            : 
    2302                 :          0 : free_action:
    2303                 :            :         simple_free(action);
    2304                 :          0 :         return NULL;
    2305                 :            : }
    2306                 :            : 
    2307                 :            : static int
    2308                 :          0 : mlx5dr_action_create_modify_header_root(struct mlx5dr_action *action,
    2309                 :            :                                         size_t actions_sz,
    2310                 :            :                                         rte_be64_t *actions)
    2311                 :            : {
    2312                 :          0 :         enum mlx5dv_flow_table_type ft_type = 0;
    2313                 :            :         struct ibv_context *local_ibv_ctx;
    2314                 :            :         int ret;
    2315                 :            : 
    2316                 :          0 :         ret = mlx5dr_action_conv_root_flags_to_dv_ft(action->flags, &ft_type);
    2317         [ #  # ]:          0 :         if (ret)
    2318                 :            :                 return ret;
    2319                 :            : 
    2320         [ #  # ]:          0 :         local_ibv_ctx = mlx5dr_context_get_local_ibv(action->ctx);
    2321                 :            : 
    2322                 :          0 :         action->flow_action =
    2323                 :          0 :                 mlx5_glue->dv_create_flow_action_modify_header_root(local_ibv_ctx,
    2324                 :            :                                                                     actions_sz,
    2325                 :            :                                                                     (uint64_t *)actions,
    2326                 :            :                                                                     ft_type);
    2327         [ #  # ]:          0 :         if (!action->flow_action) {
    2328                 :          0 :                 rte_errno = errno;
    2329                 :          0 :                 return rte_errno;
    2330                 :            :         }
    2331                 :            : 
    2332                 :            :         return 0;
    2333                 :            : }
    2334                 :            : 
    2335                 :            : static int
    2336                 :          0 : mlx5dr_action_create_modify_header_hws(struct mlx5dr_action *action,
    2337                 :            :                                        uint8_t num_of_patterns,
    2338                 :            :                                        struct mlx5dr_action_mh_pattern *pattern,
    2339                 :            :                                        uint32_t log_bulk_size,
    2340                 :            :                                        uint32_t reparse)
    2341                 :            : {
    2342                 :            :         struct mlx5dr_devx_obj *pat_obj, *arg_obj = NULL;
    2343                 :          0 :         struct mlx5dr_context *ctx = action->ctx;
    2344                 :            :         uint16_t num_actions, max_mh_actions = 0;
    2345                 :            :         int i, ret;
    2346                 :            : 
    2347                 :            :         /* Calculate maximum number of mh actions for shared arg allocation */
    2348         [ #  # ]:          0 :         for (i = 0; i < num_of_patterns; i++)
    2349                 :          0 :                 max_mh_actions = RTE_MAX(max_mh_actions, pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE);
    2350                 :            : 
    2351                 :            :         /* Allocate single shared arg for all patterns based on the max size */
    2352         [ #  # ]:          0 :         if (max_mh_actions > 1) {
    2353                 :          0 :                 arg_obj = mlx5dr_arg_create_modify_header_arg(ctx,
    2354                 :            :                                                               pattern->data,
    2355                 :            :                                                               max_mh_actions,
    2356                 :            :                                                               log_bulk_size,
    2357                 :          0 :                                                               action->flags &
    2358                 :            :                                                               MLX5DR_ACTION_FLAG_SHARED);
    2359         [ #  # ]:          0 :                 if (!arg_obj)
    2360                 :          0 :                         return rte_errno;
    2361                 :            :         }
    2362                 :            : 
    2363         [ #  # ]:          0 :         for (i = 0; i < num_of_patterns; i++) {
    2364         [ #  # ]:          0 :                 if (!mlx5dr_pat_verify_actions(pattern[i].data, pattern[i].sz)) {
    2365                 :          0 :                         DR_LOG(ERR, "Fail to verify pattern modify actions");
    2366                 :          0 :                         rte_errno = EINVAL;
    2367                 :          0 :                         goto free_stc_and_pat;
    2368                 :            :                 }
    2369                 :            : 
    2370                 :          0 :                 num_actions = pattern[i].sz / MLX5DR_MODIFY_ACTION_SIZE;
    2371                 :          0 :                 action[i].modify_header.num_of_patterns = num_of_patterns;
    2372                 :          0 :                 action[i].modify_header.max_num_of_actions = max_mh_actions;
    2373                 :          0 :                 action[i].modify_header.num_of_actions = num_actions;
    2374                 :            : 
    2375         [ #  # ]:          0 :                 if (likely(reparse == MLX5DR_ACTION_STC_REPARSE_DEFAULT))
    2376                 :          0 :                         action[i].modify_header.require_reparse =
    2377                 :          0 :                                 mlx5dr_pat_require_reparse(pattern[i].data, num_actions);
    2378         [ #  # ]:          0 :                 else if (reparse == MLX5DR_ACTION_STC_REPARSE_ON)
    2379                 :          0 :                         action[i].modify_header.require_reparse = true;
    2380                 :            : 
    2381         [ #  # ]:          0 :                 if (num_actions == 1) {
    2382                 :            :                         pat_obj = NULL;
    2383                 :            :                         /* Optimize single modify action to be used inline */
    2384                 :          0 :                         action[i].modify_header.single_action = pattern[i].data[0];
    2385                 :          0 :                         action[i].modify_header.single_action_type =
    2386         [ #  # ]:          0 :                                 MLX5_GET(set_action_in, pattern[i].data, action_type);
    2387                 :            :                 } else {
    2388                 :            :                         /* Multiple modify actions require a pattern */
    2389                 :          0 :                         pat_obj = mlx5dr_pat_get_pattern(ctx, pattern[i].data, pattern[i].sz);
    2390         [ #  # ]:          0 :                         if (!pat_obj) {
    2391                 :          0 :                                 DR_LOG(ERR, "Failed to allocate pattern for modify header");
    2392                 :          0 :                                 goto free_stc_and_pat;
    2393                 :            :                         }
    2394                 :            : 
    2395                 :          0 :                         action[i].modify_header.arg_obj = arg_obj;
    2396                 :          0 :                         action[i].modify_header.pat_obj = pat_obj;
    2397                 :            :                 }
    2398                 :            :                 /* Allocate STC for each action representing a header */
    2399                 :          0 :                 ret = mlx5dr_action_create_stcs(&action[i], NULL);
    2400         [ #  # ]:          0 :                 if (ret) {
    2401         [ #  # ]:          0 :                         if (pat_obj)
    2402                 :          0 :                                 mlx5dr_pat_put_pattern(ctx, pat_obj);
    2403                 :          0 :                         goto free_stc_and_pat;
    2404                 :            :                 }
    2405                 :            :         }
    2406                 :            : 
    2407                 :            :         return 0;
    2408                 :            : 
    2409                 :            : free_stc_and_pat:
    2410         [ #  # ]:          0 :         while (i--) {
    2411                 :          0 :                 mlx5dr_action_destroy_stcs(&action[i]);
    2412         [ #  # ]:          0 :                 if (action[i].modify_header.pat_obj)
    2413                 :          0 :                         mlx5dr_pat_put_pattern(ctx, action[i].modify_header.pat_obj);
    2414                 :            :         }
    2415                 :            : 
    2416         [ #  # ]:          0 :         if (arg_obj)
    2417                 :          0 :                 mlx5dr_cmd_destroy_obj(arg_obj);
    2418                 :            : 
    2419                 :          0 :         return rte_errno;
    2420                 :            : }
    2421                 :            : 
    2422                 :            : struct mlx5dr_action *
    2423                 :          0 : mlx5dr_action_create_modify_header_reparse(struct mlx5dr_context *ctx,
    2424                 :            :                                            uint8_t num_of_patterns,
    2425                 :            :                                            struct mlx5dr_action_mh_pattern *patterns,
    2426                 :            :                                            uint32_t log_bulk_size,
    2427                 :            :                                            uint32_t flags, uint32_t reparse)
    2428                 :            : {
    2429                 :            :         struct mlx5dr_action *action;
    2430                 :            :         int ret;
    2431                 :            : 
    2432         [ #  # ]:          0 :         if (!num_of_patterns) {
    2433                 :          0 :                 DR_LOG(ERR, "Invalid number of patterns");
    2434                 :          0 :                 rte_errno = ENOTSUP;
    2435                 :          0 :                 return NULL;
    2436                 :            :         }
    2437                 :            : 
    2438                 :          0 :         action = mlx5dr_action_create_generic_bulk(ctx, flags,
    2439                 :            :                                                    MLX5DR_ACTION_TYP_MODIFY_HDR,
    2440                 :            :                                                    num_of_patterns);
    2441         [ #  # ]:          0 :         if (!action)
    2442                 :            :                 return NULL;
    2443                 :            : 
    2444         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    2445         [ #  # ]:          0 :                 if (log_bulk_size) {
    2446                 :          0 :                         DR_LOG(ERR, "Bulk modify-header not supported over root");
    2447                 :          0 :                         rte_errno = ENOTSUP;
    2448                 :          0 :                         goto free_action;
    2449                 :            :                 }
    2450                 :            : 
    2451         [ #  # ]:          0 :                 if (num_of_patterns != 1) {
    2452                 :          0 :                         DR_LOG(ERR, "Only a single pattern supported over root");
    2453                 :          0 :                         rte_errno = ENOTSUP;
    2454                 :          0 :                         goto free_action;
    2455                 :            :                 }
    2456                 :            : 
    2457                 :          0 :                 ret = mlx5dr_action_create_modify_header_root(action,
    2458                 :            :                                                               patterns->sz,
    2459                 :            :                                                               patterns->data);
    2460         [ #  # ]:          0 :                 if (ret)
    2461                 :          0 :                         goto free_action;
    2462                 :            : 
    2463                 :            :                 return action;
    2464                 :            :         }
    2465                 :            : 
    2466   [ #  #  #  # ]:          0 :         if ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_patterns > 1)) {
    2467                 :          0 :                 DR_LOG(ERR, "Action cannot be shared with requested pattern or size");
    2468                 :          0 :                 rte_errno = EINVAL;
    2469                 :          0 :                 goto free_action;
    2470                 :            :         }
    2471                 :            : 
    2472                 :          0 :         ret = mlx5dr_action_create_modify_header_hws(action,
    2473                 :            :                                                      num_of_patterns,
    2474                 :            :                                                      patterns,
    2475                 :            :                                                      log_bulk_size,
    2476                 :            :                                                      reparse);
    2477         [ #  # ]:          0 :         if (ret)
    2478                 :          0 :                 goto free_action;
    2479                 :            : 
    2480                 :            :         return action;
    2481                 :            : 
    2482                 :          0 : free_action:
    2483                 :            :         simple_free(action);
    2484                 :          0 :         return NULL;
    2485                 :            : }
    2486                 :            : 
    2487                 :            : struct mlx5dr_action *
    2488                 :          0 : mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
    2489                 :            :                                    uint8_t num_of_patterns,
    2490                 :            :                                    struct mlx5dr_action_mh_pattern *patterns,
    2491                 :            :                                    uint32_t log_bulk_size,
    2492                 :            :                                    uint32_t flags)
    2493                 :            : {
    2494                 :          0 :         return mlx5dr_action_create_modify_header_reparse(ctx, num_of_patterns, patterns,
    2495                 :            :                                                           log_bulk_size, flags,
    2496                 :            :                                                           MLX5DR_ACTION_STC_REPARSE_DEFAULT);
    2497                 :            : }
    2498                 :            : static struct mlx5dr_devx_obj *
    2499                 :          0 : mlx5dr_action_dest_array_process_reformat(struct mlx5dr_context *ctx,
    2500                 :            :                                           enum mlx5dr_action_type type,
    2501                 :            :                                           void *reformat_data,
    2502                 :            :                                           size_t reformat_data_sz)
    2503                 :            : {
    2504                 :          0 :         struct mlx5dr_cmd_packet_reformat_create_attr pr_attr = {0};
    2505                 :            :         struct mlx5dr_devx_obj *reformat_devx_obj;
    2506                 :            : 
    2507         [ #  # ]:          0 :         if (!reformat_data || !reformat_data_sz) {
    2508                 :          0 :                 DR_LOG(ERR, "Empty reformat action or data");
    2509                 :          0 :                 rte_errno = EINVAL;
    2510                 :          0 :                 return NULL;
    2511                 :            :         }
    2512                 :            : 
    2513      [ #  #  # ]:          0 :         switch (type) {
    2514                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    2515                 :          0 :                 pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L2_TUNNEL;
    2516                 :          0 :                 break;
    2517                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    2518                 :          0 :                 pr_attr.type = MLX5_PACKET_REFORMAT_CONTEXT_REFORMAT_TYPE_L2_TO_L3_TUNNEL;
    2519                 :          0 :                 break;
    2520                 :          0 :         default:
    2521                 :          0 :                 DR_LOG(ERR, "Invalid value for reformat type");
    2522                 :          0 :                 rte_errno = EINVAL;
    2523                 :          0 :                 return NULL;
    2524                 :            :         }
    2525                 :            :         pr_attr.reformat_param_0 = 0;
    2526                 :          0 :         pr_attr.data_sz = reformat_data_sz;
    2527                 :          0 :         pr_attr.data = reformat_data;
    2528                 :            : 
    2529                 :          0 :         reformat_devx_obj = mlx5dr_cmd_packet_reformat_create(ctx->ibv_ctx, &pr_attr);
    2530         [ #  # ]:          0 :         if (!reformat_devx_obj)
    2531                 :          0 :                 return NULL;
    2532                 :            : 
    2533                 :            :         return reformat_devx_obj;
    2534                 :            : }
    2535                 :            : 
    2536                 :            : struct mlx5dr_action *
    2537                 :          0 : mlx5dr_action_create_dest_array(struct mlx5dr_context *ctx,
    2538                 :            :                                 size_t num_dest,
    2539                 :            :                                 struct mlx5dr_action_dest_attr *dests,
    2540                 :            :                                 uint32_t flags)
    2541                 :            : {
    2542                 :            :         struct mlx5dr_cmd_set_fte_dest *dest_list = NULL;
    2543                 :            :         struct mlx5dr_devx_obj *packet_reformat = NULL;
    2544                 :          0 :         struct mlx5dr_cmd_ft_create_attr ft_attr = {0};
    2545                 :          0 :         struct mlx5dr_cmd_set_fte_attr fte_attr = {0};
    2546                 :            :         struct mlx5dr_cmd_forward_tbl *fw_island;
    2547                 :            :         enum mlx5dr_table_type table_type;
    2548                 :            :         struct mlx5dr_action *action;
    2549                 :            :         uint32_t i;
    2550                 :            :         int ret;
    2551                 :            : 
    2552         [ #  # ]:          0 :         if (num_dest <= 1) {
    2553                 :          0 :                 rte_errno = EINVAL;
    2554                 :          0 :                 DR_LOG(ERR, "Action must have multiple dests");
    2555                 :          0 :                 return NULL;
    2556                 :            :         }
    2557                 :            : 
    2558         [ #  # ]:          0 :         if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
    2559                 :          0 :                 DR_LOG(ERR, "Action flags not supported, should include SHARED");
    2560                 :          0 :                 rte_errno = ENOTSUP;
    2561                 :          0 :                 return NULL;
    2562                 :            :         }
    2563                 :            : 
    2564                 :          0 :         flags = flags & ~MLX5DR_ACTION_FLAG_SHARED;
    2565                 :            : 
    2566         [ #  # ]:          0 :         if (flags == MLX5DR_ACTION_FLAG_HWS_RX) {
    2567                 :            :                 ft_attr.type = FS_FT_NIC_RX;
    2568                 :          0 :                 ft_attr.level = MLX5_IFC_MULTI_PATH_FT_MAX_LEVEL - 1;
    2569                 :            :                 table_type = MLX5DR_TABLE_TYPE_NIC_RX;
    2570         [ #  # ]:          0 :         } else if (flags & (MLX5DR_ACTION_FLAG_HWS_FDB | MLX5DR_ACTION_FLAG_HWS_FDB_RX |
    2571                 :            :                             MLX5DR_ACTION_FLAG_HWS_FDB_TX |
    2572                 :            :                             MLX5DR_ACTION_FLAG_HWS_FDB_UNIFIED)) {
    2573                 :          0 :                 ft_attr.type = FS_FT_FDB;
    2574                 :          0 :                 ft_attr.level = ctx->caps->fdb_ft.max_level - 1;
    2575                 :            :                 table_type = MLX5DR_TABLE_TYPE_FDB;
    2576                 :            :         } else {
    2577                 :          0 :                 DR_LOG(ERR, "Action flags not supported");
    2578                 :          0 :                 rte_errno = ENOTSUP;
    2579                 :          0 :                 return NULL;
    2580                 :            :         }
    2581                 :            : 
    2582         [ #  # ]:          0 :         if (mlx5dr_context_shared_gvmi_used(ctx)) {
    2583                 :          0 :                 DR_LOG(ERR, "Cannot use this action in shared GVMI context");
    2584                 :          0 :                 rte_errno = ENOTSUP;
    2585                 :          0 :                 return NULL;
    2586                 :            :         }
    2587                 :            : 
    2588                 :            :         dest_list = simple_calloc(num_dest, sizeof(*dest_list));
    2589         [ #  # ]:          0 :         if (!dest_list) {
    2590                 :          0 :                 DR_LOG(ERR, "Failed to allocate memory for destinations");
    2591                 :          0 :                 rte_errno = ENOMEM;
    2592                 :          0 :                 return NULL;
    2593                 :            :         }
    2594                 :            : 
    2595         [ #  # ]:          0 :         for (i = 0; i < num_dest; i++) {
    2596                 :          0 :                 enum mlx5dr_action_type *action_type = dests[i].action_type;
    2597                 :            : 
    2598         [ #  # ]:          0 :                 if (!mlx5dr_action_check_combo(dests[i].action_type, table_type)) {
    2599                 :          0 :                         DR_LOG(ERR, "Invalid combination of actions");
    2600                 :          0 :                         rte_errno = EINVAL;
    2601                 :          0 :                         goto free_dest_list;
    2602                 :            :                 }
    2603                 :            : 
    2604         [ #  # ]:          0 :                 for (; *action_type != MLX5DR_ACTION_TYP_LAST; action_type++) {
    2605   [ #  #  #  #  :          0 :                         switch (*action_type) {
                #  #  # ]
    2606                 :          0 :                         case MLX5DR_ACTION_TYP_TBL:
    2607                 :          0 :                                 dest_list[i].destination_type =
    2608                 :            :                                         MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
    2609                 :          0 :                                 dest_list[i].destination_id = dests[i].dest->dest_tbl.devx_obj->id;
    2610                 :          0 :                                 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
    2611                 :          0 :                                 fte_attr.ignore_flow_level = 1;
    2612                 :          0 :                                 break;
    2613                 :            :                         case MLX5DR_ACTION_TYP_MISS:
    2614                 :            :                                 if (!mlx5dr_table_is_fdb_any(table_type)) {
    2615                 :          0 :                                         DR_LOG(ERR, "Miss action supported for FDB only");
    2616                 :          0 :                                         rte_errno = ENOTSUP;
    2617                 :          0 :                                         goto free_dest_list;
    2618                 :            :                                 }
    2619                 :          0 :                                 dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
    2620                 :          0 :                                 dest_list[i].destination_id =
    2621                 :          0 :                                         ctx->caps->eswitch_manager_vport_number;
    2622                 :          0 :                                 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
    2623                 :          0 :                                 break;
    2624                 :          0 :                         case MLX5DR_ACTION_TYP_VPORT:
    2625                 :          0 :                                 dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
    2626                 :          0 :                                 dest_list[i].destination_id = dests[i].dest->vport.vport_num;
    2627                 :          0 :                                 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
    2628         [ #  # ]:          0 :                                 if (ctx->caps->merged_eswitch) {
    2629                 :          0 :                                         dest_list[i].ext_flags |=
    2630                 :            :                                                 MLX5DR_CMD_EXT_DEST_ESW_OWNER_VHCA_ID;
    2631                 :          0 :                                         dest_list[i].esw_owner_vhca_id =
    2632                 :          0 :                                                 dests[i].dest->vport.esw_owner_vhca_id;
    2633                 :            :                                 }
    2634                 :            :                                 break;
    2635                 :          0 :                         case MLX5DR_ACTION_TYP_TIR:
    2636                 :          0 :                                 dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_TIR;
    2637                 :          0 :                                 dest_list[i].destination_id = dests[i].dest->devx_dest.devx_obj->id;
    2638                 :          0 :                                 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
    2639                 :          0 :                                 break;
    2640                 :          0 :                         case MLX5DR_ACTION_TYP_DROP:
    2641                 :          0 :                                 dest_list[i].destination_type = MLX5_FLOW_DESTINATION_TYPE_NOP;
    2642                 :          0 :                                 fte_attr.action_flags |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
    2643                 :          0 :                                 break;
    2644                 :          0 :                         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    2645                 :            :                         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    2646                 :          0 :                                 packet_reformat = mlx5dr_action_dest_array_process_reformat
    2647                 :            :                                                         (ctx,
    2648                 :            :                                                          *action_type,
    2649                 :            :                                                          dests[i].reformat.reformat_data,
    2650                 :            :                                                          dests[i].reformat.reformat_data_sz);
    2651         [ #  # ]:          0 :                                 if (!packet_reformat)
    2652                 :          0 :                                         goto free_dest_list;
    2653                 :            : 
    2654                 :          0 :                                 dest_list[i].ext_flags |= MLX5DR_CMD_EXT_DEST_REFORMAT;
    2655                 :          0 :                                 dest_list[i].ext_reformat = packet_reformat;
    2656                 :          0 :                                 ft_attr.reformat_en = true;
    2657                 :          0 :                                 fte_attr.extended_dest = 1;
    2658                 :          0 :                                 break;
    2659                 :          0 :                         default:
    2660                 :          0 :                                 DR_LOG(ERR, "Unsupported action in dest_array");
    2661                 :          0 :                                 rte_errno = ENOTSUP;
    2662                 :          0 :                                 goto free_dest_list;
    2663                 :            :                         }
    2664                 :            :                 }
    2665                 :            :         }
    2666                 :          0 :         fte_attr.dests_num = num_dest;
    2667                 :          0 :         fte_attr.dests = dest_list;
    2668                 :            : 
    2669                 :          0 :         fw_island = mlx5dr_cmd_forward_tbl_create(ctx->ibv_ctx, &ft_attr, &fte_attr);
    2670         [ #  # ]:          0 :         if (!fw_island)
    2671                 :          0 :                 goto free_dest_list;
    2672                 :            : 
    2673                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ARRAY);
    2674         [ #  # ]:          0 :         if (!action)
    2675                 :          0 :                 goto destroy_fw_island;
    2676                 :            : 
    2677                 :          0 :         ret = mlx5dr_action_create_stcs(action, fw_island->ft);
    2678         [ #  # ]:          0 :         if (ret)
    2679                 :          0 :                 goto free_action;
    2680                 :            : 
    2681                 :          0 :         action->dest_array.fw_island = fw_island;
    2682                 :          0 :         action->dest_array.num_dest = num_dest;
    2683                 :          0 :         action->dest_array.dest_list = dest_list;
    2684                 :            : 
    2685                 :          0 :         return action;
    2686                 :            : 
    2687                 :            : free_action:
    2688                 :            :         simple_free(action);
    2689                 :          0 : destroy_fw_island:
    2690                 :          0 :         mlx5dr_cmd_forward_tbl_destroy(fw_island);
    2691                 :            : free_dest_list:
    2692         [ #  # ]:          0 :         for (i = 0; i < num_dest; i++) {
    2693         [ #  # ]:          0 :                 if (dest_list[i].ext_reformat)
    2694                 :          0 :                         mlx5dr_cmd_destroy_obj(dest_list[i].ext_reformat);
    2695                 :            :         }
    2696                 :            :         simple_free(dest_list);
    2697                 :          0 :         return NULL;
    2698                 :            : }
    2699                 :            : 
    2700                 :            : struct mlx5dr_action *
    2701                 :          0 : mlx5dr_action_create_dest_root(struct mlx5dr_context *ctx,
    2702                 :            :                                uint16_t priority,
    2703                 :            :                                uint32_t flags)
    2704                 :            : {
    2705                 :          0 :         struct mlx5dv_steering_anchor_attr attr = {0};
    2706                 :            :         struct mlx5dv_steering_anchor *sa;
    2707                 :            :         struct mlx5dr_action *action;
    2708                 :            :         int ret;
    2709                 :            : 
    2710         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    2711                 :          0 :                 DR_LOG(ERR, "Action flags must be only non root (HWS)");
    2712                 :          0 :                 rte_errno = ENOTSUP;
    2713                 :          0 :                 return NULL;
    2714                 :            :         }
    2715                 :            : 
    2716         [ #  # ]:          0 :         if (mlx5dr_context_shared_gvmi_used(ctx)) {
    2717                 :          0 :                 DR_LOG(ERR, "Cannot use this action in shared GVMI context");
    2718                 :          0 :                 rte_errno = ENOTSUP;
    2719                 :          0 :                 return NULL;
    2720                 :            :         }
    2721                 :            : 
    2722         [ #  # ]:          0 :         if (mlx5dr_action_conv_hws_flags_to_dv_ft(flags, &attr.ft_type))
    2723                 :            :                 return NULL;
    2724                 :            : 
    2725                 :          0 :         attr.priority = priority;
    2726                 :            : 
    2727                 :          0 :         sa = mlx5_glue->create_steering_anchor(ctx->ibv_ctx, &attr);
    2728         [ #  # ]:          0 :         if (!sa) {
    2729                 :          0 :                 DR_LOG(ERR, "Creation of steering anchor failed");
    2730                 :          0 :                 return NULL;
    2731                 :            :         }
    2732                 :            : 
    2733                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ROOT);
    2734         [ #  # ]:          0 :         if (!action)
    2735                 :          0 :                 goto free_steering_anchor;
    2736                 :            : 
    2737                 :          0 :         action->root_tbl.sa = sa;
    2738                 :            : 
    2739                 :          0 :         ret = mlx5dr_action_create_stcs(action, NULL);
    2740         [ #  # ]:          0 :         if (ret)
    2741                 :          0 :                 goto free_action;
    2742                 :            : 
    2743                 :            :         return action;
    2744                 :            : 
    2745                 :            : free_action:
    2746                 :            :         simple_free(action);
    2747                 :          0 : free_steering_anchor:
    2748                 :          0 :         mlx5_glue->destroy_steering_anchor(sa);
    2749                 :          0 :         return NULL;
    2750                 :            : }
    2751                 :            : 
    2752                 :            : static struct mlx5dr_action *
    2753                 :          0 : mlx5dr_action_create_insert_header_reparse(struct mlx5dr_context *ctx,
    2754                 :            :                                            uint8_t num_of_hdrs,
    2755                 :            :                                            struct mlx5dr_action_insert_header *hdrs,
    2756                 :            :                                            uint32_t log_bulk_size,
    2757                 :            :                                            uint32_t flags, uint32_t reparse)
    2758                 :            : {
    2759                 :            :         struct mlx5dr_action_reformat_header *reformat_hdrs;
    2760                 :            :         struct mlx5dr_action *action;
    2761                 :            :         int i, ret;
    2762                 :            : 
    2763         [ #  # ]:          0 :         if (!num_of_hdrs) {
    2764                 :          0 :                 DR_LOG(ERR, "Reformat num_of_hdrs cannot be zero");
    2765                 :          0 :                 rte_errno = EINVAL;
    2766                 :          0 :                 return NULL;
    2767                 :            :         }
    2768                 :            : 
    2769         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    2770                 :          0 :                 DR_LOG(ERR, "Dynamic reformat action not supported over root");
    2771                 :          0 :                 rte_errno = ENOTSUP;
    2772                 :          0 :                 return NULL;
    2773                 :            :         }
    2774                 :            : 
    2775         [ #  # ]:          0 :         if (!mlx5dr_action_is_hws_flags(flags) ||
    2776   [ #  #  #  # ]:          0 :             ((flags & MLX5DR_ACTION_FLAG_SHARED) && (log_bulk_size || num_of_hdrs > 1))) {
    2777                 :          0 :                 DR_LOG(ERR, "Reformat flags don't fit HWS (flags: 0x%x)", flags);
    2778                 :          0 :                 rte_errno = EINVAL;
    2779                 :          0 :                 return NULL;
    2780                 :            :         }
    2781                 :            : 
    2782                 :          0 :         action = mlx5dr_action_create_generic_bulk(ctx, flags,
    2783                 :            :                                                    MLX5DR_ACTION_TYP_INSERT_HEADER,
    2784                 :            :                                                    num_of_hdrs);
    2785         [ #  # ]:          0 :         if (!action)
    2786                 :            :                 return NULL;
    2787                 :            : 
    2788                 :          0 :         reformat_hdrs = simple_calloc(num_of_hdrs, sizeof(*reformat_hdrs));
    2789         [ #  # ]:          0 :         if (!reformat_hdrs) {
    2790                 :          0 :                 DR_LOG(ERR, "Failed to allocate memory for reformat_hdrs");
    2791                 :          0 :                 rte_errno = ENOMEM;
    2792                 :          0 :                 goto free_action;
    2793                 :            :         }
    2794                 :            : 
    2795         [ #  # ]:          0 :         for (i = 0; i < num_of_hdrs; i++) {
    2796         [ #  # ]:          0 :                 if (hdrs[i].offset % W_SIZE != 0) {
    2797                 :          0 :                         DR_LOG(ERR, "Header offset should be in WORD granularity");
    2798                 :          0 :                         rte_errno = EINVAL;
    2799                 :          0 :                         goto free_reformat_hdrs;
    2800                 :            :                 }
    2801                 :            : 
    2802                 :          0 :                 action[i].reformat.anchor = hdrs[i].anchor;
    2803                 :          0 :                 action[i].reformat.encap = hdrs[i].encap;
    2804                 :          0 :                 action[i].reformat.push_esp = hdrs[i].push_esp;
    2805                 :          0 :                 action[i].reformat.offset = hdrs[i].offset;
    2806                 :          0 :                 reformat_hdrs[i].sz = hdrs[i].hdr.sz;
    2807                 :          0 :                 reformat_hdrs[i].data = hdrs[i].hdr.data;
    2808                 :            :         }
    2809                 :            : 
    2810                 :          0 :         ret = mlx5dr_action_handle_insert_with_ptr(action, num_of_hdrs,
    2811                 :            :                                                    reformat_hdrs, log_bulk_size,
    2812                 :            :                                                    reparse);
    2813         [ #  # ]:          0 :         if (ret) {
    2814                 :          0 :                 DR_LOG(ERR, "Failed to create HWS reformat action");
    2815                 :          0 :                 goto free_reformat_hdrs;
    2816                 :            :         }
    2817                 :            : 
    2818                 :            :         simple_free(reformat_hdrs);
    2819                 :            : 
    2820                 :          0 :         return action;
    2821                 :            : 
    2822                 :          0 : free_reformat_hdrs:
    2823                 :            :         simple_free(reformat_hdrs);
    2824                 :          0 : free_action:
    2825                 :            :         simple_free(action);
    2826                 :          0 :         return NULL;
    2827                 :            : }
    2828                 :            : 
    2829                 :            : struct mlx5dr_action *
    2830                 :          0 : mlx5dr_action_create_insert_header(struct mlx5dr_context *ctx,
    2831                 :            :                                    uint8_t num_of_hdrs,
    2832                 :            :                                    struct mlx5dr_action_insert_header *hdrs,
    2833                 :            :                                    uint32_t log_bulk_size,
    2834                 :            :                                    uint32_t flags)
    2835                 :            : {
    2836                 :          0 :         return mlx5dr_action_create_insert_header_reparse(ctx, num_of_hdrs, hdrs,
    2837                 :            :                                                           log_bulk_size, flags,
    2838                 :            :                                                           MLX5DR_ACTION_STC_REPARSE_DEFAULT);
    2839                 :            : }
    2840                 :            : 
    2841                 :            : struct mlx5dr_action *
    2842                 :          0 : mlx5dr_action_create_remove_header(struct mlx5dr_context *ctx,
    2843                 :            :                                    struct mlx5dr_action_remove_header_attr *attr,
    2844                 :            :                                    uint32_t flags)
    2845                 :            : {
    2846                 :            :         struct mlx5dr_action *action;
    2847                 :            : 
    2848         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    2849                 :          0 :                 DR_LOG(ERR, "Remove header action not supported over root");
    2850                 :          0 :                 rte_errno = ENOTSUP;
    2851                 :          0 :                 return NULL;
    2852                 :            :         }
    2853                 :            : 
    2854                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_REMOVE_HEADER);
    2855         [ #  # ]:          0 :         if (!action)
    2856                 :            :                 return NULL;
    2857                 :            : 
    2858      [ #  #  # ]:          0 :         switch (attr->type) {
    2859                 :          0 :         case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER:
    2860                 :          0 :                 action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
    2861                 :          0 :                 action->remove_header.start_anchor = attr->by_anchor.start_anchor;
    2862                 :          0 :                 action->remove_header.end_anchor = attr->by_anchor.end_anchor;
    2863                 :          0 :                 action->remove_header.decap = attr->by_anchor.decap;
    2864                 :          0 :                 break;
    2865                 :          0 :         case MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET:
    2866         [ #  # ]:          0 :                 if (attr->by_offset.size % W_SIZE != 0) {
    2867                 :          0 :                         DR_LOG(ERR, "Invalid size, HW supports header remove in WORD granularity");
    2868                 :          0 :                         rte_errno = EINVAL;
    2869                 :          0 :                         goto free_action;
    2870                 :            :                 }
    2871                 :            : 
    2872         [ #  # ]:          0 :                 if (attr->by_offset.size > MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE) {
    2873                 :          0 :                         DR_LOG(ERR, "Header removal size limited to %u bytes",
    2874                 :            :                                MLX5DR_ACTION_REMOVE_HEADER_MAX_SIZE);
    2875                 :          0 :                         rte_errno = EINVAL;
    2876                 :          0 :                         goto free_action;
    2877                 :            :                 }
    2878                 :            : 
    2879                 :          0 :                 action->remove_header.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_OFFSET;
    2880                 :          0 :                 action->remove_header.start_anchor = attr->by_offset.start_anchor;
    2881                 :          0 :                 action->remove_header.num_of_words = attr->by_offset.size / W_SIZE;
    2882                 :          0 :                 break;
    2883                 :          0 :         default:
    2884                 :          0 :                 DR_LOG(ERR, "Unsupported remove header type %u", attr->type);
    2885                 :          0 :                 rte_errno = ENOTSUP;
    2886                 :          0 :                 goto free_action;
    2887                 :            :         }
    2888                 :            : 
    2889         [ #  # ]:          0 :         if (mlx5dr_action_create_stcs(action, NULL))
    2890                 :          0 :                 goto free_action;
    2891                 :            : 
    2892                 :            :         return action;
    2893                 :            : 
    2894                 :          0 : free_action:
    2895                 :            :         simple_free(action);
    2896                 :          0 :         return NULL;
    2897                 :            : }
    2898                 :            : 
    2899                 :            : static void *
    2900                 :          0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
    2901                 :            : {
    2902                 :            :         struct mlx5dr_action_mh_pattern pattern;
    2903                 :          0 :         rte_be64_t cmd[3] = {0};
    2904                 :            :         uint16_t mod_id;
    2905                 :            : 
    2906                 :          0 :         mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
    2907         [ #  # ]:          0 :         if (!mod_id) {
    2908                 :          0 :                 rte_errno = EINVAL;
    2909                 :          0 :                 return NULL;
    2910                 :            :         }
    2911                 :            : 
    2912                 :            :         /*
    2913                 :            :          * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
    2914                 :            :          * Next_hdr will be copied to ipv6.protocol after pop done.
    2915                 :            :          */
    2916         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[0], action_type, MLX5_MODIFICATION_TYPE_COPY);
    2917         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[0], length, 8);
    2918         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[0], src_offset, 24);
    2919         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[0], src_field, mod_id);
    2920         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[0], dst_field, mod_id);
    2921                 :            : 
    2922                 :            :         /* Add nop between the continuous same modify field id */
    2923         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[1], action_type, MLX5_MODIFICATION_TYPE_NOP);
    2924                 :            : 
    2925                 :            :         /* Clear next_hdr for right checksum */
    2926         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[2], action_type, MLX5_MODIFICATION_TYPE_SET);
    2927         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[2], length, 8);
    2928         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[2], offset, 24);
    2929         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[2], field, mod_id);
    2930                 :            : 
    2931                 :          0 :         pattern.data = cmd;
    2932                 :          0 :         pattern.sz = sizeof(cmd);
    2933                 :            : 
    2934                 :          0 :         return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
    2935                 :          0 :                                                           action->flags,
    2936                 :            :                                                           MLX5DR_ACTION_STC_REPARSE_ON);
    2937                 :            : }
    2938                 :            : 
    2939                 :            : static void *
    2940                 :          0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(struct mlx5dr_action *action)
    2941                 :            : {
    2942                 :          0 :         enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
    2943                 :            :                 MLX5_MODI_OUT_DIPV6_127_96,
    2944                 :            :                 MLX5_MODI_OUT_DIPV6_95_64,
    2945                 :            :                 MLX5_MODI_OUT_DIPV6_63_32,
    2946                 :            :                 MLX5_MODI_OUT_DIPV6_31_0
    2947                 :            :         };
    2948                 :            :         struct mlx5dr_action_mh_pattern pattern;
    2949                 :          0 :         rte_be64_t cmd[5] = {0};
    2950                 :            :         uint16_t mod_id;
    2951                 :            :         uint32_t i;
    2952                 :            : 
    2953                 :            :         /* Copy ipv6_route_ext[first_segment].dst_addr by flex parser to ipv6.dst_addr */
    2954         [ #  # ]:          0 :         for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
    2955                 :          0 :                 mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, i + 1);
    2956         [ #  # ]:          0 :                 if (!mod_id) {
    2957                 :          0 :                         rte_errno = EINVAL;
    2958                 :          0 :                         return NULL;
    2959                 :            :                 }
    2960                 :            : 
    2961         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_COPY);
    2962         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, &cmd[i], dst_field, field[i]);
    2963         [ #  # ]:          0 :                 MLX5_SET(copy_action_in, &cmd[i], src_field, mod_id);
    2964                 :            :         }
    2965                 :            : 
    2966                 :          0 :         mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
    2967         [ #  # ]:          0 :         if (!mod_id) {
    2968                 :          0 :                 rte_errno = EINVAL;
    2969                 :          0 :                 return NULL;
    2970                 :            :         }
    2971                 :            : 
    2972                 :            :         /* Restore next_hdr from seg_left for flex parser identifying */
    2973         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_COPY);
    2974         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[4], length, 8);
    2975         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[4], dst_offset, 24);
    2976         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[4], src_field, mod_id);
    2977         [ #  # ]:          0 :         MLX5_SET(copy_action_in, &cmd[4], dst_field, mod_id);
    2978                 :            : 
    2979                 :          0 :         pattern.data = cmd;
    2980                 :          0 :         pattern.sz = sizeof(cmd);
    2981                 :            : 
    2982                 :          0 :         return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
    2983                 :          0 :                                                           action->flags,
    2984                 :            :                                                           MLX5DR_ACTION_STC_REPARSE_ON);
    2985                 :            : }
    2986                 :            : 
    2987                 :            : static void *
    2988                 :          0 : mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(struct mlx5dr_action *action)
    2989                 :            : {
    2990                 :          0 :         uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
    2991                 :            :         struct mlx5dr_action_mh_pattern pattern;
    2992                 :            :         uint16_t mod_id;
    2993                 :            : 
    2994                 :          0 :         mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
    2995         [ #  # ]:          0 :         if (!mod_id) {
    2996                 :          0 :                 rte_errno = EINVAL;
    2997                 :          0 :                 return NULL;
    2998                 :            :         }
    2999                 :            : 
    3000                 :            :         /* Copy ipv6_route_ext.next_hdr to ipv6.protocol */
    3001         [ #  # ]:          0 :         MLX5_SET(copy_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_COPY);
    3002         [ #  # ]:          0 :         MLX5_SET(copy_action_in, cmd, length, 8);
    3003         [ #  # ]:          0 :         MLX5_SET(copy_action_in, cmd, src_offset, 24);
    3004         [ #  # ]:          0 :         MLX5_SET(copy_action_in, cmd, src_field, mod_id);
    3005         [ #  # ]:          0 :         MLX5_SET(copy_action_in, cmd, dst_field, MLX5_MODI_OUT_IP_PROTOCOL);
    3006                 :            : 
    3007                 :          0 :         pattern.data = (rte_be64_t *)cmd;
    3008                 :          0 :         pattern.sz = sizeof(cmd);
    3009                 :            : 
    3010                 :          0 :         return mlx5dr_action_create_modify_header_reparse(action->ctx, 1, &pattern, 0,
    3011                 :          0 :                                                           action->flags,
    3012                 :            :                                                           MLX5DR_ACTION_STC_REPARSE_OFF);
    3013                 :            : }
    3014                 :            : 
    3015                 :            : static int
    3016                 :          0 : mlx5dr_action_create_pop_ipv6_route_ext(struct mlx5dr_action *action)
    3017                 :            : {
    3018                 :          0 :         uint8_t anchor_id = flow_hw_get_ipv6_route_ext_anchor_from_ctx(action->ctx);
    3019                 :            :         struct mlx5dr_action_remove_header_attr hdr_attr;
    3020                 :            :         uint32_t i;
    3021                 :            : 
    3022         [ #  # ]:          0 :         if (!anchor_id) {
    3023                 :          0 :                 rte_errno = EINVAL;
    3024                 :          0 :                 return rte_errno;
    3025                 :            :         }
    3026                 :            : 
    3027                 :          0 :         action->ipv6_route_ext.action[0] =
    3028                 :          0 :                 mlx5dr_action_create_pop_ipv6_route_ext_mhdr1(action);
    3029                 :          0 :         action->ipv6_route_ext.action[1] =
    3030                 :          0 :                 mlx5dr_action_create_pop_ipv6_route_ext_mhdr2(action);
    3031                 :          0 :         action->ipv6_route_ext.action[2] =
    3032                 :          0 :                 mlx5dr_action_create_pop_ipv6_route_ext_mhdr3(action);
    3033                 :            : 
    3034                 :          0 :         hdr_attr.by_anchor.decap = 1;
    3035                 :          0 :         hdr_attr.by_anchor.start_anchor = anchor_id;
    3036                 :          0 :         hdr_attr.by_anchor.end_anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
    3037                 :          0 :         hdr_attr.type = MLX5DR_ACTION_REMOVE_HEADER_TYPE_BY_HEADER;
    3038                 :          0 :         action->ipv6_route_ext.action[3] =
    3039                 :          0 :                 mlx5dr_action_create_remove_header(action->ctx, &hdr_attr, action->flags);
    3040                 :            : 
    3041   [ #  #  #  # ]:          0 :         if (!action->ipv6_route_ext.action[0] || !action->ipv6_route_ext.action[1] ||
    3042   [ #  #  #  # ]:          0 :             !action->ipv6_route_ext.action[2] || !action->ipv6_route_ext.action[3]) {
    3043                 :          0 :                 DR_LOG(ERR, "Failed to create ipv6_route_ext pop subaction");
    3044                 :          0 :                 goto err;
    3045                 :            :         }
    3046                 :            : 
    3047                 :            :         return 0;
    3048                 :            : 
    3049                 :            : err:
    3050         [ #  # ]:          0 :         for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
    3051         [ #  # ]:          0 :                 if (action->ipv6_route_ext.action[i])
    3052                 :          0 :                         mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
    3053                 :            : 
    3054                 :          0 :         return rte_errno;
    3055                 :            : }
    3056                 :            : 
    3057                 :            : static void *
    3058                 :          0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr1(struct mlx5dr_action *action)
    3059                 :            : {
    3060                 :            :         uint8_t cmd[MLX5DR_MODIFY_ACTION_SIZE] = {0};
    3061                 :            :         struct mlx5dr_action_mh_pattern pattern;
    3062                 :            : 
    3063                 :            :         /* Set ipv6.protocol to IPPROTO_ROUTING */
    3064                 :            :         MLX5_SET(set_action_in, cmd, action_type, MLX5_MODIFICATION_TYPE_SET);
    3065         [ #  # ]:          0 :         MLX5_SET(set_action_in, cmd, length, 8);
    3066         [ #  # ]:          0 :         MLX5_SET(set_action_in, cmd, field, MLX5_MODI_OUT_IP_PROTOCOL);
    3067                 :          0 :         MLX5_SET(set_action_in, cmd, data, IPPROTO_ROUTING);
    3068                 :            : 
    3069                 :          0 :         pattern.data = (rte_be64_t *)cmd;
    3070                 :          0 :         pattern.sz = sizeof(cmd);
    3071                 :            : 
    3072                 :          0 :         return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern, 0,
    3073                 :          0 :                                                   action->flags | MLX5DR_ACTION_FLAG_SHARED);
    3074                 :            : }
    3075                 :            : 
    3076                 :            : static void *
    3077                 :          0 : mlx5dr_action_create_push_ipv6_route_ext_mhdr2(struct mlx5dr_action *action,
    3078                 :            :                                                uint32_t bulk_size,
    3079                 :            :                                                uint8_t *data)
    3080                 :            : {
    3081                 :          0 :         enum mlx5_modification_field field[MLX5_ST_SZ_DW(definer_hl_ipv6_addr)] = {
    3082                 :            :                 MLX5_MODI_OUT_DIPV6_127_96,
    3083                 :            :                 MLX5_MODI_OUT_DIPV6_95_64,
    3084                 :            :                 MLX5_MODI_OUT_DIPV6_63_32,
    3085                 :            :                 MLX5_MODI_OUT_DIPV6_31_0
    3086                 :            :         };
    3087                 :            :         struct mlx5dr_action_mh_pattern pattern;
    3088                 :            :         uint32_t *ipv6_dst_addr = NULL;
    3089                 :            :         uint8_t seg_left, next_hdr;
    3090                 :          0 :         rte_be64_t cmd[5] = {0};
    3091                 :            :         uint16_t mod_id;
    3092                 :            :         uint32_t i;
    3093                 :            : 
    3094                 :            :         /* Fetch the last IPv6 address in the segment list */
    3095         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
    3096         [ #  # ]:          0 :                 seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
    3097                 :          0 :                 ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext) +
    3098                 :            :                                 seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
    3099                 :            :         }
    3100                 :            : 
    3101                 :            :         /* Copy IPv6 destination address from ipv6_route_ext.last_segment */
    3102         [ #  # ]:          0 :         for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
    3103         [ #  # ]:          0 :                 MLX5_SET(set_action_in, &cmd[i], action_type, MLX5_MODIFICATION_TYPE_SET);
    3104         [ #  # ]:          0 :                 MLX5_SET(set_action_in, &cmd[i], field, field[i]);
    3105         [ #  # ]:          0 :                 if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
    3106         [ #  # ]:          0 :                         MLX5_SET(set_action_in, &cmd[i], data, be32toh(*ipv6_dst_addr++));
    3107                 :            :         }
    3108                 :            : 
    3109                 :          0 :         mod_id = flow_hw_get_ipv6_route_ext_mod_id_from_ctx(action->ctx, 0);
    3110         [ #  # ]:          0 :         if (!mod_id) {
    3111                 :          0 :                 rte_errno = EINVAL;
    3112                 :          0 :                 return NULL;
    3113                 :            :         }
    3114                 :            : 
    3115                 :            :         /* Set ipv6_route_ext.next_hdr since initially pushed as 0 for right checksum */
    3116         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[4], action_type, MLX5_MODIFICATION_TYPE_SET);
    3117         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[4], length, 8);
    3118         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[4], offset, 24);
    3119         [ #  # ]:          0 :         MLX5_SET(set_action_in, &cmd[4], field, mod_id);
    3120         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
    3121         [ #  # ]:          0 :                 next_hdr = MLX5_GET(header_ipv6_routing_ext, data, next_hdr);
    3122         [ #  # ]:          0 :                 MLX5_SET(set_action_in, &cmd[4], data, next_hdr);
    3123                 :            :         }
    3124                 :            : 
    3125                 :          0 :         pattern.data = cmd;
    3126                 :          0 :         pattern.sz = sizeof(cmd);
    3127                 :            : 
    3128                 :          0 :         return mlx5dr_action_create_modify_header(action->ctx, 1, &pattern,
    3129                 :            :                                                   bulk_size, action->flags);
    3130                 :            : }
    3131                 :            : 
    3132                 :            : static int
    3133                 :          0 : mlx5dr_action_create_push_ipv6_route_ext(struct mlx5dr_action *action,
    3134                 :            :                                          struct mlx5dr_action_reformat_header *hdr,
    3135                 :            :                                          uint32_t bulk_size)
    3136                 :            : {
    3137                 :          0 :         struct mlx5dr_action_insert_header insert_hdr = { {0} };
    3138                 :            :         uint8_t header[MLX5_PUSH_MAX_LEN];
    3139                 :            :         uint32_t i;
    3140                 :            : 
    3141   [ #  #  #  #  :          0 :         if (!hdr || !hdr->sz || hdr->sz > MLX5_PUSH_MAX_LEN ||
                   #  # ]
    3142   [ #  #  #  # ]:          0 :             ((action->flags & MLX5DR_ACTION_FLAG_SHARED) && !hdr->data)) {
    3143                 :          0 :                 DR_LOG(ERR, "Invalid ipv6_route_ext header");
    3144                 :          0 :                 rte_errno = EINVAL;
    3145                 :          0 :                 return rte_errno;
    3146                 :            :         }
    3147                 :            : 
    3148         [ #  # ]:          0 :         if (action->flags & MLX5DR_ACTION_FLAG_SHARED) {
    3149         [ #  # ]:          0 :                 memcpy(header, hdr->data, hdr->sz);
    3150                 :            :                 /* Clear ipv6_route_ext.next_hdr for right checksum */
    3151         [ #  # ]:          0 :                 MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
    3152                 :            :         }
    3153                 :            : 
    3154                 :          0 :         insert_hdr.anchor = MLX5_HEADER_ANCHOR_TCP_UDP;
    3155                 :          0 :         insert_hdr.encap = 1;
    3156                 :          0 :         insert_hdr.hdr.sz = hdr->sz;
    3157                 :          0 :         insert_hdr.hdr.data = header;
    3158                 :          0 :         action->ipv6_route_ext.action[0] =
    3159                 :          0 :                 mlx5dr_action_create_insert_header_reparse(action->ctx, 1, &insert_hdr,
    3160                 :            :                                                             bulk_size, action->flags,
    3161                 :            :                                                             MLX5DR_ACTION_STC_REPARSE_OFF);
    3162                 :          0 :         action->ipv6_route_ext.action[1] =
    3163                 :          0 :                 mlx5dr_action_create_push_ipv6_route_ext_mhdr1(action);
    3164                 :          0 :         action->ipv6_route_ext.action[2] =
    3165                 :          0 :                 mlx5dr_action_create_push_ipv6_route_ext_mhdr2(action, bulk_size, hdr->data);
    3166                 :            : 
    3167         [ #  # ]:          0 :         if (!action->ipv6_route_ext.action[0] ||
    3168   [ #  #  #  # ]:          0 :             !action->ipv6_route_ext.action[1] ||
    3169                 :            :             !action->ipv6_route_ext.action[2]) {
    3170                 :          0 :                 DR_LOG(ERR, "Failed to create ipv6_route_ext push subaction");
    3171                 :          0 :                 goto err;
    3172                 :            :         }
    3173                 :            : 
    3174                 :            :         return 0;
    3175                 :            : 
    3176                 :            : err:
    3177         [ #  # ]:          0 :         for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
    3178         [ #  # ]:          0 :                 if (action->ipv6_route_ext.action[i])
    3179                 :          0 :                         mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
    3180                 :            : 
    3181                 :          0 :         return rte_errno;
    3182                 :            : }
    3183                 :            : 
    3184                 :            : struct mlx5dr_action *
    3185                 :          0 : mlx5dr_action_create_reformat_ipv6_ext(struct mlx5dr_context *ctx,
    3186                 :            :                                        enum mlx5dr_action_type action_type,
    3187                 :            :                                        struct mlx5dr_action_reformat_header *hdr,
    3188                 :            :                                        uint32_t log_bulk_size,
    3189                 :            :                                        uint32_t flags)
    3190                 :            : {
    3191                 :            :         struct mlx5dr_action *action;
    3192                 :            :         int ret;
    3193                 :            : 
    3194         [ #  # ]:          0 :         if (!mlx5dr_action_is_hws_flags(flags) ||
    3195   [ #  #  #  # ]:          0 :             ((flags & MLX5DR_ACTION_FLAG_SHARED) && log_bulk_size)) {
    3196                 :          0 :                 DR_LOG(ERR, "IPv6 extension flags don't fit HWS (flags: 0x%x)", flags);
    3197                 :          0 :                 rte_errno = EINVAL;
    3198                 :          0 :                 return NULL;
    3199                 :            :         }
    3200                 :            : 
    3201                 :            :         action = mlx5dr_action_create_generic(ctx, flags, action_type);
    3202         [ #  # ]:          0 :         if (!action) {
    3203                 :          0 :                 rte_errno = ENOMEM;
    3204                 :          0 :                 return NULL;
    3205                 :            :         }
    3206                 :            : 
    3207      [ #  #  # ]:          0 :         switch (action_type) {
    3208                 :          0 :         case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
    3209         [ #  # ]:          0 :                 if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
    3210                 :          0 :                         DR_LOG(ERR, "Pop ipv6_route_ext must be shared");
    3211                 :          0 :                         rte_errno = EINVAL;
    3212                 :          0 :                         goto free_action;
    3213                 :            :                 }
    3214                 :            : 
    3215                 :          0 :                 ret = mlx5dr_action_create_pop_ipv6_route_ext(action);
    3216                 :          0 :                 break;
    3217                 :          0 :         case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
    3218         [ #  # ]:          0 :                 if (!mlx5dr_context_cap_dynamic_reparse(ctx)) {
    3219                 :          0 :                         DR_LOG(ERR, "IPv6 routing extension push actions is not supported");
    3220                 :          0 :                         rte_errno = ENOTSUP;
    3221                 :          0 :                         goto free_action;
    3222                 :            :                 }
    3223                 :            : 
    3224                 :          0 :                 ret = mlx5dr_action_create_push_ipv6_route_ext(action, hdr, log_bulk_size);
    3225                 :          0 :                 break;
    3226                 :          0 :         default:
    3227                 :          0 :                 DR_LOG(ERR, "Unsupported action type %d\n", action_type);
    3228                 :          0 :                 rte_errno = ENOTSUP;
    3229                 :          0 :                 goto free_action;
    3230                 :            :         }
    3231                 :            : 
    3232         [ #  # ]:          0 :         if (ret) {
    3233                 :          0 :                 DR_LOG(ERR, "Failed to create IPv6 extension reformat action");
    3234                 :          0 :                 goto free_action;
    3235                 :            :         }
    3236                 :            : 
    3237                 :            :         return action;
    3238                 :            : 
    3239                 :          0 : free_action:
    3240                 :            :         simple_free(action);
    3241                 :          0 :         return NULL;
    3242                 :            : }
    3243                 :            : 
    3244                 :            : static bool
    3245                 :          0 : mlx5dr_action_nat64_validate_param(struct mlx5dr_action_nat64_attr *attr,
    3246                 :            :                                    uint32_t flags)
    3247                 :            : {
    3248         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    3249                 :          0 :                 DR_LOG(ERR, "Nat64 action not supported for root");
    3250                 :          0 :                 rte_errno = ENOTSUP;
    3251                 :          0 :                 return false;
    3252                 :            :         }
    3253                 :            : 
    3254         [ #  # ]:          0 :         if (!(flags & MLX5DR_ACTION_FLAG_SHARED)) {
    3255                 :          0 :                 DR_LOG(ERR, "Nat64 action must be with SHARED flag");
    3256                 :          0 :                 rte_errno = EINVAL;
    3257                 :          0 :                 return false;
    3258                 :            :         }
    3259                 :            : 
    3260         [ #  # ]:          0 :         if (attr->num_of_registers > MLX5DR_ACTION_NAT64_REG_MAX) {
    3261                 :          0 :                 DR_LOG(ERR, "Nat64 action doesn't support more than %d registers",
    3262                 :            :                        MLX5DR_ACTION_NAT64_REG_MAX);
    3263                 :          0 :                 rte_errno = EINVAL;
    3264                 :          0 :                 return false;
    3265                 :            :         }
    3266                 :            : 
    3267   [ #  #  #  # ]:          0 :         if (attr->flags & MLX5DR_ACTION_NAT64_BACKUP_ADDR &&
    3268                 :            :             attr->num_of_registers != MLX5DR_ACTION_NAT64_REG_MAX) {
    3269                 :          0 :                 DR_LOG(ERR, "Nat64 backup addr requires %d registers",
    3270                 :            :                        MLX5DR_ACTION_NAT64_REG_MAX);
    3271                 :          0 :                 rte_errno = EINVAL;
    3272                 :          0 :                 return false;
    3273                 :            :         }
    3274                 :            : 
    3275         [ #  # ]:          0 :         if (!(attr->flags & MLX5DR_ACTION_NAT64_V4_TO_V6 ||
    3276                 :            :               attr->flags & MLX5DR_ACTION_NAT64_V6_TO_V4)) {
    3277                 :          0 :                 DR_LOG(ERR, "Nat64 backup addr requires one mode at least");
    3278                 :          0 :                 rte_errno = EINVAL;
    3279                 :          0 :                 return false;
    3280                 :            :         }
    3281                 :            : 
    3282                 :            :         return true;
    3283                 :            : }
    3284                 :            : 
    3285                 :            : struct mlx5dr_action *
    3286                 :          0 : mlx5dr_action_create_nat64(struct mlx5dr_context *ctx,
    3287                 :            :                            struct mlx5dr_action_nat64_attr *attr,
    3288                 :            :                            uint32_t flags)
    3289                 :            : {
    3290                 :            :         struct mlx5dr_action *action;
    3291                 :            : 
    3292         [ #  # ]:          0 :         if (!mlx5dr_action_nat64_validate_param(attr, flags))
    3293                 :            :                 return NULL;
    3294                 :            : 
    3295                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_NAT64);
    3296         [ #  # ]:          0 :         if (!action)
    3297                 :            :                 return NULL;
    3298                 :            : 
    3299                 :          0 :         action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY] =
    3300                 :          0 :                 mlx5dr_action_create_nat64_copy_state(ctx, attr, flags);
    3301         [ #  # ]:          0 :         if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY]) {
    3302                 :          0 :                 DR_LOG(ERR, "Nat64 failed creating copy state");
    3303                 :          0 :                 goto free_action;
    3304                 :            :         }
    3305                 :            : 
    3306                 :          0 :         action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE] =
    3307                 :          0 :                 mlx5dr_action_create_nat64_repalce_state(ctx, attr, flags);
    3308         [ #  # ]:          0 :         if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE]) {
    3309                 :          0 :                 DR_LOG(ERR, "Nat64 failed creating replace state");
    3310                 :          0 :                 goto free_copy;
    3311                 :            :         }
    3312                 :          0 :         action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL] =
    3313                 :          0 :                 mlx5dr_action_create_nat64_copy_proto_state(ctx, attr, flags);
    3314         [ #  # ]:          0 :         if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL]) {
    3315                 :          0 :                 DR_LOG(ERR, "Nat64 failed creating copy protocol state");
    3316                 :          0 :                 goto free_replace;
    3317                 :            :         }
    3318                 :            : 
    3319                 :          0 :         action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPYBACK] =
    3320                 :          0 :                 mlx5dr_action_create_nat64_copy_back_state(ctx, attr, flags);
    3321         [ #  # ]:          0 :         if (!action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPYBACK]) {
    3322                 :          0 :                 DR_LOG(ERR, "Nat64 failed creating copyback state");
    3323                 :          0 :                 goto free_copy_proto;
    3324                 :            :         }
    3325                 :            : 
    3326                 :            :         return action;
    3327                 :            : 
    3328                 :            : free_copy_proto:
    3329                 :          0 :         mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY_PROTOCOL]);
    3330                 :          0 : free_replace:
    3331                 :          0 :         mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_REPLACE]);
    3332                 :          0 : free_copy:
    3333                 :          0 :         mlx5dr_action_destroy(action->nat64.stages[MLX5DR_ACTION_NAT64_STAGE_COPY]);
    3334                 :          0 : free_action:
    3335                 :            :         simple_free(action);
    3336                 :          0 :         return NULL;
    3337                 :            : }
    3338                 :            : 
    3339                 :            : struct mlx5dr_action *
    3340                 :          0 : mlx5dr_action_create_jump_to_matcher(struct mlx5dr_context *ctx,
    3341                 :            :                                      struct mlx5dr_action_jump_to_matcher_attr *attr,
    3342                 :            :                                      uint32_t flags)
    3343                 :            : {
    3344                 :          0 :         struct mlx5dr_matcher *matcher = attr->matcher;
    3345                 :            :         struct mlx5dr_matcher_attr *m_attr;
    3346                 :            :         struct mlx5dr_action *action;
    3347                 :            : 
    3348         [ #  # ]:          0 :         if (attr->type != MLX5DR_ACTION_JUMP_TO_MATCHER_BY_INDEX) {
    3349                 :          0 :                 DR_LOG(ERR, "Only jump to matcher by index is supported");
    3350                 :          0 :                 goto enotsup;
    3351                 :            :         }
    3352                 :            : 
    3353         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(flags)) {
    3354                 :          0 :                 DR_LOG(ERR, "Action flags must be only non root (HWS)");
    3355                 :          0 :                 goto enotsup;
    3356                 :            :         }
    3357                 :            : 
    3358         [ #  # ]:          0 :         if (mlx5dr_table_is_root(matcher->tbl)) {
    3359                 :          0 :                 DR_LOG(ERR, "Root matcher cannot be set as destination");
    3360                 :          0 :                 goto enotsup;
    3361                 :            :         }
    3362                 :            : 
    3363                 :            :         m_attr = &matcher->attr;
    3364                 :            : 
    3365         [ #  # ]:          0 :         if (!(matcher->flags & MLX5DR_MATCHER_FLAGS_STE_ARRAY) &&
    3366         [ #  # ]:          0 :             (m_attr->resizable || m_attr->table.sz_col_log || m_attr->table.sz_row_log)) {
    3367                 :          0 :                 DR_LOG(ERR, "Only STE array or matcher of size 1 can be set as destination");
    3368                 :          0 :                 goto enotsup;
    3369                 :            :         }
    3370                 :            : 
    3371                 :            :         action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_JUMP_TO_MATCHER);
    3372         [ #  # ]:          0 :         if (!action)
    3373                 :            :                 return NULL;
    3374                 :            : 
    3375                 :          0 :         action->jump_to_matcher.matcher = matcher;
    3376                 :            : 
    3377         [ #  # ]:          0 :         if (mlx5dr_action_create_stcs(action, NULL)) {
    3378                 :          0 :                 DR_LOG(ERR, "Failed to create action jump to matcher STC");
    3379                 :            :                 simple_free(action);
    3380                 :          0 :                 return NULL;
    3381                 :            :         }
    3382                 :            : 
    3383                 :            :         return action;
    3384                 :            : 
    3385                 :          0 : enotsup:
    3386                 :          0 :         rte_errno = ENOTSUP;
    3387                 :          0 :         return NULL;
    3388                 :            : }
    3389                 :            : 
    3390                 :          0 : static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
    3391                 :            : {
    3392                 :            :         struct mlx5dr_devx_obj *obj = NULL;
    3393                 :            :         uint32_t i;
    3394                 :            : 
    3395   [ #  #  #  #  :          0 :         switch (action->type) {
          #  #  #  #  #  
                #  #  # ]
    3396                 :          0 :         case MLX5DR_ACTION_TYP_TIR:
    3397                 :          0 :                 mlx5dr_action_destroy_stcs(action);
    3398         [ #  # ]:          0 :                 if (mlx5dr_context_shared_gvmi_used(action->ctx))
    3399                 :          0 :                         mlx5dr_cmd_destroy_obj(action->alias.devx_obj);
    3400                 :            :                 break;
    3401                 :          0 :         case MLX5DR_ACTION_TYP_MISS:
    3402                 :            :         case MLX5DR_ACTION_TYP_TAG:
    3403                 :            :         case MLX5DR_ACTION_TYP_DROP:
    3404                 :            :         case MLX5DR_ACTION_TYP_CTR:
    3405                 :            :         case MLX5DR_ACTION_TYP_TBL:
    3406                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    3407                 :            :         case MLX5DR_ACTION_TYP_ASO_METER:
    3408                 :            :         case MLX5DR_ACTION_TYP_ASO_CT:
    3409                 :            :         case MLX5DR_ACTION_TYP_PUSH_VLAN:
    3410                 :            :         case MLX5DR_ACTION_TYP_REMOVE_HEADER:
    3411                 :            :         case MLX5DR_ACTION_TYP_VPORT:
    3412                 :            :         case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
    3413                 :          0 :                 mlx5dr_action_destroy_stcs(action);
    3414                 :          0 :                 break;
    3415                 :          0 :         case MLX5DR_ACTION_TYP_DEST_ROOT:
    3416                 :          0 :                 mlx5dr_action_destroy_stcs(action);
    3417                 :          0 :                 mlx5_glue->destroy_steering_anchor(action->root_tbl.sa);
    3418                 :          0 :                 break;
    3419                 :          0 :         case MLX5DR_ACTION_TYP_POP_VLAN:
    3420                 :          0 :                 mlx5dr_action_destroy_stcs(action);
    3421                 :          0 :                 mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP);
    3422                 :          0 :                 break;
    3423                 :          0 :         case MLX5DR_ACTION_TYP_DEST_ARRAY:
    3424                 :          0 :                 mlx5dr_action_destroy_stcs(action);
    3425                 :          0 :                 mlx5dr_cmd_forward_tbl_destroy(action->dest_array.fw_island);
    3426         [ #  # ]:          0 :                 for (i = 0; i < action->dest_array.num_dest; i++) {
    3427         [ #  # ]:          0 :                         if (action->dest_array.dest_list[i].ext_reformat)
    3428                 :          0 :                                 mlx5dr_cmd_destroy_obj
    3429                 :            :                                         (action->dest_array.dest_list[i].ext_reformat);
    3430                 :            :                 }
    3431                 :          0 :                 simple_free(action->dest_array.dest_list);
    3432                 :            :                 break;
    3433                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    3434                 :            :         case MLX5DR_ACTION_TYP_MODIFY_HDR:
    3435         [ #  # ]:          0 :                 for (i = 0; i < action->modify_header.num_of_patterns; i++) {
    3436                 :          0 :                         mlx5dr_action_destroy_stcs(&action[i]);
    3437         [ #  # ]:          0 :                         if (action[i].modify_header.num_of_actions > 1) {
    3438                 :          0 :                                 mlx5dr_pat_put_pattern(action[i].ctx,
    3439                 :            :                                                        action[i].modify_header.pat_obj);
    3440                 :            :                                 /* Save shared arg object if was used to free */
    3441         [ #  # ]:          0 :                                 if (action[i].modify_header.arg_obj)
    3442                 :            :                                         obj = action[i].modify_header.arg_obj;
    3443                 :            :                         }
    3444                 :            :                 }
    3445         [ #  # ]:          0 :                 if (obj)
    3446                 :          0 :                         mlx5dr_cmd_destroy_obj(obj);
    3447                 :            :                 break;
    3448                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    3449                 :          0 :                 mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_DECAP_L3);
    3450         [ #  # ]:          0 :                 for (i = 0; i < action->reformat.num_of_hdrs; i++)
    3451                 :          0 :                         mlx5dr_action_destroy_stcs(&action[i]);
    3452                 :          0 :                 mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
    3453                 :          0 :                 break;
    3454                 :            :         case MLX5DR_ACTION_TYP_INSERT_HEADER:
    3455                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    3456         [ #  # ]:          0 :                 for (i = 0; i < action->reformat.num_of_hdrs; i++)
    3457                 :          0 :                         mlx5dr_action_destroy_stcs(&action[i]);
    3458                 :          0 :                 mlx5dr_cmd_destroy_obj(action->reformat.arg_obj);
    3459                 :          0 :                 break;
    3460                 :            :         case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
    3461                 :            :         case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
    3462         [ #  # ]:          0 :                 for (i = 0; i < MLX5DR_ACTION_IPV6_EXT_MAX_SA; i++)
    3463         [ #  # ]:          0 :                         if (action->ipv6_route_ext.action[i])
    3464                 :          0 :                                 mlx5dr_action_destroy(action->ipv6_route_ext.action[i]);
    3465                 :            :                 break;
    3466                 :            :         case MLX5DR_ACTION_TYP_NAT64:
    3467         [ #  # ]:          0 :                 for (i = 0; i < MLX5DR_ACTION_NAT64_STAGES; i++)
    3468                 :          0 :                         mlx5dr_action_destroy(action->nat64.stages[i]);
    3469                 :            :                 break;
    3470                 :            :         case MLX5DR_ACTION_TYP_LAST:
    3471                 :            :                 break;
    3472                 :          0 :         default:
    3473                 :          0 :                 DR_LOG(ERR, "Not supported action type: %d", action->type);
    3474                 :          0 :                 assert(false);
    3475                 :            :         }
    3476                 :          0 : }
    3477                 :            : 
    3478                 :          0 : static void mlx5dr_action_destroy_root(struct mlx5dr_action *action)
    3479                 :            : {
    3480         [ #  # ]:          0 :         switch (action->type) {
    3481                 :          0 :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    3482                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    3483                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    3484                 :            :         case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    3485                 :            :         case MLX5DR_ACTION_TYP_MODIFY_HDR:
    3486         [ #  # ]:          0 :                 ibv_destroy_flow_action(action->flow_action);
    3487                 :            :                 break;
    3488                 :            :         }
    3489                 :          0 : }
    3490                 :            : 
    3491                 :          0 : int mlx5dr_action_destroy(struct mlx5dr_action *action)
    3492                 :            : {
    3493         [ #  # ]:          0 :         if (mlx5dr_action_is_root_flags(action->flags))
    3494                 :          0 :                 mlx5dr_action_destroy_root(action);
    3495                 :            :         else
    3496                 :          0 :                 mlx5dr_action_destroy_hws(action);
    3497                 :            : 
    3498                 :            :         simple_free(action);
    3499                 :          0 :         return 0;
    3500                 :            : }
    3501                 :            : 
    3502                 :            : /* Called under pthread_spin_lock(&ctx->ctrl_lock) */
    3503                 :          0 : int mlx5dr_action_get_default_stc(struct mlx5dr_context *ctx,
    3504                 :            :                                   uint8_t tbl_type)
    3505                 :            : {
    3506                 :          0 :         struct mlx5dr_cmd_stc_modify_attr stc_attr = {0};
    3507                 :            :         struct mlx5dr_action_default_stc *default_stc;
    3508                 :            :         int ret;
    3509                 :            : 
    3510         [ #  # ]:          0 :         if (ctx->common_res[tbl_type].default_stc) {
    3511                 :          0 :                 ctx->common_res[tbl_type].default_stc->refcount++;
    3512                 :          0 :                 return 0;
    3513                 :            :         }
    3514                 :            : 
    3515                 :            :         default_stc = simple_calloc(1, sizeof(*default_stc));
    3516         [ #  # ]:          0 :         if (!default_stc) {
    3517                 :          0 :                 DR_LOG(ERR, "Failed to allocate memory for default STCs");
    3518                 :          0 :                 rte_errno = ENOMEM;
    3519                 :          0 :                 return rte_errno;
    3520                 :            :         }
    3521                 :            : 
    3522                 :          0 :         stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_NOP;
    3523                 :          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW0;
    3524                 :          0 :         stc_attr.reparse_mode = MLX5_IFC_STC_REPARSE_IGNORE;
    3525                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
    3526                 :            :                                              &default_stc->nop_ctr);
    3527         [ #  # ]:          0 :         if (ret) {
    3528                 :          0 :                 DR_LOG(ERR, "Failed to allocate default counter STC");
    3529                 :          0 :                 goto free_default_stc;
    3530                 :            :         }
    3531                 :            : 
    3532                 :          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW5;
    3533                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
    3534                 :            :                                              &default_stc->nop_dw5);
    3535         [ #  # ]:          0 :         if (ret) {
    3536                 :          0 :                 DR_LOG(ERR, "Failed to allocate default NOP DW5 STC");
    3537                 :          0 :                 goto free_nop_ctr;
    3538                 :            :         }
    3539                 :            : 
    3540                 :          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW6;
    3541                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
    3542                 :            :                                              &default_stc->nop_dw6);
    3543         [ #  # ]:          0 :         if (ret) {
    3544                 :          0 :                 DR_LOG(ERR, "Failed to allocate default NOP DW6 STC");
    3545                 :          0 :                 goto free_nop_dw5;
    3546                 :            :         }
    3547                 :            : 
    3548                 :          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_DW7;
    3549                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
    3550                 :            :                                              &default_stc->nop_dw7);
    3551         [ #  # ]:          0 :         if (ret) {
    3552                 :          0 :                 DR_LOG(ERR, "Failed to allocate default NOP DW7 STC");
    3553                 :          0 :                 goto free_nop_dw6;
    3554                 :            :         }
    3555                 :            : 
    3556         [ #  # ]:          0 :         stc_attr.action_offset = MLX5DR_ACTION_OFFSET_HIT;
    3557         [ #  # ]:          0 :         if (!mlx5dr_context_shared_gvmi_used(ctx)) {
    3558                 :          0 :                 stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_ALLOW;
    3559                 :            :         } else {
    3560                 :            :                 /* On shared gvmi the default hit behavior is jump to alias end ft */
    3561                 :          0 :                 stc_attr.action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
    3562                 :          0 :                 stc_attr.dest_table_id = ctx->gvmi_res[tbl_type].aliased_end_ft->id;
    3563                 :            :         }
    3564                 :            : 
    3565                 :          0 :         ret = mlx5dr_action_alloc_single_stc(ctx, &stc_attr, tbl_type,
    3566                 :            :                                              &default_stc->default_hit);
    3567         [ #  # ]:          0 :         if (ret) {
    3568                 :          0 :                 DR_LOG(ERR, "Failed to allocate default allow STC");
    3569                 :          0 :                 goto free_nop_dw7;
    3570                 :            :         }
    3571                 :            : 
    3572                 :          0 :         ctx->common_res[tbl_type].default_stc = default_stc;
    3573                 :          0 :         ctx->common_res[tbl_type].default_stc->refcount++;
    3574                 :            : 
    3575                 :          0 :         return 0;
    3576                 :            : 
    3577                 :            : free_nop_dw7:
    3578                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
    3579                 :          0 : free_nop_dw6:
    3580                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
    3581                 :          0 : free_nop_dw5:
    3582                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
    3583                 :          0 : free_nop_ctr:
    3584                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
    3585                 :          0 : free_default_stc:
    3586                 :            :         simple_free(default_stc);
    3587                 :          0 :         return rte_errno;
    3588                 :            : }
    3589                 :            : 
    3590                 :          0 : void mlx5dr_action_put_default_stc(struct mlx5dr_context *ctx,
    3591                 :            :                                    uint8_t tbl_type)
    3592                 :            : {
    3593                 :            :         struct mlx5dr_action_default_stc *default_stc;
    3594                 :            : 
    3595                 :          0 :         default_stc = ctx->common_res[tbl_type].default_stc;
    3596                 :            : 
    3597                 :            :         default_stc = ctx->common_res[tbl_type].default_stc;
    3598         [ #  # ]:          0 :         if (--default_stc->refcount)
    3599                 :            :                 return;
    3600                 :            : 
    3601                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->default_hit);
    3602                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw7);
    3603                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw6);
    3604                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
    3605                 :          0 :         mlx5dr_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
    3606                 :            :         simple_free(default_stc);
    3607                 :          0 :         ctx->common_res[tbl_type].default_stc = NULL;
    3608                 :            : }
    3609                 :            : 
    3610                 :            : static void mlx5dr_action_modify_write(struct mlx5dr_send_engine *queue,
    3611                 :            :                                        uint32_t arg_idx,
    3612                 :            :                                        uint8_t *arg_data,
    3613                 :            :                                        uint16_t num_of_actions)
    3614                 :            : {
    3615                 :          0 :         mlx5dr_arg_write(queue, NULL, arg_idx, arg_data,
    3616                 :          0 :                          num_of_actions * MLX5DR_MODIFY_ACTION_SIZE);
    3617                 :          0 : }
    3618                 :            : 
    3619                 :            : void
    3620                 :          0 : mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,
    3621                 :            :                                     uint16_t num_of_actions)
    3622                 :            : {
    3623                 :            :         uint8_t *e_src;
    3624                 :            :         int i;
    3625                 :            : 
    3626                 :            :         /*
    3627                 :            :          * When LTO inlines this into mlx5dr_action_handle_tunnel_l3_to_l2(),
    3628                 :            :          * GCC sees the 64-byte mh_data buffer but cannot prove num_of_actions
    3629                 :            :          * is bounded, causing false -Wstringop-overflow warnings.
    3630                 :            :          *
    3631                 :            :          * Valid num_of_actions values are DECAP_L3_NUM_ACTIONS_W_NO_VLAN (6)
    3632                 :            :          * or DECAP_L3_NUM_ACTIONS_W_VLAN (7). This check gives GCC the proof
    3633                 :            :          * it needs that the loop iterations stay within buffer bounds.
    3634                 :            :          */
    3635         [ #  # ]:          0 :         __rte_assume(num_of_actions <= DECAP_L3_NUM_ACTIONS_W_VLAN);
    3636                 :            : 
    3637                 :            :         /* num_of_actions = remove l3l2 + 4/5 inserts + remove extra 2 bytes
    3638                 :            :          * copy from end of src to the start of dst.
    3639                 :            :          * move to the end, 2 is the leftover from 14B or 18B
    3640                 :            :          */
    3641         [ #  # ]:          0 :         if (num_of_actions == DECAP_L3_NUM_ACTIONS_W_NO_VLAN)
    3642                 :          0 :                 e_src = src + MLX5DR_ACTION_HDR_LEN_L2;
    3643                 :            :         else
    3644                 :          0 :                 e_src = src + MLX5DR_ACTION_HDR_LEN_L2_W_VLAN;
    3645                 :            : 
    3646                 :            :         /* Move dst over the first remove action + zero data */
    3647                 :            :         dst += MLX5DR_ACTION_DOUBLE_SIZE;
    3648                 :            :         /* Move dst over the first insert ctrl action */
    3649                 :          0 :         dst += MLX5DR_ACTION_DOUBLE_SIZE / 2;
    3650                 :            :         /* Actions:
    3651                 :            :          * no vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
    3652                 :            :          * with vlan: r_h-insert_4b-insert_4b-insert_4b-insert_4b-insert_4b-remove_2b.
    3653                 :            :          * the loop is without the last insertion.
    3654                 :            :          */
    3655         [ #  # ]:          0 :         for (i = 0; i < num_of_actions - 3; i++) {
    3656                 :          0 :                 e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE;
    3657                 :            :                 memcpy(dst, e_src, MLX5DR_ACTION_INLINE_DATA_SIZE); /* data */
    3658                 :          0 :                 dst += MLX5DR_ACTION_DOUBLE_SIZE;
    3659                 :            :         }
    3660                 :            :         /* Copy the last 2 bytes after a gap of 2 bytes which will be removed */
    3661                 :          0 :         e_src -= MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
    3662                 :          0 :         dst += MLX5DR_ACTION_INLINE_DATA_SIZE / 2;
    3663                 :            :         memcpy(dst, e_src, 2);
    3664                 :          0 : }
    3665                 :            : 
    3666                 :            : static int mlx5dr_action_get_shared_stc_offset(struct mlx5dr_context_common_res *common_res,
    3667                 :            :                                                enum mlx5dr_context_shared_stc_type stc_type)
    3668                 :            : {
    3669                 :          0 :         return common_res->shared_stc[stc_type]->remove_header.offset;
    3670                 :            : }
    3671                 :            : 
    3672                 :            : static struct mlx5dr_actions_wqe_setter *
    3673                 :            : mlx5dr_action_setter_find_first(struct mlx5dr_actions_wqe_setter *setter,
    3674                 :            :                                 uint8_t req_flags)
    3675                 :            : {
    3676                 :            :         /* Use a new setter if requested flags are taken */
    3677   [ #  #  #  #  :          0 :         while (setter->flags & req_flags)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    3678                 :          0 :                 setter++;
    3679                 :            : 
    3680                 :            :         /* Use current setter in required flags are not used */
    3681                 :            :         return setter;
    3682                 :            : }
    3683                 :            : 
    3684                 :            : static void
    3685                 :            : mlx5dr_action_apply_stc(struct mlx5dr_actions_apply_data *apply,
    3686                 :            :                         enum mlx5dr_action_stc_idx stc_idx,
    3687                 :            :                         uint8_t action_idx)
    3688                 :            : {
    3689                 :          0 :         struct mlx5dr_action *action = apply->rule_action[action_idx].action;
    3690                 :            : 
    3691                 :          0 :         apply->wqe_ctrl->stc_ix[stc_idx] =
    3692                 :          0 :                 htobe32(action->stc[apply->tbl_type].offset);
    3693                 :            : }
    3694                 :            : 
    3695                 :            : static void
    3696                 :          0 : mlx5dr_action_setter_push_vlan(struct mlx5dr_actions_apply_data *apply,
    3697                 :            :                                struct mlx5dr_actions_wqe_setter *setter)
    3698                 :            : {
    3699                 :            :         struct mlx5dr_rule_action *rule_action;
    3700                 :            : 
    3701                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3702                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
    3703                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = rule_action->push_vlan.vlan_hdr;
    3704                 :            : 
    3705                 :            :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
    3706                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3707                 :          0 : }
    3708                 :            : 
    3709                 :            : static void
    3710                 :          0 : mlx5dr_action_setter_modify_header(struct mlx5dr_actions_apply_data *apply,
    3711                 :            :                                    struct mlx5dr_actions_wqe_setter *setter)
    3712                 :            : {
    3713                 :            :         struct mlx5dr_rule_action *rule_action;
    3714                 :            :         uint32_t stc_idx, arg_sz, arg_idx;
    3715                 :            :         struct mlx5dr_action *action;
    3716                 :            :         uint8_t *single_action;
    3717                 :            : 
    3718                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3719                 :          0 :         action = rule_action->action + rule_action->modify_header.pattern_idx;
    3720                 :            : 
    3721         [ #  # ]:          0 :         stc_idx = htobe32(action->stc[apply->tbl_type].offset);
    3722                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
    3723                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3724                 :            : 
    3725                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
    3726                 :            : 
    3727         [ #  # ]:          0 :         if (action->modify_header.num_of_actions == 1) {
    3728                 :          0 :                 if (action->modify_header.single_action_type ==
    3729         [ #  # ]:          0 :                     MLX5_MODIFICATION_TYPE_COPY ||
    3730                 :            :                     action->modify_header.single_action_type ==
    3731                 :            :                     MLX5_MODIFICATION_TYPE_ADD_FIELD) {
    3732                 :          0 :                         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
    3733                 :          0 :                         return;
    3734                 :            :                 }
    3735                 :            : 
    3736         [ #  # ]:          0 :                 if (action->flags & MLX5DR_ACTION_FLAG_SHARED)
    3737                 :          0 :                         single_action = (uint8_t *)&action->modify_header.single_action;
    3738                 :            :                 else
    3739                 :          0 :                         single_action = rule_action->modify_header.data;
    3740                 :            : 
    3741                 :          0 :                 apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] =
    3742                 :            :                         *(__be32 *)MLX5_ADDR_OF(set_action_in, single_action, data);
    3743                 :            :         } else {
    3744                 :            :                 /* Argument offset multiple with number of args per these actions */
    3745                 :          0 :                 arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
    3746                 :          0 :                 arg_idx = rule_action->modify_header.offset * arg_sz;
    3747                 :            : 
    3748         [ #  # ]:          0 :                 apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
    3749                 :            : 
    3750         [ #  # ]:          0 :                 if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
    3751                 :          0 :                         apply->require_dep = 1;
    3752                 :          0 :                         mlx5dr_action_modify_write(apply->queue,
    3753                 :          0 :                                                    action->modify_header.arg_obj->id + arg_idx,
    3754                 :            :                                                    rule_action->modify_header.data,
    3755                 :          0 :                                                    action->modify_header.num_of_actions);
    3756                 :            :                 }
    3757                 :            :         }
    3758                 :            : }
    3759                 :            : 
    3760                 :            : static void
    3761                 :          0 : mlx5dr_action_setter_nat64(struct mlx5dr_actions_apply_data *apply,
    3762                 :            :                            struct mlx5dr_actions_wqe_setter *setter)
    3763                 :            : {
    3764                 :            :         struct mlx5dr_rule_action *rule_action;
    3765                 :            :         struct mlx5dr_action *cur_stage_action;
    3766                 :            :         struct mlx5dr_action *action;
    3767                 :            :         uint32_t stc_idx;
    3768                 :            : 
    3769                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3770                 :          0 :         action = rule_action->action;
    3771                 :          0 :         cur_stage_action = action->nat64.stages[setter->stage_idx];
    3772                 :            : 
    3773                 :          0 :         stc_idx = htobe32(cur_stage_action->stc[apply->tbl_type].offset);
    3774                 :            : 
    3775                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
    3776                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3777                 :            : 
    3778                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
    3779                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
    3780                 :          0 : }
    3781                 :            : 
    3782                 :            : static void
    3783                 :          0 : mlx5dr_action_setter_insert_ptr(struct mlx5dr_actions_apply_data *apply,
    3784                 :            :                                 struct mlx5dr_actions_wqe_setter *setter)
    3785                 :            : {
    3786                 :            :         struct mlx5dr_rule_action *rule_action;
    3787                 :            :         uint32_t stc_idx, arg_idx, arg_sz;
    3788                 :            :         struct mlx5dr_action *action;
    3789                 :            : 
    3790                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3791                 :          0 :         action = rule_action->action + rule_action->reformat.hdr_idx;
    3792                 :            : 
    3793                 :            :         /* Argument offset multiple on args required for header size */
    3794                 :          0 :         arg_sz = mlx5dr_arg_data_size_to_arg_size(action->reformat.max_hdr_sz);
    3795                 :          0 :         arg_idx = rule_action->reformat.offset * arg_sz;
    3796                 :            : 
    3797         [ #  # ]:          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
    3798                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
    3799                 :            : 
    3800                 :          0 :         stc_idx = htobe32(action->stc[apply->tbl_type].offset);
    3801                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
    3802                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3803                 :            : 
    3804         [ #  # ]:          0 :         if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
    3805                 :          0 :                 apply->require_dep = 1;
    3806                 :          0 :                 mlx5dr_arg_write(apply->queue, NULL,
    3807                 :          0 :                                  action->reformat.arg_obj->id + arg_idx,
    3808                 :            :                                  rule_action->reformat.data,
    3809                 :          0 :                                  action->reformat.header_size);
    3810                 :            :         }
    3811                 :          0 : }
    3812                 :            : 
    3813                 :            : static void
    3814                 :          0 : mlx5dr_action_setter_tnl_l3_to_l2(struct mlx5dr_actions_apply_data *apply,
    3815                 :            :                                   struct mlx5dr_actions_wqe_setter *setter)
    3816                 :            : {
    3817                 :            :         struct mlx5dr_rule_action *rule_action;
    3818                 :            :         uint32_t stc_idx, arg_sz, arg_idx;
    3819                 :            :         struct mlx5dr_action *action;
    3820                 :            : 
    3821                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3822                 :          0 :         action = rule_action->action + rule_action->reformat.hdr_idx;
    3823                 :            : 
    3824                 :            :         /* Argument offset multiple on args required for num of actions */
    3825                 :          0 :         arg_sz = mlx5dr_arg_get_arg_size(action->modify_header.max_num_of_actions);
    3826                 :          0 :         arg_idx = rule_action->reformat.offset * arg_sz;
    3827                 :            : 
    3828         [ #  # ]:          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
    3829                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(arg_idx);
    3830                 :            : 
    3831                 :          0 :         stc_idx = htobe32(action->stc[apply->tbl_type].offset);
    3832                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = stc_idx;
    3833                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3834                 :            : 
    3835         [ #  # ]:          0 :         if (!(action->flags & MLX5DR_ACTION_FLAG_SHARED)) {
    3836                 :          0 :                 apply->require_dep = 1;
    3837                 :          0 :                 mlx5dr_arg_decapl3_write(apply->queue,
    3838                 :          0 :                                          action->modify_header.arg_obj->id + arg_idx,
    3839                 :            :                                          rule_action->reformat.data,
    3840                 :          0 :                                          action->modify_header.num_of_actions);
    3841                 :            :         }
    3842                 :          0 : }
    3843                 :            : 
    3844                 :            : static void
    3845                 :          0 : mlx5dr_action_setter_aso(struct mlx5dr_actions_apply_data *apply,
    3846                 :            :                          struct mlx5dr_actions_wqe_setter *setter)
    3847                 :            : {
    3848                 :            :         struct mlx5dr_rule_action *rule_action;
    3849                 :            :         uint32_t exe_aso_ctrl;
    3850                 :            :         uint32_t offset;
    3851                 :            : 
    3852                 :          0 :         rule_action = &apply->rule_action[setter->idx_double];
    3853                 :            : 
    3854      [ #  #  # ]:          0 :         switch (rule_action->action->type) {
    3855                 :          0 :         case MLX5DR_ACTION_TYP_ASO_METER:
    3856                 :            :                 /* exe_aso_ctrl format:
    3857                 :            :                  * [STC only and reserved bits 29b][init_color 2b][meter_id 1b]
    3858                 :            :                  */
    3859                 :          0 :                 offset = rule_action->aso_meter.offset / MLX5_ASO_METER_NUM_PER_OBJ;
    3860                 :          0 :                 exe_aso_ctrl = rule_action->aso_meter.offset % MLX5_ASO_METER_NUM_PER_OBJ;
    3861                 :          0 :                 exe_aso_ctrl |= rule_action->aso_meter.init_color <<
    3862                 :            :                                 MLX5DR_ACTION_METER_INIT_COLOR_OFFSET;
    3863                 :          0 :                 break;
    3864                 :          0 :         case MLX5DR_ACTION_TYP_ASO_CT:
    3865                 :            :                 /* exe_aso_ctrl CT format:
    3866                 :            :                  * [STC only and reserved bits 31b][direction 1b]
    3867                 :            :                  */
    3868                 :          0 :                 offset = rule_action->aso_ct.offset / MLX5_ASO_CT_NUM_PER_OBJ;
    3869                 :          0 :                 exe_aso_ctrl = rule_action->aso_ct.direction;
    3870                 :          0 :                 break;
    3871                 :          0 :         default:
    3872                 :          0 :                 DR_LOG(ERR, "Unsupported ASO action type: %d", rule_action->action->type);
    3873                 :          0 :                 rte_errno = ENOTSUP;
    3874                 :          0 :                 return;
    3875                 :            :         }
    3876                 :            : 
    3877                 :            :         /* aso_object_offset format: [24B] */
    3878                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = htobe32(offset);
    3879                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = htobe32(exe_aso_ctrl);
    3880                 :            : 
    3881                 :            :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW6, setter->idx_double);
    3882                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
    3883                 :            : }
    3884                 :            : 
    3885                 :            : static void
    3886                 :          0 : mlx5dr_action_setter_tag(struct mlx5dr_actions_apply_data *apply,
    3887                 :            :                          struct mlx5dr_actions_wqe_setter *setter)
    3888                 :            : {
    3889                 :            :         struct mlx5dr_rule_action *rule_action;
    3890                 :            : 
    3891                 :          0 :         rule_action = &apply->rule_action[setter->idx_single];
    3892                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = htobe32(rule_action->tag.value);
    3893                 :            :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
    3894                 :          0 : }
    3895                 :            : 
    3896                 :            : static void
    3897                 :          0 : mlx5dr_action_setter_ctrl_ctr(struct mlx5dr_actions_apply_data *apply,
    3898                 :            :                               struct mlx5dr_actions_wqe_setter *setter)
    3899                 :            : {
    3900                 :            :         struct mlx5dr_rule_action *rule_action;
    3901                 :            : 
    3902                 :          0 :         rule_action = &apply->rule_action[setter->idx_ctr];
    3903                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW0] = htobe32(rule_action->counter.offset);
    3904                 :            :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_CTRL, setter->idx_ctr);
    3905                 :          0 : }
    3906                 :            : 
    3907                 :            : static void
    3908                 :          0 : mlx5dr_action_setter_single(struct mlx5dr_actions_apply_data *apply,
    3909                 :            :                             struct mlx5dr_actions_wqe_setter *setter)
    3910                 :            : {
    3911                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
    3912                 :          0 :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_DW5, setter->idx_single);
    3913                 :          0 : }
    3914                 :            : 
    3915                 :            : static void
    3916                 :          0 : mlx5dr_action_setter_single_double_pop(struct mlx5dr_actions_apply_data *apply,
    3917                 :            :                                        __rte_unused struct mlx5dr_actions_wqe_setter *setter)
    3918                 :            : {
    3919                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
    3920                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
    3921                 :          0 :                 htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
    3922                 :            :                                                             MLX5DR_CONTEXT_SHARED_STC_DOUBLE_POP));
    3923                 :          0 : }
    3924                 :            : 
    3925                 :            : static void
    3926                 :          0 : mlx5dr_action_setter_hit(struct mlx5dr_actions_apply_data *apply,
    3927                 :            :                          struct mlx5dr_actions_wqe_setter *setter)
    3928                 :            : {
    3929                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
    3930                 :          0 :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_HIT, setter->idx_hit);
    3931                 :          0 : }
    3932                 :            : 
    3933                 :            : static void
    3934                 :          0 : mlx5dr_action_setter_default_hit(struct mlx5dr_actions_apply_data *apply,
    3935                 :            :                                  __rte_unused struct mlx5dr_actions_wqe_setter *setter)
    3936                 :            : {
    3937                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = 0;
    3938                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] =
    3939                 :          0 :                 htobe32(apply->common_res->default_stc->default_hit.offset);
    3940                 :          0 : }
    3941                 :            : 
    3942                 :            : static void
    3943                 :          0 : mlx5dr_action_setter_hit_matcher(struct mlx5dr_actions_apply_data *apply,
    3944                 :            :                                  struct mlx5dr_actions_wqe_setter *setter)
    3945                 :            : {
    3946                 :            :         struct mlx5dr_rule_action *rule_action;
    3947                 :            : 
    3948                 :          0 :         rule_action = &apply->rule_action[setter->idx_hit];
    3949                 :            : 
    3950                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] =
    3951                 :          0 :                 htobe32(rule_action->jump_to_matcher.offset << 6);
    3952                 :            :         mlx5dr_action_apply_stc(apply, MLX5DR_ACTION_STC_IDX_HIT, setter->idx_hit);
    3953                 :          0 : }
    3954                 :            : 
    3955                 :            : static void
    3956                 :          0 : mlx5dr_action_setter_hit_next_action(struct mlx5dr_actions_apply_data *apply,
    3957                 :            :                                      __rte_unused struct mlx5dr_actions_wqe_setter *setter)
    3958                 :            : {
    3959                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_HIT_LSB] = htobe32(apply->next_direct_idx << 6);
    3960                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_HIT] = htobe32(apply->jump_to_action_stc);
    3961                 :          0 : }
    3962                 :            : 
    3963                 :            : static void
    3964                 :          0 : mlx5dr_action_setter_common_decap(struct mlx5dr_actions_apply_data *apply,
    3965                 :            :                                   __rte_unused struct mlx5dr_actions_wqe_setter *setter)
    3966                 :            : {
    3967                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
    3968                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
    3969                 :          0 :                 htobe32(mlx5dr_action_get_shared_stc_offset(apply->common_res,
    3970                 :            :                                                             MLX5DR_CONTEXT_SHARED_STC_DECAP_L3));
    3971                 :          0 : }
    3972                 :            : 
    3973                 :            : static void
    3974                 :          0 : mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(uint8_t *data, void *mh_data)
    3975                 :            : {
    3976                 :            :         uint8_t *action_ptr = mh_data;
    3977                 :            :         uint32_t *ipv6_dst_addr;
    3978                 :            :         uint8_t seg_left;
    3979                 :            :         uint32_t i;
    3980                 :            : 
    3981                 :            :         /* Fetch the last IPv6 address in the segment list which is the next hop */
    3982         [ #  # ]:          0 :         seg_left = MLX5_GET(header_ipv6_routing_ext, data, segments_left) - 1;
    3983                 :          0 :         ipv6_dst_addr = (uint32_t *)data + MLX5_ST_SZ_DW(header_ipv6_routing_ext)
    3984                 :          0 :                         + seg_left * MLX5_ST_SZ_DW(definer_hl_ipv6_addr);
    3985                 :            : 
    3986                 :            :         /* Load next hop IPv6 address in reverse order to ipv6.dst_address */
    3987         [ #  # ]:          0 :         for (i = 0; i < MLX5_ST_SZ_DW(definer_hl_ipv6_addr); i++) {
    3988         [ #  # ]:          0 :                 MLX5_SET(set_action_in, action_ptr, data, be32toh(*ipv6_dst_addr++));
    3989                 :          0 :                 action_ptr += MLX5DR_MODIFY_ACTION_SIZE;
    3990                 :            :         }
    3991                 :            : 
    3992                 :            :         /* Set ipv6_route_ext.next_hdr per user input */
    3993         [ #  # ]:          0 :         MLX5_SET(set_action_in, action_ptr, data, *data);
    3994                 :          0 : }
    3995                 :            : 
    3996                 :            : static void
    3997                 :          0 : mlx5dr_action_setter_ipv6_route_ext_mhdr(struct mlx5dr_actions_apply_data *apply,
    3998                 :            :                                          struct mlx5dr_actions_wqe_setter *setter)
    3999                 :            : {
    4000                 :          0 :         struct mlx5dr_rule_action *rule_action = apply->rule_action;
    4001                 :          0 :         struct mlx5dr_actions_wqe_setter tmp_setter = {0};
    4002                 :            :         struct mlx5dr_rule_action tmp_rule_action;
    4003                 :          0 :         __be64 cmd[MLX5_SRV6_SAMPLE_NUM] = {0};
    4004                 :            :         struct mlx5dr_action *ipv6_ext_action;
    4005                 :            :         uint8_t *header;
    4006                 :            : 
    4007                 :          0 :         header = rule_action[setter->idx_double].ipv6_ext.header;
    4008                 :          0 :         ipv6_ext_action = rule_action[setter->idx_double].action;
    4009                 :          0 :         tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
    4010                 :            : 
    4011         [ #  # ]:          0 :         if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
    4012                 :          0 :                 tmp_rule_action.modify_header.offset = 0;
    4013                 :          0 :                 tmp_rule_action.modify_header.pattern_idx = 0;
    4014                 :          0 :                 tmp_rule_action.modify_header.data = NULL;
    4015                 :            :         } else {
    4016                 :            :                 /*
    4017                 :            :                  * Copy ipv6_dst from ipv6_route_ext.last_seg.
    4018                 :            :                  * Set ipv6_route_ext.next_hdr.
    4019                 :            :                  */
    4020                 :          0 :                 mlx5dr_action_setter_ipv6_route_ext_gen_push_mhdr(header, cmd);
    4021                 :          0 :                 tmp_rule_action.modify_header.data = (uint8_t *)cmd;
    4022                 :          0 :                 tmp_rule_action.modify_header.pattern_idx = 0;
    4023                 :          0 :                 tmp_rule_action.modify_header.offset =
    4024                 :          0 :                         rule_action[setter->idx_double].ipv6_ext.offset;
    4025                 :            :         }
    4026                 :            : 
    4027                 :          0 :         apply->rule_action = &tmp_rule_action;
    4028                 :            : 
    4029                 :            :         /* Reuse regular */
    4030                 :          0 :         mlx5dr_action_setter_modify_header(apply, &tmp_setter);
    4031                 :            : 
    4032                 :            :         /* Swap rule actions from backup */
    4033                 :          0 :         apply->rule_action = rule_action;
    4034                 :          0 : }
    4035                 :            : 
    4036                 :            : static void
    4037                 :          0 : mlx5dr_action_setter_ipv6_route_ext_insert_ptr(struct mlx5dr_actions_apply_data *apply,
    4038                 :            :                                                struct mlx5dr_actions_wqe_setter *setter)
    4039                 :            : {
    4040                 :          0 :         struct mlx5dr_rule_action *rule_action = apply->rule_action;
    4041                 :          0 :         struct mlx5dr_actions_wqe_setter tmp_setter = {0};
    4042                 :            :         struct mlx5dr_rule_action tmp_rule_action;
    4043                 :            :         struct mlx5dr_action *ipv6_ext_action;
    4044                 :            :         uint8_t header[MLX5_PUSH_MAX_LEN];
    4045                 :            : 
    4046                 :          0 :         ipv6_ext_action = rule_action[setter->idx_double].action;
    4047                 :          0 :         tmp_rule_action.action = ipv6_ext_action->ipv6_route_ext.action[setter->extra_data];
    4048                 :            : 
    4049         [ #  # ]:          0 :         if (tmp_rule_action.action->flags & MLX5DR_ACTION_FLAG_SHARED) {
    4050                 :          0 :                 tmp_rule_action.reformat.offset = 0;
    4051                 :          0 :                 tmp_rule_action.reformat.hdr_idx = 0;
    4052                 :          0 :                 tmp_rule_action.reformat.data = NULL;
    4053                 :            :         } else {
    4054                 :          0 :                 memcpy(header, rule_action[setter->idx_double].ipv6_ext.header,
    4055         [ #  # ]:          0 :                        tmp_rule_action.action->reformat.header_size);
    4056                 :            :                 /* Clear ipv6_route_ext.next_hdr for right checksum */
    4057         [ #  # ]:          0 :                 MLX5_SET(header_ipv6_routing_ext, header, next_hdr, 0);
    4058                 :          0 :                 tmp_rule_action.reformat.data = header;
    4059                 :          0 :                 tmp_rule_action.reformat.hdr_idx = 0;
    4060                 :          0 :                 tmp_rule_action.reformat.offset =
    4061                 :          0 :                         rule_action[setter->idx_double].ipv6_ext.offset;
    4062                 :            :         }
    4063                 :            : 
    4064                 :          0 :         apply->rule_action = &tmp_rule_action;
    4065                 :            : 
    4066                 :            :         /* Reuse regular */
    4067                 :          0 :         mlx5dr_action_setter_insert_ptr(apply, &tmp_setter);
    4068                 :            : 
    4069                 :            :         /* Swap rule actions from backup */
    4070                 :          0 :         apply->rule_action = rule_action;
    4071                 :          0 : }
    4072                 :            : 
    4073                 :            : static void
    4074                 :          0 : mlx5dr_action_setter_ipv6_route_ext_pop(struct mlx5dr_actions_apply_data *apply,
    4075                 :            :                                         struct mlx5dr_actions_wqe_setter *setter)
    4076                 :            : {
    4077                 :          0 :         struct mlx5dr_rule_action *rule_action = &apply->rule_action[setter->idx_single];
    4078                 :            :         uint8_t idx = MLX5DR_ACTION_IPV6_EXT_MAX_SA - 1;
    4079                 :            :         struct mlx5dr_action *action;
    4080                 :            : 
    4081                 :            :         /* Pop the ipv6_route_ext as set_single logic */
    4082                 :          0 :         action = rule_action->action->ipv6_route_ext.action[idx];
    4083                 :          0 :         apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
    4084                 :          0 :         apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
    4085                 :          0 :                 htobe32(action->stc[apply->tbl_type].offset);
    4086                 :          0 : }
    4087                 :            : 
    4088                 :          0 : int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
    4089                 :            : {
    4090                 :          0 :         struct mlx5dr_actions_wqe_setter *start_setter = at->setters + 1;
    4091                 :          0 :         enum mlx5dr_action_type *action_type = at->action_type_arr;
    4092                 :          0 :         struct mlx5dr_actions_wqe_setter *setter = at->setters;
    4093                 :            :         struct mlx5dr_actions_wqe_setter *pop_setter = NULL;
    4094                 :            :         struct mlx5dr_actions_wqe_setter *last_setter;
    4095                 :            :         int i, j;
    4096                 :            : 
    4097                 :            :         /* Note: Given action combination must be valid */
    4098                 :            : 
    4099                 :            :         /* Check if action were already processed */
    4100         [ #  # ]:          0 :         if (at->num_of_action_stes)
    4101                 :            :                 return 0;
    4102                 :            : 
    4103         [ #  # ]:          0 :         for (i = 0; i < MLX5DR_ACTION_MAX_STE; i++)
    4104                 :          0 :                 setter[i].set_hit = &mlx5dr_action_setter_hit_next_action;
    4105                 :            : 
    4106                 :            :         /* The same action template setters can be used with jumbo or match
    4107                 :            :          * STE, to support both cases we reseve the first setter for cases
    4108                 :            :          * with jumbo STE to allow jump to the first action STE.
    4109                 :            :          * This extra setter can be reduced in some cases on rule creation.
    4110                 :            :          */
    4111                 :            :         setter = start_setter;
    4112                 :            :         last_setter = start_setter;
    4113                 :            : 
    4114         [ #  # ]:          0 :         for (i = 0; i < at->num_actions; i++) {
    4115   [ #  #  #  #  :          0 :                 switch (action_type[i]) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    4116                 :          0 :                 case MLX5DR_ACTION_TYP_DROP:
    4117                 :            :                 case MLX5DR_ACTION_TYP_TIR:
    4118                 :            :                 case MLX5DR_ACTION_TYP_TBL:
    4119                 :            :                 case MLX5DR_ACTION_TYP_DEST_ROOT:
    4120                 :            :                 case MLX5DR_ACTION_TYP_DEST_ARRAY:
    4121                 :            :                 case MLX5DR_ACTION_TYP_VPORT:
    4122                 :            :                 case MLX5DR_ACTION_TYP_MISS:
    4123                 :            :                         /* Hit action */
    4124                 :          0 :                         last_setter->flags |= ASF_HIT;
    4125                 :          0 :                         last_setter->set_hit = &mlx5dr_action_setter_hit;
    4126                 :          0 :                         last_setter->idx_hit = i;
    4127                 :          0 :                         break;
    4128                 :            : 
    4129                 :          0 :                 case MLX5DR_ACTION_TYP_POP_VLAN:
    4130                 :            :                         /* Single remove header to header */
    4131         [ #  # ]:          0 :                         if (pop_setter) {
    4132                 :            :                                 /* We have 2 pops, use the shared */
    4133                 :          0 :                                 pop_setter->set_single = &mlx5dr_action_setter_single_double_pop;
    4134                 :          0 :                                 break;
    4135                 :            :                         }
    4136                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_MODIFY | ASF_INSERT);
    4137                 :          0 :                         setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
    4138                 :          0 :                         setter->set_single = &mlx5dr_action_setter_single;
    4139                 :          0 :                         setter->idx_single = i;
    4140                 :            :                         pop_setter = setter;
    4141                 :          0 :                         break;
    4142                 :            : 
    4143                 :            :                 case MLX5DR_ACTION_TYP_PUSH_VLAN:
    4144                 :            :                         /* Double insert inline */
    4145                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4146                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_INSERT;
    4147                 :          0 :                         setter->set_double = &mlx5dr_action_setter_push_vlan;
    4148                 :          0 :                         setter->idx_double = i;
    4149                 :          0 :                         break;
    4150                 :            : 
    4151                 :            :                 case MLX5DR_ACTION_TYP_POP_IPV6_ROUTE_EXT:
    4152                 :            :                         /*
    4153                 :            :                          * Backup ipv6_route_ext.next_hdr to ipv6_route_ext.seg_left.
    4154                 :            :                          * Set ipv6_route_ext.next_hdr to 0 for checksum bug.
    4155                 :            :                          */
    4156                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4157                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4158                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
    4159                 :          0 :                         setter->idx_double = i;
    4160                 :          0 :                         setter->extra_data = 0;
    4161                 :            :                         setter++;
    4162                 :            : 
    4163                 :            :                         /*
    4164                 :            :                          * Restore ipv6_route_ext.next_hdr from ipv6_route_ext.seg_left.
    4165                 :            :                          * Load the final destination address from flex parser sample 1->4.
    4166                 :            :                          */
    4167                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4168                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
    4169                 :          0 :                         setter->idx_double = i;
    4170                 :          0 :                         setter->extra_data = 1;
    4171                 :          0 :                         setter++;
    4172                 :            : 
    4173                 :            :                         /* Set the ipv6.protocol per ipv6_route_ext.next_hdr */
    4174                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4175                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
    4176                 :          0 :                         setter->idx_double = i;
    4177                 :          0 :                         setter->extra_data = 2;
    4178                 :            :                         /* Pop ipv6_route_ext */
    4179                 :          0 :                         setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
    4180                 :          0 :                         setter->set_single = &mlx5dr_action_setter_ipv6_route_ext_pop;
    4181                 :          0 :                         setter->idx_single = i;
    4182                 :          0 :                         at->need_dep_write = true;
    4183                 :          0 :                         break;
    4184                 :            : 
    4185                 :            :                 case MLX5DR_ACTION_TYP_PUSH_IPV6_ROUTE_EXT:
    4186                 :            :                         /* Insert ipv6_route_ext with next_hdr as 0 due to checksum bug */
    4187                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4188                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_INSERT;
    4189                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_insert_ptr;
    4190                 :          0 :                         setter->idx_double = i;
    4191                 :          0 :                         setter->extra_data = 0;
    4192                 :            :                         setter++;
    4193                 :            : 
    4194                 :            :                         /* Set ipv6.protocol as IPPROTO_ROUTING: 0x2b */
    4195                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4196                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
    4197                 :          0 :                         setter->idx_double = i;
    4198                 :          0 :                         setter->extra_data = 1;
    4199                 :          0 :                         setter++;
    4200                 :            : 
    4201                 :            :                         /*
    4202                 :            :                          * Load the right ipv6_route_ext.next_hdr per user input buffer.
    4203                 :            :                          * Load the next dest_addr from the ipv6_route_ext.seg_list[last].
    4204                 :            :                          */
    4205                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4206                 :          0 :                         setter->set_double = &mlx5dr_action_setter_ipv6_route_ext_mhdr;
    4207                 :          0 :                         setter->idx_double = i;
    4208                 :          0 :                         setter->extra_data = 2;
    4209                 :          0 :                         at->need_dep_write = true;
    4210                 :          0 :                         break;
    4211                 :            : 
    4212                 :            :                 case MLX5DR_ACTION_TYP_MODIFY_HDR:
    4213                 :            :                         /* Double modify header list */
    4214                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4215                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4216                 :          0 :                         setter->set_double = &mlx5dr_action_setter_modify_header;
    4217                 :          0 :                         setter->idx_double = i;
    4218                 :          0 :                         at->need_dep_write = true;
    4219                 :          0 :                         break;
    4220                 :            : 
    4221                 :            :                 case MLX5DR_ACTION_TYP_ASO_METER:
    4222                 :            :                 case MLX5DR_ACTION_TYP_ASO_CT:
    4223                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE);
    4224                 :          0 :                         setter->flags |= ASF_DOUBLE;
    4225                 :          0 :                         setter->set_double = &mlx5dr_action_setter_aso;
    4226                 :          0 :                         setter->idx_double = i;
    4227                 :          0 :                         break;
    4228                 :            : 
    4229                 :            :                 case MLX5DR_ACTION_TYP_REMOVE_HEADER:
    4230                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_TNL_L2_TO_L2:
    4231                 :            :                         /* Single remove header to header */
    4232                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter,
    4233                 :            :                                         ASF_SINGLE1 | ASF_MODIFY | ASF_INSERT);
    4234                 :          0 :                         setter->flags |= ASF_SINGLE1 | ASF_REMOVE;
    4235                 :          0 :                         setter->set_single = &mlx5dr_action_setter_single;
    4236                 :          0 :                         setter->idx_single = i;
    4237                 :          0 :                         break;
    4238                 :            : 
    4239                 :            :                 case MLX5DR_ACTION_TYP_INSERT_HEADER:
    4240                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L2:
    4241                 :            :                         /* Double insert header with pointer */
    4242                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4243                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_INSERT;
    4244                 :          0 :                         setter->set_double = &mlx5dr_action_setter_insert_ptr;
    4245                 :          0 :                         setter->idx_double = i;
    4246                 :          0 :                         at->need_dep_write = true;
    4247                 :          0 :                         break;
    4248                 :            : 
    4249                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_L2_TO_TNL_L3:
    4250                 :            :                         /* Single remove + Double insert header with pointer */
    4251                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_SINGLE1 | ASF_DOUBLE);
    4252                 :          0 :                         setter->flags |= ASF_SINGLE1 | ASF_DOUBLE;
    4253                 :          0 :                         setter->set_double = &mlx5dr_action_setter_insert_ptr;
    4254                 :          0 :                         setter->idx_double = i;
    4255                 :          0 :                         setter->set_single = &mlx5dr_action_setter_common_decap;
    4256                 :          0 :                         setter->idx_single = i;
    4257                 :          0 :                         at->need_dep_write = true;
    4258                 :          0 :                         break;
    4259                 :            : 
    4260                 :            :                 case MLX5DR_ACTION_TYP_REFORMAT_TNL_L3_TO_L2:
    4261                 :            :                         /* Double modify header list with remove and push inline */
    4262                 :            :                         setter = mlx5dr_action_setter_find_first(last_setter, ASF_DOUBLE | ASF_REMOVE);
    4263                 :          0 :                         setter->flags |= ASF_DOUBLE | ASF_MODIFY | ASF_INSERT;
    4264                 :          0 :                         setter->set_double = &mlx5dr_action_setter_tnl_l3_to_l2;
    4265                 :          0 :                         setter->idx_double = i;
    4266                 :          0 :                         at->need_dep_write = true;
    4267                 :          0 :                         break;
    4268                 :            : 
    4269                 :            :                 case MLX5DR_ACTION_TYP_TAG:
    4270                 :            :                         /* Single TAG action, search for any room from the start */
    4271                 :            :                         setter = mlx5dr_action_setter_find_first(start_setter, ASF_SINGLE1);
    4272                 :          0 :                         setter->flags |= ASF_SINGLE1;
    4273                 :          0 :                         setter->set_single = &mlx5dr_action_setter_tag;
    4274                 :          0 :                         setter->idx_single = i;
    4275                 :          0 :                         break;
    4276                 :            : 
    4277                 :            :                 case MLX5DR_ACTION_TYP_CTR:
    4278                 :            :                         /* Control counter action
    4279                 :            :                          * TODO: Current counter executed first. Support is needed
    4280                 :            :                          *       for single ation counter action which is done last.
    4281                 :            :                          *       Example: Decap + CTR
    4282                 :            :                          */
    4283                 :            :                         setter = mlx5dr_action_setter_find_first(start_setter, ASF_CTR);
    4284                 :          0 :                         setter->flags |= ASF_CTR;
    4285                 :          0 :                         setter->set_ctr = &mlx5dr_action_setter_ctrl_ctr;
    4286                 :          0 :                         setter->idx_ctr = i;
    4287                 :          0 :                         break;
    4288                 :            : 
    4289                 :            :                 case MLX5DR_ACTION_TYP_NAT64:
    4290                 :            :                         /* NAT64 requires 3 setters, each of them does specific modify header */
    4291         [ #  # ]:          0 :                         for (j = 0; j < MLX5DR_ACTION_NAT64_STAGES; j++) {
    4292                 :            :                                 setter = mlx5dr_action_setter_find_first(last_setter,
    4293                 :            :                                                                          ASF_DOUBLE | ASF_REMOVE);
    4294                 :          0 :                                 setter->flags |= ASF_DOUBLE | ASF_MODIFY;
    4295                 :          0 :                                 setter->set_double = &mlx5dr_action_setter_nat64;
    4296                 :          0 :                                 setter->idx_double = i;
    4297                 :            :                                 /* The stage indicates which modify-header to push */
    4298                 :          0 :                                 setter->stage_idx = j;
    4299                 :            :                         }
    4300                 :            :                         break;
    4301                 :            : 
    4302                 :          0 :                 case MLX5DR_ACTION_TYP_JUMP_TO_MATCHER:
    4303                 :          0 :                         last_setter->flags |= ASF_HIT;
    4304                 :          0 :                         last_setter->set_hit = &mlx5dr_action_setter_hit_matcher;
    4305                 :          0 :                         last_setter->idx_hit = i;
    4306                 :          0 :                         break;
    4307                 :            : 
    4308                 :          0 :                 default:
    4309                 :          0 :                         DR_LOG(ERR, "Unsupported action type: %d", action_type[i]);
    4310                 :          0 :                         rte_errno = ENOTSUP;
    4311                 :          0 :                         assert(false);
    4312                 :            :                         return rte_errno;
    4313                 :            :                 }
    4314                 :            : 
    4315                 :          0 :                 last_setter = RTE_MAX(setter, last_setter);
    4316                 :            :         }
    4317                 :            : 
    4318                 :            :         /* Set default hit on the last STE if no hit action provided */
    4319         [ #  # ]:          0 :         if (!(last_setter->flags & ASF_HIT))
    4320                 :          0 :                 last_setter->set_hit = &mlx5dr_action_setter_default_hit;
    4321                 :            : 
    4322                 :          0 :         at->num_of_action_stes = last_setter - start_setter + 1;
    4323                 :            : 
    4324                 :            :         /* Check if action template doesn't require any action DWs */
    4325         [ #  # ]:          0 :         at->only_term = (at->num_of_action_stes == 1) &&
    4326         [ #  # ]:          0 :                 !(last_setter->flags & ~(ASF_CTR | ASF_HIT));
    4327                 :            : 
    4328                 :          0 :         return 0;
    4329                 :            : }
    4330                 :            : 
    4331                 :            : struct mlx5dr_action_template *
    4332                 :          0 : mlx5dr_action_template_create(const enum mlx5dr_action_type action_type[],
    4333                 :            :                               uint32_t flags)
    4334                 :            : {
    4335                 :            :         struct mlx5dr_action_template *at;
    4336                 :            :         uint8_t num_actions = 0;
    4337                 :            :         int i;
    4338                 :            : 
    4339         [ #  # ]:          0 :         if (flags > MLX5DR_ACTION_TEMPLATE_FLAG_RELAXED_ORDER) {
    4340                 :          0 :                 DR_LOG(ERR, "Unsupported action template flag provided");
    4341                 :          0 :                 rte_errno = EINVAL;
    4342                 :          0 :                 return NULL;
    4343                 :            :         }
    4344                 :            : 
    4345                 :            :         at = simple_calloc(1, sizeof(*at));
    4346         [ #  # ]:          0 :         if (!at) {
    4347                 :          0 :                 DR_LOG(ERR, "Failed to allocate action template");
    4348                 :          0 :                 rte_errno = ENOMEM;
    4349                 :          0 :                 return NULL;
    4350                 :            :         }
    4351                 :            : 
    4352                 :          0 :         at->flags = flags;
    4353                 :            : 
    4354         [ #  # ]:          0 :         while (action_type[num_actions++] != MLX5DR_ACTION_TYP_LAST)
    4355                 :            :                 ;
    4356                 :            : 
    4357                 :          0 :         at->num_actions = num_actions - 1;
    4358                 :          0 :         at->action_type_arr = simple_calloc(num_actions, sizeof(*action_type));
    4359         [ #  # ]:          0 :         if (!at->action_type_arr) {
    4360                 :          0 :                 DR_LOG(ERR, "Failed to allocate action type array");
    4361                 :          0 :                 rte_errno = ENOMEM;
    4362                 :          0 :                 goto free_at;
    4363                 :            :         }
    4364                 :            : 
    4365         [ #  # ]:          0 :         for (i = 0; i < num_actions; i++)
    4366                 :          0 :                 at->action_type_arr[i] = action_type[i];
    4367                 :            : 
    4368                 :            :         return at;
    4369                 :            : 
    4370                 :            : free_at:
    4371                 :            :         simple_free(at);
    4372                 :          0 :         return NULL;
    4373                 :            : }
    4374                 :            : 
    4375                 :          0 : int mlx5dr_action_template_destroy(struct mlx5dr_action_template *at)
    4376                 :            : {
    4377                 :          0 :         simple_free(at->action_type_arr);
    4378                 :            :         simple_free(at);
    4379                 :          0 :         return 0;
    4380                 :            : }

Generated by: LCOV version 1.14