2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003 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.");
114 * Proc structures and functions
123 static void copy_mem_info(struct info_str *, char *, int);
124 static int copy_info(struct info_str *, char *, ...);
128 * List of host adapters
130 LIST_HEAD(qla_hostlist);
131 rwlock_t qla_hostlist_lock = RW_LOCK_UNLOCKED;
133 static void qla2x00_free_device(scsi_qla_host_t *);
135 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
138 * SCSI host template entry points
140 static int qla2xxx_slave_configure(struct scsi_device * device);
141 static int qla2xxx_eh_abort(struct scsi_cmnd *);
142 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
143 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
144 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
145 static uint8_t qla2x00_loop_reset(scsi_qla_host_t *ha);
146 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
148 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
151 static struct scsi_host_template qla2x00_driver_template = {
152 .module = THIS_MODULE,
154 .proc_name = "qla2xxx",
155 .proc_info = qla2x00_proc_info,
156 .queuecommand = qla2x00_queuecommand,
158 .eh_abort_handler = qla2xxx_eh_abort,
159 .eh_device_reset_handler = qla2xxx_eh_device_reset,
160 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
161 .eh_host_reset_handler = qla2xxx_eh_host_reset,
163 .slave_configure = qla2xxx_slave_configure,
166 .can_queue = REQUEST_ENTRY_CNT+128,
168 .use_clustering = ENABLE_CLUSTERING,
169 .sg_tablesize = SG_ALL,
172 * The RISC allows for each command to transfer (2^32-1) bytes of data,
173 * which equates to 0x800000 sectors.
175 .max_sectors = 0xFFFF,
178 static void qla2x00_display_fc_names(scsi_qla_host_t *);
180 void qla2x00_blink_led(scsi_qla_host_t *);
182 /* TODO Convert to inlines
186 #define WATCH_INTERVAL 1 /* number of seconds */
188 static void qla2x00_timer(scsi_qla_host_t *);
190 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
191 void *, unsigned long);
192 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
193 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
196 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
198 init_timer(&ha->timer);
199 ha->timer.expires = jiffies + interval * HZ;
200 ha->timer.data = (unsigned long)ha;
201 ha->timer.function = (void (*)(unsigned long))func;
202 add_timer(&ha->timer);
203 ha->timer_active = 1;
207 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
209 mod_timer(&ha->timer, jiffies + interval * HZ);
212 static __inline__ void
213 qla2x00_stop_timer(scsi_qla_host_t *ha)
215 del_timer_sync(&ha->timer);
216 ha->timer_active = 0;
220 static void qla2x00_cmd_timeout(srb_t *sp);
221 static __inline__ void qla2x00_add_timer_to_cmd(srb_t *sp, int timeout);
222 static __inline__ void qla2x00_delete_timer_from_cmd(srb_t *sp);
224 /**************************************************************************
225 * qla2x00_add_timer_to_cmd
228 * Creates a timer for the specified command. The timeout is usually
229 * the command time from kernel minus 2 secs.
232 * sp - pointer to validate
236 **************************************************************************/
238 qla2x00_add_timer_to_cmd(srb_t *sp, int timeout)
240 init_timer(&sp->timer);
241 sp->timer.expires = jiffies + timeout * HZ;
242 sp->timer.data = (unsigned long) sp;
243 sp->timer.function = (void (*) (unsigned long))qla2x00_cmd_timeout;
244 add_timer(&sp->timer);
247 /**************************************************************************
248 * qla2x00_delete_timer_from_cmd
251 * Delete the timer for the specified command.
254 * sp - pointer to validate
258 **************************************************************************/
260 qla2x00_delete_timer_from_cmd(srb_t *sp)
262 if (sp->timer.function != NULL) {
263 del_timer(&sp->timer);
264 sp->timer.function = NULL;
265 sp->timer.data = (unsigned long) NULL;
269 static __inline__ void qla2x00_callback(scsi_qla_host_t *, struct scsi_cmnd *);
270 static __inline__ void sp_put(struct scsi_qla_host * ha, srb_t *sp);
271 static __inline__ void sp_get(struct scsi_qla_host * ha, srb_t *sp);
272 static __inline__ void
273 qla2x00_delete_from_done_queue(scsi_qla_host_t *, srb_t *);
275 /**************************************************************************
279 * Decrement reference count and call the callback if we're the last
280 * owner of the specified sp. Will get the host_lock before calling
284 * ha - pointer to the scsi_qla_host_t where the callback is to occur.
285 * sp - pointer to srb_t structure to use.
289 **************************************************************************/
291 sp_put(struct scsi_qla_host * ha, srb_t *sp)
293 if (atomic_read(&sp->ref_count) == 0) {
294 qla_printk(KERN_INFO, ha,
295 "%s(): **** SP->ref_count not zero\n",
302 if (!atomic_dec_and_test(&sp->ref_count)) {
306 qla2x00_callback(ha, sp->cmd);
309 /**************************************************************************
313 * Increment reference count of the specified sp.
316 * sp - pointer to srb_t structure to use.
320 **************************************************************************/
322 sp_get(struct scsi_qla_host * ha, srb_t *sp)
324 atomic_inc(&sp->ref_count);
326 if (atomic_read(&sp->ref_count) > 2) {
327 qla_printk(KERN_INFO, ha,
328 "%s(): **** SP->ref_count greater than two\n",
338 * Returns the completed SCSI command to LINUX.
341 * ha -- Host adapter structure
342 * cmd -- SCSI mid-level command structure.
345 * Note:From failover point of view we always get the sp
346 * from vis_ha pool in queuecommand.So when we put it
347 * back to the pool it has to be the vis_ha.
348 * So rely on struct scsi_cmnd to get the vis_ha and not on sp.
351 qla2x00_callback(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
353 srb_t *sp = (srb_t *) CMD_SP(cmd);
354 scsi_qla_host_t *vis_ha;
357 unsigned long cpu_flags = 0;
359 cmd->host_scribble = (unsigned char *) NULL;
360 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
363 qla_printk(KERN_INFO, ha,
364 "%s(): **** CMD derives a NULL SP\n",
371 * If command status is not DID_BUS_BUSY then go ahead and freed sp.
374 * Cancel command timeout
376 qla2x00_delete_timer_from_cmd(sp);
379 * Put SP back in the free queue
384 got_sense = (sp->flags & SRB_GOT_SENSE)? 1: 0;
385 add_to_free_queue(vis_ha, sp);
387 if (host_byte(cmd->result) == DID_OK) {
389 ha->total_bytes += cmd->bufflen;
391 /* If lun was suspended then clear retry count */
392 spin_lock_irqsave(&lq->q_lock, cpu_flags);
393 if (!test_bit(LUN_EXEC_DELAYED, &lq->q_flag))
394 lq->q_state = LUN_STATE_READY;
395 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
397 } else if (host_byte(cmd->result) == DID_ERROR) {
399 ha->total_dev_errs++;
402 /* Call the mid-level driver interrupt handler */
403 (*(cmd)->scsi_done)(cmd);
407 qla2x00_delete_from_done_queue(scsi_qla_host_t *dest_ha, srb_t *sp)
409 /* remove command from done list */
410 list_del_init(&sp->list);
411 dest_ha->done_q_cnt--;
412 sp->state = SRB_NO_QUEUE_STATE;
414 if (sp->flags & SRB_DMA_VALID) {
415 sp->flags &= ~SRB_DMA_VALID;
417 /* Release memory used for this I/O */
418 if (sp->cmd->use_sg) {
419 pci_unmap_sg(dest_ha->pdev, sp->cmd->request_buffer,
420 sp->cmd->use_sg, sp->cmd->sc_data_direction);
421 } else if (sp->cmd->request_bufflen) {
422 pci_unmap_page(dest_ha->pdev, sp->dma_handle,
423 sp->cmd->request_bufflen,
424 sp->cmd->sc_data_direction);
429 static int qla2x00_do_dpc(void *data);
431 static void qla2x00_rst_aen(scsi_qla_host_t *);
433 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
434 static void qla2x00_mem_free(scsi_qla_host_t *ha);
435 int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
436 void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
438 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
440 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
442 static struct bin_attribute sysfs_fw_dump_attr = {
445 .mode = S_IRUSR | S_IWUSR,
448 .read = qla2x00_sysfs_read_fw_dump,
449 .write = qla2x00_sysfs_write_fw_dump,
451 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
453 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
455 static struct bin_attribute sysfs_nvram_attr = {
458 .mode = S_IRUSR | S_IWUSR,
460 .size = sizeof(nvram_t),
461 .read = qla2x00_sysfs_read_nvram,
462 .write = qla2x00_sysfs_write_nvram,
467 qla2x00_set_info(char *buffer, int length, struct Scsi_Host *shost)
469 return (-ENOSYS); /* Currently this is a no-op */
472 /* -------------------------------------------------------------------------- */
475 /* SysFS attributes. */
476 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
477 loff_t off, size_t count)
479 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
480 struct device, kobj)));
482 if (ha->fw_dump_reading == 0)
484 if (off > ha->fw_dump_buffer_len)
486 if (off + count > ha->fw_dump_buffer_len)
487 count = ha->fw_dump_buffer_len - off;
489 memcpy(buf, &ha->fw_dump_buffer[off], count);
494 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
495 loff_t off, size_t count)
497 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
498 struct device, kobj)));
504 reading = simple_strtol(buf, NULL, 10);
507 if (ha->fw_dump_reading == 1) {
508 qla_printk(KERN_INFO, ha,
509 "Firmware dump cleared on (%ld).\n",
512 vfree(ha->fw_dump_buffer);
513 free_pages((unsigned long)ha->fw_dump,
516 ha->fw_dump_reading = 0;
517 ha->fw_dump_buffer = NULL;
522 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
523 ha->fw_dump_reading = 1;
525 ha->fw_dump_buffer = (char *)vmalloc(FW_DUMP_SIZE);
526 if (ha->fw_dump_buffer == NULL) {
527 qla_printk(KERN_WARNING, ha,
528 "Unable to allocate memory for firmware "
529 "dump buffer (%d).\n", FW_DUMP_SIZE);
531 ha->fw_dump_reading = 0;
534 qla_printk(KERN_INFO, ha,
535 "Firmware dump ready for read on (%ld).\n",
537 memset(ha->fw_dump_buffer, 0, FW_DUMP_SIZE);
538 if (IS_QLA2100(ha) || IS_QLA2200(ha))
539 qla2100_ascii_fw_dump(ha);
541 qla2300_ascii_fw_dump(ha);
542 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
549 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
550 loff_t off, size_t count)
552 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
553 struct device, kobj)));
558 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
562 spin_lock_irqsave(&ha->hardware_lock, flags);
563 qla2x00_lock_nvram_access(ha);
564 witer = (uint16_t *)buf;
565 for (cnt = 0; cnt < count / 2; cnt++) {
566 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
567 cnt+ha->nvram_base));
570 qla2x00_unlock_nvram_access(ha);
571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
576 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
577 loff_t off, size_t count)
579 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
580 struct device, kobj)));
587 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
590 /* Checksum NVRAM. */
591 iter = (uint8_t *)buf;
593 for (cnt = 0; cnt < count - 1; cnt++)
595 chksum = ~chksum + 1;
599 spin_lock_irqsave(&ha->hardware_lock, flags);
600 qla2x00_lock_nvram_access(ha);
601 witer = (uint16_t *)buf;
602 for (cnt = 0; cnt < count / 2; cnt++) {
603 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
604 cpu_to_le16(*witer));
607 qla2x00_unlock_nvram_access(ha);
608 spin_unlock_irqrestore(&ha->hardware_lock, flags);
613 /* -------------------------------------------------------------------------- */
615 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
617 static char *pci_bus_modes[] = {
618 "33", "66", "100", "133",
623 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
626 strcat(str, pci_bus_modes[pci_bus]);
628 pci_bus = (ha->pci_attr & BIT_8) >> 8;
630 strcat(str, pci_bus_modes[pci_bus]);
632 strcat(str, " MHz)");
638 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
642 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
643 ha->fw_minor_version,
644 ha->fw_subminor_version);
646 if (ha->fw_attributes & BIT_9) {
651 switch (ha->fw_attributes & 0xFF) {
665 sprintf(un_str, "(%x)", ha->fw_attributes);
669 if (ha->fw_attributes & 0x100)
675 /**************************************************************************
676 * qla2x00_queuecommand
679 * Queue a command to the controller.
682 * cmd - pointer to Scsi cmd structure
683 * fn - pointer to Scsi done function
689 * The mid-level driver tries to ensures that queuecommand never gets invoked
690 * concurrently with itself or the interrupt handler (although the
691 * interrupt handler may call this routine as part of request-completion
693 **************************************************************************/
695 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
700 scsi_qla_host_t *ha, *ha2;
702 struct Scsi_Host *host;
703 unsigned int b, t, l;
704 unsigned long handle;
708 host = cmd->device->host;
709 ha = (scsi_qla_host_t *) host->hostdata;
713 spin_unlock_irq(ha->host->host_lock);
716 * Allocate a command packet from the "sp" pool. If we cant get back
717 * one then let scsi layer come back later.
719 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
720 qla_printk(KERN_WARNING, ha,
721 "Couldn't allocate memory for sp - retried.\n");
723 spin_lock_irq(ha->host->host_lock);
729 CMD_SP(cmd) = (void *)sp;
732 if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {
733 /* Need to set sp->flags */
734 sp->flags |= SRB_IOCTL;
735 CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */
738 sp->fo_retry_cnt = 0;
740 /* Generate LU queue on bus, target, LUN */
741 b = cmd->device->channel;
743 l = cmd->device->lun;
746 * Start Command Timer. Typically it will be 2 seconds less than what
747 * is requested by the Host such that we can return the IO before
750 if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)
751 qla2x00_add_timer_to_cmd(sp,
752 (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
754 qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);
756 if (l >= ha->max_luns) {
757 cmd->result = DID_NO_CONNECT << 16;
759 spin_lock_irq(ha->host->host_lock);
766 if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&
767 (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {
768 fcport = lq->fclun->fcport;
776 /* Set an invalid handle until we issue the command to ISP */
777 /* then we will set the real handle value. */
778 handle = INVALID_HANDLE;
779 cmd->host_scribble = (unsigned char *)handle;
781 /* Bookkeeping information */
782 sp->r_start = jiffies; /* time the request was recieved */
785 /* Setup device queue pointers. */
792 * 1. When device is added from persistent binding but has not been
793 * discovered yet.The state of loopid == PORT_AVAIL.
794 * 2. When device is never found on the bus.(loopid == UNUSED)
796 * IF Device Queue is not created, or device is not in a valid state
797 * and link down error reporting is enabled, reject IO.
799 if (fcport == NULL) {
800 DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",
803 cmd->result = DID_NO_CONNECT << 16;
805 spin_lock_irq(ha->host->host_lock);
812 /* Only modify the allowed count if the target is a *non* tape device */
813 if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {
814 if (cmd->allowed < ql2xretrycount) {
815 cmd->allowed = ql2xretrycount;
819 DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "
820 "flags=0x%x fo retry=%d, pid=%ld\n",
821 ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,
822 cmd->serial_number));
823 DEBUG5(qla2x00_print_scsi_cmd(cmd));
825 sp->fclun = lq->fclun;
828 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&
829 cmd->request_bufflen != 0) {
831 DEBUG2(printk(KERN_WARNING
832 "scsi(%ld): Incorrect data direction - transfer "
833 "length=%d, direction=%d, pid=%ld, opcode=%x\n",
834 ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,
835 cmd->serial_number, cmd->cmnd[0]));
840 * Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.
842 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
843 atomic_read(&ha->loop_state) == LOOP_DEAD) {
845 * Add the command to the done-queue for later failover
848 cmd->result = DID_NO_CONNECT << 16;
849 add_to_done_queue(ha, sp);
850 if (!list_empty(&ha->done_queue))
853 spin_lock_irq(ha->host->host_lock);
856 was_empty = add_to_pending_queue(ha, sp);
858 if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {
863 if (RD_REG_WORD(ISP_RSP_Q_IN(ha, reg)) != ha->rsp_ring_index) {
864 spin_lock_irqsave(&ha->hardware_lock, flags);
865 qla2x00_process_response_queue(ha);
866 spin_unlock_irqrestore(&ha->hardware_lock, flags);
870 /* We submit to the hardware if:
872 * 1) we're on the cpu the irq's arrive on or
873 * 2) there are very few io's outstanding.
875 * In all other cases we'll let an irq pick up our IO and submit it
876 * to the controller to improve affinity.
878 if (smp_processor_id() == ha->last_irq_cpu || was_empty)
881 spin_lock_irq(ha->host->host_lock);
887 * qla2x00_eh_wait_on_command
888 * Waits for the command to be returned by the Firmware for some
892 * ha = actual ha whose done queue will contain the command
893 * returned by firmware.
894 * cmd = Scsi Command to wait on.
895 * flag = Abort/Reset(Bus or Device Reset)
902 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
904 #define ABORT_WAIT_TIME 10 /* seconds */
909 struct list_head *list, *temp;
910 u_long cpu_flags = 0;
911 u_long max_wait_time = ABORT_WAIT_TIME;
914 /* Check on done queue */
916 spin_lock_irqsave(&ha->list_lock, cpu_flags);
917 list_for_each_safe(list, temp, &ha->done_queue) {
918 rp = list_entry(list, srb_t, list);
921 * Found command. Just exit and wait for the
924 if (cmd == rp->cmd) {
926 DEBUG3(printk("%s: found in done "
927 "queue.\n", __func__);)
931 spin_unlock_irqrestore(&ha->list_lock, cpu_flags);
934 /* Checking to see if its returned to OS */
935 rp = (srb_t *) CMD_SP(cmd);
941 spin_unlock_irq(ha->host->host_lock);
943 set_current_state(TASK_INTERRUPTIBLE);
944 schedule_timeout(2*HZ);
946 spin_lock_irq(ha->host->host_lock);
948 } while ((max_wait_time--));
951 DEBUG2(printk(KERN_INFO "%s: found cmd=%p.\n", __func__, cmd));
953 /* Immediately return command to the mid-layer */
954 qla2x00_delete_from_done_queue(ha, rp);
963 * qla2x00_wait_for_hba_online
964 * Wait till the HBA is online after going through
965 * <= MAX_RETRIES_OF_ISP_ABORT or
966 * finally HBA is disabled ie marked offline
969 * ha - pointer to host adapter structure
972 * Does context switching-Release SPIN_LOCK
973 * (if any) before calling this routine.
976 * Success (Adapter is online) : 0
977 * Failed (Adapter is offline/disabled) : 1
980 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
983 unsigned long wait_online;
985 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
986 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
987 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
988 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) &&
989 time_before(jiffies, wait_online)) {
991 set_current_state(TASK_INTERRUPTIBLE);
992 schedule_timeout(HZ);
994 if (ha->flags.online == TRUE)
995 return_status = QLA_SUCCESS;
997 /* Adapter is disabled/offline */
998 return_status = QLA_FUNCTION_FAILED;
1000 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
1002 return (return_status);
1006 * qla2x00_wait_for_loop_ready
1007 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
1008 * to be in LOOP_READY state.
1010 * ha - pointer to host adapter structure
1013 * Does context switching-Release SPIN_LOCK
1014 * (if any) before calling this routine.
1018 * Success (LOOP_READY) : 0
1019 * Failed (LOOP_NOT_READY) : 1
1022 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
1024 int return_status = QLA_SUCCESS;
1025 unsigned long loop_timeout ;
1027 /* wait for 5 min at the max for loop to be ready */
1028 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1030 while ((!atomic_read(&ha->loop_down_timer) &&
1031 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
1032 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
1033 atomic_read(&ha->loop_state) != LOOP_READY) {
1034 set_current_state(TASK_INTERRUPTIBLE);
1035 schedule_timeout(HZ);
1036 if (time_after_eq(jiffies, loop_timeout)) {
1037 return_status = QLA_FUNCTION_FAILED;
1041 return (return_status);
1044 /**************************************************************************
1048 * The abort function will abort the specified command.
1051 * cmd = Linux SCSI command packet to be aborted.
1054 * Either SUCCESS or FAILED.
1057 **************************************************************************/
1059 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1062 int return_status = FAILED;
1064 scsi_qla_host_t *ha;
1065 scsi_qla_host_t *vis_ha;
1068 struct list_head *list, *temp;
1069 struct Scsi_Host *host;
1071 unsigned int b, t, l;
1072 unsigned long flags;
1074 /* Get the SCSI request ptr */
1075 sp = (srb_t *) CMD_SP(cmd);
1078 * If sp is NULL, command is already returned.
1079 * sp is NULLED just before we call back scsi_done
1083 /* no action - we don't have command */
1084 qla_printk(KERN_INFO, to_qla_host(cmd->device->host),
1085 "qla2xxx_eh_abort: cmd already done sp=%p\n", sp);
1086 DEBUG(printk("qla2xxx_eh_abort: cmd already done sp=%p\n", sp);)
1090 DEBUG(printk("qla2xxx_eh_abort: refcount %i \n",
1091 atomic_read(&sp->ref_count));)
1094 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1095 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1099 /* Generate LU queue on bus, target, LUN */
1100 b = cmd->device->channel;
1101 t = cmd->device->id;
1102 l = cmd->device->lun;
1103 q = GET_LU_Q(vis_ha, t, l);
1105 qla_printk(KERN_INFO, ha,
1106 "%s scsi(%ld:%d:%d:%d): cmd_timeout_in_sec=0x%x.\n", __func__,
1107 ha->host_no, (int)b, (int)t, (int)l,
1108 cmd->timeout_per_command / HZ);
1111 * if no LUN queue then something is very wrong!!!
1114 qla_printk(KERN_WARNING, ha,
1115 "qla2x00: (%x:%x:%x) No LUN queue.\n", b, t, l);
1117 /* no action - we don't have command */
1121 DEBUG2(printk("scsi(%ld): ABORTing cmd=%p sp=%p jiffies = 0x%lx, "
1122 "timeout=%x, dpc_flags=%lx, vis_ha->dpc_flags=%lx q->flag=%lx\n",
1123 ha->host_no, cmd, sp, jiffies, cmd->timeout_per_command / HZ,
1124 ha->dpc_flags, vis_ha->dpc_flags, q->q_flag));
1125 DEBUG2(qla2x00_print_scsi_cmd(cmd));
1127 spin_unlock_irq(ha->host->host_lock);
1128 /* Blocking call-Does context switching if abort isp is active etc */
1129 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1130 DEBUG2(printk("%s failed:board disabled\n", __func__);)
1131 spin_lock_irq(ha->host->host_lock);
1134 spin_lock_irq(ha->host->host_lock);
1136 /* Search done queue */
1137 spin_lock_irqsave(&ha->list_lock,flags);
1138 list_for_each_safe(list, temp, &ha->done_queue) {
1139 rp = list_entry(list, srb_t, list);
1145 * Found command.Remove it from done list.
1146 * And proceed to post completion to scsi mid layer.
1148 return_status = SUCCESS;
1150 qla2x00_delete_from_done_queue(ha, sp);
1153 } /* list_for_each_safe() */
1154 spin_unlock_irqrestore(&ha->list_lock, flags);
1157 * Return immediately if the aborted command was already in the done
1161 qla_printk(KERN_INFO, ha,
1162 "qla2xxx_eh_abort: Returning completed command=%p sp=%p\n",
1165 return (return_status);
1170 * See if this command is in the retry queue
1172 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p in retry "
1175 spin_lock_irqsave(&ha->list_lock, flags);
1176 list_for_each_safe(list, temp, &ha->retry_queue) {
1177 rp = list_entry(list, srb_t, list);
1183 DEBUG2(printk("qla2xxx_eh_abort: found "
1184 "in retry queue. SP=%p\n", sp);)
1186 __del_from_retry_queue(ha, rp);
1187 cmd->result = DID_ABORT << 16;
1188 __add_to_done_queue(ha, rp);
1190 return_status = SUCCESS;
1196 spin_unlock_irqrestore(&ha->list_lock, flags);
1200 * Our SP pointer points at the command we want to remove from the
1201 * pending queue providing we haven't already sent it to the adapter.
1204 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1205 "in pending queue.\n", sp);)
1207 spin_lock_irqsave(&vis_ha->list_lock, flags);
1208 list_for_each_safe(list, temp, &vis_ha->pending_queue) {
1209 rp = list_entry(list, srb_t, list);
1214 /* Remove srb from LUN queue. */
1215 rp->flags |= SRB_ABORTED;
1217 DEBUG2(printk("qla2xxx_eh_abort: Cmd in pending queue."
1218 " serial_number %ld.\n",
1219 sp->cmd->serial_number);)
1221 __del_from_pending_queue(vis_ha, rp);
1222 cmd->result = DID_ABORT << 16;
1224 __add_to_done_queue(vis_ha, rp);
1226 return_status = SUCCESS;
1230 } /* list_for_each_safe() */
1231 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
1232 } /*End of if !found */
1234 if (!found) { /* find the command in our active list */
1235 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1236 "in outstanding queue.\n", sp);)
1238 spin_lock_irqsave(&ha->hardware_lock, flags);
1239 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1240 sp = ha->outstanding_cmds[i];
1248 DEBUG2(printk("qla2xxx_eh_abort(%ld): aborting sp %p "
1249 "from RISC. pid=%ld sp->state=%x q->q_flag=%lx\n",
1250 ha->host_no, sp, sp->cmd->serial_number,
1251 sp->state, q->q_flag);)
1252 DEBUG(qla2x00_print_scsi_cmd(cmd);)
1254 /* Get a reference to the sp and drop the lock.*/
1257 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1258 spin_unlock(ha->host->host_lock);
1260 if (qla2x00_abort_command(ha, sp)) {
1261 DEBUG2(printk("qla2xxx_eh_abort: abort_command "
1263 return_status = FAILED;
1265 DEBUG3(printk("qla2xxx_eh_abort: abort_command "
1266 " mbx success.\n");)
1267 return_status = SUCCESS;
1272 spin_lock_irq(ha->host->host_lock);
1273 spin_lock_irqsave(&ha->hardware_lock, flags);
1276 * Regardless of mailbox command status, go check on
1277 * done queue just in case the sp is already done.
1281 }/*End of for loop */
1282 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1284 } /*End of if !found */
1286 /*Waiting for our command in done_queue to be returned to OS.*/
1287 if (qla2x00_eh_wait_on_command(ha, cmd) != 0) {
1288 DEBUG2(printk("qla2xxx_eh_abort: cmd returned back to OS.\n");)
1289 return_status = SUCCESS;
1292 if (return_status == FAILED) {
1293 qla_printk(KERN_INFO, ha,
1294 "qla2xxx_eh_abort Exiting: status=Failed\n");
1298 DEBUG2(printk("qla2xxx_eh_abort: Exiting. return_status=0x%x.\n",
1301 return(return_status);
1304 /**************************************************************************
1305 * qla2x00_eh_wait_for_pending_target_commands
1308 * Waits for all the commands to come back from the specified target.
1311 * ha - pointer to scsi_qla_host structure.
1314 * Either SUCCESS or FAILED.
1317 **************************************************************************/
1319 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
1323 unsigned long flags;
1325 struct scsi_cmnd *cmd;
1330 * Waiting for all commands for the designated target in the active
1333 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1334 spin_lock_irqsave(&ha->hardware_lock, flags);
1335 sp = ha->outstanding_cmds[cnt];
1338 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1339 if (cmd->device->id == t) {
1340 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
1347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1354 /**************************************************************************
1355 * qla2xxx_eh_device_reset
1358 * The device reset function will reset the target and abort any
1359 * executing commands.
1361 * NOTE: The use of SP is undefined within this context. Do *NOT*
1362 * attempt to use this value, even if you determine it is
1366 * cmd = Linux SCSI command packet of the command that cause the
1370 * SUCCESS/FAILURE (defined as macro in scsi.h).
1372 **************************************************************************/
1374 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1377 unsigned int b, t, l;
1378 scsi_qla_host_t *ha;
1381 fc_port_t *fcport_to_reset;
1383 return_status = FAILED;
1386 "%s(): **** SCSI mid-layer passing in NULL cmd\n",
1389 return (return_status);
1392 b = cmd->device->channel;
1393 t = cmd->device->id;
1394 l = cmd->device->lun;
1395 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1399 qla_printk(KERN_INFO, ha,
1400 "%s(): **** CMD derives a NULL TGT_Q\n", __func__);
1402 return (return_status);
1404 lq = (os_lun_t *)LUN_Q(ha, t, l);
1407 "%s(): **** CMD derives a NULL LUN_Q\n", __func__);
1409 return (return_status);
1411 fcport_to_reset = lq->fclun->fcport;
1413 qla_printk(KERN_INFO, ha,
1414 "scsi(%ld:%d:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, b, t, l);
1416 DEBUG2(printk(KERN_INFO
1417 "scsi(%ld): DEVICE_RESET cmd=%p jiffies = 0x%lx, timeout=%x, "
1418 "dpc_flags=%lx, status=%x allowed=%d cmd.state=%x\n",
1419 ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
1420 ha->dpc_flags, cmd->result, cmd->allowed, cmd->state));
1422 spin_unlock_irq(ha->host->host_lock);
1424 /* Blocking call-Does context switching if abort isp is active etc */
1425 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1426 DEBUG2(printk(KERN_INFO
1427 "%s failed:board disabled\n",__func__));
1429 spin_lock_irq(ha->host->host_lock);
1430 goto eh_dev_reset_done;
1433 /* Blocking call-Does context switching if loop is Not Ready */
1434 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1435 if (qla2x00_device_reset(ha, fcport_to_reset) == 0) {
1436 return_status = SUCCESS;
1439 #if defined(LOGOUT_AFTER_DEVICE_RESET)
1440 if (return_status == SUCCESS) {
1441 if (fcport_to_reset->flags & FC_FABRIC_DEVICE) {
1442 qla2x00_fabric_logout(ha,
1443 fcport_to_reset->loop_id);
1444 qla2x00_mark_device_lost(ha, fcport_to_reset);
1449 DEBUG2(printk(KERN_INFO
1450 "%s failed: loop not ready\n",__func__);)
1453 spin_lock_irq(ha->host->host_lock);
1455 if (return_status == FAILED) {
1456 DEBUG3(printk("%s(%ld): device reset failed\n",
1457 __func__,ha->host_no));
1458 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
1461 goto eh_dev_reset_done;
1465 * If we are coming down the EH path, wait for all commands to
1466 * complete for the device.
1468 if (cmd->device->host->eh_active) {
1469 if (qla2x00_eh_wait_for_pending_target_commands(ha, t))
1470 return_status = FAILED;
1472 if (return_status == FAILED) {
1473 DEBUG3(printk("%s(%ld): failed while waiting for "
1474 "commands\n", __func__, ha->host_no));
1475 qla_printk(KERN_INFO, ha,
1476 "%s: failed while waiting for commands\n",
1479 goto eh_dev_reset_done;
1483 qla_printk(KERN_INFO, ha,
1484 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1485 ha->host_no, b, t, l);
1489 return (return_status);
1492 /**************************************************************************
1493 * qla2x00_eh_wait_for_pending_commands
1496 * Waits for all the commands to come back from the specified host.
1499 * ha - pointer to scsi_qla_host structure.
1506 **************************************************************************/
1508 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
1512 unsigned long flags;
1514 struct scsi_cmnd *cmd;
1519 * Waiting for all commands for the designated target in the active
1522 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1523 spin_lock_irqsave(&ha->hardware_lock, flags);
1524 sp = ha->outstanding_cmds[cnt];
1527 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1528 status = qla2x00_eh_wait_on_command(ha, cmd);
1533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1540 /**************************************************************************
1541 * qla2xxx_eh_bus_reset
1544 * The bus reset function will reset the bus and abort any executing
1548 * cmd = Linux SCSI command packet of the command that cause the
1552 * SUCCESS/FAILURE (defined as macro in scsi.h).
1554 **************************************************************************/
1556 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1558 scsi_qla_host_t *ha;
1562 ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1563 sp = (srb_t *) CMD_SP(cmd);
1565 qla_printk(KERN_INFO, ha,
1566 "scsi(%ld:%d:%d:%d): LOOP RESET ISSUED.\n", ha->host_no,
1567 cmd->device->channel, cmd->device->id, cmd->device->lun);
1569 spin_unlock_irq(ha->host->host_lock);
1571 /* Blocking call-Does context switching if abort isp is active etc*/
1572 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1573 DEBUG2(printk("%s failed:board disabled\n",__func__));
1574 spin_lock_irq(ha->host->host_lock);
1578 /* Blocking call-Does context switching if loop is Not Ready */
1579 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1580 if (qla2x00_loop_reset(ha))
1584 spin_lock_irq(ha->host->host_lock);
1589 * Blocking Call. It goes to sleep waiting for cmd to get to done q
1591 * XXX(hch): really? We're under host_lock here..
1593 /* Waiting for our command in done_queue to be returned to OS.*/
1594 if (!qla2x00_eh_wait_for_pending_commands(ha))
1598 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1599 (rval == FAILED) ? "failed" : "succeded");
1604 /**************************************************************************
1605 * qla2xxx_eh_host_reset
1608 * The reset function will reset the Adapter.
1611 * cmd = Linux SCSI command packet of the command that cause the
1615 * Either SUCCESS or FAILED.
1618 **************************************************************************/
1620 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1622 scsi_qla_host_t *ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1625 /* Display which one we're actually resetting for debug. */
1626 DEBUG(printk("qla2xxx_eh_host_reset:Resetting scsi(%ld).\n",
1632 qla_printk(KERN_INFO, ha,
1633 "scsi(%ld:%d:%d:%d): ADAPTER RESET issued.\n", ha->host_no,
1634 cmd->device->channel, cmd->device->id, cmd->device->lun);
1636 spin_unlock_irq(ha->host->host_lock);
1638 /* Blocking call-Does context switching if abort isp is active etc*/
1639 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1640 goto board_disabled;
1643 * Fixme-may be dpc thread is active and processing
1644 * loop_resync,so wait a while for it to
1645 * be completed and then issue big hammer.Otherwise
1646 * it may cause I/O failure as big hammer marks the
1647 * devices as lost kicking of the port_down_timer
1648 * while dpc is stuck for the mailbox to complete.
1650 /* Blocking call-Does context switching if loop is Not Ready */
1651 qla2x00_wait_for_loop_ready(ha);
1652 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1653 if (qla2x00_abort_isp(ha)) {
1654 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1655 /* failed. schedule dpc to try */
1656 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1658 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1659 goto board_disabled;
1662 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1664 spin_lock_irq(ha->host->host_lock);
1668 /* Waiting for our command in done_queue to be returned to OS.*/
1669 if (qla2x00_eh_wait_for_pending_commands(ha))
1673 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1674 (rval == FAILED) ? "failed" : "succeded");
1679 spin_lock_irq(ha->host->host_lock);
1681 qla_printk(KERN_INFO, ha, "%s: failed:board disabled\n", __func__);
1687 * qla2x00_loop_reset
1691 * ha = adapter block pointer.
1697 qla2x00_loop_reset(scsi_qla_host_t *ha)
1699 uint8_t status = QLA_SUCCESS;
1703 if (ha->flags.enable_lip_reset) {
1704 status = qla2x00_lip_reset(ha);
1707 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1708 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1709 if ((tq = TGT_Q(ha, t)) == NULL)
1712 if (tq->fcport == NULL)
1715 status = qla2x00_target_reset(ha, 0, t);
1716 if (status != QLA_SUCCESS) {
1722 if (status == QLA_SUCCESS &&
1723 ((!ha->flags.enable_target_reset &&
1724 !ha->flags.enable_lip_reset) ||
1725 ha->flags.enable_lip_full_login)) {
1727 status = qla2x00_full_login_lip(ha);
1730 /* Issue marker command only when we are going to start the I/O */
1731 ha->marker_needed = 1;
1735 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1740 DEBUG3(printk("%s(%ld): exiting normally.\n",
1749 * qla2x00_device_reset
1750 * Issue bus device reset message to the target.
1753 * ha = adapter block pointer.
1755 * TARGET_QUEUE_LOCK must be released.
1756 * ADAPTER_STATE_LOCK must be released.
1762 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1764 /* Abort Target command will clear Reservation */
1765 return qla2x00_abort_target(reset_fcport);
1768 /**************************************************************************
1769 * qla2x00_slave_configure
1772 **************************************************************************/
1774 qla2xxx_slave_configure(struct scsi_device *sdev)
1776 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1779 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1784 if (sdev->tagged_supported) {
1786 if (!(ql2xmaxqdepth == 0 || ql2xmaxqdepth > 256))
1787 queue_depth = ql2xmaxqdepth;
1789 ql2xmaxqdepth = queue_depth;
1791 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
1793 qla_printk(KERN_INFO, ha,
1794 "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue "
1796 sdev->host->host_no, sdev->channel, sdev->id, sdev->lun,
1799 scsi_adjust_queue_depth(sdev, 0 /* TCQ off */,
1800 sdev->host->hostt->cmd_per_lun /* 3 */);
1807 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1810 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1811 * supported addressing method.
1814 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1816 /* Assume 32bit DMA address */
1817 ha->flags.enable_64bit_addressing = 0;
1818 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1819 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1822 * Given the two variants pci_set_dma_mask(), allow the compiler to
1823 * assist in setting the proper dma mask.
1825 if (sizeof(dma_addr_t) > 4) {
1826 /* Update our PCI device dma_mask for full 64 bits */
1827 if (pci_set_dma_mask(ha->pdev, 0xffffffffffffffffULL) == 0) {
1828 ha->flags.enable_64bit_addressing = 1;
1829 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1830 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1832 if (pci_set_consistent_dma_mask(ha->pdev,
1833 0xffffffffffffffffULL)) {
1834 qla_printk(KERN_DEBUG, ha,
1835 "Failed to set 64 bit PCI consistent mask; "
1837 pci_set_consistent_dma_mask(ha->pdev,
1841 qla_printk(KERN_DEBUG, ha,
1842 "Failed to set 64 bit PCI DMA mask, falling back "
1843 "to 32 bit MASK.\n");
1844 pci_set_dma_mask(ha->pdev, 0xffffffff);
1847 pci_set_dma_mask(ha->pdev, 0xffffffff);
1852 qla2x00_iospace_config(scsi_qla_host_t *ha)
1854 unsigned long pio, pio_len, pio_flags;
1855 unsigned long mmio, mmio_len, mmio_flags;
1857 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1858 pio = pci_resource_start(ha->pdev, 0);
1859 pio_len = pci_resource_len(ha->pdev, 0);
1860 pio_flags = pci_resource_flags(ha->pdev, 0);
1861 if (pio_flags & IORESOURCE_IO) {
1862 if (pio_len < MIN_IOBASE_LEN) {
1863 qla_printk(KERN_WARNING, ha,
1864 "Invalid PCI I/O region size (%s)...\n",
1865 ha->pdev->slot_name);
1869 qla_printk(KERN_WARNING, ha,
1870 "region #0 not a PIO resource (%s)...\n",
1871 ha->pdev->slot_name);
1875 /* Use MMIO operations for all accesses. */
1876 mmio = pci_resource_start(ha->pdev, 1);
1877 mmio_len = pci_resource_len(ha->pdev, 1);
1878 mmio_flags = pci_resource_flags(ha->pdev, 1);
1880 if (!(mmio_flags & IORESOURCE_MEM)) {
1881 qla_printk(KERN_ERR, ha,
1882 "region #0 not an MMIO resource (%s), aborting\n",
1883 ha->pdev->slot_name);
1884 goto iospace_error_exit;
1886 if (mmio_len < MIN_IOBASE_LEN) {
1887 qla_printk(KERN_ERR, ha,
1888 "Invalid PCI mem region size (%s), aborting\n",
1889 ha->pdev->slot_name);
1890 goto iospace_error_exit;
1893 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1894 qla_printk(KERN_WARNING, ha,
1895 "Failed to reserve PIO/MMIO regions (%s)\n",
1896 ha->pdev->slot_name);
1898 goto iospace_error_exit;
1901 ha->pio_address = pio;
1902 ha->pio_length = pio_len;
1903 ha->mmio_address = ioremap(mmio, MIN_IOBASE_LEN);
1904 if (!ha->mmio_address) {
1905 qla_printk(KERN_ERR, ha,
1906 "cannot remap MMIO (%s), aborting\n", ha->pdev->slot_name);
1908 goto iospace_error_exit;
1910 ha->mmio_length = mmio_len;
1911 ha->iobase = (device_reg_t *) ha->mmio_address;
1920 * PCI driver interface
1922 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1926 struct Scsi_Host *host;
1927 scsi_qla_host_t *ha;
1928 unsigned long flags = 0;
1929 unsigned long wait_switch = 0;
1933 if (pci_enable_device(pdev))
1936 host = scsi_host_alloc(&qla2x00_driver_template,
1937 sizeof(scsi_qla_host_t));
1940 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1944 /* Clear our data area */
1945 ha = (scsi_qla_host_t *)host->hostdata;
1946 memset(ha, 0, sizeof(scsi_qla_host_t));
1950 ha->host_no = host->host_no;
1951 ha->brd_info = brd_info;
1952 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1954 /* Configure PCI I/O space */
1955 ret = qla2x00_iospace_config(ha);
1960 /* Sanitize the information from PCI BIOS. */
1961 host->irq = pdev->irq;
1963 qla_printk(KERN_INFO, ha,
1964 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1965 host->irq, ha->iobase);
1967 spin_lock_init(&ha->hardware_lock);
1969 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1972 ha->total_isr_cnt = 0;
1973 ha->total_isp_aborts = 0;
1974 ha->total_lip_cnt = 0;
1975 ha->total_dev_errs = 0;
1977 ha->total_bytes = 0;
1979 ha->prev_topology = 0;
1980 ha->ports = MAX_BUSES;
1982 if (IS_QLA2100(ha)) {
1983 ha->max_targets = MAX_TARGETS_2100;
1984 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1985 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1986 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1987 } else if (IS_QLA2200(ha)) {
1988 ha->max_targets = MAX_TARGETS_2200;
1989 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1990 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1991 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1992 } else /*if (IS_QLA2300(ha))*/ {
1993 ha->max_targets = MAX_TARGETS_2200;
1994 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1995 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1996 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1999 /* load the F/W, read paramaters, and init the H/W */
2000 ha->instance = num_hosts;
2002 init_MUTEX(&ha->mbx_cmd_sem);
2003 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
2005 INIT_LIST_HEAD(&ha->list);
2006 INIT_LIST_HEAD(&ha->fcports);
2007 INIT_LIST_HEAD(&ha->rscn_fcports);
2008 INIT_LIST_HEAD(&ha->done_queue);
2009 INIT_LIST_HEAD(&ha->retry_queue);
2010 INIT_LIST_HEAD(&ha->scsi_retry_queue);
2011 INIT_LIST_HEAD(&ha->pending_queue);
2014 * These locks are used to prevent more than one CPU
2015 * from modifying the queue at the same time. The
2016 * higher level "host_lock" will reduce most
2017 * contention for these locks.
2019 spin_lock_init(&ha->mbx_reg_lock);
2020 spin_lock_init(&ha->list_lock);
2022 init_completion(&ha->dpc_inited);
2023 init_completion(&ha->dpc_exited);
2025 qla2x00_config_dma_addressing(ha);
2026 if (qla2x00_mem_alloc(ha)) {
2027 qla_printk(KERN_WARNING, ha,
2028 "[ERROR] Failed to allocate memory for adapter\n");
2033 if (qla2x00_initialize_adapter(ha) &&
2034 !(ha->device_flags & DFLG_NO_CABLE)) {
2036 qla_printk(KERN_WARNING, ha,
2037 "Failed to initialize adapter\n");
2039 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2040 "Adapter flags %x.\n",
2041 ha->host_no, ha->device_flags));
2047 * Startup the kernel thread for this host adapter
2049 ha->dpc_should_die = 0;
2050 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
2051 if (ha->dpc_pid < 0) {
2052 qla_printk(KERN_WARNING, ha,
2053 "Unable to start DPC thread!\n");
2057 wait_for_completion(&ha->dpc_inited);
2059 host->this_id = 255;
2060 host->cmd_per_lun = 3;
2061 host->max_cmd_len = MAX_CMDSZ;
2062 host->max_channel = ha->ports - 1;
2063 host->max_lun = ha->max_luns;
2064 host->unique_id = ha->instance;
2065 host->max_id = ha->max_targets;
2067 if (request_irq(host->irq, qla2x00_intr_handler, SA_INTERRUPT|SA_SHIRQ,
2068 ha->brd_info->drv_name, ha)) {
2069 qla_printk(KERN_WARNING, ha,
2070 "Failed to reserve interrupt %d already in use.\n",
2075 /* Initialized the timer */
2076 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
2078 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2083 /* Disable ISP interrupts. */
2084 qla2x00_disable_intrs(ha);
2086 /* Ensure mailbox registers are free. */
2087 spin_lock_irqsave(&ha->hardware_lock, flags);
2088 WRT_REG_WORD(®->semaphore, 0);
2089 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2090 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2092 /* Enable proper parity */
2093 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2096 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
2098 /* SRAM, Instruction RAM and GP RAM parity */
2099 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
2101 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2104 /* Enable chip interrupts. */
2105 qla2x00_enable_intrs(ha);
2107 /* Insert new entry into the list of adapters */
2108 write_lock(&qla_hostlist_lock);
2109 list_add_tail(&ha->list, &qla_hostlist);
2110 write_unlock(&qla_hostlist_lock);
2114 * Wait around max loop_reset_delay secs for the devices to come
2115 * on-line. We don't want Linux scanning before we are ready.
2118 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
2119 time_before(jiffies,wait_switch) &&
2120 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
2121 && (ha->device_flags & SWITCH_FOUND) ;) {
2123 qla2x00_check_fabric_devices(ha);
2125 set_current_state(TASK_INTERRUPTIBLE);
2126 schedule_timeout(5);
2129 pci_set_drvdata(pdev, ha);
2130 ha->flags.init_done = 1;
2133 /* List the target we have found */
2134 if (displayConfig) {
2135 qla2x00_display_fc_names(ha);
2138 if (scsi_add_host(host, &pdev->dev))
2141 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
2142 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
2144 qla_printk(KERN_INFO, ha, "\n"
2145 " QLogic Fibre Channel HBA Driver: %s\n"
2147 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
2148 ha->model_number, ha->model_desc ? ha->model_desc: "",
2149 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
2150 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
2151 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
2154 scsi_scan_host(host);
2159 qla2x00_free_device(ha);
2161 scsi_host_put(host);
2165 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
2167 void qla2x00_remove_one(struct pci_dev *pdev)
2169 scsi_qla_host_t *ha;
2171 ha = pci_get_drvdata(pdev);
2173 write_lock(&qla_hostlist_lock);
2174 list_del(&ha->list);
2175 write_unlock(&qla_hostlist_lock);
2177 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
2178 &sysfs_fw_dump_attr);
2179 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
2181 scsi_remove_host(ha->host);
2183 qla2x00_free_device(ha);
2185 scsi_host_put(ha->host);
2187 pci_set_drvdata(pdev, NULL);
2189 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
2192 qla2x00_free_device(scsi_qla_host_t *ha)
2196 /* Abort any outstanding IO descriptors. */
2197 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2198 qla2x00_cancel_io_descriptors(ha);
2200 /* turn-off interrupts on the card */
2201 if (ha->interrupts_on)
2202 qla2x00_disable_intrs(ha);
2205 if (ha->timer_active)
2206 qla2x00_stop_timer(ha);
2208 /* Kill the kernel thread for this host */
2209 if (ha->dpc_pid >= 0) {
2210 ha->dpc_should_die = 1;
2212 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
2214 qla_printk(KERN_ERR, ha,
2215 "Unable to signal DPC thread -- (%d)\n", ret);
2217 /* TODO: SOMETHING MORE??? */
2219 wait_for_completion(&ha->dpc_exited);
2223 qla2x00_mem_free(ha);
2226 ha->flags.online = FALSE;
2228 /* Detach interrupts */
2230 free_irq(ha->pdev->irq, ha);
2232 /* release io space registers */
2233 pci_release_regions(ha->pdev);
2235 #if MEMORY_MAPPED_IO
2236 if (ha->mmio_address)
2237 iounmap(ha->mmio_address);
2243 * The following support functions are adopted to handle
2244 * the re-entrant qla2x00_proc_info correctly.
2247 copy_mem_info(struct info_str *info, char *data, int len)
2249 if (info->pos + len > info->offset + info->length)
2250 len = info->offset + info->length - info->pos;
2252 if (info->pos + len < info->offset) {
2257 if (info->pos < info->offset) {
2260 partial = info->offset - info->pos;
2262 info->pos += partial;
2267 memcpy(info->buffer, data, len);
2269 info->buffer += len;
2274 copy_info(struct info_str *info, char *fmt, ...)
2280 va_start(args, fmt);
2281 len = vsprintf(buf, fmt, args);
2284 copy_mem_info(info, buf, len);
2289 /*************************************************************************
2293 * Return information to handle /proc support for the driver.
2295 * inout : decides the direction of the dataflow and the meaning of the
2297 * buffer: If inout==FALSE data is being written to it else read from it
2298 * (ptr to a page buffer)
2299 * *start: If inout==FALSE start of the valid data in the buffer
2300 * offset: If inout==FALSE starting offset from the beginning of all
2301 * possible data to return.
2302 * length: If inout==FALSE max number of bytes to be written into the buffer
2303 * else number of bytes in "buffer"
2305 * < 0: error. errno value.
2306 * >= 0: sizeof data returned.
2307 *************************************************************************/
2309 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
2310 char **start, off_t offset, int length, int inout)
2312 struct info_str info;
2314 int retval = -EINVAL;
2319 unsigned long *flags;
2320 uint8_t *loop_state;
2322 scsi_qla_host_t *ha;
2325 DEBUG3(printk(KERN_INFO
2326 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
2327 buffer, offset, length);)
2331 /* Find the host that was specified */
2333 read_lock(&qla_hostlist_lock);
2334 list_for_each_entry(ha, &qla_hostlist, list) {
2335 if (ha->host == shost) {
2340 read_unlock(&qla_hostlist_lock);
2342 /* if host wasn't found then exit */
2344 DEBUG2_3(printk(KERN_WARNING
2345 "%s: Can't find adapter for host %p\n",
2351 if (inout == TRUE) {
2352 /* Has data been written to the file? */
2354 "%s: has data been written to the file. \n",
2357 return (qla2x00_set_info(buffer, length, shost));
2364 info.buffer = buffer;
2365 info.length = length;
2366 info.offset = offset;
2369 /* start building the print buffer */
2371 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
2372 " Firmware version %s, ",
2373 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
2375 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
2377 copy_info(&info, "Entry address = %p\n", qla2x00_set_info);
2379 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
2381 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
2382 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
2385 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
2386 (unsigned long long)ha->request_dma,
2387 (unsigned long long)ha->response_dma);
2390 "Request Queue count = %ld, Response Queue count = %ld\n",
2391 (long)REQUEST_ENTRY_CNT, (long)ha->response_q_length);
2394 "Total number of active commands = %ld\n",
2398 "Total number of interrupts = %ld\n",
2399 (long)ha->total_isr_cnt);
2402 " Device queue depth = 0x%x\n",
2403 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
2406 "Number of free request entries = %d\n", ha->req_q_cnt);
2409 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
2412 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
2415 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
2418 "Number of retries for empty slots = %ld\n",
2419 qla2x00_stats.outarray_full);
2422 "Number of reqs in pending_q= %ld, retry_q= %d, "
2423 "done_q= %ld, scsi_retry_q= %d\n",
2424 ha->qthreads, ha->retry_q_cnt,
2425 ha->done_q_cnt, ha->scsi_retry_q_cnt);
2428 flags = (unsigned long *) &ha->flags;
2430 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
2431 loop_state = "DOWN";
2432 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
2434 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
2435 loop_state = "READY";
2436 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
2437 loop_state = "TIMEOUT";
2438 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
2439 loop_state = "UPDATE";
2441 loop_state = "UNKNOWN";
2445 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
2446 loop_state , *flags);
2448 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
2450 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
2452 copy_info(&info, "Link down Timeout = %3.3d\n",
2453 ha->link_down_timeout);
2455 copy_info(&info, "Port down retry = %3.3d\n",
2456 ha->port_down_retry_count);
2458 copy_info(&info, "Login retry count = %3.3d\n",
2459 ha->login_retry_count);
2462 "Commands retried with dropped frame(s) = %d\n",
2463 ha->dropped_frame_error_cnt);
2466 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
2467 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
2469 copy_info(&info, "\n");
2471 /* 2.25 node/port display to proc */
2472 /* Display the node name for adapter */
2473 copy_info(&info, "\nSCSI Device Information:\n");
2475 "scsi-qla%d-adapter-node="
2476 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2478 ha->init_cb->node_name[0],
2479 ha->init_cb->node_name[1],
2480 ha->init_cb->node_name[2],
2481 ha->init_cb->node_name[3],
2482 ha->init_cb->node_name[4],
2483 ha->init_cb->node_name[5],
2484 ha->init_cb->node_name[6],
2485 ha->init_cb->node_name[7]);
2487 /* display the port name for adapter */
2489 "scsi-qla%d-adapter-port="
2490 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2492 ha->init_cb->port_name[0],
2493 ha->init_cb->port_name[1],
2494 ha->init_cb->port_name[2],
2495 ha->init_cb->port_name[3],
2496 ha->init_cb->port_name[4],
2497 ha->init_cb->port_name[5],
2498 ha->init_cb->port_name[6],
2499 ha->init_cb->port_name[7]);
2501 /* Print out device port names */
2502 for (i = 0; i < MAX_TARGETS; i++) {
2503 if ((tq = TGT_Q(ha, i)) == NULL)
2507 "scsi-qla%d-target-%d="
2508 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2509 (int)ha->instance, i,
2510 tq->port_name[0], tq->port_name[1],
2511 tq->port_name[2], tq->port_name[3],
2512 tq->port_name[4], tq->port_name[5],
2513 tq->port_name[6], tq->port_name[7]);
2515 } /* 2.25 node/port display to proc */
2517 copy_info(&info, "\nSCSI LUN Information:\n");
2519 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
2521 /* scan for all equipment stats */
2522 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2524 for (l = 0; l < ha->max_luns; l++) {
2525 up = (os_lun_t *) GET_LU_Q(ha, t, l);
2530 if (up->fclun == NULL) {
2535 "(%2d:%2d): Total reqs %ld,",
2539 " Pending reqs %ld,",
2542 if (up->io_cnt < 4) {
2553 " %ld:%d:%02x %02x",
2554 up->fclun->fcport->ha->instance,
2555 up->fclun->fcport->cur_path,
2556 up->fclun->fcport->loop_id,
2557 up->fclun->device_type);
2559 copy_info(&info, "\n");
2561 if (info.pos >= info.offset + info.length) {
2562 /* No need to continue */
2567 if (info.pos >= info.offset + info.length) {
2568 /* No need to continue */
2575 retval = info.pos > info.offset ? info.pos - info.offset : 0;
2577 DEBUG3(printk(KERN_INFO
2578 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
2579 "length=0x%x\n", info.pos, offset, length);)
2585 * qla2x00_display_fc_names
2586 * This routine will the node names of the different devices found
2587 * after port inquiry.
2590 * cmd = SCSI command structure
2596 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2601 /* Display the node name for adapter */
2602 qla_printk(KERN_INFO, ha,
2603 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2605 ha->init_cb->node_name[0],
2606 ha->init_cb->node_name[1],
2607 ha->init_cb->node_name[2],
2608 ha->init_cb->node_name[3],
2609 ha->init_cb->node_name[4],
2610 ha->init_cb->node_name[5],
2611 ha->init_cb->node_name[6],
2612 ha->init_cb->node_name[7]);
2614 /* display the port name for adapter */
2615 qla_printk(KERN_INFO, ha,
2616 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2618 ha->init_cb->port_name[0],
2619 ha->init_cb->port_name[1],
2620 ha->init_cb->port_name[2],
2621 ha->init_cb->port_name[3],
2622 ha->init_cb->port_name[4],
2623 ha->init_cb->port_name[5],
2624 ha->init_cb->port_name[6],
2625 ha->init_cb->port_name[7]);
2627 /* Print out device port names */
2628 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2629 if ((tq = ha->otgt[tgt]) == NULL)
2632 if (tq->fcport == NULL)
2635 switch (ha->binding_type) {
2636 case BIND_BY_PORT_NAME:
2637 qla_printk(KERN_INFO, ha,
2638 "scsi-qla%d-tgt-%d-di-0-port="
2639 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2653 case BIND_BY_PORT_ID:
2654 qla_printk(KERN_INFO, ha,
2655 "scsi-qla%d-tgt-%d-di-0-pid="
2656 "%02x%02x%02x\\;\n",
2666 qla_printk(KERN_INFO, ha,
2667 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2673 * qla2x00_suspend_lun
2674 * Suspend lun and start port down timer
2677 * ha = visable adapter block pointer.
2679 * cp = Scsi command pointer
2680 * time = time in seconds
2681 * count = number of times to let time expire
2682 * delay_lun = non-zero, if lun should be delayed rather than suspended
2685 * QLA_SUCCESS -- suspended lun
2686 * QLA_FUNCTION_FAILED -- Didn't suspend lun
2689 * Interrupt context.
2692 __qla2x00_suspend_lun(scsi_qla_host_t *ha,
2693 os_lun_t *lq, int time, int count, int delay_lun)
2697 struct list_head *list, *temp;
2698 unsigned long flags;
2702 /* if the lun_q is already suspended then don't do it again */
2703 if (lq->q_state == LUN_STATE_READY ||lq->q_state == LUN_STATE_RUN) {
2705 spin_lock_irqsave(&lq->q_lock, flags);
2706 if (lq->q_state == LUN_STATE_READY) {
2710 /* Set the suspend time usually 6 secs */
2711 atomic_set(&lq->q_timer, time);
2713 /* now suspend the lun */
2714 lq->q_state = LUN_STATE_WAIT;
2717 set_bit(LUN_EXEC_DELAYED, &lq->q_flag);
2718 DEBUG(printk(KERN_INFO
2719 "scsi(%ld): Delay lun execution for %d secs, "
2720 "count=%d, max count=%d, state=%d\n",
2723 lq->q_count, lq->q_max, lq->q_state));
2725 DEBUG(printk(KERN_INFO
2726 "scsi(%ld): Suspend lun for %d secs, count=%d, "
2727 "max count=%d, state=%d\n",
2730 lq->q_count, lq->q_max, lq->q_state));
2732 spin_unlock_irqrestore(&lq->q_lock, flags);
2735 * Remove all pending commands from request queue and put them
2736 * in the scsi_retry queue.
2738 spin_lock_irqsave(&ha->list_lock, flags);
2739 list_for_each_safe(list, temp, &ha->pending_queue) {
2740 sp = list_entry(list, srb_t, list);
2741 if (sp->lun_queue != lq)
2744 __del_from_pending_queue(ha, sp);
2746 if (sp->cmd->allowed < count)
2747 sp->cmd->allowed = count;
2748 __add_to_scsi_retry_queue(ha, sp);
2750 } /* list_for_each_safe */
2751 spin_unlock_irqrestore(&ha->list_lock, flags);
2754 rval = QLA_FUNCTION_FAILED;
2761 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2763 * Input: ha = adapter block pointer. fcport = port structure pointer.
2769 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2773 * We may need to retry the login, so don't change the state of the
2774 * port but do the retries.
2776 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2777 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2782 if (fcport->login_retry == 0) {
2783 fcport->login_retry = ha->login_retry_count;
2784 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2786 DEBUG(printk("scsi(%ld): Port login retry: "
2787 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2788 "id = 0x%04x retry cnt=%d\n",
2790 fcport->port_name[0],
2791 fcport->port_name[1],
2792 fcport->port_name[2],
2793 fcport->port_name[3],
2794 fcport->port_name[4],
2795 fcport->port_name[5],
2796 fcport->port_name[6],
2797 fcport->port_name[7],
2799 fcport->login_retry));
2804 * qla2x00_mark_all_devices_lost
2805 * Updates fcport state when device goes offline.
2808 * ha = adapter block pointer.
2809 * fcport = port structure pointer.
2817 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2819 struct list_head *fcpl;
2822 list_for_each(fcpl, &ha->fcports) {
2823 fcport = list_entry(fcpl, fc_port_t, list);
2826 * No point in marking the device as lost, if the device is
2829 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2832 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2838 * Allocates adapter memory.
2845 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2852 * This will loop only once if everything goes well, else some
2853 * number of retries will be performed to get around a kernel
2854 * bug where available mem is not allocated until after a
2855 * little delay and a retry.
2857 ha->request_ring = pci_alloc_consistent(ha->pdev,
2858 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
2860 if (ha->request_ring == NULL) {
2861 qla_printk(KERN_WARNING, ha,
2862 "Memory Allocation failed - request_ring\n");
2864 qla2x00_mem_free(ha);
2865 set_current_state(TASK_INTERRUPTIBLE);
2866 schedule_timeout(HZ/10);
2871 ha->response_ring = pci_alloc_consistent(ha->pdev,
2872 ((ha->response_q_length + 1) * (sizeof(response_t))),
2874 if (ha->response_ring == NULL) {
2875 qla_printk(KERN_WARNING, ha,
2876 "Memory Allocation failed - response_ring\n");
2878 qla2x00_mem_free(ha);
2879 set_current_state(TASK_INTERRUPTIBLE);
2880 schedule_timeout(HZ/10);
2885 /* get consistent memory allocated for init control block */
2886 ha->init_cb = pci_alloc_consistent(ha->pdev,
2887 sizeof(init_cb_t), &ha->init_cb_dma);
2888 if (ha->init_cb == NULL) {
2889 qla_printk(KERN_WARNING, ha,
2890 "Memory Allocation failed - init_cb\n");
2892 qla2x00_mem_free(ha);
2893 set_current_state(TASK_INTERRUPTIBLE);
2894 schedule_timeout(HZ/10);
2898 memset(ha->init_cb, 0, sizeof(init_cb_t));
2900 /* Allocate ioctl related memory. */
2901 if (qla2x00_alloc_ioctl_mem(ha)) {
2902 qla_printk(KERN_WARNING, ha,
2903 "Memory Allocation failed - ioctl_mem\n");
2905 qla2x00_mem_free(ha);
2906 set_current_state(TASK_INTERRUPTIBLE);
2907 schedule_timeout(HZ/10);
2912 if (qla2x00_allocate_sp_pool(ha)) {
2913 qla_printk(KERN_WARNING, ha,
2914 "Memory Allocation failed - "
2915 "qla2x00_allocate_sp_pool()\n");
2917 qla2x00_mem_free(ha);
2918 set_current_state(TASK_INTERRUPTIBLE);
2919 schedule_timeout(HZ/10);
2924 /* Allocate memory for SNS commands */
2925 if (IS_QLA2200(ha)) {
2926 /* Get consistent memory allocated for SNS commands */
2927 ha->sns_cmd = pci_alloc_consistent(ha->pdev,
2928 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma);
2929 if (ha->sns_cmd == NULL) {
2931 qla_printk(KERN_WARNING, ha,
2932 "Memory Allocation failed - sns_cmd\n");
2934 qla2x00_mem_free(ha);
2935 set_current_state(TASK_INTERRUPTIBLE);
2936 schedule_timeout(HZ/10);
2940 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2941 } else if (!IS_QLA2100(ha)) {
2942 /* Get consistent memory allocated for MS IOCB */
2943 ha->ms_iocb = pci_alloc_consistent(ha->pdev,
2944 sizeof(ms_iocb_entry_t), &ha->ms_iocb_dma);
2945 if (ha->ms_iocb == NULL) {
2947 qla_printk(KERN_WARNING, ha,
2948 "Memory Allocation failed - ms_iocb\n");
2950 qla2x00_mem_free(ha);
2951 set_current_state(TASK_INTERRUPTIBLE);
2952 schedule_timeout(HZ/10);
2956 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2959 * Get consistent memory allocated for CT SNS
2962 ha->ct_sns = pci_alloc_consistent(ha->pdev,
2963 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma);
2964 if (ha->ct_sns == NULL) {
2966 qla_printk(KERN_WARNING, ha,
2967 "Memory Allocation failed - ct_sns\n");
2969 qla2x00_mem_free(ha);
2970 set_current_state(TASK_INTERRUPTIBLE);
2971 schedule_timeout(HZ/10);
2975 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2978 /* Get consistent memory allocated for Get Port Database cmd */
2979 ha->iodesc_pd = pci_alloc_consistent(ha->pdev,
2980 PORT_DATABASE_SIZE, &ha->iodesc_pd_dma);
2981 if (ha->iodesc_pd == NULL) {
2983 qla_printk(KERN_WARNING, ha,
2984 "Memory Allocation failed - iodesc_pd\n");
2986 qla2x00_mem_free(ha);
2987 set_current_state(TASK_INTERRUPTIBLE);
2988 schedule_timeout(HZ/10);
2992 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2994 /* Done all allocations without any error. */
2997 } while (retry-- && status != 0);
3001 "%s(): **** FAILED ****\n", __func__);
3009 * Frees all adapter allocated memory.
3012 * ha = adapter block pointer.
3015 qla2x00_mem_free(scsi_qla_host_t *ha)
3018 struct list_head *fcpl, *fcptemp;
3020 struct list_head *fcll, *fcltemp;
3022 unsigned long wtime;/* max wait time if mbx cmd is busy. */
3026 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
3030 /* Free the target queues */
3031 for (t = 0; t < MAX_TARGETS; t++) {
3032 qla2x00_tgt_free(ha, t);
3035 /* Make sure all other threads are stopped. */
3037 while (ha->dpc_wait && wtime) {
3038 set_current_state(TASK_INTERRUPTIBLE);
3039 wtime = schedule_timeout(wtime);
3042 /* free ioctl memory */
3043 qla2x00_free_ioctl_mem(ha);
3046 qla2x00_free_sp_pool(ha);
3048 if (ha->iodesc_pd) {
3049 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE,
3050 ha->iodesc_pd, ha->iodesc_pd_dma);
3054 pci_free_consistent(ha->pdev,
3055 sizeof(struct sns_cmd_pkt), ha->sns_cmd, ha->sns_cmd_dma);
3059 pci_free_consistent(ha->pdev,
3060 sizeof(struct ct_sns_pkt), ha->ct_sns, ha->ct_sns_dma);
3063 pci_free_consistent(ha->pdev,
3064 sizeof(ms_iocb_entry_t), ha->ms_iocb, ha->ms_iocb_dma);
3068 pci_free_consistent(ha->pdev,
3069 sizeof(init_cb_t), ha->init_cb, ha->init_cb_dma);
3072 if (ha->request_ring) {
3073 pci_free_consistent(ha->pdev,
3074 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
3075 ha->request_ring, ha->request_dma);
3078 if (ha->response_ring) {
3079 pci_free_consistent(ha->pdev,
3080 ((ha->response_q_length + 1) * (sizeof(response_t))),
3081 ha->response_ring, ha->response_dma);
3084 ha->iodesc_pd = NULL;
3085 ha->iodesc_pd_dma = 0;
3090 ha->request_ring = NULL;
3091 ha->request_dma = 0;
3092 ha->response_ring = NULL;
3093 ha->response_dma = 0;
3095 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
3096 fcport = list_entry(fcpl, fc_port_t, list);
3099 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
3100 fclun = list_entry(fcll, fc_lun_t, list);
3102 list_del_init(&fclun->list);
3107 list_del_init(&fcport->list);
3110 INIT_LIST_HEAD(&ha->fcports);
3113 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
3117 if (ha->fw_dump_buffer) {
3118 vfree(ha->fw_dump_buffer);
3119 ha->fw_dump_reading = 0;
3120 ha->fw_dump_buffer = NULL;
3125 * qla2x00_allocate_sp_pool
3126 * This routine is called during initialization to allocate
3127 * memory for local srb_t.
3130 * ha = adapter block pointer.
3135 * Note: Sets the ref_count for non Null sp to one.
3138 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
3143 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3144 mempool_free_slab, srb_cachep);
3145 if (ha->srb_mempool == NULL) {
3146 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
3147 rval = QLA_FUNCTION_FAILED;
3153 * This routine frees all adapter allocated memory.
3157 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
3159 if (ha->srb_mempool) {
3160 mempool_destroy(ha->srb_mempool);
3161 ha->srb_mempool = NULL;
3165 /**************************************************************************
3167 * This kernel thread is a task that is schedule by the interrupt handler
3168 * to perform the background processing for interrupts.
3171 * This task always run in the context of a kernel thread. It
3172 * is kick-off by the driver's detect code and starts up
3173 * up one per adapter. It immediately goes to sleep and waits for
3174 * some fibre event. When either the interrupt handler or
3175 * the timer routine detects a event it will one of the task
3176 * bits then wake us up.
3177 **************************************************************************/
3179 qla2x00_do_dpc(void *data)
3181 DECLARE_MUTEX_LOCKED(sem);
3182 scsi_qla_host_t *ha;
3183 struct list_head *fcpl;
3188 unsigned long flags = 0;
3189 struct list_head *list, *templist;
3190 int dead_cnt, online_cnt;
3191 uint16_t next_loopid;
3193 ha = (scsi_qla_host_t *)data;
3197 daemonize("%s_dpc", ha->host_str);
3198 allow_signal(SIGHUP);
3200 ha->dpc_wait = &sem;
3202 set_user_nice(current, -20);
3206 complete(&ha->dpc_inited);
3209 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3211 if (down_interruptible(&sem))
3214 if (ha->dpc_should_die)
3217 if (!list_empty(&ha->done_queue))
3220 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3222 /* Initialization not yet finished. Don't do anything yet. */
3223 if (!ha->flags.init_done || ha->dpc_active)
3226 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
3230 /* Process commands in retry queue */
3231 if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {
3232 DEBUG(printk("scsi(%ld): DPC checking retry_q. "
3234 ha->host_no, ha->retry_q_cnt));
3236 spin_lock_irqsave(&ha->list_lock, flags);
3237 dead_cnt = online_cnt = 0;
3238 list_for_each_safe(list, templist, &ha->retry_queue) {
3239 sp = list_entry(list, srb_t, list);
3241 DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "
3242 "spflags=0x%x, q_flag= 0x%lx\n",
3243 ha->host_no, sp->cmd->serial_number, sp,
3244 sp->flags, q->q_flag));
3248 fcport = q->fclun->fcport;
3250 if (atomic_read(&fcport->state) ==
3252 atomic_read(&ha->loop_state) == LOOP_DEAD) {
3254 __del_from_retry_queue(ha, sp);
3255 sp->cmd->result = DID_NO_CONNECT << 16;
3256 sp->cmd->host_scribble =
3257 (unsigned char *) NULL;
3258 __add_to_done_queue(ha, sp);
3260 } else if (atomic_read(&fcport->state) !=
3263 __del_from_retry_queue(ha, sp);
3264 sp->cmd->result = DID_BUS_BUSY << 16;
3265 sp->cmd->host_scribble =
3266 (unsigned char *) NULL;
3267 __add_to_done_queue(ha, sp);
3270 } /* list_for_each_safe() */
3271 spin_unlock_irqrestore(&ha->list_lock, flags);
3273 DEBUG(printk("scsi(%ld): done processing retry queue "
3274 "- dead=%d, online=%d\n ",
3275 ha->host_no, dead_cnt, online_cnt));
3278 /* Process commands in scsi retry queue */
3279 if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {
3281 * Any requests we want to delay for some period is put
3282 * in the scsi retry queue with a delay added. The
3283 * timer will schedule a "scsi_restart_needed" every
3284 * second as long as there are requests in the scsi
3287 DEBUG(printk("scsi(%ld): DPC checking scsi "
3288 "retry_q.total=%d\n",
3289 ha->host_no, ha->scsi_retry_q_cnt));
3292 spin_lock_irqsave(&ha->list_lock, flags);
3293 list_for_each_safe(list, templist,
3294 &ha->scsi_retry_queue) {
3296 sp = list_entry(list, srb_t, list);
3299 DEBUG3(printk("scsi(%ld): scsi_retry_q: "
3300 "pid=%ld sp=%p, spflags=0x%x, "
3301 "q_flag= 0x%lx,q_state=%d\n",
3302 ha->host_no, sp->cmd->serial_number,
3303 sp, sp->flags, q->q_flag, q->q_state));
3305 /* Was this lun suspended */
3306 if (q->q_state != LUN_STATE_WAIT) {
3308 __del_from_scsi_retry_queue(ha, sp);
3309 __add_to_retry_queue(ha,sp);
3312 /* Was this command suspended for N secs */
3313 if (sp->delay != 0) {
3315 if (sp->delay == 0) {
3317 __del_from_scsi_retry_queue(
3319 __add_to_retry_queue(ha,sp);
3323 spin_unlock_irqrestore(&ha->list_lock, flags);
3325 DEBUG(if (online_cnt > 0))
3326 DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "
3328 ha->host_no, online_cnt));
3331 if (ha->flags.mbox_busy) {
3332 if (!list_empty(&ha->done_queue))
3339 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3341 DEBUG(printk("scsi(%ld): dpc: sched "
3342 "qla2x00_abort_isp ha = %p\n",
3344 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3347 if (qla2x00_abort_isp(ha)) {
3348 /* failed. retry later */
3349 set_bit(ISP_ABORT_NEEDED,
3352 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
3354 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3358 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
3359 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
3361 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3364 qla2x00_rst_aen(ha);
3365 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
3368 /* Retry each device up to login retry count */
3369 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3370 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
3371 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3373 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3377 list_for_each(fcpl, &ha->fcports) {
3378 fcport = list_entry(fcpl, fc_port_t, list);
3381 * If the port is not ONLINE then try to login
3382 * to it if we haven't run out of retries.
3384 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3385 fcport->login_retry) {
3387 fcport->login_retry--;
3388 if (fcport->flags & FCF_FABRIC_DEVICE)
3389 status = qla2x00_fabric_login(
3390 ha, fcport, &next_loopid);
3393 qla2x00_local_device_login(
3394 ha, fcport->loop_id);
3396 if (status == QLA_SUCCESS) {
3397 fcport->old_loop_id = fcport->loop_id;
3399 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
3400 ha->host_no, fcport->loop_id));
3402 fcport->port_login_retry_count =
3403 ha->port_down_retry_count * PORT_RETRY_TIME;
3404 atomic_set(&fcport->state, FCS_ONLINE);
3405 atomic_set(&fcport->port_down_timer,
3406 ha->port_down_retry_count * PORT_RETRY_TIME);
3408 fcport->login_retry = 0;
3409 } else if (status == 1) {
3410 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
3411 /* retry the login again */
3412 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
3414 fcport->login_retry, fcport->loop_id));
3416 fcport->login_retry = 0;
3419 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
3422 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3426 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
3427 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3429 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
3430 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
3433 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3435 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
3439 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
3441 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3444 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3447 qla2x00_loop_resync(ha);
3449 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3452 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3457 if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {
3458 DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",
3461 qla2x00_restart_queues(ha,FALSE);
3463 DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",
3467 if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {
3469 DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",
3472 qla2x00_abort_queues(ha, FALSE);
3474 DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",
3478 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
3480 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
3483 qla2x00_rescan_fcports(ha);
3485 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
3491 if (!ha->interrupts_on)
3492 qla2x00_enable_intrs(ha);
3494 if (!list_empty(&ha->done_queue))
3498 } /* End of while(1) */
3500 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
3503 * Make sure that nobody tries to wake us up again.
3505 ha->dpc_wait = NULL;
3508 complete_and_exit(&ha->dpc_exited, 0);
3512 * qla2x00_abort_queues
3513 * Abort all commands on queues on device
3516 * ha = adapter block pointer.
3519 * Interrupt context.
3522 qla2x00_abort_queues(scsi_qla_host_t *ha, uint8_t doneqflg)
3526 struct list_head *list, *temp;
3527 unsigned long flags;
3529 clear_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3531 /* Return all commands device queues. */
3532 spin_lock_irqsave(&ha->list_lock,flags);
3533 list_for_each_safe(list, temp, &ha->pending_queue) {
3534 sp = list_entry(list, srb_t, list);
3536 if (sp->flags & SRB_ABORTED)
3539 /* Remove srb from LUN queue. */
3540 __del_from_pending_queue(ha, sp);
3542 /* Set ending status. */
3543 sp->cmd->result = DID_BUS_BUSY << 16;
3545 __add_to_done_queue(ha, sp);
3547 spin_unlock_irqrestore(&ha->list_lock, flags);
3552 * Processes asynchronous reset.
3555 * ha = adapter block pointer.
3558 qla2x00_rst_aen(scsi_qla_host_t *ha)
3560 if (ha->flags.online && !ha->flags.reset_active &&
3561 !atomic_read(&ha->loop_down_timer) &&
3562 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
3564 /* 10/15 ha->flags.reset_active = TRUE; */
3566 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3569 * Issue marker command only when we are going to start
3572 ha->marker_needed = 1;
3573 } while (!atomic_read(&ha->loop_down_timer) &&
3574 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
3576 /* 10/15 ha->flags.reset_active = FALSE; */
3582 * This routine will alloacte SP from the free queue
3589 qla2x00_get_new_sp(scsi_qla_host_t *ha)
3593 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
3595 atomic_set(&sp->ref_count, 1);
3600 /**************************************************************************
3604 * This function sets the colour of the LED while preserving the
3605 * unsued GPIO pins every sec.
3608 * ha - Host adapter structure
3613 * Context: qla2x00_timer() Interrupt
3614 ***************************************************************************/
3616 qla2x00_blink_led(scsi_qla_host_t *ha)
3618 uint16_t gpio_enable, gpio_data, led_color;
3619 unsigned long cpu_flags = 0;
3620 device_reg_t *reg = ha->iobase;
3622 /* Save the Original GPIOE */
3623 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3624 gpio_enable = RD_REG_WORD(®->gpioe);
3625 gpio_data = RD_REG_WORD(®->gpiod);
3626 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3628 DEBUG2(printk("%s Original data of gpio_enable_reg=0x%x"
3629 " gpio_data_reg=0x%x\n",
3630 __func__,gpio_enable,gpio_data));
3632 if (ha->beacon_green_on){
3633 led_color = GPIO_LED_GREEN_ON_AMBER_OFF;
3634 ha->beacon_green_on = 0;
3636 led_color = GPIO_LED_GREEN_OFF_AMBER_OFF;
3637 ha->beacon_green_on = 1;
3640 /* Set the modified gpio_enable values */
3641 gpio_enable |= GPIO_LED_GREEN_ON_AMBER_OFF;
3643 DEBUG2(printk("%s Before writing enable : gpio_enable_reg=0x%x"
3644 " gpio_data_reg=0x%x led_color=0x%x\n",
3645 __func__, gpio_enable, gpio_data, led_color));
3647 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3648 WRT_REG_WORD(®->gpioe,gpio_enable);
3649 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3651 /* Clear out the previously set LED colour */
3652 gpio_data &= ~GPIO_LED_GREEN_ON_AMBER_OFF;
3654 /* Set the new input LED colour to GPIOD */
3655 gpio_data |= led_color;
3657 DEBUG2(printk("%s Before writing data: gpio_enable_reg=0x%x"
3658 " gpio_data_reg=0x%x led_color=0x%x\n",
3659 __func__,gpio_enable,gpio_data,led_color));
3661 /* Set the modified gpio_data values */
3662 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3663 WRT_REG_WORD(®->gpiod,gpio_data);
3664 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3667 /**************************************************************************
3673 * Context: Interrupt
3674 ***************************************************************************/
3676 qla2x00_timer(scsi_qla_host_t *ha)
3679 unsigned long cpu_flags = 0;
3680 struct list_head *fcpl;
3687 * We try and restart any request in the retry queue every second.
3689 if (!list_empty(&ha->retry_queue)) {
3690 set_bit(PORT_RESTART_NEEDED, &ha->dpc_flags);
3695 * We try and restart any request in the scsi_retry queue every second.
3697 if (!list_empty(&ha->scsi_retry_queue)) {
3698 set_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags);
3702 /* Check if beacon LED needs to be blinked */
3703 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && ha->beacon_blink_led)
3704 qla2x00_blink_led(ha);
3708 * Ports - Port down timer.
3710 * Whenever, a port is in the LOST state we start decrementing its port
3711 * down timer every second until it reaches zero. Once it reaches zero
3712 * the port it marked DEAD.
3715 list_for_each(fcpl, &ha->fcports) {
3716 fcport = list_entry(fcpl, fc_port_t, list);
3718 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3720 if (atomic_read(&fcport->port_down_timer) == 0)
3723 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3724 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3726 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3729 t, atomic_read(&fcport->port_down_timer)));
3732 } /* End of for fcport */
3735 * LUNS - lun suspend timer.
3737 * Whenever, a lun is suspended the timer starts decrementing its
3738 * suspend timer every second until it reaches zero. Once it reaches
3739 * zero the lun retry count is decremented.
3743 * FIXME(dg) - Need to convert this linear search of luns into a search
3744 * of a list of suspended luns.
3746 for (t = 0; t < ha->max_targets; t++) {
3747 if ((tq = ha->otgt[t]) == NULL)
3750 for (l = 0; l < ha->max_luns; l++) {
3751 if ((lq = (os_lun_t *) tq->olun[l]) == NULL)
3754 spin_lock_irqsave(&lq->q_lock, cpu_flags);
3755 if (lq->q_state == LUN_STATE_WAIT &&
3756 atomic_read(&lq->q_timer) != 0) {
3758 if (atomic_dec_and_test(&lq->q_timer) != 0) {
3760 * A delay should immediately
3761 * transition to a READY state
3763 if (test_and_clear_bit(LUN_EXEC_DELAYED,
3765 lq->q_state = LUN_STATE_READY;
3769 if (lq->q_count == lq->q_max)
3777 DEBUG3(printk("scsi(%ld): lun%d - timer %d, "
3778 "count=%d, max=%d, state=%d\n",
3781 atomic_read(&lq->q_timer),
3782 lq->q_count, lq->q_max, lq->q_state));
3784 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
3785 } /* End of for luns */
3786 } /* End of for targets */
3788 /* Loop down handler. */
3789 if (atomic_read(&ha->loop_down_timer) > 0 &&
3790 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
3792 /* dg 10/30 if (atomic_read(&ha->loop_down_timer) == LOOP_DOWN_TIME) { */
3793 if (atomic_read(&ha->loop_down_timer) ==
3794 ha->loop_down_abort_time) {
3796 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3797 "queues before time expire\n",
3800 if (!IS_QLA2100(ha) && ha->link_down_timeout)
3801 atomic_set(&ha->loop_state, LOOP_DEAD);
3803 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3807 /* if the loop has been down for 4 minutes, reinit adapter */
3808 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
3809 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
3810 "restarting queues.\n",
3813 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3816 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3817 DEBUG(printk("scsi(%ld): Loop down - "
3821 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3824 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
3826 atomic_read(&ha->loop_down_timer)));
3830 * Done Q Handler -- dgFIXME This handler will kick off doneq if we
3831 * haven't process it in 2 seconds.
3833 if (!list_empty(&ha->done_queue))
3837 /* Schedule the DPC routine if needed */
3838 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
3839 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
3841 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
3842 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3843 ha->dpc_wait && !ha->dpc_active) {
3848 qla2x00_restart_timer(ha, WATCH_INTERVAL);
3852 * qla2x00_extend_timeout
3853 * This routine will extend the timeout to the specified value.
3856 * cmd = SCSI command structure
3862 qla2x00_extend_timeout(struct scsi_cmnd *cmd, int timeout)
3864 srb_t *sp = (srb_t *) CMD_SP(cmd);
3865 u_long our_jiffies = (timeout * HZ) + jiffies;
3868 sp->e_start = jiffies;
3869 if (cmd->eh_timeout.function) {
3870 mod_timer(&cmd->eh_timeout,our_jiffies);
3871 sp->ext_history |= 1;
3873 if (sp->timer.function != NULL) {
3875 * Our internal timer should timeout before the midlayer has a
3876 * chance begin the abort process
3878 mod_timer(&sp->timer,our_jiffies - (QLA_CMD_TIMER_DELTA * HZ));
3880 sp->ext_history |= 2;
3884 /**************************************************************************
3885 * qla2x00_cmd_timeout
3888 * Handles the command if it times out in any state.
3891 * sp - pointer to validate
3895 * Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).
3896 **************************************************************************/
3898 qla2x00_cmd_timeout(srb_t *sp)
3902 scsi_qla_host_t *vis_ha, *dest_ha;
3903 struct scsi_cmnd *cmd;
3905 #if defined(QL_DEBUG_LEVEL_3)
3911 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
3913 DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state));
3915 t = cmd->device->id;
3916 l = cmd->device->lun;
3917 fcport = sp->fclun->fcport;
3921 * If IO is found either in retry Queue
3923 * Return this IO back to host
3925 spin_lock_irqsave(&vis_ha->list_lock, flags);
3927 if (sp->state == SRB_PENDING_STATE) {
3928 __del_from_pending_queue(vis_ha, sp);
3929 DEBUG2(printk("scsi(%ld): Found in Pending queue pid %ld, "
3930 "State = %x., fcport state=%d jiffies=%lx\n",
3931 vis_ha->host_no, cmd->serial_number, sp->state,
3932 atomic_read(&fcport->state), jiffies));
3935 * If FC_DEVICE is marked as dead return the cmd with
3936 * DID_NO_CONNECT status. Otherwise set the host_byte to
3937 * DID_BUS_BUSY to let the OS retry this cmd.
3939 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
3940 atomic_read(&vis_ha->loop_state) == LOOP_DEAD) {
3941 cmd->result = DID_NO_CONNECT << 16;
3943 cmd->result = DID_BUS_BUSY << 16;
3945 __add_to_done_queue(vis_ha, sp);
3948 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
3951 qla2x00_done(vis_ha);
3955 spin_lock_irqsave(&dest_ha->list_lock, flags);
3956 if ((sp->state == SRB_RETRY_STATE) ||
3957 (sp->state == SRB_SCSI_RETRY_STATE)) {
3959 DEBUG2(printk("scsi(%ld): Found in (Scsi) Retry queue or "
3960 "failover Q pid %ld, State = %x., fcport state=%d "
3961 "jiffies=%lx retried=%d\n",
3962 dest_ha->host_no, cmd->serial_number, sp->state,
3963 atomic_read(&fcport->state), jiffies, cmd->retries));
3965 if ((sp->state == SRB_RETRY_STATE)) {
3966 __del_from_retry_queue(dest_ha, sp);
3967 } else if ((sp->state == SRB_SCSI_RETRY_STATE)) {
3968 __del_from_scsi_retry_queue(dest_ha, sp);
3972 * If FC_DEVICE is marked as dead return the cmd with
3973 * DID_NO_CONNECT status. Otherwise set the host_byte to
3974 * DID_BUS_BUSY to let the OS retry this cmd.
3976 if ((atomic_read(&fcport->state) == FCS_DEVICE_DEAD) ||
3977 atomic_read(&dest_ha->loop_state) == LOOP_DEAD) {
3978 qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT);
3979 cmd->result = DID_NO_CONNECT << 16;
3981 cmd->result = DID_BUS_BUSY << 16;
3984 __add_to_done_queue(dest_ha, sp);
3987 spin_unlock_irqrestore(&dest_ha->list_lock, flags);
3990 qla2x00_done(dest_ha);
3994 /* TODO: Remove this code!!! */
3995 #if defined(QL_DEBUG_LEVEL_3)
3996 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
3997 if (sp->state == SRB_DONE_STATE) {
3998 /* IO in done_q -- leave it */
3999 DEBUG(printk("scsi(%ld): Found in Done queue pid %ld sp=%p.\n",
4000 dest_ha->host_no, cmd->serial_number, sp));
4001 } else if (sp->state == SRB_SUSPENDED_STATE) {
4002 DEBUG(printk("scsi(%ld): Found SP %p in suspended state "
4004 dest_ha->host_no, sp, cmd->serial_number));
4005 DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));)
4006 } else if (sp->state == SRB_ACTIVE_STATE) {
4008 * IO is with ISP find the command in our active list.
4010 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4011 spin_lock_irqsave(&dest_ha->hardware_lock, flags);
4013 dest_ha->outstanding_cmds[(u_long)sp->cmd->host_scribble]) {
4015 DEBUG(printk("cmd_timeout: Found in ISP \n");)
4017 sp->state = SRB_ACTIVE_TIMEOUT_STATE;
4018 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4020 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4022 "qla_cmd_timeout: State indicates it is with "
4023 "ISP, But not in active array\n");
4025 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags); /* 01/03 */
4026 } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) {
4027 DEBUG(printk("qla2100%ld: Found in Active timeout state"
4028 "pid %ld, State = %x., \n",
4030 sp->cmd->serial_number, sp->state);)
4033 DEBUG2(printk("cmd_timeout%ld: LOST command state = "
4035 vis_ha->host_no, sp->state,sp);)
4037 qla_printk(KERN_INFO, vis_ha,
4038 "cmd_timeout: LOST command state = 0x%x\n", sp->state);
4040 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4043 DEBUG3(printk("cmd_timeout: Leaving\n");)
4046 /**************************************************************************
4048 * Process completed commands.
4051 * old_ha = adapter block pointer.
4053 **************************************************************************/
4055 qla2x00_done(scsi_qla_host_t *old_ha)
4058 struct scsi_cmnd *cmd;
4059 unsigned long flags = 0;
4060 scsi_qla_host_t *ha;
4061 scsi_qla_host_t *vis_ha;
4062 int send_marker_once = 0;
4064 LIST_HEAD(local_sp_list);
4067 * Get into local queue such that we do not wind up calling done queue
4068 * tasklet for the same IOs from DPC or any other place.
4070 spin_lock_irqsave(&old_ha->list_lock, flags);
4071 list_splice_init(&old_ha->done_queue, &local_sp_list);
4072 spin_unlock_irqrestore(&old_ha->list_lock, flags);
4075 * All done commands are in the local queue, now do the call back.
4077 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4078 old_ha->done_q_cnt--;
4079 sp->state = SRB_NO_QUEUE_STATE;
4081 /* remove command from local list */
4082 list_del_init(&sp->list);
4088 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
4092 if (sp->flags & SRB_DMA_VALID) {
4093 sp->flags &= ~SRB_DMA_VALID;
4095 /* Release memory used for this I/O */
4097 pci_unmap_sg(ha->pdev, cmd->request_buffer,
4098 cmd->use_sg, cmd->sc_data_direction);
4099 } else if (cmd->request_bufflen) {
4100 pci_unmap_page(ha->pdev, sp->dma_handle,
4101 cmd->request_bufflen,
4102 cmd->sc_data_direction);
4107 switch (host_byte(cmd->result)) {
4114 * Set marker needed, so we don't have to
4115 * send multiple markers
4117 if (!send_marker_once) {
4118 ha->marker_needed = 1;
4125 * A backdoor device-reset requires different
4126 * error handling. This code differentiates
4127 * between normal error handling and the
4131 if (ha->host->eh_active != EH_ACTIVE)
4132 cmd->result = DID_BUS_BUSY << 16;
4137 sp->flags &= ~SRB_ABORT_PENDING;
4138 sp->flags |= SRB_ABORTED;
4140 if (sp->flags & SRB_TIMEOUT)
4141 cmd->result = DID_TIME_OUT << 16;
4146 DEBUG2(printk("scsi(%ld:%d:%d) %s: did_error "
4147 "= %d, comp-scsi= 0x%x-0x%x.\n",
4149 cmd->device->id, cmd->device->lun,
4151 host_byte(cmd->result),
4152 CMD_COMPL_STATUS(cmd),
4153 CMD_SCSI_STATUS(cmd)));
4158 * Call the mid-level driver interrupt handler -- via sp_put()
4161 } /* end of while */
4165 * qla2x00_process_response_queue_in_zio_mode
4166 * Process response queue completion as fast as possible
4167 * to achieve Zero Interrupt Opertions-ZIO
4170 * ha = adapter block pointer.
4176 qla2x00_process_response_queue_in_zio_mode(scsi_qla_host_t *ha)
4178 unsigned long flags;
4180 /* Check for unprocessed commands in response queue. */
4181 if (!ha->flags.process_response_queue)
4183 if (!ha->flags.online)
4185 if (ha->response_ring_ptr->signature == RESPONSE_PROCESSED)
4188 spin_lock_irqsave(&ha->hardware_lock,flags);
4189 qla2x00_process_response_queue(ha);
4190 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4192 if (!list_empty(&ha->done_queue))
4198 * Retrieve and process next job in the LUN queue.
4201 * tq = SCSI target queue pointer.
4202 * lq = SCSI LUN queue pointer.
4203 * TGT_LOCK must be already obtained.
4206 * Releases TGT_LOCK upon exit.
4209 * Kernel/Interrupt context.
4211 * Note: This routine will always try to start I/O from visible HBA.
4214 qla2x00_next(scsi_qla_host_t *vis_ha)
4217 unsigned long flags;
4218 scsi_qla_host_t *dest_ha;
4221 LIST_HEAD(local_sp_list);
4225 spin_lock_irqsave(&vis_ha->list_lock, flags);
4226 list_splice_init(&vis_ha->pending_queue, &local_sp_list);
4227 vis_ha->qthreads = 0;
4228 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
4230 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4231 list_del_init(&sp->list);
4232 sp->state = SRB_NO_QUEUE_STATE;
4234 fcport = sp->fclun->fcport;
4235 dest_ha = fcport->ha;
4237 /* If device is dead then send request back to OS */
4238 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
4240 sp->cmd->result = DID_NO_CONNECT << 16;
4242 if (!atomic_read(&dest_ha->loop_down_timer) &&
4243 atomic_read(&dest_ha->loop_state) == LOOP_DOWN) {
4248 DEBUG3(printk("scsi(%ld): loop/port is down - "
4249 "pid=%ld, sp=%p loopid=0x%x queued to dest HBA "
4252 sp->cmd->serial_number, sp,
4253 fcport->loop_id, dest_ha->host_no));
4255 * Initiate a failover - done routine will initiate.
4257 add_to_done_queue(vis_ha, sp);
4263 * SCSI Kluge: Whenever, we need to wait for an event such as
4264 * loop down (i.e. loop_down_timer ) or port down (i.e. LUN
4265 * request qeueue is suspended) then we will recycle new
4266 * commands back to the SCSI layer. We do this because this is
4267 * normally a temporary condition and we don't want the
4268 * mid-level scsi.c driver to get upset and start aborting
4269 * commands. The timeout value is extracted from the command
4270 * minus 1-second and put on a retry queue (watchdog). Once the
4271 * command timeout it is returned to the mid-level with a BUSY
4272 * status, so the mid-level will retry it. This process
4273 * continues until the LOOP DOWN time expires or the condition
4276 if (!(sp->flags & SRB_IOCTL) &&
4277 (atomic_read(&fcport->state) != FCS_ONLINE ||
4278 test_bit(ABORT_ISP_ACTIVE, &dest_ha->dpc_flags) ||
4279 atomic_read(&dest_ha->loop_state) != LOOP_READY)) {
4281 DEBUG3(printk("scsi(%ld): port=(0x%x) retry_q(%d) "
4282 "loop state = %d, loop counter = 0x%x dpc flags "
4286 atomic_read(&fcport->state),
4287 atomic_read(&dest_ha->loop_state),
4288 atomic_read(&dest_ha->loop_down_timer),
4289 dest_ha->dpc_flags));
4291 qla2x00_extend_timeout(sp->cmd, EXTEND_CMD_TIMEOUT);
4292 add_to_retry_queue(vis_ha, sp);
4298 * If this request's lun is suspended then put the request on
4299 * the scsi_retry queue.
4301 if (!(sp->flags & SRB_IOCTL) &&
4302 sp->lun_queue->q_state == LUN_STATE_WAIT) {
4303 DEBUG3(printk("scsi(%ld): lun wait state - pid=%ld, "
4304 "opcode=%d, allowed=%d, retries=%d\n",
4306 sp->cmd->serial_number,
4311 add_to_scsi_retry_queue(vis_ha, sp);
4316 sp->lun_queue->io_cnt++;
4318 rval = qla2x00_start_scsi(sp);
4319 if (rval != QLA_SUCCESS) {
4320 /* Place request back on top of device queue */
4321 /* add to the top of queue */
4322 add_to_pending_queue_head(vis_ha, sp);
4324 sp->lun_queue->io_cnt--;
4328 if (!IS_QLA2100(vis_ha) && !IS_QLA2200(vis_ha)) {
4329 /* Process response_queue if ZIO support is enabled*/
4330 qla2x00_process_response_queue_in_zio_mode(vis_ha);
4336 /**************************************************************************
4337 * qla2x00_check_tgt_status
4340 * Checks to see if the target or loop is down.
4343 * cmd - pointer to Scsi cmd structure
4346 * 1 - if target is present
4347 * 0 - if target is not present
4349 **************************************************************************/
4351 qla2x00_check_tgt_status(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
4354 unsigned int b, t, l;
4357 /* Generate LU queue on bus, target, LUN */
4358 b = cmd->device->channel;
4359 t = cmd->device->id;
4360 l = cmd->device->lun;
4362 if ((lq = GET_LU_Q(ha,t,l)) == NULL) {
4363 return (QLA_FUNCTION_FAILED);
4366 fcport = lq->fclun->fcport;
4368 if (TGT_Q(ha, t) == NULL ||
4369 l >= ha->max_luns ||
4370 atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4371 atomic_read(&ha->loop_state) == LOOP_DEAD ||
4372 (!atomic_read(&ha->loop_down_timer) &&
4373 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4374 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
4375 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4376 atomic_read(&ha->loop_state) != LOOP_READY) {
4378 DEBUG(printk(KERN_INFO
4379 "scsi(%ld:%2d:%2d:%2d): %s connection is down\n",
4384 cmd->result = DID_NO_CONNECT << 16;
4385 return (QLA_FUNCTION_FAILED);
4387 return (QLA_SUCCESS);
4390 /**************************************************************************
4391 * qla2x00_check_port_status
4394 * Checks to see if the port or loop is down.
4397 * fcport - pointer to fc_port_t structure.
4400 * 1 - if port is present
4401 * 0 - if port is not present
4403 **************************************************************************/
4405 qla2x00_check_port_status(scsi_qla_host_t *ha, fc_port_t *fcport)
4407 if (fcport == NULL) {
4408 return (QLA_FUNCTION_FAILED);
4411 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4412 atomic_read(&ha->loop_state) == LOOP_DEAD) {
4413 return (QLA_FUNCTION_FAILED);
4416 if ((atomic_read(&fcport->state) != FCS_ONLINE) ||
4417 (!atomic_read(&ha->loop_down_timer) &&
4418 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4419 (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) ||
4420 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
4421 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4422 atomic_read(&ha->loop_state) != LOOP_READY) {
4424 DEBUG(printk(KERN_INFO
4425 "scsi(%ld): Connection is down. fcport=%p.\n",
4426 ha->host_no, fcport));
4431 return (QLA_SUCCESS);
4434 /* XXX(hch): crude hack to emulate a down_timeout() */
4436 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
4438 const unsigned int step = HZ/10;
4441 if (!down_trylock(sema))
4443 set_current_state(TASK_INTERRUPTIBLE);
4444 if (schedule_timeout(step))
4446 } while ((timeout -= step) > 0);
4452 * qla2x00_module_init - Module initialization.
4455 qla2x00_module_init(void)
4457 /* Derive version string. */
4458 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4460 strcat(qla2x00_version_str, "-debug");
4463 /* Allocate cache for SRBs. */
4464 sprintf(srb_cachep_name, "qla2xxx_srbs");
4465 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
4466 SLAB_HWCACHE_ALIGN, NULL, NULL);
4467 if (srb_cachep == NULL) {
4469 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4474 "QLogic Fibre Channel HBA Driver (%p)\n", qla2x00_set_info);
4480 * qla2x00_module_exit - Module cleanup.
4483 qla2x00_module_exit(void)
4485 /* Free SRBs cache. */
4486 if (srb_cachep != NULL) {
4487 if (kmem_cache_destroy(srb_cachep) != 0) {
4489 "qla2xxx: Unable to free SRB cache...Memory pools "
4496 module_init(qla2x00_module_init);
4497 module_exit(qla2x00_module_exit);
4499 MODULE_AUTHOR("QLogic Corporation");
4500 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4501 MODULE_LICENSE("GPL");