All of lore.kernel.org
 help / color / mirror / Atom feed
* replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors
@ 2016-09-11 13:31 Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
                   ` (5 more replies)
  0 siblings, 6 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Hi all,

this series switch the remaining users of pci_enable_msi_{exact_range}
(accounting for ahci and nvme being done through other channels) to
use the pci_alloc_irq_vectors helper instead and thus simplify the
interrupt code in those drivers a lot.  I decided to post it as a
series to everyone involved and linux-pci so that we can get a bit of
cross-review given that I have none of the involved hardware myself.


^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-19 20:45   ` Martin K. Petersen
  2016-10-11 20:16   ` Martin K. Petersen
  2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Switch the arcmsr driver to use pci_alloc_irq_vectors.  We need to two
calls to pci_alloc_irq_vectors as arcmsr only supports multiple MSI-X
vectors, but not multiple MSI vectors.

Otherwise this cleans up a lot of cruft and allows to use a common
request_irq loop for irq types, which happens to only iterate over a
single line in the non MSI-X case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/arcmsr/arcmsr.h     |  5 +--
 drivers/scsi/arcmsr/arcmsr_hba.c | 82 ++++++++++++++++------------------------
 2 files changed, 33 insertions(+), 54 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr.h b/drivers/scsi/arcmsr/arcmsr.h
index cf99f8c..a254b32 100644
--- a/drivers/scsi/arcmsr/arcmsr.h
+++ b/drivers/scsi/arcmsr/arcmsr.h
@@ -629,7 +629,6 @@ struct AdapterControlBlock
 	struct pci_dev *		pdev;
 	struct Scsi_Host *		host;
 	unsigned long			vir2phy_offset;
-	struct msix_entry	entries[ARCMST_NUM_MSIX_VECTORS];
 	/* Offset is used in making arc cdb physical to virtual calculations */
 	uint32_t			outbound_int_enable;
 	uint32_t			cdb_phyaddr_hi32;
@@ -671,8 +670,6 @@ struct AdapterControlBlock
 	/* iop init */
 	#define ACB_F_ABORT				0x0200
 	#define ACB_F_FIRMWARE_TRAP           		0x0400
-	#define ACB_F_MSI_ENABLED		0x1000
-	#define ACB_F_MSIX_ENABLED		0x2000
 	struct CommandControlBlock *			pccb_pool[ARCMSR_MAX_FREECCB_NUM];
 	/* used for memory free */
 	struct list_head		ccb_free_list;
@@ -725,7 +722,7 @@ struct AdapterControlBlock
 	atomic_t 			rq_map_token;
 	atomic_t			ante_token_value;
 	uint32_t	maxOutstanding;
-	int		msix_vector_count;
+	int		vector_count;
 };/* HW_DEVICE_EXTENSION */
 /*
 *******************************************************************************
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 7640498..a267327 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -720,51 +720,39 @@ static void arcmsr_message_isr_bh_fn(struct work_struct *work)
 static int
 arcmsr_request_irq(struct pci_dev *pdev, struct AdapterControlBlock *acb)
 {
-	int	i, j, r;
-	struct msix_entry entries[ARCMST_NUM_MSIX_VECTORS];
-
-	for (i = 0; i < ARCMST_NUM_MSIX_VECTORS; i++)
-		entries[i].entry = i;
-	r = pci_enable_msix_range(pdev, entries, 1, ARCMST_NUM_MSIX_VECTORS);
-	if (r < 0)
-		goto msi_int;
-	acb->msix_vector_count = r;
-	for (i = 0; i < r; i++) {
-		if (request_irq(entries[i].vector,
-			arcmsr_do_interrupt, 0, "arcmsr", acb)) {
+	unsigned long flags;
+	int nvec, i;
+
+	nvec = pci_alloc_irq_vectors(pdev, 1, ARCMST_NUM_MSIX_VECTORS,
+			PCI_IRQ_MSIX);
+	if (nvec > 0) {
+		pr_info("arcmsr%d: msi-x enabled\n", acb->host->host_no);
+		flags = 0;
+	} else {
+		nvec = pci_alloc_irq_vectors(pdev, 1, 1,
+				PCI_IRQ_MSI | PCI_IRQ_LEGACY);
+		if (nvec < 1)
+			return FAILED;
+
+		flags = IRQF_SHARED;
+	}
+
+	acb->vector_count = nvec;
+	for (i = 0; i < nvec; i++) {
+		if (request_irq(pci_irq_vector(pdev, i), arcmsr_do_interrupt,
+				flags, "arcmsr", acb)) {
 			pr_warn("arcmsr%d: request_irq =%d failed!\n",
-				acb->host->host_no, entries[i].vector);
-			for (j = 0 ; j < i ; j++)
-				free_irq(entries[j].vector, acb);
-			pci_disable_msix(pdev);
-			goto msi_int;
+				acb->host->host_no, pci_irq_vector(pdev, i));
+			goto out_free_irq;
 		}
-		acb->entries[i] = entries[i];
-	}
-	acb->acb_flags |= ACB_F_MSIX_ENABLED;
-	pr_info("arcmsr%d: msi-x enabled\n", acb->host->host_no);
-	return SUCCESS;
-msi_int:
-	if (pci_enable_msi_exact(pdev, 1) < 0)
-		goto legacy_int;
-	if (request_irq(pdev->irq, arcmsr_do_interrupt,
-		IRQF_SHARED, "arcmsr", acb)) {
-		pr_warn("arcmsr%d: request_irq =%d failed!\n",
-			acb->host->host_no, pdev->irq);
-		pci_disable_msi(pdev);
-		goto legacy_int;
-	}
-	acb->acb_flags |= ACB_F_MSI_ENABLED;
-	pr_info("arcmsr%d: msi enabled\n", acb->host->host_no);
-	return SUCCESS;
-legacy_int:
-	if (request_irq(pdev->irq, arcmsr_do_interrupt,
-		IRQF_SHARED, "arcmsr", acb)) {
-		pr_warn("arcmsr%d: request_irq = %d failed!\n",
-			acb->host->host_no, pdev->irq);
-		return FAILED;
 	}
+
 	return SUCCESS;
+out_free_irq:
+	while (--i >= 0)
+		free_irq(pci_irq_vector(pdev, i), acb);
+	pci_free_irq_vectors(pdev);
+	return FAILED;
 }
 
 static int arcmsr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -886,15 +874,9 @@ static void arcmsr_free_irq(struct pci_dev *pdev,
 {
 	int i;
 
-	if (acb->acb_flags & ACB_F_MSI_ENABLED) {
-		free_irq(pdev->irq, acb);
-		pci_disable_msi(pdev);
-	} else if (acb->acb_flags & ACB_F_MSIX_ENABLED) {
-		for (i = 0; i < acb->msix_vector_count; i++)
-			free_irq(acb->entries[i].vector, acb);
-		pci_disable_msix(pdev);
-	} else
-		free_irq(pdev->irq, acb);
+	for (i = 0; i < acb->vector_count; i++)
+		free_irq(pci_irq_vector(pdev, i), acb);
+	pci_free_irq_vectors(pdev);
 }
 
 static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 2/6] ipr: use pci_irq_allocate_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-19 20:44   ` Martin K. Petersen
                     ` (2 more replies)
  2016-09-11 13:31 ` [PATCH 3/6] skd: use pci_alloc_irq_vectors Christoph Hellwig
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Switch the ipr driver to use pci_alloc_irq_vectors.  We need to two calls to
pci_alloc_irq_vectors as ipr only supports multiple MSI-X vectors, but not
multiple MSI vectors.

