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>
25 #include <scsi/scsi_tcq.h>
26 #include <scsi/scsicam.h>
27 #include <scsi/scsi_transport.h>
28 #include <scsi/scsi_transport_fc.h>
33 char qla2x00_version_str[40];
36 * SRB allocation cache
38 char srb_cachep_name[16];
39 kmem_cache_t *srb_cachep;
42 * Stats for all adpaters.
44 struct _qla2x00stats qla2x00_stats;
47 * Ioctl related information.
53 * Module parameter information and variables
56 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
57 MODULE_PARM_DESC(ql2xmaxqdepth,
58 "Maximum queue depth to report for target devices.");
60 int ql2xlogintimeout = 20;
61 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
62 MODULE_PARM_DESC(ql2xlogintimeout,
63 "Login timeout value in seconds.");
65 int qlport_down_retry;
66 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
67 MODULE_PARM_DESC(qlport_down_retry,
68 "Maximum number of command retries to a port that returns"
69 "a PORT-DOWN status.");
71 int ql2xretrycount = 20;
72 module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR);
73 MODULE_PARM_DESC(ql2xretrycount,
74 "Maximum number of mid-layer retries allowed for a command. "
75 "Default value is 20, ");
78 module_param(displayConfig, int, S_IRUGO|S_IWUSR);
79 MODULE_PARM_DESC(displayConfig,
80 "If 1 then display the configuration used in /etc/modprobe.conf.");
82 int ql2xplogiabsentdevice;
83 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
84 MODULE_PARM_DESC(ql2xplogiabsentdevice,
85 "Option to enable PLOGI to devices that are not present after "
86 "a Fabric scan. This is needed for several broken switches."
87 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
89 int ql2xenablezio = 0;
90 module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
91 MODULE_PARM_DESC(ql2xenablezio,
92 "Option to enable ZIO:If 1 then enable it otherwise"
93 " use the default set in the NVRAM."
94 " Default is 0 : disabled");
96 int ql2xintrdelaytimer = 10;
97 module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
98 MODULE_PARM_DESC(ql2xintrdelaytimer,
99 "ZIO: Waiting time for Firmware before it generates an "
100 "interrupt to the host to notify completion of request.");
103 module_param(ConfigRequired, int, S_IRUGO|S_IRUSR);
104 MODULE_PARM_DESC(ConfigRequired,
105 "If 1, then only configured devices passed in through the"
106 "ql2xopts parameter will be presented to the OS");
108 int Bind = BIND_BY_PORT_NAME;
109 module_param(Bind, int, S_IRUGO|S_IRUSR);
110 MODULE_PARM_DESC(Bind,
111 "Target persistent binding method: "
112 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
114 int ql2xsuspendcount = SUSPEND_COUNT;
115 module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR);
116 MODULE_PARM_DESC(ql2xsuspendcount,
117 "Number of 6-second suspend iterations to perform while a "
118 "target returns a <NOT READY> status. Default is 10 "
121 int ql2xdoinitscan = 1;
122 module_param(ql2xdoinitscan, int, S_IRUGO|S_IWUSR);
123 MODULE_PARM_DESC(ql2xdoinitscan,
124 "Signal mid-layer to perform scan after driver load: 0 -- no "
125 "signal sent to mid-layer.");
127 int ql2xloginretrycount = 0;
128 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
129 MODULE_PARM_DESC(ql2xloginretrycount,
130 "Specify an alternate value for the NVRAM login retry count.");
133 * Proc structures and functions
142 static void copy_mem_info(struct info_str *, char *, int);
143 static int copy_info(struct info_str *, char *, ...);
145 static void qla2x00_free_device(scsi_qla_host_t *);
147 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
150 * SCSI host template entry points
152 static int qla2xxx_slave_configure(struct scsi_device * device);
153 static int qla2xxx_eh_abort(struct scsi_cmnd *);
154 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
155 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
156 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
157 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
158 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
160 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
163 static struct scsi_host_template qla2x00_driver_template = {
164 .module = THIS_MODULE,
166 .proc_name = "qla2xxx",
167 .proc_info = qla2x00_proc_info,
168 .queuecommand = qla2x00_queuecommand,
170 .eh_abort_handler = qla2xxx_eh_abort,
171 .eh_device_reset_handler = qla2xxx_eh_device_reset,
172 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
173 .eh_host_reset_handler = qla2xxx_eh_host_reset,
175 .slave_configure = qla2xxx_slave_configure,
179 .use_clustering = ENABLE_CLUSTERING,
180 .sg_tablesize = SG_ALL,
183 * The RISC allows for each command to transfer (2^32-1) bytes of data,
184 * which equates to 0x800000 sectors.
186 .max_sectors = 0xFFFF,
189 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
191 static void qla2x00_display_fc_names(scsi_qla_host_t *);
193 /* TODO Convert to inlines
197 #define WATCH_INTERVAL 1 /* number of seconds */
199 static void qla2x00_timer(scsi_qla_host_t *);
201 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
202 void *, unsigned long);
203 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
204 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
207 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
209 init_timer(&ha->timer);
210 ha->timer.expires = jiffies + interval * HZ;
211 ha->timer.data = (unsigned long)ha;
212 ha->timer.function = (void (*)(unsigned long))func;
213 add_timer(&ha->timer);
214 ha->timer_active = 1;
218 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
220 mod_timer(&ha->timer, jiffies + interval * HZ);
223 static __inline__ void
224 qla2x00_stop_timer(scsi_qla_host_t *ha)
226 del_timer_sync(&ha->timer);
227 ha->timer_active = 0;
230 void qla2x00_cmd_timeout(srb_t *);
232 static __inline__ void qla2x00_callback(scsi_qla_host_t *, struct scsi_cmnd *);
233 static __inline__ void sp_put(struct scsi_qla_host * ha, srb_t *sp);
234 static __inline__ void sp_get(struct scsi_qla_host * ha, srb_t *sp);
235 static __inline__ void
236 qla2x00_delete_from_done_queue(scsi_qla_host_t *, srb_t *);
238 /**************************************************************************
242 * Decrement reference count and call the callback if we're the last
243 * owner of the specified sp. Will get the host_lock before calling
247 * ha - pointer to the scsi_qla_host_t where the callback is to occur.
248 * sp - pointer to srb_t structure to use.
252 **************************************************************************/
254 sp_put(struct scsi_qla_host * ha, srb_t *sp)
256 if (atomic_read(&sp->ref_count) == 0) {
257 qla_printk(KERN_INFO, ha,
258 "%s(): **** SP->ref_count not zero\n",
265 if (!atomic_dec_and_test(&sp->ref_count)) {
269 qla2x00_callback(ha, sp->cmd);
272 /**************************************************************************
276 * Increment reference count of the specified sp.
279 * sp - pointer to srb_t structure to use.
283 **************************************************************************/
285 sp_get(struct scsi_qla_host * ha, srb_t *sp)
287 atomic_inc(&sp->ref_count);
289 if (atomic_read(&sp->ref_count) > 2) {
290 qla_printk(KERN_INFO, ha,
291 "%s(): **** SP->ref_count greater than two\n",
301 * Returns the completed SCSI command to LINUX.
304 * ha -- Host adapter structure
305 * cmd -- SCSI mid-level command structure.
308 * Note:From failover point of view we always get the sp
309 * from vis_ha pool in queuecommand.So when we put it
310 * back to the pool it has to be the vis_ha.
311 * So rely on struct scsi_cmnd to get the vis_ha and not on sp.
314 qla2x00_callback(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
316 srb_t *sp = (srb_t *) CMD_SP(cmd);
317 scsi_qla_host_t *vis_ha;
320 unsigned long cpu_flags = 0;
322 cmd->host_scribble = (unsigned char *) NULL;
323 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
326 qla_printk(KERN_INFO, ha,
327 "%s(): **** CMD derives a NULL SP\n",
334 * If command status is not DID_BUS_BUSY then go ahead and freed sp.
337 * Cancel command timeout
339 qla2x00_delete_timer_from_cmd(sp);
342 * Put SP back in the free queue
347 got_sense = (sp->flags & SRB_GOT_SENSE)? 1: 0;
348 add_to_free_queue(vis_ha, sp);
350 if (host_byte(cmd->result) == DID_OK) {
352 ha->total_bytes += cmd->bufflen;
354 /* If lun was suspended then clear retry count */
355 spin_lock_irqsave(&lq->q_lock, cpu_flags);
356 if (!test_bit(LUN_EXEC_DELAYED, &lq->q_flag))
357 lq->q_state = LUN_STATE_READY;
358 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
360 } else if (host_byte(cmd->result) == DID_ERROR) {
362 ha->total_dev_errs++;
365 /* Call the mid-level driver interrupt handler */
366 (*(cmd)->scsi_done)(cmd);
370 qla2x00_delete_from_done_queue(scsi_qla_host_t *dest_ha, srb_t *sp)
372 /* remove command from done list */
373 list_del_init(&sp->list);
374 dest_ha->done_q_cnt--;
375 sp->state = SRB_NO_QUEUE_STATE;
377 if (sp->flags & SRB_DMA_VALID) {
378 sp->flags &= ~SRB_DMA_VALID;
380 /* Release memory used for this I/O */
381 if (sp->cmd->use_sg) {
382 pci_unmap_sg(dest_ha->pdev, sp->cmd->request_buffer,
383 sp->cmd->use_sg, sp->cmd->sc_data_direction);
384 } else if (sp->cmd->request_bufflen) {
385 pci_unmap_page(dest_ha->pdev, sp->dma_handle,
386 sp->cmd->request_bufflen,
387 sp->cmd->sc_data_direction);
392 static int qla2x00_do_dpc(void *data);
394 static void qla2x00_rst_aen(scsi_qla_host_t *);
396 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
397 static void qla2x00_mem_free(scsi_qla_host_t *ha);
398 int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
399 void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
401 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
403 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
405 static struct bin_attribute sysfs_fw_dump_attr = {
408 .mode = S_IRUSR | S_IWUSR,
409 .owner = THIS_MODULE,
412 .read = qla2x00_sysfs_read_fw_dump,
413 .write = qla2x00_sysfs_write_fw_dump,
415 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
417 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
419 static struct bin_attribute sysfs_nvram_attr = {
422 .mode = S_IRUSR | S_IWUSR,
423 .owner = THIS_MODULE,
425 .size = sizeof(nvram_t),
426 .read = qla2x00_sysfs_read_nvram,
427 .write = qla2x00_sysfs_write_nvram,
432 qla2x00_set_info(char *buffer, int length, struct Scsi_Host *shost)
434 return (-ENOSYS); /* Currently this is a no-op */
437 /* -------------------------------------------------------------------------- */
440 /* SysFS attributes. */
441 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
442 loff_t off, size_t count)
444 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
445 struct device, kobj)));
447 if (ha->fw_dump_reading == 0)
449 if (off > ha->fw_dump_buffer_len)
451 if (off + count > ha->fw_dump_buffer_len)
452 count = ha->fw_dump_buffer_len - off;
454 memcpy(buf, &ha->fw_dump_buffer[off], count);
459 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
460 loff_t off, size_t count)
462 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
463 struct device, kobj)));
470 reading = simple_strtol(buf, NULL, 10);
473 if (ha->fw_dump_reading == 1) {
474 qla_printk(KERN_INFO, ha,
475 "Firmware dump cleared on (%ld).\n",
478 vfree(ha->fw_dump_buffer);
479 free_pages((unsigned long)ha->fw_dump,
482 ha->fw_dump_reading = 0;
483 ha->fw_dump_buffer = NULL;
488 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
489 ha->fw_dump_reading = 1;
491 dump_size = FW_DUMP_SIZE_1M;
492 if (ha->fw_memory_size < 0x20000)
493 dump_size = FW_DUMP_SIZE_128K;
494 else if (ha->fw_memory_size < 0x80000)
495 dump_size = FW_DUMP_SIZE_512K;
496 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
497 if (ha->fw_dump_buffer == NULL) {
498 qla_printk(KERN_WARNING, ha,
499 "Unable to allocate memory for firmware "
500 "dump buffer (%d).\n", dump_size);
502 ha->fw_dump_reading = 0;
505 qla_printk(KERN_INFO, ha,
506 "Firmware dump ready for read on (%ld).\n",
508 memset(ha->fw_dump_buffer, 0, dump_size);
509 if (IS_QLA2100(ha) || IS_QLA2200(ha))
510 qla2100_ascii_fw_dump(ha);
512 qla2300_ascii_fw_dump(ha);
513 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
520 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
521 loff_t off, size_t count)
523 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
524 struct device, kobj)));
529 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
533 spin_lock_irqsave(&ha->hardware_lock, flags);
534 qla2x00_lock_nvram_access(ha);
535 witer = (uint16_t *)buf;
536 for (cnt = 0; cnt < count / 2; cnt++) {
537 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
538 cnt+ha->nvram_base));
541 qla2x00_unlock_nvram_access(ha);
542 spin_unlock_irqrestore(&ha->hardware_lock, flags);
547 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
548 loff_t off, size_t count)
550 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
551 struct device, kobj)));
558 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
561 /* Checksum NVRAM. */
562 iter = (uint8_t *)buf;
564 for (cnt = 0; cnt < count - 1; cnt++)
566 chksum = ~chksum + 1;
570 spin_lock_irqsave(&ha->hardware_lock, flags);
571 qla2x00_lock_nvram_access(ha);
572 witer = (uint16_t *)buf;
573 for (cnt = 0; cnt < count / 2; cnt++) {
574 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
575 cpu_to_le16(*witer));
578 qla2x00_unlock_nvram_access(ha);
579 spin_unlock_irqrestore(&ha->hardware_lock, flags);
584 /* -------------------------------------------------------------------------- */
586 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
588 static char *pci_bus_modes[] = {
589 "33", "66", "100", "133",
594 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
597 strcat(str, pci_bus_modes[pci_bus]);
599 pci_bus = (ha->pci_attr & BIT_8) >> 8;
601 strcat(str, pci_bus_modes[pci_bus]);
603 strcat(str, " MHz)");
609 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
613 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
614 ha->fw_minor_version,
615 ha->fw_subminor_version);
617 if (ha->fw_attributes & BIT_9) {
622 switch (ha->fw_attributes & 0xFF) {
636 sprintf(un_str, "(%x)", ha->fw_attributes);
640 if (ha->fw_attributes & 0x100)
646 /**************************************************************************
647 * qla2x00_queuecommand
650 * Queue a command to the controller.
653 * cmd - pointer to Scsi cmd structure
654 * fn - pointer to Scsi done function
660 * The mid-level driver tries to ensures that queuecommand never gets invoked
661 * concurrently with itself or the interrupt handler (although the
662 * interrupt handler may call this routine as part of request-completion
664 **************************************************************************/
666 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
671 scsi_qla_host_t *ha, *ha2;
673 struct Scsi_Host *host;
674 unsigned int b, t, l;
675 unsigned long handle;
679 host = cmd->device->host;
680 ha = (scsi_qla_host_t *) host->hostdata;
685 spin_unlock_irq(ha->host->host_lock);
688 * Allocate a command packet from the "sp" pool. If we cant get back
689 * one then let scsi layer come back later.
691 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
692 qla_printk(KERN_WARNING, ha,
693 "Couldn't allocate memory for sp - retried.\n");
695 spin_lock_irq(ha->host->host_lock);
701 CMD_SP(cmd) = (void *)sp;
704 if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {
705 /* Need to set sp->flags */
706 sp->flags |= SRB_IOCTL;
707 CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */
710 sp->fo_retry_cnt = 0;
713 /* Generate LU queue on bus, target, LUN */
714 b = cmd->device->channel;
716 l = cmd->device->lun;
719 * Start Command Timer. Typically it will be 2 seconds less than what
720 * is requested by the Host such that we can return the IO before
723 if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)
724 qla2x00_add_timer_to_cmd(sp,
725 (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
727 qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);
729 if (l >= ha->max_luns) {
730 cmd->result = DID_NO_CONNECT << 16;
731 sp->err_id = SRB_ERR_PORT;
733 spin_lock_irq(ha->host->host_lock);
740 if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&
741 (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {
742 fcport = lq->fclun->fcport;
750 /* Set an invalid handle until we issue the command to ISP */
751 /* then we will set the real handle value. */
752 handle = INVALID_HANDLE;
753 cmd->host_scribble = (unsigned char *)handle;
755 /* Bookkeeping information */
756 sp->r_start = jiffies; /* time the request was recieved */
759 /* Setup device queue pointers. */
766 * 1. When device is added from persistent binding but has not been
767 * discovered yet.The state of loopid == PORT_AVAIL.
768 * 2. When device is never found on the bus.(loopid == UNUSED)
770 * IF Device Queue is not created, or device is not in a valid state
771 * and link down error reporting is enabled, reject IO.
773 if (fcport == NULL) {
774 DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",
777 cmd->result = DID_NO_CONNECT << 16;
778 sp->err_id = SRB_ERR_PORT;
780 spin_lock_irq(ha->host->host_lock);
787 /* Only modify the allowed count if the target is a *non* tape device */
788 if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {
789 sp->flags &= ~SRB_TAPE;
790 if (cmd->allowed < ql2xretrycount) {
791 cmd->allowed = ql2xretrycount;
794 sp->flags |= SRB_TAPE;
797 DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "
798 "flags=0x%x fo retry=%d, pid=%ld\n",
799 ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,
800 cmd->serial_number));
801 DEBUG5(qla2x00_print_scsi_cmd(cmd));
803 sp->fclun = lq->fclun;
806 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&
807 cmd->request_bufflen != 0) {
809 DEBUG2(printk(KERN_WARNING
810 "scsi(%ld): Incorrect data direction - transfer "
811 "length=%d, direction=%d, pid=%ld, opcode=%x\n",
812 ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,
813 cmd->serial_number, cmd->cmnd[0]));
818 * Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.
820 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
821 atomic_read(&ha2->loop_state) == LOOP_DEAD) {
823 * Add the command to the done-queue for later failover
826 cmd->result = DID_NO_CONNECT << 16;
827 if (atomic_read(&ha2->loop_state) == LOOP_DOWN)
828 sp->err_id = SRB_ERR_LOOP;
830 sp->err_id = SRB_ERR_PORT;
832 add_to_done_queue(ha, sp);
835 spin_lock_irq(ha->host->host_lock);
838 if (tq && test_bit(TQF_SUSPENDED, &tq->flags) &&
839 (sp->flags & SRB_TAPE) == 0) {
840 /* If target suspended put incoming I/O in retry_q. */
841 qla2x00_extend_timeout(sp->cmd, 10);
842 add_to_scsi_retry_queue(ha, sp);
844 was_empty = add_to_pending_queue(ha, sp);
846 if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {
851 if (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
852 spin_lock_irqsave(&ha->hardware_lock, flags);
853 qla2x00_process_response_queue(ha);
854 spin_unlock_irqrestore(&ha->hardware_lock, flags);
858 /* We submit to the hardware if:
860 * 1) we're on the cpu the irq's arrive on or
861 * 2) there are very few io's outstanding.
863 * In all other cases we'll let an irq pick up our IO and submit it
864 * to the controller to improve affinity.
866 if (smp_processor_id() == ha->last_irq_cpu || was_empty)
869 spin_lock_irq(ha->host->host_lock);
875 * qla2x00_eh_wait_on_command
876 * Waits for the command to be returned by the Firmware for some
880 * ha = actual ha whose done queue will contain the command
881 * returned by firmware.
882 * cmd = Scsi Command to wait on.
883 * flag = Abort/Reset(Bus or Device Reset)
890 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
892 #define ABORT_POLLING_PERIOD HZ
893 #define ABORT_WAIT_TIME ((10 * HZ) / (ABORT_POLLING_PERIOD))
898 struct list_head *list, *temp;
899 u_long max_wait_time = ABORT_WAIT_TIME;
902 /* Check on done queue */
903 spin_lock(&ha->list_lock);
904 list_for_each_safe(list, temp, &ha->done_queue) {
905 rp = list_entry(list, srb_t, list);
908 * Found command. Just exit and wait for the cmd sent
911 if (cmd == rp->cmd) {
913 DEBUG3(printk("%s: found in done queue.\n",
918 spin_unlock(&ha->list_lock);
920 /* Complete the cmd right away. */
922 qla2x00_delete_from_done_queue(ha, rp);
928 spin_unlock_irq(ha->host->host_lock);
930 set_current_state(TASK_UNINTERRUPTIBLE);
931 schedule_timeout(ABORT_POLLING_PERIOD);
933 spin_lock_irq(ha->host->host_lock);
935 } while ((max_wait_time--));
938 DEBUG2(printk(KERN_INFO "%s: found cmd=%p.\n", __func__, cmd));
944 * qla2x00_wait_for_hba_online
945 * Wait till the HBA is online after going through
946 * <= MAX_RETRIES_OF_ISP_ABORT or
947 * finally HBA is disabled ie marked offline
950 * ha - pointer to host adapter structure
953 * Does context switching-Release SPIN_LOCK
954 * (if any) before calling this routine.
957 * Success (Adapter is online) : 0
958 * Failed (Adapter is offline/disabled) : 1
961 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
964 unsigned long wait_online;
966 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
967 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
968 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
969 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
970 ha->dpc_active) && time_before(jiffies, wait_online)) {
972 set_current_state(TASK_UNINTERRUPTIBLE);
973 schedule_timeout(HZ);
975 if (ha->flags.online)
976 return_status = QLA_SUCCESS;
978 return_status = QLA_FUNCTION_FAILED;
980 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
982 return (return_status);
986 * qla2x00_wait_for_loop_ready
987 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
988 * to be in LOOP_READY state.
990 * ha - pointer to host adapter structure
993 * Does context switching-Release SPIN_LOCK
994 * (if any) before calling this routine.
998 * Success (LOOP_READY) : 0
999 * Failed (LOOP_NOT_READY) : 1
1002 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
1004 int return_status = QLA_SUCCESS;
1005 unsigned long loop_timeout ;
1007 /* wait for 5 min at the max for loop to be ready */
1008 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1010 while ((!atomic_read(&ha->loop_down_timer) &&
1011 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
1012 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
1013 atomic_read(&ha->loop_state) != LOOP_READY) {
1014 set_current_state(TASK_UNINTERRUPTIBLE);
1015 schedule_timeout(HZ);
1016 if (time_after_eq(jiffies, loop_timeout)) {
1017 return_status = QLA_FUNCTION_FAILED;
1021 return (return_status);
1024 /**************************************************************************
1028 * The abort function will abort the specified command.
1031 * cmd = Linux SCSI command packet to be aborted.
1034 * Either SUCCESS or FAILED.
1037 **************************************************************************/
1039 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1042 int return_status = FAILED;
1044 scsi_qla_host_t *ha;
1045 scsi_qla_host_t *vis_ha;
1048 struct list_head *list, *temp;
1049 struct Scsi_Host *host;
1051 unsigned int b, t, l;
1053 /* Get the SCSI request ptr */
1054 sp = (srb_t *) CMD_SP(cmd);
1057 * If sp is NULL, command is already returned.
1058 * sp is NULLED just before we call back scsi_done
1062 /* no action - we don't have command */
1063 qla_printk(KERN_INFO, to_qla_host(cmd->device->host),
1064 "qla2xxx_eh_abort: cmd already done sp=%p\n", sp);
1065 DEBUG(printk("qla2xxx_eh_abort: cmd already done sp=%p\n", sp);)
1069 DEBUG(printk("qla2xxx_eh_abort: refcount %i \n",
1070 atomic_read(&sp->ref_count));)
1073 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1074 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1078 /* Generate LU queue on bus, target, LUN */
1079 b = cmd->device->channel;
1080 t = cmd->device->id;
1081 l = cmd->device->lun;
1082 q = GET_LU_Q(vis_ha, t, l);
1084 qla_printk(KERN_INFO, ha,
1085 "%s scsi(%ld:%d:%d:%d): cmd_timeout_in_sec=0x%x.\n", __func__,
1086 ha->host_no, (int)b, (int)t, (int)l,
1087 cmd->timeout_per_command / HZ);
1090 * if no LUN queue then something is very wrong!!!
1093 qla_printk(KERN_WARNING, ha,
1094 "qla2x00: (%x:%x:%x) No LUN queue.\n", b, t, l);
1096 /* no action - we don't have command */
1100 DEBUG2(printk("scsi(%ld): ABORTing cmd=%p sp=%p jiffies = 0x%lx, "
1101 "timeout=%x, dpc_flags=%lx, vis_ha->dpc_flags=%lx q->flag=%lx\n",
1102 ha->host_no, cmd, sp, jiffies, cmd->timeout_per_command / HZ,
1103 ha->dpc_flags, vis_ha->dpc_flags, q->q_flag));
1104 DEBUG2(qla2x00_print_scsi_cmd(cmd));
1106 spin_unlock_irq(ha->host->host_lock);
1107 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1108 DEBUG2(printk("%s failed:board disabled\n", __func__);)
1109 spin_lock_irq(ha->host->host_lock);
1112 spin_lock_irq(ha->host->host_lock);
1114 /* Search done queue */
1115 spin_lock(&ha->list_lock);
1116 list_for_each_safe(list, temp, &ha->done_queue) {
1117 rp = list_entry(list, srb_t, list);
1123 * Found command.Remove it from done list.
1124 * And proceed to post completion to scsi mid layer.
1126 return_status = SUCCESS;
1128 qla2x00_delete_from_done_queue(ha, sp);
1131 } /* list_for_each_safe() */
1132 spin_unlock(&ha->list_lock);
1135 * Return immediately if the aborted command was already in the done
1139 qla_printk(KERN_INFO, ha,
1140 "qla2xxx_eh_abort: Returning completed command=%p sp=%p\n",
1143 return (return_status);
1148 * See if this command is in the retry queue
1150 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p in retry "
1153 spin_lock(&ha->list_lock);
1154 list_for_each_safe(list, temp, &ha->retry_queue) {
1155 rp = list_entry(list, srb_t, list);
1161 DEBUG2(printk("qla2xxx_eh_abort: found "
1162 "in retry queue. SP=%p\n", sp);)
1164 __del_from_retry_queue(ha, rp);
1165 cmd->result = DID_ABORT << 16;
1166 __add_to_done_queue(ha, rp);
1168 return_status = SUCCESS;
1174 spin_unlock(&ha->list_lock);
1178 * Our SP pointer points at the command we want to remove from the
1179 * pending queue providing we haven't already sent it to the adapter.
1182 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1183 "in pending queue.\n", sp);)
1185 spin_lock(&vis_ha->list_lock);
1186 list_for_each_safe(list, temp, &vis_ha->pending_queue) {
1187 rp = list_entry(list, srb_t, list);
1192 /* Remove srb from LUN queue. */
1193 rp->flags |= SRB_ABORTED;
1195 DEBUG2(printk("qla2xxx_eh_abort: Cmd in pending queue."
1196 " serial_number %ld.\n",
1197 sp->cmd->serial_number);)
1199 __del_from_pending_queue(vis_ha, rp);
1200 cmd->result = DID_ABORT << 16;
1202 __add_to_done_queue(vis_ha, rp);
1204 return_status = SUCCESS;
1208 } /* list_for_each_safe() */
1209 spin_unlock(&vis_ha->list_lock);
1210 } /*End of if !found */
1212 if (!found) { /* find the command in our active list */
1213 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1214 "in outstanding queue.\n", sp);)
1216 spin_lock(&ha->hardware_lock);
1217 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1218 sp = ha->outstanding_cmds[i];
1226 DEBUG2(printk("qla2xxx_eh_abort(%ld): aborting sp %p "
1227 "from RISC. pid=%ld sp->state=%x q->q_flag=%lx\n",
1228 ha->host_no, sp, sp->cmd->serial_number,
1229 sp->state, q->q_flag);)
1230 DEBUG(qla2x00_print_scsi_cmd(cmd);)
1232 /* Get a reference to the sp and drop the lock.*/
1235 spin_unlock(&ha->hardware_lock);
1236 spin_unlock_irq(ha->host->host_lock);
1238 if (qla2x00_abort_command(ha, sp)) {
1239 DEBUG2(printk("qla2xxx_eh_abort: abort_command "
1241 return_status = FAILED;
1243 DEBUG3(printk("qla2xxx_eh_abort: abort_command "
1244 " mbx success.\n");)
1245 return_status = SUCCESS;
1250 spin_lock_irq(ha->host->host_lock);
1251 spin_lock(&ha->hardware_lock);
1254 * Regardless of mailbox command status, go check on
1255 * done queue just in case the sp is already done.
1259 }/*End of for loop */
1260 spin_unlock(&ha->hardware_lock);
1262 } /*End of if !found */
1264 /* Waiting for our command in done_queue to be returned to OS.*/
1265 if (qla2x00_eh_wait_on_command(ha, cmd) != 0) {
1266 DEBUG2(printk("qla2xxx_eh_abort: cmd returned back to OS.\n");)
1267 return_status = SUCCESS;
1270 if (return_status == FAILED) {
1271 qla_printk(KERN_INFO, ha,
1272 "qla2xxx_eh_abort Exiting: status=Failed\n");
1276 DEBUG2(printk("qla2xxx_eh_abort: Exiting. return_status=0x%x.\n",
1279 return return_status;
1282 /**************************************************************************
1283 * qla2x00_eh_wait_for_pending_target_commands
1286 * Waits for all the commands to come back from the specified target.
1289 * ha - pointer to scsi_qla_host structure.
1292 * Either SUCCESS or FAILED.
1295 **************************************************************************/
1297 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
1302 struct scsi_cmnd *cmd;
1307 * Waiting for all commands for the designated target in the active
1310 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1311 spin_lock(&ha->hardware_lock);
1312 sp = ha->outstanding_cmds[cnt];
1315 spin_unlock(&ha->hardware_lock);
1316 if (cmd->device->id == t) {
1317 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
1324 spin_unlock(&ha->hardware_lock);
1331 /**************************************************************************
1332 * qla2xxx_eh_device_reset
1335 * The device reset function will reset the target and abort any
1336 * executing commands.
1338 * NOTE: The use of SP is undefined within this context. Do *NOT*
1339 * attempt to use this value, even if you determine it is
1343 * cmd = Linux SCSI command packet of the command that cause the
1347 * SUCCESS/FAILURE (defined as macro in scsi.h).
1349 **************************************************************************/
1351 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1354 unsigned int b, t, l;
1355 scsi_qla_host_t *ha;
1358 fc_port_t *fcport_to_reset;
1360 struct list_head *list, *temp;
1362 return_status = FAILED;
1365 "%s(): **** SCSI mid-layer passing in NULL cmd\n",
1368 return (return_status);
1371 b = cmd->device->channel;
1372 t = cmd->device->id;
1373 l = cmd->device->lun;
1374 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1378 qla_printk(KERN_INFO, ha,
1379 "%s(): **** CMD derives a NULL TGT_Q\n", __func__);
1381 return (return_status);
1383 lq = (os_lun_t *)LUN_Q(ha, t, l);
1386 "%s(): **** CMD derives a NULL LUN_Q\n", __func__);
1388 return (return_status);
1390 fcport_to_reset = lq->fclun->fcport;
1392 /* If we are coming in from the back-door, stall I/O until complete. */
1393 if (!cmd->device->host->eh_active)
1394 set_bit(TQF_SUSPENDED, &tq->flags);
1396 qla_printk(KERN_INFO, ha,
1397 "scsi(%ld:%d:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, b, t, l);
1399 DEBUG2(printk(KERN_INFO
1400 "scsi(%ld): DEVICE_RESET cmd=%p jiffies = 0x%lx, timeout=%x, "
1401 "dpc_flags=%lx, status=%x allowed=%d cmd.state=%x\n",
1402 ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
1403 ha->dpc_flags, cmd->result, cmd->allowed, cmd->state));
1405 /* Clear commands from the retry queue. */
1406 spin_lock(&ha->list_lock);
1407 list_for_each_safe(list, temp, &ha->retry_queue) {
1408 rp = list_entry(list, srb_t, list);
1410 if (t != rp->cmd->device->id)
1413 DEBUG2(printk(KERN_INFO
1414 "qla2xxx_eh_reset: found in retry queue. SP=%p\n", rp));
1416 __del_from_retry_queue(ha, rp);
1417 rp->cmd->result = DID_RESET << 16;
1418 __add_to_done_queue(ha, rp);
1420 spin_unlock(&ha->list_lock);
1422 spin_unlock_irq(ha->host->host_lock);
1424 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1425 DEBUG2(printk(KERN_INFO
1426 "%s failed:board disabled\n",__func__));
1428 spin_lock_irq(ha->host->host_lock);
1429 goto eh_dev_reset_done;
1432 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1433 if (qla2x00_device_reset(ha, fcport_to_reset) == 0) {
1434 return_status = SUCCESS;
1437 #if defined(LOGOUT_AFTER_DEVICE_RESET)
1438 if (return_status == SUCCESS) {
1439 if (fcport_to_reset->flags & FC_FABRIC_DEVICE) {
1440 qla2x00_fabric_logout(ha,
1441 fcport_to_reset->loop_id);
1442 qla2x00_mark_device_lost(ha, fcport_to_reset);
1447 DEBUG2(printk(KERN_INFO
1448 "%s failed: loop not ready\n",__func__);)
1451 spin_lock_irq(ha->host->host_lock);
1453 if (return_status == FAILED) {
1454 DEBUG3(printk("%s(%ld): device reset failed\n",
1455 __func__, ha->host_no));
1456 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
1459 goto eh_dev_reset_done;
1463 * If we are coming down the EH path, wait for all commands to
1464 * complete for the device.
1466 if (cmd->device->host->eh_active) {
1467 if (qla2x00_eh_wait_for_pending_target_commands(ha, t))
1468 return_status = FAILED;
1470 if (return_status == FAILED) {
1471 DEBUG3(printk("%s(%ld): failed while waiting for "
1472 "commands\n", __func__, ha->host_no));
1473 qla_printk(KERN_INFO, ha,
1474 "%s: failed while waiting for commands\n",
1477 goto eh_dev_reset_done;
1481 qla_printk(KERN_INFO, ha,
1482 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1483 ha->host_no, b, t, l);
1487 if (!cmd->device->host->eh_active)
1488 clear_bit(TQF_SUSPENDED, &tq->flags);
1490 return (return_status);
1493 /**************************************************************************
1494 * qla2x00_eh_wait_for_pending_commands
1497 * Waits for all the commands to come back from the specified host.
1500 * ha - pointer to scsi_qla_host structure.
1507 **************************************************************************/
1509 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
1514 struct scsi_cmnd *cmd;
1519 * Waiting for all commands for the designated target in the active
1522 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1523 spin_lock(&ha->hardware_lock);
1524 sp = ha->outstanding_cmds[cnt];
1527 spin_unlock(&ha->hardware_lock);
1528 status = qla2x00_eh_wait_on_command(ha, cmd);
1533 spin_unlock(&ha->hardware_lock);
1540 /**************************************************************************
1541 * qla2xxx_eh_bus_reset
1544 * The bus reset function will reset the bus and abort any executing
1548 * cmd = Linux SCSI command packet of the command that cause the
1552 * SUCCESS/FAILURE (defined as macro in scsi.h).
1554 **************************************************************************/
1556 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1558 scsi_qla_host_t *ha;
1562 ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1563 sp = (srb_t *) CMD_SP(cmd);
1565 qla_printk(KERN_INFO, ha,
1566 "scsi(%ld:%d:%d:%d): LOOP RESET ISSUED.\n", ha->host_no,
1567 cmd->device->channel, cmd->device->id, cmd->device->lun);
1569 spin_unlock_irq(ha->host->host_lock);
1571 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1572 DEBUG2(printk("%s failed:board disabled\n",__func__));
1573 spin_lock_irq(ha->host->host_lock);
1577 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1578 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
1582 spin_lock_irq(ha->host->host_lock);
1587 * Blocking Call. It goes to sleep waiting for cmd to get to done q
1589 * XXX(hch): really? We're under host_lock here..
1591 /* Waiting for our command in done_queue to be returned to OS.*/
1592 if (!qla2x00_eh_wait_for_pending_commands(ha))
1596 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1597 (rval == FAILED) ? "failed" : "succeded");
1602 /**************************************************************************
1603 * qla2xxx_eh_host_reset
1606 * The reset function will reset the Adapter.
1609 * cmd = Linux SCSI command packet of the command that cause the
1613 * Either SUCCESS or FAILED.
1616 **************************************************************************/
1618 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1620 scsi_qla_host_t *ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1623 /* Display which one we're actually resetting for debug. */
1624 DEBUG(printk("qla2xxx_eh_host_reset:Resetting scsi(%ld).\n",
1630 qla_printk(KERN_INFO, ha,
1631 "scsi(%ld:%d:%d:%d): ADAPTER RESET issued.\n", ha->host_no,
1632 cmd->device->channel, cmd->device->id, cmd->device->lun);
1634 spin_unlock_irq(ha->host->host_lock);
1636 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1637 goto board_disabled;
1640 * Fixme-may be dpc thread is active and processing
1641 * loop_resync,so wait a while for it to
1642 * be completed and then issue big hammer.Otherwise
1643 * it may cause I/O failure as big hammer marks the
1644 * devices as lost kicking of the port_down_timer
1645 * while dpc is stuck for the mailbox to complete.
1647 /* Blocking call-Does context switching if loop is Not Ready */
1648 qla2x00_wait_for_loop_ready(ha);
1649 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1650 if (qla2x00_abort_isp(ha)) {
1651 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1652 /* failed. schedule dpc to try */
1653 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1655 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1656 goto board_disabled;
1659 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1661 spin_lock_irq(ha->host->host_lock);
1665 /* Waiting for our command in done_queue to be returned to OS.*/
1666 if (!qla2x00_eh_wait_for_pending_commands(ha))
1670 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1671 (rval == FAILED) ? "failed" : "succeded");
1676 spin_lock_irq(ha->host->host_lock);
1678 qla_printk(KERN_INFO, ha, "%s: failed:board disabled\n", __func__);
1684 * qla2x00_loop_reset
1688 * ha = adapter block pointer.
1694 qla2x00_loop_reset(scsi_qla_host_t *ha)
1696 int status = QLA_SUCCESS;
1700 if (ha->flags.enable_lip_reset) {
1701 status = qla2x00_lip_reset(ha);
1704 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1705 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1706 if ((tq = TGT_Q(ha, t)) == NULL)
1709 if (tq->fcport == NULL)
1712 status = qla2x00_target_reset(ha, 0, t);
1713 if (status != QLA_SUCCESS) {
1719 if (status == QLA_SUCCESS &&
1720 ((!ha->flags.enable_target_reset &&
1721 !ha->flags.enable_lip_reset) ||
1722 ha->flags.enable_lip_full_login)) {
1724 status = qla2x00_full_login_lip(ha);
1727 /* Issue marker command only when we are going to start the I/O */
1728 ha->marker_needed = 1;
1732 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1737 DEBUG3(printk("%s(%ld): exiting normally.\n",
1746 * qla2x00_device_reset
1747 * Issue bus device reset message to the target.
1750 * ha = adapter block pointer.
1752 * TARGET_QUEUE_LOCK must be released.
1753 * ADAPTER_STATE_LOCK must be released.
1759 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1761 /* Abort Target command will clear Reservation */
1762 return qla2x00_abort_target(reset_fcport);
1765 /**************************************************************************
1766 * qla2xxx_slave_configure
1769 **************************************************************************/
1771 qla2xxx_slave_configure(struct scsi_device *sdev)
1773 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1776 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1781 if (sdev->tagged_supported) {
1782 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1783 queue_depth = ql2xmaxqdepth;
1785 ql2xmaxqdepth = queue_depth;
1787 scsi_activate_tcq(sdev, queue_depth);
1789 qla_printk(KERN_INFO, ha,
1790 "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue "
1792 sdev->host->host_no, sdev->channel, sdev->id, sdev->lun,
1795 scsi_adjust_queue_depth(sdev, 0 /* TCQ off */,
1796 sdev->host->hostt->cmd_per_lun /* 3 */);
1803 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1806 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1807 * supported addressing method.
1810 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1812 /* Assume 32bit DMA address */
1813 ha->flags.enable_64bit_addressing = 0;
1814 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1815 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1818 * Given the two variants pci_set_dma_mask(), allow the compiler to
1819 * assist in setting the proper dma mask.
1821 if (sizeof(dma_addr_t) > 4) {
1822 /* Update our PCI device dma_mask for full 64 bits */
1823 if (pci_set_dma_mask(ha->pdev, 0xffffffffffffffffULL) == 0) {
1824 ha->flags.enable_64bit_addressing = 1;
1825 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1826 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1828 if (pci_set_consistent_dma_mask(ha->pdev,
1829 0xffffffffffffffffULL)) {
1830 qla_printk(KERN_DEBUG, ha,
1831 "Failed to set 64 bit PCI consistent mask; "
1833 pci_set_consistent_dma_mask(ha->pdev,
1837 qla_printk(KERN_DEBUG, ha,
1838 "Failed to set 64 bit PCI DMA mask, falling back "
1839 "to 32 bit MASK.\n");
1840 pci_set_dma_mask(ha->pdev, 0xffffffff);
1843 pci_set_dma_mask(ha->pdev, 0xffffffff);
1848 qla2x00_iospace_config(scsi_qla_host_t *ha)
1850 unsigned long pio, pio_len, pio_flags;
1851 unsigned long mmio, mmio_len, mmio_flags;
1853 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1854 pio = pci_resource_start(ha->pdev, 0);
1855 pio_len = pci_resource_len(ha->pdev, 0);
1856 pio_flags = pci_resource_flags(ha->pdev, 0);
1857 if (pio_flags & IORESOURCE_IO) {
1858 if (pio_len < MIN_IOBASE_LEN) {
1859 qla_printk(KERN_WARNING, ha,
1860 "Invalid PCI I/O region size (%s)...\n",
1861 ha->pdev->slot_name);
1865 qla_printk(KERN_WARNING, ha,
1866 "region #0 not a PIO resource (%s)...\n",
1867 ha->pdev->slot_name);
1871 /* Use MMIO operations for all accesses. */
1872 mmio = pci_resource_start(ha->pdev, 1);
1873 mmio_len = pci_resource_len(ha->pdev, 1);
1874 mmio_flags = pci_resource_flags(ha->pdev, 1);
1876 if (!(mmio_flags & IORESOURCE_MEM)) {
1877 qla_printk(KERN_ERR, ha,
1878 "region #0 not an MMIO resource (%s), aborting\n",
1879 ha->pdev->slot_name);
1880 goto iospace_error_exit;
1882 if (mmio_len < MIN_IOBASE_LEN) {
1883 qla_printk(KERN_ERR, ha,
1884 "Invalid PCI mem region size (%s), aborting\n",
1885 ha->pdev->slot_name);
1886 goto iospace_error_exit;
1889 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1890 qla_printk(KERN_WARNING, ha,
1891 "Failed to reserve PIO/MMIO regions (%s)\n",
1892 ha->pdev->slot_name);
1894 goto iospace_error_exit;
1897 ha->pio_address = pio;
1898 ha->pio_length = pio_len;
1899 ha->mmio_address = ioremap(mmio, MIN_IOBASE_LEN);
1900 if (!ha->mmio_address) {
1901 qla_printk(KERN_ERR, ha,
1902 "cannot remap MMIO (%s), aborting\n", ha->pdev->slot_name);
1904 goto iospace_error_exit;
1906 ha->mmio_length = mmio_len;
1907 ha->iobase = (device_reg_t *) ha->mmio_address;
1916 * PCI driver interface
1918 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1922 struct Scsi_Host *host;
1923 scsi_qla_host_t *ha;
1924 unsigned long flags = 0;
1925 unsigned long wait_switch = 0;
1929 if (pci_enable_device(pdev))
1932 host = scsi_host_alloc(&qla2x00_driver_template,
1933 sizeof(scsi_qla_host_t));
1936 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1940 /* Clear our data area */
1941 ha = (scsi_qla_host_t *)host->hostdata;
1942 memset(ha, 0, sizeof(scsi_qla_host_t));
1946 ha->host_no = host->host_no;
1947 ha->brd_info = brd_info;
1948 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1950 /* Configure PCI I/O space */
1951 ret = qla2x00_iospace_config(ha);
1956 /* Sanitize the information from PCI BIOS. */
1957 host->irq = pdev->irq;
1959 qla_printk(KERN_INFO, ha,
1960 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1961 host->irq, ha->iobase);
1963 spin_lock_init(&ha->hardware_lock);
1965 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1968 ha->total_isr_cnt = 0;
1969 ha->total_isp_aborts = 0;
1970 ha->total_lip_cnt = 0;
1971 ha->total_dev_errs = 0;
1973 ha->total_bytes = 0;
1975 ha->prev_topology = 0;
1976 ha->ports = MAX_BUSES;
1978 if (IS_QLA2100(ha)) {
1979 ha->max_targets = MAX_TARGETS_2100;
1980 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1981 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1982 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1983 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1984 host->sg_tablesize = 32;
1985 } else if (IS_QLA2200(ha)) {
1986 ha->max_targets = MAX_TARGETS_2200;
1987 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1988 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1989 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1990 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1991 } else /*if (IS_QLA2300(ha))*/ {
1992 ha->max_targets = MAX_TARGETS_2200;
1993 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1994 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1995 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1996 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1998 host->can_queue = ha->request_q_length + 128;
2000 /* load the F/W, read paramaters, and init the H/W */
2001 ha->instance = num_hosts;
2003 init_MUTEX(&ha->mbx_cmd_sem);
2004 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
2006 INIT_LIST_HEAD(&ha->list);
2007 INIT_LIST_HEAD(&ha->fcports);
2008 INIT_LIST_HEAD(&ha->rscn_fcports);
2009 INIT_LIST_HEAD(&ha->done_queue);
2010 INIT_LIST_HEAD(&ha->retry_queue);
2011 INIT_LIST_HEAD(&ha->scsi_retry_queue);
2012 INIT_LIST_HEAD(&ha->pending_queue);
2015 * These locks are used to prevent more than one CPU
2016 * from modifying the queue at the same time. The
2017 * higher level "host_lock" will reduce most
2018 * contention for these locks.
2020 spin_lock_init(&ha->mbx_reg_lock);
2021 spin_lock_init(&ha->list_lock);
2024 init_completion(&ha->dpc_inited);
2025 init_completion(&ha->dpc_exited);
2027 qla2x00_config_dma_addressing(ha);
2028 if (qla2x00_mem_alloc(ha)) {
2029 qla_printk(KERN_WARNING, ha,
2030 "[ERROR] Failed to allocate memory for adapter\n");
2035 if (qla2x00_initialize_adapter(ha) &&
2036 !(ha->device_flags & DFLG_NO_CABLE)) {
2038 qla_printk(KERN_WARNING, ha,
2039 "Failed to initialize adapter\n");
2041 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2042 "Adapter flags %x.\n",
2043 ha->host_no, ha->device_flags));
2049 * Startup the kernel thread for this host adapter
2051 ha->dpc_should_die = 0;
2052 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
2053 if (ha->dpc_pid < 0) {
2054 qla_printk(KERN_WARNING, ha,
2055 "Unable to start DPC thread!\n");
2059 wait_for_completion(&ha->dpc_inited);
2061 host->this_id = 255;
2062 host->cmd_per_lun = 3;
2063 host->max_cmd_len = MAX_CMDSZ;
2064 host->max_channel = ha->ports - 1;
2065 host->max_lun = ha->max_luns;
2066 BUG_ON(qla2xxx_transport_template == NULL);
2067 host->transportt = qla2xxx_transport_template;
2068 host->unique_id = ha->instance;
2069 host->max_id = ha->max_targets;
2071 if (request_irq(host->irq, qla2x00_intr_handler, SA_INTERRUPT|SA_SHIRQ,
2072 ha->brd_info->drv_name, ha)) {
2073 qla_printk(KERN_WARNING, ha,
2074 "Failed to reserve interrupt %d already in use.\n",
2079 /* Initialized the timer */
2080 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
2082 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2087 /* Disable ISP interrupts. */
2088 qla2x00_disable_intrs(ha);
2090 /* Ensure mailbox registers are free. */
2091 spin_lock_irqsave(&ha->hardware_lock, flags);
2092 WRT_REG_WORD(®->semaphore, 0);
2093 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2094 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2096 /* Enable proper parity */
2097 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2100 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
2102 /* SRAM, Instruction RAM and GP RAM parity */
2103 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
2105 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2107 /* Enable chip interrupts. */
2108 qla2x00_enable_intrs(ha);
2112 * Wait around max loop_reset_delay secs for the devices to come
2113 * on-line. We don't want Linux scanning before we are ready.
2116 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
2117 time_before(jiffies,wait_switch) &&
2118 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
2119 && (ha->device_flags & SWITCH_FOUND) ;) {
2121 qla2x00_check_fabric_devices(ha);
2123 set_current_state(TASK_UNINTERRUPTIBLE);
2124 schedule_timeout(HZ/100);
2127 pci_set_drvdata(pdev, ha);
2128 ha->flags.init_done = 1;
2131 /* List the target we have found */
2132 if (displayConfig) {
2133 qla2x00_display_fc_names(ha);
2136 if (scsi_add_host(host, &pdev->dev))
2139 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
2140 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
2142 qla_printk(KERN_INFO, ha, "\n"
2143 " QLogic Fibre Channel HBA Driver: %s\n"
2145 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
2146 ha->model_number, ha->model_desc ? ha->model_desc: "",
2147 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
2148 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
2149 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
2152 scsi_scan_host(host);
2157 qla2x00_free_device(ha);
2159 scsi_host_put(host);
2163 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
2165 void qla2x00_remove_one(struct pci_dev *pdev)
2167 scsi_qla_host_t *ha;
2169 ha = pci_get_drvdata(pdev);
2171 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
2172 &sysfs_fw_dump_attr);
2173 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
2175 scsi_remove_host(ha->host);
2177 qla2x00_free_device(ha);
2179 scsi_host_put(ha->host);
2181 pci_set_drvdata(pdev, NULL);
2183 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
2186 qla2x00_free_device(scsi_qla_host_t *ha)
2190 /* Abort any outstanding IO descriptors. */
2191 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2192 qla2x00_cancel_io_descriptors(ha);
2194 /* turn-off interrupts on the card */
2195 if (ha->interrupts_on)
2196 qla2x00_disable_intrs(ha);
2199 if (ha->timer_active)
2200 qla2x00_stop_timer(ha);
2202 /* Kill the kernel thread for this host */
2203 if (ha->dpc_pid >= 0) {
2204 ha->dpc_should_die = 1;
2206 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
2208 qla_printk(KERN_ERR, ha,
2209 "Unable to signal DPC thread -- (%d)\n", ret);
2211 /* TODO: SOMETHING MORE??? */
2213 wait_for_completion(&ha->dpc_exited);
2217 qla2x00_mem_free(ha);
2220 ha->flags.online = 0;
2222 /* Detach interrupts */
2224 free_irq(ha->pdev->irq, ha);
2226 /* release io space registers */
2227 pci_release_regions(ha->pdev);
2229 #if MEMORY_MAPPED_IO
2230 if (ha->mmio_address)
2231 iounmap(ha->mmio_address);
2237 * The following support functions are adopted to handle
2238 * the re-entrant qla2x00_proc_info correctly.
2241 copy_mem_info(struct info_str *info, char *data, int len)
2243 if (info->pos + len > info->offset + info->length)
2244 len = info->offset + info->length - info->pos;
2246 if (info->pos + len < info->offset) {
2251 if (info->pos < info->offset) {
2254 partial = info->offset - info->pos;
2256 info->pos += partial;
2261 memcpy(info->buffer, data, len);
2263 info->buffer += len;
2268 copy_info(struct info_str *info, char *fmt, ...)
2274 va_start(args, fmt);
2275 len = vsprintf(buf, fmt, args);
2278 copy_mem_info(info, buf, len);
2283 /*************************************************************************
2287 * Return information to handle /proc support for the driver.
2289 * inout : decides the direction of the dataflow and the meaning of the
2291 * buffer: If inout==0 data is being written to it else read from it
2292 * (ptr to a page buffer)
2293 * *start: If inout==0 start of the valid data in the buffer
2294 * offset: If inout==0 starting offset from the beginning of all
2295 * possible data to return.
2296 * length: If inout==0 max number of bytes to be written into the buffer
2297 * else number of bytes in "buffer"
2299 * < 0: error. errno value.
2300 * >= 0: sizeof data returned.
2301 *************************************************************************/
2303 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
2304 char **start, off_t offset, int length, int inout)
2306 struct info_str info;
2307 int retval = -EINVAL;
2313 uint8_t *loop_state;
2314 scsi_qla_host_t *ha;
2317 DEBUG3(printk(KERN_INFO
2318 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
2319 buffer, offset, length);)
2321 ha = (scsi_qla_host_t *) shost->hostdata;
2324 /* Has data been written to the file? */
2326 "%s: has data been written to the file. \n",
2329 return (qla2x00_set_info(buffer, length, shost));
2336 info.buffer = buffer;
2337 info.length = length;
2338 info.offset = offset;
2341 /* start building the print buffer */
2343 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
2344 " Firmware version %s, ",
2345 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
2347 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
2349 copy_info(&info, "Entry address = %p\n", qla2x00_set_info);
2351 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
2353 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
2354 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
2357 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
2358 (unsigned long long)ha->request_dma,
2359 (unsigned long long)ha->response_dma);
2362 "Request Queue count = %d, Response Queue count = %d\n",
2363 ha->request_q_length, ha->response_q_length);
2366 "Total number of active commands = %ld\n",
2370 "Total number of interrupts = %ld\n",
2371 (long)ha->total_isr_cnt);
2374 " Device queue depth = 0x%x\n",
2375 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
2378 "Number of free request entries = %d\n", ha->req_q_cnt);
2381 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
2384 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
2387 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
2390 "Number of retries for empty slots = %ld\n",
2391 qla2x00_stats.outarray_full);
2394 "Number of reqs in pending_q= %ld, retry_q= %d, "
2395 "done_q= %ld, scsi_retry_q= %d\n",
2396 ha->qthreads, ha->retry_q_cnt,
2397 ha->done_q_cnt, ha->scsi_retry_q_cnt);
2400 flags = (uint32_t *) &ha->flags;
2402 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
2403 loop_state = "DOWN";
2404 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
2406 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
2407 loop_state = "READY";
2408 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
2409 loop_state = "TIMEOUT";
2410 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
2411 loop_state = "UPDATE";
2413 loop_state = "UNKNOWN";
2417 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
2418 loop_state , *flags);
2420 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
2422 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
2424 copy_info(&info, "Link down Timeout = %3.3d\n",
2425 ha->link_down_timeout);
2427 copy_info(&info, "Port down retry = %3.3d\n",
2428 ha->port_down_retry_count);
2430 copy_info(&info, "Login retry count = %3.3d\n",
2431 ha->login_retry_count);
2434 "Commands retried with dropped frame(s) = %d\n",
2435 ha->dropped_frame_error_cnt);
2438 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
2439 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
2441 copy_info(&info, "\n");
2443 /* 2.25 node/port display to proc */
2444 /* Display the node name for adapter */
2445 copy_info(&info, "\nSCSI Device Information:\n");
2447 "scsi-qla%d-adapter-node="
2448 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2450 ha->init_cb->node_name[0],
2451 ha->init_cb->node_name[1],
2452 ha->init_cb->node_name[2],
2453 ha->init_cb->node_name[3],
2454 ha->init_cb->node_name[4],
2455 ha->init_cb->node_name[5],
2456 ha->init_cb->node_name[6],
2457 ha->init_cb->node_name[7]);
2459 /* display the port name for adapter */
2461 "scsi-qla%d-adapter-port="
2462 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2464 ha->init_cb->port_name[0],
2465 ha->init_cb->port_name[1],
2466 ha->init_cb->port_name[2],
2467 ha->init_cb->port_name[3],
2468 ha->init_cb->port_name[4],
2469 ha->init_cb->port_name[5],
2470 ha->init_cb->port_name[6],
2471 ha->init_cb->port_name[7]);
2473 /* Print out device port names */
2474 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2475 if ((tq = TGT_Q(ha, t)) == NULL)
2479 "scsi-qla%d-target-%d="
2480 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2481 (int)ha->instance, t,
2482 tq->port_name[0], tq->port_name[1],
2483 tq->port_name[2], tq->port_name[3],
2484 tq->port_name[4], tq->port_name[5],
2485 tq->port_name[6], tq->port_name[7]);
2488 copy_info(&info, "\nSCSI LUN Information:\n");
2490 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
2492 /* scan for all equipment stats */
2493 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2495 for (l = 0; l < ha->max_luns; l++) {
2496 up = (os_lun_t *) GET_LU_Q(ha, t, l);
2501 if (up->fclun == NULL) {
2506 "(%2d:%2d): Total reqs %ld,",
2510 " Pending reqs %ld,",
2513 if (up->io_cnt < 4) {
2524 " %ld:%d:%02x %02x",
2525 up->fclun->fcport->ha->instance,
2526 up->fclun->fcport->cur_path,
2527 up->fclun->fcport->loop_id,
2528 up->fclun->device_type);
2530 copy_info(&info, "\n");
2532 if (info.pos >= info.offset + info.length) {
2533 /* No need to continue */
2538 if (info.pos >= info.offset + info.length) {
2539 /* No need to continue */
2546 retval = info.pos > info.offset ? info.pos - info.offset : 0;
2548 DEBUG3(printk(KERN_INFO
2549 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
2550 "length=0x%x\n", info.pos, offset, length);)
2556 * qla2x00_display_fc_names
2557 * This routine will the node names of the different devices found
2558 * after port inquiry.
2561 * cmd = SCSI command structure
2567 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2572 /* Display the node name for adapter */
2573 qla_printk(KERN_INFO, ha,
2574 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2576 ha->init_cb->node_name[0],
2577 ha->init_cb->node_name[1],
2578 ha->init_cb->node_name[2],
2579 ha->init_cb->node_name[3],
2580 ha->init_cb->node_name[4],
2581 ha->init_cb->node_name[5],
2582 ha->init_cb->node_name[6],
2583 ha->init_cb->node_name[7]);
2585 /* display the port name for adapter */
2586 qla_printk(KERN_INFO, ha,
2587 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2589 ha->init_cb->port_name[0],
2590 ha->init_cb->port_name[1],
2591 ha->init_cb->port_name[2],
2592 ha->init_cb->port_name[3],
2593 ha->init_cb->port_name[4],
2594 ha->init_cb->port_name[5],
2595 ha->init_cb->port_name[6],
2596 ha->init_cb->port_name[7]);
2598 /* Print out device port names */
2599 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2600 if ((tq = ha->otgt[tgt]) == NULL)
2603 if (tq->fcport == NULL)
2606 switch (ha->binding_type) {
2607 case BIND_BY_PORT_NAME:
2608 qla_printk(KERN_INFO, ha,
2609 "scsi-qla%d-tgt-%d-di-0-port="
2610 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2624 case BIND_BY_PORT_ID:
2625 qla_printk(KERN_INFO, ha,
2626 "scsi-qla%d-tgt-%d-di-0-pid="
2627 "%02x%02x%02x\\;\n",
2637 qla_printk(KERN_INFO, ha,
2638 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2644 * qla2x00_suspend_lun
2645 * Suspend lun and start port down timer
2648 * ha = visable adapter block pointer.
2650 * cp = Scsi command pointer
2651 * time = time in seconds
2652 * count = number of times to let time expire
2653 * delay_lun = non-zero, if lun should be delayed rather than suspended
2656 * QLA_SUCCESS -- suspended lun
2657 * QLA_FUNCTION_FAILED -- Didn't suspend lun
2660 * Interrupt context.
2663 __qla2x00_suspend_lun(scsi_qla_host_t *ha,
2664 os_lun_t *lq, int time, int count, int delay_lun)
2668 struct list_head *list, *temp;
2669 unsigned long flags;
2673 /* if the lun_q is already suspended then don't do it again */
2674 if (lq->q_state == LUN_STATE_READY ||lq->q_state == LUN_STATE_RUN) {
2676 spin_lock_irqsave(&lq->q_lock, flags);
2677 if (lq->q_state == LUN_STATE_READY) {
2681 /* Set the suspend time usually 6 secs */
2682 atomic_set(&lq->q_timer, time);
2684 /* now suspend the lun */
2685 lq->q_state = LUN_STATE_WAIT;
2688 set_bit(LUN_EXEC_DELAYED, &lq->q_flag);
2689 DEBUG(printk(KERN_INFO
2690 "scsi(%ld): Delay lun execution for %d secs, "
2691 "count=%d, max count=%d, state=%d\n",
2694 lq->q_count, lq->q_max, lq->q_state));
2696 DEBUG(printk(KERN_INFO
2697 "scsi(%ld): Suspend lun for %d secs, count=%d, "
2698 "max count=%d, state=%d\n",
2701 lq->q_count, lq->q_max, lq->q_state));
2703 spin_unlock_irqrestore(&lq->q_lock, flags);
2706 * Remove all pending commands from request queue and put them
2707 * in the scsi_retry queue.
2709 spin_lock_irqsave(&ha->list_lock, flags);
2710 list_for_each_safe(list, temp, &ha->pending_queue) {
2711 sp = list_entry(list, srb_t, list);
2712 if (sp->lun_queue != lq)
2715 __del_from_pending_queue(ha, sp);
2717 if (sp->cmd->allowed < count)
2718 sp->cmd->allowed = count;
2719 __add_to_scsi_retry_queue(ha, sp);
2721 } /* list_for_each_safe */
2722 spin_unlock_irqrestore(&ha->list_lock, flags);
2725 rval = QLA_FUNCTION_FAILED;
2732 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2734 * Input: ha = adapter block pointer. fcport = port structure pointer.
2740 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2744 * We may need to retry the login, so don't change the state of the
2745 * port but do the retries.
2747 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2748 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2753 if (fcport->login_retry == 0) {
2754 fcport->login_retry = ha->login_retry_count;
2755 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2757 DEBUG(printk("scsi(%ld): Port login retry: "
2758 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2759 "id = 0x%04x retry cnt=%d\n",
2761 fcport->port_name[0],
2762 fcport->port_name[1],
2763 fcport->port_name[2],
2764 fcport->port_name[3],
2765 fcport->port_name[4],
2766 fcport->port_name[5],
2767 fcport->port_name[6],
2768 fcport->port_name[7],
2770 fcport->login_retry));
2775 * qla2x00_mark_all_devices_lost
2776 * Updates fcport state when device goes offline.
2779 * ha = adapter block pointer.
2780 * fcport = port structure pointer.
2788 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2792 list_for_each_entry(fcport, &ha->fcports, list) {
2793 if (fcport->port_type != FCT_TARGET)
2797 * No point in marking the device as lost, if the device is
2800 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2803 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2809 * Allocates adapter memory.
2816 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2823 * This will loop only once if everything goes well, else some
2824 * number of retries will be performed to get around a kernel
2825 * bug where available mem is not allocated until after a
2826 * little delay and a retry.
2828 ha->request_ring = pci_alloc_consistent(ha->pdev,
2829 ((ha->request_q_length + 1) * (sizeof(request_t))),
2831 if (ha->request_ring == NULL) {
2832 qla_printk(KERN_WARNING, ha,
2833 "Memory Allocation failed - request_ring\n");
2835 qla2x00_mem_free(ha);
2836 set_current_state(TASK_UNINTERRUPTIBLE);
2837 schedule_timeout(HZ/10);
2842 ha->response_ring = pci_alloc_consistent(ha->pdev,
2843 ((ha->response_q_length + 1) * (sizeof(response_t))),
2845 if (ha->response_ring == NULL) {
2846 qla_printk(KERN_WARNING, ha,
2847 "Memory Allocation failed - response_ring\n");
2849 qla2x00_mem_free(ha);
2850 set_current_state(TASK_UNINTERRUPTIBLE);
2851 schedule_timeout(HZ/10);
2856 /* get consistent memory allocated for init control block */
2857 ha->init_cb = pci_alloc_consistent(ha->pdev,
2858 sizeof(init_cb_t), &ha->init_cb_dma);
2859 if (ha->init_cb == NULL) {
2860 qla_printk(KERN_WARNING, ha,
2861 "Memory Allocation failed - init_cb\n");
2863 qla2x00_mem_free(ha);
2864 set_current_state(TASK_UNINTERRUPTIBLE);
2865 schedule_timeout(HZ/10);
2869 memset(ha->init_cb, 0, sizeof(init_cb_t));
2871 /* Allocate ioctl related memory. */
2872 if (qla2x00_alloc_ioctl_mem(ha)) {
2873 qla_printk(KERN_WARNING, ha,
2874 "Memory Allocation failed - ioctl_mem\n");
2876 qla2x00_mem_free(ha);
2877 set_current_state(TASK_UNINTERRUPTIBLE);
2878 schedule_timeout(HZ/10);
2883 if (qla2x00_allocate_sp_pool(ha)) {
2884 qla_printk(KERN_WARNING, ha,
2885 "Memory Allocation failed - "
2886 "qla2x00_allocate_sp_pool()\n");
2888 qla2x00_mem_free(ha);
2889 set_current_state(TASK_UNINTERRUPTIBLE);
2890 schedule_timeout(HZ/10);
2895 /* Allocate memory for SNS commands */
2896 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2897 /* Get consistent memory allocated for SNS commands */
2898 ha->sns_cmd = pci_alloc_consistent(ha->pdev,
2899 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma);
2900 if (ha->sns_cmd == NULL) {
2902 qla_printk(KERN_WARNING, ha,
2903 "Memory Allocation failed - sns_cmd\n");
2905 qla2x00_mem_free(ha);
2906 set_current_state(TASK_UNINTERRUPTIBLE);
2907 schedule_timeout(HZ/10);
2911 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2913 /* Get consistent memory allocated for MS IOCB */
2914 ha->ms_iocb = pci_alloc_consistent(ha->pdev,
2915 sizeof(ms_iocb_entry_t), &ha->ms_iocb_dma);
2916 if (ha->ms_iocb == NULL) {
2918 qla_printk(KERN_WARNING, ha,
2919 "Memory Allocation failed - ms_iocb\n");
2921 qla2x00_mem_free(ha);
2922 set_current_state(TASK_UNINTERRUPTIBLE);
2923 schedule_timeout(HZ/10);
2927 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2930 * Get consistent memory allocated for CT SNS
2933 ha->ct_sns = pci_alloc_consistent(ha->pdev,
2934 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma);
2935 if (ha->ct_sns == NULL) {
2937 qla_printk(KERN_WARNING, ha,
2938 "Memory Allocation failed - ct_sns\n");
2940 qla2x00_mem_free(ha);
2941 set_current_state(TASK_UNINTERRUPTIBLE);
2942 schedule_timeout(HZ/10);
2946 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2949 /* Get consistent memory allocated for Get Port Database cmd */
2950 ha->iodesc_pd = pci_alloc_consistent(ha->pdev,
2951 PORT_DATABASE_SIZE, &ha->iodesc_pd_dma);
2952 if (ha->iodesc_pd == NULL) {
2954 qla_printk(KERN_WARNING, ha,
2955 "Memory Allocation failed - iodesc_pd\n");
2957 qla2x00_mem_free(ha);
2958 set_current_state(TASK_UNINTERRUPTIBLE);
2959 schedule_timeout(HZ/10);
2963 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2965 /* Done all allocations without any error. */
2968 } while (retry-- && status != 0);
2972 "%s(): **** FAILED ****\n", __func__);
2980 * Frees all adapter allocated memory.
2983 * ha = adapter block pointer.
2986 qla2x00_mem_free(scsi_qla_host_t *ha)
2989 struct list_head *fcpl, *fcptemp;
2991 struct list_head *fcll, *fcltemp;
2993 unsigned long wtime;/* max wait time if mbx cmd is busy. */
2997 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
3001 /* Free the target queues */
3002 for (t = 0; t < MAX_TARGETS; t++) {
3003 qla2x00_tgt_free(ha, t);
3006 /* Make sure all other threads are stopped. */
3008 while (ha->dpc_wait && wtime) {
3009 set_current_state(TASK_INTERRUPTIBLE);
3010 wtime = schedule_timeout(wtime);
3013 /* free ioctl memory */
3014 qla2x00_free_ioctl_mem(ha);
3017 qla2x00_free_sp_pool(ha);
3019 if (ha->iodesc_pd) {
3020 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE,
3021 ha->iodesc_pd, ha->iodesc_pd_dma);
3025 pci_free_consistent(ha->pdev,
3026 sizeof(struct sns_cmd_pkt), ha->sns_cmd, ha->sns_cmd_dma);
3030 pci_free_consistent(ha->pdev,
3031 sizeof(struct ct_sns_pkt), ha->ct_sns, ha->ct_sns_dma);
3034 pci_free_consistent(ha->pdev,
3035 sizeof(ms_iocb_entry_t), ha->ms_iocb, ha->ms_iocb_dma);
3039 pci_free_consistent(ha->pdev,
3040 sizeof(init_cb_t), ha->init_cb, ha->init_cb_dma);
3043 if (ha->request_ring) {
3044 pci_free_consistent(ha->pdev,
3045 ((ha->request_q_length + 1) * (sizeof(request_t))),
3046 ha->request_ring, ha->request_dma);
3049 if (ha->response_ring) {
3050 pci_free_consistent(ha->pdev,
3051 ((ha->response_q_length + 1) * (sizeof(response_t))),
3052 ha->response_ring, ha->response_dma);
3055 ha->iodesc_pd = NULL;
3056 ha->iodesc_pd_dma = 0;
3061 ha->request_ring = NULL;
3062 ha->request_dma = 0;
3063 ha->response_ring = NULL;
3064 ha->response_dma = 0;
3066 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
3067 fcport = list_entry(fcpl, fc_port_t, list);
3070 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
3071 fclun = list_entry(fcll, fc_lun_t, list);
3073 list_del_init(&fclun->list);
3078 list_del_init(&fcport->list);
3081 INIT_LIST_HEAD(&ha->fcports);
3084 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
3088 if (ha->fw_dump_buffer) {
3089 vfree(ha->fw_dump_buffer);
3090 ha->fw_dump_reading = 0;
3091 ha->fw_dump_buffer = NULL;
3096 * qla2x00_allocate_sp_pool
3097 * This routine is called during initialization to allocate
3098 * memory for local srb_t.
3101 * ha = adapter block pointer.
3106 * Note: Sets the ref_count for non Null sp to one.
3109 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
3114 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3115 mempool_free_slab, srb_cachep);
3116 if (ha->srb_mempool == NULL) {
3117 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
3118 rval = QLA_FUNCTION_FAILED;
3124 * This routine frees all adapter allocated memory.
3128 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
3130 if (ha->srb_mempool) {
3131 mempool_destroy(ha->srb_mempool);
3132 ha->srb_mempool = NULL;
3136 /**************************************************************************
3138 * This kernel thread is a task that is schedule by the interrupt handler
3139 * to perform the background processing for interrupts.
3142 * This task always run in the context of a kernel thread. It
3143 * is kick-off by the driver's detect code and starts up
3144 * up one per adapter. It immediately goes to sleep and waits for
3145 * some fibre event. When either the interrupt handler or
3146 * the timer routine detects a event it will one of the task
3147 * bits then wake us up.
3148 **************************************************************************/
3150 qla2x00_do_dpc(void *data)
3152 DECLARE_MUTEX_LOCKED(sem);
3153 scsi_qla_host_t *ha;
3158 unsigned long flags = 0;
3159 struct list_head *list, *templist;
3160 int dead_cnt, online_cnt;
3162 uint16_t next_loopid;
3166 ha = (scsi_qla_host_t *)data;
3170 daemonize("%s_dpc", ha->host_str);
3171 allow_signal(SIGHUP);
3173 ha->dpc_wait = &sem;
3175 set_user_nice(current, -20);
3179 complete(&ha->dpc_inited);
3182 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3184 if (down_interruptible(&sem))
3187 if (ha->dpc_should_die)
3190 if (!list_empty(&ha->done_queue))
3193 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3195 /* Initialization not yet finished. Don't do anything yet. */
3196 if (!ha->flags.init_done || ha->dpc_active)
3199 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
3203 /* Process commands in retry queue */
3204 if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {
3205 DEBUG(printk("scsi(%ld): DPC checking retry_q. "
3207 ha->host_no, ha->retry_q_cnt));
3209 spin_lock_irqsave(&ha->list_lock, flags);
3210 dead_cnt = online_cnt = 0;
3211 list_for_each_safe(list, templist, &ha->retry_queue) {
3212 sp = list_entry(list, srb_t, list);
3214 DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "
3215 "spflags=0x%x, q_flag= 0x%lx\n",
3216 ha->host_no, sp->cmd->serial_number, sp,
3217 sp->flags, q->q_flag));
3221 fcport = q->fclun->fcport;
3223 if (atomic_read(&fcport->state) ==
3225 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3227 __del_from_retry_queue(ha, sp);
3228 sp->cmd->result = DID_NO_CONNECT << 16;
3229 if (atomic_read(&fcport->ha->loop_state) ==
3231 sp->err_id = SRB_ERR_LOOP;
3233 sp->err_id = SRB_ERR_PORT;
3234 sp->cmd->host_scribble =
3235 (unsigned char *) NULL;
3236 __add_to_done_queue(ha, sp);
3238 } else if (atomic_read(&fcport->state) !=
3241 __del_from_retry_queue(ha, sp);
3242 sp->cmd->result = DID_BUS_BUSY << 16;
3243 sp->cmd->host_scribble =
3244 (unsigned char *) NULL;
3245 __add_to_done_queue(ha, sp);
3248 } /* list_for_each_safe() */
3249 spin_unlock_irqrestore(&ha->list_lock, flags);
3251 DEBUG(printk("scsi(%ld): done processing retry queue "
3252 "- dead=%d, online=%d\n ",
3253 ha->host_no, dead_cnt, online_cnt));
3256 /* Process commands in scsi retry queue */
3257 if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {
3259 * Any requests we want to delay for some period is put
3260 * in the scsi retry queue with a delay added. The
3261 * timer will schedule a "scsi_restart_needed" every
3262 * second as long as there are requests in the scsi
3265 DEBUG(printk("scsi(%ld): DPC checking scsi "
3266 "retry_q.total=%d\n",
3267 ha->host_no, ha->scsi_retry_q_cnt));
3270 spin_lock_irqsave(&ha->list_lock, flags);
3271 list_for_each_safe(list, templist,
3272 &ha->scsi_retry_queue) {
3274 sp = list_entry(list, srb_t, list);
3278 DEBUG3(printk("scsi(%ld): scsi_retry_q: "
3279 "pid=%ld sp=%p, spflags=0x%x, "
3280 "q_flag= 0x%lx,q_state=%d\n",
3281 ha->host_no, sp->cmd->serial_number,
3282 sp, sp->flags, q->q_flag, q->q_state));
3284 /* Was this lun suspended */
3285 if (q->q_state != LUN_STATE_WAIT) {
3287 __del_from_scsi_retry_queue(ha, sp);
3289 if (test_bit(TQF_RETRY_CMDS,
3291 qla2x00_extend_timeout(sp->cmd,
3292 (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
3293 __add_to_pending_queue(ha, sp);
3296 __add_to_retry_queue(ha, sp);
3299 /* Was this command suspended for N secs */
3300 if (sp->delay != 0) {
3302 if (sp->delay == 0) {
3304 __del_from_scsi_retry_queue(
3306 __add_to_retry_queue(ha,sp);
3310 spin_unlock_irqrestore(&ha->list_lock, flags);
3312 /* Clear all Target Unsuspended bits */
3313 for (t = 0; t < ha->max_targets; t++) {
3314 if ((tq = ha->otgt[t]) == NULL)
3317 if (test_bit(TQF_RETRY_CMDS, &tq->flags))
3318 clear_bit(TQF_RETRY_CMDS, &tq->flags);
3323 DEBUG(if (online_cnt > 0))
3324 DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "
3326 ha->host_no, online_cnt));
3329 if (ha->flags.mbox_busy) {
3330 if (!list_empty(&ha->done_queue))
3337 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3339 DEBUG(printk("scsi(%ld): dpc: sched "
3340 "qla2x00_abort_isp ha = %p\n",
3342 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3345 if (qla2x00_abort_isp(ha)) {
3346 /* failed. retry later */
3347 set_bit(ISP_ABORT_NEEDED,
3350 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
3352 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3356 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
3357 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
3359 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3362 qla2x00_rst_aen(ha);
3363 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
3366 /* Retry each device up to login retry count */
3367 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3368 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
3369 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3371 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3375 list_for_each_entry(fcport, &ha->fcports, list) {
3376 if (fcport->port_type != FCT_TARGET)
3380 * If the port is not ONLINE then try to login
3381 * to it if we haven't run out of retries.
3383 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3384 fcport->login_retry) {
3386 fcport->login_retry--;
3387 if (fcport->flags & FCF_FABRIC_DEVICE) {
3390 qla2x00_fabric_logout(
3393 status = qla2x00_fabric_login(
3394 ha, fcport, &next_loopid);
3397 qla2x00_local_device_login(
3398 ha, fcport->loop_id);
3400 if (status == QLA_SUCCESS) {
3401 fcport->old_loop_id = fcport->loop_id;
3403 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
3404 ha->host_no, fcport->loop_id));
3406 fcport->port_login_retry_count =
3407 ha->port_down_retry_count * PORT_RETRY_TIME;
3408 atomic_set(&fcport->state, FCS_ONLINE);
3409 atomic_set(&fcport->port_down_timer,
3410 ha->port_down_retry_count * PORT_RETRY_TIME);
3412 fcport->login_retry = 0;
3413 } else if (status == 1) {
3414 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
3415 /* retry the login again */
3416 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
3418 fcport->login_retry, fcport->loop_id));
3420 fcport->login_retry = 0;
3423 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
3426 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3430 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
3431 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3433 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
3434 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
3437 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3439 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
3443 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
3445 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3448 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3451 qla2x00_loop_resync(ha);
3453 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3456 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3461 if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {
3462 DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",
3465 qla2x00_restart_queues(ha, 0);
3467 DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",
3471 if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {
3473 DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",
3476 qla2x00_abort_queues(ha, 0);
3478 DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",
3482 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
3484 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
3487 qla2x00_rescan_fcports(ha);
3489 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
3495 if (!ha->interrupts_on)
3496 qla2x00_enable_intrs(ha);
3498 if (!list_empty(&ha->done_queue))
3502 } /* End of while(1) */
3504 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
3507 * Make sure that nobody tries to wake us up again.
3509 ha->dpc_wait = NULL;
3512 complete_and_exit(&ha->dpc_exited, 0);
3516 * qla2x00_abort_queues
3517 * Abort all commands on queues on device
3520 * ha = adapter block pointer.
3523 * Interrupt context.
3526 qla2x00_abort_queues(scsi_qla_host_t *ha, uint8_t doneqflg)
3530 struct list_head *list, *temp;
3531 unsigned long flags;
3533 clear_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3535 /* Return all commands device queues. */
3536 spin_lock_irqsave(&ha->list_lock,flags);
3537 list_for_each_safe(list, temp, &ha->pending_queue) {
3538 sp = list_entry(list, srb_t, list);
3540 if (sp->flags & SRB_ABORTED)
3543 /* Remove srb from LUN queue. */
3544 __del_from_pending_queue(ha, sp);
3546 /* Set ending status. */
3547 sp->cmd->result = DID_BUS_BUSY << 16;
3549 __add_to_done_queue(ha, sp);
3551 spin_unlock_irqrestore(&ha->list_lock, flags);
3556 * Processes asynchronous reset.
3559 * ha = adapter block pointer.
3562 qla2x00_rst_aen(scsi_qla_host_t *ha)
3564 if (ha->flags.online && !ha->flags.reset_active &&
3565 !atomic_read(&ha->loop_down_timer) &&
3566 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
3568 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3571 * Issue marker command only when we are going to start
3574 ha->marker_needed = 1;
3575 } while (!atomic_read(&ha->loop_down_timer) &&
3576 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
3582 * This routine will allocate SP from the free queue
3589 qla2x00_get_new_sp(scsi_qla_host_t *ha)
3593 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3595 atomic_set(&sp->ref_count, 1);
3599 /**************************************************************************
3605 * Context: Interrupt
3606 ***************************************************************************/
3608 qla2x00_timer(scsi_qla_host_t *ha)
3611 unsigned long cpu_flags = 0;
3620 * We try and restart any request in the retry queue every second.
3622 if (!list_empty(&ha->retry_queue)) {
3623 set_bit(PORT_RESTART_NEEDED, &ha->dpc_flags);
3628 * We try and restart any request in the scsi_retry queue every second.
3630 if (!list_empty(&ha->scsi_retry_queue)) {
3631 set_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags);
3636 * Ports - Port down timer.
3638 * Whenever, a port is in the LOST state we start decrementing its port
3639 * down timer every second until it reaches zero. Once it reaches zero
3640 * the port it marked DEAD.
3643 list_for_each_entry(fcport, &ha->fcports, list) {
3644 if (fcport->port_type != FCT_TARGET)
3647 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3649 if (atomic_read(&fcport->port_down_timer) == 0)
3652 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3653 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3655 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3658 t, atomic_read(&fcport->port_down_timer)));
3661 } /* End of for fcport */
3664 * LUNS - lun suspend timer.
3666 * Whenever, a lun is suspended the timer starts decrementing its
3667 * suspend timer every second until it reaches zero. Once it reaches
3668 * zero the lun retry count is decremented.
3672 * FIXME(dg) - Need to convert this linear search of luns into a search
3673 * of a list of suspended luns.
3675 for (t = 0; t < ha->max_targets; t++) {
3676 if ((tq = ha->otgt[t]) == NULL)
3679 for (l = 0; l < ha->max_luns; l++) {
3680 if ((lq = (os_lun_t *) tq->olun[l]) == NULL)
3683 spin_lock_irqsave(&lq->q_lock, cpu_flags);
3684 if (lq->q_state == LUN_STATE_WAIT &&
3685 atomic_read(&lq->q_timer) != 0) {
3687 if (atomic_dec_and_test(&lq->q_timer) != 0) {
3689 * A delay should immediately
3690 * transition to a READY state
3692 if (test_and_clear_bit(LUN_EXEC_DELAYED,
3694 lq->q_state = LUN_STATE_READY;
3698 if (lq->q_count == lq->q_max)
3706 DEBUG3(printk("scsi(%ld): lun%d - timer %d, "
3707 "count=%d, max=%d, state=%d\n",
3710 atomic_read(&lq->q_timer),
3711 lq->q_count, lq->q_max, lq->q_state));
3713 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
3714 } /* End of for luns */
3715 } /* End of for targets */
3717 /* Loop down handler. */
3718 if (atomic_read(&ha->loop_down_timer) > 0 &&
3719 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
3721 if (atomic_read(&ha->loop_down_timer) ==
3722 ha->loop_down_abort_time) {
3724 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3725 "queues before time expire\n",
3728 if (!IS_QLA2100(ha) && ha->link_down_timeout)
3729 atomic_set(&ha->loop_state, LOOP_DEAD);
3731 /* Schedule an ISP abort to return any tape commands. */
3732 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3733 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
3735 sp = ha->outstanding_cmds[index];
3738 if (!(sp->fclun->fcport->flags &
3742 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3745 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3747 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3751 /* if the loop has been down for 4 minutes, reinit adapter */
3752 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
3753 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
3754 "restarting queues.\n",
3757 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3760 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3761 DEBUG(printk("scsi(%ld): Loop down - "
3764 qla_printk(KERN_WARNING, ha,
3765 "Loop down - aborting ISP.\n");
3767 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3770 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
3772 atomic_read(&ha->loop_down_timer)));
3776 * Done Q Handler -- dgFIXME This handler will kick off doneq if we
3777 * haven't process it in 2 seconds.
3779 if (!list_empty(&ha->done_queue))
3783 /* Schedule the DPC routine if needed */
3784 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
3785 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
3787 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
3788 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3789 ha->dpc_wait && !ha->dpc_active) {
3794 qla2x00_restart_timer(ha, WATCH_INTERVAL);
3798 * qla2x00_extend_timeout
3799 * This routine will extend the timeout to the specified value.
3802 * cmd = SCSI command structure
3808 qla2x00_extend_timeout(struct scsi_cmnd *cmd, int timeout)
3810 srb_t *sp = (srb_t *) CMD_SP(cmd);
3811 u_long our_jiffies = (timeout * HZ) + jiffies;
3814 sp->e_start = jiffies;
3815 if (cmd->eh_timeout.function) {
3816 mod_timer(&cmd->eh_timeout,our_jiffies);
3817 sp->ext_history |= 1;
3819 if (sp->timer.function != NULL) {
3821 * Our internal timer should timeout before the midlayer has a
3822 * chance begin the abort process
3824 mod_timer(&sp->timer,our_jiffies - (QLA_CMD_TIMER_DELTA * HZ));
3826 sp->ext_history |= 2;
3830 /**************************************************************************
3831 * qla2x00_cmd_timeout
3834 * Handles the command if it times out in any state.
3837 * sp - pointer to validate
3841 * Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).
3842 **************************************************************************/
3844 qla2x00_cmd_timeout(srb_t *sp)
3848 scsi_qla_host_t *vis_ha, *dest_ha;
3849 struct scsi_cmnd *cmd;
3850 unsigned long flags, cpu_flags;
3854 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
3856 DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state));
3858 t = cmd->device->id;
3859 l = cmd->device->lun;
3860 fcport = sp->fclun->fcport;
3864 * If IO is found either in retry Queue
3866 * Return this IO back to host
3868 spin_lock_irqsave(&vis_ha->list_lock, flags);
3870 if (sp->state == SRB_PENDING_STATE) {
3871 __del_from_pending_queue(vis_ha, sp);
3872 DEBUG2(printk("scsi(%ld): Found in Pending queue pid %ld, "
3873 "State = %x., fcport state=%d jiffies=%lx\n",
3874 vis_ha->host_no, cmd->serial_number, sp->state,
3875 atomic_read(&fcport->state), jiffies));
3878 * If FC_DEVICE is marked as dead return the cmd with
3879 * DID_NO_CONNECT status. Otherwise set the host_byte to
3880 * DID_BUS_BUSY to let the OS retry this cmd.
3882 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
3883 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3884 cmd->result = DID_NO_CONNECT << 16;
3885 if (atomic_read(&fcport->ha->loop_state) == LOOP_DOWN)
3886 sp->err_id = SRB_ERR_LOOP;
3888 sp->err_id = SRB_ERR_PORT;
3890 cmd->result = DID_BUS_BUSY << 16;
3892 __add_to_done_queue(vis_ha, sp);
3895 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
3898 qla2x00_done(vis_ha);
3902 spin_lock_irqsave(&dest_ha->list_lock, flags);
3903 if ((sp->state == SRB_RETRY_STATE) ||
3904 (sp->state == SRB_SCSI_RETRY_STATE)) {
3906 DEBUG2(printk("scsi(%ld): Found in (Scsi) Retry queue or "
3907 "failover Q pid %ld, State = %x., fcport state=%d "
3908 "jiffies=%lx retried=%d\n",
3909 dest_ha->host_no, cmd->serial_number, sp->state,
3910 atomic_read(&fcport->state), jiffies, cmd->retries));
3912 if ((sp->state == SRB_RETRY_STATE)) {
3913 __del_from_retry_queue(dest_ha, sp);
3914 } else if ((sp->state == SRB_SCSI_RETRY_STATE)) {
3915 __del_from_scsi_retry_queue(dest_ha, sp);
3919 * If FC_DEVICE is marked as dead return the cmd with
3920 * DID_NO_CONNECT status. Otherwise set the host_byte to
3921 * DID_BUS_BUSY to let the OS retry this cmd.
3923 if ((atomic_read(&fcport->state) == FCS_DEVICE_DEAD) ||
3924 atomic_read(&dest_ha->loop_state) == LOOP_DEAD) {
3925 qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT);
3926 cmd->result = DID_NO_CONNECT << 16;
3927 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
3928 sp->err_id = SRB_ERR_LOOP;
3930 sp->err_id = SRB_ERR_PORT;
3932 cmd->result = DID_BUS_BUSY << 16;
3935 __add_to_done_queue(dest_ha, sp);
3938 spin_unlock_irqrestore(&dest_ha->list_lock, flags);
3941 qla2x00_done(dest_ha);
3946 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
3947 if (sp->state == SRB_DONE_STATE) {
3948 /* IO in done_q -- leave it */
3949 DEBUG(printk("scsi(%ld): Found in Done queue pid %ld sp=%p.\n",
3950 dest_ha->host_no, cmd->serial_number, sp));
3951 } else if (sp->state == SRB_SUSPENDED_STATE) {
3952 DEBUG(printk("scsi(%ld): Found SP %p in suspended state "
3954 dest_ha->host_no, sp, cmd->serial_number));
3955 DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));)
3956 } else if (sp->state == SRB_ACTIVE_STATE) {
3958 * IO is with ISP find the command in our active list.
3960 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
3961 spin_lock_irqsave(&dest_ha->hardware_lock, flags);
3962 if (sp == dest_ha->outstanding_cmds[
3963 (unsigned long)sp->cmd->host_scribble]) {
3965 DEBUG(printk("cmd_timeout: Found in ISP \n"));
3967 if (sp->flags & SRB_TAPE) {
3969 * We cannot allow the midlayer error handler
3970 * to wakeup and begin the abort process.
3971 * Extend the timer so that the firmware can
3972 * properly return the IOCB.
3974 DEBUG(printk("cmd_timeout: Extending timeout "
3975 "of FCP2 tape command!\n"));
3976 qla2x00_extend_timeout(sp->cmd,
3977 EXTEND_CMD_TIMEOUT);
3979 sp->state = SRB_ACTIVE_TIMEOUT_STATE;
3980 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
3982 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
3984 "qla_cmd_timeout: State indicates it is with "
3985 "ISP, But not in active array\n");
3987 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
3988 } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) {
3989 DEBUG(printk("qla2100%ld: Found in Active timeout state"
3990 "pid %ld, State = %x., \n",
3992 sp->cmd->serial_number, sp->state);)
3995 DEBUG2(printk("cmd_timeout%ld: LOST command state = "
3997 vis_ha->host_no, sp->state,sp);)
3999 qla_printk(KERN_INFO, vis_ha,
4000 "cmd_timeout: LOST command state = 0x%x\n", sp->state);
4002 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4004 DEBUG3(printk("cmd_timeout: Leaving\n");)
4007 /**************************************************************************
4009 * Process completed commands.
4012 * old_ha = adapter block pointer.
4014 **************************************************************************/
4016 qla2x00_done(scsi_qla_host_t *old_ha)
4019 struct scsi_cmnd *cmd;
4020 unsigned long flags = 0;
4021 scsi_qla_host_t *ha;
4022 scsi_qla_host_t *vis_ha;
4023 int send_marker_once = 0;
4025 LIST_HEAD(local_sp_list);
4028 * Get into local queue such that we do not wind up calling done queue
4029 * tasklet for the same IOs from DPC or any other place.
4031 spin_lock_irqsave(&old_ha->list_lock, flags);
4032 list_splice_init(&old_ha->done_queue, &local_sp_list);
4033 spin_unlock_irqrestore(&old_ha->list_lock, flags);
4036 * All done commands are in the local queue, now do the call back.
4038 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4039 old_ha->done_q_cnt--;
4040 sp->state = SRB_NO_QUEUE_STATE;
4042 /* remove command from local list */
4043 list_del_init(&sp->list);
4049 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
4053 if (sp->flags & SRB_DMA_VALID) {
4054 sp->flags &= ~SRB_DMA_VALID;
4056 /* Release memory used for this I/O */
4058 pci_unmap_sg(ha->pdev, cmd->request_buffer,
4059 cmd->use_sg, cmd->sc_data_direction);
4060 } else if (cmd->request_bufflen) {
4061 pci_unmap_page(ha->pdev, sp->dma_handle,
4062 cmd->request_bufflen,
4063 cmd->sc_data_direction);
4068 switch (host_byte(cmd->result)) {
4075 * Set marker needed, so we don't have to
4076 * send multiple markers
4078 if (!send_marker_once) {
4079 ha->marker_needed = 1;
4086 * A backdoor device-reset requires different
4087 * error handling. This code differentiates
4088 * between normal error handling and the
4092 if (ha->host->eh_active != EH_ACTIVE)
4093 cmd->result = DID_BUS_BUSY << 16;
4098 sp->flags &= ~SRB_ABORT_PENDING;
4099 sp->flags |= SRB_ABORTED;
4101 if (sp->flags & SRB_TIMEOUT)
4102 cmd->result = DID_TIME_OUT << 16;
4107 DEBUG2(printk("scsi(%ld:%d:%d) %s: did_error "
4108 "= %d, comp-scsi= 0x%x-0x%x.\n",
4110 cmd->device->id, cmd->device->lun,
4112 host_byte(cmd->result),
4113 CMD_COMPL_STATUS(cmd),
4114 CMD_SCSI_STATUS(cmd)));
4119 * Call the mid-level driver interrupt handler -- via sp_put()
4122 } /* end of while */
4126 * qla2x00_process_response_queue_in_zio_mode
4127 * Process response queue completion as fast as possible
4128 * to achieve Zero Interrupt Opertions-ZIO
4131 * ha = adapter block pointer.
4137 qla2x00_process_response_queue_in_zio_mode(scsi_qla_host_t *ha)
4139 unsigned long flags;
4141 /* Check for unprocessed commands in response queue. */
4142 if (!ha->flags.process_response_queue)
4144 if (!ha->flags.online)
4146 if (ha->response_ring_ptr->signature == RESPONSE_PROCESSED)
4149 spin_lock_irqsave(&ha->hardware_lock,flags);
4150 qla2x00_process_response_queue(ha);
4151 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4156 * Retrieve and process next job in the LUN queue.
4159 * tq = SCSI target queue pointer.
4160 * lq = SCSI LUN queue pointer.
4161 * TGT_LOCK must be already obtained.
4164 * Releases TGT_LOCK upon exit.
4167 * Kernel/Interrupt context.
4169 * Note: This routine will always try to start I/O from visible HBA.
4172 qla2x00_next(scsi_qla_host_t *vis_ha)
4175 unsigned long flags;
4176 scsi_qla_host_t *dest_ha;
4179 LIST_HEAD(local_sp_list);
4183 spin_lock_irqsave(&vis_ha->list_lock, flags);
4184 list_splice_init(&vis_ha->pending_queue, &local_sp_list);
4185 vis_ha->qthreads = 0;
4186 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
4188 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4189 list_del_init(&sp->list);
4190 sp->state = SRB_NO_QUEUE_STATE;
4192 fcport = sp->fclun->fcport;
4193 dest_ha = fcport->ha;
4195 /* If device is dead then send request back to OS */
4196 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
4197 sp->cmd->result = DID_NO_CONNECT << 16;
4198 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
4199 sp->err_id = SRB_ERR_LOOP;
4201 sp->err_id = SRB_ERR_PORT;
4203 DEBUG3(printk("scsi(%ld): loop/port is down - pid=%ld, "
4204 "sp=%p err_id=%d loopid=0x%x queued to dest HBA "
4205 "scsi%ld.\n", dest_ha->host_no,
4206 sp->cmd->serial_number, sp, sp->err_id,
4207 fcport->loop_id, dest_ha->host_no));
4209 * Initiate a failover - done routine will initiate.
4211 add_to_done_queue(vis_ha, sp);
4217 * SCSI Kluge: Whenever, we need to wait for an event such as
4218 * loop down (i.e. loop_down_timer ) or port down (i.e. LUN
4219 * request qeueue is suspended) then we will recycle new
4220 * commands back to the SCSI layer. We do this because this is
4221 * normally a temporary condition and we don't want the
4222 * mid-level scsi.c driver to get upset and start aborting
4223 * commands. The timeout value is extracted from the command
4224 * minus 1-second and put on a retry queue (watchdog). Once the
4225 * command timeout it is returned to the mid-level with a BUSY
4226 * status, so the mid-level will retry it. This process
4227 * continues until the LOOP DOWN time expires or the condition
4230 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4231 (atomic_read(&fcport->state) != FCS_ONLINE ||
4232 test_bit(ABORT_ISP_ACTIVE, &dest_ha->dpc_flags) ||
4233 atomic_read(&dest_ha->loop_state) != LOOP_READY)) {
4235 DEBUG3(printk("scsi(%ld): port=(0x%x) retry_q(%d) "
4236 "loop state = %d, loop counter = 0x%x dpc flags "
4240 atomic_read(&fcport->state),
4241 atomic_read(&dest_ha->loop_state),
4242 atomic_read(&dest_ha->loop_down_timer),
4243 dest_ha->dpc_flags));
4245 qla2x00_extend_timeout(sp->cmd, EXTEND_CMD_TIMEOUT);
4246 add_to_retry_queue(vis_ha, sp);
4252 * If this request's lun is suspended then put the request on
4253 * the scsi_retry queue.
4255 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4256 sp->lun_queue->q_state == LUN_STATE_WAIT) {
4257 DEBUG3(printk("scsi(%ld): lun wait state - pid=%ld, "
4258 "opcode=%d, allowed=%d, retries=%d\n",
4260 sp->cmd->serial_number,
4265 add_to_scsi_retry_queue(vis_ha, sp);
4270 sp->lun_queue->io_cnt++;
4272 rval = qla2x00_start_scsi(sp);
4273 if (rval != QLA_SUCCESS) {
4274 /* Place request back on top of device queue */
4275 /* add to the top of queue */
4276 add_to_pending_queue_head(vis_ha, sp);
4278 sp->lun_queue->io_cnt--;
4282 if (!IS_QLA2100(vis_ha) && !IS_QLA2200(vis_ha)) {
4283 /* Process response_queue if ZIO support is enabled*/
4284 qla2x00_process_response_queue_in_zio_mode(vis_ha);
4290 /**************************************************************************
4291 * qla2x00_check_tgt_status
4294 * Checks to see if the target or loop is down.
4297 * cmd - pointer to Scsi cmd structure
4300 * 1 - if target is present
4301 * 0 - if target is not present
4303 **************************************************************************/
4305 qla2x00_check_tgt_status(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
4308 unsigned int b, t, l;
4311 /* Generate LU queue on bus, target, LUN */
4312 b = cmd->device->channel;
4313 t = cmd->device->id;
4314 l = cmd->device->lun;
4316 if ((lq = GET_LU_Q(ha,t,l)) == NULL) {
4317 return (QLA_FUNCTION_FAILED);
4320 fcport = lq->fclun->fcport;
4322 if (TGT_Q(ha, t) == NULL ||
4323 l >= ha->max_luns ||
4324 atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4325 atomic_read(&ha->loop_state) == LOOP_DEAD ||
4326 (!atomic_read(&ha->loop_down_timer) &&
4327 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4328 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
4329 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4330 atomic_read(&ha->loop_state) != LOOP_READY) {
4332 DEBUG(printk(KERN_INFO
4333 "scsi(%ld:%2d:%2d:%2d): %s connection is down\n",
4338 cmd->result = DID_NO_CONNECT << 16;
4339 return (QLA_FUNCTION_FAILED);
4341 return (QLA_SUCCESS);
4344 /**************************************************************************
4345 * qla2x00_check_port_status
4348 * Checks to see if the port or loop is down.
4351 * fcport - pointer to fc_port_t structure.
4354 * 1 - if port is present
4355 * 0 - if port is not present
4357 **************************************************************************/
4359 qla2x00_check_port_status(scsi_qla_host_t *ha, fc_port_t *fcport)
4361 if (fcport == NULL) {
4362 return (QLA_FUNCTION_FAILED);
4365 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4366 atomic_read(&ha->loop_state) == LOOP_DEAD) {
4367 return (QLA_FUNCTION_FAILED);
4370 if ((atomic_read(&fcport->state) != FCS_ONLINE) ||
4371 (!atomic_read(&ha->loop_down_timer) &&
4372 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4373 (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) ||
4374 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
4375 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4376 atomic_read(&ha->loop_state) != LOOP_READY) {
4378 DEBUG(printk(KERN_INFO
4379 "scsi(%ld): Connection is down. fcport=%p.\n",
4380 ha->host_no, fcport));
4385 return (QLA_SUCCESS);
4388 /* XXX(hch): crude hack to emulate a down_timeout() */
4390 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
4392 const unsigned int step = HZ/10;
4395 if (!down_trylock(sema))
4397 set_current_state(TASK_INTERRUPTIBLE);
4398 if (schedule_timeout(step))
4400 } while ((timeout -= step) > 0);
4406 qla2xxx_get_port_id(struct scsi_device *sdev)
4408 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4411 list_for_each_entry(fc, &ha->fcports, list) {
4412 if (fc->os_target_id == sdev->id) {
4413 fc_port_id(sdev) = fc->d_id.b.domain << 16 |
4414 fc->d_id.b.area << 8 |
4419 fc_port_id(sdev) = -1;
4423 qla2xxx_get_port_name(struct scsi_device *sdev)
4425 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4428 list_for_each_entry(fc, &ha->fcports, list) {
4429 if (fc->os_target_id == sdev->id) {
4430 fc_port_name(sdev) =
4431 __be64_to_cpu(*(uint64_t *)fc->port_name);
4435 fc_port_name(sdev) = -1;
4439 qla2xxx_get_node_name(struct scsi_device *sdev)
4441 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4444 list_for_each_entry(fc, &ha->fcports, list) {
4445 if (fc->os_target_id == sdev->id) {
4446 fc_node_name(sdev) =
4447 __be64_to_cpu(*(uint64_t *)fc->node_name);
4451 fc_node_name(sdev) = -1;
4454 static struct fc_function_template qla2xxx_transport_functions = {
4455 .get_port_id = qla2xxx_get_port_id,
4457 .get_port_name = qla2xxx_get_port_name,
4458 .show_port_name = 1,
4459 .get_node_name = qla2xxx_get_node_name,
4460 .show_node_name = 1,
4464 * qla2x00_module_init - Module initialization.
4467 qla2x00_module_init(void)
4469 /* Allocate cache for SRBs. */
4470 sprintf(srb_cachep_name, "qla2xxx_srbs");
4471 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
4472 SLAB_HWCACHE_ALIGN, NULL, NULL);
4473 if (srb_cachep == NULL) {
4475 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4479 /* Derive version string. */
4480 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4482 strcat(qla2x00_version_str, "-debug");
4485 qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions);
4486 if (!qla2xxx_transport_template)
4490 "QLogic Fibre Channel HBA Driver (%p)\n", qla2x00_set_info);
4496 * qla2x00_module_exit - Module cleanup.
4499 qla2x00_module_exit(void)
4501 /* Free SRBs cache. */
4502 if (srb_cachep != NULL) {
4503 if (kmem_cache_destroy(srb_cachep) != 0) {
4505 "qla2xxx: Unable to free SRB cache...Memory pools "
4511 fc_release_transport(qla2xxx_transport_template);
4514 module_init(qla2x00_module_init);
4515 module_exit(qla2x00_module_exit);
4517 MODULE_AUTHOR("QLogic Corporation");
4518 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4519 MODULE_LICENSE("GPL");
4520 MODULE_VERSION(QLA2XXX_VERSION);