]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/scsi/qla2xxx/qla_init.c
[SCSI] Maintain module-parameter name consistency with qla2xxx/qla4xxx.
[linux-2.6.git] / drivers / scsi / qla2xxx / qla_init.c
index e38d0cf7363729c3adfa1da5cf8a796abaf5f971..d5e0a124c4f429e3d513ff1c66cda23a4885c5cb 100644 (file)
@@ -1,27 +1,13 @@
 /*
- *                  QLOGIC LINUX SOFTWARE
- *
- * QLogic ISP2x00 device driver for Linux 2.6.x
- * Copyright (C) 2003-2005 QLogic Corporation
- * (www.qlogic.com)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * QLogic Fibre Channel HBA Driver
+ * Copyright (c)  2003-2005 QLogic Corporation
  *
+ * See LICENSE.qla2xxx for copyright and licensing details.
  */
 #include "qla_def.h"
 
 #include <linux/delay.h>
 #include <linux/vmalloc.h>
-#include <linux/firmware.h>
-#include <scsi/scsi_transport_fc.h>
 
 #include "qla_devtbl.h"
 
@@ -45,7 +31,6 @@ static int qla2x00_fw_ready(scsi_qla_host_t *);
 static int qla2x00_configure_hba(scsi_qla_host_t *);
 static int qla2x00_configure_loop(scsi_qla_host_t *);
 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
-static void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
 static int qla2x00_configure_fabric(scsi_qla_host_t *);
 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
 static int qla2x00_device_resync(scsi_qla_host_t *);
@@ -54,6 +39,8 @@ static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
 
 static int qla2x00_restart_isp(scsi_qla_host_t *);
 
+static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
+
 /****************************************************************************/
 /*                QLogic ISP2x00 Hardware Support Functions.                */
 /****************************************************************************/
@@ -104,6 +91,17 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
 
        ha->isp_ops.nvram_config(ha);
 
+       if (ha->flags.disable_serdes) {
+               /* Mask HBA via NVRAM settings? */
+               qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
+                   "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
+                   ha->port_name[0], ha->port_name[1],
+                   ha->port_name[2], ha->port_name[3],
+                   ha->port_name[4], ha->port_name[5],
+                   ha->port_name[6], ha->port_name[7]);
+               return QLA_FUNCTION_FAILED;
+       }
+
        qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
 
        retry = 10;
@@ -159,8 +157,8 @@ check_fw_ready_again:
                                         * LIP to complete
                                         */
 
-                                       if (atomic_read(&ha->loop_state) ==
-                                           LOOP_DOWN && retry--) {
+                                       if (atomic_read(&ha->loop_state) !=
+                                           LOOP_READY && retry--) {
                                                goto check_fw_ready_again;
                                        }
                                        wait_time--;
@@ -201,6 +199,7 @@ int
 qla2100_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t w, mwi;
+       uint32_t d;
        unsigned long flags;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
 
@@ -208,16 +207,15 @@ qla2100_pci_config(scsi_qla_host_t *ha)
        mwi = 0;
        if (pci_set_mwi(ha->pdev))
                mwi = PCI_COMMAND_INVALIDATE;
-       pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
 
        pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
        w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
        pci_write_config_word(ha->pdev, PCI_COMMAND, w);
 
        /* Reset expansion ROM address decode enable */
-       pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
-       w &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
+       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
+       d &= ~PCI_ROM_ADDRESS_ENABLE;
+       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
 
        /* Get PCI bus information. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -237,6 +235,7 @@ int
 qla2300_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t        w, mwi;
+       uint32_t        d;
        unsigned long   flags = 0;
        uint32_t        cnt;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
@@ -245,7 +244,6 @@ qla2300_pci_config(scsi_qla_host_t *ha)
        mwi = 0;
        if (pci_set_mwi(ha->pdev))
                mwi = PCI_COMMAND_INVALIDATE;
-       pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
 
        pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
        w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
@@ -302,9 +300,9 @@ qla2300_pci_config(scsi_qla_host_t *ha)
        pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
 
        /* Reset expansion ROM address decode enable */
-       pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
-       w &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
+       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
+       d &= ~PCI_ROM_ADDRESS_ENABLE;
+       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
 
        /* Get PCI bus information. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -324,6 +322,7 @@ int
 qla24xx_pci_config(scsi_qla_host_t *ha)
 {
        uint16_t w, mwi;
+       uint32_t d;
        unsigned long flags = 0;
        struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
        int pcix_cmd_reg, pcie_dctl_reg;
@@ -332,7 +331,6 @@ qla24xx_pci_config(scsi_qla_host_t *ha)
        mwi = 0;
        if (pci_set_mwi(ha->pdev))
                mwi = PCI_COMMAND_INVALIDATE;
-       pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->revision);
 
        pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
        w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
@@ -366,9 +364,9 @@ qla24xx_pci_config(scsi_qla_host_t *ha)
        }
 
        /* Reset expansion ROM address decode enable */
-       pci_read_config_word(ha->pdev, PCI_ROM_ADDRESS, &w);
-       w &= ~PCI_ROM_ADDRESS_ENABLE;
-       pci_write_config_word(ha->pdev, PCI_ROM_ADDRESS, w);
+       pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
+       d &= ~PCI_ROM_ADDRESS_ENABLE;
+       pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
 
        /* Get PCI bus information. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
@@ -398,9 +396,7 @@ qla2x00_isp_firmware(scsi_qla_host_t *ha)
                qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
 
                /* Verify checksum of loaded RISC code. */
-               rval = qla2x00_verify_checksum(ha,
-                   IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RISC_SADDRESS :
-                   *ha->brd_info->fw_info[0].fwstart);
+               rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
        }
 
        if (rval) {
@@ -423,7 +419,6 @@ qla2x00_reset_chip(scsi_qla_host_t *ha)
        unsigned long   flags = 0;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
        uint32_t        cnt;
-       unsigned long   mbx_flags = 0;
        uint16_t        cmd;
 
        ha->isp_ops.disable_intrs(ha);
@@ -531,20 +526,8 @@ qla2x00_reset_chip(scsi_qla_host_t *ha)
 
        if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
                for (cnt = 0; cnt < 30000; cnt++) {
-                       if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
-                               spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
-
-                       if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) {
-                               if (!(test_bit(ABORT_ISP_ACTIVE,
-                                   &ha->dpc_flags)))
-                                       spin_unlock_irqrestore(
-                                           &ha->mbx_reg_lock, mbx_flags);
+                       if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
                                break;
-                       }
-
-                       if (!(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)))
-                               spin_unlock_irqrestore(&ha->mbx_reg_lock,
-                                   mbx_flags);
 
                        udelay(100);
                }
@@ -576,6 +559,7 @@ qla24xx_reset_risc(scsi_qla_host_t *ha)
        unsigned long flags = 0;
        struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
        uint32_t cnt, d2;
