Commit 3bb434cd authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Greg Kroah-Hartman

vmw_vmci: switch to pci_irq_alloc_vectors

Cleans up the IRQ management code a lot, including removing a lot of
state from the per-device structure.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cadf8106
...@@ -54,10 +54,7 @@ struct vmci_guest_device { ...@@ -54,10 +54,7 @@ struct vmci_guest_device {
struct device *dev; /* PCI device we are attached to */ struct device *dev; /* PCI device we are attached to */
void __iomem *iobase; void __iomem *iobase;
unsigned int irq;
unsigned int intr_type;
bool exclusive_vectors; bool exclusive_vectors;
struct msix_entry msix_entries[VMCI_MAX_INTRS];
struct tasklet_struct datagram_tasklet; struct tasklet_struct datagram_tasklet;
struct tasklet_struct bm_tasklet; struct tasklet_struct bm_tasklet;
...@@ -368,30 +365,6 @@ static void vmci_process_bitmap(unsigned long data) ...@@ -368,30 +365,6 @@ static void vmci_process_bitmap(unsigned long data)
vmci_dbell_scan_notification_entries(dev->notification_bitmap); vmci_dbell_scan_notification_entries(dev->notification_bitmap);
} }
/*
* Enable MSI-X. Try exclusive vectors first, then shared vectors.
*/
static int vmci_enable_msix(struct pci_dev *pdev,
struct vmci_guest_device *vmci_dev)
{
int i;
int result;
for (i = 0; i < VMCI_MAX_INTRS; ++i) {
vmci_dev->msix_entries[i].entry = i;
vmci_dev->msix_entries[i].vector = i;
}
result = pci_enable_msix_exact(pdev,
vmci_dev->msix_entries, VMCI_MAX_INTRS);
if (result == 0)
vmci_dev->exclusive_vectors = true;
else if (result == -ENOSPC)
result = pci_enable_msix_exact(pdev, vmci_dev->msix_entries, 1);
return result;
}
/* /*
* Interrupt handler for legacy or MSI interrupt, or for first MSI-X * Interrupt handler for legacy or MSI interrupt, or for first MSI-X
* interrupt (vector VMCI_INTR_DATAGRAM). * interrupt (vector VMCI_INTR_DATAGRAM).
...@@ -406,7 +379,7 @@ static irqreturn_t vmci_interrupt(int irq, void *_dev) ...@@ -406,7 +379,7 @@ static irqreturn_t vmci_interrupt(int irq, void *_dev)
* Otherwise we must read the ICR to determine what to do. * Otherwise we must read the ICR to determine what to do.
*/ */
if (dev->intr_type == VMCI_INTR_TYPE_MSIX && dev->exclusive_vectors) { if (dev->exclusive_vectors) {
tasklet_schedule(&dev->datagram_tasklet); tasklet_schedule(&dev->datagram_tasklet);
} else { } else {
unsigned int icr; unsigned int icr;
...@@ -491,7 +464,6 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, ...@@ -491,7 +464,6 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
} }
vmci_dev->dev = &pdev->dev; vmci_dev->dev = &pdev->dev;
vmci_dev->intr_type = VMCI_INTR_TYPE_INTX;
vmci_dev->exclusive_vectors = false; vmci_dev->exclusive_vectors = false;
vmci_dev->iobase = iobase; vmci_dev->iobase = iobase;
...@@ -592,26 +564,26 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, ...@@ -592,26 +564,26 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
* Enable interrupts. Try MSI-X first, then MSI, and then fallback on * Enable interrupts. Try MSI-X first, then MSI, and then fallback on
* legacy interrupts. * legacy interrupts.
*/ */
if (!vmci_disable_msix && !vmci_enable_msix(pdev, vmci_dev)) { error = pci_alloc_irq_vectors(pdev, VMCI_MAX_INTRS, VMCI_MAX_INTRS,
vmci_dev->intr_type = VMCI_INTR_TYPE_MSIX; PCI_IRQ_MSIX);
vmci_dev->irq = vmci_dev->msix_entries[0].vector; if (error) {
} else if (!vmci_disable_msi && !pci_enable_msi(pdev)) { error = pci_alloc_irq_vectors(pdev, 1, 1,
vmci_dev->intr_type = VMCI_INTR_TYPE_MSI; PCI_IRQ_MSIX | PCI_IRQ_MSI | PCI_IRQ_LEGACY);
vmci_dev->irq = pdev->irq; if (error)
goto err_remove_bitmap;
} else { } else {
vmci_dev->intr_type = VMCI_INTR_TYPE_INTX; vmci_dev->exclusive_vectors = true;
vmci_dev->irq = pdev->irq;
} }
/* /*
* Request IRQ for legacy or MSI interrupts, or for first * Request IRQ for legacy or MSI interrupts, or for first
* MSI-X vector. * MSI-X vector.
*/ */
error = request_irq(vmci_dev->irq, vmci_interrupt, IRQF_SHARED, error = request_irq(pci_irq_vector(pdev, 0), vmci_interrupt,
KBUILD_MODNAME, vmci_dev); IRQF_SHARED, KBUILD_MODNAME, vmci_dev);
if (error) { if (error) {
dev_err(&pdev->dev, "Irq %u in use: %d\n", dev_err(&pdev->dev, "Irq %u in use: %d\n",
vmci_dev->irq, error); pci_irq_vector(pdev, 0), error);
goto err_disable_msi; goto err_disable_msi;
} }
...@@ -622,13 +594,13 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, ...@@ -622,13 +594,13 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
* between the vectors. * between the vectors.
*/ */
if (vmci_dev->exclusive_vectors) { if (vmci_dev->exclusive_vectors) {
error = request_irq(vmci_dev->msix_entries[1].vector, error = request_irq(pci_irq_vector(pdev, 1),
vmci_interrupt_bm, 0, KBUILD_MODNAME, vmci_interrupt_bm, 0, KBUILD_MODNAME,
vmci_dev); vmci_dev);
if (error) { if (error) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Failed to allocate irq %u: %d\n", "Failed to allocate irq %u: %d\n",
vmci_dev->msix_entries[1].vector, error); pci_irq_vector(pdev, 1), error);
goto err_free_irq; goto err_free_irq;
} }
} }
...@@ -651,15 +623,12 @@ static int vmci_guest_probe_device(struct pci_dev *pdev, ...@@ -651,15 +623,12 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
return 0; return 0;
err_free_irq: err_free_irq:
free_irq(vmci_dev->irq, vmci_dev); free_irq(pci_irq_vector(pdev, 0), vmci_dev);
tasklet_kill(&vmci_dev->datagram_tasklet); tasklet_kill(&vmci_dev->datagram_tasklet);
tasklet_kill(&vmci_dev->bm_tasklet); tasklet_kill(&vmci_dev->bm_tasklet);
err_disable_msi: err_disable_msi:
if (vmci_dev->intr_type == VMCI_INTR_TYPE_MSIX) pci_free_irq_vectors(pdev);
pci_disable_msix(pdev);
else if (vmci_dev->intr_type == VMCI_INTR_TYPE_MSI)
pci_disable_msi(pdev);
vmci_err = vmci_event_unsubscribe(ctx_update_sub_id); vmci_err = vmci_event_unsubscribe(ctx_update_sub_id);
if (vmci_err < VMCI_SUCCESS) if (vmci_err < VMCI_SUCCESS)
...@@ -719,14 +688,10 @@ static void vmci_guest_remove_device(struct pci_dev *pdev) ...@@ -719,14 +688,10 @@ static void vmci_guest_remove_device(struct pci_dev *pdev)
* MSI-X, we might have multiple vectors, each with their own * MSI-X, we might have multiple vectors, each with their own
* IRQ, which we must free too. * IRQ, which we must free too.
*/ */
free_irq(vmci_dev->irq, vmci_dev); if (vmci_dev->exclusive_vectors)
if (vmci_dev->intr_type == VMCI_INTR_TYPE_MSIX) { free_irq(pci_irq_vector(pdev, 1), vmci_dev);
if (vmci_dev->exclusive_vectors) free_irq(pci_irq_vector(pdev, 0), vmci_dev);
free_irq(vmci_dev->msix_entries[1].vector, vmci_dev); pci_free_irq_vectors(pdev);
pci_disable_msix(pdev);
} else if (vmci_dev->intr_type == VMCI_INTR_TYPE_MSI) {
pci_disable_msi(pdev);
}
tasklet_kill(&vmci_dev->datagram_tasklet); tasklet_kill(&vmci_dev->datagram_tasklet);
tasklet_kill(&vmci_dev->bm_tasklet); tasklet_kill(&vmci_dev->bm_tasklet);
......
...@@ -54,13 +54,6 @@ ...@@ -54,13 +54,6 @@
#define VMCI_IMR_DATAGRAM 0x1 #define VMCI_IMR_DATAGRAM 0x1
#define VMCI_IMR_NOTIFICATION 0x2 #define VMCI_IMR_NOTIFICATION 0x2
/* Interrupt type. */
enum {
VMCI_INTR_TYPE_INTX = 0,
VMCI_INTR_TYPE_MSI = 1,
VMCI_INTR_TYPE_MSIX = 2,
};
/* Maximum MSI/MSI-X interrupt vectors in the device. */ /* Maximum MSI/MSI-X interrupt vectors in the device. */
#define VMCI_MAX_INTRS 2 #define VMCI_MAX_INTRS 2
......
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