2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/moduleparam.h>
22 #include <linux/vmalloc.h>
23 #include <linux/smp_lock.h>
24 #include <linux/delay.h>
26 #include <scsi/scsi_tcq.h>
27 #include <scsi/scsicam.h>
28 #include <scsi/scsi_transport.h>
29 #include <scsi/scsi_transport_fc.h>
34 char qla2x00_version_str[40];
37 * SRB allocation cache
39 char srb_cachep_name[16];
40 kmem_cache_t *srb_cachep;
43 * Stats for all adpaters.
45 struct _qla2x00stats qla2x00_stats;
48 * Ioctl related information.
54 * Module parameter information and variables
57 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
58 MODULE_PARM_DESC(ql2xmaxqdepth,
59 "Maximum queue depth to report for target devices.");
61 int ql2xlogintimeout = 20;
62 module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
63 MODULE_PARM_DESC(ql2xlogintimeout,
64 "Login timeout value in seconds.");
66 int qlport_down_retry;
67 module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
68 MODULE_PARM_DESC(qlport_down_retry,
69 "Maximum number of command retries to a port that returns"
70 "a PORT-DOWN status.");
72 int ql2xretrycount = 20;
73 module_param(ql2xretrycount, int, S_IRUGO|S_IWUSR);
74 MODULE_PARM_DESC(ql2xretrycount,
75 "Maximum number of mid-layer retries allowed for a command. "
76 "Default value is 20, ");
79 module_param(displayConfig, int, S_IRUGO|S_IWUSR);
80 MODULE_PARM_DESC(displayConfig,
81 "If 1 then display the configuration used in /etc/modprobe.conf.");
83 int ql2xplogiabsentdevice;
84 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
85 MODULE_PARM_DESC(ql2xplogiabsentdevice,
86 "Option to enable PLOGI to devices that are not present after "
87 "a Fabric scan. This is needed for several broken switches."
88 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
90 int ql2xenablezio = 0;
91 module_param(ql2xenablezio, int, S_IRUGO|S_IRUSR);
92 MODULE_PARM_DESC(ql2xenablezio,
93 "Option to enable ZIO:If 1 then enable it otherwise"
94 " use the default set in the NVRAM."
95 " Default is 0 : disabled");
97 int ql2xintrdelaytimer = 10;
98 module_param(ql2xintrdelaytimer, int, S_IRUGO|S_IRUSR);
99 MODULE_PARM_DESC(ql2xintrdelaytimer,
100 "ZIO: Waiting time for Firmware before it generates an "
101 "interrupt to the host to notify completion of request.");
104 module_param(ConfigRequired, int, S_IRUGO|S_IRUSR);
105 MODULE_PARM_DESC(ConfigRequired,
106 "If 1, then only configured devices passed in through the"
107 "ql2xopts parameter will be presented to the OS");
109 int Bind = BIND_BY_PORT_NAME;
110 module_param(Bind, int, S_IRUGO|S_IRUSR);
111 MODULE_PARM_DESC(Bind,
112 "Target persistent binding method: "
113 "0 by Portname (default); 1 by PortID; 2 by Nodename. ");
115 int ql2xsuspendcount = SUSPEND_COUNT;
116 module_param(ql2xsuspendcount, int, S_IRUGO|S_IWUSR);
117 MODULE_PARM_DESC(ql2xsuspendcount,
118 "Number of 6-second suspend iterations to perform while a "
119 "target returns a <NOT READY> status. Default is 10 "
122 int ql2xdoinitscan = 1;
123 module_param(ql2xdoinitscan, int, S_IRUGO|S_IWUSR);
124 MODULE_PARM_DESC(ql2xdoinitscan,
125 "Signal mid-layer to perform scan after driver load: 0 -- no "
126 "signal sent to mid-layer.");
128 int ql2xloginretrycount = 0;
129 module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
130 MODULE_PARM_DESC(ql2xloginretrycount,
131 "Specify an alternate value for the NVRAM login retry count.");
134 * Proc structures and functions
143 static void copy_mem_info(struct info_str *, char *, int);
144 static int copy_info(struct info_str *, char *, ...);
146 static void qla2x00_free_device(scsi_qla_host_t *);
148 static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
151 * SCSI host template entry points
153 static int qla2xxx_slave_configure(struct scsi_device * device);
154 static int qla2xxx_eh_abort(struct scsi_cmnd *);
155 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
156 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
157 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
158 static int qla2x00_loop_reset(scsi_qla_host_t *ha);
159 static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
161 static int qla2x00_proc_info(struct Scsi_Host *, char *, char **,
164 static struct scsi_host_template qla2x00_driver_template = {
165 .module = THIS_MODULE,
167 .proc_name = "qla2xxx",
168 .proc_info = qla2x00_proc_info,
169 .queuecommand = qla2x00_queuecommand,
171 .eh_abort_handler = qla2xxx_eh_abort,
172 .eh_device_reset_handler = qla2xxx_eh_device_reset,
173 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
174 .eh_host_reset_handler = qla2xxx_eh_host_reset,
176 .slave_configure = qla2xxx_slave_configure,
180 .use_clustering = ENABLE_CLUSTERING,
181 .sg_tablesize = SG_ALL,
184 * The RISC allows for each command to transfer (2^32-1) bytes of data,
185 * which equates to 0x800000 sectors.
187 .max_sectors = 0xFFFF,
190 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
192 static void qla2x00_display_fc_names(scsi_qla_host_t *);
194 /* TODO Convert to inlines
198 #define WATCH_INTERVAL 1 /* number of seconds */
200 static void qla2x00_timer(scsi_qla_host_t *);
202 static __inline__ void qla2x00_start_timer(scsi_qla_host_t *,
203 void *, unsigned long);
204 static __inline__ void qla2x00_restart_timer(scsi_qla_host_t *, unsigned long);
205 static __inline__ void qla2x00_stop_timer(scsi_qla_host_t *);
208 qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval)
210 init_timer(&ha->timer);
211 ha->timer.expires = jiffies + interval * HZ;
212 ha->timer.data = (unsigned long)ha;
213 ha->timer.function = (void (*)(unsigned long))func;
214 add_timer(&ha->timer);
215 ha->timer_active = 1;
219 qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval)
221 mod_timer(&ha->timer, jiffies + interval * HZ);
224 static __inline__ void
225 qla2x00_stop_timer(scsi_qla_host_t *ha)
227 del_timer_sync(&ha->timer);
228 ha->timer_active = 0;
231 void qla2x00_cmd_timeout(srb_t *);
233 static __inline__ void qla2x00_callback(scsi_qla_host_t *, struct scsi_cmnd *);
234 static __inline__ void sp_put(struct scsi_qla_host * ha, srb_t *sp);
235 static __inline__ void sp_get(struct scsi_qla_host * ha, srb_t *sp);
236 static __inline__ void
237 qla2x00_delete_from_done_queue(scsi_qla_host_t *, srb_t *);
241 * Returns the completed SCSI command to LINUX.
244 * ha -- Host adapter structure
245 * cmd -- SCSI mid-level command structure.
248 * Note:From failover point of view we always get the sp
249 * from vis_ha pool in queuecommand.So when we put it
250 * back to the pool it has to be the vis_ha.
251 * So rely on struct scsi_cmnd to get the vis_ha and not on sp.
254 qla2x00_callback(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
256 srb_t *sp = (srb_t *) CMD_SP(cmd);
257 scsi_qla_host_t *vis_ha;
260 unsigned long cpu_flags = 0;
262 cmd->host_scribble = (unsigned char *) NULL;
263 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
266 qla_printk(KERN_INFO, ha,
267 "%s(): **** CMD derives a NULL SP\n",
274 * If command status is not DID_BUS_BUSY then go ahead and freed sp.
277 * Cancel command timeout
279 qla2x00_delete_timer_from_cmd(sp);
282 * Put SP back in the free queue
287 got_sense = (sp->flags & SRB_GOT_SENSE)? 1: 0;
288 add_to_free_queue(vis_ha, sp);
290 if (host_byte(cmd->result) == DID_OK) {
292 ha->total_bytes += cmd->bufflen;
294 /* If lun was suspended then clear retry count */
295 spin_lock_irqsave(&lq->q_lock, cpu_flags);
296 if (!test_bit(LUN_EXEC_DELAYED, &lq->q_flag))
297 lq->q_state = LUN_STATE_READY;
298 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
300 } else if (host_byte(cmd->result) == DID_ERROR) {
302 ha->total_dev_errs++;
305 /* Call the mid-level driver interrupt handler */
306 (*(cmd)->scsi_done)(cmd);
309 /**************************************************************************
313 * Decrement reference count and call the callback if we're the last
314 * owner of the specified sp. Will get the host_lock before calling
318 * ha - pointer to the scsi_qla_host_t where the callback is to occur.
319 * sp - pointer to srb_t structure to use.
323 **************************************************************************/
325 sp_put(struct scsi_qla_host * ha, srb_t *sp)
327 if (atomic_read(&sp->ref_count) == 0) {
328 qla_printk(KERN_INFO, ha,
329 "%s(): **** SP->ref_count not zero\n",
336 if (!atomic_dec_and_test(&sp->ref_count)) {
340 qla2x00_callback(ha, sp->cmd);
343 /**************************************************************************
347 * Increment reference count of the specified sp.
350 * sp - pointer to srb_t structure to use.
354 **************************************************************************/
356 sp_get(struct scsi_qla_host * ha, srb_t *sp)
358 atomic_inc(&sp->ref_count);
360 if (atomic_read(&sp->ref_count) > 2) {
361 qla_printk(KERN_INFO, ha,
362 "%s(): **** SP->ref_count greater than two\n",
371 qla2x00_delete_from_done_queue(scsi_qla_host_t *dest_ha, srb_t *sp)
373 /* remove command from done list */
374 list_del_init(&sp->list);
375 dest_ha->done_q_cnt--;
376 sp->state = SRB_NO_QUEUE_STATE;
378 if (sp->flags & SRB_DMA_VALID) {
379 sp->flags &= ~SRB_DMA_VALID;
381 /* Release memory used for this I/O */
382 if (sp->cmd->use_sg) {
383 pci_unmap_sg(dest_ha->pdev, sp->cmd->request_buffer,
384 sp->cmd->use_sg, sp->cmd->sc_data_direction);
385 } else if (sp->cmd->request_bufflen) {
386 pci_unmap_page(dest_ha->pdev, sp->dma_handle,
387 sp->cmd->request_bufflen,
388 sp->cmd->sc_data_direction);
393 static int qla2x00_do_dpc(void *data);
395 static void qla2x00_rst_aen(scsi_qla_host_t *);
397 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
398 static void qla2x00_mem_free(scsi_qla_host_t *ha);
399 int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
400 void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
402 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *, char *, loff_t,
404 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *, char *, loff_t,
406 static struct bin_attribute sysfs_fw_dump_attr = {
409 .mode = S_IRUSR | S_IWUSR,
410 .owner = THIS_MODULE,
413 .read = qla2x00_sysfs_read_fw_dump,
414 .write = qla2x00_sysfs_write_fw_dump,
416 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *, char *, loff_t,
418 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *, char *, loff_t,
420 static struct bin_attribute sysfs_nvram_attr = {
423 .mode = S_IRUSR | S_IWUSR,
424 .owner = THIS_MODULE,
426 .size = sizeof(nvram_t),
427 .read = qla2x00_sysfs_read_nvram,
428 .write = qla2x00_sysfs_write_nvram,
433 qla2x00_set_info(char *buffer, int length, struct Scsi_Host *shost)
435 return (-ENOSYS); /* Currently this is a no-op */
438 /* -------------------------------------------------------------------------- */
441 /* SysFS attributes. */
442 static ssize_t qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf,
443 loff_t off, size_t count)
445 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
446 struct device, kobj)));
448 if (ha->fw_dump_reading == 0)
450 if (off > ha->fw_dump_buffer_len)
452 if (off + count > ha->fw_dump_buffer_len)
453 count = ha->fw_dump_buffer_len - off;
455 memcpy(buf, &ha->fw_dump_buffer[off], count);
460 static ssize_t qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf,
461 loff_t off, size_t count)
463 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
464 struct device, kobj)));
471 reading = simple_strtol(buf, NULL, 10);
474 if (ha->fw_dump_reading == 1) {
475 qla_printk(KERN_INFO, ha,
476 "Firmware dump cleared on (%ld).\n",
479 vfree(ha->fw_dump_buffer);
480 free_pages((unsigned long)ha->fw_dump,
483 ha->fw_dump_reading = 0;
484 ha->fw_dump_buffer = NULL;
489 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
490 ha->fw_dump_reading = 1;
492 dump_size = FW_DUMP_SIZE_1M;
493 if (ha->fw_memory_size < 0x20000)
494 dump_size = FW_DUMP_SIZE_128K;
495 else if (ha->fw_memory_size < 0x80000)
496 dump_size = FW_DUMP_SIZE_512K;
497 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
498 if (ha->fw_dump_buffer == NULL) {
499 qla_printk(KERN_WARNING, ha,
500 "Unable to allocate memory for firmware "
501 "dump buffer (%d).\n", dump_size);
503 ha->fw_dump_reading = 0;
506 qla_printk(KERN_INFO, ha,
507 "Firmware dump ready for read on (%ld).\n",
509 memset(ha->fw_dump_buffer, 0, dump_size);
510 if (IS_QLA2100(ha) || IS_QLA2200(ha))
511 qla2100_ascii_fw_dump(ha);
513 qla2300_ascii_fw_dump(ha);
514 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
521 static ssize_t qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf,
522 loff_t off, size_t count)
524 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
525 struct device, kobj)));
530 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
534 spin_lock_irqsave(&ha->hardware_lock, flags);
535 qla2x00_lock_nvram_access(ha);
536 witer = (uint16_t *)buf;
537 for (cnt = 0; cnt < count / 2; cnt++) {
538 *witer = cpu_to_le16(qla2x00_get_nvram_word(ha,
539 cnt+ha->nvram_base));
542 qla2x00_unlock_nvram_access(ha);
543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
548 static ssize_t qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf,
549 loff_t off, size_t count)
551 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
552 struct device, kobj)));
559 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
562 /* Checksum NVRAM. */
563 iter = (uint8_t *)buf;
565 for (cnt = 0; cnt < count - 1; cnt++)
567 chksum = ~chksum + 1;
571 spin_lock_irqsave(&ha->hardware_lock, flags);
572 qla2x00_lock_nvram_access(ha);
573 witer = (uint16_t *)buf;
574 for (cnt = 0; cnt < count / 2; cnt++) {
575 qla2x00_write_nvram_word(ha, cnt+ha->nvram_base,
576 cpu_to_le16(*witer));
579 qla2x00_unlock_nvram_access(ha);
580 spin_unlock_irqrestore(&ha->hardware_lock, flags);
585 /* -------------------------------------------------------------------------- */
587 qla2x00_get_pci_info_str(struct scsi_qla_host *ha, char *str)
589 static char *pci_bus_modes[] = {
590 "33", "66", "100", "133",
595 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
598 strcat(str, pci_bus_modes[pci_bus]);
600 pci_bus = (ha->pci_attr & BIT_8) >> 8;
602 strcat(str, pci_bus_modes[pci_bus]);
604 strcat(str, " MHz)");
610 qla2x00_get_fw_version_str(struct scsi_qla_host *ha, char *str)
614 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
615 ha->fw_minor_version,
616 ha->fw_subminor_version);
618 if (ha->fw_attributes & BIT_9) {
623 switch (ha->fw_attributes & 0xFF) {
637 sprintf(un_str, "(%x)", ha->fw_attributes);
641 if (ha->fw_attributes & 0x100)
647 /**************************************************************************
648 * qla2x00_queuecommand
651 * Queue a command to the controller.
654 * cmd - pointer to Scsi cmd structure
655 * fn - pointer to Scsi done function
661 * The mid-level driver tries to ensures that queuecommand never gets invoked
662 * concurrently with itself or the interrupt handler (although the
663 * interrupt handler may call this routine as part of request-completion
665 **************************************************************************/
667 qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
672 scsi_qla_host_t *ha, *ha2;
674 struct Scsi_Host *host;
675 unsigned int b, t, l;
676 unsigned long handle;
680 host = cmd->device->host;
681 ha = (scsi_qla_host_t *) host->hostdata;
686 spin_unlock_irq(ha->host->host_lock);
689 * Allocate a command packet from the "sp" pool. If we cant get back
690 * one then let scsi layer come back later.
692 if ((sp = qla2x00_get_new_sp(ha)) == NULL) {
693 qla_printk(KERN_WARNING, ha,
694 "Couldn't allocate memory for sp - retried.\n");
696 spin_lock_irq(ha->host->host_lock);
702 CMD_SP(cmd) = (void *)sp;
705 if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {
706 /* Need to set sp->flags */
707 sp->flags |= SRB_IOCTL;
708 CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */
711 sp->fo_retry_cnt = 0;
714 /* Generate LU queue on bus, target, LUN */
715 b = cmd->device->channel;
717 l = cmd->device->lun;
720 * Start Command Timer. Typically it will be 2 seconds less than what
721 * is requested by the Host such that we can return the IO before
724 if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)
725 qla2x00_add_timer_to_cmd(sp,
726 (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
728 qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);
730 if (l >= ha->max_luns) {
731 cmd->result = DID_NO_CONNECT << 16;
732 sp->err_id = SRB_ERR_PORT;
734 spin_lock_irq(ha->host->host_lock);
741 if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&
742 (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {
743 fcport = lq->fclun->fcport;
751 /* Set an invalid handle until we issue the command to ISP */
752 /* then we will set the real handle value. */
753 handle = INVALID_HANDLE;
754 cmd->host_scribble = (unsigned char *)handle;
756 /* Bookkeeping information */
757 sp->r_start = jiffies; /* time the request was received */
760 /* Setup device queue pointers. */
767 * 1. When device is added from persistent binding but has not been
768 * discovered yet.The state of loopid == PORT_AVAIL.
769 * 2. When device is never found on the bus.(loopid == UNUSED)
771 * IF Device Queue is not created, or device is not in a valid state
772 * and link down error reporting is enabled, reject IO.
774 if (fcport == NULL) {
775 DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",
778 cmd->result = DID_NO_CONNECT << 16;
779 sp->err_id = SRB_ERR_PORT;
781 spin_lock_irq(ha->host->host_lock);
788 /* Only modify the allowed count if the target is a *non* tape device */
789 if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {
790 sp->flags &= ~SRB_TAPE;
791 if (cmd->allowed < ql2xretrycount) {
792 cmd->allowed = ql2xretrycount;
795 sp->flags |= SRB_TAPE;
798 DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "
799 "flags=0x%x fo retry=%d, pid=%ld\n",
800 ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,
801 cmd->serial_number));
802 DEBUG5(qla2x00_print_scsi_cmd(cmd));
804 sp->fclun = lq->fclun;
807 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&
808 cmd->request_bufflen != 0) {
810 DEBUG2(printk(KERN_WARNING
811 "scsi(%ld): Incorrect data direction - transfer "
812 "length=%d, direction=%d, pid=%ld, opcode=%x\n",
813 ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,
814 cmd->serial_number, cmd->cmnd[0]));
819 * Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.
821 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
822 atomic_read(&ha2->loop_state) == LOOP_DEAD) {
824 * Add the command to the done-queue for later failover
827 cmd->result = DID_NO_CONNECT << 16;
828 if (atomic_read(&ha2->loop_state) == LOOP_DOWN)
829 sp->err_id = SRB_ERR_LOOP;
831 sp->err_id = SRB_ERR_PORT;
833 add_to_done_queue(ha, sp);
836 spin_lock_irq(ha->host->host_lock);
839 if (tq && test_bit(TQF_SUSPENDED, &tq->flags) &&
840 (sp->flags & SRB_TAPE) == 0) {
841 /* If target suspended put incoming I/O in retry_q. */
842 qla2x00_extend_timeout(sp->cmd, 10);
843 add_to_scsi_retry_queue(ha, sp);
845 was_empty = add_to_pending_queue(ha, sp);
847 if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {
848 if (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {
851 spin_lock_irqsave(&ha->hardware_lock, flags);
852 qla2x00_process_response_queue(ha);
853 spin_unlock_irqrestore(&ha->hardware_lock, flags);
857 /* We submit to the hardware if:
859 * 1) we're on the cpu the irq's arrive on or
860 * 2) there are very few io's outstanding.
862 * In all other cases we'll let an irq pick up our IO and submit it
863 * to the controller to improve affinity.
865 if (smp_processor_id() == ha->last_irq_cpu || was_empty)
868 spin_lock_irq(ha->host->host_lock);
874 * qla2x00_eh_wait_on_command
875 * Waits for the command to be returned by the Firmware for some
879 * ha = actual ha whose done queue will contain the command
880 * returned by firmware.
881 * cmd = Scsi Command to wait on.
882 * flag = Abort/Reset(Bus or Device Reset)
889 qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
891 #define ABORT_POLLING_PERIOD HZ
892 #define ABORT_WAIT_TIME ((10 * HZ) / (ABORT_POLLING_PERIOD))
897 struct list_head *list, *temp;
898 u_long max_wait_time = ABORT_WAIT_TIME;
901 /* Check on done queue */
902 spin_lock(&ha->list_lock);
903 list_for_each_safe(list, temp, &ha->done_queue) {
904 rp = list_entry(list, srb_t, list);
907 * Found command. Just exit and wait for the cmd sent
910 if (cmd == rp->cmd) {
912 DEBUG3(printk("%s: found in done queue.\n",
917 spin_unlock(&ha->list_lock);
919 /* Complete the cmd right away. */
921 qla2x00_delete_from_done_queue(ha, rp);
927 spin_unlock_irq(ha->host->host_lock);
929 set_current_state(TASK_UNINTERRUPTIBLE);
930 schedule_timeout(ABORT_POLLING_PERIOD);
932 spin_lock_irq(ha->host->host_lock);
934 } while ((max_wait_time--));
937 DEBUG2(printk(KERN_INFO "%s: found cmd=%p.\n", __func__, cmd));
943 * qla2x00_wait_for_hba_online
944 * Wait till the HBA is online after going through
945 * <= MAX_RETRIES_OF_ISP_ABORT or
946 * finally HBA is disabled ie marked offline
949 * ha - pointer to host adapter structure
952 * Does context switching-Release SPIN_LOCK
953 * (if any) before calling this routine.
956 * Success (Adapter is online) : 0
957 * Failed (Adapter is offline/disabled) : 1
960 qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
963 unsigned long wait_online;
965 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
966 while (((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) ||
967 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
968 test_bit(ISP_ABORT_RETRY, &ha->dpc_flags) ||
969 ha->dpc_active) && time_before(jiffies, wait_online)) {
973 if (ha->flags.online)
974 return_status = QLA_SUCCESS;
976 return_status = QLA_FUNCTION_FAILED;
978 DEBUG2(printk("%s return_status=%d\n",__func__,return_status));
980 return (return_status);
984 * qla2x00_wait_for_loop_ready
985 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
986 * to be in LOOP_READY state.
988 * ha - pointer to host adapter structure
991 * Does context switching-Release SPIN_LOCK
992 * (if any) before calling this routine.
996 * Success (LOOP_READY) : 0
997 * Failed (LOOP_NOT_READY) : 1
1000 qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
1002 int return_status = QLA_SUCCESS;
1003 unsigned long loop_timeout ;
1005 /* wait for 5 min at the max for loop to be ready */
1006 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1008 while ((!atomic_read(&ha->loop_down_timer) &&
1009 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
1010 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
1011 atomic_read(&ha->loop_state) != LOOP_READY) {
1013 if (time_after_eq(jiffies, loop_timeout)) {
1014 return_status = QLA_FUNCTION_FAILED;
1018 return (return_status);
1021 /**************************************************************************
1025 * The abort function will abort the specified command.
1028 * cmd = Linux SCSI command packet to be aborted.
1031 * Either SUCCESS or FAILED.
1034 **************************************************************************/
1036 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1039 int return_status = FAILED;
1041 scsi_qla_host_t *ha;
1042 scsi_qla_host_t *vis_ha;
1045 struct list_head *list, *temp;
1046 struct Scsi_Host *host;
1048 unsigned int b, t, l;
1050 /* Get the SCSI request ptr */
1051 sp = (srb_t *) CMD_SP(cmd);
1054 * If sp is NULL, command is already returned.
1055 * sp is NULLED just before we call back scsi_done
1059 /* no action - we don't have command */
1060 qla_printk(KERN_INFO, to_qla_host(cmd->device->host),
1061 "qla2xxx_eh_abort: cmd already done sp=%p\n", sp);
1062 DEBUG(printk("qla2xxx_eh_abort: cmd already done sp=%p\n", sp);)
1066 DEBUG(printk("qla2xxx_eh_abort: refcount %i \n",
1067 atomic_read(&sp->ref_count));)
1070 vis_ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1071 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1075 /* Generate LU queue on bus, target, LUN */
1076 b = cmd->device->channel;
1077 t = cmd->device->id;
1078 l = cmd->device->lun;
1079 q = GET_LU_Q(vis_ha, t, l);
1081 qla_printk(KERN_INFO, ha,
1082 "%s scsi(%ld:%d:%d:%d): cmd_timeout_in_sec=0x%x.\n", __func__,
1083 ha->host_no, (int)b, (int)t, (int)l,
1084 cmd->timeout_per_command / HZ);
1087 * if no LUN queue then something is very wrong!!!
1090 qla_printk(KERN_WARNING, ha,
1091 "qla2x00: (%x:%x:%x) No LUN queue.\n", b, t, l);
1093 /* no action - we don't have command */
1097 DEBUG2(printk("scsi(%ld): ABORTing cmd=%p sp=%p jiffies = 0x%lx, "
1098 "timeout=%x, dpc_flags=%lx, vis_ha->dpc_flags=%lx q->flag=%lx\n",
1099 ha->host_no, cmd, sp, jiffies, cmd->timeout_per_command / HZ,
1100 ha->dpc_flags, vis_ha->dpc_flags, q->q_flag));
1101 DEBUG2(qla2x00_print_scsi_cmd(cmd));
1103 spin_unlock_irq(ha->host->host_lock);
1104 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1105 DEBUG2(printk("%s failed:board disabled\n", __func__);)
1106 spin_lock_irq(ha->host->host_lock);
1109 spin_lock_irq(ha->host->host_lock);
1111 /* Search done queue */
1112 spin_lock(&ha->list_lock);
1113 list_for_each_safe(list, temp, &ha->done_queue) {
1114 rp = list_entry(list, srb_t, list);
1120 * Found command.Remove it from done list.
1121 * And proceed to post completion to scsi mid layer.
1123 return_status = SUCCESS;
1125 qla2x00_delete_from_done_queue(ha, sp);
1128 } /* list_for_each_safe() */
1129 spin_unlock(&ha->list_lock);
1132 * Return immediately if the aborted command was already in the done
1136 qla_printk(KERN_INFO, ha,
1137 "qla2xxx_eh_abort: Returning completed command=%p sp=%p\n",
1140 return (return_status);
1145 * See if this command is in the retry queue
1147 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p in retry "
1150 spin_lock(&ha->list_lock);
1151 list_for_each_safe(list, temp, &ha->retry_queue) {
1152 rp = list_entry(list, srb_t, list);
1158 DEBUG2(printk("qla2xxx_eh_abort: found "
1159 "in retry queue. SP=%p\n", sp);)
1161 __del_from_retry_queue(ha, rp);
1162 cmd->result = DID_ABORT << 16;
1163 __add_to_done_queue(ha, rp);
1165 return_status = SUCCESS;
1171 spin_unlock(&ha->list_lock);
1175 * Our SP pointer points at the command we want to remove from the
1176 * pending queue providing we haven't already sent it to the adapter.
1179 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1180 "in pending queue.\n", sp);)
1182 spin_lock(&vis_ha->list_lock);
1183 list_for_each_safe(list, temp, &vis_ha->pending_queue) {
1184 rp = list_entry(list, srb_t, list);
1189 /* Remove srb from LUN queue. */
1190 rp->flags |= SRB_ABORTED;
1192 DEBUG2(printk("qla2xxx_eh_abort: Cmd in pending queue."
1193 " serial_number %ld.\n",
1194 sp->cmd->serial_number);)
1196 __del_from_pending_queue(vis_ha, rp);
1197 cmd->result = DID_ABORT << 16;
1199 __add_to_done_queue(vis_ha, rp);
1201 return_status = SUCCESS;
1205 } /* list_for_each_safe() */
1206 spin_unlock(&vis_ha->list_lock);
1207 } /*End of if !found */
1209 if (!found) { /* find the command in our active list */
1210 DEBUG3(printk("qla2xxx_eh_abort: searching sp %p "
1211 "in outstanding queue.\n", sp);)
1213 spin_lock(&ha->hardware_lock);
1214 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
1215 sp = ha->outstanding_cmds[i];
1223 DEBUG2(printk("qla2xxx_eh_abort(%ld): aborting sp %p "
1224 "from RISC. pid=%ld sp->state=%x q->q_flag=%lx\n",
1225 ha->host_no, sp, sp->cmd->serial_number,
1226 sp->state, q->q_flag);)
1227 DEBUG(qla2x00_print_scsi_cmd(cmd);)
1229 /* Get a reference to the sp and drop the lock.*/
1232 spin_unlock(&ha->hardware_lock);
1233 spin_unlock_irq(ha->host->host_lock);
1235 if (qla2x00_abort_command(ha, sp)) {
1236 DEBUG2(printk("qla2xxx_eh_abort: abort_command "
1238 return_status = FAILED;
1240 DEBUG3(printk("qla2xxx_eh_abort: abort_command "
1241 " mbx success.\n");)
1242 return_status = SUCCESS;
1247 spin_lock_irq(ha->host->host_lock);
1248 spin_lock(&ha->hardware_lock);
1251 * Regardless of mailbox command status, go check on
1252 * done queue just in case the sp is already done.
1256 }/*End of for loop */
1257 spin_unlock(&ha->hardware_lock);
1259 } /*End of if !found */
1261 /* Waiting for our command in done_queue to be returned to OS.*/
1262 if (qla2x00_eh_wait_on_command(ha, cmd) != 0) {
1263 DEBUG2(printk("qla2xxx_eh_abort: cmd returned back to OS.\n");)
1264 return_status = SUCCESS;
1267 if (return_status == FAILED) {
1268 qla_printk(KERN_INFO, ha,
1269 "qla2xxx_eh_abort Exiting: status=Failed\n");
1273 DEBUG2(printk("qla2xxx_eh_abort: Exiting. return_status=0x%x.\n",
1276 return return_status;
1279 /**************************************************************************
1280 * qla2x00_eh_wait_for_pending_target_commands
1283 * Waits for all the commands to come back from the specified target.
1286 * ha - pointer to scsi_qla_host structure.
1289 * Either SUCCESS or FAILED.
1292 **************************************************************************/
1294 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
1299 struct scsi_cmnd *cmd;
1304 * Waiting for all commands for the designated target in the active
1307 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1308 spin_lock(&ha->hardware_lock);
1309 sp = ha->outstanding_cmds[cnt];
1312 spin_unlock(&ha->hardware_lock);
1313 if (cmd->device->id == t) {
1314 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
1321 spin_unlock(&ha->hardware_lock);
1328 /**************************************************************************
1329 * qla2xxx_eh_device_reset
1332 * The device reset function will reset the target and abort any
1333 * executing commands.
1335 * NOTE: The use of SP is undefined within this context. Do *NOT*
1336 * attempt to use this value, even if you determine it is
1340 * cmd = Linux SCSI command packet of the command that cause the
1344 * SUCCESS/FAILURE (defined as macro in scsi.h).
1346 **************************************************************************/
1348 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1351 unsigned int b, t, l;
1352 scsi_qla_host_t *ha;
1355 fc_port_t *fcport_to_reset;
1357 struct list_head *list, *temp;
1359 return_status = FAILED;
1362 "%s(): **** SCSI mid-layer passing in NULL cmd\n",
1365 return (return_status);
1368 b = cmd->device->channel;
1369 t = cmd->device->id;
1370 l = cmd->device->lun;
1371 ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1375 qla_printk(KERN_INFO, ha,
1376 "%s(): **** CMD derives a NULL TGT_Q\n", __func__);
1378 return (return_status);
1380 lq = (os_lun_t *)LUN_Q(ha, t, l);
1383 "%s(): **** CMD derives a NULL LUN_Q\n", __func__);
1385 return (return_status);
1387 fcport_to_reset = lq->fclun->fcport;
1389 /* If we are coming in from the back-door, stall I/O until complete. */
1390 if (!cmd->device->host->eh_active)
1391 set_bit(TQF_SUSPENDED, &tq->flags);
1393 qla_printk(KERN_INFO, ha,
1394 "scsi(%ld:%d:%d:%d): DEVICE RESET ISSUED.\n", ha->host_no, b, t, l);
1396 DEBUG2(printk(KERN_INFO
1397 "scsi(%ld): DEVICE_RESET cmd=%p jiffies = 0x%lx, timeout=%x, "
1398 "dpc_flags=%lx, status=%x allowed=%d cmd.state=%x\n",
1399 ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
1400 ha->dpc_flags, cmd->result, cmd->allowed, cmd->state));
1402 /* Clear commands from the retry queue. */
1403 spin_lock(&ha->list_lock);
1404 list_for_each_safe(list, temp, &ha->retry_queue) {
1405 rp = list_entry(list, srb_t, list);
1407 if (t != rp->cmd->device->id)
1410 DEBUG2(printk(KERN_INFO
1411 "qla2xxx_eh_reset: found in retry queue. SP=%p\n", rp));
1413 __del_from_retry_queue(ha, rp);
1414 rp->cmd->result = DID_RESET << 16;
1415 __add_to_done_queue(ha, rp);
1417 spin_unlock(&ha->list_lock);
1419 spin_unlock_irq(ha->host->host_lock);
1421 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1422 DEBUG2(printk(KERN_INFO
1423 "%s failed:board disabled\n",__func__));
1425 spin_lock_irq(ha->host->host_lock);
1426 goto eh_dev_reset_done;
1429 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1430 if (qla2x00_device_reset(ha, fcport_to_reset) == 0) {
1431 return_status = SUCCESS;
1434 #if defined(LOGOUT_AFTER_DEVICE_RESET)
1435 if (return_status == SUCCESS) {
1436 if (fcport_to_reset->flags & FC_FABRIC_DEVICE) {
1437 qla2x00_fabric_logout(ha,
1438 fcport_to_reset->loop_id);
1439 qla2x00_mark_device_lost(ha, fcport_to_reset);
1444 DEBUG2(printk(KERN_INFO
1445 "%s failed: loop not ready\n",__func__);)
1448 spin_lock_irq(ha->host->host_lock);
1450 if (return_status == FAILED) {
1451 DEBUG3(printk("%s(%ld): device reset failed\n",
1452 __func__, ha->host_no));
1453 qla_printk(KERN_INFO, ha, "%s: device reset failed\n",
1456 goto eh_dev_reset_done;
1460 * If we are coming down the EH path, wait for all commands to
1461 * complete for the device.
1463 if (cmd->device->host->eh_active) {
1464 if (qla2x00_eh_wait_for_pending_target_commands(ha, t))
1465 return_status = FAILED;
1467 if (return_status == FAILED) {
1468 DEBUG3(printk("%s(%ld): failed while waiting for "
1469 "commands\n", __func__, ha->host_no));
1470 qla_printk(KERN_INFO, ha,
1471 "%s: failed while waiting for commands\n",
1474 goto eh_dev_reset_done;
1478 qla_printk(KERN_INFO, ha,
1479 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1480 ha->host_no, b, t, l);
1484 if (!cmd->device->host->eh_active)
1485 clear_bit(TQF_SUSPENDED, &tq->flags);
1487 return (return_status);
1490 /**************************************************************************
1491 * qla2x00_eh_wait_for_pending_commands
1494 * Waits for all the commands to come back from the specified host.
1497 * ha - pointer to scsi_qla_host structure.
1504 **************************************************************************/
1506 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
1511 struct scsi_cmnd *cmd;
1516 * Waiting for all commands for the designated target in the active
1519 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1520 spin_lock(&ha->hardware_lock);
1521 sp = ha->outstanding_cmds[cnt];
1524 spin_unlock(&ha->hardware_lock);
1525 status = qla2x00_eh_wait_on_command(ha, cmd);
1530 spin_unlock(&ha->hardware_lock);
1537 /**************************************************************************
1538 * qla2xxx_eh_bus_reset
1541 * The bus reset function will reset the bus and abort any executing
1545 * cmd = Linux SCSI command packet of the command that cause the
1549 * SUCCESS/FAILURE (defined as macro in scsi.h).
1551 **************************************************************************/
1553 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1555 scsi_qla_host_t *ha;
1559 ha = (scsi_qla_host_t *) cmd->device->host->hostdata;
1560 sp = (srb_t *) CMD_SP(cmd);
1562 qla_printk(KERN_INFO, ha,
1563 "scsi(%ld:%d:%d:%d): LOOP RESET ISSUED.\n", ha->host_no,
1564 cmd->device->channel, cmd->device->id, cmd->device->lun);
1566 spin_unlock_irq(ha->host->host_lock);
1568 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) {
1569 DEBUG2(printk("%s failed:board disabled\n",__func__));
1570 spin_lock_irq(ha->host->host_lock);
1574 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) {
1575 if (qla2x00_loop_reset(ha) == QLA_SUCCESS)
1579 spin_lock_irq(ha->host->host_lock);
1583 /* Waiting for our command in done_queue to be returned to OS.*/
1584 if (cmd->device->host->eh_active)
1585 if (!qla2x00_eh_wait_for_pending_commands(ha))
1589 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1590 (rval == FAILED) ? "failed" : "succeded");
1595 /**************************************************************************
1596 * qla2xxx_eh_host_reset
1599 * The reset function will reset the Adapter.
1602 * cmd = Linux SCSI command packet of the command that cause the
1606 * Either SUCCESS or FAILED.
1609 **************************************************************************/
1611 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1613 scsi_qla_host_t *ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
1616 /* Display which one we're actually resetting for debug. */
1617 DEBUG(printk("qla2xxx_eh_host_reset:Resetting scsi(%ld).\n",
1623 qla_printk(KERN_INFO, ha,
1624 "scsi(%ld:%d:%d:%d): ADAPTER RESET issued.\n", ha->host_no,
1625 cmd->device->channel, cmd->device->id, cmd->device->lun);
1627 spin_unlock_irq(ha->host->host_lock);
1629 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1630 goto board_disabled;
1633 * Fixme-may be dpc thread is active and processing
1634 * loop_resync,so wait a while for it to
1635 * be completed and then issue big hammer.Otherwise
1636 * it may cause I/O failure as big hammer marks the
1637 * devices as lost kicking of the port_down_timer
1638 * while dpc is stuck for the mailbox to complete.
1640 /* Blocking call-Does context switching if loop is Not Ready */
1641 qla2x00_wait_for_loop_ready(ha);
1642 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1643 if (qla2x00_abort_isp(ha)) {
1644 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1645 /* failed. schedule dpc to try */
1646 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1648 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
1649 goto board_disabled;
1652 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1654 spin_lock_irq(ha->host->host_lock);
1658 /* Waiting for our command in done_queue to be returned to OS.*/
1659 if (!qla2x00_eh_wait_for_pending_commands(ha))
1663 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1664 (rval == FAILED) ? "failed" : "succeded");
1669 spin_lock_irq(ha->host->host_lock);
1671 qla_printk(KERN_INFO, ha, "%s: failed:board disabled\n", __func__);
1677 * qla2x00_loop_reset
1681 * ha = adapter block pointer.
1687 qla2x00_loop_reset(scsi_qla_host_t *ha)
1689 int status = QLA_SUCCESS;
1693 if (ha->flags.enable_lip_reset) {
1694 status = qla2x00_lip_reset(ha);
1697 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) {
1698 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
1699 if ((tq = TGT_Q(ha, t)) == NULL)
1702 if (tq->fcport == NULL)
1705 status = qla2x00_target_reset(ha, 0, t);
1706 if (status != QLA_SUCCESS) {
1712 if (status == QLA_SUCCESS &&
1713 ((!ha->flags.enable_target_reset &&
1714 !ha->flags.enable_lip_reset) ||
1715 ha->flags.enable_lip_full_login)) {
1717 status = qla2x00_full_login_lip(ha);
1720 /* Issue marker command only when we are going to start the I/O */
1721 ha->marker_needed = 1;
1725 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1730 DEBUG3(printk("%s(%ld): exiting normally.\n",
1739 * qla2x00_device_reset
1740 * Issue bus device reset message to the target.
1743 * ha = adapter block pointer.
1745 * TARGET_QUEUE_LOCK must be released.
1746 * ADAPTER_STATE_LOCK must be released.
1752 qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
1754 /* Abort Target command will clear Reservation */
1755 return qla2x00_abort_target(reset_fcport);
1758 /**************************************************************************
1759 * qla2xxx_slave_configure
1762 **************************************************************************/
1764 qla2xxx_slave_configure(struct scsi_device *sdev)
1766 scsi_qla_host_t *ha = to_qla_host(sdev->host);
1769 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1774 if (sdev->tagged_supported) {
1775 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1776 queue_depth = ql2xmaxqdepth;
1778 ql2xmaxqdepth = queue_depth;
1780 scsi_activate_tcq(sdev, queue_depth);
1782 qla_printk(KERN_INFO, ha,
1783 "scsi(%d:%d:%d:%d): Enabled tagged queuing, queue "
1785 sdev->host->host_no, sdev->channel, sdev->id, sdev->lun,
1788 scsi_adjust_queue_depth(sdev, 0 /* TCQ off */,
1789 sdev->host->hostt->cmd_per_lun /* 3 */);
1796 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1799 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1800 * supported addressing method.
1803 qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1805 /* Assume 32bit DMA address */
1806 ha->flags.enable_64bit_addressing = 0;
1807 ha->calc_request_entries = qla2x00_calc_iocbs_32;
1808 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_32;
1811 * Given the two variants pci_set_dma_mask(), allow the compiler to
1812 * assist in setting the proper dma mask.
1814 if (sizeof(dma_addr_t) > 4) {
1815 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1816 ha->flags.enable_64bit_addressing = 1;
1817 ha->calc_request_entries = qla2x00_calc_iocbs_64;
1818 ha->build_scsi_iocbs = qla2x00_build_scsi_iocbs_64;
1820 if (pci_set_consistent_dma_mask(ha->pdev,
1822 qla_printk(KERN_DEBUG, ha,
1823 "Failed to set 64 bit PCI consistent mask; "
1825 pci_set_consistent_dma_mask(ha->pdev,
1829 qla_printk(KERN_DEBUG, ha,
1830 "Failed to set 64 bit PCI DMA mask, falling back "
1831 "to 32 bit MASK.\n");
1832 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1835 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1840 qla2x00_iospace_config(scsi_qla_host_t *ha)
1842 unsigned long pio, pio_len, pio_flags;
1843 unsigned long mmio, mmio_len, mmio_flags;
1845 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1846 pio = pci_resource_start(ha->pdev, 0);
1847 pio_len = pci_resource_len(ha->pdev, 0);
1848 pio_flags = pci_resource_flags(ha->pdev, 0);
1849 if (pio_flags & IORESOURCE_IO) {
1850 if (pio_len < MIN_IOBASE_LEN) {
1851 qla_printk(KERN_WARNING, ha,
1852 "Invalid PCI I/O region size (%s)...\n",
1853 ha->pdev->slot_name);
1857 qla_printk(KERN_WARNING, ha,
1858 "region #0 not a PIO resource (%s)...\n",
1859 ha->pdev->slot_name);
1863 /* Use MMIO operations for all accesses. */
1864 mmio = pci_resource_start(ha->pdev, 1);
1865 mmio_len = pci_resource_len(ha->pdev, 1);
1866 mmio_flags = pci_resource_flags(ha->pdev, 1);
1868 if (!(mmio_flags & IORESOURCE_MEM)) {
1869 qla_printk(KERN_ERR, ha,
1870 "region #0 not an MMIO resource (%s), aborting\n",
1871 ha->pdev->slot_name);
1872 goto iospace_error_exit;
1874 if (mmio_len < MIN_IOBASE_LEN) {
1875 qla_printk(KERN_ERR, ha,
1876 "Invalid PCI mem region size (%s), aborting\n",
1877 ha->pdev->slot_name);
1878 goto iospace_error_exit;
1881 if (pci_request_regions(ha->pdev, ha->brd_info->drv_name)) {
1882 qla_printk(KERN_WARNING, ha,
1883 "Failed to reserve PIO/MMIO regions (%s)\n",
1884 ha->pdev->slot_name);
1886 goto iospace_error_exit;
1889 ha->pio_address = pio;
1890 ha->pio_length = pio_len;
1891 ha->iobase = ioremap(mmio, MIN_IOBASE_LEN);
1893 qla_printk(KERN_ERR, ha,
1894 "cannot remap MMIO (%s), aborting\n", ha->pdev->slot_name);
1896 goto iospace_error_exit;
1906 * PCI driver interface
1908 int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1911 device_reg_t __iomem *reg;
1912 struct Scsi_Host *host;
1913 scsi_qla_host_t *ha;
1914 unsigned long flags = 0;
1915 unsigned long wait_switch = 0;
1919 if (pci_enable_device(pdev))
1922 host = scsi_host_alloc(&qla2x00_driver_template,
1923 sizeof(scsi_qla_host_t));
1926 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1927 goto probe_disable_device;
1930 /* Clear our data area */
1931 ha = (scsi_qla_host_t *)host->hostdata;
1932 memset(ha, 0, sizeof(scsi_qla_host_t));
1936 ha->host_no = host->host_no;
1937 ha->brd_info = brd_info;
1938 sprintf(ha->host_str, "%s_%ld", ha->brd_info->drv_name, ha->host_no);
1940 /* Configure PCI I/O space */
1941 ret = qla2x00_iospace_config(ha);
1946 /* Sanitize the information from PCI BIOS. */
1947 host->irq = pdev->irq;
1949 qla_printk(KERN_INFO, ha,
1950 "Found an %s, irq %d, iobase 0x%p\n", ha->brd_info->isp_name,
1951 host->irq, ha->iobase);
1953 spin_lock_init(&ha->hardware_lock);
1955 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1958 ha->total_isr_cnt = 0;
1959 ha->total_isp_aborts = 0;
1960 ha->total_lip_cnt = 0;
1961 ha->total_dev_errs = 0;
1963 ha->total_bytes = 0;
1965 ha->prev_topology = 0;
1966 ha->ports = MAX_BUSES;
1968 if (IS_QLA2100(ha)) {
1969 ha->max_targets = MAX_TARGETS_2100;
1970 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1971 ha->request_q_length = REQUEST_ENTRY_CNT_2100;
1972 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1973 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1974 host->sg_tablesize = 32;
1975 } else if (IS_QLA2200(ha)) {
1976 ha->max_targets = MAX_TARGETS_2200;
1977 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1978 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1979 ha->response_q_length = RESPONSE_ENTRY_CNT_2100;
1980 ha->last_loop_id = SNS_LAST_LOOP_ID_2100;
1981 } else /*if (IS_QLA2300(ha))*/ {
1982 ha->max_targets = MAX_TARGETS_2200;
1983 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1984 ha->request_q_length = REQUEST_ENTRY_CNT_2200;
1985 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1986 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1988 host->can_queue = ha->request_q_length + 128;
1990 /* load the F/W, read paramaters, and init the H/W */
1991 ha->instance = num_hosts;
1993 init_MUTEX(&ha->mbx_cmd_sem);
1994 init_MUTEX_LOCKED(&ha->mbx_intr_sem);
1996 INIT_LIST_HEAD(&ha->list);
1997 INIT_LIST_HEAD(&ha->fcports);
1998 INIT_LIST_HEAD(&ha->rscn_fcports);
1999 INIT_LIST_HEAD(&ha->done_queue);
2000 INIT_LIST_HEAD(&ha->retry_queue);
2001 INIT_LIST_HEAD(&ha->scsi_retry_queue);
2002 INIT_LIST_HEAD(&ha->pending_queue);
2005 * These locks are used to prevent more than one CPU
2006 * from modifying the queue at the same time. The
2007 * higher level "host_lock" will reduce most
2008 * contention for these locks.
2010 spin_lock_init(&ha->mbx_reg_lock);
2011 spin_lock_init(&ha->list_lock);
2014 init_completion(&ha->dpc_inited);
2015 init_completion(&ha->dpc_exited);
2017 qla2x00_config_dma_addressing(ha);
2018 if (qla2x00_mem_alloc(ha)) {
2019 qla_printk(KERN_WARNING, ha,
2020 "[ERROR] Failed to allocate memory for adapter\n");
2025 if (qla2x00_initialize_adapter(ha) &&
2026 !(ha->device_flags & DFLG_NO_CABLE)) {
2028 qla_printk(KERN_WARNING, ha,
2029 "Failed to initialize adapter\n");
2031 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
2032 "Adapter flags %x.\n",
2033 ha->host_no, ha->device_flags));
2039 * Startup the kernel thread for this host adapter
2041 ha->dpc_should_die = 0;
2042 ha->dpc_pid = kernel_thread(qla2x00_do_dpc, ha, 0);
2043 if (ha->dpc_pid < 0) {
2044 qla_printk(KERN_WARNING, ha,
2045 "Unable to start DPC thread!\n");
2049 wait_for_completion(&ha->dpc_inited);
2051 host->this_id = 255;
2052 host->cmd_per_lun = 3;
2053 host->max_cmd_len = MAX_CMDSZ;
2054 host->max_channel = ha->ports - 1;
2055 host->max_lun = ha->max_luns;
2056 BUG_ON(qla2xxx_transport_template == NULL);
2057 host->transportt = qla2xxx_transport_template;
2058 host->unique_id = ha->instance;
2059 host->max_id = ha->max_targets;
2061 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2062 ret = request_irq(host->irq, qla2100_intr_handler,
2063 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
2065 ret = request_irq(host->irq, qla2300_intr_handler,
2066 SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
2068 qla_printk(KERN_WARNING, ha,
2069 "Failed to reserve interrupt %d already in use.\n",
2074 /* Initialized the timer */
2075 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
2077 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
2082 /* Disable ISP interrupts. */
2083 qla2x00_disable_intrs(ha);
2085 /* Ensure mailbox registers are free. */
2086 spin_lock_irqsave(&ha->hardware_lock, flags);
2087 WRT_REG_WORD(®->semaphore, 0);
2088 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2089 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2091 /* Enable proper parity */
2092 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2095 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x1));
2097 /* SRAM, Instruction RAM and GP RAM parity */
2098 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x7));
2100 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2102 /* Enable chip interrupts. */
2103 qla2x00_enable_intrs(ha);
2107 * Wait around max loop_reset_delay secs for the devices to come
2108 * on-line. We don't want Linux scanning before we are ready.
2111 for (wait_switch = jiffies + (ha->loop_reset_delay * HZ);
2112 time_before(jiffies,wait_switch) &&
2113 !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES))
2114 && (ha->device_flags & SWITCH_FOUND) ;) {
2116 qla2x00_check_fabric_devices(ha);
2121 pci_set_drvdata(pdev, ha);
2122 ha->flags.init_done = 1;
2125 /* List the target we have found */
2126 if (displayConfig) {
2127 qla2x00_display_fc_names(ha);
2130 if (scsi_add_host(host, &pdev->dev))
2133 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
2134 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
2136 qla_printk(KERN_INFO, ha, "\n"
2137 " QLogic Fibre Channel HBA Driver: %s\n"
2139 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str,
2140 ha->model_number, ha->model_desc ? ha->model_desc: "",
2141 ha->brd_info->isp_name, qla2x00_get_pci_info_str(ha, pci_info),
2142 pci_name(ha->pdev), ha->flags.enable_64bit_addressing ? '+': '-',
2143 ha->host_no, qla2x00_get_fw_version_str(ha, fw_str));
2146 scsi_scan_host(host);
2151 qla2x00_free_device(ha);
2153 scsi_host_put(host);
2155 probe_disable_device:
2156 pci_disable_device(pdev);
2160 EXPORT_SYMBOL_GPL(qla2x00_probe_one);
2162 void qla2x00_remove_one(struct pci_dev *pdev)
2164 scsi_qla_host_t *ha;
2166 ha = pci_get_drvdata(pdev);
2168 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj,
2169 &sysfs_fw_dump_attr);
2170 sysfs_remove_bin_file(&ha->host->shost_gendev.kobj, &sysfs_nvram_attr);
2172 scsi_remove_host(ha->host);
2174 qla2x00_free_device(ha);
2176 scsi_host_put(ha->host);
2178 pci_set_drvdata(pdev, NULL);
2180 EXPORT_SYMBOL_GPL(qla2x00_remove_one);
2183 qla2x00_free_device(scsi_qla_host_t *ha)
2187 /* Abort any outstanding IO descriptors. */
2188 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2189 qla2x00_cancel_io_descriptors(ha);
2191 /* turn-off interrupts on the card */
2192 if (ha->interrupts_on)
2193 qla2x00_disable_intrs(ha);
2196 if (ha->timer_active)
2197 qla2x00_stop_timer(ha);
2199 /* Kill the kernel thread for this host */
2200 if (ha->dpc_pid >= 0) {
2201 ha->dpc_should_die = 1;
2203 ret = kill_proc(ha->dpc_pid, SIGHUP, 1);
2205 qla_printk(KERN_ERR, ha,
2206 "Unable to signal DPC thread -- (%d)\n", ret);
2208 /* TODO: SOMETHING MORE??? */
2210 wait_for_completion(&ha->dpc_exited);
2214 qla2x00_mem_free(ha);
2217 ha->flags.online = 0;
2219 /* Detach interrupts */
2221 free_irq(ha->pdev->irq, ha);
2223 /* release io space registers */
2225 iounmap(ha->iobase);
2226 pci_release_regions(ha->pdev);
2228 pci_disable_device(ha->pdev);
2233 * The following support functions are adopted to handle
2234 * the re-entrant qla2x00_proc_info correctly.
2237 copy_mem_info(struct info_str *info, char *data, int len)
2239 if (info->pos + len > info->offset + info->length)
2240 len = info->offset + info->length - info->pos;
2242 if (info->pos + len < info->offset) {
2247 if (info->pos < info->offset) {
2250 partial = info->offset - info->pos;
2252 info->pos += partial;
2257 memcpy(info->buffer, data, len);
2259 info->buffer += len;
2264 copy_info(struct info_str *info, char *fmt, ...)
2270 va_start(args, fmt);
2271 len = vsprintf(buf, fmt, args);
2274 copy_mem_info(info, buf, len);
2279 /*************************************************************************
2283 * Return information to handle /proc support for the driver.
2285 * inout : decides the direction of the dataflow and the meaning of the
2287 * buffer: If inout==0 data is being written to it else read from it
2288 * (ptr to a page buffer)
2289 * *start: If inout==0 start of the valid data in the buffer
2290 * offset: If inout==0 starting offset from the beginning of all
2291 * possible data to return.
2292 * length: If inout==0 max number of bytes to be written into the buffer
2293 * else number of bytes in "buffer"
2295 * < 0: error. errno value.
2296 * >= 0: sizeof data returned.
2297 *************************************************************************/
2299 qla2x00_proc_info(struct Scsi_Host *shost, char *buffer,
2300 char **start, off_t offset, int length, int inout)
2302 struct info_str info;
2303 int retval = -EINVAL;
2309 uint8_t *loop_state;
2310 scsi_qla_host_t *ha;
2313 DEBUG3(printk(KERN_INFO
2314 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
2315 buffer, offset, length);)
2317 ha = (scsi_qla_host_t *) shost->hostdata;
2320 /* Has data been written to the file? */
2322 "%s: has data been written to the file. \n",
2325 return (qla2x00_set_info(buffer, length, shost));
2332 info.buffer = buffer;
2333 info.length = length;
2334 info.offset = offset;
2337 /* start building the print buffer */
2339 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
2340 " Firmware version %s, ",
2341 ha->model_number, qla2x00_get_fw_version_str(ha, fw_info));
2343 copy_info(&info, "Driver version %s\n", qla2x00_version_str);
2345 copy_info(&info, "Entry address = %p\n", qla2x00_set_info);
2347 tmp_sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) |
2349 copy_info(&info, "ISP: %s, Serial# %c%05d\n",
2350 ha->brd_info->isp_name, ('A' + tmp_sn/100000), (tmp_sn%100000));
2353 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
2354 (unsigned long long)ha->request_dma,
2355 (unsigned long long)ha->response_dma);
2358 "Request Queue count = %d, Response Queue count = %d\n",
2359 ha->request_q_length, ha->response_q_length);
2362 "Total number of active commands = %ld\n",
2366 "Total number of interrupts = %ld\n",
2367 (long)ha->total_isr_cnt);
2370 " Device queue depth = 0x%x\n",
2371 (ql2xmaxqdepth == 0) ? 16 : ql2xmaxqdepth);
2374 "Number of free request entries = %d\n", ha->req_q_cnt);
2377 "Number of mailbox timeouts = %ld\n", ha->total_mbx_timeout);
2380 "Number of ISP aborts = %ld\n", ha->total_isp_aborts);
2383 "Number of loop resyncs = %ld\n", ha->total_loop_resync);
2386 "Number of retries for empty slots = %ld\n",
2387 qla2x00_stats.outarray_full);
2390 "Number of reqs in pending_q= %ld, retry_q= %d, "
2391 "done_q= %ld, scsi_retry_q= %d\n",
2392 ha->qthreads, ha->retry_q_cnt,
2393 ha->done_q_cnt, ha->scsi_retry_q_cnt);
2396 flags = (uint32_t *) &ha->flags;
2398 if (atomic_read(&ha->loop_state) == LOOP_DOWN) {
2399 loop_state = "DOWN";
2400 } else if (atomic_read(&ha->loop_state) == LOOP_UP) {
2402 } else if (atomic_read(&ha->loop_state) == LOOP_READY) {
2403 loop_state = "READY";
2404 } else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT) {
2405 loop_state = "TIMEOUT";
2406 } else if (atomic_read(&ha->loop_state) == LOOP_UPDATE) {
2407 loop_state = "UPDATE";
2409 loop_state = "UNKNOWN";
2413 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
2414 loop_state , *flags);
2416 copy_info(&info, "Dpc flags = 0x%lx\n", ha->dpc_flags);
2418 copy_info(&info, "MBX flags = 0x%x\n", ha->mbx_flags);
2420 copy_info(&info, "Link down Timeout = %3.3d\n",
2421 ha->link_down_timeout);
2423 copy_info(&info, "Port down retry = %3.3d\n",
2424 ha->port_down_retry_count);
2426 copy_info(&info, "Login retry count = %3.3d\n",
2427 ha->login_retry_count);
2430 "Commands retried with dropped frame(s) = %d\n",
2431 ha->dropped_frame_error_cnt);
2434 "Product ID = %04x %04x %04x %04x\n", ha->product_id[0],
2435 ha->product_id[1], ha->product_id[2], ha->product_id[3]);
2437 copy_info(&info, "\n");
2439 /* 2.25 node/port display to proc */
2440 /* Display the node name for adapter */
2441 copy_info(&info, "\nSCSI Device Information:\n");
2443 "scsi-qla%d-adapter-node="
2444 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2446 ha->init_cb->node_name[0],
2447 ha->init_cb->node_name[1],
2448 ha->init_cb->node_name[2],
2449 ha->init_cb->node_name[3],
2450 ha->init_cb->node_name[4],
2451 ha->init_cb->node_name[5],
2452 ha->init_cb->node_name[6],
2453 ha->init_cb->node_name[7]);
2455 /* display the port name for adapter */
2457 "scsi-qla%d-adapter-port="
2458 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2460 ha->init_cb->port_name[0],
2461 ha->init_cb->port_name[1],
2462 ha->init_cb->port_name[2],
2463 ha->init_cb->port_name[3],
2464 ha->init_cb->port_name[4],
2465 ha->init_cb->port_name[5],
2466 ha->init_cb->port_name[6],
2467 ha->init_cb->port_name[7]);
2469 /* Print out device port names */
2470 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2471 if ((tq = TGT_Q(ha, t)) == NULL)
2475 "scsi-qla%d-target-%d="
2476 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
2477 (int)ha->instance, t,
2478 tq->port_name[0], tq->port_name[1],
2479 tq->port_name[2], tq->port_name[3],
2480 tq->port_name[4], tq->port_name[5],
2481 tq->port_name[6], tq->port_name[7]);
2484 copy_info(&info, "\nSCSI LUN Information:\n");
2486 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
2488 /* scan for all equipment stats */
2489 for (t = 0; t < MAX_FIBRE_DEVICES; t++) {
2491 for (l = 0; l < ha->max_luns; l++) {
2492 up = (os_lun_t *) GET_LU_Q(ha, t, l);
2497 if (up->fclun == NULL) {
2502 "(%2d:%2d): Total reqs %ld,",
2506 " Pending reqs %ld,",
2509 if (up->io_cnt < 4) {
2520 " %ld:%d:%02x %02x",
2521 up->fclun->fcport->ha->instance,
2522 up->fclun->fcport->cur_path,
2523 up->fclun->fcport->loop_id,
2524 up->fclun->device_type);
2526 copy_info(&info, "\n");
2528 if (info.pos >= info.offset + info.length) {
2529 /* No need to continue */
2534 if (info.pos >= info.offset + info.length) {
2535 /* No need to continue */
2542 retval = info.pos > info.offset ? info.pos - info.offset : 0;
2544 DEBUG3(printk(KERN_INFO
2545 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
2546 "length=0x%x\n", info.pos, offset, length);)
2552 * qla2x00_display_fc_names
2553 * This routine will the node names of the different devices found
2554 * after port inquiry.
2557 * cmd = SCSI command structure
2563 qla2x00_display_fc_names(scsi_qla_host_t *ha)
2568 /* Display the node name for adapter */
2569 qla_printk(KERN_INFO, ha,
2570 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2572 ha->init_cb->node_name[0],
2573 ha->init_cb->node_name[1],
2574 ha->init_cb->node_name[2],
2575 ha->init_cb->node_name[3],
2576 ha->init_cb->node_name[4],
2577 ha->init_cb->node_name[5],
2578 ha->init_cb->node_name[6],
2579 ha->init_cb->node_name[7]);
2581 /* display the port name for adapter */
2582 qla_printk(KERN_INFO, ha,
2583 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2585 ha->init_cb->port_name[0],
2586 ha->init_cb->port_name[1],
2587 ha->init_cb->port_name[2],
2588 ha->init_cb->port_name[3],
2589 ha->init_cb->port_name[4],
2590 ha->init_cb->port_name[5],
2591 ha->init_cb->port_name[6],
2592 ha->init_cb->port_name[7]);
2594 /* Print out device port names */
2595 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
2596 if ((tq = ha->otgt[tgt]) == NULL)
2599 if (tq->fcport == NULL)
2602 switch (ha->binding_type) {
2603 case BIND_BY_PORT_NAME:
2604 qla_printk(KERN_INFO, ha,
2605 "scsi-qla%d-tgt-%d-di-0-port="
2606 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2620 case BIND_BY_PORT_ID:
2621 qla_printk(KERN_INFO, ha,
2622 "scsi-qla%d-tgt-%d-di-0-pid="
2623 "%02x%02x%02x\\;\n",
2633 qla_printk(KERN_INFO, ha,
2634 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha->instance, tgt);
2640 * qla2x00_suspend_lun
2641 * Suspend lun and start port down timer
2644 * ha = visable adapter block pointer.
2646 * cp = Scsi command pointer
2647 * time = time in seconds
2648 * count = number of times to let time expire
2649 * delay_lun = non-zero, if lun should be delayed rather than suspended
2652 * QLA_SUCCESS -- suspended lun
2653 * QLA_FUNCTION_FAILED -- Didn't suspend lun
2656 * Interrupt context.
2659 __qla2x00_suspend_lun(scsi_qla_host_t *ha,
2660 os_lun_t *lq, int time, int count, int delay_lun)
2664 struct list_head *list, *temp;
2665 unsigned long flags;
2669 /* if the lun_q is already suspended then don't do it again */
2670 if (lq->q_state == LUN_STATE_READY ||lq->q_state == LUN_STATE_RUN) {
2672 spin_lock_irqsave(&lq->q_lock, flags);
2673 if (lq->q_state == LUN_STATE_READY) {
2677 /* Set the suspend time usually 6 secs */
2678 atomic_set(&lq->q_timer, time);
2680 /* now suspend the lun */
2681 lq->q_state = LUN_STATE_WAIT;
2684 set_bit(LUN_EXEC_DELAYED, &lq->q_flag);
2685 DEBUG(printk(KERN_INFO
2686 "scsi(%ld): Delay lun execution for %d secs, "
2687 "count=%d, max count=%d, state=%d\n",
2690 lq->q_count, lq->q_max, lq->q_state));
2692 DEBUG(printk(KERN_INFO
2693 "scsi(%ld): Suspend lun for %d secs, count=%d, "
2694 "max count=%d, state=%d\n",
2697 lq->q_count, lq->q_max, lq->q_state));
2699 spin_unlock_irqrestore(&lq->q_lock, flags);
2702 * Remove all pending commands from request queue and put them
2703 * in the scsi_retry queue.
2705 spin_lock_irqsave(&ha->list_lock, flags);
2706 list_for_each_safe(list, temp, &ha->pending_queue) {
2707 sp = list_entry(list, srb_t, list);
2708 if (sp->lun_queue != lq)
2711 __del_from_pending_queue(ha, sp);
2713 if (sp->cmd->allowed < count)
2714 sp->cmd->allowed = count;
2715 __add_to_scsi_retry_queue(ha, sp);
2717 } /* list_for_each_safe */
2718 spin_unlock_irqrestore(&ha->list_lock, flags);
2721 rval = QLA_FUNCTION_FAILED;
2728 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2730 * Input: ha = adapter block pointer. fcport = port structure pointer.
2736 void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
2740 * We may need to retry the login, so don't change the state of the
2741 * port but do the retries.
2743 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2744 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2749 if (fcport->login_retry == 0) {
2750 fcport->login_retry = ha->login_retry_count;
2751 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2753 DEBUG(printk("scsi(%ld): Port login retry: "
2754 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2755 "id = 0x%04x retry cnt=%d\n",
2757 fcport->port_name[0],
2758 fcport->port_name[1],
2759 fcport->port_name[2],
2760 fcport->port_name[3],
2761 fcport->port_name[4],
2762 fcport->port_name[5],
2763 fcport->port_name[6],
2764 fcport->port_name[7],
2766 fcport->login_retry));
2771 * qla2x00_mark_all_devices_lost
2772 * Updates fcport state when device goes offline.
2775 * ha = adapter block pointer.
2776 * fcport = port structure pointer.
2784 qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha)
2788 list_for_each_entry(fcport, &ha->fcports, list) {
2789 if (fcport->port_type != FCT_TARGET)
2793 * No point in marking the device as lost, if the device is
2796 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2799 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2805 * Allocates adapter memory.
2812 qla2x00_mem_alloc(scsi_qla_host_t *ha)
2820 * This will loop only once if everything goes well, else some
2821 * number of retries will be performed to get around a kernel
2822 * bug where available mem is not allocated until after a
2823 * little delay and a retry.
2825 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
2826 (ha->request_q_length + 1) * sizeof(request_t),
2827 &ha->request_dma, GFP_KERNEL);
2828 if (ha->request_ring == NULL) {
2829 qla_printk(KERN_WARNING, ha,
2830 "Memory Allocation failed - request_ring\n");
2832 qla2x00_mem_free(ha);
2838 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
2839 (ha->response_q_length + 1) * sizeof(response_t),
2840 &ha->response_dma, GFP_KERNEL);
2841 if (ha->response_ring == NULL) {
2842 qla_printk(KERN_WARNING, ha,
2843 "Memory Allocation failed - response_ring\n");
2845 qla2x00_mem_free(ha);
2851 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2852 &ha->gid_list_dma, GFP_KERNEL);
2853 if (ha->gid_list == NULL) {
2854 qla_printk(KERN_WARNING, ha,
2855 "Memory Allocation failed - gid_list\n");
2857 qla2x00_mem_free(ha);
2863 ha->rlc_rsp = dma_alloc_coherent(&ha->pdev->dev,
2864 sizeof(rpt_lun_cmd_rsp_t), &ha->rlc_rsp_dma, GFP_KERNEL);
2865 if (ha->rlc_rsp == NULL) {
2866 qla_printk(KERN_WARNING, ha,
2867 "Memory Allocation failed - rlc");
2869 qla2x00_mem_free(ha);
2875 snprintf(name, sizeof(name), "qla2xxx_%ld", ha->host_no);
2876 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2877 DMA_POOL_SIZE, 8, 0);
2878 if (ha->s_dma_pool == NULL) {
2879 qla_printk(KERN_WARNING, ha,
2880 "Memory Allocation failed - s_dma_pool\n");
2882 qla2x00_mem_free(ha);
2888 /* get consistent memory allocated for init control block */
2889 ha->init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2891 if (ha->init_cb == NULL) {
2892 qla_printk(KERN_WARNING, ha,
2893 "Memory Allocation failed - init_cb\n");
2895 qla2x00_mem_free(ha);
2900 memset(ha->init_cb, 0, sizeof(init_cb_t));
2902 /* Get consistent memory allocated for Get Port Database cmd */
2903 ha->iodesc_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2904 &ha->iodesc_pd_dma);
2905 if (ha->iodesc_pd == NULL) {
2907 qla_printk(KERN_WARNING, ha,
2908 "Memory Allocation failed - iodesc_pd\n");
2910 qla2x00_mem_free(ha);
2915 memset(ha->iodesc_pd, 0, PORT_DATABASE_SIZE);
2917 /* Allocate ioctl related memory. */
2918 if (qla2x00_alloc_ioctl_mem(ha)) {
2919 qla_printk(KERN_WARNING, ha,
2920 "Memory Allocation failed - ioctl_mem\n");
2922 qla2x00_mem_free(ha);
2928 if (qla2x00_allocate_sp_pool(ha)) {
2929 qla_printk(KERN_WARNING, ha,
2930 "Memory Allocation failed - "
2931 "qla2x00_allocate_sp_pool()\n");
2933 qla2x00_mem_free(ha);
2939 /* Allocate memory for SNS commands */
2940 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2941 /* Get consistent memory allocated for SNS commands */
2942 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2943 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
2945 if (ha->sns_cmd == NULL) {
2947 qla_printk(KERN_WARNING, ha,
2948 "Memory Allocation failed - sns_cmd\n");
2950 qla2x00_mem_free(ha);
2955 memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
2957 /* Get consistent memory allocated for MS IOCB */
2958 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2960 if (ha->ms_iocb == NULL) {
2962 qla_printk(KERN_WARNING, ha,
2963 "Memory Allocation failed - ms_iocb\n");
2965 qla2x00_mem_free(ha);
2970 memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
2973 * Get consistent memory allocated for CT SNS
2976 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2977 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
2979 if (ha->ct_sns == NULL) {
2981 qla_printk(KERN_WARNING, ha,
2982 "Memory Allocation failed - ct_sns\n");
2984 qla2x00_mem_free(ha);
2989 memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
2992 /* Done all allocations without any error. */
2995 } while (retry-- && status != 0);
2999 "%s(): **** FAILED ****\n", __func__);
3007 * Frees all adapter allocated memory.
3010 * ha = adapter block pointer.
3013 qla2x00_mem_free(scsi_qla_host_t *ha)
3016 struct list_head *fcpl, *fcptemp;
3018 struct list_head *fcll, *fcltemp;
3020 unsigned long wtime;/* max wait time if mbx cmd is busy. */
3024 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
3028 /* Free the target queues */
3029 for (t = 0; t < MAX_TARGETS; t++) {
3030 qla2x00_tgt_free(ha, t);
3033 /* Make sure all other threads are stopped. */
3035 while (ha->dpc_wait && wtime) {
3036 set_current_state(TASK_INTERRUPTIBLE);
3037 wtime = schedule_timeout(wtime);
3040 /* free ioctl memory */
3041 qla2x00_free_ioctl_mem(ha);
3044 qla2x00_free_sp_pool(ha);
3047 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3048 ha->sns_cmd, ha->sns_cmd_dma);
3051 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3052 ha->ct_sns, ha->ct_sns_dma);
3055 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3058 dma_pool_free(ha->s_dma_pool, ha->iodesc_pd, ha->iodesc_pd_dma);
3061 dma_pool_free(ha->s_dma_pool, ha->init_cb, ha->init_cb_dma);
3064 dma_pool_destroy(ha->s_dma_pool);
3067 dma_free_coherent(&ha->pdev->dev,
3068 sizeof(rpt_lun_cmd_rsp_t), ha->rlc_rsp,
3072 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
3075 if (ha->response_ring)
3076 dma_free_coherent(&ha->pdev->dev,
3077 (ha->response_q_length + 1) * sizeof(response_t),
3078 ha->response_ring, ha->response_dma);
3080 if (ha->request_ring)
3081 dma_free_coherent(&ha->pdev->dev,
3082 (ha->request_q_length + 1) * sizeof(request_t),
3083 ha->request_ring, ha->request_dma);
3086 ha->sns_cmd_dma = 0;
3090 ha->ms_iocb_dma = 0;
3091 ha->iodesc_pd = NULL;
3092 ha->iodesc_pd_dma = 0;
3094 ha->init_cb_dma = 0;
3096 ha->s_dma_pool = NULL;
3099 ha->rlc_rsp_dma = 0;
3100 ha->gid_list = NULL;
3101 ha->gid_list_dma = 0;
3103 ha->response_ring = NULL;
3104 ha->response_dma = 0;
3105 ha->request_ring = NULL;
3106 ha->request_dma = 0;
3108 list_for_each_safe(fcpl, fcptemp, &ha->fcports) {
3109 fcport = list_entry(fcpl, fc_port_t, list);
3112 list_for_each_safe(fcll, fcltemp, &fcport->fcluns) {
3113 fclun = list_entry(fcll, fc_lun_t, list);
3115 list_del_init(&fclun->list);
3120 list_del_init(&fcport->list);
3123 INIT_LIST_HEAD(&ha->fcports);
3126 free_pages((unsigned long)ha->fw_dump, ha->fw_dump_order);
3128 if (ha->fw_dump_buffer)
3129 vfree(ha->fw_dump_buffer);
3132 ha->fw_dump_reading = 0;
3133 ha->fw_dump_buffer = NULL;
3137 * qla2x00_allocate_sp_pool
3138 * This routine is called during initialization to allocate
3139 * memory for local srb_t.
3142 * ha = adapter block pointer.
3147 * Note: Sets the ref_count for non Null sp to one.
3150 qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
3155 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
3156 mempool_free_slab, srb_cachep);
3157 if (ha->srb_mempool == NULL) {
3158 qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
3159 rval = QLA_FUNCTION_FAILED;
3165 * This routine frees all adapter allocated memory.
3169 qla2x00_free_sp_pool( scsi_qla_host_t *ha)
3171 if (ha->srb_mempool) {
3172 mempool_destroy(ha->srb_mempool);
3173 ha->srb_mempool = NULL;
3177 /**************************************************************************
3179 * This kernel thread is a task that is schedule by the interrupt handler
3180 * to perform the background processing for interrupts.
3183 * This task always run in the context of a kernel thread. It
3184 * is kick-off by the driver's detect code and starts up
3185 * up one per adapter. It immediately goes to sleep and waits for
3186 * some fibre event. When either the interrupt handler or
3187 * the timer routine detects a event it will one of the task
3188 * bits then wake us up.
3189 **************************************************************************/
3191 qla2x00_do_dpc(void *data)
3193 DECLARE_MUTEX_LOCKED(sem);
3194 scsi_qla_host_t *ha;
3199 unsigned long flags = 0;
3200 struct list_head *list, *templist;
3201 int dead_cnt, online_cnt;
3203 uint16_t next_loopid;
3207 ha = (scsi_qla_host_t *)data;
3211 daemonize("%s_dpc", ha->host_str);
3212 allow_signal(SIGHUP);
3214 ha->dpc_wait = &sem;
3216 set_user_nice(current, -20);
3220 complete(&ha->dpc_inited);
3223 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
3225 if (down_interruptible(&sem))
3228 if (ha->dpc_should_die)
3231 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
3233 /* Initialization not yet finished. Don't do anything yet. */
3234 if (!ha->flags.init_done || ha->dpc_active)
3237 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));
3241 if (!list_empty(&ha->done_queue))
3244 /* Process commands in retry queue */
3245 if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {
3246 DEBUG(printk("scsi(%ld): DPC checking retry_q. "
3248 ha->host_no, ha->retry_q_cnt));
3250 spin_lock_irqsave(&ha->list_lock, flags);
3251 dead_cnt = online_cnt = 0;
3252 list_for_each_safe(list, templist, &ha->retry_queue) {
3253 sp = list_entry(list, srb_t, list);
3255 DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "
3256 "spflags=0x%x, q_flag= 0x%lx\n",
3257 ha->host_no, sp->cmd->serial_number, sp,
3258 sp->flags, q->q_flag));
3262 fcport = q->fclun->fcport;
3264 if (atomic_read(&fcport->state) ==
3266 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3268 __del_from_retry_queue(ha, sp);
3269 sp->cmd->result = DID_NO_CONNECT << 16;
3270 if (atomic_read(&fcport->ha->loop_state) ==
3272 sp->err_id = SRB_ERR_LOOP;
3274 sp->err_id = SRB_ERR_PORT;
3275 sp->cmd->host_scribble =
3276 (unsigned char *) NULL;
3277 __add_to_done_queue(ha, sp);
3279 } else if (atomic_read(&fcport->state) !=
3282 __del_from_retry_queue(ha, sp);
3283 sp->cmd->result = DID_BUS_BUSY << 16;
3284 sp->cmd->host_scribble =
3285 (unsigned char *) NULL;
3286 __add_to_done_queue(ha, sp);
3289 } /* list_for_each_safe() */
3290 spin_unlock_irqrestore(&ha->list_lock, flags);
3292 DEBUG(printk("scsi(%ld): done processing retry queue "
3293 "- dead=%d, online=%d\n ",
3294 ha->host_no, dead_cnt, online_cnt));
3297 /* Process commands in scsi retry queue */
3298 if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {
3300 * Any requests we want to delay for some period is put
3301 * in the scsi retry queue with a delay added. The
3302 * timer will schedule a "scsi_restart_needed" every
3303 * second as long as there are requests in the scsi
3306 DEBUG(printk("scsi(%ld): DPC checking scsi "
3307 "retry_q.total=%d\n",
3308 ha->host_no, ha->scsi_retry_q_cnt));
3311 spin_lock_irqsave(&ha->list_lock, flags);
3312 list_for_each_safe(list, templist,
3313 &ha->scsi_retry_queue) {
3315 sp = list_entry(list, srb_t, list);
3319 DEBUG3(printk("scsi(%ld): scsi_retry_q: "
3320 "pid=%ld sp=%p, spflags=0x%x, "
3321 "q_flag= 0x%lx,q_state=%d\n",
3322 ha->host_no, sp->cmd->serial_number,
3323 sp, sp->flags, q->q_flag, q->q_state));
3325 /* Was this lun suspended */
3326 if (q->q_state != LUN_STATE_WAIT) {
3328 __del_from_scsi_retry_queue(ha, sp);
3330 if (test_bit(TQF_RETRY_CMDS,
3332 qla2x00_extend_timeout(sp->cmd,
3333 (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);
3334 __add_to_pending_queue(ha, sp);
3337 __add_to_retry_queue(ha, sp);
3340 /* Was this command suspended for N secs */
3341 if (sp->delay != 0) {
3343 if (sp->delay == 0) {
3345 __del_from_scsi_retry_queue(
3347 __add_to_retry_queue(ha,sp);
3351 spin_unlock_irqrestore(&ha->list_lock, flags);
3353 /* Clear all Target Unsuspended bits */
3354 for (t = 0; t < ha->max_targets; t++) {
3355 if ((tq = ha->otgt[t]) == NULL)
3358 if (test_bit(TQF_RETRY_CMDS, &tq->flags))
3359 clear_bit(TQF_RETRY_CMDS, &tq->flags);
3364 DEBUG(if (online_cnt > 0))
3365 DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "
3367 ha->host_no, online_cnt));
3370 if (ha->flags.mbox_busy) {
3371 if (!list_empty(&ha->done_queue))
3378 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3380 DEBUG(printk("scsi(%ld): dpc: sched "
3381 "qla2x00_abort_isp ha = %p\n",
3383 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3386 if (qla2x00_abort_isp(ha)) {
3387 /* failed. retry later */
3388 set_bit(ISP_ABORT_NEEDED,
3391 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
3393 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
3397 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&
3398 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {
3400 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
3403 qla2x00_rst_aen(ha);
3404 clear_bit(RESET_ACTIVE, &ha->dpc_flags);
3407 /* Retry each device up to login retry count */
3408 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3409 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&
3410 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3412 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
3416 list_for_each_entry(fcport, &ha->fcports, list) {
3417 if (fcport->port_type != FCT_TARGET)
3421 * If the port is not ONLINE then try to login
3422 * to it if we haven't run out of retries.
3424 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3425 fcport->login_retry) {
3427 fcport->login_retry--;
3428 if (fcport->flags & FCF_FABRIC_DEVICE) {
3431 qla2x00_fabric_logout(
3434 status = qla2x00_fabric_login(
3435 ha, fcport, &next_loopid);
3438 qla2x00_local_device_login(
3439 ha, fcport->loop_id);
3441 if (status == QLA_SUCCESS) {
3442 fcport->old_loop_id = fcport->loop_id;
3444 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
3445 ha->host_no, fcport->loop_id));
3447 fcport->port_login_retry_count =
3448 ha->port_down_retry_count * PORT_RETRY_TIME;
3449 atomic_set(&fcport->state, FCS_ONLINE);
3450 atomic_set(&fcport->port_down_timer,
3451 ha->port_down_retry_count * PORT_RETRY_TIME);
3453 fcport->login_retry = 0;
3454 } else if (status == 1) {
3455 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
3456 /* retry the login again */
3457 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
3459 fcport->login_retry, fcport->loop_id));
3461 fcport->login_retry = 0;
3464 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
3467 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
3471 if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&
3472 atomic_read(&ha->loop_state) != LOOP_DOWN) {
3474 clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);
3475 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
3478 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3480 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
3484 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
3486 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
3489 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3492 qla2x00_loop_resync(ha);
3494 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3497 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
3502 if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {
3503 DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",
3506 qla2x00_restart_queues(ha, 0);
3508 DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",
3512 if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {
3514 DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",
3517 qla2x00_abort_queues(ha, 0);
3519 DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",
3523 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {
3525 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
3528 qla2x00_rescan_fcports(ha);
3530 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
3536 if (!ha->interrupts_on)
3537 qla2x00_enable_intrs(ha);
3539 if (!list_empty(&ha->done_queue))
3543 } /* End of while(1) */
3545 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));
3548 * Make sure that nobody tries to wake us up again.
3550 ha->dpc_wait = NULL;
3553 complete_and_exit(&ha->dpc_exited, 0);
3557 * qla2x00_abort_queues
3558 * Abort all commands on queues on device
3561 * ha = adapter block pointer.
3564 * Interrupt context.
3567 qla2x00_abort_queues(scsi_qla_host_t *ha, uint8_t doneqflg)
3571 struct list_head *list, *temp;
3572 unsigned long flags;
3574 clear_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3576 /* Return all commands device queues. */
3577 spin_lock_irqsave(&ha->list_lock,flags);
3578 list_for_each_safe(list, temp, &ha->pending_queue) {
3579 sp = list_entry(list, srb_t, list);
3581 if (sp->flags & SRB_ABORTED)
3584 /* Remove srb from LUN queue. */
3585 __del_from_pending_queue(ha, sp);
3587 /* Set ending status. */
3588 sp->cmd->result = DID_BUS_BUSY << 16;
3590 __add_to_done_queue(ha, sp);
3592 spin_unlock_irqrestore(&ha->list_lock, flags);
3597 * Processes asynchronous reset.
3600 * ha = adapter block pointer.
3603 qla2x00_rst_aen(scsi_qla_host_t *ha)
3605 if (ha->flags.online && !ha->flags.reset_active &&
3606 !atomic_read(&ha->loop_down_timer) &&
3607 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) {
3609 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3612 * Issue marker command only when we are going to start
3615 ha->marker_needed = 1;
3616 } while (!atomic_read(&ha->loop_down_timer) &&
3617 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags)));
3623 * This routine will allocate SP from the free queue
3630 qla2x00_get_new_sp(scsi_qla_host_t *ha)
3634 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
3636 atomic_set(&sp->ref_count, 1);
3640 /**************************************************************************
3646 * Context: Interrupt
3647 ***************************************************************************/
3649 qla2x00_timer(scsi_qla_host_t *ha)
3652 unsigned long cpu_flags = 0;
3661 * We try and restart any request in the retry queue every second.
3663 if (!list_empty(&ha->retry_queue)) {
3664 set_bit(PORT_RESTART_NEEDED, &ha->dpc_flags);
3669 * We try and restart any request in the scsi_retry queue every second.
3671 if (!list_empty(&ha->scsi_retry_queue)) {
3672 set_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags);
3677 * Ports - Port down timer.
3679 * Whenever, a port is in the LOST state we start decrementing its port
3680 * down timer every second until it reaches zero. Once it reaches zero
3681 * the port it marked DEAD.
3684 list_for_each_entry(fcport, &ha->fcports, list) {
3685 if (fcport->port_type != FCT_TARGET)
3688 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
3690 if (atomic_read(&fcport->port_down_timer) == 0)
3693 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
3694 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
3696 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
3699 t, atomic_read(&fcport->port_down_timer)));
3702 } /* End of for fcport */
3705 * LUNS - lun suspend timer.
3707 * Whenever, a lun is suspended the timer starts decrementing its
3708 * suspend timer every second until it reaches zero. Once it reaches
3709 * zero the lun retry count is decremented.
3713 * FIXME(dg) - Need to convert this linear search of luns into a search
3714 * of a list of suspended luns.
3716 for (t = 0; t < ha->max_targets; t++) {
3717 if ((tq = ha->otgt[t]) == NULL)
3720 for (l = 0; l < ha->max_luns; l++) {
3721 if ((lq = (os_lun_t *) tq->olun[l]) == NULL)
3724 spin_lock_irqsave(&lq->q_lock, cpu_flags);
3725 if (lq->q_state == LUN_STATE_WAIT &&
3726 atomic_read(&lq->q_timer) != 0) {
3728 if (atomic_dec_and_test(&lq->q_timer) != 0) {
3730 * A delay should immediately
3731 * transition to a READY state
3733 if (test_and_clear_bit(LUN_EXEC_DELAYED,
3735 lq->q_state = LUN_STATE_READY;
3739 if (lq->q_count == lq->q_max)
3747 DEBUG3(printk("scsi(%ld): lun%d - timer %d, "
3748 "count=%d, max=%d, state=%d\n",
3751 atomic_read(&lq->q_timer),
3752 lq->q_count, lq->q_max, lq->q_state));
3754 spin_unlock_irqrestore(&lq->q_lock, cpu_flags);
3755 } /* End of for luns */
3756 } /* End of for targets */
3758 /* Loop down handler. */
3759 if (atomic_read(&ha->loop_down_timer) > 0 &&
3760 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) {
3762 if (atomic_read(&ha->loop_down_timer) ==
3763 ha->loop_down_abort_time) {
3765 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
3766 "queues before time expire\n",
3769 if (!IS_QLA2100(ha) && ha->link_down_timeout)
3770 atomic_set(&ha->loop_state, LOOP_DEAD);
3772 /* Schedule an ISP abort to return any tape commands. */
3773 spin_lock_irqsave(&ha->hardware_lock, cpu_flags);
3774 for (index = 1; index < MAX_OUTSTANDING_COMMANDS;
3776 sp = ha->outstanding_cmds[index];
3779 if (!(sp->fclun->fcport->flags &
3783 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3786 spin_unlock_irqrestore(&ha->hardware_lock, cpu_flags);
3788 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags);
3792 /* if the loop has been down for 4 minutes, reinit adapter */
3793 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) {
3794 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
3795 "restarting queues.\n",
3798 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags);
3801 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3802 DEBUG(printk("scsi(%ld): Loop down - "
3805 qla_printk(KERN_WARNING, ha,
3806 "Loop down - aborting ISP.\n");
3808 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
3811 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
3813 atomic_read(&ha->loop_down_timer)));
3817 * Done Q Handler -- dgFIXME This handler will kick off doneq if we
3818 * haven't process it in 2 seconds.
3820 if (!list_empty(&ha->done_queue))
3824 /* Schedule the DPC routine if needed */
3825 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
3826 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) ||
3828 test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags) ||
3829 test_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&
3830 ha->dpc_wait && !ha->dpc_active) {
3835 qla2x00_restart_timer(ha, WATCH_INTERVAL);
3839 * qla2x00_extend_timeout
3840 * This routine will extend the timeout to the specified value.
3843 * cmd = SCSI command structure
3849 qla2x00_extend_timeout(struct scsi_cmnd *cmd, int timeout)
3851 srb_t *sp = (srb_t *) CMD_SP(cmd);
3852 u_long our_jiffies = (timeout * HZ) + jiffies;
3855 sp->e_start = jiffies;
3856 if (cmd->eh_timeout.function) {
3857 mod_timer(&cmd->eh_timeout,our_jiffies);
3858 sp->ext_history |= 1;
3860 if (sp->timer.function != NULL) {
3862 * Our internal timer should timeout before the midlayer has a
3863 * chance begin the abort process
3865 mod_timer(&sp->timer,our_jiffies - (QLA_CMD_TIMER_DELTA * HZ));
3867 sp->ext_history |= 2;
3871 /**************************************************************************
3872 * qla2x00_cmd_timeout
3875 * Handles the command if it times out in any state.
3878 * sp - pointer to validate
3882 * Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).
3883 **************************************************************************/
3885 qla2x00_cmd_timeout(srb_t *sp)
3889 scsi_qla_host_t *vis_ha, *dest_ha;
3890 struct scsi_cmnd *cmd;
3891 unsigned long flags, cpu_flags;
3895 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
3897 DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state));
3899 t = cmd->device->id;
3900 l = cmd->device->lun;
3901 fcport = sp->fclun->fcport;
3905 * If IO is found either in retry Queue
3907 * Return this IO back to host
3909 spin_lock_irqsave(&vis_ha->list_lock, flags);
3911 if (sp->state == SRB_PENDING_STATE) {
3912 __del_from_pending_queue(vis_ha, sp);
3913 DEBUG2(printk("scsi(%ld): Found in Pending queue pid %ld, "
3914 "State = %x., fcport state=%d jiffies=%lx\n",
3915 vis_ha->host_no, cmd->serial_number, sp->state,
3916 atomic_read(&fcport->state), jiffies));
3919 * If FC_DEVICE is marked as dead return the cmd with
3920 * DID_NO_CONNECT status. Otherwise set the host_byte to
3921 * DID_BUS_BUSY to let the OS retry this cmd.
3923 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
3924 atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {
3925 cmd->result = DID_NO_CONNECT << 16;
3926 if (atomic_read(&fcport->ha->loop_state) == LOOP_DOWN)
3927 sp->err_id = SRB_ERR_LOOP;
3929 sp->err_id = SRB_ERR_PORT;
3931 cmd->result = DID_BUS_BUSY << 16;
3933 __add_to_done_queue(vis_ha, sp);
3936 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
3939 qla2x00_done(vis_ha);
3943 spin_lock_irqsave(&dest_ha->list_lock, flags);
3944 if ((sp->state == SRB_RETRY_STATE) ||
3945 (sp->state == SRB_SCSI_RETRY_STATE)) {
3947 DEBUG2(printk("scsi(%ld): Found in (Scsi) Retry queue or "
3948 "failover Q pid %ld, State = %x., fcport state=%d "
3949 "jiffies=%lx retried=%d\n",
3950 dest_ha->host_no, cmd->serial_number, sp->state,
3951 atomic_read(&fcport->state), jiffies, cmd->retries));
3953 if ((sp->state == SRB_RETRY_STATE)) {
3954 __del_from_retry_queue(dest_ha, sp);
3955 } else if ((sp->state == SRB_SCSI_RETRY_STATE)) {
3956 __del_from_scsi_retry_queue(dest_ha, sp);
3960 * If FC_DEVICE is marked as dead return the cmd with
3961 * DID_NO_CONNECT status. Otherwise set the host_byte to
3962 * DID_BUS_BUSY to let the OS retry this cmd.
3964 if ((atomic_read(&fcport->state) == FCS_DEVICE_DEAD) ||
3965 atomic_read(&dest_ha->loop_state) == LOOP_DEAD) {
3966 qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT);
3967 cmd->result = DID_NO_CONNECT << 16;
3968 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
3969 sp->err_id = SRB_ERR_LOOP;
3971 sp->err_id = SRB_ERR_PORT;
3973 cmd->result = DID_BUS_BUSY << 16;
3976 __add_to_done_queue(dest_ha, sp);
3979 spin_unlock_irqrestore(&dest_ha->list_lock, flags);
3982 qla2x00_done(dest_ha);
3987 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
3988 if (sp->state == SRB_DONE_STATE) {
3989 /* IO in done_q -- leave it */
3990 DEBUG(printk("scsi(%ld): Found in Done queue pid %ld sp=%p.\n",
3991 dest_ha->host_no, cmd->serial_number, sp));
3992 } else if (sp->state == SRB_SUSPENDED_STATE) {
3993 DEBUG(printk("scsi(%ld): Found SP %p in suspended state "
3995 dest_ha->host_no, sp, cmd->serial_number));
3996 DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));)
3997 } else if (sp->state == SRB_ACTIVE_STATE) {
3999 * IO is with ISP find the command in our active list.
4001 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4002 spin_lock_irqsave(&dest_ha->hardware_lock, flags);
4003 if (sp == dest_ha->outstanding_cmds[
4004 (unsigned long)sp->cmd->host_scribble]) {
4006 DEBUG(printk("cmd_timeout: Found in ISP \n"));
4008 if (sp->flags & SRB_TAPE) {
4010 * We cannot allow the midlayer error handler
4011 * to wakeup and begin the abort process.
4012 * Extend the timer so that the firmware can
4013 * properly return the IOCB.
4015 DEBUG(printk("cmd_timeout: Extending timeout "
4016 "of FCP2 tape command!\n"));
4017 qla2x00_extend_timeout(sp->cmd,
4018 EXTEND_CMD_TIMEOUT);
4020 sp->state = SRB_ACTIVE_TIMEOUT_STATE;
4021 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4023 spin_unlock_irqrestore(&dest_ha->hardware_lock, flags);
4025 "qla_cmd_timeout: State indicates it is with "
4026 "ISP, But not in active array\n");
4028 spin_lock_irqsave(&dest_ha->list_lock, cpu_flags);
4029 } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) {
4030 DEBUG(printk("qla2100%ld: Found in Active timeout state"
4031 "pid %ld, State = %x., \n",
4033 sp->cmd->serial_number, sp->state);)
4036 DEBUG2(printk("cmd_timeout%ld: LOST command state = "
4038 vis_ha->host_no, sp->state,sp);)
4040 qla_printk(KERN_INFO, vis_ha,
4041 "cmd_timeout: LOST command state = 0x%x\n", sp->state);
4043 spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);
4045 DEBUG3(printk("cmd_timeout: Leaving\n");)
4048 /**************************************************************************
4050 * Process completed commands.
4053 * old_ha = adapter block pointer.
4055 **************************************************************************/
4057 qla2x00_done(scsi_qla_host_t *old_ha)
4060 struct scsi_cmnd *cmd;
4061 unsigned long flags = 0;
4062 scsi_qla_host_t *ha;
4063 scsi_qla_host_t *vis_ha;
4064 int send_marker_once = 0;
4066 LIST_HEAD(local_sp_list);
4069 * Get into local queue such that we do not wind up calling done queue
4070 * tasklet for the same IOs from DPC or any other place.
4072 spin_lock_irqsave(&old_ha->list_lock, flags);
4073 list_splice_init(&old_ha->done_queue, &local_sp_list);
4074 spin_unlock_irqrestore(&old_ha->list_lock, flags);
4077 * All done commands are in the local queue, now do the call back.
4079 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4080 old_ha->done_q_cnt--;
4081 sp->state = SRB_NO_QUEUE_STATE;
4083 /* remove command from local list */
4084 list_del_init(&sp->list);
4090 vis_ha = (scsi_qla_host_t *)cmd->device->host->hostdata;
4094 if (sp->flags & SRB_DMA_VALID) {
4095 sp->flags &= ~SRB_DMA_VALID;
4097 /* Release memory used for this I/O */
4099 pci_unmap_sg(ha->pdev, cmd->request_buffer,
4100 cmd->use_sg, cmd->sc_data_direction);
4101 } else if (cmd->request_bufflen) {
4102 pci_unmap_page(ha->pdev, sp->dma_handle,
4103 cmd->request_bufflen,
4104 cmd->sc_data_direction);
4109 switch (host_byte(cmd->result)) {
4116 * Set marker needed, so we don't have to
4117 * send multiple markers
4119 if (!send_marker_once) {
4120 ha->marker_needed = 1;
4127 * A backdoor device-reset requires different
4128 * error handling. This code differentiates
4129 * between normal error handling and the
4133 if (ha->host->eh_active != EH_ACTIVE)
4134 cmd->result = DID_BUS_BUSY << 16;
4139 sp->flags &= ~SRB_ABORT_PENDING;
4140 sp->flags |= SRB_ABORTED;
4142 if (sp->flags & SRB_TIMEOUT)
4143 cmd->result = DID_TIME_OUT << 16;
4148 DEBUG2(printk("scsi(%ld:%d:%d) %s: did_error "
4149 "= %d, comp-scsi= 0x%x-0x%x.\n",
4151 cmd->device->id, cmd->device->lun,
4153 host_byte(cmd->result),
4154 CMD_COMPL_STATUS(cmd),
4155 CMD_SCSI_STATUS(cmd)));
4160 * Call the mid-level driver interrupt handler -- via sp_put()
4163 } /* end of while */
4167 * qla2x00_process_response_queue_in_zio_mode
4168 * Process response queue completion as fast as possible
4169 * to achieve Zero Interrupt Opertions-ZIO
4172 * ha = adapter block pointer.
4178 qla2x00_process_response_queue_in_zio_mode(scsi_qla_host_t *ha)
4180 unsigned long flags;
4182 /* Check for unprocessed commands in response queue. */
4183 if (!ha->flags.process_response_queue)
4185 if (!ha->flags.online)
4187 if (ha->response_ring_ptr->signature == RESPONSE_PROCESSED)
4190 spin_lock_irqsave(&ha->hardware_lock,flags);
4191 qla2x00_process_response_queue(ha);
4192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4197 * Retrieve and process next job in the LUN queue.
4200 * tq = SCSI target queue pointer.
4201 * lq = SCSI LUN queue pointer.
4202 * TGT_LOCK must be already obtained.
4205 * Releases TGT_LOCK upon exit.
4208 * Kernel/Interrupt context.
4210 * Note: This routine will always try to start I/O from visible HBA.
4213 qla2x00_next(scsi_qla_host_t *vis_ha)
4216 unsigned long flags;
4217 scsi_qla_host_t *dest_ha;
4220 LIST_HEAD(local_sp_list);
4224 spin_lock_irqsave(&vis_ha->list_lock, flags);
4225 list_splice_init(&vis_ha->pending_queue, &local_sp_list);
4226 vis_ha->qthreads = 0;
4227 spin_unlock_irqrestore(&vis_ha->list_lock, flags);
4229 list_for_each_entry_safe(sp, sptemp, &local_sp_list, list) {
4230 list_del_init(&sp->list);
4231 sp->state = SRB_NO_QUEUE_STATE;
4233 fcport = sp->fclun->fcport;
4234 dest_ha = fcport->ha;
4236 /* If device is dead then send request back to OS */
4237 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) {
4238 sp->cmd->result = DID_NO_CONNECT << 16;
4239 if (atomic_read(&dest_ha->loop_state) == LOOP_DOWN)
4240 sp->err_id = SRB_ERR_LOOP;
4242 sp->err_id = SRB_ERR_PORT;
4244 DEBUG3(printk("scsi(%ld): loop/port is down - pid=%ld, "
4245 "sp=%p err_id=%d loopid=0x%x queued to dest HBA "
4246 "scsi%ld.\n", dest_ha->host_no,
4247 sp->cmd->serial_number, sp, sp->err_id,
4248 fcport->loop_id, dest_ha->host_no));
4250 * Initiate a failover - done routine will initiate.
4252 add_to_done_queue(vis_ha, sp);
4258 * SCSI Kluge: Whenever, we need to wait for an event such as
4259 * loop down (i.e. loop_down_timer ) or port down (i.e. LUN
4260 * request qeueue is suspended) then we will recycle new
4261 * commands back to the SCSI layer. We do this because this is
4262 * normally a temporary condition and we don't want the
4263 * mid-level scsi.c driver to get upset and start aborting
4264 * commands. The timeout value is extracted from the command
4265 * minus 1-second and put on a retry queue (watchdog). Once the
4266 * command timeout it is returned to the mid-level with a BUSY
4267 * status, so the mid-level will retry it. This process
4268 * continues until the LOOP DOWN time expires or the condition
4271 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4272 (atomic_read(&fcport->state) != FCS_ONLINE ||
4273 test_bit(ABORT_ISP_ACTIVE, &dest_ha->dpc_flags) ||
4274 atomic_read(&dest_ha->loop_state) != LOOP_READY)) {
4276 DEBUG3(printk("scsi(%ld): port=(0x%x) retry_q(%d) "
4277 "loop state = %d, loop counter = 0x%x dpc flags "
4281 atomic_read(&fcport->state),
4282 atomic_read(&dest_ha->loop_state),
4283 atomic_read(&dest_ha->loop_down_timer),
4284 dest_ha->dpc_flags));
4286 qla2x00_extend_timeout(sp->cmd, EXTEND_CMD_TIMEOUT);
4287 add_to_retry_queue(vis_ha, sp);
4293 * If this request's lun is suspended then put the request on
4294 * the scsi_retry queue.
4296 if (!(sp->flags & (SRB_IOCTL | SRB_TAPE)) &&
4297 sp->lun_queue->q_state == LUN_STATE_WAIT) {
4298 DEBUG3(printk("scsi(%ld): lun wait state - pid=%ld, "
4299 "opcode=%d, allowed=%d, retries=%d\n",
4301 sp->cmd->serial_number,
4306 add_to_scsi_retry_queue(vis_ha, sp);
4311 sp->lun_queue->io_cnt++;
4313 rval = qla2x00_start_scsi(sp);
4314 if (rval != QLA_SUCCESS) {
4315 /* Place request back on top of device queue */
4316 /* add to the top of queue */
4317 add_to_pending_queue_head(vis_ha, sp);
4319 sp->lun_queue->io_cnt--;
4323 if (!IS_QLA2100(vis_ha) && !IS_QLA2200(vis_ha)) {
4324 /* Process response_queue if ZIO support is enabled*/
4325 qla2x00_process_response_queue_in_zio_mode(vis_ha);
4331 /**************************************************************************
4332 * qla2x00_check_tgt_status
4335 * Checks to see if the target or loop is down.
4338 * cmd - pointer to Scsi cmd structure
4341 * 1 - if target is present
4342 * 0 - if target is not present
4344 **************************************************************************/
4346 qla2x00_check_tgt_status(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
4349 unsigned int b, t, l;
4352 /* Generate LU queue on bus, target, LUN */
4353 b = cmd->device->channel;
4354 t = cmd->device->id;
4355 l = cmd->device->lun;
4357 if ((lq = GET_LU_Q(ha,t,l)) == NULL) {
4358 return (QLA_FUNCTION_FAILED);
4361 fcport = lq->fclun->fcport;
4363 if (TGT_Q(ha, t) == NULL ||
4364 l >= ha->max_luns ||
4365 atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4366 atomic_read(&ha->loop_state) == LOOP_DEAD ||
4367 (!atomic_read(&ha->loop_down_timer) &&
4368 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4369 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
4370 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4371 atomic_read(&ha->loop_state) != LOOP_READY) {
4373 DEBUG(printk(KERN_INFO
4374 "scsi(%ld:%2d:%2d:%2d): %s connection is down\n",
4379 cmd->result = DID_NO_CONNECT << 16;
4380 return (QLA_FUNCTION_FAILED);
4382 return (QLA_SUCCESS);
4385 /**************************************************************************
4386 * qla2x00_check_port_status
4389 * Checks to see if the port or loop is down.
4392 * fcport - pointer to fc_port_t structure.
4395 * 1 - if port is present
4396 * 0 - if port is not present
4398 **************************************************************************/
4400 qla2x00_check_port_status(scsi_qla_host_t *ha, fc_port_t *fcport)
4402 if (fcport == NULL) {
4403 return (QLA_FUNCTION_FAILED);
4406 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
4407 atomic_read(&ha->loop_state) == LOOP_DEAD) {
4408 return (QLA_FUNCTION_FAILED);
4411 if ((atomic_read(&fcport->state) != FCS_ONLINE) ||
4412 (!atomic_read(&ha->loop_down_timer) &&
4413 atomic_read(&ha->loop_state) == LOOP_DOWN) ||
4414 (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) ||
4415 test_bit(CFG_ACTIVE, &ha->cfg_flags) ||
4416 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) ||
4417 atomic_read(&ha->loop_state) != LOOP_READY) {
4419 DEBUG(printk(KERN_INFO
4420 "scsi(%ld): Connection is down. fcport=%p.\n",
4421 ha->host_no, fcport));
4426 return (QLA_SUCCESS);
4429 /* XXX(hch): crude hack to emulate a down_timeout() */
4431 qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
4433 const unsigned int step = HZ/10;
4436 if (!down_trylock(sema))
4438 set_current_state(TASK_INTERRUPTIBLE);
4439 if (schedule_timeout(step))
4441 } while ((timeout -= step) > 0);
4447 qla2xxx_get_port_id(struct scsi_target *starget)
4449 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4450 scsi_qla_host_t *ha = to_qla_host(shost);
4453 list_for_each_entry(fc, &ha->fcports, list) {
4454 if (fc->os_target_id == starget->id) {
4455 fc_starget_port_id(starget) = fc->d_id.b.domain << 16 |
4456 fc->d_id.b.area << 8 |
4461 fc_starget_port_id(starget) = -1;
4465 qla2xxx_get_port_name(struct scsi_target *starget)
4467 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4468 scsi_qla_host_t *ha = to_qla_host(shost);
4471 list_for_each_entry(fc, &ha->fcports, list) {
4472 if (fc->os_target_id == starget->id) {
4473 fc_starget_port_name(starget) =
4474 __be64_to_cpu(*(uint64_t *)fc->port_name);
4478 fc_starget_port_name(starget) = -1;
4482 qla2xxx_get_node_name(struct scsi_target *starget)
4484 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4485 scsi_qla_host_t *ha = to_qla_host(shost);
4488 list_for_each_entry(fc, &ha->fcports, list) {
4489 if (fc->os_target_id == starget->id) {
4490 fc_starget_node_name(starget) =
4491 __be64_to_cpu(*(uint64_t *)fc->node_name);
4495 fc_starget_node_name(starget) = -1;
4498 static struct fc_function_template qla2xxx_transport_functions = {
4499 .get_starget_port_id = qla2xxx_get_port_id,
4500 .show_starget_port_id = 1,
4501 .get_starget_port_name = qla2xxx_get_port_name,
4502 .show_starget_port_name = 1,
4503 .get_starget_node_name = qla2xxx_get_node_name,
4504 .show_starget_node_name = 1,
4508 * qla2x00_module_init - Module initialization.
4511 qla2x00_module_init(void)
4513 /* Allocate cache for SRBs. */
4514 sprintf(srb_cachep_name, "qla2xxx_srbs");
4515 srb_cachep = kmem_cache_create(srb_cachep_name, sizeof(srb_t), 0,
4516 SLAB_HWCACHE_ALIGN, NULL, NULL);
4517 if (srb_cachep == NULL) {
4519 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
4523 /* Derive version string. */
4524 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4526 strcat(qla2x00_version_str, "-debug");
4529 qla2xxx_transport_template = fc_attach_transport(&qla2xxx_transport_functions);
4530 if (!qla2xxx_transport_template)
4534 "QLogic Fibre Channel HBA Driver (%p)\n", qla2x00_set_info);
4540 * qla2x00_module_exit - Module cleanup.
4543 qla2x00_module_exit(void)
4545 /* Free SRBs cache. */
4546 if (srb_cachep != NULL) {
4547 if (kmem_cache_destroy(srb_cachep) != 0) {
4549 "qla2xxx: Unable to free SRB cache...Memory pools "
4555 fc_release_transport(qla2xxx_transport_template);
4558 module_init(qla2x00_module_init);
4559 module_exit(qla2x00_module_exit);
4561 MODULE_AUTHOR("QLogic Corporation");
4562 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4563 MODULE_LICENSE("GPL");
4564 MODULE_VERSION(QLA2XXX_VERSION);