diff mbox series

[02/10] regex/mlx5: add cleanup code

Message ID 20211022154600.2180938-2-fkelly@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series [01/10] common/mlx5: update PRM definitions for regex availability | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Francis Kelly Oct. 22, 2021, 3:45 p.m. UTC
From: Ori Kam <orika@nvidia.com>

When stopping the device we should release all
data allocated.

This commit add this cleanup logic.

Signed-off-by: Ori Kam <orika@nvidia.com>
---
 drivers/regex/mlx5/mlx5_regex.c         | 14 ++++++++++++++
 drivers/regex/mlx5/mlx5_regex.h         |  1 +
 drivers/regex/mlx5/mlx5_regex_control.c | 20 ++++++++++++++++++++
 drivers/regex/mlx5/mlx5_rxp.c           |  4 ++--
 4 files changed, 37 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/regex/mlx5/mlx5_regex.c b/drivers/regex/mlx5/mlx5_regex.c
index 2124fd15f0..b7175ff8e9 100644
--- a/drivers/regex/mlx5/mlx5_regex.c
+++ b/drivers/regex/mlx5/mlx5_regex.c
@@ -48,6 +48,20 @@  mlx5_regex_start(struct rte_regexdev *dev __rte_unused)
 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;
 }
 
diff --git a/drivers/regex/mlx5/mlx5_regex.h b/drivers/regex/mlx5/mlx5_regex.h
index 2242d250a3..329768980d 100644
--- a/drivers/regex/mlx5/mlx5_regex.h
+++ b/drivers/regex/mlx5/mlx5_regex.h
@@ -125,6 +125,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);
diff --git a/drivers/regex/mlx5/mlx5_regex_control.c b/drivers/regex/mlx5/mlx5_regex_control.c
index 572ecc6d86..1783df923c 100644
--- a/drivers/regex/mlx5/mlx5_regex_control.c
+++ b/drivers/regex/mlx5/mlx5_regex_control.c
@@ -271,3 +271,23 @@  mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
 	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];
+		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);
+	}
+}
diff --git a/drivers/regex/mlx5/mlx5_rxp.c b/drivers/regex/mlx5/mlx5_rxp.c
index 380037e24c..5afdcb35cc 100644
--- a/drivers/regex/mlx5/mlx5_rxp.c
+++ b/drivers/regex/mlx5/mlx5_rxp.c
@@ -776,10 +776,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;
 }