Otherwise this cleans up a lot of cruft and allows to use a common
request_irq loop for irq types, which happens to only iterate over a
single line in the non MSI-X case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/ipr.c | 173 ++++++++++++++++-------------------------------------
 drivers/scsi/ipr.h |   7 +--
 2 files changed, 52 insertions(+), 128 deletions(-)

diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 17d04c7..cadf56c 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -186,16 +186,16 @@ static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
 };
 
 static const struct ipr_chip_t ipr_chip[] = {
-	{ PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
-	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
-	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
-	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
+	{ PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
+	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
+	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
+	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
 };
 
 static int ipr_max_bus_speeds[] = {
@@ -9356,23 +9356,11 @@ static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
 static void ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
 {
 	struct pci_dev *pdev = ioa_cfg->pdev;
+	int i;
 
-	if (ioa_cfg->intr_flag == IPR_USE_MSI ||
-	    ioa_cfg->intr_flag == IPR_USE_MSIX) {
-		int i;
-		for (i = 0; i < ioa_cfg->nvectors; i++)
-			free_irq(ioa_cfg->vectors_info[i].vec,
-				 &ioa_cfg->hrrq[i]);
-	} else
-		free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
-
-	if (ioa_cfg->intr_flag == IPR_USE_MSI) {
-		pci_disable_msi(pdev);
-		ioa_cfg->intr_flag &= ~IPR_USE_MSI;
-	} else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
-		pci_disable_msix(pdev);
-		ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
-	}
+	for (i = 0; i < ioa_cfg->nvectors; i++)
+		free_irq(pci_irq_vector(pdev, i), &ioa_cfg->hrrq[i]);
+	pci_free_irq_vectors(pdev);
 }
 
 /**
@@ -9799,45 +9787,6 @@ static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
 	}
 }
 
-static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
-{
-	struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
-	int i, vectors;
-
-	for (i = 0; i < ARRAY_SIZE(entries); ++i)
-		entries[i].entry = i;
-
-	vectors = pci_enable_msix_range(ioa_cfg->pdev,
-					entries, 1, ipr_number_of_msix);
-	if (vectors < 0) {
-		ipr_wait_for_pci_err_recovery(ioa_cfg);
-		return vectors;
-	}
-
-	for (i = 0; i < vectors; i++)
-		ioa_cfg->vectors_info[i].vec = entries[i].vector;
-	ioa_cfg->nvectors = vectors;
-
-	return 0;
-}
-
-static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
-{
-	int i, vectors;
-
-	vectors = pci_enable_msi_range(ioa_cfg->pdev, 1, ipr_number_of_msix);
-	if (vectors < 0) {
-		ipr_wait_for_pci_err_recovery(ioa_cfg);
-		return vectors;
-	}
-
-	for (i = 0; i < vectors; i++)
-		ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
-	ioa_cfg->nvectors = vectors;
-
-	return 0;
-}
-
 static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
 {
 	int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
@@ -9850,19 +9799,20 @@ static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
 	}
 }
 
-static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
+static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg,
+		struct pci_dev *pdev)
 {
 	int i, rc;
 
 	for (i = 1; i < ioa_cfg->nvectors; i++) {
-		rc = request_irq(ioa_cfg->vectors_info[i].vec,
+		rc = request_irq(pci_irq_vector(pdev, i),
 			ipr_isr_mhrrq,
 			0,
 			ioa_cfg->vectors_info[i].desc,
 			&ioa_cfg->hrrq[i]);
 		if (rc) {
 			while (--i >= 0)
-				free_irq(ioa_cfg->vectors_info[i].vec,
+				free_irq(pci_irq_vector(pdev, i),
 					&ioa_cfg->hrrq[i]);
 			return rc;
 		}
@@ -9900,8 +9850,7 @@ static irqreturn_t ipr_test_intr(int irq, void *devp)
  * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
  * @pdev:		PCI device struct
  *
- * Description: The return value from pci_enable_msi_range() can not always be
- * trusted.  This routine sets up and initiates a test interrupt to determine
+ * Description: This routine sets up and initiates a test interrupt to determine
  * if the interrupt is received via the ipr_test_intr() service routine.
  * If the tests fails, the driver will fall back to LSI.
  *
@@ -9913,6 +9862,7 @@ static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
 	int rc;
 	volatile u32 int_reg;
 	unsigned long lock_flags = 0;
+	int irq = pci_irq_vector(pdev, 0);
 
 	ENTER;
 
@@ -9924,15 +9874,12 @@ static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
 	int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 
-	if (ioa_cfg->intr_flag == IPR_USE_MSIX)
-		rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
-	else
-		rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
+	rc = request_irq(irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
 	if (rc) {
-		dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
+		dev_err(&pdev->dev, "Can not assign irq %d\n", irq);
 		return rc;
 	} else if (ipr_debug)
-		dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
+		dev_info(&pdev->dev, "IRQ assigned: %d\n", irq);
 
 	writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
 	int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
@@ -9949,10 +9896,7 @@ static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
 
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 
-	if (ioa_cfg->intr_flag == IPR_USE_MSIX)
-		free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
-	else
-		free_irq(pdev->irq, ioa_cfg);
+	free_irq(irq, ioa_cfg);
 
 	LEAVE;
 
@@ -9976,6 +9920,7 @@ static int ipr_probe_ioa(struct pci_dev *pdev,
 	int rc = PCIBIOS_SUCCESSFUL;
 	volatile u32 mask, uproc, interrupts;
 	unsigned long lock_flags, driver_lock_flags;
+	unsigned int irq_flag;
 
 	ENTER;
 
@@ -10091,18 +10036,18 @@ static int ipr_probe_ioa(struct pci_dev *pdev,
 		ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
 	}
 
-	if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
-			ipr_enable_msix(ioa_cfg) == 0)
-		ioa_cfg->intr_flag = IPR_USE_MSIX;
-	else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
-			ipr_enable_msi(ioa_cfg) == 0)
-		ioa_cfg->intr_flag = IPR_USE_MSI;
-	else {
-		ioa_cfg->intr_flag = IPR_USE_LSI;
-		ioa_cfg->clear_isr = 1;
-		ioa_cfg->nvectors = 1;
-		dev_info(&pdev->dev, "Cannot enable MSI.\n");
+	irq_flag = PCI_IRQ_LEGACY;
+	if (ioa_cfg->ipr_chip->has_msi)
+		irq_flag |= PCI_IRQ_MSI | PCI_IRQ_MSIX;
+	rc = pci_alloc_irq_vectors(pdev, 1, ipr_number_of_msix, irq_flag);
+	if (rc < 0) {
+		ipr_wait_for_pci_err_recovery(ioa_cfg);
+		goto cleanup_nomem;
 	}
+	ioa_cfg->nvectors = rc;
+
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		ioa_cfg->clear_isr = 1;
 
 	pci_set_master(pdev);
 
@@ -10115,33 +10060,22 @@ static int ipr_probe_ioa(struct pci_dev *pdev,
 		}
 	}
 
-	if (ioa_cfg->intr_flag == IPR_USE_MSI ||
-	    ioa_cfg->intr_flag == IPR_USE_MSIX) {
+	if (pdev->msi_enabled || pdev->msix_enabled) {
 		rc = ipr_test_msi(ioa_cfg, pdev);
-		if (rc == -EOPNOTSUPP) {
+		switch (rc) {
+		case 0:
+			dev_info(&pdev->dev,
+				"Request for %d MSI%ss succeeded.", ioa_cfg->nvectors,
+				pdev->msix_enabled ? "-X" : "");
+			break;
+		case -EOPNOTSUPP:
 			ipr_wait_for_pci_err_recovery(ioa_cfg);
-			if (ioa_cfg->intr_flag == IPR_USE_MSI) {
-				ioa_cfg->intr_flag &= ~IPR_USE_MSI;
-				pci_disable_msi(pdev);
-			 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
-				ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
-				pci_disable_msix(pdev);
-			}
+			pci_free_irq_vectors(pdev);
 
-			ioa_cfg->intr_flag = IPR_USE_LSI;
 			ioa_cfg->nvectors = 1;
-		}
-		else if (rc)
+			break;
+		default:
 			goto out_msi_disable;
-		else {
-			if (ioa_cfg->intr_flag == IPR_USE_MSI)
-				dev_info(&pdev->dev,
-					"Request for %d MSIs succeeded with starting IRQ: %d\n",
-					ioa_cfg->nvectors, pdev->irq);
-			else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
-				dev_info(&pdev->dev,
-					"Request for %d MSIXs succeeded.",
-					ioa_cfg->nvectors);
 		}
 	}
 
@@ -10189,15 +10123,13 @@ static int ipr_probe_ioa(struct pci_dev *pdev,
 	ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
 	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 
-	if (ioa_cfg->intr_flag == IPR_USE_MSI
-			|| ioa_cfg->intr_flag == IPR_USE_MSIX) {
+	if (pdev->msi_enabled || pdev->msix_enabled) {
 		name_msi_vectors(ioa_cfg);
-		rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
-			0,
+		rc = request_irq(pci_irq_vector(pdev, 0), ipr_isr, 0,
 			ioa_cfg->vectors_info[0].desc,
 			&ioa_cfg->hrrq[0]);
 		if (!rc)
-			rc = ipr_request_other_msi_irqs(ioa_cfg);
+			rc = ipr_request_other_msi_irqs(ioa_cfg, pdev);
 	} else {
 		rc = request_irq(pdev->irq, ipr_isr,
 			 IRQF_SHARED,
@@ -10239,10 +10171,7 @@ cleanup_nolog:
 	ipr_free_mem(ioa_cfg);
 out_msi_disable:
 	ipr_wait_for_pci_err_recovery(ioa_cfg);
-	if (ioa_cfg->intr_flag == IPR_USE_MSI)
-		pci_disable_msi(pdev);
-	else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
-		pci_disable_msix(pdev);
+	pci_free_irq_vectors(pdev);
 cleanup_nomem:
 	iounmap(ipr_regs);
 out_disable:
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index cdb5196..ec4110e 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -1411,10 +1411,7 @@ struct ipr_chip_cfg_t {
 struct ipr_chip_t {
 	u16 vendor;
 	u16 device;
-	u16 intr_type;
-#define IPR_USE_LSI			0x00
-#define IPR_USE_MSI			0x01
-#define IPR_USE_MSIX			0x02
+	bool has_msi;
 	u16 sis_type;
 #define IPR_SIS32			0x00
 #define IPR_SIS64			0x01
@@ -1589,11 +1586,9 @@ struct ipr_ioa_cfg {
 	struct ipr_cmnd **ipr_cmnd_list;
 	dma_addr_t *ipr_cmnd_list_dma;
 
-	u16 intr_flag;
 	unsigned int nvectors;
 
 	struct {
-		unsigned short vec;
 		char desc[22];
 	} vectors_info[IPR_MAX_MSIX_VECTORS];
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 3/6] skd: use pci_alloc_irq_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-29 18:44   ` Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors Christoph Hellwig
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Switch the skd driver to use pci_alloc_irq_vectors.  We need to two calls to
pci_alloc_irq_vectors as skd only supports multiple MSI-X vectors, but not
multiple MSI vectors.

Otherwise this cleans up a lot of cruft and allows to a lot more common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/skd_main.c | 212 +++++++++++++++--------------------------------
 1 file changed, 66 insertions(+), 146 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index 3822eae..702f543 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -270,8 +270,6 @@ struct skd_device {
 	resource_size_t mem_phys[SKD_MAX_BARS];
 	u32 mem_size[SKD_MAX_BARS];
 
-	skd_irq_type_t irq_type;
-	u32 msix_count;
 	struct skd_msix_entry *msix_entries;
 
 	struct pci_dev *pdev;
@@ -3821,10 +3819,6 @@ static irqreturn_t skd_qfull_isr(int irq, void *skd_host_data)
  */
 
 struct skd_msix_entry {
-	int have_irq;
-	u32 vector;
-	u32 entry;
-	struct skd_device *rsp;
 	char isr_name[30];
 };
 
@@ -3853,56 +3847,21 @@ static struct skd_init_msix_entry msix_entries[SKD_MAX_MSIX_COUNT] = {
 	{ "(Queue Full 3)", skd_qfull_isr    },
 };
 
-static void skd_release_msix(struct skd_device *skdev)
-{
-	struct skd_msix_entry *qentry;
-	int i;
-
-	if (skdev->msix_entries) {
-		for (i = 0; i < skdev->msix_count; i++) {
-			qentry = &skdev->msix_entries[i];
-			skdev = qentry->rsp;
-
-			if (qentry->have_irq)
-				devm_free_irq(&skdev->pdev->dev,
-					      qentry->vector, qentry->rsp);
-		}
-
-		kfree(skdev->msix_entries);
-	}
-
-	if (skdev->msix_count)
-		pci_disable_msix(skdev->pdev);
-
-	skdev->msix_count = 0;
-	skdev->msix_entries = NULL;
-}
-
 static int skd_acquire_msix(struct skd_device *skdev)
 {
 	int i, rc;
 	struct pci_dev *pdev = skdev->pdev;
-	struct msix_entry *entries;
-	struct skd_msix_entry *qentry;
-
-	entries = kzalloc(sizeof(struct msix_entry) * SKD_MAX_MSIX_COUNT,
-			  GFP_KERNEL);
-	if (!entries)
-		return -ENOMEM;
 
-	for (i = 0; i < SKD_MAX_MSIX_COUNT; i++)
-		entries[i].entry = i;
-
-	rc = pci_enable_msix_exact(pdev, entries, SKD_MAX_MSIX_COUNT);
-	if (rc) {
+	rc = pci_alloc_irq_vectors(pdev, SKD_MAX_MSIX_COUNT, SKD_MAX_MSIX_COUNT,
+			PCI_IRQ_MSIX);
+	if (rc < 0) {
 		pr_err("(%s): failed to enable MSI-X %d\n",
 		       skd_name(skdev), rc);
 		goto msix_out;
 	}
 
-	skdev->msix_count = SKD_MAX_MSIX_COUNT;
-	skdev->msix_entries = kzalloc(sizeof(struct skd_msix_entry) *
-				      skdev->msix_count, GFP_KERNEL);
+	skdev->msix_entries = kcalloc(SKD_MAX_MSIX_COUNT,
+			sizeof(struct skd_msix_entry), GFP_KERNEL);
 	if (!skdev->msix_entries) {
 		rc = -ENOMEM;
 		pr_err("(%s): msix table allocation error\n",
@@ -3910,136 +3869,98 @@ static int skd_acquire_msix(struct skd_device *skdev)
 		goto msix_out;
 	}
 
-	for (i = 0; i < skdev->msix_count; i++) {
-		qentry = &skdev->msix_entries[i];
-		qentry->vector = entries[i].vector;
-		qentry->entry = entries[i].entry;
-		qentry->rsp = NULL;
-		qentry->have_irq = 0;
-		pr_debug("%s:%s:%d %s: <%s> msix (%d) vec %d, entry %x\n",
-			 skdev->name, __func__, __LINE__,
-			 pci_name(pdev), skdev->name,
-			 i, qentry->vector, qentry->entry);
-	}
-
 	/* Enable MSI-X vectors for the base queue */
-	for (i = 0; i < skdev->msix_count; i++) {
-		qentry = &skdev->msix_entries[i];
+	for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) {
+		struct skd_msix_entry *qentry = &skdev->msix_entries[i];
+
 		snprintf(qentry->isr_name, sizeof(qentry->isr_name),
 			 "%s%d-msix %s", DRV_NAME, skdev->devno,
 			 msix_entries[i].name);
-		rc = devm_request_irq(&skdev->pdev->dev, qentry->vector,
-				      msix_entries[i].handler, 0,
-				      qentry->isr_name, skdev);
+
+		rc = devm_request_irq(&skdev->pdev->dev,
+				pci_irq_vector(skdev->pdev, i),
+				msix_entries[i].handler, 0,
+				qentry->isr_name, skdev);
 		if (rc) {
 			pr_err("(%s): Unable to register(%d) MSI-X "
 			       "handler %d: %s\n",
 			       skd_name(skdev), rc, i, qentry->isr_name);
 			goto msix_out;
-		} else {
-			qentry->have_irq = 1;
-			qentry->rsp = skdev;
 		}
 	}
+
 	pr_debug("%s:%s:%d %s: <%s> msix %d irq(s) enabled\n",
 		 skdev->name, __func__, __LINE__,
-		 pci_name(pdev), skdev->name, skdev->msix_count);
+		 pci_name(pdev), skdev->name, SKD_MAX_MSIX_COUNT);
 	return 0;
 
 msix_out:
-	if (entries)
-		kfree(entries);
-	skd_release_msix(skdev);
+	while (--i >= 0)
+		devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i), skdev);
+	kfree(skdev->msix_entries);
+	skdev->msix_entries = NULL;
 	return rc;
 }
 
 static int skd_acquire_irq(struct skd_device *skdev)
 {
+	struct pci_dev *pdev = skdev->pdev;
+	unsigned int irq_flag = PCI_IRQ_LEGACY;
 	int rc;
-	struct pci_dev *pdev;
 
-	pdev = skdev->pdev;
-	skdev->msix_count = 0;
-
-RETRY_IRQ_TYPE:
-	switch (skdev->irq_type) {
-	case SKD_IRQ_MSIX:
+	if (skd_isr_type == SKD_IRQ_MSIX) {
 		rc = skd_acquire_msix(skdev);
 		if (!rc)
-			pr_info("(%s): MSI-X %d irqs enabled\n",
-			       skd_name(skdev), skdev->msix_count);
-		else {
-			pr_err(
-			       "(%s): failed to enable MSI-X, re-trying with MSI %d\n",
-			       skd_name(skdev), rc);
-			skdev->irq_type = SKD_IRQ_MSI;
-			goto RETRY_IRQ_TYPE;
-		}
-		break;
-	case SKD_IRQ_MSI:
-		snprintf(skdev->isr_name, sizeof(skdev->isr_name), "%s%d-msi",
-			 DRV_NAME, skdev->devno);
-		rc = pci_enable_msi_range(pdev, 1, 1);
-		if (rc > 0) {
-			rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr, 0,
-					      skdev->isr_name, skdev);
-			if (rc) {
-				pci_disable_msi(pdev);
-				pr_err(
-				       "(%s): failed to allocate the MSI interrupt %d\n",
-				       skd_name(skdev), rc);
-				goto RETRY_IRQ_LEGACY;
-			}
-			pr_info("(%s): MSI irq %d enabled\n",
-			       skd_name(skdev), pdev->irq);
-		} else {
-RETRY_IRQ_LEGACY:
-			pr_err(
-			       "(%s): failed to enable MSI, re-trying with LEGACY %d\n",
-			       skd_name(skdev), rc);
-			skdev->irq_type = SKD_IRQ_LEGACY;
-			goto RETRY_IRQ_TYPE;
-		}
-		break;
-	case SKD_IRQ_LEGACY:
-		snprintf(skdev->isr_name, sizeof(skdev->isr_name),
-			 "%s%d-legacy", DRV_NAME, skdev->devno);
-		rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr,
-				      IRQF_SHARED, skdev->isr_name, skdev);
-		if (!rc)
-			pr_info("(%s): LEGACY irq %d enabled\n",
-			       skd_name(skdev), pdev->irq);
-		else
-			pr_err("(%s): request LEGACY irq error %d\n",
-			       skd_name(skdev), rc);
-		break;
-	default:
-		pr_info("(%s): irq_type %d invalid, re-set to %d\n",
-		       skd_name(skdev), skdev->irq_type, SKD_IRQ_DEFAULT);
-		skdev->irq_type = SKD_IRQ_LEGACY;
-		goto RETRY_IRQ_TYPE;
+			return 0;
+
+		pr_err("(%s): failed to enable MSI-X, re-trying with MSI %d\n",
+		       skd_name(skdev), rc);
 	}
-	return rc;
+
+	snprintf(skdev->isr_name, sizeof(skdev->isr_name), "%s%d", DRV_NAME,
+			skdev->devno);
+
+	if (skd_isr_type != SKD_IRQ_LEGACY)
+		irq_flag |= PCI_IRQ_MSI;
+	rc = pci_alloc_irq_vectors(pdev, 1, 1, irq_flag);
+	if (rc < 0) {
+		pr_err("(%s): failed to allocate the MSI interrupt %d\n",
+			skd_name(skdev), rc);
+		return rc;
+	}
+
+	rc = devm_request_irq(&pdev->dev, pdev->irq, skd_isr,
+			pdev->msi_enabled ? 0 : IRQF_SHARED,
+			skdev->isr_name, skdev);
+	if (rc) {
+		pci_free_irq_vectors(pdev);
+		pr_err("(%s): failed to allocate interrupt %d\n",
+			skd_name(skdev), rc);
+		return rc;
+	}
+
+	return 0;
 }
 
 static void skd_release_irq(struct skd_device *skdev)
 {
-	switch (skdev->irq_type) {
-	case SKD_IRQ_MSIX:
-		skd_release_msix(skdev);
-		break;
-	case SKD_IRQ_MSI:
-		devm_free_irq(&skdev->pdev->dev, skdev->pdev->irq, skdev);
-		pci_disable_msi(skdev->pdev);
-		break;
-	case SKD_IRQ_LEGACY:
-		devm_free_irq(&skdev->pdev->dev, skdev->pdev->irq, skdev);
-		break;
-	default:
-		pr_err("(%s): wrong irq type %d!",
-		       skd_name(skdev), skdev->irq_type);
-		break;
+	struct pci_dev *pdev = skdev->pdev;
+
+	if (skdev->msix_entries) {
+		int i;
+
+		for (i = 0; i < SKD_MAX_MSIX_COUNT; i++) {
+			devm_free_irq(&pdev->dev, pci_irq_vector(pdev, i),
+					skdev);
+		}
+
+		kfree(skdev->msix_entries);
+		skdev->msix_entries = NULL;
+	} else {
+		devm_free_irq(&pdev->dev, pdev->irq, skdev);
 	}
+
+	pci_free_irq_vectors(pdev);
 }
 
 /*
@@ -4402,7 +4323,6 @@ static struct skd_device *skd_construct(struct pci_dev *pdev)
 	skdev->pdev = pdev;
 	skdev->devno = skd_next_devno++;
 	skdev->major = blk_major;
-	skdev->irq_type = skd_isr_type;
 	sprintf(skdev->name, DRV_NAME "%d", skdev->devno);
 	skdev->dev_max_queue_depth = 0;
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
                   ` (2 preceding siblings ...)
  2016-09-11 13:31 ` [PATCH 3/6] skd: use pci_alloc_irq_vectors Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-29 18:42   ` Christoph Hellwig
  2016-09-29 19:21   ` Alex Williamson
  2016-09-11 13:31 ` [PATCH 5/6] genwqe: " Christoph Hellwig
  2016-09-11 13:31 ` [PATCH 6/6] media/cobalt: " Christoph Hellwig
  5 siblings, 2 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Simply the interrupt setup by using the new PCI layer helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/vfio/pci/vfio_pci_intrs.c   | 45 +++++++++----------------------------
 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 152b438..a1d283e 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)
 static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
 {
 	struct pci_dev *pdev = vdev->pdev;
+	unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI;
 	int ret;
 
 	if (!is_irq_none(vdev))
@@ -259,35 +260,13 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
 	if (!vdev->ctx)
 		return -ENOMEM;
 
-	if (msix) {
-		int i;
-
-		vdev->msix = kzalloc(nvec * sizeof(struct msix_entry),
-				     GFP_KERNEL);
-		if (!vdev->msix) {
-			kfree(vdev->ctx);
-			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;
-		}
+	/* return the number of supported vectors if we can't get all: */
+	ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag);
+	if (ret < nvec) {
+		if (ret > 0)
+			pci_free_irq_vectors(pdev);
+		kfree(vdev->ctx);
+		return ret;
 	}
 
 	vdev->num_ctx = nvec;
