]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/qla2xxx/qla_isr.c
potential parse error in ifdef
[linux-2.6-omap-h63xx.git] / drivers / scsi / qla2xxx / qla_isr.c
index 626c7178a4341bbf2b482c74d13b6abee23c66cc..ca463469063d56358e2a1c91235f824175e2e738 100644 (file)
@@ -6,6 +6,8 @@
  */
 #include "qla_def.h"
 
+#include <scsi/scsi_tcq.h>
+
 static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
 static void qla2x00_async_event(scsi_qla_host_t *, uint16_t *);
 static void qla2x00_process_completed_request(struct scsi_qla_host *, uint32_t);
@@ -84,12 +86,8 @@ qla2100_intr_handler(int irq, void *dev_id)
 
        if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
            (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
-               spin_lock_irqsave(&ha->mbx_reg_lock, flags);
-
                set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
                up(&ha->mbx_intr_sem);
-
-               spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
        }
 
        return (IRQ_HANDLED);
@@ -132,11 +130,11 @@ qla2300_intr_handler(int irq, void *dev_id)
                if (stat & HSR_RISC_PAUSED) {
                        hccr = RD_REG_WORD(&reg->hccr);
                        if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
-                               qla_printk(KERN_INFO, ha,
-                                   "Parity error -- HCCR=%x.\n", hccr);
+                               qla_printk(KERN_INFO, ha, "Parity error -- "
+                                   "HCCR=%x, Dumping firmware!\n", hccr);
                        else
-                               qla_printk(KERN_INFO, ha,
-                                   "RISC paused -- HCCR=%x.\n", hccr);
+                               qla_printk(KERN_INFO, ha, "RISC paused -- "
+                                   "HCCR=%x, Dumping firmware!\n", hccr);
 
                        /*
                         * Issue a "HARD" reset in order for the RISC
@@ -145,6 +143,8 @@ qla2300_intr_handler(int irq, void *dev_id)
                         */
                        WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
                        RD_REG_WORD(&reg->hccr);
+
+                       ha->isp_ops.fw_dump(ha, 1);
                        set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
                        break;
                } else if ((stat & HSR_RISC_INT) == 0)
@@ -195,12 +195,8 @@ qla2300_intr_handler(int irq, void *dev_id)
 
        if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
            (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
-               spin_lock_irqsave(&ha->mbx_reg_lock, flags);
-
                set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
                up(&ha->mbx_intr_sem);
-
-               spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
        }
 
        return (IRQ_HANDLED);
@@ -473,6 +469,8 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
                        set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
                }
                set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
+
+               ha->flags.gpsc_supported = 1;
                break;
 
        case MBA_CHG_IN_CONNECTION:     /* Change in connection mode */
@@ -593,6 +591,65 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
        }
 }
 
+static void
+qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, void *data)
+{
+       fc_port_t *fcport = data;
+
+       if (fcport->ha->max_q_depth <= sdev->queue_depth)
+               return;
+
+       if (sdev->ordered_tags)
+               scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG,
+                   sdev->queue_depth + 1);
+       else
+               scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG,
+                   sdev->queue_depth + 1);
+
+       fcport->last_ramp_up = jiffies;
+
+       DEBUG2(qla_printk(KERN_INFO, fcport->ha,
+           "scsi(%ld:%d:%d:%d): Queue depth adjusted-up to %d.\n",
+           fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
+           sdev->queue_depth));
+}
+
+static void
+qla2x00_adjust_sdev_qdepth_down(struct scsi_device *sdev, void *data)
+{
+       fc_port_t *fcport = data;
+
+       if (!scsi_track_queue_full(sdev, sdev->queue_depth - 1))
+               return;
+
+       DEBUG2(qla_printk(KERN_INFO, fcport->ha,
+           "scsi(%ld:%d:%d:%d): Queue depth adjusted-down to %d.\n",
+           fcport->ha->host_no, sdev->channel, sdev->id, sdev->lun,
+           sdev->queue_depth));
+}
+
+static inline void
+qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
+{
+       fc_port_t *fcport;
+       struct scsi_device *sdev;
+
+       sdev = sp->cmd->device;
+       if (sdev->queue_depth >= ha->max_q_depth)
+               return;
+
+       fcport = sp->fcport;
+       if (time_before(jiffies,
+           fcport->last_ramp_up + ql2xqfullrampup * HZ))
+               return;
+       if (time_before(jiffies,
+           fcport->last_queue_full + ql2xqfullrampup * HZ))
+               return;
+
+       starget_for_each_device(sdev->sdev_target, fcport,
+           qla2x00_adjust_sdev_qdepth_up);
+}
+
 /**
  * qla2x00_process_completed_request() - Process a Fast Post response.
  * @ha: SCSI driver HA context
@@ -624,6 +681,8 @@ qla2x00_process_completed_request(struct scsi_qla_host *ha, uint32_t index)
 
                /* Save ISP completion status */
                sp->cmd->result = DID_OK << 16;
