1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
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>
16 #include <mlx5_common.h>
17 #include <mlx5_glue.h>
18 #include <mlx5_devx_cmds.h>
20 #include <mlx5_common_os.h>
21 #include <mlx5_common_devx.h>
23 #include "mlx5_regex.h"
24 #include "mlx5_regex_utils.h"
25 #include "mlx5_rxp_csrs.h"
28 #define MLX5_REGEX_NUM_WQE_PER_PAGE (4096/64)
31 * Returns the number of qp obj to be created.
34 * The number of descriptors for the queue.
37 * The number of obj to be created.
40 regex_ctrl_get_nb_obj(uint16_t nb_desc)
42 return ((nb_desc / MLX5_REGEX_NUM_WQE_PER_PAGE) +
43 !!(nb_desc % MLX5_REGEX_NUM_WQE_PER_PAGE));
50 * Pointer to the CQ to be destroyed.
53 * 0 on success, a negative errno value otherwise and rte_errno is set.
56 regex_ctrl_destroy_cq(struct mlx5_regex_cq *cq)
58 mlx5_devx_cq_destroy(&cq->cq_obj);
59 memset(cq, 0, sizeof(*cq));
64 * create the CQ object.
67 * Pointer to the priv object.
69 * Pointer to the CQ to be created.
72 * 0 on success, a negative errno value otherwise and rte_errno is set.
75 regex_ctrl_create_cq(struct mlx5_regex_priv *priv, struct mlx5_regex_cq *cq)
77 struct mlx5_devx_cq_attr attr = {
78 .uar_page_id = priv->uar->page_id,
83 ret = mlx5_devx_cq_create(priv->ctx, &cq->cq_obj, cq->log_nb_desc,
84 &attr, SOCKET_ID_ANY);
86 DRV_LOG(ERR, "Can't create CQ object.");
87 memset(cq, 0, sizeof(*cq));
94 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
96 regex_get_pdn(void *pd, uint32_t *pdn)
98 struct mlx5dv_obj obj;
99 struct mlx5dv_pd pd_info;
103 obj.pd.out = &pd_info;
104 ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD);
106 DRV_LOG(DEBUG, "Fail to get PD object info");
115 * Destroy the SQ object.
118 * Pointer to the QP element
120 * The index of the queue.
123 * 0 on success, a negative errno value otherwise and rte_errno is set.
126 regex_ctrl_destroy_sq(struct mlx5_regex_qp *qp, uint16_t q_ind)
128 struct mlx5_regex_sq *sq = &qp->sqs[q_ind];
130 mlx5_devx_sq_destroy(&sq->sq_obj);
131 memset(sq, 0, sizeof(*sq));
136 * create the SQ object.
139 * Pointer to the priv object.
141 * Pointer to the QP element
143 * The index of the queue.
145 * Log 2 of the number of descriptors to be used.
148 * 0 on success, a negative errno value otherwise and rte_errno is set.
151 regex_ctrl_create_sq(struct mlx5_regex_priv *priv, struct mlx5_regex_qp *qp,
152 uint16_t q_ind, uint16_t log_nb_desc)
154 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
155 struct mlx5_devx_create_sq_attr attr = {
157 .cqn = qp->cq.cq_obj.cq->id,
158 .wq_attr = (struct mlx5_devx_wq_attr){
159 .uar_page = priv->uar->page_id,
162 struct mlx5_devx_modify_sq_attr modify_attr = {
163 .state = MLX5_SQC_STATE_RDY,
165 struct mlx5_regex_sq *sq = &qp->sqs[q_ind];
169 sq->log_nb_desc = log_nb_desc;
172 ret = regex_get_pdn(priv->pd, &pd_num);
175 attr.wq_attr.pd = pd_num;
176 ret = mlx5_devx_sq_create(priv->ctx, &sq->sq_obj, log_nb_desc, &attr,
179 DRV_LOG(ERR, "Can't create SQ object.");
183 ret = mlx5_devx_cmd_modify_sq(sq->sq_obj.sq, &modify_attr);
185 DRV_LOG(ERR, "Can't change SQ state to ready.");
186 regex_ctrl_destroy_sq(qp, q_ind);
196 DRV_LOG(ERR, "Cannot get pdn - no DV support.");
205 * Pointer to RegEx dev structure.
207 * The queue index to setup.
209 * The queue requested configuration.
212 * 0 on success, a negative errno value otherwise and rte_errno is set.
215 mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
216 const struct rte_regexdev_qp_conf *cfg)
218 struct mlx5_regex_priv *priv = dev->data->dev_private;
219 struct mlx5_regex_qp *qp;
221 int nb_sq_config = 0;
225 qp = &priv->qps[qp_ind];
226 qp->flags = cfg->qp_conf_flags;
227 qp->cq.log_nb_desc = rte_log2_u32(cfg->nb_desc);
228 qp->nb_desc = 1 << qp->cq.log_nb_desc;
229 if (qp->flags & RTE_REGEX_QUEUE_PAIR_CFG_OOS_F)
230 qp->nb_obj = regex_ctrl_get_nb_obj(qp->nb_desc);
233 qp->sqs = rte_malloc(NULL,
234 qp->nb_obj * sizeof(struct mlx5_regex_sq), 64);
236 DRV_LOG(ERR, "Can't allocate sq array memory.");
240 log_desc = rte_log2_u32(qp->nb_desc / qp->nb_obj);
241 ret = regex_ctrl_create_cq(priv, &qp->cq);
243 DRV_LOG(ERR, "Can't create cq.");
246 for (i = 0; i < qp->nb_obj; i++) {
247 ret = regex_ctrl_create_sq(priv, qp, i, log_desc);
249 DRV_LOG(ERR, "Can't create sq.");
255 ret = mlx5_mr_btree_init(&qp->mr_ctrl.cache_bh, MLX5_MR_BTREE_CACHE_N,
258 DRV_LOG(ERR, "Error setting up mr btree");
262 ret = mlx5_regexdev_setup_fastpath(priv, qp_ind);
264 DRV_LOG(ERR, "Error setting up fastpath");
270 mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
272 for (i = 0; i < nb_sq_config; i++)
273 regex_ctrl_destroy_sq(qp, i);
274 regex_ctrl_destroy_cq(&qp->cq);