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_slave_alloc(struct scsi_device
*);
155 static void qla2xxx_slave_destroy(struct scsi_device
*);
156 static int qla2x00_queuecommand(struct scsi_cmnd
*cmd
,
157 void (*fn
)(struct scsi_cmnd
*));
158 static int qla2xxx_eh_abort(struct scsi_cmnd
*);
159 static int qla2xxx_eh_device_reset(struct scsi_cmnd
*);
160 static int qla2xxx_eh_bus_reset(struct scsi_cmnd
*);
161 static int qla2xxx_eh_host_reset(struct scsi_cmnd
*);
162 static int qla2x00_loop_reset(scsi_qla_host_t
*ha
);
163 static int qla2x00_device_reset(scsi_qla_host_t
*, fc_port_t
*);
165 static int qla2x00_proc_info(struct Scsi_Host
*, char *, char **,
168 static struct scsi_host_template qla2x00_driver_template
= {
169 .module
= THIS_MODULE
,
171 .proc_name
= "qla2xxx",
172 .proc_info
= qla2x00_proc_info
,
173 .queuecommand
= qla2x00_queuecommand
,
175 .eh_abort_handler
= qla2xxx_eh_abort
,
176 .eh_device_reset_handler
= qla2xxx_eh_device_reset
,
177 .eh_bus_reset_handler
= qla2xxx_eh_bus_reset
,
178 .eh_host_reset_handler
= qla2xxx_eh_host_reset
,
180 .slave_configure
= qla2xxx_slave_configure
,
182 .slave_alloc
= qla2xxx_slave_alloc
,
183 .slave_destroy
= qla2xxx_slave_destroy
,
186 .use_clustering
= ENABLE_CLUSTERING
,
187 .sg_tablesize
= SG_ALL
,
190 * The RISC allows for each command to transfer (2^32-1) bytes of data,
191 * which equates to 0x800000 sectors.
193 .max_sectors
= 0xFFFF,
196 static struct scsi_transport_template
*qla2xxx_transport_template
= NULL
;
198 static void qla2x00_display_fc_names(scsi_qla_host_t
*);
200 /* TODO Convert to inlines
204 #define WATCH_INTERVAL 1 /* number of seconds */
206 static void qla2x00_timer(scsi_qla_host_t
*);
208 static __inline__
void qla2x00_start_timer(scsi_qla_host_t
*,
209 void *, unsigned long);
210 static __inline__
void qla2x00_restart_timer(scsi_qla_host_t
*, unsigned long);
211 static __inline__
void qla2x00_stop_timer(scsi_qla_host_t
*);
214 qla2x00_start_timer(scsi_qla_host_t
*ha
, void *func
, unsigned long interval
)
216 init_timer(&ha
->timer
);
217 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
218 ha
->timer
.data
= (unsigned long)ha
;
219 ha
->timer
.function
= (void (*)(unsigned long))func
;
220 add_timer(&ha
->timer
);
221 ha
->timer_active
= 1;
225 qla2x00_restart_timer(scsi_qla_host_t
*ha
, unsigned long interval
)
227 mod_timer(&ha
->timer
, jiffies
+ interval
* HZ
);
230 static __inline__
void
231 qla2x00_stop_timer(scsi_qla_host_t
*ha
)
233 del_timer_sync(&ha
->timer
);
234 ha
->timer_active
= 0;
237 static int qla2x00_do_dpc(void *data
);
239 static void qla2x00_rst_aen(scsi_qla_host_t
*);
241 static uint8_t qla2x00_mem_alloc(scsi_qla_host_t
*);
242 static void qla2x00_mem_free(scsi_qla_host_t
*ha
);
243 static int qla2x00_allocate_sp_pool( scsi_qla_host_t
*ha
);
244 static void qla2x00_free_sp_pool(scsi_qla_host_t
*ha
);
245 static srb_t
*qla2x00_get_new_sp(scsi_qla_host_t
*);
246 static void qla2x00_sp_free_dma(scsi_qla_host_t
*, srb_t
*);
247 void qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*);
249 static ssize_t
qla2x00_sysfs_read_fw_dump(struct kobject
*, char *, loff_t
,
251 static ssize_t
qla2x00_sysfs_write_fw_dump(struct kobject
*, char *, loff_t
,
253 static struct bin_attribute sysfs_fw_dump_attr
= {
256 .mode
= S_IRUSR
| S_IWUSR
,
257 .owner
= THIS_MODULE
,
260 .read
= qla2x00_sysfs_read_fw_dump
,
261 .write
= qla2x00_sysfs_write_fw_dump
,
263 static ssize_t
qla2x00_sysfs_read_nvram(struct kobject
*, char *, loff_t
,
265 static ssize_t
qla2x00_sysfs_write_nvram(struct kobject
*, char *, loff_t
,
267 static struct bin_attribute sysfs_nvram_attr
= {
270 .mode
= S_IRUSR
| S_IWUSR
,
271 .owner
= THIS_MODULE
,
273 .size
= sizeof(nvram_t
),
274 .read
= qla2x00_sysfs_read_nvram
,
275 .write
= qla2x00_sysfs_write_nvram
,
278 /* -------------------------------------------------------------------------- */
281 /* SysFS attributes. */
282 static ssize_t
qla2x00_sysfs_read_fw_dump(struct kobject
*kobj
, char *buf
,
283 loff_t off
, size_t count
)
285 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
286 struct device
, kobj
)));
288 if (ha
->fw_dump_reading
== 0)
290 if (off
> ha
->fw_dump_buffer_len
)
292 if (off
+ count
> ha
->fw_dump_buffer_len
)
293 count
= ha
->fw_dump_buffer_len
- off
;
295 memcpy(buf
, &ha
->fw_dump_buffer
[off
], count
);
300 static ssize_t
qla2x00_sysfs_write_fw_dump(struct kobject
*kobj
, char *buf
,
301 loff_t off
, size_t count
)
303 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
304 struct device
, kobj
)));
311 reading
= simple_strtol(buf
, NULL
, 10);
314 if (ha
->fw_dump_reading
== 1) {
315 qla_printk(KERN_INFO
, ha
,
316 "Firmware dump cleared on (%ld).\n",
319 vfree(ha
->fw_dump_buffer
);
320 free_pages((unsigned long)ha
->fw_dump
,
323 ha
->fw_dump_reading
= 0;
324 ha
->fw_dump_buffer
= NULL
;
329 if (ha
->fw_dump
!= NULL
&& !ha
->fw_dump_reading
) {
330 ha
->fw_dump_reading
= 1;
332 dump_size
= FW_DUMP_SIZE_1M
;
333 if (ha
->fw_memory_size
< 0x20000)
334 dump_size
= FW_DUMP_SIZE_128K
;
335 else if (ha
->fw_memory_size
< 0x80000)
336 dump_size
= FW_DUMP_SIZE_512K
;
337 ha
->fw_dump_buffer
= (char *)vmalloc(dump_size
);
338 if (ha
->fw_dump_buffer
== NULL
) {
339 qla_printk(KERN_WARNING
, ha
,
340 "Unable to allocate memory for firmware "
341 "dump buffer (%d).\n", dump_size
);
343 ha
->fw_dump_reading
= 0;
346 qla_printk(KERN_INFO
, ha
,
347 "Firmware dump ready for read on (%ld).\n",
349 memset(ha
->fw_dump_buffer
, 0, dump_size
);
350 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
351 qla2100_ascii_fw_dump(ha
);
353 qla2300_ascii_fw_dump(ha
);
354 ha
->fw_dump_buffer_len
= strlen(ha
->fw_dump_buffer
);
361 static ssize_t
qla2x00_sysfs_read_nvram(struct kobject
*kobj
, char *buf
,
362 loff_t off
, size_t count
)
364 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
365 struct device
, kobj
)));
370 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= sizeof(nvram_t
))
374 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
375 qla2x00_lock_nvram_access(ha
);
376 witer
= (uint16_t *)buf
;
377 for (cnt
= 0; cnt
< count
/ 2; cnt
++) {
378 *witer
= cpu_to_le16(qla2x00_get_nvram_word(ha
,
379 cnt
+ha
->nvram_base
));
382 qla2x00_unlock_nvram_access(ha
);
383 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
388 static ssize_t
qla2x00_sysfs_write_nvram(struct kobject
*kobj
, char *buf
,
389 loff_t off
, size_t count
)
391 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
392 struct device
, kobj
)));
399 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= sizeof(nvram_t
))
402 /* Checksum NVRAM. */
403 iter
= (uint8_t *)buf
;
405 for (cnt
= 0; cnt
< count
- 1; cnt
++)
407 chksum
= ~chksum
+ 1;
411 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
412 qla2x00_lock_nvram_access(ha
);
413 qla2x00_release_nvram_protection(ha
);
414 witer
= (uint16_t *)buf
;
415 for (cnt
= 0; cnt
< count
/ 2; cnt
++) {
416 qla2x00_write_nvram_word(ha
, cnt
+ha
->nvram_base
,
417 cpu_to_le16(*witer
));
420 qla2x00_unlock_nvram_access(ha
);
421 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
426 /* -------------------------------------------------------------------------- */
428 qla2x00_get_pci_info_str(struct scsi_qla_host
*ha
, char *str
)
430 static char *pci_bus_modes
[] = {
431 "33", "66", "100", "133",
436 pci_bus
= (ha
->pci_attr
& (BIT_9
| BIT_10
)) >> 9;
439 strcat(str
, pci_bus_modes
[pci_bus
]);
441 pci_bus
= (ha
->pci_attr
& BIT_8
) >> 8;
443 strcat(str
, pci_bus_modes
[pci_bus
]);
445 strcat(str
, " MHz)");
451 qla2x00_get_fw_version_str(struct scsi_qla_host
*ha
, char *str
)
455 sprintf(str
, "%d.%02d.%02d ", ha
->fw_major_version
,
456 ha
->fw_minor_version
,
457 ha
->fw_subminor_version
);
459 if (ha
->fw_attributes
& BIT_9
) {
464 switch (ha
->fw_attributes
& 0xFF) {
478 sprintf(un_str
, "(%x)", ha
->fw_attributes
);
482 if (ha
->fw_attributes
& 0x100)
488 /**************************************************************************
489 * qla2x00_queuecommand
492 * Queue a command to the controller.
495 * cmd - pointer to Scsi cmd structure
496 * fn - pointer to Scsi done function
502 * The mid-level driver tries to ensures that queuecommand never gets invoked
503 * concurrently with itself or the interrupt handler (although the
504 * interrupt handler may call this routine as part of request-completion
506 **************************************************************************/
508 qla2x00_queuecommand(struct scsi_cmnd
*cmd
, void (*done
)(struct scsi_cmnd
*))
510 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
511 os_tgt_t
*tq
= (os_tgt_t
*) cmd
->device
->hostdata
;
512 fc_port_t
*fcport
= tq
->fcport
;
517 lq
= GET_LU_Q(ha
, cmd
->device
->id
, cmd
->device
->lun
);
518 if (!fcport
|| !lq
) {
519 cmd
->result
= DID_NO_CONNECT
<< 16;
520 goto qc_fail_command
;
523 if (atomic_read(&fcport
->state
) != FCS_ONLINE
) {
524 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
||
525 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
526 cmd
->result
= DID_NO_CONNECT
<< 16;
527 goto qc_fail_command
;
532 spin_unlock_irq(ha
->host
->host_lock
);
534 /* Allocate a command packet from the "sp" pool. */
535 if ((sp
= qla2x00_get_new_sp(ha
)) == NULL
) {
536 goto qc_host_busy_lock
;
545 sp
->fclun
= lq
->fclun
;
550 CMD_SP(cmd
) = (void *)sp
;
551 cmd
->scsi_done
= done
;
553 rval
= qla2x00_start_scsi(sp
);
554 if (rval
!= QLA_SUCCESS
)
555 goto qc_host_busy_free_sp
;
557 /* Manage unprocessed RIO/ZIO commands in response queue. */
558 if (ha
->flags
.online
&& ha
->flags
.process_response_queue
&&
559 ha
->response_ring_ptr
->signature
!= RESPONSE_PROCESSED
) {
562 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
563 qla2x00_process_response_queue(ha
);
564 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
567 spin_lock_irq(ha
->host
->host_lock
);
571 qc_host_busy_free_sp
:
572 qla2x00_sp_free_dma(ha
, sp
);
574 mempool_free(sp
, ha
->srb_mempool
);
577 spin_lock_irq(ha
->host
->host_lock
);
580 return SCSI_MLQUEUE_HOST_BUSY
;
589 * qla2x00_eh_wait_on_command
590 * Waits for the command to be returned by the Firmware for some
594 * ha = actual ha whose done queue will contain the command
595 * returned by firmware.
596 * cmd = Scsi Command to wait on.
597 * flag = Abort/Reset(Bus or Device Reset)
604 qla2x00_eh_wait_on_command(scsi_qla_host_t
*ha
, struct scsi_cmnd
*cmd
)
606 #define ABORT_POLLING_PERIOD HZ
607 #define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD))
608 unsigned long wait_iter
= ABORT_WAIT_ITER
;
609 int ret
= QLA_SUCCESS
;
611 while (CMD_SP(cmd
)) {
612 set_current_state(TASK_UNINTERRUPTIBLE
);
613 schedule_timeout(ABORT_POLLING_PERIOD
);
619 ret
= QLA_FUNCTION_FAILED
;
625 * qla2x00_wait_for_hba_online
626 * Wait till the HBA is online after going through
627 * <= MAX_RETRIES_OF_ISP_ABORT or
628 * finally HBA is disabled ie marked offline
631 * ha - pointer to host adapter structure
634 * Does context switching-Release SPIN_LOCK
635 * (if any) before calling this routine.
638 * Success (Adapter is online) : 0
639 * Failed (Adapter is offline/disabled) : 1
642 qla2x00_wait_for_hba_online(scsi_qla_host_t
*ha
)
645 unsigned long wait_online
;
647 wait_online
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
648 while (((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) ||
649 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
650 test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
) ||
651 ha
->dpc_active
) && time_before(jiffies
, wait_online
)) {
655 if (ha
->flags
.online
)
656 return_status
= QLA_SUCCESS
;
658 return_status
= QLA_FUNCTION_FAILED
;
660 DEBUG2(printk("%s return_status=%d\n",__func__
,return_status
));
662 return (return_status
);
666 * qla2x00_wait_for_loop_ready
667 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
668 * to be in LOOP_READY state.
670 * ha - pointer to host adapter structure
673 * Does context switching-Release SPIN_LOCK
674 * (if any) before calling this routine.
678 * Success (LOOP_READY) : 0
679 * Failed (LOOP_NOT_READY) : 1
682 qla2x00_wait_for_loop_ready(scsi_qla_host_t
*ha
)
684 int return_status
= QLA_SUCCESS
;
685 unsigned long loop_timeout
;
687 /* wait for 5 min at the max for loop to be ready */
688 loop_timeout
= jiffies
+ (MAX_LOOP_TIMEOUT
* HZ
);
690 while ((!atomic_read(&ha
->loop_down_timer
) &&
691 atomic_read(&ha
->loop_state
) == LOOP_DOWN
) ||
692 test_bit(CFG_ACTIVE
, &ha
->cfg_flags
) ||
693 atomic_read(&ha
->loop_state
) != LOOP_READY
) {
695 if (time_after_eq(jiffies
, loop_timeout
)) {
696 return_status
= QLA_FUNCTION_FAILED
;
700 return (return_status
);
703 /**************************************************************************
707 * The abort function will abort the specified command.
710 * cmd = Linux SCSI command packet to be aborted.
713 * Either SUCCESS or FAILED.
716 **************************************************************************/
718 qla2xxx_eh_abort(struct scsi_cmnd
*cmd
)
720 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
723 unsigned int id
, lun
;
724 unsigned long serial
;
731 id
= cmd
->device
->id
;
732 lun
= cmd
->device
->lun
;
733 serial
= cmd
->serial_number
;
735 /* Check active list for command command. */
736 spin_unlock_irq(ha
->host
->host_lock
);
737 spin_lock(&ha
->hardware_lock
);
738 for (i
= 1; i
< MAX_OUTSTANDING_COMMANDS
; i
++) {
739 sp
= ha
->outstanding_cmds
[i
];
747 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld "
748 "sp->state=%x\n", __func__
, ha
->host_no
, sp
, serial
,
750 DEBUG3(qla2x00_print_scsi_cmd(cmd
);)
752 spin_unlock(&ha
->hardware_lock
);
753 if (qla2x00_abort_command(ha
, sp
)) {
754 DEBUG2(printk("%s(%ld): abort_command "
755 "mbx failed.\n", __func__
, ha
->host_no
));
757 DEBUG3(printk("%s(%ld): abort_command "
758 "mbx success.\n", __func__
, ha
->host_no
));
761 spin_lock(&ha
->hardware_lock
);
766 /* Wait for the command to be returned. */
767 if (ret
== SUCCESS
) {
768 spin_unlock(&ha
->hardware_lock
);
769 if (qla2x00_eh_wait_on_command(ha
, cmd
) != QLA_SUCCESS
) {
770 qla_printk(KERN_ERR
, ha
,
771 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
772 "%x.\n", ha
->host_no
, id
, lun
, serial
, ret
);
774 spin_lock(&ha
->hardware_lock
);
776 spin_lock_irq(ha
->host
->host_lock
);
778 qla_printk(KERN_INFO
, ha
,
779 "scsi(%ld:%d:%d): Abort command issued -- %lx %x.\n", ha
->host_no
,
780 id
, lun
, serial
, ret
);
785 /**************************************************************************
786 * qla2x00_eh_wait_for_pending_target_commands
789 * Waits for all the commands to come back from the specified target.
792 * ha - pointer to scsi_qla_host structure.
795 * Either SUCCESS or FAILED.
798 **************************************************************************/
800 qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t
*ha
, unsigned int t
)
805 struct scsi_cmnd
*cmd
;
810 * Waiting for all commands for the designated target in the active
813 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
814 spin_lock(&ha
->hardware_lock
);
815 sp
= ha
->outstanding_cmds
[cnt
];
818 spin_unlock(&ha
->hardware_lock
);
819 if (cmd
->device
->id
== t
) {
820 if (!qla2x00_eh_wait_on_command(ha
, cmd
)) {
826 spin_unlock(&ha
->hardware_lock
);
833 /**************************************************************************
834 * qla2xxx_eh_device_reset
837 * The device reset function will reset the target and abort any
838 * executing commands.
840 * NOTE: The use of SP is undefined within this context. Do *NOT*
841 * attempt to use this value, even if you determine it is
845 * cmd = Linux SCSI command packet of the command that cause the
849 * SUCCESS/FAILURE (defined as macro in scsi.h).
851 **************************************************************************/
853 qla2xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
855 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
856 os_tgt_t
*tq
= (os_tgt_t
*) cmd
->device
->hostdata
;
857 fc_port_t
*fcport
= tq
->fcport
;
861 unsigned int id
, lun
;
862 unsigned long serial
;
866 id
= cmd
->device
->id
;
867 lun
= cmd
->device
->lun
;
868 serial
= cmd
->serial_number
;
870 sp
= (srb_t
*) CMD_SP(cmd
);
871 lq
= GET_LU_Q(ha
, id
, lun
);
872 if (!sp
|| !fcport
|| !lq
)
875 qla_printk(KERN_INFO
, ha
,
876 "scsi(%ld:%d:%d): DEVICE RESET ISSUED.\n", ha
->host_no
, id
, lun
);
878 spin_unlock_irq(ha
->host
->host_lock
);
880 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
881 spin_lock_irq(ha
->host
->host_lock
);
882 goto eh_dev_reset_done
;
885 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
886 if (qla2x00_device_reset(ha
, fcport
) == 0)
889 #if defined(LOGOUT_AFTER_DEVICE_RESET)
890 if (ret
== SUCCESS
) {
891 if (fcport
->flags
& FC_FABRIC_DEVICE
) {
892 qla2x00_fabric_logout(ha
, fcport
->loop_id
);
893 qla2x00_mark_device_lost(ha
, fcport
);
898 DEBUG2(printk(KERN_INFO
899 "%s failed: loop not ready\n",__func__
);)
903 DEBUG3(printk("%s(%ld): device reset failed\n",
904 __func__
, ha
->host_no
));
905 qla_printk(KERN_INFO
, ha
, "%s: device reset failed\n",
908 goto eh_dev_reset_done
;
912 * If we are coming down the EH path, wait for all commands to
913 * complete for the device.
915 if (cmd
->device
->host
->eh_active
) {
916 if (qla2x00_eh_wait_for_pending_target_commands(ha
, id
))
920 DEBUG3(printk("%s(%ld): failed while waiting for "
921 "commands\n", __func__
, ha
->host_no
));
922 qla_printk(KERN_INFO
, ha
,
923 "%s: failed while waiting for commands\n",
926 goto eh_dev_reset_done
;
930 qla_printk(KERN_INFO
, ha
,
931 "scsi(%ld:%d:%d): DEVICE RESET SUCCEEDED.\n", ha
->host_no
, id
, lun
);
934 spin_lock_irq(ha
->host
->host_lock
);
939 /**************************************************************************
940 * qla2x00_eh_wait_for_pending_commands
943 * Waits for all the commands to come back from the specified host.
946 * ha - pointer to scsi_qla_host structure.
953 **************************************************************************/
955 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t
*ha
)
960 struct scsi_cmnd
*cmd
;
965 * Waiting for all commands for the designated target in the active
968 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
969 spin_lock(&ha
->hardware_lock
);
970 sp
= ha
->outstanding_cmds
[cnt
];
973 spin_unlock(&ha
->hardware_lock
);
974 status
= qla2x00_eh_wait_on_command(ha
, cmd
);
979 spin_unlock(&ha
->hardware_lock
);
986 /**************************************************************************
987 * qla2xxx_eh_bus_reset
990 * The bus reset function will reset the bus and abort any executing
994 * cmd = Linux SCSI command packet of the command that cause the
998 * SUCCESS/FAILURE (defined as macro in scsi.h).
1000 **************************************************************************/
1002 qla2xxx_eh_bus_reset(struct scsi_cmnd
*cmd
)
1004 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
1005 os_tgt_t
*tq
= (os_tgt_t
*) cmd
->device
->hostdata
;
1006 fc_port_t
*fcport
= tq
->fcport
;
1010 unsigned int id
, lun
;
1011 unsigned long serial
;
1015 id
= cmd
->device
->id
;
1016 lun
= cmd
->device
->lun
;
1017 serial
= cmd
->serial_number
;
1019 sp
= (srb_t
*) CMD_SP(cmd
);
1020 lq
= GET_LU_Q(ha
, id
, lun
);
1021 if (!sp
|| !fcport
|| !lq
)
1024 qla_printk(KERN_INFO
, ha
,
1025 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha
->host_no
, id
, lun
);
1027 spin_unlock_irq(ha
->host
->host_lock
);
1029 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
1030 DEBUG2(printk("%s failed:board disabled\n",__func__
));
1031 goto eh_bus_reset_done
;
1034 if (qla2x00_wait_for_loop_ready(ha
) == QLA_SUCCESS
) {
1035 if (qla2x00_loop_reset(ha
) == QLA_SUCCESS
)
1039 goto eh_bus_reset_done
;
1041 /* Waiting for our command in done_queue to be returned to OS.*/
1042 if (cmd
->device
->host
->eh_active
)
1043 if (!qla2x00_eh_wait_for_pending_commands(ha
))
1047 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1048 (ret
== FAILED
) ? "failed" : "succeded");
1050 spin_lock_irq(ha
->host
->host_lock
);
1055 /**************************************************************************
1056 * qla2xxx_eh_host_reset
1059 * The reset function will reset the Adapter.
1062 * cmd = Linux SCSI command packet of the command that cause the
1066 * Either SUCCESS or FAILED.
1069 **************************************************************************/
1071 qla2xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1073 scsi_qla_host_t
*ha
= to_qla_host(cmd
->device
->host
);
1074 os_tgt_t
*tq
= (os_tgt_t
*) cmd
->device
->hostdata
;
1075 fc_port_t
*fcport
= tq
->fcport
;
1079 unsigned int id
, lun
;
1080 unsigned long serial
;
1084 id
= cmd
->device
->id
;
1085 lun
= cmd
->device
->lun
;
1086 serial
= cmd
->serial_number
;
1088 sp
= (srb_t
*) CMD_SP(cmd
);
1089 lq
= GET_LU_Q(ha
, id
, lun
);
1090 if (!sp
|| !fcport
|| !lq
)
1093 qla_printk(KERN_INFO
, ha
,
1094 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
, id
, lun
);
1096 spin_unlock_irq(ha
->host
->host_lock
);
1098 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
1099 goto eh_host_reset_lock
;
1102 * Fixme-may be dpc thread is active and processing
1103 * loop_resync,so wait a while for it to
1104 * be completed and then issue big hammer.Otherwise
1105 * it may cause I/O failure as big hammer marks the
1106 * devices as lost kicking of the port_down_timer
1107 * while dpc is stuck for the mailbox to complete.
1109 qla2x00_wait_for_loop_ready(ha
);
1110 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
1111 if (qla2x00_abort_isp(ha
)) {
1112 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
1113 /* failed. schedule dpc to try */
1114 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1116 if (qla2x00_wait_for_hba_online(ha
) != QLA_SUCCESS
)
1117 goto eh_host_reset_lock
;
1119 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
1121 /* Waiting for our command in done_queue to be returned to OS.*/
1122 if (qla2x00_eh_wait_for_pending_commands(ha
))
1126 spin_lock_irq(ha
->host
->host_lock
);
1128 qla_printk(KERN_INFO
, ha
, "%s: reset %s\n", __func__
,
1129 (ret
== FAILED
) ? "failed" : "succeded");
1135 * qla2x00_loop_reset
1139 * ha = adapter block pointer.
1145 qla2x00_loop_reset(scsi_qla_host_t
*ha
)
1147 int status
= QLA_SUCCESS
;
1151 if (ha
->flags
.enable_lip_reset
) {
1152 status
= qla2x00_lip_reset(ha
);
1155 if (status
== QLA_SUCCESS
&& ha
->flags
.enable_target_reset
) {
1156 for (t
= 0; t
< MAX_FIBRE_DEVICES
; t
++) {
1157 if ((tq
= TGT_Q(ha
, t
)) == NULL
)
1160 if (tq
->fcport
== NULL
)
1163 status
= qla2x00_target_reset(ha
, 0, t
);
1164 if (status
!= QLA_SUCCESS
) {
1170 if (status
== QLA_SUCCESS
&&
1171 ((!ha
->flags
.enable_target_reset
&&
1172 !ha
->flags
.enable_lip_reset
) ||
1173 ha
->flags
.enable_lip_full_login
)) {
1175 status
= qla2x00_full_login_lip(ha
);
1178 /* Issue marker command only when we are going to start the I/O */
1179 ha
->marker_needed
= 1;
1183 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1188 DEBUG3(printk("%s(%ld): exiting normally.\n",
1197 * qla2x00_device_reset
1198 * Issue bus device reset message to the target.
1201 * ha = adapter block pointer.
1203 * TARGET_QUEUE_LOCK must be released.
1204 * ADAPTER_STATE_LOCK must be released.
1210 qla2x00_device_reset(scsi_qla_host_t
*ha
, fc_port_t
*reset_fcport
)
1212 /* Abort Target command will clear Reservation */
1213 return qla2x00_abort_target(reset_fcport
);
1217 qla2xxx_slave_alloc(struct scsi_device
*sdev
)
1219 scsi_qla_host_t
*ha
= to_qla_host(sdev
->host
);
1222 tq
= (os_tgt_t
*) TGT_Q(ha
, sdev
->id
);
1228 sdev
->hostdata
= tq
;
1234 qla2xxx_slave_configure(struct scsi_device
*sdev
)
1236 if (sdev
->tagged_supported
)
1237 scsi_activate_tcq(sdev
, 32);
1239 scsi_deactivate_tcq(sdev
, 32);
1245 qla2xxx_slave_destroy(struct scsi_device
*sdev
)
1247 sdev
->hostdata
= NULL
;
1251 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1254 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1255 * supported addressing method.
1258 qla2x00_config_dma_addressing(scsi_qla_host_t
*ha
)
1260 /* Assume 32bit DMA address */
1261 ha
->flags
.enable_64bit_addressing
= 0;
1262 ha
->calc_request_entries
= qla2x00_calc_iocbs_32
;
1263 ha
->build_scsi_iocbs
= qla2x00_build_scsi_iocbs_32
;
1266 * Given the two variants pci_set_dma_mask(), allow the compiler to
1267 * assist in setting the proper dma mask.
1269 if (sizeof(dma_addr_t
) > 4) {
1270 if (pci_set_dma_mask(ha
->pdev
, DMA_64BIT_MASK
) == 0) {
1271 ha
->flags
.enable_64bit_addressing
= 1;
1272 ha
->calc_request_entries
= qla2x00_calc_iocbs_64
;
1273 ha
->build_scsi_iocbs
= qla2x00_build_scsi_iocbs_64
;
1275 if (pci_set_consistent_dma_mask(ha
->pdev
,
1277 qla_printk(KERN_DEBUG
, ha
,
1278 "Failed to set 64 bit PCI consistent mask; "
1280 pci_set_consistent_dma_mask(ha
->pdev
,
1284 qla_printk(KERN_DEBUG
, ha
,
1285 "Failed to set 64 bit PCI DMA mask, falling back "
1286 "to 32 bit MASK.\n");
1287 pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1290 pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1295 qla2x00_iospace_config(scsi_qla_host_t
*ha
)
1297 unsigned long pio
, pio_len
, pio_flags
;
1298 unsigned long mmio
, mmio_len
, mmio_flags
;
1300 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1301 pio
= pci_resource_start(ha
->pdev
, 0);
1302 pio_len
= pci_resource_len(ha
->pdev
, 0);
1303 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1304 if (pio_flags
& IORESOURCE_IO
) {
1305 if (pio_len
< MIN_IOBASE_LEN
) {
1306 qla_printk(KERN_WARNING
, ha
,
1307 "Invalid PCI I/O region size (%s)...\n",
1308 pci_name(ha
->pdev
));
1312 qla_printk(KERN_WARNING
, ha
,
1313 "region #0 not a PIO resource (%s)...\n",
1314 pci_name(ha
->pdev
));
1318 /* Use MMIO operations for all accesses. */
1319 mmio
= pci_resource_start(ha
->pdev
, 1);
1320 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1321 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1323 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1324 qla_printk(KERN_ERR
, ha
,
1325 "region #0 not an MMIO resource (%s), aborting\n",
1326 pci_name(ha
->pdev
));
1327 goto iospace_error_exit
;
1329 if (mmio_len
< MIN_IOBASE_LEN
) {
1330 qla_printk(KERN_ERR
, ha
,
1331 "Invalid PCI mem region size (%s), aborting\n",
1332 pci_name(ha
->pdev
));
1333 goto iospace_error_exit
;
1336 if (pci_request_regions(ha
->pdev
, ha
->brd_info
->drv_name
)) {
1337 qla_printk(KERN_WARNING
, ha
,
1338 "Failed to reserve PIO/MMIO regions (%s)\n",
1339 pci_name(ha
->pdev
));
1341 goto iospace_error_exit
;
1344 ha
->pio_address
= pio
;
1345 ha
->pio_length
= pio_len
;
1346 ha
->iobase
= ioremap(mmio
, MIN_IOBASE_LEN
);
1348 qla_printk(KERN_ERR
, ha
,
1349 "cannot remap MMIO (%s), aborting\n", pci_name(ha
->pdev
));
1351 goto iospace_error_exit
;
1361 * PCI driver interface
1363 int qla2x00_probe_one(struct pci_dev
*pdev
, struct qla_board_info
*brd_info
)
1366 device_reg_t __iomem
*reg
;
1367 struct Scsi_Host
*host
;
1368 scsi_qla_host_t
*ha
;
1369 unsigned long flags
= 0;
1370 unsigned long wait_switch
= 0;
1374 if (pci_enable_device(pdev
))
1377 host
= scsi_host_alloc(&qla2x00_driver_template
,
1378 sizeof(scsi_qla_host_t
));
1381 "qla2xxx: Couldn't allocate host from scsi layer!\n");
1382 goto probe_disable_device
;
1385 /* Clear our data area */
1386 ha
= (scsi_qla_host_t
*)host
->hostdata
;
1387 memset(ha
, 0, sizeof(scsi_qla_host_t
));
1391 ha
->host_no
= host
->host_no
;
1392 ha
->brd_info
= brd_info
;
1393 sprintf(ha
->host_str
, "%s_%ld", ha
->brd_info
->drv_name
, ha
->host_no
);
1395 /* Configure PCI I/O space */
1396 ret
= qla2x00_iospace_config(ha
);
1401 /* Sanitize the information from PCI BIOS. */
1402 host
->irq
= pdev
->irq
;
1404 qla_printk(KERN_INFO
, ha
,
1405 "Found an %s, irq %d, iobase 0x%p\n", ha
->brd_info
->isp_name
,
1406 host
->irq
, ha
->iobase
);
1408 spin_lock_init(&ha
->hardware_lock
);
1410 /* 4.23 Initialize /proc/scsi/qla2x00 counters */
1413 ha
->total_isr_cnt
= 0;
1414 ha
->total_isp_aborts
= 0;
1415 ha
->total_lip_cnt
= 0;
1416 ha
->total_dev_errs
= 0;
1418 ha
->total_bytes
= 0;
1420 ha
->prev_topology
= 0;
1421 ha
->ports
= MAX_BUSES
;
1423 if (IS_QLA2100(ha
)) {
1424 ha
->max_targets
= MAX_TARGETS_2100
;
1425 ha
->mbx_count
= MAILBOX_REGISTER_COUNT_2100
;
1426 ha
->request_q_length
= REQUEST_ENTRY_CNT_2100
;
1427 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1428 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1429 host
->sg_tablesize
= 32;
1430 } else if (IS_QLA2200(ha
)) {
1431 ha
->max_targets
= MAX_TARGETS_2200
;
1432 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1433 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1434 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2100
;
1435 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2100
;
1436 } else /*if (IS_QLA2300(ha))*/ {
1437 ha
->max_targets
= MAX_TARGETS_2200
;
1438 ha
->mbx_count
= MAILBOX_REGISTER_COUNT
;
1439 ha
->request_q_length
= REQUEST_ENTRY_CNT_2200
;
1440 ha
->response_q_length
= RESPONSE_ENTRY_CNT_2300
;
1441 ha
->last_loop_id
= SNS_LAST_LOOP_ID_2300
;
1443 host
->can_queue
= ha
->request_q_length
+ 128;
1445 /* load the F/W, read paramaters, and init the H/W */
1446 ha
->instance
= num_hosts
;
1448 init_MUTEX(&ha
->mbx_cmd_sem
);
1449 init_MUTEX_LOCKED(&ha
->mbx_intr_sem
);
1451 INIT_LIST_HEAD(&ha
->list
);
1452 INIT_LIST_HEAD(&ha
->fcports
);
1453 INIT_LIST_HEAD(&ha
->rscn_fcports
);
1456 * These locks are used to prevent more than one CPU
1457 * from modifying the queue at the same time. The
1458 * higher level "host_lock" will reduce most
1459 * contention for these locks.
1461 spin_lock_init(&ha
->mbx_reg_lock
);
1464 init_completion(&ha
->dpc_inited
);
1465 init_completion(&ha
->dpc_exited
);
1467 qla2x00_config_dma_addressing(ha
);
1468 if (qla2x00_mem_alloc(ha
)) {
1469 qla_printk(KERN_WARNING
, ha
,
1470 "[ERROR] Failed to allocate memory for adapter\n");
1475 if (qla2x00_initialize_adapter(ha
) &&
1476 !(ha
->device_flags
& DFLG_NO_CABLE
)) {
1478 qla_printk(KERN_WARNING
, ha
,
1479 "Failed to initialize adapter\n");
1481 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1482 "Adapter flags %x.\n",
1483 ha
->host_no
, ha
->device_flags
));
1489 * Startup the kernel thread for this host adapter
1491 ha
->dpc_should_die
= 0;
1492 ha
->dpc_pid
= kernel_thread(qla2x00_do_dpc
, ha
, 0);
1493 if (ha
->dpc_pid
< 0) {
1494 qla_printk(KERN_WARNING
, ha
,
1495 "Unable to start DPC thread!\n");
1499 wait_for_completion(&ha
->dpc_inited
);
1501 host
->this_id
= 255;
1502 host
->cmd_per_lun
= 3;
1503 host
->max_cmd_len
= MAX_CMDSZ
;
1504 host
->max_channel
= ha
->ports
- 1;
1505 host
->max_lun
= ha
->max_luns
;
1506 BUG_ON(qla2xxx_transport_template
== NULL
);
1507 host
->transportt
= qla2xxx_transport_template
;
1508 host
->unique_id
= ha
->instance
;
1509 host
->max_id
= ha
->max_targets
;
1511 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1512 ret
= request_irq(host
->irq
, qla2100_intr_handler
,
1513 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1515 ret
= request_irq(host
->irq
, qla2300_intr_handler
,
1516 SA_INTERRUPT
|SA_SHIRQ
, ha
->brd_info
->drv_name
, ha
);
1518 qla_printk(KERN_WARNING
, ha
,
1519 "Failed to reserve interrupt %d already in use.\n",
1524 /* Initialized the timer */
1525 qla2x00_start_timer(ha
, qla2x00_timer
, WATCH_INTERVAL
);
1527 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1532 /* Disable ISP interrupts. */
1533 qla2x00_disable_intrs(ha
);
1535 /* Ensure mailbox registers are free. */
1536 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1537 WRT_REG_WORD(®
->semaphore
, 0);
1538 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
1539 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
1541 /* Enable proper parity */
1542 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1545 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x1));
1547 /* SRAM, Instruction RAM and GP RAM parity */
1548 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x7));
1550 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1552 /* Enable chip interrupts. */
1553 qla2x00_enable_intrs(ha
);
1557 * Wait around max loop_reset_delay secs for the devices to come
1558 * on-line. We don't want Linux scanning before we are ready.
1561 for (wait_switch
= jiffies
+ (ha
->loop_reset_delay
* HZ
);
1562 time_before(jiffies
,wait_switch
) &&
1563 !(ha
->device_flags
& (DFLG_NO_CABLE
| DFLG_FABRIC_DEVICES
))
1564 && (ha
->device_flags
& SWITCH_FOUND
) ;) {
1566 qla2x00_check_fabric_devices(ha
);
1571 pci_set_drvdata(pdev
, ha
);
1572 ha
->flags
.init_done
= 1;
1575 /* List the target we have found */
1576 if (displayConfig
) {
1577 qla2x00_display_fc_names(ha
);
1580 if (scsi_add_host(host
, &pdev
->dev
))
1583 sysfs_create_bin_file(&host
->shost_gendev
.kobj
, &sysfs_fw_dump_attr
);
1584 sysfs_create_bin_file(&host
->shost_gendev
.kobj
, &sysfs_nvram_attr
);
1586 qla_printk(KERN_INFO
, ha
, "\n"
1587 " QLogic Fibre Channel HBA Driver: %s\n"
1589 " %s: %s @ %s hdma%c, host#=%ld, fw=%s\n", qla2x00_version_str
,
1590 ha
->model_number
, ha
->model_desc
? ha
->model_desc
: "",
1591 ha
->brd_info
->isp_name
, qla2x00_get_pci_info_str(ha
, pci_info
),
1592 pci_name(ha
->pdev
), ha
->flags
.enable_64bit_addressing
? '+': '-',
1593 ha
->host_no
, qla2x00_get_fw_version_str(ha
, fw_str
));
1596 scsi_scan_host(host
);
1601 qla2x00_free_device(ha
);
1603 scsi_host_put(host
);
1605 probe_disable_device
:
1606 pci_disable_device(pdev
);
1610 EXPORT_SYMBOL_GPL(qla2x00_probe_one
);
1612 void qla2x00_remove_one(struct pci_dev
*pdev
)
1614 scsi_qla_host_t
*ha
;
1616 ha
= pci_get_drvdata(pdev
);
1618 sysfs_remove_bin_file(&ha
->host
->shost_gendev
.kobj
,
1619 &sysfs_fw_dump_attr
);
1620 sysfs_remove_bin_file(&ha
->host
->shost_gendev
.kobj
, &sysfs_nvram_attr
);
1622 scsi_remove_host(ha
->host
);
1624 qla2x00_free_device(ha
);
1626 scsi_host_put(ha
->host
);
1628 pci_set_drvdata(pdev
, NULL
);
1630 EXPORT_SYMBOL_GPL(qla2x00_remove_one
);
1633 qla2x00_free_device(scsi_qla_host_t
*ha
)
1637 /* Abort any outstanding IO descriptors. */
1638 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1639 qla2x00_cancel_io_descriptors(ha
);
1641 /* turn-off interrupts on the card */
1642 if (ha
->interrupts_on
)
1643 qla2x00_disable_intrs(ha
);
1646 if (ha
->timer_active
)
1647 qla2x00_stop_timer(ha
);
1649 /* Kill the kernel thread for this host */
1650 if (ha
->dpc_pid
>= 0) {
1651 ha
->dpc_should_die
= 1;
1653 ret
= kill_proc(ha
->dpc_pid
, SIGHUP
, 1);
1655 qla_printk(KERN_ERR
, ha
,
1656 "Unable to signal DPC thread -- (%d)\n", ret
);
1658 /* TODO: SOMETHING MORE??? */
1660 wait_for_completion(&ha
->dpc_exited
);
1664 qla2x00_mem_free(ha
);
1667 ha
->flags
.online
= 0;
1669 /* Detach interrupts */
1671 free_irq(ha
->pdev
->irq
, ha
);
1673 /* release io space registers */
1675 iounmap(ha
->iobase
);
1676 pci_release_regions(ha
->pdev
);
1678 pci_disable_device(ha
->pdev
);
1683 * The following support functions are adopted to handle
1684 * the re-entrant qla2x00_proc_info correctly.
1687 copy_mem_info(struct info_str
*info
, char *data
, int len
)
1689 if (info
->pos
+ len
> info
->offset
+ info
->length
)
1690 len
= info
->offset
+ info
->length
- info
->pos
;
1692 if (info
->pos
+ len
< info
->offset
) {
1697 if (info
->pos
< info
->offset
) {
1700 partial
= info
->offset
- info
->pos
;
1702 info
->pos
+= partial
;
1707 memcpy(info
->buffer
, data
, len
);
1709 info
->buffer
+= len
;
1714 copy_info(struct info_str
*info
, char *fmt
, ...)
1720 va_start(args
, fmt
);
1721 len
= vsprintf(buf
, fmt
, args
);
1724 copy_mem_info(info
, buf
, len
);
1729 /*************************************************************************
1733 * Return information to handle /proc support for the driver.
1735 * inout : decides the direction of the dataflow and the meaning of the
1737 * buffer: If inout==0 data is being written to it else read from it
1738 * (ptr to a page buffer)
1739 * *start: If inout==0 start of the valid data in the buffer
1740 * offset: If inout==0 starting offset from the beginning of all
1741 * possible data to return.
1742 * length: If inout==0 max number of bytes to be written into the buffer
1743 * else number of bytes in "buffer"
1745 * < 0: error. errno value.
1746 * >= 0: sizeof data returned.
1747 *************************************************************************/
1749 qla2x00_proc_info(struct Scsi_Host
*shost
, char *buffer
,
1750 char **start
, off_t offset
, int length
, int inout
)
1752 struct info_str info
;
1753 int retval
= -EINVAL
;
1759 uint8_t *loop_state
;
1760 scsi_qla_host_t
*ha
;
1763 DEBUG3(printk(KERN_INFO
1764 "Entering proc_info buff_in=%p, offset=0x%lx, length=0x%x\n",
1765 buffer
, offset
, length
);)
1767 ha
= (scsi_qla_host_t
*) shost
->hostdata
;
1770 /* Has data been written to the file? */
1772 "%s: has data been written to the file. \n",
1782 info
.buffer
= buffer
;
1783 info
.length
= length
;
1784 info
.offset
= offset
;
1787 /* start building the print buffer */
1789 "QLogic PCI to Fibre Channel Host Adapter for %s:\n"
1790 " Firmware version %s, ",
1791 ha
->model_number
, qla2x00_get_fw_version_str(ha
, fw_info
));
1793 copy_info(&info
, "Driver version %s\n", qla2x00_version_str
);
1795 tmp_sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) |
1797 copy_info(&info
, "ISP: %s, Serial# %c%05d\n",
1798 ha
->brd_info
->isp_name
, ('A' + tmp_sn
/100000), (tmp_sn
%100000));
1801 "Request Queue = 0x%llx, Response Queue = 0x%llx\n",
1802 (unsigned long long)ha
->request_dma
,
1803 (unsigned long long)ha
->response_dma
);
1806 "Request Queue count = %d, Response Queue count = %d\n",
1807 ha
->request_q_length
, ha
->response_q_length
);
1810 "Total number of active commands = %ld\n",
1814 "Total number of interrupts = %ld\n",
1815 (long)ha
->total_isr_cnt
);
1818 " Device queue depth = 0x%x\n",
1819 (ql2xmaxqdepth
== 0) ? 16 : ql2xmaxqdepth
);
1822 "Number of free request entries = %d\n", ha
->req_q_cnt
);
1825 "Number of mailbox timeouts = %ld\n", ha
->total_mbx_timeout
);
1828 "Number of ISP aborts = %ld\n", ha
->total_isp_aborts
);
1831 "Number of loop resyncs = %ld\n", ha
->total_loop_resync
);
1834 "Number of retries for empty slots = %ld\n",
1835 qla2x00_stats
.outarray_full
);
1837 flags
= (uint32_t *) &ha
->flags
;
1839 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
) {
1840 loop_state
= "DOWN";
1841 } else if (atomic_read(&ha
->loop_state
) == LOOP_UP
) {
1843 } else if (atomic_read(&ha
->loop_state
) == LOOP_READY
) {
1844 loop_state
= "READY";
1845 } else if (atomic_read(&ha
->loop_state
) == LOOP_TIMEOUT
) {
1846 loop_state
= "TIMEOUT";
1847 } else if (atomic_read(&ha
->loop_state
) == LOOP_UPDATE
) {
1848 loop_state
= "UPDATE";
1850 loop_state
= "UNKNOWN";
1854 "Host adapter:loop state = <%s>, flags = 0x%lx\n",
1855 loop_state
, *flags
);
1857 copy_info(&info
, "Dpc flags = 0x%lx\n", ha
->dpc_flags
);
1859 copy_info(&info
, "MBX flags = 0x%x\n", ha
->mbx_flags
);
1861 copy_info(&info
, "Link down Timeout = %3.3d\n",
1862 ha
->link_down_timeout
);
1864 copy_info(&info
, "Port down retry = %3.3d\n",
1865 ha
->port_down_retry_count
);
1867 copy_info(&info
, "Login retry count = %3.3d\n",
1868 ha
->login_retry_count
);
1871 "Commands retried with dropped frame(s) = %d\n",
1872 ha
->dropped_frame_error_cnt
);
1875 "Product ID = %04x %04x %04x %04x\n", ha
->product_id
[0],
1876 ha
->product_id
[1], ha
->product_id
[2], ha
->product_id
[3]);
1878 copy_info(&info
, "\n");
1880 /* 2.25 node/port display to proc */
1881 /* Display the node name for adapter */
1882 copy_info(&info
, "\nSCSI Device Information:\n");
1884 "scsi-qla%d-adapter-node="
1885 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1887 ha
->init_cb
->node_name
[0],
1888 ha
->init_cb
->node_name
[1],
1889 ha
->init_cb
->node_name
[2],
1890 ha
->init_cb
->node_name
[3],
1891 ha
->init_cb
->node_name
[4],
1892 ha
->init_cb
->node_name
[5],
1893 ha
->init_cb
->node_name
[6],
1894 ha
->init_cb
->node_name
[7]);
1896 /* display the port name for adapter */
1898 "scsi-qla%d-adapter-port="
1899 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1901 ha
->init_cb
->port_name
[0],
1902 ha
->init_cb
->port_name
[1],
1903 ha
->init_cb
->port_name
[2],
1904 ha
->init_cb
->port_name
[3],
1905 ha
->init_cb
->port_name
[4],
1906 ha
->init_cb
->port_name
[5],
1907 ha
->init_cb
->port_name
[6],
1908 ha
->init_cb
->port_name
[7]);
1910 /* Print out device port names */
1911 for (t
= 0; t
< MAX_FIBRE_DEVICES
; t
++) {
1912 if ((tq
= TGT_Q(ha
, t
)) == NULL
)
1916 "scsi-qla%d-target-%d="
1917 "%02x%02x%02x%02x%02x%02x%02x%02x;\n",
1918 (int)ha
->instance
, t
,
1919 tq
->port_name
[0], tq
->port_name
[1],
1920 tq
->port_name
[2], tq
->port_name
[3],
1921 tq
->port_name
[4], tq
->port_name
[5],
1922 tq
->port_name
[6], tq
->port_name
[7]);
1925 copy_info(&info
, "\nSCSI LUN Information:\n");
1927 "(Id:Lun) * - indicates lun is not registered with the OS.\n");
1929 /* scan for all equipment stats */
1930 for (t
= 0; t
< MAX_FIBRE_DEVICES
; t
++) {
1932 for (l
= 0; l
< ha
->max_luns
; l
++) {
1933 up
= (os_lun_t
*) GET_LU_Q(ha
, t
, l
);
1938 if (up
->fclun
== NULL
) {
1943 "(%2d:%2d): Total reqs %ld,",
1947 " Pending reqs %ld,",
1950 if (up
->io_cnt
< 4) {
1961 " %ld:%d:%02x %02x",
1962 up
->fclun
->fcport
->ha
->instance
,
1963 up
->fclun
->fcport
->cur_path
,
1964 up
->fclun
->fcport
->loop_id
,
1965 up
->fclun
->device_type
);
1967 copy_info(&info
, "\n");
1969 if (info
.pos
>= info
.offset
+ info
.length
) {
1970 /* No need to continue */
1975 if (info
.pos
>= info
.offset
+ info
.length
) {
1976 /* No need to continue */
1983 retval
= info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;
1985 DEBUG3(printk(KERN_INFO
1986 "Exiting proc_info: info.pos=%d, offset=0x%lx, "
1987 "length=0x%x\n", info
.pos
, offset
, length
);)
1993 * qla2x00_display_fc_names
1994 * This routine will the node names of the different devices found
1995 * after port inquiry.
1998 * cmd = SCSI command structure
2004 qla2x00_display_fc_names(scsi_qla_host_t
*ha
)
2009 /* Display the node name for adapter */
2010 qla_printk(KERN_INFO
, ha
,
2011 "scsi-qla%d-adapter-node=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2013 ha
->init_cb
->node_name
[0],
2014 ha
->init_cb
->node_name
[1],
2015 ha
->init_cb
->node_name
[2],
2016 ha
->init_cb
->node_name
[3],
2017 ha
->init_cb
->node_name
[4],
2018 ha
->init_cb
->node_name
[5],
2019 ha
->init_cb
->node_name
[6],
2020 ha
->init_cb
->node_name
[7]);
2022 /* display the port name for adapter */
2023 qla_printk(KERN_INFO
, ha
,
2024 "scsi-qla%d-adapter-port=%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2026 ha
->init_cb
->port_name
[0],
2027 ha
->init_cb
->port_name
[1],
2028 ha
->init_cb
->port_name
[2],
2029 ha
->init_cb
->port_name
[3],
2030 ha
->init_cb
->port_name
[4],
2031 ha
->init_cb
->port_name
[5],
2032 ha
->init_cb
->port_name
[6],
2033 ha
->init_cb
->port_name
[7]);
2035 /* Print out device port names */
2036 for (tgt
= 0; tgt
< MAX_TARGETS
; tgt
++) {
2037 if ((tq
= ha
->otgt
[tgt
]) == NULL
)
2040 if (tq
->fcport
== NULL
)
2043 switch (ha
->binding_type
) {
2044 case BIND_BY_PORT_NAME
:
2045 qla_printk(KERN_INFO
, ha
,
2046 "scsi-qla%d-tgt-%d-di-0-port="
2047 "%02x%02x%02x%02x%02x%02x%02x%02x\\;\n",
2061 case BIND_BY_PORT_ID
:
2062 qla_printk(KERN_INFO
, ha
,
2063 "scsi-qla%d-tgt-%d-di-0-pid="
2064 "%02x%02x%02x\\;\n",
2074 qla_printk(KERN_INFO
, ha
,
2075 "scsi-qla%d-target-%d-vsa=01;\n", (int)ha
->instance
, tgt
);
2082 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2084 * Input: ha = adapter block pointer. fcport = port structure pointer.
2090 void qla2x00_mark_device_lost(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2094 * We may need to retry the login, so don't change the state of the
2095 * port but do the retries.
2097 if (atomic_read(&fcport
->state
) != FCS_DEVICE_DEAD
)
2098 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2103 if (fcport
->login_retry
== 0) {
2104 fcport
->login_retry
= ha
->login_retry_count
;
2105 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
2107 DEBUG(printk("scsi(%ld): Port login retry: "
2108 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2109 "id = 0x%04x retry cnt=%d\n",
2111 fcport
->port_name
[0],
2112 fcport
->port_name
[1],
2113 fcport
->port_name
[2],
2114 fcport
->port_name
[3],
2115 fcport
->port_name
[4],
2116 fcport
->port_name
[5],
2117 fcport
->port_name
[6],
2118 fcport
->port_name
[7],
2120 fcport
->login_retry
));
2125 * qla2x00_mark_all_devices_lost
2126 * Updates fcport state when device goes offline.
2129 * ha = adapter block pointer.
2130 * fcport = port structure pointer.
2138 qla2x00_mark_all_devices_lost(scsi_qla_host_t
*ha
)
2142 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2143 if (fcport
->port_type
!= FCT_TARGET
)
2147 * No point in marking the device as lost, if the device is
2150 if (atomic_read(&fcport
->state
) == FCS_DEVICE_DEAD
)
2153 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2159 * Allocates adapter memory.
2166 qla2x00_mem_alloc(scsi_qla_host_t
*ha
)
2174 * This will loop only once if everything goes well, else some
2175 * number of retries will be performed to get around a kernel
2176 * bug where available mem is not allocated until after a
2177 * little delay and a retry.
2179 ha
->request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2180 (ha
->request_q_length
+ 1) * sizeof(request_t
),
2181 &ha
->request_dma
, GFP_KERNEL
);
2182 if (ha
->request_ring
== NULL
) {
2183 qla_printk(KERN_WARNING
, ha
,
2184 "Memory Allocation failed - request_ring\n");
2186 qla2x00_mem_free(ha
);
2192 ha
->response_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
2193 (ha
->response_q_length
+ 1) * sizeof(response_t
),
2194 &ha
->response_dma
, GFP_KERNEL
);
2195 if (ha
->response_ring
== NULL
) {
2196 qla_printk(KERN_WARNING
, ha
,
2197 "Memory Allocation failed - response_ring\n");
2199 qla2x00_mem_free(ha
);
2205 ha
->gid_list
= dma_alloc_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
,
2206 &ha
->gid_list_dma
, GFP_KERNEL
);
2207 if (ha
->gid_list
== NULL
) {
2208 qla_printk(KERN_WARNING
, ha
,
2209 "Memory Allocation failed - gid_list\n");
2211 qla2x00_mem_free(ha
);
2217 ha
->rlc_rsp
= dma_alloc_coherent(&ha
->pdev
->dev
,
2218 sizeof(rpt_lun_cmd_rsp_t
), &ha
->rlc_rsp_dma
, GFP_KERNEL
);
2219 if (ha
->rlc_rsp
== NULL
) {
2220 qla_printk(KERN_WARNING
, ha
,
2221 "Memory Allocation failed - rlc");
2223 qla2x00_mem_free(ha
);
2229 snprintf(name
, sizeof(name
), "qla2xxx_%ld", ha
->host_no
);
2230 ha
->s_dma_pool
= dma_pool_create(name
, &ha
->pdev
->dev
,
2231 DMA_POOL_SIZE
, 8, 0);
2232 if (ha
->s_dma_pool
== NULL
) {
2233 qla_printk(KERN_WARNING
, ha
,
2234 "Memory Allocation failed - s_dma_pool\n");
2236 qla2x00_mem_free(ha
);
2242 /* get consistent memory allocated for init control block */
2243 ha
->init_cb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2245 if (ha
->init_cb
== NULL
) {
2246 qla_printk(KERN_WARNING
, ha
,
2247 "Memory Allocation failed - init_cb\n");
2249 qla2x00_mem_free(ha
);
2254 memset(ha
->init_cb
, 0, sizeof(init_cb_t
));
2256 /* Get consistent memory allocated for Get Port Database cmd */
2257 ha
->iodesc_pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2258 &ha
->iodesc_pd_dma
);
2259 if (ha
->iodesc_pd
== NULL
) {
2261 qla_printk(KERN_WARNING
, ha
,
2262 "Memory Allocation failed - iodesc_pd\n");
2264 qla2x00_mem_free(ha
);
2269 memset(ha
->iodesc_pd
, 0, PORT_DATABASE_SIZE
);
2271 /* Allocate ioctl related memory. */
2272 if (qla2x00_alloc_ioctl_mem(ha
)) {
2273 qla_printk(KERN_WARNING
, ha
,
2274 "Memory Allocation failed - ioctl_mem\n");
2276 qla2x00_mem_free(ha
);
2282 if (qla2x00_allocate_sp_pool(ha
)) {
2283 qla_printk(KERN_WARNING
, ha
,
2284 "Memory Allocation failed - "
2285 "qla2x00_allocate_sp_pool()\n");
2287 qla2x00_mem_free(ha
);
2293 /* Allocate memory for SNS commands */
2294 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2295 /* Get consistent memory allocated for SNS commands */
2296 ha
->sns_cmd
= dma_alloc_coherent(&ha
->pdev
->dev
,
2297 sizeof(struct sns_cmd_pkt
), &ha
->sns_cmd_dma
,
2299 if (ha
->sns_cmd
== NULL
) {
2301 qla_printk(KERN_WARNING
, ha
,
2302 "Memory Allocation failed - sns_cmd\n");
2304 qla2x00_mem_free(ha
);
2309 memset(ha
->sns_cmd
, 0, sizeof(struct sns_cmd_pkt
));
2311 /* Get consistent memory allocated for MS IOCB */
2312 ha
->ms_iocb
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
2314 if (ha
->ms_iocb
== NULL
) {
2316 qla_printk(KERN_WARNING
, ha
,
2317 "Memory Allocation failed - ms_iocb\n");
2319 qla2x00_mem_free(ha
);
2324 memset(ha
->ms_iocb
, 0, sizeof(ms_iocb_entry_t
));
2327 * Get consistent memory allocated for CT SNS
2330 ha
->ct_sns
= dma_alloc_coherent(&ha
->pdev
->dev
,
2331 sizeof(struct ct_sns_pkt
), &ha
->ct_sns_dma
,
2333 if (ha
->ct_sns
== NULL
) {
2335 qla_printk(KERN_WARNING
, ha
,
2336 "Memory Allocation failed - ct_sns\n");
2338 qla2x00_mem_free(ha
);
2343 memset(ha
->ct_sns
, 0, sizeof(struct ct_sns_pkt
));
2346 /* Done all allocations without any error. */
2349 } while (retry
-- && status
!= 0);
2353 "%s(): **** FAILED ****\n", __func__
);
2361 * Frees all adapter allocated memory.
2364 * ha = adapter block pointer.
2367 qla2x00_mem_free(scsi_qla_host_t
*ha
)
2370 struct list_head
*fcpl
, *fcptemp
;
2372 struct list_head
*fcll
, *fcltemp
;
2374 unsigned long wtime
;/* max wait time if mbx cmd is busy. */
2378 DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__
));
2382 /* Free the target queues */
2383 for (t
= 0; t
< MAX_TARGETS
; t
++) {
2384 qla2x00_tgt_free(ha
, t
);
2387 /* Make sure all other threads are stopped. */
2389 while (ha
->dpc_wait
&& wtime
) {
2390 set_current_state(TASK_INTERRUPTIBLE
);
2391 wtime
= schedule_timeout(wtime
);
2394 /* free ioctl memory */
2395 qla2x00_free_ioctl_mem(ha
);
2398 qla2x00_free_sp_pool(ha
);
2401 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct sns_cmd_pkt
),
2402 ha
->sns_cmd
, ha
->sns_cmd_dma
);
2405 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct ct_sns_pkt
),
2406 ha
->ct_sns
, ha
->ct_sns_dma
);
2409 dma_pool_free(ha
->s_dma_pool
, ha
->ms_iocb
, ha
->ms_iocb_dma
);
2412 dma_pool_free(ha
->s_dma_pool
, ha
->iodesc_pd
, ha
->iodesc_pd_dma
);
2415 dma_pool_free(ha
->s_dma_pool
, ha
->init_cb
, ha
->init_cb_dma
);
2418 dma_pool_destroy(ha
->s_dma_pool
);
2421 dma_free_coherent(&ha
->pdev
->dev
,
2422 sizeof(rpt_lun_cmd_rsp_t
), ha
->rlc_rsp
,
2426 dma_free_coherent(&ha
->pdev
->dev
, GID_LIST_SIZE
, ha
->gid_list
,
2429 if (ha
->response_ring
)
2430 dma_free_coherent(&ha
->pdev
->dev
,
2431 (ha
->response_q_length
+ 1) * sizeof(response_t
),
2432 ha
->response_ring
, ha
->response_dma
);
2434 if (ha
->request_ring
)
2435 dma_free_coherent(&ha
->pdev
->dev
,
2436 (ha
->request_q_length
+ 1) * sizeof(request_t
),
2437 ha
->request_ring
, ha
->request_dma
);
2440 ha
->sns_cmd_dma
= 0;
2444 ha
->ms_iocb_dma
= 0;
2445 ha
->iodesc_pd
= NULL
;
2446 ha
->iodesc_pd_dma
= 0;
2448 ha
->init_cb_dma
= 0;
2450 ha
->s_dma_pool
= NULL
;
2453 ha
->rlc_rsp_dma
= 0;
2454 ha
->gid_list
= NULL
;
2455 ha
->gid_list_dma
= 0;
2457 ha
->response_ring
= NULL
;
2458 ha
->response_dma
= 0;
2459 ha
->request_ring
= NULL
;
2460 ha
->request_dma
= 0;
2462 list_for_each_safe(fcpl
, fcptemp
, &ha
->fcports
) {
2463 fcport
= list_entry(fcpl
, fc_port_t
, list
);
2466 list_for_each_safe(fcll
, fcltemp
, &fcport
->fcluns
) {
2467 fclun
= list_entry(fcll
, fc_lun_t
, list
);
2469 list_del_init(&fclun
->list
);
2474 list_del_init(&fcport
->list
);
2477 INIT_LIST_HEAD(&ha
->fcports
);
2480 free_pages((unsigned long)ha
->fw_dump
, ha
->fw_dump_order
);
2482 if (ha
->fw_dump_buffer
)
2483 vfree(ha
->fw_dump_buffer
);
2486 ha
->fw_dump_reading
= 0;
2487 ha
->fw_dump_buffer
= NULL
;
2491 * qla2x00_allocate_sp_pool
2492 * This routine is called during initialization to allocate
2493 * memory for local srb_t.
2496 * ha = adapter block pointer.
2501 * Note: Sets the ref_count for non Null sp to one.
2504 qla2x00_allocate_sp_pool(scsi_qla_host_t
*ha
)
2509 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
2510 mempool_free_slab
, srb_cachep
);
2511 if (ha
->srb_mempool
== NULL
) {
2512 qla_printk(KERN_INFO
, ha
, "Unable to allocate SRB mempool.\n");
2513 rval
= QLA_FUNCTION_FAILED
;
2519 * This routine frees all adapter allocated memory.
2523 qla2x00_free_sp_pool( scsi_qla_host_t
*ha
)
2525 if (ha
->srb_mempool
) {
2526 mempool_destroy(ha
->srb_mempool
);
2527 ha
->srb_mempool
= NULL
;
2531 /**************************************************************************
2533 * This kernel thread is a task that is schedule by the interrupt handler
2534 * to perform the background processing for interrupts.
2537 * This task always run in the context of a kernel thread. It
2538 * is kick-off by the driver's detect code and starts up
2539 * up one per adapter. It immediately goes to sleep and waits for
2540 * some fibre event. When either the interrupt handler or
2541 * the timer routine detects a event it will one of the task
2542 * bits then wake us up.
2543 **************************************************************************/
2545 qla2x00_do_dpc(void *data
)
2547 DECLARE_MUTEX_LOCKED(sem
);
2548 scsi_qla_host_t
*ha
;
2551 uint16_t next_loopid
;
2553 ha
= (scsi_qla_host_t
*)data
;
2557 daemonize("%s_dpc", ha
->host_str
);
2558 allow_signal(SIGHUP
);
2560 ha
->dpc_wait
= &sem
;
2562 set_user_nice(current
, -20);
2566 complete(&ha
->dpc_inited
);
2569 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2571 if (down_interruptible(&sem
))
2574 if (ha
->dpc_should_die
)
2577 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2579 /* Initialization not yet finished. Don't do anything yet. */
2580 if (!ha
->flags
.init_done
|| ha
->dpc_active
)
2583 DEBUG3(printk("scsi(%ld): DPC handler\n", ha
->host_no
));
2587 if (ha
->flags
.mbox_busy
) {
2592 if (test_and_clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2594 DEBUG(printk("scsi(%ld): dpc: sched "
2595 "qla2x00_abort_isp ha = %p\n",
2597 if (!(test_and_set_bit(ABORT_ISP_ACTIVE
,
2600 if (qla2x00_abort_isp(ha
)) {
2601 /* failed. retry later */
2602 set_bit(ISP_ABORT_NEEDED
,
2605 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
2607 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2611 if (test_and_clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) &&
2612 (!(test_and_set_bit(RESET_ACTIVE
, &ha
->dpc_flags
)))) {
2614 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2617 qla2x00_rst_aen(ha
);
2618 clear_bit(RESET_ACTIVE
, &ha
->dpc_flags
);
2621 /* Retry each device up to login retry count */
2622 if ((test_and_clear_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2623 !test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) &&
2624 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2626 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2630 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2631 if (fcport
->port_type
!= FCT_TARGET
)
2635 * If the port is not ONLINE then try to login
2636 * to it if we haven't run out of retries.
2638 if (atomic_read(&fcport
->state
) != FCS_ONLINE
&&
2639 fcport
->login_retry
) {
2641 fcport
->login_retry
--;
2642 if (fcport
->flags
& FCF_FABRIC_DEVICE
) {
2645 qla2x00_fabric_logout(
2648 status
= qla2x00_fabric_login(
2649 ha
, fcport
, &next_loopid
);
2652 qla2x00_local_device_login(
2653 ha
, fcport
->loop_id
);
2655 if (status
== QLA_SUCCESS
) {
2656 fcport
->old_loop_id
= fcport
->loop_id
;
2658 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2659 ha
->host_no
, fcport
->loop_id
));
2661 fcport
->port_login_retry_count
=
2662 ha
->port_down_retry_count
* PORT_RETRY_TIME
;
2663 atomic_set(&fcport
->state
, FCS_ONLINE
);
2664 atomic_set(&fcport
->port_down_timer
,
2665 ha
->port_down_retry_count
* PORT_RETRY_TIME
);
2667 fcport
->login_retry
= 0;
2668 } else if (status
== 1) {
2669 set_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
);
2670 /* retry the login again */
2671 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2673 fcport
->login_retry
, fcport
->loop_id
));
2675 fcport
->login_retry
= 0;
2678 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2681 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2685 if ((test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
)) &&
2686 atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2688 clear_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
);
2689 DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",
2692 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2694 DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",
2698 if (test_and_clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
2700 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2703 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE
,
2706 qla2x00_loop_resync(ha
);
2708 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
2711 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2715 if (test_and_clear_bit(FCPORT_RESCAN_NEEDED
, &ha
->dpc_flags
)) {
2717 DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",
2720 qla2x00_rescan_fcports(ha
);
2722 DEBUG(printk("scsi(%ld): Rescan flagged fcports..."
2727 if (!ha
->interrupts_on
)
2728 qla2x00_enable_intrs(ha
);
2731 } /* End of while(1) */
2733 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha
->host_no
));
2736 * Make sure that nobody tries to wake us up again.
2738 ha
->dpc_wait
= NULL
;
2741 complete_and_exit(&ha
->dpc_exited
, 0);
2746 * Processes asynchronous reset.
2749 * ha = adapter block pointer.
2752 qla2x00_rst_aen(scsi_qla_host_t
*ha
)
2754 if (ha
->flags
.online
&& !ha
->flags
.reset_active
&&
2755 !atomic_read(&ha
->loop_down_timer
) &&
2756 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
))) {
2758 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
2761 * Issue marker command only when we are going to start
2764 ha
->marker_needed
= 1;
2765 } while (!atomic_read(&ha
->loop_down_timer
) &&
2766 (test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
)));
2772 * This routine will allocate SP from the free queue
2779 qla2x00_get_new_sp(scsi_qla_host_t
*ha
)
2783 sp
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
2785 atomic_set(&sp
->ref_count
, 1);
2790 qla2x00_sp_free_dma(scsi_qla_host_t
*ha
, srb_t
*sp
)
2792 struct scsi_cmnd
*cmd
= sp
->cmd
;
2794 if (sp
->flags
& SRB_DMA_VALID
) {
2796 dma_unmap_sg(&ha
->pdev
->dev
, cmd
->request_buffer
,
2797 cmd
->use_sg
, cmd
->sc_data_direction
);
2798 } else if (cmd
->request_bufflen
) {
2799 dma_unmap_single(&ha
->pdev
->dev
, sp
->dma_handle
,
2800 cmd
->request_bufflen
, cmd
->sc_data_direction
);
2802 sp
->flags
&= ~SRB_DMA_VALID
;
2807 qla2x00_sp_compl(scsi_qla_host_t
*ha
, srb_t
*sp
)
2809 struct scsi_cmnd
*cmd
= sp
->cmd
;
2811 qla2x00_sp_free_dma(ha
, sp
);
2814 mempool_free(sp
, ha
->srb_mempool
);
2816 cmd
->scsi_done(cmd
);
2819 /**************************************************************************
2825 * Context: Interrupt
2826 ***************************************************************************/
2828 qla2x00_timer(scsi_qla_host_t
*ha
)
2830 unsigned long cpu_flags
= 0;
2838 * Ports - Port down timer.
2840 * Whenever, a port is in the LOST state we start decrementing its port
2841 * down timer every second until it reaches zero. Once it reaches zero
2842 * the port it marked DEAD.
2845 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2846 if (fcport
->port_type
!= FCT_TARGET
)
2849 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2851 if (atomic_read(&fcport
->port_down_timer
) == 0)
2854 if (atomic_dec_and_test(&fcport
->port_down_timer
) != 0)
2855 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2857 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2860 t
, atomic_read(&fcport
->port_down_timer
)));
2863 } /* End of for fcport */
2866 /* Loop down handler. */
2867 if (atomic_read(&ha
->loop_down_timer
) > 0 &&
2868 !(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) && ha
->flags
.online
) {
2870 if (atomic_read(&ha
->loop_down_timer
) ==
2871 ha
->loop_down_abort_time
) {
2873 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2874 "queues before time expire\n",
2877 if (!IS_QLA2100(ha
) && ha
->link_down_timeout
)
2878 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
2880 /* Schedule an ISP abort to return any tape commands. */
2881 spin_lock_irqsave(&ha
->hardware_lock
, cpu_flags
);
2882 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
;
2884 sp
= ha
->outstanding_cmds
[index
];
2887 if (!(sp
->fclun
->fcport
->flags
&
2891 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2894 spin_unlock_irqrestore(&ha
->hardware_lock
, cpu_flags
);
2896 set_bit(ABORT_QUEUES_NEEDED
, &ha
->dpc_flags
);
2900 /* if the loop has been down for 4 minutes, reinit adapter */
2901 if (atomic_dec_and_test(&ha
->loop_down_timer
) != 0) {
2902 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2903 "restarting queues.\n",
2906 set_bit(RESTART_QUEUES_NEEDED
, &ha
->dpc_flags
);
2909 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
2910 DEBUG(printk("scsi(%ld): Loop down - "
2913 qla_printk(KERN_WARNING
, ha
,
2914 "Loop down - aborting ISP.\n");
2916 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2919 DEBUG3(printk("scsi(%ld): Loop Down - seconds remainning %d\n",
2921 atomic_read(&ha
->loop_down_timer
)));
2924 /* Schedule the DPC routine if needed */
2925 if ((test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) ||
2926 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
) ||
2928 test_bit(LOGIN_RETRY_NEEDED
, &ha
->dpc_flags
) ||
2929 test_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
) ||
2930 test_bit(RELOGIN_NEEDED
, &ha
->dpc_flags
)) &&
2931 ha
->dpc_wait
&& !ha
->dpc_active
) {
2936 qla2x00_restart_timer(ha
, WATCH_INTERVAL
);
2939 /* XXX(hch): crude hack to emulate a down_timeout() */
2941 qla2x00_down_timeout(struct semaphore
*sema
, unsigned long timeout
)
2943 const unsigned int step
= HZ
/10;
2946 if (!down_trylock(sema
))
2948 set_current_state(TASK_INTERRUPTIBLE
);
2949 if (schedule_timeout(step
))
2951 } while ((timeout
-= step
) > 0);
2957 qla2xxx_get_port_id(struct scsi_target
*starget
)
2959 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2960 scsi_qla_host_t
*ha
= to_qla_host(shost
);
2963 list_for_each_entry(fc
, &ha
->fcports
, list
) {
2964 if (fc
->os_target_id
== starget
->id
) {
2965 fc_starget_port_id(starget
) = fc
->d_id
.b
.domain
<< 16 |
2966 fc
->d_id
.b
.area
<< 8 |
2971 fc_starget_port_id(starget
) = -1;
2975 qla2xxx_get_port_name(struct scsi_target
*starget
)
2977 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2978 scsi_qla_host_t
*ha
= to_qla_host(shost
);
2981 list_for_each_entry(fc
, &ha
->fcports
, list
) {
2982 if (fc
->os_target_id
== starget
->id
) {
2983 fc_starget_port_name(starget
) =
2984 __be64_to_cpu(*(uint64_t *)fc
->port_name
);
2988 fc_starget_port_name(starget
) = -1;
2992 qla2xxx_get_node_name(struct scsi_target
*starget
)
2994 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
2995 scsi_qla_host_t
*ha
= to_qla_host(shost
);
2998 list_for_each_entry(fc
, &ha
->fcports
, list
) {
2999 if (fc
->os_target_id
== starget
->id
) {
3000 fc_starget_node_name(starget
) =
3001 __be64_to_cpu(*(uint64_t *)fc
->node_name
);
3005 fc_starget_node_name(starget
) = -1;
3008 static struct fc_function_template qla2xxx_transport_functions
= {
3009 .get_starget_port_id
= qla2xxx_get_port_id
,
3010 .show_starget_port_id
= 1,
3011 .get_starget_port_name
= qla2xxx_get_port_name
,
3012 .show_starget_port_name
= 1,
3013 .get_starget_node_name
= qla2xxx_get_node_name
,
3014 .show_starget_node_name
= 1,
3018 * qla2x00_module_init - Module initialization.
3021 qla2x00_module_init(void)
3023 /* Allocate cache for SRBs. */
3024 sprintf(srb_cachep_name
, "qla2xxx_srbs");
3025 srb_cachep
= kmem_cache_create(srb_cachep_name
, sizeof(srb_t
), 0,
3026 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
3027 if (srb_cachep
== NULL
) {
3029 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3033 /* Derive version string. */
3034 strcpy(qla2x00_version_str
, QLA2XXX_VERSION
);
3036 strcat(qla2x00_version_str
, "-debug");
3039 qla2xxx_transport_template
= fc_attach_transport(&qla2xxx_transport_functions
);
3040 if (!qla2xxx_transport_template
)
3043 printk(KERN_INFO
"QLogic Fibre Channel HBA Driver\n");
3048 * qla2x00_module_exit - Module cleanup.
3051 qla2x00_module_exit(void)
3053 /* Free SRBs cache. */
3054 if (srb_cachep
!= NULL
) {
3055 if (kmem_cache_destroy(srb_cachep
) != 0) {
3057 "qla2xxx: Unable to free SRB cache...Memory pools "
3063 fc_release_transport(qla2xxx_transport_template
);
3066 module_init(qla2x00_module_init
);
3067 module_exit(qla2x00_module_exit
);
3069 MODULE_AUTHOR("QLogic Corporation");
3070 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3071 MODULE_LICENSE("GPL");
3072 MODULE_VERSION(QLA2XXX_VERSION
);