virtio_pci: support the arg sizes of find_vqs()
Virtio PCI supports new parameter sizes of find_vqs(). Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Message-Id: <20220801063902.129329-35-xuanzhuo@linux.alibaba.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
a10fba0377
commit
cdb44806fc
4 changed files with 23 additions and 12 deletions
|
@ -174,6 +174,7 @@ error:
|
||||||
static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int index,
|
static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int index,
|
||||||
void (*callback)(struct virtqueue *vq),
|
void (*callback)(struct virtqueue *vq),
|
||||||
const char *name,
|
const char *name,
|
||||||
|
u32 size,
|
||||||
bool ctx,
|
bool ctx,
|
||||||
u16 msix_vec)
|
u16 msix_vec)
|
||||||
{
|
{
|
||||||
|
@ -186,7 +187,7 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int in
|
||||||
if (!info)
|
if (!info)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
vq = vp_dev->setup_vq(vp_dev, info, index, callback, name, ctx,
|
vq = vp_dev->setup_vq(vp_dev, info, index, callback, name, size, ctx,
|
||||||
msix_vec);
|
msix_vec);
|
||||||
if (IS_ERR(vq))
|
if (IS_ERR(vq))
|
||||||
goto out_info;
|
goto out_info;
|
||||||
|
@ -283,7 +284,7 @@ void vp_del_vqs(struct virtio_device *vdev)
|
||||||
|
|
||||||
static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
|
static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
|
||||||
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
||||||
const char * const names[], bool per_vq_vectors,
|
const char * const names[], u32 sizes[], bool per_vq_vectors,
|
||||||
const bool *ctx,
|
const bool *ctx,
|
||||||
struct irq_affinity *desc)
|
struct irq_affinity *desc)
|
||||||
{
|
{
|
||||||
|
@ -326,8 +327,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
|
||||||
else
|
else
|
||||||
msix_vec = VP_MSIX_VQ_VECTOR;
|
msix_vec = VP_MSIX_VQ_VECTOR;
|
||||||
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
|
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
|
||||||
ctx ? ctx[i] : false,
|
sizes ? sizes[i] : 0,
|
||||||
msix_vec);
|
ctx ? ctx[i] : false, msix_vec);
|
||||||
if (IS_ERR(vqs[i])) {
|
if (IS_ERR(vqs[i])) {
|
||||||
err = PTR_ERR(vqs[i]);
|
err = PTR_ERR(vqs[i]);
|
||||||
goto error_find;
|
goto error_find;
|
||||||
|
@ -357,7 +358,7 @@ error_find:
|
||||||
|
|
||||||
static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
|
static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
|
||||||
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
struct virtqueue *vqs[], vq_callback_t *callbacks[],
|
||||||
const char * const names[], const bool *ctx)
|
const char * const names[], u32 sizes[], const bool *ctx)
|
||||||
{
|
{
|
||||||
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
|
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
|
||||||
int i, err, queue_idx = 0;
|
int i, err, queue_idx = 0;
|
||||||
|
@ -379,6 +380,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
|
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
|
||||||
|
sizes ? sizes[i] : 0,
|
||||||
ctx ? ctx[i] : false,
|
ctx ? ctx[i] : false,
|
||||||
VIRTIO_MSI_NO_VECTOR);
|
VIRTIO_MSI_NO_VECTOR);
|
||||||
if (IS_ERR(vqs[i])) {
|
if (IS_ERR(vqs[i])) {
|
||||||
|
@ -402,15 +404,15 @@ int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* Try MSI-X with one vector per queue. */
|
/* Try MSI-X with one vector per queue. */
|
||||||
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, true, ctx, desc);
|
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, sizes, true, ctx, desc);
|
||||||
if (!err)
|
if (!err)
|
||||||
return 0;
|
return 0;
|
||||||
/* Fallback: MSI-X with one vector for config, one shared for queues. */
|
/* Fallback: MSI-X with one vector for config, one shared for queues. */
|
||||||
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, false, ctx, desc);
|
err = vp_find_vqs_msix(vdev, nvqs, vqs, callbacks, names, sizes, false, ctx, desc);
|
||||||
if (!err)
|
if (!err)
|
||||||
return 0;
|
return 0;
|
||||||
/* Finally fall back to regular interrupts. */
|
/* Finally fall back to regular interrupts. */
|
||||||
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, ctx);
|
return vp_find_vqs_intx(vdev, nvqs, vqs, callbacks, names, sizes, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *vp_bus_name(struct virtio_device *vdev)
|
const char *vp_bus_name(struct virtio_device *vdev)
|
||||||
|
|
|
@ -80,6 +80,7 @@ struct virtio_pci_device {
|
||||||
unsigned int idx,
|
unsigned int idx,
|
||||||
void (*callback)(struct virtqueue *vq),
|
void (*callback)(struct virtqueue *vq),
|
||||||
const char *name,
|
const char *name,
|
||||||
|
u32 size,
|
||||||
bool ctx,
|
bool ctx,
|
||||||
u16 msix_vec);
|
u16 msix_vec);
|
||||||
void (*del_vq)(struct virtio_pci_vq_info *info);
|
void (*del_vq)(struct virtio_pci_vq_info *info);
|
||||||
|
|
|
@ -112,6 +112,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
|
||||||
unsigned int index,
|
unsigned int index,
|
||||||
void (*callback)(struct virtqueue *vq),
|
void (*callback)(struct virtqueue *vq),
|
||||||
const char *name,
|
const char *name,
|
||||||
|
u32 size,
|
||||||
bool ctx,
|
bool ctx,
|
||||||
u16 msix_vec)
|
u16 msix_vec)
|
||||||
{
|
{
|
||||||
|
@ -125,10 +126,13 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
|
||||||
if (!num || vp_legacy_get_queue_enable(&vp_dev->ldev, index))
|
if (!num || vp_legacy_get_queue_enable(&vp_dev->ldev, index))
|
||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
|
|
||||||
|
if (!size || size > num)
|
||||||
|
size = num;
|
||||||
|
|
||||||
info->msix_vector = msix_vec;
|
info->msix_vector = msix_vec;
|
||||||
|
|
||||||
/* create the vring */
|
/* create the vring */
|
||||||
vq = vring_create_virtqueue(index, num,
|
vq = vring_create_virtqueue(index, size,
|
||||||
VIRTIO_PCI_VRING_ALIGN, &vp_dev->vdev,
|
VIRTIO_PCI_VRING_ALIGN, &vp_dev->vdev,
|
||||||
true, false, ctx,
|
true, false, ctx,
|
||||||
vp_notify, callback, name);
|
vp_notify, callback, name);
|
||||||
|
|
|
@ -293,6 +293,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
|
||||||
unsigned int index,
|
unsigned int index,
|
||||||
void (*callback)(struct virtqueue *vq),
|
void (*callback)(struct virtqueue *vq),
|
||||||
const char *name,
|
const char *name,
|
||||||
|
u32 size,
|
||||||
bool ctx,
|
bool ctx,
|
||||||
u16 msix_vec)
|
u16 msix_vec)
|
||||||
{
|
{
|
||||||
|
@ -310,15 +311,18 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
|
||||||
if (!num || vp_modern_get_queue_enable(mdev, index))
|
if (!num || vp_modern_get_queue_enable(mdev, index))
|
||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
|
|
||||||
if (num & (num - 1)) {
|
if (!size || size > num)
|
||||||
dev_warn(&vp_dev->pci_dev->dev, "bad queue size %u", num);
|
size = num;
|
||||||
|
|
||||||
|
if (size & (size - 1)) {
|
||||||
|
dev_warn(&vp_dev->pci_dev->dev, "bad queue size %u", size);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
info->msix_vector = msix_vec;
|
info->msix_vector = msix_vec;
|
||||||
|
|
||||||
/* create the vring */
|
/* create the vring */
|
||||||
vq = vring_create_virtqueue(index, num,
|
vq = vring_create_virtqueue(index, size,
|
||||||
SMP_CACHE_BYTES, &vp_dev->vdev,
|
SMP_CACHE_BYTES, &vp_dev->vdev,
|
||||||
true, true, ctx,
|
true, true, ctx,
|
||||||
vp_notify, callback, name);
|
vp_notify, callback, name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue