Skip to content

Commit a997448

Browse files
Max Gurtovoymstsirkin
authored andcommitted
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: Max Gurtovoy <[email protected]> Reviewed-by: Jason Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent de91a4d commit a997448

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
431431
}
432432

433433
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
434-
dev, &ifc_vdpa_ops);
434+
dev, &ifc_vdpa_ops,
435+
IFCVF_MAX_QUEUE_PAIRS * 2);
435436
if (adapter == NULL) {
436437
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
437438
return -ENOMEM;

drivers/vdpa/vdpa.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static void vdpa_release_dev(struct device *d)
6161
* initialized but before registered.
6262
* @parent: the parent device
6363
* @config: the bus operations that is supported by this device
64+
* @nvqs: number of virtqueues supported by this device
6465
* @size: size of the parent structure that contains private data
6566
*
6667
* Driver should use vdpa_alloc_device() wrapper macro instead of
@@ -71,6 +72,7 @@ static void vdpa_release_dev(struct device *d)
7172
*/
7273
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
7374
const struct vdpa_config_ops *config,
75+
int nvqs,
7476
size_t size)
7577
{
7678
struct vdpa_device *vdev;
@@ -97,6 +99,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
9799
vdev->index = err;
98100
vdev->config = config;
99101
vdev->features_valid = false;
102+
vdev->nvqs = nvqs;
100103

101104
err = dev_set_name(&vdev->dev, "vdpa%u", vdev->index);
102105
if (err)

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
6565
/* State of each vdpasim device */
6666
struct vdpasim {
6767
struct vdpa_device vdpa;
68-
struct vdpasim_virtqueue vqs[2];
68+
struct vdpasim_virtqueue vqs[VDPASIM_VQ_NUM];
6969
struct work_struct work;
7070
/* spinlock to synchronize virtqueue state */
7171
spinlock_t lock;
@@ -352,7 +352,7 @@ static struct vdpasim *vdpasim_create(void)
352352
else
353353
ops = &vdpasim_net_config_ops;
354354

355-
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops);
355+
vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, VDPASIM_VQ_NUM);
356356
if (!vdpasim)
357357
goto err_alloc;
358358

drivers/vhost/vdpa.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ enum {
3232
(1ULL << VHOST_BACKEND_F_IOTLB_BATCH),
3333
};
3434

35-
/* Currently, only network backend w/o multiqueue is supported. */
36-
#define VHOST_VDPA_VQ_MAX 2
37-
3835
#define VHOST_VDPA_DEV_MAX (1U << MINORBITS)
3936

4037
struct vhost_vdpa {
@@ -930,7 +927,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
930927
{
931928
const struct vdpa_config_ops *ops = vdpa->config;
932929
struct vhost_vdpa *v;
933-
int minor, nvqs = VHOST_VDPA_VQ_MAX;
930+
int minor;
934931
int r;
935932

936933
/* Currently, we only accept the network devices. */
@@ -951,14 +948,14 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
951948
atomic_set(&v->opened, 0);
952949
v->minor = minor;
953950
v->vdpa = vdpa;
954-
v->nvqs = nvqs;
951+
v->nvqs = vdpa->nvqs;
955952
v->virtio_id = ops->get_device_id(vdpa);
956953

957954
device_initialize(&v->dev);
958955
v->dev.release = vhost_vdpa_release_dev;
959956
v->dev.parent = &vdpa->dev;
960957
v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
961-
v->vqs = kmalloc_array(nvqs, sizeof(struct vhost_virtqueue),
958+
v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
962959
GFP_KERNEL);
963960
if (!v->vqs) {
964961
r = -ENOMEM;

include/linux/vdpa.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct vdpa_device {
4141
const struct vdpa_config_ops *config;
4242
unsigned int index;
4343
bool features_valid;
44+
int nvqs;
4445
};
4546

4647
/**
@@ -218,11 +219,12 @@ struct vdpa_config_ops {
218219

219220
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
220221
const struct vdpa_config_ops *config,
222+
int nvqs,
221223
size_t size);
222224

223-
#define vdpa_alloc_device(dev_struct, member, parent, config) \
225+
#define vdpa_alloc_device(dev_struct, member, parent, config, nvqs) \
224226
container_of(__vdpa_alloc_device( \
225-
parent, config, \
227+
parent, config, nvqs, \
226228
sizeof(dev_struct) + \
227229
BUILD_BUG_ON_ZERO(offsetof( \
228230
dev_struct, member))), \

0 commit comments

Comments
 (0)