Re: [PATCH] hpsa: use pci_alloc_irq_vectors and automatic irq affinity

2016-11-12 Thread Martin K. Petersen
> "Christoph" == Christoph Hellwig  writes:

Christoph> This patch converts over hpsa to use the
Christoph> pci_alloc_irq_vectors including the PCI_IRQ_AFFINITY flag
Christoph> that automatically assigns spread out irq affinity to the I/O
Christoph> queues.

Applied to 4.10/scsi-queue.

-- 
Martin K. Petersen  Oracle Linux Engineering
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] hpsa: use pci_alloc_irq_vectors and automatic irq affinity

2016-11-09 Thread Hannes Reinecke
On 11/09/2016 07:42 PM, Christoph Hellwig wrote:
> This patch converts over hpsa to use the pci_alloc_irq_vectors including
> the PCI_IRQ_AFFINITY flag that automatically assigns spread out
> irq affinity to the I/O queues.
> 
> It also cleans up the per-ctrl interrupt state due to the use of the
> pci_irq_vector and pci_free_irq_vectors helpers that don't need to know
> the exact irq type.  Additionally it changes a little oddity in the
> existing code that was using different array indixes into the per-vector
> arrays depending on wether a controller is using a single INTx or single
> MSI irq.
> 
> Signed-off-by: Christoph Hellwig 
> ---
>  drivers/scsi/hpsa.c | 143 
> ++--
>  drivers/scsi/hpsa.h |   6 +--
>  2 files changed, 52 insertions(+), 97 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH] hpsa: use pci_alloc_irq_vectors and automatic irq affinity

2016-11-09 Thread Don Brace

> -Original Message-
> From: Christoph Hellwig [mailto:h...@lst.de]
> Sent: Wednesday, November 09, 2016 12:42 PM
> To: Don Brace
> Cc: h...@suse.de; linux-scsi@vger.kernel.org
> Subject: [PATCH] hpsa: use pci_alloc_irq_vectors and automatic irq affinity
> 
> EXTERNAL EMAIL
> 
> 
> This patch converts over hpsa to use the pci_alloc_irq_vectors including
> the PCI_IRQ_AFFINITY flag that automatically assigns spread out
> irq affinity to the I/O queues.
> 
> It also cleans up the per-ctrl interrupt state due to the use of the
> pci_irq_vector and pci_free_irq_vectors helpers that don't need to know
> the exact irq type.  Additionally it changes a little oddity in the
> existing code that was using different array indixes into the per-vector
> arrays depending on wether a controller is using a single INTx or single
> MSI irq.
> 
> Signed-off-by: Christoph Hellwig <h...@lst.de>

Acked-by: Don Brace <don.br...@microsemi.com>
Tested-by: Don Brace <don.br...@microsemi.com>

