]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/qla2xxx/qla_os.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[linux-2.6-omap-h63xx.git] / drivers / scsi / qla2xxx / qla_os.c
index 7aec93f9d4231689b33ce9c450629904f3432807..4916847d84ec9321a58629c0eef15543e73d2873 100644 (file)
@@ -1,20 +1,8 @@
 /*
- *                  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"
 
@@ -61,28 +49,17 @@ MODULE_PARM_DESC(ql2xplogiabsentdevice,
                "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=1;
-module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
-MODULE_PARM_DESC(ql2xfwloadbin,
-               "Load ISP2xxx firmware image via hotplug.");
+#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
 
 static void qla2x00_free_device(scsi_qla_host_t *);
 
@@ -94,6 +71,12 @@ 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.");
+
 /*
  * SCSI host template entry points
  */
@@ -373,11 +356,13 @@ 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;
        }
 
@@ -400,16 +385,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 +411,13 @@ 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;
        }
 
@@ -797,29 +774,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 +888,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__,
@@ -1087,10 +1053,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;
 }
@@ -1303,12 +1269,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");
@@ -1333,8 +1303,8 @@ 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);
 
@@ -1410,9 +1380,11 @@ 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;
+#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;
@@ -1573,11 +1545,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)
@@ -1682,7 +1655,8 @@ void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
     int do_login)
 {
        if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
-               fc_remote_port_block(fcport->rport);
+               schedule_work(&fcport->rport_del_work);
+
        /*
         * We may need to retry the login, so don't change the state of the
         * port but do the retries.
@@ -1743,7 +1717,7 @@ 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);
+                       schedule_work(&fcport->rport_del_work);
                atomic_set(&fcport->state, FCS_DEVICE_LOST);
        }
 }
@@ -2187,6 +2161,12 @@ qla2x00_do_dpc(void *data)
                            ha->host_no));
                }
 
+               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)))) {
 
@@ -2488,6 +2468,7 @@ qla2x00_timer(scsi_qla_host_t *ha)
        /* 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) ||
            start_dpc ||
            test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
            test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
@@ -2517,45 +2498,115 @@ 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,
-       },
+#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       6
+#define FW_ISP21XX     0
+#define FW_ISP22XX     1
+#define FW_ISP2300     2
+#define FW_ISP2322     3
+#define FW_ISP63XX     4
+#define FW_ISP24XX     5
+
+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 = "ql6312_fw.bin", .segs = { 0x800, 0 }, },
+       { .name = "ql2400_fw.bin", },
+};
+
+struct fw_blob *
+qla2x00_request_firmware(scsi_qla_host_t *ha)
+{
+       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)) {
+               blob = &qla_fw_blobs[FW_ISP2300];
+       } else if (IS_QLA2322(ha)) {
+               blob = &qla_fw_blobs[FW_ISP2322];
+       } else if (IS_QLA6312(ha) || IS_QLA6322(ha)) {
+               blob = &qla_fw_blobs[FW_ISP63XX];
+       } else if (IS_QLA24XX(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
+qla2x00_release_firmware(void)
+{
+       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 qla_board_info qla_board_tbl = {
+       .drv_name       = "qla2xxx",
 };
 
 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},
+       { 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, },
+       { 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,
-           (struct qla_board_info *)id->driver_data);
+       return qla2x00_probe_one(pdev, &qla_board_tbl);
 }
 
 static void __devexit
@@ -2566,11 +2617,28 @@ qla2xxx_remove_one(struct pci_dev *pdev)
 
 static struct pci_driver qla2xxx_pci_driver = {
        .name           = "qla2xxx",
+       .driver         = {
+               .owner          = THIS_MODULE,
+       },
        .id_table       = qla2xxx_pci_tbl,
        .probe          = qla2xxx_probe_one,
        .remove         = __devexit_p(qla2xxx_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.
  **/
@@ -2590,6 +2658,9 @@ 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
@@ -2599,7 +2670,7 @@ qla2x00_module_init(void)
                return -ENODEV;
 
        printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
-       ret = pci_module_init(&qla2xxx_pci_driver);
+       ret = qla2x00_pci_module_init();
        if (ret) {
                kmem_cache_destroy(srb_cachep);
                fc_release_transport(qla2xxx_transport_template);
@@ -2613,7 +2684,8 @@ qla2x00_module_init(void)
 static void __exit
 qla2x00_module_exit(void)
 {
-       pci_unregister_driver(&qla2xxx_pci_driver);
+       qla2x00_pci_module_exit();
+       qla2x00_release_firmware();
        kmem_cache_destroy(srb_cachep);
        fc_release_transport(qla2xxx_transport_template);
 }