From: Adrian Moreno Date: Wed, 5 Aug 2020 14:45:16 +0000 (+0200) Subject: net/virtio-user: support vhost status getting X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=0b0dc66c72774fc5de721f1ecf726f6fcb102dbe;p=dpdk.git net/virtio-user: support vhost status getting This patch adds support for VHOST_USER_GET_STATUS request. Only vhost-user backed is supported for now Signed-off-by: Adrian Moreno Reviewed-by: Chenbo Xia --- diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 337e511990..12b6c7dbcf 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -279,6 +279,7 @@ vhost_user_sock(struct virtio_user_dev *dev, switch (req) { case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: + case VHOST_USER_GET_STATUS: need_reply = 1; break; @@ -373,6 +374,7 @@ vhost_user_sock(struct virtio_user_dev *dev, switch (req) { case VHOST_USER_GET_FEATURES: + case VHOST_USER_GET_STATUS: case VHOST_USER_GET_PROTOCOL_FEATURES: if (msg.size != sizeof(m.payload.u64)) { PMD_DRV_LOG(ERR, "Received bad msg size"); diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 670fc9d40d..2a0c861085 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -807,3 +807,47 @@ virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) return 0; } + +int +virtio_user_update_status(struct virtio_user_dev *dev) +{ + uint64_t ret; + int err; + + /* Vhost-user only for now */ + if (!is_vhost_user_by_type(dev->path)) + return 0; + + if (!(dev->protocol_features & (1UL << VHOST_USER_PROTOCOL_F_STATUS))) + 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; + PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" + "\t-RESET: %u\n" + "\t-ACKNOWLEDGE: %u\n" + "\t-DRIVER: %u\n" + "\t-DRIVER_OK: %u\n" + "\t-FEATURES_OK: %u\n" + "\t-DEVICE_NEED_RESET: %u\n" + "\t-FAILED: %u\n", + dev->status, + (dev->status == VIRTIO_CONFIG_STATUS_RESET), + !!(dev->status & VIRTIO_CONFIG_STATUS_ACK), + !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER), + !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK), + !!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK), + !!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET), + !!(dev->status & VIRTIO_CONFIG_STATUS_FAILED)); + return 0; +} diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 835ab64ae4..9377d5ba66 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -73,4 +73,5 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status); +int virtio_user_update_status(struct virtio_user_dev *dev); #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 785882e062..87f6cb6950 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -280,6 +280,8 @@ virtio_user_get_status(struct virtio_hw *hw) { struct virtio_user_dev *dev = virtio_user_get_dev(hw); + virtio_user_update_status(dev); + return dev->status; }