diff options
author | Christoph Hellwig <hch@lst.de> | 2016-09-11 09:31:26 -0400 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2016-09-29 15:36:38 -0400 |
commit | 61771468e0a567f007fc450725063bb9cf7eb199 (patch) | |
tree | 5065da5efca34a18e5cb0b0d9f7418e533444981 /drivers/vfio | |
parent | c93a97ee0583cd65adaf872e7cc402493eae92a7 (diff) |
vfio_pci: use pci_alloc_irq_vectors
Simplify the interrupt setup by using the new PCI layer helpers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio')
-rw-r--r-- | drivers/vfio/pci/vfio_pci_intrs.c | 45 | ||||
-rw-r--r-- | drivers/vfio/pci/vfio_pci_private.h | 1 |
2 files changed, 10 insertions, 36 deletions
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index aa23e9a4a22f..c2e60893cd09 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c | |||
@@ -250,6 +250,7 @@ static irqreturn_t vfio_msihandler(int irq, void *arg) | |||
250 | static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) | 250 | static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) |
251 | { | 251 | { |
252 | struct pci_dev *pdev = vdev->pdev; | 252 | struct pci_dev *pdev = vdev->pdev; |
253 | unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI; | ||
253 | int ret; | 254 | int ret; |
254 | 255 | ||
255 | if (!is_irq_none(vdev)) | 256 | if (!is_irq_none(vdev)) |
@@ -259,35 +260,13 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix) | |||
259 | if (!vdev->ctx) | 260 | if (!vdev->ctx) |
260 | return -ENOMEM; | 261 | return -ENOMEM; |
261 | 262 | ||
262 | if (msix) { | 263 | /* return the number of supported vectors if we can't get all: */ |
263 | int i; | 264 | ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag); |
264 | 265 | if (ret < nvec) { | |
265 | vdev->msix = kzalloc(nvec * sizeof(struct msix_entry), | 266 | if (ret > 0) |
266 | GFP_KERNEL); | 267 | pci_free_irq_vectors(pdev); |
267 | if (!vdev->msix) { | 268 | kfree(vdev->ctx); |
268 | kfree(vdev->ctx); | 269 | return ret; |
269 | return -ENOMEM; | ||
270 | } | ||
271 | |||
272 | for (i = 0; i < nvec; i++) | ||
273 | vdev->msix[i].entry = i; | ||
274 | |||
275 | ret = pci_enable_msix_range(pdev, vdev->msix, 1, nvec); | ||
276 | if (ret < nvec) { | ||
277 | if (ret > 0) | ||
278 | pci_disable_msix(pdev); | ||
279 | kfree(vdev->msix); | ||
280 | kfree(vdev->ctx); | ||
281 | return ret; | ||
282 | } | ||
283 | } else { | ||
284 | ret = pci_enable_msi_range(pdev, 1, nvec); | ||
285 | if (ret < nvec) { | ||
286 | if (ret > 0) | ||
287 | pci_disable_msi(pdev); | ||
288 | kfree(vdev->ctx); | ||
289 | return ret; | ||
290 | } | ||
291 | } | 270 | } |
292 | 271 | ||
293 | vdev->num_ctx = nvec; | 272 | vdev->num_ctx = nvec; |
@@ -315,7 +294,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, | |||
315 | if (vector < 0 || vector >= vdev->num_ctx) | 294 | if (vector < 0 || vector >= vdev->num_ctx) |
316 | return -EINVAL; | 295 | return -EINVAL; |
317 | 296 | ||
318 | irq = msix ? vdev->msix[vector].vector : pdev->irq + vector; | 297 | irq = pci_irq_vector(pdev, vector); |
319 | 298 | ||
320 | if (vdev->ctx[vector].trigger) { | 299 | if (vdev->ctx[vector].trigger) { |
321 | free_irq(irq, vdev->ctx[vector].trigger); | 300 | free_irq(irq, vdev->ctx[vector].trigger); |
@@ -408,11 +387,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix) | |||
408 | 387 | ||
409 | vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix); | 388 | vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix); |
410 | 389 | ||
411 | if (msix) { | 390 | pci_free_irq_vectors(pdev); |
412 | pci_disable_msix(vdev->pdev); | ||
413 | kfree(vdev->msix); | ||
414 | } else | ||
415 | pci_disable_msi(pdev); | ||
416 | 391 | ||
417 | /* | 392 | /* |
418 | * Both disable paths above use pci_intx_for_msi() to clear DisINTx | 393 | * Both disable paths above use pci_intx_for_msi() to clear DisINTx |
diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 2128de86c80d..f561ac1c78a0 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h | |||
@@ -72,7 +72,6 @@ struct vfio_pci_device { | |||
72 | struct perm_bits *msi_perm; | 72 | struct perm_bits *msi_perm; |
73 | spinlock_t irqlock; | 73 | spinlock_t irqlock; |
74 | struct mutex igate; | 74 | struct mutex igate; |
75 | struct msix_entry *msix; | ||
76 | struct vfio_pci_irq_ctx *ctx; | 75 | struct vfio_pci_irq_ctx *ctx; |
77 | int num_ctx; | 76 | int num_ctx; |
78 | int irq_type; | 77 | int irq_type; |