[SCSI] qla4xxx: use CRB Register for Request Queue in-pointer
[linux-2.6.git] / drivers / scsi / qla4xxx / ql4_mbx.c
index 0d3a652..2d2f9c8 100644 (file)
@@ -39,6 +39,22 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
                              "pointer\n", ha->host_no, __func__));
                return status;
        }
+
+       if (is_qla8022(ha) &&
+           test_bit(AF_FW_RECOVERY, &ha->flags)) {
+               DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: prematurely "
+                   "completing mbx cmd as firmware recovery detected\n",
+                   ha->host_no, __func__));
+               return status;
+       }
+
+       if ((is_aer_supported(ha)) &&
+           (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
+               DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
+                   "timeout MBX Exiting.\n", ha->host_no, __func__));
+               return status;
+       }
+
        /* Mailbox code active */
        wait_count = MBOX_TOV * 100;
 
@@ -150,6 +166,7 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
                while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
                        if (time_after_eq(jiffies, wait_count))
                                break;
+
                        /*
                         * Service the interrupt.
                         * The ISR will save the mailbox status registers
@@ -196,6 +213,14 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
 
        /* Check for mailbox timeout. */
        if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
+               if (is_qla8022(ha) &&
+                   test_bit(AF_FW_RECOVERY, &ha->flags)) {
+                       DEBUG2(ql4_printk(KERN_INFO, ha,
+                           "scsi%ld: %s: prematurely completing mbx cmd as "
+                           "firmware recovery detected\n",
+                           ha->host_no, __func__));
+                       goto mbox_exit;
+               }
                DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
                              " Scheduling Adapter Reset\n", ha->host_no,
                              mbx_cmd[0]));
@@ -246,12 +271,38 @@ mbox_exit:
        return status;
 }
 
+void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
+{
+       set_bit(AF_FW_RECOVERY, &ha->flags);
+       ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
+           ha->host_no, __func__);
+
+       if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
+               if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
+                       complete(&ha->mbx_intr_comp);
+                       ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
+                           "recovery, doing premature completion of "
+                           "mbx cmd\n", ha->host_no, __func__);
+
+               } else {
+                       set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
+                       ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
+                           "recovery, doing premature completion of "
+                           "polling mbx cmd\n", ha->host_no, __func__);
+               }
+       }
+}
+
 static uint8_t
 qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
                 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
 {
        memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
        memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
+
+       if (is_qla8022(ha))
+               qla4_8xxx_wr_32(ha, ha->nx_db_wr_ptr, 0);
+
        mbox_cmd[0] = MBOX_CMD_INITIALIZE_FIRMWARE;
        mbox_cmd[1] = 0;
        mbox_cmd[2] = LSDW(init_fw_cb_dma);
@@ -361,7 +412,6 @@ qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
               min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
 
        /* Save Command Line Paramater info */
-       ha->port_down_retry_count = le16_to_cpu(init_fw_cb->conn_ka_timeout);
        ha->discovery_wait = ql4xdiscoverywait;
 
        if (ha->acb_version == ACB_SUPPORTED) {
@@ -426,6 +476,11 @@ int qla4xxx_initialize_fw_cb(struct scsi_qla_host * ha)
        init_fw_cb->fw_options |=
                __constant_cpu_to_le16(FWOPT_SESSION_MODE |
                                       FWOPT_INITIATOR_MODE);
+
+       if (is_qla8022(ha))
+               init_fw_cb->fw_options |=
+                   __constant_cpu_to_le16(FWOPT_ENABLE_CRBDB);
+
        init_fw_cb->fw_options &= __constant_cpu_to_le16(~FWOPT_TARGET_MODE);
 
        if (qla4xxx_set_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)
@@ -546,7 +601,7 @@ int qla4xxx_get_firmware_status(struct scsi_qla_host * ha)
        }
 
        ql4_printk(KERN_INFO, ha, "%ld firmare IOCBs available (%d).\n",
-           ha->host_no, mbox_cmd[2]);
+           ha->host_no, mbox_sts[2]);
 
        return QLA_SUCCESS;
 }
@@ -607,7 +662,7 @@ int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
        if (fw_ddb_entry) {
                options = le16_to_cpu(fw_ddb_entry->options);
                if (options & DDB_OPT_IPV6_DEVICE) {
-                       dev_info(&ha->pdev->dev, "%s: DDB[%d] MB0 %04x Tot %d "
+                       ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
                                "Next %d State %04x ConnErr %08x %pI6 "
                                ":%04d \"%s\"\n", __func__, fw_ddb_index,
                                mbox_sts[0], mbox_sts[2], mbox_sts[3],
@@ -616,7 +671,7 @@ int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
                                le16_to_cpu(fw_ddb_entry->port),
                                fw_ddb_entry->iscsi_name);
                } else {
-                       dev_info(&ha->pdev->dev, "%s: DDB[%d] MB0 %04x Tot %d "
+                       ql4_printk(KERN_INFO, ha, "%s: DDB[%d] MB0 %04x Tot %d "
                                "Next %d State %04x ConnErr %08x %pI4 "
                                ":%04d \"%s\"\n", __func__, fw_ddb_index,
                                mbox_sts[0], mbox_sts[2], mbox_sts[3],