[SCSI] qla2xxx: make some more functions static
[safe/jmp/linux-2.6] / drivers / scsi / qla2xxx / qla_os.c
index af9b4e7..01fc30c 100644 (file)
@@ -1,27 +1,15 @@
 /*
- *                  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/moduleparam.h>
 #include <linux/vmalloc.h>
-#include <linux/smp_lock.h>
 #include <linux/delay.h>
+#include <linux/kthread.h>
 
 #include <scsi/scsi_tcq.h>
 #include <scsi/scsicam.h>
@@ -51,38 +39,33 @@ MODULE_PARM_DESC(ql2xlogintimeout,
 int qlport_down_retry = 30;
 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
 MODULE_PARM_DESC(qlport_down_retry,
-               "Maximum number of command retries to a port that returns"
+               "Maximum number of command retries to a port that returns "
                "a PORT-DOWN status.");
 
 int ql2xplogiabsentdevice;
 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(ql2xplogiabsentdevice,
                "Option to enable PLOGI to devices that are not present after "
-               "a Fabric scan.  This is needed for several broken switches."
+               "a Fabric scan.  This is needed for several broken switches. "
                "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
 
-int ql2xenablezio = 0;
-module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xenablezio,
-               "Option to enable ZIO:If 1 then enable it otherwise"
-               " use the default set in the NVRAM."
-               " Default is 0 : disabled");
-
-int ql2xintrdelaytimer = 10;
-module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xintrdelaytimer,
-               "ZIO: Waiting time for Firmware before it generates an "
-               "interrupt to the host to notify completion of request.");
-
 int ql2xloginretrycount = 0;
 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
 MODULE_PARM_DESC(ql2xloginretrycount,
                "Specify an alternate value for the NVRAM login retry count.");
 
-int ql2xfwloadbin;
-module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xfwloadbin,
-               "Load ISP2xxx firmware image via hotplug.");
+int ql2xallocfwdump = 1;
+module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
+MODULE_PARM_DESC(ql2xallocfwdump,
+               "Option to enable allocation of memory for a firmware dump "
+               "during HBA initialization.  Memory allocation requirements "
+               "vary by ISP type.  Default is 1 - allocate memory.");
+
+int extended_error_logging;
+module_param(extended_error_logging, int, S_IRUGO|S_IRUSR);
+MODULE_PARM_DESC(extended_error_logging,
+               "Option to enable extended error logging, "
+               "Default is 0 - no logging. 1 - log errors.");
 
 static void qla2x00_free_device(scsi_qla_host_t *);
 
@@ -116,7 +99,7 @@ static int qla2x00_change_queue_type(struct scsi_device *, int);
 
 static struct scsi_host_template qla2x00_driver_template = {
        .module                 = THIS_MODULE,
-       .name                   = "qla2xxx",
+       .name                   = QLA2XXX_DRIVER_NAME,
        .queuecommand           = qla2x00_queuecommand,
 
        .eh_abort_handler       = qla2xxx_eh_abort,
@@ -145,7 +128,7 @@ static struct scsi_host_template qla2x00_driver_template = {
 
 static struct scsi_host_template qla24xx_driver_template = {
        .module                 = THIS_MODULE,
-       .name                   = "qla2xxx",
+       .name                   = QLA2XXX_DRIVER_NAME,
        .queuecommand           = qla24xx_queuecommand,
 
        .eh_abort_handler       = qla2xxx_eh_abort,
@@ -357,7 +340,6 @@ qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
        if (!sp)
                return sp;
 
-       atomic_set(&sp->ref_count, 1);
        sp->ha = ha;
        sp->fcport = fcport;
        sp->cmd = cmd;
@@ -373,11 +355,19 @@ qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
        fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
+       struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
        srb_t *sp;
        int rval;
 
-       if (!fcport) {
-               cmd->result = DID_NO_CONNECT << 16;
+       rval = fc_remote_port_chkready(rport);
+       if (rval) {
+               cmd->result = rval;
+               goto qc_fail_command;
+       }
+
+       /* Close window on fcport/rport state-transitioning. */
+       if (!*(fc_port_t **)rport->dd_data) {
+               cmd->result = DID_IMM_RETRY << 16;
                goto qc_fail_command;
        }
 
@@ -400,16 +390,6 @@ qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
        if (rval != QLA_SUCCESS)
                goto qc_host_busy_free_sp;
 
-       /* Manage unprocessed RIO/ZIO commands in response queue. */
-       if (ha->flags.online && ha->flags.process_response_queue &&
-           ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
-               unsigned long flags;
-
-               spin_lock_irqsave(&ha->hardware_lock, flags);
-               qla2x00_process_response_queue(ha);
-               spin_unlock_irqrestore(&ha->hardware_lock, flags);
-       }
-
        spin_lock_irq(ha->host->host_lock);
 
        return 0;
@@ -436,11 +416,19 @@ qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
        fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
+       struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
        srb_t *sp;
        int rval;
 
-       if (!fcport) {
-               cmd->result = DID_NO_CONNECT << 16;
+       rval = fc_remote_port_chkready(rport);
+       if (rval) {
+               cmd->result = rval;
+               goto qc24_fail_command;
+       }
+
+       /* Close window on fcport/rport state-transitioning. */
+       if (!*(fc_port_t **)rport->dd_data) {
+               cmd->result = DID_IMM_RETRY << 16;
                goto qc24_fail_command;
        }
 
@@ -536,7 +524,7 @@ qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
  *    Success (Adapter is online) : 0
  *    Failed  (Adapter is offline/disabled) : 1
  */
-static int
+int
 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
 {
        int             return_status;
@@ -588,6 +576,10 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
        while ((!atomic_read(&ha->loop_down_timer) &&
            atomic_read(&ha->loop_state) == LOOP_DOWN) ||
            atomic_read(&ha->loop_state) != LOOP_READY) {
+               if (atomic_read(&ha->loop_state) == LOOP_DEAD) {
+                       return_status = QLA_FUNCTION_FAILED;
+                       break;
+               }
                msleep(1000);
                if (time_after_eq(jiffies, loop_timeout)) {
                        return_status = QLA_FUNCTION_FAILED;
@@ -610,6 +602,7 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
 *    Either SUCCESS or FAILED.
 *
 * Note:
+*    Only return FAILED if command not returned by firmware.
 **************************************************************************/
 int
 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
@@ -620,11 +613,12 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
        unsigned int id, lun;
        unsigned long serial;
        unsigned long flags;
+       int wait = 0;
 
        if (!CMD_SP(cmd))
-               return FAILED;
+               return SUCCESS;
 
-       ret = FAILED;
+       ret = SUCCESS;
 
        id = cmd->device->id;
        lun = cmd->device->lun;
@@ -641,10 +635,9 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
                if (sp->cmd != cmd)
                        continue;
 
-               DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
-                   "sp->state=%x\n", __func__, ha->host_no, sp, serial,
-                   sp->state));
-               DEBUG3(qla2x00_print_scsi_cmd(cmd);)
+               DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
+                   __func__, ha->host_no, sp, serial));
+               DEBUG3(qla2x00_print_scsi_cmd(cmd));
 
                spin_unlock_irqrestore(&ha->hardware_lock, flags);
                if (ha->isp_ops.abort_command(ha, sp)) {
@@ -653,7 +646,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
                } else {
                        DEBUG3(printk("%s(%ld): abort_command "
                            "mbx success.\n", __func__, ha->host_no));
-                       ret = SUCCESS;
+                       wait = 1;
                }
                spin_lock_irqsave(&ha->hardware_lock, flags);
 
@@ -662,17 +655,18 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
        spin_unlock_irqrestore(&ha->hardware_lock, flags);
 
        /* Wait for the command to be returned. */
-       if (ret == SUCCESS) {
+       if (wait) {
                if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
                        qla_printk(KERN_ERR, ha,
                            "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
                            "%x.\n", ha->host_no, id, lun, serial, ret);
+                       ret = FAILED;
                }
        }
 
        qla_printk(KERN_INFO, ha,
-           "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
-           id, lun, serial, ret);
+           "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
+           ha->host_no, id, lun, wait, serial, ret);
 
        return ret;
 }
@@ -779,13 +773,13 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
                if (ret == SUCCESS) {
                        if (fcport->flags & FC_FABRIC_DEVICE) {
                                ha->isp_ops.fabric_logout(ha, fcport->loop_id);
-                               qla2x00_mark_device_lost(ha, fcport);
+                               qla2x00_mark_device_lost(ha, fcport, 0, 0);
                        }
                }
 #endif
        } else {
                DEBUG2(printk(KERN_INFO
-                   "%s failed: loop not ready\n",__func__);)
+                   "%s failed: loop not ready\n",__func__));
        }
 
        if (ret == FAILED) {
@@ -797,29 +791,19 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
                goto eh_dev_reset_done;
        }
 
-       /*
-        * If we are coming down the EH path, wait for all commands to
-        * complete for the device.
-        */
-       if (cmd->device->host->eh_active) {
-               if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
-                       ret = FAILED;
-
-               if (ret == FAILED) {
-                       DEBUG3(printk("%s(%ld): failed while waiting for "
-                           "commands\n", __func__, ha->host_no));
-                       qla_printk(KERN_INFO, ha,
-                           "%s: failed while waiting for commands\n",
-                           __func__);
-
-                       goto eh_dev_reset_done;
-               }
-       }
-
-       qla_printk(KERN_INFO, ha,
-           "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
-
-eh_dev_reset_done:
+       /* Flush outstanding commands. */
+       if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
+               ret = FAILED;
+       if (ret == FAILED) {
+               DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
+                   __func__, ha->host_no));
+               qla_printk(KERN_INFO, ha,
+                   "%s: failed while waiting for commands\n", __func__);
+       } else
+               qla_printk(KERN_INFO, ha,
+                   "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no,
+                   id, lun);
+ eh_dev_reset_done:
        return ret;
 }
 
@@ -921,10 +905,9 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
        if (ret == FAILED)
                goto eh_bus_reset_done;
 
-       /* Waiting for our command in done_queue to be returned to OS.*/
-       if (cmd->device->host->eh_active)
-               if (!qla2x00_eh_wait_for_pending_commands(ha))
-                       ret = FAILED;
+       /* Flush outstanding commands. */
+       if (!qla2x00_eh_wait_for_pending_commands(ha))
+               ret = FAILED;
 
 eh_bus_reset_done:
        qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
