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.
26 char qla2x00_version_str[40];
29 * SRB allocation cache
31 char srb_cachep_name[16];
32 kmem_cache_t *srb_cachep;
35 * Stats for all adpaters.
37 struct _qla2x00stats qla2x00_stats;
40 * Ioctl related information.
46 * Module parameter information and variables
49 module_param(ql2xmaxqdepth, int, 0);
50 MODULE_PARM_DESC(ql2xmaxqdepth,
51 "Maximum queue depth to report for target devices.");
53 int ql2xlogintimeout = 20;
54 module_param(ql2xlogintimeout, int, 0);
55 MODULE_PARM_DESC(ql2xlogintimeout,
56 "Login timeout value in seconds.");
58 int qlport_down_retry;
59 module_param(qlport_down_retry, int, 0);
60 MODULE_PARM_DESC(qlport_down_retry,
61 "Maximum number of command retries to a port that returns"
62 "a PORT-DOWN status.");
64 int ql2xretrycount = 20;
65 module_param(ql2xretrycount, int, 0);
66 MODULE_PARM_DESC(ql2xretrycount,
67 "Maximum number of mid-layer retries allowed for a command. "
68 "Default value is 20, ");
71 module_param(displayConfig, int, 0);
72 MODULE_PARM_DESC(displayConfig,
73 "If 1 then display the configuration used in /etc/modprobe.conf.");
75 int ql2xplogiabsentdevice;
76 module_param(ql2xplogiabsentdevice, int, 0);
77 MODULE_PARM_DESC(ql2xplogiabsentdevice,
78 "Option to enable PLOGI to devices that are not present after "
79 "a Fabric scan. This is needed for several broken switches."
80 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
82 int ql2xintrdelaytimer = 10;
83 module_param(ql2xintrdelaytimer, int, 0);
84 MODULE_PARM_DESC(ql2xintrdelaytimer,
85 "ZIO: Waiting time for Firmware before it generates an "
86 "interrupt to the host to notify completion of request.");
89 module_param(ConfigRequired, int, 0);
90 MODULE_PARM_DESC(ConfigRequired,
91 "If 1, then only configured devices passed in through the"
92 "ql2xopts parameter will be presented to the OS");
94 int Bind = BIND_BY_PORT_NAME;
95 module_param(Bind, int, 0);
96 MODULE_PARM_DESC(Bind,
97 "Target persistent binding method: "
98 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
100 int ql2xsuspendcount = SUSPEND_COUNT;
101 module_param(ql2xsuspendcount, int, 0);
102 MODULE_PARM_DESC(ql2xsuspendcount,
103 "Number of 6-second suspend iterations to perform while a "
104 "target returns a <NOT READY> status. Default is 10 "
107 int ql2xdoinitscan = 1;
108 module_param(ql2xdoinitscan, int, 0);
109 MODULE_PARM_DESC(ql2xdoinitscan,
110 "Signal mid-layer to perform scan after driver load: 0 -- no "
111 "signal sent to mid-layer.");
113 int ql2xloginretrycount = 0;
114 module_param(ql2xloginretrycount, int, 0);
115 MODULE_PARM_DESC(ql2xloginretrycount,
116 "Specify an alternate value for the NVRAM login retry count.");
119 * Proc structures and functions
128 static void copy_mem_info(struct info_str *, char *, int);
129 static int copy_info(struct info_str *, char *, ...);
133 * List of host adapters
135 LIST_HEAD(qla_hostlist);
136 rwlock_t qla_hostlist_lock = RW_LOCK_UNLOCKED;
138 static void qla2x00_free_device(scsi_qla_host_t *);
140 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
143 * SCSI host template entry points
145 static int qla2xxx_slave_configure(struct scsi_device * device);
146 static int qla2xxx_eh_abort(struct scsi_cmnd *);
147 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
148 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
149 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
150 static uint8_t qla2x00_loop_reset(scsi_qla_host_t *ha);
151 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
153 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
156 static struct scsi_host_template qla2x00_driver_template = {
157 .module = THIS_MODULE,
159 .proc_name = "qla2xxx",
160 .proc_info = qla2x00_proc_info,
161 .queuecommand = qla2x00_queuecommand,
163 .eh_abort_handler = qla2xxx_eh_abort,
164 .eh_device_reset_handler = qla2xxx_eh_device_reset,
165 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
166 .eh_host_reset_handler = qla2xxx_eh_host_reset,
168 .slave_configure = qla2xxx_slave_configure,
172 .use_clustering = ENABLE_CLUSTERING,
173 .sg_tablesize = SG_ALL,
176 * The RISC allows for each command to transfer (2^32-1) bytes of data,
177 * which equates to 0x800000 sectors.
179 .max_sectors = 0xFFFF,
182 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
184 static void qla2x00_display_fc_names(scsi_qla_host_t *);
186 void qla2x00_blink_led(scsi_qla_host_t *);
188 /* TODO Convert to inlines
192 #define WATCH_INTERVAL 1 /* number of seconds */
194 static void qla2x00_timer(scsi_qla_host_t *);
196 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
197 void *, unsigned long);
198 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
199 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
202 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
204 init_timer(&ha->timer);
205 ha->timer.expires = jiffies + interval * HZ;
206 ha->timer.data = (unsigned long)ha;
207 ha->timer.function = (void (*)(unsigned long))func;
208 add_timer(&ha->timer);
209 ha->timer_active = 1;
213 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
215 mod_timer(&ha->timer, jiffies + interval * HZ);
218 static __inline__ void
219 qla2x00_stop_timer(scsi_qla_host_t *ha)
221 del_timer_sync(&ha->timer);
222 ha->timer_active = 0;
225 void qla2x00_cmd_timeout(srb_t *);
227 static __inline__ void qla2x00_callback(scsi_qla_host_t *, struct scsi_cmnd *);
228 static __inline__ void sp_put(struct scsi_qla_host * ha, srb_t *sp);
229 static __inline__ void sp_get(struct scsi_qla_host * ha, srb_t *sp);
230 static __inline__ void
231 qla2x00_delete_from_done_queue(scsi_qla_host_t *, srb_t *);
233 /**************************************************************************
237 * Decrement reference count and call the callback if we're the last
238 * owner of the specified sp. Will get the host_lock before calling
242 * ha - pointer to the scsi_qla_host_t where the callback is to occur.
243 * sp - pointer to srb_t structure to use.
247 **************************************************************************/
249 sp_put(struct scsi_qla_host * ha, srb_t *sp)
251 if (atomic_read(&sp->ref_count) == 0) {
252 qla_printk(KERN_INFO, ha,
253 "%s(): **** SP->ref_count not zero\n",
260 if (!atomic_dec_and_test(&sp->ref_count)) {
264 qla2x00_callback(ha, sp->cmd);
267 /**************************************************************************
271 * Increment reference count of the specified sp.
274 * sp - pointer to srb_t structure to use.
278 **************************************************************************/
280 sp_get(struct scsi_qla_host * ha, srb_t *sp)
282 atomic_inc(&sp->ref_count);
284 if (atomic_read(&sp->ref_count) > 2) {
285 qla_printk(KERN_INFO, ha,
286 "%s(): **** SP->ref_count greater than two\n",
296 * Returns the completed SCSI command to LINUX.
299 * ha -- Host adapter structure
300 * cmd -- SCSI mid-level command structure.
303 * Note:From failover point of view we always get the sp
304 * from vis_ha pool in queuecommand.So when we put it
305 * back to the pool it has to be the vis_ha.
306 * So rely on struct scsi_cmnd to get the vis_ha and not on sp.
309 qla2x00_callback(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
311 srb_t *sp = (srb_t *) CMD_SP(cmd);
312 scsi_qla_host_t *vis_ha;
315 unsigned long cpu_flags = 0;
317 cmd->host_scribble = (unsigned char *) NULL;
318 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
321 qla_printk(KERN_INFO, ha,
322 "%s(): **** CMD derives a NULL SP\n",
329 * If command status is not DID_BUS_BUSY then go ahead and freed sp.
332 * Cancel command timeout
334 qla2x00_delete_timer_from_cmd(sp);
337 * Put SP back in the free queue
342 got_sense = (sp->flags & SRB_GOT_SENSE)? 1: 0;
343 add_to_free_queue(vis_ha, sp);
345 if (host_byte(cmd->result) == DID_OK) {
347 ha->total_bytes += cmd->bufflen;
349 /* If lun was suspended then clear retry count */
350 spin_lock_irqsave(&lq->q_lock, cpu_flags);
351 if (!test_bit(LUN_EXEC_DELAYED, &lq->q_flag))
352 lq->q_state = LUN_STATE_READY;
353 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
355 } else if (host_byte(cmd->result) == DID_ERROR) {
357 ha->total_dev_errs++;
360 /* Call the mid-level driver interrupt handler */
361 (*(cmd)->scsi_done)(cmd);
365 qla2x00_delete_from_done_queue(scsi_qla_host_t *dest_ha, srb_t *sp)
367 /* remove command from done list */
368 list_del_init(&sp->list);
369 dest_ha->done_q_cnt--;
370 sp->state = SRB_NO_QUEUE_STATE;
372 if (sp->flags & SRB_DMA_VALID) {
373 sp->flags &= ~SRB_DMA_VALID;
375 /* Release memory used for this I/O */
376 if (sp->cmd->use_sg) {
377 pci_unmap_sg(dest_ha->pdev, sp->cmd->request_buffer,
378 sp->cmd->use_sg, sp->cmd->sc_data_direction);
379 } else if (sp->cmd->request_bufflen) {
380 pci_unmap_page(dest_ha->pdev, sp->dma_handle,
381 sp->cmd->request_bufflen,
382 sp->cmd->sc_data_direction);
387 static int qla2x00_do_dpc(void *data);
389 static void qla2x00_rst_aen(scsi_qla_host_t *);
391 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
392 static void qla2x00_mem_free(scsi_qla_host_t *ha);
393 int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
394 void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
396 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
398 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
400 static struct bin_attribute sysfs_fw_dump_attr = {
403 .mode = S_IRUSR | S_IWUSR,
404 .owner = THIS_MODULE,
407 .read = qla2x00_sysfs_read_fw_dump,
408 .write = qla2x00_sysfs_write_fw_dump,
410 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
412 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
414 static struct bin_attribute sysfs_nvram_attr = {
417 .mode = S_IRUSR | S_IWUSR,
418 .owner = THIS_MODULE,
420 .size = sizeof(nvram_t),
421 .read = qla2x00_sysfs_read_nvram,
422 .write = qla2x00_sysfs_write_nvram,
427 qla2x00_set_info(char *buffer, int length, struct Scsi_Host *shost)
429 return (-ENOSYS); /* Currently this is a no-op */
432 /* -------------------------------------------------------------------------- */
435 /* SysFS attributes. */
436 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
437 loff_t off, size_t count)
439 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
440 struct device, kobj)));
442 if (ha->fw_dump_reading == 0)
444 if (off > ha->fw_dump_buffer_len)
446 if (off + count > ha->fw_dump_buffer_len)
447 count = ha->fw_dump_buffer_len - off;
449 memcpy(buf, &ha->fw_dump_buffer[off], count);
454 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
455 loff_t off, size_t count)
457 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
458 struct device, kobj)));
464 reading = simple_strtol(buf, NULL, 10);
467 if (ha->fw_dump_reading == 1) {
468 qla_printk(KERN_INFO, ha,
469 "Firmware dump cleared on (%ld).\n",
472 vfree(ha->fw_dump_buffer);
473 free_pages((unsigned long)ha->fw_dump,
476 ha->fw_dump_reading = 0;
477 ha->fw_dump_buffer = NULL;
482 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
483 ha->fw_dump_reading = 1;
485 ha->fw_dump_buffer = (char *)vmalloc(FW_DUMP_SIZE);
486 if (ha->fw_dump_buffer == NULL) {
487 qla_printk(KERN_WARNING, ha,
488 "Unable to allocate memory for firmware "
489 "dump buffer (%d).\n", FW_DUMP_SIZE);
491 ha->fw_dump_reading = 0;
494 qla_printk(KERN_INFO, ha,
495 "Firmware dump ready for read on (%ld).\n",
497 memset(ha->fw_dump_buffer, 0, FW_DUMP_SIZE);
498 if (IS_QLA2100(ha) || IS_QLA2200(ha))
499 qla2100_ascii_fw_dump(ha);
501 qla2300_ascii_fw_dump(ha);
502 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
509 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
510 loff_t off, size_t count)
512 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
513 struct device, kobj)));
518 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
522 spin_lock_irqsave(&ha->hardware_lock, flags);
523 qla2x00_lock_nvram_access(ha);
524 witer = (uint16_t *)buf;
525 for (cnt = 0; cnt < count / 2; cnt++) {
526 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
527 cnt+ha->nvram_base));
530 qla2x00_unlock_nvram_access(ha);
531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
536 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
537 loff_t off, size_t count)
539 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
540 struct device, kobj)));
547 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
550 /* Checksum NVRAM. */
551 iter = (uint8_t *)buf;
553 for (cnt = 0; cnt < count - 1; cnt++)
555 chksum = ~chksum + 1;
559 spin_lock_irqsave(&ha->hardware_lock, flags);
560 qla2x00_lock_nvram_access(ha);
561 witer = (uint16_t *)buf;
562 for (cnt = 0; cnt < count / 2; cnt++) {
563 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
564 cpu_to_le16(*witer));
567 qla2x00_unlock_nvram_access(ha);
568 spin_unlock_irqrestore(&ha->hardware_lock, flags);
573 /* -------------------------------------------------------------------------- */
575 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
577 static char *pci_bus_modes[] = {
578 "33", "66", "100", "133",
583 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
586 strcat(str, pci_bus_modes[pci_bus]);
588 pci_bus = (ha->pci_attr & BIT_8) >> 8;
590 strcat(str, pci_bus_modes[pci_bus]);
592 strcat(str, " MHz)");
598 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
602 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
603 ha->fw_minor_version,
604 ha->fw_subminor_version);
606 if (ha->fw_attributes & BIT_9) {
611 switch (ha->fw_attributes & 0xFF) {
625 sprintf(un_str, "(%x)", ha->fw_attributes);
629 if (ha->fw_attributes & 0x100)
635 /**************************************************************************
636 * qla2x00_queuecommand
639 * Queue a command to the controller.
642 * cmd - pointer to Scsi cmd structure
643 * fn - pointer to Scsi done function
649 * The mid-level driver tries to ensures that queuecommand never gets invoked
650 * concurrently with itself or the interrupt handler (although the
651 * interrupt handler may call this routine as part of request-completion
653 **************************************************************************/
655 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
660 scsi_qla_host_t *ha, *ha2;
662 struct Scsi_Host *host;
663 unsigned int b, t, l;
664 unsigned long handle;
668 host = cmd->device->host;
669 ha = (scsi_qla_host_t *) host->hostdata;
674 spin_unlock_irq(ha->host->host_lock);
677 * Allocate a command packet from the "sp" pool. If we cant get back
678 * one then let scsi layer come back later.
680 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
681 qla_printk(KERN_WARNING, ha,
682 "Couldn't allocate memory for sp - retried.\n");
684 spin_lock_irq(ha->host->host_lock);
690 CMD_SP(cmd) = (void *)sp;
693 if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {
694 /* Need to set sp->flags */
695 sp->flags |= SRB_IOCTL;
696 CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */
699 sp->fo_retry_cnt = 0;
702 /* Generate LU queue on bus, target, LUN */
703 b = cmd->device->channel;
705 l = cmd->device->lun;
708 * Start Command Timer. Typically it will be 2 seconds less than what
709 * is requested by the Host such that we can return the IO before
712 if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)
713 qla2x00_add_timer_to_cmd(sp,
714 (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
716 qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);
718 if (l >= ha->max_luns) {
719 cmd->result = DID_NO_CONNECT << 16;
720 sp->err_id = SRB_ERR_PORT;
722 spin_lock_irq(ha->host->host_lock);
729 if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&
730 (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {
731 fcport = lq->fclun->fcport;
739 /* Set an invalid handle until we issue the command to ISP */
740 /* then we will set the real handle value. */
741 handle = INVALID_HANDLE;
742 cmd->host_scribble = (unsigned char *)handle;
744 /* Bookkeeping information */
745 sp->r_start = jiffies; /* time the request was recieved */
748 /* Setup device queue pointers. */
755 * 1. When device is added from persistent binding but has not been
756 * discovered yet.The state of loopid == PORT_AVAIL.
757 * 2. When device is never found on the bus.(loopid == UNUSED)
759 * IF Device Queue is not created, or device is not in a valid state
760 * and link down error reporting is enabled, reject IO.
762 if (fcport == NULL) {
763 DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",
766 cmd->result = DID_NO_CONNECT << 16;
767 sp->err_id = SRB_ERR_PORT;
769 spin_lock_irq(ha->host->host_lock);
776 /* Only modify the allowed count if the target is a *non* tape device */
777 if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {
778 sp->flags &= ~SRB_TAPE;
779 if (cmd->allowed < ql2xretrycount) {
780 cmd->allowed = ql2xretrycount;
783 sp->flags |= SRB_TAPE;
786 DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "
787 "flags=0x%x fo retry=%d, pid=%ld\n",
788 ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,
789 cmd->serial_number));
790 DEBUG5(qla2x00_print_scsi_cmd(cmd));
792 sp->fclun = lq->fclun;
795 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&
796 cmd->request_bufflen != 0) {
798 DEBUG2(printk(KERN_WARNING
799 "scsi(%ld): Incorrect data direction - transfer "
800 "length=%d, direction=%d, pid=%ld, opcode=%x\n",
801 ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,
802 cmd->serial_number, cmd->cmnd[0]));
807 * Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.
809 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
810 atomic_read(&ha2->loop_state) == LOOP_DEAD) {
812 * Add the command to the done-queue for later failover
815 cmd->result = DID_NO_CONNECT << 16;
816 if (atomic_read(&ha2->loop_state) == LOOP_DOWN)
817 sp->err_id = SRB_ERR_LOOP;
819 sp->err_id = SRB_ERR_PORT;
821 add_to_done_queue(ha, sp);
824 spin_lock_irq(ha->host->host_lock);
827 if (tq && test_bit(TQF_SUSPENDED, &tq->flags) &&
828 (sp->flags & SRB_TAPE) == 0) {
829 /* If target suspended put incoming I/O in retry_q. */
830 qla2x00_extend_timeout(sp->cmd, 10);
831 add_to_scsi_retry_queue(ha, sp);
833 was_empty = add_to_pending_queue(ha, sp);
835 if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {
840 if (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
841 spin_lock_irqsave(&ha->hardware_lock, flags);
842 qla2x00_process_response_queue(ha);
843 spin_unlock_irqrestore(&ha->hardware_lock, flags);
847 /* We submit to the hardware if:
849 * 1) we're on the cpu the irq's arrive on or
850 * 2) there are very few io's outstanding.
852 * In all other cases we'll let an irq pick up our IO and submit it
853 * to the controller to improve affinity.
855 if (smp_processor_id() == ha->last_irq_cpu || was_empty)
858 spin_lock_irq(ha->host->host_lock);
864 * qla2x00_eh_wait_on_command
865 * Waits for the command to be returned by the Firmware for some
869 * ha = actual ha whose done queue will contain the command
870 * returned by firmware.
871 * cmd = Scsi Command to wait on.
872 * flag = Abort/Reset(Bus or Device Reset)
879 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
881 #define ABORT_WAIT_TIME 10 /* seconds */
886 struct list_head *list, *temp;
887 u_long cpu_flags = 0;
888 u_long max_wait_time = ABORT_WAIT_TIME;
891 /* Check on done queue */
893 spin_lock_irqsave(&ha->list_lock, cpu_flags);
894 list_for_each_safe(list, temp, &ha->done_queue) {
895 rp = list_entry(list, srb_t, list);
898 * Found command. Just exit and wait for the
901 if (cmd == rp->cmd) {
903 DEBUG3(printk("%s: found in done "
904 "queue.\n", __func__);)
908 spin_unlock_irqrestore(&ha->list_lock, cpu_flags);
911 /* Checking to see if its returned to OS */
912 rp = (srb_t *) CMD_SP(cmd);
918 spin_unlock_irq(ha->host->host_lock);
920 set_current_state(TASK_UNINTERRUPTIBLE);
921 schedule_timeout(2*HZ);
923 spin_lock_irq(ha->host->host_lock);
925 } while ((max_wait_time--));
928 DEBUG2(printk(KERN_INFO "%s: found cmd=%p.\n", __func__, cmd));
930 /* Immediately return command to the mid-layer */
931 qla2x00_delete_from_done_queue(ha, rp);
940 * qla2x00_wait_for_hba_online
941 * Wait till the HBA is online after going through
942 * <= MAX_RETRIES_OF_ISP_ABORT or
943 * finally HBA is disabled ie marked offline
946 * ha - pointer to host adapter structure
949 * Does context switching-Release SPIN_LOCK
950 * (if any) before calling this routine.
953 * Success (Adapter is online) : 0
954 * Failed (Adapter is offline/disabled) : 1
957 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
960 unsigned long wait_online;
962 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
963 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
964 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
965 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) &&
966 time_before(jiffies, wait_online)) {
968 set_current_state(TASK_UNINTERRUPTIBLE);
969 schedule_timeout(HZ);
971 if (ha->flags.online == TRUE)
972 return_status = QLA_SUCCESS;
974 /* Adapter is disabled/offline */
975 return_status = QLA_FUNCTION_FAILED;
977 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
979 return (return_status);
983 * qla2x00_wait_for_loop_ready
984 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
985 * to be in LOOP_READY state.
987 * ha - pointer to host adapter structure
990 * Does context switching-Release SPIN_LOCK
991 * (if any) before calling this routine.
995 * Success (LOOP_READY) : 0
996 * Failed (LOOP_NOT_READY) : 1
999 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
1001 int return_status = QLA_SUCCESS;
1002 unsigned long loop_timeout ;
1004 /* wait for 5 min at the max for loop to be ready */
1005 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1007 while ((!atomic_read(&ha->loop_down_timer) &&
1008 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
1009 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
1010 atomic_read(&ha->loop_state) != LOOP_READY) {
1011 set_current_state(TASK_UNINTERRUPTIBLE);
1012 schedule_timeout(HZ);
1013 if (time_after_eq(jiffies, loop_timeout)) {
1014 return_status = QLA_FUNCTION_FAILED;
1018 return (return_status);
1021 /**************************************************************************
1025 * The abort function will abort the specified command.
1028 * cmd = Linux SCSI command packet to be aborted.
1031 * Either SUCCESS or FAILED.
1034 **************************************************************************/
1036 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1039 int return_status = FAILED;
1041 scsi_qla_host_t *ha;
1042 scsi_qla_host_t *vis_ha;
1045 struct list_head *list, *temp;
1046 struct Scsi_Host *host;
1048 unsigned int b, t, l;
1049 unsigned long flags;
1051 /* Get the SCSI request ptr */
1052 sp = (srb_t *) CMD_SP(cmd);
1055 * If sp is NULL, command is already returned.
1056 * sp is NULLED just before we call back scsi_done
1060 /* no action - we don't have command */
1061 qla_printk(KERN_INFO, to_qla_host(cmd->device->host),
1062 "qla2xxx_eh_abort: cmd already done sp=%p\n", sp);
1063 DEBUG(printk("qla2xxx_eh_abort: cmd already done sp=%p\n", sp);)
1067 DEBUG(printk("qla2xxx_eh_abort: refcount %i \n",
1068 atomic_read(&sp->ref_count));)
1071 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1072 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1076 /* Generate LU queue on bus, target, LUN */
1077 b = cmd->device->channel;
1078 t = cmd->device->id;
1079 l = cmd->device->lun;
1080 q = GET_LU_Q(vis_ha, t, l);
1082 qla_printk(KERN_INFO, ha,
1083 "%s scsi(%ld:%d:%d:%d): cmd_timeout_in_sec=0x%x.\n", __func__,
1084 ha->host_no, (int)b, (int)t, (int)l,
1085 cmd->timeout_per_command / HZ);
1088 * if no LUN queue then something is very wrong!!!
1091 qla_printk(KERN_WARNING, ha,
1092 "qla2x00: (%x:%x:%x) No LUN queue.\n", b, t, l);
1094 /* no action - we don't have command */
1098 DEBUG2(printk("scsi(%ld): ABORTing cmd=%p sp=%p jiffies = 0x%lx, "
1099 "timeout=%x, dpc_flags=%lx, vis_ha->dpc_flags=%lx q->flag=%lx\n",
1100 ha->host_no, cmd, sp, jiffies, cmd->timeout_per_command / HZ,
1101 ha->dpc_flags, vis_ha->dpc_flags, q->q_flag));
1102 DEBUG2(qla2x00_print_scsi_cmd(cmd));
1104 spin_unlock_irq(ha->host->host_lock);
1105 /* Blocking call-Does context switching if abort isp is active etc */
1106 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1107 DEBUG2(printk("%s failed:board disabled\n", __func__);)
1108 spin_lock_irq(ha->host->host_lock);
1111 spin_lock_irq(ha->host->host_lock);
1113 /* Search done queue */
1114 spin_lock_irqsave(&ha->list_lock,flags);
1115 list_for_each_safe(list, temp, &ha->done_queue) {
1116 rp = list_entry(list, srb_t, list);
1122 * Found command.Remove it from done list.
1123 * And proceed to post completion to scsi mid layer.
1125 return_status = SUCCESS;
1127 qla2x00_delete_from_done_queue(ha, sp);
1130 } /* list_for_each_safe() */
1131 spin_unlock_irqrestore(&ha->list_lock, flags);
1134 * Return immediately if the aborted command was already in the done
1138 qla_printk(KERN_INFO, ha,
1139 "qla2xxx_eh_abort: Returning completed command=%p sp=%p\n",
1142 return (return_status);
1147 * See if this command is in the retry queue
1149 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p in retry "
1152 spin_lock_irqsave(&ha->list_lock, flags);
1153 list_for_each_safe(list, temp, &ha->retry_queue) {
1154 rp = list_entry(list, srb_t, list);
1160 DEBUG2(printk("qla2xxx_eh_abort: found "
1161 "in retry queue. SP=%p\n", sp);)
1163 __del_from_retry_queue(ha, rp);
1164 cmd->result = DID_ABORT << 16;
1165 __add_to_done_queue(ha, rp);
1167 return_status = SUCCESS;
1173 spin_unlock_irqrestore(&ha->list_lock, flags);
1177 * Our SP pointer points at the command we want to remove from the
1178 * pending queue providing we haven't already sent it to the adapter.
1181 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1182 "in pending queue.\n", sp);)
1184 spin_lock_irqsave(&vis_ha->list_lock, flags);
1185 list_for_each_safe(list, temp, &vis_ha->pending_queue) {
1186 rp = list_entry(list, srb_t, list);
1191 /* Remove srb from LUN queue. */
1192 rp->flags |= SRB_ABORTED;
1194 DEBUG2(printk("qla2xxx_eh_abort: Cmd in pending queue."
1195 " serial_number %ld.\n",
1196 sp->cmd->serial_number);)
1198 __del_from_pending_queue(vis_ha, rp);
1199 cmd->result = DID_ABORT << 16;
1201 __add_to_done_queue(vis_ha, rp);
1203 return_status = SUCCESS;
1207 } /* list_for_each_safe() */
1208 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
1209 } /*End of if !found */
1211 if (!found) { /* find the command in our active list */
1212 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1213 "in outstanding queue.\n", sp);)
1215 spin_lock_irqsave(&ha->hardware_lock, flags);
1216 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1217 sp = ha->outstanding_cmds[i];
1225 DEBUG2(printk("qla2xxx_eh_abort(%ld): aborting sp %p "
1226 "from RISC. pid=%ld sp->state=%x q->q_flag=%lx\n",
1227 ha->host_no, sp, sp->cmd->serial_number,
1228 sp->state, q->q_flag);)
1229 DEBUG(qla2x00_print_scsi_cmd(cmd);)
1231 /* Get a reference to the sp and drop the lock.*/
1234 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1235 spin_unlock(ha->host->host_lock);
1237 if (qla2x00_abort_command(ha, sp)) {
1238 DEBUG2(printk("qla2xxx_eh_abort: abort_command "
1240 return_status = FAILED;
1242 DEBUG3(printk("qla2xxx_eh_abort: abort_command "
1243 " mbx success.\n");)
1244 return_status = SUCCESS;
1249 spin_lock_irq(ha->host->host_lock);
1250 spin_lock_irqsave(&ha->hardware_lock, flags);
1253 * Regardless of mailbox command status, go check on
1254 * done queue just in case the sp is already done.
1258 }/*End of for loop */
1259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1261 } /*End of if !found */
1263 /*Waiting for our command in done_queue to be returned to OS.*/
1264 if (qla2x00_eh_wait_on_command(ha, cmd) != 0) {
1265 DEBUG2(printk("qla2xxx_eh_abort: cmd returned back to OS.\n");)
1266 return_status = SUCCESS;
1269 if (return_status == FAILED) {
1270 qla_printk(KERN_INFO, ha,
1271 "qla2xxx_eh_abort Exiting: status=Failed\n");
1275 DEBUG2(printk("qla2xxx_eh_abort: Exiting. return_status=0x%x.\n",
1278 return(return_status);
1281 /**************************************************************************
1282 * qla2x00_eh_wait_for_pending_target_commands
1285 * Waits for all the commands to come back from the specified target.
1288 * ha - pointer to scsi_qla_host structure.
1291 * Either SUCCESS or FAILED.
1294 **************************************************************************/
1296 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
1300 unsigned long flags;
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_irqsave(&ha->hardware_lock, flags);
1312 sp = ha->outstanding_cmds[cnt];
1315 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1316 if (cmd->device->id == t) {
1317 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
1324 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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;
1359 unsigned long flags;
1361 struct list_head *list, *temp;
1363 return_status = FAILED;
1366 "%s(): **** SCSI mid-layer passing in NULL cmd\n",
1369 return (return_status);
1372 b = cmd->device->channel;
1373 t = cmd->device->id;
1374 l = cmd->device->lun;
1375 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1379 qla_printk(KERN_INFO, ha,
1380 "%s(): **** CMD derives a NULL TGT_Q\n", __func__);
1382 return (return_status);
1384 lq = (os_lun_t *)LUN_Q(ha, t, l);
1387 "%s(): **** CMD derives a NULL LUN_Q\n", __func__);
1389 return (return_status);
1391 fcport_to_reset = lq->fclun->fcport;
1393 /* If we are coming in from the back-door, stall I/O until complete. */
1394 if (!cmd->device->host->eh_active)
1395 set_bit(TQF_SUSPENDED, &tq->flags);
1397 qla_printk(KERN_INFO, ha,
1398 "scsi(%ld:%d:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, b, t, l);
1400 DEBUG2(printk(KERN_INFO
1401 "scsi(%ld): DEVICE_RESET cmd=%p jiffies = 0x%lx, timeout=%x, "
1402 "dpc_flags=%lx, status=%x allowed=%d cmd.state=%x\n",
1403 ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
1404 ha->dpc_flags, cmd->result, cmd->allowed, cmd->state));
1406 /* Clear commands from the retry queue. */
1407 spin_lock_irqsave(&ha->list_lock, flags);
1408 list_for_each_safe(list, temp, &ha->retry_queue) {
1409 rp = list_entry(list, srb_t, list);
1411 if (t != rp->cmd->device->id)
1414 DEBUG2(printk(KERN_INFO
1415 "qla2xxx_eh_reset: found in retry queue. SP=%p\n", rp));
1417 __del_from_retry_queue(ha, rp);
1418 rp->cmd->result = DID_RESET << 16;
1419 __add_to_done_queue(ha, rp);
1421 spin_unlock_irqrestore(&ha->list_lock, flags);
1423 spin_unlock_irq(ha->host->host_lock);
1425 /* Blocking call-Does context switching if abort isp is active etc */
1426 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1427 DEBUG2(printk(KERN_INFO
1428 "%s failed:board disabled\n",__func__));
1430 spin_lock_irq(ha->host->host_lock);
1431 goto eh_dev_reset_done;
1434 /* Blocking call-Does context switching if loop is Not Ready */
1435 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1436 if (qla2x00_device_reset(ha, fcport_to_reset) == 0) {
1437 return_status = SUCCESS;
1440 #if defined(LOGOUT_AFTER_DEVICE_RESET)
1441 if (return_status == SUCCESS) {
1442 if (fcport_to_reset->flags & FC_FABRIC_DEVICE) {
1443 qla2x00_fabric_logout(ha,
1444 fcport_to_reset->loop_id);
1445 qla2x00_mark_device_lost(ha, fcport_to_reset);
1450 DEBUG2(printk(KERN_INFO
1451 "%s failed: loop not ready\n",__func__);)
1454 spin_lock_irq(ha->host->host_lock);
1456 if (return_status == FAILED) {
1457 DEBUG3(printk("%s(%ld): device reset failed\n",
1458 __func__,ha->host_no));
1459 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
1462 goto eh_dev_reset_done;
1466 * If we are coming down the EH path, wait for all commands to
1467 * complete for the device.
1469 if (cmd->device->host->eh_active) {
1470 if (qla2x00_eh_wait_for_pending_target_commands(ha, t))
1471 return_status = FAILED;
1473 if (return_status == FAILED) {
1474 DEBUG3(printk("%s(%ld): failed while waiting for "
1475 "commands\n", __func__, ha->host_no));
1476 qla_printk(KERN_INFO, ha,
1477 "%s: failed while waiting for commands\n",
1480 goto eh_dev_reset_done;
1484 qla_printk(KERN_INFO, ha,
1485 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1486 ha->host_no, b, t, l);
1490 if (!cmd->device->host->eh_active)
1491 clear_bit(TQF_SUSPENDED, &tq->flags);
1493 return (return_status);
1496 /**************************************************************************
1497 * qla2x00_eh_wait_for_pending_commands
1500 * Waits for all the commands to come back from the specified host.
1503 * ha - pointer to scsi_qla_host structure.
1510 **************************************************************************/
1512 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
1516 unsigned long flags;
1518 struct scsi_cmnd *cmd;
1523 * Waiting for all commands for the designated target in the active
1526 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1527 spin_lock_irqsave(&ha->hardware_lock, flags);
1528 sp = ha->outstanding_cmds[cnt];
1531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1532 status = qla2x00_eh_wait_on_command(ha, cmd);
1537 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1544 /**************************************************************************
1545 * qla2xxx_eh_bus_reset
1548 * The bus reset function will reset the bus and abort any executing
1552 * cmd = Linux SCSI command packet of the command that cause the
1556 * SUCCESS/FAILURE (defined as macro in scsi.h).
1558 **************************************************************************/
1560 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1562 scsi_qla_host_t *ha;
1566 ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1567 sp = (srb_t *) CMD_SP(cmd);
1569 qla_printk(KERN_INFO, ha,
1570 "scsi(%ld:%d:%d:%d): LOOP RESET ISSUED.\n", ha->host_no,
1571 cmd->device->channel, cmd->device->id, cmd->device->lun);
1573 spin_unlock_irq(ha->host->host_lock);
1575 /* Blocking call-Does context switching if abort isp is active etc*/
1576 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1577 DEBUG2(printk("%s failed:board disabled\n",__func__));
1578 spin_lock_irq(ha->host->host_lock);
1582 /* Blocking call-Does context switching if loop is Not Ready */
1583 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1584 if (qla2x00_loop_reset(ha))
1588 spin_lock_irq(ha->host->host_lock);
1593 * Blocking Call. It goes to sleep waiting for cmd to get to done q
1595 * XXX(hch): really? We're under host_lock here..
1597 /* Waiting for our command in done_queue to be returned to OS.*/
1598 if (!qla2x00_eh_wait_for_pending_commands(ha))
1602 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1603 (rval == FAILED) ? "failed" : "succeded");
1608 /**************************************************************************
1609 * qla2xxx_eh_host_reset
1612 * The reset function will reset the Adapter.
1615 * cmd = Linux SCSI command packet of the command that cause the
1619 * Either SUCCESS or FAILED.
1622 **************************************************************************/
1624 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1626 scsi_qla_host_t *ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1629 /* Display which one we're actually resetting for debug. */
1630 DEBUG(printk("qla2xxx_eh_host_reset:Resetting scsi(%ld).\n",
1636 qla_printk(KERN_INFO, ha,
1637 "scsi(%ld:%d:%d:%d): ADAPTER RESET issued.\n", ha->host_no,
1638 cmd->device->channel, cmd->device->id, cmd->device->lun);
1640 spin_unlock_irq(ha->host->host_lock);
1642 /* Blocking call-Does context switching if abort isp is active etc*/
1643 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1644 goto board_disabled;
1647 * Fixme-may be dpc thread is active and processing
1648 * loop_resync,so wait a while for it to
1649 * be completed and then issue big hammer.Otherwise
1650 * it may cause I/O failure as big hammer marks the
1651 * devices as lost kicking of the port_down_timer
1652 * while dpc is stuck for the mailbox to complete.
1654 /* Blocking call-Does context switching if loop is Not Ready */
1655 qla2x00_wait_for_loop_ready(ha);
1656 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1657 if (qla2x00_abort_isp(ha)) {
1658 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1659 /* failed. schedule dpc to try */
1660 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1662 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1663 goto board_disabled;
1666 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1668 spin_lock_irq(ha->host->host_lock);
1672 /* Waiting for our command in done_queue to be returned to OS.*/
1673 if (qla2x00_eh_wait_for_pending_commands(ha))
1677 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1678 (rval == FAILED) ? "failed" : "succeded");
1683 spin_lock_irq(ha->host->host_lock);
1685 qla_printk(KERN_INFO, ha, "%s: failed:board disabled\n", __func__);
1691 * qla2x00_loop_reset
1695 * ha = adapter block pointer.
1701 qla2x00_loop_reset(scsi_qla_host_t *ha)
1703 uint8_t status = QLA_SUCCESS;
1707 if (ha->flags.enable_lip_reset) {
1708 status = qla2x00_lip_reset(ha);
1711 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1712 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1713 if ((tq = TGT_Q(ha, t)) == NULL)
1716 if (tq->fcport == NULL)
1719 status = qla2x00_target_reset(ha, 0, t);
1720 if (status != QLA_SUCCESS) {
1726 if (status == QLA_SUCCESS &&
1727 ((!ha->flags.enable_target_reset &&
1728 !ha->flags.enable_lip_reset) ||
1729 ha->flags.enable_lip_full_login)) {
1731 status = qla2x00_full_login_lip(ha);
1734 /* Issue marker command only when we are going to start the I/O */
1735 ha->marker_needed = 1;
1739 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1744 DEBUG3(printk("%s(%ld): exiting normally.\n",
1753 * qla2x00_device_reset
1754 * Issue bus device reset message to the target.
1757 * ha = adapter block pointer.
1759 * TARGET_QUEUE_LOCK must be released.
1760 * ADAPTER_STATE_LOCK must be released.
1766 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1768 /* Abort Target command will clear Reservation */
1769 return qla2x00_abort_target(reset_fcport);
1772 /**************************************************************************
1773 * qla2xxx_slave_configure
1776 **************************************************************************/
1778 qla2xxx_slave_configure(struct scsi_device *sdev)
1780 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1783 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1788 if (sdev->tagged_supported) {
1789 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1790 queue_depth = ql2xmaxqdepth;
1792 ql2xmaxqdepth = queue_depth;
1794 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
1796 qla_printk(KERN_INFO, ha,
1797 "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue "
1799 sdev->host->host_no, sdev->channel, sdev->id, sdev->lun,
1802 scsi_adjust_queue_depth(sdev, 0 /* TCQ off */,
1803 sdev->host->hostt->cmd_per_lun /* 3 */);
1810 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1813 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1814 * supported addressing method.
1817 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1819 /* Assume 32bit DMA address */
1820 ha->flags.enable_64bit_addressing = 0;
1821 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1822 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1825 * Given the two variants pci_set_dma_mask(), allow the compiler to
1826 * assist in setting the proper dma mask.
1828 if (sizeof(dma_addr_t) > 4) {
1829 /* Update our PCI device dma_mask for full 64 bits */
1830 if (pci_set_dma_mask(ha->pdev, 0xffffffffffffffffULL) == 0) {
1831 ha->flags.enable_64bit_addressing = 1;
1832 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1833 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1835 if (pci_set_consistent_dma_mask(ha->pdev,
1836 0xffffffffffffffffULL)) {
1837 qla_printk(KERN_DEBUG, ha,
1838 "Failed to set 64 bit PCI consistent mask; "
1840 pci_set_consistent_dma_mask(ha->pdev,
1844 qla_printk(KERN_DEBUG, ha,
1845 "Failed to set 64 bit PCI DMA mask, falling back "
1846 "to 32 bit MASK.\n");
1847 pci_set_dma_mask(ha->pdev, 0xffffffff);
1850 pci_set_dma_mask(ha->pdev, 0xffffffff);
1855 qla2x00_iospace_config(scsi_qla_host_t *ha)
1857 unsigned long pio, pio_len, pio_flags;
1858 unsigned long mmio, mmio_len, mmio_flags;
1860 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1861 pio = pci_resource_start(ha->pdev, 0);
1862 pio_len = pci_resource_len(ha->pdev, 0);
1863 pio_flags = pci_resource_flags(ha->pdev, 0);
1864 if (pio_flags & IORESOURCE_IO) {
1865 if (pio_len < MIN_IOBASE_LEN) {
1866 qla_printk(KERN_WARNING, ha,
1867 "Invalid PCI I/O region size (%s)...\n",
1868 ha->pdev->slot_name);
1872 qla_printk(KERN_WARNING, ha,
1873 "region #0 not a PIO resource (%s)...\n",
1874 ha->pdev->slot_name);
1878 /* Use MMIO operations for all accesses. */
1879 mmio = pci_resource_start(ha->pdev, 1);
1880 mmio_len = pci_resource_len(ha->pdev, 1);
1881 mmio_flags = pci_resource_flags(ha->pdev, 1);
1883 if (!(mmio_flags & IORESOURCE_MEM)) {
1884 qla_printk(KERN_ERR, ha,
1885 "region #0 not an MMIO resource (%s), aborting\n",
1886 ha->pdev->slot_name);
1887 goto iospace_error_exit;
1889 if (mmio_len < MIN_IOBASE_LEN) {
1890 qla_printk(KERN_ERR, ha,
1891 "Invalid PCI mem region size (%s), aborting\n",
1892 ha->pdev->slot_name);
1893 goto iospace_error_exit;
1896 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1897 qla_printk(KERN_WARNING, ha,
1898 "Failed to reserve PIO/MMIO regions (%s)\n",
1899 ha->pdev->slot_name);
1901 goto iospace_error_exit;
1904 ha->pio_address = pio;
1905 ha->pio_length = pio_len;
1906 ha->mmio_address = ioremap(mmio, MIN_IOBASE_LEN);
1907 if (!ha->mmio_address) {
1908 qla_printk(KERN_ERR, ha,
1909 "cannot remap MMIO (%s), aborting\n", ha->pdev->slot_name);
1911 goto iospace_error_exit;
1913 ha->mmio_length = mmio_len;
1914 ha->iobase = (device_reg_t *) ha->mmio_address;
1923 * PCI driver interface
1925 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1929 struct Scsi_Host *host;
1930 scsi_qla_host_t *ha;
1931 unsigned long flags = 0;
1932 unsigned long wait_switch = 0;
1936 if (pci_enable_device(pdev))
1939 host = scsi_host_alloc(&qla2x00_driver_template,
1940 sizeof(scsi_qla_host_t));
1943 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1947 /* Clear our data area */
1948 ha = (scsi_qla_host_t *)host->hostdata;
1949 memset(ha, 0, sizeof(scsi_qla_host_t));
1953 ha->host_no = host->host_no;
1954 ha->brd_info = brd_info;
1955 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1957 /* Configure PCI I/O space */
1958 ret = qla2x00_iospace_config(ha);
1963 /* Sanitize the information from PCI BIOS. */
1964 host->irq = pdev->irq;
1966 qla_printk(KERN_INFO, ha,
1967 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1968 host->irq, ha->iobase);
1970 spin_lock_init(&ha->hardware_lock);
1972 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1975 ha->total_isr_cnt = 0;
1976 ha->total_isp_aborts = 0;
1977 ha->total_lip_cnt = 0;
1978 ha->total_dev_errs = 0;
1980 ha->total_bytes = 0;
1982 ha->prev_topology = 0;
1983 ha->ports = MAX_BUSES;
1985 if (IS_QLA2100(ha)) {
1986 ha->max_targets = MAX_TARGETS_2100;
1987 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1988 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1989 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1990 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1991 host->sg_tablesize = 32;
1992 } else if (IS_QLA2200(ha)) {
1993 ha->max_targets = MAX_TARGETS_2200;
1994 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1995 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1996 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1997 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1998 } else /*if (IS_QLA2300(ha))*/ {
1999 ha->max_targets = MAX_TARGETS_2200;
2000 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2001 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
2002 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
2003 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
2005 host->can_queue = ha->request_q_length + 128;
2007 /* load the F/W, read paramaters, and init the H/W */
2008 ha->instance = num_hosts;
2010 init_MUTEX(&ha->mbx_cmd_sem);
2011 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
2013 INIT_LIST_HEAD(&ha->list);
2014 INIT_LIST_HEAD(&ha->fcports);
2015 INIT_LIST_HEAD(&ha->rscn_fcports);
2016 INIT_LIST_HEAD(&ha->done_queue);
2017 INIT_LIST_HEAD(&ha->retry_queue);
2018 INIT_LIST_HEAD(&ha->scsi_retry_queue);
2019 INIT_LIST_HEAD(&ha->pending_queue);
2022 * These locks are used to prevent more than one CPU
2023 * from modifying the queue at the same time. The
2024 * higher level "host_lock" will reduce most
2025 * contention for these locks.
2027 spin_lock_init(&ha->mbx_reg_lock);
2028 spin_lock_init(&ha->list_lock);
2031 init_completion(&ha->dpc_inited);
2032 init_completion(&ha->dpc_exited);
2034 qla2x00_config_dma_addressing(ha);
2035 if (qla2x00_mem_alloc(ha)) {
2036 qla_printk(KERN_WARNING, ha,
2037 "[ERROR] Failed to allocate memory for adapter\n");
2042 if (qla2x00_initialize_adapter(ha) &&
2043 !(ha->device_flags & DFLG_NO_CABLE)) {
2045 qla_printk(KERN_WARNING, ha,
2046 "Failed to initialize adapter\n");
2048 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2049 "Adapter flags %x.\n",
2050 ha->host_no, ha->device_flags));
2056 * Startup the kernel thread for this host adapter
2058 ha->dpc_should_die = 0;
2059 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
2060 if (ha->dpc_pid < 0) {
2061 qla_printk(KERN_WARNING, ha,
2062 "Unable to start DPC thread!\n");
2066 wait_for_completion(&ha->dpc_inited);
2068 host->this_id = 255;
2069 host->cmd_per_lun = 3;
2070 host->max_cmd_len = MAX_CMDSZ;
2071 host->max_channel = ha->ports - 1;
2072 host->max_lun = ha->max_luns;
2073 BUG_ON(qla2xxx_transport_template == NULL);
2074 host->transportt = qla2xxx_transport_template;
2075 host->unique_id = ha->instance;
2076 host->max_id = ha->max_targets;
2078 if (request_irq(host->irq, qla2x00_intr_handler, SA_INTERRUPT|SA_SHIRQ,
2079 ha->brd_info->drv_name, ha)) {
2080 qla_printk(KERN_WARNING, ha,
2081 "Failed to reserve interrupt %d already in use.\n",
2086 /* Initialized the timer */
2087 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
2089 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2094 /* Disable ISP interrupts. */
2095 qla2x00_disable_intrs(ha);
2097 /* Ensure mailbox registers are free. */
2098 spin_lock_irqsave(&ha->hardware_lock, flags);
2099 WRT_REG_WORD(®->semaphore, 0);
2100 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2101 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2103 /* Enable proper parity */
2104 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2107 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
2109 /* SRAM, Instruction RAM and GP RAM parity */
2110 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
2112 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2115 /* Enable chip interrupts. */
2116 qla2x00_enable_intrs(ha);
2118 /* Insert new entry into the list of adapters */
2119 write_lock(&qla_hostlist_lock);
2120 list_add_tail(&ha->list, &qla_hostlist);
2121 write_unlock(&qla_hostlist_lock);
2125 * Wait around max loop_reset_delay secs for the devices to come
2126 * on-line. We don't want Linux scanning before we are ready.
2129 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
2130 time_before(jiffies,wait_switch) &&
2131 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
2132 && (ha->device_flags & SWITCH_FOUND) ;) {
2134 qla2x00_check_fabric_devices(ha);
2136 set_current_state(TASK_UNINTERRUPTIBLE);
2137 schedule_timeout(HZ/100);
2140 pci_set_drvdata(pdev, ha);
2141 ha->flags.init_done = 1;
2144 /* List the target we have found */
2145 if (displayConfig) {
2146 qla2x00_display_fc_names(ha);
2149 if (scsi_add_host(host, &pdev->dev))
2152 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
2153 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
2155 qla_printk(KERN_INFO, ha, "\n"
2156 " QLogic Fibre Channel HBA Driver: %s\n"
2158 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
2159 ha->model_number, ha->model_desc ? ha->model_desc: "",
2160 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
2161 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
2162 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
2165 scsi_scan_host(host);
2170 qla2x00_free_device(ha);
2172 scsi_host_put(host);
2176 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
2178 void qla2x00_remove_one(struct pci_dev *pdev)
2180 scsi_qla_host_t *ha;
2182 ha = pci_get_drvdata(pdev);
2184 write_lock(&qla_hostlist_lock);
2185 list_del(&ha->list);
2186 write_unlock(&qla_hostlist_lock);
2188 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
2189 &sysfs_fw_dump_attr);
2190 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
2192 scsi_remove_host(ha->host);
2194 qla2x00_free_device(ha);
2196 scsi_host_put(ha->host);
2198 pci_set_drvdata(pdev, NULL);
2200 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
2203 qla2x00_free_device(scsi_qla_host_t *ha)
2207 /* Abort any outstanding IO descriptors. */
2208 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2209 qla2x00_cancel_io_descriptors(ha);
2211 /* turn-off interrupts on the card */
2212 if (ha->interrupts_on)
2213 qla2x00_disable_intrs(ha);
2216 if (ha->timer_active)
2217 qla2x00_stop_timer(ha);
2219 /* Kill the kernel thread for this host */
2220 if (ha->dpc_pid >= 0) {
2221 ha->dpc_should_die = 1;
2223 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
2225 qla_printk(KERN_ERR, ha,
2226 "Unable to signal DPC thread -- (%d)\n", ret);
2228 /* TODO: SOMETHING MORE??? */
2230 wait_for_completion(&ha->dpc_exited);
2234 qla2x00_mem_free(ha);
2237 ha->flags.online = FALSE;
2239 /* Detach interrupts */
2241 free_irq(ha->pdev->irq, ha);
2243 /* release io space registers */
2244 pci_release_regions(ha->pdev);
2246 #if MEMORY_MAPPED_IO
2247 if (ha->mmio_address)
2248 iounmap(ha->mmio_address);
2254 * The following support functions are adopted to handle
2255 * the re-entrant qla2x00_proc_info correctly.
2258 copy_mem_info(struct info_str *info, char *data, int len)
2260 if (info->pos + len > info->offset + info->length)
2261 len = info->offset + info->length - info->pos;
2263 if (info->pos + len < info->offset) {
2268 if (info->pos < info->offset) {
2271 partial = info->offset - info->pos;
2273 info->pos += partial;
2278 memcpy(info->buffer, data, len);
2280 info->buffer += len;
2285 copy_info(struct info_str *info, char *fmt, ...)
2291 va_start(args, fmt);
2292 len = vsprintf(buf, fmt, args);
2295 copy_mem_info(info, buf, len);
2300 /*************************************************************************
2304 * Return information to handle /proc support for the driver.
2306 * inout : decides the direction of the dataflow and the meaning of the
2308 * buffer: If inout==FALSE data is being written to it else read from it
2309 * (ptr to a page buffer)
2310 * *start: If inout==FALSE start of the valid data in the buffer
2311 * offset: If inout==FALSE starting offset from the beginning of all
2312 * possible data to return.
2313 * length: If inout==FALSE max number of bytes to be written into the buffer
2314 * else number of bytes in "buffer"
2316 * < 0: error. errno value.
2317 * >= 0: sizeof data returned.
2318 *************************************************************************/
2320 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
2321 char **start, off_t offset, int length, int inout)
2323 struct info_str info;
2324 int retval = -EINVAL;
2330 uint8_t *loop_state;
2332 scsi_qla_host_t *ha;
2335 DEBUG3(printk(KERN_INFO
2336 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
2337 buffer, offset, length);)
2341 /* Find the host that was specified */
2343 read_lock(&qla_hostlist_lock);
2344 list_for_each_entry(ha, &qla_hostlist, list) {
2345 if (ha->host == shost) {
2350 read_unlock(&qla_hostlist_lock);
2352 /* if host wasn't found then exit */
2354 DEBUG2_3(printk(KERN_WARNING
2355 "%s: Can't find adapter for host %p\n",
2361 if (inout == TRUE) {
2362 /* Has data been written to the file? */
2364 "%s: has data been written to the file. \n",
2367 return (qla2x00_set_info(buffer, length, shost));
2374 info.buffer = buffer;
2375 info.length = length;
2376 info.offset = offset;
2379 /* start building the print buffer */
2381 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
2382 " Firmware version %s, ",
2383 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
2385 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
2387 copy_info(&info, "Entry address = %p\n", qla2x00_set_info);
2389 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
2391 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
2392 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
2395 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
2396 (unsigned long long)ha->request_dma,
2397 (unsigned long long)ha->response_dma);
2400 "Request Queue count = %d, Response Queue count = %d\n",
2401 ha->request_q_length, ha->response_q_length);
2404 "Total number of active commands = %ld\n",
2408 "Total number of interrupts = %ld\n",
2409 (long)ha->total_isr_cnt);
2412 " Device queue depth = 0x%x\n",
2413 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
2416 "Number of free request entries = %d\n", ha->req_q_cnt);
2419 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
2422 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
2425 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
2428 "Number of retries for empty slots = %ld\n",
2429 qla2x00_stats.outarray_full);
2432 "Number of reqs in pending_q= %ld, retry_q= %d, "
2433 "done_q= %ld, scsi_retry_q= %d\n",
2434 ha->qthreads, ha->retry_q_cnt,
2435 ha->done_q_cnt, ha->scsi_retry_q_cnt);
2438 flags = (uint32_t *) &ha->flags;
2440 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
2441 loop_state = "DOWN";
2442 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
2444 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
2445 loop_state = "READY";
2446 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
2447 loop_state = "TIMEOUT";
2448 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
2449 loop_state = "UPDATE";
2451 loop_state = "UNKNOWN";
2455 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
2456 loop_state , *flags);
2458 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
2460 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
2462 copy_info(&info, "Link down Timeout = %3.3d\n",
2463 ha->link_down_timeout);
2465 copy_info(&info, "Port down retry = %3.3d\n",
2466 ha->port_down_retry_count);
2468 copy_info(&info, "Login retry count = %3.3d\n",
2469 ha->login_retry_count);
2472 "Commands retried with dropped frame(s) = %d\n",
2473 ha->dropped_frame_error_cnt);
2476 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
2477 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
2479 copy_info(&info, "\n");
2481 /* 2.25 node/port display to proc */
2482 /* Display the node name for adapter */
2483 copy_info(&info, "\nSCSI Device Information:\n");
2485 "scsi-qla%d-adapter-node="
2486 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2488 ha->init_cb->node_name[0],
2489 ha->init_cb->node_name[1],
2490 ha->init_cb->node_name[2],
2491 ha->init_cb->node_name[3],
2492 ha->init_cb->node_name[4],
2493 ha->init_cb->node_name[5],
2494 ha->init_cb->node_name[6],
2495 ha->init_cb->node_name[7]);
2497 /* display the port name for adapter */
2499 "scsi-qla%d-adapter-port="
2500 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2502 ha->init_cb->port_name[0],
2503 ha->init_cb->port_name[1],
2504 ha->init_cb->port_name[2],
2505 ha->init_cb->port_name[3],
2506 ha->init_cb->port_name[4],
2507 ha->init_cb->port_name[5],
2508 ha->init_cb->port_name[6],
2509 ha->init_cb->port_name[7]);
2511 /* Print out device port names */
2512 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2513 if ((tq = TGT_Q(ha, t)) == NULL)
2517 "scsi-qla%d-target-%d="
2518 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2519 (int)ha->instance, t,
2520 tq->port_name[0], tq->port_name[1],
2521 tq->port_name[2], tq->port_name[3],
2522 tq->port_name[4], tq->port_name[5],
2523 tq->port_name[6], tq->port_name[7]);
2525 copy_info(&info, "\nSCSI LUN Information:\n");
2527 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
2529 /* scan for all equipment stats */
2530 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2532 for (l = 0; l < ha->max_luns; l++) {
2533 up = (os_lun_t *) GET_LU_Q(ha, t, l);
2538 if (up->fclun == NULL) {
2543 "(%2d:%2d): Total reqs %ld,",
2547 " Pending reqs %ld,",
2550 if (up->io_cnt < 4) {
2561 " %ld:%d:%02x %02x",
2562 up->fclun->fcport->ha->instance,
2563 up->fclun->fcport->cur_path,
2564 up->fclun->fcport->loop_id,
2565 up->fclun->device_type);
2567 copy_info(&info, "\n");
2569 if (info.pos >= info.offset + info.length) {
2570 /* No need to continue */
2575 if (info.pos >= info.offset + info.length) {
2576 /* No need to continue */
2583 retval = info.pos > info.offset ? info.pos - info.offset : 0;
2585 DEBUG3(printk(KERN_INFO
2586 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
2587 "length=0x%x\n", info.pos, offset, length);)
2593 * qla2x00_display_fc_names
2594 * This routine will the node names of the different devices found
2595 * after port inquiry.
2598 * cmd = SCSI command structure
2604 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2609 /* Display the node name for adapter */
2610 qla_printk(KERN_INFO, ha,
2611 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2613 ha->init_cb->node_name[0],
2614 ha->init_cb->node_name[1],
2615 ha->init_cb->node_name[2],
2616 ha->init_cb->node_name[3],
2617 ha->init_cb->node_name[4],
2618 ha->init_cb->node_name[5],
2619 ha->init_cb->node_name[6],
2620 ha->init_cb->node_name[7]);
2622 /* display the port name for adapter */
2623 qla_printk(KERN_INFO, ha,
2624 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2626 ha->init_cb->port_name[0],
2627 ha->init_cb->port_name[1],
2628 ha->init_cb->port_name[2],
2629 ha->init_cb->port_name[3],
2630 ha->init_cb->port_name[4],
2631 ha->init_cb->port_name[5],
2632 ha->init_cb->port_name[6],
2633 ha->init_cb->port_name[7]);
2635 /* Print out device port names */
2636 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2637 if ((tq = ha->otgt[tgt]) == NULL)
2640 if (tq->fcport == NULL)
2643 switch (ha->binding_type) {
2644 case BIND_BY_PORT_NAME:
2645 qla_printk(KERN_INFO, ha,
2646 "scsi-qla%d-tgt-%d-di-0-port="
2647 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2661 case BIND_BY_PORT_ID:
2662 qla_printk(KERN_INFO, ha,
2663 "scsi-qla%d-tgt-%d-di-0-pid="
2664 "%02x%02x%02x\\;\n",
2674 qla_printk(KERN_INFO, ha,
2675 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2681 * qla2x00_suspend_lun
2682 * Suspend lun and start port down timer
2685 * ha = visable adapter block pointer.
2687 * cp = Scsi command pointer
2688 * time = time in seconds
2689 * count = number of times to let time expire
2690 * delay_lun = non-zero, if lun should be delayed rather than suspended
2693 * QLA_SUCCESS -- suspended lun
2694 * QLA_FUNCTION_FAILED -- Didn't suspend lun
2697 * Interrupt context.
2700 __qla2x00_suspend_lun(scsi_qla_host_t *ha,
2701 os_lun_t *lq, int time, int count, int delay_lun)
2705 struct list_head *list, *temp;
2706 unsigned long flags;
2710 /* if the lun_q is already suspended then don't do it again */
2711 if (lq->q_state == LUN_STATE_READY ||lq->q_state == LUN_STATE_RUN) {
2713 spin_lock_irqsave(&lq->q_lock, flags);
2714 if (lq->q_state == LUN_STATE_READY) {
2718 /* Set the suspend time usually 6 secs */
2719 atomic_set(&lq->q_timer, time);
2721 /* now suspend the lun */
2722 lq->q_state = LUN_STATE_WAIT;
2725 set_bit(LUN_EXEC_DELAYED, &lq->q_flag);
2726 DEBUG(printk(KERN_INFO
2727 "scsi(%ld): Delay lun execution for %d secs, "
2728 "count=%d, max count=%d, state=%d\n",
2731 lq->q_count, lq->q_max, lq->q_state));
2733 DEBUG(printk(KERN_INFO
2734 "scsi(%ld): Suspend lun for %d secs, count=%d, "
2735 "max count=%d, state=%d\n",
2738 lq->q_count, lq->q_max, lq->q_state));
2740 spin_unlock_irqrestore(&lq->q_lock, flags);
2743 * Remove all pending commands from request queue and put them
2744 * in the scsi_retry queue.
2746 spin_lock_irqsave(&ha->list_lock, flags);
2747 list_for_each_safe(list, temp, &ha->pending_queue) {
2748 sp = list_entry(list, srb_t, list);
2749 if (sp->lun_queue != lq)
2752 __del_from_pending_queue(ha, sp);
2754 if (sp->cmd->allowed < count)
2755 sp->cmd->allowed = count;
2756 __add_to_scsi_retry_queue(ha, sp);
2758 } /* list_for_each_safe */
2759 spin_unlock_irqrestore(&ha->list_lock, flags);
2762 rval = QLA_FUNCTION_FAILED;
2769 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2771 * Input: ha = adapter block pointer. fcport = port structure pointer.
2777 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2781 * We may need to retry the login, so don't change the state of the
2782 * port but do the retries.
2784 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2785 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2790 if (fcport->login_retry == 0) {
2791 fcport->login_retry = ha->login_retry_count;
2792 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2794 DEBUG(printk("scsi(%ld): Port login retry: "
2795 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2796 "id = 0x%04x retry cnt=%d\n",
2798 fcport->port_name[0],
2799 fcport->port_name[1],
2800 fcport->port_name[2],
2801 fcport->port_name[3],
2802 fcport->port_name[4],
2803 fcport->port_name[5],
2804 fcport->port_name[6],
2805 fcport->port_name[7],
2807 fcport->login_retry));
2812 * qla2x00_mark_all_devices_lost
2813 * Updates fcport state when device goes offline.
2816 * ha = adapter block pointer.
2817 * fcport = port structure pointer.
2825 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2829 list_for_each_entry(fcport, &ha->fcports, list) {
2830 if (fcport->port_type != FCT_TARGET)
2834 * No point in marking the device as lost, if the device is
2837 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2840 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2846 * Allocates adapter memory.
2853 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2860 * This will loop only once if everything goes well, else some
2861 * number of retries will be performed to get around a kernel
2862 * bug where available mem is not allocated until after a
2863 * little delay and a retry.
2865 ha->request_ring = pci_alloc_consistent(ha->pdev,
2866 ((ha->request_q_length + 1) * (sizeof(request_t))),
2868 if (ha->request_ring == NULL) {
2869 qla_printk(KERN_WARNING, ha,
2870 "Memory Allocation failed - request_ring\n");
2872 qla2x00_mem_free(ha);
2873 set_current_state(TASK_UNINTERRUPTIBLE);
2874 schedule_timeout(HZ/10);
2879 ha->response_ring = pci_alloc_consistent(ha->pdev,
2880 ((ha->response_q_length + 1) * (sizeof(response_t))),
2882 if (ha->response_ring == NULL) {
2883 qla_printk(KERN_WARNING, ha,
2884 "Memory Allocation failed - response_ring\n");
2886 qla2x00_mem_free(ha);
2887 set_current_state(TASK_UNINTERRUPTIBLE);
2888 schedule_timeout(HZ/10);
2893 /* get consistent memory allocated for init control block */
2894 ha->init_cb = pci_alloc_consistent(ha->pdev,
2895 sizeof(init_cb_t), &ha->init_cb_dma);
2896 if (ha->init_cb == NULL) {
2897 qla_printk(KERN_WARNING, ha,
2898 "Memory Allocation failed - init_cb\n");
2900 qla2x00_mem_free(ha);
2901 set_current_state(TASK_UNINTERRUPTIBLE);
2902 schedule_timeout(HZ/10);
2906 memset(ha->init_cb, 0, sizeof(init_cb_t));
2908 /* Allocate ioctl related memory. */
2909 if (qla2x00_alloc_ioctl_mem(ha)) {
2910 qla_printk(KERN_WARNING, ha,
2911 "Memory Allocation failed - ioctl_mem\n");
2913 qla2x00_mem_free(ha);
2914 set_current_state(TASK_UNINTERRUPTIBLE);
2915 schedule_timeout(HZ/10);
2920 if (qla2x00_allocate_sp_pool(ha)) {
2921 qla_printk(KERN_WARNING, ha,
2922 "Memory Allocation failed - "
2923 "qla2x00_allocate_sp_pool()\n");
2925 qla2x00_mem_free(ha);
2926 set_current_state(TASK_UNINTERRUPTIBLE);
2927 schedule_timeout(HZ/10);
2932 /* Allocate memory for SNS commands */
2933 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2934 /* Get consistent memory allocated for SNS commands */
2935 ha->sns_cmd = pci_alloc_consistent(ha->pdev,
2936 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma);
2937 if (ha->sns_cmd == NULL) {
2939 qla_printk(KERN_WARNING, ha,
2940 "Memory Allocation failed - sns_cmd\n");
2942 qla2x00_mem_free(ha);
2943 set_current_state(TASK_UNINTERRUPTIBLE);
2944 schedule_timeout(HZ/10);
2948 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2950 /* Get consistent memory allocated for MS IOCB */
2951 ha->ms_iocb = pci_alloc_consistent(ha->pdev,
2952 sizeof(ms_iocb_entry_t), &ha->ms_iocb_dma);
2953 if (ha->ms_iocb == NULL) {
2955 qla_printk(KERN_WARNING, ha,
2956 "Memory Allocation failed - ms_iocb\n");
2958 qla2x00_mem_free(ha);
2959 set_current_state(TASK_UNINTERRUPTIBLE);
2960 schedule_timeout(HZ/10);
2964 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2967 * Get consistent memory allocated for CT SNS
2970 ha->ct_sns = pci_alloc_consistent(ha->pdev,
2971 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma);
2972 if (ha->ct_sns == NULL) {
2974 qla_printk(KERN_WARNING, ha,
2975 "Memory Allocation failed - ct_sns\n");
2977 qla2x00_mem_free(ha);
2978 set_current_state(TASK_UNINTERRUPTIBLE);
2979 schedule_timeout(HZ/10);
2983 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2986 /* Get consistent memory allocated for Get Port Database cmd */
2987 ha->iodesc_pd = pci_alloc_consistent(ha->pdev,
2988 PORT_DATABASE_SIZE, &ha->iodesc_pd_dma);
2989 if (ha->iodesc_pd == NULL) {
2991 qla_printk(KERN_WARNING, ha,
2992 "Memory Allocation failed - iodesc_pd\n");
2994 qla2x00_mem_free(ha);
2995 set_current_state(TASK_UNINTERRUPTIBLE);
2996 schedule_timeout(HZ/10);
3000 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
3002 /* Done all allocations without any error. */
3005 } while (retry-- && status != 0);
3009 "%s(): **** FAILED ****\n", __func__);
3017 * Frees all adapter allocated memory.
3020 * ha = adapter block pointer.
3023 qla2x00_mem_free(scsi_qla_host_t *ha)
3026 struct list_head *fcpl, *fcptemp;
3028 struct list_head *fcll, *fcltemp;
3030 unsigned long wtime;/* max wait time if mbx cmd is busy. */
3034 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
3038 /* Free the target queues */
3039 for (t = 0; t < MAX_TARGETS; t++) {
3040 qla2x00_tgt_free(ha, t);
3043 /* Make sure all other threads are stopped. */
3045 while (ha->dpc_wait && wtime) {
3046 set_current_state(TASK_INTERRUPTIBLE);
3047 wtime = schedule_timeout(wtime);
3050 /* free ioctl memory */
3051 qla2x00_free_ioctl_mem(ha);
3054 qla2x00_free_sp_pool(ha);
3056 if (ha->iodesc_pd) {
3057 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE,
3058 ha->iodesc_pd, ha->iodesc_pd_dma);
3062 pci_free_consistent(ha->pdev,
3063 sizeof(struct sns_cmd_pkt), ha->sns_cmd, ha->sns_cmd_dma);
3067 pci_free_consistent(ha->pdev,
3068 sizeof(struct ct_sns_pkt), ha->ct_sns, ha->ct_sns_dma);
3071 pci_free_consistent(ha->pdev,
3072 sizeof(ms_iocb_entry_t), ha->ms_iocb, ha->ms_iocb_dma);
3076 pci_free_consistent(ha->pdev,
3077 sizeof(init_cb_t), ha->init_cb, ha->init_cb_dma);
3080 if (ha->request_ring) {
3081 pci_free_consistent(ha->pdev,
3082 ((ha->request_q_length + 1) * (sizeof(request_t))),
3083 ha->request_ring, ha->request_dma);
3086 if (ha->response_ring) {
3087 pci_free_consistent(ha->pdev,
3088 ((ha->response_q_length + 1) * (sizeof(response_t))),
3089 ha->response_ring, ha->response_dma);
3092 ha->iodesc_pd = NULL;
3093 ha->iodesc_pd_dma = 0;
3098 ha->request_ring = NULL;
3099 ha->request_dma = 0;
3100 ha->response_ring = NULL;
3101 ha->response_dma = 0;
3103 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
3104 fcport = list_entry(fcpl, fc_port_t, list);
3107 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
3108 fclun = list_entry(fcll, fc_lun_t, list);
3110 list_del_init(&fclun->list);
3115 list_del_init(&fcport->list);
3118 INIT_LIST_HEAD(&ha->fcports);
3121 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
3125 if (ha->fw_dump_buffer) {
3126 vfree(ha->fw_dump_buffer);
3127 ha->fw_dump_reading = 0;
3128 ha->fw_dump_buffer = NULL;
3133 * qla2x00_allocate_sp_pool
3134 * This routine is called during initialization to allocate
3135 * memory for local srb_t.
3138 * ha = adapter block pointer.
3143 * Note: Sets the ref_count for non Null sp to one.
3146 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
3151 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3152 mempool_free_slab, srb_cachep);
3153 if (ha->srb_mempool == NULL) {
3154 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
3155 rval = QLA_FUNCTION_FAILED;
3161 * This routine frees all adapter allocated memory.
3165 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
3167 if (ha->srb_mempool) {
3168 mempool_destroy(ha->srb_mempool);
3169 ha->srb_mempool = NULL;
3173 /**************************************************************************
3175 * This kernel thread is a task that is schedule by the interrupt handler
3176 * to perform the background processing for interrupts.
3179 * This task always run in the context of a kernel thread. It
3180 * is kick-off by the driver's detect code and starts up
3181 * up one per adapter. It immediately goes to sleep and waits for
3182 * some fibre event. When either the interrupt handler or
3183 * the timer routine detects a event it will one of the task
3184 * bits then wake us up.
3185 **************************************************************************/
3187 qla2x00_do_dpc(void *data)
3189 DECLARE_MUTEX_LOCKED(sem);
3190 scsi_qla_host_t *ha;
3195 unsigned long flags = 0;
3196 struct list_head *list, *templist;
3197 int dead_cnt, online_cnt;
3199 uint16_t next_loopid;
3203 ha = (scsi_qla_host_t *)data;
3207 daemonize("%s_dpc", ha->host_str);
3208 allow_signal(SIGHUP);
3210 ha->dpc_wait = &sem;
3212 set_user_nice(current, -20);
3216 complete(&ha->dpc_inited);
3219 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3221 if (down_interruptible(&sem))
3224 if (ha->dpc_should_die)
3227 if (!list_empty(&ha->done_queue))
3230 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3232 /* Initialization not yet finished. Don't do anything yet. */
3233 if (!ha->flags.init_done || ha->dpc_active)
3236 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
3240 /* Process commands in retry queue */
3241 if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {
3242 DEBUG(printk("scsi(%ld): DPC checking retry_q. "
3244 ha->host_no, ha->retry_q_cnt));
3246 spin_lock_irqsave(&ha->list_lock, flags);
3247 dead_cnt = online_cnt = 0;
3248 list_for_each_safe(list, templist, &ha->retry_queue) {
3249 sp = list_entry(list, srb_t, list);
3251 DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "
3252 "spflags=0x%x, q_flag= 0x%lx\n",
3253 ha->host_no, sp->cmd->serial_number, sp,
3254 sp->flags, q->q_flag));
3258 fcport = q->fclun->fcport;
3260 if (atomic_read(&fcport->state) ==
3262 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3264 __del_from_retry_queue(ha, sp);
3265 sp->cmd->result = DID_NO_CONNECT << 16;
3266 if (atomic_read(&fcport->ha->loop_state) ==
3268 sp->err_id = SRB_ERR_LOOP;
3270 sp->err_id = SRB_ERR_PORT;
3271 sp->cmd->host_scribble =
3272 (unsigned char *) NULL;
3273 __add_to_done_queue(ha, sp);
3275 } else if (atomic_read(&fcport->state) !=
3278 __del_from_retry_queue(ha, sp);
3279 sp->cmd->result = DID_BUS_BUSY << 16;
3280 sp->cmd->host_scribble =
3281 (unsigned char *) NULL;
3282 __add_to_done_queue(ha, sp);
3285 } /* list_for_each_safe() */
3286 spin_unlock_irqrestore(&ha->list_lock, flags);
3288 DEBUG(printk("scsi(%ld): done processing retry queue "
3289 "- dead=%d, online=%d\n ",
3290 ha->host_no, dead_cnt, online_cnt));
3293 /* Process commands in scsi retry queue */
3294 if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {
3296 * Any requests we want to delay for some period is put
3297 * in the scsi retry queue with a delay added. The
3298 * timer will schedule a "scsi_restart_needed" every
3299 * second as long as there are requests in the scsi
3302 DEBUG(printk("scsi(%ld): DPC checking scsi "
3303 "retry_q.total=%d\n",
3304 ha->host_no, ha->scsi_retry_q_cnt));
3307 spin_lock_irqsave(&ha->list_lock, flags);
3308 list_for_each_safe(list, templist,
3309 &ha->scsi_retry_queue) {
3311 sp = list_entry(list, srb_t, list);
3315 DEBUG3(printk("scsi(%ld): scsi_retry_q: "
3316 "pid=%ld sp=%p, spflags=0x%x, "
3317 "q_flag= 0x%lx,q_state=%d\n",
3318 ha->host_no, sp->cmd->serial_number,
3319 sp, sp->flags, q->q_flag, q->q_state));
3321 /* Was this lun suspended */
3322 if (q->q_state != LUN_STATE_WAIT) {
3324 __del_from_scsi_retry_queue(ha, sp);
3326 if (test_bit(TQF_RETRY_CMDS,
3328 qla2x00_extend_timeout(sp->cmd,
3329 (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
3330 __add_to_pending_queue(ha, sp);
3333 __add_to_retry_queue(ha, sp);
3336 /* Was this command suspended for N secs */
3337 if (sp->delay != 0) {
3339 if (sp->delay == 0) {
3341 __del_from_scsi_retry_queue(
3343 __add_to_retry_queue(ha,sp);
3347 spin_unlock_irqrestore(&ha->list_lock, flags);
3349 /* Clear all Target Unsuspended bits */
3350 for (t = 0; t < ha->max_targets; t++) {
3351 if ((tq = ha->otgt[t]) == NULL)
3354 if (test_bit(TQF_RETRY_CMDS, &tq->flags))
3355 clear_bit(TQF_RETRY_CMDS, &tq->flags);
3360 DEBUG(if (online_cnt > 0))
3361 DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "
3363 ha->host_no, online_cnt));
3366 if (ha->flags.mbox_busy) {
3367 if (!list_empty(&ha->done_queue))
3374 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3376 DEBUG(printk("scsi(%ld): dpc: sched "
3377 "qla2x00_abort_isp ha = %p\n",
3379 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3382 if (qla2x00_abort_isp(ha)) {
3383 /* failed. retry later */
3384 set_bit(ISP_ABORT_NEEDED,
3387 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
3389 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3393 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
3394 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
3396 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3399 qla2x00_rst_aen(ha);
3400 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
3403 /* Retry each device up to login retry count */
3404 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3405 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
3406 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3408 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3412 list_for_each_entry(fcport, &ha->fcports, list) {
3413 if (fcport->port_type != FCT_TARGET)
3417 * If the port is not ONLINE then try to login
3418 * to it if we haven't run out of retries.
3420 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3421 fcport->login_retry) {
3423 fcport->login_retry--;
3424 if (fcport->flags & FCF_FABRIC_DEVICE)
3425 status = qla2x00_fabric_login(
3426 ha, fcport, &next_loopid);
3429 qla2x00_local_device_login(
3430 ha, fcport->loop_id);
3432 if (status == QLA_SUCCESS) {
3433 fcport->old_loop_id = fcport->loop_id;
3435 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
3436 ha->host_no, fcport->loop_id));
3438 fcport->port_login_retry_count =
3439 ha->port_down_retry_count * PORT_RETRY_TIME;
3440 atomic_set(&fcport->state, FCS_ONLINE);
3441 atomic_set(&fcport->port_down_timer,
3442 ha->port_down_retry_count * PORT_RETRY_TIME);
3444 fcport->login_retry = 0;
3445 } else if (status == 1) {
3446 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
3447 /* retry the login again */
3448 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
3450 fcport->login_retry, fcport->loop_id));
3452 fcport->login_retry = 0;
3455 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
3458 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3462 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
3463 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3465 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
3466 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
3469 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3471 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
3475 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
3477 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3480 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3483 qla2x00_loop_resync(ha);
3485 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3488 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3493 if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {
3494 DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",
3497 qla2x00_restart_queues(ha,FALSE);
3499 DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",
3503 if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {
3505 DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",
3508 qla2x00_abort_queues(ha, FALSE);
3510 DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",
3514 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
3516 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
3519 qla2x00_rescan_fcports(ha);
3521 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
3527 if (!ha->interrupts_on)
3528 qla2x00_enable_intrs(ha);
3530 if (!list_empty(&ha->done_queue))
3534 } /* End of while(1) */
3536 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
3539 * Make sure that nobody tries to wake us up again.
3541 ha->dpc_wait = NULL;
3544 complete_and_exit(&ha->dpc_exited, 0);
3548 * qla2x00_abort_queues
3549 * Abort all commands on queues on device
3552 * ha = adapter block pointer.
3555 * Interrupt context.
3558 qla2x00_abort_queues(scsi_qla_host_t *ha, uint8_t doneqflg)
3562 struct list_head *list, *temp;
3563 unsigned long flags;
3565 clear_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3567 /* Return all commands device queues. */
3568 spin_lock_irqsave(&ha->list_lock,flags);
3569 list_for_each_safe(list, temp, &ha->pending_queue) {
3570 sp = list_entry(list, srb_t, list);
3572 if (sp->flags & SRB_ABORTED)
3575 /* Remove srb from LUN queue. */
3576 __del_from_pending_queue(ha, sp);
3578 /* Set ending status. */
3579 sp->cmd->result = DID_BUS_BUSY << 16;
3581 __add_to_done_queue(ha, sp);
3583 spin_unlock_irqrestore(&ha->list_lock, flags);
3588 * Processes asynchronous reset.
3591 * ha = adapter block pointer.
3594 qla2x00_rst_aen(scsi_qla_host_t *ha)
3596 if (ha->flags.online && !ha->flags.reset_active &&
3597 !atomic_read(&ha->loop_down_timer) &&
3598 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
3600 /* 10/15 ha->flags.reset_active = TRUE; */
3602 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3605 * Issue marker command only when we are going to start
3608 ha->marker_needed = 1;
3609 } while (!atomic_read(&ha->loop_down_timer) &&
3610 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
3612 /* 10/15 ha->flags.reset_active = FALSE; */
3618 * This routine will allocate SP from the free queue
3625 qla2x00_get_new_sp(scsi_qla_host_t *ha)
3629 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
3631 atomic_set(&sp->ref_count, 1);
3637 /**************************************************************************
3641 * This function sets the colour of the LED while preserving the
3642 * unsued GPIO pins every sec.
3645 * ha - Host adapter structure
3650 * Context: qla2x00_timer() Interrupt
3651 ***************************************************************************/
3653 qla2x00_blink_led(scsi_qla_host_t *ha)
3655 uint16_t gpio_enable, gpio_data, led_color;
3656 unsigned long cpu_flags = 0;
3657 device_reg_t *reg = ha->iobase;
3659 /* Save the Original GPIOE */
3660 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3661 gpio_enable = RD_REG_WORD(®->gpioe);
3662 gpio_data = RD_REG_WORD(®->gpiod);
3663 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3665 DEBUG2(printk("%s Original data of gpio_enable_reg=0x%x"
3666 " gpio_data_reg=0x%x\n",
3667 __func__,gpio_enable,gpio_data));
3669 if (ha->beacon_green_on){
3670 led_color = GPIO_LED_GREEN_ON_AMBER_OFF;
3671 ha->beacon_green_on = 0;
3673 led_color = GPIO_LED_GREEN_OFF_AMBER_OFF;
3674 ha->beacon_green_on = 1;
3677 /* Set the modified gpio_enable values */
3678 gpio_enable |= GPIO_LED_GREEN_ON_AMBER_OFF;
3680 DEBUG2(printk("%s Before writing enable : gpio_enable_reg=0x%x"
3681 " gpio_data_reg=0x%x led_color=0x%x\n",
3682 __func__, gpio_enable, gpio_data, led_color));
3684 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3685 WRT_REG_WORD(®->gpioe,gpio_enable);
3686 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3688 /* Clear out the previously set LED colour */
3689 gpio_data &= ~GPIO_LED_GREEN_ON_AMBER_OFF;
3691 /* Set the new input LED colour to GPIOD */
3692 gpio_data |= led_color;
3694 DEBUG2(printk("%s Before writing data: gpio_enable_reg=0x%x"
3695 " gpio_data_reg=0x%x led_color=0x%x\n",
3696 __func__,gpio_enable,gpio_data,led_color));
3698 /* Set the modified gpio_data values */
3699 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3700 WRT_REG_WORD(®->gpiod,gpio_data);
3701 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3704 /**************************************************************************
3710 * Context: Interrupt
3711 ***************************************************************************/
3713 qla2x00_timer(scsi_qla_host_t *ha)
3716 unsigned long cpu_flags = 0;
3723 * We try and restart any request in the retry queue every second.
3725 if (!list_empty(&ha->retry_queue)) {
3726 set_bit(PORT_RESTART_NEEDED, &ha->dpc_flags);
3731 * We try and restart any request in the scsi_retry queue every second.
3733 if (!list_empty(&ha->scsi_retry_queue)) {
3734 set_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags);
3738 /* Check if beacon LED needs to be blinked */
3739 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && ha->beacon_blink_led)
3740 qla2x00_blink_led(ha);
3744 * Ports - Port down timer.
3746 * Whenever, a port is in the LOST state we start decrementing its port
3747 * down timer every second until it reaches zero. Once it reaches zero
3748 * the port it marked DEAD.
3751 list_for_each_entry(fcport, &ha->fcports, list) {
3752 if (fcport->port_type != FCT_TARGET)
3755 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3757 if (atomic_read(&fcport->port_down_timer) == 0)
3760 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3761 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3763 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3766 t, atomic_read(&fcport->port_down_timer)));
3769 } /* End of for fcport */
3772 * LUNS - lun suspend timer.
3774 * Whenever, a lun is suspended the timer starts decrementing its
3775 * suspend timer every second until it reaches zero. Once it reaches
3776 * zero the lun retry count is decremented.
3780 * FIXME(dg) - Need to convert this linear search of luns into a search
3781 * of a list of suspended luns.
3783 for (t = 0; t < ha->max_targets; t++) {
3784 if ((tq = ha->otgt[t]) == NULL)
3787 for (l = 0; l < ha->max_luns; l++) {
3788 if ((lq = (os_lun_t *) tq->olun[l]) == NULL)
3791 spin_lock_irqsave(&lq->q_lock, cpu_flags);
3792 if (lq->q_state == LUN_STATE_WAIT &&
3793 atomic_read(&lq->q_timer) != 0) {
3795 if (atomic_dec_and_test(&lq->q_timer) != 0) {
3797 * A delay should immediately
3798 * transition to a READY state
3800 if (test_and_clear_bit(LUN_EXEC_DELAYED,
3802 lq->q_state = LUN_STATE_READY;
3806 if (lq->q_count == lq->q_max)
3814 DEBUG3(printk("scsi(%ld): lun%d - timer %d, "
3815 "count=%d, max=%d, state=%d\n",
3818 atomic_read(&lq->q_timer),
3819 lq->q_count, lq->q_max, lq->q_state));
3821 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
3822 } /* End of for luns */
3823 } /* End of for targets */
3825 /* Loop down handler. */
3826 if (atomic_read(&ha->loop_down_timer) > 0 &&
3827 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
3829 /* dg 10/30 if (atomic_read(&ha->loop_down_timer) == LOOP_DOWN_TIME) { */
3830 if (atomic_read(&ha->loop_down_timer) ==
3831 ha->loop_down_abort_time) {
3833 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3834 "queues before time expire\n",
3837 if (!IS_QLA2100(ha) && ha->link_down_timeout)
3838 atomic_set(&ha->loop_state, LOOP_DEAD);
3840 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3844 /* if the loop has been down for 4 minutes, reinit adapter */
3845 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
3846 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
3847 "restarting queues.\n",
3850 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3853 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3854 DEBUG(printk("scsi(%ld): Loop down - "
3857 qla_printk(KERN_WARNING, ha,
3858 "Loop down - aborting ISP.\n");
3860 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3863 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
3865 atomic_read(&ha->loop_down_timer)));
3869 * Done Q Handler -- dgFIXME This handler will kick off doneq if we
3870 * haven't process it in 2 seconds.
3872 if (!list_empty(&ha->done_queue))
3876 /* Schedule the DPC routine if needed */
3877 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
3878 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
3880 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
3881 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3882 ha->dpc_wait && !ha->dpc_active) {
3887 qla2x00_restart_timer(ha, WATCH_INTERVAL);
3891 * qla2x00_extend_timeout
3892 * This routine will extend the timeout to the specified value.
3895 * cmd = SCSI command structure
3901 qla2x00_extend_timeout(struct scsi_cmnd *cmd, int timeout)
3903 srb_t *sp = (srb_t *) CMD_SP(cmd);
3904 u_long our_jiffies = (timeout * HZ) + jiffies;
3907 sp->e_start = jiffies;
3908 if (cmd->eh_timeout.function) {
3909 mod_timer(&cmd->eh_timeout,our_jiffies);
3910 sp->ext_history |= 1;
3912 if (sp->timer.function != NULL) {
3914 * Our internal timer should timeout before the midlayer has a
3915 * chance begin the abort process
3917 mod_timer(&sp->timer,our_jiffies - (QLA_CMD_TIMER_DELTA * HZ));
3919 sp->ext_history |= 2;
3923 /**************************************************************************
3924 * qla2x00_cmd_timeout
3927 * Handles the command if it times out in any state.
3930 * sp - pointer to validate
3934 * Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).
3935 **************************************************************************/
3937 qla2x00_cmd_timeout(srb_t *sp)
3941 scsi_qla_host_t *vis_ha, *dest_ha;
3942 struct scsi_cmnd *cmd;
3943 unsigned long flags, cpu_flags;
3947 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
3949 DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state));
3951 t = cmd->device->id;
3952 l = cmd->device->lun;
3953 fcport = sp->fclun->fcport;
3957 * If IO is found either in retry Queue
3959 * Return this IO back to host
3961 spin_lock_irqsave(&vis_ha->list_lock, flags);
3963 if (sp->state == SRB_PENDING_STATE) {
3964 __del_from_pending_queue(vis_ha, sp);
3965 DEBUG2(printk("scsi(%ld): Found in Pending queue pid %ld, "
3966 "State = %x., fcport state=%d jiffies=%lx\n",
3967 vis_ha->host_no, cmd->serial_number, sp->state,
3968 atomic_read(&fcport->state), jiffies));
3971 * If FC_DEVICE is marked as dead return the cmd with
3972 * DID_NO_CONNECT status. Otherwise set the host_byte to
3973 * DID_BUS_BUSY to let the OS retry this cmd.
3975 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
3976 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3977 cmd->result = DID_NO_CONNECT << 16;
3978 if (atomic_read(&fcport->ha->loop_state) == LOOP_DOWN)
3979 sp->err_id = SRB_ERR_LOOP;
3981 sp->err_id = SRB_ERR_PORT;
3983 cmd->result = DID_BUS_BUSY << 16;
3985 __add_to_done_queue(vis_ha, sp);
3988 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
3991 qla2x00_done(vis_ha);
3995 spin_lock_irqsave(&dest_ha->list_lock, flags);
3996 if ((sp->state == SRB_RETRY_STATE) ||
3997 (sp->state == SRB_SCSI_RETRY_STATE)) {
3999 DEBUG2(printk("scsi(%ld): Found in (Scsi) Retry queue or "
4000 "failover Q pid %ld, State = %x., fcport state=%d "
4001 "jiffies=%lx retried=%d\n",
4002 dest_ha->host_no, cmd->serial_number, sp->state,
4003 atomic_read(&fcport->state), jiffies, cmd->retries));
4005 if ((sp->state == SRB_RETRY_STATE)) {
4006 __del_from_retry_queue(dest_ha, sp);
4007 } else if ((sp->state == SRB_SCSI_RETRY_STATE)) {
4008 __del_from_scsi_retry_queue(dest_ha, sp);
4012 * If FC_DEVICE is marked as dead return the cmd with
4013 * DID_NO_CONNECT status. Otherwise set the host_byte to
4014 * DID_BUS_BUSY to let the OS retry this cmd.
4016 if ((atomic_read(&fcport->state) == FCS_DEVICE_DEAD) ||
4017 atomic_read(&dest_ha->loop_state) == LOOP_DEAD) {
4018 qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT);
4019 cmd->result = DID_NO_CONNECT << 16;
4020 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
4021 sp->err_id = SRB_ERR_LOOP;
4023 sp->err_id = SRB_ERR_PORT;
4025 cmd->result = DID_BUS_BUSY << 16;
4028 __add_to_done_queue(dest_ha, sp);
4031 spin_unlock_irqrestore(&dest_ha->list_lock, flags);
4034 qla2x00_done(dest_ha);
4039 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
4040 if (sp->state == SRB_DONE_STATE) {
4041 /* IO in done_q -- leave it */
4042 DEBUG(printk("scsi(%ld): Found in Done queue pid %ld sp=%p.\n",
4043 dest_ha->host_no, cmd->serial_number, sp));
4044 } else if (sp->state == SRB_SUSPENDED_STATE) {
4045 DEBUG(printk("scsi(%ld): Found SP %p in suspended state "
4047 dest_ha->host_no, sp, cmd->serial_number));
4048 DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));)
4049 } else if (sp->state == SRB_ACTIVE_STATE) {
4051 * IO is with ISP find the command in our active list.
4053 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4054 spin_lock_irqsave(&dest_ha->hardware_lock, flags);
4055 if (sp == dest_ha->outstanding_cmds[
4056 (unsigned long)sp->cmd->host_scribble]) {
4058 DEBUG(printk("cmd_timeout: Found in ISP \n"));
4060 if (sp->flags & SRB_TAPE) {
4062 * We cannot allow the midlayer error handler
4063 * to wakeup and begin the abort process.
4064 * Extend the timer so that the firmware can
4065 * properly return the IOCB.
4067 DEBUG(printk("cmd_timeout: Extending timeout "
4068 "of FCP2 tape command!\n"));
4069 qla2x00_extend_timeout(sp->cmd,
4070 EXTEND_CMD_TIMEOUT);
4072 sp->state = SRB_ACTIVE_TIMEOUT_STATE;
4073 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4075 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4077 "qla_cmd_timeout: State indicates it is with "
4078 "ISP, But not in active array\n");
4080 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
4081 } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) {
4082 DEBUG(printk("qla2100%ld: Found in Active timeout state"
4083 "pid %ld, State = %x., \n",
4085 sp->cmd->serial_number, sp->state);)
4088 DEBUG2(printk("cmd_timeout%ld: LOST command state = "
4090 vis_ha->host_no, sp->state,sp);)
4092 qla_printk(KERN_INFO, vis_ha,
4093 "cmd_timeout: LOST command state = 0x%x\n", sp->state);
4095 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4097 DEBUG3(printk("cmd_timeout: Leaving\n");)
4100 /**************************************************************************
4102 * Process completed commands.
4105 * old_ha = adapter block pointer.
4107 **************************************************************************/
4109 qla2x00_done(scsi_qla_host_t *old_ha)
4112 struct scsi_cmnd *cmd;
4113 unsigned long flags = 0;
4114 scsi_qla_host_t *ha;
4115 scsi_qla_host_t *vis_ha;
4116 int send_marker_once = 0;
4118 LIST_HEAD(local_sp_list);
4121 * Get into local queue such that we do not wind up calling done queue
4122 * tasklet for the same IOs from DPC or any other place.
4124 spin_lock_irqsave(&old_ha->list_lock, flags);
4125 list_splice_init(&old_ha->done_queue, &local_sp_list);
4126 spin_unlock_irqrestore(&old_ha->list_lock, flags);
4129 * All done commands are in the local queue, now do the call back.
4131 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4132 old_ha->done_q_cnt--;
4133 sp->state = SRB_NO_QUEUE_STATE;
4135 /* remove command from local list */
4136 list_del_init(&sp->list);
4142 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
4146 if (sp->flags & SRB_DMA_VALID) {
4147 sp->flags &= ~SRB_DMA_VALID;
4149 /* Release memory used for this I/O */
4151 pci_unmap_sg(ha->pdev, cmd->request_buffer,
4152 cmd->use_sg, cmd->sc_data_direction);
4153 } else if (cmd->request_bufflen) {
4154 pci_unmap_page(ha->pdev, sp->dma_handle,
4155 cmd->request_bufflen,
4156 cmd->sc_data_direction);
4161 switch (host_byte(cmd->result)) {
4168 * Set marker needed, so we don't have to
4169 * send multiple markers
4171 if (!send_marker_once) {
4172 ha->marker_needed = 1;
4179 * A backdoor device-reset requires different
4180 * error handling. This code differentiates
4181 * between normal error handling and the
4185 if (ha->host->eh_active != EH_ACTIVE)
4186 cmd->result = DID_BUS_BUSY << 16;
4191 sp->flags &= ~SRB_ABORT_PENDING;
4192 sp->flags |= SRB_ABORTED;
4194 if (sp->flags & SRB_TIMEOUT)
4195 cmd->result = DID_TIME_OUT << 16;
4200 DEBUG2(printk("scsi(%ld:%d:%d) %s: did_error "
4201 "= %d, comp-scsi= 0x%x-0x%x.\n",
4203 cmd->device->id, cmd->device->lun,
4205 host_byte(cmd->result),
4206 CMD_COMPL_STATUS(cmd),
4207 CMD_SCSI_STATUS(cmd)));
4212 * Call the mid-level driver interrupt handler -- via sp_put()
4215 } /* end of while */
4219 * qla2x00_process_response_queue_in_zio_mode
4220 * Process response queue completion as fast as possible
4221 * to achieve Zero Interrupt Opertions-ZIO
4224 * ha = adapter block pointer.
4230 qla2x00_process_response_queue_in_zio_mode(scsi_qla_host_t *ha)
4232 unsigned long flags;
4234 /* Check for unprocessed commands in response queue. */
4235 if (!ha->flags.process_response_queue)
4237 if (!ha->flags.online)
4239 if (ha->response_ring_ptr->signature == RESPONSE_PROCESSED)
4242 spin_lock_irqsave(&ha->hardware_lock,flags);
4243 qla2x00_process_response_queue(ha);
4244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4249 * Retrieve and process next job in the LUN queue.
4252 * tq = SCSI target queue pointer.
4253 * lq = SCSI LUN queue pointer.
4254 * TGT_LOCK must be already obtained.
4257 * Releases TGT_LOCK upon exit.
4260 * Kernel/Interrupt context.
4262 * Note: This routine will always try to start I/O from visible HBA.
4265 qla2x00_next(scsi_qla_host_t *vis_ha)
4268 unsigned long flags;
4269 scsi_qla_host_t *dest_ha;
4272 LIST_HEAD(local_sp_list);
4276 spin_lock_irqsave(&vis_ha->list_lock, flags);
4277 list_splice_init(&vis_ha->pending_queue, &local_sp_list);
4278 vis_ha->qthreads = 0;
4279 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
4281 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4282 list_del_init(&sp->list);
4283 sp->state = SRB_NO_QUEUE_STATE;
4285 fcport = sp->fclun->fcport;
4286 dest_ha = fcport->ha;
4288 /* If device is dead then send request back to OS */
4289 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
4290 sp->cmd->result = DID_NO_CONNECT << 16;
4291 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
4292 sp->err_id = SRB_ERR_LOOP;
4294 sp->err_id = SRB_ERR_PORT;
4296 DEBUG3(printk("scsi(%ld): loop/port is down - pid=%ld, "
4297 "sp=%p err_id=%d loopid=0x%x queued to dest HBA "
4298 "scsi%ld.\n", dest_ha->host_no,
4299 sp->cmd->serial_number, sp, sp->err_id,
4300 fcport->loop_id, dest_ha->host_no));
4302 * Initiate a failover - done routine will initiate.
4304 add_to_done_queue(vis_ha, sp);
4310 * SCSI Kluge: Whenever, we need to wait for an event such as
4311 * loop down (i.e. loop_down_timer ) or port down (i.e. LUN
4312 * request qeueue is suspended) then we will recycle new
4313 * commands back to the SCSI layer. We do this because this is
4314 * normally a temporary condition and we don't want the
4315 * mid-level scsi.c driver to get upset and start aborting
4316 * commands. The timeout value is extracted from the command
4317 * minus 1-second and put on a retry queue (watchdog). Once the
4318 * command timeout it is returned to the mid-level with a BUSY
4319 * status, so the mid-level will retry it. This process
4320 * continues until the LOOP DOWN time expires or the condition
4323 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4324 (atomic_read(&fcport->state) != FCS_ONLINE ||
4325 test_bit(ABORT_ISP_ACTIVE, &dest_ha->dpc_flags) ||
4326 atomic_read(&dest_ha->loop_state) != LOOP_READY)) {
4328 DEBUG3(printk("scsi(%ld): port=(0x%x) retry_q(%d) "
4329 "loop state = %d, loop counter = 0x%x dpc flags "
4333 atomic_read(&fcport->state),
4334 atomic_read(&dest_ha->loop_state),
4335 atomic_read(&dest_ha->loop_down_timer),
4336 dest_ha->dpc_flags));
4338 qla2x00_extend_timeout(sp->cmd, EXTEND_CMD_TIMEOUT);
4339 add_to_retry_queue(vis_ha, sp);
4345 * If this request's lun is suspended then put the request on
4346 * the scsi_retry queue.
4348 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4349 sp->lun_queue->q_state == LUN_STATE_WAIT) {
4350 DEBUG3(printk("scsi(%ld): lun wait state - pid=%ld, "
4351 "opcode=%d, allowed=%d, retries=%d\n",
4353 sp->cmd->serial_number,
4358 add_to_scsi_retry_queue(vis_ha, sp);
4363 sp->lun_queue->io_cnt++;
4365 rval = qla2x00_start_scsi(sp);
4366 if (rval != QLA_SUCCESS) {
4367 /* Place request back on top of device queue */
4368 /* add to the top of queue */
4369 add_to_pending_queue_head(vis_ha, sp);
4371 sp->lun_queue->io_cnt--;
4375 if (!IS_QLA2100(vis_ha) && !IS_QLA2200(vis_ha)) {
4376 /* Process response_queue if ZIO support is enabled*/
4377 qla2x00_process_response_queue_in_zio_mode(vis_ha);
4383 /**************************************************************************
4384 * qla2x00_check_tgt_status
4387 * Checks to see if the target or loop is down.
4390 * cmd - pointer to Scsi cmd structure
4393 * 1 - if target is present
4394 * 0 - if target is not present
4396 **************************************************************************/
4398 qla2x00_check_tgt_status(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
4401 unsigned int b, t, l;
4404 /* Generate LU queue on bus, target, LUN */
4405 b = cmd->device->channel;
4406 t = cmd->device->id;
4407 l = cmd->device->lun;
4409 if ((lq = GET_LU_Q(ha,t,l)) == NULL) {
4410 return (QLA_FUNCTION_FAILED);
4413 fcport = lq->fclun->fcport;
4415 if (TGT_Q(ha, t) == NULL ||
4416 l >= ha->max_luns ||
4417 atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4418 atomic_read(&ha->loop_state) == LOOP_DEAD ||
4419 (!atomic_read(&ha->loop_down_timer) &&
4420 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4421 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
4422 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4423 atomic_read(&ha->loop_state) != LOOP_READY) {
4425 DEBUG(printk(KERN_INFO
4426 "scsi(%ld:%2d:%2d:%2d): %s connection is down\n",
4431 cmd->result = DID_NO_CONNECT << 16;
4432 return (QLA_FUNCTION_FAILED);
4434 return (QLA_SUCCESS);
4437 /**************************************************************************
4438 * qla2x00_check_port_status
4441 * Checks to see if the port or loop is down.
4444 * fcport - pointer to fc_port_t structure.
4447 * 1 - if port is present
4448 * 0 - if port is not present
4450 **************************************************************************/
4452 qla2x00_check_port_status(scsi_qla_host_t *ha, fc_port_t *fcport)
4454 if (fcport == NULL) {
4455 return (QLA_FUNCTION_FAILED);
4458 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4459 atomic_read(&ha->loop_state) == LOOP_DEAD) {
4460 return (QLA_FUNCTION_FAILED);
4463 if ((atomic_read(&fcport->state) != FCS_ONLINE) ||
4464 (!atomic_read(&ha->loop_down_timer) &&
4465 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4466 (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) ||
4467 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
4468 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4469 atomic_read(&ha->loop_state) != LOOP_READY) {
4471 DEBUG(printk(KERN_INFO
4472 "scsi(%ld): Connection is down. fcport=%p.\n",
4473 ha->host_no, fcport));
4478 return (QLA_SUCCESS);
4481 /* XXX(hch): crude hack to emulate a down_timeout() */
4483 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
4485 const unsigned int step = HZ/10;
4488 if (!down_trylock(sema))
4490 set_current_state(TASK_INTERRUPTIBLE);
4491 if (schedule_timeout(step))
4493 } while ((timeout -= step) > 0);
4499 qla2xxx_get_port_id(struct scsi_device *sdev)
4501 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4504 list_for_each_entry(fc, &ha->fcports, list) {
4505 if (fc->os_target_id == sdev->id) {
4506 fc_port_id(sdev) = fc->d_id.b.domain << 16 |
4507 fc->d_id.b.area << 8 |
4512 fc_port_id(sdev) = -1;
4516 qla2xxx_get_port_name(struct scsi_device *sdev)
4518 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4521 list_for_each_entry(fc, &ha->fcports, list) {
4522 if (fc->os_target_id == sdev->id) {
4523 fc_port_name(sdev) =
4524 __be64_to_cpu(*(uint64_t *)fc->port_name);
4528 fc_port_name(sdev) = -1;
4532 qla2xxx_get_node_name(struct scsi_device *sdev)
4534 scsi_qla_host_t *ha = to_qla_host(sdev->host);
4537 list_for_each_entry(fc, &ha->fcports, list) {
4538 if (fc->os_target_id == sdev->id) {
4539 fc_node_name(sdev) =
4540 __be64_to_cpu(*(uint64_t *)fc->node_name);
4544 fc_node_name(sdev) = -1;
4547 static struct fc_function_template qla2xxx_transport_functions = {
4548 .get_port_id = qla2xxx_get_port_id,
4550 .get_port_name = qla2xxx_get_port_name,
4551 .show_port_name = 1,
4552 .get_node_name = qla2xxx_get_node_name,
4553 .show_node_name = 1,
4557 * qla2x00_module_init - Module initialization.
4560 qla2x00_module_init(void)
4562 /* Allocate cache for SRBs. */
4563 sprintf(srb_cachep_name, "qla2xxx_srbs");
4564 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
4565 SLAB_HWCACHE_ALIGN, NULL, NULL);
4566 if (srb_cachep == NULL) {
4568 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4572 /* Derive version string. */
4573 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4575 strcat(qla2x00_version_str, "-debug");
4578 qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions);
4579 if (!qla2xxx_transport_template)
4583 "QLogic Fibre Channel HBA Driver (%p)\n", qla2x00_set_info);
4589 * qla2x00_module_exit - Module cleanup.
4592 qla2x00_module_exit(void)
4594 /* Free SRBs cache. */
4595 if (srb_cachep != NULL) {
4596 if (kmem_cache_destroy(srb_cachep) != 0) {
4598 "qla2xxx: Unable to free SRB cache...Memory pools "
4604 fc_release_transport(qla2xxx_transport_template);
4607 module_init(qla2x00_module_init);
4608 module_exit(qla2x00_module_exit);
4610 MODULE_AUTHOR("QLogic Corporation");
4611 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4612 MODULE_LICENSE("GPL");