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;
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 qla2x00_queuecommand(struct scsi_cmnd *cmd,
155 void (*fn)(struct scsi_cmnd *));
156 static int qla2xxx_eh_abort(struct scsi_cmnd *);
157 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
158 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
159 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
160 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
161 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
163 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
166 static struct scsi_host_template qla2x00_driver_template = {
167 .module = THIS_MODULE,
169 .proc_name = "qla2xxx",
170 .proc_info = qla2x00_proc_info,
171 .queuecommand = qla2x00_queuecommand,
173 .eh_abort_handler = qla2xxx_eh_abort,
174 .eh_device_reset_handler = qla2xxx_eh_device_reset,
175 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
176 .eh_host_reset_handler = qla2xxx_eh_host_reset,
178 .slave_configure = qla2xxx_slave_configure,
182 .use_clustering = ENABLE_CLUSTERING,
183 .sg_tablesize = SG_ALL,
186 * The RISC allows for each command to transfer (2^32-1) bytes of data,
187 * which equates to 0x800000 sectors.
189 .max_sectors = 0xFFFF,
192 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
194 static void qla2x00_display_fc_names(scsi_qla_host_t *);
196 /* TODO Convert to inlines
200 #define WATCH_INTERVAL 1 /* number of seconds */
202 static void qla2x00_timer(scsi_qla_host_t *);
204 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
205 void *, unsigned long);
206 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
207 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
210 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
212 init_timer(&ha->timer);
213 ha->timer.expires = jiffies + interval * HZ;
214 ha->timer.data = (unsigned long)ha;
215 ha->timer.function = (void (*)(unsigned long))func;
216 add_timer(&ha->timer);
217 ha->timer_active = 1;
221 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
223 mod_timer(&ha->timer, jiffies + interval * HZ);
226 static __inline__ void
227 qla2x00_stop_timer(scsi_qla_host_t *ha)
229 del_timer_sync(&ha->timer);
230 ha->timer_active = 0;
233 void qla2x00_cmd_timeout(srb_t *);
235 static __inline__ void qla2x00_callback(scsi_qla_host_t *, struct scsi_cmnd *);
236 static __inline__ void sp_put(struct scsi_qla_host * ha, srb_t *sp);
237 static __inline__ void sp_get(struct scsi_qla_host * ha, srb_t *sp);
238 static __inline__ void
239 qla2x00_delete_from_done_queue(scsi_qla_host_t *, srb_t *);
243 * Returns the completed SCSI command to LINUX.
246 * ha -- Host adapter structure
247 * cmd -- SCSI mid-level command structure.
250 * Note:From failover point of view we always get the sp
251 * from vis_ha pool in queuecommand.So when we put it
252 * back to the pool it has to be the vis_ha.
253 * So rely on struct scsi_cmnd to get the vis_ha and not on sp.
256 qla2x00_callback(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
258 srb_t *sp = (srb_t *) CMD_SP(cmd);
259 scsi_qla_host_t *vis_ha;
262 unsigned long cpu_flags = 0;
264 cmd->host_scribble = (unsigned char *) NULL;
265 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
268 qla_printk(KERN_INFO, ha,
269 "%s(): **** CMD derives a NULL SP\n",
276 * If command status is not DID_BUS_BUSY then go ahead and freed sp.
279 * Cancel command timeout
281 qla2x00_delete_timer_from_cmd(sp);
284 * Put SP back in the free queue
289 got_sense = (sp->flags & SRB_GOT_SENSE)? 1: 0;
290 add_to_free_queue(vis_ha, sp);
292 if (host_byte(cmd->result) == DID_OK) {
294 ha->total_bytes += cmd->bufflen;
296 /* If lun was suspended then clear retry count */
297 spin_lock_irqsave(&lq->q_lock, cpu_flags);
298 if (!test_bit(LUN_EXEC_DELAYED, &lq->q_flag))
299 lq->q_state = LUN_STATE_READY;
300 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
302 } else if (host_byte(cmd->result) == DID_ERROR) {
304 ha->total_dev_errs++;
307 /* Call the mid-level driver interrupt handler */
308 (*(cmd)->scsi_done)(cmd);
311 /**************************************************************************
315 * Decrement reference count and call the callback if we're the last
316 * owner of the specified sp. Will get the host_lock before calling
320 * ha - pointer to the scsi_qla_host_t where the callback is to occur.
321 * sp - pointer to srb_t structure to use.
325 **************************************************************************/
327 sp_put(struct scsi_qla_host * ha, srb_t *sp)
329 if (atomic_read(&sp->ref_count) == 0) {
330 qla_printk(KERN_INFO, ha,
331 "%s(): **** SP->ref_count not zero\n",
338 if (!atomic_dec_and_test(&sp->ref_count)) {
342 qla2x00_callback(ha, sp->cmd);
345 /**************************************************************************
349 * Increment reference count of the specified sp.
352 * sp - pointer to srb_t structure to use.
356 **************************************************************************/
358 sp_get(struct scsi_qla_host * ha, srb_t *sp)
360 atomic_inc(&sp->ref_count);
362 if (atomic_read(&sp->ref_count) > 2) {
363 qla_printk(KERN_INFO, ha,
364 "%s(): **** SP->ref_count greater than two\n",
373 qla2x00_delete_from_done_queue(scsi_qla_host_t *dest_ha, srb_t *sp)
375 /* remove command from done list */
376 list_del_init(&sp->list);
377 dest_ha->done_q_cnt--;
378 sp->state = SRB_NO_QUEUE_STATE;
380 if (sp->flags & SRB_DMA_VALID) {
381 sp->flags &= ~SRB_DMA_VALID;
383 /* Release memory used for this I/O */
384 if (sp->cmd->use_sg) {
385 pci_unmap_sg(dest_ha->pdev, sp->cmd->request_buffer,
386 sp->cmd->use_sg, sp->cmd->sc_data_direction);
387 } else if (sp->cmd->request_bufflen) {
388 pci_unmap_page(dest_ha->pdev, sp->dma_handle,
389 sp->cmd->request_bufflen,
390 sp->cmd->sc_data_direction);
395 static int qla2x00_do_dpc(void *data);
397 static void qla2x00_rst_aen(scsi_qla_host_t *);
399 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
400 static void qla2x00_mem_free(scsi_qla_host_t *ha);
401 static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
402 static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
403 static srb_t *qla2x00_get_new_sp(scsi_qla_host_t *ha);
405 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
407 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
409 static struct bin_attribute sysfs_fw_dump_attr = {
412 .mode = S_IRUSR | S_IWUSR,
413 .owner = THIS_MODULE,
416 .read = qla2x00_sysfs_read_fw_dump,
417 .write = qla2x00_sysfs_write_fw_dump,
419 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
421 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
423 static struct bin_attribute sysfs_nvram_attr = {
426 .mode = S_IRUSR | S_IWUSR,
427 .owner = THIS_MODULE,
429 .size = sizeof(nvram_t),
430 .read = qla2x00_sysfs_read_nvram,
431 .write = qla2x00_sysfs_write_nvram,
434 /* -------------------------------------------------------------------------- */
437 /* SysFS attributes. */
438 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
439 loff_t off, size_t count)
441 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
442 struct device, kobj)));
444 if (ha->fw_dump_reading == 0)
446 if (off > ha->fw_dump_buffer_len)
448 if (off + count > ha->fw_dump_buffer_len)
449 count = ha->fw_dump_buffer_len - off;
451 memcpy(buf, &ha->fw_dump_buffer[off], count);
456 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
457 loff_t off, size_t count)
459 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
460 struct device, kobj)));
467 reading = simple_strtol(buf, NULL, 10);
470 if (ha->fw_dump_reading == 1) {
471 qla_printk(KERN_INFO, ha,
472 "Firmware dump cleared on (%ld).\n",
475 vfree(ha->fw_dump_buffer);
476 free_pages((unsigned long)ha->fw_dump,
479 ha->fw_dump_reading = 0;
480 ha->fw_dump_buffer = NULL;
485 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
486 ha->fw_dump_reading = 1;
488 dump_size = FW_DUMP_SIZE_1M;
489 if (ha->fw_memory_size < 0x20000)
490 dump_size = FW_DUMP_SIZE_128K;
491 else if (ha->fw_memory_size < 0x80000)
492 dump_size = FW_DUMP_SIZE_512K;
493 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
494 if (ha->fw_dump_buffer == NULL) {
495 qla_printk(KERN_WARNING, ha,
496 "Unable to allocate memory for firmware "
497 "dump buffer (%d).\n", dump_size);
499 ha->fw_dump_reading = 0;
502 qla_printk(KERN_INFO, ha,
503 "Firmware dump ready for read on (%ld).\n",
505 memset(ha->fw_dump_buffer, 0, dump_size);
506 if (IS_QLA2100(ha) || IS_QLA2200(ha))
507 qla2100_ascii_fw_dump(ha);
509 qla2300_ascii_fw_dump(ha);
510 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
517 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
518 loff_t off, size_t count)
520 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
521 struct device, kobj)));
526 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
530 spin_lock_irqsave(&ha->hardware_lock, flags);
531 qla2x00_lock_nvram_access(ha);
532 witer = (uint16_t *)buf;
533 for (cnt = 0; cnt < count / 2; cnt++) {
534 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
535 cnt+ha->nvram_base));
538 qla2x00_unlock_nvram_access(ha);
539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
544 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
545 loff_t off, size_t count)
547 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
548 struct device, kobj)));
555 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
558 /* Checksum NVRAM. */
559 iter = (uint8_t *)buf;
561 for (cnt = 0; cnt < count - 1; cnt++)
563 chksum = ~chksum + 1;
567 spin_lock_irqsave(&ha->hardware_lock, flags);
568 qla2x00_lock_nvram_access(ha);
569 qla2x00_release_nvram_protection(ha);
570 witer = (uint16_t *)buf;
571 for (cnt = 0; cnt < count / 2; cnt++) {
572 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
573 cpu_to_le16(*witer));
576 qla2x00_unlock_nvram_access(ha);
577 spin_unlock_irqrestore(&ha->hardware_lock, flags);
582 /* -------------------------------------------------------------------------- */
584 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
586 static char *pci_bus_modes[] = {
587 "33", "66", "100", "133",
592 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
595 strcat(str, pci_bus_modes[pci_bus]);
597 pci_bus = (ha->pci_attr & BIT_8) >> 8;
599 strcat(str, pci_bus_modes[pci_bus]);
601 strcat(str, " MHz)");
607 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
611 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
612 ha->fw_minor_version,
613 ha->fw_subminor_version);
615 if (ha->fw_attributes & BIT_9) {
620 switch (ha->fw_attributes & 0xFF) {
634 sprintf(un_str, "(%x)", ha->fw_attributes);
638 if (ha->fw_attributes & 0x100)
644 /**************************************************************************
645 * qla2x00_queuecommand
648 * Queue a command to the controller.
651 * cmd - pointer to Scsi cmd structure
652 * fn - pointer to Scsi done function
658 * The mid-level driver tries to ensures that queuecommand never gets invoked
659 * concurrently with itself or the interrupt handler (although the
660 * interrupt handler may call this routine as part of request-completion
662 **************************************************************************/
664 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
669 scsi_qla_host_t *ha, *ha2;
671 struct Scsi_Host *host;
672 unsigned int b, t, l;
673 unsigned long handle;
677 host = cmd->device->host;
678 ha = (scsi_qla_host_t *) host->hostdata;
683 spin_unlock_irq(ha->host->host_lock);
686 * Allocate a command packet from the "sp" pool. If we cant get back
687 * one then let scsi layer come back later.
689 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
690 qla_printk(KERN_WARNING, ha,
691 "Couldn't allocate memory for sp - retried.\n");
693 spin_lock_irq(ha->host->host_lock);
699 CMD_SP(cmd) = (void *)sp;
702 if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {
703 /* Need to set sp->flags */
704 sp->flags |= SRB_IOCTL;
705 CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */
708 sp->fo_retry_cnt = 0;
711 /* Generate LU queue on bus, target, LUN */
712 b = cmd->device->channel;
714 l = cmd->device->lun;
717 * Start Command Timer. Typically it will be 2 seconds less than what
718 * is requested by the Host such that we can return the IO before
721 if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)
722 qla2x00_add_timer_to_cmd(sp,
723 (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
725 qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);
727 if (l >= ha->max_luns) {
728 cmd->result = DID_NO_CONNECT << 16;
729 sp->err_id = SRB_ERR_PORT;
731 spin_lock_irq(ha->host->host_lock);
738 if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&
739 (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {
740 fcport = lq->fclun->fcport;
748 /* Set an invalid handle until we issue the command to ISP */
749 /* then we will set the real handle value. */
750 handle = INVALID_HANDLE;
751 cmd->host_scribble = (unsigned char *)handle;
753 /* Bookkeeping information */
754 sp->r_start = jiffies; /* Time the request was recieved. */
757 /* Setup device queue pointers. */
764 * 1. When device is added from persistent binding but has not been
765 * discovered yet.The state of loopid == PORT_AVAIL.
766 * 2. When device is never found on the bus.(loopid == UNUSED)
768 * IF Device Queue is not created, or device is not in a valid state
769 * and link down error reporting is enabled, reject IO.
771 if (fcport == NULL) {
772 DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",
775 cmd->result = DID_NO_CONNECT << 16;
776 sp->err_id = SRB_ERR_PORT;
778 spin_lock_irq(ha->host->host_lock);
785 /* Only modify the allowed count if the target is a *non* tape device */
786 if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {
787 sp->flags &= ~SRB_TAPE;
788 if (cmd->allowed < ql2xretrycount) {
789 cmd->allowed = ql2xretrycount;
792 sp->flags |= SRB_TAPE;
794 DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "
795 "flags=0x%x fo retry=%d, pid=%ld\n",
796 ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,
797 cmd->serial_number));
798 DEBUG5(qla2x00_print_scsi_cmd(cmd));
800 sp->fclun = lq->fclun;
803 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&
804 cmd->request_bufflen != 0) {
806 DEBUG2(printk(KERN_WARNING
807 "scsi(%ld): Incorrect data direction - transfer "
808 "length=%d, direction=%d, pid=%ld, opcode=%x\n",
809 ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,
810 cmd->serial_number, cmd->cmnd[0]));
815 * Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.
817 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
818 atomic_read(&ha2->loop_state) == LOOP_DEAD) {
820 * Add the command to the done-queue for later failover
823 cmd->result = DID_NO_CONNECT << 16;
824 if (atomic_read(&ha2->loop_state) == LOOP_DOWN)
825 sp->err_id = SRB_ERR_LOOP;
827 sp->err_id = SRB_ERR_PORT;
829 add_to_done_queue(ha, sp);
832 spin_lock_irq(ha->host->host_lock);
836 if (tq && test_bit(TQF_SUSPENDED, &tq->flags) &&
837 (sp->flags & SRB_TAPE) == 0) {
838 /* If target suspended put incoming I/O in retry_q. */
839 qla2x00_extend_timeout(sp->cmd, 10);
840 add_to_scsi_retry_queue(ha, sp);
842 was_empty = add_to_pending_queue(ha, sp);
844 if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {
845 if (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
848 spin_lock_irqsave(&ha->hardware_lock, flags);
849 qla2x00_process_response_queue(ha);
850 spin_unlock_irqrestore(&ha->hardware_lock, flags);
854 /* We submit to the hardware if:
856 * 1) we're on the cpu the irq's arrive on or
857 * 2) there are very few io's outstanding.
859 * In all other cases we'll let an irq pick up our IO and submit it
860 * to the controller to improve affinity.
862 if (_smp_processor_id() == ha->last_irq_cpu || was_empty)
865 spin_lock_irq(ha->host->host_lock);
871 * qla2x00_eh_wait_on_command
872 * Waits for the command to be returned by the Firmware for some
876 * ha = actual ha whose done queue will contain the command
877 * returned by firmware.
878 * cmd = Scsi Command to wait on.
879 * flag = Abort/Reset(Bus or Device Reset)
886 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
888 #define ABORT_POLLING_PERIOD HZ
889 #define ABORT_WAIT_TIME ((10 * HZ) / (ABORT_POLLING_PERIOD))
894 struct list_head *list, *temp;
895 u_long max_wait_time = ABORT_WAIT_TIME;
898 /* Check on done queue */
899 spin_lock(&ha->list_lock);
900 list_for_each_safe(list, temp, &ha->done_queue) {
901 rp = list_entry(list, srb_t, list);
904 * Found command. Just exit and wait for the cmd sent
907 if (cmd == rp->cmd) {
909 DEBUG3(printk("%s: found in done queue.\n",
914 spin_unlock(&ha->list_lock);
916 /* Complete the cmd right away. */
918 qla2x00_delete_from_done_queue(ha, rp);
924 spin_unlock_irq(ha->host->host_lock);
926 set_current_state(TASK_UNINTERRUPTIBLE);
927 schedule_timeout(ABORT_POLLING_PERIOD);
929 spin_lock_irq(ha->host->host_lock);
931 } while ((max_wait_time--));
934 DEBUG2(printk(KERN_INFO "%s: found cmd=%p.\n", __func__, cmd));
940 * qla2x00_wait_for_hba_online
941 * Wait till the HBA is online after going through
942 * <= MAX_RETRIES_OF_ISP_ABORT or
943 * finally HBA is disabled ie marked offline
946 * ha - pointer to host adapter structure
949 * Does context switching-Release SPIN_LOCK
950 * (if any) before calling this routine.
953 * Success (Adapter is online) : 0
954 * Failed (Adapter is offline/disabled) : 1
957 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
960 unsigned long wait_online;
962 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
963 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
964 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
965 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
966 ha->dpc_active) && time_before(jiffies, wait_online)) {
970 if (ha->flags.online)
971 return_status = QLA_SUCCESS;
973 return_status = QLA_FUNCTION_FAILED;
975 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
977 return (return_status);
981 * qla2x00_wait_for_loop_ready
982 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
983 * to be in LOOP_READY state.
985 * ha - pointer to host adapter structure
988 * Does context switching-Release SPIN_LOCK
989 * (if any) before calling this routine.
993 * Success (LOOP_READY) : 0
994 * Failed (LOOP_NOT_READY) : 1
997 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
999 int return_status = QLA_SUCCESS;
1000 unsigned long loop_timeout ;
1002 /* wait for 5 min at the max for loop to be ready */
1003 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1005 while ((!atomic_read(&ha->loop_down_timer) &&
1006 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
1007 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
1008 atomic_read(&ha->loop_state) != LOOP_READY) {
1010 if (time_after_eq(jiffies, loop_timeout)) {
1011 return_status = QLA_FUNCTION_FAILED;
1015 return (return_status);
1018 /**************************************************************************
1022 * The abort function will abort the specified command.
1025 * cmd = Linux SCSI command packet to be aborted.
1028 * Either SUCCESS or FAILED.
1031 **************************************************************************/
1033 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1036 int return_status = FAILED;
1038 scsi_qla_host_t *ha;
1039 scsi_qla_host_t *vis_ha;
1042 struct list_head *list, *temp;
1043 struct Scsi_Host *host;
1045 unsigned int b, t, l;
1047 /* Get the SCSI request ptr */
1048 sp = (srb_t *) CMD_SP(cmd);
1051 * If sp is NULL, command is already returned.
1052 * sp is NULLED just before we call back scsi_done
1056 /* no action - we don't have command */
1057 qla_printk(KERN_INFO, to_qla_host(cmd->device->host),
1058 "qla2xxx_eh_abort: cmd already done sp=%p\n", sp);
1059 DEBUG(printk("qla2xxx_eh_abort: cmd already done sp=%p\n", sp);)
1063 DEBUG(printk("qla2xxx_eh_abort: refcount %i \n",
1064 atomic_read(&sp->ref_count));)
1067 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1068 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1072 /* Generate LU queue on bus, target, LUN */
1073 b = cmd->device->channel;
1074 t = cmd->device->id;
1075 l = cmd->device->lun;
1076 q = GET_LU_Q(vis_ha, t, l);
1078 qla_printk(KERN_INFO, ha,
1079 "%s scsi(%ld:%d:%d:%d): cmd_timeout_in_sec=0x%x.\n", __func__,
1080 ha->host_no, (int)b, (int)t, (int)l,
1081 cmd->timeout_per_command / HZ);
1084 * if no LUN queue then something is very wrong!!!
1087 qla_printk(KERN_WARNING, ha,
1088 "qla2x00: (%x:%x:%x) No LUN queue.\n", b, t, l);
1090 /* no action - we don't have command */
1094 DEBUG2(printk("scsi(%ld): ABORTing cmd=%p sp=%p jiffies = 0x%lx, "
1095 "timeout=%x, dpc_flags=%lx, vis_ha->dpc_flags=%lx q->flag=%lx\n",
1096 ha->host_no, cmd, sp, jiffies, cmd->timeout_per_command / HZ,
1097 ha->dpc_flags, vis_ha->dpc_flags, q->q_flag));
1098 DEBUG2(qla2x00_print_scsi_cmd(cmd));
1100 spin_unlock_irq(ha->host->host_lock);
1101 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1102 DEBUG2(printk("%s failed:board disabled\n", __func__);)
1103 spin_lock_irq(ha->host->host_lock);
1106 spin_lock_irq(ha->host->host_lock);
1108 /* Search done queue */
1109 spin_lock(&ha->list_lock);
1110 list_for_each_safe(list, temp, &ha->done_queue) {
1111 rp = list_entry(list, srb_t, list);
1117 * Found command.Remove it from done list.
1118 * And proceed to post completion to scsi mid layer.
1120 return_status = SUCCESS;
1122 qla2x00_delete_from_done_queue(ha, sp);
1125 } /* list_for_each_safe() */
1126 spin_unlock(&ha->list_lock);
1129 * Return immediately if the aborted command was already in the done
1133 qla_printk(KERN_INFO, ha,
1134 "qla2xxx_eh_abort: Returning completed command=%p sp=%p\n",
1137 return (return_status);
1142 * See if this command is in the retry queue
1144 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p in retry "
1147 spin_lock(&ha->list_lock);
1148 list_for_each_safe(list, temp, &ha->retry_queue) {
1149 rp = list_entry(list, srb_t, list);
1155 DEBUG2(printk("qla2xxx_eh_abort: found "
1156 "in retry queue. SP=%p\n", sp);)
1158 __del_from_retry_queue(ha, rp);
1159 cmd->result = DID_ABORT << 16;
1160 __add_to_done_queue(ha, rp);
1162 return_status = SUCCESS;
1168 spin_unlock(&ha->list_lock);
1172 * Our SP pointer points at the command we want to remove from the
1173 * pending queue providing we haven't already sent it to the adapter.
1176 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1177 "in pending queue.\n", sp);)
1179 spin_lock(&vis_ha->list_lock);
1180 list_for_each_safe(list, temp, &vis_ha->pending_queue) {
1181 rp = list_entry(list, srb_t, list);
1186 /* Remove srb from LUN queue. */
1187 rp->flags |= SRB_ABORTED;
1189 DEBUG2(printk("qla2xxx_eh_abort: Cmd in pending queue."
1190 " serial_number %ld.\n",
1191 sp->cmd->serial_number);)
1193 __del_from_pending_queue(vis_ha, rp);
1194 cmd->result = DID_ABORT << 16;
1196 __add_to_done_queue(vis_ha, rp);
1198 return_status = SUCCESS;
1202 } /* list_for_each_safe() */
1203 spin_unlock(&vis_ha->list_lock);
1204 } /*End of if !found */
1206 if (!found) { /* find the command in our active list */
1207 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1208 "in outstanding queue.\n", sp);)
1210 spin_lock(&ha->hardware_lock);
1211 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1212 sp = ha->outstanding_cmds[i];
1220 DEBUG2(printk("qla2xxx_eh_abort(%ld): aborting sp %p "
1221 "from RISC. pid=%ld sp->state=%x q->q_flag=%lx\n",
1222 ha->host_no, sp, sp->cmd->serial_number,
1223 sp->state, q->q_flag);)
1224 DEBUG(qla2x00_print_scsi_cmd(cmd);)
1226 /* Get a reference to the sp and drop the lock.*/
1229 spin_unlock(&ha->hardware_lock);
1230 spin_unlock_irq(ha->host->host_lock);
1232 if (qla2x00_abort_command(ha, sp)) {
1233 DEBUG2(printk("qla2xxx_eh_abort: abort_command "
1235 return_status = FAILED;
1237 DEBUG3(printk("qla2xxx_eh_abort: abort_command "
1238 " mbx success.\n");)
1239 return_status = SUCCESS;
1244 spin_lock_irq(ha->host->host_lock);
1245 spin_lock(&ha->hardware_lock);
1248 * Regardless of mailbox command status, go check on
1249 * done queue just in case the sp is already done.
1253 }/*End of for loop */
1254 spin_unlock(&ha->hardware_lock);
1256 } /*End of if !found */
1258 /* Waiting for our command in done_queue to be returned to OS.*/
1259 if (qla2x00_eh_wait_on_command(ha, cmd) != 0) {
1260 DEBUG2(printk("qla2xxx_eh_abort: cmd returned back to OS.\n");)
1261 return_status = SUCCESS;
1264 if (return_status == FAILED) {
1265 qla_printk(KERN_INFO, ha,
1266 "qla2xxx_eh_abort Exiting: status=Failed\n");
1270 DEBUG2(printk("qla2xxx_eh_abort: Exiting. return_status=0x%x.\n",
1273 return return_status;
1276 /**************************************************************************
1277 * qla2x00_eh_wait_for_pending_target_commands
1280 * Waits for all the commands to come back from the specified target.
1283 * ha - pointer to scsi_qla_host structure.
1286 * Either SUCCESS or FAILED.
1289 **************************************************************************/
1291 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
1296 struct scsi_cmnd *cmd;
1301 * Waiting for all commands for the designated target in the active
1304 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1305 spin_lock(&ha->hardware_lock);
1306 sp = ha->outstanding_cmds[cnt];
1309 spin_unlock(&ha->hardware_lock);
1310 if (cmd->device->id == t) {
1311 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
1318 spin_unlock(&ha->hardware_lock);
1325 /**************************************************************************
1326 * qla2xxx_eh_device_reset
1329 * The device reset function will reset the target and abort any
1330 * executing commands.
1332 * NOTE: The use of SP is undefined within this context. Do *NOT*
1333 * attempt to use this value, even if you determine it is
1337 * cmd = Linux SCSI command packet of the command that cause the
1341 * SUCCESS/FAILURE (defined as macro in scsi.h).
1343 **************************************************************************/
1345 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1348 unsigned int b, t, l;
1349 scsi_qla_host_t *ha;
1352 fc_port_t *fcport_to_reset;
1354 struct list_head *list, *temp;
1356 return_status = FAILED;
1359 "%s(): **** SCSI mid-layer passing in NULL cmd\n",
1362 return (return_status);
1365 b = cmd->device->channel;
1366 t = cmd->device->id;
1367 l = cmd->device->lun;
1368 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1372 qla_printk(KERN_INFO, ha,
1373 "%s(): **** CMD derives a NULL TGT_Q\n", __func__);
1375 return (return_status);
1377 lq = (os_lun_t *)LUN_Q(ha, t, l);
1380 "%s(): **** CMD derives a NULL LUN_Q\n", __func__);
1382 return (return_status);
1384 fcport_to_reset = lq->fclun->fcport;
1386 /* If we are coming in from the back-door, stall I/O until complete. */
1387 if (!cmd->device->host->eh_active)
1388 set_bit(TQF_SUSPENDED, &tq->flags);
1390 qla_printk(KERN_INFO, ha,
1391 "scsi(%ld:%d:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, b, t, l);
1393 DEBUG2(printk(KERN_INFO
1394 "scsi(%ld): DEVICE_RESET cmd=%p jiffies = 0x%lx, timeout=%x, "
1395 "dpc_flags=%lx, status=%x allowed=%d cmd.state=%x\n",
1396 ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
1397 ha->dpc_flags, cmd->result, cmd->allowed, cmd->state));
1399 /* Clear commands from the retry queue. */
1400 spin_lock(&ha->list_lock);
1401 list_for_each_safe(list, temp, &ha->retry_queue) {
1402 rp = list_entry(list, srb_t, list);
1404 if (t != rp->cmd->device->id)
1407 DEBUG2(printk(KERN_INFO
1408 "qla2xxx_eh_reset: found in retry queue. SP=%p\n", rp));
1410 __del_from_retry_queue(ha, rp);
1411 rp->cmd->result = DID_RESET << 16;
1412 __add_to_done_queue(ha, rp);
1414 spin_unlock(&ha->list_lock);
1416 spin_unlock_irq(ha->host->host_lock);
1418 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1419 DEBUG2(printk(KERN_INFO
1420 "%s failed:board disabled\n",__func__));
1422 spin_lock_irq(ha->host->host_lock);
1423 goto eh_dev_reset_done;
1426 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1427 if (qla2x00_device_reset(ha, fcport_to_reset) == 0) {
1428 return_status = SUCCESS;
1431 #if defined(LOGOUT_AFTER_DEVICE_RESET)
1432 if (return_status == SUCCESS) {
1433 if (fcport_to_reset->flags & FC_FABRIC_DEVICE) {
1434 qla2x00_fabric_logout(ha,
1435 fcport_to_reset->loop_id);
1436 qla2x00_mark_device_lost(ha, fcport_to_reset);
1441 DEBUG2(printk(KERN_INFO
1442 "%s failed: loop not ready\n",__func__);)
1445 spin_lock_irq(ha->host->host_lock);
1447 if (return_status == FAILED) {
1448 DEBUG3(printk("%s(%ld): device reset failed\n",
1449 __func__, ha->host_no));
1450 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
1453 goto eh_dev_reset_done;
1457 * If we are coming down the EH path, wait for all commands to
1458 * complete for the device.
1460 if (cmd->device->host->eh_active) {
1461 if (qla2x00_eh_wait_for_pending_target_commands(ha, t))
1462 return_status = FAILED;
1464 if (return_status == FAILED) {
1465 DEBUG3(printk("%s(%ld): failed while waiting for "
1466 "commands\n", __func__, ha->host_no));
1467 qla_printk(KERN_INFO, ha,
1468 "%s: failed while waiting for commands\n",
1471 goto eh_dev_reset_done;
1475 qla_printk(KERN_INFO, ha,
1476 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1477 ha->host_no, b, t, l);
1481 if (!cmd->device->host->eh_active)
1482 clear_bit(TQF_SUSPENDED, &tq->flags);
1484 return (return_status);
1487 /**************************************************************************
1488 * qla2x00_eh_wait_for_pending_commands
1491 * Waits for all the commands to come back from the specified host.
1494 * ha - pointer to scsi_qla_host structure.
1501 **************************************************************************/
1503 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
1508 struct scsi_cmnd *cmd;
1513 * Waiting for all commands for the designated target in the active
1516 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1517 spin_lock(&ha->hardware_lock);
1518 sp = ha->outstanding_cmds[cnt];
1521 spin_unlock(&ha->hardware_lock);
1522 status = qla2x00_eh_wait_on_command(ha, cmd);
1527 spin_unlock(&ha->hardware_lock);
1534 /**************************************************************************
1535 * qla2xxx_eh_bus_reset
1538 * The bus reset function will reset the bus and abort any executing
1542 * cmd = Linux SCSI command packet of the command that cause the
1546 * SUCCESS/FAILURE (defined as macro in scsi.h).
1548 **************************************************************************/
1550 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1552 scsi_qla_host_t *ha;
1556 ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1557 sp = (srb_t *) CMD_SP(cmd);
1559 qla_printk(KERN_INFO, ha,
1560 "scsi(%ld:%d:%d:%d): LOOP RESET ISSUED.\n", ha->host_no,
1561 cmd->device->channel, cmd->device->id, cmd->device->lun);
1563 spin_unlock_irq(ha->host->host_lock);
1565 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1566 DEBUG2(printk("%s failed:board disabled\n",__func__));
1567 spin_lock_irq(ha->host->host_lock);
1571 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1572 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
1576 spin_lock_irq(ha->host->host_lock);
1580 /* Waiting for our command in done_queue to be returned to OS.*/
1581 if (cmd->device->host->eh_active)
1582 if (!qla2x00_eh_wait_for_pending_commands(ha))
1586 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1587 (rval == FAILED) ? "failed" : "succeded");
1592 /**************************************************************************
1593 * qla2xxx_eh_host_reset
1596 * The reset function will reset the Adapter.
1599 * cmd = Linux SCSI command packet of the command that cause the
1603 * Either SUCCESS or FAILED.
1606 **************************************************************************/
1608 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1610 scsi_qla_host_t *ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1613 /* Display which one we're actually resetting for debug. */
1614 DEBUG(printk("qla2xxx_eh_host_reset:Resetting scsi(%ld).\n",
1620 qla_printk(KERN_INFO, ha,
1621 "scsi(%ld:%d:%d:%d): ADAPTER RESET issued.\n", ha->host_no,
1622 cmd->device->channel, cmd->device->id, cmd->device->lun);
1624 spin_unlock_irq(ha->host->host_lock);
1626 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1627 goto board_disabled;
1630 * Fixme-may be dpc thread is active and processing
1631 * loop_resync,so wait a while for it to
1632 * be completed and then issue big hammer.Otherwise
1633 * it may cause I/O failure as big hammer marks the
1634 * devices as lost kicking of the port_down_timer
1635 * while dpc is stuck for the mailbox to complete.
1637 /* Blocking call-Does context switching if loop is Not Ready */
1638 qla2x00_wait_for_loop_ready(ha);
1639 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1640 if (qla2x00_abort_isp(ha)) {
1641 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1642 /* failed. schedule dpc to try */
1643 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1645 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1646 goto board_disabled;
1649 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1651 spin_lock_irq(ha->host->host_lock);
1655 /* Waiting for our command in done_queue to be returned to OS.*/
1656 if (!qla2x00_eh_wait_for_pending_commands(ha))
1660 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1661 (rval == FAILED) ? "failed" : "succeded");
1666 spin_lock_irq(ha->host->host_lock);
1668 qla_printk(KERN_INFO, ha, "%s: failed:board disabled\n", __func__);
1674 * qla2x00_loop_reset
1678 * ha = adapter block pointer.
1684 qla2x00_loop_reset(scsi_qla_host_t *ha)
1686 int status = QLA_SUCCESS;
1690 if (ha->flags.enable_lip_reset) {
1691 status = qla2x00_lip_reset(ha);
1694 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1695 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1696 if ((tq = TGT_Q(ha, t)) == NULL)
1699 if (tq->fcport == NULL)
1702 status = qla2x00_target_reset(ha, 0, t);
1703 if (status != QLA_SUCCESS) {
1709 if (status == QLA_SUCCESS &&
1710 ((!ha->flags.enable_target_reset &&
1711 !ha->flags.enable_lip_reset) ||
1712 ha->flags.enable_lip_full_login)) {
1714 status = qla2x00_full_login_lip(ha);
1717 /* Issue marker command only when we are going to start the I/O */
1718 ha->marker_needed = 1;
1722 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1727 DEBUG3(printk("%s(%ld): exiting normally.\n",
1736 * qla2x00_device_reset
1737 * Issue bus device reset message to the target.
1740 * ha = adapter block pointer.
1742 * TARGET_QUEUE_LOCK must be released.
1743 * ADAPTER_STATE_LOCK must be released.
1749 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1751 /* Abort Target command will clear Reservation */
1752 return qla2x00_abort_target(reset_fcport);
1755 /**************************************************************************
1756 * qla2xxx_slave_configure
1759 **************************************************************************/
1761 qla2xxx_slave_configure(struct scsi_device *sdev)
1763 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1766 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1771 if (sdev->tagged_supported) {
1772 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1773 queue_depth = ql2xmaxqdepth;
1775 ql2xmaxqdepth = queue_depth;
1777 scsi_activate_tcq(sdev, queue_depth);
1779 qla_printk(KERN_INFO, ha,
1780 "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue "
1782 sdev->host->host_no, sdev->channel, sdev->id, sdev->lun,
1785 scsi_adjust_queue_depth(sdev, 0 /* TCQ off */,
1786 sdev->host->hostt->cmd_per_lun /* 3 */);
1793 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1796 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1797 * supported addressing method.
1800 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1802 /* Assume 32bit DMA address */
1803 ha->flags.enable_64bit_addressing = 0;
1804 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1805 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1808 * Given the two variants pci_set_dma_mask(), allow the compiler to
1809 * assist in setting the proper dma mask.
1811 if (sizeof(dma_addr_t) > 4) {
1812 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1813 ha->flags.enable_64bit_addressing = 1;
1814 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1815 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1817 if (pci_set_consistent_dma_mask(ha->pdev,
1819 qla_printk(KERN_DEBUG, ha,
1820 "Failed to set 64 bit PCI consistent mask; "
1822 pci_set_consistent_dma_mask(ha->pdev,
1826 qla_printk(KERN_DEBUG, ha,
1827 "Failed to set 64 bit PCI DMA mask, falling back "
1828 "to 32 bit MASK.\n");
1829 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1832 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1837 qla2x00_iospace_config(scsi_qla_host_t *ha)
1839 unsigned long pio, pio_len, pio_flags;
1840 unsigned long mmio, mmio_len, mmio_flags;
1842 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1843 pio = pci_resource_start(ha->pdev, 0);
1844 pio_len = pci_resource_len(ha->pdev, 0);
1845 pio_flags = pci_resource_flags(ha->pdev, 0);
1846 if (pio_flags & IORESOURCE_IO) {
1847 if (pio_len < MIN_IOBASE_LEN) {
1848 qla_printk(KERN_WARNING, ha,
1849 "Invalid PCI I/O region size (%s)...\n",
1850 pci_name(ha->pdev));
1854 qla_printk(KERN_WARNING, ha,
1855 "region #0 not a PIO resource (%s)...\n",
1856 pci_name(ha->pdev));
1860 /* Use MMIO operations for all accesses. */
1861 mmio = pci_resource_start(ha->pdev, 1);
1862 mmio_len = pci_resource_len(ha->pdev, 1);
1863 mmio_flags = pci_resource_flags(ha->pdev, 1);
1865 if (!(mmio_flags & IORESOURCE_MEM)) {
1866 qla_printk(KERN_ERR, ha,
1867 "region #0 not an MMIO resource (%s), aborting\n",
1868 pci_name(ha->pdev));
1869 goto iospace_error_exit;
1871 if (mmio_len < MIN_IOBASE_LEN) {
1872 qla_printk(KERN_ERR, ha,
1873 "Invalid PCI mem region size (%s), aborting\n",
1874 pci_name(ha->pdev));
1875 goto iospace_error_exit;
1878 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1879 qla_printk(KERN_WARNING, ha,
1880 "Failed to reserve PIO/MMIO regions (%s)\n",
1881 pci_name(ha->pdev));
1883 goto iospace_error_exit;
1886 ha->pio_address = pio;
1887 ha->pio_length = pio_len;
1888 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1890 qla_printk(KERN_ERR, ha,
1891 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1893 goto iospace_error_exit;
1903 * PCI driver interface
1905 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1908 device_reg_t __iomem *reg;
1909 struct Scsi_Host *host;
1910 scsi_qla_host_t *ha;
1911 unsigned long flags = 0;
1912 unsigned long wait_switch = 0;
1916 if (pci_enable_device(pdev))
1919 host = scsi_host_alloc(&qla2x00_driver_template,
1920 sizeof(scsi_qla_host_t));
1923 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1924 goto probe_disable_device;
1927 /* Clear our data area */
1928 ha = (scsi_qla_host_t *)host->hostdata;
1929 memset(ha, 0, sizeof(scsi_qla_host_t));
1933 ha->host_no = host->host_no;
1934 ha->brd_info = brd_info;
1935 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1937 /* Configure PCI I/O space */
1938 ret = qla2x00_iospace_config(ha);
1943 /* Sanitize the information from PCI BIOS. */
1944 host->irq = pdev->irq;
1946 qla_printk(KERN_INFO, ha,
1947 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1948 host->irq, ha->iobase);
1950 spin_lock_init(&ha->hardware_lock);
1952 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1955 ha->total_isr_cnt = 0;
1956 ha->total_isp_aborts = 0;
1957 ha->total_lip_cnt = 0;
1958 ha->total_dev_errs = 0;
1960 ha->total_bytes = 0;
1962 ha->prev_topology = 0;
1963 ha->ports = MAX_BUSES;
1965 if (IS_QLA2100(ha)) {
1966 ha->max_targets = MAX_TARGETS_2100;
1967 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1968 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1969 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1970 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1971 host->sg_tablesize = 32;
1972 } else if (IS_QLA2200(ha)) {
1973 ha->max_targets = MAX_TARGETS_2200;
1974 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1975 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1976 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1977 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1978 } else /*if (IS_QLA2300(ha))*/ {
1979 ha->max_targets = MAX_TARGETS_2200;
1980 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1981 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1982 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1983 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1985 host->can_queue = ha->request_q_length + 128;
1987 /* load the F/W, read paramaters, and init the H/W */
1988 ha->instance = num_hosts;
1990 init_MUTEX(&ha->mbx_cmd_sem);
1991 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1993 INIT_LIST_HEAD(&ha->list);
1994 INIT_LIST_HEAD(&ha->fcports);
1995 INIT_LIST_HEAD(&ha->rscn_fcports);
1996 INIT_LIST_HEAD(&ha->done_queue);
1997 INIT_LIST_HEAD(&ha->retry_queue);
1998 INIT_LIST_HEAD(&ha->scsi_retry_queue);
1999 INIT_LIST_HEAD(&ha->pending_queue);
2002 * These locks are used to prevent more than one CPU
2003 * from modifying the queue at the same time. The
2004 * higher level "host_lock" will reduce most
2005 * contention for these locks.
2007 spin_lock_init(&ha->mbx_reg_lock);
2008 spin_lock_init(&ha->list_lock);
2011 init_completion(&ha->dpc_inited);
2012 init_completion(&ha->dpc_exited);
2014 qla2x00_config_dma_addressing(ha);
2015 if (qla2x00_mem_alloc(ha)) {
2016 qla_printk(KERN_WARNING, ha,
2017 "[ERROR] Failed to allocate memory for adapter\n");
2022 if (qla2x00_initialize_adapter(ha) &&
2023 !(ha->device_flags & DFLG_NO_CABLE)) {
2025 qla_printk(KERN_WARNING, ha,
2026 "Failed to initialize adapter\n");
2028 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2029 "Adapter flags %x.\n",
2030 ha->host_no, ha->device_flags));
2036 * Startup the kernel thread for this host adapter
2038 ha->dpc_should_die = 0;
2039 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
2040 if (ha->dpc_pid < 0) {
2041 qla_printk(KERN_WARNING, ha,
2042 "Unable to start DPC thread!\n");
2046 wait_for_completion(&ha->dpc_inited);
2048 host->this_id = 255;
2049 host->cmd_per_lun = 3;
2050 host->max_cmd_len = MAX_CMDSZ;
2051 host->max_channel = ha->ports - 1;
2052 host->max_lun = ha->max_luns;
2053 BUG_ON(qla2xxx_transport_template == NULL);
2054 host->transportt = qla2xxx_transport_template;
2055 host->unique_id = ha->instance;
2056 host->max_id = ha->max_targets;
2058 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2059 ret = request_irq(host->irq, qla2100_intr_handler,
2060 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
2062 ret = request_irq(host->irq, qla2300_intr_handler,
2063 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
2065 qla_printk(KERN_WARNING, ha,
2066 "Failed to reserve interrupt %d already in use.\n",
2071 /* Initialized the timer */
2072 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
2074 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2079 /* Disable ISP interrupts. */
2080 qla2x00_disable_intrs(ha);
2082 /* Ensure mailbox registers are free. */
2083 spin_lock_irqsave(&ha->hardware_lock, flags);
2084 WRT_REG_WORD(®->semaphore, 0);
2085 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2086 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2088 /* Enable proper parity */
2089 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2092 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
2094 /* SRAM, Instruction RAM and GP RAM parity */
2095 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
2097 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2099 /* Enable chip interrupts. */
2100 qla2x00_enable_intrs(ha);
2104 * Wait around max loop_reset_delay secs for the devices to come
2105 * on-line. We don't want Linux scanning before we are ready.
2108 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
2109 time_before(jiffies,wait_switch) &&
2110 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
2111 && (ha->device_flags & SWITCH_FOUND) ;) {
2113 qla2x00_check_fabric_devices(ha);
2118 pci_set_drvdata(pdev, ha);
2119 ha->flags.init_done = 1;
2122 /* List the target we have found */
2123 if (displayConfig) {
2124 qla2x00_display_fc_names(ha);
2127 if (scsi_add_host(host, &pdev->dev))
2130 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
2131 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
2133 qla_printk(KERN_INFO, ha, "\n"
2134 " QLogic Fibre Channel HBA Driver: %s\n"
2136 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
2137 ha->model_number, ha->model_desc ? ha->model_desc: "",
2138 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
2139 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
2140 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
2143 scsi_scan_host(host);
2148 qla2x00_free_device(ha);
2150 scsi_host_put(host);
2152 probe_disable_device:
2153 pci_disable_device(pdev);
2157 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
2159 void qla2x00_remove_one(struct pci_dev *pdev)
2161 scsi_qla_host_t *ha;
2163 ha = pci_get_drvdata(pdev);
2165 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
2166 &sysfs_fw_dump_attr);
2167 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
2169 scsi_remove_host(ha->host);
2171 qla2x00_free_device(ha);
2173 scsi_host_put(ha->host);
2175 pci_set_drvdata(pdev, NULL);
2177 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
2180 qla2x00_free_device(scsi_qla_host_t *ha)
2184 /* Abort any outstanding IO descriptors. */
2185 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2186 qla2x00_cancel_io_descriptors(ha);
2188 /* turn-off interrupts on the card */
2189 if (ha->interrupts_on)
2190 qla2x00_disable_intrs(ha);
2193 if (ha->timer_active)
2194 qla2x00_stop_timer(ha);
2196 /* Kill the kernel thread for this host */
2197 if (ha->dpc_pid >= 0) {
2198 ha->dpc_should_die = 1;
2200 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
2202 qla_printk(KERN_ERR, ha,
2203 "Unable to signal DPC thread -- (%d)\n", ret);
2205 /* TODO: SOMETHING MORE??? */
2207 wait_for_completion(&ha->dpc_exited);
2211 qla2x00_mem_free(ha);
2214 ha->flags.online = 0;
2216 /* Detach interrupts */
2218 free_irq(ha->pdev->irq, ha);
2220 /* release io space registers */
2222 iounmap(ha->iobase);
2223 pci_release_regions(ha->pdev);
2225 pci_disable_device(ha->pdev);
2230 * The following support functions are adopted to handle
2231 * the re-entrant qla2x00_proc_info correctly.
2234 copy_mem_info(struct info_str *info, char *data, int len)
2236 if (info->pos + len > info->offset + info->length)
2237 len = info->offset + info->length - info->pos;
2239 if (info->pos + len < info->offset) {
2244 if (info->pos < info->offset) {
2247 partial = info->offset - info->pos;
2249 info->pos += partial;
2254 memcpy(info->buffer, data, len);
2256 info->buffer += len;
2261 copy_info(struct info_str *info, char *fmt, ...)
2267 va_start(args, fmt);
2268 len = vsprintf(buf, fmt, args);
2271 copy_mem_info(info, buf, len);
2276 /*************************************************************************
2280 * Return information to handle /proc support for the driver.
2282 * inout : decides the direction of the dataflow and the meaning of the
2284 * buffer: If inout==0 data is being written to it else read from it
2285 * (ptr to a page buffer)
2286 * *start: If inout==0 start of the valid data in the buffer
2287 * offset: If inout==0 starting offset from the beginning of all
2288 * possible data to return.
2289 * length: If inout==0 max number of bytes to be written into the buffer
2290 * else number of bytes in "buffer"
2292 * < 0: error. errno value.
2293 * >= 0: sizeof data returned.
2294 *************************************************************************/
2296 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
2297 char **start, off_t offset, int length, int inout)
2299 struct info_str info;
2300 int retval = -EINVAL;
2306 uint8_t *loop_state;
2307 scsi_qla_host_t *ha;
2310 DEBUG3(printk(KERN_INFO
2311 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
2312 buffer, offset, length);)
2314 ha = (scsi_qla_host_t *) shost->hostdata;
2317 /* Has data been written to the file? */
2319 "%s: has data been written to the file. \n",
2329 info.buffer = buffer;
2330 info.length = length;
2331 info.offset = offset;
2334 /* start building the print buffer */
2336 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
2337 " Firmware version %s, ",
2338 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
2340 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
2342 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
2344 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
2345 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
2348 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
2349 (unsigned long long)ha->request_dma,
2350 (unsigned long long)ha->response_dma);
2353 "Request Queue count = %d, Response Queue count = %d\n",
2354 ha->request_q_length, ha->response_q_length);
2357 "Total number of active commands = %ld\n",
2361 "Total number of interrupts = %ld\n",
2362 (long)ha->total_isr_cnt);
2365 " Device queue depth = 0x%x\n",
2366 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
2369 "Number of free request entries = %d\n", ha->req_q_cnt);
2372 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
2375 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
2378 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
2381 "Number of retries for empty slots = %ld\n",
2382 qla2x00_stats.outarray_full);
2385 "Number of reqs in pending_q= %ld, retry_q= %d, "
2386 "done_q= %ld, scsi_retry_q= %d\n",
2387 ha->qthreads, ha->retry_q_cnt,
2388 ha->done_q_cnt, ha->scsi_retry_q_cnt);
2391 flags = (uint32_t *) &ha->flags;
2393 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
2394 loop_state = "DOWN";
2395 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
2397 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
2398 loop_state = "READY";
2399 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
2400 loop_state = "TIMEOUT";
2401 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
2402 loop_state = "UPDATE";
2404 loop_state = "UNKNOWN";
2408 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
2409 loop_state , *flags);
2411 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
2413 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
2415 copy_info(&info, "Link down Timeout = %3.3d\n",
2416 ha->link_down_timeout);
2418 copy_info(&info, "Port down retry = %3.3d\n",
2419 ha->port_down_retry_count);
2421 copy_info(&info, "Login retry count = %3.3d\n",
2422 ha->login_retry_count);
2425 "Commands retried with dropped frame(s) = %d\n",
2426 ha->dropped_frame_error_cnt);
2429 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
2430 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
2432 copy_info(&info, "\n");
2434 /* 2.25 node/port display to proc */
2435 /* Display the node name for adapter */
2436 copy_info(&info, "\nSCSI Device Information:\n");
2438 "scsi-qla%d-adapter-node="
2439 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2441 ha->init_cb->node_name[0],
2442 ha->init_cb->node_name[1],
2443 ha->init_cb->node_name[2],
2444 ha->init_cb->node_name[3],
2445 ha->init_cb->node_name[4],
2446 ha->init_cb->node_name[5],
2447 ha->init_cb->node_name[6],
2448 ha->init_cb->node_name[7]);
2450 /* display the port name for adapter */
2452 "scsi-qla%d-adapter-port="
2453 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2455 ha->init_cb->port_name[0],
2456 ha->init_cb->port_name[1],
2457 ha->init_cb->port_name[2],
2458 ha->init_cb->port_name[3],
2459 ha->init_cb->port_name[4],
2460 ha->init_cb->port_name[5],
2461 ha->init_cb->port_name[6],
2462 ha->init_cb->port_name[7]);
2464 /* Print out device port names */
2465 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2466 if ((tq = TGT_Q(ha, t)) == NULL)
2470 "scsi-qla%d-target-%d="
2471 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2472 (int)ha->instance, t,
2473 tq->port_name[0], tq->port_name[1],
2474 tq->port_name[2], tq->port_name[3],
2475 tq->port_name[4], tq->port_name[5],
2476 tq->port_name[6], tq->port_name[7]);
2479 copy_info(&info, "\nSCSI LUN Information:\n");
2481 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
2483 /* scan for all equipment stats */
2484 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2486 for (l = 0; l < ha->max_luns; l++) {
2487 up = (os_lun_t *) GET_LU_Q(ha, t, l);
2492 if (up->fclun == NULL) {
2497 "(%2d:%2d): Total reqs %ld,",
2501 " Pending reqs %ld,",
2504 if (up->io_cnt < 4) {
2515 " %ld:%d:%02x %02x",
2516 up->fclun->fcport->ha->instance,
2517 up->fclun->fcport->cur_path,
2518 up->fclun->fcport->loop_id,
2519 up->fclun->device_type);
2521 copy_info(&info, "\n");
2523 if (info.pos >= info.offset + info.length) {
2524 /* No need to continue */
2529 if (info.pos >= info.offset + info.length) {
2530 /* No need to continue */
2537 retval = info.pos > info.offset ? info.pos - info.offset : 0;
2539 DEBUG3(printk(KERN_INFO
2540 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
2541 "length=0x%x\n", info.pos, offset, length);)
2547 * qla2x00_display_fc_names
2548 * This routine will the node names of the different devices found
2549 * after port inquiry.
2552 * cmd = SCSI command structure
2558 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2563 /* Display the node name for adapter */
2564 qla_printk(KERN_INFO, ha,
2565 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2567 ha->init_cb->node_name[0],
2568 ha->init_cb->node_name[1],
2569 ha->init_cb->node_name[2],
2570 ha->init_cb->node_name[3],
2571 ha->init_cb->node_name[4],
2572 ha->init_cb->node_name[5],
2573 ha->init_cb->node_name[6],
2574 ha->init_cb->node_name[7]);
2576 /* display the port name for adapter */
2577 qla_printk(KERN_INFO, ha,
2578 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2580 ha->init_cb->port_name[0],
2581 ha->init_cb->port_name[1],
2582 ha->init_cb->port_name[2],
2583 ha->init_cb->port_name[3],
2584 ha->init_cb->port_name[4],
2585 ha->init_cb->port_name[5],
2586 ha->init_cb->port_name[6],
2587 ha->init_cb->port_name[7]);
2589 /* Print out device port names */
2590 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2591 if ((tq = ha->otgt[tgt]) == NULL)
2594 if (tq->fcport == NULL)
2597 switch (ha->binding_type) {
2598 case BIND_BY_PORT_NAME:
2599 qla_printk(KERN_INFO, ha,
2600 "scsi-qla%d-tgt-%d-di-0-port="
2601 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2615 case BIND_BY_PORT_ID:
2616 qla_printk(KERN_INFO, ha,
2617 "scsi-qla%d-tgt-%d-di-0-pid="
2618 "%02x%02x%02x\\;\n",
2628 qla_printk(KERN_INFO, ha,
2629 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2635 * qla2x00_suspend_lun
2636 * Suspend lun and start port down timer
2639 * ha = visable adapter block pointer.
2641 * cp = Scsi command pointer
2642 * time = time in seconds
2643 * count = number of times to let time expire
2644 * delay_lun = non-zero, if lun should be delayed rather than suspended
2647 * QLA_SUCCESS -- suspended lun
2648 * QLA_FUNCTION_FAILED -- Didn't suspend lun
2651 * Interrupt context.
2654 __qla2x00_suspend_lun(scsi_qla_host_t *ha,
2655 os_lun_t *lq, int time, int count, int delay_lun)
2659 struct list_head *list, *temp;
2660 unsigned long flags;
2664 /* if the lun_q is already suspended then don't do it again */
2665 if (lq->q_state == LUN_STATE_READY ||lq->q_state == LUN_STATE_RUN) {
2667 spin_lock_irqsave(&lq->q_lock, flags);
2668 if (lq->q_state == LUN_STATE_READY) {
2672 /* Set the suspend time usually 6 secs */
2673 atomic_set(&lq->q_timer, time);
2675 /* now suspend the lun */
2676 lq->q_state = LUN_STATE_WAIT;
2679 set_bit(LUN_EXEC_DELAYED, &lq->q_flag);
2680 DEBUG(printk(KERN_INFO
2681 "scsi(%ld): Delay lun execution for %d secs, "
2682 "count=%d, max count=%d, state=%d\n",
2685 lq->q_count, lq->q_max, lq->q_state));
2687 DEBUG(printk(KERN_INFO
2688 "scsi(%ld): Suspend lun for %d secs, count=%d, "
2689 "max count=%d, state=%d\n",
2692 lq->q_count, lq->q_max, lq->q_state));
2694 spin_unlock_irqrestore(&lq->q_lock, flags);
2697 * Remove all pending commands from request queue and put them
2698 * in the scsi_retry queue.
2700 spin_lock_irqsave(&ha->list_lock, flags);
2701 list_for_each_safe(list, temp, &ha->pending_queue) {
2702 sp = list_entry(list, srb_t, list);
2703 if (sp->lun_queue != lq)
2706 __del_from_pending_queue(ha, sp);
2708 if (sp->cmd->allowed < count)
2709 sp->cmd->allowed = count;
2710 __add_to_scsi_retry_queue(ha, sp);
2712 } /* list_for_each_safe */
2713 spin_unlock_irqrestore(&ha->list_lock, flags);
2716 rval = QLA_FUNCTION_FAILED;
2723 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2725 * Input: ha = adapter block pointer. fcport = port structure pointer.
2731 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2735 * We may need to retry the login, so don't change the state of the
2736 * port but do the retries.
2738 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2739 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2744 if (fcport->login_retry == 0) {
2745 fcport->login_retry = ha->login_retry_count;
2746 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2748 DEBUG(printk("scsi(%ld): Port login retry: "
2749 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2750 "id = 0x%04x retry cnt=%d\n",
2752 fcport->port_name[0],
2753 fcport->port_name[1],
2754 fcport->port_name[2],
2755 fcport->port_name[3],
2756 fcport->port_name[4],
2757 fcport->port_name[5],
2758 fcport->port_name[6],
2759 fcport->port_name[7],
2761 fcport->login_retry));
2766 * qla2x00_mark_all_devices_lost
2767 * Updates fcport state when device goes offline.
2770 * ha = adapter block pointer.
2771 * fcport = port structure pointer.
2779 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2783 list_for_each_entry(fcport, &ha->fcports, list) {
2784 if (fcport->port_type != FCT_TARGET)
2788 * No point in marking the device as lost, if the device is
2791 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2794 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2800 * Allocates adapter memory.
2807 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2815 * This will loop only once if everything goes well, else some
2816 * number of retries will be performed to get around a kernel
2817 * bug where available mem is not allocated until after a
2818 * little delay and a retry.
2820 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2821 (ha->request_q_length + 1) * sizeof(request_t),
2822 &ha->request_dma, GFP_KERNEL);
2823 if (ha->request_ring == NULL) {
2824 qla_printk(KERN_WARNING, ha,
2825 "Memory Allocation failed - request_ring\n");
2827 qla2x00_mem_free(ha);
2833 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2834 (ha->response_q_length + 1) * sizeof(response_t),
2835 &ha->response_dma, GFP_KERNEL);
2836 if (ha->response_ring == NULL) {
2837 qla_printk(KERN_WARNING, ha,
2838 "Memory Allocation failed - response_ring\n");
2840 qla2x00_mem_free(ha);
2846 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2847 &ha->gid_list_dma, GFP_KERNEL);
2848 if (ha->gid_list == NULL) {
2849 qla_printk(KERN_WARNING, ha,
2850 "Memory Allocation failed - gid_list\n");
2852 qla2x00_mem_free(ha);
2858 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
2859 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
2860 if (ha->rlc_rsp == NULL) {
2861 qla_printk(KERN_WARNING, ha,
2862 "Memory Allocation failed - rlc");
2864 qla2x00_mem_free(ha);
2870 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
2871 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2872 DMA_POOL_SIZE, 8, 0);
2873 if (ha->s_dma_pool == NULL) {
2874 qla_printk(KERN_WARNING, ha,
2875 "Memory Allocation failed - s_dma_pool\n");
2877 qla2x00_mem_free(ha);
2883 /* get consistent memory allocated for init control block */
2884 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2886 if (ha->init_cb == NULL) {
2887 qla_printk(KERN_WARNING, ha,
2888 "Memory Allocation failed - init_cb\n");
2890 qla2x00_mem_free(ha);
2895 memset(ha->init_cb, 0, sizeof(init_cb_t));
2897 /* Get consistent memory allocated for Get Port Database cmd */
2898 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2899 &ha->iodesc_pd_dma);
2900 if (ha->iodesc_pd == NULL) {
2902 qla_printk(KERN_WARNING, ha,
2903 "Memory Allocation failed - iodesc_pd\n");
2905 qla2x00_mem_free(ha);
2910 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2912 /* Allocate ioctl related memory. */
2913 if (qla2x00_alloc_ioctl_mem(ha)) {
2914 qla_printk(KERN_WARNING, ha,
2915 "Memory Allocation failed - ioctl_mem\n");
2917 qla2x00_mem_free(ha);
2923 if (qla2x00_allocate_sp_pool(ha)) {
2924 qla_printk(KERN_WARNING, ha,
2925 "Memory Allocation failed - "
2926 "qla2x00_allocate_sp_pool()\n");
2928 qla2x00_mem_free(ha);
2934 /* Allocate memory for SNS commands */
2935 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2936 /* Get consistent memory allocated for SNS commands */
2937 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2938 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2940 if (ha->sns_cmd == NULL) {
2942 qla_printk(KERN_WARNING, ha,
2943 "Memory Allocation failed - sns_cmd\n");
2945 qla2x00_mem_free(ha);
2950 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2952 /* Get consistent memory allocated for MS IOCB */
2953 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2955 if (ha->ms_iocb == NULL) {
2957 qla_printk(KERN_WARNING, ha,
2958 "Memory Allocation failed - ms_iocb\n");
2960 qla2x00_mem_free(ha);
2965 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2968 * Get consistent memory allocated for CT SNS
2971 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2972 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2974 if (ha->ct_sns == NULL) {
2976 qla_printk(KERN_WARNING, ha,
2977 "Memory Allocation failed - ct_sns\n");
2979 qla2x00_mem_free(ha);
2984 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2987 /* Done all allocations without any error. */
2990 } while (retry-- && status != 0);
2994 "%s(): **** FAILED ****\n", __func__);
3002 * Frees all adapter allocated memory.
3005 * ha = adapter block pointer.
3008 qla2x00_mem_free(scsi_qla_host_t *ha)
3011 struct list_head *fcpl, *fcptemp;
3013 struct list_head *fcll, *fcltemp;
3015 unsigned long wtime;/* max wait time if mbx cmd is busy. */
3019 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
3023 /* Free the target queues */
3024 for (t = 0; t < MAX_TARGETS; t++) {
3025 qla2x00_tgt_free(ha, t);
3028 /* Make sure all other threads are stopped. */
3030 while (ha->dpc_wait && wtime) {
3031 set_current_state(TASK_INTERRUPTIBLE);
3032 wtime = schedule_timeout(wtime);
3035 /* free ioctl memory */
3036 qla2x00_free_ioctl_mem(ha);
3039 qla2x00_free_sp_pool(ha);
3042 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3043 ha->sns_cmd, ha->sns_cmd_dma);
3046 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3047 ha->ct_sns, ha->ct_sns_dma);
3050 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3053 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
3056 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
3059 dma_pool_destroy(ha->s_dma_pool);
3062 dma_free_coherent(&ha->pdev->dev,
3063 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
3067 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
3070 if (ha->response_ring)
3071 dma_free_coherent(&ha->pdev->dev,
3072 (ha->response_q_length + 1) * sizeof(response_t),
3073 ha->response_ring, ha->response_dma);
3075 if (ha->request_ring)
3076 dma_free_coherent(&ha->pdev->dev,
3077 (ha->request_q_length + 1) * sizeof(request_t),
3078 ha->request_ring, ha->request_dma);
3081 ha->sns_cmd_dma = 0;
3085 ha->ms_iocb_dma = 0;
3086 ha->iodesc_pd = NULL;
3087 ha->iodesc_pd_dma = 0;
3089 ha->init_cb_dma = 0;
3091 ha->s_dma_pool = NULL;
3094 ha->rlc_rsp_dma = 0;
3095 ha->gid_list = NULL;
3096 ha->gid_list_dma = 0;
3098 ha->response_ring = NULL;
3099 ha->response_dma = 0;
3100 ha->request_ring = NULL;
3101 ha->request_dma = 0;
3103 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
3104 fcport = list_entry(fcpl, fc_port_t, list);
3107 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
3108 fclun = list_entry(fcll, fc_lun_t, list);
3110 list_del_init(&fclun->list);
3115 list_del_init(&fcport->list);
3118 INIT_LIST_HEAD(&ha->fcports);
3121 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
3123 if (ha->fw_dump_buffer)
3124 vfree(ha->fw_dump_buffer);
3127 ha->fw_dump_reading = 0;
3128 ha->fw_dump_buffer = NULL;
3132 * qla2x00_allocate_sp_pool
3133 * This routine is called during initialization to allocate
3134 * memory for local srb_t.
3137 * ha = adapter block pointer.
3142 * Note: Sets the ref_count for non Null sp to one.
3145 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
3150 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3151 mempool_free_slab, srb_cachep);
3152 if (ha->srb_mempool == NULL) {
3153 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
3154 rval = QLA_FUNCTION_FAILED;
3160 * This routine frees all adapter allocated memory.
3164 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
3166 if (ha->srb_mempool) {
3167 mempool_destroy(ha->srb_mempool);
3168 ha->srb_mempool = NULL;
3172 /**************************************************************************
3174 * This kernel thread is a task that is schedule by the interrupt handler
3175 * to perform the background processing for interrupts.
3178 * This task always run in the context of a kernel thread. It
3179 * is kick-off by the driver's detect code and starts up
3180 * up one per adapter. It immediately goes to sleep and waits for
3181 * some fibre event. When either the interrupt handler or
3182 * the timer routine detects a event it will one of the task
3183 * bits then wake us up.
3184 **************************************************************************/
3186 qla2x00_do_dpc(void *data)
3188 DECLARE_MUTEX_LOCKED(sem);
3189 scsi_qla_host_t *ha;
3194 unsigned long flags = 0;
3195 struct list_head *list, *templist;
3196 int dead_cnt, online_cnt;
3198 uint16_t next_loopid;
3202 ha = (scsi_qla_host_t *)data;
3206 daemonize("%s_dpc", ha->host_str);
3207 allow_signal(SIGHUP);
3209 ha->dpc_wait = &sem;
3211 set_user_nice(current, -20);
3215 complete(&ha->dpc_inited);
3218 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3220 if (down_interruptible(&sem))
3223 if (ha->dpc_should_die)
3226 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3228 /* Initialization not yet finished. Don't do anything yet. */
3229 if (!ha->flags.init_done || ha->dpc_active)
3232 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
3236 if (!list_empty(&ha->done_queue))
3239 /* Process commands in retry queue */
3240 if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {
3241 DEBUG(printk("scsi(%ld): DPC checking retry_q. "
3243 ha->host_no, ha->retry_q_cnt));
3245 spin_lock_irqsave(&ha->list_lock, flags);
3246 dead_cnt = online_cnt = 0;
3247 list_for_each_safe(list, templist, &ha->retry_queue) {
3248 sp = list_entry(list, srb_t, list);
3250 DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "
3251 "spflags=0x%x, q_flag= 0x%lx\n",
3252 ha->host_no, sp->cmd->serial_number, sp,
3253 sp->flags, q->q_flag));
3257 fcport = q->fclun->fcport;
3259 if (atomic_read(&fcport->state) ==
3261 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3263 __del_from_retry_queue(ha, sp);
3264 sp->cmd->result = DID_NO_CONNECT << 16;
3265 if (atomic_read(&fcport->ha->loop_state) ==
3267 sp->err_id = SRB_ERR_LOOP;
3269 sp->err_id = SRB_ERR_PORT;
3270 sp->cmd->host_scribble =
3271 (unsigned char *) NULL;
3272 __add_to_done_queue(ha, sp);
3274 } else if (atomic_read(&fcport->state) !=
3277 __del_from_retry_queue(ha, sp);
3278 sp->cmd->result = DID_BUS_BUSY << 16;
3279 sp->cmd->host_scribble =
3280 (unsigned char *) NULL;
3281 __add_to_done_queue(ha, sp);
3284 } /* list_for_each_safe() */
3285 spin_unlock_irqrestore(&ha->list_lock, flags);
3287 DEBUG(printk("scsi(%ld): done processing retry queue "
3288 "- dead=%d, online=%d\n ",
3289 ha->host_no, dead_cnt, online_cnt));
3292 /* Process commands in scsi retry queue */
3293 if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {
3295 * Any requests we want to delay for some period is put
3296 * in the scsi retry queue with a delay added. The
3297 * timer will schedule a "scsi_restart_needed" every
3298 * second as long as there are requests in the scsi
3301 DEBUG(printk("scsi(%ld): DPC checking scsi "
3302 "retry_q.total=%d\n",
3303 ha->host_no, ha->scsi_retry_q_cnt));
3306 spin_lock_irqsave(&ha->list_lock, flags);
3307 list_for_each_safe(list, templist,
3308 &ha->scsi_retry_queue) {
3310 sp = list_entry(list, srb_t, list);
3314 DEBUG3(printk("scsi(%ld): scsi_retry_q: "
3315 "pid=%ld sp=%p, spflags=0x%x, "
3316 "q_flag= 0x%lx,q_state=%d\n",
3317 ha->host_no, sp->cmd->serial_number,
3318 sp, sp->flags, q->q_flag, q->q_state));
3320 /* Was this lun suspended */
3321 if (q->q_state != LUN_STATE_WAIT) {
3323 __del_from_scsi_retry_queue(ha, sp);
3325 if (test_bit(TQF_RETRY_CMDS,
3327 qla2x00_extend_timeout(sp->cmd,
3328 (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
3329 __add_to_pending_queue(ha, sp);
3332 __add_to_retry_queue(ha, sp);
3335 /* Was this command suspended for N secs */
3336 if (sp->delay != 0) {
3338 if (sp->delay == 0) {
3340 __del_from_scsi_retry_queue(
3342 __add_to_retry_queue(ha,sp);
3346 spin_unlock_irqrestore(&ha->list_lock, flags);
3348 /* Clear all Target Unsuspended bits */
3349 for (t = 0; t < ha->max_targets; t++) {
3350 if ((tq = ha->otgt[t]) == NULL)
3353 if (test_bit(TQF_RETRY_CMDS, &tq->flags))
3354 clear_bit(TQF_RETRY_CMDS, &tq->flags);
3359 DEBUG(if (online_cnt > 0))
3360 DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "
3362 ha->host_no, online_cnt));
3365 if (ha->flags.mbox_busy) {
3366 if (!list_empty(&ha->done_queue))
3373 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3375 DEBUG(printk("scsi(%ld): dpc: sched "
3376 "qla2x00_abort_isp ha = %p\n",
3378 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3381 if (qla2x00_abort_isp(ha)) {
3382 /* failed. retry later */
3383 set_bit(ISP_ABORT_NEEDED,
3386 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
3388 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3392 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
3393 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
3395 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3398 qla2x00_rst_aen(ha);
3399 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
3402 /* Retry each device up to login retry count */
3403 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3404 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
3405 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3407 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3411 list_for_each_entry(fcport, &ha->fcports, list) {
3412 if (fcport->port_type != FCT_TARGET)
3416 * If the port is not ONLINE then try to login
3417 * to it if we haven't run out of retries.
3419 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3420 fcport->login_retry) {
3422 fcport->login_retry--;
3423 if (fcport->flags & FCF_FABRIC_DEVICE) {
3426 qla2x00_fabric_logout(
3429 status = qla2x00_fabric_login(
3430 ha, fcport, &next_loopid);
3433 qla2x00_local_device_login(
3434 ha, fcport->loop_id);
3436 if (status == QLA_SUCCESS) {
3437 fcport->old_loop_id = fcport->loop_id;
3439 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
3440 ha->host_no, fcport->loop_id));
3442 fcport->port_login_retry_count =
3443 ha->port_down_retry_count * PORT_RETRY_TIME;
3444 atomic_set(&fcport->state, FCS_ONLINE);
3445 atomic_set(&fcport->port_down_timer,
3446 ha->port_down_retry_count * PORT_RETRY_TIME);
3448 fcport->login_retry = 0;
3449 } else if (status == 1) {
3450 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
3451 /* retry the login again */
3452 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
3454 fcport->login_retry, fcport->loop_id));
3456 fcport->login_retry = 0;
3459 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
3462 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3466 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
3467 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3469 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
3470 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
3473 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3475 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
3479 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
3481 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3484 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3487 qla2x00_loop_resync(ha);
3489 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3492 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3497 if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {
3498 DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",
3501 qla2x00_restart_queues(ha, 0);
3503 DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",
3507 if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {
3509 DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",
3512 qla2x00_abort_queues(ha, 0);
3514 DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",
3518 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
3520 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
3523 qla2x00_rescan_fcports(ha);
3525 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
3531 if (!ha->interrupts_on)
3532 qla2x00_enable_intrs(ha);
3534 if (!list_empty(&ha->done_queue))
3538 } /* End of while(1) */
3540 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
3543 * Make sure that nobody tries to wake us up again.
3545 ha->dpc_wait = NULL;
3548 complete_and_exit(&ha->dpc_exited, 0);
3552 * qla2x00_abort_queues
3553 * Abort all commands on queues on device
3556 * ha = adapter block pointer.
3559 * Interrupt context.
3562 qla2x00_abort_queues(scsi_qla_host_t *ha, uint8_t doneqflg)
3566 struct list_head *list, *temp;
3567 unsigned long flags;
3569 clear_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3571 /* Return all commands device queues. */
3572 spin_lock_irqsave(&ha->list_lock,flags);
3573 list_for_each_safe(list, temp, &ha->pending_queue) {
3574 sp = list_entry(list, srb_t, list);
3576 if (sp->flags & SRB_ABORTED)
3579 /* Remove srb from LUN queue. */
3580 __del_from_pending_queue(ha, sp);
3582 /* Set ending status. */
3583 sp->cmd->result = DID_BUS_BUSY << 16;
3585 __add_to_done_queue(ha, sp);
3587 spin_unlock_irqrestore(&ha->list_lock, flags);
3592 * Processes asynchronous reset.
3595 * ha = adapter block pointer.
3598 qla2x00_rst_aen(scsi_qla_host_t *ha)
3600 if (ha->flags.online && !ha->flags.reset_active &&
3601 !atomic_read(&ha->loop_down_timer) &&
3602 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
3604 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3607 * Issue marker command only when we are going to start
3610 ha->marker_needed = 1;
3611 } while (!atomic_read(&ha->loop_down_timer) &&
3612 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
3618 * This routine will allocate SP from the free queue
3625 qla2x00_get_new_sp(scsi_qla_host_t *ha)
3629 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3631 atomic_set(&sp->ref_count, 1);
3635 /**************************************************************************
3641 * Context: Interrupt
3642 ***************************************************************************/
3644 qla2x00_timer(scsi_qla_host_t *ha)
3647 unsigned long cpu_flags = 0;
3656 * We try and restart any request in the retry queue every second.
3658 if (!list_empty(&ha->retry_queue)) {
3659 set_bit(PORT_RESTART_NEEDED, &ha->dpc_flags);
3664 * We try and restart any request in the scsi_retry queue every second.
3666 if (!list_empty(&ha->scsi_retry_queue)) {
3667 set_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags);
3672 * Ports - Port down timer.
3674 * Whenever, a port is in the LOST state we start decrementing its port
3675 * down timer every second until it reaches zero. Once it reaches zero
3676 * the port it marked DEAD.
3679 list_for_each_entry(fcport, &ha->fcports, list) {
3680 if (fcport->port_type != FCT_TARGET)
3683 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3685 if (atomic_read(&fcport->port_down_timer) == 0)
3688 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3689 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3691 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3694 t, atomic_read(&fcport->port_down_timer)));
3697 } /* End of for fcport */
3700 * LUNS - lun suspend timer.
3702 * Whenever, a lun is suspended the timer starts decrementing its
3703 * suspend timer every second until it reaches zero. Once it reaches
3704 * zero the lun retry count is decremented.
3708 * FIXME(dg) - Need to convert this linear search of luns into a search
3709 * of a list of suspended luns.
3711 for (t = 0; t < ha->max_targets; t++) {
3712 if ((tq = ha->otgt[t]) == NULL)
3715 for (l = 0; l < ha->max_luns; l++) {
3716 if ((lq = (os_lun_t *) tq->olun[l]) == NULL)
3719 spin_lock_irqsave(&lq->q_lock, cpu_flags);
3720 if (lq->q_state == LUN_STATE_WAIT &&
3721 atomic_read(&lq->q_timer) != 0) {
3723 if (atomic_dec_and_test(&lq->q_timer) != 0) {
3725 * A delay should immediately
3726 * transition to a READY state
3728 if (test_and_clear_bit(LUN_EXEC_DELAYED,
3730 lq->q_state = LUN_STATE_READY;
3734 if (lq->q_count == lq->q_max)
3742 DEBUG3(printk("scsi(%ld): lun%d - timer %d, "
3743 "count=%d, max=%d, state=%d\n",
3746 atomic_read(&lq->q_timer),
3747 lq->q_count, lq->q_max, lq->q_state));
3749 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
3750 } /* End of for luns */
3751 } /* End of for targets */
3753 /* Loop down handler. */
3754 if (atomic_read(&ha->loop_down_timer) > 0 &&
3755 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
3757 if (atomic_read(&ha->loop_down_timer) ==
3758 ha->loop_down_abort_time) {
3760 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3761 "queues before time expire\n",
3764 if (!IS_QLA2100(ha) && ha->link_down_timeout)
3765 atomic_set(&ha->loop_state, LOOP_DEAD);
3767 /* Schedule an ISP abort to return any tape commands. */
3768 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3769 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
3771 sp = ha->outstanding_cmds[index];
3774 if (!(sp->fclun->fcport->flags &
3778 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3781 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3783 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3787 /* if the loop has been down for 4 minutes, reinit adapter */
3788 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
3789 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
3790 "restarting queues.\n",
3793 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3796 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3797 DEBUG(printk("scsi(%ld): Loop down - "
3800 qla_printk(KERN_WARNING, ha,
3801 "Loop down - aborting ISP.\n");
3803 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3806 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
3808 atomic_read(&ha->loop_down_timer)));
3812 * Done Q Handler -- dgFIXME This handler will kick off doneq if we
3813 * haven't process it in 2 seconds.
3815 if (!list_empty(&ha->done_queue))
3819 /* Schedule the DPC routine if needed */
3820 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
3821 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
3823 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
3824 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3825 ha->dpc_wait && !ha->dpc_active) {
3830 qla2x00_restart_timer(ha, WATCH_INTERVAL);
3834 * qla2x00_extend_timeout
3835 * This routine will extend the timeout to the specified value.
3838 * cmd = SCSI command structure
3844 qla2x00_extend_timeout(struct scsi_cmnd *cmd, int timeout)
3846 srb_t *sp = (srb_t *) CMD_SP(cmd);
3847 u_long our_jiffies = (timeout * HZ) + jiffies;
3850 sp->e_start = jiffies;
3851 if (cmd->eh_timeout.function) {
3852 mod_timer(&cmd->eh_timeout,our_jiffies);
3853 sp->ext_history |= 1;
3855 if (sp->timer.function != NULL) {
3857 * Our internal timer should timeout before the midlayer has a
3858 * chance begin the abort process
3860 mod_timer(&sp->timer,our_jiffies - (QLA_CMD_TIMER_DELTA * HZ));
3862 sp->ext_history |= 2;
3866 /**************************************************************************
3867 * qla2x00_cmd_timeout
3870 * Handles the command if it times out in any state.
3873 * sp - pointer to validate
3877 * Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).
3878 **************************************************************************/
3880 qla2x00_cmd_timeout(srb_t *sp)
3884 scsi_qla_host_t *vis_ha, *dest_ha;
3885 struct scsi_cmnd *cmd;
3886 unsigned long flags, cpu_flags;
3890 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
3892 DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state));
3894 t = cmd->device->id;
3895 l = cmd->device->lun;
3896 fcport = sp->fclun->fcport;
3900 * If IO is found either in retry Queue
3902 * Return this IO back to host
3904 spin_lock_irqsave(&vis_ha->list_lock, flags);
3906 if (sp->state == SRB_PENDING_STATE) {
3907 __del_from_pending_queue(vis_ha, sp);
3908 DEBUG2(printk("scsi(%ld): Found in Pending queue pid %ld, "
3909 "State = %x., fcport state=%d sjiffs=%lx njiffs=%lx\n",
3910 vis_ha->host_no, cmd->serial_number, sp->state,
3911 atomic_read(&fcport->state), sp->r_start, jiffies));
3914 * If FC_DEVICE is marked as dead return the cmd with
3915 * DID_NO_CONNECT status. Otherwise set the host_byte to
3916 * DID_BUS_BUSY to let the OS retry this cmd.
3918 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
3919 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3920 cmd->result = DID_NO_CONNECT << 16;
3921 if (atomic_read(&fcport->ha->loop_state) == LOOP_DOWN)
3922 sp->err_id = SRB_ERR_LOOP;
3924 sp->err_id = SRB_ERR_PORT;
3926 cmd->result = DID_BUS_BUSY << 16;
3928 __add_to_done_queue(vis_ha, sp);
3931 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
3934 qla2x00_done(vis_ha);
3938 spin_lock_irqsave(&dest_ha->list_lock, flags);
3939 if ((sp->state == SRB_RETRY_STATE) ||
3940 (sp->state == SRB_SCSI_RETRY_STATE)) {
3942 DEBUG2(printk("scsi(%ld): Found in (Scsi) Retry queue or "
3943 "failover Q pid %ld, State = %x., fcport state=%d "
3944 "jiffies=%lx retried=%d\n",
3945 dest_ha->host_no, cmd->serial_number, sp->state,
3946 atomic_read(&fcport->state), jiffies, cmd->retries));
3948 if ((sp->state == SRB_RETRY_STATE)) {
3949 __del_from_retry_queue(dest_ha, sp);
3950 } else if ((sp->state == SRB_SCSI_RETRY_STATE)) {
3951 __del_from_scsi_retry_queue(dest_ha, sp);
3955 * If FC_DEVICE is marked as dead return the cmd with
3956 * DID_NO_CONNECT status. Otherwise set the host_byte to
3957 * DID_BUS_BUSY to let the OS retry this cmd.
3959 if ((atomic_read(&fcport->state) == FCS_DEVICE_DEAD) ||
3960 atomic_read(&dest_ha->loop_state) == LOOP_DEAD) {
3961 qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT);
3962 cmd->result = DID_NO_CONNECT << 16;
3963 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
3964 sp->err_id = SRB_ERR_LOOP;
3966 sp->err_id = SRB_ERR_PORT;
3968 cmd->result = DID_BUS_BUSY << 16;
3971 __add_to_done_queue(dest_ha, sp);
3974 spin_unlock_irqrestore(&dest_ha->list_lock, flags);
3977 qla2x00_done(dest_ha);
3981 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
3982 if (sp->state == SRB_DONE_STATE) {
3983 /* IO in done_q -- leave it */
3984 DEBUG(printk("scsi(%ld): Found in Done queue pid %ld sp=%p.\n",
3985 dest_ha->host_no, cmd->serial_number, sp));
3986 } else if (sp->state == SRB_SUSPENDED_STATE) {
3987 DEBUG(printk("scsi(%ld): Found SP %p in suspended state "
3989 dest_ha->host_no, sp, cmd->serial_number));
3990 DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));)
3991 } else if (sp->state == SRB_ACTIVE_STATE) {
3993 * IO is with ISP find the command in our active list.
3995 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
3996 spin_lock_irqsave(&dest_ha->hardware_lock, flags);
3997 if (sp == dest_ha->outstanding_cmds[
3998 (unsigned long)sp->cmd->host_scribble]) {
4000 DEBUG(printk("cmd_timeout: Found in ISP \n"));
4002 if (sp->flags & SRB_TAPE) {
4004 * We cannot allow the midlayer error handler
4005 * to wakeup and begin the abort process.
4006 * Extend the timer so that the firmware can
4007 * properly return the IOCB.
4009 DEBUG(printk("cmd_timeout: Extending timeout "
4010 "of FCP2 tape command!\n"));
4011 qla2x00_extend_timeout(sp->cmd,
4012 EXTEND_CMD_TIMEOUT);
4014 sp->state = SRB_ACTIVE_TIMEOUT_STATE;
4015 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4017 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4019 "qla_cmd_timeout: State indicates it is with "
4020 "ISP, But not in active array\n");
4022 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
4023 } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) {
4024 DEBUG(printk("qla2100%ld: Found in Active timeout state"
4025 "pid %ld, State = %x., \n",
4027 sp->cmd->serial_number, sp->state);)
4030 DEBUG2(printk("cmd_timeout%ld: LOST command state = "
4032 vis_ha->host_no, sp->state,sp);)
4034 qla_printk(KERN_INFO, vis_ha,
4035 "cmd_timeout: LOST command state = 0x%x\n", sp->state);
4037 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4039 DEBUG3(printk("cmd_timeout: Leaving\n");)
4042 /**************************************************************************
4044 * Process completed commands.
4047 * old_ha = adapter block pointer.
4049 **************************************************************************/
4051 qla2x00_done(scsi_qla_host_t *old_ha)
4054 struct scsi_cmnd *cmd;
4055 unsigned long flags = 0;
4056 scsi_qla_host_t *ha;
4057 scsi_qla_host_t *vis_ha;
4058 int send_marker_once = 0;
4060 LIST_HEAD(local_sp_list);
4063 * Get into local queue such that we do not wind up calling done queue
4064 * tasklet for the same IOs from DPC or any other place.
4066 spin_lock_irqsave(&old_ha->list_lock, flags);
4067 list_splice_init(&old_ha->done_queue, &local_sp_list);
4068 spin_unlock_irqrestore(&old_ha->list_lock, flags);
4071 * All done commands are in the local queue, now do the call back.
4073 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4074 old_ha->done_q_cnt--;
4075 sp->state = SRB_NO_QUEUE_STATE;
4077 /* remove command from local list */
4078 list_del_init(&sp->list);
4084 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
4088 if (sp->flags & SRB_DMA_VALID) {
4089 sp->flags &= ~SRB_DMA_VALID;
4091 /* Release memory used for this I/O */
4093 pci_unmap_sg(ha->pdev, cmd->request_buffer,
4094 cmd->use_sg, cmd->sc_data_direction);
4095 } else if (cmd->request_bufflen) {
4096 pci_unmap_page(ha->pdev, sp->dma_handle,
4097 cmd->request_bufflen,
4098 cmd->sc_data_direction);
4103 switch (host_byte(cmd->result)) {
4110 * Set marker needed, so we don't have to
4111 * send multiple markers
4113 if (!send_marker_once) {
4114 ha->marker_needed = 1;
4121 * A backdoor device-reset requires different
4122 * error handling. This code differentiates
4123 * between normal error handling and the
4127 if (ha->host->eh_active != EH_ACTIVE)
4128 cmd->result = DID_BUS_BUSY << 16;
4133 sp->flags &= ~SRB_ABORT_PENDING;
4134 sp->flags |= SRB_ABORTED;
4136 if (sp->flags & SRB_TIMEOUT)
4137 cmd->result = DID_TIME_OUT << 16;
4142 DEBUG2(printk("scsi(%ld:%d:%d) %s: did_error "
4143 "= %d, comp-scsi= 0x%x-0x%x pid=%ld.\n",
4145 cmd->device->id, cmd->device->lun,
4147 host_byte(cmd->result),
4148 CMD_COMPL_STATUS(cmd),
4149 CMD_SCSI_STATUS(cmd), cmd->serial_number));
4154 * Call the mid-level driver interrupt handler -- via sp_put()
4157 } /* end of while */
4161 * qla2x00_process_response_queue_in_zio_mode
4162 * Process response queue completion as fast as possible
4163 * to achieve Zero Interrupt Opertions-ZIO
4166 * ha = adapter block pointer.
4172 qla2x00_process_response_queue_in_zio_mode(scsi_qla_host_t *ha)
4174 unsigned long flags;
4176 /* Check for unprocessed commands in response queue. */
4177 if (!ha->flags.process_response_queue)
4179 if (!ha->flags.online)
4181 if (ha->response_ring_ptr->signature == RESPONSE_PROCESSED)
4184 spin_lock_irqsave(&ha->hardware_lock,flags);
4185 qla2x00_process_response_queue(ha);
4186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4191 * Retrieve and process next job in the LUN queue.
4194 * tq = SCSI target queue pointer.
4195 * lq = SCSI LUN queue pointer.
4196 * TGT_LOCK must be already obtained.
4199 * Releases TGT_LOCK upon exit.
4202 * Kernel/Interrupt context.
4204 * Note: This routine will always try to start I/O from visible HBA.
4207 qla2x00_next(scsi_qla_host_t *vis_ha)
4210 unsigned long flags;
4211 scsi_qla_host_t *dest_ha;
4214 LIST_HEAD(local_sp_list);
4218 spin_lock_irqsave(&vis_ha->list_lock, flags);
4219 list_splice_init(&vis_ha->pending_queue, &local_sp_list);
4220 vis_ha->qthreads = 0;
4221 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
4223 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4224 list_del_init(&sp->list);
4225 sp->state = SRB_NO_QUEUE_STATE;
4227 fcport = sp->fclun->fcport;
4228 dest_ha = fcport->ha;
4230 /* If device is dead then send request back to OS */
4231 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
4232 sp->cmd->result = DID_NO_CONNECT << 16;
4233 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
4234 sp->err_id = SRB_ERR_LOOP;
4236 sp->err_id = SRB_ERR_PORT;
4238 DEBUG3(printk("scsi(%ld): loop/port is down - pid=%ld, "
4239 "sp=%p err_id=%d loopid=0x%x queued to dest HBA "
4240 "scsi%ld.\n", dest_ha->host_no,
4241 sp->cmd->serial_number, sp, sp->err_id,
4242 fcport->loop_id, dest_ha->host_no));
4244 * Initiate a failover - done routine will initiate.
4246 add_to_done_queue(vis_ha, sp);
4252 * SCSI Kluge: Whenever, we need to wait for an event such as
4253 * loop down (i.e. loop_down_timer ) or port down (i.e. LUN
4254 * request qeueue is suspended) then we will recycle new
4255 * commands back to the SCSI layer. We do this because this is
4256 * normally a temporary condition and we don't want the
4257 * mid-level scsi.c driver to get upset and start aborting
4258 * commands. The timeout value is extracted from the command
4259 * minus 1-second and put on a retry queue (watchdog). Once the
4260 * command timeout it is returned to the mid-level with a BUSY
4261 * status, so the mid-level will retry it. This process
4262 * continues until the LOOP DOWN time expires or the condition
4265 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4266 (atomic_read(&fcport->state) != FCS_ONLINE ||
4267 test_bit(ABORT_ISP_ACTIVE, &dest_ha->dpc_flags) ||
4268 atomic_read(&dest_ha->loop_state) != LOOP_READY)) {
4270 DEBUG3(printk("scsi(%ld): pid=%ld port=0x%x state=%d "
4271 "loop state=%d, loop counter=0x%x "
4272 "dpc_flags=0x%lx\n", sp->cmd->serial_number,
4273 dest_ha->host_no, fcport->loop_id,
4274 atomic_read(&fcport->state),
4275 atomic_read(&dest_ha->loop_state),
4276 atomic_read(&dest_ha->loop_down_timer),
4277 dest_ha->dpc_flags));
4279 qla2x00_extend_timeout(sp->cmd, EXTEND_CMD_TIMEOUT);
4280 add_to_retry_queue(vis_ha, sp);
4286 * If this request's lun is suspended then put the request on
4287 * the scsi_retry queue.
4289 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4290 sp->lun_queue->q_state == LUN_STATE_WAIT) {
4291 DEBUG3(printk("scsi(%ld): lun wait state - pid=%ld, "
4292 "opcode=%d, allowed=%d, retries=%d\n",
4294 sp->cmd->serial_number,
4299 add_to_scsi_retry_queue(vis_ha, sp);
4304 sp->lun_queue->io_cnt++;
4306 rval = qla2x00_start_scsi(sp);
4307 if (rval != QLA_SUCCESS) {
4308 /* Place request back on top of device queue */
4309 /* add to the top of queue */
4310 add_to_pending_queue_head(vis_ha, sp);
4312 sp->lun_queue->io_cnt--;
4316 if (!IS_QLA2100(vis_ha) && !IS_QLA2200(vis_ha)) {
4317 /* Process response_queue if ZIO support is enabled*/
4318 qla2x00_process_response_queue_in_zio_mode(vis_ha);
4323 /* XXX(hch): crude hack to emulate a down_timeout() */
4325 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
4327 const unsigned int step = HZ/10;
4330 if (!down_trylock(sema))
4332 set_current_state(TASK_INTERRUPTIBLE);
4333 if (schedule_timeout(step))
4335 } while ((timeout -= step) > 0);
4341 qla2xxx_get_port_id(struct scsi_target *starget)
4343 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4344 scsi_qla_host_t *ha = to_qla_host(shost);
4347 list_for_each_entry(fc, &ha->fcports, list) {
4348 if (fc->os_target_id == starget->id) {
4349 fc_starget_port_id(starget) = fc->d_id.b.domain << 16 |
4350 fc->d_id.b.area << 8 |
4355 fc_starget_port_id(starget) = -1;
4359 qla2xxx_get_port_name(struct scsi_target *starget)
4361 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4362 scsi_qla_host_t *ha = to_qla_host(shost);
4365 list_for_each_entry(fc, &ha->fcports, list) {
4366 if (fc->os_target_id == starget->id) {
4367 fc_starget_port_name(starget) =
4368 __be64_to_cpu(*(uint64_t *)fc->port_name);
4372 fc_starget_port_name(starget) = -1;
4376 qla2xxx_get_node_name(struct scsi_target *starget)
4378 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4379 scsi_qla_host_t *ha = to_qla_host(shost);
4382 list_for_each_entry(fc, &ha->fcports, list) {
4383 if (fc->os_target_id == starget->id) {
4384 fc_starget_node_name(starget) =
4385 __be64_to_cpu(*(uint64_t *)fc->node_name);
4389 fc_starget_node_name(starget) = -1;
4392 static struct fc_function_template qla2xxx_transport_functions = {
4393 .get_starget_port_id = qla2xxx_get_port_id,
4394 .show_starget_port_id = 1,
4395 .get_starget_port_name = qla2xxx_get_port_name,
4396 .show_starget_port_name = 1,
4397 .get_starget_node_name = qla2xxx_get_node_name,
4398 .show_starget_node_name = 1,
4402 * qla2x00_module_init - Module initialization.
4405 qla2x00_module_init(void)
4407 /* Allocate cache for SRBs. */
4408 sprintf(srb_cachep_name, "qla2xxx_srbs");
4409 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
4410 SLAB_HWCACHE_ALIGN, NULL, NULL);
4411 if (srb_cachep == NULL) {
4413 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4417 /* Derive version string. */
4418 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4420 strcat(qla2x00_version_str, "-debug");
4423 qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions);
4424 if (!qla2xxx_transport_template)
4427 printk(KERN_INFO "QLogic Fibre Channel HBA Driver\n");
4432 * qla2x00_module_exit - Module cleanup.
4435 qla2x00_module_exit(void)
4437 /* Free SRBs cache. */
4438 if (srb_cachep != NULL) {
4439 if (kmem_cache_destroy(srb_cachep) != 0) {
4441 "qla2xxx: Unable to free SRB cache...Memory pools "
4447 fc_release_transport(qla2xxx_transport_template);
4450 module_init(qla2x00_module_init);
4451 module_exit(qla2x00_module_exit);
4453 MODULE_AUTHOR("QLogic Corporation");
4454 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4455 MODULE_LICENSE("GPL");
4456 MODULE_VERSION(QLA2XXX_VERSION);