Re: [PATCH v2] qla4xxx: switch to pci_alloc_irq_vectors

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

Christoph> And simplify the MSI-X logic in general - just request the
Christoph> two vectors directly instead of going through an indirection
Christoph> table.

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 v2] qla4xxx: switch to pci_alloc_irq_vectors

2016-12-06 Thread Javali, Nilesh

On 06/12/16, 7:26 PM, "Christoph Hellwig"  wrote:

>And simplify the MSI-X logic in general - just request the two
>vectors directly instead of going through an indirection table.
>
>Signed-off-by: Christoph Hellwig 
>---
> drivers/scsi/qla4xxx/ql4_def.h  | 18 +
> drivers/scsi/qla4xxx/ql4_glbl.h |  1 -
> drivers/scsi/qla4xxx/ql4_isr.c  | 27 +
> drivers/scsi/qla4xxx/ql4_nx.c   | 89
>+++--
> 4 files changed, 37 insertions(+), 98 deletions(-)
>
>diff --git a/drivers/scsi/qla4xxx/ql4_def.h
>b/drivers/scsi/qla4xxx/ql4_def.h
>index a7cfc27..aeebefb 100644
>--- a/drivers/scsi/qla4xxx/ql4_def.h
>+++ b/drivers/scsi/qla4xxx/ql4_def.h
>@@ -409,18 +409,9 @@ struct qla4_8xxx_legacy_intr_set {
> 
> /* MSI-X Support */
> 
>-#define QLA_MSIX_DEFAULT  0x00
>-#define QLA_MSIX_RSP_Q0x01
>-
>+#define QLA_MSIX_DEFAULT  0
>+#define QLA_MSIX_RSP_Q1
> #define QLA_MSIX_ENTRIES  2
>-#define QLA_MIDX_DEFAULT  0
>-#define QLA_MIDX_RSP_Q1
>-
>-struct ql4_msix_entry {
>-  int have_irq;
>-  uint16_t msix_vector;
>-  uint16_t msix_entry;
>-};
> 
> /*
>  * ISP Operations
>@@ -572,9 +563,6 @@ struct scsi_qla_host {
> #define AF_IRQ_ATTACHED   10 /* 0x0400 */
> #define AF_DISABLE_ACB_COMPLETE   11 /* 0x0800 */
> #define AF_HA_REMOVAL 12 /* 0x1000 */
>-#define AF_INTx_ENABLED   15 /* 0x8000 */
>-#define AF_MSI_ENABLED16 /* 0x0001 */
>-#define AF_MSIX_ENABLED   17 /* 0x0002 */
> #define AF_MBOX_COMMAND_NOPOLL18 /* 0x0004 */
> #define AF_FW_RECOVERY19 /* 0x0008 */
> #define AF_EEH_BUSY   20 /* 0x0010 */
>@@ -762,8 +750,6 @@ struct scsi_qla_host {
>   struct isp_operations *isp_ops;
>   struct ql82xx_hw_data hw;
> 
>-  struct ql4_msix_entry msix_entries[QLA_MSIX_ENTRIES];
>-
>   uint32_t nx_dev_init_timeout;
>   uint32_t nx_reset_timeout;
>   void *fw_dump;
>diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h
>b/drivers/scsi/qla4xxx/ql4_glbl.h
>index 2559144..bce96a5 100644
>--- a/drivers/scsi/qla4xxx/ql4_glbl.h
>+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
>@@ -134,7 +134,6 @@ int qla4_8xxx_get_flash_info(struct scsi_qla_host
>*ha);
> void qla4_82xx_enable_intrs(struct scsi_qla_host *ha);
> void qla4_82xx_disable_intrs(struct scsi_qla_host *ha);
> int qla4_8xxx_enable_msix(struct scsi_qla_host *ha);
>-void qla4_8xxx_disable_msix(struct scsi_qla_host *ha);
> irqreturn_t qla4_8xxx_msi_handler(int irq, void *dev_id);
> irqreturn_t qla4_8xxx_default_intr_handler(int irq, void *dev_id);
> irqreturn_t qla4_8xxx_msix_rsp_q(int irq, void *dev_id);
>diff --git a/drivers/scsi/qla4xxx/ql4_isr.c
>b/drivers/scsi/qla4xxx/ql4_isr.c
>index 4f9c0f2..d2cd33d 100644
>--- a/drivers/scsi/qla4xxx/ql4_isr.c
>+++ b/drivers/scsi/qla4xxx/ql4_isr.c
>@@ -1107,7 +1107,7 @@ static void qla4_82xx_spurious_interrupt(struct
>scsi_qla_host *ha,
>   DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
>   if (is_qla8022(ha)) {
>   writel(0, >qla4_82xx_reg->host_int);
>-  if (test_bit(AF_INTx_ENABLED, >flags))
>+  if (!ha->pdev->msi_enabled && !ha->pdev->msix_enabled)
>   qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
>   0xfbff);
>   }
>@@ -1564,19 +1564,18 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
> 
> try_msi:
>   /* Trying MSI */
>-  ret = pci_enable_msi(ha->pdev);
>-  if (!ret) {
>+  ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI);
>+  if (ret > 0) {
>   ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
>   0, DRIVER_NAME, ha);
>   if (!ret) {
>   DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
>-  set_bit(AF_MSI_ENABLED, >flags);
>   goto irq_attached;
>   } else {
>   ql4_printk(KERN_WARNING, ha,
>   "MSI: Failed to reserve interrupt %d "
>   "already in use.\n", ha->pdev->irq);
>-  pci_disable_msi(ha->pdev);
>+  pci_free_irq_vectors(ha->pdev);
>   }
>   }
> 
>@@ -1592,7 +1591,6 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
>   IRQF_SHARED, DRIVER_NAME, ha);
>   if (!ret) {
>   DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
>-  set_bit(AF_INTx_ENABLED, >flags);
>   goto irq_attached;
> 
>   } else {
>@@ -1614,14 +1612,11 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
> 
> void qla4xxx_free_irqs(struct scsi_qla_host *ha)
> {
>-  if (test_and_clear_bit(AF_IRQ_ATTACHED, >flags)) {
>-  if (test_bit(AF_MSIX_ENABLED, >flags)) {
>-   

[PATCH v2] qla4xxx: switch to pci_alloc_irq_vectors

2016-12-06 Thread Christoph Hellwig
And simplify the MSI-X logic in general - just request the two
vectors directly instead of going through an indirection table.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/qla4xxx/ql4_def.h  | 18 +
 drivers/scsi/qla4xxx/ql4_glbl.h |  1 -
 drivers/scsi/qla4xxx/ql4_isr.c  | 27 +
 drivers/scsi/qla4xxx/ql4_nx.c   | 89 +++--
 4 files changed, 37 insertions(+), 98 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
index a7cfc27..aeebefb 100644
--- a/drivers/scsi/qla4xxx/ql4_def.h
+++ b/drivers/scsi/qla4xxx/ql4_def.h
@@ -409,18 +409,9 @@ struct qla4_8xxx_legacy_intr_set {
 
 /* MSI-X Support */
 
-#define QLA_MSIX_DEFAULT   0x00
-#define QLA_MSIX_RSP_Q 0x01
-
+#define QLA_MSIX_DEFAULT   0
+#define QLA_MSIX_RSP_Q 1
 #define QLA_MSIX_ENTRIES   2
-#define QLA_MIDX_DEFAULT   0
-#define QLA_MIDX_RSP_Q 1
-
-struct ql4_msix_entry {
-   int have_irq;
-   uint16_t msix_vector;
-   uint16_t msix_entry;
-};
 
 /*
  * ISP Operations
@@ -572,9 +563,6 @@ struct scsi_qla_host {
 #define AF_IRQ_ATTACHED10 /* 0x0400 */
 #define AF_DISABLE_ACB_COMPLETE11 /* 0x0800 */
 #define AF_HA_REMOVAL  12 /* 0x1000 */
-#define AF_INTx_ENABLED15 /* 0x8000 */
-#define AF_MSI_ENABLED 16 /* 0x0001 */
-#define AF_MSIX_ENABLED17 /* 0x0002 */
 #define AF_MBOX_COMMAND_NOPOLL 18 /* 0x0004 */
 #define AF_FW_RECOVERY 19 /* 0x0008 */
 #define AF_EEH_BUSY20 /* 0x0010 */
@@ -762,8 +750,6 @@ struct scsi_qla_host {
struct isp_operations *isp_ops;
struct ql82xx_hw_data hw;
 
-   struct ql4_msix_entry msix_entries[QLA_MSIX_ENTRIES];
-
uint32_t nx_dev_init_timeout;
uint32_t nx_reset_timeout;
void *fw_dump;
diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index 2559144..bce96a5 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -134,7 +134,6 @@ int qla4_8xxx_get_flash_info(struct scsi_qla_host *ha);
 void qla4_82xx_enable_intrs(struct scsi_qla_host *ha);
 void qla4_82xx_disable_intrs(struct scsi_qla_host *ha);
 int qla4_8xxx_enable_msix(struct scsi_qla_host *ha);
-void qla4_8xxx_disable_msix(struct scsi_qla_host *ha);
 irqreturn_t qla4_8xxx_msi_handler(int irq, void *dev_id);
 irqreturn_t qla4_8xxx_default_intr_handler(int irq, void *dev_id);
 irqreturn_t qla4_8xxx_msix_rsp_q(int irq, void *dev_id);
diff --git a/drivers/scsi/qla4xxx/ql4_isr.c b/drivers/scsi/qla4xxx/ql4_isr.c
index 4f9c0f2..d2cd33d 100644
--- a/drivers/scsi/qla4xxx/ql4_isr.c
+++ b/drivers/scsi/qla4xxx/ql4_isr.c
@@ -1107,7 +1107,7 @@ static void qla4_82xx_spurious_interrupt(struct 
scsi_qla_host *ha,
DEBUG2(ql4_printk(KERN_INFO, ha, "Spurious Interrupt\n"));
if (is_qla8022(ha)) {
writel(0, >qla4_82xx_reg->host_int);
-   if (test_bit(AF_INTx_ENABLED, >flags))
+   if (!ha->pdev->msi_enabled && !ha->pdev->msix_enabled)
qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
0xfbff);
}
@@ -1564,19 +1564,18 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
 
 try_msi:
/* Trying MSI */
-   ret = pci_enable_msi(ha->pdev);
-   if (!ret) {
+   ret = pci_alloc_irq_vectors(ha->pdev, 1, 1, PCI_IRQ_MSI);
+   if (ret > 0) {
ret = request_irq(ha->pdev->irq, qla4_8xxx_msi_handler,
0, DRIVER_NAME, ha);
if (!ret) {
DEBUG2(ql4_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
-   set_bit(AF_MSI_ENABLED, >flags);
goto irq_attached;
} else {
ql4_printk(KERN_WARNING, ha,
"MSI: Failed to reserve interrupt %d "
"already in use.\n", ha->pdev->irq);
-   pci_disable_msi(ha->pdev);
+   pci_free_irq_vectors(ha->pdev);
}
}
 
@@ -1592,7 +1591,6 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
IRQF_SHARED, DRIVER_NAME, ha);
if (!ret) {
DEBUG2(ql4_printk(KERN_INFO, ha, "INTx: Enabled.\n"));
-   set_bit(AF_INTx_ENABLED, >flags);
goto irq_attached;
 
} else {
@@ -1614,14 +1612,11 @@ int qla4xxx_request_irqs(struct scsi_qla_host *ha)
 
 void qla4xxx_free_irqs(struct scsi_qla_host *ha)
 {
-   if (test_and_clear_bit(AF_IRQ_ATTACHED, >flags)) {
-   if (test_bit(AF_MSIX_ENABLED, >flags)) {
-   qla4_8xxx_disable_msix(ha);
-   } else if (test_and_clear_bit(AF_MSI_ENABLED, >flags)) {
-   free_irq(ha->pdev->irq, ha);
-