2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/version.h>
16 #include <scsi/scsi_tcq.h>
17 #include <scsi/scsicam.h>
18 #include <scsi/scsi_transport.h>
19 #include <scsi/scsi_transport_fc.h>
21 #include "qla2x_tgt.h"
26 char qla2x00_version_str[40];
29 * SRB allocation cache
31 static struct kmem_cache *srb_cachep;
34 int ql2xlogintimeout = 20;
35 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
36 MODULE_PARM_DESC(ql2xlogintimeout,
37 "Login timeout value in seconds.");
39 int qlport_down_retry;
40 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
41 MODULE_PARM_DESC(qlport_down_retry,
42 "Maximum number of command retries to a port that returns "
43 "a PORT-DOWN status.");
45 int ql2xplogiabsentdevice;
46 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
47 MODULE_PARM_DESC(ql2xplogiabsentdevice,
48 "Option to enable PLOGI to devices that are not present after "
49 "a Fabric scan. This is needed for several broken switches. "
50 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
52 int ql2xloginretrycount = 0;
53 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
54 MODULE_PARM_DESC(ql2xloginretrycount,
55 "Specify an alternate value for the NVRAM login retry count.");
57 int ql2xenableclass2 = 0;
58 module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
59 MODULE_PARM_DESC(ql2xenableclass2,
60 "Specify if Class 2 operations are supported from the very "
63 int ql2xallocfwdump = 0;
64 module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
65 MODULE_PARM_DESC(ql2xallocfwdump,
66 "Option to enable allocation of memory for a firmware dump "
67 "during HBA initialization. Memory allocation requirements "
68 "vary by ISP type. Default is 0 - don't allocate memory.");
70 int ql2xextended_error_logging;
71 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
72 MODULE_PARM_DESC(ql2xextended_error_logging,
73 "Option to enable extended error logging, "
74 "Default is 0 - no logging. 1 - log errors.");
76 static void qla2x00_free_device(scsi_qla_host_t *);
78 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
81 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
82 MODULE_PARM_DESC(ql2xfdmienable,
83 "Enables FDMI registratons "
84 "Default is 0 - no FDMI. 1 - perfom FDMI.");
86 #define MAX_Q_DEPTH 32
87 static int ql2xmaxqdepth = MAX_Q_DEPTH;
88 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
89 MODULE_PARM_DESC(ql2xmaxqdepth,
90 "Maximum queue depth to report for target devices.");
92 int ql2xqfullrampup = 120;
93 module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
94 MODULE_PARM_DESC(ql2xqfullrampup,
95 "Number of seconds to wait to begin to ramp-up the queue "
96 "depth for a device after a queue-full condition has been "
97 "detected. Default is 120 seconds.");
100 * SCSI host template entry points
102 static int qla2xxx_slave_configure(struct scsi_device * device);
103 static int qla2xxx_slave_alloc(struct scsi_device *);
104 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
105 static void qla2xxx_scan_start(struct Scsi_Host *);
106 static void qla2xxx_slave_destroy(struct scsi_device *);
107 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
108 void (*fn)(struct scsi_cmnd *));
109 static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
110 void (*fn)(struct scsi_cmnd *));
111 static int qla2xxx_eh_abort(struct scsi_cmnd *);
112 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
113 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
114 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
115 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
117 static int qla2x00_change_queue_depth(struct scsi_device *, int);
118 static int qla2x00_change_queue_type(struct scsi_device *, int);
120 static struct scsi_host_template qla2x00_driver_template = {
121 .module = THIS_MODULE,
122 .name = QLA2XXX_DRIVER_NAME,
123 .queuecommand = qla2x00_queuecommand,
125 .eh_abort_handler = qla2xxx_eh_abort,
126 .eh_device_reset_handler = qla2xxx_eh_device_reset,
127 .eh_target_reset_handler = qla2xxx_eh_target_reset,
128 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
129 .eh_host_reset_handler = qla2xxx_eh_host_reset,
131 .slave_configure = qla2xxx_slave_configure,
133 .slave_alloc = qla2xxx_slave_alloc,
134 .slave_destroy = qla2xxx_slave_destroy,
135 .scan_finished = qla2xxx_scan_finished,
136 .scan_start = qla2xxx_scan_start,
137 .change_queue_depth = qla2x00_change_queue_depth,
138 .change_queue_type = qla2x00_change_queue_type,
141 .use_clustering = ENABLE_CLUSTERING,
142 .sg_tablesize = SG_ALL,
145 * The RISC allows for each command to transfer (2^32-1) bytes of data,
146 * which equates to 0x800000 sectors.
148 .max_sectors = 0xFFFF,
149 .shost_attrs = qla2x00_host_attrs,
151 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
152 .supported_mode = MODE_INITIATOR | MODE_TARGET,
156 struct scsi_host_template qla24xx_driver_template = {
157 .module = THIS_MODULE,
158 .name = QLA2XXX_DRIVER_NAME,
159 .queuecommand = qla24xx_queuecommand,
161 .eh_abort_handler = qla2xxx_eh_abort,
162 .eh_device_reset_handler = qla2xxx_eh_device_reset,
163 .eh_target_reset_handler = qla2xxx_eh_target_reset,
164 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
165 .eh_host_reset_handler = qla2xxx_eh_host_reset,
167 .slave_configure = qla2xxx_slave_configure,
169 .slave_alloc = qla2xxx_slave_alloc,
170 .slave_destroy = qla2xxx_slave_destroy,
171 .scan_finished = qla2xxx_scan_finished,
172 .scan_start = qla2xxx_scan_start,
173 .change_queue_depth = qla2x00_change_queue_depth,
174 .change_queue_type = qla2x00_change_queue_type,
177 .use_clustering = ENABLE_CLUSTERING,
178 .sg_tablesize = SG_ALL,
180 .max_sectors = 0xFFFF,
181 .shost_attrs = qla2x00_host_attrs,
183 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
184 .supported_mode = MODE_INITIATOR | MODE_TARGET,
188 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
189 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
191 /* TODO Convert to inlines
197 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
199 init_timer(&ha->timer);
200 ha->timer.expires = jiffies + interval * HZ;
201 ha->timer.data = (unsigned long)ha;
202 ha->timer.function = (void (*)(unsigned long))func;
203 add_timer(&ha->timer);
204 ha->timer_active = 1;
208 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
210 mod_timer(&ha->timer, jiffies + interval * HZ);
213 static __inline__ void
214 qla2x00_stop_timer(scsi_qla_host_t *ha)
216 del_timer_sync(&ha->timer);
217 ha->timer_active = 0;
220 static int qla2x00_do_dpc(void *data);
222 static void qla2x00_rst_aen(scsi_qla_host_t *);
224 static int qla2x00_mem_alloc(scsi_qla_host_t *);
225 static void qla2x00_mem_free(scsi_qla_host_t *ha);
226 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
228 /* -------------------------------------------------------------------------- */
231 qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
233 static char *pci_bus_modes[] = {
234 "33", "66", "100", "133",
239 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
242 strcat(str, pci_bus_modes[pci_bus]);
244 pci_bus = (ha->pci_attr & BIT_8) >> 8;
246 strcat(str, pci_bus_modes[pci_bus]);
248 strcat(str, " MHz)");
254 qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
256 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
260 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
263 uint16_t pcie_lstat, lspeed, lwidth;
266 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
267 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
268 lwidth = (pcie_lstat &
269 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
271 strcpy(str, "PCIe (");
273 strcat(str, "2.5GT/s ");
274 else if (lspeed == 2)
275 strcat(str, "5.0GT/s ");
277 strcat(str, "<unknown> ");
278 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
285 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
286 if (pci_bus == 0 || pci_bus == 8) {
288 strcat(str, pci_bus_modes[pci_bus >> 3]);
292 strcat(str, "Mode 2");
294 strcat(str, "Mode 1");
296 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
298 strcat(str, " MHz)");
304 qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
308 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
309 ha->fw_minor_version,
310 ha->fw_subminor_version);
312 if (ha->fw_attributes & BIT_9) {
317 switch (ha->fw_attributes & 0xFF) {
331 sprintf(un_str, "(%x)", ha->fw_attributes);
335 if (ha->fw_attributes & 0x100)
342 qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
344 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
345 ha->fw_minor_version,
346 ha->fw_subminor_version);
348 if (ha->fw_attributes & BIT_0)
349 strcat(str, "[Class 2] ");
350 if (ha->fw_attributes & BIT_1)
351 strcat(str, "[IP] ");
352 if (ha->fw_attributes & BIT_2)
353 strcat(str, "[Multi-ID] ");
354 if (ha->fw_attributes & BIT_3)
355 strcat(str, "[SB-2] ");
356 if (ha->fw_attributes & BIT_4)
357 strcat(str, "[T10 CRC] ");
358 if (ha->fw_attributes & BIT_5)
359 strcat(str, "[VI] ");
360 if (ha->fw_attributes & BIT_10)
361 strcat(str, "[84XX] ");
362 if (ha->fw_attributes & BIT_13)
363 strcat(str, "[Experimental]");
367 static inline srb_t *
368 qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
369 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
373 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
381 CMD_SP(cmd) = (void *)sp;
382 cmd->scsi_done = done;
388 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
390 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
391 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
392 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
396 if (unlikely(pci_channel_offline(ha->pdev))) {
397 cmd->result = DID_REQUEUE << 16;
398 goto qc_fail_command;
401 rval = fc_remote_port_chkready(rport);
404 goto qc_fail_command;
407 /* Close window on fcport/rport state-transitioning. */
408 if (!*(fc_port_t **)rport->dd_data) {
409 cmd->result = DID_IMM_RETRY << 16;
410 goto qc_fail_command;
413 if (atomic_read(&fcport->state) != FCS_ONLINE) {
414 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
415 atomic_read(&ha->loop_state) == LOOP_DEAD) {
416 cmd->result = DID_NO_CONNECT << 16;
417 goto qc_fail_command;
422 spin_unlock_irq(ha->host->host_lock);
424 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
426 goto qc_host_busy_lock;
428 rval = qla2x00_start_scsi(sp);
429 if (rval != QLA_SUCCESS)
430 goto qc_host_busy_free_sp;
432 spin_lock_irq(ha->host->host_lock);
436 qc_host_busy_free_sp:
437 qla2x00_sp_free_dma(ha, sp);
438 mempool_free(sp, ha->srb_mempool);
441 spin_lock_irq(ha->host->host_lock);
444 return SCSI_MLQUEUE_HOST_BUSY;
454 qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
456 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
457 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
458 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
461 scsi_qla_host_t *pha = to_qla_parent(ha);
463 if (unlikely(pci_channel_offline(ha->pdev))) {
464 cmd->result = DID_REQUEUE << 16;
465 goto qc24_fail_command;
468 rval = fc_remote_port_chkready(rport);
471 goto qc24_fail_command;
474 /* Close window on fcport/rport state-transitioning. */
475 if (!*(fc_port_t **)rport->dd_data) {
476 cmd->result = DID_IMM_RETRY << 16;
477 goto qc24_fail_command;
480 if (atomic_read(&fcport->state) != FCS_ONLINE) {
481 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
482 atomic_read(&pha->loop_state) == LOOP_DEAD) {
483 cmd->result = DID_NO_CONNECT << 16;
484 goto qc24_fail_command;
489 spin_unlock_irq(ha->host->host_lock);
491 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
493 goto qc24_host_busy_lock;
495 rval = qla24xx_start_scsi(sp);
496 if (rval != QLA_SUCCESS)
497 goto qc24_host_busy_free_sp;
499 spin_lock_irq(ha->host->host_lock);
503 qc24_host_busy_free_sp:
504 qla2x00_sp_free_dma(pha, sp);
505 mempool_free(sp, pha->srb_mempool);
508 spin_lock_irq(ha->host->host_lock);
511 return SCSI_MLQUEUE_HOST_BUSY;
521 * qla2x00_eh_wait_on_command
522 * Waits for the command to be returned by the Firmware for some
526 * ha = actual ha whose done queue will contain the command
527 * returned by firmware.
528 * cmd = Scsi Command to wait on.
529 * flag = Abort/Reset(Bus or Device Reset)
536 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
538 #define ABORT_POLLING_PERIOD 1000
539 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
540 unsigned long wait_iter = ABORT_WAIT_ITER;
541 int ret = QLA_SUCCESS;
543 while (CMD_SP(cmd)) {
544 msleep(ABORT_POLLING_PERIOD);
550 ret = QLA_FUNCTION_FAILED;
556 * qla2x00_wait_for_hba_online
557 * Wait till the HBA is online after going through
558 * <= MAX_RETRIES_OF_ISP_ABORT or
559 * finally HBA is disabled ie marked offline
562 * ha - pointer to host adapter structure
565 * Does context switching-Release SPIN_LOCK
566 * (if any) before calling this routine.
569 * Success (Adapter is online) : 0
570 * Failed (Adapter is offline/disabled) : 1
573 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
576 unsigned long wait_online;
577 scsi_qla_host_t *pha = to_qla_parent(ha);
579 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
580 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
581 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
582 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
583 pha->dpc_active) && time_before(jiffies, wait_online)) {
587 if (pha->flags.online)
588 return_status = QLA_SUCCESS;
590 return_status = QLA_FUNCTION_FAILED;
592 return (return_status);
596 * qla2x00_wait_for_loop_ready
597 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
598 * to be in LOOP_READY state.
600 * ha - pointer to host adapter structure
603 * Does context switching-Release SPIN_LOCK
604 * (if any) before calling this routine.
608 * Success (LOOP_READY) : 0
609 * Failed (LOOP_NOT_READY) : 1
612 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
614 int return_status = QLA_SUCCESS;
615 unsigned long loop_timeout ;
616 scsi_qla_host_t *pha = to_qla_parent(ha);
618 /* wait for 5 min at the max for loop to be ready */
619 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
621 while ((!atomic_read(&pha->loop_down_timer) &&
622 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
623 atomic_read(&pha->loop_state) != LOOP_READY) {
624 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
625 return_status = QLA_FUNCTION_FAILED;
629 if (time_after_eq(jiffies, loop_timeout)) {
630 return_status = QLA_FUNCTION_FAILED;
634 return (return_status);
638 qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
640 struct Scsi_Host *shost = cmnd->device->host;
641 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
644 spin_lock_irqsave(shost->host_lock, flags);
645 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
646 spin_unlock_irqrestore(shost->host_lock, flags);
648 spin_lock_irqsave(shost->host_lock, flags);
650 spin_unlock_irqrestore(shost->host_lock, flags);
654 /**************************************************************************
658 * The abort function will abort the specified command.
661 * cmd = Linux SCSI command packet to be aborted.
664 * Either SUCCESS or FAILED.
667 * Only return FAILED if command not returned by firmware.
668 **************************************************************************/
670 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
672 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
675 unsigned int id, lun;
676 unsigned long serial;
679 scsi_qla_host_t *pha = to_qla_parent(ha);
681 qla2x00_block_error_handler(cmd);
688 id = cmd->device->id;
689 lun = cmd->device->lun;
690 serial = cmd->serial_number;
692 /* Check active list for command command. */
693 spin_lock_irqsave(&pha->hardware_lock, flags);
694 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
695 sp = pha->outstanding_cmds[i];
703 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
704 __func__, ha->host_no, sp, serial));
706 spin_unlock_irqrestore(&pha->hardware_lock, flags);
707 if (ha->isp_ops->abort_command(ha, sp)) {
708 DEBUG2(printk("%s(%ld): abort_command "
709 "mbx failed.\n", __func__, ha->host_no));
711 DEBUG3(printk("%s(%ld): abort_command "
712 "mbx success.\n", __func__, ha->host_no));
715 spin_lock_irqsave(&pha->hardware_lock, flags);
719 spin_unlock_irqrestore(&pha->hardware_lock, flags);
721 /* Wait for the command to be returned. */
723 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
724 qla_printk(KERN_ERR, ha,
725 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
726 "%x.\n", ha->host_no, id, lun, serial, ret);
731 qla_printk(KERN_INFO, ha,
732 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
733 ha->host_no, id, lun, wait, serial, ret);
738 enum nexus_wait_type {
745 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
746 unsigned int l, enum nexus_wait_type type)
748 int cnt, match, status;
751 scsi_qla_host_t *pha = to_qla_parent(ha);
753 status = QLA_SUCCESS;
754 spin_lock_irqsave(&pha->hardware_lock, flags);
755 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
757 sp = pha->outstanding_cmds[cnt];
760 if (ha->vp_idx != sp->ha->vp_idx)
768 match = sp->cmd->device->id == t;
771 match = (sp->cmd->device->id == t &&
772 sp->cmd->device->lun == l);
778 spin_unlock_irqrestore(&pha->hardware_lock, flags);
779 status = qla2x00_eh_wait_on_command(ha, sp->cmd);
780 spin_lock_irqsave(&pha->hardware_lock, flags);
782 spin_unlock_irqrestore(&pha->hardware_lock, flags);
787 static char *reset_errors[] = {
790 "Task management failed",
791 "Waiting for command completions",
795 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
796 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
798 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
799 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
802 qla2x00_block_error_handler(cmd);
807 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
808 ha->host_no, cmd->device->id, cmd->device->lun, name);
811 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
812 goto eh_reset_failed;
814 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
815 goto eh_reset_failed;
817 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
818 goto eh_reset_failed;
820 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
821 cmd->device->lun, type) != QLA_SUCCESS)
822 goto eh_reset_failed;
824 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
825 ha->host_no, cmd->device->id, cmd->device->lun, name);
830 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
831 ha->host_no, cmd->device->id, cmd->device->lun, name,
837 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
839 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
841 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
842 ha->isp_ops->lun_reset);
846 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
848 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
850 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
851 ha->isp_ops->target_reset);
854 /**************************************************************************
855 * qla2xxx_eh_bus_reset
858 * The bus reset function will reset the bus and abort any executing
862 * cmd = Linux SCSI command packet of the command that cause the
866 * SUCCESS/FAILURE (defined as macro in scsi.h).
868 **************************************************************************/
870 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
872 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
873 scsi_qla_host_t *pha = to_qla_parent(ha);
874 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
876 unsigned int id, lun;
877 unsigned long serial;
879 qla2x00_block_error_handler(cmd);
881 id = cmd->device->id;
882 lun = cmd->device->lun;
883 serial = cmd->serial_number;
888 qla_printk(KERN_INFO, ha,
889 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
891 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
892 DEBUG2(printk("%s failed:board disabled\n",__func__));
893 goto eh_bus_reset_done;
896 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
897 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
901 goto eh_bus_reset_done;
903 /* Flush outstanding commands. */
904 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
909 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
910 (ret == FAILED) ? "failed" : "succeded");
915 /**************************************************************************
916 * qla2xxx_eh_host_reset
919 * The reset function will reset the Adapter.
922 * cmd = Linux SCSI command packet of the command that cause the
926 * Either SUCCESS or FAILED.
929 **************************************************************************/
931 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
933 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
934 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
936 unsigned int id, lun;
937 unsigned long serial;
938 scsi_qla_host_t *pha = to_qla_parent(ha);
940 qla2x00_block_error_handler(cmd);
942 id = cmd->device->id;
943 lun = cmd->device->lun;
944 serial = cmd->serial_number;
949 qla_printk(KERN_INFO, ha,
950 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
952 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
953 goto eh_host_reset_lock;
956 * Fixme-may be dpc thread is active and processing
957 * loop_resync,so wait a while for it to
958 * be completed and then issue big hammer.Otherwise
959 * it may cause I/O failure as big hammer marks the
960 * devices as lost kicking of the port_down_timer
961 * while dpc is stuck for the mailbox to complete.
963 qla2x00_wait_for_loop_ready(ha);
964 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
965 if (qla2x00_abort_isp(pha)) {
966 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
967 /* failed. schedule dpc to try */
968 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
970 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
971 goto eh_host_reset_lock;
973 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
975 /* Waiting for our command in done_queue to be returned to OS.*/
976 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
981 qla2x00_vp_abort_isp(ha);
984 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
985 (ret == FAILED) ? "failed" : "succeded");
995 * ha = adapter block pointer.
1001 qla2x00_loop_reset(scsi_qla_host_t *ha)
1004 struct fc_port *fcport;
1006 if (ha->flags.enable_lip_full_login) {
1007 ret = qla2x00_full_login_lip(ha);
1008 if (ret != QLA_SUCCESS) {
1009 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1010 "full_login_lip=%d.\n", __func__, ha->host_no,
1013 atomic_set(&ha->loop_state, LOOP_DOWN);
1014 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1015 qla2x00_mark_all_devices_lost(ha, 0);
1016 qla2x00_wait_for_loop_ready(ha);
1019 if (ha->flags.enable_lip_reset) {
1020 ret = qla2x00_lip_reset(ha);
1021 if (ret != QLA_SUCCESS) {
1022 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1023 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1025 qla2x00_wait_for_loop_ready(ha);
1028 if (ha->flags.enable_target_reset) {
1029 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
1030 if (fcport->port_type != FCT_TARGET)
1033 ret = ha->isp_ops->target_reset(fcport, 0);
1034 if (ret != QLA_SUCCESS) {
1035 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1036 "target_reset=%d d_id=%x.\n", __func__,
1037 ha->host_no, ret, fcport->d_id.b24));
1042 /* Issue marker command only when we are going to start the I/O */
1043 ha->marker_needed = 1;
1049 qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1052 unsigned long flags;
1055 spin_lock_irqsave(&ha->hardware_lock, flags);
1056 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1057 sp = ha->outstanding_cmds[cnt];
1059 ha->outstanding_cmds[cnt] = NULL;
1061 sp->cmd->result = res;
1062 sp->cmd->host_scribble = (unsigned char *)NULL;
1063 qla2x00_sp_compl(ha, sp);
1066 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1070 qla2xxx_slave_alloc(struct scsi_device *sdev)
1072 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1074 if (!rport || fc_remote_port_chkready(rport))
1077 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1083 qla2xxx_slave_configure(struct scsi_device *sdev)
1085 scsi_qla_host_t *ha = shost_priv(sdev->host);
1086 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1088 if (sdev->tagged_supported)
1089 scsi_activate_tcq(sdev, ha->max_q_depth);
1091 scsi_deactivate_tcq(sdev, ha->max_q_depth);
1093 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1099 qla2xxx_slave_destroy(struct scsi_device *sdev)
1101 sdev->hostdata = NULL;
1105 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1107 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1108 return sdev->queue_depth;
1112 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1114 if (sdev->tagged_supported) {
1115 scsi_set_tag_type(sdev, tag_type);
1117 scsi_activate_tcq(sdev, sdev->queue_depth);
1119 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1127 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1130 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1131 * supported addressing method.
1134 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1136 /* Assume a 32bit DMA mask. */
1137 ha->flags.enable_64bit_addressing = 0;
1139 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1140 /* Any upper-dword bits set? */
1141 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1142 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1143 /* Ok, a 64bit DMA mask is applicable. */
1144 ha->flags.enable_64bit_addressing = 1;
1145 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1146 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1151 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1152 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
1156 qla2x00_enable_intrs(scsi_qla_host_t *ha)
1158 unsigned long flags = 0;
1159 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1161 spin_lock_irqsave(&ha->hardware_lock, flags);
1162 ha->interrupts_on = 1;
1163 /* enable risc and host interrupts */
1164 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1165 RD_REG_WORD(®->ictrl);
1166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1171 qla2x00_disable_intrs(scsi_qla_host_t *ha)
1173 unsigned long flags = 0;
1174 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1176 spin_lock_irqsave(&ha->hardware_lock, flags);
1177 ha->interrupts_on = 0;
1178 /* disable risc and host interrupts */
1179 WRT_REG_WORD(®->ictrl, 0);
1180 RD_REG_WORD(®->ictrl);
1181 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1185 qla24xx_enable_intrs(scsi_qla_host_t *ha)
1187 unsigned long flags = 0;
1188 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1190 spin_lock_irqsave(&ha->hardware_lock, flags);
1191 ha->interrupts_on = 1;
1192 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1193 RD_REG_DWORD(®->ictrl);
1194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1198 qla24xx_disable_intrs(scsi_qla_host_t *ha)
1200 unsigned long flags = 0;
1201 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1203 spin_lock_irqsave(&ha->hardware_lock, flags);
1204 ha->interrupts_on = 0;
1205 WRT_REG_DWORD(®->ictrl, 0);
1206 RD_REG_DWORD(®->ictrl);
1207 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1210 static struct isp_operations qla2100_isp_ops = {
1211 .pci_config = qla2100_pci_config,
1212 .reset_chip = qla2x00_reset_chip,
1213 .chip_diag = qla2x00_chip_diag,
1214 .config_rings = qla2x00_config_rings,
1215 .reset_adapter = qla2x00_reset_adapter,
1216 .nvram_config = qla2x00_nvram_config,
1217 .update_fw_options = qla2x00_update_fw_options,
1218 .load_risc = qla2x00_load_risc,
1219 .pci_info_str = qla2x00_pci_info_str,
1220 .fw_version_str = qla2x00_fw_version_str,
1221 .intr_handler = qla2100_intr_handler,
1222 .enable_intrs = qla2x00_enable_intrs,
1223 .disable_intrs = qla2x00_disable_intrs,
1224 .abort_command = qla2x00_abort_command,
1225 .target_reset = qla2x00_abort_target,
1226 .lun_reset = qla2x00_lun_reset,
1227 .fabric_login = qla2x00_login_fabric,
1228 .fabric_logout = qla2x00_fabric_logout,
1229 .calc_req_entries = qla2x00_calc_iocbs_32,
1230 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1231 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1232 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1233 .read_nvram = qla2x00_read_nvram_data,
1234 .write_nvram = qla2x00_write_nvram_data,
1235 .fw_dump = qla2100_fw_dump,
1238 .beacon_blink = NULL,
1239 .read_optrom = qla2x00_read_optrom_data,
1240 .write_optrom = qla2x00_write_optrom_data,
1241 .get_flash_version = qla2x00_get_flash_version,
1244 static struct isp_operations qla2300_isp_ops = {
1245 .pci_config = qla2300_pci_config,
1246 .reset_chip = qla2x00_reset_chip,
1247 .chip_diag = qla2x00_chip_diag,
1248 .config_rings = qla2x00_config_rings,
1249 .reset_adapter = qla2x00_reset_adapter,
1250 .nvram_config = qla2x00_nvram_config,
1251 .update_fw_options = qla2x00_update_fw_options,
1252 .load_risc = qla2x00_load_risc,
1253 .pci_info_str = qla2x00_pci_info_str,
1254 .fw_version_str = qla2x00_fw_version_str,
1255 .intr_handler = qla2300_intr_handler,
1256 .enable_intrs = qla2x00_enable_intrs,
1257 .disable_intrs = qla2x00_disable_intrs,
1258 .abort_command = qla2x00_abort_command,
1259 .target_reset = qla2x00_abort_target,
1260 .lun_reset = qla2x00_lun_reset,
1261 .fabric_login = qla2x00_login_fabric,
1262 .fabric_logout = qla2x00_fabric_logout,
1263 .calc_req_entries = qla2x00_calc_iocbs_32,
1264 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1265 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1266 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1267 .read_nvram = qla2x00_read_nvram_data,
1268 .write_nvram = qla2x00_write_nvram_data,
1269 .fw_dump = qla2300_fw_dump,
1270 .beacon_on = qla2x00_beacon_on,
1271 .beacon_off = qla2x00_beacon_off,
1272 .beacon_blink = qla2x00_beacon_blink,
1273 .read_optrom = qla2x00_read_optrom_data,
1274 .write_optrom = qla2x00_write_optrom_data,
1275 .get_flash_version = qla2x00_get_flash_version,
1278 static struct isp_operations qla24xx_isp_ops = {
1279 .pci_config = qla24xx_pci_config,
1280 .reset_chip = qla24xx_reset_chip,
1281 .chip_diag = qla24xx_chip_diag,
1282 .config_rings = qla24xx_config_rings,
1283 .reset_adapter = qla24xx_reset_adapter,
1284 .nvram_config = qla24xx_nvram_config,
1285 .update_fw_options = qla24xx_update_fw_options,
1286 .load_risc = qla24xx_load_risc,
1287 .pci_info_str = qla24xx_pci_info_str,
1288 .fw_version_str = qla24xx_fw_version_str,
1289 .intr_handler = qla24xx_intr_handler,
1290 .enable_intrs = qla24xx_enable_intrs,
1291 .disable_intrs = qla24xx_disable_intrs,
1292 .abort_command = qla24xx_abort_command,
1293 .target_reset = qla24xx_abort_target,
1294 .lun_reset = qla24xx_lun_reset,
1295 .fabric_login = qla24xx_login_fabric,
1296 .fabric_logout = qla24xx_fabric_logout,
1297 .calc_req_entries = NULL,
1298 .build_iocbs = NULL,
1299 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1300 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1301 .read_nvram = qla24xx_read_nvram_data,
1302 .write_nvram = qla24xx_write_nvram_data,
1303 .fw_dump = qla24xx_fw_dump,
1304 .beacon_on = qla24xx_beacon_on,
1305 .beacon_off = qla24xx_beacon_off,
1306 .beacon_blink = qla24xx_beacon_blink,
1307 .read_optrom = qla24xx_read_optrom_data,
1308 .write_optrom = qla24xx_write_optrom_data,
1309 .get_flash_version = qla24xx_get_flash_version,
1312 static struct isp_operations qla25xx_isp_ops = {
1313 .pci_config = qla25xx_pci_config,
1314 .reset_chip = qla24xx_reset_chip,
1315 .chip_diag = qla24xx_chip_diag,
1316 .config_rings = qla24xx_config_rings,
1317 .reset_adapter = qla24xx_reset_adapter,
1318 .nvram_config = qla24xx_nvram_config,
1319 .update_fw_options = qla24xx_update_fw_options,
1320 .load_risc = qla24xx_load_risc,
1321 .pci_info_str = qla24xx_pci_info_str,
1322 .fw_version_str = qla24xx_fw_version_str,
1323 .intr_handler = qla24xx_intr_handler,
1324 .enable_intrs = qla24xx_enable_intrs,
1325 .disable_intrs = qla24xx_disable_intrs,
1326 .abort_command = qla24xx_abort_command,
1327 .target_reset = qla24xx_abort_target,
1328 .lun_reset = qla24xx_lun_reset,
1329 .fabric_login = qla24xx_login_fabric,
1330 .fabric_logout = qla24xx_fabric_logout,
1331 .calc_req_entries = NULL,
1332 .build_iocbs = NULL,
1333 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1334 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1335 .read_nvram = qla25xx_read_nvram_data,
1336 .write_nvram = qla25xx_write_nvram_data,
1337 .fw_dump = qla25xx_fw_dump,
1338 .beacon_on = qla24xx_beacon_on,
1339 .beacon_off = qla24xx_beacon_off,
1340 .beacon_blink = qla24xx_beacon_blink,
1341 .read_optrom = qla25xx_read_optrom_data,
1342 .write_optrom = qla24xx_write_optrom_data,
1343 .get_flash_version = qla24xx_get_flash_version,
1347 qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1349 ha->device_type = DT_EXTENDED_IDS;
1350 switch (ha->pdev->device) {
1351 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1352 ha->device_type |= DT_ISP2100;
1353 ha->device_type &= ~DT_EXTENDED_IDS;
1354 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1356 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1357 ha->device_type |= DT_ISP2200;
1358 ha->device_type &= ~DT_EXTENDED_IDS;
1359 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1361 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1362 ha->device_type |= DT_ISP2300;
1363 ha->device_type |= DT_ZIO_SUPPORTED;
1364 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1366 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1367 ha->device_type |= DT_ISP2312;
1368 ha->device_type |= DT_ZIO_SUPPORTED;
1369 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1371 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1372 ha->device_type |= DT_ISP2322;
1373 ha->device_type |= DT_ZIO_SUPPORTED;
1374 if (ha->pdev->subsystem_vendor == 0x1028 &&
1375 ha->pdev->subsystem_device == 0x0170)
1376 ha->device_type |= DT_OEM_001;
1377 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1379 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1380 ha->device_type |= DT_ISP6312;
1381 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1383 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1384 ha->device_type |= DT_ISP6322;
1385 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1387 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1388 ha->device_type |= DT_ISP2422;
1389 ha->device_type |= DT_ZIO_SUPPORTED;
1390 ha->device_type |= DT_FWI2;
1391 ha->device_type |= DT_IIDMA;
1392 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1394 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1395 ha->device_type |= DT_ISP2432;
1396 ha->device_type |= DT_ZIO_SUPPORTED;
1397 ha->device_type |= DT_FWI2;
1398 ha->device_type |= DT_IIDMA;
1399 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1401 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1402 ha->device_type |= DT_ISP8432;
1403 ha->device_type |= DT_ZIO_SUPPORTED;
1404 ha->device_type |= DT_FWI2;
1405 ha->device_type |= DT_IIDMA;
1406 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1408 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1409 ha->device_type |= DT_ISP5422;
1410 ha->device_type |= DT_FWI2;
1411 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1413 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1414 ha->device_type |= DT_ISP5432;
1415 ha->device_type |= DT_FWI2;
1416 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1418 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1419 ha->device_type |= DT_ISP2532;
1420 ha->device_type |= DT_ZIO_SUPPORTED;
1421 ha->device_type |= DT_FWI2;
1422 ha->device_type |= DT_IIDMA;
1423 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1429 qla2x00_iospace_config(scsi_qla_host_t *ha)
1431 resource_size_t pio;
1433 if (pci_request_selected_regions(ha->pdev, ha->bars,
1434 QLA2XXX_DRIVER_NAME)) {
1435 qla_printk(KERN_WARNING, ha,
1436 "Failed to reserve PIO/MMIO regions (%s)\n",
1437 pci_name(ha->pdev));
1439 goto iospace_error_exit;
1441 if (!(ha->bars & 1))
1444 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1445 pio = pci_resource_start(ha->pdev, 0);
1446 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1447 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1448 qla_printk(KERN_WARNING, ha,
1449 "Invalid PCI I/O region size (%s)...\n",
1450 pci_name(ha->pdev));
1454 qla_printk(KERN_WARNING, ha,
1455 "region #0 not a PIO resource (%s)...\n",
1456 pci_name(ha->pdev));
1459 ha->pio_address = pio;
1462 /* Use MMIO operations for all accesses. */
1463 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1464 qla_printk(KERN_ERR, ha,
1465 "region #1 not an MMIO resource (%s), aborting\n",
1466 pci_name(ha->pdev));
1467 goto iospace_error_exit;
1469 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1470 qla_printk(KERN_ERR, ha,
1471 "Invalid PCI mem region size (%s), aborting\n",
1472 pci_name(ha->pdev));
1473 goto iospace_error_exit;
1476 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1478 qla_printk(KERN_ERR, ha,
1479 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1481 goto iospace_error_exit;
1491 qla2xxx_scan_start(struct Scsi_Host *shost)
1493 scsi_qla_host_t *ha = shost_priv(shost);
1495 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1496 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1497 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1501 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1503 scsi_qla_host_t *ha = shost_priv(shost);
1507 if (time > ha->loop_reset_delay * HZ)
1510 return atomic_read(&ha->loop_state) == LOOP_READY;
1514 * PCI driver interface
1516 static int __devinit
1517 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1520 struct Scsi_Host *host;
1521 scsi_qla_host_t *ha;
1524 struct scsi_host_template *sht;
1525 int bars, mem_only = 0;
1527 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1528 sht = &qla2x00_driver_template;
1529 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1530 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1531 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1532 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1533 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1534 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1535 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1536 sht = &qla24xx_driver_template;
1541 if (pci_enable_device_mem(pdev))
1544 if (pci_enable_device(pdev))
1548 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
1549 if (pci_find_aer_capability(pdev))
1550 if (pci_enable_pcie_error_reporting(pdev))
1552 #else /* taken from 2.6.28 */
1553 /* This may fail but that's ok */
1554 pci_enable_pcie_error_reporting(pdev);
1557 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
1560 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1561 goto probe_disable_device;
1564 /* Clear our data area */
1565 ha = shost_priv(host);
1566 memset(ha, 0, sizeof(scsi_qla_host_t));
1568 ha->enable_class_2 = ql2xenableclass2;
1571 ha->host_no = host->host_no;
1572 snprintf(ha->host_str, HA_HOST_STR_SIZE, "%s_%ld", QLA2XXX_DRIVER_NAME,
1576 ha->mem_only = mem_only;
1577 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1578 mutex_init(&ha->tgt_mutex);
1579 qla_clear_tgt_mode(ha);
1581 spin_lock_init(&ha->hardware_lock);
1583 /* Set ISP-type information. */
1584 qla2x00_set_isp_flags(ha);
1586 /* Configure PCI I/O space */
1587 ret = qla2x00_iospace_config(ha);
1591 qla_printk(KERN_INFO, ha,
1592 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1595 ha->prev_topology = 0;
1596 ha->init_cb_size = sizeof(init_cb_t);
1597 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
1598 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1599 ha->optrom_size = OPTROM_SIZE_2300;
1601 ha->max_q_depth = MAX_Q_DEPTH;
1602 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1603 ha->max_q_depth = ql2xmaxqdepth;
1605 /* Assign ISP specific operations. */
1606 if (IS_QLA2100(ha)) {
1607 host->max_id = MAX_TARGETS_2100;
1608 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1609 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1610 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1611 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1612 host->sg_tablesize = 32;
1613 ha->gid_list_info_size = 4;
1614 ha->isp_ops = &qla2100_isp_ops;
1615 } else if (IS_QLA2200(ha)) {
1616 host->max_id = MAX_TARGETS_2200;
1617 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1618 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1619 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1620 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1621 ha->gid_list_info_size = 4;
1622 ha->isp_ops = &qla2100_isp_ops;
1623 } else if (IS_QLA23XX(ha)) {
1624 host->max_id = MAX_TARGETS_2200;
1625 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1626 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1627 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1628 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1629 ha->gid_list_info_size = 6;
1630 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1631 ha->optrom_size = OPTROM_SIZE_2322;
1632 ha->isp_ops = &qla2300_isp_ops;
1633 } else if (IS_QLA24XX_TYPE(ha)) {
1634 host->max_id = MAX_TARGETS_2200;
1635 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1636 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1637 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1638 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1639 ha->atio_q_length = ATIO_ENTRY_CNT_24XX;
1641 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1642 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1643 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1644 ha->gid_list_info_size = 8;
1645 ha->optrom_size = OPTROM_SIZE_24XX;
1646 ha->isp_ops = &qla24xx_isp_ops;
1647 } else if (IS_QLA25XX(ha)) {
1648 host->max_id = MAX_TARGETS_2200;
1649 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1650 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1651 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1652 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1653 ha->atio_q_length = ATIO_ENTRY_CNT_24XX;
1655 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1656 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1657 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1658 ha->gid_list_info_size = 8;
1659 ha->optrom_size = OPTROM_SIZE_25XX;
1660 ha->isp_ops = &qla25xx_isp_ops;
1661 ha->hw_event_start = PCI_FUNC(pdev->devfn) ?
1662 FA_HW_EVENT1_ADDR: FA_HW_EVENT0_ADDR;
1664 host->can_queue = ha->request_q_length + 128;
1666 /* load the F/W, read paramaters, and init the H/W */
1667 ha->instance = num_hosts;
1669 spin_lock_init(&ha->dpc_lock);
1671 mutex_init(&ha->vport_lock);
1672 init_completion(&ha->mbx_cmd_comp);
1673 complete(&ha->mbx_cmd_comp);
1674 init_completion(&ha->mbx_intr_comp);
1676 INIT_LIST_HEAD(&ha->list);
1677 INIT_LIST_HEAD(&ha->fcports);
1678 INIT_LIST_HEAD(&ha->vp_list);
1679 INIT_LIST_HEAD(&ha->work_list);
1681 set_bit(0, (unsigned long *) ha->vp_idx_map);
1683 qla2x00_config_dma_addressing(ha);
1684 if (qla2x00_mem_alloc(ha)) {
1685 qla_printk(KERN_WARNING, ha,
1686 "[ERROR] Failed to allocate memory for adapter\n");
1692 if (qla2x00_initialize_adapter(ha)) {
1693 qla_printk(KERN_WARNING, ha,
1694 "Failed to initialize adapter\n");
1696 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1697 "Adapter flags %x.\n",
1698 ha->host_no, ha->device_flags));
1705 * Startup the kernel thread for this host adapter
1707 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1708 "%s_dpc", ha->host_str);
1709 if (IS_ERR(ha->dpc_thread)) {
1710 qla_printk(KERN_WARNING, ha,
1711 "Unable to start DPC thread!\n");
1712 ret = PTR_ERR(ha->dpc_thread);
1716 host->this_id = 255;
1717 host->cmd_per_lun = 3;
1718 host->unique_id = ha->instance;
1719 host->max_cmd_len = MAX_CMDSZ;
1720 host->max_channel = MAX_BUSES - 1;
1721 host->max_lun = MAX_LUNS;
1722 host->transportt = qla2xxx_transport_template;
1724 ret = qla2x00_request_irqs(ha);
1728 /* Initialized the timer */
1729 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1731 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1734 pci_set_drvdata(pdev, ha);
1736 ha->flags.init_done = 1;
1737 ha->flags.online = 1;
1741 ret = scsi_add_host(host, &pdev->dev);
1745 scsi_scan_host(host);
1747 qla2x00_alloc_sysfs_attr(ha);
1749 qla2x00_init_host_attr(ha);
1751 qla2x00_dfs_setup(ha);
1753 qla_printk(KERN_INFO, ha, "\n"
1754 " QLogic Fibre Channel HBA Driver: %s\n"
1756 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1757 qla2x00_version_str, ha->model_number,
1758 ha->model_desc ? ha->model_desc: "", pdev->device,
1759 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
1760 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
1761 ha->isp_ops->fw_version_str(ha, fw_str));
1766 qla2x00_free_device(ha);
1768 scsi_host_put(host);
1770 probe_disable_device:
1771 pci_disable_device(pdev);
1778 qla2x00_stop_dpc_thread(scsi_qla_host_t *ha)
1780 struct task_struct *t = NULL;
1782 spin_lock_irq(&ha->dpc_lock);
1783 if (ha->dpc_thread != NULL) {
1786 * qla2xxx_wake_dpc checks for ->dpc_thread
1787 * so we need to zero it out.
1789 ha->dpc_thread = NULL;
1791 spin_unlock_irq(&ha->dpc_lock);
1798 qla2x00_remove_one(struct pci_dev *pdev)
1800 scsi_qla_host_t *ha;
1802 ha = pci_get_drvdata(pdev);
1804 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1806 unsigned long flags;
1807 spin_lock_irqsave(&ha->hardware_lock, flags);
1808 ha->host_shutting_down = 1;
1809 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1811 if (qla_target.tgt_host_action != NULL)
1812 qla_target.tgt_host_action(ha, DISABLE_TARGET_MODE);
1815 /* Necessary to prevent races with it */
1816 qla2x00_stop_dpc_thread(ha);
1818 qla2x00_dfs_remove(ha);
1820 qla84xx_put_chip(ha);
1822 qla2x00_free_sysfs_attr(ha);
1824 fc_remove_host(ha->host);
1826 scsi_remove_host(ha->host);
1828 qla2x00_free_device(ha);
1830 scsi_host_put(ha->host);
1832 pci_disable_device(pdev);
1833 pci_set_drvdata(pdev, NULL);
1837 qla2x00_free_device(scsi_qla_host_t *ha)
1839 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1842 if (ha->timer_active)
1843 qla2x00_stop_timer(ha);
1845 ha->flags.online = 0;
1847 /* Kill the kernel thread for this host */
1848 qla2x00_stop_dpc_thread(ha);
1850 if (ha->flags.fce_enabled)
1851 qla2x00_disable_fce_trace(ha, NULL, NULL);
1854 qla2x00_disable_eft_trace(ha);
1856 /* Stop currently executing firmware. */
1857 qla2x00_try_to_stop_firmware(ha);
1859 /* turn-off interrupts on the card */
1860 if (ha->interrupts_on)
1861 ha->isp_ops->disable_intrs(ha);
1863 qla2x00_mem_free(ha);
1865 qla2x00_free_irqs(ha);
1867 /* release io space registers */
1869 iounmap(ha->iobase);
1870 pci_release_selected_regions(ha->pdev, ha->bars);
1874 qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1877 unsigned long flags;
1878 struct fc_rport *rport;
1883 rport = fcport->rport;
1885 spin_lock_irqsave(&fcport->rport_lock, flags);
1886 fcport->drport = rport;
1887 fcport->rport = NULL;
1888 *(fc_port_t **)rport->dd_data = NULL;
1889 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1890 set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
1892 spin_lock_irqsave(&fcport->rport_lock, flags);
1893 fcport->rport = NULL;
1894 *(fc_port_t **)rport->dd_data = NULL;
1895 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1896 fc_remote_port_delete(rport);
1897 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1898 if (qla_target.tgt_fc_port_deleted)
1899 qla_target.tgt_fc_port_deleted(ha, fcport);
1905 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1907 * Input: ha = adapter block pointer. fcport = port structure pointer.
1913 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1914 int do_login, int defer)
1916 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1917 ha->vp_idx == fcport->vp_idx)
1918 qla2x00_schedule_rport_del(ha, fcport, defer);
1921 * We may need to retry the login, so don't change the state of the
1922 * port but do the retries.
1924 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1925 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1930 if (fcport->login_retry == 0) {
1931 fcport->login_retry = ha->login_retry_count;
1932 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1934 DEBUG(printk("scsi(%ld): Port login retry: "
1935 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1936 "id = 0x%04x retry cnt=%d\n",
1938 fcport->port_name[0],
1939 fcport->port_name[1],
1940 fcport->port_name[2],
1941 fcport->port_name[3],
1942 fcport->port_name[4],
1943 fcport->port_name[5],
1944 fcport->port_name[6],
1945 fcport->port_name[7],
1947 fcport->login_retry));
1952 * qla2x00_mark_all_devices_lost
1953 * Updates fcport state when device goes offline.
1956 * ha = adapter block pointer.
1957 * fcport = port structure pointer.
1965 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
1968 scsi_qla_host_t *pha = to_qla_parent(ha);
1970 list_for_each_entry_rcu(fcport, &pha->fcports, list) {
1971 #ifndef CONFIG_SCSI_QLA2XXX_TARGET
1972 if (ha->vp_idx != 0 && ha->vp_idx != fcport->vp_idx)
1976 * No point in marking the device as lost, if the device is
1979 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1981 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1983 qla2x00_schedule_rport_del(ha, fcport, defer);
1984 else if (ha->vp_idx == fcport->vp_idx)
1985 qla2x00_schedule_rport_del(ha, fcport, defer);
1987 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1991 qla2xxx_wake_dpc(ha);
1996 * Allocates adapter memory.
2003 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2007 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2008 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
2010 if (!ha->request_ring)
2013 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2014 (ha->response_q_length + 1) * sizeof(response_t),
2015 &ha->response_dma, GFP_KERNEL);
2016 if (!ha->response_ring)
2017 goto fail_free_request_ring;
2019 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
2020 if (IS_FWI2_CAPABLE(ha)) {
2021 ha->atio_ring = dma_alloc_coherent(&ha->pdev->dev,
2022 (ha->atio_q_length + 1) * sizeof(atio_t),
2023 &ha->atio_dma, GFP_KERNEL);
2024 if (ha->atio_ring == NULL)
2025 goto fail_free_response_ring;
2029 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2030 &ha->gid_list_dma, GFP_KERNEL);
2032 goto fail_free_atio_ring;
2034 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2035 &ha->init_cb_dma, GFP_KERNEL);
2037 goto fail_free_gid_list;
2039 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
2041 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2042 DMA_POOL_SIZE, 8, 0);
2043 if (!ha->s_dma_pool)
2044 goto fail_free_init_cb;
2046 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2047 if (!ha->srb_mempool)
2048 goto fail_free_s_dma_pool;
2050 /* Get memory for cached NVRAM */
2051 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2053 goto fail_free_srb_mempool;
2055 /* Allocate memory for SNS commands */
2056 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2057 /* Get consistent memory allocated for SNS commands */
2058 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2059 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2061 goto fail_free_nvram;
2063 /* Get consistent memory allocated for MS IOCB */
2064 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2067 goto fail_free_nvram;
2069 /* Get consistent memory allocated for CT SNS commands */
2070 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2071 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2073 goto fail_free_ms_iocb;
2079 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2081 ha->ms_iocb_dma = 0;
2085 fail_free_srb_mempool:
2086 mempool_destroy(ha->srb_mempool);
2087 ha->srb_mempool = NULL;
2088 fail_free_s_dma_pool:
2089 dma_pool_destroy(ha->s_dma_pool);
2090 ha->s_dma_pool = NULL;
2092 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2095 ha->init_cb_dma = 0;
2097 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2099 ha->gid_list = NULL;
2100 ha->gid_list_dma = 0;
2101 fail_free_atio_ring:
2102 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
2103 dma_free_coherent(&ha->pdev->dev, (ha->atio_q_length + 1) *
2104 sizeof(response_t), ha->atio_ring, ha->atio_dma);
2105 ha->atio_ring = NULL;
2107 fail_free_response_ring:
2109 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2110 sizeof(response_t), ha->response_ring, ha->response_dma);
2111 ha->response_ring = NULL;
2112 ha->response_dma = 0;
2113 fail_free_request_ring:
2114 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2115 sizeof(request_t), ha->request_ring, ha->request_dma);
2116 ha->request_ring = NULL;
2117 ha->request_dma = 0;
2124 * Frees all adapter allocated memory.
2127 * ha = adapter block pointer.
2130 qla2x00_mem_free(scsi_qla_host_t *ha)
2132 struct list_head *fcpl, *fcptemp;
2135 if (ha->srb_mempool)
2136 mempool_destroy(ha->srb_mempool);
2139 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2144 dma_free_coherent(&ha->pdev->dev,
2145 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2150 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2151 ha->sns_cmd, ha->sns_cmd_dma);
2154 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2155 ha->ct_sns, ha->ct_sns_dma);
2158 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2161 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2164 dma_pool_destroy(ha->s_dma_pool);
2167 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2168 ha->init_cb, ha->init_cb_dma);
2171 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2174 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
2176 dma_free_coherent(&ha->pdev->dev,
2177 (ha->atio_q_length + 1) * sizeof(atio_t),
2178 ha->atio_ring, ha->atio_dma);
2181 if (ha->response_ring)
2182 dma_free_coherent(&ha->pdev->dev,
2183 (ha->response_q_length + 1) * sizeof(response_t),
2184 ha->response_ring, ha->response_dma);
2186 if (ha->request_ring)
2187 dma_free_coherent(&ha->pdev->dev,
2188 (ha->request_q_length + 1) * sizeof(request_t),
2189 ha->request_ring, ha->request_dma);
2191 ha->srb_mempool = NULL;
2195 ha->sns_cmd_dma = 0;
2199 ha->ms_iocb_dma = 0;
2201 ha->init_cb_dma = 0;
2203 ha->s_dma_pool = NULL;
2205 ha->gid_list = NULL;
2206 ha->gid_list_dma = 0;
2208 ha->response_ring = NULL;
2209 ha->response_dma = 0;
2210 ha->request_ring = NULL;
2211 ha->request_dma = 0;
2212 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
2213 ha->atio_ring = NULL;
2217 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2218 fcport = list_entry(fcpl, fc_port_t, list);
2221 list_del_init(&fcport->list);
2224 INIT_LIST_HEAD(&ha->fcports);
2228 ha->fw_dump_reading = 0;
2230 vfree(ha->optrom_buffer);
2234 static struct qla_work_evt *
2235 qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2238 struct qla_work_evt *e;
2240 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2245 INIT_LIST_HEAD(&e->list);
2247 e->flags = QLA_EVT_FLAG_FREE;
2252 qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
2254 unsigned long flags = 0;
2255 scsi_qla_host_t *pha = to_qla_parent(ha);
2258 spin_lock_irqsave(&pha->hardware_lock, flags);
2259 list_add_tail(&e->list, &ha->work_list);
2260 qla2xxx_wake_dpc(ha);
2262 spin_unlock_irqrestore(&pha->hardware_lock, flags);
2267 qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
2270 struct qla_work_evt *e;
2272 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
2274 return QLA_FUNCTION_FAILED;
2276 e->u.aen.code = code;
2277 e->u.aen.data = data;
2278 return qla2x00_post_work(ha, e, 1);
2282 qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2283 uint16_t d2, uint16_t d3)
2285 struct qla_work_evt *e;
2287 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
2289 return QLA_FUNCTION_FAILED;
2291 e->u.hwe.code = code;
2295 return qla2x00_post_work(ha, e, 1);
2299 qla2x00_do_work(struct scsi_qla_host *ha)
2301 struct qla_work_evt *e;
2302 scsi_qla_host_t *pha = to_qla_parent(ha);
2304 spin_lock_irq(&pha->hardware_lock);
2305 while (!list_empty(&ha->work_list)) {
2306 e = list_entry(ha->work_list.next, struct qla_work_evt, list);
2307 list_del_init(&e->list);
2308 spin_unlock_irq(&pha->hardware_lock);
2312 fc_host_post_event(ha->host, fc_get_event_number(),
2313 e->u.aen.code, e->u.aen.data);
2315 case QLA_EVT_HWE_LOG:
2316 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
2317 e->u.hwe.d2, e->u.hwe.d3);
2320 if (e->flags & QLA_EVT_FLAG_FREE)
2322 spin_lock_irq(&pha->hardware_lock);
2324 spin_unlock_irq(&pha->hardware_lock);
2327 /**************************************************************************
2329 * This kernel thread is a task that is schedule by the interrupt handler
2330 * to perform the background processing for interrupts.
2333 * This task always run in the context of a kernel thread. It
2334 * is kick-off by the driver's detect code and starts up
2335 * up one per adapter. It immediately goes to sleep and waits for
2336 * some fibre event. When either the interrupt handler or
2337 * the timer routine detects a event it will one of the task
2338 * bits then wake us up.
2339 **************************************************************************/
2341 qla2x00_do_dpc(void *data)
2344 scsi_qla_host_t *ha;
2347 uint16_t next_loopid;
2348 struct scsi_qla_host *vha;
2352 ha = (scsi_qla_host_t *)data;
2354 set_user_nice(current, -10);
2356 while (!kthread_should_stop()) {
2357 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2359 set_current_state(TASK_INTERRUPTIBLE);
2361 __set_current_state(TASK_RUNNING);
2363 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2365 /* Initialization not yet finished. Don't do anything yet. */
2366 if (!ha->flags.init_done)
2369 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2373 if (ha->flags.mbox_busy) {
2378 qla2x00_do_work(ha);
2380 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2382 DEBUG(printk("scsi(%ld): dpc: sched "
2383 "qla2x00_abort_isp ha = %p\n",
2385 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2388 if (qla2x00_abort_isp(ha)) {
2389 /* failed. retry later */
2390 set_bit(ISP_ABORT_NEEDED,
2393 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2396 for_each_mapped_vp_idx(ha, i) {
2397 list_for_each_entry(vha, &ha->vp_list,
2399 if (i == vha->vp_idx) {
2400 set_bit(ISP_ABORT_NEEDED,
2407 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2411 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
2412 qla2x00_update_fcports(ha);
2414 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2415 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2417 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2420 qla2x00_rst_aen(ha);
2421 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2424 /* Retry each device up to login retry count */
2425 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2426 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2427 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2429 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2433 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
2435 * If the port is not ONLINE then try to login
2436 * to it if we haven't run out of retries.
2438 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2439 fcport->login_retry) {
2441 if (fcport->flags & FCF_FABRIC_DEVICE) {
2444 ha->isp_ops->fabric_logout(
2445 ha, fcport->loop_id,
2446 fcport->d_id.b.domain,
2447 fcport->d_id.b.area,
2448 fcport->d_id.b.al_pa);
2449 status = qla2x00_fabric_login(
2450 ha, fcport, &next_loopid);
2453 qla2x00_local_device_login(
2456 fcport->login_retry--;
2457 if (status == QLA_SUCCESS) {
2458 fcport->old_loop_id = fcport->loop_id;
2460 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2461 ha->host_no, fcport->loop_id));
2463 qla2x00_update_fcport(ha,
2465 } else if (status == 1) {
2466 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2467 /* retry the login again */
2468 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2470 fcport->login_retry, fcport->loop_id));
2472 fcport->login_retry = 0;
2474 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2475 fcport->loop_id = FC_NO_LOOP_ID;
2477 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2480 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2484 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2486 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2489 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2492 rval = qla2x00_loop_resync(ha);
2494 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2497 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2501 if (!ha->interrupts_on)
2502 ha->isp_ops->enable_intrs(ha);
2504 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
2505 ha->isp_ops->beacon_blink(ha);
2507 qla2x00_do_dpc_all_vps(ha);
2510 } /* End of while(1) */
2512 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2515 * Make sure that nobody tries to wake us up again.
2523 qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2525 unsigned long flags;
2526 spin_lock_irqsave(&ha->dpc_lock, flags);
2528 wake_up_process(ha->dpc_thread);
2529 spin_unlock_irqrestore(&ha->dpc_lock, flags);
2534 * Processes asynchronous reset.
2537 * ha = adapter block pointer.
2540 qla2x00_rst_aen(scsi_qla_host_t *ha)
2542 if (ha->flags.online && !ha->flags.reset_active &&
2543 !atomic_read(&ha->loop_down_timer) &&
2544 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2546 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2549 * Issue marker command only when we are going to start
2552 ha->marker_needed = 1;
2553 } while (!atomic_read(&ha->loop_down_timer) &&
2554 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2559 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2561 struct scsi_cmnd *cmd = sp->cmd;
2563 if (sp->flags & SRB_DMA_VALID) {
2564 scsi_dma_unmap(cmd);
2565 sp->flags &= ~SRB_DMA_VALID;
2571 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2573 struct scsi_cmnd *cmd = sp->cmd;
2575 qla2x00_sp_free_dma(ha, sp);
2577 mempool_free(sp, ha->srb_mempool);
2579 cmd->scsi_done(cmd);
2582 /**************************************************************************
2588 * Context: Interrupt
2589 ***************************************************************************/
2591 qla2x00_timer(scsi_qla_host_t *ha)
2593 unsigned long cpu_flags = 0;
2599 scsi_qla_host_t *pha = to_qla_parent(ha);
2602 * Ports - Port down timer.
2604 * Whenever, a port is in the LOST state we start decrementing its port
2605 * down timer every second until it reaches zero. Once it reaches zero
2606 * the port it marked DEAD.
2609 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
2610 #ifndef CONFIG_SCSI_QLA2XXX_TARGET
2611 if (fcport->port_type != FCT_TARGET)
2614 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2615 if (atomic_read(&fcport->port_down_timer) == 0)
2618 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2619 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2621 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2624 t, atomic_read(&fcport->port_down_timer)));
2627 } /* End of for fcport */
2629 /* Loop down handler. */
2630 if (atomic_read(&ha->loop_down_timer) > 0 &&
2631 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2633 if (atomic_read(&ha->loop_down_timer) ==
2634 ha->loop_down_abort_time) {
2636 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2637 "queues before time expire\n",
2640 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2641 atomic_set(&ha->loop_state, LOOP_DEAD);
2643 /* Schedule an ISP abort to return any tape commands. */
2644 /* NPIV - scan physical port only */
2646 spin_lock_irqsave(&ha->hardware_lock,
2649 index < MAX_OUTSTANDING_COMMANDS;
2653 sp = ha->outstanding_cmds[index];
2657 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2660 set_bit(ISP_ABORT_NEEDED,
2664 spin_unlock_irqrestore(&ha->hardware_lock,
2667 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2671 /* if the loop has been down for 4 minutes, reinit adapter */
2672 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2673 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2674 "restarting queues.\n",
2677 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2680 if (!(ha->device_flags & DFLG_NO_CABLE) &&
2682 DEBUG(printk("scsi(%ld): Loop down - "
2685 qla_printk(KERN_WARNING, ha,
2686 "Loop down - aborting ISP.\n");
2688 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2691 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2693 atomic_read(&ha->loop_down_timer)));
2696 /* Check if beacon LED needs to be blinked */
2697 if (ha->beacon_blink_led == 1) {
2698 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2702 /* Process any deferred work. */
2703 if (!list_empty(&ha->work_list))
2706 /* Schedule the DPC routine if needed */
2707 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2708 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2709 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
2711 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2712 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
2713 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
2714 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
2715 qla2xxx_wake_dpc(pha);
2717 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2720 /* Firmware interface routines. */
2723 #define FW_ISP21XX 0
2724 #define FW_ISP22XX 1
2725 #define FW_ISP2300 2
2726 #define FW_ISP2322 3
2727 #define FW_ISP24XX 4
2728 #define FW_ISP25XX 5
2730 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2731 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2732 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2733 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2734 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2735 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2737 static DEFINE_MUTEX(qla_fw_lock);
2739 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
2740 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2741 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2742 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2743 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2744 { .name = FW_FILE_ISP24XX, },
2745 { .name = FW_FILE_ISP25XX, },
2749 qla2x00_request_firmware(scsi_qla_host_t *ha)
2751 struct fw_blob *blob;
2754 if (IS_QLA2100(ha)) {
2755 blob = &qla_fw_blobs[FW_ISP21XX];
2756 } else if (IS_QLA2200(ha)) {
2757 blob = &qla_fw_blobs[FW_ISP22XX];
2758 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2759 blob = &qla_fw_blobs[FW_ISP2300];
2760 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2761 blob = &qla_fw_blobs[FW_ISP2322];
2762 } else if (IS_QLA24XX_TYPE(ha)) {
2763 blob = &qla_fw_blobs[FW_ISP24XX];
2764 } else if (IS_QLA25XX(ha)) {
2765 blob = &qla_fw_blobs[FW_ISP25XX];
2768 mutex_lock(&qla_fw_lock);
2772 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2773 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2774 "(%s).\n", ha->host_no, blob->name));
2781 mutex_unlock(&qla_fw_lock);
2786 qla2x00_release_firmware(void)
2790 mutex_lock(&qla_fw_lock);
2791 for (idx = 0; idx < FW_BLOBS; idx++)
2792 if (qla_fw_blobs[idx].fw)
2793 release_firmware(qla_fw_blobs[idx].fw);
2794 mutex_unlock(&qla_fw_lock);
2797 static pci_ers_result_t
2798 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2801 case pci_channel_io_normal:
2802 return PCI_ERS_RESULT_CAN_RECOVER;
2803 case pci_channel_io_frozen:
2804 pci_disable_device(pdev);
2805 return PCI_ERS_RESULT_NEED_RESET;
2806 case pci_channel_io_perm_failure:
2807 qla2x00_remove_one(pdev);
2808 return PCI_ERS_RESULT_DISCONNECT;
2810 return PCI_ERS_RESULT_NEED_RESET;
2813 static pci_ers_result_t
2814 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2816 int risc_paused = 0;
2818 unsigned long flags;
2819 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2820 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2821 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2823 spin_lock_irqsave(&ha->hardware_lock, flags);
2824 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2825 stat = RD_REG_DWORD(®->hccr);
2826 if (stat & HCCR_RISC_PAUSE)
2828 } else if (IS_QLA23XX(ha)) {
2829 stat = RD_REG_DWORD(®->u.isp2300.host_status);
2830 if (stat & HSR_RISC_PAUSED)
2832 } else if (IS_FWI2_CAPABLE(ha)) {
2833 stat = RD_REG_DWORD(®24->host_status);
2834 if (stat & HSRX_RISC_PAUSED)
2837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2840 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2841 "Dumping firmware!\n");
2842 ha->isp_ops->fw_dump(ha, 0);
2844 return PCI_ERS_RESULT_NEED_RESET;
2846 return PCI_ERS_RESULT_RECOVERED;
2849 static pci_ers_result_t
2850 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2852 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2853 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2857 rc = pci_enable_device_mem(pdev);
2859 rc = pci_enable_device(pdev);
2862 qla_printk(KERN_WARNING, ha,
2863 "Can't re-enable PCI device after reset.\n");
2867 pci_set_master(pdev);
2869 if (ha->isp_ops->pci_config(ha))
2872 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2873 if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
2874 ret = PCI_ERS_RESULT_RECOVERED;
2875 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2881 qla2xxx_pci_resume(struct pci_dev *pdev)
2883 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2886 ret = qla2x00_wait_for_hba_online(ha);
2887 if (ret != QLA_SUCCESS) {
2888 qla_printk(KERN_ERR, ha,
2889 "the device failed to resume I/O "
2890 "from slot/link_reset");
2892 pci_cleanup_aer_uncorrect_error_status(pdev);
2895 static struct pci_error_handlers qla2xxx_err_handler = {
2896 .error_detected = qla2xxx_pci_error_detected,
2897 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2898 .slot_reset = qla2xxx_pci_slot_reset,
2899 .resume = qla2xxx_pci_resume,
2902 static struct pci_device_id qla2xxx_pci_tbl[] = {
2903 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2904 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2905 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2906 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2907 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2908 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2909 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2910 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2911 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
2912 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
2913 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2914 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
2915 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
2918 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2920 static struct pci_driver qla2xxx_pci_driver = {
2921 .name = QLA2XXX_DRIVER_NAME,
2923 .owner = THIS_MODULE,
2925 .id_table = qla2xxx_pci_tbl,
2926 .probe = qla2x00_probe_one,
2927 .remove = qla2x00_remove_one,
2928 .err_handler = &qla2xxx_err_handler,
2932 * qla2x00_module_init - Module initialization.
2935 qla2x00_module_init(void)
2939 #if defined(QL_DEBUG_LEVEL_1) || \
2940 defined(QL_DEBUG_LEVEL_2) || \
2941 defined(QL_DEBUG_LEVEL_3) || \
2942 defined(QL_DEBUG_LEVEL_4) || \
2943 defined(QL_DEBUG_LEVEL_5) || \
2944 defined(QL_DEBUG_LEVEL_6) || \
2945 defined(QL_DEBUG_LEVEL_7) || \
2946 defined(QL_DEBUG_LEVEL_8) || \
2947 defined(QL_DEBUG_LEVEL_9) || \
2948 defined(QL_DEBUG_LEVEL_10) || \
2949 defined(QL_DEBUG_LEVEL_11) || \
2950 defined(QL_DEBUG_LEVEL_12) || \
2951 defined(QL_DEBUG_LEVEL_13) || \
2952 defined(QL_DEBUG_LEVEL_14) || \
2953 defined(QL_DEBUG_LEVEL_15) || \
2954 defined(QL_DEBUG_LEVEL_16)
2955 ql2xextended_error_logging = 1;
2958 /* Allocate cache for SRBs. */
2959 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
2960 SLAB_HWCACHE_ALIGN, NULL);
2961 if (srb_cachep == NULL) {
2963 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2967 /* Derive version string. */
2968 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2969 if (ql2xextended_error_logging)
2970 strcat(qla2x00_version_str, "-debug");
2972 qla2xxx_transport_template =
2973 fc_attach_transport(&qla2xxx_transport_functions);
2974 if (!qla2xxx_transport_template) {
2975 kmem_cache_destroy(srb_cachep);
2978 qla2xxx_transport_vport_template =
2979 fc_attach_transport(&qla2xxx_transport_vport_functions);
2980 if (!qla2xxx_transport_vport_template) {
2981 kmem_cache_destroy(srb_cachep);
2982 fc_release_transport(qla2xxx_transport_template);
2986 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
2987 qla2x00_version_str);
2988 ret = pci_register_driver(&qla2xxx_pci_driver);
2990 kmem_cache_destroy(srb_cachep);
2991 fc_release_transport(qla2xxx_transport_template);
2992 fc_release_transport(qla2xxx_transport_vport_template);
2998 * qla2x00_module_exit - Module cleanup.
3001 qla2x00_module_exit(void)
3003 pci_unregister_driver(&qla2xxx_pci_driver);
3004 qla2x00_release_firmware();
3005 kmem_cache_destroy(srb_cachep);
3006 fc_release_transport(qla2xxx_transport_template);
3007 fc_release_transport(qla2xxx_transport_vport_template);
3010 module_init(qla2x00_module_init);
3011 module_exit(qla2x00_module_exit);
3013 MODULE_AUTHOR("QLogic Corporation");
3014 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
3015 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver (Target Mode Support, including 24xx+ ISP)");
3017 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3019 MODULE_LICENSE("GPL");
3020 MODULE_VERSION(QLA2XXX_VERSION);
3021 MODULE_FIRMWARE(FW_FILE_ISP21XX);
3022 MODULE_FIRMWARE(FW_FILE_ISP22XX);
3023 MODULE_FIRMWARE(FW_FILE_ISP2300);
3024 MODULE_FIRMWARE(FW_FILE_ISP2322);
3025 MODULE_FIRMWARE(FW_FILE_ISP24XX);
3026 MODULE_FIRMWARE(FW_FILE_ISP25XX);