vhost: use new APIs to handle features
[dpdk.git] / lib / librte_vhost / vhost_user.c
index 2767cca..65fd0fc 100644 (file)
@@ -51,6 +51,9 @@
 #include "vhost.h"
 #include "vhost_user.h"
 
+#define VIRTIO_MIN_MTU 68
+#define VIRTIO_MAX_MTU 65535
+
 static const char *vhost_message_str[VHOST_USER_MAX] = {
        [VHOST_USER_NONE] = "VHOST_USER_NONE",
        [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
@@ -72,6 +75,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {
        [VHOST_USER_GET_QUEUE_NUM]  = "VHOST_USER_GET_QUEUE_NUM",
        [VHOST_USER_SET_VRING_ENABLE]  = "VHOST_USER_SET_VRING_ENABLE",
        [VHOST_USER_SEND_RARP]  = "VHOST_USER_SEND_RARP",
+       [VHOST_USER_NET_SET_MTU]  = "VHOST_USER_NET_SET_MTU",
 };
 
 static uint64_t
@@ -143,9 +147,12 @@ vhost_user_reset_owner(struct virtio_net *dev)
  * The features that we support are requested.
  */
 static uint64_t
-vhost_user_get_features(void)
+vhost_user_get_features(struct virtio_net *dev)
 {
-       return VHOST_FEATURES;
+       uint64_t features = 0;
+
+       rte_vhost_driver_get_features(dev->ifname, &features);
+       return features;
 }
 
 /*
@@ -154,7 +161,10 @@ vhost_user_get_features(void)
 static int
 vhost_user_set_features(struct virtio_net *dev, uint64_t features)
 {
-       if (features & ~VHOST_FEATURES)
+       uint64_t vhost_features = 0;
+
+       rte_vhost_driver_get_features(dev->ifname, &vhost_features);
+       if (features & ~vhost_features)
                return -1;
 
        dev->features = features;
@@ -674,14 +684,18 @@ vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg)
                close(vq->kickfd);
        vq->kickfd = file.fd;
 
-       if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-               if (dev->dequeue_zero_copy) {
-                       RTE_LOG(INFO, VHOST_CONFIG,
-                               "dequeue zero copy is enabled\n");
-               }
+       if (virtio_is_ready(dev)) {
+               dev->flags |= VIRTIO_DEV_READY;
 
-               if (notify_ops->new_device(dev->vid) == 0)
-                       dev->flags |= VIRTIO_DEV_RUNNING;
+               if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
+                       if (dev->dequeue_zero_copy) {
+                               RTE_LOG(INFO, VHOST_CONFIG,
+                                               "dequeue zero copy is enabled\n");
+                       }
+
+                       if (notify_ops->new_device(dev->vid) == 0)
+                               dev->flags |= VIRTIO_DEV_RUNNING;
+               }
        }
 }
 
@@ -716,6 +730,8 @@ vhost_user_get_vring_base(struct virtio_net *dev,
                notify_ops->destroy_device(dev->vid);
        }
 
+       dev->flags &= ~VIRTIO_DEV_READY;
+
        /* Here we are safe to get the last used index */
        state->num = vq->last_used_idx;
 
@@ -852,6 +868,22 @@ vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg)
        return 0;
 }
 
+static int
+vhost_user_net_set_mtu(struct virtio_net *dev, struct VhostUserMsg *msg)
+{
+       if (msg->payload.u64 < VIRTIO_MIN_MTU ||
+                       msg->payload.u64 > VIRTIO_MAX_MTU) {
+               RTE_LOG(ERR, VHOST_CONFIG, "Invalid MTU size (%"PRIu64")\n",
+                               msg->payload.u64);
+
+               return -1;
+       }
+
+       dev->mtu = msg->payload.u64;
+
+       return 0;
+}
+
 /* return bytes# of read on success or negative val on failure. */
 static int
 read_vhost_message(int sockfd, struct VhostUserMsg *msg)
@@ -980,7 +1012,7 @@ vhost_user_msg_handler(int vid, int fd)
 
        switch (msg.request) {
        case VHOST_USER_GET_FEATURES:
-               msg.payload.u64 = vhost_user_get_features();
+               msg.payload.u64 = vhost_user_get_features(dev);
                msg.size = sizeof(msg.payload.u64);
                send_vhost_message(fd, &msg);
                break;
@@ -1062,6 +1094,10 @@ vhost_user_msg_handler(int vid, int fd)
                vhost_user_send_rarp(dev, &msg);
                break;
 
+       case VHOST_USER_NET_SET_MTU:
+               ret = vhost_user_net_set_mtu(dev, &msg);
+               break;
+
        default:
                ret = -1;
                break;