2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/moduleparam.h>
22 #include <linux/vmalloc.h>
23 #include <linux/smp_lock.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi_tcq.h>
27 #include <scsi/scsicam.h>
28 #include <scsi/scsi_transport.h>
29 #include <scsi/scsi_transport_fc.h>
34 char qla2x00_version_str[40];
37 * SRB allocation cache
39 static kmem_cache_t *srb_cachep;
42 * Ioctl related information.
46 int ql2xlogintimeout = 20;
47 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
48 MODULE_PARM_DESC(ql2xlogintimeout,
49 "Login timeout value in seconds.");
51 int qlport_down_retry = 30;
52 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
53 MODULE_PARM_DESC(qlport_down_retry,
54 "Maximum number of command retries to a port that returns"
55 "a PORT-DOWN status.");
57 int ql2xplogiabsentdevice;
58 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
59 MODULE_PARM_DESC(ql2xplogiabsentdevice,
60 "Option to enable PLOGI to devices that are not present after "
61 "a Fabric scan. This is needed for several broken switches."
62 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
64 int ql2xenablezio = 0;
65 module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
66 MODULE_PARM_DESC(ql2xenablezio,
67 "Option to enable ZIO:If 1 then enable it otherwise"
68 " use the default set in the NVRAM."
69 " Default is 0 : disabled");
71 int ql2xintrdelaytimer = 10;
72 module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
73 MODULE_PARM_DESC(ql2xintrdelaytimer,
74 "ZIO: Waiting time for Firmware before it generates an "
75 "interrupt to the host to notify completion of request.");
77 int ql2xloginretrycount = 0;
78 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
79 MODULE_PARM_DESC(ql2xloginretrycount,
80 "Specify an alternate value for the NVRAM login retry count.");
83 module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
84 MODULE_PARM_DESC(ql2xfwloadbin,
85 "Load ISP2xxx firmware image via hotplug.");
87 static void qla2x00_free_device(scsi_qla_host_t *);
89 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
92 module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
93 MODULE_PARM_DESC(ql2xfdmienable,
94 "Enables FDMI registratons "
95 "Default is 0 - no FDMI. 1 - perfom FDMI.");
98 * SCSI host template entry points
100 static int qla2xxx_slave_configure(struct scsi_device * device);
101 static int qla2xxx_slave_alloc(struct scsi_device *);
102 static void qla2xxx_slave_destroy(struct scsi_device *);
103 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
104 void (*fn)(struct scsi_cmnd *));
105 static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
106 void (*fn)(struct scsi_cmnd *));
107 static int qla2xxx_eh_abort(struct scsi_cmnd *);
108 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
109 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
110 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
111 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
112 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
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,
120 .queuecommand = qla2x00_queuecommand,
122 .eh_abort_handler = qla2xxx_eh_abort,
123 .eh_device_reset_handler = qla2xxx_eh_device_reset,
124 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
125 .eh_host_reset_handler = qla2xxx_eh_host_reset,
127 .slave_configure = qla2xxx_slave_configure,
129 .slave_alloc = qla2xxx_slave_alloc,
130 .slave_destroy = qla2xxx_slave_destroy,
131 .change_queue_depth = qla2x00_change_queue_depth,
132 .change_queue_type = qla2x00_change_queue_type,
135 .use_clustering = ENABLE_CLUSTERING,
136 .sg_tablesize = SG_ALL,
139 * The RISC allows for each command to transfer (2^32-1) bytes of data,
140 * which equates to 0x800000 sectors.
142 .max_sectors = 0xFFFF,
143 .shost_attrs = qla2x00_host_attrs,
146 static struct scsi_host_template qla24xx_driver_template = {
147 .module = THIS_MODULE,
149 .queuecommand = qla24xx_queuecommand,
151 .eh_abort_handler = qla2xxx_eh_abort,
152 .eh_device_reset_handler = qla2xxx_eh_device_reset,
153 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
154 .eh_host_reset_handler = qla2xxx_eh_host_reset,
156 .slave_configure = qla2xxx_slave_configure,
158 .slave_alloc = qla2xxx_slave_alloc,
159 .slave_destroy = qla2xxx_slave_destroy,
160 .change_queue_depth = qla2x00_change_queue_depth,
161 .change_queue_type = qla2x00_change_queue_type,
164 .use_clustering = ENABLE_CLUSTERING,
165 .sg_tablesize = SG_ALL,
167 .max_sectors = 0xFFFF,
168 .shost_attrs = qla2x00_host_attrs,
171 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
173 /* TODO Convert to inlines
177 #define WATCH_INTERVAL 1 /* number of seconds */
179 static void qla2x00_timer(scsi_qla_host_t *);
181 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
182 void *, unsigned long);
183 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
184 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
187 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
189 init_timer(&ha->timer);
190 ha->timer.expires = jiffies + interval * HZ;
191 ha->timer.data = (unsigned long)ha;
192 ha->timer.function = (void (*)(unsigned long))func;
193 add_timer(&ha->timer);
194 ha->timer_active = 1;
198 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
200 mod_timer(&ha->timer, jiffies + interval * HZ);
203 static __inline__ void
204 qla2x00_stop_timer(scsi_qla_host_t *ha)
206 del_timer_sync(&ha->timer);
207 ha->timer_active = 0;
210 static int qla2x00_do_dpc(void *data);
212 static void qla2x00_rst_aen(scsi_qla_host_t *);
214 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
215 static void qla2x00_mem_free(scsi_qla_host_t *ha);
216 static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
217 static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
218 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
219 void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
221 /* -------------------------------------------------------------------------- */
224 qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
226 static char *pci_bus_modes[] = {
227 "33", "66", "100", "133",
232 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
235 strcat(str, pci_bus_modes[pci_bus]);
237 pci_bus = (ha->pci_attr & BIT_8) >> 8;
239 strcat(str, pci_bus_modes[pci_bus]);
241 strcat(str, " MHz)");
247 qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
249 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
253 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
256 uint16_t pcie_lstat, lspeed, lwidth;
259 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
260 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
261 lwidth = (pcie_lstat &
262 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
264 strcpy(str, "PCIe (");
266 strcat(str, "2.5Gb/s ");
268 strcat(str, "<unknown> ");
269 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
276 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
277 if (pci_bus == 0 || pci_bus == 8) {
279 strcat(str, pci_bus_modes[pci_bus >> 3]);
283 strcat(str, "Mode 2");
285 strcat(str, "Mode 1");
287 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
289 strcat(str, " MHz)");
295 qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
299 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
300 ha->fw_minor_version,
301 ha->fw_subminor_version);
303 if (ha->fw_attributes & BIT_9) {
308 switch (ha->fw_attributes & 0xFF) {
322 sprintf(un_str, "(%x)", ha->fw_attributes);
326 if (ha->fw_attributes & 0x100)
333 qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
335 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
336 ha->fw_minor_version,
337 ha->fw_subminor_version);
339 if (ha->fw_attributes & BIT_0)
340 strcat(str, "[Class 2] ");
341 if (ha->fw_attributes & BIT_1)
342 strcat(str, "[IP] ");
343 if (ha->fw_attributes & BIT_2)
344 strcat(str, "[Multi-ID] ");
345 if (ha->fw_attributes & BIT_13)
346 strcat(str, "[Experimental]");
350 static inline srb_t *
351 qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
352 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
356 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
360 atomic_set(&sp->ref_count, 1);
365 CMD_SP(cmd) = (void *)sp;
366 cmd->scsi_done = done;
372 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
374 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
375 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
380 cmd->result = DID_NO_CONNECT << 16;
381 goto qc_fail_command;
384 if (atomic_read(&fcport->state) != FCS_ONLINE) {
385 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
386 atomic_read(&ha->loop_state) == LOOP_DEAD) {
387 cmd->result = DID_NO_CONNECT << 16;
388 goto qc_fail_command;
393 spin_unlock_irq(ha->host->host_lock);
395 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
397 goto qc_host_busy_lock;
399 rval = qla2x00_start_scsi(sp);
400 if (rval != QLA_SUCCESS)
401 goto qc_host_busy_free_sp;
403 /* Manage unprocessed RIO/ZIO commands in response queue. */
404 if (ha->flags.online && ha->flags.process_response_queue &&
405 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
408 spin_lock_irqsave(&ha->hardware_lock, flags);
409 qla2x00_process_response_queue(ha);
410 spin_unlock_irqrestore(&ha->hardware_lock, flags);
413 spin_lock_irq(ha->host->host_lock);
417 qc_host_busy_free_sp:
418 qla2x00_sp_free_dma(ha, sp);
419 mempool_free(sp, ha->srb_mempool);
422 spin_lock_irq(ha->host->host_lock);
425 return SCSI_MLQUEUE_HOST_BUSY;
435 qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
437 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
438 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
443 cmd->result = DID_NO_CONNECT << 16;
444 goto qc24_fail_command;
447 if (atomic_read(&fcport->state) != FCS_ONLINE) {
448 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
449 atomic_read(&ha->loop_state) == LOOP_DEAD) {
450 cmd->result = DID_NO_CONNECT << 16;
451 goto qc24_fail_command;
456 spin_unlock_irq(ha->host->host_lock);
458 sp = qla2x00_get_new_sp(ha, fcport, cmd, done);
460 goto qc24_host_busy_lock;
462 rval = qla24xx_start_scsi(sp);
463 if (rval != QLA_SUCCESS)
464 goto qc24_host_busy_free_sp;
466 spin_lock_irq(ha->host->host_lock);
470 qc24_host_busy_free_sp:
471 qla2x00_sp_free_dma(ha, sp);
472 mempool_free(sp, ha->srb_mempool);
475 spin_lock_irq(ha->host->host_lock);
478 return SCSI_MLQUEUE_HOST_BUSY;
488 * qla2x00_eh_wait_on_command
489 * Waits for the command to be returned by the Firmware for some
493 * ha = actual ha whose done queue will contain the command
494 * returned by firmware.
495 * cmd = Scsi Command to wait on.
496 * flag = Abort/Reset(Bus or Device Reset)
503 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
505 #define ABORT_POLLING_PERIOD 1000
506 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
507 unsigned long wait_iter = ABORT_WAIT_ITER;
508 int ret = QLA_SUCCESS;
510 while (CMD_SP(cmd)) {
511 msleep(ABORT_POLLING_PERIOD);
517 ret = QLA_FUNCTION_FAILED;
523 * qla2x00_wait_for_hba_online
524 * Wait till the HBA is online after going through
525 * <= MAX_RETRIES_OF_ISP_ABORT or
526 * finally HBA is disabled ie marked offline
529 * ha - pointer to host adapter structure
532 * Does context switching-Release SPIN_LOCK
533 * (if any) before calling this routine.
536 * Success (Adapter is online) : 0
537 * Failed (Adapter is offline/disabled) : 1
540 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
543 unsigned long wait_online;
545 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
546 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
547 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
548 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
549 ha->dpc_active) && time_before(jiffies, wait_online)) {
553 if (ha->flags.online)
554 return_status = QLA_SUCCESS;
556 return_status = QLA_FUNCTION_FAILED;
558 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
560 return (return_status);
564 * qla2x00_wait_for_loop_ready
565 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
566 * to be in LOOP_READY state.
568 * ha - pointer to host adapter structure
571 * Does context switching-Release SPIN_LOCK
572 * (if any) before calling this routine.
576 * Success (LOOP_READY) : 0
577 * Failed (LOOP_NOT_READY) : 1
580 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
582 int return_status = QLA_SUCCESS;
583 unsigned long loop_timeout ;
585 /* wait for 5 min at the max for loop to be ready */
586 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
588 while ((!atomic_read(&ha->loop_down_timer) &&
589 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
590 atomic_read(&ha->loop_state) != LOOP_READY) {
592 if (time_after_eq(jiffies, loop_timeout)) {
593 return_status = QLA_FUNCTION_FAILED;
597 return (return_status);
600 /**************************************************************************
604 * The abort function will abort the specified command.
607 * cmd = Linux SCSI command packet to be aborted.
610 * Either SUCCESS or FAILED.
613 **************************************************************************/
615 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
617 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
620 unsigned int id, lun;
621 unsigned long serial;
629 id = cmd->device->id;
630 lun = cmd->device->lun;
631 serial = cmd->serial_number;
633 /* Check active list for command command. */
634 spin_lock_irqsave(&ha->hardware_lock, flags);
635 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
636 sp = ha->outstanding_cmds[i];
644 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
645 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
647 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
649 spin_unlock_irqrestore(&ha->hardware_lock, flags);
650 if (ha->isp_ops.abort_command(ha, sp)) {
651 DEBUG2(printk("%s(%ld): abort_command "
652 "mbx failed.\n", __func__, ha->host_no));
654 DEBUG3(printk("%s(%ld): abort_command "
655 "mbx success.\n", __func__, ha->host_no));
658 spin_lock_irqsave(&ha->hardware_lock, flags);
662 spin_unlock_irqrestore(&ha->hardware_lock, flags);
664 /* Wait for the command to be returned. */
665 if (ret == SUCCESS) {
666 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
667 qla_printk(KERN_ERR, ha,
668 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
669 "%x.\n", ha->host_no, id, lun, serial, ret);
673 qla_printk(KERN_INFO, ha,
674 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
675 id, lun, serial, ret);
680 /**************************************************************************
681 * qla2x00_eh_wait_for_pending_target_commands
684 * Waits for all the commands to come back from the specified target.
687 * ha - pointer to scsi_qla_host structure.
690 * Either SUCCESS or FAILED.
693 **************************************************************************/
695 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
700 struct scsi_cmnd *cmd;
706 * Waiting for all commands for the designated target in the active
709 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711 sp = ha->outstanding_cmds[cnt];
714 spin_unlock_irqrestore(&ha->hardware_lock, flags);
715 if (cmd->device->id == t) {
716 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
722 spin_unlock_irqrestore(&ha->hardware_lock, flags);
729 /**************************************************************************
730 * qla2xxx_eh_device_reset
733 * The device reset function will reset the target and abort any
734 * executing commands.
736 * NOTE: The use of SP is undefined within this context. Do *NOT*
737 * attempt to use this value, even if you determine it is
741 * cmd = Linux SCSI command packet of the command that cause the
745 * SUCCESS/FAILURE (defined as macro in scsi.h).
747 **************************************************************************/
749 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
751 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
752 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
755 unsigned int id, lun;
756 unsigned long serial;
760 id = cmd->device->id;
761 lun = cmd->device->lun;
762 serial = cmd->serial_number;
764 sp = (srb_t *) CMD_SP(cmd);
768 qla_printk(KERN_INFO, ha,
769 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
771 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
772 goto eh_dev_reset_done;
774 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
775 if (qla2x00_device_reset(ha, fcport) == 0)
778 #if defined(LOGOUT_AFTER_DEVICE_RESET)
779 if (ret == SUCCESS) {
780 if (fcport->flags & FC_FABRIC_DEVICE) {
781 ha->isp_ops.fabric_logout(ha, fcport->loop_id);
782 qla2x00_mark_device_lost(ha, fcport);
787 DEBUG2(printk(KERN_INFO
788 "%s failed: loop not ready\n",__func__);)
792 DEBUG3(printk("%s(%ld): device reset failed\n",
793 __func__, ha->host_no));
794 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
797 goto eh_dev_reset_done;
801 * If we are coming down the EH path, wait for all commands to
802 * complete for the device.
804 if (cmd->device->host->eh_active) {
805 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
809 DEBUG3(printk("%s(%ld): failed while waiting for "
810 "commands\n", __func__, ha->host_no));
811 qla_printk(KERN_INFO, ha,
812 "%s: failed while waiting for commands\n",
815 goto eh_dev_reset_done;
819 qla_printk(KERN_INFO, ha,
820 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
826 /**************************************************************************
827 * qla2x00_eh_wait_for_pending_commands
830 * Waits for all the commands to come back from the specified host.
833 * ha - pointer to scsi_qla_host structure.
840 **************************************************************************/
842 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
847 struct scsi_cmnd *cmd;
853 * Waiting for all commands for the designated target in the active
856 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
857 spin_lock_irqsave(&ha->hardware_lock, flags);
858 sp = ha->outstanding_cmds[cnt];
861 spin_unlock_irqrestore(&ha->hardware_lock, flags);
862 status = qla2x00_eh_wait_on_command(ha, cmd);
867 spin_unlock_irqrestore(&ha->hardware_lock, flags);
874 /**************************************************************************
875 * qla2xxx_eh_bus_reset
878 * The bus reset function will reset the bus and abort any executing
882 * cmd = Linux SCSI command packet of the command that cause the
886 * SUCCESS/FAILURE (defined as macro in scsi.h).
888 **************************************************************************/
890 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
892 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
893 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
896 unsigned int id, lun;
897 unsigned long serial;
901 id = cmd->device->id;
902 lun = cmd->device->lun;
903 serial = cmd->serial_number;
905 sp = (srb_t *) CMD_SP(cmd);
909 qla_printk(KERN_INFO, ha,
910 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
912 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
913 DEBUG2(printk("%s failed:board disabled\n",__func__));
914 goto eh_bus_reset_done;
917 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
918 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
922 goto eh_bus_reset_done;
924 /* Waiting for our command in done_queue to be returned to OS.*/
925 if (cmd->device->host->eh_active)
926 if (!qla2x00_eh_wait_for_pending_commands(ha))
930 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
931 (ret == FAILED) ? "failed" : "succeded");
936 /**************************************************************************
937 * qla2xxx_eh_host_reset
940 * The reset function will reset the Adapter.
943 * cmd = Linux SCSI command packet of the command that cause the
947 * Either SUCCESS or FAILED.
950 **************************************************************************/
952 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
954 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
955 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
958 unsigned int id, lun;
959 unsigned long serial;
963 id = cmd->device->id;
964 lun = cmd->device->lun;
965 serial = cmd->serial_number;
967 sp = (srb_t *) CMD_SP(cmd);
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, &ha->dpc_flags);
987 if (qla2x00_abort_isp(ha)) {
988 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
989 /* failed. schedule dpc to try */
990 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
992 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
993 goto eh_host_reset_lock;
995 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
997 /* Waiting for our command in done_queue to be returned to OS.*/
998 if (qla2x00_eh_wait_for_pending_commands(ha))
1002 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1003 (ret == FAILED) ? "failed" : "succeded");
1009 * qla2x00_loop_reset
1013 * ha = adapter block pointer.
1019 qla2x00_loop_reset(scsi_qla_host_t *ha)
1021 int status = QLA_SUCCESS;
1022 struct fc_port *fcport;
1024 if (ha->flags.enable_lip_reset) {
1025 status = qla2x00_lip_reset(ha);
1028 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1029 list_for_each_entry(fcport, &ha->fcports, list) {
1030 if (fcport->port_type != FCT_TARGET)
1033 status = qla2x00_device_reset(ha, fcport);
1034 if (status != QLA_SUCCESS)
1039 if (status == QLA_SUCCESS &&
1040 ((!ha->flags.enable_target_reset &&
1041 !ha->flags.enable_lip_reset) ||
1042 ha->flags.enable_lip_full_login)) {
1044 status = qla2x00_full_login_lip(ha);
1047 /* Issue marker command only when we are going to start the I/O */
1048 ha->marker_needed = 1;
1052 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1057 DEBUG3(printk("%s(%ld): exiting normally.\n",
1066 * qla2x00_device_reset
1067 * Issue bus device reset message to the target.
1070 * ha = adapter block pointer.
1072 * TARGET_QUEUE_LOCK must be released.
1073 * ADAPTER_STATE_LOCK must be released.
1079 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1081 /* Abort Target command will clear Reservation */
1082 return ha->isp_ops.abort_target(reset_fcport);
1086 qla2xxx_slave_alloc(struct scsi_device *sdev)
1088 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1093 sdev->hostdata = rport->dd_data;
1099 qla2xxx_slave_configure(struct scsi_device *sdev)
1101 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1102 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1104 if (sdev->tagged_supported)
1105 scsi_activate_tcq(sdev, 32);
1107 scsi_deactivate_tcq(sdev, 32);
1109 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1115 qla2xxx_slave_destroy(struct scsi_device *sdev)
1117 sdev->hostdata = NULL;
1121 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1123 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1124 return sdev->queue_depth;
1128 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1130 if (sdev->tagged_supported) {
1131 scsi_set_tag_type(sdev, tag_type);
1133 scsi_activate_tcq(sdev, sdev->queue_depth);
1135 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1143 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1146 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1147 * supported addressing method.
1150 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1152 /* Assume a 32bit DMA mask. */
1153 ha->flags.enable_64bit_addressing = 0;
1155 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1156 /* Any upper-dword bits set? */
1157 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1158 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1159 /* Ok, a 64bit DMA mask is applicable. */
1160 ha->flags.enable_64bit_addressing = 1;
1161 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1162 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
1167 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1168 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
1172 qla2x00_iospace_config(scsi_qla_host_t *ha)
1174 unsigned long pio, pio_len, pio_flags;
1175 unsigned long mmio, mmio_len, mmio_flags;
1177 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1178 pio = pci_resource_start(ha->pdev, 0);
1179 pio_len = pci_resource_len(ha->pdev, 0);
1180 pio_flags = pci_resource_flags(ha->pdev, 0);
1181 if (pio_flags & IORESOURCE_IO) {
1182 if (pio_len < MIN_IOBASE_LEN) {
1183 qla_printk(KERN_WARNING, ha,
1184 "Invalid PCI I/O region size (%s)...\n",
1185 pci_name(ha->pdev));
1189 qla_printk(KERN_WARNING, ha,
1190 "region #0 not a PIO resource (%s)...\n",
1191 pci_name(ha->pdev));
1195 /* Use MMIO operations for all accesses. */
1196 mmio = pci_resource_start(ha->pdev, 1);
1197 mmio_len = pci_resource_len(ha->pdev, 1);
1198 mmio_flags = pci_resource_flags(ha->pdev, 1);
1200 if (!(mmio_flags & IORESOURCE_MEM)) {
1201 qla_printk(KERN_ERR, ha,
1202 "region #0 not an MMIO resource (%s), aborting\n",
1203 pci_name(ha->pdev));
1204 goto iospace_error_exit;
1206 if (mmio_len < MIN_IOBASE_LEN) {
1207 qla_printk(KERN_ERR, ha,
1208 "Invalid PCI mem region size (%s), aborting\n",
1209 pci_name(ha->pdev));
1210 goto iospace_error_exit;
1213 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1214 qla_printk(KERN_WARNING, ha,
1215 "Failed to reserve PIO/MMIO regions (%s)\n",
1216 pci_name(ha->pdev));
1218 goto iospace_error_exit;
1221 ha->pio_address = pio;
1222 ha->pio_length = pio_len;
1223 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1225 qla_printk(KERN_ERR, ha,
1226 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1228 goto iospace_error_exit;
1238 qla2x00_enable_intrs(scsi_qla_host_t *ha)
1240 unsigned long flags = 0;
1241 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1243 spin_lock_irqsave(&ha->hardware_lock, flags);
1244 ha->interrupts_on = 1;
1245 /* enable risc and host interrupts */
1246 WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC);
1247 RD_REG_WORD(®->ictrl);
1248 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1253 qla2x00_disable_intrs(scsi_qla_host_t *ha)
1255 unsigned long flags = 0;
1256 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1258 spin_lock_irqsave(&ha->hardware_lock, flags);
1259 ha->interrupts_on = 0;
1260 /* disable risc and host interrupts */
1261 WRT_REG_WORD(®->ictrl, 0);
1262 RD_REG_WORD(®->ictrl);
1263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1267 qla24xx_enable_intrs(scsi_qla_host_t *ha)
1269 unsigned long flags = 0;
1270 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1272 spin_lock_irqsave(&ha->hardware_lock, flags);
1273 ha->interrupts_on = 1;
1274 WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT);
1275 RD_REG_DWORD(®->ictrl);
1276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1280 qla24xx_disable_intrs(scsi_qla_host_t *ha)
1282 unsigned long flags = 0;
1283 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1285 spin_lock_irqsave(&ha->hardware_lock, flags);
1286 ha->interrupts_on = 0;
1287 WRT_REG_DWORD(®->ictrl, 0);
1288 RD_REG_DWORD(®->ictrl);
1289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1293 * PCI driver interface
1295 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1298 device_reg_t __iomem *reg;
1299 struct Scsi_Host *host;
1300 scsi_qla_host_t *ha;
1301 unsigned long flags = 0;
1302 unsigned long wait_switch = 0;
1307 if (pci_enable_device(pdev))
1310 host = scsi_host_alloc(brd_info->sht ? brd_info->sht:
1311 &qla2x00_driver_template, sizeof(scsi_qla_host_t));
1314 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1315 goto probe_disable_device;
1318 /* Clear our data area */
1319 ha = (scsi_qla_host_t *)host->hostdata;
1320 memset(ha, 0, sizeof(scsi_qla_host_t));
1324 ha->host_no = host->host_no;
1325 ha->brd_info = brd_info;
1326 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1328 /* Configure PCI I/O space */
1329 ret = qla2x00_iospace_config(ha);
1333 qla_printk(KERN_INFO, ha,
1334 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1335 pdev->irq, ha->iobase);
1337 spin_lock_init(&ha->hardware_lock);
1339 ha->prev_topology = 0;
1340 ha->ports = MAX_BUSES;
1341 ha->init_cb_size = sizeof(init_cb_t);
1342 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
1344 /* Assign ISP specific operations. */
1345 ha->isp_ops.pci_config = qla2100_pci_config;
1346 ha->isp_ops.reset_chip = qla2x00_reset_chip;
1347 ha->isp_ops.chip_diag = qla2x00_chip_diag;
1348 ha->isp_ops.config_rings = qla2x00_config_rings;
1349 ha->isp_ops.reset_adapter = qla2x00_reset_adapter;
1350 ha->isp_ops.nvram_config = qla2x00_nvram_config;
1351 ha->isp_ops.update_fw_options = qla2x00_update_fw_options;
1352 ha->isp_ops.load_risc = qla2x00_load_risc;
1353 ha->isp_ops.pci_info_str = qla2x00_pci_info_str;
1354 ha->isp_ops.fw_version_str = qla2x00_fw_version_str;
1355 ha->isp_ops.intr_handler = qla2100_intr_handler;
1356 ha->isp_ops.enable_intrs = qla2x00_enable_intrs;
1357 ha->isp_ops.disable_intrs = qla2x00_disable_intrs;
1358 ha->isp_ops.abort_command = qla2x00_abort_command;
1359 ha->isp_ops.abort_target = qla2x00_abort_target;
1360 ha->isp_ops.fabric_login = qla2x00_login_fabric;
1361 ha->isp_ops.fabric_logout = qla2x00_fabric_logout;
1362 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1363 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1364 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
1365 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
1366 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1367 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
1368 ha->isp_ops.fw_dump = qla2100_fw_dump;
1369 ha->isp_ops.ascii_fw_dump = qla2100_ascii_fw_dump;
1370 if (IS_QLA2100(ha)) {
1371 host->max_id = MAX_TARGETS_2100;
1372 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1373 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1374 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1375 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1376 host->sg_tablesize = 32;
1377 ha->gid_list_info_size = 4;
1378 } else if (IS_QLA2200(ha)) {
1379 host->max_id = MAX_TARGETS_2200;
1380 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1381 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1382 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1383 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1384 ha->gid_list_info_size = 4;
1385 } else if (IS_QLA23XX(ha)) {
1386 host->max_id = MAX_TARGETS_2200;
1387 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1388 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1389 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1390 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1391 ha->isp_ops.pci_config = qla2300_pci_config;
1392 ha->isp_ops.intr_handler = qla2300_intr_handler;
1393 ha->isp_ops.fw_dump = qla2300_fw_dump;
1394 ha->isp_ops.ascii_fw_dump = qla2300_ascii_fw_dump;
1395 ha->gid_list_info_size = 6;
1396 } else if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1397 host->max_id = MAX_TARGETS_2200;
1398 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1399 ha->request_q_length = REQUEST_ENTRY_CNT_24XX;
1400 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1401 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1402 ha->init_cb_size = sizeof(struct init_cb_24xx);
1403 ha->mgmt_svr_loop_id = 10;
1404 ha->isp_ops.pci_config = qla24xx_pci_config;
1405 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1406 ha->isp_ops.chip_diag = qla24xx_chip_diag;
1407 ha->isp_ops.config_rings = qla24xx_config_rings;
1408 ha->isp_ops.reset_adapter = qla24xx_reset_adapter;
1409 ha->isp_ops.nvram_config = qla24xx_nvram_config;
1410 ha->isp_ops.update_fw_options = qla24xx_update_fw_options;
1411 ha->isp_ops.load_risc = qla24xx_load_risc_flash;
1413 ha->isp_ops.load_risc = qla24xx_load_risc_hotplug;
1414 ha->isp_ops.pci_info_str = qla24xx_pci_info_str;
1415 ha->isp_ops.fw_version_str = qla24xx_fw_version_str;
1416 ha->isp_ops.intr_handler = qla24xx_intr_handler;
1417 ha->isp_ops.enable_intrs = qla24xx_enable_intrs;
1418 ha->isp_ops.disable_intrs = qla24xx_disable_intrs;
1419 ha->isp_ops.abort_command = qla24xx_abort_command;
1420 ha->isp_ops.abort_target = qla24xx_abort_target;
1421 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1422 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1423 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
1424 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
1425 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1426 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1427 ha->isp_ops.fw_dump = qla24xx_fw_dump;
1428 ha->isp_ops.ascii_fw_dump = qla24xx_ascii_fw_dump;
1429 ha->gid_list_info_size = 8;
1431 host->can_queue = ha->request_q_length + 128;
1433 /* load the F/W, read paramaters, and init the H/W */
1434 ha->instance = num_hosts;
1436 init_MUTEX(&ha->mbx_cmd_sem);
1437 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1439 INIT_LIST_HEAD(&ha->list);
1440 INIT_LIST_HEAD(&ha->fcports);
1441 INIT_LIST_HEAD(&ha->rscn_fcports);
1444 * These locks are used to prevent more than one CPU
1445 * from modifying the queue at the same time. The
1446 * higher level "host_lock" will reduce most
1447 * contention for these locks.
1449 spin_lock_init(&ha->mbx_reg_lock);
1452 init_completion(&ha->dpc_inited);
1453 init_completion(&ha->dpc_exited);
1455 qla2x00_config_dma_addressing(ha);
1456 if (qla2x00_mem_alloc(ha)) {
1457 qla_printk(KERN_WARNING, ha,
1458 "[ERROR] Failed to allocate memory for adapter\n");
1464 if (qla2x00_initialize_adapter(ha) &&
1465 !(ha->device_flags & DFLG_NO_CABLE)) {
1467 qla_printk(KERN_WARNING, ha,
1468 "Failed to initialize adapter\n");
1470 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1471 "Adapter flags %x.\n",
1472 ha->host_no, ha->device_flags));
1479 * Startup the kernel thread for this host adapter
1481 ha->dpc_should_die = 0;
1482 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1483 if (ha->dpc_pid < 0) {
1484 qla_printk(KERN_WARNING, ha,
1485 "Unable to start DPC thread!\n");
1490 wait_for_completion(&ha->dpc_inited);
1492 host->this_id = 255;
1493 host->cmd_per_lun = 3;
1494 host->unique_id = ha->instance;
1495 host->max_cmd_len = MAX_CMDSZ;
1496 host->max_channel = ha->ports - 1;
1497 host->max_lun = MAX_LUNS;
1498 host->transportt = qla2xxx_transport_template;
1500 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler,
1501 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1503 qla_printk(KERN_WARNING, ha,
1504 "Failed to reserve interrupt %d already in use.\n",
1508 host->irq = pdev->irq;
1510 /* Initialized the timer */
1511 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1513 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1516 ha->isp_ops.disable_intrs(ha);
1518 spin_lock_irqsave(&ha->hardware_lock, flags);
1520 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1521 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_HOST_INT);
1522 WRT_REG_DWORD(®->isp24.hccr, HCCRX_CLR_RISC_INT);
1524 WRT_REG_WORD(®->isp.semaphore, 0);
1525 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_RISC_INT);
1526 WRT_REG_WORD(®->isp.hccr, HCCR_CLR_HOST_INT);
1528 /* Enable proper parity */
1529 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1532 WRT_REG_WORD(®->isp.hccr,
1533 (HCCR_ENABLE_PARITY + 0x1));
1535 /* SRAM, Instruction RAM and GP RAM parity */
1536 WRT_REG_WORD(®->isp.hccr,
1537 (HCCR_ENABLE_PARITY + 0x7));
1540 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1542 ha->isp_ops.enable_intrs(ha);
1546 * Wait around max loop_reset_delay secs for the devices to come
1547 * on-line. We don't want Linux scanning before we are ready.
1550 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1551 time_before(jiffies,wait_switch) &&
1552 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1553 && (ha->device_flags & SWITCH_FOUND) ;) {
1555 qla2x00_check_fabric_devices(ha);
1560 pci_set_drvdata(pdev, ha);
1561 ha->flags.init_done = 1;
1564 ret = scsi_add_host(host, &pdev->dev);
1568 qla2x00_alloc_sysfs_attr(ha);
1570 qla2x00_init_host_attr(ha);
1572 qla_printk(KERN_INFO, ha, "\n"
1573 " QLogic Fibre Channel HBA Driver: %s\n"
1575 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1576 ha->model_number, ha->model_desc ? ha->model_desc: "",
1577 ha->brd_info->isp_name, ha->isp_ops.pci_info_str(ha, pci_info),
1578 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+': '-',
1579 ha->host_no, ha->isp_ops.fw_version_str(ha, fw_str));
1581 /* Go with fc_rport registration. */
1582 list_for_each_entry(fcport, &ha->fcports, list)
1583 qla2x00_reg_remote_port(ha, fcport);
1588 qla2x00_free_device(ha);
1590 scsi_host_put(host);
1592 probe_disable_device:
1593 pci_disable_device(pdev);
1598 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1600 void qla2x00_remove_one(struct pci_dev *pdev)
1602 scsi_qla_host_t *ha;
1604 ha = pci_get_drvdata(pdev);
1606 qla2x00_free_sysfs_attr(ha);
1608 fc_remove_host(ha->host);
1610 scsi_remove_host(ha->host);
1612 qla2x00_free_device(ha);
1614 scsi_host_put(ha->host);
1616 pci_set_drvdata(pdev, NULL);
1618 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1621 qla2x00_free_device(scsi_qla_host_t *ha)
1625 /* Abort any outstanding IO descriptors. */
1626 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1627 qla2x00_cancel_io_descriptors(ha);
1629 /* turn-off interrupts on the card */
1630 if (ha->interrupts_on)
1631 ha->isp_ops.disable_intrs(ha);
1634 if (ha->timer_active)
1635 qla2x00_stop_timer(ha);
1637 /* Kill the kernel thread for this host */
1638 if (ha->dpc_pid >= 0) {
1639 ha->dpc_should_die = 1;
1641 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1643 qla_printk(KERN_ERR, ha,
1644 "Unable to signal DPC thread -- (%d)\n", ret);
1646 /* TODO: SOMETHING MORE??? */
1648 wait_for_completion(&ha->dpc_exited);
1652 qla2x00_mem_free(ha);
1655 ha->flags.online = 0;
1657 /* Detach interrupts */
1659 free_irq(ha->pdev->irq, ha);
1661 /* release io space registers */
1663 iounmap(ha->iobase);
1664 pci_release_regions(ha->pdev);
1666 pci_disable_device(ha->pdev);
1670 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1672 * Input: ha = adapter block pointer. fcport = port structure pointer.
1678 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1681 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1682 fc_remote_port_block(fcport->rport);
1684 * We may need to retry the login, so don't change the state of the
1685 * port but do the retries.
1687 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1688 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1693 if (fcport->login_retry == 0) {
1694 fcport->login_retry = ha->login_retry_count;
1695 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1697 DEBUG(printk("scsi(%ld): Port login retry: "
1698 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1699 "id = 0x%04x retry cnt=%d\n",
1701 fcport->port_name[0],
1702 fcport->port_name[1],
1703 fcport->port_name[2],
1704 fcport->port_name[3],
1705 fcport->port_name[4],
1706 fcport->port_name[5],
1707 fcport->port_name[6],
1708 fcport->port_name[7],
1710 fcport->login_retry));
1715 * qla2x00_mark_all_devices_lost
1716 * Updates fcport state when device goes offline.
1719 * ha = adapter block pointer.
1720 * fcport = port structure pointer.
1728 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
1732 list_for_each_entry(fcport, &ha->fcports, list) {
1733 if (fcport->port_type != FCT_TARGET)
1737 * No point in marking the device as lost, if the device is
1740 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1742 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1743 fc_remote_port_block(fcport->rport);
1744 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1750 * Allocates adapter memory.
1757 qla2x00_mem_alloc(scsi_qla_host_t *ha)
1765 * This will loop only once if everything goes well, else some
1766 * number of retries will be performed to get around a kernel
1767 * bug where available mem is not allocated until after a
1768 * little delay and a retry.
1770 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
1771 (ha->request_q_length + 1) * sizeof(request_t),
1772 &ha->request_dma, GFP_KERNEL);
1773 if (ha->request_ring == NULL) {
1774 qla_printk(KERN_WARNING, ha,
1775 "Memory Allocation failed - request_ring\n");
1777 qla2x00_mem_free(ha);
1783 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1784 (ha->response_q_length + 1) * sizeof(response_t),
1785 &ha->response_dma, GFP_KERNEL);
1786 if (ha->response_ring == NULL) {
1787 qla_printk(KERN_WARNING, ha,
1788 "Memory Allocation failed - response_ring\n");
1790 qla2x00_mem_free(ha);
1796 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1797 &ha->gid_list_dma, GFP_KERNEL);
1798 if (ha->gid_list == NULL) {
1799 qla_printk(KERN_WARNING, ha,
1800 "Memory Allocation failed - gid_list\n");
1802 qla2x00_mem_free(ha);
1808 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
1809 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
1810 if (ha->rlc_rsp == NULL) {
1811 qla_printk(KERN_WARNING, ha,
1812 "Memory Allocation failed - rlc");
1814 qla2x00_mem_free(ha);
1820 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
1821 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
1822 DMA_POOL_SIZE, 8, 0);
1823 if (ha->s_dma_pool == NULL) {
1824 qla_printk(KERN_WARNING, ha,
1825 "Memory Allocation failed - s_dma_pool\n");
1827 qla2x00_mem_free(ha);
1833 /* get consistent memory allocated for init control block */
1834 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1836 if (ha->init_cb == NULL) {
1837 qla_printk(KERN_WARNING, ha,
1838 "Memory Allocation failed - init_cb\n");
1840 qla2x00_mem_free(ha);
1845 memset(ha->init_cb, 0, ha->init_cb_size);
1847 /* Get consistent memory allocated for Get Port Database cmd */
1848 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1849 &ha->iodesc_pd_dma);
1850 if (ha->iodesc_pd == NULL) {
1852 qla_printk(KERN_WARNING, ha,
1853 "Memory Allocation failed - iodesc_pd\n");
1855 qla2x00_mem_free(ha);
1860 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
1862 /* Allocate ioctl related memory. */
1863 if (qla2x00_alloc_ioctl_mem(ha)) {
1864 qla_printk(KERN_WARNING, ha,
1865 "Memory Allocation failed - ioctl_mem\n");
1867 qla2x00_mem_free(ha);
1873 if (qla2x00_allocate_sp_pool(ha)) {
1874 qla_printk(KERN_WARNING, ha,
1875 "Memory Allocation failed - "
1876 "qla2x00_allocate_sp_pool()\n");
1878 qla2x00_mem_free(ha);
1884 /* Allocate memory for SNS commands */
1885 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1886 /* Get consistent memory allocated for SNS commands */
1887 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
1888 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
1890 if (ha->sns_cmd == NULL) {
1892 qla_printk(KERN_WARNING, ha,
1893 "Memory Allocation failed - sns_cmd\n");
1895 qla2x00_mem_free(ha);
1900 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
1902 /* Get consistent memory allocated for MS IOCB */
1903 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
1905 if (ha->ms_iocb == NULL) {
1907 qla_printk(KERN_WARNING, ha,
1908 "Memory Allocation failed - ms_iocb\n");
1910 qla2x00_mem_free(ha);
1915 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
1918 * Get consistent memory allocated for CT SNS
1921 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
1922 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
1924 if (ha->ct_sns == NULL) {
1926 qla_printk(KERN_WARNING, ha,
1927 "Memory Allocation failed - ct_sns\n");
1929 qla2x00_mem_free(ha);
1934 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
1937 /* Done all allocations without any error. */
1940 } while (retry-- && status != 0);
1944 "%s(): **** FAILED ****\n", __func__);
1952 * Frees all adapter allocated memory.
1955 * ha = adapter block pointer.
1958 qla2x00_mem_free(scsi_qla_host_t *ha)
1960 struct list_head *fcpl, *fcptemp;
1962 unsigned int wtime;/* max wait time if mbx cmd is busy. */
1966 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
1970 /* Make sure all other threads are stopped. */
1972 while (ha->dpc_wait && wtime)
1973 wtime = msleep_interruptible(wtime);
1975 /* free ioctl memory */
1976 qla2x00_free_ioctl_mem(ha);
1979 qla2x00_free_sp_pool(ha);
1982 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
1983 ha->sns_cmd, ha->sns_cmd_dma);
1986 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
1987 ha->ct_sns, ha->ct_sns_dma);
1990 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
1993 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
1996 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
1999 dma_pool_destroy(ha->s_dma_pool);
2002 dma_free_coherent(&ha->pdev->dev,
2003 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2007 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2010 if (ha->response_ring)
2011 dma_free_coherent(&ha->pdev->dev,
2012 (ha->response_q_length + 1) * sizeof(response_t),
2013 ha->response_ring, ha->response_dma);
2015 if (ha->request_ring)
2016 dma_free_coherent(&ha->pdev->dev,
2017 (ha->request_q_length + 1) * sizeof(request_t),
2018 ha->request_ring, ha->request_dma);
2021 ha->sns_cmd_dma = 0;
2025 ha->ms_iocb_dma = 0;
2026 ha->iodesc_pd = NULL;
2027 ha->iodesc_pd_dma = 0;
2029 ha->init_cb_dma = 0;
2031 ha->s_dma_pool = NULL;
2034 ha->rlc_rsp_dma = 0;
2035 ha->gid_list = NULL;
2036 ha->gid_list_dma = 0;
2038 ha->response_ring = NULL;
2039 ha->response_dma = 0;
2040 ha->request_ring = NULL;
2041 ha->request_dma = 0;
2043 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2044 fcport = list_entry(fcpl, fc_port_t, list);
2047 list_del_init(&fcport->list);
2050 INIT_LIST_HEAD(&ha->fcports);
2053 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2055 vfree(ha->fw_dump24);
2057 vfree(ha->fw_dump_buffer);
2060 ha->fw_dump24 = NULL;
2062 ha->fw_dump_reading = 0;
2063 ha->fw_dump_buffer = NULL;
2067 * qla2x00_allocate_sp_pool
2068 * This routine is called during initialization to allocate
2069 * memory for local srb_t.
2072 * ha = adapter block pointer.
2077 * Note: Sets the ref_count for non Null sp to one.
2080 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2085 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2086 mempool_free_slab, srb_cachep);
2087 if (ha->srb_mempool == NULL) {
2088 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2089 rval = QLA_FUNCTION_FAILED;
2095 * This routine frees all adapter allocated memory.
2099 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
2101 if (ha->srb_mempool) {
2102 mempool_destroy(ha->srb_mempool);
2103 ha->srb_mempool = NULL;
2107 /**************************************************************************
2109 * This kernel thread is a task that is schedule by the interrupt handler
2110 * to perform the background processing for interrupts.
2113 * This task always run in the context of a kernel thread. It
2114 * is kick-off by the driver's detect code and starts up
2115 * up one per adapter. It immediately goes to sleep and waits for
2116 * some fibre event. When either the interrupt handler or
2117 * the timer routine detects a event it will one of the task
2118 * bits then wake us up.
2119 **************************************************************************/
2121 qla2x00_do_dpc(void *data)
2123 DECLARE_MUTEX_LOCKED(sem);
2124 scsi_qla_host_t *ha;
2127 uint16_t next_loopid;
2129 ha = (scsi_qla_host_t *)data;
2133 daemonize("%s_dpc", ha->host_str);
2134 allow_signal(SIGHUP);
2136 ha->dpc_wait = &sem;
2138 set_user_nice(current, -20);
2142 complete(&ha->dpc_inited);
2145 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2147 if (down_interruptible(&sem))
2150 if (ha->dpc_should_die)
2153 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2155 /* Initialization not yet finished. Don't do anything yet. */
2156 if (!ha->flags.init_done || ha->dpc_active)
2159 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2163 if (ha->flags.mbox_busy) {
2168 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2170 DEBUG(printk("scsi(%ld): dpc: sched "
2171 "qla2x00_abort_isp ha = %p\n",
2173 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2176 if (qla2x00_abort_isp(ha)) {
2177 /* failed. retry later */
2178 set_bit(ISP_ABORT_NEEDED,
2181 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2183 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2187 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2188 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2190 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2193 qla2x00_rst_aen(ha);
2194 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2197 /* Retry each device up to login retry count */
2198 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2199 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2200 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2202 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2206 list_for_each_entry(fcport, &ha->fcports, list) {
2207 if (fcport->port_type != FCT_TARGET)
2211 * If the port is not ONLINE then try to login
2212 * to it if we haven't run out of retries.
2214 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2215 fcport->login_retry) {
2217 fcport->login_retry--;
2218 if (fcport->flags & FCF_FABRIC_DEVICE) {
2221 ha->isp_ops.fabric_logout(
2222 ha, fcport->loop_id,
2223 fcport->d_id.b.domain,
2224 fcport->d_id.b.area,
2225 fcport->d_id.b.al_pa);
2226 status = qla2x00_fabric_login(
2227 ha, fcport, &next_loopid);
2230 qla2x00_local_device_login(
2231 ha, fcport->loop_id);
2233 if (status == QLA_SUCCESS) {
2234 fcport->old_loop_id = fcport->loop_id;
2236 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2237 ha->host_no, fcport->loop_id));
2239 fcport->port_login_retry_count =
2240 ha->port_down_retry_count * PORT_RETRY_TIME;
2241 atomic_set(&fcport->state, FCS_ONLINE);
2242 atomic_set(&fcport->port_down_timer,
2243 ha->port_down_retry_count * PORT_RETRY_TIME);
2245 fcport->login_retry = 0;
2246 } else if (status == 1) {
2247 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2248 /* retry the login again */
2249 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2251 fcport->login_retry, fcport->loop_id));
2253 fcport->login_retry = 0;
2256 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2259 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2263 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2264 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2266 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2267 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2270 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2272 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2276 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2278 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2281 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2284 qla2x00_loop_resync(ha);
2286 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2289 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2293 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2295 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2298 qla2x00_rescan_fcports(ha);
2300 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2305 if (!ha->interrupts_on)
2306 ha->isp_ops.enable_intrs(ha);
2309 } /* End of while(1) */
2311 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2314 * Make sure that nobody tries to wake us up again.
2316 ha->dpc_wait = NULL;
2319 complete_and_exit(&ha->dpc_exited, 0);
2324 * Processes asynchronous reset.
2327 * ha = adapter block pointer.
2330 qla2x00_rst_aen(scsi_qla_host_t *ha)
2332 if (ha->flags.online && !ha->flags.reset_active &&
2333 !atomic_read(&ha->loop_down_timer) &&
2334 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2336 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2339 * Issue marker command only when we are going to start
2342 ha->marker_needed = 1;
2343 } while (!atomic_read(&ha->loop_down_timer) &&
2344 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2349 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2351 struct scsi_cmnd *cmd = sp->cmd;
2353 if (sp->flags & SRB_DMA_VALID) {
2355 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2356 cmd->use_sg, cmd->sc_data_direction);
2357 } else if (cmd->request_bufflen) {
2358 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2359 cmd->request_bufflen, cmd->sc_data_direction);
2361 sp->flags &= ~SRB_DMA_VALID;
2367 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2369 struct scsi_cmnd *cmd = sp->cmd;
2371 qla2x00_sp_free_dma(ha, sp);
2373 mempool_free(sp, ha->srb_mempool);
2375 cmd->scsi_done(cmd);
2378 /**************************************************************************
2384 * Context: Interrupt
2385 ***************************************************************************/
2387 qla2x00_timer(scsi_qla_host_t *ha)
2389 unsigned long cpu_flags = 0;
2397 * Ports - Port down timer.
2399 * Whenever, a port is in the LOST state we start decrementing its port
2400 * down timer every second until it reaches zero. Once it reaches zero
2401 * the port it marked DEAD.
2404 list_for_each_entry(fcport, &ha->fcports, list) {
2405 if (fcport->port_type != FCT_TARGET)
2408 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2410 if (atomic_read(&fcport->port_down_timer) == 0)
2413 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2414 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2416 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2419 t, atomic_read(&fcport->port_down_timer)));
2422 } /* End of for fcport */
2425 /* Loop down handler. */
2426 if (atomic_read(&ha->loop_down_timer) > 0 &&
2427 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2429 if (atomic_read(&ha->loop_down_timer) ==
2430 ha->loop_down_abort_time) {
2432 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2433 "queues before time expire\n",
2436 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2437 atomic_set(&ha->loop_state, LOOP_DEAD);
2439 /* Schedule an ISP abort to return any tape commands. */
2440 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2441 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2445 sp = ha->outstanding_cmds[index];
2449 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2452 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2455 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2457 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2461 /* if the loop has been down for 4 minutes, reinit adapter */
2462 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2463 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2464 "restarting queues.\n",
2467 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2470 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2471 DEBUG(printk("scsi(%ld): Loop down - "
2474 qla_printk(KERN_WARNING, ha,
2475 "Loop down - aborting ISP.\n");
2477 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2480 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2482 atomic_read(&ha->loop_down_timer)));
2485 /* Schedule the DPC routine if needed */
2486 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2487 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2489 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
2490 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2491 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2492 ha->dpc_wait && !ha->dpc_active) {
2497 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2500 /* XXX(hch): crude hack to emulate a down_timeout() */
2502 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2504 const unsigned int step = 100; /* msecs */
2505 unsigned int iterations = jiffies_to_msecs(timeout)/100;
2508 if (!down_trylock(sema))
2510 if (msleep_interruptible(step))
2512 } while (--iterations >= 0);
2517 static struct qla_board_info qla_board_tbl[] = {
2519 .drv_name = "qla2400",
2520 .isp_name = "ISP2422",
2521 .fw_fname = "ql2400_fw.bin",
2522 .sht = &qla24xx_driver_template,
2525 .drv_name = "qla2400",
2526 .isp_name = "ISP2432",
2527 .fw_fname = "ql2400_fw.bin",
2528 .sht = &qla24xx_driver_template,
2532 static struct pci_device_id qla2xxx_pci_tbl[] = {
2534 .vendor = PCI_VENDOR_ID_QLOGIC,
2535 .device = PCI_DEVICE_ID_QLOGIC_ISP2422,
2536 .subvendor = PCI_ANY_ID,
2537 .subdevice = PCI_ANY_ID,
2538 .driver_data = (unsigned long)&qla_board_tbl[0],
2541 .vendor = PCI_VENDOR_ID_QLOGIC,
2542 .device = PCI_DEVICE_ID_QLOGIC_ISP2432,
2543 .subvendor = PCI_ANY_ID,
2544 .subdevice = PCI_ANY_ID,
2545 .driver_data = (unsigned long)&qla_board_tbl[1],
2549 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
2551 static int __devinit
2552 qla2xxx_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2554 return qla2x00_probe_one(pdev,
2555 (struct qla_board_info *)id->driver_data);
2558 static void __devexit
2559 qla2xxx_remove_one(struct pci_dev *pdev)
2561 qla2x00_remove_one(pdev);
2564 static struct pci_driver qla2xxx_pci_driver = {
2566 .id_table = qla2xxx_pci_tbl,
2567 .probe = qla2xxx_probe_one,
2568 .remove = __devexit_p(qla2xxx_remove_one),
2572 * qla2x00_module_init - Module initialization.
2575 qla2x00_module_init(void)
2579 /* Allocate cache for SRBs. */
2580 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
2581 SLAB_HWCACHE_ALIGN, NULL, NULL);
2582 if (srb_cachep == NULL) {
2584 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2588 /* Derive version string. */
2589 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2591 strcat(qla2x00_version_str, "-debug");
2593 qla2xxx_transport_template =
2594 fc_attach_transport(&qla2xxx_transport_functions);
2595 if (!qla2xxx_transport_template)
2598 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2599 ret = pci_module_init(&qla2xxx_pci_driver);
2601 kmem_cache_destroy(srb_cachep);
2602 fc_release_transport(qla2xxx_transport_template);
2608 * qla2x00_module_exit - Module cleanup.
2611 qla2x00_module_exit(void)
2613 pci_unregister_driver(&qla2xxx_pci_driver);
2614 kmem_cache_destroy(srb_cachep);
2615 fc_release_transport(qla2xxx_transport_template);
2618 module_init(qla2x00_module_init);
2619 module_exit(qla2x00_module_exit);
2621 MODULE_AUTHOR("QLogic Corporation");
2622 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2623 MODULE_LICENSE("GPL");
2624 MODULE_VERSION(QLA2XXX_VERSION);