net/i40e: fix logging for Tx free threshold check
[dpdk.git] / lib / librte_vhost / vhost.c
index 30bb0ce..e415093 100644 (file)
@@ -121,9 +121,18 @@ static void
 free_device(struct virtio_net *dev)
 {
        uint32_t i;
+       struct vhost_virtqueue *rxq, *txq;
 
-       for (i = 0; i < dev->virt_qp_nb; i++)
-               rte_free(dev->virtqueue[i * VIRTIO_QNUM]);
+       for (i = 0; i < dev->virt_qp_nb; i++) {
+               rxq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ];
+               txq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ];
+
+               rte_free(rxq->shadow_used_ring);
+               rte_free(txq->shadow_used_ring);
+
+               /* rxq and txq are allocated together as queue-pair */
+               rte_free(rxq);
+       }
 
        rte_free(dev);
 }
@@ -142,6 +151,8 @@ init_vring_queue(struct vhost_virtqueue *vq, int qp_idx)
        /* always set the default vq pair to enabled */
        if (qp_idx == 0)
                vq->enabled = 1;
+
+       TAILQ_INIT(&vq->zmbuf_list);
 }
 
 static void
@@ -216,9 +227,8 @@ reset_device(struct virtio_net *dev)
 }
 
 /*
- * Function is called from the CUSE open function. The device structure is
- * initialised and a new entry is added to the device configuration linked
- * list.
+ * Invoked when there is a new vhost-user connection established (when
+ * there is a new virtio device being attached).
  */
 int
 vhost_new_device(void)
@@ -240,6 +250,7 @@ vhost_new_device(void)
        if (i == MAX_VHOST_DEVICE) {
                RTE_LOG(ERR, VHOST_CONFIG,
                        "Failed to find a free slot for new device.\n");
+               rte_free(dev);
                return -1;
        }
 
@@ -250,8 +261,8 @@ vhost_new_device(void)
 }
 
 /*
- * Function is called from the CUSE release function. This function will
- * cleanup the device and remove it from device configuration linked list.
+ * Invoked when there is the vhost-user connection is broken (when
+ * the virtio device is being detached).
  */
 void
 vhost_destroy_device(int vid)
@@ -289,6 +300,16 @@ vhost_set_ifname(int vid, const char *if_name, unsigned int if_len)
        dev->ifname[sizeof(dev->ifname) - 1] = '\0';
 }
 
+void
+vhost_enable_dequeue_zero_copy(int vid)
+{
+       struct virtio_net *dev = get_device(vid);
+
+       if (dev == NULL)
+               return;
+
+       dev->dequeue_zero_copy = 1;
+}
 
 int
 rte_vhost_get_numa_node(int vid)