Commit ad9a1257 authored by Jiri Pirko's avatar Jiri Pirko Committed by Michael S. Tsirkin

virtio_pci: convert vp_*find_vqs() ops to find_vqs_info()

Convert existing vp_find_vqs() and vp_modern_find_vqs() implementations
to find_vqs_info() config op.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Message-Id: <20240708074814.1739223-6-jiri@resnulli.us>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent c502eb85
...@@ -285,12 +285,13 @@ void vp_del_vqs(struct virtio_device *vdev) ...@@ -285,12 +285,13 @@ 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[],
const char * const names[], bool per_vq_vectors, struct virtqueue_info vqs_info[],
const bool *ctx, bool per_vq_vectors,
struct irq_affinity *desc) struct irq_affinity *desc)
{ {
struct virtio_pci_device *vp_dev = to_vp_device(vdev); struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtqueue_info *vqi;
u16 msix_vec; u16 msix_vec;
int i, err, nvectors, allocated_vectors, queue_idx = 0; int i, err, nvectors, allocated_vectors, queue_idx = 0;
...@@ -301,9 +302,11 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, ...@@ -301,9 +302,11 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
if (per_vq_vectors) { if (per_vq_vectors) {
/* Best option: one for change interrupt, one per vq. */ /* Best option: one for change interrupt, one per vq. */
nvectors = 1; nvectors = 1;
for (i = 0; i < nvqs; ++i) for (i = 0; i < nvqs; ++i) {
if (names[i] && callbacks[i]) vqi = &vqs_info[i];
if (vqi->name && vqi->callback)
++nvectors; ++nvectors;
}
} else { } else {
/* Second best: one for change, shared for all vqs. */ /* Second best: one for change, shared for all vqs. */
nvectors = 2; nvectors = 2;
...@@ -317,20 +320,20 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, ...@@ -317,20 +320,20 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
vp_dev->per_vq_vectors = per_vq_vectors; vp_dev->per_vq_vectors = per_vq_vectors;
allocated_vectors = vp_dev->msix_used_vectors; allocated_vectors = vp_dev->msix_used_vectors;
for (i = 0; i < nvqs; ++i) { for (i = 0; i < nvqs; ++i) {
if (!names[i]) { vqi = &vqs_info[i];
if (!vqi->name) {
vqs[i] = NULL; vqs[i] = NULL;
continue; continue;
} }
if (!callbacks[i]) if (!vqi->callback)
msix_vec = VIRTIO_MSI_NO_VECTOR; msix_vec = VIRTIO_MSI_NO_VECTOR;
else if (vp_dev->per_vq_vectors) else if (vp_dev->per_vq_vectors)
msix_vec = allocated_vectors++; msix_vec = allocated_vectors++;
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++, vqi->callback,
ctx ? ctx[i] : false, vqi->name, vqi->ctx, msix_vec);
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;
...@@ -343,7 +346,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, ...@@ -343,7 +346,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
snprintf(vp_dev->msix_names[msix_vec], snprintf(vp_dev->msix_names[msix_vec],
sizeof *vp_dev->msix_names, sizeof *vp_dev->msix_names,
"%s-%s", "%s-%s",
dev_name(&vp_dev->vdev.dev), names[i]); dev_name(&vp_dev->vdev.dev), vqi->name);
err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec), err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec),
vring_interrupt, 0, vring_interrupt, 0,
vp_dev->msix_names[msix_vec], vp_dev->msix_names[msix_vec],
...@@ -361,8 +364,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs, ...@@ -361,8 +364,8 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned int nvqs,
} }
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[],
const char * const names[], const bool *ctx) struct virtqueue_info vqs_info[])
{ {
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,12 +382,14 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, ...@@ -379,12 +382,14 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
vp_dev->intx_enabled = 1; vp_dev->intx_enabled = 1;
vp_dev->per_vq_vectors = false; vp_dev->per_vq_vectors = false;
for (i = 0; i < nvqs; ++i) { for (i = 0; i < nvqs; ++i) {
if (!names[i]) { struct virtqueue_info *vqi = &vqs_info[i];
if (!vqi->name) {
vqs[i] = NULL; vqs[i] = NULL;
continue; continue;
} }
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i], vqs[i] = vp_setup_vq(vdev, queue_idx++, vqi->callback,
ctx ? ctx[i] : false, vqi->name, vqi->ctx,
VIRTIO_MSI_NO_VECTOR); VIRTIO_MSI_NO_VECTOR);
if (IS_ERR(vqs[i])) { if (IS_ERR(vqs[i])) {
err = PTR_ERR(vqs[i]); err = PTR_ERR(vqs[i]);
...@@ -400,25 +405,24 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs, ...@@ -400,25 +405,24 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned int nvqs,
/* the config->find_vqs() implementation */ /* the config->find_vqs() implementation */
int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs, int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
struct virtqueue *vqs[], vq_callback_t *callbacks[], struct virtqueue *vqs[], struct virtqueue_info vqs_info[],
const char * const names[], const bool *ctx,
struct irq_affinity *desc) struct irq_affinity *desc)
{ {
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, vqs_info, true, 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, vqs_info, false, desc);
if (!err) if (!err)
return 0; return 0;
/* Is there an interrupt? If not give up. */ /* Is there an interrupt? If not give up. */
if (!(to_vp_device(vdev)->pci_dev->irq)) if (!(to_vp_device(vdev)->pci_dev->irq))
return err; return err;
/* 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, vqs_info);
} }
const char *vp_bus_name(struct virtio_device *vdev) const char *vp_bus_name(struct virtio_device *vdev)
......
...@@ -127,8 +127,7 @@ bool vp_notify(struct virtqueue *vq); ...@@ -127,8 +127,7 @@ bool vp_notify(struct virtqueue *vq);
void vp_del_vqs(struct virtio_device *vdev); void vp_del_vqs(struct virtio_device *vdev);
/* the config->find_vqs() implementation */ /* the config->find_vqs() implementation */
int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs, int vp_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
struct virtqueue *vqs[], vq_callback_t *callbacks[], struct virtqueue *vqs[], struct virtqueue_info vqs_info[],
const char * const names[], const bool *ctx,
struct irq_affinity *desc); struct irq_affinity *desc);
const char *vp_bus_name(struct virtio_device *vdev); const char *vp_bus_name(struct virtio_device *vdev);
......
...@@ -192,7 +192,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = { ...@@ -192,7 +192,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
.get_status = vp_get_status, .get_status = vp_get_status,
.set_status = vp_set_status, .set_status = vp_set_status,
.reset = vp_reset, .reset = vp_reset,
.find_vqs = vp_find_vqs, .find_vqs_info = vp_find_vqs,
.del_vqs = vp_del_vqs, .del_vqs = vp_del_vqs,
.synchronize_cbs = vp_synchronize_vectors, .synchronize_cbs = vp_synchronize_vectors,
.get_features = vp_get_features, .get_features = vp_get_features,
......
...@@ -595,13 +595,12 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, ...@@ -595,13 +595,12 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned int nvqs, static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
struct virtqueue *vqs[], struct virtqueue *vqs[],
vq_callback_t *callbacks[], struct virtqueue_info vqs_info[],
const char * const names[], const bool *ctx,
struct irq_affinity *desc) struct irq_affinity *desc)
{ {
struct virtio_pci_device *vp_dev = to_vp_device(vdev); struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtqueue *vq; struct virtqueue *vq;
int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, desc); int rc = vp_find_vqs(vdev, nvqs, vqs, vqs_info, desc);
if (rc) if (rc)
return rc; return rc;
...@@ -782,7 +781,7 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { ...@@ -782,7 +781,7 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
.get_status = vp_get_status, .get_status = vp_get_status,
.set_status = vp_set_status, .set_status = vp_set_status,
.reset = vp_reset, .reset = vp_reset,
.find_vqs = vp_modern_find_vqs, .find_vqs_info = vp_modern_find_vqs,
.del_vqs = vp_del_vqs, .del_vqs = vp_del_vqs,
.synchronize_cbs = vp_synchronize_vectors, .synchronize_cbs = vp_synchronize_vectors,
.get_features = vp_get_features, .get_features = vp_get_features,
...@@ -804,7 +803,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = { ...@@ -804,7 +803,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = {
.get_status = vp_get_status, .get_status = vp_get_status,
.set_status = vp_set_status, .set_status = vp_set_status,
.reset = vp_reset, .reset = vp_reset,
.find_vqs = vp_modern_find_vqs, .find_vqs_info = vp_modern_find_vqs,
.del_vqs = vp_del_vqs, .del_vqs = vp_del_vqs,
.synchronize_cbs = vp_synchronize_vectors, .synchronize_cbs = vp_synchronize_vectors,
.get_features = vp_get_features, .get_features = vp_get_features,
......
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