Commit a9974489 authored by Max Gurtovoy's avatar Max Gurtovoy Committed by Michael S. Tsirkin

vdpa: remove hard coded virtq num

This will enable vdpa providers to add support for multi queue feature
and publish it to upper layers (vhost and virtio).
Signed-off-by: default avatarMax Gurtovoy <maxg@mellanox.com>
Reviewed-by: default avatarJason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20200804162048.22587-7-eli@mellanox.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent de91a4d0
...@@ -431,7 +431,8 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -431,7 +431,8 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
} }
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa, adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
dev, &ifc_vdpa_ops); dev, &ifc_vdpa_ops,
IFCVF_MAX_QUEUE_PAIRS * 2);
if (adapter == NULL) { if (adapter == NULL) {
IFCVF_ERR(pdev, "Failed to allocate vDPA structure"); IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
return -ENOMEM; return -ENOMEM;
......
...@@ -61,6 +61,7 @@ static void vdpa_release_dev(struct device *d) ...@@ -61,6 +61,7 @@ static void vdpa_release_dev(struct device *d)
* initialized but before registered. * initialized but before registered.
* @parent: the parent device * @parent: the parent device
* @config: the bus operations that is supported by this device * @config: the bus operations that is supported by this device
* @nvqs: number of virtqueues supported by this device
* @size: size of the parent structure that contains private data * @size: size of the parent structure that contains private data
* *
* Driver should use vdpa_alloc_device() wrapper macro instead of * Driver should use vdpa_alloc_device() wrapper macro instead of
...@@ -71,6 +72,7 @@ static void vdpa_release_dev(struct device *d) ...@@ -71,6 +72,7 @@ static void vdpa_release_dev(struct device *d)
*/ */
struct vdpa_device *__vdpa_alloc_device(struct device *parent, struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config, const struct vdpa_config_ops *config,
int nvqs,
size_t size) size_t size)
{ {
struct vdpa_device *vdev; struct vdpa_device *vdev;
...@@ -97,6 +99,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent, ...@@ -97,6 +99,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
vdev->index = err; vdev->index = err;
vdev->config = config; vdev->config = config;
vdev->features_valid = false; vdev->features_valid = false;
vdev->nvqs = nvqs;
err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index); err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index);
if (err) if (err)
......
...@@ -65,7 +65,7 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) | ...@@ -65,7 +65,7 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
/* State of each vdpasim device */ /* State of each vdpasim device */
struct vdpasim { struct vdpasim {
struct vdpa_device vdpa; struct vdpa_device vdpa;
struct vdpasim_virtqueue vqs[2]; struct vdpasim_virtqueue vqs[VDPASIM_VQ_NUM];
struct work_struct work; struct work_struct work;
/* spinlock to synchronize virtqueue state */ /* spinlock to synchronize virtqueue state */
spinlock_t lock; spinlock_t lock;
...@@ -352,7 +352,7 @@ static struct vdpasim *vdpasim_create(void) ...@@ -352,7 +352,7 @@ static struct vdpasim *vdpasim_create(void)
else else
ops = &vdpasim_net_config_ops; ops = &vdpasim_net_config_ops;
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops); vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM);
if (!vdpasim) if (!vdpasim)
goto err_alloc; goto err_alloc;
......
...@@ -32,9 +32,6 @@ enum { ...@@ -32,9 +32,6 @@ enum {
(1ULL << VHOST_BACKEND_F_IOTLB_BATCH), (1ULL << VHOST_BACKEND_F_IOTLB_BATCH),
}; };
/* Currently, only network backend w/o multiqueue is supported. */
#define VHOST_VDPA_VQ_MAX 2
#define VHOST_VDPA_DEV_MAX (1U << MINORBITS) #define VHOST_VDPA_DEV_MAX (1U << MINORBITS)
struct vhost_vdpa { struct vhost_vdpa {
...@@ -930,7 +927,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) ...@@ -930,7 +927,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
{ {
const struct vdpa_config_ops *ops = vdpa->config; const struct vdpa_config_ops *ops = vdpa->config;
struct vhost_vdpa *v; struct vhost_vdpa *v;
int minor, nvqs = VHOST_VDPA_VQ_MAX; int minor;
int r; int r;
/* Currently, we only accept the network devices. */ /* Currently, we only accept the network devices. */
...@@ -951,14 +948,14 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa) ...@@ -951,14 +948,14 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
atomic_set(&v->opened, 0); atomic_set(&v->opened, 0);
v->minor = minor; v->minor = minor;
v->vdpa = vdpa; v->vdpa = vdpa;
v->nvqs = nvqs; v->nvqs = vdpa->nvqs;
v->virtio_id = ops->get_device_id(vdpa); v->virtio_id = ops->get_device_id(vdpa);
device_initialize(&v->dev); device_initialize(&v->dev);
v->dev.release = vhost_vdpa_release_dev; v->dev.release = vhost_vdpa_release_dev;
v->dev.parent = &vdpa->dev; v->dev.parent = &vdpa->dev;
v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor); v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
v->vqs = kmalloc_array(nvqs, sizeof(struct vhost_virtqueue), v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
GFP_KERNEL); GFP_KERNEL);
if (!v->vqs) { if (!v->vqs) {
r = -ENOMEM; r = -ENOMEM;
......
...@@ -41,6 +41,7 @@ struct vdpa_device { ...@@ -41,6 +41,7 @@ struct vdpa_device {
const struct vdpa_config_ops *config; const struct vdpa_config_ops *config;
unsigned int index; unsigned int index;
bool features_valid; bool features_valid;
int nvqs;
}; };
/** /**
...@@ -218,11 +219,12 @@ struct vdpa_config_ops { ...@@ -218,11 +219,12 @@ struct vdpa_config_ops {
struct vdpa_device *__vdpa_alloc_device(struct device *parent, struct vdpa_device *__vdpa_alloc_device(struct device *parent,
const struct vdpa_config_ops *config, const struct vdpa_config_ops *config,
int nvqs,
size_t size); size_t size);
#define vdpa_alloc_device(dev_struct, member, parent, config) \ #define vdpa_alloc_device(dev_struct, member, parent, config, nvqs) \
container_of(__vdpa_alloc_device( \ container_of(__vdpa_alloc_device( \
parent, config, \ parent, config, nvqs, \
sizeof(dev_struct) + \ sizeof(dev_struct) + \
BUILD_BUG_ON_ZERO(offsetof( \ BUILD_BUG_ON_ZERO(offsetof( \
dev_struct, member))), \ dev_struct, member))), \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment