net/virtio: adapt virtio-user status size
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Tue, 29 Sep 2020 16:14:02 +0000 (18:14 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 30 Sep 2020 21:16:56 +0000 (23:16 +0200)
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>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
drivers/net/virtio/virtio_user/virtio_user_dev.c

index d7cd6b0..ded44bf 100644 (file)
@@ -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"