regex/mlx5: add cleanup on stop

When stopping the device we should release all
data allocated.

After rte_regexdev_configure(), the QPs are pre-allocated,
and will be configured only in rte_regexdev_queue_pair_setup().
That's why the QP jobs array initialization is checked
before attempting to destroy the QP.

Signed-off-by: Ori Kam <orika@nvidia.com>
Signed-off-by: Ady Agbarih <adypodoman@gmail.com>
This commit is contained in:
Ori Kam 2021-10-22 15:45:52 +00:00 committed by Thomas Monjalon
parent 2044860ebd
commit fe37533668
5 changed files with 44 additions and 5 deletions

View File

@ -46,6 +46,20 @@ mlx5_regex_start(struct rte_regexdev *dev)
int
mlx5_regex_stop(struct rte_regexdev *dev __rte_unused)
{
struct mlx5_regex_priv *priv = dev->data->dev_private;
uint32_t i;
mlx5_regex_clean_ctrl(dev);
rte_free(priv->qps);
priv->qps = NULL;
for (i = 0; i < (priv->nb_engines + MLX5_RXP_EM_COUNT); i++) {
if (priv->db[i].umem.umem)
mlx5_glue->devx_umem_dereg(priv->db[i].umem.umem);
rte_free(priv->db[i].ptr);
priv->db[i].ptr = NULL;
}
return 0;
}

View File

@ -100,6 +100,7 @@ int mlx5_devx_regex_database_program(void *ctx, uint8_t engine,
/* mlx5_regex_control.c */
int mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
const struct rte_regexdev_qp_conf *cfg);
void mlx5_regex_clean_ctrl(struct rte_regexdev *dev);
/* mlx5_regex_fastpath.c */
int mlx5_regexdev_setup_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id);

View File

@ -266,3 +266,26 @@ err_cq:
rte_free(qp->qps);
return ret;
}
void
mlx5_regex_clean_ctrl(struct rte_regexdev *dev)
{
struct mlx5_regex_priv *priv = dev->data->dev_private;
struct mlx5_regex_qp *qp;
int qp_ind;
int i;
if (!priv->qps)
return;
for (qp_ind = 0; qp_ind < priv->nb_queues; qp_ind++) {
qp = &priv->qps[qp_ind];
/* Check if mlx5_regex_qp_setup() was called for this QP */
if (!qp->jobs)
continue;
mlx5_regexdev_teardown_fastpath(priv, qp_ind);
mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
for (i = 0; i < qp->nb_obj; i++)
regex_ctrl_destroy_hw_qp(qp, i);
regex_ctrl_destroy_cq(&qp->cq);
}
}

View File

@ -727,6 +727,7 @@ mlx5_regexdev_setup_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id)
err = setup_buffers(priv, qp);
if (err) {
rte_free(qp->jobs);
qp->jobs = NULL;
return err;
}
@ -774,14 +775,14 @@ mlx5_regexdev_teardown_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id)
struct mlx5_regex_qp *qp = &priv->qps[qp_id];
uint32_t i;
if (qp) {
if (qp->jobs) {
for (i = 0; i < qp->nb_desc; i++) {
if (qp->jobs[i].imkey)
claim_zero(mlx5_devx_cmd_destroy
(qp->jobs[i].imkey));
}
free_buffers(qp);
if (qp->jobs)
rte_free(qp->jobs);
rte_free(qp->jobs);
qp->jobs = NULL;
}
}

View File

@ -774,10 +774,10 @@ rxp_db_setup(struct mlx5_regex_priv *priv)
return 0;
tidyup_error:
for (i = 0; i < (priv->nb_engines + MLX5_RXP_EM_COUNT); i++) {
if (priv->db[i].ptr)
rte_free(priv->db[i].ptr);
if (priv->db[i].umem.umem)
mlx5_glue->devx_umem_dereg(priv->db[i].umem.umem);
rte_free(priv->db[i].ptr);
priv->db[i].ptr = NULL;
}
return -ret;
}