@@ -1051,12 +1034,12 @@ qla2x00_loop_reset(scsi_qla_host_t *ha)
                /* Empty */
                DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
                                __func__,
-                               ha->host_no);)
+                               ha->host_no));
        } else {
                /* Empty */
                DEBUG3(printk("%s(%ld): exiting normally.\n",
                                __func__,
-                               ha->host_no);)
+                               ha->host_no));
        }
 
        return(status);
@@ -1087,10 +1070,10 @@ qla2xxx_slave_alloc(struct scsi_device *sdev)
 {
        struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
 
-       if (!rport)
+       if (!rport || fc_remote_port_chkready(rport))
                return -ENXIO;
 
-       sdev->hostdata = rport->dd_data;
+       sdev->hostdata = *(fc_port_t **)rport->dd_data;
 
        return 0;
 }
@@ -1168,6 +1151,68 @@ qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
        pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
 }
 
+static inline void
+qla2x00_set_isp_flags(scsi_qla_host_t *ha)
+{
+       ha->device_type = DT_EXTENDED_IDS;
+       switch (ha->pdev->device) {
+       case PCI_DEVICE_ID_QLOGIC_ISP2100:
+               ha->device_type |= DT_ISP2100;
+               ha->device_type &= ~DT_EXTENDED_IDS;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2100;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2200:
+               ha->device_type |= DT_ISP2200;
+               ha->device_type &= ~DT_EXTENDED_IDS;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2100;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2300:
+               ha->device_type |= DT_ISP2300;
+               ha->device_type |= DT_ZIO_SUPPORTED;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2300;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2312:
+               ha->device_type |= DT_ISP2312;
+               ha->device_type |= DT_ZIO_SUPPORTED;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2300;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2322:
+               ha->device_type |= DT_ISP2322;
+               ha->device_type |= DT_ZIO_SUPPORTED;
+               if (ha->pdev->subsystem_vendor == 0x1028 &&
+                   ha->pdev->subsystem_device == 0x0170)
+                       ha->device_type |= DT_OEM_001;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2300;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP6312:
+               ha->device_type |= DT_ISP6312;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2300;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP6322:
+               ha->device_type |= DT_ISP6322;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2300;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2422:
+               ha->device_type |= DT_ISP2422;
+               ha->device_type |= DT_ZIO_SUPPORTED;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2400;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP2432:
+               ha->device_type |= DT_ISP2432;
+               ha->device_type |= DT_ZIO_SUPPORTED;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2400;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP5422:
+               ha->device_type |= DT_ISP5422;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2400;
+               break;
+       case PCI_DEVICE_ID_QLOGIC_ISP5432:
+               ha->device_type |= DT_ISP5432;
+               ha->fw_srisc_address = RISC_START_ADDRESS_2400;
+               break;
+       }
+}
+
 static int
 qla2x00_iospace_config(scsi_qla_host_t *ha)
 {
@@ -1210,7 +1255,7 @@ qla2x00_iospace_config(scsi_qla_host_t *ha)
                goto iospace_error_exit;
        }
 
-       if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
+       if (pci_request_regions(ha->pdev, QLA2XXX_DRIVER_NAME)) {
                qla_printk(KERN_WARNING, ha,
                    "Failed to reserve PIO/MMIO regions (%s)\n",
                    pci_name(ha->pdev));
@@ -1292,7 +1337,8 @@ qla24xx_disable_intrs(scsi_qla_host_t *ha)
 /*
  * PCI driver interface
  */
-int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
+static int __devinit
+qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 {
        int     ret = -ENODEV;
        device_reg_t __iomem *reg;
@@ -1303,12 +1349,16 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        char pci_info[20];
        char fw_str[30];
        fc_port_t *fcport;
+       struct scsi_host_template *sht;
 
        if (pci_enable_device(pdev))
                goto probe_out;
 
-       host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
-           &qla2x00_driver_template, sizeof(scsi_qla_host_t));
+       sht = &qla2x00_driver_template;
+       if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
+           pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432)
+               sht = &qla24xx_driver_template;
+       host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
        if (host == NULL) {
                printk(KERN_WARNING
                    "qla2xxx: Couldn't allocate host from scsi layer!\n");
@@ -1322,8 +1372,10 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        ha->pdev = pdev;
        ha->host = host;
        ha->host_no = host->host_no;
-       ha->brd_info = brd_info;
-       sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
+       sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
+
+       /* Set ISP-type information. */
+       qla2x00_set_isp_flags(ha);
 
        /* Configure PCI I/O space */
        ret = qla2x00_iospace_config(ha);
@@ -1331,15 +1383,16 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
                goto probe_failed;
 
        qla_printk(KERN_INFO, ha,
-           "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
-           pdev->irq, ha->iobase);
+           "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
+           ha->iobase);
 
        spin_lock_init(&ha->hardware_lock);
 
        ha->prev_topology = 0;
-       ha->ports = MAX_BUSES;
        ha->init_cb_size = sizeof(init_cb_t);
        ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
+       ha->link_data_rate = LDR_UNKNOWN;
+       ha->optrom_size = OPTROM_SIZE_2300;
 
        /* Assign ISP specific operations. */
        ha->isp_ops.pci_config          = qla2100_pci_config;
@@ -1366,7 +1419,8 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        ha->isp_ops.read_nvram          = qla2x00_read_nvram_data;
        ha->isp_ops.write_nvram         = qla2x00_write_nvram_data;
        ha->isp_ops.fw_dump             = qla2100_fw_dump;
-       ha->isp_ops.ascii_fw_dump       = qla2100_ascii_fw_dump;
+       ha->isp_ops.read_optrom         = qla2x00_read_optrom_data;
+       ha->isp_ops.write_optrom        = qla2x00_write_optrom_data;
        if (IS_QLA2100(ha)) {
                host->max_id = MAX_TARGETS_2100;
                ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
@@ -1391,9 +1445,13 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
                ha->isp_ops.pci_config = qla2300_pci_config;
                ha->isp_ops.intr_handler = qla2300_intr_handler;
                ha->isp_ops.fw_dump = qla2300_fw_dump;
-               ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
+               ha->isp_ops.beacon_on = qla2x00_beacon_on;
+               ha->isp_ops.beacon_off = qla2x00_beacon_off;
+               ha->isp_ops.beacon_blink = qla2x00_beacon_blink;
                ha->gid_list_info_size = 6;
-       } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+               if (IS_QLA2322(ha) || IS_QLA6322(ha))
+                       ha->optrom_size = OPTROM_SIZE_2322;
+       } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                host->max_id = MAX_TARGETS_2200;
                ha->mbx_count = MAILBOX_REGISTER_COUNT;
                ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
@@ -1408,9 +1466,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
                ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
                ha->isp_ops.nvram_config = qla24xx_nvram_config;
                ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
-               ha->isp_ops.load_risc = qla24xx_load_risc_flash;
-               if (ql2xfwloadbin)
-                       ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
+               ha->isp_ops.load_risc = qla24xx_load_risc;
                ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
                ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
                ha->isp_ops.intr_handler = qla24xx_intr_handler;
@@ -1425,8 +1481,13 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
                ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
                ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
                ha->isp_ops.fw_dump = qla24xx_fw_dump;
-               ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
+               ha->isp_ops.read_optrom = qla24xx_read_optrom_data;
+               ha->isp_ops.write_optrom = qla24xx_write_optrom_data;
+               ha->isp_ops.beacon_on = qla24xx_beacon_on;
+               ha->isp_ops.beacon_off = qla24xx_beacon_off;
+               ha->isp_ops.beacon_blink = qla24xx_beacon_blink;
                ha->gid_list_info_size = 8;
+               ha->optrom_size = OPTROM_SIZE_24XX;
        }
        host->can_queue = ha->request_q_length + 128;
 
@@ -1438,7 +1499,6 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
 
        INIT_LIST_HEAD(&ha->list);
        INIT_LIST_HEAD(&ha->fcports);
-       INIT_LIST_HEAD(&ha->rscn_fcports);
 
        /*
         * These locks are used to prevent more than one CPU
@@ -1448,10 +1508,6 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
         */
        spin_lock_init(&ha->mbx_reg_lock);
 