+       uint16_t wd;
 
        spin_lock_irqsave(&ha->hardware_lock, flags);
 
@@ -590,10 +574,10 @@ qla24xx_reset_risc(scsi_qla_host_t *ha)
 
        WRT_REG_DWORD(&reg->ctrl_status,
            CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
-       RD_REG_DWORD(&reg->ctrl_status);
+       pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
 
+       udelay(100);
        /* Wait for firmware to complete NVRAM accesses. */
-       udelay(5);
        d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
        for (cnt = 10000 ; cnt && d2; cnt--) {
                udelay(5);
@@ -601,7 +585,7 @@ qla24xx_reset_risc(scsi_qla_host_t *ha)
                barrier();
        }
 
-       udelay(20);
+       /* Wait for soft-reset to complete. */
        d2 = RD_REG_DWORD(&reg->ctrl_status);
        for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
                udelay(5);
@@ -738,6 +722,7 @@ qla2x00_chip_diag(scsi_qla_host_t *ha)
                DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
                    ha->host_no));
 
+               ha->device_type |= DT_ISP2200A;
                ha->fw_transfer_size = 128;
        }
 
@@ -798,19 +783,104 @@ qla24xx_chip_diag(scsi_qla_host_t *ha)
        return rval;
 }
 
-static void
+void
 qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
 {
+       int rval;
+       uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
+           eft_size;
+       dma_addr_t eft_dma;
+       void *eft;
+
+       if (ha->fw_dump) {
+               qla_printk(KERN_WARNING, ha,
+                   "Firmware dump previously allocated.\n");
+               return;
+       }
+
        ha->fw_dumped = 0;
-       ha->fw_dump24_len = sizeof(struct qla24xx_fw_dump);
-       ha->fw_dump24_len += (ha->fw_memory_size - 0x100000) * sizeof(uint32_t);
-       ha->fw_dump24 = vmalloc(ha->fw_dump24_len);
-       if (ha->fw_dump24)
-               qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware "
-                   "dump...\n", ha->fw_dump24_len / 1024);
-       else
+       fixed_size = mem_size = eft_size = 0;
+       if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
+               fixed_size = sizeof(struct qla2100_fw_dump);
+       } else if (IS_QLA23XX(ha)) {
+               fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
+               mem_size = (ha->fw_memory_size - 0x11000 + 1) *
+                   sizeof(uint16_t);
+       } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+               fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
+               mem_size = (ha->fw_memory_size - 0x100000 + 1) *
+                   sizeof(uint32_t);
+
+               /* Allocate memory for Extended Trace Buffer. */
+               eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
+                   GFP_KERNEL);
+               if (!eft) {
+                       qla_printk(KERN_WARNING, ha, "Unable to allocate "
+                           "(%d KB) for EFT.\n", EFT_SIZE / 1024);
+                       goto cont_alloc;
+               }
+
+               rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
+                   EFT_NUM_BUFFERS);
+               if (rval) {
+                       qla_printk(KERN_WARNING, ha, "Unable to initialize "
+                           "EFT (%d).\n", rval);
+                       dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
+                           eft_dma);
+                       goto cont_alloc;
+               }
+
+               qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
+                   EFT_SIZE / 1024);
+
+               eft_size = EFT_SIZE;
+               memset(eft, 0, eft_size);
+               ha->eft_dma = eft_dma;
+               ha->eft = eft;
+       }
+cont_alloc:
+       req_q_size = ha->request_q_length * sizeof(request_t);
+       rsp_q_size = ha->response_q_length * sizeof(response_t);
+
+       dump_size = offsetof(struct qla2xxx_fw_dump, isp);
+       dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
+           eft_size;
+
+       ha->fw_dump = vmalloc(dump_size);
+       if (!ha->fw_dump) {
                qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
-                   "firmware dump!!!\n", ha->fw_dump24_len / 1024);
+                   "firmware dump!!!\n", dump_size / 1024);
+
+               if (ha->eft) {
+                       dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
+                           ha->eft_dma);
+                       ha->eft = NULL;
+                       ha->eft_dma = 0;
+               }
+               return;
+       }
+
+       qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
+           dump_size / 1024);
+
+       ha->fw_dump_len = dump_size;
+       ha->fw_dump->signature[0] = 'Q';
+       ha->fw_dump->signature[1] = 'L';
+       ha->fw_dump->signature[2] = 'G';
+       ha->fw_dump->signature[3] = 'C';
+       ha->fw_dump->version = __constant_htonl(1);
+
+       ha->fw_dump->fixed_size = htonl(fixed_size);
+       ha->fw_dump->mem_size = htonl(mem_size);
+       ha->fw_dump->req_q_size = htonl(req_q_size);
+       ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
+
+       ha->fw_dump->eft_size = htonl(eft_size);
+       ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
+       ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
+
+       ha->fw_dump->header_size =
+           htonl(offsetof(struct qla2xxx_fw_dump, isp));
 }
 
 /**
@@ -832,9 +902,6 @@ qla2x00_resize_request_q(scsi_qla_host_t *ha)
        if (IS_QLA2100(ha) || IS_QLA2200(ha))
                return;
 
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
-               qla2x00_alloc_fw_dump(ha);
-
        /* Retrieve IOCB counts available to the firmware. */
        rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt);
        if (rval)
@@ -902,6 +969,9 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
                                    &ha->fw_subminor_version,
                                    &ha->fw_attributes, &ha->fw_memory_size);
                                qla2x00_resize_request_q(ha);