+
+               qla2x00_ramp_up_queue_depth(ha, sp);
                qla2x00_sp_compl(ha, sp);
        } else {
                DEBUG2(printk("scsi(%ld): Invalid ISP SCSI completion handle\n",
@@ -823,6 +882,7 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
         */
        switch (comp_status) {
        case CS_COMPLETE:
+       case CS_QUEUE_FULL:
                if (scsi_status == 0) {
                        cp->result = DID_OK << 16;
                        break;
@@ -849,6 +909,18 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
                }
                cp->result = DID_OK << 16 | lscsi_status;
 
+               if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
+                       DEBUG2(printk(KERN_INFO
+                           "scsi(%ld): QUEUE FULL status detected "
+                           "0x%x-0x%x.\n", ha->host_no, comp_status,
+                           scsi_status));
+
+                       /* Adjust queue depth for all luns on the port. */
+                       fcport->last_queue_full = jiffies;
+                       starget_for_each_device(cp->device->sdev_target,
+                           fcport, qla2x00_adjust_sdev_qdepth_down);
+                       break;
+               }
                if (lscsi_status != SS_CHECK_CONDITION)
                        break;
 
@@ -911,6 +983,22 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
                if (lscsi_status != 0) {
                        cp->result = DID_OK << 16 | lscsi_status;
 
+                       if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
+                               DEBUG2(printk(KERN_INFO
+                                   "scsi(%ld): QUEUE FULL status detected "
+                                   "0x%x-0x%x.\n", ha->host_no, comp_status,
+                                   scsi_status));
+
+                               /*
+                                * Adjust queue depth for all luns on the
+                                * port.
+                                */
+                               fcport->last_queue_full = jiffies;
+                               starget_for_each_device(
+                                   cp->device->sdev_target, fcport,
+                                   qla2x00_adjust_sdev_qdepth_down);
+                               break;
+                       }
                        if (lscsi_status != SS_CHECK_CONDITION)
                                break;
 
@@ -1066,17 +1154,6 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
                        qla2x00_mark_device_lost(ha, fcport, 1, 1);
                break;
 
-       case CS_QUEUE_FULL:
-               DEBUG2(printk(KERN_INFO
-                   "scsi(%ld): QUEUE FULL status detected 0x%x-0x%x.\n",
-                   ha->host_no, comp_status, scsi_status));
-
-               /* SCSI Mid-Layer handles device queue full */
-
-               cp->result = DID_OK << 16 | lscsi_status;
-
-               break;
-
        default:
                DEBUG3(printk("scsi(%ld): Error detected (unknown status) "
                    "0x%x-0x%x.\n", ha->host_no, comp_status, scsi_status));
@@ -1371,8 +1448,7 @@ qla24xx_intr_handler(int irq, void *dev_id)
 
                        qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
                            "Dumping firmware!\n", hccr);
-                       qla24xx_fw_dump(ha, 1);
-
+                       ha->isp_ops.fw_dump(ha, 1);
                        set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
                        break;
                } else if ((stat & HSRX_RISC_INT) == 0)
@@ -1410,12 +1486,8 @@ qla24xx_intr_handler(int irq, void *dev_id)
 
        if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
            (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
-               spin_lock_irqsave(&ha->mbx_reg_lock, flags);
-
                set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
                up(&ha->mbx_intr_sem);
-
-               spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
        }
 
        return IRQ_HANDLED;
@@ -1464,3 +1536,229 @@ qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
        qla2x00_sp_compl(ha, sp);
 }
 
