]> git.droids-corp.org - dpdk.git/commitdiff
vhost: get vDPA device type
authorAndy Pei <andy.pei@intel.com>
Tue, 24 May 2022 02:48:11 +0000 (10:48 +0800)
committerMaxime Coquelin <maxime.coquelin@redhat.com>
Wed, 1 Jun 2022 09:50:10 +0000 (11:50 +0200)
Vhost backend of different devices have different features.
Add an API to get vDPA device type, net device or blk device
currently, so users can set different features for different
kinds of devices.

Signed-off-by: Andy Pei <andy.pei@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
doc/guides/prog_guide/vhost_lib.rst
doc/guides/rel_notes/release_22_07.rst
lib/vhost/rte_vhost.h
lib/vhost/socket.c
lib/vhost/vdpa_driver.h
lib/vhost/version.map

index 680da504c80b507eb27536a2db3e283be4ea92b4..cd3f6caa9ad8da04fdf7145ebe7d69fb9dee5a7b 100644 (file)
@@ -312,6 +312,11 @@ The following is an overview of some key Vhost API functions:
   Receive ``count`` packets from guest to host in async data path,
   and store them at ``pkts``.
 
+* ``rte_vhost_driver_get_vdpa_dev_type(path, type)``
+
+  Get device type of vDPA device, such as VDPA_DEVICE_TYPE_NET,
+  VDPA_DEVICE_TYPE_BLK.
+
 Vhost-user Implementations
 --------------------------
 
index e9a4603bd73b3a5cb74cb789136ea70f0f217ddb..4863b9c8326ee1e44c24550486c84904f798611b 100644 (file)
@@ -83,6 +83,10 @@ New Features
   Added vhost async dequeue API which can leverage DMA devices to
   accelerate receiving packets from guest.
 
+* **Added vhost API to get the device type of a vDPA device.**
+
+  Added an API which can get the device type of vDPA device.
+
 * **Updated Intel iavf driver.**
 
   * Added Tx QoS queue rate limitation support.
index 266048f3e53b960fc4441677101b1551453eb703..4683a5329961211ebdb4f10f0546d0549df8be35 100644 (file)
@@ -118,6 +118,9 @@ extern "C" {
 
 #define RTE_MAX_VHOST_DEVICE   1024
 
+#define RTE_VHOST_VDPA_DEVICE_TYPE_NET 0
+#define RTE_VHOST_VDPA_DEVICE_TYPE_BLK 1
+
 struct rte_vdpa_device;
 
 /**
@@ -512,6 +515,20 @@ rte_vhost_driver_detach_vdpa_device(const char *path);
 struct rte_vdpa_device *
 rte_vhost_driver_get_vdpa_device(const char *path);
 
+/**
+ * Get the device type of the vdpa device.
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @param type
+ *  the device type of the vdpa device
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type);
+
 /**
  * Set the feature bits the vhost-user driver supports.
  *
index baf6c338d3c680843a643dd96aaeeb03d84010ec..7a0f63af14df4c9a5aa9d12b02500db356a1b43b 100644 (file)
@@ -619,6 +619,50 @@ rte_vhost_driver_get_vdpa_device(const char *path)
        return dev;
 }
 
+int
+rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type)
+{
+       struct vhost_user_socket *vsocket;
+       struct rte_vdpa_device *vdpa_dev;
+       uint32_t vdpa_type = 0;
+       int ret = 0;
+
+       pthread_mutex_lock(&vhost_user.mutex);
+       vsocket = find_vhost_user_socket(path);
+       if (!vsocket) {
+               VHOST_LOG_CONFIG(ERR,
+                                "(%s) socket file is not registered yet.\n",
+                                path);
+               ret = -1;
+               goto unlock_exit;
+       }
+
+       vdpa_dev = vsocket->vdpa_dev;
+       if (!vdpa_dev) {
+               ret = -1;
+               goto unlock_exit;
+       }
+
+       if (vdpa_dev->ops->get_dev_type) {
+               ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type);
+               if (ret) {
+                       VHOST_LOG_CONFIG(ERR,
+                                        "(%s) failed to get vdpa dev type for socket file.\n",
+                                        path);
+                       ret = -1;
+                       goto unlock_exit;
+               }
+       } else {
+               vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET;
+       }
+
+       *type = vdpa_type;
+
+unlock_exit:
+       pthread_mutex_unlock(&vhost_user.mutex);
+       return ret;
+}
+
 int
 rte_vhost_driver_disable_features(const char *path, uint64_t features)
 {
index c4233a622c2edabfcb21bd7f880ae4e948543740..8b88a5360f57e8cae5a6fe4742ebea2a764133cc 100644 (file)
@@ -78,6 +78,9 @@ struct rte_vdpa_dev_ops {
        /** Set the device configuration space */
        int (*set_config)(int vid, uint8_t *config, uint32_t offset,
                      uint32_t size, uint32_t flags);
+
+       /** get device type: net device, blk device... */
+       int (*get_dev_type)(struct rte_vdpa_device *dev, uint32_t *type);
 };
 
 /**
index bc75d4d724d5139dbcacad4581bc08325f4aae61..4880b9a42219a647584a3ddeec9d5a1dc57739ec 100644 (file)
@@ -94,6 +94,7 @@ EXPERIMENTAL {
        rte_vhost_vring_stats_get;
        rte_vhost_vring_stats_reset;
        rte_vhost_async_try_dequeue_burst;
+       rte_vhost_driver_get_vdpa_dev_type;
 };
 
 INTERNAL {