Commit 61771468 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Alex Williamson

vfio_pci: use pci_alloc_irq_vectors

Simplify the interrupt setup by using the new PCI layer helpers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent c93a97ee
...@@ -250,6 +250,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) ...@@ -250,6 +250,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg)
static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
{ {
struct pci_dev *pdev = vdev->pdev; struct pci_dev *pdev = vdev->pdev;
unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI;
int ret; int ret;
if (!is_irq_none(vdev)) if (!is_irq_none(vdev))
...@@ -259,35 +260,13 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) ...@@ -259,35 +260,13 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
if (!vdev->ctx) if (!vdev->ctx)
return -ENOMEM; return -ENOMEM;
if (msix) { /* return the number of supported vectors if we can't get all: */
int i; ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag);
if (ret < nvec) {
vdev->msix = kzalloc(nvec * sizeof(struct msix_entry), if (ret > 0)
GFP_KERNEL); pci_free_irq_vectors(pdev);
if (!vdev->msix) { kfree(vdev->ctx);
kfree(vdev->ctx); return ret;
return -ENOMEM;
}
for (i = 0; i < nvec; i++)
vdev->msix[i].entry = i;
ret = pci_enable_msix_range(pdev, vdev->msix, 1, nvec);
if (ret < nvec) {
if (ret > 0)
pci_disable_msix(pdev);
kfree(vdev->msix);
kfree(vdev->ctx);
return ret;
}
} else {
ret = pci_enable_msi_range(pdev, 1, nvec);
if (ret < nvec) {
if (ret > 0)
pci_disable_msi(pdev);
kfree(vdev->ctx);
return ret;
}
} }
vdev->num_ctx = nvec; vdev->num_ctx = nvec;
...@@ -315,7 +294,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, ...@@ -315,7 +294,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
if (vector < 0 || vector >= vdev->num_ctx) if (vector < 0 || vector >= vdev->num_ctx)
return -EINVAL; return -EINVAL;
irq = msix ? vdev->msix[vector].vector : pdev->irq + vector; irq = pci_irq_vector(pdev, vector);
if (vdev->ctx[vector].trigger) { if (vdev->ctx[vector].trigger) {
free_irq(irq, vdev->ctx[vector].trigger); free_irq(irq, vdev->ctx[vector].trigger);
...@@ -408,11 +387,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix) ...@@ -408,11 +387,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix); vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
if (msix) { pci_free_irq_vectors(pdev);
pci_disable_msix(vdev->pdev);
kfree(vdev->msix);
} else
pci_disable_msi(pdev);
/* /*
* Both disable paths above use pci_intx_for_msi() to clear DisINTx * Both disable paths above use pci_intx_for_msi() to clear DisINTx
......
...@@ -72,7 +72,6 @@ struct vfio_pci_device { ...@@ -72,7 +72,6 @@ struct vfio_pci_device {
struct perm_bits *msi_perm; struct perm_bits *msi_perm;
spinlock_t irqlock; spinlock_t irqlock;
struct mutex igate; struct mutex igate;
struct msix_entry *msix;
struct vfio_pci_irq_ctx *ctx; struct vfio_pci_irq_ctx *ctx;
int num_ctx; int num_ctx;
int irq_type; int irq_type;
......
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