net/ice/base: add sideband queue info
[dpdk.git] / lib / librte_vhost / vhost_user.c
index 508228a..8fec773 100644 (file)
@@ -489,6 +489,9 @@ qva_to_vva(struct virtio_net *dev, uint64_t qva, uint64_t *len)
        struct rte_vhost_mem_region *r;
        uint32_t i;
 
+       if (unlikely(!dev || !dev->mem))
+               goto out_error;
+
        /* Find the region where the address lives. */
        for (i = 0; i < dev->mem->nregions; i++) {
                r = &dev->mem->regions[i];
@@ -503,6 +506,7 @@ qva_to_vva(struct virtio_net *dev, uint64_t qva, uint64_t *len)
                               r->host_user_addr;
                }
        }
+out_error:
        *len = 0;
 
        return 0;
@@ -696,10 +700,27 @@ vhost_user_set_vring_base(struct virtio_net **pdev,
                        int main_fd __rte_unused)
 {
        struct virtio_net *dev = *pdev;
-       dev->virtqueue[msg->payload.state.index]->last_used_idx  =
-                       msg->payload.state.num;
-       dev->virtqueue[msg->payload.state.index]->last_avail_idx =
-                       msg->payload.state.num;
+       struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+       uint64_t val = msg->payload.state.num;
+
+       if (vq_is_packed(dev)) {
+               /*
+                * Bit[0:14]: avail index
+                * Bit[15]: avail wrap counter
+                */
+               vq->last_avail_idx = val & 0x7fff;
+               vq->avail_wrap_counter = !!(val & (0x1 << 15));
+               /*
+                * Set used index to same value as available one, as
+                * their values should be the same since ring processing
+                * was stopped at get time.
+                */
+               vq->last_used_idx = vq->last_avail_idx;
+               vq->used_wrap_counter = vq->avail_wrap_counter;
+       } else {
+               vq->last_used_idx = msg->payload.state.num;
+               vq->last_avail_idx = msg->payload.state.num;
+       }
 
        return VH_RESULT_OK;
 }
@@ -1208,6 +1229,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 {
        struct virtio_net *dev = *pdev;
        struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+       uint64_t val;
 
        /* We have to stop the queue (virtio) if it is running. */
        vhost_destroy_device_notify(dev);
@@ -1215,8 +1237,18 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
        dev->flags &= ~VIRTIO_DEV_READY;
        dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED;
 
-       /* Here we are safe to get the last avail index */
-       msg->payload.state.num = vq->last_avail_idx;
+       /* Here we are safe to get the indexes */
+       if (vq_is_packed(dev)) {
+               /*
+                * Bit[0:14]: avail index
+                * Bit[15]: avail wrap counter
+                */
+               val = vq->last_avail_idx & 0x7fff;
+               val |= vq->avail_wrap_counter << 15;
+               msg->payload.state.num = val;
+       } else {
+               msg->payload.state.num = vq->last_avail_idx;
+       }
 
        RTE_LOG(INFO, VHOST_CONFIG,
                "vring base idx:%d file:%d\n", msg->payload.state.index,
@@ -1704,7 +1736,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg)
        if (ret <= 0)
                return ret;
 
-       if (msg && msg->size) {
+       if (msg->size) {
                if (msg->size > sizeof(msg->payload)) {
                        RTE_LOG(ERR, VHOST_CONFIG,
                                "invalid msg size: %d\n", msg->size);
@@ -2017,11 +2049,6 @@ skip_to_reply:
                if (vdpa_dev->ops->dev_conf)
                        vdpa_dev->ops->dev_conf(dev->vid);
                dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;
-               if (vhost_user_host_notifier_ctrl(dev->vid, true) != 0) {
-                       RTE_LOG(INFO, VHOST_CONFIG,
-                               "(%d) software relay is used for vDPA, performance may be low.\n",
-                               dev->vid);
-               }
        }
 
        return 0;
@@ -2116,7 +2143,7 @@ static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
        return process_slave_message_reply(dev, &msg);
 }
 
-int vhost_user_host_notifier_ctrl(int vid, bool enable)
+int rte_vhost_host_notifier_ctrl(int vid, bool enable)
 {
        struct virtio_net *dev;
        struct rte_vdpa_device *vdpa_dev;