[3/4] vdpa/mlx5: validate notifier configuration
diff mbox series

Message ID 1585059877-2369-4-git-send-email-asafp@mellanox.com
State New
Delegated to: Maxime Coquelin
Headers show
Series
  • vdpa/mlx5: support direct notification
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Asaf Penso March 24, 2020, 2:24 p.m. UTC
From: Matan Azrad <matan@mellanox.com>

When both, direct and indirect notifier management cannot be
configured, return an error.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

Patch
diff mbox series

diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
index 6390385..8bebb92 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
@@ -46,7 +46,7 @@ 
 	int retries = MLX5_VDPA_INTR_RETRIES;
 	int ret = -EAGAIN;
 
-	if (virtq->intr_handle.fd) {
+	if (virtq->intr_handle.fd != -1) {
 		while (retries-- && ret == -EAGAIN) {
 			ret = rte_intr_callback_unregister(&virtq->intr_handle,
 							mlx5_vdpa_virtq_handler,
@@ -59,7 +59,7 @@ 
 				usleep(MLX5_VDPA_INTR_RETRIES_USEC);
 			}
 		}
-		memset(&virtq->intr_handle, 0, sizeof(virtq->intr_handle));
+		virtq->intr_handle.fd = -1;
 	}
 	if (virtq->virtq) {
 		claim_zero(mlx5_devx_cmd_destroy(virtq->virtq));
@@ -255,15 +255,25 @@ 
 	rte_write32(virtq->index, priv->virtq_db_addr);
 	/* Setup doorbell mapping. */
 	virtq->intr_handle.fd = vq.kickfd;
-	virtq->intr_handle.type = RTE_INTR_HANDLE_EXT;
-	if (rte_intr_callback_register(&virtq->intr_handle,
-				       mlx5_vdpa_virtq_handler, virtq)) {
-		virtq->intr_handle.fd = 0;
-		DRV_LOG(ERR, "Failed to register virtq %d interrupt.", index);
-		goto error;
+	if (virtq->intr_handle.fd == -1) {
+		DRV_LOG(WARNING, "Virtq %d kickfd is invalid.", index);
+		if (!priv->direct_notifier) {
+			DRV_LOG(ERR, "Virtq %d cannot be notified.", index);
+			goto error;
+		}
 	} else {
-		DRV_LOG(DEBUG, "Register fd %d interrupt for virtq %d.",
-			virtq->intr_handle.fd, index);
+		virtq->intr_handle.type = RTE_INTR_HANDLE_EXT;
+		if (rte_intr_callback_register(&virtq->intr_handle,
+					       mlx5_vdpa_virtq_handler,
+					       virtq)) {
+			virtq->intr_handle.fd = -1;
+			DRV_LOG(ERR, "Failed to register virtq %d interrupt.",
+				index);
+			goto error;
+		} else {
+			DRV_LOG(DEBUG, "Register fd %d interrupt for virtq %d.",
+				virtq->intr_handle.fd, index);
+		}
 	}
 	return 0;
 error: