fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / scsi / qla2xxx / qla_os.c
index 584fe5d..af3f54a 100644 (file)
@@ -24,7 +24,7 @@ char qla2x00_version_str[40];
 /*
  * SRB allocation cache
  */
-static kmem_cache_t *srb_cachep;
+static struct kmem_cache *srb_cachep;
 
 /*
  * Ioctl related information.
@@ -39,14 +39,14 @@ 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 ql2xloginretrycount = 0;
@@ -54,12 +54,18 @@ module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
 MODULE_PARM_DESC(ql2xloginretrycount,
                "Specify an alternate value for the NVRAM login retry count.");
 
-#if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
-int ql2xfwloadflash;
-module_param(ql2xfwloadflash, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xfwloadflash,
-               "Load ISP24xx firmware image from FLASH (onboard memory).");
-#endif
+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 ql2xextended_error_logging;
+module_param(ql2xextended_error_logging, int, S_IRUGO|S_IRUSR);
+MODULE_PARM_DESC(ql2xextended_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 *);
 
@@ -71,17 +77,26 @@ MODULE_PARM_DESC(ql2xfdmienable,
                "Enables FDMI registratons "
                "Default is 0 - no FDMI. 1 - perfom FDMI.");
 
-int ql2xprocessrscn;
-module_param(ql2xprocessrscn, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xprocessrscn,
-               "Option to enable port RSCN handling via a series of less"
-               "fabric intrusive ADISCs and PLOGIs.");
+#define MAX_Q_DEPTH    32
+static int ql2xmaxqdepth = MAX_Q_DEPTH;
+module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(ql2xmaxqdepth,
+               "Maximum queue depth to report for target devices.");
+
+int ql2xqfullrampup = 120;
+module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(ql2xqfullrampup,
+               "Number of seconds to wait to begin to ramp-up the queue "
+               "depth for a device after a queue-full condition has been "
+               "detected.  Default is 120 seconds.");
 
 /*
  * SCSI host template entry points
  */
 static int qla2xxx_slave_configure(struct scsi_device * device);
 static int qla2xxx_slave_alloc(struct scsi_device *);
+static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
+static void qla2xxx_scan_start(struct Scsi_Host *);
 static void qla2xxx_slave_destroy(struct scsi_device *);
 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
                void (*fn)(struct scsi_cmnd *));
@@ -99,7 +114,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,
@@ -111,6 +126,8 @@ static struct scsi_host_template qla2x00_driver_template = {
 
        .slave_alloc            = qla2xxx_slave_alloc,
        .slave_destroy          = qla2xxx_slave_destroy,
+       .scan_finished          = qla2xxx_scan_finished,
+       .scan_start             = qla2xxx_scan_start,
        .change_queue_depth     = qla2x00_change_queue_depth,
        .change_queue_type      = qla2x00_change_queue_type,
        .this_id                = -1,
@@ -128,7 +145,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,
@@ -274,7 +291,7 @@ qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
        return str;
 }
 
-char *
+static char *
 qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
 {
        char un_str[10];
@@ -312,7 +329,7 @@ qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
        return (str);
 }
 
-char *
+static char *
 qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
 {
        sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
@@ -340,7 +357,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;
@@ -577,6 +593,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;
@@ -586,6 +606,23 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
        return (return_status);
 }
 
+static void
+qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
+{
+       struct Scsi_Host *shost = cmnd->device->host;
+       struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
+       unsigned long flags;
+
+       spin_lock_irqsave(shost->host_lock, flags);
+       while (rport->port_state == FC_PORTSTATE_BLOCKED) {
+               spin_unlock_irqrestore(shost->host_lock, flags);
+               msleep(1000);
+               spin_lock_irqsave(shost->host_lock, flags);
+       }
+       spin_unlock_irqrestore(shost->host_lock, flags);
+       return;
+}
+
 /**************************************************************************
 * qla2xxx_eh_abort
 *
@@ -601,7 +638,7 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
 * Note:
 *    Only return FAILED if command not returned by firmware.
 **************************************************************************/
-int
+static int
 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
@@ -612,6 +649,8 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
        unsigned long flags;
        int wait = 0;
 
+       qla2x00_block_error_handler(cmd);
+
        if (!CMD_SP(cmd))
                return SUCCESS;
 
@@ -632,10 +671,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)) {
@@ -737,24 +775,24 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
 *    SUCCESS/FAILURE (defined as macro in scsi.h).
 *
 **************************************************************************/
-int
+static int
 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
        fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
-       srb_t *sp;
        int ret;
        unsigned int id, lun;
        unsigned long serial;
 
+       qla2x00_block_error_handler(cmd);
+
        ret = FAILED;
 
        id = cmd->device->id;
        lun = cmd->device->lun;
        serial = cmd->serial_number;
 
-       sp = (srb_t *) CMD_SP(cmd);
-       if (!sp || !fcport)
+       if (!fcport)
                return ret;
 
        qla_printk(KERN_INFO, ha,
@@ -777,7 +815,7 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
 #endif
        } else {
                DEBUG2(printk(KERN_INFO
-                   "%s failed: loop not ready\n",__func__);)
+                   "%s failed: loop not ready\n",__func__));
        }
 
        if (ret == FAILED) {
@@ -868,24 +906,24 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
 *    SUCCESS/FAILURE (defined as macro in scsi.h).
 *
 **************************************************************************/
-int
+static int
 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
        fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
-       srb_t *sp;
        int ret;
        unsigned int id, lun;
        unsigned long serial;
 
+       qla2x00_block_error_handler(cmd);
+
        ret = FAILED;
 
        id = cmd->device->id;
        lun = cmd->device->lun;
        serial = cmd->serial_number;
 
-       sp = (srb_t *) CMD_SP(cmd);
-       if (!sp || !fcport)
+       if (!fcport)
                return ret;
 
        qla_printk(KERN_INFO, ha,
@@ -929,24 +967,24 @@ eh_bus_reset_done:
 *
 * Note:
 **************************************************************************/
-int
+static int
 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
 {
        scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
        fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
-       srb_t *sp;
        int ret;
        unsigned int id, lun;
        unsigned long serial;
 
+       qla2x00_block_error_handler(cmd);
+
        ret = FAILED;
 
        id = cmd->device->id;
        lun = cmd->device->lun;
        serial = cmd->serial_number;
 
-       sp = (srb_t *) CMD_SP(cmd);
-       if (!sp || !fcport)
+       if (!fcport)
                return ret;
 
        qla_printk(KERN_INFO, ha,
@@ -999,48 +1037,49 @@ eh_host_reset_lock:
 static int
 qla2x00_loop_reset(scsi_qla_host_t *ha)
 {
-       int status = QLA_SUCCESS;
+       int ret;
        struct fc_port *fcport;
 
+       if (ha->flags.enable_lip_full_login) {
+               ret = qla2x00_full_login_lip(ha);
+               if (ret != QLA_SUCCESS) {
+                       DEBUG2_3(printk("%s(%ld): bus_reset failed: "
+                           "full_login_lip=%d.\n", __func__, ha->host_no,
+                           ret));
+               }
+               atomic_set(&ha->loop_state, LOOP_DOWN);
+               atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
+               qla2x00_mark_all_devices_lost(ha, 0);
+               qla2x00_wait_for_loop_ready(ha);
+       }
+
        if (ha->flags.enable_lip_reset) {
-               status = qla2x00_lip_reset(ha);
+               ret = qla2x00_lip_reset(ha);
+               if (ret != QLA_SUCCESS) {
+                       DEBUG2_3(printk("%s(%ld): bus_reset failed: "
+                           "lip_reset=%d.\n", __func__, ha->host_no, ret));
+               }
+               qla2x00_wait_for_loop_ready(ha);
        }
 
-       if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
+       if (ha->flags.enable_target_reset) {
                list_for_each_entry(fcport, &ha->fcports, list) {
                        if (fcport->port_type != FCT_TARGET)
                                continue;
 
-                       status = qla2x00_device_reset(ha, fcport);
-                       if (status != QLA_SUCCESS)
-                               break;
+                       ret = qla2x00_device_reset(ha, fcport);
+                       if (ret != QLA_SUCCESS) {
+                               DEBUG2_3(printk("%s(%ld): bus_reset failed: "
+                                   "target_reset=%d d_id=%x.\n", __func__,
+                                   ha->host_no, ret, fcport->d_id.b24));
+                       }
                }
        }
 
-       if (status == QLA_SUCCESS &&
-               ((!ha->flags.enable_target_reset &&
-                 !ha->flags.enable_lip_reset) ||
-               ha->flags.enable_lip_full_login)) {
-
-               status = qla2x00_full_login_lip(ha);
-       }
-
        /* Issue marker command only when we are going to start the I/O */
        ha->marker_needed = 1;
 
-       if (status) {
-               /* Empty */
-               DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
-                               __func__,
-                               ha->host_no);)
-       } else {
-               /* Empty */
-               DEBUG3(printk("%s(%ld): exiting normally.\n",
-                               __func__,
-                               ha->host_no);)
-       }
-
-       return(status);
+       return QLA_SUCCESS;
 }
 
 /*
@@ -1083,9 +1122,9 @@ qla2xxx_slave_configure(struct scsi_device *sdev)
        struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
 
        if (sdev->tagged_supported)
-               scsi_activate_tcq(sdev, 32);
+               scsi_activate_tcq(sdev, ha->max_q_depth);
        else
-               scsi_deactivate_tcq(sdev, 32);
+               scsi_deactivate_tcq(sdev, ha->max_q_depth);
 
        rport->dev_loss_tmo = ha->port_down_retry_count + 5;
 
@@ -1157,18 +1196,22 @@ qla2x00_set_isp_flags(scsi_qla_host_t *ha)
        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;
@@ -1176,26 +1219,33 @@ qla2x00_set_isp_flags(scsi_qla_host_t *ha)
                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;
        }
 }
@@ -1242,7 +1292,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));
@@ -1321,20 +1371,42 @@ qla24xx_disable_intrs(scsi_qla_host_t *ha)
        spin_unlock_irqrestore(&ha->hardware_lock, flags);
 }
 
+static void
+qla2xxx_scan_start(struct Scsi_Host *shost)
+{
+       scsi_qla_host_t *ha = (scsi_qla_host_t *)shost->hostdata;
+
+       set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
+       set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
+       set_bit(RSCN_UPDATE, &ha->dpc_flags);
+}
+
+static int
+qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
+{
+       scsi_qla_host_t *ha = (scsi_qla_host_t *)shost->hostdata;
+
+       if (!ha->host)
+               return 1;
+       if (time > ha->loop_reset_delay * HZ)
+               return 1;
+
+       return atomic_read(&ha->loop_state) == LOOP_READY;
+}
+
 /*
  * 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;
        struct Scsi_Host *host;
        scsi_qla_host_t *ha;
        unsigned long   flags = 0;
-       unsigned long   wait_switch = 0;
        char pci_info[20];
        char fw_str[30];
-       fc_port_t *fcport;
        struct scsi_host_template *sht;
 
        if (pci_enable_device(pdev))
@@ -1342,7 +1414,9 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
 
        sht = &qla2x00_driver_template;
        if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
-           pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432)
+           pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
+           pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
+           pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432)
                sht = &qla24xx_driver_template;
        host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
        if (host == NULL) {
@@ -1358,8 +1432,7 @@ 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);
@@ -1376,12 +1449,15 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        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->link_data_rate = PORT_SPEED_UNKNOWN;
        ha->optrom_size = OPTROM_SIZE_2300;
 
+       ha->max_q_depth = MAX_Q_DEPTH;
+       if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
+               ha->max_q_depth = ql2xmaxqdepth;
+
        /* Assign ISP specific operations. */
        ha->isp_ops.pci_config          = qla2100_pci_config;
        ha->isp_ops.reset_chip          = qla2x00_reset_chip;
@@ -1407,7 +1483,6 @@ 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)) {
@@ -1434,7 +1509,6 @@ 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;
@@ -1457,10 +1531,6 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
                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;
-#if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
-               if (ql2xfwloadflash)
-                       ha->isp_ops.load_risc = qla24xx_load_risc_flash;
-#endif
                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;
@@ -1475,7 +1545,6 @@ 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;
@@ -1494,7 +1563,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
@@ -1543,12 +1611,12 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
        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);
+           IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
        if (ret) {
                qla_printk(KERN_WARNING, ha,
                    "Failed to reserve interrupt %d already in use.\n",
@@ -1591,30 +1659,19 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
 
        ha->isp_ops.enable_intrs(ha);
 
-       /* v2.19.5b6 */
-       /*
-        * Wait around max loop_reset_delay secs for the devices to come
-        * on-line. We don't want Linux scanning before we are ready.
-        *
-        */
-       for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
-           time_before(jiffies,wait_switch) &&
-            !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
-            && (ha->device_flags & SWITCH_FOUND) ;) {
-
-               qla2x00_check_fabric_devices(ha);
-
-               msleep(10);
-       }
-
        pci_set_drvdata(pdev, ha);
+
        ha->flags.init_done = 1;
+       ha->flags.online = 1;
+
        num_hosts++;
 
        ret = scsi_add_host(host, &pdev->dev);
        if (ret)
                goto probe_failed;
 
+       scsi_scan_host(host);
+
        qla2x00_alloc_sysfs_attr(ha);
 
        qla2x00_init_host_attr(ha);
@@ -1629,10 +1686,6 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
            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)
-               qla2x00_reg_remote_port(ha, fcport);
-
        return 0;
 
 probe_failed:
@@ -1646,9 +1699,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;
 