+
+                               if (ql2xallocfwdump)
+                                       qla2x00_alloc_fw_dump(ha);
                        }
                } else {
                        DEBUG2(printk(KERN_INFO
@@ -1013,6 +1083,10 @@ qla2x00_update_fw_options(scsi_qla_host_t *ha)
        if (ha->flags.enable_led_scheme)
                ha->fw_options[2] |= BIT_12;
 
+       /* Detect ISP6312. */
+       if (IS_QLA6312(ha))
+               ha->fw_options[2] |= BIT_13;
+
        /* Update firmware options. */
        qla2x00_set_fw_options(ha, ha->fw_options);
 }
@@ -1023,11 +1097,13 @@ qla24xx_update_fw_options(scsi_qla_host_t *ha)
        int rval;
 
        /* Update Serial Link options. */
-       if ((ha->fw_seriallink_options24[0] & BIT_0) == 0)
+       if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
                return;
 
-       rval = qla2x00_set_serdes_params(ha, ha->fw_seriallink_options24[1],
-           ha->fw_seriallink_options24[2], ha->fw_seriallink_options24[3]);
+       rval = qla2x00_set_serdes_params(ha,
+           le16_to_cpu(ha->fw_seriallink_options24[1]),
+           le16_to_cpu(ha->fw_seriallink_options24[2]),
+           le16_to_cpu(ha->fw_seriallink_options24[3]));
        if (rval != QLA_SUCCESS) {
                qla_printk(KERN_WARNING, ha,
                    "Unable to update Serial Link options (%x).\n", rval);
@@ -1199,8 +1275,7 @@ qla2x00_fw_ready(scsi_qla_host_t *ha)
                        rval = QLA_FUNCTION_FAILED;
 
                        if (atomic_read(&ha->loop_down_timer) &&
-                           (fw_state >= FSTATE_LOSS_OF_SYNC ||
-                               fw_state == FSTATE_WAIT_AL_PA)) {
+                           fw_state != FSTATE_READY) {
                                /* Loop down. Timeout on min_wait for states
                                 * other than Wait for Login.
                                 */
@@ -1267,9 +1342,15 @@ qla2x00_configure_hba(scsi_qla_host_t *ha)
        rval = qla2x00_get_adapter_id(ha,
            &loop_id, &al_pa, &area, &domain, &topo);
        if (rval != QLA_SUCCESS) {
-               qla_printk(KERN_WARNING, ha,
-                   "ERROR -- Unable to get host loop ID.\n");
-               set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
+               if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
+                   (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
+                       DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
+                           __func__, ha->host_no));
+               } else {
+                       qla_printk(KERN_WARNING, ha,
+                           "ERROR -- Unable to get host loop ID.\n");
+                       set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
+               }
                return (rval);
        }
 
@@ -1369,7 +1450,6 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
        nvram_t         *nv = (nvram_t *)ha->request_ring;
        uint8_t         *ptr = (uint8_t *)ha->request_ring;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
-       uint8_t         timer_mode;
 
        rval = QLA_SUCCESS;
 
@@ -1504,9 +1584,9 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
                                index = (ha->pdev->subsystem_device & 0xff);
                                if (index < QLA_MODEL_NAMES) {
                                        strcpy(ha->model_number,
-                                           qla2x00_model_name[index]);
+                                           qla2x00_model_name[index * 2]);
                                        ha->model_desc =
-                                           qla2x00_model_desc[index];
+                                           qla2x00_model_name[index * 2 + 1];
                                } else {
                                        strcpy(ha->model_number, "QLA23xx");
                                }
@@ -1544,6 +1624,12 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
        while (cnt--)
                *dptr1++ = *dptr2++;
 
+       /* Use alternate WWN? */
+       if (nv->host_p[1] & BIT_7) {
+               memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
+               memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
+       }
+
        /* Prepare nodename */
        if ((icb->firmware_options[1] & BIT_6) == 0) {
                /*
@@ -1557,6 +1643,8 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
        /*
         * Set host adapter parameters.
         */
+       if (nv->host_p[0] & BIT_7)
+               ql2xextended_error_logging = 1;
        ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
        /* Always load RISC code on non ISP2[12]00 chips. */
        if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
@@ -1564,7 +1652,8 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
        ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
        ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
        ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
-       ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0);
+       ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
+       ha->flags.disable_serdes = 0;
 
        ha->operating_mode =
            (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
@@ -1647,22 +1736,28 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
 
                ha->flags.process_response_queue = 1;
        } else {
-               /* Enable ZIO -- Support mode 5 only. */
-               timer_mode = icb->add_firmware_options[0] &
-                   (BIT_3 | BIT_2 | BIT_1 | BIT_0);
+               /* Enable ZIO. */
+               if (!ha->flags.init_done) {
+                       ha->zio_mode = icb->add_firmware_options[0] &
+                           (BIT_3 | BIT_2 | BIT_1 | BIT_0);
+                       ha->zio_timer = icb->interrupt_delay_timer ?
+                           icb->interrupt_delay_timer: 2;
+               }
                icb->add_firmware_options[0] &=
                    ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
-               if (ql2xenablezio)
-                       timer_mode = BIT_2 | BIT_0;
-               if (timer_mode == (BIT_2 | BIT_0)) {
-                       DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
-                           "(%d).\n", ha->host_no, ql2xintrdelaytimer));
+               ha->flags.process_response_queue = 0;
+               if (ha->zio_mode != QLA_ZIO_DISABLED) {
+                       ha->zio_mode = QLA_ZIO_MODE_6;
+
+                       DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
+                           "delay (%d us).\n", ha->host_no, ha->zio_mode,
+                           ha->zio_timer * 100));
                        qla_printk(KERN_INFO, ha,
-                           "ZIO enabled; timer delay (%d).\n",
-                           ql2xintrdelaytimer);
+                           "ZIO mode %d enabled; timer delay (%d us).\n",
+                           ha->zio_mode, ha->zio_timer * 100);
 
-                       icb->add_firmware_options[0] |= timer_mode;
-                       icb->interrupt_delay_timer = ql2xintrdelaytimer;
+                       icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
+                       icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
                        ha->flags.process_response_queue = 1;
                }
        }
@@ -1674,6 +1769,22 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
        return (rval);
 }
 
+static void
+qla2x00_rport_del(void *data)
+{
+       fc_port_t *fcport = data;
+       struct fc_rport *rport;
+       unsigned long flags;
+
+       spin_lock_irqsave(&fcport->rport_lock, flags);
+       rport = fcport->drport;
+       fcport->drport = NULL;
+       spin_unlock_irqrestore(&fcport->rport_lock, flags);
+       if (rport)
+               fc_remote_port_delete(rport);
+
+}
+
 /**
  * qla2x00_alloc_fcport() - Allocate a generic fcport.
  * @ha: HA context
@@ -1681,8 +1792,8 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
  *
  * Returns a pointer to the allocated fcport, or NULL, if none available.
  */
-fc_port_t *
-qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
+static fc_port_t *
+qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
 {
        fc_port_t *fcport;
 
@@ -1695,10 +1806,10 @@ qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
        fcport->ha = ha;
        fcport->port_type = FCT_UNKNOWN;
        fcport->loop_id = FC_NO_LOOP_ID;
-       fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
        atomic_set(&fcport->state, FCS_UNCONFIGURED);
        fcport->flags = FCF_RLC_SUPPORT;
        fcport->supported_classes = FC_COS_UNSPECIFIED;
+       spin_lock_init(&fcport->rport_lock);
 
        return (fcport);
 }
@@ -1758,6 +1869,9 @@ qla2x00_configure_loop(scsi_qla_host_t *ha)
                set_bit(RSCN_UPDATE, &flags);
                clear_bit(LOCAL_LOOP_UPDATE, &flags);
 
+       } else if (ha->current_topology == ISP_CFG_N) {
+               clear_bit(RSCN_UPDATE, &flags);
+
        } else if (!ha->flags.online ||
            (test_bit(ABORT_ISP_ACTIVE, &flags))) {
 
@@ -1775,7 +1889,7 @@ qla2x00_configure_loop(scsi_qla_host_t *ha)
        }
 
        if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
-               if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
+               if (LOOP_TRANSITION(ha)) {
                        rval = QLA_FUNCTION_FAILED;
                } else {
                        rval = qla2x00_configure_fabric(ha);
@@ -1900,7 +2014,8 @@ qla2x00_configure_local_loop(scsi_qla_host_t *ha)
                        continue;
 
                /* Bypass if not same domain and area of adapter. */
-               if (area != ha->d_id.b.area || domain != ha->d_id.b.domain)
+               if (area && domain &&
+                   (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
                        continue;
 
                /* Bypass invalid local loop ID. */
@@ -1918,6 +2033,9 @@ qla2x00_configure_local_loop(scsi_qla_host_t *ha)
                            "information -- get_port_database=%x, "
                            "loop_id=0x%04x\n",
                            ha->host_no, rval2, new_fcport->loop_id));
+                       DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
+                           ha->host_no));
+                       set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
                        continue;
                }
 
@@ -1956,14 +2074,26 @@ qla2x00_configure_local_loop(scsi_qla_host_t *ha)
                        new_fcport->flags &= ~FCF_FABRIC_DEVICE;
                }
 
+               /* Base iIDMA settings on HBA port speed. */
+               switch (ha->link_data_rate) {
+               case PORT_SPEED_1GB:
+                       fcport->fp_speed = cpu_to_be16(BIT_15);
+                       break;
+               case PORT_SPEED_2GB:
+                       fcport->fp_speed = cpu_to_be16(BIT_14);
+                       break;
+               case PORT_SPEED_4GB:
+                       fcport->fp_speed = cpu_to_be16(BIT_13);
+                       break;
+               }
+
                qla2x00_update_fcport(ha, fcport);
 
                found_devs++;
        }
 
 cleanup_allocation:
-       if (new_fcport)
-               kfree(new_fcport);
+       kfree(new_fcport);
 
        if (rval != QLA_SUCCESS) {
                DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
@@ -1983,7 +2113,7 @@ qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
 {
        fc_port_t       *fcport;
 
-       qla2x00_mark_all_devices_lost(ha);
+       qla2x00_mark_all_devices_lost(ha, 0);
        list_for_each_entry(fcport, &ha->fcports, list) {
                if (fcport->port_type != FCT_TARGET)
                        continue;
@@ -1992,6 +2122,62 @@ qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
        }
 }
 
+static void
+qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
+{
+#define LS_UNKNOWN      2
+       static char *link_speeds[5] = { "1", "2", "?", "4" };
+       int rval;
+       uint16_t port_speed, mb[6];
+
+       if (!IS_QLA24XX(ha))
+               return;
+
+       switch (be16_to_cpu(fcport->fp_speed)) {
+       case BIT_15:
+               port_speed = PORT_SPEED_1GB;
+               break;
+       case BIT_14:
+               port_speed = PORT_SPEED_2GB;
+               break;
+       case BIT_13:
+               port_speed = PORT_SPEED_4GB;
+               break;
+       default:
+               DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
+                   "unsupported FM port operating speed (%04x).\n",
+                   ha->host_no, fcport->port_name[0], fcport->port_name[1],
+                   fcport->port_name[2], fcport->port_name[3],
+                   fcport->port_name[4], fcport->port_name[5],
+                   fcport->port_name[6], fcport->port_name[7],
+                   be16_to_cpu(fcport->fp_speed)));
+               port_speed = PORT_SPEED_UNKNOWN;
+               break;
+       }
+       if (port_speed == PORT_SPEED_UNKNOWN)
+               return;
+
+       rval = qla2x00_set_idma_speed(ha, fcport->loop_id, port_speed, mb);
+       if (rval != QLA_SUCCESS) {
+               DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
+                   "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
+                   ha->host_no, fcport->port_name[0], fcport->port_name[1],
+                   fcport->port_name[2], fcport->port_name[3],
+                   fcport->port_name[4], fcport->port_name[5],
+                   fcport->port_name[6], fcport->port_name[7], rval,
+                   port_speed, mb[0], mb[1]));
+       } else {
+               DEBUG2(qla_printk(KERN_INFO, ha,
+                   "iIDMA adjusted to %s GB/s on "
+                   "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
+                   link_speeds[port_speed], fcport->port_name[0],
+                   fcport->port_name[1], fcport->port_name[2],
+                   fcport->port_name[3], fcport->port_name[4],
+                   fcport->port_name[5], fcport->port_name[6],
+                   fcport->port_name[7]));
+       }
+}
+
 /*
  * qla2x00_update_fcport
  *     Updates device on list.
@@ -2007,13 +2193,9 @@ qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
  * Context:
  *     Kernel context.
  */
-static void
+void
 qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
 {
-       uint16_t        index;
-       unsigned long flags;
-       srb_t *sp;
-
        fcport->ha = ha;
        fcport->login_retry = 0;
        fcport->port_login_retry_count = ha->port_down_retry_count *
@@ -2022,31 +2204,7 @@ qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
            PORT_RETRY_TIME);
        fcport->flags &= ~FCF_LOGIN_NEEDED;
 
-       /*
-        * Check for outstanding cmd on tape Bypass LUN discovery if active
-        * command on tape.
-        */
-       if (fcport->flags & FCF_TAPE_PRESENT) {
-               spin_lock_irqsave(&ha->hardware_lock, flags);
-               for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
-                       fc_port_t *sfcp;
-
-                       if ((sp = ha->outstanding_cmds[index]) != 0) {
-                               sfcp = sp->fcport;
-                               if (sfcp == fcport) {
-                                       atomic_set(&fcport->state, FCS_ONLINE);
-                                       spin_unlock_irqrestore(
-                                           &ha->hardware_lock, flags);
-                                       return;
-                               }
-                       }
-               }
-               spin_unlock_irqrestore(&ha->hardware_lock, flags);
-       }
-
-       if (fcport->port_type == FCT_INITIATOR ||
-           fcport->port_type == FCT_BROADCAST)
-               fcport->device_type = TYPE_PROCESSOR;
+       qla2x00_iidma_fcport(ha, fcport);
 
        atomic_set(&fcport->state, FCS_ONLINE);
 
