New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / vhost / rte_eth_vhost.c
index 257bf6d..2536ee4 100644 (file)
@@ -39,7 +39,7 @@
 #include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
-#include <rte_vdev.h>
+#include <rte_bus_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_vhost.h>
 #include <rte_spinlock.h>
@@ -52,6 +52,7 @@ enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
 #define ETH_VHOST_QUEUES_ARG           "queues"
 #define ETH_VHOST_CLIENT_ARG           "client"
 #define ETH_VHOST_DEQUEUE_ZERO_COPY    "dequeue-zero-copy"
+#define ETH_VHOST_IOMMU_SUPPORT                "iommu-support"
 #define VHOST_MAX_PKT_BURST 32
 
 static const char *valid_arguments[] = {
@@ -59,6 +60,7 @@ static const char *valid_arguments[] = {
        ETH_VHOST_QUEUES_ARG,
        ETH_VHOST_CLIENT_ARG,
        ETH_VHOST_DEQUEUE_ZERO_COPY,
+       ETH_VHOST_IOMMU_SUPPORT,
        NULL
 };
 
@@ -105,7 +107,7 @@ struct vhost_queue {
        rte_atomic32_t while_queuing;
        struct pmd_internal *internal;
        struct rte_mempool *mb_pool;
-       uint8_t port;
+       uint16_t port;
        uint16_t virtqueue_id;
        struct vhost_stats stats;
 };
@@ -607,7 +609,8 @@ new_device(int vid)
 
        RTE_LOG(INFO, PMD, "New connection established\n");
 
-       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC,
+                                     NULL, NULL);
 
        return 0;
 }
@@ -661,7 +664,8 @@ destroy_device(int vid)
 
        RTE_LOG(INFO, PMD, "Connection closed\n");
 
-       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC,
+                                     NULL, NULL);
 }
 
 static int
@@ -690,7 +694,8 @@ vring_state_changed(int vid, uint16_t vring, int enable)
        RTE_LOG(INFO, PMD, "vring%u is %s\n",
                        vring, enable ? "enabled" : "disabled");
 
-       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_QUEUE_STATE, NULL);
+       _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_QUEUE_STATE,
+                                     NULL, NULL);
 
        return 0;
 }
@@ -702,7 +707,7 @@ static struct vhost_device_ops vhost_ops = {
 };
 
 int
-rte_eth_vhost_get_queue_event(uint8_t port_id,
+rte_eth_vhost_get_queue_event(uint16_t port_id,
                struct rte_eth_vhost_queue_event *event)
 {
        struct rte_vhost_vring_state *state;
@@ -739,7 +744,7 @@ rte_eth_vhost_get_queue_event(uint8_t port_id,
 }
 
 int
-rte_eth_vhost_get_vid_from_port_id(uint8_t port_id)
+rte_eth_vhost_get_vid_from_port_id(uint16_t port_id)
 {
        struct internal_list *list;
        struct rte_eth_dev *eth_dev;
@@ -887,7 +892,7 @@ eth_dev_info(struct rte_eth_dev *dev,
        dev_info->min_rx_bufsize = 0;
 }
 
-static void
+static int
 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
        unsigned i;
@@ -925,6 +930,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
        stats->oerrors = tx_missed_total;
        stats->ibytes = rx_total_bytes;
        stats->obytes = tx_total_bytes;
+
+       return 0;
 }
 
 static void
@@ -973,6 +980,18 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
        return 0;
 }
 
+static uint32_t
+eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+       struct vhost_queue *vq;
+
+       vq = dev->data->rx_queues[rx_queue_id];
+       if (vq == NULL)
+               return 0;
+
+       return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
+}
+
 static const struct eth_dev_ops ops = {
        .dev_start = eth_dev_start,
        .dev_stop = eth_dev_stop,
@@ -984,6 +1003,7 @@ static const struct eth_dev_ops ops = {
        .rx_queue_release = eth_queue_release,
        .tx_queue_release = eth_queue_release,
        .tx_done_cleanup = eth_tx_done_cleanup,
+       .rx_queue_count = eth_rx_queue_count,
        .link_update = eth_link_update,
        .stats_get = eth_stats_get,
        .stats_reset = eth_stats_reset,
@@ -1068,8 +1088,7 @@ eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name,
        internal->max_queues = queues;
        data->dev_link = pmd_link;
        data->mac_addrs = eth_addr;
-       data->dev_flags =
-               RTE_ETH_DEV_DETACHABLE | RTE_ETH_DEV_INTR_LSC;
+       data->dev_flags = RTE_ETH_DEV_INTR_LSC;
 
        eth_dev->dev_ops = &ops;
 
@@ -1147,6 +1166,7 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
        uint64_t flags = 0;
        int client_mode = 0;
        int dequeue_zero_copy = 0;
+       int iommu_support = 0;
 
        RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n",
                rte_vdev_device_name(dev));
@@ -1194,6 +1214,16 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
                        flags |= RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
        }
 
+       if (rte_kvargs_count(kvlist, ETH_VHOST_IOMMU_SUPPORT) == 1) {
+               ret = rte_kvargs_process(kvlist, ETH_VHOST_IOMMU_SUPPORT,
+                                        &open_int, &iommu_support);
+               if (ret < 0)
+                       goto out_free;
+
+               if (iommu_support)
+                       flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
+       }
+
        if (dev->device.numa_node == SOCKET_ID_ANY)
                dev->device.numa_node = rte_socket_id();