@@ -315,7 +294,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
 	if (vector < 0 || vector >= vdev->num_ctx)
 		return -EINVAL;
 
-	irq = msix ? vdev->msix[vector].vector : pdev->irq + vector;
+	irq = pci_irq_vector(pdev, vector);
 
 	if (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)
 
 	vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
 
-	if (msix) {
-		pci_disable_msix(vdev->pdev);
-		kfree(vdev->msix);
-	} else
-		pci_disable_msi(pdev);
+	pci_free_irq_vectors(pdev);
 
 	vdev->irq_type = VFIO_PCI_NUM_IRQS;
 	vdev->num_ctx = 0;
diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
index 2128de8..f561ac1 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 {
 	struct perm_bits	*msi_perm;
 	spinlock_t		irqlock;
 	struct mutex		igate;
-	struct msix_entry	*msix;
 	struct vfio_pci_irq_ctx	*ctx;
 	int			num_ctx;
 	int			irq_type;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
                   ` (3 preceding siblings ...)
  2016-09-11 13:31 ` [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-29 18:28   ` Gabriel Krisman Bertazi
  2016-09-11 13:31 ` [PATCH 6/6] media/cobalt: " Christoph Hellwig
  5 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Simply the interrupt setup by using the new PCI layer helpers.

One odd thing about this driver is that it looks like it could request
multiple MSI vectors, but it will then only ever use a single one.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/misc/genwqe/card_base.h  |  1 -
 drivers/misc/genwqe/card_utils.c | 12 ++----------
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/misc/genwqe/card_base.h b/drivers/misc/genwqe/card_base.h
index cb851c1..5813b5f 100644
--- a/drivers/misc/genwqe/card_base.h
+++ b/drivers/misc/genwqe/card_base.h
@@ -41,7 +41,6 @@
 #include "genwqe_driver.h"
 
 #define GENWQE_MSI_IRQS			4  /* Just one supported, no MSIx */
-#define GENWQE_FLAG_MSI_ENABLED		(1 << 0)
 
 #define GENWQE_MAX_VFS			15 /* maximum 15 VFs are possible */
 #define GENWQE_MAX_FUNCS		16 /* 1 PF and 15 VFs */
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 222367c..da424c2 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -730,13 +730,10 @@ int genwqe_read_softreset(struct genwqe_dev *cd)
 int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
 {
 	int rc;
-	struct pci_dev *pci_dev = cd->pci_dev;
 
-	rc = pci_enable_msi_range(pci_dev, 1, count);
+	rc = pci_alloc_irq_vectors(cd->pci_dev, 1, count, PCI_IRQ_MSI);
 	if (rc < 0)
 		return rc;
-
-	cd->flags |= GENWQE_FLAG_MSI_ENABLED;
 	return 0;
 }
 
@@ -746,12 +743,7 @@ int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
  */
 void genwqe_reset_interrupt_capability(struct genwqe_dev *cd)
 {
-	struct pci_dev *pci_dev = cd->pci_dev;
-
-	if (cd->flags & GENWQE_FLAG_MSI_ENABLED) {
-		pci_disable_msi(pci_dev);
-		cd->flags &= ~GENWQE_FLAG_MSI_ENABLED;
-	}
+	pci_free_irq_vectors(cd->pci_dev);
 }
 
 /**
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
                   ` (4 preceding siblings ...)
  2016-09-11 13:31 ` [PATCH 5/6] genwqe: " Christoph Hellwig
@ 2016-09-11 13:31 ` Christoph Hellwig
  2016-09-16  8:01   ` Hans Verkuil
  5 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-11 13:31 UTC (permalink / raw)
  To: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Simply the interrupt setup by using the new PCI layer helpers.

Despite using pci_enable_msi_range, this driver was only requesting a
single MSI vector anyway.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/media/pci/cobalt/cobalt-driver.c | 8 ++------
 drivers/media/pci/cobalt/cobalt-driver.h | 2 --
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
index 476f7f0..5a0a9e4 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -307,9 +307,7 @@ static void cobalt_pci_iounmap(struct cobalt *cobalt, struct pci_dev *pci_dev)
 static void cobalt_free_msi(struct cobalt *cobalt, struct pci_dev *pci_dev)
 {
 	free_irq(pci_dev->irq, (void *)cobalt);
-
-	if (cobalt->msi_enabled)
-		pci_disable_msi(pci_dev);
+	pci_free_irq_vectors(pci_dev);
 }
 
 static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev,
@@ -386,14 +384,12 @@ static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev,
 	   from being generated. */
 	cobalt_set_interrupt(cobalt, false);
 
-	if (pci_enable_msi_range(pci_dev, 1, 1) < 1) {
+	if (pci_alloc_irq_vectors(pci_dev, 1, 1, PCI_IRQ_MSI) < 1) {
 		cobalt_err("Could not enable MSI\n");
-		cobalt->msi_enabled = false;
 		ret = -EIO;
 		goto err_release;
 	}
 	msi_config_show(cobalt, pci_dev);
-	cobalt->msi_enabled = true;
 
 	/* Register IRQ */
 	if (request_irq(pci_dev->irq, cobalt_irq_handler, IRQF_SHARED,
diff --git a/drivers/media/pci/cobalt/cobalt-driver.h b/drivers/media/pci/cobalt/cobalt-driver.h
index ed00dc9..00f773e 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.h
+++ b/drivers/media/pci/cobalt/cobalt-driver.h
@@ -287,8 +287,6 @@ struct cobalt {
 	u32 irq_none;
 	u32 irq_full_fifo;
 
-	bool msi_enabled;
-
 	/* omnitek dma */
 	int dma_channels;
 	int first_fifo_channel;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 6/6] media/cobalt: " Christoph Hellwig
@ 2016-09-16  8:01   ` Hans Verkuil
  2016-09-16  8:31     ` Christoph Hellwig
  2016-12-14 10:29     ` Christoph Hellwig
  0 siblings, 2 replies; 29+ messages in thread
From: Hans Verkuil @ 2016-09-16  8:01 UTC (permalink / raw)
  To: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Hi Christoph,

On 09/11/2016 03:31 PM, Christoph Hellwig wrote:
> Simply the interrupt setup by using the new PCI layer helpers.
> 
> Despite using pci_enable_msi_range, this driver was only requesting a
> single MSI vector anyway.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/media/pci/cobalt/cobalt-driver.c | 8 ++------
>  drivers/media/pci/cobalt/cobalt-driver.h | 2 --
>  2 files changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
> index 476f7f0..5a0a9e4 100644
> --- a/drivers/media/pci/cobalt/cobalt-driver.c
> +++ b/drivers/media/pci/cobalt/cobalt-driver.c
> @@ -307,9 +307,7 @@ static void cobalt_pci_iounmap(struct cobalt *cobalt, struct pci_dev *pci_dev)
>  static void cobalt_free_msi(struct cobalt *cobalt, struct pci_dev *pci_dev)
>  {
>  	free_irq(pci_dev->irq, (void *)cobalt);
> -
> -	if (cobalt->msi_enabled)
> -		pci_disable_msi(pci_dev);
> +	pci_free_irq_vectors(pci_dev);
>  }
>  
>  static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev,
> @@ -386,14 +384,12 @@ static int cobalt_setup_pci(struct cobalt *cobalt, struct pci_dev *pci_dev,
>  	   from being generated. */
>  	cobalt_set_interrupt(cobalt, false);
>  
> -	if (pci_enable_msi_range(pci_dev, 1, 1) < 1) {
> +	if (pci_alloc_irq_vectors(pci_dev, 1, 1, PCI_IRQ_MSI) < 1) {

PCI_IRQ_MSI is unknown, I assume that this will appear in 4.9?

Looks good otherwise.

Regards,

	Hans

>  		cobalt_err("Could not enable MSI\n");
> -		cobalt->msi_enabled = false;
>  		ret = -EIO;
>  		goto err_release;
>  	}
>  	msi_config_show(cobalt, pci_dev);
> -	cobalt->msi_enabled = true;
>  
>  	/* Register IRQ */
>  	if (request_irq(pci_dev->irq, cobalt_irq_handler, IRQF_SHARED,
> diff --git a/drivers/media/pci/cobalt/cobalt-driver.h b/drivers/media/pci/cobalt/cobalt-driver.h
> index ed00dc9..00f773e 100644
> --- a/drivers/media/pci/cobalt/cobalt-driver.h
> +++ b/drivers/media/pci/cobalt/cobalt-driver.h
> @@ -287,8 +287,6 @@ struct cobalt {
>  	u32 irq_none;
>  	u32 irq_full_fifo;
>  
> -	bool msi_enabled;
> -
>  	/* omnitek dma */
>  	int dma_channels;
>  	int first_fifo_channel;
> 

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-09-16  8:01   ` Hans Verkuil
@ 2016-09-16  8:31     ` Christoph Hellwig
  2016-12-14 10:29     ` Christoph Hellwig
  1 sibling, 0 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-16  8:31 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

On Fri, Sep 16, 2016 at 10:01:42AM +0200, Hans Verkuil wrote:
> PCI_IRQ_MSI is unknown, I assume that this will appear in 4.9?

The flag is in 4.8-rc.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 2/6] ipr: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
@ 2016-09-19 20:44   ` Martin K. Petersen
  2016-09-29 14:01   ` Brian King
  2016-10-11 20:18   ` Martin K. Petersen
  2 siblings, 0 replies; 29+ messages in thread
From: Martin K. Petersen @ 2016-09-19 20:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:

Christoph> Switch the ipr driver to use pci_alloc_irq_vectors.  We need
Christoph> to two calls to pci_alloc_irq_vectors as ipr only supports
Christoph> multiple MSI-X vectors, but not multiple MSI vectors.

Christoph> Otherwise this cleans up a lot of cruft and allows to use a
Christoph> common request_irq loop for irq types, which happens to only
Christoph> iterate over a single line in the non MSI-X case.

Brian, Gabriel: Please test and review. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors
  2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
@ 2016-09-19 20:45   ` Martin K. Petersen
  2016-10-11 20:16   ` Martin K. Petersen
  1 sibling, 0 replies; 29+ messages in thread
From: Martin K. Petersen @ 2016-09-19 20:45 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:

Christoph> Switch the arcmsr driver to use pci_alloc_irq_vectors.  We
Christoph> need to two calls to pci_alloc_irq_vectors as arcmsr only
Christoph> supports multiple MSI-X vectors, but not multiple MSI
Christoph> vectors.

Christoph> Otherwise this cleans up a lot of cruft and allows to use a
Christoph> common request_irq loop for irq types, which happens to only
Christoph> iterate over a single line in the non MSI-X case.

Ching: Please test and review. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 2/6] ipr: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
  2016-09-19 20:44   ` Martin K. Petersen
@ 2016-09-29 14:01   ` Brian King
  2016-09-29 15:32     ` Christoph Hellwig
  2016-10-11 20:18   ` Martin K. Petersen
  2 siblings, 1 reply; 29+ messages in thread
From: Brian King @ 2016-09-29 14:01 UTC (permalink / raw)
  To: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson
  Cc: kvm, linux-scsi, linux-block, linux-media, linux-pci, linux-kernel

Thanks Christoph. Very nice. As I was reviewing the patch, I noticed
the additional PCI_IRQ_AFFINITY flag, which is currently not being set
in this patch. Is the intention to set that globally by default, or
should I follow up with a one liner to add that to the ipr driver
in the next patch set I send out?

Acked-by: Brian King <brking@linux.vnet.ibm.com>

Thanks,

Brian


-- 
Brian King
Power Linux I/O
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 2/6] ipr: use pci_irq_allocate_vectors
  2016-09-29 14:01   ` Brian King
@ 2016-09-29 15:32     ` Christoph Hellwig
  0 siblings, 0 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 15:32 UTC (permalink / raw)
  To: Brian King
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

On Thu, Sep 29, 2016 at 09:01:44AM -0500, Brian King wrote:
> Thanks Christoph. Very nice. As I was reviewing the patch, I noticed
> the additional PCI_IRQ_AFFINITY flag, which is currently not being set
> in this patch. Is the intention to set that globally by default, or
> should I follow up with a one liner to add that to the ipr driver
> in the next patch set I send out?

Hi Brian,

PCI_IRQ_AFFINITY seems useful for ipr, especially if you also increase
the number of vectors above the current default 2.  And yes, please
make it a separate patch.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 5/6] genwqe: " Christoph Hellwig
@ 2016-09-29 18:28   ` Gabriel Krisman Bertazi
  2016-09-29 18:37     ` Christoph Hellwig
  0 siblings, 1 reply; 29+ messages in thread
From: Gabriel Krisman Bertazi @ 2016-09-29 18:28 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

Christoph Hellwig <hch@lst.de> writes:

> Simply the interrupt setup by using the new PCI layer helpers.

Good clean up.  Tested and:

Acked-by: Gabriel Krisman Bertazi <krisman@linux.vnet.ibm.com>

> One odd thing about this driver is that it looks like it could request
> multiple MSI vectors, but it will then only ever use a single one.

I'll take a look at this.

-- 
Gabriel Krisman Bertazi


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-29 18:28   ` Gabriel Krisman Bertazi
@ 2016-09-29 18:37     ` Christoph Hellwig
  2016-09-29 18:45       ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 18:37 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

On Thu, Sep 29, 2016 at 03:28:02PM -0300, Gabriel Krisman Bertazi wrote:
> Christoph Hellwig <hch@lst.de> writes:
> 
> > Simply the interrupt setup by using the new PCI layer helpers.
> 
> Good clean up.  Tested and:
> 
> Acked-by: Gabriel Krisman Bertazi <krisman@linux.vnet.ibm.com>

Which tree should this go in through?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors Christoph Hellwig
@ 2016-09-29 18:42   ` Christoph Hellwig
  2016-09-29 19:21   ` Alex Williamson
  1 sibling, 0 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 18:42 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: alex.williamson, kvm, linux-pci, linux-kernel

On Sun, Sep 11, 2016 at 03:31:26PM +0200, Christoph Hellwig wrote:
> Simply the interrupt setup by using the new PCI layer helpers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Any chance to get a review for this one?  Vfio seems to be actively
maintained, so the silence seems odd.  I'm still hoping to get rid
of the pci_enable_msi_range interface for 4.9.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 3/6] skd: use pci_alloc_irq_vectors
  2016-09-11 13:31 ` [PATCH 3/6] skd: use pci_alloc_irq_vectors Christoph Hellwig
@ 2016-09-29 18:44   ` Christoph Hellwig
  0 siblings, 0 replies; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 18:44 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: axboe, linux-block

On Sun, Sep 11, 2016 at 03:31:25PM +0200, Christoph Hellwig wrote:
> Switch the skd driver to use pci_alloc_irq_vectors.  We need to two calls to
> pci_alloc_irq_vectors as skd only supports multiple MSI-X vectors, but not
> multiple MSI vectors.
> 
> Otherwise this cleans up a lot of cruft and allows to a lot more common code.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Jens, is this something you could pick up for 4.9?  I'd like to get get
rid of all users of pci_enable_msi_range in this merge window.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-29 18:37     ` Christoph Hellwig
@ 2016-09-29 18:45       ` Gabriel Krisman Bertazi
  2016-09-29 18:48         ` Christoph Hellwig
  0 siblings, 1 reply; 29+ messages in thread
From: Gabriel Krisman Bertazi @ 2016-09-29 18:45 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

Christoph Hellwig <hch@lst.de> writes:

> On Thu, Sep 29, 2016 at 03:28:02PM -0300, Gabriel Krisman Bertazi wrote:
>> Christoph Hellwig <hch@lst.de> writes:
>> 
>> > Simply the interrupt setup by using the new PCI layer helpers.
>> 
>> Good clean up.  Tested and:
>> 
>> Acked-by: Gabriel Krisman Bertazi <krisman@linux.vnet.ibm.com>
>
> Which tree should this go in through?

I'd say Greg's char-misc tree.

I'm stepping up to assist with the genwqe_card driver just now, since we
(ibm) missed some of the last patches that went in.  I'll add myself to
maintainers file.


-- 
Gabriel Krisman Bertazi


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-29 18:45       ` Gabriel Krisman Bertazi
@ 2016-09-29 18:48         ` Christoph Hellwig
  2016-09-29 18:51           ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 18:48 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

On Thu, Sep 29, 2016 at 03:45:29PM -0300, Gabriel Krisman Bertazi wrote:
> I'm stepping up to assist with the genwqe_card driver just now, since we
> (ibm) missed some of the last patches that went in.  I'll add myself to
> maintainers file.

Can your forward it to Greg together with whatever other changes are
pending for the driver?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 5/6] genwqe: use pci_irq_allocate_vectors
  2016-09-29 18:48         ` Christoph Hellwig
@ 2016-09-29 18:51           ` Gabriel Krisman Bertazi
  0 siblings, 0 replies; 29+ messages in thread
From: Gabriel Krisman Bertazi @ 2016-09-29 18:51 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

Christoph Hellwig <hch@lst.de> writes:

> On Thu, Sep 29, 2016 at 03:45:29PM -0300, Gabriel Krisman Bertazi wrote:
>> I'm stepping up to assist with the genwqe_card driver just now, since we
>> (ibm) missed some of the last patches that went in.  I'll add myself to
>> maintainers file.
>
> Can your forward it to Greg together with whatever other changes are
> pending for the driver?

sure, will do.

-- 
Gabriel Krisman Bertazi


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors Christoph Hellwig
  2016-09-29 18:42   ` Christoph Hellwig
@ 2016-09-29 19:21   ` Alex Williamson
  2016-09-29 19:24     ` Christoph Hellwig
  1 sibling, 1 reply; 29+ messages in thread
From: Alex Williamson @ 2016-09-29 19:21 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, kvm, linux-scsi,
	linux-block, linux-media, linux-pci, linux-kernel

On Sun, 11 Sep 2016 15:31:26 +0200
Christoph Hellwig <hch@lst.de> wrote:

> Simply the interrupt setup by using the new PCI layer helpers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/vfio/pci/vfio_pci_intrs.c   | 45 +++++++++----------------------------
>  drivers/vfio/pci/vfio_pci_private.h |  1 -
>  2 files changed, 10 insertions(+), 36 deletions(-)

Sorry for the delay, slipped by me.  Overall a really nice cleanup.
One tiny nit, the commit log mis-names the function as
pci_irq_allocate_vectors instead of pci_alloc_irq_vectors.  With that,

Acked-by: Alex Williamson <alex.williamson@redhat.com>

Let me know if you're wanting me to pull this through my tree, I'm
assuming not.  Thanks,

Alex
 
> diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
> index 152b438..a1d283e 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)
>  static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
>  {
>  	struct pci_dev *pdev = vdev->pdev;
> +	unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI;
>  	int ret;
>  
>  	if (!is_irq_none(vdev))
> @@ -259,35 +260,13 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
>  	if (!vdev->ctx)
>  		return -ENOMEM;
>  
> -	if (msix) {
> -		int i;
> -
> -		vdev->msix = kzalloc(nvec * sizeof(struct msix_entry),
> -				     GFP_KERNEL);
> -		if (!vdev->msix) {
> -			kfree(vdev->ctx);
> -			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;
> -		}
> +	/* return the number of supported vectors if we can't get all: */
> +	ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag);
> +	if (ret < nvec) {
> +		if (ret > 0)
> +			pci_free_irq_vectors(pdev);
> +		kfree(vdev->ctx);
> +		return ret;
>  	}
>  
>  	vdev->num_ctx = nvec;
> @@ -315,7 +294,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
>  	if (vector < 0 || vector >= vdev->num_ctx)
>  		return -EINVAL;
>  
> -	irq = msix ? vdev->msix[vector].vector : pdev->irq + vector;
> +	irq = pci_irq_vector(pdev, vector);
>  
>  	if (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)
>  
>  	vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
>  
> -	if (msix) {
> -		pci_disable_msix(vdev->pdev);
> -		kfree(vdev->msix);
> -	} else
> -		pci_disable_msi(pdev);
> +	pci_free_irq_vectors(pdev);
>  
>  	vdev->irq_type = VFIO_PCI_NUM_IRQS;
>  	vdev->num_ctx = 0;
> diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
> index 2128de8..f561ac1 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 {
>  	struct perm_bits	*msi_perm;
>  	spinlock_t		irqlock;
>  	struct mutex		igate;
> -	struct msix_entry	*msix;
>  	struct vfio_pci_irq_ctx	*ctx;
>  	int			num_ctx;
>  	int			irq_type;


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors
  2016-09-29 19:21   ` Alex Williamson
@ 2016-09-29 19:24     ` Christoph Hellwig
  2016-09-29 19:27       ` Alex Williamson
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-09-29 19:24 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

On Thu, Sep 29, 2016 at 01:21:01PM -0600, Alex Williamson wrote:
> Sorry for the delay, slipped by me.  Overall a really nice cleanup.
> One tiny nit, the commit log mis-names the function as
> pci_irq_allocate_vectors instead of pci_alloc_irq_vectors.  With that,
> 
> Acked-by: Alex Williamson <alex.williamson@redhat.com>
> 
> Let me know if you're wanting me to pull this through my tree, I'm
> assuming not.  Thanks,

Please pull in through your tree.  If you can also just fix up that
type that'd be even better.

Thanks a lot!

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors
  2016-09-29 19:24     ` Christoph Hellwig
@ 2016-09-29 19:27       ` Alex Williamson
  0 siblings, 0 replies; 29+ messages in thread
From: Alex Williamson @ 2016-09-29 19:27 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, kvm, linux-scsi,
	linux-block, linux-media, linux-pci, linux-kernel

On Thu, 29 Sep 2016 21:24:04 +0200
Christoph Hellwig <hch@lst.de> wrote:

> On Thu, Sep 29, 2016 at 01:21:01PM -0600, Alex Williamson wrote:
> > Sorry for the delay, slipped by me.  Overall a really nice cleanup.
> > One tiny nit, the commit log mis-names the function as
> > pci_irq_allocate_vectors instead of pci_alloc_irq_vectors.  With that,
> > 
> > Acked-by: Alex Williamson <alex.williamson@redhat.com>
> > 
> > Let me know if you're wanting me to pull this through my tree, I'm
> > assuming not.  Thanks,  
> 
> Please pull in through your tree.  If you can also just fix up that
> type that'd be even better.

Will do.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors
  2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
  2016-09-19 20:45   ` Martin K. Petersen
@ 2016-10-11 20:16   ` Martin K. Petersen
  1 sibling, 0 replies; 29+ messages in thread
From: Martin K. Petersen @ 2016-10-11 20:16 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:

Christoph> Switch the arcmsr driver to use pci_alloc_irq_vectors.  We
Christoph> need to two calls to pci_alloc_irq_vectors as arcmsr only
Christoph> supports multiple MSI-X vectors, but not multiple MSI
Christoph> vectors.

Christoph> Otherwise this cleans up a lot of cruft and allows to use a
Christoph> common request_irq loop for irq types, which happens to only
Christoph> iterate over a single line in the non MSI-X case.

Applied to 4.10/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 2/6] ipr: use pci_irq_allocate_vectors
  2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
  2016-09-19 20:44   ` Martin K. Petersen
  2016-09-29 14:01   ` Brian King
@ 2016-10-11 20:18   ` Martin K. Petersen
  2 siblings, 0 replies; 29+ messages in thread
From: Martin K. Petersen @ 2016-10-11 20:18 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:

Christoph> Switch the ipr driver to use pci_alloc_irq_vectors.  We need
Christoph> to two calls to pci_alloc_irq_vectors as ipr only supports
Christoph> multiple MSI-X vectors, but not multiple MSI vectors.

Christoph> Otherwise this cleans up a lot of cruft and allows to use a
Christoph> common request_irq loop for irq types, which happens to only
Christoph> iterate over a single line in the non MSI-X case.

Applied to 4.10/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-09-16  8:01   ` Hans Verkuil
  2016-09-16  8:31     ` Christoph Hellwig
@ 2016-12-14 10:29     ` Christoph Hellwig
  2016-12-14 10:37       ` Hans Verkuil
  1 sibling, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-12-14 10:29 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

Hi Hans,

just checked the current Linux tree and cobalt still uses the old
pci_enable_msi_range call.  Did you queue this patch up for 4.10?

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-12-14 10:29     ` Christoph Hellwig
@ 2016-12-14 10:37       ` Hans Verkuil
  2016-12-14 10:47         ` Christoph Hellwig
  0 siblings, 1 reply; 29+ messages in thread
From: Hans Verkuil @ 2016-12-14 10:37 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

On 14/12/16 11:29, Christoph Hellwig wrote:
> Hi Hans,
>
> just checked the current Linux tree and cobalt still uses the old
> pci_enable_msi_range call.  Did you queue this patch up for 4.10?
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

Completely forgot this. Is it OK to queue it for 4.11? Or is it blocking
other follow-up work you want to do for 4.10?

Regards,

	Hans

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-12-14 10:37       ` Hans Verkuil
@ 2016-12-14 10:47         ` Christoph Hellwig
  2016-12-14 10:52           ` Hans Verkuil
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Hellwig @ 2016-12-14 10:47 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Christoph Hellwig, hans.verkuil, brking, haver, ching2048, axboe,
	alex.williamson, kvm, linux-scsi, linux-block, linux-media,
	linux-pci, linux-kernel

On Wed, Dec 14, 2016 at 11:37:17AM +0100, Hans Verkuil wrote:
> Completely forgot this. Is it OK to queue it for 4.11? Or is it blocking
> other follow-up work you want to do for 4.10?

My plan was to see if Bjorn would take the patch to do the trivial removal
of pci_enable_msix_exact and pci_enable_msix_range even as a late 4.10 patch
given it's so harmless, but either way there is follow work pending ASAP
so getting it in for 4.10 would be very helpful.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 6/6] media/cobalt: use pci_irq_allocate_vectors
  2016-12-14 10:47         ` Christoph Hellwig
@ 2016-12-14 10:52           ` Hans Verkuil
  0 siblings, 0 replies; 29+ messages in thread
From: Hans Verkuil @ 2016-12-14 10:52 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hans.verkuil, brking, haver, ching2048, axboe, alex.williamson,
	kvm, linux-scsi, linux-block, linux-media, linux-pci,
	linux-kernel

On 14/12/16 11:47, Christoph Hellwig wrote:
> On Wed, Dec 14, 2016 at 11:37:17AM +0100, Hans Verkuil wrote:
>> Completely forgot this. Is it OK to queue it for 4.11? Or is it blocking
>> other follow-up work you want to do for 4.10?
>
> My plan was to see if Bjorn would take the patch to do the trivial removal
> of pci_enable_msix_exact and pci_enable_msix_range even as a late 4.10 patch
> given it's so harmless, but either way there is follow work pending ASAP
> so getting it in for 4.10 would be very helpful.
>

OK, then I'll make a pull request for 4.10 tomorrow.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2016-12-14 10:55 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-11 13:31 replace pci_enable_msi_{exact_range} with pci_alloc_irq_vectors Christoph Hellwig
2016-09-11 13:31 ` [PATCH 1/6] arcmsr: use pci_alloc_irq_vectors Christoph Hellwig
2016-09-19 20:45   ` Martin K. Petersen
2016-10-11 20:16   ` Martin K. Petersen
2016-09-11 13:31 ` [PATCH 2/6] ipr: use pci_irq_allocate_vectors Christoph Hellwig
2016-09-19 20:44   ` Martin K. Petersen
2016-09-29 14:01   ` Brian King
2016-09-29 15:32     ` Christoph Hellwig
2016-10-11 20:18   ` Martin K. Petersen
2016-09-11 13:31 ` [PATCH 3/6] skd: use pci_alloc_irq_vectors Christoph Hellwig
2016-09-29 18:44   ` Christoph Hellwig
2016-09-11 13:31 ` [PATCH 4/6] vfio_pci: use pci_irq_allocate_vectors Christoph Hellwig
2016-09-29 18:42   ` Christoph Hellwig
2016-09-29 19:21   ` Alex Williamson
2016-09-29 19:24     ` Christoph Hellwig
2016-09-29 19:27       ` Alex Williamson
2016-09-11 13:31 ` [PATCH 5/6] genwqe: " Christoph Hellwig
2016-09-29 18:28   ` Gabriel Krisman Bertazi
2016-09-29 18:37     ` Christoph Hellwig
2016-09-29 18:45       ` Gabriel Krisman Bertazi
2016-09-29 18:48         ` Christoph Hellwig
2016-09-29 18:51           ` Gabriel Krisman Bertazi
2016-09-11 13:31 ` [PATCH 6/6] media/cobalt: " Christoph Hellwig
2016-09-16  8:01   ` Hans Verkuil
2016-09-16  8:31     ` Christoph Hellwig
2016-12-14 10:29     ` Christoph Hellwig
2016-12-14 10:37       ` Hans Verkuil
2016-12-14 10:47         ` Christoph Hellwig
2016-12-14 10:52           ` Hans Verkuil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.