From: Max Gurtovoy <[email protected]>

Currently only net devices can act as vDPA backends. Add an
infrastructure for block devices will basic feature list that will be
increased in the future.

Signed-off-by: Max Gurtovoy <[email protected]>
Reviewed-by: Jason Wang <[email protected]>
Signed-off-by: Stefano Garzarella <[email protected]>
---
 drivers/vhost/vdpa.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 2754f3069738..fb0411594963 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -22,6 +22,7 @@
 #include <linux/nospec.h>
 #include <linux/vhost.h>
 #include <linux/virtio_net.h>
+#include <linux/virtio_blk.h>
 
 #include "vhost.h"
 
@@ -194,6 +195,9 @@ static int vhost_vdpa_config_validate(struct vhost_vdpa *v,
        case VIRTIO_ID_NET:
                size = sizeof(struct virtio_net_config);
                break;
+       case VIRTIO_ID_BLOCK:
+               size = sizeof(struct virtio_blk_config);
+               break;
        }
 
        if (c->len == 0)
@@ -975,12 +979,13 @@ static void vhost_vdpa_release_dev(struct device *device)
 static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 {
        const struct vdpa_config_ops *ops = vdpa->config;
+       u32 device_id = ops->get_device_id(vdpa);
        struct vhost_vdpa *v;
        int minor;
        int r;
 
-       /* Currently, we only accept the network devices. */
-       if (ops->get_device_id(vdpa) != VIRTIO_ID_NET)
+       /* Currently, we only accept the network and block devices. */
+       if (device_id != VIRTIO_ID_NET && device_id != VIRTIO_ID_BLOCK)
                return -ENOTSUPP;
 
        v = kzalloc(sizeof(*v), GFP_KERNEL | __GFP_RETRY_MAYFAIL);
@@ -998,7 +1003,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
        v->minor = minor;
        v->vdpa = vdpa;
        v->nvqs = vdpa->nvqs;
-       v->virtio_id = ops->get_device_id(vdpa);
+       v->virtio_id = device_id;
 
        device_initialize(&v->dev);
        v->dev.release = vhost_vdpa_release_dev;
-- 
2.26.2

Reply via email to