2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 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 char srb_cachep_name[16];
40 kmem_cache_t *srb_cachep;
43 * Stats for all adpaters.
45 struct _qla2x00stats qla2x00_stats;
48 * Ioctl related information.
54 * Module parameter information and variables
57 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql2xmaxqdepth,
59 "Maximum queue depth to report for target devices.");
61 int ql2xlogintimeout = 20;
62 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
63 MODULE_PARM_DESC(ql2xlogintimeout,
64 "Login timeout value in seconds.");
66 int qlport_down_retry = 30;
67 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
68 MODULE_PARM_DESC(qlport_down_retry,
69 "Maximum number of command retries to a port that returns"
70 "a PORT-DOWN status.");
72 int ql2xretrycount = 20;
73 module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR);
74 MODULE_PARM_DESC(ql2xretrycount,
75 "Maximum number of mid-layer retries allowed for a command. "
76 "Default value is 20, ");
79 module_param(displayConfig, int, S_IRUGO|S_IWUSR);
80 MODULE_PARM_DESC(displayConfig,
81 "If 1 then display the configuration used in /etc/modprobe.conf.");
83 int ql2xplogiabsentdevice;
84 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
85 MODULE_PARM_DESC(ql2xplogiabsentdevice,
86 "Option to enable PLOGI to devices that are not present after "
87 "a Fabric scan. This is needed for several broken switches."
88 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
90 int ql2xenablezio = 0;
91 module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
92 MODULE_PARM_DESC(ql2xenablezio,
93 "Option to enable ZIO:If 1 then enable it otherwise"
94 " use the default set in the NVRAM."
95 " Default is 0 : disabled");
97 int ql2xintrdelaytimer = 10;
98 module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
99 MODULE_PARM_DESC(ql2xintrdelaytimer,
100 "ZIO: Waiting time for Firmware before it generates an "
101 "interrupt to the host to notify completion of request.");
104 module_param(ConfigRequired, int, S_IRUGO|S_IRUSR);
105 MODULE_PARM_DESC(ConfigRequired,
106 "If 1, then only configured devices passed in through the"
107 "ql2xopts parameter will be presented to the OS");
109 int Bind = BIND_BY_PORT_NAME;
110 module_param(Bind, int, S_IRUGO|S_IRUSR);
111 MODULE_PARM_DESC(Bind,
112 "Target persistent binding method: "
113 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
115 int ql2xsuspendcount = SUSPEND_COUNT;
116 module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR);
117 MODULE_PARM_DESC(ql2xsuspendcount,
118 "Number of 6-second suspend iterations to perform while a "
119 "target returns a <NOT READY> status. Default is 10 "
122 int ql2xdoinitscan = 1;
123 module_param(ql2xdoinitscan, int, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(ql2xdoinitscan,
125 "Signal mid-layer to perform scan after driver load: 0 -- no "
126 "signal sent to mid-layer.");
128 int ql2xloginretrycount = 0;
129 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
130 MODULE_PARM_DESC(ql2xloginretrycount,
131 "Specify an alternate value for the NVRAM login retry count.");
134 * Proc structures and functions
143 static void copy_mem_info(struct info_str *, char *, int);
144 static int copy_info(struct info_str *, char *, ...);
146 static void qla2x00_free_device(scsi_qla_host_t *);
148 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
151 * SCSI host template entry points
153 static int qla2xxx_slave_configure(struct scsi_device * device);
154 static int qla2xxx_slave_alloc(struct scsi_device *);
155 static void qla2xxx_slave_destroy(struct scsi_device *);
156 static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
157 void (*fn)(struct scsi_cmnd *));
158 static int qla2xxx_eh_abort(struct scsi_cmnd *);
159 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
160 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
161 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
162 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
163 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
165 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
168 static struct scsi_host_template qla2x00_driver_template = {
169 .module = THIS_MODULE,
171 .proc_name = "qla2xxx",
172 .proc_info = qla2x00_proc_info,
173 .queuecommand = qla2x00_queuecommand,
175 .eh_abort_handler = qla2xxx_eh_abort,
176 .eh_device_reset_handler = qla2xxx_eh_device_reset,
177 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
178 .eh_host_reset_handler = qla2xxx_eh_host_reset,
180 .slave_configure = qla2xxx_slave_configure,
182 .slave_alloc = qla2xxx_slave_alloc,
183 .slave_destroy = qla2xxx_slave_destroy,
186 .use_clustering = ENABLE_CLUSTERING,
187 .sg_tablesize = SG_ALL,
190 * The RISC allows for each command to transfer (2^32-1) bytes of data,
191 * which equates to 0x800000 sectors.
193 .max_sectors = 0xFFFF,
196 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
198 static void qla2x00_display_fc_names(scsi_qla_host_t *);
200 /* TODO Convert to inlines
204 #define WATCH_INTERVAL 1 /* number of seconds */
206 static void qla2x00_timer(scsi_qla_host_t *);
208 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
209 void *, unsigned long);
210 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
211 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
214 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
216 init_timer(&ha->timer);
217 ha->timer.expires = jiffies + interval * HZ;
218 ha->timer.data = (unsigned long)ha;
219 ha->timer.function = (void (*)(unsigned long))func;
220 add_timer(&ha->timer);
221 ha->timer_active = 1;
225 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
227 mod_timer(&ha->timer, jiffies + interval * HZ);
230 static __inline__ void
231 qla2x00_stop_timer(scsi_qla_host_t *ha)
233 del_timer_sync(&ha->timer);
234 ha->timer_active = 0;
237 static int qla2x00_do_dpc(void *data);
239 static void qla2x00_rst_aen(scsi_qla_host_t *);
241 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
242 static void qla2x00_mem_free(scsi_qla_host_t *ha);
243 static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
244 static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
245 static srb_t *qla2x00_get_new_sp(scsi_qla_host_t *);
246 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
247 void qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *);
249 /* -------------------------------------------------------------------------- */
252 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
254 static char *pci_bus_modes[] = {
255 "33", "66", "100", "133",
260 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
263 strcat(str, pci_bus_modes[pci_bus]);
265 pci_bus = (ha->pci_attr & BIT_8) >> 8;
267 strcat(str, pci_bus_modes[pci_bus]);
269 strcat(str, " MHz)");
275 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
279 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
280 ha->fw_minor_version,
281 ha->fw_subminor_version);
283 if (ha->fw_attributes & BIT_9) {
288 switch (ha->fw_attributes & 0xFF) {
302 sprintf(un_str, "(%x)", ha->fw_attributes);
306 if (ha->fw_attributes & 0x100)
312 /**************************************************************************
313 * qla2x00_queuecommand
316 * Queue a command to the controller.
319 * cmd - pointer to Scsi cmd structure
320 * fn - pointer to Scsi done function
326 * The mid-level driver tries to ensures that queuecommand never gets invoked
327 * concurrently with itself or the interrupt handler (although the
328 * interrupt handler may call this routine as part of request-completion
330 **************************************************************************/
332 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
334 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
335 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
336 fc_port_t *fcport = tq->fcport;
341 lq = GET_LU_Q(ha, cmd->device->id, cmd->device->lun);
342 if (!fcport || !lq) {
343 cmd->result = DID_NO_CONNECT << 16;
344 goto qc_fail_command;
347 if (atomic_read(&fcport->state) != FCS_ONLINE) {
348 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
349 atomic_read(&ha->loop_state) == LOOP_DEAD) {
350 cmd->result = DID_NO_CONNECT << 16;
351 goto qc_fail_command;
356 spin_unlock_irq(ha->host->host_lock);
358 /* Allocate a command packet from the "sp" pool. */
359 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
360 goto qc_host_busy_lock;
369 sp->fclun = lq->fclun;
374 CMD_SP(cmd) = (void *)sp;
375 cmd->scsi_done = done;
377 rval = qla2x00_start_scsi(sp);
378 if (rval != QLA_SUCCESS)
379 goto qc_host_busy_free_sp;
381 /* Manage unprocessed RIO/ZIO commands in response queue. */
382 if (ha->flags.online && ha->flags.process_response_queue &&
383 ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
386 spin_lock_irqsave(&ha->hardware_lock, flags);
387 qla2x00_process_response_queue(ha);
388 spin_unlock_irqrestore(&ha->hardware_lock, flags);
391 spin_lock_irq(ha->host->host_lock);
395 qc_host_busy_free_sp:
396 qla2x00_sp_free_dma(ha, sp);
398 mempool_free(sp, ha->srb_mempool);
401 spin_lock_irq(ha->host->host_lock);
404 return SCSI_MLQUEUE_HOST_BUSY;
413 * qla2x00_eh_wait_on_command
414 * Waits for the command to be returned by the Firmware for some
418 * ha = actual ha whose done queue will contain the command
419 * returned by firmware.
420 * cmd = Scsi Command to wait on.
421 * flag = Abort/Reset(Bus or Device Reset)
428 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
430 #define ABORT_POLLING_PERIOD HZ
431 #define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
432 unsigned long wait_iter = ABORT_WAIT_ITER;
433 int ret = QLA_SUCCESS;
435 while (CMD_SP(cmd)) {
436 set_current_state(TASK_UNINTERRUPTIBLE);
437 schedule_timeout(ABORT_POLLING_PERIOD);
443 ret = QLA_FUNCTION_FAILED;
449 * qla2x00_wait_for_hba_online
450 * Wait till the HBA is online after going through
451 * <= MAX_RETRIES_OF_ISP_ABORT or
452 * finally HBA is disabled ie marked offline
455 * ha - pointer to host adapter structure
458 * Does context switching-Release SPIN_LOCK
459 * (if any) before calling this routine.
462 * Success (Adapter is online) : 0
463 * Failed (Adapter is offline/disabled) : 1
466 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
469 unsigned long wait_online;
471 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
472 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
473 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
474 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
475 ha->dpc_active) && time_before(jiffies, wait_online)) {
479 if (ha->flags.online)
480 return_status = QLA_SUCCESS;
482 return_status = QLA_FUNCTION_FAILED;
484 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
486 return (return_status);
490 * qla2x00_wait_for_loop_ready
491 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
492 * to be in LOOP_READY state.
494 * ha - pointer to host adapter structure
497 * Does context switching-Release SPIN_LOCK
498 * (if any) before calling this routine.
502 * Success (LOOP_READY) : 0
503 * Failed (LOOP_NOT_READY) : 1
506 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
508 int return_status = QLA_SUCCESS;
509 unsigned long loop_timeout ;
511 /* wait for 5 min at the max for loop to be ready */
512 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
514 while ((!atomic_read(&ha->loop_down_timer) &&
515 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
516 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
517 atomic_read(&ha->loop_state) != LOOP_READY) {
519 if (time_after_eq(jiffies, loop_timeout)) {
520 return_status = QLA_FUNCTION_FAILED;
524 return (return_status);
527 /**************************************************************************
531 * The abort function will abort the specified command.
534 * cmd = Linux SCSI command packet to be aborted.
537 * Either SUCCESS or FAILED.
540 **************************************************************************/
542 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
544 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
547 unsigned int id, lun;
548 unsigned long serial;
555 id = cmd->device->id;
556 lun = cmd->device->lun;
557 serial = cmd->serial_number;
559 /* Check active list for command command. */
560 spin_unlock_irq(ha->host->host_lock);
561 spin_lock(&ha->hardware_lock);
562 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
563 sp = ha->outstanding_cmds[i];
571 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
572 "sp->state=%x\n", __func__, ha->host_no, sp, serial,
574 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
576 spin_unlock(&ha->hardware_lock);
577 if (qla2x00_abort_command(ha, sp)) {
578 DEBUG2(printk("%s(%ld): abort_command "
579 "mbx failed.\n", __func__, ha->host_no));
581 DEBUG3(printk("%s(%ld): abort_command "
582 "mbx success.\n", __func__, ha->host_no));
585 spin_lock(&ha->hardware_lock);
590 /* Wait for the command to be returned. */
591 if (ret == SUCCESS) {
592 spin_unlock(&ha->hardware_lock);
593 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
594 qla_printk(KERN_ERR, ha,
595 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
596 "%x.\n", ha->host_no, id, lun, serial, ret);
598 spin_lock(&ha->hardware_lock);
600 spin_lock_irq(ha->host->host_lock);
602 qla_printk(KERN_INFO, ha,
603 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha->host_no,
604 id, lun, serial, ret);
609 /**************************************************************************
610 * qla2x00_eh_wait_for_pending_target_commands
613 * Waits for all the commands to come back from the specified target.
616 * ha - pointer to scsi_qla_host structure.
619 * Either SUCCESS or FAILED.
622 **************************************************************************/
624 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
629 struct scsi_cmnd *cmd;
634 * Waiting for all commands for the designated target in the active
637 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
638 spin_lock(&ha->hardware_lock);
639 sp = ha->outstanding_cmds[cnt];
642 spin_unlock(&ha->hardware_lock);
643 if (cmd->device->id == t) {
644 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
650 spin_unlock(&ha->hardware_lock);
657 /**************************************************************************
658 * qla2xxx_eh_device_reset
661 * The device reset function will reset the target and abort any
662 * executing commands.
664 * NOTE: The use of SP is undefined within this context. Do *NOT*
665 * attempt to use this value, even if you determine it is
669 * cmd = Linux SCSI command packet of the command that cause the
673 * SUCCESS/FAILURE (defined as macro in scsi.h).
675 **************************************************************************/
677 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
679 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
680 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
681 fc_port_t *fcport = tq->fcport;
685 unsigned int id, lun;
686 unsigned long serial;
690 id = cmd->device->id;
691 lun = cmd->device->lun;
692 serial = cmd->serial_number;
694 sp = (srb_t *) CMD_SP(cmd);
695 lq = GET_LU_Q(ha, id, lun);
696 if (!sp || !fcport || !lq)
699 qla_printk(KERN_INFO, ha,
700 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, id, lun);
702 spin_unlock_irq(ha->host->host_lock);
704 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
705 spin_lock_irq(ha->host->host_lock);
706 goto eh_dev_reset_done;
709 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
710 if (qla2x00_device_reset(ha, fcport) == 0)
713 #if defined(LOGOUT_AFTER_DEVICE_RESET)
714 if (ret == SUCCESS) {
715 if (fcport->flags & FC_FABRIC_DEVICE) {
716 qla2x00_fabric_logout(ha, fcport->loop_id);
717 qla2x00_mark_device_lost(ha, fcport);
722 DEBUG2(printk(KERN_INFO
723 "%s failed: loop not ready\n",__func__);)
727 DEBUG3(printk("%s(%ld): device reset failed\n",
728 __func__, ha->host_no));
729 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
732 goto eh_dev_reset_done;
736 * If we are coming down the EH path, wait for all commands to
737 * complete for the device.
739 if (cmd->device->host->eh_active) {
740 if (qla2x00_eh_wait_for_pending_target_commands(ha, id))
744 DEBUG3(printk("%s(%ld): failed while waiting for "
745 "commands\n", __func__, ha->host_no));
746 qla_printk(KERN_INFO, ha,
747 "%s: failed while waiting for commands\n",
750 goto eh_dev_reset_done;
754 qla_printk(KERN_INFO, ha,
755 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha->host_no, id, lun);
758 spin_lock_irq(ha->host->host_lock);
763 /**************************************************************************
764 * qla2x00_eh_wait_for_pending_commands
767 * Waits for all the commands to come back from the specified host.
770 * ha - pointer to scsi_qla_host structure.
777 **************************************************************************/
779 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
784 struct scsi_cmnd *cmd;
789 * Waiting for all commands for the designated target in the active
792 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
793 spin_lock(&ha->hardware_lock);
794 sp = ha->outstanding_cmds[cnt];
797 spin_unlock(&ha->hardware_lock);
798 status = qla2x00_eh_wait_on_command(ha, cmd);
803 spin_unlock(&ha->hardware_lock);
810 /**************************************************************************
811 * qla2xxx_eh_bus_reset
814 * The bus reset function will reset the bus and abort any executing
818 * cmd = Linux SCSI command packet of the command that cause the
822 * SUCCESS/FAILURE (defined as macro in scsi.h).
824 **************************************************************************/
826 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
828 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
829 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
830 fc_port_t *fcport = tq->fcport;
834 unsigned int id, lun;
835 unsigned long serial;
839 id = cmd->device->id;
840 lun = cmd->device->lun;
841 serial = cmd->serial_number;
843 sp = (srb_t *) CMD_SP(cmd);
844 lq = GET_LU_Q(ha, id, lun);
845 if (!sp || !fcport || !lq)
848 qla_printk(KERN_INFO, ha,
849 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun);
851 spin_unlock_irq(ha->host->host_lock);
853 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
854 DEBUG2(printk("%s failed:board disabled\n",__func__));
855 goto eh_bus_reset_done;
858 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
859 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
863 goto eh_bus_reset_done;
865 /* Waiting for our command in done_queue to be returned to OS.*/
866 if (cmd->device->host->eh_active)
867 if (!qla2x00_eh_wait_for_pending_commands(ha))
871 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
872 (ret == FAILED) ? "failed" : "succeded");
874 spin_lock_irq(ha->host->host_lock);
879 /**************************************************************************
880 * qla2xxx_eh_host_reset
883 * The reset function will reset the Adapter.
886 * cmd = Linux SCSI command packet of the command that cause the
890 * Either SUCCESS or FAILED.
893 **************************************************************************/
895 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
897 scsi_qla_host_t *ha = to_qla_host(cmd->device->host);
898 os_tgt_t *tq = (os_tgt_t *) cmd->device->hostdata;
899 fc_port_t *fcport = tq->fcport;
903 unsigned int id, lun;
904 unsigned long serial;
908 id = cmd->device->id;
909 lun = cmd->device->lun;
910 serial = cmd->serial_number;
912 sp = (srb_t *) CMD_SP(cmd);
913 lq = GET_LU_Q(ha, id, lun);
914 if (!sp || !fcport || !lq)
917 qla_printk(KERN_INFO, ha,
918 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun);
920 spin_unlock_irq(ha->host->host_lock);
922 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
923 goto eh_host_reset_lock;
926 * Fixme-may be dpc thread is active and processing
927 * loop_resync,so wait a while for it to
928 * be completed and then issue big hammer.Otherwise
929 * it may cause I/O failure as big hammer marks the
930 * devices as lost kicking of the port_down_timer
931 * while dpc is stuck for the mailbox to complete.
933 qla2x00_wait_for_loop_ready(ha);
934 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
935 if (qla2x00_abort_isp(ha)) {
936 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
937 /* failed. schedule dpc to try */
938 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
940 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
941 goto eh_host_reset_lock;
943 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
945 /* Waiting for our command in done_queue to be returned to OS.*/
946 if (qla2x00_eh_wait_for_pending_commands(ha))
950 spin_lock_irq(ha->host->host_lock);
952 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
953 (ret == FAILED) ? "failed" : "succeded");
963 * ha = adapter block pointer.
969 qla2x00_loop_reset(scsi_qla_host_t *ha)
971 int status = QLA_SUCCESS;
975 if (ha->flags.enable_lip_reset) {
976 status = qla2x00_lip_reset(ha);
979 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
980 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
981 if ((tq = TGT_Q(ha, t)) == NULL)
984 if (tq->fcport == NULL)
987 status = qla2x00_target_reset(ha, 0, t);
988 if (status != QLA_SUCCESS) {
994 if (status == QLA_SUCCESS &&
995 ((!ha->flags.enable_target_reset &&
996 !ha->flags.enable_lip_reset) ||
997 ha->flags.enable_lip_full_login)) {
999 status = qla2x00_full_login_lip(ha);
1002 /* Issue marker command only when we are going to start the I/O */
1003 ha->marker_needed = 1;
1007 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1012 DEBUG3(printk("%s(%ld): exiting normally.\n",
1021 * qla2x00_device_reset
1022 * Issue bus device reset message to the target.
1025 * ha = adapter block pointer.
1027 * TARGET_QUEUE_LOCK must be released.
1028 * ADAPTER_STATE_LOCK must be released.
1034 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1036 /* Abort Target command will clear Reservation */
1037 return qla2x00_abort_target(reset_fcport);
1041 qla2xxx_slave_alloc(struct scsi_device *sdev)
1043 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1046 tq = (os_tgt_t *) TGT_Q(ha, sdev->id);
1052 sdev->hostdata = tq;
1058 qla2xxx_slave_configure(struct scsi_device *sdev)
1060 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1061 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1063 if (sdev->tagged_supported)
1064 scsi_activate_tcq(sdev, 32);
1066 scsi_deactivate_tcq(sdev, 32);
1068 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
1074 qla2xxx_slave_destroy(struct scsi_device *sdev)
1076 sdev->hostdata = NULL;
1080 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1083 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1084 * supported addressing method.
1087 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1089 /* Assume 32bit DMA address */
1090 ha->flags.enable_64bit_addressing = 0;
1091 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1092 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1095 * Given the two variants pci_set_dma_mask(), allow the compiler to
1096 * assist in setting the proper dma mask.
1098 if (sizeof(dma_addr_t) > 4) {
1099 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1100 ha->flags.enable_64bit_addressing = 1;
1101 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1102 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1104 if (pci_set_consistent_dma_mask(ha->pdev,
1106 qla_printk(KERN_DEBUG, ha,
1107 "Failed to set 64 bit PCI consistent mask; "
1109 pci_set_consistent_dma_mask(ha->pdev,
1113 qla_printk(KERN_DEBUG, ha,
1114 "Failed to set 64 bit PCI DMA mask, falling back "
1115 "to 32 bit MASK.\n");
1116 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1119 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1124 qla2x00_iospace_config(scsi_qla_host_t *ha)
1126 unsigned long pio, pio_len, pio_flags;
1127 unsigned long mmio, mmio_len, mmio_flags;
1129 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1130 pio = pci_resource_start(ha->pdev, 0);
1131 pio_len = pci_resource_len(ha->pdev, 0);
1132 pio_flags = pci_resource_flags(ha->pdev, 0);
1133 if (pio_flags & IORESOURCE_IO) {
1134 if (pio_len < MIN_IOBASE_LEN) {
1135 qla_printk(KERN_WARNING, ha,
1136 "Invalid PCI I/O region size (%s)...\n",
1137 pci_name(ha->pdev));
1141 qla_printk(KERN_WARNING, ha,
1142 "region #0 not a PIO resource (%s)...\n",
1143 pci_name(ha->pdev));
1147 /* Use MMIO operations for all accesses. */
1148 mmio = pci_resource_start(ha->pdev, 1);
1149 mmio_len = pci_resource_len(ha->pdev, 1);
1150 mmio_flags = pci_resource_flags(ha->pdev, 1);
1152 if (!(mmio_flags & IORESOURCE_MEM)) {
1153 qla_printk(KERN_ERR, ha,
1154 "region #0 not an MMIO resource (%s), aborting\n",
1155 pci_name(ha->pdev));
1156 goto iospace_error_exit;
1158 if (mmio_len < MIN_IOBASE_LEN) {
1159 qla_printk(KERN_ERR, ha,
1160 "Invalid PCI mem region size (%s), aborting\n",
1161 pci_name(ha->pdev));
1162 goto iospace_error_exit;
1165 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1166 qla_printk(KERN_WARNING, ha,
1167 "Failed to reserve PIO/MMIO regions (%s)\n",
1168 pci_name(ha->pdev));
1170 goto iospace_error_exit;
1173 ha->pio_address = pio;
1174 ha->pio_length = pio_len;
1175 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1177 qla_printk(KERN_ERR, ha,
1178 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1180 goto iospace_error_exit;
1190 * PCI driver interface
1192 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1195 device_reg_t __iomem *reg;
1196 struct Scsi_Host *host;
1197 scsi_qla_host_t *ha;
1198 unsigned long flags = 0;
1199 unsigned long wait_switch = 0;
1204 if (pci_enable_device(pdev))
1207 host = scsi_host_alloc(&qla2x00_driver_template,
1208 sizeof(scsi_qla_host_t));
1211 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1212 goto probe_disable_device;
1215 /* Clear our data area */
1216 ha = (scsi_qla_host_t *)host->hostdata;
1217 memset(ha, 0, sizeof(scsi_qla_host_t));
1221 ha->host_no = host->host_no;
1222 ha->brd_info = brd_info;
1223 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1225 /* Configure PCI I/O space */
1226 ret = qla2x00_iospace_config(ha);
1228 goto probe_alloc_failed;
1231 /* Sanitize the information from PCI BIOS. */
1232 host->irq = pdev->irq;
1234 qla_printk(KERN_INFO, ha,
1235 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1236 host->irq, ha->iobase);
1238 spin_lock_init(&ha->hardware_lock);
1240 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1243 ha->total_isr_cnt = 0;
1244 ha->total_isp_aborts = 0;
1245 ha->total_lip_cnt = 0;
1246 ha->total_dev_errs = 0;
1248 ha->total_bytes = 0;
1250 ha->prev_topology = 0;
1251 ha->ports = MAX_BUSES;
1253 if (IS_QLA2100(ha)) {
1254 ha->max_targets = MAX_TARGETS_2100;
1255 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1256 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1257 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1258 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1259 host->sg_tablesize = 32;
1260 } else if (IS_QLA2200(ha)) {
1261 ha->max_targets = MAX_TARGETS_2200;
1262 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1263 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1264 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1265 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1266 } else /*if (IS_QLA2300(ha))*/ {
1267 ha->max_targets = MAX_TARGETS_2200;
1268 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1269 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1270 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1271 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1273 host->can_queue = ha->request_q_length + 128;
1275 /* load the F/W, read paramaters, and init the H/W */
1276 ha->instance = num_hosts;
1278 init_MUTEX(&ha->mbx_cmd_sem);
1279 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1281 INIT_LIST_HEAD(&ha->list);
1282 INIT_LIST_HEAD(&ha->fcports);
1283 INIT_LIST_HEAD(&ha->rscn_fcports);
1286 * These locks are used to prevent more than one CPU
1287 * from modifying the queue at the same time. The
1288 * higher level "host_lock" will reduce most
1289 * contention for these locks.
1291 spin_lock_init(&ha->mbx_reg_lock);
1294 init_completion(&ha->dpc_inited);
1295 init_completion(&ha->dpc_exited);
1297 qla2x00_config_dma_addressing(ha);
1298 if (qla2x00_mem_alloc(ha)) {
1299 qla_printk(KERN_WARNING, ha,
1300 "[ERROR] Failed to allocate memory for adapter\n");
1302 goto probe_alloc_failed;
1305 pci_set_drvdata(pdev, ha);
1306 host->this_id = 255;
1307 host->cmd_per_lun = 3;
1308 host->unique_id = ha->instance;
1309 host->max_cmd_len = MAX_CMDSZ;
1310 host->max_channel = ha->ports - 1;
1311 host->max_id = ha->max_targets;
1312 host->max_lun = ha->max_luns;
1313 host->transportt = qla2xxx_transport_template;
1314 if (scsi_add_host(host, &pdev->dev))
1315 goto probe_alloc_failed;
1317 qla2x00_alloc_sysfs_attr(ha);
1319 if (qla2x00_initialize_adapter(ha) &&
1320 !(ha->device_flags & DFLG_NO_CABLE)) {
1322 qla_printk(KERN_WARNING, ha,
1323 "Failed to initialize adapter\n");
1325 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1326 "Adapter flags %x.\n",
1327 ha->host_no, ha->device_flags));
1332 qla2x00_init_host_attr(ha);
1334 * Startup the kernel thread for this host adapter
1336 ha->dpc_should_die = 0;
1337 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
1338 if (ha->dpc_pid < 0) {
1339 qla_printk(KERN_WARNING, ha,
1340 "Unable to start DPC thread!\n");
1344 wait_for_completion(&ha->dpc_inited);
1346 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1347 ret = request_irq(host->irq, qla2100_intr_handler,
1348 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1350 ret = request_irq(host->irq, qla2300_intr_handler,
1351 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
1353 qla_printk(KERN_WARNING, ha,
1354 "Failed to reserve interrupt %d already in use.\n",
1359 /* Initialized the timer */
1360 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
1362 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1367 /* Disable ISP interrupts. */
1368 qla2x00_disable_intrs(ha);
1370 /* Ensure mailbox registers are free. */
1371 spin_lock_irqsave(&ha->hardware_lock, flags);
1372 WRT_REG_WORD(®->semaphore, 0);
1373 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
1374 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
1376 /* Enable proper parity */
1377 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1380 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
1382 /* SRAM, Instruction RAM and GP RAM parity */
1383 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
1385 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1387 /* Enable chip interrupts. */
1388 qla2x00_enable_intrs(ha);
1392 * Wait around max loop_reset_delay secs for the devices to come
1393 * on-line. We don't want Linux scanning before we are ready.
1396 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
1397 time_before(jiffies,wait_switch) &&
1398 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
1399 && (ha->device_flags & SWITCH_FOUND) ;) {
1401 qla2x00_check_fabric_devices(ha);
1406 ha->flags.init_done = 1;
1409 /* List the target we have found */
1410 if (displayConfig) {
1411 qla2x00_display_fc_names(ha);
1414 qla_printk(KERN_INFO, ha, "\n"
1415 " QLogic Fibre Channel HBA Driver: %s\n"
1417 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
1418 ha->model_number, ha->model_desc ? ha->model_desc: "",
1419 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
1420 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
1421 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
1423 /* Go with fc_rport registration. */
1424 list_for_each_entry(fcport, &ha->fcports, list)
1425 qla2x00_reg_remote_port(ha, fcport);
1430 scsi_remove_host(host);
1433 qla2x00_free_device(ha);
1435 scsi_host_put(host);
1437 probe_disable_device:
1438 pci_disable_device(pdev);
1442 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
1444 void qla2x00_remove_one(struct pci_dev *pdev)
1446 scsi_qla_host_t *ha;
1448 ha = pci_get_drvdata(pdev);
1450 qla2x00_free_sysfs_attr(ha);
1452 scsi_remove_host(ha->host);
1454 qla2x00_free_device(ha);
1456 scsi_host_put(ha->host);
1458 pci_set_drvdata(pdev, NULL);
1460 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
1463 qla2x00_free_device(scsi_qla_host_t *ha)
1467 /* Abort any outstanding IO descriptors. */
1468 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1469 qla2x00_cancel_io_descriptors(ha);
1471 /* turn-off interrupts on the card */
1472 if (ha->interrupts_on)
1473 qla2x00_disable_intrs(ha);
1476 if (ha->timer_active)
1477 qla2x00_stop_timer(ha);
1479 /* Kill the kernel thread for this host */
1480 if (ha->dpc_pid >= 0) {
1481 ha->dpc_should_die = 1;
1483 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
1485 qla_printk(KERN_ERR, ha,
1486 "Unable to signal DPC thread -- (%d)\n", ret);
1488 /* TODO: SOMETHING MORE??? */
1490 wait_for_completion(&ha->dpc_exited);
1494 qla2x00_mem_free(ha);
1497 ha->flags.online = 0;
1499 /* Detach interrupts */
1501 free_irq(ha->pdev->irq, ha);
1503 /* release io space registers */
1505 iounmap(ha->iobase);
1506 pci_release_regions(ha->pdev);
1508 pci_disable_device(ha->pdev);
1513 * The following support functions are adopted to handle
1514 * the re-entrant qla2x00_proc_info correctly.
1517 copy_mem_info(struct info_str *info, char *data, int len)
1519 if (info->pos + len > info->offset + info->length)
1520 len = info->offset + info->length - info->pos;
1522 if (info->pos + len < info->offset) {
1527 if (info->pos < info->offset) {
1530 partial = info->offset - info->pos;
1532 info->pos += partial;
1537 memcpy(info->buffer, data, len);
1539 info->buffer += len;
1544 copy_info(struct info_str *info, char *fmt, ...)
1550 va_start(args, fmt);
1551 len = vsprintf(buf, fmt, args);
1554 copy_mem_info(info, buf, len);
1559 /*************************************************************************
1563 * Return information to handle /proc support for the driver.
1565 * inout : decides the direction of the dataflow and the meaning of the
1567 * buffer: If inout==0 data is being written to it else read from it
1568 * (ptr to a page buffer)
1569 * *start: If inout==0 start of the valid data in the buffer
1570 * offset: If inout==0 starting offset from the beginning of all
1571 * possible data to return.
1572 * length: If inout==0 max number of bytes to be written into the buffer
1573 * else number of bytes in "buffer"
1575 * < 0: error. errno value.
1576 * >= 0: sizeof data returned.
1577 *************************************************************************/
1579 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
1580 char **start, off_t offset, int length, int inout)
1582 struct info_str info;
1583 int retval = -EINVAL;
1589 uint8_t *loop_state;
1590 scsi_qla_host_t *ha;
1593 DEBUG3(printk(KERN_INFO
1594 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
1595 buffer, offset, length);)
1597 ha = (scsi_qla_host_t *) shost->hostdata;
1600 /* Has data been written to the file? */
1602 "%s: has data been written to the file. \n",
1612 info.buffer = buffer;
1613 info.length = length;
1614 info.offset = offset;
1617 /* start building the print buffer */
1619 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
1620 " Firmware version %s, ",
1621 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
1623 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
1625 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
1627 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
1628 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
1631 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
1632 (unsigned long long)ha->request_dma,
1633 (unsigned long long)ha->response_dma);
1636 "Request Queue count = %d, Response Queue count = %d\n",
1637 ha->request_q_length, ha->response_q_length);
1640 "Total number of active commands = %ld\n",
1644 "Total number of interrupts = %ld\n",
1645 (long)ha->total_isr_cnt);
1648 " Device queue depth = 0x%x\n",
1649 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
1652 "Number of free request entries = %d\n", ha->req_q_cnt);
1655 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
1658 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
1661 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
1664 "Number of retries for empty slots = %ld\n",
1665 qla2x00_stats.outarray_full);
1667 flags = (uint32_t *) &ha->flags;
1669 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
1670 loop_state = "DOWN";
1671 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
1673 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
1674 loop_state = "READY";
1675 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
1676 loop_state = "TIMEOUT";
1677 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
1678 loop_state = "UPDATE";
1680 loop_state = "UNKNOWN";
1684 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
1685 loop_state , *flags);
1687 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
1689 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
1691 copy_info(&info, "Link down Timeout = %3.3d\n",
1692 ha->link_down_timeout);
1694 copy_info(&info, "Port down retry = %3.3d\n",
1695 ha->port_down_retry_count);
1697 copy_info(&info, "Login retry count = %3.3d\n",
1698 ha->login_retry_count);
1701 "Commands retried with dropped frame(s) = %d\n",
1702 ha->dropped_frame_error_cnt);
1705 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
1706 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
1708 copy_info(&info, "\n");
1710 /* 2.25 node/port display to proc */
1711 /* Display the node name for adapter */
1712 copy_info(&info, "\nSCSI Device Information:\n");
1714 "scsi-qla%d-adapter-node="
1715 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1717 ha->init_cb->node_name[0],
1718 ha->init_cb->node_name[1],
1719 ha->init_cb->node_name[2],
1720 ha->init_cb->node_name[3],
1721 ha->init_cb->node_name[4],
1722 ha->init_cb->node_name[5],
1723 ha->init_cb->node_name[6],
1724 ha->init_cb->node_name[7]);
1726 /* display the port name for adapter */
1728 "scsi-qla%d-adapter-port="
1729 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1731 ha->init_cb->port_name[0],
1732 ha->init_cb->port_name[1],
1733 ha->init_cb->port_name[2],
1734 ha->init_cb->port_name[3],
1735 ha->init_cb->port_name[4],
1736 ha->init_cb->port_name[5],
1737 ha->init_cb->port_name[6],
1738 ha->init_cb->port_name[7]);
1740 /* Print out device port names */
1741 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1742 if ((tq = TGT_Q(ha, t)) == NULL)
1746 "scsi-qla%d-target-%d="
1747 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1748 (int)ha->instance, t,
1749 tq->port_name[0], tq->port_name[1],
1750 tq->port_name[2], tq->port_name[3],
1751 tq->port_name[4], tq->port_name[5],
1752 tq->port_name[6], tq->port_name[7]);
1755 copy_info(&info, "\nSCSI LUN Information:\n");
1757 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
1759 /* scan for all equipment stats */
1760 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1762 for (l = 0; l < ha->max_luns; l++) {
1763 up = (os_lun_t *) GET_LU_Q(ha, t, l);
1768 if (up->fclun == NULL) {
1773 "(%2d:%2d): Total reqs %ld,",
1777 " Pending reqs %ld,",
1780 if (up->io_cnt < 4) {
1791 " %ld:%d:%02x %02x",
1792 up->fclun->fcport->ha->instance,
1793 up->fclun->fcport->cur_path,
1794 up->fclun->fcport->loop_id,
1795 up->fclun->device_type);
1797 copy_info(&info, "\n");
1799 if (info.pos >= info.offset + info.length) {
1800 /* No need to continue */
1805 if (info.pos >= info.offset + info.length) {
1806 /* No need to continue */
1813 retval = info.pos > info.offset ? info.pos - info.offset : 0;
1815 DEBUG3(printk(KERN_INFO
1816 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
1817 "length=0x%x\n", info.pos, offset, length);)
1823 * qla2x00_display_fc_names
1824 * This routine will the node names of the different devices found
1825 * after port inquiry.
1828 * cmd = SCSI command structure
1834 qla2x00_display_fc_names(scsi_qla_host_t *ha)
1839 /* Display the node name for adapter */
1840 qla_printk(KERN_INFO, ha,
1841 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
1843 ha->init_cb->node_name[0],
1844 ha->init_cb->node_name[1],
1845 ha->init_cb->node_name[2],
1846 ha->init_cb->node_name[3],
1847 ha->init_cb->node_name[4],
1848 ha->init_cb->node_name[5],
1849 ha->init_cb->node_name[6],
1850 ha->init_cb->node_name[7]);
1852 /* display the port name for adapter */
1853 qla_printk(KERN_INFO, ha,
1854 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
1856 ha->init_cb->port_name[0],
1857 ha->init_cb->port_name[1],
1858 ha->init_cb->port_name[2],
1859 ha->init_cb->port_name[3],
1860 ha->init_cb->port_name[4],
1861 ha->init_cb->port_name[5],
1862 ha->init_cb->port_name[6],
1863 ha->init_cb->port_name[7]);
1865 /* Print out device port names */
1866 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1867 if ((tq = ha->otgt[tgt]) == NULL)
1870 if (tq->fcport == NULL)
1873 switch (ha->binding_type) {
1874 case BIND_BY_PORT_NAME:
1875 qla_printk(KERN_INFO, ha,
1876 "scsi-qla%d-tgt-%d-di-0-port="
1877 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
1891 case BIND_BY_PORT_ID:
1892 qla_printk(KERN_INFO, ha,
1893 "scsi-qla%d-tgt-%d-di-0-pid="
1894 "%02x%02x%02x\\;\n",
1904 qla_printk(KERN_INFO, ha,
1905 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
1912 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
1914 * Input: ha = adapter block pointer. fcport = port structure pointer.
1920 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1923 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1924 fc_remote_port_block(fcport->rport);
1926 * We may need to retry the login, so don't change the state of the
1927 * port but do the retries.
1929 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
1930 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1935 if (fcport->login_retry == 0) {
1936 fcport->login_retry = ha->login_retry_count;
1937 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
1939 DEBUG(printk("scsi(%ld): Port login retry: "
1940 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1941 "id = 0x%04x retry cnt=%d\n",
1943 fcport->port_name[0],
1944 fcport->port_name[1],
1945 fcport->port_name[2],
1946 fcport->port_name[3],
1947 fcport->port_name[4],
1948 fcport->port_name[5],
1949 fcport->port_name[6],
1950 fcport->port_name[7],
1952 fcport->login_retry));
1957 * qla2x00_mark_all_devices_lost
1958 * Updates fcport state when device goes offline.
1961 * ha = adapter block pointer.
1962 * fcport = port structure pointer.
1970 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
1974 list_for_each_entry(fcport, &ha->fcports, list) {
1975 if (fcport->port_type != FCT_TARGET)
1979 * No point in marking the device as lost, if the device is
1982 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1984 if (atomic_read(&fcport->state) == FCS_ONLINE && fcport->rport)
1985 fc_remote_port_block(fcport->rport);
1986 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1992 * Allocates adapter memory.
1999 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2007 * This will loop only once if everything goes well, else some
2008 * number of retries will be performed to get around a kernel
2009 * bug where available mem is not allocated until after a
2010 * little delay and a retry.
2012 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2013 (ha->request_q_length + 1) * sizeof(request_t),
2014 &ha->request_dma, GFP_KERNEL);
2015 if (ha->request_ring == NULL) {
2016 qla_printk(KERN_WARNING, ha,
2017 "Memory Allocation failed - request_ring\n");
2019 qla2x00_mem_free(ha);
2025 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2026 (ha->response_q_length + 1) * sizeof(response_t),
2027 &ha->response_dma, GFP_KERNEL);
2028 if (ha->response_ring == NULL) {
2029 qla_printk(KERN_WARNING, ha,
2030 "Memory Allocation failed - response_ring\n");
2032 qla2x00_mem_free(ha);
2038 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2039 &ha->gid_list_dma, GFP_KERNEL);
2040 if (ha->gid_list == NULL) {
2041 qla_printk(KERN_WARNING, ha,
2042 "Memory Allocation failed - gid_list\n");
2044 qla2x00_mem_free(ha);
2050 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
2051 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
2052 if (ha->rlc_rsp == NULL) {
2053 qla_printk(KERN_WARNING, ha,
2054 "Memory Allocation failed - rlc");
2056 qla2x00_mem_free(ha);
2062 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
2063 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2064 DMA_POOL_SIZE, 8, 0);
2065 if (ha->s_dma_pool == NULL) {
2066 qla_printk(KERN_WARNING, ha,
2067 "Memory Allocation failed - s_dma_pool\n");
2069 qla2x00_mem_free(ha);
2075 /* get consistent memory allocated for init control block */
2076 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2078 if (ha->init_cb == NULL) {
2079 qla_printk(KERN_WARNING, ha,
2080 "Memory Allocation failed - init_cb\n");
2082 qla2x00_mem_free(ha);
2087 memset(ha->init_cb, 0, sizeof(init_cb_t));
2089 /* Get consistent memory allocated for Get Port Database cmd */
2090 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2091 &ha->iodesc_pd_dma);
2092 if (ha->iodesc_pd == NULL) {
2094 qla_printk(KERN_WARNING, ha,
2095 "Memory Allocation failed - iodesc_pd\n");
2097 qla2x00_mem_free(ha);
2102 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2104 /* Allocate ioctl related memory. */
2105 if (qla2x00_alloc_ioctl_mem(ha)) {
2106 qla_printk(KERN_WARNING, ha,
2107 "Memory Allocation failed - ioctl_mem\n");
2109 qla2x00_mem_free(ha);
2115 if (qla2x00_allocate_sp_pool(ha)) {
2116 qla_printk(KERN_WARNING, ha,
2117 "Memory Allocation failed - "
2118 "qla2x00_allocate_sp_pool()\n");
2120 qla2x00_mem_free(ha);
2126 /* Allocate memory for SNS commands */
2127 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2128 /* Get consistent memory allocated for SNS commands */
2129 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2130 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2132 if (ha->sns_cmd == NULL) {
2134 qla_printk(KERN_WARNING, ha,
2135 "Memory Allocation failed - sns_cmd\n");
2137 qla2x00_mem_free(ha);
2142 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2144 /* Get consistent memory allocated for MS IOCB */
2145 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2147 if (ha->ms_iocb == NULL) {
2149 qla_printk(KERN_WARNING, ha,
2150 "Memory Allocation failed - ms_iocb\n");
2152 qla2x00_mem_free(ha);
2157 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2160 * Get consistent memory allocated for CT SNS
2163 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2164 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2166 if (ha->ct_sns == NULL) {
2168 qla_printk(KERN_WARNING, ha,
2169 "Memory Allocation failed - ct_sns\n");
2171 qla2x00_mem_free(ha);
2176 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2179 /* Done all allocations without any error. */
2182 } while (retry-- && status != 0);
2186 "%s(): **** FAILED ****\n", __func__);
2194 * Frees all adapter allocated memory.
2197 * ha = adapter block pointer.
2200 qla2x00_mem_free(scsi_qla_host_t *ha)
2203 struct list_head *fcpl, *fcptemp;
2205 struct list_head *fcll, *fcltemp;
2207 unsigned long wtime;/* max wait time if mbx cmd is busy. */
2211 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
2215 /* Free the target queues */
2216 for (t = 0; t < MAX_TARGETS; t++) {
2217 qla2x00_tgt_free(ha, t);
2220 /* Make sure all other threads are stopped. */
2222 while (ha->dpc_wait && wtime) {
2223 set_current_state(TASK_INTERRUPTIBLE);
2224 wtime = schedule_timeout(wtime);
2227 /* free ioctl memory */
2228 qla2x00_free_ioctl_mem(ha);
2231 qla2x00_free_sp_pool(ha);
2234 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2235 ha->sns_cmd, ha->sns_cmd_dma);
2238 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2239 ha->ct_sns, ha->ct_sns_dma);
2242 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2245 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
2248 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
2251 dma_pool_destroy(ha->s_dma_pool);
2254 dma_free_coherent(&ha->pdev->dev,
2255 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
2259 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2262 if (ha->response_ring)
2263 dma_free_coherent(&ha->pdev->dev,
2264 (ha->response_q_length + 1) * sizeof(response_t),
2265 ha->response_ring, ha->response_dma);
2267 if (ha->request_ring)
2268 dma_free_coherent(&ha->pdev->dev,
2269 (ha->request_q_length + 1) * sizeof(request_t),
2270 ha->request_ring, ha->request_dma);
2273 ha->sns_cmd_dma = 0;
2277 ha->ms_iocb_dma = 0;
2278 ha->iodesc_pd = NULL;
2279 ha->iodesc_pd_dma = 0;
2281 ha->init_cb_dma = 0;
2283 ha->s_dma_pool = NULL;
2286 ha->rlc_rsp_dma = 0;
2287 ha->gid_list = NULL;
2288 ha->gid_list_dma = 0;
2290 ha->response_ring = NULL;
2291 ha->response_dma = 0;
2292 ha->request_ring = NULL;
2293 ha->request_dma = 0;
2295 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
2296 fcport = list_entry(fcpl, fc_port_t, list);
2299 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
2300 fclun = list_entry(fcll, fc_lun_t, list);
2302 list_del_init(&fclun->list);
2307 list_del_init(&fcport->list);
2310 INIT_LIST_HEAD(&ha->fcports);
2313 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
2315 if (ha->fw_dump_buffer)
2316 vfree(ha->fw_dump_buffer);
2319 ha->fw_dump_reading = 0;
2320 ha->fw_dump_buffer = NULL;
2324 * qla2x00_allocate_sp_pool
2325 * This routine is called during initialization to allocate
2326 * memory for local srb_t.
2329 * ha = adapter block pointer.
2334 * Note: Sets the ref_count for non Null sp to one.
2337 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
2342 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
2343 mempool_free_slab, srb_cachep);
2344 if (ha->srb_mempool == NULL) {
2345 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
2346 rval = QLA_FUNCTION_FAILED;
2352 * This routine frees all adapter allocated memory.
2356 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
2358 if (ha->srb_mempool) {
2359 mempool_destroy(ha->srb_mempool);
2360 ha->srb_mempool = NULL;
2364 /**************************************************************************
2366 * This kernel thread is a task that is schedule by the interrupt handler
2367 * to perform the background processing for interrupts.
2370 * This task always run in the context of a kernel thread. It
2371 * is kick-off by the driver's detect code and starts up
2372 * up one per adapter. It immediately goes to sleep and waits for
2373 * some fibre event. When either the interrupt handler or
2374 * the timer routine detects a event it will one of the task
2375 * bits then wake us up.
2376 **************************************************************************/
2378 qla2x00_do_dpc(void *data)
2380 DECLARE_MUTEX_LOCKED(sem);
2381 scsi_qla_host_t *ha;
2384 uint16_t next_loopid;
2386 ha = (scsi_qla_host_t *)data;
2390 daemonize("%s_dpc", ha->host_str);
2391 allow_signal(SIGHUP);
2393 ha->dpc_wait = &sem;
2395 set_user_nice(current, -20);
2399 complete(&ha->dpc_inited);
2402 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2404 if (down_interruptible(&sem))
2407 if (ha->dpc_should_die)
2410 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2412 /* Initialization not yet finished. Don't do anything yet. */
2413 if (!ha->flags.init_done || ha->dpc_active)
2416 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
2420 if (ha->flags.mbox_busy) {
2425 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
2427 DEBUG(printk("scsi(%ld): dpc: sched "
2428 "qla2x00_abort_isp ha = %p\n",
2430 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2433 if (qla2x00_abort_isp(ha)) {
2434 /* failed. retry later */
2435 set_bit(ISP_ABORT_NEEDED,
2438 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2440 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2444 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
2445 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
2447 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2450 qla2x00_rst_aen(ha);
2451 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
2454 /* Retry each device up to login retry count */
2455 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2456 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
2457 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2459 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2463 list_for_each_entry(fcport, &ha->fcports, list) {
2464 if (fcport->port_type != FCT_TARGET)
2468 * If the port is not ONLINE then try to login
2469 * to it if we haven't run out of retries.
2471 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2472 fcport->login_retry) {
2474 fcport->login_retry--;
2475 if (fcport->flags & FCF_FABRIC_DEVICE) {
2478 qla2x00_fabric_logout(
2481 status = qla2x00_fabric_login(
2482 ha, fcport, &next_loopid);
2485 qla2x00_local_device_login(
2486 ha, fcport->loop_id);
2488 if (status == QLA_SUCCESS) {
2489 fcport->old_loop_id = fcport->loop_id;
2491 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2492 ha->host_no, fcport->loop_id));
2494 fcport->port_login_retry_count =
2495 ha->port_down_retry_count * PORT_RETRY_TIME;
2496 atomic_set(&fcport->state, FCS_ONLINE);
2497 atomic_set(&fcport->port_down_timer,
2498 ha->port_down_retry_count * PORT_RETRY_TIME);
2500 fcport->login_retry = 0;
2501 } else if (status == 1) {
2502 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2503 /* retry the login again */
2504 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2506 fcport->login_retry, fcport->loop_id));
2508 fcport->login_retry = 0;
2511 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2514 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2518 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
2519 atomic_read(&ha->loop_state) != LOOP_DOWN) {
2521 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
2522 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2525 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
2527 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2531 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
2533 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2536 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2539 qla2x00_loop_resync(ha);
2541 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
2544 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2548 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
2550 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2553 qla2x00_rescan_fcports(ha);
2555 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2560 if (!ha->interrupts_on)
2561 qla2x00_enable_intrs(ha);
2564 } /* End of while(1) */
2566 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
2569 * Make sure that nobody tries to wake us up again.
2571 ha->dpc_wait = NULL;
2574 complete_and_exit(&ha->dpc_exited, 0);
2579 * Processes asynchronous reset.
2582 * ha = adapter block pointer.
2585 qla2x00_rst_aen(scsi_qla_host_t *ha)
2587 if (ha->flags.online && !ha->flags.reset_active &&
2588 !atomic_read(&ha->loop_down_timer) &&
2589 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
2591 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
2594 * Issue marker command only when we are going to start
2597 ha->marker_needed = 1;
2598 } while (!atomic_read(&ha->loop_down_timer) &&
2599 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
2605 * This routine will allocate SP from the free queue
2612 qla2x00_get_new_sp(scsi_qla_host_t *ha)
2616 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
2618 atomic_set(&sp->ref_count, 1);
2623 qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2625 struct scsi_cmnd *cmd = sp->cmd;
2627 if (sp->flags & SRB_DMA_VALID) {
2629 dma_unmap_sg(&ha->pdev->dev, cmd->request_buffer,
2630 cmd->use_sg, cmd->sc_data_direction);
2631 } else if (cmd->request_bufflen) {
2632 dma_unmap_single(&ha->pdev->dev, sp->dma_handle,
2633 cmd->request_bufflen, cmd->sc_data_direction);
2635 sp->flags &= ~SRB_DMA_VALID;
2640 qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2642 struct scsi_cmnd *cmd = sp->cmd;
2644 qla2x00_sp_free_dma(ha, sp);
2647 mempool_free(sp, ha->srb_mempool);
2649 cmd->scsi_done(cmd);
2651 /**************************************************************************
2657 * Context: Interrupt
2658 ***************************************************************************/
2660 qla2x00_timer(scsi_qla_host_t *ha)
2662 unsigned long cpu_flags = 0;
2670 * Ports - Port down timer.
2672 * Whenever, a port is in the LOST state we start decrementing its port
2673 * down timer every second until it reaches zero. Once it reaches zero
2674 * the port it marked DEAD.
2677 list_for_each_entry(fcport, &ha->fcports, list) {
2678 if (fcport->port_type != FCT_TARGET)
2681 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2683 if (atomic_read(&fcport->port_down_timer) == 0)
2686 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
2687 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
2689 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2692 t, atomic_read(&fcport->port_down_timer)));
2695 } /* End of for fcport */
2698 /* Loop down handler. */
2699 if (atomic_read(&ha->loop_down_timer) > 0 &&
2700 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
2702 if (atomic_read(&ha->loop_down_timer) ==
2703 ha->loop_down_abort_time) {
2705 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2706 "queues before time expire\n",
2709 if (!IS_QLA2100(ha) && ha->link_down_timeout)
2710 atomic_set(&ha->loop_state, LOOP_DEAD);
2712 /* Schedule an ISP abort to return any tape commands. */
2713 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
2714 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
2716 sp = ha->outstanding_cmds[index];
2719 if (!(sp->fclun->fcport->flags &
2723 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2726 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
2728 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
2732 /* if the loop has been down for 4 minutes, reinit adapter */
2733 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
2734 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2735 "restarting queues.\n",
2738 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
2741 if (!(ha->device_flags & DFLG_NO_CABLE)) {
2742 DEBUG(printk("scsi(%ld): Loop down - "
2745 qla_printk(KERN_WARNING, ha,
2746 "Loop down - aborting ISP.\n");
2748 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
2751 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2753 atomic_read(&ha->loop_down_timer)));
2756 /* Schedule the DPC routine if needed */
2757 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
2758 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
2760 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
2761 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) ||
2762 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
2763 ha->dpc_wait && !ha->dpc_active) {
2768 qla2x00_restart_timer(ha, WATCH_INTERVAL);
2771 /* XXX(hch): crude hack to emulate a down_timeout() */
2773 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2775 const unsigned int step = HZ/10;
2778 if (!down_trylock(sema))
2780 set_current_state(TASK_INTERRUPTIBLE);
2781 if (schedule_timeout(step))
2783 } while ((timeout -= step) > 0);
2789 * qla2x00_module_init - Module initialization.
2792 qla2x00_module_init(void)
2794 /* Allocate cache for SRBs. */
2795 sprintf(srb_cachep_name, "qla2xxx_srbs");
2796 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
2797 SLAB_HWCACHE_ALIGN, NULL, NULL);
2798 if (srb_cachep == NULL) {
2800 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
2804 /* Derive version string. */
2805 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
2807 strcat(qla2x00_version_str, "-debug");
2809 qla2xxx_transport_template = qla2x00_alloc_transport_tmpl();
2810 if (!qla2xxx_transport_template)
2813 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
2818 * qla2x00_module_exit - Module cleanup.
2821 qla2x00_module_exit(void)
2823 /* Free SRBs cache. */
2824 if (srb_cachep != NULL) {
2825 if (kmem_cache_destroy(srb_cachep) != 0) {
2827 "qla2xxx: Unable to free SRB cache...Memory pools "
2833 fc_release_transport(qla2xxx_transport_template);
2836 module_init(qla2x00_module_init);
2837 module_exit(qla2x00_module_exit);
2839 MODULE_AUTHOR("QLogic Corporation");
2840 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
2841 MODULE_LICENSE("GPL");
2842 MODULE_VERSION(QLA2XXX_VERSION);