@@ -2059,24 +2217,29 @@ qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
 {
        struct fc_rport_identifiers rport_ids;
        struct fc_rport *rport;
+       unsigned long flags;
 
-       if (fcport->rport) {
-               fc_remote_port_unblock(fcport->rport);
+       if (fcport->drport)
+               qla2x00_rport_del(fcport);
+       if (fcport->rport)
                return;
-       }
 
-       rport_ids.node_name = be64_to_cpu(*(uint64_t *)fcport->node_name);
-       rport_ids.port_name = be64_to_cpu(*(uint64_t *)fcport->port_name);
+       rport_ids.node_name = wwn_to_u64(fcport->node_name);
+       rport_ids.port_name = wwn_to_u64(fcport->port_name);
        rport_ids.port_id = fcport->d_id.b.domain << 16 |
            fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
        rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
-       fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
+       rport = fc_remote_port_add(ha->host, 0, &rport_ids);
        if (!rport) {
                qla_printk(KERN_WARNING, ha,
                    "Unable to allocate fc remote port!\n");
                return;
        }
-       rport->dd_data = fcport;
+       spin_lock_irqsave(&fcport->rport_lock, flags);
+       fcport->rport = rport;
+       *((fc_port_t **)rport->dd_data) = fcport;
+       spin_unlock_irqrestore(&fcport->rport_lock, flags);
+
        rport->supported_classes = fcport->supported_classes;
 
        rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
@@ -2113,11 +2276,11 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
        LIST_HEAD(new_fcports);
 
        /* If FL port exists, then SNS is present */
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
                loop_id = NPH_F_PORT;
        else
                loop_id = SNS_FL_PORT;
-       rval = qla2x00_get_port_name(ha, loop_id, NULL, 0);
+       rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
        if (rval != QLA_SUCCESS) {
                DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
                    "Port\n", ha->host_no));
@@ -2125,6 +2288,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
                ha->device_flags &= ~SWITCH_FOUND;
                return (QLA_SUCCESS);
        }
+       ha->device_flags |= SWITCH_FOUND;
 
        /* Mark devices that need re-synchronization. */
        rval2 = qla2x00_device_resync(ha);
@@ -2139,7 +2303,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
                        qla2x00_fdmi_register(ha);
 
                /* Ensure we are logged into the SNS. */
-               if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
                        loop_id = NPH_SNS;
                else
                        loop_id = SIMPLE_NAME_SERVER;
@@ -2192,12 +2356,11 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
 
                        if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
                                qla2x00_mark_device_lost(ha, fcport,
-                                   ql2xplogiabsentdevice);
+                                   ql2xplogiabsentdevice, 0);
                                if (fcport->loop_id != FC_NO_LOOP_ID &&
                                    (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
                                    fcport->port_type != FCT_INITIATOR &&
                                    fcport->port_type != FCT_BROADCAST) {
-
                                        ha->isp_ops.fabric_logout(ha,
                                            fcport->loop_id,
                                            fcport->d_id.b.domain,
@@ -2258,8 +2421,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
                        }
 
                        /* Remove device from the new list and add it to DB */
-                       list_del(&fcport->list);
-                       list_add_tail(&fcport->list, &ha->fcports);
+                       list_move_tail(&fcport->list, &ha->fcports);
 
                        /* Login and update database */
                        qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
@@ -2326,6 +2488,8 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
                } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
                        kfree(swl);
                        swl = NULL;
+               } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
+                       qla2x00_gpsc(ha, swl);
                }
        }
        swl_idx = 0;
@@ -2333,8 +2497,7 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
        /* Allocate temporary fcport for any new fcports discovered. */
        new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
        if (new_fcport == NULL) {
-               if (swl)
-                       kfree(swl);
+               kfree(swl);
                return (QLA_MEMORY_ALLOC_FAILED);
        }
        new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
@@ -2349,8 +2512,7 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
                if (qla2x00_is_reserved_id(ha, loop_id))
                        continue;
 