> ---
>  drivers/scsi/hpsa.c | 143 
> ++--
>  drivers/scsi/hpsa.h |   6 +--
>  2 files changed, 52 insertions(+), 97 deletions(-)
> 
> diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> index d007ec1..dce8f80 100644
> --- a/drivers/scsi/hpsa.c
> +++ b/drivers/scsi/hpsa.c
> @@ -1001,7 +1001,7 @@ static void set_performant_mode(struct ctlr_info
> *h, struct CommandList *c,
>  {
> if (likely(h->transMethod & CFGTBL_Trans_Performant)) {
> c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
> -   if (unlikely(!h->msix_vector))
> +   if (unlikely(!h->msix_vectors))
> return;
> if (likely(reply_queue == DEFAULT_REPLY_QUEUE))
> c->Header.ReplyQueue =
> @@ -5618,7 +5618,7 @@ static int hpsa_scsi_host_alloc(struct ctlr_info *h)
> sh->sg_tablesize = h->maxsgentries;
> sh->transportt = hpsa_sas_transport_template;
> sh->hostdata[0] = (unsigned long) h;
> -   sh->irq = h->intr[h->intr_mode];
> +   sh->irq = pci_irq_vector(h->pdev, 0);
> sh->unique_id = sh->irq;
> 
> h->scsi_host = sh;
> @@ -7652,67 +7652,41 @@ static int find_PCI_BAR_index(struct pci_dev
> *pdev, unsigned long pci_bar_addr)
> 
>  static void hpsa_disable_interrupt_mode(struct ctlr_info *h)
>  {
> -   if (h->msix_vector) {
> -   if (h->pdev->msix_enabled)
> -   pci_disable_msix(h->pdev);
> -   h->msix_vector = 0;
> -   } else if (h->msi_vector) {
> -   if (h->pdev->msi_enabled)
> -   pci_disable_msi(h->pdev);
> -   h->msi_vector = 0;
> -   }
> +   pci_free_irq_vectors(h->pdev);
> +   h->msix_vectors = 0;
>  }
> 
>  /* If MSI/MSI-X is supported by the kernel we will try to enable it on
>   * controllers that are capable. If not, we use legacy INTx mode.
>   */
> -static void hpsa_interrupt_mode(struct ctlr_info *h)
> +static int hpsa_interrupt_mode(struct ctlr_info *h)
>  {
> -#ifdef CONFIG_PCI_MSI
> -   int err, i;
> -   struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES];
> -
> -   for (i = 0; i < MAX_REPLY_QUEUES; i++) {
> -   hpsa_msix_entries[i].vector = 0;
> -   hpsa_msix_entries[i].entry = i;
> -   }
> +   unsigned int flags = PCI_IRQ_LEGACY;
> +   int ret;
> 
> /* Some boards advertise MSI but don't really support it */
> -   if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) ||
> -   (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11))
> -   goto default_int_mode;
> -   if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) {
> -   dev_info(>pdev->dev, "MSI-X capable controller\n");
> -   h->msix_vector = MAX_REPLY_QUEUES;
> -   if (h->msix_vector > num_online_cpus())
> -   h->msix_vector = num_online_cpus();
> -   err = pci_enable_msix_range(h->pdev, hpsa_msix_entries,
> -   1, h->msix_vector);
> -   if (err < 0) {
> -   dev_warn(>pdev->dev, "MSI-X init failed %d\n", 
> err);
> -   h->msix_vector = 0;
> -   goto single_msi_mode;
> -   } else if (err < h->msix_vector) {
> -   dev_warn(>pdev->dev, "

[PATCH] hpsa: use pci_alloc_irq_vectors and automatic irq affinity

2016-11-09 Thread Christoph Hellwig
This patch converts over hpsa to use the pci_alloc_irq_vectors including
the PCI_IRQ_AFFINITY flag that automatically assigns spread out
irq affinity to the I/O queues.

It also cleans up the per-ctrl interrupt state due to the use of the
pci_irq_vector and pci_free_irq_vectors helpers that don't need to know
the exact irq type.  Additionally it changes a little oddity in the
existing code that was using different array indixes into the per-vector
arrays depending on wether a controller is using a single INTx or single
MSI irq.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/hpsa.c | 143 ++--
 drivers/scsi/hpsa.h |   6 +--
 2 files changed, 52 insertions(+), 97 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index d007ec1..dce8f80 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -1001,7 +1001,7 @@ static void set_performant_mode(struct ctlr_info *h, 
struct CommandList *c,
 {
if (likely(h->transMethod & CFGTBL_Trans_Performant)) {
c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
-   if (unlikely(!h->msix_vector))
+   if (unlikely(!h->msix_vectors))
return;
if (likely(reply_queue == DEFAULT_REPLY_QUEUE))
c->Header.ReplyQueue =
@@ -5618,7 +5618,7 @@ static int hpsa_scsi_host_alloc(struct ctlr_info *h)
sh->sg_tablesize = h->maxsgentries;
sh->transportt = hpsa_sas_transport_template;
sh->hostdata[0] = (unsigned long) h;
-   sh->irq = h->intr[h->intr_mode];
+   sh->irq = pci_irq_vector(h->pdev, 0);
sh->unique_id = sh->irq;
 
h->scsi_host = sh;
@@ -7652,67 +7652,41 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, 
unsigned long pci_bar_addr)
 
 static void hpsa_disable_interrupt_mode(struct ctlr_info *h)
 {
-   if (h->msix_vector) {
-   if (h->pdev->msix_enabled)
-   pci_disable_msix(h->pdev);
-   h->msix_vector = 0;
-   } else if (h->msi_vector) {
-   if (h->pdev->msi_enabled)
-   pci_disable_msi(h->pdev);
-   h->msi_vector = 0;
-   }
+   pci_free_irq_vectors(h->pdev);
+   h->msix_vectors = 0;
 }
 
 /* If MSI/MSI-X is supported by the kernel we will try to enable it on
  * controllers that are capable. If not, we use legacy INTx mode.
  */
-static void hpsa_interrupt_mode(struct ctlr_info *h)
+static int hpsa_interrupt_mode(struct ctlr_info *h)
 {
-#ifdef CONFIG_PCI_MSI
-   int err, i;
-   struct msix_entry hpsa_msix_entries[MAX_REPLY_QUEUES];
-
-   for (i = 0; i < MAX_REPLY_QUEUES; i++) {
-   hpsa_msix_entries[i].vector = 0;
-   hpsa_msix_entries[i].entry = i;
-   }
+   unsigned int flags = PCI_IRQ_LEGACY;
+   int ret;
 
/* Some boards advertise MSI but don't really support it */
-   if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) ||
-   (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11))
-   goto default_int_mode;
-   if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) {
-   dev_info(>pdev->dev, "MSI-X capable controller\n");
-   h->msix_vector = MAX_REPLY_QUEUES;
-   if (h->msix_vector > num_online_cpus())
-   h->msix_vector = num_online_cpus();
-   err = pci_enable_msix_range(h->pdev, hpsa_msix_entries,
-   1, h->msix_vector);
-   if (err < 0) {
-   dev_warn(>pdev->dev, "MSI-X init failed %d\n", err);
-   h->msix_vector = 0;
-   goto single_msi_mode;
-   } else if (err < h->msix_vector) {
-   dev_warn(>pdev->dev, "only %d MSI-X vectors "
-  "available\n", err);
+   switch (h->board_id) {
+   case 0x40700E11:
+   case 0x40800E11:
+   case 0x40820E11:
+   case 0x40830E11:
+   break;
+   default:
+   ret = pci_alloc_irq_vectors(h->pdev, 1, MAX_REPLY_QUEUES,
+   PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
+   if (ret > 0) {
+   h->msix_vectors = ret;
+   return 0;
}
-   h->msix_vector = err;
-   for (i = 0; i < h->msix_vector; i++)
-   h->intr[i] = hpsa_msix_entries[i].vector;
-   return;
-   }
-single_msi_mode:
-   if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) {
-   dev_info(>pdev->dev, "MSI capable controller\n");
-   if (!pci_enable_msi(h->pdev))
-   h->msi_vector = 1;
-   else
-   dev_warn(>pdev->dev, "MSI init failed\n");
+
+   flags |= PCI_IRQ_MSI;
+   break;
}
-default_int_mode: