1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
9 #include <rte_malloc.h>
10 #include <rte_regexdev.h>
11 #include <rte_regexdev_core.h>
12 #include <rte_regexdev_driver.h>
14 #include <mlx5_common.h>
15 #include <mlx5_glue.h>
16 #include <mlx5_devx_cmds.h>
18 #include <mlx5_common_os.h>
20 #include "mlx5_regex.h"
21 #include "mlx5_regex_utils.h"
22 #include "mlx5_rxp_csrs.h"
25 #define MLX5_REGEX_NUM_WQE_PER_PAGE (4096/64)
28 * Returns the number of qp obj to be created.
31 * The number of descriptors for the queue.
34 * The number of obj to be created.
37 regex_ctrl_get_nb_obj(uint16_t nb_desc)
39 return ((nb_desc / MLX5_REGEX_NUM_WQE_PER_PAGE) +
40 !!(nb_desc % MLX5_REGEX_NUM_WQE_PER_PAGE));
47 * Pointer to the priv object.
49 * Pointer to the CQ to be destroyed.
52 * 0 on success, a negative errno value otherwise and rte_errno is set.
55 regex_ctrl_destroy_cq(struct mlx5_regex_priv *priv, struct mlx5_regex_cq *cq)
58 mlx5_glue->devx_umem_dereg(cq->cqe_umem);
62 rte_free((void *)(uintptr_t)cq->cqe);
66 mlx5_release_dbr(&priv->dbrpgs, cq->dbr_umem, cq->dbr_offset);
70 mlx5_devx_cmd_destroy(cq->obj);
77 * create the CQ object.
80 * Pointer to the priv object.
82 * Pointer to the CQ to be created.
85 * 0 on success, a negative errno value otherwise and rte_errno is set.
88 regex_ctrl_create_cq(struct mlx5_regex_priv *priv, struct mlx5_regex_cq *cq)
90 struct mlx5_devx_cq_attr attr = {
95 struct mlx5_devx_dbr_page *dbr_page = NULL;
97 size_t pgsize = sysconf(_SC_PAGESIZE);
98 uint32_t cq_size = 1 << cq->log_nb_desc;
101 cq->dbr_offset = mlx5_get_dbr(priv->ctx, &priv->dbrpgs, &dbr_page);
102 if (cq->dbr_offset < 0) {
103 DRV_LOG(ERR, "Can't allocate cq door bell record.");
107 cq->dbr_umem = mlx5_os_get_umem_id(dbr_page->umem);
108 buf = rte_calloc(NULL, 1, sizeof(struct mlx5_cqe) * cq_size, 4096);
110 DRV_LOG(ERR, "Can't allocate cqe buffer.");
115 for (i = 0; i < cq_size; i++)
116 cq->cqe[i].op_own = 0xff;
117 cq->cqe_umem = mlx5_glue->devx_umem_reg(priv->ctx, buf,
118 sizeof(struct mlx5_cqe) *
121 DRV_LOG(ERR, "Can't register cqe mem.");
125 attr.db_umem_offset = cq->dbr_offset;
126 attr.db_umem_id = cq->dbr_umem;
127 attr.q_umem_id = mlx5_os_get_umem_id(cq->cqe_umem);
128 attr.log_cq_size = cq->log_nb_desc;
129 attr.uar_page_id = priv->uar->page_id;
130 attr.log_page_size = rte_log2_u32(pgsize);
131 cq->obj = mlx5_devx_cmd_create_cq(priv->ctx, &attr);
133 DRV_LOG(ERR, "Can't create cq object.");
140 mlx5_glue->devx_umem_dereg(cq->cqe_umem);
144 mlx5_release_dbr(&priv->dbrpgs, cq->dbr_umem, cq->dbr_offset);
152 * Pointer to RegEx dev structure.
154 * The queue index to setup.
156 * The queue requested configuration.
159 * 0 on success, a negative errno value otherwise and rte_errno is set.
162 mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
163 const struct rte_regexdev_qp_conf *cfg)
165 struct mlx5_regex_priv *priv = dev->data->dev_private;
166 struct mlx5_regex_qp *qp;
169 qp = &priv->qps[qp_ind];
170 qp->flags = cfg->qp_conf_flags;
171 qp->cq.log_nb_desc = rte_log2_u32(cfg->nb_desc);
172 qp->nb_desc = 1 << qp->cq.log_nb_desc;
173 if (qp->flags & RTE_REGEX_QUEUE_PAIR_CFG_OOS_F)
174 qp->nb_obj = regex_ctrl_get_nb_obj(qp->nb_desc);
177 qp->sqs = rte_malloc(NULL,
178 qp->nb_obj * sizeof(struct mlx5_regex_sq), 64);
180 DRV_LOG(ERR, "Can't allocate sq array memory.");
184 ret = regex_ctrl_create_cq(priv, &qp->cq);
186 DRV_LOG(ERR, "Can't create cq.");
192 regex_ctrl_destroy_cq(priv, &qp->cq);