-               if (atomic_read(&ha->loop_down_timer) ||
-                   test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
+               if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
                        break;
 
                if (swl != NULL) {
@@ -2362,6 +2524,9 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
                                    swl[swl_idx].node_name, WWN_SIZE);
                                memcpy(new_fcport->port_name,
                                    swl[swl_idx].port_name, WWN_SIZE);
+                               memcpy(new_fcport->fabric_port_name,
+                                   swl[swl_idx].fabric_port_name, WWN_SIZE);
+                               new_fcport->fp_speed = swl[swl_idx].fp_speed;
 
                                if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
                                        last_dev = 1;
@@ -2400,6 +2565,12 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
                if (new_fcport->d_id.b24 == ha->d_id.b24)
                        continue;
 
+               /* Bypass if same domain and area of adapter. */
+               if (((new_fcport->d_id.b24 & 0xffff00) ==
+                   (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
+                       ISP_CFG_FL)
+                           continue;
+
                /* Bypass reserved domain fields. */
                if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
                        continue;
@@ -2413,6 +2584,11 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
 
                        found++;
 
+                       /* Update port state. */
+                       memcpy(fcport->fabric_port_name,
+                           new_fcport->fabric_port_name, WWN_SIZE);
+                       fcport->fp_speed = new_fcport->fp_speed;
+
                        /*
                         * If address the same and state FCS_ONLINE, nothing
                         * changed.
@@ -2464,19 +2640,15 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
                nxt_d_id.b24 = new_fcport->d_id.b24;
                new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
                if (new_fcport == NULL) {
-                       if (swl)
-                               kfree(swl);
+                       kfree(swl);
                        return (QLA_MEMORY_ALLOC_FAILED);
                }
                new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
                new_fcport->d_id.b24 = nxt_d_id.b24;
        }
 
-       if (swl)
-               kfree(swl);
-
-       if (new_fcport)
-               kfree(new_fcport);
+       kfree(swl);
+       kfree(new_fcport);
 
        if (!list_empty(new_fcports))
                ha->device_flags |= DFLG_FABRIC_DEVICES;
@@ -2498,7 +2670,7 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
  * Context:
  *     Kernel context.
  */
-int
+static int
 qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
 {
        int     rval;
@@ -2572,7 +2744,6 @@ static int
 qla2x00_device_resync(scsi_qla_host_t *ha)
 {
        int     rval;
-       int     rval2;
        uint32_t mask;
        fc_port_t *fcport;
        uint32_t rscn_entry;
@@ -2628,16 +2799,6 @@ qla2x00_device_resync(scsi_qla_host_t *ha)
 
                switch (format) {
                case 0:
-                       if (!IS_QLA2100(ha) && !IS_QLA2200(ha) &&
-                           !IS_QLA6312(ha) && !IS_QLA6322(ha) &&
-                           !IS_QLA24XX(ha) && !IS_QLA25XX(ha) &&
-                           ha->flags.init_done) {
-                               /* Handle port RSCN via asyncronous IOCBs */
-                               rval2 = qla2x00_handle_port_rscn(ha, rscn_entry,
-                                   NULL, 0);
-                               if (rval2 == QLA_SUCCESS)
-                                       continue;
-                       }
                        mask = 0xffffff;
                        break;
                case 1:
@@ -2655,10 +2816,6 @@ qla2x00_device_resync(scsi_qla_host_t *ha)
 
                rval = QLA_SUCCESS;
 
-               /* Abort any outstanding IO descriptors. */
-               if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
-                       qla2x00_cancel_io_descriptors(ha);
-
                list_for_each_entry(fcport, &ha->fcports, list) {
                        if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
                            (fcport->d_id.b24 & mask) != d_id.b24 ||
@@ -2668,7 +2825,8 @@ qla2x00_device_resync(scsi_qla_host_t *ha)
                        if (atomic_read(&fcport->state) == FCS_ONLINE) {
                                if (format != 3 ||
                                    fcport->port_type != FCT_INITIATOR) {
-                                       qla2x00_mark_device_lost(ha, fcport, 0);
+                                       qla2x00_mark_device_lost(ha, fcport,
+                                           0, 0);
                                }
                        }
                        fcport->flags &= ~FCF_FARP_DONE;
@@ -2715,8 +2873,7 @@ qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
                        ha->isp_ops.fabric_logout(ha, fcport->loop_id,
                            fcport->d_id.b.domain, fcport->d_id.b.area,
                            fcport->d_id.b.al_pa);
-                       qla2x00_mark_device_lost(ha, fcport, 1);
-
+                       qla2x00_mark_device_lost(ha, fcport, 1, 0);
                } else {
                        qla2x00_update_fcport(ha, fcport);
                }
@@ -2829,7 +2986,7 @@ qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
                        ha->isp_ops.fabric_logout(ha, fcport->loop_id,
                            fcport->d_id.b.domain, fcport->d_id.b.area,
                            fcport->d_id.b.al_pa);
-                       qla2x00_mark_device_lost(ha, fcport, 1);
+                       qla2x00_mark_device_lost(ha, fcport, 1, 0);
 
                        rval = 1;
                        break;
@@ -2848,7 +3005,7 @@ qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
                            fcport->d_id.b.domain, fcport->d_id.b.area,
                            fcport->d_id.b.al_pa);
                        fcport->loop_id = FC_NO_LOOP_ID;
-                       atomic_set(&fcport->state, FCS_DEVICE_DEAD);
+                       fcport->login_retry = 0;
 
                        rval = 3;
                        break;
@@ -2872,13 +3029,13 @@ qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
  *      3 - Fatal error
  */
 int
-qla2x00_local_device_login(scsi_qla_host_t *ha, uint16_t loop_id)
+qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
 {
        int             rval;
        uint16_t        mb[MAILBOX_REGISTER_COUNT];
 
        memset(mb, 0, sizeof(mb));
-       rval = qla2x00_login_local_device(ha, loop_id, mb, BIT_0);
+       rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
        if (rval == QLA_SUCCESS) {
                /* Interrogate mailbox registers for any errors */
                if (mb[0] == MBS_COMMAND_ERROR)
@@ -2964,6 +3121,17 @@ qla2x00_rescan_fcports(scsi_qla_host_t *ha)
        qla2x00_probe_for_all_luns(ha);
 }
 
+void
+qla2x00_update_fcports(scsi_qla_host_t *ha)
+{
+       fc_port_t *fcport;
+
+       /* Go with deferred removal of rport references. */
+       list_for_each_entry(fcport, &ha->fcports, list)
+               if (fcport->drport)
+                       qla2x00_rport_del(fcport);
+}
+
 /*
 *  qla2x00_abort_isp
 *      Resets ISP and aborts all outstanding commands.
@@ -2977,6 +3145,7 @@ qla2x00_rescan_fcports(scsi_qla_host_t *ha)
 int
 qla2x00_abort_isp(scsi_qla_host_t *ha)
 {
+       int rval;
        unsigned long flags = 0;
        uint16_t       cnt;
        srb_t          *sp;
@@ -2993,7 +3162,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
                atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
                if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
                        atomic_set(&ha->loop_state, LOOP_DOWN);
-                       qla2x00_mark_all_devices_lost(ha);
+                       qla2x00_mark_all_devices_lost(ha, 0);
                } else {
                        if (!atomic_read(&ha->loop_down_timer))
                                atomic_set(&ha->loop_down_timer,
@@ -3033,6 +3202,16 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
 
                        ha->isp_abort_cnt = 0;
                        clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
+
+                       if (ha->eft) {
+                               rval = qla2x00_trace_control(ha, TC_ENABLE,
+                                   ha->eft_dma, EFT_NUM_BUFFERS);
+                               if (rval) {
+                                       qla_printk(KERN_WARNING, ha,
+                                           "Unable to reinitialize EFT "
+                                           "(%d).\n", rval);
+                               }
+                       }
                } else {        /* failed the ISP abort */
                        ha->flags.online = 1;
                        if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
@@ -3053,14 +3232,14 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
                                        ha->isp_abort_cnt--;
                                        DEBUG(printk("qla%ld: ISP abort - "
                                            "retry remaining %d\n",
-                                           ha->host_no, ha->isp_abort_cnt);)
+                                           ha->host_no, ha->isp_abort_cnt));
                                        status = 1;
                                }
                        } else {
                                ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
                                DEBUG(printk("qla2x00(%ld): ISP error recovery "
                                    "- retrying (%d) more times\n",
-                                   ha->host_no, ha->isp_abort_cnt);)
+                                   ha->host_no, ha->isp_abort_cnt));
                                set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
                                status = 1;
                        }
@@ -3074,7 +3253,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
        } else {
                DEBUG(printk(KERN_INFO
                                "qla2x00_abort_isp(%ld): exiting.\n",
-                               ha->host_no);)
+                               ha->host_no));
        }
 
        return(status);
@@ -3109,7 +3288,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
 
                        spin_lock_irqsave(&ha->hardware_lock, flags);
 
-                       if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
+                       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
                                /*
                                 * Disable SRAM, Instruction RAM and GP RAM
                                 * parity.
@@ -3125,7 +3304,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
 
                        spin_lock_irqsave(&ha->hardware_lock, flags);
 
-                       if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha)) {
+                       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) {
                                /* Enable proper parity */
                                if (IS_QLA2300(ha))
                                        /* SRAM parity */
@@ -3150,7 +3329,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
                clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
                if (!(status = qla2x00_fw_ready(ha))) {
                        DEBUG(printk("%s(): Start configure loop, "
-                           "status = %d\n", __func__, status);)
+                           "status = %d\n", __func__, status));
 
                        /* Issue a marker after FW becomes ready. */
                        qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
@@ -3174,7 +3353,7 @@ qla2x00_restart_isp(scsi_qla_host_t *ha)
 
                DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
                                __func__,
-                               status);)
+                               status));
        }
        return (status);
 }
@@ -3238,8 +3417,12 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
        /* Determine NVRAM starting address. */
        ha->nvram_size = sizeof(struct nvram_24xx);
        ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
