common/mlx5: share MR top-half search function
[dpdk.git] / drivers / regex / mlx5 / mlx5_regex.c
index f915a9d..b39181e 100644 (file)
@@ -125,18 +125,13 @@ static int
 mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
 {
        struct mlx5_regex_priv *priv = NULL;
-       struct mlx5_hca_attr attr;
+       struct mlx5_hca_attr *attr = &cdev->config.hca_attr;
        char name[RTE_REGEXDEV_NAME_MAX_LEN];
        int ret;
        uint32_t val;
 
-       ret = mlx5_devx_cmd_query_hca_attr(cdev->ctx, &attr);
-       if (ret) {
-               DRV_LOG(ERR, "Unable to read HCA capabilities.");
-               rte_errno = ENOTSUP;
-               return -rte_errno;
-       } else if (((!attr.regex) && (!attr.mmo_regex_sq_en) &&
-               (!attr.mmo_regex_qp_en)) || attr.regexp_num_of_engines == 0) {
+       if ((!attr->regex && !attr->mmo_regex_sq_en && !attr->mmo_regex_qp_en)
+           || attr->regexp_num_of_engines == 0) {
                DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe "
                        "old FW/OFED version?");
                rte_errno = ENOTSUP;
@@ -154,9 +149,8 @@ mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
                rte_errno = ENOMEM;
                return -rte_errno;
        }
-       priv->mmo_regex_qp_cap = attr.mmo_regex_qp_en;
-       priv->mmo_regex_sq_cap = attr.mmo_regex_sq_en;
-       priv->qp_ts_format = attr.qp_ts_format;
+       priv->mmo_regex_qp_cap = attr->mmo_regex_qp_en;
+       priv->mmo_regex_sq_cap = attr->mmo_regex_sq_en;
        priv->cdev = cdev;
        priv->nb_engines = 2; /* attr.regexp_num_of_engines */
        ret = mlx5_devx_regex_register_read(priv->cdev->ctx, 0,
@@ -187,17 +181,11 @@ mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
                rte_errno = ENOMEM;
                goto error;
        }
-       priv->pd = mlx5_glue->alloc_pd(priv->cdev->ctx);
-       if (!priv->pd) {
-               DRV_LOG(ERR, "can't allocate pd.");
-               rte_errno = ENOMEM;
-               goto error;
-       }
        priv->regexdev->dev_ops = &mlx5_regexdev_ops;
        priv->regexdev->enqueue = mlx5_regexdev_enqueue;
 #ifdef HAVE_MLX5_UMR_IMKEY
-       if (!attr.umr_indirect_mkey_disabled &&
-           !attr.umr_modify_entity_size_disabled)
+       if (!attr->umr_indirect_mkey_disabled &&
+           !attr->umr_modify_entity_size_disabled)
                priv->has_umr = 1;
        if (priv->has_umr)
                priv->regexdev->enqueue = mlx5_regexdev_enqueue_gga;
@@ -206,11 +194,7 @@ mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
        priv->regexdev->device = cdev->dev;
        priv->regexdev->data->dev_private = priv;
        priv->regexdev->state = RTE_REGEXDEV_READY;
-       priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr;
-       priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr;
-       ret = mlx5_mr_btree_init(&priv->mr_scache.cache,
-                                MLX5_MR_BTREE_CACHE_N * 2,
-                                rte_socket_id());
+       ret = mlx5_mr_create_cache(&priv->mr_scache, rte_socket_id());
        if (ret) {
                DRV_LOG(ERR, "MR init tree failed.");
            rte_errno = ENOMEM;
@@ -230,8 +214,6 @@ mlx5_regex_dev_probe(struct mlx5_common_device *cdev)
        return 0;
 
 error:
-       if (priv->pd)
-               mlx5_glue->dealloc_pd(priv->pd);
        if (priv->uar)
                mlx5_glue->devx_free_uar(priv->uar);
        if (priv->regexdev)
@@ -264,8 +246,6 @@ mlx5_regex_dev_remove(struct mlx5_common_device *cdev)
                                                          NULL);
                if (priv->mr_scache.cache.table)
                        mlx5_mr_release_cache(&priv->mr_scache);
-               if (priv->pd)
-                       mlx5_glue->dealloc_pd(priv->pd);
                if (priv->uar)
                        mlx5_glue->devx_free_uar(priv->uar);
                if (priv->regexdev)