-       ha->dpc_pid = -1;
-       init_completion(&ha->dpc_inited);
-       init_completion(&ha->dpc_exited);
-
        qla2x00_config_dma_addressing(ha);
        if (qla2x00_mem_alloc(ha)) {
                qla_printk(KERN_WARNING, ha,
@@ -1478,27 +1534,25 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        /*
         * Startup the kernel thread for this host adapter
         */
-       ha->dpc_should_die = 0;
-       ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
-       if (ha->dpc_pid < 0) {
+       ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
+                       "%s_dpc", ha->host_str);
+       if (IS_ERR(ha->dpc_thread)) {
                qla_printk(KERN_WARNING, ha,
                    "Unable to start DPC thread!\n");
-
-               ret = -ENODEV;
+               ret = PTR_ERR(ha->dpc_thread);
                goto probe_failed;
        }
-       wait_for_completion(&ha->dpc_inited);
 
        host->this_id = 255;
        host->cmd_per_lun = 3;
        host->unique_id = ha->instance;
        host->max_cmd_len = MAX_CMDSZ;
-       host->max_channel = ha->ports - 1;
+       host->max_channel = MAX_BUSES - 1;
        host->max_lun = MAX_LUNS;
        host->transportt = qla2xxx_transport_template;
 
        ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
-           SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
+           SA_INTERRUPT|SA_SHIRQ, QLA2XXX_DRIVER_NAME, ha);
        if (ret) {
                qla_printk(KERN_WARNING, ha,
                    "Failed to reserve interrupt %d already in use.\n",
@@ -1517,7 +1571,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
 
        spin_lock_irqsave(&ha->hardware_lock, flags);
        reg = ha->iobase;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
                WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
        } else {
@@ -1572,11 +1626,12 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        qla_printk(KERN_INFO, ha, "\n"
            " QLogic Fibre Channel HBA Driver: %s\n"
            "  QLogic %s - %s\n"
-           "  %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
-           ha->model_number, ha->model_desc ? ha->model_desc: "",
-           ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
-           pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
-           ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
+           "  ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
+           qla2x00_version_str, ha->model_number,
+           ha->model_desc ? ha->model_desc: "", pdev->device,
+           ha->isp_ops.pci_info_str(ha, pci_info), pci_name(pdev),
+           ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
+           ha->isp_ops.fw_version_str(ha, fw_str));
 
        /* Go with fc_rport registration. */
        list_for_each_entry(fcport, &ha->fcports, list)
@@ -1595,9 +1650,9 @@ probe_disable_device:
 probe_out:
        return ret;
 }
-EXPORT_SYMBOL_GPL(qla2x00_probe_one);
 
-void qla2x00_remove_one(struct pci_dev *pdev)
+static void __devexit
+qla2x00_remove_one(struct pci_dev *pdev)
 {
        scsi_qla_host_t *ha;
 
@@ -1615,48 +1670,43 @@ void qla2x00_remove_one(struct pci_dev *pdev)
 
        pci_set_drvdata(pdev, NULL);
 }
-EXPORT_SYMBOL_GPL(qla2x00_remove_one);
 
 static void
 qla2x00_free_device(scsi_qla_host_t *ha)
 {
-       int ret;
-
-       /* Abort any outstanding IO descriptors. */
-       if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
-               qla2x00_cancel_io_descriptors(ha);
-
-       /* turn-off interrupts on the card */
-       if (ha->interrupts_on)
-               ha->isp_ops.disable_intrs(ha);
-
        /* Disable timer */
        if (ha->timer_active)
                qla2x00_stop_timer(ha);
 
        /* Kill the kernel thread for this host */
-       if (ha->dpc_pid >= 0) {
-               ha->dpc_should_die = 1;
-               wmb();
-               ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
-               if (ret) {
-                       qla_printk(KERN_ERR, ha,
-                           "Unable to signal DPC thread -- (%d)\n", ret);
+       if (ha->dpc_thread) {
+               struct task_struct *t = ha->dpc_thread;
 
-                       /* TODO: SOMETHING MORE??? */
-               } else {
-                       wait_for_completion(&ha->dpc_exited);
-               }
+               /*
+                * qla2xxx_wake_dpc checks for ->dpc_thread
+                * so we need to zero it out.
+                */
+               ha->dpc_thread = NULL;
+               kthread_stop(t);
        }
 
-       qla2x00_mem_free(ha);
+       if (ha->eft)
+               qla2x00_trace_control(ha, TC_DISABLE, 0, 0);
+
+       /* Stop currently executing firmware. */
+       qla2x00_stop_firmware(ha);
+
+       /* turn-off interrupts on the card */
+       if (ha->interrupts_on)
+               ha->isp_ops.disable_intrs(ha);
 
+       qla2x00_mem_free(ha);
 
        ha->flags.online = 0;
 
        /* Detach interrupts */
-       if (ha->pdev->irq)
-               free_irq(ha->pdev->irq, ha);
+       if (ha->host->irq)
+               free_irq(ha->host->irq, ha);
 
        /* release io space registers  */
        if (ha->iobase)
@@ -1666,6 +1716,33 @@ qla2x00_free_device(scsi_qla_host_t *ha)
        pci_disable_device(ha->pdev);
 }
 
+static inline void
+qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
+    int defer)
+{
+       unsigned long flags;
+       struct fc_rport *rport;
+
+       if (!fcport->rport)
+               return;
+
+       rport = fcport->rport;
+       if (defer) {
+               spin_lock_irqsave(&fcport->rport_lock, flags);
+               fcport->drport = rport;
+               fcport->rport = NULL;
+               *(fc_port_t **)rport->dd_data = NULL;
+               spin_unlock_irqrestore(&fcport->rport_lock, flags);
+               set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
+       } else {
+               spin_lock_irqsave(&fcport->rport_lock, flags);
+               fcport->rport = NULL;
+               *(fc_port_t **)rport->dd_data = NULL;
+               spin_unlock_irqrestore(&fcport->rport_lock, flags);
+               fc_remote_port_delete(rport);
+       }
+}
+
 /*
  * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  *
@@ -1676,10 +1753,11 @@ qla2x00_free_device(scsi_qla_host_t *ha)
  * Context:
  */
 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
-    int do_login)
+    int do_login, int defer)
 {
-       if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
-               fc_remote_port_block(fcport->rport);
+       if (atomic_read(&fcport->state) == FCS_ONLINE)
+               qla2x00_schedule_rport_del(ha, fcport, defer);
+
        /*
         * We may need to retry the login, so don't change the state of the
         * port but do the retries.
@@ -1725,7 +1803,7 @@ void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
  * Context:
  */
 void
-qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
+qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
 {
        fc_port_t *fcport;
 
@@ -1739,10 +1817,13 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
                 */
                if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
                        continue;
-               if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
-                       fc_remote_port_block(fcport->rport);
+               if (atomic_read(&fcport->state) == FCS_ONLINE)
+                       qla2x00_schedule_rport_del(ha, fcport, defer);
                atomic_set(&fcport->state, FCS_DEVICE_LOST);
        }
+
+       if (defer)
+               qla2xxx_wake_dpc(ha);
 }
 
 /*
@@ -1805,19 +1886,8 @@ qla2x00_mem_alloc(scsi_qla_host_t *ha)
                        continue;
                }
 
-               ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
-                   sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
-               if (ha->rlc_rsp == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                               "Memory Allocation failed - rlc");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
+               snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
+                   ha->host_no);
                ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
                    DMA_POOL_SIZE, 8, 0);
                if (ha->s_dma_pool == NULL) {
@@ -1844,32 +1914,6 @@ qla2x00_mem_alloc(scsi_qla_host_t *ha)
                }
                memset(ha->init_cb, 0, ha->init_cb_size);
 
-               /* Get consistent memory allocated for Get Port Database cmd */
-               ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
-                   &ha->iodesc_pd_dma);
-               if (ha->iodesc_pd == NULL) {
-                       /* error */
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - iodesc_pd\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-               memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
-
-               /* Allocate ioctl related memory. */
-               if (qla2x00_alloc_ioctl_mem(ha)) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - ioctl_mem\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
                if (qla2x00_allocate_sp_pool(ha)) {
                        qla_printk(KERN_WARNING, ha,
                            "Memory Allocation failed - "
@@ -1932,6 +1976,26 @@ qla2x00_mem_alloc(scsi_qla_host_t *ha)
                                continue;
                        }
                        memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
+
+                       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+                               /*
+                                * Get consistent memory allocated for SFP
+                                * block.
+                                */
+                               ha->sfp_data = dma_pool_alloc(ha->s_dma_pool,
+                                   GFP_KERNEL, &ha->sfp_data_dma);
+                               if (ha->sfp_data == NULL) {
+                                       qla_printk(KERN_WARNING, ha,
+                                           "Memory Allocation failed - "
+                                           "sfp_data\n");
+
+                                       qla2x00_mem_free(ha);
+                                       msleep(100);
+
+                                       continue;
+                               }
+                               memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
+                       }
                }
 
                /* Done all allocations without any error. */
