net/bnxt: consolidate template table processing
[dpdk.git] / drivers / net / virtio / virtio_user / virtio_user_dev.c
index ded44bf..3681758 100644 (file)
@@ -112,25 +112,11 @@ virtio_user_queue_setup(struct virtio_user_dev *dev,
 }
 
 int
-virtio_user_start_device(struct virtio_user_dev *dev)
+virtio_user_dev_set_features(struct virtio_user_dev *dev)
 {
        uint64_t features;
-       int ret;
+       int ret = -1;
 
-       /*
-        * XXX workaround!
-        *
-        * We need to make sure that the locks will be
-        * taken in the correct order to avoid deadlocks.
-        *
-        * Before releasing this lock, this thread should
-        * not trigger any memory hotplug events.
-        *
-        * This is a temporary workaround, and should be
-        * replaced when we get proper supports from the
-        * memory subsystem in the future.
-        */
-       rte_mcfg_mem_read_lock();
        pthread_mutex_lock(&dev->mutex);
 
        if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER &&
@@ -141,10 +127,8 @@ virtio_user_start_device(struct virtio_user_dev *dev)
        if (virtio_user_queue_setup(dev, virtio_user_create_queue) < 0)
                goto error;
 
-       /* Step 1: negotiate protocol features & set features */
        features = dev->features;
 
-
        /* Strip VIRTIO_NET_F_MAC, as MAC address is handled in vdev init */
        features &= ~(1ull << VIRTIO_NET_F_MAC);
        /* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */
@@ -154,6 +138,36 @@ virtio_user_start_device(struct virtio_user_dev *dev)
        if (ret < 0)
                goto error;
        PMD_DRV_LOG(INFO, "set features: %" PRIx64, features);
+error:
+       pthread_mutex_unlock(&dev->mutex);
+
+       return ret;
+}
+
+int
+virtio_user_start_device(struct virtio_user_dev *dev)
+{
+       int ret;
+
+       /*
+        * XXX workaround!
+        *
+        * We need to make sure that the locks will be
+        * taken in the correct order to avoid deadlocks.
+        *
+        * Before releasing this lock, this thread should
+        * not trigger any memory hotplug events.
+        *
+        * This is a temporary workaround, and should be
+        * replaced when we get proper supports from the
+        * memory subsystem in the future.
+        */
+       rte_mcfg_mem_read_lock();
+       pthread_mutex_lock(&dev->mutex);
+
+       if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER &&
+                       dev->vhostfd < 0)
+               goto error;
 
        /* Step 2: share memory regions */
        ret = dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL);
@@ -375,6 +389,12 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
                                dev->vhostfds[q] = -1;
                                dev->tapfds[q] = -1;
                        }
+               } else if (dev->backend_type ==
+                               VIRTIO_USER_BACKEND_VHOST_VDPA) {
+                       dev->ops = &virtio_ops_vdpa;
+               } else {
+                       PMD_DRV_LOG(ERR, "Unknown backend type");
+                       return -1;
                }
        }