+static irqreturn_t
+qla24xx_msix_rsp_q(int irq, void *dev_id)
+{
+       scsi_qla_host_t *ha;
+       struct device_reg_24xx __iomem *reg;
+       unsigned long flags;
+
+       ha = dev_id;
+       reg = &ha->iobase->isp24;
+
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+
+       qla24xx_process_response_queue(ha);
+
+       WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
+       RD_REG_DWORD_RELAXED(&reg->hccr);
+
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t
+qla24xx_msix_default(int irq, void *dev_id)
+{
+       scsi_qla_host_t *ha;
+       struct device_reg_24xx __iomem *reg;
+       int             status;
+       unsigned long   flags;
+       unsigned long   iter;
+       uint32_t        stat;
+       uint32_t        hccr;
+       uint16_t        mb[4];
+
+       ha = dev_id;
+       reg = &ha->iobase->isp24;
+       status = 0;
+
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+       for (iter = 50; iter--; ) {
+               stat = RD_REG_DWORD(&reg->host_status);
+               if (stat & HSRX_RISC_PAUSED) {
+                       hccr = RD_REG_DWORD(&reg->hccr);
+
+                       qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
+                           "Dumping firmware!\n", hccr);
+                       ha->isp_ops.fw_dump(ha, 1);
+                       set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
+                       break;
+               } else if ((stat & HSRX_RISC_INT) == 0)
+                       break;
+
+               switch (stat & 0xff) {
+               case 0x1:
+               case 0x2:
+               case 0x10:
+               case 0x11:
+                       qla24xx_mbx_completion(ha, MSW(stat));
+                       status |= MBX_INTERRUPT;
+
+                       break;
+               case 0x12:
+                       mb[0] = MSW(stat);
+                       mb[1] = RD_REG_WORD(&reg->mailbox1);
+                       mb[2] = RD_REG_WORD(&reg->mailbox2);
+                       mb[3] = RD_REG_WORD(&reg->mailbox3);
+                       qla2x00_async_event(ha, mb);
+                       break;
+               case 0x13:
+                       qla24xx_process_response_queue(ha);
+                       break;
+               default:
+                       DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
+                           "(%d).\n",
+                           ha->host_no, stat & 0xff));
+                       break;
+               }
+               WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
+               RD_REG_DWORD_RELAXED(&reg->hccr);
+       }
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+
+       if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
+           (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
+               set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
+               up(&ha->mbx_intr_sem);
+       }
+
+       return IRQ_HANDLED;
+}
+
+/* Interrupt handling helpers. */
+
+struct qla_init_msix_entry {
+       uint16_t entry;
+       uint16_t index;
+       const char *name;
+       irqreturn_t (*handler)(int, void *);
+};
+
+static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
+       { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
+               "qla2xxx (default)", qla24xx_msix_default },
+
+       { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
+               "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
+};
+
+static void
+qla24xx_disable_msix(scsi_qla_host_t *ha)
+{
+       int i;
+       struct qla_msix_entry *qentry;
+
+       for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
+               qentry = &ha->msix_entries[imsix_entries[i].index];
+               if (qentry->have_irq)
+                       free_irq(qentry->msix_vector, ha);
+       }
+       pci_disable_msix(ha->pdev);
+}
+
+static int
+qla24xx_enable_msix(scsi_qla_host_t *ha)
+{
+       int i, ret;
+       struct msix_entry entries[QLA_MSIX_ENTRIES];
+       struct qla_msix_entry *qentry;
+
+       for (i = 0; i < QLA_MSIX_ENTRIES; i++)
+               entries[i].entry = imsix_entries[i].entry;
+
+       ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
+       if (ret) {
+               qla_printk(KERN_WARNING, ha,
+                   "MSI-X: Failed to enable support -- %d/%d\n",
+                   QLA_MSIX_ENTRIES, ret);
+               goto msix_out;
+       }
+       ha->flags.msix_enabled = 1;
+
+       for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
+               qentry = &ha->msix_entries[imsix_entries[i].index];
+               qentry->msix_vector = entries[i].vector;
+               qentry->msix_entry = entries[i].entry;
+               qentry->have_irq = 0;
+               ret = request_irq(qentry->msix_vector,
+                   imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
+               if (ret) {
+                       qla_printk(KERN_WARNING, ha,
+                           "MSI-X: Unable to register handler -- %x/%d.\n",
+                           imsix_entries[i].index, ret);
+                       qla24xx_disable_msix(ha);
+                       goto msix_out;
+               }
+               qentry->have_irq = 1;
+       }
+
+msix_out:
+       return ret;
+}
+
+int
+qla2x00_request_irqs(scsi_qla_host_t *ha)
+{
+       int ret;
+
+       /* If possible, enable MSI-X. */
+       if (!IS_QLA2432(ha))
+               goto skip_msix;
+
+        if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
+           !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
+               DEBUG2(qla_printk(KERN_WARNING, ha,
+                   "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
+                   ha->chip_revision, ha->fw_attributes));
+
+               goto skip_msix;
+       }
+
+       ret = qla24xx_enable_msix(ha);
+       if (!ret) {
+               DEBUG2(qla_printk(KERN_INFO, ha,
+                   "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
+                   ha->fw_attributes));
+               return ret;
+       }
+       qla_printk(KERN_WARNING, ha,
+           "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
+skip_msix:
+
+       if (!IS_QLA24XX(ha))
+               goto skip_msi;
+
+       ret = pci_enable_msi(ha->pdev);
+       if (!ret) {
+               DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
+               ha->flags.msi_enabled = 1;
+       }
+skip_msi:
+
+       ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
+           IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
+       if (!ret) {
+               ha->flags.inta_enabled = 1;
+               ha->host->irq = ha->pdev->irq;
+       } else {
+               qla_printk(KERN_WARNING, ha,
+                   "Failed to reserve interrupt %d already in use.\n",
+                   ha->pdev->irq);
+       }
+
+       return ret;
+}
+
+void
+qla2x00_free_irqs(scsi_qla_host_t *ha)
+{
+
+       if (ha->flags.msix_enabled)
+               qla24xx_disable_msix(ha);
+       else if (ha->flags.inta_enabled) {
+               free_irq(ha->host->irq, ha);
+               pci_disable_msi(ha->pdev);
+       }
+}