@@ -1959,7 +2023,6 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
 {
        struct list_head        *fcpl, *fcptemp;
        fc_port_t       *fcport;
-       unsigned int    wtime;/* max wait time if mbx cmd is busy. */
 
        if (ha == NULL) {
                /* error */
@@ -1967,17 +2030,16 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
                return;
        }
 
-       /* Make sure all other threads are stopped. */
-       wtime = 60 * 1000;
-       while (ha->dpc_wait && wtime)
-               wtime = msleep_interruptible(wtime);
-
-       /* free ioctl memory */
-       qla2x00_free_ioctl_mem(ha);
-
        /* free sp pool */
        qla2x00_free_sp_pool(ha);
 
+       if (ha->fw_dump) {
+               if (ha->eft)
+                       dma_free_coherent(&ha->pdev->dev,
+                           ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
+               vfree(ha->fw_dump);
+       }
+
        if (ha->sns_cmd)
                dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
                    ha->sns_cmd, ha->sns_cmd_dma);
@@ -1986,23 +2048,18 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
                dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
                    ha->ct_sns, ha->ct_sns_dma);
 
+       if (ha->sfp_data)
+               dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
+
        if (ha->ms_iocb)
                dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
 
-       if (ha->iodesc_pd)
-               dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
-
        if (ha->init_cb)
                dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
 
        if (ha->s_dma_pool)
                dma_pool_destroy(ha->s_dma_pool);
 
-       if (ha->rlc_rsp)
-               dma_free_coherent(&ha->pdev->dev,
-                   sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
-                   ha->rlc_rsp_dma);
-
        if (ha->gid_list)
                dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
                    ha->gid_list_dma);
@@ -2017,21 +2074,19 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
                    (ha->request_q_length + 1) * sizeof(request_t),
                    ha->request_ring, ha->request_dma);
 
+       ha->eft = NULL;
+       ha->eft_dma = 0;
        ha->sns_cmd = NULL;
        ha->sns_cmd_dma = 0;
        ha->ct_sns = NULL;
        ha->ct_sns_dma = 0;
        ha->ms_iocb = NULL;
        ha->ms_iocb_dma = 0;
-       ha->iodesc_pd = NULL;
-       ha->iodesc_pd_dma = 0;
        ha->init_cb = NULL;
        ha->init_cb_dma = 0;
 
        ha->s_dma_pool = NULL;
 
-       ha->rlc_rsp = NULL;
-       ha->rlc_rsp_dma = 0;
        ha->gid_list = NULL;
        ha->gid_list_dma = 0;
 
@@ -2049,18 +2104,11 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
        }
        INIT_LIST_HEAD(&ha->fcports);
 
-       if (ha->fw_dump)
-               free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
-
-       vfree(ha->fw_dump24);
-
-       vfree(ha->fw_dump_buffer);
-
        ha->fw_dump = NULL;
-       ha->fw_dump24 = NULL;
        ha->fw_dumped = 0;
        ha->fw_dump_reading = 0;
-       ha->fw_dump_buffer = NULL;
+
+       vfree(ha->optrom_buffer);
 }
 
 /*
@@ -2073,8 +2121,6 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
  *
  * Context:
  *      Kernel context.
- *
- * Note: Sets the ref_count for non Null sp to one.
  */
 static int
 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
@@ -2082,8 +2128,7 @@ qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
        int      rval;
 
        rval = QLA_SUCCESS;
-       ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
-           mempool_free_slab, srb_cachep);
+       ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
        if (ha->srb_mempool == NULL) {
                qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
                rval = QLA_FUNCTION_FAILED;
@@ -2120,7 +2165,6 @@ qla2x00_free_sp_pool( scsi_qla_host_t *ha)
 static int
 qla2x00_do_dpc(void *data)
 {
-       DECLARE_MUTEX_LOCKED(sem);
        scsi_qla_host_t *ha;
        fc_port_t       *fcport;
        uint8_t         status;
@@ -2128,32 +2172,19 @@ qla2x00_do_dpc(void *data)
 
        ha = (scsi_qla_host_t *)data;
 
-       lock_kernel();
-
-       daemonize("%s_dpc", ha->host_str);
-       allow_signal(SIGHUP);
-
-       ha->dpc_wait = &sem;
-
        set_user_nice(current, -20);
 
-       unlock_kernel();
-
-       complete(&ha->dpc_inited);
-
-       while (1) {
+       while (!kthread_should_stop()) {
                DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
 
-               if (down_interruptible(&sem))
-                       break;
-
-               if (ha->dpc_should_die)
-                       break;
+               set_current_state(TASK_INTERRUPTIBLE);
+               schedule();
+               __set_current_state(TASK_RUNNING);
 
                DEBUG3(printk("qla2x00: DPC handler waking up\n"));
 
                /* Initialization not yet finished. Don't do anything yet. */
-               if (!ha->flags.init_done || ha->dpc_active)
+               if (!ha->flags.init_done)
                        continue;
 
                DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
@@ -2184,6 +2215,15 @@ qla2x00_do_dpc(void *data)
                            ha->host_no));
                }
 
+               if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
+                       qla2x00_update_fcports(ha);
+
+               if (test_and_clear_bit(LOOP_RESET_NEEDED, &ha->dpc_flags)) {
+                       DEBUG(printk("scsi(%ld): dpc: sched loop_reset()\n",
+                           ha->host_no));
+                       qla2x00_loop_reset(ha);
+               }
+
                if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
                    (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
 
@@ -2228,7 +2268,7 @@ qla2x00_do_dpc(void *data)
                                        } else
                                                status =
                                                    qla2x00_local_device_login(
-                                                       ha, fcport->loop_id);
+                                                       ha, fcport);
 
                                        if (status == QLA_SUCCESS) {
                                                fcport->old_loop_id = fcport->loop_id;
@@ -2236,13 +2276,8 @@ qla2x00_do_dpc(void *data)
                                                DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
                                                    ha->host_no, fcport->loop_id));
 
-                                               fcport->port_login_retry_count =
-                                                   ha->port_down_retry_count * PORT_RETRY_TIME;
-                                               atomic_set(&fcport->state, FCS_ONLINE);
-                                               atomic_set(&fcport->port_down_timer,
-                                                   ha->port_down_retry_count * PORT_RETRY_TIME);
-
-                                               fcport->login_retry = 0;
+                                               qla2x00_update_fcport(ha,
+                                                   fcport);
                                        } else if (status == 1) {
                                                set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
                                                /* retry the login again */
@@ -2305,6 +2340,9 @@ qla2x00_do_dpc(void *data)
                if (!ha->interrupts_on)
                        ha->isp_ops.enable_intrs(ha);
 
+               if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
+                       ha->isp_ops.beacon_blink(ha);
+
                ha->dpc_active = 0;
        } /* End of while(1) */
 
@@ -2313,10 +2351,16 @@ qla2x00_do_dpc(void *data)
        /*
         * Make sure that nobody tries to wake us up again.
         */
-       ha->dpc_wait = NULL;
        ha->dpc_active = 0;
 
-       complete_and_exit(&ha->dpc_exited, 0);
+       return 0;
+}
+
+void
+qla2xxx_wake_dpc(scsi_qla_host_t *ha)
+{
+       if (ha->dpc_thread)
+               wake_up_process(ha->dpc_thread);
 }
 
 /*
@@ -2482,17 +2526,23 @@ qla2x00_timer(scsi_qla_host_t *ha)
                    atomic_read(&ha->loop_down_timer)));
        }
 
+       /* Check if beacon LED needs to be blinked */
+       if (ha->beacon_blink_led == 1) {
+               set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
+               start_dpc++;
+       }
+
        /* Schedule the DPC routine if needed */
        if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
            test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
+           test_bit(LOOP_RESET_NEEDED, &ha->dpc_flags) ||
+           test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
            start_dpc ||
            test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
            test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
-           test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
-           ha->dpc_wait && !ha->dpc_active) {
-
-               up(ha->dpc_wait);
-       }
+           test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
+           test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
+               qla2xxx_wake_dpc(ha);
 
        qla2x00_restart_timer(ha, WATCH_INTERVAL);
 }
@@ -2514,58 +2564,96 @@ qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
        return -ETIMEDOUT;
 }
 
