2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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/version.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>
20 #if defined(FC_TARGET_SUPPORT)
21 #include "qla2x_tgt.h"
27 char qla2x00_version_str[40];
30 * SRB allocation cache
32 static struct kmem_cache *srb_cachep;
35 * Ioctl related information.
39 int ql2xlogintimeout = 20;
40 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
41 MODULE_PARM_DESC(ql2xlogintimeout,
42 "Login timeout value in seconds.");
44 int qlport_down_retry = 30;
45 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
46 MODULE_PARM_DESC(qlport_down_retry,
47 "Maximum number of command retries to a port that returns"
48 "a PORT-DOWN status.");
50 int ql2xplogiabsentdevice;
51 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
52 MODULE_PARM_DESC(ql2xplogiabsentdevice,
53 "Option to enable PLOGI to devices that are not present after "
54 "a Fabric scan. This is needed for several broken switches."
55 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
57 int ql2xloginretrycount = 0;
58 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
59 MODULE_PARM_DESC(ql2xloginretrycount,
60 "Specify an alternate value for the NVRAM login retry count.");
62 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
64 module_param(ql2xfwloadflash, int, S_IRUGO|S_IRUSR);
65 MODULE_PARM_DESC(ql2xfwloadflash,
66 "Load ISP24xx firmware image from FLASH (onboard memory).");
69 static void qla2x00_free_device(scsi_qla_host_t *);
71 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
74 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
75 MODULE_PARM_DESC(ql2xfdmienable,
76 "Enables FDMI registratons "
77 "Default is 0 - no FDMI. 1 - perfom FDMI.");
80 module_param(ql2xprocessrscn, int, S_IRUGO|S_IRUSR);
81 MODULE_PARM_DESC(ql2xprocessrscn,
82 "Option to enable port RSCN handling via a series of less"
83 "fabric intrusive ADISCs and PLOGIs.");
86 * SCSI host template entry points
88 static int qla2xxx_slave_configure(struct scsi_device * device);
89 static int qla2xxx_slave_alloc(struct scsi_device *);
90 static void qla2xxx_slave_destroy(struct scsi_device *);
91 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
92 void (*fn)(struct scsi_cmnd *));
93 static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
94 void (*fn)(struct scsi_cmnd *));
95 static int qla2xxx_eh_abort(struct scsi_cmnd *);
96 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
97 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
98 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
99 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
100 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
102 static int qla2x00_change_queue_depth(struct scsi_device *, int);
103 static int qla2x00_change_queue_type(struct scsi_device *, int);
105 static struct scsi_host_template qla2x00_driver_template = {
106 .module = THIS_MODULE,
108 .queuecommand = qla2x00_queuecommand,
110 .eh_abort_handler = qla2xxx_eh_abort,
111 .eh_device_reset_handler = qla2xxx_eh_device_reset,
112 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
113 .eh_host_reset_handler = qla2xxx_eh_host_reset,
115 .slave_configure = qla2xxx_slave_configure,
117 .slave_alloc = qla2xxx_slave_alloc,
118 .slave_destroy = qla2xxx_slave_destroy,
119 .change_queue_depth = qla2x00_change_queue_depth,
120 .change_queue_type = qla2x00_change_queue_type,
123 .use_clustering = ENABLE_CLUSTERING,
124 .sg_tablesize = SG_ALL,
127 * The RISC allows for each command to transfer (2^32-1) bytes of data,
128 * which equates to 0x800000 sectors.
130 .max_sectors = 0xFFFF,
131 .shost_attrs = qla2x00_host_attrs,
134 static struct scsi_host_template qla24xx_driver_template = {
135 .module = THIS_MODULE,
137 .queuecommand = qla24xx_queuecommand,
139 .eh_abort_handler = qla2xxx_eh_abort,
140 .eh_device_reset_handler = qla2xxx_eh_device_reset,
141 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
142 .eh_host_reset_handler = qla2xxx_eh_host_reset,
144 .slave_configure = qla2xxx_slave_configure,
146 .slave_alloc = qla2xxx_slave_alloc,
147 .slave_destroy = qla2xxx_slave_destroy,
148 .change_queue_depth = qla2x00_change_queue_depth,
149 .change_queue_type = qla2x00_change_queue_type,
152 .use_clustering = ENABLE_CLUSTERING,
153 .sg_tablesize = SG_ALL,
155 .max_sectors = 0xFFFF,
156 .shost_attrs = qla2x00_host_attrs,
159 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
161 /* TODO Convert to inlines
165 #define WATCH_INTERVAL 1 /* number of seconds */
167 static void qla2x00_timer(scsi_qla_host_t *);
169 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
170 void *, unsigned long);
171 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
172 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
175 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
177 init_timer(&ha->timer);
178 ha->timer.expires = jiffies + interval * HZ;
179 ha->timer.data = (unsigned long)ha;
180 ha->timer.function = (void (*)(unsigned long))func;
181 add_timer(&ha->timer);
182 ha->timer_active = 1;
186 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
188 mod_timer(&ha->timer, jiffies + interval * HZ);
191 static __inline__ void
192 qla2x00_stop_timer(scsi_qla_host_t *ha)
194 del_timer_sync(&ha->timer);
195 ha->timer_active = 0;
198 static int qla2x00_do_dpc(void *data);
200 static void qla2x00_rst_aen(scsi_qla_host_t *);
202 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
203 static void qla2x00_mem_free(scsi_qla_host_t *ha);
204 static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
205 static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
206 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
207 void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
209 /* -------------------------------------------------------------------------- */
212 qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
214 static char *pci_bus_modes[] = {
215 "33", "66", "100", "133",
220 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
223 strcat(str, pci_bus_modes[pci_bus]);
225 pci_bus = (ha->pci_attr & BIT_8) >> 8;
227 strcat(str, pci_bus_modes[pci_bus]);
229 strcat(str, " MHz)");
235 qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
237 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
241 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
244 uint16_t pcie_lstat, lspeed, lwidth;
247 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
248 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
249 lwidth = (pcie_lstat &
250 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
252 strcpy(str, "PCIe (");
254 strcat(str, "2.5Gb/s ");
256 strcat(str, "<unknown> ");
257 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
264 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
265 if (pci_bus == 0 || pci_bus == 8) {
267 strcat(str, pci_bus_modes[pci_bus >> 3]);
271 strcat(str, "Mode 2");
273 strcat(str, "Mode 1");
275 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
277 strcat(str, " MHz)");
283 qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
287 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
288 ha->fw_minor_version,
289 ha->fw_subminor_version);
291 if (ha->fw_attributes & BIT_9) {
296 switch (ha->fw_attributes & 0xFF) {
310 sprintf(un_str, "(%x)", ha->fw_attributes);
314 if (ha->fw_attributes & 0x100)
321 qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
323 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
324 ha->fw_minor_version,
325 ha->fw_subminor_version);
327 if (ha->fw_attributes & BIT_0)
328 strcat(str, "[Class 2] ");
329 if (ha->fw_attributes & BIT_1)
330 strcat(str, "[IP] ");
331 if (ha->fw_attributes & BIT_2)
332 strcat(str, "[Multi-ID] ");
333 if (ha->fw_attributes & BIT_13)
334 strcat(str, "[Experimental]");
338 static inline srb_t *
339 qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
340 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
344 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
348 atomic_set(&sp->ref_count, 1);
353 CMD_SP(cmd) = (void *)sp;
354 cmd->scsi_done = done;
360 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
362 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
363 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
364 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
368 rval = fc_remote_port_chkready(rport);
371 goto qc_fail_command;
374 /* Close window on fcport/rport state-transitioning. */
375 if (!*(fc_port_t **)rport->dd_data) {
376 cmd->result = DID_IMM_RETRY << 16;
377 goto qc_fail_command;
380 if (atomic_read(&fcport->state) != FCS_ONLINE) {
381 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
382 atomic_read(&ha->loop_state) == LOOP_DEAD) {
383 cmd->result = DID_NO_CONNECT << 16;
384 goto qc_fail_command;
389 spin_unlock_irq(ha->host->host_lock);
391 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
393 goto qc_host_busy_lock;
395 rval = qla2x00_start_scsi(sp);
396 if (rval != QLA_SUCCESS)
397 goto qc_host_busy_free_sp;
399 spin_lock_irq(ha->host->host_lock);
403 qc_host_busy_free_sp:
404 qla2x00_sp_free_dma(ha, sp);
405 mempool_free(sp, ha->srb_mempool);
408 spin_lock_irq(ha->host->host_lock);
411 return SCSI_MLQUEUE_HOST_BUSY;
421 qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
423 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
424 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
425 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
429 rval = fc_remote_port_chkready(rport);
432 goto qc24_fail_command;
435 /* Close window on fcport/rport state-transitioning. */
436 if (!*(fc_port_t **)rport->dd_data) {
437 cmd->result = DID_IMM_RETRY << 16;
438 goto qc24_fail_command;
441 if (atomic_read(&fcport->state) != FCS_ONLINE) {
442 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
443 atomic_read(&ha->loop_state) == LOOP_DEAD) {
444 cmd->result = DID_NO_CONNECT << 16;
445 goto qc24_fail_command;
450 spin_unlock_irq(ha->host->host_lock);
452 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
454 goto qc24_host_busy_lock;
456 rval = qla24xx_start_scsi(sp);
457 if (rval != QLA_SUCCESS)
458 goto qc24_host_busy_free_sp;
460 spin_lock_irq(ha->host->host_lock);
464 qc24_host_busy_free_sp:
465 qla2x00_sp_free_dma(ha, sp);
466 mempool_free(sp, ha->srb_mempool);
469 spin_lock_irq(ha->host->host_lock);
472 return SCSI_MLQUEUE_HOST_BUSY;
482 * qla2x00_eh_wait_on_command
483 * Waits for the command to be returned by the Firmware for some
487 * ha = actual ha whose done queue will contain the command
488 * returned by firmware.
489 * cmd = Scsi Command to wait on.
490 * flag = Abort/Reset(Bus or Device Reset)
497 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
499 #define ABORT_POLLING_PERIOD 1000
500 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
501 unsigned long wait_iter = ABORT_WAIT_ITER;
502 int ret = QLA_SUCCESS;
504 while (CMD_SP(cmd)) {
505 msleep(ABORT_POLLING_PERIOD);
511 ret = QLA_FUNCTION_FAILED;
517 * qla2x00_wait_for_hba_online
518 * Wait till the HBA is online after going through
519 * <= MAX_RETRIES_OF_ISP_ABORT or
520 * finally HBA is disabled ie marked offline
523 * ha - pointer to host adapter structure
526 * Does context switching-Release SPIN_LOCK
527 * (if any) before calling this routine.
530 * Success (Adapter is online) : 0
531 * Failed (Adapter is offline/disabled) : 1
534 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
537 unsigned long wait_online;
539 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
540 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
541 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
542 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
543 ha->dpc_active) && time_before(jiffies, wait_online)) {
547 if (ha->flags.online)
548 return_status = QLA_SUCCESS;
550 return_status = QLA_FUNCTION_FAILED;
552 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
554 return (return_status);
558 * qla2x00_wait_for_loop_ready
559 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
560 * to be in LOOP_READY state.
562 * ha - pointer to host adapter structure
565 * Does context switching-Release SPIN_LOCK
566 * (if any) before calling this routine.
570 * Success (LOOP_READY) : 0
571 * Failed (LOOP_NOT_READY) : 1
574 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
576 int return_status = QLA_SUCCESS;
577 unsigned long loop_timeout ;
579 /* wait for 5 min at the max for loop to be ready */
580 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
582 while ((!atomic_read(&ha->loop_down_timer) &&
583 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
584 atomic_read(&ha->loop_state) != LOOP_READY) {
586 if (time_after_eq(jiffies, loop_timeout)) {
587 return_status = QLA_FUNCTION_FAILED;
591 return (return_status);
594 /**************************************************************************
598 * The abort function will abort the specified command.
601 * cmd = Linux SCSI command packet to be aborted.
604 * Either SUCCESS or FAILED.
607 * Only return FAILED if command not returned by firmware.
608 **************************************************************************/
610 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
612 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
615 unsigned int id, lun;
616 unsigned long serial;
625 id = cmd->device->id;
626 lun = cmd->device->lun;
627 serial = cmd->serial_number;
629 /* Check active list for command command. */
630 spin_lock_irqsave(&ha->hardware_lock, flags);
631 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
632 sp = ha->outstanding_cmds[i];
640 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
641 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
643 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
645 spin_unlock_irqrestore(&ha->hardware_lock, flags);
646 if (ha->isp_ops.abort_command(ha, sp)) {
647 DEBUG2(printk("%s(%ld): abort_command "
648 "mbx failed.\n", __func__, ha->host_no));
650 DEBUG3(printk("%s(%ld): abort_command "
651 "mbx success.\n", __func__, ha->host_no));
654 spin_lock_irqsave(&ha->hardware_lock, flags);
658 spin_unlock_irqrestore(&ha->hardware_lock, flags);
660 /* Wait for the command to be returned. */
662 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
663 qla_printk(KERN_ERR, ha,
664 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
665 "%x.\n", ha->host_no, id, lun, serial, ret);
670 qla_printk(KERN_INFO, ha,
671 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
672 ha->host_no, id, lun, wait, serial, ret);
677 /**************************************************************************
678 * qla2x00_eh_wait_for_pending_target_commands
681 * Waits for all the commands to come back from the specified target.
684 * ha - pointer to scsi_qla_host structure.
687 * Either SUCCESS or FAILED.
690 **************************************************************************/
692 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
697 struct scsi_cmnd *cmd;
703 * Waiting for all commands for the designated target in the active
706 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
707 spin_lock_irqsave(&ha->hardware_lock, flags);
708 sp = ha->outstanding_cmds[cnt];
711 spin_unlock_irqrestore(&ha->hardware_lock, flags);
712 if (cmd->device->id == t) {
713 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
726 /**************************************************************************
727 * qla2xxx_eh_device_reset
730 * The device reset function will reset the target and abort any
731 * executing commands.
733 * NOTE: The use of SP is undefined within this context. Do *NOT*
734 * attempt to use this value, even if you determine it is
738 * cmd = Linux SCSI command packet of the command that cause the
742 * SUCCESS/FAILURE (defined as macro in scsi.h).
744 **************************************************************************/
746 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
748 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
749 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
752 unsigned int id, lun;
753 unsigned long serial;
757 id = cmd->device->id;
758 lun = cmd->device->lun;
759 serial = cmd->serial_number;
761 sp = (srb_t *) CMD_SP(cmd);
765 qla_printk(KERN_INFO, ha,
766 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
768 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
769 goto eh_dev_reset_done;
771 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
772 if (qla2x00_device_reset(ha, fcport) == 0)
775 #if defined(LOGOUT_AFTER_DEVICE_RESET)
776 if (ret == SUCCESS) {
777 if (fcport->flags & FC_FABRIC_DEVICE) {
778 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
779 qla2x00_mark_device_lost(ha, fcport, 0, 0);
784 DEBUG2(printk(KERN_INFO
785 "%s failed: loop not ready\n",__func__);)
789 DEBUG3(printk("%s(%ld): device reset failed\n",
790 __func__, ha->host_no));
791 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
794 goto eh_dev_reset_done;
797 /* Flush outstanding commands. */
798 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
801 DEBUG3(printk("%s(%ld): failed while waiting for commands\n",
802 __func__, ha->host_no));
803 qla_printk(KERN_INFO, ha,
804 "%s: failed while waiting for commands\n", __func__);
806 qla_printk(KERN_INFO, ha,
807 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n",
808 ha->host_no, id, lun);
815 /**************************************************************************
816 * qla2x00_eh_wait_for_pending_commands
819 * Waits for all the commands to come back from the specified host.
822 * ha - pointer to scsi_qla_host structure.
829 **************************************************************************/
831 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
836 struct scsi_cmnd *cmd;
842 * Waiting for all commands for the designated target in the active
845 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
846 spin_lock_irqsave(&ha->hardware_lock, flags);
847 sp = ha->outstanding_cmds[cnt];
850 spin_unlock_irqrestore(&ha->hardware_lock, flags);
851 status = qla2x00_eh_wait_on_command(ha, cmd);
856 spin_unlock_irqrestore(&ha->hardware_lock, flags);
863 /**************************************************************************
864 * qla2xxx_eh_bus_reset
867 * The bus reset function will reset the bus and abort any executing
871 * cmd = Linux SCSI command packet of the command that cause the
875 * SUCCESS/FAILURE (defined as macro in scsi.h).
877 **************************************************************************/
879 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
881 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
882 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
885 unsigned int id, lun;
886 unsigned long serial;
890 id = cmd->device->id;
891 lun = cmd->device->lun;
892 serial = cmd->serial_number;
894 sp = (srb_t *) CMD_SP(cmd);
898 qla_printk(KERN_INFO, ha,
899 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
901 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
902 DEBUG2(printk("%s failed:board disabled\n",__func__));
903 goto eh_bus_reset_done;
906 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
907 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
911 goto eh_bus_reset_done;
913 /* Flush outstanding commands. */
914 if (!qla2x00_eh_wait_for_pending_commands(ha))
918 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
919 (ret == FAILED) ? "failed" : "succeded");
924 /**************************************************************************
925 * qla2xxx_eh_host_reset
928 * The reset function will reset the Adapter.
931 * cmd = Linux SCSI command packet of the command that cause the
935 * Either SUCCESS or FAILED.
938 **************************************************************************/
940 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
942 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
943 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
946 unsigned int id, lun;
947 unsigned long serial;
951 id = cmd->device->id;
952 lun = cmd->device->lun;
953 serial = cmd->serial_number;
955 sp = (srb_t *) CMD_SP(cmd);
959 qla_printk(KERN_INFO, ha,
960 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
962 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
963 goto eh_host_reset_lock;
966 * Fixme-may be dpc thread is active and processing
967 * loop_resync,so wait a while for it to
968 * be completed and then issue big hammer.Otherwise
969 * it may cause I/O failure as big hammer marks the
970 * devices as lost kicking of the port_down_timer
971 * while dpc is stuck for the mailbox to complete.
973 qla2x00_wait_for_loop_ready(ha);
974 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
975 if (qla2x00_abort_isp(ha)) {
976 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
977 /* failed. schedule dpc to try */
978 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
980 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
981 goto eh_host_reset_lock;
983 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
985 /* Waiting for our command in done_queue to be returned to OS.*/
986 if (qla2x00_eh_wait_for_pending_commands(ha))
990 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
991 (ret == FAILED) ? "failed" : "succeded");
1001 * ha = adapter block pointer.
1007 qla2x00_loop_reset(scsi_qla_host_t *ha)
1009 int status = QLA_SUCCESS;
1010 struct fc_port *fcport;
1012 if (ha->flags.enable_lip_reset) {
1013 status = qla2x00_lip_reset(ha);
1016 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1017 list_for_each_entry(fcport, &ha->fcports, list) {
1018 if (fcport->port_type != FCT_TARGET)
1021 status = qla2x00_device_reset(ha, fcport);
1022 if (status != QLA_SUCCESS)
1027 if (status == QLA_SUCCESS &&
1028 ((!ha->flags.enable_target_reset &&
1029 !ha->flags.enable_lip_reset) ||
1030 ha->flags.enable_lip_full_login)) {
1032 status = qla2x00_full_login_lip(ha);
1035 /* Issue marker command only when we are going to start the I/O */
1036 ha->marker_needed = 1;
1040 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1045 DEBUG3(printk("%s(%ld): exiting normally.\n",
1054 * qla2x00_device_reset
1055 * Issue bus device reset message to the target.
1058 * ha = adapter block pointer.
1060 * TARGET_QUEUE_LOCK must be released.
1061 * ADAPTER_STATE_LOCK must be released.
1067 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1069 /* Abort Target command will clear Reservation */
1070 return ha->isp_ops.abort_target(reset_fcport);
1074 qla2xxx_slave_alloc(struct scsi_device *sdev)
1076 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1078 if (!rport || fc_remote_port_chkready(rport))
1081 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1087 qla2xxx_slave_configure(struct scsi_device *sdev)
1089 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1090 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1092 if (sdev->tagged_supported)
1093 scsi_activate_tcq(sdev, 32);
1095 scsi_deactivate_tcq(sdev, 32);
1097 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1103 qla2xxx_slave_destroy(struct scsi_device *sdev)
1105 sdev->hostdata = NULL;
1109 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1111 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1112 return sdev->queue_depth;
1116 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1118 if (sdev->tagged_supported) {
1119 scsi_set_tag_type(sdev, tag_type);
1121 scsi_activate_tcq(sdev, sdev->queue_depth);
1123 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1131 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1134 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1135 * supported addressing method.
1138 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1140 /* Assume a 32bit DMA mask. */
1141 ha->flags.enable_64bit_addressing = 0;
1143 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1144 /* Any upper-dword bits set? */
1145 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1146 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1147 /* Ok, a 64bit DMA mask is applicable. */
1148 ha->flags.enable_64bit_addressing = 1;
1149 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1150 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
1155 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1156 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
1160 qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1162 ha->device_type = DT_EXTENDED_IDS;
1163 switch (ha->pdev->device) {
1164 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1165 ha->device_type |= DT_ISP2100;
1166 ha->device_type &= ~DT_EXTENDED_IDS;
1168 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1169 ha->device_type |= DT_ISP2200;
1170 ha->device_type &= ~DT_EXTENDED_IDS;
1172 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1173 ha->device_type |= DT_ISP2300;
1174 ha->device_type |= DT_ZIO_SUPPORTED;
1176 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1177 ha->device_type |= DT_ISP2312;
1178 ha->device_type |= DT_ZIO_SUPPORTED;
1180 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1181 ha->device_type |= DT_ISP2322;
1182 ha->device_type |= DT_ZIO_SUPPORTED;
1183 if (ha->pdev->subsystem_vendor == 0x1028 &&
1184 ha->pdev->subsystem_device == 0x0170)
1185 ha->device_type |= DT_OEM_001;
1187 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1188 ha->device_type |= DT_ISP6312;
1190 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1191 ha->device_type |= DT_ISP6322;
1193 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1194 ha->device_type |= DT_ISP2422;
1195 ha->device_type |= DT_ZIO_SUPPORTED;
1197 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1198 ha->device_type |= DT_ISP2432;
1199 ha->device_type |= DT_ZIO_SUPPORTED;
1201 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
1202 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1203 ha->device_type |= DT_ISP5422;
1205 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1206 ha->device_type |= DT_ISP5432;
1213 qla2x00_iospace_config(scsi_qla_host_t *ha)
1215 unsigned long pio, pio_len, pio_flags;
1216 unsigned long mmio, mmio_len, mmio_flags;
1218 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1219 pio = pci_resource_start(ha->pdev, 0);
1220 pio_len = pci_resource_len(ha->pdev, 0);
1221 pio_flags = pci_resource_flags(ha->pdev, 0);
1222 if (pio_flags & IORESOURCE_IO) {
1223 if (pio_len < MIN_IOBASE_LEN) {
1224 qla_printk(KERN_WARNING, ha,
1225 "Invalid PCI I/O region size (%s)...\n",
1226 pci_name(ha->pdev));
1230 qla_printk(KERN_WARNING, ha,
1231 "region #0 not a PIO resource (%s)...\n",
1232 pci_name(ha->pdev));
1236 /* Use MMIO operations for all accesses. */
1237 mmio = pci_resource_start(ha->pdev, 1);
1238 mmio_len = pci_resource_len(ha->pdev, 1);
1239 mmio_flags = pci_resource_flags(ha->pdev, 1);
1241 if (!(mmio_flags & IORESOURCE_MEM)) {
1242 qla_printk(KERN_ERR, ha,
1243 "region #0 not an MMIO resource (%s), aborting\n",
1244 pci_name(ha->pdev));
1245 goto iospace_error_exit;
1247 if (mmio_len < MIN_IOBASE_LEN) {
1248 qla_printk(KERN_ERR, ha,
1249 "Invalid PCI mem region size (%s), aborting\n",
1250 pci_name(ha->pdev));
1251 goto iospace_error_exit;
1254 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1255 qla_printk(KERN_WARNING, ha,
1256 "Failed to reserve PIO/MMIO regions (%s)\n",
1257 pci_name(ha->pdev));
1259 goto iospace_error_exit;
1262 ha->pio_address = pio;
1263 ha->pio_length = pio_len;
1264 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1266 qla_printk(KERN_ERR, ha,
1267 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1269 goto iospace_error_exit;
1279 qla2x00_enable_intrs(scsi_qla_host_t *ha)
1281 unsigned long flags = 0;
1282 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1284 spin_lock_irqsave(&ha->hardware_lock, flags);
1285 ha->interrupts_on = 1;
1286 /* enable risc and host interrupts */
1287 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1288 RD_REG_WORD(®->ictrl);
1289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1294 qla2x00_disable_intrs(scsi_qla_host_t *ha)
1296 unsigned long flags = 0;
1297 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1299 spin_lock_irqsave(&ha->hardware_lock, flags);
1300 ha->interrupts_on = 0;
1301 /* disable risc and host interrupts */
1302 WRT_REG_WORD(®->ictrl, 0);
1303 RD_REG_WORD(®->ictrl);
1304 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1308 qla24xx_enable_intrs(scsi_qla_host_t *ha)
1310 unsigned long flags = 0;
1311 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1313 spin_lock_irqsave(&ha->hardware_lock, flags);
1314 ha->interrupts_on = 1;
1315 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1316 RD_REG_DWORD(®->ictrl);
1317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1321 qla24xx_disable_intrs(scsi_qla_host_t *ha)
1323 unsigned long flags = 0;
1324 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1326 spin_lock_irqsave(&ha->hardware_lock, flags);
1327 ha->interrupts_on = 0;
1328 WRT_REG_DWORD(®->ictrl, 0);
1329 RD_REG_DWORD(®->ictrl);
1330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1334 * PCI driver interface
1336 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1339 device_reg_t __iomem *reg;
1340 struct Scsi_Host *host;
1341 scsi_qla_host_t *ha;
1342 unsigned long flags = 0;
1343 unsigned long wait_switch = 0;
1347 struct scsi_host_template *sht;
1349 if (pci_enable_device(pdev))
1352 sht = &qla2x00_driver_template;
1353 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1354 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432)
1355 sht = &qla24xx_driver_template;
1356 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
1359 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1360 goto probe_disable_device;
1363 /* Clear our data area */
1364 ha = (scsi_qla_host_t *)host->hostdata;
1365 memset(ha, 0, sizeof(scsi_qla_host_t));
1369 ha->host_no = host->host_no;
1370 ha->brd_info = brd_info;
1371 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1373 /* Set ISP-type information. */
1374 qla2x00_set_isp_flags(ha);
1376 /* Configure PCI I/O space */
1377 ret = qla2x00_iospace_config(ha);
1381 qla_printk(KERN_INFO, ha,
1382 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1385 spin_lock_init(&ha->hardware_lock);
1387 ha->prev_topology = 0;
1388 ha->ports = MAX_BUSES;
1389 ha->init_cb_size = sizeof(init_cb_t);
1390 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
1391 ha->link_data_rate = LDR_UNKNOWN;
1392 ha->optrom_size = OPTROM_SIZE_2300;
1394 /* Assign ISP specific operations. */
1395 ha->isp_ops.pci_config = qla2100_pci_config;
1396 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1397 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1398 ha->isp_ops.config_rings = qla2x00_config_rings;
1399 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1400 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1401 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
1402 ha->isp_ops.load_risc = qla2x00_load_risc;
1403 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1404 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1405 ha->isp_ops.intr_handler = qla2100_intr_handler;
1406 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1407 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1408 ha->isp_ops.abort_command = qla2x00_abort_command;
1409 ha->isp_ops.abort_target = qla2x00_abort_target;
1410 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1411 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1412 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1413 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1414 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
1415 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
1416 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1417 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
1418 ha->isp_ops.fw_dump = qla2100_fw_dump;
1419 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
1420 ha->isp_ops.read_optrom = qla2x00_read_optrom_data;
1421 ha->isp_ops.write_optrom = qla2x00_write_optrom_data;
1422 if (IS_QLA2100(ha)) {
1423 host->max_id = MAX_TARGETS_2100;
1424 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1425 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1426 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1427 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1428 host->sg_tablesize = 32;
1429 ha->gid_list_info_size = 4;
1430 } else if (IS_QLA2200(ha)) {
1431 host->max_id = MAX_TARGETS_2200;
1432 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1433 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1434 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1435 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1436 ha->gid_list_info_size = 4;
1437 } else if (IS_QLA23XX(ha)) {
1438 host->max_id = MAX_TARGETS_2200;
1439 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1440 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1441 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1442 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1443 ha->isp_ops.pci_config = qla2300_pci_config;
1444 ha->isp_ops.intr_handler = qla2300_intr_handler;
1445 ha->isp_ops.fw_dump = qla2300_fw_dump;
1446 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1447 ha->isp_ops.beacon_on = qla2x00_beacon_on;
1448 ha->isp_ops.beacon_off = qla2x00_beacon_off;
1449 ha->isp_ops.beacon_blink = qla2x00_beacon_blink;
1450 ha->gid_list_info_size = 6;
1451 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1452 ha->optrom_size = OPTROM_SIZE_2322;
1453 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1454 host->max_id = MAX_TARGETS_2200;
1455 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1456 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1457 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1458 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1459 ha->init_cb_size = sizeof(struct init_cb_24xx);
1460 ha->mgmt_svr_loop_id = 10;
1461 ha->isp_ops.pci_config = qla24xx_pci_config;
1462 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1463 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1464 ha->isp_ops.config_rings = qla24xx_config_rings;
1465 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1466 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1467 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1468 ha->isp_ops.load_risc = qla24xx_load_risc;
1469 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
1470 if (ql2xfwloadflash)
1471 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1473 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1474 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1475 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1476 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1477 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1478 ha->isp_ops.abort_command = qla24xx_abort_command;
1479 ha->isp_ops.abort_target = qla24xx_abort_target;
1480 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1481 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1482 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
1483 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
1484 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1485 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1486 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1487 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1488 ha->isp_ops.read_optrom = qla24xx_read_optrom_data;
1489 ha->isp_ops.write_optrom = qla24xx_write_optrom_data;
1490 ha->isp_ops.beacon_on = qla24xx_beacon_on;
1491 ha->isp_ops.beacon_off = qla24xx_beacon_off;
1492 ha->isp_ops.beacon_blink = qla24xx_beacon_blink;
1493 ha->gid_list_info_size = 8;
1494 ha->optrom_size = OPTROM_SIZE_24XX;
1496 host->can_queue = ha->request_q_length + 128;
1498 /* load the F/W, read paramaters, and init the H/W */
1499 ha->instance = num_hosts;
1501 init_MUTEX(&ha->mbx_cmd_sem);
1502 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1504 INIT_LIST_HEAD(&ha->list);
1505 INIT_LIST_HEAD(&ha->fcports);
1506 INIT_LIST_HEAD(&ha->rscn_fcports);
1509 * These locks are used to prevent more than one CPU
1510 * from modifying the queue at the same time. The
1511 * higher level "host_lock" will reduce most
1512 * contention for these locks.
1514 spin_lock_init(&ha->mbx_reg_lock);
1516 qla2x00_config_dma_addressing(ha);
1517 if (qla2x00_mem_alloc(ha)) {
1518 qla_printk(KERN_WARNING, ha,
1519 "[ERROR] Failed to allocate memory for adapter\n");
1525 if (qla2x00_initialize_adapter(ha) &&
1526 !(ha->device_flags & DFLG_NO_CABLE)) {
1528 qla_printk(KERN_WARNING, ha,
1529 "Failed to initialize adapter\n");
1531 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1532 "Adapter flags %x.\n",
1533 ha->host_no, ha->device_flags));
1540 * Startup the kernel thread for this host adapter
1542 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1543 "%s_dpc", ha->host_str);
1544 if (IS_ERR(ha->dpc_thread)) {
1545 qla_printk(KERN_WARNING, ha,
1546 "Unable to start DPC thread!\n");
1547 ret = PTR_ERR(ha->dpc_thread);
1551 host->this_id = 255;
1552 host->cmd_per_lun = 3;
1553 host->unique_id = ha->instance;
1554 host->max_cmd_len = MAX_CMDSZ;
1555 host->max_channel = ha->ports - 1;
1556 host->max_lun = MAX_LUNS;
1557 host->transportt = qla2xxx_transport_template;
1559 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
1560 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1562 qla_printk(KERN_WARNING, ha,
1563 "Failed to reserve interrupt %d already in use.\n",
1567 host->irq = pdev->irq;
1569 /* Initialized the timer */
1570 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1572 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1575 ha->isp_ops.disable_intrs(ha);
1577 spin_lock_irqsave(&ha->hardware_lock, flags);
1579 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1580 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
1581 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
1583 WRT_REG_WORD(®->isp.semaphore, 0);
1584 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
1585 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
1587 /* Enable proper parity */
1588 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1591 WRT_REG_WORD(®->isp.hccr,
1592 (HCCR_ENABLE_PARITY + 0x1));
1594 /* SRAM, Instruction RAM and GP RAM parity */
1595 WRT_REG_WORD(®->isp.hccr,
1596 (HCCR_ENABLE_PARITY + 0x7));
1599 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1601 ha->isp_ops.enable_intrs(ha);
1605 * Wait around max loop_reset_delay secs for the devices to come
1606 * on-line. We don't want Linux scanning before we are ready.
1609 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1610 time_before(jiffies,wait_switch) &&
1611 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1612 && (ha->device_flags & SWITCH_FOUND) ;) {
1614 qla2x00_check_fabric_devices(ha);
1619 pci_set_drvdata(pdev, ha);
1620 ha->flags.init_done = 1;
1623 ret = scsi_add_host(host, &pdev->dev);
1627 qla2x00_alloc_sysfs_attr(ha);
1629 qla2x00_init_host_attr(ha);
1631 qla_printk(KERN_INFO, ha, "\n"
1632 " QLogic Fibre Channel HBA Driver: %s\n"
1634 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1635 qla2x00_version_str, ha->model_number,
1636 ha->model_desc ? ha->model_desc: "", pdev->device,
1637 ha->isp_ops.pci_info_str(ha, pci_info), pci_name(pdev),
1638 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no,
1639 ha->isp_ops.fw_version_str(ha, fw_str));
1641 /* Go with fc_rport registration. */
1642 list_for_each_entry(fcport, &ha->fcports, list)
1643 qla2x00_reg_remote_port(ha, fcport);
1648 qla2x00_free_device(ha);
1650 scsi_host_put(host);
1652 probe_disable_device:
1653 pci_disable_device(pdev);
1658 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1660 void qla2x00_remove_one(struct pci_dev *pdev)
1662 scsi_qla_host_t *ha;
1664 ha = pci_get_drvdata(pdev);
1666 #if defined(FC_TARGET_SUPPORT)
1667 ha->flags.host_shutting_down = 1;
1668 if (qla_target.tgt_host_action != NULL)
1669 qla_target.tgt_host_action(ha, DISABLE_TARGET_MODE);
1671 qla2x00_free_sysfs_attr(ha);
1673 fc_remove_host(ha->host);
1675 scsi_remove_host(ha->host);
1677 qla2x00_free_device(ha);
1679 scsi_host_put(ha->host);
1681 pci_set_drvdata(pdev, NULL);
1683 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1686 qla2x00_free_device(scsi_qla_host_t *ha)
1688 /* Abort any outstanding IO descriptors. */
1689 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1690 qla2x00_cancel_io_descriptors(ha);
1693 if (ha->timer_active)
1694 qla2x00_stop_timer(ha);
1696 /* Kill the kernel thread for this host */
1697 if (ha->dpc_thread) {
1698 struct task_struct *t = ha->dpc_thread;
1701 * qla2xxx_wake_dpc checks for ->dpc_thread
1702 * so we need to zero it out.
1704 ha->dpc_thread = NULL;
1708 /* Stop currently executing firmware. */
1709 qla2x00_stop_firmware(ha);
1711 /* turn-off interrupts on the card */
1712 if (ha->interrupts_on)
1713 ha->isp_ops.disable_intrs(ha);
1715 qla2x00_mem_free(ha);
1717 ha->flags.online = 0;
1719 /* Detach interrupts */
1721 free_irq(ha->host->irq, ha);
1723 /* release io space registers */
1725 iounmap(ha->iobase);
1726 pci_release_regions(ha->pdev);
1728 pci_disable_device(ha->pdev);
1732 qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1735 unsigned long flags;
1736 struct fc_rport *rport;
1741 rport = fcport->rport;
1743 spin_lock_irqsave(&fcport->rport_lock, flags);
1744 fcport->drport = rport;
1745 fcport->rport = NULL;
1746 *(fc_port_t **)rport->dd_data = NULL;
1747 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1748 set_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags);
1750 spin_lock_irqsave(&fcport->rport_lock, flags);
1751 fcport->rport = NULL;
1752 *(fc_port_t **)rport->dd_data = NULL;
1753 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1754 fc_remote_port_delete(rport);
1759 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1761 * Input: ha = adapter block pointer. fcport = port structure pointer.
1767 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1768 int do_login, int defer)
1770 if (atomic_read(&fcport->state) == FCS_ONLINE)
1771 qla2x00_schedule_rport_del(ha, fcport, defer);
1774 * We may need to retry the login, so don't change the state of the
1775 * port but do the retries.
1777 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1778 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1783 if (fcport->login_retry == 0) {
1784 fcport->login_retry = ha->login_retry_count;
1785 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1787 DEBUG(printk("scsi(%ld): Port login retry: "
1788 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1789 "id = 0x%04x retry cnt=%d\n",
1791 fcport->port_name[0],
1792 fcport->port_name[1],
1793 fcport->port_name[2],
1794 fcport->port_name[3],
1795 fcport->port_name[4],
1796 fcport->port_name[5],
1797 fcport->port_name[6],
1798 fcport->port_name[7],
1800 fcport->login_retry));
1805 * qla2x00_mark_all_devices_lost
1806 * Updates fcport state when device goes offline.
1809 * ha = adapter block pointer.
1810 * fcport = port structure pointer.
1818 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
1822 list_for_each_entry(fcport, &ha->fcports, list) {
1823 if (fcport->port_type != FCT_TARGET)
1827 * No point in marking the device as lost, if the device is
1830 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1832 if (atomic_read(&fcport->state) == FCS_ONLINE)
1833 qla2x00_schedule_rport_del(ha, fcport, defer);
1834 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1838 qla2xxx_wake_dpc(ha);
1843 * Allocates adapter memory.
1850 qla2x00_mem_alloc(scsi_qla_host_t *ha)
1858 * This will loop only once if everything goes well, else some
1859 * number of retries will be performed to get around a kernel
1860 * bug where available mem is not allocated until after a
1861 * little delay and a retry.
1863 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1864 (ha->request_q_length + 1) * sizeof(request_t),
1865 &ha->request_dma, GFP_KERNEL);
1866 if (ha->request_ring == NULL) {
1867 qla_printk(KERN_WARNING, ha,
1868 "Memory Allocation failed - request_ring\n");
1870 qla2x00_mem_free(ha);
1876 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1877 (ha->response_q_length + 1) * sizeof(response_t),
1878 &ha->response_dma, GFP_KERNEL);
1879 if (ha->response_ring == NULL) {
1880 qla_printk(KERN_WARNING, ha,
1881 "Memory Allocation failed - response_ring\n");
1883 qla2x00_mem_free(ha);
1889 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1890 &ha->gid_list_dma, GFP_KERNEL);
1891 if (ha->gid_list == NULL) {
1892 qla_printk(KERN_WARNING, ha,
1893 "Memory Allocation failed - gid_list\n");
1895 qla2x00_mem_free(ha);
1901 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1902 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1903 if (ha->rlc_rsp == NULL) {
1904 qla_printk(KERN_WARNING, ha,
1905 "Memory Allocation failed - rlc");
1907 qla2x00_mem_free(ha);
1913 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1914 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1915 DMA_POOL_SIZE, 8, 0);
1916 if (ha->s_dma_pool == NULL) {
1917 qla_printk(KERN_WARNING, ha,
1918 "Memory Allocation failed - s_dma_pool\n");
1920 qla2x00_mem_free(ha);
1926 /* get consistent memory allocated for init control block */
1927 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1929 if (ha->init_cb == NULL) {
1930 qla_printk(KERN_WARNING, ha,
1931 "Memory Allocation failed - init_cb\n");
1933 qla2x00_mem_free(ha);
1938 memset(ha->init_cb, 0, ha->init_cb_size);
1940 /* Get consistent memory allocated for Get Port Database cmd */
1941 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1942 &ha->iodesc_pd_dma);
1943 if (ha->iodesc_pd == NULL) {
1945 qla_printk(KERN_WARNING, ha,
1946 "Memory Allocation failed - iodesc_pd\n");
1948 qla2x00_mem_free(ha);
1953 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1955 /* Allocate ioctl related memory. */
1956 if (qla2x00_alloc_ioctl_mem(ha)) {
1957 qla_printk(KERN_WARNING, ha,
1958 "Memory Allocation failed - ioctl_mem\n");
1960 qla2x00_mem_free(ha);
1966 if (qla2x00_allocate_sp_pool(ha)) {
1967 qla_printk(KERN_WARNING, ha,
1968 "Memory Allocation failed - "
1969 "qla2x00_allocate_sp_pool()\n");
1971 qla2x00_mem_free(ha);
1977 /* Allocate memory for SNS commands */
1978 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1979 /* Get consistent memory allocated for SNS commands */
1980 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1981 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1983 if (ha->sns_cmd == NULL) {
1985 qla_printk(KERN_WARNING, ha,
1986 "Memory Allocation failed - sns_cmd\n");
1988 qla2x00_mem_free(ha);
1993 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1995 /* Get consistent memory allocated for MS IOCB */
1996 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1998 if (ha->ms_iocb == NULL) {
2000 qla_printk(KERN_WARNING, ha,
2001 "Memory Allocation failed - ms_iocb\n");
2003 qla2x00_mem_free(ha);
2008 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2011 * Get consistent memory allocated for CT SNS
2014 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2015 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2017 if (ha->ct_sns == NULL) {
2019 qla_printk(KERN_WARNING, ha,
2020 "Memory Allocation failed - ct_sns\n");
2022 qla2x00_mem_free(ha);
2027 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2030 /* Done all allocations without any error. */
2033 } while (retry-- && status != 0);
2037 "%s(): **** FAILED ****\n", __func__);
2045 * Frees all adapter allocated memory.
2048 * ha = adapter block pointer.
2051 qla2x00_mem_free(scsi_qla_host_t *ha)
2053 struct list_head *fcpl, *fcptemp;
2058 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
2062 /* free ioctl memory */
2063 qla2x00_free_ioctl_mem(ha);
2066 qla2x00_free_sp_pool(ha);
2069 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2070 ha->sns_cmd, ha->sns_cmd_dma);
2073 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2074 ha->ct_sns, ha->ct_sns_dma);
2077 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2080 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
2083 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
2086 dma_pool_destroy(ha->s_dma_pool);
2089 dma_free_coherent(&ha->pdev->dev,
2090 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2094 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2097 if (ha->response_ring)
2098 dma_free_coherent(&ha->pdev->dev,
2099 (ha->response_q_length + 1) * sizeof(response_t),
2100 ha->response_ring, ha->response_dma);
2102 if (ha->request_ring)
2103 dma_free_coherent(&ha->pdev->dev,
2104 (ha->request_q_length + 1) * sizeof(request_t),
2105 ha->request_ring, ha->request_dma);
2108 ha->sns_cmd_dma = 0;
2112 ha->ms_iocb_dma = 0;
2113 ha->iodesc_pd = NULL;
2114 ha->iodesc_pd_dma = 0;
2116 ha->init_cb_dma = 0;
2118 ha->s_dma_pool = NULL;
2121 ha->rlc_rsp_dma = 0;
2122 ha->gid_list = NULL;
2123 ha->gid_list_dma = 0;
2125 ha->response_ring = NULL;
2126 ha->response_dma = 0;
2127 ha->request_ring = NULL;
2128 ha->request_dma = 0;
2130 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2131 fcport = list_entry(fcpl, fc_port_t, list);
2134 list_del_init(&fcport->list);
2137 INIT_LIST_HEAD(&ha->fcports);
2140 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2142 vfree(ha->fw_dump24);
2144 vfree(ha->fw_dump_buffer);
2147 ha->fw_dump24 = NULL;
2149 ha->fw_dump_reading = 0;
2150 ha->fw_dump_buffer = NULL;
2152 vfree(ha->optrom_buffer);
2156 * qla2x00_allocate_sp_pool
2157 * This routine is called during initialization to allocate
2158 * memory for local srb_t.
2161 * ha = adapter block pointer.
2166 * Note: Sets the ref_count for non Null sp to one.
2169 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2174 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
2175 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2177 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2178 mempool_free_slab, srb_cachep);
2180 if (ha->srb_mempool == NULL) {
2181 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2182 rval = QLA_FUNCTION_FAILED;
2188 * This routine frees all adapter allocated memory.
2192 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
2194 if (ha->srb_mempool) {
2195 mempool_destroy(ha->srb_mempool);
2196 ha->srb_mempool = NULL;
2200 /**************************************************************************
2202 * This kernel thread is a task that is schedule by the interrupt handler
2203 * to perform the background processing for interrupts.
2206 * This task always run in the context of a kernel thread. It
2207 * is kick-off by the driver's detect code and starts up
2208 * up one per adapter. It immediately goes to sleep and waits for
2209 * some fibre event. When either the interrupt handler or
2210 * the timer routine detects a event it will one of the task
2211 * bits then wake us up.
2212 **************************************************************************/
2214 qla2x00_do_dpc(void *data)
2216 scsi_qla_host_t *ha;
2219 uint16_t next_loopid;
2221 ha = (scsi_qla_host_t *)data;
2223 set_user_nice(current, -20);
2225 while (!kthread_should_stop()) {
2226 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2228 set_current_state(TASK_INTERRUPTIBLE);
2230 __set_current_state(TASK_RUNNING);
2232 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2234 /* Initialization not yet finished. Don't do anything yet. */
2235 if (!ha->flags.init_done)
2238 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2242 if (ha->flags.mbox_busy) {
2247 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2249 DEBUG(printk("scsi(%ld): dpc: sched "
2250 "qla2x00_abort_isp ha = %p\n",
2252 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2255 if (qla2x00_abort_isp(ha)) {
2256 /* failed. retry later */
2257 set_bit(ISP_ABORT_NEEDED,
2260 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2262 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2266 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags))
2267 qla2x00_update_fcports(ha);
2269 if (test_and_clear_bit(LOOP_RESET_NEEDED, &ha->dpc_flags)) {
2270 DEBUG(printk("scsi(%ld): dpc: sched loop_reset()\n",
2272 qla2x00_loop_reset(ha);
2275 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2276 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2278 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2281 qla2x00_rst_aen(ha);
2282 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2285 /* Retry each device up to login retry count */
2286 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2287 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2288 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2290 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2294 list_for_each_entry(fcport, &ha->fcports, list) {
2295 if (fcport->port_type != FCT_TARGET)
2299 * If the port is not ONLINE then try to login
2300 * to it if we haven't run out of retries.
2302 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2303 fcport->login_retry) {
2305 fcport->login_retry--;
2306 if (fcport->flags & FCF_FABRIC_DEVICE) {
2309 ha->isp_ops.fabric_logout(
2310 ha, fcport->loop_id,
2311 fcport->d_id.b.domain,
2312 fcport->d_id.b.area,
2313 fcport->d_id.b.al_pa);
2314 status = qla2x00_fabric_login(
2315 ha, fcport, &next_loopid);
2318 qla2x00_local_device_login(
2321 if (status == QLA_SUCCESS) {
2322 fcport->old_loop_id = fcport->loop_id;
2324 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2325 ha->host_no, fcport->loop_id));
2327 qla2x00_update_fcport(ha,
2329 } else if (status == 1) {
2330 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2331 /* retry the login again */
2332 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2334 fcport->login_retry, fcport->loop_id));
2336 fcport->login_retry = 0;
2339 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2342 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2346 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2347 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2349 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2350 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2353 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2355 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2359 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2361 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2364 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2367 qla2x00_loop_resync(ha);
2369 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2372 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2376 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2378 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2381 qla2x00_rescan_fcports(ha);
2383 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2388 if (!ha->interrupts_on)
2389 ha->isp_ops.enable_intrs(ha);
2391 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags))
2392 ha->isp_ops.beacon_blink(ha);
2395 } /* End of while(1) */
2397 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2400 * Make sure that nobody tries to wake us up again.
2408 qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2411 wake_up_process(ha->dpc_thread);
2416 * Processes asynchronous reset.
2419 * ha = adapter block pointer.
2422 qla2x00_rst_aen(scsi_qla_host_t *ha)
2424 if (ha->flags.online && !ha->flags.reset_active &&
2425 !atomic_read(&ha->loop_down_timer) &&
2426 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2428 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2431 * Issue marker command only when we are going to start
2434 ha->marker_needed = 1;
2435 } while (!atomic_read(&ha->loop_down_timer) &&
2436 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2441 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2443 struct scsi_cmnd *cmd = sp->cmd;
2445 if (sp->flags & SRB_DMA_VALID) {
2447 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2448 cmd->use_sg, cmd->sc_data_direction);
2449 } else if (cmd->request_bufflen) {
2450 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2451 cmd->request_bufflen, cmd->sc_data_direction);
2453 sp->flags &= ~SRB_DMA_VALID;
2459 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2461 struct scsi_cmnd *cmd = sp->cmd;
2463 qla2x00_sp_free_dma(ha, sp);
2465 mempool_free(sp, ha->srb_mempool);
2467 cmd->scsi_done(cmd);
2470 /**************************************************************************
2476 * Context: Interrupt
2477 ***************************************************************************/
2479 qla2x00_timer(scsi_qla_host_t *ha)
2481 unsigned long cpu_flags = 0;
2489 * Ports - Port down timer.
2491 * Whenever, a port is in the LOST state we start decrementing its port
2492 * down timer every second until it reaches zero. Once it reaches zero
2493 * the port it marked DEAD.
2496 list_for_each_entry(fcport, &ha->fcports, list) {
2497 if (fcport->port_type != FCT_TARGET)
2500 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2502 if (atomic_read(&fcport->port_down_timer) == 0)
2505 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2506 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2508 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2511 t, atomic_read(&fcport->port_down_timer)));
2514 } /* End of for fcport */
2517 /* Loop down handler. */
2518 if (atomic_read(&ha->loop_down_timer) > 0 &&
2519 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2521 if (atomic_read(&ha->loop_down_timer) ==
2522 ha->loop_down_abort_time) {
2524 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2525 "queues before time expire\n",
2528 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2529 atomic_set(&ha->loop_state, LOOP_DEAD);
2531 /* Schedule an ISP abort to return any tape commands. */
2532 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2533 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2537 sp = ha->outstanding_cmds[index];
2541 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2544 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2547 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2549 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2553 /* if the loop has been down for 4 minutes, reinit adapter */
2554 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2555 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2556 "restarting queues.\n",
2559 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2562 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2563 DEBUG(printk("scsi(%ld): Loop down - "
2566 qla_printk(KERN_WARNING, ha,
2567 "Loop down - aborting ISP.\n");
2569 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2572 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2574 atomic_read(&ha->loop_down_timer)));
2577 /* Check if beacon LED needs to be blinked */
2578 if (ha->beacon_blink_led == 1) {
2579 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags);
2583 /* Schedule the DPC routine if needed */
2584 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2585 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2586 test_bit(LOOP_RESET_NEEDED, &ha->dpc_flags) ||
2587 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) ||
2589 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
2590 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2591 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) ||
2592 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)))
2593 qla2xxx_wake_dpc(ha);
2595 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2598 /* XXX(hch): crude hack to emulate a down_timeout() */
2600 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2602 const unsigned int step = 100; /* msecs */
2603 unsigned int iterations = jiffies_to_msecs(timeout)/100;
2606 if (!down_trylock(sema))
2608 if (msleep_interruptible(step))
2610 } while (--iterations >= 0);
2615 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
2617 #define qla2x00_release_firmware() do { } while (0)
2618 #define qla2x00_pci_module_init() (0)
2619 #define qla2x00_pci_module_exit() do { } while (0)
2621 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
2623 /* Firmware interface routines. */
2626 #define FW_ISP21XX 0
2627 #define FW_ISP22XX 1
2628 #define FW_ISP2300 2
2629 #define FW_ISP2322 3
2630 #define FW_ISP24XX 4
2632 static DECLARE_MUTEX(qla_fw_lock);
2634 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
2635 { .name = "ql2100_fw.bin", .segs = { 0x1000, 0 }, },
2636 { .name = "ql2200_fw.bin", .segs = { 0x1000, 0 }, },
2637 { .name = "ql2300_fw.bin", .segs = { 0x800, 0 }, },
2638 { .name = "ql2322_fw.bin", .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2639 { .name = "ql2400_fw.bin", },
2643 qla2x00_request_firmware(scsi_qla_host_t *ha)
2645 struct fw_blob *blob;
2648 if (IS_QLA2100(ha)) {
2649 blob = &qla_fw_blobs[FW_ISP21XX];
2650 } else if (IS_QLA2200(ha)) {
2651 blob = &qla_fw_blobs[FW_ISP22XX];
2652 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2653 blob = &qla_fw_blobs[FW_ISP2300];
2654 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
2655 blob = &qla_fw_blobs[FW_ISP2322];
2656 } else if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
2657 blob = &qla_fw_blobs[FW_ISP24XX];
2664 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2665 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2666 "(%s).\n", ha->host_no, blob->name));
2678 qla2x00_release_firmware(void)
2683 for (idx = 0; idx < FW_BLOBS; idx++)
2684 if (qla_fw_blobs[idx].fw)
2685 release_firmware(qla_fw_blobs[idx].fw);
2689 static struct qla_board_info qla_board_tbl = {
2690 .drv_name = "qla2xxx",
2693 static struct pci_device_id qla2xxx_pci_tbl[] = {
2694 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100,
2695 PCI_ANY_ID, PCI_ANY_ID, },
2696 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200,
2697 PCI_ANY_ID, PCI_ANY_ID, },
2698 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300,
2699 PCI_ANY_ID, PCI_ANY_ID, },
2700 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312,
2701 PCI_ANY_ID, PCI_ANY_ID, },
2702 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322,
2703 PCI_ANY_ID, PCI_ANY_ID, },
2704 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312,
2705 PCI_ANY_ID, PCI_ANY_ID, },
2706 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322,
2707 PCI_ANY_ID, PCI_ANY_ID, },
2708 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422,
2709 PCI_ANY_ID, PCI_ANY_ID, },
2710 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432,
2711 PCI_ANY_ID, PCI_ANY_ID, },
2712 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
2713 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422,
2714 PCI_ANY_ID, PCI_ANY_ID, },
2715 { PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432,
2716 PCI_ANY_ID, PCI_ANY_ID, },
2720 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2722 static int __devinit
2723 qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2725 return qla2x00_probe_one(pdev, &qla_board_tbl);
2728 static void __devexit
2729 qla2xxx_remove_one(struct pci_dev *pdev)
2731 qla2x00_remove_one(pdev);
2734 static struct pci_driver qla2xxx_pci_driver = {
2737 .owner = THIS_MODULE,
2739 .id_table = qla2xxx_pci_tbl,
2740 .probe = qla2xxx_probe_one,
2741 .remove = __devexit_p(qla2xxx_remove_one),
2745 qla2x00_pci_module_init(void)
2747 return pci_module_init(&qla2xxx_pci_driver);
2751 qla2x00_pci_module_exit(void)
2753 pci_unregister_driver(&qla2xxx_pci_driver);
2759 * qla2x00_module_init - Module initialization.
2762 qla2x00_module_init(void)
2766 /* Allocate cache for SRBs. */
2767 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
2768 SLAB_HWCACHE_ALIGN, NULL, NULL);
2769 if (srb_cachep == NULL) {
2771 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2775 /* Derive version string. */
2776 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2777 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
2778 strcat(qla2x00_version_str, "-fw");
2781 strcat(qla2x00_version_str, "-debug");
2783 qla2xxx_transport_template =
2784 fc_attach_transport(&qla2xxx_transport_functions);
2785 if (!qla2xxx_transport_template)
2788 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2789 ret = qla2x00_pci_module_init();
2791 kmem_cache_destroy(srb_cachep);
2792 fc_release_transport(qla2xxx_transport_template);
2798 * qla2x00_module_exit - Module cleanup.
2801 qla2x00_module_exit(void)
2803 qla2x00_pci_module_exit();
2804 qla2x00_release_firmware();
2805 kmem_cache_destroy(srb_cachep);
2806 fc_release_transport(qla2xxx_transport_template);
2809 module_init(qla2x00_module_init);
2810 module_exit(qla2x00_module_exit);
2812 MODULE_AUTHOR("QLogic Corporation");
2813 #if defined(FC_TARGET_SUPPORT)
2814 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver (Target Support)");
2816 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2818 MODULE_LICENSE("GPL");
2819 MODULE_VERSION(QLA2XXX_VERSION);