LCOV - code coverage report
Current view: top level - drivers/regex/mlx5 - mlx5_regex_control.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 106 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 46 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2020 Mellanox Technologies, Ltd
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <errno.h>
       6                 :            : 
       7                 :            : #include <rte_log.h>
       8                 :            : #include <rte_errno.h>
       9                 :            : #include <rte_memory.h>
      10                 :            : #include <rte_malloc.h>
      11                 :            : #include <rte_regexdev.h>
      12                 :            : #include <rte_regexdev_core.h>
      13                 :            : #include <rte_regexdev_driver.h>
      14                 :            : #include <dev_driver.h>
      15                 :            : 
      16                 :            : #include <mlx5_common.h>
      17                 :            : #include <mlx5_glue.h>
      18                 :            : #include <mlx5_devx_cmds.h>
      19                 :            : #include <mlx5_prm.h>
      20                 :            : #include <mlx5_common_os.h>
      21                 :            : #include <mlx5_common_devx.h>
      22                 :            : 
      23                 :            : #include "mlx5_regex.h"
      24                 :            : #include "mlx5_regex_utils.h"
      25                 :            : #include "mlx5_rxp.h"
      26                 :            : 
      27                 :            : #define MLX5_REGEX_NUM_WQE_PER_PAGE (4096/64)
      28                 :            : 
      29                 :            : #define MLX5_REGEX_WQE_LOG_NUM(has_umr, log_desc) \
      30                 :            :                 ((has_umr) ? ((log_desc) + 2) : (log_desc))
      31                 :            : 
      32                 :            : /**
      33                 :            :  * Returns the number of qp obj to be created.
      34                 :            :  *
      35                 :            :  * @param nb_desc
      36                 :            :  *   The number of descriptors for the queue.
      37                 :            :  *
      38                 :            :  * @return
      39                 :            :  *   The number of obj to be created.
      40                 :            :  */
      41                 :            : static uint16_t
      42                 :            : regex_ctrl_get_nb_obj(uint16_t nb_desc)
      43                 :            : {
      44                 :          0 :         return ((nb_desc / MLX5_REGEX_NUM_WQE_PER_PAGE) +
      45                 :          0 :                 !!(nb_desc % MLX5_REGEX_NUM_WQE_PER_PAGE));
      46                 :            : }
      47                 :            : 
      48                 :            : /**
      49                 :            :  * destroy CQ.
      50                 :            :  *
      51                 :            :  * @param cp
      52                 :            :  *   Pointer to the CQ to be destroyed.
      53                 :            :  *
      54                 :            :  * @return
      55                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
      56                 :            :  */
      57                 :            : static int
      58                 :          0 : regex_ctrl_destroy_cq(struct mlx5_regex_cq *cq)
      59                 :            : {
      60                 :          0 :         mlx5_devx_cq_destroy(&cq->cq_obj);
      61                 :            :         memset(cq, 0, sizeof(*cq));
      62                 :          0 :         return 0;
      63                 :            : }
      64                 :            : 
      65                 :            : /**
      66                 :            :  * create the CQ object.
      67                 :            :  *
      68                 :            :  * @param priv
      69                 :            :  *   Pointer to the priv object.
      70                 :            :  * @param cp
      71                 :            :  *   Pointer to the CQ to be created.
      72                 :            :  *
      73                 :            :  * @return
      74                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
      75                 :            :  */
      76                 :            : static int
      77                 :          0 : regex_ctrl_create_cq(struct mlx5_regex_priv *priv, struct mlx5_regex_cq *cq)
      78                 :            : {
      79                 :          0 :         struct mlx5_devx_cq_attr attr = {
      80         [ #  # ]:          0 :                 .uar_page_id = mlx5_os_get_devx_uar_page_id(priv->uar.obj),
      81                 :            :         };
      82                 :            :         int ret;
      83                 :            : 
      84                 :          0 :         cq->ci = 0;
      85                 :          0 :         ret = mlx5_devx_cq_create(priv->cdev->ctx, &cq->cq_obj, cq->log_nb_desc,
      86                 :            :                                   &attr, SOCKET_ID_ANY);
      87         [ #  # ]:          0 :         if (ret) {
      88                 :          0 :                 DRV_LOG(ERR, "Can't create CQ object.");
      89                 :            :                 memset(cq, 0, sizeof(*cq));
      90                 :          0 :                 rte_errno = ENOMEM;
      91                 :          0 :                 return -rte_errno;
      92                 :            :         }
      93                 :            :         return 0;
      94                 :            : }
      95                 :            : 
      96                 :            : /**
      97                 :            :  * Destroy the SQ object.
      98                 :            :  *
      99                 :            :  * @param qp
     100                 :            :  *   Pointer to the QP element
     101                 :            :  * @param q_ind
     102                 :            :  *   The index of the queue.
     103                 :            :  *
     104                 :            :  * @return
     105                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     106                 :            :  */
     107                 :            : static int
     108                 :          0 : regex_ctrl_destroy_hw_qp(struct mlx5_regex_qp *qp, uint16_t q_ind)
     109                 :            : {
     110                 :          0 :         struct mlx5_regex_hw_qp *qp_obj = &qp->qps[q_ind];
     111                 :            : 
     112                 :          0 :         mlx5_devx_qp_destroy(&qp_obj->qp_obj);
     113                 :            :         memset(qp, 0, sizeof(*qp));
     114                 :          0 :         return 0;
     115                 :            : }
     116                 :            : 
     117                 :            : /**
     118                 :            :  * create the SQ object.
     119                 :            :  *
     120                 :            :  * @param priv
     121                 :            :  *   Pointer to the priv object.
     122                 :            :  * @param qp
     123                 :            :  *   Pointer to the QP element
     124                 :            :  * @param q_ind
     125                 :            :  *   The index of the queue.
     126                 :            :  * @param log_nb_desc
     127                 :            :  *   Log 2 of the number of descriptors to be used.
     128                 :            :  *
     129                 :            :  * @return
     130                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     131                 :            :  */
     132                 :            : static int
     133                 :          0 : regex_ctrl_create_hw_qp(struct mlx5_regex_priv *priv, struct mlx5_regex_qp *qp,
     134                 :            :                      uint16_t q_ind, uint16_t log_nb_desc)
     135                 :            : {
     136                 :            : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
     137                 :          0 :         struct mlx5_devx_qp_attr attr = {
     138                 :          0 :                 .cqn = qp->cq.cq_obj.cq->id,
     139                 :          0 :                 .uar_index = mlx5_os_get_devx_uar_page_id(priv->uar.obj),
     140         [ #  # ]:          0 :                 .pd = priv->cdev->pdn,
     141                 :          0 :                 .ts_format = mlx5_ts_format_conv
     142         [ #  # ]:          0 :                                      (priv->cdev->config.hca_attr.qp_ts_format),
     143                 :            :                 .user_index = q_ind,
     144                 :            :         };
     145                 :          0 :         struct mlx5_regex_hw_qp *qp_obj = &qp->qps[q_ind];
     146                 :            :         int ret;
     147                 :            : 
     148                 :          0 :         qp_obj->log_nb_desc = log_nb_desc;
     149                 :          0 :         qp_obj->qpn = q_ind;
     150                 :          0 :         qp_obj->ci = 0;
     151                 :          0 :         qp_obj->pi = 0;
     152                 :          0 :         attr.num_of_receive_wqes = 0;
     153         [ #  # ]:          0 :         attr.num_of_send_wqbbs = RTE_BIT32(MLX5_REGEX_WQE_LOG_NUM(priv->has_umr,
     154                 :            :                         log_nb_desc));
     155                 :          0 :         attr.mmo = priv->mmo_regex_qp_cap;
     156                 :          0 :         ret = mlx5_devx_qp_create(priv->cdev->ctx, &qp_obj->qp_obj,
     157                 :          0 :                         attr.num_of_send_wqbbs * MLX5_WQE_SIZE, &attr,
     158                 :            :                         SOCKET_ID_ANY);
     159         [ #  # ]:          0 :         if (ret) {
     160                 :          0 :                 DRV_LOG(ERR, "Can't create QP object.");
     161                 :          0 :                 rte_errno = ENOMEM;
     162                 :          0 :                 return -rte_errno;
     163                 :            :         }
     164                 :          0 :         ret = mlx5_devx_qp2rts(&qp_obj->qp_obj, 0);
     165         [ #  # ]:          0 :         if (ret) {
     166                 :          0 :                 DRV_LOG(ERR, "Can't change QP state to RTS.");
     167                 :          0 :                 regex_ctrl_destroy_hw_qp(qp, q_ind);
     168                 :          0 :                 rte_errno = ENOMEM;
     169                 :          0 :                 return -rte_errno;
     170                 :            :         }
     171                 :            :         return 0;
     172                 :            : #else
     173                 :            :         (void)priv;
     174                 :            :         (void)qp;
     175                 :            :         (void)q_ind;
     176                 :            :         (void)log_nb_desc;
     177                 :            :         DRV_LOG(ERR, "Cannot get pdn - no DV support.");
     178                 :            :         return -ENOTSUP;
     179                 :            : #endif
     180                 :            : }
     181                 :            : 
     182                 :            : /**
     183                 :            :  * Setup the qp.
     184                 :            :  *
     185                 :            :  * @param dev
     186                 :            :  *   Pointer to RegEx dev structure.
     187                 :            :  * @param qp_ind
     188                 :            :  *   The queue index to setup.
     189                 :            :  * @param cfg
     190                 :            :  *   The queue requested configuration.
     191                 :            :  *
     192                 :            :  * @return
     193                 :            :  *   0 on success, a negative errno value otherwise and rte_errno is set.
     194                 :            :  */
     195                 :            : int
     196                 :          0 : mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
     197                 :            :                     const struct rte_regexdev_qp_conf *cfg)
     198                 :            : {
     199                 :          0 :         struct mlx5_regex_priv *priv = dev->data->dev_private;
     200                 :            :         struct mlx5_regex_qp *qp;
     201                 :            :         int i;
     202                 :            :         int nb_sq_config = 0;
     203                 :            :         int ret;
     204                 :            :         uint16_t log_desc;
     205                 :            : 
     206                 :          0 :         qp = &priv->qps[qp_ind];
     207         [ #  # ]:          0 :         if (qp->jobs) {
     208                 :          0 :                 DRV_LOG(ERR, "Attempting to setup QP a second time.");
     209                 :          0 :                 rte_errno = EINVAL;
     210                 :          0 :                 return -rte_errno;
     211                 :            :         }
     212                 :            : 
     213                 :          0 :         qp->flags = cfg->qp_conf_flags;
     214         [ #  # ]:          0 :         log_desc = rte_log2_u32(cfg->nb_desc);
     215                 :            :         /*
     216                 :            :          * UMR mode requires two WQEs(UMR and RegEx WQE) for one descriptor.
     217                 :            :          * For CQ, expand the CQE number multiple with 2.
     218                 :            :          * For SQ, the UMR and RegEx WQE for one descriptor consumes 4 WQEBBS,
     219                 :            :          * expand the WQE number multiple with 4.
     220                 :            :          */
     221                 :          0 :         qp->cq.log_nb_desc = log_desc + (!!priv->has_umr);
     222                 :          0 :         qp->nb_desc = 1 << log_desc;
     223         [ #  # ]:          0 :         if (qp->flags & RTE_REGEX_QUEUE_PAIR_CFG_OOS_F)
     224         [ #  # ]:          0 :                 qp->nb_obj = regex_ctrl_get_nb_obj
     225                 :          0 :                         (1 << MLX5_REGEX_WQE_LOG_NUM(priv->has_umr, log_desc));
     226                 :            :         else
     227                 :          0 :                 qp->nb_obj = 1;
     228                 :          0 :         qp->qps = rte_malloc(NULL,
     229                 :          0 :                              qp->nb_obj * sizeof(struct mlx5_regex_hw_qp), 64);
     230         [ #  # ]:          0 :         if (!qp->qps) {
     231                 :          0 :                 DRV_LOG(ERR, "Can't allocate qp array memory.");
     232                 :          0 :                 rte_errno = ENOMEM;
     233                 :          0 :                 return -rte_errno;
     234                 :            :         }
     235         [ #  # ]:          0 :         log_desc = rte_log2_u32(qp->nb_desc / qp->nb_obj);
     236                 :          0 :         ret = regex_ctrl_create_cq(priv, &qp->cq);
     237         [ #  # ]:          0 :         if (ret) {
     238                 :          0 :                 DRV_LOG(ERR, "Can't create cq.");
     239                 :          0 :                 goto err_cq;
     240                 :            :         }
     241         [ #  # ]:          0 :         for (i = 0; i < qp->nb_obj; i++) {
     242                 :          0 :                 ret = regex_ctrl_create_hw_qp(priv, qp, i, log_desc);
     243         [ #  # ]:          0 :                 if (ret) {
     244                 :          0 :                         DRV_LOG(ERR, "Can't create qp object.");
     245                 :          0 :                         goto err_btree;
     246                 :            :                 }
     247                 :          0 :                 nb_sq_config++;
     248                 :            :         }
     249                 :            : 
     250                 :          0 :         ret = mlx5_mr_ctrl_init(&qp->mr_ctrl, &priv->cdev->mr_scache.dev_gen,
     251                 :          0 :                                 rte_socket_id());
     252         [ #  # ]:          0 :         if (ret) {
     253                 :          0 :                 DRV_LOG(ERR, "Error setting up mr btree");
     254                 :          0 :                 goto err_btree;
     255                 :            :         }
     256                 :            : 
     257                 :          0 :         ret = mlx5_regexdev_setup_fastpath(priv, qp_ind);
     258         [ #  # ]:          0 :         if (ret) {
     259                 :          0 :                 DRV_LOG(ERR, "Error setting up fastpath");
     260                 :          0 :                 goto err_fp;
     261                 :            :         }
     262                 :            :         return 0;
     263                 :            : 
     264                 :            : err_fp:
     265                 :          0 :         mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
     266                 :          0 : err_btree:
     267         [ #  # ]:          0 :         for (i = 0; i < nb_sq_config; i++)
     268                 :          0 :                 regex_ctrl_destroy_hw_qp(qp, i);
     269                 :          0 :         regex_ctrl_destroy_cq(&qp->cq);
     270                 :          0 : err_cq:
     271                 :          0 :         rte_free(qp->qps);
     272                 :          0 :         return ret;
     273                 :            : }
     274                 :            : 
     275                 :            : void
     276                 :          0 : mlx5_regex_clean_ctrl(struct rte_regexdev *dev)
     277                 :            : {
     278                 :          0 :         struct mlx5_regex_priv *priv = dev->data->dev_private;
     279                 :            :         struct mlx5_regex_qp *qp;
     280                 :            :         int qp_ind;
     281                 :            :         int i;
     282                 :            : 
     283         [ #  # ]:          0 :         if (!priv->qps)
     284                 :            :                 return;
     285         [ #  # ]:          0 :         for (qp_ind = 0; qp_ind < priv->nb_queues; qp_ind++) {
     286                 :          0 :                 qp = &priv->qps[qp_ind];
     287                 :            :                 /* Check if mlx5_regex_qp_setup() was called for this QP */
     288         [ #  # ]:          0 :                 if (!qp->jobs)
     289                 :          0 :                         continue;
     290                 :          0 :                 mlx5_regexdev_teardown_fastpath(priv, qp_ind);
     291                 :          0 :                 mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
     292         [ #  # ]:          0 :                 for (i = 0; i < qp->nb_obj; i++)
     293                 :          0 :                         regex_ctrl_destroy_hw_qp(qp, i);
     294                 :          0 :                 regex_ctrl_destroy_cq(&qp->cq);
     295                 :            :         }
     296                 :            : }

Generated by: LCOV version 1.14