@@ -1666,15 +1719,10 @@ 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)
 {
-       /* Abort any outstanding IO descriptors. */
-       if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
-               qla2x00_cancel_io_descriptors(ha);
-
        /* Disable timer */
        if (ha->timer_active)
                qla2x00_stop_timer(ha);
@@ -1691,8 +1739,13 @@ qla2x00_free_device(scsi_qla_host_t *ha)
                kthread_stop(t);
        }
 
+       if (ha->eft)
+               qla2x00_trace_control(ha, TC_DISABLE, 0, 0);
+
+       ha->flags.online = 0;
+
        /* Stop currently executing firmware. */
-       qla2x00_stop_firmware(ha);
+       qla2x00_try_to_stop_firmware(ha);
 
        /* turn-off interrupts on the card */
        if (ha->interrupts_on)
@@ -1700,8 +1753,6 @@ qla2x00_free_device(scsi_qla_host_t *ha)
 
        qla2x00_mem_free(ha);
 
-       ha->flags.online = 0;
-
        /* Detach interrupts */
        if (ha->host->irq)
                free_irq(ha->host->irq, ha);
@@ -1884,19 +1935,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) {
@@ -1923,32 +1963,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 - "
@@ -2011,6 +2025,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. */
@@ -2045,12 +2079,16 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
                return;
        }
 
-       /* 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);
@@ -2059,23 +2097,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);
@@ -2090,21 +2123,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;
 
@@ -2122,18 +2153,9 @@ 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);
 }
@@ -2148,8 +2170,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)
@@ -2273,9 +2293,6 @@ qla2x00_do_dpc(void *data)
 
                        next_loopid = 0;
                        list_for_each_entry(fcport, &ha->fcports, list) {
-                               if (fcport->port_type != FCT_TARGET)
-                                       continue;
-
                                /*
                                 * If the port is not ONLINE then try to login
                                 * to it if we haven't run out of retries.
@@ -2593,14 +2610,6 @@ qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
        return -ETIMEDOUT;
 }
 
-#if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
-
-#define qla2x00_release_firmware()     do { } while (0)
-#define qla2x00_pci_module_init()      (0)
-#define qla2x00_pci_module_exit()      do { } while (0)
-
-#else  /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
-
 /* Firmware interface routines. */
 
 #define FW_BLOBS       5