-static struct qla_board_info qla_board_tbl[] = {
-       {
-               .drv_name       = "qla2400",
-               .isp_name       = "ISP2422",
-               .fw_fname       = "ql2400_fw.bin",
-               .sht            = &qla24xx_driver_template,
-       },
-       {
-               .drv_name       = "qla2400",
-               .isp_name       = "ISP2432",
-               .fw_fname       = "ql2400_fw.bin",
-               .sht            = &qla24xx_driver_template,
-       },
-};
+/* Firmware interface routines. */
 
-static struct pci_device_id qla2xxx_pci_tbl[] = {
-       {
-               .vendor         = PCI_VENDOR_ID_QLOGIC,
-               .device         = PCI_DEVICE_ID_QLOGIC_ISP2422,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .driver_data    = (unsigned long)&qla_board_tbl[0],
-       },
-       {
-               .vendor         = PCI_VENDOR_ID_QLOGIC,
-               .device         = PCI_DEVICE_ID_QLOGIC_ISP2432,
-               .subvendor      = PCI_ANY_ID,
-               .subdevice      = PCI_ANY_ID,
-               .driver_data    = (unsigned long)&qla_board_tbl[1],
-       },
-       {0, 0},
+#define FW_BLOBS       5
+#define FW_ISP21XX     0
+#define FW_ISP22XX     1
+#define FW_ISP2300     2
+#define FW_ISP2322     3
+#define FW_ISP24XX     4
+
+static DECLARE_MUTEX(qla_fw_lock);
+
+static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
+       { .name = "ql2100_fw.bin", .segs = { 0x1000, 0 }, },
+       { .name = "ql2200_fw.bin", .segs = { 0x1000, 0 }, },
+       { .name = "ql2300_fw.bin", .segs = { 0x800, 0 }, },
+       { .name = "ql2322_fw.bin", .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
+       { .name = "ql2400_fw.bin", },
 };
-MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
 
-static int __devinit
-qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
+struct fw_blob *
+qla2x00_request_firmware(scsi_qla_host_t *ha)
 {
-       return qla2x00_probe_one(pdev,
-           (struct qla_board_info *)id->driver_data);
+       struct fw_blob *blob;
+
+       blob = NULL;
+       if (IS_QLA2100(ha)) {
+               blob = &qla_fw_blobs[FW_ISP21XX];
+       } else if (IS_QLA2200(ha)) {
+               blob = &qla_fw_blobs[FW_ISP22XX];
+       } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
+               blob = &qla_fw_blobs[FW_ISP2300];
+       } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
+               blob = &qla_fw_blobs[FW_ISP2322];
+       } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+               blob = &qla_fw_blobs[FW_ISP24XX];
+       }
+
+       down(&qla_fw_lock);
+       if (blob->fw)
+               goto out;
+
+       if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
+               DEBUG2(printk("scsi(%ld): Failed to load firmware image "
+                   "(%s).\n", ha->host_no, blob->name));
+               blob->fw = NULL;
+               blob = NULL;
+               goto out;
+       }
+
+out:
+       up(&qla_fw_lock);
+       return blob;
 }
 
-static void __devexit
-qla2xxx_remove_one(struct pci_dev *pdev)
+static void
+qla2x00_release_firmware(void)
 {
-       qla2x00_remove_one(pdev);
+       int idx;
+
+       down(&qla_fw_lock);
+       for (idx = 0; idx < FW_BLOBS; idx++)
+               if (qla_fw_blobs[idx].fw)
+                       release_firmware(qla_fw_blobs[idx].fw);
+       up(&qla_fw_lock);
 }
 
+static struct pci_device_id qla2xxx_pci_tbl[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
+       { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
+       { 0 },
+};
+MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
+
 static struct pci_driver qla2xxx_pci_driver = {
-       .name           = "qla2xxx",
+       .name           = QLA2XXX_DRIVER_NAME,
+       .driver         = {
+               .owner          = THIS_MODULE,
+       },
        .id_table       = qla2xxx_pci_tbl,
-       .probe          = qla2xxx_probe_one,
-       .remove         = __devexit_p(qla2xxx_remove_one),
+       .probe          = qla2x00_probe_one,
+       .remove         = __devexit_p(qla2x00_remove_one),
 };
 
 /**
@@ -2587,16 +2675,16 @@ qla2x00_module_init(void)
 
        /* Derive version string. */
        strcpy(qla2x00_version_str, QLA2XXX_VERSION);
-#if DEBUG_QLA2100
-       strcat(qla2x00_version_str, "-debug");
-#endif
+       if (extended_error_logging)
+               strcat(qla2x00_version_str, "-debug");
+
        qla2xxx_transport_template =
            fc_attach_transport(&qla2xxx_transport_functions);
        if (!qla2xxx_transport_template)
                return -ENODEV;
 
        printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
-       ret = pci_module_init(&qla2xxx_pci_driver);
+       ret = pci_register_driver(&qla2xxx_pci_driver);
        if (ret) {
                kmem_cache_destroy(srb_cachep);
                fc_release_transport(qla2xxx_transport_template);
@@ -2611,6 +2699,7 @@ static void __exit
 qla2x00_module_exit(void)
 {
        pci_unregister_driver(&qla2xxx_pci_driver);
+       qla2x00_release_firmware();
        kmem_cache_destroy(srb_cachep);
        fc_release_transport(qla2xxx_transport_template);
 }