doc: add vDPA features table
[dpdk.git] / drivers / net / ifc / ifcvf_vdpa.c
index 619cdc2..da4667b 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <fcntl.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/epoll.h>
 #include <linux/virtio_net.h>
@@ -81,6 +82,8 @@ static struct internal_list_head internal_list =
 
 static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER;
 
+static void update_used_ring(struct ifcvf_internal *internal, uint16_t qid);
+
 static struct internal_list *
 find_internal_resource_by_did(int did)
 {
@@ -133,15 +136,19 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal)
        struct rte_pci_device *dev = internal->pdev;
        char devname[RTE_DEV_NAME_MAX_LEN] = {0};
        int iommu_group_num;
-       int i;
+       int i, ret;
 
        internal->vfio_dev_fd = -1;
        internal->vfio_group_fd = -1;
        internal->vfio_container_fd = -1;
 
        rte_pci_device_name(&dev->addr, devname, RTE_DEV_NAME_MAX_LEN);
-       rte_vfio_get_group_num(rte_pci_get_sysfs_path(), devname,
+       ret = rte_vfio_get_group_num(rte_pci_get_sysfs_path(), devname,
                        &iommu_group_num);
+       if (ret <= 0) {
+               DRV_LOG(ERR, "%s failed to get IOMMU group", devname);
+               return -1;
+       }
 
        internal->vfio_container_fd = rte_vfio_container_create();
        if (internal->vfio_container_fd < 0)
@@ -302,8 +309,8 @@ vdpa_ifcvf_stop(struct ifcvf_internal *internal)
        struct ifcvf_hw *hw = &internal->hw;
        uint32_t i;
        int vid;
-       uint64_t features;
-       uint64_t log_base, log_size;
+       uint64_t features = 0;
+       uint64_t log_base = 0, log_size = 0;
        uint64_t len;
 
        vid = internal->vid;
@@ -346,6 +353,8 @@ vdpa_enable_vfio_intr(struct ifcvf_internal *internal, bool m_rx)
        struct rte_vhost_vring vring;
        int fd;
 
+       vring.callfd = -1;
+
        nr_vring = rte_vhost_get_vring_num(internal->vid);
 
        irq_set = (struct vfio_irq_set *)irq_set_buf;
@@ -440,6 +449,7 @@ notify_relay(void *arg)
        }
        internal->epfd = epfd;
 
+       vring.kickfd = -1;
        for (qid = 0; qid < q_num; qid++) {
                ev.events = EPOLLIN | EPOLLPRI;
                rte_vhost_get_vhost_vring(internal->vid, qid, &vring);
@@ -581,6 +591,7 @@ m_ifcvf_start(struct ifcvf_internal *internal)
        uint64_t size;
        uint64_t gpa;
 
+       memset(&vq, 0, sizeof(vq));
        vid = internal->vid;
        nr_vring = rte_vhost_get_vring_num(vid);
        rte_vhost_get_negotiated_features(vid, &hw->req_features);
@@ -631,6 +642,10 @@ m_ifcvf_start(struct ifcvf_internal *internal)
 
                hw->vring[i].size = vq.size;
 
+               rte_vhost_get_vring_base(vid, i,
+                               &internal->m_vring[i].avail->idx,
+                               &internal->m_vring[i].used->idx);
+
                rte_vhost_get_vring_base(vid, i, &hw->vring[i].last_avail_idx,
                                &hw->vring[i].last_used_idx);
 
@@ -662,6 +677,10 @@ m_ifcvf_stop(struct ifcvf_internal *internal)
        ifcvf_stop_hw(hw);
 
        for (i = 0; i < hw->nr_vring; i++) {
+               /* synchronize remaining new used entries if any */
+               if ((i & 1) == 0)
+                       update_used_ring(internal, i);
+
                rte_vhost_get_vhost_vring(vid, i, &vq);
                len = IFCVF_USED_RING_LEN(vq.size);
                rte_vhost_log_used_vring(vid, i, 0, len);
@@ -702,11 +721,6 @@ vring_relay(void *arg)
 
        vid = internal->vid;
        q_num = rte_vhost_get_vring_num(vid);
-       /* prepare the mediated vring */
-       for (qid = 0; qid < q_num; qid++)
-               rte_vhost_get_vring_base(vid, qid,
-                               &internal->m_vring[qid].avail->idx,
-                               &internal->m_vring[qid].used->idx);
 
        /* add notify fd and interrupt fd to epoll */
        epfd = epoll_create(IFCVF_MAX_QUEUES * 2);
@@ -716,6 +730,7 @@ vring_relay(void *arg)
        }
        internal->epfd = epfd;
 
+       vring.kickfd = -1;
        for (qid = 0; qid < q_num; qid++) {
                ev.events = EPOLLIN | EPOLLPRI;
                rte_vhost_get_vhost_vring(vid, qid, &vring);
@@ -736,6 +751,7 @@ vring_relay(void *arg)
                        DRV_LOG(ERR, "epoll add error: %s", strerror(errno));
                        return NULL;
                }
+               update_used_ring(internal, qid);
        }
 
        /* start relay with a first kick */
@@ -924,11 +940,11 @@ ifcvf_dev_close(int vid)
 static int
 ifcvf_set_features(int vid)
 {
-       uint64_t features;
+       uint64_t features = 0;
        int did;
        struct internal_list *list;
        struct ifcvf_internal *internal;
-       uint64_t log_base, log_size;
+       uint64_t log_base = 0, log_size = 0;
 
        did = rte_vhost_get_vdpa_device_id(vid);
        list = find_internal_resource_by_did(did);
@@ -1108,6 +1124,9 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       if (!pci_dev->device.devargs)
+               return 1;
+
        kvlist = rte_kvargs_parse(pci_dev->device.devargs->args,
                        ifcvf_valid_arguments);
        if (kvlist == NULL)