@@ -2610,14 +2619,22 @@ qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
 #define FW_ISP2322     3
 #define FW_ISP24XX     4
 
+#define FW_FILE_ISP21XX        "ql2100_fw.bin"
+#define FW_FILE_ISP22XX        "ql2200_fw.bin"
+#define FW_FILE_ISP2300        "ql2300_fw.bin"
+#define FW_FILE_ISP2322        "ql2322_fw.bin"
+#define FW_FILE_ISP24XX        "ql2400_fw.bin"
+
 static DECLARE_MUTEX(qla_fw_lock);
 
+extern struct firmware ql2100_fw, ql2200_fw, ql2300_fw, ql2322_fw, ql2400_fw;
+
 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", },
+       { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, .fw = &ql2100_fw },
+       { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, .fw = &ql2200_fw },
+       { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, .fw = &ql2300_fw },
+       { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, .fw = &ql2322_fw },
+       { .name = FW_FILE_ISP24XX, .fw = &ql2400_fw },
 };
 
 struct fw_blob *
@@ -2667,73 +2684,32 @@ qla2x00_release_firmware(void)
        up(&qla_fw_lock);
 }
 
-static struct qla_board_info qla_board_tbl = {
-       .drv_name       = "qla2xxx",
-};
-
 static struct pci_device_id qla2xxx_pci_tbl[] = {
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422,
-               PCI_ANY_ID, PCI_ANY_ID, },
-       { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432,
-               PCI_ANY_ID, PCI_ANY_ID, },
+       { 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 int __devinit
-qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
-{
-       return qla2x00_probe_one(pdev, &qla_board_tbl);
-}
-
-static void __devexit
-qla2xxx_remove_one(struct pci_dev *pdev)
-{
-       qla2x00_remove_one(pdev);
-}
-
 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),
 };
 
-static inline int
-qla2x00_pci_module_init(void)
-{
-       return pci_module_init(&qla2xxx_pci_driver);
-}
-
-static inline void
-qla2x00_pci_module_exit(void)
-{
-       pci_unregister_driver(&qla2xxx_pci_driver);
-}
-
-#endif
-
 /**
  * qla2x00_module_init - Module initialization.
  **/
@@ -2753,19 +2729,16 @@ qla2x00_module_init(void)
 
        /* Derive version string. */
        strcpy(qla2x00_version_str, QLA2XXX_VERSION);
-#if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
-       strcat(qla2x00_version_str, "-fw");
-#endif
-#if DEBUG_QLA2100
-       strcat(qla2x00_version_str, "-debug");
-#endif
+       if (ql2xextended_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 = qla2x00_pci_module_init();
+       ret = pci_register_driver(&qla2xxx_pci_driver);
        if (ret) {
                kmem_cache_destroy(srb_cachep);
                fc_release_transport(qla2xxx_transport_template);
@@ -2779,8 +2752,8 @@ qla2x00_module_init(void)
 static void __exit
 qla2x00_module_exit(void)
 {
-       qla2x00_pci_module_exit();
-       qla2x00_release_firmware();
+       pci_unregister_driver(&qla2xxx_pci_driver);
+       /* qla2x00_release_firmware(); */
        kmem_cache_destroy(srb_cachep);
        fc_release_transport(qla2xxx_transport_template);
 }
@@ -2792,3 +2765,8 @@ MODULE_AUTHOR("QLogic Corporation");
 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(QLA2XXX_VERSION);
+MODULE_FIRMWARE(FW_FILE_ISP21XX);
+MODULE_FIRMWARE(FW_FILE_ISP22XX);
+MODULE_FIRMWARE(FW_FILE_ISP2300);
+MODULE_FIRMWARE(FW_FILE_ISP2322);
+MODULE_FIRMWARE(FW_FILE_ISP24XX);