-       if (PCI_FUNC(ha->pdev->devfn))
+       ha->vpd_size = FA_NVRAM_VPD_SIZE;
+       ha->vpd_base = FA_NVRAM_VPD0_ADDR;
+       if (PCI_FUNC(ha->pdev->devfn)) {
                ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
+               ha->vpd_base = FA_NVRAM_VPD1_ADDR;
+       }
 
        /* Get NVRAM data and calculate checksum. */
        dptr = (uint32_t *)nv;
@@ -3290,7 +3473,6 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
                nv->node_name[6] = 0x55;
                nv->node_name[7] = 0x86;
                nv->login_retry_count = __constant_cpu_to_le16(8);
-               nv->link_down_timeout = __constant_cpu_to_le16(200);
                nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
                nv->login_timeout = __constant_cpu_to_le16(0);
                nv->firmware_options_1 =
@@ -3319,7 +3501,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
                *dptr1++ = *dptr2++;
 
        icb->login_retry_count = nv->login_retry_count;
-       icb->link_down_timeout = nv->link_down_timeout;
+       icb->link_down_on_nos = nv->link_down_on_nos;
 
        /* Copy 2nd segment. */
        dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
@@ -3348,12 +3530,18 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
 
                index = (ha->pdev->subsystem_device & 0xff);
                if (index < QLA_MODEL_NAMES)
-                       ha->model_desc = qla2x00_model_desc[index];
+                       ha->model_desc = qla2x00_model_name[index * 2 + 1];
        } else
                strcpy(ha->model_number, "QLA2462");
 
+       /* Use alternate WWN? */
+       if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
+               memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
+               memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
+       }
+
        /* Prepare nodename */
-       if ((icb->firmware_options_1 & BIT_14) == 0) {
+       if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
                /*
                 * Firmware will apply the following mask if the nodename was
                 * not provided.
@@ -3368,9 +3556,10 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
        ha->flags.enable_lip_full_login = 1;
        ha->flags.enable_target_reset = 1;
        ha->flags.enable_led_scheme = 0;
+       ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
 
-       ha->operating_mode =
-           (icb->firmware_options_2 & (BIT_6 | BIT_5 | BIT_4)) >> 4;
+       ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
+           (BIT_6 | BIT_5 | BIT_4)) >> 4;
 
        memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
            sizeof(ha->fw_seriallink_options24));
@@ -3382,6 +3571,8 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
        ha->node_name = icb->node_name;
        ha->port_name = icb->port_name;
 
+       icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
+
        ha->retry_count = le16_to_cpu(nv->login_retry_count);
 
        /* Set minimum login_timeout to 4 seconds. */
@@ -3432,6 +3623,32 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
        if (ql2xloginretrycount)
                ha->login_retry_count = ql2xloginretrycount;
 
+       /* Enable ZIO. */
+       if (!ha->flags.init_done) {
+               ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
+                   (BIT_3 | BIT_2 | BIT_1 | BIT_0);
+               ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
+                   le16_to_cpu(icb->interrupt_delay_timer): 2;
+       }
+       icb->firmware_options_2 &= __constant_cpu_to_le32(
+           ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
+       ha->flags.process_response_queue = 0;
+       if (ha->zio_mode != QLA_ZIO_DISABLED) {
+               ha->zio_mode = QLA_ZIO_MODE_6;
+
+               DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
+                   "(%d us).\n", ha->host_no, ha->zio_mode,
+                   ha->zio_timer * 100));
+               qla_printk(KERN_INFO, ha,
+                   "ZIO mode %d enabled; timer delay (%d us).\n",
+                   ha->zio_mode, ha->zio_timer * 100);
+
+               icb->firmware_options_2 |= cpu_to_le32(
+                   (uint32_t)ha->zio_mode);
+               icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
+               ha->flags.process_response_queue = 1;
+       }
+
        if (rval) {
                DEBUG2_3(printk(KERN_WARNING
                    "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
@@ -3439,83 +3656,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
        return (rval);
 }
 
-int
-qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
-{
-       int             rval;
-       uint16_t        cnt;
-       uint16_t        *risc_code;
-       unsigned long   risc_address;
-       unsigned long   risc_code_size;
-       int             num;
-       int             i;
-       uint16_t        *req_ring;
-       struct qla_fw_info *fw_iter;
-
-       rval = QLA_SUCCESS;
-
-       /* Load firmware sequences */
-       fw_iter = ha->brd_info->fw_info;
-       *srisc_addr = *ha->brd_info->fw_info->fwstart;
-       while (fw_iter->addressing != FW_INFO_ADDR_NOMORE) {
-               risc_code = fw_iter->fwcode;
-               risc_code_size = *fw_iter->fwlen;
-
-               if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
-                       risc_address = *fw_iter->fwstart;
-               } else {
-                       /* Extended address */
-                       risc_address = *fw_iter->lfwstart;
-               }
-
-               num = 0;
-               rval = 0;
-               while (risc_code_size > 0 && !rval) {
-                       cnt = (uint16_t)(ha->fw_transfer_size >> 1);
-                       if (cnt > risc_code_size)
-                               cnt = risc_code_size;
-
-                       DEBUG7(printk("scsi(%ld): Loading risc segment@ "
-                           "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
-                           ha->host_no, risc_code, cnt, risc_address));
-
-                       req_ring = (uint16_t *)ha->request_ring;
-                       for (i = 0; i < cnt; i++)
-                               req_ring[i] = cpu_to_le16(risc_code[i]);
-
-                       if (fw_iter->addressing == FW_INFO_ADDR_NORMAL) {
-                               rval = qla2x00_load_ram(ha, ha->request_dma,
-                                   risc_address, cnt);
-                       } else {
-                               rval = qla2x00_load_ram_ext(ha,
-                                   ha->request_dma, risc_address, cnt);
-                       }
-                       if (rval) {
-                               DEBUG(printk("scsi(%ld): [ERROR] Failed to "
-                                   "load segment %d of firmware\n",
-                                   ha->host_no, num));
-                               qla_printk(KERN_WARNING, ha,
-                                   "[ERROR] Failed to load segment %d of "
-                                   "firmware\n", num);
-
-                               qla2x00_dump_regs(ha);
-                               break;
-                       }
-
-                       risc_code += cnt;
-                       risc_address += cnt;
-                       risc_code_size -= cnt;
-                       num++;
-               }
-
-               /* Next firmware sequence */
-               fw_iter++;
-       }
-
-       return (rval);
-}
-
-int
+static int
 qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
 {
        int     rval;
@@ -3572,8 +3713,8 @@ qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
                        for (i = 0; i < dlen; i++)
                                dcode[i] = swab32(dcode[i]);
 
-                       rval = qla2x00_load_ram_ext(ha, ha->request_dma,
-                           risc_addr, dlen);
+                       rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
+                           dlen);
                        if (rval) {
                                DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
                                    "segment %d of firmware\n", ha->host_no,
@@ -3597,8 +3738,110 @@ qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
        return rval;
 }
 
+#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
+
+int
+qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
+{
+       int     rval;
+       int     i, fragment;
+       uint16_t *wcode, *fwcode;
+       uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
+       struct fw_blob *blob;
+
+       /* Load firmware blob. */
+       blob = qla2x00_request_firmware(ha);
+       if (!blob) {
+               qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
+               qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
+                   "from: " QLA_FW_URL ".\n");
+               return QLA_FUNCTION_FAILED;
+       }
+
+       rval = QLA_SUCCESS;
+
+       wcode = (uint16_t *)ha->request_ring;
+       *srisc_addr = 0;
+       fwcode = (uint16_t *)blob->fw->data;
+       fwclen = 0;
+
+       /* Validate firmware image by checking version. */
+       if (blob->fw->size < 8 * sizeof(uint16_t)) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to verify integrity of firmware image (%Zd)!\n",
+                   blob->fw->size);
+               goto fail_fw_integrity;
+       }
+       for (i = 0; i < 4; i++)
+               wcode[i] = be16_to_cpu(fwcode[i + 4]);
+       if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
+           wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
+               wcode[2] == 0 && wcode[3] == 0)) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to verify integrity of firmware image!\n");
+               qla_printk(KERN_WARNING, ha,
+                   "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
+                   wcode[1], wcode[2], wcode[3]);
+               goto fail_fw_integrity;
+       }
+
+       seg = blob->segs;
+       while (*seg && rval == QLA_SUCCESS) {
+               risc_addr = *seg;
+               *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
+               risc_size = be16_to_cpu(fwcode[3]);
+
+               /* Validate firmware image size. */
+               fwclen += risc_size * sizeof(uint16_t);
+               if (blob->fw->size < fwclen) {
+                       qla_printk(KERN_WARNING, ha,
+                           "Unable to verify integrity of firmware image "
+                           "(%Zd)!\n", blob->fw->size);
+                       goto fail_fw_integrity;
+               }
+
+               fragment = 0;
+               while (risc_size > 0 && rval == QLA_SUCCESS) {
+                       wlen = (uint16_t)(ha->fw_transfer_size >> 1);
+                       if (wlen > risc_size)
+                               wlen = risc_size;
+
+                       DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
+                           "addr %x, number of words 0x%x.\n", ha->host_no,
+                           risc_addr, wlen));
+
+                       for (i = 0; i < wlen; i++)
+                               wcode[i] = swab16(fwcode[i]);
+
+                       rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
+                           wlen);
+                       if (rval) {
+                               DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
+                                   "segment %d of firmware\n", ha->host_no,
+                                   fragment));
+                               qla_printk(KERN_WARNING, ha,
+                                   "[ERROR] Failed to load segment %d of "
+                                   "firmware\n", fragment);
+                               break;
+                       }
+
+                       fwcode += wlen;
+                       risc_addr += wlen;
+                       risc_size -= wlen;
+                       fragment++;
+               }
+
+               /* Next segment. */
+               seg++;
+       }
+       return rval;
+
+fail_fw_integrity:
+       return QLA_FUNCTION_FAILED;
+}
+
 int
-qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
+qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
 {
        int     rval;
        int     segments, fragment;
@@ -3606,15 +3849,20 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
        uint32_t risc_addr;
        uint32_t risc_size;
        uint32_t i;
-       const struct firmware *fw_entry;
+       struct fw_blob *blob;
        uint32_t *fwcode, fwclen;
 
-       if (request_firmware(&fw_entry, ha->brd_info->fw_fname,
-           &ha->pdev->dev)) {
-               qla_printk(KERN_ERR, ha,
-                   "Firmware image file not available: '%s'\n",
-                   ha->brd_info->fw_fname);
-               return QLA_FUNCTION_FAILED;
+       /* Load firmware blob. */
+       blob = qla2x00_request_firmware(ha);
+       if (!blob) {
+               qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
+               qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
+                   "from: " QLA_FW_URL ".\n");
+
+               /* Try to load RISC code from flash. */
+               qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
+                   "outdated) firmware from flash.\n");
+               return qla24xx_load_risc_flash(ha, srisc_addr);
        }
 
        rval = QLA_SUCCESS;
@@ -3622,14 +3870,14 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
        segments = FA_RISC_CODE_SEGMENTS;
        dcode = (uint32_t *)ha->request_ring;
        *srisc_addr = 0;
-       fwcode = (uint32_t *)fw_entry->data;
+       fwcode = (uint32_t *)blob->fw->data;
        fwclen = 0;
 
        /* Validate firmware image by checking version. */
-       if (fw_entry->size < 8 * sizeof(uint32_t)) {
+       if (blob->fw->size < 8 * sizeof(uint32_t)) {
                qla_printk(KERN_WARNING, ha,
-                   "Unable to verify integrity of flash firmware image "
-                   "(%Zd)!\n", fw_entry->size);
+                   "Unable to verify integrity of firmware image (%Zd)!\n",
+                   blob->fw->size);
                goto fail_fw_integrity;
        }
        for (i = 0; i < 4; i++)
@@ -3639,7 +3887,7 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
            (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
                dcode[3] == 0)) {
                qla_printk(KERN_WARNING, ha,
-                   "Unable to verify integrity of flash firmware image!\n");
+                   "Unable to verify integrity of firmware image!\n");
                qla_printk(KERN_WARNING, ha,
                    "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
                    dcode[1], dcode[2], dcode[3]);
@@ -3653,10 +3901,11 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
 
                /* Validate firmware image size. */
                fwclen += risc_size * sizeof(uint32_t);
-               if (fw_entry->size < fwclen) {
+               if (blob->fw->size < fwclen) {
                        qla_printk(KERN_WARNING, ha,
-                           "Unable to verify integrity of flash firmware "
-                           "image (%Zd)!\n", fw_entry->size);
+                           "Unable to verify integrity of firmware image "
+                           "(%Zd)!\n", blob->fw->size);
+
                        goto fail_fw_integrity;
                }
 
@@ -3673,8 +3922,8 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
                        for (i = 0; i < dlen; i++)
                                dcode[i] = swab32(fwcode[i]);
 
-                       rval = qla2x00_load_ram_ext(ha, ha->request_dma,
-                           risc_addr, dlen);
+                       rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
+                           dlen);
                        if (rval) {
                                DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
                                    "segment %d of firmware\n", ha->host_no,
@@ -3694,13 +3943,8 @@ qla24xx_load_risc_hotplug(scsi_qla_host_t *ha, uint32_t *srisc_addr)
                /* Next segment. */
                segments--;
        }
-
-       release_firmware(fw_entry);
        return rval;
 
 fail_fw_integrity:
-
-       release_firmware(fw_entry);
        return QLA_FUNCTION_FAILED;
-
 }