[v2,6/8] net/virtio: adapt Virtio-user status size
diff mbox series

Message ID 20200925123113.68916-7-maxime.coquelin@redhat.com
State Superseded
Delegated to: Maxime Coquelin
Headers show
Series
  • virtio-user: introduce vhost-vdpa backend
Related show

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Maxime Coquelin Sept. 25, 2020, 12:31 p.m. UTC
Set proper payload size for set/get status message. The payload
size varies according to backend types.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Signed-off-by: Patrick Fu <patrick.fu@intel.com>
---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 34 +++++++++++++------
 1 file changed, 23 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 0128a5fefb..5988bc92fe 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -784,11 +784,15 @@  virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status)
 	int ret;
 	uint64_t arg = status;
 
-	/* Vhost-user only for now */
-	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
+	if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER)
+		ret = dev->ops->send_request(dev,
+				VHOST_USER_SET_STATUS, &arg);
+	else if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA)
+		ret = dev->ops->send_request(dev,
+				VHOST_USER_SET_STATUS, &status);
+	else
 		return 0;
 
-	ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &arg);
 	if (ret) {
 		PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret,
 			     strerror(errno));
@@ -802,24 +806,32 @@  int
 virtio_user_update_status(struct virtio_user_dev *dev)
 {
 	uint64_t ret;
+	uint8_t status;
 	int err;
 
-	/* Vhost-user only for now */
-	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
+	if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER) {
+		err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret);
+		if (!err && ret > UINT8_MAX) {
+			PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS "
+					"response 0x%" PRIx64 "\n", ret);
+			return -1;
+		}
+
+		status = ret;
+	} else if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA) {
+		err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS,
+				&status);
+	} else {
 		return 0;
+	}
 
-	err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret);
 	if (err) {
 		PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err,
 			     strerror(errno));
 		return -1;
 	}
-	if (ret > UINT8_MAX) {
-		PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS response 0x%" PRIx64 "\n", ret);
-		return -1;
-	}
 
-	dev->status = ret;
+	dev->status = status;
 	PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n"
 			"\t-RESET: %u\n"
 			"\t-ACKNOWLEDGE: %u\n"