> -----Original Message----- > From: Pei, Andy <andy....@intel.com> > Sent: Wednesday, April 27, 2022 4:30 PM > To: dev@dpdk.org > Cc: Xia, Chenbo <chenbo....@intel.com>; maxime.coque...@redhat.com; Cao, > Gang <gang....@intel.com>; Liu, Changpeng <changpeng....@intel.com> > Subject: [PATCH v7 07/18] vhost: add API to get vDPA device type > > Vhost backend of different devices have different features. > Add a 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....@intel.com> > --- > lib/vhost/rte_vhost.h | 17 +++++++++++++++++ > lib/vhost/socket.c | 39 +++++++++++++++++++++++++++++++++++++++ > lib/vhost/vdpa_driver.h | 3 +++ > lib/vhost/version.map | 2 ++ > 4 files changed, 61 insertions(+) > > diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h > index c733f85..c977a24 100644 > --- a/lib/vhost/rte_vhost.h > +++ b/lib/vhost/rte_vhost.h > @@ -117,6 +117,9 @@ > > #define RTE_MAX_VHOST_DEVICE 1024 > > +#define VDPA_DEVICE_TYPE_NET 0 > +#define VDPA_DEVICE_TYPE_BLK 1 > + > struct rte_vdpa_device; > > /** > @@ -486,6 +489,20 @@ 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. > * > * @param path > diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c > index b304339..7da90e8 100644 > --- a/lib/vhost/socket.c > +++ b/lib/vhost/socket.c > @@ -619,6 +619,45 @@ struct rte_vdpa_device * > } > > 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(vdpa_dev, &vdpa_type) < 0) { > + VHOST_LOG_CONFIG(ERR, > + "(%s) failed to get vdpa dev type for socket file.\n", > + path); > + ret = -1; > + goto unlock_exit; > + }
If vendor's vdpa driver does not implement this callback, should return type NET. Another way to do may be make every vdpa driver implement the callback, but since other vendors only have one type. I prefer the first way. > + > + *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) > { > struct vhost_user_socket *vsocket; > diff --git a/lib/vhost/vdpa_driver.h b/lib/vhost/vdpa_driver.h > index e59a834..9cbd7cd 100644 > --- a/lib/vhost/vdpa_driver.h > +++ b/lib/vhost/vdpa_driver.h > @@ -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); > }; > > /** > diff --git a/lib/vhost/version.map b/lib/vhost/version.map > index 0a66c58..fe4e8de 100644 > --- a/lib/vhost/version.map > +++ b/lib/vhost/version.map > @@ -87,6 +87,8 @@ EXPERIMENTAL { > > # added in 22.03 > rte_vhost_async_dma_configure; > + > + rte_vhost_driver_get_vdpa_dev_type; Missed '# added in 22.07' tag, but when you do v8, this may not be a problem as other patches may add this tag with new API introduced. And introducing new API will need update of release note. Please refer to http://git.dpdk.org/next/dpdk-next-virtio/commit/?id=868883e899af386abcc298ea80ec7f6a18d8a8e7 as an example. Thanks, Chenbo > }; > > INTERNAL { > -- > 1.8.3.1