LCOV - code coverage report
Current view: top level - drivers/regex/mlx5 - mlx5_regex.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 6 73 8.2 %
Date: 2024-12-01 18:57:19 Functions: 2 7 28.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 36 5.6 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2020 Mellanox Technologies, Ltd
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_malloc.h>
       6                 :            : #include <rte_log.h>
       7                 :            : #include <rte_errno.h>
       8                 :            : #include <rte_pci.h>
       9                 :            : #include <rte_regexdev.h>
      10                 :            : #include <rte_regexdev_core.h>
      11                 :            : #include <rte_regexdev_driver.h>
      12                 :            : #include <bus_pci_driver.h>
      13                 :            : 
      14                 :            : #include <mlx5_common.h>
      15                 :            : #include <mlx5_common_mr.h>
      16                 :            : #include <mlx5_glue.h>
      17                 :            : #include <mlx5_devx_cmds.h>
      18                 :            : #include <mlx5_prm.h>
      19                 :            : 
      20                 :            : #include "mlx5_regex.h"
      21                 :            : #include "mlx5_regex_utils.h"
      22                 :            : 
      23                 :            : #define MLX5_REGEX_DRIVER_NAME regex_mlx5
      24                 :            : 
      25                 :            : int mlx5_regex_logtype;
      26                 :            : 
      27                 :            : const struct rte_regexdev_ops mlx5_regexdev_ops = {
      28                 :            :         .dev_info_get = mlx5_regex_info_get,
      29                 :            :         .dev_configure = mlx5_regex_configure,
      30                 :            :         .dev_db_import = mlx5_regex_rules_db_import,
      31                 :            :         .dev_qp_setup = mlx5_regex_qp_setup,
      32                 :            :         .dev_start = mlx5_regex_start,
      33                 :            :         .dev_stop = mlx5_regex_stop,
      34                 :            :         .dev_close = mlx5_regex_close,
      35                 :            : };
      36                 :            : 
      37                 :            : int
      38                 :          0 : mlx5_regex_start(struct rte_regexdev *dev)
      39                 :            : {
      40                 :          0 :         struct mlx5_regex_priv *priv = dev->data->dev_private;
      41                 :            : 
      42                 :          0 :         return mlx5_dev_mempool_subscribe(priv->cdev);
      43                 :            : }
      44                 :            : 
      45                 :            : int
      46                 :          0 : mlx5_regex_stop(struct rte_regexdev *dev __rte_unused)
      47                 :            : {
      48                 :          0 :         struct mlx5_regex_priv *priv = dev->data->dev_private;
      49                 :            : 
      50                 :          0 :         mlx5_regex_clean_ctrl(dev);
      51                 :          0 :         rte_free(priv->qps);
      52                 :          0 :         priv->qps = NULL;
      53                 :            : 
      54                 :          0 :         return 0;
      55                 :            : }
      56                 :            : 
      57                 :            : int
      58                 :          0 : mlx5_regex_close(struct rte_regexdev *dev __rte_unused)
      59                 :            : {
      60                 :          0 :         return 0;
      61                 :            : }
      62                 :            : 
      63                 :            : static void
      64                 :            : mlx5_regex_get_name(char *name, struct rte_device *dev)
      65                 :            : {
      66                 :          0 :         sprintf(name, "mlx5_regex_%s", dev->name);
      67                 :            : }
      68                 :            : 
      69                 :            : static int
      70                 :          0 : mlx5_regex_dev_probe(struct mlx5_common_device *cdev,
      71                 :            :                      struct mlx5_kvargs_ctrl *mkvlist __rte_unused)
      72                 :            : {
      73                 :            :         struct mlx5_regex_priv *priv = NULL;
      74                 :            :         struct mlx5_hca_attr *attr = &cdev->config.hca_attr;
      75                 :            :         char name[RTE_REGEXDEV_NAME_MAX_LEN];
      76                 :            :         int ret;
      77                 :            : 
      78   [ #  #  #  # ]:          0 :         if ((!attr->regexp_params && !attr->mmo_regex_sq_en && !attr->mmo_regex_qp_en)
      79         [ #  # ]:          0 :             || attr->regexp_num_of_engines == 0) {
      80                 :          0 :                 DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe "
      81                 :            :                         "old FW/OFED version?");
      82                 :          0 :                 rte_errno = ENOTSUP;
      83                 :          0 :                 return -rte_errno;
      84                 :            :         }
      85                 :          0 :         priv = rte_zmalloc("mlx5 regex device private", sizeof(*priv),
      86                 :            :                            RTE_CACHE_LINE_SIZE);
      87         [ #  # ]:          0 :         if (!priv) {
      88                 :          0 :                 DRV_LOG(ERR, "Failed to allocate private memory.");
      89                 :          0 :                 rte_errno = ENOMEM;
      90                 :          0 :                 return -rte_errno;
      91                 :            :         }
      92                 :          0 :         priv->mmo_regex_qp_cap = attr->mmo_regex_qp_en;
      93                 :          0 :         priv->mmo_regex_sq_cap = attr->mmo_regex_sq_en;
      94                 :          0 :         priv->cdev = cdev;
      95                 :          0 :         priv->nb_engines = 2; /* attr.regexp_num_of_engines */
      96         [ #  # ]:          0 :         if (attr->regexp_version == MLX5_RXP_BF2_IDENTIFIER)
      97                 :          0 :                 priv->is_bf2 = 1;
      98                 :            :         /* Default RXP programming mode to Shared. */
      99                 :          0 :         priv->prog_mode = MLX5_RXP_SHARED_PROG_MODE;
     100                 :          0 :         mlx5_regex_get_name(name, cdev->dev);
     101                 :          0 :         priv->regexdev = rte_regexdev_register(name);
     102         [ #  # ]:          0 :         if (priv->regexdev == NULL) {
     103                 :          0 :                 DRV_LOG(ERR, "Failed to register RegEx device.");
     104         [ #  # ]:          0 :                 rte_errno = rte_errno ? rte_errno : EINVAL;
     105                 :          0 :                 goto dev_error;
     106                 :            :         }
     107                 :          0 :         ret = mlx5_devx_uar_prepare(cdev, &priv->uar);
     108         [ #  # ]:          0 :         if (ret)
     109                 :          0 :                 goto error;
     110                 :          0 :         priv->regexdev->dev_ops = &mlx5_regexdev_ops;
     111                 :          0 :         priv->regexdev->enqueue = mlx5_regexdev_enqueue;
     112                 :            : #ifdef HAVE_MLX5_UMR_IMKEY
     113         [ #  # ]:          0 :         if (!attr->umr_indirect_mkey_disabled &&
     114         [ #  # ]:          0 :             !attr->umr_modify_entity_size_disabled)
     115                 :          0 :                 priv->has_umr = 1;
     116         [ #  # ]:          0 :         if (priv->has_umr)
     117                 :          0 :                 priv->regexdev->enqueue = mlx5_regexdev_enqueue_gga;
     118                 :            : #endif
     119                 :          0 :         priv->regexdev->dequeue = mlx5_regexdev_dequeue;
     120                 :          0 :         priv->regexdev->device = cdev->dev;
     121                 :          0 :         priv->regexdev->data->dev_private = priv;
     122                 :          0 :         priv->regexdev->state = RTE_REGEXDEV_READY;
     123         [ #  # ]:          0 :         DRV_LOG(INFO, "RegEx GGA is %s.",
     124                 :            :                 priv->has_umr ? "supported" : "unsupported");
     125                 :          0 :         return 0;
     126                 :            : 
     127                 :            : error:
     128         [ #  # ]:          0 :         if (priv->regexdev)
     129                 :          0 :                 rte_regexdev_unregister(priv->regexdev);
     130                 :          0 : dev_error:
     131                 :          0 :         rte_free(priv);
     132                 :          0 :         return -rte_errno;
     133                 :            : }
     134                 :            : 
     135                 :            : static int
     136                 :          0 : mlx5_regex_dev_remove(struct mlx5_common_device *cdev)
     137                 :            : {
     138                 :            :         char name[RTE_REGEXDEV_NAME_MAX_LEN];
     139                 :            :         struct rte_regexdev *dev;
     140                 :            :         struct mlx5_regex_priv *priv = NULL;
     141                 :            : 
     142                 :          0 :         mlx5_regex_get_name(name, cdev->dev);
     143                 :          0 :         dev = rte_regexdev_get_device_by_name(name);
     144         [ #  # ]:          0 :         if (!dev)
     145                 :            :                 return 0;
     146                 :          0 :         priv = dev->data->dev_private;
     147         [ #  # ]:          0 :         if (priv) {
     148                 :          0 :                 mlx5_devx_uar_release(&priv->uar);
     149         [ #  # ]:          0 :                 if (priv->regexdev)
     150                 :          0 :                         rte_regexdev_unregister(priv->regexdev);
     151                 :          0 :                 rte_free(priv);
     152                 :            :         }
     153                 :            :         return 0;
     154                 :            : }
     155                 :            : 
     156                 :            : static const struct rte_pci_id mlx5_regex_pci_id_map[] = {
     157                 :            :         {
     158                 :            :                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
     159                 :            :                                 PCI_DEVICE_ID_MELLANOX_BLUEFIELD2)
     160                 :            :         },
     161                 :            :         {
     162                 :            :                 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
     163                 :            :                                 PCI_DEVICE_ID_MELLANOX_BLUEFIELD3)
     164                 :            :         },
     165                 :            :         {
     166                 :            :                 .vendor_id = 0
     167                 :            :         }
     168                 :            : };
     169                 :            : 
     170                 :            : static struct mlx5_class_driver mlx5_regex_driver = {
     171                 :            :         .drv_class = MLX5_CLASS_REGEX,
     172                 :            :         .name = RTE_STR(MLX5_REGEX_DRIVER_NAME),
     173                 :            :         .id_table = mlx5_regex_pci_id_map,
     174                 :            :         .probe = mlx5_regex_dev_probe,
     175                 :            :         .remove = mlx5_regex_dev_remove,
     176                 :            : };
     177                 :            : 
     178                 :        251 : RTE_INIT(rte_mlx5_regex_init)
     179                 :            : {
     180                 :        251 :         mlx5_common_init();
     181         [ +  - ]:        251 :         if (mlx5_glue)
     182                 :        251 :                 mlx5_class_driver_register(&mlx5_regex_driver);
     183                 :        251 : }
     184                 :            : 
     185         [ -  + ]:        251 : RTE_LOG_REGISTER_DEFAULT(mlx5_regex_logtype, NOTICE)
     186                 :            : RTE_PMD_EXPORT_NAME(MLX5_REGEX_DRIVER_NAME, __COUNTER__);
     187                 :            : RTE_PMD_REGISTER_PCI_TABLE(MLX5_REGEX_DRIVER_NAME, mlx5_regex_pci_id_map);
     188                 :            : RTE_PMD_REGISTER_KMOD_DEP(MLX5_REGEX_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");

Generated by: LCOV version 1.14