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>
15 #include <scsi/scsi_tcq.h>
16 #include <scsi/scsicam.h>
17 #include <scsi/scsi_transport.h>
18 #include <scsi/scsi_transport_fc.h>
23 char qla2x00_version_str[40];
26 * SRB allocation cache
28 static struct kmem_cache *srb_cachep;
30 int ql2xlogintimeout = 20;
31 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32 MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
35 int qlport_down_retry;
36 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37 MODULE_PARM_DESC(qlport_down_retry,
38 "Maximum number of command retries to a port that returns "
39 "a PORT-DOWN status.");
41 int ql2xplogiabsentdevice;
42 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43 MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
45 "a Fabric scan. This is needed for several broken switches. "
46 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
48 int ql2xloginretrycount = 0;
49 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50 MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
53 int ql2xallocfwdump = 1;
54 module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55 MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
60 int ql2xextended_error_logging;
61 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
62 MODULE_PARM_DESC(ql2xextended_error_logging,
63 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
66 static void qla2x00_free_device(scsi_qla_host_t *);
68 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
71 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
72 MODULE_PARM_DESC(ql2xfdmienable,
73 "Enables FDMI registratons "
74 "Default is 0 - no FDMI. 1 - perfom FDMI.");
76 #define MAX_Q_DEPTH 32
77 static int ql2xmaxqdepth = MAX_Q_DEPTH;
78 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
79 MODULE_PARM_DESC(ql2xmaxqdepth,
80 "Maximum queue depth to report for target devices.");
82 int ql2xqfullrampup = 120;
83 module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
84 MODULE_PARM_DESC(ql2xqfullrampup,
85 "Number of seconds to wait to begin to ramp-up the queue "
86 "depth for a device after a queue-full condition has been "
87 "detected. Default is 120 seconds.");
89 int ql2xiidmaenable=1;
90 module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
91 MODULE_PARM_DESC(ql2xiidmaenable,
92 "Enables iIDMA settings "
93 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
97 * SCSI host template entry points
99 static int qla2xxx_slave_configure(struct scsi_device * device);
100 static int qla2xxx_slave_alloc(struct scsi_device *);
101 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
102 static void qla2xxx_scan_start(struct Scsi_Host *);
103 static void qla2xxx_slave_destroy(struct scsi_device *);
104 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
105 void (*fn)(struct scsi_cmnd *));
106 static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
107 void (*fn)(struct scsi_cmnd *));
108 static int qla2xxx_eh_abort(struct scsi_cmnd *);
109 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
110 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
111 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
112 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
114 static int qla2x00_change_queue_depth(struct scsi_device *, int);
115 static int qla2x00_change_queue_type(struct scsi_device *, int);
117 static struct scsi_host_template qla2x00_driver_template = {
118 .module = THIS_MODULE,
119 .name = QLA2XXX_DRIVER_NAME,
120 .queuecommand = qla2x00_queuecommand,
122 .eh_abort_handler = qla2xxx_eh_abort,
123 .eh_device_reset_handler = qla2xxx_eh_device_reset,
124 .eh_target_reset_handler = qla2xxx_eh_target_reset,
125 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
126 .eh_host_reset_handler = qla2xxx_eh_host_reset,
128 .slave_configure = qla2xxx_slave_configure,
130 .slave_alloc = qla2xxx_slave_alloc,
131 .slave_destroy = qla2xxx_slave_destroy,
132 .scan_finished = qla2xxx_scan_finished,
133 .scan_start = qla2xxx_scan_start,
134 .change_queue_depth = qla2x00_change_queue_depth,
135 .change_queue_type = qla2x00_change_queue_type,
138 .use_clustering = ENABLE_CLUSTERING,
139 .sg_tablesize = SG_ALL,
142 * The RISC allows for each command to transfer (2^32-1) bytes of data,
143 * which equates to 0x800000 sectors.
145 .max_sectors = 0xFFFF,
146 .shost_attrs = qla2x00_host_attrs,
149 struct scsi_host_template qla24xx_driver_template = {
150 .module = THIS_MODULE,
151 .name = QLA2XXX_DRIVER_NAME,
152 .queuecommand = qla24xx_queuecommand,
154 .eh_abort_handler = qla2xxx_eh_abort,
155 .eh_device_reset_handler = qla2xxx_eh_device_reset,
156 .eh_target_reset_handler = qla2xxx_eh_target_reset,
157 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
158 .eh_host_reset_handler = qla2xxx_eh_host_reset,
160 .slave_configure = qla2xxx_slave_configure,
162 .slave_alloc = qla2xxx_slave_alloc,
163 .slave_destroy = qla2xxx_slave_destroy,
164 .scan_finished = qla2xxx_scan_finished,
165 .scan_start = qla2xxx_scan_start,
166 .change_queue_depth = qla2x00_change_queue_depth,
167 .change_queue_type = qla2x00_change_queue_type,
170 .use_clustering = ENABLE_CLUSTERING,
171 .sg_tablesize = SG_ALL,
173 .max_sectors = 0xFFFF,
174 .shost_attrs = qla2x00_host_attrs,
177 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
178 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
180 /* TODO Convert to inlines
186 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
188 init_timer(&ha->timer);
189 ha->timer.expires = jiffies + interval * HZ;
190 ha->timer.data = (unsigned long)ha;
191 ha->timer.function = (void (*)(unsigned long))func;
192 add_timer(&ha->timer);
193 ha->timer_active = 1;
197 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
199 mod_timer(&ha->timer, jiffies + interval * HZ);
202 static __inline__ void
203 qla2x00_stop_timer(scsi_qla_host_t *ha)
205 del_timer_sync(&ha->timer);
206 ha->timer_active = 0;
209 static int qla2x00_do_dpc(void *data);
211 static void qla2x00_rst_aen(scsi_qla_host_t *);
213 static int qla2x00_mem_alloc(scsi_qla_host_t *);
214 static void qla2x00_mem_free(scsi_qla_host_t *ha);
215 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
217 /* -------------------------------------------------------------------------- */
220 qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
222 static char *pci_bus_modes[] = {
223 "33", "66", "100", "133",
228 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
231 strcat(str, pci_bus_modes[pci_bus]);
233 pci_bus = (ha->pci_attr & BIT_8) >> 8;
235 strcat(str, pci_bus_modes[pci_bus]);
237 strcat(str, " MHz)");
243 qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
245 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
249 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
252 uint16_t pcie_lstat, lspeed, lwidth;
255 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
256 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
257 lwidth = (pcie_lstat &
258 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
260 strcpy(str, "PCIe (");
262 strcat(str, "2.5GT/s ");
263 else if (lspeed == 2)
264 strcat(str, "5.0GT/s ");
266 strcat(str, "<unknown> ");
267 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
274 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
275 if (pci_bus == 0 || pci_bus == 8) {
277 strcat(str, pci_bus_modes[pci_bus >> 3]);
281 strcat(str, "Mode 2");
283 strcat(str, "Mode 1");
285 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
287 strcat(str, " MHz)");
293 qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
297 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
298 ha->fw_minor_version,
299 ha->fw_subminor_version);
301 if (ha->fw_attributes & BIT_9) {
306 switch (ha->fw_attributes & 0xFF) {
320 sprintf(un_str, "(%x)", ha->fw_attributes);
324 if (ha->fw_attributes & 0x100)
331 qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
333 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
334 ha->fw_minor_version,
335 ha->fw_subminor_version);
337 if (ha->fw_attributes & BIT_0)
338 strcat(str, "[Class 2] ");
339 if (ha->fw_attributes & BIT_1)
340 strcat(str, "[IP] ");
341 if (ha->fw_attributes & BIT_2)
342 strcat(str, "[Multi-ID] ");
343 if (ha->fw_attributes & BIT_3)
344 strcat(str, "[SB-2] ");
345 if (ha->fw_attributes & BIT_4)
346 strcat(str, "[T10 CRC] ");
347 if (ha->fw_attributes & BIT_5)
348 strcat(str, "[VI] ");
349 if (ha->fw_attributes & BIT_10)
350 strcat(str, "[84XX] ");
351 if (ha->fw_attributes & BIT_13)
352 strcat(str, "[Experimental]");
356 static inline srb_t *
357 qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
358 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
362 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
370 CMD_SP(cmd) = (void *)sp;
371 cmd->scsi_done = done;
377 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
379 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
380 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
381 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
385 if (unlikely(pci_channel_offline(ha->pdev))) {
386 cmd->result = DID_REQUEUE << 16;
387 goto qc_fail_command;
390 rval = fc_remote_port_chkready(rport);
393 goto qc_fail_command;
396 /* Close window on fcport/rport state-transitioning. */
400 if (atomic_read(&fcport->state) != FCS_ONLINE) {
401 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
402 atomic_read(&ha->loop_state) == LOOP_DEAD) {
403 cmd->result = DID_NO_CONNECT << 16;
404 goto qc_fail_command;
409 spin_unlock_irq(ha->host->host_lock);
411 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
413 goto qc_host_busy_lock;
415 rval = qla2x00_start_scsi(sp);
416 if (rval != QLA_SUCCESS)
417 goto qc_host_busy_free_sp;
419 spin_lock_irq(ha->host->host_lock);
423 qc_host_busy_free_sp:
424 qla2x00_sp_free_dma(ha, sp);
425 mempool_free(sp, ha->srb_mempool);
428 spin_lock_irq(ha->host->host_lock);
429 return SCSI_MLQUEUE_HOST_BUSY;
432 return SCSI_MLQUEUE_TARGET_BUSY;
442 qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
444 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
445 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
446 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
449 scsi_qla_host_t *pha = to_qla_parent(ha);
451 if (unlikely(pci_channel_offline(pha->pdev))) {
452 cmd->result = DID_REQUEUE << 16;
453 goto qc24_fail_command;
456 rval = fc_remote_port_chkready(rport);
459 goto qc24_fail_command;
462 /* Close window on fcport/rport state-transitioning. */
464 goto qc24_target_busy;
466 if (atomic_read(&fcport->state) != FCS_ONLINE) {
467 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
468 atomic_read(&pha->loop_state) == LOOP_DEAD) {
469 cmd->result = DID_NO_CONNECT << 16;
470 goto qc24_fail_command;
472 goto qc24_target_busy;
475 spin_unlock_irq(ha->host->host_lock);
477 sp = qla2x00_get_new_sp(pha, fcport, cmd, done);
479 goto qc24_host_busy_lock;
481 rval = qla24xx_start_scsi(sp);
482 if (rval != QLA_SUCCESS)
483 goto qc24_host_busy_free_sp;
485 spin_lock_irq(ha->host->host_lock);
489 qc24_host_busy_free_sp:
490 qla2x00_sp_free_dma(pha, sp);
491 mempool_free(sp, pha->srb_mempool);
494 spin_lock_irq(ha->host->host_lock);
495 return SCSI_MLQUEUE_HOST_BUSY;
498 return SCSI_MLQUEUE_TARGET_BUSY;
508 * qla2x00_eh_wait_on_command
509 * Waits for the command to be returned by the Firmware for some
513 * ha = actual ha whose done queue will contain the command
514 * returned by firmware.
515 * cmd = Scsi Command to wait on.
516 * flag = Abort/Reset(Bus or Device Reset)
523 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
525 #define ABORT_POLLING_PERIOD 1000
526 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
527 unsigned long wait_iter = ABORT_WAIT_ITER;
528 int ret = QLA_SUCCESS;
530 while (CMD_SP(cmd)) {
531 msleep(ABORT_POLLING_PERIOD);
537 ret = QLA_FUNCTION_FAILED;
543 * qla2x00_wait_for_hba_online
544 * Wait till the HBA is online after going through
545 * <= MAX_RETRIES_OF_ISP_ABORT or
546 * finally HBA is disabled ie marked offline
549 * ha - pointer to host adapter structure
552 * Does context switching-Release SPIN_LOCK
553 * (if any) before calling this routine.
556 * Success (Adapter is online) : 0
557 * Failed (Adapter is offline/disabled) : 1
560 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
563 unsigned long wait_online;
564 scsi_qla_host_t *pha = to_qla_parent(ha);
566 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
567 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) ||
568 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) ||
569 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) ||
570 pha->dpc_active) && time_before(jiffies, wait_online)) {
574 if (pha->flags.online)
575 return_status = QLA_SUCCESS;
577 return_status = QLA_FUNCTION_FAILED;
579 return (return_status);
583 * qla2x00_wait_for_loop_ready
584 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
585 * to be in LOOP_READY state.
587 * ha - pointer to host adapter structure
590 * Does context switching-Release SPIN_LOCK
591 * (if any) before calling this routine.
595 * Success (LOOP_READY) : 0
596 * Failed (LOOP_NOT_READY) : 1
599 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
601 int return_status = QLA_SUCCESS;
602 unsigned long loop_timeout ;
603 scsi_qla_host_t *pha = to_qla_parent(ha);
605 /* wait for 5 min at the max for loop to be ready */
606 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
608 while ((!atomic_read(&pha->loop_down_timer) &&
609 atomic_read(&pha->loop_state) == LOOP_DOWN) ||
610 atomic_read(&pha->loop_state) != LOOP_READY) {
611 if (atomic_read(&pha->loop_state) == LOOP_DEAD) {
612 return_status = QLA_FUNCTION_FAILED;
616 if (time_after_eq(jiffies, loop_timeout)) {
617 return_status = QLA_FUNCTION_FAILED;
621 return (return_status);
625 qla2x00_abort_fcport_cmds(fc_port_t *fcport)
630 scsi_qla_host_t *ha = fcport->ha;
631 scsi_qla_host_t *pha = to_qla_parent(ha);
633 spin_lock_irqsave(&pha->hardware_lock, flags);
634 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
635 sp = pha->outstanding_cmds[cnt];
638 if (sp->fcport != fcport)
641 spin_unlock_irqrestore(&pha->hardware_lock, flags);
642 if (ha->isp_ops->abort_command(ha, sp)) {
643 DEBUG2(qla_printk(KERN_WARNING, ha,
644 "Abort failed -- %lx\n", sp->cmd->serial_number));
646 if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
648 DEBUG2(qla_printk(KERN_WARNING, ha,
649 "Abort failed while waiting -- %lx\n",
650 sp->cmd->serial_number));
653 spin_lock_irqsave(&pha->hardware_lock, flags);
655 spin_unlock_irqrestore(&pha->hardware_lock, flags);
659 qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
661 struct Scsi_Host *shost = cmnd->device->host;
662 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
665 spin_lock_irqsave(shost->host_lock, flags);
666 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
667 spin_unlock_irqrestore(shost->host_lock, flags);
669 spin_lock_irqsave(shost->host_lock, flags);
671 spin_unlock_irqrestore(shost->host_lock, flags);
675 /**************************************************************************
679 * The abort function will abort the specified command.
682 * cmd = Linux SCSI command packet to be aborted.
685 * Either SUCCESS or FAILED.
688 * Only return FAILED if command not returned by firmware.
689 **************************************************************************/
691 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
693 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
696 unsigned int id, lun;
697 unsigned long serial;
700 scsi_qla_host_t *pha = to_qla_parent(ha);
702 qla2x00_block_error_handler(cmd);
709 id = cmd->device->id;
710 lun = cmd->device->lun;
711 serial = cmd->serial_number;
713 /* Check active list for command command. */
714 spin_lock_irqsave(&pha->hardware_lock, flags);
715 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
716 sp = pha->outstanding_cmds[i];
724 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n",
725 __func__, ha->host_no, sp, serial));
727 spin_unlock_irqrestore(&pha->hardware_lock, flags);
728 if (ha->isp_ops->abort_command(ha, sp)) {
729 DEBUG2(printk("%s(%ld): abort_command "
730 "mbx failed.\n", __func__, ha->host_no));
732 DEBUG3(printk("%s(%ld): abort_command "
733 "mbx success.\n", __func__, ha->host_no));
736 spin_lock_irqsave(&pha->hardware_lock, flags);
740 spin_unlock_irqrestore(&pha->hardware_lock, flags);
742 /* Wait for the command to be returned. */
744 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
745 qla_printk(KERN_ERR, ha,
746 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
747 "%x.\n", ha->host_no, id, lun, serial, ret);
752 qla_printk(KERN_INFO, ha,
753 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
754 ha->host_no, id, lun, wait, serial, ret);
759 enum nexus_wait_type {
766 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
767 unsigned int l, enum nexus_wait_type type)
769 int cnt, match, status;
772 scsi_qla_host_t *pha = to_qla_parent(ha);
774 status = QLA_SUCCESS;
775 spin_lock_irqsave(&pha->hardware_lock, flags);
776 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS;
778 sp = pha->outstanding_cmds[cnt];
782 if (ha->vp_idx != sp->fcport->ha->vp_idx)
790 match = sp->cmd->device->id == t;
793 match = (sp->cmd->device->id == t &&
794 sp->cmd->device->lun == l);
800 spin_unlock_irqrestore(&pha->hardware_lock, flags);
801 status = qla2x00_eh_wait_on_command(ha, sp->cmd);
802 spin_lock_irqsave(&pha->hardware_lock, flags);
804 spin_unlock_irqrestore(&pha->hardware_lock, flags);
809 static char *reset_errors[] = {
812 "Task management failed",
813 "Waiting for command completions",
817 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
818 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
820 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
821 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
824 qla2x00_block_error_handler(cmd);
829 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
830 ha->host_no, cmd->device->id, cmd->device->lun, name);
833 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
834 goto eh_reset_failed;
836 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS)
837 goto eh_reset_failed;
839 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
840 goto eh_reset_failed;
842 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id,
843 cmd->device->lun, type) != QLA_SUCCESS)
844 goto eh_reset_failed;
846 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
847 ha->host_no, cmd->device->id, cmd->device->lun, name);
852 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n",
853 ha->host_no, cmd->device->id, cmd->device->lun, name,
859 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
861 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
863 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
864 ha->isp_ops->lun_reset);
868 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
870 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
872 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
873 ha->isp_ops->target_reset);
876 /**************************************************************************
877 * qla2xxx_eh_bus_reset
880 * The bus reset function will reset the bus and abort any executing
884 * cmd = Linux SCSI command packet of the command that cause the
888 * SUCCESS/FAILURE (defined as macro in scsi.h).
890 **************************************************************************/
892 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
894 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
895 scsi_qla_host_t *pha = to_qla_parent(ha);
896 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
898 unsigned int id, lun;
899 unsigned long serial;
901 qla2x00_block_error_handler(cmd);
903 id = cmd->device->id;
904 lun = cmd->device->lun;
905 serial = cmd->serial_number;
910 qla_printk(KERN_INFO, ha,
911 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
913 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
914 DEBUG2(printk("%s failed:board disabled\n",__func__));
915 goto eh_bus_reset_done;
918 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
919 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
923 goto eh_bus_reset_done;
925 /* Flush outstanding commands. */
926 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) !=
931 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
932 (ret == FAILED) ? "failed" : "succeded");
937 /**************************************************************************
938 * qla2xxx_eh_host_reset
941 * The reset function will reset the Adapter.
944 * cmd = Linux SCSI command packet of the command that cause the
948 * Either SUCCESS or FAILED.
951 **************************************************************************/
953 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
955 scsi_qla_host_t *ha = shost_priv(cmd->device->host);
956 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
958 unsigned int id, lun;
959 unsigned long serial;
960 scsi_qla_host_t *pha = to_qla_parent(ha);
962 qla2x00_block_error_handler(cmd);
964 id = cmd->device->id;
965 lun = cmd->device->lun;
966 serial = cmd->serial_number;
971 qla_printk(KERN_INFO, ha,
972 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
974 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
975 goto eh_host_reset_lock;
978 * Fixme-may be dpc thread is active and processing
979 * loop_resync,so wait a while for it to
980 * be completed and then issue big hammer.Otherwise
981 * it may cause I/O failure as big hammer marks the
982 * devices as lost kicking of the port_down_timer
983 * while dpc is stuck for the mailbox to complete.
985 qla2x00_wait_for_loop_ready(ha);
986 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
987 if (qla2x00_abort_isp(pha)) {
988 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
989 /* failed. schedule dpc to try */
990 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
992 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
993 goto eh_host_reset_lock;
995 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
997 /* Waiting for our command in done_queue to be returned to OS.*/
998 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) ==
1003 qla2x00_vp_abort_isp(ha);
1006 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1007 (ret == FAILED) ? "failed" : "succeded");
1013 * qla2x00_loop_reset
1017 * ha = adapter block pointer.
1023 qla2x00_loop_reset(scsi_qla_host_t *ha)
1026 struct fc_port *fcport;
1028 if (ha->flags.enable_lip_full_login) {
1029 ret = qla2x00_full_login_lip(ha);
1030 if (ret != QLA_SUCCESS) {
1031 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1032 "full_login_lip=%d.\n", __func__, ha->host_no,
1035 atomic_set(&ha->loop_state, LOOP_DOWN);
1036 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1037 qla2x00_mark_all_devices_lost(ha, 0);
1038 qla2x00_wait_for_loop_ready(ha);
1041 if (ha->flags.enable_lip_reset) {
1042 ret = qla2x00_lip_reset(ha);
1043 if (ret != QLA_SUCCESS) {
1044 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1045 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1047 qla2x00_wait_for_loop_ready(ha);
1050 if (ha->flags.enable_target_reset) {
1051 list_for_each_entry(fcport, &ha->fcports, list) {
1052 if (fcport->port_type != FCT_TARGET)
1055 ret = ha->isp_ops->target_reset(fcport, 0);
1056 if (ret != QLA_SUCCESS) {
1057 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1058 "target_reset=%d d_id=%x.\n", __func__,
1059 ha->host_no, ret, fcport->d_id.b24));
1064 /* Issue marker command only when we are going to start the I/O */
1065 ha->marker_needed = 1;
1071 qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
1074 unsigned long flags;
1077 spin_lock_irqsave(&ha->hardware_lock, flags);
1078 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1079 sp = ha->outstanding_cmds[cnt];
1081 ha->outstanding_cmds[cnt] = NULL;
1082 sp->cmd->result = res;
1083 qla2x00_sp_compl(ha, sp);
1086 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1090 qla2xxx_slave_alloc(struct scsi_device *sdev)
1092 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1094 if (!rport || fc_remote_port_chkready(rport))
1097 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1103 qla2xxx_slave_configure(struct scsi_device *sdev)
1105 scsi_qla_host_t *ha = shost_priv(sdev->host);
1106 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1108 if (sdev->tagged_supported)
1109 scsi_activate_tcq(sdev, ha->max_q_depth);
1111 scsi_deactivate_tcq(sdev, ha->max_q_depth);
1113 rport->dev_loss_tmo = ha->port_down_retry_count;
1119 qla2xxx_slave_destroy(struct scsi_device *sdev)
1121 sdev->hostdata = NULL;
1125 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1127 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1128 return sdev->queue_depth;
1132 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1134 if (sdev->tagged_supported) {
1135 scsi_set_tag_type(sdev, tag_type);
1137 scsi_activate_tcq(sdev, sdev->queue_depth);
1139 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1147 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1150 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1151 * supported addressing method.
1154 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1156 /* Assume a 32bit DMA mask. */
1157 ha->flags.enable_64bit_addressing = 0;
1159 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1160 /* Any upper-dword bits set? */
1161 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1162 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1163 /* Ok, a 64bit DMA mask is applicable. */
1164 ha->flags.enable_64bit_addressing = 1;
1165 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1166 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1171 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1172 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
1176 qla2x00_enable_intrs(scsi_qla_host_t *ha)
1178 unsigned long flags = 0;
1179 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1181 spin_lock_irqsave(&ha->hardware_lock, flags);
1182 ha->interrupts_on = 1;
1183 /* enable risc and host interrupts */
1184 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1185 RD_REG_WORD(®->ictrl);
1186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1191 qla2x00_disable_intrs(scsi_qla_host_t *ha)
1193 unsigned long flags = 0;
1194 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1196 spin_lock_irqsave(&ha->hardware_lock, flags);
1197 ha->interrupts_on = 0;
1198 /* disable risc and host interrupts */
1199 WRT_REG_WORD(®->ictrl, 0);
1200 RD_REG_WORD(®->ictrl);
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1205 qla24xx_enable_intrs(scsi_qla_host_t *ha)
1207 unsigned long flags = 0;
1208 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1210 spin_lock_irqsave(&ha->hardware_lock, flags);
1211 ha->interrupts_on = 1;
1212 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1213 RD_REG_DWORD(®->ictrl);
1214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1218 qla24xx_disable_intrs(scsi_qla_host_t *ha)
1220 unsigned long flags = 0;
1221 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1223 spin_lock_irqsave(&ha->hardware_lock, flags);
1224 ha->interrupts_on = 0;
1225 WRT_REG_DWORD(®->ictrl, 0);
1226 RD_REG_DWORD(®->ictrl);
1227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1230 static struct isp_operations qla2100_isp_ops = {
1231 .pci_config = qla2100_pci_config,
1232 .reset_chip = qla2x00_reset_chip,
1233 .chip_diag = qla2x00_chip_diag,
1234 .config_rings = qla2x00_config_rings,
1235 .reset_adapter = qla2x00_reset_adapter,
1236 .nvram_config = qla2x00_nvram_config,
1237 .update_fw_options = qla2x00_update_fw_options,
1238 .load_risc = qla2x00_load_risc,
1239 .pci_info_str = qla2x00_pci_info_str,
1240 .fw_version_str = qla2x00_fw_version_str,
1241 .intr_handler = qla2100_intr_handler,
1242 .enable_intrs = qla2x00_enable_intrs,
1243 .disable_intrs = qla2x00_disable_intrs,
1244 .abort_command = qla2x00_abort_command,
1245 .target_reset = qla2x00_abort_target,
1246 .lun_reset = qla2x00_lun_reset,
1247 .fabric_login = qla2x00_login_fabric,
1248 .fabric_logout = qla2x00_fabric_logout,
1249 .calc_req_entries = qla2x00_calc_iocbs_32,
1250 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1251 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1252 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1253 .read_nvram = qla2x00_read_nvram_data,
1254 .write_nvram = qla2x00_write_nvram_data,
1255 .fw_dump = qla2100_fw_dump,
1258 .beacon_blink = NULL,
1259 .read_optrom = qla2x00_read_optrom_data,
1260 .write_optrom = qla2x00_write_optrom_data,
1261 .get_flash_version = qla2x00_get_flash_version,
1264 static struct isp_operations qla2300_isp_ops = {
1265 .pci_config = qla2300_pci_config,
1266 .reset_chip = qla2x00_reset_chip,
1267 .chip_diag = qla2x00_chip_diag,
1268 .config_rings = qla2x00_config_rings,
1269 .reset_adapter = qla2x00_reset_adapter,
1270 .nvram_config = qla2x00_nvram_config,
1271 .update_fw_options = qla2x00_update_fw_options,
1272 .load_risc = qla2x00_load_risc,
1273 .pci_info_str = qla2x00_pci_info_str,
1274 .fw_version_str = qla2x00_fw_version_str,
1275 .intr_handler = qla2300_intr_handler,
1276 .enable_intrs = qla2x00_enable_intrs,
1277 .disable_intrs = qla2x00_disable_intrs,
1278 .abort_command = qla2x00_abort_command,
1279 .target_reset = qla2x00_abort_target,
1280 .lun_reset = qla2x00_lun_reset,
1281 .fabric_login = qla2x00_login_fabric,
1282 .fabric_logout = qla2x00_fabric_logout,
1283 .calc_req_entries = qla2x00_calc_iocbs_32,
1284 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1285 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1286 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1287 .read_nvram = qla2x00_read_nvram_data,
1288 .write_nvram = qla2x00_write_nvram_data,
1289 .fw_dump = qla2300_fw_dump,
1290 .beacon_on = qla2x00_beacon_on,
1291 .beacon_off = qla2x00_beacon_off,
1292 .beacon_blink = qla2x00_beacon_blink,
1293 .read_optrom = qla2x00_read_optrom_data,
1294 .write_optrom = qla2x00_write_optrom_data,
1295 .get_flash_version = qla2x00_get_flash_version,
1298 static struct isp_operations qla24xx_isp_ops = {
1299 .pci_config = qla24xx_pci_config,
1300 .reset_chip = qla24xx_reset_chip,
1301 .chip_diag = qla24xx_chip_diag,
1302 .config_rings = qla24xx_config_rings,
1303 .reset_adapter = qla24xx_reset_adapter,
1304 .nvram_config = qla24xx_nvram_config,
1305 .update_fw_options = qla24xx_update_fw_options,
1306 .load_risc = qla24xx_load_risc,
1307 .pci_info_str = qla24xx_pci_info_str,
1308 .fw_version_str = qla24xx_fw_version_str,
1309 .intr_handler = qla24xx_intr_handler,
1310 .enable_intrs = qla24xx_enable_intrs,
1311 .disable_intrs = qla24xx_disable_intrs,
1312 .abort_command = qla24xx_abort_command,
1313 .target_reset = qla24xx_abort_target,
1314 .lun_reset = qla24xx_lun_reset,
1315 .fabric_login = qla24xx_login_fabric,
1316 .fabric_logout = qla24xx_fabric_logout,
1317 .calc_req_entries = NULL,
1318 .build_iocbs = NULL,
1319 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1320 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1321 .read_nvram = qla24xx_read_nvram_data,
1322 .write_nvram = qla24xx_write_nvram_data,
1323 .fw_dump = qla24xx_fw_dump,
1324 .beacon_on = qla24xx_beacon_on,
1325 .beacon_off = qla24xx_beacon_off,
1326 .beacon_blink = qla24xx_beacon_blink,
1327 .read_optrom = qla24xx_read_optrom_data,
1328 .write_optrom = qla24xx_write_optrom_data,
1329 .get_flash_version = qla24xx_get_flash_version,
1332 static struct isp_operations qla25xx_isp_ops = {
1333 .pci_config = qla25xx_pci_config,
1334 .reset_chip = qla24xx_reset_chip,
1335 .chip_diag = qla24xx_chip_diag,
1336 .config_rings = qla24xx_config_rings,
1337 .reset_adapter = qla24xx_reset_adapter,
1338 .nvram_config = qla24xx_nvram_config,
1339 .update_fw_options = qla24xx_update_fw_options,
1340 .load_risc = qla24xx_load_risc,
1341 .pci_info_str = qla24xx_pci_info_str,
1342 .fw_version_str = qla24xx_fw_version_str,
1343 .intr_handler = qla24xx_intr_handler,
1344 .enable_intrs = qla24xx_enable_intrs,
1345 .disable_intrs = qla24xx_disable_intrs,
1346 .abort_command = qla24xx_abort_command,
1347 .target_reset = qla24xx_abort_target,
1348 .lun_reset = qla24xx_lun_reset,
1349 .fabric_login = qla24xx_login_fabric,
1350 .fabric_logout = qla24xx_fabric_logout,
1351 .calc_req_entries = NULL,
1352 .build_iocbs = NULL,
1353 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1354 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1355 .read_nvram = qla25xx_read_nvram_data,
1356 .write_nvram = qla25xx_write_nvram_data,
1357 .fw_dump = qla25xx_fw_dump,
1358 .beacon_on = qla24xx_beacon_on,
1359 .beacon_off = qla24xx_beacon_off,
1360 .beacon_blink = qla24xx_beacon_blink,
1361 .read_optrom = qla25xx_read_optrom_data,
1362 .write_optrom = qla24xx_write_optrom_data,
1363 .get_flash_version = qla24xx_get_flash_version,
1367 qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1369 ha->device_type = DT_EXTENDED_IDS;
1370 switch (ha->pdev->device) {
1371 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1372 ha->device_type |= DT_ISP2100;
1373 ha->device_type &= ~DT_EXTENDED_IDS;
1374 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1376 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1377 ha->device_type |= DT_ISP2200;
1378 ha->device_type &= ~DT_EXTENDED_IDS;
1379 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1381 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1382 ha->device_type |= DT_ISP2300;
1383 ha->device_type |= DT_ZIO_SUPPORTED;
1384 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1386 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1387 ha->device_type |= DT_ISP2312;
1388 ha->device_type |= DT_ZIO_SUPPORTED;
1389 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1391 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1392 ha->device_type |= DT_ISP2322;
1393 ha->device_type |= DT_ZIO_SUPPORTED;
1394 if (ha->pdev->subsystem_vendor == 0x1028 &&
1395 ha->pdev->subsystem_device == 0x0170)
1396 ha->device_type |= DT_OEM_001;
1397 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1399 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1400 ha->device_type |= DT_ISP6312;
1401 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1403 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1404 ha->device_type |= DT_ISP6322;
1405 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1407 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1408 ha->device_type |= DT_ISP2422;
1409 ha->device_type |= DT_ZIO_SUPPORTED;
1410 ha->device_type |= DT_FWI2;
1411 ha->device_type |= DT_IIDMA;
1412 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1414 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1415 ha->device_type |= DT_ISP2432;
1416 ha->device_type |= DT_ZIO_SUPPORTED;
1417 ha->device_type |= DT_FWI2;
1418 ha->device_type |= DT_IIDMA;
1419 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1421 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1422 ha->device_type |= DT_ISP8432;
1423 ha->device_type |= DT_ZIO_SUPPORTED;
1424 ha->device_type |= DT_FWI2;
1425 ha->device_type |= DT_IIDMA;
1426 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1428 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1429 ha->device_type |= DT_ISP5422;
1430 ha->device_type |= DT_FWI2;
1431 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1433 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1434 ha->device_type |= DT_ISP5432;
1435 ha->device_type |= DT_FWI2;
1436 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1438 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1439 ha->device_type |= DT_ISP2532;
1440 ha->device_type |= DT_ZIO_SUPPORTED;
1441 ha->device_type |= DT_FWI2;
1442 ha->device_type |= DT_IIDMA;
1443 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1449 qla2x00_iospace_config(scsi_qla_host_t *ha)
1451 resource_size_t pio;
1453 if (pci_request_selected_regions(ha->pdev, ha->bars,
1454 QLA2XXX_DRIVER_NAME)) {
1455 qla_printk(KERN_WARNING, ha,
1456 "Failed to reserve PIO/MMIO regions (%s)\n",
1457 pci_name(ha->pdev));
1459 goto iospace_error_exit;
1461 if (!(ha->bars & 1))
1464 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1465 pio = pci_resource_start(ha->pdev, 0);
1466 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1467 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1468 qla_printk(KERN_WARNING, ha,
1469 "Invalid PCI I/O region size (%s)...\n",
1470 pci_name(ha->pdev));
1474 qla_printk(KERN_WARNING, ha,
1475 "region #0 not a PIO resource (%s)...\n",
1476 pci_name(ha->pdev));
1479 ha->pio_address = pio;
1482 /* Use MMIO operations for all accesses. */
1483 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1484 qla_printk(KERN_ERR, ha,
1485 "region #1 not an MMIO resource (%s), aborting\n",
1486 pci_name(ha->pdev));
1487 goto iospace_error_exit;
1489 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1490 qla_printk(KERN_ERR, ha,
1491 "Invalid PCI mem region size (%s), aborting\n",
1492 pci_name(ha->pdev));
1493 goto iospace_error_exit;
1496 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1498 qla_printk(KERN_ERR, ha,
1499 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1501 goto iospace_error_exit;
1511 qla2xxx_scan_start(struct Scsi_Host *shost)
1513 scsi_qla_host_t *ha = shost_priv(shost);
1515 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
1516 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1517 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1518 set_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags);
1522 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1524 scsi_qla_host_t *ha = shost_priv(shost);
1528 if (time > ha->loop_reset_delay * HZ)
1531 return atomic_read(&ha->loop_state) == LOOP_READY;
1535 * PCI driver interface
1537 static int __devinit
1538 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1541 struct Scsi_Host *host;
1542 scsi_qla_host_t *ha;
1545 struct scsi_host_template *sht;
1546 int bars, mem_only = 0;
1548 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1549 sht = &qla2x00_driver_template;
1550 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1551 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1552 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
1553 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1554 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
1555 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532) {
1556 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1557 sht = &qla24xx_driver_template;
1562 if (pci_enable_device_mem(pdev))
1565 if (pci_enable_device(pdev))
1569 /* This may fail but that's ok */
1570 pci_enable_pcie_error_reporting(pdev);
1572 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
1575 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1576 goto probe_disable_device;
1579 /* Clear our data area */
1580 ha = shost_priv(host);
1581 memset(ha, 0, sizeof(scsi_qla_host_t));
1585 ha->host_no = host->host_no;
1586 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
1589 ha->mem_only = mem_only;
1590 spin_lock_init(&ha->hardware_lock);
1592 /* Set ISP-type information. */
1593 qla2x00_set_isp_flags(ha);
1595 /* Configure PCI I/O space */
1596 ret = qla2x00_iospace_config(ha);
1600 qla_printk(KERN_INFO, ha,
1601 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1604 ha->prev_topology = 0;
1605 ha->init_cb_size = sizeof(init_cb_t);
1606 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
1607 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1608 ha->optrom_size = OPTROM_SIZE_2300;
1610 ha->max_q_depth = MAX_Q_DEPTH;
1611 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1612 ha->max_q_depth = ql2xmaxqdepth;
1614 /* Assign ISP specific operations. */
1615 if (IS_QLA2100(ha)) {
1616 host->max_id = MAX_TARGETS_2100;
1617 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1618 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1619 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1620 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1621 host->sg_tablesize = 32;
1622 ha->gid_list_info_size = 4;
1623 ha->isp_ops = &qla2100_isp_ops;
1624 } else if (IS_QLA2200(ha)) {
1625 host->max_id = MAX_TARGETS_2200;
1626 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1627 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1628 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1629 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1630 ha->gid_list_info_size = 4;
1631 ha->isp_ops = &qla2100_isp_ops;
1632 } else if (IS_QLA23XX(ha)) {
1633 host->max_id = MAX_TARGETS_2200;
1634 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1635 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1636 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1637 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1638 ha->gid_list_info_size = 6;
1639 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1640 ha->optrom_size = OPTROM_SIZE_2322;
1641 ha->isp_ops = &qla2300_isp_ops;
1642 } else if (IS_QLA24XX_TYPE(ha)) {
1643 host->max_id = MAX_TARGETS_2200;
1644 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1645 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1646 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1647 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1648 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1649 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1650 ha->gid_list_info_size = 8;
1651 ha->optrom_size = OPTROM_SIZE_24XX;
1652 ha->isp_ops = &qla24xx_isp_ops;
1653 } else if (IS_QLA25XX(ha)) {
1654 host->max_id = MAX_TARGETS_2200;
1655 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1656 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1657 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1658 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1659 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1660 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1661 ha->gid_list_info_size = 8;
1662 ha->optrom_size = OPTROM_SIZE_25XX;
1663 ha->isp_ops = &qla25xx_isp_ops;
1665 host->can_queue = ha->request_q_length + 128;
1667 mutex_init(&ha->vport_lock);
1668 init_completion(&ha->mbx_cmd_comp);
1669 complete(&ha->mbx_cmd_comp);
1670 init_completion(&ha->mbx_intr_comp);
1672 INIT_LIST_HEAD(&ha->list);
1673 INIT_LIST_HEAD(&ha->fcports);
1674 INIT_LIST_HEAD(&ha->vp_list);
1675 INIT_LIST_HEAD(&ha->work_list);
1677 set_bit(0, (unsigned long *) ha->vp_idx_map);
1679 qla2x00_config_dma_addressing(ha);
1680 if (qla2x00_mem_alloc(ha)) {
1681 qla_printk(KERN_WARNING, ha,
1682 "[ERROR] Failed to allocate memory for adapter\n");
1688 if (qla2x00_initialize_adapter(ha)) {
1689 qla_printk(KERN_WARNING, ha,
1690 "Failed to initialize adapter\n");
1692 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1693 "Adapter flags %x.\n",
1694 ha->host_no, ha->device_flags));
1701 * Startup the kernel thread for this host adapter
1703 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1704 "%s_dpc", ha->host_str);
1705 if (IS_ERR(ha->dpc_thread)) {
1706 qla_printk(KERN_WARNING, ha,
1707 "Unable to start DPC thread!\n");
1708 ret = PTR_ERR(ha->dpc_thread);
1712 host->this_id = 255;
1713 host->cmd_per_lun = 3;
1714 host->unique_id = host->host_no;
1715 host->max_cmd_len = MAX_CMDSZ;
1716 host->max_channel = MAX_BUSES - 1;
1717 host->max_lun = MAX_LUNS;
1718 host->transportt = qla2xxx_transport_template;
1720 ret = qla2x00_request_irqs(ha);
1724 /* Initialized the timer */
1725 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1727 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1730 pci_set_drvdata(pdev, ha);
1732 ha->flags.init_done = 1;
1733 ha->flags.online = 1;
1735 ret = scsi_add_host(host, &pdev->dev);
1739 ha->isp_ops->enable_intrs(ha);
1741 scsi_scan_host(host);
1743 qla2x00_alloc_sysfs_attr(ha);
1745 qla2x00_init_host_attr(ha);
1747 qla2x00_dfs_setup(ha);
1749 qla_printk(KERN_INFO, ha, "\n"
1750 " QLogic Fibre Channel HBA Driver: %s\n"
1752 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1753 qla2x00_version_str, ha->model_number,
1754 ha->model_desc ? ha->model_desc: "", pdev->device,
1755 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev),
1756 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
1757 ha->isp_ops->fw_version_str(ha, fw_str));
1762 qla2x00_free_device(ha);
1764 scsi_host_put(host);
1766 probe_disable_device:
1767 pci_disable_device(pdev);
1774 qla2x00_remove_one(struct pci_dev *pdev)
1776 scsi_qla_host_t *ha, *vha, *temp;
1778 ha = pci_get_drvdata(pdev);
1780 list_for_each_entry_safe(vha, temp, &ha->vp_list, vp_list)
1781 fc_vport_terminate(vha->fc_vport);
1783 set_bit(UNLOADING, &ha->dpc_flags);
1785 qla2x00_dfs_remove(ha);
1787 qla84xx_put_chip(ha);
1789 qla2x00_free_sysfs_attr(ha);
1791 fc_remove_host(ha->host);
1793 scsi_remove_host(ha->host);
1795 qla2x00_free_device(ha);
1797 scsi_host_put(ha->host);
1799 pci_disable_device(pdev);
1800 pci_set_drvdata(pdev, NULL);
1804 qla2x00_free_device(scsi_qla_host_t *ha)
1806 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
1809 if (ha->timer_active)
1810 qla2x00_stop_timer(ha);
1812 ha->flags.online = 0;
1814 /* Kill the kernel thread for this host */
1815 if (ha->dpc_thread) {
1816 struct task_struct *t = ha->dpc_thread;
1819 * qla2xxx_wake_dpc checks for ->dpc_thread
1820 * so we need to zero it out.
1822 ha->dpc_thread = NULL;
1826 if (ha->flags.fce_enabled)
1827 qla2x00_disable_fce_trace(ha, NULL, NULL);
1830 qla2x00_disable_eft_trace(ha);
1832 /* Stop currently executing firmware. */
1833 qla2x00_try_to_stop_firmware(ha);
1835 /* turn-off interrupts on the card */
1836 if (ha->interrupts_on)
1837 ha->isp_ops->disable_intrs(ha);
1839 qla2x00_mem_free(ha);
1841 qla2x00_free_irqs(ha);
1843 /* release io space registers */
1845 iounmap(ha->iobase);
1846 pci_release_selected_regions(ha->pdev, ha->bars);
1850 qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1853 struct fc_rport *rport;
1854 scsi_qla_host_t *pha = to_qla_parent(ha);
1859 rport = fcport->rport;
1861 spin_lock_irq(ha->host->host_lock);
1862 fcport->drport = rport;
1863 spin_unlock_irq(ha->host->host_lock);
1864 set_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags);
1865 qla2xxx_wake_dpc(pha);
1867 fc_remote_port_delete(rport);
1871 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1873 * Input: ha = adapter block pointer. fcport = port structure pointer.
1879 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1880 int do_login, int defer)
1882 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1883 ha->vp_idx == fcport->vp_idx)
1884 qla2x00_schedule_rport_del(ha, fcport, defer);
1887 * We may need to retry the login, so don't change the state of the
1888 * port but do the retries.
1890 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1891 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1896 if (fcport->login_retry == 0) {
1897 fcport->login_retry = ha->login_retry_count;
1898 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1900 DEBUG(printk("scsi(%ld): Port login retry: "
1901 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1902 "id = 0x%04x retry cnt=%d\n",
1904 fcport->port_name[0],
1905 fcport->port_name[1],
1906 fcport->port_name[2],
1907 fcport->port_name[3],
1908 fcport->port_name[4],
1909 fcport->port_name[5],
1910 fcport->port_name[6],
1911 fcport->port_name[7],
1913 fcport->login_retry));
1918 * qla2x00_mark_all_devices_lost
1919 * Updates fcport state when device goes offline.
1922 * ha = adapter block pointer.
1923 * fcport = port structure pointer.
1931 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
1934 scsi_qla_host_t *pha = to_qla_parent(ha);
1936 list_for_each_entry(fcport, &pha->fcports, list) {
1937 if (ha->vp_idx != fcport->vp_idx)
1940 * No point in marking the device as lost, if the device is
1943 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1945 if (atomic_read(&fcport->state) == FCS_ONLINE)
1946 qla2x00_schedule_rport_del(ha, fcport, defer);
1947 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1953 * Allocates adapter memory.
1960 qla2x00_mem_alloc(scsi_qla_host_t *ha)
1964 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1965 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
1967 if (!ha->request_ring)
1970 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1971 (ha->response_q_length + 1) * sizeof(response_t),
1972 &ha->response_dma, GFP_KERNEL);
1973 if (!ha->response_ring)
1974 goto fail_free_request_ring;
1976 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1977 &ha->gid_list_dma, GFP_KERNEL);
1979 goto fail_free_response_ring;
1981 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
1982 &ha->init_cb_dma, GFP_KERNEL);
1984 goto fail_free_gid_list;
1986 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
1988 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1989 DMA_POOL_SIZE, 8, 0);
1990 if (!ha->s_dma_pool)
1991 goto fail_free_init_cb;
1993 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
1994 if (!ha->srb_mempool)
1995 goto fail_free_s_dma_pool;
1997 /* Get memory for cached NVRAM */
1998 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2000 goto fail_free_srb_mempool;
2002 /* Allocate memory for SNS commands */
2003 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2004 /* Get consistent memory allocated for SNS commands */
2005 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2006 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2008 goto fail_free_nvram;
2010 /* Get consistent memory allocated for MS IOCB */
2011 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2014 goto fail_free_nvram;
2016 /* Get consistent memory allocated for CT SNS commands */
2017 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2018 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2020 goto fail_free_ms_iocb;
2026 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2028 ha->ms_iocb_dma = 0;
2032 fail_free_srb_mempool:
2033 mempool_destroy(ha->srb_mempool);
2034 ha->srb_mempool = NULL;
2035 fail_free_s_dma_pool:
2036 dma_pool_destroy(ha->s_dma_pool);
2037 ha->s_dma_pool = NULL;
2039 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2042 ha->init_cb_dma = 0;
2044 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2046 ha->gid_list = NULL;
2047 ha->gid_list_dma = 0;
2048 fail_free_response_ring:
2049 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
2050 sizeof(response_t), ha->response_ring, ha->response_dma);
2051 ha->response_ring = NULL;
2052 ha->response_dma = 0;
2053 fail_free_request_ring:
2054 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2055 sizeof(request_t), ha->request_ring, ha->request_dma);
2056 ha->request_ring = NULL;
2057 ha->request_dma = 0;
2064 * Frees all adapter allocated memory.
2067 * ha = adapter block pointer.
2070 qla2x00_mem_free(scsi_qla_host_t *ha)
2072 struct list_head *fcpl, *fcptemp;
2075 if (ha->srb_mempool)
2076 mempool_destroy(ha->srb_mempool);
2079 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2084 dma_free_coherent(&ha->pdev->dev,
2085 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2090 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2091 ha->sns_cmd, ha->sns_cmd_dma);
2094 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2095 ha->ct_sns, ha->ct_sns_dma);
2098 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2101 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2104 dma_pool_destroy(ha->s_dma_pool);
2107 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2108 ha->init_cb, ha->init_cb_dma);
2111 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2114 if (ha->response_ring)
2115 dma_free_coherent(&ha->pdev->dev,
2116 (ha->response_q_length + 1) * sizeof(response_t),
2117 ha->response_ring, ha->response_dma);
2119 if (ha->request_ring)
2120 dma_free_coherent(&ha->pdev->dev,
2121 (ha->request_q_length + 1) * sizeof(request_t),
2122 ha->request_ring, ha->request_dma);
2124 ha->srb_mempool = NULL;
2128 ha->sns_cmd_dma = 0;
2132 ha->ms_iocb_dma = 0;
2134 ha->init_cb_dma = 0;
2136 ha->s_dma_pool = NULL;
2138 ha->gid_list = NULL;
2139 ha->gid_list_dma = 0;
2141 ha->response_ring = NULL;
2142 ha->response_dma = 0;
2143 ha->request_ring = NULL;
2144 ha->request_dma = 0;
2146 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2147 fcport = list_entry(fcpl, fc_port_t, list);
2150 list_del_init(&fcport->list);
2153 INIT_LIST_HEAD(&ha->fcports);
2157 ha->fw_dump_reading = 0;
2159 vfree(ha->optrom_buffer);
2163 static struct qla_work_evt *
2164 qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2167 struct qla_work_evt *e;
2169 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2174 INIT_LIST_HEAD(&e->list);
2176 e->flags = QLA_EVT_FLAG_FREE;
2181 qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked)
2183 unsigned long uninitialized_var(flags);
2184 scsi_qla_host_t *pha = to_qla_parent(ha);
2187 spin_lock_irqsave(&pha->hardware_lock, flags);
2188 list_add_tail(&e->list, &ha->work_list);
2189 qla2xxx_wake_dpc(ha);
2191 spin_unlock_irqrestore(&pha->hardware_lock, flags);
2196 qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code,
2199 struct qla_work_evt *e;
2201 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1);
2203 return QLA_FUNCTION_FAILED;
2205 e->u.aen.code = code;
2206 e->u.aen.data = data;
2207 return qla2x00_post_work(ha, e, 1);
2211 qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2212 uint16_t d2, uint16_t d3)
2214 struct qla_work_evt *e;
2216 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1);
2218 return QLA_FUNCTION_FAILED;
2220 e->u.hwe.code = code;
2224 return qla2x00_post_work(ha, e, 1);
2228 qla2x00_do_work(struct scsi_qla_host *ha)
2230 struct qla_work_evt *e;
2231 scsi_qla_host_t *pha = to_qla_parent(ha);
2233 spin_lock_irq(&pha->hardware_lock);
2234 while (!list_empty(&ha->work_list)) {
2235 e = list_entry(ha->work_list.next, struct qla_work_evt, list);
2236 list_del_init(&e->list);
2237 spin_unlock_irq(&pha->hardware_lock);
2241 fc_host_post_event(ha->host, fc_get_event_number(),
2242 e->u.aen.code, e->u.aen.data);
2244 case QLA_EVT_HWE_LOG:
2245 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1,
2246 e->u.hwe.d2, e->u.hwe.d3);
2249 if (e->flags & QLA_EVT_FLAG_FREE)
2251 spin_lock_irq(&pha->hardware_lock);
2253 spin_unlock_irq(&pha->hardware_lock);
2256 /**************************************************************************
2258 * This kernel thread is a task that is schedule by the interrupt handler
2259 * to perform the background processing for interrupts.
2262 * This task always run in the context of a kernel thread. It
2263 * is kick-off by the driver's detect code and starts up
2264 * up one per adapter. It immediately goes to sleep and waits for
2265 * some fibre event. When either the interrupt handler or
2266 * the timer routine detects a event it will one of the task
2267 * bits then wake us up.
2268 **************************************************************************/
2270 qla2x00_do_dpc(void *data)
2273 scsi_qla_host_t *ha;
2276 uint16_t next_loopid;
2277 struct scsi_qla_host *vha;
2281 ha = (scsi_qla_host_t *)data;
2283 set_user_nice(current, -20);
2285 while (!kthread_should_stop()) {
2286 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2288 set_current_state(TASK_INTERRUPTIBLE);
2290 __set_current_state(TASK_RUNNING);
2292 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2294 /* Initialization not yet finished. Don't do anything yet. */
2295 if (!ha->flags.init_done)
2298 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2302 if (ha->flags.mbox_busy) {
2307 qla2x00_do_work(ha);
2309 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2311 DEBUG(printk("scsi(%ld): dpc: sched "
2312 "qla2x00_abort_isp ha = %p\n",
2314 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2317 if (qla2x00_abort_isp(ha)) {
2318 /* failed. retry later */
2319 set_bit(ISP_ABORT_NEEDED,
2322 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2325 for_each_mapped_vp_idx(ha, i) {
2326 list_for_each_entry(vha, &ha->vp_list,
2328 if (i == vha->vp_idx) {
2329 set_bit(ISP_ABORT_NEEDED,
2336 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2340 if (test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags)) {
2341 qla2x00_update_fcports(ha);
2342 clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
2345 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2346 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2348 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2351 qla2x00_rst_aen(ha);
2352 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2355 /* Retry each device up to login retry count */
2356 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2357 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2358 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2360 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2364 list_for_each_entry(fcport, &ha->fcports, list) {
2366 * If the port is not ONLINE then try to login
2367 * to it if we haven't run out of retries.
2369 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2370 fcport->login_retry) {
2372 if (fcport->flags & FCF_FABRIC_DEVICE) {
2375 ha->isp_ops->fabric_logout(
2376 ha, fcport->loop_id,
2377 fcport->d_id.b.domain,
2378 fcport->d_id.b.area,
2379 fcport->d_id.b.al_pa);
2380 status = qla2x00_fabric_login(
2381 ha, fcport, &next_loopid);
2384 qla2x00_local_device_login(
2387 fcport->login_retry--;
2388 if (status == QLA_SUCCESS) {
2389 fcport->old_loop_id = fcport->loop_id;
2391 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2392 ha->host_no, fcport->loop_id));
2394 qla2x00_update_fcport(ha,
2396 } else if (status == 1) {
2397 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2398 /* retry the login again */
2399 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2401 fcport->login_retry, fcport->loop_id));
2403 fcport->login_retry = 0;
2405 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2406 fcport->loop_id = FC_NO_LOOP_ID;
2408 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2411 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2415 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2417 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2420 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2423 rval = qla2x00_loop_resync(ha);
2425 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2428 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2432 if (test_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags) &&
2433 atomic_read(&ha->loop_state) == LOOP_READY) {
2434 clear_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags);
2435 qla2xxx_flash_npiv_conf(ha);
2438 if (!ha->interrupts_on)
2439 ha->isp_ops->enable_intrs(ha);
2441 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
2442 ha->isp_ops->beacon_blink(ha);
2444 qla2x00_do_dpc_all_vps(ha);
2447 } /* End of while(1) */
2449 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2452 * Make sure that nobody tries to wake us up again.
2460 qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2462 struct task_struct *t = ha->dpc_thread;
2464 if (!test_bit(UNLOADING, &ha->dpc_flags) && t)
2470 * Processes asynchronous reset.
2473 * ha = adapter block pointer.
2476 qla2x00_rst_aen(scsi_qla_host_t *ha)
2478 if (ha->flags.online && !ha->flags.reset_active &&
2479 !atomic_read(&ha->loop_down_timer) &&
2480 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2482 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2485 * Issue marker command only when we are going to start
2488 ha->marker_needed = 1;
2489 } while (!atomic_read(&ha->loop_down_timer) &&
2490 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2495 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2497 struct scsi_cmnd *cmd = sp->cmd;
2499 if (sp->flags & SRB_DMA_VALID) {
2500 scsi_dma_unmap(cmd);
2501 sp->flags &= ~SRB_DMA_VALID;
2507 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2509 struct scsi_cmnd *cmd = sp->cmd;
2511 qla2x00_sp_free_dma(ha, sp);
2513 mempool_free(sp, ha->srb_mempool);
2515 cmd->scsi_done(cmd);
2518 /**************************************************************************
2524 * Context: Interrupt
2525 ***************************************************************************/
2527 qla2x00_timer(scsi_qla_host_t *ha)
2529 unsigned long cpu_flags = 0;
2535 scsi_qla_host_t *pha = to_qla_parent(ha);
2538 * Ports - Port down timer.
2540 * Whenever, a port is in the LOST state we start decrementing its port
2541 * down timer every second until it reaches zero. Once it reaches zero
2542 * the port it marked DEAD.
2545 list_for_each_entry(fcport, &ha->fcports, list) {
2546 if (fcport->port_type != FCT_TARGET)
2549 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2551 if (atomic_read(&fcport->port_down_timer) == 0)
2554 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2555 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2557 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2560 t, atomic_read(&fcport->port_down_timer)));
2563 } /* End of for fcport */
2566 /* Loop down handler. */
2567 if (atomic_read(&ha->loop_down_timer) > 0 &&
2568 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2570 if (atomic_read(&ha->loop_down_timer) ==
2571 ha->loop_down_abort_time) {
2573 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2574 "queues before time expire\n",
2577 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2578 atomic_set(&ha->loop_state, LOOP_DEAD);
2580 /* Schedule an ISP abort to return any tape commands. */
2581 /* NPIV - scan physical port only */
2583 spin_lock_irqsave(&ha->hardware_lock,
2586 index < MAX_OUTSTANDING_COMMANDS;
2590 sp = ha->outstanding_cmds[index];
2594 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2597 set_bit(ISP_ABORT_NEEDED,
2601 spin_unlock_irqrestore(&ha->hardware_lock,
2604 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2608 /* if the loop has been down for 4 minutes, reinit adapter */
2609 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2610 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2611 "restarting queues.\n",
2614 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2617 if (!(ha->device_flags & DFLG_NO_CABLE) &&
2619 DEBUG(printk("scsi(%ld): Loop down - "
2622 qla_printk(KERN_WARNING, ha,
2623 "Loop down - aborting ISP.\n");
2625 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2628 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2630 atomic_read(&ha->loop_down_timer)));
2633 /* Check if beacon LED needs to be blinked */
2634 if (ha->beacon_blink_led == 1) {
2635 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2639 /* Process any deferred work. */
2640 if (!list_empty(&ha->work_list))
2643 /* Schedule the DPC routine if needed */
2644 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2645 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2646 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
2648 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2649 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
2650 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) ||
2651 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
2652 qla2xxx_wake_dpc(pha);
2654 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2657 /* Firmware interface routines. */
2660 #define FW_ISP21XX 0
2661 #define FW_ISP22XX 1
2662 #define FW_ISP2300 2
2663 #define FW_ISP2322 3
2664 #define FW_ISP24XX 4
2665 #define FW_ISP25XX 5
2667 #define FW_FILE_ISP21XX "ql2100_fw.bin"
2668 #define FW_FILE_ISP22XX "ql2200_fw.bin"
2669 #define FW_FILE_ISP2300 "ql2300_fw.bin"
2670 #define FW_FILE_ISP2322 "ql2322_fw.bin"
2671 #define FW_FILE_ISP24XX "ql2400_fw.bin"
2672 #define FW_FILE_ISP25XX "ql2500_fw.bin"
2674 static DEFINE_MUTEX(qla_fw_lock);
2676 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
2677 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2678 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2679 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2680 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2681 { .name = FW_FILE_ISP24XX, },
2682 { .name = FW_FILE_ISP25XX, },
2686 qla2x00_request_firmware(scsi_qla_host_t *ha)
2688 struct fw_blob *blob;
2691 if (IS_QLA2100(ha)) {
2692 blob = &qla_fw_blobs[FW_ISP21XX];
2693 } else if (IS_QLA2200(ha)) {
2694 blob = &qla_fw_blobs[FW_ISP22XX];
2695 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2696 blob = &qla_fw_blobs[FW_ISP2300];
2697 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2698 blob = &qla_fw_blobs[FW_ISP2322];
2699 } else if (IS_QLA24XX_TYPE(ha)) {
2700 blob = &qla_fw_blobs[FW_ISP24XX];
2701 } else if (IS_QLA25XX(ha)) {
2702 blob = &qla_fw_blobs[FW_ISP25XX];
2705 mutex_lock(&qla_fw_lock);
2709 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2710 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2711 "(%s).\n", ha->host_no, blob->name));
2718 mutex_unlock(&qla_fw_lock);
2723 qla2x00_release_firmware(void)
2727 mutex_lock(&qla_fw_lock);
2728 for (idx = 0; idx < FW_BLOBS; idx++)
2729 if (qla_fw_blobs[idx].fw)
2730 release_firmware(qla_fw_blobs[idx].fw);
2731 mutex_unlock(&qla_fw_lock);
2734 static pci_ers_result_t
2735 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2738 case pci_channel_io_normal:
2739 return PCI_ERS_RESULT_CAN_RECOVER;
2740 case pci_channel_io_frozen:
2741 pci_disable_device(pdev);
2742 return PCI_ERS_RESULT_NEED_RESET;
2743 case pci_channel_io_perm_failure:
2744 qla2x00_remove_one(pdev);
2745 return PCI_ERS_RESULT_DISCONNECT;
2747 return PCI_ERS_RESULT_NEED_RESET;
2750 static pci_ers_result_t
2751 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2753 int risc_paused = 0;
2755 unsigned long flags;
2756 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2757 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2758 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2760 spin_lock_irqsave(&ha->hardware_lock, flags);
2761 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
2762 stat = RD_REG_DWORD(®->hccr);
2763 if (stat & HCCR_RISC_PAUSE)
2765 } else if (IS_QLA23XX(ha)) {
2766 stat = RD_REG_DWORD(®->u.isp2300.host_status);
2767 if (stat & HSR_RISC_PAUSED)
2769 } else if (IS_FWI2_CAPABLE(ha)) {
2770 stat = RD_REG_DWORD(®24->host_status);
2771 if (stat & HSRX_RISC_PAUSED)
2774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2777 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2778 "Dumping firmware!\n");
2779 ha->isp_ops->fw_dump(ha, 0);
2781 return PCI_ERS_RESULT_NEED_RESET;
2783 return PCI_ERS_RESULT_RECOVERED;
2786 static pci_ers_result_t
2787 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2789 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2790 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2794 rc = pci_enable_device_mem(pdev);
2796 rc = pci_enable_device(pdev);
2799 qla_printk(KERN_WARNING, ha,
2800 "Can't re-enable PCI device after reset.\n");
2804 pci_set_master(pdev);
2806 if (ha->isp_ops->pci_config(ha))
2809 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2810 if (qla2x00_abort_isp(ha)== QLA_SUCCESS)
2811 ret = PCI_ERS_RESULT_RECOVERED;
2812 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2818 qla2xxx_pci_resume(struct pci_dev *pdev)
2820 scsi_qla_host_t *ha = pci_get_drvdata(pdev);
2823 ret = qla2x00_wait_for_hba_online(ha);
2824 if (ret != QLA_SUCCESS) {
2825 qla_printk(KERN_ERR, ha,
2826 "the device failed to resume I/O "
2827 "from slot/link_reset");
2829 pci_cleanup_aer_uncorrect_error_status(pdev);
2832 static struct pci_error_handlers qla2xxx_err_handler = {
2833 .error_detected = qla2xxx_pci_error_detected,
2834 .mmio_enabled = qla2xxx_pci_mmio_enabled,
2835 .slot_reset = qla2xxx_pci_slot_reset,
2836 .resume = qla2xxx_pci_resume,
2839 static struct pci_device_id qla2xxx_pci_tbl[] = {
2840 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
2841 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
2842 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
2843 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
2844 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
2845 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
2846 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
2847 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
2848 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
2849 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
2850 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
2851 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
2852 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
2855 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2857 static struct pci_driver qla2xxx_pci_driver = {
2858 .name = QLA2XXX_DRIVER_NAME,
2860 .owner = THIS_MODULE,
2862 .id_table = qla2xxx_pci_tbl,
2863 .probe = qla2x00_probe_one,
2864 .remove = qla2x00_remove_one,
2865 .err_handler = &qla2xxx_err_handler,
2869 * qla2x00_module_init - Module initialization.
2872 qla2x00_module_init(void)
2876 /* Allocate cache for SRBs. */
2877 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
2878 SLAB_HWCACHE_ALIGN, NULL);
2879 if (srb_cachep == NULL) {
2881 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2885 /* Derive version string. */
2886 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2887 if (ql2xextended_error_logging)
2888 strcat(qla2x00_version_str, "-debug");
2890 qla2xxx_transport_template =
2891 fc_attach_transport(&qla2xxx_transport_functions);
2892 if (!qla2xxx_transport_template) {
2893 kmem_cache_destroy(srb_cachep);
2896 qla2xxx_transport_vport_template =
2897 fc_attach_transport(&qla2xxx_transport_vport_functions);
2898 if (!qla2xxx_transport_vport_template) {
2899 kmem_cache_destroy(srb_cachep);
2900 fc_release_transport(qla2xxx_transport_template);
2904 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
2905 qla2x00_version_str);
2906 ret = pci_register_driver(&qla2xxx_pci_driver);
2908 kmem_cache_destroy(srb_cachep);
2909 fc_release_transport(qla2xxx_transport_template);
2910 fc_release_transport(qla2xxx_transport_vport_template);
2916 * qla2x00_module_exit - Module cleanup.
2919 qla2x00_module_exit(void)
2921 pci_unregister_driver(&qla2xxx_pci_driver);
2922 qla2x00_release_firmware();
2923 kmem_cache_destroy(srb_cachep);
2924 fc_release_transport(qla2xxx_transport_template);
2925 fc_release_transport(qla2xxx_transport_vport_template);
2928 module_init(qla2x00_module_init);
2929 module_exit(qla2x00_module_exit);
2931 MODULE_AUTHOR("QLogic Corporation");
2932 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2933 MODULE_LICENSE("GPL");
2934 MODULE_VERSION(QLA2XXX_VERSION);
2935 MODULE_FIRMWARE(FW_FILE_ISP21XX);
2936 MODULE_FIRMWARE(FW_FILE_ISP22XX);
2937 MODULE_FIRMWARE(FW_FILE_ISP2300);
2938 MODULE_FIRMWARE(FW_FILE_ISP2322);
2939 MODULE_FIRMWARE(FW_FILE_ISP24XX);
2940 MODULE_FIRMWARE(FW_FILE_ISP25XX);