[v2,12/13] vdpa/mlx5: support close and config operations

Message ID 1580292549-27439-13-git-send-email-matan@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Introduce mlx5 vDPA driver |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Matan Azrad Jan. 29, 2020, 10:09 a.m. UTC
Support dev_conf and dev_conf operations.
These operations allow vdpa traffic.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/vdpa/mlx5/mlx5_vdpa.c | 58 ++++++++++++++++++++++++++++++++++++++++---
 drivers/vdpa/mlx5/mlx5_vdpa.h |  1 +
 2 files changed, 55 insertions(+), 4 deletions(-)
  

Comments

Maxime Coquelin Jan. 31, 2020, 4:06 p.m. UTC | #1
On 1/29/20 11:09 AM, Matan Azrad wrote:
> Support dev_conf and dev_conf operations.
> These operations allow vdpa traffic.
> 
> Signed-off-by: Matan Azrad <matan@mellanox.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> ---
>  drivers/vdpa/mlx5/mlx5_vdpa.c | 58 ++++++++++++++++++++++++++++++++++++++++---
>  drivers/vdpa/mlx5/mlx5_vdpa.h |  1 +
>  2 files changed, 55 insertions(+), 4 deletions(-)
> 

Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c
index 4ce0ba0..c8ef3b4 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa.c
@@ -167,12 +167,59 @@ 
 	return 0;
 }
 
+static int
+mlx5_vdpa_dev_close(int vid)
+{
+	int did = rte_vhost_get_vdpa_device_id(vid);
+	struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+	int ret = 0;
+
+	if (priv == NULL) {
+		DRV_LOG(ERR, "Invalid device id: %d.", did);
+		return -1;
+	}
+	if (priv->configured)
+		ret |= mlx5_vdpa_lm_log(priv);
+	mlx5_vdpa_cqe_event_unset(priv);
+	ret |= mlx5_vdpa_steer_unset(priv);
+	mlx5_vdpa_virtqs_release(priv);
+	mlx5_vdpa_event_qp_global_release(priv);
+	mlx5_vdpa_mem_dereg(priv);
+	priv->configured = 0;
+	priv->vid = 0;
+	return ret;
+}
+
+static int
+mlx5_vdpa_dev_config(int vid)
+{
+	int did = rte_vhost_get_vdpa_device_id(vid);
+	struct mlx5_vdpa_priv *priv = mlx5_vdpa_find_priv_resource_by_did(did);
+
+	if (priv == NULL) {
+		DRV_LOG(ERR, "Invalid device id: %d.", did);
+		return -EINVAL;
+	}
+	if (priv->configured && mlx5_vdpa_dev_close(vid)) {
+		DRV_LOG(ERR, "Failed to reconfigure vid %d.", vid);
+		return -1;
+	}
+	priv->vid = vid;
+	if (mlx5_vdpa_mem_register(priv) || mlx5_vdpa_virtqs_prepare(priv) ||
+	    mlx5_vdpa_steer_setup(priv) || mlx5_vdpa_cqe_event_setup(priv)) {
+		mlx5_vdpa_dev_close(vid);
+		return -1;
+	}
+	priv->configured = 1;
+	return 0;
+}
+
 static struct rte_vdpa_dev_ops mlx5_vdpa_ops = {
 	.get_queue_num = mlx5_vdpa_get_queue_num,
 	.get_features = mlx5_vdpa_get_vdpa_features,
 	.get_protocol_features = mlx5_vdpa_get_protocol_features,
-	.dev_conf = NULL,
-	.dev_close = NULL,
+	.dev_conf = mlx5_vdpa_dev_config,
+	.dev_close = mlx5_vdpa_dev_close,
 	.set_vring_state = mlx5_vdpa_set_vring_state,
 	.set_features = mlx5_vdpa_features_set,
 	.migration_done = NULL,
@@ -320,12 +367,15 @@ 
 			break;
 		}
 	}
-	if (found) {
+	if (found)
 		TAILQ_REMOVE(&priv_list, priv, next);
+	pthread_mutex_unlock(&priv_list_lock);
+	if (found) {
+		if (priv->configured)
+			mlx5_vdpa_dev_close(priv->vid);
 		mlx5_glue->close_device(priv->ctx);
 		rte_free(priv);
 	}
-	pthread_mutex_unlock(&priv_list_lock);
 	return 0;
 }
 
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h
index 70264e4..75e96d6 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa.h
+++ b/drivers/vdpa/mlx5/mlx5_vdpa.h
@@ -92,6 +92,7 @@  struct mlx5_vdpa_steer {
 
 struct mlx5_vdpa_priv {
 	TAILQ_ENTRY(mlx5_vdpa_priv) next;
+	uint8_t configured;
 	int id; /* vDPA device id. */
 	int vid; /* vhost device id. */
 	struct ibv_context *ctx; /* Device context. */